]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.17.7-201412170700.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.17.7-201412170700.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 267f893..78c2d4b 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..2e964a2 100644
983 --- a/arch/arm/include/asm/atomic.h
984 +++ b/arch/arm/include/asm/atomic.h
985 @@ -18,17 +18,41 @@
986 #include <asm/barrier.h>
987 #include <asm/cmpxchg.h>
988
989 +#ifdef CONFIG_GENERIC_ATOMIC64
990 +#include <asm-generic/atomic64.h>
991 +#endif
992 +
993 #define ATOMIC_INIT(i) { (i) }
994
995 #ifdef __KERNEL__
996
997 +#ifdef CONFIG_THUMB2_KERNEL
998 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
999 +#else
1000 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
1001 +#endif
1002 +
1003 +#define _ASM_EXTABLE(from, to) \
1004 +" .pushsection __ex_table,\"a\"\n"\
1005 +" .align 3\n" \
1006 +" .long " #from ", " #to"\n" \
1007 +" .popsection"
1008 +
1009 /*
1010 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1011 * strex/ldrex monitor on some implementations. The reason we can use it for
1012 * atomic_set() is the clrex or dummy strex done on every exception return.
1013 */
1014 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1015 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1016 +{
1017 + return *(const volatile int *)&v->counter;
1018 +}
1019 #define atomic_set(v,i) (((v)->counter) = (i))
1020 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1021 +{
1022 + v->counter = i;
1023 +}
1024
1025 #if __LINUX_ARM_ARCH__ >= 6
1026
1027 @@ -44,6 +68,36 @@ static inline void atomic_add(int i, atomic_t *v)
1028
1029 prefetchw(&v->counter);
1030 __asm__ __volatile__("@ atomic_add\n"
1031 +"1: ldrex %1, [%3]\n"
1032 +" adds %0, %1, %4\n"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +" bvc 3f\n"
1036 +"2: " REFCOUNT_TRAP_INSN "\n"
1037 +"3:\n"
1038 +#endif
1039 +
1040 +" strex %1, %0, [%3]\n"
1041 +" teq %1, #0\n"
1042 +" bne 1b"
1043 +
1044 +#ifdef CONFIG_PAX_REFCOUNT
1045 +"\n4:\n"
1046 + _ASM_EXTABLE(2b, 4b)
1047 +#endif
1048 +
1049 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1050 + : "r" (&v->counter), "Ir" (i)
1051 + : "cc");
1052 +}
1053 +
1054 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1055 +{
1056 + unsigned long tmp;
1057 + int result;
1058 +
1059 + prefetchw(&v->counter);
1060 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1061 "1: ldrex %0, [%3]\n"
1062 " add %0, %0, %4\n"
1063 " strex %1, %0, [%3]\n"
1064 @@ -63,6 +117,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065 prefetchw(&v->counter);
1066
1067 __asm__ __volatile__("@ atomic_add_return\n"
1068 +"1: ldrex %1, [%3]\n"
1069 +" adds %0, %1, %4\n"
1070 +
1071 +#ifdef CONFIG_PAX_REFCOUNT
1072 +" bvc 3f\n"
1073 +" mov %0, %1\n"
1074 +"2: " REFCOUNT_TRAP_INSN "\n"
1075 +"3:\n"
1076 +#endif
1077 +
1078 +" strex %1, %0, [%3]\n"
1079 +" teq %1, #0\n"
1080 +" bne 1b"
1081 +
1082 +#ifdef CONFIG_PAX_REFCOUNT
1083 +"\n4:\n"
1084 + _ASM_EXTABLE(2b, 4b)
1085 +#endif
1086 +
1087 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1088 + : "r" (&v->counter), "Ir" (i)
1089 + : "cc");
1090 +
1091 + smp_mb();
1092 +
1093 + return result;
1094 +}
1095 +
1096 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1097 +{
1098 + unsigned long tmp;
1099 + int result;
1100 +
1101 + smp_mb();
1102 + prefetchw(&v->counter);
1103 +
1104 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1105 "1: ldrex %0, [%3]\n"
1106 " add %0, %0, %4\n"
1107 " strex %1, %0, [%3]\n"
1108 @@ -84,6 +175,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1109
1110 prefetchw(&v->counter);
1111 __asm__ __volatile__("@ atomic_sub\n"
1112 +"1: ldrex %1, [%3]\n"
1113 +" subs %0, %1, %4\n"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 +" bvc 3f\n"
1117 +"2: " REFCOUNT_TRAP_INSN "\n"
1118 +"3:\n"
1119 +#endif
1120 +
1121 +" strex %1, %0, [%3]\n"
1122 +" teq %1, #0\n"
1123 +" bne 1b"
1124 +
1125 +#ifdef CONFIG_PAX_REFCOUNT
1126 +"\n4:\n"
1127 + _ASM_EXTABLE(2b, 4b)
1128 +#endif
1129 +
1130 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1131 + : "r" (&v->counter), "Ir" (i)
1132 + : "cc");
1133 +}
1134 +
1135 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1136 +{
1137 + unsigned long tmp;
1138 + int result;
1139 +
1140 + prefetchw(&v->counter);
1141 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1142 "1: ldrex %0, [%3]\n"
1143 " sub %0, %0, %4\n"
1144 " strex %1, %0, [%3]\n"
1145 @@ -103,11 +224,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1146 prefetchw(&v->counter);
1147
1148 __asm__ __volatile__("@ atomic_sub_return\n"
1149 -"1: ldrex %0, [%3]\n"
1150 -" sub %0, %0, %4\n"
1151 +"1: ldrex %1, [%3]\n"
1152 +" subs %0, %1, %4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +" mov %0, %1\n"
1157 +"2: " REFCOUNT_TRAP_INSN "\n"
1158 +"3:\n"
1159 +#endif
1160 +
1161 " strex %1, %0, [%3]\n"
1162 " teq %1, #0\n"
1163 " bne 1b"
1164 +
1165 +#ifdef CONFIG_PAX_REFCOUNT
1166 +"\n4:\n"
1167 + _ASM_EXTABLE(2b, 4b)
1168 +#endif
1169 +
1170 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1171 : "r" (&v->counter), "Ir" (i)
1172 : "cc");
1173 @@ -152,12 +287,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1174 __asm__ __volatile__ ("@ atomic_add_unless\n"
1175 "1: ldrex %0, [%4]\n"
1176 " teq %0, %5\n"
1177 -" beq 2f\n"
1178 -" add %1, %0, %6\n"
1179 +" beq 4f\n"
1180 +" adds %1, %0, %6\n"
1181 +
1182 +#ifdef CONFIG_PAX_REFCOUNT
1183 +" bvc 3f\n"
1184 +"2: " REFCOUNT_TRAP_INSN "\n"
1185 +"3:\n"
1186 +#endif
1187 +
1188 " strex %2, %1, [%4]\n"
1189 " teq %2, #0\n"
1190 " bne 1b\n"
1191 -"2:"
1192 +"4:"
1193 +
1194 +#ifdef CONFIG_PAX_REFCOUNT
1195 + _ASM_EXTABLE(2b, 4b)
1196 +#endif
1197 +
1198 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1199 : "r" (&v->counter), "r" (u), "r" (a)
1200 : "cc");
1201 @@ -168,6 +315,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1202 return oldval;
1203 }
1204
1205 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1206 +{
1207 + unsigned long oldval, res;
1208 +
1209 + smp_mb();
1210 +
1211 + do {
1212 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1213 + "ldrex %1, [%3]\n"
1214 + "mov %0, #0\n"
1215 + "teq %1, %4\n"
1216 + "strexeq %0, %5, [%3]\n"
1217 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1218 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1219 + : "cc");
1220 + } while (res);
1221 +
1222 + smp_mb();
1223 +
1224 + return oldval;
1225 +}
1226 +
1227 #else /* ARM_ARCH_6 */
1228
1229 #ifdef CONFIG_SMP
1230 @@ -186,7 +355,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1231
1232 return val;
1233 }
1234 +
1235 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1236 +{
1237 + return atomic_add_return(i, v);
1238 +}
1239 +
1240 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1241 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1242 +{
1243 + (void) atomic_add_return(i, v);
1244 +}
1245
1246 static inline int atomic_sub_return(int i, atomic_t *v)
1247 {
1248 @@ -201,6 +380,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1249 return val;
1250 }
1251 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1252 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1253 +{
1254 + (void) atomic_sub_return(i, v);
1255 +}
1256
1257 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1258 {
1259 @@ -216,6 +399,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1260 return ret;
1261 }
1262
1263 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1264 +{
1265 + return atomic_cmpxchg(v, old, new);
1266 +}
1267 +
1268 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1269 {
1270 int c, old;
1271 @@ -229,13 +417,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1272 #endif /* __LINUX_ARM_ARCH__ */
1273
1274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1275 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1276 +{
1277 + return xchg(&v->counter, new);
1278 +}
1279
1280 #define atomic_inc(v) atomic_add(1, v)
1281 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1282 +{
1283 + atomic_add_unchecked(1, v);
1284 +}
1285 #define atomic_dec(v) atomic_sub(1, v)
1286 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1287 +{
1288 + atomic_sub_unchecked(1, v);
1289 +}
1290
1291 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1292 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1293 +{
1294 + return atomic_add_return_unchecked(1, v) == 0;
1295 +}
1296 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1297 #define atomic_inc_return(v) (atomic_add_return(1, v))
1298 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1299 +{
1300 + return atomic_add_return_unchecked(1, v);
1301 +}
1302 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1303 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1304
1305 @@ -246,6 +454,14 @@ typedef struct {
1306 long long counter;
1307 } atomic64_t;
1308
1309 +#ifdef CONFIG_PAX_REFCOUNT
1310 +typedef struct {
1311 + long long counter;
1312 +} atomic64_unchecked_t;
1313 +#else
1314 +typedef atomic64_t atomic64_unchecked_t;
1315 +#endif
1316 +
1317 #define ATOMIC64_INIT(i) { (i) }
1318
1319 #ifdef CONFIG_ARM_LPAE
1320 @@ -262,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1321 return result;
1322 }
1323
1324 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1325 +{
1326 + long long result;
1327 +
1328 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1329 +" ldrd %0, %H0, [%1]"
1330 + : "=&r" (result)
1331 + : "r" (&v->counter), "Qo" (v->counter)
1332 + );
1333 +
1334 + return result;
1335 +}
1336 +
1337 static inline void atomic64_set(atomic64_t *v, long long i)
1338 {
1339 __asm__ __volatile__("@ atomic64_set\n"
1340 @@ -270,6 +499,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1341 : "r" (&v->counter), "r" (i)
1342 );
1343 }
1344 +
1345 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1346 +{
1347 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1348 +" strd %2, %H2, [%1]"
1349 + : "=Qo" (v->counter)
1350 + : "r" (&v->counter), "r" (i)
1351 + );
1352 +}
1353 #else
1354 static inline long long atomic64_read(const atomic64_t *v)
1355 {
1356 @@ -284,6 +522,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1357 return result;
1358 }
1359
1360 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1361 +{
1362 + long long result;
1363 +
1364 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1365 +" ldrexd %0, %H0, [%1]"
1366 + : "=&r" (result)
1367 + : "r" (&v->counter), "Qo" (v->counter)
1368 + );
1369 +
1370 + return result;
1371 +}
1372 +
1373 static inline void atomic64_set(atomic64_t *v, long long i)
1374 {
1375 long long tmp;
1376 @@ -298,6 +549,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1377 : "r" (&v->counter), "r" (i)
1378 : "cc");
1379 }
1380 +
1381 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1382 +{
1383 + long long tmp;
1384 +
1385 + prefetchw(&v->counter);
1386 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1387 +"1: ldrexd %0, %H0, [%2]\n"
1388 +" strexd %0, %3, %H3, [%2]\n"
1389 +" teq %0, #0\n"
1390 +" bne 1b"
1391 + : "=&r" (tmp), "=Qo" (v->counter)
1392 + : "r" (&v->counter), "r" (i)
1393 + : "cc");
1394 +}
1395 #endif
1396
1397 static inline void atomic64_add(long long i, atomic64_t *v)
1398 @@ -309,6 +575,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1399 __asm__ __volatile__("@ atomic64_add\n"
1400 "1: ldrexd %0, %H0, [%3]\n"
1401 " adds %Q0, %Q0, %Q4\n"
1402 +" adcs %R0, %R0, %R4\n"
1403 +
1404 +#ifdef CONFIG_PAX_REFCOUNT
1405 +" bvc 3f\n"
1406 +"2: " REFCOUNT_TRAP_INSN "\n"
1407 +"3:\n"
1408 +#endif
1409 +
1410 +" strexd %1, %0, %H0, [%3]\n"
1411 +" teq %1, #0\n"
1412 +" bne 1b"
1413 +
1414 +#ifdef CONFIG_PAX_REFCOUNT
1415 +"\n4:\n"
1416 + _ASM_EXTABLE(2b, 4b)
1417 +#endif
1418 +
1419 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1420 + : "r" (&v->counter), "r" (i)
1421 + : "cc");
1422 +}
1423 +
1424 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1425 +{
1426 + long long result;
1427 + unsigned long tmp;
1428 +
1429 + prefetchw(&v->counter);
1430 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1431 +"1: ldrexd %0, %H0, [%3]\n"
1432 +" adds %Q0, %Q0, %Q4\n"
1433 " adc %R0, %R0, %R4\n"
1434 " strexd %1, %0, %H0, [%3]\n"
1435 " teq %1, #0\n"
1436 @@ -329,6 +626,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1437 __asm__ __volatile__("@ atomic64_add_return\n"
1438 "1: ldrexd %0, %H0, [%3]\n"
1439 " adds %Q0, %Q0, %Q4\n"
1440 +" adcs %R0, %R0, %R4\n"
1441 +
1442 +#ifdef CONFIG_PAX_REFCOUNT
1443 +" bvc 3f\n"
1444 +" mov %0, %1\n"
1445 +" mov %H0, %H1\n"
1446 +"2: " REFCOUNT_TRAP_INSN "\n"
1447 +"3:\n"
1448 +#endif
1449 +
1450 +" strexd %1, %0, %H0, [%3]\n"
1451 +" teq %1, #0\n"
1452 +" bne 1b"
1453 +
1454 +#ifdef CONFIG_PAX_REFCOUNT
1455 +"\n4:\n"
1456 + _ASM_EXTABLE(2b, 4b)
1457 +#endif
1458 +
1459 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1460 + : "r" (&v->counter), "r" (i)
1461 + : "cc");
1462 +
1463 + smp_mb();
1464 +
1465 + return result;
1466 +}
1467 +
1468 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1469 +{
1470 + long long result;
1471 + unsigned long tmp;
1472 +
1473 + smp_mb();
1474 +
1475 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1476 +"1: ldrexd %0, %H0, [%3]\n"
1477 +" adds %Q0, %Q0, %Q4\n"
1478 " adc %R0, %R0, %R4\n"
1479 " strexd %1, %0, %H0, [%3]\n"
1480 " teq %1, #0\n"
1481 @@ -351,6 +686,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1482 __asm__ __volatile__("@ atomic64_sub\n"
1483 "1: ldrexd %0, %H0, [%3]\n"
1484 " subs %Q0, %Q0, %Q4\n"
1485 +" sbcs %R0, %R0, %R4\n"
1486 +
1487 +#ifdef CONFIG_PAX_REFCOUNT
1488 +" bvc 3f\n"
1489 +"2: " REFCOUNT_TRAP_INSN "\n"
1490 +"3:\n"
1491 +#endif
1492 +
1493 +" strexd %1, %0, %H0, [%3]\n"
1494 +" teq %1, #0\n"
1495 +" bne 1b"
1496 +
1497 +#ifdef CONFIG_PAX_REFCOUNT
1498 +"\n4:\n"
1499 + _ASM_EXTABLE(2b, 4b)
1500 +#endif
1501 +
1502 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1503 + : "r" (&v->counter), "r" (i)
1504 + : "cc");
1505 +}
1506 +
1507 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1508 +{
1509 + long long result;
1510 + unsigned long tmp;
1511 +
1512 + prefetchw(&v->counter);
1513 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1514 +"1: ldrexd %0, %H0, [%3]\n"
1515 +" subs %Q0, %Q0, %Q4\n"
1516 " sbc %R0, %R0, %R4\n"
1517 " strexd %1, %0, %H0, [%3]\n"
1518 " teq %1, #0\n"
1519 @@ -371,10 +737,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1520 __asm__ __volatile__("@ atomic64_sub_return\n"
1521 "1: ldrexd %0, %H0, [%3]\n"
1522 " subs %Q0, %Q0, %Q4\n"
1523 -" sbc %R0, %R0, %R4\n"
1524 +" sbcs %R0, %R0, %R4\n"
1525 +
1526 +#ifdef CONFIG_PAX_REFCOUNT
1527 +" bvc 3f\n"
1528 +" mov %0, %1\n"
1529 +" mov %H0, %H1\n"
1530 +"2: " REFCOUNT_TRAP_INSN "\n"
1531 +"3:\n"
1532 +#endif
1533 +
1534 " strexd %1, %0, %H0, [%3]\n"
1535 " teq %1, #0\n"
1536 " bne 1b"
1537 +
1538 +#ifdef CONFIG_PAX_REFCOUNT
1539 +"\n4:\n"
1540 + _ASM_EXTABLE(2b, 4b)
1541 +#endif
1542 +
1543 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (i)
1545 : "cc");
1546 @@ -410,6 +791,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1547 return oldval;
1548 }
1549
1550 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1551 + long long new)
1552 +{
1553 + long long oldval;
1554 + unsigned long res;
1555 +
1556 + smp_mb();
1557 +
1558 + do {
1559 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1560 + "ldrexd %1, %H1, [%3]\n"
1561 + "mov %0, #0\n"
1562 + "teq %1, %4\n"
1563 + "teqeq %H1, %H4\n"
1564 + "strexdeq %0, %5, %H5, [%3]"
1565 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1566 + : "r" (&ptr->counter), "r" (old), "r" (new)
1567 + : "cc");
1568 + } while (res);
1569 +
1570 + smp_mb();
1571 +
1572 + return oldval;
1573 +}
1574 +
1575 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1576 {
1577 long long result;
1578 @@ -435,21 +841,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1579 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1580 {
1581 long long result;
1582 - unsigned long tmp;
1583 + u64 tmp;
1584
1585 smp_mb();
1586 prefetchw(&v->counter);
1587
1588 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1589 -"1: ldrexd %0, %H0, [%3]\n"
1590 -" subs %Q0, %Q0, #1\n"
1591 -" sbc %R0, %R0, #0\n"
1592 +"1: ldrexd %1, %H1, [%3]\n"
1593 +" subs %Q0, %Q1, #1\n"
1594 +" sbcs %R0, %R1, #0\n"
1595 +
1596 +#ifdef CONFIG_PAX_REFCOUNT
1597 +" bvc 3f\n"
1598 +" mov %Q0, %Q1\n"
1599 +" mov %R0, %R1\n"
1600 +"2: " REFCOUNT_TRAP_INSN "\n"
1601 +"3:\n"
1602 +#endif
1603 +
1604 " teq %R0, #0\n"
1605 -" bmi 2f\n"
1606 +" bmi 4f\n"
1607 " strexd %1, %0, %H0, [%3]\n"
1608 " teq %1, #0\n"
1609 " bne 1b\n"
1610 -"2:"
1611 +"4:\n"
1612 +
1613 +#ifdef CONFIG_PAX_REFCOUNT
1614 + _ASM_EXTABLE(2b, 4b)
1615 +#endif
1616 +
1617 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1618 : "r" (&v->counter)
1619 : "cc");
1620 @@ -473,13 +893,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1621 " teq %0, %5\n"
1622 " teqeq %H0, %H5\n"
1623 " moveq %1, #0\n"
1624 -" beq 2f\n"
1625 +" beq 4f\n"
1626 " adds %Q0, %Q0, %Q6\n"
1627 -" adc %R0, %R0, %R6\n"
1628 +" adcs %R0, %R0, %R6\n"
1629 +
1630 +#ifdef CONFIG_PAX_REFCOUNT
1631 +" bvc 3f\n"
1632 +"2: " REFCOUNT_TRAP_INSN "\n"
1633 +"3:\n"
1634 +#endif
1635 +
1636 " strexd %2, %0, %H0, [%4]\n"
1637 " teq %2, #0\n"
1638 " bne 1b\n"
1639 -"2:"
1640 +"4:\n"
1641 +
1642 +#ifdef CONFIG_PAX_REFCOUNT
1643 + _ASM_EXTABLE(2b, 4b)
1644 +#endif
1645 +
1646 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1647 : "r" (&v->counter), "r" (u), "r" (a)
1648 : "cc");
1649 @@ -492,10 +924,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1650
1651 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1652 #define atomic64_inc(v) atomic64_add(1LL, (v))
1653 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1654 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1655 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1656 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1657 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1658 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1659 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1660 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1661 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
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 ce73ab6..7310f8a 100644
2271 --- a/arch/arm/include/asm/thread_info.h
2272 +++ b/arch/arm/include/asm/thread_info.h
2273 @@ -78,9 +78,9 @@ struct thread_info {
2274 .flags = 0, \
2275 .preempt_count = INIT_PREEMPT_COUNT, \
2276 .addr_limit = KERNEL_DS, \
2277 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2278 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2279 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2280 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2281 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2282 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2283 .restart_block = { \
2284 .fn = do_no_restart_syscall, \
2285 }, \
2286 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2287 #define TIF_SYSCALL_AUDIT 9
2288 #define TIF_SYSCALL_TRACEPOINT 10
2289 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2290 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2291 +/* within 8 bits of TIF_SYSCALL_TRACE
2292 + * to meet flexible second operand requirements
2293 + */
2294 +#define TIF_GRSEC_SETXID 12
2295 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2296 #define TIF_USING_IWMMXT 17
2297 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2298 #define TIF_RESTORE_SIGMASK 20
2299 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2300 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2301 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2302 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2303 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2304
2305 /* Checks for any syscall work in entry-common.S */
2306 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2307 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2308 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2309
2310 /*
2311 * Change these and you break ASM code in entry-common.S
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 bea63f5..bc660a7 100644
3288 --- a/arch/arm/kernel/traps.c
3289 +++ b/arch/arm/kernel/traps.c
3290 @@ -64,7 +64,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3291 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3292 {
3293 #ifdef CONFIG_KALLSYMS
3294 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3295 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3296 #else
3297 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3298 #endif
3299 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3300 static int die_owner = -1;
3301 static unsigned int die_nest_count;
3302
3303 +extern void gr_handle_kernel_exploit(void);
3304 +
3305 static unsigned long oops_begin(void)
3306 {
3307 int cpu;
3308 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3309 panic("Fatal exception in interrupt");
3310 if (panic_on_oops)
3311 panic("Fatal exception");
3312 +
3313 + gr_handle_kernel_exploit();
3314 +
3315 if (signr)
3316 do_exit(signr);
3317 }
3318 @@ -860,7 +865,11 @@ void __init early_trap_init(void *vectors_base)
3319 kuser_init(vectors_base);
3320
3321 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3322 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3323 +
3324 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3325 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3326 +#endif
3327 +
3328 #else /* ifndef CONFIG_CPU_V7M */
3329 /*
3330 * on V7-M there is no need to copy the vector table to a dedicated
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 044b511..afd1da8 100644
3624 --- a/arch/arm/mach-mvebu/coherency.c
3625 +++ b/arch/arm/mach-mvebu/coherency.c
3626 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3627
3628 /*
3629 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3630 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3631 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3632 * is needed as a workaround for a deadlock issue between the PCIe
3633 * interface and the cache controller.
3634 */
3635 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3636 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3637
3638 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3639 - mtype = MT_UNCACHED;
3640 + mtype = MT_UNCACHED_RW;
3641
3642 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3643 }
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 b9ab717..3a15c28 100644
6981 --- a/arch/mips/include/asm/uaccess.h
6982 +++ b/arch/mips/include/asm/uaccess.h
6983 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6984 __ok == 0; \
6985 })
6986
6987 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6988 #define access_ok(type, addr, size) \
6989 likely(__access_ok((addr), (size), __access_mask))
6990
6991 @@ -301,7 +302,8 @@ do { \
6992 __get_kernel_common((x), size, __gu_ptr); \
6993 else \
6994 __get_user_common((x), size, __gu_ptr); \
6995 - } \
6996 + } else \
6997 + (x) = 0; \
6998 \
6999 __gu_err; \
7000 })
7001 @@ -316,6 +318,7 @@ do { \
7002 " .insn \n" \
7003 " .section .fixup,\"ax\" \n" \
7004 "3: li %0, %4 \n" \
7005 + " move %1, $0 \n" \
7006 " j 2b \n" \
7007 " .previous \n" \
7008 " .section __ex_table,\"a\" \n" \
7009 @@ -630,6 +633,7 @@ do { \
7010 " .insn \n" \
7011 " .section .fixup,\"ax\" \n" \
7012 "3: li %0, %4 \n" \
7013 + " move %1, $0 \n" \
7014 " j 2b \n" \
7015 " .previous \n" \
7016 " .section __ex_table,\"a\" \n" \
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 1588716..42cfa97 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..bbbff7e 100644
8173 --- a/arch/powerpc/include/asm/atomic.h
8174 +++ b/arch/powerpc/include/asm/atomic.h
8175 @@ -12,6 +12,11 @@
8176
8177 #define ATOMIC_INIT(i) { (i) }
8178
8179 +#define _ASM_EXTABLE(from, to) \
8180 +" .section __ex_table,\"a\"\n" \
8181 + PPC_LONG" " #from ", " #to"\n" \
8182 +" .previous\n"
8183 +
8184 static __inline__ int atomic_read(const atomic_t *v)
8185 {
8186 int t;
8187 @@ -21,16 +26,61 @@ static __inline__ int atomic_read(const atomic_t *v)
8188 return t;
8189 }
8190
8191 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
8192 +{
8193 + int t;
8194 +
8195 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8196 +
8197 + return t;
8198 +}
8199 +
8200 static __inline__ void atomic_set(atomic_t *v, int i)
8201 {
8202 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8203 }
8204
8205 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8206 +{
8207 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8208 +}
8209 +
8210 static __inline__ void atomic_add(int a, atomic_t *v)
8211 {
8212 int t;
8213
8214 __asm__ __volatile__(
8215 +"1: lwarx %0,0,%3 # atomic_add\n"
8216 +
8217 +#ifdef CONFIG_PAX_REFCOUNT
8218 +" mcrxr cr0\n"
8219 +" addo. %0,%2,%0\n"
8220 +" bf 4*cr0+so, 3f\n"
8221 +"2:.long " "0x00c00b00""\n"
8222 +#else
8223 +" add %0,%2,%0\n"
8224 +#endif
8225 +
8226 +"3:\n"
8227 + PPC405_ERR77(0,%3)
8228 +" stwcx. %0,0,%3 \n\
8229 + bne- 1b"
8230 +
8231 +#ifdef CONFIG_PAX_REFCOUNT
8232 +"\n4:\n"
8233 + _ASM_EXTABLE(2b, 4b)
8234 +#endif
8235 +
8236 + : "=&r" (t), "+m" (v->counter)
8237 + : "r" (a), "r" (&v->counter)
8238 + : "cc");
8239 +}
8240 +
8241 +static __inline__ void atomic_add_unchecked(int a, atomic_unchecked_t *v)
8242 +{
8243 + int t;
8244 +
8245 + __asm__ __volatile__(
8246 "1: lwarx %0,0,%3 # atomic_add\n\
8247 add %0,%2,%0\n"
8248 PPC405_ERR77(0,%3)
8249 @@ -41,12 +91,49 @@ static __inline__ void atomic_add(int a, atomic_t *v)
8250 : "cc");
8251 }
8252
8253 +/* Same as atomic_add but return the value */
8254 static __inline__ int atomic_add_return(int a, atomic_t *v)
8255 {
8256 int t;
8257
8258 __asm__ __volatile__(
8259 PPC_ATOMIC_ENTRY_BARRIER
8260 +"1: lwarx %0,0,%2 # atomic_add_return\n"
8261 +
8262 +#ifdef CONFIG_PAX_REFCOUNT
8263 +" mcrxr cr0\n"
8264 +" addo. %0,%1,%0\n"
8265 +" bf 4*cr0+so, 3f\n"
8266 +"2:.long " "0x00c00b00""\n"
8267 +#else
8268 +" add %0,%1,%0\n"
8269 +#endif
8270 +
8271 +"3:\n"
8272 + PPC405_ERR77(0,%2)
8273 +" stwcx. %0,0,%2 \n\
8274 + bne- 1b\n"
8275 +"4:"
8276 +
8277 +#ifdef CONFIG_PAX_REFCOUNT
8278 + _ASM_EXTABLE(2b, 4b)
8279 +#endif
8280 +
8281 + PPC_ATOMIC_EXIT_BARRIER
8282 + : "=&r" (t)
8283 + : "r" (a), "r" (&v->counter)
8284 + : "cc", "memory");
8285 +
8286 + return t;
8287 +}
8288 +
8289 +/* Same as atomic_add_unchecked but return the value */
8290 +static __inline__ int atomic_add_return_unchecked(int a, atomic_unchecked_t *v)
8291 +{
8292 + int t;
8293 +
8294 + __asm__ __volatile__(
8295 + PPC_ATOMIC_ENTRY_BARRIER
8296 "1: lwarx %0,0,%2 # atomic_add_return\n\
8297 add %0,%1,%0\n"
8298 PPC405_ERR77(0,%2)
8299 @@ -67,6 +154,37 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8300 int t;
8301
8302 __asm__ __volatile__(
8303 +"1: lwarx %0,0,%3 # atomic_sub\n"
8304 +
8305 +#ifdef CONFIG_PAX_REFCOUNT
8306 +" mcrxr cr0\n"
8307 +" subfo. %0,%2,%0\n"
8308 +" bf 4*cr0+so, 3f\n"
8309 +"2:.long " "0x00c00b00""\n"
8310 +#else
8311 +" subf %0,%2,%0\n"
8312 +#endif
8313 +
8314 +"3:\n"
8315 + PPC405_ERR77(0,%3)
8316 +" stwcx. %0,0,%3 \n\
8317 + bne- 1b\n"
8318 +"4:"
8319 +
8320 +#ifdef CONFIG_PAX_REFCOUNT
8321 + _ASM_EXTABLE(2b, 4b)
8322 +#endif
8323 +
8324 + : "=&r" (t), "+m" (v->counter)
8325 + : "r" (a), "r" (&v->counter)
8326 + : "cc");
8327 +}
8328 +
8329 +static __inline__ void atomic_sub_unchecked(int a, atomic_unchecked_t *v)
8330 +{
8331 + int t;
8332 +
8333 + __asm__ __volatile__(
8334 "1: lwarx %0,0,%3 # atomic_sub\n\
8335 subf %0,%2,%0\n"
8336 PPC405_ERR77(0,%3)
8337 @@ -77,12 +195,49 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8338 : "cc");
8339 }
8340
8341 +/* Same as atomic_sub but return the value */
8342 static __inline__ int atomic_sub_return(int a, atomic_t *v)
8343 {
8344 int t;
8345
8346 __asm__ __volatile__(
8347 PPC_ATOMIC_ENTRY_BARRIER
8348 +"1: lwarx %0,0,%2 # atomic_sub_return\n"
8349 +
8350 +#ifdef CONFIG_PAX_REFCOUNT
8351 +" mcrxr cr0\n"
8352 +" subfo. %0,%1,%0\n"
8353 +" bf 4*cr0+so, 3f\n"
8354 +"2:.long " "0x00c00b00""\n"
8355 +#else
8356 +" subf %0,%1,%0\n"
8357 +#endif
8358 +
8359 +"3:\n"
8360 + PPC405_ERR77(0,%2)
8361 +" stwcx. %0,0,%2 \n\
8362 + bne- 1b\n"
8363 + PPC_ATOMIC_EXIT_BARRIER
8364 +"4:"
8365 +
8366 +#ifdef CONFIG_PAX_REFCOUNT
8367 + _ASM_EXTABLE(2b, 4b)
8368 +#endif
8369 +
8370 + : "=&r" (t)
8371 + : "r" (a), "r" (&v->counter)
8372 + : "cc", "memory");
8373 +
8374 + return t;
8375 +}
8376 +
8377 +/* Same as atomic_sub_unchecked but return the value */
8378 +static __inline__ int atomic_sub_return_unchecked(int a, atomic_unchecked_t *v)
8379 +{
8380 + int t;
8381 +
8382 + __asm__ __volatile__(
8383 + PPC_ATOMIC_ENTRY_BARRIER
8384 "1: lwarx %0,0,%2 # atomic_sub_return\n\
8385 subf %0,%1,%0\n"
8386 PPC405_ERR77(0,%2)
8387 @@ -96,38 +251,23 @@ static __inline__ int atomic_sub_return(int a, atomic_t *v)
8388 return t;
8389 }
8390
8391 -static __inline__ void atomic_inc(atomic_t *v)
8392 -{
8393 - int t;
8394 +/*
8395 + * atomic_inc - increment atomic variable
8396 + * @v: pointer of type atomic_t
8397 + *
8398 + * Automatically increments @v by 1
8399 + */
8400 +#define atomic_inc(v) atomic_add(1, (v))
8401 +#define atomic_inc_return(v) atomic_add_return(1, (v))
8402
8403 - __asm__ __volatile__(
8404 -"1: lwarx %0,0,%2 # atomic_inc\n\
8405 - addic %0,%0,1\n"
8406 - PPC405_ERR77(0,%2)
8407 -" stwcx. %0,0,%2 \n\
8408 - bne- 1b"
8409 - : "=&r" (t), "+m" (v->counter)
8410 - : "r" (&v->counter)
8411 - : "cc", "xer");
8412 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
8413 +{
8414 + atomic_add_unchecked(1, v);
8415 }
8416
8417 -static __inline__ int atomic_inc_return(atomic_t *v)
8418 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8419 {
8420 - int t;
8421 -
8422 - __asm__ __volatile__(
8423 - PPC_ATOMIC_ENTRY_BARRIER
8424 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
8425 - addic %0,%0,1\n"
8426 - PPC405_ERR77(0,%1)
8427 -" stwcx. %0,0,%1 \n\
8428 - bne- 1b"
8429 - PPC_ATOMIC_EXIT_BARRIER
8430 - : "=&r" (t)
8431 - : "r" (&v->counter)
8432 - : "cc", "xer", "memory");
8433 -
8434 - return t;
8435 + return atomic_add_return_unchecked(1, v);
8436 }
8437
8438 /*
8439 @@ -140,43 +280,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
8440 */
8441 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8442
8443 -static __inline__ void atomic_dec(atomic_t *v)
8444 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8445 {
8446 - int t;
8447 -
8448 - __asm__ __volatile__(
8449 -"1: lwarx %0,0,%2 # atomic_dec\n\
8450 - addic %0,%0,-1\n"
8451 - PPC405_ERR77(0,%2)\
8452 -" stwcx. %0,0,%2\n\
8453 - bne- 1b"
8454 - : "=&r" (t), "+m" (v->counter)
8455 - : "r" (&v->counter)
8456 - : "cc", "xer");
8457 + return atomic_add_return_unchecked(1, v) == 0;
8458 }
8459
8460 -static __inline__ int atomic_dec_return(atomic_t *v)
8461 +/*
8462 + * atomic_dec - decrement atomic variable
8463 + * @v: pointer of type atomic_t
8464 + *
8465 + * Atomically decrements @v by 1
8466 + */
8467 +#define atomic_dec(v) atomic_sub(1, (v))
8468 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
8469 +
8470 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
8471 {
8472 - int t;
8473 -
8474 - __asm__ __volatile__(
8475 - PPC_ATOMIC_ENTRY_BARRIER
8476 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
8477 - addic %0,%0,-1\n"
8478 - PPC405_ERR77(0,%1)
8479 -" stwcx. %0,0,%1\n\
8480 - bne- 1b"
8481 - PPC_ATOMIC_EXIT_BARRIER
8482 - : "=&r" (t)
8483 - : "r" (&v->counter)
8484 - : "cc", "xer", "memory");
8485 -
8486 - return t;
8487 + atomic_sub_unchecked(1, v);
8488 }
8489
8490 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8491 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8492
8493 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8494 +{
8495 + return cmpxchg(&(v->counter), old, new);
8496 +}
8497 +
8498 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8499 +{
8500 + return xchg(&(v->counter), new);
8501 +}
8502 +
8503 /**
8504 * __atomic_add_unless - add unless the number is a given value
8505 * @v: pointer of type atomic_t
8506 @@ -194,11 +329,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
8507 PPC_ATOMIC_ENTRY_BARRIER
8508 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
8509 cmpw 0,%0,%3 \n\
8510 - beq- 2f \n\
8511 - add %0,%2,%0 \n"
8512 + beq- 2f \n"
8513 +
8514 +#ifdef CONFIG_PAX_REFCOUNT
8515 +" mcrxr cr0\n"
8516 +" addo. %0,%2,%0\n"
8517 +" bf 4*cr0+so, 4f\n"
8518 +"3:.long " "0x00c00b00""\n"
8519 +"4:\n"
8520 +#else
8521 + "add %0,%2,%0 \n"
8522 +#endif
8523 +
8524 PPC405_ERR77(0,%2)
8525 " stwcx. %0,0,%1 \n\
8526 bne- 1b \n"
8527 +"5:"
8528 +
8529 +#ifdef CONFIG_PAX_REFCOUNT
8530 + _ASM_EXTABLE(3b, 5b)
8531 +#endif
8532 +
8533 PPC_ATOMIC_EXIT_BARRIER
8534 " subf %0,%2,%0 \n\
8535 2:"
8536 @@ -271,6 +422,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8537 }
8538 #define atomic_dec_if_positive atomic_dec_if_positive
8539
8540 +#define smp_mb__before_atomic_dec() smp_mb()
8541 +#define smp_mb__after_atomic_dec() smp_mb()
8542 +#define smp_mb__before_atomic_inc() smp_mb()
8543 +#define smp_mb__after_atomic_inc() smp_mb()
8544 +
8545 #ifdef __powerpc64__
8546
8547 #define ATOMIC64_INIT(i) { (i) }
8548 @@ -284,11 +440,25 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8549 return t;
8550 }
8551
8552 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8553 +{
8554 + long t;
8555 +
8556 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8557 +
8558 + return t;
8559 +}
8560 +
8561 static __inline__ void atomic64_set(atomic64_t *v, long i)
8562 {
8563 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8564 }
8565
8566 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8567 +{
8568 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8569 +}
8570 +
8571 static __inline__ void atomic64_add(long a, atomic64_t *v)
8572 {
8573 long t;
8574 @@ -303,12 +473,76 @@ static __inline__ void atomic64_add(long a, atomic64_t *v)
8575 : "cc");
8576 }
8577
8578 +static __inline__ void atomic64_add_unchecked(long a, atomic64_unchecked_t *v)
8579 +{
8580 + long t;
8581 +
8582 + __asm__ __volatile__(
8583 +"1: ldarx %0,0,%3 # atomic64_add\n"
8584 +
8585 +#ifdef CONFIG_PAX_REFCOUNT
8586 +" mcrxr cr0\n"
8587 +" addo. %0,%2,%0\n"
8588 +" bf 4*cr0+so, 3f\n"
8589 +"2:.long " "0x00c00b00""\n"
8590 +#else
8591 +" add %0,%2,%0\n"
8592 +#endif
8593 +
8594 +"3:\n"
8595 +" stdcx. %0,0,%3 \n\
8596 + bne- 1b\n"
8597 +"4:"
8598 +
8599 +#ifdef CONFIG_PAX_REFCOUNT
8600 + _ASM_EXTABLE(2b, 4b)
8601 +#endif
8602 +
8603 + : "=&r" (t), "+m" (v->counter)
8604 + : "r" (a), "r" (&v->counter)
8605 + : "cc");
8606 +}
8607 +
8608 static __inline__ long atomic64_add_return(long a, atomic64_t *v)
8609 {
8610 long t;
8611
8612 __asm__ __volatile__(
8613 PPC_ATOMIC_ENTRY_BARRIER
8614 +"1: ldarx %0,0,%2 # atomic64_add_return\n"
8615 +
8616 +#ifdef CONFIG_PAX_REFCOUNT
8617 +" mcrxr cr0\n"
8618 +" addo. %0,%1,%0\n"
8619 +" bf 4*cr0+so, 3f\n"
8620 +"2:.long " "0x00c00b00""\n"
8621 +#else
8622 +" add %0,%1,%0\n"
8623 +#endif
8624 +
8625 +"3:\n"
8626 +" stdcx. %0,0,%2 \n\
8627 + bne- 1b\n"
8628 + PPC_ATOMIC_EXIT_BARRIER
8629 +"4:"
8630 +
8631 +#ifdef CONFIG_PAX_REFCOUNT
8632 + _ASM_EXTABLE(2b, 4b)
8633 +#endif
8634 +
8635 + : "=&r" (t)
8636 + : "r" (a), "r" (&v->counter)
8637 + : "cc", "memory");
8638 +
8639 + return t;
8640 +}
8641 +
8642 +static __inline__ long atomic64_add_return_unchecked(long a, atomic64_unchecked_t *v)
8643 +{
8644 + long t;
8645 +
8646 + __asm__ __volatile__(
8647 + PPC_ATOMIC_ENTRY_BARRIER
8648 "1: ldarx %0,0,%2 # atomic64_add_return\n\
8649 add %0,%1,%0\n\
8650 stdcx. %0,0,%2 \n\
8651 @@ -328,6 +562,36 @@ static __inline__ void atomic64_sub(long a, atomic64_t *v)
8652 long t;
8653
8654 __asm__ __volatile__(
8655 +"1: ldarx %0,0,%3 # atomic64_sub\n"
8656 +
8657 +#ifdef CONFIG_PAX_REFCOUNT
8658 +" mcrxr cr0\n"
8659 +" subfo. %0,%2,%0\n"
8660 +" bf 4*cr0+so, 3f\n"
8661 +"2:.long " "0x00c00b00""\n"
8662 +#else
8663 +" subf %0,%2,%0\n"
8664 +#endif
8665 +
8666 +"3:\n"
8667 +" stdcx. %0,0,%3 \n\
8668 + bne- 1b"
8669 +"4:"
8670 +
8671 +#ifdef CONFIG_PAX_REFCOUNT
8672 + _ASM_EXTABLE(2b, 4b)
8673 +#endif
8674 +
8675 + : "=&r" (t), "+m" (v->counter)
8676 + : "r" (a), "r" (&v->counter)
8677 + : "cc");
8678 +}
8679 +
8680 +static __inline__ void atomic64_sub_unchecked(long a, atomic64_unchecked_t *v)
8681 +{
8682 + long t;
8683 +
8684 + __asm__ __volatile__(
8685 "1: ldarx %0,0,%3 # atomic64_sub\n\
8686 subf %0,%2,%0\n\
8687 stdcx. %0,0,%3 \n\
8688 @@ -343,6 +607,40 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8689
8690 __asm__ __volatile__(
8691 PPC_ATOMIC_ENTRY_BARRIER
8692 +"1: ldarx %0,0,%2 # atomic64_sub_return\n"
8693 +
8694 +#ifdef CONFIG_PAX_REFCOUNT
8695 +" mcrxr cr0\n"
8696 +" subfo. %0,%1,%0\n"
8697 +" bf 4*cr0+so, 3f\n"
8698 +"2:.long " "0x00c00b00""\n"
8699 +#else
8700 +" subf %0,%1,%0\n"
8701 +#endif
8702 +
8703 +"3:\n"
8704 +" stdcx. %0,0,%2 \n\
8705 + bne- 1b\n"
8706 + PPC_ATOMIC_EXIT_BARRIER
8707 +"4:"
8708 +
8709 +#ifdef CONFIG_PAX_REFCOUNT
8710 + _ASM_EXTABLE(2b, 4b)
8711 +#endif
8712 +
8713 + : "=&r" (t)
8714 + : "r" (a), "r" (&v->counter)
8715 + : "cc", "memory");
8716 +
8717 + return t;
8718 +}
8719 +
8720 +static __inline__ long atomic64_sub_return_unchecked(long a, atomic64_unchecked_t *v)
8721 +{
8722 + long t;
8723 +
8724 + __asm__ __volatile__(
8725 + PPC_ATOMIC_ENTRY_BARRIER
8726 "1: ldarx %0,0,%2 # atomic64_sub_return\n\
8727 subf %0,%1,%0\n\
8728 stdcx. %0,0,%2 \n\
8729 @@ -355,36 +653,23 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8730 return t;
8731 }
8732
8733 -static __inline__ void atomic64_inc(atomic64_t *v)
8734 -{
8735 - long t;
8736 +/*
8737 + * atomic64_inc - increment atomic variable
8738 + * @v: pointer of type atomic64_t
8739 + *
8740 + * Automatically increments @v by 1
8741 + */
8742 +#define atomic64_inc(v) atomic64_add(1, (v))
8743 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8744
8745 - __asm__ __volatile__(
8746 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8747 - addic %0,%0,1\n\
8748 - stdcx. %0,0,%2 \n\
8749 - bne- 1b"
8750 - : "=&r" (t), "+m" (v->counter)
8751 - : "r" (&v->counter)
8752 - : "cc", "xer");
8753 +static __inline__ void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8754 +{
8755 + atomic64_add_unchecked(1, v);
8756 }
8757
8758 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8759 +static __inline__ long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8760 {
8761 - long t;
8762 -
8763 - __asm__ __volatile__(
8764 - PPC_ATOMIC_ENTRY_BARRIER
8765 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8766 - addic %0,%0,1\n\
8767 - stdcx. %0,0,%1 \n\
8768 - bne- 1b"
8769 - PPC_ATOMIC_EXIT_BARRIER
8770 - : "=&r" (t)
8771 - : "r" (&v->counter)
8772 - : "cc", "xer", "memory");
8773 -
8774 - return t;
8775 + return atomic64_add_return_unchecked(1, v);
8776 }
8777
8778 /*
8779 @@ -397,36 +682,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8780 */
8781 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8782
8783 -static __inline__ void atomic64_dec(atomic64_t *v)
8784 +/*
8785 + * atomic64_dec - decrement atomic variable
8786 + * @v: pointer of type atomic64_t
8787 + *
8788 + * Atomically decrements @v by 1
8789 + */
8790 +#define atomic64_dec(v) atomic64_sub(1, (v))
8791 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8792 +
8793 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8794 {
8795 - long t;
8796 -
8797 - __asm__ __volatile__(
8798 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8799 - addic %0,%0,-1\n\
8800 - stdcx. %0,0,%2\n\
8801 - bne- 1b"
8802 - : "=&r" (t), "+m" (v->counter)
8803 - : "r" (&v->counter)
8804 - : "cc", "xer");
8805 -}
8806 -
8807 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8808 -{
8809 - long t;
8810 -
8811 - __asm__ __volatile__(
8812 - PPC_ATOMIC_ENTRY_BARRIER
8813 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8814 - addic %0,%0,-1\n\
8815 - stdcx. %0,0,%1\n\
8816 - bne- 1b"
8817 - PPC_ATOMIC_EXIT_BARRIER
8818 - : "=&r" (t)
8819 - : "r" (&v->counter)
8820 - : "cc", "xer", "memory");
8821 -
8822 - return t;
8823 + atomic64_sub_unchecked(1, v);
8824 }
8825
8826 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8827 @@ -459,6 +726,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8828 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8829 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8830
8831 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8832 +{
8833 + return cmpxchg(&(v->counter), old, new);
8834 +}
8835 +
8836 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8837 +{
8838 + return xchg(&(v->counter), new);
8839 +}
8840 +
8841 /**
8842 * atomic64_add_unless - add unless the number is a given value
8843 * @v: pointer of type atomic64_t
8844 @@ -474,13 +751,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8845
8846 __asm__ __volatile__ (
8847 PPC_ATOMIC_ENTRY_BARRIER
8848 -"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8849 +"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8850 cmpd 0,%0,%3 \n\
8851 - beq- 2f \n\
8852 - add %0,%2,%0 \n"
8853 + beq- 2f \n"
8854 +
8855 +#ifdef CONFIG_PAX_REFCOUNT
8856 +" mcrxr cr0\n"
8857 +" addo. %0,%2,%0\n"
8858 +" bf 4*cr0+so, 4f\n"
8859 +"3:.long " "0x00c00b00""\n"
8860 +"4:\n"
8861 +#else
8862 + "add %0,%2,%0 \n"
8863 +#endif
8864 +
8865 " stdcx. %0,0,%1 \n\
8866 bne- 1b \n"
8867 PPC_ATOMIC_EXIT_BARRIER
8868 +"5:"
8869 +
8870 +#ifdef CONFIG_PAX_REFCOUNT
8871 + _ASM_EXTABLE(3b, 5b)
8872 +#endif
8873 +
8874 " subf %0,%2,%0 \n\
8875 2:"
8876 : "=&r" (t)
8877 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8878 index bab79a1..4a3eabc 100644
8879 --- a/arch/powerpc/include/asm/barrier.h
8880 +++ b/arch/powerpc/include/asm/barrier.h
8881 @@ -73,7 +73,7 @@
8882 do { \
8883 compiletime_assert_atomic_type(*p); \
8884 __lwsync(); \
8885 - ACCESS_ONCE(*p) = (v); \
8886 + ACCESS_ONCE_RW(*p) = (v); \
8887 } while (0)
8888
8889 #define smp_load_acquire(p) \
8890 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8891 index 34a05a1..a1f2c67 100644
8892 --- a/arch/powerpc/include/asm/cache.h
8893 +++ b/arch/powerpc/include/asm/cache.h
8894 @@ -4,6 +4,7 @@
8895 #ifdef __KERNEL__
8896
8897 #include <asm/reg.h>
8898 +#include <linux/const.h>
8899
8900 /* bytes per L1 cache line */
8901 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8902 @@ -23,7 +24,7 @@
8903 #define L1_CACHE_SHIFT 7
8904 #endif
8905
8906 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8907 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8908
8909 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8910
8911 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8912 index 888d8f3..66f581c 100644
8913 --- a/arch/powerpc/include/asm/elf.h
8914 +++ b/arch/powerpc/include/asm/elf.h
8915 @@ -28,8 +28,19 @@
8916 the loader. We need to make sure that it is out of the way of the program
8917 that it will "exec", and that there is sufficient room for the brk. */
8918
8919 -extern unsigned long randomize_et_dyn(unsigned long base);
8920 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8921 +#define ELF_ET_DYN_BASE (0x20000000)
8922 +
8923 +#ifdef CONFIG_PAX_ASLR
8924 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8925 +
8926 +#ifdef __powerpc64__
8927 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8928 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8929 +#else
8930 +#define PAX_DELTA_MMAP_LEN 15
8931 +#define PAX_DELTA_STACK_LEN 15
8932 +#endif
8933 +#endif
8934
8935 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8936
8937 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8938 (0x7ff >> (PAGE_SHIFT - 12)) : \
8939 (0x3ffff >> (PAGE_SHIFT - 12)))
8940
8941 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8942 -#define arch_randomize_brk arch_randomize_brk
8943 -
8944 -
8945 #ifdef CONFIG_SPU_BASE
8946 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8947 #define NT_SPU 1
8948 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8949 index 8196e9c..d83a9f3 100644
8950 --- a/arch/powerpc/include/asm/exec.h
8951 +++ b/arch/powerpc/include/asm/exec.h
8952 @@ -4,6 +4,6 @@
8953 #ifndef _ASM_POWERPC_EXEC_H
8954 #define _ASM_POWERPC_EXEC_H
8955
8956 -extern unsigned long arch_align_stack(unsigned long sp);
8957 +#define arch_align_stack(x) ((x) & ~0xfUL)
8958
8959 #endif /* _ASM_POWERPC_EXEC_H */
8960 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8961 index 5acabbd..7ea14fa 100644
8962 --- a/arch/powerpc/include/asm/kmap_types.h
8963 +++ b/arch/powerpc/include/asm/kmap_types.h
8964 @@ -10,7 +10,7 @@
8965 * 2 of the License, or (at your option) any later version.
8966 */
8967
8968 -#define KM_TYPE_NR 16
8969 +#define KM_TYPE_NR 17
8970
8971 #endif /* __KERNEL__ */
8972 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8973 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8974 index b8da913..c02b593 100644
8975 --- a/arch/powerpc/include/asm/local.h
8976 +++ b/arch/powerpc/include/asm/local.h
8977 @@ -9,21 +9,65 @@ typedef struct
8978 atomic_long_t a;
8979 } local_t;
8980
8981 +typedef struct
8982 +{
8983 + atomic_long_unchecked_t a;
8984 +} local_unchecked_t;
8985 +
8986 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8987
8988 #define local_read(l) atomic_long_read(&(l)->a)
8989 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8990 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8991 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8992
8993 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8994 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8995 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8996 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8997 #define local_inc(l) atomic_long_inc(&(l)->a)
8998 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8999 #define local_dec(l) atomic_long_dec(&(l)->a)
9000 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
9001
9002 static __inline__ long local_add_return(long a, local_t *l)
9003 {
9004 long t;
9005
9006 __asm__ __volatile__(
9007 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
9008 +
9009 +#ifdef CONFIG_PAX_REFCOUNT
9010 +" mcrxr cr0\n"
9011 +" addo. %0,%1,%0\n"
9012 +" bf 4*cr0+so, 3f\n"
9013 +"2:.long " "0x00c00b00""\n"
9014 +#else
9015 +" add %0,%1,%0\n"
9016 +#endif
9017 +
9018 +"3:\n"
9019 + PPC405_ERR77(0,%2)
9020 + PPC_STLCX "%0,0,%2 \n\
9021 + bne- 1b"
9022 +
9023 +#ifdef CONFIG_PAX_REFCOUNT
9024 +"\n4:\n"
9025 + _ASM_EXTABLE(2b, 4b)
9026 +#endif
9027 +
9028 + : "=&r" (t)
9029 + : "r" (a), "r" (&(l->a.counter))
9030 + : "cc", "memory");
9031 +
9032 + return t;
9033 +}
9034 +
9035 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
9036 +{
9037 + long t;
9038 +
9039 + __asm__ __volatile__(
9040 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
9041 add %0,%1,%0\n"
9042 PPC405_ERR77(0,%2)
9043 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
9044
9045 #define local_cmpxchg(l, o, n) \
9046 (cmpxchg_local(&((l)->a.counter), (o), (n)))
9047 +#define local_cmpxchg_unchecked(l, o, n) \
9048 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
9049 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
9050
9051 /**
9052 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
9053 index 8565c25..2865190 100644
9054 --- a/arch/powerpc/include/asm/mman.h
9055 +++ b/arch/powerpc/include/asm/mman.h
9056 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
9057 }
9058 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
9059
9060 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
9061 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
9062 {
9063 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
9064 }
9065 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
9066 index 26fe1ae..987ffc5 100644
9067 --- a/arch/powerpc/include/asm/page.h
9068 +++ b/arch/powerpc/include/asm/page.h
9069 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
9070 * and needs to be executable. This means the whole heap ends
9071 * up being executable.
9072 */
9073 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9074 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9075 +#define VM_DATA_DEFAULT_FLAGS32 \
9076 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9077 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9078
9079 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9080 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9081 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
9082 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
9083 #endif
9084
9085 +#define ktla_ktva(addr) (addr)
9086 +#define ktva_ktla(addr) (addr)
9087 +
9088 #ifndef CONFIG_PPC_BOOK3S_64
9089 /*
9090 * Use the top bit of the higher-level page table entries to indicate whether
9091 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
9092 index 88693ce..ac6f9ab 100644
9093 --- a/arch/powerpc/include/asm/page_64.h
9094 +++ b/arch/powerpc/include/asm/page_64.h
9095 @@ -153,15 +153,18 @@ do { \
9096 * stack by default, so in the absence of a PT_GNU_STACK program header
9097 * we turn execute permission off.
9098 */
9099 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9100 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9101 +#define VM_STACK_DEFAULT_FLAGS32 \
9102 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9103 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9104
9105 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9106 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9107
9108 +#ifndef CONFIG_PAX_PAGEEXEC
9109 #define VM_STACK_DEFAULT_FLAGS \
9110 (is_32bit_task() ? \
9111 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
9112 +#endif
9113
9114 #include <asm-generic/getorder.h>
9115
9116 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
9117 index 4b0be20..c15a27d 100644
9118 --- a/arch/powerpc/include/asm/pgalloc-64.h
9119 +++ b/arch/powerpc/include/asm/pgalloc-64.h
9120 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9121 #ifndef CONFIG_PPC_64K_PAGES
9122
9123 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
9124 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
9125
9126 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
9127 {
9128 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9129 pud_set(pud, (unsigned long)pmd);
9130 }
9131
9132 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9133 +{
9134 + pud_populate(mm, pud, pmd);
9135 +}
9136 +
9137 #define pmd_populate(mm, pmd, pte_page) \
9138 pmd_populate_kernel(mm, pmd, page_address(pte_page))
9139 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
9140 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
9141 #endif
9142
9143 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
9144 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9145
9146 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
9147 pte_t *pte)
9148 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
9149 index d98c1ec..9f61569 100644
9150 --- a/arch/powerpc/include/asm/pgtable.h
9151 +++ b/arch/powerpc/include/asm/pgtable.h
9152 @@ -2,6 +2,7 @@
9153 #define _ASM_POWERPC_PGTABLE_H
9154 #ifdef __KERNEL__
9155
9156 +#include <linux/const.h>
9157 #ifndef __ASSEMBLY__
9158 #include <linux/mmdebug.h>
9159 #include <asm/processor.h> /* For TASK_SIZE */
9160 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
9161 index 4aad413..85d86bf 100644
9162 --- a/arch/powerpc/include/asm/pte-hash32.h
9163 +++ b/arch/powerpc/include/asm/pte-hash32.h
9164 @@ -21,6 +21,7 @@
9165 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
9166 #define _PAGE_USER 0x004 /* usermode access allowed */
9167 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
9168 +#define _PAGE_EXEC _PAGE_GUARDED
9169 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
9170 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
9171 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
9172 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
9173 index 0c05059..7e056e4 100644
9174 --- a/arch/powerpc/include/asm/reg.h
9175 +++ b/arch/powerpc/include/asm/reg.h
9176 @@ -251,6 +251,7 @@
9177 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
9178 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
9179 #define DSISR_NOHPTE 0x40000000 /* no translation found */
9180 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
9181 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
9182 #define DSISR_ISSTORE 0x02000000 /* access was a store */
9183 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
9184 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
9185 index 5a6614a..d89995d1 100644
9186 --- a/arch/powerpc/include/asm/smp.h
9187 +++ b/arch/powerpc/include/asm/smp.h
9188 @@ -51,7 +51,7 @@ struct smp_ops_t {
9189 int (*cpu_disable)(void);
9190 void (*cpu_die)(unsigned int nr);
9191 int (*cpu_bootable)(unsigned int nr);
9192 -};
9193 +} __no_const;
9194
9195 extern void smp_send_debugger_break(void);
9196 extern void start_secondary_resume(void);
9197 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
9198 index 4dbe072..b803275 100644
9199 --- a/arch/powerpc/include/asm/spinlock.h
9200 +++ b/arch/powerpc/include/asm/spinlock.h
9201 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
9202 __asm__ __volatile__(
9203 "1: " PPC_LWARX(%0,0,%1,1) "\n"
9204 __DO_SIGN_EXTEND
9205 -" addic. %0,%0,1\n\
9206 - ble- 2f\n"
9207 +
9208 +#ifdef CONFIG_PAX_REFCOUNT
9209 +" mcrxr cr0\n"
9210 +" addico. %0,%0,1\n"
9211 +" bf 4*cr0+so, 3f\n"
9212 +"2:.long " "0x00c00b00""\n"
9213 +#else
9214 +" addic. %0,%0,1\n"
9215 +#endif
9216 +
9217 +"3:\n"
9218 + "ble- 4f\n"
9219 PPC405_ERR77(0,%1)
9220 " stwcx. %0,0,%1\n\
9221 bne- 1b\n"
9222 PPC_ACQUIRE_BARRIER
9223 -"2:" : "=&r" (tmp)
9224 +"4:"
9225 +
9226 +#ifdef CONFIG_PAX_REFCOUNT
9227 + _ASM_EXTABLE(2b,4b)
9228 +#endif
9229 +
9230 + : "=&r" (tmp)
9231 : "r" (&rw->lock)
9232 : "cr0", "xer", "memory");
9233
9234 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
9235 __asm__ __volatile__(
9236 "# read_unlock\n\t"
9237 PPC_RELEASE_BARRIER
9238 -"1: lwarx %0,0,%1\n\
9239 - addic %0,%0,-1\n"
9240 +"1: lwarx %0,0,%1\n"
9241 +
9242 +#ifdef CONFIG_PAX_REFCOUNT
9243 +" mcrxr cr0\n"
9244 +" addico. %0,%0,-1\n"
9245 +" bf 4*cr0+so, 3f\n"
9246 +"2:.long " "0x00c00b00""\n"
9247 +#else
9248 +" addic. %0,%0,-1\n"
9249 +#endif
9250 +
9251 +"3:\n"
9252 PPC405_ERR77(0,%1)
9253 " stwcx. %0,0,%1\n\
9254 bne- 1b"
9255 +
9256 +#ifdef CONFIG_PAX_REFCOUNT
9257 +"\n4:\n"
9258 + _ASM_EXTABLE(2b, 4b)
9259 +#endif
9260 +
9261 : "=&r"(tmp)
9262 : "r"(&rw->lock)
9263 : "cr0", "xer", "memory");
9264 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
9265 index b034ecd..af7e31f 100644
9266 --- a/arch/powerpc/include/asm/thread_info.h
9267 +++ b/arch/powerpc/include/asm/thread_info.h
9268 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
9269 #if defined(CONFIG_PPC64)
9270 #define TIF_ELF2ABI 18 /* function descriptors must die! */
9271 #endif
9272 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
9273 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9274
9275 /* as above, but as bit values */
9276 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9277 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
9278 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9279 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
9280 #define _TIF_NOHZ (1<<TIF_NOHZ)
9281 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9282 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
9283 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
9284 - _TIF_NOHZ)
9285 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
9286
9287 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
9288 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
9289 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
9290 index 9485b43..3bd3c16 100644
9291 --- a/arch/powerpc/include/asm/uaccess.h
9292 +++ b/arch/powerpc/include/asm/uaccess.h
9293 @@ -58,6 +58,7 @@
9294
9295 #endif
9296
9297 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9298 #define access_ok(type, addr, size) \
9299 (__chk_user_ptr(addr), \
9300 __access_ok((__force unsigned long)(addr), (size), get_fs()))
9301 @@ -318,52 +319,6 @@ do { \
9302 extern unsigned long __copy_tofrom_user(void __user *to,
9303 const void __user *from, unsigned long size);
9304
9305 -#ifndef __powerpc64__
9306 -
9307 -static inline unsigned long copy_from_user(void *to,
9308 - const void __user *from, unsigned long n)
9309 -{
9310 - unsigned long over;
9311 -
9312 - if (access_ok(VERIFY_READ, from, n))
9313 - return __copy_tofrom_user((__force void __user *)to, from, n);
9314 - if ((unsigned long)from < TASK_SIZE) {
9315 - over = (unsigned long)from + n - TASK_SIZE;
9316 - return __copy_tofrom_user((__force void __user *)to, from,
9317 - n - over) + over;
9318 - }
9319 - return n;
9320 -}
9321 -
9322 -static inline unsigned long copy_to_user(void __user *to,
9323 - const void *from, unsigned long n)
9324 -{
9325 - unsigned long over;
9326 -
9327 - if (access_ok(VERIFY_WRITE, to, n))
9328 - return __copy_tofrom_user(to, (__force void __user *)from, n);
9329 - if ((unsigned long)to < TASK_SIZE) {
9330 - over = (unsigned long)to + n - TASK_SIZE;
9331 - return __copy_tofrom_user(to, (__force void __user *)from,
9332 - n - over) + over;
9333 - }
9334 - return n;
9335 -}
9336 -
9337 -#else /* __powerpc64__ */
9338 -
9339 -#define __copy_in_user(to, from, size) \
9340 - __copy_tofrom_user((to), (from), (size))
9341 -
9342 -extern unsigned long copy_from_user(void *to, const void __user *from,
9343 - unsigned long n);
9344 -extern unsigned long copy_to_user(void __user *to, const void *from,
9345 - unsigned long n);
9346 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
9347 - unsigned long n);
9348 -
9349 -#endif /* __powerpc64__ */
9350 -
9351 static inline unsigned long __copy_from_user_inatomic(void *to,
9352 const void __user *from, unsigned long n)
9353 {
9354 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
9355 if (ret == 0)
9356 return 0;
9357 }
9358 +
9359 + if (!__builtin_constant_p(n))
9360 + check_object_size(to, n, false);
9361 +
9362 return __copy_tofrom_user((__force void __user *)to, from, n);
9363 }
9364
9365 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
9366 if (ret == 0)
9367 return 0;
9368 }
9369 +
9370 + if (!__builtin_constant_p(n))
9371 + check_object_size(from, n, true);
9372 +
9373 return __copy_tofrom_user(to, (__force const void __user *)from, n);
9374 }
9375
9376 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
9377 return __copy_to_user_inatomic(to, from, size);
9378 }
9379
9380 +#ifndef __powerpc64__
9381 +
9382 +static inline unsigned long __must_check copy_from_user(void *to,
9383 + const void __user *from, unsigned long n)
9384 +{
9385 + unsigned long over;
9386 +
9387 + if ((long)n < 0)
9388 + return n;
9389 +
9390 + if (access_ok(VERIFY_READ, from, n)) {
9391 + if (!__builtin_constant_p(n))
9392 + check_object_size(to, n, false);
9393 + return __copy_tofrom_user((__force void __user *)to, from, n);
9394 + }
9395 + if ((unsigned long)from < TASK_SIZE) {
9396 + over = (unsigned long)from + n - TASK_SIZE;
9397 + if (!__builtin_constant_p(n - over))
9398 + check_object_size(to, n - over, false);
9399 + return __copy_tofrom_user((__force void __user *)to, from,
9400 + n - over) + over;
9401 + }
9402 + return n;
9403 +}
9404 +
9405 +static inline unsigned long __must_check copy_to_user(void __user *to,
9406 + const void *from, unsigned long n)
9407 +{
9408 + unsigned long over;
9409 +
9410 + if ((long)n < 0)
9411 + return n;
9412 +
9413 + if (access_ok(VERIFY_WRITE, to, n)) {
9414 + if (!__builtin_constant_p(n))
9415 + check_object_size(from, n, true);
9416 + return __copy_tofrom_user(to, (__force void __user *)from, n);
9417 + }
9418 + if ((unsigned long)to < TASK_SIZE) {
9419 + over = (unsigned long)to + n - TASK_SIZE;
9420 + if (!__builtin_constant_p(n))
9421 + check_object_size(from, n - over, true);
9422 + return __copy_tofrom_user(to, (__force void __user *)from,
9423 + n - over) + over;
9424 + }
9425 + return n;
9426 +}
9427 +
9428 +#else /* __powerpc64__ */
9429 +
9430 +#define __copy_in_user(to, from, size) \
9431 + __copy_tofrom_user((to), (from), (size))
9432 +
9433 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
9434 +{
9435 + if ((long)n < 0 || n > INT_MAX)
9436 + return n;
9437 +
9438 + if (!__builtin_constant_p(n))
9439 + check_object_size(to, n, false);
9440 +
9441 + if (likely(access_ok(VERIFY_READ, from, n)))
9442 + n = __copy_from_user(to, from, n);
9443 + else
9444 + memset(to, 0, n);
9445 + return n;
9446 +}
9447 +
9448 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
9449 +{
9450 + if ((long)n < 0 || n > INT_MAX)
9451 + return n;
9452 +
9453 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
9454 + if (!__builtin_constant_p(n))
9455 + check_object_size(from, n, true);
9456 + n = __copy_to_user(to, from, n);
9457 + }
9458 + return n;
9459 +}
9460 +
9461 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
9462 + unsigned long n);
9463 +
9464 +#endif /* __powerpc64__ */
9465 +
9466 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9467
9468 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9469 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9470 index 670c312..60c2b52 100644
9471 --- a/arch/powerpc/kernel/Makefile
9472 +++ b/arch/powerpc/kernel/Makefile
9473 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9474 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9475 endif
9476
9477 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9478 +
9479 obj-y := cputable.o ptrace.o syscalls.o \
9480 irq.o align.o signal_32.o pmc.o vdso.o \
9481 process.o systbl.o idle.o \
9482 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9483 index bb9cac6..5181202 100644
9484 --- a/arch/powerpc/kernel/exceptions-64e.S
9485 +++ b/arch/powerpc/kernel/exceptions-64e.S
9486 @@ -1010,6 +1010,7 @@ storage_fault_common:
9487 std r14,_DAR(r1)
9488 std r15,_DSISR(r1)
9489 addi r3,r1,STACK_FRAME_OVERHEAD
9490 + bl save_nvgprs
9491 mr r4,r14
9492 mr r5,r15
9493 ld r14,PACA_EXGEN+EX_R14(r13)
9494 @@ -1018,8 +1019,7 @@ storage_fault_common:
9495 cmpdi r3,0
9496 bne- 1f
9497 b ret_from_except_lite
9498 -1: bl save_nvgprs
9499 - mr r5,r3
9500 +1: mr r5,r3
9501 addi r3,r1,STACK_FRAME_OVERHEAD
9502 ld r4,_DAR(r1)
9503 bl bad_page_fault
9504 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9505 index 050f79a..f385bfe 100644
9506 --- a/arch/powerpc/kernel/exceptions-64s.S
9507 +++ b/arch/powerpc/kernel/exceptions-64s.S
9508 @@ -1593,10 +1593,10 @@ handle_page_fault:
9509 11: ld r4,_DAR(r1)
9510 ld r5,_DSISR(r1)
9511 addi r3,r1,STACK_FRAME_OVERHEAD
9512 + bl save_nvgprs
9513 bl do_page_fault
9514 cmpdi r3,0
9515 beq+ 12f
9516 - bl save_nvgprs
9517 mr r5,r3
9518 addi r3,r1,STACK_FRAME_OVERHEAD
9519 lwz r4,_DAR(r1)
9520 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9521 index 4c5891d..a5d88bb 100644
9522 --- a/arch/powerpc/kernel/irq.c
9523 +++ b/arch/powerpc/kernel/irq.c
9524 @@ -461,6 +461,8 @@ void migrate_irqs(void)
9525 }
9526 #endif
9527
9528 +extern void gr_handle_kernel_exploit(void);
9529 +
9530 static inline void check_stack_overflow(void)
9531 {
9532 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9533 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
9534 printk("do_IRQ: stack overflow: %ld\n",
9535 sp - sizeof(struct thread_info));
9536 dump_stack();
9537 + gr_handle_kernel_exploit();
9538 }
9539 #endif
9540 }
9541 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9542 index 6cff040..74ac5d1b 100644
9543 --- a/arch/powerpc/kernel/module_32.c
9544 +++ b/arch/powerpc/kernel/module_32.c
9545 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9546 me->arch.core_plt_section = i;
9547 }
9548 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9549 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9550 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9551 return -ENOEXEC;
9552 }
9553
9554 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9555
9556 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9557 /* Init, or core PLT? */
9558 - if (location >= mod->module_core
9559 - && location < mod->module_core + mod->core_size)
9560 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9561 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9562 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9563 - else
9564 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9565 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9566 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9567 + else {
9568 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9569 + return ~0UL;
9570 + }
9571
9572 /* Find this entry, or if that fails, the next avail. entry */
9573 while (entry->jump[0]) {
9574 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9575 }
9576 #ifdef CONFIG_DYNAMIC_FTRACE
9577 module->arch.tramp =
9578 - do_plt_call(module->module_core,
9579 + do_plt_call(module->module_core_rx,
9580 (unsigned long)ftrace_caller,
9581 sechdrs, module);
9582 #endif
9583 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9584 index bf44ae9..6d2ce71 100644
9585 --- a/arch/powerpc/kernel/process.c
9586 +++ b/arch/powerpc/kernel/process.c
9587 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9588 * Lookup NIP late so we have the best change of getting the
9589 * above info out without failing
9590 */
9591 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9592 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9593 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9594 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9595 #endif
9596 show_stack(current, (unsigned long *) regs->gpr[1]);
9597 if (!user_mode(regs))
9598 @@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9599 newsp = stack[0];
9600 ip = stack[STACK_FRAME_LR_SAVE];
9601 if (!firstframe || ip != lr) {
9602 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9603 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9604 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9605 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9606 - printk(" (%pS)",
9607 + printk(" (%pA)",
9608 (void *)current->ret_stack[curr_frame].ret);
9609 curr_frame--;
9610 }
9611 @@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9612 struct pt_regs *regs = (struct pt_regs *)
9613 (sp + STACK_FRAME_OVERHEAD);
9614 lr = regs->link;
9615 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9616 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9617 regs->trap, (void *)regs->nip, (void *)lr);
9618 firstframe = 1;
9619 }
9620 @@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
9621 mtspr(SPRN_CTRLT, ctrl);
9622 }
9623 #endif /* CONFIG_PPC64 */
9624 -
9625 -unsigned long arch_align_stack(unsigned long sp)
9626 -{
9627 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9628 - sp -= get_random_int() & ~PAGE_MASK;
9629 - return sp & ~0xf;
9630 -}
9631 -
9632 -static inline unsigned long brk_rnd(void)
9633 -{
9634 - unsigned long rnd = 0;
9635 -
9636 - /* 8MB for 32bit, 1GB for 64bit */
9637 - if (is_32bit_task())
9638 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9639 - else
9640 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9641 -
9642 - return rnd << PAGE_SHIFT;
9643 -}
9644 -
9645 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9646 -{
9647 - unsigned long base = mm->brk;
9648 - unsigned long ret;
9649 -
9650 -#ifdef CONFIG_PPC_STD_MMU_64
9651 - /*
9652 - * If we are using 1TB segments and we are allowed to randomise
9653 - * the heap, we can put it above 1TB so it is backed by a 1TB
9654 - * segment. Otherwise the heap will be in the bottom 1TB
9655 - * which always uses 256MB segments and this may result in a
9656 - * performance penalty.
9657 - */
9658 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9659 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9660 -#endif
9661 -
9662 - ret = PAGE_ALIGN(base + brk_rnd());
9663 -
9664 - if (ret < mm->brk)
9665 - return mm->brk;
9666 -
9667 - return ret;
9668 -}
9669 -
9670 -unsigned long randomize_et_dyn(unsigned long base)
9671 -{
9672 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9673 -
9674 - if (ret < base)
9675 - return base;
9676 -
9677 - return ret;
9678 -}
9679 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9680 index 2e3d2bf..35df241 100644
9681 --- a/arch/powerpc/kernel/ptrace.c
9682 +++ b/arch/powerpc/kernel/ptrace.c
9683 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9684 return ret;
9685 }
9686
9687 +#ifdef CONFIG_GRKERNSEC_SETXID
9688 +extern void gr_delayed_cred_worker(void);
9689 +#endif
9690 +
9691 /*
9692 * We must return the syscall number to actually look up in the table.
9693 * This can be -1L to skip running any syscall at all.
9694 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9695
9696 secure_computing_strict(regs->gpr[0]);
9697
9698 +#ifdef CONFIG_GRKERNSEC_SETXID
9699 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9700 + gr_delayed_cred_worker();
9701 +#endif
9702 +
9703 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9704 tracehook_report_syscall_entry(regs))
9705 /*
9706 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9707 {
9708 int step;
9709
9710 +#ifdef CONFIG_GRKERNSEC_SETXID
9711 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9712 + gr_delayed_cred_worker();
9713 +#endif
9714 +
9715 audit_syscall_exit(regs);
9716
9717 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9718 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9719 index b171001..4ac7ac5 100644
9720 --- a/arch/powerpc/kernel/signal_32.c
9721 +++ b/arch/powerpc/kernel/signal_32.c
9722 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9723 /* Save user registers on the stack */
9724 frame = &rt_sf->uc.uc_mcontext;
9725 addr = frame;
9726 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9727 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9728 sigret = 0;
9729 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9730 } else {
9731 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9732 index 2cb0c94..c0c0bc9 100644
9733 --- a/arch/powerpc/kernel/signal_64.c
9734 +++ b/arch/powerpc/kernel/signal_64.c
9735 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9736 current->thread.fp_state.fpscr = 0;
9737
9738 /* Set up to return from userspace. */
9739 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9740 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9741 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9742 } else {
9743 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9744 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9745 index 0dc43f9..a885d33 100644
9746 --- a/arch/powerpc/kernel/traps.c
9747 +++ b/arch/powerpc/kernel/traps.c
9748 @@ -36,6 +36,7 @@
9749 #include <linux/debugfs.h>
9750 #include <linux/ratelimit.h>
9751 #include <linux/context_tracking.h>
9752 +#include <linux/uaccess.h>
9753
9754 #include <asm/emulated_ops.h>
9755 #include <asm/pgtable.h>
9756 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9757 return flags;
9758 }
9759
9760 +extern void gr_handle_kernel_exploit(void);
9761 +
9762 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9763 int signr)
9764 {
9765 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9766 panic("Fatal exception in interrupt");
9767 if (panic_on_oops)
9768 panic("Fatal exception");
9769 +
9770 + gr_handle_kernel_exploit();
9771 +
9772 do_exit(signr);
9773 }
9774
9775 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9776 enum ctx_state prev_state = exception_enter();
9777 unsigned int reason = get_reason(regs);
9778
9779 +#ifdef CONFIG_PAX_REFCOUNT
9780 + unsigned int bkpt;
9781 + const struct exception_table_entry *entry;
9782 +
9783 + if (reason & REASON_ILLEGAL) {
9784 + /* Check if PaX bad instruction */
9785 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9786 + current->thread.trap_nr = 0;
9787 + pax_report_refcount_overflow(regs);
9788 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9789 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9790 + regs->nip = entry->fixup;
9791 + return;
9792 + }
9793 + /* fixup_exception() could not handle */
9794 + goto bail;
9795 + }
9796 + }
9797 +#endif
9798 +
9799 /* We can now get here via a FP Unavailable exception if the core
9800 * has no FPU, in that case the reason flags will be 0 */
9801
9802 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9803 index f174351..5722009 100644
9804 --- a/arch/powerpc/kernel/vdso.c
9805 +++ b/arch/powerpc/kernel/vdso.c
9806 @@ -35,6 +35,7 @@
9807 #include <asm/vdso.h>
9808 #include <asm/vdso_datapage.h>
9809 #include <asm/setup.h>
9810 +#include <asm/mman.h>
9811
9812 #undef DEBUG
9813
9814 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9815 vdso_base = VDSO32_MBASE;
9816 #endif
9817
9818 - current->mm->context.vdso_base = 0;
9819 + current->mm->context.vdso_base = ~0UL;
9820
9821 /* vDSO has a problem and was disabled, just don't "enable" it for the
9822 * process
9823 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9824 vdso_base = get_unmapped_area(NULL, vdso_base,
9825 (vdso_pages << PAGE_SHIFT) +
9826 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9827 - 0, 0);
9828 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9829 if (IS_ERR_VALUE(vdso_base)) {
9830 rc = vdso_base;
9831 goto fail_mmapsem;
9832 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9833 index 4c79284..0e462c3 100644
9834 --- a/arch/powerpc/kvm/powerpc.c
9835 +++ b/arch/powerpc/kvm/powerpc.c
9836 @@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9837 }
9838 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9839
9840 -int kvm_arch_init(void *opaque)
9841 +int kvm_arch_init(const void *opaque)
9842 {
9843 return 0;
9844 }
9845 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9846 index 5eea6f3..5d10396 100644
9847 --- a/arch/powerpc/lib/usercopy_64.c
9848 +++ b/arch/powerpc/lib/usercopy_64.c
9849 @@ -9,22 +9,6 @@
9850 #include <linux/module.h>
9851 #include <asm/uaccess.h>
9852
9853 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9854 -{
9855 - if (likely(access_ok(VERIFY_READ, from, n)))
9856 - n = __copy_from_user(to, from, n);
9857 - else
9858 - memset(to, 0, n);
9859 - return n;
9860 -}
9861 -
9862 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9863 -{
9864 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9865 - n = __copy_to_user(to, from, n);
9866 - return n;
9867 -}
9868 -
9869 unsigned long copy_in_user(void __user *to, const void __user *from,
9870 unsigned long n)
9871 {
9872 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9873 return n;
9874 }
9875
9876 -EXPORT_SYMBOL(copy_from_user);
9877 -EXPORT_SYMBOL(copy_to_user);
9878 EXPORT_SYMBOL(copy_in_user);
9879
9880 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9881 index 51ab9e7..7d3c78b 100644
9882 --- a/arch/powerpc/mm/fault.c
9883 +++ b/arch/powerpc/mm/fault.c
9884 @@ -33,6 +33,10 @@
9885 #include <linux/magic.h>
9886 #include <linux/ratelimit.h>
9887 #include <linux/context_tracking.h>
9888 +#include <linux/slab.h>
9889 +#include <linux/pagemap.h>
9890 +#include <linux/compiler.h>
9891 +#include <linux/unistd.h>
9892
9893 #include <asm/firmware.h>
9894 #include <asm/page.h>
9895 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9896 }
9897 #endif
9898
9899 +#ifdef CONFIG_PAX_PAGEEXEC
9900 +/*
9901 + * PaX: decide what to do with offenders (regs->nip = fault address)
9902 + *
9903 + * returns 1 when task should be killed
9904 + */
9905 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9906 +{
9907 + return 1;
9908 +}
9909 +
9910 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9911 +{
9912 + unsigned long i;
9913 +
9914 + printk(KERN_ERR "PAX: bytes at PC: ");
9915 + for (i = 0; i < 5; i++) {
9916 + unsigned int c;
9917 + if (get_user(c, (unsigned int __user *)pc+i))
9918 + printk(KERN_CONT "???????? ");
9919 + else
9920 + printk(KERN_CONT "%08x ", c);
9921 + }
9922 + printk("\n");
9923 +}
9924 +#endif
9925 +
9926 /*
9927 * Check whether the instruction at regs->nip is a store using
9928 * an update addressing form which will update r1.
9929 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9930 * indicate errors in DSISR but can validly be set in SRR1.
9931 */
9932 if (trap == 0x400)
9933 - error_code &= 0x48200000;
9934 + error_code &= 0x58200000;
9935 else
9936 is_write = error_code & DSISR_ISSTORE;
9937 #else
9938 @@ -378,7 +409,7 @@ good_area:
9939 * "undefined". Of those that can be set, this is the only
9940 * one which seems bad.
9941 */
9942 - if (error_code & 0x10000000)
9943 + if (error_code & DSISR_GUARDED)
9944 /* Guarded storage error. */
9945 goto bad_area;
9946 #endif /* CONFIG_8xx */
9947 @@ -393,7 +424,7 @@ good_area:
9948 * processors use the same I/D cache coherency mechanism
9949 * as embedded.
9950 */
9951 - if (error_code & DSISR_PROTFAULT)
9952 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9953 goto bad_area;
9954 #endif /* CONFIG_PPC_STD_MMU */
9955
9956 @@ -483,6 +514,23 @@ bad_area:
9957 bad_area_nosemaphore:
9958 /* User mode accesses cause a SIGSEGV */
9959 if (user_mode(regs)) {
9960 +
9961 +#ifdef CONFIG_PAX_PAGEEXEC
9962 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9963 +#ifdef CONFIG_PPC_STD_MMU
9964 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9965 +#else
9966 + if (is_exec && regs->nip == address) {
9967 +#endif
9968 + switch (pax_handle_fetch_fault(regs)) {
9969 + }
9970 +
9971 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9972 + do_group_exit(SIGKILL);
9973 + }
9974 + }
9975 +#endif
9976 +
9977 _exception(SIGSEGV, regs, code, address);
9978 goto bail;
9979 }
9980 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9981 index cb8bdbe..cde4bc7 100644
9982 --- a/arch/powerpc/mm/mmap.c
9983 +++ b/arch/powerpc/mm/mmap.c
9984 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9985 return sysctl_legacy_va_layout;
9986 }
9987
9988 -static unsigned long mmap_rnd(void)
9989 +static unsigned long mmap_rnd(struct mm_struct *mm)
9990 {
9991 unsigned long rnd = 0;
9992
9993 +#ifdef CONFIG_PAX_RANDMMAP
9994 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9995 +#endif
9996 +
9997 if (current->flags & PF_RANDOMIZE) {
9998 /* 8MB for 32bit, 1GB for 64bit */
9999 if (is_32bit_task())
10000 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
10001 return rnd << PAGE_SHIFT;
10002 }
10003
10004 -static inline unsigned long mmap_base(void)
10005 +static inline unsigned long mmap_base(struct mm_struct *mm)
10006 {
10007 unsigned long gap = rlimit(RLIMIT_STACK);
10008
10009 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
10010 else if (gap > MAX_GAP)
10011 gap = MAX_GAP;
10012
10013 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
10014 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
10015 }
10016
10017 /*
10018 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10019 */
10020 if (mmap_is_legacy()) {
10021 mm->mmap_base = TASK_UNMAPPED_BASE;
10022 +
10023 +#ifdef CONFIG_PAX_RANDMMAP
10024 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10025 + mm->mmap_base += mm->delta_mmap;
10026 +#endif
10027 +
10028 mm->get_unmapped_area = arch_get_unmapped_area;
10029 } else {
10030 - mm->mmap_base = mmap_base();
10031 + mm->mmap_base = mmap_base(mm);
10032 +
10033 +#ifdef CONFIG_PAX_RANDMMAP
10034 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10035 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10036 +#endif
10037 +
10038 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10039 }
10040 }
10041 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
10042 index b0c75cc..ef7fb93 100644
10043 --- a/arch/powerpc/mm/slice.c
10044 +++ b/arch/powerpc/mm/slice.c
10045 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
10046 if ((mm->task_size - len) < addr)
10047 return 0;
10048 vma = find_vma(mm, addr);
10049 - return (!vma || (addr + len) <= vma->vm_start);
10050 + return check_heap_stack_gap(vma, addr, len, 0);
10051 }
10052
10053 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
10054 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
10055 info.align_offset = 0;
10056
10057 addr = TASK_UNMAPPED_BASE;
10058 +
10059 +#ifdef CONFIG_PAX_RANDMMAP
10060 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10061 + addr += mm->delta_mmap;
10062 +#endif
10063 +
10064 while (addr < TASK_SIZE) {
10065 info.low_limit = addr;
10066 if (!slice_scan_available(addr, available, 1, &addr))
10067 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
10068 if (fixed && addr > (mm->task_size - len))
10069 return -ENOMEM;
10070
10071 +#ifdef CONFIG_PAX_RANDMMAP
10072 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
10073 + addr = 0;
10074 +#endif
10075 +
10076 /* If hint, make sure it matches our alignment restrictions */
10077 if (!fixed && addr) {
10078 addr = _ALIGN_UP(addr, 1ul << pshift);
10079 diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
10080 index 3afa6f4..40c53ff 100644
10081 --- a/arch/powerpc/net/bpf_jit_comp.c
10082 +++ b/arch/powerpc/net/bpf_jit_comp.c
10083 @@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
10084 {
10085 if (fp->jited)
10086 module_free(NULL, fp->bpf_func);
10087 - kfree(fp);
10088 +
10089 + bpf_prog_unlock_free(fp);
10090 }
10091 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10092 index 4278acf..67fd0e6 100644
10093 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10094 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10095 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
10096 }
10097
10098 static struct pci_ops scc_pciex_pci_ops = {
10099 - scc_pciex_read_config,
10100 - scc_pciex_write_config,
10101 + .read = scc_pciex_read_config,
10102 + .write = scc_pciex_write_config,
10103 };
10104
10105 static void pciex_clear_intr_all(unsigned int __iomem *base)
10106 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
10107 index d966bbe..372124a 100644
10108 --- a/arch/powerpc/platforms/cell/spufs/file.c
10109 +++ b/arch/powerpc/platforms/cell/spufs/file.c
10110 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10111 return VM_FAULT_NOPAGE;
10112 }
10113
10114 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
10115 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
10116 unsigned long address,
10117 - void *buf, int len, int write)
10118 + void *buf, size_t len, int write)
10119 {
10120 struct spu_context *ctx = vma->vm_file->private_data;
10121 unsigned long offset = address - vma->vm_start;
10122 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
10123 index fa934fe..c296056 100644
10124 --- a/arch/s390/include/asm/atomic.h
10125 +++ b/arch/s390/include/asm/atomic.h
10126 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
10127 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
10128 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10129
10130 +#define atomic64_read_unchecked(v) atomic64_read(v)
10131 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10132 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10133 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10134 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10135 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
10136 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10137 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
10138 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10139 +
10140 #endif /* __ARCH_S390_ATOMIC__ */
10141 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
10142 index 19ff956..8d39cb1 100644
10143 --- a/arch/s390/include/asm/barrier.h
10144 +++ b/arch/s390/include/asm/barrier.h
10145 @@ -37,7 +37,7 @@
10146 do { \
10147 compiletime_assert_atomic_type(*p); \
10148 barrier(); \
10149 - ACCESS_ONCE(*p) = (v); \
10150 + ACCESS_ONCE_RW(*p) = (v); \
10151 } while (0)
10152
10153 #define smp_load_acquire(p) \
10154 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
10155 index 4d7ccac..d03d0ad 100644
10156 --- a/arch/s390/include/asm/cache.h
10157 +++ b/arch/s390/include/asm/cache.h
10158 @@ -9,8 +9,10 @@
10159 #ifndef __ARCH_S390_CACHE_H
10160 #define __ARCH_S390_CACHE_H
10161
10162 -#define L1_CACHE_BYTES 256
10163 +#include <linux/const.h>
10164 +
10165 #define L1_CACHE_SHIFT 8
10166 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10167 #define NET_SKB_PAD 32
10168
10169 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10170 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
10171 index 78f4f87..598ce39 100644
10172 --- a/arch/s390/include/asm/elf.h
10173 +++ b/arch/s390/include/asm/elf.h
10174 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
10175 the loader. We need to make sure that it is out of the way of the program
10176 that it will "exec", and that there is sufficient room for the brk. */
10177
10178 -extern unsigned long randomize_et_dyn(unsigned long base);
10179 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
10180 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
10181 +
10182 +#ifdef CONFIG_PAX_ASLR
10183 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
10184 +
10185 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10186 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10187 +#endif
10188
10189 /* This yields a mask that user programs can use to figure out what
10190 instruction set this CPU supports. */
10191 @@ -222,9 +228,6 @@ struct linux_binprm;
10192 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
10193 int arch_setup_additional_pages(struct linux_binprm *, int);
10194
10195 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10196 -#define arch_randomize_brk arch_randomize_brk
10197 -
10198 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
10199
10200 #endif
10201 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
10202 index c4a93d6..4d2a9b4 100644
10203 --- a/arch/s390/include/asm/exec.h
10204 +++ b/arch/s390/include/asm/exec.h
10205 @@ -7,6 +7,6 @@
10206 #ifndef __ASM_EXEC_H
10207 #define __ASM_EXEC_H
10208
10209 -extern unsigned long arch_align_stack(unsigned long sp);
10210 +#define arch_align_stack(x) ((x) & ~0xfUL)
10211
10212 #endif /* __ASM_EXEC_H */
10213 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
10214 index cd4c68e..6764641 100644
10215 --- a/arch/s390/include/asm/uaccess.h
10216 +++ b/arch/s390/include/asm/uaccess.h
10217 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
10218 __range_ok((unsigned long)(addr), (size)); \
10219 })
10220
10221 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
10222 #define access_ok(type, addr, size) __access_ok(addr, size)
10223
10224 /*
10225 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
10226 copy_to_user(void __user *to, const void *from, unsigned long n)
10227 {
10228 might_fault();
10229 +
10230 + if ((long)n < 0)
10231 + return n;
10232 +
10233 return __copy_to_user(to, from, n);
10234 }
10235
10236 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
10237 static inline unsigned long __must_check
10238 copy_from_user(void *to, const void __user *from, unsigned long n)
10239 {
10240 - unsigned int sz = __compiletime_object_size(to);
10241 + size_t sz = __compiletime_object_size(to);
10242
10243 might_fault();
10244 - if (unlikely(sz != -1 && sz < n)) {
10245 +
10246 + if ((long)n < 0)
10247 + return n;
10248 +
10249 + if (unlikely(sz != (size_t)-1 && sz < n)) {
10250 copy_from_user_overflow();
10251 return n;
10252 }
10253 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
10254 index b89b591..fd9609d 100644
10255 --- a/arch/s390/kernel/module.c
10256 +++ b/arch/s390/kernel/module.c
10257 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
10258
10259 /* Increase core size by size of got & plt and set start
10260 offsets for got and plt. */
10261 - me->core_size = ALIGN(me->core_size, 4);
10262 - me->arch.got_offset = me->core_size;
10263 - me->core_size += me->arch.got_size;
10264 - me->arch.plt_offset = me->core_size;
10265 - me->core_size += me->arch.plt_size;
10266 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
10267 + me->arch.got_offset = me->core_size_rw;
10268 + me->core_size_rw += me->arch.got_size;
10269 + me->arch.plt_offset = me->core_size_rx;
10270 + me->core_size_rx += me->arch.plt_size;
10271 return 0;
10272 }
10273
10274 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10275 if (info->got_initialized == 0) {
10276 Elf_Addr *gotent;
10277
10278 - gotent = me->module_core + me->arch.got_offset +
10279 + gotent = me->module_core_rw + me->arch.got_offset +
10280 info->got_offset;
10281 *gotent = val;
10282 info->got_initialized = 1;
10283 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10284 rc = apply_rela_bits(loc, val, 0, 64, 0);
10285 else if (r_type == R_390_GOTENT ||
10286 r_type == R_390_GOTPLTENT) {
10287 - val += (Elf_Addr) me->module_core - loc;
10288 + val += (Elf_Addr) me->module_core_rw - loc;
10289 rc = apply_rela_bits(loc, val, 1, 32, 1);
10290 }
10291 break;
10292 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10293 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
10294 if (info->plt_initialized == 0) {
10295 unsigned int *ip;
10296 - ip = me->module_core + me->arch.plt_offset +
10297 + ip = me->module_core_rx + me->arch.plt_offset +
10298 info->plt_offset;
10299 #ifndef CONFIG_64BIT
10300 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
10301 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10302 val - loc + 0xffffUL < 0x1ffffeUL) ||
10303 (r_type == R_390_PLT32DBL &&
10304 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
10305 - val = (Elf_Addr) me->module_core +
10306 + val = (Elf_Addr) me->module_core_rx +
10307 me->arch.plt_offset +
10308 info->plt_offset;
10309 val += rela->r_addend - loc;
10310 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10311 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
10312 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
10313 val = val + rela->r_addend -
10314 - ((Elf_Addr) me->module_core + me->arch.got_offset);
10315 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
10316 if (r_type == R_390_GOTOFF16)
10317 rc = apply_rela_bits(loc, val, 0, 16, 0);
10318 else if (r_type == R_390_GOTOFF32)
10319 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10320 break;
10321 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
10322 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
10323 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
10324 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
10325 rela->r_addend - loc;
10326 if (r_type == R_390_GOTPC)
10327 rc = apply_rela_bits(loc, val, 1, 32, 0);
10328 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
10329 index 93b9ca4..4ea1454 100644
10330 --- a/arch/s390/kernel/process.c
10331 +++ b/arch/s390/kernel/process.c
10332 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
10333 }
10334 return 0;
10335 }
10336 -
10337 -unsigned long arch_align_stack(unsigned long sp)
10338 -{
10339 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10340 - sp -= get_random_int() & ~PAGE_MASK;
10341 - return sp & ~0xf;
10342 -}
10343 -
10344 -static inline unsigned long brk_rnd(void)
10345 -{
10346 - /* 8MB for 32bit, 1GB for 64bit */
10347 - if (is_32bit_task())
10348 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
10349 - else
10350 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
10351 -}
10352 -
10353 -unsigned long arch_randomize_brk(struct mm_struct *mm)
10354 -{
10355 - unsigned long ret;
10356 -
10357 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
10358 - return (ret > mm->brk) ? ret : mm->brk;
10359 -}
10360 -
10361 -unsigned long randomize_et_dyn(unsigned long base)
10362 -{
10363 - unsigned long ret;
10364 -
10365 - if (!(current->flags & PF_RANDOMIZE))
10366 - return base;
10367 - ret = PAGE_ALIGN(base + brk_rnd());
10368 - return (ret > base) ? ret : base;
10369 -}
10370 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
10371 index 9b436c2..54fbf0a 100644
10372 --- a/arch/s390/mm/mmap.c
10373 +++ b/arch/s390/mm/mmap.c
10374 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10375 */
10376 if (mmap_is_legacy()) {
10377 mm->mmap_base = mmap_base_legacy();
10378 +
10379 +#ifdef CONFIG_PAX_RANDMMAP
10380 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10381 + mm->mmap_base += mm->delta_mmap;
10382 +#endif
10383 +
10384 mm->get_unmapped_area = arch_get_unmapped_area;
10385 } else {
10386 mm->mmap_base = mmap_base();
10387 +
10388 +#ifdef CONFIG_PAX_RANDMMAP
10389 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10390 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10391 +#endif
10392 +
10393 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10394 }
10395 }
10396 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10397 */
10398 if (mmap_is_legacy()) {
10399 mm->mmap_base = mmap_base_legacy();
10400 +
10401 +#ifdef CONFIG_PAX_RANDMMAP
10402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10403 + mm->mmap_base += mm->delta_mmap;
10404 +#endif
10405 +
10406 mm->get_unmapped_area = s390_get_unmapped_area;
10407 } else {
10408 mm->mmap_base = mmap_base();
10409 +
10410 +#ifdef CONFIG_PAX_RANDMMAP
10411 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10412 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10413 +#endif
10414 +
10415 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
10416 }
10417 }
10418 diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
10419 index 61e45b7..f2833c5 100644
10420 --- a/arch/s390/net/bpf_jit_comp.c
10421 +++ b/arch/s390/net/bpf_jit_comp.c
10422 @@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
10423 module_free(NULL, header);
10424
10425 free_filter:
10426 - kfree(fp);
10427 + bpf_prog_unlock_free(fp);
10428 }
10429 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
10430 index ae3d59f..f65f075 100644
10431 --- a/arch/score/include/asm/cache.h
10432 +++ b/arch/score/include/asm/cache.h
10433 @@ -1,7 +1,9 @@
10434 #ifndef _ASM_SCORE_CACHE_H
10435 #define _ASM_SCORE_CACHE_H
10436
10437 +#include <linux/const.h>
10438 +
10439 #define L1_CACHE_SHIFT 4
10440 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10441 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10442
10443 #endif /* _ASM_SCORE_CACHE_H */
10444 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
10445 index f9f3cd5..58ff438 100644
10446 --- a/arch/score/include/asm/exec.h
10447 +++ b/arch/score/include/asm/exec.h
10448 @@ -1,6 +1,6 @@
10449 #ifndef _ASM_SCORE_EXEC_H
10450 #define _ASM_SCORE_EXEC_H
10451
10452 -extern unsigned long arch_align_stack(unsigned long sp);
10453 +#define arch_align_stack(x) (x)
10454
10455 #endif /* _ASM_SCORE_EXEC_H */
10456 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
10457 index a1519ad3..e8ac1ff 100644
10458 --- a/arch/score/kernel/process.c
10459 +++ b/arch/score/kernel/process.c
10460 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
10461
10462 return task_pt_regs(task)->cp0_epc;
10463 }
10464 -
10465 -unsigned long arch_align_stack(unsigned long sp)
10466 -{
10467 - return sp;
10468 -}
10469 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
10470 index ef9e555..331bd29 100644
10471 --- a/arch/sh/include/asm/cache.h
10472 +++ b/arch/sh/include/asm/cache.h
10473 @@ -9,10 +9,11 @@
10474 #define __ASM_SH_CACHE_H
10475 #ifdef __KERNEL__
10476
10477 +#include <linux/const.h>
10478 #include <linux/init.h>
10479 #include <cpu/cache.h>
10480
10481 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10482 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10483
10484 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10485
10486 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
10487 index 6777177..cb5e44f 100644
10488 --- a/arch/sh/mm/mmap.c
10489 +++ b/arch/sh/mm/mmap.c
10490 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10491 struct mm_struct *mm = current->mm;
10492 struct vm_area_struct *vma;
10493 int do_colour_align;
10494 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10495 struct vm_unmapped_area_info info;
10496
10497 if (flags & MAP_FIXED) {
10498 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10499 if (filp || (flags & MAP_SHARED))
10500 do_colour_align = 1;
10501
10502 +#ifdef CONFIG_PAX_RANDMMAP
10503 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10504 +#endif
10505 +
10506 if (addr) {
10507 if (do_colour_align)
10508 addr = COLOUR_ALIGN(addr, pgoff);
10509 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10510 addr = PAGE_ALIGN(addr);
10511
10512 vma = find_vma(mm, addr);
10513 - if (TASK_SIZE - len >= addr &&
10514 - (!vma || addr + len <= vma->vm_start))
10515 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10516 return addr;
10517 }
10518
10519 info.flags = 0;
10520 info.length = len;
10521 - info.low_limit = TASK_UNMAPPED_BASE;
10522 + info.low_limit = mm->mmap_base;
10523 info.high_limit = TASK_SIZE;
10524 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10525 info.align_offset = pgoff << PAGE_SHIFT;
10526 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10527 struct mm_struct *mm = current->mm;
10528 unsigned long addr = addr0;
10529 int do_colour_align;
10530 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10531 struct vm_unmapped_area_info info;
10532
10533 if (flags & MAP_FIXED) {
10534 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10535 if (filp || (flags & MAP_SHARED))
10536 do_colour_align = 1;
10537
10538 +#ifdef CONFIG_PAX_RANDMMAP
10539 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10540 +#endif
10541 +
10542 /* requesting a specific address */
10543 if (addr) {
10544 if (do_colour_align)
10545 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10546 addr = PAGE_ALIGN(addr);
10547
10548 vma = find_vma(mm, addr);
10549 - if (TASK_SIZE - len >= addr &&
10550 - (!vma || addr + len <= vma->vm_start))
10551 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10552 return addr;
10553 }
10554
10555 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10556 VM_BUG_ON(addr != -ENOMEM);
10557 info.flags = 0;
10558 info.low_limit = TASK_UNMAPPED_BASE;
10559 +
10560 +#ifdef CONFIG_PAX_RANDMMAP
10561 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10562 + info.low_limit += mm->delta_mmap;
10563 +#endif
10564 +
10565 info.high_limit = TASK_SIZE;
10566 addr = vm_unmapped_area(&info);
10567 }
10568 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10569 index bb894c8..81b82e9 100644
10570 --- a/arch/sparc/include/asm/atomic_64.h
10571 +++ b/arch/sparc/include/asm/atomic_64.h
10572 @@ -15,18 +15,40 @@
10573 #define ATOMIC64_INIT(i) { (i) }
10574
10575 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10576 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10577 +{
10578 + return *(const volatile int *)&v->counter;
10579 +}
10580 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10581 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10582 +{
10583 + return *(const volatile long *)&v->counter;
10584 +}
10585
10586 #define atomic_set(v, i) (((v)->counter) = i)
10587 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10588 +{
10589 + v->counter = i;
10590 +}
10591 #define atomic64_set(v, i) (((v)->counter) = i)
10592 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10593 +{
10594 + v->counter = i;
10595 +}
10596
10597 void atomic_add(int, atomic_t *);
10598 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10599 void atomic64_add(long, atomic64_t *);
10600 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10601 void atomic_sub(int, atomic_t *);
10602 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10603 void atomic64_sub(long, atomic64_t *);
10604 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10605
10606 int atomic_add_ret(int, atomic_t *);
10607 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10608 long atomic64_add_ret(long, atomic64_t *);
10609 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10610 int atomic_sub_ret(int, atomic_t *);
10611 long atomic64_sub_ret(long, atomic64_t *);
10612
10613 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10614 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10615
10616 #define atomic_inc_return(v) atomic_add_ret(1, v)
10617 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10618 +{
10619 + return atomic_add_ret_unchecked(1, v);
10620 +}
10621 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10622 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10623 +{
10624 + return atomic64_add_ret_unchecked(1, v);
10625 +}
10626
10627 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10628 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10629
10630 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10631 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10632 +{
10633 + return atomic_add_ret_unchecked(i, v);
10634 +}
10635 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10636 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10637 +{
10638 + return atomic64_add_ret_unchecked(i, v);
10639 +}
10640
10641 /*
10642 * atomic_inc_and_test - increment and test
10643 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10644 * other cases.
10645 */
10646 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10647 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10648 +{
10649 + return atomic_inc_return_unchecked(v) == 0;
10650 +}
10651 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10652
10653 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10654 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10655 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10656
10657 #define atomic_inc(v) atomic_add(1, v)
10658 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10659 +{
10660 + atomic_add_unchecked(1, v);
10661 +}
10662 #define atomic64_inc(v) atomic64_add(1, v)
10663 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10664 +{
10665 + atomic64_add_unchecked(1, v);
10666 +}
10667
10668 #define atomic_dec(v) atomic_sub(1, v)
10669 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10670 +{
10671 + atomic_sub_unchecked(1, v);
10672 +}
10673 #define atomic64_dec(v) atomic64_sub(1, v)
10674 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10675 +{
10676 + atomic64_sub_unchecked(1, v);
10677 +}
10678
10679 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10680 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10681
10682 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10683 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10684 +{
10685 + return cmpxchg(&v->counter, old, new);
10686 +}
10687 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10688 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10689 +{
10690 + return xchg(&v->counter, new);
10691 +}
10692
10693 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10694 {
10695 - int c, old;
10696 + int c, old, new;
10697 c = atomic_read(v);
10698 for (;;) {
10699 - if (unlikely(c == (u)))
10700 + if (unlikely(c == u))
10701 break;
10702 - old = atomic_cmpxchg((v), c, c + (a));
10703 +
10704 + asm volatile("addcc %2, %0, %0\n"
10705 +
10706 +#ifdef CONFIG_PAX_REFCOUNT
10707 + "tvs %%icc, 6\n"
10708 +#endif
10709 +
10710 + : "=r" (new)
10711 + : "0" (c), "ir" (a)
10712 + : "cc");
10713 +
10714 + old = atomic_cmpxchg(v, c, new);
10715 if (likely(old == c))
10716 break;
10717 c = old;
10718 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10719 #define atomic64_cmpxchg(v, o, n) \
10720 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10721 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10722 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10723 +{
10724 + return xchg(&v->counter, new);
10725 +}
10726
10727 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10728 {
10729 - long c, old;
10730 + long c, old, new;
10731 c = atomic64_read(v);
10732 for (;;) {
10733 - if (unlikely(c == (u)))
10734 + if (unlikely(c == u))
10735 break;
10736 - old = atomic64_cmpxchg((v), c, c + (a));
10737 +
10738 + asm volatile("addcc %2, %0, %0\n"
10739 +
10740 +#ifdef CONFIG_PAX_REFCOUNT
10741 + "tvs %%xcc, 6\n"
10742 +#endif
10743 +
10744 + : "=r" (new)
10745 + : "0" (c), "ir" (a)
10746 + : "cc");
10747 +
10748 + old = atomic64_cmpxchg(v, c, new);
10749 if (likely(old == c))
10750 break;
10751 c = old;
10752 }
10753 - return c != (u);
10754 + return c != u;
10755 }
10756
10757 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10758 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10759 index 305dcc3..7835030 100644
10760 --- a/arch/sparc/include/asm/barrier_64.h
10761 +++ b/arch/sparc/include/asm/barrier_64.h
10762 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10763 do { \
10764 compiletime_assert_atomic_type(*p); \
10765 barrier(); \
10766 - ACCESS_ONCE(*p) = (v); \
10767 + ACCESS_ONCE_RW(*p) = (v); \
10768 } while (0)
10769
10770 #define smp_load_acquire(p) \
10771 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10772 index 5bb6991..5c2132e 100644
10773 --- a/arch/sparc/include/asm/cache.h
10774 +++ b/arch/sparc/include/asm/cache.h
10775 @@ -7,10 +7,12 @@
10776 #ifndef _SPARC_CACHE_H
10777 #define _SPARC_CACHE_H
10778
10779 +#include <linux/const.h>
10780 +
10781 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10782
10783 #define L1_CACHE_SHIFT 5
10784 -#define L1_CACHE_BYTES 32
10785 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10786
10787 #ifdef CONFIG_SPARC32
10788 #define SMP_CACHE_BYTES_SHIFT 5
10789 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10790 index a24e41f..47677ff 100644
10791 --- a/arch/sparc/include/asm/elf_32.h
10792 +++ b/arch/sparc/include/asm/elf_32.h
10793 @@ -114,6 +114,13 @@ typedef struct {
10794
10795 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10796
10797 +#ifdef CONFIG_PAX_ASLR
10798 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10799 +
10800 +#define PAX_DELTA_MMAP_LEN 16
10801 +#define PAX_DELTA_STACK_LEN 16
10802 +#endif
10803 +
10804 /* This yields a mask that user programs can use to figure out what
10805 instruction set this cpu supports. This can NOT be done in userspace
10806 on Sparc. */
10807 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10808 index 370ca1e..d4f4a98 100644
10809 --- a/arch/sparc/include/asm/elf_64.h
10810 +++ b/arch/sparc/include/asm/elf_64.h
10811 @@ -189,6 +189,13 @@ typedef struct {
10812 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10813 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10814
10815 +#ifdef CONFIG_PAX_ASLR
10816 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10817 +
10818 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10819 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10820 +#endif
10821 +
10822 extern unsigned long sparc64_elf_hwcap;
10823 #define ELF_HWCAP sparc64_elf_hwcap
10824
10825 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10826 index a3890da..f6a408e 100644
10827 --- a/arch/sparc/include/asm/pgalloc_32.h
10828 +++ b/arch/sparc/include/asm/pgalloc_32.h
10829 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10830 }
10831
10832 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10833 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10834
10835 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10836 unsigned long address)
10837 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10838 index 5e31871..13469c6 100644
10839 --- a/arch/sparc/include/asm/pgalloc_64.h
10840 +++ b/arch/sparc/include/asm/pgalloc_64.h
10841 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10842 }
10843
10844 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10845 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10846
10847 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10848 {
10849 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10850 }
10851
10852 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10853 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10854
10855 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10856 {
10857 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10858 index 59ba6f6..4518128 100644
10859 --- a/arch/sparc/include/asm/pgtable.h
10860 +++ b/arch/sparc/include/asm/pgtable.h
10861 @@ -5,4 +5,8 @@
10862 #else
10863 #include <asm/pgtable_32.h>
10864 #endif
10865 +
10866 +#define ktla_ktva(addr) (addr)
10867 +#define ktva_ktla(addr) (addr)
10868 +
10869 #endif
10870 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10871 index b9b91ae..950b91e 100644
10872 --- a/arch/sparc/include/asm/pgtable_32.h
10873 +++ b/arch/sparc/include/asm/pgtable_32.h
10874 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10875 #define PAGE_SHARED SRMMU_PAGE_SHARED
10876 #define PAGE_COPY SRMMU_PAGE_COPY
10877 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10878 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10879 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10880 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10881 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10882
10883 /* Top-level page directory - dummy used by init-mm.
10884 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10885
10886 /* xwr */
10887 #define __P000 PAGE_NONE
10888 -#define __P001 PAGE_READONLY
10889 -#define __P010 PAGE_COPY
10890 -#define __P011 PAGE_COPY
10891 +#define __P001 PAGE_READONLY_NOEXEC
10892 +#define __P010 PAGE_COPY_NOEXEC
10893 +#define __P011 PAGE_COPY_NOEXEC
10894 #define __P100 PAGE_READONLY
10895 #define __P101 PAGE_READONLY
10896 #define __P110 PAGE_COPY
10897 #define __P111 PAGE_COPY
10898
10899 #define __S000 PAGE_NONE
10900 -#define __S001 PAGE_READONLY
10901 -#define __S010 PAGE_SHARED
10902 -#define __S011 PAGE_SHARED
10903 +#define __S001 PAGE_READONLY_NOEXEC
10904 +#define __S010 PAGE_SHARED_NOEXEC
10905 +#define __S011 PAGE_SHARED_NOEXEC
10906 #define __S100 PAGE_READONLY
10907 #define __S101 PAGE_READONLY
10908 #define __S110 PAGE_SHARED
10909 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10910 index 79da178..c2eede8 100644
10911 --- a/arch/sparc/include/asm/pgtsrmmu.h
10912 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10913 @@ -115,6 +115,11 @@
10914 SRMMU_EXEC | SRMMU_REF)
10915 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10916 SRMMU_EXEC | SRMMU_REF)
10917 +
10918 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10919 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10920 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10921 +
10922 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10923 SRMMU_DIRTY | SRMMU_REF)
10924
10925 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10926 index 29d64b1..4272fe8 100644
10927 --- a/arch/sparc/include/asm/setup.h
10928 +++ b/arch/sparc/include/asm/setup.h
10929 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10930 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10931
10932 /* init_64.c */
10933 -extern atomic_t dcpage_flushes;
10934 -extern atomic_t dcpage_flushes_xcall;
10935 +extern atomic_unchecked_t dcpage_flushes;
10936 +extern atomic_unchecked_t dcpage_flushes_xcall;
10937
10938 extern int sysctl_tsb_ratio;
10939 #endif
10940 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10941 index 9689176..63c18ea 100644
10942 --- a/arch/sparc/include/asm/spinlock_64.h
10943 +++ b/arch/sparc/include/asm/spinlock_64.h
10944 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10945
10946 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10947
10948 -static void inline arch_read_lock(arch_rwlock_t *lock)
10949 +static inline void arch_read_lock(arch_rwlock_t *lock)
10950 {
10951 unsigned long tmp1, tmp2;
10952
10953 __asm__ __volatile__ (
10954 "1: ldsw [%2], %0\n"
10955 " brlz,pn %0, 2f\n"
10956 -"4: add %0, 1, %1\n"
10957 +"4: addcc %0, 1, %1\n"
10958 +
10959 +#ifdef CONFIG_PAX_REFCOUNT
10960 +" tvs %%icc, 6\n"
10961 +#endif
10962 +
10963 " cas [%2], %0, %1\n"
10964 " cmp %0, %1\n"
10965 " bne,pn %%icc, 1b\n"
10966 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10967 " .previous"
10968 : "=&r" (tmp1), "=&r" (tmp2)
10969 : "r" (lock)
10970 - : "memory");
10971 + : "memory", "cc");
10972 }
10973
10974 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10975 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10976 {
10977 int tmp1, tmp2;
10978
10979 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10980 "1: ldsw [%2], %0\n"
10981 " brlz,a,pn %0, 2f\n"
10982 " mov 0, %0\n"
10983 -" add %0, 1, %1\n"
10984 +" addcc %0, 1, %1\n"
10985 +
10986 +#ifdef CONFIG_PAX_REFCOUNT
10987 +" tvs %%icc, 6\n"
10988 +#endif
10989 +
10990 " cas [%2], %0, %1\n"
10991 " cmp %0, %1\n"
10992 " bne,pn %%icc, 1b\n"
10993 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10994 return tmp1;
10995 }
10996
10997 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10998 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10999 {
11000 unsigned long tmp1, tmp2;
11001
11002 __asm__ __volatile__(
11003 "1: lduw [%2], %0\n"
11004 -" sub %0, 1, %1\n"
11005 +" subcc %0, 1, %1\n"
11006 +
11007 +#ifdef CONFIG_PAX_REFCOUNT
11008 +" tvs %%icc, 6\n"
11009 +#endif
11010 +
11011 " cas [%2], %0, %1\n"
11012 " cmp %0, %1\n"
11013 " bne,pn %%xcc, 1b\n"
11014 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
11015 : "memory");
11016 }
11017
11018 -static void inline arch_write_lock(arch_rwlock_t *lock)
11019 +static inline void arch_write_lock(arch_rwlock_t *lock)
11020 {
11021 unsigned long mask, tmp1, tmp2;
11022
11023 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
11024 : "memory");
11025 }
11026
11027 -static void inline arch_write_unlock(arch_rwlock_t *lock)
11028 +static inline void arch_write_unlock(arch_rwlock_t *lock)
11029 {
11030 __asm__ __volatile__(
11031 " stw %%g0, [%0]"
11032 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
11033 : "memory");
11034 }
11035
11036 -static int inline arch_write_trylock(arch_rwlock_t *lock)
11037 +static inline int arch_write_trylock(arch_rwlock_t *lock)
11038 {
11039 unsigned long mask, tmp1, tmp2, result;
11040
11041 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
11042 index 96efa7a..16858bf 100644
11043 --- a/arch/sparc/include/asm/thread_info_32.h
11044 +++ b/arch/sparc/include/asm/thread_info_32.h
11045 @@ -49,6 +49,8 @@ struct thread_info {
11046 unsigned long w_saved;
11047
11048 struct restart_block restart_block;
11049 +
11050 + unsigned long lowest_stack;
11051 };
11052
11053 /*
11054 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
11055 index cc6275c..7eb8e21 100644
11056 --- a/arch/sparc/include/asm/thread_info_64.h
11057 +++ b/arch/sparc/include/asm/thread_info_64.h
11058 @@ -63,6 +63,8 @@ struct thread_info {
11059 struct pt_regs *kern_una_regs;
11060 unsigned int kern_una_insn;
11061
11062 + unsigned long lowest_stack;
11063 +
11064 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
11065 __attribute__ ((aligned(64)));
11066 };
11067 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
11068 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
11069 /* flag bit 4 is available */
11070 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
11071 -/* flag bit 6 is available */
11072 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
11073 #define TIF_32BIT 7 /* 32-bit binary */
11074 #define TIF_NOHZ 8 /* in adaptive nohz mode */
11075 #define TIF_SECCOMP 9 /* secure computing */
11076 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
11077 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
11078 +
11079 /* NOTE: Thread flags >= 12 should be ones we have no interest
11080 * in using in assembly, else we can't use the mask as
11081 * an immediate value in instructions such as andcc.
11082 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
11083 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
11084 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
11085 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
11086 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
11087
11088 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
11089 _TIF_DO_NOTIFY_RESUME_MASK | \
11090 _TIF_NEED_RESCHED)
11091 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
11092
11093 +#define _TIF_WORK_SYSCALL \
11094 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
11095 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
11096 +
11097 +
11098 /*
11099 * Thread-synchronous status.
11100 *
11101 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
11102 index bd56c28..4b63d83 100644
11103 --- a/arch/sparc/include/asm/uaccess.h
11104 +++ b/arch/sparc/include/asm/uaccess.h
11105 @@ -1,5 +1,6 @@
11106 #ifndef ___ASM_SPARC_UACCESS_H
11107 #define ___ASM_SPARC_UACCESS_H
11108 +
11109 #if defined(__sparc__) && defined(__arch64__)
11110 #include <asm/uaccess_64.h>
11111 #else
11112 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
11113 index 9634d08..f55fe4f 100644
11114 --- a/arch/sparc/include/asm/uaccess_32.h
11115 +++ b/arch/sparc/include/asm/uaccess_32.h
11116 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
11117
11118 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
11119 {
11120 - if (n && __access_ok((unsigned long) to, n))
11121 + if ((long)n < 0)
11122 + return n;
11123 +
11124 + if (n && __access_ok((unsigned long) to, n)) {
11125 + if (!__builtin_constant_p(n))
11126 + check_object_size(from, n, true);
11127 return __copy_user(to, (__force void __user *) from, n);
11128 - else
11129 + } else
11130 return n;
11131 }
11132
11133 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
11134 {
11135 + if ((long)n < 0)
11136 + return n;
11137 +
11138 + if (!__builtin_constant_p(n))
11139 + check_object_size(from, n, true);
11140 +
11141 return __copy_user(to, (__force void __user *) from, n);
11142 }
11143
11144 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
11145 {
11146 - if (n && __access_ok((unsigned long) from, n))
11147 + if ((long)n < 0)
11148 + return n;
11149 +
11150 + if (n && __access_ok((unsigned long) from, n)) {
11151 + if (!__builtin_constant_p(n))
11152 + check_object_size(to, n, false);
11153 return __copy_user((__force void __user *) to, from, n);
11154 - else
11155 + } else
11156 return n;
11157 }
11158
11159 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
11160 {
11161 + if ((long)n < 0)
11162 + return n;
11163 +
11164 return __copy_user((__force void __user *) to, from, n);
11165 }
11166
11167 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
11168 index c990a5e..f17b9c1 100644
11169 --- a/arch/sparc/include/asm/uaccess_64.h
11170 +++ b/arch/sparc/include/asm/uaccess_64.h
11171 @@ -10,6 +10,7 @@
11172 #include <linux/compiler.h>
11173 #include <linux/string.h>
11174 #include <linux/thread_info.h>
11175 +#include <linux/kernel.h>
11176 #include <asm/asi.h>
11177 #include <asm/spitfire.h>
11178 #include <asm-generic/uaccess-unaligned.h>
11179 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
11180 static inline unsigned long __must_check
11181 copy_from_user(void *to, const void __user *from, unsigned long size)
11182 {
11183 - unsigned long ret = ___copy_from_user(to, from, size);
11184 + unsigned long ret;
11185
11186 + if ((long)size < 0 || size > INT_MAX)
11187 + return size;
11188 +
11189 + if (!__builtin_constant_p(size))
11190 + check_object_size(to, size, false);
11191 +
11192 + ret = ___copy_from_user(to, from, size);
11193 if (unlikely(ret))
11194 ret = copy_from_user_fixup(to, from, size);
11195
11196 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
11197 static inline unsigned long __must_check
11198 copy_to_user(void __user *to, const void *from, unsigned long size)
11199 {
11200 - unsigned long ret = ___copy_to_user(to, from, size);
11201 + unsigned long ret;
11202
11203 + if ((long)size < 0 || size > INT_MAX)
11204 + return size;
11205 +
11206 + if (!__builtin_constant_p(size))
11207 + check_object_size(from, size, true);
11208 +
11209 + ret = ___copy_to_user(to, from, size);
11210 if (unlikely(ret))
11211 ret = copy_to_user_fixup(to, from, size);
11212 return ret;
11213 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
11214 index 7cf9c6e..6206648 100644
11215 --- a/arch/sparc/kernel/Makefile
11216 +++ b/arch/sparc/kernel/Makefile
11217 @@ -4,7 +4,7 @@
11218 #
11219
11220 asflags-y := -ansi
11221 -ccflags-y := -Werror
11222 +#ccflags-y := -Werror
11223
11224 extra-y := head_$(BITS).o
11225
11226 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
11227 index 50e7b62..79fae35 100644
11228 --- a/arch/sparc/kernel/process_32.c
11229 +++ b/arch/sparc/kernel/process_32.c
11230 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
11231
11232 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
11233 r->psr, r->pc, r->npc, r->y, print_tainted());
11234 - printk("PC: <%pS>\n", (void *) r->pc);
11235 + printk("PC: <%pA>\n", (void *) r->pc);
11236 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11237 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
11238 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
11239 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11240 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
11241 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
11242 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
11243 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
11244
11245 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11246 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
11247 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11248 rw = (struct reg_window32 *) fp;
11249 pc = rw->ins[7];
11250 printk("[%08lx : ", pc);
11251 - printk("%pS ] ", (void *) pc);
11252 + printk("%pA ] ", (void *) pc);
11253 fp = rw->ins[6];
11254 } while (++count < 16);
11255 printk("\n");
11256 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
11257 index 0be7bf9..2b1cba8 100644
11258 --- a/arch/sparc/kernel/process_64.c
11259 +++ b/arch/sparc/kernel/process_64.c
11260 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
11261 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
11262 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
11263 if (regs->tstate & TSTATE_PRIV)
11264 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
11265 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
11266 }
11267
11268 void show_regs(struct pt_regs *regs)
11269 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
11270
11271 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
11272 regs->tpc, regs->tnpc, regs->y, print_tainted());
11273 - printk("TPC: <%pS>\n", (void *) regs->tpc);
11274 + printk("TPC: <%pA>\n", (void *) regs->tpc);
11275 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
11276 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
11277 regs->u_regs[3]);
11278 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
11279 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
11280 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
11281 regs->u_regs[15]);
11282 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
11283 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
11284 show_regwindow(regs);
11285 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
11286 }
11287 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
11288 ((tp && tp->task) ? tp->task->pid : -1));
11289
11290 if (gp->tstate & TSTATE_PRIV) {
11291 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
11292 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
11293 (void *) gp->tpc,
11294 (void *) gp->o7,
11295 (void *) gp->i7,
11296 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
11297 index 79cc0d1..ec62734 100644
11298 --- a/arch/sparc/kernel/prom_common.c
11299 +++ b/arch/sparc/kernel/prom_common.c
11300 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
11301
11302 unsigned int prom_early_allocated __initdata;
11303
11304 -static struct of_pdt_ops prom_sparc_ops __initdata = {
11305 +static struct of_pdt_ops prom_sparc_ops __initconst = {
11306 .nextprop = prom_common_nextprop,
11307 .getproplen = prom_getproplen,
11308 .getproperty = prom_getproperty,
11309 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
11310 index c13c9f2..d572c34 100644
11311 --- a/arch/sparc/kernel/ptrace_64.c
11312 +++ b/arch/sparc/kernel/ptrace_64.c
11313 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
11314 return ret;
11315 }
11316
11317 +#ifdef CONFIG_GRKERNSEC_SETXID
11318 +extern void gr_delayed_cred_worker(void);
11319 +#endif
11320 +
11321 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11322 {
11323 int ret = 0;
11324 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11325 if (test_thread_flag(TIF_NOHZ))
11326 user_exit();
11327
11328 +#ifdef CONFIG_GRKERNSEC_SETXID
11329 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11330 + gr_delayed_cred_worker();
11331 +#endif
11332 +
11333 if (test_thread_flag(TIF_SYSCALL_TRACE))
11334 ret = tracehook_report_syscall_entry(regs);
11335
11336 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
11337 if (test_thread_flag(TIF_NOHZ))
11338 user_exit();
11339
11340 +#ifdef CONFIG_GRKERNSEC_SETXID
11341 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11342 + gr_delayed_cred_worker();
11343 +#endif
11344 +
11345 audit_syscall_exit(regs);
11346
11347 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
11348 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
11349 index 81954ee..6cfaa98 100644
11350 --- a/arch/sparc/kernel/smp_64.c
11351 +++ b/arch/sparc/kernel/smp_64.c
11352 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11353 return;
11354
11355 #ifdef CONFIG_DEBUG_DCFLUSH
11356 - atomic_inc(&dcpage_flushes);
11357 + atomic_inc_unchecked(&dcpage_flushes);
11358 #endif
11359
11360 this_cpu = get_cpu();
11361 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11362 xcall_deliver(data0, __pa(pg_addr),
11363 (u64) pg_addr, cpumask_of(cpu));
11364 #ifdef CONFIG_DEBUG_DCFLUSH
11365 - atomic_inc(&dcpage_flushes_xcall);
11366 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11367 #endif
11368 }
11369 }
11370 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11371 preempt_disable();
11372
11373 #ifdef CONFIG_DEBUG_DCFLUSH
11374 - atomic_inc(&dcpage_flushes);
11375 + atomic_inc_unchecked(&dcpage_flushes);
11376 #endif
11377 data0 = 0;
11378 pg_addr = page_address(page);
11379 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11380 xcall_deliver(data0, __pa(pg_addr),
11381 (u64) pg_addr, cpu_online_mask);
11382 #ifdef CONFIG_DEBUG_DCFLUSH
11383 - atomic_inc(&dcpage_flushes_xcall);
11384 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11385 #endif
11386 }
11387 __local_flush_dcache_page(page);
11388 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
11389 index 646988d..b88905f 100644
11390 --- a/arch/sparc/kernel/sys_sparc_32.c
11391 +++ b/arch/sparc/kernel/sys_sparc_32.c
11392 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11393 if (len > TASK_SIZE - PAGE_SIZE)
11394 return -ENOMEM;
11395 if (!addr)
11396 - addr = TASK_UNMAPPED_BASE;
11397 + addr = current->mm->mmap_base;
11398
11399 info.flags = 0;
11400 info.length = len;
11401 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
11402 index c85403d..6af95c9 100644
11403 --- a/arch/sparc/kernel/sys_sparc_64.c
11404 +++ b/arch/sparc/kernel/sys_sparc_64.c
11405 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11406 struct vm_area_struct * vma;
11407 unsigned long task_size = TASK_SIZE;
11408 int do_color_align;
11409 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11410 struct vm_unmapped_area_info info;
11411
11412 if (flags & MAP_FIXED) {
11413 /* We do not accept a shared mapping if it would violate
11414 * cache aliasing constraints.
11415 */
11416 - if ((flags & MAP_SHARED) &&
11417 + if ((filp || (flags & MAP_SHARED)) &&
11418 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11419 return -EINVAL;
11420 return addr;
11421 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11422 if (filp || (flags & MAP_SHARED))
11423 do_color_align = 1;
11424
11425 +#ifdef CONFIG_PAX_RANDMMAP
11426 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11427 +#endif
11428 +
11429 if (addr) {
11430 if (do_color_align)
11431 addr = COLOR_ALIGN(addr, pgoff);
11432 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11433 addr = PAGE_ALIGN(addr);
11434
11435 vma = find_vma(mm, addr);
11436 - if (task_size - len >= addr &&
11437 - (!vma || addr + len <= vma->vm_start))
11438 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11439 return addr;
11440 }
11441
11442 info.flags = 0;
11443 info.length = len;
11444 - info.low_limit = TASK_UNMAPPED_BASE;
11445 + info.low_limit = mm->mmap_base;
11446 info.high_limit = min(task_size, VA_EXCLUDE_START);
11447 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11448 info.align_offset = pgoff << PAGE_SHIFT;
11449 + info.threadstack_offset = offset;
11450 addr = vm_unmapped_area(&info);
11451
11452 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11453 VM_BUG_ON(addr != -ENOMEM);
11454 info.low_limit = VA_EXCLUDE_END;
11455 +
11456 +#ifdef CONFIG_PAX_RANDMMAP
11457 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11458 + info.low_limit += mm->delta_mmap;
11459 +#endif
11460 +
11461 info.high_limit = task_size;
11462 addr = vm_unmapped_area(&info);
11463 }
11464 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11465 unsigned long task_size = STACK_TOP32;
11466 unsigned long addr = addr0;
11467 int do_color_align;
11468 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11469 struct vm_unmapped_area_info info;
11470
11471 /* This should only ever run for 32-bit processes. */
11472 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11473 /* We do not accept a shared mapping if it would violate
11474 * cache aliasing constraints.
11475 */
11476 - if ((flags & MAP_SHARED) &&
11477 + if ((filp || (flags & MAP_SHARED)) &&
11478 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11479 return -EINVAL;
11480 return addr;
11481 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11482 if (filp || (flags & MAP_SHARED))
11483 do_color_align = 1;
11484
11485 +#ifdef CONFIG_PAX_RANDMMAP
11486 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11487 +#endif
11488 +
11489 /* requesting a specific address */
11490 if (addr) {
11491 if (do_color_align)
11492 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11493 addr = PAGE_ALIGN(addr);
11494
11495 vma = find_vma(mm, addr);
11496 - if (task_size - len >= addr &&
11497 - (!vma || addr + len <= vma->vm_start))
11498 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11499 return addr;
11500 }
11501
11502 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11503 info.high_limit = mm->mmap_base;
11504 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11505 info.align_offset = pgoff << PAGE_SHIFT;
11506 + info.threadstack_offset = offset;
11507 addr = vm_unmapped_area(&info);
11508
11509 /*
11510 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11511 VM_BUG_ON(addr != -ENOMEM);
11512 info.flags = 0;
11513 info.low_limit = TASK_UNMAPPED_BASE;
11514 +
11515 +#ifdef CONFIG_PAX_RANDMMAP
11516 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11517 + info.low_limit += mm->delta_mmap;
11518 +#endif
11519 +
11520 info.high_limit = STACK_TOP32;
11521 addr = vm_unmapped_area(&info);
11522 }
11523 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11524 EXPORT_SYMBOL(get_fb_unmapped_area);
11525
11526 /* Essentially the same as PowerPC. */
11527 -static unsigned long mmap_rnd(void)
11528 +static unsigned long mmap_rnd(struct mm_struct *mm)
11529 {
11530 unsigned long rnd = 0UL;
11531
11532 +#ifdef CONFIG_PAX_RANDMMAP
11533 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11534 +#endif
11535 +
11536 if (current->flags & PF_RANDOMIZE) {
11537 unsigned long val = get_random_int();
11538 if (test_thread_flag(TIF_32BIT))
11539 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11540
11541 void arch_pick_mmap_layout(struct mm_struct *mm)
11542 {
11543 - unsigned long random_factor = mmap_rnd();
11544 + unsigned long random_factor = mmap_rnd(mm);
11545 unsigned long gap;
11546
11547 /*
11548 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11549 gap == RLIM_INFINITY ||
11550 sysctl_legacy_va_layout) {
11551 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11552 +
11553 +#ifdef CONFIG_PAX_RANDMMAP
11554 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11555 + mm->mmap_base += mm->delta_mmap;
11556 +#endif
11557 +
11558 mm->get_unmapped_area = arch_get_unmapped_area;
11559 } else {
11560 /* We know it's 32-bit */
11561 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11562 gap = (task_size / 6 * 5);
11563
11564 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11565 +
11566 +#ifdef CONFIG_PAX_RANDMMAP
11567 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11568 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11569 +#endif
11570 +
11571 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11572 }
11573 }
11574 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11575 index 33a17e7..d87fb1f 100644
11576 --- a/arch/sparc/kernel/syscalls.S
11577 +++ b/arch/sparc/kernel/syscalls.S
11578 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11579 #endif
11580 .align 32
11581 1: ldx [%g6 + TI_FLAGS], %l5
11582 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11583 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11584 be,pt %icc, rtrap
11585 nop
11586 call syscall_trace_leave
11587 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11588
11589 srl %i3, 0, %o3 ! IEU0
11590 srl %i2, 0, %o2 ! IEU0 Group
11591 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11592 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11593 bne,pn %icc, linux_syscall_trace32 ! CTI
11594 mov %i0, %l5 ! IEU1
11595 5: call %l7 ! CTI Group brk forced
11596 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11597
11598 mov %i3, %o3 ! IEU1
11599 mov %i4, %o4 ! IEU0 Group
11600 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11601 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11602 bne,pn %icc, linux_syscall_trace ! CTI Group
11603 mov %i0, %l5 ! IEU0
11604 2: call %l7 ! CTI Group brk forced
11605 @@ -223,7 +223,7 @@ ret_sys_call:
11606
11607 cmp %o0, -ERESTART_RESTARTBLOCK
11608 bgeu,pn %xcc, 1f
11609 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11610 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11611 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11612
11613 2:
11614 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11615 index 6fd386c5..6907d81 100644
11616 --- a/arch/sparc/kernel/traps_32.c
11617 +++ b/arch/sparc/kernel/traps_32.c
11618 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11619 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11620 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11621
11622 +extern void gr_handle_kernel_exploit(void);
11623 +
11624 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11625 {
11626 static int die_counter;
11627 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11628 count++ < 30 &&
11629 (((unsigned long) rw) >= PAGE_OFFSET) &&
11630 !(((unsigned long) rw) & 0x7)) {
11631 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11632 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11633 (void *) rw->ins[7]);
11634 rw = (struct reg_window32 *)rw->ins[6];
11635 }
11636 }
11637 printk("Instruction DUMP:");
11638 instruction_dump ((unsigned long *) regs->pc);
11639 - if(regs->psr & PSR_PS)
11640 + if(regs->psr & PSR_PS) {
11641 + gr_handle_kernel_exploit();
11642 do_exit(SIGKILL);
11643 + }
11644 do_exit(SIGSEGV);
11645 }
11646
11647 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11648 index 981a769..d906eda 100644
11649 --- a/arch/sparc/kernel/traps_64.c
11650 +++ b/arch/sparc/kernel/traps_64.c
11651 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11652 i + 1,
11653 p->trapstack[i].tstate, p->trapstack[i].tpc,
11654 p->trapstack[i].tnpc, p->trapstack[i].tt);
11655 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11656 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11657 }
11658 }
11659
11660 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11661
11662 lvl -= 0x100;
11663 if (regs->tstate & TSTATE_PRIV) {
11664 +
11665 +#ifdef CONFIG_PAX_REFCOUNT
11666 + if (lvl == 6)
11667 + pax_report_refcount_overflow(regs);
11668 +#endif
11669 +
11670 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11671 die_if_kernel(buffer, regs);
11672 }
11673 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11674 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11675 {
11676 char buffer[32];
11677 -
11678 +
11679 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11680 0, lvl, SIGTRAP) == NOTIFY_STOP)
11681 return;
11682
11683 +#ifdef CONFIG_PAX_REFCOUNT
11684 + if (lvl == 6)
11685 + pax_report_refcount_overflow(regs);
11686 +#endif
11687 +
11688 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11689
11690 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11691 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11692 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11693 printk("%s" "ERROR(%d): ",
11694 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11695 - printk("TPC<%pS>\n", (void *) regs->tpc);
11696 + printk("TPC<%pA>\n", (void *) regs->tpc);
11697 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11698 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11699 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11700 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11701 smp_processor_id(),
11702 (type & 0x1) ? 'I' : 'D',
11703 regs->tpc);
11704 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11705 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11706 panic("Irrecoverable Cheetah+ parity error.");
11707 }
11708
11709 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11710 smp_processor_id(),
11711 (type & 0x1) ? 'I' : 'D',
11712 regs->tpc);
11713 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11714 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11715 }
11716
11717 struct sun4v_error_entry {
11718 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11719 /*0x38*/u64 reserved_5;
11720 };
11721
11722 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11723 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11724 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11725 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11726
11727 static const char *sun4v_err_type_to_str(u8 type)
11728 {
11729 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11730 }
11731
11732 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11733 - int cpu, const char *pfx, atomic_t *ocnt)
11734 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11735 {
11736 u64 *raw_ptr = (u64 *) ent;
11737 u32 attrs;
11738 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11739
11740 show_regs(regs);
11741
11742 - if ((cnt = atomic_read(ocnt)) != 0) {
11743 - atomic_set(ocnt, 0);
11744 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11745 + atomic_set_unchecked(ocnt, 0);
11746 wmb();
11747 printk("%s: Queue overflowed %d times.\n",
11748 pfx, cnt);
11749 @@ -2048,7 +2059,7 @@ out:
11750 */
11751 void sun4v_resum_overflow(struct pt_regs *regs)
11752 {
11753 - atomic_inc(&sun4v_resum_oflow_cnt);
11754 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11755 }
11756
11757 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11758 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11759 /* XXX Actually even this can make not that much sense. Perhaps
11760 * XXX we should just pull the plug and panic directly from here?
11761 */
11762 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11763 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11764 }
11765
11766 static void sun4v_tlb_error(struct pt_regs *regs)
11767 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11768
11769 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11770 regs->tpc, tl);
11771 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11772 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11773 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11774 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11775 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11776 (void *) regs->u_regs[UREG_I7]);
11777 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11778 "pte[%lx] error[%lx]\n",
11779 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11780
11781 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11782 regs->tpc, tl);
11783 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11784 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11785 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11786 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11787 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11788 (void *) regs->u_regs[UREG_I7]);
11789 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11790 "pte[%lx] error[%lx]\n",
11791 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11792 fp = (unsigned long)sf->fp + STACK_BIAS;
11793 }
11794
11795 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11796 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11797 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11798 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11799 int index = tsk->curr_ret_stack;
11800 if (tsk->ret_stack && index >= graph) {
11801 pc = tsk->ret_stack[index - graph].ret;
11802 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11803 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11804 graph++;
11805 }
11806 }
11807 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11808 return (struct reg_window *) (fp + STACK_BIAS);
11809 }
11810
11811 +extern void gr_handle_kernel_exploit(void);
11812 +
11813 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11814 {
11815 static int die_counter;
11816 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11817 while (rw &&
11818 count++ < 30 &&
11819 kstack_valid(tp, (unsigned long) rw)) {
11820 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11821 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11822 (void *) rw->ins[7]);
11823
11824 rw = kernel_stack_up(rw);
11825 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11826 }
11827 user_instruction_dump ((unsigned int __user *) regs->tpc);
11828 }
11829 - if (regs->tstate & TSTATE_PRIV)
11830 + if (regs->tstate & TSTATE_PRIV) {
11831 + gr_handle_kernel_exploit();
11832 do_exit(SIGKILL);
11833 + }
11834 do_exit(SIGSEGV);
11835 }
11836 EXPORT_SYMBOL(die_if_kernel);
11837 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11838 index 62098a8..547ab2c 100644
11839 --- a/arch/sparc/kernel/unaligned_64.c
11840 +++ b/arch/sparc/kernel/unaligned_64.c
11841 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11842 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11843
11844 if (__ratelimit(&ratelimit)) {
11845 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11846 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11847 regs->tpc, (void *) regs->tpc);
11848 }
11849 }
11850 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11851 index 3269b02..64f5231 100644
11852 --- a/arch/sparc/lib/Makefile
11853 +++ b/arch/sparc/lib/Makefile
11854 @@ -2,7 +2,7 @@
11855 #
11856
11857 asflags-y := -ansi -DST_DIV0=0x02
11858 -ccflags-y := -Werror
11859 +#ccflags-y := -Werror
11860
11861 lib-$(CONFIG_SPARC32) += ashrdi3.o
11862 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11863 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11864 index 85c233d..68500e0 100644
11865 --- a/arch/sparc/lib/atomic_64.S
11866 +++ b/arch/sparc/lib/atomic_64.S
11867 @@ -17,7 +17,12 @@
11868 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11869 BACKOFF_SETUP(%o2)
11870 1: lduw [%o1], %g1
11871 - add %g1, %o0, %g7
11872 + addcc %g1, %o0, %g7
11873 +
11874 +#ifdef CONFIG_PAX_REFCOUNT
11875 + tvs %icc, 6
11876 +#endif
11877 +
11878 cas [%o1], %g1, %g7
11879 cmp %g1, %g7
11880 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11881 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11882 2: BACKOFF_SPIN(%o2, %o3, 1b)
11883 ENDPROC(atomic_add)
11884
11885 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11886 + BACKOFF_SETUP(%o2)
11887 +1: lduw [%o1], %g1
11888 + add %g1, %o0, %g7
11889 + cas [%o1], %g1, %g7
11890 + cmp %g1, %g7
11891 + bne,pn %icc, 2f
11892 + nop
11893 + retl
11894 + nop
11895 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11896 +ENDPROC(atomic_add_unchecked)
11897 +
11898 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11899 BACKOFF_SETUP(%o2)
11900 1: lduw [%o1], %g1
11901 - sub %g1, %o0, %g7
11902 + subcc %g1, %o0, %g7
11903 +
11904 +#ifdef CONFIG_PAX_REFCOUNT
11905 + tvs %icc, 6
11906 +#endif
11907 +
11908 cas [%o1], %g1, %g7
11909 cmp %g1, %g7
11910 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11911 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11912 2: BACKOFF_SPIN(%o2, %o3, 1b)
11913 ENDPROC(atomic_sub)
11914
11915 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11916 + BACKOFF_SETUP(%o2)
11917 +1: lduw [%o1], %g1
11918 + sub %g1, %o0, %g7
11919 + cas [%o1], %g1, %g7
11920 + cmp %g1, %g7
11921 + bne,pn %icc, 2f
11922 + nop
11923 + retl
11924 + nop
11925 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11926 +ENDPROC(atomic_sub_unchecked)
11927 +
11928 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11929 BACKOFF_SETUP(%o2)
11930 1: lduw [%o1], %g1
11931 - add %g1, %o0, %g7
11932 + addcc %g1, %o0, %g7
11933 +
11934 +#ifdef CONFIG_PAX_REFCOUNT
11935 + tvs %icc, 6
11936 +#endif
11937 +
11938 cas [%o1], %g1, %g7
11939 cmp %g1, %g7
11940 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11941 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11942 2: BACKOFF_SPIN(%o2, %o3, 1b)
11943 ENDPROC(atomic_add_ret)
11944
11945 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11946 + BACKOFF_SETUP(%o2)
11947 +1: lduw [%o1], %g1
11948 + addcc %g1, %o0, %g7
11949 + cas [%o1], %g1, %g7
11950 + cmp %g1, %g7
11951 + bne,pn %icc, 2f
11952 + add %g7, %o0, %g7
11953 + sra %g7, 0, %o0
11954 + retl
11955 + nop
11956 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11957 +ENDPROC(atomic_add_ret_unchecked)
11958 +
11959 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11960 BACKOFF_SETUP(%o2)
11961 1: lduw [%o1], %g1
11962 - sub %g1, %o0, %g7
11963 + subcc %g1, %o0, %g7
11964 +
11965 +#ifdef CONFIG_PAX_REFCOUNT
11966 + tvs %icc, 6
11967 +#endif
11968 +
11969 cas [%o1], %g1, %g7
11970 cmp %g1, %g7
11971 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11972 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11973 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11974 BACKOFF_SETUP(%o2)
11975 1: ldx [%o1], %g1
11976 - add %g1, %o0, %g7
11977 + addcc %g1, %o0, %g7
11978 +
11979 +#ifdef CONFIG_PAX_REFCOUNT
11980 + tvs %xcc, 6
11981 +#endif
11982 +
11983 casx [%o1], %g1, %g7
11984 cmp %g1, %g7
11985 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11986 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11987 2: BACKOFF_SPIN(%o2, %o3, 1b)
11988 ENDPROC(atomic64_add)
11989
11990 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11991 + BACKOFF_SETUP(%o2)
11992 +1: ldx [%o1], %g1
11993 + addcc %g1, %o0, %g7
11994 + casx [%o1], %g1, %g7
11995 + cmp %g1, %g7
11996 + bne,pn %xcc, 2f
11997 + nop
11998 + retl
11999 + nop
12000 +2: BACKOFF_SPIN(%o2, %o3, 1b)
12001 +ENDPROC(atomic64_add_unchecked)
12002 +
12003 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
12004 BACKOFF_SETUP(%o2)
12005 1: ldx [%o1], %g1
12006 - sub %g1, %o0, %g7
12007 + subcc %g1, %o0, %g7
12008 +
12009 +#ifdef CONFIG_PAX_REFCOUNT
12010 + tvs %xcc, 6
12011 +#endif
12012 +
12013 casx [%o1], %g1, %g7
12014 cmp %g1, %g7
12015 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12016 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
12017 2: BACKOFF_SPIN(%o2, %o3, 1b)
12018 ENDPROC(atomic64_sub)
12019
12020 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
12021 + BACKOFF_SETUP(%o2)
12022 +1: ldx [%o1], %g1
12023 + subcc %g1, %o0, %g7
12024 + casx [%o1], %g1, %g7
12025 + cmp %g1, %g7
12026 + bne,pn %xcc, 2f
12027 + nop
12028 + retl
12029 + nop
12030 +2: BACKOFF_SPIN(%o2, %o3, 1b)
12031 +ENDPROC(atomic64_sub_unchecked)
12032 +
12033 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
12034 BACKOFF_SETUP(%o2)
12035 1: ldx [%o1], %g1
12036 - add %g1, %o0, %g7
12037 + addcc %g1, %o0, %g7
12038 +
12039 +#ifdef CONFIG_PAX_REFCOUNT
12040 + tvs %xcc, 6
12041 +#endif
12042 +
12043 casx [%o1], %g1, %g7
12044 cmp %g1, %g7
12045 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12046 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
12047 2: BACKOFF_SPIN(%o2, %o3, 1b)
12048 ENDPROC(atomic64_add_ret)
12049
12050 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
12051 + BACKOFF_SETUP(%o2)
12052 +1: ldx [%o1], %g1
12053 + addcc %g1, %o0, %g7
12054 + casx [%o1], %g1, %g7
12055 + cmp %g1, %g7
12056 + bne,pn %xcc, 2f
12057 + add %g7, %o0, %g7
12058 + mov %g7, %o0
12059 + retl
12060 + nop
12061 +2: BACKOFF_SPIN(%o2, %o3, 1b)
12062 +ENDPROC(atomic64_add_ret_unchecked)
12063 +
12064 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
12065 BACKOFF_SETUP(%o2)
12066 1: ldx [%o1], %g1
12067 - sub %g1, %o0, %g7
12068 + subcc %g1, %o0, %g7
12069 +
12070 +#ifdef CONFIG_PAX_REFCOUNT
12071 + tvs %xcc, 6
12072 +#endif
12073 +
12074 casx [%o1], %g1, %g7
12075 cmp %g1, %g7
12076 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12077 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
12078 index 323335b..ed85ea2 100644
12079 --- a/arch/sparc/lib/ksyms.c
12080 +++ b/arch/sparc/lib/ksyms.c
12081 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
12082
12083 /* Atomic counter implementation. */
12084 EXPORT_SYMBOL(atomic_add);
12085 +EXPORT_SYMBOL(atomic_add_unchecked);
12086 EXPORT_SYMBOL(atomic_add_ret);
12087 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
12088 EXPORT_SYMBOL(atomic_sub);
12089 +EXPORT_SYMBOL(atomic_sub_unchecked);
12090 EXPORT_SYMBOL(atomic_sub_ret);
12091 EXPORT_SYMBOL(atomic64_add);
12092 +EXPORT_SYMBOL(atomic64_add_unchecked);
12093 EXPORT_SYMBOL(atomic64_add_ret);
12094 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
12095 EXPORT_SYMBOL(atomic64_sub);
12096 +EXPORT_SYMBOL(atomic64_sub_unchecked);
12097 EXPORT_SYMBOL(atomic64_sub_ret);
12098 EXPORT_SYMBOL(atomic64_dec_if_positive);
12099
12100 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
12101 index 30c3ecc..736f015 100644
12102 --- a/arch/sparc/mm/Makefile
12103 +++ b/arch/sparc/mm/Makefile
12104 @@ -2,7 +2,7 @@
12105 #
12106
12107 asflags-y := -ansi
12108 -ccflags-y := -Werror
12109 +#ccflags-y := -Werror
12110
12111 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
12112 obj-y += fault_$(BITS).o
12113 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
12114 index 908e8c1..1524793 100644
12115 --- a/arch/sparc/mm/fault_32.c
12116 +++ b/arch/sparc/mm/fault_32.c
12117 @@ -21,6 +21,9 @@
12118 #include <linux/perf_event.h>
12119 #include <linux/interrupt.h>
12120 #include <linux/kdebug.h>
12121 +#include <linux/slab.h>
12122 +#include <linux/pagemap.h>
12123 +#include <linux/compiler.h>
12124
12125 #include <asm/page.h>
12126 #include <asm/pgtable.h>
12127 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
12128 return safe_compute_effective_address(regs, insn);
12129 }
12130
12131 +#ifdef CONFIG_PAX_PAGEEXEC
12132 +#ifdef CONFIG_PAX_DLRESOLVE
12133 +static void pax_emuplt_close(struct vm_area_struct *vma)
12134 +{
12135 + vma->vm_mm->call_dl_resolve = 0UL;
12136 +}
12137 +
12138 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12139 +{
12140 + unsigned int *kaddr;
12141 +
12142 + vmf->page = alloc_page(GFP_HIGHUSER);
12143 + if (!vmf->page)
12144 + return VM_FAULT_OOM;
12145 +
12146 + kaddr = kmap(vmf->page);
12147 + memset(kaddr, 0, PAGE_SIZE);
12148 + kaddr[0] = 0x9DE3BFA8U; /* save */
12149 + flush_dcache_page(vmf->page);
12150 + kunmap(vmf->page);
12151 + return VM_FAULT_MAJOR;
12152 +}
12153 +
12154 +static const struct vm_operations_struct pax_vm_ops = {
12155 + .close = pax_emuplt_close,
12156 + .fault = pax_emuplt_fault
12157 +};
12158 +
12159 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12160 +{
12161 + int ret;
12162 +
12163 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12164 + vma->vm_mm = current->mm;
12165 + vma->vm_start = addr;
12166 + vma->vm_end = addr + PAGE_SIZE;
12167 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12168 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12169 + vma->vm_ops = &pax_vm_ops;
12170 +
12171 + ret = insert_vm_struct(current->mm, vma);
12172 + if (ret)
12173 + return ret;
12174 +
12175 + ++current->mm->total_vm;
12176 + return 0;
12177 +}
12178 +#endif
12179 +
12180 +/*
12181 + * PaX: decide what to do with offenders (regs->pc = fault address)
12182 + *
12183 + * returns 1 when task should be killed
12184 + * 2 when patched PLT trampoline was detected
12185 + * 3 when unpatched PLT trampoline was detected
12186 + */
12187 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12188 +{
12189 +
12190 +#ifdef CONFIG_PAX_EMUPLT
12191 + int err;
12192 +
12193 + do { /* PaX: patched PLT emulation #1 */
12194 + unsigned int sethi1, sethi2, jmpl;
12195 +
12196 + err = get_user(sethi1, (unsigned int *)regs->pc);
12197 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
12198 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
12199 +
12200 + if (err)
12201 + break;
12202 +
12203 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12204 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12205 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12206 + {
12207 + unsigned int addr;
12208 +
12209 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12210 + addr = regs->u_regs[UREG_G1];
12211 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12212 + regs->pc = addr;
12213 + regs->npc = addr+4;
12214 + return 2;
12215 + }
12216 + } while (0);
12217 +
12218 + do { /* PaX: patched PLT emulation #2 */
12219 + unsigned int ba;
12220 +
12221 + err = get_user(ba, (unsigned int *)regs->pc);
12222 +
12223 + if (err)
12224 + break;
12225 +
12226 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12227 + unsigned int addr;
12228 +
12229 + if ((ba & 0xFFC00000U) == 0x30800000U)
12230 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12231 + else
12232 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12233 + regs->pc = addr;
12234 + regs->npc = addr+4;
12235 + return 2;
12236 + }
12237 + } while (0);
12238 +
12239 + do { /* PaX: patched PLT emulation #3 */
12240 + unsigned int sethi, bajmpl, nop;
12241 +
12242 + err = get_user(sethi, (unsigned int *)regs->pc);
12243 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
12244 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12245 +
12246 + if (err)
12247 + break;
12248 +
12249 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12250 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12251 + nop == 0x01000000U)
12252 + {
12253 + unsigned int addr;
12254 +
12255 + addr = (sethi & 0x003FFFFFU) << 10;
12256 + regs->u_regs[UREG_G1] = addr;
12257 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12258 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12259 + else
12260 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12261 + regs->pc = addr;
12262 + regs->npc = addr+4;
12263 + return 2;
12264 + }
12265 + } while (0);
12266 +
12267 + do { /* PaX: unpatched PLT emulation step 1 */
12268 + unsigned int sethi, ba, nop;
12269 +
12270 + err = get_user(sethi, (unsigned int *)regs->pc);
12271 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
12272 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12273 +
12274 + if (err)
12275 + break;
12276 +
12277 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12278 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12279 + nop == 0x01000000U)
12280 + {
12281 + unsigned int addr, save, call;
12282 +
12283 + if ((ba & 0xFFC00000U) == 0x30800000U)
12284 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12285 + else
12286 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12287 +
12288 + err = get_user(save, (unsigned int *)addr);
12289 + err |= get_user(call, (unsigned int *)(addr+4));
12290 + err |= get_user(nop, (unsigned int *)(addr+8));
12291 + if (err)
12292 + break;
12293 +
12294 +#ifdef CONFIG_PAX_DLRESOLVE
12295 + if (save == 0x9DE3BFA8U &&
12296 + (call & 0xC0000000U) == 0x40000000U &&
12297 + nop == 0x01000000U)
12298 + {
12299 + struct vm_area_struct *vma;
12300 + unsigned long call_dl_resolve;
12301 +
12302 + down_read(&current->mm->mmap_sem);
12303 + call_dl_resolve = current->mm->call_dl_resolve;
12304 + up_read(&current->mm->mmap_sem);
12305 + if (likely(call_dl_resolve))
12306 + goto emulate;
12307 +
12308 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12309 +
12310 + down_write(&current->mm->mmap_sem);
12311 + if (current->mm->call_dl_resolve) {
12312 + call_dl_resolve = current->mm->call_dl_resolve;
12313 + up_write(&current->mm->mmap_sem);
12314 + if (vma)
12315 + kmem_cache_free(vm_area_cachep, vma);
12316 + goto emulate;
12317 + }
12318 +
12319 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12320 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12321 + up_write(&current->mm->mmap_sem);
12322 + if (vma)
12323 + kmem_cache_free(vm_area_cachep, vma);
12324 + return 1;
12325 + }
12326 +
12327 + if (pax_insert_vma(vma, call_dl_resolve)) {
12328 + up_write(&current->mm->mmap_sem);
12329 + kmem_cache_free(vm_area_cachep, vma);
12330 + return 1;
12331 + }
12332 +
12333 + current->mm->call_dl_resolve = call_dl_resolve;
12334 + up_write(&current->mm->mmap_sem);
12335 +
12336 +emulate:
12337 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12338 + regs->pc = call_dl_resolve;
12339 + regs->npc = addr+4;
12340 + return 3;
12341 + }
12342 +#endif
12343 +
12344 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12345 + if ((save & 0xFFC00000U) == 0x05000000U &&
12346 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12347 + nop == 0x01000000U)
12348 + {
12349 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12350 + regs->u_regs[UREG_G2] = addr + 4;
12351 + addr = (save & 0x003FFFFFU) << 10;
12352 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12353 + regs->pc = addr;
12354 + regs->npc = addr+4;
12355 + return 3;
12356 + }
12357 + }
12358 + } while (0);
12359 +
12360 + do { /* PaX: unpatched PLT emulation step 2 */
12361 + unsigned int save, call, nop;
12362 +
12363 + err = get_user(save, (unsigned int *)(regs->pc-4));
12364 + err |= get_user(call, (unsigned int *)regs->pc);
12365 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
12366 + if (err)
12367 + break;
12368 +
12369 + if (save == 0x9DE3BFA8U &&
12370 + (call & 0xC0000000U) == 0x40000000U &&
12371 + nop == 0x01000000U)
12372 + {
12373 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
12374 +
12375 + regs->u_regs[UREG_RETPC] = regs->pc;
12376 + regs->pc = dl_resolve;
12377 + regs->npc = dl_resolve+4;
12378 + return 3;
12379 + }
12380 + } while (0);
12381 +#endif
12382 +
12383 + return 1;
12384 +}
12385 +
12386 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12387 +{
12388 + unsigned long i;
12389 +
12390 + printk(KERN_ERR "PAX: bytes at PC: ");
12391 + for (i = 0; i < 8; i++) {
12392 + unsigned int c;
12393 + if (get_user(c, (unsigned int *)pc+i))
12394 + printk(KERN_CONT "???????? ");
12395 + else
12396 + printk(KERN_CONT "%08x ", c);
12397 + }
12398 + printk("\n");
12399 +}
12400 +#endif
12401 +
12402 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
12403 int text_fault)
12404 {
12405 @@ -226,6 +500,24 @@ good_area:
12406 if (!(vma->vm_flags & VM_WRITE))
12407 goto bad_area;
12408 } else {
12409 +
12410 +#ifdef CONFIG_PAX_PAGEEXEC
12411 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
12412 + up_read(&mm->mmap_sem);
12413 + switch (pax_handle_fetch_fault(regs)) {
12414 +
12415 +#ifdef CONFIG_PAX_EMUPLT
12416 + case 2:
12417 + case 3:
12418 + return;
12419 +#endif
12420 +
12421 + }
12422 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
12423 + do_group_exit(SIGKILL);
12424 + }
12425 +#endif
12426 +
12427 /* Allow reads even for write-only mappings */
12428 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
12429 goto bad_area;
12430 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
12431 index 18fcd71..e4fe821 100644
12432 --- a/arch/sparc/mm/fault_64.c
12433 +++ b/arch/sparc/mm/fault_64.c
12434 @@ -22,6 +22,9 @@
12435 #include <linux/kdebug.h>
12436 #include <linux/percpu.h>
12437 #include <linux/context_tracking.h>
12438 +#include <linux/slab.h>
12439 +#include <linux/pagemap.h>
12440 +#include <linux/compiler.h>
12441
12442 #include <asm/page.h>
12443 #include <asm/pgtable.h>
12444 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
12445 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
12446 regs->tpc);
12447 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
12448 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
12449 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
12450 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
12451 dump_stack();
12452 unhandled_fault(regs->tpc, current, regs);
12453 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
12454 show_regs(regs);
12455 }
12456
12457 +#ifdef CONFIG_PAX_PAGEEXEC
12458 +#ifdef CONFIG_PAX_DLRESOLVE
12459 +static void pax_emuplt_close(struct vm_area_struct *vma)
12460 +{
12461 + vma->vm_mm->call_dl_resolve = 0UL;
12462 +}
12463 +
12464 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12465 +{
12466 + unsigned int *kaddr;
12467 +
12468 + vmf->page = alloc_page(GFP_HIGHUSER);
12469 + if (!vmf->page)
12470 + return VM_FAULT_OOM;
12471 +
12472 + kaddr = kmap(vmf->page);
12473 + memset(kaddr, 0, PAGE_SIZE);
12474 + kaddr[0] = 0x9DE3BFA8U; /* save */
12475 + flush_dcache_page(vmf->page);
12476 + kunmap(vmf->page);
12477 + return VM_FAULT_MAJOR;
12478 +}
12479 +
12480 +static const struct vm_operations_struct pax_vm_ops = {
12481 + .close = pax_emuplt_close,
12482 + .fault = pax_emuplt_fault
12483 +};
12484 +
12485 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12486 +{
12487 + int ret;
12488 +
12489 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12490 + vma->vm_mm = current->mm;
12491 + vma->vm_start = addr;
12492 + vma->vm_end = addr + PAGE_SIZE;
12493 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12494 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12495 + vma->vm_ops = &pax_vm_ops;
12496 +
12497 + ret = insert_vm_struct(current->mm, vma);
12498 + if (ret)
12499 + return ret;
12500 +
12501 + ++current->mm->total_vm;
12502 + return 0;
12503 +}
12504 +#endif
12505 +
12506 +/*
12507 + * PaX: decide what to do with offenders (regs->tpc = fault address)
12508 + *
12509 + * returns 1 when task should be killed
12510 + * 2 when patched PLT trampoline was detected
12511 + * 3 when unpatched PLT trampoline was detected
12512 + */
12513 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12514 +{
12515 +
12516 +#ifdef CONFIG_PAX_EMUPLT
12517 + int err;
12518 +
12519 + do { /* PaX: patched PLT emulation #1 */
12520 + unsigned int sethi1, sethi2, jmpl;
12521 +
12522 + err = get_user(sethi1, (unsigned int *)regs->tpc);
12523 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12524 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12525 +
12526 + if (err)
12527 + break;
12528 +
12529 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12530 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12531 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12532 + {
12533 + unsigned long addr;
12534 +
12535 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12536 + addr = regs->u_regs[UREG_G1];
12537 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12538 +
12539 + if (test_thread_flag(TIF_32BIT))
12540 + addr &= 0xFFFFFFFFUL;
12541 +
12542 + regs->tpc = addr;
12543 + regs->tnpc = addr+4;
12544 + return 2;
12545 + }
12546 + } while (0);
12547 +
12548 + do { /* PaX: patched PLT emulation #2 */
12549 + unsigned int ba;
12550 +
12551 + err = get_user(ba, (unsigned int *)regs->tpc);
12552 +
12553 + if (err)
12554 + break;
12555 +
12556 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12557 + unsigned long addr;
12558 +
12559 + if ((ba & 0xFFC00000U) == 0x30800000U)
12560 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12561 + else
12562 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12563 +
12564 + if (test_thread_flag(TIF_32BIT))
12565 + addr &= 0xFFFFFFFFUL;
12566 +
12567 + regs->tpc = addr;
12568 + regs->tnpc = addr+4;
12569 + return 2;
12570 + }
12571 + } while (0);
12572 +
12573 + do { /* PaX: patched PLT emulation #3 */
12574 + unsigned int sethi, bajmpl, nop;
12575 +
12576 + err = get_user(sethi, (unsigned int *)regs->tpc);
12577 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12578 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12579 +
12580 + if (err)
12581 + break;
12582 +
12583 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12584 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12585 + nop == 0x01000000U)
12586 + {
12587 + unsigned long addr;
12588 +
12589 + addr = (sethi & 0x003FFFFFU) << 10;
12590 + regs->u_regs[UREG_G1] = addr;
12591 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12592 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12593 + else
12594 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12595 +
12596 + if (test_thread_flag(TIF_32BIT))
12597 + addr &= 0xFFFFFFFFUL;
12598 +
12599 + regs->tpc = addr;
12600 + regs->tnpc = addr+4;
12601 + return 2;
12602 + }
12603 + } while (0);
12604 +
12605 + do { /* PaX: patched PLT emulation #4 */
12606 + unsigned int sethi, mov1, call, mov2;
12607 +
12608 + err = get_user(sethi, (unsigned int *)regs->tpc);
12609 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12610 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12611 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12612 +
12613 + if (err)
12614 + break;
12615 +
12616 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12617 + mov1 == 0x8210000FU &&
12618 + (call & 0xC0000000U) == 0x40000000U &&
12619 + mov2 == 0x9E100001U)
12620 + {
12621 + unsigned long addr;
12622 +
12623 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12624 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12625 +
12626 + if (test_thread_flag(TIF_32BIT))
12627 + addr &= 0xFFFFFFFFUL;
12628 +
12629 + regs->tpc = addr;
12630 + regs->tnpc = addr+4;
12631 + return 2;
12632 + }
12633 + } while (0);
12634 +
12635 + do { /* PaX: patched PLT emulation #5 */
12636 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12637 +
12638 + err = get_user(sethi, (unsigned int *)regs->tpc);
12639 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12640 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12641 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12642 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12643 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12644 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12645 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12646 +
12647 + if (err)
12648 + break;
12649 +
12650 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12651 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12652 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12653 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12654 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12655 + sllx == 0x83287020U &&
12656 + jmpl == 0x81C04005U &&
12657 + nop == 0x01000000U)
12658 + {
12659 + unsigned long addr;
12660 +
12661 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12662 + regs->u_regs[UREG_G1] <<= 32;
12663 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12664 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12665 + regs->tpc = addr;
12666 + regs->tnpc = addr+4;
12667 + return 2;
12668 + }
12669 + } while (0);
12670 +
12671 + do { /* PaX: patched PLT emulation #6 */
12672 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12673 +
12674 + err = get_user(sethi, (unsigned int *)regs->tpc);
12675 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12676 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12677 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12678 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12679 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12680 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12681 +
12682 + if (err)
12683 + break;
12684 +
12685 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12686 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12687 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12688 + sllx == 0x83287020U &&
12689 + (or & 0xFFFFE000U) == 0x8A116000U &&
12690 + jmpl == 0x81C04005U &&
12691 + nop == 0x01000000U)
12692 + {
12693 + unsigned long addr;
12694 +
12695 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12696 + regs->u_regs[UREG_G1] <<= 32;
12697 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12698 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12699 + regs->tpc = addr;
12700 + regs->tnpc = addr+4;
12701 + return 2;
12702 + }
12703 + } while (0);
12704 +
12705 + do { /* PaX: unpatched PLT emulation step 1 */
12706 + unsigned int sethi, ba, nop;
12707 +
12708 + err = get_user(sethi, (unsigned int *)regs->tpc);
12709 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12710 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12711 +
12712 + if (err)
12713 + break;
12714 +
12715 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12716 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12717 + nop == 0x01000000U)
12718 + {
12719 + unsigned long addr;
12720 + unsigned int save, call;
12721 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12722 +
12723 + if ((ba & 0xFFC00000U) == 0x30800000U)
12724 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12725 + else
12726 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12727 +
12728 + if (test_thread_flag(TIF_32BIT))
12729 + addr &= 0xFFFFFFFFUL;
12730 +
12731 + err = get_user(save, (unsigned int *)addr);
12732 + err |= get_user(call, (unsigned int *)(addr+4));
12733 + err |= get_user(nop, (unsigned int *)(addr+8));
12734 + if (err)
12735 + break;
12736 +
12737 +#ifdef CONFIG_PAX_DLRESOLVE
12738 + if (save == 0x9DE3BFA8U &&
12739 + (call & 0xC0000000U) == 0x40000000U &&
12740 + nop == 0x01000000U)
12741 + {
12742 + struct vm_area_struct *vma;
12743 + unsigned long call_dl_resolve;
12744 +
12745 + down_read(&current->mm->mmap_sem);
12746 + call_dl_resolve = current->mm->call_dl_resolve;
12747 + up_read(&current->mm->mmap_sem);
12748 + if (likely(call_dl_resolve))
12749 + goto emulate;
12750 +
12751 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12752 +
12753 + down_write(&current->mm->mmap_sem);
12754 + if (current->mm->call_dl_resolve) {
12755 + call_dl_resolve = current->mm->call_dl_resolve;
12756 + up_write(&current->mm->mmap_sem);
12757 + if (vma)
12758 + kmem_cache_free(vm_area_cachep, vma);
12759 + goto emulate;
12760 + }
12761 +
12762 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12763 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12764 + up_write(&current->mm->mmap_sem);
12765 + if (vma)
12766 + kmem_cache_free(vm_area_cachep, vma);
12767 + return 1;
12768 + }
12769 +
12770 + if (pax_insert_vma(vma, call_dl_resolve)) {
12771 + up_write(&current->mm->mmap_sem);
12772 + kmem_cache_free(vm_area_cachep, vma);
12773 + return 1;
12774 + }
12775 +
12776 + current->mm->call_dl_resolve = call_dl_resolve;
12777 + up_write(&current->mm->mmap_sem);
12778 +
12779 +emulate:
12780 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12781 + regs->tpc = call_dl_resolve;
12782 + regs->tnpc = addr+4;
12783 + return 3;
12784 + }
12785 +#endif
12786 +
12787 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12788 + if ((save & 0xFFC00000U) == 0x05000000U &&
12789 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12790 + nop == 0x01000000U)
12791 + {
12792 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12793 + regs->u_regs[UREG_G2] = addr + 4;
12794 + addr = (save & 0x003FFFFFU) << 10;
12795 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12796 +
12797 + if (test_thread_flag(TIF_32BIT))
12798 + addr &= 0xFFFFFFFFUL;
12799 +
12800 + regs->tpc = addr;
12801 + regs->tnpc = addr+4;
12802 + return 3;
12803 + }
12804 +
12805 + /* PaX: 64-bit PLT stub */
12806 + err = get_user(sethi1, (unsigned int *)addr);
12807 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12808 + err |= get_user(or1, (unsigned int *)(addr+8));
12809 + err |= get_user(or2, (unsigned int *)(addr+12));
12810 + err |= get_user(sllx, (unsigned int *)(addr+16));
12811 + err |= get_user(add, (unsigned int *)(addr+20));
12812 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12813 + err |= get_user(nop, (unsigned int *)(addr+28));
12814 + if (err)
12815 + break;
12816 +
12817 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12818 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12819 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12820 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12821 + sllx == 0x89293020U &&
12822 + add == 0x8A010005U &&
12823 + jmpl == 0x89C14000U &&
12824 + nop == 0x01000000U)
12825 + {
12826 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12827 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12828 + regs->u_regs[UREG_G4] <<= 32;
12829 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12830 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12831 + regs->u_regs[UREG_G4] = addr + 24;
12832 + addr = regs->u_regs[UREG_G5];
12833 + regs->tpc = addr;
12834 + regs->tnpc = addr+4;
12835 + return 3;
12836 + }
12837 + }
12838 + } while (0);
12839 +
12840 +#ifdef CONFIG_PAX_DLRESOLVE
12841 + do { /* PaX: unpatched PLT emulation step 2 */
12842 + unsigned int save, call, nop;
12843 +
12844 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12845 + err |= get_user(call, (unsigned int *)regs->tpc);
12846 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12847 + if (err)
12848 + break;
12849 +
12850 + if (save == 0x9DE3BFA8U &&
12851 + (call & 0xC0000000U) == 0x40000000U &&
12852 + nop == 0x01000000U)
12853 + {
12854 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12855 +
12856 + if (test_thread_flag(TIF_32BIT))
12857 + dl_resolve &= 0xFFFFFFFFUL;
12858 +
12859 + regs->u_regs[UREG_RETPC] = regs->tpc;
12860 + regs->tpc = dl_resolve;
12861 + regs->tnpc = dl_resolve+4;
12862 + return 3;
12863 + }
12864 + } while (0);
12865 +#endif
12866 +
12867 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12868 + unsigned int sethi, ba, nop;
12869 +
12870 + err = get_user(sethi, (unsigned int *)regs->tpc);
12871 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12872 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12873 +
12874 + if (err)
12875 + break;
12876 +
12877 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12878 + (ba & 0xFFF00000U) == 0x30600000U &&
12879 + nop == 0x01000000U)
12880 + {
12881 + unsigned long addr;
12882 +
12883 + addr = (sethi & 0x003FFFFFU) << 10;
12884 + regs->u_regs[UREG_G1] = addr;
12885 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12886 +
12887 + if (test_thread_flag(TIF_32BIT))
12888 + addr &= 0xFFFFFFFFUL;
12889 +
12890 + regs->tpc = addr;
12891 + regs->tnpc = addr+4;
12892 + return 2;
12893 + }
12894 + } while (0);
12895 +
12896 +#endif
12897 +
12898 + return 1;
12899 +}
12900 +
12901 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12902 +{
12903 + unsigned long i;
12904 +
12905 + printk(KERN_ERR "PAX: bytes at PC: ");
12906 + for (i = 0; i < 8; i++) {
12907 + unsigned int c;
12908 + if (get_user(c, (unsigned int *)pc+i))
12909 + printk(KERN_CONT "???????? ");
12910 + else
12911 + printk(KERN_CONT "%08x ", c);
12912 + }
12913 + printk("\n");
12914 +}
12915 +#endif
12916 +
12917 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12918 {
12919 enum ctx_state prev_state = exception_enter();
12920 @@ -353,6 +816,29 @@ retry:
12921 if (!vma)
12922 goto bad_area;
12923
12924 +#ifdef CONFIG_PAX_PAGEEXEC
12925 + /* PaX: detect ITLB misses on non-exec pages */
12926 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12927 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12928 + {
12929 + if (address != regs->tpc)
12930 + goto good_area;
12931 +
12932 + up_read(&mm->mmap_sem);
12933 + switch (pax_handle_fetch_fault(regs)) {
12934 +
12935 +#ifdef CONFIG_PAX_EMUPLT
12936 + case 2:
12937 + case 3:
12938 + return;
12939 +#endif
12940 +
12941 + }
12942 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12943 + do_group_exit(SIGKILL);
12944 + }
12945 +#endif
12946 +
12947 /* Pure DTLB misses do not tell us whether the fault causing
12948 * load/store/atomic was a write or not, it only says that there
12949 * was no match. So in such a case we (carefully) read the
12950 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12951 index d329537..2c3746a 100644
12952 --- a/arch/sparc/mm/hugetlbpage.c
12953 +++ b/arch/sparc/mm/hugetlbpage.c
12954 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12955 unsigned long addr,
12956 unsigned long len,
12957 unsigned long pgoff,
12958 - unsigned long flags)
12959 + unsigned long flags,
12960 + unsigned long offset)
12961 {
12962 + struct mm_struct *mm = current->mm;
12963 unsigned long task_size = TASK_SIZE;
12964 struct vm_unmapped_area_info info;
12965
12966 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12967
12968 info.flags = 0;
12969 info.length = len;
12970 - info.low_limit = TASK_UNMAPPED_BASE;
12971 + info.low_limit = mm->mmap_base;
12972 info.high_limit = min(task_size, VA_EXCLUDE_START);
12973 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12974 info.align_offset = 0;
12975 + info.threadstack_offset = offset;
12976 addr = vm_unmapped_area(&info);
12977
12978 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12979 VM_BUG_ON(addr != -ENOMEM);
12980 info.low_limit = VA_EXCLUDE_END;
12981 +
12982 +#ifdef CONFIG_PAX_RANDMMAP
12983 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12984 + info.low_limit += mm->delta_mmap;
12985 +#endif
12986 +
12987 info.high_limit = task_size;
12988 addr = vm_unmapped_area(&info);
12989 }
12990 @@ -55,7 +64,8 @@ static unsigned long
12991 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12992 const unsigned long len,
12993 const unsigned long pgoff,
12994 - const unsigned long flags)
12995 + const unsigned long flags,
12996 + const unsigned long offset)
12997 {
12998 struct mm_struct *mm = current->mm;
12999 unsigned long addr = addr0;
13000 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
13001 info.high_limit = mm->mmap_base;
13002 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
13003 info.align_offset = 0;
13004 + info.threadstack_offset = offset;
13005 addr = vm_unmapped_area(&info);
13006
13007 /*
13008 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
13009 VM_BUG_ON(addr != -ENOMEM);
13010 info.flags = 0;
13011 info.low_limit = TASK_UNMAPPED_BASE;
13012 +
13013 +#ifdef CONFIG_PAX_RANDMMAP
13014 + if (mm->pax_flags & MF_PAX_RANDMMAP)
13015 + info.low_limit += mm->delta_mmap;
13016 +#endif
13017 +
13018 info.high_limit = STACK_TOP32;
13019 addr = vm_unmapped_area(&info);
13020 }
13021 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
13022 struct mm_struct *mm = current->mm;
13023 struct vm_area_struct *vma;
13024 unsigned long task_size = TASK_SIZE;
13025 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
13026
13027 if (test_thread_flag(TIF_32BIT))
13028 task_size = STACK_TOP32;
13029 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
13030 return addr;
13031 }
13032
13033 +#ifdef CONFIG_PAX_RANDMMAP
13034 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
13035 +#endif
13036 +
13037 if (addr) {
13038 addr = ALIGN(addr, HPAGE_SIZE);
13039 vma = find_vma(mm, addr);
13040 - if (task_size - len >= addr &&
13041 - (!vma || addr + len <= vma->vm_start))
13042 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
13043 return addr;
13044 }
13045 if (mm->get_unmapped_area == arch_get_unmapped_area)
13046 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
13047 - pgoff, flags);
13048 + pgoff, flags, offset);
13049 else
13050 return hugetlb_get_unmapped_area_topdown(file, addr, len,
13051 - pgoff, flags);
13052 + pgoff, flags, offset);
13053 }
13054
13055 pte_t *huge_pte_alloc(struct mm_struct *mm,
13056 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
13057 index 04bc826..0fefab9 100644
13058 --- a/arch/sparc/mm/init_64.c
13059 +++ b/arch/sparc/mm/init_64.c
13060 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
13061 int num_kernel_image_mappings;
13062
13063 #ifdef CONFIG_DEBUG_DCFLUSH
13064 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
13065 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
13066 #ifdef CONFIG_SMP
13067 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
13068 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
13069 #endif
13070 #endif
13071
13072 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
13073 {
13074 BUG_ON(tlb_type == hypervisor);
13075 #ifdef CONFIG_DEBUG_DCFLUSH
13076 - atomic_inc(&dcpage_flushes);
13077 + atomic_inc_unchecked(&dcpage_flushes);
13078 #endif
13079
13080 #ifdef DCACHE_ALIASING_POSSIBLE
13081 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
13082
13083 #ifdef CONFIG_DEBUG_DCFLUSH
13084 seq_printf(m, "DCPageFlushes\t: %d\n",
13085 - atomic_read(&dcpage_flushes));
13086 + atomic_read_unchecked(&dcpage_flushes));
13087 #ifdef CONFIG_SMP
13088 seq_printf(m, "DCPageFlushesXC\t: %d\n",
13089 - atomic_read(&dcpage_flushes_xcall));
13090 + atomic_read_unchecked(&dcpage_flushes_xcall));
13091 #endif /* CONFIG_SMP */
13092 #endif /* CONFIG_DEBUG_DCFLUSH */
13093 }
13094 diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
13095 index ece4af0..f04b862 100644
13096 --- a/arch/sparc/net/bpf_jit_comp.c
13097 +++ b/arch/sparc/net/bpf_jit_comp.c
13098 @@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
13099 {
13100 if (fp->jited)
13101 module_free(NULL, fp->bpf_func);
13102 - kfree(fp);
13103 +
13104 + bpf_prog_unlock_free(fp);
13105 }
13106 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
13107 index 7fcd492..1311074 100644
13108 --- a/arch/tile/Kconfig
13109 +++ b/arch/tile/Kconfig
13110 @@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
13111
13112 config KEXEC
13113 bool "kexec system call"
13114 + depends on !GRKERNSEC_KMEM
13115 ---help---
13116 kexec is a system call that implements the ability to shutdown your
13117 current kernel, and to start another kernel. It is like a reboot
13118 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
13119 index 7b11c5f..755a026 100644
13120 --- a/arch/tile/include/asm/atomic_64.h
13121 +++ b/arch/tile/include/asm/atomic_64.h
13122 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
13123
13124 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13125
13126 +#define atomic64_read_unchecked(v) atomic64_read(v)
13127 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
13128 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
13129 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
13130 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
13131 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
13132 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
13133 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
13134 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
13135 +
13136 /* Define this to indicate that cmpxchg is an efficient operation. */
13137 #define __HAVE_ARCH_CMPXCHG
13138
13139 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
13140 index 6160761..00cac88 100644
13141 --- a/arch/tile/include/asm/cache.h
13142 +++ b/arch/tile/include/asm/cache.h
13143 @@ -15,11 +15,12 @@
13144 #ifndef _ASM_TILE_CACHE_H
13145 #define _ASM_TILE_CACHE_H
13146
13147 +#include <linux/const.h>
13148 #include <arch/chip.h>
13149
13150 /* bytes per L1 data cache line */
13151 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
13152 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13153 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13154
13155 /* bytes per L2 cache line */
13156 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
13157 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
13158 index b6cde32..c0cb736 100644
13159 --- a/arch/tile/include/asm/uaccess.h
13160 +++ b/arch/tile/include/asm/uaccess.h
13161 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
13162 const void __user *from,
13163 unsigned long n)
13164 {
13165 - int sz = __compiletime_object_size(to);
13166 + size_t sz = __compiletime_object_size(to);
13167
13168 - if (likely(sz == -1 || sz >= n))
13169 + if (likely(sz == (size_t)-1 || sz >= n))
13170 n = _copy_from_user(to, from, n);
13171 else
13172 copy_from_user_overflow();
13173 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
13174 index e514899..f8743c4 100644
13175 --- a/arch/tile/mm/hugetlbpage.c
13176 +++ b/arch/tile/mm/hugetlbpage.c
13177 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
13178 info.high_limit = TASK_SIZE;
13179 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13180 info.align_offset = 0;
13181 + info.threadstack_offset = 0;
13182 return vm_unmapped_area(&info);
13183 }
13184
13185 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
13186 info.high_limit = current->mm->mmap_base;
13187 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13188 info.align_offset = 0;
13189 + info.threadstack_offset = 0;
13190 addr = vm_unmapped_area(&info);
13191
13192 /*
13193 diff --git a/arch/um/Makefile b/arch/um/Makefile
13194 index e4b1a96..16162f8 100644
13195 --- a/arch/um/Makefile
13196 +++ b/arch/um/Makefile
13197 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
13198 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
13199 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
13200
13201 +ifdef CONSTIFY_PLUGIN
13202 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13203 +endif
13204 +
13205 #This will adjust *FLAGS accordingly to the platform.
13206 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
13207
13208 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
13209 index 19e1bdd..3665b77 100644
13210 --- a/arch/um/include/asm/cache.h
13211 +++ b/arch/um/include/asm/cache.h
13212 @@ -1,6 +1,7 @@
13213 #ifndef __UM_CACHE_H
13214 #define __UM_CACHE_H
13215
13216 +#include <linux/const.h>
13217
13218 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
13219 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13220 @@ -12,6 +13,6 @@
13221 # define L1_CACHE_SHIFT 5
13222 #endif
13223
13224 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13225 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13226
13227 #endif
13228 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
13229 index 2e0a6b1..a64d0f5 100644
13230 --- a/arch/um/include/asm/kmap_types.h
13231 +++ b/arch/um/include/asm/kmap_types.h
13232 @@ -8,6 +8,6 @@
13233
13234 /* No more #include "asm/arch/kmap_types.h" ! */
13235
13236 -#define KM_TYPE_NR 14
13237 +#define KM_TYPE_NR 15
13238
13239 #endif
13240 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
13241 index 71c5d13..4c7b9f1 100644
13242 --- a/arch/um/include/asm/page.h
13243 +++ b/arch/um/include/asm/page.h
13244 @@ -14,6 +14,9 @@
13245 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
13246 #define PAGE_MASK (~(PAGE_SIZE-1))
13247
13248 +#define ktla_ktva(addr) (addr)
13249 +#define ktva_ktla(addr) (addr)
13250 +
13251 #ifndef __ASSEMBLY__
13252
13253 struct page;
13254 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
13255 index 0032f92..cd151e0 100644
13256 --- a/arch/um/include/asm/pgtable-3level.h
13257 +++ b/arch/um/include/asm/pgtable-3level.h
13258 @@ -58,6 +58,7 @@
13259 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
13260 #define pud_populate(mm, pud, pmd) \
13261 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
13262 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
13263
13264 #ifdef CONFIG_64BIT
13265 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
13266 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
13267 index f17bca8..48adb87 100644
13268 --- a/arch/um/kernel/process.c
13269 +++ b/arch/um/kernel/process.c
13270 @@ -356,22 +356,6 @@ int singlestepping(void * t)
13271 return 2;
13272 }
13273
13274 -/*
13275 - * Only x86 and x86_64 have an arch_align_stack().
13276 - * All other arches have "#define arch_align_stack(x) (x)"
13277 - * in their asm/exec.h
13278 - * As this is included in UML from asm-um/system-generic.h,
13279 - * we can use it to behave as the subarch does.
13280 - */
13281 -#ifndef arch_align_stack
13282 -unsigned long arch_align_stack(unsigned long sp)
13283 -{
13284 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13285 - sp -= get_random_int() % 8192;
13286 - return sp & ~0xf;
13287 -}
13288 -#endif
13289 -
13290 unsigned long get_wchan(struct task_struct *p)
13291 {
13292 unsigned long stack_page, sp, ip;
13293 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
13294 index ad8f795..2c7eec6 100644
13295 --- a/arch/unicore32/include/asm/cache.h
13296 +++ b/arch/unicore32/include/asm/cache.h
13297 @@ -12,8 +12,10 @@
13298 #ifndef __UNICORE_CACHE_H__
13299 #define __UNICORE_CACHE_H__
13300
13301 -#define L1_CACHE_SHIFT (5)
13302 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13303 +#include <linux/const.h>
13304 +
13305 +#define L1_CACHE_SHIFT 5
13306 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13307
13308 /*
13309 * Memory returned by kmalloc() may be used for DMA, so we must make
13310 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
13311 index 3632743..630a8bb 100644
13312 --- a/arch/x86/Kconfig
13313 +++ b/arch/x86/Kconfig
13314 @@ -130,7 +130,7 @@ config X86
13315 select RTC_LIB
13316 select HAVE_DEBUG_STACKOVERFLOW
13317 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
13318 - select HAVE_CC_STACKPROTECTOR
13319 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
13320 select GENERIC_CPU_AUTOPROBE
13321 select HAVE_ARCH_AUDITSYSCALL
13322 select ARCH_SUPPORTS_ATOMIC_RMW
13323 @@ -258,7 +258,7 @@ config X86_HT
13324
13325 config X86_32_LAZY_GS
13326 def_bool y
13327 - depends on X86_32 && !CC_STACKPROTECTOR
13328 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
13329
13330 config ARCH_HWEIGHT_CFLAGS
13331 string
13332 @@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
13333
13334 menuconfig HYPERVISOR_GUEST
13335 bool "Linux guest support"
13336 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
13337 ---help---
13338 Say Y here to enable options for running Linux under various hyper-
13339 visors. This option enables basic hypervisor detection and platform
13340 @@ -1083,6 +1084,7 @@ choice
13341
13342 config NOHIGHMEM
13343 bool "off"
13344 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13345 ---help---
13346 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
13347 However, the address space of 32-bit x86 processors is only 4
13348 @@ -1119,6 +1121,7 @@ config NOHIGHMEM
13349
13350 config HIGHMEM4G
13351 bool "4GB"
13352 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13353 ---help---
13354 Select this if you have a 32-bit processor and between 1 and 4
13355 gigabytes of physical RAM.
13356 @@ -1171,7 +1174,7 @@ config PAGE_OFFSET
13357 hex
13358 default 0xB0000000 if VMSPLIT_3G_OPT
13359 default 0x80000000 if VMSPLIT_2G
13360 - default 0x78000000 if VMSPLIT_2G_OPT
13361 + default 0x70000000 if VMSPLIT_2G_OPT
13362 default 0x40000000 if VMSPLIT_1G
13363 default 0xC0000000
13364 depends on X86_32
13365 @@ -1586,6 +1589,7 @@ source kernel/Kconfig.hz
13366
13367 config KEXEC
13368 bool "kexec system call"
13369 + depends on !GRKERNSEC_KMEM
13370 ---help---
13371 kexec is a system call that implements the ability to shutdown your
13372 current kernel, and to start another kernel. It is like a reboot
13373 @@ -1771,7 +1775,9 @@ config X86_NEED_RELOCS
13374
13375 config PHYSICAL_ALIGN
13376 hex "Alignment value to which kernel should be aligned"
13377 - default "0x200000"
13378 + default "0x1000000"
13379 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
13380 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
13381 range 0x2000 0x1000000 if X86_32
13382 range 0x200000 0x1000000 if X86_64
13383 ---help---
13384 @@ -1854,6 +1860,7 @@ config COMPAT_VDSO
13385 def_bool n
13386 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
13387 depends on X86_32 || IA32_EMULATION
13388 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
13389 ---help---
13390 Certain buggy versions of glibc will crash if they are
13391 presented with a 32-bit vDSO that is not mapped at the address
13392 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
13393 index 6983314..54ad7e8 100644
13394 --- a/arch/x86/Kconfig.cpu
13395 +++ b/arch/x86/Kconfig.cpu
13396 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
13397
13398 config X86_F00F_BUG
13399 def_bool y
13400 - depends on M586MMX || M586TSC || M586 || M486
13401 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
13402
13403 config X86_INVD_BUG
13404 def_bool y
13405 @@ -327,7 +327,7 @@ config X86_INVD_BUG
13406
13407 config X86_ALIGNMENT_16
13408 def_bool y
13409 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13410 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13411
13412 config X86_INTEL_USERCOPY
13413 def_bool y
13414 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
13415 # generates cmov.
13416 config X86_CMOV
13417 def_bool y
13418 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13419 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13420
13421 config X86_MINIMUM_CPU_FAMILY
13422 int
13423 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
13424 index 61bd2ad..50b625d 100644
13425 --- a/arch/x86/Kconfig.debug
13426 +++ b/arch/x86/Kconfig.debug
13427 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
13428 config DEBUG_RODATA
13429 bool "Write protect kernel read-only data structures"
13430 default y
13431 - depends on DEBUG_KERNEL
13432 + depends on DEBUG_KERNEL && BROKEN
13433 ---help---
13434 Mark the kernel read-only data as write-protected in the pagetables,
13435 in order to catch accidental (and incorrect) writes to such const
13436 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
13437
13438 config DEBUG_SET_MODULE_RONX
13439 bool "Set loadable kernel module data as NX and text as RO"
13440 - depends on MODULES
13441 + depends on MODULES && BROKEN
13442 ---help---
13443 This option helps catch unintended modifications to loadable
13444 kernel module's text and read-only data. It also prevents execution
13445 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
13446 index 60087ca..9d9500e 100644
13447 --- a/arch/x86/Makefile
13448 +++ b/arch/x86/Makefile
13449 @@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
13450 # CPU-specific tuning. Anything which can be shared with UML should go here.
13451 include $(srctree)/arch/x86/Makefile_32.cpu
13452 KBUILD_CFLAGS += $(cflags-y)
13453 -
13454 - # temporary until string.h is fixed
13455 - KBUILD_CFLAGS += -ffreestanding
13456 else
13457 BITS := 64
13458 UTS_MACHINE := x86_64
13459 @@ -111,6 +108,9 @@ else
13460 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
13461 endif
13462
13463 +# temporary until string.h is fixed
13464 +KBUILD_CFLAGS += -ffreestanding
13465 +
13466 # Make sure compiler does not have buggy stack-protector support.
13467 ifdef CONFIG_CC_STACKPROTECTOR
13468 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
13469 @@ -184,6 +184,7 @@ archheaders:
13470 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
13471
13472 archprepare:
13473 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
13474 ifeq ($(CONFIG_KEXEC_FILE),y)
13475 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
13476 endif
13477 @@ -274,3 +275,9 @@ define archhelp
13478 echo ' FDINITRD=file initrd for the booted kernel'
13479 echo ' kvmconfig - Enable additional options for guest kernel support'
13480 endef
13481 +
13482 +define OLD_LD
13483 +
13484 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
13485 +*** Please upgrade your binutils to 2.18 or newer
13486 +endef
13487 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
13488 index dbe8dd2..2f0a98f 100644
13489 --- a/arch/x86/boot/Makefile
13490 +++ b/arch/x86/boot/Makefile
13491 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
13492 # ---------------------------------------------------------------------------
13493
13494 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
13495 +ifdef CONSTIFY_PLUGIN
13496 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13497 +endif
13498 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13499 GCOV_PROFILE := n
13500
13501 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
13502 index 878e4b9..20537ab 100644
13503 --- a/arch/x86/boot/bitops.h
13504 +++ b/arch/x86/boot/bitops.h
13505 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13506 u8 v;
13507 const u32 *p = (const u32 *)addr;
13508
13509 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13510 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13511 return v;
13512 }
13513
13514 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13515
13516 static inline void set_bit(int nr, void *addr)
13517 {
13518 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13519 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13520 }
13521
13522 #endif /* BOOT_BITOPS_H */
13523 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
13524 index bd49ec6..94c7f58 100644
13525 --- a/arch/x86/boot/boot.h
13526 +++ b/arch/x86/boot/boot.h
13527 @@ -84,7 +84,7 @@ static inline void io_delay(void)
13528 static inline u16 ds(void)
13529 {
13530 u16 seg;
13531 - asm("movw %%ds,%0" : "=rm" (seg));
13532 + asm volatile("movw %%ds,%0" : "=rm" (seg));
13533 return seg;
13534 }
13535
13536 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13537 index b5bb498..74110e8 100644
13538 --- a/arch/x86/boot/compressed/Makefile
13539 +++ b/arch/x86/boot/compressed/Makefile
13540 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13541 KBUILD_CFLAGS += -mno-mmx -mno-sse
13542 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13543 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13544 +ifdef CONSTIFY_PLUGIN
13545 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13546 +endif
13547
13548 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13549 GCOV_PROFILE := n
13550 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13551 index a53440e..c3dbf1e 100644
13552 --- a/arch/x86/boot/compressed/efi_stub_32.S
13553 +++ b/arch/x86/boot/compressed/efi_stub_32.S
13554 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13555 * parameter 2, ..., param n. To make things easy, we save the return
13556 * address of efi_call_phys in a global variable.
13557 */
13558 - popl %ecx
13559 - movl %ecx, saved_return_addr(%edx)
13560 - /* get the function pointer into ECX*/
13561 - popl %ecx
13562 - movl %ecx, efi_rt_function_ptr(%edx)
13563 + popl saved_return_addr(%edx)
13564 + popl efi_rt_function_ptr(%edx)
13565
13566 /*
13567 * 3. Call the physical function.
13568 */
13569 - call *%ecx
13570 + call *efi_rt_function_ptr(%edx)
13571
13572 /*
13573 * 4. Balance the stack. And because EAX contain the return value,
13574 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13575 1: popl %edx
13576 subl $1b, %edx
13577
13578 - movl efi_rt_function_ptr(%edx), %ecx
13579 - pushl %ecx
13580 + pushl efi_rt_function_ptr(%edx)
13581
13582 /*
13583 * 10. Push the saved return address onto the stack and return.
13584 */
13585 - movl saved_return_addr(%edx), %ecx
13586 - pushl %ecx
13587 - ret
13588 + jmpl *saved_return_addr(%edx)
13589 ENDPROC(efi_call_phys)
13590 .previous
13591
13592 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13593 index 1d7fbbc..36ecd58 100644
13594 --- a/arch/x86/boot/compressed/head_32.S
13595 +++ b/arch/x86/boot/compressed/head_32.S
13596 @@ -140,10 +140,10 @@ preferred_addr:
13597 addl %eax, %ebx
13598 notl %eax
13599 andl %eax, %ebx
13600 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13601 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13602 jge 1f
13603 #endif
13604 - movl $LOAD_PHYSICAL_ADDR, %ebx
13605 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13606 1:
13607
13608 /* Target address to relocate to for decompression */
13609 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13610 index 6b1766c..ad465c9 100644
13611 --- a/arch/x86/boot/compressed/head_64.S
13612 +++ b/arch/x86/boot/compressed/head_64.S
13613 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13614 addl %eax, %ebx
13615 notl %eax
13616 andl %eax, %ebx
13617 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13618 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13619 jge 1f
13620 #endif
13621 - movl $LOAD_PHYSICAL_ADDR, %ebx
13622 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13623 1:
13624
13625 /* Target address to relocate to for decompression */
13626 @@ -322,10 +322,10 @@ preferred_addr:
13627 addq %rax, %rbp
13628 notq %rax
13629 andq %rax, %rbp
13630 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13631 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13632 jge 1f
13633 #endif
13634 - movq $LOAD_PHYSICAL_ADDR, %rbp
13635 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13636 1:
13637
13638 /* Target address to relocate to for decompression */
13639 @@ -434,8 +434,8 @@ gdt:
13640 .long gdt
13641 .word 0
13642 .quad 0x0000000000000000 /* NULL descriptor */
13643 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13644 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13645 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13646 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13647 .quad 0x0080890000000000 /* TS descriptor */
13648 .quad 0x0000000000000000 /* TS continued */
13649 gdt_end:
13650 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13651 index 30dd59a..cd9edc3 100644
13652 --- a/arch/x86/boot/compressed/misc.c
13653 +++ b/arch/x86/boot/compressed/misc.c
13654 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13655 * Calculate the delta between where vmlinux was linked to load
13656 * and where it was actually loaded.
13657 */
13658 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13659 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13660 if (!delta) {
13661 debug_putstr("No relocation needed... ");
13662 return;
13663 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13664 Elf32_Ehdr ehdr;
13665 Elf32_Phdr *phdrs, *phdr;
13666 #endif
13667 - void *dest;
13668 + void *dest, *prev;
13669 int i;
13670
13671 memcpy(&ehdr, output, sizeof(ehdr));
13672 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13673 case PT_LOAD:
13674 #ifdef CONFIG_RELOCATABLE
13675 dest = output;
13676 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13677 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13678 #else
13679 dest = (void *)(phdr->p_paddr);
13680 #endif
13681 memcpy(dest,
13682 output + phdr->p_offset,
13683 phdr->p_filesz);
13684 + if (i)
13685 + memset(prev, 0xff, dest - prev);
13686 + prev = dest + phdr->p_filesz;
13687 break;
13688 default: /* Ignore other PT_* */ break;
13689 }
13690 @@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13691 error("Destination address too large");
13692 #endif
13693 #ifndef CONFIG_RELOCATABLE
13694 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13695 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13696 error("Wrong destination address");
13697 #endif
13698
13699 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13700 index 1fd7d57..0f7d096 100644
13701 --- a/arch/x86/boot/cpucheck.c
13702 +++ b/arch/x86/boot/cpucheck.c
13703 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13704 u32 ecx = MSR_K7_HWCR;
13705 u32 eax, edx;
13706
13707 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13708 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13709 eax &= ~(1 << 15);
13710 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13711 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13712
13713 get_cpuflags(); /* Make sure it really did something */
13714 err = check_cpuflags();
13715 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13716 u32 ecx = MSR_VIA_FCR;
13717 u32 eax, edx;
13718
13719 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13720 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13721 eax |= (1<<1)|(1<<7);
13722 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13723 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13724
13725 set_bit(X86_FEATURE_CX8, cpu.flags);
13726 err = check_cpuflags();
13727 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13728 u32 eax, edx;
13729 u32 level = 1;
13730
13731 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13732 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13733 - asm("cpuid"
13734 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13735 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13736 + asm volatile("cpuid"
13737 : "+a" (level), "=d" (cpu.flags[0])
13738 : : "ecx", "ebx");
13739 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13740 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13741
13742 err = check_cpuflags();
13743 } else if (err == 0x01 &&
13744 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13745 index 16ef025..91e033b 100644
13746 --- a/arch/x86/boot/header.S
13747 +++ b/arch/x86/boot/header.S
13748 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13749 # single linked list of
13750 # struct setup_data
13751
13752 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13753 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13754
13755 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13756 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13757 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13758 +#else
13759 #define VO_INIT_SIZE (VO__end - VO__text)
13760 +#endif
13761 #if ZO_INIT_SIZE > VO_INIT_SIZE
13762 #define INIT_SIZE ZO_INIT_SIZE
13763 #else
13764 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13765 index db75d07..8e6d0af 100644
13766 --- a/arch/x86/boot/memory.c
13767 +++ b/arch/x86/boot/memory.c
13768 @@ -19,7 +19,7 @@
13769
13770 static int detect_memory_e820(void)
13771 {
13772 - int count = 0;
13773 + unsigned int count = 0;
13774 struct biosregs ireg, oreg;
13775 struct e820entry *desc = boot_params.e820_map;
13776 static struct e820entry buf; /* static so it is zeroed */
13777 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13778 index ba3e100..6501b8f 100644
13779 --- a/arch/x86/boot/video-vesa.c
13780 +++ b/arch/x86/boot/video-vesa.c
13781 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13782
13783 boot_params.screen_info.vesapm_seg = oreg.es;
13784 boot_params.screen_info.vesapm_off = oreg.di;
13785 + boot_params.screen_info.vesapm_size = oreg.cx;
13786 }
13787
13788 /*
13789 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13790 index 43eda28..5ab5fdb 100644
13791 --- a/arch/x86/boot/video.c
13792 +++ b/arch/x86/boot/video.c
13793 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13794 static unsigned int get_entry(void)
13795 {
13796 char entry_buf[4];
13797 - int i, len = 0;
13798 + unsigned int i, len = 0;
13799 int key;
13800 unsigned int v;
13801
13802 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13803 index 9105655..41779c1 100644
13804 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13805 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13806 @@ -8,6 +8,8 @@
13807 * including this sentence is retained in full.
13808 */
13809
13810 +#include <asm/alternative-asm.h>
13811 +
13812 .extern crypto_ft_tab
13813 .extern crypto_it_tab
13814 .extern crypto_fl_tab
13815 @@ -70,6 +72,8 @@
13816 je B192; \
13817 leaq 32(r9),r9;
13818
13819 +#define ret pax_force_retaddr; ret
13820 +
13821 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13822 movq r1,r2; \
13823 movq r3,r4; \
13824 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13825 index 477e9d7..c92c7d8 100644
13826 --- a/arch/x86/crypto/aesni-intel_asm.S
13827 +++ b/arch/x86/crypto/aesni-intel_asm.S
13828 @@ -31,6 +31,7 @@
13829
13830 #include <linux/linkage.h>
13831 #include <asm/inst.h>
13832 +#include <asm/alternative-asm.h>
13833
13834 #ifdef __x86_64__
13835 .data
13836 @@ -205,7 +206,7 @@ enc: .octa 0x2
13837 * num_initial_blocks = b mod 4
13838 * encrypt the initial num_initial_blocks blocks and apply ghash on
13839 * the ciphertext
13840 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13841 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13842 * are clobbered
13843 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13844 */
13845 @@ -214,8 +215,8 @@ enc: .octa 0x2
13846 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13847 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13848 mov arg7, %r10 # %r10 = AAD
13849 - mov arg8, %r12 # %r12 = aadLen
13850 - mov %r12, %r11
13851 + mov arg8, %r15 # %r15 = aadLen
13852 + mov %r15, %r11
13853 pxor %xmm\i, %xmm\i
13854 _get_AAD_loop\num_initial_blocks\operation:
13855 movd (%r10), \TMP1
13856 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13857 psrldq $4, %xmm\i
13858 pxor \TMP1, %xmm\i
13859 add $4, %r10
13860 - sub $4, %r12
13861 + sub $4, %r15
13862 jne _get_AAD_loop\num_initial_blocks\operation
13863 cmp $16, %r11
13864 je _get_AAD_loop2_done\num_initial_blocks\operation
13865 - mov $16, %r12
13866 + mov $16, %r15
13867 _get_AAD_loop2\num_initial_blocks\operation:
13868 psrldq $4, %xmm\i
13869 - sub $4, %r12
13870 - cmp %r11, %r12
13871 + sub $4, %r15
13872 + cmp %r11, %r15
13873 jne _get_AAD_loop2\num_initial_blocks\operation
13874 _get_AAD_loop2_done\num_initial_blocks\operation:
13875 movdqa SHUF_MASK(%rip), %xmm14
13876 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13877 * num_initial_blocks = b mod 4
13878 * encrypt the initial num_initial_blocks blocks and apply ghash on
13879 * the ciphertext
13880 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13881 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13882 * are clobbered
13883 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13884 */
13885 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13886 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13887 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13888 mov arg7, %r10 # %r10 = AAD
13889 - mov arg8, %r12 # %r12 = aadLen
13890 - mov %r12, %r11
13891 + mov arg8, %r15 # %r15 = aadLen
13892 + mov %r15, %r11
13893 pxor %xmm\i, %xmm\i
13894 _get_AAD_loop\num_initial_blocks\operation:
13895 movd (%r10), \TMP1
13896 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13897 psrldq $4, %xmm\i
13898 pxor \TMP1, %xmm\i
13899 add $4, %r10
13900 - sub $4, %r12
13901 + sub $4, %r15
13902 jne _get_AAD_loop\num_initial_blocks\operation
13903 cmp $16, %r11
13904 je _get_AAD_loop2_done\num_initial_blocks\operation
13905 - mov $16, %r12
13906 + mov $16, %r15
13907 _get_AAD_loop2\num_initial_blocks\operation:
13908 psrldq $4, %xmm\i
13909 - sub $4, %r12
13910 - cmp %r11, %r12
13911 + sub $4, %r15
13912 + cmp %r11, %r15
13913 jne _get_AAD_loop2\num_initial_blocks\operation
13914 _get_AAD_loop2_done\num_initial_blocks\operation:
13915 movdqa SHUF_MASK(%rip), %xmm14
13916 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13917 *
13918 *****************************************************************************/
13919 ENTRY(aesni_gcm_dec)
13920 - push %r12
13921 + push %r15
13922 push %r13
13923 push %r14
13924 mov %rsp, %r14
13925 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13926 */
13927 sub $VARIABLE_OFFSET, %rsp
13928 and $~63, %rsp # align rsp to 64 bytes
13929 - mov %arg6, %r12
13930 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13931 + mov %arg6, %r15
13932 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13933 movdqa SHUF_MASK(%rip), %xmm2
13934 PSHUFB_XMM %xmm2, %xmm13
13935
13936 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13937 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13938 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13939 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13940 - mov %r13, %r12
13941 - and $(3<<4), %r12
13942 + mov %r13, %r15
13943 + and $(3<<4), %r15
13944 jz _initial_num_blocks_is_0_decrypt
13945 - cmp $(2<<4), %r12
13946 + cmp $(2<<4), %r15
13947 jb _initial_num_blocks_is_1_decrypt
13948 je _initial_num_blocks_is_2_decrypt
13949 _initial_num_blocks_is_3_decrypt:
13950 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13951 sub $16, %r11
13952 add %r13, %r11
13953 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13954 - lea SHIFT_MASK+16(%rip), %r12
13955 - sub %r13, %r12
13956 + lea SHIFT_MASK+16(%rip), %r15
13957 + sub %r13, %r15
13958 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13959 # (%r13 is the number of bytes in plaintext mod 16)
13960 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13961 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13962 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13963
13964 movdqa %xmm1, %xmm2
13965 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13966 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13967 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13968 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13969 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13970 pand %xmm1, %xmm2
13971 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13972 sub $1, %r13
13973 jne _less_than_8_bytes_left_decrypt
13974 _multiple_of_16_bytes_decrypt:
13975 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13976 - shl $3, %r12 # convert into number of bits
13977 - movd %r12d, %xmm15 # len(A) in %xmm15
13978 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13979 + shl $3, %r15 # convert into number of bits
13980 + movd %r15d, %xmm15 # len(A) in %xmm15
13981 shl $3, %arg4 # len(C) in bits (*128)
13982 MOVQ_R64_XMM %arg4, %xmm1
13983 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13984 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13985 mov %r14, %rsp
13986 pop %r14
13987 pop %r13
13988 - pop %r12
13989 + pop %r15
13990 + pax_force_retaddr
13991 ret
13992 ENDPROC(aesni_gcm_dec)
13993
13994 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13995 * poly = x^128 + x^127 + x^126 + x^121 + 1
13996 ***************************************************************************/
13997 ENTRY(aesni_gcm_enc)
13998 - push %r12
13999 + push %r15
14000 push %r13
14001 push %r14
14002 mov %rsp, %r14
14003 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
14004 #
14005 sub $VARIABLE_OFFSET, %rsp
14006 and $~63, %rsp
14007 - mov %arg6, %r12
14008 - movdqu (%r12), %xmm13
14009 + mov %arg6, %r15
14010 + movdqu (%r15), %xmm13
14011 movdqa SHUF_MASK(%rip), %xmm2
14012 PSHUFB_XMM %xmm2, %xmm13
14013
14014 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
14015 movdqa %xmm13, HashKey(%rsp)
14016 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
14017 and $-16, %r13
14018 - mov %r13, %r12
14019 + mov %r13, %r15
14020
14021 # Encrypt first few blocks
14022
14023 - and $(3<<4), %r12
14024 + and $(3<<4), %r15
14025 jz _initial_num_blocks_is_0_encrypt
14026 - cmp $(2<<4), %r12
14027 + cmp $(2<<4), %r15
14028 jb _initial_num_blocks_is_1_encrypt
14029 je _initial_num_blocks_is_2_encrypt
14030 _initial_num_blocks_is_3_encrypt:
14031 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
14032 sub $16, %r11
14033 add %r13, %r11
14034 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
14035 - lea SHIFT_MASK+16(%rip), %r12
14036 - sub %r13, %r12
14037 + lea SHIFT_MASK+16(%rip), %r15
14038 + sub %r13, %r15
14039 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
14040 # (%r13 is the number of bytes in plaintext mod 16)
14041 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
14042 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
14043 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
14044 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
14045 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
14046 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
14047 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
14048 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
14049 movdqa SHUF_MASK(%rip), %xmm10
14050 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
14051 sub $1, %r13
14052 jne _less_than_8_bytes_left_encrypt
14053 _multiple_of_16_bytes_encrypt:
14054 - mov arg8, %r12 # %r12 = addLen (number of bytes)
14055 - shl $3, %r12
14056 - movd %r12d, %xmm15 # len(A) in %xmm15
14057 + mov arg8, %r15 # %r15 = addLen (number of bytes)
14058 + shl $3, %r15
14059 + movd %r15d, %xmm15 # len(A) in %xmm15
14060 shl $3, %arg4 # len(C) in bits (*128)
14061 MOVQ_R64_XMM %arg4, %xmm1
14062 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
14063 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
14064 mov %r14, %rsp
14065 pop %r14
14066 pop %r13
14067 - pop %r12
14068 + pop %r15
14069 + pax_force_retaddr
14070 ret
14071 ENDPROC(aesni_gcm_enc)
14072
14073 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
14074 pxor %xmm1, %xmm0
14075 movaps %xmm0, (TKEYP)
14076 add $0x10, TKEYP
14077 + pax_force_retaddr
14078 ret
14079 ENDPROC(_key_expansion_128)
14080 ENDPROC(_key_expansion_256a)
14081 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
14082 shufps $0b01001110, %xmm2, %xmm1
14083 movaps %xmm1, 0x10(TKEYP)
14084 add $0x20, TKEYP
14085 + pax_force_retaddr
14086 ret
14087 ENDPROC(_key_expansion_192a)
14088
14089 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
14090
14091 movaps %xmm0, (TKEYP)
14092 add $0x10, TKEYP
14093 + pax_force_retaddr
14094 ret
14095 ENDPROC(_key_expansion_192b)
14096
14097 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
14098 pxor %xmm1, %xmm2
14099 movaps %xmm2, (TKEYP)
14100 add $0x10, TKEYP
14101 + pax_force_retaddr
14102 ret
14103 ENDPROC(_key_expansion_256b)
14104
14105 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
14106 #ifndef __x86_64__
14107 popl KEYP
14108 #endif
14109 + pax_force_retaddr
14110 ret
14111 ENDPROC(aesni_set_key)
14112
14113 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
14114 popl KLEN
14115 popl KEYP
14116 #endif
14117 + pax_force_retaddr
14118 ret
14119 ENDPROC(aesni_enc)
14120
14121 @@ -1974,6 +1983,7 @@ _aesni_enc1:
14122 AESENC KEY STATE
14123 movaps 0x70(TKEYP), KEY
14124 AESENCLAST KEY STATE
14125 + pax_force_retaddr
14126 ret
14127 ENDPROC(_aesni_enc1)
14128
14129 @@ -2083,6 +2093,7 @@ _aesni_enc4:
14130 AESENCLAST KEY STATE2
14131 AESENCLAST KEY STATE3
14132 AESENCLAST KEY STATE4
14133 + pax_force_retaddr
14134 ret
14135 ENDPROC(_aesni_enc4)
14136
14137 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
14138 popl KLEN
14139 popl KEYP
14140 #endif
14141 + pax_force_retaddr
14142 ret
14143 ENDPROC(aesni_dec)
14144
14145 @@ -2164,6 +2176,7 @@ _aesni_dec1:
14146 AESDEC KEY STATE
14147 movaps 0x70(TKEYP), KEY
14148 AESDECLAST KEY STATE
14149 + pax_force_retaddr
14150 ret
14151 ENDPROC(_aesni_dec1)
14152
14153 @@ -2273,6 +2286,7 @@ _aesni_dec4:
14154 AESDECLAST KEY STATE2
14155 AESDECLAST KEY STATE3
14156 AESDECLAST KEY STATE4
14157 + pax_force_retaddr
14158 ret
14159 ENDPROC(_aesni_dec4)
14160
14161 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
14162 popl KEYP
14163 popl LEN
14164 #endif
14165 + pax_force_retaddr
14166 ret
14167 ENDPROC(aesni_ecb_enc)
14168
14169 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
14170 popl KEYP
14171 popl LEN
14172 #endif
14173 + pax_force_retaddr
14174 ret
14175 ENDPROC(aesni_ecb_dec)
14176
14177 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
14178 popl LEN
14179 popl IVP
14180 #endif
14181 + pax_force_retaddr
14182 ret
14183 ENDPROC(aesni_cbc_enc)
14184
14185 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
14186 popl LEN
14187 popl IVP
14188 #endif
14189 + pax_force_retaddr
14190 ret
14191 ENDPROC(aesni_cbc_dec)
14192
14193 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
14194 mov $1, TCTR_LOW
14195 MOVQ_R64_XMM TCTR_LOW INC
14196 MOVQ_R64_XMM CTR TCTR_LOW
14197 + pax_force_retaddr
14198 ret
14199 ENDPROC(_aesni_inc_init)
14200
14201 @@ -2579,6 +2598,7 @@ _aesni_inc:
14202 .Linc_low:
14203 movaps CTR, IV
14204 PSHUFB_XMM BSWAP_MASK IV
14205 + pax_force_retaddr
14206 ret
14207 ENDPROC(_aesni_inc)
14208
14209 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
14210 .Lctr_enc_ret:
14211 movups IV, (IVP)
14212 .Lctr_enc_just_ret:
14213 + pax_force_retaddr
14214 ret
14215 ENDPROC(aesni_ctr_enc)
14216
14217 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
14218 pxor INC, STATE4
14219 movdqu STATE4, 0x70(OUTP)
14220
14221 + pax_force_retaddr
14222 ret
14223 ENDPROC(aesni_xts_crypt8)
14224
14225 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14226 index 246c670..466e2d6 100644
14227 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
14228 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14229 @@ -21,6 +21,7 @@
14230 */
14231
14232 #include <linux/linkage.h>
14233 +#include <asm/alternative-asm.h>
14234
14235 .file "blowfish-x86_64-asm.S"
14236 .text
14237 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
14238 jnz .L__enc_xor;
14239
14240 write_block();
14241 + pax_force_retaddr
14242 ret;
14243 .L__enc_xor:
14244 xor_block();
14245 + pax_force_retaddr
14246 ret;
14247 ENDPROC(__blowfish_enc_blk)
14248
14249 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
14250
14251 movq %r11, %rbp;
14252
14253 + pax_force_retaddr
14254 ret;
14255 ENDPROC(blowfish_dec_blk)
14256
14257 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
14258
14259 popq %rbx;
14260 popq %rbp;
14261 + pax_force_retaddr
14262 ret;
14263
14264 .L__enc_xor4:
14265 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
14266
14267 popq %rbx;
14268 popq %rbp;
14269 + pax_force_retaddr
14270 ret;
14271 ENDPROC(__blowfish_enc_blk_4way)
14272
14273 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
14274 popq %rbx;
14275 popq %rbp;
14276
14277 + pax_force_retaddr
14278 ret;
14279 ENDPROC(blowfish_dec_blk_4way)
14280 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14281 index ce71f92..1dce7ec 100644
14282 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14283 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14284 @@ -16,6 +16,7 @@
14285 */
14286
14287 #include <linux/linkage.h>
14288 +#include <asm/alternative-asm.h>
14289
14290 #define CAMELLIA_TABLE_BYTE_LEN 272
14291
14292 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14293 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
14294 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
14295 %rcx, (%r9));
14296 + pax_force_retaddr
14297 ret;
14298 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14299
14300 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14301 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
14302 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
14303 %rax, (%r9));
14304 + pax_force_retaddr
14305 ret;
14306 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14307
14308 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
14309 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14310 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
14311
14312 + pax_force_retaddr
14313 ret;
14314
14315 .align 8
14316 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
14317 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14318 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
14319
14320 + pax_force_retaddr
14321 ret;
14322
14323 .align 8
14324 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
14325 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14326 %xmm8, %rsi);
14327
14328 + pax_force_retaddr
14329 ret;
14330 ENDPROC(camellia_ecb_enc_16way)
14331
14332 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
14333 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14334 %xmm8, %rsi);
14335
14336 + pax_force_retaddr
14337 ret;
14338 ENDPROC(camellia_ecb_dec_16way)
14339
14340 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
14341 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14342 %xmm8, %rsi);
14343
14344 + pax_force_retaddr
14345 ret;
14346 ENDPROC(camellia_cbc_dec_16way)
14347
14348 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
14349 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14350 %xmm8, %rsi);
14351
14352 + pax_force_retaddr
14353 ret;
14354 ENDPROC(camellia_ctr_16way)
14355
14356 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
14357 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14358 %xmm8, %rsi);
14359
14360 + pax_force_retaddr
14361 ret;
14362 ENDPROC(camellia_xts_crypt_16way)
14363
14364 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14365 index 0e0b886..5a3123c 100644
14366 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14367 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14368 @@ -11,6 +11,7 @@
14369 */
14370
14371 #include <linux/linkage.h>
14372 +#include <asm/alternative-asm.h>
14373
14374 #define CAMELLIA_TABLE_BYTE_LEN 272
14375
14376 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14377 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
14378 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
14379 %rcx, (%r9));
14380 + pax_force_retaddr
14381 ret;
14382 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14383
14384 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14385 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
14386 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
14387 %rax, (%r9));
14388 + pax_force_retaddr
14389 ret;
14390 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14391
14392 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
14393 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14394 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
14395
14396 + pax_force_retaddr
14397 ret;
14398
14399 .align 8
14400 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
14401 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14402 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
14403
14404 + pax_force_retaddr
14405 ret;
14406
14407 .align 8
14408 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
14409
14410 vzeroupper;
14411
14412 + pax_force_retaddr
14413 ret;
14414 ENDPROC(camellia_ecb_enc_32way)
14415
14416 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
14417
14418 vzeroupper;
14419
14420 + pax_force_retaddr
14421 ret;
14422 ENDPROC(camellia_ecb_dec_32way)
14423
14424 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
14425
14426 vzeroupper;
14427
14428 + pax_force_retaddr
14429 ret;
14430 ENDPROC(camellia_cbc_dec_32way)
14431
14432 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
14433
14434 vzeroupper;
14435
14436 + pax_force_retaddr
14437 ret;
14438 ENDPROC(camellia_ctr_32way)
14439
14440 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
14441
14442 vzeroupper;
14443
14444 + pax_force_retaddr
14445 ret;
14446 ENDPROC(camellia_xts_crypt_32way)
14447
14448 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
14449 index 310319c..db3d7b5 100644
14450 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
14451 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
14452 @@ -21,6 +21,7 @@
14453 */
14454
14455 #include <linux/linkage.h>
14456 +#include <asm/alternative-asm.h>
14457
14458 .file "camellia-x86_64-asm_64.S"
14459 .text
14460 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
14461 enc_outunpack(mov, RT1);
14462
14463 movq RRBP, %rbp;
14464 + pax_force_retaddr
14465 ret;
14466
14467 .L__enc_xor:
14468 enc_outunpack(xor, RT1);
14469
14470 movq RRBP, %rbp;
14471 + pax_force_retaddr
14472 ret;
14473 ENDPROC(__camellia_enc_blk)
14474
14475 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
14476 dec_outunpack();
14477
14478 movq RRBP, %rbp;
14479 + pax_force_retaddr
14480 ret;
14481 ENDPROC(camellia_dec_blk)
14482
14483 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
14484
14485 movq RRBP, %rbp;
14486 popq %rbx;
14487 + pax_force_retaddr
14488 ret;
14489
14490 .L__enc2_xor:
14491 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
14492
14493 movq RRBP, %rbp;
14494 popq %rbx;
14495 + pax_force_retaddr
14496 ret;
14497 ENDPROC(__camellia_enc_blk_2way)
14498
14499 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
14500
14501 movq RRBP, %rbp;
14502 movq RXOR, %rbx;
14503 + pax_force_retaddr
14504 ret;
14505 ENDPROC(camellia_dec_blk_2way)
14506 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14507 index c35fd5d..2d8c7db 100644
14508 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14509 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14510 @@ -24,6 +24,7 @@
14511 */
14512
14513 #include <linux/linkage.h>
14514 +#include <asm/alternative-asm.h>
14515
14516 .file "cast5-avx-x86_64-asm_64.S"
14517
14518 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
14519 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14520 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14521
14522 + pax_force_retaddr
14523 ret;
14524 ENDPROC(__cast5_enc_blk16)
14525
14526 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
14527 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14528 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14529
14530 + pax_force_retaddr
14531 ret;
14532
14533 .L__skip_dec:
14534 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14535 vmovdqu RR4, (6*4*4)(%r11);
14536 vmovdqu RL4, (7*4*4)(%r11);
14537
14538 + pax_force_retaddr
14539 ret;
14540 ENDPROC(cast5_ecb_enc_16way)
14541
14542 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14543 vmovdqu RR4, (6*4*4)(%r11);
14544 vmovdqu RL4, (7*4*4)(%r11);
14545
14546 + pax_force_retaddr
14547 ret;
14548 ENDPROC(cast5_ecb_dec_16way)
14549
14550 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14551 * %rdx: src
14552 */
14553
14554 - pushq %r12;
14555 + pushq %r14;
14556
14557 movq %rsi, %r11;
14558 - movq %rdx, %r12;
14559 + movq %rdx, %r14;
14560
14561 vmovdqu (0*16)(%rdx), RL1;
14562 vmovdqu (1*16)(%rdx), RR1;
14563 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14564 call __cast5_dec_blk16;
14565
14566 /* xor with src */
14567 - vmovq (%r12), RX;
14568 + vmovq (%r14), RX;
14569 vpshufd $0x4f, RX, RX;
14570 vpxor RX, RR1, RR1;
14571 - vpxor 0*16+8(%r12), RL1, RL1;
14572 - vpxor 1*16+8(%r12), RR2, RR2;
14573 - vpxor 2*16+8(%r12), RL2, RL2;
14574 - vpxor 3*16+8(%r12), RR3, RR3;
14575 - vpxor 4*16+8(%r12), RL3, RL3;
14576 - vpxor 5*16+8(%r12), RR4, RR4;
14577 - vpxor 6*16+8(%r12), RL4, RL4;
14578 + vpxor 0*16+8(%r14), RL1, RL1;
14579 + vpxor 1*16+8(%r14), RR2, RR2;
14580 + vpxor 2*16+8(%r14), RL2, RL2;
14581 + vpxor 3*16+8(%r14), RR3, RR3;
14582 + vpxor 4*16+8(%r14), RL3, RL3;
14583 + vpxor 5*16+8(%r14), RR4, RR4;
14584 + vpxor 6*16+8(%r14), RL4, RL4;
14585
14586 vmovdqu RR1, (0*16)(%r11);
14587 vmovdqu RL1, (1*16)(%r11);
14588 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14589 vmovdqu RR4, (6*16)(%r11);
14590 vmovdqu RL4, (7*16)(%r11);
14591
14592 - popq %r12;
14593 + popq %r14;
14594
14595 + pax_force_retaddr
14596 ret;
14597 ENDPROC(cast5_cbc_dec_16way)
14598
14599 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14600 * %rcx: iv (big endian, 64bit)
14601 */
14602
14603 - pushq %r12;
14604 + pushq %r14;
14605
14606 movq %rsi, %r11;
14607 - movq %rdx, %r12;
14608 + movq %rdx, %r14;
14609
14610 vpcmpeqd RTMP, RTMP, RTMP;
14611 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14612 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14613 call __cast5_enc_blk16;
14614
14615 /* dst = src ^ iv */
14616 - vpxor (0*16)(%r12), RR1, RR1;
14617 - vpxor (1*16)(%r12), RL1, RL1;
14618 - vpxor (2*16)(%r12), RR2, RR2;
14619 - vpxor (3*16)(%r12), RL2, RL2;
14620 - vpxor (4*16)(%r12), RR3, RR3;
14621 - vpxor (5*16)(%r12), RL3, RL3;
14622 - vpxor (6*16)(%r12), RR4, RR4;
14623 - vpxor (7*16)(%r12), RL4, RL4;
14624 + vpxor (0*16)(%r14), RR1, RR1;
14625 + vpxor (1*16)(%r14), RL1, RL1;
14626 + vpxor (2*16)(%r14), RR2, RR2;
14627 + vpxor (3*16)(%r14), RL2, RL2;
14628 + vpxor (4*16)(%r14), RR3, RR3;
14629 + vpxor (5*16)(%r14), RL3, RL3;
14630 + vpxor (6*16)(%r14), RR4, RR4;
14631 + vpxor (7*16)(%r14), RL4, RL4;
14632 vmovdqu RR1, (0*16)(%r11);
14633 vmovdqu RL1, (1*16)(%r11);
14634 vmovdqu RR2, (2*16)(%r11);
14635 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14636 vmovdqu RR4, (6*16)(%r11);
14637 vmovdqu RL4, (7*16)(%r11);
14638
14639 - popq %r12;
14640 + popq %r14;
14641
14642 + pax_force_retaddr
14643 ret;
14644 ENDPROC(cast5_ctr_16way)
14645 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14646 index e3531f8..e123f35 100644
14647 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14648 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14649 @@ -24,6 +24,7 @@
14650 */
14651
14652 #include <linux/linkage.h>
14653 +#include <asm/alternative-asm.h>
14654 #include "glue_helper-asm-avx.S"
14655
14656 .file "cast6-avx-x86_64-asm_64.S"
14657 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14658 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14659 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14660
14661 + pax_force_retaddr
14662 ret;
14663 ENDPROC(__cast6_enc_blk8)
14664
14665 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14666 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14667 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14668
14669 + pax_force_retaddr
14670 ret;
14671 ENDPROC(__cast6_dec_blk8)
14672
14673 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14674
14675 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14676
14677 + pax_force_retaddr
14678 ret;
14679 ENDPROC(cast6_ecb_enc_8way)
14680
14681 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14682
14683 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14684
14685 + pax_force_retaddr
14686 ret;
14687 ENDPROC(cast6_ecb_dec_8way)
14688
14689 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14690 * %rdx: src
14691 */
14692
14693 - pushq %r12;
14694 + pushq %r14;
14695
14696 movq %rsi, %r11;
14697 - movq %rdx, %r12;
14698 + movq %rdx, %r14;
14699
14700 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14701
14702 call __cast6_dec_blk8;
14703
14704 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14705 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14706
14707 - popq %r12;
14708 + popq %r14;
14709
14710 + pax_force_retaddr
14711 ret;
14712 ENDPROC(cast6_cbc_dec_8way)
14713
14714 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14715 * %rcx: iv (little endian, 128bit)
14716 */
14717
14718 - pushq %r12;
14719 + pushq %r14;
14720
14721 movq %rsi, %r11;
14722 - movq %rdx, %r12;
14723 + movq %rdx, %r14;
14724
14725 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14726 RD2, RX, RKR, RKM);
14727
14728 call __cast6_enc_blk8;
14729
14730 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14731 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14732
14733 - popq %r12;
14734 + popq %r14;
14735
14736 + pax_force_retaddr
14737 ret;
14738 ENDPROC(cast6_ctr_8way)
14739
14740 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14741 /* dst <= regs xor IVs(in dst) */
14742 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14743
14744 + pax_force_retaddr
14745 ret;
14746 ENDPROC(cast6_xts_enc_8way)
14747
14748 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14749 /* dst <= regs xor IVs(in dst) */
14750 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14751
14752 + pax_force_retaddr
14753 ret;
14754 ENDPROC(cast6_xts_dec_8way)
14755 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14756 index 26d49eb..c0a8c84 100644
14757 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14758 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14759 @@ -45,6 +45,7 @@
14760
14761 #include <asm/inst.h>
14762 #include <linux/linkage.h>
14763 +#include <asm/alternative-asm.h>
14764
14765 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14766
14767 @@ -309,6 +310,7 @@ do_return:
14768 popq %rsi
14769 popq %rdi
14770 popq %rbx
14771 + pax_force_retaddr
14772 ret
14773
14774 ################################################################
14775 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14776 index 5d1e007..098cb4f 100644
14777 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14778 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14779 @@ -18,6 +18,7 @@
14780
14781 #include <linux/linkage.h>
14782 #include <asm/inst.h>
14783 +#include <asm/alternative-asm.h>
14784
14785 .data
14786
14787 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14788 psrlq $1, T2
14789 pxor T2, T1
14790 pxor T1, DATA
14791 + pax_force_retaddr
14792 ret
14793 ENDPROC(__clmul_gf128mul_ble)
14794
14795 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14796 call __clmul_gf128mul_ble
14797 PSHUFB_XMM BSWAP DATA
14798 movups DATA, (%rdi)
14799 + pax_force_retaddr
14800 ret
14801 ENDPROC(clmul_ghash_mul)
14802
14803 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14804 PSHUFB_XMM BSWAP DATA
14805 movups DATA, (%rdi)
14806 .Lupdate_just_ret:
14807 + pax_force_retaddr
14808 ret
14809 ENDPROC(clmul_ghash_update)
14810 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14811 index 9279e0b..c4b3d2c 100644
14812 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14813 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14814 @@ -1,4 +1,5 @@
14815 #include <linux/linkage.h>
14816 +#include <asm/alternative-asm.h>
14817
14818 # enter salsa20_encrypt_bytes
14819 ENTRY(salsa20_encrypt_bytes)
14820 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14821 add %r11,%rsp
14822 mov %rdi,%rax
14823 mov %rsi,%rdx
14824 + pax_force_retaddr
14825 ret
14826 # bytesatleast65:
14827 ._bytesatleast65:
14828 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14829 add %r11,%rsp
14830 mov %rdi,%rax
14831 mov %rsi,%rdx
14832 + pax_force_retaddr
14833 ret
14834 ENDPROC(salsa20_keysetup)
14835
14836 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14837 add %r11,%rsp
14838 mov %rdi,%rax
14839 mov %rsi,%rdx
14840 + pax_force_retaddr
14841 ret
14842 ENDPROC(salsa20_ivsetup)
14843 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14844 index 2f202f4..d9164d6 100644
14845 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14846 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14847 @@ -24,6 +24,7 @@
14848 */
14849
14850 #include <linux/linkage.h>
14851 +#include <asm/alternative-asm.h>
14852 #include "glue_helper-asm-avx.S"
14853
14854 .file "serpent-avx-x86_64-asm_64.S"
14855 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14856 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14857 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14858
14859 + pax_force_retaddr
14860 ret;
14861 ENDPROC(__serpent_enc_blk8_avx)
14862
14863 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14864 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14865 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14866
14867 + pax_force_retaddr
14868 ret;
14869 ENDPROC(__serpent_dec_blk8_avx)
14870
14871 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14872
14873 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14874
14875 + pax_force_retaddr
14876 ret;
14877 ENDPROC(serpent_ecb_enc_8way_avx)
14878
14879 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14880
14881 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14882
14883 + pax_force_retaddr
14884 ret;
14885 ENDPROC(serpent_ecb_dec_8way_avx)
14886
14887 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14888
14889 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14890
14891 + pax_force_retaddr
14892 ret;
14893 ENDPROC(serpent_cbc_dec_8way_avx)
14894
14895 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14896
14897 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14898
14899 + pax_force_retaddr
14900 ret;
14901 ENDPROC(serpent_ctr_8way_avx)
14902
14903 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14904 /* dst <= regs xor IVs(in dst) */
14905 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14906
14907 + pax_force_retaddr
14908 ret;
14909 ENDPROC(serpent_xts_enc_8way_avx)
14910
14911 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14912 /* dst <= regs xor IVs(in dst) */
14913 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14914
14915 + pax_force_retaddr
14916 ret;
14917 ENDPROC(serpent_xts_dec_8way_avx)
14918 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14919 index b222085..abd483c 100644
14920 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14921 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14922 @@ -15,6 +15,7 @@
14923 */
14924
14925 #include <linux/linkage.h>
14926 +#include <asm/alternative-asm.h>
14927 #include "glue_helper-asm-avx2.S"
14928
14929 .file "serpent-avx2-asm_64.S"
14930 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14931 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14932 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14933
14934 + pax_force_retaddr
14935 ret;
14936 ENDPROC(__serpent_enc_blk16)
14937
14938 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14939 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14940 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14941
14942 + pax_force_retaddr
14943 ret;
14944 ENDPROC(__serpent_dec_blk16)
14945
14946 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14947
14948 vzeroupper;
14949
14950 + pax_force_retaddr
14951 ret;
14952 ENDPROC(serpent_ecb_enc_16way)
14953
14954 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14955
14956 vzeroupper;
14957
14958 + pax_force_retaddr
14959 ret;
14960 ENDPROC(serpent_ecb_dec_16way)
14961
14962 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14963
14964 vzeroupper;
14965
14966 + pax_force_retaddr
14967 ret;
14968 ENDPROC(serpent_cbc_dec_16way)
14969
14970 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14971
14972 vzeroupper;
14973
14974 + pax_force_retaddr
14975 ret;
14976 ENDPROC(serpent_ctr_16way)
14977
14978 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14979
14980 vzeroupper;
14981
14982 + pax_force_retaddr
14983 ret;
14984 ENDPROC(serpent_xts_enc_16way)
14985
14986 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14987
14988 vzeroupper;
14989
14990 + pax_force_retaddr
14991 ret;
14992 ENDPROC(serpent_xts_dec_16way)
14993 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14994 index acc066c..1559cc4 100644
14995 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14996 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14997 @@ -25,6 +25,7 @@
14998 */
14999
15000 #include <linux/linkage.h>
15001 +#include <asm/alternative-asm.h>
15002
15003 .file "serpent-sse2-x86_64-asm_64.S"
15004 .text
15005 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
15006 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
15007 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
15008
15009 + pax_force_retaddr
15010 ret;
15011
15012 .L__enc_xor8:
15013 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
15014 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
15015
15016 + pax_force_retaddr
15017 ret;
15018 ENDPROC(__serpent_enc_blk_8way)
15019
15020 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
15021 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
15022 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
15023
15024 + pax_force_retaddr
15025 ret;
15026 ENDPROC(serpent_dec_blk_8way)
15027 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
15028 index a410950..9dfe7ad 100644
15029 --- a/arch/x86/crypto/sha1_ssse3_asm.S
15030 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
15031 @@ -29,6 +29,7 @@
15032 */
15033
15034 #include <linux/linkage.h>
15035 +#include <asm/alternative-asm.h>
15036
15037 #define CTX %rdi // arg1
15038 #define BUF %rsi // arg2
15039 @@ -75,9 +76,9 @@
15040
15041 push %rbx
15042 push %rbp
15043 - push %r12
15044 + push %r14
15045
15046 - mov %rsp, %r12
15047 + mov %rsp, %r14
15048 sub $64, %rsp # allocate workspace
15049 and $~15, %rsp # align stack
15050
15051 @@ -99,11 +100,12 @@
15052 xor %rax, %rax
15053 rep stosq
15054
15055 - mov %r12, %rsp # deallocate workspace
15056 + mov %r14, %rsp # deallocate workspace
15057
15058 - pop %r12
15059 + pop %r14
15060 pop %rbp
15061 pop %rbx
15062 + pax_force_retaddr
15063 ret
15064
15065 ENDPROC(\name)
15066 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
15067 index 642f156..51a513c 100644
15068 --- a/arch/x86/crypto/sha256-avx-asm.S
15069 +++ b/arch/x86/crypto/sha256-avx-asm.S
15070 @@ -49,6 +49,7 @@
15071
15072 #ifdef CONFIG_AS_AVX
15073 #include <linux/linkage.h>
15074 +#include <asm/alternative-asm.h>
15075
15076 ## assume buffers not aligned
15077 #define VMOVDQ vmovdqu
15078 @@ -460,6 +461,7 @@ done_hash:
15079 popq %r13
15080 popq %rbp
15081 popq %rbx
15082 + pax_force_retaddr
15083 ret
15084 ENDPROC(sha256_transform_avx)
15085
15086 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
15087 index 9e86944..3795e6a 100644
15088 --- a/arch/x86/crypto/sha256-avx2-asm.S
15089 +++ b/arch/x86/crypto/sha256-avx2-asm.S
15090 @@ -50,6 +50,7 @@
15091
15092 #ifdef CONFIG_AS_AVX2
15093 #include <linux/linkage.h>
15094 +#include <asm/alternative-asm.h>
15095
15096 ## assume buffers not aligned
15097 #define VMOVDQ vmovdqu
15098 @@ -720,6 +721,7 @@ done_hash:
15099 popq %r12
15100 popq %rbp
15101 popq %rbx
15102 + pax_force_retaddr
15103 ret
15104 ENDPROC(sha256_transform_rorx)
15105
15106 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
15107 index f833b74..8c62a9e 100644
15108 --- a/arch/x86/crypto/sha256-ssse3-asm.S
15109 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
15110 @@ -47,6 +47,7 @@
15111 ########################################################################
15112
15113 #include <linux/linkage.h>
15114 +#include <asm/alternative-asm.h>
15115
15116 ## assume buffers not aligned
15117 #define MOVDQ movdqu
15118 @@ -471,6 +472,7 @@ done_hash:
15119 popq %rbp
15120 popq %rbx
15121
15122 + pax_force_retaddr
15123 ret
15124 ENDPROC(sha256_transform_ssse3)
15125
15126 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
15127 index 974dde9..a823ff9 100644
15128 --- a/arch/x86/crypto/sha512-avx-asm.S
15129 +++ b/arch/x86/crypto/sha512-avx-asm.S
15130 @@ -49,6 +49,7 @@
15131
15132 #ifdef CONFIG_AS_AVX
15133 #include <linux/linkage.h>
15134 +#include <asm/alternative-asm.h>
15135
15136 .text
15137
15138 @@ -364,6 +365,7 @@ updateblock:
15139 mov frame_RSPSAVE(%rsp), %rsp
15140
15141 nowork:
15142 + pax_force_retaddr
15143 ret
15144 ENDPROC(sha512_transform_avx)
15145
15146 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
15147 index 568b961..ed20c37 100644
15148 --- a/arch/x86/crypto/sha512-avx2-asm.S
15149 +++ b/arch/x86/crypto/sha512-avx2-asm.S
15150 @@ -51,6 +51,7 @@
15151
15152 #ifdef CONFIG_AS_AVX2
15153 #include <linux/linkage.h>
15154 +#include <asm/alternative-asm.h>
15155
15156 .text
15157
15158 @@ -678,6 +679,7 @@ done_hash:
15159
15160 # Restore Stack Pointer
15161 mov frame_RSPSAVE(%rsp), %rsp
15162 + pax_force_retaddr
15163 ret
15164 ENDPROC(sha512_transform_rorx)
15165
15166 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
15167 index fb56855..6edd768 100644
15168 --- a/arch/x86/crypto/sha512-ssse3-asm.S
15169 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
15170 @@ -48,6 +48,7 @@
15171 ########################################################################
15172
15173 #include <linux/linkage.h>
15174 +#include <asm/alternative-asm.h>
15175
15176 .text
15177
15178 @@ -363,6 +364,7 @@ updateblock:
15179 mov frame_RSPSAVE(%rsp), %rsp
15180
15181 nowork:
15182 + pax_force_retaddr
15183 ret
15184 ENDPROC(sha512_transform_ssse3)
15185
15186 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15187 index 0505813..b067311 100644
15188 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15189 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15190 @@ -24,6 +24,7 @@
15191 */
15192
15193 #include <linux/linkage.h>
15194 +#include <asm/alternative-asm.h>
15195 #include "glue_helper-asm-avx.S"
15196
15197 .file "twofish-avx-x86_64-asm_64.S"
15198 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
15199 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
15200 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
15201
15202 + pax_force_retaddr
15203 ret;
15204 ENDPROC(__twofish_enc_blk8)
15205
15206 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
15207 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
15208 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
15209
15210 + pax_force_retaddr
15211 ret;
15212 ENDPROC(__twofish_dec_blk8)
15213
15214 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
15215
15216 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15217
15218 + pax_force_retaddr
15219 ret;
15220 ENDPROC(twofish_ecb_enc_8way)
15221
15222 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
15223
15224 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15225
15226 + pax_force_retaddr
15227 ret;
15228 ENDPROC(twofish_ecb_dec_8way)
15229
15230 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
15231 * %rdx: src
15232 */
15233
15234 - pushq %r12;
15235 + pushq %r14;
15236
15237 movq %rsi, %r11;
15238 - movq %rdx, %r12;
15239 + movq %rdx, %r14;
15240
15241 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15242
15243 call __twofish_dec_blk8;
15244
15245 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15246 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15247
15248 - popq %r12;
15249 + popq %r14;
15250
15251 + pax_force_retaddr
15252 ret;
15253 ENDPROC(twofish_cbc_dec_8way)
15254
15255 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
15256 * %rcx: iv (little endian, 128bit)
15257 */
15258
15259 - pushq %r12;
15260 + pushq %r14;
15261
15262 movq %rsi, %r11;
15263 - movq %rdx, %r12;
15264 + movq %rdx, %r14;
15265
15266 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
15267 RD2, RX0, RX1, RY0);
15268
15269 call __twofish_enc_blk8;
15270
15271 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15272 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15273
15274 - popq %r12;
15275 + popq %r14;
15276
15277 + pax_force_retaddr
15278 ret;
15279 ENDPROC(twofish_ctr_8way)
15280
15281 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
15282 /* dst <= regs xor IVs(in dst) */
15283 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15284
15285 + pax_force_retaddr
15286 ret;
15287 ENDPROC(twofish_xts_enc_8way)
15288
15289 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
15290 /* dst <= regs xor IVs(in dst) */
15291 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15292
15293 + pax_force_retaddr
15294 ret;
15295 ENDPROC(twofish_xts_dec_8way)
15296 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15297 index 1c3b7ce..02f578d 100644
15298 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15299 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15300 @@ -21,6 +21,7 @@
15301 */
15302
15303 #include <linux/linkage.h>
15304 +#include <asm/alternative-asm.h>
15305
15306 .file "twofish-x86_64-asm-3way.S"
15307 .text
15308 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
15309 popq %r13;
15310 popq %r14;
15311 popq %r15;
15312 + pax_force_retaddr
15313 ret;
15314
15315 .L__enc_xor3:
15316 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
15317 popq %r13;
15318 popq %r14;
15319 popq %r15;
15320 + pax_force_retaddr
15321 ret;
15322 ENDPROC(__twofish_enc_blk_3way)
15323
15324 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
15325 popq %r13;
15326 popq %r14;
15327 popq %r15;
15328 + pax_force_retaddr
15329 ret;
15330 ENDPROC(twofish_dec_blk_3way)
15331 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
15332 index a039d21..524b8b2 100644
15333 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
15334 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
15335 @@ -22,6 +22,7 @@
15336
15337 #include <linux/linkage.h>
15338 #include <asm/asm-offsets.h>
15339 +#include <asm/alternative-asm.h>
15340
15341 #define a_offset 0
15342 #define b_offset 4
15343 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
15344
15345 popq R1
15346 movq $1,%rax
15347 + pax_force_retaddr
15348 ret
15349 ENDPROC(twofish_enc_blk)
15350
15351 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
15352
15353 popq R1
15354 movq $1,%rax
15355 + pax_force_retaddr
15356 ret
15357 ENDPROC(twofish_dec_blk)
15358 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
15359 index d21ff89..6da8e6e 100644
15360 --- a/arch/x86/ia32/ia32_aout.c
15361 +++ b/arch/x86/ia32/ia32_aout.c
15362 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
15363 unsigned long dump_start, dump_size;
15364 struct user32 dump;
15365
15366 + memset(&dump, 0, sizeof(dump));
15367 +
15368 fs = get_fs();
15369 set_fs(KERNEL_DS);
15370 has_dumped = 1;
15371 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
15372 index f9e181a..300544c 100644
15373 --- a/arch/x86/ia32/ia32_signal.c
15374 +++ b/arch/x86/ia32/ia32_signal.c
15375 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
15376 if (__get_user(set.sig[0], &frame->sc.oldmask)
15377 || (_COMPAT_NSIG_WORDS > 1
15378 && __copy_from_user((((char *) &set.sig) + 4),
15379 - &frame->extramask,
15380 + frame->extramask,
15381 sizeof(frame->extramask))))
15382 goto badframe;
15383
15384 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
15385 sp -= frame_size;
15386 /* Align the stack pointer according to the i386 ABI,
15387 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
15388 - sp = ((sp + 4) & -16ul) - 4;
15389 + sp = ((sp - 12) & -16ul) - 4;
15390 return (void __user *) sp;
15391 }
15392
15393 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15394 } else {
15395 /* Return stub is in 32bit vsyscall page */
15396 if (current->mm->context.vdso)
15397 - restorer = current->mm->context.vdso +
15398 - selected_vdso32->sym___kernel_sigreturn;
15399 + restorer = (void __force_user *)(current->mm->context.vdso +
15400 + selected_vdso32->sym___kernel_sigreturn);
15401 else
15402 - restorer = &frame->retcode;
15403 + restorer = frame->retcode;
15404 }
15405
15406 put_user_try {
15407 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15408 * These are actually not used anymore, but left because some
15409 * gdb versions depend on them as a marker.
15410 */
15411 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15412 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15413 } put_user_catch(err);
15414
15415 if (err)
15416 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15417 0xb8,
15418 __NR_ia32_rt_sigreturn,
15419 0x80cd,
15420 - 0,
15421 + 0
15422 };
15423
15424 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
15425 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15426
15427 if (ksig->ka.sa.sa_flags & SA_RESTORER)
15428 restorer = ksig->ka.sa.sa_restorer;
15429 + else if (current->mm->context.vdso)
15430 + /* Return stub is in 32bit vsyscall page */
15431 + restorer = (void __force_user *)(current->mm->context.vdso +
15432 + selected_vdso32->sym___kernel_rt_sigreturn);
15433 else
15434 - restorer = current->mm->context.vdso +
15435 - selected_vdso32->sym___kernel_rt_sigreturn;
15436 + restorer = frame->retcode;
15437 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
15438
15439 /*
15440 * Not actually used anymore, but left because some gdb
15441 * versions need it.
15442 */
15443 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15444 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15445 } put_user_catch(err);
15446
15447 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
15448 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
15449 index 92a2e93..cd4d95f 100644
15450 --- a/arch/x86/ia32/ia32entry.S
15451 +++ b/arch/x86/ia32/ia32entry.S
15452 @@ -15,8 +15,10 @@
15453 #include <asm/irqflags.h>
15454 #include <asm/asm.h>
15455 #include <asm/smap.h>
15456 +#include <asm/pgtable.h>
15457 #include <linux/linkage.h>
15458 #include <linux/err.h>
15459 +#include <asm/alternative-asm.h>
15460
15461 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15462 #include <linux/elf-em.h>
15463 @@ -62,12 +64,12 @@
15464 */
15465 .macro LOAD_ARGS32 offset, _r9=0
15466 .if \_r9
15467 - movl \offset+16(%rsp),%r9d
15468 + movl \offset+R9(%rsp),%r9d
15469 .endif
15470 - movl \offset+40(%rsp),%ecx
15471 - movl \offset+48(%rsp),%edx
15472 - movl \offset+56(%rsp),%esi
15473 - movl \offset+64(%rsp),%edi
15474 + movl \offset+RCX(%rsp),%ecx
15475 + movl \offset+RDX(%rsp),%edx
15476 + movl \offset+RSI(%rsp),%esi
15477 + movl \offset+RDI(%rsp),%edi
15478 movl %eax,%eax /* zero extension */
15479 .endm
15480
15481 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
15482 ENDPROC(native_irq_enable_sysexit)
15483 #endif
15484
15485 + .macro pax_enter_kernel_user
15486 + pax_set_fptr_mask
15487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15488 + call pax_enter_kernel_user
15489 +#endif
15490 + .endm
15491 +
15492 + .macro pax_exit_kernel_user
15493 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15494 + call pax_exit_kernel_user
15495 +#endif
15496 +#ifdef CONFIG_PAX_RANDKSTACK
15497 + pushq %rax
15498 + pushq %r11
15499 + call pax_randomize_kstack
15500 + popq %r11
15501 + popq %rax
15502 +#endif
15503 + .endm
15504 +
15505 + .macro pax_erase_kstack
15506 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15507 + call pax_erase_kstack
15508 +#endif
15509 + .endm
15510 +
15511 /*
15512 * 32bit SYSENTER instruction entry.
15513 *
15514 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
15515 CFI_REGISTER rsp,rbp
15516 SWAPGS_UNSAFE_STACK
15517 movq PER_CPU_VAR(kernel_stack), %rsp
15518 - addq $(KERNEL_STACK_OFFSET),%rsp
15519 - /*
15520 - * No need to follow this irqs on/off section: the syscall
15521 - * disabled irqs, here we enable it straight after entry:
15522 - */
15523 - ENABLE_INTERRUPTS(CLBR_NONE)
15524 movl %ebp,%ebp /* zero extension */
15525 pushq_cfi $__USER32_DS
15526 /*CFI_REL_OFFSET ss,0*/
15527 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
15528 CFI_REL_OFFSET rsp,0
15529 pushfq_cfi
15530 /*CFI_REL_OFFSET rflags,0*/
15531 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15532 - CFI_REGISTER rip,r10
15533 + orl $X86_EFLAGS_IF,(%rsp)
15534 + GET_THREAD_INFO(%r11)
15535 + movl TI_sysenter_return(%r11), %r11d
15536 + CFI_REGISTER rip,r11
15537 pushq_cfi $__USER32_CS
15538 /*CFI_REL_OFFSET cs,0*/
15539 movl %eax, %eax
15540 - pushq_cfi %r10
15541 + pushq_cfi %r11
15542 CFI_REL_OFFSET rip,0
15543 pushq_cfi %rax
15544 cld
15545 SAVE_ARGS 0,1,0
15546 + pax_enter_kernel_user
15547 +
15548 +#ifdef CONFIG_PAX_RANDKSTACK
15549 + pax_erase_kstack
15550 +#endif
15551 +
15552 + /*
15553 + * No need to follow this irqs on/off section: the syscall
15554 + * disabled irqs, here we enable it straight after entry:
15555 + */
15556 + ENABLE_INTERRUPTS(CLBR_NONE)
15557 /* no need to do an access_ok check here because rbp has been
15558 32bit zero extended */
15559 +
15560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15561 + addq pax_user_shadow_base,%rbp
15562 + ASM_PAX_OPEN_USERLAND
15563 +#endif
15564 +
15565 ASM_STAC
15566 1: movl (%rbp),%ebp
15567 _ASM_EXTABLE(1b,ia32_badarg)
15568 ASM_CLAC
15569
15570 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15571 + ASM_PAX_CLOSE_USERLAND
15572 +#endif
15573 +
15574 /*
15575 * Sysenter doesn't filter flags, so we need to clear NT
15576 * ourselves. To save a few cycles, we can check whether
15577 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
15578 jnz sysenter_fix_flags
15579 sysenter_flags_fixed:
15580
15581 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15582 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15583 + GET_THREAD_INFO(%r11)
15584 + orl $TS_COMPAT,TI_status(%r11)
15585 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15586 CFI_REMEMBER_STATE
15587 jnz sysenter_tracesys
15588 cmpq $(IA32_NR_syscalls-1),%rax
15589 @@ -172,15 +218,18 @@ sysenter_do_call:
15590 sysenter_dispatch:
15591 call *ia32_sys_call_table(,%rax,8)
15592 movq %rax,RAX-ARGOFFSET(%rsp)
15593 + GET_THREAD_INFO(%r11)
15594 DISABLE_INTERRUPTS(CLBR_NONE)
15595 TRACE_IRQS_OFF
15596 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15597 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15598 jnz sysexit_audit
15599 sysexit_from_sys_call:
15600 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15601 + pax_exit_kernel_user
15602 + pax_erase_kstack
15603 + andl $~TS_COMPAT,TI_status(%r11)
15604 /* clear IF, that popfq doesn't enable interrupts early */
15605 - andl $~0x200,EFLAGS-R11(%rsp)
15606 - movl RIP-R11(%rsp),%edx /* User %eip */
15607 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15608 + movl RIP(%rsp),%edx /* User %eip */
15609 CFI_REGISTER rip,rdx
15610 RESTORE_ARGS 0,24,0,0,0,0
15611 xorq %r8,%r8
15612 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
15613 movl %eax,%esi /* 2nd arg: syscall number */
15614 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15615 call __audit_syscall_entry
15616 +
15617 + pax_erase_kstack
15618 +
15619 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15620 cmpq $(IA32_NR_syscalls-1),%rax
15621 ja ia32_badsys
15622 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
15623 .endm
15624
15625 .macro auditsys_exit exit
15626 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15627 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15628 jnz ia32_ret_from_sys_call
15629 TRACE_IRQS_ON
15630 ENABLE_INTERRUPTS(CLBR_NONE)
15631 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
15632 1: setbe %al /* 1 if error, 0 if not */
15633 movzbl %al,%edi /* zero-extend that into %edi */
15634 call __audit_syscall_exit
15635 + GET_THREAD_INFO(%r11)
15636 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15637 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15638 DISABLE_INTERRUPTS(CLBR_NONE)
15639 TRACE_IRQS_OFF
15640 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15641 + testl %edi,TI_flags(%r11)
15642 jz \exit
15643 CLEAR_RREGS -ARGOFFSET
15644 jmp int_with_check
15645 @@ -253,7 +306,7 @@ sysenter_fix_flags:
15646
15647 sysenter_tracesys:
15648 #ifdef CONFIG_AUDITSYSCALL
15649 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15650 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15651 jz sysenter_auditsys
15652 #endif
15653 SAVE_REST
15654 @@ -265,6 +318,9 @@ sysenter_tracesys:
15655 RESTORE_REST
15656 cmpq $(IA32_NR_syscalls-1),%rax
15657 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15658 +
15659 + pax_erase_kstack
15660 +
15661 jmp sysenter_do_call
15662 CFI_ENDPROC
15663 ENDPROC(ia32_sysenter_target)
15664 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
15665 ENTRY(ia32_cstar_target)
15666 CFI_STARTPROC32 simple
15667 CFI_SIGNAL_FRAME
15668 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15669 + CFI_DEF_CFA rsp,0
15670 CFI_REGISTER rip,rcx
15671 /*CFI_REGISTER rflags,r11*/
15672 SWAPGS_UNSAFE_STACK
15673 movl %esp,%r8d
15674 CFI_REGISTER rsp,r8
15675 movq PER_CPU_VAR(kernel_stack),%rsp
15676 + SAVE_ARGS 8*6,0,0
15677 + pax_enter_kernel_user
15678 +
15679 +#ifdef CONFIG_PAX_RANDKSTACK
15680 + pax_erase_kstack
15681 +#endif
15682 +
15683 /*
15684 * No need to follow this irqs on/off section: the syscall
15685 * disabled irqs and here we enable it straight after entry:
15686 */
15687 ENABLE_INTERRUPTS(CLBR_NONE)
15688 - SAVE_ARGS 8,0,0
15689 movl %eax,%eax /* zero extension */
15690 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15691 movq %rcx,RIP-ARGOFFSET(%rsp)
15692 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
15693 /* no need to do an access_ok check here because r8 has been
15694 32bit zero extended */
15695 /* hardware stack frame is complete now */
15696 +
15697 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15698 + ASM_PAX_OPEN_USERLAND
15699 + movq pax_user_shadow_base,%r8
15700 + addq RSP-ARGOFFSET(%rsp),%r8
15701 +#endif
15702 +
15703 ASM_STAC
15704 1: movl (%r8),%r9d
15705 _ASM_EXTABLE(1b,ia32_badarg)
15706 ASM_CLAC
15707 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15708 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15709 +
15710 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15711 + ASM_PAX_CLOSE_USERLAND
15712 +#endif
15713 +
15714 + GET_THREAD_INFO(%r11)
15715 + orl $TS_COMPAT,TI_status(%r11)
15716 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15717 CFI_REMEMBER_STATE
15718 jnz cstar_tracesys
15719 cmpq $IA32_NR_syscalls-1,%rax
15720 @@ -335,13 +410,16 @@ cstar_do_call:
15721 cstar_dispatch:
15722 call *ia32_sys_call_table(,%rax,8)
15723 movq %rax,RAX-ARGOFFSET(%rsp)
15724 + GET_THREAD_INFO(%r11)
15725 DISABLE_INTERRUPTS(CLBR_NONE)
15726 TRACE_IRQS_OFF
15727 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15728 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15729 jnz sysretl_audit
15730 sysretl_from_sys_call:
15731 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15732 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15733 + pax_exit_kernel_user
15734 + pax_erase_kstack
15735 + andl $~TS_COMPAT,TI_status(%r11)
15736 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15737 movl RIP-ARGOFFSET(%rsp),%ecx
15738 CFI_REGISTER rip,rcx
15739 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15740 @@ -368,7 +446,7 @@ sysretl_audit:
15741
15742 cstar_tracesys:
15743 #ifdef CONFIG_AUDITSYSCALL
15744 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15745 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15746 jz cstar_auditsys
15747 #endif
15748 xchgl %r9d,%ebp
15749 @@ -382,11 +460,19 @@ cstar_tracesys:
15750 xchgl %ebp,%r9d
15751 cmpq $(IA32_NR_syscalls-1),%rax
15752 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15753 +
15754 + pax_erase_kstack
15755 +
15756 jmp cstar_do_call
15757 END(ia32_cstar_target)
15758
15759 ia32_badarg:
15760 ASM_CLAC
15761 +
15762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15763 + ASM_PAX_CLOSE_USERLAND
15764 +#endif
15765 +
15766 movq $-EFAULT,%rax
15767 jmp ia32_sysret
15768 CFI_ENDPROC
15769 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15770 CFI_REL_OFFSET rip,RIP-RIP
15771 PARAVIRT_ADJUST_EXCEPTION_FRAME
15772 SWAPGS
15773 - /*
15774 - * No need to follow this irqs on/off section: the syscall
15775 - * disabled irqs and here we enable it straight after entry:
15776 - */
15777 - ENABLE_INTERRUPTS(CLBR_NONE)
15778 movl %eax,%eax
15779 pushq_cfi %rax
15780 cld
15781 /* note the registers are not zero extended to the sf.
15782 this could be a problem. */
15783 SAVE_ARGS 0,1,0
15784 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15785 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15786 + pax_enter_kernel_user
15787 +
15788 +#ifdef CONFIG_PAX_RANDKSTACK
15789 + pax_erase_kstack
15790 +#endif
15791 +
15792 + /*
15793 + * No need to follow this irqs on/off section: the syscall
15794 + * disabled irqs and here we enable it straight after entry:
15795 + */
15796 + ENABLE_INTERRUPTS(CLBR_NONE)
15797 + GET_THREAD_INFO(%r11)
15798 + orl $TS_COMPAT,TI_status(%r11)
15799 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15800 jnz ia32_tracesys
15801 cmpq $(IA32_NR_syscalls-1),%rax
15802 ja ia32_badsys
15803 @@ -458,6 +551,9 @@ ia32_tracesys:
15804 RESTORE_REST
15805 cmpq $(IA32_NR_syscalls-1),%rax
15806 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15807 +
15808 + pax_erase_kstack
15809 +
15810 jmp ia32_do_call
15811 END(ia32_syscall)
15812
15813 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15814 index 8e0ceec..af13504 100644
15815 --- a/arch/x86/ia32/sys_ia32.c
15816 +++ b/arch/x86/ia32/sys_ia32.c
15817 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15818 */
15819 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15820 {
15821 - typeof(ubuf->st_uid) uid = 0;
15822 - typeof(ubuf->st_gid) gid = 0;
15823 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15824 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15825 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15826 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15827 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15828 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15829 index 372231c..51b537d 100644
15830 --- a/arch/x86/include/asm/alternative-asm.h
15831 +++ b/arch/x86/include/asm/alternative-asm.h
15832 @@ -18,6 +18,45 @@
15833 .endm
15834 #endif
15835
15836 +#ifdef KERNEXEC_PLUGIN
15837 + .macro pax_force_retaddr_bts rip=0
15838 + btsq $63,\rip(%rsp)
15839 + .endm
15840 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15841 + .macro pax_force_retaddr rip=0, reload=0
15842 + btsq $63,\rip(%rsp)
15843 + .endm
15844 + .macro pax_force_fptr ptr
15845 + btsq $63,\ptr
15846 + .endm
15847 + .macro pax_set_fptr_mask
15848 + .endm
15849 +#endif
15850 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15851 + .macro pax_force_retaddr rip=0, reload=0
15852 + .if \reload
15853 + pax_set_fptr_mask
15854 + .endif
15855 + orq %r12,\rip(%rsp)
15856 + .endm
15857 + .macro pax_force_fptr ptr
15858 + orq %r12,\ptr
15859 + .endm
15860 + .macro pax_set_fptr_mask
15861 + movabs $0x8000000000000000,%r12
15862 + .endm
15863 +#endif
15864 +#else
15865 + .macro pax_force_retaddr rip=0, reload=0
15866 + .endm
15867 + .macro pax_force_fptr ptr
15868 + .endm
15869 + .macro pax_force_retaddr_bts rip=0
15870 + .endm
15871 + .macro pax_set_fptr_mask
15872 + .endm
15873 +#endif
15874 +
15875 .macro altinstruction_entry orig alt feature orig_len alt_len
15876 .long \orig - .
15877 .long \alt - .
15878 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15879 index 473bdbe..b1e3377 100644
15880 --- a/arch/x86/include/asm/alternative.h
15881 +++ b/arch/x86/include/asm/alternative.h
15882 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15883 ".pushsection .discard,\"aw\",@progbits\n" \
15884 DISCARD_ENTRY(1) \
15885 ".popsection\n" \
15886 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15887 + ".pushsection .altinstr_replacement, \"a\"\n" \
15888 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15889 ".popsection"
15890
15891 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15892 DISCARD_ENTRY(1) \
15893 DISCARD_ENTRY(2) \
15894 ".popsection\n" \
15895 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15896 + ".pushsection .altinstr_replacement, \"a\"\n" \
15897 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15898 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15899 ".popsection"
15900 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15901 index 465b309..ab7e51f 100644
15902 --- a/arch/x86/include/asm/apic.h
15903 +++ b/arch/x86/include/asm/apic.h
15904 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15905
15906 #ifdef CONFIG_X86_LOCAL_APIC
15907
15908 -extern unsigned int apic_verbosity;
15909 +extern int apic_verbosity;
15910 extern int local_apic_timer_c2_ok;
15911
15912 extern int disable_apic;
15913 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15914 index 20370c6..a2eb9b0 100644
15915 --- a/arch/x86/include/asm/apm.h
15916 +++ b/arch/x86/include/asm/apm.h
15917 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15918 __asm__ __volatile__(APM_DO_ZERO_SEGS
15919 "pushl %%edi\n\t"
15920 "pushl %%ebp\n\t"
15921 - "lcall *%%cs:apm_bios_entry\n\t"
15922 + "lcall *%%ss:apm_bios_entry\n\t"
15923 "setc %%al\n\t"
15924 "popl %%ebp\n\t"
15925 "popl %%edi\n\t"
15926 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15927 __asm__ __volatile__(APM_DO_ZERO_SEGS
15928 "pushl %%edi\n\t"
15929 "pushl %%ebp\n\t"
15930 - "lcall *%%cs:apm_bios_entry\n\t"
15931 + "lcall *%%ss:apm_bios_entry\n\t"
15932 "setc %%bl\n\t"
15933 "popl %%ebp\n\t"
15934 "popl %%edi\n\t"
15935 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15936 index 6dd1c7dd..5a85bf2 100644
15937 --- a/arch/x86/include/asm/atomic.h
15938 +++ b/arch/x86/include/asm/atomic.h
15939 @@ -24,7 +24,18 @@
15940 */
15941 static inline int atomic_read(const atomic_t *v)
15942 {
15943 - return (*(volatile int *)&(v)->counter);
15944 + return (*(volatile const int *)&(v)->counter);
15945 +}
15946 +
15947 +/**
15948 + * atomic_read_unchecked - read atomic variable
15949 + * @v: pointer of type atomic_unchecked_t
15950 + *
15951 + * Atomically reads the value of @v.
15952 + */
15953 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15954 +{
15955 + return (*(volatile const int *)&(v)->counter);
15956 }
15957
15958 /**
15959 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15960 }
15961
15962 /**
15963 + * atomic_set_unchecked - set atomic variable
15964 + * @v: pointer of type atomic_unchecked_t
15965 + * @i: required value
15966 + *
15967 + * Atomically sets the value of @v to @i.
15968 + */
15969 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15970 +{
15971 + v->counter = i;
15972 +}
15973 +
15974 +/**
15975 * atomic_add - add integer to atomic variable
15976 * @i: integer value to add
15977 * @v: pointer of type atomic_t
15978 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15979 */
15980 static inline void atomic_add(int i, atomic_t *v)
15981 {
15982 - asm volatile(LOCK_PREFIX "addl %1,%0"
15983 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15984 +
15985 +#ifdef CONFIG_PAX_REFCOUNT
15986 + "jno 0f\n"
15987 + LOCK_PREFIX "subl %1,%0\n"
15988 + "int $4\n0:\n"
15989 + _ASM_EXTABLE(0b, 0b)
15990 +#endif
15991 +
15992 + : "+m" (v->counter)
15993 + : "ir" (i));
15994 +}
15995 +
15996 +/**
15997 + * atomic_add_unchecked - add integer to atomic variable
15998 + * @i: integer value to add
15999 + * @v: pointer of type atomic_unchecked_t
16000 + *
16001 + * Atomically adds @i to @v.
16002 + */
16003 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
16004 +{
16005 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
16006 : "+m" (v->counter)
16007 : "ir" (i));
16008 }
16009 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
16010 */
16011 static inline void atomic_sub(int i, atomic_t *v)
16012 {
16013 - asm volatile(LOCK_PREFIX "subl %1,%0"
16014 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
16015 +
16016 +#ifdef CONFIG_PAX_REFCOUNT
16017 + "jno 0f\n"
16018 + LOCK_PREFIX "addl %1,%0\n"
16019 + "int $4\n0:\n"
16020 + _ASM_EXTABLE(0b, 0b)
16021 +#endif
16022 +
16023 + : "+m" (v->counter)
16024 + : "ir" (i));
16025 +}
16026 +
16027 +/**
16028 + * atomic_sub_unchecked - subtract integer from atomic variable
16029 + * @i: integer value to subtract
16030 + * @v: pointer of type atomic_unchecked_t
16031 + *
16032 + * Atomically subtracts @i from @v.
16033 + */
16034 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
16035 +{
16036 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
16037 : "+m" (v->counter)
16038 : "ir" (i));
16039 }
16040 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
16041 */
16042 static inline int atomic_sub_and_test(int i, atomic_t *v)
16043 {
16044 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
16045 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
16046 }
16047
16048 /**
16049 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
16050 */
16051 static inline void atomic_inc(atomic_t *v)
16052 {
16053 - asm volatile(LOCK_PREFIX "incl %0"
16054 + asm volatile(LOCK_PREFIX "incl %0\n"
16055 +
16056 +#ifdef CONFIG_PAX_REFCOUNT
16057 + "jno 0f\n"
16058 + LOCK_PREFIX "decl %0\n"
16059 + "int $4\n0:\n"
16060 + _ASM_EXTABLE(0b, 0b)
16061 +#endif
16062 +
16063 + : "+m" (v->counter));
16064 +}
16065 +
16066 +/**
16067 + * atomic_inc_unchecked - increment atomic variable
16068 + * @v: pointer of type atomic_unchecked_t
16069 + *
16070 + * Atomically increments @v by 1.
16071 + */
16072 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
16073 +{
16074 + asm volatile(LOCK_PREFIX "incl %0\n"
16075 : "+m" (v->counter));
16076 }
16077
16078 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
16079 */
16080 static inline void atomic_dec(atomic_t *v)
16081 {
16082 - asm volatile(LOCK_PREFIX "decl %0"
16083 + asm volatile(LOCK_PREFIX "decl %0\n"
16084 +
16085 +#ifdef CONFIG_PAX_REFCOUNT
16086 + "jno 0f\n"
16087 + LOCK_PREFIX "incl %0\n"
16088 + "int $4\n0:\n"
16089 + _ASM_EXTABLE(0b, 0b)
16090 +#endif
16091 +
16092 + : "+m" (v->counter));
16093 +}
16094 +
16095 +/**
16096 + * atomic_dec_unchecked - decrement atomic variable
16097 + * @v: pointer of type atomic_unchecked_t
16098 + *
16099 + * Atomically decrements @v by 1.
16100 + */
16101 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
16102 +{
16103 + asm volatile(LOCK_PREFIX "decl %0\n"
16104 : "+m" (v->counter));
16105 }
16106
16107 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
16108 */
16109 static inline int atomic_dec_and_test(atomic_t *v)
16110 {
16111 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
16112 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
16113 }
16114
16115 /**
16116 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
16117 */
16118 static inline int atomic_inc_and_test(atomic_t *v)
16119 {
16120 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
16121 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
16122 +}
16123 +
16124 +/**
16125 + * atomic_inc_and_test_unchecked - increment and test
16126 + * @v: pointer of type atomic_unchecked_t
16127 + *
16128 + * Atomically increments @v by 1
16129 + * and returns true if the result is zero, or false for all
16130 + * other cases.
16131 + */
16132 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
16133 +{
16134 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
16135 }
16136
16137 /**
16138 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
16139 */
16140 static inline int atomic_add_negative(int i, atomic_t *v)
16141 {
16142 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
16143 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
16144 }
16145
16146 /**
16147 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
16148 *
16149 * Atomically adds @i to @v and returns @i + @v
16150 */
16151 -static inline int atomic_add_return(int i, atomic_t *v)
16152 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
16153 +{
16154 + return i + xadd_check_overflow(&v->counter, i);
16155 +}
16156 +
16157 +/**
16158 + * atomic_add_return_unchecked - add integer and return
16159 + * @i: integer value to add
16160 + * @v: pointer of type atomic_unchecked_t
16161 + *
16162 + * Atomically adds @i to @v and returns @i + @v
16163 + */
16164 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
16165 {
16166 return i + xadd(&v->counter, i);
16167 }
16168 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
16169 *
16170 * Atomically subtracts @i from @v and returns @v - @i
16171 */
16172 -static inline int atomic_sub_return(int i, atomic_t *v)
16173 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
16174 {
16175 return atomic_add_return(-i, v);
16176 }
16177
16178 #define atomic_inc_return(v) (atomic_add_return(1, v))
16179 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
16180 +{
16181 + return atomic_add_return_unchecked(1, v);
16182 +}
16183 #define atomic_dec_return(v) (atomic_sub_return(1, v))
16184
16185 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
16186 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
16187 +{
16188 + return cmpxchg(&v->counter, old, new);
16189 +}
16190 +
16191 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
16192 {
16193 return cmpxchg(&v->counter, old, new);
16194 }
16195 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
16196 return xchg(&v->counter, new);
16197 }
16198
16199 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
16200 +{
16201 + return xchg(&v->counter, new);
16202 +}
16203 +
16204 /**
16205 * __atomic_add_unless - add unless the number is already a given value
16206 * @v: pointer of type atomic_t
16207 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
16208 * Atomically adds @a to @v, so long as @v was not already @u.
16209 * Returns the old value of @v.
16210 */
16211 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16212 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
16213 {
16214 - int c, old;
16215 + int c, old, new;
16216 c = atomic_read(v);
16217 for (;;) {
16218 - if (unlikely(c == (u)))
16219 + if (unlikely(c == u))
16220 break;
16221 - old = atomic_cmpxchg((v), c, c + (a));
16222 +
16223 + asm volatile("addl %2,%0\n"
16224 +
16225 +#ifdef CONFIG_PAX_REFCOUNT
16226 + "jno 0f\n"
16227 + "subl %2,%0\n"
16228 + "int $4\n0:\n"
16229 + _ASM_EXTABLE(0b, 0b)
16230 +#endif
16231 +
16232 + : "=r" (new)
16233 + : "0" (c), "ir" (a));
16234 +
16235 + old = atomic_cmpxchg(v, c, new);
16236 if (likely(old == c))
16237 break;
16238 c = old;
16239 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16240 }
16241
16242 /**
16243 + * atomic_inc_not_zero_hint - increment if not null
16244 + * @v: pointer of type atomic_t
16245 + * @hint: probable value of the atomic before the increment
16246 + *
16247 + * This version of atomic_inc_not_zero() gives a hint of probable
16248 + * value of the atomic. This helps processor to not read the memory
16249 + * before doing the atomic read/modify/write cycle, lowering
16250 + * number of bus transactions on some arches.
16251 + *
16252 + * Returns: 0 if increment was not done, 1 otherwise.
16253 + */
16254 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
16255 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
16256 +{
16257 + int val, c = hint, new;
16258 +
16259 + /* sanity test, should be removed by compiler if hint is a constant */
16260 + if (!hint)
16261 + return __atomic_add_unless(v, 1, 0);
16262 +
16263 + do {
16264 + asm volatile("incl %0\n"
16265 +
16266 +#ifdef CONFIG_PAX_REFCOUNT
16267 + "jno 0f\n"
16268 + "decl %0\n"
16269 + "int $4\n0:\n"
16270 + _ASM_EXTABLE(0b, 0b)
16271 +#endif
16272 +
16273 + : "=r" (new)
16274 + : "0" (c));
16275 +
16276 + val = atomic_cmpxchg(v, c, new);
16277 + if (val == c)
16278 + return 1;
16279 + c = val;
16280 + } while (c);
16281 +
16282 + return 0;
16283 +}
16284 +
16285 +/**
16286 * atomic_inc_short - increment of a short integer
16287 * @v: pointer to type int
16288 *
16289 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
16290 #endif
16291
16292 /* These are x86-specific, used by some header files */
16293 -#define atomic_clear_mask(mask, addr) \
16294 - asm volatile(LOCK_PREFIX "andl %0,%1" \
16295 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
16296 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
16297 +{
16298 + asm volatile(LOCK_PREFIX "andl %1,%0"
16299 + : "+m" (v->counter)
16300 + : "r" (~(mask))
16301 + : "memory");
16302 +}
16303
16304 -#define atomic_set_mask(mask, addr) \
16305 - asm volatile(LOCK_PREFIX "orl %0,%1" \
16306 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
16307 - : "memory")
16308 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16309 +{
16310 + asm volatile(LOCK_PREFIX "andl %1,%0"
16311 + : "+m" (v->counter)
16312 + : "r" (~(mask))
16313 + : "memory");
16314 +}
16315 +
16316 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
16317 +{
16318 + asm volatile(LOCK_PREFIX "orl %1,%0"
16319 + : "+m" (v->counter)
16320 + : "r" (mask)
16321 + : "memory");
16322 +}
16323 +
16324 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16325 +{
16326 + asm volatile(LOCK_PREFIX "orl %1,%0"
16327 + : "+m" (v->counter)
16328 + : "r" (mask)
16329 + : "memory");
16330 +}
16331
16332 #ifdef CONFIG_X86_32
16333 # include <asm/atomic64_32.h>
16334 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
16335 index b154de7..bf18a5a 100644
16336 --- a/arch/x86/include/asm/atomic64_32.h
16337 +++ b/arch/x86/include/asm/atomic64_32.h
16338 @@ -12,6 +12,14 @@ typedef struct {
16339 u64 __aligned(8) counter;
16340 } atomic64_t;
16341
16342 +#ifdef CONFIG_PAX_REFCOUNT
16343 +typedef struct {
16344 + u64 __aligned(8) counter;
16345 +} atomic64_unchecked_t;
16346 +#else
16347 +typedef atomic64_t atomic64_unchecked_t;
16348 +#endif
16349 +
16350 #define ATOMIC64_INIT(val) { (val) }
16351
16352 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
16353 @@ -37,21 +45,31 @@ typedef struct {
16354 ATOMIC64_DECL_ONE(sym##_386)
16355
16356 ATOMIC64_DECL_ONE(add_386);
16357 +ATOMIC64_DECL_ONE(add_unchecked_386);
16358 ATOMIC64_DECL_ONE(sub_386);
16359 +ATOMIC64_DECL_ONE(sub_unchecked_386);
16360 ATOMIC64_DECL_ONE(inc_386);
16361 +ATOMIC64_DECL_ONE(inc_unchecked_386);
16362 ATOMIC64_DECL_ONE(dec_386);
16363 +ATOMIC64_DECL_ONE(dec_unchecked_386);
16364 #endif
16365
16366 #define alternative_atomic64(f, out, in...) \
16367 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
16368
16369 ATOMIC64_DECL(read);
16370 +ATOMIC64_DECL(read_unchecked);
16371 ATOMIC64_DECL(set);
16372 +ATOMIC64_DECL(set_unchecked);
16373 ATOMIC64_DECL(xchg);
16374 ATOMIC64_DECL(add_return);
16375 +ATOMIC64_DECL(add_return_unchecked);
16376 ATOMIC64_DECL(sub_return);
16377 +ATOMIC64_DECL(sub_return_unchecked);
16378 ATOMIC64_DECL(inc_return);
16379 +ATOMIC64_DECL(inc_return_unchecked);
16380 ATOMIC64_DECL(dec_return);
16381 +ATOMIC64_DECL(dec_return_unchecked);
16382 ATOMIC64_DECL(dec_if_positive);
16383 ATOMIC64_DECL(inc_not_zero);
16384 ATOMIC64_DECL(add_unless);
16385 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
16386 }
16387
16388 /**
16389 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
16390 + * @p: pointer to type atomic64_unchecked_t
16391 + * @o: expected value
16392 + * @n: new value
16393 + *
16394 + * Atomically sets @v to @n if it was equal to @o and returns
16395 + * the old value.
16396 + */
16397 +
16398 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
16399 +{
16400 + return cmpxchg64(&v->counter, o, n);
16401 +}
16402 +
16403 +/**
16404 * atomic64_xchg - xchg atomic64 variable
16405 * @v: pointer to type atomic64_t
16406 * @n: value to assign
16407 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
16408 }
16409
16410 /**
16411 + * atomic64_set_unchecked - set atomic64 variable
16412 + * @v: pointer to type atomic64_unchecked_t
16413 + * @n: value to assign
16414 + *
16415 + * Atomically sets the value of @v to @n.
16416 + */
16417 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
16418 +{
16419 + unsigned high = (unsigned)(i >> 32);
16420 + unsigned low = (unsigned)i;
16421 + alternative_atomic64(set, /* no output */,
16422 + "S" (v), "b" (low), "c" (high)
16423 + : "eax", "edx", "memory");
16424 +}
16425 +
16426 +/**
16427 * atomic64_read - read atomic64 variable
16428 * @v: pointer to type atomic64_t
16429 *
16430 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
16431 }
16432
16433 /**
16434 + * atomic64_read_unchecked - read atomic64 variable
16435 + * @v: pointer to type atomic64_unchecked_t
16436 + *
16437 + * Atomically reads the value of @v and returns it.
16438 + */
16439 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
16440 +{
16441 + long long r;
16442 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
16443 + return r;
16444 + }
16445 +
16446 +/**
16447 * atomic64_add_return - add and return
16448 * @i: integer value to add
16449 * @v: pointer to type atomic64_t
16450 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
16451 return i;
16452 }
16453
16454 +/**
16455 + * atomic64_add_return_unchecked - add and return
16456 + * @i: integer value to add
16457 + * @v: pointer to type atomic64_unchecked_t
16458 + *
16459 + * Atomically adds @i to @v and returns @i + *@v
16460 + */
16461 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
16462 +{
16463 + alternative_atomic64(add_return_unchecked,
16464 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16465 + ASM_NO_INPUT_CLOBBER("memory"));
16466 + return i;
16467 +}
16468 +
16469 /*
16470 * Other variants with different arithmetic operators:
16471 */
16472 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
16473 return a;
16474 }
16475
16476 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16477 +{
16478 + long long a;
16479 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
16480 + "S" (v) : "memory", "ecx");
16481 + return a;
16482 +}
16483 +
16484 static inline long long atomic64_dec_return(atomic64_t *v)
16485 {
16486 long long a;
16487 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
16488 }
16489
16490 /**
16491 + * atomic64_add_unchecked - add integer to atomic64 variable
16492 + * @i: integer value to add
16493 + * @v: pointer to type atomic64_unchecked_t
16494 + *
16495 + * Atomically adds @i to @v.
16496 + */
16497 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
16498 +{
16499 + __alternative_atomic64(add_unchecked, add_return_unchecked,
16500 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16501 + ASM_NO_INPUT_CLOBBER("memory"));
16502 + return i;
16503 +}
16504 +
16505 +/**
16506 * atomic64_sub - subtract the atomic64 variable
16507 * @i: integer value to subtract
16508 * @v: pointer to type atomic64_t
16509 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
16510 index 46e9052..ae45136 100644
16511 --- a/arch/x86/include/asm/atomic64_64.h
16512 +++ b/arch/x86/include/asm/atomic64_64.h
16513 @@ -18,7 +18,19 @@
16514 */
16515 static inline long atomic64_read(const atomic64_t *v)
16516 {
16517 - return (*(volatile long *)&(v)->counter);
16518 + return (*(volatile const long *)&(v)->counter);
16519 +}
16520 +
16521 +/**
16522 + * atomic64_read_unchecked - read atomic64 variable
16523 + * @v: pointer of type atomic64_unchecked_t
16524 + *
16525 + * Atomically reads the value of @v.
16526 + * Doesn't imply a read memory barrier.
16527 + */
16528 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
16529 +{
16530 + return (*(volatile const long *)&(v)->counter);
16531 }
16532
16533 /**
16534 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
16535 }
16536
16537 /**
16538 + * atomic64_set_unchecked - set atomic64 variable
16539 + * @v: pointer to type atomic64_unchecked_t
16540 + * @i: required value
16541 + *
16542 + * Atomically sets the value of @v to @i.
16543 + */
16544 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
16545 +{
16546 + v->counter = i;
16547 +}
16548 +
16549 +/**
16550 * atomic64_add - add integer to atomic64 variable
16551 * @i: integer value to add
16552 * @v: pointer to type atomic64_t
16553 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16554 */
16555 static inline void atomic64_add(long i, atomic64_t *v)
16556 {
16557 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
16558 +
16559 +#ifdef CONFIG_PAX_REFCOUNT
16560 + "jno 0f\n"
16561 + LOCK_PREFIX "subq %1,%0\n"
16562 + "int $4\n0:\n"
16563 + _ASM_EXTABLE(0b, 0b)
16564 +#endif
16565 +
16566 + : "=m" (v->counter)
16567 + : "er" (i), "m" (v->counter));
16568 +}
16569 +
16570 +/**
16571 + * atomic64_add_unchecked - add integer to atomic64 variable
16572 + * @i: integer value to add
16573 + * @v: pointer to type atomic64_unchecked_t
16574 + *
16575 + * Atomically adds @i to @v.
16576 + */
16577 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16578 +{
16579 asm volatile(LOCK_PREFIX "addq %1,%0"
16580 : "=m" (v->counter)
16581 : "er" (i), "m" (v->counter));
16582 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16583 */
16584 static inline void atomic64_sub(long i, atomic64_t *v)
16585 {
16586 - asm volatile(LOCK_PREFIX "subq %1,%0"
16587 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16588 +
16589 +#ifdef CONFIG_PAX_REFCOUNT
16590 + "jno 0f\n"
16591 + LOCK_PREFIX "addq %1,%0\n"
16592 + "int $4\n0:\n"
16593 + _ASM_EXTABLE(0b, 0b)
16594 +#endif
16595 +
16596 + : "=m" (v->counter)
16597 + : "er" (i), "m" (v->counter));
16598 +}
16599 +
16600 +/**
16601 + * atomic64_sub_unchecked - subtract the atomic64 variable
16602 + * @i: integer value to subtract
16603 + * @v: pointer to type atomic64_unchecked_t
16604 + *
16605 + * Atomically subtracts @i from @v.
16606 + */
16607 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16608 +{
16609 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16610 : "=m" (v->counter)
16611 : "er" (i), "m" (v->counter));
16612 }
16613 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16614 */
16615 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16616 {
16617 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16618 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16619 }
16620
16621 /**
16622 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16623 */
16624 static inline void atomic64_inc(atomic64_t *v)
16625 {
16626 + asm volatile(LOCK_PREFIX "incq %0\n"
16627 +
16628 +#ifdef CONFIG_PAX_REFCOUNT
16629 + "jno 0f\n"
16630 + LOCK_PREFIX "decq %0\n"
16631 + "int $4\n0:\n"
16632 + _ASM_EXTABLE(0b, 0b)
16633 +#endif
16634 +
16635 + : "=m" (v->counter)
16636 + : "m" (v->counter));
16637 +}
16638 +
16639 +/**
16640 + * atomic64_inc_unchecked - increment atomic64 variable
16641 + * @v: pointer to type atomic64_unchecked_t
16642 + *
16643 + * Atomically increments @v by 1.
16644 + */
16645 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16646 +{
16647 asm volatile(LOCK_PREFIX "incq %0"
16648 : "=m" (v->counter)
16649 : "m" (v->counter));
16650 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16651 */
16652 static inline void atomic64_dec(atomic64_t *v)
16653 {
16654 - asm volatile(LOCK_PREFIX "decq %0"
16655 + asm volatile(LOCK_PREFIX "decq %0\n"
16656 +
16657 +#ifdef CONFIG_PAX_REFCOUNT
16658 + "jno 0f\n"
16659 + LOCK_PREFIX "incq %0\n"
16660 + "int $4\n0:\n"
16661 + _ASM_EXTABLE(0b, 0b)
16662 +#endif
16663 +
16664 + : "=m" (v->counter)
16665 + : "m" (v->counter));
16666 +}
16667 +
16668 +/**
16669 + * atomic64_dec_unchecked - decrement atomic64 variable
16670 + * @v: pointer to type atomic64_t
16671 + *
16672 + * Atomically decrements @v by 1.
16673 + */
16674 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16675 +{
16676 + asm volatile(LOCK_PREFIX "decq %0\n"
16677 : "=m" (v->counter)
16678 : "m" (v->counter));
16679 }
16680 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16681 */
16682 static inline int atomic64_dec_and_test(atomic64_t *v)
16683 {
16684 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16685 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16686 }
16687
16688 /**
16689 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16690 */
16691 static inline int atomic64_inc_and_test(atomic64_t *v)
16692 {
16693 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16694 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16695 }
16696
16697 /**
16698 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16699 */
16700 static inline int atomic64_add_negative(long i, atomic64_t *v)
16701 {
16702 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16703 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16704 }
16705
16706 /**
16707 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16708 */
16709 static inline long atomic64_add_return(long i, atomic64_t *v)
16710 {
16711 + return i + xadd_check_overflow(&v->counter, i);
16712 +}
16713 +
16714 +/**
16715 + * atomic64_add_return_unchecked - add and return
16716 + * @i: integer value to add
16717 + * @v: pointer to type atomic64_unchecked_t
16718 + *
16719 + * Atomically adds @i to @v and returns @i + @v
16720 + */
16721 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16722 +{
16723 return i + xadd(&v->counter, i);
16724 }
16725
16726 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16727 }
16728
16729 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16730 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16731 +{
16732 + return atomic64_add_return_unchecked(1, v);
16733 +}
16734 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16735
16736 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16737 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16738 return cmpxchg(&v->counter, old, new);
16739 }
16740
16741 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16742 +{
16743 + return cmpxchg(&v->counter, old, new);
16744 +}
16745 +
16746 static inline long atomic64_xchg(atomic64_t *v, long new)
16747 {
16748 return xchg(&v->counter, new);
16749 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16750 */
16751 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16752 {
16753 - long c, old;
16754 + long c, old, new;
16755 c = atomic64_read(v);
16756 for (;;) {
16757 - if (unlikely(c == (u)))
16758 + if (unlikely(c == u))
16759 break;
16760 - old = atomic64_cmpxchg((v), c, c + (a));
16761 +
16762 + asm volatile("add %2,%0\n"
16763 +
16764 +#ifdef CONFIG_PAX_REFCOUNT
16765 + "jno 0f\n"
16766 + "sub %2,%0\n"
16767 + "int $4\n0:\n"
16768 + _ASM_EXTABLE(0b, 0b)
16769 +#endif
16770 +
16771 + : "=r" (new)
16772 + : "0" (c), "ir" (a));
16773 +
16774 + old = atomic64_cmpxchg(v, c, new);
16775 if (likely(old == c))
16776 break;
16777 c = old;
16778 }
16779 - return c != (u);
16780 + return c != u;
16781 }
16782
16783 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16784 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16785 index 0f4460b..fa1ee19 100644
16786 --- a/arch/x86/include/asm/barrier.h
16787 +++ b/arch/x86/include/asm/barrier.h
16788 @@ -107,7 +107,7 @@
16789 do { \
16790 compiletime_assert_atomic_type(*p); \
16791 smp_mb(); \
16792 - ACCESS_ONCE(*p) = (v); \
16793 + ACCESS_ONCE_RW(*p) = (v); \
16794 } while (0)
16795
16796 #define smp_load_acquire(p) \
16797 @@ -124,7 +124,7 @@ do { \
16798 do { \
16799 compiletime_assert_atomic_type(*p); \
16800 barrier(); \
16801 - ACCESS_ONCE(*p) = (v); \
16802 + ACCESS_ONCE_RW(*p) = (v); \
16803 } while (0)
16804
16805 #define smp_load_acquire(p) \
16806 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16807 index cfe3b95..d01b118 100644
16808 --- a/arch/x86/include/asm/bitops.h
16809 +++ b/arch/x86/include/asm/bitops.h
16810 @@ -50,7 +50,7 @@
16811 * a mask operation on a byte.
16812 */
16813 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16814 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16815 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16816 #define CONST_MASK(nr) (1 << ((nr) & 7))
16817
16818 /**
16819 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16820 */
16821 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16822 {
16823 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16824 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16825 }
16826
16827 /**
16828 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16829 */
16830 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16831 {
16832 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16833 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16834 }
16835
16836 /**
16837 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16838 */
16839 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16840 {
16841 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16842 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16843 }
16844
16845 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16846 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16847 *
16848 * Undefined if no bit exists, so code should check against 0 first.
16849 */
16850 -static inline unsigned long __ffs(unsigned long word)
16851 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16852 {
16853 asm("rep; bsf %1,%0"
16854 : "=r" (word)
16855 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16856 *
16857 * Undefined if no zero exists, so code should check against ~0UL first.
16858 */
16859 -static inline unsigned long ffz(unsigned long word)
16860 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16861 {
16862 asm("rep; bsf %1,%0"
16863 : "=r" (word)
16864 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16865 *
16866 * Undefined if no set bit exists, so code should check against 0 first.
16867 */
16868 -static inline unsigned long __fls(unsigned long word)
16869 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16870 {
16871 asm("bsr %1,%0"
16872 : "=r" (word)
16873 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16874 * set bit if value is nonzero. The last (most significant) bit is
16875 * at position 32.
16876 */
16877 -static inline int fls(int x)
16878 +static inline int __intentional_overflow(-1) fls(int x)
16879 {
16880 int r;
16881
16882 @@ -476,7 +476,7 @@ static inline int fls(int x)
16883 * at position 64.
16884 */
16885 #ifdef CONFIG_X86_64
16886 -static __always_inline int fls64(__u64 x)
16887 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16888 {
16889 int bitpos = -1;
16890 /*
16891 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16892 index 4fa687a..60f2d39 100644
16893 --- a/arch/x86/include/asm/boot.h
16894 +++ b/arch/x86/include/asm/boot.h
16895 @@ -6,10 +6,15 @@
16896 #include <uapi/asm/boot.h>
16897
16898 /* Physical address where kernel should be loaded. */
16899 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16900 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16901 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16902 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16903
16904 +#ifndef __ASSEMBLY__
16905 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16906 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16907 +#endif
16908 +
16909 /* Minimum kernel alignment, as a power of two */
16910 #ifdef CONFIG_X86_64
16911 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16912 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16913 index 48f99f1..d78ebf9 100644
16914 --- a/arch/x86/include/asm/cache.h
16915 +++ b/arch/x86/include/asm/cache.h
16916 @@ -5,12 +5,13 @@
16917
16918 /* L1 cache line size */
16919 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16920 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16921 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16922
16923 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16924 +#define __read_only __attribute__((__section__(".data..read_only")))
16925
16926 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16927 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16928 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16929
16930 #ifdef CONFIG_X86_VSMP
16931 #ifdef CONFIG_SMP
16932 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16933 index 9863ee3..4a1f8e1 100644
16934 --- a/arch/x86/include/asm/cacheflush.h
16935 +++ b/arch/x86/include/asm/cacheflush.h
16936 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16937 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16938
16939 if (pg_flags == _PGMT_DEFAULT)
16940 - return -1;
16941 + return ~0UL;
16942 else if (pg_flags == _PGMT_WC)
16943 return _PAGE_CACHE_WC;
16944 else if (pg_flags == _PGMT_UC_MINUS)
16945 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16946 index cb4c73b..c473c29 100644
16947 --- a/arch/x86/include/asm/calling.h
16948 +++ b/arch/x86/include/asm/calling.h
16949 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16950 #define RSP 152
16951 #define SS 160
16952
16953 -#define ARGOFFSET R11
16954 -#define SWFRAME ORIG_RAX
16955 +#define ARGOFFSET R15
16956
16957 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16958 - subq $9*8+\addskip, %rsp
16959 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16960 - movq_cfi rdi, 8*8
16961 - movq_cfi rsi, 7*8
16962 - movq_cfi rdx, 6*8
16963 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16964 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16965 + movq_cfi rdi, RDI
16966 + movq_cfi rsi, RSI
16967 + movq_cfi rdx, RDX
16968
16969 .if \save_rcx
16970 - movq_cfi rcx, 5*8
16971 + movq_cfi rcx, RCX
16972 .endif
16973
16974 - movq_cfi rax, 4*8
16975 + movq_cfi rax, RAX
16976
16977 .if \save_r891011
16978 - movq_cfi r8, 3*8
16979 - movq_cfi r9, 2*8
16980 - movq_cfi r10, 1*8
16981 - movq_cfi r11, 0*8
16982 + movq_cfi r8, R8
16983 + movq_cfi r9, R9
16984 + movq_cfi r10, R10
16985 + movq_cfi r11, R11
16986 .endif
16987
16988 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16989 + movq_cfi r12, R12
16990 +#endif
16991 +
16992 .endm
16993
16994 -#define ARG_SKIP (9*8)
16995 +#define ARG_SKIP ORIG_RAX
16996
16997 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16998 rstor_r8910=1, rstor_rdx=1
16999 +
17000 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17001 + movq_cfi_restore R12, r12
17002 +#endif
17003 +
17004 .if \rstor_r11
17005 - movq_cfi_restore 0*8, r11
17006 + movq_cfi_restore R11, r11
17007 .endif
17008
17009 .if \rstor_r8910
17010 - movq_cfi_restore 1*8, r10
17011 - movq_cfi_restore 2*8, r9
17012 - movq_cfi_restore 3*8, r8
17013 + movq_cfi_restore R10, r10
17014 + movq_cfi_restore R9, r9
17015 + movq_cfi_restore R8, r8
17016 .endif
17017
17018 .if \rstor_rax
17019 - movq_cfi_restore 4*8, rax
17020 + movq_cfi_restore RAX, rax
17021 .endif
17022
17023 .if \rstor_rcx
17024 - movq_cfi_restore 5*8, rcx
17025 + movq_cfi_restore RCX, rcx
17026 .endif
17027
17028 .if \rstor_rdx
17029 - movq_cfi_restore 6*8, rdx
17030 + movq_cfi_restore RDX, rdx
17031 .endif
17032
17033 - movq_cfi_restore 7*8, rsi
17034 - movq_cfi_restore 8*8, rdi
17035 + movq_cfi_restore RSI, rsi
17036 + movq_cfi_restore RDI, rdi
17037
17038 - .if ARG_SKIP+\addskip > 0
17039 - addq $ARG_SKIP+\addskip, %rsp
17040 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
17041 + .if ORIG_RAX+\addskip > 0
17042 + addq $ORIG_RAX+\addskip, %rsp
17043 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
17044 .endif
17045 .endm
17046
17047 - .macro LOAD_ARGS offset, skiprax=0
17048 - movq \offset(%rsp), %r11
17049 - movq \offset+8(%rsp), %r10
17050 - movq \offset+16(%rsp), %r9
17051 - movq \offset+24(%rsp), %r8
17052 - movq \offset+40(%rsp), %rcx
17053 - movq \offset+48(%rsp), %rdx
17054 - movq \offset+56(%rsp), %rsi
17055 - movq \offset+64(%rsp), %rdi
17056 + .macro LOAD_ARGS skiprax=0
17057 + movq R11(%rsp), %r11
17058 + movq R10(%rsp), %r10
17059 + movq R9(%rsp), %r9
17060 + movq R8(%rsp), %r8
17061 + movq RCX(%rsp), %rcx
17062 + movq RDX(%rsp), %rdx
17063 + movq RSI(%rsp), %rsi
17064 + movq RDI(%rsp), %rdi
17065 .if \skiprax
17066 .else
17067 - movq \offset+72(%rsp), %rax
17068 + movq RAX(%rsp), %rax
17069 .endif
17070 .endm
17071
17072 -#define REST_SKIP (6*8)
17073 -
17074 .macro SAVE_REST
17075 - subq $REST_SKIP, %rsp
17076 - CFI_ADJUST_CFA_OFFSET REST_SKIP
17077 - movq_cfi rbx, 5*8
17078 - movq_cfi rbp, 4*8
17079 - movq_cfi r12, 3*8
17080 - movq_cfi r13, 2*8
17081 - movq_cfi r14, 1*8
17082 - movq_cfi r15, 0*8
17083 + movq_cfi rbx, RBX
17084 + movq_cfi rbp, RBP
17085 +
17086 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17087 + movq_cfi r12, R12
17088 +#endif
17089 +
17090 + movq_cfi r13, R13
17091 + movq_cfi r14, R14
17092 + movq_cfi r15, R15
17093 .endm
17094
17095 .macro RESTORE_REST
17096 - movq_cfi_restore 0*8, r15
17097 - movq_cfi_restore 1*8, r14
17098 - movq_cfi_restore 2*8, r13
17099 - movq_cfi_restore 3*8, r12
17100 - movq_cfi_restore 4*8, rbp
17101 - movq_cfi_restore 5*8, rbx
17102 - addq $REST_SKIP, %rsp
17103 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
17104 + movq_cfi_restore R15, r15
17105 + movq_cfi_restore R14, r14
17106 + movq_cfi_restore R13, r13
17107 +
17108 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17109 + movq_cfi_restore R12, r12
17110 +#endif
17111 +
17112 + movq_cfi_restore RBP, rbp
17113 + movq_cfi_restore RBX, rbx
17114 .endm
17115
17116 .macro SAVE_ALL
17117 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
17118 index f50de69..2b0a458 100644
17119 --- a/arch/x86/include/asm/checksum_32.h
17120 +++ b/arch/x86/include/asm/checksum_32.h
17121 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
17122 int len, __wsum sum,
17123 int *src_err_ptr, int *dst_err_ptr);
17124
17125 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
17126 + int len, __wsum sum,
17127 + int *src_err_ptr, int *dst_err_ptr);
17128 +
17129 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
17130 + int len, __wsum sum,
17131 + int *src_err_ptr, int *dst_err_ptr);
17132 +
17133 /*
17134 * Note: when you get a NULL pointer exception here this means someone
17135 * passed in an incorrect kernel address to one of these functions.
17136 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
17137
17138 might_sleep();
17139 stac();
17140 - ret = csum_partial_copy_generic((__force void *)src, dst,
17141 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
17142 len, sum, err_ptr, NULL);
17143 clac();
17144
17145 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
17146 might_sleep();
17147 if (access_ok(VERIFY_WRITE, dst, len)) {
17148 stac();
17149 - ret = csum_partial_copy_generic(src, (__force void *)dst,
17150 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
17151 len, sum, NULL, err_ptr);
17152 clac();
17153 return ret;
17154 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
17155 index 99c105d7..2f667ac 100644
17156 --- a/arch/x86/include/asm/cmpxchg.h
17157 +++ b/arch/x86/include/asm/cmpxchg.h
17158 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
17159 __compiletime_error("Bad argument size for cmpxchg");
17160 extern void __xadd_wrong_size(void)
17161 __compiletime_error("Bad argument size for xadd");
17162 +extern void __xadd_check_overflow_wrong_size(void)
17163 + __compiletime_error("Bad argument size for xadd_check_overflow");
17164 extern void __add_wrong_size(void)
17165 __compiletime_error("Bad argument size for add");
17166 +extern void __add_check_overflow_wrong_size(void)
17167 + __compiletime_error("Bad argument size for add_check_overflow");
17168
17169 /*
17170 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
17171 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
17172 __ret; \
17173 })
17174
17175 +#ifdef CONFIG_PAX_REFCOUNT
17176 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
17177 + ({ \
17178 + __typeof__ (*(ptr)) __ret = (arg); \
17179 + switch (sizeof(*(ptr))) { \
17180 + case __X86_CASE_L: \
17181 + asm volatile (lock #op "l %0, %1\n" \
17182 + "jno 0f\n" \
17183 + "mov %0,%1\n" \
17184 + "int $4\n0:\n" \
17185 + _ASM_EXTABLE(0b, 0b) \
17186 + : "+r" (__ret), "+m" (*(ptr)) \
17187 + : : "memory", "cc"); \
17188 + break; \
17189 + case __X86_CASE_Q: \
17190 + asm volatile (lock #op "q %q0, %1\n" \
17191 + "jno 0f\n" \
17192 + "mov %0,%1\n" \
17193 + "int $4\n0:\n" \
17194 + _ASM_EXTABLE(0b, 0b) \
17195 + : "+r" (__ret), "+m" (*(ptr)) \
17196 + : : "memory", "cc"); \
17197 + break; \
17198 + default: \
17199 + __ ## op ## _check_overflow_wrong_size(); \
17200 + } \
17201 + __ret; \
17202 + })
17203 +#else
17204 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
17205 +#endif
17206 +
17207 /*
17208 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
17209 * Since this is generally used to protect other memory information, we
17210 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
17211 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
17212 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
17213
17214 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
17215 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
17216 +
17217 #define __add(ptr, inc, lock) \
17218 ({ \
17219 __typeof__ (*(ptr)) __ret = (inc); \
17220 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
17221 index 59c6c40..5e0b22c 100644
17222 --- a/arch/x86/include/asm/compat.h
17223 +++ b/arch/x86/include/asm/compat.h
17224 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
17225 typedef u32 compat_uint_t;
17226 typedef u32 compat_ulong_t;
17227 typedef u64 __attribute__((aligned(4))) compat_u64;
17228 -typedef u32 compat_uptr_t;
17229 +typedef u32 __user compat_uptr_t;
17230
17231 struct compat_timespec {
17232 compat_time_t tv_sec;
17233 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
17234 index 2075e6c..4d368b4 100644
17235 --- a/arch/x86/include/asm/cpufeature.h
17236 +++ b/arch/x86/include/asm/cpufeature.h
17237 @@ -203,7 +203,7 @@
17238 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
17239 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
17240 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
17241 -
17242 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
17243
17244 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
17245 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
17246 @@ -211,7 +211,7 @@
17247 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
17248 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
17249 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
17250 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
17251 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
17252 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
17253 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
17254 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
17255 @@ -371,6 +371,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
17256 #undef cpu_has_centaur_mcr
17257 #define cpu_has_centaur_mcr 0
17258
17259 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
17260 #endif /* CONFIG_X86_64 */
17261
17262 #if __GNUC__ >= 4
17263 @@ -423,7 +424,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17264
17265 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
17266 t_warn:
17267 - warn_pre_alternatives();
17268 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
17269 + warn_pre_alternatives();
17270 return false;
17271 #endif
17272
17273 @@ -443,7 +445,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17274 ".section .discard,\"aw\",@progbits\n"
17275 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17276 ".previous\n"
17277 - ".section .altinstr_replacement,\"ax\"\n"
17278 + ".section .altinstr_replacement,\"a\"\n"
17279 "3: movb $1,%0\n"
17280 "4:\n"
17281 ".previous\n"
17282 @@ -480,7 +482,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17283 " .byte 2b - 1b\n" /* src len */
17284 " .byte 4f - 3f\n" /* repl len */
17285 ".previous\n"
17286 - ".section .altinstr_replacement,\"ax\"\n"
17287 + ".section .altinstr_replacement,\"a\"\n"
17288 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
17289 "4:\n"
17290 ".previous\n"
17291 @@ -513,7 +515,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17292 ".section .discard,\"aw\",@progbits\n"
17293 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17294 ".previous\n"
17295 - ".section .altinstr_replacement,\"ax\"\n"
17296 + ".section .altinstr_replacement,\"a\"\n"
17297 "3: movb $0,%0\n"
17298 "4:\n"
17299 ".previous\n"
17300 @@ -527,7 +529,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17301 ".section .discard,\"aw\",@progbits\n"
17302 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
17303 ".previous\n"
17304 - ".section .altinstr_replacement,\"ax\"\n"
17305 + ".section .altinstr_replacement,\"a\"\n"
17306 "5: movb $1,%0\n"
17307 "6:\n"
17308 ".previous\n"
17309 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
17310 index 50d033a..37deb26 100644
17311 --- a/arch/x86/include/asm/desc.h
17312 +++ b/arch/x86/include/asm/desc.h
17313 @@ -4,6 +4,7 @@
17314 #include <asm/desc_defs.h>
17315 #include <asm/ldt.h>
17316 #include <asm/mmu.h>
17317 +#include <asm/pgtable.h>
17318
17319 #include <linux/smp.h>
17320 #include <linux/percpu.h>
17321 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17322
17323 desc->type = (info->read_exec_only ^ 1) << 1;
17324 desc->type |= info->contents << 2;
17325 + desc->type |= info->seg_not_present ^ 1;
17326
17327 desc->s = 1;
17328 desc->dpl = 0x3;
17329 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17330 }
17331
17332 extern struct desc_ptr idt_descr;
17333 -extern gate_desc idt_table[];
17334 -extern struct desc_ptr debug_idt_descr;
17335 -extern gate_desc debug_idt_table[];
17336 -
17337 -struct gdt_page {
17338 - struct desc_struct gdt[GDT_ENTRIES];
17339 -} __attribute__((aligned(PAGE_SIZE)));
17340 -
17341 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
17342 +extern gate_desc idt_table[IDT_ENTRIES];
17343 +extern const struct desc_ptr debug_idt_descr;
17344 +extern gate_desc debug_idt_table[IDT_ENTRIES];
17345
17346 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
17347 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
17348 {
17349 - return per_cpu(gdt_page, cpu).gdt;
17350 + return cpu_gdt_table[cpu];
17351 }
17352
17353 #ifdef CONFIG_X86_64
17354 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
17355 unsigned long base, unsigned dpl, unsigned flags,
17356 unsigned short seg)
17357 {
17358 - gate->a = (seg << 16) | (base & 0xffff);
17359 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
17360 + gate->gate.offset_low = base;
17361 + gate->gate.seg = seg;
17362 + gate->gate.reserved = 0;
17363 + gate->gate.type = type;
17364 + gate->gate.s = 0;
17365 + gate->gate.dpl = dpl;
17366 + gate->gate.p = 1;
17367 + gate->gate.offset_high = base >> 16;
17368 }
17369
17370 #endif
17371 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
17372
17373 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
17374 {
17375 + pax_open_kernel();
17376 memcpy(&idt[entry], gate, sizeof(*gate));
17377 + pax_close_kernel();
17378 }
17379
17380 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
17381 {
17382 + pax_open_kernel();
17383 memcpy(&ldt[entry], desc, 8);
17384 + pax_close_kernel();
17385 }
17386
17387 static inline void
17388 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
17389 default: size = sizeof(*gdt); break;
17390 }
17391
17392 + pax_open_kernel();
17393 memcpy(&gdt[entry], desc, size);
17394 + pax_close_kernel();
17395 }
17396
17397 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
17398 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
17399
17400 static inline void native_load_tr_desc(void)
17401 {
17402 + pax_open_kernel();
17403 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
17404 + pax_close_kernel();
17405 }
17406
17407 static inline void native_load_gdt(const struct desc_ptr *dtr)
17408 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
17409 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
17410 unsigned int i;
17411
17412 + pax_open_kernel();
17413 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
17414 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
17415 + pax_close_kernel();
17416 }
17417
17418 #define _LDT_empty(info) \
17419 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
17420 preempt_enable();
17421 }
17422
17423 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
17424 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
17425 {
17426 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
17427 }
17428 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
17429 }
17430
17431 #ifdef CONFIG_X86_64
17432 -static inline void set_nmi_gate(int gate, void *addr)
17433 +static inline void set_nmi_gate(int gate, const void *addr)
17434 {
17435 gate_desc s;
17436
17437 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
17438 #endif
17439
17440 #ifdef CONFIG_TRACING
17441 -extern struct desc_ptr trace_idt_descr;
17442 -extern gate_desc trace_idt_table[];
17443 +extern const struct desc_ptr trace_idt_descr;
17444 +extern gate_desc trace_idt_table[IDT_ENTRIES];
17445 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17446 {
17447 write_idt_entry(trace_idt_table, entry, gate);
17448 }
17449
17450 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
17451 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
17452 unsigned dpl, unsigned ist, unsigned seg)
17453 {
17454 gate_desc s;
17455 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17456 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
17457 #endif
17458
17459 -static inline void _set_gate(int gate, unsigned type, void *addr,
17460 +static inline void _set_gate(int gate, unsigned type, const void *addr,
17461 unsigned dpl, unsigned ist, unsigned seg)
17462 {
17463 gate_desc s;
17464 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
17465 #define set_intr_gate(n, addr) \
17466 do { \
17467 BUG_ON((unsigned)n > 0xFF); \
17468 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
17469 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
17470 __KERNEL_CS); \
17471 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
17472 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
17473 0, 0, __KERNEL_CS); \
17474 } while (0)
17475
17476 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
17477 /*
17478 * This routine sets up an interrupt gate at directory privilege level 3.
17479 */
17480 -static inline void set_system_intr_gate(unsigned int n, void *addr)
17481 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
17482 {
17483 BUG_ON((unsigned)n > 0xFF);
17484 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
17485 }
17486
17487 -static inline void set_system_trap_gate(unsigned int n, void *addr)
17488 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
17489 {
17490 BUG_ON((unsigned)n > 0xFF);
17491 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
17492 }
17493
17494 -static inline void set_trap_gate(unsigned int n, void *addr)
17495 +static inline void set_trap_gate(unsigned int n, const void *addr)
17496 {
17497 BUG_ON((unsigned)n > 0xFF);
17498 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
17499 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
17500 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
17501 {
17502 BUG_ON((unsigned)n > 0xFF);
17503 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
17504 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
17505 }
17506
17507 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
17508 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
17509 {
17510 BUG_ON((unsigned)n > 0xFF);
17511 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
17512 }
17513
17514 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
17515 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
17516 {
17517 BUG_ON((unsigned)n > 0xFF);
17518 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
17519 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
17520 else
17521 load_idt((const struct desc_ptr *)&idt_descr);
17522 }
17523 +
17524 +#ifdef CONFIG_X86_32
17525 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
17526 +{
17527 + struct desc_struct d;
17528 +
17529 + if (likely(limit))
17530 + limit = (limit - 1UL) >> PAGE_SHIFT;
17531 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
17532 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
17533 +}
17534 +#endif
17535 +
17536 #endif /* _ASM_X86_DESC_H */
17537 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17538 index 278441f..b95a174 100644
17539 --- a/arch/x86/include/asm/desc_defs.h
17540 +++ b/arch/x86/include/asm/desc_defs.h
17541 @@ -31,6 +31,12 @@ struct desc_struct {
17542 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17543 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17544 };
17545 + struct {
17546 + u16 offset_low;
17547 + u16 seg;
17548 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17549 + unsigned offset_high: 16;
17550 + } gate;
17551 };
17552 } __attribute__((packed));
17553
17554 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17555 index ced283a..ffe04cc 100644
17556 --- a/arch/x86/include/asm/div64.h
17557 +++ b/arch/x86/include/asm/div64.h
17558 @@ -39,7 +39,7 @@
17559 __mod; \
17560 })
17561
17562 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17563 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17564 {
17565 union {
17566 u64 v64;
17567 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17568 index ca3347a..1a5082a 100644
17569 --- a/arch/x86/include/asm/elf.h
17570 +++ b/arch/x86/include/asm/elf.h
17571 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17572
17573 #include <asm/vdso.h>
17574
17575 -#ifdef CONFIG_X86_64
17576 -extern unsigned int vdso64_enabled;
17577 -#endif
17578 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17579 extern unsigned int vdso32_enabled;
17580 #endif
17581 @@ -249,7 +246,25 @@ extern int force_personality32;
17582 the loader. We need to make sure that it is out of the way of the program
17583 that it will "exec", and that there is sufficient room for the brk. */
17584
17585 +#ifdef CONFIG_PAX_SEGMEXEC
17586 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17587 +#else
17588 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17589 +#endif
17590 +
17591 +#ifdef CONFIG_PAX_ASLR
17592 +#ifdef CONFIG_X86_32
17593 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17594 +
17595 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17596 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17597 +#else
17598 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17599 +
17600 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17601 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17602 +#endif
17603 +#endif
17604
17605 /* This yields a mask that user programs can use to figure out what
17606 instruction set this CPU supports. This could be done in user space,
17607 @@ -298,17 +313,13 @@ do { \
17608
17609 #define ARCH_DLINFO \
17610 do { \
17611 - if (vdso64_enabled) \
17612 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17613 - (unsigned long __force)current->mm->context.vdso); \
17614 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17615 } while (0)
17616
17617 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17618 #define ARCH_DLINFO_X32 \
17619 do { \
17620 - if (vdso64_enabled) \
17621 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17622 - (unsigned long __force)current->mm->context.vdso); \
17623 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17624 } while (0)
17625
17626 #define AT_SYSINFO 32
17627 @@ -323,10 +334,10 @@ else \
17628
17629 #endif /* !CONFIG_X86_32 */
17630
17631 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17632 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17633
17634 #define VDSO_ENTRY \
17635 - ((unsigned long)current->mm->context.vdso + \
17636 + (current->mm->context.vdso + \
17637 selected_vdso32->sym___kernel_vsyscall)
17638
17639 struct linux_binprm;
17640 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17641 int uses_interp);
17642 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17643
17644 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17645 -#define arch_randomize_brk arch_randomize_brk
17646 -
17647 /*
17648 * True on X86_32 or when emulating IA32 on X86_64
17649 */
17650 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17651 index 77a99ac..39ff7f5 100644
17652 --- a/arch/x86/include/asm/emergency-restart.h
17653 +++ b/arch/x86/include/asm/emergency-restart.h
17654 @@ -1,6 +1,6 @@
17655 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17656 #define _ASM_X86_EMERGENCY_RESTART_H
17657
17658 -extern void machine_emergency_restart(void);
17659 +extern void machine_emergency_restart(void) __noreturn;
17660
17661 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17662 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17663 index 1c7eefe..d0e4702 100644
17664 --- a/arch/x86/include/asm/floppy.h
17665 +++ b/arch/x86/include/asm/floppy.h
17666 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17667 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17668 } fd_routine[] = {
17669 {
17670 - request_dma,
17671 - free_dma,
17672 - get_dma_residue,
17673 - dma_mem_alloc,
17674 - hard_dma_setup
17675 + ._request_dma = request_dma,
17676 + ._free_dma = free_dma,
17677 + ._get_dma_residue = get_dma_residue,
17678 + ._dma_mem_alloc = dma_mem_alloc,
17679 + ._dma_setup = hard_dma_setup
17680 },
17681 {
17682 - vdma_request_dma,
17683 - vdma_nop,
17684 - vdma_get_dma_residue,
17685 - vdma_mem_alloc,
17686 - vdma_dma_setup
17687 + ._request_dma = vdma_request_dma,
17688 + ._free_dma = vdma_nop,
17689 + ._get_dma_residue = vdma_get_dma_residue,
17690 + ._dma_mem_alloc = vdma_mem_alloc,
17691 + ._dma_setup = vdma_dma_setup
17692 }
17693 };
17694
17695 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17696 index 412ecec..c1ea43a 100644
17697 --- a/arch/x86/include/asm/fpu-internal.h
17698 +++ b/arch/x86/include/asm/fpu-internal.h
17699 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17700 #define user_insn(insn, output, input...) \
17701 ({ \
17702 int err; \
17703 + pax_open_userland(); \
17704 asm volatile(ASM_STAC "\n" \
17705 - "1:" #insn "\n\t" \
17706 + "1:" \
17707 + __copyuser_seg \
17708 + #insn "\n\t" \
17709 "2: " ASM_CLAC "\n" \
17710 ".section .fixup,\"ax\"\n" \
17711 "3: movl $-1,%[err]\n" \
17712 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17713 _ASM_EXTABLE(1b, 3b) \
17714 : [err] "=r" (err), output \
17715 : "0"(0), input); \
17716 + pax_close_userland(); \
17717 err; \
17718 })
17719
17720 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17721 "fnclex\n\t"
17722 "emms\n\t"
17723 "fildl %P[addr]" /* set F?P to defined value */
17724 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17725 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17726 }
17727
17728 return fpu_restore_checking(&tsk->thread.fpu);
17729 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17730 index b4c1f54..e290c08 100644
17731 --- a/arch/x86/include/asm/futex.h
17732 +++ b/arch/x86/include/asm/futex.h
17733 @@ -12,6 +12,7 @@
17734 #include <asm/smap.h>
17735
17736 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17737 + typecheck(u32 __user *, uaddr); \
17738 asm volatile("\t" ASM_STAC "\n" \
17739 "1:\t" insn "\n" \
17740 "2:\t" ASM_CLAC "\n" \
17741 @@ -20,15 +21,16 @@
17742 "\tjmp\t2b\n" \
17743 "\t.previous\n" \
17744 _ASM_EXTABLE(1b, 3b) \
17745 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17746 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17747 : "i" (-EFAULT), "0" (oparg), "1" (0))
17748
17749 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17750 + typecheck(u32 __user *, uaddr); \
17751 asm volatile("\t" ASM_STAC "\n" \
17752 "1:\tmovl %2, %0\n" \
17753 "\tmovl\t%0, %3\n" \
17754 "\t" insn "\n" \
17755 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17756 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17757 "\tjnz\t1b\n" \
17758 "3:\t" ASM_CLAC "\n" \
17759 "\t.section .fixup,\"ax\"\n" \
17760 @@ -38,7 +40,7 @@
17761 _ASM_EXTABLE(1b, 4b) \
17762 _ASM_EXTABLE(2b, 4b) \
17763 : "=&a" (oldval), "=&r" (ret), \
17764 - "+m" (*uaddr), "=&r" (tem) \
17765 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17766 : "r" (oparg), "i" (-EFAULT), "1" (0))
17767
17768 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17769 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17770
17771 pagefault_disable();
17772
17773 + pax_open_userland();
17774 switch (op) {
17775 case FUTEX_OP_SET:
17776 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17777 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17778 break;
17779 case FUTEX_OP_ADD:
17780 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17781 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17782 uaddr, oparg);
17783 break;
17784 case FUTEX_OP_OR:
17785 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17786 default:
17787 ret = -ENOSYS;
17788 }
17789 + pax_close_userland();
17790
17791 pagefault_enable();
17792
17793 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17794 index 4615906..788c817 100644
17795 --- a/arch/x86/include/asm/hw_irq.h
17796 +++ b/arch/x86/include/asm/hw_irq.h
17797 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17798 extern void enable_IO_APIC(void);
17799
17800 /* Statistics */
17801 -extern atomic_t irq_err_count;
17802 -extern atomic_t irq_mis_count;
17803 +extern atomic_unchecked_t irq_err_count;
17804 +extern atomic_unchecked_t irq_mis_count;
17805
17806 /* EISA */
17807 extern void eisa_set_level_irq(unsigned int irq);
17808 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17809 index ccffa53..3c90c87 100644
17810 --- a/arch/x86/include/asm/i8259.h
17811 +++ b/arch/x86/include/asm/i8259.h
17812 @@ -62,7 +62,7 @@ struct legacy_pic {
17813 void (*init)(int auto_eoi);
17814 int (*irq_pending)(unsigned int irq);
17815 void (*make_irq)(unsigned int irq);
17816 -};
17817 +} __do_const;
17818
17819 extern struct legacy_pic *legacy_pic;
17820 extern struct legacy_pic null_legacy_pic;
17821 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17822 index b8237d8..3e8864e 100644
17823 --- a/arch/x86/include/asm/io.h
17824 +++ b/arch/x86/include/asm/io.h
17825 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17826 "m" (*(volatile type __force *)addr) barrier); }
17827
17828 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17829 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17830 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17831 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17832 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17833
17834 build_mmio_read(__readb, "b", unsigned char, "=q", )
17835 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17836 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17837 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17838 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17839
17840 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17841 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17842 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17843 * this function
17844 */
17845
17846 -static inline phys_addr_t virt_to_phys(volatile void *address)
17847 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17848 {
17849 return __pa(address);
17850 }
17851 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17852 return ioremap_nocache(offset, size);
17853 }
17854
17855 -extern void iounmap(volatile void __iomem *addr);
17856 +extern void iounmap(const volatile void __iomem *addr);
17857
17858 extern void set_iounmap_nonlazy(void);
17859
17860 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17861
17862 #include <linux/vmalloc.h>
17863
17864 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17865 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17866 +{
17867 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17868 +}
17869 +
17870 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17871 +{
17872 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17873 +}
17874 +
17875 /*
17876 * Convert a virtual cached pointer to an uncached pointer
17877 */
17878 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17879 index 0a8b519..80e7d5b 100644
17880 --- a/arch/x86/include/asm/irqflags.h
17881 +++ b/arch/x86/include/asm/irqflags.h
17882 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17883 sti; \
17884 sysexit
17885
17886 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17887 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17888 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17889 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17890 +
17891 #else
17892 #define INTERRUPT_RETURN iret
17893 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17894 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17895 index 53cdfb2..d1369e6 100644
17896 --- a/arch/x86/include/asm/kprobes.h
17897 +++ b/arch/x86/include/asm/kprobes.h
17898 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17899 #define RELATIVEJUMP_SIZE 5
17900 #define RELATIVECALL_OPCODE 0xe8
17901 #define RELATIVE_ADDR_SIZE 4
17902 -#define MAX_STACK_SIZE 64
17903 -#define MIN_STACK_SIZE(ADDR) \
17904 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17905 - THREAD_SIZE - (unsigned long)(ADDR))) \
17906 - ? (MAX_STACK_SIZE) \
17907 - : (((unsigned long)current_thread_info()) + \
17908 - THREAD_SIZE - (unsigned long)(ADDR)))
17909 +#define MAX_STACK_SIZE 64UL
17910 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17911
17912 #define flush_insn_slot(p) do { } while (0)
17913
17914 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17915 index 4ad6560..75c7bdd 100644
17916 --- a/arch/x86/include/asm/local.h
17917 +++ b/arch/x86/include/asm/local.h
17918 @@ -10,33 +10,97 @@ typedef struct {
17919 atomic_long_t a;
17920 } local_t;
17921
17922 +typedef struct {
17923 + atomic_long_unchecked_t a;
17924 +} local_unchecked_t;
17925 +
17926 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17927
17928 #define local_read(l) atomic_long_read(&(l)->a)
17929 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17930 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17931 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17932
17933 static inline void local_inc(local_t *l)
17934 {
17935 - asm volatile(_ASM_INC "%0"
17936 + asm volatile(_ASM_INC "%0\n"
17937 +
17938 +#ifdef CONFIG_PAX_REFCOUNT
17939 + "jno 0f\n"
17940 + _ASM_DEC "%0\n"
17941 + "int $4\n0:\n"
17942 + _ASM_EXTABLE(0b, 0b)
17943 +#endif
17944 +
17945 + : "+m" (l->a.counter));
17946 +}
17947 +
17948 +static inline void local_inc_unchecked(local_unchecked_t *l)
17949 +{
17950 + asm volatile(_ASM_INC "%0\n"
17951 : "+m" (l->a.counter));
17952 }
17953
17954 static inline void local_dec(local_t *l)
17955 {
17956 - asm volatile(_ASM_DEC "%0"
17957 + asm volatile(_ASM_DEC "%0\n"
17958 +
17959 +#ifdef CONFIG_PAX_REFCOUNT
17960 + "jno 0f\n"
17961 + _ASM_INC "%0\n"
17962 + "int $4\n0:\n"
17963 + _ASM_EXTABLE(0b, 0b)
17964 +#endif
17965 +
17966 + : "+m" (l->a.counter));
17967 +}
17968 +
17969 +static inline void local_dec_unchecked(local_unchecked_t *l)
17970 +{
17971 + asm volatile(_ASM_DEC "%0\n"
17972 : "+m" (l->a.counter));
17973 }
17974
17975 static inline void local_add(long i, local_t *l)
17976 {
17977 - asm volatile(_ASM_ADD "%1,%0"
17978 + asm volatile(_ASM_ADD "%1,%0\n"
17979 +
17980 +#ifdef CONFIG_PAX_REFCOUNT
17981 + "jno 0f\n"
17982 + _ASM_SUB "%1,%0\n"
17983 + "int $4\n0:\n"
17984 + _ASM_EXTABLE(0b, 0b)
17985 +#endif
17986 +
17987 + : "+m" (l->a.counter)
17988 + : "ir" (i));
17989 +}
17990 +
17991 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17992 +{
17993 + asm volatile(_ASM_ADD "%1,%0\n"
17994 : "+m" (l->a.counter)
17995 : "ir" (i));
17996 }
17997
17998 static inline void local_sub(long i, local_t *l)
17999 {
18000 - asm volatile(_ASM_SUB "%1,%0"
18001 + asm volatile(_ASM_SUB "%1,%0\n"
18002 +
18003 +#ifdef CONFIG_PAX_REFCOUNT
18004 + "jno 0f\n"
18005 + _ASM_ADD "%1,%0\n"
18006 + "int $4\n0:\n"
18007 + _ASM_EXTABLE(0b, 0b)
18008 +#endif
18009 +
18010 + : "+m" (l->a.counter)
18011 + : "ir" (i));
18012 +}
18013 +
18014 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
18015 +{
18016 + asm volatile(_ASM_SUB "%1,%0\n"
18017 : "+m" (l->a.counter)
18018 : "ir" (i));
18019 }
18020 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
18021 */
18022 static inline int local_sub_and_test(long i, local_t *l)
18023 {
18024 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
18025 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
18026 }
18027
18028 /**
18029 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
18030 */
18031 static inline int local_dec_and_test(local_t *l)
18032 {
18033 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
18034 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
18035 }
18036
18037 /**
18038 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
18039 */
18040 static inline int local_inc_and_test(local_t *l)
18041 {
18042 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
18043 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
18044 }
18045
18046 /**
18047 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
18048 */
18049 static inline int local_add_negative(long i, local_t *l)
18050 {
18051 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
18052 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
18053 }
18054
18055 /**
18056 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
18057 static inline long local_add_return(long i, local_t *l)
18058 {
18059 long __i = i;
18060 + asm volatile(_ASM_XADD "%0, %1\n"
18061 +
18062 +#ifdef CONFIG_PAX_REFCOUNT
18063 + "jno 0f\n"
18064 + _ASM_MOV "%0,%1\n"
18065 + "int $4\n0:\n"
18066 + _ASM_EXTABLE(0b, 0b)
18067 +#endif
18068 +
18069 + : "+r" (i), "+m" (l->a.counter)
18070 + : : "memory");
18071 + return i + __i;
18072 +}
18073 +
18074 +/**
18075 + * local_add_return_unchecked - add and return
18076 + * @i: integer value to add
18077 + * @l: pointer to type local_unchecked_t
18078 + *
18079 + * Atomically adds @i to @l and returns @i + @l
18080 + */
18081 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
18082 +{
18083 + long __i = i;
18084 asm volatile(_ASM_XADD "%0, %1;"
18085 : "+r" (i), "+m" (l->a.counter)
18086 : : "memory");
18087 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
18088
18089 #define local_cmpxchg(l, o, n) \
18090 (cmpxchg_local(&((l)->a.counter), (o), (n)))
18091 +#define local_cmpxchg_unchecked(l, o, n) \
18092 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
18093 /* Always has a lock prefix */
18094 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
18095
18096 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
18097 new file mode 100644
18098 index 0000000..2bfd3ba
18099 --- /dev/null
18100 +++ b/arch/x86/include/asm/mman.h
18101 @@ -0,0 +1,15 @@
18102 +#ifndef _X86_MMAN_H
18103 +#define _X86_MMAN_H
18104 +
18105 +#include <uapi/asm/mman.h>
18106 +
18107 +#ifdef __KERNEL__
18108 +#ifndef __ASSEMBLY__
18109 +#ifdef CONFIG_X86_32
18110 +#define arch_mmap_check i386_mmap_check
18111 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
18112 +#endif
18113 +#endif
18114 +#endif
18115 +
18116 +#endif /* X86_MMAN_H */
18117 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
18118 index 876e74e..e20bfb1 100644
18119 --- a/arch/x86/include/asm/mmu.h
18120 +++ b/arch/x86/include/asm/mmu.h
18121 @@ -9,7 +9,7 @@
18122 * we put the segment information here.
18123 */
18124 typedef struct {
18125 - void *ldt;
18126 + struct desc_struct *ldt;
18127 int size;
18128
18129 #ifdef CONFIG_X86_64
18130 @@ -18,7 +18,19 @@ typedef struct {
18131 #endif
18132
18133 struct mutex lock;
18134 - void __user *vdso;
18135 + unsigned long vdso;
18136 +
18137 +#ifdef CONFIG_X86_32
18138 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18139 + unsigned long user_cs_base;
18140 + unsigned long user_cs_limit;
18141 +
18142 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18143 + cpumask_t cpu_user_cs_mask;
18144 +#endif
18145 +
18146 +#endif
18147 +#endif
18148 } mm_context_t;
18149
18150 #ifdef CONFIG_SMP
18151 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
18152 index 166af2a..648c200 100644
18153 --- a/arch/x86/include/asm/mmu_context.h
18154 +++ b/arch/x86/include/asm/mmu_context.h
18155 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
18156
18157 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
18158 {
18159 +
18160 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18161 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
18162 + unsigned int i;
18163 + pgd_t *pgd;
18164 +
18165 + pax_open_kernel();
18166 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
18167 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
18168 + set_pgd_batched(pgd+i, native_make_pgd(0));
18169 + pax_close_kernel();
18170 + }
18171 +#endif
18172 +
18173 #ifdef CONFIG_SMP
18174 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
18175 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
18176 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18177 struct task_struct *tsk)
18178 {
18179 unsigned cpu = smp_processor_id();
18180 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18181 + int tlbstate = TLBSTATE_OK;
18182 +#endif
18183
18184 if (likely(prev != next)) {
18185 #ifdef CONFIG_SMP
18186 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18187 + tlbstate = this_cpu_read(cpu_tlbstate.state);
18188 +#endif
18189 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18190 this_cpu_write(cpu_tlbstate.active_mm, next);
18191 #endif
18192 cpumask_set_cpu(cpu, mm_cpumask(next));
18193
18194 /* Re-load page tables */
18195 +#ifdef CONFIG_PAX_PER_CPU_PGD
18196 + pax_open_kernel();
18197 +
18198 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18199 + if (static_cpu_has(X86_FEATURE_PCID))
18200 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18201 + else
18202 +#endif
18203 +
18204 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18205 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18206 + pax_close_kernel();
18207 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
18208 +
18209 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18210 + if (static_cpu_has(X86_FEATURE_PCID)) {
18211 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18212 + u64 descriptor[2];
18213 + descriptor[0] = PCID_USER;
18214 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18215 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18216 + descriptor[0] = PCID_KERNEL;
18217 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18218 + }
18219 + } else {
18220 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18221 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18222 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18223 + else
18224 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18225 + }
18226 + } else
18227 +#endif
18228 +
18229 + load_cr3(get_cpu_pgd(cpu, kernel));
18230 +#else
18231 load_cr3(next->pgd);
18232 +#endif
18233 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18234
18235 /* Stop flush ipis for the previous mm */
18236 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18237 /* Load the LDT, if the LDT is different: */
18238 if (unlikely(prev->context.ldt != next->context.ldt))
18239 load_LDT_nolock(&next->context);
18240 +
18241 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18242 + if (!(__supported_pte_mask & _PAGE_NX)) {
18243 + smp_mb__before_atomic();
18244 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
18245 + smp_mb__after_atomic();
18246 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18247 + }
18248 +#endif
18249 +
18250 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18251 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
18252 + prev->context.user_cs_limit != next->context.user_cs_limit))
18253 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18254 +#ifdef CONFIG_SMP
18255 + else if (unlikely(tlbstate != TLBSTATE_OK))
18256 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18257 +#endif
18258 +#endif
18259 +
18260 }
18261 + else {
18262 +
18263 +#ifdef CONFIG_PAX_PER_CPU_PGD
18264 + pax_open_kernel();
18265 +
18266 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18267 + if (static_cpu_has(X86_FEATURE_PCID))
18268 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18269 + else
18270 +#endif
18271 +
18272 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18273 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18274 + pax_close_kernel();
18275 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
18276 +
18277 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18278 + if (static_cpu_has(X86_FEATURE_PCID)) {
18279 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18280 + u64 descriptor[2];
18281 + descriptor[0] = PCID_USER;
18282 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18283 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18284 + descriptor[0] = PCID_KERNEL;
18285 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18286 + }
18287 + } else {
18288 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18289 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18290 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18291 + else
18292 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18293 + }
18294 + } else
18295 +#endif
18296 +
18297 + load_cr3(get_cpu_pgd(cpu, kernel));
18298 +#endif
18299 +
18300 #ifdef CONFIG_SMP
18301 - else {
18302 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18303 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
18304
18305 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18306 * tlb flush IPI delivery. We must reload CR3
18307 * to make sure to use no freed page tables.
18308 */
18309 +
18310 +#ifndef CONFIG_PAX_PER_CPU_PGD
18311 load_cr3(next->pgd);
18312 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18313 +#endif
18314 +
18315 load_LDT_nolock(&next->context);
18316 +
18317 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18318 + if (!(__supported_pte_mask & _PAGE_NX))
18319 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18320 +#endif
18321 +
18322 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18323 +#ifdef CONFIG_PAX_PAGEEXEC
18324 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
18325 +#endif
18326 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18327 +#endif
18328 +
18329 }
18330 +#endif
18331 }
18332 -#endif
18333 }
18334
18335 #define activate_mm(prev, next) \
18336 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
18337 index e3b7819..b257c64 100644
18338 --- a/arch/x86/include/asm/module.h
18339 +++ b/arch/x86/include/asm/module.h
18340 @@ -5,6 +5,7 @@
18341
18342 #ifdef CONFIG_X86_64
18343 /* X86_64 does not define MODULE_PROC_FAMILY */
18344 +#define MODULE_PROC_FAMILY ""
18345 #elif defined CONFIG_M486
18346 #define MODULE_PROC_FAMILY "486 "
18347 #elif defined CONFIG_M586
18348 @@ -57,8 +58,20 @@
18349 #error unknown processor family
18350 #endif
18351
18352 -#ifdef CONFIG_X86_32
18353 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
18354 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
18355 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
18356 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
18357 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
18358 +#else
18359 +#define MODULE_PAX_KERNEXEC ""
18360 #endif
18361
18362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18363 +#define MODULE_PAX_UDEREF "UDEREF "
18364 +#else
18365 +#define MODULE_PAX_UDEREF ""
18366 +#endif
18367 +
18368 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
18369 +
18370 #endif /* _ASM_X86_MODULE_H */
18371 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
18372 index 5f2fc44..106caa6 100644
18373 --- a/arch/x86/include/asm/nmi.h
18374 +++ b/arch/x86/include/asm/nmi.h
18375 @@ -36,26 +36,35 @@ enum {
18376
18377 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
18378
18379 +struct nmiaction;
18380 +
18381 +struct nmiwork {
18382 + const struct nmiaction *action;
18383 + u64 max_duration;
18384 + struct irq_work irq_work;
18385 +};
18386 +
18387 struct nmiaction {
18388 struct list_head list;
18389 nmi_handler_t handler;
18390 - u64 max_duration;
18391 - struct irq_work irq_work;
18392 unsigned long flags;
18393 const char *name;
18394 -};
18395 + struct nmiwork *work;
18396 +} __do_const;
18397
18398 #define register_nmi_handler(t, fn, fg, n, init...) \
18399 ({ \
18400 - static struct nmiaction init fn##_na = { \
18401 + static struct nmiwork fn##_nw; \
18402 + static const struct nmiaction init fn##_na = { \
18403 .handler = (fn), \
18404 .name = (n), \
18405 .flags = (fg), \
18406 + .work = &fn##_nw, \
18407 }; \
18408 __register_nmi_handler((t), &fn##_na); \
18409 })
18410
18411 -int __register_nmi_handler(unsigned int, struct nmiaction *);
18412 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
18413
18414 void unregister_nmi_handler(unsigned int, const char *);
18415
18416 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
18417 index 802dde3..9183e68 100644
18418 --- a/arch/x86/include/asm/page.h
18419 +++ b/arch/x86/include/asm/page.h
18420 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18421 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
18422
18423 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
18424 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
18425
18426 #define __boot_va(x) __va(x)
18427 #define __boot_pa(x) __pa(x)
18428 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18429 * virt_to_page(kaddr) returns a valid pointer if and only if
18430 * virt_addr_valid(kaddr) returns true.
18431 */
18432 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18433 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
18434 extern bool __virt_addr_valid(unsigned long kaddr);
18435 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
18436
18437 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
18438 +#define virt_to_page(kaddr) \
18439 + ({ \
18440 + const void *__kaddr = (const void *)(kaddr); \
18441 + BUG_ON(!virt_addr_valid(__kaddr)); \
18442 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
18443 + })
18444 +#else
18445 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18446 +#endif
18447 +
18448 #endif /* __ASSEMBLY__ */
18449
18450 #include <asm-generic/memory_model.h>
18451 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
18452 index f408caf..4a0455e 100644
18453 --- a/arch/x86/include/asm/page_64.h
18454 +++ b/arch/x86/include/asm/page_64.h
18455 @@ -7,9 +7,9 @@
18456
18457 /* duplicated to the one in bootmem.h */
18458 extern unsigned long max_pfn;
18459 -extern unsigned long phys_base;
18460 +extern const unsigned long phys_base;
18461
18462 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
18463 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
18464 {
18465 unsigned long y = x - __START_KERNEL_map;
18466
18467 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
18468 index cd6e1610..70f4418 100644
18469 --- a/arch/x86/include/asm/paravirt.h
18470 +++ b/arch/x86/include/asm/paravirt.h
18471 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
18472 return (pmd_t) { ret };
18473 }
18474
18475 -static inline pmdval_t pmd_val(pmd_t pmd)
18476 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
18477 {
18478 pmdval_t ret;
18479
18480 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
18481 val);
18482 }
18483
18484 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18485 +{
18486 + pgdval_t val = native_pgd_val(pgd);
18487 +
18488 + if (sizeof(pgdval_t) > sizeof(long))
18489 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
18490 + val, (u64)val >> 32);
18491 + else
18492 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
18493 + val);
18494 +}
18495 +
18496 static inline void pgd_clear(pgd_t *pgdp)
18497 {
18498 set_pgd(pgdp, __pgd(0));
18499 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
18500 pv_mmu_ops.set_fixmap(idx, phys, flags);
18501 }
18502
18503 +#ifdef CONFIG_PAX_KERNEXEC
18504 +static inline unsigned long pax_open_kernel(void)
18505 +{
18506 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
18507 +}
18508 +
18509 +static inline unsigned long pax_close_kernel(void)
18510 +{
18511 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
18512 +}
18513 +#else
18514 +static inline unsigned long pax_open_kernel(void) { return 0; }
18515 +static inline unsigned long pax_close_kernel(void) { return 0; }
18516 +#endif
18517 +
18518 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
18519
18520 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
18521 @@ -906,7 +933,7 @@ extern void default_banner(void);
18522
18523 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
18524 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
18525 -#define PARA_INDIRECT(addr) *%cs:addr
18526 +#define PARA_INDIRECT(addr) *%ss:addr
18527 #endif
18528
18529 #define INTERRUPT_RETURN \
18530 @@ -981,6 +1008,21 @@ extern void default_banner(void);
18531 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
18532 CLBR_NONE, \
18533 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
18534 +
18535 +#define GET_CR0_INTO_RDI \
18536 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
18537 + mov %rax,%rdi
18538 +
18539 +#define SET_RDI_INTO_CR0 \
18540 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18541 +
18542 +#define GET_CR3_INTO_RDI \
18543 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18544 + mov %rax,%rdi
18545 +
18546 +#define SET_RDI_INTO_CR3 \
18547 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18548 +
18549 #endif /* CONFIG_X86_32 */
18550
18551 #endif /* __ASSEMBLY__ */
18552 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18553 index 7549b8b..f0edfda 100644
18554 --- a/arch/x86/include/asm/paravirt_types.h
18555 +++ b/arch/x86/include/asm/paravirt_types.h
18556 @@ -84,7 +84,7 @@ struct pv_init_ops {
18557 */
18558 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18559 unsigned long addr, unsigned len);
18560 -};
18561 +} __no_const __no_randomize_layout;
18562
18563
18564 struct pv_lazy_ops {
18565 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
18566 void (*enter)(void);
18567 void (*leave)(void);
18568 void (*flush)(void);
18569 -};
18570 +} __no_randomize_layout;
18571
18572 struct pv_time_ops {
18573 unsigned long long (*sched_clock)(void);
18574 unsigned long long (*steal_clock)(int cpu);
18575 unsigned long (*get_tsc_khz)(void);
18576 -};
18577 +} __no_const __no_randomize_layout;
18578
18579 struct pv_cpu_ops {
18580 /* hooks for various privileged instructions */
18581 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18582
18583 void (*start_context_switch)(struct task_struct *prev);
18584 void (*end_context_switch)(struct task_struct *next);
18585 -};
18586 +} __no_const __no_randomize_layout;
18587
18588 struct pv_irq_ops {
18589 /*
18590 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18591 #ifdef CONFIG_X86_64
18592 void (*adjust_exception_frame)(void);
18593 #endif
18594 -};
18595 +} __no_randomize_layout;
18596
18597 struct pv_apic_ops {
18598 #ifdef CONFIG_X86_LOCAL_APIC
18599 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18600 unsigned long start_eip,
18601 unsigned long start_esp);
18602 #endif
18603 -};
18604 +} __no_const __no_randomize_layout;
18605
18606 struct pv_mmu_ops {
18607 unsigned long (*read_cr2)(void);
18608 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18609 struct paravirt_callee_save make_pud;
18610
18611 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18612 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18613 #endif /* PAGETABLE_LEVELS == 4 */
18614 #endif /* PAGETABLE_LEVELS >= 3 */
18615
18616 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18617 an mfn. We can tell which is which from the index. */
18618 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18619 phys_addr_t phys, pgprot_t flags);
18620 -};
18621 +
18622 +#ifdef CONFIG_PAX_KERNEXEC
18623 + unsigned long (*pax_open_kernel)(void);
18624 + unsigned long (*pax_close_kernel)(void);
18625 +#endif
18626 +
18627 +} __no_randomize_layout;
18628
18629 struct arch_spinlock;
18630 #ifdef CONFIG_SMP
18631 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18632 struct pv_lock_ops {
18633 struct paravirt_callee_save lock_spinning;
18634 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18635 -};
18636 +} __no_randomize_layout;
18637
18638 /* This contains all the paravirt structures: we get a convenient
18639 * number for each function using the offset which we use to indicate
18640 - * what to patch. */
18641 + * what to patch.
18642 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18643 + */
18644 +
18645 struct paravirt_patch_template {
18646 struct pv_init_ops pv_init_ops;
18647 struct pv_time_ops pv_time_ops;
18648 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18649 struct pv_apic_ops pv_apic_ops;
18650 struct pv_mmu_ops pv_mmu_ops;
18651 struct pv_lock_ops pv_lock_ops;
18652 -};
18653 +} __no_randomize_layout;
18654
18655 extern struct pv_info pv_info;
18656 extern struct pv_init_ops pv_init_ops;
18657 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18658 index c4412e9..90e88c5 100644
18659 --- a/arch/x86/include/asm/pgalloc.h
18660 +++ b/arch/x86/include/asm/pgalloc.h
18661 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18662 pmd_t *pmd, pte_t *pte)
18663 {
18664 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18665 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18666 +}
18667 +
18668 +static inline void pmd_populate_user(struct mm_struct *mm,
18669 + pmd_t *pmd, pte_t *pte)
18670 +{
18671 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18672 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18673 }
18674
18675 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18676
18677 #ifdef CONFIG_X86_PAE
18678 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18679 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18680 +{
18681 + pud_populate(mm, pudp, pmd);
18682 +}
18683 #else /* !CONFIG_X86_PAE */
18684 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18685 {
18686 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18687 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18688 }
18689 +
18690 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18691 +{
18692 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18693 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18694 +}
18695 #endif /* CONFIG_X86_PAE */
18696
18697 #if PAGETABLE_LEVELS > 3
18698 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18699 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18700 }
18701
18702 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18703 +{
18704 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18705 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18706 +}
18707 +
18708 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18709 {
18710 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18711 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18712 index 206a87f..1623b06 100644
18713 --- a/arch/x86/include/asm/pgtable-2level.h
18714 +++ b/arch/x86/include/asm/pgtable-2level.h
18715 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18716
18717 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18718 {
18719 + pax_open_kernel();
18720 *pmdp = pmd;
18721 + pax_close_kernel();
18722 }
18723
18724 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18725 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18726 index 81bb91b..9392125 100644
18727 --- a/arch/x86/include/asm/pgtable-3level.h
18728 +++ b/arch/x86/include/asm/pgtable-3level.h
18729 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18730
18731 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18732 {
18733 + pax_open_kernel();
18734 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18735 + pax_close_kernel();
18736 }
18737
18738 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18739 {
18740 + pax_open_kernel();
18741 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18742 + pax_close_kernel();
18743 }
18744
18745 /*
18746 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18747 index aa97a07..5c53c32 100644
18748 --- a/arch/x86/include/asm/pgtable.h
18749 +++ b/arch/x86/include/asm/pgtable.h
18750 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18751
18752 #ifndef __PAGETABLE_PUD_FOLDED
18753 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18754 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18755 #define pgd_clear(pgd) native_pgd_clear(pgd)
18756 #endif
18757
18758 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18759
18760 #define arch_end_context_switch(prev) do {} while(0)
18761
18762 +#define pax_open_kernel() native_pax_open_kernel()
18763 +#define pax_close_kernel() native_pax_close_kernel()
18764 #endif /* CONFIG_PARAVIRT */
18765
18766 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18767 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18768 +
18769 +#ifdef CONFIG_PAX_KERNEXEC
18770 +static inline unsigned long native_pax_open_kernel(void)
18771 +{
18772 + unsigned long cr0;
18773 +
18774 + preempt_disable();
18775 + barrier();
18776 + cr0 = read_cr0() ^ X86_CR0_WP;
18777 + BUG_ON(cr0 & X86_CR0_WP);
18778 + write_cr0(cr0);
18779 + barrier();
18780 + return cr0 ^ X86_CR0_WP;
18781 +}
18782 +
18783 +static inline unsigned long native_pax_close_kernel(void)
18784 +{
18785 + unsigned long cr0;
18786 +
18787 + barrier();
18788 + cr0 = read_cr0() ^ X86_CR0_WP;
18789 + BUG_ON(!(cr0 & X86_CR0_WP));
18790 + write_cr0(cr0);
18791 + barrier();
18792 + preempt_enable_no_resched();
18793 + return cr0 ^ X86_CR0_WP;
18794 +}
18795 +#else
18796 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18797 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18798 +#endif
18799 +
18800 /*
18801 * The following only work if pte_present() is true.
18802 * Undefined behaviour if not..
18803 */
18804 +static inline int pte_user(pte_t pte)
18805 +{
18806 + return pte_val(pte) & _PAGE_USER;
18807 +}
18808 +
18809 static inline int pte_dirty(pte_t pte)
18810 {
18811 return pte_flags(pte) & _PAGE_DIRTY;
18812 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18813 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18814 }
18815
18816 +static inline unsigned long pgd_pfn(pgd_t pgd)
18817 +{
18818 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18819 +}
18820 +
18821 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18822
18823 static inline int pmd_large(pmd_t pte)
18824 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18825 return pte_clear_flags(pte, _PAGE_RW);
18826 }
18827
18828 +static inline pte_t pte_mkread(pte_t pte)
18829 +{
18830 + return __pte(pte_val(pte) | _PAGE_USER);
18831 +}
18832 +
18833 static inline pte_t pte_mkexec(pte_t pte)
18834 {
18835 - return pte_clear_flags(pte, _PAGE_NX);
18836 +#ifdef CONFIG_X86_PAE
18837 + if (__supported_pte_mask & _PAGE_NX)
18838 + return pte_clear_flags(pte, _PAGE_NX);
18839 + else
18840 +#endif
18841 + return pte_set_flags(pte, _PAGE_USER);
18842 +}
18843 +
18844 +static inline pte_t pte_exprotect(pte_t pte)
18845 +{
18846 +#ifdef CONFIG_X86_PAE
18847 + if (__supported_pte_mask & _PAGE_NX)
18848 + return pte_set_flags(pte, _PAGE_NX);
18849 + else
18850 +#endif
18851 + return pte_clear_flags(pte, _PAGE_USER);
18852 }
18853
18854 static inline pte_t pte_mkdirty(pte_t pte)
18855 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18856 #endif
18857
18858 #ifndef __ASSEMBLY__
18859 +
18860 +#ifdef CONFIG_PAX_PER_CPU_PGD
18861 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18862 +enum cpu_pgd_type {kernel = 0, user = 1};
18863 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18864 +{
18865 + return cpu_pgd[cpu][type];
18866 +}
18867 +#endif
18868 +
18869 #include <linux/mm_types.h>
18870 #include <linux/mmdebug.h>
18871 #include <linux/log2.h>
18872 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18873 * Currently stuck as a macro due to indirect forward reference to
18874 * linux/mmzone.h's __section_mem_map_addr() definition:
18875 */
18876 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18877 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18878
18879 /* Find an entry in the second-level page table.. */
18880 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18881 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18882 * Currently stuck as a macro due to indirect forward reference to
18883 * linux/mmzone.h's __section_mem_map_addr() definition:
18884 */
18885 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18886 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18887
18888 /* to find an entry in a page-table-directory. */
18889 static inline unsigned long pud_index(unsigned long address)
18890 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18891
18892 static inline int pgd_bad(pgd_t pgd)
18893 {
18894 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18895 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18896 }
18897
18898 static inline int pgd_none(pgd_t pgd)
18899 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18900 * pgd_offset() returns a (pgd_t *)
18901 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18902 */
18903 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18904 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18905 +
18906 +#ifdef CONFIG_PAX_PER_CPU_PGD
18907 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18908 +#endif
18909 +
18910 /*
18911 * a shortcut which implies the use of the kernel's pgd, instead
18912 * of a process's
18913 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18914 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18915 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18916
18917 +#ifdef CONFIG_X86_32
18918 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18919 +#else
18920 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18921 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18922 +
18923 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18924 +#ifdef __ASSEMBLY__
18925 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18926 +#else
18927 +extern unsigned long pax_user_shadow_base;
18928 +extern pgdval_t clone_pgd_mask;
18929 +#endif
18930 +#endif
18931 +
18932 +#endif
18933 +
18934 #ifndef __ASSEMBLY__
18935
18936 extern int direct_gbpages;
18937 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18938 * dst and src can be on the same page, but the range must not overlap,
18939 * and must not cross a page boundary.
18940 */
18941 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18942 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18943 {
18944 - memcpy(dst, src, count * sizeof(pgd_t));
18945 + pax_open_kernel();
18946 + while (count--)
18947 + *dst++ = *src++;
18948 + pax_close_kernel();
18949 }
18950
18951 +#ifdef CONFIG_PAX_PER_CPU_PGD
18952 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18953 +#endif
18954 +
18955 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18956 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18957 +#else
18958 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18959 +#endif
18960 +
18961 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18962 static inline int page_level_shift(enum pg_level level)
18963 {
18964 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18965 index 9ee3221..b979c6b 100644
18966 --- a/arch/x86/include/asm/pgtable_32.h
18967 +++ b/arch/x86/include/asm/pgtable_32.h
18968 @@ -25,9 +25,6 @@
18969 struct mm_struct;
18970 struct vm_area_struct;
18971
18972 -extern pgd_t swapper_pg_dir[1024];
18973 -extern pgd_t initial_page_table[1024];
18974 -
18975 static inline void pgtable_cache_init(void) { }
18976 static inline void check_pgt_cache(void) { }
18977 void paging_init(void);
18978 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18979 # include <asm/pgtable-2level.h>
18980 #endif
18981
18982 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18983 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18984 +#ifdef CONFIG_X86_PAE
18985 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18986 +#endif
18987 +
18988 #if defined(CONFIG_HIGHPTE)
18989 #define pte_offset_map(dir, address) \
18990 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18991 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18992 /* Clear a kernel PTE and flush it from the TLB */
18993 #define kpte_clear_flush(ptep, vaddr) \
18994 do { \
18995 + pax_open_kernel(); \
18996 pte_clear(&init_mm, (vaddr), (ptep)); \
18997 + pax_close_kernel(); \
18998 __flush_tlb_one((vaddr)); \
18999 } while (0)
19000
19001 #endif /* !__ASSEMBLY__ */
19002
19003 +#define HAVE_ARCH_UNMAPPED_AREA
19004 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
19005 +
19006 /*
19007 * kern_addr_valid() is (1) for FLATMEM and (0) for
19008 * SPARSEMEM and DISCONTIGMEM
19009 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
19010 index ed5903b..c7fe163 100644
19011 --- a/arch/x86/include/asm/pgtable_32_types.h
19012 +++ b/arch/x86/include/asm/pgtable_32_types.h
19013 @@ -8,7 +8,7 @@
19014 */
19015 #ifdef CONFIG_X86_PAE
19016 # include <asm/pgtable-3level_types.h>
19017 -# define PMD_SIZE (1UL << PMD_SHIFT)
19018 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
19019 # define PMD_MASK (~(PMD_SIZE - 1))
19020 #else
19021 # include <asm/pgtable-2level_types.h>
19022 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
19023 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
19024 #endif
19025
19026 +#ifdef CONFIG_PAX_KERNEXEC
19027 +#ifndef __ASSEMBLY__
19028 +extern unsigned char MODULES_EXEC_VADDR[];
19029 +extern unsigned char MODULES_EXEC_END[];
19030 +#endif
19031 +#include <asm/boot.h>
19032 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
19033 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
19034 +#else
19035 +#define ktla_ktva(addr) (addr)
19036 +#define ktva_ktla(addr) (addr)
19037 +#endif
19038 +
19039 #define MODULES_VADDR VMALLOC_START
19040 #define MODULES_END VMALLOC_END
19041 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
19042 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
19043 index 3874693..d7906ac 100644
19044 --- a/arch/x86/include/asm/pgtable_64.h
19045 +++ b/arch/x86/include/asm/pgtable_64.h
19046 @@ -16,11 +16,16 @@
19047
19048 extern pud_t level3_kernel_pgt[512];
19049 extern pud_t level3_ident_pgt[512];
19050 +extern pud_t level3_vmalloc_start_pgt[512];
19051 +extern pud_t level3_vmalloc_end_pgt[512];
19052 +extern pud_t level3_vmemmap_pgt[512];
19053 +extern pud_t level2_vmemmap_pgt[512];
19054 extern pmd_t level2_kernel_pgt[512];
19055 extern pmd_t level2_fixmap_pgt[512];
19056 -extern pmd_t level2_ident_pgt[512];
19057 +extern pmd_t level2_ident_pgt[512*2];
19058 extern pte_t level1_fixmap_pgt[512];
19059 -extern pgd_t init_level4_pgt[];
19060 +extern pte_t level1_vsyscall_pgt[512];
19061 +extern pgd_t init_level4_pgt[512];
19062
19063 #define swapper_pg_dir init_level4_pgt
19064
19065 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
19066
19067 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
19068 {
19069 + pax_open_kernel();
19070 *pmdp = pmd;
19071 + pax_close_kernel();
19072 }
19073
19074 static inline void native_pmd_clear(pmd_t *pmd)
19075 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
19076
19077 static inline void native_set_pud(pud_t *pudp, pud_t pud)
19078 {
19079 + pax_open_kernel();
19080 *pudp = pud;
19081 + pax_close_kernel();
19082 }
19083
19084 static inline void native_pud_clear(pud_t *pud)
19085 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
19086
19087 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
19088 {
19089 + pax_open_kernel();
19090 + *pgdp = pgd;
19091 + pax_close_kernel();
19092 +}
19093 +
19094 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
19095 +{
19096 *pgdp = pgd;
19097 }
19098
19099 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
19100 index 7166e25..baaa6fe 100644
19101 --- a/arch/x86/include/asm/pgtable_64_types.h
19102 +++ b/arch/x86/include/asm/pgtable_64_types.h
19103 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
19104 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
19105 #define MODULES_END _AC(0xffffffffff000000, UL)
19106 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
19107 +#define MODULES_EXEC_VADDR MODULES_VADDR
19108 +#define MODULES_EXEC_END MODULES_END
19109 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
19110 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
19111
19112 +#define ktla_ktva(addr) (addr)
19113 +#define ktva_ktla(addr) (addr)
19114 +
19115 #define EARLY_DYNAMIC_PAGE_TABLES 64
19116
19117 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
19118 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
19119 index f216963..6bd7c21 100644
19120 --- a/arch/x86/include/asm/pgtable_types.h
19121 +++ b/arch/x86/include/asm/pgtable_types.h
19122 @@ -111,8 +111,10 @@
19123
19124 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19125 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
19126 -#else
19127 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
19128 #define _PAGE_NX (_AT(pteval_t, 0))
19129 +#else
19130 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
19131 #endif
19132
19133 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
19134 @@ -151,6 +153,9 @@
19135 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
19136 _PAGE_ACCESSED)
19137
19138 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
19139 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
19140 +
19141 #define __PAGE_KERNEL_EXEC \
19142 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
19143 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
19144 @@ -161,7 +166,7 @@
19145 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
19146 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
19147 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
19148 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
19149 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
19150 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
19151 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
19152 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
19153 @@ -218,7 +223,7 @@
19154 #ifdef CONFIG_X86_64
19155 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
19156 #else
19157 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
19158 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19159 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19160 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
19161 #endif
19162 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
19163 {
19164 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
19165 }
19166 +#endif
19167
19168 +#if PAGETABLE_LEVELS == 3
19169 +#include <asm-generic/pgtable-nopud.h>
19170 +#endif
19171 +
19172 +#if PAGETABLE_LEVELS == 2
19173 +#include <asm-generic/pgtable-nopmd.h>
19174 +#endif
19175 +
19176 +#ifndef __ASSEMBLY__
19177 #if PAGETABLE_LEVELS > 3
19178 typedef struct { pudval_t pud; } pud_t;
19179
19180 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
19181 return pud.pud;
19182 }
19183 #else
19184 -#include <asm-generic/pgtable-nopud.h>
19185 -
19186 static inline pudval_t native_pud_val(pud_t pud)
19187 {
19188 return native_pgd_val(pud.pgd);
19189 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
19190 return pmd.pmd;
19191 }
19192 #else
19193 -#include <asm-generic/pgtable-nopmd.h>
19194 -
19195 static inline pmdval_t native_pmd_val(pmd_t pmd)
19196 {
19197 return native_pgd_val(pmd.pud.pgd);
19198 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
19199
19200 extern pteval_t __supported_pte_mask;
19201 extern void set_nx(void);
19202 -extern int nx_enabled;
19203
19204 #define pgprot_writecombine pgprot_writecombine
19205 extern pgprot_t pgprot_writecombine(pgprot_t prot);
19206 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
19207 index 7024c12..71c46b9 100644
19208 --- a/arch/x86/include/asm/preempt.h
19209 +++ b/arch/x86/include/asm/preempt.h
19210 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
19211 */
19212 static __always_inline bool __preempt_count_dec_and_test(void)
19213 {
19214 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
19215 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
19216 }
19217
19218 /*
19219 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
19220 index eb71ec7..f06532a 100644
19221 --- a/arch/x86/include/asm/processor.h
19222 +++ b/arch/x86/include/asm/processor.h
19223 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
19224 /* Index into per_cpu list: */
19225 u16 cpu_index;
19226 u32 microcode;
19227 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
19228 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
19229
19230 #define X86_VENDOR_INTEL 0
19231 #define X86_VENDOR_CYRIX 1
19232 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
19233 : "memory");
19234 }
19235
19236 +/* invpcid (%rdx),%rax */
19237 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
19238 +
19239 +#define INVPCID_SINGLE_ADDRESS 0UL
19240 +#define INVPCID_SINGLE_CONTEXT 1UL
19241 +#define INVPCID_ALL_GLOBAL 2UL
19242 +#define INVPCID_ALL_NONGLOBAL 3UL
19243 +
19244 +#define PCID_KERNEL 0UL
19245 +#define PCID_USER 1UL
19246 +#define PCID_NOFLUSH (1UL << 63)
19247 +
19248 static inline void load_cr3(pgd_t *pgdir)
19249 {
19250 - write_cr3(__pa(pgdir));
19251 + write_cr3(__pa(pgdir) | PCID_KERNEL);
19252 }
19253
19254 #ifdef CONFIG_X86_32
19255 @@ -282,7 +294,7 @@ struct tss_struct {
19256
19257 } ____cacheline_aligned;
19258
19259 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
19260 +extern struct tss_struct init_tss[NR_CPUS];
19261
19262 /*
19263 * Save the original ist values for checking stack pointers during debugging
19264 @@ -478,6 +490,7 @@ struct thread_struct {
19265 unsigned short ds;
19266 unsigned short fsindex;
19267 unsigned short gsindex;
19268 + unsigned short ss;
19269 #endif
19270 #ifdef CONFIG_X86_32
19271 unsigned long ip;
19272 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
19273 extern unsigned long mmu_cr4_features;
19274 extern u32 *trampoline_cr4_features;
19275
19276 -static inline void set_in_cr4(unsigned long mask)
19277 -{
19278 - unsigned long cr4;
19279 -
19280 - mmu_cr4_features |= mask;
19281 - if (trampoline_cr4_features)
19282 - *trampoline_cr4_features = mmu_cr4_features;
19283 - cr4 = read_cr4();
19284 - cr4 |= mask;
19285 - write_cr4(cr4);
19286 -}
19287 -
19288 -static inline void clear_in_cr4(unsigned long mask)
19289 -{
19290 - unsigned long cr4;
19291 -
19292 - mmu_cr4_features &= ~mask;
19293 - if (trampoline_cr4_features)
19294 - *trampoline_cr4_features = mmu_cr4_features;
19295 - cr4 = read_cr4();
19296 - cr4 &= ~mask;
19297 - write_cr4(cr4);
19298 -}
19299 +extern void set_in_cr4(unsigned long mask);
19300 +extern void clear_in_cr4(unsigned long mask);
19301
19302 typedef struct {
19303 unsigned long seg;
19304 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
19305 */
19306 #define TASK_SIZE PAGE_OFFSET
19307 #define TASK_SIZE_MAX TASK_SIZE
19308 +
19309 +#ifdef CONFIG_PAX_SEGMEXEC
19310 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
19311 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
19312 +#else
19313 #define STACK_TOP TASK_SIZE
19314 -#define STACK_TOP_MAX STACK_TOP
19315 +#endif
19316 +
19317 +#define STACK_TOP_MAX TASK_SIZE
19318
19319 #define INIT_THREAD { \
19320 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19321 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19322 .vm86_info = NULL, \
19323 .sysenter_cs = __KERNEL_CS, \
19324 .io_bitmap_ptr = NULL, \
19325 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
19326 */
19327 #define INIT_TSS { \
19328 .x86_tss = { \
19329 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19330 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19331 .ss0 = __KERNEL_DS, \
19332 .ss1 = __KERNEL_CS, \
19333 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
19334 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
19335 extern unsigned long thread_saved_pc(struct task_struct *tsk);
19336
19337 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
19338 -#define KSTK_TOP(info) \
19339 -({ \
19340 - unsigned long *__ptr = (unsigned long *)(info); \
19341 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
19342 -})
19343 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
19344
19345 /*
19346 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
19347 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19348 #define task_pt_regs(task) \
19349 ({ \
19350 struct pt_regs *__regs__; \
19351 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
19352 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
19353 __regs__ - 1; \
19354 })
19355
19356 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19357 /*
19358 * User space process size. 47bits minus one guard page.
19359 */
19360 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
19361 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
19362
19363 /* This decides where the kernel will search for a free chunk of vm
19364 * space during mmap's.
19365 */
19366 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
19367 - 0xc0000000 : 0xFFFFe000)
19368 + 0xc0000000 : 0xFFFFf000)
19369
19370 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
19371 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
19372 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19373 #define STACK_TOP_MAX TASK_SIZE_MAX
19374
19375 #define INIT_THREAD { \
19376 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19377 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19378 }
19379
19380 #define INIT_TSS { \
19381 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19382 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19383 }
19384
19385 /*
19386 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
19387 */
19388 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
19389
19390 +#ifdef CONFIG_PAX_SEGMEXEC
19391 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
19392 +#endif
19393 +
19394 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
19395
19396 /* Get/set a process' ability to use the timestamp counter instruction */
19397 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
19398 return 0;
19399 }
19400
19401 -extern unsigned long arch_align_stack(unsigned long sp);
19402 +#define arch_align_stack(x) ((x) & ~0xfUL)
19403 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
19404
19405 void default_idle(void);
19406 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
19407 #define xen_set_default_idle 0
19408 #endif
19409
19410 -void stop_this_cpu(void *dummy);
19411 +void stop_this_cpu(void *dummy) __noreturn;
19412 void df_debug(struct pt_regs *regs, long error_code);
19413 #endif /* _ASM_X86_PROCESSOR_H */
19414 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
19415 index 6205f0c..688a3a9 100644
19416 --- a/arch/x86/include/asm/ptrace.h
19417 +++ b/arch/x86/include/asm/ptrace.h
19418 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
19419 }
19420
19421 /*
19422 - * user_mode_vm(regs) determines whether a register set came from user mode.
19423 + * user_mode(regs) determines whether a register set came from user mode.
19424 * This is true if V8086 mode was enabled OR if the register set was from
19425 * protected mode with RPL-3 CS value. This tricky test checks that with
19426 * one comparison. Many places in the kernel can bypass this full check
19427 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
19428 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
19429 + * be used.
19430 */
19431 -static inline int user_mode(struct pt_regs *regs)
19432 +static inline int user_mode_novm(struct pt_regs *regs)
19433 {
19434 #ifdef CONFIG_X86_32
19435 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
19436 #else
19437 - return !!(regs->cs & 3);
19438 + return !!(regs->cs & SEGMENT_RPL_MASK);
19439 #endif
19440 }
19441
19442 -static inline int user_mode_vm(struct pt_regs *regs)
19443 +static inline int user_mode(struct pt_regs *regs)
19444 {
19445 #ifdef CONFIG_X86_32
19446 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
19447 USER_RPL;
19448 #else
19449 - return user_mode(regs);
19450 + return user_mode_novm(regs);
19451 #endif
19452 }
19453
19454 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
19455 #ifdef CONFIG_X86_64
19456 static inline bool user_64bit_mode(struct pt_regs *regs)
19457 {
19458 + unsigned long cs = regs->cs & 0xffff;
19459 #ifndef CONFIG_PARAVIRT
19460 /*
19461 * On non-paravirt systems, this is the only long mode CPL 3
19462 * selector. We do not allow long mode selectors in the LDT.
19463 */
19464 - return regs->cs == __USER_CS;
19465 + return cs == __USER_CS;
19466 #else
19467 /* Headers are too twisted for this to go in paravirt.h. */
19468 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
19469 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
19470 #endif
19471 }
19472
19473 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
19474 * Traps from the kernel do not save sp and ss.
19475 * Use the helper function to retrieve sp.
19476 */
19477 - if (offset == offsetof(struct pt_regs, sp) &&
19478 - regs->cs == __KERNEL_CS)
19479 - return kernel_stack_pointer(regs);
19480 + if (offset == offsetof(struct pt_regs, sp)) {
19481 + unsigned long cs = regs->cs & 0xffff;
19482 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
19483 + return kernel_stack_pointer(regs);
19484 + }
19485 #endif
19486 return *(unsigned long *)((unsigned long)regs + offset);
19487 }
19488 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
19489 index ae0e241..e80b10b 100644
19490 --- a/arch/x86/include/asm/qrwlock.h
19491 +++ b/arch/x86/include/asm/qrwlock.h
19492 @@ -7,8 +7,8 @@
19493 #define queue_write_unlock queue_write_unlock
19494 static inline void queue_write_unlock(struct qrwlock *lock)
19495 {
19496 - barrier();
19497 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
19498 + barrier();
19499 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
19500 }
19501 #endif
19502
19503 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
19504 index 9c6b890..5305f53 100644
19505 --- a/arch/x86/include/asm/realmode.h
19506 +++ b/arch/x86/include/asm/realmode.h
19507 @@ -22,16 +22,14 @@ struct real_mode_header {
19508 #endif
19509 /* APM/BIOS reboot */
19510 u32 machine_real_restart_asm;
19511 -#ifdef CONFIG_X86_64
19512 u32 machine_real_restart_seg;
19513 -#endif
19514 };
19515
19516 /* This must match data at trampoline_32/64.S */
19517 struct trampoline_header {
19518 #ifdef CONFIG_X86_32
19519 u32 start;
19520 - u16 gdt_pad;
19521 + u16 boot_cs;
19522 u16 gdt_limit;
19523 u32 gdt_base;
19524 #else
19525 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
19526 index a82c4f1..ac45053 100644
19527 --- a/arch/x86/include/asm/reboot.h
19528 +++ b/arch/x86/include/asm/reboot.h
19529 @@ -6,13 +6,13 @@
19530 struct pt_regs;
19531
19532 struct machine_ops {
19533 - void (*restart)(char *cmd);
19534 - void (*halt)(void);
19535 - void (*power_off)(void);
19536 + void (* __noreturn restart)(char *cmd);
19537 + void (* __noreturn halt)(void);
19538 + void (* __noreturn power_off)(void);
19539 void (*shutdown)(void);
19540 void (*crash_shutdown)(struct pt_regs *);
19541 - void (*emergency_restart)(void);
19542 -};
19543 + void (* __noreturn emergency_restart)(void);
19544 +} __no_const;
19545
19546 extern struct machine_ops machine_ops;
19547
19548 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19549 index 8f7866a..e442f20 100644
19550 --- a/arch/x86/include/asm/rmwcc.h
19551 +++ b/arch/x86/include/asm/rmwcc.h
19552 @@ -3,7 +3,34 @@
19553
19554 #ifdef CC_HAVE_ASM_GOTO
19555
19556 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19557 +#ifdef CONFIG_PAX_REFCOUNT
19558 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19559 +do { \
19560 + asm_volatile_goto (fullop \
19561 + ";jno 0f\n" \
19562 + fullantiop \
19563 + ";int $4\n0:\n" \
19564 + _ASM_EXTABLE(0b, 0b) \
19565 + ";j" cc " %l[cc_label]" \
19566 + : : "m" (var), ## __VA_ARGS__ \
19567 + : "memory" : cc_label); \
19568 + return 0; \
19569 +cc_label: \
19570 + return 1; \
19571 +} while (0)
19572 +#else
19573 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19574 +do { \
19575 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19576 + : : "m" (var), ## __VA_ARGS__ \
19577 + : "memory" : cc_label); \
19578 + return 0; \
19579 +cc_label: \
19580 + return 1; \
19581 +} while (0)
19582 +#endif
19583 +
19584 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19585 do { \
19586 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19587 : : "m" (var), ## __VA_ARGS__ \
19588 @@ -13,15 +40,46 @@ cc_label: \
19589 return 1; \
19590 } while (0)
19591
19592 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19593 - __GEN_RMWcc(op " " arg0, var, cc)
19594 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19595 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19596
19597 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19598 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19599 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19600 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19601 +
19602 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19603 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19604 +
19605 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19606 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19607
19608 #else /* !CC_HAVE_ASM_GOTO */
19609
19610 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19611 +#ifdef CONFIG_PAX_REFCOUNT
19612 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19613 +do { \
19614 + char c; \
19615 + asm volatile (fullop \
19616 + ";jno 0f\n" \
19617 + fullantiop \
19618 + ";int $4\n0:\n" \
19619 + _ASM_EXTABLE(0b, 0b) \
19620 + "; set" cc " %1" \
19621 + : "+m" (var), "=qm" (c) \
19622 + : __VA_ARGS__ : "memory"); \
19623 + return c != 0; \
19624 +} while (0)
19625 +#else
19626 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19627 +do { \
19628 + char c; \
19629 + asm volatile (fullop "; set" cc " %1" \
19630 + : "+m" (var), "=qm" (c) \
19631 + : __VA_ARGS__ : "memory"); \
19632 + return c != 0; \
19633 +} while (0)
19634 +#endif
19635 +
19636 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19637 do { \
19638 char c; \
19639 asm volatile (fullop "; set" cc " %1" \
19640 @@ -30,11 +88,17 @@ do { \
19641 return c != 0; \
19642 } while (0)
19643
19644 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19645 - __GEN_RMWcc(op " " arg0, var, cc)
19646 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19647 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19648 +
19649 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19650 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19651 +
19652 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19653 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19654
19655 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19656 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19657 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19658 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19659
19660 #endif /* CC_HAVE_ASM_GOTO */
19661
19662 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19663 index cad82c9..2e5c5c1 100644
19664 --- a/arch/x86/include/asm/rwsem.h
19665 +++ b/arch/x86/include/asm/rwsem.h
19666 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19667 {
19668 asm volatile("# beginning down_read\n\t"
19669 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19670 +
19671 +#ifdef CONFIG_PAX_REFCOUNT
19672 + "jno 0f\n"
19673 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19674 + "int $4\n0:\n"
19675 + _ASM_EXTABLE(0b, 0b)
19676 +#endif
19677 +
19678 /* adds 0x00000001 */
19679 " jns 1f\n"
19680 " call call_rwsem_down_read_failed\n"
19681 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19682 "1:\n\t"
19683 " mov %1,%2\n\t"
19684 " add %3,%2\n\t"
19685 +
19686 +#ifdef CONFIG_PAX_REFCOUNT
19687 + "jno 0f\n"
19688 + "sub %3,%2\n"
19689 + "int $4\n0:\n"
19690 + _ASM_EXTABLE(0b, 0b)
19691 +#endif
19692 +
19693 " jle 2f\n\t"
19694 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19695 " jnz 1b\n\t"
19696 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19697 long tmp;
19698 asm volatile("# beginning down_write\n\t"
19699 LOCK_PREFIX " xadd %1,(%2)\n\t"
19700 +
19701 +#ifdef CONFIG_PAX_REFCOUNT
19702 + "jno 0f\n"
19703 + "mov %1,(%2)\n"
19704 + "int $4\n0:\n"
19705 + _ASM_EXTABLE(0b, 0b)
19706 +#endif
19707 +
19708 /* adds 0xffff0001, returns the old value */
19709 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19710 /* was the active mask 0 before? */
19711 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19712 long tmp;
19713 asm volatile("# beginning __up_read\n\t"
19714 LOCK_PREFIX " xadd %1,(%2)\n\t"
19715 +
19716 +#ifdef CONFIG_PAX_REFCOUNT
19717 + "jno 0f\n"
19718 + "mov %1,(%2)\n"
19719 + "int $4\n0:\n"
19720 + _ASM_EXTABLE(0b, 0b)
19721 +#endif
19722 +
19723 /* subtracts 1, returns the old value */
19724 " jns 1f\n\t"
19725 " call call_rwsem_wake\n" /* expects old value in %edx */
19726 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19727 long tmp;
19728 asm volatile("# beginning __up_write\n\t"
19729 LOCK_PREFIX " xadd %1,(%2)\n\t"
19730 +
19731 +#ifdef CONFIG_PAX_REFCOUNT
19732 + "jno 0f\n"
19733 + "mov %1,(%2)\n"
19734 + "int $4\n0:\n"
19735 + _ASM_EXTABLE(0b, 0b)
19736 +#endif
19737 +
19738 /* subtracts 0xffff0001, returns the old value */
19739 " jns 1f\n\t"
19740 " call call_rwsem_wake\n" /* expects old value in %edx */
19741 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19742 {
19743 asm volatile("# beginning __downgrade_write\n\t"
19744 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19745 +
19746 +#ifdef CONFIG_PAX_REFCOUNT
19747 + "jno 0f\n"
19748 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19749 + "int $4\n0:\n"
19750 + _ASM_EXTABLE(0b, 0b)
19751 +#endif
19752 +
19753 /*
19754 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19755 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19756 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19757 */
19758 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19759 {
19760 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19761 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19762 +
19763 +#ifdef CONFIG_PAX_REFCOUNT
19764 + "jno 0f\n"
19765 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19766 + "int $4\n0:\n"
19767 + _ASM_EXTABLE(0b, 0b)
19768 +#endif
19769 +
19770 : "+m" (sem->count)
19771 : "er" (delta));
19772 }
19773 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19774 */
19775 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19776 {
19777 - return delta + xadd(&sem->count, delta);
19778 + return delta + xadd_check_overflow(&sem->count, delta);
19779 }
19780
19781 #endif /* __KERNEL__ */
19782 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19783 index 6f1c3a8..7744f19 100644
19784 --- a/arch/x86/include/asm/segment.h
19785 +++ b/arch/x86/include/asm/segment.h
19786 @@ -64,10 +64,15 @@
19787 * 26 - ESPFIX small SS
19788 * 27 - per-cpu [ offset to per-cpu data area ]
19789 * 28 - stack_canary-20 [ for stack protector ]
19790 - * 29 - unused
19791 - * 30 - unused
19792 + * 29 - PCI BIOS CS
19793 + * 30 - PCI BIOS DS
19794 * 31 - TSS for double fault handler
19795 */
19796 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19797 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19798 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19799 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19800 +
19801 #define GDT_ENTRY_TLS_MIN 6
19802 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19803
19804 @@ -79,6 +84,8 @@
19805
19806 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19807
19808 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19809 +
19810 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19811
19812 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19813 @@ -104,6 +111,12 @@
19814 #define __KERNEL_STACK_CANARY 0
19815 #endif
19816
19817 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19818 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19819 +
19820 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19821 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19822 +
19823 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19824
19825 /*
19826 @@ -141,7 +154,7 @@
19827 */
19828
19829 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19830 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19831 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19832
19833
19834 #else
19835 @@ -165,6 +178,8 @@
19836 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19837 #define __USER32_DS __USER_DS
19838
19839 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19840 +
19841 #define GDT_ENTRY_TSS 8 /* needs two entries */
19842 #define GDT_ENTRY_LDT 10 /* needs two entries */
19843 #define GDT_ENTRY_TLS_MIN 12
19844 @@ -173,6 +188,8 @@
19845 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19846 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19847
19848 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19849 +
19850 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19851 #define FS_TLS 0
19852 #define GS_TLS 1
19853 @@ -180,12 +197,14 @@
19854 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19855 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19856
19857 -#define GDT_ENTRIES 16
19858 +#define GDT_ENTRIES 17
19859
19860 #endif
19861
19862 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19863 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19864 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19865 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19866 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19867 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19868 #ifndef CONFIG_PARAVIRT
19869 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19870 {
19871 unsigned long __limit;
19872 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19873 - return __limit + 1;
19874 + return __limit;
19875 }
19876
19877 #endif /* !__ASSEMBLY__ */
19878 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19879 index 8d3120f..352b440 100644
19880 --- a/arch/x86/include/asm/smap.h
19881 +++ b/arch/x86/include/asm/smap.h
19882 @@ -25,11 +25,40 @@
19883
19884 #include <asm/alternative-asm.h>
19885
19886 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19887 +#define ASM_PAX_OPEN_USERLAND \
19888 + 661: jmp 663f; \
19889 + .pushsection .altinstr_replacement, "a" ; \
19890 + 662: pushq %rax; nop; \
19891 + .popsection ; \
19892 + .pushsection .altinstructions, "a" ; \
19893 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19894 + .popsection ; \
19895 + call __pax_open_userland; \
19896 + popq %rax; \
19897 + 663:
19898 +
19899 +#define ASM_PAX_CLOSE_USERLAND \
19900 + 661: jmp 663f; \
19901 + .pushsection .altinstr_replacement, "a" ; \
19902 + 662: pushq %rax; nop; \
19903 + .popsection; \
19904 + .pushsection .altinstructions, "a" ; \
19905 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19906 + .popsection; \
19907 + call __pax_close_userland; \
19908 + popq %rax; \
19909 + 663:
19910 +#else
19911 +#define ASM_PAX_OPEN_USERLAND
19912 +#define ASM_PAX_CLOSE_USERLAND
19913 +#endif
19914 +
19915 #ifdef CONFIG_X86_SMAP
19916
19917 #define ASM_CLAC \
19918 661: ASM_NOP3 ; \
19919 - .pushsection .altinstr_replacement, "ax" ; \
19920 + .pushsection .altinstr_replacement, "a" ; \
19921 662: __ASM_CLAC ; \
19922 .popsection ; \
19923 .pushsection .altinstructions, "a" ; \
19924 @@ -38,7 +67,7 @@
19925
19926 #define ASM_STAC \
19927 661: ASM_NOP3 ; \
19928 - .pushsection .altinstr_replacement, "ax" ; \
19929 + .pushsection .altinstr_replacement, "a" ; \
19930 662: __ASM_STAC ; \
19931 .popsection ; \
19932 .pushsection .altinstructions, "a" ; \
19933 @@ -56,6 +85,37 @@
19934
19935 #include <asm/alternative.h>
19936
19937 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19938 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19939 +
19940 +extern void __pax_open_userland(void);
19941 +static __always_inline unsigned long pax_open_userland(void)
19942 +{
19943 +
19944 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19945 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19946 + :
19947 + : [open] "i" (__pax_open_userland)
19948 + : "memory", "rax");
19949 +#endif
19950 +
19951 + return 0;
19952 +}
19953 +
19954 +extern void __pax_close_userland(void);
19955 +static __always_inline unsigned long pax_close_userland(void)
19956 +{
19957 +
19958 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19959 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19960 + :
19961 + : [close] "i" (__pax_close_userland)
19962 + : "memory", "rax");
19963 +#endif
19964 +
19965 + return 0;
19966 +}
19967 +
19968 #ifdef CONFIG_X86_SMAP
19969
19970 static __always_inline void clac(void)
19971 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19972 index 8cd27e0..7f05ec8 100644
19973 --- a/arch/x86/include/asm/smp.h
19974 +++ b/arch/x86/include/asm/smp.h
19975 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19976 /* cpus sharing the last level cache: */
19977 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19978 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19979 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19980 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19981
19982 static inline struct cpumask *cpu_sibling_mask(int cpu)
19983 {
19984 @@ -78,7 +78,7 @@ struct smp_ops {
19985
19986 void (*send_call_func_ipi)(const struct cpumask *mask);
19987 void (*send_call_func_single_ipi)(int cpu);
19988 -};
19989 +} __no_const;
19990
19991 /* Globals due to paravirt */
19992 extern void set_cpu_sibling_map(int cpu);
19993 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19994 extern int safe_smp_processor_id(void);
19995
19996 #elif defined(CONFIG_X86_64_SMP)
19997 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19998 -
19999 -#define stack_smp_processor_id() \
20000 -({ \
20001 - struct thread_info *ti; \
20002 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
20003 - ti->cpu; \
20004 -})
20005 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
20006 +#define stack_smp_processor_id() raw_smp_processor_id()
20007 #define safe_smp_processor_id() smp_processor_id()
20008
20009 #endif
20010 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
20011 index 54f1c80..39362a5 100644
20012 --- a/arch/x86/include/asm/spinlock.h
20013 +++ b/arch/x86/include/asm/spinlock.h
20014 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
20015 static inline void arch_read_lock(arch_rwlock_t *rw)
20016 {
20017 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
20018 +
20019 +#ifdef CONFIG_PAX_REFCOUNT
20020 + "jno 0f\n"
20021 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
20022 + "int $4\n0:\n"
20023 + _ASM_EXTABLE(0b, 0b)
20024 +#endif
20025 +
20026 "jns 1f\n"
20027 "call __read_lock_failed\n\t"
20028 "1:\n"
20029 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
20030 static inline void arch_write_lock(arch_rwlock_t *rw)
20031 {
20032 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
20033 +
20034 +#ifdef CONFIG_PAX_REFCOUNT
20035 + "jno 0f\n"
20036 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
20037 + "int $4\n0:\n"
20038 + _ASM_EXTABLE(0b, 0b)
20039 +#endif
20040 +
20041 "jz 1f\n"
20042 "call __write_lock_failed\n\t"
20043 "1:\n"
20044 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
20045
20046 static inline void arch_read_unlock(arch_rwlock_t *rw)
20047 {
20048 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
20049 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
20050 +
20051 +#ifdef CONFIG_PAX_REFCOUNT
20052 + "jno 0f\n"
20053 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
20054 + "int $4\n0:\n"
20055 + _ASM_EXTABLE(0b, 0b)
20056 +#endif
20057 +
20058 :"+m" (rw->lock) : : "memory");
20059 }
20060
20061 static inline void arch_write_unlock(arch_rwlock_t *rw)
20062 {
20063 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
20064 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
20065 +
20066 +#ifdef CONFIG_PAX_REFCOUNT
20067 + "jno 0f\n"
20068 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
20069 + "int $4\n0:\n"
20070 + _ASM_EXTABLE(0b, 0b)
20071 +#endif
20072 +
20073 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
20074 }
20075 #else
20076 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
20077 index 6a99859..03cb807 100644
20078 --- a/arch/x86/include/asm/stackprotector.h
20079 +++ b/arch/x86/include/asm/stackprotector.h
20080 @@ -47,7 +47,7 @@
20081 * head_32 for boot CPU and setup_per_cpu_areas() for others.
20082 */
20083 #define GDT_STACK_CANARY_INIT \
20084 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
20085 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
20086
20087 /*
20088 * Initialize the stackprotector canary value.
20089 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
20090
20091 static inline void load_stack_canary_segment(void)
20092 {
20093 -#ifdef CONFIG_X86_32
20094 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
20095 asm volatile ("mov %0, %%gs" : : "r" (0));
20096 #endif
20097 }
20098 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
20099 index 70bbe39..4ae2bd4 100644
20100 --- a/arch/x86/include/asm/stacktrace.h
20101 +++ b/arch/x86/include/asm/stacktrace.h
20102 @@ -11,28 +11,20 @@
20103
20104 extern int kstack_depth_to_print;
20105
20106 -struct thread_info;
20107 +struct task_struct;
20108 struct stacktrace_ops;
20109
20110 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
20111 - unsigned long *stack,
20112 - unsigned long bp,
20113 - const struct stacktrace_ops *ops,
20114 - void *data,
20115 - unsigned long *end,
20116 - int *graph);
20117 +typedef unsigned long walk_stack_t(struct task_struct *task,
20118 + void *stack_start,
20119 + unsigned long *stack,
20120 + unsigned long bp,
20121 + const struct stacktrace_ops *ops,
20122 + void *data,
20123 + unsigned long *end,
20124 + int *graph);
20125
20126 -extern unsigned long
20127 -print_context_stack(struct thread_info *tinfo,
20128 - unsigned long *stack, unsigned long bp,
20129 - const struct stacktrace_ops *ops, void *data,
20130 - unsigned long *end, int *graph);
20131 -
20132 -extern unsigned long
20133 -print_context_stack_bp(struct thread_info *tinfo,
20134 - unsigned long *stack, unsigned long bp,
20135 - const struct stacktrace_ops *ops, void *data,
20136 - unsigned long *end, int *graph);
20137 +extern walk_stack_t print_context_stack;
20138 +extern walk_stack_t print_context_stack_bp;
20139
20140 /* Generic stack tracer with callbacks */
20141
20142 @@ -40,7 +32,7 @@ struct stacktrace_ops {
20143 void (*address)(void *data, unsigned long address, int reliable);
20144 /* On negative return stop dumping */
20145 int (*stack)(void *data, char *name);
20146 - walk_stack_t walk_stack;
20147 + walk_stack_t *walk_stack;
20148 };
20149
20150 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
20151 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
20152 index d7f3b3b..3cc39f1 100644
20153 --- a/arch/x86/include/asm/switch_to.h
20154 +++ b/arch/x86/include/asm/switch_to.h
20155 @@ -108,7 +108,7 @@ do { \
20156 "call __switch_to\n\t" \
20157 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
20158 __switch_canary \
20159 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
20160 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
20161 "movq %%rax,%%rdi\n\t" \
20162 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
20163 "jnz ret_from_fork\n\t" \
20164 @@ -119,7 +119,7 @@ do { \
20165 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
20166 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
20167 [_tif_fork] "i" (_TIF_FORK), \
20168 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
20169 + [thread_info] "m" (current_tinfo), \
20170 [current_task] "m" (current_task) \
20171 __switch_canary_iparam \
20172 : "memory", "cc" __EXTRA_CLOBBER)
20173 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
20174 index 547e344..6be1175 100644
20175 --- a/arch/x86/include/asm/thread_info.h
20176 +++ b/arch/x86/include/asm/thread_info.h
20177 @@ -24,7 +24,6 @@ struct exec_domain;
20178 #include <linux/atomic.h>
20179
20180 struct thread_info {
20181 - struct task_struct *task; /* main task structure */
20182 struct exec_domain *exec_domain; /* execution domain */
20183 __u32 flags; /* low level flags */
20184 __u32 status; /* thread synchronous flags */
20185 @@ -33,13 +32,13 @@ struct thread_info {
20186 mm_segment_t addr_limit;
20187 struct restart_block restart_block;
20188 void __user *sysenter_return;
20189 + unsigned long lowest_stack;
20190 unsigned int sig_on_uaccess_error:1;
20191 unsigned int uaccess_err:1; /* uaccess failed */
20192 };
20193
20194 -#define INIT_THREAD_INFO(tsk) \
20195 +#define INIT_THREAD_INFO \
20196 { \
20197 - .task = &tsk, \
20198 .exec_domain = &default_exec_domain, \
20199 .flags = 0, \
20200 .cpu = 0, \
20201 @@ -50,7 +49,7 @@ struct thread_info {
20202 }, \
20203 }
20204
20205 -#define init_thread_info (init_thread_union.thread_info)
20206 +#define init_thread_info (init_thread_union.stack)
20207 #define init_stack (init_thread_union.stack)
20208
20209 #else /* !__ASSEMBLY__ */
20210 @@ -91,6 +90,7 @@ struct thread_info {
20211 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
20212 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
20213 #define TIF_X32 30 /* 32-bit native x86-64 binary */
20214 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
20215
20216 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
20217 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
20218 @@ -115,17 +115,18 @@ struct thread_info {
20219 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
20220 #define _TIF_ADDR32 (1 << TIF_ADDR32)
20221 #define _TIF_X32 (1 << TIF_X32)
20222 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
20223
20224 /* work to do in syscall_trace_enter() */
20225 #define _TIF_WORK_SYSCALL_ENTRY \
20226 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
20227 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
20228 - _TIF_NOHZ)
20229 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20230
20231 /* work to do in syscall_trace_leave() */
20232 #define _TIF_WORK_SYSCALL_EXIT \
20233 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
20234 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
20235 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
20236
20237 /* work to do on interrupt/exception return */
20238 #define _TIF_WORK_MASK \
20239 @@ -136,7 +137,7 @@ struct thread_info {
20240 /* work to do on any return to user space */
20241 #define _TIF_ALLWORK_MASK \
20242 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
20243 - _TIF_NOHZ)
20244 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20245
20246 /* Only used for 64 bit */
20247 #define _TIF_DO_NOTIFY_MASK \
20248 @@ -151,7 +152,6 @@ struct thread_info {
20249 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
20250
20251 #define STACK_WARN (THREAD_SIZE/8)
20252 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
20253
20254 /*
20255 * macros/functions for gaining access to the thread information structure
20256 @@ -162,26 +162,18 @@ struct thread_info {
20257
20258 DECLARE_PER_CPU(unsigned long, kernel_stack);
20259
20260 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
20261 +
20262 static inline struct thread_info *current_thread_info(void)
20263 {
20264 - struct thread_info *ti;
20265 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
20266 - KERNEL_STACK_OFFSET - THREAD_SIZE);
20267 - return ti;
20268 + return this_cpu_read_stable(current_tinfo);
20269 }
20270
20271 #else /* !__ASSEMBLY__ */
20272
20273 /* how to get the thread information struct from ASM */
20274 #define GET_THREAD_INFO(reg) \
20275 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
20276 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
20277 -
20278 -/*
20279 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
20280 - * a certain register (to be used in assembler memory operands).
20281 - */
20282 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
20283 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
20284
20285 #endif
20286
20287 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
20288 extern void arch_task_cache_init(void);
20289 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
20290 extern void arch_release_task_struct(struct task_struct *tsk);
20291 +
20292 +#define __HAVE_THREAD_FUNCTIONS
20293 +#define task_thread_info(task) (&(task)->tinfo)
20294 +#define task_stack_page(task) ((task)->stack)
20295 +#define setup_thread_stack(p, org) do {} while (0)
20296 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
20297 +
20298 #endif
20299 #endif /* _ASM_X86_THREAD_INFO_H */
20300 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
20301 index 04905bf..1178cdf 100644
20302 --- a/arch/x86/include/asm/tlbflush.h
20303 +++ b/arch/x86/include/asm/tlbflush.h
20304 @@ -17,18 +17,44 @@
20305
20306 static inline void __native_flush_tlb(void)
20307 {
20308 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20309 + u64 descriptor[2];
20310 +
20311 + descriptor[0] = PCID_KERNEL;
20312 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
20313 + return;
20314 + }
20315 +
20316 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20317 + if (static_cpu_has(X86_FEATURE_PCID)) {
20318 + unsigned int cpu = raw_get_cpu();
20319 +
20320 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
20321 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
20322 + raw_put_cpu_no_resched();
20323 + return;
20324 + }
20325 +#endif
20326 +
20327 native_write_cr3(native_read_cr3());
20328 }
20329
20330 static inline void __native_flush_tlb_global_irq_disabled(void)
20331 {
20332 - unsigned long cr4;
20333 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20334 + u64 descriptor[2];
20335
20336 - cr4 = native_read_cr4();
20337 - /* clear PGE */
20338 - native_write_cr4(cr4 & ~X86_CR4_PGE);
20339 - /* write old PGE again and flush TLBs */
20340 - native_write_cr4(cr4);
20341 + descriptor[0] = PCID_KERNEL;
20342 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
20343 + } else {
20344 + unsigned long cr4;
20345 +
20346 + cr4 = native_read_cr4();
20347 + /* clear PGE */
20348 + native_write_cr4(cr4 & ~X86_CR4_PGE);
20349 + /* write old PGE again and flush TLBs */
20350 + native_write_cr4(cr4);
20351 + }
20352 }
20353
20354 static inline void __native_flush_tlb_global(void)
20355 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
20356
20357 static inline void __native_flush_tlb_single(unsigned long addr)
20358 {
20359 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20360 + u64 descriptor[2];
20361 +
20362 + descriptor[0] = PCID_KERNEL;
20363 + descriptor[1] = addr;
20364 +
20365 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20366 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
20367 + if (addr < TASK_SIZE_MAX)
20368 + descriptor[1] += pax_user_shadow_base;
20369 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20370 + }
20371 +
20372 + descriptor[0] = PCID_USER;
20373 + descriptor[1] = addr;
20374 +#endif
20375 +
20376 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20377 + return;
20378 + }
20379 +
20380 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20381 + if (static_cpu_has(X86_FEATURE_PCID)) {
20382 + unsigned int cpu = raw_get_cpu();
20383 +
20384 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
20385 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20386 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
20387 + raw_put_cpu_no_resched();
20388 +
20389 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
20390 + addr += pax_user_shadow_base;
20391 + }
20392 +#endif
20393 +
20394 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20395 }
20396
20397 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
20398 index 0d592e0..526f797 100644
20399 --- a/arch/x86/include/asm/uaccess.h
20400 +++ b/arch/x86/include/asm/uaccess.h
20401 @@ -7,6 +7,7 @@
20402 #include <linux/compiler.h>
20403 #include <linux/thread_info.h>
20404 #include <linux/string.h>
20405 +#include <linux/spinlock.h>
20406 #include <asm/asm.h>
20407 #include <asm/page.h>
20408 #include <asm/smap.h>
20409 @@ -29,7 +30,12 @@
20410
20411 #define get_ds() (KERNEL_DS)
20412 #define get_fs() (current_thread_info()->addr_limit)
20413 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20414 +void __set_fs(mm_segment_t x);
20415 +void set_fs(mm_segment_t x);
20416 +#else
20417 #define set_fs(x) (current_thread_info()->addr_limit = (x))
20418 +#endif
20419
20420 #define segment_eq(a, b) ((a).seg == (b).seg)
20421
20422 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
20423 * checks that the pointer is in the user space range - after calling
20424 * this function, memory access functions may still return -EFAULT.
20425 */
20426 -#define access_ok(type, addr, size) \
20427 - likely(!__range_not_ok(addr, size, user_addr_max()))
20428 +extern int _cond_resched(void);
20429 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
20430 +#define access_ok(type, addr, size) \
20431 +({ \
20432 + unsigned long __size = size; \
20433 + unsigned long __addr = (unsigned long)addr; \
20434 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
20435 + if (__ret_ao && __size) { \
20436 + unsigned long __addr_ao = __addr & PAGE_MASK; \
20437 + unsigned long __end_ao = __addr + __size - 1; \
20438 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
20439 + while (__addr_ao <= __end_ao) { \
20440 + char __c_ao; \
20441 + __addr_ao += PAGE_SIZE; \
20442 + if (__size > PAGE_SIZE) \
20443 + _cond_resched(); \
20444 + if (__get_user(__c_ao, (char __user *)__addr)) \
20445 + break; \
20446 + if (type != VERIFY_WRITE) { \
20447 + __addr = __addr_ao; \
20448 + continue; \
20449 + } \
20450 + if (__put_user(__c_ao, (char __user *)__addr)) \
20451 + break; \
20452 + __addr = __addr_ao; \
20453 + } \
20454 + } \
20455 + } \
20456 + __ret_ao; \
20457 +})
20458
20459 /*
20460 * The exception table consists of pairs of addresses relative to the
20461 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20462 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
20463 __chk_user_ptr(ptr); \
20464 might_fault(); \
20465 + pax_open_userland(); \
20466 asm volatile("call __get_user_%P3" \
20467 : "=a" (__ret_gu), "=r" (__val_gu) \
20468 : "0" (ptr), "i" (sizeof(*(ptr)))); \
20469 (x) = (__typeof__(*(ptr))) __val_gu; \
20470 + pax_close_userland(); \
20471 __ret_gu; \
20472 })
20473
20474 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20475 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
20476 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
20477
20478 -
20479 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20480 +#define __copyuser_seg "gs;"
20481 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
20482 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
20483 +#else
20484 +#define __copyuser_seg
20485 +#define __COPYUSER_SET_ES
20486 +#define __COPYUSER_RESTORE_ES
20487 +#endif
20488
20489 #ifdef CONFIG_X86_32
20490 #define __put_user_asm_u64(x, addr, err, errret) \
20491 asm volatile(ASM_STAC "\n" \
20492 - "1: movl %%eax,0(%2)\n" \
20493 - "2: movl %%edx,4(%2)\n" \
20494 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
20495 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
20496 "3: " ASM_CLAC "\n" \
20497 ".section .fixup,\"ax\"\n" \
20498 "4: movl %3,%0\n" \
20499 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20500
20501 #define __put_user_asm_ex_u64(x, addr) \
20502 asm volatile(ASM_STAC "\n" \
20503 - "1: movl %%eax,0(%1)\n" \
20504 - "2: movl %%edx,4(%1)\n" \
20505 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
20506 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
20507 "3: " ASM_CLAC "\n" \
20508 _ASM_EXTABLE_EX(1b, 2b) \
20509 _ASM_EXTABLE_EX(2b, 3b) \
20510 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
20511 __typeof__(*(ptr)) __pu_val; \
20512 __chk_user_ptr(ptr); \
20513 might_fault(); \
20514 - __pu_val = x; \
20515 + __pu_val = (x); \
20516 + pax_open_userland(); \
20517 switch (sizeof(*(ptr))) { \
20518 case 1: \
20519 __put_user_x(1, __pu_val, ptr, __ret_pu); \
20520 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
20521 __put_user_x(X, __pu_val, ptr, __ret_pu); \
20522 break; \
20523 } \
20524 + pax_close_userland(); \
20525 __ret_pu; \
20526 })
20527
20528 @@ -355,8 +401,10 @@ do { \
20529 } while (0)
20530
20531 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20532 +do { \
20533 + pax_open_userland(); \
20534 asm volatile(ASM_STAC "\n" \
20535 - "1: mov"itype" %2,%"rtype"1\n" \
20536 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
20537 "2: " ASM_CLAC "\n" \
20538 ".section .fixup,\"ax\"\n" \
20539 "3: mov %3,%0\n" \
20540 @@ -364,8 +412,10 @@ do { \
20541 " jmp 2b\n" \
20542 ".previous\n" \
20543 _ASM_EXTABLE(1b, 3b) \
20544 - : "=r" (err), ltype(x) \
20545 - : "m" (__m(addr)), "i" (errret), "0" (err))
20546 + : "=r" (err), ltype (x) \
20547 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
20548 + pax_close_userland(); \
20549 +} while (0)
20550
20551 #define __get_user_size_ex(x, ptr, size) \
20552 do { \
20553 @@ -389,7 +439,7 @@ do { \
20554 } while (0)
20555
20556 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20557 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20558 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20559 "2:\n" \
20560 _ASM_EXTABLE_EX(1b, 2b) \
20561 : ltype(x) : "m" (__m(addr)))
20562 @@ -406,13 +456,24 @@ do { \
20563 int __gu_err; \
20564 unsigned long __gu_val; \
20565 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20566 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
20567 + (x) = (__typeof__(*(ptr)))__gu_val; \
20568 __gu_err; \
20569 })
20570
20571 /* FIXME: this hack is definitely wrong -AK */
20572 struct __large_struct { unsigned long buf[100]; };
20573 -#define __m(x) (*(struct __large_struct __user *)(x))
20574 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20575 +#define ____m(x) \
20576 +({ \
20577 + unsigned long ____x = (unsigned long)(x); \
20578 + if (____x < pax_user_shadow_base) \
20579 + ____x += pax_user_shadow_base; \
20580 + (typeof(x))____x; \
20581 +})
20582 +#else
20583 +#define ____m(x) (x)
20584 +#endif
20585 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20586
20587 /*
20588 * Tell gcc we read from memory instead of writing: this is because
20589 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20590 * aliasing issues.
20591 */
20592 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20593 +do { \
20594 + pax_open_userland(); \
20595 asm volatile(ASM_STAC "\n" \
20596 - "1: mov"itype" %"rtype"1,%2\n" \
20597 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20598 "2: " ASM_CLAC "\n" \
20599 ".section .fixup,\"ax\"\n" \
20600 "3: mov %3,%0\n" \
20601 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20602 ".previous\n" \
20603 _ASM_EXTABLE(1b, 3b) \
20604 : "=r"(err) \
20605 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20606 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20607 + pax_close_userland(); \
20608 +} while (0)
20609
20610 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20611 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20612 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20613 "2:\n" \
20614 _ASM_EXTABLE_EX(1b, 2b) \
20615 : : ltype(x), "m" (__m(addr)))
20616 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20617 */
20618 #define uaccess_try do { \
20619 current_thread_info()->uaccess_err = 0; \
20620 + pax_open_userland(); \
20621 stac(); \
20622 barrier();
20623
20624 #define uaccess_catch(err) \
20625 clac(); \
20626 + pax_close_userland(); \
20627 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20628 } while (0)
20629
20630 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20631 * On error, the variable @x is set to zero.
20632 */
20633
20634 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20635 +#define __get_user(x, ptr) get_user((x), (ptr))
20636 +#else
20637 #define __get_user(x, ptr) \
20638 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20639 +#endif
20640
20641 /**
20642 * __put_user: - Write a simple value into user space, with less checking.
20643 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20644 * Returns zero on success, or -EFAULT on error.
20645 */
20646
20647 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20648 +#define __put_user(x, ptr) put_user((x), (ptr))
20649 +#else
20650 #define __put_user(x, ptr) \
20651 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20652 +#endif
20653
20654 #define __get_user_unaligned __get_user
20655 #define __put_user_unaligned __put_user
20656 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20657 #define get_user_ex(x, ptr) do { \
20658 unsigned long __gue_val; \
20659 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20660 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20661 + (x) = (__typeof__(*(ptr)))__gue_val; \
20662 } while (0)
20663
20664 #define put_user_try uaccess_try
20665 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20666 __typeof__(ptr) __uval = (uval); \
20667 __typeof__(*(ptr)) __old = (old); \
20668 __typeof__(*(ptr)) __new = (new); \
20669 + pax_open_userland(); \
20670 switch (size) { \
20671 case 1: \
20672 { \
20673 asm volatile("\t" ASM_STAC "\n" \
20674 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20675 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20676 "2:\t" ASM_CLAC "\n" \
20677 "\t.section .fixup, \"ax\"\n" \
20678 "3:\tmov %3, %0\n" \
20679 "\tjmp 2b\n" \
20680 "\t.previous\n" \
20681 _ASM_EXTABLE(1b, 3b) \
20682 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20683 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20684 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20685 : "memory" \
20686 ); \
20687 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20688 case 2: \
20689 { \
20690 asm volatile("\t" ASM_STAC "\n" \
20691 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20692 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20693 "2:\t" ASM_CLAC "\n" \
20694 "\t.section .fixup, \"ax\"\n" \
20695 "3:\tmov %3, %0\n" \
20696 "\tjmp 2b\n" \
20697 "\t.previous\n" \
20698 _ASM_EXTABLE(1b, 3b) \
20699 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20700 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20701 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20702 : "memory" \
20703 ); \
20704 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20705 case 4: \
20706 { \
20707 asm volatile("\t" ASM_STAC "\n" \
20708 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20709 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20710 "2:\t" ASM_CLAC "\n" \
20711 "\t.section .fixup, \"ax\"\n" \
20712 "3:\tmov %3, %0\n" \
20713 "\tjmp 2b\n" \
20714 "\t.previous\n" \
20715 _ASM_EXTABLE(1b, 3b) \
20716 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20717 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20718 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20719 : "memory" \
20720 ); \
20721 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20722 __cmpxchg_wrong_size(); \
20723 \
20724 asm volatile("\t" ASM_STAC "\n" \
20725 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20726 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20727 "2:\t" ASM_CLAC "\n" \
20728 "\t.section .fixup, \"ax\"\n" \
20729 "3:\tmov %3, %0\n" \
20730 "\tjmp 2b\n" \
20731 "\t.previous\n" \
20732 _ASM_EXTABLE(1b, 3b) \
20733 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20734 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20735 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20736 : "memory" \
20737 ); \
20738 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20739 default: \
20740 __cmpxchg_wrong_size(); \
20741 } \
20742 + pax_close_userland(); \
20743 *__uval = __old; \
20744 __ret; \
20745 })
20746 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20747
20748 #define ARCH_HAS_NOCACHE_UACCESS 1
20749
20750 -#ifdef CONFIG_X86_32
20751 -# include <asm/uaccess_32.h>
20752 -#else
20753 -# include <asm/uaccess_64.h>
20754 -#endif
20755 -
20756 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20757 - unsigned n);
20758 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20759 - unsigned n);
20760 -
20761 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20762 # define copy_user_diag __compiletime_error
20763 #else
20764 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20765 extern void copy_user_diag("copy_from_user() buffer size is too small")
20766 copy_from_user_overflow(void);
20767 extern void copy_user_diag("copy_to_user() buffer size is too small")
20768 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20769 +copy_to_user_overflow(void);
20770
20771 #undef copy_user_diag
20772
20773 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20774
20775 extern void
20776 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20777 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20778 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20779 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20780
20781 #else
20782 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20783
20784 #endif
20785
20786 +#ifdef CONFIG_X86_32
20787 +# include <asm/uaccess_32.h>
20788 +#else
20789 +# include <asm/uaccess_64.h>
20790 +#endif
20791 +
20792 static inline unsigned long __must_check
20793 copy_from_user(void *to, const void __user *from, unsigned long n)
20794 {
20795 - int sz = __compiletime_object_size(to);
20796 + size_t sz = __compiletime_object_size(to);
20797
20798 might_fault();
20799
20800 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20801 * case, and do only runtime checking for non-constant sizes.
20802 */
20803
20804 - if (likely(sz < 0 || sz >= n))
20805 - n = _copy_from_user(to, from, n);
20806 - else if(__builtin_constant_p(n))
20807 - copy_from_user_overflow();
20808 - else
20809 - __copy_from_user_overflow(sz, n);
20810 + if (likely(sz != (size_t)-1 && sz < n)) {
20811 + if(__builtin_constant_p(n))
20812 + copy_from_user_overflow();
20813 + else
20814 + __copy_from_user_overflow(sz, n);
20815 + } else if (access_ok(VERIFY_READ, from, n))
20816 + n = __copy_from_user(to, from, n);
20817 + else if ((long)n > 0)
20818 + memset(to, 0, n);
20819
20820 return n;
20821 }
20822 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20823 static inline unsigned long __must_check
20824 copy_to_user(void __user *to, const void *from, unsigned long n)
20825 {
20826 - int sz = __compiletime_object_size(from);
20827 + size_t sz = __compiletime_object_size(from);
20828
20829 might_fault();
20830
20831 /* See the comment in copy_from_user() above. */
20832 - if (likely(sz < 0 || sz >= n))
20833 - n = _copy_to_user(to, from, n);
20834 - else if(__builtin_constant_p(n))
20835 - copy_to_user_overflow();
20836 - else
20837 - __copy_to_user_overflow(sz, n);
20838 + if (likely(sz != (size_t)-1 && sz < n)) {
20839 + if(__builtin_constant_p(n))
20840 + copy_to_user_overflow();
20841 + else
20842 + __copy_to_user_overflow(sz, n);
20843 + } else if (access_ok(VERIFY_WRITE, to, n))
20844 + n = __copy_to_user(to, from, n);
20845
20846 return n;
20847 }
20848 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20849 index 3c03a5d..1071638 100644
20850 --- a/arch/x86/include/asm/uaccess_32.h
20851 +++ b/arch/x86/include/asm/uaccess_32.h
20852 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20853 static __always_inline unsigned long __must_check
20854 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20855 {
20856 + if ((long)n < 0)
20857 + return n;
20858 +
20859 + check_object_size(from, n, true);
20860 +
20861 if (__builtin_constant_p(n)) {
20862 unsigned long ret;
20863
20864 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20865 __copy_to_user(void __user *to, const void *from, unsigned long n)
20866 {
20867 might_fault();
20868 +
20869 return __copy_to_user_inatomic(to, from, n);
20870 }
20871
20872 static __always_inline unsigned long
20873 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20874 {
20875 + if ((long)n < 0)
20876 + return n;
20877 +
20878 /* Avoid zeroing the tail if the copy fails..
20879 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20880 * but as the zeroing behaviour is only significant when n is not
20881 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20882 __copy_from_user(void *to, const void __user *from, unsigned long n)
20883 {
20884 might_fault();
20885 +
20886 + if ((long)n < 0)
20887 + return n;
20888 +
20889 + check_object_size(to, n, false);
20890 +
20891 if (__builtin_constant_p(n)) {
20892 unsigned long ret;
20893
20894 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20895 const void __user *from, unsigned long n)
20896 {
20897 might_fault();
20898 +
20899 + if ((long)n < 0)
20900 + return n;
20901 +
20902 if (__builtin_constant_p(n)) {
20903 unsigned long ret;
20904
20905 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20906 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20907 unsigned long n)
20908 {
20909 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20910 + if ((long)n < 0)
20911 + return n;
20912 +
20913 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20914 }
20915
20916 #endif /* _ASM_X86_UACCESS_32_H */
20917 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20918 index 12a26b9..206c200 100644
20919 --- a/arch/x86/include/asm/uaccess_64.h
20920 +++ b/arch/x86/include/asm/uaccess_64.h
20921 @@ -10,6 +10,9 @@
20922 #include <asm/alternative.h>
20923 #include <asm/cpufeature.h>
20924 #include <asm/page.h>
20925 +#include <asm/pgtable.h>
20926 +
20927 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20928
20929 /*
20930 * Copy To/From Userspace
20931 @@ -17,14 +20,14 @@
20932
20933 /* Handles exceptions in both to and from, but doesn't do access_ok */
20934 __must_check unsigned long
20935 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20936 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20937 __must_check unsigned long
20938 -copy_user_generic_string(void *to, const void *from, unsigned len);
20939 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20940 __must_check unsigned long
20941 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20942 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20943
20944 static __always_inline __must_check unsigned long
20945 -copy_user_generic(void *to, const void *from, unsigned len)
20946 +copy_user_generic(void *to, const void *from, unsigned long len)
20947 {
20948 unsigned ret;
20949
20950 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20951 }
20952
20953 __must_check unsigned long
20954 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20955 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20956
20957 static __always_inline __must_check
20958 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20959 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20960 {
20961 - int ret = 0;
20962 + size_t sz = __compiletime_object_size(dst);
20963 + unsigned ret = 0;
20964 +
20965 + if (size > INT_MAX)
20966 + return size;
20967 +
20968 + check_object_size(dst, size, false);
20969 +
20970 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20971 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20972 + return size;
20973 +#endif
20974 +
20975 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20976 + if(__builtin_constant_p(size))
20977 + copy_from_user_overflow();
20978 + else
20979 + __copy_from_user_overflow(sz, size);
20980 + return size;
20981 + }
20982
20983 if (!__builtin_constant_p(size))
20984 - return copy_user_generic(dst, (__force void *)src, size);
20985 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20986 switch (size) {
20987 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20988 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20989 ret, "b", "b", "=q", 1);
20990 return ret;
20991 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20992 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20993 ret, "w", "w", "=r", 2);
20994 return ret;
20995 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20996 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20997 ret, "l", "k", "=r", 4);
20998 return ret;
20999 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
21000 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21001 ret, "q", "", "=r", 8);
21002 return ret;
21003 case 10:
21004 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
21005 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21006 ret, "q", "", "=r", 10);
21007 if (unlikely(ret))
21008 return ret;
21009 __get_user_asm(*(u16 *)(8 + (char *)dst),
21010 - (u16 __user *)(8 + (char __user *)src),
21011 + (const u16 __user *)(8 + (const char __user *)src),
21012 ret, "w", "w", "=r", 2);
21013 return ret;
21014 case 16:
21015 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
21016 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21017 ret, "q", "", "=r", 16);
21018 if (unlikely(ret))
21019 return ret;
21020 __get_user_asm(*(u64 *)(8 + (char *)dst),
21021 - (u64 __user *)(8 + (char __user *)src),
21022 + (const u64 __user *)(8 + (const char __user *)src),
21023 ret, "q", "", "=r", 8);
21024 return ret;
21025 default:
21026 - return copy_user_generic(dst, (__force void *)src, size);
21027 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
21028 }
21029 }
21030
21031 static __always_inline __must_check
21032 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
21033 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
21034 {
21035 might_fault();
21036 return __copy_from_user_nocheck(dst, src, size);
21037 }
21038
21039 static __always_inline __must_check
21040 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
21041 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
21042 {
21043 - int ret = 0;
21044 + size_t sz = __compiletime_object_size(src);
21045 + unsigned ret = 0;
21046 +
21047 + if (size > INT_MAX)
21048 + return size;
21049 +
21050 + check_object_size(src, size, true);
21051 +
21052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21053 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21054 + return size;
21055 +#endif
21056 +
21057 + if (unlikely(sz != (size_t)-1 && sz < size)) {
21058 + if(__builtin_constant_p(size))
21059 + copy_to_user_overflow();
21060 + else
21061 + __copy_to_user_overflow(sz, size);
21062 + return size;
21063 + }
21064
21065 if (!__builtin_constant_p(size))
21066 - return copy_user_generic((__force void *)dst, src, size);
21067 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21068 switch (size) {
21069 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
21070 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
21071 ret, "b", "b", "iq", 1);
21072 return ret;
21073 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
21074 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
21075 ret, "w", "w", "ir", 2);
21076 return ret;
21077 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
21078 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
21079 ret, "l", "k", "ir", 4);
21080 return ret;
21081 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
21082 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21083 ret, "q", "", "er", 8);
21084 return ret;
21085 case 10:
21086 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21087 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21088 ret, "q", "", "er", 10);
21089 if (unlikely(ret))
21090 return ret;
21091 asm("":::"memory");
21092 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
21093 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
21094 ret, "w", "w", "ir", 2);
21095 return ret;
21096 case 16:
21097 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21098 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21099 ret, "q", "", "er", 16);
21100 if (unlikely(ret))
21101 return ret;
21102 asm("":::"memory");
21103 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
21104 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
21105 ret, "q", "", "er", 8);
21106 return ret;
21107 default:
21108 - return copy_user_generic((__force void *)dst, src, size);
21109 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21110 }
21111 }
21112
21113 static __always_inline __must_check
21114 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
21115 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
21116 {
21117 might_fault();
21118 return __copy_to_user_nocheck(dst, src, size);
21119 }
21120
21121 static __always_inline __must_check
21122 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21123 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21124 {
21125 - int ret = 0;
21126 + unsigned ret = 0;
21127
21128 might_fault();
21129 +
21130 + if (size > INT_MAX)
21131 + return size;
21132 +
21133 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21134 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21135 + return size;
21136 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21137 + return size;
21138 +#endif
21139 +
21140 if (!__builtin_constant_p(size))
21141 - return copy_user_generic((__force void *)dst,
21142 - (__force void *)src, size);
21143 + return copy_user_generic((__force_kernel void *)____m(dst),
21144 + (__force_kernel const void *)____m(src), size);
21145 switch (size) {
21146 case 1: {
21147 u8 tmp;
21148 - __get_user_asm(tmp, (u8 __user *)src,
21149 + __get_user_asm(tmp, (const u8 __user *)src,
21150 ret, "b", "b", "=q", 1);
21151 if (likely(!ret))
21152 __put_user_asm(tmp, (u8 __user *)dst,
21153 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21154 }
21155 case 2: {
21156 u16 tmp;
21157 - __get_user_asm(tmp, (u16 __user *)src,
21158 + __get_user_asm(tmp, (const u16 __user *)src,
21159 ret, "w", "w", "=r", 2);
21160 if (likely(!ret))
21161 __put_user_asm(tmp, (u16 __user *)dst,
21162 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21163
21164 case 4: {
21165 u32 tmp;
21166 - __get_user_asm(tmp, (u32 __user *)src,
21167 + __get_user_asm(tmp, (const u32 __user *)src,
21168 ret, "l", "k", "=r", 4);
21169 if (likely(!ret))
21170 __put_user_asm(tmp, (u32 __user *)dst,
21171 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21172 }
21173 case 8: {
21174 u64 tmp;
21175 - __get_user_asm(tmp, (u64 __user *)src,
21176 + __get_user_asm(tmp, (const u64 __user *)src,
21177 ret, "q", "", "=r", 8);
21178 if (likely(!ret))
21179 __put_user_asm(tmp, (u64 __user *)dst,
21180 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21181 return ret;
21182 }
21183 default:
21184 - return copy_user_generic((__force void *)dst,
21185 - (__force void *)src, size);
21186 + return copy_user_generic((__force_kernel void *)____m(dst),
21187 + (__force_kernel const void *)____m(src), size);
21188 }
21189 }
21190
21191 -static __must_check __always_inline int
21192 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
21193 +static __must_check __always_inline unsigned long
21194 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
21195 {
21196 return __copy_from_user_nocheck(dst, src, size);
21197 }
21198
21199 -static __must_check __always_inline int
21200 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
21201 +static __must_check __always_inline unsigned long
21202 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
21203 {
21204 return __copy_to_user_nocheck(dst, src, size);
21205 }
21206
21207 -extern long __copy_user_nocache(void *dst, const void __user *src,
21208 - unsigned size, int zerorest);
21209 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
21210 + unsigned long size, int zerorest);
21211
21212 -static inline int
21213 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
21214 +static inline unsigned long
21215 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
21216 {
21217 might_fault();
21218 +
21219 + if (size > INT_MAX)
21220 + return size;
21221 +
21222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21223 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21224 + return size;
21225 +#endif
21226 +
21227 return __copy_user_nocache(dst, src, size, 1);
21228 }
21229
21230 -static inline int
21231 +static inline unsigned long
21232 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
21233 - unsigned size)
21234 + unsigned long size)
21235 {
21236 + if (size > INT_MAX)
21237 + return size;
21238 +
21239 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21240 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21241 + return size;
21242 +#endif
21243 +
21244 return __copy_user_nocache(dst, src, size, 0);
21245 }
21246
21247 unsigned long
21248 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
21249 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
21250
21251 #endif /* _ASM_X86_UACCESS_64_H */
21252 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
21253 index 5b238981..77fdd78 100644
21254 --- a/arch/x86/include/asm/word-at-a-time.h
21255 +++ b/arch/x86/include/asm/word-at-a-time.h
21256 @@ -11,7 +11,7 @@
21257 * and shift, for example.
21258 */
21259 struct word_at_a_time {
21260 - const unsigned long one_bits, high_bits;
21261 + unsigned long one_bits, high_bits;
21262 };
21263
21264 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
21265 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
21266 index e45e4da..44e8572 100644
21267 --- a/arch/x86/include/asm/x86_init.h
21268 +++ b/arch/x86/include/asm/x86_init.h
21269 @@ -129,7 +129,7 @@ struct x86_init_ops {
21270 struct x86_init_timers timers;
21271 struct x86_init_iommu iommu;
21272 struct x86_init_pci pci;
21273 -};
21274 +} __no_const;
21275
21276 /**
21277 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
21278 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
21279 void (*setup_percpu_clockev)(void);
21280 void (*early_percpu_clock_init)(void);
21281 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
21282 -};
21283 +} __no_const;
21284
21285 struct timespec;
21286
21287 @@ -168,7 +168,7 @@ struct x86_platform_ops {
21288 void (*save_sched_clock_state)(void);
21289 void (*restore_sched_clock_state)(void);
21290 void (*apic_post_init)(void);
21291 -};
21292 +} __no_const;
21293
21294 struct pci_dev;
21295 struct msi_msg;
21296 @@ -185,7 +185,7 @@ struct x86_msi_ops {
21297 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
21298 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
21299 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
21300 -};
21301 +} __no_const;
21302
21303 struct IO_APIC_route_entry;
21304 struct io_apic_irq_attr;
21305 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
21306 unsigned int destination, int vector,
21307 struct io_apic_irq_attr *attr);
21308 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
21309 -};
21310 +} __no_const;
21311
21312 extern struct x86_init_ops x86_init;
21313 extern struct x86_cpuinit_ops x86_cpuinit;
21314 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
21315 index c949923..c22bfa4 100644
21316 --- a/arch/x86/include/asm/xen/page.h
21317 +++ b/arch/x86/include/asm/xen/page.h
21318 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
21319 extern struct page *m2p_find_override(unsigned long mfn);
21320 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
21321
21322 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
21323 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
21324 {
21325 unsigned long mfn;
21326
21327 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
21328 index 7e7a79a..0824666 100644
21329 --- a/arch/x86/include/asm/xsave.h
21330 +++ b/arch/x86/include/asm/xsave.h
21331 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21332 if (unlikely(err))
21333 return -EFAULT;
21334
21335 + pax_open_userland();
21336 __asm__ __volatile__(ASM_STAC "\n"
21337 - "1:"XSAVE"\n"
21338 + "1:"
21339 + __copyuser_seg
21340 + XSAVE"\n"
21341 "2: " ASM_CLAC "\n"
21342 xstate_fault
21343 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
21344 : "memory");
21345 + pax_close_userland();
21346 return err;
21347 }
21348
21349 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21350 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
21351 {
21352 int err = 0;
21353 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
21354 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
21355 u32 lmask = mask;
21356 u32 hmask = mask >> 32;
21357
21358 + pax_open_userland();
21359 __asm__ __volatile__(ASM_STAC "\n"
21360 - "1:"XRSTOR"\n"
21361 + "1:"
21362 + __copyuser_seg
21363 + XRSTOR"\n"
21364 "2: " ASM_CLAC "\n"
21365 xstate_fault
21366 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
21367 : "memory"); /* memory required? */
21368 + pax_close_userland();
21369 return err;
21370 }
21371
21372 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
21373 index bbae024..e1528f9 100644
21374 --- a/arch/x86/include/uapi/asm/e820.h
21375 +++ b/arch/x86/include/uapi/asm/e820.h
21376 @@ -63,7 +63,7 @@ struct e820map {
21377 #define ISA_START_ADDRESS 0xa0000
21378 #define ISA_END_ADDRESS 0x100000
21379
21380 -#define BIOS_BEGIN 0x000a0000
21381 +#define BIOS_BEGIN 0x000c0000
21382 #define BIOS_END 0x00100000
21383
21384 #define BIOS_ROM_BASE 0xffe00000
21385 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
21386 index 7b0a55a..ad115bf 100644
21387 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
21388 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
21389 @@ -49,7 +49,6 @@
21390 #define EFLAGS 144
21391 #define RSP 152
21392 #define SS 160
21393 -#define ARGOFFSET R11
21394 #endif /* __ASSEMBLY__ */
21395
21396 /* top of stack page */
21397 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
21398 index ada2e2d..ca69e16 100644
21399 --- a/arch/x86/kernel/Makefile
21400 +++ b/arch/x86/kernel/Makefile
21401 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
21402 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
21403 obj-$(CONFIG_IRQ_WORK) += irq_work.o
21404 obj-y += probe_roms.o
21405 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
21406 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
21407 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
21408 obj-$(CONFIG_X86_64) += mcount_64.o
21409 obj-y += syscall_$(BITS).o vsyscall_gtod.o
21410 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
21411 index a142e77..6222cdd 100644
21412 --- a/arch/x86/kernel/acpi/boot.c
21413 +++ b/arch/x86/kernel/acpi/boot.c
21414 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
21415 * If your system is blacklisted here, but you find that acpi=force
21416 * works for you, please contact linux-acpi@vger.kernel.org
21417 */
21418 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
21419 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
21420 /*
21421 * Boxes that need ACPI disabled
21422 */
21423 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
21424 };
21425
21426 /* second table for DMI checks that should run after early-quirks */
21427 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
21428 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
21429 /*
21430 * HP laptops which use a DSDT reporting as HP/SB400/10000,
21431 * which includes some code which overrides all temperature
21432 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
21433 index 3136820..e2c6577 100644
21434 --- a/arch/x86/kernel/acpi/sleep.c
21435 +++ b/arch/x86/kernel/acpi/sleep.c
21436 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
21437 #else /* CONFIG_64BIT */
21438 #ifdef CONFIG_SMP
21439 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
21440 +
21441 + pax_open_kernel();
21442 early_gdt_descr.address =
21443 (unsigned long)get_cpu_gdt_table(smp_processor_id());
21444 + pax_close_kernel();
21445 +
21446 initial_gs = per_cpu_offset(smp_processor_id());
21447 #endif
21448 initial_code = (unsigned long)wakeup_long64;
21449 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
21450 index 665c6b7..eae4d56 100644
21451 --- a/arch/x86/kernel/acpi/wakeup_32.S
21452 +++ b/arch/x86/kernel/acpi/wakeup_32.S
21453 @@ -29,13 +29,11 @@ wakeup_pmode_return:
21454 # and restore the stack ... but you need gdt for this to work
21455 movl saved_context_esp, %esp
21456
21457 - movl %cs:saved_magic, %eax
21458 - cmpl $0x12345678, %eax
21459 + cmpl $0x12345678, saved_magic
21460 jne bogus_magic
21461
21462 # jump to place where we left off
21463 - movl saved_eip, %eax
21464 - jmp *%eax
21465 + jmp *(saved_eip)
21466
21467 bogus_magic:
21468 jmp bogus_magic
21469 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
21470 index 703130f..27a155d 100644
21471 --- a/arch/x86/kernel/alternative.c
21472 +++ b/arch/x86/kernel/alternative.c
21473 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21474 */
21475 for (a = start; a < end; a++) {
21476 instr = (u8 *)&a->instr_offset + a->instr_offset;
21477 +
21478 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21479 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21480 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21481 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21482 +#endif
21483 +
21484 replacement = (u8 *)&a->repl_offset + a->repl_offset;
21485 BUG_ON(a->replacementlen > a->instrlen);
21486 BUG_ON(a->instrlen > sizeof(insnbuf));
21487 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21488 add_nops(insnbuf + a->replacementlen,
21489 a->instrlen - a->replacementlen);
21490
21491 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21492 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21493 + instr = ktva_ktla(instr);
21494 +#endif
21495 +
21496 text_poke_early(instr, insnbuf, a->instrlen);
21497 }
21498 }
21499 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
21500 for (poff = start; poff < end; poff++) {
21501 u8 *ptr = (u8 *)poff + *poff;
21502
21503 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21504 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21505 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21506 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21507 +#endif
21508 +
21509 if (!*poff || ptr < text || ptr >= text_end)
21510 continue;
21511 /* turn DS segment override prefix into lock prefix */
21512 - if (*ptr == 0x3e)
21513 + if (*ktla_ktva(ptr) == 0x3e)
21514 text_poke(ptr, ((unsigned char []){0xf0}), 1);
21515 }
21516 mutex_unlock(&text_mutex);
21517 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
21518 for (poff = start; poff < end; poff++) {
21519 u8 *ptr = (u8 *)poff + *poff;
21520
21521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21522 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21523 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21524 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21525 +#endif
21526 +
21527 if (!*poff || ptr < text || ptr >= text_end)
21528 continue;
21529 /* turn lock prefix into DS segment override prefix */
21530 - if (*ptr == 0xf0)
21531 + if (*ktla_ktva(ptr) == 0xf0)
21532 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21533 }
21534 mutex_unlock(&text_mutex);
21535 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21536
21537 BUG_ON(p->len > MAX_PATCH_LEN);
21538 /* prep the buffer with the original instructions */
21539 - memcpy(insnbuf, p->instr, p->len);
21540 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21541 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21542 (unsigned long)p->instr, p->len);
21543
21544 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21545 if (!uniproc_patched || num_possible_cpus() == 1)
21546 free_init_pages("SMP alternatives",
21547 (unsigned long)__smp_locks,
21548 - (unsigned long)__smp_locks_end);
21549 + PAGE_ALIGN((unsigned long)__smp_locks_end));
21550 #endif
21551
21552 apply_paravirt(__parainstructions, __parainstructions_end);
21553 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21554 * instructions. And on the local CPU you need to be protected again NMI or MCE
21555 * handlers seeing an inconsistent instruction while you patch.
21556 */
21557 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
21558 +void *__kprobes text_poke_early(void *addr, const void *opcode,
21559 size_t len)
21560 {
21561 unsigned long flags;
21562 local_irq_save(flags);
21563 - memcpy(addr, opcode, len);
21564 +
21565 + pax_open_kernel();
21566 + memcpy(ktla_ktva(addr), opcode, len);
21567 sync_core();
21568 + pax_close_kernel();
21569 +
21570 local_irq_restore(flags);
21571 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21572 that causes hangs on some VIA CPUs. */
21573 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21574 */
21575 void *text_poke(void *addr, const void *opcode, size_t len)
21576 {
21577 - unsigned long flags;
21578 - char *vaddr;
21579 + unsigned char *vaddr = ktla_ktva(addr);
21580 struct page *pages[2];
21581 - int i;
21582 + size_t i;
21583
21584 if (!core_kernel_text((unsigned long)addr)) {
21585 - pages[0] = vmalloc_to_page(addr);
21586 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21587 + pages[0] = vmalloc_to_page(vaddr);
21588 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21589 } else {
21590 - pages[0] = virt_to_page(addr);
21591 + pages[0] = virt_to_page(vaddr);
21592 WARN_ON(!PageReserved(pages[0]));
21593 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21594 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21595 }
21596 BUG_ON(!pages[0]);
21597 - local_irq_save(flags);
21598 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21599 - if (pages[1])
21600 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21601 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21602 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21603 - clear_fixmap(FIX_TEXT_POKE0);
21604 - if (pages[1])
21605 - clear_fixmap(FIX_TEXT_POKE1);
21606 - local_flush_tlb();
21607 - sync_core();
21608 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21609 - that causes hangs on some VIA CPUs. */
21610 + text_poke_early(addr, opcode, len);
21611 for (i = 0; i < len; i++)
21612 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21613 - local_irq_restore(flags);
21614 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21615 return addr;
21616 }
21617
21618 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21619 if (likely(!bp_patching_in_progress))
21620 return 0;
21621
21622 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21623 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21624 return 0;
21625
21626 /* set up the specified breakpoint handler */
21627 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21628 */
21629 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21630 {
21631 - unsigned char int3 = 0xcc;
21632 + const unsigned char int3 = 0xcc;
21633
21634 bp_int3_handler = handler;
21635 bp_int3_addr = (u8 *)addr + sizeof(int3);
21636 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21637 index 24b5894..6d9701b 100644
21638 --- a/arch/x86/kernel/apic/apic.c
21639 +++ b/arch/x86/kernel/apic/apic.c
21640 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21641 /*
21642 * Debug level, exported for io_apic.c
21643 */
21644 -unsigned int apic_verbosity;
21645 +int apic_verbosity;
21646
21647 int pic_mode;
21648
21649 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21650 apic_write(APIC_ESR, 0);
21651 v = apic_read(APIC_ESR);
21652 ack_APIC_irq();
21653 - atomic_inc(&irq_err_count);
21654 + atomic_inc_unchecked(&irq_err_count);
21655
21656 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21657 smp_processor_id(), v);
21658 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21659 index de918c4..32eed23 100644
21660 --- a/arch/x86/kernel/apic/apic_flat_64.c
21661 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21662 @@ -154,7 +154,7 @@ static int flat_probe(void)
21663 return 1;
21664 }
21665
21666 -static struct apic apic_flat = {
21667 +static struct apic apic_flat __read_only = {
21668 .name = "flat",
21669 .probe = flat_probe,
21670 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21671 @@ -260,7 +260,7 @@ static int physflat_probe(void)
21672 return 0;
21673 }
21674
21675 -static struct apic apic_physflat = {
21676 +static struct apic apic_physflat __read_only = {
21677
21678 .name = "physical flat",
21679 .probe = physflat_probe,
21680 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21681 index b205cdb..d8503ff 100644
21682 --- a/arch/x86/kernel/apic/apic_noop.c
21683 +++ b/arch/x86/kernel/apic/apic_noop.c
21684 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21685 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21686 }
21687
21688 -struct apic apic_noop = {
21689 +struct apic apic_noop __read_only = {
21690 .name = "noop",
21691 .probe = noop_probe,
21692 .acpi_madt_oem_check = NULL,
21693 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21694 index c4a8d63..fe893ac 100644
21695 --- a/arch/x86/kernel/apic/bigsmp_32.c
21696 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21697 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21698 return dmi_bigsmp;
21699 }
21700
21701 -static struct apic apic_bigsmp = {
21702 +static struct apic apic_bigsmp __read_only = {
21703
21704 .name = "bigsmp",
21705 .probe = probe_bigsmp,
21706 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21707 index 337ce5a..c8d98b4 100644
21708 --- a/arch/x86/kernel/apic/io_apic.c
21709 +++ b/arch/x86/kernel/apic/io_apic.c
21710 @@ -1230,7 +1230,7 @@ out:
21711 }
21712 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21713
21714 -void lock_vector_lock(void)
21715 +void lock_vector_lock(void) __acquires(vector_lock)
21716 {
21717 /* Used to the online set of cpus does not change
21718 * during assign_irq_vector.
21719 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21720 raw_spin_lock(&vector_lock);
21721 }
21722
21723 -void unlock_vector_lock(void)
21724 +void unlock_vector_lock(void) __releases(vector_lock)
21725 {
21726 raw_spin_unlock(&vector_lock);
21727 }
21728 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21729 ack_APIC_irq();
21730 }
21731
21732 -atomic_t irq_mis_count;
21733 +atomic_unchecked_t irq_mis_count;
21734
21735 #ifdef CONFIG_GENERIC_PENDING_IRQ
21736 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21737 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21738 * at the cpu.
21739 */
21740 if (!(v & (1 << (i & 0x1f)))) {
21741 - atomic_inc(&irq_mis_count);
21742 + atomic_inc_unchecked(&irq_mis_count);
21743
21744 eoi_ioapic_irq(irq, cfg);
21745 }
21746 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21747 index bda4886..f9c7195 100644
21748 --- a/arch/x86/kernel/apic/probe_32.c
21749 +++ b/arch/x86/kernel/apic/probe_32.c
21750 @@ -72,7 +72,7 @@ static int probe_default(void)
21751 return 1;
21752 }
21753
21754 -static struct apic apic_default = {
21755 +static struct apic apic_default __read_only = {
21756
21757 .name = "default",
21758 .probe = probe_default,
21759 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21760 index 6ce600f..cb44af8 100644
21761 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21762 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21763 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21764 return notifier_from_errno(err);
21765 }
21766
21767 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21768 +static struct notifier_block x2apic_cpu_notifier = {
21769 .notifier_call = update_clusterinfo,
21770 };
21771
21772 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21773 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21774 }
21775
21776 -static struct apic apic_x2apic_cluster = {
21777 +static struct apic apic_x2apic_cluster __read_only = {
21778
21779 .name = "cluster x2apic",
21780 .probe = x2apic_cluster_probe,
21781 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21782 index 6fae733..5ca17af 100644
21783 --- a/arch/x86/kernel/apic/x2apic_phys.c
21784 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21785 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21786 return apic == &apic_x2apic_phys;
21787 }
21788
21789 -static struct apic apic_x2apic_phys = {
21790 +static struct apic apic_x2apic_phys __read_only = {
21791
21792 .name = "physical x2apic",
21793 .probe = x2apic_phys_probe,
21794 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21795 index 004f017..8fbc8b5 100644
21796 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21797 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21798 @@ -350,7 +350,7 @@ static int uv_probe(void)
21799 return apic == &apic_x2apic_uv_x;
21800 }
21801
21802 -static struct apic __refdata apic_x2apic_uv_x = {
21803 +static struct apic apic_x2apic_uv_x __read_only = {
21804
21805 .name = "UV large system",
21806 .probe = uv_probe,
21807 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21808 index 5848744..56cb598 100644
21809 --- a/arch/x86/kernel/apm_32.c
21810 +++ b/arch/x86/kernel/apm_32.c
21811 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21812 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21813 * even though they are called in protected mode.
21814 */
21815 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21816 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21817 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21818
21819 static const char driver_version[] = "1.16ac"; /* no spaces */
21820 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21821 BUG_ON(cpu != 0);
21822 gdt = get_cpu_gdt_table(cpu);
21823 save_desc_40 = gdt[0x40 / 8];
21824 +
21825 + pax_open_kernel();
21826 gdt[0x40 / 8] = bad_bios_desc;
21827 + pax_close_kernel();
21828
21829 apm_irq_save(flags);
21830 APM_DO_SAVE_SEGS;
21831 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21832 &call->esi);
21833 APM_DO_RESTORE_SEGS;
21834 apm_irq_restore(flags);
21835 +
21836 + pax_open_kernel();
21837 gdt[0x40 / 8] = save_desc_40;
21838 + pax_close_kernel();
21839 +
21840 put_cpu();
21841
21842 return call->eax & 0xff;
21843 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21844 BUG_ON(cpu != 0);
21845 gdt = get_cpu_gdt_table(cpu);
21846 save_desc_40 = gdt[0x40 / 8];
21847 +
21848 + pax_open_kernel();
21849 gdt[0x40 / 8] = bad_bios_desc;
21850 + pax_close_kernel();
21851
21852 apm_irq_save(flags);
21853 APM_DO_SAVE_SEGS;
21854 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21855 &call->eax);
21856 APM_DO_RESTORE_SEGS;
21857 apm_irq_restore(flags);
21858 +
21859 + pax_open_kernel();
21860 gdt[0x40 / 8] = save_desc_40;
21861 + pax_close_kernel();
21862 +
21863 put_cpu();
21864 return error;
21865 }
21866 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21867 * code to that CPU.
21868 */
21869 gdt = get_cpu_gdt_table(0);
21870 +
21871 + pax_open_kernel();
21872 set_desc_base(&gdt[APM_CS >> 3],
21873 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21874 set_desc_base(&gdt[APM_CS_16 >> 3],
21875 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21876 set_desc_base(&gdt[APM_DS >> 3],
21877 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21878 + pax_close_kernel();
21879
21880 proc_create("apm", 0, NULL, &apm_file_ops);
21881
21882 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21883 index 9f6b934..cf5ffb3 100644
21884 --- a/arch/x86/kernel/asm-offsets.c
21885 +++ b/arch/x86/kernel/asm-offsets.c
21886 @@ -32,6 +32,8 @@ void common(void) {
21887 OFFSET(TI_flags, thread_info, flags);
21888 OFFSET(TI_status, thread_info, status);
21889 OFFSET(TI_addr_limit, thread_info, addr_limit);
21890 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21891 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21892
21893 BLANK();
21894 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21895 @@ -52,8 +54,26 @@ void common(void) {
21896 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21897 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21898 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21899 +
21900 +#ifdef CONFIG_PAX_KERNEXEC
21901 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21902 #endif
21903
21904 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21905 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21906 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21907 +#ifdef CONFIG_X86_64
21908 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21909 +#endif
21910 +#endif
21911 +
21912 +#endif
21913 +
21914 + BLANK();
21915 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21916 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21917 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21918 +
21919 #ifdef CONFIG_XEN
21920 BLANK();
21921 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21922 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21923 index e7c798b..2b2019b 100644
21924 --- a/arch/x86/kernel/asm-offsets_64.c
21925 +++ b/arch/x86/kernel/asm-offsets_64.c
21926 @@ -77,6 +77,7 @@ int main(void)
21927 BLANK();
21928 #undef ENTRY
21929
21930 + DEFINE(TSS_size, sizeof(struct tss_struct));
21931 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21932 BLANK();
21933
21934 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21935 index 7fd54f0..0691410 100644
21936 --- a/arch/x86/kernel/cpu/Makefile
21937 +++ b/arch/x86/kernel/cpu/Makefile
21938 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21939 CFLAGS_REMOVE_perf_event.o = -pg
21940 endif
21941
21942 -# Make sure load_percpu_segment has no stackprotector
21943 -nostackp := $(call cc-option, -fno-stack-protector)
21944 -CFLAGS_common.o := $(nostackp)
21945 -
21946 obj-y := intel_cacheinfo.o scattered.o topology.o
21947 obj-y += proc.o capflags.o powerflags.o common.o
21948 obj-y += rdrand.o
21949 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21950 index 813d29d..6e542d4 100644
21951 --- a/arch/x86/kernel/cpu/amd.c
21952 +++ b/arch/x86/kernel/cpu/amd.c
21953 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21954 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21955 {
21956 /* AMD errata T13 (order #21922) */
21957 - if ((c->x86 == 6)) {
21958 + if (c->x86 == 6) {
21959 /* Duron Rev A0 */
21960 if (c->x86_model == 3 && c->x86_mask == 0)
21961 size = 64;
21962 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21963 index 35db56b..256e87c 100644
21964 --- a/arch/x86/kernel/cpu/common.c
21965 +++ b/arch/x86/kernel/cpu/common.c
21966 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21967
21968 static const struct cpu_dev *this_cpu = &default_cpu;
21969
21970 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21971 -#ifdef CONFIG_X86_64
21972 - /*
21973 - * We need valid kernel segments for data and code in long mode too
21974 - * IRET will check the segment types kkeil 2000/10/28
21975 - * Also sysret mandates a special GDT layout
21976 - *
21977 - * TLS descriptors are currently at a different place compared to i386.
21978 - * Hopefully nobody expects them at a fixed place (Wine?)
21979 - */
21980 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21981 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21982 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21983 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21984 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21985 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21986 -#else
21987 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21988 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21989 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21990 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21991 - /*
21992 - * Segments used for calling PnP BIOS have byte granularity.
21993 - * They code segments and data segments have fixed 64k limits,
21994 - * the transfer segment sizes are set at run time.
21995 - */
21996 - /* 32-bit code */
21997 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21998 - /* 16-bit code */
21999 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
22000 - /* 16-bit data */
22001 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
22002 - /* 16-bit data */
22003 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
22004 - /* 16-bit data */
22005 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
22006 - /*
22007 - * The APM segments have byte granularity and their bases
22008 - * are set at run time. All have 64k limits.
22009 - */
22010 - /* 32-bit code */
22011 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
22012 - /* 16-bit code */
22013 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
22014 - /* data */
22015 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
22016 -
22017 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22018 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22019 - GDT_STACK_CANARY_INIT
22020 -#endif
22021 -} };
22022 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
22023 -
22024 static int __init x86_xsave_setup(char *s)
22025 {
22026 if (strlen(s))
22027 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
22028 }
22029 }
22030
22031 +#ifdef CONFIG_X86_64
22032 +static __init int setup_disable_pcid(char *arg)
22033 +{
22034 + setup_clear_cpu_cap(X86_FEATURE_PCID);
22035 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
22036 +
22037 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22038 + if (clone_pgd_mask != ~(pgdval_t)0UL)
22039 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
22040 +#endif
22041 +
22042 + return 1;
22043 +}
22044 +__setup("nopcid", setup_disable_pcid);
22045 +
22046 +static void setup_pcid(struct cpuinfo_x86 *c)
22047 +{
22048 + if (!cpu_has(c, X86_FEATURE_PCID)) {
22049 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
22050 +
22051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22052 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
22053 + pax_open_kernel();
22054 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
22055 + pax_close_kernel();
22056 + printk("PAX: slow and weak UDEREF enabled\n");
22057 + } else
22058 + printk("PAX: UDEREF disabled\n");
22059 +#endif
22060 +
22061 + return;
22062 + }
22063 +
22064 + printk("PAX: PCID detected\n");
22065 + set_in_cr4(X86_CR4_PCIDE);
22066 +
22067 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22068 + pax_open_kernel();
22069 + clone_pgd_mask = ~(pgdval_t)0UL;
22070 + pax_close_kernel();
22071 + if (pax_user_shadow_base)
22072 + printk("PAX: weak UDEREF enabled\n");
22073 + else {
22074 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
22075 + printk("PAX: strong UDEREF enabled\n");
22076 + }
22077 +#endif
22078 +
22079 + if (cpu_has(c, X86_FEATURE_INVPCID))
22080 + printk("PAX: INVPCID detected\n");
22081 +}
22082 +#endif
22083 +
22084 /*
22085 * Some CPU features depend on higher CPUID levels, which may not always
22086 * be available due to CPUID level capping or broken virtualization
22087 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
22088 {
22089 struct desc_ptr gdt_descr;
22090
22091 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
22092 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22093 gdt_descr.size = GDT_SIZE - 1;
22094 load_gdt(&gdt_descr);
22095 /* Reload the per-cpu base */
22096 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22097 setup_smep(c);
22098 setup_smap(c);
22099
22100 +#ifdef CONFIG_X86_64
22101 + setup_pcid(c);
22102 +#endif
22103 +
22104 /*
22105 * The vendor-specific functions might have changed features.
22106 * Now we do "generic changes."
22107 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22108 /* Filter out anything that depends on CPUID levels we don't have */
22109 filter_cpuid_features(c, true);
22110
22111 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22112 + setup_clear_cpu_cap(X86_FEATURE_SEP);
22113 +#endif
22114 +
22115 /* If the model name is still unset, do table lookup. */
22116 if (!c->x86_model_id[0]) {
22117 const char *p;
22118 @@ -983,7 +990,7 @@ static void syscall32_cpu_init(void)
22119 void enable_sep_cpu(void)
22120 {
22121 int cpu = get_cpu();
22122 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
22123 + struct tss_struct *tss = init_tss + cpu;
22124
22125 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22126 put_cpu();
22127 @@ -1123,14 +1130,16 @@ static __init int setup_disablecpuid(char *arg)
22128 }
22129 __setup("clearcpuid=", setup_disablecpuid);
22130
22131 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
22132 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
22133 +
22134 DEFINE_PER_CPU(unsigned long, kernel_stack) =
22135 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
22136 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
22137 EXPORT_PER_CPU_SYMBOL(kernel_stack);
22138
22139 #ifdef CONFIG_X86_64
22140 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22141 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
22142 - (unsigned long) debug_idt_table };
22143 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22144 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
22145
22146 DEFINE_PER_CPU_FIRST(union irq_stack_union,
22147 irq_stack_union) __aligned(PAGE_SIZE) __visible;
22148 @@ -1293,7 +1302,7 @@ void cpu_init(void)
22149 load_ucode_ap();
22150
22151 cpu = stack_smp_processor_id();
22152 - t = &per_cpu(init_tss, cpu);
22153 + t = init_tss + cpu;
22154 oist = &per_cpu(orig_ist, cpu);
22155
22156 #ifdef CONFIG_NUMA
22157 @@ -1328,7 +1337,6 @@ void cpu_init(void)
22158 wrmsrl(MSR_KERNEL_GS_BASE, 0);
22159 barrier();
22160
22161 - x86_configure_nx();
22162 enable_x2apic();
22163
22164 /*
22165 @@ -1380,7 +1388,7 @@ void cpu_init(void)
22166 {
22167 int cpu = smp_processor_id();
22168 struct task_struct *curr = current;
22169 - struct tss_struct *t = &per_cpu(init_tss, cpu);
22170 + struct tss_struct *t = init_tss + cpu;
22171 struct thread_struct *thread = &curr->thread;
22172
22173 show_ucode_info_early();
22174 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
22175 index c703507..28535e3 100644
22176 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
22177 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
22178 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
22179 };
22180
22181 #ifdef CONFIG_AMD_NB
22182 +static struct attribute *default_attrs_amd_nb[] = {
22183 + &type.attr,
22184 + &level.attr,
22185 + &coherency_line_size.attr,
22186 + &physical_line_partition.attr,
22187 + &ways_of_associativity.attr,
22188 + &number_of_sets.attr,
22189 + &size.attr,
22190 + &shared_cpu_map.attr,
22191 + &shared_cpu_list.attr,
22192 + NULL,
22193 + NULL,
22194 + NULL,
22195 + NULL
22196 +};
22197 +
22198 static struct attribute **amd_l3_attrs(void)
22199 {
22200 static struct attribute **attrs;
22201 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
22202
22203 n = ARRAY_SIZE(default_attrs);
22204
22205 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
22206 - n += 2;
22207 -
22208 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
22209 - n += 1;
22210 -
22211 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
22212 - if (attrs == NULL)
22213 - return attrs = default_attrs;
22214 -
22215 - for (n = 0; default_attrs[n]; n++)
22216 - attrs[n] = default_attrs[n];
22217 + attrs = default_attrs_amd_nb;
22218
22219 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
22220 attrs[n++] = &cache_disable_0.attr;
22221 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
22222 .default_attrs = default_attrs,
22223 };
22224
22225 +#ifdef CONFIG_AMD_NB
22226 +static struct kobj_type ktype_cache_amd_nb = {
22227 + .sysfs_ops = &sysfs_ops,
22228 + .default_attrs = default_attrs_amd_nb,
22229 +};
22230 +#endif
22231 +
22232 static struct kobj_type ktype_percpu_entry = {
22233 .sysfs_ops = &sysfs_ops,
22234 };
22235 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
22236 return retval;
22237 }
22238
22239 +#ifdef CONFIG_AMD_NB
22240 + amd_l3_attrs();
22241 +#endif
22242 +
22243 for (i = 0; i < num_cache_leaves; i++) {
22244 + struct kobj_type *ktype;
22245 +
22246 this_object = INDEX_KOBJECT_PTR(cpu, i);
22247 this_object->cpu = cpu;
22248 this_object->index = i;
22249
22250 this_leaf = CPUID4_INFO_IDX(cpu, i);
22251
22252 - ktype_cache.default_attrs = default_attrs;
22253 + ktype = &ktype_cache;
22254 #ifdef CONFIG_AMD_NB
22255 if (this_leaf->base.nb)
22256 - ktype_cache.default_attrs = amd_l3_attrs();
22257 + ktype = &ktype_cache_amd_nb;
22258 #endif
22259 retval = kobject_init_and_add(&(this_object->kobj),
22260 - &ktype_cache,
22261 + ktype,
22262 per_cpu(ici_cache_kobject, cpu),
22263 "index%1lu", i);
22264 if (unlikely(retval)) {
22265 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
22266 index bd9ccda..38314e7 100644
22267 --- a/arch/x86/kernel/cpu/mcheck/mce.c
22268 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
22269 @@ -45,6 +45,7 @@
22270 #include <asm/processor.h>
22271 #include <asm/mce.h>
22272 #include <asm/msr.h>
22273 +#include <asm/local.h>
22274
22275 #include "mce-internal.h"
22276
22277 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
22278 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
22279 m->cs, m->ip);
22280
22281 - if (m->cs == __KERNEL_CS)
22282 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
22283 print_symbol("{%s}", m->ip);
22284 pr_cont("\n");
22285 }
22286 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
22287
22288 #define PANIC_TIMEOUT 5 /* 5 seconds */
22289
22290 -static atomic_t mce_paniced;
22291 +static atomic_unchecked_t mce_paniced;
22292
22293 static int fake_panic;
22294 -static atomic_t mce_fake_paniced;
22295 +static atomic_unchecked_t mce_fake_paniced;
22296
22297 /* Panic in progress. Enable interrupts and wait for final IPI */
22298 static void wait_for_panic(void)
22299 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22300 /*
22301 * Make sure only one CPU runs in machine check panic
22302 */
22303 - if (atomic_inc_return(&mce_paniced) > 1)
22304 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
22305 wait_for_panic();
22306 barrier();
22307
22308 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22309 console_verbose();
22310 } else {
22311 /* Don't log too much for fake panic */
22312 - if (atomic_inc_return(&mce_fake_paniced) > 1)
22313 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
22314 return;
22315 }
22316 /* First print corrected ones that are still unlogged */
22317 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22318 if (!fake_panic) {
22319 if (panic_timeout == 0)
22320 panic_timeout = mca_cfg.panic_timeout;
22321 - panic(msg);
22322 + panic("%s", msg);
22323 } else
22324 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
22325 }
22326 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
22327 * might have been modified by someone else.
22328 */
22329 rmb();
22330 - if (atomic_read(&mce_paniced))
22331 + if (atomic_read_unchecked(&mce_paniced))
22332 wait_for_panic();
22333 if (!mca_cfg.monarch_timeout)
22334 goto out;
22335 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
22336 }
22337
22338 /* Call the installed machine check handler for this CPU setup. */
22339 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
22340 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
22341 unexpected_machine_check;
22342
22343 /*
22344 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22345 return;
22346 }
22347
22348 + pax_open_kernel();
22349 machine_check_vector = do_machine_check;
22350 + pax_close_kernel();
22351
22352 __mcheck_cpu_init_generic();
22353 __mcheck_cpu_init_vendor(c);
22354 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22355 */
22356
22357 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
22358 -static int mce_chrdev_open_count; /* #times opened */
22359 +static local_t mce_chrdev_open_count; /* #times opened */
22360 static int mce_chrdev_open_exclu; /* already open exclusive? */
22361
22362 static int mce_chrdev_open(struct inode *inode, struct file *file)
22363 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22364 spin_lock(&mce_chrdev_state_lock);
22365
22366 if (mce_chrdev_open_exclu ||
22367 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
22368 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
22369 spin_unlock(&mce_chrdev_state_lock);
22370
22371 return -EBUSY;
22372 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22373
22374 if (file->f_flags & O_EXCL)
22375 mce_chrdev_open_exclu = 1;
22376 - mce_chrdev_open_count++;
22377 + local_inc(&mce_chrdev_open_count);
22378
22379 spin_unlock(&mce_chrdev_state_lock);
22380
22381 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
22382 {
22383 spin_lock(&mce_chrdev_state_lock);
22384
22385 - mce_chrdev_open_count--;
22386 + local_dec(&mce_chrdev_open_count);
22387 mce_chrdev_open_exclu = 0;
22388
22389 spin_unlock(&mce_chrdev_state_lock);
22390 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
22391
22392 for (i = 0; i < mca_cfg.banks; i++) {
22393 struct mce_bank *b = &mce_banks[i];
22394 - struct device_attribute *a = &b->attr;
22395 + device_attribute_no_const *a = &b->attr;
22396
22397 sysfs_attr_init(&a->attr);
22398 a->attr.name = b->attrname;
22399 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
22400 static void mce_reset(void)
22401 {
22402 cpu_missing = 0;
22403 - atomic_set(&mce_fake_paniced, 0);
22404 + atomic_set_unchecked(&mce_fake_paniced, 0);
22405 atomic_set(&mce_executing, 0);
22406 atomic_set(&mce_callin, 0);
22407 atomic_set(&global_nwo, 0);
22408 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
22409 index a304298..49b6d06 100644
22410 --- a/arch/x86/kernel/cpu/mcheck/p5.c
22411 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
22412 @@ -10,6 +10,7 @@
22413 #include <asm/processor.h>
22414 #include <asm/mce.h>
22415 #include <asm/msr.h>
22416 +#include <asm/pgtable.h>
22417
22418 /* By default disabled */
22419 int mce_p5_enabled __read_mostly;
22420 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
22421 if (!cpu_has(c, X86_FEATURE_MCE))
22422 return;
22423
22424 + pax_open_kernel();
22425 machine_check_vector = pentium_machine_check;
22426 + pax_close_kernel();
22427 /* Make sure the vector pointer is visible before we enable MCEs: */
22428 wmb();
22429
22430 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
22431 index 7dc5564..1273569 100644
22432 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
22433 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
22434 @@ -9,6 +9,7 @@
22435 #include <asm/processor.h>
22436 #include <asm/mce.h>
22437 #include <asm/msr.h>
22438 +#include <asm/pgtable.h>
22439
22440 /* Machine check handler for WinChip C6: */
22441 static void winchip_machine_check(struct pt_regs *regs, long error_code)
22442 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
22443 {
22444 u32 lo, hi;
22445
22446 + pax_open_kernel();
22447 machine_check_vector = winchip_machine_check;
22448 + pax_close_kernel();
22449 /* Make sure the vector pointer is visible before we enable MCEs: */
22450 wmb();
22451
22452 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
22453 index dd9d619..86e1d81 100644
22454 --- a/arch/x86/kernel/cpu/microcode/core.c
22455 +++ b/arch/x86/kernel/cpu/microcode/core.c
22456 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22457 return NOTIFY_OK;
22458 }
22459
22460 -static struct notifier_block __refdata mc_cpu_notifier = {
22461 +static struct notifier_block mc_cpu_notifier = {
22462 .notifier_call = mc_cpu_callback,
22463 };
22464
22465 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
22466 index a276fa7..e66810f 100644
22467 --- a/arch/x86/kernel/cpu/microcode/intel.c
22468 +++ b/arch/x86/kernel/cpu/microcode/intel.c
22469 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22470
22471 static int get_ucode_user(void *to, const void *from, size_t n)
22472 {
22473 - return copy_from_user(to, from, n);
22474 + return copy_from_user(to, (const void __force_user *)from, n);
22475 }
22476
22477 static enum ucode_state
22478 request_microcode_user(int cpu, const void __user *buf, size_t size)
22479 {
22480 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22481 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22482 }
22483
22484 static void microcode_fini_cpu(int cpu)
22485 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
22486 index f961de9..8a9d332 100644
22487 --- a/arch/x86/kernel/cpu/mtrr/main.c
22488 +++ b/arch/x86/kernel/cpu/mtrr/main.c
22489 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
22490 u64 size_or_mask, size_and_mask;
22491 static bool mtrr_aps_delayed_init;
22492
22493 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
22494 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
22495
22496 const struct mtrr_ops *mtrr_if;
22497
22498 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
22499 index df5e41f..816c719 100644
22500 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
22501 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
22502 @@ -25,7 +25,7 @@ struct mtrr_ops {
22503 int (*validate_add_page)(unsigned long base, unsigned long size,
22504 unsigned int type);
22505 int (*have_wrcomb)(void);
22506 -};
22507 +} __do_const;
22508
22509 extern int generic_get_free_region(unsigned long base, unsigned long size,
22510 int replace_reg);
22511 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
22512 index 2879ecd..bb8c80b 100644
22513 --- a/arch/x86/kernel/cpu/perf_event.c
22514 +++ b/arch/x86/kernel/cpu/perf_event.c
22515 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
22516
22517 }
22518
22519 -static struct attribute_group x86_pmu_format_group = {
22520 +static attribute_group_no_const x86_pmu_format_group = {
22521 .name = "format",
22522 .attrs = NULL,
22523 };
22524 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22525 NULL,
22526 };
22527
22528 -static struct attribute_group x86_pmu_events_group = {
22529 +static attribute_group_no_const x86_pmu_events_group = {
22530 .name = "events",
22531 .attrs = events_attr,
22532 };
22533 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22534 if (idx > GDT_ENTRIES)
22535 return 0;
22536
22537 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22538 + desc = get_cpu_gdt_table(smp_processor_id());
22539 }
22540
22541 return get_desc_base(desc + idx);
22542 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22543 break;
22544
22545 perf_callchain_store(entry, frame.return_address);
22546 - fp = frame.next_frame;
22547 + fp = (const void __force_user *)frame.next_frame;
22548 }
22549 }
22550
22551 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22552 index 639d128..e92d7e5 100644
22553 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22554 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22555 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22556 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22557 {
22558 struct attribute **attrs;
22559 - struct attribute_group *attr_group;
22560 + attribute_group_no_const *attr_group;
22561 int i = 0, j;
22562
22563 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22564 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22565 index 2502d0d..e5cc05c 100644
22566 --- a/arch/x86/kernel/cpu/perf_event_intel.c
22567 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
22568 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22569 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22570
22571 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22572 - u64 capabilities;
22573 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22574
22575 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22576 - x86_pmu.intel_cap.capabilities = capabilities;
22577 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22578 + x86_pmu.intel_cap.capabilities = capabilities;
22579 }
22580
22581 intel_ds_init();
22582 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22583 index 619f769..d510008 100644
22584 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22585 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22586 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22587 NULL,
22588 };
22589
22590 -static struct attribute_group rapl_pmu_events_group = {
22591 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22592 .name = "events",
22593 .attrs = NULL, /* patched at runtime */
22594 };
22595 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22596 index 0939f86..69730af 100644
22597 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22598 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22599 @@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22600 static int __init uncore_type_init(struct intel_uncore_type *type)
22601 {
22602 struct intel_uncore_pmu *pmus;
22603 - struct attribute_group *attr_group;
22604 + attribute_group_no_const *attr_group;
22605 struct attribute **attrs;
22606 int i, j;
22607
22608 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22609 index 90236f0..54cb20d 100644
22610 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22611 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22612 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22613 struct uncore_event_desc {
22614 struct kobj_attribute attr;
22615 const char *config;
22616 -};
22617 +} __do_const;
22618
22619 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22620 { \
22621 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22622 index 3225ae6c..ee3c6db 100644
22623 --- a/arch/x86/kernel/cpuid.c
22624 +++ b/arch/x86/kernel/cpuid.c
22625 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22626 return notifier_from_errno(err);
22627 }
22628
22629 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22630 +static struct notifier_block cpuid_class_cpu_notifier =
22631 {
22632 .notifier_call = cpuid_class_cpu_callback,
22633 };
22634 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22635 index a618fcd..200e95b 100644
22636 --- a/arch/x86/kernel/crash.c
22637 +++ b/arch/x86/kernel/crash.c
22638 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22639 #ifdef CONFIG_X86_32
22640 struct pt_regs fixed_regs;
22641
22642 - if (!user_mode_vm(regs)) {
22643 + if (!user_mode(regs)) {
22644 crash_fixup_ss_esp(&fixed_regs, regs);
22645 regs = &fixed_regs;
22646 }
22647 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22648 index afa64ad..dce67dd 100644
22649 --- a/arch/x86/kernel/crash_dump_64.c
22650 +++ b/arch/x86/kernel/crash_dump_64.c
22651 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22652 return -ENOMEM;
22653
22654 if (userbuf) {
22655 - if (copy_to_user(buf, vaddr + offset, csize)) {
22656 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22657 iounmap(vaddr);
22658 return -EFAULT;
22659 }
22660 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22661 index f6dfd93..892ade4 100644
22662 --- a/arch/x86/kernel/doublefault.c
22663 +++ b/arch/x86/kernel/doublefault.c
22664 @@ -12,7 +12,7 @@
22665
22666 #define DOUBLEFAULT_STACKSIZE (1024)
22667 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22668 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22669 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22670
22671 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22672
22673 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22674 unsigned long gdt, tss;
22675
22676 native_store_gdt(&gdt_desc);
22677 - gdt = gdt_desc.address;
22678 + gdt = (unsigned long)gdt_desc.address;
22679
22680 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22681
22682 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22683 /* 0x2 bit is always set */
22684 .flags = X86_EFLAGS_SF | 0x2,
22685 .sp = STACK_START,
22686 - .es = __USER_DS,
22687 + .es = __KERNEL_DS,
22688 .cs = __KERNEL_CS,
22689 .ss = __KERNEL_DS,
22690 - .ds = __USER_DS,
22691 + .ds = __KERNEL_DS,
22692 .fs = __KERNEL_PERCPU,
22693
22694 .__cr3 = __pa_nodebug(swapper_pg_dir),
22695 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22696 index b74ebc7..2c95874 100644
22697 --- a/arch/x86/kernel/dumpstack.c
22698 +++ b/arch/x86/kernel/dumpstack.c
22699 @@ -2,6 +2,9 @@
22700 * Copyright (C) 1991, 1992 Linus Torvalds
22701 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22702 */
22703 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22704 +#define __INCLUDED_BY_HIDESYM 1
22705 +#endif
22706 #include <linux/kallsyms.h>
22707 #include <linux/kprobes.h>
22708 #include <linux/uaccess.h>
22709 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22710
22711 void printk_address(unsigned long address)
22712 {
22713 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22714 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22715 }
22716
22717 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22718 static void
22719 print_ftrace_graph_addr(unsigned long addr, void *data,
22720 const struct stacktrace_ops *ops,
22721 - struct thread_info *tinfo, int *graph)
22722 + struct task_struct *task, int *graph)
22723 {
22724 - struct task_struct *task;
22725 unsigned long ret_addr;
22726 int index;
22727
22728 if (addr != (unsigned long)return_to_handler)
22729 return;
22730
22731 - task = tinfo->task;
22732 index = task->curr_ret_stack;
22733
22734 if (!task->ret_stack || index < *graph)
22735 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22736 static inline void
22737 print_ftrace_graph_addr(unsigned long addr, void *data,
22738 const struct stacktrace_ops *ops,
22739 - struct thread_info *tinfo, int *graph)
22740 + struct task_struct *task, int *graph)
22741 { }
22742 #endif
22743
22744 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22745 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22746 */
22747
22748 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22749 - void *p, unsigned int size, void *end)
22750 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22751 {
22752 - void *t = tinfo;
22753 if (end) {
22754 if (p < end && p >= (end-THREAD_SIZE))
22755 return 1;
22756 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22757 }
22758
22759 unsigned long
22760 -print_context_stack(struct thread_info *tinfo,
22761 +print_context_stack(struct task_struct *task, void *stack_start,
22762 unsigned long *stack, unsigned long bp,
22763 const struct stacktrace_ops *ops, void *data,
22764 unsigned long *end, int *graph)
22765 {
22766 struct stack_frame *frame = (struct stack_frame *)bp;
22767
22768 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22769 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22770 unsigned long addr;
22771
22772 addr = *stack;
22773 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22774 } else {
22775 ops->address(data, addr, 0);
22776 }
22777 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22778 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22779 }
22780 stack++;
22781 }
22782 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22783 EXPORT_SYMBOL_GPL(print_context_stack);
22784
22785 unsigned long
22786 -print_context_stack_bp(struct thread_info *tinfo,
22787 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22788 unsigned long *stack, unsigned long bp,
22789 const struct stacktrace_ops *ops, void *data,
22790 unsigned long *end, int *graph)
22791 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22792 struct stack_frame *frame = (struct stack_frame *)bp;
22793 unsigned long *ret_addr = &frame->return_address;
22794
22795 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22796 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22797 unsigned long addr = *ret_addr;
22798
22799 if (!__kernel_text_address(addr))
22800 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22801 ops->address(data, addr, 1);
22802 frame = frame->next_frame;
22803 ret_addr = &frame->return_address;
22804 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22805 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22806 }
22807
22808 return (unsigned long)frame;
22809 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22810 static void print_trace_address(void *data, unsigned long addr, int reliable)
22811 {
22812 touch_nmi_watchdog();
22813 - printk(data);
22814 + printk("%s", (char *)data);
22815 printk_stack_address(addr, reliable);
22816 }
22817
22818 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22819 EXPORT_SYMBOL_GPL(oops_begin);
22820 NOKPROBE_SYMBOL(oops_begin);
22821
22822 +extern void gr_handle_kernel_exploit(void);
22823 +
22824 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22825 {
22826 if (regs && kexec_should_crash(current))
22827 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22828 panic("Fatal exception in interrupt");
22829 if (panic_on_oops)
22830 panic("Fatal exception");
22831 - do_exit(signr);
22832 +
22833 + gr_handle_kernel_exploit();
22834 +
22835 + do_group_exit(signr);
22836 }
22837 NOKPROBE_SYMBOL(oops_end);
22838
22839 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22840 print_modules();
22841 show_regs(regs);
22842 #ifdef CONFIG_X86_32
22843 - if (user_mode_vm(regs)) {
22844 + if (user_mode(regs)) {
22845 sp = regs->sp;
22846 ss = regs->ss & 0xffff;
22847 } else {
22848 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22849 unsigned long flags = oops_begin();
22850 int sig = SIGSEGV;
22851
22852 - if (!user_mode_vm(regs))
22853 + if (!user_mode(regs))
22854 report_bug(regs->ip, regs);
22855
22856 if (__die(str, regs, err))
22857 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22858 index 5abd4cd..c65733b 100644
22859 --- a/arch/x86/kernel/dumpstack_32.c
22860 +++ b/arch/x86/kernel/dumpstack_32.c
22861 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22862 bp = stack_frame(task, regs);
22863
22864 for (;;) {
22865 - struct thread_info *context;
22866 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22867 void *end_stack;
22868
22869 end_stack = is_hardirq_stack(stack, cpu);
22870 if (!end_stack)
22871 end_stack = is_softirq_stack(stack, cpu);
22872
22873 - context = task_thread_info(task);
22874 - bp = ops->walk_stack(context, stack, bp, ops, data,
22875 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22876 end_stack, &graph);
22877
22878 /* Stop if not on irq stack */
22879 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22880 int i;
22881
22882 show_regs_print_info(KERN_EMERG);
22883 - __show_regs(regs, !user_mode_vm(regs));
22884 + __show_regs(regs, !user_mode(regs));
22885
22886 /*
22887 * When in-kernel, we also print out the stack and code at the
22888 * time of the fault..
22889 */
22890 - if (!user_mode_vm(regs)) {
22891 + if (!user_mode(regs)) {
22892 unsigned int code_prologue = code_bytes * 43 / 64;
22893 unsigned int code_len = code_bytes;
22894 unsigned char c;
22895 u8 *ip;
22896 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22897
22898 pr_emerg("Stack:\n");
22899 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22900
22901 pr_emerg("Code:");
22902
22903 - ip = (u8 *)regs->ip - code_prologue;
22904 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22905 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22906 /* try starting at IP */
22907 - ip = (u8 *)regs->ip;
22908 + ip = (u8 *)regs->ip + cs_base;
22909 code_len = code_len - code_prologue + 1;
22910 }
22911 for (i = 0; i < code_len; i++, ip++) {
22912 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22913 pr_cont(" Bad EIP value.");
22914 break;
22915 }
22916 - if (ip == (u8 *)regs->ip)
22917 + if (ip == (u8 *)regs->ip + cs_base)
22918 pr_cont(" <%02x>", c);
22919 else
22920 pr_cont(" %02x", c);
22921 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22922 {
22923 unsigned short ud2;
22924
22925 + ip = ktla_ktva(ip);
22926 if (ip < PAGE_OFFSET)
22927 return 0;
22928 if (probe_kernel_address((unsigned short *)ip, ud2))
22929 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22930
22931 return ud2 == 0x0b0f;
22932 }
22933 +
22934 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22935 +void pax_check_alloca(unsigned long size)
22936 +{
22937 + unsigned long sp = (unsigned long)&sp, stack_left;
22938 +
22939 + /* all kernel stacks are of the same size */
22940 + stack_left = sp & (THREAD_SIZE - 1);
22941 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22942 +}
22943 +EXPORT_SYMBOL(pax_check_alloca);
22944 +#endif
22945 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22946 index ff86f19..a20c62c 100644
22947 --- a/arch/x86/kernel/dumpstack_64.c
22948 +++ b/arch/x86/kernel/dumpstack_64.c
22949 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22950 const struct stacktrace_ops *ops, void *data)
22951 {
22952 const unsigned cpu = get_cpu();
22953 - struct thread_info *tinfo;
22954 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22955 unsigned long dummy;
22956 unsigned used = 0;
22957 int graph = 0;
22958 int done = 0;
22959 + void *stack_start;
22960
22961 if (!task)
22962 task = current;
22963 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22964 * current stack address. If the stacks consist of nested
22965 * exceptions
22966 */
22967 - tinfo = task_thread_info(task);
22968 while (!done) {
22969 unsigned long *stack_end;
22970 enum stack_type stype;
22971 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22972 if (ops->stack(data, id) < 0)
22973 break;
22974
22975 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22976 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22977 data, stack_end, &graph);
22978 ops->stack(data, "<EOE>");
22979 /*
22980 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22981 * second-to-last pointer (index -2 to end) in the
22982 * exception stack:
22983 */
22984 + if ((u16)stack_end[-1] != __KERNEL_DS)
22985 + goto out;
22986 stack = (unsigned long *) stack_end[-2];
22987 done = 0;
22988 break;
22989 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22990
22991 if (ops->stack(data, "IRQ") < 0)
22992 break;
22993 - bp = ops->walk_stack(tinfo, stack, bp,
22994 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22995 ops, data, stack_end, &graph);
22996 /*
22997 * We link to the next stack (which would be
22998 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22999 /*
23000 * This handles the process stack:
23001 */
23002 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
23003 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
23004 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
23005 +out:
23006 put_cpu();
23007 }
23008 EXPORT_SYMBOL(dump_trace);
23009 @@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
23010
23011 return ud2 == 0x0b0f;
23012 }
23013 +
23014 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
23015 +void pax_check_alloca(unsigned long size)
23016 +{
23017 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
23018 + unsigned cpu, used;
23019 + char *id;
23020 +
23021 + /* check the process stack first */
23022 + stack_start = (unsigned long)task_stack_page(current);
23023 + stack_end = stack_start + THREAD_SIZE;
23024 + if (likely(stack_start <= sp && sp < stack_end)) {
23025 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
23026 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
23027 + return;
23028 + }
23029 +
23030 + cpu = get_cpu();
23031 +
23032 + /* check the irq stacks */
23033 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
23034 + stack_start = stack_end - IRQ_STACK_SIZE;
23035 + if (stack_start <= sp && sp < stack_end) {
23036 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
23037 + put_cpu();
23038 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
23039 + return;
23040 + }
23041 +
23042 + /* check the exception stacks */
23043 + used = 0;
23044 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
23045 + stack_start = stack_end - EXCEPTION_STKSZ;
23046 + if (stack_end && stack_start <= sp && sp < stack_end) {
23047 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
23048 + put_cpu();
23049 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
23050 + return;
23051 + }
23052 +
23053 + put_cpu();
23054 +
23055 + /* unknown stack */
23056 + BUG();
23057 +}
23058 +EXPORT_SYMBOL(pax_check_alloca);
23059 +#endif
23060 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
23061 index 988c00a..4f673b6 100644
23062 --- a/arch/x86/kernel/e820.c
23063 +++ b/arch/x86/kernel/e820.c
23064 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
23065
23066 static void early_panic(char *msg)
23067 {
23068 - early_printk(msg);
23069 - panic(msg);
23070 + early_printk("%s", msg);
23071 + panic("%s", msg);
23072 }
23073
23074 static int userdef __initdata;
23075 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
23076 index 01d1c18..8073693 100644
23077 --- a/arch/x86/kernel/early_printk.c
23078 +++ b/arch/x86/kernel/early_printk.c
23079 @@ -7,6 +7,7 @@
23080 #include <linux/pci_regs.h>
23081 #include <linux/pci_ids.h>
23082 #include <linux/errno.h>
23083 +#include <linux/sched.h>
23084 #include <asm/io.h>
23085 #include <asm/processor.h>
23086 #include <asm/fcntl.h>
23087 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
23088 index 4b0e1df..884b67e 100644
23089 --- a/arch/x86/kernel/entry_32.S
23090 +++ b/arch/x86/kernel/entry_32.S
23091 @@ -177,13 +177,153 @@
23092 /*CFI_REL_OFFSET gs, PT_GS*/
23093 .endm
23094 .macro SET_KERNEL_GS reg
23095 +
23096 +#ifdef CONFIG_CC_STACKPROTECTOR
23097 movl $(__KERNEL_STACK_CANARY), \reg
23098 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23099 + movl $(__USER_DS), \reg
23100 +#else
23101 + xorl \reg, \reg
23102 +#endif
23103 +
23104 movl \reg, %gs
23105 .endm
23106
23107 #endif /* CONFIG_X86_32_LAZY_GS */
23108
23109 -.macro SAVE_ALL
23110 +.macro pax_enter_kernel
23111 +#ifdef CONFIG_PAX_KERNEXEC
23112 + call pax_enter_kernel
23113 +#endif
23114 +.endm
23115 +
23116 +.macro pax_exit_kernel
23117 +#ifdef CONFIG_PAX_KERNEXEC
23118 + call pax_exit_kernel
23119 +#endif
23120 +.endm
23121 +
23122 +#ifdef CONFIG_PAX_KERNEXEC
23123 +ENTRY(pax_enter_kernel)
23124 +#ifdef CONFIG_PARAVIRT
23125 + pushl %eax
23126 + pushl %ecx
23127 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
23128 + mov %eax, %esi
23129 +#else
23130 + mov %cr0, %esi
23131 +#endif
23132 + bts $16, %esi
23133 + jnc 1f
23134 + mov %cs, %esi
23135 + cmp $__KERNEL_CS, %esi
23136 + jz 3f
23137 + ljmp $__KERNEL_CS, $3f
23138 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
23139 +2:
23140 +#ifdef CONFIG_PARAVIRT
23141 + mov %esi, %eax
23142 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
23143 +#else
23144 + mov %esi, %cr0
23145 +#endif
23146 +3:
23147 +#ifdef CONFIG_PARAVIRT
23148 + popl %ecx
23149 + popl %eax
23150 +#endif
23151 + ret
23152 +ENDPROC(pax_enter_kernel)
23153 +
23154 +ENTRY(pax_exit_kernel)
23155 +#ifdef CONFIG_PARAVIRT
23156 + pushl %eax
23157 + pushl %ecx
23158 +#endif
23159 + mov %cs, %esi
23160 + cmp $__KERNEXEC_KERNEL_CS, %esi
23161 + jnz 2f
23162 +#ifdef CONFIG_PARAVIRT
23163 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
23164 + mov %eax, %esi
23165 +#else
23166 + mov %cr0, %esi
23167 +#endif
23168 + btr $16, %esi
23169 + ljmp $__KERNEL_CS, $1f
23170 +1:
23171 +#ifdef CONFIG_PARAVIRT
23172 + mov %esi, %eax
23173 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
23174 +#else
23175 + mov %esi, %cr0
23176 +#endif
23177 +2:
23178 +#ifdef CONFIG_PARAVIRT
23179 + popl %ecx
23180 + popl %eax
23181 +#endif
23182 + ret
23183 +ENDPROC(pax_exit_kernel)
23184 +#endif
23185 +
23186 + .macro pax_erase_kstack
23187 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23188 + call pax_erase_kstack
23189 +#endif
23190 + .endm
23191 +
23192 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23193 +/*
23194 + * ebp: thread_info
23195 + */
23196 +ENTRY(pax_erase_kstack)
23197 + pushl %edi
23198 + pushl %ecx
23199 + pushl %eax
23200 +
23201 + mov TI_lowest_stack(%ebp), %edi
23202 + mov $-0xBEEF, %eax
23203 + std
23204 +
23205 +1: mov %edi, %ecx
23206 + and $THREAD_SIZE_asm - 1, %ecx
23207 + shr $2, %ecx
23208 + repne scasl
23209 + jecxz 2f
23210 +
23211 + cmp $2*16, %ecx
23212 + jc 2f
23213 +
23214 + mov $2*16, %ecx
23215 + repe scasl
23216 + jecxz 2f
23217 + jne 1b
23218 +
23219 +2: cld
23220 + mov %esp, %ecx
23221 + sub %edi, %ecx
23222 +
23223 + cmp $THREAD_SIZE_asm, %ecx
23224 + jb 3f
23225 + ud2
23226 +3:
23227 +
23228 + shr $2, %ecx
23229 + rep stosl
23230 +
23231 + mov TI_task_thread_sp0(%ebp), %edi
23232 + sub $128, %edi
23233 + mov %edi, TI_lowest_stack(%ebp)
23234 +
23235 + popl %eax
23236 + popl %ecx
23237 + popl %edi
23238 + ret
23239 +ENDPROC(pax_erase_kstack)
23240 +#endif
23241 +
23242 +.macro __SAVE_ALL _DS
23243 cld
23244 PUSH_GS
23245 pushl_cfi %fs
23246 @@ -206,7 +346,7 @@
23247 CFI_REL_OFFSET ecx, 0
23248 pushl_cfi %ebx
23249 CFI_REL_OFFSET ebx, 0
23250 - movl $(__USER_DS), %edx
23251 + movl $\_DS, %edx
23252 movl %edx, %ds
23253 movl %edx, %es
23254 movl $(__KERNEL_PERCPU), %edx
23255 @@ -214,6 +354,15 @@
23256 SET_KERNEL_GS %edx
23257 .endm
23258
23259 +.macro SAVE_ALL
23260 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23261 + __SAVE_ALL __KERNEL_DS
23262 + pax_enter_kernel
23263 +#else
23264 + __SAVE_ALL __USER_DS
23265 +#endif
23266 +.endm
23267 +
23268 .macro RESTORE_INT_REGS
23269 popl_cfi %ebx
23270 CFI_RESTORE ebx
23271 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
23272 popfl_cfi
23273 jmp syscall_exit
23274 CFI_ENDPROC
23275 -END(ret_from_fork)
23276 +ENDPROC(ret_from_fork)
23277
23278 ENTRY(ret_from_kernel_thread)
23279 CFI_STARTPROC
23280 @@ -340,7 +489,15 @@ ret_from_intr:
23281 andl $SEGMENT_RPL_MASK, %eax
23282 #endif
23283 cmpl $USER_RPL, %eax
23284 +
23285 +#ifdef CONFIG_PAX_KERNEXEC
23286 + jae resume_userspace
23287 +
23288 + pax_exit_kernel
23289 + jmp resume_kernel
23290 +#else
23291 jb resume_kernel # not returning to v8086 or userspace
23292 +#endif
23293
23294 ENTRY(resume_userspace)
23295 LOCKDEP_SYS_EXIT
23296 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
23297 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
23298 # int/exception return?
23299 jne work_pending
23300 - jmp restore_all
23301 -END(ret_from_exception)
23302 + jmp restore_all_pax
23303 +ENDPROC(ret_from_exception)
23304
23305 #ifdef CONFIG_PREEMPT
23306 ENTRY(resume_kernel)
23307 @@ -365,7 +522,7 @@ need_resched:
23308 jz restore_all
23309 call preempt_schedule_irq
23310 jmp need_resched
23311 -END(resume_kernel)
23312 +ENDPROC(resume_kernel)
23313 #endif
23314 CFI_ENDPROC
23315
23316 @@ -395,30 +552,45 @@ sysenter_past_esp:
23317 /*CFI_REL_OFFSET cs, 0*/
23318 /*
23319 * Push current_thread_info()->sysenter_return to the stack.
23320 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
23321 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
23322 */
23323 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
23324 + pushl_cfi $0
23325 CFI_REL_OFFSET eip, 0
23326
23327 pushl_cfi %eax
23328 SAVE_ALL
23329 + GET_THREAD_INFO(%ebp)
23330 + movl TI_sysenter_return(%ebp),%ebp
23331 + movl %ebp,PT_EIP(%esp)
23332 ENABLE_INTERRUPTS(CLBR_NONE)
23333
23334 /*
23335 * Load the potential sixth argument from user stack.
23336 * Careful about security.
23337 */
23338 + movl PT_OLDESP(%esp),%ebp
23339 +
23340 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23341 + mov PT_OLDSS(%esp),%ds
23342 +1: movl %ds:(%ebp),%ebp
23343 + push %ss
23344 + pop %ds
23345 +#else
23346 cmpl $__PAGE_OFFSET-3,%ebp
23347 jae syscall_fault
23348 ASM_STAC
23349 1: movl (%ebp),%ebp
23350 ASM_CLAC
23351 +#endif
23352 +
23353 movl %ebp,PT_EBP(%esp)
23354 _ASM_EXTABLE(1b,syscall_fault)
23355
23356 GET_THREAD_INFO(%ebp)
23357
23358 +#ifdef CONFIG_PAX_RANDKSTACK
23359 + pax_erase_kstack
23360 +#endif
23361 +
23362 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23363 jnz sysenter_audit
23364 sysenter_do_call:
23365 @@ -434,12 +606,24 @@ sysenter_after_call:
23366 testl $_TIF_ALLWORK_MASK, %ecx
23367 jne sysexit_audit
23368 sysenter_exit:
23369 +
23370 +#ifdef CONFIG_PAX_RANDKSTACK
23371 + pushl_cfi %eax
23372 + movl %esp, %eax
23373 + call pax_randomize_kstack
23374 + popl_cfi %eax
23375 +#endif
23376 +
23377 + pax_erase_kstack
23378 +
23379 /* if something modifies registers it must also disable sysexit */
23380 movl PT_EIP(%esp), %edx
23381 movl PT_OLDESP(%esp), %ecx
23382 xorl %ebp,%ebp
23383 TRACE_IRQS_ON
23384 1: mov PT_FS(%esp), %fs
23385 +2: mov PT_DS(%esp), %ds
23386 +3: mov PT_ES(%esp), %es
23387 PTGS_TO_GS
23388 ENABLE_INTERRUPTS_SYSEXIT
23389
23390 @@ -456,6 +640,9 @@ sysenter_audit:
23391 movl %eax,%edx /* 2nd arg: syscall number */
23392 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
23393 call __audit_syscall_entry
23394 +
23395 + pax_erase_kstack
23396 +
23397 pushl_cfi %ebx
23398 movl PT_EAX(%esp),%eax /* reload syscall number */
23399 jmp sysenter_do_call
23400 @@ -481,10 +668,16 @@ sysexit_audit:
23401
23402 CFI_ENDPROC
23403 .pushsection .fixup,"ax"
23404 -2: movl $0,PT_FS(%esp)
23405 +4: movl $0,PT_FS(%esp)
23406 + jmp 1b
23407 +5: movl $0,PT_DS(%esp)
23408 + jmp 1b
23409 +6: movl $0,PT_ES(%esp)
23410 jmp 1b
23411 .popsection
23412 - _ASM_EXTABLE(1b,2b)
23413 + _ASM_EXTABLE(1b,4b)
23414 + _ASM_EXTABLE(2b,5b)
23415 + _ASM_EXTABLE(3b,6b)
23416 PTGS_TO_GS_EX
23417 ENDPROC(ia32_sysenter_target)
23418
23419 @@ -495,6 +688,11 @@ ENTRY(system_call)
23420 pushl_cfi %eax # save orig_eax
23421 SAVE_ALL
23422 GET_THREAD_INFO(%ebp)
23423 +
23424 +#ifdef CONFIG_PAX_RANDKSTACK
23425 + pax_erase_kstack
23426 +#endif
23427 +
23428 # system call tracing in operation / emulation
23429 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23430 jnz syscall_trace_entry
23431 @@ -514,6 +712,15 @@ syscall_exit:
23432 testl $_TIF_ALLWORK_MASK, %ecx # current->work
23433 jne syscall_exit_work
23434
23435 +restore_all_pax:
23436 +
23437 +#ifdef CONFIG_PAX_RANDKSTACK
23438 + movl %esp, %eax
23439 + call pax_randomize_kstack
23440 +#endif
23441 +
23442 + pax_erase_kstack
23443 +
23444 restore_all:
23445 TRACE_IRQS_IRET
23446 restore_all_notrace:
23447 @@ -568,14 +775,34 @@ ldt_ss:
23448 * compensating for the offset by changing to the ESPFIX segment with
23449 * a base address that matches for the difference.
23450 */
23451 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
23452 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
23453 mov %esp, %edx /* load kernel esp */
23454 mov PT_OLDESP(%esp), %eax /* load userspace esp */
23455 mov %dx, %ax /* eax: new kernel esp */
23456 sub %eax, %edx /* offset (low word is 0) */
23457 +#ifdef CONFIG_SMP
23458 + movl PER_CPU_VAR(cpu_number), %ebx
23459 + shll $PAGE_SHIFT_asm, %ebx
23460 + addl $cpu_gdt_table, %ebx
23461 +#else
23462 + movl $cpu_gdt_table, %ebx
23463 +#endif
23464 shr $16, %edx
23465 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
23466 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
23467 +
23468 +#ifdef CONFIG_PAX_KERNEXEC
23469 + mov %cr0, %esi
23470 + btr $16, %esi
23471 + mov %esi, %cr0
23472 +#endif
23473 +
23474 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
23475 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
23476 +
23477 +#ifdef CONFIG_PAX_KERNEXEC
23478 + bts $16, %esi
23479 + mov %esi, %cr0
23480 +#endif
23481 +
23482 pushl_cfi $__ESPFIX_SS
23483 pushl_cfi %eax /* new kernel esp */
23484 /* Disable interrupts, but do not irqtrace this section: we
23485 @@ -605,20 +832,18 @@ work_resched:
23486 movl TI_flags(%ebp), %ecx
23487 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
23488 # than syscall tracing?
23489 - jz restore_all
23490 + jz restore_all_pax
23491 testb $_TIF_NEED_RESCHED, %cl
23492 jnz work_resched
23493
23494 work_notifysig: # deal with pending signals and
23495 # notify-resume requests
23496 + movl %esp, %eax
23497 #ifdef CONFIG_VM86
23498 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
23499 - movl %esp, %eax
23500 jne work_notifysig_v86 # returning to kernel-space or
23501 # vm86-space
23502 1:
23503 -#else
23504 - movl %esp, %eax
23505 #endif
23506 TRACE_IRQS_ON
23507 ENABLE_INTERRUPTS(CLBR_NONE)
23508 @@ -639,7 +864,7 @@ work_notifysig_v86:
23509 movl %eax, %esp
23510 jmp 1b
23511 #endif
23512 -END(work_pending)
23513 +ENDPROC(work_pending)
23514
23515 # perform syscall exit tracing
23516 ALIGN
23517 @@ -647,11 +872,14 @@ syscall_trace_entry:
23518 movl $-ENOSYS,PT_EAX(%esp)
23519 movl %esp, %eax
23520 call syscall_trace_enter
23521 +
23522 + pax_erase_kstack
23523 +
23524 /* What it returned is what we'll actually use. */
23525 cmpl $(NR_syscalls), %eax
23526 jnae syscall_call
23527 jmp syscall_exit
23528 -END(syscall_trace_entry)
23529 +ENDPROC(syscall_trace_entry)
23530
23531 # perform syscall exit tracing
23532 ALIGN
23533 @@ -664,26 +892,30 @@ syscall_exit_work:
23534 movl %esp, %eax
23535 call syscall_trace_leave
23536 jmp resume_userspace
23537 -END(syscall_exit_work)
23538 +ENDPROC(syscall_exit_work)
23539 CFI_ENDPROC
23540
23541 RING0_INT_FRAME # can't unwind into user space anyway
23542 syscall_fault:
23543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23544 + push %ss
23545 + pop %ds
23546 +#endif
23547 ASM_CLAC
23548 GET_THREAD_INFO(%ebp)
23549 movl $-EFAULT,PT_EAX(%esp)
23550 jmp resume_userspace
23551 -END(syscall_fault)
23552 +ENDPROC(syscall_fault)
23553
23554 syscall_badsys:
23555 movl $-ENOSYS,%eax
23556 jmp syscall_after_call
23557 -END(syscall_badsys)
23558 +ENDPROC(syscall_badsys)
23559
23560 sysenter_badsys:
23561 movl $-ENOSYS,%eax
23562 jmp sysenter_after_call
23563 -END(sysenter_badsys)
23564 +ENDPROC(sysenter_badsys)
23565 CFI_ENDPROC
23566
23567 .macro FIXUP_ESPFIX_STACK
23568 @@ -696,8 +928,15 @@ END(sysenter_badsys)
23569 */
23570 #ifdef CONFIG_X86_ESPFIX32
23571 /* fixup the stack */
23572 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23573 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23574 +#ifdef CONFIG_SMP
23575 + movl PER_CPU_VAR(cpu_number), %ebx
23576 + shll $PAGE_SHIFT_asm, %ebx
23577 + addl $cpu_gdt_table, %ebx
23578 +#else
23579 + movl $cpu_gdt_table, %ebx
23580 +#endif
23581 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23582 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23583 shl $16, %eax
23584 addl %esp, %eax /* the adjusted stack pointer */
23585 pushl_cfi $__KERNEL_DS
23586 @@ -753,7 +992,7 @@ vector=vector+1
23587 .endr
23588 2: jmp common_interrupt
23589 .endr
23590 -END(irq_entries_start)
23591 +ENDPROC(irq_entries_start)
23592
23593 .previous
23594 END(interrupt)
23595 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23596 pushl_cfi $do_coprocessor_error
23597 jmp error_code
23598 CFI_ENDPROC
23599 -END(coprocessor_error)
23600 +ENDPROC(coprocessor_error)
23601
23602 ENTRY(simd_coprocessor_error)
23603 RING0_INT_FRAME
23604 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23605 .section .altinstructions,"a"
23606 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23607 .previous
23608 -.section .altinstr_replacement,"ax"
23609 +.section .altinstr_replacement,"a"
23610 663: pushl $do_simd_coprocessor_error
23611 664:
23612 .previous
23613 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23614 #endif
23615 jmp error_code
23616 CFI_ENDPROC
23617 -END(simd_coprocessor_error)
23618 +ENDPROC(simd_coprocessor_error)
23619
23620 ENTRY(device_not_available)
23621 RING0_INT_FRAME
23622 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23623 pushl_cfi $do_device_not_available
23624 jmp error_code
23625 CFI_ENDPROC
23626 -END(device_not_available)
23627 +ENDPROC(device_not_available)
23628
23629 #ifdef CONFIG_PARAVIRT
23630 ENTRY(native_iret)
23631 iret
23632 _ASM_EXTABLE(native_iret, iret_exc)
23633 -END(native_iret)
23634 +ENDPROC(native_iret)
23635
23636 ENTRY(native_irq_enable_sysexit)
23637 sti
23638 sysexit
23639 -END(native_irq_enable_sysexit)
23640 +ENDPROC(native_irq_enable_sysexit)
23641 #endif
23642
23643 ENTRY(overflow)
23644 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23645 pushl_cfi $do_overflow
23646 jmp error_code
23647 CFI_ENDPROC
23648 -END(overflow)
23649 +ENDPROC(overflow)
23650
23651 ENTRY(bounds)
23652 RING0_INT_FRAME
23653 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23654 pushl_cfi $do_bounds
23655 jmp error_code
23656 CFI_ENDPROC
23657 -END(bounds)
23658 +ENDPROC(bounds)
23659
23660 ENTRY(invalid_op)
23661 RING0_INT_FRAME
23662 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23663 pushl_cfi $do_invalid_op
23664 jmp error_code
23665 CFI_ENDPROC
23666 -END(invalid_op)
23667 +ENDPROC(invalid_op)
23668
23669 ENTRY(coprocessor_segment_overrun)
23670 RING0_INT_FRAME
23671 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23672 pushl_cfi $do_coprocessor_segment_overrun
23673 jmp error_code
23674 CFI_ENDPROC
23675 -END(coprocessor_segment_overrun)
23676 +ENDPROC(coprocessor_segment_overrun)
23677
23678 ENTRY(invalid_TSS)
23679 RING0_EC_FRAME
23680 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23681 pushl_cfi $do_invalid_TSS
23682 jmp error_code
23683 CFI_ENDPROC
23684 -END(invalid_TSS)
23685 +ENDPROC(invalid_TSS)
23686
23687 ENTRY(segment_not_present)
23688 RING0_EC_FRAME
23689 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23690 pushl_cfi $do_segment_not_present
23691 jmp error_code
23692 CFI_ENDPROC
23693 -END(segment_not_present)
23694 +ENDPROC(segment_not_present)
23695
23696 ENTRY(stack_segment)
23697 RING0_EC_FRAME
23698 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23699 pushl_cfi $do_stack_segment
23700 jmp error_code
23701 CFI_ENDPROC
23702 -END(stack_segment)
23703 +ENDPROC(stack_segment)
23704
23705 ENTRY(alignment_check)
23706 RING0_EC_FRAME
23707 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23708 pushl_cfi $do_alignment_check
23709 jmp error_code
23710 CFI_ENDPROC
23711 -END(alignment_check)
23712 +ENDPROC(alignment_check)
23713
23714 ENTRY(divide_error)
23715 RING0_INT_FRAME
23716 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23717 pushl_cfi $do_divide_error
23718 jmp error_code
23719 CFI_ENDPROC
23720 -END(divide_error)
23721 +ENDPROC(divide_error)
23722
23723 #ifdef CONFIG_X86_MCE
23724 ENTRY(machine_check)
23725 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23726 pushl_cfi machine_check_vector
23727 jmp error_code
23728 CFI_ENDPROC
23729 -END(machine_check)
23730 +ENDPROC(machine_check)
23731 #endif
23732
23733 ENTRY(spurious_interrupt_bug)
23734 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23735 pushl_cfi $do_spurious_interrupt_bug
23736 jmp error_code
23737 CFI_ENDPROC
23738 -END(spurious_interrupt_bug)
23739 +ENDPROC(spurious_interrupt_bug)
23740
23741 #ifdef CONFIG_XEN
23742 /* Xen doesn't set %esp to be precisely what the normal sysenter
23743 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23744
23745 ENTRY(mcount)
23746 ret
23747 -END(mcount)
23748 +ENDPROC(mcount)
23749
23750 ENTRY(ftrace_caller)
23751 pushl %eax
23752 @@ -1086,7 +1325,7 @@ ftrace_graph_call:
23753 .globl ftrace_stub
23754 ftrace_stub:
23755 ret
23756 -END(ftrace_caller)
23757 +ENDPROC(ftrace_caller)
23758
23759 ENTRY(ftrace_regs_caller)
23760 pushf /* push flags before compare (in cs location) */
23761 @@ -1184,7 +1423,7 @@ trace:
23762 popl %ecx
23763 popl %eax
23764 jmp ftrace_stub
23765 -END(mcount)
23766 +ENDPROC(mcount)
23767 #endif /* CONFIG_DYNAMIC_FTRACE */
23768 #endif /* CONFIG_FUNCTION_TRACER */
23769
23770 @@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23771 popl %ecx
23772 popl %eax
23773 ret
23774 -END(ftrace_graph_caller)
23775 +ENDPROC(ftrace_graph_caller)
23776
23777 .globl return_to_handler
23778 return_to_handler:
23779 @@ -1263,15 +1502,18 @@ error_code:
23780 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23781 REG_TO_PTGS %ecx
23782 SET_KERNEL_GS %ecx
23783 - movl $(__USER_DS), %ecx
23784 + movl $(__KERNEL_DS), %ecx
23785 movl %ecx, %ds
23786 movl %ecx, %es
23787 +
23788 + pax_enter_kernel
23789 +
23790 TRACE_IRQS_OFF
23791 movl %esp,%eax # pt_regs pointer
23792 call *%edi
23793 jmp ret_from_exception
23794 CFI_ENDPROC
23795 -END(page_fault)
23796 +ENDPROC(page_fault)
23797
23798 /*
23799 * Debug traps and NMI can happen at the one SYSENTER instruction
23800 @@ -1314,7 +1556,7 @@ debug_stack_correct:
23801 call do_debug
23802 jmp ret_from_exception
23803 CFI_ENDPROC
23804 -END(debug)
23805 +ENDPROC(debug)
23806
23807 /*
23808 * NMI is doubly nasty. It can happen _while_ we're handling
23809 @@ -1354,6 +1596,9 @@ nmi_stack_correct:
23810 xorl %edx,%edx # zero error code
23811 movl %esp,%eax # pt_regs pointer
23812 call do_nmi
23813 +
23814 + pax_exit_kernel
23815 +
23816 jmp restore_all_notrace
23817 CFI_ENDPROC
23818
23819 @@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23820 FIXUP_ESPFIX_STACK # %eax == %esp
23821 xorl %edx,%edx # zero error code
23822 call do_nmi
23823 +
23824 + pax_exit_kernel
23825 +
23826 RESTORE_REGS
23827 lss 12+4(%esp), %esp # back to espfix stack
23828 CFI_ADJUST_CFA_OFFSET -24
23829 jmp irq_return
23830 #endif
23831 CFI_ENDPROC
23832 -END(nmi)
23833 +ENDPROC(nmi)
23834
23835 ENTRY(int3)
23836 RING0_INT_FRAME
23837 @@ -1410,14 +1658,14 @@ ENTRY(int3)
23838 call do_int3
23839 jmp ret_from_exception
23840 CFI_ENDPROC
23841 -END(int3)
23842 +ENDPROC(int3)
23843
23844 ENTRY(general_protection)
23845 RING0_EC_FRAME
23846 pushl_cfi $do_general_protection
23847 jmp error_code
23848 CFI_ENDPROC
23849 -END(general_protection)
23850 +ENDPROC(general_protection)
23851
23852 #ifdef CONFIG_KVM_GUEST
23853 ENTRY(async_page_fault)
23854 @@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23855 pushl_cfi $do_async_page_fault
23856 jmp error_code
23857 CFI_ENDPROC
23858 -END(async_page_fault)
23859 +ENDPROC(async_page_fault)
23860 #endif
23861
23862 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23863 index b9dde27..6e9dc4e 100644
23864 --- a/arch/x86/kernel/entry_64.S
23865 +++ b/arch/x86/kernel/entry_64.S
23866 @@ -59,6 +59,8 @@
23867 #include <asm/smap.h>
23868 #include <asm/pgtable_types.h>
23869 #include <linux/err.h>
23870 +#include <asm/pgtable.h>
23871 +#include <asm/alternative-asm.h>
23872
23873 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23874 #include <linux/elf-em.h>
23875 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23876 ENDPROC(native_usergs_sysret64)
23877 #endif /* CONFIG_PARAVIRT */
23878
23879 + .macro ljmpq sel, off
23880 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23881 + .byte 0x48; ljmp *1234f(%rip)
23882 + .pushsection .rodata
23883 + .align 16
23884 + 1234: .quad \off; .word \sel
23885 + .popsection
23886 +#else
23887 + pushq $\sel
23888 + pushq $\off
23889 + lretq
23890 +#endif
23891 + .endm
23892 +
23893 + .macro pax_enter_kernel
23894 + pax_set_fptr_mask
23895 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23896 + call pax_enter_kernel
23897 +#endif
23898 + .endm
23899 +
23900 + .macro pax_exit_kernel
23901 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23902 + call pax_exit_kernel
23903 +#endif
23904 +
23905 + .endm
23906 +
23907 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23908 +ENTRY(pax_enter_kernel)
23909 + pushq %rdi
23910 +
23911 +#ifdef CONFIG_PARAVIRT
23912 + PV_SAVE_REGS(CLBR_RDI)
23913 +#endif
23914 +
23915 +#ifdef CONFIG_PAX_KERNEXEC
23916 + GET_CR0_INTO_RDI
23917 + bts $16,%rdi
23918 + jnc 3f
23919 + mov %cs,%edi
23920 + cmp $__KERNEL_CS,%edi
23921 + jnz 2f
23922 +1:
23923 +#endif
23924 +
23925 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23926 + 661: jmp 111f
23927 + .pushsection .altinstr_replacement, "a"
23928 + 662: ASM_NOP2
23929 + .popsection
23930 + .pushsection .altinstructions, "a"
23931 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23932 + .popsection
23933 + GET_CR3_INTO_RDI
23934 + cmp $0,%dil
23935 + jnz 112f
23936 + mov $__KERNEL_DS,%edi
23937 + mov %edi,%ss
23938 + jmp 111f
23939 +112: cmp $1,%dil
23940 + jz 113f
23941 + ud2
23942 +113: sub $4097,%rdi
23943 + bts $63,%rdi
23944 + SET_RDI_INTO_CR3
23945 + mov $__UDEREF_KERNEL_DS,%edi
23946 + mov %edi,%ss
23947 +111:
23948 +#endif
23949 +
23950 +#ifdef CONFIG_PARAVIRT
23951 + PV_RESTORE_REGS(CLBR_RDI)
23952 +#endif
23953 +
23954 + popq %rdi
23955 + pax_force_retaddr
23956 + retq
23957 +
23958 +#ifdef CONFIG_PAX_KERNEXEC
23959 +2: ljmpq __KERNEL_CS,1b
23960 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23961 +4: SET_RDI_INTO_CR0
23962 + jmp 1b
23963 +#endif
23964 +ENDPROC(pax_enter_kernel)
23965 +
23966 +ENTRY(pax_exit_kernel)
23967 + pushq %rdi
23968 +
23969 +#ifdef CONFIG_PARAVIRT
23970 + PV_SAVE_REGS(CLBR_RDI)
23971 +#endif
23972 +
23973 +#ifdef CONFIG_PAX_KERNEXEC
23974 + mov %cs,%rdi
23975 + cmp $__KERNEXEC_KERNEL_CS,%edi
23976 + jz 2f
23977 + GET_CR0_INTO_RDI
23978 + bts $16,%rdi
23979 + jnc 4f
23980 +1:
23981 +#endif
23982 +
23983 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23984 + 661: jmp 111f
23985 + .pushsection .altinstr_replacement, "a"
23986 + 662: ASM_NOP2
23987 + .popsection
23988 + .pushsection .altinstructions, "a"
23989 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23990 + .popsection
23991 + mov %ss,%edi
23992 + cmp $__UDEREF_KERNEL_DS,%edi
23993 + jnz 111f
23994 + GET_CR3_INTO_RDI
23995 + cmp $0,%dil
23996 + jz 112f
23997 + ud2
23998 +112: add $4097,%rdi
23999 + bts $63,%rdi
24000 + SET_RDI_INTO_CR3
24001 + mov $__KERNEL_DS,%edi
24002 + mov %edi,%ss
24003 +111:
24004 +#endif
24005 +
24006 +#ifdef CONFIG_PARAVIRT
24007 + PV_RESTORE_REGS(CLBR_RDI);
24008 +#endif
24009 +
24010 + popq %rdi
24011 + pax_force_retaddr
24012 + retq
24013 +
24014 +#ifdef CONFIG_PAX_KERNEXEC
24015 +2: GET_CR0_INTO_RDI
24016 + btr $16,%rdi
24017 + jnc 4f
24018 + ljmpq __KERNEL_CS,3f
24019 +3: SET_RDI_INTO_CR0
24020 + jmp 1b
24021 +4: ud2
24022 + jmp 4b
24023 +#endif
24024 +ENDPROC(pax_exit_kernel)
24025 +#endif
24026 +
24027 + .macro pax_enter_kernel_user
24028 + pax_set_fptr_mask
24029 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24030 + call pax_enter_kernel_user
24031 +#endif
24032 + .endm
24033 +
24034 + .macro pax_exit_kernel_user
24035 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24036 + call pax_exit_kernel_user
24037 +#endif
24038 +#ifdef CONFIG_PAX_RANDKSTACK
24039 + pushq %rax
24040 + pushq %r11
24041 + call pax_randomize_kstack
24042 + popq %r11
24043 + popq %rax
24044 +#endif
24045 + .endm
24046 +
24047 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24048 +ENTRY(pax_enter_kernel_user)
24049 + pushq %rdi
24050 + pushq %rbx
24051 +
24052 +#ifdef CONFIG_PARAVIRT
24053 + PV_SAVE_REGS(CLBR_RDI)
24054 +#endif
24055 +
24056 + 661: jmp 111f
24057 + .pushsection .altinstr_replacement, "a"
24058 + 662: ASM_NOP2
24059 + .popsection
24060 + .pushsection .altinstructions, "a"
24061 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24062 + .popsection
24063 + GET_CR3_INTO_RDI
24064 + cmp $1,%dil
24065 + jnz 4f
24066 + sub $4097,%rdi
24067 + bts $63,%rdi
24068 + SET_RDI_INTO_CR3
24069 + jmp 3f
24070 +111:
24071 +
24072 + GET_CR3_INTO_RDI
24073 + mov %rdi,%rbx
24074 + add $__START_KERNEL_map,%rbx
24075 + sub phys_base(%rip),%rbx
24076 +
24077 +#ifdef CONFIG_PARAVIRT
24078 + cmpl $0, pv_info+PARAVIRT_enabled
24079 + jz 1f
24080 + pushq %rdi
24081 + i = 0
24082 + .rept USER_PGD_PTRS
24083 + mov i*8(%rbx),%rsi
24084 + mov $0,%sil
24085 + lea i*8(%rbx),%rdi
24086 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24087 + i = i + 1
24088 + .endr
24089 + popq %rdi
24090 + jmp 2f
24091 +1:
24092 +#endif
24093 +
24094 + i = 0
24095 + .rept USER_PGD_PTRS
24096 + movb $0,i*8(%rbx)
24097 + i = i + 1
24098 + .endr
24099 +
24100 +2: SET_RDI_INTO_CR3
24101 +
24102 +#ifdef CONFIG_PAX_KERNEXEC
24103 + GET_CR0_INTO_RDI
24104 + bts $16,%rdi
24105 + SET_RDI_INTO_CR0
24106 +#endif
24107 +
24108 +3:
24109 +
24110 +#ifdef CONFIG_PARAVIRT
24111 + PV_RESTORE_REGS(CLBR_RDI)
24112 +#endif
24113 +
24114 + popq %rbx
24115 + popq %rdi
24116 + pax_force_retaddr
24117 + retq
24118 +4: ud2
24119 +ENDPROC(pax_enter_kernel_user)
24120 +
24121 +ENTRY(pax_exit_kernel_user)
24122 + pushq %rdi
24123 + pushq %rbx
24124 +
24125 +#ifdef CONFIG_PARAVIRT
24126 + PV_SAVE_REGS(CLBR_RDI)
24127 +#endif
24128 +
24129 + GET_CR3_INTO_RDI
24130 + 661: jmp 1f
24131 + .pushsection .altinstr_replacement, "a"
24132 + 662: ASM_NOP2
24133 + .popsection
24134 + .pushsection .altinstructions, "a"
24135 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24136 + .popsection
24137 + cmp $0,%dil
24138 + jnz 3f
24139 + add $4097,%rdi
24140 + bts $63,%rdi
24141 + SET_RDI_INTO_CR3
24142 + jmp 2f
24143 +1:
24144 +
24145 + mov %rdi,%rbx
24146 +
24147 +#ifdef CONFIG_PAX_KERNEXEC
24148 + GET_CR0_INTO_RDI
24149 + btr $16,%rdi
24150 + jnc 3f
24151 + SET_RDI_INTO_CR0
24152 +#endif
24153 +
24154 + add $__START_KERNEL_map,%rbx
24155 + sub phys_base(%rip),%rbx
24156 +
24157 +#ifdef CONFIG_PARAVIRT
24158 + cmpl $0, pv_info+PARAVIRT_enabled
24159 + jz 1f
24160 + i = 0
24161 + .rept USER_PGD_PTRS
24162 + mov i*8(%rbx),%rsi
24163 + mov $0x67,%sil
24164 + lea i*8(%rbx),%rdi
24165 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24166 + i = i + 1
24167 + .endr
24168 + jmp 2f
24169 +1:
24170 +#endif
24171 +
24172 + i = 0
24173 + .rept USER_PGD_PTRS
24174 + movb $0x67,i*8(%rbx)
24175 + i = i + 1
24176 + .endr
24177 +2:
24178 +
24179 +#ifdef CONFIG_PARAVIRT
24180 + PV_RESTORE_REGS(CLBR_RDI)
24181 +#endif
24182 +
24183 + popq %rbx
24184 + popq %rdi
24185 + pax_force_retaddr
24186 + retq
24187 +3: ud2
24188 +ENDPROC(pax_exit_kernel_user)
24189 +#endif
24190 +
24191 + .macro pax_enter_kernel_nmi
24192 + pax_set_fptr_mask
24193 +
24194 +#ifdef CONFIG_PAX_KERNEXEC
24195 + GET_CR0_INTO_RDI
24196 + bts $16,%rdi
24197 + jc 110f
24198 + SET_RDI_INTO_CR0
24199 + or $2,%ebx
24200 +110:
24201 +#endif
24202 +
24203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24204 + 661: jmp 111f
24205 + .pushsection .altinstr_replacement, "a"
24206 + 662: ASM_NOP2
24207 + .popsection
24208 + .pushsection .altinstructions, "a"
24209 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24210 + .popsection
24211 + GET_CR3_INTO_RDI
24212 + cmp $0,%dil
24213 + jz 111f
24214 + sub $4097,%rdi
24215 + or $4,%ebx
24216 + bts $63,%rdi
24217 + SET_RDI_INTO_CR3
24218 + mov $__UDEREF_KERNEL_DS,%edi
24219 + mov %edi,%ss
24220 +111:
24221 +#endif
24222 + .endm
24223 +
24224 + .macro pax_exit_kernel_nmi
24225 +#ifdef CONFIG_PAX_KERNEXEC
24226 + btr $1,%ebx
24227 + jnc 110f
24228 + GET_CR0_INTO_RDI
24229 + btr $16,%rdi
24230 + SET_RDI_INTO_CR0
24231 +110:
24232 +#endif
24233 +
24234 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24235 + btr $2,%ebx
24236 + jnc 111f
24237 + GET_CR3_INTO_RDI
24238 + add $4097,%rdi
24239 + bts $63,%rdi
24240 + SET_RDI_INTO_CR3
24241 + mov $__KERNEL_DS,%edi
24242 + mov %edi,%ss
24243 +111:
24244 +#endif
24245 + .endm
24246 +
24247 + .macro pax_erase_kstack
24248 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24249 + call pax_erase_kstack
24250 +#endif
24251 + .endm
24252 +
24253 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24254 +ENTRY(pax_erase_kstack)
24255 + pushq %rdi
24256 + pushq %rcx
24257 + pushq %rax
24258 + pushq %r11
24259 +
24260 + GET_THREAD_INFO(%r11)
24261 + mov TI_lowest_stack(%r11), %rdi
24262 + mov $-0xBEEF, %rax
24263 + std
24264 +
24265 +1: mov %edi, %ecx
24266 + and $THREAD_SIZE_asm - 1, %ecx
24267 + shr $3, %ecx
24268 + repne scasq
24269 + jecxz 2f
24270 +
24271 + cmp $2*8, %ecx
24272 + jc 2f
24273 +
24274 + mov $2*8, %ecx
24275 + repe scasq
24276 + jecxz 2f
24277 + jne 1b
24278 +
24279 +2: cld
24280 + mov %esp, %ecx
24281 + sub %edi, %ecx
24282 +
24283 + cmp $THREAD_SIZE_asm, %rcx
24284 + jb 3f
24285 + ud2
24286 +3:
24287 +
24288 + shr $3, %ecx
24289 + rep stosq
24290 +
24291 + mov TI_task_thread_sp0(%r11), %rdi
24292 + sub $256, %rdi
24293 + mov %rdi, TI_lowest_stack(%r11)
24294 +
24295 + popq %r11
24296 + popq %rax
24297 + popq %rcx
24298 + popq %rdi
24299 + pax_force_retaddr
24300 + ret
24301 +ENDPROC(pax_erase_kstack)
24302 +#endif
24303
24304 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
24305 #ifdef CONFIG_TRACE_IRQFLAGS
24306 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
24307 .endm
24308
24309 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
24310 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
24311 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
24312 jnc 1f
24313 TRACE_IRQS_ON_DEBUG
24314 1:
24315 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
24316 movq \tmp,R11+\offset(%rsp)
24317 .endm
24318
24319 - .macro FAKE_STACK_FRAME child_rip
24320 - /* push in order ss, rsp, eflags, cs, rip */
24321 - xorl %eax, %eax
24322 - pushq_cfi $__KERNEL_DS /* ss */
24323 - /*CFI_REL_OFFSET ss,0*/
24324 - pushq_cfi %rax /* rsp */
24325 - CFI_REL_OFFSET rsp,0
24326 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
24327 - /*CFI_REL_OFFSET rflags,0*/
24328 - pushq_cfi $__KERNEL_CS /* cs */
24329 - /*CFI_REL_OFFSET cs,0*/
24330 - pushq_cfi \child_rip /* rip */
24331 - CFI_REL_OFFSET rip,0
24332 - pushq_cfi %rax /* orig rax */
24333 - .endm
24334 -
24335 - .macro UNFAKE_STACK_FRAME
24336 - addq $8*6, %rsp
24337 - CFI_ADJUST_CFA_OFFSET -(6*8)
24338 - .endm
24339 -
24340 /*
24341 * initial frame state for interrupts (and exceptions without error code)
24342 */
24343 @@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
24344 /* save partial stack frame */
24345 .macro SAVE_ARGS_IRQ
24346 cld
24347 - /* start from rbp in pt_regs and jump over */
24348 - movq_cfi rdi, (RDI-RBP)
24349 - movq_cfi rsi, (RSI-RBP)
24350 - movq_cfi rdx, (RDX-RBP)
24351 - movq_cfi rcx, (RCX-RBP)
24352 - movq_cfi rax, (RAX-RBP)
24353 - movq_cfi r8, (R8-RBP)
24354 - movq_cfi r9, (R9-RBP)
24355 - movq_cfi r10, (R10-RBP)
24356 - movq_cfi r11, (R11-RBP)
24357 + /* start from r15 in pt_regs and jump over */
24358 + movq_cfi rdi, RDI
24359 + movq_cfi rsi, RSI
24360 + movq_cfi rdx, RDX
24361 + movq_cfi rcx, RCX
24362 + movq_cfi rax, RAX
24363 + movq_cfi r8, R8
24364 + movq_cfi r9, R9
24365 + movq_cfi r10, R10
24366 + movq_cfi r11, R11
24367 + movq_cfi r12, R12
24368
24369 /* Save rbp so that we can unwind from get_irq_regs() */
24370 - movq_cfi rbp, 0
24371 + movq_cfi rbp, RBP
24372
24373 /* Save previous stack value */
24374 movq %rsp, %rsi
24375
24376 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
24377 - testl $3, CS-RBP(%rsi)
24378 + movq %rsp,%rdi /* arg1 for handler */
24379 + testb $3, CS(%rsi)
24380 je 1f
24381 SWAPGS
24382 /*
24383 @@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
24384 0x06 /* DW_OP_deref */, \
24385 0x08 /* DW_OP_const1u */, SS+8-RBP, \
24386 0x22 /* DW_OP_plus */
24387 +
24388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24389 + testb $3, CS(%rdi)
24390 + jnz 1f
24391 + pax_enter_kernel
24392 + jmp 2f
24393 +1: pax_enter_kernel_user
24394 +2:
24395 +#else
24396 + pax_enter_kernel
24397 +#endif
24398 +
24399 /* We entered an interrupt context - irqs are off: */
24400 TRACE_IRQS_OFF
24401 .endm
24402 @@ -308,9 +726,52 @@ ENTRY(save_paranoid)
24403 js 1f /* negative -> in kernel */
24404 SWAPGS
24405 xorl %ebx,%ebx
24406 -1: ret
24407 +1:
24408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24409 + testb $3, CS+8(%rsp)
24410 + jnz 1f
24411 + pax_enter_kernel
24412 + jmp 2f
24413 +1: pax_enter_kernel_user
24414 +2:
24415 +#else
24416 + pax_enter_kernel
24417 +#endif
24418 + pax_force_retaddr
24419 + ret
24420 CFI_ENDPROC
24421 -END(save_paranoid)
24422 +ENDPROC(save_paranoid)
24423 +
24424 +ENTRY(save_paranoid_nmi)
24425 + XCPT_FRAME 1 RDI+8
24426 + cld
24427 + movq_cfi rdi, RDI+8
24428 + movq_cfi rsi, RSI+8
24429 + movq_cfi rdx, RDX+8
24430 + movq_cfi rcx, RCX+8
24431 + movq_cfi rax, RAX+8
24432 + movq_cfi r8, R8+8
24433 + movq_cfi r9, R9+8
24434 + movq_cfi r10, R10+8
24435 + movq_cfi r11, R11+8
24436 + movq_cfi rbx, RBX+8
24437 + movq_cfi rbp, RBP+8
24438 + movq_cfi r12, R12+8
24439 + movq_cfi r13, R13+8
24440 + movq_cfi r14, R14+8
24441 + movq_cfi r15, R15+8
24442 + movl $1,%ebx
24443 + movl $MSR_GS_BASE,%ecx
24444 + rdmsr
24445 + testl %edx,%edx
24446 + js 1f /* negative -> in kernel */
24447 + SWAPGS
24448 + xorl %ebx,%ebx
24449 +1: pax_enter_kernel_nmi
24450 + pax_force_retaddr
24451 + ret
24452 + CFI_ENDPROC
24453 +ENDPROC(save_paranoid_nmi)
24454
24455 /*
24456 * A newly forked process directly context switches into this address.
24457 @@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
24458
24459 RESTORE_REST
24460
24461 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24462 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24463 jz 1f
24464
24465 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
24466 @@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
24467 jmp ret_from_sys_call # go to the SYSRET fastpath
24468
24469 1:
24470 - subq $REST_SKIP, %rsp # leave space for volatiles
24471 - CFI_ADJUST_CFA_OFFSET REST_SKIP
24472 movq %rbp, %rdi
24473 call *%rbx
24474 movl $0, RAX(%rsp)
24475 RESTORE_REST
24476 jmp int_ret_from_sys_call
24477 CFI_ENDPROC
24478 -END(ret_from_fork)
24479 +ENDPROC(ret_from_fork)
24480
24481 /*
24482 * System call entry. Up to 6 arguments in registers are supported.
24483 @@ -386,7 +845,7 @@ END(ret_from_fork)
24484 ENTRY(system_call)
24485 CFI_STARTPROC simple
24486 CFI_SIGNAL_FRAME
24487 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
24488 + CFI_DEF_CFA rsp,0
24489 CFI_REGISTER rip,rcx
24490 /*CFI_REGISTER rflags,r11*/
24491 SWAPGS_UNSAFE_STACK
24492 @@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
24493
24494 movq %rsp,PER_CPU_VAR(old_rsp)
24495 movq PER_CPU_VAR(kernel_stack),%rsp
24496 + SAVE_ARGS 8*6,0
24497 + pax_enter_kernel_user
24498 +
24499 +#ifdef CONFIG_PAX_RANDKSTACK
24500 + pax_erase_kstack
24501 +#endif
24502 +
24503 /*
24504 * No need to follow this irqs off/on section - it's straight
24505 * and short:
24506 */
24507 ENABLE_INTERRUPTS(CLBR_NONE)
24508 - SAVE_ARGS 8,0
24509 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
24510 movq %rcx,RIP-ARGOFFSET(%rsp)
24511 CFI_REL_OFFSET rip,RIP-ARGOFFSET
24512 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24513 + GET_THREAD_INFO(%rcx)
24514 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
24515 jnz tracesys
24516 system_call_fastpath:
24517 #if __SYSCALL_MASK == ~0
24518 @@ -432,10 +898,13 @@ sysret_check:
24519 LOCKDEP_SYS_EXIT
24520 DISABLE_INTERRUPTS(CLBR_NONE)
24521 TRACE_IRQS_OFF
24522 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24523 + GET_THREAD_INFO(%rcx)
24524 + movl TI_flags(%rcx),%edx
24525 andl %edi,%edx
24526 jnz sysret_careful
24527 CFI_REMEMBER_STATE
24528 + pax_exit_kernel_user
24529 + pax_erase_kstack
24530 /*
24531 * sysretq will re-enable interrupts:
24532 */
24533 @@ -494,6 +963,9 @@ auditsys:
24534 movq %rax,%rsi /* 2nd arg: syscall number */
24535 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24536 call __audit_syscall_entry
24537 +
24538 + pax_erase_kstack
24539 +
24540 LOAD_ARGS 0 /* reload call-clobbered registers */
24541 jmp system_call_fastpath
24542
24543 @@ -515,7 +987,7 @@ sysret_audit:
24544 /* Do syscall tracing */
24545 tracesys:
24546 #ifdef CONFIG_AUDITSYSCALL
24547 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24548 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24549 jz auditsys
24550 #endif
24551 SAVE_REST
24552 @@ -523,12 +995,15 @@ tracesys:
24553 FIXUP_TOP_OF_STACK %rdi
24554 movq %rsp,%rdi
24555 call syscall_trace_enter
24556 +
24557 + pax_erase_kstack
24558 +
24559 /*
24560 * Reload arg registers from stack in case ptrace changed them.
24561 * We don't reload %rax because syscall_trace_enter() returned
24562 * the value it wants us to use in the table lookup.
24563 */
24564 - LOAD_ARGS ARGOFFSET, 1
24565 + LOAD_ARGS 1
24566 RESTORE_REST
24567 #if __SYSCALL_MASK == ~0
24568 cmpq $__NR_syscall_max,%rax
24569 @@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24570 andl %edi,%edx
24571 jnz int_careful
24572 andl $~TS_COMPAT,TI_status(%rcx)
24573 - jmp retint_swapgs
24574 + pax_exit_kernel_user
24575 + pax_erase_kstack
24576 + jmp retint_swapgs_pax
24577
24578 /* Either reschedule or signal or syscall exit tracking needed. */
24579 /* First do a reschedule test. */
24580 @@ -604,7 +1081,7 @@ int_restore_rest:
24581 TRACE_IRQS_OFF
24582 jmp int_with_check
24583 CFI_ENDPROC
24584 -END(system_call)
24585 +ENDPROC(system_call)
24586
24587 .macro FORK_LIKE func
24588 ENTRY(stub_\func)
24589 @@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24590 DEFAULT_FRAME 0 8 /* offset 8: return address */
24591 call sys_\func
24592 RESTORE_TOP_OF_STACK %r11, 8
24593 - ret $REST_SKIP /* pop extended registers */
24594 + pax_force_retaddr
24595 + ret
24596 CFI_ENDPROC
24597 -END(stub_\func)
24598 +ENDPROC(stub_\func)
24599 .endm
24600
24601 .macro FIXED_FRAME label,func
24602 @@ -629,9 +1107,10 @@ ENTRY(\label)
24603 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24604 call \func
24605 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24606 + pax_force_retaddr
24607 ret
24608 CFI_ENDPROC
24609 -END(\label)
24610 +ENDPROC(\label)
24611 .endm
24612
24613 FORK_LIKE clone
24614 @@ -639,19 +1118,6 @@ END(\label)
24615 FORK_LIKE vfork
24616 FIXED_FRAME stub_iopl, sys_iopl
24617
24618 -ENTRY(ptregscall_common)
24619 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24620 - RESTORE_TOP_OF_STACK %r11, 8
24621 - movq_cfi_restore R15+8, r15
24622 - movq_cfi_restore R14+8, r14
24623 - movq_cfi_restore R13+8, r13
24624 - movq_cfi_restore R12+8, r12
24625 - movq_cfi_restore RBP+8, rbp
24626 - movq_cfi_restore RBX+8, rbx
24627 - ret $REST_SKIP /* pop extended registers */
24628 - CFI_ENDPROC
24629 -END(ptregscall_common)
24630 -
24631 ENTRY(stub_execve)
24632 CFI_STARTPROC
24633 addq $8, %rsp
24634 @@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24635 RESTORE_REST
24636 jmp int_ret_from_sys_call
24637 CFI_ENDPROC
24638 -END(stub_execve)
24639 +ENDPROC(stub_execve)
24640
24641 /*
24642 * sigreturn is special because it needs to restore all registers on return.
24643 @@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24644 RESTORE_REST
24645 jmp int_ret_from_sys_call
24646 CFI_ENDPROC
24647 -END(stub_rt_sigreturn)
24648 +ENDPROC(stub_rt_sigreturn)
24649
24650 #ifdef CONFIG_X86_X32_ABI
24651 ENTRY(stub_x32_rt_sigreturn)
24652 @@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24653 RESTORE_REST
24654 jmp int_ret_from_sys_call
24655 CFI_ENDPROC
24656 -END(stub_x32_rt_sigreturn)
24657 +ENDPROC(stub_x32_rt_sigreturn)
24658
24659 ENTRY(stub_x32_execve)
24660 CFI_STARTPROC
24661 @@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24662 RESTORE_REST
24663 jmp int_ret_from_sys_call
24664 CFI_ENDPROC
24665 -END(stub_x32_execve)
24666 +ENDPROC(stub_x32_execve)
24667
24668 #endif
24669
24670 @@ -745,7 +1211,7 @@ vector=vector+1
24671 2: jmp common_interrupt
24672 .endr
24673 CFI_ENDPROC
24674 -END(irq_entries_start)
24675 +ENDPROC(irq_entries_start)
24676
24677 .previous
24678 END(interrupt)
24679 @@ -762,8 +1228,8 @@ END(interrupt)
24680 /* 0(%rsp): ~(interrupt number) */
24681 .macro interrupt func
24682 /* reserve pt_regs for scratch regs and rbp */
24683 - subq $ORIG_RAX-RBP, %rsp
24684 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24685 + subq $ORIG_RAX, %rsp
24686 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24687 SAVE_ARGS_IRQ
24688 call \func
24689 .endm
24690 @@ -786,14 +1252,14 @@ ret_from_intr:
24691
24692 /* Restore saved previous stack */
24693 popq %rsi
24694 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24695 - leaq ARGOFFSET-RBP(%rsi), %rsp
24696 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24697 + movq %rsi, %rsp
24698 CFI_DEF_CFA_REGISTER rsp
24699 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24700 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24701
24702 exit_intr:
24703 GET_THREAD_INFO(%rcx)
24704 - testl $3,CS-ARGOFFSET(%rsp)
24705 + testb $3,CS-ARGOFFSET(%rsp)
24706 je retint_kernel
24707
24708 /* Interrupt came from user space */
24709 @@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24710 * The iretq could re-enable interrupts:
24711 */
24712 DISABLE_INTERRUPTS(CLBR_ANY)
24713 + pax_exit_kernel_user
24714 +retint_swapgs_pax:
24715 TRACE_IRQS_IRETQ
24716 SWAPGS
24717 jmp restore_args
24718
24719 retint_restore_args: /* return to kernel space */
24720 DISABLE_INTERRUPTS(CLBR_ANY)
24721 + pax_exit_kernel
24722 +
24723 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24724 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24725 + * namely calling EFI runtime services with a phys mapping. We're
24726 + * starting off with NOPs and patch in the real instrumentation
24727 + * (BTS/OR) before starting any userland process; even before starting
24728 + * up the APs.
24729 + */
24730 + .pushsection .altinstr_replacement, "a"
24731 + 601: pax_force_retaddr (RIP-ARGOFFSET)
24732 + 602:
24733 + .popsection
24734 + 603: .fill 602b-601b, 1, 0x90
24735 + .pushsection .altinstructions, "a"
24736 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24737 + .popsection
24738 +#else
24739 + pax_force_retaddr (RIP-ARGOFFSET)
24740 +#endif
24741 +
24742 /*
24743 * The iretq could re-enable interrupts:
24744 */
24745 @@ -920,7 +1409,7 @@ ENTRY(retint_kernel)
24746 jmp exit_intr
24747 #endif
24748 CFI_ENDPROC
24749 -END(common_interrupt)
24750 +ENDPROC(common_interrupt)
24751
24752 /*
24753 * APIC interrupts.
24754 @@ -934,7 +1423,7 @@ ENTRY(\sym)
24755 interrupt \do_sym
24756 jmp ret_from_intr
24757 CFI_ENDPROC
24758 -END(\sym)
24759 +ENDPROC(\sym)
24760 .endm
24761
24762 #ifdef CONFIG_TRACING
24763 @@ -1007,7 +1496,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24764 /*
24765 * Exception entry points.
24766 */
24767 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24768 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24769
24770 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24771 ENTRY(\sym)
24772 @@ -1058,6 +1547,12 @@ ENTRY(\sym)
24773 .endif
24774
24775 .if \shift_ist != -1
24776 +#ifdef CONFIG_SMP
24777 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24778 + lea init_tss(%r13), %r13
24779 +#else
24780 + lea init_tss(%rip), %r13
24781 +#endif
24782 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24783 .endif
24784
24785 @@ -1074,7 +1569,7 @@ ENTRY(\sym)
24786 .endif
24787
24788 CFI_ENDPROC
24789 -END(\sym)
24790 +ENDPROC(\sym)
24791 .endm
24792
24793 #ifdef CONFIG_TRACING
24794 @@ -1115,9 +1610,10 @@ gs_change:
24795 2: mfence /* workaround */
24796 SWAPGS
24797 popfq_cfi
24798 + pax_force_retaddr
24799 ret
24800 CFI_ENDPROC
24801 -END(native_load_gs_index)
24802 +ENDPROC(native_load_gs_index)
24803
24804 _ASM_EXTABLE(gs_change,bad_gs)
24805 .section .fixup,"ax"
24806 @@ -1145,9 +1641,10 @@ ENTRY(do_softirq_own_stack)
24807 CFI_DEF_CFA_REGISTER rsp
24808 CFI_ADJUST_CFA_OFFSET -8
24809 decl PER_CPU_VAR(irq_count)
24810 + pax_force_retaddr
24811 ret
24812 CFI_ENDPROC
24813 -END(do_softirq_own_stack)
24814 +ENDPROC(do_softirq_own_stack)
24815
24816 #ifdef CONFIG_XEN
24817 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24818 @@ -1185,7 +1682,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24819 decl PER_CPU_VAR(irq_count)
24820 jmp error_exit
24821 CFI_ENDPROC
24822 -END(xen_do_hypervisor_callback)
24823 +ENDPROC(xen_do_hypervisor_callback)
24824
24825 /*
24826 * Hypervisor uses this for application faults while it executes.
24827 @@ -1244,7 +1741,7 @@ ENTRY(xen_failsafe_callback)
24828 SAVE_ALL
24829 jmp error_exit
24830 CFI_ENDPROC
24831 -END(xen_failsafe_callback)
24832 +ENDPROC(xen_failsafe_callback)
24833
24834 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24835 xen_hvm_callback_vector xen_evtchn_do_upcall
24836 @@ -1291,18 +1788,33 @@ ENTRY(paranoid_exit)
24837 DEFAULT_FRAME
24838 DISABLE_INTERRUPTS(CLBR_NONE)
24839 TRACE_IRQS_OFF_DEBUG
24840 - testl %ebx,%ebx /* swapgs needed? */
24841 + testl $1,%ebx /* swapgs needed? */
24842 jnz paranoid_restore
24843 - testl $3,CS(%rsp)
24844 + testb $3,CS(%rsp)
24845 jnz paranoid_userspace
24846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24847 + pax_exit_kernel
24848 + TRACE_IRQS_IRETQ 0
24849 + SWAPGS_UNSAFE_STACK
24850 + RESTORE_ALL 8
24851 + pax_force_retaddr_bts
24852 + jmp irq_return
24853 +#endif
24854 paranoid_swapgs:
24855 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24856 + pax_exit_kernel_user
24857 +#else
24858 + pax_exit_kernel
24859 +#endif
24860 TRACE_IRQS_IRETQ 0
24861 SWAPGS_UNSAFE_STACK
24862 RESTORE_ALL 8
24863 jmp irq_return
24864 paranoid_restore:
24865 + pax_exit_kernel
24866 TRACE_IRQS_IRETQ_DEBUG 0
24867 RESTORE_ALL 8
24868 + pax_force_retaddr_bts
24869 jmp irq_return
24870 paranoid_userspace:
24871 GET_THREAD_INFO(%rcx)
24872 @@ -1331,7 +1843,7 @@ paranoid_schedule:
24873 TRACE_IRQS_OFF
24874 jmp paranoid_userspace
24875 CFI_ENDPROC
24876 -END(paranoid_exit)
24877 +ENDPROC(paranoid_exit)
24878
24879 /*
24880 * Exception entry point. This expects an error code/orig_rax on the stack.
24881 @@ -1358,12 +1870,23 @@ ENTRY(error_entry)
24882 movq %r14, R14+8(%rsp)
24883 movq %r15, R15+8(%rsp)
24884 xorl %ebx,%ebx
24885 - testl $3,CS+8(%rsp)
24886 + testb $3,CS+8(%rsp)
24887 je error_kernelspace
24888 error_swapgs:
24889 SWAPGS
24890 error_sti:
24891 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24892 + testb $3, CS+8(%rsp)
24893 + jnz 1f
24894 + pax_enter_kernel
24895 + jmp 2f
24896 +1: pax_enter_kernel_user
24897 +2:
24898 +#else
24899 + pax_enter_kernel
24900 +#endif
24901 TRACE_IRQS_OFF
24902 + pax_force_retaddr
24903 ret
24904
24905 /*
24906 @@ -1398,7 +1921,7 @@ error_bad_iret:
24907 decl %ebx /* Return to usergs */
24908 jmp error_sti
24909 CFI_ENDPROC
24910 -END(error_entry)
24911 +ENDPROC(error_entry)
24912
24913
24914 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24915 @@ -1409,7 +1932,7 @@ ENTRY(error_exit)
24916 DISABLE_INTERRUPTS(CLBR_NONE)
24917 TRACE_IRQS_OFF
24918 GET_THREAD_INFO(%rcx)
24919 - testl %eax,%eax
24920 + testl $1,%eax
24921 jne retint_kernel
24922 LOCKDEP_SYS_EXIT_IRQ
24923 movl TI_flags(%rcx),%edx
24924 @@ -1418,7 +1941,7 @@ ENTRY(error_exit)
24925 jnz retint_careful
24926 jmp retint_swapgs
24927 CFI_ENDPROC
24928 -END(error_exit)
24929 +ENDPROC(error_exit)
24930
24931 /*
24932 * Test if a given stack is an NMI stack or not.
24933 @@ -1476,9 +1999,11 @@ ENTRY(nmi)
24934 * If %cs was not the kernel segment, then the NMI triggered in user
24935 * space, which means it is definitely not nested.
24936 */
24937 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24938 + je 1f
24939 cmpl $__KERNEL_CS, 16(%rsp)
24940 jne first_nmi
24941 -
24942 +1:
24943 /*
24944 * Check the special variable on the stack to see if NMIs are
24945 * executing.
24946 @@ -1512,8 +2037,7 @@ nested_nmi:
24947
24948 1:
24949 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24950 - leaq -1*8(%rsp), %rdx
24951 - movq %rdx, %rsp
24952 + subq $8, %rsp
24953 CFI_ADJUST_CFA_OFFSET 1*8
24954 leaq -10*8(%rsp), %rdx
24955 pushq_cfi $__KERNEL_DS
24956 @@ -1531,6 +2055,7 @@ nested_nmi_out:
24957 CFI_RESTORE rdx
24958
24959 /* No need to check faults here */
24960 +# pax_force_retaddr_bts
24961 INTERRUPT_RETURN
24962
24963 CFI_RESTORE_STATE
24964 @@ -1627,13 +2152,13 @@ end_repeat_nmi:
24965 subq $ORIG_RAX-R15, %rsp
24966 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24967 /*
24968 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24969 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24970 * as we should not be calling schedule in NMI context.
24971 * Even with normal interrupts enabled. An NMI should not be
24972 * setting NEED_RESCHED or anything that normal interrupts and
24973 * exceptions might do.
24974 */
24975 - call save_paranoid
24976 + call save_paranoid_nmi
24977 DEFAULT_FRAME 0
24978
24979 /*
24980 @@ -1643,9 +2168,9 @@ end_repeat_nmi:
24981 * NMI itself takes a page fault, the page fault that was preempted
24982 * will read the information from the NMI page fault and not the
24983 * origin fault. Save it off and restore it if it changes.
24984 - * Use the r12 callee-saved register.
24985 + * Use the r13 callee-saved register.
24986 */
24987 - movq %cr2, %r12
24988 + movq %cr2, %r13
24989
24990 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24991 movq %rsp,%rdi
24992 @@ -1654,29 +2179,34 @@ end_repeat_nmi:
24993
24994 /* Did the NMI take a page fault? Restore cr2 if it did */
24995 movq %cr2, %rcx
24996 - cmpq %rcx, %r12
24997 + cmpq %rcx, %r13
24998 je 1f
24999 - movq %r12, %cr2
25000 + movq %r13, %cr2
25001 1:
25002
25003 - testl %ebx,%ebx /* swapgs needed? */
25004 + testl $1,%ebx /* swapgs needed? */
25005 jnz nmi_restore
25006 nmi_swapgs:
25007 SWAPGS_UNSAFE_STACK
25008 nmi_restore:
25009 + pax_exit_kernel_nmi
25010 /* Pop the extra iret frame at once */
25011 RESTORE_ALL 6*8
25012 + testb $3, 8(%rsp)
25013 + jnz 1f
25014 + pax_force_retaddr_bts
25015 +1:
25016
25017 /* Clear the NMI executing stack variable */
25018 movq $0, 5*8(%rsp)
25019 jmp irq_return
25020 CFI_ENDPROC
25021 -END(nmi)
25022 +ENDPROC(nmi)
25023
25024 ENTRY(ignore_sysret)
25025 CFI_STARTPROC
25026 mov $-ENOSYS,%eax
25027 sysret
25028 CFI_ENDPROC
25029 -END(ignore_sysret)
25030 +ENDPROC(ignore_sysret)
25031
25032 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
25033 index 94d857f..bf1f0bf 100644
25034 --- a/arch/x86/kernel/espfix_64.c
25035 +++ b/arch/x86/kernel/espfix_64.c
25036 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
25037 set_pte(&pte_p[n*PTE_STRIDE], pte);
25038
25039 /* Job is done for this CPU and any CPU which shares this page */
25040 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
25041 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
25042
25043 unlock_done:
25044 mutex_unlock(&espfix_init_mutex);
25045 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
25046 index 3386dc9..28bdf81 100644
25047 --- a/arch/x86/kernel/ftrace.c
25048 +++ b/arch/x86/kernel/ftrace.c
25049 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
25050 * kernel identity mapping to modify code.
25051 */
25052 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
25053 - ip = (unsigned long)__va(__pa_symbol(ip));
25054 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
25055
25056 return ip;
25057 }
25058 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
25059 {
25060 unsigned char replaced[MCOUNT_INSN_SIZE];
25061
25062 + ip = ktla_ktva(ip);
25063 +
25064 /*
25065 * Note: Due to modules and __init, code can
25066 * disappear and change, we need to protect against faulting
25067 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
25068 unsigned char old[MCOUNT_INSN_SIZE];
25069 int ret;
25070
25071 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
25072 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
25073
25074 ftrace_update_func = ip;
25075 /* Make sure the breakpoints see the ftrace_update_func update */
25076 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
25077 unsigned char replaced[MCOUNT_INSN_SIZE];
25078 unsigned char brk = BREAKPOINT_INSTRUCTION;
25079
25080 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
25081 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
25082 return -EFAULT;
25083
25084 /* Make sure it is what we expect it to be */
25085 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
25086 index eda1a86..8f6df48 100644
25087 --- a/arch/x86/kernel/head64.c
25088 +++ b/arch/x86/kernel/head64.c
25089 @@ -67,12 +67,12 @@ again:
25090 pgd = *pgd_p;
25091
25092 /*
25093 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
25094 - * critical -- __PAGE_OFFSET would point us back into the dynamic
25095 + * The use of __early_va rather than __va here is critical:
25096 + * __va would point us back into the dynamic
25097 * range and we might end up looping forever...
25098 */
25099 if (pgd)
25100 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25101 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
25102 else {
25103 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25104 reset_early_page_tables();
25105 @@ -82,13 +82,13 @@ again:
25106 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
25107 for (i = 0; i < PTRS_PER_PUD; i++)
25108 pud_p[i] = 0;
25109 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25110 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
25111 }
25112 pud_p += pud_index(address);
25113 pud = *pud_p;
25114
25115 if (pud)
25116 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25117 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
25118 else {
25119 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25120 reset_early_page_tables();
25121 @@ -98,7 +98,7 @@ again:
25122 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
25123 for (i = 0; i < PTRS_PER_PMD; i++)
25124 pmd_p[i] = 0;
25125 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25126 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
25127 }
25128 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
25129 pmd_p[pmd_index(address)] = pmd;
25130 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
25131 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
25132 early_printk("Kernel alive\n");
25133
25134 - clear_page(init_level4_pgt);
25135 /* set init_level4_pgt kernel high mapping*/
25136 init_level4_pgt[511] = early_level4_pgt[511];
25137
25138 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
25139 index f36bd42..0ab4474 100644
25140 --- a/arch/x86/kernel/head_32.S
25141 +++ b/arch/x86/kernel/head_32.S
25142 @@ -26,6 +26,12 @@
25143 /* Physical address */
25144 #define pa(X) ((X) - __PAGE_OFFSET)
25145
25146 +#ifdef CONFIG_PAX_KERNEXEC
25147 +#define ta(X) (X)
25148 +#else
25149 +#define ta(X) ((X) - __PAGE_OFFSET)
25150 +#endif
25151 +
25152 /*
25153 * References to members of the new_cpu_data structure.
25154 */
25155 @@ -55,11 +61,7 @@
25156 * and small than max_low_pfn, otherwise will waste some page table entries
25157 */
25158
25159 -#if PTRS_PER_PMD > 1
25160 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
25161 -#else
25162 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
25163 -#endif
25164 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
25165
25166 /* Number of possible pages in the lowmem region */
25167 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
25168 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
25169 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25170
25171 /*
25172 + * Real beginning of normal "text" segment
25173 + */
25174 +ENTRY(stext)
25175 +ENTRY(_stext)
25176 +
25177 +/*
25178 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
25179 * %esi points to the real-mode code as a 32-bit pointer.
25180 * CS and DS must be 4 GB flat segments, but we don't depend on
25181 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25182 * can.
25183 */
25184 __HEAD
25185 +
25186 +#ifdef CONFIG_PAX_KERNEXEC
25187 + jmp startup_32
25188 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
25189 +.fill PAGE_SIZE-5,1,0xcc
25190 +#endif
25191 +
25192 ENTRY(startup_32)
25193 movl pa(stack_start),%ecx
25194
25195 @@ -106,6 +121,59 @@ ENTRY(startup_32)
25196 2:
25197 leal -__PAGE_OFFSET(%ecx),%esp
25198
25199 +#ifdef CONFIG_SMP
25200 + movl $pa(cpu_gdt_table),%edi
25201 + movl $__per_cpu_load,%eax
25202 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
25203 + rorl $16,%eax
25204 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
25205 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
25206 + movl $__per_cpu_end - 1,%eax
25207 + subl $__per_cpu_start,%eax
25208 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
25209 +#endif
25210 +
25211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25212 + movl $NR_CPUS,%ecx
25213 + movl $pa(cpu_gdt_table),%edi
25214 +1:
25215 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
25216 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
25217 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
25218 + addl $PAGE_SIZE_asm,%edi
25219 + loop 1b
25220 +#endif
25221 +
25222 +#ifdef CONFIG_PAX_KERNEXEC
25223 + movl $pa(boot_gdt),%edi
25224 + movl $__LOAD_PHYSICAL_ADDR,%eax
25225 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
25226 + rorl $16,%eax
25227 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
25228 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
25229 + rorl $16,%eax
25230 +
25231 + ljmp $(__BOOT_CS),$1f
25232 +1:
25233 +
25234 + movl $NR_CPUS,%ecx
25235 + movl $pa(cpu_gdt_table),%edi
25236 + addl $__PAGE_OFFSET,%eax
25237 +1:
25238 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
25239 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
25240 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
25241 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
25242 + rorl $16,%eax
25243 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
25244 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
25245 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
25246 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
25247 + rorl $16,%eax
25248 + addl $PAGE_SIZE_asm,%edi
25249 + loop 1b
25250 +#endif
25251 +
25252 /*
25253 * Clear BSS first so that there are no surprises...
25254 */
25255 @@ -201,8 +269,11 @@ ENTRY(startup_32)
25256 movl %eax, pa(max_pfn_mapped)
25257
25258 /* Do early initialization of the fixmap area */
25259 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25260 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
25261 +#ifdef CONFIG_COMPAT_VDSO
25262 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
25263 +#else
25264 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
25265 +#endif
25266 #else /* Not PAE */
25267
25268 page_pde_offset = (__PAGE_OFFSET >> 20);
25269 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25270 movl %eax, pa(max_pfn_mapped)
25271
25272 /* Do early initialization of the fixmap area */
25273 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25274 - movl %eax,pa(initial_page_table+0xffc)
25275 +#ifdef CONFIG_COMPAT_VDSO
25276 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
25277 +#else
25278 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
25279 +#endif
25280 #endif
25281
25282 #ifdef CONFIG_PARAVIRT
25283 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25284 cmpl $num_subarch_entries, %eax
25285 jae bad_subarch
25286
25287 - movl pa(subarch_entries)(,%eax,4), %eax
25288 - subl $__PAGE_OFFSET, %eax
25289 - jmp *%eax
25290 + jmp *pa(subarch_entries)(,%eax,4)
25291
25292 bad_subarch:
25293 WEAK(lguest_entry)
25294 @@ -261,10 +333,10 @@ WEAK(xen_entry)
25295 __INITDATA
25296
25297 subarch_entries:
25298 - .long default_entry /* normal x86/PC */
25299 - .long lguest_entry /* lguest hypervisor */
25300 - .long xen_entry /* Xen hypervisor */
25301 - .long default_entry /* Moorestown MID */
25302 + .long ta(default_entry) /* normal x86/PC */
25303 + .long ta(lguest_entry) /* lguest hypervisor */
25304 + .long ta(xen_entry) /* Xen hypervisor */
25305 + .long ta(default_entry) /* Moorestown MID */
25306 num_subarch_entries = (. - subarch_entries) / 4
25307 .previous
25308 #else
25309 @@ -354,6 +426,7 @@ default_entry:
25310 movl pa(mmu_cr4_features),%eax
25311 movl %eax,%cr4
25312
25313 +#ifdef CONFIG_X86_PAE
25314 testb $X86_CR4_PAE, %al # check if PAE is enabled
25315 jz enable_paging
25316
25317 @@ -382,6 +455,9 @@ default_entry:
25318 /* Make changes effective */
25319 wrmsr
25320
25321 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
25322 +#endif
25323 +
25324 enable_paging:
25325
25326 /*
25327 @@ -449,14 +525,20 @@ is486:
25328 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
25329 movl %eax,%ss # after changing gdt.
25330
25331 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
25332 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
25333 movl %eax,%ds
25334 movl %eax,%es
25335
25336 movl $(__KERNEL_PERCPU), %eax
25337 movl %eax,%fs # set this cpu's percpu
25338
25339 +#ifdef CONFIG_CC_STACKPROTECTOR
25340 movl $(__KERNEL_STACK_CANARY),%eax
25341 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
25342 + movl $(__USER_DS),%eax
25343 +#else
25344 + xorl %eax,%eax
25345 +#endif
25346 movl %eax,%gs
25347
25348 xorl %eax,%eax # Clear LDT
25349 @@ -512,8 +594,11 @@ setup_once:
25350 * relocation. Manually set base address in stack canary
25351 * segment descriptor.
25352 */
25353 - movl $gdt_page,%eax
25354 + movl $cpu_gdt_table,%eax
25355 movl $stack_canary,%ecx
25356 +#ifdef CONFIG_SMP
25357 + addl $__per_cpu_load,%ecx
25358 +#endif
25359 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
25360 shrl $16, %ecx
25361 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
25362 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
25363 cmpl $2,(%esp) # X86_TRAP_NMI
25364 je is_nmi # Ignore NMI
25365
25366 - cmpl $2,%ss:early_recursion_flag
25367 + cmpl $1,%ss:early_recursion_flag
25368 je hlt_loop
25369 incl %ss:early_recursion_flag
25370
25371 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
25372 pushl (20+6*4)(%esp) /* trapno */
25373 pushl $fault_msg
25374 call printk
25375 -#endif
25376 call dump_stack
25377 +#endif
25378 hlt_loop:
25379 hlt
25380 jmp hlt_loop
25381 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
25382 /* This is the default interrupt "handler" :-) */
25383 ALIGN
25384 ignore_int:
25385 - cld
25386 #ifdef CONFIG_PRINTK
25387 + cmpl $2,%ss:early_recursion_flag
25388 + je hlt_loop
25389 + incl %ss:early_recursion_flag
25390 + cld
25391 pushl %eax
25392 pushl %ecx
25393 pushl %edx
25394 @@ -617,9 +705,6 @@ ignore_int:
25395 movl $(__KERNEL_DS),%eax
25396 movl %eax,%ds
25397 movl %eax,%es
25398 - cmpl $2,early_recursion_flag
25399 - je hlt_loop
25400 - incl early_recursion_flag
25401 pushl 16(%esp)
25402 pushl 24(%esp)
25403 pushl 32(%esp)
25404 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
25405 /*
25406 * BSS section
25407 */
25408 -__PAGE_ALIGNED_BSS
25409 - .align PAGE_SIZE
25410 #ifdef CONFIG_X86_PAE
25411 +.section .initial_pg_pmd,"a",@progbits
25412 initial_pg_pmd:
25413 .fill 1024*KPMDS,4,0
25414 #else
25415 +.section .initial_page_table,"a",@progbits
25416 ENTRY(initial_page_table)
25417 .fill 1024,4,0
25418 #endif
25419 +.section .initial_pg_fixmap,"a",@progbits
25420 initial_pg_fixmap:
25421 .fill 1024,4,0
25422 +.section .empty_zero_page,"a",@progbits
25423 ENTRY(empty_zero_page)
25424 .fill 4096,1,0
25425 +.section .swapper_pg_dir,"a",@progbits
25426 ENTRY(swapper_pg_dir)
25427 +#ifdef CONFIG_X86_PAE
25428 + .fill 4,8,0
25429 +#else
25430 .fill 1024,4,0
25431 +#endif
25432
25433 /*
25434 * This starts the data section.
25435 */
25436 #ifdef CONFIG_X86_PAE
25437 -__PAGE_ALIGNED_DATA
25438 - /* Page-aligned for the benefit of paravirt? */
25439 - .align PAGE_SIZE
25440 +.section .initial_page_table,"a",@progbits
25441 ENTRY(initial_page_table)
25442 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
25443 # if KPMDS == 3
25444 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
25445 # error "Kernel PMDs should be 1, 2 or 3"
25446 # endif
25447 .align PAGE_SIZE /* needs to be page-sized too */
25448 +
25449 +#ifdef CONFIG_PAX_PER_CPU_PGD
25450 +ENTRY(cpu_pgd)
25451 + .rept 2*NR_CPUS
25452 + .fill 4,8,0
25453 + .endr
25454 +#endif
25455 +
25456 #endif
25457
25458 .data
25459 .balign 4
25460 ENTRY(stack_start)
25461 - .long init_thread_union+THREAD_SIZE
25462 + .long init_thread_union+THREAD_SIZE-8
25463
25464 __INITRODATA
25465 int_msg:
25466 @@ -727,7 +825,7 @@ fault_msg:
25467 * segment size, and 32-bit linear address value:
25468 */
25469
25470 - .data
25471 +.section .rodata,"a",@progbits
25472 .globl boot_gdt_descr
25473 .globl idt_descr
25474
25475 @@ -736,7 +834,7 @@ fault_msg:
25476 .word 0 # 32 bit align gdt_desc.address
25477 boot_gdt_descr:
25478 .word __BOOT_DS+7
25479 - .long boot_gdt - __PAGE_OFFSET
25480 + .long pa(boot_gdt)
25481
25482 .word 0 # 32-bit align idt_desc.address
25483 idt_descr:
25484 @@ -747,7 +845,7 @@ idt_descr:
25485 .word 0 # 32 bit align gdt_desc.address
25486 ENTRY(early_gdt_descr)
25487 .word GDT_ENTRIES*8-1
25488 - .long gdt_page /* Overwritten for secondary CPUs */
25489 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
25490
25491 /*
25492 * The boot_gdt must mirror the equivalent in setup.S and is
25493 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
25494 .align L1_CACHE_BYTES
25495 ENTRY(boot_gdt)
25496 .fill GDT_ENTRY_BOOT_CS,8,0
25497 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
25498 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
25499 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
25500 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
25501 +
25502 + .align PAGE_SIZE_asm
25503 +ENTRY(cpu_gdt_table)
25504 + .rept NR_CPUS
25505 + .quad 0x0000000000000000 /* NULL descriptor */
25506 + .quad 0x0000000000000000 /* 0x0b reserved */
25507 + .quad 0x0000000000000000 /* 0x13 reserved */
25508 + .quad 0x0000000000000000 /* 0x1b reserved */
25509 +
25510 +#ifdef CONFIG_PAX_KERNEXEC
25511 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25512 +#else
25513 + .quad 0x0000000000000000 /* 0x20 unused */
25514 +#endif
25515 +
25516 + .quad 0x0000000000000000 /* 0x28 unused */
25517 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25518 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25519 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25520 + .quad 0x0000000000000000 /* 0x4b reserved */
25521 + .quad 0x0000000000000000 /* 0x53 reserved */
25522 + .quad 0x0000000000000000 /* 0x5b reserved */
25523 +
25524 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25525 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25526 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25527 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25528 +
25529 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25530 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25531 +
25532 + /*
25533 + * Segments used for calling PnP BIOS have byte granularity.
25534 + * The code segments and data segments have fixed 64k limits,
25535 + * the transfer segment sizes are set at run time.
25536 + */
25537 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
25538 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
25539 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
25540 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
25541 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
25542 +
25543 + /*
25544 + * The APM segments have byte granularity and their bases
25545 + * are set at run time. All have 64k limits.
25546 + */
25547 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25548 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25549 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
25550 +
25551 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25552 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25553 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25554 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25555 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25556 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25557 +
25558 + /* Be sure this is zeroed to avoid false validations in Xen */
25559 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25560 + .endr
25561 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25562 index a468c0a..8b5a879 100644
25563 --- a/arch/x86/kernel/head_64.S
25564 +++ b/arch/x86/kernel/head_64.S
25565 @@ -20,6 +20,8 @@
25566 #include <asm/processor-flags.h>
25567 #include <asm/percpu.h>
25568 #include <asm/nops.h>
25569 +#include <asm/cpufeature.h>
25570 +#include <asm/alternative-asm.h>
25571
25572 #ifdef CONFIG_PARAVIRT
25573 #include <asm/asm-offsets.h>
25574 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25575 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25576 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25577 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25578 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
25579 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25580 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25581 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25582 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25583 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25584
25585 .text
25586 __HEAD
25587 @@ -89,11 +97,24 @@ startup_64:
25588 * Fixup the physical addresses in the page table
25589 */
25590 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25591 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25592 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25593 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25594 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25595 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25596
25597 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25598 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25599 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25600 +#ifndef CONFIG_XEN
25601 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25602 +#endif
25603 +
25604 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25605 +
25606 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25607 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25608
25609 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25610 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25611
25612 /*
25613 * Set up the identity mapping for the switchover. These
25614 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25615 * after the boot processor executes this code.
25616 */
25617
25618 + orq $-1, %rbp
25619 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25620 1:
25621
25622 - /* Enable PAE mode and PGE */
25623 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25624 + /* Enable PAE mode and PSE/PGE */
25625 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25626 movq %rcx, %cr4
25627
25628 /* Setup early boot stage 4 level pagetables. */
25629 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25630 movl $MSR_EFER, %ecx
25631 rdmsr
25632 btsl $_EFER_SCE, %eax /* Enable System Call */
25633 - btl $20,%edi /* No Execute supported? */
25634 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25635 jnc 1f
25636 btsl $_EFER_NX, %eax
25637 + cmpq $-1, %rbp
25638 + je 1f
25639 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25640 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25641 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25642 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25643 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25644 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25645 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25646 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25647 1: wrmsr /* Make changes effective */
25648
25649 /* Setup cr0 */
25650 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25651 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25652 * address given in m16:64.
25653 */
25654 + pax_set_fptr_mask
25655 movq initial_code(%rip),%rax
25656 pushq $0 # fake return address to stop unwinder
25657 pushq $__KERNEL_CS # set correct cs
25658 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25659 .quad INIT_PER_CPU_VAR(irq_stack_union)
25660
25661 GLOBAL(stack_start)
25662 - .quad init_thread_union+THREAD_SIZE-8
25663 + .quad init_thread_union+THREAD_SIZE-16
25664 .word 0
25665 __FINITDATA
25666
25667 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25668 call dump_stack
25669 #ifdef CONFIG_KALLSYMS
25670 leaq early_idt_ripmsg(%rip),%rdi
25671 - movq 40(%rsp),%rsi # %rip again
25672 + movq 88(%rsp),%rsi # %rip again
25673 call __print_symbol
25674 #endif
25675 #endif /* EARLY_PRINTK */
25676 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25677 early_recursion_flag:
25678 .long 0
25679
25680 + .section .rodata,"a",@progbits
25681 #ifdef CONFIG_EARLY_PRINTK
25682 early_idt_msg:
25683 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25684 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25685 NEXT_PAGE(early_dynamic_pgts)
25686 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25687
25688 - .data
25689 + .section .rodata,"a",@progbits
25690
25691 -#ifndef CONFIG_XEN
25692 NEXT_PAGE(init_level4_pgt)
25693 - .fill 512,8,0
25694 -#else
25695 -NEXT_PAGE(init_level4_pgt)
25696 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25697 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25698 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25699 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25700 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25701 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25702 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25703 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25704 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25705 .org init_level4_pgt + L4_START_KERNEL*8, 0
25706 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25707 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25708
25709 +#ifdef CONFIG_PAX_PER_CPU_PGD
25710 +NEXT_PAGE(cpu_pgd)
25711 + .rept 2*NR_CPUS
25712 + .fill 512,8,0
25713 + .endr
25714 +#endif
25715 +
25716 NEXT_PAGE(level3_ident_pgt)
25717 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25718 +#ifdef CONFIG_XEN
25719 .fill 511, 8, 0
25720 +#else
25721 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25722 + .fill 510,8,0
25723 +#endif
25724 +
25725 +NEXT_PAGE(level3_vmalloc_start_pgt)
25726 + .fill 512,8,0
25727 +
25728 +NEXT_PAGE(level3_vmalloc_end_pgt)
25729 + .fill 512,8,0
25730 +
25731 +NEXT_PAGE(level3_vmemmap_pgt)
25732 + .fill L3_VMEMMAP_START,8,0
25733 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25734 +
25735 NEXT_PAGE(level2_ident_pgt)
25736 - /* Since I easily can, map the first 1G.
25737 + /* Since I easily can, map the first 2G.
25738 * Don't set NX because code runs from these pages.
25739 */
25740 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25741 -#endif
25742 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25743
25744 NEXT_PAGE(level3_kernel_pgt)
25745 .fill L3_START_KERNEL,8,0
25746 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25747 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25748 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25749
25750 +NEXT_PAGE(level2_vmemmap_pgt)
25751 + .fill 512,8,0
25752 +
25753 NEXT_PAGE(level2_kernel_pgt)
25754 /*
25755 * 512 MB kernel mapping. We spend a full page on this pagetable
25756 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25757 NEXT_PAGE(level2_fixmap_pgt)
25758 .fill 506,8,0
25759 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25760 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25761 - .fill 5,8,0
25762 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25763 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25764 + .fill 4,8,0
25765
25766 NEXT_PAGE(level1_fixmap_pgt)
25767 .fill 512,8,0
25768
25769 +NEXT_PAGE(level1_vsyscall_pgt)
25770 + .fill 512,8,0
25771 +
25772 #undef PMDS
25773
25774 - .data
25775 + .align PAGE_SIZE
25776 +ENTRY(cpu_gdt_table)
25777 + .rept NR_CPUS
25778 + .quad 0x0000000000000000 /* NULL descriptor */
25779 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25780 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25781 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25782 + .quad 0x00cffb000000ffff /* __USER32_CS */
25783 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25784 + .quad 0x00affb000000ffff /* __USER_CS */
25785 +
25786 +#ifdef CONFIG_PAX_KERNEXEC
25787 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25788 +#else
25789 + .quad 0x0 /* unused */
25790 +#endif
25791 +
25792 + .quad 0,0 /* TSS */
25793 + .quad 0,0 /* LDT */
25794 + .quad 0,0,0 /* three TLS descriptors */
25795 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25796 + /* asm/segment.h:GDT_ENTRIES must match this */
25797 +
25798 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25799 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25800 +#else
25801 + .quad 0x0 /* unused */
25802 +#endif
25803 +
25804 + /* zero the remaining page */
25805 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25806 + .endr
25807 +
25808 .align 16
25809 .globl early_gdt_descr
25810 early_gdt_descr:
25811 .word GDT_ENTRIES*8-1
25812 early_gdt_descr_base:
25813 - .quad INIT_PER_CPU_VAR(gdt_page)
25814 + .quad cpu_gdt_table
25815
25816 ENTRY(phys_base)
25817 /* This must match the first entry in level2_kernel_pgt */
25818 .quad 0x0000000000000000
25819
25820 #include "../../x86/xen/xen-head.S"
25821 -
25822 - __PAGE_ALIGNED_BSS
25823 +
25824 + .section .rodata,"a",@progbits
25825 NEXT_PAGE(empty_zero_page)
25826 .skip PAGE_SIZE
25827 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25828 index 05fd74f..c3548b1 100644
25829 --- a/arch/x86/kernel/i386_ksyms_32.c
25830 +++ b/arch/x86/kernel/i386_ksyms_32.c
25831 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25832 EXPORT_SYMBOL(cmpxchg8b_emu);
25833 #endif
25834
25835 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25836 +
25837 /* Networking helper routines. */
25838 EXPORT_SYMBOL(csum_partial_copy_generic);
25839 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25840 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25841
25842 EXPORT_SYMBOL(__get_user_1);
25843 EXPORT_SYMBOL(__get_user_2);
25844 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25845 EXPORT_SYMBOL(___preempt_schedule_context);
25846 #endif
25847 #endif
25848 +
25849 +#ifdef CONFIG_PAX_KERNEXEC
25850 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25851 +#endif
25852 +
25853 +#ifdef CONFIG_PAX_PER_CPU_PGD
25854 +EXPORT_SYMBOL(cpu_pgd);
25855 +#endif
25856 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25857 index a9a4229..6f4d476 100644
25858 --- a/arch/x86/kernel/i387.c
25859 +++ b/arch/x86/kernel/i387.c
25860 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25861 static inline bool interrupted_user_mode(void)
25862 {
25863 struct pt_regs *regs = get_irq_regs();
25864 - return regs && user_mode_vm(regs);
25865 + return regs && user_mode(regs);
25866 }
25867
25868 /*
25869 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25870 index 8af8171..f8c1169 100644
25871 --- a/arch/x86/kernel/i8259.c
25872 +++ b/arch/x86/kernel/i8259.c
25873 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25874 static void make_8259A_irq(unsigned int irq)
25875 {
25876 disable_irq_nosync(irq);
25877 - io_apic_irqs &= ~(1<<irq);
25878 + io_apic_irqs &= ~(1UL<<irq);
25879 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25880 i8259A_chip.name);
25881 enable_irq(irq);
25882 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25883 "spurious 8259A interrupt: IRQ%d.\n", irq);
25884 spurious_irq_mask |= irqmask;
25885 }
25886 - atomic_inc(&irq_err_count);
25887 + atomic_inc_unchecked(&irq_err_count);
25888 /*
25889 * Theoretically we do not have to handle this IRQ,
25890 * but in Linux this does not cause problems and is
25891 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25892 /* (slave's support for AEOI in flat mode is to be investigated) */
25893 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25894
25895 + pax_open_kernel();
25896 if (auto_eoi)
25897 /*
25898 * In AEOI mode we just have to mask the interrupt
25899 * when acking.
25900 */
25901 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25902 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25903 else
25904 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25905 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25906 + pax_close_kernel();
25907
25908 udelay(100); /* wait for 8259A to initialize */
25909
25910 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25911 index a979b5b..1d6db75 100644
25912 --- a/arch/x86/kernel/io_delay.c
25913 +++ b/arch/x86/kernel/io_delay.c
25914 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25915 * Quirk table for systems that misbehave (lock up, etc.) if port
25916 * 0x80 is used:
25917 */
25918 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25919 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25920 {
25921 .callback = dmi_io_delay_0xed_port,
25922 .ident = "Compaq Presario V6000",
25923 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25924 index 4ddaf66..49d5c18 100644
25925 --- a/arch/x86/kernel/ioport.c
25926 +++ b/arch/x86/kernel/ioport.c
25927 @@ -6,6 +6,7 @@
25928 #include <linux/sched.h>
25929 #include <linux/kernel.h>
25930 #include <linux/capability.h>
25931 +#include <linux/security.h>
25932 #include <linux/errno.h>
25933 #include <linux/types.h>
25934 #include <linux/ioport.h>
25935 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25936 return -EINVAL;
25937 if (turn_on && !capable(CAP_SYS_RAWIO))
25938 return -EPERM;
25939 +#ifdef CONFIG_GRKERNSEC_IO
25940 + if (turn_on && grsec_disable_privio) {
25941 + gr_handle_ioperm();
25942 + return -ENODEV;
25943 + }
25944 +#endif
25945
25946 /*
25947 * If it's the first ioperm() call in this thread's lifetime, set the
25948 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25949 * because the ->io_bitmap_max value must match the bitmap
25950 * contents:
25951 */
25952 - tss = &per_cpu(init_tss, get_cpu());
25953 + tss = init_tss + get_cpu();
25954
25955 if (turn_on)
25956 bitmap_clear(t->io_bitmap_ptr, from, num);
25957 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25958 if (level > old) {
25959 if (!capable(CAP_SYS_RAWIO))
25960 return -EPERM;
25961 +#ifdef CONFIG_GRKERNSEC_IO
25962 + if (grsec_disable_privio) {
25963 + gr_handle_iopl();
25964 + return -ENODEV;
25965 + }
25966 +#endif
25967 }
25968 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25969 t->iopl = level << 12;
25970 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25971 index 922d285..6d20692 100644
25972 --- a/arch/x86/kernel/irq.c
25973 +++ b/arch/x86/kernel/irq.c
25974 @@ -22,7 +22,7 @@
25975 #define CREATE_TRACE_POINTS
25976 #include <asm/trace/irq_vectors.h>
25977
25978 -atomic_t irq_err_count;
25979 +atomic_unchecked_t irq_err_count;
25980
25981 /* Function pointer for generic interrupt vector handling */
25982 void (*x86_platform_ipi_callback)(void) = NULL;
25983 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25984 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25985 seq_printf(p, " Hypervisor callback interrupts\n");
25986 #endif
25987 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25988 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25989 #if defined(CONFIG_X86_IO_APIC)
25990 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25991 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25992 #endif
25993 return 0;
25994 }
25995 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25996
25997 u64 arch_irq_stat(void)
25998 {
25999 - u64 sum = atomic_read(&irq_err_count);
26000 + u64 sum = atomic_read_unchecked(&irq_err_count);
26001 return sum;
26002 }
26003
26004 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
26005 index 63ce838..2ea3e06 100644
26006 --- a/arch/x86/kernel/irq_32.c
26007 +++ b/arch/x86/kernel/irq_32.c
26008 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
26009
26010 #ifdef CONFIG_DEBUG_STACKOVERFLOW
26011
26012 +extern void gr_handle_kernel_exploit(void);
26013 +
26014 int sysctl_panic_on_stackoverflow __read_mostly;
26015
26016 /* Debugging check for stack overflow: is there less than 1KB free? */
26017 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
26018 __asm__ __volatile__("andl %%esp,%0" :
26019 "=r" (sp) : "0" (THREAD_SIZE - 1));
26020
26021 - return sp < (sizeof(struct thread_info) + STACK_WARN);
26022 + return sp < STACK_WARN;
26023 }
26024
26025 static void print_stack_overflow(void)
26026 {
26027 printk(KERN_WARNING "low stack detected by irq handler\n");
26028 dump_stack();
26029 + gr_handle_kernel_exploit();
26030 if (sysctl_panic_on_stackoverflow)
26031 panic("low stack detected by irq handler - check messages\n");
26032 }
26033 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
26034 static inline int
26035 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26036 {
26037 - struct irq_stack *curstk, *irqstk;
26038 + struct irq_stack *irqstk;
26039 u32 *isp, *prev_esp, arg1, arg2;
26040
26041 - curstk = (struct irq_stack *) current_stack();
26042 irqstk = __this_cpu_read(hardirq_stack);
26043
26044 /*
26045 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26046 * handler) we can't do that and just have to keep using the
26047 * current stack (which is the irq stack already after all)
26048 */
26049 - if (unlikely(curstk == irqstk))
26050 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
26051 return 0;
26052
26053 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
26054 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
26055
26056 /* Save the next esp at the bottom of the stack */
26057 prev_esp = (u32 *)irqstk;
26058 *prev_esp = current_stack_pointer;
26059
26060 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26061 + __set_fs(MAKE_MM_SEG(0));
26062 +#endif
26063 +
26064 if (unlikely(overflow))
26065 call_on_stack(print_stack_overflow, isp);
26066
26067 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26068 : "0" (irq), "1" (desc), "2" (isp),
26069 "D" (desc->handle_irq)
26070 : "memory", "cc", "ecx");
26071 +
26072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26073 + __set_fs(current_thread_info()->addr_limit);
26074 +#endif
26075 +
26076 return 1;
26077 }
26078
26079 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26080 */
26081 void irq_ctx_init(int cpu)
26082 {
26083 - struct irq_stack *irqstk;
26084 -
26085 if (per_cpu(hardirq_stack, cpu))
26086 return;
26087
26088 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26089 - THREADINFO_GFP,
26090 - THREAD_SIZE_ORDER));
26091 - per_cpu(hardirq_stack, cpu) = irqstk;
26092 -
26093 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26094 - THREADINFO_GFP,
26095 - THREAD_SIZE_ORDER));
26096 - per_cpu(softirq_stack, cpu) = irqstk;
26097 -
26098 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
26099 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
26100 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26101 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26102 }
26103
26104 void do_softirq_own_stack(void)
26105 {
26106 - struct thread_info *curstk;
26107 struct irq_stack *irqstk;
26108 u32 *isp, *prev_esp;
26109
26110 - curstk = current_stack();
26111 irqstk = __this_cpu_read(softirq_stack);
26112
26113 /* build the stack frame on the softirq stack */
26114 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
26115 prev_esp = (u32 *)irqstk;
26116 *prev_esp = current_stack_pointer;
26117
26118 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26119 + __set_fs(MAKE_MM_SEG(0));
26120 +#endif
26121 +
26122 call_on_stack(__do_softirq, isp);
26123 +
26124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26125 + __set_fs(current_thread_info()->addr_limit);
26126 +#endif
26127 +
26128 }
26129
26130 bool handle_irq(unsigned irq, struct pt_regs *regs)
26131 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
26132 if (unlikely(!desc))
26133 return false;
26134
26135 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26136 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26137 if (unlikely(overflow))
26138 print_stack_overflow();
26139 desc->handle_irq(irq, desc);
26140 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
26141 index 4d1c746..55a22d6 100644
26142 --- a/arch/x86/kernel/irq_64.c
26143 +++ b/arch/x86/kernel/irq_64.c
26144 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
26145 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26146 EXPORT_PER_CPU_SYMBOL(irq_regs);
26147
26148 +extern void gr_handle_kernel_exploit(void);
26149 +
26150 int sysctl_panic_on_stackoverflow;
26151
26152 /*
26153 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26154 u64 estack_top, estack_bottom;
26155 u64 curbase = (u64)task_stack_page(current);
26156
26157 - if (user_mode_vm(regs))
26158 + if (user_mode(regs))
26159 return;
26160
26161 if (regs->sp >= curbase + sizeof(struct thread_info) +
26162 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26163 irq_stack_top, irq_stack_bottom,
26164 estack_top, estack_bottom);
26165
26166 + gr_handle_kernel_exploit();
26167 +
26168 if (sysctl_panic_on_stackoverflow)
26169 panic("low stack detected by irq handler - check messages\n");
26170 #endif
26171 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
26172 index 26d5a55..a01160a 100644
26173 --- a/arch/x86/kernel/jump_label.c
26174 +++ b/arch/x86/kernel/jump_label.c
26175 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26176 * Jump label is enabled for the first time.
26177 * So we expect a default_nop...
26178 */
26179 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
26180 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
26181 != 0))
26182 bug_at((void *)entry->code, __LINE__);
26183 } else {
26184 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26185 * ...otherwise expect an ideal_nop. Otherwise
26186 * something went horribly wrong.
26187 */
26188 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
26189 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
26190 != 0))
26191 bug_at((void *)entry->code, __LINE__);
26192 }
26193 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
26194 * are converting the default nop to the ideal nop.
26195 */
26196 if (init) {
26197 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
26198 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
26199 bug_at((void *)entry->code, __LINE__);
26200 } else {
26201 code.jump = 0xe9;
26202 code.offset = entry->target -
26203 (entry->code + JUMP_LABEL_NOP_SIZE);
26204 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
26205 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
26206 bug_at((void *)entry->code, __LINE__);
26207 }
26208 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
26209 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
26210 index 7ec1d5f..5a7d130 100644
26211 --- a/arch/x86/kernel/kgdb.c
26212 +++ b/arch/x86/kernel/kgdb.c
26213 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
26214 #ifdef CONFIG_X86_32
26215 switch (regno) {
26216 case GDB_SS:
26217 - if (!user_mode_vm(regs))
26218 + if (!user_mode(regs))
26219 *(unsigned long *)mem = __KERNEL_DS;
26220 break;
26221 case GDB_SP:
26222 - if (!user_mode_vm(regs))
26223 + if (!user_mode(regs))
26224 *(unsigned long *)mem = kernel_stack_pointer(regs);
26225 break;
26226 case GDB_GS:
26227 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
26228 bp->attr.bp_addr = breakinfo[breakno].addr;
26229 bp->attr.bp_len = breakinfo[breakno].len;
26230 bp->attr.bp_type = breakinfo[breakno].type;
26231 - info->address = breakinfo[breakno].addr;
26232 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
26233 + info->address = ktla_ktva(breakinfo[breakno].addr);
26234 + else
26235 + info->address = breakinfo[breakno].addr;
26236 info->len = breakinfo[breakno].len;
26237 info->type = breakinfo[breakno].type;
26238 val = arch_install_hw_breakpoint(bp);
26239 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
26240 case 'k':
26241 /* clear the trace bit */
26242 linux_regs->flags &= ~X86_EFLAGS_TF;
26243 - atomic_set(&kgdb_cpu_doing_single_step, -1);
26244 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
26245
26246 /* set the trace bit if we're stepping */
26247 if (remcomInBuffer[0] == 's') {
26248 linux_regs->flags |= X86_EFLAGS_TF;
26249 - atomic_set(&kgdb_cpu_doing_single_step,
26250 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
26251 raw_smp_processor_id());
26252 }
26253
26254 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
26255
26256 switch (cmd) {
26257 case DIE_DEBUG:
26258 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
26259 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
26260 if (user_mode(regs))
26261 return single_step_cont(regs, args);
26262 break;
26263 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26264 #endif /* CONFIG_DEBUG_RODATA */
26265
26266 bpt->type = BP_BREAKPOINT;
26267 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
26268 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
26269 BREAK_INSTR_SIZE);
26270 if (err)
26271 return err;
26272 - err = probe_kernel_write((char *)bpt->bpt_addr,
26273 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26274 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
26275 #ifdef CONFIG_DEBUG_RODATA
26276 if (!err)
26277 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26278 return -EBUSY;
26279 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
26280 BREAK_INSTR_SIZE);
26281 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26282 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26283 if (err)
26284 return err;
26285 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
26286 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
26287 if (mutex_is_locked(&text_mutex))
26288 goto knl_write;
26289 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
26290 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26291 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26292 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
26293 goto knl_write;
26294 return err;
26295 knl_write:
26296 #endif /* CONFIG_DEBUG_RODATA */
26297 - return probe_kernel_write((char *)bpt->bpt_addr,
26298 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26299 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
26300 }
26301
26302 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
26303 index 67e6d19..731ed28 100644
26304 --- a/arch/x86/kernel/kprobes/core.c
26305 +++ b/arch/x86/kernel/kprobes/core.c
26306 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
26307 s32 raddr;
26308 } __packed *insn;
26309
26310 - insn = (struct __arch_relative_insn *)from;
26311 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
26312 +
26313 + pax_open_kernel();
26314 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
26315 insn->op = op;
26316 + pax_close_kernel();
26317 }
26318
26319 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
26320 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
26321 kprobe_opcode_t opcode;
26322 kprobe_opcode_t *orig_opcodes = opcodes;
26323
26324 - if (search_exception_tables((unsigned long)opcodes))
26325 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
26326 return 0; /* Page fault may occur on this address. */
26327
26328 retry:
26329 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
26330 * for the first byte, we can recover the original instruction
26331 * from it and kp->opcode.
26332 */
26333 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26334 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26335 buf[0] = kp->opcode;
26336 - return (unsigned long)buf;
26337 + return ktva_ktla((unsigned long)buf);
26338 }
26339
26340 /*
26341 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26342 /* Another subsystem puts a breakpoint, failed to recover */
26343 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
26344 return 0;
26345 + pax_open_kernel();
26346 memcpy(dest, insn.kaddr, insn.length);
26347 + pax_close_kernel();
26348
26349 #ifdef CONFIG_X86_64
26350 if (insn_rip_relative(&insn)) {
26351 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26352 return 0;
26353 }
26354 disp = (u8 *) dest + insn_offset_displacement(&insn);
26355 + pax_open_kernel();
26356 *(s32 *) disp = (s32) newdisp;
26357 + pax_close_kernel();
26358 }
26359 #endif
26360 return insn.length;
26361 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26362 * nor set current_kprobe, because it doesn't use single
26363 * stepping.
26364 */
26365 - regs->ip = (unsigned long)p->ainsn.insn;
26366 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26367 preempt_enable_no_resched();
26368 return;
26369 }
26370 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26371 regs->flags &= ~X86_EFLAGS_IF;
26372 /* single step inline if the instruction is an int3 */
26373 if (p->opcode == BREAKPOINT_INSTRUCTION)
26374 - regs->ip = (unsigned long)p->addr;
26375 + regs->ip = ktla_ktva((unsigned long)p->addr);
26376 else
26377 - regs->ip = (unsigned long)p->ainsn.insn;
26378 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26379 }
26380 NOKPROBE_SYMBOL(setup_singlestep);
26381
26382 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26383 struct kprobe *p;
26384 struct kprobe_ctlblk *kcb;
26385
26386 - if (user_mode_vm(regs))
26387 + if (user_mode(regs))
26388 return 0;
26389
26390 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
26391 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26392 setup_singlestep(p, regs, kcb, 0);
26393 return 1;
26394 }
26395 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
26396 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
26397 /*
26398 * The breakpoint instruction was removed right
26399 * after we hit it. Another cpu has removed
26400 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
26401 " movq %rax, 152(%rsp)\n"
26402 RESTORE_REGS_STRING
26403 " popfq\n"
26404 +#ifdef KERNEXEC_PLUGIN
26405 + " btsq $63,(%rsp)\n"
26406 +#endif
26407 #else
26408 " pushf\n"
26409 SAVE_REGS_STRING
26410 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
26411 struct kprobe_ctlblk *kcb)
26412 {
26413 unsigned long *tos = stack_addr(regs);
26414 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
26415 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
26416 unsigned long orig_ip = (unsigned long)p->addr;
26417 kprobe_opcode_t *insn = p->ainsn.insn;
26418
26419 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
26420 struct die_args *args = data;
26421 int ret = NOTIFY_DONE;
26422
26423 - if (args->regs && user_mode_vm(args->regs))
26424 + if (args->regs && user_mode(args->regs))
26425 return ret;
26426
26427 if (val == DIE_GPF) {
26428 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
26429 index f1314d0..15f3154 100644
26430 --- a/arch/x86/kernel/kprobes/opt.c
26431 +++ b/arch/x86/kernel/kprobes/opt.c
26432 @@ -79,6 +79,7 @@ found:
26433 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
26434 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26435 {
26436 + pax_open_kernel();
26437 #ifdef CONFIG_X86_64
26438 *addr++ = 0x48;
26439 *addr++ = 0xbf;
26440 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26441 *addr++ = 0xb8;
26442 #endif
26443 *(unsigned long *)addr = val;
26444 + pax_close_kernel();
26445 }
26446
26447 asm (
26448 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26449 * Verify if the address gap is in 2GB range, because this uses
26450 * a relative jump.
26451 */
26452 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
26453 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
26454 if (abs(rel) > 0x7fffffff) {
26455 __arch_remove_optimized_kprobe(op, 0);
26456 return -ERANGE;
26457 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26458 op->optinsn.size = ret;
26459
26460 /* Copy arch-dep-instance from template */
26461 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
26462 + pax_open_kernel();
26463 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
26464 + pax_close_kernel();
26465
26466 /* Set probe information */
26467 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
26468
26469 /* Set probe function call */
26470 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
26471 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
26472
26473 /* Set returning jmp instruction at the tail of out-of-line buffer */
26474 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
26475 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
26476 (u8 *)op->kp.addr + op->optinsn.size);
26477
26478 flush_icache_range((unsigned long) buf,
26479 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
26480 WARN_ON(kprobe_disabled(&op->kp));
26481
26482 /* Backup instructions which will be replaced by jump address */
26483 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
26484 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
26485 RELATIVE_ADDR_SIZE);
26486
26487 insn_buf[0] = RELATIVEJUMP_OPCODE;
26488 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
26489 /* This kprobe is really able to run optimized path. */
26490 op = container_of(p, struct optimized_kprobe, kp);
26491 /* Detour through copied instructions */
26492 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
26493 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
26494 if (!reenter)
26495 reset_current_kprobe();
26496 preempt_enable_no_resched();
26497 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
26498 index c2bedae..25e7ab60 100644
26499 --- a/arch/x86/kernel/ksysfs.c
26500 +++ b/arch/x86/kernel/ksysfs.c
26501 @@ -184,7 +184,7 @@ out:
26502
26503 static struct kobj_attribute type_attr = __ATTR_RO(type);
26504
26505 -static struct bin_attribute data_attr = {
26506 +static bin_attribute_no_const data_attr __read_only = {
26507 .attr = {
26508 .name = "data",
26509 .mode = S_IRUGO,
26510 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26511 index c37886d..d851d32 100644
26512 --- a/arch/x86/kernel/ldt.c
26513 +++ b/arch/x86/kernel/ldt.c
26514 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26515 if (reload) {
26516 #ifdef CONFIG_SMP
26517 preempt_disable();
26518 - load_LDT(pc);
26519 + load_LDT_nolock(pc);
26520 if (!cpumask_equal(mm_cpumask(current->mm),
26521 cpumask_of(smp_processor_id())))
26522 smp_call_function(flush_ldt, current->mm, 1);
26523 preempt_enable();
26524 #else
26525 - load_LDT(pc);
26526 + load_LDT_nolock(pc);
26527 #endif
26528 }
26529 if (oldsize) {
26530 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26531 return err;
26532
26533 for (i = 0; i < old->size; i++)
26534 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26535 + write_ldt_entry(new->ldt, i, old->ldt + i);
26536 return 0;
26537 }
26538
26539 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26540 retval = copy_ldt(&mm->context, &old_mm->context);
26541 mutex_unlock(&old_mm->context.lock);
26542 }
26543 +
26544 + if (tsk == current) {
26545 + mm->context.vdso = 0;
26546 +
26547 +#ifdef CONFIG_X86_32
26548 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26549 + mm->context.user_cs_base = 0UL;
26550 + mm->context.user_cs_limit = ~0UL;
26551 +
26552 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26553 + cpus_clear(mm->context.cpu_user_cs_mask);
26554 +#endif
26555 +
26556 +#endif
26557 +#endif
26558 +
26559 + }
26560 +
26561 return retval;
26562 }
26563
26564 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26565 }
26566 }
26567
26568 +#ifdef CONFIG_PAX_SEGMEXEC
26569 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26570 + error = -EINVAL;
26571 + goto out_unlock;
26572 + }
26573 +#endif
26574 +
26575 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26576 error = -EINVAL;
26577 goto out_unlock;
26578 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26579 index 1667b1d..16492c5 100644
26580 --- a/arch/x86/kernel/machine_kexec_32.c
26581 +++ b/arch/x86/kernel/machine_kexec_32.c
26582 @@ -25,7 +25,7 @@
26583 #include <asm/cacheflush.h>
26584 #include <asm/debugreg.h>
26585
26586 -static void set_idt(void *newidt, __u16 limit)
26587 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26588 {
26589 struct desc_ptr curidt;
26590
26591 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26592 }
26593
26594
26595 -static void set_gdt(void *newgdt, __u16 limit)
26596 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26597 {
26598 struct desc_ptr curgdt;
26599
26600 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26601 }
26602
26603 control_page = page_address(image->control_code_page);
26604 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26605 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26606
26607 relocate_kernel_ptr = control_page;
26608 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26609 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26610 index c73aecf..4c63630 100644
26611 --- a/arch/x86/kernel/mcount_64.S
26612 +++ b/arch/x86/kernel/mcount_64.S
26613 @@ -7,7 +7,7 @@
26614 #include <linux/linkage.h>
26615 #include <asm/ptrace.h>
26616 #include <asm/ftrace.h>
26617 -
26618 +#include <asm/alternative-asm.h>
26619
26620 .code64
26621 .section .entry.text, "ax"
26622 @@ -24,8 +24,9 @@
26623 #ifdef CONFIG_DYNAMIC_FTRACE
26624
26625 ENTRY(function_hook)
26626 + pax_force_retaddr
26627 retq
26628 -END(function_hook)
26629 +ENDPROC(function_hook)
26630
26631 /* skip is set if stack has been adjusted */
26632 .macro ftrace_caller_setup skip=0
26633 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26634 #endif
26635
26636 GLOBAL(ftrace_stub)
26637 + pax_force_retaddr
26638 retq
26639 -END(ftrace_caller)
26640 +ENDPROC(ftrace_caller)
26641
26642 ENTRY(ftrace_regs_caller)
26643 /* Save the current flags before compare (in SS location)*/
26644 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26645 popfq
26646 jmp ftrace_stub
26647
26648 -END(ftrace_regs_caller)
26649 +ENDPROC(ftrace_regs_caller)
26650
26651
26652 #else /* ! CONFIG_DYNAMIC_FTRACE */
26653 @@ -145,6 +147,7 @@ ENTRY(function_hook)
26654 #endif
26655
26656 GLOBAL(ftrace_stub)
26657 + pax_force_retaddr
26658 retq
26659
26660 trace:
26661 @@ -158,12 +161,13 @@ trace:
26662 #endif
26663 subq $MCOUNT_INSN_SIZE, %rdi
26664
26665 + pax_force_fptr ftrace_trace_function
26666 call *ftrace_trace_function
26667
26668 MCOUNT_RESTORE_FRAME
26669
26670 jmp ftrace_stub
26671 -END(function_hook)
26672 +ENDPROC(function_hook)
26673 #endif /* CONFIG_DYNAMIC_FTRACE */
26674 #endif /* CONFIG_FUNCTION_TRACER */
26675
26676 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26677
26678 MCOUNT_RESTORE_FRAME
26679
26680 + pax_force_retaddr
26681 retq
26682 -END(ftrace_graph_caller)
26683 +ENDPROC(ftrace_graph_caller)
26684
26685 GLOBAL(return_to_handler)
26686 subq $24, %rsp
26687 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26688 movq 8(%rsp), %rdx
26689 movq (%rsp), %rax
26690 addq $24, %rsp
26691 + pax_force_fptr %rdi
26692 jmp *%rdi
26693 +ENDPROC(return_to_handler)
26694 #endif
26695 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26696 index e69f988..da078ea 100644
26697 --- a/arch/x86/kernel/module.c
26698 +++ b/arch/x86/kernel/module.c
26699 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26700 }
26701 #endif
26702
26703 -void *module_alloc(unsigned long size)
26704 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26705 {
26706 - if (PAGE_ALIGN(size) > MODULES_LEN)
26707 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26708 return NULL;
26709 return __vmalloc_node_range(size, 1,
26710 MODULES_VADDR + get_module_load_offset(),
26711 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26712 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26713 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26714 + prot, NUMA_NO_NODE,
26715 __builtin_return_address(0));
26716 }
26717
26718 +void *module_alloc(unsigned long size)
26719 +{
26720 +
26721 +#ifdef CONFIG_PAX_KERNEXEC
26722 + return __module_alloc(size, PAGE_KERNEL);
26723 +#else
26724 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26725 +#endif
26726 +
26727 +}
26728 +
26729 +#ifdef CONFIG_PAX_KERNEXEC
26730 +#ifdef CONFIG_X86_32
26731 +void *module_alloc_exec(unsigned long size)
26732 +{
26733 + struct vm_struct *area;
26734 +
26735 + if (size == 0)
26736 + return NULL;
26737 +
26738 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26739 +return area ? area->addr : NULL;
26740 +}
26741 +EXPORT_SYMBOL(module_alloc_exec);
26742 +
26743 +void module_free_exec(struct module *mod, void *module_region)
26744 +{
26745 + vunmap(module_region);
26746 +}
26747 +EXPORT_SYMBOL(module_free_exec);
26748 +#else
26749 +void module_free_exec(struct module *mod, void *module_region)
26750 +{
26751 + module_free(mod, module_region);
26752 +}
26753 +EXPORT_SYMBOL(module_free_exec);
26754 +
26755 +void *module_alloc_exec(unsigned long size)
26756 +{
26757 + return __module_alloc(size, PAGE_KERNEL_RX);
26758 +}
26759 +EXPORT_SYMBOL(module_alloc_exec);
26760 +#endif
26761 +#endif
26762 +
26763 #ifdef CONFIG_X86_32
26764 int apply_relocate(Elf32_Shdr *sechdrs,
26765 const char *strtab,
26766 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26767 unsigned int i;
26768 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26769 Elf32_Sym *sym;
26770 - uint32_t *location;
26771 + uint32_t *plocation, location;
26772
26773 DEBUGP("Applying relocate section %u to %u\n",
26774 relsec, sechdrs[relsec].sh_info);
26775 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26776 /* This is where to make the change */
26777 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26778 - + rel[i].r_offset;
26779 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26780 + location = (uint32_t)plocation;
26781 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26782 + plocation = ktla_ktva((void *)plocation);
26783 /* This is the symbol it is referring to. Note that all
26784 undefined symbols have been resolved. */
26785 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26786 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26787 switch (ELF32_R_TYPE(rel[i].r_info)) {
26788 case R_386_32:
26789 /* We add the value into the location given */
26790 - *location += sym->st_value;
26791 + pax_open_kernel();
26792 + *plocation += sym->st_value;
26793 + pax_close_kernel();
26794 break;
26795 case R_386_PC32:
26796 /* Add the value, subtract its position */
26797 - *location += sym->st_value - (uint32_t)location;
26798 + pax_open_kernel();
26799 + *plocation += sym->st_value - location;
26800 + pax_close_kernel();
26801 break;
26802 default:
26803 pr_err("%s: Unknown relocation: %u\n",
26804 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26805 case R_X86_64_NONE:
26806 break;
26807 case R_X86_64_64:
26808 + pax_open_kernel();
26809 *(u64 *)loc = val;
26810 + pax_close_kernel();
26811 break;
26812 case R_X86_64_32:
26813 + pax_open_kernel();
26814 *(u32 *)loc = val;
26815 + pax_close_kernel();
26816 if (val != *(u32 *)loc)
26817 goto overflow;
26818 break;
26819 case R_X86_64_32S:
26820 + pax_open_kernel();
26821 *(s32 *)loc = val;
26822 + pax_close_kernel();
26823 if ((s64)val != *(s32 *)loc)
26824 goto overflow;
26825 break;
26826 case R_X86_64_PC32:
26827 val -= (u64)loc;
26828 + pax_open_kernel();
26829 *(u32 *)loc = val;
26830 + pax_close_kernel();
26831 +
26832 #if 0
26833 if ((s64)val != *(s32 *)loc)
26834 goto overflow;
26835 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26836 index c9603ac..9f88728 100644
26837 --- a/arch/x86/kernel/msr.c
26838 +++ b/arch/x86/kernel/msr.c
26839 @@ -37,6 +37,7 @@
26840 #include <linux/notifier.h>
26841 #include <linux/uaccess.h>
26842 #include <linux/gfp.h>
26843 +#include <linux/grsecurity.h>
26844
26845 #include <asm/processor.h>
26846 #include <asm/msr.h>
26847 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26848 int err = 0;
26849 ssize_t bytes = 0;
26850
26851 +#ifdef CONFIG_GRKERNSEC_KMEM
26852 + gr_handle_msr_write();
26853 + return -EPERM;
26854 +#endif
26855 +
26856 if (count % 8)
26857 return -EINVAL; /* Invalid chunk size */
26858
26859 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26860 err = -EBADF;
26861 break;
26862 }
26863 +#ifdef CONFIG_GRKERNSEC_KMEM
26864 + gr_handle_msr_write();
26865 + return -EPERM;
26866 +#endif
26867 if (copy_from_user(&regs, uregs, sizeof regs)) {
26868 err = -EFAULT;
26869 break;
26870 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26871 return notifier_from_errno(err);
26872 }
26873
26874 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26875 +static struct notifier_block msr_class_cpu_notifier = {
26876 .notifier_call = msr_class_cpu_callback,
26877 };
26878
26879 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26880 index c3e985d..110a36a 100644
26881 --- a/arch/x86/kernel/nmi.c
26882 +++ b/arch/x86/kernel/nmi.c
26883 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26884
26885 static void nmi_max_handler(struct irq_work *w)
26886 {
26887 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26888 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26889 int remainder_ns, decimal_msecs;
26890 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26891 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26892
26893 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26894 decimal_msecs = remainder_ns / 1000;
26895
26896 printk_ratelimited(KERN_INFO
26897 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26898 - a->handler, whole_msecs, decimal_msecs);
26899 + n->action->handler, whole_msecs, decimal_msecs);
26900 }
26901
26902 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26903 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26904 delta = sched_clock() - delta;
26905 trace_nmi_handler(a->handler, (int)delta, thishandled);
26906
26907 - if (delta < nmi_longest_ns || delta < a->max_duration)
26908 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26909 continue;
26910
26911 - a->max_duration = delta;
26912 - irq_work_queue(&a->irq_work);
26913 + a->work->max_duration = delta;
26914 + irq_work_queue(&a->work->irq_work);
26915 }
26916
26917 rcu_read_unlock();
26918 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26919 }
26920 NOKPROBE_SYMBOL(nmi_handle);
26921
26922 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26923 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26924 {
26925 struct nmi_desc *desc = nmi_to_desc(type);
26926 unsigned long flags;
26927 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26928 if (!action->handler)
26929 return -EINVAL;
26930
26931 - init_irq_work(&action->irq_work, nmi_max_handler);
26932 + action->work->action = action;
26933 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26934
26935 spin_lock_irqsave(&desc->lock, flags);
26936
26937 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26938 * event confuses some handlers (kdump uses this flag)
26939 */
26940 if (action->flags & NMI_FLAG_FIRST)
26941 - list_add_rcu(&action->list, &desc->head);
26942 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26943 else
26944 - list_add_tail_rcu(&action->list, &desc->head);
26945 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26946
26947 spin_unlock_irqrestore(&desc->lock, flags);
26948 return 0;
26949 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26950 if (!strcmp(n->name, name)) {
26951 WARN(in_nmi(),
26952 "Trying to free NMI (%s) from NMI context!\n", n->name);
26953 - list_del_rcu(&n->list);
26954 + pax_list_del_rcu((struct list_head *)&n->list);
26955 break;
26956 }
26957 }
26958 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26959 dotraplinkage notrace void
26960 do_nmi(struct pt_regs *regs, long error_code)
26961 {
26962 +
26963 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26964 + if (!user_mode(regs)) {
26965 + unsigned long cs = regs->cs & 0xFFFF;
26966 + unsigned long ip = ktva_ktla(regs->ip);
26967 +
26968 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26969 + regs->ip = ip;
26970 + }
26971 +#endif
26972 +
26973 nmi_nesting_preprocess(regs);
26974
26975 nmi_enter();
26976 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26977 index 6d9582e..f746287 100644
26978 --- a/arch/x86/kernel/nmi_selftest.c
26979 +++ b/arch/x86/kernel/nmi_selftest.c
26980 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26981 {
26982 /* trap all the unknown NMIs we may generate */
26983 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26984 - __initdata);
26985 + __initconst);
26986 }
26987
26988 static void __init cleanup_nmi_testsuite(void)
26989 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26990 unsigned long timeout;
26991
26992 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26993 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26994 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26995 nmi_fail = FAILURE;
26996 return;
26997 }
26998 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26999 index bbb6c73..24a58ef 100644
27000 --- a/arch/x86/kernel/paravirt-spinlocks.c
27001 +++ b/arch/x86/kernel/paravirt-spinlocks.c
27002 @@ -8,7 +8,7 @@
27003
27004 #include <asm/paravirt.h>
27005
27006 -struct pv_lock_ops pv_lock_ops = {
27007 +struct pv_lock_ops pv_lock_ops __read_only = {
27008 #ifdef CONFIG_SMP
27009 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
27010 .unlock_kick = paravirt_nop,
27011 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
27012 index 548d25f..f8fb99c 100644
27013 --- a/arch/x86/kernel/paravirt.c
27014 +++ b/arch/x86/kernel/paravirt.c
27015 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
27016 {
27017 return x;
27018 }
27019 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27020 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
27021 +#endif
27022
27023 void __init default_banner(void)
27024 {
27025 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
27026
27027 if (opfunc == NULL)
27028 /* If there's no function, patch it with a ud2a (BUG) */
27029 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
27030 - else if (opfunc == _paravirt_nop)
27031 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
27032 + else if (opfunc == (void *)_paravirt_nop)
27033 /* If the operation is a nop, then nop the callsite */
27034 ret = paravirt_patch_nop();
27035
27036 /* identity functions just return their single argument */
27037 - else if (opfunc == _paravirt_ident_32)
27038 + else if (opfunc == (void *)_paravirt_ident_32)
27039 ret = paravirt_patch_ident_32(insnbuf, len);
27040 - else if (opfunc == _paravirt_ident_64)
27041 + else if (opfunc == (void *)_paravirt_ident_64)
27042 ret = paravirt_patch_ident_64(insnbuf, len);
27043 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27044 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
27045 + ret = paravirt_patch_ident_64(insnbuf, len);
27046 +#endif
27047
27048 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
27049 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
27050 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
27051 if (insn_len > len || start == NULL)
27052 insn_len = len;
27053 else
27054 - memcpy(insnbuf, start, insn_len);
27055 + memcpy(insnbuf, ktla_ktva(start), insn_len);
27056
27057 return insn_len;
27058 }
27059 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
27060 return this_cpu_read(paravirt_lazy_mode);
27061 }
27062
27063 -struct pv_info pv_info = {
27064 +struct pv_info pv_info __read_only = {
27065 .name = "bare hardware",
27066 .paravirt_enabled = 0,
27067 .kernel_rpl = 0,
27068 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
27069 #endif
27070 };
27071
27072 -struct pv_init_ops pv_init_ops = {
27073 +struct pv_init_ops pv_init_ops __read_only = {
27074 .patch = native_patch,
27075 };
27076
27077 -struct pv_time_ops pv_time_ops = {
27078 +struct pv_time_ops pv_time_ops __read_only = {
27079 .sched_clock = native_sched_clock,
27080 .steal_clock = native_steal_clock,
27081 };
27082
27083 -__visible struct pv_irq_ops pv_irq_ops = {
27084 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
27085 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
27086 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
27087 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
27088 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
27089 #endif
27090 };
27091
27092 -__visible struct pv_cpu_ops pv_cpu_ops = {
27093 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
27094 .cpuid = native_cpuid,
27095 .get_debugreg = native_get_debugreg,
27096 .set_debugreg = native_set_debugreg,
27097 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
27098 NOKPROBE_SYMBOL(native_set_debugreg);
27099 NOKPROBE_SYMBOL(native_load_idt);
27100
27101 -struct pv_apic_ops pv_apic_ops = {
27102 +struct pv_apic_ops pv_apic_ops __read_only= {
27103 #ifdef CONFIG_X86_LOCAL_APIC
27104 .startup_ipi_hook = paravirt_nop,
27105 #endif
27106 };
27107
27108 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
27109 +#ifdef CONFIG_X86_32
27110 +#ifdef CONFIG_X86_PAE
27111 +/* 64-bit pagetable entries */
27112 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
27113 +#else
27114 /* 32-bit pagetable entries */
27115 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
27116 +#endif
27117 #else
27118 /* 64-bit pagetable entries */
27119 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
27120 #endif
27121
27122 -struct pv_mmu_ops pv_mmu_ops = {
27123 +struct pv_mmu_ops pv_mmu_ops __read_only = {
27124
27125 .read_cr2 = native_read_cr2,
27126 .write_cr2 = native_write_cr2,
27127 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
27128 .make_pud = PTE_IDENT,
27129
27130 .set_pgd = native_set_pgd,
27131 + .set_pgd_batched = native_set_pgd_batched,
27132 #endif
27133 #endif /* PAGETABLE_LEVELS >= 3 */
27134
27135 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
27136 },
27137
27138 .set_fixmap = native_set_fixmap,
27139 +
27140 +#ifdef CONFIG_PAX_KERNEXEC
27141 + .pax_open_kernel = native_pax_open_kernel,
27142 + .pax_close_kernel = native_pax_close_kernel,
27143 +#endif
27144 +
27145 };
27146
27147 EXPORT_SYMBOL_GPL(pv_time_ops);
27148 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
27149 index 0497f71..7186c0d 100644
27150 --- a/arch/x86/kernel/pci-calgary_64.c
27151 +++ b/arch/x86/kernel/pci-calgary_64.c
27152 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
27153 tce_space = be64_to_cpu(readq(target));
27154 tce_space = tce_space & TAR_SW_BITS;
27155
27156 - tce_space = tce_space & (~specified_table_size);
27157 + tce_space = tce_space & (~(unsigned long)specified_table_size);
27158 info->tce_space = (u64 *)__va(tce_space);
27159 }
27160 }
27161 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
27162 index 35ccf75..7a15747 100644
27163 --- a/arch/x86/kernel/pci-iommu_table.c
27164 +++ b/arch/x86/kernel/pci-iommu_table.c
27165 @@ -2,7 +2,7 @@
27166 #include <asm/iommu_table.h>
27167 #include <linux/string.h>
27168 #include <linux/kallsyms.h>
27169 -
27170 +#include <linux/sched.h>
27171
27172 #define DEBUG 1
27173
27174 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
27175 index 77dd0ad..9ec4723 100644
27176 --- a/arch/x86/kernel/pci-swiotlb.c
27177 +++ b/arch/x86/kernel/pci-swiotlb.c
27178 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
27179 struct dma_attrs *attrs)
27180 {
27181 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
27182 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
27183 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
27184 else
27185 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
27186 }
27187 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
27188 index ca7f0d5..8996469 100644
27189 --- a/arch/x86/kernel/preempt.S
27190 +++ b/arch/x86/kernel/preempt.S
27191 @@ -3,12 +3,14 @@
27192 #include <asm/dwarf2.h>
27193 #include <asm/asm.h>
27194 #include <asm/calling.h>
27195 +#include <asm/alternative-asm.h>
27196
27197 ENTRY(___preempt_schedule)
27198 CFI_STARTPROC
27199 SAVE_ALL
27200 call preempt_schedule
27201 RESTORE_ALL
27202 + pax_force_retaddr
27203 ret
27204 CFI_ENDPROC
27205
27206 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
27207 SAVE_ALL
27208 call preempt_schedule_context
27209 RESTORE_ALL
27210 + pax_force_retaddr
27211 ret
27212 CFI_ENDPROC
27213
27214 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
27215 index f804dc9..7c62095 100644
27216 --- a/arch/x86/kernel/process.c
27217 +++ b/arch/x86/kernel/process.c
27218 @@ -36,7 +36,8 @@
27219 * section. Since TSS's are completely CPU-local, we want them
27220 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
27221 */
27222 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
27223 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
27224 +EXPORT_SYMBOL(init_tss);
27225
27226 #ifdef CONFIG_X86_64
27227 static DEFINE_PER_CPU(unsigned char, is_idle);
27228 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
27229 task_xstate_cachep =
27230 kmem_cache_create("task_xstate", xstate_size,
27231 __alignof__(union thread_xstate),
27232 - SLAB_PANIC | SLAB_NOTRACK, NULL);
27233 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
27234 setup_xstate_comp();
27235 }
27236
27237 @@ -106,7 +107,7 @@ void exit_thread(void)
27238 unsigned long *bp = t->io_bitmap_ptr;
27239
27240 if (bp) {
27241 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
27242 + struct tss_struct *tss = init_tss + get_cpu();
27243
27244 t->io_bitmap_ptr = NULL;
27245 clear_thread_flag(TIF_IO_BITMAP);
27246 @@ -126,6 +127,9 @@ void flush_thread(void)
27247 {
27248 struct task_struct *tsk = current;
27249
27250 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
27251 + loadsegment(gs, 0);
27252 +#endif
27253 flush_ptrace_hw_breakpoint(tsk);
27254 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
27255 drop_init_fpu(tsk);
27256 @@ -272,7 +276,7 @@ static void __exit_idle(void)
27257 void exit_idle(void)
27258 {
27259 /* idle loop has pid 0 */
27260 - if (current->pid)
27261 + if (task_pid_nr(current))
27262 return;
27263 __exit_idle();
27264 }
27265 @@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
27266 return ret;
27267 }
27268 #endif
27269 -void stop_this_cpu(void *dummy)
27270 +__noreturn void stop_this_cpu(void *dummy)
27271 {
27272 local_irq_disable();
27273 /*
27274 @@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
27275 }
27276 early_param("idle", idle_setup);
27277
27278 -unsigned long arch_align_stack(unsigned long sp)
27279 +#ifdef CONFIG_PAX_RANDKSTACK
27280 +void pax_randomize_kstack(struct pt_regs *regs)
27281 {
27282 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
27283 - sp -= get_random_int() % 8192;
27284 - return sp & ~0xf;
27285 -}
27286 + struct thread_struct *thread = &current->thread;
27287 + unsigned long time;
27288
27289 -unsigned long arch_randomize_brk(struct mm_struct *mm)
27290 -{
27291 - unsigned long range_end = mm->brk + 0x02000000;
27292 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
27293 -}
27294 + if (!randomize_va_space)
27295 + return;
27296 +
27297 + if (v8086_mode(regs))
27298 + return;
27299
27300 + rdtscl(time);
27301 +
27302 + /* P4 seems to return a 0 LSB, ignore it */
27303 +#ifdef CONFIG_MPENTIUM4
27304 + time &= 0x3EUL;
27305 + time <<= 2;
27306 +#elif defined(CONFIG_X86_64)
27307 + time &= 0xFUL;
27308 + time <<= 4;
27309 +#else
27310 + time &= 0x1FUL;
27311 + time <<= 3;
27312 +#endif
27313 +
27314 + thread->sp0 ^= time;
27315 + load_sp0(init_tss + smp_processor_id(), thread);
27316 +
27317 +#ifdef CONFIG_X86_64
27318 + this_cpu_write(kernel_stack, thread->sp0);
27319 +#endif
27320 +}
27321 +#endif
27322 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
27323 index 7bc86bb..0ea06e8 100644
27324 --- a/arch/x86/kernel/process_32.c
27325 +++ b/arch/x86/kernel/process_32.c
27326 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
27327 unsigned long thread_saved_pc(struct task_struct *tsk)
27328 {
27329 return ((unsigned long *)tsk->thread.sp)[3];
27330 +//XXX return tsk->thread.eip;
27331 }
27332
27333 void __show_regs(struct pt_regs *regs, int all)
27334 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
27335 unsigned long sp;
27336 unsigned short ss, gs;
27337
27338 - if (user_mode_vm(regs)) {
27339 + if (user_mode(regs)) {
27340 sp = regs->sp;
27341 ss = regs->ss & 0xffff;
27342 - gs = get_user_gs(regs);
27343 } else {
27344 sp = kernel_stack_pointer(regs);
27345 savesegment(ss, ss);
27346 - savesegment(gs, gs);
27347 }
27348 + gs = get_user_gs(regs);
27349
27350 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
27351 (u16)regs->cs, regs->ip, regs->flags,
27352 - smp_processor_id());
27353 + raw_smp_processor_id());
27354 print_symbol("EIP is at %s\n", regs->ip);
27355
27356 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27357 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
27358 int copy_thread(unsigned long clone_flags, unsigned long sp,
27359 unsigned long arg, struct task_struct *p)
27360 {
27361 - struct pt_regs *childregs = task_pt_regs(p);
27362 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
27363 struct task_struct *tsk;
27364 int err;
27365
27366 p->thread.sp = (unsigned long) childregs;
27367 p->thread.sp0 = (unsigned long) (childregs+1);
27368 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27369
27370 if (unlikely(p->flags & PF_KTHREAD)) {
27371 /* kernel thread */
27372 memset(childregs, 0, sizeof(struct pt_regs));
27373 p->thread.ip = (unsigned long) ret_from_kernel_thread;
27374 - task_user_gs(p) = __KERNEL_STACK_CANARY;
27375 - childregs->ds = __USER_DS;
27376 - childregs->es = __USER_DS;
27377 + savesegment(gs, childregs->gs);
27378 + childregs->ds = __KERNEL_DS;
27379 + childregs->es = __KERNEL_DS;
27380 childregs->fs = __KERNEL_PERCPU;
27381 childregs->bx = sp; /* function */
27382 childregs->bp = arg;
27383 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27384 struct thread_struct *prev = &prev_p->thread,
27385 *next = &next_p->thread;
27386 int cpu = smp_processor_id();
27387 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27388 + struct tss_struct *tss = init_tss + cpu;
27389 fpu_switch_t fpu;
27390
27391 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
27392 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27393 */
27394 lazy_save_gs(prev->gs);
27395
27396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27397 + __set_fs(task_thread_info(next_p)->addr_limit);
27398 +#endif
27399 +
27400 /*
27401 * Load the per-thread Thread-Local Storage descriptor.
27402 */
27403 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27404 */
27405 arch_end_context_switch(next_p);
27406
27407 - this_cpu_write(kernel_stack,
27408 - (unsigned long)task_stack_page(next_p) +
27409 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27410 + this_cpu_write(current_task, next_p);
27411 + this_cpu_write(current_tinfo, &next_p->tinfo);
27412 + this_cpu_write(kernel_stack, next->sp0);
27413
27414 /*
27415 * Restore %gs if needed (which is common)
27416 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27417
27418 switch_fpu_finish(next_p, fpu);
27419
27420 - this_cpu_write(current_task, next_p);
27421 -
27422 return prev_p;
27423 }
27424
27425 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
27426 } while (count++ < 16);
27427 return 0;
27428 }
27429 -
27430 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
27431 index ca5b02d..c0b2f6a 100644
27432 --- a/arch/x86/kernel/process_64.c
27433 +++ b/arch/x86/kernel/process_64.c
27434 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27435 struct pt_regs *childregs;
27436 struct task_struct *me = current;
27437
27438 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
27439 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
27440 childregs = task_pt_regs(p);
27441 p->thread.sp = (unsigned long) childregs;
27442 p->thread.usersp = me->thread.usersp;
27443 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27444 set_tsk_thread_flag(p, TIF_FORK);
27445 p->thread.fpu_counter = 0;
27446 p->thread.io_bitmap_ptr = NULL;
27447 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27448 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
27449 savesegment(es, p->thread.es);
27450 savesegment(ds, p->thread.ds);
27451 + savesegment(ss, p->thread.ss);
27452 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
27453 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
27454
27455 if (unlikely(p->flags & PF_KTHREAD)) {
27456 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27457 struct thread_struct *prev = &prev_p->thread;
27458 struct thread_struct *next = &next_p->thread;
27459 int cpu = smp_processor_id();
27460 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27461 + struct tss_struct *tss = init_tss + cpu;
27462 unsigned fsindex, gsindex;
27463 fpu_switch_t fpu;
27464
27465 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27466 if (unlikely(next->ds | prev->ds))
27467 loadsegment(ds, next->ds);
27468
27469 + savesegment(ss, prev->ss);
27470 + if (unlikely(next->ss != prev->ss))
27471 + loadsegment(ss, next->ss);
27472
27473 /* We must save %fs and %gs before load_TLS() because
27474 * %fs and %gs may be cleared by load_TLS().
27475 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27476 prev->usersp = this_cpu_read(old_rsp);
27477 this_cpu_write(old_rsp, next->usersp);
27478 this_cpu_write(current_task, next_p);
27479 + this_cpu_write(current_tinfo, &next_p->tinfo);
27480
27481 /*
27482 * If it were not for PREEMPT_ACTIVE we could guarantee that the
27483 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27484 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
27485 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
27486
27487 - this_cpu_write(kernel_stack,
27488 - (unsigned long)task_stack_page(next_p) +
27489 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27490 + this_cpu_write(kernel_stack, next->sp0);
27491
27492 /*
27493 * Now maybe reload the debug registers and handle I/O bitmaps
27494 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
27495 if (!p || p == current || p->state == TASK_RUNNING)
27496 return 0;
27497 stack = (unsigned long)task_stack_page(p);
27498 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
27499 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
27500 return 0;
27501 fp = *(u64 *)(p->thread.sp);
27502 do {
27503 - if (fp < (unsigned long)stack ||
27504 - fp >= (unsigned long)stack+THREAD_SIZE)
27505 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27506 return 0;
27507 ip = *(u64 *)(fp+8);
27508 if (!in_sched_functions(ip))
27509 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27510 index b1a5dfa..ed94526 100644
27511 --- a/arch/x86/kernel/ptrace.c
27512 +++ b/arch/x86/kernel/ptrace.c
27513 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27514 unsigned long sp = (unsigned long)&regs->sp;
27515 u32 *prev_esp;
27516
27517 - if (context == (sp & ~(THREAD_SIZE - 1)))
27518 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27519 return sp;
27520
27521 - prev_esp = (u32 *)(context);
27522 + prev_esp = *(u32 **)(context);
27523 if (prev_esp)
27524 return (unsigned long)prev_esp;
27525
27526 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27527 if (child->thread.gs != value)
27528 return do_arch_prctl(child, ARCH_SET_GS, value);
27529 return 0;
27530 +
27531 + case offsetof(struct user_regs_struct,ip):
27532 + /*
27533 + * Protect against any attempt to set ip to an
27534 + * impossible address. There are dragons lurking if the
27535 + * address is noncanonical. (This explicitly allows
27536 + * setting ip to TASK_SIZE_MAX, because user code can do
27537 + * that all by itself by running off the end of its
27538 + * address space.
27539 + */
27540 + if (value > TASK_SIZE_MAX)
27541 + return -EIO;
27542 + break;
27543 +
27544 #endif
27545 }
27546
27547 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27548 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27549 {
27550 int i;
27551 - int dr7 = 0;
27552 + unsigned long dr7 = 0;
27553 struct arch_hw_breakpoint *info;
27554
27555 for (i = 0; i < HBP_NUM; i++) {
27556 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27557 unsigned long addr, unsigned long data)
27558 {
27559 int ret;
27560 - unsigned long __user *datap = (unsigned long __user *)data;
27561 + unsigned long __user *datap = (__force unsigned long __user *)data;
27562
27563 switch (request) {
27564 /* read the word at location addr in the USER area. */
27565 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27566 if ((int) addr < 0)
27567 return -EIO;
27568 ret = do_get_thread_area(child, addr,
27569 - (struct user_desc __user *)data);
27570 + (__force struct user_desc __user *) data);
27571 break;
27572
27573 case PTRACE_SET_THREAD_AREA:
27574 if ((int) addr < 0)
27575 return -EIO;
27576 ret = do_set_thread_area(child, addr,
27577 - (struct user_desc __user *)data, 0);
27578 + (__force struct user_desc __user *) data, 0);
27579 break;
27580 #endif
27581
27582 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27583
27584 #ifdef CONFIG_X86_64
27585
27586 -static struct user_regset x86_64_regsets[] __read_mostly = {
27587 +static user_regset_no_const x86_64_regsets[] __read_only = {
27588 [REGSET_GENERAL] = {
27589 .core_note_type = NT_PRSTATUS,
27590 .n = sizeof(struct user_regs_struct) / sizeof(long),
27591 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27592 #endif /* CONFIG_X86_64 */
27593
27594 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27595 -static struct user_regset x86_32_regsets[] __read_mostly = {
27596 +static user_regset_no_const x86_32_regsets[] __read_only = {
27597 [REGSET_GENERAL] = {
27598 .core_note_type = NT_PRSTATUS,
27599 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27600 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27601 */
27602 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27603
27604 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27605 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27606 {
27607 #ifdef CONFIG_X86_64
27608 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27609 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27610 memset(info, 0, sizeof(*info));
27611 info->si_signo = SIGTRAP;
27612 info->si_code = si_code;
27613 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27614 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27615 }
27616
27617 void user_single_step_siginfo(struct task_struct *tsk,
27618 @@ -1441,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27619 force_sig_info(SIGTRAP, &info, tsk);
27620 }
27621
27622 +#ifdef CONFIG_GRKERNSEC_SETXID
27623 +extern void gr_delayed_cred_worker(void);
27624 +#endif
27625 +
27626 /*
27627 * We must return the syscall number to actually look up in the table.
27628 * This can be -1L to skip running any syscall at all.
27629 @@ -1451,6 +1469,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27630
27631 user_exit();
27632
27633 +#ifdef CONFIG_GRKERNSEC_SETXID
27634 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27635 + gr_delayed_cred_worker();
27636 +#endif
27637 +
27638 /*
27639 * If we stepped into a sysenter/syscall insn, it trapped in
27640 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27641 @@ -1506,6 +1529,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27642 */
27643 user_exit();
27644
27645 +#ifdef CONFIG_GRKERNSEC_SETXID
27646 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27647 + gr_delayed_cred_worker();
27648 +#endif
27649 +
27650 audit_syscall_exit(regs);
27651
27652 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27653 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27654 index 2f355d2..e75ed0a 100644
27655 --- a/arch/x86/kernel/pvclock.c
27656 +++ b/arch/x86/kernel/pvclock.c
27657 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27658 reset_hung_task_detector();
27659 }
27660
27661 -static atomic64_t last_value = ATOMIC64_INIT(0);
27662 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27663
27664 void pvclock_resume(void)
27665 {
27666 - atomic64_set(&last_value, 0);
27667 + atomic64_set_unchecked(&last_value, 0);
27668 }
27669
27670 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27671 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27672 * updating at the same time, and one of them could be slightly behind,
27673 * making the assumption that last_value always go forward fail to hold.
27674 */
27675 - last = atomic64_read(&last_value);
27676 + last = atomic64_read_unchecked(&last_value);
27677 do {
27678 if (ret < last)
27679 return last;
27680 - last = atomic64_cmpxchg(&last_value, last, ret);
27681 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27682 } while (unlikely(last != ret));
27683
27684 return ret;
27685 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27686 index 17962e6..47f55db 100644
27687 --- a/arch/x86/kernel/reboot.c
27688 +++ b/arch/x86/kernel/reboot.c
27689 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27690
27691 void __noreturn machine_real_restart(unsigned int type)
27692 {
27693 +
27694 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27695 + struct desc_struct *gdt;
27696 +#endif
27697 +
27698 local_irq_disable();
27699
27700 /*
27701 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27702
27703 /* Jump to the identity-mapped low memory code */
27704 #ifdef CONFIG_X86_32
27705 - asm volatile("jmpl *%0" : :
27706 +
27707 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27708 + gdt = get_cpu_gdt_table(smp_processor_id());
27709 + pax_open_kernel();
27710 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27711 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27712 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27713 + loadsegment(ds, __KERNEL_DS);
27714 + loadsegment(es, __KERNEL_DS);
27715 + loadsegment(ss, __KERNEL_DS);
27716 +#endif
27717 +#ifdef CONFIG_PAX_KERNEXEC
27718 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27719 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27720 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27721 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27722 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27723 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27724 +#endif
27725 + pax_close_kernel();
27726 +#endif
27727 +
27728 + asm volatile("ljmpl *%0" : :
27729 "rm" (real_mode_header->machine_real_restart_asm),
27730 "a" (type));
27731 #else
27732 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27733 * This means that this function can never return, it can misbehave
27734 * by not rebooting properly and hanging.
27735 */
27736 -static void native_machine_emergency_restart(void)
27737 +static void __noreturn native_machine_emergency_restart(void)
27738 {
27739 int i;
27740 int attempt = 0;
27741 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27742 #endif
27743 }
27744
27745 -static void __machine_emergency_restart(int emergency)
27746 +static void __noreturn __machine_emergency_restart(int emergency)
27747 {
27748 reboot_emergency = emergency;
27749 machine_ops.emergency_restart();
27750 }
27751
27752 -static void native_machine_restart(char *__unused)
27753 +static void __noreturn native_machine_restart(char *__unused)
27754 {
27755 pr_notice("machine restart\n");
27756
27757 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27758 __machine_emergency_restart(0);
27759 }
27760
27761 -static void native_machine_halt(void)
27762 +static void __noreturn native_machine_halt(void)
27763 {
27764 /* Stop other cpus and apics */
27765 machine_shutdown();
27766 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27767 stop_this_cpu(NULL);
27768 }
27769
27770 -static void native_machine_power_off(void)
27771 +static void __noreturn native_machine_power_off(void)
27772 {
27773 if (pm_power_off) {
27774 if (!reboot_force)
27775 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27776 }
27777 /* A fallback in case there is no PM info available */
27778 tboot_shutdown(TB_SHUTDOWN_HALT);
27779 + unreachable();
27780 }
27781
27782 -struct machine_ops machine_ops = {
27783 +struct machine_ops machine_ops __read_only = {
27784 .power_off = native_machine_power_off,
27785 .shutdown = native_machine_shutdown,
27786 .emergency_restart = native_machine_emergency_restart,
27787 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27788 index c8e41e9..64049ef 100644
27789 --- a/arch/x86/kernel/reboot_fixups_32.c
27790 +++ b/arch/x86/kernel/reboot_fixups_32.c
27791 @@ -57,7 +57,7 @@ struct device_fixup {
27792 unsigned int vendor;
27793 unsigned int device;
27794 void (*reboot_fixup)(struct pci_dev *);
27795 -};
27796 +} __do_const;
27797
27798 /*
27799 * PCI ids solely used for fixups_table go here
27800 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27801 index 3fd2c69..a444264 100644
27802 --- a/arch/x86/kernel/relocate_kernel_64.S
27803 +++ b/arch/x86/kernel/relocate_kernel_64.S
27804 @@ -96,8 +96,7 @@ relocate_kernel:
27805
27806 /* jump to identity mapped page */
27807 addq $(identity_mapped - relocate_kernel), %r8
27808 - pushq %r8
27809 - ret
27810 + jmp *%r8
27811
27812 identity_mapped:
27813 /* set return address to 0 if not preserving context */
27814 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27815 index 41ead8d..7ccde23 100644
27816 --- a/arch/x86/kernel/setup.c
27817 +++ b/arch/x86/kernel/setup.c
27818 @@ -110,6 +110,7 @@
27819 #include <asm/mce.h>
27820 #include <asm/alternative.h>
27821 #include <asm/prom.h>
27822 +#include <asm/boot.h>
27823
27824 /*
27825 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27826 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27827 #endif
27828
27829
27830 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27831 -__visible unsigned long mmu_cr4_features;
27832 +#ifdef CONFIG_X86_64
27833 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27834 +#elif defined(CONFIG_X86_PAE)
27835 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27836 #else
27837 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27838 +__visible unsigned long mmu_cr4_features __read_only;
27839 #endif
27840
27841 +void set_in_cr4(unsigned long mask)
27842 +{
27843 + unsigned long cr4 = read_cr4();
27844 +
27845 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27846 + return;
27847 +
27848 + pax_open_kernel();
27849 + mmu_cr4_features |= mask;
27850 + pax_close_kernel();
27851 +
27852 + if (trampoline_cr4_features)
27853 + *trampoline_cr4_features = mmu_cr4_features;
27854 + cr4 |= mask;
27855 + write_cr4(cr4);
27856 +}
27857 +EXPORT_SYMBOL(set_in_cr4);
27858 +
27859 +void clear_in_cr4(unsigned long mask)
27860 +{
27861 + unsigned long cr4 = read_cr4();
27862 +
27863 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27864 + return;
27865 +
27866 + pax_open_kernel();
27867 + mmu_cr4_features &= ~mask;
27868 + pax_close_kernel();
27869 +
27870 + if (trampoline_cr4_features)
27871 + *trampoline_cr4_features = mmu_cr4_features;
27872 + cr4 &= ~mask;
27873 + write_cr4(cr4);
27874 +}
27875 +EXPORT_SYMBOL(clear_in_cr4);
27876 +
27877 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27878 int bootloader_type, bootloader_version;
27879
27880 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27881 * area (640->1Mb) as ram even though it is not.
27882 * take them out.
27883 */
27884 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27885 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27886
27887 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27888 }
27889 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27890 /* called before trim_bios_range() to spare extra sanitize */
27891 static void __init e820_add_kernel_range(void)
27892 {
27893 - u64 start = __pa_symbol(_text);
27894 + u64 start = __pa_symbol(ktla_ktva(_text));
27895 u64 size = __pa_symbol(_end) - start;
27896
27897 /*
27898 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27899
27900 void __init setup_arch(char **cmdline_p)
27901 {
27902 +#ifdef CONFIG_X86_32
27903 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27904 +#else
27905 memblock_reserve(__pa_symbol(_text),
27906 (unsigned long)__bss_stop - (unsigned long)_text);
27907 +#endif
27908
27909 early_reserve_initrd();
27910
27911 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27912
27913 if (!boot_params.hdr.root_flags)
27914 root_mountflags &= ~MS_RDONLY;
27915 - init_mm.start_code = (unsigned long) _text;
27916 - init_mm.end_code = (unsigned long) _etext;
27917 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27918 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27919 init_mm.end_data = (unsigned long) _edata;
27920 init_mm.brk = _brk_end;
27921
27922 - code_resource.start = __pa_symbol(_text);
27923 - code_resource.end = __pa_symbol(_etext)-1;
27924 - data_resource.start = __pa_symbol(_etext);
27925 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27926 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27927 + data_resource.start = __pa_symbol(_sdata);
27928 data_resource.end = __pa_symbol(_edata)-1;
27929 bss_resource.start = __pa_symbol(__bss_start);
27930 bss_resource.end = __pa_symbol(__bss_stop)-1;
27931 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27932 index 5cdff03..80fa283 100644
27933 --- a/arch/x86/kernel/setup_percpu.c
27934 +++ b/arch/x86/kernel/setup_percpu.c
27935 @@ -21,19 +21,17 @@
27936 #include <asm/cpu.h>
27937 #include <asm/stackprotector.h>
27938
27939 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27940 +#ifdef CONFIG_SMP
27941 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27942 EXPORT_PER_CPU_SYMBOL(cpu_number);
27943 +#endif
27944
27945 -#ifdef CONFIG_X86_64
27946 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27947 -#else
27948 -#define BOOT_PERCPU_OFFSET 0
27949 -#endif
27950
27951 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27952 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27953
27954 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27955 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27956 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27957 };
27958 EXPORT_SYMBOL(__per_cpu_offset);
27959 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27960 {
27961 #ifdef CONFIG_NEED_MULTIPLE_NODES
27962 pg_data_t *last = NULL;
27963 - unsigned int cpu;
27964 + int cpu;
27965
27966 for_each_possible_cpu(cpu) {
27967 int node = early_cpu_to_node(cpu);
27968 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27969 {
27970 #ifdef CONFIG_X86_32
27971 struct desc_struct gdt;
27972 + unsigned long base = per_cpu_offset(cpu);
27973
27974 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27975 - 0x2 | DESCTYPE_S, 0x8);
27976 - gdt.s = 1;
27977 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27978 + 0x83 | DESCTYPE_S, 0xC);
27979 write_gdt_entry(get_cpu_gdt_table(cpu),
27980 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27981 #endif
27982 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27983 /* alrighty, percpu areas up and running */
27984 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27985 for_each_possible_cpu(cpu) {
27986 +#ifdef CONFIG_CC_STACKPROTECTOR
27987 +#ifdef CONFIG_X86_32
27988 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27989 +#endif
27990 +#endif
27991 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27992 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27993 per_cpu(cpu_number, cpu) = cpu;
27994 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27995 */
27996 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27997 #endif
27998 +#ifdef CONFIG_CC_STACKPROTECTOR
27999 +#ifdef CONFIG_X86_32
28000 + if (!cpu)
28001 + per_cpu(stack_canary.canary, cpu) = canary;
28002 +#endif
28003 +#endif
28004 /*
28005 * Up to this point, the boot CPU has been using .init.data
28006 * area. Reload any changed state for the boot CPU.
28007 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
28008 index ed37a76..39f936e 100644
28009 --- a/arch/x86/kernel/signal.c
28010 +++ b/arch/x86/kernel/signal.c
28011 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
28012 * Align the stack pointer according to the i386 ABI,
28013 * i.e. so that on function entry ((sp + 4) & 15) == 0.
28014 */
28015 - sp = ((sp + 4) & -16ul) - 4;
28016 + sp = ((sp - 12) & -16ul) - 4;
28017 #else /* !CONFIG_X86_32 */
28018 sp = round_down(sp, 16) - 8;
28019 #endif
28020 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
28021 }
28022
28023 if (current->mm->context.vdso)
28024 - restorer = current->mm->context.vdso +
28025 - selected_vdso32->sym___kernel_sigreturn;
28026 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
28027 else
28028 - restorer = &frame->retcode;
28029 + restorer = (void __user *)&frame->retcode;
28030 if (ksig->ka.sa.sa_flags & SA_RESTORER)
28031 restorer = ksig->ka.sa.sa_restorer;
28032
28033 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
28034 * reasons and because gdb uses it as a signature to notice
28035 * signal handler stack frames.
28036 */
28037 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
28038 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
28039
28040 if (err)
28041 return -EFAULT;
28042 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
28043 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
28044
28045 /* Set up to return from userspace. */
28046 - restorer = current->mm->context.vdso +
28047 - selected_vdso32->sym___kernel_rt_sigreturn;
28048 + if (current->mm->context.vdso)
28049 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
28050 + else
28051 + restorer = (void __user *)&frame->retcode;
28052 if (ksig->ka.sa.sa_flags & SA_RESTORER)
28053 restorer = ksig->ka.sa.sa_restorer;
28054 put_user_ex(restorer, &frame->pretcode);
28055 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
28056 * reasons and because gdb uses it as a signature to notice
28057 * signal handler stack frames.
28058 */
28059 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
28060 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
28061 } put_user_catch(err);
28062
28063 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
28064 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28065 {
28066 int usig = signr_convert(ksig->sig);
28067 sigset_t *set = sigmask_to_save();
28068 - compat_sigset_t *cset = (compat_sigset_t *) set;
28069 + sigset_t sigcopy;
28070 + compat_sigset_t *cset;
28071 +
28072 + sigcopy = *set;
28073 +
28074 + cset = (compat_sigset_t *) &sigcopy;
28075
28076 /* Set up the stack frame */
28077 if (is_ia32_frame()) {
28078 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28079 } else if (is_x32_frame()) {
28080 return x32_setup_rt_frame(ksig, cset, regs);
28081 } else {
28082 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
28083 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
28084 }
28085 }
28086
28087 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
28088 index be8e1bd..a3d93fa 100644
28089 --- a/arch/x86/kernel/smp.c
28090 +++ b/arch/x86/kernel/smp.c
28091 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
28092
28093 __setup("nonmi_ipi", nonmi_ipi_setup);
28094
28095 -struct smp_ops smp_ops = {
28096 +struct smp_ops smp_ops __read_only = {
28097 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
28098 .smp_prepare_cpus = native_smp_prepare_cpus,
28099 .smp_cpus_done = native_smp_cpus_done,
28100 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
28101 index 42a2dca..35a07aa 100644
28102 --- a/arch/x86/kernel/smpboot.c
28103 +++ b/arch/x86/kernel/smpboot.c
28104 @@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
28105
28106 enable_start_cpu0 = 0;
28107
28108 -#ifdef CONFIG_X86_32
28109 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
28110 + barrier();
28111 +
28112 /* switch away from the initial page table */
28113 +#ifdef CONFIG_PAX_PER_CPU_PGD
28114 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
28115 +#else
28116 load_cr3(swapper_pg_dir);
28117 +#endif
28118 __flush_tlb_all();
28119 -#endif
28120
28121 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
28122 - barrier();
28123 /*
28124 * Check TSC synchronization with the BP:
28125 */
28126 @@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28127 alternatives_enable_smp();
28128
28129 idle->thread.sp = (unsigned long) (((struct pt_regs *)
28130 - (THREAD_SIZE + task_stack_page(idle))) - 1);
28131 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
28132 per_cpu(current_task, cpu) = idle;
28133 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
28134
28135 #ifdef CONFIG_X86_32
28136 /* Stack for startup_32 can be just as for start_secondary onwards */
28137 @@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28138 clear_tsk_thread_flag(idle, TIF_FORK);
28139 initial_gs = per_cpu_offset(cpu);
28140 #endif
28141 - per_cpu(kernel_stack, cpu) =
28142 - (unsigned long)task_stack_page(idle) -
28143 - KERNEL_STACK_OFFSET + THREAD_SIZE;
28144 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28145 + pax_open_kernel();
28146 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
28147 + pax_close_kernel();
28148 initial_code = (unsigned long)start_secondary;
28149 stack_start = idle->thread.sp;
28150
28151 @@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
28152 /* the FPU context is blank, nobody can own it */
28153 __cpu_disable_lazy_restore(cpu);
28154
28155 +#ifdef CONFIG_PAX_PER_CPU_PGD
28156 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
28157 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28158 + KERNEL_PGD_PTRS);
28159 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
28160 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28161 + KERNEL_PGD_PTRS);
28162 +#endif
28163 +
28164 err = do_boot_cpu(apicid, cpu, tidle);
28165 if (err) {
28166 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
28167 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
28168 index 9b4d51d..5d28b58 100644
28169 --- a/arch/x86/kernel/step.c
28170 +++ b/arch/x86/kernel/step.c
28171 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28172 struct desc_struct *desc;
28173 unsigned long base;
28174
28175 - seg &= ~7UL;
28176 + seg >>= 3;
28177
28178 mutex_lock(&child->mm->context.lock);
28179 - if (unlikely((seg >> 3) >= child->mm->context.size))
28180 + if (unlikely(seg >= child->mm->context.size))
28181 addr = -1L; /* bogus selector, access would fault */
28182 else {
28183 desc = child->mm->context.ldt + seg;
28184 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28185 addr += base;
28186 }
28187 mutex_unlock(&child->mm->context.lock);
28188 - }
28189 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
28190 + addr = ktla_ktva(addr);
28191
28192 return addr;
28193 }
28194 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
28195 unsigned char opcode[15];
28196 unsigned long addr = convert_ip_to_linear(child, regs);
28197
28198 + if (addr == -EINVAL)
28199 + return 0;
28200 +
28201 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
28202 for (i = 0; i < copied; i++) {
28203 switch (opcode[i]) {
28204 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
28205 new file mode 100644
28206 index 0000000..5877189
28207 --- /dev/null
28208 +++ b/arch/x86/kernel/sys_i386_32.c
28209 @@ -0,0 +1,189 @@
28210 +/*
28211 + * This file contains various random system calls that
28212 + * have a non-standard calling sequence on the Linux/i386
28213 + * platform.
28214 + */
28215 +
28216 +#include <linux/errno.h>
28217 +#include <linux/sched.h>
28218 +#include <linux/mm.h>
28219 +#include <linux/fs.h>
28220 +#include <linux/smp.h>
28221 +#include <linux/sem.h>
28222 +#include <linux/msg.h>
28223 +#include <linux/shm.h>
28224 +#include <linux/stat.h>
28225 +#include <linux/syscalls.h>
28226 +#include <linux/mman.h>
28227 +#include <linux/file.h>
28228 +#include <linux/utsname.h>
28229 +#include <linux/ipc.h>
28230 +#include <linux/elf.h>
28231 +
28232 +#include <linux/uaccess.h>
28233 +#include <linux/unistd.h>
28234 +
28235 +#include <asm/syscalls.h>
28236 +
28237 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
28238 +{
28239 + unsigned long pax_task_size = TASK_SIZE;
28240 +
28241 +#ifdef CONFIG_PAX_SEGMEXEC
28242 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
28243 + pax_task_size = SEGMEXEC_TASK_SIZE;
28244 +#endif
28245 +
28246 + if (flags & MAP_FIXED)
28247 + if (len > pax_task_size || addr > pax_task_size - len)
28248 + return -EINVAL;
28249 +
28250 + return 0;
28251 +}
28252 +
28253 +/*
28254 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
28255 + */
28256 +static unsigned long get_align_mask(void)
28257 +{
28258 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
28259 + return 0;
28260 +
28261 + if (!(current->flags & PF_RANDOMIZE))
28262 + return 0;
28263 +
28264 + return va_align.mask;
28265 +}
28266 +
28267 +unsigned long
28268 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
28269 + unsigned long len, unsigned long pgoff, unsigned long flags)
28270 +{
28271 + struct mm_struct *mm = current->mm;
28272 + struct vm_area_struct *vma;
28273 + unsigned long pax_task_size = TASK_SIZE;
28274 + struct vm_unmapped_area_info info;
28275 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28276 +
28277 +#ifdef CONFIG_PAX_SEGMEXEC
28278 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28279 + pax_task_size = SEGMEXEC_TASK_SIZE;
28280 +#endif
28281 +
28282 + pax_task_size -= PAGE_SIZE;
28283 +
28284 + if (len > pax_task_size)
28285 + return -ENOMEM;
28286 +
28287 + if (flags & MAP_FIXED)
28288 + return addr;
28289 +
28290 +#ifdef CONFIG_PAX_RANDMMAP
28291 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28292 +#endif
28293 +
28294 + if (addr) {
28295 + addr = PAGE_ALIGN(addr);
28296 + if (pax_task_size - len >= addr) {
28297 + vma = find_vma(mm, addr);
28298 + if (check_heap_stack_gap(vma, addr, len, offset))
28299 + return addr;
28300 + }
28301 + }
28302 +
28303 + info.flags = 0;
28304 + info.length = len;
28305 + info.align_mask = filp ? get_align_mask() : 0;
28306 + info.align_offset = pgoff << PAGE_SHIFT;
28307 + info.threadstack_offset = offset;
28308 +
28309 +#ifdef CONFIG_PAX_PAGEEXEC
28310 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
28311 + info.low_limit = 0x00110000UL;
28312 + info.high_limit = mm->start_code;
28313 +
28314 +#ifdef CONFIG_PAX_RANDMMAP
28315 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28316 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
28317 +#endif
28318 +
28319 + if (info.low_limit < info.high_limit) {
28320 + addr = vm_unmapped_area(&info);
28321 + if (!IS_ERR_VALUE(addr))
28322 + return addr;
28323 + }
28324 + } else
28325 +#endif
28326 +
28327 + info.low_limit = mm->mmap_base;
28328 + info.high_limit = pax_task_size;
28329 +
28330 + return vm_unmapped_area(&info);
28331 +}
28332 +
28333 +unsigned long
28334 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28335 + const unsigned long len, const unsigned long pgoff,
28336 + const unsigned long flags)
28337 +{
28338 + struct vm_area_struct *vma;
28339 + struct mm_struct *mm = current->mm;
28340 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
28341 + struct vm_unmapped_area_info info;
28342 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28343 +
28344 +#ifdef CONFIG_PAX_SEGMEXEC
28345 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28346 + pax_task_size = SEGMEXEC_TASK_SIZE;
28347 +#endif
28348 +
28349 + pax_task_size -= PAGE_SIZE;
28350 +
28351 + /* requested length too big for entire address space */
28352 + if (len > pax_task_size)
28353 + return -ENOMEM;
28354 +
28355 + if (flags & MAP_FIXED)
28356 + return addr;
28357 +
28358 +#ifdef CONFIG_PAX_PAGEEXEC
28359 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
28360 + goto bottomup;
28361 +#endif
28362 +
28363 +#ifdef CONFIG_PAX_RANDMMAP
28364 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28365 +#endif
28366 +
28367 + /* requesting a specific address */
28368 + if (addr) {
28369 + addr = PAGE_ALIGN(addr);
28370 + if (pax_task_size - len >= addr) {
28371 + vma = find_vma(mm, addr);
28372 + if (check_heap_stack_gap(vma, addr, len, offset))
28373 + return addr;
28374 + }
28375 + }
28376 +
28377 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
28378 + info.length = len;
28379 + info.low_limit = PAGE_SIZE;
28380 + info.high_limit = mm->mmap_base;
28381 + info.align_mask = filp ? get_align_mask() : 0;
28382 + info.align_offset = pgoff << PAGE_SHIFT;
28383 + info.threadstack_offset = offset;
28384 +
28385 + addr = vm_unmapped_area(&info);
28386 + if (!(addr & ~PAGE_MASK))
28387 + return addr;
28388 + VM_BUG_ON(addr != -ENOMEM);
28389 +
28390 +bottomup:
28391 + /*
28392 + * A failed mmap() very likely causes application failure,
28393 + * so fall back to the bottom-up function here. This scenario
28394 + * can happen with large stack limits and large mmap()
28395 + * allocations.
28396 + */
28397 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
28398 +}
28399 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
28400 index 30277e2..5664a29 100644
28401 --- a/arch/x86/kernel/sys_x86_64.c
28402 +++ b/arch/x86/kernel/sys_x86_64.c
28403 @@ -81,8 +81,8 @@ out:
28404 return error;
28405 }
28406
28407 -static void find_start_end(unsigned long flags, unsigned long *begin,
28408 - unsigned long *end)
28409 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
28410 + unsigned long *begin, unsigned long *end)
28411 {
28412 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
28413 unsigned long new_begin;
28414 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
28415 *begin = new_begin;
28416 }
28417 } else {
28418 - *begin = current->mm->mmap_legacy_base;
28419 + *begin = mm->mmap_legacy_base;
28420 *end = TASK_SIZE;
28421 }
28422 }
28423 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28424 struct vm_area_struct *vma;
28425 struct vm_unmapped_area_info info;
28426 unsigned long begin, end;
28427 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28428
28429 if (flags & MAP_FIXED)
28430 return addr;
28431
28432 - find_start_end(flags, &begin, &end);
28433 + find_start_end(mm, flags, &begin, &end);
28434
28435 if (len > end)
28436 return -ENOMEM;
28437
28438 +#ifdef CONFIG_PAX_RANDMMAP
28439 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28440 +#endif
28441 +
28442 if (addr) {
28443 addr = PAGE_ALIGN(addr);
28444 vma = find_vma(mm, addr);
28445 - if (end - len >= addr &&
28446 - (!vma || addr + len <= vma->vm_start))
28447 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28448 return addr;
28449 }
28450
28451 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28452 info.high_limit = end;
28453 info.align_mask = filp ? get_align_mask() : 0;
28454 info.align_offset = pgoff << PAGE_SHIFT;
28455 + info.threadstack_offset = offset;
28456 return vm_unmapped_area(&info);
28457 }
28458
28459 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28460 struct mm_struct *mm = current->mm;
28461 unsigned long addr = addr0;
28462 struct vm_unmapped_area_info info;
28463 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28464
28465 /* requested length too big for entire address space */
28466 if (len > TASK_SIZE)
28467 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28468 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
28469 goto bottomup;
28470
28471 +#ifdef CONFIG_PAX_RANDMMAP
28472 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28473 +#endif
28474 +
28475 /* requesting a specific address */
28476 if (addr) {
28477 addr = PAGE_ALIGN(addr);
28478 vma = find_vma(mm, addr);
28479 - if (TASK_SIZE - len >= addr &&
28480 - (!vma || addr + len <= vma->vm_start))
28481 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28482 return addr;
28483 }
28484
28485 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28486 info.high_limit = mm->mmap_base;
28487 info.align_mask = filp ? get_align_mask() : 0;
28488 info.align_offset = pgoff << PAGE_SHIFT;
28489 + info.threadstack_offset = offset;
28490 addr = vm_unmapped_area(&info);
28491 if (!(addr & ~PAGE_MASK))
28492 return addr;
28493 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
28494 index 91a4496..bb87552 100644
28495 --- a/arch/x86/kernel/tboot.c
28496 +++ b/arch/x86/kernel/tboot.c
28497 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
28498
28499 void tboot_shutdown(u32 shutdown_type)
28500 {
28501 - void (*shutdown)(void);
28502 + void (* __noreturn shutdown)(void);
28503
28504 if (!tboot_enabled())
28505 return;
28506 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28507
28508 switch_to_tboot_pt();
28509
28510 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28511 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28512 shutdown();
28513
28514 /* should not reach here */
28515 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28516 return -ENODEV;
28517 }
28518
28519 -static atomic_t ap_wfs_count;
28520 +static atomic_unchecked_t ap_wfs_count;
28521
28522 static int tboot_wait_for_aps(int num_aps)
28523 {
28524 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28525 {
28526 switch (action) {
28527 case CPU_DYING:
28528 - atomic_inc(&ap_wfs_count);
28529 + atomic_inc_unchecked(&ap_wfs_count);
28530 if (num_online_cpus() == 1)
28531 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28532 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28533 return NOTIFY_BAD;
28534 break;
28535 }
28536 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28537
28538 tboot_create_trampoline();
28539
28540 - atomic_set(&ap_wfs_count, 0);
28541 + atomic_set_unchecked(&ap_wfs_count, 0);
28542 register_hotcpu_notifier(&tboot_cpu_notifier);
28543
28544 #ifdef CONFIG_DEBUG_FS
28545 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28546 index 0fa2960..91eabbe 100644
28547 --- a/arch/x86/kernel/time.c
28548 +++ b/arch/x86/kernel/time.c
28549 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28550 {
28551 unsigned long pc = instruction_pointer(regs);
28552
28553 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28554 + if (!user_mode(regs) && in_lock_functions(pc)) {
28555 #ifdef CONFIG_FRAME_POINTER
28556 - return *(unsigned long *)(regs->bp + sizeof(long));
28557 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28558 #else
28559 unsigned long *sp =
28560 (unsigned long *)kernel_stack_pointer(regs);
28561 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28562 * or above a saved flags. Eflags has bits 22-31 zero,
28563 * kernel addresses don't.
28564 */
28565 +
28566 +#ifdef CONFIG_PAX_KERNEXEC
28567 + return ktla_ktva(sp[0]);
28568 +#else
28569 if (sp[0] >> 22)
28570 return sp[0];
28571 if (sp[1] >> 22)
28572 return sp[1];
28573 #endif
28574 +
28575 +#endif
28576 }
28577 return pc;
28578 }
28579 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28580 index f7fec09..9991981 100644
28581 --- a/arch/x86/kernel/tls.c
28582 +++ b/arch/x86/kernel/tls.c
28583 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28584 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28585 return -EINVAL;
28586
28587 +#ifdef CONFIG_PAX_SEGMEXEC
28588 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28589 + return -EINVAL;
28590 +#endif
28591 +
28592 set_tls_desc(p, idx, &info, 1);
28593
28594 return 0;
28595 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28596
28597 if (kbuf)
28598 info = kbuf;
28599 - else if (__copy_from_user(infobuf, ubuf, count))
28600 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28601 return -EFAULT;
28602 else
28603 info = infobuf;
28604 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28605 index 1c113db..287b42e 100644
28606 --- a/arch/x86/kernel/tracepoint.c
28607 +++ b/arch/x86/kernel/tracepoint.c
28608 @@ -9,11 +9,11 @@
28609 #include <linux/atomic.h>
28610
28611 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28612 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28613 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28614 (unsigned long) trace_idt_table };
28615
28616 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28617 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28618 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28619
28620 static int trace_irq_vector_refcount;
28621 static DEFINE_MUTEX(irq_vector_mutex);
28622 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28623 index de801f2..f189dcf 100644
28624 --- a/arch/x86/kernel/traps.c
28625 +++ b/arch/x86/kernel/traps.c
28626 @@ -67,7 +67,7 @@
28627 #include <asm/proto.h>
28628
28629 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28630 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28631 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28632 #else
28633 #include <asm/processor-flags.h>
28634 #include <asm/setup.h>
28635 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28636 #endif
28637
28638 /* Must be page-aligned because the real IDT is used in a fixmap. */
28639 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28640 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28641
28642 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28643 EXPORT_SYMBOL_GPL(used_vectors);
28644 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28645 }
28646
28647 static nokprobe_inline int
28648 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28649 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28650 struct pt_regs *regs, long error_code)
28651 {
28652 #ifdef CONFIG_X86_32
28653 - if (regs->flags & X86_VM_MASK) {
28654 + if (v8086_mode(regs)) {
28655 /*
28656 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28657 * On nmi (interrupt 2), do_trap should not be called.
28658 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28659 return -1;
28660 }
28661 #endif
28662 - if (!user_mode(regs)) {
28663 + if (!user_mode_novm(regs)) {
28664 if (!fixup_exception(regs)) {
28665 tsk->thread.error_code = error_code;
28666 tsk->thread.trap_nr = trapnr;
28667 +
28668 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28669 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28670 + str = "PAX: suspicious stack segment fault";
28671 +#endif
28672 +
28673 die(str, regs, error_code);
28674 }
28675 +
28676 +#ifdef CONFIG_PAX_REFCOUNT
28677 + if (trapnr == X86_TRAP_OF)
28678 + pax_report_refcount_overflow(regs);
28679 +#endif
28680 +
28681 return 0;
28682 }
28683
28684 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28685 }
28686
28687 static void
28688 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28689 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28690 long error_code, siginfo_t *info)
28691 {
28692 struct task_struct *tsk = current;
28693 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28694 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28695 printk_ratelimit()) {
28696 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28697 - tsk->comm, tsk->pid, str,
28698 + tsk->comm, task_pid_nr(tsk), str,
28699 regs->ip, regs->sp, error_code);
28700 print_vma_addr(" in ", regs->ip);
28701 pr_cont("\n");
28702 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28703 tsk->thread.error_code = error_code;
28704 tsk->thread.trap_nr = X86_TRAP_DF;
28705
28706 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28707 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28708 + die("grsec: kernel stack overflow detected", regs, error_code);
28709 +#endif
28710 +
28711 #ifdef CONFIG_DOUBLEFAULT
28712 df_debug(regs, error_code);
28713 #endif
28714 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28715 conditional_sti(regs);
28716
28717 #ifdef CONFIG_X86_32
28718 - if (regs->flags & X86_VM_MASK) {
28719 + if (v8086_mode(regs)) {
28720 local_irq_enable();
28721 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28722 goto exit;
28723 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28724 #endif
28725
28726 tsk = current;
28727 - if (!user_mode(regs)) {
28728 + if (!user_mode_novm(regs)) {
28729 if (fixup_exception(regs))
28730 goto exit;
28731
28732 tsk->thread.error_code = error_code;
28733 tsk->thread.trap_nr = X86_TRAP_GP;
28734 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28735 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28736 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28737 +
28738 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28739 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28740 + die("PAX: suspicious general protection fault", regs, error_code);
28741 + else
28742 +#endif
28743 +
28744 die("general protection fault", regs, error_code);
28745 + }
28746 goto exit;
28747 }
28748
28749 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28750 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28751 + struct mm_struct *mm = tsk->mm;
28752 + unsigned long limit;
28753 +
28754 + down_write(&mm->mmap_sem);
28755 + limit = mm->context.user_cs_limit;
28756 + if (limit < TASK_SIZE) {
28757 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28758 + up_write(&mm->mmap_sem);
28759 + return;
28760 + }
28761 + up_write(&mm->mmap_sem);
28762 + }
28763 +#endif
28764 +
28765 tsk->thread.error_code = error_code;
28766 tsk->thread.trap_nr = X86_TRAP_GP;
28767
28768 @@ -433,7 +474,7 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28769 /* Copy the remainder of the stack from the current stack. */
28770 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28771
28772 - BUG_ON(!user_mode_vm(&new_stack->regs));
28773 + BUG_ON(!user_mode(&new_stack->regs));
28774 return new_stack;
28775 }
28776 #endif
28777 @@ -518,7 +559,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28778 /* It's safe to allow irq's after DR6 has been saved */
28779 preempt_conditional_sti(regs);
28780
28781 - if (regs->flags & X86_VM_MASK) {
28782 + if (v8086_mode(regs)) {
28783 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28784 X86_TRAP_DB);
28785 preempt_conditional_cli(regs);
28786 @@ -533,7 +574,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28787 * We already checked v86 mode above, so we can check for kernel mode
28788 * by just checking the CPL of CS.
28789 */
28790 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28791 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28792 tsk->thread.debugreg6 &= ~DR_STEP;
28793 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28794 regs->flags &= ~X86_EFLAGS_TF;
28795 @@ -566,7 +607,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28796 return;
28797 conditional_sti(regs);
28798
28799 - if (!user_mode_vm(regs))
28800 + if (!user_mode(regs))
28801 {
28802 if (!fixup_exception(regs)) {
28803 task->thread.error_code = error_code;
28804 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28805 index b7e50bb..f4a93ae 100644
28806 --- a/arch/x86/kernel/tsc.c
28807 +++ b/arch/x86/kernel/tsc.c
28808 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28809 */
28810 smp_wmb();
28811
28812 - ACCESS_ONCE(c2n->head) = data;
28813 + ACCESS_ONCE_RW(c2n->head) = data;
28814 }
28815
28816 /*
28817 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28818 index 5d1cbfe..2a21feb 100644
28819 --- a/arch/x86/kernel/uprobes.c
28820 +++ b/arch/x86/kernel/uprobes.c
28821 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28822 int ret = NOTIFY_DONE;
28823
28824 /* We are only interested in userspace traps */
28825 - if (regs && !user_mode_vm(regs))
28826 + if (regs && !user_mode(regs))
28827 return NOTIFY_DONE;
28828
28829 switch (val) {
28830 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28831
28832 if (nleft != rasize) {
28833 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28834 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28835 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28836
28837 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28838 }
28839 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28840 index b9242ba..50c5edd 100644
28841 --- a/arch/x86/kernel/verify_cpu.S
28842 +++ b/arch/x86/kernel/verify_cpu.S
28843 @@ -20,6 +20,7 @@
28844 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28845 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28846 * arch/x86/kernel/head_32.S: processor startup
28847 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28848 *
28849 * verify_cpu, returns the status of longmode and SSE in register %eax.
28850 * 0: Success 1: Failure
28851 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28852 index e8edcf5..27f9344 100644
28853 --- a/arch/x86/kernel/vm86_32.c
28854 +++ b/arch/x86/kernel/vm86_32.c
28855 @@ -44,6 +44,7 @@
28856 #include <linux/ptrace.h>
28857 #include <linux/audit.h>
28858 #include <linux/stddef.h>
28859 +#include <linux/grsecurity.h>
28860
28861 #include <asm/uaccess.h>
28862 #include <asm/io.h>
28863 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28864 do_exit(SIGSEGV);
28865 }
28866
28867 - tss = &per_cpu(init_tss, get_cpu());
28868 + tss = init_tss + get_cpu();
28869 current->thread.sp0 = current->thread.saved_sp0;
28870 current->thread.sysenter_cs = __KERNEL_CS;
28871 load_sp0(tss, &current->thread);
28872 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28873
28874 if (tsk->thread.saved_sp0)
28875 return -EPERM;
28876 +
28877 +#ifdef CONFIG_GRKERNSEC_VM86
28878 + if (!capable(CAP_SYS_RAWIO)) {
28879 + gr_handle_vm86();
28880 + return -EPERM;
28881 + }
28882 +#endif
28883 +
28884 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28885 offsetof(struct kernel_vm86_struct, vm86plus) -
28886 sizeof(info.regs));
28887 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28888 int tmp;
28889 struct vm86plus_struct __user *v86;
28890
28891 +#ifdef CONFIG_GRKERNSEC_VM86
28892 + if (!capable(CAP_SYS_RAWIO)) {
28893 + gr_handle_vm86();
28894 + return -EPERM;
28895 + }
28896 +#endif
28897 +
28898 tsk = current;
28899 switch (cmd) {
28900 case VM86_REQUEST_IRQ:
28901 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28902 tsk->thread.saved_fs = info->regs32->fs;
28903 tsk->thread.saved_gs = get_user_gs(info->regs32);
28904
28905 - tss = &per_cpu(init_tss, get_cpu());
28906 + tss = init_tss + get_cpu();
28907 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28908 if (cpu_has_sep)
28909 tsk->thread.sysenter_cs = 0;
28910 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28911 goto cannot_handle;
28912 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28913 goto cannot_handle;
28914 - intr_ptr = (unsigned long __user *) (i << 2);
28915 + intr_ptr = (__force unsigned long __user *) (i << 2);
28916 if (get_user(segoffs, intr_ptr))
28917 goto cannot_handle;
28918 if ((segoffs >> 16) == BIOSSEG)
28919 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28920 index 49edf2d..c0d1362 100644
28921 --- a/arch/x86/kernel/vmlinux.lds.S
28922 +++ b/arch/x86/kernel/vmlinux.lds.S
28923 @@ -26,6 +26,13 @@
28924 #include <asm/page_types.h>
28925 #include <asm/cache.h>
28926 #include <asm/boot.h>
28927 +#include <asm/segment.h>
28928 +
28929 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28930 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28931 +#else
28932 +#define __KERNEL_TEXT_OFFSET 0
28933 +#endif
28934
28935 #undef i386 /* in case the preprocessor is a 32bit one */
28936
28937 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28938
28939 PHDRS {
28940 text PT_LOAD FLAGS(5); /* R_E */
28941 +#ifdef CONFIG_X86_32
28942 + module PT_LOAD FLAGS(5); /* R_E */
28943 +#endif
28944 +#ifdef CONFIG_XEN
28945 + rodata PT_LOAD FLAGS(5); /* R_E */
28946 +#else
28947 + rodata PT_LOAD FLAGS(4); /* R__ */
28948 +#endif
28949 data PT_LOAD FLAGS(6); /* RW_ */
28950 -#ifdef CONFIG_X86_64
28951 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28952 #ifdef CONFIG_SMP
28953 percpu PT_LOAD FLAGS(6); /* RW_ */
28954 #endif
28955 + text.init PT_LOAD FLAGS(5); /* R_E */
28956 + text.exit PT_LOAD FLAGS(5); /* R_E */
28957 init PT_LOAD FLAGS(7); /* RWE */
28958 -#endif
28959 note PT_NOTE FLAGS(0); /* ___ */
28960 }
28961
28962 SECTIONS
28963 {
28964 #ifdef CONFIG_X86_32
28965 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28966 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28967 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28968 #else
28969 - . = __START_KERNEL;
28970 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28971 + . = __START_KERNEL;
28972 #endif
28973
28974 /* Text and read-only data */
28975 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28976 - _text = .;
28977 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28978 /* bootstrapping code */
28979 +#ifdef CONFIG_X86_32
28980 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28981 +#else
28982 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28983 +#endif
28984 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28985 + _text = .;
28986 HEAD_TEXT
28987 . = ALIGN(8);
28988 _stext = .;
28989 @@ -104,13 +124,47 @@ SECTIONS
28990 IRQENTRY_TEXT
28991 *(.fixup)
28992 *(.gnu.warning)
28993 - /* End of text section */
28994 - _etext = .;
28995 } :text = 0x9090
28996
28997 - NOTES :text :note
28998 + . += __KERNEL_TEXT_OFFSET;
28999
29000 - EXCEPTION_TABLE(16) :text = 0x9090
29001 +#ifdef CONFIG_X86_32
29002 + . = ALIGN(PAGE_SIZE);
29003 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
29004 +
29005 +#ifdef CONFIG_PAX_KERNEXEC
29006 + MODULES_EXEC_VADDR = .;
29007 + BYTE(0)
29008 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
29009 + . = ALIGN(HPAGE_SIZE) - 1;
29010 + MODULES_EXEC_END = .;
29011 +#endif
29012 +
29013 + } :module
29014 +#endif
29015 +
29016 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
29017 + /* End of text section */
29018 + BYTE(0)
29019 + _etext = . - __KERNEL_TEXT_OFFSET;
29020 + }
29021 +
29022 +#ifdef CONFIG_X86_32
29023 + . = ALIGN(PAGE_SIZE);
29024 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
29025 + . = ALIGN(PAGE_SIZE);
29026 + *(.empty_zero_page)
29027 + *(.initial_pg_fixmap)
29028 + *(.initial_pg_pmd)
29029 + *(.initial_page_table)
29030 + *(.swapper_pg_dir)
29031 + } :rodata
29032 +#endif
29033 +
29034 + . = ALIGN(PAGE_SIZE);
29035 + NOTES :rodata :note
29036 +
29037 + EXCEPTION_TABLE(16) :rodata
29038
29039 #if defined(CONFIG_DEBUG_RODATA)
29040 /* .text should occupy whole number of pages */
29041 @@ -122,16 +176,20 @@ SECTIONS
29042
29043 /* Data */
29044 .data : AT(ADDR(.data) - LOAD_OFFSET) {
29045 +
29046 +#ifdef CONFIG_PAX_KERNEXEC
29047 + . = ALIGN(HPAGE_SIZE);
29048 +#else
29049 + . = ALIGN(PAGE_SIZE);
29050 +#endif
29051 +
29052 /* Start of data section */
29053 _sdata = .;
29054
29055 /* init_task */
29056 INIT_TASK_DATA(THREAD_SIZE)
29057
29058 -#ifdef CONFIG_X86_32
29059 - /* 32 bit has nosave before _edata */
29060 NOSAVE_DATA
29061 -#endif
29062
29063 PAGE_ALIGNED_DATA(PAGE_SIZE)
29064
29065 @@ -174,12 +232,19 @@ SECTIONS
29066 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
29067
29068 /* Init code and data - will be freed after init */
29069 - . = ALIGN(PAGE_SIZE);
29070 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
29071 + BYTE(0)
29072 +
29073 +#ifdef CONFIG_PAX_KERNEXEC
29074 + . = ALIGN(HPAGE_SIZE);
29075 +#else
29076 + . = ALIGN(PAGE_SIZE);
29077 +#endif
29078 +
29079 __init_begin = .; /* paired with __init_end */
29080 - }
29081 + } :init.begin
29082
29083 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
29084 +#ifdef CONFIG_SMP
29085 /*
29086 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
29087 * output PHDR, so the next output section - .init.text - should
29088 @@ -188,12 +253,27 @@ SECTIONS
29089 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
29090 #endif
29091
29092 - INIT_TEXT_SECTION(PAGE_SIZE)
29093 -#ifdef CONFIG_X86_64
29094 - :init
29095 -#endif
29096 + . = ALIGN(PAGE_SIZE);
29097 + init_begin = .;
29098 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
29099 + VMLINUX_SYMBOL(_sinittext) = .;
29100 + INIT_TEXT
29101 + VMLINUX_SYMBOL(_einittext) = .;
29102 + . = ALIGN(PAGE_SIZE);
29103 + } :text.init
29104
29105 - INIT_DATA_SECTION(16)
29106 + /*
29107 + * .exit.text is discard at runtime, not link time, to deal with
29108 + * references from .altinstructions and .eh_frame
29109 + */
29110 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29111 + EXIT_TEXT
29112 + . = ALIGN(16);
29113 + } :text.exit
29114 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
29115 +
29116 + . = ALIGN(PAGE_SIZE);
29117 + INIT_DATA_SECTION(16) :init
29118
29119 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
29120 __x86_cpu_dev_start = .;
29121 @@ -264,19 +344,12 @@ SECTIONS
29122 }
29123
29124 . = ALIGN(8);
29125 - /*
29126 - * .exit.text is discard at runtime, not link time, to deal with
29127 - * references from .altinstructions and .eh_frame
29128 - */
29129 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
29130 - EXIT_TEXT
29131 - }
29132
29133 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
29134 EXIT_DATA
29135 }
29136
29137 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
29138 +#ifndef CONFIG_SMP
29139 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
29140 #endif
29141
29142 @@ -295,16 +368,10 @@ SECTIONS
29143 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
29144 __smp_locks = .;
29145 *(.smp_locks)
29146 - . = ALIGN(PAGE_SIZE);
29147 __smp_locks_end = .;
29148 + . = ALIGN(PAGE_SIZE);
29149 }
29150
29151 -#ifdef CONFIG_X86_64
29152 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
29153 - NOSAVE_DATA
29154 - }
29155 -#endif
29156 -
29157 /* BSS */
29158 . = ALIGN(PAGE_SIZE);
29159 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
29160 @@ -320,6 +387,7 @@ SECTIONS
29161 __brk_base = .;
29162 . += 64 * 1024; /* 64k alignment slop space */
29163 *(.brk_reservation) /* areas brk users have reserved */
29164 + . = ALIGN(HPAGE_SIZE);
29165 __brk_limit = .;
29166 }
29167
29168 @@ -346,13 +414,12 @@ SECTIONS
29169 * for the boot processor.
29170 */
29171 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
29172 -INIT_PER_CPU(gdt_page);
29173 INIT_PER_CPU(irq_stack_union);
29174
29175 /*
29176 * Build-time check on the image size:
29177 */
29178 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
29179 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
29180 "kernel image bigger than KERNEL_IMAGE_SIZE");
29181
29182 #ifdef CONFIG_SMP
29183 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
29184 index e1e1e80..1400089 100644
29185 --- a/arch/x86/kernel/vsyscall_64.c
29186 +++ b/arch/x86/kernel/vsyscall_64.c
29187 @@ -54,15 +54,13 @@
29188
29189 DEFINE_VVAR(int, vgetcpu_mode);
29190
29191 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
29192 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
29193
29194 static int __init vsyscall_setup(char *str)
29195 {
29196 if (str) {
29197 if (!strcmp("emulate", str))
29198 vsyscall_mode = EMULATE;
29199 - else if (!strcmp("native", str))
29200 - vsyscall_mode = NATIVE;
29201 else if (!strcmp("none", str))
29202 vsyscall_mode = NONE;
29203 else
29204 @@ -279,8 +277,7 @@ do_ret:
29205 return true;
29206
29207 sigsegv:
29208 - force_sig(SIGSEGV, current);
29209 - return true;
29210 + do_group_exit(SIGKILL);
29211 }
29212
29213 /*
29214 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
29215 extern char __vsyscall_page;
29216 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
29217
29218 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
29219 - vsyscall_mode == NATIVE
29220 - ? PAGE_KERNEL_VSYSCALL
29221 - : PAGE_KERNEL_VVAR);
29222 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
29223 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
29224 (unsigned long)VSYSCALL_ADDR);
29225 }
29226 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
29227 index 04068192..4d75aa6 100644
29228 --- a/arch/x86/kernel/x8664_ksyms_64.c
29229 +++ b/arch/x86/kernel/x8664_ksyms_64.c
29230 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
29231 EXPORT_SYMBOL(copy_user_generic_unrolled);
29232 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
29233 EXPORT_SYMBOL(__copy_user_nocache);
29234 -EXPORT_SYMBOL(_copy_from_user);
29235 -EXPORT_SYMBOL(_copy_to_user);
29236
29237 EXPORT_SYMBOL(copy_page);
29238 EXPORT_SYMBOL(clear_page);
29239 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
29240 EXPORT_SYMBOL(___preempt_schedule_context);
29241 #endif
29242 #endif
29243 +
29244 +#ifdef CONFIG_PAX_PER_CPU_PGD
29245 +EXPORT_SYMBOL(cpu_pgd);
29246 +#endif
29247 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
29248 index e48b674..a451dd9 100644
29249 --- a/arch/x86/kernel/x86_init.c
29250 +++ b/arch/x86/kernel/x86_init.c
29251 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
29252 static void default_nmi_init(void) { };
29253 static int default_i8042_detect(void) { return 1; };
29254
29255 -struct x86_platform_ops x86_platform = {
29256 +struct x86_platform_ops x86_platform __read_only = {
29257 .calibrate_tsc = native_calibrate_tsc,
29258 .get_wallclock = mach_get_cmos_time,
29259 .set_wallclock = mach_set_rtc_mmss,
29260 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
29261 EXPORT_SYMBOL_GPL(x86_platform);
29262
29263 #if defined(CONFIG_PCI_MSI)
29264 -struct x86_msi_ops x86_msi = {
29265 +struct x86_msi_ops x86_msi __read_only = {
29266 .setup_msi_irqs = native_setup_msi_irqs,
29267 .compose_msi_msg = native_compose_msi_msg,
29268 .teardown_msi_irq = native_teardown_msi_irq,
29269 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
29270 }
29271 #endif
29272
29273 -struct x86_io_apic_ops x86_io_apic_ops = {
29274 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
29275 .init = native_io_apic_init_mappings,
29276 .read = native_io_apic_read,
29277 .write = native_io_apic_write,
29278 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
29279 index 4c540c4..0b985b0 100644
29280 --- a/arch/x86/kernel/xsave.c
29281 +++ b/arch/x86/kernel/xsave.c
29282 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29283
29284 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
29285 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
29286 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29287 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29288
29289 if (!use_xsave())
29290 return err;
29291
29292 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
29293 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
29294
29295 /*
29296 * Read the xstate_bv which we copied (directly from the cpu or
29297 * from the state in task struct) to the user buffers.
29298 */
29299 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29300 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29301
29302 /*
29303 * For legacy compatible, we always set FP/SSE bits in the bit
29304 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29305 */
29306 xstate_bv |= XSTATE_FPSSE;
29307
29308 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29309 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29310
29311 return err;
29312 }
29313 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
29314 {
29315 int err;
29316
29317 + buf = (struct xsave_struct __user *)____m(buf);
29318 if (use_xsave())
29319 err = xsave_user(buf);
29320 else if (use_fxsr())
29321 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
29322 */
29323 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
29324 {
29325 + buf = (void __user *)____m(buf);
29326 if (use_xsave()) {
29327 if ((unsigned long)buf % 64 || fx_only) {
29328 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
29329 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
29330 index 38a0afe..94421a9 100644
29331 --- a/arch/x86/kvm/cpuid.c
29332 +++ b/arch/x86/kvm/cpuid.c
29333 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
29334 struct kvm_cpuid2 *cpuid,
29335 struct kvm_cpuid_entry2 __user *entries)
29336 {
29337 - int r;
29338 + int r, i;
29339
29340 r = -E2BIG;
29341 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
29342 goto out;
29343 r = -EFAULT;
29344 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
29345 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29346 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29347 goto out;
29348 + for (i = 0; i < cpuid->nent; ++i) {
29349 + struct kvm_cpuid_entry2 cpuid_entry;
29350 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
29351 + goto out;
29352 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
29353 + }
29354 vcpu->arch.cpuid_nent = cpuid->nent;
29355 kvm_apic_set_version(vcpu);
29356 kvm_x86_ops->cpuid_update(vcpu);
29357 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
29358 struct kvm_cpuid2 *cpuid,
29359 struct kvm_cpuid_entry2 __user *entries)
29360 {
29361 - int r;
29362 + int r, i;
29363
29364 r = -E2BIG;
29365 if (cpuid->nent < vcpu->arch.cpuid_nent)
29366 goto out;
29367 r = -EFAULT;
29368 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
29369 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29370 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29371 goto out;
29372 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
29373 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
29374 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
29375 + goto out;
29376 + }
29377 return 0;
29378
29379 out:
29380 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29381 index 08e8a89..0e9183e 100644
29382 --- a/arch/x86/kvm/lapic.c
29383 +++ b/arch/x86/kvm/lapic.c
29384 @@ -55,7 +55,7 @@
29385 #define APIC_BUS_CYCLE_NS 1
29386
29387 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29388 -#define apic_debug(fmt, arg...)
29389 +#define apic_debug(fmt, arg...) do {} while (0)
29390
29391 #define APIC_LVT_NUM 6
29392 /* 14 is the version for Xeon and Pentium 8.4.8*/
29393 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29394 index 4107765..d9eb358 100644
29395 --- a/arch/x86/kvm/paging_tmpl.h
29396 +++ b/arch/x86/kvm/paging_tmpl.h
29397 @@ -331,7 +331,7 @@ retry_walk:
29398 if (unlikely(kvm_is_error_hva(host_addr)))
29399 goto error;
29400
29401 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29402 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29403 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29404 goto error;
29405 walker->ptep_user[walker->level - 1] = ptep_user;
29406 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29407 index 78dadc3..fd84599 100644
29408 --- a/arch/x86/kvm/svm.c
29409 +++ b/arch/x86/kvm/svm.c
29410 @@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29411 int cpu = raw_smp_processor_id();
29412
29413 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29414 +
29415 + pax_open_kernel();
29416 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29417 + pax_close_kernel();
29418 +
29419 load_TR_desc();
29420 }
29421
29422 @@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29423 #endif
29424 #endif
29425
29426 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29427 + __set_fs(current_thread_info()->addr_limit);
29428 +#endif
29429 +
29430 reload_tss(vcpu);
29431
29432 local_irq_disable();
29433 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29434 index 41a5426..c0b3c00 100644
29435 --- a/arch/x86/kvm/vmx.c
29436 +++ b/arch/x86/kvm/vmx.c
29437 @@ -1341,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29438 #endif
29439 }
29440
29441 -static void vmcs_clear_bits(unsigned long field, u32 mask)
29442 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29443 {
29444 vmcs_writel(field, vmcs_readl(field) & ~mask);
29445 }
29446
29447 -static void vmcs_set_bits(unsigned long field, u32 mask)
29448 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
29449 {
29450 vmcs_writel(field, vmcs_readl(field) | mask);
29451 }
29452 @@ -1606,7 +1606,11 @@ static void reload_tss(void)
29453 struct desc_struct *descs;
29454
29455 descs = (void *)gdt->address;
29456 +
29457 + pax_open_kernel();
29458 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29459 + pax_close_kernel();
29460 +
29461 load_TR_desc();
29462 }
29463
29464 @@ -1834,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29465 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29466 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29467
29468 +#ifdef CONFIG_PAX_PER_CPU_PGD
29469 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29470 +#endif
29471 +
29472 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29473 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29474 vmx->loaded_vmcs->cpu = cpu;
29475 @@ -2123,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29476 * reads and returns guest's timestamp counter "register"
29477 * guest_tsc = host_tsc + tsc_offset -- 21.3
29478 */
29479 -static u64 guest_read_tsc(void)
29480 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
29481 {
29482 u64 host_tsc, tsc_offset;
29483
29484 @@ -3114,8 +3122,11 @@ static __init int hardware_setup(void)
29485 if (!cpu_has_vmx_flexpriority())
29486 flexpriority_enabled = 0;
29487
29488 - if (!cpu_has_vmx_tpr_shadow())
29489 - kvm_x86_ops->update_cr8_intercept = NULL;
29490 + if (!cpu_has_vmx_tpr_shadow()) {
29491 + pax_open_kernel();
29492 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29493 + pax_close_kernel();
29494 + }
29495
29496 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29497 kvm_disable_largepages();
29498 @@ -3126,13 +3137,15 @@ static __init int hardware_setup(void)
29499 if (!cpu_has_vmx_apicv())
29500 enable_apicv = 0;
29501
29502 + pax_open_kernel();
29503 if (enable_apicv)
29504 - kvm_x86_ops->update_cr8_intercept = NULL;
29505 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29506 else {
29507 - kvm_x86_ops->hwapic_irr_update = NULL;
29508 - kvm_x86_ops->deliver_posted_interrupt = NULL;
29509 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29510 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29511 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29512 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29513 }
29514 + pax_close_kernel();
29515
29516 if (nested)
29517 nested_vmx_setup_ctls_msrs();
29518 @@ -4242,7 +4255,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29519 unsigned long cr4;
29520
29521 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29522 +
29523 +#ifndef CONFIG_PAX_PER_CPU_PGD
29524 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29525 +#endif
29526
29527 /* Save the most likely value for this task's CR4 in the VMCS. */
29528 cr4 = read_cr4();
29529 @@ -4269,7 +4285,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29530 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29531 vmx->host_idt_base = dt.address;
29532
29533 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29534 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29535
29536 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29537 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29538 @@ -7475,6 +7491,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29539 "jmp 2f \n\t"
29540 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29541 "2: "
29542 +
29543 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29544 + "ljmp %[cs],$3f\n\t"
29545 + "3: "
29546 +#endif
29547 +
29548 /* Save guest registers, load host registers, keep flags */
29549 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29550 "pop %0 \n\t"
29551 @@ -7527,6 +7549,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29552 #endif
29553 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29554 [wordsize]"i"(sizeof(ulong))
29555 +
29556 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29557 + ,[cs]"i"(__KERNEL_CS)
29558 +#endif
29559 +
29560 : "cc", "memory"
29561 #ifdef CONFIG_X86_64
29562 , "rax", "rbx", "rdi", "rsi"
29563 @@ -7540,7 +7567,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29564 if (debugctlmsr)
29565 update_debugctlmsr(debugctlmsr);
29566
29567 -#ifndef CONFIG_X86_64
29568 +#ifdef CONFIG_X86_32
29569 /*
29570 * The sysexit path does not restore ds/es, so we must set them to
29571 * a reasonable value ourselves.
29572 @@ -7549,8 +7576,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29573 * may be executed in interrupt context, which saves and restore segments
29574 * around it, nullifying its effect.
29575 */
29576 - loadsegment(ds, __USER_DS);
29577 - loadsegment(es, __USER_DS);
29578 + loadsegment(ds, __KERNEL_DS);
29579 + loadsegment(es, __KERNEL_DS);
29580 + loadsegment(ss, __KERNEL_DS);
29581 +
29582 +#ifdef CONFIG_PAX_KERNEXEC
29583 + loadsegment(fs, __KERNEL_PERCPU);
29584 +#endif
29585 +
29586 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29587 + __set_fs(current_thread_info()->addr_limit);
29588 +#endif
29589 +
29590 #endif
29591
29592 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29593 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29594 index d6aeccf..cea125a 100644
29595 --- a/arch/x86/kvm/x86.c
29596 +++ b/arch/x86/kvm/x86.c
29597 @@ -1857,8 +1857,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29598 {
29599 struct kvm *kvm = vcpu->kvm;
29600 int lm = is_long_mode(vcpu);
29601 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29602 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29603 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29604 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29605 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29606 : kvm->arch.xen_hvm_config.blob_size_32;
29607 u32 page_num = data & ~PAGE_MASK;
29608 @@ -2779,6 +2779,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29609 if (n < msr_list.nmsrs)
29610 goto out;
29611 r = -EFAULT;
29612 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29613 + goto out;
29614 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29615 num_msrs_to_save * sizeof(u32)))
29616 goto out;
29617 @@ -5639,7 +5641,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29618 };
29619 #endif
29620
29621 -int kvm_arch_init(void *opaque)
29622 +int kvm_arch_init(const void *opaque)
29623 {
29624 int r;
29625 struct kvm_x86_ops *ops = opaque;
29626 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29627 index aae9413..d11e829 100644
29628 --- a/arch/x86/lguest/boot.c
29629 +++ b/arch/x86/lguest/boot.c
29630 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29631 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29632 * Launcher to reboot us.
29633 */
29634 -static void lguest_restart(char *reason)
29635 +static __noreturn void lguest_restart(char *reason)
29636 {
29637 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29638 + BUG();
29639 }
29640
29641 /*G:050
29642 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29643 index 00933d5..3a64af9 100644
29644 --- a/arch/x86/lib/atomic64_386_32.S
29645 +++ b/arch/x86/lib/atomic64_386_32.S
29646 @@ -48,6 +48,10 @@ BEGIN(read)
29647 movl (v), %eax
29648 movl 4(v), %edx
29649 RET_ENDP
29650 +BEGIN(read_unchecked)
29651 + movl (v), %eax
29652 + movl 4(v), %edx
29653 +RET_ENDP
29654 #undef v
29655
29656 #define v %esi
29657 @@ -55,6 +59,10 @@ BEGIN(set)
29658 movl %ebx, (v)
29659 movl %ecx, 4(v)
29660 RET_ENDP
29661 +BEGIN(set_unchecked)
29662 + movl %ebx, (v)
29663 + movl %ecx, 4(v)
29664 +RET_ENDP
29665 #undef v
29666
29667 #define v %esi
29668 @@ -70,6 +78,20 @@ RET_ENDP
29669 BEGIN(add)
29670 addl %eax, (v)
29671 adcl %edx, 4(v)
29672 +
29673 +#ifdef CONFIG_PAX_REFCOUNT
29674 + jno 0f
29675 + subl %eax, (v)
29676 + sbbl %edx, 4(v)
29677 + int $4
29678 +0:
29679 + _ASM_EXTABLE(0b, 0b)
29680 +#endif
29681 +
29682 +RET_ENDP
29683 +BEGIN(add_unchecked)
29684 + addl %eax, (v)
29685 + adcl %edx, 4(v)
29686 RET_ENDP
29687 #undef v
29688
29689 @@ -77,6 +99,24 @@ RET_ENDP
29690 BEGIN(add_return)
29691 addl (v), %eax
29692 adcl 4(v), %edx
29693 +
29694 +#ifdef CONFIG_PAX_REFCOUNT
29695 + into
29696 +1234:
29697 + _ASM_EXTABLE(1234b, 2f)
29698 +#endif
29699 +
29700 + movl %eax, (v)
29701 + movl %edx, 4(v)
29702 +
29703 +#ifdef CONFIG_PAX_REFCOUNT
29704 +2:
29705 +#endif
29706 +
29707 +RET_ENDP
29708 +BEGIN(add_return_unchecked)
29709 + addl (v), %eax
29710 + adcl 4(v), %edx
29711 movl %eax, (v)
29712 movl %edx, 4(v)
29713 RET_ENDP
29714 @@ -86,6 +126,20 @@ RET_ENDP
29715 BEGIN(sub)
29716 subl %eax, (v)
29717 sbbl %edx, 4(v)
29718 +
29719 +#ifdef CONFIG_PAX_REFCOUNT
29720 + jno 0f
29721 + addl %eax, (v)
29722 + adcl %edx, 4(v)
29723 + int $4
29724 +0:
29725 + _ASM_EXTABLE(0b, 0b)
29726 +#endif
29727 +
29728 +RET_ENDP
29729 +BEGIN(sub_unchecked)
29730 + subl %eax, (v)
29731 + sbbl %edx, 4(v)
29732 RET_ENDP
29733 #undef v
29734
29735 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29736 sbbl $0, %edx
29737 addl (v), %eax
29738 adcl 4(v), %edx
29739 +
29740 +#ifdef CONFIG_PAX_REFCOUNT
29741 + into
29742 +1234:
29743 + _ASM_EXTABLE(1234b, 2f)
29744 +#endif
29745 +
29746 + movl %eax, (v)
29747 + movl %edx, 4(v)
29748 +
29749 +#ifdef CONFIG_PAX_REFCOUNT
29750 +2:
29751 +#endif
29752 +
29753 +RET_ENDP
29754 +BEGIN(sub_return_unchecked)
29755 + negl %edx
29756 + negl %eax
29757 + sbbl $0, %edx
29758 + addl (v), %eax
29759 + adcl 4(v), %edx
29760 movl %eax, (v)
29761 movl %edx, 4(v)
29762 RET_ENDP
29763 @@ -105,6 +180,20 @@ RET_ENDP
29764 BEGIN(inc)
29765 addl $1, (v)
29766 adcl $0, 4(v)
29767 +
29768 +#ifdef CONFIG_PAX_REFCOUNT
29769 + jno 0f
29770 + subl $1, (v)
29771 + sbbl $0, 4(v)
29772 + int $4
29773 +0:
29774 + _ASM_EXTABLE(0b, 0b)
29775 +#endif
29776 +
29777 +RET_ENDP
29778 +BEGIN(inc_unchecked)
29779 + addl $1, (v)
29780 + adcl $0, 4(v)
29781 RET_ENDP
29782 #undef v
29783
29784 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29785 movl 4(v), %edx
29786 addl $1, %eax
29787 adcl $0, %edx
29788 +
29789 +#ifdef CONFIG_PAX_REFCOUNT
29790 + into
29791 +1234:
29792 + _ASM_EXTABLE(1234b, 2f)
29793 +#endif
29794 +
29795 + movl %eax, (v)
29796 + movl %edx, 4(v)
29797 +
29798 +#ifdef CONFIG_PAX_REFCOUNT
29799 +2:
29800 +#endif
29801 +
29802 +RET_ENDP
29803 +BEGIN(inc_return_unchecked)
29804 + movl (v), %eax
29805 + movl 4(v), %edx
29806 + addl $1, %eax
29807 + adcl $0, %edx
29808 movl %eax, (v)
29809 movl %edx, 4(v)
29810 RET_ENDP
29811 @@ -123,6 +232,20 @@ RET_ENDP
29812 BEGIN(dec)
29813 subl $1, (v)
29814 sbbl $0, 4(v)
29815 +
29816 +#ifdef CONFIG_PAX_REFCOUNT
29817 + jno 0f
29818 + addl $1, (v)
29819 + adcl $0, 4(v)
29820 + int $4
29821 +0:
29822 + _ASM_EXTABLE(0b, 0b)
29823 +#endif
29824 +
29825 +RET_ENDP
29826 +BEGIN(dec_unchecked)
29827 + subl $1, (v)
29828 + sbbl $0, 4(v)
29829 RET_ENDP
29830 #undef v
29831
29832 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29833 movl 4(v), %edx
29834 subl $1, %eax
29835 sbbl $0, %edx
29836 +
29837 +#ifdef CONFIG_PAX_REFCOUNT
29838 + into
29839 +1234:
29840 + _ASM_EXTABLE(1234b, 2f)
29841 +#endif
29842 +
29843 + movl %eax, (v)
29844 + movl %edx, 4(v)
29845 +
29846 +#ifdef CONFIG_PAX_REFCOUNT
29847 +2:
29848 +#endif
29849 +
29850 +RET_ENDP
29851 +BEGIN(dec_return_unchecked)
29852 + movl (v), %eax
29853 + movl 4(v), %edx
29854 + subl $1, %eax
29855 + sbbl $0, %edx
29856 movl %eax, (v)
29857 movl %edx, 4(v)
29858 RET_ENDP
29859 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29860 adcl %edx, %edi
29861 addl (v), %eax
29862 adcl 4(v), %edx
29863 +
29864 +#ifdef CONFIG_PAX_REFCOUNT
29865 + into
29866 +1234:
29867 + _ASM_EXTABLE(1234b, 2f)
29868 +#endif
29869 +
29870 cmpl %eax, %ecx
29871 je 3f
29872 1:
29873 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29874 1:
29875 addl $1, %eax
29876 adcl $0, %edx
29877 +
29878 +#ifdef CONFIG_PAX_REFCOUNT
29879 + into
29880 +1234:
29881 + _ASM_EXTABLE(1234b, 2f)
29882 +#endif
29883 +
29884 movl %eax, (v)
29885 movl %edx, 4(v)
29886 movl $1, %eax
29887 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29888 movl 4(v), %edx
29889 subl $1, %eax
29890 sbbl $0, %edx
29891 +
29892 +#ifdef CONFIG_PAX_REFCOUNT
29893 + into
29894 +1234:
29895 + _ASM_EXTABLE(1234b, 1f)
29896 +#endif
29897 +
29898 js 1f
29899 movl %eax, (v)
29900 movl %edx, 4(v)
29901 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29902 index f5cc9eb..51fa319 100644
29903 --- a/arch/x86/lib/atomic64_cx8_32.S
29904 +++ b/arch/x86/lib/atomic64_cx8_32.S
29905 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29906 CFI_STARTPROC
29907
29908 read64 %ecx
29909 + pax_force_retaddr
29910 ret
29911 CFI_ENDPROC
29912 ENDPROC(atomic64_read_cx8)
29913
29914 +ENTRY(atomic64_read_unchecked_cx8)
29915 + CFI_STARTPROC
29916 +
29917 + read64 %ecx
29918 + pax_force_retaddr
29919 + ret
29920 + CFI_ENDPROC
29921 +ENDPROC(atomic64_read_unchecked_cx8)
29922 +
29923 ENTRY(atomic64_set_cx8)
29924 CFI_STARTPROC
29925
29926 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29927 cmpxchg8b (%esi)
29928 jne 1b
29929
29930 + pax_force_retaddr
29931 ret
29932 CFI_ENDPROC
29933 ENDPROC(atomic64_set_cx8)
29934
29935 +ENTRY(atomic64_set_unchecked_cx8)
29936 + CFI_STARTPROC
29937 +
29938 +1:
29939 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29940 + * are atomic on 586 and newer */
29941 + cmpxchg8b (%esi)
29942 + jne 1b
29943 +
29944 + pax_force_retaddr
29945 + ret
29946 + CFI_ENDPROC
29947 +ENDPROC(atomic64_set_unchecked_cx8)
29948 +
29949 ENTRY(atomic64_xchg_cx8)
29950 CFI_STARTPROC
29951
29952 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29953 cmpxchg8b (%esi)
29954 jne 1b
29955
29956 + pax_force_retaddr
29957 ret
29958 CFI_ENDPROC
29959 ENDPROC(atomic64_xchg_cx8)
29960
29961 -.macro addsub_return func ins insc
29962 -ENTRY(atomic64_\func\()_return_cx8)
29963 +.macro addsub_return func ins insc unchecked=""
29964 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29965 CFI_STARTPROC
29966 SAVE ebp
29967 SAVE ebx
29968 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29969 movl %edx, %ecx
29970 \ins\()l %esi, %ebx
29971 \insc\()l %edi, %ecx
29972 +
29973 +.ifb \unchecked
29974 +#ifdef CONFIG_PAX_REFCOUNT
29975 + into
29976 +2:
29977 + _ASM_EXTABLE(2b, 3f)
29978 +#endif
29979 +.endif
29980 +
29981 LOCK_PREFIX
29982 cmpxchg8b (%ebp)
29983 jne 1b
29984 -
29985 -10:
29986 movl %ebx, %eax
29987 movl %ecx, %edx
29988 +
29989 +.ifb \unchecked
29990 +#ifdef CONFIG_PAX_REFCOUNT
29991 +3:
29992 +#endif
29993 +.endif
29994 +
29995 RESTORE edi
29996 RESTORE esi
29997 RESTORE ebx
29998 RESTORE ebp
29999 + pax_force_retaddr
30000 ret
30001 CFI_ENDPROC
30002 -ENDPROC(atomic64_\func\()_return_cx8)
30003 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30004 .endm
30005
30006 addsub_return add add adc
30007 addsub_return sub sub sbb
30008 +addsub_return add add adc _unchecked
30009 +addsub_return sub sub sbb _unchecked
30010
30011 -.macro incdec_return func ins insc
30012 -ENTRY(atomic64_\func\()_return_cx8)
30013 +.macro incdec_return func ins insc unchecked=""
30014 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
30015 CFI_STARTPROC
30016 SAVE ebx
30017
30018 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
30019 movl %edx, %ecx
30020 \ins\()l $1, %ebx
30021 \insc\()l $0, %ecx
30022 +
30023 +.ifb \unchecked
30024 +#ifdef CONFIG_PAX_REFCOUNT
30025 + into
30026 +2:
30027 + _ASM_EXTABLE(2b, 3f)
30028 +#endif
30029 +.endif
30030 +
30031 LOCK_PREFIX
30032 cmpxchg8b (%esi)
30033 jne 1b
30034
30035 -10:
30036 movl %ebx, %eax
30037 movl %ecx, %edx
30038 +
30039 +.ifb \unchecked
30040 +#ifdef CONFIG_PAX_REFCOUNT
30041 +3:
30042 +#endif
30043 +.endif
30044 +
30045 RESTORE ebx
30046 + pax_force_retaddr
30047 ret
30048 CFI_ENDPROC
30049 -ENDPROC(atomic64_\func\()_return_cx8)
30050 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30051 .endm
30052
30053 incdec_return inc add adc
30054 incdec_return dec sub sbb
30055 +incdec_return inc add adc _unchecked
30056 +incdec_return dec sub sbb _unchecked
30057
30058 ENTRY(atomic64_dec_if_positive_cx8)
30059 CFI_STARTPROC
30060 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
30061 movl %edx, %ecx
30062 subl $1, %ebx
30063 sbb $0, %ecx
30064 +
30065 +#ifdef CONFIG_PAX_REFCOUNT
30066 + into
30067 +1234:
30068 + _ASM_EXTABLE(1234b, 2f)
30069 +#endif
30070 +
30071 js 2f
30072 LOCK_PREFIX
30073 cmpxchg8b (%esi)
30074 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
30075 movl %ebx, %eax
30076 movl %ecx, %edx
30077 RESTORE ebx
30078 + pax_force_retaddr
30079 ret
30080 CFI_ENDPROC
30081 ENDPROC(atomic64_dec_if_positive_cx8)
30082 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30083 movl %edx, %ecx
30084 addl %ebp, %ebx
30085 adcl %edi, %ecx
30086 +
30087 +#ifdef CONFIG_PAX_REFCOUNT
30088 + into
30089 +1234:
30090 + _ASM_EXTABLE(1234b, 3f)
30091 +#endif
30092 +
30093 LOCK_PREFIX
30094 cmpxchg8b (%esi)
30095 jne 1b
30096 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30097 CFI_ADJUST_CFA_OFFSET -8
30098 RESTORE ebx
30099 RESTORE ebp
30100 + pax_force_retaddr
30101 ret
30102 4:
30103 cmpl %edx, 4(%esp)
30104 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30105 xorl %ecx, %ecx
30106 addl $1, %ebx
30107 adcl %edx, %ecx
30108 +
30109 +#ifdef CONFIG_PAX_REFCOUNT
30110 + into
30111 +1234:
30112 + _ASM_EXTABLE(1234b, 3f)
30113 +#endif
30114 +
30115 LOCK_PREFIX
30116 cmpxchg8b (%esi)
30117 jne 1b
30118 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30119 movl $1, %eax
30120 3:
30121 RESTORE ebx
30122 + pax_force_retaddr
30123 ret
30124 CFI_ENDPROC
30125 ENDPROC(atomic64_inc_not_zero_cx8)
30126 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30127 index e78b8eee..7e173a8 100644
30128 --- a/arch/x86/lib/checksum_32.S
30129 +++ b/arch/x86/lib/checksum_32.S
30130 @@ -29,7 +29,8 @@
30131 #include <asm/dwarf2.h>
30132 #include <asm/errno.h>
30133 #include <asm/asm.h>
30134 -
30135 +#include <asm/segment.h>
30136 +
30137 /*
30138 * computes a partial checksum, e.g. for TCP/UDP fragments
30139 */
30140 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30141
30142 #define ARGBASE 16
30143 #define FP 12
30144 -
30145 -ENTRY(csum_partial_copy_generic)
30146 +
30147 +ENTRY(csum_partial_copy_generic_to_user)
30148 CFI_STARTPROC
30149 +
30150 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30151 + pushl_cfi %gs
30152 + popl_cfi %es
30153 + jmp csum_partial_copy_generic
30154 +#endif
30155 +
30156 +ENTRY(csum_partial_copy_generic_from_user)
30157 +
30158 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30159 + pushl_cfi %gs
30160 + popl_cfi %ds
30161 +#endif
30162 +
30163 +ENTRY(csum_partial_copy_generic)
30164 subl $4,%esp
30165 CFI_ADJUST_CFA_OFFSET 4
30166 pushl_cfi %edi
30167 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30168 jmp 4f
30169 SRC(1: movw (%esi), %bx )
30170 addl $2, %esi
30171 -DST( movw %bx, (%edi) )
30172 +DST( movw %bx, %es:(%edi) )
30173 addl $2, %edi
30174 addw %bx, %ax
30175 adcl $0, %eax
30176 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30177 SRC(1: movl (%esi), %ebx )
30178 SRC( movl 4(%esi), %edx )
30179 adcl %ebx, %eax
30180 -DST( movl %ebx, (%edi) )
30181 +DST( movl %ebx, %es:(%edi) )
30182 adcl %edx, %eax
30183 -DST( movl %edx, 4(%edi) )
30184 +DST( movl %edx, %es:4(%edi) )
30185
30186 SRC( movl 8(%esi), %ebx )
30187 SRC( movl 12(%esi), %edx )
30188 adcl %ebx, %eax
30189 -DST( movl %ebx, 8(%edi) )
30190 +DST( movl %ebx, %es:8(%edi) )
30191 adcl %edx, %eax
30192 -DST( movl %edx, 12(%edi) )
30193 +DST( movl %edx, %es:12(%edi) )
30194
30195 SRC( movl 16(%esi), %ebx )
30196 SRC( movl 20(%esi), %edx )
30197 adcl %ebx, %eax
30198 -DST( movl %ebx, 16(%edi) )
30199 +DST( movl %ebx, %es:16(%edi) )
30200 adcl %edx, %eax
30201 -DST( movl %edx, 20(%edi) )
30202 +DST( movl %edx, %es:20(%edi) )
30203
30204 SRC( movl 24(%esi), %ebx )
30205 SRC( movl 28(%esi), %edx )
30206 adcl %ebx, %eax
30207 -DST( movl %ebx, 24(%edi) )
30208 +DST( movl %ebx, %es:24(%edi) )
30209 adcl %edx, %eax
30210 -DST( movl %edx, 28(%edi) )
30211 +DST( movl %edx, %es:28(%edi) )
30212
30213 lea 32(%esi), %esi
30214 lea 32(%edi), %edi
30215 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30216 shrl $2, %edx # This clears CF
30217 SRC(3: movl (%esi), %ebx )
30218 adcl %ebx, %eax
30219 -DST( movl %ebx, (%edi) )
30220 +DST( movl %ebx, %es:(%edi) )
30221 lea 4(%esi), %esi
30222 lea 4(%edi), %edi
30223 dec %edx
30224 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30225 jb 5f
30226 SRC( movw (%esi), %cx )
30227 leal 2(%esi), %esi
30228 -DST( movw %cx, (%edi) )
30229 +DST( movw %cx, %es:(%edi) )
30230 leal 2(%edi), %edi
30231 je 6f
30232 shll $16,%ecx
30233 SRC(5: movb (%esi), %cl )
30234 -DST( movb %cl, (%edi) )
30235 +DST( movb %cl, %es:(%edi) )
30236 6: addl %ecx, %eax
30237 adcl $0, %eax
30238 7:
30239 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30240
30241 6001:
30242 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30243 - movl $-EFAULT, (%ebx)
30244 + movl $-EFAULT, %ss:(%ebx)
30245
30246 # zero the complete destination - computing the rest
30247 # is too much work
30248 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30249
30250 6002:
30251 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30252 - movl $-EFAULT,(%ebx)
30253 + movl $-EFAULT,%ss:(%ebx)
30254 jmp 5000b
30255
30256 .previous
30257
30258 + pushl_cfi %ss
30259 + popl_cfi %ds
30260 + pushl_cfi %ss
30261 + popl_cfi %es
30262 popl_cfi %ebx
30263 CFI_RESTORE ebx
30264 popl_cfi %esi
30265 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30266 popl_cfi %ecx # equivalent to addl $4,%esp
30267 ret
30268 CFI_ENDPROC
30269 -ENDPROC(csum_partial_copy_generic)
30270 +ENDPROC(csum_partial_copy_generic_to_user)
30271
30272 #else
30273
30274 /* Version for PentiumII/PPro */
30275
30276 #define ROUND1(x) \
30277 + nop; nop; nop; \
30278 SRC(movl x(%esi), %ebx ) ; \
30279 addl %ebx, %eax ; \
30280 - DST(movl %ebx, x(%edi) ) ;
30281 + DST(movl %ebx, %es:x(%edi)) ;
30282
30283 #define ROUND(x) \
30284 + nop; nop; nop; \
30285 SRC(movl x(%esi), %ebx ) ; \
30286 adcl %ebx, %eax ; \
30287 - DST(movl %ebx, x(%edi) ) ;
30288 + DST(movl %ebx, %es:x(%edi)) ;
30289
30290 #define ARGBASE 12
30291 -
30292 -ENTRY(csum_partial_copy_generic)
30293 +
30294 +ENTRY(csum_partial_copy_generic_to_user)
30295 CFI_STARTPROC
30296 +
30297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30298 + pushl_cfi %gs
30299 + popl_cfi %es
30300 + jmp csum_partial_copy_generic
30301 +#endif
30302 +
30303 +ENTRY(csum_partial_copy_generic_from_user)
30304 +
30305 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30306 + pushl_cfi %gs
30307 + popl_cfi %ds
30308 +#endif
30309 +
30310 +ENTRY(csum_partial_copy_generic)
30311 pushl_cfi %ebx
30312 CFI_REL_OFFSET ebx, 0
30313 pushl_cfi %edi
30314 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30315 subl %ebx, %edi
30316 lea -1(%esi),%edx
30317 andl $-32,%edx
30318 - lea 3f(%ebx,%ebx), %ebx
30319 + lea 3f(%ebx,%ebx,2), %ebx
30320 testl %esi, %esi
30321 jmp *%ebx
30322 1: addl $64,%esi
30323 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30324 jb 5f
30325 SRC( movw (%esi), %dx )
30326 leal 2(%esi), %esi
30327 -DST( movw %dx, (%edi) )
30328 +DST( movw %dx, %es:(%edi) )
30329 leal 2(%edi), %edi
30330 je 6f
30331 shll $16,%edx
30332 5:
30333 SRC( movb (%esi), %dl )
30334 -DST( movb %dl, (%edi) )
30335 +DST( movb %dl, %es:(%edi) )
30336 6: addl %edx, %eax
30337 adcl $0, %eax
30338 7:
30339 .section .fixup, "ax"
30340 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30341 - movl $-EFAULT, (%ebx)
30342 + movl $-EFAULT, %ss:(%ebx)
30343 # zero the complete destination (computing the rest is too much work)
30344 movl ARGBASE+8(%esp),%edi # dst
30345 movl ARGBASE+12(%esp),%ecx # len
30346 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30347 rep; stosb
30348 jmp 7b
30349 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30350 - movl $-EFAULT, (%ebx)
30351 + movl $-EFAULT, %ss:(%ebx)
30352 jmp 7b
30353 .previous
30354
30355 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30356 + pushl_cfi %ss
30357 + popl_cfi %ds
30358 + pushl_cfi %ss
30359 + popl_cfi %es
30360 +#endif
30361 +
30362 popl_cfi %esi
30363 CFI_RESTORE esi
30364 popl_cfi %edi
30365 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30366 CFI_RESTORE ebx
30367 ret
30368 CFI_ENDPROC
30369 -ENDPROC(csum_partial_copy_generic)
30370 +ENDPROC(csum_partial_copy_generic_to_user)
30371
30372 #undef ROUND
30373 #undef ROUND1
30374 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30375 index f2145cf..cea889d 100644
30376 --- a/arch/x86/lib/clear_page_64.S
30377 +++ b/arch/x86/lib/clear_page_64.S
30378 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30379 movl $4096/8,%ecx
30380 xorl %eax,%eax
30381 rep stosq
30382 + pax_force_retaddr
30383 ret
30384 CFI_ENDPROC
30385 ENDPROC(clear_page_c)
30386 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30387 movl $4096,%ecx
30388 xorl %eax,%eax
30389 rep stosb
30390 + pax_force_retaddr
30391 ret
30392 CFI_ENDPROC
30393 ENDPROC(clear_page_c_e)
30394 @@ -43,6 +45,7 @@ ENTRY(clear_page)
30395 leaq 64(%rdi),%rdi
30396 jnz .Lloop
30397 nop
30398 + pax_force_retaddr
30399 ret
30400 CFI_ENDPROC
30401 .Lclear_page_end:
30402 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
30403
30404 #include <asm/cpufeature.h>
30405
30406 - .section .altinstr_replacement,"ax"
30407 + .section .altinstr_replacement,"a"
30408 1: .byte 0xeb /* jmp <disp8> */
30409 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30410 2: .byte 0xeb /* jmp <disp8> */
30411 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30412 index 1e572c5..2a162cd 100644
30413 --- a/arch/x86/lib/cmpxchg16b_emu.S
30414 +++ b/arch/x86/lib/cmpxchg16b_emu.S
30415 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30416
30417 popf
30418 mov $1, %al
30419 + pax_force_retaddr
30420 ret
30421
30422 not_same:
30423 popf
30424 xor %al,%al
30425 + pax_force_retaddr
30426 ret
30427
30428 CFI_ENDPROC
30429 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30430 index 176cca6..e0d658e 100644
30431 --- a/arch/x86/lib/copy_page_64.S
30432 +++ b/arch/x86/lib/copy_page_64.S
30433 @@ -9,6 +9,7 @@ copy_page_rep:
30434 CFI_STARTPROC
30435 movl $4096/8, %ecx
30436 rep movsq
30437 + pax_force_retaddr
30438 ret
30439 CFI_ENDPROC
30440 ENDPROC(copy_page_rep)
30441 @@ -24,8 +25,8 @@ ENTRY(copy_page)
30442 CFI_ADJUST_CFA_OFFSET 2*8
30443 movq %rbx, (%rsp)
30444 CFI_REL_OFFSET rbx, 0
30445 - movq %r12, 1*8(%rsp)
30446 - CFI_REL_OFFSET r12, 1*8
30447 + movq %r13, 1*8(%rsp)
30448 + CFI_REL_OFFSET r13, 1*8
30449
30450 movl $(4096/64)-5, %ecx
30451 .p2align 4
30452 @@ -38,7 +39,7 @@ ENTRY(copy_page)
30453 movq 0x8*4(%rsi), %r9
30454 movq 0x8*5(%rsi), %r10
30455 movq 0x8*6(%rsi), %r11
30456 - movq 0x8*7(%rsi), %r12
30457 + movq 0x8*7(%rsi), %r13
30458
30459 prefetcht0 5*64(%rsi)
30460
30461 @@ -49,7 +50,7 @@ ENTRY(copy_page)
30462 movq %r9, 0x8*4(%rdi)
30463 movq %r10, 0x8*5(%rdi)
30464 movq %r11, 0x8*6(%rdi)
30465 - movq %r12, 0x8*7(%rdi)
30466 + movq %r13, 0x8*7(%rdi)
30467
30468 leaq 64 (%rsi), %rsi
30469 leaq 64 (%rdi), %rdi
30470 @@ -68,7 +69,7 @@ ENTRY(copy_page)
30471 movq 0x8*4(%rsi), %r9
30472 movq 0x8*5(%rsi), %r10
30473 movq 0x8*6(%rsi), %r11
30474 - movq 0x8*7(%rsi), %r12
30475 + movq 0x8*7(%rsi), %r13
30476
30477 movq %rax, 0x8*0(%rdi)
30478 movq %rbx, 0x8*1(%rdi)
30479 @@ -77,7 +78,7 @@ ENTRY(copy_page)
30480 movq %r9, 0x8*4(%rdi)
30481 movq %r10, 0x8*5(%rdi)
30482 movq %r11, 0x8*6(%rdi)
30483 - movq %r12, 0x8*7(%rdi)
30484 + movq %r13, 0x8*7(%rdi)
30485
30486 leaq 64(%rdi), %rdi
30487 leaq 64(%rsi), %rsi
30488 @@ -85,10 +86,11 @@ ENTRY(copy_page)
30489
30490 movq (%rsp), %rbx
30491 CFI_RESTORE rbx
30492 - movq 1*8(%rsp), %r12
30493 - CFI_RESTORE r12
30494 + movq 1*8(%rsp), %r13
30495 + CFI_RESTORE r13
30496 addq $2*8, %rsp
30497 CFI_ADJUST_CFA_OFFSET -2*8
30498 + pax_force_retaddr
30499 ret
30500 .Lcopy_page_end:
30501 CFI_ENDPROC
30502 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
30503
30504 #include <asm/cpufeature.h>
30505
30506 - .section .altinstr_replacement,"ax"
30507 + .section .altinstr_replacement,"a"
30508 1: .byte 0xeb /* jmp <disp8> */
30509 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30510 2:
30511 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30512 index dee945d..a84067b 100644
30513 --- a/arch/x86/lib/copy_user_64.S
30514 +++ b/arch/x86/lib/copy_user_64.S
30515 @@ -18,31 +18,7 @@
30516 #include <asm/alternative-asm.h>
30517 #include <asm/asm.h>
30518 #include <asm/smap.h>
30519 -
30520 -/*
30521 - * By placing feature2 after feature1 in altinstructions section, we logically
30522 - * implement:
30523 - * If CPU has feature2, jmp to alt2 is used
30524 - * else if CPU has feature1, jmp to alt1 is used
30525 - * else jmp to orig is used.
30526 - */
30527 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30528 -0:
30529 - .byte 0xe9 /* 32bit jump */
30530 - .long \orig-1f /* by default jump to orig */
30531 -1:
30532 - .section .altinstr_replacement,"ax"
30533 -2: .byte 0xe9 /* near jump with 32bit immediate */
30534 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30535 -3: .byte 0xe9 /* near jump with 32bit immediate */
30536 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30537 - .previous
30538 -
30539 - .section .altinstructions,"a"
30540 - altinstruction_entry 0b,2b,\feature1,5,5
30541 - altinstruction_entry 0b,3b,\feature2,5,5
30542 - .previous
30543 - .endm
30544 +#include <asm/pgtable.h>
30545
30546 .macro ALIGN_DESTINATION
30547 #ifdef FIX_ALIGNMENT
30548 @@ -70,52 +46,6 @@
30549 #endif
30550 .endm
30551
30552 -/* Standard copy_to_user with segment limit checking */
30553 -ENTRY(_copy_to_user)
30554 - CFI_STARTPROC
30555 - GET_THREAD_INFO(%rax)
30556 - movq %rdi,%rcx
30557 - addq %rdx,%rcx
30558 - jc bad_to_user
30559 - cmpq TI_addr_limit(%rax),%rcx
30560 - ja bad_to_user
30561 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30562 - copy_user_generic_unrolled,copy_user_generic_string, \
30563 - copy_user_enhanced_fast_string
30564 - CFI_ENDPROC
30565 -ENDPROC(_copy_to_user)
30566 -
30567 -/* Standard copy_from_user with segment limit checking */
30568 -ENTRY(_copy_from_user)
30569 - CFI_STARTPROC
30570 - GET_THREAD_INFO(%rax)
30571 - movq %rsi,%rcx
30572 - addq %rdx,%rcx
30573 - jc bad_from_user
30574 - cmpq TI_addr_limit(%rax),%rcx
30575 - ja bad_from_user
30576 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30577 - copy_user_generic_unrolled,copy_user_generic_string, \
30578 - copy_user_enhanced_fast_string
30579 - CFI_ENDPROC
30580 -ENDPROC(_copy_from_user)
30581 -
30582 - .section .fixup,"ax"
30583 - /* must zero dest */
30584 -ENTRY(bad_from_user)
30585 -bad_from_user:
30586 - CFI_STARTPROC
30587 - movl %edx,%ecx
30588 - xorl %eax,%eax
30589 - rep
30590 - stosb
30591 -bad_to_user:
30592 - movl %edx,%eax
30593 - ret
30594 - CFI_ENDPROC
30595 -ENDPROC(bad_from_user)
30596 - .previous
30597 -
30598 /*
30599 * copy_user_generic_unrolled - memory copy with exception handling.
30600 * This version is for CPUs like P4 that don't have efficient micro
30601 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30602 */
30603 ENTRY(copy_user_generic_unrolled)
30604 CFI_STARTPROC
30605 + ASM_PAX_OPEN_USERLAND
30606 ASM_STAC
30607 cmpl $8,%edx
30608 jb 20f /* less then 8 bytes, go to byte copy loop */
30609 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30610 jnz 21b
30611 23: xor %eax,%eax
30612 ASM_CLAC
30613 + ASM_PAX_CLOSE_USERLAND
30614 + pax_force_retaddr
30615 ret
30616
30617 .section .fixup,"ax"
30618 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30619 */
30620 ENTRY(copy_user_generic_string)
30621 CFI_STARTPROC
30622 + ASM_PAX_OPEN_USERLAND
30623 ASM_STAC
30624 cmpl $8,%edx
30625 jb 2f /* less than 8 bytes, go to byte copy loop */
30626 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30627 movsb
30628 xorl %eax,%eax
30629 ASM_CLAC
30630 + ASM_PAX_CLOSE_USERLAND
30631 + pax_force_retaddr
30632 ret
30633
30634 .section .fixup,"ax"
30635 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30636 */
30637 ENTRY(copy_user_enhanced_fast_string)
30638 CFI_STARTPROC
30639 + ASM_PAX_OPEN_USERLAND
30640 ASM_STAC
30641 movl %edx,%ecx
30642 1: rep
30643 movsb
30644 xorl %eax,%eax
30645 ASM_CLAC
30646 + ASM_PAX_CLOSE_USERLAND
30647 + pax_force_retaddr
30648 ret
30649
30650 .section .fixup,"ax"
30651 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30652 index 6a4f43c..c70fb52 100644
30653 --- a/arch/x86/lib/copy_user_nocache_64.S
30654 +++ b/arch/x86/lib/copy_user_nocache_64.S
30655 @@ -8,6 +8,7 @@
30656
30657 #include <linux/linkage.h>
30658 #include <asm/dwarf2.h>
30659 +#include <asm/alternative-asm.h>
30660
30661 #define FIX_ALIGNMENT 1
30662
30663 @@ -16,6 +17,7 @@
30664 #include <asm/thread_info.h>
30665 #include <asm/asm.h>
30666 #include <asm/smap.h>
30667 +#include <asm/pgtable.h>
30668
30669 .macro ALIGN_DESTINATION
30670 #ifdef FIX_ALIGNMENT
30671 @@ -49,6 +51,16 @@
30672 */
30673 ENTRY(__copy_user_nocache)
30674 CFI_STARTPROC
30675 +
30676 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30677 + mov pax_user_shadow_base,%rcx
30678 + cmp %rcx,%rsi
30679 + jae 1f
30680 + add %rcx,%rsi
30681 +1:
30682 +#endif
30683 +
30684 + ASM_PAX_OPEN_USERLAND
30685 ASM_STAC
30686 cmpl $8,%edx
30687 jb 20f /* less then 8 bytes, go to byte copy loop */
30688 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30689 jnz 21b
30690 23: xorl %eax,%eax
30691 ASM_CLAC
30692 + ASM_PAX_CLOSE_USERLAND
30693 sfence
30694 + pax_force_retaddr
30695 ret
30696
30697 .section .fixup,"ax"
30698 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30699 index 2419d5f..fe52d0e 100644
30700 --- a/arch/x86/lib/csum-copy_64.S
30701 +++ b/arch/x86/lib/csum-copy_64.S
30702 @@ -9,6 +9,7 @@
30703 #include <asm/dwarf2.h>
30704 #include <asm/errno.h>
30705 #include <asm/asm.h>
30706 +#include <asm/alternative-asm.h>
30707
30708 /*
30709 * Checksum copy with exception handling.
30710 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30711 CFI_ADJUST_CFA_OFFSET 7*8
30712 movq %rbx, 2*8(%rsp)
30713 CFI_REL_OFFSET rbx, 2*8
30714 - movq %r12, 3*8(%rsp)
30715 - CFI_REL_OFFSET r12, 3*8
30716 + movq %r15, 3*8(%rsp)
30717 + CFI_REL_OFFSET r15, 3*8
30718 movq %r14, 4*8(%rsp)
30719 CFI_REL_OFFSET r14, 4*8
30720 movq %r13, 5*8(%rsp)
30721 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30722 movl %edx, %ecx
30723
30724 xorl %r9d, %r9d
30725 - movq %rcx, %r12
30726 + movq %rcx, %r15
30727
30728 - shrq $6, %r12
30729 + shrq $6, %r15
30730 jz .Lhandle_tail /* < 64 */
30731
30732 clc
30733
30734 /* main loop. clear in 64 byte blocks */
30735 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30736 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30737 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30738 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30739 .p2align 4
30740 .Lloop:
30741 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30742 adcq %r14, %rax
30743 adcq %r13, %rax
30744
30745 - decl %r12d
30746 + decl %r15d
30747
30748 dest
30749 movq %rbx, (%rsi)
30750 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30751 .Lende:
30752 movq 2*8(%rsp), %rbx
30753 CFI_RESTORE rbx
30754 - movq 3*8(%rsp), %r12
30755 - CFI_RESTORE r12
30756 + movq 3*8(%rsp), %r15
30757 + CFI_RESTORE r15
30758 movq 4*8(%rsp), %r14
30759 CFI_RESTORE r14
30760 movq 5*8(%rsp), %r13
30761 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30762 CFI_RESTORE rbp
30763 addq $7*8, %rsp
30764 CFI_ADJUST_CFA_OFFSET -7*8
30765 + pax_force_retaddr
30766 ret
30767 CFI_RESTORE_STATE
30768
30769 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30770 index 7609e0e..b449b98 100644
30771 --- a/arch/x86/lib/csum-wrappers_64.c
30772 +++ b/arch/x86/lib/csum-wrappers_64.c
30773 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30774 len -= 2;
30775 }
30776 }
30777 + pax_open_userland();
30778 stac();
30779 - isum = csum_partial_copy_generic((__force const void *)src,
30780 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30781 dst, len, isum, errp, NULL);
30782 clac();
30783 + pax_close_userland();
30784 if (unlikely(*errp))
30785 goto out_err;
30786
30787 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30788 }
30789
30790 *errp = 0;
30791 + pax_open_userland();
30792 stac();
30793 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30794 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30795 len, isum, NULL, errp);
30796 clac();
30797 + pax_close_userland();
30798 return ret;
30799 }
30800 EXPORT_SYMBOL(csum_partial_copy_to_user);
30801 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30802 index a451235..1daa956 100644
30803 --- a/arch/x86/lib/getuser.S
30804 +++ b/arch/x86/lib/getuser.S
30805 @@ -33,17 +33,40 @@
30806 #include <asm/thread_info.h>
30807 #include <asm/asm.h>
30808 #include <asm/smap.h>
30809 +#include <asm/segment.h>
30810 +#include <asm/pgtable.h>
30811 +#include <asm/alternative-asm.h>
30812 +
30813 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30814 +#define __copyuser_seg gs;
30815 +#else
30816 +#define __copyuser_seg
30817 +#endif
30818
30819 .text
30820 ENTRY(__get_user_1)
30821 CFI_STARTPROC
30822 +
30823 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30824 GET_THREAD_INFO(%_ASM_DX)
30825 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30826 jae bad_get_user
30827 ASM_STAC
30828 -1: movzbl (%_ASM_AX),%edx
30829 +
30830 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30831 + mov pax_user_shadow_base,%_ASM_DX
30832 + cmp %_ASM_DX,%_ASM_AX
30833 + jae 1234f
30834 + add %_ASM_DX,%_ASM_AX
30835 +1234:
30836 +#endif
30837 +
30838 +#endif
30839 +
30840 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30841 xor %eax,%eax
30842 ASM_CLAC
30843 + pax_force_retaddr
30844 ret
30845 CFI_ENDPROC
30846 ENDPROC(__get_user_1)
30847 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30848 ENTRY(__get_user_2)
30849 CFI_STARTPROC
30850 add $1,%_ASM_AX
30851 +
30852 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30853 jc bad_get_user
30854 GET_THREAD_INFO(%_ASM_DX)
30855 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30856 jae bad_get_user
30857 ASM_STAC
30858 -2: movzwl -1(%_ASM_AX),%edx
30859 +
30860 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30861 + mov pax_user_shadow_base,%_ASM_DX
30862 + cmp %_ASM_DX,%_ASM_AX
30863 + jae 1234f
30864 + add %_ASM_DX,%_ASM_AX
30865 +1234:
30866 +#endif
30867 +
30868 +#endif
30869 +
30870 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30871 xor %eax,%eax
30872 ASM_CLAC
30873 + pax_force_retaddr
30874 ret
30875 CFI_ENDPROC
30876 ENDPROC(__get_user_2)
30877 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30878 ENTRY(__get_user_4)
30879 CFI_STARTPROC
30880 add $3,%_ASM_AX
30881 +
30882 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30883 jc bad_get_user
30884 GET_THREAD_INFO(%_ASM_DX)
30885 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30886 jae bad_get_user
30887 ASM_STAC
30888 -3: movl -3(%_ASM_AX),%edx
30889 +
30890 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30891 + mov pax_user_shadow_base,%_ASM_DX
30892 + cmp %_ASM_DX,%_ASM_AX
30893 + jae 1234f
30894 + add %_ASM_DX,%_ASM_AX
30895 +1234:
30896 +#endif
30897 +
30898 +#endif
30899 +
30900 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30901 xor %eax,%eax
30902 ASM_CLAC
30903 + pax_force_retaddr
30904 ret
30905 CFI_ENDPROC
30906 ENDPROC(__get_user_4)
30907 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30908 GET_THREAD_INFO(%_ASM_DX)
30909 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30910 jae bad_get_user
30911 +
30912 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30913 + mov pax_user_shadow_base,%_ASM_DX
30914 + cmp %_ASM_DX,%_ASM_AX
30915 + jae 1234f
30916 + add %_ASM_DX,%_ASM_AX
30917 +1234:
30918 +#endif
30919 +
30920 ASM_STAC
30921 4: movq -7(%_ASM_AX),%rdx
30922 xor %eax,%eax
30923 ASM_CLAC
30924 + pax_force_retaddr
30925 ret
30926 #else
30927 add $7,%_ASM_AX
30928 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30929 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30930 jae bad_get_user_8
30931 ASM_STAC
30932 -4: movl -7(%_ASM_AX),%edx
30933 -5: movl -3(%_ASM_AX),%ecx
30934 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30935 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30936 xor %eax,%eax
30937 ASM_CLAC
30938 + pax_force_retaddr
30939 ret
30940 #endif
30941 CFI_ENDPROC
30942 @@ -113,6 +175,7 @@ bad_get_user:
30943 xor %edx,%edx
30944 mov $(-EFAULT),%_ASM_AX
30945 ASM_CLAC
30946 + pax_force_retaddr
30947 ret
30948 CFI_ENDPROC
30949 END(bad_get_user)
30950 @@ -124,6 +187,7 @@ bad_get_user_8:
30951 xor %ecx,%ecx
30952 mov $(-EFAULT),%_ASM_AX
30953 ASM_CLAC
30954 + pax_force_retaddr
30955 ret
30956 CFI_ENDPROC
30957 END(bad_get_user_8)
30958 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30959 index 54fcffe..7be149e 100644
30960 --- a/arch/x86/lib/insn.c
30961 +++ b/arch/x86/lib/insn.c
30962 @@ -20,8 +20,10 @@
30963
30964 #ifdef __KERNEL__
30965 #include <linux/string.h>
30966 +#include <asm/pgtable_types.h>
30967 #else
30968 #include <string.h>
30969 +#define ktla_ktva(addr) addr
30970 #endif
30971 #include <asm/inat.h>
30972 #include <asm/insn.h>
30973 @@ -53,8 +55,8 @@
30974 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30975 {
30976 memset(insn, 0, sizeof(*insn));
30977 - insn->kaddr = kaddr;
30978 - insn->next_byte = kaddr;
30979 + insn->kaddr = ktla_ktva(kaddr);
30980 + insn->next_byte = ktla_ktva(kaddr);
30981 insn->x86_64 = x86_64 ? 1 : 0;
30982 insn->opnd_bytes = 4;
30983 if (x86_64)
30984 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30985 index 05a95e7..326f2fa 100644
30986 --- a/arch/x86/lib/iomap_copy_64.S
30987 +++ b/arch/x86/lib/iomap_copy_64.S
30988 @@ -17,6 +17,7 @@
30989
30990 #include <linux/linkage.h>
30991 #include <asm/dwarf2.h>
30992 +#include <asm/alternative-asm.h>
30993
30994 /*
30995 * override generic version in lib/iomap_copy.c
30996 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30997 CFI_STARTPROC
30998 movl %edx,%ecx
30999 rep movsd
31000 + pax_force_retaddr
31001 ret
31002 CFI_ENDPROC
31003 ENDPROC(__iowrite32_copy)
31004 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
31005 index 56313a3..0db417e 100644
31006 --- a/arch/x86/lib/memcpy_64.S
31007 +++ b/arch/x86/lib/memcpy_64.S
31008 @@ -24,7 +24,7 @@
31009 * This gets patched over the unrolled variant (below) via the
31010 * alternative instructions framework:
31011 */
31012 - .section .altinstr_replacement, "ax", @progbits
31013 + .section .altinstr_replacement, "a", @progbits
31014 .Lmemcpy_c:
31015 movq %rdi, %rax
31016 movq %rdx, %rcx
31017 @@ -33,6 +33,7 @@
31018 rep movsq
31019 movl %edx, %ecx
31020 rep movsb
31021 + pax_force_retaddr
31022 ret
31023 .Lmemcpy_e:
31024 .previous
31025 @@ -44,11 +45,12 @@
31026 * This gets patched over the unrolled variant (below) via the
31027 * alternative instructions framework:
31028 */
31029 - .section .altinstr_replacement, "ax", @progbits
31030 + .section .altinstr_replacement, "a", @progbits
31031 .Lmemcpy_c_e:
31032 movq %rdi, %rax
31033 movq %rdx, %rcx
31034 rep movsb
31035 + pax_force_retaddr
31036 ret
31037 .Lmemcpy_e_e:
31038 .previous
31039 @@ -136,6 +138,7 @@ ENTRY(memcpy)
31040 movq %r9, 1*8(%rdi)
31041 movq %r10, -2*8(%rdi, %rdx)
31042 movq %r11, -1*8(%rdi, %rdx)
31043 + pax_force_retaddr
31044 retq
31045 .p2align 4
31046 .Lless_16bytes:
31047 @@ -148,6 +151,7 @@ ENTRY(memcpy)
31048 movq -1*8(%rsi, %rdx), %r9
31049 movq %r8, 0*8(%rdi)
31050 movq %r9, -1*8(%rdi, %rdx)
31051 + pax_force_retaddr
31052 retq
31053 .p2align 4
31054 .Lless_8bytes:
31055 @@ -161,6 +165,7 @@ ENTRY(memcpy)
31056 movl -4(%rsi, %rdx), %r8d
31057 movl %ecx, (%rdi)
31058 movl %r8d, -4(%rdi, %rdx)
31059 + pax_force_retaddr
31060 retq
31061 .p2align 4
31062 .Lless_3bytes:
31063 @@ -179,6 +184,7 @@ ENTRY(memcpy)
31064 movb %cl, (%rdi)
31065
31066 .Lend:
31067 + pax_force_retaddr
31068 retq
31069 CFI_ENDPROC
31070 ENDPROC(memcpy)
31071 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
31072 index 65268a6..dd1de11 100644
31073 --- a/arch/x86/lib/memmove_64.S
31074 +++ b/arch/x86/lib/memmove_64.S
31075 @@ -202,14 +202,16 @@ ENTRY(memmove)
31076 movb (%rsi), %r11b
31077 movb %r11b, (%rdi)
31078 13:
31079 + pax_force_retaddr
31080 retq
31081 CFI_ENDPROC
31082
31083 - .section .altinstr_replacement,"ax"
31084 + .section .altinstr_replacement,"a"
31085 .Lmemmove_begin_forward_efs:
31086 /* Forward moving data. */
31087 movq %rdx, %rcx
31088 rep movsb
31089 + pax_force_retaddr
31090 retq
31091 .Lmemmove_end_forward_efs:
31092 .previous
31093 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31094 index 2dcb380..2eb79fe 100644
31095 --- a/arch/x86/lib/memset_64.S
31096 +++ b/arch/x86/lib/memset_64.S
31097 @@ -16,7 +16,7 @@
31098 *
31099 * rax original destination
31100 */
31101 - .section .altinstr_replacement, "ax", @progbits
31102 + .section .altinstr_replacement, "a", @progbits
31103 .Lmemset_c:
31104 movq %rdi,%r9
31105 movq %rdx,%rcx
31106 @@ -30,6 +30,7 @@
31107 movl %edx,%ecx
31108 rep stosb
31109 movq %r9,%rax
31110 + pax_force_retaddr
31111 ret
31112 .Lmemset_e:
31113 .previous
31114 @@ -45,13 +46,14 @@
31115 *
31116 * rax original destination
31117 */
31118 - .section .altinstr_replacement, "ax", @progbits
31119 + .section .altinstr_replacement, "a", @progbits
31120 .Lmemset_c_e:
31121 movq %rdi,%r9
31122 movb %sil,%al
31123 movq %rdx,%rcx
31124 rep stosb
31125 movq %r9,%rax
31126 + pax_force_retaddr
31127 ret
31128 .Lmemset_e_e:
31129 .previous
31130 @@ -118,6 +120,7 @@ ENTRY(__memset)
31131
31132 .Lende:
31133 movq %r10,%rax
31134 + pax_force_retaddr
31135 ret
31136
31137 CFI_RESTORE_STATE
31138 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31139 index c9f2d9b..e7fd2c0 100644
31140 --- a/arch/x86/lib/mmx_32.c
31141 +++ b/arch/x86/lib/mmx_32.c
31142 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31143 {
31144 void *p;
31145 int i;
31146 + unsigned long cr0;
31147
31148 if (unlikely(in_interrupt()))
31149 return __memcpy(to, from, len);
31150 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31151 kernel_fpu_begin();
31152
31153 __asm__ __volatile__ (
31154 - "1: prefetch (%0)\n" /* This set is 28 bytes */
31155 - " prefetch 64(%0)\n"
31156 - " prefetch 128(%0)\n"
31157 - " prefetch 192(%0)\n"
31158 - " prefetch 256(%0)\n"
31159 + "1: prefetch (%1)\n" /* This set is 28 bytes */
31160 + " prefetch 64(%1)\n"
31161 + " prefetch 128(%1)\n"
31162 + " prefetch 192(%1)\n"
31163 + " prefetch 256(%1)\n"
31164 "2: \n"
31165 ".section .fixup, \"ax\"\n"
31166 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31167 + "3: \n"
31168 +
31169 +#ifdef CONFIG_PAX_KERNEXEC
31170 + " movl %%cr0, %0\n"
31171 + " movl %0, %%eax\n"
31172 + " andl $0xFFFEFFFF, %%eax\n"
31173 + " movl %%eax, %%cr0\n"
31174 +#endif
31175 +
31176 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31177 +
31178 +#ifdef CONFIG_PAX_KERNEXEC
31179 + " movl %0, %%cr0\n"
31180 +#endif
31181 +
31182 " jmp 2b\n"
31183 ".previous\n"
31184 _ASM_EXTABLE(1b, 3b)
31185 - : : "r" (from));
31186 + : "=&r" (cr0) : "r" (from) : "ax");
31187
31188 for ( ; i > 5; i--) {
31189 __asm__ __volatile__ (
31190 - "1: prefetch 320(%0)\n"
31191 - "2: movq (%0), %%mm0\n"
31192 - " movq 8(%0), %%mm1\n"
31193 - " movq 16(%0), %%mm2\n"
31194 - " movq 24(%0), %%mm3\n"
31195 - " movq %%mm0, (%1)\n"
31196 - " movq %%mm1, 8(%1)\n"
31197 - " movq %%mm2, 16(%1)\n"
31198 - " movq %%mm3, 24(%1)\n"
31199 - " movq 32(%0), %%mm0\n"
31200 - " movq 40(%0), %%mm1\n"
31201 - " movq 48(%0), %%mm2\n"
31202 - " movq 56(%0), %%mm3\n"
31203 - " movq %%mm0, 32(%1)\n"
31204 - " movq %%mm1, 40(%1)\n"
31205 - " movq %%mm2, 48(%1)\n"
31206 - " movq %%mm3, 56(%1)\n"
31207 + "1: prefetch 320(%1)\n"
31208 + "2: movq (%1), %%mm0\n"
31209 + " movq 8(%1), %%mm1\n"
31210 + " movq 16(%1), %%mm2\n"
31211 + " movq 24(%1), %%mm3\n"
31212 + " movq %%mm0, (%2)\n"
31213 + " movq %%mm1, 8(%2)\n"
31214 + " movq %%mm2, 16(%2)\n"
31215 + " movq %%mm3, 24(%2)\n"
31216 + " movq 32(%1), %%mm0\n"
31217 + " movq 40(%1), %%mm1\n"
31218 + " movq 48(%1), %%mm2\n"
31219 + " movq 56(%1), %%mm3\n"
31220 + " movq %%mm0, 32(%2)\n"
31221 + " movq %%mm1, 40(%2)\n"
31222 + " movq %%mm2, 48(%2)\n"
31223 + " movq %%mm3, 56(%2)\n"
31224 ".section .fixup, \"ax\"\n"
31225 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31226 + "3:\n"
31227 +
31228 +#ifdef CONFIG_PAX_KERNEXEC
31229 + " movl %%cr0, %0\n"
31230 + " movl %0, %%eax\n"
31231 + " andl $0xFFFEFFFF, %%eax\n"
31232 + " movl %%eax, %%cr0\n"
31233 +#endif
31234 +
31235 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31236 +
31237 +#ifdef CONFIG_PAX_KERNEXEC
31238 + " movl %0, %%cr0\n"
31239 +#endif
31240 +
31241 " jmp 2b\n"
31242 ".previous\n"
31243 _ASM_EXTABLE(1b, 3b)
31244 - : : "r" (from), "r" (to) : "memory");
31245 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31246
31247 from += 64;
31248 to += 64;
31249 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31250 static void fast_copy_page(void *to, void *from)
31251 {
31252 int i;
31253 + unsigned long cr0;
31254
31255 kernel_fpu_begin();
31256
31257 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31258 * but that is for later. -AV
31259 */
31260 __asm__ __volatile__(
31261 - "1: prefetch (%0)\n"
31262 - " prefetch 64(%0)\n"
31263 - " prefetch 128(%0)\n"
31264 - " prefetch 192(%0)\n"
31265 - " prefetch 256(%0)\n"
31266 + "1: prefetch (%1)\n"
31267 + " prefetch 64(%1)\n"
31268 + " prefetch 128(%1)\n"
31269 + " prefetch 192(%1)\n"
31270 + " prefetch 256(%1)\n"
31271 "2: \n"
31272 ".section .fixup, \"ax\"\n"
31273 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31274 + "3: \n"
31275 +
31276 +#ifdef CONFIG_PAX_KERNEXEC
31277 + " movl %%cr0, %0\n"
31278 + " movl %0, %%eax\n"
31279 + " andl $0xFFFEFFFF, %%eax\n"
31280 + " movl %%eax, %%cr0\n"
31281 +#endif
31282 +
31283 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31284 +
31285 +#ifdef CONFIG_PAX_KERNEXEC
31286 + " movl %0, %%cr0\n"
31287 +#endif
31288 +
31289 " jmp 2b\n"
31290 ".previous\n"
31291 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31292 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31293
31294 for (i = 0; i < (4096-320)/64; i++) {
31295 __asm__ __volatile__ (
31296 - "1: prefetch 320(%0)\n"
31297 - "2: movq (%0), %%mm0\n"
31298 - " movntq %%mm0, (%1)\n"
31299 - " movq 8(%0), %%mm1\n"
31300 - " movntq %%mm1, 8(%1)\n"
31301 - " movq 16(%0), %%mm2\n"
31302 - " movntq %%mm2, 16(%1)\n"
31303 - " movq 24(%0), %%mm3\n"
31304 - " movntq %%mm3, 24(%1)\n"
31305 - " movq 32(%0), %%mm4\n"
31306 - " movntq %%mm4, 32(%1)\n"
31307 - " movq 40(%0), %%mm5\n"
31308 - " movntq %%mm5, 40(%1)\n"
31309 - " movq 48(%0), %%mm6\n"
31310 - " movntq %%mm6, 48(%1)\n"
31311 - " movq 56(%0), %%mm7\n"
31312 - " movntq %%mm7, 56(%1)\n"
31313 + "1: prefetch 320(%1)\n"
31314 + "2: movq (%1), %%mm0\n"
31315 + " movntq %%mm0, (%2)\n"
31316 + " movq 8(%1), %%mm1\n"
31317 + " movntq %%mm1, 8(%2)\n"
31318 + " movq 16(%1), %%mm2\n"
31319 + " movntq %%mm2, 16(%2)\n"
31320 + " movq 24(%1), %%mm3\n"
31321 + " movntq %%mm3, 24(%2)\n"
31322 + " movq 32(%1), %%mm4\n"
31323 + " movntq %%mm4, 32(%2)\n"
31324 + " movq 40(%1), %%mm5\n"
31325 + " movntq %%mm5, 40(%2)\n"
31326 + " movq 48(%1), %%mm6\n"
31327 + " movntq %%mm6, 48(%2)\n"
31328 + " movq 56(%1), %%mm7\n"
31329 + " movntq %%mm7, 56(%2)\n"
31330 ".section .fixup, \"ax\"\n"
31331 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31332 + "3:\n"
31333 +
31334 +#ifdef CONFIG_PAX_KERNEXEC
31335 + " movl %%cr0, %0\n"
31336 + " movl %0, %%eax\n"
31337 + " andl $0xFFFEFFFF, %%eax\n"
31338 + " movl %%eax, %%cr0\n"
31339 +#endif
31340 +
31341 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31342 +
31343 +#ifdef CONFIG_PAX_KERNEXEC
31344 + " movl %0, %%cr0\n"
31345 +#endif
31346 +
31347 " jmp 2b\n"
31348 ".previous\n"
31349 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31350 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31351
31352 from += 64;
31353 to += 64;
31354 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31355 static void fast_copy_page(void *to, void *from)
31356 {
31357 int i;
31358 + unsigned long cr0;
31359
31360 kernel_fpu_begin();
31361
31362 __asm__ __volatile__ (
31363 - "1: prefetch (%0)\n"
31364 - " prefetch 64(%0)\n"
31365 - " prefetch 128(%0)\n"
31366 - " prefetch 192(%0)\n"
31367 - " prefetch 256(%0)\n"
31368 + "1: prefetch (%1)\n"
31369 + " prefetch 64(%1)\n"
31370 + " prefetch 128(%1)\n"
31371 + " prefetch 192(%1)\n"
31372 + " prefetch 256(%1)\n"
31373 "2: \n"
31374 ".section .fixup, \"ax\"\n"
31375 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31376 + "3: \n"
31377 +
31378 +#ifdef CONFIG_PAX_KERNEXEC
31379 + " movl %%cr0, %0\n"
31380 + " movl %0, %%eax\n"
31381 + " andl $0xFFFEFFFF, %%eax\n"
31382 + " movl %%eax, %%cr0\n"
31383 +#endif
31384 +
31385 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31386 +
31387 +#ifdef CONFIG_PAX_KERNEXEC
31388 + " movl %0, %%cr0\n"
31389 +#endif
31390 +
31391 " jmp 2b\n"
31392 ".previous\n"
31393 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31394 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31395
31396 for (i = 0; i < 4096/64; i++) {
31397 __asm__ __volatile__ (
31398 - "1: prefetch 320(%0)\n"
31399 - "2: movq (%0), %%mm0\n"
31400 - " movq 8(%0), %%mm1\n"
31401 - " movq 16(%0), %%mm2\n"
31402 - " movq 24(%0), %%mm3\n"
31403 - " movq %%mm0, (%1)\n"
31404 - " movq %%mm1, 8(%1)\n"
31405 - " movq %%mm2, 16(%1)\n"
31406 - " movq %%mm3, 24(%1)\n"
31407 - " movq 32(%0), %%mm0\n"
31408 - " movq 40(%0), %%mm1\n"
31409 - " movq 48(%0), %%mm2\n"
31410 - " movq 56(%0), %%mm3\n"
31411 - " movq %%mm0, 32(%1)\n"
31412 - " movq %%mm1, 40(%1)\n"
31413 - " movq %%mm2, 48(%1)\n"
31414 - " movq %%mm3, 56(%1)\n"
31415 + "1: prefetch 320(%1)\n"
31416 + "2: movq (%1), %%mm0\n"
31417 + " movq 8(%1), %%mm1\n"
31418 + " movq 16(%1), %%mm2\n"
31419 + " movq 24(%1), %%mm3\n"
31420 + " movq %%mm0, (%2)\n"
31421 + " movq %%mm1, 8(%2)\n"
31422 + " movq %%mm2, 16(%2)\n"
31423 + " movq %%mm3, 24(%2)\n"
31424 + " movq 32(%1), %%mm0\n"
31425 + " movq 40(%1), %%mm1\n"
31426 + " movq 48(%1), %%mm2\n"
31427 + " movq 56(%1), %%mm3\n"
31428 + " movq %%mm0, 32(%2)\n"
31429 + " movq %%mm1, 40(%2)\n"
31430 + " movq %%mm2, 48(%2)\n"
31431 + " movq %%mm3, 56(%2)\n"
31432 ".section .fixup, \"ax\"\n"
31433 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31434 + "3:\n"
31435 +
31436 +#ifdef CONFIG_PAX_KERNEXEC
31437 + " movl %%cr0, %0\n"
31438 + " movl %0, %%eax\n"
31439 + " andl $0xFFFEFFFF, %%eax\n"
31440 + " movl %%eax, %%cr0\n"
31441 +#endif
31442 +
31443 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31444 +
31445 +#ifdef CONFIG_PAX_KERNEXEC
31446 + " movl %0, %%cr0\n"
31447 +#endif
31448 +
31449 " jmp 2b\n"
31450 ".previous\n"
31451 _ASM_EXTABLE(1b, 3b)
31452 - : : "r" (from), "r" (to) : "memory");
31453 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31454
31455 from += 64;
31456 to += 64;
31457 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31458 index f6d13ee..d789440 100644
31459 --- a/arch/x86/lib/msr-reg.S
31460 +++ b/arch/x86/lib/msr-reg.S
31461 @@ -3,6 +3,7 @@
31462 #include <asm/dwarf2.h>
31463 #include <asm/asm.h>
31464 #include <asm/msr.h>
31465 +#include <asm/alternative-asm.h>
31466
31467 #ifdef CONFIG_X86_64
31468 /*
31469 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31470 movl %edi, 28(%r10)
31471 popq_cfi %rbp
31472 popq_cfi %rbx
31473 + pax_force_retaddr
31474 ret
31475 3:
31476 CFI_RESTORE_STATE
31477 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31478 index fc6ba17..d4d989d 100644
31479 --- a/arch/x86/lib/putuser.S
31480 +++ b/arch/x86/lib/putuser.S
31481 @@ -16,7 +16,9 @@
31482 #include <asm/errno.h>
31483 #include <asm/asm.h>
31484 #include <asm/smap.h>
31485 -
31486 +#include <asm/segment.h>
31487 +#include <asm/pgtable.h>
31488 +#include <asm/alternative-asm.h>
31489
31490 /*
31491 * __put_user_X
31492 @@ -30,57 +32,125 @@
31493 * as they get called from within inline assembly.
31494 */
31495
31496 -#define ENTER CFI_STARTPROC ; \
31497 - GET_THREAD_INFO(%_ASM_BX)
31498 -#define EXIT ASM_CLAC ; \
31499 - ret ; \
31500 +#define ENTER CFI_STARTPROC
31501 +#define EXIT ASM_CLAC ; \
31502 + pax_force_retaddr ; \
31503 + ret ; \
31504 CFI_ENDPROC
31505
31506 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31507 +#define _DEST %_ASM_CX,%_ASM_BX
31508 +#else
31509 +#define _DEST %_ASM_CX
31510 +#endif
31511 +
31512 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31513 +#define __copyuser_seg gs;
31514 +#else
31515 +#define __copyuser_seg
31516 +#endif
31517 +
31518 .text
31519 ENTRY(__put_user_1)
31520 ENTER
31521 +
31522 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31523 + GET_THREAD_INFO(%_ASM_BX)
31524 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31525 jae bad_put_user
31526 ASM_STAC
31527 -1: movb %al,(%_ASM_CX)
31528 +
31529 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31530 + mov pax_user_shadow_base,%_ASM_BX
31531 + cmp %_ASM_BX,%_ASM_CX
31532 + jb 1234f
31533 + xor %ebx,%ebx
31534 +1234:
31535 +#endif
31536 +
31537 +#endif
31538 +
31539 +1: __copyuser_seg movb %al,(_DEST)
31540 xor %eax,%eax
31541 EXIT
31542 ENDPROC(__put_user_1)
31543
31544 ENTRY(__put_user_2)
31545 ENTER
31546 +
31547 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31548 + GET_THREAD_INFO(%_ASM_BX)
31549 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31550 sub $1,%_ASM_BX
31551 cmp %_ASM_BX,%_ASM_CX
31552 jae bad_put_user
31553 ASM_STAC
31554 -2: movw %ax,(%_ASM_CX)
31555 +
31556 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31557 + mov pax_user_shadow_base,%_ASM_BX
31558 + cmp %_ASM_BX,%_ASM_CX
31559 + jb 1234f
31560 + xor %ebx,%ebx
31561 +1234:
31562 +#endif
31563 +
31564 +#endif
31565 +
31566 +2: __copyuser_seg movw %ax,(_DEST)
31567 xor %eax,%eax
31568 EXIT
31569 ENDPROC(__put_user_2)
31570
31571 ENTRY(__put_user_4)
31572 ENTER
31573 +
31574 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31575 + GET_THREAD_INFO(%_ASM_BX)
31576 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31577 sub $3,%_ASM_BX
31578 cmp %_ASM_BX,%_ASM_CX
31579 jae bad_put_user
31580 ASM_STAC
31581 -3: movl %eax,(%_ASM_CX)
31582 +
31583 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31584 + mov pax_user_shadow_base,%_ASM_BX
31585 + cmp %_ASM_BX,%_ASM_CX
31586 + jb 1234f
31587 + xor %ebx,%ebx
31588 +1234:
31589 +#endif
31590 +
31591 +#endif
31592 +
31593 +3: __copyuser_seg movl %eax,(_DEST)
31594 xor %eax,%eax
31595 EXIT
31596 ENDPROC(__put_user_4)
31597
31598 ENTRY(__put_user_8)
31599 ENTER
31600 +
31601 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31602 + GET_THREAD_INFO(%_ASM_BX)
31603 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31604 sub $7,%_ASM_BX
31605 cmp %_ASM_BX,%_ASM_CX
31606 jae bad_put_user
31607 ASM_STAC
31608 -4: mov %_ASM_AX,(%_ASM_CX)
31609 +
31610 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31611 + mov pax_user_shadow_base,%_ASM_BX
31612 + cmp %_ASM_BX,%_ASM_CX
31613 + jb 1234f
31614 + xor %ebx,%ebx
31615 +1234:
31616 +#endif
31617 +
31618 +#endif
31619 +
31620 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31621 #ifdef CONFIG_X86_32
31622 -5: movl %edx,4(%_ASM_CX)
31623 +5: __copyuser_seg movl %edx,4(_DEST)
31624 #endif
31625 xor %eax,%eax
31626 EXIT
31627 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31628 index 1cad221..de671ee 100644
31629 --- a/arch/x86/lib/rwlock.S
31630 +++ b/arch/x86/lib/rwlock.S
31631 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31632 FRAME
31633 0: LOCK_PREFIX
31634 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31635 +
31636 +#ifdef CONFIG_PAX_REFCOUNT
31637 + jno 1234f
31638 + LOCK_PREFIX
31639 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31640 + int $4
31641 +1234:
31642 + _ASM_EXTABLE(1234b, 1234b)
31643 +#endif
31644 +
31645 1: rep; nop
31646 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31647 jne 1b
31648 LOCK_PREFIX
31649 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31650 +
31651 +#ifdef CONFIG_PAX_REFCOUNT
31652 + jno 1234f
31653 + LOCK_PREFIX
31654 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31655 + int $4
31656 +1234:
31657 + _ASM_EXTABLE(1234b, 1234b)
31658 +#endif
31659 +
31660 jnz 0b
31661 ENDFRAME
31662 + pax_force_retaddr
31663 ret
31664 CFI_ENDPROC
31665 END(__write_lock_failed)
31666 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31667 FRAME
31668 0: LOCK_PREFIX
31669 READ_LOCK_SIZE(inc) (%__lock_ptr)
31670 +
31671 +#ifdef CONFIG_PAX_REFCOUNT
31672 + jno 1234f
31673 + LOCK_PREFIX
31674 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31675 + int $4
31676 +1234:
31677 + _ASM_EXTABLE(1234b, 1234b)
31678 +#endif
31679 +
31680 1: rep; nop
31681 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31682 js 1b
31683 LOCK_PREFIX
31684 READ_LOCK_SIZE(dec) (%__lock_ptr)
31685 +
31686 +#ifdef CONFIG_PAX_REFCOUNT
31687 + jno 1234f
31688 + LOCK_PREFIX
31689 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31690 + int $4
31691 +1234:
31692 + _ASM_EXTABLE(1234b, 1234b)
31693 +#endif
31694 +
31695 js 0b
31696 ENDFRAME
31697 + pax_force_retaddr
31698 ret
31699 CFI_ENDPROC
31700 END(__read_lock_failed)
31701 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31702 index 5dff5f0..cadebf4 100644
31703 --- a/arch/x86/lib/rwsem.S
31704 +++ b/arch/x86/lib/rwsem.S
31705 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31706 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31707 CFI_RESTORE __ASM_REG(dx)
31708 restore_common_regs
31709 + pax_force_retaddr
31710 ret
31711 CFI_ENDPROC
31712 ENDPROC(call_rwsem_down_read_failed)
31713 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31714 movq %rax,%rdi
31715 call rwsem_down_write_failed
31716 restore_common_regs
31717 + pax_force_retaddr
31718 ret
31719 CFI_ENDPROC
31720 ENDPROC(call_rwsem_down_write_failed)
31721 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31722 movq %rax,%rdi
31723 call rwsem_wake
31724 restore_common_regs
31725 -1: ret
31726 +1: pax_force_retaddr
31727 + ret
31728 CFI_ENDPROC
31729 ENDPROC(call_rwsem_wake)
31730
31731 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31732 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31733 CFI_RESTORE __ASM_REG(dx)
31734 restore_common_regs
31735 + pax_force_retaddr
31736 ret
31737 CFI_ENDPROC
31738 ENDPROC(call_rwsem_downgrade_wake)
31739 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31740 index 92d9fea..b2762c8 100644
31741 --- a/arch/x86/lib/thunk_64.S
31742 +++ b/arch/x86/lib/thunk_64.S
31743 @@ -9,6 +9,7 @@
31744 #include <asm/dwarf2.h>
31745 #include <asm/calling.h>
31746 #include <asm/asm.h>
31747 +#include <asm/alternative-asm.h>
31748
31749 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31750 .macro THUNK name, func, put_ret_addr_in_rdi=0
31751 @@ -16,11 +17,11 @@
31752 \name:
31753 CFI_STARTPROC
31754
31755 - /* this one pushes 9 elems, the next one would be %rIP */
31756 - SAVE_ARGS
31757 + /* this one pushes 15+1 elems, the next one would be %rIP */
31758 + SAVE_ARGS 8
31759
31760 .if \put_ret_addr_in_rdi
31761 - movq_cfi_restore 9*8, rdi
31762 + movq_cfi_restore RIP, rdi
31763 .endif
31764
31765 call \func
31766 @@ -40,9 +41,10 @@
31767
31768 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31769 CFI_STARTPROC
31770 - SAVE_ARGS
31771 + SAVE_ARGS 8
31772 restore:
31773 - RESTORE_ARGS
31774 + RESTORE_ARGS 1,8
31775 + pax_force_retaddr
31776 ret
31777 CFI_ENDPROC
31778 _ASM_NOKPROBE(restore)
31779 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31780 index e2f5e21..4b22130 100644
31781 --- a/arch/x86/lib/usercopy_32.c
31782 +++ b/arch/x86/lib/usercopy_32.c
31783 @@ -42,11 +42,13 @@ do { \
31784 int __d0; \
31785 might_fault(); \
31786 __asm__ __volatile__( \
31787 + __COPYUSER_SET_ES \
31788 ASM_STAC "\n" \
31789 "0: rep; stosl\n" \
31790 " movl %2,%0\n" \
31791 "1: rep; stosb\n" \
31792 "2: " ASM_CLAC "\n" \
31793 + __COPYUSER_RESTORE_ES \
31794 ".section .fixup,\"ax\"\n" \
31795 "3: lea 0(%2,%0,4),%0\n" \
31796 " jmp 2b\n" \
31797 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31798
31799 #ifdef CONFIG_X86_INTEL_USERCOPY
31800 static unsigned long
31801 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31802 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31803 {
31804 int d0, d1;
31805 __asm__ __volatile__(
31806 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31807 " .align 2,0x90\n"
31808 "3: movl 0(%4), %%eax\n"
31809 "4: movl 4(%4), %%edx\n"
31810 - "5: movl %%eax, 0(%3)\n"
31811 - "6: movl %%edx, 4(%3)\n"
31812 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31813 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31814 "7: movl 8(%4), %%eax\n"
31815 "8: movl 12(%4),%%edx\n"
31816 - "9: movl %%eax, 8(%3)\n"
31817 - "10: movl %%edx, 12(%3)\n"
31818 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31819 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31820 "11: movl 16(%4), %%eax\n"
31821 "12: movl 20(%4), %%edx\n"
31822 - "13: movl %%eax, 16(%3)\n"
31823 - "14: movl %%edx, 20(%3)\n"
31824 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31825 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31826 "15: movl 24(%4), %%eax\n"
31827 "16: movl 28(%4), %%edx\n"
31828 - "17: movl %%eax, 24(%3)\n"
31829 - "18: movl %%edx, 28(%3)\n"
31830 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31831 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31832 "19: movl 32(%4), %%eax\n"
31833 "20: movl 36(%4), %%edx\n"
31834 - "21: movl %%eax, 32(%3)\n"
31835 - "22: movl %%edx, 36(%3)\n"
31836 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31837 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31838 "23: movl 40(%4), %%eax\n"
31839 "24: movl 44(%4), %%edx\n"
31840 - "25: movl %%eax, 40(%3)\n"
31841 - "26: movl %%edx, 44(%3)\n"
31842 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31843 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31844 "27: movl 48(%4), %%eax\n"
31845 "28: movl 52(%4), %%edx\n"
31846 - "29: movl %%eax, 48(%3)\n"
31847 - "30: movl %%edx, 52(%3)\n"
31848 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31849 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31850 "31: movl 56(%4), %%eax\n"
31851 "32: movl 60(%4), %%edx\n"
31852 - "33: movl %%eax, 56(%3)\n"
31853 - "34: movl %%edx, 60(%3)\n"
31854 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31855 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31856 " addl $-64, %0\n"
31857 " addl $64, %4\n"
31858 " addl $64, %3\n"
31859 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31860 " shrl $2, %0\n"
31861 " andl $3, %%eax\n"
31862 " cld\n"
31863 + __COPYUSER_SET_ES
31864 "99: rep; movsl\n"
31865 "36: movl %%eax, %0\n"
31866 "37: rep; movsb\n"
31867 "100:\n"
31868 + __COPYUSER_RESTORE_ES
31869 + ".section .fixup,\"ax\"\n"
31870 + "101: lea 0(%%eax,%0,4),%0\n"
31871 + " jmp 100b\n"
31872 + ".previous\n"
31873 + _ASM_EXTABLE(1b,100b)
31874 + _ASM_EXTABLE(2b,100b)
31875 + _ASM_EXTABLE(3b,100b)
31876 + _ASM_EXTABLE(4b,100b)
31877 + _ASM_EXTABLE(5b,100b)
31878 + _ASM_EXTABLE(6b,100b)
31879 + _ASM_EXTABLE(7b,100b)
31880 + _ASM_EXTABLE(8b,100b)
31881 + _ASM_EXTABLE(9b,100b)
31882 + _ASM_EXTABLE(10b,100b)
31883 + _ASM_EXTABLE(11b,100b)
31884 + _ASM_EXTABLE(12b,100b)
31885 + _ASM_EXTABLE(13b,100b)
31886 + _ASM_EXTABLE(14b,100b)
31887 + _ASM_EXTABLE(15b,100b)
31888 + _ASM_EXTABLE(16b,100b)
31889 + _ASM_EXTABLE(17b,100b)
31890 + _ASM_EXTABLE(18b,100b)
31891 + _ASM_EXTABLE(19b,100b)
31892 + _ASM_EXTABLE(20b,100b)
31893 + _ASM_EXTABLE(21b,100b)
31894 + _ASM_EXTABLE(22b,100b)
31895 + _ASM_EXTABLE(23b,100b)
31896 + _ASM_EXTABLE(24b,100b)
31897 + _ASM_EXTABLE(25b,100b)
31898 + _ASM_EXTABLE(26b,100b)
31899 + _ASM_EXTABLE(27b,100b)
31900 + _ASM_EXTABLE(28b,100b)
31901 + _ASM_EXTABLE(29b,100b)
31902 + _ASM_EXTABLE(30b,100b)
31903 + _ASM_EXTABLE(31b,100b)
31904 + _ASM_EXTABLE(32b,100b)
31905 + _ASM_EXTABLE(33b,100b)
31906 + _ASM_EXTABLE(34b,100b)
31907 + _ASM_EXTABLE(35b,100b)
31908 + _ASM_EXTABLE(36b,100b)
31909 + _ASM_EXTABLE(37b,100b)
31910 + _ASM_EXTABLE(99b,101b)
31911 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31912 + : "1"(to), "2"(from), "0"(size)
31913 + : "eax", "edx", "memory");
31914 + return size;
31915 +}
31916 +
31917 +static unsigned long
31918 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31919 +{
31920 + int d0, d1;
31921 + __asm__ __volatile__(
31922 + " .align 2,0x90\n"
31923 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31924 + " cmpl $67, %0\n"
31925 + " jbe 3f\n"
31926 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31927 + " .align 2,0x90\n"
31928 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31929 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31930 + "5: movl %%eax, 0(%3)\n"
31931 + "6: movl %%edx, 4(%3)\n"
31932 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31933 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31934 + "9: movl %%eax, 8(%3)\n"
31935 + "10: movl %%edx, 12(%3)\n"
31936 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31937 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31938 + "13: movl %%eax, 16(%3)\n"
31939 + "14: movl %%edx, 20(%3)\n"
31940 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31941 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31942 + "17: movl %%eax, 24(%3)\n"
31943 + "18: movl %%edx, 28(%3)\n"
31944 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31945 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31946 + "21: movl %%eax, 32(%3)\n"
31947 + "22: movl %%edx, 36(%3)\n"
31948 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31949 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31950 + "25: movl %%eax, 40(%3)\n"
31951 + "26: movl %%edx, 44(%3)\n"
31952 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31953 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31954 + "29: movl %%eax, 48(%3)\n"
31955 + "30: movl %%edx, 52(%3)\n"
31956 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31957 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31958 + "33: movl %%eax, 56(%3)\n"
31959 + "34: movl %%edx, 60(%3)\n"
31960 + " addl $-64, %0\n"
31961 + " addl $64, %4\n"
31962 + " addl $64, %3\n"
31963 + " cmpl $63, %0\n"
31964 + " ja 1b\n"
31965 + "35: movl %0, %%eax\n"
31966 + " shrl $2, %0\n"
31967 + " andl $3, %%eax\n"
31968 + " cld\n"
31969 + "99: rep; "__copyuser_seg" movsl\n"
31970 + "36: movl %%eax, %0\n"
31971 + "37: rep; "__copyuser_seg" movsb\n"
31972 + "100:\n"
31973 ".section .fixup,\"ax\"\n"
31974 "101: lea 0(%%eax,%0,4),%0\n"
31975 " jmp 100b\n"
31976 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31977 int d0, d1;
31978 __asm__ __volatile__(
31979 " .align 2,0x90\n"
31980 - "0: movl 32(%4), %%eax\n"
31981 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31982 " cmpl $67, %0\n"
31983 " jbe 2f\n"
31984 - "1: movl 64(%4), %%eax\n"
31985 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31986 " .align 2,0x90\n"
31987 - "2: movl 0(%4), %%eax\n"
31988 - "21: movl 4(%4), %%edx\n"
31989 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31990 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31991 " movl %%eax, 0(%3)\n"
31992 " movl %%edx, 4(%3)\n"
31993 - "3: movl 8(%4), %%eax\n"
31994 - "31: movl 12(%4),%%edx\n"
31995 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31996 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31997 " movl %%eax, 8(%3)\n"
31998 " movl %%edx, 12(%3)\n"
31999 - "4: movl 16(%4), %%eax\n"
32000 - "41: movl 20(%4), %%edx\n"
32001 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32002 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32003 " movl %%eax, 16(%3)\n"
32004 " movl %%edx, 20(%3)\n"
32005 - "10: movl 24(%4), %%eax\n"
32006 - "51: movl 28(%4), %%edx\n"
32007 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32008 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32009 " movl %%eax, 24(%3)\n"
32010 " movl %%edx, 28(%3)\n"
32011 - "11: movl 32(%4), %%eax\n"
32012 - "61: movl 36(%4), %%edx\n"
32013 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32014 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32015 " movl %%eax, 32(%3)\n"
32016 " movl %%edx, 36(%3)\n"
32017 - "12: movl 40(%4), %%eax\n"
32018 - "71: movl 44(%4), %%edx\n"
32019 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32020 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32021 " movl %%eax, 40(%3)\n"
32022 " movl %%edx, 44(%3)\n"
32023 - "13: movl 48(%4), %%eax\n"
32024 - "81: movl 52(%4), %%edx\n"
32025 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32026 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32027 " movl %%eax, 48(%3)\n"
32028 " movl %%edx, 52(%3)\n"
32029 - "14: movl 56(%4), %%eax\n"
32030 - "91: movl 60(%4), %%edx\n"
32031 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32032 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32033 " movl %%eax, 56(%3)\n"
32034 " movl %%edx, 60(%3)\n"
32035 " addl $-64, %0\n"
32036 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
32037 " shrl $2, %0\n"
32038 " andl $3, %%eax\n"
32039 " cld\n"
32040 - "6: rep; movsl\n"
32041 + "6: rep; "__copyuser_seg" movsl\n"
32042 " movl %%eax,%0\n"
32043 - "7: rep; movsb\n"
32044 + "7: rep; "__copyuser_seg" movsb\n"
32045 "8:\n"
32046 ".section .fixup,\"ax\"\n"
32047 "9: lea 0(%%eax,%0,4),%0\n"
32048 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32049
32050 __asm__ __volatile__(
32051 " .align 2,0x90\n"
32052 - "0: movl 32(%4), %%eax\n"
32053 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32054 " cmpl $67, %0\n"
32055 " jbe 2f\n"
32056 - "1: movl 64(%4), %%eax\n"
32057 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32058 " .align 2,0x90\n"
32059 - "2: movl 0(%4), %%eax\n"
32060 - "21: movl 4(%4), %%edx\n"
32061 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32062 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32063 " movnti %%eax, 0(%3)\n"
32064 " movnti %%edx, 4(%3)\n"
32065 - "3: movl 8(%4), %%eax\n"
32066 - "31: movl 12(%4),%%edx\n"
32067 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32068 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32069 " movnti %%eax, 8(%3)\n"
32070 " movnti %%edx, 12(%3)\n"
32071 - "4: movl 16(%4), %%eax\n"
32072 - "41: movl 20(%4), %%edx\n"
32073 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32074 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32075 " movnti %%eax, 16(%3)\n"
32076 " movnti %%edx, 20(%3)\n"
32077 - "10: movl 24(%4), %%eax\n"
32078 - "51: movl 28(%4), %%edx\n"
32079 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32080 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32081 " movnti %%eax, 24(%3)\n"
32082 " movnti %%edx, 28(%3)\n"
32083 - "11: movl 32(%4), %%eax\n"
32084 - "61: movl 36(%4), %%edx\n"
32085 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32086 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32087 " movnti %%eax, 32(%3)\n"
32088 " movnti %%edx, 36(%3)\n"
32089 - "12: movl 40(%4), %%eax\n"
32090 - "71: movl 44(%4), %%edx\n"
32091 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32092 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32093 " movnti %%eax, 40(%3)\n"
32094 " movnti %%edx, 44(%3)\n"
32095 - "13: movl 48(%4), %%eax\n"
32096 - "81: movl 52(%4), %%edx\n"
32097 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32098 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32099 " movnti %%eax, 48(%3)\n"
32100 " movnti %%edx, 52(%3)\n"
32101 - "14: movl 56(%4), %%eax\n"
32102 - "91: movl 60(%4), %%edx\n"
32103 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32104 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32105 " movnti %%eax, 56(%3)\n"
32106 " movnti %%edx, 60(%3)\n"
32107 " addl $-64, %0\n"
32108 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32109 " shrl $2, %0\n"
32110 " andl $3, %%eax\n"
32111 " cld\n"
32112 - "6: rep; movsl\n"
32113 + "6: rep; "__copyuser_seg" movsl\n"
32114 " movl %%eax,%0\n"
32115 - "7: rep; movsb\n"
32116 + "7: rep; "__copyuser_seg" movsb\n"
32117 "8:\n"
32118 ".section .fixup,\"ax\"\n"
32119 "9: lea 0(%%eax,%0,4),%0\n"
32120 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32121
32122 __asm__ __volatile__(
32123 " .align 2,0x90\n"
32124 - "0: movl 32(%4), %%eax\n"
32125 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32126 " cmpl $67, %0\n"
32127 " jbe 2f\n"
32128 - "1: movl 64(%4), %%eax\n"
32129 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32130 " .align 2,0x90\n"
32131 - "2: movl 0(%4), %%eax\n"
32132 - "21: movl 4(%4), %%edx\n"
32133 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32134 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32135 " movnti %%eax, 0(%3)\n"
32136 " movnti %%edx, 4(%3)\n"
32137 - "3: movl 8(%4), %%eax\n"
32138 - "31: movl 12(%4),%%edx\n"
32139 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32140 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32141 " movnti %%eax, 8(%3)\n"
32142 " movnti %%edx, 12(%3)\n"
32143 - "4: movl 16(%4), %%eax\n"
32144 - "41: movl 20(%4), %%edx\n"
32145 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32146 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32147 " movnti %%eax, 16(%3)\n"
32148 " movnti %%edx, 20(%3)\n"
32149 - "10: movl 24(%4), %%eax\n"
32150 - "51: movl 28(%4), %%edx\n"
32151 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32152 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32153 " movnti %%eax, 24(%3)\n"
32154 " movnti %%edx, 28(%3)\n"
32155 - "11: movl 32(%4), %%eax\n"
32156 - "61: movl 36(%4), %%edx\n"
32157 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32158 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32159 " movnti %%eax, 32(%3)\n"
32160 " movnti %%edx, 36(%3)\n"
32161 - "12: movl 40(%4), %%eax\n"
32162 - "71: movl 44(%4), %%edx\n"
32163 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32164 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32165 " movnti %%eax, 40(%3)\n"
32166 " movnti %%edx, 44(%3)\n"
32167 - "13: movl 48(%4), %%eax\n"
32168 - "81: movl 52(%4), %%edx\n"
32169 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32170 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32171 " movnti %%eax, 48(%3)\n"
32172 " movnti %%edx, 52(%3)\n"
32173 - "14: movl 56(%4), %%eax\n"
32174 - "91: movl 60(%4), %%edx\n"
32175 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32176 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32177 " movnti %%eax, 56(%3)\n"
32178 " movnti %%edx, 60(%3)\n"
32179 " addl $-64, %0\n"
32180 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32181 " shrl $2, %0\n"
32182 " andl $3, %%eax\n"
32183 " cld\n"
32184 - "6: rep; movsl\n"
32185 + "6: rep; "__copyuser_seg" movsl\n"
32186 " movl %%eax,%0\n"
32187 - "7: rep; movsb\n"
32188 + "7: rep; "__copyuser_seg" movsb\n"
32189 "8:\n"
32190 ".section .fixup,\"ax\"\n"
32191 "9: lea 0(%%eax,%0,4),%0\n"
32192 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32193 */
32194 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32195 unsigned long size);
32196 -unsigned long __copy_user_intel(void __user *to, const void *from,
32197 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32198 + unsigned long size);
32199 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32200 unsigned long size);
32201 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32202 const void __user *from, unsigned long size);
32203 #endif /* CONFIG_X86_INTEL_USERCOPY */
32204
32205 /* Generic arbitrary sized copy. */
32206 -#define __copy_user(to, from, size) \
32207 +#define __copy_user(to, from, size, prefix, set, restore) \
32208 do { \
32209 int __d0, __d1, __d2; \
32210 __asm__ __volatile__( \
32211 + set \
32212 " cmp $7,%0\n" \
32213 " jbe 1f\n" \
32214 " movl %1,%0\n" \
32215 " negl %0\n" \
32216 " andl $7,%0\n" \
32217 " subl %0,%3\n" \
32218 - "4: rep; movsb\n" \
32219 + "4: rep; "prefix"movsb\n" \
32220 " movl %3,%0\n" \
32221 " shrl $2,%0\n" \
32222 " andl $3,%3\n" \
32223 " .align 2,0x90\n" \
32224 - "0: rep; movsl\n" \
32225 + "0: rep; "prefix"movsl\n" \
32226 " movl %3,%0\n" \
32227 - "1: rep; movsb\n" \
32228 + "1: rep; "prefix"movsb\n" \
32229 "2:\n" \
32230 + restore \
32231 ".section .fixup,\"ax\"\n" \
32232 "5: addl %3,%0\n" \
32233 " jmp 2b\n" \
32234 @@ -538,14 +650,14 @@ do { \
32235 " negl %0\n" \
32236 " andl $7,%0\n" \
32237 " subl %0,%3\n" \
32238 - "4: rep; movsb\n" \
32239 + "4: rep; "__copyuser_seg"movsb\n" \
32240 " movl %3,%0\n" \
32241 " shrl $2,%0\n" \
32242 " andl $3,%3\n" \
32243 " .align 2,0x90\n" \
32244 - "0: rep; movsl\n" \
32245 + "0: rep; "__copyuser_seg"movsl\n" \
32246 " movl %3,%0\n" \
32247 - "1: rep; movsb\n" \
32248 + "1: rep; "__copyuser_seg"movsb\n" \
32249 "2:\n" \
32250 ".section .fixup,\"ax\"\n" \
32251 "5: addl %3,%0\n" \
32252 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32253 {
32254 stac();
32255 if (movsl_is_ok(to, from, n))
32256 - __copy_user(to, from, n);
32257 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32258 else
32259 - n = __copy_user_intel(to, from, n);
32260 + n = __generic_copy_to_user_intel(to, from, n);
32261 clac();
32262 return n;
32263 }
32264 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32265 {
32266 stac();
32267 if (movsl_is_ok(to, from, n))
32268 - __copy_user(to, from, n);
32269 + __copy_user(to, from, n, __copyuser_seg, "", "");
32270 else
32271 - n = __copy_user_intel((void __user *)to,
32272 - (const void *)from, n);
32273 + n = __generic_copy_from_user_intel(to, from, n);
32274 clac();
32275 return n;
32276 }
32277 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32278 if (n > 64 && cpu_has_xmm2)
32279 n = __copy_user_intel_nocache(to, from, n);
32280 else
32281 - __copy_user(to, from, n);
32282 + __copy_user(to, from, n, __copyuser_seg, "", "");
32283 #else
32284 - __copy_user(to, from, n);
32285 + __copy_user(to, from, n, __copyuser_seg, "", "");
32286 #endif
32287 clac();
32288 return n;
32289 }
32290 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32291
32292 -/**
32293 - * copy_to_user: - Copy a block of data into user space.
32294 - * @to: Destination address, in user space.
32295 - * @from: Source address, in kernel space.
32296 - * @n: Number of bytes to copy.
32297 - *
32298 - * Context: User context only. This function may sleep.
32299 - *
32300 - * Copy data from kernel space to user space.
32301 - *
32302 - * Returns number of bytes that could not be copied.
32303 - * On success, this will be zero.
32304 - */
32305 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32306 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32307 +void __set_fs(mm_segment_t x)
32308 {
32309 - if (access_ok(VERIFY_WRITE, to, n))
32310 - n = __copy_to_user(to, from, n);
32311 - return n;
32312 + switch (x.seg) {
32313 + case 0:
32314 + loadsegment(gs, 0);
32315 + break;
32316 + case TASK_SIZE_MAX:
32317 + loadsegment(gs, __USER_DS);
32318 + break;
32319 + case -1UL:
32320 + loadsegment(gs, __KERNEL_DS);
32321 + break;
32322 + default:
32323 + BUG();
32324 + }
32325 }
32326 -EXPORT_SYMBOL(_copy_to_user);
32327 +EXPORT_SYMBOL(__set_fs);
32328
32329 -/**
32330 - * copy_from_user: - Copy a block of data from user space.
32331 - * @to: Destination address, in kernel space.
32332 - * @from: Source address, in user space.
32333 - * @n: Number of bytes to copy.
32334 - *
32335 - * Context: User context only. This function may sleep.
32336 - *
32337 - * Copy data from user space to kernel space.
32338 - *
32339 - * Returns number of bytes that could not be copied.
32340 - * On success, this will be zero.
32341 - *
32342 - * If some data could not be copied, this function will pad the copied
32343 - * data to the requested size using zero bytes.
32344 - */
32345 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32346 +void set_fs(mm_segment_t x)
32347 {
32348 - if (access_ok(VERIFY_READ, from, n))
32349 - n = __copy_from_user(to, from, n);
32350 - else
32351 - memset(to, 0, n);
32352 - return n;
32353 + current_thread_info()->addr_limit = x;
32354 + __set_fs(x);
32355 }
32356 -EXPORT_SYMBOL(_copy_from_user);
32357 +EXPORT_SYMBOL(set_fs);
32358 +#endif
32359 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32360 index c905e89..01ab928 100644
32361 --- a/arch/x86/lib/usercopy_64.c
32362 +++ b/arch/x86/lib/usercopy_64.c
32363 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32364 might_fault();
32365 /* no memory constraint because it doesn't change any memory gcc knows
32366 about */
32367 + pax_open_userland();
32368 stac();
32369 asm volatile(
32370 " testq %[size8],%[size8]\n"
32371 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32372 _ASM_EXTABLE(0b,3b)
32373 _ASM_EXTABLE(1b,2b)
32374 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32375 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32376 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32377 [zero] "r" (0UL), [eight] "r" (8UL));
32378 clac();
32379 + pax_close_userland();
32380 return size;
32381 }
32382 EXPORT_SYMBOL(__clear_user);
32383 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32384 }
32385 EXPORT_SYMBOL(clear_user);
32386
32387 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32388 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32389 {
32390 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32391 - return copy_user_generic((__force void *)to, (__force void *)from, len);
32392 - }
32393 - return len;
32394 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32395 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32396 + return len;
32397 }
32398 EXPORT_SYMBOL(copy_in_user);
32399
32400 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32401 * it is not necessary to optimize tail handling.
32402 */
32403 __visible unsigned long
32404 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32405 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32406 {
32407 char c;
32408 unsigned zero_len;
32409
32410 + clac();
32411 + pax_close_userland();
32412 for (; len; --len, to++) {
32413 if (__get_user_nocheck(c, from++, sizeof(char)))
32414 break;
32415 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32416 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32417 if (__put_user_nocheck(c, to++, sizeof(char)))
32418 break;
32419 - clac();
32420 return len;
32421 }
32422 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32423 index 6a19ad9..1c48f9a 100644
32424 --- a/arch/x86/mm/Makefile
32425 +++ b/arch/x86/mm/Makefile
32426 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32427 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32428
32429 obj-$(CONFIG_MEMTEST) += memtest.o
32430 +
32431 +quote:="
32432 +obj-$(CONFIG_X86_64) += uderef_64.o
32433 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32434 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32435 index 903ec1e..c4166b2 100644
32436 --- a/arch/x86/mm/extable.c
32437 +++ b/arch/x86/mm/extable.c
32438 @@ -6,12 +6,24 @@
32439 static inline unsigned long
32440 ex_insn_addr(const struct exception_table_entry *x)
32441 {
32442 - return (unsigned long)&x->insn + x->insn;
32443 + unsigned long reloc = 0;
32444 +
32445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32446 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32447 +#endif
32448 +
32449 + return (unsigned long)&x->insn + x->insn + reloc;
32450 }
32451 static inline unsigned long
32452 ex_fixup_addr(const struct exception_table_entry *x)
32453 {
32454 - return (unsigned long)&x->fixup + x->fixup;
32455 + unsigned long reloc = 0;
32456 +
32457 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32458 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32459 +#endif
32460 +
32461 + return (unsigned long)&x->fixup + x->fixup + reloc;
32462 }
32463
32464 int fixup_exception(struct pt_regs *regs)
32465 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32466 unsigned long new_ip;
32467
32468 #ifdef CONFIG_PNPBIOS
32469 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32470 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32471 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32472 extern u32 pnp_bios_is_utter_crap;
32473 pnp_bios_is_utter_crap = 1;
32474 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32475 i += 4;
32476 p->fixup -= i;
32477 i += 4;
32478 +
32479 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32480 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32481 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32482 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32483 +#endif
32484 +
32485 }
32486 }
32487
32488 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32489 index a241946..d7a04cf 100644
32490 --- a/arch/x86/mm/fault.c
32491 +++ b/arch/x86/mm/fault.c
32492 @@ -14,12 +14,19 @@
32493 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32494 #include <linux/prefetch.h> /* prefetchw */
32495 #include <linux/context_tracking.h> /* exception_enter(), ... */
32496 +#include <linux/unistd.h>
32497 +#include <linux/compiler.h>
32498
32499 #include <asm/traps.h> /* dotraplinkage, ... */
32500 #include <asm/pgalloc.h> /* pgd_*(), ... */
32501 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32502 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32503 #include <asm/vsyscall.h> /* emulate_vsyscall */
32504 +#include <asm/tlbflush.h>
32505 +
32506 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32507 +#include <asm/stacktrace.h>
32508 +#endif
32509
32510 #define CREATE_TRACE_POINTS
32511 #include <asm/trace/exceptions.h>
32512 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32513 int ret = 0;
32514
32515 /* kprobe_running() needs smp_processor_id() */
32516 - if (kprobes_built_in() && !user_mode_vm(regs)) {
32517 + if (kprobes_built_in() && !user_mode(regs)) {
32518 preempt_disable();
32519 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32520 ret = 1;
32521 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32522 return !instr_lo || (instr_lo>>1) == 1;
32523 case 0x00:
32524 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32525 - if (probe_kernel_address(instr, opcode))
32526 + if (user_mode(regs)) {
32527 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32528 + return 0;
32529 + } else if (probe_kernel_address(instr, opcode))
32530 return 0;
32531
32532 *prefetch = (instr_lo == 0xF) &&
32533 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32534 while (instr < max_instr) {
32535 unsigned char opcode;
32536
32537 - if (probe_kernel_address(instr, opcode))
32538 + if (user_mode(regs)) {
32539 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32540 + break;
32541 + } else if (probe_kernel_address(instr, opcode))
32542 break;
32543
32544 instr++;
32545 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32546 force_sig_info(si_signo, &info, tsk);
32547 }
32548
32549 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32550 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32551 +#endif
32552 +
32553 +#ifdef CONFIG_PAX_EMUTRAMP
32554 +static int pax_handle_fetch_fault(struct pt_regs *regs);
32555 +#endif
32556 +
32557 +#ifdef CONFIG_PAX_PAGEEXEC
32558 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32559 +{
32560 + pgd_t *pgd;
32561 + pud_t *pud;
32562 + pmd_t *pmd;
32563 +
32564 + pgd = pgd_offset(mm, address);
32565 + if (!pgd_present(*pgd))
32566 + return NULL;
32567 + pud = pud_offset(pgd, address);
32568 + if (!pud_present(*pud))
32569 + return NULL;
32570 + pmd = pmd_offset(pud, address);
32571 + if (!pmd_present(*pmd))
32572 + return NULL;
32573 + return pmd;
32574 +}
32575 +#endif
32576 +
32577 DEFINE_SPINLOCK(pgd_lock);
32578 LIST_HEAD(pgd_list);
32579
32580 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32581 for (address = VMALLOC_START & PMD_MASK;
32582 address >= TASK_SIZE && address < FIXADDR_TOP;
32583 address += PMD_SIZE) {
32584 +
32585 +#ifdef CONFIG_PAX_PER_CPU_PGD
32586 + unsigned long cpu;
32587 +#else
32588 struct page *page;
32589 +#endif
32590
32591 spin_lock(&pgd_lock);
32592 +
32593 +#ifdef CONFIG_PAX_PER_CPU_PGD
32594 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32595 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32596 + pmd_t *ret;
32597 +
32598 + ret = vmalloc_sync_one(pgd, address);
32599 + if (!ret)
32600 + break;
32601 + pgd = get_cpu_pgd(cpu, kernel);
32602 +#else
32603 list_for_each_entry(page, &pgd_list, lru) {
32604 + pgd_t *pgd;
32605 spinlock_t *pgt_lock;
32606 pmd_t *ret;
32607
32608 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32609 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32610
32611 spin_lock(pgt_lock);
32612 - ret = vmalloc_sync_one(page_address(page), address);
32613 + pgd = page_address(page);
32614 +#endif
32615 +
32616 + ret = vmalloc_sync_one(pgd, address);
32617 +
32618 +#ifndef CONFIG_PAX_PER_CPU_PGD
32619 spin_unlock(pgt_lock);
32620 +#endif
32621
32622 if (!ret)
32623 break;
32624 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32625 * an interrupt in the middle of a task switch..
32626 */
32627 pgd_paddr = read_cr3();
32628 +
32629 +#ifdef CONFIG_PAX_PER_CPU_PGD
32630 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32631 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32632 +#endif
32633 +
32634 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32635 if (!pmd_k)
32636 return -1;
32637 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32638 * happen within a race in page table update. In the later
32639 * case just flush:
32640 */
32641 - pgd = pgd_offset(current->active_mm, address);
32642 +
32643 pgd_ref = pgd_offset_k(address);
32644 if (pgd_none(*pgd_ref))
32645 return -1;
32646
32647 +#ifdef CONFIG_PAX_PER_CPU_PGD
32648 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32649 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32650 + if (pgd_none(*pgd)) {
32651 + set_pgd(pgd, *pgd_ref);
32652 + arch_flush_lazy_mmu_mode();
32653 + } else {
32654 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32655 + }
32656 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32657 +#else
32658 + pgd = pgd_offset(current->active_mm, address);
32659 +#endif
32660 +
32661 if (pgd_none(*pgd)) {
32662 set_pgd(pgd, *pgd_ref);
32663 arch_flush_lazy_mmu_mode();
32664 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32665 static int is_errata100(struct pt_regs *regs, unsigned long address)
32666 {
32667 #ifdef CONFIG_X86_64
32668 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32669 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32670 return 1;
32671 #endif
32672 return 0;
32673 @@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32674 }
32675
32676 static const char nx_warning[] = KERN_CRIT
32677 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32678 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32679 static const char smep_warning[] = KERN_CRIT
32680 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
32681 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32682
32683 static void
32684 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32685 @@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32686 if (!oops_may_print())
32687 return;
32688
32689 - if (error_code & PF_INSTR) {
32690 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32691 unsigned int level;
32692 pgd_t *pgd;
32693 pte_t *pte;
32694 @@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32695 pte = lookup_address_in_pgd(pgd, address, &level);
32696
32697 if (pte && pte_present(*pte) && !pte_exec(*pte))
32698 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32699 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32700 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32701 (pgd_flags(*pgd) & _PAGE_USER) &&
32702 (read_cr4() & X86_CR4_SMEP))
32703 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32704 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32705 }
32706
32707 +#ifdef CONFIG_PAX_KERNEXEC
32708 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32709 + if (current->signal->curr_ip)
32710 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32711 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32712 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32713 + else
32714 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32715 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32716 + }
32717 +#endif
32718 +
32719 printk(KERN_ALERT "BUG: unable to handle kernel ");
32720 if (address < PAGE_SIZE)
32721 printk(KERN_CONT "NULL pointer dereference");
32722 @@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32723 return;
32724 }
32725 #endif
32726 +
32727 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32728 + if (pax_is_fetch_fault(regs, error_code, address)) {
32729 +
32730 +#ifdef CONFIG_PAX_EMUTRAMP
32731 + switch (pax_handle_fetch_fault(regs)) {
32732 + case 2:
32733 + return;
32734 + }
32735 +#endif
32736 +
32737 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32738 + do_group_exit(SIGKILL);
32739 + }
32740 +#endif
32741 +
32742 /* Kernel addresses are always protection faults: */
32743 if (address >= TASK_SIZE)
32744 error_code |= PF_PROT;
32745 @@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32746 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32747 printk(KERN_ERR
32748 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32749 - tsk->comm, tsk->pid, address);
32750 + tsk->comm, task_pid_nr(tsk), address);
32751 code = BUS_MCEERR_AR;
32752 }
32753 #endif
32754 @@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32755 return 1;
32756 }
32757
32758 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32759 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32760 +{
32761 + pte_t *pte;
32762 + pmd_t *pmd;
32763 + spinlock_t *ptl;
32764 + unsigned char pte_mask;
32765 +
32766 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32767 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32768 + return 0;
32769 +
32770 + /* PaX: it's our fault, let's handle it if we can */
32771 +
32772 + /* PaX: take a look at read faults before acquiring any locks */
32773 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32774 + /* instruction fetch attempt from a protected page in user mode */
32775 + up_read(&mm->mmap_sem);
32776 +
32777 +#ifdef CONFIG_PAX_EMUTRAMP
32778 + switch (pax_handle_fetch_fault(regs)) {
32779 + case 2:
32780 + return 1;
32781 + }
32782 +#endif
32783 +
32784 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32785 + do_group_exit(SIGKILL);
32786 + }
32787 +
32788 + pmd = pax_get_pmd(mm, address);
32789 + if (unlikely(!pmd))
32790 + return 0;
32791 +
32792 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32793 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32794 + pte_unmap_unlock(pte, ptl);
32795 + return 0;
32796 + }
32797 +
32798 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32799 + /* write attempt to a protected page in user mode */
32800 + pte_unmap_unlock(pte, ptl);
32801 + return 0;
32802 + }
32803 +
32804 +#ifdef CONFIG_SMP
32805 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32806 +#else
32807 + if (likely(address > get_limit(regs->cs)))
32808 +#endif
32809 + {
32810 + set_pte(pte, pte_mkread(*pte));
32811 + __flush_tlb_one(address);
32812 + pte_unmap_unlock(pte, ptl);
32813 + up_read(&mm->mmap_sem);
32814 + return 1;
32815 + }
32816 +
32817 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32818 +
32819 + /*
32820 + * PaX: fill DTLB with user rights and retry
32821 + */
32822 + __asm__ __volatile__ (
32823 + "orb %2,(%1)\n"
32824 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32825 +/*
32826 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32827 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32828 + * page fault when examined during a TLB load attempt. this is true not only
32829 + * for PTEs holding a non-present entry but also present entries that will
32830 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32831 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32832 + * for our target pages since their PTEs are simply not in the TLBs at all.
32833 +
32834 + * the best thing in omitting it is that we gain around 15-20% speed in the
32835 + * fast path of the page fault handler and can get rid of tracing since we
32836 + * can no longer flush unintended entries.
32837 + */
32838 + "invlpg (%0)\n"
32839 +#endif
32840 + __copyuser_seg"testb $0,(%0)\n"
32841 + "xorb %3,(%1)\n"
32842 + :
32843 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32844 + : "memory", "cc");
32845 + pte_unmap_unlock(pte, ptl);
32846 + up_read(&mm->mmap_sem);
32847 + return 1;
32848 +}
32849 +#endif
32850 +
32851 /*
32852 * Handle a spurious fault caused by a stale TLB entry.
32853 *
32854 @@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
32855 static inline int
32856 access_error(unsigned long error_code, struct vm_area_struct *vma)
32857 {
32858 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32859 + return 1;
32860 +
32861 if (error_code & PF_WRITE) {
32862 /* write, present and write, not present: */
32863 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32864 @@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32865 if (error_code & PF_USER)
32866 return false;
32867
32868 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32869 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32870 return false;
32871
32872 return true;
32873 @@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32874 tsk = current;
32875 mm = tsk->mm;
32876
32877 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32878 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32879 + if (!search_exception_tables(regs->ip)) {
32880 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32881 + bad_area_nosemaphore(regs, error_code, address);
32882 + return;
32883 + }
32884 + if (address < pax_user_shadow_base) {
32885 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32886 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32887 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32888 + } else
32889 + address -= pax_user_shadow_base;
32890 + }
32891 +#endif
32892 +
32893 /*
32894 * Detect and handle instructions that would cause a page fault for
32895 * both a tracked kernel page and a userspace page.
32896 @@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32897 * User-mode registers count as a user access even for any
32898 * potential system fault or CPU buglet:
32899 */
32900 - if (user_mode_vm(regs)) {
32901 + if (user_mode(regs)) {
32902 local_irq_enable();
32903 error_code |= PF_USER;
32904 flags |= FAULT_FLAG_USER;
32905 @@ -1177,6 +1401,11 @@ retry:
32906 might_sleep();
32907 }
32908
32909 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32910 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32911 + return;
32912 +#endif
32913 +
32914 vma = find_vma(mm, address);
32915 if (unlikely(!vma)) {
32916 bad_area(regs, error_code, address);
32917 @@ -1188,18 +1417,24 @@ retry:
32918 bad_area(regs, error_code, address);
32919 return;
32920 }
32921 - if (error_code & PF_USER) {
32922 - /*
32923 - * Accessing the stack below %sp is always a bug.
32924 - * The large cushion allows instructions like enter
32925 - * and pusha to work. ("enter $65535, $31" pushes
32926 - * 32 pointers and then decrements %sp by 65535.)
32927 - */
32928 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32929 - bad_area(regs, error_code, address);
32930 - return;
32931 - }
32932 + /*
32933 + * Accessing the stack below %sp is always a bug.
32934 + * The large cushion allows instructions like enter
32935 + * and pusha to work. ("enter $65535, $31" pushes
32936 + * 32 pointers and then decrements %sp by 65535.)
32937 + */
32938 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32939 + bad_area(regs, error_code, address);
32940 + return;
32941 }
32942 +
32943 +#ifdef CONFIG_PAX_SEGMEXEC
32944 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32945 + bad_area(regs, error_code, address);
32946 + return;
32947 + }
32948 +#endif
32949 +
32950 if (unlikely(expand_stack(vma, address))) {
32951 bad_area(regs, error_code, address);
32952 return;
32953 @@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32954 }
32955 NOKPROBE_SYMBOL(trace_do_page_fault);
32956 #endif /* CONFIG_TRACING */
32957 +
32958 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32959 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32960 +{
32961 + struct mm_struct *mm = current->mm;
32962 + unsigned long ip = regs->ip;
32963 +
32964 + if (v8086_mode(regs))
32965 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32966 +
32967 +#ifdef CONFIG_PAX_PAGEEXEC
32968 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32969 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32970 + return true;
32971 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32972 + return true;
32973 + return false;
32974 + }
32975 +#endif
32976 +
32977 +#ifdef CONFIG_PAX_SEGMEXEC
32978 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32979 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32980 + return true;
32981 + return false;
32982 + }
32983 +#endif
32984 +
32985 + return false;
32986 +}
32987 +#endif
32988 +
32989 +#ifdef CONFIG_PAX_EMUTRAMP
32990 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32991 +{
32992 + int err;
32993 +
32994 + do { /* PaX: libffi trampoline emulation */
32995 + unsigned char mov, jmp;
32996 + unsigned int addr1, addr2;
32997 +
32998 +#ifdef CONFIG_X86_64
32999 + if ((regs->ip + 9) >> 32)
33000 + break;
33001 +#endif
33002 +
33003 + err = get_user(mov, (unsigned char __user *)regs->ip);
33004 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33005 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33006 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33007 +
33008 + if (err)
33009 + break;
33010 +
33011 + if (mov == 0xB8 && jmp == 0xE9) {
33012 + regs->ax = addr1;
33013 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33014 + return 2;
33015 + }
33016 + } while (0);
33017 +
33018 + do { /* PaX: gcc trampoline emulation #1 */
33019 + unsigned char mov1, mov2;
33020 + unsigned short jmp;
33021 + unsigned int addr1, addr2;
33022 +
33023 +#ifdef CONFIG_X86_64
33024 + if ((regs->ip + 11) >> 32)
33025 + break;
33026 +#endif
33027 +
33028 + err = get_user(mov1, (unsigned char __user *)regs->ip);
33029 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33030 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
33031 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33032 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
33033 +
33034 + if (err)
33035 + break;
33036 +
33037 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
33038 + regs->cx = addr1;
33039 + regs->ax = addr2;
33040 + regs->ip = addr2;
33041 + return 2;
33042 + }
33043 + } while (0);
33044 +
33045 + do { /* PaX: gcc trampoline emulation #2 */
33046 + unsigned char mov, jmp;
33047 + unsigned int addr1, addr2;
33048 +
33049 +#ifdef CONFIG_X86_64
33050 + if ((regs->ip + 9) >> 32)
33051 + break;
33052 +#endif
33053 +
33054 + err = get_user(mov, (unsigned char __user *)regs->ip);
33055 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33056 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33057 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33058 +
33059 + if (err)
33060 + break;
33061 +
33062 + if (mov == 0xB9 && jmp == 0xE9) {
33063 + regs->cx = addr1;
33064 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33065 + return 2;
33066 + }
33067 + } while (0);
33068 +
33069 + return 1; /* PaX in action */
33070 +}
33071 +
33072 +#ifdef CONFIG_X86_64
33073 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
33074 +{
33075 + int err;
33076 +
33077 + do { /* PaX: libffi trampoline emulation */
33078 + unsigned short mov1, mov2, jmp1;
33079 + unsigned char stcclc, jmp2;
33080 + unsigned long addr1, addr2;
33081 +
33082 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33083 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33084 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33085 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33086 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33087 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33088 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33089 +
33090 + if (err)
33091 + break;
33092 +
33093 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33094 + regs->r11 = addr1;
33095 + regs->r10 = addr2;
33096 + if (stcclc == 0xF8)
33097 + regs->flags &= ~X86_EFLAGS_CF;
33098 + else
33099 + regs->flags |= X86_EFLAGS_CF;
33100 + regs->ip = addr1;
33101 + return 2;
33102 + }
33103 + } while (0);
33104 +
33105 + do { /* PaX: gcc trampoline emulation #1 */
33106 + unsigned short mov1, mov2, jmp1;
33107 + unsigned char jmp2;
33108 + unsigned int addr1;
33109 + unsigned long addr2;
33110 +
33111 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33112 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33113 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33114 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33115 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33116 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33117 +
33118 + if (err)
33119 + break;
33120 +
33121 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33122 + regs->r11 = addr1;
33123 + regs->r10 = addr2;
33124 + regs->ip = addr1;
33125 + return 2;
33126 + }
33127 + } while (0);
33128 +
33129 + do { /* PaX: gcc trampoline emulation #2 */
33130 + unsigned short mov1, mov2, jmp1;
33131 + unsigned char jmp2;
33132 + unsigned long addr1, addr2;
33133 +
33134 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33135 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33136 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33137 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33138 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33139 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33140 +
33141 + if (err)
33142 + break;
33143 +
33144 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33145 + regs->r11 = addr1;
33146 + regs->r10 = addr2;
33147 + regs->ip = addr1;
33148 + return 2;
33149 + }
33150 + } while (0);
33151 +
33152 + return 1; /* PaX in action */
33153 +}
33154 +#endif
33155 +
33156 +/*
33157 + * PaX: decide what to do with offenders (regs->ip = fault address)
33158 + *
33159 + * returns 1 when task should be killed
33160 + * 2 when gcc trampoline was detected
33161 + */
33162 +static int pax_handle_fetch_fault(struct pt_regs *regs)
33163 +{
33164 + if (v8086_mode(regs))
33165 + return 1;
33166 +
33167 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33168 + return 1;
33169 +
33170 +#ifdef CONFIG_X86_32
33171 + return pax_handle_fetch_fault_32(regs);
33172 +#else
33173 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33174 + return pax_handle_fetch_fault_32(regs);
33175 + else
33176 + return pax_handle_fetch_fault_64(regs);
33177 +#endif
33178 +}
33179 +#endif
33180 +
33181 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33182 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33183 +{
33184 + long i;
33185 +
33186 + printk(KERN_ERR "PAX: bytes at PC: ");
33187 + for (i = 0; i < 20; i++) {
33188 + unsigned char c;
33189 + if (get_user(c, (unsigned char __force_user *)pc+i))
33190 + printk(KERN_CONT "?? ");
33191 + else
33192 + printk(KERN_CONT "%02x ", c);
33193 + }
33194 + printk("\n");
33195 +
33196 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33197 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
33198 + unsigned long c;
33199 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
33200 +#ifdef CONFIG_X86_32
33201 + printk(KERN_CONT "???????? ");
33202 +#else
33203 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33204 + printk(KERN_CONT "???????? ???????? ");
33205 + else
33206 + printk(KERN_CONT "???????????????? ");
33207 +#endif
33208 + } else {
33209 +#ifdef CONFIG_X86_64
33210 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33211 + printk(KERN_CONT "%08x ", (unsigned int)c);
33212 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33213 + } else
33214 +#endif
33215 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33216 + }
33217 + }
33218 + printk("\n");
33219 +}
33220 +#endif
33221 +
33222 +/**
33223 + * probe_kernel_write(): safely attempt to write to a location
33224 + * @dst: address to write to
33225 + * @src: pointer to the data that shall be written
33226 + * @size: size of the data chunk
33227 + *
33228 + * Safely write to address @dst from the buffer at @src. If a kernel fault
33229 + * happens, handle that and return -EFAULT.
33230 + */
33231 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33232 +{
33233 + long ret;
33234 + mm_segment_t old_fs = get_fs();
33235 +
33236 + set_fs(KERNEL_DS);
33237 + pagefault_disable();
33238 + pax_open_kernel();
33239 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33240 + pax_close_kernel();
33241 + pagefault_enable();
33242 + set_fs(old_fs);
33243 +
33244 + return ret ? -EFAULT : 0;
33245 +}
33246 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33247 index 207d9aef..69030980 100644
33248 --- a/arch/x86/mm/gup.c
33249 +++ b/arch/x86/mm/gup.c
33250 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33251 addr = start;
33252 len = (unsigned long) nr_pages << PAGE_SHIFT;
33253 end = start + len;
33254 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33255 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33256 (void __user *)start, len)))
33257 return 0;
33258
33259 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33260 goto slow_irqon;
33261 #endif
33262
33263 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33264 + (void __user *)start, len)))
33265 + return 0;
33266 +
33267 /*
33268 * XXX: batch / limit 'nr', to avoid large irq off latency
33269 * needs some instrumenting to determine the common sizes used by
33270 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33271 index 4500142..53a363c 100644
33272 --- a/arch/x86/mm/highmem_32.c
33273 +++ b/arch/x86/mm/highmem_32.c
33274 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33275 idx = type + KM_TYPE_NR*smp_processor_id();
33276 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33277 BUG_ON(!pte_none(*(kmap_pte-idx)));
33278 +
33279 + pax_open_kernel();
33280 set_pte(kmap_pte-idx, mk_pte(page, prot));
33281 + pax_close_kernel();
33282 +
33283 arch_flush_lazy_mmu_mode();
33284
33285 return (void *)vaddr;
33286 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33287 index 8b977eb..4732c33 100644
33288 --- a/arch/x86/mm/hugetlbpage.c
33289 +++ b/arch/x86/mm/hugetlbpage.c
33290 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33291 #ifdef CONFIG_HUGETLB_PAGE
33292 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33293 unsigned long addr, unsigned long len,
33294 - unsigned long pgoff, unsigned long flags)
33295 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33296 {
33297 struct hstate *h = hstate_file(file);
33298 struct vm_unmapped_area_info info;
33299 -
33300 +
33301 info.flags = 0;
33302 info.length = len;
33303 info.low_limit = current->mm->mmap_legacy_base;
33304 info.high_limit = TASK_SIZE;
33305 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33306 info.align_offset = 0;
33307 + info.threadstack_offset = offset;
33308 return vm_unmapped_area(&info);
33309 }
33310
33311 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33312 unsigned long addr0, unsigned long len,
33313 - unsigned long pgoff, unsigned long flags)
33314 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33315 {
33316 struct hstate *h = hstate_file(file);
33317 struct vm_unmapped_area_info info;
33318 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33319 info.high_limit = current->mm->mmap_base;
33320 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33321 info.align_offset = 0;
33322 + info.threadstack_offset = offset;
33323 addr = vm_unmapped_area(&info);
33324
33325 /*
33326 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33327 VM_BUG_ON(addr != -ENOMEM);
33328 info.flags = 0;
33329 info.low_limit = TASK_UNMAPPED_BASE;
33330 +
33331 +#ifdef CONFIG_PAX_RANDMMAP
33332 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33333 + info.low_limit += current->mm->delta_mmap;
33334 +#endif
33335 +
33336 info.high_limit = TASK_SIZE;
33337 addr = vm_unmapped_area(&info);
33338 }
33339 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33340 struct hstate *h = hstate_file(file);
33341 struct mm_struct *mm = current->mm;
33342 struct vm_area_struct *vma;
33343 + unsigned long pax_task_size = TASK_SIZE;
33344 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33345
33346 if (len & ~huge_page_mask(h))
33347 return -EINVAL;
33348 - if (len > TASK_SIZE)
33349 +
33350 +#ifdef CONFIG_PAX_SEGMEXEC
33351 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33352 + pax_task_size = SEGMEXEC_TASK_SIZE;
33353 +#endif
33354 +
33355 + pax_task_size -= PAGE_SIZE;
33356 +
33357 + if (len > pax_task_size)
33358 return -ENOMEM;
33359
33360 if (flags & MAP_FIXED) {
33361 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33362 return addr;
33363 }
33364
33365 +#ifdef CONFIG_PAX_RANDMMAP
33366 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33367 +#endif
33368 +
33369 if (addr) {
33370 addr = ALIGN(addr, huge_page_size(h));
33371 vma = find_vma(mm, addr);
33372 - if (TASK_SIZE - len >= addr &&
33373 - (!vma || addr + len <= vma->vm_start))
33374 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33375 return addr;
33376 }
33377 if (mm->get_unmapped_area == arch_get_unmapped_area)
33378 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33379 - pgoff, flags);
33380 + pgoff, flags, offset);
33381 else
33382 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33383 - pgoff, flags);
33384 + pgoff, flags, offset);
33385 }
33386 #endif /* CONFIG_HUGETLB_PAGE */
33387
33388 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33389 index 66dba36..f8082ec 100644
33390 --- a/arch/x86/mm/init.c
33391 +++ b/arch/x86/mm/init.c
33392 @@ -4,6 +4,7 @@
33393 #include <linux/swap.h>
33394 #include <linux/memblock.h>
33395 #include <linux/bootmem.h> /* for max_low_pfn */
33396 +#include <linux/tboot.h>
33397
33398 #include <asm/cacheflush.h>
33399 #include <asm/e820.h>
33400 @@ -17,6 +18,8 @@
33401 #include <asm/proto.h>
33402 #include <asm/dma.h> /* for MAX_DMA_PFN */
33403 #include <asm/microcode.h>
33404 +#include <asm/desc.h>
33405 +#include <asm/bios_ebda.h>
33406
33407 /*
33408 * We need to define the tracepoints somewhere, and tlb.c
33409 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33410 early_ioremap_page_table_range_init();
33411 #endif
33412
33413 +#ifdef CONFIG_PAX_PER_CPU_PGD
33414 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33415 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33416 + KERNEL_PGD_PTRS);
33417 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33418 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33419 + KERNEL_PGD_PTRS);
33420 + load_cr3(get_cpu_pgd(0, kernel));
33421 +#else
33422 load_cr3(swapper_pg_dir);
33423 +#endif
33424 +
33425 __flush_tlb_all();
33426
33427 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33428 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33429 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33430 * mmio resources as well as potential bios/acpi data regions.
33431 */
33432 +
33433 +#ifdef CONFIG_GRKERNSEC_KMEM
33434 +static unsigned int ebda_start __read_only;
33435 +static unsigned int ebda_end __read_only;
33436 +#endif
33437 +
33438 int devmem_is_allowed(unsigned long pagenr)
33439 {
33440 - if (pagenr < 256)
33441 +#ifdef CONFIG_GRKERNSEC_KMEM
33442 + /* allow BDA */
33443 + if (!pagenr)
33444 return 1;
33445 + /* allow EBDA */
33446 + if (pagenr >= ebda_start && pagenr < ebda_end)
33447 + return 1;
33448 + /* if tboot is in use, allow access to its hardcoded serial log range */
33449 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33450 + return 1;
33451 +#else
33452 + if (!pagenr)
33453 + return 1;
33454 +#ifdef CONFIG_VM86
33455 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33456 + return 1;
33457 +#endif
33458 +#endif
33459 +
33460 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33461 + return 1;
33462 +#ifdef CONFIG_GRKERNSEC_KMEM
33463 + /* throw out everything else below 1MB */
33464 + if (pagenr <= 256)
33465 + return 0;
33466 +#endif
33467 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33468 return 0;
33469 if (!page_is_ram(pagenr))
33470 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33471 #endif
33472 }
33473
33474 +#ifdef CONFIG_GRKERNSEC_KMEM
33475 +static inline void gr_init_ebda(void)
33476 +{
33477 + unsigned int ebda_addr;
33478 + unsigned int ebda_size = 0;
33479 +
33480 + ebda_addr = get_bios_ebda();
33481 + if (ebda_addr) {
33482 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33483 + ebda_size <<= 10;
33484 + }
33485 + if (ebda_addr && ebda_size) {
33486 + ebda_start = ebda_addr >> PAGE_SHIFT;
33487 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33488 + } else {
33489 + ebda_start = 0x9f000 >> PAGE_SHIFT;
33490 + ebda_end = 0xa0000 >> PAGE_SHIFT;
33491 + }
33492 +}
33493 +#else
33494 +static inline void gr_init_ebda(void) { }
33495 +#endif
33496 +
33497 void free_initmem(void)
33498 {
33499 +#ifdef CONFIG_PAX_KERNEXEC
33500 +#ifdef CONFIG_X86_32
33501 + /* PaX: limit KERNEL_CS to actual size */
33502 + unsigned long addr, limit;
33503 + struct desc_struct d;
33504 + int cpu;
33505 +#else
33506 + pgd_t *pgd;
33507 + pud_t *pud;
33508 + pmd_t *pmd;
33509 + unsigned long addr, end;
33510 +#endif
33511 +#endif
33512 +
33513 + gr_init_ebda();
33514 +
33515 +#ifdef CONFIG_PAX_KERNEXEC
33516 +#ifdef CONFIG_X86_32
33517 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33518 + limit = (limit - 1UL) >> PAGE_SHIFT;
33519 +
33520 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33521 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33522 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33523 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33524 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33525 + }
33526 +
33527 + /* PaX: make KERNEL_CS read-only */
33528 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33529 + if (!paravirt_enabled())
33530 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33531 +/*
33532 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33533 + pgd = pgd_offset_k(addr);
33534 + pud = pud_offset(pgd, addr);
33535 + pmd = pmd_offset(pud, addr);
33536 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33537 + }
33538 +*/
33539 +#ifdef CONFIG_X86_PAE
33540 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33541 +/*
33542 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33543 + pgd = pgd_offset_k(addr);
33544 + pud = pud_offset(pgd, addr);
33545 + pmd = pmd_offset(pud, addr);
33546 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33547 + }
33548 +*/
33549 +#endif
33550 +
33551 +#ifdef CONFIG_MODULES
33552 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33553 +#endif
33554 +
33555 +#else
33556 + /* PaX: make kernel code/rodata read-only, rest non-executable */
33557 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33558 + pgd = pgd_offset_k(addr);
33559 + pud = pud_offset(pgd, addr);
33560 + pmd = pmd_offset(pud, addr);
33561 + if (!pmd_present(*pmd))
33562 + continue;
33563 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33564 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33565 + else
33566 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33567 + }
33568 +
33569 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33570 + end = addr + KERNEL_IMAGE_SIZE;
33571 + for (; addr < end; addr += PMD_SIZE) {
33572 + pgd = pgd_offset_k(addr);
33573 + pud = pud_offset(pgd, addr);
33574 + pmd = pmd_offset(pud, addr);
33575 + if (!pmd_present(*pmd))
33576 + continue;
33577 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33578 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33579 + }
33580 +#endif
33581 +
33582 + flush_tlb_all();
33583 +#endif
33584 +
33585 free_init_pages("unused kernel",
33586 (unsigned long)(&__init_begin),
33587 (unsigned long)(&__init_end));
33588 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33589 index 7d05565..bfc5338 100644
33590 --- a/arch/x86/mm/init_32.c
33591 +++ b/arch/x86/mm/init_32.c
33592 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33593 bool __read_mostly __vmalloc_start_set = false;
33594
33595 /*
33596 - * Creates a middle page table and puts a pointer to it in the
33597 - * given global directory entry. This only returns the gd entry
33598 - * in non-PAE compilation mode, since the middle layer is folded.
33599 - */
33600 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33601 -{
33602 - pud_t *pud;
33603 - pmd_t *pmd_table;
33604 -
33605 -#ifdef CONFIG_X86_PAE
33606 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33607 - pmd_table = (pmd_t *)alloc_low_page();
33608 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33609 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33610 - pud = pud_offset(pgd, 0);
33611 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33612 -
33613 - return pmd_table;
33614 - }
33615 -#endif
33616 - pud = pud_offset(pgd, 0);
33617 - pmd_table = pmd_offset(pud, 0);
33618 -
33619 - return pmd_table;
33620 -}
33621 -
33622 -/*
33623 * Create a page table and place a pointer to it in a middle page
33624 * directory entry:
33625 */
33626 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33627 pte_t *page_table = (pte_t *)alloc_low_page();
33628
33629 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33630 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33631 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33632 +#else
33633 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33634 +#endif
33635 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33636 }
33637
33638 return pte_offset_kernel(pmd, 0);
33639 }
33640
33641 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33642 +{
33643 + pud_t *pud;
33644 + pmd_t *pmd_table;
33645 +
33646 + pud = pud_offset(pgd, 0);
33647 + pmd_table = pmd_offset(pud, 0);
33648 +
33649 + return pmd_table;
33650 +}
33651 +
33652 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33653 {
33654 int pgd_idx = pgd_index(vaddr);
33655 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33656 int pgd_idx, pmd_idx;
33657 unsigned long vaddr;
33658 pgd_t *pgd;
33659 + pud_t *pud;
33660 pmd_t *pmd;
33661 pte_t *pte = NULL;
33662 unsigned long count = page_table_range_init_count(start, end);
33663 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33664 pgd = pgd_base + pgd_idx;
33665
33666 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33667 - pmd = one_md_table_init(pgd);
33668 - pmd = pmd + pmd_index(vaddr);
33669 + pud = pud_offset(pgd, vaddr);
33670 + pmd = pmd_offset(pud, vaddr);
33671 +
33672 +#ifdef CONFIG_X86_PAE
33673 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33674 +#endif
33675 +
33676 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33677 pmd++, pmd_idx++) {
33678 pte = page_table_kmap_check(one_page_table_init(pmd),
33679 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33680 }
33681 }
33682
33683 -static inline int is_kernel_text(unsigned long addr)
33684 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33685 {
33686 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33687 - return 1;
33688 - return 0;
33689 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33690 + end <= ktla_ktva((unsigned long)_stext)) &&
33691 + (start >= ktla_ktva((unsigned long)_einittext) ||
33692 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33693 +
33694 +#ifdef CONFIG_ACPI_SLEEP
33695 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33696 +#endif
33697 +
33698 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33699 + return 0;
33700 + return 1;
33701 }
33702
33703 /*
33704 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33705 unsigned long last_map_addr = end;
33706 unsigned long start_pfn, end_pfn;
33707 pgd_t *pgd_base = swapper_pg_dir;
33708 - int pgd_idx, pmd_idx, pte_ofs;
33709 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33710 unsigned long pfn;
33711 pgd_t *pgd;
33712 + pud_t *pud;
33713 pmd_t *pmd;
33714 pte_t *pte;
33715 unsigned pages_2m, pages_4k;
33716 @@ -291,8 +295,13 @@ repeat:
33717 pfn = start_pfn;
33718 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33719 pgd = pgd_base + pgd_idx;
33720 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33721 - pmd = one_md_table_init(pgd);
33722 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33723 + pud = pud_offset(pgd, 0);
33724 + pmd = pmd_offset(pud, 0);
33725 +
33726 +#ifdef CONFIG_X86_PAE
33727 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33728 +#endif
33729
33730 if (pfn >= end_pfn)
33731 continue;
33732 @@ -304,14 +313,13 @@ repeat:
33733 #endif
33734 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33735 pmd++, pmd_idx++) {
33736 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33737 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33738
33739 /*
33740 * Map with big pages if possible, otherwise
33741 * create normal page tables:
33742 */
33743 if (use_pse) {
33744 - unsigned int addr2;
33745 pgprot_t prot = PAGE_KERNEL_LARGE;
33746 /*
33747 * first pass will use the same initial
33748 @@ -322,11 +330,7 @@ repeat:
33749 _PAGE_PSE);
33750
33751 pfn &= PMD_MASK >> PAGE_SHIFT;
33752 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33753 - PAGE_OFFSET + PAGE_SIZE-1;
33754 -
33755 - if (is_kernel_text(addr) ||
33756 - is_kernel_text(addr2))
33757 + if (is_kernel_text(address, address + PMD_SIZE))
33758 prot = PAGE_KERNEL_LARGE_EXEC;
33759
33760 pages_2m++;
33761 @@ -343,7 +347,7 @@ repeat:
33762 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33763 pte += pte_ofs;
33764 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33765 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33766 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33767 pgprot_t prot = PAGE_KERNEL;
33768 /*
33769 * first pass will use the same initial
33770 @@ -351,7 +355,7 @@ repeat:
33771 */
33772 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33773
33774 - if (is_kernel_text(addr))
33775 + if (is_kernel_text(address, address + PAGE_SIZE))
33776 prot = PAGE_KERNEL_EXEC;
33777
33778 pages_4k++;
33779 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33780
33781 pud = pud_offset(pgd, va);
33782 pmd = pmd_offset(pud, va);
33783 - if (!pmd_present(*pmd))
33784 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33785 break;
33786
33787 /* should not be large page here */
33788 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33789
33790 static void __init pagetable_init(void)
33791 {
33792 - pgd_t *pgd_base = swapper_pg_dir;
33793 -
33794 - permanent_kmaps_init(pgd_base);
33795 + permanent_kmaps_init(swapper_pg_dir);
33796 }
33797
33798 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33799 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33800 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33801
33802 /* user-defined highmem size */
33803 @@ -787,10 +789,10 @@ void __init mem_init(void)
33804 ((unsigned long)&__init_end -
33805 (unsigned long)&__init_begin) >> 10,
33806
33807 - (unsigned long)&_etext, (unsigned long)&_edata,
33808 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33809 + (unsigned long)&_sdata, (unsigned long)&_edata,
33810 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33811
33812 - (unsigned long)&_text, (unsigned long)&_etext,
33813 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33814 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33815
33816 /*
33817 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33818 if (!kernel_set_to_readonly)
33819 return;
33820
33821 + start = ktla_ktva(start);
33822 pr_debug("Set kernel text: %lx - %lx for read write\n",
33823 start, start+size);
33824
33825 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33826 if (!kernel_set_to_readonly)
33827 return;
33828
33829 + start = ktla_ktva(start);
33830 pr_debug("Set kernel text: %lx - %lx for read only\n",
33831 start, start+size);
33832
33833 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33834 unsigned long start = PFN_ALIGN(_text);
33835 unsigned long size = PFN_ALIGN(_etext) - start;
33836
33837 + start = ktla_ktva(start);
33838 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33839 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33840 size >> 10);
33841 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33842 index ac7de5f..ceb56df 100644
33843 --- a/arch/x86/mm/init_64.c
33844 +++ b/arch/x86/mm/init_64.c
33845 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33846 * around without checking the pgd every time.
33847 */
33848
33849 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33850 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33851 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33852
33853 int force_personality32;
33854 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33855
33856 for (address = start; address <= end; address += PGDIR_SIZE) {
33857 const pgd_t *pgd_ref = pgd_offset_k(address);
33858 +
33859 +#ifdef CONFIG_PAX_PER_CPU_PGD
33860 + unsigned long cpu;
33861 +#else
33862 struct page *page;
33863 +#endif
33864
33865 if (pgd_none(*pgd_ref))
33866 continue;
33867
33868 spin_lock(&pgd_lock);
33869 +
33870 +#ifdef CONFIG_PAX_PER_CPU_PGD
33871 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33872 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33873 +
33874 + if (pgd_none(*pgd))
33875 + set_pgd(pgd, *pgd_ref);
33876 + else
33877 + BUG_ON(pgd_page_vaddr(*pgd)
33878 + != pgd_page_vaddr(*pgd_ref));
33879 + pgd = pgd_offset_cpu(cpu, kernel, address);
33880 +#else
33881 list_for_each_entry(page, &pgd_list, lru) {
33882 pgd_t *pgd;
33883 spinlock_t *pgt_lock;
33884 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33885 /* the pgt_lock only for Xen */
33886 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33887 spin_lock(pgt_lock);
33888 +#endif
33889
33890 if (pgd_none(*pgd))
33891 set_pgd(pgd, *pgd_ref);
33892 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33893 BUG_ON(pgd_page_vaddr(*pgd)
33894 != pgd_page_vaddr(*pgd_ref));
33895
33896 +#ifndef CONFIG_PAX_PER_CPU_PGD
33897 spin_unlock(pgt_lock);
33898 +#endif
33899 +
33900 }
33901 spin_unlock(&pgd_lock);
33902 }
33903 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33904 {
33905 if (pgd_none(*pgd)) {
33906 pud_t *pud = (pud_t *)spp_getpage();
33907 - pgd_populate(&init_mm, pgd, pud);
33908 + pgd_populate_kernel(&init_mm, pgd, pud);
33909 if (pud != pud_offset(pgd, 0))
33910 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33911 pud, pud_offset(pgd, 0));
33912 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33913 {
33914 if (pud_none(*pud)) {
33915 pmd_t *pmd = (pmd_t *) spp_getpage();
33916 - pud_populate(&init_mm, pud, pmd);
33917 + pud_populate_kernel(&init_mm, pud, pmd);
33918 if (pmd != pmd_offset(pud, 0))
33919 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33920 pmd, pmd_offset(pud, 0));
33921 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33922 pmd = fill_pmd(pud, vaddr);
33923 pte = fill_pte(pmd, vaddr);
33924
33925 + pax_open_kernel();
33926 set_pte(pte, new_pte);
33927 + pax_close_kernel();
33928
33929 /*
33930 * It's enough to flush this one mapping.
33931 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33932 pgd = pgd_offset_k((unsigned long)__va(phys));
33933 if (pgd_none(*pgd)) {
33934 pud = (pud_t *) spp_getpage();
33935 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33936 - _PAGE_USER));
33937 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33938 }
33939 pud = pud_offset(pgd, (unsigned long)__va(phys));
33940 if (pud_none(*pud)) {
33941 pmd = (pmd_t *) spp_getpage();
33942 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33943 - _PAGE_USER));
33944 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33945 }
33946 pmd = pmd_offset(pud, phys);
33947 BUG_ON(!pmd_none(*pmd));
33948 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33949 prot);
33950
33951 spin_lock(&init_mm.page_table_lock);
33952 - pud_populate(&init_mm, pud, pmd);
33953 + pud_populate_kernel(&init_mm, pud, pmd);
33954 spin_unlock(&init_mm.page_table_lock);
33955 }
33956 __flush_tlb_all();
33957 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33958 page_size_mask);
33959
33960 spin_lock(&init_mm.page_table_lock);
33961 - pgd_populate(&init_mm, pgd, pud);
33962 + pgd_populate_kernel(&init_mm, pgd, pud);
33963 spin_unlock(&init_mm.page_table_lock);
33964 pgd_changed = true;
33965 }
33966 @@ -1205,8 +1226,8 @@ static struct vm_operations_struct gate_vma_ops = {
33967 static struct vm_area_struct gate_vma = {
33968 .vm_start = VSYSCALL_ADDR,
33969 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33970 - .vm_page_prot = PAGE_READONLY_EXEC,
33971 - .vm_flags = VM_READ | VM_EXEC,
33972 + .vm_page_prot = PAGE_READONLY,
33973 + .vm_flags = VM_READ,
33974 .vm_ops = &gate_vma_ops,
33975 };
33976
33977 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33978 index 7b179b49..6bd17777 100644
33979 --- a/arch/x86/mm/iomap_32.c
33980 +++ b/arch/x86/mm/iomap_32.c
33981 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33982 type = kmap_atomic_idx_push();
33983 idx = type + KM_TYPE_NR * smp_processor_id();
33984 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33985 +
33986 + pax_open_kernel();
33987 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33988 + pax_close_kernel();
33989 +
33990 arch_flush_lazy_mmu_mode();
33991
33992 return (void *)vaddr;
33993 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33994 index baff1da..2816ef4 100644
33995 --- a/arch/x86/mm/ioremap.c
33996 +++ b/arch/x86/mm/ioremap.c
33997 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33998 unsigned long i;
33999
34000 for (i = 0; i < nr_pages; ++i)
34001 - if (pfn_valid(start_pfn + i) &&
34002 - !PageReserved(pfn_to_page(start_pfn + i)))
34003 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
34004 + !PageReserved(pfn_to_page(start_pfn + i))))
34005 return 1;
34006
34007 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
34008 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
34009 *
34010 * Caller must ensure there is only one unmapping for the same pointer.
34011 */
34012 -void iounmap(volatile void __iomem *addr)
34013 +void iounmap(const volatile void __iomem *addr)
34014 {
34015 struct vm_struct *p, *o;
34016
34017 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34018
34019 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
34020 if (page_is_ram(start >> PAGE_SHIFT))
34021 +#ifdef CONFIG_HIGHMEM
34022 + if ((start >> PAGE_SHIFT) < max_low_pfn)
34023 +#endif
34024 return __va(phys);
34025
34026 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
34027 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34028 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
34029 {
34030 if (page_is_ram(phys >> PAGE_SHIFT))
34031 +#ifdef CONFIG_HIGHMEM
34032 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
34033 +#endif
34034 return;
34035
34036 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
34037 return;
34038 }
34039
34040 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
34041 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
34042
34043 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
34044 {
34045 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
34046 early_ioremap_setup();
34047
34048 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
34049 - memset(bm_pte, 0, sizeof(bm_pte));
34050 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
34051 + pmd_populate_user(&init_mm, pmd, bm_pte);
34052
34053 /*
34054 * The boot-ioremap range spans multiple pmds, for which
34055 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
34056 index dd89a13..d77bdcc 100644
34057 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
34058 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
34059 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
34060 * memory (e.g. tracked pages)? For now, we need this to avoid
34061 * invoking kmemcheck for PnP BIOS calls.
34062 */
34063 - if (regs->flags & X86_VM_MASK)
34064 + if (v8086_mode(regs))
34065 return false;
34066 - if (regs->cs != __KERNEL_CS)
34067 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
34068 return false;
34069
34070 pte = kmemcheck_pte_lookup(address);
34071 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
34072 index 919b912..9267313 100644
34073 --- a/arch/x86/mm/mmap.c
34074 +++ b/arch/x86/mm/mmap.c
34075 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
34076 * Leave an at least ~128 MB hole with possible stack randomization.
34077 */
34078 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
34079 -#define MAX_GAP (TASK_SIZE/6*5)
34080 +#define MAX_GAP (pax_task_size/6*5)
34081
34082 static int mmap_is_legacy(void)
34083 {
34084 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34085 return rnd << PAGE_SHIFT;
34086 }
34087
34088 -static unsigned long mmap_base(void)
34089 +static unsigned long mmap_base(struct mm_struct *mm)
34090 {
34091 unsigned long gap = rlimit(RLIMIT_STACK);
34092 + unsigned long pax_task_size = TASK_SIZE;
34093 +
34094 +#ifdef CONFIG_PAX_SEGMEXEC
34095 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34096 + pax_task_size = SEGMEXEC_TASK_SIZE;
34097 +#endif
34098
34099 if (gap < MIN_GAP)
34100 gap = MIN_GAP;
34101 else if (gap > MAX_GAP)
34102 gap = MAX_GAP;
34103
34104 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34105 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34106 }
34107
34108 /*
34109 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34110 * does, but not when emulating X86_32
34111 */
34112 -static unsigned long mmap_legacy_base(void)
34113 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
34114 {
34115 - if (mmap_is_ia32())
34116 + if (mmap_is_ia32()) {
34117 +
34118 +#ifdef CONFIG_PAX_SEGMEXEC
34119 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34120 + return SEGMEXEC_TASK_UNMAPPED_BASE;
34121 + else
34122 +#endif
34123 +
34124 return TASK_UNMAPPED_BASE;
34125 - else
34126 + } else
34127 return TASK_UNMAPPED_BASE + mmap_rnd();
34128 }
34129
34130 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34131 */
34132 void arch_pick_mmap_layout(struct mm_struct *mm)
34133 {
34134 - mm->mmap_legacy_base = mmap_legacy_base();
34135 - mm->mmap_base = mmap_base();
34136 + mm->mmap_legacy_base = mmap_legacy_base(mm);
34137 + mm->mmap_base = mmap_base(mm);
34138 +
34139 +#ifdef CONFIG_PAX_RANDMMAP
34140 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
34141 + mm->mmap_legacy_base += mm->delta_mmap;
34142 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34143 + }
34144 +#endif
34145
34146 if (mmap_is_legacy()) {
34147 mm->mmap_base = mm->mmap_legacy_base;
34148 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34149 index 0057a7a..95c7edd 100644
34150 --- a/arch/x86/mm/mmio-mod.c
34151 +++ b/arch/x86/mm/mmio-mod.c
34152 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34153 break;
34154 default:
34155 {
34156 - unsigned char *ip = (unsigned char *)instptr;
34157 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34158 my_trace->opcode = MMIO_UNKNOWN_OP;
34159 my_trace->width = 0;
34160 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34161 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34162 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34163 void __iomem *addr)
34164 {
34165 - static atomic_t next_id;
34166 + static atomic_unchecked_t next_id;
34167 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34168 /* These are page-unaligned. */
34169 struct mmiotrace_map map = {
34170 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34171 .private = trace
34172 },
34173 .phys = offset,
34174 - .id = atomic_inc_return(&next_id)
34175 + .id = atomic_inc_return_unchecked(&next_id)
34176 };
34177 map.map_id = trace->id;
34178
34179 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34180 ioremap_trace_core(offset, size, addr);
34181 }
34182
34183 -static void iounmap_trace_core(volatile void __iomem *addr)
34184 +static void iounmap_trace_core(const volatile void __iomem *addr)
34185 {
34186 struct mmiotrace_map map = {
34187 .phys = 0,
34188 @@ -328,7 +328,7 @@ not_enabled:
34189 }
34190 }
34191
34192 -void mmiotrace_iounmap(volatile void __iomem *addr)
34193 +void mmiotrace_iounmap(const volatile void __iomem *addr)
34194 {
34195 might_sleep();
34196 if (is_enabled()) /* recheck and proper locking in *_core() */
34197 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34198 index a32b706..efb308b 100644
34199 --- a/arch/x86/mm/numa.c
34200 +++ b/arch/x86/mm/numa.c
34201 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34202 return true;
34203 }
34204
34205 -static int __init numa_register_memblks(struct numa_meminfo *mi)
34206 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34207 {
34208 unsigned long uninitialized_var(pfn_align);
34209 int i, nid;
34210 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34211 index 36de293..b820ddc 100644
34212 --- a/arch/x86/mm/pageattr.c
34213 +++ b/arch/x86/mm/pageattr.c
34214 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34215 */
34216 #ifdef CONFIG_PCI_BIOS
34217 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34218 - pgprot_val(forbidden) |= _PAGE_NX;
34219 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34220 #endif
34221
34222 /*
34223 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34224 * Does not cover __inittext since that is gone later on. On
34225 * 64bit we do not enforce !NX on the low mapping
34226 */
34227 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
34228 - pgprot_val(forbidden) |= _PAGE_NX;
34229 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34230 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34231
34232 +#ifdef CONFIG_DEBUG_RODATA
34233 /*
34234 * The .rodata section needs to be read-only. Using the pfn
34235 * catches all aliases.
34236 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34237 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34238 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34239 pgprot_val(forbidden) |= _PAGE_RW;
34240 +#endif
34241
34242 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34243 /*
34244 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34245 }
34246 #endif
34247
34248 +#ifdef CONFIG_PAX_KERNEXEC
34249 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34250 + pgprot_val(forbidden) |= _PAGE_RW;
34251 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34252 + }
34253 +#endif
34254 +
34255 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34256
34257 return prot;
34258 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34259 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34260 {
34261 /* change init_mm */
34262 + pax_open_kernel();
34263 set_pte_atomic(kpte, pte);
34264 +
34265 #ifdef CONFIG_X86_32
34266 if (!SHARED_KERNEL_PMD) {
34267 +
34268 +#ifdef CONFIG_PAX_PER_CPU_PGD
34269 + unsigned long cpu;
34270 +#else
34271 struct page *page;
34272 +#endif
34273
34274 +#ifdef CONFIG_PAX_PER_CPU_PGD
34275 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34276 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34277 +#else
34278 list_for_each_entry(page, &pgd_list, lru) {
34279 - pgd_t *pgd;
34280 + pgd_t *pgd = (pgd_t *)page_address(page);
34281 +#endif
34282 +
34283 pud_t *pud;
34284 pmd_t *pmd;
34285
34286 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
34287 + pgd += pgd_index(address);
34288 pud = pud_offset(pgd, address);
34289 pmd = pmd_offset(pud, address);
34290 set_pte_atomic((pte_t *)pmd, pte);
34291 }
34292 }
34293 #endif
34294 + pax_close_kernel();
34295 }
34296
34297 static int
34298 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34299 index 6574388..87e9bef 100644
34300 --- a/arch/x86/mm/pat.c
34301 +++ b/arch/x86/mm/pat.c
34302 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34303
34304 if (!entry) {
34305 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34306 - current->comm, current->pid, start, end - 1);
34307 + current->comm, task_pid_nr(current), start, end - 1);
34308 return -EINVAL;
34309 }
34310
34311 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34312
34313 while (cursor < to) {
34314 if (!devmem_is_allowed(pfn)) {
34315 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34316 - current->comm, from, to - 1);
34317 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34318 + current->comm, from, to - 1, cursor);
34319 return 0;
34320 }
34321 cursor += PAGE_SIZE;
34322 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34323 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34324 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34325 "for [mem %#010Lx-%#010Lx]\n",
34326 - current->comm, current->pid,
34327 + current->comm, task_pid_nr(current),
34328 cattr_name(flags),
34329 base, (unsigned long long)(base + size-1));
34330 return -EINVAL;
34331 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34332 flags = lookup_memtype(paddr);
34333 if (want_flags != flags) {
34334 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34335 - current->comm, current->pid,
34336 + current->comm, task_pid_nr(current),
34337 cattr_name(want_flags),
34338 (unsigned long long)paddr,
34339 (unsigned long long)(paddr + size - 1),
34340 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34341 free_memtype(paddr, paddr + size);
34342 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34343 " for [mem %#010Lx-%#010Lx], got %s\n",
34344 - current->comm, current->pid,
34345 + current->comm, task_pid_nr(current),
34346 cattr_name(want_flags),
34347 (unsigned long long)paddr,
34348 (unsigned long long)(paddr + size - 1),
34349 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34350 index 415f6c4..d319983 100644
34351 --- a/arch/x86/mm/pat_rbtree.c
34352 +++ b/arch/x86/mm/pat_rbtree.c
34353 @@ -160,7 +160,7 @@ success:
34354
34355 failure:
34356 printk(KERN_INFO "%s:%d conflicting memory types "
34357 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34358 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34359 end, cattr_name(found_type), cattr_name(match->type));
34360 return -EBUSY;
34361 }
34362 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34363 index 9f0614d..92ae64a 100644
34364 --- a/arch/x86/mm/pf_in.c
34365 +++ b/arch/x86/mm/pf_in.c
34366 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34367 int i;
34368 enum reason_type rv = OTHERS;
34369
34370 - p = (unsigned char *)ins_addr;
34371 + p = (unsigned char *)ktla_ktva(ins_addr);
34372 p += skip_prefix(p, &prf);
34373 p += get_opcode(p, &opcode);
34374
34375 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34376 struct prefix_bits prf;
34377 int i;
34378
34379 - p = (unsigned char *)ins_addr;
34380 + p = (unsigned char *)ktla_ktva(ins_addr);
34381 p += skip_prefix(p, &prf);
34382 p += get_opcode(p, &opcode);
34383
34384 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34385 struct prefix_bits prf;
34386 int i;
34387
34388 - p = (unsigned char *)ins_addr;
34389 + p = (unsigned char *)ktla_ktva(ins_addr);
34390 p += skip_prefix(p, &prf);
34391 p += get_opcode(p, &opcode);
34392
34393 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34394 struct prefix_bits prf;
34395 int i;
34396
34397 - p = (unsigned char *)ins_addr;
34398 + p = (unsigned char *)ktla_ktva(ins_addr);
34399 p += skip_prefix(p, &prf);
34400 p += get_opcode(p, &opcode);
34401 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34402 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34403 struct prefix_bits prf;
34404 int i;
34405
34406 - p = (unsigned char *)ins_addr;
34407 + p = (unsigned char *)ktla_ktva(ins_addr);
34408 p += skip_prefix(p, &prf);
34409 p += get_opcode(p, &opcode);
34410 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34411 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34412 index 6fb6927..4fc13c0 100644
34413 --- a/arch/x86/mm/pgtable.c
34414 +++ b/arch/x86/mm/pgtable.c
34415 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34416 list_del(&page->lru);
34417 }
34418
34419 -#define UNSHARED_PTRS_PER_PGD \
34420 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34421 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34422 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34423
34424 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34425 +{
34426 + unsigned int count = USER_PGD_PTRS;
34427
34428 + if (!pax_user_shadow_base)
34429 + return;
34430 +
34431 + while (count--)
34432 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34433 +}
34434 +#endif
34435 +
34436 +#ifdef CONFIG_PAX_PER_CPU_PGD
34437 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34438 +{
34439 + unsigned int count = USER_PGD_PTRS;
34440 +
34441 + while (count--) {
34442 + pgd_t pgd;
34443 +
34444 +#ifdef CONFIG_X86_64
34445 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34446 +#else
34447 + pgd = *src++;
34448 +#endif
34449 +
34450 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34451 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34452 +#endif
34453 +
34454 + *dst++ = pgd;
34455 + }
34456 +
34457 +}
34458 +#endif
34459 +
34460 +#ifdef CONFIG_X86_64
34461 +#define pxd_t pud_t
34462 +#define pyd_t pgd_t
34463 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34464 +#define pgtable_pxd_page_ctor(page) true
34465 +#define pgtable_pxd_page_dtor(page)
34466 +#define pxd_free(mm, pud) pud_free((mm), (pud))
34467 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34468 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
34469 +#define PYD_SIZE PGDIR_SIZE
34470 +#else
34471 +#define pxd_t pmd_t
34472 +#define pyd_t pud_t
34473 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34474 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34475 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34476 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
34477 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34478 +#define pyd_offset(mm, address) pud_offset((mm), (address))
34479 +#define PYD_SIZE PUD_SIZE
34480 +#endif
34481 +
34482 +#ifdef CONFIG_PAX_PER_CPU_PGD
34483 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34484 +static inline void pgd_dtor(pgd_t *pgd) {}
34485 +#else
34486 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34487 {
34488 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34489 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34490 pgd_list_del(pgd);
34491 spin_unlock(&pgd_lock);
34492 }
34493 +#endif
34494
34495 /*
34496 * List of all pgd's needed for non-PAE so it can invalidate entries
34497 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34498 * -- nyc
34499 */
34500
34501 -#ifdef CONFIG_X86_PAE
34502 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34503 /*
34504 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34505 * updating the top-level pagetable entries to guarantee the
34506 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34507 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34508 * and initialize the kernel pmds here.
34509 */
34510 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34511 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34512
34513 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34514 {
34515 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34516 */
34517 flush_tlb_mm(mm);
34518 }
34519 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34520 +#define PREALLOCATED_PXDS USER_PGD_PTRS
34521 #else /* !CONFIG_X86_PAE */
34522
34523 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34524 -#define PREALLOCATED_PMDS 0
34525 +#define PREALLOCATED_PXDS 0
34526
34527 #endif /* CONFIG_X86_PAE */
34528
34529 -static void free_pmds(pmd_t *pmds[])
34530 +static void free_pxds(pxd_t *pxds[])
34531 {
34532 int i;
34533
34534 - for(i = 0; i < PREALLOCATED_PMDS; i++)
34535 - if (pmds[i]) {
34536 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34537 - free_page((unsigned long)pmds[i]);
34538 + for(i = 0; i < PREALLOCATED_PXDS; i++)
34539 + if (pxds[i]) {
34540 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34541 + free_page((unsigned long)pxds[i]);
34542 }
34543 }
34544
34545 -static int preallocate_pmds(pmd_t *pmds[])
34546 +static int preallocate_pxds(pxd_t *pxds[])
34547 {
34548 int i;
34549 bool failed = false;
34550
34551 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34552 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34553 - if (!pmd)
34554 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34555 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34556 + if (!pxd)
34557 failed = true;
34558 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34559 - free_page((unsigned long)pmd);
34560 - pmd = NULL;
34561 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34562 + free_page((unsigned long)pxd);
34563 + pxd = NULL;
34564 failed = true;
34565 }
34566 - pmds[i] = pmd;
34567 + pxds[i] = pxd;
34568 }
34569
34570 if (failed) {
34571 - free_pmds(pmds);
34572 + free_pxds(pxds);
34573 return -ENOMEM;
34574 }
34575
34576 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34577 * preallocate which never got a corresponding vma will need to be
34578 * freed manually.
34579 */
34580 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34581 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34582 {
34583 int i;
34584
34585 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34586 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34587 pgd_t pgd = pgdp[i];
34588
34589 if (pgd_val(pgd) != 0) {
34590 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34591 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34592
34593 - pgdp[i] = native_make_pgd(0);
34594 + set_pgd(pgdp + i, native_make_pgd(0));
34595
34596 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34597 - pmd_free(mm, pmd);
34598 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34599 + pxd_free(mm, pxd);
34600 }
34601 }
34602 }
34603
34604 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34605 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34606 {
34607 - pud_t *pud;
34608 + pyd_t *pyd;
34609 int i;
34610
34611 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34612 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34613 return;
34614
34615 - pud = pud_offset(pgd, 0);
34616 -
34617 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34618 - pmd_t *pmd = pmds[i];
34619 +#ifdef CONFIG_X86_64
34620 + pyd = pyd_offset(mm, 0L);
34621 +#else
34622 + pyd = pyd_offset(pgd, 0L);
34623 +#endif
34624
34625 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34626 + pxd_t *pxd = pxds[i];
34627 if (i >= KERNEL_PGD_BOUNDARY)
34628 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34629 - sizeof(pmd_t) * PTRS_PER_PMD);
34630 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34631 + sizeof(pxd_t) * PTRS_PER_PMD);
34632
34633 - pud_populate(mm, pud, pmd);
34634 + pyd_populate(mm, pyd, pxd);
34635 }
34636 }
34637
34638 pgd_t *pgd_alloc(struct mm_struct *mm)
34639 {
34640 pgd_t *pgd;
34641 - pmd_t *pmds[PREALLOCATED_PMDS];
34642 + pxd_t *pxds[PREALLOCATED_PXDS];
34643
34644 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34645
34646 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34647
34648 mm->pgd = pgd;
34649
34650 - if (preallocate_pmds(pmds) != 0)
34651 + if (preallocate_pxds(pxds) != 0)
34652 goto out_free_pgd;
34653
34654 if (paravirt_pgd_alloc(mm) != 0)
34655 - goto out_free_pmds;
34656 + goto out_free_pxds;
34657
34658 /*
34659 * Make sure that pre-populating the pmds is atomic with
34660 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34661 spin_lock(&pgd_lock);
34662
34663 pgd_ctor(mm, pgd);
34664 - pgd_prepopulate_pmd(mm, pgd, pmds);
34665 + pgd_prepopulate_pxd(mm, pgd, pxds);
34666
34667 spin_unlock(&pgd_lock);
34668
34669 return pgd;
34670
34671 -out_free_pmds:
34672 - free_pmds(pmds);
34673 +out_free_pxds:
34674 + free_pxds(pxds);
34675 out_free_pgd:
34676 free_page((unsigned long)pgd);
34677 out:
34678 @@ -313,7 +380,7 @@ out:
34679
34680 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34681 {
34682 - pgd_mop_up_pmds(mm, pgd);
34683 + pgd_mop_up_pxds(mm, pgd);
34684 pgd_dtor(pgd);
34685 paravirt_pgd_free(mm, pgd);
34686 free_page((unsigned long)pgd);
34687 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34688 index 4dd8cf6..f9d143e 100644
34689 --- a/arch/x86/mm/pgtable_32.c
34690 +++ b/arch/x86/mm/pgtable_32.c
34691 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34692 return;
34693 }
34694 pte = pte_offset_kernel(pmd, vaddr);
34695 +
34696 + pax_open_kernel();
34697 if (pte_val(pteval))
34698 set_pte_at(&init_mm, vaddr, pte, pteval);
34699 else
34700 pte_clear(&init_mm, vaddr, pte);
34701 + pax_close_kernel();
34702
34703 /*
34704 * It's enough to flush this one mapping.
34705 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34706 index e666cbb..61788c45 100644
34707 --- a/arch/x86/mm/physaddr.c
34708 +++ b/arch/x86/mm/physaddr.c
34709 @@ -10,7 +10,7 @@
34710 #ifdef CONFIG_X86_64
34711
34712 #ifdef CONFIG_DEBUG_VIRTUAL
34713 -unsigned long __phys_addr(unsigned long x)
34714 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34715 {
34716 unsigned long y = x - __START_KERNEL_map;
34717
34718 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34719 #else
34720
34721 #ifdef CONFIG_DEBUG_VIRTUAL
34722 -unsigned long __phys_addr(unsigned long x)
34723 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34724 {
34725 unsigned long phys_addr = x - PAGE_OFFSET;
34726 /* VMALLOC_* aren't constants */
34727 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34728 index 90555bf..f5f1828 100644
34729 --- a/arch/x86/mm/setup_nx.c
34730 +++ b/arch/x86/mm/setup_nx.c
34731 @@ -5,8 +5,10 @@
34732 #include <asm/pgtable.h>
34733 #include <asm/proto.h>
34734
34735 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34736 static int disable_nx;
34737
34738 +#ifndef CONFIG_PAX_PAGEEXEC
34739 /*
34740 * noexec = on|off
34741 *
34742 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34743 return 0;
34744 }
34745 early_param("noexec", noexec_setup);
34746 +#endif
34747 +
34748 +#endif
34749
34750 void x86_configure_nx(void)
34751 {
34752 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34753 if (cpu_has_nx && !disable_nx)
34754 __supported_pte_mask |= _PAGE_NX;
34755 else
34756 +#endif
34757 __supported_pte_mask &= ~_PAGE_NX;
34758 }
34759
34760 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34761 index ee61c36..e6fedeb 100644
34762 --- a/arch/x86/mm/tlb.c
34763 +++ b/arch/x86/mm/tlb.c
34764 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34765 BUG();
34766 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34767 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34768 +
34769 +#ifndef CONFIG_PAX_PER_CPU_PGD
34770 load_cr3(swapper_pg_dir);
34771 +#endif
34772 +
34773 /*
34774 * This gets called in the idle path where RCU
34775 * functions differently. Tracing normally
34776 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34777 new file mode 100644
34778 index 0000000..dace51c
34779 --- /dev/null
34780 +++ b/arch/x86/mm/uderef_64.c
34781 @@ -0,0 +1,37 @@
34782 +#include <linux/mm.h>
34783 +#include <asm/pgtable.h>
34784 +#include <asm/uaccess.h>
34785 +
34786 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34787 +/* PaX: due to the special call convention these functions must
34788 + * - remain leaf functions under all configurations,
34789 + * - never be called directly, only dereferenced from the wrappers.
34790 + */
34791 +void __pax_open_userland(void)
34792 +{
34793 + unsigned int cpu;
34794 +
34795 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34796 + return;
34797 +
34798 + cpu = raw_get_cpu();
34799 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34800 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34801 + raw_put_cpu_no_resched();
34802 +}
34803 +EXPORT_SYMBOL(__pax_open_userland);
34804 +
34805 +void __pax_close_userland(void)
34806 +{
34807 + unsigned int cpu;
34808 +
34809 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34810 + return;
34811 +
34812 + cpu = raw_get_cpu();
34813 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34814 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34815 + raw_put_cpu_no_resched();
34816 +}
34817 +EXPORT_SYMBOL(__pax_close_userland);
34818 +#endif
34819 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34820 index 6440221..f84b5c7 100644
34821 --- a/arch/x86/net/bpf_jit.S
34822 +++ b/arch/x86/net/bpf_jit.S
34823 @@ -9,6 +9,7 @@
34824 */
34825 #include <linux/linkage.h>
34826 #include <asm/dwarf2.h>
34827 +#include <asm/alternative-asm.h>
34828
34829 /*
34830 * Calling convention :
34831 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34832 jle bpf_slow_path_word
34833 mov (SKBDATA,%rsi),%eax
34834 bswap %eax /* ntohl() */
34835 + pax_force_retaddr
34836 ret
34837
34838 sk_load_half:
34839 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34840 jle bpf_slow_path_half
34841 movzwl (SKBDATA,%rsi),%eax
34842 rol $8,%ax # ntohs()
34843 + pax_force_retaddr
34844 ret
34845
34846 sk_load_byte:
34847 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34848 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34849 jle bpf_slow_path_byte
34850 movzbl (SKBDATA,%rsi),%eax
34851 + pax_force_retaddr
34852 ret
34853
34854 /* rsi contains offset and can be scratched */
34855 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34856 js bpf_error
34857 mov - MAX_BPF_STACK + 32(%rbp),%eax
34858 bswap %eax
34859 + pax_force_retaddr
34860 ret
34861
34862 bpf_slow_path_half:
34863 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34864 mov - MAX_BPF_STACK + 32(%rbp),%ax
34865 rol $8,%ax
34866 movzwl %ax,%eax
34867 + pax_force_retaddr
34868 ret
34869
34870 bpf_slow_path_byte:
34871 bpf_slow_path_common(1)
34872 js bpf_error
34873 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34874 + pax_force_retaddr
34875 ret
34876
34877 #define sk_negative_common(SIZE) \
34878 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34879 sk_negative_common(4)
34880 mov (%rax), %eax
34881 bswap %eax
34882 + pax_force_retaddr
34883 ret
34884
34885 bpf_slow_path_half_neg:
34886 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34887 mov (%rax),%ax
34888 rol $8,%ax
34889 movzwl %ax,%eax
34890 + pax_force_retaddr
34891 ret
34892
34893 bpf_slow_path_byte_neg:
34894 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34895 .globl sk_load_byte_negative_offset
34896 sk_negative_common(1)
34897 movzbl (%rax), %eax
34898 + pax_force_retaddr
34899 ret
34900
34901 bpf_error:
34902 @@ -156,4 +166,5 @@ bpf_error:
34903 mov - MAX_BPF_STACK + 16(%rbp),%r14
34904 mov - MAX_BPF_STACK + 24(%rbp),%r15
34905 leaveq
34906 + pax_force_retaddr
34907 ret
34908 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34909 index c881ba8..71aca2e 100644
34910 --- a/arch/x86/net/bpf_jit_comp.c
34911 +++ b/arch/x86/net/bpf_jit_comp.c
34912 @@ -15,7 +15,11 @@
34913 #include <linux/if_vlan.h>
34914 #include <linux/random.h>
34915
34916 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34917 +int bpf_jit_enable __read_only;
34918 +#else
34919 int bpf_jit_enable __read_mostly;
34920 +#endif
34921
34922 /*
34923 * assembly code in arch/x86/net/bpf_jit.S
34924 @@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
34925 #define CHOOSE_LOAD_FUNC(K, func) \
34926 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34927
34928 -struct bpf_binary_header {
34929 - unsigned int pages;
34930 - /* Note : for security reasons, bpf code will follow a randomly
34931 - * sized amount of int3 instructions
34932 - */
34933 - u8 image[];
34934 -};
34935 -
34936 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34937 +/* Note : for security reasons, bpf code will follow a randomly
34938 + * sized amount of int3 instructions
34939 + */
34940 +static u8 *bpf_alloc_binary(unsigned int proglen,
34941 u8 **image_ptr)
34942 {
34943 unsigned int sz, hole;
34944 - struct bpf_binary_header *header;
34945 + u8 *header;
34946
34947 /* Most of BPF filters are really small,
34948 * but if some of them fill a page, allow at least
34949 * 128 extra bytes to insert a random section of int3
34950 */
34951 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34952 - header = module_alloc(sz);
34953 + sz = round_up(proglen + 128, PAGE_SIZE);
34954 + header = module_alloc_exec(sz);
34955 if (!header)
34956 return NULL;
34957
34958 + pax_open_kernel();
34959 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34960 + pax_close_kernel();
34961
34962 - header->pages = sz / PAGE_SIZE;
34963 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34964 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34965
34966 /* insert a random number of int3 instructions before BPF code */
34967 - *image_ptr = &header->image[prandom_u32() % hole];
34968 + *image_ptr = &header[prandom_u32() % hole];
34969 return header;
34970 }
34971
34972 @@ -864,7 +864,9 @@ common_load:
34973 pr_err("bpf_jit_compile fatal error\n");
34974 return -EFAULT;
34975 }
34976 + pax_open_kernel();
34977 memcpy(image + proglen, temp, ilen);
34978 + pax_close_kernel();
34979 }
34980 proglen += ilen;
34981 addrs[i] = proglen;
34982 @@ -879,7 +881,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
34983
34984 void bpf_int_jit_compile(struct bpf_prog *prog)
34985 {
34986 - struct bpf_binary_header *header = NULL;
34987 + u8 *header = NULL;
34988 int proglen, oldproglen = 0;
34989 struct jit_context ctx = {};
34990 u8 *image = NULL;
34991 @@ -911,7 +913,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34992 if (proglen <= 0) {
34993 image = NULL;
34994 if (header)
34995 - module_free(NULL, header);
34996 + module_free_exec(NULL, image);
34997 goto out;
34998 }
34999 if (image) {
35000 @@ -935,7 +937,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
35001
35002 if (image) {
35003 bpf_flush_icache(header, image + proglen);
35004 - set_memory_ro((unsigned long)header, header->pages);
35005 prog->bpf_func = (void *)image;
35006 prog->jited = 1;
35007 }
35008 @@ -943,23 +944,15 @@ out:
35009 kfree(addrs);
35010 }
35011
35012 -static void bpf_jit_free_deferred(struct work_struct *work)
35013 -{
35014 - struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
35015 - unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35016 - struct bpf_binary_header *header = (void *)addr;
35017 -
35018 - set_memory_rw(addr, header->pages);
35019 - module_free(NULL, header);
35020 - kfree(fp);
35021 -}
35022 -
35023 void bpf_jit_free(struct bpf_prog *fp)
35024 {
35025 - if (fp->jited) {
35026 - INIT_WORK(&fp->work, bpf_jit_free_deferred);
35027 - schedule_work(&fp->work);
35028 - } else {
35029 - kfree(fp);
35030 - }
35031 + unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35032 +
35033 + if (!fp->jited)
35034 + goto free_filter;
35035 +
35036 + module_free_exec(NULL, (void *)addr);
35037 +
35038 +free_filter:
35039 + bpf_prog_unlock_free(fp);
35040 }
35041 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
35042 index 5d04be5..2beeaa2 100644
35043 --- a/arch/x86/oprofile/backtrace.c
35044 +++ b/arch/x86/oprofile/backtrace.c
35045 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
35046 struct stack_frame_ia32 *fp;
35047 unsigned long bytes;
35048
35049 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35050 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35051 if (bytes != 0)
35052 return NULL;
35053
35054 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
35055 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
35056
35057 oprofile_add_trace(bufhead[0].return_address);
35058
35059 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
35060 struct stack_frame bufhead[2];
35061 unsigned long bytes;
35062
35063 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35064 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35065 if (bytes != 0)
35066 return NULL;
35067
35068 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
35069 {
35070 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
35071
35072 - if (!user_mode_vm(regs)) {
35073 + if (!user_mode(regs)) {
35074 unsigned long stack = kernel_stack_pointer(regs);
35075 if (depth)
35076 dump_trace(NULL, regs, (unsigned long *)stack, 0,
35077 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
35078 index 379e8bd..6386e09 100644
35079 --- a/arch/x86/oprofile/nmi_int.c
35080 +++ b/arch/x86/oprofile/nmi_int.c
35081 @@ -23,6 +23,7 @@
35082 #include <asm/nmi.h>
35083 #include <asm/msr.h>
35084 #include <asm/apic.h>
35085 +#include <asm/pgtable.h>
35086
35087 #include "op_counter.h"
35088 #include "op_x86_model.h"
35089 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35090 if (ret)
35091 return ret;
35092
35093 - if (!model->num_virt_counters)
35094 - model->num_virt_counters = model->num_counters;
35095 + if (!model->num_virt_counters) {
35096 + pax_open_kernel();
35097 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
35098 + pax_close_kernel();
35099 + }
35100
35101 mux_init(ops);
35102
35103 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35104 index 50d86c0..7985318 100644
35105 --- a/arch/x86/oprofile/op_model_amd.c
35106 +++ b/arch/x86/oprofile/op_model_amd.c
35107 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35108 num_counters = AMD64_NUM_COUNTERS;
35109 }
35110
35111 - op_amd_spec.num_counters = num_counters;
35112 - op_amd_spec.num_controls = num_counters;
35113 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35114 + pax_open_kernel();
35115 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35116 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35117 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35118 + pax_close_kernel();
35119
35120 return 0;
35121 }
35122 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35123 index d90528e..0127e2b 100644
35124 --- a/arch/x86/oprofile/op_model_ppro.c
35125 +++ b/arch/x86/oprofile/op_model_ppro.c
35126 @@ -19,6 +19,7 @@
35127 #include <asm/msr.h>
35128 #include <asm/apic.h>
35129 #include <asm/nmi.h>
35130 +#include <asm/pgtable.h>
35131
35132 #include "op_x86_model.h"
35133 #include "op_counter.h"
35134 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35135
35136 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35137
35138 - op_arch_perfmon_spec.num_counters = num_counters;
35139 - op_arch_perfmon_spec.num_controls = num_counters;
35140 + pax_open_kernel();
35141 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35142 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35143 + pax_close_kernel();
35144 }
35145
35146 static int arch_perfmon_init(struct oprofile_operations *ignore)
35147 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35148 index 71e8a67..6a313bb 100644
35149 --- a/arch/x86/oprofile/op_x86_model.h
35150 +++ b/arch/x86/oprofile/op_x86_model.h
35151 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
35152 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35153 struct op_msrs const * const msrs);
35154 #endif
35155 -};
35156 +} __do_const;
35157
35158 struct op_counter_config;
35159
35160 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35161 index b9958c3..24229ab 100644
35162 --- a/arch/x86/pci/intel_mid_pci.c
35163 +++ b/arch/x86/pci/intel_mid_pci.c
35164 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35165 pci_mmcfg_late_init();
35166 pcibios_enable_irq = intel_mid_pci_irq_enable;
35167 pcibios_disable_irq = intel_mid_pci_irq_disable;
35168 - pci_root_ops = intel_mid_pci_ops;
35169 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35170 pci_soc_mode = 1;
35171 /* Continue with standard init */
35172 return 1;
35173 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35174 index eb500c2..eab9e70 100644
35175 --- a/arch/x86/pci/irq.c
35176 +++ b/arch/x86/pci/irq.c
35177 @@ -51,7 +51,7 @@ struct irq_router {
35178 struct irq_router_handler {
35179 u16 vendor;
35180 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35181 -};
35182 +} __do_const;
35183
35184 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35185 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35186 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35187 return 0;
35188 }
35189
35190 -static __initdata struct irq_router_handler pirq_routers[] = {
35191 +static __initconst const struct irq_router_handler pirq_routers[] = {
35192 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35193 { PCI_VENDOR_ID_AL, ali_router_probe },
35194 { PCI_VENDOR_ID_ITE, ite_router_probe },
35195 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35196 static void __init pirq_find_router(struct irq_router *r)
35197 {
35198 struct irq_routing_table *rt = pirq_table;
35199 - struct irq_router_handler *h;
35200 + const struct irq_router_handler *h;
35201
35202 #ifdef CONFIG_PCI_BIOS
35203 if (!rt->signature) {
35204 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35205 return 0;
35206 }
35207
35208 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35209 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35210 {
35211 .callback = fix_broken_hp_bios_irq9,
35212 .ident = "HP Pavilion N5400 Series Laptop",
35213 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35214 index c77b24a..c979855 100644
35215 --- a/arch/x86/pci/pcbios.c
35216 +++ b/arch/x86/pci/pcbios.c
35217 @@ -79,7 +79,7 @@ union bios32 {
35218 static struct {
35219 unsigned long address;
35220 unsigned short segment;
35221 -} bios32_indirect = { 0, __KERNEL_CS };
35222 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35223
35224 /*
35225 * Returns the entry point for the given service, NULL on error
35226 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35227 unsigned long length; /* %ecx */
35228 unsigned long entry; /* %edx */
35229 unsigned long flags;
35230 + struct desc_struct d, *gdt;
35231
35232 local_irq_save(flags);
35233 - __asm__("lcall *(%%edi); cld"
35234 +
35235 + gdt = get_cpu_gdt_table(smp_processor_id());
35236 +
35237 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35238 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35239 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35240 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35241 +
35242 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35243 : "=a" (return_code),
35244 "=b" (address),
35245 "=c" (length),
35246 "=d" (entry)
35247 : "0" (service),
35248 "1" (0),
35249 - "D" (&bios32_indirect));
35250 + "D" (&bios32_indirect),
35251 + "r"(__PCIBIOS_DS)
35252 + : "memory");
35253 +
35254 + pax_open_kernel();
35255 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35256 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35257 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35258 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35259 + pax_close_kernel();
35260 +
35261 local_irq_restore(flags);
35262
35263 switch (return_code) {
35264 - case 0:
35265 - return address + entry;
35266 - case 0x80: /* Not present */
35267 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35268 - return 0;
35269 - default: /* Shouldn't happen */
35270 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35271 - service, return_code);
35272 + case 0: {
35273 + int cpu;
35274 + unsigned char flags;
35275 +
35276 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35277 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35278 + printk(KERN_WARNING "bios32_service: not valid\n");
35279 return 0;
35280 + }
35281 + address = address + PAGE_OFFSET;
35282 + length += 16UL; /* some BIOSs underreport this... */
35283 + flags = 4;
35284 + if (length >= 64*1024*1024) {
35285 + length >>= PAGE_SHIFT;
35286 + flags |= 8;
35287 + }
35288 +
35289 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35290 + gdt = get_cpu_gdt_table(cpu);
35291 + pack_descriptor(&d, address, length, 0x9b, flags);
35292 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35293 + pack_descriptor(&d, address, length, 0x93, flags);
35294 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35295 + }
35296 + return entry;
35297 + }
35298 + case 0x80: /* Not present */
35299 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35300 + return 0;
35301 + default: /* Shouldn't happen */
35302 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35303 + service, return_code);
35304 + return 0;
35305 }
35306 }
35307
35308 static struct {
35309 unsigned long address;
35310 unsigned short segment;
35311 -} pci_indirect = { 0, __KERNEL_CS };
35312 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35313
35314 -static int pci_bios_present;
35315 +static int pci_bios_present __read_only;
35316
35317 static int check_pcibios(void)
35318 {
35319 @@ -131,11 +174,13 @@ static int check_pcibios(void)
35320 unsigned long flags, pcibios_entry;
35321
35322 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35323 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35324 + pci_indirect.address = pcibios_entry;
35325
35326 local_irq_save(flags);
35327 - __asm__(
35328 - "lcall *(%%edi); cld\n\t"
35329 + __asm__("movw %w6, %%ds\n\t"
35330 + "lcall *%%ss:(%%edi); cld\n\t"
35331 + "push %%ss\n\t"
35332 + "pop %%ds\n\t"
35333 "jc 1f\n\t"
35334 "xor %%ah, %%ah\n"
35335 "1:"
35336 @@ -144,7 +189,8 @@ static int check_pcibios(void)
35337 "=b" (ebx),
35338 "=c" (ecx)
35339 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35340 - "D" (&pci_indirect)
35341 + "D" (&pci_indirect),
35342 + "r" (__PCIBIOS_DS)
35343 : "memory");
35344 local_irq_restore(flags);
35345
35346 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35347
35348 switch (len) {
35349 case 1:
35350 - __asm__("lcall *(%%esi); cld\n\t"
35351 + __asm__("movw %w6, %%ds\n\t"
35352 + "lcall *%%ss:(%%esi); cld\n\t"
35353 + "push %%ss\n\t"
35354 + "pop %%ds\n\t"
35355 "jc 1f\n\t"
35356 "xor %%ah, %%ah\n"
35357 "1:"
35358 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35359 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35360 "b" (bx),
35361 "D" ((long)reg),
35362 - "S" (&pci_indirect));
35363 + "S" (&pci_indirect),
35364 + "r" (__PCIBIOS_DS));
35365 /*
35366 * Zero-extend the result beyond 8 bits, do not trust the
35367 * BIOS having done it:
35368 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35369 *value &= 0xff;
35370 break;
35371 case 2:
35372 - __asm__("lcall *(%%esi); cld\n\t"
35373 + __asm__("movw %w6, %%ds\n\t"
35374 + "lcall *%%ss:(%%esi); cld\n\t"
35375 + "push %%ss\n\t"
35376 + "pop %%ds\n\t"
35377 "jc 1f\n\t"
35378 "xor %%ah, %%ah\n"
35379 "1:"
35380 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35381 : "1" (PCIBIOS_READ_CONFIG_WORD),
35382 "b" (bx),
35383 "D" ((long)reg),
35384 - "S" (&pci_indirect));
35385 + "S" (&pci_indirect),
35386 + "r" (__PCIBIOS_DS));
35387 /*
35388 * Zero-extend the result beyond 16 bits, do not trust the
35389 * BIOS having done it:
35390 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35391 *value &= 0xffff;
35392 break;
35393 case 4:
35394 - __asm__("lcall *(%%esi); cld\n\t"
35395 + __asm__("movw %w6, %%ds\n\t"
35396 + "lcall *%%ss:(%%esi); cld\n\t"
35397 + "push %%ss\n\t"
35398 + "pop %%ds\n\t"
35399 "jc 1f\n\t"
35400 "xor %%ah, %%ah\n"
35401 "1:"
35402 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35403 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35404 "b" (bx),
35405 "D" ((long)reg),
35406 - "S" (&pci_indirect));
35407 + "S" (&pci_indirect),
35408 + "r" (__PCIBIOS_DS));
35409 break;
35410 }
35411
35412 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35413
35414 switch (len) {
35415 case 1:
35416 - __asm__("lcall *(%%esi); cld\n\t"
35417 + __asm__("movw %w6, %%ds\n\t"
35418 + "lcall *%%ss:(%%esi); cld\n\t"
35419 + "push %%ss\n\t"
35420 + "pop %%ds\n\t"
35421 "jc 1f\n\t"
35422 "xor %%ah, %%ah\n"
35423 "1:"
35424 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35425 "c" (value),
35426 "b" (bx),
35427 "D" ((long)reg),
35428 - "S" (&pci_indirect));
35429 + "S" (&pci_indirect),
35430 + "r" (__PCIBIOS_DS));
35431 break;
35432 case 2:
35433 - __asm__("lcall *(%%esi); cld\n\t"
35434 + __asm__("movw %w6, %%ds\n\t"
35435 + "lcall *%%ss:(%%esi); cld\n\t"
35436 + "push %%ss\n\t"
35437 + "pop %%ds\n\t"
35438 "jc 1f\n\t"
35439 "xor %%ah, %%ah\n"
35440 "1:"
35441 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35442 "c" (value),
35443 "b" (bx),
35444 "D" ((long)reg),
35445 - "S" (&pci_indirect));
35446 + "S" (&pci_indirect),
35447 + "r" (__PCIBIOS_DS));
35448 break;
35449 case 4:
35450 - __asm__("lcall *(%%esi); cld\n\t"
35451 + __asm__("movw %w6, %%ds\n\t"
35452 + "lcall *%%ss:(%%esi); cld\n\t"
35453 + "push %%ss\n\t"
35454 + "pop %%ds\n\t"
35455 "jc 1f\n\t"
35456 "xor %%ah, %%ah\n"
35457 "1:"
35458 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35459 "c" (value),
35460 "b" (bx),
35461 "D" ((long)reg),
35462 - "S" (&pci_indirect));
35463 + "S" (&pci_indirect),
35464 + "r" (__PCIBIOS_DS));
35465 break;
35466 }
35467
35468 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35469
35470 DBG("PCI: Fetching IRQ routing table... ");
35471 __asm__("push %%es\n\t"
35472 + "movw %w8, %%ds\n\t"
35473 "push %%ds\n\t"
35474 "pop %%es\n\t"
35475 - "lcall *(%%esi); cld\n\t"
35476 + "lcall *%%ss:(%%esi); cld\n\t"
35477 "pop %%es\n\t"
35478 + "push %%ss\n\t"
35479 + "pop %%ds\n"
35480 "jc 1f\n\t"
35481 "xor %%ah, %%ah\n"
35482 "1:"
35483 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35484 "1" (0),
35485 "D" ((long) &opt),
35486 "S" (&pci_indirect),
35487 - "m" (opt)
35488 + "m" (opt),
35489 + "r" (__PCIBIOS_DS)
35490 : "memory");
35491 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35492 if (ret & 0xff00)
35493 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35494 {
35495 int ret;
35496
35497 - __asm__("lcall *(%%esi); cld\n\t"
35498 + __asm__("movw %w5, %%ds\n\t"
35499 + "lcall *%%ss:(%%esi); cld\n\t"
35500 + "push %%ss\n\t"
35501 + "pop %%ds\n"
35502 "jc 1f\n\t"
35503 "xor %%ah, %%ah\n"
35504 "1:"
35505 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35506 : "0" (PCIBIOS_SET_PCI_HW_INT),
35507 "b" ((dev->bus->number << 8) | dev->devfn),
35508 "c" ((irq << 8) | (pin + 10)),
35509 - "S" (&pci_indirect));
35510 + "S" (&pci_indirect),
35511 + "r" (__PCIBIOS_DS));
35512 return !(ret & 0xff00);
35513 }
35514 EXPORT_SYMBOL(pcibios_set_irq_routing);
35515 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35516 index 9ee3491..872192f 100644
35517 --- a/arch/x86/platform/efi/efi_32.c
35518 +++ b/arch/x86/platform/efi/efi_32.c
35519 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35520 {
35521 struct desc_ptr gdt_descr;
35522
35523 +#ifdef CONFIG_PAX_KERNEXEC
35524 + struct desc_struct d;
35525 +#endif
35526 +
35527 local_irq_save(efi_rt_eflags);
35528
35529 load_cr3(initial_page_table);
35530 __flush_tlb_all();
35531
35532 +#ifdef CONFIG_PAX_KERNEXEC
35533 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35534 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35535 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35536 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35537 +#endif
35538 +
35539 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35540 gdt_descr.size = GDT_SIZE - 1;
35541 load_gdt(&gdt_descr);
35542 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35543 {
35544 struct desc_ptr gdt_descr;
35545
35546 +#ifdef CONFIG_PAX_KERNEXEC
35547 + struct desc_struct d;
35548 +
35549 + memset(&d, 0, sizeof d);
35550 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35551 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35552 +#endif
35553 +
35554 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35555 gdt_descr.size = GDT_SIZE - 1;
35556 load_gdt(&gdt_descr);
35557
35558 +#ifdef CONFIG_PAX_PER_CPU_PGD
35559 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35560 +#else
35561 load_cr3(swapper_pg_dir);
35562 +#endif
35563 +
35564 __flush_tlb_all();
35565
35566 local_irq_restore(efi_rt_eflags);
35567 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35568 index 290d397..e09d270 100644
35569 --- a/arch/x86/platform/efi/efi_64.c
35570 +++ b/arch/x86/platform/efi/efi_64.c
35571 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35572 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35573 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35574 }
35575 +
35576 +#ifdef CONFIG_PAX_PER_CPU_PGD
35577 + load_cr3(swapper_pg_dir);
35578 +#endif
35579 +
35580 __flush_tlb_all();
35581 }
35582
35583 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35584 for (pgd = 0; pgd < n_pgds; pgd++)
35585 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35586 kfree(save_pgd);
35587 +
35588 +#ifdef CONFIG_PAX_PER_CPU_PGD
35589 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35590 +#endif
35591 +
35592 __flush_tlb_all();
35593 local_irq_restore(efi_flags);
35594 early_code_mapping_set_exec(0);
35595 @@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35596 unsigned npages;
35597 pgd_t *pgd;
35598
35599 - if (efi_enabled(EFI_OLD_MEMMAP))
35600 + if (efi_enabled(EFI_OLD_MEMMAP)) {
35601 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35602 + * able to execute the EFI services.
35603 + */
35604 + if (__supported_pte_mask & _PAGE_NX) {
35605 + unsigned long addr = (unsigned long) __va(0);
35606 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35607 +
35608 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35609 +#ifdef CONFIG_PAX_PER_CPU_PGD
35610 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35611 +#endif
35612 + set_pgd(pgd_offset_k(addr), pe);
35613 + }
35614 +
35615 return 0;
35616 + }
35617
35618 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35619 pgd = __va(efi_scratch.efi_pgt);
35620 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35621 index fbe66e6..eae5e38 100644
35622 --- a/arch/x86/platform/efi/efi_stub_32.S
35623 +++ b/arch/x86/platform/efi/efi_stub_32.S
35624 @@ -6,7 +6,9 @@
35625 */
35626
35627 #include <linux/linkage.h>
35628 +#include <linux/init.h>
35629 #include <asm/page_types.h>
35630 +#include <asm/segment.h>
35631
35632 /*
35633 * efi_call_phys(void *, ...) is a function with variable parameters.
35634 @@ -20,7 +22,7 @@
35635 * service functions will comply with gcc calling convention, too.
35636 */
35637
35638 -.text
35639 +__INIT
35640 ENTRY(efi_call_phys)
35641 /*
35642 * 0. The function can only be called in Linux kernel. So CS has been
35643 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35644 * The mapping of lower virtual memory has been created in prelog and
35645 * epilog.
35646 */
35647 - movl $1f, %edx
35648 - subl $__PAGE_OFFSET, %edx
35649 - jmp *%edx
35650 +#ifdef CONFIG_PAX_KERNEXEC
35651 + movl $(__KERNEXEC_EFI_DS), %edx
35652 + mov %edx, %ds
35653 + mov %edx, %es
35654 + mov %edx, %ss
35655 + addl $2f,(1f)
35656 + ljmp *(1f)
35657 +
35658 +__INITDATA
35659 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35660 +.previous
35661 +
35662 +2:
35663 + subl $2b,(1b)
35664 +#else
35665 + jmp 1f-__PAGE_OFFSET
35666 1:
35667 +#endif
35668
35669 /*
35670 * 2. Now on the top of stack is the return
35671 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35672 * parameter 2, ..., param n. To make things easy, we save the return
35673 * address of efi_call_phys in a global variable.
35674 */
35675 - popl %edx
35676 - movl %edx, saved_return_addr
35677 - /* get the function pointer into ECX*/
35678 - popl %ecx
35679 - movl %ecx, efi_rt_function_ptr
35680 - movl $2f, %edx
35681 - subl $__PAGE_OFFSET, %edx
35682 - pushl %edx
35683 + popl (saved_return_addr)
35684 + popl (efi_rt_function_ptr)
35685
35686 /*
35687 * 3. Clear PG bit in %CR0.
35688 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35689 /*
35690 * 5. Call the physical function.
35691 */
35692 - jmp *%ecx
35693 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
35694
35695 -2:
35696 /*
35697 * 6. After EFI runtime service returns, control will return to
35698 * following instruction. We'd better readjust stack pointer first.
35699 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35700 movl %cr0, %edx
35701 orl $0x80000000, %edx
35702 movl %edx, %cr0
35703 - jmp 1f
35704 -1:
35705 +
35706 /*
35707 * 8. Now restore the virtual mode from flat mode by
35708 * adding EIP with PAGE_OFFSET.
35709 */
35710 - movl $1f, %edx
35711 - jmp *%edx
35712 +#ifdef CONFIG_PAX_KERNEXEC
35713 + movl $(__KERNEL_DS), %edx
35714 + mov %edx, %ds
35715 + mov %edx, %es
35716 + mov %edx, %ss
35717 + ljmp $(__KERNEL_CS),$1f
35718 +#else
35719 + jmp 1f+__PAGE_OFFSET
35720 +#endif
35721 1:
35722
35723 /*
35724 * 9. Balance the stack. And because EAX contain the return value,
35725 * we'd better not clobber it.
35726 */
35727 - leal efi_rt_function_ptr, %edx
35728 - movl (%edx), %ecx
35729 - pushl %ecx
35730 + pushl (efi_rt_function_ptr)
35731
35732 /*
35733 - * 10. Push the saved return address onto the stack and return.
35734 + * 10. Return to the saved return address.
35735 */
35736 - leal saved_return_addr, %edx
35737 - movl (%edx), %ecx
35738 - pushl %ecx
35739 - ret
35740 + jmpl *(saved_return_addr)
35741 ENDPROC(efi_call_phys)
35742 .previous
35743
35744 -.data
35745 +__INITDATA
35746 saved_return_addr:
35747 .long 0
35748 efi_rt_function_ptr:
35749 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35750 index 5fcda72..cd4dc41 100644
35751 --- a/arch/x86/platform/efi/efi_stub_64.S
35752 +++ b/arch/x86/platform/efi/efi_stub_64.S
35753 @@ -11,6 +11,7 @@
35754 #include <asm/msr.h>
35755 #include <asm/processor-flags.h>
35756 #include <asm/page_types.h>
35757 +#include <asm/alternative-asm.h>
35758
35759 #define SAVE_XMM \
35760 mov %rsp, %rax; \
35761 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35762 RESTORE_PGT
35763 addq $48, %rsp
35764 RESTORE_XMM
35765 + pax_force_retaddr 0, 1
35766 ret
35767 ENDPROC(efi_call)
35768
35769 @@ -245,8 +247,8 @@ efi_gdt64:
35770 .long 0 /* Filled out by user */
35771 .word 0
35772 .quad 0x0000000000000000 /* NULL descriptor */
35773 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
35774 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
35775 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
35776 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
35777 .quad 0x0080890000000000 /* TS descriptor */
35778 .quad 0x0000000000000000 /* TS continued */
35779 efi_gdt64_end:
35780 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35781 index 1bbedc4..eb795b5 100644
35782 --- a/arch/x86/platform/intel-mid/intel-mid.c
35783 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35784 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35785 {
35786 };
35787
35788 -static void intel_mid_reboot(void)
35789 +static void __noreturn intel_mid_reboot(void)
35790 {
35791 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35792 + BUG();
35793 }
35794
35795 static unsigned long __init intel_mid_calibrate_tsc(void)
35796 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35797 index 46aa25c..59a68ed 100644
35798 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35799 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35800 @@ -10,10 +10,9 @@
35801 */
35802
35803
35804 -/* __attribute__((weak)) makes these declarations overridable */
35805 /* For every CPU addition a new get_<cpuname>_ops interface needs
35806 * to be added.
35807 */
35808 -extern void *get_penwell_ops(void) __attribute__((weak));
35809 -extern void *get_cloverview_ops(void) __attribute__((weak));
35810 -extern void *get_tangier_ops(void) __attribute__((weak));
35811 +extern const void *get_penwell_ops(void);
35812 +extern const void *get_cloverview_ops(void);
35813 +extern const void *get_tangier_ops(void);
35814 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35815 index 23381d2..8ddc10e 100644
35816 --- a/arch/x86/platform/intel-mid/mfld.c
35817 +++ b/arch/x86/platform/intel-mid/mfld.c
35818 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35819 pm_power_off = mfld_power_off;
35820 }
35821
35822 -void *get_penwell_ops(void)
35823 +const void *get_penwell_ops(void)
35824 {
35825 return &penwell_ops;
35826 }
35827
35828 -void *get_cloverview_ops(void)
35829 +const void *get_cloverview_ops(void)
35830 {
35831 return &penwell_ops;
35832 }
35833 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35834 index aaca917..66eadbc 100644
35835 --- a/arch/x86/platform/intel-mid/mrfl.c
35836 +++ b/arch/x86/platform/intel-mid/mrfl.c
35837 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35838 .arch_setup = tangier_arch_setup,
35839 };
35840
35841 -void *get_tangier_ops(void)
35842 +const void *get_tangier_ops(void)
35843 {
35844 return &tangier_ops;
35845 }
35846 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35847 index d6ee929..3637cb5 100644
35848 --- a/arch/x86/platform/olpc/olpc_dt.c
35849 +++ b/arch/x86/platform/olpc/olpc_dt.c
35850 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35851 return res;
35852 }
35853
35854 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35855 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35856 .nextprop = olpc_dt_nextprop,
35857 .getproplen = olpc_dt_getproplen,
35858 .getproperty = olpc_dt_getproperty,
35859 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35860 index 6ec7910..ecdbb11 100644
35861 --- a/arch/x86/power/cpu.c
35862 +++ b/arch/x86/power/cpu.c
35863 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35864 static void fix_processor_context(void)
35865 {
35866 int cpu = smp_processor_id();
35867 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35868 -#ifdef CONFIG_X86_64
35869 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35870 - tss_desc tss;
35871 -#endif
35872 + struct tss_struct *t = init_tss + cpu;
35873 +
35874 set_tss_desc(cpu, t); /*
35875 * This just modifies memory; should not be
35876 * necessary. But... This is necessary, because
35877 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35878 */
35879
35880 #ifdef CONFIG_X86_64
35881 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35882 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35883 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35884 -
35885 syscall_init(); /* This sets MSR_*STAR and related */
35886 #endif
35887 load_TR_desc(); /* This does ltr */
35888 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35889 index bad628a..a102610 100644
35890 --- a/arch/x86/realmode/init.c
35891 +++ b/arch/x86/realmode/init.c
35892 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35893 __va(real_mode_header->trampoline_header);
35894
35895 #ifdef CONFIG_X86_32
35896 - trampoline_header->start = __pa_symbol(startup_32_smp);
35897 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35898 +
35899 +#ifdef CONFIG_PAX_KERNEXEC
35900 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35901 +#endif
35902 +
35903 + trampoline_header->boot_cs = __BOOT_CS;
35904 trampoline_header->gdt_limit = __BOOT_DS + 7;
35905 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35906 #else
35907 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35908 *trampoline_cr4_features = read_cr4();
35909
35910 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35911 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35912 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35913 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35914 #endif
35915 }
35916 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35917 index 7c0d7be..d24dc88 100644
35918 --- a/arch/x86/realmode/rm/Makefile
35919 +++ b/arch/x86/realmode/rm/Makefile
35920 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35921
35922 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35923 -I$(srctree)/arch/x86/boot
35924 +ifdef CONSTIFY_PLUGIN
35925 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35926 +endif
35927 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35928 GCOV_PROFILE := n
35929 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35930 index a28221d..93c40f1 100644
35931 --- a/arch/x86/realmode/rm/header.S
35932 +++ b/arch/x86/realmode/rm/header.S
35933 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35934 #endif
35935 /* APM/BIOS reboot */
35936 .long pa_machine_real_restart_asm
35937 -#ifdef CONFIG_X86_64
35938 +#ifdef CONFIG_X86_32
35939 + .long __KERNEL_CS
35940 +#else
35941 .long __KERNEL32_CS
35942 #endif
35943 END(real_mode_header)
35944 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35945 index 48ddd76..c26749f 100644
35946 --- a/arch/x86/realmode/rm/trampoline_32.S
35947 +++ b/arch/x86/realmode/rm/trampoline_32.S
35948 @@ -24,6 +24,12 @@
35949 #include <asm/page_types.h>
35950 #include "realmode.h"
35951
35952 +#ifdef CONFIG_PAX_KERNEXEC
35953 +#define ta(X) (X)
35954 +#else
35955 +#define ta(X) (pa_ ## X)
35956 +#endif
35957 +
35958 .text
35959 .code16
35960
35961 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35962
35963 cli # We should be safe anyway
35964
35965 - movl tr_start, %eax # where we need to go
35966 -
35967 movl $0xA5A5A5A5, trampoline_status
35968 # write marker for master knows we're running
35969
35970 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35971 movw $1, %dx # protected mode (PE) bit
35972 lmsw %dx # into protected mode
35973
35974 - ljmpl $__BOOT_CS, $pa_startup_32
35975 + ljmpl *(trampoline_header)
35976
35977 .section ".text32","ax"
35978 .code32
35979 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35980 .balign 8
35981 GLOBAL(trampoline_header)
35982 tr_start: .space 4
35983 - tr_gdt_pad: .space 2
35984 + tr_boot_cs: .space 2
35985 tr_gdt: .space 6
35986 END(trampoline_header)
35987
35988 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35989 index dac7b20..72dbaca 100644
35990 --- a/arch/x86/realmode/rm/trampoline_64.S
35991 +++ b/arch/x86/realmode/rm/trampoline_64.S
35992 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35993 movl %edx, %gs
35994
35995 movl pa_tr_cr4, %eax
35996 + andl $~X86_CR4_PCIDE, %eax
35997 movl %eax, %cr4 # Enable PAE mode
35998
35999 # Setup trampoline 4 level pagetables
36000 @@ -106,7 +107,7 @@ ENTRY(startup_32)
36001 wrmsr
36002
36003 # Enable paging and in turn activate Long Mode
36004 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36005 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
36006 movl %eax, %cr0
36007
36008 /*
36009 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36010 index 9e7e147..25a4158 100644
36011 --- a/arch/x86/realmode/rm/wakeup_asm.S
36012 +++ b/arch/x86/realmode/rm/wakeup_asm.S
36013 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36014 lgdtl pmode_gdt
36015
36016 /* This really couldn't... */
36017 - movl pmode_entry, %eax
36018 movl pmode_cr0, %ecx
36019 movl %ecx, %cr0
36020 - ljmpl $__KERNEL_CS, $pa_startup_32
36021 - /* -> jmp *%eax in trampoline_32.S */
36022 +
36023 + ljmpl *pmode_entry
36024 #else
36025 jmp trampoline_start
36026 #endif
36027 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36028 index 604a37e..e49702a 100644
36029 --- a/arch/x86/tools/Makefile
36030 +++ b/arch/x86/tools/Makefile
36031 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
36032
36033 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
36034
36035 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
36036 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
36037 hostprogs-y += relocs
36038 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
36039 PHONY += relocs
36040 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
36041 index bbb1d22..e505211 100644
36042 --- a/arch/x86/tools/relocs.c
36043 +++ b/arch/x86/tools/relocs.c
36044 @@ -1,5 +1,7 @@
36045 /* This is included from relocs_32/64.c */
36046
36047 +#include "../../../include/generated/autoconf.h"
36048 +
36049 #define ElfW(type) _ElfW(ELF_BITS, type)
36050 #define _ElfW(bits, type) __ElfW(bits, type)
36051 #define __ElfW(bits, type) Elf##bits##_##type
36052 @@ -11,6 +13,7 @@
36053 #define Elf_Sym ElfW(Sym)
36054
36055 static Elf_Ehdr ehdr;
36056 +static Elf_Phdr *phdr;
36057
36058 struct relocs {
36059 uint32_t *offset;
36060 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
36061 }
36062 }
36063
36064 +static void read_phdrs(FILE *fp)
36065 +{
36066 + unsigned int i;
36067 +
36068 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
36069 + if (!phdr) {
36070 + die("Unable to allocate %d program headers\n",
36071 + ehdr.e_phnum);
36072 + }
36073 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
36074 + die("Seek to %d failed: %s\n",
36075 + ehdr.e_phoff, strerror(errno));
36076 + }
36077 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
36078 + die("Cannot read ELF program headers: %s\n",
36079 + strerror(errno));
36080 + }
36081 + for(i = 0; i < ehdr.e_phnum; i++) {
36082 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36083 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36084 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36085 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36086 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36087 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36088 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36089 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36090 + }
36091 +
36092 +}
36093 +
36094 static void read_shdrs(FILE *fp)
36095 {
36096 - int i;
36097 + unsigned int i;
36098 Elf_Shdr shdr;
36099
36100 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36101 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36102
36103 static void read_strtabs(FILE *fp)
36104 {
36105 - int i;
36106 + unsigned int i;
36107 for (i = 0; i < ehdr.e_shnum; i++) {
36108 struct section *sec = &secs[i];
36109 if (sec->shdr.sh_type != SHT_STRTAB) {
36110 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36111
36112 static void read_symtabs(FILE *fp)
36113 {
36114 - int i,j;
36115 + unsigned int i,j;
36116 for (i = 0; i < ehdr.e_shnum; i++) {
36117 struct section *sec = &secs[i];
36118 if (sec->shdr.sh_type != SHT_SYMTAB) {
36119 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36120 }
36121
36122
36123 -static void read_relocs(FILE *fp)
36124 +static void read_relocs(FILE *fp, int use_real_mode)
36125 {
36126 - int i,j;
36127 + unsigned int i,j;
36128 + uint32_t base;
36129 +
36130 for (i = 0; i < ehdr.e_shnum; i++) {
36131 struct section *sec = &secs[i];
36132 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36133 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36134 die("Cannot read symbol table: %s\n",
36135 strerror(errno));
36136 }
36137 + base = 0;
36138 +
36139 +#ifdef CONFIG_X86_32
36140 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36141 + if (phdr[j].p_type != PT_LOAD )
36142 + continue;
36143 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
36144 + continue;
36145 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36146 + break;
36147 + }
36148 +#endif
36149 +
36150 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36151 Elf_Rel *rel = &sec->reltab[j];
36152 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36153 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36154 rel->r_info = elf_xword_to_cpu(rel->r_info);
36155 #if (SHT_REL_TYPE == SHT_RELA)
36156 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36157 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36158
36159 static void print_absolute_symbols(void)
36160 {
36161 - int i;
36162 + unsigned int i;
36163 const char *format;
36164
36165 if (ELF_BITS == 64)
36166 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36167 for (i = 0; i < ehdr.e_shnum; i++) {
36168 struct section *sec = &secs[i];
36169 char *sym_strtab;
36170 - int j;
36171 + unsigned int j;
36172
36173 if (sec->shdr.sh_type != SHT_SYMTAB) {
36174 continue;
36175 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36176
36177 static void print_absolute_relocs(void)
36178 {
36179 - int i, printed = 0;
36180 + unsigned int i, printed = 0;
36181 const char *format;
36182
36183 if (ELF_BITS == 64)
36184 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36185 struct section *sec_applies, *sec_symtab;
36186 char *sym_strtab;
36187 Elf_Sym *sh_symtab;
36188 - int j;
36189 + unsigned int j;
36190 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36191 continue;
36192 }
36193 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36194 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36195 Elf_Sym *sym, const char *symname))
36196 {
36197 - int i;
36198 + unsigned int i;
36199 /* Walk through the relocations */
36200 for (i = 0; i < ehdr.e_shnum; i++) {
36201 char *sym_strtab;
36202 Elf_Sym *sh_symtab;
36203 struct section *sec_applies, *sec_symtab;
36204 - int j;
36205 + unsigned int j;
36206 struct section *sec = &secs[i];
36207
36208 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36209 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36210 {
36211 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36212 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36213 + char *sym_strtab = sec->link->link->strtab;
36214 +
36215 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36216 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36217 + return 0;
36218 +
36219 +#ifdef CONFIG_PAX_KERNEXEC
36220 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36221 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36222 + return 0;
36223 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36224 + return 0;
36225 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36226 + return 0;
36227 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36228 + return 0;
36229 +#endif
36230
36231 switch (r_type) {
36232 case R_386_NONE:
36233 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36234
36235 static void emit_relocs(int as_text, int use_real_mode)
36236 {
36237 - int i;
36238 + unsigned int i;
36239 int (*write_reloc)(uint32_t, FILE *) = write32;
36240 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36241 const char *symname);
36242 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36243 {
36244 regex_init(use_real_mode);
36245 read_ehdr(fp);
36246 + read_phdrs(fp);
36247 read_shdrs(fp);
36248 read_strtabs(fp);
36249 read_symtabs(fp);
36250 - read_relocs(fp);
36251 + read_relocs(fp, use_real_mode);
36252 if (ELF_BITS == 64)
36253 percpu_init();
36254 if (show_absolute_syms) {
36255 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36256 index f40281e..92728c9 100644
36257 --- a/arch/x86/um/mem_32.c
36258 +++ b/arch/x86/um/mem_32.c
36259 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36260 gate_vma.vm_start = FIXADDR_USER_START;
36261 gate_vma.vm_end = FIXADDR_USER_END;
36262 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36263 - gate_vma.vm_page_prot = __P101;
36264 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36265
36266 return 0;
36267 }
36268 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36269 index 80ffa5b..a33bd15 100644
36270 --- a/arch/x86/um/tls_32.c
36271 +++ b/arch/x86/um/tls_32.c
36272 @@ -260,7 +260,7 @@ out:
36273 if (unlikely(task == current &&
36274 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36275 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36276 - "without flushed TLS.", current->pid);
36277 + "without flushed TLS.", task_pid_nr(current));
36278 }
36279
36280 return 0;
36281 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36282 index 5a4affe..9e2d522 100644
36283 --- a/arch/x86/vdso/Makefile
36284 +++ b/arch/x86/vdso/Makefile
36285 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36286 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36287 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36288
36289 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36290 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36291 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36292 GCOV_PROFILE := n
36293
36294 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36295 index e904c27..b9eaa03 100644
36296 --- a/arch/x86/vdso/vdso32-setup.c
36297 +++ b/arch/x86/vdso/vdso32-setup.c
36298 @@ -14,6 +14,7 @@
36299 #include <asm/cpufeature.h>
36300 #include <asm/processor.h>
36301 #include <asm/vdso.h>
36302 +#include <asm/mman.h>
36303
36304 #ifdef CONFIG_COMPAT_VDSO
36305 #define VDSO_DEFAULT 0
36306 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36307 index 970463b..da82d3e 100644
36308 --- a/arch/x86/vdso/vma.c
36309 +++ b/arch/x86/vdso/vma.c
36310 @@ -16,10 +16,9 @@
36311 #include <asm/vdso.h>
36312 #include <asm/page.h>
36313 #include <asm/hpet.h>
36314 +#include <asm/mman.h>
36315
36316 #if defined(CONFIG_X86_64)
36317 -unsigned int __read_mostly vdso64_enabled = 1;
36318 -
36319 extern unsigned short vdso_sync_cpuid;
36320 #endif
36321
36322 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36323 .pages = no_pages,
36324 };
36325
36326 +#ifdef CONFIG_PAX_RANDMMAP
36327 + if (mm->pax_flags & MF_PAX_RANDMMAP)
36328 + calculate_addr = false;
36329 +#endif
36330 +
36331 if (calculate_addr) {
36332 addr = vdso_addr(current->mm->start_stack,
36333 image->size - image->sym_vvar_start);
36334 @@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36335 down_write(&mm->mmap_sem);
36336
36337 addr = get_unmapped_area(NULL, addr,
36338 - image->size - image->sym_vvar_start, 0, 0);
36339 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36340 if (IS_ERR_VALUE(addr)) {
36341 ret = addr;
36342 goto up_fail;
36343 }
36344
36345 text_start = addr - image->sym_vvar_start;
36346 - current->mm->context.vdso = (void __user *)text_start;
36347 + mm->context.vdso = text_start;
36348
36349 /*
36350 * MAYWRITE to allow gdb to COW and set breakpoints
36351 @@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36352 hpet_address >> PAGE_SHIFT,
36353 PAGE_SIZE,
36354 pgprot_noncached(PAGE_READONLY));
36355 -
36356 - if (ret)
36357 - goto up_fail;
36358 }
36359 #endif
36360
36361 up_fail:
36362 if (ret)
36363 - current->mm->context.vdso = NULL;
36364 + current->mm->context.vdso = 0;
36365
36366 up_write(&mm->mmap_sem);
36367 return ret;
36368 @@ -191,8 +192,8 @@ static int load_vdso32(void)
36369
36370 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36371 current_thread_info()->sysenter_return =
36372 - current->mm->context.vdso +
36373 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36374 + (void __force_user *)(current->mm->context.vdso +
36375 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36376
36377 return 0;
36378 }
36379 @@ -201,9 +202,6 @@ static int load_vdso32(void)
36380 #ifdef CONFIG_X86_64
36381 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36382 {
36383 - if (!vdso64_enabled)
36384 - return 0;
36385 -
36386 return map_vdso(&vdso_image_64, true);
36387 }
36388
36389 @@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36390 int uses_interp)
36391 {
36392 #ifdef CONFIG_X86_X32_ABI
36393 - if (test_thread_flag(TIF_X32)) {
36394 - if (!vdso64_enabled)
36395 - return 0;
36396 -
36397 + if (test_thread_flag(TIF_X32))
36398 return map_vdso(&vdso_image_x32, true);
36399 - }
36400 #endif
36401
36402 return load_vdso32();
36403 @@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36404 return load_vdso32();
36405 }
36406 #endif
36407 -
36408 -#ifdef CONFIG_X86_64
36409 -static __init int vdso_setup(char *s)
36410 -{
36411 - vdso64_enabled = simple_strtoul(s, NULL, 0);
36412 - return 0;
36413 -}
36414 -__setup("vdso=", vdso_setup);
36415 -#endif
36416 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36417 index e88fda8..76ce7ce 100644
36418 --- a/arch/x86/xen/Kconfig
36419 +++ b/arch/x86/xen/Kconfig
36420 @@ -9,6 +9,7 @@ config XEN
36421 select XEN_HAVE_PVMMU
36422 depends on X86_64 || (X86_32 && X86_PAE)
36423 depends on X86_TSC
36424 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36425 help
36426 This is the Linux Xen port. Enabling this will allow the
36427 kernel to boot in a paravirtualized environment under the
36428 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36429 index c0cb11f..bed56ff 100644
36430 --- a/arch/x86/xen/enlighten.c
36431 +++ b/arch/x86/xen/enlighten.c
36432 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36433
36434 struct shared_info xen_dummy_shared_info;
36435
36436 -void *xen_initial_gdt;
36437 -
36438 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36439 __read_mostly int xen_have_vector_callback;
36440 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36441 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36442 {
36443 unsigned long va = dtr->address;
36444 unsigned int size = dtr->size + 1;
36445 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36446 - unsigned long frames[pages];
36447 + unsigned long frames[65536 / PAGE_SIZE];
36448 int f;
36449
36450 /*
36451 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36452 {
36453 unsigned long va = dtr->address;
36454 unsigned int size = dtr->size + 1;
36455 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36456 - unsigned long frames[pages];
36457 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36458 int f;
36459
36460 /*
36461 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36462 * 8-byte entries, or 16 4k pages..
36463 */
36464
36465 - BUG_ON(size > 65536);
36466 + BUG_ON(size > GDT_SIZE);
36467 BUG_ON(va & ~PAGE_MASK);
36468
36469 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36470 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36471 return 0;
36472 }
36473
36474 -static void set_xen_basic_apic_ops(void)
36475 +static void __init set_xen_basic_apic_ops(void)
36476 {
36477 apic->read = xen_apic_read;
36478 apic->write = xen_apic_write;
36479 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36480 #endif
36481 };
36482
36483 -static void xen_reboot(int reason)
36484 +static __noreturn void xen_reboot(int reason)
36485 {
36486 struct sched_shutdown r = { .reason = reason };
36487
36488 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36489 - BUG();
36490 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36491 + BUG();
36492 }
36493
36494 -static void xen_restart(char *msg)
36495 +static __noreturn void xen_restart(char *msg)
36496 {
36497 xen_reboot(SHUTDOWN_reboot);
36498 }
36499
36500 -static void xen_emergency_restart(void)
36501 +static __noreturn void xen_emergency_restart(void)
36502 {
36503 xen_reboot(SHUTDOWN_reboot);
36504 }
36505
36506 -static void xen_machine_halt(void)
36507 +static __noreturn void xen_machine_halt(void)
36508 {
36509 xen_reboot(SHUTDOWN_poweroff);
36510 }
36511
36512 -static void xen_machine_power_off(void)
36513 +static __noreturn void xen_machine_power_off(void)
36514 {
36515 if (pm_power_off)
36516 pm_power_off();
36517 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36518 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36519
36520 /* Work out if we support NX */
36521 - x86_configure_nx();
36522 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36523 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36524 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36525 + unsigned l, h;
36526 +
36527 + __supported_pte_mask |= _PAGE_NX;
36528 + rdmsr(MSR_EFER, l, h);
36529 + l |= EFER_NX;
36530 + wrmsr(MSR_EFER, l, h);
36531 + }
36532 +#endif
36533
36534 /* Get mfn list */
36535 xen_build_dynamic_phys_to_machine();
36536 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36537
36538 machine_ops = xen_machine_ops;
36539
36540 - /*
36541 - * The only reliable way to retain the initial address of the
36542 - * percpu gdt_page is to remember it here, so we can go and
36543 - * mark it RW later, when the initial percpu area is freed.
36544 - */
36545 - xen_initial_gdt = &per_cpu(gdt_page, 0);
36546 -
36547 xen_smp_init();
36548
36549 #ifdef CONFIG_ACPI_NUMA
36550 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36551 index 16fb009..02b7801 100644
36552 --- a/arch/x86/xen/mmu.c
36553 +++ b/arch/x86/xen/mmu.c
36554 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36555 return val;
36556 }
36557
36558 -static pteval_t pte_pfn_to_mfn(pteval_t val)
36559 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36560 {
36561 if (val & _PAGE_PRESENT) {
36562 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36563 @@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36564 * L3_k[511] -> level2_fixmap_pgt */
36565 convert_pfn_mfn(level3_kernel_pgt);
36566
36567 + convert_pfn_mfn(level3_vmalloc_start_pgt);
36568 + convert_pfn_mfn(level3_vmalloc_end_pgt);
36569 + convert_pfn_mfn(level3_vmemmap_pgt);
36570 /* L3_k[511][506] -> level1_fixmap_pgt */
36571 + /* L3_k[511][507] -> level1_vsyscall_pgt */
36572 convert_pfn_mfn(level2_fixmap_pgt);
36573 }
36574 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36575 @@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36576 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36577 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36578 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36579 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36580 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36581 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36582 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36583 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36584 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36585 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36586 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36587 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36588 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36589
36590 /* Pin down new L4 */
36591 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36592 @@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36593 pv_mmu_ops.set_pud = xen_set_pud;
36594 #if PAGETABLE_LEVELS == 4
36595 pv_mmu_ops.set_pgd = xen_set_pgd;
36596 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36597 #endif
36598
36599 /* This will work as long as patching hasn't happened yet
36600 @@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36601 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36602 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36603 .set_pgd = xen_set_pgd_hyper,
36604 + .set_pgd_batched = xen_set_pgd_hyper,
36605
36606 .alloc_pud = xen_alloc_pmd_init,
36607 .release_pud = xen_release_pmd_init,
36608 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36609 index 7005974..54fb05f 100644
36610 --- a/arch/x86/xen/smp.c
36611 +++ b/arch/x86/xen/smp.c
36612 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36613
36614 if (xen_pv_domain()) {
36615 if (!xen_feature(XENFEAT_writable_page_tables))
36616 - /* We've switched to the "real" per-cpu gdt, so make
36617 - * sure the old memory can be recycled. */
36618 - make_lowmem_page_readwrite(xen_initial_gdt);
36619 -
36620 #ifdef CONFIG_X86_32
36621 /*
36622 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36623 * expects __USER_DS
36624 */
36625 - loadsegment(ds, __USER_DS);
36626 - loadsegment(es, __USER_DS);
36627 + loadsegment(ds, __KERNEL_DS);
36628 + loadsegment(es, __KERNEL_DS);
36629 #endif
36630
36631 xen_filter_cpu_maps();
36632 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36633 #ifdef CONFIG_X86_32
36634 /* Note: PVH is not yet supported on x86_32. */
36635 ctxt->user_regs.fs = __KERNEL_PERCPU;
36636 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36637 + savesegment(gs, ctxt->user_regs.gs);
36638 #endif
36639 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36640
36641 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36642 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36643 ctxt->flags = VGCF_IN_KERNEL;
36644 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36645 - ctxt->user_regs.ds = __USER_DS;
36646 - ctxt->user_regs.es = __USER_DS;
36647 + ctxt->user_regs.ds = __KERNEL_DS;
36648 + ctxt->user_regs.es = __KERNEL_DS;
36649 ctxt->user_regs.ss = __KERNEL_DS;
36650
36651 xen_copy_trap_info(ctxt->trap_ctxt);
36652 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36653 int rc;
36654
36655 per_cpu(current_task, cpu) = idle;
36656 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
36657 #ifdef CONFIG_X86_32
36658 irq_ctx_init(cpu);
36659 #else
36660 clear_tsk_thread_flag(idle, TIF_FORK);
36661 #endif
36662 - per_cpu(kernel_stack, cpu) =
36663 - (unsigned long)task_stack_page(idle) -
36664 - KERNEL_STACK_OFFSET + THREAD_SIZE;
36665 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36666
36667 xen_setup_runstate_info(cpu);
36668 xen_setup_timer(cpu);
36669 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36670
36671 void __init xen_smp_init(void)
36672 {
36673 - smp_ops = xen_smp_ops;
36674 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36675 xen_fill_possible_map();
36676 }
36677
36678 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36679 index fd92a64..1f72641 100644
36680 --- a/arch/x86/xen/xen-asm_32.S
36681 +++ b/arch/x86/xen/xen-asm_32.S
36682 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
36683 pushw %fs
36684 movl $(__KERNEL_PERCPU), %eax
36685 movl %eax, %fs
36686 - movl %fs:xen_vcpu, %eax
36687 + mov PER_CPU_VAR(xen_vcpu), %eax
36688 POP_FS
36689 #else
36690 movl %ss:xen_vcpu, %eax
36691 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36692 index 485b695..fda3e7c 100644
36693 --- a/arch/x86/xen/xen-head.S
36694 +++ b/arch/x86/xen/xen-head.S
36695 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36696 #ifdef CONFIG_X86_32
36697 mov %esi,xen_start_info
36698 mov $init_thread_union+THREAD_SIZE,%esp
36699 +#ifdef CONFIG_SMP
36700 + movl $cpu_gdt_table,%edi
36701 + movl $__per_cpu_load,%eax
36702 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36703 + rorl $16,%eax
36704 + movb %al,__KERNEL_PERCPU + 4(%edi)
36705 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36706 + movl $__per_cpu_end - 1,%eax
36707 + subl $__per_cpu_start,%eax
36708 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36709 +#endif
36710 #else
36711 mov %rsi,xen_start_info
36712 mov $init_thread_union+THREAD_SIZE,%rsp
36713 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36714 index 28c7e0b..2acfec7 100644
36715 --- a/arch/x86/xen/xen-ops.h
36716 +++ b/arch/x86/xen/xen-ops.h
36717 @@ -10,8 +10,6 @@
36718 extern const char xen_hypervisor_callback[];
36719 extern const char xen_failsafe_callback[];
36720
36721 -extern void *xen_initial_gdt;
36722 -
36723 struct trap_info;
36724 void xen_copy_trap_info(struct trap_info *traps);
36725
36726 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36727 index 525bd3d..ef888b1 100644
36728 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36729 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36730 @@ -119,9 +119,9 @@
36731 ----------------------------------------------------------------------*/
36732
36733 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36734 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36735 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36736 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36737 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36738
36739 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36740 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36741 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36742 index 2f33760..835e50a 100644
36743 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36744 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36745 @@ -11,6 +11,7 @@
36746 #ifndef _XTENSA_CORE_H
36747 #define _XTENSA_CORE_H
36748
36749 +#include <linux/const.h>
36750
36751 /****************************************************************************
36752 Parameters Useful for Any Code, USER or PRIVILEGED
36753 @@ -112,9 +113,9 @@
36754 ----------------------------------------------------------------------*/
36755
36756 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36757 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36758 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36759 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36760 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36761
36762 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36763 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36764 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36765 index af00795..2bb8105 100644
36766 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36767 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36768 @@ -11,6 +11,7 @@
36769 #ifndef _XTENSA_CORE_CONFIGURATION_H
36770 #define _XTENSA_CORE_CONFIGURATION_H
36771
36772 +#include <linux/const.h>
36773
36774 /****************************************************************************
36775 Parameters Useful for Any Code, USER or PRIVILEGED
36776 @@ -118,9 +119,9 @@
36777 ----------------------------------------------------------------------*/
36778
36779 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36780 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36781 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36782 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36783 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36784
36785 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36786 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36787 diff --git a/block/bio.c b/block/bio.c
36788 index 3e6331d..f970433 100644
36789 --- a/block/bio.c
36790 +++ b/block/bio.c
36791 @@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36792 /*
36793 * Overflow, abort
36794 */
36795 - if (end < start)
36796 + if (end < start || end - start > INT_MAX - nr_pages)
36797 return ERR_PTR(-EINVAL);
36798
36799 nr_pages += end - start;
36800 @@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36801 /*
36802 * Overflow, abort
36803 */
36804 - if (end < start)
36805 + if (end < start || end - start > INT_MAX - nr_pages)
36806 return ERR_PTR(-EINVAL);
36807
36808 nr_pages += end - start;
36809 @@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36810 const int read = bio_data_dir(bio) == READ;
36811 struct bio_map_data *bmd = bio->bi_private;
36812 int i;
36813 - char *p = bmd->sgvecs[0].iov_base;
36814 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36815
36816 bio_for_each_segment_all(bvec, bio, i) {
36817 char *addr = page_address(bvec->bv_page);
36818 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36819 index e17da94..e01cce1 100644
36820 --- a/block/blk-cgroup.c
36821 +++ b/block/blk-cgroup.c
36822 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36823 static struct cgroup_subsys_state *
36824 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36825 {
36826 - static atomic64_t id_seq = ATOMIC64_INIT(0);
36827 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36828 struct blkcg *blkcg;
36829
36830 if (!parent_css) {
36831 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36832
36833 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36834 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36835 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36836 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36837 done:
36838 spin_lock_init(&blkcg->lock);
36839 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36840 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36841 index 0736729..2ec3b48 100644
36842 --- a/block/blk-iopoll.c
36843 +++ b/block/blk-iopoll.c
36844 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36845 }
36846 EXPORT_SYMBOL(blk_iopoll_complete);
36847
36848 -static void blk_iopoll_softirq(struct softirq_action *h)
36849 +static __latent_entropy void blk_iopoll_softirq(void)
36850 {
36851 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36852 int rearm = 0, budget = blk_iopoll_budget;
36853 diff --git a/block/blk-map.c b/block/blk-map.c
36854 index f890d43..97b0482 100644
36855 --- a/block/blk-map.c
36856 +++ b/block/blk-map.c
36857 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36858 if (!len || !kbuf)
36859 return -EINVAL;
36860
36861 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36862 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36863 if (do_copy)
36864 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36865 else
36866 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36867 index 53b1737..08177d2e 100644
36868 --- a/block/blk-softirq.c
36869 +++ b/block/blk-softirq.c
36870 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36871 * Softirq action handler - move entries to local list and loop over them
36872 * while passing them to the queue registered handler.
36873 */
36874 -static void blk_done_softirq(struct softirq_action *h)
36875 +static __latent_entropy void blk_done_softirq(void)
36876 {
36877 struct list_head *cpu_list, local_list;
36878
36879 diff --git a/block/bsg.c b/block/bsg.c
36880 index ff46add..c4ba8ee 100644
36881 --- a/block/bsg.c
36882 +++ b/block/bsg.c
36883 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36884 struct sg_io_v4 *hdr, struct bsg_device *bd,
36885 fmode_t has_write_perm)
36886 {
36887 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36888 + unsigned char *cmdptr;
36889 +
36890 if (hdr->request_len > BLK_MAX_CDB) {
36891 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36892 if (!rq->cmd)
36893 return -ENOMEM;
36894 - }
36895 + cmdptr = rq->cmd;
36896 + } else
36897 + cmdptr = tmpcmd;
36898
36899 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36900 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36901 hdr->request_len))
36902 return -EFAULT;
36903
36904 + if (cmdptr != rq->cmd)
36905 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36906 +
36907 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36908 if (blk_verify_command(rq->cmd, has_write_perm))
36909 return -EPERM;
36910 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36911 index 18b282c..050dbe5 100644
36912 --- a/block/compat_ioctl.c
36913 +++ b/block/compat_ioctl.c
36914 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36915 cgc = compat_alloc_user_space(sizeof(*cgc));
36916 cgc32 = compat_ptr(arg);
36917
36918 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36919 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36920 get_user(data, &cgc32->buffer) ||
36921 put_user(compat_ptr(data), &cgc->buffer) ||
36922 copy_in_user(&cgc->buflen, &cgc32->buflen,
36923 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36924 err |= __get_user(f->spec1, &uf->spec1);
36925 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36926 err |= __get_user(name, &uf->name);
36927 - f->name = compat_ptr(name);
36928 + f->name = (void __force_kernel *)compat_ptr(name);
36929 if (err) {
36930 err = -EFAULT;
36931 goto out;
36932 diff --git a/block/genhd.c b/block/genhd.c
36933 index e6723bd..703e4ac 100644
36934 --- a/block/genhd.c
36935 +++ b/block/genhd.c
36936 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36937
36938 /*
36939 * Register device numbers dev..(dev+range-1)
36940 - * range must be nonzero
36941 + * Noop if @range is zero.
36942 * The hash chain is sorted on range, so that subranges can override.
36943 */
36944 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36945 struct kobject *(*probe)(dev_t, int *, void *),
36946 int (*lock)(dev_t, void *), void *data)
36947 {
36948 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36949 + if (range)
36950 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36951 }
36952
36953 EXPORT_SYMBOL(blk_register_region);
36954
36955 +/* undo blk_register_region(), noop if @range is zero */
36956 void blk_unregister_region(dev_t devt, unsigned long range)
36957 {
36958 - kobj_unmap(bdev_map, devt, range);
36959 + if (range)
36960 + kobj_unmap(bdev_map, devt, range);
36961 }
36962
36963 EXPORT_SYMBOL(blk_unregister_region);
36964 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36965 index 56d08fd..2e07090 100644
36966 --- a/block/partitions/efi.c
36967 +++ b/block/partitions/efi.c
36968 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36969 if (!gpt)
36970 return NULL;
36971
36972 + if (!le32_to_cpu(gpt->num_partition_entries))
36973 + return NULL;
36974 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36975 + if (!pte)
36976 + return NULL;
36977 +
36978 count = le32_to_cpu(gpt->num_partition_entries) *
36979 le32_to_cpu(gpt->sizeof_partition_entry);
36980 - if (!count)
36981 - return NULL;
36982 - pte = kmalloc(count, GFP_KERNEL);
36983 - if (!pte)
36984 - return NULL;
36985 -
36986 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36987 (u8 *) pte, count) < count) {
36988 kfree(pte);
36989 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36990 index a6d6270..c4bb72f 100644
36991 --- a/block/scsi_ioctl.c
36992 +++ b/block/scsi_ioctl.c
36993 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36994 return put_user(0, p);
36995 }
36996
36997 -static int sg_get_timeout(struct request_queue *q)
36998 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36999 {
37000 return jiffies_to_clock_t(q->sg_timeout);
37001 }
37002 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
37003 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37004 struct sg_io_hdr *hdr, fmode_t mode)
37005 {
37006 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37007 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37008 + unsigned char *cmdptr;
37009 +
37010 + if (rq->cmd != rq->__cmd)
37011 + cmdptr = rq->cmd;
37012 + else
37013 + cmdptr = tmpcmd;
37014 +
37015 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37016 return -EFAULT;
37017 +
37018 + if (cmdptr != rq->cmd)
37019 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37020 +
37021 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37022 return -EPERM;
37023
37024 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37025 int err;
37026 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37027 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37028 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37029 + unsigned char *cmdptr;
37030
37031 if (!sic)
37032 return -EINVAL;
37033 @@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37034 */
37035 err = -EFAULT;
37036 rq->cmd_len = cmdlen;
37037 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
37038 +
37039 + if (rq->cmd != rq->__cmd)
37040 + cmdptr = rq->cmd;
37041 + else
37042 + cmdptr = tmpcmd;
37043 +
37044 + if (copy_from_user(cmdptr, sic->data, cmdlen))
37045 goto error;
37046
37047 + if (rq->cmd != cmdptr)
37048 + memcpy(rq->cmd, cmdptr, cmdlen);
37049 +
37050 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
37051 goto error;
37052
37053 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
37054 index e592c90..c566114 100644
37055 --- a/crypto/cryptd.c
37056 +++ b/crypto/cryptd.c
37057 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
37058
37059 struct cryptd_blkcipher_request_ctx {
37060 crypto_completion_t complete;
37061 -};
37062 +} __no_const;
37063
37064 struct cryptd_hash_ctx {
37065 struct crypto_shash *child;
37066 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
37067
37068 struct cryptd_aead_request_ctx {
37069 crypto_completion_t complete;
37070 -};
37071 +} __no_const;
37072
37073 static void cryptd_queue_worker(struct work_struct *work);
37074
37075 diff --git a/crypto/cts.c b/crypto/cts.c
37076 index 042223f..133f087 100644
37077 --- a/crypto/cts.c
37078 +++ b/crypto/cts.c
37079 @@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37080 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37081 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37082 /* 6. Decrypt En to create Pn-1 */
37083 - memset(iv, 0, sizeof(iv));
37084 + memzero_explicit(iv, sizeof(iv));
37085 +
37086 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37087 sg_set_buf(&sgdst[0], d, bsize);
37088 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37089 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37090 index 309d345..1632720 100644
37091 --- a/crypto/pcrypt.c
37092 +++ b/crypto/pcrypt.c
37093 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37094 int ret;
37095
37096 pinst->kobj.kset = pcrypt_kset;
37097 - ret = kobject_add(&pinst->kobj, NULL, name);
37098 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37099 if (!ret)
37100 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37101
37102 diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37103 index 4279480..7bb0474 100644
37104 --- a/crypto/sha1_generic.c
37105 +++ b/crypto/sha1_generic.c
37106 @@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37107 src = data + done;
37108 } while (done + SHA1_BLOCK_SIZE <= len);
37109
37110 - memset(temp, 0, sizeof(temp));
37111 + memzero_explicit(temp, sizeof(temp));
37112 partial = 0;
37113 }
37114 memcpy(sctx->buffer + partial, src, len - done);
37115 diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37116 index 5433667..32c5e5e 100644
37117 --- a/crypto/sha256_generic.c
37118 +++ b/crypto/sha256_generic.c
37119 @@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37120
37121 /* clear any sensitive info... */
37122 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37123 - memset(W, 0, 64 * sizeof(u32));
37124 + memzero_explicit(W, 64 * sizeof(u32));
37125 }
37126
37127 -
37128 static int sha224_init(struct shash_desc *desc)
37129 {
37130 struct sha256_state *sctx = shash_desc_ctx(desc);
37131 @@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37132 sha256_final(desc, D);
37133
37134 memcpy(hash, D, SHA224_DIGEST_SIZE);
37135 - memset(D, 0, SHA256_DIGEST_SIZE);
37136 + memzero_explicit(D, SHA256_DIGEST_SIZE);
37137
37138 return 0;
37139 }
37140 diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37141 index 6ed124f..04d295a 100644
37142 --- a/crypto/sha512_generic.c
37143 +++ b/crypto/sha512_generic.c
37144 @@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37145 sha512_final(desc, D);
37146
37147 memcpy(hash, D, 48);
37148 - memset(D, 0, 64);
37149 + memzero_explicit(D, 64);
37150
37151 return 0;
37152 }
37153 diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37154 index 8740355..3c7af0d 100644
37155 --- a/crypto/tgr192.c
37156 +++ b/crypto/tgr192.c
37157 @@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37158
37159 tgr192_final(desc, D);
37160 memcpy(out, D, TGR160_DIGEST_SIZE);
37161 - memset(D, 0, TGR192_DIGEST_SIZE);
37162 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37163
37164 return 0;
37165 }
37166 @@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37167
37168 tgr192_final(desc, D);
37169 memcpy(out, D, TGR128_DIGEST_SIZE);
37170 - memset(D, 0, TGR192_DIGEST_SIZE);
37171 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37172
37173 return 0;
37174 }
37175 diff --git a/crypto/vmac.c b/crypto/vmac.c
37176 index 2eb11a3..d84c24b 100644
37177 --- a/crypto/vmac.c
37178 +++ b/crypto/vmac.c
37179 @@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37180 }
37181 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37182 memcpy(out, &mac, sizeof(vmac_t));
37183 - memset(&mac, 0, sizeof(vmac_t));
37184 + memzero_explicit(&mac, sizeof(vmac_t));
37185 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37186 ctx->partial_size = 0;
37187 return 0;
37188 diff --git a/crypto/wp512.c b/crypto/wp512.c
37189 index 180f1d6..ec64e77 100644
37190 --- a/crypto/wp512.c
37191 +++ b/crypto/wp512.c
37192 @@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37193 u8 D[64];
37194
37195 wp512_final(desc, D);
37196 - memcpy (out, D, WP384_DIGEST_SIZE);
37197 - memset (D, 0, WP512_DIGEST_SIZE);
37198 + memcpy(out, D, WP384_DIGEST_SIZE);
37199 + memzero_explicit(D, WP512_DIGEST_SIZE);
37200
37201 return 0;
37202 }
37203 @@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37204 u8 D[64];
37205
37206 wp512_final(desc, D);
37207 - memcpy (out, D, WP256_DIGEST_SIZE);
37208 - memset (D, 0, WP512_DIGEST_SIZE);
37209 + memcpy(out, D, WP256_DIGEST_SIZE);
37210 + memzero_explicit(D, WP512_DIGEST_SIZE);
37211
37212 return 0;
37213 }
37214 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37215 index 6921c7f..78e1af7 100644
37216 --- a/drivers/acpi/acpica/hwxfsleep.c
37217 +++ b/drivers/acpi/acpica/hwxfsleep.c
37218 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37219 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37220
37221 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37222 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37223 - acpi_hw_extended_sleep},
37224 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37225 - acpi_hw_extended_wake_prep},
37226 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37227 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37228 + .extended_function = acpi_hw_extended_sleep},
37229 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37230 + .extended_function = acpi_hw_extended_wake_prep},
37231 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37232 + .extended_function = acpi_hw_extended_wake}
37233 };
37234
37235 /*
37236 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37237 index 16129c7..8b675cd 100644
37238 --- a/drivers/acpi/apei/apei-internal.h
37239 +++ b/drivers/acpi/apei/apei-internal.h
37240 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37241 struct apei_exec_ins_type {
37242 u32 flags;
37243 apei_exec_ins_func_t run;
37244 -};
37245 +} __do_const;
37246
37247 struct apei_exec_context {
37248 u32 ip;
37249 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37250 index fc5f780..e5ac91a 100644
37251 --- a/drivers/acpi/apei/ghes.c
37252 +++ b/drivers/acpi/apei/ghes.c
37253 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37254 const struct acpi_hest_generic *generic,
37255 const struct acpi_hest_generic_status *estatus)
37256 {
37257 - static atomic_t seqno;
37258 + static atomic_unchecked_t seqno;
37259 unsigned int curr_seqno;
37260 char pfx_seq[64];
37261
37262 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37263 else
37264 pfx = KERN_ERR;
37265 }
37266 - curr_seqno = atomic_inc_return(&seqno);
37267 + curr_seqno = atomic_inc_return_unchecked(&seqno);
37268 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37269 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37270 pfx_seq, generic->header.source_id);
37271 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37272 index a83e3c6..c3d617f 100644
37273 --- a/drivers/acpi/bgrt.c
37274 +++ b/drivers/acpi/bgrt.c
37275 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37276 if (!bgrt_image)
37277 return -ENODEV;
37278
37279 - bin_attr_image.private = bgrt_image;
37280 - bin_attr_image.size = bgrt_image_size;
37281 + pax_open_kernel();
37282 + *(void **)&bin_attr_image.private = bgrt_image;
37283 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
37284 + pax_close_kernel();
37285
37286 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37287 if (!bgrt_kobj)
37288 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37289 index 36eb42e..3b2f47e 100644
37290 --- a/drivers/acpi/blacklist.c
37291 +++ b/drivers/acpi/blacklist.c
37292 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37293 u32 is_critical_error;
37294 };
37295
37296 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37297 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37298
37299 /*
37300 * POLICY: If *anything* doesn't work, put it on the blacklist.
37301 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37302 return 0;
37303 }
37304
37305 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37306 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37307 {
37308 .callback = dmi_disable_osi_vista,
37309 .ident = "Fujitsu Siemens",
37310 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37311 index c68e724..e863008 100644
37312 --- a/drivers/acpi/custom_method.c
37313 +++ b/drivers/acpi/custom_method.c
37314 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37315 struct acpi_table_header table;
37316 acpi_status status;
37317
37318 +#ifdef CONFIG_GRKERNSEC_KMEM
37319 + return -EPERM;
37320 +#endif
37321 +
37322 if (!(*ppos)) {
37323 /* parse the table header to get the table length */
37324 if (count <= sizeof(struct acpi_table_header))
37325 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37326 index 17f9ec5..d9a455e 100644
37327 --- a/drivers/acpi/processor_idle.c
37328 +++ b/drivers/acpi/processor_idle.c
37329 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37330 {
37331 int i, count = CPUIDLE_DRIVER_STATE_START;
37332 struct acpi_processor_cx *cx;
37333 - struct cpuidle_state *state;
37334 + cpuidle_state_no_const *state;
37335 struct cpuidle_driver *drv = &acpi_idle_driver;
37336
37337 if (!pr->flags.power_setup_done)
37338 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37339 index 38cb978..352c761 100644
37340 --- a/drivers/acpi/sysfs.c
37341 +++ b/drivers/acpi/sysfs.c
37342 @@ -423,11 +423,11 @@ static u32 num_counters;
37343 static struct attribute **all_attrs;
37344 static u32 acpi_gpe_count;
37345
37346 -static struct attribute_group interrupt_stats_attr_group = {
37347 +static attribute_group_no_const interrupt_stats_attr_group = {
37348 .name = "interrupts",
37349 };
37350
37351 -static struct kobj_attribute *counter_attrs;
37352 +static kobj_attribute_no_const *counter_attrs;
37353
37354 static void delete_gpe_attr_array(void)
37355 {
37356 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37357 index b784e9d..a69a049 100644
37358 --- a/drivers/ata/libahci.c
37359 +++ b/drivers/ata/libahci.c
37360 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37361 }
37362 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37363
37364 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37365 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37366 struct ata_taskfile *tf, int is_cmd, u16 flags,
37367 unsigned long timeout_msec)
37368 {
37369 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37370 index 6f67490..f951ead 100644
37371 --- a/drivers/ata/libata-core.c
37372 +++ b/drivers/ata/libata-core.c
37373 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37374 static void ata_dev_xfermask(struct ata_device *dev);
37375 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37376
37377 -atomic_t ata_print_id = ATOMIC_INIT(0);
37378 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37379
37380 struct ata_force_param {
37381 const char *name;
37382 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37383 struct ata_port *ap;
37384 unsigned int tag;
37385
37386 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37387 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37388 ap = qc->ap;
37389
37390 qc->flags = 0;
37391 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37392 struct ata_port *ap;
37393 struct ata_link *link;
37394
37395 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37396 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37397 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37398 ap = qc->ap;
37399 link = qc->dev->link;
37400 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37401 return;
37402
37403 spin_lock(&lock);
37404 + pax_open_kernel();
37405
37406 for (cur = ops->inherits; cur; cur = cur->inherits) {
37407 void **inherit = (void **)cur;
37408 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37409 if (IS_ERR(*pp))
37410 *pp = NULL;
37411
37412 - ops->inherits = NULL;
37413 + *(struct ata_port_operations **)&ops->inherits = NULL;
37414
37415 + pax_close_kernel();
37416 spin_unlock(&lock);
37417 }
37418
37419 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37420
37421 /* give ports names and add SCSI hosts */
37422 for (i = 0; i < host->n_ports; i++) {
37423 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37424 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37425 host->ports[i]->local_port_no = i + 1;
37426 }
37427
37428 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37429 index 0586f66..1a8f74a 100644
37430 --- a/drivers/ata/libata-scsi.c
37431 +++ b/drivers/ata/libata-scsi.c
37432 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37433
37434 if (rc)
37435 return rc;
37436 - ap->print_id = atomic_inc_return(&ata_print_id);
37437 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37438 return 0;
37439 }
37440 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37441 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37442 index 5f4e0cc..ff2c347 100644
37443 --- a/drivers/ata/libata.h
37444 +++ b/drivers/ata/libata.h
37445 @@ -53,7 +53,7 @@ enum {
37446 ATA_DNXFER_QUIET = (1 << 31),
37447 };
37448
37449 -extern atomic_t ata_print_id;
37450 +extern atomic_unchecked_t ata_print_id;
37451 extern int atapi_passthru16;
37452 extern int libata_fua;
37453 extern int libata_noacpi;
37454 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37455 index 4edb1a8..84e1658 100644
37456 --- a/drivers/ata/pata_arasan_cf.c
37457 +++ b/drivers/ata/pata_arasan_cf.c
37458 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37459 /* Handle platform specific quirks */
37460 if (quirk) {
37461 if (quirk & CF_BROKEN_PIO) {
37462 - ap->ops->set_piomode = NULL;
37463 + pax_open_kernel();
37464 + *(void **)&ap->ops->set_piomode = NULL;
37465 + pax_close_kernel();
37466 ap->pio_mask = 0;
37467 }
37468 if (quirk & CF_BROKEN_MWDMA)
37469 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37470 index f9b983a..887b9d8 100644
37471 --- a/drivers/atm/adummy.c
37472 +++ b/drivers/atm/adummy.c
37473 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37474 vcc->pop(vcc, skb);
37475 else
37476 dev_kfree_skb_any(skb);
37477 - atomic_inc(&vcc->stats->tx);
37478 + atomic_inc_unchecked(&vcc->stats->tx);
37479
37480 return 0;
37481 }
37482 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37483 index f1a9198..f466a4a 100644
37484 --- a/drivers/atm/ambassador.c
37485 +++ b/drivers/atm/ambassador.c
37486 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37487 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37488
37489 // VC layer stats
37490 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37491 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37492
37493 // free the descriptor
37494 kfree (tx_descr);
37495 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37496 dump_skb ("<<<", vc, skb);
37497
37498 // VC layer stats
37499 - atomic_inc(&atm_vcc->stats->rx);
37500 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37501 __net_timestamp(skb);
37502 // end of our responsibility
37503 atm_vcc->push (atm_vcc, skb);
37504 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37505 } else {
37506 PRINTK (KERN_INFO, "dropped over-size frame");
37507 // should we count this?
37508 - atomic_inc(&atm_vcc->stats->rx_drop);
37509 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37510 }
37511
37512 } else {
37513 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37514 }
37515
37516 if (check_area (skb->data, skb->len)) {
37517 - atomic_inc(&atm_vcc->stats->tx_err);
37518 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37519 return -ENOMEM; // ?
37520 }
37521
37522 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37523 index 480fa6f..947067c 100644
37524 --- a/drivers/atm/atmtcp.c
37525 +++ b/drivers/atm/atmtcp.c
37526 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37527 if (vcc->pop) vcc->pop(vcc,skb);
37528 else dev_kfree_skb(skb);
37529 if (dev_data) return 0;
37530 - atomic_inc(&vcc->stats->tx_err);
37531 + atomic_inc_unchecked(&vcc->stats->tx_err);
37532 return -ENOLINK;
37533 }
37534 size = skb->len+sizeof(struct atmtcp_hdr);
37535 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37536 if (!new_skb) {
37537 if (vcc->pop) vcc->pop(vcc,skb);
37538 else dev_kfree_skb(skb);
37539 - atomic_inc(&vcc->stats->tx_err);
37540 + atomic_inc_unchecked(&vcc->stats->tx_err);
37541 return -ENOBUFS;
37542 }
37543 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37544 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37545 if (vcc->pop) vcc->pop(vcc,skb);
37546 else dev_kfree_skb(skb);
37547 out_vcc->push(out_vcc,new_skb);
37548 - atomic_inc(&vcc->stats->tx);
37549 - atomic_inc(&out_vcc->stats->rx);
37550 + atomic_inc_unchecked(&vcc->stats->tx);
37551 + atomic_inc_unchecked(&out_vcc->stats->rx);
37552 return 0;
37553 }
37554
37555 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37556 read_unlock(&vcc_sklist_lock);
37557 if (!out_vcc) {
37558 result = -EUNATCH;
37559 - atomic_inc(&vcc->stats->tx_err);
37560 + atomic_inc_unchecked(&vcc->stats->tx_err);
37561 goto done;
37562 }
37563 skb_pull(skb,sizeof(struct atmtcp_hdr));
37564 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37565 __net_timestamp(new_skb);
37566 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37567 out_vcc->push(out_vcc,new_skb);
37568 - atomic_inc(&vcc->stats->tx);
37569 - atomic_inc(&out_vcc->stats->rx);
37570 + atomic_inc_unchecked(&vcc->stats->tx);
37571 + atomic_inc_unchecked(&out_vcc->stats->rx);
37572 done:
37573 if (vcc->pop) vcc->pop(vcc,skb);
37574 else dev_kfree_skb(skb);
37575 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37576 index d65975a..0b87e20 100644
37577 --- a/drivers/atm/eni.c
37578 +++ b/drivers/atm/eni.c
37579 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37580 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37581 vcc->dev->number);
37582 length = 0;
37583 - atomic_inc(&vcc->stats->rx_err);
37584 + atomic_inc_unchecked(&vcc->stats->rx_err);
37585 }
37586 else {
37587 length = ATM_CELL_SIZE-1; /* no HEC */
37588 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37589 size);
37590 }
37591 eff = length = 0;
37592 - atomic_inc(&vcc->stats->rx_err);
37593 + atomic_inc_unchecked(&vcc->stats->rx_err);
37594 }
37595 else {
37596 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37597 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37598 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37599 vcc->dev->number,vcc->vci,length,size << 2,descr);
37600 length = eff = 0;
37601 - atomic_inc(&vcc->stats->rx_err);
37602 + atomic_inc_unchecked(&vcc->stats->rx_err);
37603 }
37604 }
37605 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37606 @@ -767,7 +767,7 @@ rx_dequeued++;
37607 vcc->push(vcc,skb);
37608 pushed++;
37609 }
37610 - atomic_inc(&vcc->stats->rx);
37611 + atomic_inc_unchecked(&vcc->stats->rx);
37612 }
37613 wake_up(&eni_dev->rx_wait);
37614 }
37615 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37616 PCI_DMA_TODEVICE);
37617 if (vcc->pop) vcc->pop(vcc,skb);
37618 else dev_kfree_skb_irq(skb);
37619 - atomic_inc(&vcc->stats->tx);
37620 + atomic_inc_unchecked(&vcc->stats->tx);
37621 wake_up(&eni_dev->tx_wait);
37622 dma_complete++;
37623 }
37624 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37625 index 82f2ae0..f205c02 100644
37626 --- a/drivers/atm/firestream.c
37627 +++ b/drivers/atm/firestream.c
37628 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37629 }
37630 }
37631
37632 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37633 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37634
37635 fs_dprintk (FS_DEBUG_TXMEM, "i");
37636 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37637 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37638 #endif
37639 skb_put (skb, qe->p1 & 0xffff);
37640 ATM_SKB(skb)->vcc = atm_vcc;
37641 - atomic_inc(&atm_vcc->stats->rx);
37642 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37643 __net_timestamp(skb);
37644 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37645 atm_vcc->push (atm_vcc, skb);
37646 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37647 kfree (pe);
37648 }
37649 if (atm_vcc)
37650 - atomic_inc(&atm_vcc->stats->rx_drop);
37651 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37652 break;
37653 case 0x1f: /* Reassembly abort: no buffers. */
37654 /* Silently increment error counter. */
37655 if (atm_vcc)
37656 - atomic_inc(&atm_vcc->stats->rx_drop);
37657 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37658 break;
37659 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37660 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37661 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37662 index d4725fc..2d4ea65 100644
37663 --- a/drivers/atm/fore200e.c
37664 +++ b/drivers/atm/fore200e.c
37665 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37666 #endif
37667 /* check error condition */
37668 if (*entry->status & STATUS_ERROR)
37669 - atomic_inc(&vcc->stats->tx_err);
37670 + atomic_inc_unchecked(&vcc->stats->tx_err);
37671 else
37672 - atomic_inc(&vcc->stats->tx);
37673 + atomic_inc_unchecked(&vcc->stats->tx);
37674 }
37675 }
37676
37677 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37678 if (skb == NULL) {
37679 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37680
37681 - atomic_inc(&vcc->stats->rx_drop);
37682 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37683 return -ENOMEM;
37684 }
37685
37686 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37687
37688 dev_kfree_skb_any(skb);
37689
37690 - atomic_inc(&vcc->stats->rx_drop);
37691 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37692 return -ENOMEM;
37693 }
37694
37695 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37696
37697 vcc->push(vcc, skb);
37698 - atomic_inc(&vcc->stats->rx);
37699 + atomic_inc_unchecked(&vcc->stats->rx);
37700
37701 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37702
37703 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37704 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37705 fore200e->atm_dev->number,
37706 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37707 - atomic_inc(&vcc->stats->rx_err);
37708 + atomic_inc_unchecked(&vcc->stats->rx_err);
37709 }
37710 }
37711
37712 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37713 goto retry_here;
37714 }
37715
37716 - atomic_inc(&vcc->stats->tx_err);
37717 + atomic_inc_unchecked(&vcc->stats->tx_err);
37718
37719 fore200e->tx_sat++;
37720 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37721 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37722 index c39702b..785b73b 100644
37723 --- a/drivers/atm/he.c
37724 +++ b/drivers/atm/he.c
37725 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37726
37727 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37728 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37729 - atomic_inc(&vcc->stats->rx_drop);
37730 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37731 goto return_host_buffers;
37732 }
37733
37734 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37735 RBRQ_LEN_ERR(he_dev->rbrq_head)
37736 ? "LEN_ERR" : "",
37737 vcc->vpi, vcc->vci);
37738 - atomic_inc(&vcc->stats->rx_err);
37739 + atomic_inc_unchecked(&vcc->stats->rx_err);
37740 goto return_host_buffers;
37741 }
37742
37743 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37744 vcc->push(vcc, skb);
37745 spin_lock(&he_dev->global_lock);
37746
37747 - atomic_inc(&vcc->stats->rx);
37748 + atomic_inc_unchecked(&vcc->stats->rx);
37749
37750 return_host_buffers:
37751 ++pdus_assembled;
37752 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37753 tpd->vcc->pop(tpd->vcc, tpd->skb);
37754 else
37755 dev_kfree_skb_any(tpd->skb);
37756 - atomic_inc(&tpd->vcc->stats->tx_err);
37757 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37758 }
37759 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37760 return;
37761 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37762 vcc->pop(vcc, skb);
37763 else
37764 dev_kfree_skb_any(skb);
37765 - atomic_inc(&vcc->stats->tx_err);
37766 + atomic_inc_unchecked(&vcc->stats->tx_err);
37767 return -EINVAL;
37768 }
37769
37770 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37771 vcc->pop(vcc, skb);
37772 else
37773 dev_kfree_skb_any(skb);
37774 - atomic_inc(&vcc->stats->tx_err);
37775 + atomic_inc_unchecked(&vcc->stats->tx_err);
37776 return -EINVAL;
37777 }
37778 #endif
37779 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37780 vcc->pop(vcc, skb);
37781 else
37782 dev_kfree_skb_any(skb);
37783 - atomic_inc(&vcc->stats->tx_err);
37784 + atomic_inc_unchecked(&vcc->stats->tx_err);
37785 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37786 return -ENOMEM;
37787 }
37788 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37789 vcc->pop(vcc, skb);
37790 else
37791 dev_kfree_skb_any(skb);
37792 - atomic_inc(&vcc->stats->tx_err);
37793 + atomic_inc_unchecked(&vcc->stats->tx_err);
37794 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37795 return -ENOMEM;
37796 }
37797 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37798 __enqueue_tpd(he_dev, tpd, cid);
37799 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37800
37801 - atomic_inc(&vcc->stats->tx);
37802 + atomic_inc_unchecked(&vcc->stats->tx);
37803
37804 return 0;
37805 }
37806 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37807 index 1dc0519..1aadaf7 100644
37808 --- a/drivers/atm/horizon.c
37809 +++ b/drivers/atm/horizon.c
37810 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37811 {
37812 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37813 // VC layer stats
37814 - atomic_inc(&vcc->stats->rx);
37815 + atomic_inc_unchecked(&vcc->stats->rx);
37816 __net_timestamp(skb);
37817 // end of our responsibility
37818 vcc->push (vcc, skb);
37819 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37820 dev->tx_iovec = NULL;
37821
37822 // VC layer stats
37823 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37824 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37825
37826 // free the skb
37827 hrz_kfree_skb (skb);
37828 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37829 index 2b24ed0..b3d6acc 100644
37830 --- a/drivers/atm/idt77252.c
37831 +++ b/drivers/atm/idt77252.c
37832 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37833 else
37834 dev_kfree_skb(skb);
37835
37836 - atomic_inc(&vcc->stats->tx);
37837 + atomic_inc_unchecked(&vcc->stats->tx);
37838 }
37839
37840 atomic_dec(&scq->used);
37841 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37842 if ((sb = dev_alloc_skb(64)) == NULL) {
37843 printk("%s: Can't allocate buffers for aal0.\n",
37844 card->name);
37845 - atomic_add(i, &vcc->stats->rx_drop);
37846 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37847 break;
37848 }
37849 if (!atm_charge(vcc, sb->truesize)) {
37850 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37851 card->name);
37852 - atomic_add(i - 1, &vcc->stats->rx_drop);
37853 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37854 dev_kfree_skb(sb);
37855 break;
37856 }
37857 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37858 ATM_SKB(sb)->vcc = vcc;
37859 __net_timestamp(sb);
37860 vcc->push(vcc, sb);
37861 - atomic_inc(&vcc->stats->rx);
37862 + atomic_inc_unchecked(&vcc->stats->rx);
37863
37864 cell += ATM_CELL_PAYLOAD;
37865 }
37866 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37867 "(CDC: %08x)\n",
37868 card->name, len, rpp->len, readl(SAR_REG_CDC));
37869 recycle_rx_pool_skb(card, rpp);
37870 - atomic_inc(&vcc->stats->rx_err);
37871 + atomic_inc_unchecked(&vcc->stats->rx_err);
37872 return;
37873 }
37874 if (stat & SAR_RSQE_CRC) {
37875 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37876 recycle_rx_pool_skb(card, rpp);
37877 - atomic_inc(&vcc->stats->rx_err);
37878 + atomic_inc_unchecked(&vcc->stats->rx_err);
37879 return;
37880 }
37881 if (skb_queue_len(&rpp->queue) > 1) {
37882 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37883 RXPRINTK("%s: Can't alloc RX skb.\n",
37884 card->name);
37885 recycle_rx_pool_skb(card, rpp);
37886 - atomic_inc(&vcc->stats->rx_err);
37887 + atomic_inc_unchecked(&vcc->stats->rx_err);
37888 return;
37889 }
37890 if (!atm_charge(vcc, skb->truesize)) {
37891 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37892 __net_timestamp(skb);
37893
37894 vcc->push(vcc, skb);
37895 - atomic_inc(&vcc->stats->rx);
37896 + atomic_inc_unchecked(&vcc->stats->rx);
37897
37898 return;
37899 }
37900 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37901 __net_timestamp(skb);
37902
37903 vcc->push(vcc, skb);
37904 - atomic_inc(&vcc->stats->rx);
37905 + atomic_inc_unchecked(&vcc->stats->rx);
37906
37907 if (skb->truesize > SAR_FB_SIZE_3)
37908 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37909 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37910 if (vcc->qos.aal != ATM_AAL0) {
37911 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37912 card->name, vpi, vci);
37913 - atomic_inc(&vcc->stats->rx_drop);
37914 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37915 goto drop;
37916 }
37917
37918 if ((sb = dev_alloc_skb(64)) == NULL) {
37919 printk("%s: Can't allocate buffers for AAL0.\n",
37920 card->name);
37921 - atomic_inc(&vcc->stats->rx_err);
37922 + atomic_inc_unchecked(&vcc->stats->rx_err);
37923 goto drop;
37924 }
37925
37926 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37927 ATM_SKB(sb)->vcc = vcc;
37928 __net_timestamp(sb);
37929 vcc->push(vcc, sb);
37930 - atomic_inc(&vcc->stats->rx);
37931 + atomic_inc_unchecked(&vcc->stats->rx);
37932
37933 drop:
37934 skb_pull(queue, 64);
37935 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37936
37937 if (vc == NULL) {
37938 printk("%s: NULL connection in send().\n", card->name);
37939 - atomic_inc(&vcc->stats->tx_err);
37940 + atomic_inc_unchecked(&vcc->stats->tx_err);
37941 dev_kfree_skb(skb);
37942 return -EINVAL;
37943 }
37944 if (!test_bit(VCF_TX, &vc->flags)) {
37945 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37946 - atomic_inc(&vcc->stats->tx_err);
37947 + atomic_inc_unchecked(&vcc->stats->tx_err);
37948 dev_kfree_skb(skb);
37949 return -EINVAL;
37950 }
37951 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37952 break;
37953 default:
37954 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37955 - atomic_inc(&vcc->stats->tx_err);
37956 + atomic_inc_unchecked(&vcc->stats->tx_err);
37957 dev_kfree_skb(skb);
37958 return -EINVAL;
37959 }
37960
37961 if (skb_shinfo(skb)->nr_frags != 0) {
37962 printk("%s: No scatter-gather yet.\n", card->name);
37963 - atomic_inc(&vcc->stats->tx_err);
37964 + atomic_inc_unchecked(&vcc->stats->tx_err);
37965 dev_kfree_skb(skb);
37966 return -EINVAL;
37967 }
37968 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37969
37970 err = queue_skb(card, vc, skb, oam);
37971 if (err) {
37972 - atomic_inc(&vcc->stats->tx_err);
37973 + atomic_inc_unchecked(&vcc->stats->tx_err);
37974 dev_kfree_skb(skb);
37975 return err;
37976 }
37977 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37978 skb = dev_alloc_skb(64);
37979 if (!skb) {
37980 printk("%s: Out of memory in send_oam().\n", card->name);
37981 - atomic_inc(&vcc->stats->tx_err);
37982 + atomic_inc_unchecked(&vcc->stats->tx_err);
37983 return -ENOMEM;
37984 }
37985 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37986 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37987 index 4217f29..88f547a 100644
37988 --- a/drivers/atm/iphase.c
37989 +++ b/drivers/atm/iphase.c
37990 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37991 status = (u_short) (buf_desc_ptr->desc_mode);
37992 if (status & (RX_CER | RX_PTE | RX_OFL))
37993 {
37994 - atomic_inc(&vcc->stats->rx_err);
37995 + atomic_inc_unchecked(&vcc->stats->rx_err);
37996 IF_ERR(printk("IA: bad packet, dropping it");)
37997 if (status & RX_CER) {
37998 IF_ERR(printk(" cause: packet CRC error\n");)
37999 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38000 len = dma_addr - buf_addr;
38001 if (len > iadev->rx_buf_sz) {
38002 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38003 - atomic_inc(&vcc->stats->rx_err);
38004 + atomic_inc_unchecked(&vcc->stats->rx_err);
38005 goto out_free_desc;
38006 }
38007
38008 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38009 ia_vcc = INPH_IA_VCC(vcc);
38010 if (ia_vcc == NULL)
38011 {
38012 - atomic_inc(&vcc->stats->rx_err);
38013 + atomic_inc_unchecked(&vcc->stats->rx_err);
38014 atm_return(vcc, skb->truesize);
38015 dev_kfree_skb_any(skb);
38016 goto INCR_DLE;
38017 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38018 if ((length > iadev->rx_buf_sz) || (length >
38019 (skb->len - sizeof(struct cpcs_trailer))))
38020 {
38021 - atomic_inc(&vcc->stats->rx_err);
38022 + atomic_inc_unchecked(&vcc->stats->rx_err);
38023 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38024 length, skb->len);)
38025 atm_return(vcc, skb->truesize);
38026 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38027
38028 IF_RX(printk("rx_dle_intr: skb push");)
38029 vcc->push(vcc,skb);
38030 - atomic_inc(&vcc->stats->rx);
38031 + atomic_inc_unchecked(&vcc->stats->rx);
38032 iadev->rx_pkt_cnt++;
38033 }
38034 INCR_DLE:
38035 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38036 {
38037 struct k_sonet_stats *stats;
38038 stats = &PRIV(_ia_dev[board])->sonet_stats;
38039 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38040 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38041 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38042 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38043 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38044 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38045 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38046 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38047 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38048 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38049 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38050 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38051 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38052 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38053 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38054 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38055 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38056 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38057 }
38058 ia_cmds.status = 0;
38059 break;
38060 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38061 if ((desc == 0) || (desc > iadev->num_tx_desc))
38062 {
38063 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38064 - atomic_inc(&vcc->stats->tx);
38065 + atomic_inc_unchecked(&vcc->stats->tx);
38066 if (vcc->pop)
38067 vcc->pop(vcc, skb);
38068 else
38069 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38070 ATM_DESC(skb) = vcc->vci;
38071 skb_queue_tail(&iadev->tx_dma_q, skb);
38072
38073 - atomic_inc(&vcc->stats->tx);
38074 + atomic_inc_unchecked(&vcc->stats->tx);
38075 iadev->tx_pkt_cnt++;
38076 /* Increment transaction counter */
38077 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38078
38079 #if 0
38080 /* add flow control logic */
38081 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38082 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38083 if (iavcc->vc_desc_cnt > 10) {
38084 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38085 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38086 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38087 index fa7d7019..1e404c7 100644
38088 --- a/drivers/atm/lanai.c
38089 +++ b/drivers/atm/lanai.c
38090 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38091 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38092 lanai_endtx(lanai, lvcc);
38093 lanai_free_skb(lvcc->tx.atmvcc, skb);
38094 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38095 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38096 }
38097
38098 /* Try to fill the buffer - don't call unless there is backlog */
38099 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38100 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38101 __net_timestamp(skb);
38102 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38103 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38104 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38105 out:
38106 lvcc->rx.buf.ptr = end;
38107 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38108 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38109 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38110 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38111 lanai->stats.service_rxnotaal5++;
38112 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38113 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38114 return 0;
38115 }
38116 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38117 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38118 int bytes;
38119 read_unlock(&vcc_sklist_lock);
38120 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38121 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38122 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38123 lvcc->stats.x.aal5.service_trash++;
38124 bytes = (SERVICE_GET_END(s) * 16) -
38125 (((unsigned long) lvcc->rx.buf.ptr) -
38126 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38127 }
38128 if (s & SERVICE_STREAM) {
38129 read_unlock(&vcc_sklist_lock);
38130 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38131 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38132 lvcc->stats.x.aal5.service_stream++;
38133 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38134 "PDU on VCI %d!\n", lanai->number, vci);
38135 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38136 return 0;
38137 }
38138 DPRINTK("got rx crc error on vci %d\n", vci);
38139 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38140 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38141 lvcc->stats.x.aal5.service_rxcrc++;
38142 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38143 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38144 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38145 index 9988ac9..7c52585 100644
38146 --- a/drivers/atm/nicstar.c
38147 +++ b/drivers/atm/nicstar.c
38148 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38149 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38150 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38151 card->index);
38152 - atomic_inc(&vcc->stats->tx_err);
38153 + atomic_inc_unchecked(&vcc->stats->tx_err);
38154 dev_kfree_skb_any(skb);
38155 return -EINVAL;
38156 }
38157 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38158 if (!vc->tx) {
38159 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38160 card->index);
38161 - atomic_inc(&vcc->stats->tx_err);
38162 + atomic_inc_unchecked(&vcc->stats->tx_err);
38163 dev_kfree_skb_any(skb);
38164 return -EINVAL;
38165 }
38166 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38167 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38168 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38169 card->index);
38170 - atomic_inc(&vcc->stats->tx_err);
38171 + atomic_inc_unchecked(&vcc->stats->tx_err);
38172 dev_kfree_skb_any(skb);
38173 return -EINVAL;
38174 }
38175
38176 if (skb_shinfo(skb)->nr_frags != 0) {
38177 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38178 - atomic_inc(&vcc->stats->tx_err);
38179 + atomic_inc_unchecked(&vcc->stats->tx_err);
38180 dev_kfree_skb_any(skb);
38181 return -EINVAL;
38182 }
38183 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38184 }
38185
38186 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38187 - atomic_inc(&vcc->stats->tx_err);
38188 + atomic_inc_unchecked(&vcc->stats->tx_err);
38189 dev_kfree_skb_any(skb);
38190 return -EIO;
38191 }
38192 - atomic_inc(&vcc->stats->tx);
38193 + atomic_inc_unchecked(&vcc->stats->tx);
38194
38195 return 0;
38196 }
38197 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38198 printk
38199 ("nicstar%d: Can't allocate buffers for aal0.\n",
38200 card->index);
38201 - atomic_add(i, &vcc->stats->rx_drop);
38202 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38203 break;
38204 }
38205 if (!atm_charge(vcc, sb->truesize)) {
38206 RXPRINTK
38207 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38208 card->index);
38209 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38210 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38211 dev_kfree_skb_any(sb);
38212 break;
38213 }
38214 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38215 ATM_SKB(sb)->vcc = vcc;
38216 __net_timestamp(sb);
38217 vcc->push(vcc, sb);
38218 - atomic_inc(&vcc->stats->rx);
38219 + atomic_inc_unchecked(&vcc->stats->rx);
38220 cell += ATM_CELL_PAYLOAD;
38221 }
38222
38223 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38224 if (iovb == NULL) {
38225 printk("nicstar%d: Out of iovec buffers.\n",
38226 card->index);
38227 - atomic_inc(&vcc->stats->rx_drop);
38228 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38229 recycle_rx_buf(card, skb);
38230 return;
38231 }
38232 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38233 small or large buffer itself. */
38234 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38235 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38236 - atomic_inc(&vcc->stats->rx_err);
38237 + atomic_inc_unchecked(&vcc->stats->rx_err);
38238 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38239 NS_MAX_IOVECS);
38240 NS_PRV_IOVCNT(iovb) = 0;
38241 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38242 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38243 card->index);
38244 which_list(card, skb);
38245 - atomic_inc(&vcc->stats->rx_err);
38246 + atomic_inc_unchecked(&vcc->stats->rx_err);
38247 recycle_rx_buf(card, skb);
38248 vc->rx_iov = NULL;
38249 recycle_iov_buf(card, iovb);
38250 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38251 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38252 card->index);
38253 which_list(card, skb);
38254 - atomic_inc(&vcc->stats->rx_err);
38255 + atomic_inc_unchecked(&vcc->stats->rx_err);
38256 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38257 NS_PRV_IOVCNT(iovb));
38258 vc->rx_iov = NULL;
38259 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38260 printk(" - PDU size mismatch.\n");
38261 else
38262 printk(".\n");
38263 - atomic_inc(&vcc->stats->rx_err);
38264 + atomic_inc_unchecked(&vcc->stats->rx_err);
38265 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38266 NS_PRV_IOVCNT(iovb));
38267 vc->rx_iov = NULL;
38268 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38269 /* skb points to a small buffer */
38270 if (!atm_charge(vcc, skb->truesize)) {
38271 push_rxbufs(card, skb);
38272 - atomic_inc(&vcc->stats->rx_drop);
38273 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38274 } else {
38275 skb_put(skb, len);
38276 dequeue_sm_buf(card, skb);
38277 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38278 ATM_SKB(skb)->vcc = vcc;
38279 __net_timestamp(skb);
38280 vcc->push(vcc, skb);
38281 - atomic_inc(&vcc->stats->rx);
38282 + atomic_inc_unchecked(&vcc->stats->rx);
38283 }
38284 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38285 struct sk_buff *sb;
38286 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38287 if (len <= NS_SMBUFSIZE) {
38288 if (!atm_charge(vcc, sb->truesize)) {
38289 push_rxbufs(card, sb);
38290 - atomic_inc(&vcc->stats->rx_drop);
38291 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38292 } else {
38293 skb_put(sb, len);
38294 dequeue_sm_buf(card, sb);
38295 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38296 ATM_SKB(sb)->vcc = vcc;
38297 __net_timestamp(sb);
38298 vcc->push(vcc, sb);
38299 - atomic_inc(&vcc->stats->rx);
38300 + atomic_inc_unchecked(&vcc->stats->rx);
38301 }
38302
38303 push_rxbufs(card, skb);
38304 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38305
38306 if (!atm_charge(vcc, skb->truesize)) {
38307 push_rxbufs(card, skb);
38308 - atomic_inc(&vcc->stats->rx_drop);
38309 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38310 } else {
38311 dequeue_lg_buf(card, skb);
38312 #ifdef NS_USE_DESTRUCTORS
38313 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38314 ATM_SKB(skb)->vcc = vcc;
38315 __net_timestamp(skb);
38316 vcc->push(vcc, skb);
38317 - atomic_inc(&vcc->stats->rx);
38318 + atomic_inc_unchecked(&vcc->stats->rx);
38319 }
38320
38321 push_rxbufs(card, sb);
38322 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38323 printk
38324 ("nicstar%d: Out of huge buffers.\n",
38325 card->index);
38326 - atomic_inc(&vcc->stats->rx_drop);
38327 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38328 recycle_iovec_rx_bufs(card,
38329 (struct iovec *)
38330 iovb->data,
38331 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38332 card->hbpool.count++;
38333 } else
38334 dev_kfree_skb_any(hb);
38335 - atomic_inc(&vcc->stats->rx_drop);
38336 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38337 } else {
38338 /* Copy the small buffer to the huge buffer */
38339 sb = (struct sk_buff *)iov->iov_base;
38340 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38341 #endif /* NS_USE_DESTRUCTORS */
38342 __net_timestamp(hb);
38343 vcc->push(vcc, hb);
38344 - atomic_inc(&vcc->stats->rx);
38345 + atomic_inc_unchecked(&vcc->stats->rx);
38346 }
38347 }
38348
38349 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38350 index 7652e8d..db45069 100644
38351 --- a/drivers/atm/solos-pci.c
38352 +++ b/drivers/atm/solos-pci.c
38353 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38354 }
38355 atm_charge(vcc, skb->truesize);
38356 vcc->push(vcc, skb);
38357 - atomic_inc(&vcc->stats->rx);
38358 + atomic_inc_unchecked(&vcc->stats->rx);
38359 break;
38360
38361 case PKT_STATUS:
38362 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38363 vcc = SKB_CB(oldskb)->vcc;
38364
38365 if (vcc) {
38366 - atomic_inc(&vcc->stats->tx);
38367 + atomic_inc_unchecked(&vcc->stats->tx);
38368 solos_pop(vcc, oldskb);
38369 } else {
38370 dev_kfree_skb_irq(oldskb);
38371 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38372 index 0215934..ce9f5b1 100644
38373 --- a/drivers/atm/suni.c
38374 +++ b/drivers/atm/suni.c
38375 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38376
38377
38378 #define ADD_LIMITED(s,v) \
38379 - atomic_add((v),&stats->s); \
38380 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38381 + atomic_add_unchecked((v),&stats->s); \
38382 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38383
38384
38385 static void suni_hz(unsigned long from_timer)
38386 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38387 index 5120a96..e2572bd 100644
38388 --- a/drivers/atm/uPD98402.c
38389 +++ b/drivers/atm/uPD98402.c
38390 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38391 struct sonet_stats tmp;
38392 int error = 0;
38393
38394 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38395 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38396 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38397 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38398 if (zero && !error) {
38399 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38400
38401
38402 #define ADD_LIMITED(s,v) \
38403 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38404 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38405 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38406 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38407 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38408 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38409
38410
38411 static void stat_event(struct atm_dev *dev)
38412 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38413 if (reason & uPD98402_INT_PFM) stat_event(dev);
38414 if (reason & uPD98402_INT_PCO) {
38415 (void) GET(PCOCR); /* clear interrupt cause */
38416 - atomic_add(GET(HECCT),
38417 + atomic_add_unchecked(GET(HECCT),
38418 &PRIV(dev)->sonet_stats.uncorr_hcs);
38419 }
38420 if ((reason & uPD98402_INT_RFO) &&
38421 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38422 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38423 uPD98402_INT_LOS),PIMR); /* enable them */
38424 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38425 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38426 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38427 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38428 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38429 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38430 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38431 return 0;
38432 }
38433
38434 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38435 index 969c3c2..9b72956 100644
38436 --- a/drivers/atm/zatm.c
38437 +++ b/drivers/atm/zatm.c
38438 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38439 }
38440 if (!size) {
38441 dev_kfree_skb_irq(skb);
38442 - if (vcc) atomic_inc(&vcc->stats->rx_err);
38443 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38444 continue;
38445 }
38446 if (!atm_charge(vcc,skb->truesize)) {
38447 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38448 skb->len = size;
38449 ATM_SKB(skb)->vcc = vcc;
38450 vcc->push(vcc,skb);
38451 - atomic_inc(&vcc->stats->rx);
38452 + atomic_inc_unchecked(&vcc->stats->rx);
38453 }
38454 zout(pos & 0xffff,MTA(mbx));
38455 #if 0 /* probably a stupid idea */
38456 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38457 skb_queue_head(&zatm_vcc->backlog,skb);
38458 break;
38459 }
38460 - atomic_inc(&vcc->stats->tx);
38461 + atomic_inc_unchecked(&vcc->stats->tx);
38462 wake_up(&zatm_vcc->tx_wait);
38463 }
38464
38465 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38466 index 83e910a..b224a73 100644
38467 --- a/drivers/base/bus.c
38468 +++ b/drivers/base/bus.c
38469 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38470 return -EINVAL;
38471
38472 mutex_lock(&subsys->p->mutex);
38473 - list_add_tail(&sif->node, &subsys->p->interfaces);
38474 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38475 if (sif->add_dev) {
38476 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38477 while ((dev = subsys_dev_iter_next(&iter)))
38478 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38479 subsys = sif->subsys;
38480
38481 mutex_lock(&subsys->p->mutex);
38482 - list_del_init(&sif->node);
38483 + pax_list_del_init((struct list_head *)&sif->node);
38484 if (sif->remove_dev) {
38485 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38486 while ((dev = subsys_dev_iter_next(&iter)))
38487 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38488 index 25798db..15f130e 100644
38489 --- a/drivers/base/devtmpfs.c
38490 +++ b/drivers/base/devtmpfs.c
38491 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38492 if (!thread)
38493 return 0;
38494
38495 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38496 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38497 if (err)
38498 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38499 else
38500 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38501 *err = sys_unshare(CLONE_NEWNS);
38502 if (*err)
38503 goto out;
38504 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38505 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38506 if (*err)
38507 goto out;
38508 - sys_chdir("/.."); /* will traverse into overmounted root */
38509 - sys_chroot(".");
38510 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38511 + sys_chroot((char __force_user *)".");
38512 complete(&setup_done);
38513 while (1) {
38514 spin_lock(&req_lock);
38515 diff --git a/drivers/base/node.c b/drivers/base/node.c
38516 index d51c49c..28908df 100644
38517 --- a/drivers/base/node.c
38518 +++ b/drivers/base/node.c
38519 @@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38520 struct node_attr {
38521 struct device_attribute attr;
38522 enum node_states state;
38523 -};
38524 +} __do_const;
38525
38526 static ssize_t show_node_state(struct device *dev,
38527 struct device_attribute *attr, char *buf)
38528 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38529 index eee55c1..b8c9393 100644
38530 --- a/drivers/base/power/domain.c
38531 +++ b/drivers/base/power/domain.c
38532 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38533
38534 if (dev->power.subsys_data->domain_data) {
38535 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38536 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
38537 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38538 if (clear_td)
38539 - gpd_data->td = (struct gpd_timing_data){ 0 };
38540 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38541
38542 if (--gpd_data->refcount == 0) {
38543 dev->power.subsys_data->domain_data = NULL;
38544 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38545 {
38546 struct cpuidle_driver *cpuidle_drv;
38547 struct gpd_cpu_data *cpu_data;
38548 - struct cpuidle_state *idle_state;
38549 + cpuidle_state_no_const *idle_state;
38550 int ret = 0;
38551
38552 if (IS_ERR_OR_NULL(genpd) || state < 0)
38553 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38554 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38555 {
38556 struct gpd_cpu_data *cpu_data;
38557 - struct cpuidle_state *idle_state;
38558 + cpuidle_state_no_const *idle_state;
38559 int ret = 0;
38560
38561 if (IS_ERR_OR_NULL(genpd))
38562 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38563 index 95b181d1..c4f0e19 100644
38564 --- a/drivers/base/power/sysfs.c
38565 +++ b/drivers/base/power/sysfs.c
38566 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38567 return -EIO;
38568 }
38569 }
38570 - return sprintf(buf, p);
38571 + return sprintf(buf, "%s", p);
38572 }
38573
38574 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38575 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38576 index eb1bd2e..2667d3a 100644
38577 --- a/drivers/base/power/wakeup.c
38578 +++ b/drivers/base/power/wakeup.c
38579 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38580 * They need to be modified together atomically, so it's better to use one
38581 * atomic variable to hold them both.
38582 */
38583 -static atomic_t combined_event_count = ATOMIC_INIT(0);
38584 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38585
38586 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38587 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38588
38589 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38590 {
38591 - unsigned int comb = atomic_read(&combined_event_count);
38592 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
38593
38594 *cnt = (comb >> IN_PROGRESS_BITS);
38595 *inpr = comb & MAX_IN_PROGRESS;
38596 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38597 ws->start_prevent_time = ws->last_time;
38598
38599 /* Increment the counter of events in progress. */
38600 - cec = atomic_inc_return(&combined_event_count);
38601 + cec = atomic_inc_return_unchecked(&combined_event_count);
38602
38603 trace_wakeup_source_activate(ws->name, cec);
38604 }
38605 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38606 * Increment the counter of registered wakeup events and decrement the
38607 * couter of wakeup events in progress simultaneously.
38608 */
38609 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38610 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38611 trace_wakeup_source_deactivate(ws->name, cec);
38612
38613 split_counters(&cnt, &inpr);
38614 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38615 index dbb8350..4762f4c 100644
38616 --- a/drivers/base/syscore.c
38617 +++ b/drivers/base/syscore.c
38618 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38619 void register_syscore_ops(struct syscore_ops *ops)
38620 {
38621 mutex_lock(&syscore_ops_lock);
38622 - list_add_tail(&ops->node, &syscore_ops_list);
38623 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38624 mutex_unlock(&syscore_ops_lock);
38625 }
38626 EXPORT_SYMBOL_GPL(register_syscore_ops);
38627 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38628 void unregister_syscore_ops(struct syscore_ops *ops)
38629 {
38630 mutex_lock(&syscore_ops_lock);
38631 - list_del(&ops->node);
38632 + pax_list_del((struct list_head *)&ops->node);
38633 mutex_unlock(&syscore_ops_lock);
38634 }
38635 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38636 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38637 index ff20f19..018f1da 100644
38638 --- a/drivers/block/cciss.c
38639 +++ b/drivers/block/cciss.c
38640 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38641 while (!list_empty(&h->reqQ)) {
38642 c = list_entry(h->reqQ.next, CommandList_struct, list);
38643 /* can't do anything if fifo is full */
38644 - if ((h->access.fifo_full(h))) {
38645 + if ((h->access->fifo_full(h))) {
38646 dev_warn(&h->pdev->dev, "fifo full\n");
38647 break;
38648 }
38649 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38650 h->Qdepth--;
38651
38652 /* Tell the controller execute command */
38653 - h->access.submit_command(h, c);
38654 + h->access->submit_command(h, c);
38655
38656 /* Put job onto the completed Q */
38657 addQ(&h->cmpQ, c);
38658 @@ -3444,17 +3444,17 @@ startio:
38659
38660 static inline unsigned long get_next_completion(ctlr_info_t *h)
38661 {
38662 - return h->access.command_completed(h);
38663 + return h->access->command_completed(h);
38664 }
38665
38666 static inline int interrupt_pending(ctlr_info_t *h)
38667 {
38668 - return h->access.intr_pending(h);
38669 + return h->access->intr_pending(h);
38670 }
38671
38672 static inline long interrupt_not_for_us(ctlr_info_t *h)
38673 {
38674 - return ((h->access.intr_pending(h) == 0) ||
38675 + return ((h->access->intr_pending(h) == 0) ||
38676 (h->interrupts_enabled == 0));
38677 }
38678
38679 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38680 u32 a;
38681
38682 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38683 - return h->access.command_completed(h);
38684 + return h->access->command_completed(h);
38685
38686 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38687 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38688 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38689 trans_support & CFGTBL_Trans_use_short_tags);
38690
38691 /* Change the access methods to the performant access methods */
38692 - h->access = SA5_performant_access;
38693 + h->access = &SA5_performant_access;
38694 h->transMethod = CFGTBL_Trans_Performant;
38695
38696 return;
38697 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38698 if (prod_index < 0)
38699 return -ENODEV;
38700 h->product_name = products[prod_index].product_name;
38701 - h->access = *(products[prod_index].access);
38702 + h->access = products[prod_index].access;
38703
38704 if (cciss_board_disabled(h)) {
38705 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38706 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38707 }
38708
38709 /* make sure the board interrupts are off */
38710 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38711 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38712 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38713 if (rc)
38714 goto clean2;
38715 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38716 * fake ones to scoop up any residual completions.
38717 */
38718 spin_lock_irqsave(&h->lock, flags);
38719 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38720 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38721 spin_unlock_irqrestore(&h->lock, flags);
38722 free_irq(h->intr[h->intr_mode], h);
38723 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38724 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38725 dev_info(&h->pdev->dev, "Board READY.\n");
38726 dev_info(&h->pdev->dev,
38727 "Waiting for stale completions to drain.\n");
38728 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38729 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38730 msleep(10000);
38731 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38732 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38733
38734 rc = controller_reset_failed(h->cfgtable);
38735 if (rc)
38736 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38737 cciss_scsi_setup(h);
38738
38739 /* Turn the interrupts on so we can service requests */
38740 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38741 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38742
38743 /* Get the firmware version */
38744 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38745 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38746 kfree(flush_buf);
38747 if (return_code != IO_OK)
38748 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38749 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38750 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38751 free_irq(h->intr[h->intr_mode], h);
38752 }
38753
38754 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38755 index 7fda30e..2f27946 100644
38756 --- a/drivers/block/cciss.h
38757 +++ b/drivers/block/cciss.h
38758 @@ -101,7 +101,7 @@ struct ctlr_info
38759 /* information about each logical volume */
38760 drive_info_struct *drv[CISS_MAX_LUN];
38761
38762 - struct access_method access;
38763 + struct access_method *access;
38764
38765 /* queue and queue Info */
38766 struct list_head reqQ;
38767 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38768 }
38769
38770 static struct access_method SA5_access = {
38771 - SA5_submit_command,
38772 - SA5_intr_mask,
38773 - SA5_fifo_full,
38774 - SA5_intr_pending,
38775 - SA5_completed,
38776 + .submit_command = SA5_submit_command,
38777 + .set_intr_mask = SA5_intr_mask,
38778 + .fifo_full = SA5_fifo_full,
38779 + .intr_pending = SA5_intr_pending,
38780 + .command_completed = SA5_completed,
38781 };
38782
38783 static struct access_method SA5B_access = {
38784 - SA5_submit_command,
38785 - SA5B_intr_mask,
38786 - SA5_fifo_full,
38787 - SA5B_intr_pending,
38788 - SA5_completed,
38789 + .submit_command = SA5_submit_command,
38790 + .set_intr_mask = SA5B_intr_mask,
38791 + .fifo_full = SA5_fifo_full,
38792 + .intr_pending = SA5B_intr_pending,
38793 + .command_completed = SA5_completed,
38794 };
38795
38796 static struct access_method SA5_performant_access = {
38797 - SA5_submit_command,
38798 - SA5_performant_intr_mask,
38799 - SA5_fifo_full,
38800 - SA5_performant_intr_pending,
38801 - SA5_performant_completed,
38802 + .submit_command = SA5_submit_command,
38803 + .set_intr_mask = SA5_performant_intr_mask,
38804 + .fifo_full = SA5_fifo_full,
38805 + .intr_pending = SA5_performant_intr_pending,
38806 + .command_completed = SA5_performant_completed,
38807 };
38808
38809 struct board_type {
38810 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38811 index 2b94403..fd6ad1f 100644
38812 --- a/drivers/block/cpqarray.c
38813 +++ b/drivers/block/cpqarray.c
38814 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38815 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38816 goto Enomem4;
38817 }
38818 - hba[i]->access.set_intr_mask(hba[i], 0);
38819 + hba[i]->access->set_intr_mask(hba[i], 0);
38820 if (request_irq(hba[i]->intr, do_ida_intr,
38821 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38822 {
38823 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38824 add_timer(&hba[i]->timer);
38825
38826 /* Enable IRQ now that spinlock and rate limit timer are set up */
38827 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38828 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38829
38830 for(j=0; j<NWD; j++) {
38831 struct gendisk *disk = ida_gendisk[i][j];
38832 @@ -694,7 +694,7 @@ DBGINFO(
38833 for(i=0; i<NR_PRODUCTS; i++) {
38834 if (board_id == products[i].board_id) {
38835 c->product_name = products[i].product_name;
38836 - c->access = *(products[i].access);
38837 + c->access = products[i].access;
38838 break;
38839 }
38840 }
38841 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38842 hba[ctlr]->intr = intr;
38843 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38844 hba[ctlr]->product_name = products[j].product_name;
38845 - hba[ctlr]->access = *(products[j].access);
38846 + hba[ctlr]->access = products[j].access;
38847 hba[ctlr]->ctlr = ctlr;
38848 hba[ctlr]->board_id = board_id;
38849 hba[ctlr]->pci_dev = NULL; /* not PCI */
38850 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38851
38852 while((c = h->reqQ) != NULL) {
38853 /* Can't do anything if we're busy */
38854 - if (h->access.fifo_full(h) == 0)
38855 + if (h->access->fifo_full(h) == 0)
38856 return;
38857
38858 /* Get the first entry from the request Q */
38859 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38860 h->Qdepth--;
38861
38862 /* Tell the controller to do our bidding */
38863 - h->access.submit_command(h, c);
38864 + h->access->submit_command(h, c);
38865
38866 /* Get onto the completion Q */
38867 addQ(&h->cmpQ, c);
38868 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38869 unsigned long flags;
38870 __u32 a,a1;
38871
38872 - istat = h->access.intr_pending(h);
38873 + istat = h->access->intr_pending(h);
38874 /* Is this interrupt for us? */
38875 if (istat == 0)
38876 return IRQ_NONE;
38877 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38878 */
38879 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38880 if (istat & FIFO_NOT_EMPTY) {
38881 - while((a = h->access.command_completed(h))) {
38882 + while((a = h->access->command_completed(h))) {
38883 a1 = a; a &= ~3;
38884 if ((c = h->cmpQ) == NULL)
38885 {
38886 @@ -1448,11 +1448,11 @@ static int sendcmd(
38887 /*
38888 * Disable interrupt
38889 */
38890 - info_p->access.set_intr_mask(info_p, 0);
38891 + info_p->access->set_intr_mask(info_p, 0);
38892 /* Make sure there is room in the command FIFO */
38893 /* Actually it should be completely empty at this time. */
38894 for (i = 200000; i > 0; i--) {
38895 - temp = info_p->access.fifo_full(info_p);
38896 + temp = info_p->access->fifo_full(info_p);
38897 if (temp != 0) {
38898 break;
38899 }
38900 @@ -1465,7 +1465,7 @@ DBG(
38901 /*
38902 * Send the cmd
38903 */
38904 - info_p->access.submit_command(info_p, c);
38905 + info_p->access->submit_command(info_p, c);
38906 complete = pollcomplete(ctlr);
38907
38908 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38909 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38910 * we check the new geometry. Then turn interrupts back on when
38911 * we're done.
38912 */
38913 - host->access.set_intr_mask(host, 0);
38914 + host->access->set_intr_mask(host, 0);
38915 getgeometry(ctlr);
38916 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38917 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38918
38919 for(i=0; i<NWD; i++) {
38920 struct gendisk *disk = ida_gendisk[ctlr][i];
38921 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38922 /* Wait (up to 2 seconds) for a command to complete */
38923
38924 for (i = 200000; i > 0; i--) {
38925 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38926 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38927 if (done == 0) {
38928 udelay(10); /* a short fixed delay */
38929 } else
38930 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38931 index be73e9d..7fbf140 100644
38932 --- a/drivers/block/cpqarray.h
38933 +++ b/drivers/block/cpqarray.h
38934 @@ -99,7 +99,7 @@ struct ctlr_info {
38935 drv_info_t drv[NWD];
38936 struct proc_dir_entry *proc;
38937
38938 - struct access_method access;
38939 + struct access_method *access;
38940
38941 cmdlist_t *reqQ;
38942 cmdlist_t *cmpQ;
38943 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38944 index 426c97a..8c58607 100644
38945 --- a/drivers/block/drbd/drbd_bitmap.c
38946 +++ b/drivers/block/drbd/drbd_bitmap.c
38947 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38948 submit_bio(rw, bio);
38949 /* this should not count as user activity and cause the
38950 * resync to throttle -- see drbd_rs_should_slow_down(). */
38951 - atomic_add(len >> 9, &device->rs_sect_ev);
38952 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38953 }
38954 }
38955
38956 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38957 index 1a00001..c0d4253 100644
38958 --- a/drivers/block/drbd/drbd_int.h
38959 +++ b/drivers/block/drbd/drbd_int.h
38960 @@ -387,7 +387,7 @@ struct drbd_epoch {
38961 struct drbd_connection *connection;
38962 struct list_head list;
38963 unsigned int barrier_nr;
38964 - atomic_t epoch_size; /* increased on every request added. */
38965 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38966 atomic_t active; /* increased on every req. added, and dec on every finished. */
38967 unsigned long flags;
38968 };
38969 @@ -948,7 +948,7 @@ struct drbd_device {
38970 unsigned int al_tr_number;
38971 int al_tr_cycle;
38972 wait_queue_head_t seq_wait;
38973 - atomic_t packet_seq;
38974 + atomic_unchecked_t packet_seq;
38975 unsigned int peer_seq;
38976 spinlock_t peer_seq_lock;
38977 unsigned long comm_bm_set; /* communicated number of set bits. */
38978 @@ -957,8 +957,8 @@ struct drbd_device {
38979 struct mutex own_state_mutex;
38980 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38981 char congestion_reason; /* Why we where congested... */
38982 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38983 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38984 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38985 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38986 int rs_last_sect_ev; /* counter to compare with */
38987 int rs_last_events; /* counter of read or write "events" (unit sectors)
38988 * on the lower level device when we last looked. */
38989 @@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38990 char __user *uoptval;
38991 int err;
38992
38993 - uoptval = (char __user __force *)optval;
38994 + uoptval = (char __force_user *)optval;
38995
38996 set_fs(KERNEL_DS);
38997 if (level == SOL_SOCKET)
38998 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38999 index 04a14e0..5b8f0aa 100644
39000 --- a/drivers/block/drbd/drbd_interval.c
39001 +++ b/drivers/block/drbd/drbd_interval.c
39002 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39003 }
39004
39005 static const struct rb_augment_callbacks augment_callbacks = {
39006 - augment_propagate,
39007 - augment_copy,
39008 - augment_rotate,
39009 + .propagate = augment_propagate,
39010 + .copy = augment_copy,
39011 + .rotate = augment_rotate,
39012 };
39013
39014 /**
39015 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39016 index 9b465bb..00034ecf 100644
39017 --- a/drivers/block/drbd/drbd_main.c
39018 +++ b/drivers/block/drbd/drbd_main.c
39019 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39020 p->sector = sector;
39021 p->block_id = block_id;
39022 p->blksize = blksize;
39023 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39024 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39025 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39026 }
39027
39028 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39029 return -EIO;
39030 p->sector = cpu_to_be64(req->i.sector);
39031 p->block_id = (unsigned long)req;
39032 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39033 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39034 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39035 if (device->state.conn >= C_SYNC_SOURCE &&
39036 device->state.conn <= C_PAUSED_SYNC_T)
39037 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
39038 atomic_set(&device->unacked_cnt, 0);
39039 atomic_set(&device->local_cnt, 0);
39040 atomic_set(&device->pp_in_use_by_net, 0);
39041 - atomic_set(&device->rs_sect_in, 0);
39042 - atomic_set(&device->rs_sect_ev, 0);
39043 + atomic_set_unchecked(&device->rs_sect_in, 0);
39044 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39045 atomic_set(&device->ap_in_flight, 0);
39046 atomic_set(&device->md_io.in_use, 0);
39047
39048 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
39049 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39050 struct drbd_resource *resource = connection->resource;
39051
39052 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39053 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39054 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39055 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39056 kfree(connection->current_epoch);
39057
39058 idr_destroy(&connection->peer_devices);
39059 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39060 index 1cd47df..57c53c0 100644
39061 --- a/drivers/block/drbd/drbd_nl.c
39062 +++ b/drivers/block/drbd/drbd_nl.c
39063 @@ -3645,13 +3645,13 @@ finish:
39064
39065 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39066 {
39067 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39068 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39069 struct sk_buff *msg;
39070 struct drbd_genlmsghdr *d_out;
39071 unsigned seq;
39072 int err = -ENOMEM;
39073
39074 - seq = atomic_inc_return(&drbd_genl_seq);
39075 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39076 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39077 if (!msg)
39078 goto failed;
39079 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39080 index 9342b8d..b6a6825 100644
39081 --- a/drivers/block/drbd/drbd_receiver.c
39082 +++ b/drivers/block/drbd/drbd_receiver.c
39083 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39084 struct drbd_device *device = peer_device->device;
39085 int err;
39086
39087 - atomic_set(&device->packet_seq, 0);
39088 + atomic_set_unchecked(&device->packet_seq, 0);
39089 device->peer_seq = 0;
39090
39091 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39092 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39093 do {
39094 next_epoch = NULL;
39095
39096 - epoch_size = atomic_read(&epoch->epoch_size);
39097 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39098
39099 switch (ev & ~EV_CLEANUP) {
39100 case EV_PUT:
39101 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39102 rv = FE_DESTROYED;
39103 } else {
39104 epoch->flags = 0;
39105 - atomic_set(&epoch->epoch_size, 0);
39106 + atomic_set_unchecked(&epoch->epoch_size, 0);
39107 /* atomic_set(&epoch->active, 0); is already zero */
39108 if (rv == FE_STILL_LIVE)
39109 rv = FE_RECYCLED;
39110 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39111 conn_wait_active_ee_empty(connection);
39112 drbd_flush(connection);
39113
39114 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39115 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39116 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39117 if (epoch)
39118 break;
39119 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39120 }
39121
39122 epoch->flags = 0;
39123 - atomic_set(&epoch->epoch_size, 0);
39124 + atomic_set_unchecked(&epoch->epoch_size, 0);
39125 atomic_set(&epoch->active, 0);
39126
39127 spin_lock(&connection->epoch_lock);
39128 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39129 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39130 list_add(&epoch->list, &connection->current_epoch->list);
39131 connection->current_epoch = epoch;
39132 connection->epochs++;
39133 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39134 list_add_tail(&peer_req->w.list, &device->sync_ee);
39135 spin_unlock_irq(&device->resource->req_lock);
39136
39137 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
39138 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39139 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39140 return 0;
39141
39142 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39143 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39144 }
39145
39146 - atomic_add(pi->size >> 9, &device->rs_sect_in);
39147 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39148
39149 return err;
39150 }
39151 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39152
39153 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39154 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39155 - atomic_inc(&connection->current_epoch->epoch_size);
39156 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39157 err2 = drbd_drain_block(peer_device, pi->size);
39158 if (!err)
39159 err = err2;
39160 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39161
39162 spin_lock(&connection->epoch_lock);
39163 peer_req->epoch = connection->current_epoch;
39164 - atomic_inc(&peer_req->epoch->epoch_size);
39165 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39166 atomic_inc(&peer_req->epoch->active);
39167 spin_unlock(&connection->epoch_lock);
39168
39169 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39170
39171 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39172 (int)part_stat_read(&disk->part0, sectors[1]) -
39173 - atomic_read(&device->rs_sect_ev);
39174 + atomic_read_unchecked(&device->rs_sect_ev);
39175
39176 if (atomic_read(&device->ap_actlog_cnt)
39177 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39178 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39179 device->use_csums = true;
39180 } else if (pi->cmd == P_OV_REPLY) {
39181 /* track progress, we may need to throttle */
39182 - atomic_add(size >> 9, &device->rs_sect_in);
39183 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39184 peer_req->w.cb = w_e_end_ov_reply;
39185 dec_rs_pending(device);
39186 /* drbd_rs_begin_io done when we sent this request,
39187 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39188 goto out_free_e;
39189
39190 submit_for_resync:
39191 - atomic_add(size >> 9, &device->rs_sect_ev);
39192 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39193
39194 submit:
39195 update_receiver_timing_details(connection, drbd_submit_peer_request);
39196 @@ -4564,7 +4564,7 @@ struct data_cmd {
39197 int expect_payload;
39198 size_t pkt_size;
39199 int (*fn)(struct drbd_connection *, struct packet_info *);
39200 -};
39201 +} __do_const;
39202
39203 static struct data_cmd drbd_cmd_handler[] = {
39204 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39205 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39206 if (!list_empty(&connection->current_epoch->list))
39207 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39208 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39209 - atomic_set(&connection->current_epoch->epoch_size, 0);
39210 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39211 connection->send.seen_any_write_yet = false;
39212
39213 drbd_info(connection, "Connection closed\n");
39214 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39215 put_ldev(device);
39216 }
39217 dec_rs_pending(device);
39218 - atomic_add(blksize >> 9, &device->rs_sect_in);
39219 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39220
39221 return 0;
39222 }
39223 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39224 struct asender_cmd {
39225 size_t pkt_size;
39226 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39227 -};
39228 +} __do_const;
39229
39230 static struct asender_cmd asender_tbl[] = {
39231 [P_PING] = { 0, got_Ping },
39232 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39233 index 50776b3..1477c3f 100644
39234 --- a/drivers/block/drbd/drbd_worker.c
39235 +++ b/drivers/block/drbd/drbd_worker.c
39236 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39237 list_add_tail(&peer_req->w.list, &device->read_ee);
39238 spin_unlock_irq(&device->resource->req_lock);
39239
39240 - atomic_add(size >> 9, &device->rs_sect_ev);
39241 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39242 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39243 return 0;
39244
39245 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39246 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39247 int number, mxb;
39248
39249 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
39250 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39251 device->rs_in_flight -= sect_in;
39252
39253 rcu_read_lock();
39254 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39255 {
39256 struct fifo_buffer *plan;
39257
39258 - atomic_set(&device->rs_sect_in, 0);
39259 - atomic_set(&device->rs_sect_ev, 0);
39260 + atomic_set_unchecked(&device->rs_sect_in, 0);
39261 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39262 device->rs_in_flight = 0;
39263
39264 /* Updating the RCU protected object in place is necessary since
39265 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39266 index 6cb1beb..bf490f7 100644
39267 --- a/drivers/block/loop.c
39268 +++ b/drivers/block/loop.c
39269 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39270
39271 file_start_write(file);
39272 set_fs(get_ds());
39273 - bw = file->f_op->write(file, buf, len, &pos);
39274 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39275 set_fs(old_fs);
39276 file_end_write(file);
39277 if (likely(bw == len))
39278 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39279 index 02351e2..a9ea617 100644
39280 --- a/drivers/block/nvme-core.c
39281 +++ b/drivers/block/nvme-core.c
39282 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39283 static struct task_struct *nvme_thread;
39284 static struct workqueue_struct *nvme_workq;
39285 static wait_queue_head_t nvme_kthread_wait;
39286 -static struct notifier_block nvme_nb;
39287
39288 static void nvme_reset_failed_dev(struct work_struct *ws);
39289
39290 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39291 .err_handler = &nvme_err_handler,
39292 };
39293
39294 +static struct notifier_block nvme_nb = {
39295 + .notifier_call = &nvme_cpu_notify,
39296 +};
39297 +
39298 static int __init nvme_init(void)
39299 {
39300 int result;
39301 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39302 else if (result > 0)
39303 nvme_major = result;
39304
39305 - nvme_nb.notifier_call = &nvme_cpu_notify;
39306 result = register_hotcpu_notifier(&nvme_nb);
39307 if (result)
39308 goto unregister_blkdev;
39309 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39310 index 758ac44..58087fd 100644
39311 --- a/drivers/block/pktcdvd.c
39312 +++ b/drivers/block/pktcdvd.c
39313 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39314
39315 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39316 {
39317 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39318 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39319 }
39320
39321 /*
39322 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39323 return -EROFS;
39324 }
39325 pd->settings.fp = ti.fp;
39326 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39327 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39328
39329 if (ti.nwa_v) {
39330 pd->nwa = be32_to_cpu(ti.next_writable);
39331 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39332 index e5565fb..71be10b4 100644
39333 --- a/drivers/block/smart1,2.h
39334 +++ b/drivers/block/smart1,2.h
39335 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39336 }
39337
39338 static struct access_method smart4_access = {
39339 - smart4_submit_command,
39340 - smart4_intr_mask,
39341 - smart4_fifo_full,
39342 - smart4_intr_pending,
39343 - smart4_completed,
39344 + .submit_command = smart4_submit_command,
39345 + .set_intr_mask = smart4_intr_mask,
39346 + .fifo_full = smart4_fifo_full,
39347 + .intr_pending = smart4_intr_pending,
39348 + .command_completed = smart4_completed,
39349 };
39350
39351 /*
39352 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39353 }
39354
39355 static struct access_method smart2_access = {
39356 - smart2_submit_command,
39357 - smart2_intr_mask,
39358 - smart2_fifo_full,
39359 - smart2_intr_pending,
39360 - smart2_completed,
39361 + .submit_command = smart2_submit_command,
39362 + .set_intr_mask = smart2_intr_mask,
39363 + .fifo_full = smart2_fifo_full,
39364 + .intr_pending = smart2_intr_pending,
39365 + .command_completed = smart2_completed,
39366 };
39367
39368 /*
39369 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39370 }
39371
39372 static struct access_method smart2e_access = {
39373 - smart2e_submit_command,
39374 - smart2e_intr_mask,
39375 - smart2e_fifo_full,
39376 - smart2e_intr_pending,
39377 - smart2e_completed,
39378 + .submit_command = smart2e_submit_command,
39379 + .set_intr_mask = smart2e_intr_mask,
39380 + .fifo_full = smart2e_fifo_full,
39381 + .intr_pending = smart2e_intr_pending,
39382 + .command_completed = smart2e_completed,
39383 };
39384
39385 /*
39386 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39387 }
39388
39389 static struct access_method smart1_access = {
39390 - smart1_submit_command,
39391 - smart1_intr_mask,
39392 - smart1_fifo_full,
39393 - smart1_intr_pending,
39394 - smart1_completed,
39395 + .submit_command = smart1_submit_command,
39396 + .set_intr_mask = smart1_intr_mask,
39397 + .fifo_full = smart1_fifo_full,
39398 + .intr_pending = smart1_intr_pending,
39399 + .command_completed = smart1_completed,
39400 };
39401 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39402 index f038dba..bb74c08 100644
39403 --- a/drivers/bluetooth/btwilink.c
39404 +++ b/drivers/bluetooth/btwilink.c
39405 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39406
39407 static int bt_ti_probe(struct platform_device *pdev)
39408 {
39409 - static struct ti_st *hst;
39410 + struct ti_st *hst;
39411 struct hci_dev *hdev;
39412 int err;
39413
39414 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39415 index 898b84b..86f74b9 100644
39416 --- a/drivers/cdrom/cdrom.c
39417 +++ b/drivers/cdrom/cdrom.c
39418 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39419 ENSURE(reset, CDC_RESET);
39420 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39421 cdi->mc_flags = 0;
39422 - cdo->n_minors = 0;
39423 cdi->options = CDO_USE_FFLAGS;
39424
39425 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39426 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39427 else
39428 cdi->cdda_method = CDDA_OLD;
39429
39430 - if (!cdo->generic_packet)
39431 - cdo->generic_packet = cdrom_dummy_generic_packet;
39432 + if (!cdo->generic_packet) {
39433 + pax_open_kernel();
39434 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39435 + pax_close_kernel();
39436 + }
39437
39438 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39439 mutex_lock(&cdrom_mutex);
39440 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39441 if (cdi->exit)
39442 cdi->exit(cdi);
39443
39444 - cdi->ops->n_minors--;
39445 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39446 }
39447
39448 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39449 */
39450 nr = nframes;
39451 do {
39452 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39453 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39454 if (cgc.buffer)
39455 break;
39456
39457 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39458 struct cdrom_device_info *cdi;
39459 int ret;
39460
39461 - ret = scnprintf(info + *pos, max_size - *pos, header);
39462 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39463 if (!ret)
39464 return 1;
39465
39466 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39467 index 584bc31..e64a12c 100644
39468 --- a/drivers/cdrom/gdrom.c
39469 +++ b/drivers/cdrom/gdrom.c
39470 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39471 .audio_ioctl = gdrom_audio_ioctl,
39472 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39473 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39474 - .n_minors = 1,
39475 };
39476
39477 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39478 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39479 index 6e9f74a..50c7cea 100644
39480 --- a/drivers/char/Kconfig
39481 +++ b/drivers/char/Kconfig
39482 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39483
39484 config DEVKMEM
39485 bool "/dev/kmem virtual device support"
39486 - default y
39487 + default n
39488 + depends on !GRKERNSEC_KMEM
39489 help
39490 Say Y here if you want to support the /dev/kmem device. The
39491 /dev/kmem device is rarely used, but can be used for certain
39492 @@ -577,6 +578,7 @@ config DEVPORT
39493 bool
39494 depends on !M68K
39495 depends on ISA || PCI
39496 + depends on !GRKERNSEC_KMEM
39497 default y
39498
39499 source "drivers/s390/char/Kconfig"
39500 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39501 index a48e05b..6bac831 100644
39502 --- a/drivers/char/agp/compat_ioctl.c
39503 +++ b/drivers/char/agp/compat_ioctl.c
39504 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39505 return -ENOMEM;
39506 }
39507
39508 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39509 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39510 sizeof(*usegment) * ureserve.seg_count)) {
39511 kfree(usegment);
39512 kfree(ksegment);
39513 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39514 index 09f17eb..8531d2f 100644
39515 --- a/drivers/char/agp/frontend.c
39516 +++ b/drivers/char/agp/frontend.c
39517 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39518 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39519 return -EFAULT;
39520
39521 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39522 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39523 return -EFAULT;
39524
39525 client = agp_find_client_by_pid(reserve.pid);
39526 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39527 if (segment == NULL)
39528 return -ENOMEM;
39529
39530 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
39531 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39532 sizeof(struct agp_segment) * reserve.seg_count)) {
39533 kfree(segment);
39534 return -EFAULT;
39535 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39536 index 4f94375..413694e 100644
39537 --- a/drivers/char/genrtc.c
39538 +++ b/drivers/char/genrtc.c
39539 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39540 switch (cmd) {
39541
39542 case RTC_PLL_GET:
39543 + memset(&pll, 0, sizeof(pll));
39544 if (get_rtc_pll(&pll))
39545 return -EINVAL;
39546 else
39547 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39548 index d5d4cd8..22d561d 100644
39549 --- a/drivers/char/hpet.c
39550 +++ b/drivers/char/hpet.c
39551 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39552 }
39553
39554 static int
39555 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39556 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39557 struct hpet_info *info)
39558 {
39559 struct hpet_timer __iomem *timer;
39560 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39561 index 86fe45c..c0ea948 100644
39562 --- a/drivers/char/hw_random/intel-rng.c
39563 +++ b/drivers/char/hw_random/intel-rng.c
39564 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39565
39566 if (no_fwh_detect)
39567 return -ENODEV;
39568 - printk(warning);
39569 + printk("%s", warning);
39570 return -EBUSY;
39571 }
39572
39573 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39574 index e6db938..835e3a2 100644
39575 --- a/drivers/char/ipmi/ipmi_msghandler.c
39576 +++ b/drivers/char/ipmi/ipmi_msghandler.c
39577 @@ -438,7 +438,7 @@ struct ipmi_smi {
39578 struct proc_dir_entry *proc_dir;
39579 char proc_dir_name[10];
39580
39581 - atomic_t stats[IPMI_NUM_STATS];
39582 + atomic_unchecked_t stats[IPMI_NUM_STATS];
39583
39584 /*
39585 * run_to_completion duplicate of smb_info, smi_info
39586 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39587 static DEFINE_MUTEX(smi_watchers_mutex);
39588
39589 #define ipmi_inc_stat(intf, stat) \
39590 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39591 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39592 #define ipmi_get_stat(intf, stat) \
39593 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39594 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39595
39596 static int is_lan_addr(struct ipmi_addr *addr)
39597 {
39598 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39599 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39600 init_waitqueue_head(&intf->waitq);
39601 for (i = 0; i < IPMI_NUM_STATS; i++)
39602 - atomic_set(&intf->stats[i], 0);
39603 + atomic_set_unchecked(&intf->stats[i], 0);
39604
39605 intf->proc_dir = NULL;
39606
39607 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39608 index 5d66568..c9d93c3 100644
39609 --- a/drivers/char/ipmi/ipmi_si_intf.c
39610 +++ b/drivers/char/ipmi/ipmi_si_intf.c
39611 @@ -285,7 +285,7 @@ struct smi_info {
39612 unsigned char slave_addr;
39613
39614 /* Counters and things for the proc filesystem. */
39615 - atomic_t stats[SI_NUM_STATS];
39616 + atomic_unchecked_t stats[SI_NUM_STATS];
39617
39618 struct task_struct *thread;
39619
39620 @@ -294,9 +294,9 @@ struct smi_info {
39621 };
39622
39623 #define smi_inc_stat(smi, stat) \
39624 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39625 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39626 #define smi_get_stat(smi, stat) \
39627 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39628 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39629
39630 #define SI_MAX_PARMS 4
39631
39632 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39633 atomic_set(&new_smi->req_events, 0);
39634 new_smi->run_to_completion = false;
39635 for (i = 0; i < SI_NUM_STATS; i++)
39636 - atomic_set(&new_smi->stats[i], 0);
39637 + atomic_set_unchecked(&new_smi->stats[i], 0);
39638
39639 new_smi->interrupt_disabled = true;
39640 atomic_set(&new_smi->stop_operation, 0);
39641 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39642 index 917403f..dddd899 100644
39643 --- a/drivers/char/mem.c
39644 +++ b/drivers/char/mem.c
39645 @@ -18,6 +18,7 @@
39646 #include <linux/raw.h>
39647 #include <linux/tty.h>
39648 #include <linux/capability.h>
39649 +#include <linux/security.h>
39650 #include <linux/ptrace.h>
39651 #include <linux/device.h>
39652 #include <linux/highmem.h>
39653 @@ -36,6 +37,10 @@
39654
39655 #define DEVPORT_MINOR 4
39656
39657 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39658 +extern const struct file_operations grsec_fops;
39659 +#endif
39660 +
39661 static inline unsigned long size_inside_page(unsigned long start,
39662 unsigned long size)
39663 {
39664 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39665
39666 while (cursor < to) {
39667 if (!devmem_is_allowed(pfn)) {
39668 +#ifdef CONFIG_GRKERNSEC_KMEM
39669 + gr_handle_mem_readwrite(from, to);
39670 +#else
39671 printk(KERN_INFO
39672 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39673 current->comm, from, to);
39674 +#endif
39675 return 0;
39676 }
39677 cursor += PAGE_SIZE;
39678 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39679 }
39680 return 1;
39681 }
39682 +#elif defined(CONFIG_GRKERNSEC_KMEM)
39683 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39684 +{
39685 + return 0;
39686 +}
39687 #else
39688 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39689 {
39690 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39691
39692 while (count > 0) {
39693 unsigned long remaining;
39694 + char *temp;
39695
39696 sz = size_inside_page(p, count);
39697
39698 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39699 if (!ptr)
39700 return -EFAULT;
39701
39702 - remaining = copy_to_user(buf, ptr, sz);
39703 +#ifdef CONFIG_PAX_USERCOPY
39704 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39705 + if (!temp) {
39706 + unxlate_dev_mem_ptr(p, ptr);
39707 + return -ENOMEM;
39708 + }
39709 + memcpy(temp, ptr, sz);
39710 +#else
39711 + temp = ptr;
39712 +#endif
39713 +
39714 + remaining = copy_to_user(buf, temp, sz);
39715 +
39716 +#ifdef CONFIG_PAX_USERCOPY
39717 + kfree(temp);
39718 +#endif
39719 +
39720 unxlate_dev_mem_ptr(p, ptr);
39721 if (remaining)
39722 return -EFAULT;
39723 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39724 size_t count, loff_t *ppos)
39725 {
39726 unsigned long p = *ppos;
39727 - ssize_t low_count, read, sz;
39728 + ssize_t low_count, read, sz, err = 0;
39729 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39730 - int err = 0;
39731
39732 read = 0;
39733 if (p < (unsigned long) high_memory) {
39734 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39735 }
39736 #endif
39737 while (low_count > 0) {
39738 + char *temp;
39739 +
39740 sz = size_inside_page(p, low_count);
39741
39742 /*
39743 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39744 */
39745 kbuf = xlate_dev_kmem_ptr((char *)p);
39746
39747 - if (copy_to_user(buf, kbuf, sz))
39748 +#ifdef CONFIG_PAX_USERCOPY
39749 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39750 + if (!temp)
39751 + return -ENOMEM;
39752 + memcpy(temp, kbuf, sz);
39753 +#else
39754 + temp = kbuf;
39755 +#endif
39756 +
39757 + err = copy_to_user(buf, temp, sz);
39758 +
39759 +#ifdef CONFIG_PAX_USERCOPY
39760 + kfree(temp);
39761 +#endif
39762 +
39763 + if (err)
39764 return -EFAULT;
39765 buf += sz;
39766 p += sz;
39767 @@ -827,6 +874,9 @@ static const struct memdev {
39768 #ifdef CONFIG_PRINTK
39769 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39770 #endif
39771 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39772 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39773 +#endif
39774 };
39775
39776 static int memory_open(struct inode *inode, struct file *filp)
39777 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
39778 continue;
39779
39780 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39781 - NULL, devlist[minor].name);
39782 + NULL, "%s", devlist[minor].name);
39783 }
39784
39785 return tty_init();
39786 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39787 index 9df78e2..01ba9ae 100644
39788 --- a/drivers/char/nvram.c
39789 +++ b/drivers/char/nvram.c
39790 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
39791
39792 spin_unlock_irq(&rtc_lock);
39793
39794 - if (copy_to_user(buf, contents, tmp - contents))
39795 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
39796 return -EFAULT;
39797
39798 *ppos = i;
39799 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
39800 index 0ea9986..e7b07e4 100644
39801 --- a/drivers/char/pcmcia/synclink_cs.c
39802 +++ b/drivers/char/pcmcia/synclink_cs.c
39803 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39804
39805 if (debug_level >= DEBUG_LEVEL_INFO)
39806 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
39807 - __FILE__, __LINE__, info->device_name, port->count);
39808 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
39809
39810 if (tty_port_close_start(port, tty, filp) == 0)
39811 goto cleanup;
39812 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39813 cleanup:
39814 if (debug_level >= DEBUG_LEVEL_INFO)
39815 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
39816 - tty->driver->name, port->count);
39817 + tty->driver->name, atomic_read(&port->count));
39818 }
39819
39820 /* Wait until the transmitter is empty.
39821 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39822
39823 if (debug_level >= DEBUG_LEVEL_INFO)
39824 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
39825 - __FILE__, __LINE__, tty->driver->name, port->count);
39826 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
39827
39828 /* If port is closing, signal caller to try again */
39829 if (port->flags & ASYNC_CLOSING){
39830 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39831 goto cleanup;
39832 }
39833 spin_lock(&port->lock);
39834 - port->count++;
39835 + atomic_inc(&port->count);
39836 spin_unlock(&port->lock);
39837 spin_unlock_irqrestore(&info->netlock, flags);
39838
39839 - if (port->count == 1) {
39840 + if (atomic_read(&port->count) == 1) {
39841 /* 1st open on this device, init hardware */
39842 retval = startup(info, tty);
39843 if (retval < 0)
39844 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39845 unsigned short new_crctype;
39846
39847 /* return error if TTY interface open */
39848 - if (info->port.count)
39849 + if (atomic_read(&info->port.count))
39850 return -EBUSY;
39851
39852 switch (encoding)
39853 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
39854
39855 /* arbitrate between network and tty opens */
39856 spin_lock_irqsave(&info->netlock, flags);
39857 - if (info->port.count != 0 || info->netcount != 0) {
39858 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39859 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39860 spin_unlock_irqrestore(&info->netlock, flags);
39861 return -EBUSY;
39862 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39863 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39864
39865 /* return error if TTY interface open */
39866 - if (info->port.count)
39867 + if (atomic_read(&info->port.count))
39868 return -EBUSY;
39869
39870 if (cmd != SIOCWANDEV)
39871 diff --git a/drivers/char/random.c b/drivers/char/random.c
39872 index 8c86a95..7c499f3 100644
39873 --- a/drivers/char/random.c
39874 +++ b/drivers/char/random.c
39875 @@ -289,9 +289,6 @@
39876 /*
39877 * To allow fractional bits to be tracked, the entropy_count field is
39878 * denominated in units of 1/8th bits.
39879 - *
39880 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39881 - * credit_entropy_bits() needs to be 64 bits wide.
39882 */
39883 #define ENTROPY_SHIFT 3
39884 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39885 @@ -439,9 +436,9 @@ struct entropy_store {
39886 };
39887
39888 static void push_to_pool(struct work_struct *work);
39889 -static __u32 input_pool_data[INPUT_POOL_WORDS];
39890 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39891 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39892 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39893 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39894 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39895
39896 static struct entropy_store input_pool = {
39897 .poolinfo = &poolinfo_table[0],
39898 @@ -635,7 +632,7 @@ retry:
39899 /* The +2 corresponds to the /4 in the denominator */
39900
39901 do {
39902 - unsigned int anfrac = min(pnfrac, pool_size/2);
39903 + u64 anfrac = min(pnfrac, pool_size/2);
39904 unsigned int add =
39905 ((pool_size - entropy_count)*anfrac*3) >> s;
39906
39907 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39908
39909 extract_buf(r, tmp);
39910 i = min_t(int, nbytes, EXTRACT_SIZE);
39911 - if (copy_to_user(buf, tmp, i)) {
39912 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39913 ret = -EFAULT;
39914 break;
39915 }
39916 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39917 static int proc_do_uuid(struct ctl_table *table, int write,
39918 void __user *buffer, size_t *lenp, loff_t *ppos)
39919 {
39920 - struct ctl_table fake_table;
39921 + ctl_table_no_const fake_table;
39922 unsigned char buf[64], tmp_uuid[16], *uuid;
39923
39924 uuid = table->data;
39925 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39926 static int proc_do_entropy(struct ctl_table *table, int write,
39927 void __user *buffer, size_t *lenp, loff_t *ppos)
39928 {
39929 - struct ctl_table fake_table;
39930 + ctl_table_no_const fake_table;
39931 int entropy_count;
39932
39933 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39934 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39935 index 7cc1fe22..b602d6b 100644
39936 --- a/drivers/char/sonypi.c
39937 +++ b/drivers/char/sonypi.c
39938 @@ -54,6 +54,7 @@
39939
39940 #include <asm/uaccess.h>
39941 #include <asm/io.h>
39942 +#include <asm/local.h>
39943
39944 #include <linux/sonypi.h>
39945
39946 @@ -490,7 +491,7 @@ static struct sonypi_device {
39947 spinlock_t fifo_lock;
39948 wait_queue_head_t fifo_proc_list;
39949 struct fasync_struct *fifo_async;
39950 - int open_count;
39951 + local_t open_count;
39952 int model;
39953 struct input_dev *input_jog_dev;
39954 struct input_dev *input_key_dev;
39955 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39956 static int sonypi_misc_release(struct inode *inode, struct file *file)
39957 {
39958 mutex_lock(&sonypi_device.lock);
39959 - sonypi_device.open_count--;
39960 + local_dec(&sonypi_device.open_count);
39961 mutex_unlock(&sonypi_device.lock);
39962 return 0;
39963 }
39964 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39965 {
39966 mutex_lock(&sonypi_device.lock);
39967 /* Flush input queue on first open */
39968 - if (!sonypi_device.open_count)
39969 + if (!local_read(&sonypi_device.open_count))
39970 kfifo_reset(&sonypi_device.fifo);
39971 - sonypi_device.open_count++;
39972 + local_inc(&sonypi_device.open_count);
39973 mutex_unlock(&sonypi_device.lock);
39974
39975 return 0;
39976 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39977 index 565a947..dcdc06e 100644
39978 --- a/drivers/char/tpm/tpm_acpi.c
39979 +++ b/drivers/char/tpm/tpm_acpi.c
39980 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39981 virt = acpi_os_map_iomem(start, len);
39982 if (!virt) {
39983 kfree(log->bios_event_log);
39984 + log->bios_event_log = NULL;
39985 printk("%s: ERROR - Unable to map memory\n", __func__);
39986 return -EIO;
39987 }
39988
39989 - memcpy_fromio(log->bios_event_log, virt, len);
39990 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39991
39992 acpi_os_unmap_iomem(virt, len);
39993 return 0;
39994 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39995 index 3a56a13..f8cbd25 100644
39996 --- a/drivers/char/tpm/tpm_eventlog.c
39997 +++ b/drivers/char/tpm/tpm_eventlog.c
39998 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39999 event = addr;
40000
40001 if ((event->event_type == 0 && event->event_size == 0) ||
40002 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40003 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40004 return NULL;
40005
40006 return addr;
40007 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40008 return NULL;
40009
40010 if ((event->event_type == 0 && event->event_size == 0) ||
40011 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40012 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40013 return NULL;
40014
40015 (*pos)++;
40016 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40017 int i;
40018
40019 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40020 - seq_putc(m, data[i]);
40021 + if (!seq_putc(m, data[i]))
40022 + return -EFAULT;
40023
40024 return 0;
40025 }
40026 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40027 index b585b47..488f43e 100644
40028 --- a/drivers/char/virtio_console.c
40029 +++ b/drivers/char/virtio_console.c
40030 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40031 if (to_user) {
40032 ssize_t ret;
40033
40034 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40035 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40036 if (ret)
40037 return -EFAULT;
40038 } else {
40039 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40040 if (!port_has_data(port) && !port->host_connected)
40041 return 0;
40042
40043 - return fill_readbuf(port, ubuf, count, true);
40044 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40045 }
40046
40047 static int wait_port_writable(struct port *port, bool nonblock)
40048 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40049 index b9355da..9611f4e 100644
40050 --- a/drivers/clk/clk-composite.c
40051 +++ b/drivers/clk/clk-composite.c
40052 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40053 struct clk *clk;
40054 struct clk_init_data init;
40055 struct clk_composite *composite;
40056 - struct clk_ops *clk_composite_ops;
40057 + clk_ops_no_const *clk_composite_ops;
40058
40059 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40060 if (!composite) {
40061 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40062 index dd3a78c..386d49c 100644
40063 --- a/drivers/clk/socfpga/clk-gate.c
40064 +++ b/drivers/clk/socfpga/clk-gate.c
40065 @@ -22,6 +22,7 @@
40066 #include <linux/mfd/syscon.h>
40067 #include <linux/of.h>
40068 #include <linux/regmap.h>
40069 +#include <asm/pgtable.h>
40070
40071 #include "clk.h"
40072
40073 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40074 return 0;
40075 }
40076
40077 -static struct clk_ops gateclk_ops = {
40078 +static clk_ops_no_const gateclk_ops __read_only = {
40079 .prepare = socfpga_clk_prepare,
40080 .recalc_rate = socfpga_clk_recalc_rate,
40081 .get_parent = socfpga_clk_get_parent,
40082 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40083 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40084 socfpga_clk->hw.bit_idx = clk_gate[1];
40085
40086 - gateclk_ops.enable = clk_gate_ops.enable;
40087 - gateclk_ops.disable = clk_gate_ops.disable;
40088 + pax_open_kernel();
40089 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40090 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40091 + pax_close_kernel();
40092 }
40093
40094 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40095 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40096 index de6da95..c98278b 100644
40097 --- a/drivers/clk/socfpga/clk-pll.c
40098 +++ b/drivers/clk/socfpga/clk-pll.c
40099 @@ -21,6 +21,7 @@
40100 #include <linux/io.h>
40101 #include <linux/of.h>
40102 #include <linux/of_address.h>
40103 +#include <asm/pgtable.h>
40104
40105 #include "clk.h"
40106
40107 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40108 CLK_MGR_PLL_CLK_SRC_MASK;
40109 }
40110
40111 -static struct clk_ops clk_pll_ops = {
40112 +static clk_ops_no_const clk_pll_ops __read_only = {
40113 .recalc_rate = clk_pll_recalc_rate,
40114 .get_parent = clk_pll_get_parent,
40115 };
40116 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40117 pll_clk->hw.hw.init = &init;
40118
40119 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40120 - clk_pll_ops.enable = clk_gate_ops.enable;
40121 - clk_pll_ops.disable = clk_gate_ops.disable;
40122 + pax_open_kernel();
40123 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40124 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40125 + pax_close_kernel();
40126
40127 clk = clk_register(NULL, &pll_clk->hw.hw);
40128 if (WARN_ON(IS_ERR(clk))) {
40129 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40130 index b0c18ed..1713a80 100644
40131 --- a/drivers/cpufreq/acpi-cpufreq.c
40132 +++ b/drivers/cpufreq/acpi-cpufreq.c
40133 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40134 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40135 per_cpu(acfreq_data, cpu) = data;
40136
40137 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40138 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40139 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40140 + pax_open_kernel();
40141 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40142 + pax_close_kernel();
40143 + }
40144
40145 result = acpi_processor_register_performance(data->acpi_data, cpu);
40146 if (result)
40147 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40148 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40149 break;
40150 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40151 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40152 + pax_open_kernel();
40153 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40154 + pax_close_kernel();
40155 break;
40156 default:
40157 break;
40158 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40159 if (!msrs)
40160 return;
40161
40162 - acpi_cpufreq_driver.boost_supported = true;
40163 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40164 + pax_open_kernel();
40165 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40166 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40167 + pax_close_kernel();
40168
40169 cpu_notifier_register_begin();
40170
40171 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40172 index 07c8276..38bd07c 100644
40173 --- a/drivers/cpufreq/cpufreq.c
40174 +++ b/drivers/cpufreq/cpufreq.c
40175 @@ -2107,7 +2107,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40176 }
40177
40178 mutex_lock(&cpufreq_governor_mutex);
40179 - list_del(&governor->governor_list);
40180 + pax_list_del(&governor->governor_list);
40181 mutex_unlock(&cpufreq_governor_mutex);
40182 return;
40183 }
40184 @@ -2323,7 +2323,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40185 return NOTIFY_OK;
40186 }
40187
40188 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40189 +static struct notifier_block cpufreq_cpu_notifier = {
40190 .notifier_call = cpufreq_cpu_callback,
40191 };
40192
40193 @@ -2363,13 +2363,17 @@ int cpufreq_boost_trigger_state(int state)
40194 return 0;
40195
40196 write_lock_irqsave(&cpufreq_driver_lock, flags);
40197 - cpufreq_driver->boost_enabled = state;
40198 + pax_open_kernel();
40199 + *(bool *)&cpufreq_driver->boost_enabled = state;
40200 + pax_close_kernel();
40201 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40202
40203 ret = cpufreq_driver->set_boost(state);
40204 if (ret) {
40205 write_lock_irqsave(&cpufreq_driver_lock, flags);
40206 - cpufreq_driver->boost_enabled = !state;
40207 + pax_open_kernel();
40208 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40209 + pax_close_kernel();
40210 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40211
40212 pr_err("%s: Cannot %s BOOST\n",
40213 @@ -2426,8 +2430,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40214
40215 pr_debug("trying to register driver %s\n", driver_data->name);
40216
40217 - if (driver_data->setpolicy)
40218 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40219 + if (driver_data->setpolicy) {
40220 + pax_open_kernel();
40221 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40222 + pax_close_kernel();
40223 + }
40224
40225 write_lock_irqsave(&cpufreq_driver_lock, flags);
40226 if (cpufreq_driver) {
40227 @@ -2442,8 +2449,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40228 * Check if driver provides function to enable boost -
40229 * if not, use cpufreq_boost_set_sw as default
40230 */
40231 - if (!cpufreq_driver->set_boost)
40232 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40233 + if (!cpufreq_driver->set_boost) {
40234 + pax_open_kernel();
40235 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40236 + pax_close_kernel();
40237 + }
40238
40239 ret = cpufreq_sysfs_create_file(&boost.attr);
40240 if (ret) {
40241 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40242 index 1b44496..b80ff5e 100644
40243 --- a/drivers/cpufreq/cpufreq_governor.c
40244 +++ b/drivers/cpufreq/cpufreq_governor.c
40245 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40246 struct dbs_data *dbs_data;
40247 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40248 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40249 - struct od_ops *od_ops = NULL;
40250 + const struct od_ops *od_ops = NULL;
40251 struct od_dbs_tuners *od_tuners = NULL;
40252 struct cs_dbs_tuners *cs_tuners = NULL;
40253 struct cpu_dbs_common_info *cpu_cdbs;
40254 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40255
40256 if ((cdata->governor == GOV_CONSERVATIVE) &&
40257 (!policy->governor->initialized)) {
40258 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40259 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40260
40261 cpufreq_register_notifier(cs_ops->notifier_block,
40262 CPUFREQ_TRANSITION_NOTIFIER);
40263 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40264
40265 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40266 (policy->governor->initialized == 1)) {
40267 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40268 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40269
40270 cpufreq_unregister_notifier(cs_ops->notifier_block,
40271 CPUFREQ_TRANSITION_NOTIFIER);
40272 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40273 index cc401d1..8197340 100644
40274 --- a/drivers/cpufreq/cpufreq_governor.h
40275 +++ b/drivers/cpufreq/cpufreq_governor.h
40276 @@ -212,7 +212,7 @@ struct common_dbs_data {
40277 void (*exit)(struct dbs_data *dbs_data);
40278
40279 /* Governor specific ops, see below */
40280 - void *gov_ops;
40281 + const void *gov_ops;
40282 };
40283
40284 /* Governor Per policy data */
40285 @@ -232,7 +232,7 @@ struct od_ops {
40286 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40287 unsigned int freq_next, unsigned int relation);
40288 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40289 -};
40290 +} __no_const;
40291
40292 struct cs_ops {
40293 struct notifier_block *notifier_block;
40294 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40295 index ad3f38f..8f086cd 100644
40296 --- a/drivers/cpufreq/cpufreq_ondemand.c
40297 +++ b/drivers/cpufreq/cpufreq_ondemand.c
40298 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40299
40300 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40301
40302 -static struct od_ops od_ops = {
40303 +static struct od_ops od_ops __read_only = {
40304 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40305 .powersave_bias_target = generic_powersave_bias_target,
40306 .freq_increase = dbs_freq_increase,
40307 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40308 (struct cpufreq_policy *, unsigned int, unsigned int),
40309 unsigned int powersave_bias)
40310 {
40311 - od_ops.powersave_bias_target = f;
40312 + pax_open_kernel();
40313 + *(void **)&od_ops.powersave_bias_target = f;
40314 + pax_close_kernel();
40315 od_set_powersave_bias(powersave_bias);
40316 }
40317 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40318
40319 void od_unregister_powersave_bias_handler(void)
40320 {
40321 - od_ops.powersave_bias_target = generic_powersave_bias_target;
40322 + pax_open_kernel();
40323 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40324 + pax_close_kernel();
40325 od_set_powersave_bias(0);
40326 }
40327 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40328 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40329 index 27bb6d3..4cf595c 100644
40330 --- a/drivers/cpufreq/intel_pstate.c
40331 +++ b/drivers/cpufreq/intel_pstate.c
40332 @@ -133,10 +133,10 @@ struct pstate_funcs {
40333 struct cpu_defaults {
40334 struct pstate_adjust_policy pid_policy;
40335 struct pstate_funcs funcs;
40336 -};
40337 +} __do_const;
40338
40339 static struct pstate_adjust_policy pid_params;
40340 -static struct pstate_funcs pstate_funcs;
40341 +static struct pstate_funcs *pstate_funcs;
40342
40343 struct perf_limits {
40344 int no_turbo;
40345 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40346
40347 cpu->pstate.current_pstate = pstate;
40348
40349 - pstate_funcs.set(cpu, pstate);
40350 + pstate_funcs->set(cpu, pstate);
40351 }
40352
40353 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40354 {
40355 - cpu->pstate.min_pstate = pstate_funcs.get_min();
40356 - cpu->pstate.max_pstate = pstate_funcs.get_max();
40357 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40358 - cpu->pstate.scaling = pstate_funcs.get_scaling();
40359 + cpu->pstate.min_pstate = pstate_funcs->get_min();
40360 + cpu->pstate.max_pstate = pstate_funcs->get_max();
40361 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40362 + cpu->pstate.scaling = pstate_funcs->get_scaling();
40363
40364 - if (pstate_funcs.get_vid)
40365 - pstate_funcs.get_vid(cpu);
40366 + if (pstate_funcs->get_vid)
40367 + pstate_funcs->get_vid(cpu);
40368 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40369 }
40370
40371 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
40372 rdmsrl(MSR_IA32_APERF, aperf);
40373 rdmsrl(MSR_IA32_MPERF, mperf);
40374
40375 - if (!pstate_funcs.get_max() ||
40376 - !pstate_funcs.get_min() ||
40377 - !pstate_funcs.get_turbo())
40378 + if (!pstate_funcs->get_max() ||
40379 + !pstate_funcs->get_min() ||
40380 + !pstate_funcs->get_turbo())
40381 return -ENODEV;
40382
40383 rdmsrl(MSR_IA32_APERF, tmp);
40384 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
40385 return 0;
40386 }
40387
40388 -static void copy_pid_params(struct pstate_adjust_policy *policy)
40389 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
40390 {
40391 pid_params.sample_rate_ms = policy->sample_rate_ms;
40392 pid_params.p_gain_pct = policy->p_gain_pct;
40393 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40394
40395 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40396 {
40397 - pstate_funcs.get_max = funcs->get_max;
40398 - pstate_funcs.get_min = funcs->get_min;
40399 - pstate_funcs.get_turbo = funcs->get_turbo;
40400 - pstate_funcs.get_scaling = funcs->get_scaling;
40401 - pstate_funcs.set = funcs->set;
40402 - pstate_funcs.get_vid = funcs->get_vid;
40403 + pstate_funcs = funcs;
40404 }
40405
40406 #if IS_ENABLED(CONFIG_ACPI)
40407 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40408 index 529cfd9..0e28fff 100644
40409 --- a/drivers/cpufreq/p4-clockmod.c
40410 +++ b/drivers/cpufreq/p4-clockmod.c
40411 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40412 case 0x0F: /* Core Duo */
40413 case 0x16: /* Celeron Core */
40414 case 0x1C: /* Atom */
40415 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40416 + pax_open_kernel();
40417 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40418 + pax_close_kernel();
40419 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40420 case 0x0D: /* Pentium M (Dothan) */
40421 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40422 + pax_open_kernel();
40423 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40424 + pax_close_kernel();
40425 /* fall through */
40426 case 0x09: /* Pentium M (Banias) */
40427 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40428 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40429
40430 /* on P-4s, the TSC runs with constant frequency independent whether
40431 * throttling is active or not. */
40432 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40433 + pax_open_kernel();
40434 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40435 + pax_close_kernel();
40436
40437 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40438 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40439 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40440 index 9bb42ba..b01b4a2 100644
40441 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
40442 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40443 @@ -18,14 +18,12 @@
40444 #include <asm/head.h>
40445 #include <asm/timer.h>
40446
40447 -static struct cpufreq_driver *cpufreq_us3_driver;
40448 -
40449 struct us3_freq_percpu_info {
40450 struct cpufreq_frequency_table table[4];
40451 };
40452
40453 /* Indexed by cpu number. */
40454 -static struct us3_freq_percpu_info *us3_freq_table;
40455 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40456
40457 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40458 * in the Safari config register.
40459 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40460
40461 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40462 {
40463 - if (cpufreq_us3_driver)
40464 - us3_freq_target(policy, 0);
40465 + us3_freq_target(policy, 0);
40466
40467 return 0;
40468 }
40469
40470 +static int __init us3_freq_init(void);
40471 +static void __exit us3_freq_exit(void);
40472 +
40473 +static struct cpufreq_driver cpufreq_us3_driver = {
40474 + .init = us3_freq_cpu_init,
40475 + .verify = cpufreq_generic_frequency_table_verify,
40476 + .target_index = us3_freq_target,
40477 + .get = us3_freq_get,
40478 + .exit = us3_freq_cpu_exit,
40479 + .name = "UltraSPARC-III",
40480 +
40481 +};
40482 +
40483 static int __init us3_freq_init(void)
40484 {
40485 unsigned long manuf, impl, ver;
40486 - int ret;
40487
40488 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40489 return -ENODEV;
40490 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40491 (impl == CHEETAH_IMPL ||
40492 impl == CHEETAH_PLUS_IMPL ||
40493 impl == JAGUAR_IMPL ||
40494 - impl == PANTHER_IMPL)) {
40495 - struct cpufreq_driver *driver;
40496 -
40497 - ret = -ENOMEM;
40498 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40499 - if (!driver)
40500 - goto err_out;
40501 -
40502 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40503 - GFP_KERNEL);
40504 - if (!us3_freq_table)
40505 - goto err_out;
40506 -
40507 - driver->init = us3_freq_cpu_init;
40508 - driver->verify = cpufreq_generic_frequency_table_verify;
40509 - driver->target_index = us3_freq_target;
40510 - driver->get = us3_freq_get;
40511 - driver->exit = us3_freq_cpu_exit;
40512 - strcpy(driver->name, "UltraSPARC-III");
40513 -
40514 - cpufreq_us3_driver = driver;
40515 - ret = cpufreq_register_driver(driver);
40516 - if (ret)
40517 - goto err_out;
40518 -
40519 - return 0;
40520 -
40521 -err_out:
40522 - if (driver) {
40523 - kfree(driver);
40524 - cpufreq_us3_driver = NULL;
40525 - }
40526 - kfree(us3_freq_table);
40527 - us3_freq_table = NULL;
40528 - return ret;
40529 - }
40530 + impl == PANTHER_IMPL))
40531 + return cpufreq_register_driver(&cpufreq_us3_driver);
40532
40533 return -ENODEV;
40534 }
40535
40536 static void __exit us3_freq_exit(void)
40537 {
40538 - if (cpufreq_us3_driver) {
40539 - cpufreq_unregister_driver(cpufreq_us3_driver);
40540 - kfree(cpufreq_us3_driver);
40541 - cpufreq_us3_driver = NULL;
40542 - kfree(us3_freq_table);
40543 - us3_freq_table = NULL;
40544 - }
40545 + cpufreq_unregister_driver(&cpufreq_us3_driver);
40546 }
40547
40548 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40549 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40550 index 7d4a315..21bb886 100644
40551 --- a/drivers/cpufreq/speedstep-centrino.c
40552 +++ b/drivers/cpufreq/speedstep-centrino.c
40553 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40554 !cpu_has(cpu, X86_FEATURE_EST))
40555 return -ENODEV;
40556
40557 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40558 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40559 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40560 + pax_open_kernel();
40561 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40562 + pax_close_kernel();
40563 + }
40564
40565 if (policy->cpu != 0)
40566 return -ENODEV;
40567 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40568 index e431d11..d0b997e 100644
40569 --- a/drivers/cpuidle/driver.c
40570 +++ b/drivers/cpuidle/driver.c
40571 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40572
40573 static void poll_idle_init(struct cpuidle_driver *drv)
40574 {
40575 - struct cpuidle_state *state = &drv->states[0];
40576 + cpuidle_state_no_const *state = &drv->states[0];
40577
40578 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40579 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40580 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40581 index ca89412..a7b9c49 100644
40582 --- a/drivers/cpuidle/governor.c
40583 +++ b/drivers/cpuidle/governor.c
40584 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40585 mutex_lock(&cpuidle_lock);
40586 if (__cpuidle_find_governor(gov->name) == NULL) {
40587 ret = 0;
40588 - list_add_tail(&gov->governor_list, &cpuidle_governors);
40589 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40590 if (!cpuidle_curr_governor ||
40591 cpuidle_curr_governor->rating < gov->rating)
40592 cpuidle_switch_governor(gov);
40593 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40594 index 97c5903..023ad23 100644
40595 --- a/drivers/cpuidle/sysfs.c
40596 +++ b/drivers/cpuidle/sysfs.c
40597 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40598 NULL
40599 };
40600
40601 -static struct attribute_group cpuidle_attr_group = {
40602 +static attribute_group_no_const cpuidle_attr_group = {
40603 .attrs = cpuidle_default_attrs,
40604 .name = "cpuidle",
40605 };
40606 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40607 index 8d2a772..33826c9 100644
40608 --- a/drivers/crypto/hifn_795x.c
40609 +++ b/drivers/crypto/hifn_795x.c
40610 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40611 MODULE_PARM_DESC(hifn_pll_ref,
40612 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40613
40614 -static atomic_t hifn_dev_number;
40615 +static atomic_unchecked_t hifn_dev_number;
40616
40617 #define ACRYPTO_OP_DECRYPT 0
40618 #define ACRYPTO_OP_ENCRYPT 1
40619 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40620 goto err_out_disable_pci_device;
40621
40622 snprintf(name, sizeof(name), "hifn%d",
40623 - atomic_inc_return(&hifn_dev_number)-1);
40624 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
40625
40626 err = pci_request_regions(pdev, name);
40627 if (err)
40628 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40629 index 9f90369..bfcacdb 100644
40630 --- a/drivers/devfreq/devfreq.c
40631 +++ b/drivers/devfreq/devfreq.c
40632 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40633 goto err_out;
40634 }
40635
40636 - list_add(&governor->node, &devfreq_governor_list);
40637 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40638
40639 list_for_each_entry(devfreq, &devfreq_list, node) {
40640 int ret = 0;
40641 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40642 }
40643 }
40644
40645 - list_del(&governor->node);
40646 + pax_list_del((struct list_head *)&governor->node);
40647 err_out:
40648 mutex_unlock(&devfreq_list_lock);
40649
40650 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40651 index 42d4974..2714f36 100644
40652 --- a/drivers/dma/sh/shdma-base.c
40653 +++ b/drivers/dma/sh/shdma-base.c
40654 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40655 schan->slave_id = -EINVAL;
40656 }
40657
40658 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40659 - sdev->desc_size, GFP_KERNEL);
40660 + schan->desc = kcalloc(sdev->desc_size,
40661 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40662 if (!schan->desc) {
40663 ret = -ENOMEM;
40664 goto edescalloc;
40665 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40666 index 58eb857..d7e42c8 100644
40667 --- a/drivers/dma/sh/shdmac.c
40668 +++ b/drivers/dma/sh/shdmac.c
40669 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40670 return ret;
40671 }
40672
40673 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40674 +static struct notifier_block sh_dmae_nmi_notifier = {
40675 .notifier_call = sh_dmae_nmi_handler,
40676
40677 /* Run before NMI debug handler and KGDB */
40678 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40679 index 592af5f..bb1d583 100644
40680 --- a/drivers/edac/edac_device.c
40681 +++ b/drivers/edac/edac_device.c
40682 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40683 */
40684 int edac_device_alloc_index(void)
40685 {
40686 - static atomic_t device_indexes = ATOMIC_INIT(0);
40687 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40688
40689 - return atomic_inc_return(&device_indexes) - 1;
40690 + return atomic_inc_return_unchecked(&device_indexes) - 1;
40691 }
40692 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40693
40694 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40695 index a6cd361..7bdbf53 100644
40696 --- a/drivers/edac/edac_mc_sysfs.c
40697 +++ b/drivers/edac/edac_mc_sysfs.c
40698 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40699 struct dev_ch_attribute {
40700 struct device_attribute attr;
40701 int channel;
40702 -};
40703 +} __do_const;
40704
40705 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40706 struct dev_ch_attribute dev_attr_legacy_##_name = \
40707 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40708 }
40709
40710 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40711 + pax_open_kernel();
40712 if (mci->get_sdram_scrub_rate) {
40713 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40714 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40715 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40716 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40717 }
40718 if (mci->set_sdram_scrub_rate) {
40719 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40720 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40721 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40722 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40723 }
40724 + pax_close_kernel();
40725 err = device_create_file(&mci->dev,
40726 &dev_attr_sdram_scrub_rate);
40727 if (err) {
40728 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40729 index 2cf44b4d..6dd2dc7 100644
40730 --- a/drivers/edac/edac_pci.c
40731 +++ b/drivers/edac/edac_pci.c
40732 @@ -29,7 +29,7 @@
40733
40734 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40735 static LIST_HEAD(edac_pci_list);
40736 -static atomic_t pci_indexes = ATOMIC_INIT(0);
40737 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40738
40739 /*
40740 * edac_pci_alloc_ctl_info
40741 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40742 */
40743 int edac_pci_alloc_index(void)
40744 {
40745 - return atomic_inc_return(&pci_indexes) - 1;
40746 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
40747 }
40748 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40749
40750 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40751 index e8658e4..22746d6 100644
40752 --- a/drivers/edac/edac_pci_sysfs.c
40753 +++ b/drivers/edac/edac_pci_sysfs.c
40754 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40755 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40756 static int edac_pci_poll_msec = 1000; /* one second workq period */
40757
40758 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
40759 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40760 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40761 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40762
40763 static struct kobject *edac_pci_top_main_kobj;
40764 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40765 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40766 void *value;
40767 ssize_t(*show) (void *, char *);
40768 ssize_t(*store) (void *, const char *, size_t);
40769 -};
40770 +} __do_const;
40771
40772 /* Set of show/store abstract level functions for PCI Parity object */
40773 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40774 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40775 edac_printk(KERN_CRIT, EDAC_PCI,
40776 "Signaled System Error on %s\n",
40777 pci_name(dev));
40778 - atomic_inc(&pci_nonparity_count);
40779 + atomic_inc_unchecked(&pci_nonparity_count);
40780 }
40781
40782 if (status & (PCI_STATUS_PARITY)) {
40783 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40784 "Master Data Parity Error on %s\n",
40785 pci_name(dev));
40786
40787 - atomic_inc(&pci_parity_count);
40788 + atomic_inc_unchecked(&pci_parity_count);
40789 }
40790
40791 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40792 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40793 "Detected Parity Error on %s\n",
40794 pci_name(dev));
40795
40796 - atomic_inc(&pci_parity_count);
40797 + atomic_inc_unchecked(&pci_parity_count);
40798 }
40799 }
40800
40801 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40802 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
40803 "Signaled System Error on %s\n",
40804 pci_name(dev));
40805 - atomic_inc(&pci_nonparity_count);
40806 + atomic_inc_unchecked(&pci_nonparity_count);
40807 }
40808
40809 if (status & (PCI_STATUS_PARITY)) {
40810 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40811 "Master Data Parity Error on "
40812 "%s\n", pci_name(dev));
40813
40814 - atomic_inc(&pci_parity_count);
40815 + atomic_inc_unchecked(&pci_parity_count);
40816 }
40817
40818 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40819 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40820 "Detected Parity Error on %s\n",
40821 pci_name(dev));
40822
40823 - atomic_inc(&pci_parity_count);
40824 + atomic_inc_unchecked(&pci_parity_count);
40825 }
40826 }
40827 }
40828 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40829 if (!check_pci_errors)
40830 return;
40831
40832 - before_count = atomic_read(&pci_parity_count);
40833 + before_count = atomic_read_unchecked(&pci_parity_count);
40834
40835 /* scan all PCI devices looking for a Parity Error on devices and
40836 * bridges.
40837 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40838 /* Only if operator has selected panic on PCI Error */
40839 if (edac_pci_get_panic_on_pe()) {
40840 /* If the count is different 'after' from 'before' */
40841 - if (before_count != atomic_read(&pci_parity_count))
40842 + if (before_count != atomic_read_unchecked(&pci_parity_count))
40843 panic("EDAC: PCI Parity Error");
40844 }
40845 }
40846 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40847 index 51b7e3a..aa8a3e8 100644
40848 --- a/drivers/edac/mce_amd.h
40849 +++ b/drivers/edac/mce_amd.h
40850 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
40851 bool (*mc0_mce)(u16, u8);
40852 bool (*mc1_mce)(u16, u8);
40853 bool (*mc2_mce)(u16, u8);
40854 -};
40855 +} __no_const;
40856
40857 void amd_report_gart_errors(bool);
40858 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40859 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40860 index 57ea7f4..af06b76 100644
40861 --- a/drivers/firewire/core-card.c
40862 +++ b/drivers/firewire/core-card.c
40863 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40864 const struct fw_card_driver *driver,
40865 struct device *device)
40866 {
40867 - static atomic_t index = ATOMIC_INIT(-1);
40868 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
40869
40870 - card->index = atomic_inc_return(&index);
40871 + card->index = atomic_inc_return_unchecked(&index);
40872 card->driver = driver;
40873 card->device = device;
40874 card->current_tlabel = 0;
40875 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40876
40877 void fw_core_remove_card(struct fw_card *card)
40878 {
40879 - struct fw_card_driver dummy_driver = dummy_driver_template;
40880 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
40881
40882 card->driver->update_phy_reg(card, 4,
40883 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40884 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40885 index 2c6d5e1..a2cca6b 100644
40886 --- a/drivers/firewire/core-device.c
40887 +++ b/drivers/firewire/core-device.c
40888 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40889 struct config_rom_attribute {
40890 struct device_attribute attr;
40891 u32 key;
40892 -};
40893 +} __do_const;
40894
40895 static ssize_t show_immediate(struct device *dev,
40896 struct device_attribute *dattr, char *buf)
40897 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40898 index eb6935c..3cc2bfa 100644
40899 --- a/drivers/firewire/core-transaction.c
40900 +++ b/drivers/firewire/core-transaction.c
40901 @@ -38,6 +38,7 @@
40902 #include <linux/timer.h>
40903 #include <linux/types.h>
40904 #include <linux/workqueue.h>
40905 +#include <linux/sched.h>
40906
40907 #include <asm/byteorder.h>
40908
40909 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40910 index e1480ff6..1a429bd 100644
40911 --- a/drivers/firewire/core.h
40912 +++ b/drivers/firewire/core.h
40913 @@ -111,6 +111,7 @@ struct fw_card_driver {
40914
40915 int (*stop_iso)(struct fw_iso_context *ctx);
40916 };
40917 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40918
40919 void fw_card_initialize(struct fw_card *card,
40920 const struct fw_card_driver *driver, struct device *device);
40921 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40922 index a66a321..f6caf20 100644
40923 --- a/drivers/firewire/ohci.c
40924 +++ b/drivers/firewire/ohci.c
40925 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40926 be32_to_cpu(ohci->next_header));
40927 }
40928
40929 +#ifndef CONFIG_GRKERNSEC
40930 if (param_remote_dma) {
40931 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40932 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40933 }
40934 +#endif
40935
40936 spin_unlock_irq(&ohci->lock);
40937
40938 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40939 unsigned long flags;
40940 int n, ret = 0;
40941
40942 +#ifndef CONFIG_GRKERNSEC
40943 if (param_remote_dma)
40944 return 0;
40945 +#endif
40946
40947 /*
40948 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40949 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40950 index 94a58a0..f5eba42 100644
40951 --- a/drivers/firmware/dmi-id.c
40952 +++ b/drivers/firmware/dmi-id.c
40953 @@ -16,7 +16,7 @@
40954 struct dmi_device_attribute{
40955 struct device_attribute dev_attr;
40956 int field;
40957 -};
40958 +} __do_const;
40959 #define to_dmi_dev_attr(_dev_attr) \
40960 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40961
40962 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40963 index 17afc51..0ef90cd 100644
40964 --- a/drivers/firmware/dmi_scan.c
40965 +++ b/drivers/firmware/dmi_scan.c
40966 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40967 if (buf == NULL)
40968 return -1;
40969
40970 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40971 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40972
40973 dmi_unmap(buf);
40974 return 0;
40975 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40976 index 5b53d61..72cee96 100644
40977 --- a/drivers/firmware/efi/cper.c
40978 +++ b/drivers/firmware/efi/cper.c
40979 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40980 */
40981 u64 cper_next_record_id(void)
40982 {
40983 - static atomic64_t seq;
40984 + static atomic64_unchecked_t seq;
40985
40986 - if (!atomic64_read(&seq))
40987 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40988 + if (!atomic64_read_unchecked(&seq))
40989 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40990
40991 - return atomic64_inc_return(&seq);
40992 + return atomic64_inc_return_unchecked(&seq);
40993 }
40994 EXPORT_SYMBOL_GPL(cper_next_record_id);
40995
40996 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40997 index 64ecbb5..d921eb3 100644
40998 --- a/drivers/firmware/efi/efi.c
40999 +++ b/drivers/firmware/efi/efi.c
41000 @@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
41001 };
41002
41003 static struct efivars generic_efivars;
41004 -static struct efivar_operations generic_ops;
41005 +static efivar_operations_no_const generic_ops __read_only;
41006
41007 static int generic_ops_register(void)
41008 {
41009 - generic_ops.get_variable = efi.get_variable;
41010 - generic_ops.set_variable = efi.set_variable;
41011 - generic_ops.get_next_variable = efi.get_next_variable;
41012 - generic_ops.query_variable_store = efi_query_variable_store;
41013 + pax_open_kernel();
41014 + *(void **)&generic_ops.get_variable = efi.get_variable;
41015 + *(void **)&generic_ops.set_variable = efi.set_variable;
41016 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41017 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41018 + pax_close_kernel();
41019
41020 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41021 }
41022 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41023 index f256ecd..387dcb1 100644
41024 --- a/drivers/firmware/efi/efivars.c
41025 +++ b/drivers/firmware/efi/efivars.c
41026 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41027 static int
41028 create_efivars_bin_attributes(void)
41029 {
41030 - struct bin_attribute *attr;
41031 + bin_attribute_no_const *attr;
41032 int error;
41033
41034 /* new_var */
41035 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41036 index 2f569aa..c95f4fb 100644
41037 --- a/drivers/firmware/google/memconsole.c
41038 +++ b/drivers/firmware/google/memconsole.c
41039 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41040 if (!found_memconsole())
41041 return -ENODEV;
41042
41043 - memconsole_bin_attr.size = memconsole_length;
41044 + pax_open_kernel();
41045 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41046 + pax_close_kernel();
41047 +
41048 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41049 }
41050
41051 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41052 index fe49ec3..1ade794 100644
41053 --- a/drivers/gpio/gpio-em.c
41054 +++ b/drivers/gpio/gpio-em.c
41055 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41056 struct em_gio_priv *p;
41057 struct resource *io[2], *irq[2];
41058 struct gpio_chip *gpio_chip;
41059 - struct irq_chip *irq_chip;
41060 + irq_chip_no_const *irq_chip;
41061 const char *name = dev_name(&pdev->dev);
41062 int ret;
41063
41064 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41065 index 3784e81..73637b5 100644
41066 --- a/drivers/gpio/gpio-ich.c
41067 +++ b/drivers/gpio/gpio-ich.c
41068 @@ -94,7 +94,7 @@ struct ichx_desc {
41069 * this option allows driver caching written output values
41070 */
41071 bool use_outlvl_cache;
41072 -};
41073 +} __do_const;
41074
41075 static struct {
41076 spinlock_t lock;
41077 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41078 index bf6c094..6573caf 100644
41079 --- a/drivers/gpio/gpio-rcar.c
41080 +++ b/drivers/gpio/gpio-rcar.c
41081 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41082 struct gpio_rcar_priv *p;
41083 struct resource *io, *irq;
41084 struct gpio_chip *gpio_chip;
41085 - struct irq_chip *irq_chip;
41086 + irq_chip_no_const *irq_chip;
41087 struct device *dev = &pdev->dev;
41088 const char *name = dev_name(dev);
41089 int ret;
41090 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41091 index dbf28fa..04dad4e 100644
41092 --- a/drivers/gpio/gpio-vr41xx.c
41093 +++ b/drivers/gpio/gpio-vr41xx.c
41094 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41095 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41096 maskl, pendl, maskh, pendh);
41097
41098 - atomic_inc(&irq_err_count);
41099 + atomic_inc_unchecked(&irq_err_count);
41100
41101 return -EINVAL;
41102 }
41103 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41104 index c68d037..2f4f9a9 100644
41105 --- a/drivers/gpio/gpiolib.c
41106 +++ b/drivers/gpio/gpiolib.c
41107 @@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41108 }
41109
41110 if (gpiochip->irqchip) {
41111 - gpiochip->irqchip->irq_request_resources = NULL;
41112 - gpiochip->irqchip->irq_release_resources = NULL;
41113 + pax_open_kernel();
41114 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41115 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41116 + pax_close_kernel();
41117 gpiochip->irqchip = NULL;
41118 }
41119 }
41120 @@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41121 gpiochip->irqchip = NULL;
41122 return -EINVAL;
41123 }
41124 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41125 - irqchip->irq_release_resources = gpiochip_irq_relres;
41126 +
41127 + pax_open_kernel();
41128 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41129 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41130 + pax_close_kernel();
41131
41132 /*
41133 * Prepare the mapping since the irqchip shall be orthogonal to
41134 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41135 index 90e7730..3b41807 100644
41136 --- a/drivers/gpu/drm/drm_crtc.c
41137 +++ b/drivers/gpu/drm/drm_crtc.c
41138 @@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41139 goto done;
41140 }
41141
41142 - if (copy_to_user(&enum_ptr[copied].name,
41143 + if (copy_to_user(enum_ptr[copied].name,
41144 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41145 ret = -EFAULT;
41146 goto done;
41147 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41148 index 3242e20..7e4f621 100644
41149 --- a/drivers/gpu/drm/drm_drv.c
41150 +++ b/drivers/gpu/drm/drm_drv.c
41151 @@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41152
41153 drm_device_set_unplugged(dev);
41154
41155 - if (dev->open_count == 0) {
41156 + if (local_read(&dev->open_count) == 0) {
41157 drm_put_dev(dev);
41158 }
41159 mutex_unlock(&drm_global_mutex);
41160 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41161 index 79d5221..7ff73496 100644
41162 --- a/drivers/gpu/drm/drm_fops.c
41163 +++ b/drivers/gpu/drm/drm_fops.c
41164 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41165 return PTR_ERR(minor);
41166
41167 dev = minor->dev;
41168 - if (!dev->open_count++)
41169 + if (local_inc_return(&dev->open_count) == 1)
41170 need_setup = 1;
41171
41172 /* share address_space across all char-devs of a single device */
41173 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41174 return 0;
41175
41176 err_undo:
41177 - dev->open_count--;
41178 + local_dec(&dev->open_count);
41179 drm_minor_release(minor);
41180 return retcode;
41181 }
41182 @@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41183
41184 mutex_lock(&drm_global_mutex);
41185
41186 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41187 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41188
41189 mutex_lock(&dev->struct_mutex);
41190 list_del(&file_priv->lhead);
41191 @@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41192 * Begin inline drm_release
41193 */
41194
41195 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41196 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41197 task_pid_nr(current),
41198 (long)old_encode_dev(file_priv->minor->kdev->devt),
41199 - dev->open_count);
41200 + local_read(&dev->open_count));
41201
41202 /* Release any auth tokens that might point to this file_priv,
41203 (do that under the drm_global_mutex) */
41204 @@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41205 * End inline drm_release
41206 */
41207
41208 - if (!--dev->open_count) {
41209 + if (local_dec_and_test(&dev->open_count)) {
41210 retcode = drm_lastclose(dev);
41211 if (drm_device_is_unplugged(dev))
41212 drm_put_dev(dev);
41213 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41214 index 3d2e91c..d31c4c9 100644
41215 --- a/drivers/gpu/drm/drm_global.c
41216 +++ b/drivers/gpu/drm/drm_global.c
41217 @@ -36,7 +36,7 @@
41218 struct drm_global_item {
41219 struct mutex mutex;
41220 void *object;
41221 - int refcount;
41222 + atomic_t refcount;
41223 };
41224
41225 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41226 @@ -49,7 +49,7 @@ void drm_global_init(void)
41227 struct drm_global_item *item = &glob[i];
41228 mutex_init(&item->mutex);
41229 item->object = NULL;
41230 - item->refcount = 0;
41231 + atomic_set(&item->refcount, 0);
41232 }
41233 }
41234
41235 @@ -59,7 +59,7 @@ void drm_global_release(void)
41236 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41237 struct drm_global_item *item = &glob[i];
41238 BUG_ON(item->object != NULL);
41239 - BUG_ON(item->refcount != 0);
41240 + BUG_ON(atomic_read(&item->refcount) != 0);
41241 }
41242 }
41243
41244 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41245 struct drm_global_item *item = &glob[ref->global_type];
41246
41247 mutex_lock(&item->mutex);
41248 - if (item->refcount == 0) {
41249 + if (atomic_read(&item->refcount) == 0) {
41250 item->object = kzalloc(ref->size, GFP_KERNEL);
41251 if (unlikely(item->object == NULL)) {
41252 ret = -ENOMEM;
41253 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41254 goto out_err;
41255
41256 }
41257 - ++item->refcount;
41258 + atomic_inc(&item->refcount);
41259 ref->object = item->object;
41260 mutex_unlock(&item->mutex);
41261 return 0;
41262 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41263 struct drm_global_item *item = &glob[ref->global_type];
41264
41265 mutex_lock(&item->mutex);
41266 - BUG_ON(item->refcount == 0);
41267 + BUG_ON(atomic_read(&item->refcount) == 0);
41268 BUG_ON(ref->object != item->object);
41269 - if (--item->refcount == 0) {
41270 + if (atomic_dec_and_test(&item->refcount)) {
41271 ref->release(ref);
41272 item->object = NULL;
41273 }
41274 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41275 index ecaf0fa..a49cee9 100644
41276 --- a/drivers/gpu/drm/drm_info.c
41277 +++ b/drivers/gpu/drm/drm_info.c
41278 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41279 struct drm_local_map *map;
41280 struct drm_map_list *r_list;
41281
41282 - /* Hardcoded from _DRM_FRAME_BUFFER,
41283 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41284 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41285 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41286 + static const char * const types[] = {
41287 + [_DRM_FRAME_BUFFER] = "FB",
41288 + [_DRM_REGISTERS] = "REG",
41289 + [_DRM_SHM] = "SHM",
41290 + [_DRM_AGP] = "AGP",
41291 + [_DRM_SCATTER_GATHER] = "SG",
41292 + [_DRM_CONSISTENT] = "PCI"};
41293 const char *type;
41294 int i;
41295
41296 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41297 map = r_list->map;
41298 if (!map)
41299 continue;
41300 - if (map->type < 0 || map->type > 5)
41301 + if (map->type >= ARRAY_SIZE(types))
41302 type = "??";
41303 else
41304 type = types[map->type];
41305 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41306 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41307 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41308 vma->vm_flags & VM_IO ? 'i' : '-',
41309 +#ifdef CONFIG_GRKERNSEC_HIDESYM
41310 + 0);
41311 +#else
41312 vma->vm_pgoff);
41313 +#endif
41314
41315 #if defined(__i386__)
41316 pgprot = pgprot_val(vma->vm_page_prot);
41317 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41318 index 2f4c4343..dd12cd2 100644
41319 --- a/drivers/gpu/drm/drm_ioc32.c
41320 +++ b/drivers/gpu/drm/drm_ioc32.c
41321 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41322 request = compat_alloc_user_space(nbytes);
41323 if (!access_ok(VERIFY_WRITE, request, nbytes))
41324 return -EFAULT;
41325 - list = (struct drm_buf_desc *) (request + 1);
41326 + list = (struct drm_buf_desc __user *) (request + 1);
41327
41328 if (__put_user(count, &request->count)
41329 || __put_user(list, &request->list))
41330 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41331 request = compat_alloc_user_space(nbytes);
41332 if (!access_ok(VERIFY_WRITE, request, nbytes))
41333 return -EFAULT;
41334 - list = (struct drm_buf_pub *) (request + 1);
41335 + list = (struct drm_buf_pub __user *) (request + 1);
41336
41337 if (__put_user(count, &request->count)
41338 || __put_user(list, &request->list))
41339 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41340 return 0;
41341 }
41342
41343 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
41344 +drm_ioctl_compat_t drm_compat_ioctls[] = {
41345 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41346 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41347 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41348 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41349 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41350 {
41351 unsigned int nr = DRM_IOCTL_NR(cmd);
41352 - drm_ioctl_compat_t *fn;
41353 int ret;
41354
41355 /* Assume that ioctls without an explicit compat routine will just
41356 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41357 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41358 return drm_ioctl(filp, cmd, arg);
41359
41360 - fn = drm_compat_ioctls[nr];
41361 -
41362 - if (fn != NULL)
41363 - ret = (*fn) (filp, cmd, arg);
41364 + if (drm_compat_ioctls[nr] != NULL)
41365 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41366 else
41367 ret = drm_ioctl(filp, cmd, arg);
41368
41369 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41370 index 40be746..fd78faf 100644
41371 --- a/drivers/gpu/drm/drm_ioctl.c
41372 +++ b/drivers/gpu/drm/drm_ioctl.c
41373 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41374 struct drm_file *file_priv = filp->private_data;
41375 struct drm_device *dev;
41376 const struct drm_ioctl_desc *ioctl = NULL;
41377 - drm_ioctl_t *func;
41378 + drm_ioctl_no_const_t func;
41379 unsigned int nr = DRM_IOCTL_NR(cmd);
41380 int retcode = -EINVAL;
41381 char stack_kdata[128];
41382 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41383 index d4d16ed..8fb0b51 100644
41384 --- a/drivers/gpu/drm/i810/i810_drv.h
41385 +++ b/drivers/gpu/drm/i810/i810_drv.h
41386 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41387 int page_flipping;
41388
41389 wait_queue_head_t irq_queue;
41390 - atomic_t irq_received;
41391 - atomic_t irq_emitted;
41392 + atomic_unchecked_t irq_received;
41393 + atomic_unchecked_t irq_emitted;
41394
41395 int front_offset;
41396 } drm_i810_private_t;
41397 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41398 index 2d23e57..1c61d41 100644
41399 --- a/drivers/gpu/drm/i915/i915_dma.c
41400 +++ b/drivers/gpu/drm/i915/i915_dma.c
41401 @@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41402 * locking inversion with the driver load path. And the access here is
41403 * completely racy anyway. So don't bother with locking for now.
41404 */
41405 - return dev->open_count == 0;
41406 + return local_read(&dev->open_count) == 0;
41407 }
41408
41409 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41410 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41411 index 60998fc..3b244bc 100644
41412 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41413 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41414 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41415
41416 static int
41417 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41418 - int count)
41419 + unsigned int count)
41420 {
41421 - int i;
41422 + unsigned int i;
41423 unsigned relocs_total = 0;
41424 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41425
41426 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41427 index 2e0613e..a8b94d9 100644
41428 --- a/drivers/gpu/drm/i915/i915_ioc32.c
41429 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
41430 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41431 (unsigned long)request);
41432 }
41433
41434 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41435 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
41436 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41437 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41438 [DRM_I915_GETPARAM] = compat_i915_getparam,
41439 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41440 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41441 {
41442 unsigned int nr = DRM_IOCTL_NR(cmd);
41443 - drm_ioctl_compat_t *fn = NULL;
41444 int ret;
41445
41446 if (nr < DRM_COMMAND_BASE)
41447 return drm_compat_ioctl(filp, cmd, arg);
41448
41449 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41450 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41451 -
41452 - if (fn != NULL)
41453 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41454 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41455 ret = (*fn) (filp, cmd, arg);
41456 - else
41457 + } else
41458 ret = drm_ioctl(filp, cmd, arg);
41459
41460 return ret;
41461 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41462 index 8663c21..46f2cbf 100644
41463 --- a/drivers/gpu/drm/i915/intel_display.c
41464 +++ b/drivers/gpu/drm/i915/intel_display.c
41465 @@ -12439,13 +12439,13 @@ struct intel_quirk {
41466 int subsystem_vendor;
41467 int subsystem_device;
41468 void (*hook)(struct drm_device *dev);
41469 -};
41470 +} __do_const;
41471
41472 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41473 struct intel_dmi_quirk {
41474 void (*hook)(struct drm_device *dev);
41475 const struct dmi_system_id (*dmi_id_list)[];
41476 -};
41477 +} __do_const;
41478
41479 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41480 {
41481 @@ -12453,18 +12453,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41482 return 1;
41483 }
41484
41485 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41486 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
41487 {
41488 - .dmi_id_list = &(const struct dmi_system_id[]) {
41489 - {
41490 - .callback = intel_dmi_reverse_brightness,
41491 - .ident = "NCR Corporation",
41492 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41493 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
41494 - },
41495 - },
41496 - { } /* terminating entry */
41497 + .callback = intel_dmi_reverse_brightness,
41498 + .ident = "NCR Corporation",
41499 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41500 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
41501 },
41502 + },
41503 + { } /* terminating entry */
41504 +};
41505 +
41506 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41507 + {
41508 + .dmi_id_list = &intel_dmi_quirks_table,
41509 .hook = quirk_invert_brightness,
41510 },
41511 };
41512 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41513 index fe45321..836fdca 100644
41514 --- a/drivers/gpu/drm/mga/mga_drv.h
41515 +++ b/drivers/gpu/drm/mga/mga_drv.h
41516 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41517 u32 clear_cmd;
41518 u32 maccess;
41519
41520 - atomic_t vbl_received; /**< Number of vblanks received. */
41521 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41522 wait_queue_head_t fence_queue;
41523 - atomic_t last_fence_retired;
41524 + atomic_unchecked_t last_fence_retired;
41525 u32 next_fence_to_post;
41526
41527 unsigned int fb_cpp;
41528 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41529 index 729bfd5..ead8823 100644
41530 --- a/drivers/gpu/drm/mga/mga_ioc32.c
41531 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
41532 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41533 return 0;
41534 }
41535
41536 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
41537 +drm_ioctl_compat_t mga_compat_ioctls[] = {
41538 [DRM_MGA_INIT] = compat_mga_init,
41539 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41540 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41541 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41542 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41543 {
41544 unsigned int nr = DRM_IOCTL_NR(cmd);
41545 - drm_ioctl_compat_t *fn = NULL;
41546 int ret;
41547
41548 if (nr < DRM_COMMAND_BASE)
41549 return drm_compat_ioctl(filp, cmd, arg);
41550
41551 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41552 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41553 -
41554 - if (fn != NULL)
41555 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41556 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41557 ret = (*fn) (filp, cmd, arg);
41558 - else
41559 + } else
41560 ret = drm_ioctl(filp, cmd, arg);
41561
41562 return ret;
41563 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41564 index 1b071b8..de8601a 100644
41565 --- a/drivers/gpu/drm/mga/mga_irq.c
41566 +++ b/drivers/gpu/drm/mga/mga_irq.c
41567 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41568 if (crtc != 0)
41569 return 0;
41570
41571 - return atomic_read(&dev_priv->vbl_received);
41572 + return atomic_read_unchecked(&dev_priv->vbl_received);
41573 }
41574
41575
41576 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41577 /* VBLANK interrupt */
41578 if (status & MGA_VLINEPEN) {
41579 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41580 - atomic_inc(&dev_priv->vbl_received);
41581 + atomic_inc_unchecked(&dev_priv->vbl_received);
41582 drm_handle_vblank(dev, 0);
41583 handled = 1;
41584 }
41585 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41586 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41587 MGA_WRITE(MGA_PRIMEND, prim_end);
41588
41589 - atomic_inc(&dev_priv->last_fence_retired);
41590 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
41591 wake_up(&dev_priv->fence_queue);
41592 handled = 1;
41593 }
41594 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41595 * using fences.
41596 */
41597 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41598 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41599 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41600 - *sequence) <= (1 << 23)));
41601
41602 *sequence = cur_fence;
41603 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41604 index dae2c96..324dbe4 100644
41605 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41606 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41607 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41608 struct bit_table {
41609 const char id;
41610 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41611 -};
41612 +} __no_const;
41613
41614 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41615
41616 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41617 index b02b024..aed7bad 100644
41618 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41619 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41620 @@ -119,7 +119,6 @@ struct nouveau_drm {
41621 struct drm_global_reference mem_global_ref;
41622 struct ttm_bo_global_ref bo_global_ref;
41623 struct ttm_bo_device bdev;
41624 - atomic_t validate_sequence;
41625 int (*move)(struct nouveau_channel *,
41626 struct ttm_buffer_object *,
41627 struct ttm_mem_reg *, struct ttm_mem_reg *);
41628 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41629 index 462679a..88e32a7 100644
41630 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41631 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41632 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41633 unsigned long arg)
41634 {
41635 unsigned int nr = DRM_IOCTL_NR(cmd);
41636 - drm_ioctl_compat_t *fn = NULL;
41637 + drm_ioctl_compat_t fn = NULL;
41638 int ret;
41639
41640 if (nr < DRM_COMMAND_BASE)
41641 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41642 index 53874b7..1db0a68 100644
41643 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41644 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41645 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41646 }
41647
41648 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41649 - nouveau_vram_manager_init,
41650 - nouveau_vram_manager_fini,
41651 - nouveau_vram_manager_new,
41652 - nouveau_vram_manager_del,
41653 - nouveau_vram_manager_debug
41654 + .init = nouveau_vram_manager_init,
41655 + .takedown = nouveau_vram_manager_fini,
41656 + .get_node = nouveau_vram_manager_new,
41657 + .put_node = nouveau_vram_manager_del,
41658 + .debug = nouveau_vram_manager_debug
41659 };
41660
41661 static int
41662 @@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41663 }
41664
41665 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41666 - nouveau_gart_manager_init,
41667 - nouveau_gart_manager_fini,
41668 - nouveau_gart_manager_new,
41669 - nouveau_gart_manager_del,
41670 - nouveau_gart_manager_debug
41671 + .init = nouveau_gart_manager_init,
41672 + .takedown = nouveau_gart_manager_fini,
41673 + .get_node = nouveau_gart_manager_new,
41674 + .put_node = nouveau_gart_manager_del,
41675 + .debug = nouveau_gart_manager_debug
41676 };
41677
41678 /*XXX*/
41679 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41680 }
41681
41682 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41683 - nv04_gart_manager_init,
41684 - nv04_gart_manager_fini,
41685 - nv04_gart_manager_new,
41686 - nv04_gart_manager_del,
41687 - nv04_gart_manager_debug
41688 + .init = nv04_gart_manager_init,
41689 + .takedown = nv04_gart_manager_fini,
41690 + .get_node = nv04_gart_manager_new,
41691 + .put_node = nv04_gart_manager_del,
41692 + .debug = nv04_gart_manager_debug
41693 };
41694
41695 int
41696 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41697 index c7592ec..dd45ebc 100644
41698 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41699 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41700 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41701 * locking inversion with the driver load path. And the access here is
41702 * completely racy anyway. So don't bother with locking for now.
41703 */
41704 - return dev->open_count == 0;
41705 + return local_read(&dev->open_count) == 0;
41706 }
41707
41708 static const struct vga_switcheroo_client_ops
41709 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41710 index eb89653..613cf71 100644
41711 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
41712 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41713 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41714 int ret;
41715
41716 mutex_lock(&qdev->async_io_mutex);
41717 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41718 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41719 if (qdev->last_sent_io_cmd > irq_num) {
41720 if (intr)
41721 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41722 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41723 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41724 else
41725 ret = wait_event_timeout(qdev->io_cmd_event,
41726 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41727 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41728 /* 0 is timeout, just bail the "hw" has gone away */
41729 if (ret <= 0)
41730 goto out;
41731 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41732 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41733 }
41734 outb(val, addr);
41735 qdev->last_sent_io_cmd = irq_num + 1;
41736 if (intr)
41737 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41738 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41739 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41740 else
41741 ret = wait_event_timeout(qdev->io_cmd_event,
41742 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41743 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41744 out:
41745 if (ret > 0)
41746 ret = 0;
41747 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41748 index c3c2bbd..bc3c0fb 100644
41749 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41750 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41751 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41752 struct drm_info_node *node = (struct drm_info_node *) m->private;
41753 struct qxl_device *qdev = node->minor->dev->dev_private;
41754
41755 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41756 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41757 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41758 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41759 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41760 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41761 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41762 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41763 seq_printf(m, "%d\n", qdev->irq_received_error);
41764 return 0;
41765 }
41766 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41767 index 36ed40b..0397633 100644
41768 --- a/drivers/gpu/drm/qxl/qxl_drv.h
41769 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
41770 @@ -290,10 +290,10 @@ struct qxl_device {
41771 unsigned int last_sent_io_cmd;
41772
41773 /* interrupt handling */
41774 - atomic_t irq_received;
41775 - atomic_t irq_received_display;
41776 - atomic_t irq_received_cursor;
41777 - atomic_t irq_received_io_cmd;
41778 + atomic_unchecked_t irq_received;
41779 + atomic_unchecked_t irq_received_display;
41780 + atomic_unchecked_t irq_received_cursor;
41781 + atomic_unchecked_t irq_received_io_cmd;
41782 unsigned irq_received_error;
41783 wait_queue_head_t display_event;
41784 wait_queue_head_t cursor_event;
41785 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41786 index b110883..dd06418 100644
41787 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41788 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41789 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41790
41791 /* TODO copy slow path code from i915 */
41792 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41793 - unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
41794 + unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
41795
41796 {
41797 struct qxl_drawable *draw = fb_cmd;
41798 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41799 struct drm_qxl_reloc reloc;
41800
41801 if (copy_from_user(&reloc,
41802 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41803 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41804 sizeof(reloc))) {
41805 ret = -EFAULT;
41806 goto out_free_bos;
41807 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41808
41809 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41810
41811 - struct drm_qxl_command *commands =
41812 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41813 + struct drm_qxl_command __user *commands =
41814 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41815
41816 - if (copy_from_user(&user_cmd, &commands[cmd_num],
41817 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41818 sizeof(user_cmd)))
41819 return -EFAULT;
41820
41821 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41822 index 0bf1e20..42a7310 100644
41823 --- a/drivers/gpu/drm/qxl/qxl_irq.c
41824 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
41825 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41826 if (!pending)
41827 return IRQ_NONE;
41828
41829 - atomic_inc(&qdev->irq_received);
41830 + atomic_inc_unchecked(&qdev->irq_received);
41831
41832 if (pending & QXL_INTERRUPT_DISPLAY) {
41833 - atomic_inc(&qdev->irq_received_display);
41834 + atomic_inc_unchecked(&qdev->irq_received_display);
41835 wake_up_all(&qdev->display_event);
41836 qxl_queue_garbage_collect(qdev, false);
41837 }
41838 if (pending & QXL_INTERRUPT_CURSOR) {
41839 - atomic_inc(&qdev->irq_received_cursor);
41840 + atomic_inc_unchecked(&qdev->irq_received_cursor);
41841 wake_up_all(&qdev->cursor_event);
41842 }
41843 if (pending & QXL_INTERRUPT_IO_CMD) {
41844 - atomic_inc(&qdev->irq_received_io_cmd);
41845 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41846 wake_up_all(&qdev->io_cmd_event);
41847 }
41848 if (pending & QXL_INTERRUPT_ERROR) {
41849 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41850 init_waitqueue_head(&qdev->io_cmd_event);
41851 INIT_WORK(&qdev->client_monitors_config_work,
41852 qxl_client_monitors_config_work_func);
41853 - atomic_set(&qdev->irq_received, 0);
41854 - atomic_set(&qdev->irq_received_display, 0);
41855 - atomic_set(&qdev->irq_received_cursor, 0);
41856 - atomic_set(&qdev->irq_received_io_cmd, 0);
41857 + atomic_set_unchecked(&qdev->irq_received, 0);
41858 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41859 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41860 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41861 qdev->irq_received_error = 0;
41862 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41863 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41864 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41865 index 71a1bae..cb1f103 100644
41866 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41867 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41868 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41869 }
41870 }
41871
41872 -static struct vm_operations_struct qxl_ttm_vm_ops;
41873 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41874 static const struct vm_operations_struct *ttm_vm_ops;
41875
41876 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41877 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41878 return r;
41879 if (unlikely(ttm_vm_ops == NULL)) {
41880 ttm_vm_ops = vma->vm_ops;
41881 + pax_open_kernel();
41882 qxl_ttm_vm_ops = *ttm_vm_ops;
41883 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41884 + pax_close_kernel();
41885 }
41886 vma->vm_ops = &qxl_ttm_vm_ops;
41887 return 0;
41888 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41889 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41890 {
41891 #if defined(CONFIG_DEBUG_FS)
41892 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41893 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41894 - unsigned i;
41895 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41896 + {
41897 + .name = "qxl_mem_mm",
41898 + .show = &qxl_mm_dump_table,
41899 + },
41900 + {
41901 + .name = "qxl_surf_mm",
41902 + .show = &qxl_mm_dump_table,
41903 + }
41904 + };
41905
41906 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41907 - if (i == 0)
41908 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41909 - else
41910 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41911 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41912 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41913 - qxl_mem_types_list[i].driver_features = 0;
41914 - if (i == 0)
41915 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41916 - else
41917 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41918 + pax_open_kernel();
41919 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41920 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41921 + pax_close_kernel();
41922
41923 - }
41924 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41925 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41926 #else
41927 return 0;
41928 #endif
41929 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41930 index 59459fe..be26b31 100644
41931 --- a/drivers/gpu/drm/r128/r128_cce.c
41932 +++ b/drivers/gpu/drm/r128/r128_cce.c
41933 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41934
41935 /* GH: Simple idle check.
41936 */
41937 - atomic_set(&dev_priv->idle_count, 0);
41938 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41939
41940 /* We don't support anything other than bus-mastering ring mode,
41941 * but the ring can be in either AGP or PCI space for the ring
41942 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41943 index 5bf3f5f..7000661 100644
41944 --- a/drivers/gpu/drm/r128/r128_drv.h
41945 +++ b/drivers/gpu/drm/r128/r128_drv.h
41946 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41947 int is_pci;
41948 unsigned long cce_buffers_offset;
41949
41950 - atomic_t idle_count;
41951 + atomic_unchecked_t idle_count;
41952
41953 int page_flipping;
41954 int current_page;
41955 u32 crtc_offset;
41956 u32 crtc_offset_cntl;
41957
41958 - atomic_t vbl_received;
41959 + atomic_unchecked_t vbl_received;
41960
41961 u32 color_fmt;
41962 unsigned int front_offset;
41963 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41964 index 663f38c..c689495 100644
41965 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41966 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41967 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41968 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41969 }
41970
41971 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41972 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41973 [DRM_R128_INIT] = compat_r128_init,
41974 [DRM_R128_DEPTH] = compat_r128_depth,
41975 [DRM_R128_STIPPLE] = compat_r128_stipple,
41976 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41977 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41978 {
41979 unsigned int nr = DRM_IOCTL_NR(cmd);
41980 - drm_ioctl_compat_t *fn = NULL;
41981 int ret;
41982
41983 if (nr < DRM_COMMAND_BASE)
41984 return drm_compat_ioctl(filp, cmd, arg);
41985
41986 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41987 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41988 -
41989 - if (fn != NULL)
41990 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41991 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41992 ret = (*fn) (filp, cmd, arg);
41993 - else
41994 + } else
41995 ret = drm_ioctl(filp, cmd, arg);
41996
41997 return ret;
41998 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41999 index c2ae496..30b5993 100644
42000 --- a/drivers/gpu/drm/r128/r128_irq.c
42001 +++ b/drivers/gpu/drm/r128/r128_irq.c
42002 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42003 if (crtc != 0)
42004 return 0;
42005
42006 - return atomic_read(&dev_priv->vbl_received);
42007 + return atomic_read_unchecked(&dev_priv->vbl_received);
42008 }
42009
42010 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42011 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42012 /* VBLANK interrupt */
42013 if (status & R128_CRTC_VBLANK_INT) {
42014 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42015 - atomic_inc(&dev_priv->vbl_received);
42016 + atomic_inc_unchecked(&dev_priv->vbl_received);
42017 drm_handle_vblank(dev, 0);
42018 return IRQ_HANDLED;
42019 }
42020 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42021 index 575e986..66e62ca 100644
42022 --- a/drivers/gpu/drm/r128/r128_state.c
42023 +++ b/drivers/gpu/drm/r128/r128_state.c
42024 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42025
42026 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42027 {
42028 - if (atomic_read(&dev_priv->idle_count) == 0)
42029 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42030 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42031 else
42032 - atomic_set(&dev_priv->idle_count, 0);
42033 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42034 }
42035
42036 #endif
42037 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42038 index 4a85bb6..aaea819 100644
42039 --- a/drivers/gpu/drm/radeon/mkregtable.c
42040 +++ b/drivers/gpu/drm/radeon/mkregtable.c
42041 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42042 regex_t mask_rex;
42043 regmatch_t match[4];
42044 char buf[1024];
42045 - size_t end;
42046 + long end;
42047 int len;
42048 int done = 0;
42049 int r;
42050 unsigned o;
42051 struct offset *offset;
42052 char last_reg_s[10];
42053 - int last_reg;
42054 + unsigned long last_reg;
42055
42056 if (regcomp
42057 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42058 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42059 index 5d4416f..80b7fc4 100644
42060 --- a/drivers/gpu/drm/radeon/radeon_device.c
42061 +++ b/drivers/gpu/drm/radeon/radeon_device.c
42062 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42063 * locking inversion with the driver load path. And the access here is
42064 * completely racy anyway. So don't bother with locking for now.
42065 */
42066 - return dev->open_count == 0;
42067 + return local_read(&dev->open_count) == 0;
42068 }
42069
42070 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42071 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42072 index dafd812..1bf20c7 100644
42073 --- a/drivers/gpu/drm/radeon/radeon_drv.h
42074 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42075 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42076
42077 /* SW interrupt */
42078 wait_queue_head_t swi_queue;
42079 - atomic_t swi_emitted;
42080 + atomic_unchecked_t swi_emitted;
42081 int vblank_crtc;
42082 uint32_t irq_enable_reg;
42083 uint32_t r500_disp_irq_reg;
42084 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42085 index 0b98ea1..0881827 100644
42086 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42087 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42088 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42089 request = compat_alloc_user_space(sizeof(*request));
42090 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42091 || __put_user(req32.param, &request->param)
42092 - || __put_user((void __user *)(unsigned long)req32.value,
42093 + || __put_user((unsigned long)req32.value,
42094 &request->value))
42095 return -EFAULT;
42096
42097 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42098 #define compat_radeon_cp_setparam NULL
42099 #endif /* X86_64 || IA64 */
42100
42101 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42102 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42103 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42104 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42105 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42106 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42107 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42108 {
42109 unsigned int nr = DRM_IOCTL_NR(cmd);
42110 - drm_ioctl_compat_t *fn = NULL;
42111 int ret;
42112
42113 if (nr < DRM_COMMAND_BASE)
42114 return drm_compat_ioctl(filp, cmd, arg);
42115
42116 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42117 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42118 -
42119 - if (fn != NULL)
42120 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42121 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42122 ret = (*fn) (filp, cmd, arg);
42123 - else
42124 + } else
42125 ret = drm_ioctl(filp, cmd, arg);
42126
42127 return ret;
42128 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42129 index 244b19b..c19226d 100644
42130 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42131 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42132 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42133 unsigned int ret;
42134 RING_LOCALS;
42135
42136 - atomic_inc(&dev_priv->swi_emitted);
42137 - ret = atomic_read(&dev_priv->swi_emitted);
42138 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42139 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42140
42141 BEGIN_RING(4);
42142 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42143 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42144 drm_radeon_private_t *dev_priv =
42145 (drm_radeon_private_t *) dev->dev_private;
42146
42147 - atomic_set(&dev_priv->swi_emitted, 0);
42148 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42149 init_waitqueue_head(&dev_priv->swi_queue);
42150
42151 dev->max_vblank_count = 0x001fffff;
42152 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42153 index 23bb64f..69d7234 100644
42154 --- a/drivers/gpu/drm/radeon/radeon_state.c
42155 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42156 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42157 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42158 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42159
42160 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42161 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42162 sarea_priv->nbox * sizeof(depth_boxes[0])))
42163 return -EFAULT;
42164
42165 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42166 {
42167 drm_radeon_private_t *dev_priv = dev->dev_private;
42168 drm_radeon_getparam_t *param = data;
42169 - int value;
42170 + int value = 0;
42171
42172 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42173
42174 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42175 index 72afe82..056a57a 100644
42176 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42177 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42178 @@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42179 man->size = size >> PAGE_SHIFT;
42180 }
42181
42182 -static struct vm_operations_struct radeon_ttm_vm_ops;
42183 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42184 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42185
42186 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42187 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42188 }
42189 if (unlikely(ttm_vm_ops == NULL)) {
42190 ttm_vm_ops = vma->vm_ops;
42191 + pax_open_kernel();
42192 radeon_ttm_vm_ops = *ttm_vm_ops;
42193 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42194 + pax_close_kernel();
42195 }
42196 vma->vm_ops = &radeon_ttm_vm_ops;
42197 return 0;
42198 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42199 index 6553fd2..aecd29c 100644
42200 --- a/drivers/gpu/drm/tegra/dc.c
42201 +++ b/drivers/gpu/drm/tegra/dc.c
42202 @@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42203 }
42204
42205 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42206 - dc->debugfs_files[i].data = dc;
42207 + *(void **)&dc->debugfs_files[i].data = dc;
42208
42209 err = drm_debugfs_create_files(dc->debugfs_files,
42210 ARRAY_SIZE(debugfs_files),
42211 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42212 index f787445..2df2c65 100644
42213 --- a/drivers/gpu/drm/tegra/dsi.c
42214 +++ b/drivers/gpu/drm/tegra/dsi.c
42215 @@ -41,7 +41,7 @@ struct tegra_dsi {
42216 struct clk *clk_lp;
42217 struct clk *clk;
42218
42219 - struct drm_info_list *debugfs_files;
42220 + drm_info_list_no_const *debugfs_files;
42221 struct drm_minor *minor;
42222 struct dentry *debugfs;
42223
42224 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42225 index ffe2654..03c7b1c 100644
42226 --- a/drivers/gpu/drm/tegra/hdmi.c
42227 +++ b/drivers/gpu/drm/tegra/hdmi.c
42228 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42229 bool stereo;
42230 bool dvi;
42231
42232 - struct drm_info_list *debugfs_files;
42233 + drm_info_list_no_const *debugfs_files;
42234 struct drm_minor *minor;
42235 struct dentry *debugfs;
42236 };
42237 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42238 index 9e103a48..0e117f3 100644
42239 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42240 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42241 @@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42242 }
42243
42244 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42245 - ttm_bo_man_init,
42246 - ttm_bo_man_takedown,
42247 - ttm_bo_man_get_node,
42248 - ttm_bo_man_put_node,
42249 - ttm_bo_man_debug
42250 + .init = ttm_bo_man_init,
42251 + .takedown = ttm_bo_man_takedown,
42252 + .get_node = ttm_bo_man_get_node,
42253 + .put_node = ttm_bo_man_put_node,
42254 + .debug = ttm_bo_man_debug
42255 };
42256 EXPORT_SYMBOL(ttm_bo_manager_func);
42257 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42258 index dbc2def..0a9f710 100644
42259 --- a/drivers/gpu/drm/ttm/ttm_memory.c
42260 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
42261 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42262 zone->glob = glob;
42263 glob->zone_kernel = zone;
42264 ret = kobject_init_and_add(
42265 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42266 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42267 if (unlikely(ret != 0)) {
42268 kobject_put(&zone->kobj);
42269 return ret;
42270 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42271 zone->glob = glob;
42272 glob->zone_dma32 = zone;
42273 ret = kobject_init_and_add(
42274 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42275 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42276 if (unlikely(ret != 0)) {
42277 kobject_put(&zone->kobj);
42278 return ret;
42279 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
42280 index 09874d6..d6da1de 100644
42281 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
42282 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
42283 @@ -54,7 +54,7 @@
42284
42285 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
42286 #define SMALL_ALLOCATION 16
42287 -#define FREE_ALL_PAGES (~0U)
42288 +#define FREE_ALL_PAGES (~0UL)
42289 /* times are in msecs */
42290 #define PAGE_FREE_INTERVAL 1000
42291
42292 @@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
42293 * @free_all: If set to true will free all pages in pool
42294 * @gfp: GFP flags.
42295 **/
42296 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
42297 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
42298 gfp_t gfp)
42299 {
42300 unsigned long irq_flags;
42301 struct page *p;
42302 struct page **pages_to_free;
42303 - unsigned freed_pages = 0,
42304 - npages_to_free = nr_free;
42305 + unsigned long freed_pages = 0, npages_to_free = nr_free;
42306
42307 if (NUM_PAGES_TO_ALLOC < nr_free)
42308 npages_to_free = NUM_PAGES_TO_ALLOC;
42309 @@ -366,7 +365,8 @@ restart:
42310 __list_del(&p->lru, &pool->list);
42311
42312 ttm_pool_update_free_locked(pool, freed_pages);
42313 - nr_free -= freed_pages;
42314 + if (likely(nr_free != FREE_ALL_PAGES))
42315 + nr_free -= freed_pages;
42316 }
42317
42318 spin_unlock_irqrestore(&pool->lock, irq_flags);
42319 @@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42320 unsigned i;
42321 unsigned pool_offset;
42322 struct ttm_page_pool *pool;
42323 - int shrink_pages = sc->nr_to_scan;
42324 + unsigned long shrink_pages = sc->nr_to_scan;
42325 unsigned long freed = 0;
42326
42327 if (!mutex_trylock(&lock))
42328 @@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42329 pool_offset = ++start_pool % NUM_POOLS;
42330 /* select start pool in round robin fashion */
42331 for (i = 0; i < NUM_POOLS; ++i) {
42332 - unsigned nr_free = shrink_pages;
42333 + unsigned long nr_free = shrink_pages;
42334 if (shrink_pages == 0)
42335 break;
42336 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
42337 @@ -669,7 +669,7 @@ out:
42338 }
42339
42340 /* Put all pages in pages list to correct pool to wait for reuse */
42341 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
42342 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
42343 enum ttm_caching_state cstate)
42344 {
42345 unsigned long irq_flags;
42346 @@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
42347 struct list_head plist;
42348 struct page *p = NULL;
42349 gfp_t gfp_flags = GFP_USER;
42350 - unsigned count;
42351 + unsigned long count;
42352 int r;
42353
42354 /* set zero flag for page allocation if required */
42355 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42356 index c96db43..c367557 100644
42357 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42358 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42359 @@ -56,7 +56,7 @@
42360
42361 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
42362 #define SMALL_ALLOCATION 4
42363 -#define FREE_ALL_PAGES (~0U)
42364 +#define FREE_ALL_PAGES (~0UL)
42365 /* times are in msecs */
42366 #define IS_UNDEFINED (0)
42367 #define IS_WC (1<<1)
42368 @@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
42369 * @nr_free: If set to true will free all pages in pool
42370 * @gfp: GFP flags.
42371 **/
42372 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
42373 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
42374 gfp_t gfp)
42375 {
42376 unsigned long irq_flags;
42377 struct dma_page *dma_p, *tmp;
42378 struct page **pages_to_free;
42379 struct list_head d_pages;
42380 - unsigned freed_pages = 0,
42381 - npages_to_free = nr_free;
42382 + unsigned long freed_pages = 0, npages_to_free = nr_free;
42383
42384 if (NUM_PAGES_TO_ALLOC < nr_free)
42385 npages_to_free = NUM_PAGES_TO_ALLOC;
42386 @@ -494,7 +493,8 @@ restart:
42387 /* remove range of pages from the pool */
42388 if (freed_pages) {
42389 ttm_pool_update_free_locked(pool, freed_pages);
42390 - nr_free -= freed_pages;
42391 + if (likely(nr_free != FREE_ALL_PAGES))
42392 + nr_free -= freed_pages;
42393 }
42394
42395 spin_unlock_irqrestore(&pool->lock, irq_flags);
42396 @@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
42397 struct dma_page *d_page, *next;
42398 enum pool_type type;
42399 bool is_cached = false;
42400 - unsigned count = 0, i, npages = 0;
42401 + unsigned long count = 0, i, npages = 0;
42402 unsigned long irq_flags;
42403
42404 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
42405 @@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42406 static unsigned start_pool;
42407 unsigned idx = 0;
42408 unsigned pool_offset;
42409 - unsigned shrink_pages = sc->nr_to_scan;
42410 + unsigned long shrink_pages = sc->nr_to_scan;
42411 struct device_pools *p;
42412 unsigned long freed = 0;
42413
42414 @@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42415 goto out;
42416 pool_offset = ++start_pool % _manager->npools;
42417 list_for_each_entry(p, &_manager->pools, pools) {
42418 - unsigned nr_free;
42419 + unsigned long nr_free;
42420
42421 if (!p->dev)
42422 continue;
42423 @@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42424 sc->gfp_mask);
42425 freed += nr_free - shrink_pages;
42426
42427 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
42428 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
42429 p->pool->dev_name, p->pool->name, current->pid,
42430 nr_free, shrink_pages);
42431 }
42432 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42433 index d1da339..829235e 100644
42434 --- a/drivers/gpu/drm/udl/udl_fb.c
42435 +++ b/drivers/gpu/drm/udl/udl_fb.c
42436 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42437 fb_deferred_io_cleanup(info);
42438 kfree(info->fbdefio);
42439 info->fbdefio = NULL;
42440 - info->fbops->fb_mmap = udl_fb_mmap;
42441 }
42442
42443 pr_warn("released /dev/fb%d user=%d count=%d\n",
42444 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42445 index ad02732..144f5ed 100644
42446 --- a/drivers/gpu/drm/via/via_drv.h
42447 +++ b/drivers/gpu/drm/via/via_drv.h
42448 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42449 typedef uint32_t maskarray_t[5];
42450
42451 typedef struct drm_via_irq {
42452 - atomic_t irq_received;
42453 + atomic_unchecked_t irq_received;
42454 uint32_t pending_mask;
42455 uint32_t enable_mask;
42456 wait_queue_head_t irq_queue;
42457 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
42458 struct timeval last_vblank;
42459 int last_vblank_valid;
42460 unsigned usec_per_vblank;
42461 - atomic_t vbl_received;
42462 + atomic_unchecked_t vbl_received;
42463 drm_via_state_t hc_state;
42464 char pci_buf[VIA_PCI_BUF_SIZE];
42465 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42466 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42467 index 1319433..a993b0c 100644
42468 --- a/drivers/gpu/drm/via/via_irq.c
42469 +++ b/drivers/gpu/drm/via/via_irq.c
42470 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42471 if (crtc != 0)
42472 return 0;
42473
42474 - return atomic_read(&dev_priv->vbl_received);
42475 + return atomic_read_unchecked(&dev_priv->vbl_received);
42476 }
42477
42478 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42479 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42480
42481 status = VIA_READ(VIA_REG_INTERRUPT);
42482 if (status & VIA_IRQ_VBLANK_PENDING) {
42483 - atomic_inc(&dev_priv->vbl_received);
42484 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42485 + atomic_inc_unchecked(&dev_priv->vbl_received);
42486 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42487 do_gettimeofday(&cur_vblank);
42488 if (dev_priv->last_vblank_valid) {
42489 dev_priv->usec_per_vblank =
42490 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42491 dev_priv->last_vblank = cur_vblank;
42492 dev_priv->last_vblank_valid = 1;
42493 }
42494 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42495 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42496 DRM_DEBUG("US per vblank is: %u\n",
42497 dev_priv->usec_per_vblank);
42498 }
42499 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42500
42501 for (i = 0; i < dev_priv->num_irqs; ++i) {
42502 if (status & cur_irq->pending_mask) {
42503 - atomic_inc(&cur_irq->irq_received);
42504 + atomic_inc_unchecked(&cur_irq->irq_received);
42505 wake_up(&cur_irq->irq_queue);
42506 handled = 1;
42507 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42508 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42509 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42510 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42511 masks[irq][4]));
42512 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42513 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42514 } else {
42515 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42516 (((cur_irq_sequence =
42517 - atomic_read(&cur_irq->irq_received)) -
42518 + atomic_read_unchecked(&cur_irq->irq_received)) -
42519 *sequence) <= (1 << 23)));
42520 }
42521 *sequence = cur_irq_sequence;
42522 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42523 }
42524
42525 for (i = 0; i < dev_priv->num_irqs; ++i) {
42526 - atomic_set(&cur_irq->irq_received, 0);
42527 + atomic_set_unchecked(&cur_irq->irq_received, 0);
42528 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42529 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42530 init_waitqueue_head(&cur_irq->irq_queue);
42531 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42532 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42533 case VIA_IRQ_RELATIVE:
42534 irqwait->request.sequence +=
42535 - atomic_read(&cur_irq->irq_received);
42536 + atomic_read_unchecked(&cur_irq->irq_received);
42537 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42538 case VIA_IRQ_ABSOLUTE:
42539 break;
42540 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42541 index 99f7317..33a835b 100644
42542 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42543 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42544 @@ -447,7 +447,7 @@ struct vmw_private {
42545 * Fencing and IRQs.
42546 */
42547
42548 - atomic_t marker_seq;
42549 + atomic_unchecked_t marker_seq;
42550 wait_queue_head_t fence_queue;
42551 wait_queue_head_t fifo_queue;
42552 int fence_queue_waiters; /* Protected by hw_mutex */
42553 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42554 index 6eae14d..aa311b3 100644
42555 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42556 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42557 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42558 (unsigned int) min,
42559 (unsigned int) fifo->capabilities);
42560
42561 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42562 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42563 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42564 vmw_marker_queue_init(&fifo->marker_queue);
42565 return vmw_fifo_send_fence(dev_priv, &dummy);
42566 @@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42567 if (reserveable)
42568 iowrite32(bytes, fifo_mem +
42569 SVGA_FIFO_RESERVED);
42570 - return fifo_mem + (next_cmd >> 2);
42571 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42572 } else {
42573 need_bounce = true;
42574 }
42575 @@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42576
42577 fm = vmw_fifo_reserve(dev_priv, bytes);
42578 if (unlikely(fm == NULL)) {
42579 - *seqno = atomic_read(&dev_priv->marker_seq);
42580 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42581 ret = -ENOMEM;
42582 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42583 false, 3*HZ);
42584 @@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42585 }
42586
42587 do {
42588 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42589 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42590 } while (*seqno == 0);
42591
42592 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42593 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42594 index 26f8bdd..90a0008 100644
42595 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42596 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42597 @@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42598 }
42599
42600 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42601 - vmw_gmrid_man_init,
42602 - vmw_gmrid_man_takedown,
42603 - vmw_gmrid_man_get_node,
42604 - vmw_gmrid_man_put_node,
42605 - vmw_gmrid_man_debug
42606 + .init = vmw_gmrid_man_init,
42607 + .takedown = vmw_gmrid_man_takedown,
42608 + .get_node = vmw_gmrid_man_get_node,
42609 + .put_node = vmw_gmrid_man_put_node,
42610 + .debug = vmw_gmrid_man_debug
42611 };
42612 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42613 index 37881ec..319065d 100644
42614 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42615 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42616 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42617 int ret;
42618
42619 num_clips = arg->num_clips;
42620 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42621 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42622
42623 if (unlikely(num_clips == 0))
42624 return 0;
42625 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42626 int ret;
42627
42628 num_clips = arg->num_clips;
42629 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42630 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42631
42632 if (unlikely(num_clips == 0))
42633 return 0;
42634 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42635 index 0c42376..6febe77 100644
42636 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42637 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42638 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42639 * emitted. Then the fence is stale and signaled.
42640 */
42641
42642 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42643 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42644 > VMW_FENCE_WRAP);
42645
42646 return ret;
42647 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42648
42649 if (fifo_idle)
42650 down_read(&fifo_state->rwsem);
42651 - signal_seq = atomic_read(&dev_priv->marker_seq);
42652 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42653 ret = 0;
42654
42655 for (;;) {
42656 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42657 index efd1ffd..0ae13ca 100644
42658 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42659 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42660 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42661 while (!vmw_lag_lt(queue, us)) {
42662 spin_lock(&queue->lock);
42663 if (list_empty(&queue->head))
42664 - seqno = atomic_read(&dev_priv->marker_seq);
42665 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42666 else {
42667 marker = list_first_entry(&queue->head,
42668 struct vmw_marker, head);
42669 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42670 index 37ac7b5..d52a5c9 100644
42671 --- a/drivers/gpu/vga/vga_switcheroo.c
42672 +++ b/drivers/gpu/vga/vga_switcheroo.c
42673 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42674
42675 /* this version is for the case where the power switch is separate
42676 to the device being powered down. */
42677 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42678 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42679 {
42680 /* copy over all the bus versions */
42681 if (dev->bus && dev->bus->pm) {
42682 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42683 return ret;
42684 }
42685
42686 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42687 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42688 {
42689 /* copy over all the bus versions */
42690 if (dev->bus && dev->bus->pm) {
42691 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42692 index 12b6e67..ddd983c 100644
42693 --- a/drivers/hid/hid-core.c
42694 +++ b/drivers/hid/hid-core.c
42695 @@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42696
42697 int hid_add_device(struct hid_device *hdev)
42698 {
42699 - static atomic_t id = ATOMIC_INIT(0);
42700 + static atomic_unchecked_t id = ATOMIC_INIT(0);
42701 int ret;
42702
42703 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42704 @@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42705 /* XXX hack, any other cleaner solution after the driver core
42706 * is converted to allow more than 20 bytes as the device name? */
42707 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42708 - hdev->vendor, hdev->product, atomic_inc_return(&id));
42709 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42710
42711 hid_debug_register(hdev, dev_name(&hdev->dev));
42712 ret = device_add(&hdev->dev);
42713 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42714 index 9bf8637..f462416 100644
42715 --- a/drivers/hid/hid-logitech-dj.c
42716 +++ b/drivers/hid/hid-logitech-dj.c
42717 @@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42718 * device (via hid_input_report() ) and return 1 so hid-core does not do
42719 * anything else with it.
42720 */
42721 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42722 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42723 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42724 + __func__, dj_report->device_index);
42725 + return false;
42726 + }
42727
42728 /* case 1) */
42729 if (data[0] != REPORT_ID_DJ_SHORT)
42730 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42731 index c13fb5b..55a3802 100644
42732 --- a/drivers/hid/hid-wiimote-debug.c
42733 +++ b/drivers/hid/hid-wiimote-debug.c
42734 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42735 else if (size == 0)
42736 return -EIO;
42737
42738 - if (copy_to_user(u, buf, size))
42739 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42740 return -EFAULT;
42741
42742 *off += size;
42743 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
42744 index 0cb92e3..c7d453d 100644
42745 --- a/drivers/hid/uhid.c
42746 +++ b/drivers/hid/uhid.c
42747 @@ -47,7 +47,7 @@ struct uhid_device {
42748 struct mutex report_lock;
42749 wait_queue_head_t report_wait;
42750 atomic_t report_done;
42751 - atomic_t report_id;
42752 + atomic_unchecked_t report_id;
42753 struct uhid_event report_buf;
42754 };
42755
42756 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42757
42758 spin_lock_irqsave(&uhid->qlock, flags);
42759 ev->type = UHID_FEATURE;
42760 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42761 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42762 ev->u.feature.rnum = rnum;
42763 ev->u.feature.rtype = report_type;
42764
42765 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42766 spin_lock_irqsave(&uhid->qlock, flags);
42767
42768 /* id for old report; drop it silently */
42769 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42770 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42771 goto unlock;
42772 if (atomic_read(&uhid->report_done))
42773 goto unlock;
42774 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42775 index 19bad59..ca24eaf 100644
42776 --- a/drivers/hv/channel.c
42777 +++ b/drivers/hv/channel.c
42778 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42779 unsigned long flags;
42780 int ret = 0;
42781
42782 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42783 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42784 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42785 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42786
42787 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42788 if (ret)
42789 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42790 index 3e4235c..877d0e5 100644
42791 --- a/drivers/hv/hv.c
42792 +++ b/drivers/hv/hv.c
42793 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42794 u64 output_address = (output) ? virt_to_phys(output) : 0;
42795 u32 output_address_hi = output_address >> 32;
42796 u32 output_address_lo = output_address & 0xFFFFFFFF;
42797 - void *hypercall_page = hv_context.hypercall_page;
42798 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42799
42800 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42801 "=a"(hv_status_lo) : "d" (control_hi),
42802 @@ -156,7 +156,7 @@ int hv_init(void)
42803 /* See if the hypercall page is already set */
42804 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42805
42806 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42807 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42808
42809 if (!virtaddr)
42810 goto cleanup;
42811 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42812 index 5e90c5d..d8fcefb 100644
42813 --- a/drivers/hv/hv_balloon.c
42814 +++ b/drivers/hv/hv_balloon.c
42815 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42816
42817 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42818 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42819 -static atomic_t trans_id = ATOMIC_INIT(0);
42820 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42821
42822 static int dm_ring_size = (5 * PAGE_SIZE);
42823
42824 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42825 pr_info("Memory hot add failed\n");
42826
42827 dm->state = DM_INITIALIZED;
42828 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42829 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42830 vmbus_sendpacket(dm->dev->channel, &resp,
42831 sizeof(struct dm_hot_add_response),
42832 (unsigned long)NULL,
42833 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42834 memset(&status, 0, sizeof(struct dm_status));
42835 status.hdr.type = DM_STATUS_REPORT;
42836 status.hdr.size = sizeof(struct dm_status);
42837 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42838 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42839
42840 /*
42841 * The host expects the guest to report free memory.
42842 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42843 * send the status. This can happen if we were interrupted
42844 * after we picked our transaction ID.
42845 */
42846 - if (status.hdr.trans_id != atomic_read(&trans_id))
42847 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42848 return;
42849
42850 /*
42851 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42852 */
42853
42854 do {
42855 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42856 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42857 ret = vmbus_sendpacket(dm_device.dev->channel,
42858 bl_resp,
42859 bl_resp->hdr.size,
42860 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42861
42862 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42863 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42864 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42865 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42866 resp.hdr.size = sizeof(struct dm_unballoon_response);
42867
42868 vmbus_sendpacket(dm_device.dev->channel, &resp,
42869 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42870 memset(&version_req, 0, sizeof(struct dm_version_request));
42871 version_req.hdr.type = DM_VERSION_REQUEST;
42872 version_req.hdr.size = sizeof(struct dm_version_request);
42873 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42874 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42875 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42876 version_req.is_last_attempt = 1;
42877
42878 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42879 memset(&version_req, 0, sizeof(struct dm_version_request));
42880 version_req.hdr.type = DM_VERSION_REQUEST;
42881 version_req.hdr.size = sizeof(struct dm_version_request);
42882 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42883 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42884 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42885 version_req.is_last_attempt = 0;
42886
42887 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42888 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42889 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42890 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42891 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42892 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42893
42894 cap_msg.caps.cap_bits.balloon = 1;
42895 cap_msg.caps.cap_bits.hot_add = 1;
42896 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42897 index c386d8d..d6004c4 100644
42898 --- a/drivers/hv/hyperv_vmbus.h
42899 +++ b/drivers/hv/hyperv_vmbus.h
42900 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42901 struct vmbus_connection {
42902 enum vmbus_connect_state conn_state;
42903
42904 - atomic_t next_gpadl_handle;
42905 + atomic_unchecked_t next_gpadl_handle;
42906
42907 /*
42908 * Represents channel interrupts. Each bit position represents a
42909 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42910 index 4d6b269..2e23b86 100644
42911 --- a/drivers/hv/vmbus_drv.c
42912 +++ b/drivers/hv/vmbus_drv.c
42913 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42914 {
42915 int ret = 0;
42916
42917 - static atomic_t device_num = ATOMIC_INIT(0);
42918 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42919
42920 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42921 - atomic_inc_return(&device_num));
42922 + atomic_inc_return_unchecked(&device_num));
42923
42924 child_device_obj->device.bus = &hv_bus;
42925 child_device_obj->device.parent = &hv_acpi_dev->dev;
42926 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42927 index 579bdf9..75118b5 100644
42928 --- a/drivers/hwmon/acpi_power_meter.c
42929 +++ b/drivers/hwmon/acpi_power_meter.c
42930 @@ -116,7 +116,7 @@ struct sensor_template {
42931 struct device_attribute *devattr,
42932 const char *buf, size_t count);
42933 int index;
42934 -};
42935 +} __do_const;
42936
42937 /* Averaging interval */
42938 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42939 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42940 struct sensor_template *attrs)
42941 {
42942 struct device *dev = &resource->acpi_dev->dev;
42943 - struct sensor_device_attribute *sensors =
42944 + sensor_device_attribute_no_const *sensors =
42945 &resource->sensors[resource->num_sensors];
42946 int res = 0;
42947
42948 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42949 index 3288f13..71cfb4e 100644
42950 --- a/drivers/hwmon/applesmc.c
42951 +++ b/drivers/hwmon/applesmc.c
42952 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42953 {
42954 struct applesmc_node_group *grp;
42955 struct applesmc_dev_attr *node;
42956 - struct attribute *attr;
42957 + attribute_no_const *attr;
42958 int ret, i;
42959
42960 for (grp = groups; grp->format; grp++) {
42961 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42962 index cccef87..06ce8ec 100644
42963 --- a/drivers/hwmon/asus_atk0110.c
42964 +++ b/drivers/hwmon/asus_atk0110.c
42965 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42966 struct atk_sensor_data {
42967 struct list_head list;
42968 struct atk_data *data;
42969 - struct device_attribute label_attr;
42970 - struct device_attribute input_attr;
42971 - struct device_attribute limit1_attr;
42972 - struct device_attribute limit2_attr;
42973 + device_attribute_no_const label_attr;
42974 + device_attribute_no_const input_attr;
42975 + device_attribute_no_const limit1_attr;
42976 + device_attribute_no_const limit2_attr;
42977 char label_attr_name[ATTR_NAME_SIZE];
42978 char input_attr_name[ATTR_NAME_SIZE];
42979 char limit1_attr_name[ATTR_NAME_SIZE];
42980 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42981 static struct device_attribute atk_name_attr =
42982 __ATTR(name, 0444, atk_name_show, NULL);
42983
42984 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42985 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42986 sysfs_show_func show)
42987 {
42988 sysfs_attr_init(&attr->attr);
42989 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42990 index d76f0b7..55ae976 100644
42991 --- a/drivers/hwmon/coretemp.c
42992 +++ b/drivers/hwmon/coretemp.c
42993 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42994 return NOTIFY_OK;
42995 }
42996
42997 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42998 +static struct notifier_block coretemp_cpu_notifier = {
42999 .notifier_call = coretemp_cpu_callback,
43000 };
43001
43002 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43003 index 7a8a6fb..015c1fd 100644
43004 --- a/drivers/hwmon/ibmaem.c
43005 +++ b/drivers/hwmon/ibmaem.c
43006 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
43007 struct aem_rw_sensor_template *rw)
43008 {
43009 struct device *dev = &data->pdev->dev;
43010 - struct sensor_device_attribute *sensors = data->sensors;
43011 + sensor_device_attribute_no_const *sensors = data->sensors;
43012 int err;
43013
43014 /* Set up read-only sensors */
43015 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43016 index 14c82da..09b25d7 100644
43017 --- a/drivers/hwmon/iio_hwmon.c
43018 +++ b/drivers/hwmon/iio_hwmon.c
43019 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43020 {
43021 struct device *dev = &pdev->dev;
43022 struct iio_hwmon_state *st;
43023 - struct sensor_device_attribute *a;
43024 + sensor_device_attribute_no_const *a;
43025 int ret, i;
43026 int in_i = 1, temp_i = 1, curr_i = 1;
43027 enum iio_chan_type type;
43028 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43029 index 7710f46..427a28d 100644
43030 --- a/drivers/hwmon/nct6683.c
43031 +++ b/drivers/hwmon/nct6683.c
43032 @@ -397,11 +397,11 @@ static struct attribute_group *
43033 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43034 int repeat)
43035 {
43036 - struct sensor_device_attribute_2 *a2;
43037 - struct sensor_device_attribute *a;
43038 + sensor_device_attribute_2_no_const *a2;
43039 + sensor_device_attribute_no_const *a;
43040 struct sensor_device_template **t;
43041 struct sensor_device_attr_u *su;
43042 - struct attribute_group *group;
43043 + attribute_group_no_const *group;
43044 struct attribute **attrs;
43045 int i, j, count;
43046
43047 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43048 index 504cbdd..35d6f25 100644
43049 --- a/drivers/hwmon/nct6775.c
43050 +++ b/drivers/hwmon/nct6775.c
43051 @@ -943,10 +943,10 @@ static struct attribute_group *
43052 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43053 int repeat)
43054 {
43055 - struct attribute_group *group;
43056 + attribute_group_no_const *group;
43057 struct sensor_device_attr_u *su;
43058 - struct sensor_device_attribute *a;
43059 - struct sensor_device_attribute_2 *a2;
43060 + sensor_device_attribute_no_const *a;
43061 + sensor_device_attribute_2_no_const *a2;
43062 struct attribute **attrs;
43063 struct sensor_device_template **t;
43064 int i, count;
43065 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43066 index 291d11f..3f0dbbd 100644
43067 --- a/drivers/hwmon/pmbus/pmbus_core.c
43068 +++ b/drivers/hwmon/pmbus/pmbus_core.c
43069 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43070 return 0;
43071 }
43072
43073 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43074 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43075 const char *name,
43076 umode_t mode,
43077 ssize_t (*show)(struct device *dev,
43078 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43079 dev_attr->store = store;
43080 }
43081
43082 -static void pmbus_attr_init(struct sensor_device_attribute *a,
43083 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43084 const char *name,
43085 umode_t mode,
43086 ssize_t (*show)(struct device *dev,
43087 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43088 u16 reg, u8 mask)
43089 {
43090 struct pmbus_boolean *boolean;
43091 - struct sensor_device_attribute *a;
43092 + sensor_device_attribute_no_const *a;
43093
43094 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43095 if (!boolean)
43096 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43097 bool update, bool readonly)
43098 {
43099 struct pmbus_sensor *sensor;
43100 - struct device_attribute *a;
43101 + device_attribute_no_const *a;
43102
43103 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43104 if (!sensor)
43105 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43106 const char *lstring, int index)
43107 {
43108 struct pmbus_label *label;
43109 - struct device_attribute *a;
43110 + device_attribute_no_const *a;
43111
43112 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43113 if (!label)
43114 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43115 index 97cd45a..ac54d8b 100644
43116 --- a/drivers/hwmon/sht15.c
43117 +++ b/drivers/hwmon/sht15.c
43118 @@ -169,7 +169,7 @@ struct sht15_data {
43119 int supply_uv;
43120 bool supply_uv_valid;
43121 struct work_struct update_supply_work;
43122 - atomic_t interrupt_handled;
43123 + atomic_unchecked_t interrupt_handled;
43124 };
43125
43126 /**
43127 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43128 ret = gpio_direction_input(data->pdata->gpio_data);
43129 if (ret)
43130 return ret;
43131 - atomic_set(&data->interrupt_handled, 0);
43132 + atomic_set_unchecked(&data->interrupt_handled, 0);
43133
43134 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43135 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43136 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43137 /* Only relevant if the interrupt hasn't occurred. */
43138 - if (!atomic_read(&data->interrupt_handled))
43139 + if (!atomic_read_unchecked(&data->interrupt_handled))
43140 schedule_work(&data->read_work);
43141 }
43142 ret = wait_event_timeout(data->wait_queue,
43143 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43144
43145 /* First disable the interrupt */
43146 disable_irq_nosync(irq);
43147 - atomic_inc(&data->interrupt_handled);
43148 + atomic_inc_unchecked(&data->interrupt_handled);
43149 /* Then schedule a reading work struct */
43150 if (data->state != SHT15_READING_NOTHING)
43151 schedule_work(&data->read_work);
43152 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43153 * If not, then start the interrupt again - care here as could
43154 * have gone low in meantime so verify it hasn't!
43155 */
43156 - atomic_set(&data->interrupt_handled, 0);
43157 + atomic_set_unchecked(&data->interrupt_handled, 0);
43158 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43159 /* If still not occurred or another handler was scheduled */
43160 if (gpio_get_value(data->pdata->gpio_data)
43161 - || atomic_read(&data->interrupt_handled))
43162 + || atomic_read_unchecked(&data->interrupt_handled))
43163 return;
43164 }
43165
43166 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43167 index 8df43c5..b07b91d 100644
43168 --- a/drivers/hwmon/via-cputemp.c
43169 +++ b/drivers/hwmon/via-cputemp.c
43170 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43171 return NOTIFY_OK;
43172 }
43173
43174 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43175 +static struct notifier_block via_cputemp_cpu_notifier = {
43176 .notifier_call = via_cputemp_cpu_callback,
43177 };
43178
43179 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43180 index 41fc683..a39cfea 100644
43181 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
43182 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43183 @@ -43,7 +43,7 @@
43184 extern struct i2c_adapter amd756_smbus;
43185
43186 static struct i2c_adapter *s4882_adapter;
43187 -static struct i2c_algorithm *s4882_algo;
43188 +static i2c_algorithm_no_const *s4882_algo;
43189
43190 /* Wrapper access functions for multiplexed SMBus */
43191 static DEFINE_MUTEX(amd756_lock);
43192 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43193 index b19a310..d6eece0 100644
43194 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
43195 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43196 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43197 /* usb layer */
43198
43199 /* Send command to device, and get response. */
43200 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43201 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43202 {
43203 int ret = 0;
43204 int actual;
43205 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43206 index b170bdf..3c76427 100644
43207 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43208 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43209 @@ -41,7 +41,7 @@
43210 extern struct i2c_adapter *nforce2_smbus;
43211
43212 static struct i2c_adapter *s4985_adapter;
43213 -static struct i2c_algorithm *s4985_algo;
43214 +static i2c_algorithm_no_const *s4985_algo;
43215
43216 /* Wrapper access functions for multiplexed SMBus */
43217 static DEFINE_MUTEX(nforce2_lock);
43218 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43219 index 80b47e8..1a6040d9 100644
43220 --- a/drivers/i2c/i2c-dev.c
43221 +++ b/drivers/i2c/i2c-dev.c
43222 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43223 break;
43224 }
43225
43226 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43227 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43228 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43229 if (IS_ERR(rdwr_pa[i].buf)) {
43230 res = PTR_ERR(rdwr_pa[i].buf);
43231 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43232 index 0b510ba..4fbb5085 100644
43233 --- a/drivers/ide/ide-cd.c
43234 +++ b/drivers/ide/ide-cd.c
43235 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43236 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43237 if ((unsigned long)buf & alignment
43238 || blk_rq_bytes(rq) & q->dma_pad_mask
43239 - || object_is_on_stack(buf))
43240 + || object_starts_on_stack(buf))
43241 drive->dma = 0;
43242 }
43243 }
43244 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43245 index af3e76d..96dfe5e 100644
43246 --- a/drivers/iio/industrialio-core.c
43247 +++ b/drivers/iio/industrialio-core.c
43248 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43249 }
43250
43251 static
43252 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43253 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43254 const char *postfix,
43255 struct iio_chan_spec const *chan,
43256 ssize_t (*readfunc)(struct device *dev,
43257 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43258 index e28a494..f7c2671 100644
43259 --- a/drivers/infiniband/core/cm.c
43260 +++ b/drivers/infiniband/core/cm.c
43261 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43262
43263 struct cm_counter_group {
43264 struct kobject obj;
43265 - atomic_long_t counter[CM_ATTR_COUNT];
43266 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43267 };
43268
43269 struct cm_counter_attribute {
43270 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43271 struct ib_mad_send_buf *msg = NULL;
43272 int ret;
43273
43274 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43275 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43276 counter[CM_REQ_COUNTER]);
43277
43278 /* Quick state check to discard duplicate REQs. */
43279 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43280 if (!cm_id_priv)
43281 return;
43282
43283 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43284 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43285 counter[CM_REP_COUNTER]);
43286 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43287 if (ret)
43288 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43289 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43290 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43291 spin_unlock_irq(&cm_id_priv->lock);
43292 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43293 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43294 counter[CM_RTU_COUNTER]);
43295 goto out;
43296 }
43297 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43298 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43299 dreq_msg->local_comm_id);
43300 if (!cm_id_priv) {
43301 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43302 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43303 counter[CM_DREQ_COUNTER]);
43304 cm_issue_drep(work->port, work->mad_recv_wc);
43305 return -EINVAL;
43306 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43307 case IB_CM_MRA_REP_RCVD:
43308 break;
43309 case IB_CM_TIMEWAIT:
43310 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43311 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43312 counter[CM_DREQ_COUNTER]);
43313 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43314 goto unlock;
43315 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43316 cm_free_msg(msg);
43317 goto deref;
43318 case IB_CM_DREQ_RCVD:
43319 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43320 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43321 counter[CM_DREQ_COUNTER]);
43322 goto unlock;
43323 default:
43324 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43325 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43326 cm_id_priv->msg, timeout)) {
43327 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43328 - atomic_long_inc(&work->port->
43329 + atomic_long_inc_unchecked(&work->port->
43330 counter_group[CM_RECV_DUPLICATES].
43331 counter[CM_MRA_COUNTER]);
43332 goto out;
43333 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43334 break;
43335 case IB_CM_MRA_REQ_RCVD:
43336 case IB_CM_MRA_REP_RCVD:
43337 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43338 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43339 counter[CM_MRA_COUNTER]);
43340 /* fall through */
43341 default:
43342 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43343 case IB_CM_LAP_IDLE:
43344 break;
43345 case IB_CM_MRA_LAP_SENT:
43346 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43347 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43348 counter[CM_LAP_COUNTER]);
43349 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43350 goto unlock;
43351 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43352 cm_free_msg(msg);
43353 goto deref;
43354 case IB_CM_LAP_RCVD:
43355 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43356 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43357 counter[CM_LAP_COUNTER]);
43358 goto unlock;
43359 default:
43360 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43361 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43362 if (cur_cm_id_priv) {
43363 spin_unlock_irq(&cm.lock);
43364 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43365 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43366 counter[CM_SIDR_REQ_COUNTER]);
43367 goto out; /* Duplicate message. */
43368 }
43369 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43370 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43371 msg->retries = 1;
43372
43373 - atomic_long_add(1 + msg->retries,
43374 + atomic_long_add_unchecked(1 + msg->retries,
43375 &port->counter_group[CM_XMIT].counter[attr_index]);
43376 if (msg->retries)
43377 - atomic_long_add(msg->retries,
43378 + atomic_long_add_unchecked(msg->retries,
43379 &port->counter_group[CM_XMIT_RETRIES].
43380 counter[attr_index]);
43381
43382 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43383 }
43384
43385 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43386 - atomic_long_inc(&port->counter_group[CM_RECV].
43387 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43388 counter[attr_id - CM_ATTR_ID_OFFSET]);
43389
43390 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43391 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43392 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43393
43394 return sprintf(buf, "%ld\n",
43395 - atomic_long_read(&group->counter[cm_attr->index]));
43396 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43397 }
43398
43399 static const struct sysfs_ops cm_counter_ops = {
43400 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43401 index 9f5ad7c..588cd84 100644
43402 --- a/drivers/infiniband/core/fmr_pool.c
43403 +++ b/drivers/infiniband/core/fmr_pool.c
43404 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
43405
43406 struct task_struct *thread;
43407
43408 - atomic_t req_ser;
43409 - atomic_t flush_ser;
43410 + atomic_unchecked_t req_ser;
43411 + atomic_unchecked_t flush_ser;
43412
43413 wait_queue_head_t force_wait;
43414 };
43415 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43416 struct ib_fmr_pool *pool = pool_ptr;
43417
43418 do {
43419 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43420 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43421 ib_fmr_batch_release(pool);
43422
43423 - atomic_inc(&pool->flush_ser);
43424 + atomic_inc_unchecked(&pool->flush_ser);
43425 wake_up_interruptible(&pool->force_wait);
43426
43427 if (pool->flush_function)
43428 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43429 }
43430
43431 set_current_state(TASK_INTERRUPTIBLE);
43432 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43433 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43434 !kthread_should_stop())
43435 schedule();
43436 __set_current_state(TASK_RUNNING);
43437 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43438 pool->dirty_watermark = params->dirty_watermark;
43439 pool->dirty_len = 0;
43440 spin_lock_init(&pool->pool_lock);
43441 - atomic_set(&pool->req_ser, 0);
43442 - atomic_set(&pool->flush_ser, 0);
43443 + atomic_set_unchecked(&pool->req_ser, 0);
43444 + atomic_set_unchecked(&pool->flush_ser, 0);
43445 init_waitqueue_head(&pool->force_wait);
43446
43447 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43448 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43449 }
43450 spin_unlock_irq(&pool->pool_lock);
43451
43452 - serial = atomic_inc_return(&pool->req_ser);
43453 + serial = atomic_inc_return_unchecked(&pool->req_ser);
43454 wake_up_process(pool->thread);
43455
43456 if (wait_event_interruptible(pool->force_wait,
43457 - atomic_read(&pool->flush_ser) - serial >= 0))
43458 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43459 return -EINTR;
43460
43461 return 0;
43462 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43463 } else {
43464 list_add_tail(&fmr->list, &pool->dirty_list);
43465 if (++pool->dirty_len >= pool->dirty_watermark) {
43466 - atomic_inc(&pool->req_ser);
43467 + atomic_inc_unchecked(&pool->req_ser);
43468 wake_up_process(pool->thread);
43469 }
43470 }
43471 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43472 index ec7a298..8742e59 100644
43473 --- a/drivers/infiniband/hw/cxgb4/mem.c
43474 +++ b/drivers/infiniband/hw/cxgb4/mem.c
43475 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43476 int err;
43477 struct fw_ri_tpte tpt;
43478 u32 stag_idx;
43479 - static atomic_t key;
43480 + static atomic_unchecked_t key;
43481
43482 if (c4iw_fatal_error(rdev))
43483 return -EIO;
43484 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43485 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43486 rdev->stats.stag.max = rdev->stats.stag.cur;
43487 mutex_unlock(&rdev->stats.lock);
43488 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43489 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
43490 }
43491 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
43492 __func__, stag_state, type, pdid, stag_idx);
43493 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
43494 index 79b3dbc..96e5fcc 100644
43495 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
43496 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
43497 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43498 struct ib_atomic_eth *ateth;
43499 struct ipath_ack_entry *e;
43500 u64 vaddr;
43501 - atomic64_t *maddr;
43502 + atomic64_unchecked_t *maddr;
43503 u64 sdata;
43504 u32 rkey;
43505 u8 next;
43506 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43507 IB_ACCESS_REMOTE_ATOMIC)))
43508 goto nack_acc_unlck;
43509 /* Perform atomic OP and save result. */
43510 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43511 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43512 sdata = be64_to_cpu(ateth->swap_data);
43513 e = &qp->s_ack_queue[qp->r_head_ack_queue];
43514 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
43515 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43516 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43517 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43518 be64_to_cpu(ateth->compare_data),
43519 sdata);
43520 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
43521 index 1f95bba..9530f87 100644
43522 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
43523 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
43524 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
43525 unsigned long flags;
43526 struct ib_wc wc;
43527 u64 sdata;
43528 - atomic64_t *maddr;
43529 + atomic64_unchecked_t *maddr;
43530 enum ib_wc_status send_status;
43531
43532 /*
43533 @@ -382,11 +382,11 @@ again:
43534 IB_ACCESS_REMOTE_ATOMIC)))
43535 goto acc_err;
43536 /* Perform atomic OP and save result. */
43537 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43538 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43539 sdata = wqe->wr.wr.atomic.compare_add;
43540 *(u64 *) sqp->s_sge.sge.vaddr =
43541 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43542 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43543 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43544 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43545 sdata, wqe->wr.wr.atomic.swap);
43546 goto send_comp;
43547 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43548 index 82a7dd8..8fb6ba6 100644
43549 --- a/drivers/infiniband/hw/mlx4/mad.c
43550 +++ b/drivers/infiniband/hw/mlx4/mad.c
43551 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43552
43553 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43554 {
43555 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43556 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43557 cpu_to_be64(0xff00000000000000LL);
43558 }
43559
43560 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43561 index ed327e6..ca1739e0 100644
43562 --- a/drivers/infiniband/hw/mlx4/mcg.c
43563 +++ b/drivers/infiniband/hw/mlx4/mcg.c
43564 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43565 {
43566 char name[20];
43567
43568 - atomic_set(&ctx->tid, 0);
43569 + atomic_set_unchecked(&ctx->tid, 0);
43570 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43571 ctx->mcg_wq = create_singlethread_workqueue(name);
43572 if (!ctx->mcg_wq)
43573 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43574 index 6eb743f..a7b0f6d 100644
43575 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43576 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43577 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43578 struct list_head mcg_mgid0_list;
43579 struct workqueue_struct *mcg_wq;
43580 struct mlx4_ib_demux_pv_ctx **tun;
43581 - atomic_t tid;
43582 + atomic_unchecked_t tid;
43583 int flushing; /* flushing the work queue */
43584 };
43585
43586 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43587 index 9d3e5c1..6f166df 100644
43588 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43589 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43590 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43591 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43592 }
43593
43594 -int mthca_QUERY_FW(struct mthca_dev *dev)
43595 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43596 {
43597 struct mthca_mailbox *mailbox;
43598 u32 *outbox;
43599 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43600 CMD_TIME_CLASS_B);
43601 }
43602
43603 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43604 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43605 int num_mtt)
43606 {
43607 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43608 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43609 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43610 }
43611
43612 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43613 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43614 int eq_num)
43615 {
43616 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43617 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43618 CMD_TIME_CLASS_B);
43619 }
43620
43621 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43622 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43623 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43624 void *in_mad, void *response_mad)
43625 {
43626 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43627 index ded76c1..0cf0a08 100644
43628 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43629 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43630 @@ -692,7 +692,7 @@ err_close:
43631 return err;
43632 }
43633
43634 -static int mthca_setup_hca(struct mthca_dev *dev)
43635 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43636 {
43637 int err;
43638
43639 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43640 index ed9a989..6aa5dc2 100644
43641 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43642 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43643 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43644 * through the bitmaps)
43645 */
43646
43647 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43648 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43649 {
43650 int o;
43651 int m;
43652 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43653 return key;
43654 }
43655
43656 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43657 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43658 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43659 {
43660 struct mthca_mailbox *mailbox;
43661 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43662 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43663 }
43664
43665 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43666 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43667 u64 *buffer_list, int buffer_size_shift,
43668 int list_len, u64 iova, u64 total_size,
43669 u32 access, struct mthca_mr *mr)
43670 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43671 index 415f8e1..e34214e 100644
43672 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43673 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43674 @@ -764,7 +764,7 @@ unlock:
43675 return 0;
43676 }
43677
43678 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43679 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43680 {
43681 struct mthca_dev *dev = to_mdev(ibcq->device);
43682 struct mthca_cq *cq = to_mcq(ibcq);
43683 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43684 index 3b2a6dc..bce26ff 100644
43685 --- a/drivers/infiniband/hw/nes/nes.c
43686 +++ b/drivers/infiniband/hw/nes/nes.c
43687 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43688 LIST_HEAD(nes_adapter_list);
43689 static LIST_HEAD(nes_dev_list);
43690
43691 -atomic_t qps_destroyed;
43692 +atomic_unchecked_t qps_destroyed;
43693
43694 static unsigned int ee_flsh_adapter;
43695 static unsigned int sysfs_nonidx_addr;
43696 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43697 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43698 struct nes_adapter *nesadapter = nesdev->nesadapter;
43699
43700 - atomic_inc(&qps_destroyed);
43701 + atomic_inc_unchecked(&qps_destroyed);
43702
43703 /* Free the control structures */
43704
43705 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43706 index bd9d132..70d84f4 100644
43707 --- a/drivers/infiniband/hw/nes/nes.h
43708 +++ b/drivers/infiniband/hw/nes/nes.h
43709 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43710 extern unsigned int wqm_quanta;
43711 extern struct list_head nes_adapter_list;
43712
43713 -extern atomic_t cm_connects;
43714 -extern atomic_t cm_accepts;
43715 -extern atomic_t cm_disconnects;
43716 -extern atomic_t cm_closes;
43717 -extern atomic_t cm_connecteds;
43718 -extern atomic_t cm_connect_reqs;
43719 -extern atomic_t cm_rejects;
43720 -extern atomic_t mod_qp_timouts;
43721 -extern atomic_t qps_created;
43722 -extern atomic_t qps_destroyed;
43723 -extern atomic_t sw_qps_destroyed;
43724 +extern atomic_unchecked_t cm_connects;
43725 +extern atomic_unchecked_t cm_accepts;
43726 +extern atomic_unchecked_t cm_disconnects;
43727 +extern atomic_unchecked_t cm_closes;
43728 +extern atomic_unchecked_t cm_connecteds;
43729 +extern atomic_unchecked_t cm_connect_reqs;
43730 +extern atomic_unchecked_t cm_rejects;
43731 +extern atomic_unchecked_t mod_qp_timouts;
43732 +extern atomic_unchecked_t qps_created;
43733 +extern atomic_unchecked_t qps_destroyed;
43734 +extern atomic_unchecked_t sw_qps_destroyed;
43735 extern u32 mh_detected;
43736 extern u32 mh_pauses_sent;
43737 extern u32 cm_packets_sent;
43738 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43739 extern u32 cm_packets_received;
43740 extern u32 cm_packets_dropped;
43741 extern u32 cm_packets_retrans;
43742 -extern atomic_t cm_listens_created;
43743 -extern atomic_t cm_listens_destroyed;
43744 +extern atomic_unchecked_t cm_listens_created;
43745 +extern atomic_unchecked_t cm_listens_destroyed;
43746 extern u32 cm_backlog_drops;
43747 -extern atomic_t cm_loopbacks;
43748 -extern atomic_t cm_nodes_created;
43749 -extern atomic_t cm_nodes_destroyed;
43750 -extern atomic_t cm_accel_dropped_pkts;
43751 -extern atomic_t cm_resets_recvd;
43752 -extern atomic_t pau_qps_created;
43753 -extern atomic_t pau_qps_destroyed;
43754 +extern atomic_unchecked_t cm_loopbacks;
43755 +extern atomic_unchecked_t cm_nodes_created;
43756 +extern atomic_unchecked_t cm_nodes_destroyed;
43757 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43758 +extern atomic_unchecked_t cm_resets_recvd;
43759 +extern atomic_unchecked_t pau_qps_created;
43760 +extern atomic_unchecked_t pau_qps_destroyed;
43761
43762 extern u32 int_mod_timer_init;
43763 extern u32 int_mod_cq_depth_256;
43764 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43765 index 6f09a72..cf4399d 100644
43766 --- a/drivers/infiniband/hw/nes/nes_cm.c
43767 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43768 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43769 u32 cm_packets_retrans;
43770 u32 cm_packets_created;
43771 u32 cm_packets_received;
43772 -atomic_t cm_listens_created;
43773 -atomic_t cm_listens_destroyed;
43774 +atomic_unchecked_t cm_listens_created;
43775 +atomic_unchecked_t cm_listens_destroyed;
43776 u32 cm_backlog_drops;
43777 -atomic_t cm_loopbacks;
43778 -atomic_t cm_nodes_created;
43779 -atomic_t cm_nodes_destroyed;
43780 -atomic_t cm_accel_dropped_pkts;
43781 -atomic_t cm_resets_recvd;
43782 +atomic_unchecked_t cm_loopbacks;
43783 +atomic_unchecked_t cm_nodes_created;
43784 +atomic_unchecked_t cm_nodes_destroyed;
43785 +atomic_unchecked_t cm_accel_dropped_pkts;
43786 +atomic_unchecked_t cm_resets_recvd;
43787
43788 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43789 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43790 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43791 /* instance of function pointers for client API */
43792 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43793 static struct nes_cm_ops nes_cm_api = {
43794 - mini_cm_accelerated,
43795 - mini_cm_listen,
43796 - mini_cm_del_listen,
43797 - mini_cm_connect,
43798 - mini_cm_close,
43799 - mini_cm_accept,
43800 - mini_cm_reject,
43801 - mini_cm_recv_pkt,
43802 - mini_cm_dealloc_core,
43803 - mini_cm_get,
43804 - mini_cm_set
43805 + .accelerated = mini_cm_accelerated,
43806 + .listen = mini_cm_listen,
43807 + .stop_listener = mini_cm_del_listen,
43808 + .connect = mini_cm_connect,
43809 + .close = mini_cm_close,
43810 + .accept = mini_cm_accept,
43811 + .reject = mini_cm_reject,
43812 + .recv_pkt = mini_cm_recv_pkt,
43813 + .destroy_cm_core = mini_cm_dealloc_core,
43814 + .get = mini_cm_get,
43815 + .set = mini_cm_set
43816 };
43817
43818 static struct nes_cm_core *g_cm_core;
43819
43820 -atomic_t cm_connects;
43821 -atomic_t cm_accepts;
43822 -atomic_t cm_disconnects;
43823 -atomic_t cm_closes;
43824 -atomic_t cm_connecteds;
43825 -atomic_t cm_connect_reqs;
43826 -atomic_t cm_rejects;
43827 +atomic_unchecked_t cm_connects;
43828 +atomic_unchecked_t cm_accepts;
43829 +atomic_unchecked_t cm_disconnects;
43830 +atomic_unchecked_t cm_closes;
43831 +atomic_unchecked_t cm_connecteds;
43832 +atomic_unchecked_t cm_connect_reqs;
43833 +atomic_unchecked_t cm_rejects;
43834
43835 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43836 {
43837 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43838 kfree(listener);
43839 listener = NULL;
43840 ret = 0;
43841 - atomic_inc(&cm_listens_destroyed);
43842 + atomic_inc_unchecked(&cm_listens_destroyed);
43843 } else {
43844 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43845 }
43846 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43847 cm_node->rem_mac);
43848
43849 add_hte_node(cm_core, cm_node);
43850 - atomic_inc(&cm_nodes_created);
43851 + atomic_inc_unchecked(&cm_nodes_created);
43852
43853 return cm_node;
43854 }
43855 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43856 }
43857
43858 atomic_dec(&cm_core->node_cnt);
43859 - atomic_inc(&cm_nodes_destroyed);
43860 + atomic_inc_unchecked(&cm_nodes_destroyed);
43861 nesqp = cm_node->nesqp;
43862 if (nesqp) {
43863 nesqp->cm_node = NULL;
43864 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43865
43866 static void drop_packet(struct sk_buff *skb)
43867 {
43868 - atomic_inc(&cm_accel_dropped_pkts);
43869 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43870 dev_kfree_skb_any(skb);
43871 }
43872
43873 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43874 {
43875
43876 int reset = 0; /* whether to send reset in case of err.. */
43877 - atomic_inc(&cm_resets_recvd);
43878 + atomic_inc_unchecked(&cm_resets_recvd);
43879 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43880 " refcnt=%d\n", cm_node, cm_node->state,
43881 atomic_read(&cm_node->ref_count));
43882 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43883 rem_ref_cm_node(cm_node->cm_core, cm_node);
43884 return NULL;
43885 }
43886 - atomic_inc(&cm_loopbacks);
43887 + atomic_inc_unchecked(&cm_loopbacks);
43888 loopbackremotenode->loopbackpartner = cm_node;
43889 loopbackremotenode->tcp_cntxt.rcv_wscale =
43890 NES_CM_DEFAULT_RCV_WND_SCALE;
43891 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43892 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43893 else {
43894 rem_ref_cm_node(cm_core, cm_node);
43895 - atomic_inc(&cm_accel_dropped_pkts);
43896 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43897 dev_kfree_skb_any(skb);
43898 }
43899 break;
43900 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43901
43902 if ((cm_id) && (cm_id->event_handler)) {
43903 if (issue_disconn) {
43904 - atomic_inc(&cm_disconnects);
43905 + atomic_inc_unchecked(&cm_disconnects);
43906 cm_event.event = IW_CM_EVENT_DISCONNECT;
43907 cm_event.status = disconn_status;
43908 cm_event.local_addr = cm_id->local_addr;
43909 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43910 }
43911
43912 if (issue_close) {
43913 - atomic_inc(&cm_closes);
43914 + atomic_inc_unchecked(&cm_closes);
43915 nes_disconnect(nesqp, 1);
43916
43917 cm_id->provider_data = nesqp;
43918 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43919
43920 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43921 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43922 - atomic_inc(&cm_accepts);
43923 + atomic_inc_unchecked(&cm_accepts);
43924
43925 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43926 netdev_refcnt_read(nesvnic->netdev));
43927 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43928 struct nes_cm_core *cm_core;
43929 u8 *start_buff;
43930
43931 - atomic_inc(&cm_rejects);
43932 + atomic_inc_unchecked(&cm_rejects);
43933 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43934 loopback = cm_node->loopbackpartner;
43935 cm_core = cm_node->cm_core;
43936 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43937 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43938 ntohs(laddr->sin_port));
43939
43940 - atomic_inc(&cm_connects);
43941 + atomic_inc_unchecked(&cm_connects);
43942 nesqp->active_conn = 1;
43943
43944 /* cache the cm_id in the qp */
43945 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43946 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43947 return err;
43948 }
43949 - atomic_inc(&cm_listens_created);
43950 + atomic_inc_unchecked(&cm_listens_created);
43951 }
43952
43953 cm_id->add_ref(cm_id);
43954 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43955
43956 if (nesqp->destroyed)
43957 return;
43958 - atomic_inc(&cm_connecteds);
43959 + atomic_inc_unchecked(&cm_connecteds);
43960 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43961 " local port 0x%04X. jiffies = %lu.\n",
43962 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43963 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43964
43965 cm_id->add_ref(cm_id);
43966 ret = cm_id->event_handler(cm_id, &cm_event);
43967 - atomic_inc(&cm_closes);
43968 + atomic_inc_unchecked(&cm_closes);
43969 cm_event.event = IW_CM_EVENT_CLOSE;
43970 cm_event.status = 0;
43971 cm_event.provider_data = cm_id->provider_data;
43972 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43973 return;
43974 cm_id = cm_node->cm_id;
43975
43976 - atomic_inc(&cm_connect_reqs);
43977 + atomic_inc_unchecked(&cm_connect_reqs);
43978 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43979 cm_node, cm_id, jiffies);
43980
43981 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43982 return;
43983 cm_id = cm_node->cm_id;
43984
43985 - atomic_inc(&cm_connect_reqs);
43986 + atomic_inc_unchecked(&cm_connect_reqs);
43987 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43988 cm_node, cm_id, jiffies);
43989
43990 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43991 index 4166452..fc952c3 100644
43992 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43993 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43994 @@ -40,8 +40,8 @@
43995 #include "nes.h"
43996 #include "nes_mgt.h"
43997
43998 -atomic_t pau_qps_created;
43999 -atomic_t pau_qps_destroyed;
44000 +atomic_unchecked_t pau_qps_created;
44001 +atomic_unchecked_t pau_qps_destroyed;
44002
44003 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44004 {
44005 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44006 {
44007 struct sk_buff *skb;
44008 unsigned long flags;
44009 - atomic_inc(&pau_qps_destroyed);
44010 + atomic_inc_unchecked(&pau_qps_destroyed);
44011
44012 /* Free packets that have not yet been forwarded */
44013 /* Lock is acquired by skb_dequeue when removing the skb */
44014 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44015 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44016 skb_queue_head_init(&nesqp->pau_list);
44017 spin_lock_init(&nesqp->pau_lock);
44018 - atomic_inc(&pau_qps_created);
44019 + atomic_inc_unchecked(&pau_qps_created);
44020 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44021 }
44022
44023 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44024 index 49eb511..a774366 100644
44025 --- a/drivers/infiniband/hw/nes/nes_nic.c
44026 +++ b/drivers/infiniband/hw/nes/nes_nic.c
44027 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44028 target_stat_values[++index] = mh_detected;
44029 target_stat_values[++index] = mh_pauses_sent;
44030 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44031 - target_stat_values[++index] = atomic_read(&cm_connects);
44032 - target_stat_values[++index] = atomic_read(&cm_accepts);
44033 - target_stat_values[++index] = atomic_read(&cm_disconnects);
44034 - target_stat_values[++index] = atomic_read(&cm_connecteds);
44035 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44036 - target_stat_values[++index] = atomic_read(&cm_rejects);
44037 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44038 - target_stat_values[++index] = atomic_read(&qps_created);
44039 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44040 - target_stat_values[++index] = atomic_read(&qps_destroyed);
44041 - target_stat_values[++index] = atomic_read(&cm_closes);
44042 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44043 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44044 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44045 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44046 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44047 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44048 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44049 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44050 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44051 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44052 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44053 target_stat_values[++index] = cm_packets_sent;
44054 target_stat_values[++index] = cm_packets_bounced;
44055 target_stat_values[++index] = cm_packets_created;
44056 target_stat_values[++index] = cm_packets_received;
44057 target_stat_values[++index] = cm_packets_dropped;
44058 target_stat_values[++index] = cm_packets_retrans;
44059 - target_stat_values[++index] = atomic_read(&cm_listens_created);
44060 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44061 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44062 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44063 target_stat_values[++index] = cm_backlog_drops;
44064 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
44065 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
44066 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44067 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44068 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44069 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44070 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44071 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44072 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44073 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44074 target_stat_values[++index] = nesadapter->free_4kpbl;
44075 target_stat_values[++index] = nesadapter->free_256pbl;
44076 target_stat_values[++index] = int_mod_timer_init;
44077 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44078 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44079 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44080 - target_stat_values[++index] = atomic_read(&pau_qps_created);
44081 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44082 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44083 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44084 }
44085
44086 /**
44087 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44088 index fef067c..6a25ccd 100644
44089 --- a/drivers/infiniband/hw/nes/nes_verbs.c
44090 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
44091 @@ -46,9 +46,9 @@
44092
44093 #include <rdma/ib_umem.h>
44094
44095 -atomic_t mod_qp_timouts;
44096 -atomic_t qps_created;
44097 -atomic_t sw_qps_destroyed;
44098 +atomic_unchecked_t mod_qp_timouts;
44099 +atomic_unchecked_t qps_created;
44100 +atomic_unchecked_t sw_qps_destroyed;
44101
44102 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44103
44104 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44105 if (init_attr->create_flags)
44106 return ERR_PTR(-EINVAL);
44107
44108 - atomic_inc(&qps_created);
44109 + atomic_inc_unchecked(&qps_created);
44110 switch (init_attr->qp_type) {
44111 case IB_QPT_RC:
44112 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44113 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44114 struct iw_cm_event cm_event;
44115 int ret = 0;
44116
44117 - atomic_inc(&sw_qps_destroyed);
44118 + atomic_inc_unchecked(&sw_qps_destroyed);
44119 nesqp->destroyed = 1;
44120
44121 /* Blow away the connection if it exists. */
44122 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44123 index c00ae09..04e91be 100644
44124 --- a/drivers/infiniband/hw/qib/qib.h
44125 +++ b/drivers/infiniband/hw/qib/qib.h
44126 @@ -52,6 +52,7 @@
44127 #include <linux/kref.h>
44128 #include <linux/sched.h>
44129 #include <linux/kthread.h>
44130 +#include <linux/slab.h>
44131
44132 #include "qib_common.h"
44133 #include "qib_verbs.h"
44134 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44135 index cdc7df4..a2fdfdb 100644
44136 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44137 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44138 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
44139 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
44140 }
44141
44142 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
44143 +static struct rtnl_link_ops ipoib_link_ops = {
44144 .kind = "ipoib",
44145 .maxtype = IFLA_IPOIB_MAX,
44146 .policy = ipoib_policy,
44147 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44148 index 24c41ba..102d71f 100644
44149 --- a/drivers/input/gameport/gameport.c
44150 +++ b/drivers/input/gameport/gameport.c
44151 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44152 */
44153 static void gameport_init_port(struct gameport *gameport)
44154 {
44155 - static atomic_t gameport_no = ATOMIC_INIT(0);
44156 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44157
44158 __module_get(THIS_MODULE);
44159
44160 mutex_init(&gameport->drv_mutex);
44161 device_initialize(&gameport->dev);
44162 dev_set_name(&gameport->dev, "gameport%lu",
44163 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
44164 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44165 gameport->dev.bus = &gameport_bus;
44166 gameport->dev.release = gameport_release_port;
44167 if (gameport->parent)
44168 diff --git a/drivers/input/input.c b/drivers/input/input.c
44169 index 29ca0bb..f4bc2e3 100644
44170 --- a/drivers/input/input.c
44171 +++ b/drivers/input/input.c
44172 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44173 */
44174 struct input_dev *input_allocate_device(void)
44175 {
44176 - static atomic_t input_no = ATOMIC_INIT(0);
44177 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44178 struct input_dev *dev;
44179
44180 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44181 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44182 INIT_LIST_HEAD(&dev->node);
44183
44184 dev_set_name(&dev->dev, "input%ld",
44185 - (unsigned long) atomic_inc_return(&input_no) - 1);
44186 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44187
44188 __module_get(THIS_MODULE);
44189 }
44190 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44191 index 4a95b22..874c182 100644
44192 --- a/drivers/input/joystick/sidewinder.c
44193 +++ b/drivers/input/joystick/sidewinder.c
44194 @@ -30,6 +30,7 @@
44195 #include <linux/kernel.h>
44196 #include <linux/module.h>
44197 #include <linux/slab.h>
44198 +#include <linux/sched.h>
44199 #include <linux/input.h>
44200 #include <linux/gameport.h>
44201 #include <linux/jiffies.h>
44202 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44203 index e65d9c0..ad3942e 100644
44204 --- a/drivers/input/joystick/xpad.c
44205 +++ b/drivers/input/joystick/xpad.c
44206 @@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44207
44208 static int xpad_led_probe(struct usb_xpad *xpad)
44209 {
44210 - static atomic_t led_seq = ATOMIC_INIT(0);
44211 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44212 long led_no;
44213 struct xpad_led *led;
44214 struct led_classdev *led_cdev;
44215 @@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44216 if (!led)
44217 return -ENOMEM;
44218
44219 - led_no = (long)atomic_inc_return(&led_seq) - 1;
44220 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44221
44222 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44223 led->xpad = xpad;
44224 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44225 index 719410f..1896169 100644
44226 --- a/drivers/input/misc/ims-pcu.c
44227 +++ b/drivers/input/misc/ims-pcu.c
44228 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44229
44230 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44231 {
44232 - static atomic_t device_no = ATOMIC_INIT(0);
44233 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44234
44235 const struct ims_pcu_device_info *info;
44236 int error;
44237 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44238 }
44239
44240 /* Device appears to be operable, complete initialization */
44241 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44242 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44243
44244 /*
44245 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44246 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44247 index 2f0b39d..7370f13 100644
44248 --- a/drivers/input/mouse/psmouse.h
44249 +++ b/drivers/input/mouse/psmouse.h
44250 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44251 ssize_t (*set)(struct psmouse *psmouse, void *data,
44252 const char *buf, size_t count);
44253 bool protect;
44254 -};
44255 +} __do_const;
44256 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44257
44258 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44259 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44260 index b604564..3f14ae4 100644
44261 --- a/drivers/input/mousedev.c
44262 +++ b/drivers/input/mousedev.c
44263 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44264
44265 spin_unlock_irq(&client->packet_lock);
44266
44267 - if (copy_to_user(buffer, data, count))
44268 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44269 return -EFAULT;
44270
44271 return count;
44272 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44273 index b29134d..394deb0 100644
44274 --- a/drivers/input/serio/serio.c
44275 +++ b/drivers/input/serio/serio.c
44276 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44277 */
44278 static void serio_init_port(struct serio *serio)
44279 {
44280 - static atomic_t serio_no = ATOMIC_INIT(0);
44281 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44282
44283 __module_get(THIS_MODULE);
44284
44285 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44286 mutex_init(&serio->drv_mutex);
44287 device_initialize(&serio->dev);
44288 dev_set_name(&serio->dev, "serio%ld",
44289 - (long)atomic_inc_return(&serio_no) - 1);
44290 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44291 serio->dev.bus = &serio_bus;
44292 serio->dev.release = serio_release_port;
44293 serio->dev.groups = serio_device_attr_groups;
44294 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44295 index c9a02fe..0debc75 100644
44296 --- a/drivers/input/serio/serio_raw.c
44297 +++ b/drivers/input/serio/serio_raw.c
44298 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44299
44300 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44301 {
44302 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44303 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44304 struct serio_raw *serio_raw;
44305 int err;
44306
44307 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44308 }
44309
44310 snprintf(serio_raw->name, sizeof(serio_raw->name),
44311 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44312 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44313 kref_init(&serio_raw->kref);
44314 INIT_LIST_HEAD(&serio_raw->client_list);
44315 init_waitqueue_head(&serio_raw->wait);
44316 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
44317 index 5aff937..9cff67c 100644
44318 --- a/drivers/iommu/amd_iommu.c
44319 +++ b/drivers/iommu/amd_iommu.c
44320 @@ -798,11 +798,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
44321
44322 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
44323 {
44324 + phys_addr_t physaddr;
44325 WARN_ON(address & 0x7ULL);
44326
44327 memset(cmd, 0, sizeof(*cmd));
44328 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
44329 - cmd->data[1] = upper_32_bits(__pa(address));
44330 +
44331 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
44332 + if (object_starts_on_stack(address)) {
44333 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
44334 + physaddr = __pa((u64)adjbuf);
44335 + } else
44336 +#endif
44337 + physaddr = __pa(address);
44338 +
44339 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
44340 + cmd->data[1] = upper_32_bits(physaddr);
44341 cmd->data[2] = 1;
44342 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
44343 }
44344 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44345 index a83cc2a..64462e6 100644
44346 --- a/drivers/iommu/arm-smmu.c
44347 +++ b/drivers/iommu/arm-smmu.c
44348 @@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44349 cfg->irptndx = cfg->cbndx;
44350 }
44351
44352 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
44353 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44354 arm_smmu_init_context_bank(smmu_domain);
44355 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44356
44357 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44358 index 33c4395..e06447e 100644
44359 --- a/drivers/iommu/irq_remapping.c
44360 +++ b/drivers/iommu/irq_remapping.c
44361 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44362 void panic_if_irq_remap(const char *msg)
44363 {
44364 if (irq_remapping_enabled)
44365 - panic(msg);
44366 + panic("%s", msg);
44367 }
44368
44369 static void ir_ack_apic_edge(struct irq_data *data)
44370 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44371
44372 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44373 {
44374 - chip->irq_print_chip = ir_print_prefix;
44375 - chip->irq_ack = ir_ack_apic_edge;
44376 - chip->irq_eoi = ir_ack_apic_level;
44377 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44378 + pax_open_kernel();
44379 + *(void **)&chip->irq_print_chip = ir_print_prefix;
44380 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
44381 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
44382 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44383 + pax_close_kernel();
44384 }
44385
44386 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44387 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44388 index dda6dbc..f9adebb 100644
44389 --- a/drivers/irqchip/irq-gic.c
44390 +++ b/drivers/irqchip/irq-gic.c
44391 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44392 * Supported arch specific GIC irq extension.
44393 * Default make them NULL.
44394 */
44395 -struct irq_chip gic_arch_extn = {
44396 +irq_chip_no_const gic_arch_extn = {
44397 .irq_eoi = NULL,
44398 .irq_mask = NULL,
44399 .irq_unmask = NULL,
44400 @@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44401 chained_irq_exit(chip, desc);
44402 }
44403
44404 -static struct irq_chip gic_chip = {
44405 +static irq_chip_no_const gic_chip __read_only = {
44406 .name = "GIC",
44407 .irq_mask = gic_mask_irq,
44408 .irq_unmask = gic_unmask_irq,
44409 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44410 index 8777065..a4a9967 100644
44411 --- a/drivers/irqchip/irq-renesas-irqc.c
44412 +++ b/drivers/irqchip/irq-renesas-irqc.c
44413 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44414 struct irqc_priv *p;
44415 struct resource *io;
44416 struct resource *irq;
44417 - struct irq_chip *irq_chip;
44418 + irq_chip_no_const *irq_chip;
44419 const char *name = dev_name(&pdev->dev);
44420 int ret;
44421 int k;
44422 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44423 index 6a2df32..dc962f1 100644
44424 --- a/drivers/isdn/capi/capi.c
44425 +++ b/drivers/isdn/capi/capi.c
44426 @@ -81,8 +81,8 @@ struct capiminor {
44427
44428 struct capi20_appl *ap;
44429 u32 ncci;
44430 - atomic_t datahandle;
44431 - atomic_t msgid;
44432 + atomic_unchecked_t datahandle;
44433 + atomic_unchecked_t msgid;
44434
44435 struct tty_port port;
44436 int ttyinstop;
44437 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44438 capimsg_setu16(s, 2, mp->ap->applid);
44439 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44440 capimsg_setu8 (s, 5, CAPI_RESP);
44441 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44442 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44443 capimsg_setu32(s, 8, mp->ncci);
44444 capimsg_setu16(s, 12, datahandle);
44445 }
44446 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44447 mp->outbytes -= len;
44448 spin_unlock_bh(&mp->outlock);
44449
44450 - datahandle = atomic_inc_return(&mp->datahandle);
44451 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44452 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44453 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44454 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44455 capimsg_setu16(skb->data, 2, mp->ap->applid);
44456 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44457 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44458 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44459 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44460 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44461 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44462 capimsg_setu16(skb->data, 16, len); /* Data length */
44463 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44464 index b7ae0a0..04590fa 100644
44465 --- a/drivers/isdn/gigaset/bas-gigaset.c
44466 +++ b/drivers/isdn/gigaset/bas-gigaset.c
44467 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44468
44469
44470 static const struct gigaset_ops gigops = {
44471 - gigaset_write_cmd,
44472 - gigaset_write_room,
44473 - gigaset_chars_in_buffer,
44474 - gigaset_brkchars,
44475 - gigaset_init_bchannel,
44476 - gigaset_close_bchannel,
44477 - gigaset_initbcshw,
44478 - gigaset_freebcshw,
44479 - gigaset_reinitbcshw,
44480 - gigaset_initcshw,
44481 - gigaset_freecshw,
44482 - gigaset_set_modem_ctrl,
44483 - gigaset_baud_rate,
44484 - gigaset_set_line_ctrl,
44485 - gigaset_isoc_send_skb,
44486 - gigaset_isoc_input,
44487 + .write_cmd = gigaset_write_cmd,
44488 + .write_room = gigaset_write_room,
44489 + .chars_in_buffer = gigaset_chars_in_buffer,
44490 + .brkchars = gigaset_brkchars,
44491 + .init_bchannel = gigaset_init_bchannel,
44492 + .close_bchannel = gigaset_close_bchannel,
44493 + .initbcshw = gigaset_initbcshw,
44494 + .freebcshw = gigaset_freebcshw,
44495 + .reinitbcshw = gigaset_reinitbcshw,
44496 + .initcshw = gigaset_initcshw,
44497 + .freecshw = gigaset_freecshw,
44498 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44499 + .baud_rate = gigaset_baud_rate,
44500 + .set_line_ctrl = gigaset_set_line_ctrl,
44501 + .send_skb = gigaset_isoc_send_skb,
44502 + .handle_input = gigaset_isoc_input,
44503 };
44504
44505 /* bas_gigaset_init
44506 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44507 index 600c79b..3752bab 100644
44508 --- a/drivers/isdn/gigaset/interface.c
44509 +++ b/drivers/isdn/gigaset/interface.c
44510 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44511 }
44512 tty->driver_data = cs;
44513
44514 - ++cs->port.count;
44515 + atomic_inc(&cs->port.count);
44516
44517 - if (cs->port.count == 1) {
44518 + if (atomic_read(&cs->port.count) == 1) {
44519 tty_port_tty_set(&cs->port, tty);
44520 cs->port.low_latency = 1;
44521 }
44522 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44523
44524 if (!cs->connected)
44525 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44526 - else if (!cs->port.count)
44527 + else if (!atomic_read(&cs->port.count))
44528 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44529 - else if (!--cs->port.count)
44530 + else if (!atomic_dec_return(&cs->port.count))
44531 tty_port_tty_set(&cs->port, NULL);
44532
44533 mutex_unlock(&cs->mutex);
44534 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44535 index 8c91fd5..14f13ce 100644
44536 --- a/drivers/isdn/gigaset/ser-gigaset.c
44537 +++ b/drivers/isdn/gigaset/ser-gigaset.c
44538 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44539 }
44540
44541 static const struct gigaset_ops ops = {
44542 - gigaset_write_cmd,
44543 - gigaset_write_room,
44544 - gigaset_chars_in_buffer,
44545 - gigaset_brkchars,
44546 - gigaset_init_bchannel,
44547 - gigaset_close_bchannel,
44548 - gigaset_initbcshw,
44549 - gigaset_freebcshw,
44550 - gigaset_reinitbcshw,
44551 - gigaset_initcshw,
44552 - gigaset_freecshw,
44553 - gigaset_set_modem_ctrl,
44554 - gigaset_baud_rate,
44555 - gigaset_set_line_ctrl,
44556 - gigaset_m10x_send_skb, /* asyncdata.c */
44557 - gigaset_m10x_input, /* asyncdata.c */
44558 + .write_cmd = gigaset_write_cmd,
44559 + .write_room = gigaset_write_room,
44560 + .chars_in_buffer = gigaset_chars_in_buffer,
44561 + .brkchars = gigaset_brkchars,
44562 + .init_bchannel = gigaset_init_bchannel,
44563 + .close_bchannel = gigaset_close_bchannel,
44564 + .initbcshw = gigaset_initbcshw,
44565 + .freebcshw = gigaset_freebcshw,
44566 + .reinitbcshw = gigaset_reinitbcshw,
44567 + .initcshw = gigaset_initcshw,
44568 + .freecshw = gigaset_freecshw,
44569 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44570 + .baud_rate = gigaset_baud_rate,
44571 + .set_line_ctrl = gigaset_set_line_ctrl,
44572 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44573 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44574 };
44575
44576
44577 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44578 index d0a41cb..b953e50 100644
44579 --- a/drivers/isdn/gigaset/usb-gigaset.c
44580 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44581 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44582 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44583 memcpy(cs->hw.usb->bchars, buf, 6);
44584 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44585 - 0, 0, &buf, 6, 2000);
44586 + 0, 0, buf, 6, 2000);
44587 }
44588
44589 static void gigaset_freebcshw(struct bc_state *bcs)
44590 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44591 }
44592
44593 static const struct gigaset_ops ops = {
44594 - gigaset_write_cmd,
44595 - gigaset_write_room,
44596 - gigaset_chars_in_buffer,
44597 - gigaset_brkchars,
44598 - gigaset_init_bchannel,
44599 - gigaset_close_bchannel,
44600 - gigaset_initbcshw,
44601 - gigaset_freebcshw,
44602 - gigaset_reinitbcshw,
44603 - gigaset_initcshw,
44604 - gigaset_freecshw,
44605 - gigaset_set_modem_ctrl,
44606 - gigaset_baud_rate,
44607 - gigaset_set_line_ctrl,
44608 - gigaset_m10x_send_skb,
44609 - gigaset_m10x_input,
44610 + .write_cmd = gigaset_write_cmd,
44611 + .write_room = gigaset_write_room,
44612 + .chars_in_buffer = gigaset_chars_in_buffer,
44613 + .brkchars = gigaset_brkchars,
44614 + .init_bchannel = gigaset_init_bchannel,
44615 + .close_bchannel = gigaset_close_bchannel,
44616 + .initbcshw = gigaset_initbcshw,
44617 + .freebcshw = gigaset_freebcshw,
44618 + .reinitbcshw = gigaset_reinitbcshw,
44619 + .initcshw = gigaset_initcshw,
44620 + .freecshw = gigaset_freecshw,
44621 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44622 + .baud_rate = gigaset_baud_rate,
44623 + .set_line_ctrl = gigaset_set_line_ctrl,
44624 + .send_skb = gigaset_m10x_send_skb,
44625 + .handle_input = gigaset_m10x_input,
44626 };
44627
44628 /*
44629 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44630 index 4d9b195..455075c 100644
44631 --- a/drivers/isdn/hardware/avm/b1.c
44632 +++ b/drivers/isdn/hardware/avm/b1.c
44633 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44634 }
44635 if (left) {
44636 if (t4file->user) {
44637 - if (copy_from_user(buf, dp, left))
44638 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44639 return -EFAULT;
44640 } else {
44641 memcpy(buf, dp, left);
44642 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44643 }
44644 if (left) {
44645 if (config->user) {
44646 - if (copy_from_user(buf, dp, left))
44647 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44648 return -EFAULT;
44649 } else {
44650 memcpy(buf, dp, left);
44651 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44652 index 9b856e1..fa03c92 100644
44653 --- a/drivers/isdn/i4l/isdn_common.c
44654 +++ b/drivers/isdn/i4l/isdn_common.c
44655 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44656 } else
44657 return -EINVAL;
44658 case IIOCDBGVAR:
44659 + if (!capable(CAP_SYS_RAWIO))
44660 + return -EPERM;
44661 if (arg) {
44662 if (copy_to_user(argp, &dev, sizeof(ulong)))
44663 return -EFAULT;
44664 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44665 index 91d5730..336523e 100644
44666 --- a/drivers/isdn/i4l/isdn_concap.c
44667 +++ b/drivers/isdn/i4l/isdn_concap.c
44668 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44669 }
44670
44671 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44672 - &isdn_concap_dl_data_req,
44673 - &isdn_concap_dl_connect_req,
44674 - &isdn_concap_dl_disconn_req
44675 + .data_req = &isdn_concap_dl_data_req,
44676 + .connect_req = &isdn_concap_dl_connect_req,
44677 + .disconn_req = &isdn_concap_dl_disconn_req
44678 };
44679
44680 /* The following should better go into a dedicated source file such that
44681 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44682 index 3c5f249..5fac4d0 100644
44683 --- a/drivers/isdn/i4l/isdn_tty.c
44684 +++ b/drivers/isdn/i4l/isdn_tty.c
44685 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44686
44687 #ifdef ISDN_DEBUG_MODEM_OPEN
44688 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44689 - port->count);
44690 + atomic_read(&port->count));
44691 #endif
44692 - port->count++;
44693 + atomic_inc(&port->count);
44694 port->tty = tty;
44695 /*
44696 * Start up serial port
44697 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44698 #endif
44699 return;
44700 }
44701 - if ((tty->count == 1) && (port->count != 1)) {
44702 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44703 /*
44704 * Uh, oh. tty->count is 1, which means that the tty
44705 * structure will be freed. Info->count should always
44706 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44707 * serial port won't be shutdown.
44708 */
44709 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44710 - "info->count is %d\n", port->count);
44711 - port->count = 1;
44712 + "info->count is %d\n", atomic_read(&port->count));
44713 + atomic_set(&port->count, 1);
44714 }
44715 - if (--port->count < 0) {
44716 + if (atomic_dec_return(&port->count) < 0) {
44717 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44718 - info->line, port->count);
44719 - port->count = 0;
44720 + info->line, atomic_read(&port->count));
44721 + atomic_set(&port->count, 0);
44722 }
44723 - if (port->count) {
44724 + if (atomic_read(&port->count)) {
44725 #ifdef ISDN_DEBUG_MODEM_OPEN
44726 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44727 #endif
44728 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44729 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44730 return;
44731 isdn_tty_shutdown(info);
44732 - port->count = 0;
44733 + atomic_set(&port->count, 0);
44734 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44735 port->tty = NULL;
44736 wake_up_interruptible(&port->open_wait);
44737 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44738 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44739 modem_info *info = &dev->mdm.info[i];
44740
44741 - if (info->port.count == 0)
44742 + if (atomic_read(&info->port.count) == 0)
44743 continue;
44744 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44745 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44746 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44747 index e2d4e58..40cd045 100644
44748 --- a/drivers/isdn/i4l/isdn_x25iface.c
44749 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44750 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44751
44752
44753 static struct concap_proto_ops ix25_pops = {
44754 - &isdn_x25iface_proto_new,
44755 - &isdn_x25iface_proto_del,
44756 - &isdn_x25iface_proto_restart,
44757 - &isdn_x25iface_proto_close,
44758 - &isdn_x25iface_xmit,
44759 - &isdn_x25iface_receive,
44760 - &isdn_x25iface_connect_ind,
44761 - &isdn_x25iface_disconn_ind
44762 + .proto_new = &isdn_x25iface_proto_new,
44763 + .proto_del = &isdn_x25iface_proto_del,
44764 + .restart = &isdn_x25iface_proto_restart,
44765 + .close = &isdn_x25iface_proto_close,
44766 + .encap_and_xmit = &isdn_x25iface_xmit,
44767 + .data_ind = &isdn_x25iface_receive,
44768 + .connect_ind = &isdn_x25iface_connect_ind,
44769 + .disconn_ind = &isdn_x25iface_disconn_ind
44770 };
44771
44772 /* error message helper function */
44773 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44774 index 6a7447c..cae33fe 100644
44775 --- a/drivers/isdn/icn/icn.c
44776 +++ b/drivers/isdn/icn/icn.c
44777 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44778 if (count > len)
44779 count = len;
44780 if (user) {
44781 - if (copy_from_user(msg, buf, count))
44782 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44783 return -EFAULT;
44784 } else
44785 memcpy(msg, buf, count);
44786 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44787 index a4f05c5..1433bc5 100644
44788 --- a/drivers/isdn/mISDN/dsp_cmx.c
44789 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44790 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44791 static u16 dsp_count; /* last sample count */
44792 static int dsp_count_valid; /* if we have last sample count */
44793
44794 -void
44795 +void __intentional_overflow(-1)
44796 dsp_cmx_send(void *arg)
44797 {
44798 struct dsp_conf *conf;
44799 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44800 index f58a354..fbae176 100644
44801 --- a/drivers/leds/leds-clevo-mail.c
44802 +++ b/drivers/leds/leds-clevo-mail.c
44803 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44804 * detected as working, but in reality it is not) as low as
44805 * possible.
44806 */
44807 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44808 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44809 {
44810 .callback = clevo_mail_led_dmi_callback,
44811 .ident = "Clevo D410J",
44812 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44813 index 046cb70..6b20d39 100644
44814 --- a/drivers/leds/leds-ss4200.c
44815 +++ b/drivers/leds/leds-ss4200.c
44816 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44817 * detected as working, but in reality it is not) as low as
44818 * possible.
44819 */
44820 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44821 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44822 {
44823 .callback = ss4200_led_dmi_callback,
44824 .ident = "Intel SS4200-E",
44825 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44826 index 6590558..a74c5dd 100644
44827 --- a/drivers/lguest/core.c
44828 +++ b/drivers/lguest/core.c
44829 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44830 * The end address needs +1 because __get_vm_area allocates an
44831 * extra guard page, so we need space for that.
44832 */
44833 +
44834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44835 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44836 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44837 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44838 +#else
44839 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44840 VM_ALLOC, switcher_addr, switcher_addr
44841 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44842 +#endif
44843 +
44844 if (!switcher_vma) {
44845 err = -ENOMEM;
44846 printk("lguest: could not map switcher pages high\n");
44847 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44848 * Now the Switcher is mapped at the right address, we can't fail!
44849 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44850 */
44851 - memcpy(switcher_vma->addr, start_switcher_text,
44852 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44853 end_switcher_text - start_switcher_text);
44854
44855 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44856 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44857 index e8b55c3..3514c37 100644
44858 --- a/drivers/lguest/page_tables.c
44859 +++ b/drivers/lguest/page_tables.c
44860 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44861 /*:*/
44862
44863 #ifdef CONFIG_X86_PAE
44864 -static void release_pmd(pmd_t *spmd)
44865 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44866 {
44867 /* If the entry's not present, there's nothing to release. */
44868 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44869 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44870 index 922a1ac..9dd0c2a 100644
44871 --- a/drivers/lguest/x86/core.c
44872 +++ b/drivers/lguest/x86/core.c
44873 @@ -59,7 +59,7 @@ static struct {
44874 /* Offset from where switcher.S was compiled to where we've copied it */
44875 static unsigned long switcher_offset(void)
44876 {
44877 - return switcher_addr - (unsigned long)start_switcher_text;
44878 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44879 }
44880
44881 /* This cpu's struct lguest_pages (after the Switcher text page) */
44882 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44883 * These copies are pretty cheap, so we do them unconditionally: */
44884 /* Save the current Host top-level page directory.
44885 */
44886 +
44887 +#ifdef CONFIG_PAX_PER_CPU_PGD
44888 + pages->state.host_cr3 = read_cr3();
44889 +#else
44890 pages->state.host_cr3 = __pa(current->mm->pgd);
44891 +#endif
44892 +
44893 /*
44894 * Set up the Guest's page tables to see this CPU's pages (and no
44895 * other CPU's pages).
44896 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44897 * compiled-in switcher code and the high-mapped copy we just made.
44898 */
44899 for (i = 0; i < IDT_ENTRIES; i++)
44900 - default_idt_entries[i] += switcher_offset();
44901 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44902
44903 /*
44904 * Set up the Switcher's per-cpu areas.
44905 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44906 * it will be undisturbed when we switch. To change %cs and jump we
44907 * need this structure to feed to Intel's "lcall" instruction.
44908 */
44909 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44910 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44911 lguest_entry.segment = LGUEST_CS;
44912
44913 /*
44914 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44915 index 40634b0..4f5855e 100644
44916 --- a/drivers/lguest/x86/switcher_32.S
44917 +++ b/drivers/lguest/x86/switcher_32.S
44918 @@ -87,6 +87,7 @@
44919 #include <asm/page.h>
44920 #include <asm/segment.h>
44921 #include <asm/lguest.h>
44922 +#include <asm/processor-flags.h>
44923
44924 // We mark the start of the code to copy
44925 // It's placed in .text tho it's never run here
44926 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44927 // Changes type when we load it: damn Intel!
44928 // For after we switch over our page tables
44929 // That entry will be read-only: we'd crash.
44930 +
44931 +#ifdef CONFIG_PAX_KERNEXEC
44932 + mov %cr0, %edx
44933 + xor $X86_CR0_WP, %edx
44934 + mov %edx, %cr0
44935 +#endif
44936 +
44937 movl $(GDT_ENTRY_TSS*8), %edx
44938 ltr %dx
44939
44940 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44941 // Let's clear it again for our return.
44942 // The GDT descriptor of the Host
44943 // Points to the table after two "size" bytes
44944 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44945 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44946 // Clear "used" from type field (byte 5, bit 2)
44947 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44948 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44949 +
44950 +#ifdef CONFIG_PAX_KERNEXEC
44951 + mov %cr0, %eax
44952 + xor $X86_CR0_WP, %eax
44953 + mov %eax, %cr0
44954 +#endif
44955
44956 // Once our page table's switched, the Guest is live!
44957 // The Host fades as we run this final step.
44958 @@ -295,13 +309,12 @@ deliver_to_host:
44959 // I consulted gcc, and it gave
44960 // These instructions, which I gladly credit:
44961 leal (%edx,%ebx,8), %eax
44962 - movzwl (%eax),%edx
44963 - movl 4(%eax), %eax
44964 - xorw %ax, %ax
44965 - orl %eax, %edx
44966 + movl 4(%eax), %edx
44967 + movw (%eax), %dx
44968 // Now the address of the handler's in %edx
44969 // We call it now: its "iret" drops us home.
44970 - jmp *%edx
44971 + ljmp $__KERNEL_CS, $1f
44972 +1: jmp *%edx
44973
44974 // Every interrupt can come to us here
44975 // But we must truly tell each apart.
44976 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44977 index a08e3ee..df8ade2 100644
44978 --- a/drivers/md/bcache/closure.h
44979 +++ b/drivers/md/bcache/closure.h
44980 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44981 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44982 struct workqueue_struct *wq)
44983 {
44984 - BUG_ON(object_is_on_stack(cl));
44985 + BUG_ON(object_starts_on_stack(cl));
44986 closure_set_ip(cl);
44987 cl->fn = fn;
44988 cl->wq = wq;
44989 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44990 index 67f8b31..9418f2b 100644
44991 --- a/drivers/md/bitmap.c
44992 +++ b/drivers/md/bitmap.c
44993 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44994 chunk_kb ? "KB" : "B");
44995 if (bitmap->storage.file) {
44996 seq_printf(seq, ", file: ");
44997 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44998 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44999 }
45000
45001 seq_printf(seq, "\n");
45002 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45003 index 5152142..623d141 100644
45004 --- a/drivers/md/dm-ioctl.c
45005 +++ b/drivers/md/dm-ioctl.c
45006 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45007 cmd == DM_LIST_VERSIONS_CMD)
45008 return 0;
45009
45010 - if ((cmd == DM_DEV_CREATE_CMD)) {
45011 + if (cmd == DM_DEV_CREATE_CMD) {
45012 if (!*param->name) {
45013 DMWARN("name not supplied when creating device");
45014 return -EINVAL;
45015 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45016 index 7dfdb5c..4caada6 100644
45017 --- a/drivers/md/dm-raid1.c
45018 +++ b/drivers/md/dm-raid1.c
45019 @@ -40,7 +40,7 @@ enum dm_raid1_error {
45020
45021 struct mirror {
45022 struct mirror_set *ms;
45023 - atomic_t error_count;
45024 + atomic_unchecked_t error_count;
45025 unsigned long error_type;
45026 struct dm_dev *dev;
45027 sector_t offset;
45028 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45029 struct mirror *m;
45030
45031 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45032 - if (!atomic_read(&m->error_count))
45033 + if (!atomic_read_unchecked(&m->error_count))
45034 return m;
45035
45036 return NULL;
45037 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45038 * simple way to tell if a device has encountered
45039 * errors.
45040 */
45041 - atomic_inc(&m->error_count);
45042 + atomic_inc_unchecked(&m->error_count);
45043
45044 if (test_and_set_bit(error_type, &m->error_type))
45045 return;
45046 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45047 struct mirror *m = get_default_mirror(ms);
45048
45049 do {
45050 - if (likely(!atomic_read(&m->error_count)))
45051 + if (likely(!atomic_read_unchecked(&m->error_count)))
45052 return m;
45053
45054 if (m-- == ms->mirror)
45055 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45056 {
45057 struct mirror *default_mirror = get_default_mirror(m->ms);
45058
45059 - return !atomic_read(&default_mirror->error_count);
45060 + return !atomic_read_unchecked(&default_mirror->error_count);
45061 }
45062
45063 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45064 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45065 */
45066 if (likely(region_in_sync(ms, region, 1)))
45067 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45068 - else if (m && atomic_read(&m->error_count))
45069 + else if (m && atomic_read_unchecked(&m->error_count))
45070 m = NULL;
45071
45072 if (likely(m))
45073 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45074 }
45075
45076 ms->mirror[mirror].ms = ms;
45077 - atomic_set(&(ms->mirror[mirror].error_count), 0);
45078 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45079 ms->mirror[mirror].error_type = 0;
45080 ms->mirror[mirror].offset = offset;
45081
45082 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45083 */
45084 static char device_status_char(struct mirror *m)
45085 {
45086 - if (!atomic_read(&(m->error_count)))
45087 + if (!atomic_read_unchecked(&(m->error_count)))
45088 return 'A';
45089
45090 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45091 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45092 index 28a9012..9c0f6a5 100644
45093 --- a/drivers/md/dm-stats.c
45094 +++ b/drivers/md/dm-stats.c
45095 @@ -382,7 +382,7 @@ do_sync_free:
45096 synchronize_rcu_expedited();
45097 dm_stat_free(&s->rcu_head);
45098 } else {
45099 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45100 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45101 call_rcu(&s->rcu_head, dm_stat_free);
45102 }
45103 return 0;
45104 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45105 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45106 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45107 ));
45108 - ACCESS_ONCE(last->last_sector) = end_sector;
45109 - ACCESS_ONCE(last->last_rw) = bi_rw;
45110 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
45111 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45112 }
45113
45114 rcu_read_lock();
45115 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45116 index d1600d2..4c3af3a 100644
45117 --- a/drivers/md/dm-stripe.c
45118 +++ b/drivers/md/dm-stripe.c
45119 @@ -21,7 +21,7 @@ struct stripe {
45120 struct dm_dev *dev;
45121 sector_t physical_start;
45122
45123 - atomic_t error_count;
45124 + atomic_unchecked_t error_count;
45125 };
45126
45127 struct stripe_c {
45128 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
45129 kfree(sc);
45130 return r;
45131 }
45132 - atomic_set(&(sc->stripe[i].error_count), 0);
45133 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
45134 }
45135
45136 ti->private = sc;
45137 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
45138 DMEMIT("%d ", sc->stripes);
45139 for (i = 0; i < sc->stripes; i++) {
45140 DMEMIT("%s ", sc->stripe[i].dev->name);
45141 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
45142 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
45143 'D' : 'A';
45144 }
45145 buffer[i] = '\0';
45146 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
45147 */
45148 for (i = 0; i < sc->stripes; i++)
45149 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
45150 - atomic_inc(&(sc->stripe[i].error_count));
45151 - if (atomic_read(&(sc->stripe[i].error_count)) <
45152 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
45153 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
45154 DM_IO_ERROR_THRESHOLD)
45155 schedule_work(&sc->trigger_event);
45156 }
45157 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
45158 index f9c6cb8..e272df6 100644
45159 --- a/drivers/md/dm-table.c
45160 +++ b/drivers/md/dm-table.c
45161 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
45162 static int open_dev(struct dm_dev_internal *d, dev_t dev,
45163 struct mapped_device *md)
45164 {
45165 - static char *_claim_ptr = "I belong to device-mapper";
45166 + static char _claim_ptr[] = "I belong to device-mapper";
45167 struct block_device *bdev;
45168
45169 int r;
45170 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
45171 if (!dev_size)
45172 return 0;
45173
45174 - if ((start >= dev_size) || (start + len > dev_size)) {
45175 + if ((start >= dev_size) || (len > dev_size - start)) {
45176 DMWARN("%s: %s too small for target: "
45177 "start=%llu, len=%llu, dev_size=%llu",
45178 dm_device_name(ti->table->md), bdevname(bdev, b),
45179 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
45180 index e9d33ad..dae9880d 100644
45181 --- a/drivers/md/dm-thin-metadata.c
45182 +++ b/drivers/md/dm-thin-metadata.c
45183 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45184 {
45185 pmd->info.tm = pmd->tm;
45186 pmd->info.levels = 2;
45187 - pmd->info.value_type.context = pmd->data_sm;
45188 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45189 pmd->info.value_type.size = sizeof(__le64);
45190 pmd->info.value_type.inc = data_block_inc;
45191 pmd->info.value_type.dec = data_block_dec;
45192 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45193
45194 pmd->bl_info.tm = pmd->tm;
45195 pmd->bl_info.levels = 1;
45196 - pmd->bl_info.value_type.context = pmd->data_sm;
45197 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45198 pmd->bl_info.value_type.size = sizeof(__le64);
45199 pmd->bl_info.value_type.inc = data_block_inc;
45200 pmd->bl_info.value_type.dec = data_block_dec;
45201 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
45202 index 32b958d..34011e8 100644
45203 --- a/drivers/md/dm.c
45204 +++ b/drivers/md/dm.c
45205 @@ -180,9 +180,9 @@ struct mapped_device {
45206 /*
45207 * Event handling.
45208 */
45209 - atomic_t event_nr;
45210 + atomic_unchecked_t event_nr;
45211 wait_queue_head_t eventq;
45212 - atomic_t uevent_seq;
45213 + atomic_unchecked_t uevent_seq;
45214 struct list_head uevent_list;
45215 spinlock_t uevent_lock; /* Protect access to uevent_list */
45216
45217 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
45218 spin_lock_init(&md->deferred_lock);
45219 atomic_set(&md->holders, 1);
45220 atomic_set(&md->open_count, 0);
45221 - atomic_set(&md->event_nr, 0);
45222 - atomic_set(&md->uevent_seq, 0);
45223 + atomic_set_unchecked(&md->event_nr, 0);
45224 + atomic_set_unchecked(&md->uevent_seq, 0);
45225 INIT_LIST_HEAD(&md->uevent_list);
45226 spin_lock_init(&md->uevent_lock);
45227
45228 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
45229
45230 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
45231
45232 - atomic_inc(&md->event_nr);
45233 + atomic_inc_unchecked(&md->event_nr);
45234 wake_up(&md->eventq);
45235 }
45236
45237 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
45238
45239 uint32_t dm_next_uevent_seq(struct mapped_device *md)
45240 {
45241 - return atomic_add_return(1, &md->uevent_seq);
45242 + return atomic_add_return_unchecked(1, &md->uevent_seq);
45243 }
45244
45245 uint32_t dm_get_event_nr(struct mapped_device *md)
45246 {
45247 - return atomic_read(&md->event_nr);
45248 + return atomic_read_unchecked(&md->event_nr);
45249 }
45250
45251 int dm_wait_event(struct mapped_device *md, int event_nr)
45252 {
45253 return wait_event_interruptible(md->eventq,
45254 - (event_nr != atomic_read(&md->event_nr)));
45255 + (event_nr != atomic_read_unchecked(&md->event_nr)));
45256 }
45257
45258 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
45259 diff --git a/drivers/md/md.c b/drivers/md/md.c
45260 index b7f603c..723d2bd 100644
45261 --- a/drivers/md/md.c
45262 +++ b/drivers/md/md.c
45263 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
45264 * start build, activate spare
45265 */
45266 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
45267 -static atomic_t md_event_count;
45268 +static atomic_unchecked_t md_event_count;
45269 void md_new_event(struct mddev *mddev)
45270 {
45271 - atomic_inc(&md_event_count);
45272 + atomic_inc_unchecked(&md_event_count);
45273 wake_up(&md_event_waiters);
45274 }
45275 EXPORT_SYMBOL_GPL(md_new_event);
45276 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45277 */
45278 static void md_new_event_inintr(struct mddev *mddev)
45279 {
45280 - atomic_inc(&md_event_count);
45281 + atomic_inc_unchecked(&md_event_count);
45282 wake_up(&md_event_waiters);
45283 }
45284
45285 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45286 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45287 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45288 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45289 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45290 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45291
45292 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45293 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45294 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45295 else
45296 sb->resync_offset = cpu_to_le64(0);
45297
45298 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45299 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45300
45301 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45302 sb->size = cpu_to_le64(mddev->dev_sectors);
45303 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45304 static ssize_t
45305 errors_show(struct md_rdev *rdev, char *page)
45306 {
45307 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45308 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45309 }
45310
45311 static ssize_t
45312 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45313 char *e;
45314 unsigned long n = simple_strtoul(buf, &e, 10);
45315 if (*buf && (*e == 0 || *e == '\n')) {
45316 - atomic_set(&rdev->corrected_errors, n);
45317 + atomic_set_unchecked(&rdev->corrected_errors, n);
45318 return len;
45319 }
45320 return -EINVAL;
45321 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45322 rdev->sb_loaded = 0;
45323 rdev->bb_page = NULL;
45324 atomic_set(&rdev->nr_pending, 0);
45325 - atomic_set(&rdev->read_errors, 0);
45326 - atomic_set(&rdev->corrected_errors, 0);
45327 + atomic_set_unchecked(&rdev->read_errors, 0);
45328 + atomic_set_unchecked(&rdev->corrected_errors, 0);
45329
45330 INIT_LIST_HEAD(&rdev->same_set);
45331 init_waitqueue_head(&rdev->blocked_wait);
45332 @@ -7072,7 +7072,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45333
45334 spin_unlock(&pers_lock);
45335 seq_printf(seq, "\n");
45336 - seq->poll_event = atomic_read(&md_event_count);
45337 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45338 return 0;
45339 }
45340 if (v == (void*)2) {
45341 @@ -7175,7 +7175,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45342 return error;
45343
45344 seq = file->private_data;
45345 - seq->poll_event = atomic_read(&md_event_count);
45346 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45347 return error;
45348 }
45349
45350 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45351 /* always allow read */
45352 mask = POLLIN | POLLRDNORM;
45353
45354 - if (seq->poll_event != atomic_read(&md_event_count))
45355 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45356 mask |= POLLERR | POLLPRI;
45357 return mask;
45358 }
45359 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45360 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45361 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45362 (int)part_stat_read(&disk->part0, sectors[1]) -
45363 - atomic_read(&disk->sync_io);
45364 + atomic_read_unchecked(&disk->sync_io);
45365 /* sync IO will cause sync_io to increase before the disk_stats
45366 * as sync_io is counted when a request starts, and
45367 * disk_stats is counted when it completes.
45368 diff --git a/drivers/md/md.h b/drivers/md/md.h
45369 index a49d991..3582bb7 100644
45370 --- a/drivers/md/md.h
45371 +++ b/drivers/md/md.h
45372 @@ -94,13 +94,13 @@ struct md_rdev {
45373 * only maintained for arrays that
45374 * support hot removal
45375 */
45376 - atomic_t read_errors; /* number of consecutive read errors that
45377 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
45378 * we have tried to ignore.
45379 */
45380 struct timespec last_read_error; /* monotonic time since our
45381 * last read error
45382 */
45383 - atomic_t corrected_errors; /* number of corrected read errors,
45384 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45385 * for reporting to userspace and storing
45386 * in superblock.
45387 */
45388 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45389
45390 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45391 {
45392 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45393 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45394 }
45395
45396 struct md_personality
45397 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45398 index 786b689..ea8c956 100644
45399 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
45400 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45401 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45402 * Flick into a mode where all blocks get allocated in the new area.
45403 */
45404 smm->begin = old_len;
45405 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
45406 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45407
45408 /*
45409 * Extend.
45410 @@ -710,7 +710,7 @@ out:
45411 /*
45412 * Switch back to normal behaviour.
45413 */
45414 - memcpy(sm, &ops, sizeof(*sm));
45415 + memcpy((void *)sm, &ops, sizeof(*sm));
45416 return r;
45417 }
45418
45419 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45420 index 3e6d115..ffecdeb 100644
45421 --- a/drivers/md/persistent-data/dm-space-map.h
45422 +++ b/drivers/md/persistent-data/dm-space-map.h
45423 @@ -71,6 +71,7 @@ struct dm_space_map {
45424 dm_sm_threshold_fn fn,
45425 void *context);
45426 };
45427 +typedef struct dm_space_map __no_const dm_space_map_no_const;
45428
45429 /*----------------------------------------------------------------*/
45430
45431 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45432 index 55de4f6..b1c57fe 100644
45433 --- a/drivers/md/raid1.c
45434 +++ b/drivers/md/raid1.c
45435 @@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45436 if (r1_sync_page_io(rdev, sect, s,
45437 bio->bi_io_vec[idx].bv_page,
45438 READ) != 0)
45439 - atomic_add(s, &rdev->corrected_errors);
45440 + atomic_add_unchecked(s, &rdev->corrected_errors);
45441 }
45442 sectors -= s;
45443 sect += s;
45444 @@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45445 !test_bit(Faulty, &rdev->flags)) {
45446 if (r1_sync_page_io(rdev, sect, s,
45447 conf->tmppage, READ)) {
45448 - atomic_add(s, &rdev->corrected_errors);
45449 + atomic_add_unchecked(s, &rdev->corrected_errors);
45450 printk(KERN_INFO
45451 "md/raid1:%s: read error corrected "
45452 "(%d sectors at %llu on %s)\n",
45453 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45454 index 6703751..187af1e 100644
45455 --- a/drivers/md/raid10.c
45456 +++ b/drivers/md/raid10.c
45457 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45458 /* The write handler will notice the lack of
45459 * R10BIO_Uptodate and record any errors etc
45460 */
45461 - atomic_add(r10_bio->sectors,
45462 + atomic_add_unchecked(r10_bio->sectors,
45463 &conf->mirrors[d].rdev->corrected_errors);
45464
45465 /* for reconstruct, we always reschedule after a read.
45466 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45467 {
45468 struct timespec cur_time_mon;
45469 unsigned long hours_since_last;
45470 - unsigned int read_errors = atomic_read(&rdev->read_errors);
45471 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45472
45473 ktime_get_ts(&cur_time_mon);
45474
45475 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45476 * overflowing the shift of read_errors by hours_since_last.
45477 */
45478 if (hours_since_last >= 8 * sizeof(read_errors))
45479 - atomic_set(&rdev->read_errors, 0);
45480 + atomic_set_unchecked(&rdev->read_errors, 0);
45481 else
45482 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45483 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45484 }
45485
45486 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45487 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45488 return;
45489
45490 check_decay_read_errors(mddev, rdev);
45491 - atomic_inc(&rdev->read_errors);
45492 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
45493 + atomic_inc_unchecked(&rdev->read_errors);
45494 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
45495 char b[BDEVNAME_SIZE];
45496 bdevname(rdev->bdev, b);
45497
45498 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45499 "md/raid10:%s: %s: Raid device exceeded "
45500 "read_error threshold [cur %d:max %d]\n",
45501 mdname(mddev), b,
45502 - atomic_read(&rdev->read_errors), max_read_errors);
45503 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
45504 printk(KERN_NOTICE
45505 "md/raid10:%s: %s: Failing raid device\n",
45506 mdname(mddev), b);
45507 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45508 sect +
45509 choose_data_offset(r10_bio, rdev)),
45510 bdevname(rdev->bdev, b));
45511 - atomic_add(s, &rdev->corrected_errors);
45512 + atomic_add_unchecked(s, &rdev->corrected_errors);
45513 }
45514
45515 rdev_dec_pending(rdev, mddev);
45516 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45517 index 9f0fbec..991e7a1 100644
45518 --- a/drivers/md/raid5.c
45519 +++ b/drivers/md/raid5.c
45520 @@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45521 return 1;
45522 }
45523
45524 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45525 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45526 +#endif
45527 +
45528 static int grow_stripes(struct r5conf *conf, int num)
45529 {
45530 struct kmem_cache *sc;
45531 @@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45532 "raid%d-%s", conf->level, mdname(conf->mddev));
45533 else
45534 sprintf(conf->cache_name[0],
45535 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45536 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45537 +#else
45538 "raid%d-%p", conf->level, conf->mddev);
45539 +#endif
45540 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45541
45542 conf->active_name = 0;
45543 @@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45544 mdname(conf->mddev), STRIPE_SECTORS,
45545 (unsigned long long)s,
45546 bdevname(rdev->bdev, b));
45547 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45548 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45549 clear_bit(R5_ReadError, &sh->dev[i].flags);
45550 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45551 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45552 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45553
45554 - if (atomic_read(&rdev->read_errors))
45555 - atomic_set(&rdev->read_errors, 0);
45556 + if (atomic_read_unchecked(&rdev->read_errors))
45557 + atomic_set_unchecked(&rdev->read_errors, 0);
45558 } else {
45559 const char *bdn = bdevname(rdev->bdev, b);
45560 int retry = 0;
45561 int set_bad = 0;
45562
45563 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45564 - atomic_inc(&rdev->read_errors);
45565 + atomic_inc_unchecked(&rdev->read_errors);
45566 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45567 printk_ratelimited(
45568 KERN_WARNING
45569 @@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45570 mdname(conf->mddev),
45571 (unsigned long long)s,
45572 bdn);
45573 - } else if (atomic_read(&rdev->read_errors)
45574 + } else if (atomic_read_unchecked(&rdev->read_errors)
45575 > conf->max_nr_stripes)
45576 printk(KERN_WARNING
45577 "md/raid:%s: Too many read errors, failing device %s.\n",
45578 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45579 index 983db75..ef9248c 100644
45580 --- a/drivers/media/dvb-core/dvbdev.c
45581 +++ b/drivers/media/dvb-core/dvbdev.c
45582 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45583 const struct dvb_device *template, void *priv, int type)
45584 {
45585 struct dvb_device *dvbdev;
45586 - struct file_operations *dvbdevfops;
45587 + file_operations_no_const *dvbdevfops;
45588 struct device *clsdev;
45589 int minor;
45590 int id;
45591 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45592 index 539f4db..cdd403b 100644
45593 --- a/drivers/media/dvb-frontends/af9033.h
45594 +++ b/drivers/media/dvb-frontends/af9033.h
45595 @@ -82,7 +82,7 @@ struct af9033_ops {
45596 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45597 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45598 int onoff);
45599 -};
45600 +} __no_const;
45601
45602
45603 #if IS_ENABLED(CONFIG_DVB_AF9033)
45604 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45605 index 9b6c3bb..baeb5c7 100644
45606 --- a/drivers/media/dvb-frontends/dib3000.h
45607 +++ b/drivers/media/dvb-frontends/dib3000.h
45608 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45609 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45610 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45611 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45612 -};
45613 +} __no_const;
45614
45615 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45616 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45617 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45618 index 1fea0e9..321ce8f 100644
45619 --- a/drivers/media/dvb-frontends/dib7000p.h
45620 +++ b/drivers/media/dvb-frontends/dib7000p.h
45621 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45622 int (*get_adc_power)(struct dvb_frontend *fe);
45623 int (*slave_reset)(struct dvb_frontend *fe);
45624 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45625 -};
45626 +} __no_const;
45627
45628 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45629 void *dib7000p_attach(struct dib7000p_ops *ops);
45630 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45631 index 84cc103..5780c54 100644
45632 --- a/drivers/media/dvb-frontends/dib8000.h
45633 +++ b/drivers/media/dvb-frontends/dib8000.h
45634 @@ -61,7 +61,7 @@ struct dib8000_ops {
45635 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45636 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45637 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45638 -};
45639 +} __no_const;
45640
45641 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45642 void *dib8000_attach(struct dib8000_ops *ops);
45643 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45644 index ed8cb90..5ef7f79 100644
45645 --- a/drivers/media/pci/cx88/cx88-video.c
45646 +++ b/drivers/media/pci/cx88/cx88-video.c
45647 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45648
45649 /* ------------------------------------------------------------------ */
45650
45651 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45652 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45653 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45654 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45655 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45656 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45657
45658 module_param_array(video_nr, int, NULL, 0444);
45659 module_param_array(vbi_nr, int, NULL, 0444);
45660 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45661 index 802642d..5534900 100644
45662 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45663 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45664 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45665 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45666
45667 /* ivtv instance counter */
45668 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45669 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45670
45671 /* Parameter declarations */
45672 static int cardtype[IVTV_MAX_CARDS];
45673 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45674 index 172583d..0f806f4 100644
45675 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45676 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45677 @@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
45678
45679 static int solo_sysfs_init(struct solo_dev *solo_dev)
45680 {
45681 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45682 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45683 struct device *dev = &solo_dev->dev;
45684 const char *driver;
45685 int i;
45686 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45687 index c7141f2..5301fec 100644
45688 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45689 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45690 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45691
45692 int solo_g723_init(struct solo_dev *solo_dev)
45693 {
45694 - static struct snd_device_ops ops = { NULL };
45695 + static struct snd_device_ops ops = { };
45696 struct snd_card *card;
45697 struct snd_kcontrol_new kctl;
45698 char name[32];
45699 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45700 index 8c84846..27b4f83 100644
45701 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45702 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45703 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45704
45705 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45706 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45707 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45708 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45709 if (p2m_id < 0)
45710 p2m_id = -p2m_id;
45711 }
45712 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45713 index c6154b0..73e4ae9 100644
45714 --- a/drivers/media/pci/solo6x10/solo6x10.h
45715 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45716 @@ -219,7 +219,7 @@ struct solo_dev {
45717
45718 /* P2M DMA Engine */
45719 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45720 - atomic_t p2m_count;
45721 + atomic_unchecked_t p2m_count;
45722 int p2m_jiffies;
45723 unsigned int p2m_timeouts;
45724
45725 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45726 index 2d177fa..5b925a1 100644
45727 --- a/drivers/media/platform/omap/omap_vout.c
45728 +++ b/drivers/media/platform/omap/omap_vout.c
45729 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45730 OMAP_VIDEO2,
45731 };
45732
45733 -static struct videobuf_queue_ops video_vbq_ops;
45734 /* Variables configurable through module params*/
45735 static u32 video1_numbuffers = 3;
45736 static u32 video2_numbuffers = 3;
45737 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
45738 {
45739 struct videobuf_queue *q;
45740 struct omap_vout_device *vout = NULL;
45741 + static struct videobuf_queue_ops video_vbq_ops = {
45742 + .buf_setup = omap_vout_buffer_setup,
45743 + .buf_prepare = omap_vout_buffer_prepare,
45744 + .buf_release = omap_vout_buffer_release,
45745 + .buf_queue = omap_vout_buffer_queue,
45746 + };
45747
45748 vout = video_drvdata(file);
45749 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45750 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
45751 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45752
45753 q = &vout->vbq;
45754 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45755 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45756 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45757 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45758 spin_lock_init(&vout->vbq_lock);
45759
45760 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45761 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45762 index fb2acc5..a2fcbdc4 100644
45763 --- a/drivers/media/platform/s5p-tv/mixer.h
45764 +++ b/drivers/media/platform/s5p-tv/mixer.h
45765 @@ -156,7 +156,7 @@ struct mxr_layer {
45766 /** layer index (unique identifier) */
45767 int idx;
45768 /** callbacks for layer methods */
45769 - struct mxr_layer_ops ops;
45770 + struct mxr_layer_ops *ops;
45771 /** format array */
45772 const struct mxr_format **fmt_array;
45773 /** size of format array */
45774 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45775 index 74344c7..a39e70e 100644
45776 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45777 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45778 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45779 {
45780 struct mxr_layer *layer;
45781 int ret;
45782 - struct mxr_layer_ops ops = {
45783 + static struct mxr_layer_ops ops = {
45784 .release = mxr_graph_layer_release,
45785 .buffer_set = mxr_graph_buffer_set,
45786 .stream_set = mxr_graph_stream_set,
45787 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45788 index b713403..53cb5ad 100644
45789 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45790 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45791 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45792 layer->update_buf = next;
45793 }
45794
45795 - layer->ops.buffer_set(layer, layer->update_buf);
45796 + layer->ops->buffer_set(layer, layer->update_buf);
45797
45798 if (done && done != layer->shadow_buf)
45799 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45800 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45801 index b4d2696..91df48e 100644
45802 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45803 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45804 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45805 layer->geo.src.height = layer->geo.src.full_height;
45806
45807 mxr_geometry_dump(mdev, &layer->geo);
45808 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45809 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45810 mxr_geometry_dump(mdev, &layer->geo);
45811 }
45812
45813 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45814 layer->geo.dst.full_width = mbus_fmt.width;
45815 layer->geo.dst.full_height = mbus_fmt.height;
45816 layer->geo.dst.field = mbus_fmt.field;
45817 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45818 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45819
45820 mxr_geometry_dump(mdev, &layer->geo);
45821 }
45822 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45823 /* set source size to highest accepted value */
45824 geo->src.full_width = max(geo->dst.full_width, pix->width);
45825 geo->src.full_height = max(geo->dst.full_height, pix->height);
45826 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45827 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45828 mxr_geometry_dump(mdev, &layer->geo);
45829 /* set cropping to total visible screen */
45830 geo->src.width = pix->width;
45831 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45832 geo->src.x_offset = 0;
45833 geo->src.y_offset = 0;
45834 /* assure consistency of geometry */
45835 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45836 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45837 mxr_geometry_dump(mdev, &layer->geo);
45838 /* set full size to lowest possible value */
45839 geo->src.full_width = 0;
45840 geo->src.full_height = 0;
45841 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45842 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45843 mxr_geometry_dump(mdev, &layer->geo);
45844
45845 /* returning results */
45846 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45847 target->width = s->r.width;
45848 target->height = s->r.height;
45849
45850 - layer->ops.fix_geometry(layer, stage, s->flags);
45851 + layer->ops->fix_geometry(layer, stage, s->flags);
45852
45853 /* retrieve update selection rectangle */
45854 res.left = target->x_offset;
45855 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45856 mxr_output_get(mdev);
45857
45858 mxr_layer_update_output(layer);
45859 - layer->ops.format_set(layer);
45860 + layer->ops->format_set(layer);
45861 /* enabling layer in hardware */
45862 spin_lock_irqsave(&layer->enq_slock, flags);
45863 layer->state = MXR_LAYER_STREAMING;
45864 spin_unlock_irqrestore(&layer->enq_slock, flags);
45865
45866 - layer->ops.stream_set(layer, MXR_ENABLE);
45867 + layer->ops->stream_set(layer, MXR_ENABLE);
45868 mxr_streamer_get(mdev);
45869
45870 return 0;
45871 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45872 spin_unlock_irqrestore(&layer->enq_slock, flags);
45873
45874 /* disabling layer in hardware */
45875 - layer->ops.stream_set(layer, MXR_DISABLE);
45876 + layer->ops->stream_set(layer, MXR_DISABLE);
45877 /* remove one streamer */
45878 mxr_streamer_put(mdev);
45879 /* allow changes in output configuration */
45880 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45881
45882 void mxr_layer_release(struct mxr_layer *layer)
45883 {
45884 - if (layer->ops.release)
45885 - layer->ops.release(layer);
45886 + if (layer->ops->release)
45887 + layer->ops->release(layer);
45888 }
45889
45890 void mxr_base_layer_release(struct mxr_layer *layer)
45891 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45892
45893 layer->mdev = mdev;
45894 layer->idx = idx;
45895 - layer->ops = *ops;
45896 + layer->ops = ops;
45897
45898 spin_lock_init(&layer->enq_slock);
45899 INIT_LIST_HEAD(&layer->enq_list);
45900 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45901 index c9388c4..ce71ece 100644
45902 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45903 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45904 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45905 {
45906 struct mxr_layer *layer;
45907 int ret;
45908 - struct mxr_layer_ops ops = {
45909 + static struct mxr_layer_ops ops = {
45910 .release = mxr_vp_layer_release,
45911 .buffer_set = mxr_vp_buffer_set,
45912 .stream_set = mxr_vp_stream_set,
45913 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45914 index 8033371..de5bca0 100644
45915 --- a/drivers/media/platform/vivi.c
45916 +++ b/drivers/media/platform/vivi.c
45917 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45918 MODULE_LICENSE("Dual BSD/GPL");
45919 MODULE_VERSION(VIVI_VERSION);
45920
45921 -static unsigned video_nr = -1;
45922 -module_param(video_nr, uint, 0644);
45923 +static int video_nr = -1;
45924 +module_param(video_nr, int, 0644);
45925 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45926
45927 static unsigned n_devs = 1;
45928 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45929 index 82affae..42833ec 100644
45930 --- a/drivers/media/radio/radio-cadet.c
45931 +++ b/drivers/media/radio/radio-cadet.c
45932 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45933 unsigned char readbuf[RDS_BUFFER];
45934 int i = 0;
45935
45936 + if (count > RDS_BUFFER)
45937 + return -EFAULT;
45938 mutex_lock(&dev->lock);
45939 if (dev->rdsstat == 0)
45940 cadet_start_rds(dev);
45941 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45942 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45943 mutex_unlock(&dev->lock);
45944
45945 - if (i && copy_to_user(data, readbuf, i))
45946 - return -EFAULT;
45947 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45948 + i = -EFAULT;
45949 +
45950 return i;
45951 }
45952
45953 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45954 index 5236035..c622c74 100644
45955 --- a/drivers/media/radio/radio-maxiradio.c
45956 +++ b/drivers/media/radio/radio-maxiradio.c
45957 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45958 /* TEA5757 pin mappings */
45959 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45960
45961 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45962 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45963
45964 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45965 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45966 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45967 index 050b3bb..79f62b9 100644
45968 --- a/drivers/media/radio/radio-shark.c
45969 +++ b/drivers/media/radio/radio-shark.c
45970 @@ -79,7 +79,7 @@ struct shark_device {
45971 u32 last_val;
45972 };
45973
45974 -static atomic_t shark_instance = ATOMIC_INIT(0);
45975 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45976
45977 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45978 {
45979 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45980 index 8654e0d..0608a64 100644
45981 --- a/drivers/media/radio/radio-shark2.c
45982 +++ b/drivers/media/radio/radio-shark2.c
45983 @@ -74,7 +74,7 @@ struct shark_device {
45984 u8 *transfer_buffer;
45985 };
45986
45987 -static atomic_t shark_instance = ATOMIC_INIT(0);
45988 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45989
45990 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45991 {
45992 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45993 index 633022b..7f10754 100644
45994 --- a/drivers/media/radio/radio-si476x.c
45995 +++ b/drivers/media/radio/radio-si476x.c
45996 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45997 struct si476x_radio *radio;
45998 struct v4l2_ctrl *ctrl;
45999
46000 - static atomic_t instance = ATOMIC_INIT(0);
46001 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
46002
46003 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46004 if (!radio)
46005 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46006 index 9fd1527..8927230 100644
46007 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
46008 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46009 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
46010
46011 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
46012 {
46013 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
46014 - char result[64];
46015 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
46016 - sizeof(result), 0);
46017 + char *buf;
46018 + char *result;
46019 + int retval;
46020 +
46021 + buf = kmalloc(2, GFP_KERNEL);
46022 + if (buf == NULL)
46023 + return -ENOMEM;
46024 + result = kmalloc(64, GFP_KERNEL);
46025 + if (result == NULL) {
46026 + kfree(buf);
46027 + return -ENOMEM;
46028 + }
46029 +
46030 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
46031 + buf[1] = enable ? 1 : 0;
46032 +
46033 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
46034 +
46035 + kfree(buf);
46036 + kfree(result);
46037 + return retval;
46038 }
46039
46040 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
46041 {
46042 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
46043 - char state[3];
46044 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
46045 + char *buf;
46046 + char *state;
46047 + int retval;
46048 +
46049 + buf = kmalloc(2, GFP_KERNEL);
46050 + if (buf == NULL)
46051 + return -ENOMEM;
46052 + state = kmalloc(3, GFP_KERNEL);
46053 + if (state == NULL) {
46054 + kfree(buf);
46055 + return -ENOMEM;
46056 + }
46057 +
46058 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
46059 + buf[1] = enable ? 1 : 0;
46060 +
46061 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
46062 +
46063 + kfree(buf);
46064 + kfree(state);
46065 + return retval;
46066 }
46067
46068 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46069 {
46070 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
46071 - char state[3];
46072 + char *query;
46073 + char *state;
46074 int ret;
46075 + query = kmalloc(1, GFP_KERNEL);
46076 + if (query == NULL)
46077 + return -ENOMEM;
46078 + state = kmalloc(3, GFP_KERNEL);
46079 + if (state == NULL) {
46080 + kfree(query);
46081 + return -ENOMEM;
46082 + }
46083 +
46084 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
46085
46086 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
46087
46088 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
46089 - sizeof(state), 0);
46090 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
46091 if (ret < 0) {
46092 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
46093 "state info\n");
46094 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46095
46096 /* Copy this pointer as we are gonna need it in the release phase */
46097 cinergyt2_usb_device = adap->dev;
46098 -
46099 + kfree(query);
46100 + kfree(state);
46101 return 0;
46102 }
46103
46104 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
46105 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46106 {
46107 struct cinergyt2_state *st = d->priv;
46108 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
46109 + u8 *key, *cmd;
46110 int i;
46111
46112 + cmd = kmalloc(1, GFP_KERNEL);
46113 + if (cmd == NULL)
46114 + return -EINVAL;
46115 + key = kzalloc(5, GFP_KERNEL);
46116 + if (key == NULL) {
46117 + kfree(cmd);
46118 + return -EINVAL;
46119 + }
46120 +
46121 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
46122 +
46123 *state = REMOTE_NO_KEY_PRESSED;
46124
46125 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
46126 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
46127 if (key[4] == 0xff) {
46128 /* key repeat */
46129 st->rc_counter++;
46130 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46131 *event = d->last_event;
46132 deb_rc("repeat key, event %x\n",
46133 *event);
46134 - return 0;
46135 + goto out;
46136 }
46137 }
46138 deb_rc("repeated key (non repeatable)\n");
46139 }
46140 - return 0;
46141 + goto out;
46142 }
46143
46144 /* hack to pass checksum on the custom field */
46145 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46146
46147 deb_rc("key: %*ph\n", 5, key);
46148 }
46149 +out:
46150 + kfree(cmd);
46151 + kfree(key);
46152 return 0;
46153 }
46154
46155 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46156 index c890fe4..f9b2ae6 100644
46157 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46158 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46159 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
46160 fe_status_t *status)
46161 {
46162 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46163 - struct dvbt_get_status_msg result;
46164 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46165 + struct dvbt_get_status_msg *result;
46166 + u8 *cmd;
46167 int ret;
46168
46169 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
46170 - sizeof(result), 0);
46171 + cmd = kmalloc(1, GFP_KERNEL);
46172 + if (cmd == NULL)
46173 + return -ENOMEM;
46174 + result = kmalloc(sizeof(*result), GFP_KERNEL);
46175 + if (result == NULL) {
46176 + kfree(cmd);
46177 + return -ENOMEM;
46178 + }
46179 +
46180 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46181 +
46182 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
46183 + sizeof(*result), 0);
46184 if (ret < 0)
46185 - return ret;
46186 + goto out;
46187
46188 *status = 0;
46189
46190 - if (0xffff - le16_to_cpu(result.gain) > 30)
46191 + if (0xffff - le16_to_cpu(result->gain) > 30)
46192 *status |= FE_HAS_SIGNAL;
46193 - if (result.lock_bits & (1 << 6))
46194 + if (result->lock_bits & (1 << 6))
46195 *status |= FE_HAS_LOCK;
46196 - if (result.lock_bits & (1 << 5))
46197 + if (result->lock_bits & (1 << 5))
46198 *status |= FE_HAS_SYNC;
46199 - if (result.lock_bits & (1 << 4))
46200 + if (result->lock_bits & (1 << 4))
46201 *status |= FE_HAS_CARRIER;
46202 - if (result.lock_bits & (1 << 1))
46203 + if (result->lock_bits & (1 << 1))
46204 *status |= FE_HAS_VITERBI;
46205
46206 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
46207 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
46208 *status &= ~FE_HAS_LOCK;
46209
46210 - return 0;
46211 +out:
46212 + kfree(cmd);
46213 + kfree(result);
46214 + return ret;
46215 }
46216
46217 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
46218 {
46219 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46220 - struct dvbt_get_status_msg status;
46221 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46222 + struct dvbt_get_status_msg *status;
46223 + char *cmd;
46224 int ret;
46225
46226 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46227 - sizeof(status), 0);
46228 + cmd = kmalloc(1, GFP_KERNEL);
46229 + if (cmd == NULL)
46230 + return -ENOMEM;
46231 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46232 + if (status == NULL) {
46233 + kfree(cmd);
46234 + return -ENOMEM;
46235 + }
46236 +
46237 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46238 +
46239 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46240 + sizeof(*status), 0);
46241 if (ret < 0)
46242 - return ret;
46243 + goto out;
46244
46245 - *ber = le32_to_cpu(status.viterbi_error_rate);
46246 + *ber = le32_to_cpu(status->viterbi_error_rate);
46247 +out:
46248 + kfree(cmd);
46249 + kfree(status);
46250 return 0;
46251 }
46252
46253 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
46254 {
46255 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46256 - struct dvbt_get_status_msg status;
46257 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46258 + struct dvbt_get_status_msg *status;
46259 + u8 *cmd;
46260 int ret;
46261
46262 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
46263 - sizeof(status), 0);
46264 + cmd = kmalloc(1, GFP_KERNEL);
46265 + if (cmd == NULL)
46266 + return -ENOMEM;
46267 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46268 + if (status == NULL) {
46269 + kfree(cmd);
46270 + return -ENOMEM;
46271 + }
46272 +
46273 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46274 +
46275 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46276 + sizeof(*status), 0);
46277 if (ret < 0) {
46278 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46279 ret);
46280 - return ret;
46281 + goto out;
46282 }
46283 - *unc = le32_to_cpu(status.uncorrected_block_count);
46284 - return 0;
46285 + *unc = le32_to_cpu(status->uncorrected_block_count);
46286 +
46287 +out:
46288 + kfree(cmd);
46289 + kfree(status);
46290 + return ret;
46291 }
46292
46293 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46294 u16 *strength)
46295 {
46296 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46297 - struct dvbt_get_status_msg status;
46298 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46299 + struct dvbt_get_status_msg *status;
46300 + char *cmd;
46301 int ret;
46302
46303 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46304 - sizeof(status), 0);
46305 + cmd = kmalloc(1, GFP_KERNEL);
46306 + if (cmd == NULL)
46307 + return -ENOMEM;
46308 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46309 + if (status == NULL) {
46310 + kfree(cmd);
46311 + return -ENOMEM;
46312 + }
46313 +
46314 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46315 +
46316 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46317 + sizeof(*status), 0);
46318 if (ret < 0) {
46319 err("cinergyt2_fe_read_signal_strength() Failed!"
46320 " (Error=%d)\n", ret);
46321 - return ret;
46322 + goto out;
46323 }
46324 - *strength = (0xffff - le16_to_cpu(status.gain));
46325 + *strength = (0xffff - le16_to_cpu(status->gain));
46326 +
46327 +out:
46328 + kfree(cmd);
46329 + kfree(status);
46330 return 0;
46331 }
46332
46333 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46334 {
46335 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46336 - struct dvbt_get_status_msg status;
46337 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46338 + struct dvbt_get_status_msg *status;
46339 + char *cmd;
46340 int ret;
46341
46342 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46343 - sizeof(status), 0);
46344 + cmd = kmalloc(1, GFP_KERNEL);
46345 + if (cmd == NULL)
46346 + return -ENOMEM;
46347 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46348 + if (status == NULL) {
46349 + kfree(cmd);
46350 + return -ENOMEM;
46351 + }
46352 +
46353 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46354 +
46355 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46356 + sizeof(*status), 0);
46357 if (ret < 0) {
46358 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46359 - return ret;
46360 + goto out;
46361 }
46362 - *snr = (status.snr << 8) | status.snr;
46363 - return 0;
46364 + *snr = (status->snr << 8) | status->snr;
46365 +
46366 +out:
46367 + kfree(cmd);
46368 + kfree(status);
46369 + return ret;
46370 }
46371
46372 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46373 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46374 {
46375 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46376 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46377 - struct dvbt_set_parameters_msg param;
46378 - char result[2];
46379 + struct dvbt_set_parameters_msg *param;
46380 + char *result;
46381 int err;
46382
46383 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46384 - param.tps = cpu_to_le16(compute_tps(fep));
46385 - param.freq = cpu_to_le32(fep->frequency / 1000);
46386 - param.flags = 0;
46387 + result = kmalloc(2, GFP_KERNEL);
46388 + if (result == NULL)
46389 + return -ENOMEM;
46390 + param = kmalloc(sizeof(*param), GFP_KERNEL);
46391 + if (param == NULL) {
46392 + kfree(result);
46393 + return -ENOMEM;
46394 + }
46395 +
46396 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46397 + param->tps = cpu_to_le16(compute_tps(fep));
46398 + param->freq = cpu_to_le32(fep->frequency / 1000);
46399 + param->flags = 0;
46400
46401 switch (fep->bandwidth_hz) {
46402 default:
46403 case 8000000:
46404 - param.bandwidth = 8;
46405 + param->bandwidth = 8;
46406 break;
46407 case 7000000:
46408 - param.bandwidth = 7;
46409 + param->bandwidth = 7;
46410 break;
46411 case 6000000:
46412 - param.bandwidth = 6;
46413 + param->bandwidth = 6;
46414 break;
46415 }
46416
46417 err = dvb_usb_generic_rw(state->d,
46418 - (char *)&param, sizeof(param),
46419 - result, sizeof(result), 0);
46420 + (char *)param, sizeof(*param),
46421 + result, 2, 0);
46422 if (err < 0)
46423 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46424
46425 - return (err < 0) ? err : 0;
46426 + kfree(result);
46427 + kfree(param);
46428 + return err;
46429 }
46430
46431 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46432 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46433 index 733a7ff..f8b52e3 100644
46434 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46435 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46436 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46437
46438 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46439 {
46440 - struct hexline hx;
46441 - u8 reset;
46442 + struct hexline *hx;
46443 + u8 *reset;
46444 int ret,pos=0;
46445
46446 + reset = kmalloc(1, GFP_KERNEL);
46447 + if (reset == NULL)
46448 + return -ENOMEM;
46449 +
46450 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46451 + if (hx == NULL) {
46452 + kfree(reset);
46453 + return -ENOMEM;
46454 + }
46455 +
46456 /* stop the CPU */
46457 - reset = 1;
46458 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46459 + reset[0] = 1;
46460 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46461 err("could not stop the USB controller CPU.");
46462
46463 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46464 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46465 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46466 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46467 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46468 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46469
46470 - if (ret != hx.len) {
46471 + if (ret != hx->len) {
46472 err("error while transferring firmware "
46473 "(transferred size: %d, block size: %d)",
46474 - ret,hx.len);
46475 + ret,hx->len);
46476 ret = -EINVAL;
46477 break;
46478 }
46479 }
46480 if (ret < 0) {
46481 err("firmware download failed at %d with %d",pos,ret);
46482 + kfree(reset);
46483 + kfree(hx);
46484 return ret;
46485 }
46486
46487 if (ret == 0) {
46488 /* restart the CPU */
46489 - reset = 0;
46490 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46491 + reset[0] = 0;
46492 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46493 err("could not restart the USB controller CPU.");
46494 ret = -EINVAL;
46495 }
46496 } else
46497 ret = -EIO;
46498
46499 + kfree(reset);
46500 + kfree(hx);
46501 +
46502 return ret;
46503 }
46504 EXPORT_SYMBOL(usb_cypress_load_firmware);
46505 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46506 index 2add8c5..c33b854 100644
46507 --- a/drivers/media/usb/dvb-usb/dw2102.c
46508 +++ b/drivers/media/usb/dvb-usb/dw2102.c
46509 @@ -118,7 +118,7 @@ struct su3000_state {
46510
46511 struct s6x0_state {
46512 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46513 -};
46514 +} __no_const;
46515
46516 /* debug */
46517 static int dvb_usb_dw2102_debug;
46518 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46519 index 6b0b8b6b..4038398 100644
46520 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46521 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46522 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46523 static int technisat_usb2_i2c_access(struct usb_device *udev,
46524 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46525 {
46526 - u8 b[64];
46527 - int ret, actual_length;
46528 + u8 *b = kmalloc(64, GFP_KERNEL);
46529 + int ret, actual_length, error = 0;
46530 +
46531 + if (b == NULL)
46532 + return -ENOMEM;
46533
46534 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46535 debug_dump(tx, txlen, deb_i2c);
46536 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46537
46538 if (ret < 0) {
46539 err("i2c-error: out failed %02x = %d", device_addr, ret);
46540 - return -ENODEV;
46541 + error = -ENODEV;
46542 + goto out;
46543 }
46544
46545 ret = usb_bulk_msg(udev,
46546 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46547 b, 64, &actual_length, 1000);
46548 if (ret < 0) {
46549 err("i2c-error: in failed %02x = %d", device_addr, ret);
46550 - return -ENODEV;
46551 + error = -ENODEV;
46552 + goto out;
46553 }
46554
46555 if (b[0] != I2C_STATUS_OK) {
46556 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46557 /* handle tuner-i2c-nak */
46558 if (!(b[0] == I2C_STATUS_NAK &&
46559 device_addr == 0x60
46560 - /* && device_is_technisat_usb2 */))
46561 - return -ENODEV;
46562 + /* && device_is_technisat_usb2 */)) {
46563 + error = -ENODEV;
46564 + goto out;
46565 + }
46566 }
46567
46568 deb_i2c("status: %d, ", b[0]);
46569 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46570
46571 deb_i2c("\n");
46572
46573 - return 0;
46574 +out:
46575 + kfree(b);
46576 + return error;
46577 }
46578
46579 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46580 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46581 {
46582 int ret;
46583
46584 - u8 led[8] = {
46585 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46586 - 0
46587 - };
46588 + u8 *led = kzalloc(8, GFP_KERNEL);
46589 +
46590 + if (led == NULL)
46591 + return -ENOMEM;
46592
46593 if (disable_led_control && state != TECH_LED_OFF)
46594 return 0;
46595
46596 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46597 +
46598 switch (state) {
46599 case TECH_LED_ON:
46600 led[1] = 0x82;
46601 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46602 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46603 USB_TYPE_VENDOR | USB_DIR_OUT,
46604 0, 0,
46605 - led, sizeof(led), 500);
46606 + led, 8, 500);
46607
46608 mutex_unlock(&d->i2c_mutex);
46609 +
46610 + kfree(led);
46611 +
46612 return ret;
46613 }
46614
46615 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46616 {
46617 int ret;
46618 - u8 b = 0;
46619 + u8 *b = kzalloc(1, GFP_KERNEL);
46620 +
46621 + if (b == NULL)
46622 + return -ENOMEM;
46623
46624 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46625 return -EAGAIN;
46626 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46627 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46628 USB_TYPE_VENDOR | USB_DIR_OUT,
46629 (red << 8) | green, 0,
46630 - &b, 1, 500);
46631 + b, 1, 500);
46632
46633 mutex_unlock(&d->i2c_mutex);
46634
46635 + kfree(b);
46636 +
46637 return ret;
46638 }
46639
46640 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46641 struct dvb_usb_device_description **desc, int *cold)
46642 {
46643 int ret;
46644 - u8 version[3];
46645 + u8 *version = kmalloc(3, GFP_KERNEL);
46646
46647 /* first select the interface */
46648 if (usb_set_interface(udev, 0, 1) != 0)
46649 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46650
46651 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46652
46653 + if (version == NULL)
46654 + return 0;
46655 +
46656 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46657 GET_VERSION_INFO_VENDOR_REQUEST,
46658 USB_TYPE_VENDOR | USB_DIR_IN,
46659 0, 0,
46660 - version, sizeof(version), 500);
46661 + version, 3, 500);
46662
46663 if (ret < 0)
46664 *cold = 1;
46665 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46666 *cold = 0;
46667 }
46668
46669 + kfree(version);
46670 +
46671 return 0;
46672 }
46673
46674 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46675
46676 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46677 {
46678 - u8 buf[62], *b;
46679 + u8 *buf, *b;
46680 int ret;
46681 struct ir_raw_event ev;
46682
46683 + buf = kmalloc(62, GFP_KERNEL);
46684 +
46685 + if (buf == NULL)
46686 + return -ENOMEM;
46687 +
46688 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46689 buf[1] = 0x08;
46690 buf[2] = 0x8f;
46691 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46692 GET_IR_DATA_VENDOR_REQUEST,
46693 USB_TYPE_VENDOR | USB_DIR_IN,
46694 0x8080, 0,
46695 - buf, sizeof(buf), 500);
46696 + buf, 62, 500);
46697
46698 unlock:
46699 mutex_unlock(&d->i2c_mutex);
46700
46701 - if (ret < 0)
46702 + if (ret < 0) {
46703 + kfree(buf);
46704 return ret;
46705 + }
46706
46707 - if (ret == 1)
46708 + if (ret == 1) {
46709 + kfree(buf);
46710 return 0; /* no key pressed */
46711 + }
46712
46713 /* decoding */
46714 b = buf+1;
46715 @@ -653,6 +686,8 @@ unlock:
46716
46717 ir_raw_event_handle(d->rc_dev);
46718
46719 + kfree(buf);
46720 +
46721 return 1;
46722 }
46723
46724 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46725 index cca6c2f..77b9a18 100644
46726 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46727 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46728 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
46729 __u32 reserved;
46730 };
46731
46732 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46733 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46734 enum v4l2_memory memory)
46735 {
46736 void __user *up_pln;
46737 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46738 return 0;
46739 }
46740
46741 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46742 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46743 enum v4l2_memory memory)
46744 {
46745 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
46746 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46747 * by passing a very big num_planes value */
46748 uplane = compat_alloc_user_space(num_planes *
46749 sizeof(struct v4l2_plane));
46750 - kp->m.planes = uplane;
46751 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
46752
46753 while (--num_planes >= 0) {
46754 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46755 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46756 if (num_planes == 0)
46757 return 0;
46758
46759 - uplane = kp->m.planes;
46760 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46761 if (get_user(p, &up->m.planes))
46762 return -EFAULT;
46763 uplane32 = compat_ptr(p);
46764 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46765 get_user(kp->flags, &up->flags) ||
46766 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46767 return -EFAULT;
46768 - kp->base = compat_ptr(tmp);
46769 + kp->base = (void __force_kernel *)compat_ptr(tmp);
46770 return 0;
46771 }
46772
46773 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46774 n * sizeof(struct v4l2_ext_control32)))
46775 return -EFAULT;
46776 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46777 - kp->controls = kcontrols;
46778 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
46779 while (--n >= 0) {
46780 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
46781 return -EFAULT;
46782 @@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46783 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
46784 {
46785 struct v4l2_ext_control32 __user *ucontrols;
46786 - struct v4l2_ext_control __user *kcontrols = kp->controls;
46787 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
46788 int n = kp->count;
46789 compat_caddr_t p;
46790
46791 @@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46792 put_user(kp->start_block, &up->start_block) ||
46793 put_user(kp->blocks, &up->blocks) ||
46794 put_user(tmp, &up->edid) ||
46795 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46796 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
46797 return -EFAULT;
46798 return 0;
46799 }
46800 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46801 index 015f92a..59e311e 100644
46802 --- a/drivers/media/v4l2-core/v4l2-device.c
46803 +++ b/drivers/media/v4l2-core/v4l2-device.c
46804 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46805 EXPORT_SYMBOL_GPL(v4l2_device_put);
46806
46807 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46808 - atomic_t *instance)
46809 + atomic_unchecked_t *instance)
46810 {
46811 - int num = atomic_inc_return(instance) - 1;
46812 + int num = atomic_inc_return_unchecked(instance) - 1;
46813 int len = strlen(basename);
46814
46815 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46816 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46817 index d15e167..337f374 100644
46818 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46819 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46820 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46821 struct file *file, void *fh, void *p);
46822 } u;
46823 void (*debug)(const void *arg, bool write_only);
46824 -};
46825 +} __do_const;
46826 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46827
46828 /* This control needs a priority check */
46829 #define INFO_FL_PRIO (1 << 0)
46830 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46831 struct video_device *vfd = video_devdata(file);
46832 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46833 bool write_only = false;
46834 - struct v4l2_ioctl_info default_info;
46835 + v4l2_ioctl_info_no_const default_info;
46836 const struct v4l2_ioctl_info *info;
46837 void *fh = file->private_data;
46838 struct v4l2_fh *vfh = NULL;
46839 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46840 ret = -EINVAL;
46841 break;
46842 }
46843 - *user_ptr = (void __user *)buf->m.planes;
46844 + *user_ptr = (void __force_user *)buf->m.planes;
46845 *kernel_ptr = (void **)&buf->m.planes;
46846 *array_size = sizeof(struct v4l2_plane) * buf->length;
46847 ret = 1;
46848 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46849 ret = -EINVAL;
46850 break;
46851 }
46852 - *user_ptr = (void __user *)edid->edid;
46853 + *user_ptr = (void __force_user *)edid->edid;
46854 *kernel_ptr = (void **)&edid->edid;
46855 *array_size = edid->blocks * 128;
46856 ret = 1;
46857 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46858 ret = -EINVAL;
46859 break;
46860 }
46861 - *user_ptr = (void __user *)ctrls->controls;
46862 + *user_ptr = (void __force_user *)ctrls->controls;
46863 *kernel_ptr = (void **)&ctrls->controls;
46864 *array_size = sizeof(struct v4l2_ext_control)
46865 * ctrls->count;
46866 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46867 }
46868
46869 if (has_array_args) {
46870 - *kernel_ptr = (void __force *)user_ptr;
46871 + *kernel_ptr = (void __force_kernel *)user_ptr;
46872 if (copy_to_user(user_ptr, mbuf, array_size))
46873 err = -EFAULT;
46874 goto out_array_args;
46875 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46876 index a896d94..a5d56b1 100644
46877 --- a/drivers/message/fusion/mptbase.c
46878 +++ b/drivers/message/fusion/mptbase.c
46879 @@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46880 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46881 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46882
46883 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46884 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46885 +#else
46886 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46887 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46888 +#endif
46889 +
46890 /*
46891 * Rounding UP to nearest 4-kB boundary here...
46892 */
46893 @@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46894 ioc->facts.GlobalCredits);
46895
46896 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46897 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46898 + NULL, NULL);
46899 +#else
46900 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46901 +#endif
46902 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46903 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46904 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46905 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46906 index 0707fa2..70ca794 100644
46907 --- a/drivers/message/fusion/mptsas.c
46908 +++ b/drivers/message/fusion/mptsas.c
46909 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46910 return 0;
46911 }
46912
46913 +static inline void
46914 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46915 +{
46916 + if (phy_info->port_details) {
46917 + phy_info->port_details->rphy = rphy;
46918 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46919 + ioc->name, rphy));
46920 + }
46921 +
46922 + if (rphy) {
46923 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46924 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46925 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46926 + ioc->name, rphy, rphy->dev.release));
46927 + }
46928 +}
46929 +
46930 /* no mutex */
46931 static void
46932 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46933 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46934 return NULL;
46935 }
46936
46937 -static inline void
46938 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46939 -{
46940 - if (phy_info->port_details) {
46941 - phy_info->port_details->rphy = rphy;
46942 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46943 - ioc->name, rphy));
46944 - }
46945 -
46946 - if (rphy) {
46947 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46948 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46949 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46950 - ioc->name, rphy, rphy->dev.release));
46951 - }
46952 -}
46953 -
46954 static inline struct sas_port *
46955 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46956 {
46957 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46958 index b7d87cd..3fb36da 100644
46959 --- a/drivers/message/i2o/i2o_proc.c
46960 +++ b/drivers/message/i2o/i2o_proc.c
46961 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46962 "Array Controller Device"
46963 };
46964
46965 -static char *chtostr(char *tmp, u8 *chars, int n)
46966 -{
46967 - tmp[0] = 0;
46968 - return strncat(tmp, (char *)chars, n);
46969 -}
46970 -
46971 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46972 char *group)
46973 {
46974 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46975 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46976 {
46977 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46978 - static u32 work32[5];
46979 - static u8 *work8 = (u8 *) work32;
46980 - static u16 *work16 = (u16 *) work32;
46981 + u32 work32[5];
46982 + u8 *work8 = (u8 *) work32;
46983 + u16 *work16 = (u16 *) work32;
46984 int token;
46985 u32 hwcap;
46986
46987 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46988 } *result;
46989
46990 i2o_exec_execute_ddm_table ddm_table;
46991 - char tmp[28 + 1];
46992
46993 result = kmalloc(sizeof(*result), GFP_KERNEL);
46994 if (!result)
46995 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46996
46997 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46998 seq_printf(seq, "%-#8x", ddm_table.module_id);
46999 - seq_printf(seq, "%-29s",
47000 - chtostr(tmp, ddm_table.module_name_version, 28));
47001 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47002 seq_printf(seq, "%9d ", ddm_table.data_size);
47003 seq_printf(seq, "%8d", ddm_table.code_size);
47004
47005 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47006
47007 i2o_driver_result_table *result;
47008 i2o_driver_store_table *dst;
47009 - char tmp[28 + 1];
47010
47011 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47012 if (result == NULL)
47013 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47014
47015 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47016 seq_printf(seq, "%-#8x", dst->module_id);
47017 - seq_printf(seq, "%-29s",
47018 - chtostr(tmp, dst->module_name_version, 28));
47019 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47020 + seq_printf(seq, "%-.28s", dst->module_name_version);
47021 + seq_printf(seq, "%-.8s", dst->date);
47022 seq_printf(seq, "%8d ", dst->module_size);
47023 seq_printf(seq, "%8d ", dst->mpb_size);
47024 seq_printf(seq, "0x%04x", dst->module_flags);
47025 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47026 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47027 {
47028 struct i2o_device *d = (struct i2o_device *)seq->private;
47029 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47030 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47031 // == (allow) 512d bytes (max)
47032 - static u16 *work16 = (u16 *) work32;
47033 + u16 *work16 = (u16 *) work32;
47034 int token;
47035 - char tmp[16 + 1];
47036
47037 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47038
47039 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47040 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47041 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47042 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47043 - seq_printf(seq, "Vendor info : %s\n",
47044 - chtostr(tmp, (u8 *) (work32 + 2), 16));
47045 - seq_printf(seq, "Product info : %s\n",
47046 - chtostr(tmp, (u8 *) (work32 + 6), 16));
47047 - seq_printf(seq, "Description : %s\n",
47048 - chtostr(tmp, (u8 *) (work32 + 10), 16));
47049 - seq_printf(seq, "Product rev. : %s\n",
47050 - chtostr(tmp, (u8 *) (work32 + 14), 8));
47051 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47052 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47053 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47054 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47055
47056 seq_printf(seq, "Serial number : ");
47057 print_serial_number(seq, (u8 *) (work32 + 16),
47058 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47059 u8 pad[256]; // allow up to 256 byte (max) serial number
47060 } result;
47061
47062 - char tmp[24 + 1];
47063 -
47064 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47065
47066 if (token < 0) {
47067 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47068 }
47069
47070 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47071 - seq_printf(seq, "Module name : %s\n",
47072 - chtostr(tmp, result.module_name, 24));
47073 - seq_printf(seq, "Module revision : %s\n",
47074 - chtostr(tmp, result.module_rev, 8));
47075 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
47076 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47077
47078 seq_printf(seq, "Serial number : ");
47079 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47080 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47081 u8 instance_number[4];
47082 } result;
47083
47084 - char tmp[64 + 1];
47085 -
47086 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47087
47088 if (token < 0) {
47089 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47090 return 0;
47091 }
47092
47093 - seq_printf(seq, "Device name : %s\n",
47094 - chtostr(tmp, result.device_name, 64));
47095 - seq_printf(seq, "Service name : %s\n",
47096 - chtostr(tmp, result.service_name, 64));
47097 - seq_printf(seq, "Physical name : %s\n",
47098 - chtostr(tmp, result.physical_location, 64));
47099 - seq_printf(seq, "Instance number : %s\n",
47100 - chtostr(tmp, result.instance_number, 4));
47101 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
47102 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
47103 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47104 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47105
47106 return 0;
47107 }
47108 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47109 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47110 {
47111 struct i2o_device *d = (struct i2o_device *)seq->private;
47112 - static u32 work32[12];
47113 - static u16 *work16 = (u16 *) work32;
47114 - static u8 *work8 = (u8 *) work32;
47115 + u32 work32[12];
47116 + u16 *work16 = (u16 *) work32;
47117 + u8 *work8 = (u8 *) work32;
47118 int token;
47119
47120 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47121 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47122 index 92752fb..a7494f6 100644
47123 --- a/drivers/message/i2o/iop.c
47124 +++ b/drivers/message/i2o/iop.c
47125 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47126
47127 spin_lock_irqsave(&c->context_list_lock, flags);
47128
47129 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47130 - atomic_inc(&c->context_list_counter);
47131 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47132 + atomic_inc_unchecked(&c->context_list_counter);
47133
47134 - entry->context = atomic_read(&c->context_list_counter);
47135 + entry->context = atomic_read_unchecked(&c->context_list_counter);
47136
47137 list_add(&entry->list, &c->context_list);
47138
47139 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47140
47141 #if BITS_PER_LONG == 64
47142 spin_lock_init(&c->context_list_lock);
47143 - atomic_set(&c->context_list_counter, 0);
47144 + atomic_set_unchecked(&c->context_list_counter, 0);
47145 INIT_LIST_HEAD(&c->context_list);
47146 #endif
47147
47148 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47149 index b2c7e3b..85aa4764 100644
47150 --- a/drivers/mfd/ab8500-debugfs.c
47151 +++ b/drivers/mfd/ab8500-debugfs.c
47152 @@ -100,7 +100,7 @@ static int irq_last;
47153 static u32 *irq_count;
47154 static int num_irqs;
47155
47156 -static struct device_attribute **dev_attr;
47157 +static device_attribute_no_const **dev_attr;
47158 static char **event_name;
47159
47160 static u8 avg_sample = SAMPLE_16;
47161 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47162 index ecbe78e..b2ca870 100644
47163 --- a/drivers/mfd/max8925-i2c.c
47164 +++ b/drivers/mfd/max8925-i2c.c
47165 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47166 const struct i2c_device_id *id)
47167 {
47168 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47169 - static struct max8925_chip *chip;
47170 + struct max8925_chip *chip;
47171 struct device_node *node = client->dev.of_node;
47172
47173 if (node && !pdata) {
47174 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47175 index f243e75..322176c 100644
47176 --- a/drivers/mfd/tps65910.c
47177 +++ b/drivers/mfd/tps65910.c
47178 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47179 struct tps65910_platform_data *pdata)
47180 {
47181 int ret = 0;
47182 - static struct regmap_irq_chip *tps6591x_irqs_chip;
47183 + struct regmap_irq_chip *tps6591x_irqs_chip;
47184
47185 if (!irq) {
47186 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47187 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47188 index b1dabba..24a88f2 100644
47189 --- a/drivers/mfd/twl4030-irq.c
47190 +++ b/drivers/mfd/twl4030-irq.c
47191 @@ -34,6 +34,7 @@
47192 #include <linux/of.h>
47193 #include <linux/irqdomain.h>
47194 #include <linux/i2c/twl.h>
47195 +#include <asm/pgtable.h>
47196
47197 #include "twl-core.h"
47198
47199 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47200 * Install an irq handler for each of the SIH modules;
47201 * clone dummy irq_chip since PIH can't *do* anything
47202 */
47203 - twl4030_irq_chip = dummy_irq_chip;
47204 - twl4030_irq_chip.name = "twl4030";
47205 + pax_open_kernel();
47206 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47207 + *(const char **)&twl4030_irq_chip.name = "twl4030";
47208
47209 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47210 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47211 + pax_close_kernel();
47212
47213 for (i = irq_base; i < irq_end; i++) {
47214 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47215 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47216 index 464419b..64bae8d 100644
47217 --- a/drivers/misc/c2port/core.c
47218 +++ b/drivers/misc/c2port/core.c
47219 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47220 goto error_idr_alloc;
47221 c2dev->id = ret;
47222
47223 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47224 + pax_open_kernel();
47225 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47226 + pax_close_kernel();
47227
47228 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47229 "c2port%d", c2dev->id);
47230 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47231 index 3f2b625..945e179 100644
47232 --- a/drivers/misc/eeprom/sunxi_sid.c
47233 +++ b/drivers/misc/eeprom/sunxi_sid.c
47234 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47235
47236 platform_set_drvdata(pdev, sid_data);
47237
47238 - sid_bin_attr.size = sid_data->keysize;
47239 + pax_open_kernel();
47240 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47241 + pax_close_kernel();
47242 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47243 return -ENODEV;
47244
47245 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47246 index 36f5d52..32311c3 100644
47247 --- a/drivers/misc/kgdbts.c
47248 +++ b/drivers/misc/kgdbts.c
47249 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47250 char before[BREAK_INSTR_SIZE];
47251 char after[BREAK_INSTR_SIZE];
47252
47253 - probe_kernel_read(before, (char *)kgdbts_break_test,
47254 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47255 BREAK_INSTR_SIZE);
47256 init_simple_test();
47257 ts.tst = plant_and_detach_test;
47258 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47259 /* Activate test with initial breakpoint */
47260 if (!is_early)
47261 kgdb_breakpoint();
47262 - probe_kernel_read(after, (char *)kgdbts_break_test,
47263 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47264 BREAK_INSTR_SIZE);
47265 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47266 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47267 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47268 index 3ef4627..8d00486 100644
47269 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47270 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47271 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47272 * the lid is closed. This leads to interrupts as soon as a little move
47273 * is done.
47274 */
47275 - atomic_inc(&lis3->count);
47276 + atomic_inc_unchecked(&lis3->count);
47277
47278 wake_up_interruptible(&lis3->misc_wait);
47279 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47280 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47281 if (lis3->pm_dev)
47282 pm_runtime_get_sync(lis3->pm_dev);
47283
47284 - atomic_set(&lis3->count, 0);
47285 + atomic_set_unchecked(&lis3->count, 0);
47286 return 0;
47287 }
47288
47289 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47290 add_wait_queue(&lis3->misc_wait, &wait);
47291 while (true) {
47292 set_current_state(TASK_INTERRUPTIBLE);
47293 - data = atomic_xchg(&lis3->count, 0);
47294 + data = atomic_xchg_unchecked(&lis3->count, 0);
47295 if (data)
47296 break;
47297
47298 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47299 struct lis3lv02d, miscdev);
47300
47301 poll_wait(file, &lis3->misc_wait, wait);
47302 - if (atomic_read(&lis3->count))
47303 + if (atomic_read_unchecked(&lis3->count))
47304 return POLLIN | POLLRDNORM;
47305 return 0;
47306 }
47307 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47308 index c439c82..1f20f57 100644
47309 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47310 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47311 @@ -297,7 +297,7 @@ struct lis3lv02d {
47312 struct input_polled_dev *idev; /* input device */
47313 struct platform_device *pdev; /* platform device */
47314 struct regulator_bulk_data regulators[2];
47315 - atomic_t count; /* interrupt count after last read */
47316 + atomic_unchecked_t count; /* interrupt count after last read */
47317 union axis_conversion ac; /* hw -> logical axis */
47318 int mapped_btns[3];
47319
47320 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47321 index 2f30bad..c4c13d0 100644
47322 --- a/drivers/misc/sgi-gru/gruhandles.c
47323 +++ b/drivers/misc/sgi-gru/gruhandles.c
47324 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47325 unsigned long nsec;
47326
47327 nsec = CLKS2NSEC(clks);
47328 - atomic_long_inc(&mcs_op_statistics[op].count);
47329 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47330 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47331 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47332 if (mcs_op_statistics[op].max < nsec)
47333 mcs_op_statistics[op].max = nsec;
47334 }
47335 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47336 index 4f76359..cdfcb2e 100644
47337 --- a/drivers/misc/sgi-gru/gruprocfs.c
47338 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47339 @@ -32,9 +32,9 @@
47340
47341 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47342
47343 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47344 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47345 {
47346 - unsigned long val = atomic_long_read(v);
47347 + unsigned long val = atomic_long_read_unchecked(v);
47348
47349 seq_printf(s, "%16lu %s\n", val, id);
47350 }
47351 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47352
47353 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47354 for (op = 0; op < mcsop_last; op++) {
47355 - count = atomic_long_read(&mcs_op_statistics[op].count);
47356 - total = atomic_long_read(&mcs_op_statistics[op].total);
47357 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47358 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47359 max = mcs_op_statistics[op].max;
47360 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47361 count ? total / count : 0, max);
47362 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47363 index 5c3ce24..4915ccb 100644
47364 --- a/drivers/misc/sgi-gru/grutables.h
47365 +++ b/drivers/misc/sgi-gru/grutables.h
47366 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47367 * GRU statistics.
47368 */
47369 struct gru_stats_s {
47370 - atomic_long_t vdata_alloc;
47371 - atomic_long_t vdata_free;
47372 - atomic_long_t gts_alloc;
47373 - atomic_long_t gts_free;
47374 - atomic_long_t gms_alloc;
47375 - atomic_long_t gms_free;
47376 - atomic_long_t gts_double_allocate;
47377 - atomic_long_t assign_context;
47378 - atomic_long_t assign_context_failed;
47379 - atomic_long_t free_context;
47380 - atomic_long_t load_user_context;
47381 - atomic_long_t load_kernel_context;
47382 - atomic_long_t lock_kernel_context;
47383 - atomic_long_t unlock_kernel_context;
47384 - atomic_long_t steal_user_context;
47385 - atomic_long_t steal_kernel_context;
47386 - atomic_long_t steal_context_failed;
47387 - atomic_long_t nopfn;
47388 - atomic_long_t asid_new;
47389 - atomic_long_t asid_next;
47390 - atomic_long_t asid_wrap;
47391 - atomic_long_t asid_reuse;
47392 - atomic_long_t intr;
47393 - atomic_long_t intr_cbr;
47394 - atomic_long_t intr_tfh;
47395 - atomic_long_t intr_spurious;
47396 - atomic_long_t intr_mm_lock_failed;
47397 - atomic_long_t call_os;
47398 - atomic_long_t call_os_wait_queue;
47399 - atomic_long_t user_flush_tlb;
47400 - atomic_long_t user_unload_context;
47401 - atomic_long_t user_exception;
47402 - atomic_long_t set_context_option;
47403 - atomic_long_t check_context_retarget_intr;
47404 - atomic_long_t check_context_unload;
47405 - atomic_long_t tlb_dropin;
47406 - atomic_long_t tlb_preload_page;
47407 - atomic_long_t tlb_dropin_fail_no_asid;
47408 - atomic_long_t tlb_dropin_fail_upm;
47409 - atomic_long_t tlb_dropin_fail_invalid;
47410 - atomic_long_t tlb_dropin_fail_range_active;
47411 - atomic_long_t tlb_dropin_fail_idle;
47412 - atomic_long_t tlb_dropin_fail_fmm;
47413 - atomic_long_t tlb_dropin_fail_no_exception;
47414 - atomic_long_t tfh_stale_on_fault;
47415 - atomic_long_t mmu_invalidate_range;
47416 - atomic_long_t mmu_invalidate_page;
47417 - atomic_long_t flush_tlb;
47418 - atomic_long_t flush_tlb_gru;
47419 - atomic_long_t flush_tlb_gru_tgh;
47420 - atomic_long_t flush_tlb_gru_zero_asid;
47421 + atomic_long_unchecked_t vdata_alloc;
47422 + atomic_long_unchecked_t vdata_free;
47423 + atomic_long_unchecked_t gts_alloc;
47424 + atomic_long_unchecked_t gts_free;
47425 + atomic_long_unchecked_t gms_alloc;
47426 + atomic_long_unchecked_t gms_free;
47427 + atomic_long_unchecked_t gts_double_allocate;
47428 + atomic_long_unchecked_t assign_context;
47429 + atomic_long_unchecked_t assign_context_failed;
47430 + atomic_long_unchecked_t free_context;
47431 + atomic_long_unchecked_t load_user_context;
47432 + atomic_long_unchecked_t load_kernel_context;
47433 + atomic_long_unchecked_t lock_kernel_context;
47434 + atomic_long_unchecked_t unlock_kernel_context;
47435 + atomic_long_unchecked_t steal_user_context;
47436 + atomic_long_unchecked_t steal_kernel_context;
47437 + atomic_long_unchecked_t steal_context_failed;
47438 + atomic_long_unchecked_t nopfn;
47439 + atomic_long_unchecked_t asid_new;
47440 + atomic_long_unchecked_t asid_next;
47441 + atomic_long_unchecked_t asid_wrap;
47442 + atomic_long_unchecked_t asid_reuse;
47443 + atomic_long_unchecked_t intr;
47444 + atomic_long_unchecked_t intr_cbr;
47445 + atomic_long_unchecked_t intr_tfh;
47446 + atomic_long_unchecked_t intr_spurious;
47447 + atomic_long_unchecked_t intr_mm_lock_failed;
47448 + atomic_long_unchecked_t call_os;
47449 + atomic_long_unchecked_t call_os_wait_queue;
47450 + atomic_long_unchecked_t user_flush_tlb;
47451 + atomic_long_unchecked_t user_unload_context;
47452 + atomic_long_unchecked_t user_exception;
47453 + atomic_long_unchecked_t set_context_option;
47454 + atomic_long_unchecked_t check_context_retarget_intr;
47455 + atomic_long_unchecked_t check_context_unload;
47456 + atomic_long_unchecked_t tlb_dropin;
47457 + atomic_long_unchecked_t tlb_preload_page;
47458 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47459 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47460 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47461 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47462 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47463 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47464 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47465 + atomic_long_unchecked_t tfh_stale_on_fault;
47466 + atomic_long_unchecked_t mmu_invalidate_range;
47467 + atomic_long_unchecked_t mmu_invalidate_page;
47468 + atomic_long_unchecked_t flush_tlb;
47469 + atomic_long_unchecked_t flush_tlb_gru;
47470 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47471 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47472
47473 - atomic_long_t copy_gpa;
47474 - atomic_long_t read_gpa;
47475 + atomic_long_unchecked_t copy_gpa;
47476 + atomic_long_unchecked_t read_gpa;
47477
47478 - atomic_long_t mesq_receive;
47479 - atomic_long_t mesq_receive_none;
47480 - atomic_long_t mesq_send;
47481 - atomic_long_t mesq_send_failed;
47482 - atomic_long_t mesq_noop;
47483 - atomic_long_t mesq_send_unexpected_error;
47484 - atomic_long_t mesq_send_lb_overflow;
47485 - atomic_long_t mesq_send_qlimit_reached;
47486 - atomic_long_t mesq_send_amo_nacked;
47487 - atomic_long_t mesq_send_put_nacked;
47488 - atomic_long_t mesq_page_overflow;
47489 - atomic_long_t mesq_qf_locked;
47490 - atomic_long_t mesq_qf_noop_not_full;
47491 - atomic_long_t mesq_qf_switch_head_failed;
47492 - atomic_long_t mesq_qf_unexpected_error;
47493 - atomic_long_t mesq_noop_unexpected_error;
47494 - atomic_long_t mesq_noop_lb_overflow;
47495 - atomic_long_t mesq_noop_qlimit_reached;
47496 - atomic_long_t mesq_noop_amo_nacked;
47497 - atomic_long_t mesq_noop_put_nacked;
47498 - atomic_long_t mesq_noop_page_overflow;
47499 + atomic_long_unchecked_t mesq_receive;
47500 + atomic_long_unchecked_t mesq_receive_none;
47501 + atomic_long_unchecked_t mesq_send;
47502 + atomic_long_unchecked_t mesq_send_failed;
47503 + atomic_long_unchecked_t mesq_noop;
47504 + atomic_long_unchecked_t mesq_send_unexpected_error;
47505 + atomic_long_unchecked_t mesq_send_lb_overflow;
47506 + atomic_long_unchecked_t mesq_send_qlimit_reached;
47507 + atomic_long_unchecked_t mesq_send_amo_nacked;
47508 + atomic_long_unchecked_t mesq_send_put_nacked;
47509 + atomic_long_unchecked_t mesq_page_overflow;
47510 + atomic_long_unchecked_t mesq_qf_locked;
47511 + atomic_long_unchecked_t mesq_qf_noop_not_full;
47512 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
47513 + atomic_long_unchecked_t mesq_qf_unexpected_error;
47514 + atomic_long_unchecked_t mesq_noop_unexpected_error;
47515 + atomic_long_unchecked_t mesq_noop_lb_overflow;
47516 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
47517 + atomic_long_unchecked_t mesq_noop_amo_nacked;
47518 + atomic_long_unchecked_t mesq_noop_put_nacked;
47519 + atomic_long_unchecked_t mesq_noop_page_overflow;
47520
47521 };
47522
47523 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47524 tghop_invalidate, mcsop_last};
47525
47526 struct mcs_op_statistic {
47527 - atomic_long_t count;
47528 - atomic_long_t total;
47529 + atomic_long_unchecked_t count;
47530 + atomic_long_unchecked_t total;
47531 unsigned long max;
47532 };
47533
47534 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47535
47536 #define STAT(id) do { \
47537 if (gru_options & OPT_STATS) \
47538 - atomic_long_inc(&gru_stats.id); \
47539 + atomic_long_inc_unchecked(&gru_stats.id); \
47540 } while (0)
47541
47542 #ifdef CONFIG_SGI_GRU_DEBUG
47543 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47544 index c862cd4..0d176fe 100644
47545 --- a/drivers/misc/sgi-xp/xp.h
47546 +++ b/drivers/misc/sgi-xp/xp.h
47547 @@ -288,7 +288,7 @@ struct xpc_interface {
47548 xpc_notify_func, void *);
47549 void (*received) (short, int, void *);
47550 enum xp_retval (*partid_to_nasids) (short, void *);
47551 -};
47552 +} __no_const;
47553
47554 extern struct xpc_interface xpc_interface;
47555
47556 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47557 index 01be66d..e3a0c7e 100644
47558 --- a/drivers/misc/sgi-xp/xp_main.c
47559 +++ b/drivers/misc/sgi-xp/xp_main.c
47560 @@ -78,13 +78,13 @@ xpc_notloaded(void)
47561 }
47562
47563 struct xpc_interface xpc_interface = {
47564 - (void (*)(int))xpc_notloaded,
47565 - (void (*)(int))xpc_notloaded,
47566 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47567 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47568 + .connect = (void (*)(int))xpc_notloaded,
47569 + .disconnect = (void (*)(int))xpc_notloaded,
47570 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47571 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47572 void *))xpc_notloaded,
47573 - (void (*)(short, int, void *))xpc_notloaded,
47574 - (enum xp_retval(*)(short, void *))xpc_notloaded
47575 + .received = (void (*)(short, int, void *))xpc_notloaded,
47576 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47577 };
47578 EXPORT_SYMBOL_GPL(xpc_interface);
47579
47580 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47581 index b94d5f7..7f494c5 100644
47582 --- a/drivers/misc/sgi-xp/xpc.h
47583 +++ b/drivers/misc/sgi-xp/xpc.h
47584 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47585 void (*received_payload) (struct xpc_channel *, void *);
47586 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47587 };
47588 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47589
47590 /* struct xpc_partition act_state values (for XPC HB) */
47591
47592 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47593 /* found in xpc_main.c */
47594 extern struct device *xpc_part;
47595 extern struct device *xpc_chan;
47596 -extern struct xpc_arch_operations xpc_arch_ops;
47597 +extern xpc_arch_operations_no_const xpc_arch_ops;
47598 extern int xpc_disengage_timelimit;
47599 extern int xpc_disengage_timedout;
47600 extern int xpc_activate_IRQ_rcvd;
47601 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47602 index 82dc574..8539ab2 100644
47603 --- a/drivers/misc/sgi-xp/xpc_main.c
47604 +++ b/drivers/misc/sgi-xp/xpc_main.c
47605 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47606 .notifier_call = xpc_system_die,
47607 };
47608
47609 -struct xpc_arch_operations xpc_arch_ops;
47610 +xpc_arch_operations_no_const xpc_arch_ops;
47611
47612 /*
47613 * Timer function to enforce the timelimit on the partition disengage.
47614 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47615
47616 if (((die_args->trapnr == X86_TRAP_MF) ||
47617 (die_args->trapnr == X86_TRAP_XF)) &&
47618 - !user_mode_vm(die_args->regs))
47619 + !user_mode(die_args->regs))
47620 xpc_die_deactivate();
47621
47622 break;
47623 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47624 index ede41f0..744fbd9 100644
47625 --- a/drivers/mmc/card/block.c
47626 +++ b/drivers/mmc/card/block.c
47627 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47628 if (idata->ic.postsleep_min_us)
47629 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47630
47631 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47632 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47633 err = -EFAULT;
47634 goto cmd_rel_host;
47635 }
47636 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47637 index f51b5ba..86614a7 100644
47638 --- a/drivers/mmc/core/mmc_ops.c
47639 +++ b/drivers/mmc/core/mmc_ops.c
47640 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47641 void *data_buf;
47642 int is_on_stack;
47643
47644 - is_on_stack = object_is_on_stack(buf);
47645 + is_on_stack = object_starts_on_stack(buf);
47646 if (is_on_stack) {
47647 /*
47648 * dma onto stack is unsafe/nonportable, but callers to this
47649 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47650 index 08fd956..370487a 100644
47651 --- a/drivers/mmc/host/dw_mmc.h
47652 +++ b/drivers/mmc/host/dw_mmc.h
47653 @@ -262,5 +262,5 @@ struct dw_mci_drv_data {
47654 int (*parse_dt)(struct dw_mci *host);
47655 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47656 struct dw_mci_tuning_data *tuning_data);
47657 -};
47658 +} __do_const;
47659 #endif /* _DW_MMC_H_ */
47660 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47661 index e4d4707..28262a3 100644
47662 --- a/drivers/mmc/host/mmci.c
47663 +++ b/drivers/mmc/host/mmci.c
47664 @@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
47665 mmc->caps |= MMC_CAP_CMD23;
47666
47667 if (variant->busy_detect) {
47668 - mmci_ops.card_busy = mmci_card_busy;
47669 + pax_open_kernel();
47670 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47671 + pax_close_kernel();
47672 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47673 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47674 mmc->max_busy_timeout = 0;
47675 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47676 index ccec0e3..199f9ce 100644
47677 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47678 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47679 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47680 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47681 }
47682
47683 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47684 - sdhci_esdhc_ops.platform_execute_tuning =
47685 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47686 + pax_open_kernel();
47687 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47688 esdhc_executing_tuning;
47689 + pax_close_kernel();
47690 + }
47691
47692 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47693 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47694 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47695 index 1e47903..7683916 100644
47696 --- a/drivers/mmc/host/sdhci-s3c.c
47697 +++ b/drivers/mmc/host/sdhci-s3c.c
47698 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47699 * we can use overriding functions instead of default.
47700 */
47701 if (sc->no_divider) {
47702 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47703 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47704 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47705 + pax_open_kernel();
47706 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47707 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47708 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47709 + pax_close_kernel();
47710 }
47711
47712 /* It supports additional host capabilities if needed */
47713 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47714 index 423666b..81ff5eb 100644
47715 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47716 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47717 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47718 size_t totlen = 0, thislen;
47719 int ret = 0;
47720 size_t buflen = 0;
47721 - static char *buffer;
47722 + char *buffer;
47723
47724 if (!ECCBUF_SIZE) {
47725 /* We should fall back to a general writev implementation.
47726 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47727 index 0b071a3..8ec3d5b 100644
47728 --- a/drivers/mtd/nand/denali.c
47729 +++ b/drivers/mtd/nand/denali.c
47730 @@ -24,6 +24,7 @@
47731 #include <linux/slab.h>
47732 #include <linux/mtd/mtd.h>
47733 #include <linux/module.h>
47734 +#include <linux/slab.h>
47735
47736 #include "denali.h"
47737
47738 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47739 index 959cb9b..8520fe5 100644
47740 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47741 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47742 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47743
47744 /* first try to map the upper buffer directly */
47745 if (virt_addr_valid(this->upper_buf) &&
47746 - !object_is_on_stack(this->upper_buf)) {
47747 + !object_starts_on_stack(this->upper_buf)) {
47748 sg_init_one(sgl, this->upper_buf, this->upper_len);
47749 ret = dma_map_sg(this->dev, sgl, 1, dr);
47750 if (ret == 0)
47751 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47752 index 51b9d6a..52af9a7 100644
47753 --- a/drivers/mtd/nftlmount.c
47754 +++ b/drivers/mtd/nftlmount.c
47755 @@ -24,6 +24,7 @@
47756 #include <asm/errno.h>
47757 #include <linux/delay.h>
47758 #include <linux/slab.h>
47759 +#include <linux/sched.h>
47760 #include <linux/mtd/mtd.h>
47761 #include <linux/mtd/nand.h>
47762 #include <linux/mtd/nftl.h>
47763 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47764 index cf49c22..971b133 100644
47765 --- a/drivers/mtd/sm_ftl.c
47766 +++ b/drivers/mtd/sm_ftl.c
47767 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47768 #define SM_CIS_VENDOR_OFFSET 0x59
47769 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47770 {
47771 - struct attribute_group *attr_group;
47772 + attribute_group_no_const *attr_group;
47773 struct attribute **attributes;
47774 struct sm_sysfs_attribute *vendor_attribute;
47775 char *vendor;
47776 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47777 index fc061c3..53853ef 100644
47778 --- a/drivers/net/bonding/bond_netlink.c
47779 +++ b/drivers/net/bonding/bond_netlink.c
47780 @@ -553,7 +553,7 @@ nla_put_failure:
47781 return -EMSGSIZE;
47782 }
47783
47784 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47785 +struct rtnl_link_ops bond_link_ops = {
47786 .kind = "bond",
47787 .priv_size = sizeof(struct bonding),
47788 .setup = bond_setup,
47789 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47790 index 5e40a8b..126bfda 100644
47791 --- a/drivers/net/caif/caif_hsi.c
47792 +++ b/drivers/net/caif/caif_hsi.c
47793 @@ -1445,7 +1445,7 @@ err:
47794 return -ENODEV;
47795 }
47796
47797 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47798 +static struct rtnl_link_ops caif_hsi_link_ops = {
47799 .kind = "cfhsi",
47800 .priv_size = sizeof(struct cfhsi),
47801 .setup = cfhsi_setup,
47802 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47803 index 4168822..f38eeddf 100644
47804 --- a/drivers/net/can/Kconfig
47805 +++ b/drivers/net/can/Kconfig
47806 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47807
47808 config CAN_FLEXCAN
47809 tristate "Support for Freescale FLEXCAN based chips"
47810 - depends on ARM || PPC
47811 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47812 ---help---
47813 Say Y here if you want to support for Freescale FlexCAN.
47814
47815 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47816 index 6403503..a0c8bb6 100644
47817 --- a/drivers/net/can/dev.c
47818 +++ b/drivers/net/can/dev.c
47819 @@ -869,7 +869,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47820 return -EOPNOTSUPP;
47821 }
47822
47823 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47824 +static struct rtnl_link_ops can_link_ops = {
47825 .kind = "can",
47826 .maxtype = IFLA_CAN_MAX,
47827 .policy = can_policy,
47828 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47829 index 4e94057..32032ff 100644
47830 --- a/drivers/net/can/vcan.c
47831 +++ b/drivers/net/can/vcan.c
47832 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47833 dev->destructor = free_netdev;
47834 }
47835
47836 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47837 +static struct rtnl_link_ops vcan_link_ops = {
47838 .kind = "vcan",
47839 .setup = vcan_setup,
47840 };
47841 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47842 index ff435fb..d408b1f 100644
47843 --- a/drivers/net/dummy.c
47844 +++ b/drivers/net/dummy.c
47845 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47846 return 0;
47847 }
47848
47849 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47850 +static struct rtnl_link_ops dummy_link_ops = {
47851 .kind = "dummy",
47852 .setup = dummy_setup,
47853 .validate = dummy_validate,
47854 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47855 index 1d162cc..b546a75 100644
47856 --- a/drivers/net/ethernet/8390/ax88796.c
47857 +++ b/drivers/net/ethernet/8390/ax88796.c
47858 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47859 if (ax->plat->reg_offsets)
47860 ei_local->reg_offset = ax->plat->reg_offsets;
47861 else {
47862 + resource_size_t _mem_size = mem_size;
47863 + do_div(_mem_size, 0x18);
47864 ei_local->reg_offset = ax->reg_offsets;
47865 for (ret = 0; ret < 0x18; ret++)
47866 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47867 + ax->reg_offsets[ret] = _mem_size * ret;
47868 }
47869
47870 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47871 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47872 index 7330681..7e9e463 100644
47873 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47874 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47875 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
47876 return 0;
47877 }
47878
47879 -static struct net_device_ops altera_tse_netdev_ops = {
47880 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47881 .ndo_open = tse_open,
47882 .ndo_stop = tse_shutdown,
47883 .ndo_start_xmit = tse_start_xmit,
47884 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47885 ndev->netdev_ops = &altera_tse_netdev_ops;
47886 altera_tse_set_ethtool_ops(ndev);
47887
47888 + pax_open_kernel();
47889 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47890
47891 if (priv->hash_filter)
47892 altera_tse_netdev_ops.ndo_set_rx_mode =
47893 tse_set_rx_mode_hashfilter;
47894 + pax_close_kernel();
47895
47896 /* Scatter/gather IO is not supported,
47897 * so it is turned off
47898 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47899 index cc25a3a..c8d72d3 100644
47900 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47901 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47902 @@ -1083,14 +1083,14 @@ do { \
47903 * operations, everything works on mask values.
47904 */
47905 #define XMDIO_READ(_pdata, _mmd, _reg) \
47906 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47907 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47908 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47909
47910 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47911 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47912
47913 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47914 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47915 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47916 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47917
47918 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47919 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47920 index 7d6a49b..e6d403b 100644
47921 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47922 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47923 @@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47924
47925 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47926
47927 - pdata->hw_if.config_dcb_tc(pdata);
47928 + pdata->hw_if->config_dcb_tc(pdata);
47929
47930 return 0;
47931 }
47932 @@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47933
47934 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47935
47936 - pdata->hw_if.config_dcb_pfc(pdata);
47937 + pdata->hw_if->config_dcb_pfc(pdata);
47938
47939 return 0;
47940 }
47941 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47942 index 1c5d62e..8e14d54 100644
47943 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47944 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47945 @@ -236,7 +236,7 @@ err_ring:
47946
47947 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47948 {
47949 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47950 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47951 struct xgbe_channel *channel;
47952 struct xgbe_ring *ring;
47953 struct xgbe_ring_data *rdata;
47954 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47955
47956 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47957 {
47958 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47959 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47960 struct xgbe_channel *channel;
47961 struct xgbe_ring *ring;
47962 struct xgbe_ring_desc *rdesc;
47963 @@ -506,7 +506,7 @@ err_out:
47964 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47965 {
47966 struct xgbe_prv_data *pdata = channel->pdata;
47967 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47968 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47969 struct xgbe_ring *ring = channel->rx_ring;
47970 struct xgbe_ring_data *rdata;
47971 struct sk_buff *skb = NULL;
47972 @@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47973 DBGPR("<--xgbe_realloc_skb\n");
47974 }
47975
47976 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47977 -{
47978 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47979 -
47980 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47981 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47982 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47983 - desc_if->realloc_skb = xgbe_realloc_skb;
47984 - desc_if->unmap_skb = xgbe_unmap_skb;
47985 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47986 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47987 -
47988 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47989 -}
47990 +const struct xgbe_desc_if default_xgbe_desc_if = {
47991 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47992 + .free_ring_resources = xgbe_free_ring_resources,
47993 + .map_tx_skb = xgbe_map_tx_skb,
47994 + .realloc_skb = xgbe_realloc_skb,
47995 + .unmap_skb = xgbe_unmap_skb,
47996 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47997 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47998 +};
47999 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48000 index ea27383..faa8936 100644
48001 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48002 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48003 @@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48004
48005 static int xgbe_init(struct xgbe_prv_data *pdata)
48006 {
48007 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48008 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48009 int ret;
48010
48011 DBGPR("-->xgbe_init\n");
48012 @@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48013 return 0;
48014 }
48015
48016 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48017 -{
48018 - DBGPR("-->xgbe_init_function_ptrs\n");
48019 -
48020 - hw_if->tx_complete = xgbe_tx_complete;
48021 -
48022 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48023 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48024 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
48025 - hw_if->set_mac_address = xgbe_set_mac_address;
48026 -
48027 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48028 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48029 -
48030 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48031 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48032 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
48033 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
48034 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
48035 -
48036 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48037 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48038 -
48039 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48040 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48041 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48042 -
48043 - hw_if->enable_tx = xgbe_enable_tx;
48044 - hw_if->disable_tx = xgbe_disable_tx;
48045 - hw_if->enable_rx = xgbe_enable_rx;
48046 - hw_if->disable_rx = xgbe_disable_rx;
48047 -
48048 - hw_if->powerup_tx = xgbe_powerup_tx;
48049 - hw_if->powerdown_tx = xgbe_powerdown_tx;
48050 - hw_if->powerup_rx = xgbe_powerup_rx;
48051 - hw_if->powerdown_rx = xgbe_powerdown_rx;
48052 -
48053 - hw_if->pre_xmit = xgbe_pre_xmit;
48054 - hw_if->dev_read = xgbe_dev_read;
48055 - hw_if->enable_int = xgbe_enable_int;
48056 - hw_if->disable_int = xgbe_disable_int;
48057 - hw_if->init = xgbe_init;
48058 - hw_if->exit = xgbe_exit;
48059 +const struct xgbe_hw_if default_xgbe_hw_if = {
48060 + .tx_complete = xgbe_tx_complete,
48061 +
48062 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48063 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48064 + .add_mac_addresses = xgbe_add_mac_addresses,
48065 + .set_mac_address = xgbe_set_mac_address,
48066 +
48067 + .enable_rx_csum = xgbe_enable_rx_csum,
48068 + .disable_rx_csum = xgbe_disable_rx_csum,
48069 +
48070 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48071 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48072 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
48073 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
48074 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
48075 +
48076 + .read_mmd_regs = xgbe_read_mmd_regs,
48077 + .write_mmd_regs = xgbe_write_mmd_regs,
48078 +
48079 + .set_gmii_speed = xgbe_set_gmii_speed,
48080 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48081 + .set_xgmii_speed = xgbe_set_xgmii_speed,
48082 +
48083 + .enable_tx = xgbe_enable_tx,
48084 + .disable_tx = xgbe_disable_tx,
48085 + .enable_rx = xgbe_enable_rx,
48086 + .disable_rx = xgbe_disable_rx,
48087 +
48088 + .powerup_tx = xgbe_powerup_tx,
48089 + .powerdown_tx = xgbe_powerdown_tx,
48090 + .powerup_rx = xgbe_powerup_rx,
48091 + .powerdown_rx = xgbe_powerdown_rx,
48092 +
48093 + .pre_xmit = xgbe_pre_xmit,
48094 + .dev_read = xgbe_dev_read,
48095 + .enable_int = xgbe_enable_int,
48096 + .disable_int = xgbe_disable_int,
48097 + .init = xgbe_init,
48098 + .exit = xgbe_exit,
48099
48100 /* Descriptor related Sequences have to be initialized here */
48101 - hw_if->tx_desc_init = xgbe_tx_desc_init;
48102 - hw_if->rx_desc_init = xgbe_rx_desc_init;
48103 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48104 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48105 - hw_if->is_last_desc = xgbe_is_last_desc;
48106 - hw_if->is_context_desc = xgbe_is_context_desc;
48107 + .tx_desc_init = xgbe_tx_desc_init,
48108 + .rx_desc_init = xgbe_rx_desc_init,
48109 + .tx_desc_reset = xgbe_tx_desc_reset,
48110 + .rx_desc_reset = xgbe_rx_desc_reset,
48111 + .is_last_desc = xgbe_is_last_desc,
48112 + .is_context_desc = xgbe_is_context_desc,
48113
48114 /* For FLOW ctrl */
48115 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48116 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48117 + .config_tx_flow_control = xgbe_config_tx_flow_control,
48118 + .config_rx_flow_control = xgbe_config_rx_flow_control,
48119
48120 /* For RX coalescing */
48121 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48122 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48123 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48124 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48125 + .config_rx_coalesce = xgbe_config_rx_coalesce,
48126 + .config_tx_coalesce = xgbe_config_tx_coalesce,
48127 + .usec_to_riwt = xgbe_usec_to_riwt,
48128 + .riwt_to_usec = xgbe_riwt_to_usec,
48129
48130 /* For RX and TX threshold config */
48131 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48132 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48133 + .config_rx_threshold = xgbe_config_rx_threshold,
48134 + .config_tx_threshold = xgbe_config_tx_threshold,
48135
48136 /* For RX and TX Store and Forward Mode config */
48137 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48138 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48139 + .config_rsf_mode = xgbe_config_rsf_mode,
48140 + .config_tsf_mode = xgbe_config_tsf_mode,
48141
48142 /* For TX DMA Operating on Second Frame config */
48143 - hw_if->config_osp_mode = xgbe_config_osp_mode;
48144 + .config_osp_mode = xgbe_config_osp_mode,
48145
48146 /* For RX and TX PBL config */
48147 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48148 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48149 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48150 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48151 - hw_if->config_pblx8 = xgbe_config_pblx8;
48152 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48153 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48154 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48155 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48156 + .config_pblx8 = xgbe_config_pblx8,
48157
48158 /* For MMC statistics support */
48159 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48160 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48161 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48162 + .tx_mmc_int = xgbe_tx_mmc_int,
48163 + .rx_mmc_int = xgbe_rx_mmc_int,
48164 + .read_mmc_stats = xgbe_read_mmc_stats,
48165
48166 /* For PTP config */
48167 - hw_if->config_tstamp = xgbe_config_tstamp;
48168 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
48169 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
48170 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
48171 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
48172 + .config_tstamp = xgbe_config_tstamp,
48173 + .update_tstamp_addend = xgbe_update_tstamp_addend,
48174 + .set_tstamp_time = xgbe_set_tstamp_time,
48175 + .get_tstamp_time = xgbe_get_tstamp_time,
48176 + .get_tx_tstamp = xgbe_get_tx_tstamp,
48177
48178 /* For Data Center Bridging config */
48179 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
48180 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
48181 -
48182 - DBGPR("<--xgbe_init_function_ptrs\n");
48183 -}
48184 + .config_dcb_tc = xgbe_config_dcb_tc,
48185 + .config_dcb_pfc = xgbe_config_dcb_pfc,
48186 +};
48187 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48188 index b26d758..b0d1c3b 100644
48189 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48190 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48191 @@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48192
48193 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48194 {
48195 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48196 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48197 struct xgbe_channel *channel;
48198 enum xgbe_int int_id;
48199 unsigned int i;
48200 @@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48201
48202 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48203 {
48204 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48205 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48206 struct xgbe_channel *channel;
48207 enum xgbe_int int_id;
48208 unsigned int i;
48209 @@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48210 static irqreturn_t xgbe_isr(int irq, void *data)
48211 {
48212 struct xgbe_prv_data *pdata = data;
48213 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48214 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48215 struct xgbe_channel *channel;
48216 unsigned int dma_isr, dma_ch_isr;
48217 unsigned int mac_isr, mac_tssr;
48218 @@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
48219
48220 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48221 {
48222 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48223 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48224
48225 DBGPR("-->xgbe_init_tx_coalesce\n");
48226
48227 @@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48228
48229 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48230 {
48231 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48232 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48233
48234 DBGPR("-->xgbe_init_rx_coalesce\n");
48235
48236 @@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48237
48238 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48239 {
48240 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48241 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48242 struct xgbe_channel *channel;
48243 struct xgbe_ring *ring;
48244 struct xgbe_ring_data *rdata;
48245 @@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48246
48247 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48248 {
48249 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48250 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48251 struct xgbe_channel *channel;
48252 struct xgbe_ring *ring;
48253 struct xgbe_ring_data *rdata;
48254 @@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48255 static void xgbe_adjust_link(struct net_device *netdev)
48256 {
48257 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48258 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48259 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48260 struct phy_device *phydev = pdata->phydev;
48261 int new_state = 0;
48262
48263 @@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
48264 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48265 {
48266 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48267 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48268 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48269 unsigned long flags;
48270
48271 DBGPR("-->xgbe_powerdown\n");
48272 @@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48273 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48274 {
48275 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48276 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48277 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48278 unsigned long flags;
48279
48280 DBGPR("-->xgbe_powerup\n");
48281 @@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48282
48283 static int xgbe_start(struct xgbe_prv_data *pdata)
48284 {
48285 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48286 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48287 struct net_device *netdev = pdata->netdev;
48288
48289 DBGPR("-->xgbe_start\n");
48290 @@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48291
48292 static void xgbe_stop(struct xgbe_prv_data *pdata)
48293 {
48294 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48295 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48296 struct net_device *netdev = pdata->netdev;
48297
48298 DBGPR("-->xgbe_stop\n");
48299 @@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48300
48301 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48302 {
48303 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48304 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48305
48306 DBGPR("-->xgbe_restart_dev\n");
48307
48308 @@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
48309 return -ERANGE;
48310 }
48311
48312 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
48313 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
48314
48315 memcpy(&pdata->tstamp_config, &config, sizeof(config));
48316
48317 @@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
48318 static int xgbe_open(struct net_device *netdev)
48319 {
48320 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48321 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48322 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48323 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48324 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48325 int ret;
48326
48327 DBGPR("-->xgbe_open\n");
48328 @@ -1171,8 +1171,8 @@ err_phy_init:
48329 static int xgbe_close(struct net_device *netdev)
48330 {
48331 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48332 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48333 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48334 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48335 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48336
48337 DBGPR("-->xgbe_close\n");
48338
48339 @@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48340 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48341 {
48342 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48343 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48344 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48345 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48346 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48347 struct xgbe_channel *channel;
48348 struct xgbe_ring *ring;
48349 struct xgbe_packet_data *packet;
48350 @@ -1276,7 +1276,7 @@ tx_netdev_return:
48351 static void xgbe_set_rx_mode(struct net_device *netdev)
48352 {
48353 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48354 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48355 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48356 unsigned int pr_mode, am_mode;
48357
48358 DBGPR("-->xgbe_set_rx_mode\n");
48359 @@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48360 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48361 {
48362 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48363 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48364 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48365 struct sockaddr *saddr = addr;
48366
48367 DBGPR("-->xgbe_set_mac_address\n");
48368 @@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48369
48370 DBGPR("-->%s\n", __func__);
48371
48372 - pdata->hw_if.read_mmc_stats(pdata);
48373 + pdata->hw_if->read_mmc_stats(pdata);
48374
48375 s->rx_packets = pstats->rxframecount_gb;
48376 s->rx_bytes = pstats->rxoctetcount_gb;
48377 @@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48378 u16 vid)
48379 {
48380 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48381 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48382 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48383
48384 DBGPR("-->%s\n", __func__);
48385
48386 @@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48387 u16 vid)
48388 {
48389 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48390 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48391 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48392
48393 DBGPR("-->%s\n", __func__);
48394
48395 @@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48396 netdev_features_t features)
48397 {
48398 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48399 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48400 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48401 unsigned int rxcsum, rxvlan, rxvlan_filter;
48402
48403 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48404 @@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48405 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48406 {
48407 struct xgbe_prv_data *pdata = channel->pdata;
48408 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48409 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48410 struct xgbe_ring *ring = channel->rx_ring;
48411 struct xgbe_ring_data *rdata;
48412
48413 @@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48414 static int xgbe_tx_poll(struct xgbe_channel *channel)
48415 {
48416 struct xgbe_prv_data *pdata = channel->pdata;
48417 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48418 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48419 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48420 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48421 struct xgbe_ring *ring = channel->tx_ring;
48422 struct xgbe_ring_data *rdata;
48423 struct xgbe_ring_desc *rdesc;
48424 @@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48425 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48426 {
48427 struct xgbe_prv_data *pdata = channel->pdata;
48428 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48429 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48430 struct xgbe_ring *ring = channel->rx_ring;
48431 struct xgbe_ring_data *rdata;
48432 struct xgbe_packet_data *packet;
48433 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48434 index 46f6130..f37dde3 100644
48435 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48436 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48437 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48438
48439 DBGPR("-->%s\n", __func__);
48440
48441 - pdata->hw_if.read_mmc_stats(pdata);
48442 + pdata->hw_if->read_mmc_stats(pdata);
48443 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48444 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48445 *data++ = *(u64 *)stat;
48446 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48447 struct ethtool_coalesce *ec)
48448 {
48449 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48450 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48451 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48452 unsigned int riwt;
48453
48454 DBGPR("-->xgbe_get_coalesce\n");
48455 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48456 struct ethtool_coalesce *ec)
48457 {
48458 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48459 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48460 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48461 unsigned int rx_frames, rx_riwt, rx_usecs;
48462 unsigned int tx_frames, tx_usecs;
48463
48464 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48465 index bdf9cfa..340aea1 100644
48466 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48467 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48468 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48469 DBGPR("<--xgbe_default_config\n");
48470 }
48471
48472 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48473 -{
48474 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48475 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48476 -}
48477 -
48478 static int xgbe_probe(struct platform_device *pdev)
48479 {
48480 struct xgbe_prv_data *pdata;
48481 @@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48482 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48483
48484 /* Set all the function pointers */
48485 - xgbe_init_all_fptrs(pdata);
48486 - hw_if = &pdata->hw_if;
48487 - desc_if = &pdata->desc_if;
48488 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48489 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
48490
48491 /* Issue software reset to device */
48492 hw_if->exit(pdata);
48493 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48494 index 6d2221e..47d1325 100644
48495 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48496 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48497 @@ -127,7 +127,7 @@
48498 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48499 {
48500 struct xgbe_prv_data *pdata = mii->priv;
48501 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48502 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48503 int mmd_data;
48504
48505 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48506 @@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48507 u16 mmd_val)
48508 {
48509 struct xgbe_prv_data *pdata = mii->priv;
48510 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48511 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48512 int mmd_data = mmd_val;
48513
48514 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48515 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48516 index 37e64cf..c3b61cf 100644
48517 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48518 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48519 @@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48520 tstamp_cc);
48521 u64 nsec;
48522
48523 - nsec = pdata->hw_if.get_tstamp_time(pdata);
48524 + nsec = pdata->hw_if->get_tstamp_time(pdata);
48525
48526 return nsec;
48527 }
48528 @@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48529
48530 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48531
48532 - pdata->hw_if.update_tstamp_addend(pdata, addend);
48533 + pdata->hw_if->update_tstamp_addend(pdata, addend);
48534
48535 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48536
48537 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48538 index e9fe6e6..875fbaf 100644
48539 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48540 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48541 @@ -585,8 +585,8 @@ struct xgbe_prv_data {
48542
48543 int irq_number;
48544
48545 - struct xgbe_hw_if hw_if;
48546 - struct xgbe_desc_if desc_if;
48547 + const struct xgbe_hw_if *hw_if;
48548 + const struct xgbe_desc_if *desc_if;
48549
48550 /* AXI DMA settings */
48551 unsigned int axdomain;
48552 @@ -699,6 +699,9 @@ struct xgbe_prv_data {
48553 #endif
48554 };
48555
48556 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48557 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48558 +
48559 /* Function prototypes*/
48560
48561 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48562 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48563 index 571427c..e9fe9e7 100644
48564 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48565 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48566 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48567 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48568 {
48569 /* RX_MODE controlling object */
48570 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48571 + bnx2x_init_rx_mode_obj(bp);
48572
48573 /* multicast configuration controlling object */
48574 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48575 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48576 index b193604..8873bfd 100644
48577 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48578 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48579 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48580 return rc;
48581 }
48582
48583 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48584 - struct bnx2x_rx_mode_obj *o)
48585 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48586 {
48587 if (CHIP_IS_E1x(bp)) {
48588 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48589 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48590 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48591 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48592 } else {
48593 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48594 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48595 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48596 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48597 }
48598 }
48599
48600 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48601 index 718ecd2..2183b2f 100644
48602 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48603 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48604 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48605
48606 /********************* RX MODE ****************/
48607
48608 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48609 - struct bnx2x_rx_mode_obj *o);
48610 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48611
48612 /**
48613 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48614 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48615 index 31c9f82..e65e986 100644
48616 --- a/drivers/net/ethernet/broadcom/tg3.h
48617 +++ b/drivers/net/ethernet/broadcom/tg3.h
48618 @@ -150,6 +150,7 @@
48619 #define CHIPREV_ID_5750_A0 0x4000
48620 #define CHIPREV_ID_5750_A1 0x4001
48621 #define CHIPREV_ID_5750_A3 0x4003
48622 +#define CHIPREV_ID_5750_C1 0x4201
48623 #define CHIPREV_ID_5750_C2 0x4202
48624 #define CHIPREV_ID_5752_A0_HW 0x5000
48625 #define CHIPREV_ID_5752_A0 0x6000
48626 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48627 index 13f9636..228040f 100644
48628 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48629 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48630 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48631 }
48632
48633 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48634 - bna_cb_ioceth_enable,
48635 - bna_cb_ioceth_disable,
48636 - bna_cb_ioceth_hbfail,
48637 - bna_cb_ioceth_reset
48638 + .enable_cbfn = bna_cb_ioceth_enable,
48639 + .disable_cbfn = bna_cb_ioceth_disable,
48640 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48641 + .reset_cbfn = bna_cb_ioceth_reset
48642 };
48643
48644 static void bna_attr_init(struct bna_ioceth *ioceth)
48645 diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
48646 index ffc92a4..40edc77 100644
48647 --- a/drivers/net/ethernet/brocade/bna/bnad.c
48648 +++ b/drivers/net/ethernet/brocade/bna/bnad.c
48649 @@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48650
48651 len = (vec == nvecs) ?
48652 last_fraglen : unmap->vector.len;
48653 + skb->truesize += unmap->vector.len;
48654 totlen += len;
48655
48656 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
48657 @@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48658
48659 skb->len += totlen;
48660 skb->data_len += totlen;
48661 - skb->truesize += totlen;
48662 }
48663
48664 static inline void
48665 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48666 index 8cffcdf..aadf043 100644
48667 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48668 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48669 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48670 */
48671 struct l2t_skb_cb {
48672 arp_failure_handler_func arp_failure_handler;
48673 -};
48674 +} __no_const;
48675
48676 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48677
48678 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48679 index 9f5f3c3..86d21a6 100644
48680 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48681 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48682 @@ -2359,7 +2359,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48683
48684 int i;
48685 struct adapter *ap = netdev2adap(dev);
48686 - static const unsigned int *reg_ranges;
48687 + const unsigned int *reg_ranges;
48688 int arr_size = 0, buf_size = 0;
48689
48690 if (is_t4(ap->params.chip)) {
48691 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48692 index cf8b6ff..274271e 100644
48693 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48694 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48695 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48696 for (i=0; i<ETH_ALEN; i++) {
48697 tmp.addr[i] = dev->dev_addr[i];
48698 }
48699 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48700 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48701 break;
48702
48703 case DE4X5_SET_HWADDR: /* Set the hardware address */
48704 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48705 spin_lock_irqsave(&lp->lock, flags);
48706 memcpy(&statbuf, &lp->pktStats, ioc->len);
48707 spin_unlock_irqrestore(&lp->lock, flags);
48708 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48709 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48710 return -EFAULT;
48711 break;
48712 }
48713 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48714 index 93ff8ef..39c64dd 100644
48715 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48716 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48717 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48718
48719 if (wrapped)
48720 newacc += 65536;
48721 - ACCESS_ONCE(*acc) = newacc;
48722 + ACCESS_ONCE_RW(*acc) = newacc;
48723 }
48724
48725 static void populate_erx_stats(struct be_adapter *adapter,
48726 @@ -4286,6 +4286,9 @@ static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh)
48727 if (nla_type(attr) != IFLA_BRIDGE_MODE)
48728 continue;
48729
48730 + if (nla_len(attr) < sizeof(mode))
48731 + return -EINVAL;
48732 +
48733 mode = nla_get_u16(attr);
48734 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
48735 return -EINVAL;
48736 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48737 index c77fa4a..7fd42fc 100644
48738 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48739 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48740 @@ -30,6 +30,8 @@
48741 #include <linux/netdevice.h>
48742 #include <linux/phy.h>
48743 #include <linux/platform_device.h>
48744 +#include <linux/interrupt.h>
48745 +#include <linux/irqreturn.h>
48746 #include <net/ip.h>
48747
48748 #include "ftgmac100.h"
48749 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48750 index 4ff1adc..0ea6bf4 100644
48751 --- a/drivers/net/ethernet/faraday/ftmac100.c
48752 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48753 @@ -31,6 +31,8 @@
48754 #include <linux/module.h>
48755 #include <linux/netdevice.h>
48756 #include <linux/platform_device.h>
48757 +#include <linux/interrupt.h>
48758 +#include <linux/irqreturn.h>
48759
48760 #include "ftmac100.h"
48761
48762 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48763 index 537b621..07f87ce 100644
48764 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48765 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48766 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48767 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48768
48769 /* Update the base adjustement value. */
48770 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48771 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48772 smp_mb(); /* Force the above update. */
48773 }
48774
48775 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48776 index e82821f..c7dd0af 100644
48777 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48778 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48779 @@ -7789,6 +7789,9 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
48780 if (nla_type(attr) != IFLA_BRIDGE_MODE)
48781 continue;
48782
48783 + if (nla_len(attr) < sizeof(mode))
48784 + return -EINVAL;
48785 +
48786 mode = nla_get_u16(attr);
48787 if (mode == BRIDGE_MODE_VEPA) {
48788 reg = 0;
48789 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48790 index 5fd4b52..87aa34b 100644
48791 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48792 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48793 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48794 }
48795
48796 /* update the base incval used to calculate frequency adjustment */
48797 - ACCESS_ONCE(adapter->base_incval) = incval;
48798 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48799 smp_mb();
48800
48801 /* need lock to prevent incorrect read while modifying cyclecounter */
48802 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48803 index c14d4d8..66da603 100644
48804 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48805 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48806 @@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
48807 struct ixgbe_hw *hw = &adapter->hw;
48808 u32 regval;
48809
48810 + if (vf >= adapter->num_vfs)
48811 + return -EINVAL;
48812 +
48813 adapter->vfinfo[vf].spoofchk_enabled = setting;
48814
48815 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
48816 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48817 index 2bbd01f..e8baa64 100644
48818 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48819 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48820 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48821 struct __vxge_hw_fifo *fifo;
48822 struct vxge_hw_fifo_config *config;
48823 u32 txdl_size, txdl_per_memblock;
48824 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48825 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48826 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48827 + };
48828 +
48829 struct __vxge_hw_virtualpath *vpath;
48830
48831 if ((vp == NULL) || (attr == NULL)) {
48832 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48833 goto exit;
48834 }
48835
48836 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48837 -
48838 fifo->mempool =
48839 __vxge_hw_mempool_create(vpath->hldev,
48840 fifo->config->memblock_size,
48841 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48842 index 3172cdf..d01ab34 100644
48843 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48844 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48845 @@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48846 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48847 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48848 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48849 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48850 + pax_open_kernel();
48851 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48852 + pax_close_kernel();
48853 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48854 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48855 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48856 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48857 index be7d7a6..a8983f8 100644
48858 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48859 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48860 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48861 case QLCNIC_NON_PRIV_FUNC:
48862 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48863 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48864 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48865 + pax_open_kernel();
48866 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48867 + pax_close_kernel();
48868 break;
48869 case QLCNIC_PRIV_FUNC:
48870 ahw->op_mode = QLCNIC_PRIV_FUNC;
48871 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48872 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48873 + pax_open_kernel();
48874 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48875 + pax_close_kernel();
48876 break;
48877 case QLCNIC_MGMT_FUNC:
48878 ahw->op_mode = QLCNIC_MGMT_FUNC;
48879 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48880 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48881 + pax_open_kernel();
48882 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48883 + pax_close_kernel();
48884 break;
48885 default:
48886 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48887 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48888 index c9f57fb..208bdc1 100644
48889 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48890 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48891 @@ -1285,7 +1285,7 @@ flash_temp:
48892 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48893 {
48894 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48895 - static const struct qlcnic_dump_operations *fw_dump_ops;
48896 + const struct qlcnic_dump_operations *fw_dump_ops;
48897 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48898 u32 entry_offset, dump, no_entries, buf_offset = 0;
48899 int i, k, ops_cnt, ops_index, dump_size = 0;
48900 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48901 index 0921302..927f761 100644
48902 --- a/drivers/net/ethernet/realtek/r8169.c
48903 +++ b/drivers/net/ethernet/realtek/r8169.c
48904 @@ -744,22 +744,22 @@ struct rtl8169_private {
48905 struct mdio_ops {
48906 void (*write)(struct rtl8169_private *, int, int);
48907 int (*read)(struct rtl8169_private *, int);
48908 - } mdio_ops;
48909 + } __no_const mdio_ops;
48910
48911 struct pll_power_ops {
48912 void (*down)(struct rtl8169_private *);
48913 void (*up)(struct rtl8169_private *);
48914 - } pll_power_ops;
48915 + } __no_const pll_power_ops;
48916
48917 struct jumbo_ops {
48918 void (*enable)(struct rtl8169_private *);
48919 void (*disable)(struct rtl8169_private *);
48920 - } jumbo_ops;
48921 + } __no_const jumbo_ops;
48922
48923 struct csi_ops {
48924 void (*write)(struct rtl8169_private *, int, int);
48925 u32 (*read)(struct rtl8169_private *, int);
48926 - } csi_ops;
48927 + } __no_const csi_ops;
48928
48929 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48930 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48931 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48932 index 6b861e3..204ac86 100644
48933 --- a/drivers/net/ethernet/sfc/ptp.c
48934 +++ b/drivers/net/ethernet/sfc/ptp.c
48935 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48936 ptp->start.dma_addr);
48937
48938 /* Clear flag that signals MC ready */
48939 - ACCESS_ONCE(*start) = 0;
48940 + ACCESS_ONCE_RW(*start) = 0;
48941 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48942 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48943 EFX_BUG_ON_PARANOID(rc);
48944 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48945 index 08c483b..2c4a553 100644
48946 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48947 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48948 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48949
48950 writel(value, ioaddr + MMC_CNTRL);
48951
48952 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48953 - MMC_CNTRL, value);
48954 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48955 +// MMC_CNTRL, value);
48956 }
48957
48958 /* To mask all all interrupts.*/
48959 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48960 index d5e07de..e3bf20a 100644
48961 --- a/drivers/net/hyperv/hyperv_net.h
48962 +++ b/drivers/net/hyperv/hyperv_net.h
48963 @@ -171,7 +171,7 @@ struct rndis_device {
48964 enum rndis_device_state state;
48965 bool link_state;
48966 bool link_change;
48967 - atomic_t new_req_id;
48968 + atomic_unchecked_t new_req_id;
48969
48970 spinlock_t request_lock;
48971 struct list_head req_list;
48972 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48973 index 2b86f0b..ecc996f 100644
48974 --- a/drivers/net/hyperv/rndis_filter.c
48975 +++ b/drivers/net/hyperv/rndis_filter.c
48976 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48977 * template
48978 */
48979 set = &rndis_msg->msg.set_req;
48980 - set->req_id = atomic_inc_return(&dev->new_req_id);
48981 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48982
48983 /* Add to the request list */
48984 spin_lock_irqsave(&dev->request_lock, flags);
48985 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48986
48987 /* Setup the rndis set */
48988 halt = &request->request_msg.msg.halt_req;
48989 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48990 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48991
48992 /* Ignore return since this msg is optional. */
48993 rndis_filter_send_request(dev, request);
48994 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48995 index 6cbc56a..5f7e6c8 100644
48996 --- a/drivers/net/ieee802154/fakehard.c
48997 +++ b/drivers/net/ieee802154/fakehard.c
48998 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48999 phy->transmit_power = 0xbf;
49000
49001 dev->netdev_ops = &fake_ops;
49002 - dev->ml_priv = &fake_mlme;
49003 + dev->ml_priv = (void *)&fake_mlme;
49004
49005 priv = netdev_priv(dev);
49006 priv->phy = phy;
49007 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
49008 index d2d4a3d..8b7a1be 100644
49009 --- a/drivers/net/ifb.c
49010 +++ b/drivers/net/ifb.c
49011 @@ -252,7 +252,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
49012 return 0;
49013 }
49014
49015 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
49016 +static struct rtnl_link_ops ifb_link_ops = {
49017 .kind = "ifb",
49018 .priv_size = sizeof(struct ifb_private),
49019 .setup = ifb_setup,
49020 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49021 index 5f17ad0..e0463c8 100644
49022 --- a/drivers/net/macvlan.c
49023 +++ b/drivers/net/macvlan.c
49024 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49025 free_nskb:
49026 kfree_skb(nskb);
49027 err:
49028 - atomic_long_inc(&skb->dev->rx_dropped);
49029 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49030 }
49031
49032 /* called under rcu_read_lock() from netif_receive_skb */
49033 @@ -1150,13 +1150,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49034 int macvlan_link_register(struct rtnl_link_ops *ops)
49035 {
49036 /* common fields */
49037 - ops->priv_size = sizeof(struct macvlan_dev);
49038 - ops->validate = macvlan_validate;
49039 - ops->maxtype = IFLA_MACVLAN_MAX;
49040 - ops->policy = macvlan_policy;
49041 - ops->changelink = macvlan_changelink;
49042 - ops->get_size = macvlan_get_size;
49043 - ops->fill_info = macvlan_fill_info;
49044 + pax_open_kernel();
49045 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49046 + *(void **)&ops->validate = macvlan_validate;
49047 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49048 + *(const void **)&ops->policy = macvlan_policy;
49049 + *(void **)&ops->changelink = macvlan_changelink;
49050 + *(void **)&ops->get_size = macvlan_get_size;
49051 + *(void **)&ops->fill_info = macvlan_fill_info;
49052 + pax_close_kernel();
49053
49054 return rtnl_link_register(ops);
49055 };
49056 @@ -1236,7 +1238,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49057 return NOTIFY_DONE;
49058 }
49059
49060 -static struct notifier_block macvlan_notifier_block __read_mostly = {
49061 +static struct notifier_block macvlan_notifier_block = {
49062 .notifier_call = macvlan_device_event,
49063 };
49064
49065 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49066 index 07c942b..bce8b8a 100644
49067 --- a/drivers/net/macvtap.c
49068 +++ b/drivers/net/macvtap.c
49069 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
49070 dev->tx_queue_len = TUN_READQ_SIZE;
49071 }
49072
49073 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
49074 +static struct rtnl_link_ops macvtap_link_ops = {
49075 .kind = "macvtap",
49076 .setup = macvtap_setup,
49077 .newlink = macvtap_newlink,
49078 @@ -1023,7 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49079 }
49080
49081 ret = 0;
49082 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49083 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49084 put_user(q->flags, &ifr->ifr_flags))
49085 ret = -EFAULT;
49086 macvtap_put_vlan(vlan);
49087 @@ -1193,7 +1193,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49088 return NOTIFY_DONE;
49089 }
49090
49091 -static struct notifier_block macvtap_notifier_block __read_mostly = {
49092 +static struct notifier_block macvtap_notifier_block = {
49093 .notifier_call = macvtap_device_event,
49094 };
49095
49096 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
49097 index 34924df..a747360 100644
49098 --- a/drivers/net/nlmon.c
49099 +++ b/drivers/net/nlmon.c
49100 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
49101 return 0;
49102 }
49103
49104 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
49105 +static struct rtnl_link_ops nlmon_link_ops = {
49106 .kind = "nlmon",
49107 .priv_size = sizeof(struct nlmon),
49108 .setup = nlmon_setup,
49109 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49110 index 17ecdd6..79ad848 100644
49111 --- a/drivers/net/ppp/ppp_generic.c
49112 +++ b/drivers/net/ppp/ppp_generic.c
49113 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49114 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
49115 struct ppp_stats stats;
49116 struct ppp_comp_stats cstats;
49117 - char *vers;
49118
49119 switch (cmd) {
49120 case SIOCGPPPSTATS:
49121 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49122 break;
49123
49124 case SIOCGPPPVER:
49125 - vers = PPP_VERSION;
49126 - if (copy_to_user(addr, vers, strlen(vers) + 1))
49127 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
49128 break;
49129 err = 0;
49130 break;
49131 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49132 index 079f7ad..b2a2bfa7 100644
49133 --- a/drivers/net/slip/slhc.c
49134 +++ b/drivers/net/slip/slhc.c
49135 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49136 register struct tcphdr *thp;
49137 register struct iphdr *ip;
49138 register struct cstate *cs;
49139 - int len, hdrlen;
49140 + long len, hdrlen;
49141 unsigned char *cp = icp;
49142
49143 /* We've got a compressed packet; read the change byte */
49144 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49145 index 1f76c2ea..997760b 100644
49146 --- a/drivers/net/team/team.c
49147 +++ b/drivers/net/team/team.c
49148 @@ -2072,7 +2072,7 @@ static unsigned int team_get_num_rx_queues(void)
49149 return TEAM_DEFAULT_NUM_RX_QUEUES;
49150 }
49151
49152 -static struct rtnl_link_ops team_link_ops __read_mostly = {
49153 +static struct rtnl_link_ops team_link_ops = {
49154 .kind = DRV_NAME,
49155 .priv_size = sizeof(struct team),
49156 .setup = team_setup,
49157 @@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
49158 return NOTIFY_DONE;
49159 }
49160
49161 -static struct notifier_block team_notifier_block __read_mostly = {
49162 +static struct notifier_block team_notifier_block = {
49163 .notifier_call = team_device_event,
49164 };
49165
49166 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49167 index d965e8a..6226000 100644
49168 --- a/drivers/net/tun.c
49169 +++ b/drivers/net/tun.c
49170 @@ -1414,7 +1414,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
49171 return -EINVAL;
49172 }
49173
49174 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
49175 +static struct rtnl_link_ops tun_link_ops = {
49176 .kind = DRV_NAME,
49177 .priv_size = sizeof(struct tun_struct),
49178 .setup = tun_setup,
49179 @@ -1861,7 +1861,7 @@ unlock:
49180 }
49181
49182 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49183 - unsigned long arg, int ifreq_len)
49184 + unsigned long arg, size_t ifreq_len)
49185 {
49186 struct tun_file *tfile = file->private_data;
49187 struct tun_struct *tun;
49188 @@ -1874,6 +1874,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49189 unsigned int ifindex;
49190 int ret;
49191
49192 + if (ifreq_len > sizeof ifr)
49193 + return -EFAULT;
49194 +
49195 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49196 if (copy_from_user(&ifr, argp, ifreq_len))
49197 return -EFAULT;
49198 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49199 index babda7d..e40c90a 100644
49200 --- a/drivers/net/usb/hso.c
49201 +++ b/drivers/net/usb/hso.c
49202 @@ -71,7 +71,7 @@
49203 #include <asm/byteorder.h>
49204 #include <linux/serial_core.h>
49205 #include <linux/serial.h>
49206 -
49207 +#include <asm/local.h>
49208
49209 #define MOD_AUTHOR "Option Wireless"
49210 #define MOD_DESCRIPTION "USB High Speed Option driver"
49211 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49212 struct urb *urb;
49213
49214 urb = serial->rx_urb[0];
49215 - if (serial->port.count > 0) {
49216 + if (atomic_read(&serial->port.count) > 0) {
49217 count = put_rxbuf_data(urb, serial);
49218 if (count == -1)
49219 return;
49220 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49221 DUMP1(urb->transfer_buffer, urb->actual_length);
49222
49223 /* Anyone listening? */
49224 - if (serial->port.count == 0)
49225 + if (atomic_read(&serial->port.count) == 0)
49226 return;
49227
49228 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49229 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49230 tty_port_tty_set(&serial->port, tty);
49231
49232 /* check for port already opened, if not set the termios */
49233 - serial->port.count++;
49234 - if (serial->port.count == 1) {
49235 + if (atomic_inc_return(&serial->port.count) == 1) {
49236 serial->rx_state = RX_IDLE;
49237 /* Force default termio settings */
49238 _hso_serial_set_termios(tty, NULL);
49239 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49240 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49241 if (result) {
49242 hso_stop_serial_device(serial->parent);
49243 - serial->port.count--;
49244 + atomic_dec(&serial->port.count);
49245 kref_put(&serial->parent->ref, hso_serial_ref_free);
49246 }
49247 } else {
49248 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49249
49250 /* reset the rts and dtr */
49251 /* do the actual close */
49252 - serial->port.count--;
49253 + atomic_dec(&serial->port.count);
49254
49255 - if (serial->port.count <= 0) {
49256 - serial->port.count = 0;
49257 + if (atomic_read(&serial->port.count) <= 0) {
49258 + atomic_set(&serial->port.count, 0);
49259 tty_port_tty_set(&serial->port, NULL);
49260 if (!usb_gone)
49261 hso_stop_serial_device(serial->parent);
49262 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49263
49264 /* the actual setup */
49265 spin_lock_irqsave(&serial->serial_lock, flags);
49266 - if (serial->port.count)
49267 + if (atomic_read(&serial->port.count))
49268 _hso_serial_set_termios(tty, old);
49269 else
49270 tty->termios = *old;
49271 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
49272 D1("Pending read interrupt on port %d\n", i);
49273 spin_lock(&serial->serial_lock);
49274 if (serial->rx_state == RX_IDLE &&
49275 - serial->port.count > 0) {
49276 + atomic_read(&serial->port.count) > 0) {
49277 /* Setup and send a ctrl req read on
49278 * port i */
49279 if (!serial->rx_urb_filled[0]) {
49280 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
49281 /* Start all serial ports */
49282 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49283 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49284 - if (dev2ser(serial_table[i])->port.count) {
49285 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49286 result =
49287 hso_start_serial_device(serial_table[i], GFP_NOIO);
49288 hso_kick_transmit(dev2ser(serial_table[i]));
49289 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49290 index 604ef21..d1f49a1 100644
49291 --- a/drivers/net/usb/r8152.c
49292 +++ b/drivers/net/usb/r8152.c
49293 @@ -575,7 +575,7 @@ struct r8152 {
49294 void (*up)(struct r8152 *);
49295 void (*down)(struct r8152 *);
49296 void (*unload)(struct r8152 *);
49297 - } rtl_ops;
49298 + } __no_const rtl_ops;
49299
49300 int intr_interval;
49301 u32 saved_wolopts;
49302 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49303 index a2515887..6d13233 100644
49304 --- a/drivers/net/usb/sierra_net.c
49305 +++ b/drivers/net/usb/sierra_net.c
49306 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49307 /* atomic counter partially included in MAC address to make sure 2 devices
49308 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49309 */
49310 -static atomic_t iface_counter = ATOMIC_INIT(0);
49311 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49312
49313 /*
49314 * SYNC Timer Delay definition used to set the expiry time
49315 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49316 dev->net->netdev_ops = &sierra_net_device_ops;
49317
49318 /* change MAC addr to include, ifacenum, and to be unique */
49319 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49320 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49321 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49322
49323 /* we will have to manufacture ethernet headers, prepare template */
49324 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49325 index 59caa06..de191b3 100644
49326 --- a/drivers/net/virtio_net.c
49327 +++ b/drivers/net/virtio_net.c
49328 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
49329 #define RECEIVE_AVG_WEIGHT 64
49330
49331 /* Minimum alignment for mergeable packet buffers. */
49332 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49333 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49334
49335 #define VIRTNET_DRIVER_VERSION "1.0.0"
49336
49337 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49338 index 2aa3a8d..d15e3c4 100644
49339 --- a/drivers/net/vxlan.c
49340 +++ b/drivers/net/vxlan.c
49341 @@ -2758,7 +2758,7 @@ nla_put_failure:
49342 return -EMSGSIZE;
49343 }
49344
49345 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49346 +static struct rtnl_link_ops vxlan_link_ops = {
49347 .kind = "vxlan",
49348 .maxtype = IFLA_VXLAN_MAX,
49349 .policy = vxlan_policy,
49350 @@ -2805,7 +2805,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49351 return NOTIFY_DONE;
49352 }
49353
49354 -static struct notifier_block vxlan_notifier_block __read_mostly = {
49355 +static struct notifier_block vxlan_notifier_block = {
49356 .notifier_call = vxlan_lowerdev_event,
49357 };
49358
49359 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49360 index 5920c99..ff2e4a5 100644
49361 --- a/drivers/net/wan/lmc/lmc_media.c
49362 +++ b/drivers/net/wan/lmc/lmc_media.c
49363 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49364 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49365
49366 lmc_media_t lmc_ds3_media = {
49367 - lmc_ds3_init, /* special media init stuff */
49368 - lmc_ds3_default, /* reset to default state */
49369 - lmc_ds3_set_status, /* reset status to state provided */
49370 - lmc_dummy_set_1, /* set clock source */
49371 - lmc_dummy_set2_1, /* set line speed */
49372 - lmc_ds3_set_100ft, /* set cable length */
49373 - lmc_ds3_set_scram, /* set scrambler */
49374 - lmc_ds3_get_link_status, /* get link status */
49375 - lmc_dummy_set_1, /* set link status */
49376 - lmc_ds3_set_crc_length, /* set CRC length */
49377 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49378 - lmc_ds3_watchdog
49379 + .init = lmc_ds3_init, /* special media init stuff */
49380 + .defaults = lmc_ds3_default, /* reset to default state */
49381 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
49382 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49383 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49384 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49385 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49386 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49387 + .set_link_status = lmc_dummy_set_1, /* set link status */
49388 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49389 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49390 + .watchdog = lmc_ds3_watchdog
49391 };
49392
49393 lmc_media_t lmc_hssi_media = {
49394 - lmc_hssi_init, /* special media init stuff */
49395 - lmc_hssi_default, /* reset to default state */
49396 - lmc_hssi_set_status, /* reset status to state provided */
49397 - lmc_hssi_set_clock, /* set clock source */
49398 - lmc_dummy_set2_1, /* set line speed */
49399 - lmc_dummy_set_1, /* set cable length */
49400 - lmc_dummy_set_1, /* set scrambler */
49401 - lmc_hssi_get_link_status, /* get link status */
49402 - lmc_hssi_set_link_status, /* set link status */
49403 - lmc_hssi_set_crc_length, /* set CRC length */
49404 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49405 - lmc_hssi_watchdog
49406 + .init = lmc_hssi_init, /* special media init stuff */
49407 + .defaults = lmc_hssi_default, /* reset to default state */
49408 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49409 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49410 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49411 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49412 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49413 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49414 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49415 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49416 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49417 + .watchdog = lmc_hssi_watchdog
49418 };
49419
49420 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49421 - lmc_ssi_default, /* reset to default state */
49422 - lmc_ssi_set_status, /* reset status to state provided */
49423 - lmc_ssi_set_clock, /* set clock source */
49424 - lmc_ssi_set_speed, /* set line speed */
49425 - lmc_dummy_set_1, /* set cable length */
49426 - lmc_dummy_set_1, /* set scrambler */
49427 - lmc_ssi_get_link_status, /* get link status */
49428 - lmc_ssi_set_link_status, /* set link status */
49429 - lmc_ssi_set_crc_length, /* set CRC length */
49430 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49431 - lmc_ssi_watchdog
49432 +lmc_media_t lmc_ssi_media = {
49433 + .init = lmc_ssi_init, /* special media init stuff */
49434 + .defaults = lmc_ssi_default, /* reset to default state */
49435 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49436 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49437 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49438 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49439 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49440 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49441 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49442 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49443 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49444 + .watchdog = lmc_ssi_watchdog
49445 };
49446
49447 lmc_media_t lmc_t1_media = {
49448 - lmc_t1_init, /* special media init stuff */
49449 - lmc_t1_default, /* reset to default state */
49450 - lmc_t1_set_status, /* reset status to state provided */
49451 - lmc_t1_set_clock, /* set clock source */
49452 - lmc_dummy_set2_1, /* set line speed */
49453 - lmc_dummy_set_1, /* set cable length */
49454 - lmc_dummy_set_1, /* set scrambler */
49455 - lmc_t1_get_link_status, /* get link status */
49456 - lmc_dummy_set_1, /* set link status */
49457 - lmc_t1_set_crc_length, /* set CRC length */
49458 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49459 - lmc_t1_watchdog
49460 + .init = lmc_t1_init, /* special media init stuff */
49461 + .defaults = lmc_t1_default, /* reset to default state */
49462 + .set_status = lmc_t1_set_status, /* reset status to state provided */
49463 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
49464 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49465 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49466 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49467 + .get_link_status = lmc_t1_get_link_status, /* get link status */
49468 + .set_link_status = lmc_dummy_set_1, /* set link status */
49469 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49470 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49471 + .watchdog = lmc_t1_watchdog
49472 };
49473
49474 static void
49475 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49476 index feacc3b..5bac0de 100644
49477 --- a/drivers/net/wan/z85230.c
49478 +++ b/drivers/net/wan/z85230.c
49479 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49480
49481 struct z8530_irqhandler z8530_sync =
49482 {
49483 - z8530_rx,
49484 - z8530_tx,
49485 - z8530_status
49486 + .rx = z8530_rx,
49487 + .tx = z8530_tx,
49488 + .status = z8530_status
49489 };
49490
49491 EXPORT_SYMBOL(z8530_sync);
49492 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49493 }
49494
49495 static struct z8530_irqhandler z8530_dma_sync = {
49496 - z8530_dma_rx,
49497 - z8530_dma_tx,
49498 - z8530_dma_status
49499 + .rx = z8530_dma_rx,
49500 + .tx = z8530_dma_tx,
49501 + .status = z8530_dma_status
49502 };
49503
49504 static struct z8530_irqhandler z8530_txdma_sync = {
49505 - z8530_rx,
49506 - z8530_dma_tx,
49507 - z8530_dma_status
49508 + .rx = z8530_rx,
49509 + .tx = z8530_dma_tx,
49510 + .status = z8530_dma_status
49511 };
49512
49513 /**
49514 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49515
49516 struct z8530_irqhandler z8530_nop=
49517 {
49518 - z8530_rx_clear,
49519 - z8530_tx_clear,
49520 - z8530_status_clear
49521 + .rx = z8530_rx_clear,
49522 + .tx = z8530_tx_clear,
49523 + .status = z8530_status_clear
49524 };
49525
49526
49527 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49528 index 0b60295..b8bfa5b 100644
49529 --- a/drivers/net/wimax/i2400m/rx.c
49530 +++ b/drivers/net/wimax/i2400m/rx.c
49531 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49532 if (i2400m->rx_roq == NULL)
49533 goto error_roq_alloc;
49534
49535 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49536 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49537 GFP_KERNEL);
49538 if (rd == NULL) {
49539 result = -ENOMEM;
49540 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49541 index e71a2ce..2268d61 100644
49542 --- a/drivers/net/wireless/airo.c
49543 +++ b/drivers/net/wireless/airo.c
49544 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49545 struct airo_info *ai = dev->ml_priv;
49546 int ridcode;
49547 int enabled;
49548 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49549 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49550 unsigned char *iobuf;
49551
49552 /* Only super-user can write RIDs */
49553 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49554 index da92bfa..5a9001a 100644
49555 --- a/drivers/net/wireless/at76c50x-usb.c
49556 +++ b/drivers/net/wireless/at76c50x-usb.c
49557 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49558 }
49559
49560 /* Convert timeout from the DFU status to jiffies */
49561 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49562 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49563 {
49564 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49565 | (s->poll_timeout[1] << 8)
49566 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49567 index 5fdc40d..3975205 100644
49568 --- a/drivers/net/wireless/ath/ath10k/htc.c
49569 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49570 @@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49571 /* registered target arrival callback from the HIF layer */
49572 int ath10k_htc_init(struct ath10k *ar)
49573 {
49574 - struct ath10k_hif_cb htc_callbacks;
49575 + static struct ath10k_hif_cb htc_callbacks = {
49576 + .rx_completion = ath10k_htc_rx_completion_handler,
49577 + .tx_completion = ath10k_htc_tx_completion_handler,
49578 + };
49579 struct ath10k_htc_ep *ep = NULL;
49580 struct ath10k_htc *htc = &ar->htc;
49581
49582 @@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
49583 ath10k_htc_reset_endpoint_states(htc);
49584
49585 /* setup HIF layer callbacks */
49586 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49587 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49588 htc->ar = ar;
49589
49590 /* Get HIF default pipe for HTC message exchange */
49591 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49592 index 4716d33..a688310 100644
49593 --- a/drivers/net/wireless/ath/ath10k/htc.h
49594 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49595 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
49596
49597 struct ath10k_htc_ops {
49598 void (*target_send_suspend_complete)(struct ath10k *ar);
49599 -};
49600 +} __no_const;
49601
49602 struct ath10k_htc_ep_ops {
49603 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49604 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49605 void (*ep_tx_credits)(struct ath10k *);
49606 -};
49607 +} __no_const;
49608
49609 /* service connection information */
49610 struct ath10k_htc_svc_conn_req {
49611 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49612 index 59af9f9..5f3564f 100644
49613 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49614 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49615 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49616 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49617 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49618
49619 - ACCESS_ONCE(ads->ds_link) = i->link;
49620 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49621 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49622 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49623
49624 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49625 ctl6 = SM(i->keytype, AR_EncrType);
49626 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49627
49628 if ((i->is_first || i->is_last) &&
49629 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49630 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49631 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49632 | set11nTries(i->rates, 1)
49633 | set11nTries(i->rates, 2)
49634 | set11nTries(i->rates, 3)
49635 | (i->dur_update ? AR_DurUpdateEna : 0)
49636 | SM(0, AR_BurstDur);
49637
49638 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49639 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49640 | set11nRate(i->rates, 1)
49641 | set11nRate(i->rates, 2)
49642 | set11nRate(i->rates, 3);
49643 } else {
49644 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49645 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49646 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49647 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49648 }
49649
49650 if (!i->is_first) {
49651 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49652 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49653 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49654 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49655 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49656 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49657 return;
49658 }
49659
49660 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49661 break;
49662 }
49663
49664 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49665 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49666 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49667 | SM(i->txpower, AR_XmitPower0)
49668 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49669 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49670 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49671 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49672
49673 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49674 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49675 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49676 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49677
49678 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49679 return;
49680
49681 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49682 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49683 | set11nPktDurRTSCTS(i->rates, 1);
49684
49685 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49686 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49687 | set11nPktDurRTSCTS(i->rates, 3);
49688
49689 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49690 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49691 | set11nRateFlags(i->rates, 1)
49692 | set11nRateFlags(i->rates, 2)
49693 | set11nRateFlags(i->rates, 3)
49694 | SM(i->rtscts_rate, AR_RTSCTSRate);
49695
49696 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49697 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49698 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49699 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49700 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49701 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49702 }
49703
49704 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49705 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49706 index 71e38e8..5ac96ca 100644
49707 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49708 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49709 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49710 (i->qcu << AR_TxQcuNum_S) | desc_len;
49711
49712 checksum += val;
49713 - ACCESS_ONCE(ads->info) = val;
49714 + ACCESS_ONCE_RW(ads->info) = val;
49715
49716 checksum += i->link;
49717 - ACCESS_ONCE(ads->link) = i->link;
49718 + ACCESS_ONCE_RW(ads->link) = i->link;
49719
49720 checksum += i->buf_addr[0];
49721 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49722 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49723 checksum += i->buf_addr[1];
49724 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49725 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49726 checksum += i->buf_addr[2];
49727 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49728 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49729 checksum += i->buf_addr[3];
49730 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49731 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49732
49733 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49734 - ACCESS_ONCE(ads->ctl3) = val;
49735 + ACCESS_ONCE_RW(ads->ctl3) = val;
49736 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49737 - ACCESS_ONCE(ads->ctl5) = val;
49738 + ACCESS_ONCE_RW(ads->ctl5) = val;
49739 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49740 - ACCESS_ONCE(ads->ctl7) = val;
49741 + ACCESS_ONCE_RW(ads->ctl7) = val;
49742 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49743 - ACCESS_ONCE(ads->ctl9) = val;
49744 + ACCESS_ONCE_RW(ads->ctl9) = val;
49745
49746 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49747 - ACCESS_ONCE(ads->ctl10) = checksum;
49748 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49749
49750 if (i->is_first || i->is_last) {
49751 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49752 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49753 | set11nTries(i->rates, 1)
49754 | set11nTries(i->rates, 2)
49755 | set11nTries(i->rates, 3)
49756 | (i->dur_update ? AR_DurUpdateEna : 0)
49757 | SM(0, AR_BurstDur);
49758
49759 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49760 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49761 | set11nRate(i->rates, 1)
49762 | set11nRate(i->rates, 2)
49763 | set11nRate(i->rates, 3);
49764 } else {
49765 - ACCESS_ONCE(ads->ctl13) = 0;
49766 - ACCESS_ONCE(ads->ctl14) = 0;
49767 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49768 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49769 }
49770
49771 ads->ctl20 = 0;
49772 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49773
49774 ctl17 = SM(i->keytype, AR_EncrType);
49775 if (!i->is_first) {
49776 - ACCESS_ONCE(ads->ctl11) = 0;
49777 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49778 - ACCESS_ONCE(ads->ctl15) = 0;
49779 - ACCESS_ONCE(ads->ctl16) = 0;
49780 - ACCESS_ONCE(ads->ctl17) = ctl17;
49781 - ACCESS_ONCE(ads->ctl18) = 0;
49782 - ACCESS_ONCE(ads->ctl19) = 0;
49783 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49784 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49785 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49786 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49787 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49788 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49789 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49790 return;
49791 }
49792
49793 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49794 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49795 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49796 | SM(i->txpower, AR_XmitPower0)
49797 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49798 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49799 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49800 ctl12 |= SM(val, AR_PAPRDChainMask);
49801
49802 - ACCESS_ONCE(ads->ctl12) = ctl12;
49803 - ACCESS_ONCE(ads->ctl17) = ctl17;
49804 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49805 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49806
49807 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49808 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49809 | set11nPktDurRTSCTS(i->rates, 1);
49810
49811 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49812 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49813 | set11nPktDurRTSCTS(i->rates, 3);
49814
49815 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49816 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49817 | set11nRateFlags(i->rates, 1)
49818 | set11nRateFlags(i->rates, 2)
49819 | set11nRateFlags(i->rates, 3)
49820 | SM(i->rtscts_rate, AR_RTSCTSRate);
49821
49822 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49823 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49824
49825 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49826 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49827 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49828 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49829 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49830 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49831 }
49832
49833 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49834 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49835 index 51b4ebe..d1929dd 100644
49836 --- a/drivers/net/wireless/ath/ath9k/hw.h
49837 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49838 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
49839
49840 /* ANI */
49841 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49842 -};
49843 +} __no_const;
49844
49845 /**
49846 * struct ath_spec_scan - parameters for Atheros spectral scan
49847 @@ -706,7 +706,7 @@ struct ath_hw_ops {
49848 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49849 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49850 #endif
49851 -};
49852 +} __no_const;
49853
49854 struct ath_nf_limits {
49855 s16 max;
49856 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49857 index 4b148bb..ac738fa 100644
49858 --- a/drivers/net/wireless/ath/ath9k/main.c
49859 +++ b/drivers/net/wireless/ath/ath9k/main.c
49860 @@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
49861 if (!ath9k_use_chanctx)
49862 return;
49863
49864 - ath9k_ops.hw_scan = ath9k_hw_scan;
49865 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49866 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49867 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49868 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49869 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49870 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49871 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49872 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49873 - ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49874 + pax_open_kernel();
49875 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49876 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49877 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49878 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49879 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49880 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49881 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49882 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49883 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49884 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49885 + pax_close_kernel();
49886 }
49887
49888 struct ieee80211_ops ath9k_ops = {
49889 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49890 index 92190da..f3a4c4c 100644
49891 --- a/drivers/net/wireless/b43/phy_lp.c
49892 +++ b/drivers/net/wireless/b43/phy_lp.c
49893 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49894 {
49895 struct ssb_bus *bus = dev->dev->sdev->bus;
49896
49897 - static const struct b206x_channel *chandata = NULL;
49898 + const struct b206x_channel *chandata = NULL;
49899 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49900 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49901 u16 old_comm15, scale;
49902 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49903 index dc1d20c..f7a4f06 100644
49904 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49905 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49906 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49907 */
49908 if (il3945_mod_params.disable_hw_scan) {
49909 D_INFO("Disabling hw_scan\n");
49910 - il3945_mac_ops.hw_scan = NULL;
49911 + pax_open_kernel();
49912 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49913 + pax_close_kernel();
49914 }
49915
49916 D_INFO("*** LOAD DRIVER ***\n");
49917 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49918 index 0ffb6ff..c0b7f0e 100644
49919 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49920 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49921 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49922 {
49923 struct iwl_priv *priv = file->private_data;
49924 char buf[64];
49925 - int buf_size;
49926 + size_t buf_size;
49927 u32 offset, len;
49928
49929 memset(buf, 0, sizeof(buf));
49930 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49931 struct iwl_priv *priv = file->private_data;
49932
49933 char buf[8];
49934 - int buf_size;
49935 + size_t buf_size;
49936 u32 reset_flag;
49937
49938 memset(buf, 0, sizeof(buf));
49939 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49940 {
49941 struct iwl_priv *priv = file->private_data;
49942 char buf[8];
49943 - int buf_size;
49944 + size_t buf_size;
49945 int ht40;
49946
49947 memset(buf, 0, sizeof(buf));
49948 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49949 {
49950 struct iwl_priv *priv = file->private_data;
49951 char buf[8];
49952 - int buf_size;
49953 + size_t buf_size;
49954 int value;
49955
49956 memset(buf, 0, sizeof(buf));
49957 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49958 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49959 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49960
49961 -static const char *fmt_value = " %-30s %10u\n";
49962 -static const char *fmt_hex = " %-30s 0x%02X\n";
49963 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49964 -static const char *fmt_header =
49965 +static const char fmt_value[] = " %-30s %10u\n";
49966 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49967 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49968 +static const char fmt_header[] =
49969 "%-32s current cumulative delta max\n";
49970
49971 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49972 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49973 {
49974 struct iwl_priv *priv = file->private_data;
49975 char buf[8];
49976 - int buf_size;
49977 + size_t buf_size;
49978 int clear;
49979
49980 memset(buf, 0, sizeof(buf));
49981 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49982 {
49983 struct iwl_priv *priv = file->private_data;
49984 char buf[8];
49985 - int buf_size;
49986 + size_t buf_size;
49987 int trace;
49988
49989 memset(buf, 0, sizeof(buf));
49990 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49991 {
49992 struct iwl_priv *priv = file->private_data;
49993 char buf[8];
49994 - int buf_size;
49995 + size_t buf_size;
49996 int missed;
49997
49998 memset(buf, 0, sizeof(buf));
49999 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50000
50001 struct iwl_priv *priv = file->private_data;
50002 char buf[8];
50003 - int buf_size;
50004 + size_t buf_size;
50005 int plcp;
50006
50007 memset(buf, 0, sizeof(buf));
50008 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50009
50010 struct iwl_priv *priv = file->private_data;
50011 char buf[8];
50012 - int buf_size;
50013 + size_t buf_size;
50014 int flush;
50015
50016 memset(buf, 0, sizeof(buf));
50017 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50018
50019 struct iwl_priv *priv = file->private_data;
50020 char buf[8];
50021 - int buf_size;
50022 + size_t buf_size;
50023 int rts;
50024
50025 if (!priv->cfg->ht_params)
50026 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50027 {
50028 struct iwl_priv *priv = file->private_data;
50029 char buf[8];
50030 - int buf_size;
50031 + size_t buf_size;
50032
50033 memset(buf, 0, sizeof(buf));
50034 buf_size = min(count, sizeof(buf) - 1);
50035 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50036 struct iwl_priv *priv = file->private_data;
50037 u32 event_log_flag;
50038 char buf[8];
50039 - int buf_size;
50040 + size_t buf_size;
50041
50042 /* check that the interface is up */
50043 if (!iwl_is_ready(priv))
50044 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50045 struct iwl_priv *priv = file->private_data;
50046 char buf[8];
50047 u32 calib_disabled;
50048 - int buf_size;
50049 + size_t buf_size;
50050
50051 memset(buf, 0, sizeof(buf));
50052 buf_size = min(count, sizeof(buf) - 1);
50053 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50054 index bb36d67..a43451e 100644
50055 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50056 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50057 @@ -1686,7 +1686,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50058 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50059
50060 char buf[8];
50061 - int buf_size;
50062 + size_t buf_size;
50063 u32 reset_flag;
50064
50065 memset(buf, 0, sizeof(buf));
50066 @@ -1707,7 +1707,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50067 {
50068 struct iwl_trans *trans = file->private_data;
50069 char buf[8];
50070 - int buf_size;
50071 + size_t buf_size;
50072 int csr;
50073
50074 memset(buf, 0, sizeof(buf));
50075 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50076 index 6b48c865..19646a7 100644
50077 --- a/drivers/net/wireless/mac80211_hwsim.c
50078 +++ b/drivers/net/wireless/mac80211_hwsim.c
50079 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
50080 if (channels < 1)
50081 return -EINVAL;
50082
50083 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50084 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50085 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50086 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50087 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50088 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50089 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50090 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50091 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50092 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50093 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50094 - mac80211_hwsim_assign_vif_chanctx;
50095 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50096 - mac80211_hwsim_unassign_vif_chanctx;
50097 + pax_open_kernel();
50098 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50099 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50100 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50101 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50102 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50103 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50104 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50105 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50106 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50107 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50108 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50109 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50110 + pax_close_kernel();
50111
50112 spin_lock_init(&hwsim_radio_lock);
50113 INIT_LIST_HEAD(&hwsim_radios);
50114 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50115 index d2a9a08..0cb175d 100644
50116 --- a/drivers/net/wireless/rndis_wlan.c
50117 +++ b/drivers/net/wireless/rndis_wlan.c
50118 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50119
50120 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50121
50122 - if (rts_threshold < 0 || rts_threshold > 2347)
50123 + if (rts_threshold > 2347)
50124 rts_threshold = 2347;
50125
50126 tmp = cpu_to_le32(rts_threshold);
50127 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50128 index d13f25c..2573994 100644
50129 --- a/drivers/net/wireless/rt2x00/rt2x00.h
50130 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
50131 @@ -375,7 +375,7 @@ struct rt2x00_intf {
50132 * for hardware which doesn't support hardware
50133 * sequence counting.
50134 */
50135 - atomic_t seqno;
50136 + atomic_unchecked_t seqno;
50137 };
50138
50139 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50140 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50141 index 66ff364..3ce34f7 100644
50142 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50143 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50144 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50145 * sequence counter given by mac80211.
50146 */
50147 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50148 - seqno = atomic_add_return(0x10, &intf->seqno);
50149 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50150 else
50151 - seqno = atomic_read(&intf->seqno);
50152 + seqno = atomic_read_unchecked(&intf->seqno);
50153
50154 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50155 hdr->seq_ctrl |= cpu_to_le16(seqno);
50156 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50157 index b661f896..ddf7d2b 100644
50158 --- a/drivers/net/wireless/ti/wl1251/sdio.c
50159 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
50160 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50161
50162 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50163
50164 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50165 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50166 + pax_open_kernel();
50167 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50168 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50169 + pax_close_kernel();
50170
50171 wl1251_info("using dedicated interrupt line");
50172 } else {
50173 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50174 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50175 + pax_open_kernel();
50176 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50177 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50178 + pax_close_kernel();
50179
50180 wl1251_info("using SDIO interrupt");
50181 }
50182 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50183 index 0bccf12..3d95068 100644
50184 --- a/drivers/net/wireless/ti/wl12xx/main.c
50185 +++ b/drivers/net/wireless/ti/wl12xx/main.c
50186 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50187 sizeof(wl->conf.mem));
50188
50189 /* read data preparation is only needed by wl127x */
50190 - wl->ops->prepare_read = wl127x_prepare_read;
50191 + pax_open_kernel();
50192 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50193 + pax_close_kernel();
50194
50195 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50196 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50197 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50198 sizeof(wl->conf.mem));
50199
50200 /* read data preparation is only needed by wl127x */
50201 - wl->ops->prepare_read = wl127x_prepare_read;
50202 + pax_open_kernel();
50203 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50204 + pax_close_kernel();
50205
50206 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50207 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50208 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50209 index 7af1936..128bb35 100644
50210 --- a/drivers/net/wireless/ti/wl18xx/main.c
50211 +++ b/drivers/net/wireless/ti/wl18xx/main.c
50212 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50213 }
50214
50215 if (!checksum_param) {
50216 - wl18xx_ops.set_rx_csum = NULL;
50217 - wl18xx_ops.init_vif = NULL;
50218 + pax_open_kernel();
50219 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
50220 + *(void **)&wl18xx_ops.init_vif = NULL;
50221 + pax_close_kernel();
50222 }
50223
50224 /* Enable 11a Band only if we have 5G antennas */
50225 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50226 index a912dc0..a8225ba 100644
50227 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
50228 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50229 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50230 {
50231 struct zd_usb *usb = urb->context;
50232 struct zd_usb_interrupt *intr = &usb->intr;
50233 - int len;
50234 + unsigned int len;
50235 u16 int_num;
50236
50237 ZD_ASSERT(in_interrupt());
50238 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50239 index 683671a..4519fc2 100644
50240 --- a/drivers/nfc/nfcwilink.c
50241 +++ b/drivers/nfc/nfcwilink.c
50242 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50243
50244 static int nfcwilink_probe(struct platform_device *pdev)
50245 {
50246 - static struct nfcwilink *drv;
50247 + struct nfcwilink *drv;
50248 int rc;
50249 __u32 protocols;
50250
50251 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50252 index d93b2b6..ae50401 100644
50253 --- a/drivers/oprofile/buffer_sync.c
50254 +++ b/drivers/oprofile/buffer_sync.c
50255 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50256 if (cookie == NO_COOKIE)
50257 offset = pc;
50258 if (cookie == INVALID_COOKIE) {
50259 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50260 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50261 offset = pc;
50262 }
50263 if (cookie != last_cookie) {
50264 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50265 /* add userspace sample */
50266
50267 if (!mm) {
50268 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
50269 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50270 return 0;
50271 }
50272
50273 cookie = lookup_dcookie(mm, s->eip, &offset);
50274
50275 if (cookie == INVALID_COOKIE) {
50276 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50277 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50278 return 0;
50279 }
50280
50281 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50282 /* ignore backtraces if failed to add a sample */
50283 if (state == sb_bt_start) {
50284 state = sb_bt_ignore;
50285 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50286 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50287 }
50288 }
50289 release_mm(mm);
50290 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50291 index c0cc4e7..44d4e54 100644
50292 --- a/drivers/oprofile/event_buffer.c
50293 +++ b/drivers/oprofile/event_buffer.c
50294 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50295 }
50296
50297 if (buffer_pos == buffer_size) {
50298 - atomic_inc(&oprofile_stats.event_lost_overflow);
50299 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50300 return;
50301 }
50302
50303 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50304 index ed2c3ec..deda85a 100644
50305 --- a/drivers/oprofile/oprof.c
50306 +++ b/drivers/oprofile/oprof.c
50307 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50308 if (oprofile_ops.switch_events())
50309 return;
50310
50311 - atomic_inc(&oprofile_stats.multiplex_counter);
50312 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50313 start_switch_worker();
50314 }
50315
50316 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50317 index ee2cfce..7f8f699 100644
50318 --- a/drivers/oprofile/oprofile_files.c
50319 +++ b/drivers/oprofile/oprofile_files.c
50320 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50321
50322 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50323
50324 -static ssize_t timeout_read(struct file *file, char __user *buf,
50325 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50326 size_t count, loff_t *offset)
50327 {
50328 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50329 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50330 index 59659ce..6c860a0 100644
50331 --- a/drivers/oprofile/oprofile_stats.c
50332 +++ b/drivers/oprofile/oprofile_stats.c
50333 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50334 cpu_buf->sample_invalid_eip = 0;
50335 }
50336
50337 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50338 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50339 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
50340 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50341 - atomic_set(&oprofile_stats.multiplex_counter, 0);
50342 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50343 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50344 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50345 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50346 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50347 }
50348
50349
50350 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50351 index 1fc622b..8c48fc3 100644
50352 --- a/drivers/oprofile/oprofile_stats.h
50353 +++ b/drivers/oprofile/oprofile_stats.h
50354 @@ -13,11 +13,11 @@
50355 #include <linux/atomic.h>
50356
50357 struct oprofile_stat_struct {
50358 - atomic_t sample_lost_no_mm;
50359 - atomic_t sample_lost_no_mapping;
50360 - atomic_t bt_lost_no_mapping;
50361 - atomic_t event_lost_overflow;
50362 - atomic_t multiplex_counter;
50363 + atomic_unchecked_t sample_lost_no_mm;
50364 + atomic_unchecked_t sample_lost_no_mapping;
50365 + atomic_unchecked_t bt_lost_no_mapping;
50366 + atomic_unchecked_t event_lost_overflow;
50367 + atomic_unchecked_t multiplex_counter;
50368 };
50369
50370 extern struct oprofile_stat_struct oprofile_stats;
50371 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50372 index 3f49345..c750d0b 100644
50373 --- a/drivers/oprofile/oprofilefs.c
50374 +++ b/drivers/oprofile/oprofilefs.c
50375 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50376
50377 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50378 {
50379 - atomic_t *val = file->private_data;
50380 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50381 + atomic_unchecked_t *val = file->private_data;
50382 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50383 }
50384
50385
50386 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50387
50388
50389 int oprofilefs_create_ro_atomic(struct dentry *root,
50390 - char const *name, atomic_t *val)
50391 + char const *name, atomic_unchecked_t *val)
50392 {
50393 return __oprofilefs_create_file(root, name,
50394 &atomic_ro_fops, 0444, val);
50395 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50396 index 61be1d9..dec05d7 100644
50397 --- a/drivers/oprofile/timer_int.c
50398 +++ b/drivers/oprofile/timer_int.c
50399 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50400 return NOTIFY_OK;
50401 }
50402
50403 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50404 +static struct notifier_block oprofile_cpu_notifier = {
50405 .notifier_call = oprofile_cpu_notify,
50406 };
50407
50408 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50409 index 3b47080..6cd05dd 100644
50410 --- a/drivers/parport/procfs.c
50411 +++ b/drivers/parport/procfs.c
50412 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50413
50414 *ppos += len;
50415
50416 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50417 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50418 }
50419
50420 #ifdef CONFIG_PARPORT_1284
50421 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50422
50423 *ppos += len;
50424
50425 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50426 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50427 }
50428 #endif /* IEEE1284.3 support. */
50429
50430 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50431 index 8dcccff..35d701d 100644
50432 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50433 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50434 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50435 goto init_cleanup;
50436 }
50437
50438 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50439 + pax_open_kernel();
50440 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50441 + pax_close_kernel();
50442 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50443
50444 return retval;
50445 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50446 index 04fcd78..39e83f1 100644
50447 --- a/drivers/pci/hotplug/cpcihp_generic.c
50448 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50449 @@ -73,7 +73,6 @@ static u16 port;
50450 static unsigned int enum_bit;
50451 static u8 enum_mask;
50452
50453 -static struct cpci_hp_controller_ops generic_hpc_ops;
50454 static struct cpci_hp_controller generic_hpc;
50455
50456 static int __init validate_parameters(void)
50457 @@ -139,6 +138,10 @@ static int query_enum(void)
50458 return ((value & enum_mask) == enum_mask);
50459 }
50460
50461 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50462 + .query_enum = query_enum,
50463 +};
50464 +
50465 static int __init cpcihp_generic_init(void)
50466 {
50467 int status;
50468 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50469 pci_dev_put(dev);
50470
50471 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50472 - generic_hpc_ops.query_enum = query_enum;
50473 generic_hpc.ops = &generic_hpc_ops;
50474
50475 status = cpci_hp_register_controller(&generic_hpc);
50476 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50477 index 6757b3e..d3bad62 100644
50478 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50479 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50480 @@ -59,7 +59,6 @@
50481 /* local variables */
50482 static bool debug;
50483 static bool poll;
50484 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50485 static struct cpci_hp_controller zt5550_hpc;
50486
50487 /* Primary cPCI bus bridge device */
50488 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50489 return 0;
50490 }
50491
50492 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50493 + .query_enum = zt5550_hc_query_enum,
50494 +};
50495 +
50496 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50497 {
50498 int status;
50499 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50500 dbg("returned from zt5550_hc_config");
50501
50502 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50503 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50504 zt5550_hpc.ops = &zt5550_hpc_ops;
50505 if(!poll) {
50506 zt5550_hpc.irq = hc_dev->irq;
50507 zt5550_hpc.irq_flags = IRQF_SHARED;
50508 zt5550_hpc.dev_id = hc_dev;
50509
50510 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50511 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50512 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50513 + pax_open_kernel();
50514 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50515 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50516 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50517 + pax_open_kernel();
50518 } else {
50519 info("using ENUM# polling mode");
50520 }
50521 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50522 index 0968a9b..5a00edf 100644
50523 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50524 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50525 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50526
50527 void compaq_nvram_init (void __iomem *rom_start)
50528 {
50529 +
50530 +#ifndef CONFIG_PAX_KERNEXEC
50531 if (rom_start) {
50532 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50533 }
50534 +#endif
50535 +
50536 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50537
50538 /* initialize our int15 lock */
50539 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50540 index 56d8486..f26113f 100644
50541 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50542 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50543 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50544 return -EINVAL;
50545 }
50546
50547 - slot->ops->owner = owner;
50548 - slot->ops->mod_name = mod_name;
50549 + pax_open_kernel();
50550 + *(struct module **)&slot->ops->owner = owner;
50551 + *(const char **)&slot->ops->mod_name = mod_name;
50552 + pax_close_kernel();
50553
50554 mutex_lock(&pci_hp_mutex);
50555 /*
50556 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50557 index 07aa722..84514b4 100644
50558 --- a/drivers/pci/hotplug/pciehp_core.c
50559 +++ b/drivers/pci/hotplug/pciehp_core.c
50560 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50561 struct slot *slot = ctrl->slot;
50562 struct hotplug_slot *hotplug = NULL;
50563 struct hotplug_slot_info *info = NULL;
50564 - struct hotplug_slot_ops *ops = NULL;
50565 + hotplug_slot_ops_no_const *ops = NULL;
50566 char name[SLOT_NAME_SIZE];
50567 int retval = -ENOMEM;
50568
50569 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50570 index 6807edd..086a7dc 100644
50571 --- a/drivers/pci/msi.c
50572 +++ b/drivers/pci/msi.c
50573 @@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50574 {
50575 struct attribute **msi_attrs;
50576 struct attribute *msi_attr;
50577 - struct device_attribute *msi_dev_attr;
50578 - struct attribute_group *msi_irq_group;
50579 + device_attribute_no_const *msi_dev_attr;
50580 + attribute_group_no_const *msi_irq_group;
50581 const struct attribute_group **msi_irq_groups;
50582 struct msi_desc *entry;
50583 int ret = -ENOMEM;
50584 @@ -568,7 +568,7 @@ error_attrs:
50585 count = 0;
50586 msi_attr = msi_attrs[count];
50587 while (msi_attr) {
50588 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50589 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50590 kfree(msi_attr->name);
50591 kfree(msi_dev_attr);
50592 ++count;
50593 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50594 index 6d04771..4126004 100644
50595 --- a/drivers/pci/pci-sysfs.c
50596 +++ b/drivers/pci/pci-sysfs.c
50597 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50598 {
50599 /* allocate attribute structure, piggyback attribute name */
50600 int name_len = write_combine ? 13 : 10;
50601 - struct bin_attribute *res_attr;
50602 + bin_attribute_no_const *res_attr;
50603 int retval;
50604
50605 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50606 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50607 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50608 {
50609 int retval;
50610 - struct bin_attribute *attr;
50611 + bin_attribute_no_const *attr;
50612
50613 /* If the device has VPD, try to expose it in sysfs. */
50614 if (dev->vpd) {
50615 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50616 {
50617 int retval;
50618 int rom_size = 0;
50619 - struct bin_attribute *attr;
50620 + bin_attribute_no_const *attr;
50621
50622 if (!sysfs_initialized)
50623 return -EACCES;
50624 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50625 index 0601890..dc15007 100644
50626 --- a/drivers/pci/pci.h
50627 +++ b/drivers/pci/pci.h
50628 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
50629 struct pci_vpd {
50630 unsigned int len;
50631 const struct pci_vpd_ops *ops;
50632 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50633 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50634 };
50635
50636 int pci_vpd_pci22_init(struct pci_dev *dev);
50637 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50638 index e1e7026..d28dd33 100644
50639 --- a/drivers/pci/pcie/aspm.c
50640 +++ b/drivers/pci/pcie/aspm.c
50641 @@ -27,9 +27,9 @@
50642 #define MODULE_PARAM_PREFIX "pcie_aspm."
50643
50644 /* Note: those are not register definitions */
50645 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50646 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50647 -#define ASPM_STATE_L1 (4) /* L1 state */
50648 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50649 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50650 +#define ASPM_STATE_L1 (4U) /* L1 state */
50651 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50652 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50653
50654 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50655 index 9cce960..7c530f4 100644
50656 --- a/drivers/pci/probe.c
50657 +++ b/drivers/pci/probe.c
50658 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50659 struct pci_bus_region region, inverted_region;
50660 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50661
50662 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50663 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50664
50665 /* No printks while decoding is disabled! */
50666 if (!dev->mmio_always_on) {
50667 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50668 index 3f155e7..0f4b1f0 100644
50669 --- a/drivers/pci/proc.c
50670 +++ b/drivers/pci/proc.c
50671 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50672 static int __init pci_proc_init(void)
50673 {
50674 struct pci_dev *dev = NULL;
50675 +
50676 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50677 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50678 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50679 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50680 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50681 +#endif
50682 +#else
50683 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50684 +#endif
50685 proc_create("devices", 0, proc_bus_pci_dir,
50686 &proc_bus_pci_dev_operations);
50687 proc_initialized = 1;
50688 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50689 index d866db8..c827d1f 100644
50690 --- a/drivers/platform/chrome/chromeos_laptop.c
50691 +++ b/drivers/platform/chrome/chromeos_laptop.c
50692 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50693 .callback = chromeos_laptop_dmi_matched, \
50694 .driver_data = (void *)&board_
50695
50696 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50697 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50698 {
50699 .ident = "Samsung Series 5 550",
50700 .matches = {
50701 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50702 index c5af23b..3d62d5e 100644
50703 --- a/drivers/platform/x86/alienware-wmi.c
50704 +++ b/drivers/platform/x86/alienware-wmi.c
50705 @@ -150,7 +150,7 @@ struct wmax_led_args {
50706 } __packed;
50707
50708 static struct platform_device *platform_device;
50709 -static struct device_attribute *zone_dev_attrs;
50710 +static device_attribute_no_const *zone_dev_attrs;
50711 static struct attribute **zone_attrs;
50712 static struct platform_zone *zone_data;
50713
50714 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50715 }
50716 };
50717
50718 -static struct attribute_group zone_attribute_group = {
50719 +static attribute_group_no_const zone_attribute_group = {
50720 .name = "rgb_zones",
50721 };
50722
50723 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50724 index 21fc932..ee9394a 100644
50725 --- a/drivers/platform/x86/asus-wmi.c
50726 +++ b/drivers/platform/x86/asus-wmi.c
50727 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50728 int err;
50729 u32 retval = -1;
50730
50731 +#ifdef CONFIG_GRKERNSEC_KMEM
50732 + return -EPERM;
50733 +#endif
50734 +
50735 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50736
50737 if (err < 0)
50738 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50739 int err;
50740 u32 retval = -1;
50741
50742 +#ifdef CONFIG_GRKERNSEC_KMEM
50743 + return -EPERM;
50744 +#endif
50745 +
50746 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50747 &retval);
50748
50749 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50750 union acpi_object *obj;
50751 acpi_status status;
50752
50753 +#ifdef CONFIG_GRKERNSEC_KMEM
50754 + return -EPERM;
50755 +#endif
50756 +
50757 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50758 1, asus->debug.method_id,
50759 &input, &output);
50760 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50761 index 62f8030..c7f2a45 100644
50762 --- a/drivers/platform/x86/msi-laptop.c
50763 +++ b/drivers/platform/x86/msi-laptop.c
50764 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50765
50766 if (!quirks->ec_read_only) {
50767 /* allow userland write sysfs file */
50768 - dev_attr_bluetooth.store = store_bluetooth;
50769 - dev_attr_wlan.store = store_wlan;
50770 - dev_attr_threeg.store = store_threeg;
50771 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50772 - dev_attr_wlan.attr.mode |= S_IWUSR;
50773 - dev_attr_threeg.attr.mode |= S_IWUSR;
50774 + pax_open_kernel();
50775 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50776 + *(void **)&dev_attr_wlan.store = store_wlan;
50777 + *(void **)&dev_attr_threeg.store = store_threeg;
50778 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50779 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50780 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50781 + pax_close_kernel();
50782 }
50783
50784 /* disable hardware control by fn key */
50785 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50786 index 70222f2..8c8ce66 100644
50787 --- a/drivers/platform/x86/msi-wmi.c
50788 +++ b/drivers/platform/x86/msi-wmi.c
50789 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50790 static void msi_wmi_notify(u32 value, void *context)
50791 {
50792 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50793 - static struct key_entry *key;
50794 + struct key_entry *key;
50795 union acpi_object *obj;
50796 acpi_status status;
50797
50798 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50799 index 26ad9ff..7c52909 100644
50800 --- a/drivers/platform/x86/sony-laptop.c
50801 +++ b/drivers/platform/x86/sony-laptop.c
50802 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50803 }
50804
50805 /* High speed charging function */
50806 -static struct device_attribute *hsc_handle;
50807 +static device_attribute_no_const *hsc_handle;
50808
50809 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50810 struct device_attribute *attr,
50811 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50812 }
50813
50814 /* low battery function */
50815 -static struct device_attribute *lowbatt_handle;
50816 +static device_attribute_no_const *lowbatt_handle;
50817
50818 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50819 struct device_attribute *attr,
50820 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50821 }
50822
50823 /* fan speed function */
50824 -static struct device_attribute *fan_handle, *hsf_handle;
50825 +static device_attribute_no_const *fan_handle, *hsf_handle;
50826
50827 static ssize_t sony_nc_hsfan_store(struct device *dev,
50828 struct device_attribute *attr,
50829 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50830 }
50831
50832 /* USB charge function */
50833 -static struct device_attribute *uc_handle;
50834 +static device_attribute_no_const *uc_handle;
50835
50836 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50837 struct device_attribute *attr,
50838 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50839 }
50840
50841 /* Panel ID function */
50842 -static struct device_attribute *panel_handle;
50843 +static device_attribute_no_const *panel_handle;
50844
50845 static ssize_t sony_nc_panelid_show(struct device *dev,
50846 struct device_attribute *attr, char *buffer)
50847 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50848 }
50849
50850 /* smart connect function */
50851 -static struct device_attribute *sc_handle;
50852 +static device_attribute_no_const *sc_handle;
50853
50854 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50855 struct device_attribute *attr,
50856 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50857 index 3bbc6eb..7760460 100644
50858 --- a/drivers/platform/x86/thinkpad_acpi.c
50859 +++ b/drivers/platform/x86/thinkpad_acpi.c
50860 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50861 return 0;
50862 }
50863
50864 -void static hotkey_mask_warn_incomplete_mask(void)
50865 +static void hotkey_mask_warn_incomplete_mask(void)
50866 {
50867 /* log only what the user can fix... */
50868 const u32 wantedmask = hotkey_driver_mask &
50869 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50870 && !tp_features.bright_unkfw)
50871 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50872 }
50873 +}
50874
50875 #undef TPACPI_COMPARE_KEY
50876 #undef TPACPI_MAY_SEND_KEY
50877 -}
50878
50879 /*
50880 * Polling driver
50881 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50882 index 438d4c7..ca8a2fb 100644
50883 --- a/drivers/pnp/pnpbios/bioscalls.c
50884 +++ b/drivers/pnp/pnpbios/bioscalls.c
50885 @@ -59,7 +59,7 @@ do { \
50886 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50887 } while(0)
50888
50889 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50890 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50891 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50892
50893 /*
50894 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50895
50896 cpu = get_cpu();
50897 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50898 +
50899 + pax_open_kernel();
50900 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50901 + pax_close_kernel();
50902
50903 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50904 spin_lock_irqsave(&pnp_bios_lock, flags);
50905 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50906 :"memory");
50907 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50908
50909 + pax_open_kernel();
50910 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50911 + pax_close_kernel();
50912 +
50913 put_cpu();
50914
50915 /* If we get here and this is set then the PnP BIOS faulted on us. */
50916 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50917 return status;
50918 }
50919
50920 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50921 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50922 {
50923 int i;
50924
50925 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50926 pnp_bios_callpoint.offset = header->fields.pm16offset;
50927 pnp_bios_callpoint.segment = PNP_CS16;
50928
50929 + pax_open_kernel();
50930 +
50931 for_each_possible_cpu(i) {
50932 struct desc_struct *gdt = get_cpu_gdt_table(i);
50933 if (!gdt)
50934 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50935 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50936 (unsigned long)__va(header->fields.pm16dseg));
50937 }
50938 +
50939 + pax_close_kernel();
50940 }
50941 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50942 index 0c52e2a..3421ab7 100644
50943 --- a/drivers/power/pda_power.c
50944 +++ b/drivers/power/pda_power.c
50945 @@ -37,7 +37,11 @@ static int polling;
50946
50947 #if IS_ENABLED(CONFIG_USB_PHY)
50948 static struct usb_phy *transceiver;
50949 -static struct notifier_block otg_nb;
50950 +static int otg_handle_notification(struct notifier_block *nb,
50951 + unsigned long event, void *unused);
50952 +static struct notifier_block otg_nb = {
50953 + .notifier_call = otg_handle_notification
50954 +};
50955 #endif
50956
50957 static struct regulator *ac_draw;
50958 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50959
50960 #if IS_ENABLED(CONFIG_USB_PHY)
50961 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50962 - otg_nb.notifier_call = otg_handle_notification;
50963 ret = usb_register_notifier(transceiver, &otg_nb);
50964 if (ret) {
50965 dev_err(dev, "failure to register otg notifier\n");
50966 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50967 index cc439fd..8fa30df 100644
50968 --- a/drivers/power/power_supply.h
50969 +++ b/drivers/power/power_supply.h
50970 @@ -16,12 +16,12 @@ struct power_supply;
50971
50972 #ifdef CONFIG_SYSFS
50973
50974 -extern void power_supply_init_attrs(struct device_type *dev_type);
50975 +extern void power_supply_init_attrs(void);
50976 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50977
50978 #else
50979
50980 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50981 +static inline void power_supply_init_attrs(void) {}
50982 #define power_supply_uevent NULL
50983
50984 #endif /* CONFIG_SYSFS */
50985 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50986 index 078afd6..fbac9da 100644
50987 --- a/drivers/power/power_supply_core.c
50988 +++ b/drivers/power/power_supply_core.c
50989 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50990 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50991 EXPORT_SYMBOL_GPL(power_supply_notifier);
50992
50993 -static struct device_type power_supply_dev_type;
50994 +extern const struct attribute_group *power_supply_attr_groups[];
50995 +static struct device_type power_supply_dev_type = {
50996 + .groups = power_supply_attr_groups,
50997 +};
50998
50999 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51000 struct power_supply *supply)
51001 @@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
51002 return PTR_ERR(power_supply_class);
51003
51004 power_supply_class->dev_uevent = power_supply_uevent;
51005 - power_supply_init_attrs(&power_supply_dev_type);
51006 + power_supply_init_attrs();
51007
51008 return 0;
51009 }
51010 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51011 index 750a202..99c8f4b 100644
51012 --- a/drivers/power/power_supply_sysfs.c
51013 +++ b/drivers/power/power_supply_sysfs.c
51014 @@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
51015 .is_visible = power_supply_attr_is_visible,
51016 };
51017
51018 -static const struct attribute_group *power_supply_attr_groups[] = {
51019 +const struct attribute_group *power_supply_attr_groups[] = {
51020 &power_supply_attr_group,
51021 NULL,
51022 };
51023
51024 -void power_supply_init_attrs(struct device_type *dev_type)
51025 +void power_supply_init_attrs(void)
51026 {
51027 int i;
51028
51029 - dev_type->groups = power_supply_attr_groups;
51030 -
51031 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51032 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51033 }
51034 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51035 index 84419af..268ede8 100644
51036 --- a/drivers/powercap/powercap_sys.c
51037 +++ b/drivers/powercap/powercap_sys.c
51038 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51039 struct device_attribute name_attr;
51040 };
51041
51042 +static ssize_t show_constraint_name(struct device *dev,
51043 + struct device_attribute *dev_attr,
51044 + char *buf);
51045 +
51046 static struct powercap_constraint_attr
51047 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51048 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51049 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51050 + .power_limit_attr = {
51051 + .attr = {
51052 + .name = NULL,
51053 + .mode = S_IWUSR | S_IRUGO
51054 + },
51055 + .show = show_constraint_power_limit_uw,
51056 + .store = store_constraint_power_limit_uw
51057 + },
51058 +
51059 + .time_window_attr = {
51060 + .attr = {
51061 + .name = NULL,
51062 + .mode = S_IWUSR | S_IRUGO
51063 + },
51064 + .show = show_constraint_time_window_us,
51065 + .store = store_constraint_time_window_us
51066 + },
51067 +
51068 + .max_power_attr = {
51069 + .attr = {
51070 + .name = NULL,
51071 + .mode = S_IRUGO
51072 + },
51073 + .show = show_constraint_max_power_uw,
51074 + .store = NULL
51075 + },
51076 +
51077 + .min_power_attr = {
51078 + .attr = {
51079 + .name = NULL,
51080 + .mode = S_IRUGO
51081 + },
51082 + .show = show_constraint_min_power_uw,
51083 + .store = NULL
51084 + },
51085 +
51086 + .max_time_window_attr = {
51087 + .attr = {
51088 + .name = NULL,
51089 + .mode = S_IRUGO
51090 + },
51091 + .show = show_constraint_max_time_window_us,
51092 + .store = NULL
51093 + },
51094 +
51095 + .min_time_window_attr = {
51096 + .attr = {
51097 + .name = NULL,
51098 + .mode = S_IRUGO
51099 + },
51100 + .show = show_constraint_min_time_window_us,
51101 + .store = NULL
51102 + },
51103 +
51104 + .name_attr = {
51105 + .attr = {
51106 + .name = NULL,
51107 + .mode = S_IRUGO
51108 + },
51109 + .show = show_constraint_name,
51110 + .store = NULL
51111 + }
51112 + }
51113 +};
51114
51115 /* A list of powercap control_types */
51116 static LIST_HEAD(powercap_cntrl_list);
51117 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51118 }
51119
51120 static int create_constraint_attribute(int id, const char *name,
51121 - int mode,
51122 - struct device_attribute *dev_attr,
51123 - ssize_t (*show)(struct device *,
51124 - struct device_attribute *, char *),
51125 - ssize_t (*store)(struct device *,
51126 - struct device_attribute *,
51127 - const char *, size_t)
51128 - )
51129 + struct device_attribute *dev_attr)
51130 {
51131 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51132
51133 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51134 - id, name);
51135 - if (!dev_attr->attr.name)
51136 + if (!name)
51137 return -ENOMEM;
51138 - dev_attr->attr.mode = mode;
51139 - dev_attr->show = show;
51140 - dev_attr->store = store;
51141 +
51142 + pax_open_kernel();
51143 + *(const char **)&dev_attr->attr.name = name;
51144 + pax_close_kernel();
51145
51146 return 0;
51147 }
51148 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51149
51150 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51151 ret = create_constraint_attribute(i, "power_limit_uw",
51152 - S_IWUSR | S_IRUGO,
51153 - &constraint_attrs[i].power_limit_attr,
51154 - show_constraint_power_limit_uw,
51155 - store_constraint_power_limit_uw);
51156 + &constraint_attrs[i].power_limit_attr);
51157 if (ret)
51158 goto err_alloc;
51159 ret = create_constraint_attribute(i, "time_window_us",
51160 - S_IWUSR | S_IRUGO,
51161 - &constraint_attrs[i].time_window_attr,
51162 - show_constraint_time_window_us,
51163 - store_constraint_time_window_us);
51164 + &constraint_attrs[i].time_window_attr);
51165 if (ret)
51166 goto err_alloc;
51167 - ret = create_constraint_attribute(i, "name", S_IRUGO,
51168 - &constraint_attrs[i].name_attr,
51169 - show_constraint_name,
51170 - NULL);
51171 + ret = create_constraint_attribute(i, "name",
51172 + &constraint_attrs[i].name_attr);
51173 if (ret)
51174 goto err_alloc;
51175 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51176 - &constraint_attrs[i].max_power_attr,
51177 - show_constraint_max_power_uw,
51178 - NULL);
51179 + ret = create_constraint_attribute(i, "max_power_uw",
51180 + &constraint_attrs[i].max_power_attr);
51181 if (ret)
51182 goto err_alloc;
51183 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51184 - &constraint_attrs[i].min_power_attr,
51185 - show_constraint_min_power_uw,
51186 - NULL);
51187 + ret = create_constraint_attribute(i, "min_power_uw",
51188 + &constraint_attrs[i].min_power_attr);
51189 if (ret)
51190 goto err_alloc;
51191 ret = create_constraint_attribute(i, "max_time_window_us",
51192 - S_IRUGO,
51193 - &constraint_attrs[i].max_time_window_attr,
51194 - show_constraint_max_time_window_us,
51195 - NULL);
51196 + &constraint_attrs[i].max_time_window_attr);
51197 if (ret)
51198 goto err_alloc;
51199 ret = create_constraint_attribute(i, "min_time_window_us",
51200 - S_IRUGO,
51201 - &constraint_attrs[i].min_time_window_attr,
51202 - show_constraint_min_time_window_us,
51203 - NULL);
51204 + &constraint_attrs[i].min_time_window_attr);
51205 if (ret)
51206 goto err_alloc;
51207
51208 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51209 power_zone->zone_dev_attrs[count++] =
51210 &dev_attr_max_energy_range_uj.attr;
51211 if (power_zone->ops->get_energy_uj) {
51212 + pax_open_kernel();
51213 if (power_zone->ops->reset_energy_uj)
51214 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51215 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51216 else
51217 - dev_attr_energy_uj.attr.mode = S_IRUGO;
51218 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51219 + pax_close_kernel();
51220 power_zone->zone_dev_attrs[count++] =
51221 &dev_attr_energy_uj.attr;
51222 }
51223 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51224 index 9c5d414..c7900ce 100644
51225 --- a/drivers/ptp/ptp_private.h
51226 +++ b/drivers/ptp/ptp_private.h
51227 @@ -51,7 +51,7 @@ struct ptp_clock {
51228 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51229 wait_queue_head_t tsev_wq;
51230 int defunct; /* tells readers to go away when clock is being removed */
51231 - struct device_attribute *pin_dev_attr;
51232 + device_attribute_no_const *pin_dev_attr;
51233 struct attribute **pin_attr;
51234 struct attribute_group pin_attr_group;
51235 };
51236 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51237 index 302e626..12579af 100644
51238 --- a/drivers/ptp/ptp_sysfs.c
51239 +++ b/drivers/ptp/ptp_sysfs.c
51240 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51241 goto no_pin_attr;
51242
51243 for (i = 0; i < n_pins; i++) {
51244 - struct device_attribute *da = &ptp->pin_dev_attr[i];
51245 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51246 sysfs_attr_init(&da->attr);
51247 da->attr.name = info->pin_config[i].name;
51248 da->attr.mode = 0644;
51249 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51250 index a3c3785..c901e3a 100644
51251 --- a/drivers/regulator/core.c
51252 +++ b/drivers/regulator/core.c
51253 @@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51254 {
51255 const struct regulation_constraints *constraints = NULL;
51256 const struct regulator_init_data *init_data;
51257 - static atomic_t regulator_no = ATOMIC_INIT(0);
51258 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51259 struct regulator_dev *rdev;
51260 struct device *dev;
51261 int ret, i;
51262 @@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51263 rdev->dev.of_node = of_node_get(config->of_node);
51264 rdev->dev.parent = dev;
51265 dev_set_name(&rdev->dev, "regulator.%d",
51266 - atomic_inc_return(&regulator_no) - 1);
51267 + atomic_inc_return_unchecked(&regulator_no) - 1);
51268 ret = device_register(&rdev->dev);
51269 if (ret != 0) {
51270 put_device(&rdev->dev);
51271 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51272 index 2fc4111..6aa88ca 100644
51273 --- a/drivers/regulator/max8660.c
51274 +++ b/drivers/regulator/max8660.c
51275 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51276 max8660->shadow_regs[MAX8660_OVER1] = 5;
51277 } else {
51278 /* Otherwise devices can be toggled via software */
51279 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
51280 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
51281 + pax_open_kernel();
51282 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51283 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51284 + pax_close_kernel();
51285 }
51286
51287 /*
51288 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51289 index dbedf17..18ff6b7 100644
51290 --- a/drivers/regulator/max8973-regulator.c
51291 +++ b/drivers/regulator/max8973-regulator.c
51292 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51293 if (!pdata || !pdata->enable_ext_control) {
51294 max->desc.enable_reg = MAX8973_VOUT;
51295 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51296 - max->ops.enable = regulator_enable_regmap;
51297 - max->ops.disable = regulator_disable_regmap;
51298 - max->ops.is_enabled = regulator_is_enabled_regmap;
51299 + pax_open_kernel();
51300 + *(void **)&max->ops.enable = regulator_enable_regmap;
51301 + *(void **)&max->ops.disable = regulator_disable_regmap;
51302 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51303 + pax_close_kernel();
51304 }
51305
51306 if (pdata) {
51307 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51308 index f374fa5..26f0683 100644
51309 --- a/drivers/regulator/mc13892-regulator.c
51310 +++ b/drivers/regulator/mc13892-regulator.c
51311 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51312 }
51313 mc13xxx_unlock(mc13892);
51314
51315 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51316 + pax_open_kernel();
51317 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51318 = mc13892_vcam_set_mode;
51319 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51320 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51321 = mc13892_vcam_get_mode;
51322 + pax_close_kernel();
51323
51324 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51325 ARRAY_SIZE(mc13892_regulators));
51326 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51327 index 5b2e761..c8c8a4a 100644
51328 --- a/drivers/rtc/rtc-cmos.c
51329 +++ b/drivers/rtc/rtc-cmos.c
51330 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51331 hpet_rtc_timer_init();
51332
51333 /* export at least the first block of NVRAM */
51334 - nvram.size = address_space - NVRAM_OFFSET;
51335 + pax_open_kernel();
51336 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51337 + pax_close_kernel();
51338 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51339 if (retval < 0) {
51340 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51341 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51342 index d049393..bb20be0 100644
51343 --- a/drivers/rtc/rtc-dev.c
51344 +++ b/drivers/rtc/rtc-dev.c
51345 @@ -16,6 +16,7 @@
51346 #include <linux/module.h>
51347 #include <linux/rtc.h>
51348 #include <linux/sched.h>
51349 +#include <linux/grsecurity.h>
51350 #include "rtc-core.h"
51351
51352 static dev_t rtc_devt;
51353 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51354 if (copy_from_user(&tm, uarg, sizeof(tm)))
51355 return -EFAULT;
51356
51357 + gr_log_timechange();
51358 +
51359 return rtc_set_time(rtc, &tm);
51360
51361 case RTC_PIE_ON:
51362 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51363 index f03d5ba..8325bf6 100644
51364 --- a/drivers/rtc/rtc-ds1307.c
51365 +++ b/drivers/rtc/rtc-ds1307.c
51366 @@ -107,7 +107,7 @@ struct ds1307 {
51367 u8 offset; /* register's offset */
51368 u8 regs[11];
51369 u16 nvram_offset;
51370 - struct bin_attribute *nvram;
51371 + bin_attribute_no_const *nvram;
51372 enum ds_type type;
51373 unsigned long flags;
51374 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51375 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51376 index 11880c1..b823aa4 100644
51377 --- a/drivers/rtc/rtc-m48t59.c
51378 +++ b/drivers/rtc/rtc-m48t59.c
51379 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51380 if (IS_ERR(m48t59->rtc))
51381 return PTR_ERR(m48t59->rtc);
51382
51383 - m48t59_nvram_attr.size = pdata->offset;
51384 + pax_open_kernel();
51385 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51386 + pax_close_kernel();
51387
51388 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51389 if (ret)
51390 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51391 index e693af6..2e525b6 100644
51392 --- a/drivers/scsi/bfa/bfa_fcpim.h
51393 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51394 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51395
51396 struct bfa_itn_s {
51397 bfa_isr_func_t isr;
51398 -};
51399 +} __no_const;
51400
51401 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51402 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51403 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51404 index 0f19455..ef7adb5 100644
51405 --- a/drivers/scsi/bfa/bfa_fcs.c
51406 +++ b/drivers/scsi/bfa/bfa_fcs.c
51407 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51408 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51409
51410 static struct bfa_fcs_mod_s fcs_modules[] = {
51411 - { bfa_fcs_port_attach, NULL, NULL },
51412 - { bfa_fcs_uf_attach, NULL, NULL },
51413 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51414 - bfa_fcs_fabric_modexit },
51415 + {
51416 + .attach = bfa_fcs_port_attach,
51417 + .modinit = NULL,
51418 + .modexit = NULL
51419 + },
51420 + {
51421 + .attach = bfa_fcs_uf_attach,
51422 + .modinit = NULL,
51423 + .modexit = NULL
51424 + },
51425 + {
51426 + .attach = bfa_fcs_fabric_attach,
51427 + .modinit = bfa_fcs_fabric_modinit,
51428 + .modexit = bfa_fcs_fabric_modexit
51429 + },
51430 };
51431
51432 /*
51433 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51434 index ff75ef8..2dfe00a 100644
51435 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51436 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51437 @@ -89,15 +89,26 @@ static struct {
51438 void (*offline) (struct bfa_fcs_lport_s *port);
51439 } __port_action[] = {
51440 {
51441 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51442 - bfa_fcs_lport_unknown_offline}, {
51443 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51444 - bfa_fcs_lport_fab_offline}, {
51445 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51446 - bfa_fcs_lport_n2n_offline}, {
51447 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51448 - bfa_fcs_lport_loop_offline},
51449 - };
51450 + .init = bfa_fcs_lport_unknown_init,
51451 + .online = bfa_fcs_lport_unknown_online,
51452 + .offline = bfa_fcs_lport_unknown_offline
51453 + },
51454 + {
51455 + .init = bfa_fcs_lport_fab_init,
51456 + .online = bfa_fcs_lport_fab_online,
51457 + .offline = bfa_fcs_lport_fab_offline
51458 + },
51459 + {
51460 + .init = bfa_fcs_lport_n2n_init,
51461 + .online = bfa_fcs_lport_n2n_online,
51462 + .offline = bfa_fcs_lport_n2n_offline
51463 + },
51464 + {
51465 + .init = bfa_fcs_lport_loop_init,
51466 + .online = bfa_fcs_lport_loop_online,
51467 + .offline = bfa_fcs_lport_loop_offline
51468 + },
51469 +};
51470
51471 /*
51472 * fcs_port_sm FCS logical port state machine
51473 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51474 index a38aafa0..fe8f03b 100644
51475 --- a/drivers/scsi/bfa/bfa_ioc.h
51476 +++ b/drivers/scsi/bfa/bfa_ioc.h
51477 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51478 bfa_ioc_disable_cbfn_t disable_cbfn;
51479 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51480 bfa_ioc_reset_cbfn_t reset_cbfn;
51481 -};
51482 +} __no_const;
51483
51484 /*
51485 * IOC event notification mechanism.
51486 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51487 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51488 enum bfi_ioc_state fwstate);
51489 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51490 -};
51491 +} __no_const;
51492
51493 /*
51494 * Queue element to wait for room in request queue. FIFO order is
51495 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51496 index a14c784..6de6790 100644
51497 --- a/drivers/scsi/bfa/bfa_modules.h
51498 +++ b/drivers/scsi/bfa/bfa_modules.h
51499 @@ -78,12 +78,12 @@ enum {
51500 \
51501 extern struct bfa_module_s hal_mod_ ## __mod; \
51502 struct bfa_module_s hal_mod_ ## __mod = { \
51503 - bfa_ ## __mod ## _meminfo, \
51504 - bfa_ ## __mod ## _attach, \
51505 - bfa_ ## __mod ## _detach, \
51506 - bfa_ ## __mod ## _start, \
51507 - bfa_ ## __mod ## _stop, \
51508 - bfa_ ## __mod ## _iocdisable, \
51509 + .meminfo = bfa_ ## __mod ## _meminfo, \
51510 + .attach = bfa_ ## __mod ## _attach, \
51511 + .detach = bfa_ ## __mod ## _detach, \
51512 + .start = bfa_ ## __mod ## _start, \
51513 + .stop = bfa_ ## __mod ## _stop, \
51514 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51515 }
51516
51517 #define BFA_CACHELINE_SZ (256)
51518 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51519 index 045c4e1..13de803 100644
51520 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51521 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51522 @@ -33,8 +33,8 @@
51523 */
51524 #include "libfcoe.h"
51525
51526 -static atomic_t ctlr_num;
51527 -static atomic_t fcf_num;
51528 +static atomic_unchecked_t ctlr_num;
51529 +static atomic_unchecked_t fcf_num;
51530
51531 /*
51532 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51533 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51534 if (!ctlr)
51535 goto out;
51536
51537 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51538 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51539 ctlr->f = f;
51540 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51541 INIT_LIST_HEAD(&ctlr->fcfs);
51542 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51543 fcf->dev.parent = &ctlr->dev;
51544 fcf->dev.bus = &fcoe_bus_type;
51545 fcf->dev.type = &fcoe_fcf_device_type;
51546 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51547 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51548 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51549
51550 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51551 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51552 {
51553 int error;
51554
51555 - atomic_set(&ctlr_num, 0);
51556 - atomic_set(&fcf_num, 0);
51557 + atomic_set_unchecked(&ctlr_num, 0);
51558 + atomic_set_unchecked(&fcf_num, 0);
51559
51560 error = bus_register(&fcoe_bus_type);
51561 if (error)
51562 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51563 index 6de80e3..a11e0ac 100644
51564 --- a/drivers/scsi/hosts.c
51565 +++ b/drivers/scsi/hosts.c
51566 @@ -42,7 +42,7 @@
51567 #include "scsi_logging.h"
51568
51569
51570 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51571 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51572
51573
51574 static void scsi_host_cls_release(struct device *dev)
51575 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51576 * subtract one because we increment first then return, but we need to
51577 * know what the next host number was before increment
51578 */
51579 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51580 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51581 shost->dma_channel = 0xff;
51582
51583 /* These three are default values which can be overridden */
51584 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51585 index 6b35d0d..2880305 100644
51586 --- a/drivers/scsi/hpsa.c
51587 +++ b/drivers/scsi/hpsa.c
51588 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51589 unsigned long flags;
51590
51591 if (h->transMethod & CFGTBL_Trans_io_accel1)
51592 - return h->access.command_completed(h, q);
51593 + return h->access->command_completed(h, q);
51594
51595 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51596 - return h->access.command_completed(h, q);
51597 + return h->access->command_completed(h, q);
51598
51599 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51600 a = rq->head[rq->current_entry];
51601 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51602 while (!list_empty(&h->reqQ)) {
51603 c = list_entry(h->reqQ.next, struct CommandList, list);
51604 /* can't do anything if fifo is full */
51605 - if ((h->access.fifo_full(h))) {
51606 + if ((h->access->fifo_full(h))) {
51607 h->fifo_recently_full = 1;
51608 dev_warn(&h->pdev->dev, "fifo full\n");
51609 break;
51610 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51611
51612 /* Tell the controller execute command */
51613 spin_unlock_irqrestore(&h->lock, *flags);
51614 - h->access.submit_command(h, c);
51615 + h->access->submit_command(h, c);
51616 spin_lock_irqsave(&h->lock, *flags);
51617 }
51618 }
51619 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51620
51621 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51622 {
51623 - return h->access.command_completed(h, q);
51624 + return h->access->command_completed(h, q);
51625 }
51626
51627 static inline bool interrupt_pending(struct ctlr_info *h)
51628 {
51629 - return h->access.intr_pending(h);
51630 + return h->access->intr_pending(h);
51631 }
51632
51633 static inline long interrupt_not_for_us(struct ctlr_info *h)
51634 {
51635 - return (h->access.intr_pending(h) == 0) ||
51636 + return (h->access->intr_pending(h) == 0) ||
51637 (h->interrupts_enabled == 0);
51638 }
51639
51640 @@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51641 if (prod_index < 0)
51642 return -ENODEV;
51643 h->product_name = products[prod_index].product_name;
51644 - h->access = *(products[prod_index].access);
51645 + h->access = products[prod_index].access;
51646
51647 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51648 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51649 @@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51650 unsigned long flags;
51651 u32 lockup_detected;
51652
51653 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51654 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51655 spin_lock_irqsave(&h->lock, flags);
51656 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51657 if (!lockup_detected) {
51658 @@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
51659 }
51660
51661 /* make sure the board interrupts are off */
51662 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51663 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51664
51665 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51666 goto clean2;
51667 @@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
51668 * fake ones to scoop up any residual completions.
51669 */
51670 spin_lock_irqsave(&h->lock, flags);
51671 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51672 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51673 spin_unlock_irqrestore(&h->lock, flags);
51674 free_irqs(h);
51675 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51676 @@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
51677 dev_info(&h->pdev->dev, "Board READY.\n");
51678 dev_info(&h->pdev->dev,
51679 "Waiting for stale completions to drain.\n");
51680 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51681 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51682 msleep(10000);
51683 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51684 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51685
51686 rc = controller_reset_failed(h->cfgtable);
51687 if (rc)
51688 @@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
51689 h->drv_req_rescan = 0;
51690
51691 /* Turn the interrupts on so we can service requests */
51692 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51693 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51694
51695 hpsa_hba_inquiry(h);
51696 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51697 @@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51698 * To write all data in the battery backed cache to disks
51699 */
51700 hpsa_flush_cache(h);
51701 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51702 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51703 hpsa_free_irqs_and_disable_msix(h);
51704 }
51705
51706 @@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51707 CFGTBL_Trans_enable_directed_msix |
51708 (trans_support & (CFGTBL_Trans_io_accel1 |
51709 CFGTBL_Trans_io_accel2));
51710 - struct access_method access = SA5_performant_access;
51711 + struct access_method *access = &SA5_performant_access;
51712
51713 /* This is a bit complicated. There are 8 registers on
51714 * the controller which we write to to tell it 8 different
51715 @@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51716 * perform the superfluous readl() after each command submission.
51717 */
51718 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51719 - access = SA5_performant_access_no_read;
51720 + access = &SA5_performant_access_no_read;
51721
51722 /* Controller spec: zero out this buffer. */
51723 for (i = 0; i < h->nreply_queues; i++)
51724 @@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51725 * enable outbound interrupt coalescing in accelerator mode;
51726 */
51727 if (trans_support & CFGTBL_Trans_io_accel1) {
51728 - access = SA5_ioaccel_mode1_access;
51729 + access = &SA5_ioaccel_mode1_access;
51730 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51731 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51732 } else {
51733 if (trans_support & CFGTBL_Trans_io_accel2) {
51734 - access = SA5_ioaccel_mode2_access;
51735 + access = &SA5_ioaccel_mode2_access;
51736 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51737 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51738 }
51739 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51740 index 24472ce..8782caf 100644
51741 --- a/drivers/scsi/hpsa.h
51742 +++ b/drivers/scsi/hpsa.h
51743 @@ -127,7 +127,7 @@ struct ctlr_info {
51744 unsigned int msix_vector;
51745 unsigned int msi_vector;
51746 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51747 - struct access_method access;
51748 + struct access_method *access;
51749 char hba_mode_enabled;
51750
51751 /* queue and queue Info */
51752 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51753 }
51754
51755 static struct access_method SA5_access = {
51756 - SA5_submit_command,
51757 - SA5_intr_mask,
51758 - SA5_fifo_full,
51759 - SA5_intr_pending,
51760 - SA5_completed,
51761 + .submit_command = SA5_submit_command,
51762 + .set_intr_mask = SA5_intr_mask,
51763 + .fifo_full = SA5_fifo_full,
51764 + .intr_pending = SA5_intr_pending,
51765 + .command_completed = SA5_completed,
51766 };
51767
51768 static struct access_method SA5_ioaccel_mode1_access = {
51769 - SA5_submit_command,
51770 - SA5_performant_intr_mask,
51771 - SA5_fifo_full,
51772 - SA5_ioaccel_mode1_intr_pending,
51773 - SA5_ioaccel_mode1_completed,
51774 + .submit_command = SA5_submit_command,
51775 + .set_intr_mask = SA5_performant_intr_mask,
51776 + .fifo_full = SA5_fifo_full,
51777 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51778 + .command_completed = SA5_ioaccel_mode1_completed,
51779 };
51780
51781 static struct access_method SA5_ioaccel_mode2_access = {
51782 - SA5_submit_command_ioaccel2,
51783 - SA5_performant_intr_mask,
51784 - SA5_fifo_full,
51785 - SA5_performant_intr_pending,
51786 - SA5_performant_completed,
51787 + .submit_command = SA5_submit_command_ioaccel2,
51788 + .set_intr_mask = SA5_performant_intr_mask,
51789 + .fifo_full = SA5_fifo_full,
51790 + .intr_pending = SA5_performant_intr_pending,
51791 + .command_completed = SA5_performant_completed,
51792 };
51793
51794 static struct access_method SA5_performant_access = {
51795 - SA5_submit_command,
51796 - SA5_performant_intr_mask,
51797 - SA5_fifo_full,
51798 - SA5_performant_intr_pending,
51799 - SA5_performant_completed,
51800 + .submit_command = SA5_submit_command,
51801 + .set_intr_mask = SA5_performant_intr_mask,
51802 + .fifo_full = SA5_fifo_full,
51803 + .intr_pending = SA5_performant_intr_pending,
51804 + .command_completed = SA5_performant_completed,
51805 };
51806
51807 static struct access_method SA5_performant_access_no_read = {
51808 - SA5_submit_command_no_read,
51809 - SA5_performant_intr_mask,
51810 - SA5_fifo_full,
51811 - SA5_performant_intr_pending,
51812 - SA5_performant_completed,
51813 + .submit_command = SA5_submit_command_no_read,
51814 + .set_intr_mask = SA5_performant_intr_mask,
51815 + .fifo_full = SA5_fifo_full,
51816 + .intr_pending = SA5_performant_intr_pending,
51817 + .command_completed = SA5_performant_completed,
51818 };
51819
51820 struct board_type {
51821 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51822 index 1b3a094..068e683 100644
51823 --- a/drivers/scsi/libfc/fc_exch.c
51824 +++ b/drivers/scsi/libfc/fc_exch.c
51825 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51826 u16 pool_max_index;
51827
51828 struct {
51829 - atomic_t no_free_exch;
51830 - atomic_t no_free_exch_xid;
51831 - atomic_t xid_not_found;
51832 - atomic_t xid_busy;
51833 - atomic_t seq_not_found;
51834 - atomic_t non_bls_resp;
51835 + atomic_unchecked_t no_free_exch;
51836 + atomic_unchecked_t no_free_exch_xid;
51837 + atomic_unchecked_t xid_not_found;
51838 + atomic_unchecked_t xid_busy;
51839 + atomic_unchecked_t seq_not_found;
51840 + atomic_unchecked_t non_bls_resp;
51841 } stats;
51842 };
51843
51844 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51845 /* allocate memory for exchange */
51846 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51847 if (!ep) {
51848 - atomic_inc(&mp->stats.no_free_exch);
51849 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51850 goto out;
51851 }
51852 memset(ep, 0, sizeof(*ep));
51853 @@ -874,7 +874,7 @@ out:
51854 return ep;
51855 err:
51856 spin_unlock_bh(&pool->lock);
51857 - atomic_inc(&mp->stats.no_free_exch_xid);
51858 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51859 mempool_free(ep, mp->ep_pool);
51860 return NULL;
51861 }
51862 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51863 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51864 ep = fc_exch_find(mp, xid);
51865 if (!ep) {
51866 - atomic_inc(&mp->stats.xid_not_found);
51867 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51868 reject = FC_RJT_OX_ID;
51869 goto out;
51870 }
51871 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51872 ep = fc_exch_find(mp, xid);
51873 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51874 if (ep) {
51875 - atomic_inc(&mp->stats.xid_busy);
51876 + atomic_inc_unchecked(&mp->stats.xid_busy);
51877 reject = FC_RJT_RX_ID;
51878 goto rel;
51879 }
51880 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51881 }
51882 xid = ep->xid; /* get our XID */
51883 } else if (!ep) {
51884 - atomic_inc(&mp->stats.xid_not_found);
51885 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51886 reject = FC_RJT_RX_ID; /* XID not found */
51887 goto out;
51888 }
51889 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51890 } else {
51891 sp = &ep->seq;
51892 if (sp->id != fh->fh_seq_id) {
51893 - atomic_inc(&mp->stats.seq_not_found);
51894 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51895 if (f_ctl & FC_FC_END_SEQ) {
51896 /*
51897 * Update sequence_id based on incoming last
51898 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51899
51900 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51901 if (!ep) {
51902 - atomic_inc(&mp->stats.xid_not_found);
51903 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51904 goto out;
51905 }
51906 if (ep->esb_stat & ESB_ST_COMPLETE) {
51907 - atomic_inc(&mp->stats.xid_not_found);
51908 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51909 goto rel;
51910 }
51911 if (ep->rxid == FC_XID_UNKNOWN)
51912 ep->rxid = ntohs(fh->fh_rx_id);
51913 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51914 - atomic_inc(&mp->stats.xid_not_found);
51915 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51916 goto rel;
51917 }
51918 if (ep->did != ntoh24(fh->fh_s_id) &&
51919 ep->did != FC_FID_FLOGI) {
51920 - atomic_inc(&mp->stats.xid_not_found);
51921 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51922 goto rel;
51923 }
51924 sof = fr_sof(fp);
51925 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51926 sp->ssb_stat |= SSB_ST_RESP;
51927 sp->id = fh->fh_seq_id;
51928 } else if (sp->id != fh->fh_seq_id) {
51929 - atomic_inc(&mp->stats.seq_not_found);
51930 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51931 goto rel;
51932 }
51933
51934 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51935 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51936
51937 if (!sp)
51938 - atomic_inc(&mp->stats.xid_not_found);
51939 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51940 else
51941 - atomic_inc(&mp->stats.non_bls_resp);
51942 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51943
51944 fc_frame_free(fp);
51945 }
51946 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51947
51948 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51949 mp = ema->mp;
51950 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51951 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51952 st->fc_no_free_exch_xid +=
51953 - atomic_read(&mp->stats.no_free_exch_xid);
51954 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51955 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51956 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51957 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51958 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51959 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51960 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51961 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51962 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51963 }
51964 }
51965 EXPORT_SYMBOL(fc_exch_update_stats);
51966 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51967 index 766098a..1c6c971 100644
51968 --- a/drivers/scsi/libsas/sas_ata.c
51969 +++ b/drivers/scsi/libsas/sas_ata.c
51970 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51971 .postreset = ata_std_postreset,
51972 .error_handler = ata_std_error_handler,
51973 .post_internal_cmd = sas_ata_post_internal,
51974 - .qc_defer = ata_std_qc_defer,
51975 + .qc_defer = ata_std_qc_defer,
51976 .qc_prep = ata_noop_qc_prep,
51977 .qc_issue = sas_ata_qc_issue,
51978 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51979 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51980 index 434e903..5a4a79b 100644
51981 --- a/drivers/scsi/lpfc/lpfc.h
51982 +++ b/drivers/scsi/lpfc/lpfc.h
51983 @@ -430,7 +430,7 @@ struct lpfc_vport {
51984 struct dentry *debug_nodelist;
51985 struct dentry *vport_debugfs_root;
51986 struct lpfc_debugfs_trc *disc_trc;
51987 - atomic_t disc_trc_cnt;
51988 + atomic_unchecked_t disc_trc_cnt;
51989 #endif
51990 uint8_t stat_data_enabled;
51991 uint8_t stat_data_blocked;
51992 @@ -880,8 +880,8 @@ struct lpfc_hba {
51993 struct timer_list fabric_block_timer;
51994 unsigned long bit_flags;
51995 #define FABRIC_COMANDS_BLOCKED 0
51996 - atomic_t num_rsrc_err;
51997 - atomic_t num_cmd_success;
51998 + atomic_unchecked_t num_rsrc_err;
51999 + atomic_unchecked_t num_cmd_success;
52000 unsigned long last_rsrc_error_time;
52001 unsigned long last_ramp_down_time;
52002 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52003 @@ -916,7 +916,7 @@ struct lpfc_hba {
52004
52005 struct dentry *debug_slow_ring_trc;
52006 struct lpfc_debugfs_trc *slow_ring_trc;
52007 - atomic_t slow_ring_trc_cnt;
52008 + atomic_unchecked_t slow_ring_trc_cnt;
52009 /* iDiag debugfs sub-directory */
52010 struct dentry *idiag_root;
52011 struct dentry *idiag_pci_cfg;
52012 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52013 index b0aedce..89c6ca6 100644
52014 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
52015 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52016 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52017
52018 #include <linux/debugfs.h>
52019
52020 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52021 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52022 static unsigned long lpfc_debugfs_start_time = 0L;
52023
52024 /* iDiag */
52025 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52026 lpfc_debugfs_enable = 0;
52027
52028 len = 0;
52029 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52030 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52031 (lpfc_debugfs_max_disc_trc - 1);
52032 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52033 dtp = vport->disc_trc + i;
52034 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52035 lpfc_debugfs_enable = 0;
52036
52037 len = 0;
52038 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52039 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52040 (lpfc_debugfs_max_slow_ring_trc - 1);
52041 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52042 dtp = phba->slow_ring_trc + i;
52043 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52044 !vport || !vport->disc_trc)
52045 return;
52046
52047 - index = atomic_inc_return(&vport->disc_trc_cnt) &
52048 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52049 (lpfc_debugfs_max_disc_trc - 1);
52050 dtp = vport->disc_trc + index;
52051 dtp->fmt = fmt;
52052 dtp->data1 = data1;
52053 dtp->data2 = data2;
52054 dtp->data3 = data3;
52055 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52056 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52057 dtp->jif = jiffies;
52058 #endif
52059 return;
52060 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52061 !phba || !phba->slow_ring_trc)
52062 return;
52063
52064 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52065 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52066 (lpfc_debugfs_max_slow_ring_trc - 1);
52067 dtp = phba->slow_ring_trc + index;
52068 dtp->fmt = fmt;
52069 dtp->data1 = data1;
52070 dtp->data2 = data2;
52071 dtp->data3 = data3;
52072 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52073 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52074 dtp->jif = jiffies;
52075 #endif
52076 return;
52077 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52078 "slow_ring buffer\n");
52079 goto debug_failed;
52080 }
52081 - atomic_set(&phba->slow_ring_trc_cnt, 0);
52082 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52083 memset(phba->slow_ring_trc, 0,
52084 (sizeof(struct lpfc_debugfs_trc) *
52085 lpfc_debugfs_max_slow_ring_trc));
52086 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52087 "buffer\n");
52088 goto debug_failed;
52089 }
52090 - atomic_set(&vport->disc_trc_cnt, 0);
52091 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52092
52093 snprintf(name, sizeof(name), "discovery_trace");
52094 vport->debug_disc_trc =
52095 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52096 index a5769a9..718ecc7 100644
52097 --- a/drivers/scsi/lpfc/lpfc_init.c
52098 +++ b/drivers/scsi/lpfc/lpfc_init.c
52099 @@ -11299,8 +11299,10 @@ lpfc_init(void)
52100 "misc_register returned with status %d", error);
52101
52102 if (lpfc_enable_npiv) {
52103 - lpfc_transport_functions.vport_create = lpfc_vport_create;
52104 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52105 + pax_open_kernel();
52106 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52107 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52108 + pax_close_kernel();
52109 }
52110 lpfc_transport_template =
52111 fc_attach_transport(&lpfc_transport_functions);
52112 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52113 index 7862c55..5aa65df 100644
52114 --- a/drivers/scsi/lpfc/lpfc_scsi.c
52115 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
52116 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52117 uint32_t evt_posted;
52118
52119 spin_lock_irqsave(&phba->hbalock, flags);
52120 - atomic_inc(&phba->num_rsrc_err);
52121 + atomic_inc_unchecked(&phba->num_rsrc_err);
52122 phba->last_rsrc_error_time = jiffies;
52123
52124 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52125 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52126 unsigned long num_rsrc_err, num_cmd_success;
52127 int i;
52128
52129 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52130 - num_cmd_success = atomic_read(&phba->num_cmd_success);
52131 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52132 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52133
52134 /*
52135 * The error and success command counters are global per
52136 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52137 }
52138 }
52139 lpfc_destroy_vport_work_array(phba, vports);
52140 - atomic_set(&phba->num_rsrc_err, 0);
52141 - atomic_set(&phba->num_cmd_success, 0);
52142 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
52143 + atomic_set_unchecked(&phba->num_cmd_success, 0);
52144 }
52145
52146 /**
52147 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52148 index dd46101..ca80eb9 100644
52149 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52150 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52151 @@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
52152 {
52153 struct scsi_device *sdev = to_scsi_device(dev);
52154 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52155 - static struct _raid_device *raid_device;
52156 + struct _raid_device *raid_device;
52157 unsigned long flags;
52158 Mpi2RaidVolPage0_t vol_pg0;
52159 Mpi2ConfigReply_t mpi_reply;
52160 @@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
52161 {
52162 struct scsi_device *sdev = to_scsi_device(dev);
52163 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52164 - static struct _raid_device *raid_device;
52165 + struct _raid_device *raid_device;
52166 unsigned long flags;
52167 Mpi2RaidVolPage0_t vol_pg0;
52168 Mpi2ConfigReply_t mpi_reply;
52169 @@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52170 Mpi2EventDataIrOperationStatus_t *event_data =
52171 (Mpi2EventDataIrOperationStatus_t *)
52172 fw_event->event_data;
52173 - static struct _raid_device *raid_device;
52174 + struct _raid_device *raid_device;
52175 unsigned long flags;
52176 u16 handle;
52177
52178 @@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52179 u64 sas_address;
52180 struct _sas_device *sas_device;
52181 struct _sas_node *expander_device;
52182 - static struct _raid_device *raid_device;
52183 + struct _raid_device *raid_device;
52184 u8 retry_count;
52185 unsigned long flags;
52186
52187 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52188 index 6f3275d..fa5e6b6 100644
52189 --- a/drivers/scsi/pmcraid.c
52190 +++ b/drivers/scsi/pmcraid.c
52191 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52192 res->scsi_dev = scsi_dev;
52193 scsi_dev->hostdata = res;
52194 res->change_detected = 0;
52195 - atomic_set(&res->read_failures, 0);
52196 - atomic_set(&res->write_failures, 0);
52197 + atomic_set_unchecked(&res->read_failures, 0);
52198 + atomic_set_unchecked(&res->write_failures, 0);
52199 rc = 0;
52200 }
52201 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52202 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52203
52204 /* If this was a SCSI read/write command keep count of errors */
52205 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52206 - atomic_inc(&res->read_failures);
52207 + atomic_inc_unchecked(&res->read_failures);
52208 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52209 - atomic_inc(&res->write_failures);
52210 + atomic_inc_unchecked(&res->write_failures);
52211
52212 if (!RES_IS_GSCSI(res->cfg_entry) &&
52213 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52214 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52215 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52216 * hrrq_id assigned here in queuecommand
52217 */
52218 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52219 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52220 pinstance->num_hrrq;
52221 cmd->cmd_done = pmcraid_io_done;
52222
52223 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52224 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52225 * hrrq_id assigned here in queuecommand
52226 */
52227 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52228 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52229 pinstance->num_hrrq;
52230
52231 if (request_size) {
52232 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52233
52234 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52235 /* add resources only after host is added into system */
52236 - if (!atomic_read(&pinstance->expose_resources))
52237 + if (!atomic_read_unchecked(&pinstance->expose_resources))
52238 return;
52239
52240 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52241 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52242 init_waitqueue_head(&pinstance->reset_wait_q);
52243
52244 atomic_set(&pinstance->outstanding_cmds, 0);
52245 - atomic_set(&pinstance->last_message_id, 0);
52246 - atomic_set(&pinstance->expose_resources, 0);
52247 + atomic_set_unchecked(&pinstance->last_message_id, 0);
52248 + atomic_set_unchecked(&pinstance->expose_resources, 0);
52249
52250 INIT_LIST_HEAD(&pinstance->free_res_q);
52251 INIT_LIST_HEAD(&pinstance->used_res_q);
52252 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52253 /* Schedule worker thread to handle CCN and take care of adding and
52254 * removing devices to OS
52255 */
52256 - atomic_set(&pinstance->expose_resources, 1);
52257 + atomic_set_unchecked(&pinstance->expose_resources, 1);
52258 schedule_work(&pinstance->worker_q);
52259 return rc;
52260
52261 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52262 index e1d150f..6c6df44 100644
52263 --- a/drivers/scsi/pmcraid.h
52264 +++ b/drivers/scsi/pmcraid.h
52265 @@ -748,7 +748,7 @@ struct pmcraid_instance {
52266 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52267
52268 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52269 - atomic_t last_message_id;
52270 + atomic_unchecked_t last_message_id;
52271
52272 /* configuration table */
52273 struct pmcraid_config_table *cfg_table;
52274 @@ -777,7 +777,7 @@ struct pmcraid_instance {
52275 atomic_t outstanding_cmds;
52276
52277 /* should add/delete resources to mid-layer now ?*/
52278 - atomic_t expose_resources;
52279 + atomic_unchecked_t expose_resources;
52280
52281
52282
52283 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52284 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52285 };
52286 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52287 - atomic_t read_failures; /* count of failed READ commands */
52288 - atomic_t write_failures; /* count of failed WRITE commands */
52289 + atomic_unchecked_t read_failures; /* count of failed READ commands */
52290 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52291
52292 /* To indicate add/delete/modify during CCN */
52293 u8 change_detected;
52294 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52295 index 16fe519..3b1ec82 100644
52296 --- a/drivers/scsi/qla2xxx/qla_attr.c
52297 +++ b/drivers/scsi/qla2xxx/qla_attr.c
52298 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52299 return 0;
52300 }
52301
52302 -struct fc_function_template qla2xxx_transport_functions = {
52303 +fc_function_template_no_const qla2xxx_transport_functions = {
52304
52305 .show_host_node_name = 1,
52306 .show_host_port_name = 1,
52307 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52308 .bsg_timeout = qla24xx_bsg_timeout,
52309 };
52310
52311 -struct fc_function_template qla2xxx_transport_vport_functions = {
52312 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
52313
52314 .show_host_node_name = 1,
52315 .show_host_port_name = 1,
52316 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52317 index d646540..5b13554 100644
52318 --- a/drivers/scsi/qla2xxx/qla_gbl.h
52319 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
52320 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52321 struct device_attribute;
52322 extern struct device_attribute *qla2x00_host_attrs[];
52323 struct fc_function_template;
52324 -extern struct fc_function_template qla2xxx_transport_functions;
52325 -extern struct fc_function_template qla2xxx_transport_vport_functions;
52326 +extern fc_function_template_no_const qla2xxx_transport_functions;
52327 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52328 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52329 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52330 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52331 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52332 index 8252c0e..613adad 100644
52333 --- a/drivers/scsi/qla2xxx/qla_os.c
52334 +++ b/drivers/scsi/qla2xxx/qla_os.c
52335 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52336 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52337 /* Ok, a 64bit DMA mask is applicable. */
52338 ha->flags.enable_64bit_addressing = 1;
52339 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52340 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52341 + pax_open_kernel();
52342 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52343 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52344 + pax_close_kernel();
52345 return;
52346 }
52347 }
52348 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52349 index 8f6d0fb..1b21097 100644
52350 --- a/drivers/scsi/qla4xxx/ql4_def.h
52351 +++ b/drivers/scsi/qla4xxx/ql4_def.h
52352 @@ -305,7 +305,7 @@ struct ddb_entry {
52353 * (4000 only) */
52354 atomic_t relogin_timer; /* Max Time to wait for
52355 * relogin to complete */
52356 - atomic_t relogin_retry_count; /* Num of times relogin has been
52357 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52358 * retried */
52359 uint32_t default_time2wait; /* Default Min time between
52360 * relogins (+aens) */
52361 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52362 index 199fcf7..3c3a918 100644
52363 --- a/drivers/scsi/qla4xxx/ql4_os.c
52364 +++ b/drivers/scsi/qla4xxx/ql4_os.c
52365 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52366 */
52367 if (!iscsi_is_session_online(cls_sess)) {
52368 /* Reset retry relogin timer */
52369 - atomic_inc(&ddb_entry->relogin_retry_count);
52370 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52371 DEBUG2(ql4_printk(KERN_INFO, ha,
52372 "%s: index[%d] relogin timed out-retrying"
52373 " relogin (%d), retry (%d)\n", __func__,
52374 ddb_entry->fw_ddb_index,
52375 - atomic_read(&ddb_entry->relogin_retry_count),
52376 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52377 ddb_entry->default_time2wait + 4));
52378 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52379 atomic_set(&ddb_entry->retry_relogin_timer,
52380 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52381
52382 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52383 atomic_set(&ddb_entry->relogin_timer, 0);
52384 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52385 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52386 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52387 ddb_entry->default_relogin_timeout =
52388 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52389 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52390 index d81f3cc..0093e5b 100644
52391 --- a/drivers/scsi/scsi.c
52392 +++ b/drivers/scsi/scsi.c
52393 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52394 struct Scsi_Host *host = cmd->device->host;
52395 int rtn = 0;
52396
52397 - atomic_inc(&cmd->device->iorequest_cnt);
52398 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52399
52400 /* check if the device is still usable */
52401 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52402 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52403 index 7cb8c73..14561b5 100644
52404 --- a/drivers/scsi/scsi_lib.c
52405 +++ b/drivers/scsi/scsi_lib.c
52406 @@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52407 shost = sdev->host;
52408 scsi_init_cmd_errh(cmd);
52409 cmd->result = DID_NO_CONNECT << 16;
52410 - atomic_inc(&cmd->device->iorequest_cnt);
52411 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52412
52413 /*
52414 * SCSI request completion path will do scsi_device_unbusy(),
52415 @@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52416
52417 INIT_LIST_HEAD(&cmd->eh_entry);
52418
52419 - atomic_inc(&cmd->device->iodone_cnt);
52420 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52421 if (cmd->result)
52422 - atomic_inc(&cmd->device->ioerr_cnt);
52423 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52424
52425 disposition = scsi_decide_disposition(cmd);
52426 if (disposition != SUCCESS &&
52427 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52428 index 8b4105a..1f58363 100644
52429 --- a/drivers/scsi/scsi_sysfs.c
52430 +++ b/drivers/scsi/scsi_sysfs.c
52431 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52432 char *buf) \
52433 { \
52434 struct scsi_device *sdev = to_scsi_device(dev); \
52435 - unsigned long long count = atomic_read(&sdev->field); \
52436 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52437 return snprintf(buf, 20, "0x%llx\n", count); \
52438 } \
52439 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52440 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52441 index 5d6f348..18778a6b 100644
52442 --- a/drivers/scsi/scsi_transport_fc.c
52443 +++ b/drivers/scsi/scsi_transport_fc.c
52444 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52445 * Netlink Infrastructure
52446 */
52447
52448 -static atomic_t fc_event_seq;
52449 +static atomic_unchecked_t fc_event_seq;
52450
52451 /**
52452 * fc_get_event_number - Obtain the next sequential FC event number
52453 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52454 u32
52455 fc_get_event_number(void)
52456 {
52457 - return atomic_add_return(1, &fc_event_seq);
52458 + return atomic_add_return_unchecked(1, &fc_event_seq);
52459 }
52460 EXPORT_SYMBOL(fc_get_event_number);
52461
52462 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52463 {
52464 int error;
52465
52466 - atomic_set(&fc_event_seq, 0);
52467 + atomic_set_unchecked(&fc_event_seq, 0);
52468
52469 error = transport_class_register(&fc_host_class);
52470 if (error)
52471 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52472 char *cp;
52473
52474 *val = simple_strtoul(buf, &cp, 0);
52475 - if ((*cp && (*cp != '\n')) || (*val < 0))
52476 + if (*cp && (*cp != '\n'))
52477 return -EINVAL;
52478 /*
52479 * Check for overflow; dev_loss_tmo is u32
52480 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52481 index 67d43e3..8cee73c 100644
52482 --- a/drivers/scsi/scsi_transport_iscsi.c
52483 +++ b/drivers/scsi/scsi_transport_iscsi.c
52484 @@ -79,7 +79,7 @@ struct iscsi_internal {
52485 struct transport_container session_cont;
52486 };
52487
52488 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52489 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52490 static struct workqueue_struct *iscsi_eh_timer_workq;
52491
52492 static DEFINE_IDA(iscsi_sess_ida);
52493 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52494 int err;
52495
52496 ihost = shost->shost_data;
52497 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52498 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52499
52500 if (target_id == ISCSI_MAX_TARGET) {
52501 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52502 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52503 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52504 ISCSI_TRANSPORT_VERSION);
52505
52506 - atomic_set(&iscsi_session_nr, 0);
52507 + atomic_set_unchecked(&iscsi_session_nr, 0);
52508
52509 err = class_register(&iscsi_transport_class);
52510 if (err)
52511 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52512 index ae45bd9..c32a586 100644
52513 --- a/drivers/scsi/scsi_transport_srp.c
52514 +++ b/drivers/scsi/scsi_transport_srp.c
52515 @@ -35,7 +35,7 @@
52516 #include "scsi_priv.h"
52517
52518 struct srp_host_attrs {
52519 - atomic_t next_port_id;
52520 + atomic_unchecked_t next_port_id;
52521 };
52522 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52523
52524 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52525 struct Scsi_Host *shost = dev_to_shost(dev);
52526 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52527
52528 - atomic_set(&srp_host->next_port_id, 0);
52529 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52530 return 0;
52531 }
52532
52533 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52534 rport_fast_io_fail_timedout);
52535 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52536
52537 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52538 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52539 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52540
52541 transport_setup_device(&rport->dev);
52542 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52543 index 2c2041c..9d94085 100644
52544 --- a/drivers/scsi/sd.c
52545 +++ b/drivers/scsi/sd.c
52546 @@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
52547 sdkp->disk = gd;
52548 sdkp->index = index;
52549 atomic_set(&sdkp->openers, 0);
52550 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52551 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52552
52553 if (!sdp->request_queue->rq_timeout) {
52554 if (sdp->type != TYPE_MOD)
52555 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52556 index 01cf888..59e0475 100644
52557 --- a/drivers/scsi/sg.c
52558 +++ b/drivers/scsi/sg.c
52559 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52560 sdp->disk->disk_name,
52561 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52562 NULL,
52563 - (char *)arg);
52564 + (char __user *)arg);
52565 case BLKTRACESTART:
52566 return blk_trace_startstop(sdp->device->request_queue, 1);
52567 case BLKTRACESTOP:
52568 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52569 index 11a5043..e36f04c 100644
52570 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52571 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52572 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52573 return i;
52574 }
52575
52576 -static struct bin_attribute fuse_bin_attr = {
52577 +static bin_attribute_no_const fuse_bin_attr = {
52578 .attr = { .name = "fuse", .mode = S_IRUGO, },
52579 .read = fuse_read,
52580 };
52581 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52582 index 2bf2dfa..b4d9008 100644
52583 --- a/drivers/spi/spi.c
52584 +++ b/drivers/spi/spi.c
52585 @@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
52586 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52587
52588 /* portable code must never pass more than 32 bytes */
52589 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52590 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52591
52592 static u8 *buf;
52593
52594 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52595 index b41429f..2de5373 100644
52596 --- a/drivers/staging/android/timed_output.c
52597 +++ b/drivers/staging/android/timed_output.c
52598 @@ -25,7 +25,7 @@
52599 #include "timed_output.h"
52600
52601 static struct class *timed_output_class;
52602 -static atomic_t device_count;
52603 +static atomic_unchecked_t device_count;
52604
52605 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52606 char *buf)
52607 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52608 timed_output_class = class_create(THIS_MODULE, "timed_output");
52609 if (IS_ERR(timed_output_class))
52610 return PTR_ERR(timed_output_class);
52611 - atomic_set(&device_count, 0);
52612 + atomic_set_unchecked(&device_count, 0);
52613 timed_output_class->dev_groups = timed_output_groups;
52614 }
52615
52616 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52617 if (ret < 0)
52618 return ret;
52619
52620 - tdev->index = atomic_inc_return(&device_count);
52621 + tdev->index = atomic_inc_return_unchecked(&device_count);
52622 tdev->dev = device_create(timed_output_class, NULL,
52623 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52624 if (IS_ERR(tdev->dev))
52625 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52626 index 001348c..cfaac8a 100644
52627 --- a/drivers/staging/gdm724x/gdm_tty.c
52628 +++ b/drivers/staging/gdm724x/gdm_tty.c
52629 @@ -44,7 +44,7 @@
52630 #define gdm_tty_send_control(n, r, v, d, l) (\
52631 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52632
52633 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52634 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52635
52636 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52637 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52638 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52639 index 6b22106..6c6e641 100644
52640 --- a/drivers/staging/imx-drm/imx-drm-core.c
52641 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52642 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52643 if (imxdrm->pipes >= MAX_CRTC)
52644 return -EINVAL;
52645
52646 - if (imxdrm->drm->open_count)
52647 + if (local_read(&imxdrm->drm->open_count))
52648 return -EBUSY;
52649
52650 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52651 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52652 index 503b2d7..c918745 100644
52653 --- a/drivers/staging/line6/driver.c
52654 +++ b/drivers/staging/line6/driver.c
52655 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52656 {
52657 struct usb_device *usbdev = line6->usbdev;
52658 int ret;
52659 - unsigned char len;
52660 + unsigned char *plen;
52661
52662 /* query the serial number: */
52663 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52664 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52665 return ret;
52666 }
52667
52668 + plen = kmalloc(1, GFP_KERNEL);
52669 + if (plen == NULL)
52670 + return -ENOMEM;
52671 +
52672 /* Wait for data length. We'll get 0xff until length arrives. */
52673 do {
52674 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52675 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52676 USB_DIR_IN,
52677 - 0x0012, 0x0000, &len, 1,
52678 + 0x0012, 0x0000, plen, 1,
52679 LINE6_TIMEOUT * HZ);
52680 if (ret < 0) {
52681 dev_err(line6->ifcdev,
52682 "receive length failed (error %d)\n", ret);
52683 + kfree(plen);
52684 return ret;
52685 }
52686 - } while (len == 0xff);
52687 + } while (*plen == 0xff);
52688
52689 - if (len != datalen) {
52690 + if (*plen != datalen) {
52691 /* should be equal or something went wrong */
52692 dev_err(line6->ifcdev,
52693 "length mismatch (expected %d, got %d)\n",
52694 - (int)datalen, (int)len);
52695 + (int)datalen, (int)*plen);
52696 + kfree(plen);
52697 return -EINVAL;
52698 }
52699 + kfree(plen);
52700
52701 /* receive the result: */
52702 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52703 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52704 index bcce919..f30fcf9 100644
52705 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52706 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52707 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52708 return 0;
52709 }
52710
52711 -sfw_test_client_ops_t brw_test_client;
52712 -void brw_init_test_client(void)
52713 -{
52714 - brw_test_client.tso_init = brw_client_init;
52715 - brw_test_client.tso_fini = brw_client_fini;
52716 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52717 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52718 +sfw_test_client_ops_t brw_test_client = {
52719 + .tso_init = brw_client_init,
52720 + .tso_fini = brw_client_fini,
52721 + .tso_prep_rpc = brw_client_prep_rpc,
52722 + .tso_done_rpc = brw_client_done_rpc,
52723 };
52724
52725 srpc_service_t brw_test_service;
52726 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52727 index 7e83dff..1f9a545 100644
52728 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52729 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52730 @@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
52731
52732 extern sfw_test_client_ops_t ping_test_client;
52733 extern srpc_service_t ping_test_service;
52734 -extern void ping_init_test_client(void);
52735 extern void ping_init_test_service(void);
52736
52737 extern sfw_test_client_ops_t brw_test_client;
52738 extern srpc_service_t brw_test_service;
52739 -extern void brw_init_test_client(void);
52740 extern void brw_init_test_service(void);
52741
52742
52743 @@ -1682,12 +1680,10 @@ sfw_startup (void)
52744 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52745 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52746
52747 - brw_init_test_client();
52748 brw_init_test_service();
52749 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52750 LASSERT (rc == 0);
52751
52752 - ping_init_test_client();
52753 ping_init_test_service();
52754 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52755 LASSERT (rc == 0);
52756 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52757 index 750cac4..e4d751f 100644
52758 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52759 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52760 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52761 return 0;
52762 }
52763
52764 -sfw_test_client_ops_t ping_test_client;
52765 -void ping_init_test_client(void)
52766 -{
52767 - ping_test_client.tso_init = ping_client_init;
52768 - ping_test_client.tso_fini = ping_client_fini;
52769 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52770 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52771 -}
52772 +sfw_test_client_ops_t ping_test_client = {
52773 + .tso_init = ping_client_init,
52774 + .tso_fini = ping_client_fini,
52775 + .tso_prep_rpc = ping_client_prep_rpc,
52776 + .tso_done_rpc = ping_client_done_rpc,
52777 +};
52778
52779 srpc_service_t ping_test_service;
52780 void ping_init_test_service(void)
52781 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52782 index 30b1812f..9e5bd0b 100644
52783 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52784 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52785 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
52786 ldlm_completion_callback lcs_completion;
52787 ldlm_blocking_callback lcs_blocking;
52788 ldlm_glimpse_callback lcs_glimpse;
52789 -};
52790 +} __no_const;
52791
52792 /* ldlm_lockd.c */
52793 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52794 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52795 index 489bdd3..65058081 100644
52796 --- a/drivers/staging/lustre/lustre/include/obd.h
52797 +++ b/drivers/staging/lustre/lustre/include/obd.h
52798 @@ -1438,7 +1438,7 @@ struct md_ops {
52799 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52800 * wrapper function in include/linux/obd_class.h.
52801 */
52802 -};
52803 +} __no_const;
52804
52805 struct lsm_operations {
52806 void (*lsm_free)(struct lov_stripe_md *);
52807 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52808 index b798daa..b28ca8f 100644
52809 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52810 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52811 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52812 int added = (mode == LCK_NL);
52813 int overlaps = 0;
52814 int splitted = 0;
52815 - const struct ldlm_callback_suite null_cbs = { NULL };
52816 + const struct ldlm_callback_suite null_cbs = { };
52817
52818 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52819 *flags, new->l_policy_data.l_flock.owner,
52820 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52821 index 13a9266..3439390 100644
52822 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52823 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52824 @@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52825 void __user *buffer, size_t *lenp, loff_t *ppos)
52826 {
52827 int rc, max_delay_cs;
52828 - struct ctl_table dummy = *table;
52829 + ctl_table_no_const dummy = *table;
52830 long d;
52831
52832 dummy.data = &max_delay_cs;
52833 @@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52834 void __user *buffer, size_t *lenp, loff_t *ppos)
52835 {
52836 int rc, min_delay_cs;
52837 - struct ctl_table dummy = *table;
52838 + ctl_table_no_const dummy = *table;
52839 long d;
52840
52841 dummy.data = &min_delay_cs;
52842 @@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52843 void __user *buffer, size_t *lenp, loff_t *ppos)
52844 {
52845 int rc, backoff;
52846 - struct ctl_table dummy = *table;
52847 + ctl_table_no_const dummy = *table;
52848
52849 dummy.data = &backoff;
52850 dummy.proc_handler = &proc_dointvec;
52851 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52852 index 3396858..c0bd996 100644
52853 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52854 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52855 @@ -314,11 +314,11 @@ out:
52856
52857
52858 struct cfs_psdev_ops libcfs_psdev_ops = {
52859 - libcfs_psdev_open,
52860 - libcfs_psdev_release,
52861 - NULL,
52862 - NULL,
52863 - libcfs_ioctl
52864 + .p_open = libcfs_psdev_open,
52865 + .p_close = libcfs_psdev_release,
52866 + .p_read = NULL,
52867 + .p_write = NULL,
52868 + .p_ioctl = libcfs_ioctl
52869 };
52870
52871 extern int insert_proc(void);
52872 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52873 index efa2faf..03a9836 100644
52874 --- a/drivers/staging/lustre/lustre/llite/dir.c
52875 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52876 @@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52877 int mode;
52878 int err;
52879
52880 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52881 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52882 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52883 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52884 lump);
52885 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52886 index a0f4868..139f1fb 100644
52887 --- a/drivers/staging/octeon/ethernet-rx.c
52888 +++ b/drivers/staging/octeon/ethernet-rx.c
52889 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52890 /* Increment RX stats for virtual ports */
52891 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52892 #ifdef CONFIG_64BIT
52893 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52894 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52895 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52896 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52897 #else
52898 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52899 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52900 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52901 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52902 #endif
52903 }
52904 netif_receive_skb(skb);
52905 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52906 dev->name);
52907 */
52908 #ifdef CONFIG_64BIT
52909 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52910 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52911 #else
52912 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52913 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52914 #endif
52915 dev_kfree_skb_irq(skb);
52916 }
52917 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52918 index 2aa7235..ba3c205 100644
52919 --- a/drivers/staging/octeon/ethernet.c
52920 +++ b/drivers/staging/octeon/ethernet.c
52921 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52922 * since the RX tasklet also increments it.
52923 */
52924 #ifdef CONFIG_64BIT
52925 - atomic64_add(rx_status.dropped_packets,
52926 - (atomic64_t *)&priv->stats.rx_dropped);
52927 + atomic64_add_unchecked(rx_status.dropped_packets,
52928 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52929 #else
52930 - atomic_add(rx_status.dropped_packets,
52931 - (atomic_t *)&priv->stats.rx_dropped);
52932 + atomic_add_unchecked(rx_status.dropped_packets,
52933 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52934 #endif
52935 }
52936
52937 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52938 index 56d5c50..a14f4db 100644
52939 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52940 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52941 @@ -234,7 +234,7 @@ struct hal_ops {
52942
52943 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52944 void (*hal_reset_security_engine)(struct adapter *adapter);
52945 -};
52946 +} __no_const;
52947
52948 enum rt_eeprom_type {
52949 EEPROM_93C46,
52950 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52951 index dc23395..cf7e9b1 100644
52952 --- a/drivers/staging/rtl8712/rtl871x_io.h
52953 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52954 @@ -108,7 +108,7 @@ struct _io_ops {
52955 u8 *pmem);
52956 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52957 u8 *pmem);
52958 -};
52959 +} __no_const;
52960
52961 struct io_req {
52962 struct list_head list;
52963 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52964 index 2bf2e2f..84421c9 100644
52965 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52966 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52967 @@ -228,7 +228,7 @@ typedef struct {
52968 void (*device_resume)(ulong busNo, ulong devNo);
52969 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52970 ulong *maxSize);
52971 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52972 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52973
52974 /* These functions live inside visorchipset, and will be called to indicate
52975 * responses to specific events (by code outside of visorchipset).
52976 @@ -243,7 +243,7 @@ typedef struct {
52977 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52978 void (*device_pause)(ulong busNo, ulong devNo, int response);
52979 void (*device_resume)(ulong busNo, ulong devNo, int response);
52980 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52981 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52982
52983 /** Register functions (in the bus driver) to get called by visorchipset
52984 * whenever a bus or device appears for which this service partition is
52985 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52986 index 164136b..7244df5 100644
52987 --- a/drivers/staging/vt6655/hostap.c
52988 +++ b/drivers/staging/vt6655/hostap.c
52989 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
52990 *
52991 */
52992
52993 +static net_device_ops_no_const apdev_netdev_ops;
52994 +
52995 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52996 {
52997 PSDevice apdev_priv;
52998 struct net_device *dev = pDevice->dev;
52999 int ret;
53000 - const struct net_device_ops apdev_netdev_ops = {
53001 - .ndo_start_xmit = pDevice->tx_80211,
53002 - };
53003
53004 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53005
53006 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53007 *apdev_priv = *pDevice;
53008 eth_hw_addr_inherit(pDevice->apdev, dev);
53009
53010 + /* only half broken now */
53011 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53012 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53013
53014 pDevice->apdev->type = ARPHRD_IEEE80211;
53015 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53016 index e7e9372..161f530 100644
53017 --- a/drivers/target/sbp/sbp_target.c
53018 +++ b/drivers/target/sbp/sbp_target.c
53019 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53020
53021 #define SESSION_MAINTENANCE_INTERVAL HZ
53022
53023 -static atomic_t login_id = ATOMIC_INIT(0);
53024 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53025
53026 static void session_maintenance_work(struct work_struct *);
53027 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53028 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
53029 login->lun = se_lun;
53030 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53031 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53032 - login->login_id = atomic_inc_return(&login_id);
53033 + login->login_id = atomic_inc_return_unchecked(&login_id);
53034
53035 login->tgt_agt = sbp_target_agent_register(login);
53036 if (IS_ERR(login->tgt_agt)) {
53037 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53038 index 15a1c13..6c9b96b 100644
53039 --- a/drivers/target/target_core_device.c
53040 +++ b/drivers/target/target_core_device.c
53041 @@ -1526,7 +1526,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53042 spin_lock_init(&dev->se_tmr_lock);
53043 spin_lock_init(&dev->qf_cmd_lock);
53044 sema_init(&dev->caw_sem, 1);
53045 - atomic_set(&dev->dev_ordered_id, 0);
53046 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
53047 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53048 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53049 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53050 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53051 index a9c77b5..024a07d 100644
53052 --- a/drivers/target/target_core_transport.c
53053 +++ b/drivers/target/target_core_transport.c
53054 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53055 * Used to determine when ORDERED commands should go from
53056 * Dormant to Active status.
53057 */
53058 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53059 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53060 smp_mb__after_atomic();
53061 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53062 cmd->se_ordered_id, cmd->sam_task_attr,
53063 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53064 index 4b2b999..cad9fa5 100644
53065 --- a/drivers/thermal/of-thermal.c
53066 +++ b/drivers/thermal/of-thermal.c
53067 @@ -30,6 +30,7 @@
53068 #include <linux/err.h>
53069 #include <linux/export.h>
53070 #include <linux/string.h>
53071 +#include <linux/mm.h>
53072
53073 #include "thermal_core.h"
53074
53075 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53076 tz->get_trend = get_trend;
53077 tz->sensor_data = data;
53078
53079 - tzd->ops->get_temp = of_thermal_get_temp;
53080 - tzd->ops->get_trend = of_thermal_get_trend;
53081 + pax_open_kernel();
53082 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53083 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53084 + pax_close_kernel();
53085 mutex_unlock(&tzd->lock);
53086
53087 return tzd;
53088 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53089 return;
53090
53091 mutex_lock(&tzd->lock);
53092 - tzd->ops->get_temp = NULL;
53093 - tzd->ops->get_trend = NULL;
53094 + pax_open_kernel();
53095 + *(void **)&tzd->ops->get_temp = NULL;
53096 + *(void **)&tzd->ops->get_trend = NULL;
53097 + pax_close_kernel();
53098
53099 tz->get_temp = NULL;
53100 tz->get_trend = NULL;
53101 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53102 index fd66f57..48e6376 100644
53103 --- a/drivers/tty/cyclades.c
53104 +++ b/drivers/tty/cyclades.c
53105 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53106 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53107 info->port.count);
53108 #endif
53109 - info->port.count++;
53110 + atomic_inc(&info->port.count);
53111 #ifdef CY_DEBUG_COUNT
53112 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53113 - current->pid, info->port.count);
53114 + current->pid, atomic_read(&info->port.count));
53115 #endif
53116
53117 /*
53118 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53119 for (j = 0; j < cy_card[i].nports; j++) {
53120 info = &cy_card[i].ports[j];
53121
53122 - if (info->port.count) {
53123 + if (atomic_read(&info->port.count)) {
53124 /* XXX is the ldisc num worth this? */
53125 struct tty_struct *tty;
53126 struct tty_ldisc *ld;
53127 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53128 index 4fcec1d..5a036f7 100644
53129 --- a/drivers/tty/hvc/hvc_console.c
53130 +++ b/drivers/tty/hvc/hvc_console.c
53131 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53132
53133 spin_lock_irqsave(&hp->port.lock, flags);
53134 /* Check and then increment for fast path open. */
53135 - if (hp->port.count++ > 0) {
53136 + if (atomic_inc_return(&hp->port.count) > 1) {
53137 spin_unlock_irqrestore(&hp->port.lock, flags);
53138 hvc_kick();
53139 return 0;
53140 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53141
53142 spin_lock_irqsave(&hp->port.lock, flags);
53143
53144 - if (--hp->port.count == 0) {
53145 + if (atomic_dec_return(&hp->port.count) == 0) {
53146 spin_unlock_irqrestore(&hp->port.lock, flags);
53147 /* We are done with the tty pointer now. */
53148 tty_port_tty_set(&hp->port, NULL);
53149 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53150 */
53151 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53152 } else {
53153 - if (hp->port.count < 0)
53154 + if (atomic_read(&hp->port.count) < 0)
53155 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53156 - hp->vtermno, hp->port.count);
53157 + hp->vtermno, atomic_read(&hp->port.count));
53158 spin_unlock_irqrestore(&hp->port.lock, flags);
53159 }
53160 }
53161 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53162 * open->hangup case this can be called after the final close so prevent
53163 * that from happening for now.
53164 */
53165 - if (hp->port.count <= 0) {
53166 + if (atomic_read(&hp->port.count) <= 0) {
53167 spin_unlock_irqrestore(&hp->port.lock, flags);
53168 return;
53169 }
53170
53171 - hp->port.count = 0;
53172 + atomic_set(&hp->port.count, 0);
53173 spin_unlock_irqrestore(&hp->port.lock, flags);
53174 tty_port_tty_set(&hp->port, NULL);
53175
53176 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53177 return -EPIPE;
53178
53179 /* FIXME what's this (unprotected) check for? */
53180 - if (hp->port.count <= 0)
53181 + if (atomic_read(&hp->port.count) <= 0)
53182 return -EIO;
53183
53184 spin_lock_irqsave(&hp->lock, flags);
53185 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53186 index 81e939e..95ead10 100644
53187 --- a/drivers/tty/hvc/hvcs.c
53188 +++ b/drivers/tty/hvc/hvcs.c
53189 @@ -83,6 +83,7 @@
53190 #include <asm/hvcserver.h>
53191 #include <asm/uaccess.h>
53192 #include <asm/vio.h>
53193 +#include <asm/local.h>
53194
53195 /*
53196 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53197 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53198
53199 spin_lock_irqsave(&hvcsd->lock, flags);
53200
53201 - if (hvcsd->port.count > 0) {
53202 + if (atomic_read(&hvcsd->port.count) > 0) {
53203 spin_unlock_irqrestore(&hvcsd->lock, flags);
53204 printk(KERN_INFO "HVCS: vterm state unchanged. "
53205 "The hvcs device node is still in use.\n");
53206 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53207 }
53208 }
53209
53210 - hvcsd->port.count = 0;
53211 + atomic_set(&hvcsd->port.count, 0);
53212 hvcsd->port.tty = tty;
53213 tty->driver_data = hvcsd;
53214
53215 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53216 unsigned long flags;
53217
53218 spin_lock_irqsave(&hvcsd->lock, flags);
53219 - hvcsd->port.count++;
53220 + atomic_inc(&hvcsd->port.count);
53221 hvcsd->todo_mask |= HVCS_SCHED_READ;
53222 spin_unlock_irqrestore(&hvcsd->lock, flags);
53223
53224 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53225 hvcsd = tty->driver_data;
53226
53227 spin_lock_irqsave(&hvcsd->lock, flags);
53228 - if (--hvcsd->port.count == 0) {
53229 + if (atomic_dec_and_test(&hvcsd->port.count)) {
53230
53231 vio_disable_interrupts(hvcsd->vdev);
53232
53233 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53234
53235 free_irq(irq, hvcsd);
53236 return;
53237 - } else if (hvcsd->port.count < 0) {
53238 + } else if (atomic_read(&hvcsd->port.count) < 0) {
53239 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53240 " is missmanaged.\n",
53241 - hvcsd->vdev->unit_address, hvcsd->port.count);
53242 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53243 }
53244
53245 spin_unlock_irqrestore(&hvcsd->lock, flags);
53246 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53247
53248 spin_lock_irqsave(&hvcsd->lock, flags);
53249 /* Preserve this so that we know how many kref refs to put */
53250 - temp_open_count = hvcsd->port.count;
53251 + temp_open_count = atomic_read(&hvcsd->port.count);
53252
53253 /*
53254 * Don't kref put inside the spinlock because the destruction
53255 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53256 tty->driver_data = NULL;
53257 hvcsd->port.tty = NULL;
53258
53259 - hvcsd->port.count = 0;
53260 + atomic_set(&hvcsd->port.count, 0);
53261
53262 /* This will drop any buffered data on the floor which is OK in a hangup
53263 * scenario. */
53264 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53265 * the middle of a write operation? This is a crummy place to do this
53266 * but we want to keep it all in the spinlock.
53267 */
53268 - if (hvcsd->port.count <= 0) {
53269 + if (atomic_read(&hvcsd->port.count) <= 0) {
53270 spin_unlock_irqrestore(&hvcsd->lock, flags);
53271 return -ENODEV;
53272 }
53273 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53274 {
53275 struct hvcs_struct *hvcsd = tty->driver_data;
53276
53277 - if (!hvcsd || hvcsd->port.count <= 0)
53278 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53279 return 0;
53280
53281 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53282 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53283 index 4190199..06d5bfa 100644
53284 --- a/drivers/tty/hvc/hvsi.c
53285 +++ b/drivers/tty/hvc/hvsi.c
53286 @@ -85,7 +85,7 @@ struct hvsi_struct {
53287 int n_outbuf;
53288 uint32_t vtermno;
53289 uint32_t virq;
53290 - atomic_t seqno; /* HVSI packet sequence number */
53291 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
53292 uint16_t mctrl;
53293 uint8_t state; /* HVSI protocol state */
53294 uint8_t flags;
53295 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53296
53297 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53298 packet.hdr.len = sizeof(struct hvsi_query_response);
53299 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53300 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53301 packet.verb = VSV_SEND_VERSION_NUMBER;
53302 packet.u.version = HVSI_VERSION;
53303 packet.query_seqno = query_seqno+1;
53304 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53305
53306 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53307 packet.hdr.len = sizeof(struct hvsi_query);
53308 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53309 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53310 packet.verb = verb;
53311
53312 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53313 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53314 int wrote;
53315
53316 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53317 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53318 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53319 packet.hdr.len = sizeof(struct hvsi_control);
53320 packet.verb = VSV_SET_MODEM_CTL;
53321 packet.mask = HVSI_TSDTR;
53322 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53323 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53324
53325 packet.hdr.type = VS_DATA_PACKET_HEADER;
53326 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53327 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53328 packet.hdr.len = count + sizeof(struct hvsi_header);
53329 memcpy(&packet.data, buf, count);
53330
53331 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53332 struct hvsi_control packet __ALIGNED__;
53333
53334 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53335 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53336 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53337 packet.hdr.len = 6;
53338 packet.verb = VSV_CLOSE_PROTOCOL;
53339
53340 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53341
53342 tty_port_tty_set(&hp->port, tty);
53343 spin_lock_irqsave(&hp->lock, flags);
53344 - hp->port.count++;
53345 + atomic_inc(&hp->port.count);
53346 atomic_set(&hp->seqno, 0);
53347 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53348 spin_unlock_irqrestore(&hp->lock, flags);
53349 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53350
53351 spin_lock_irqsave(&hp->lock, flags);
53352
53353 - if (--hp->port.count == 0) {
53354 + if (atomic_dec_return(&hp->port.count) == 0) {
53355 tty_port_tty_set(&hp->port, NULL);
53356 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53357
53358 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53359
53360 spin_lock_irqsave(&hp->lock, flags);
53361 }
53362 - } else if (hp->port.count < 0)
53363 + } else if (atomic_read(&hp->port.count) < 0)
53364 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53365 - hp - hvsi_ports, hp->port.count);
53366 + hp - hvsi_ports, atomic_read(&hp->port.count));
53367
53368 spin_unlock_irqrestore(&hp->lock, flags);
53369 }
53370 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53371 tty_port_tty_set(&hp->port, NULL);
53372
53373 spin_lock_irqsave(&hp->lock, flags);
53374 - hp->port.count = 0;
53375 + atomic_set(&hp->port.count, 0);
53376 hp->n_outbuf = 0;
53377 spin_unlock_irqrestore(&hp->lock, flags);
53378 }
53379 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53380 index 7ae6c29..05c6dba 100644
53381 --- a/drivers/tty/hvc/hvsi_lib.c
53382 +++ b/drivers/tty/hvc/hvsi_lib.c
53383 @@ -8,7 +8,7 @@
53384
53385 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53386 {
53387 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53388 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53389
53390 /* Assumes that always succeeds, works in practice */
53391 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53392 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53393
53394 /* Reset state */
53395 pv->established = 0;
53396 - atomic_set(&pv->seqno, 0);
53397 + atomic_set_unchecked(&pv->seqno, 0);
53398
53399 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53400
53401 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53402 index 345cebb..d5a1e9e 100644
53403 --- a/drivers/tty/ipwireless/tty.c
53404 +++ b/drivers/tty/ipwireless/tty.c
53405 @@ -28,6 +28,7 @@
53406 #include <linux/tty_driver.h>
53407 #include <linux/tty_flip.h>
53408 #include <linux/uaccess.h>
53409 +#include <asm/local.h>
53410
53411 #include "tty.h"
53412 #include "network.h"
53413 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53414 return -ENODEV;
53415
53416 mutex_lock(&tty->ipw_tty_mutex);
53417 - if (tty->port.count == 0)
53418 + if (atomic_read(&tty->port.count) == 0)
53419 tty->tx_bytes_queued = 0;
53420
53421 - tty->port.count++;
53422 + atomic_inc(&tty->port.count);
53423
53424 tty->port.tty = linux_tty;
53425 linux_tty->driver_data = tty;
53426 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53427
53428 static void do_ipw_close(struct ipw_tty *tty)
53429 {
53430 - tty->port.count--;
53431 -
53432 - if (tty->port.count == 0) {
53433 + if (atomic_dec_return(&tty->port.count) == 0) {
53434 struct tty_struct *linux_tty = tty->port.tty;
53435
53436 if (linux_tty != NULL) {
53437 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53438 return;
53439
53440 mutex_lock(&tty->ipw_tty_mutex);
53441 - if (tty->port.count == 0) {
53442 + if (atomic_read(&tty->port.count) == 0) {
53443 mutex_unlock(&tty->ipw_tty_mutex);
53444 return;
53445 }
53446 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53447
53448 mutex_lock(&tty->ipw_tty_mutex);
53449
53450 - if (!tty->port.count) {
53451 + if (!atomic_read(&tty->port.count)) {
53452 mutex_unlock(&tty->ipw_tty_mutex);
53453 return;
53454 }
53455 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53456 return -ENODEV;
53457
53458 mutex_lock(&tty->ipw_tty_mutex);
53459 - if (!tty->port.count) {
53460 + if (!atomic_read(&tty->port.count)) {
53461 mutex_unlock(&tty->ipw_tty_mutex);
53462 return -EINVAL;
53463 }
53464 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53465 if (!tty)
53466 return -ENODEV;
53467
53468 - if (!tty->port.count)
53469 + if (!atomic_read(&tty->port.count))
53470 return -EINVAL;
53471
53472 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53473 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53474 if (!tty)
53475 return 0;
53476
53477 - if (!tty->port.count)
53478 + if (!atomic_read(&tty->port.count))
53479 return 0;
53480
53481 return tty->tx_bytes_queued;
53482 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53483 if (!tty)
53484 return -ENODEV;
53485
53486 - if (!tty->port.count)
53487 + if (!atomic_read(&tty->port.count))
53488 return -EINVAL;
53489
53490 return get_control_lines(tty);
53491 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53492 if (!tty)
53493 return -ENODEV;
53494
53495 - if (!tty->port.count)
53496 + if (!atomic_read(&tty->port.count))
53497 return -EINVAL;
53498
53499 return set_control_lines(tty, set, clear);
53500 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53501 if (!tty)
53502 return -ENODEV;
53503
53504 - if (!tty->port.count)
53505 + if (!atomic_read(&tty->port.count))
53506 return -EINVAL;
53507
53508 /* FIXME: Exactly how is the tty object locked here .. */
53509 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53510 * are gone */
53511 mutex_lock(&ttyj->ipw_tty_mutex);
53512 }
53513 - while (ttyj->port.count)
53514 + while (atomic_read(&ttyj->port.count))
53515 do_ipw_close(ttyj);
53516 ipwireless_disassociate_network_ttys(network,
53517 ttyj->channel_idx);
53518 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53519 index 1deaca4..c8582d4 100644
53520 --- a/drivers/tty/moxa.c
53521 +++ b/drivers/tty/moxa.c
53522 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53523 }
53524
53525 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53526 - ch->port.count++;
53527 + atomic_inc(&ch->port.count);
53528 tty->driver_data = ch;
53529 tty_port_tty_set(&ch->port, tty);
53530 mutex_lock(&ch->port.mutex);
53531 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53532 index c434376..114ce13 100644
53533 --- a/drivers/tty/n_gsm.c
53534 +++ b/drivers/tty/n_gsm.c
53535 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53536 spin_lock_init(&dlci->lock);
53537 mutex_init(&dlci->mutex);
53538 dlci->fifo = &dlci->_fifo;
53539 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53540 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53541 kfree(dlci);
53542 return NULL;
53543 }
53544 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53545 struct gsm_dlci *dlci = tty->driver_data;
53546 struct tty_port *port = &dlci->port;
53547
53548 - port->count++;
53549 + atomic_inc(&port->count);
53550 tty_port_tty_set(port, tty);
53551
53552 dlci->modem_rx = 0;
53553 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53554 index f44f1ba..a8d5915 100644
53555 --- a/drivers/tty/n_tty.c
53556 +++ b/drivers/tty/n_tty.c
53557 @@ -115,7 +115,7 @@ struct n_tty_data {
53558 int minimum_to_wake;
53559
53560 /* consumer-published */
53561 - size_t read_tail;
53562 + size_t read_tail __intentional_overflow(-1);
53563 size_t line_start;
53564
53565 /* protected by output lock */
53566 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53567 {
53568 *ops = tty_ldisc_N_TTY;
53569 ops->owner = NULL;
53570 - ops->refcount = ops->flags = 0;
53571 + atomic_set(&ops->refcount, 0);
53572 + ops->flags = 0;
53573 }
53574 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53575 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53576 index 9bbdb1d..dc514ee 100644
53577 --- a/drivers/tty/pty.c
53578 +++ b/drivers/tty/pty.c
53579 @@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
53580 panic("Couldn't register Unix98 pts driver");
53581
53582 /* Now create the /dev/ptmx special device */
53583 + pax_open_kernel();
53584 tty_default_fops(&ptmx_fops);
53585 - ptmx_fops.open = ptmx_open;
53586 + *(void **)&ptmx_fops.open = ptmx_open;
53587 + pax_close_kernel();
53588
53589 cdev_init(&ptmx_cdev, &ptmx_fops);
53590 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53591 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53592 index 383c4c7..d408e21 100644
53593 --- a/drivers/tty/rocket.c
53594 +++ b/drivers/tty/rocket.c
53595 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53596 tty->driver_data = info;
53597 tty_port_tty_set(port, tty);
53598
53599 - if (port->count++ == 0) {
53600 + if (atomic_inc_return(&port->count) == 1) {
53601 atomic_inc(&rp_num_ports_open);
53602
53603 #ifdef ROCKET_DEBUG_OPEN
53604 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53605 #endif
53606 }
53607 #ifdef ROCKET_DEBUG_OPEN
53608 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53609 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53610 #endif
53611
53612 /*
53613 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53614 spin_unlock_irqrestore(&info->port.lock, flags);
53615 return;
53616 }
53617 - if (info->port.count)
53618 + if (atomic_read(&info->port.count))
53619 atomic_dec(&rp_num_ports_open);
53620 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53621 spin_unlock_irqrestore(&info->port.lock, flags);
53622 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53623 index aa28209..e08fb85 100644
53624 --- a/drivers/tty/serial/ioc4_serial.c
53625 +++ b/drivers/tty/serial/ioc4_serial.c
53626 @@ -437,7 +437,7 @@ struct ioc4_soft {
53627 } is_intr_info[MAX_IOC4_INTR_ENTS];
53628
53629 /* Number of entries active in the above array */
53630 - atomic_t is_num_intrs;
53631 + atomic_unchecked_t is_num_intrs;
53632 } is_intr_type[IOC4_NUM_INTR_TYPES];
53633
53634 /* is_ir_lock must be held while
53635 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53636 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53637 || (type == IOC4_OTHER_INTR_TYPE)));
53638
53639 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53640 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53641 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53642
53643 /* Save off the lower level interrupt handler */
53644 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53645
53646 soft = arg;
53647 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53648 - num_intrs = (int)atomic_read(
53649 + num_intrs = (int)atomic_read_unchecked(
53650 &soft->is_intr_type[intr_type].is_num_intrs);
53651
53652 this_mir = this_ir = pending_intrs(soft, intr_type);
53653 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53654 index 6ec7501..265bcbf 100644
53655 --- a/drivers/tty/serial/kgdb_nmi.c
53656 +++ b/drivers/tty/serial/kgdb_nmi.c
53657 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53658 * I/O utilities that messages sent to the console will automatically
53659 * be displayed on the dbg_io.
53660 */
53661 - dbg_io_ops->is_console = true;
53662 + pax_open_kernel();
53663 + *(int *)&dbg_io_ops->is_console = true;
53664 + pax_close_kernel();
53665
53666 return 0;
53667 }
53668 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53669 index a260cde..6b2b5ce 100644
53670 --- a/drivers/tty/serial/kgdboc.c
53671 +++ b/drivers/tty/serial/kgdboc.c
53672 @@ -24,8 +24,9 @@
53673 #define MAX_CONFIG_LEN 40
53674
53675 static struct kgdb_io kgdboc_io_ops;
53676 +static struct kgdb_io kgdboc_io_ops_console;
53677
53678 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53679 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53680 static int configured = -1;
53681
53682 static char config[MAX_CONFIG_LEN];
53683 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53684 kgdboc_unregister_kbd();
53685 if (configured == 1)
53686 kgdb_unregister_io_module(&kgdboc_io_ops);
53687 + else if (configured == 2)
53688 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53689 }
53690
53691 static int configure_kgdboc(void)
53692 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53693 int err;
53694 char *cptr = config;
53695 struct console *cons;
53696 + int is_console = 0;
53697
53698 err = kgdboc_option_setup(config);
53699 if (err || !strlen(config) || isspace(config[0]))
53700 goto noconfig;
53701
53702 err = -ENODEV;
53703 - kgdboc_io_ops.is_console = 0;
53704 kgdb_tty_driver = NULL;
53705
53706 kgdboc_use_kms = 0;
53707 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53708 int idx;
53709 if (cons->device && cons->device(cons, &idx) == p &&
53710 idx == tty_line) {
53711 - kgdboc_io_ops.is_console = 1;
53712 + is_console = 1;
53713 break;
53714 }
53715 cons = cons->next;
53716 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53717 kgdb_tty_line = tty_line;
53718
53719 do_register:
53720 - err = kgdb_register_io_module(&kgdboc_io_ops);
53721 + if (is_console) {
53722 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53723 + configured = 2;
53724 + } else {
53725 + err = kgdb_register_io_module(&kgdboc_io_ops);
53726 + configured = 1;
53727 + }
53728 if (err)
53729 goto noconfig;
53730
53731 @@ -205,8 +214,6 @@ do_register:
53732 if (err)
53733 goto nmi_con_failed;
53734
53735 - configured = 1;
53736 -
53737 return 0;
53738
53739 nmi_con_failed:
53740 @@ -223,7 +230,7 @@ noconfig:
53741 static int __init init_kgdboc(void)
53742 {
53743 /* Already configured? */
53744 - if (configured == 1)
53745 + if (configured >= 1)
53746 return 0;
53747
53748 return configure_kgdboc();
53749 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53750 if (config[len - 1] == '\n')
53751 config[len - 1] = '\0';
53752
53753 - if (configured == 1)
53754 + if (configured >= 1)
53755 cleanup_kgdboc();
53756
53757 /* Go and configure with the new params. */
53758 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53759 .post_exception = kgdboc_post_exp_handler,
53760 };
53761
53762 +static struct kgdb_io kgdboc_io_ops_console = {
53763 + .name = "kgdboc",
53764 + .read_char = kgdboc_get_char,
53765 + .write_char = kgdboc_put_char,
53766 + .pre_exception = kgdboc_pre_exp_handler,
53767 + .post_exception = kgdboc_post_exp_handler,
53768 + .is_console = 1
53769 +};
53770 +
53771 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53772 /* This is only available if kgdboc is a built in for early debugging */
53773 static int __init kgdboc_early_init(char *opt)
53774 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53775 index 077570a..12550a9 100644
53776 --- a/drivers/tty/serial/msm_serial.c
53777 +++ b/drivers/tty/serial/msm_serial.c
53778 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
53779 .cons = MSM_CONSOLE,
53780 };
53781
53782 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53783 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53784
53785 static const struct of_device_id msm_uartdm_table[] = {
53786 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53787 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53788 int irq;
53789
53790 if (pdev->id == -1)
53791 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53792 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53793
53794 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53795 return -ENXIO;
53796 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53797 index c78f43a..22b1dab 100644
53798 --- a/drivers/tty/serial/samsung.c
53799 +++ b/drivers/tty/serial/samsung.c
53800 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53801 }
53802 }
53803
53804 +static int s3c64xx_serial_startup(struct uart_port *port);
53805 static int s3c24xx_serial_startup(struct uart_port *port)
53806 {
53807 struct s3c24xx_uart_port *ourport = to_ourport(port);
53808 int ret;
53809
53810 + /* Startup sequence is different for s3c64xx and higher SoC's */
53811 + if (s3c24xx_serial_has_interrupt_mask(port))
53812 + return s3c64xx_serial_startup(port);
53813 +
53814 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53815 port, (unsigned long long)port->mapbase, port->membase);
53816
53817 @@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53818 /* setup info for port */
53819 port->dev = &platdev->dev;
53820
53821 - /* Startup sequence is different for s3c64xx and higher SoC's */
53822 - if (s3c24xx_serial_has_interrupt_mask(port))
53823 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53824 -
53825 port->uartclk = 1;
53826
53827 if (cfg->uart_flags & UPF_CONS_FLOW) {
53828 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53829 index 0f03988..8a8038d 100644
53830 --- a/drivers/tty/serial/serial_core.c
53831 +++ b/drivers/tty/serial/serial_core.c
53832 @@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53833
53834 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53835
53836 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53837 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53838 return;
53839
53840 /*
53841 @@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
53842 uart_flush_buffer(tty);
53843 uart_shutdown(tty, state);
53844 spin_lock_irqsave(&port->lock, flags);
53845 - port->count = 0;
53846 + atomic_set(&port->count, 0);
53847 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53848 spin_unlock_irqrestore(&port->lock, flags);
53849 tty_port_tty_set(port, NULL);
53850 @@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53851 goto end;
53852 }
53853
53854 - port->count++;
53855 + atomic_inc(&port->count);
53856 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53857 retval = -ENXIO;
53858 goto err_dec_count;
53859 @@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53860 end:
53861 return retval;
53862 err_dec_count:
53863 - port->count--;
53864 + atomic_inc(&port->count);
53865 mutex_unlock(&port->mutex);
53866 goto end;
53867 }
53868 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53869 index b799170..87dafd5 100644
53870 --- a/drivers/tty/synclink.c
53871 +++ b/drivers/tty/synclink.c
53872 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53873
53874 if (debug_level >= DEBUG_LEVEL_INFO)
53875 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53876 - __FILE__,__LINE__, info->device_name, info->port.count);
53877 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53878
53879 if (tty_port_close_start(&info->port, tty, filp) == 0)
53880 goto cleanup;
53881 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53882 cleanup:
53883 if (debug_level >= DEBUG_LEVEL_INFO)
53884 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53885 - tty->driver->name, info->port.count);
53886 + tty->driver->name, atomic_read(&info->port.count));
53887
53888 } /* end of mgsl_close() */
53889
53890 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53891
53892 mgsl_flush_buffer(tty);
53893 shutdown(info);
53894 -
53895 - info->port.count = 0;
53896 +
53897 + atomic_set(&info->port.count, 0);
53898 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53899 info->port.tty = NULL;
53900
53901 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53902
53903 if (debug_level >= DEBUG_LEVEL_INFO)
53904 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53905 - __FILE__,__LINE__, tty->driver->name, port->count );
53906 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53907
53908 spin_lock_irqsave(&info->irq_spinlock, flags);
53909 - port->count--;
53910 + atomic_dec(&port->count);
53911 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53912 port->blocked_open++;
53913
53914 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53915
53916 if (debug_level >= DEBUG_LEVEL_INFO)
53917 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53918 - __FILE__,__LINE__, tty->driver->name, port->count );
53919 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53920
53921 tty_unlock(tty);
53922 schedule();
53923 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53924
53925 /* FIXME: Racy on hangup during close wait */
53926 if (!tty_hung_up_p(filp))
53927 - port->count++;
53928 + atomic_inc(&port->count);
53929 port->blocked_open--;
53930
53931 if (debug_level >= DEBUG_LEVEL_INFO)
53932 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53933 - __FILE__,__LINE__, tty->driver->name, port->count );
53934 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53935
53936 if (!retval)
53937 port->flags |= ASYNC_NORMAL_ACTIVE;
53938 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53939
53940 if (debug_level >= DEBUG_LEVEL_INFO)
53941 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53942 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53943 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53944
53945 /* If port is closing, signal caller to try again */
53946 if (info->port.flags & ASYNC_CLOSING){
53947 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53948 spin_unlock_irqrestore(&info->netlock, flags);
53949 goto cleanup;
53950 }
53951 - info->port.count++;
53952 + atomic_inc(&info->port.count);
53953 spin_unlock_irqrestore(&info->netlock, flags);
53954
53955 - if (info->port.count == 1) {
53956 + if (atomic_read(&info->port.count) == 1) {
53957 /* 1st open on this device, init hardware */
53958 retval = startup(info);
53959 if (retval < 0)
53960 @@ -3442,8 +3442,8 @@ cleanup:
53961 if (retval) {
53962 if (tty->count == 1)
53963 info->port.tty = NULL; /* tty layer will release tty struct */
53964 - if(info->port.count)
53965 - info->port.count--;
53966 + if (atomic_read(&info->port.count))
53967 + atomic_dec(&info->port.count);
53968 }
53969
53970 return retval;
53971 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53972 unsigned short new_crctype;
53973
53974 /* return error if TTY interface open */
53975 - if (info->port.count)
53976 + if (atomic_read(&info->port.count))
53977 return -EBUSY;
53978
53979 switch (encoding)
53980 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53981
53982 /* arbitrate between network and tty opens */
53983 spin_lock_irqsave(&info->netlock, flags);
53984 - if (info->port.count != 0 || info->netcount != 0) {
53985 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53986 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53987 spin_unlock_irqrestore(&info->netlock, flags);
53988 return -EBUSY;
53989 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53990 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53991
53992 /* return error if TTY interface open */
53993 - if (info->port.count)
53994 + if (atomic_read(&info->port.count))
53995 return -EBUSY;
53996
53997 if (cmd != SIOCWANDEV)
53998 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53999 index 0e8c39b..e0cb171 100644
54000 --- a/drivers/tty/synclink_gt.c
54001 +++ b/drivers/tty/synclink_gt.c
54002 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54003 tty->driver_data = info;
54004 info->port.tty = tty;
54005
54006 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54007 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54008
54009 /* If port is closing, signal caller to try again */
54010 if (info->port.flags & ASYNC_CLOSING){
54011 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54012 mutex_unlock(&info->port.mutex);
54013 goto cleanup;
54014 }
54015 - info->port.count++;
54016 + atomic_inc(&info->port.count);
54017 spin_unlock_irqrestore(&info->netlock, flags);
54018
54019 - if (info->port.count == 1) {
54020 + if (atomic_read(&info->port.count) == 1) {
54021 /* 1st open on this device, init hardware */
54022 retval = startup(info);
54023 if (retval < 0) {
54024 @@ -715,8 +715,8 @@ cleanup:
54025 if (retval) {
54026 if (tty->count == 1)
54027 info->port.tty = NULL; /* tty layer will release tty struct */
54028 - if(info->port.count)
54029 - info->port.count--;
54030 + if(atomic_read(&info->port.count))
54031 + atomic_dec(&info->port.count);
54032 }
54033
54034 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54035 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54036
54037 if (sanity_check(info, tty->name, "close"))
54038 return;
54039 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54040 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54041
54042 if (tty_port_close_start(&info->port, tty, filp) == 0)
54043 goto cleanup;
54044 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54045 tty_port_close_end(&info->port, tty);
54046 info->port.tty = NULL;
54047 cleanup:
54048 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54049 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54050 }
54051
54052 static void hangup(struct tty_struct *tty)
54053 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54054 shutdown(info);
54055
54056 spin_lock_irqsave(&info->port.lock, flags);
54057 - info->port.count = 0;
54058 + atomic_set(&info->port.count, 0);
54059 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54060 info->port.tty = NULL;
54061 spin_unlock_irqrestore(&info->port.lock, flags);
54062 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54063 unsigned short new_crctype;
54064
54065 /* return error if TTY interface open */
54066 - if (info->port.count)
54067 + if (atomic_read(&info->port.count))
54068 return -EBUSY;
54069
54070 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54071 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54072
54073 /* arbitrate between network and tty opens */
54074 spin_lock_irqsave(&info->netlock, flags);
54075 - if (info->port.count != 0 || info->netcount != 0) {
54076 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54077 DBGINFO(("%s hdlc_open busy\n", dev->name));
54078 spin_unlock_irqrestore(&info->netlock, flags);
54079 return -EBUSY;
54080 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54081 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54082
54083 /* return error if TTY interface open */
54084 - if (info->port.count)
54085 + if (atomic_read(&info->port.count))
54086 return -EBUSY;
54087
54088 if (cmd != SIOCWANDEV)
54089 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54090 if (port == NULL)
54091 continue;
54092 spin_lock(&port->lock);
54093 - if ((port->port.count || port->netcount) &&
54094 + if ((atomic_read(&port->port.count) || port->netcount) &&
54095 port->pending_bh && !port->bh_running &&
54096 !port->bh_requested) {
54097 DBGISR(("%s bh queued\n", port->device_name));
54098 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54099 add_wait_queue(&port->open_wait, &wait);
54100
54101 spin_lock_irqsave(&info->lock, flags);
54102 - port->count--;
54103 + atomic_dec(&port->count);
54104 spin_unlock_irqrestore(&info->lock, flags);
54105 port->blocked_open++;
54106
54107 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54108 remove_wait_queue(&port->open_wait, &wait);
54109
54110 if (!tty_hung_up_p(filp))
54111 - port->count++;
54112 + atomic_inc(&port->count);
54113 port->blocked_open--;
54114
54115 if (!retval)
54116 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54117 index c3f9091..abe4601 100644
54118 --- a/drivers/tty/synclinkmp.c
54119 +++ b/drivers/tty/synclinkmp.c
54120 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54121
54122 if (debug_level >= DEBUG_LEVEL_INFO)
54123 printk("%s(%d):%s open(), old ref count = %d\n",
54124 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54125 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54126
54127 /* If port is closing, signal caller to try again */
54128 if (info->port.flags & ASYNC_CLOSING){
54129 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54130 spin_unlock_irqrestore(&info->netlock, flags);
54131 goto cleanup;
54132 }
54133 - info->port.count++;
54134 + atomic_inc(&info->port.count);
54135 spin_unlock_irqrestore(&info->netlock, flags);
54136
54137 - if (info->port.count == 1) {
54138 + if (atomic_read(&info->port.count) == 1) {
54139 /* 1st open on this device, init hardware */
54140 retval = startup(info);
54141 if (retval < 0)
54142 @@ -796,8 +796,8 @@ cleanup:
54143 if (retval) {
54144 if (tty->count == 1)
54145 info->port.tty = NULL; /* tty layer will release tty struct */
54146 - if(info->port.count)
54147 - info->port.count--;
54148 + if(atomic_read(&info->port.count))
54149 + atomic_dec(&info->port.count);
54150 }
54151
54152 return retval;
54153 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54154
54155 if (debug_level >= DEBUG_LEVEL_INFO)
54156 printk("%s(%d):%s close() entry, count=%d\n",
54157 - __FILE__,__LINE__, info->device_name, info->port.count);
54158 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54159
54160 if (tty_port_close_start(&info->port, tty, filp) == 0)
54161 goto cleanup;
54162 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54163 cleanup:
54164 if (debug_level >= DEBUG_LEVEL_INFO)
54165 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54166 - tty->driver->name, info->port.count);
54167 + tty->driver->name, atomic_read(&info->port.count));
54168 }
54169
54170 /* Called by tty_hangup() when a hangup is signaled.
54171 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54172 shutdown(info);
54173
54174 spin_lock_irqsave(&info->port.lock, flags);
54175 - info->port.count = 0;
54176 + atomic_set(&info->port.count, 0);
54177 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54178 info->port.tty = NULL;
54179 spin_unlock_irqrestore(&info->port.lock, flags);
54180 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54181 unsigned short new_crctype;
54182
54183 /* return error if TTY interface open */
54184 - if (info->port.count)
54185 + if (atomic_read(&info->port.count))
54186 return -EBUSY;
54187
54188 switch (encoding)
54189 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54190
54191 /* arbitrate between network and tty opens */
54192 spin_lock_irqsave(&info->netlock, flags);
54193 - if (info->port.count != 0 || info->netcount != 0) {
54194 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54195 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54196 spin_unlock_irqrestore(&info->netlock, flags);
54197 return -EBUSY;
54198 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54199 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54200
54201 /* return error if TTY interface open */
54202 - if (info->port.count)
54203 + if (atomic_read(&info->port.count))
54204 return -EBUSY;
54205
54206 if (cmd != SIOCWANDEV)
54207 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54208 * do not request bottom half processing if the
54209 * device is not open in a normal mode.
54210 */
54211 - if ( port && (port->port.count || port->netcount) &&
54212 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54213 port->pending_bh && !port->bh_running &&
54214 !port->bh_requested ) {
54215 if ( debug_level >= DEBUG_LEVEL_ISR )
54216 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54217
54218 if (debug_level >= DEBUG_LEVEL_INFO)
54219 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54220 - __FILE__,__LINE__, tty->driver->name, port->count );
54221 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54222
54223 spin_lock_irqsave(&info->lock, flags);
54224 - port->count--;
54225 + atomic_dec(&port->count);
54226 spin_unlock_irqrestore(&info->lock, flags);
54227 port->blocked_open++;
54228
54229 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54230
54231 if (debug_level >= DEBUG_LEVEL_INFO)
54232 printk("%s(%d):%s block_til_ready() count=%d\n",
54233 - __FILE__,__LINE__, tty->driver->name, port->count );
54234 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54235
54236 tty_unlock(tty);
54237 schedule();
54238 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54239 set_current_state(TASK_RUNNING);
54240 remove_wait_queue(&port->open_wait, &wait);
54241 if (!tty_hung_up_p(filp))
54242 - port->count++;
54243 + atomic_inc(&port->count);
54244 port->blocked_open--;
54245
54246 if (debug_level >= DEBUG_LEVEL_INFO)
54247 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54248 - __FILE__,__LINE__, tty->driver->name, port->count );
54249 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54250
54251 if (!retval)
54252 port->flags |= ASYNC_NORMAL_ACTIVE;
54253 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54254 index 42bad18..447d7a2 100644
54255 --- a/drivers/tty/sysrq.c
54256 +++ b/drivers/tty/sysrq.c
54257 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54258 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54259 size_t count, loff_t *ppos)
54260 {
54261 - if (count) {
54262 + if (count && capable(CAP_SYS_ADMIN)) {
54263 char c;
54264
54265 if (get_user(c, buf))
54266 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54267 index 848c17a..e930437 100644
54268 --- a/drivers/tty/tty_io.c
54269 +++ b/drivers/tty/tty_io.c
54270 @@ -3469,7 +3469,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54271
54272 void tty_default_fops(struct file_operations *fops)
54273 {
54274 - *fops = tty_fops;
54275 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54276 }
54277
54278 /*
54279 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54280 index 2d822aa..a566234 100644
54281 --- a/drivers/tty/tty_ldisc.c
54282 +++ b/drivers/tty/tty_ldisc.c
54283 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54284 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54285 tty_ldiscs[disc] = new_ldisc;
54286 new_ldisc->num = disc;
54287 - new_ldisc->refcount = 0;
54288 + atomic_set(&new_ldisc->refcount, 0);
54289 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54290
54291 return ret;
54292 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54293 return -EINVAL;
54294
54295 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54296 - if (tty_ldiscs[disc]->refcount)
54297 + if (atomic_read(&tty_ldiscs[disc]->refcount))
54298 ret = -EBUSY;
54299 else
54300 tty_ldiscs[disc] = NULL;
54301 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54302 if (ldops) {
54303 ret = ERR_PTR(-EAGAIN);
54304 if (try_module_get(ldops->owner)) {
54305 - ldops->refcount++;
54306 + atomic_inc(&ldops->refcount);
54307 ret = ldops;
54308 }
54309 }
54310 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54311 unsigned long flags;
54312
54313 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54314 - ldops->refcount--;
54315 + atomic_dec(&ldops->refcount);
54316 module_put(ldops->owner);
54317 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54318 }
54319 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54320 index 1b93357..ea9f82c 100644
54321 --- a/drivers/tty/tty_port.c
54322 +++ b/drivers/tty/tty_port.c
54323 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
54324 unsigned long flags;
54325
54326 spin_lock_irqsave(&port->lock, flags);
54327 - port->count = 0;
54328 + atomic_set(&port->count, 0);
54329 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54330 tty = port->tty;
54331 if (tty)
54332 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54333
54334 /* The port lock protects the port counts */
54335 spin_lock_irqsave(&port->lock, flags);
54336 - port->count--;
54337 + atomic_dec(&port->count);
54338 port->blocked_open++;
54339 spin_unlock_irqrestore(&port->lock, flags);
54340
54341 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54342 we must not mess that up further */
54343 spin_lock_irqsave(&port->lock, flags);
54344 if (!tty_hung_up_p(filp))
54345 - port->count++;
54346 + atomic_inc(&port->count);
54347 port->blocked_open--;
54348 if (retval == 0)
54349 port->flags |= ASYNC_NORMAL_ACTIVE;
54350 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
54351 return 0;
54352 }
54353
54354 - if (tty->count == 1 && port->count != 1) {
54355 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
54356 printk(KERN_WARNING
54357 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54358 - port->count);
54359 - port->count = 1;
54360 + atomic_read(&port->count));
54361 + atomic_set(&port->count, 1);
54362 }
54363 - if (--port->count < 0) {
54364 + if (atomic_dec_return(&port->count) < 0) {
54365 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54366 - port->count);
54367 - port->count = 0;
54368 + atomic_read(&port->count));
54369 + atomic_set(&port->count, 0);
54370 }
54371
54372 - if (port->count) {
54373 + if (atomic_read(&port->count)) {
54374 spin_unlock_irqrestore(&port->lock, flags);
54375 return 0;
54376 }
54377 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54378 struct file *filp)
54379 {
54380 spin_lock_irq(&port->lock);
54381 - ++port->count;
54382 + atomic_inc(&port->count);
54383 spin_unlock_irq(&port->lock);
54384 tty_port_tty_set(port, tty);
54385
54386 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54387 index d0e3a44..5f8b754 100644
54388 --- a/drivers/tty/vt/keyboard.c
54389 +++ b/drivers/tty/vt/keyboard.c
54390 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54391 kbd->kbdmode == VC_OFF) &&
54392 value != KVAL(K_SAK))
54393 return; /* SAK is allowed even in raw mode */
54394 +
54395 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54396 + {
54397 + void *func = fn_handler[value];
54398 + if (func == fn_show_state || func == fn_show_ptregs ||
54399 + func == fn_show_mem)
54400 + return;
54401 + }
54402 +#endif
54403 +
54404 fn_handler[value](vc);
54405 }
54406
54407 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54408 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54409 return -EFAULT;
54410
54411 - if (!capable(CAP_SYS_TTY_CONFIG))
54412 - perm = 0;
54413 -
54414 switch (cmd) {
54415 case KDGKBENT:
54416 /* Ensure another thread doesn't free it under us */
54417 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54418 spin_unlock_irqrestore(&kbd_event_lock, flags);
54419 return put_user(val, &user_kbe->kb_value);
54420 case KDSKBENT:
54421 + if (!capable(CAP_SYS_TTY_CONFIG))
54422 + perm = 0;
54423 +
54424 if (!perm)
54425 return -EPERM;
54426 if (!i && v == K_NOSUCHMAP) {
54427 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54428 int i, j, k;
54429 int ret;
54430
54431 - if (!capable(CAP_SYS_TTY_CONFIG))
54432 - perm = 0;
54433 -
54434 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54435 if (!kbs) {
54436 ret = -ENOMEM;
54437 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54438 kfree(kbs);
54439 return ((p && *p) ? -EOVERFLOW : 0);
54440 case KDSKBSENT:
54441 + if (!capable(CAP_SYS_TTY_CONFIG))
54442 + perm = 0;
54443 +
54444 if (!perm) {
54445 ret = -EPERM;
54446 goto reterr;
54447 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54448 index a673e5b..36e5d32 100644
54449 --- a/drivers/uio/uio.c
54450 +++ b/drivers/uio/uio.c
54451 @@ -25,6 +25,7 @@
54452 #include <linux/kobject.h>
54453 #include <linux/cdev.h>
54454 #include <linux/uio_driver.h>
54455 +#include <asm/local.h>
54456
54457 #define UIO_MAX_DEVICES (1U << MINORBITS)
54458
54459 @@ -32,7 +33,7 @@ struct uio_device {
54460 struct module *owner;
54461 struct device *dev;
54462 int minor;
54463 - atomic_t event;
54464 + atomic_unchecked_t event;
54465 struct fasync_struct *async_queue;
54466 wait_queue_head_t wait;
54467 struct uio_info *info;
54468 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54469 struct device_attribute *attr, char *buf)
54470 {
54471 struct uio_device *idev = dev_get_drvdata(dev);
54472 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54473 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54474 }
54475 static DEVICE_ATTR_RO(event);
54476
54477 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54478 {
54479 struct uio_device *idev = info->uio_dev;
54480
54481 - atomic_inc(&idev->event);
54482 + atomic_inc_unchecked(&idev->event);
54483 wake_up_interruptible(&idev->wait);
54484 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54485 }
54486 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54487 }
54488
54489 listener->dev = idev;
54490 - listener->event_count = atomic_read(&idev->event);
54491 + listener->event_count = atomic_read_unchecked(&idev->event);
54492 filep->private_data = listener;
54493
54494 if (idev->info->open) {
54495 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54496 return -EIO;
54497
54498 poll_wait(filep, &idev->wait, wait);
54499 - if (listener->event_count != atomic_read(&idev->event))
54500 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54501 return POLLIN | POLLRDNORM;
54502 return 0;
54503 }
54504 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54505 do {
54506 set_current_state(TASK_INTERRUPTIBLE);
54507
54508 - event_count = atomic_read(&idev->event);
54509 + event_count = atomic_read_unchecked(&idev->event);
54510 if (event_count != listener->event_count) {
54511 if (copy_to_user(buf, &event_count, count))
54512 retval = -EFAULT;
54513 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54514 static int uio_find_mem_index(struct vm_area_struct *vma)
54515 {
54516 struct uio_device *idev = vma->vm_private_data;
54517 + unsigned long size;
54518
54519 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54520 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54521 + size = idev->info->mem[vma->vm_pgoff].size;
54522 + if (size == 0)
54523 + return -1;
54524 + if (vma->vm_end - vma->vm_start > size)
54525 return -1;
54526 return (int)vma->vm_pgoff;
54527 }
54528 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54529 idev->owner = owner;
54530 idev->info = info;
54531 init_waitqueue_head(&idev->wait);
54532 - atomic_set(&idev->event, 0);
54533 + atomic_set_unchecked(&idev->event, 0);
54534
54535 ret = uio_get_minor(idev);
54536 if (ret)
54537 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54538 index 813d4d3..a71934f 100644
54539 --- a/drivers/usb/atm/cxacru.c
54540 +++ b/drivers/usb/atm/cxacru.c
54541 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54542 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54543 if (ret < 2)
54544 return -EINVAL;
54545 - if (index < 0 || index > 0x7f)
54546 + if (index > 0x7f)
54547 return -EINVAL;
54548 pos += tmp;
54549
54550 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54551 index dada014..1d0d517 100644
54552 --- a/drivers/usb/atm/usbatm.c
54553 +++ b/drivers/usb/atm/usbatm.c
54554 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54555 if (printk_ratelimit())
54556 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54557 __func__, vpi, vci);
54558 - atomic_inc(&vcc->stats->rx_err);
54559 + atomic_inc_unchecked(&vcc->stats->rx_err);
54560 return;
54561 }
54562
54563 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54564 if (length > ATM_MAX_AAL5_PDU) {
54565 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54566 __func__, length, vcc);
54567 - atomic_inc(&vcc->stats->rx_err);
54568 + atomic_inc_unchecked(&vcc->stats->rx_err);
54569 goto out;
54570 }
54571
54572 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54573 if (sarb->len < pdu_length) {
54574 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54575 __func__, pdu_length, sarb->len, vcc);
54576 - atomic_inc(&vcc->stats->rx_err);
54577 + atomic_inc_unchecked(&vcc->stats->rx_err);
54578 goto out;
54579 }
54580
54581 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54582 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54583 __func__, vcc);
54584 - atomic_inc(&vcc->stats->rx_err);
54585 + atomic_inc_unchecked(&vcc->stats->rx_err);
54586 goto out;
54587 }
54588
54589 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54590 if (printk_ratelimit())
54591 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54592 __func__, length);
54593 - atomic_inc(&vcc->stats->rx_drop);
54594 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54595 goto out;
54596 }
54597
54598 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54599
54600 vcc->push(vcc, skb);
54601
54602 - atomic_inc(&vcc->stats->rx);
54603 + atomic_inc_unchecked(&vcc->stats->rx);
54604 out:
54605 skb_trim(sarb, 0);
54606 }
54607 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54608 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54609
54610 usbatm_pop(vcc, skb);
54611 - atomic_inc(&vcc->stats->tx);
54612 + atomic_inc_unchecked(&vcc->stats->tx);
54613
54614 skb = skb_dequeue(&instance->sndqueue);
54615 }
54616 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54617 if (!left--)
54618 return sprintf(page,
54619 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54620 - atomic_read(&atm_dev->stats.aal5.tx),
54621 - atomic_read(&atm_dev->stats.aal5.tx_err),
54622 - atomic_read(&atm_dev->stats.aal5.rx),
54623 - atomic_read(&atm_dev->stats.aal5.rx_err),
54624 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54625 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54626 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54627 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54628 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54629 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54630
54631 if (!left--) {
54632 if (instance->disconnected)
54633 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54634 index 2a3bbdf..91d72cf 100644
54635 --- a/drivers/usb/core/devices.c
54636 +++ b/drivers/usb/core/devices.c
54637 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54638 * time it gets called.
54639 */
54640 static struct device_connect_event {
54641 - atomic_t count;
54642 + atomic_unchecked_t count;
54643 wait_queue_head_t wait;
54644 } device_event = {
54645 .count = ATOMIC_INIT(1),
54646 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54647
54648 void usbfs_conn_disc_event(void)
54649 {
54650 - atomic_add(2, &device_event.count);
54651 + atomic_add_unchecked(2, &device_event.count);
54652 wake_up(&device_event.wait);
54653 }
54654
54655 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54656
54657 poll_wait(file, &device_event.wait, wait);
54658
54659 - event_count = atomic_read(&device_event.count);
54660 + event_count = atomic_read_unchecked(&device_event.count);
54661 if (file->f_version != event_count) {
54662 file->f_version = event_count;
54663 return POLLIN | POLLRDNORM;
54664 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54665 index 0b59731..46ee7d1 100644
54666 --- a/drivers/usb/core/devio.c
54667 +++ b/drivers/usb/core/devio.c
54668 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54669 struct usb_dev_state *ps = file->private_data;
54670 struct usb_device *dev = ps->dev;
54671 ssize_t ret = 0;
54672 - unsigned len;
54673 + size_t len;
54674 loff_t pos;
54675 int i;
54676
54677 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54678 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54679 struct usb_config_descriptor *config =
54680 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54681 - unsigned int length = le16_to_cpu(config->wTotalLength);
54682 + size_t length = le16_to_cpu(config->wTotalLength);
54683
54684 if (*ppos < pos + length) {
54685
54686 /* The descriptor may claim to be longer than it
54687 * really is. Here is the actual allocated length. */
54688 - unsigned alloclen =
54689 + size_t alloclen =
54690 le16_to_cpu(dev->config[i].desc.wTotalLength);
54691
54692 - len = length - (*ppos - pos);
54693 + len = length + pos - *ppos;
54694 if (len > nbytes)
54695 len = nbytes;
54696
54697 /* Simply don't write (skip over) unallocated parts */
54698 if (alloclen > (*ppos - pos)) {
54699 - alloclen -= (*ppos - pos);
54700 + alloclen = alloclen + pos - *ppos;
54701 if (copy_to_user(buf,
54702 dev->rawdescriptors[i] + (*ppos - pos),
54703 min(len, alloclen))) {
54704 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54705 index 258e6fe..9ea48d7 100644
54706 --- a/drivers/usb/core/hcd.c
54707 +++ b/drivers/usb/core/hcd.c
54708 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54709 */
54710 usb_get_urb(urb);
54711 atomic_inc(&urb->use_count);
54712 - atomic_inc(&urb->dev->urbnum);
54713 + atomic_inc_unchecked(&urb->dev->urbnum);
54714 usbmon_urb_submit(&hcd->self, urb);
54715
54716 /* NOTE requirements on root-hub callers (usbfs and the hub
54717 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54718 urb->hcpriv = NULL;
54719 INIT_LIST_HEAD(&urb->urb_list);
54720 atomic_dec(&urb->use_count);
54721 - atomic_dec(&urb->dev->urbnum);
54722 + atomic_dec_unchecked(&urb->dev->urbnum);
54723 if (atomic_read(&urb->reject))
54724 wake_up(&usb_kill_urb_queue);
54725 usb_put_urb(urb);
54726 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54727 index 674c262..71fdd90 100644
54728 --- a/drivers/usb/core/hub.c
54729 +++ b/drivers/usb/core/hub.c
54730 @@ -27,6 +27,7 @@
54731 #include <linux/freezer.h>
54732 #include <linux/random.h>
54733 #include <linux/pm_qos.h>
54734 +#include <linux/grsecurity.h>
54735
54736 #include <asm/uaccess.h>
54737 #include <asm/byteorder.h>
54738 @@ -4665,6 +4666,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54739 goto done;
54740 return;
54741 }
54742 +
54743 + if (gr_handle_new_usb())
54744 + goto done;
54745 +
54746 if (hub_is_superspeed(hub->hdev))
54747 unit_load = 150;
54748 else
54749 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54750 index 0c8a7fc..c45b40a 100644
54751 --- a/drivers/usb/core/message.c
54752 +++ b/drivers/usb/core/message.c
54753 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54754 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54755 * error number.
54756 */
54757 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54758 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54759 __u8 requesttype, __u16 value, __u16 index, void *data,
54760 __u16 size, int timeout)
54761 {
54762 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54763 * If successful, 0. Otherwise a negative error number. The number of actual
54764 * bytes transferred will be stored in the @actual_length parameter.
54765 */
54766 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54767 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54768 void *data, int len, int *actual_length, int timeout)
54769 {
54770 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54771 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54772 * bytes transferred will be stored in the @actual_length parameter.
54773 *
54774 */
54775 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54776 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54777 void *data, int len, int *actual_length, int timeout)
54778 {
54779 struct urb *urb;
54780 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54781 index 1236c60..d47a51c 100644
54782 --- a/drivers/usb/core/sysfs.c
54783 +++ b/drivers/usb/core/sysfs.c
54784 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54785 struct usb_device *udev;
54786
54787 udev = to_usb_device(dev);
54788 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54789 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54790 }
54791 static DEVICE_ATTR_RO(urbnum);
54792
54793 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54794 index 2dd2362..1135437 100644
54795 --- a/drivers/usb/core/usb.c
54796 +++ b/drivers/usb/core/usb.c
54797 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54798 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54799 dev->state = USB_STATE_ATTACHED;
54800 dev->lpm_disable_count = 1;
54801 - atomic_set(&dev->urbnum, 0);
54802 + atomic_set_unchecked(&dev->urbnum, 0);
54803
54804 INIT_LIST_HEAD(&dev->ep0.urb_list);
54805 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54806 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54807 index 8cfc319..4868255 100644
54808 --- a/drivers/usb/early/ehci-dbgp.c
54809 +++ b/drivers/usb/early/ehci-dbgp.c
54810 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54811
54812 #ifdef CONFIG_KGDB
54813 static struct kgdb_io kgdbdbgp_io_ops;
54814 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54815 +static struct kgdb_io kgdbdbgp_io_ops_console;
54816 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54817 #else
54818 #define dbgp_kgdb_mode (0)
54819 #endif
54820 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54821 .write_char = kgdbdbgp_write_char,
54822 };
54823
54824 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54825 + .name = "kgdbdbgp",
54826 + .read_char = kgdbdbgp_read_char,
54827 + .write_char = kgdbdbgp_write_char,
54828 + .is_console = 1
54829 +};
54830 +
54831 static int kgdbdbgp_wait_time;
54832
54833 static int __init kgdbdbgp_parse_config(char *str)
54834 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54835 ptr++;
54836 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54837 }
54838 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54839 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54840 + if (early_dbgp_console.index != -1)
54841 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54842 + else
54843 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54844
54845 return 0;
54846 }
54847 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54848 index 2b4c82d..06a8ee6 100644
54849 --- a/drivers/usb/gadget/function/f_uac1.c
54850 +++ b/drivers/usb/gadget/function/f_uac1.c
54851 @@ -13,6 +13,7 @@
54852 #include <linux/kernel.h>
54853 #include <linux/device.h>
54854 #include <linux/atomic.h>
54855 +#include <linux/module.h>
54856
54857 #include "u_uac1.h"
54858
54859 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54860 index ad0aca8..8ff84865 100644
54861 --- a/drivers/usb/gadget/function/u_serial.c
54862 +++ b/drivers/usb/gadget/function/u_serial.c
54863 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54864 spin_lock_irq(&port->port_lock);
54865
54866 /* already open? Great. */
54867 - if (port->port.count) {
54868 + if (atomic_read(&port->port.count)) {
54869 status = 0;
54870 - port->port.count++;
54871 + atomic_inc(&port->port.count);
54872
54873 /* currently opening/closing? wait ... */
54874 } else if (port->openclose) {
54875 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54876 tty->driver_data = port;
54877 port->port.tty = tty;
54878
54879 - port->port.count = 1;
54880 + atomic_set(&port->port.count, 1);
54881 port->openclose = false;
54882
54883 /* if connected, start the I/O stream */
54884 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54885
54886 spin_lock_irq(&port->port_lock);
54887
54888 - if (port->port.count != 1) {
54889 - if (port->port.count == 0)
54890 + if (atomic_read(&port->port.count) != 1) {
54891 + if (atomic_read(&port->port.count) == 0)
54892 WARN_ON(1);
54893 else
54894 - --port->port.count;
54895 + atomic_dec(&port->port.count);
54896 goto exit;
54897 }
54898
54899 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54900 * and sleep if necessary
54901 */
54902 port->openclose = true;
54903 - port->port.count = 0;
54904 + atomic_set(&port->port.count, 0);
54905
54906 gser = port->port_usb;
54907 if (gser && gser->disconnect)
54908 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
54909 int cond;
54910
54911 spin_lock_irq(&port->port_lock);
54912 - cond = (port->port.count == 0) && !port->openclose;
54913 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54914 spin_unlock_irq(&port->port_lock);
54915 return cond;
54916 }
54917 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54918 /* if it's already open, start I/O ... and notify the serial
54919 * protocol about open/close status (connect/disconnect).
54920 */
54921 - if (port->port.count) {
54922 + if (atomic_read(&port->port.count)) {
54923 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54924 gs_start_io(port);
54925 if (gser->connect)
54926 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
54927
54928 port->port_usb = NULL;
54929 gser->ioport = NULL;
54930 - if (port->port.count > 0 || port->openclose) {
54931 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54932 wake_up_interruptible(&port->drain_wait);
54933 if (port->port.tty)
54934 tty_hangup(port->port.tty);
54935 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
54936
54937 /* finally, free any unused/unusable I/O buffers */
54938 spin_lock_irqsave(&port->port_lock, flags);
54939 - if (port->port.count == 0 && !port->openclose)
54940 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54941 gs_buf_free(&port->port_write_buf);
54942 gs_free_requests(gser->out, &port->read_pool, NULL);
54943 gs_free_requests(gser->out, &port->read_queue, NULL);
54944 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54945 index 7a55fea..cc0ed4f 100644
54946 --- a/drivers/usb/gadget/function/u_uac1.c
54947 +++ b/drivers/usb/gadget/function/u_uac1.c
54948 @@ -16,6 +16,7 @@
54949 #include <linux/ctype.h>
54950 #include <linux/random.h>
54951 #include <linux/syscalls.h>
54952 +#include <linux/module.h>
54953
54954 #include "u_uac1.h"
54955
54956 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54957 index 6130b75..3b60008 100644
54958 --- a/drivers/usb/host/ehci-hub.c
54959 +++ b/drivers/usb/host/ehci-hub.c
54960 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54961 urb->transfer_flags = URB_DIR_IN;
54962 usb_get_urb(urb);
54963 atomic_inc(&urb->use_count);
54964 - atomic_inc(&urb->dev->urbnum);
54965 + atomic_inc_unchecked(&urb->dev->urbnum);
54966 urb->setup_dma = dma_map_single(
54967 hcd->self.controller,
54968 urb->setup_packet,
54969 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54970 urb->status = -EINPROGRESS;
54971 usb_get_urb(urb);
54972 atomic_inc(&urb->use_count);
54973 - atomic_inc(&urb->dev->urbnum);
54974 + atomic_inc_unchecked(&urb->dev->urbnum);
54975 retval = submit_single_step_set_feature(hcd, urb, 0);
54976 if (!retval && !wait_for_completion_timeout(&done,
54977 msecs_to_jiffies(2000))) {
54978 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54979 index d0d8fad..668ef7b 100644
54980 --- a/drivers/usb/host/hwa-hc.c
54981 +++ b/drivers/usb/host/hwa-hc.c
54982 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54983 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54984 struct wahc *wa = &hwahc->wa;
54985 struct device *dev = &wa->usb_iface->dev;
54986 - u8 mas_le[UWB_NUM_MAS/8];
54987 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54988 +
54989 + if (mas_le == NULL)
54990 + return -ENOMEM;
54991
54992 /* Set the stream index */
54993 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54994 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54995 WUSB_REQ_SET_WUSB_MAS,
54996 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54997 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54998 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54999 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55000 if (result < 0)
55001 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55002 out:
55003 + kfree(mas_le);
55004 +
55005 return result;
55006 }
55007
55008 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55009 index b3d245e..99549ed 100644
55010 --- a/drivers/usb/misc/appledisplay.c
55011 +++ b/drivers/usb/misc/appledisplay.c
55012 @@ -84,7 +84,7 @@ struct appledisplay {
55013 struct mutex sysfslock; /* concurrent read and write */
55014 };
55015
55016 -static atomic_t count_displays = ATOMIC_INIT(0);
55017 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55018 static struct workqueue_struct *wq;
55019
55020 static void appledisplay_complete(struct urb *urb)
55021 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55022
55023 /* Register backlight device */
55024 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55025 - atomic_inc_return(&count_displays) - 1);
55026 + atomic_inc_return_unchecked(&count_displays) - 1);
55027 memset(&props, 0, sizeof(struct backlight_properties));
55028 props.type = BACKLIGHT_RAW;
55029 props.max_brightness = 0xff;
55030 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55031 index 8d7fc48..01c4986 100644
55032 --- a/drivers/usb/serial/console.c
55033 +++ b/drivers/usb/serial/console.c
55034 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55035
55036 info->port = port;
55037
55038 - ++port->port.count;
55039 + atomic_inc(&port->port.count);
55040 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55041 if (serial->type->set_termios) {
55042 /*
55043 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55044 }
55045 /* Now that any required fake tty operations are completed restore
55046 * the tty port count */
55047 - --port->port.count;
55048 + atomic_dec(&port->port.count);
55049 /* The console is special in terms of closing the device so
55050 * indicate this port is now acting as a system console. */
55051 port->port.console = 1;
55052 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55053 free_tty:
55054 kfree(tty);
55055 reset_open_count:
55056 - port->port.count = 0;
55057 + atomic_set(&port->port.count, 0);
55058 usb_autopm_put_interface(serial->interface);
55059 error_get_interface:
55060 usb_serial_put(serial);
55061 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55062 static void usb_console_write(struct console *co,
55063 const char *buf, unsigned count)
55064 {
55065 - static struct usbcons_info *info = &usbcons_info;
55066 + struct usbcons_info *info = &usbcons_info;
55067 struct usb_serial_port *port = info->port;
55068 struct usb_serial *serial;
55069 int retval = -ENODEV;
55070 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55071 index 307e339..6aa97cb 100644
55072 --- a/drivers/usb/storage/usb.h
55073 +++ b/drivers/usb/storage/usb.h
55074 @@ -63,7 +63,7 @@ struct us_unusual_dev {
55075 __u8 useProtocol;
55076 __u8 useTransport;
55077 int (*initFunction)(struct us_data *);
55078 -};
55079 +} __do_const;
55080
55081
55082 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55083 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
55084 index a863a98..d272795 100644
55085 --- a/drivers/usb/usbip/vhci.h
55086 +++ b/drivers/usb/usbip/vhci.h
55087 @@ -83,7 +83,7 @@ struct vhci_hcd {
55088 unsigned resuming:1;
55089 unsigned long re_timeout;
55090
55091 - atomic_t seqnum;
55092 + atomic_unchecked_t seqnum;
55093
55094 /*
55095 * NOTE:
55096 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
55097 index c02374b..32d47a9 100644
55098 --- a/drivers/usb/usbip/vhci_hcd.c
55099 +++ b/drivers/usb/usbip/vhci_hcd.c
55100 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
55101
55102 spin_lock(&vdev->priv_lock);
55103
55104 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
55105 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55106 if (priv->seqnum == 0xffff)
55107 dev_info(&urb->dev->dev, "seqnum max\n");
55108
55109 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
55110 return -ENOMEM;
55111 }
55112
55113 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
55114 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55115 if (unlink->seqnum == 0xffff)
55116 pr_info("seqnum max\n");
55117
55118 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
55119 vdev->rhport = rhport;
55120 }
55121
55122 - atomic_set(&vhci->seqnum, 0);
55123 + atomic_set_unchecked(&vhci->seqnum, 0);
55124 spin_lock_init(&vhci->lock);
55125
55126 hcd->power_budget = 0; /* no limit */
55127 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
55128 index 00e4a54..d676f85 100644
55129 --- a/drivers/usb/usbip/vhci_rx.c
55130 +++ b/drivers/usb/usbip/vhci_rx.c
55131 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
55132 if (!urb) {
55133 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
55134 pr_info("max seqnum %d\n",
55135 - atomic_read(&the_controller->seqnum));
55136 + atomic_read_unchecked(&the_controller->seqnum));
55137 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
55138 return;
55139 }
55140 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55141 index f2a8d29..7bc3fe7 100644
55142 --- a/drivers/usb/wusbcore/wa-hc.h
55143 +++ b/drivers/usb/wusbcore/wa-hc.h
55144 @@ -240,7 +240,7 @@ struct wahc {
55145 spinlock_t xfer_list_lock;
55146 struct work_struct xfer_enqueue_work;
55147 struct work_struct xfer_error_work;
55148 - atomic_t xfer_id_count;
55149 + atomic_unchecked_t xfer_id_count;
55150
55151 kernel_ulong_t quirks;
55152 };
55153 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55154 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55155 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55156 wa->dto_in_use = 0;
55157 - atomic_set(&wa->xfer_id_count, 1);
55158 + atomic_set_unchecked(&wa->xfer_id_count, 1);
55159 /* init the buf in URBs */
55160 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55161 usb_init_urb(&(wa->buf_in_urbs[index]));
55162 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55163 index e279015..c2d0dae 100644
55164 --- a/drivers/usb/wusbcore/wa-xfer.c
55165 +++ b/drivers/usb/wusbcore/wa-xfer.c
55166 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55167 */
55168 static void wa_xfer_id_init(struct wa_xfer *xfer)
55169 {
55170 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55171 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55172 }
55173
55174 /* Return the xfer's ID. */
55175 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55176 index f018d8d..ccab63f 100644
55177 --- a/drivers/vfio/vfio.c
55178 +++ b/drivers/vfio/vfio.c
55179 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55180 return 0;
55181
55182 /* TODO Prevent device auto probing */
55183 - WARN("Device %s added to live group %d!\n", dev_name(dev),
55184 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55185 iommu_group_id(group->iommu_group));
55186
55187 return 0;
55188 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55189 index 5174eba..451e6bc 100644
55190 --- a/drivers/vhost/vringh.c
55191 +++ b/drivers/vhost/vringh.c
55192 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55193 /* Userspace access helpers: in this case, addresses are really userspace. */
55194 static inline int getu16_user(u16 *val, const u16 *p)
55195 {
55196 - return get_user(*val, (__force u16 __user *)p);
55197 + return get_user(*val, (u16 __force_user *)p);
55198 }
55199
55200 static inline int putu16_user(u16 *p, u16 val)
55201 {
55202 - return put_user(val, (__force u16 __user *)p);
55203 + return put_user(val, (u16 __force_user *)p);
55204 }
55205
55206 static inline int copydesc_user(void *dst, const void *src, size_t len)
55207 {
55208 - return copy_from_user(dst, (__force void __user *)src, len) ?
55209 + return copy_from_user(dst, (void __force_user *)src, len) ?
55210 -EFAULT : 0;
55211 }
55212
55213 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55214 const struct vring_used_elem *src,
55215 unsigned int num)
55216 {
55217 - return copy_to_user((__force void __user *)dst, src,
55218 + return copy_to_user((void __force_user *)dst, src,
55219 sizeof(*dst) * num) ? -EFAULT : 0;
55220 }
55221
55222 static inline int xfer_from_user(void *src, void *dst, size_t len)
55223 {
55224 - return copy_from_user(dst, (__force void __user *)src, len) ?
55225 + return copy_from_user(dst, (void __force_user *)src, len) ?
55226 -EFAULT : 0;
55227 }
55228
55229 static inline int xfer_to_user(void *dst, void *src, size_t len)
55230 {
55231 - return copy_to_user((__force void __user *)dst, src, len) ?
55232 + return copy_to_user((void __force_user *)dst, src, len) ?
55233 -EFAULT : 0;
55234 }
55235
55236 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55237 vrh->last_used_idx = 0;
55238 vrh->vring.num = num;
55239 /* vring expects kernel addresses, but only used via accessors. */
55240 - vrh->vring.desc = (__force struct vring_desc *)desc;
55241 - vrh->vring.avail = (__force struct vring_avail *)avail;
55242 - vrh->vring.used = (__force struct vring_used *)used;
55243 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55244 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55245 + vrh->vring.used = (__force_kernel struct vring_used *)used;
55246 return 0;
55247 }
55248 EXPORT_SYMBOL(vringh_init_user);
55249 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55250
55251 static inline int putu16_kern(u16 *p, u16 val)
55252 {
55253 - ACCESS_ONCE(*p) = val;
55254 + ACCESS_ONCE_RW(*p) = val;
55255 return 0;
55256 }
55257
55258 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55259 index 84a110a..96312c3 100644
55260 --- a/drivers/video/backlight/kb3886_bl.c
55261 +++ b/drivers/video/backlight/kb3886_bl.c
55262 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55263 static unsigned long kb3886bl_flags;
55264 #define KB3886BL_SUSPENDED 0x01
55265
55266 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55267 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55268 {
55269 .ident = "Sahara Touch-iT",
55270 .matches = {
55271 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55272 index 1b0b233..6f34c2c 100644
55273 --- a/drivers/video/fbdev/arcfb.c
55274 +++ b/drivers/video/fbdev/arcfb.c
55275 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55276 return -ENOSPC;
55277
55278 err = 0;
55279 - if ((count + p) > fbmemlength) {
55280 + if (count > (fbmemlength - p)) {
55281 count = fbmemlength - p;
55282 err = -ENOSPC;
55283 }
55284 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55285 index ff60701..814b973 100644
55286 --- a/drivers/video/fbdev/aty/aty128fb.c
55287 +++ b/drivers/video/fbdev/aty/aty128fb.c
55288 @@ -149,7 +149,7 @@ enum {
55289 };
55290
55291 /* Must match above enum */
55292 -static char * const r128_family[] = {
55293 +static const char * const r128_family[] = {
55294 "AGP",
55295 "PCI",
55296 "PRO AGP",
55297 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55298 index 37ec09b..98f8862 100644
55299 --- a/drivers/video/fbdev/aty/atyfb_base.c
55300 +++ b/drivers/video/fbdev/aty/atyfb_base.c
55301 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55302 par->accel_flags = var->accel_flags; /* hack */
55303
55304 if (var->accel_flags) {
55305 - info->fbops->fb_sync = atyfb_sync;
55306 + pax_open_kernel();
55307 + *(void **)&info->fbops->fb_sync = atyfb_sync;
55308 + pax_close_kernel();
55309 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55310 } else {
55311 - info->fbops->fb_sync = NULL;
55312 + pax_open_kernel();
55313 + *(void **)&info->fbops->fb_sync = NULL;
55314 + pax_close_kernel();
55315 info->flags |= FBINFO_HWACCEL_DISABLED;
55316 }
55317
55318 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55319 index 2fa0317..4983f2a 100644
55320 --- a/drivers/video/fbdev/aty/mach64_cursor.c
55321 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
55322 @@ -8,6 +8,7 @@
55323 #include "../core/fb_draw.h"
55324
55325 #include <asm/io.h>
55326 +#include <asm/pgtable.h>
55327
55328 #ifdef __sparc__
55329 #include <asm/fbio.h>
55330 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55331 info->sprite.buf_align = 16; /* and 64 lines tall. */
55332 info->sprite.flags = FB_PIXMAP_IO;
55333
55334 - info->fbops->fb_cursor = atyfb_cursor;
55335 + pax_open_kernel();
55336 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55337 + pax_close_kernel();
55338
55339 return 0;
55340 }
55341 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55342 index 900aa4e..6d49418 100644
55343 --- a/drivers/video/fbdev/core/fb_defio.c
55344 +++ b/drivers/video/fbdev/core/fb_defio.c
55345 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55346
55347 BUG_ON(!fbdefio);
55348 mutex_init(&fbdefio->lock);
55349 - info->fbops->fb_mmap = fb_deferred_io_mmap;
55350 + pax_open_kernel();
55351 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55352 + pax_close_kernel();
55353 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55354 INIT_LIST_HEAD(&fbdefio->pagelist);
55355 if (fbdefio->delay == 0) /* set a default of 1 s */
55356 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55357 page->mapping = NULL;
55358 }
55359
55360 - info->fbops->fb_mmap = NULL;
55361 + *(void **)&info->fbops->fb_mmap = NULL;
55362 mutex_destroy(&fbdefio->lock);
55363 }
55364 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55365 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55366 index b5e85f6..290f8c7 100644
55367 --- a/drivers/video/fbdev/core/fbmem.c
55368 +++ b/drivers/video/fbdev/core/fbmem.c
55369 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55370 __u32 data;
55371 int err;
55372
55373 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55374 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55375
55376 data = (__u32) (unsigned long) fix->smem_start;
55377 err |= put_user(data, &fix32->smem_start);
55378 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55379 index 4254336..282567e 100644
55380 --- a/drivers/video/fbdev/hyperv_fb.c
55381 +++ b/drivers/video/fbdev/hyperv_fb.c
55382 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55383 static inline int synthvid_send(struct hv_device *hdev,
55384 struct synthvid_msg *msg)
55385 {
55386 - static atomic64_t request_id = ATOMIC64_INIT(0);
55387 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55388 int ret;
55389
55390 msg->pipe_hdr.type = PIPE_MSG_DATA;
55391 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55392
55393 ret = vmbus_sendpacket(hdev->channel, msg,
55394 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55395 - atomic64_inc_return(&request_id),
55396 + atomic64_inc_return_unchecked(&request_id),
55397 VM_PKT_DATA_INBAND, 0);
55398
55399 if (ret)
55400 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55401 index 7672d2e..b56437f 100644
55402 --- a/drivers/video/fbdev/i810/i810_accel.c
55403 +++ b/drivers/video/fbdev/i810/i810_accel.c
55404 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55405 }
55406 }
55407 printk("ringbuffer lockup!!!\n");
55408 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55409 i810_report_error(mmio);
55410 par->dev_flags |= LOCKUP;
55411 info->pixmap.scan_align = 1;
55412 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55413 index a01147f..5d896f8 100644
55414 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55415 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55416 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55417
55418 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55419 struct matrox_switch matrox_mystique = {
55420 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55421 + .preinit = MGA1064_preinit,
55422 + .reset = MGA1064_reset,
55423 + .init = MGA1064_init,
55424 + .restore = MGA1064_restore,
55425 };
55426 EXPORT_SYMBOL(matrox_mystique);
55427 #endif
55428
55429 #ifdef CONFIG_FB_MATROX_G
55430 struct matrox_switch matrox_G100 = {
55431 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55432 + .preinit = MGAG100_preinit,
55433 + .reset = MGAG100_reset,
55434 + .init = MGAG100_init,
55435 + .restore = MGAG100_restore,
55436 };
55437 EXPORT_SYMBOL(matrox_G100);
55438 #endif
55439 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55440 index 195ad7c..09743fc 100644
55441 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55442 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55443 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55444 }
55445
55446 struct matrox_switch matrox_millennium = {
55447 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55448 + .preinit = Ti3026_preinit,
55449 + .reset = Ti3026_reset,
55450 + .init = Ti3026_init,
55451 + .restore = Ti3026_restore
55452 };
55453 EXPORT_SYMBOL(matrox_millennium);
55454 #endif
55455 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55456 index fe92eed..106e085 100644
55457 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55458 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55459 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55460 struct mb862xxfb_par *par = info->par;
55461
55462 if (info->var.bits_per_pixel == 32) {
55463 - info->fbops->fb_fillrect = cfb_fillrect;
55464 - info->fbops->fb_copyarea = cfb_copyarea;
55465 - info->fbops->fb_imageblit = cfb_imageblit;
55466 + pax_open_kernel();
55467 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55468 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55469 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55470 + pax_close_kernel();
55471 } else {
55472 outreg(disp, GC_L0EM, 3);
55473 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55474 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55475 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55476 + pax_open_kernel();
55477 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55478 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55479 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55480 + pax_close_kernel();
55481 }
55482 outreg(draw, GDC_REG_DRAW_BASE, 0);
55483 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55484 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55485 index def0412..fed6529 100644
55486 --- a/drivers/video/fbdev/nvidia/nvidia.c
55487 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55488 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55489 info->fix.line_length = (info->var.xres_virtual *
55490 info->var.bits_per_pixel) >> 3;
55491 if (info->var.accel_flags) {
55492 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55493 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55494 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55495 - info->fbops->fb_sync = nvidiafb_sync;
55496 + pax_open_kernel();
55497 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55498 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55499 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55500 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55501 + pax_close_kernel();
55502 info->pixmap.scan_align = 4;
55503 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55504 info->flags |= FBINFO_READS_FAST;
55505 NVResetGraphics(info);
55506 } else {
55507 - info->fbops->fb_imageblit = cfb_imageblit;
55508 - info->fbops->fb_fillrect = cfb_fillrect;
55509 - info->fbops->fb_copyarea = cfb_copyarea;
55510 - info->fbops->fb_sync = NULL;
55511 + pax_open_kernel();
55512 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55513 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55514 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55515 + *(void **)&info->fbops->fb_sync = NULL;
55516 + pax_close_kernel();
55517 info->pixmap.scan_align = 1;
55518 info->flags |= FBINFO_HWACCEL_DISABLED;
55519 info->flags &= ~FBINFO_READS_FAST;
55520 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55521 info->pixmap.size = 8 * 1024;
55522 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55523
55524 - if (!hwcur)
55525 - info->fbops->fb_cursor = NULL;
55526 + if (!hwcur) {
55527 + pax_open_kernel();
55528 + *(void **)&info->fbops->fb_cursor = NULL;
55529 + pax_close_kernel();
55530 + }
55531
55532 info->var.accel_flags = (!noaccel);
55533
55534 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55535 index 2412a0d..294215b 100644
55536 --- a/drivers/video/fbdev/omap2/dss/display.c
55537 +++ b/drivers/video/fbdev/omap2/dss/display.c
55538 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55539 if (dssdev->name == NULL)
55540 dssdev->name = dssdev->alias;
55541
55542 + pax_open_kernel();
55543 if (drv && drv->get_resolution == NULL)
55544 - drv->get_resolution = omapdss_default_get_resolution;
55545 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55546 if (drv && drv->get_recommended_bpp == NULL)
55547 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55548 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55549 if (drv && drv->get_timings == NULL)
55550 - drv->get_timings = omapdss_default_get_timings;
55551 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55552 + pax_close_kernel();
55553
55554 mutex_lock(&panel_list_mutex);
55555 list_add_tail(&dssdev->panel_list, &panel_list);
55556 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55557 index 83433cb..71e9b98 100644
55558 --- a/drivers/video/fbdev/s1d13xxxfb.c
55559 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55560 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55561
55562 switch(prod_id) {
55563 case S1D13506_PROD_ID: /* activate acceleration */
55564 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55565 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55566 + pax_open_kernel();
55567 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55568 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55569 + pax_close_kernel();
55570 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55571 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55572 break;
55573 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55574 index 2bcc84a..29dd1ea 100644
55575 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55576 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55577 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55578 }
55579
55580 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55581 - lcdc_sys_write_index,
55582 - lcdc_sys_write_data,
55583 - lcdc_sys_read_data,
55584 + .write_index = lcdc_sys_write_index,
55585 + .write_data = lcdc_sys_write_data,
55586 + .read_data = lcdc_sys_read_data,
55587 };
55588
55589 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55590 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55591 index d513ed6..90b0de9 100644
55592 --- a/drivers/video/fbdev/smscufx.c
55593 +++ b/drivers/video/fbdev/smscufx.c
55594 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55595 fb_deferred_io_cleanup(info);
55596 kfree(info->fbdefio);
55597 info->fbdefio = NULL;
55598 - info->fbops->fb_mmap = ufx_ops_mmap;
55599 + pax_open_kernel();
55600 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55601 + pax_close_kernel();
55602 }
55603
55604 pr_debug("released /dev/fb%d user=%d count=%d",
55605 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55606 index 77b890e..458e666 100644
55607 --- a/drivers/video/fbdev/udlfb.c
55608 +++ b/drivers/video/fbdev/udlfb.c
55609 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55610 dlfb_urb_completion(urb);
55611
55612 error:
55613 - atomic_add(bytes_sent, &dev->bytes_sent);
55614 - atomic_add(bytes_identical, &dev->bytes_identical);
55615 - atomic_add(width*height*2, &dev->bytes_rendered);
55616 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55617 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55618 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55619 end_cycles = get_cycles();
55620 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55621 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55622 >> 10)), /* Kcycles */
55623 &dev->cpu_kcycles_used);
55624
55625 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55626 dlfb_urb_completion(urb);
55627
55628 error:
55629 - atomic_add(bytes_sent, &dev->bytes_sent);
55630 - atomic_add(bytes_identical, &dev->bytes_identical);
55631 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55632 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55633 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55634 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55635 end_cycles = get_cycles();
55636 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55637 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55638 >> 10)), /* Kcycles */
55639 &dev->cpu_kcycles_used);
55640 }
55641 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55642 fb_deferred_io_cleanup(info);
55643 kfree(info->fbdefio);
55644 info->fbdefio = NULL;
55645 - info->fbops->fb_mmap = dlfb_ops_mmap;
55646 + pax_open_kernel();
55647 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55648 + pax_close_kernel();
55649 }
55650
55651 pr_warn("released /dev/fb%d user=%d count=%d\n",
55652 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55653 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55654 struct dlfb_data *dev = fb_info->par;
55655 return snprintf(buf, PAGE_SIZE, "%u\n",
55656 - atomic_read(&dev->bytes_rendered));
55657 + atomic_read_unchecked(&dev->bytes_rendered));
55658 }
55659
55660 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55661 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55662 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55663 struct dlfb_data *dev = fb_info->par;
55664 return snprintf(buf, PAGE_SIZE, "%u\n",
55665 - atomic_read(&dev->bytes_identical));
55666 + atomic_read_unchecked(&dev->bytes_identical));
55667 }
55668
55669 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55670 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55671 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55672 struct dlfb_data *dev = fb_info->par;
55673 return snprintf(buf, PAGE_SIZE, "%u\n",
55674 - atomic_read(&dev->bytes_sent));
55675 + atomic_read_unchecked(&dev->bytes_sent));
55676 }
55677
55678 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55679 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55680 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55681 struct dlfb_data *dev = fb_info->par;
55682 return snprintf(buf, PAGE_SIZE, "%u\n",
55683 - atomic_read(&dev->cpu_kcycles_used));
55684 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55685 }
55686
55687 static ssize_t edid_show(
55688 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55689 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55690 struct dlfb_data *dev = fb_info->par;
55691
55692 - atomic_set(&dev->bytes_rendered, 0);
55693 - atomic_set(&dev->bytes_identical, 0);
55694 - atomic_set(&dev->bytes_sent, 0);
55695 - atomic_set(&dev->cpu_kcycles_used, 0);
55696 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55697 + atomic_set_unchecked(&dev->bytes_identical, 0);
55698 + atomic_set_unchecked(&dev->bytes_sent, 0);
55699 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55700
55701 return count;
55702 }
55703 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55704 index 509d452..7c9d2de 100644
55705 --- a/drivers/video/fbdev/uvesafb.c
55706 +++ b/drivers/video/fbdev/uvesafb.c
55707 @@ -19,6 +19,7 @@
55708 #include <linux/io.h>
55709 #include <linux/mutex.h>
55710 #include <linux/slab.h>
55711 +#include <linux/moduleloader.h>
55712 #include <video/edid.h>
55713 #include <video/uvesafb.h>
55714 #ifdef CONFIG_X86
55715 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55716 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55717 par->pmi_setpal = par->ypan = 0;
55718 } else {
55719 +
55720 +#ifdef CONFIG_PAX_KERNEXEC
55721 +#ifdef CONFIG_MODULES
55722 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55723 +#endif
55724 + if (!par->pmi_code) {
55725 + par->pmi_setpal = par->ypan = 0;
55726 + return 0;
55727 + }
55728 +#endif
55729 +
55730 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55731 + task->t.regs.edi);
55732 +
55733 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55734 + pax_open_kernel();
55735 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55736 + pax_close_kernel();
55737 +
55738 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55739 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55740 +#else
55741 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55742 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55743 +#endif
55744 +
55745 printk(KERN_INFO "uvesafb: protected mode interface info at "
55746 "%04x:%04x\n",
55747 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55748 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55749 par->ypan = ypan;
55750
55751 if (par->pmi_setpal || par->ypan) {
55752 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55753 if (__supported_pte_mask & _PAGE_NX) {
55754 par->pmi_setpal = par->ypan = 0;
55755 printk(KERN_WARNING "uvesafb: NX protection is active, "
55756 "better not use the PMI.\n");
55757 - } else {
55758 + } else
55759 +#endif
55760 uvesafb_vbe_getpmi(task, par);
55761 - }
55762 }
55763 #else
55764 /* The protected mode interface is not available on non-x86. */
55765 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55766 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55767
55768 /* Disable blanking if the user requested so. */
55769 - if (!blank)
55770 - info->fbops->fb_blank = NULL;
55771 + if (!blank) {
55772 + pax_open_kernel();
55773 + *(void **)&info->fbops->fb_blank = NULL;
55774 + pax_close_kernel();
55775 + }
55776
55777 /*
55778 * Find out how much IO memory is required for the mode with
55779 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55780 info->flags = FBINFO_FLAG_DEFAULT |
55781 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55782
55783 - if (!par->ypan)
55784 - info->fbops->fb_pan_display = NULL;
55785 + if (!par->ypan) {
55786 + pax_open_kernel();
55787 + *(void **)&info->fbops->fb_pan_display = NULL;
55788 + pax_close_kernel();
55789 + }
55790 }
55791
55792 static void uvesafb_init_mtrr(struct fb_info *info)
55793 @@ -1787,6 +1817,11 @@ out_mode:
55794 out:
55795 kfree(par->vbe_modes);
55796
55797 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55798 + if (par->pmi_code)
55799 + module_free_exec(NULL, par->pmi_code);
55800 +#endif
55801 +
55802 framebuffer_release(info);
55803 return err;
55804 }
55805 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55806 kfree(par->vbe_state_orig);
55807 kfree(par->vbe_state_saved);
55808
55809 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55810 + if (par->pmi_code)
55811 + module_free_exec(NULL, par->pmi_code);
55812 +#endif
55813 +
55814 framebuffer_release(info);
55815 }
55816 return 0;
55817 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55818 index 6170e7f..dd63031 100644
55819 --- a/drivers/video/fbdev/vesafb.c
55820 +++ b/drivers/video/fbdev/vesafb.c
55821 @@ -9,6 +9,7 @@
55822 */
55823
55824 #include <linux/module.h>
55825 +#include <linux/moduleloader.h>
55826 #include <linux/kernel.h>
55827 #include <linux/errno.h>
55828 #include <linux/string.h>
55829 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55830 static int vram_total; /* Set total amount of memory */
55831 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55832 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55833 -static void (*pmi_start)(void) __read_mostly;
55834 -static void (*pmi_pal) (void) __read_mostly;
55835 +static void (*pmi_start)(void) __read_only;
55836 +static void (*pmi_pal) (void) __read_only;
55837 static int depth __read_mostly;
55838 static int vga_compat __read_mostly;
55839 /* --------------------------------------------------------------------- */
55840 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55841 unsigned int size_remap;
55842 unsigned int size_total;
55843 char *option = NULL;
55844 + void *pmi_code = NULL;
55845
55846 /* ignore error return of fb_get_options */
55847 fb_get_options("vesafb", &option);
55848 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55849 size_remap = size_total;
55850 vesafb_fix.smem_len = size_remap;
55851
55852 -#ifndef __i386__
55853 - screen_info.vesapm_seg = 0;
55854 -#endif
55855 -
55856 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55857 printk(KERN_WARNING
55858 "vesafb: cannot reserve video memory at 0x%lx\n",
55859 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55860 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55861 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55862
55863 +#ifdef __i386__
55864 +
55865 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55866 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55867 + if (!pmi_code)
55868 +#elif !defined(CONFIG_PAX_KERNEXEC)
55869 + if (0)
55870 +#endif
55871 +
55872 +#endif
55873 + screen_info.vesapm_seg = 0;
55874 +
55875 if (screen_info.vesapm_seg) {
55876 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55877 - screen_info.vesapm_seg,screen_info.vesapm_off);
55878 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55879 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55880 }
55881
55882 if (screen_info.vesapm_seg < 0xc000)
55883 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55884
55885 if (ypan || pmi_setpal) {
55886 unsigned short *pmi_base;
55887 +
55888 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55889 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55890 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55891 +
55892 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55893 + pax_open_kernel();
55894 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55895 +#else
55896 + pmi_code = pmi_base;
55897 +#endif
55898 +
55899 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55900 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55901 +
55902 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55903 + pmi_start = ktva_ktla(pmi_start);
55904 + pmi_pal = ktva_ktla(pmi_pal);
55905 + pax_close_kernel();
55906 +#endif
55907 +
55908 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55909 if (pmi_base[3]) {
55910 printk(KERN_INFO "vesafb: pmi: ports = ");
55911 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55912 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55913 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55914
55915 - if (!ypan)
55916 - info->fbops->fb_pan_display = NULL;
55917 + if (!ypan) {
55918 + pax_open_kernel();
55919 + *(void **)&info->fbops->fb_pan_display = NULL;
55920 + pax_close_kernel();
55921 + }
55922
55923 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55924 err = -ENOMEM;
55925 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55926 fb_info(info, "%s frame buffer device\n", info->fix.id);
55927 return 0;
55928 err:
55929 +
55930 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55931 + module_free_exec(NULL, pmi_code);
55932 +#endif
55933 +
55934 if (info->screen_base)
55935 iounmap(info->screen_base);
55936 framebuffer_release(info);
55937 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55938 index 88714ae..16c2e11 100644
55939 --- a/drivers/video/fbdev/via/via_clock.h
55940 +++ b/drivers/video/fbdev/via/via_clock.h
55941 @@ -56,7 +56,7 @@ struct via_clock {
55942
55943 void (*set_engine_pll_state)(u8 state);
55944 void (*set_engine_pll)(struct via_pll_config config);
55945 -};
55946 +} __no_const;
55947
55948
55949 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55950 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55951 index 3c14e43..2630570 100644
55952 --- a/drivers/video/logo/logo_linux_clut224.ppm
55953 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55954 @@ -2,1603 +2,1123 @@ P3
55955 # Standard 224-color Linux logo
55956 80 80
55957 255
55958 - 0 0 0 0 0 0 0 0 0 0 0 0
55959 - 0 0 0 0 0 0 0 0 0 0 0 0
55960 - 0 0 0 0 0 0 0 0 0 0 0 0
55961 - 0 0 0 0 0 0 0 0 0 0 0 0
55962 - 0 0 0 0 0 0 0 0 0 0 0 0
55963 - 0 0 0 0 0 0 0 0 0 0 0 0
55964 - 0 0 0 0 0 0 0 0 0 0 0 0
55965 - 0 0 0 0 0 0 0 0 0 0 0 0
55966 - 0 0 0 0 0 0 0 0 0 0 0 0
55967 - 6 6 6 6 6 6 10 10 10 10 10 10
55968 - 10 10 10 6 6 6 6 6 6 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 0 0 0
55982 - 0 0 0 0 0 0 0 0 0 0 0 0
55983 - 0 0 0 0 0 0 0 0 0 0 0 0
55984 - 0 0 0 0 0 0 0 0 0 0 0 0
55985 - 0 0 0 0 0 0 0 0 0 0 0 0
55986 - 0 0 0 6 6 6 10 10 10 14 14 14
55987 - 22 22 22 26 26 26 30 30 30 34 34 34
55988 - 30 30 30 30 30 30 26 26 26 18 18 18
55989 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0
55996 - 0 0 0 0 0 0 0 0 0 0 0 0
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 1 0 0 1 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 0 0 0
56002 - 0 0 0 0 0 0 0 0 0 0 0 0
56003 - 0 0 0 0 0 0 0 0 0 0 0 0
56004 - 0 0 0 0 0 0 0 0 0 0 0 0
56005 - 0 0 0 0 0 0 0 0 0 0 0 0
56006 - 6 6 6 14 14 14 26 26 26 42 42 42
56007 - 54 54 54 66 66 66 78 78 78 78 78 78
56008 - 78 78 78 74 74 74 66 66 66 54 54 54
56009 - 42 42 42 26 26 26 18 18 18 10 10 10
56010 - 6 6 6 0 0 0 0 0 0 0 0 0
56011 - 0 0 0 0 0 0 0 0 0 0 0 0
56012 - 0 0 0 0 0 0 0 0 0 0 0 0
56013 - 0 0 0 0 0 0 0 0 0 0 0 0
56014 - 0 0 0 0 0 0 0 0 0 0 0 0
56015 - 0 0 0 0 0 0 0 0 0 0 0 0
56016 - 0 0 0 0 0 0 0 0 0 0 0 0
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 1 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 0 0 0
56022 - 0 0 0 0 0 0 0 0 0 0 0 0
56023 - 0 0 0 0 0 0 0 0 0 0 0 0
56024 - 0 0 0 0 0 0 0 0 0 0 0 0
56025 - 0 0 0 0 0 0 0 0 0 10 10 10
56026 - 22 22 22 42 42 42 66 66 66 86 86 86
56027 - 66 66 66 38 38 38 38 38 38 22 22 22
56028 - 26 26 26 34 34 34 54 54 54 66 66 66
56029 - 86 86 86 70 70 70 46 46 46 26 26 26
56030 - 14 14 14 6 6 6 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 0 0 0 0
56036 - 0 0 0 0 0 0 0 0 0 0 0 0
56037 - 0 0 0 0 0 0 0 0 0 0 0 0
56038 - 0 0 0 0 0 0 0 0 0 0 0 0
56039 - 0 0 1 0 0 1 0 0 1 0 0 0
56040 - 0 0 0 0 0 0 0 0 0 0 0 0
56041 - 0 0 0 0 0 0 0 0 0 0 0 0
56042 - 0 0 0 0 0 0 0 0 0 0 0 0
56043 - 0 0 0 0 0 0 0 0 0 0 0 0
56044 - 0 0 0 0 0 0 0 0 0 0 0 0
56045 - 0 0 0 0 0 0 10 10 10 26 26 26
56046 - 50 50 50 82 82 82 58 58 58 6 6 6
56047 - 2 2 6 2 2 6 2 2 6 2 2 6
56048 - 2 2 6 2 2 6 2 2 6 2 2 6
56049 - 6 6 6 54 54 54 86 86 86 66 66 66
56050 - 38 38 38 18 18 18 6 6 6 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 0 0 0
56062 - 0 0 0 0 0 0 0 0 0 0 0 0
56063 - 0 0 0 0 0 0 0 0 0 0 0 0
56064 - 0 0 0 0 0 0 0 0 0 0 0 0
56065 - 0 0 0 6 6 6 22 22 22 50 50 50
56066 - 78 78 78 34 34 34 2 2 6 2 2 6
56067 - 2 2 6 2 2 6 2 2 6 2 2 6
56068 - 2 2 6 2 2 6 2 2 6 2 2 6
56069 - 2 2 6 2 2 6 6 6 6 70 70 70
56070 - 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
56080 - 0 0 0 0 0 0 0 0 0 0 0 0
56081 - 0 0 0 0 0 0 0 0 0 0 0 0
56082 - 0 0 0 0 0 0 0 0 0 0 0 0
56083 - 0 0 0 0 0 0 0 0 0 0 0 0
56084 - 0 0 0 0 0 0 0 0 0 0 0 0
56085 - 6 6 6 18 18 18 42 42 42 82 82 82
56086 - 26 26 26 2 2 6 2 2 6 2 2 6
56087 - 2 2 6 2 2 6 2 2 6 2 2 6
56088 - 2 2 6 2 2 6 2 2 6 14 14 14
56089 - 46 46 46 34 34 34 6 6 6 2 2 6
56090 - 42 42 42 78 78 78 42 42 42 18 18 18
56091 - 6 6 6 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 1 0 0 0 0 0 1 0 0 0
56100 - 0 0 0 0 0 0 0 0 0 0 0 0
56101 - 0 0 0 0 0 0 0 0 0 0 0 0
56102 - 0 0 0 0 0 0 0 0 0 0 0 0
56103 - 0 0 0 0 0 0 0 0 0 0 0 0
56104 - 0 0 0 0 0 0 0 0 0 0 0 0
56105 - 10 10 10 30 30 30 66 66 66 58 58 58
56106 - 2 2 6 2 2 6 2 2 6 2 2 6
56107 - 2 2 6 2 2 6 2 2 6 2 2 6
56108 - 2 2 6 2 2 6 2 2 6 26 26 26
56109 - 86 86 86 101 101 101 46 46 46 10 10 10
56110 - 2 2 6 58 58 58 70 70 70 34 34 34
56111 - 10 10 10 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 1 0 0 1 0 0 1 0 0 0
56120 - 0 0 0 0 0 0 0 0 0 0 0 0
56121 - 0 0 0 0 0 0 0 0 0 0 0 0
56122 - 0 0 0 0 0 0 0 0 0 0 0 0
56123 - 0 0 0 0 0 0 0 0 0 0 0 0
56124 - 0 0 0 0 0 0 0 0 0 0 0 0
56125 - 14 14 14 42 42 42 86 86 86 10 10 10
56126 - 2 2 6 2 2 6 2 2 6 2 2 6
56127 - 2 2 6 2 2 6 2 2 6 2 2 6
56128 - 2 2 6 2 2 6 2 2 6 30 30 30
56129 - 94 94 94 94 94 94 58 58 58 26 26 26
56130 - 2 2 6 6 6 6 78 78 78 54 54 54
56131 - 22 22 22 6 6 6 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 0 0 0
56142 - 0 0 0 0 0 0 0 0 0 0 0 0
56143 - 0 0 0 0 0 0 0 0 0 0 0 0
56144 - 0 0 0 0 0 0 0 0 0 6 6 6
56145 - 22 22 22 62 62 62 62 62 62 2 2 6
56146 - 2 2 6 2 2 6 2 2 6 2 2 6
56147 - 2 2 6 2 2 6 2 2 6 2 2 6
56148 - 2 2 6 2 2 6 2 2 6 26 26 26
56149 - 54 54 54 38 38 38 18 18 18 10 10 10
56150 - 2 2 6 2 2 6 34 34 34 82 82 82
56151 - 38 38 38 14 14 14 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 1 0 0 1 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 0 0 0 0 0 0 0 0 0
56162 - 0 0 0 0 0 0 0 0 0 0 0 0
56163 - 0 0 0 0 0 0 0 0 0 0 0 0
56164 - 0 0 0 0 0 0 0 0 0 6 6 6
56165 - 30 30 30 78 78 78 30 30 30 2 2 6
56166 - 2 2 6 2 2 6 2 2 6 2 2 6
56167 - 2 2 6 2 2 6 2 2 6 2 2 6
56168 - 2 2 6 2 2 6 2 2 6 10 10 10
56169 - 10 10 10 2 2 6 2 2 6 2 2 6
56170 - 2 2 6 2 2 6 2 2 6 78 78 78
56171 - 50 50 50 18 18 18 6 6 6 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 1 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 0 0 0 0 0 0 0 0 0 0 0 0
56182 - 0 0 0 0 0 0 0 0 0 0 0 0
56183 - 0 0 0 0 0 0 0 0 0 0 0 0
56184 - 0 0 0 0 0 0 0 0 0 10 10 10
56185 - 38 38 38 86 86 86 14 14 14 2 2 6
56186 - 2 2 6 2 2 6 2 2 6 2 2 6
56187 - 2 2 6 2 2 6 2 2 6 2 2 6
56188 - 2 2 6 2 2 6 2 2 6 2 2 6
56189 - 2 2 6 2 2 6 2 2 6 2 2 6
56190 - 2 2 6 2 2 6 2 2 6 54 54 54
56191 - 66 66 66 26 26 26 6 6 6 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 1 0 0 1 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 0 0 0
56201 - 0 0 0 0 0 0 0 0 0 0 0 0
56202 - 0 0 0 0 0 0 0 0 0 0 0 0
56203 - 0 0 0 0 0 0 0 0 0 0 0 0
56204 - 0 0 0 0 0 0 0 0 0 14 14 14
56205 - 42 42 42 82 82 82 2 2 6 2 2 6
56206 - 2 2 6 6 6 6 10 10 10 2 2 6
56207 - 2 2 6 2 2 6 2 2 6 2 2 6
56208 - 2 2 6 2 2 6 2 2 6 6 6 6
56209 - 14 14 14 10 10 10 2 2 6 2 2 6
56210 - 2 2 6 2 2 6 2 2 6 18 18 18
56211 - 82 82 82 34 34 34 10 10 10 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 1 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 0 0 0
56221 - 0 0 0 0 0 0 0 0 0 0 0 0
56222 - 0 0 0 0 0 0 0 0 0 0 0 0
56223 - 0 0 0 0 0 0 0 0 0 0 0 0
56224 - 0 0 0 0 0 0 0 0 0 14 14 14
56225 - 46 46 46 86 86 86 2 2 6 2 2 6
56226 - 6 6 6 6 6 6 22 22 22 34 34 34
56227 - 6 6 6 2 2 6 2 2 6 2 2 6
56228 - 2 2 6 2 2 6 18 18 18 34 34 34
56229 - 10 10 10 50 50 50 22 22 22 2 2 6
56230 - 2 2 6 2 2 6 2 2 6 10 10 10
56231 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
56240 - 0 0 0 0 0 0 0 0 0 0 0 0
56241 - 0 0 0 0 0 0 0 0 0 0 0 0
56242 - 0 0 0 0 0 0 0 0 0 0 0 0
56243 - 0 0 0 0 0 0 0 0 0 0 0 0
56244 - 0 0 0 0 0 0 0 0 0 14 14 14
56245 - 46 46 46 86 86 86 2 2 6 2 2 6
56246 - 38 38 38 116 116 116 94 94 94 22 22 22
56247 - 22 22 22 2 2 6 2 2 6 2 2 6
56248 - 14 14 14 86 86 86 138 138 138 162 162 162
56249 -154 154 154 38 38 38 26 26 26 6 6 6
56250 - 2 2 6 2 2 6 2 2 6 2 2 6
56251 - 86 86 86 46 46 46 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
56262 - 0 0 0 0 0 0 0 0 0 0 0 0
56263 - 0 0 0 0 0 0 0 0 0 0 0 0
56264 - 0 0 0 0 0 0 0 0 0 14 14 14
56265 - 46 46 46 86 86 86 2 2 6 14 14 14
56266 -134 134 134 198 198 198 195 195 195 116 116 116
56267 - 10 10 10 2 2 6 2 2 6 6 6 6
56268 -101 98 89 187 187 187 210 210 210 218 218 218
56269 -214 214 214 134 134 134 14 14 14 6 6 6
56270 - 2 2 6 2 2 6 2 2 6 2 2 6
56271 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
56279 - 0 0 1 0 0 1 0 0 1 0 0 0
56280 - 0 0 0 0 0 0 0 0 0 0 0 0
56281 - 0 0 0 0 0 0 0 0 0 0 0 0
56282 - 0 0 0 0 0 0 0 0 0 0 0 0
56283 - 0 0 0 0 0 0 0 0 0 0 0 0
56284 - 0 0 0 0 0 0 0 0 0 14 14 14
56285 - 46 46 46 86 86 86 2 2 6 54 54 54
56286 -218 218 218 195 195 195 226 226 226 246 246 246
56287 - 58 58 58 2 2 6 2 2 6 30 30 30
56288 -210 210 210 253 253 253 174 174 174 123 123 123
56289 -221 221 221 234 234 234 74 74 74 2 2 6
56290 - 2 2 6 2 2 6 2 2 6 2 2 6
56291 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
56301 - 0 0 0 0 0 0 0 0 0 0 0 0
56302 - 0 0 0 0 0 0 0 0 0 0 0 0
56303 - 0 0 0 0 0 0 0 0 0 0 0 0
56304 - 0 0 0 0 0 0 0 0 0 14 14 14
56305 - 46 46 46 82 82 82 2 2 6 106 106 106
56306 -170 170 170 26 26 26 86 86 86 226 226 226
56307 -123 123 123 10 10 10 14 14 14 46 46 46
56308 -231 231 231 190 190 190 6 6 6 70 70 70
56309 - 90 90 90 238 238 238 158 158 158 2 2 6
56310 - 2 2 6 2 2 6 2 2 6 2 2 6
56311 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
56319 - 0 0 1 0 0 1 0 0 1 0 0 0
56320 - 0 0 0 0 0 0 0 0 0 0 0 0
56321 - 0 0 0 0 0 0 0 0 0 0 0 0
56322 - 0 0 0 0 0 0 0 0 0 0 0 0
56323 - 0 0 0 0 0 0 0 0 0 0 0 0
56324 - 0 0 0 0 0 0 0 0 0 14 14 14
56325 - 42 42 42 86 86 86 6 6 6 116 116 116
56326 -106 106 106 6 6 6 70 70 70 149 149 149
56327 -128 128 128 18 18 18 38 38 38 54 54 54
56328 -221 221 221 106 106 106 2 2 6 14 14 14
56329 - 46 46 46 190 190 190 198 198 198 2 2 6
56330 - 2 2 6 2 2 6 2 2 6 2 2 6
56331 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
56339 - 0 0 1 0 0 0 0 0 1 0 0 0
56340 - 0 0 0 0 0 0 0 0 0 0 0 0
56341 - 0 0 0 0 0 0 0 0 0 0 0 0
56342 - 0 0 0 0 0 0 0 0 0 0 0 0
56343 - 0 0 0 0 0 0 0 0 0 0 0 0
56344 - 0 0 0 0 0 0 0 0 0 14 14 14
56345 - 42 42 42 94 94 94 14 14 14 101 101 101
56346 -128 128 128 2 2 6 18 18 18 116 116 116
56347 -118 98 46 121 92 8 121 92 8 98 78 10
56348 -162 162 162 106 106 106 2 2 6 2 2 6
56349 - 2 2 6 195 195 195 195 195 195 6 6 6
56350 - 2 2 6 2 2 6 2 2 6 2 2 6
56351 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
56359 - 0 0 1 0 0 0 0 0 1 0 0 0
56360 - 0 0 0 0 0 0 0 0 0 0 0 0
56361 - 0 0 0 0 0 0 0 0 0 0 0 0
56362 - 0 0 0 0 0 0 0 0 0 0 0 0
56363 - 0 0 0 0 0 0 0 0 0 0 0 0
56364 - 0 0 0 0 0 0 0 0 0 10 10 10
56365 - 38 38 38 90 90 90 14 14 14 58 58 58
56366 -210 210 210 26 26 26 54 38 6 154 114 10
56367 -226 170 11 236 186 11 225 175 15 184 144 12
56368 -215 174 15 175 146 61 37 26 9 2 2 6
56369 - 70 70 70 246 246 246 138 138 138 2 2 6
56370 - 2 2 6 2 2 6 2 2 6 2 2 6
56371 - 70 70 70 66 66 66 26 26 26 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
56381 - 0 0 0 0 0 0 0 0 0 0 0 0
56382 - 0 0 0 0 0 0 0 0 0 0 0 0
56383 - 0 0 0 0 0 0 0 0 0 0 0 0
56384 - 0 0 0 0 0 0 0 0 0 10 10 10
56385 - 38 38 38 86 86 86 14 14 14 10 10 10
56386 -195 195 195 188 164 115 192 133 9 225 175 15
56387 -239 182 13 234 190 10 232 195 16 232 200 30
56388 -245 207 45 241 208 19 232 195 16 184 144 12
56389 -218 194 134 211 206 186 42 42 42 2 2 6
56390 - 2 2 6 2 2 6 2 2 6 2 2 6
56391 - 50 50 50 74 74 74 30 30 30 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
56401 - 0 0 0 0 0 0 0 0 0 0 0 0
56402 - 0 0 0 0 0 0 0 0 0 0 0 0
56403 - 0 0 0 0 0 0 0 0 0 0 0 0
56404 - 0 0 0 0 0 0 0 0 0 10 10 10
56405 - 34 34 34 86 86 86 14 14 14 2 2 6
56406 -121 87 25 192 133 9 219 162 10 239 182 13
56407 -236 186 11 232 195 16 241 208 19 244 214 54
56408 -246 218 60 246 218 38 246 215 20 241 208 19
56409 -241 208 19 226 184 13 121 87 25 2 2 6
56410 - 2 2 6 2 2 6 2 2 6 2 2 6
56411 - 50 50 50 82 82 82 34 34 34 10 10 10
56412 - 0 0 0 0 0 0 0 0 0 0 0 0
56413 - 0 0 0 0 0 0 0 0 0 0 0 0
56414 - 0 0 0 0 0 0 0 0 0 0 0 0
56415 - 0 0 0 0 0 0 0 0 0 0 0 0
56416 - 0 0 0 0 0 0 0 0 0 0 0 0
56417 - 0 0 0 0 0 0 0 0 0 0 0 0
56418 - 0 0 0 0 0 0 0 0 0 0 0 0
56419 - 0 0 0 0 0 0 0 0 0 0 0 0
56420 - 0 0 0 0 0 0 0 0 0 0 0 0
56421 - 0 0 0 0 0 0 0 0 0 0 0 0
56422 - 0 0 0 0 0 0 0 0 0 0 0 0
56423 - 0 0 0 0 0 0 0 0 0 0 0 0
56424 - 0 0 0 0 0 0 0 0 0 10 10 10
56425 - 34 34 34 82 82 82 30 30 30 61 42 6
56426 -180 123 7 206 145 10 230 174 11 239 182 13
56427 -234 190 10 238 202 15 241 208 19 246 218 74
56428 -246 218 38 246 215 20 246 215 20 246 215 20
56429 -226 184 13 215 174 15 184 144 12 6 6 6
56430 - 2 2 6 2 2 6 2 2 6 2 2 6
56431 - 26 26 26 94 94 94 42 42 42 14 14 14
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 0 0 0 0 0 0
56435 - 0 0 0 0 0 0 0 0 0 0 0 0
56436 - 0 0 0 0 0 0 0 0 0 0 0 0
56437 - 0 0 0 0 0 0 0 0 0 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 0 0 0
56439 - 0 0 0 0 0 0 0 0 0 0 0 0
56440 - 0 0 0 0 0 0 0 0 0 0 0 0
56441 - 0 0 0 0 0 0 0 0 0 0 0 0
56442 - 0 0 0 0 0 0 0 0 0 0 0 0
56443 - 0 0 0 0 0 0 0 0 0 0 0 0
56444 - 0 0 0 0 0 0 0 0 0 10 10 10
56445 - 30 30 30 78 78 78 50 50 50 104 69 6
56446 -192 133 9 216 158 10 236 178 12 236 186 11
56447 -232 195 16 241 208 19 244 214 54 245 215 43
56448 -246 215 20 246 215 20 241 208 19 198 155 10
56449 -200 144 11 216 158 10 156 118 10 2 2 6
56450 - 2 2 6 2 2 6 2 2 6 2 2 6
56451 - 6 6 6 90 90 90 54 54 54 18 18 18
56452 - 6 6 6 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 0 0 0 0 0 0 0 0 0
56455 - 0 0 0 0 0 0 0 0 0 0 0 0
56456 - 0 0 0 0 0 0 0 0 0 0 0 0
56457 - 0 0 0 0 0 0 0 0 0 0 0 0
56458 - 0 0 0 0 0 0 0 0 0 0 0 0
56459 - 0 0 0 0 0 0 0 0 0 0 0 0
56460 - 0 0 0 0 0 0 0 0 0 0 0 0
56461 - 0 0 0 0 0 0 0 0 0 0 0 0
56462 - 0 0 0 0 0 0 0 0 0 0 0 0
56463 - 0 0 0 0 0 0 0 0 0 0 0 0
56464 - 0 0 0 0 0 0 0 0 0 10 10 10
56465 - 30 30 30 78 78 78 46 46 46 22 22 22
56466 -137 92 6 210 162 10 239 182 13 238 190 10
56467 -238 202 15 241 208 19 246 215 20 246 215 20
56468 -241 208 19 203 166 17 185 133 11 210 150 10
56469 -216 158 10 210 150 10 102 78 10 2 2 6
56470 - 6 6 6 54 54 54 14 14 14 2 2 6
56471 - 2 2 6 62 62 62 74 74 74 30 30 30
56472 - 10 10 10 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 0 0 0 0 0 0 0 0 0 0 0 0
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 0 0 0 0 0 0 0 0 0 0 0 0
56480 - 0 0 0 0 0 0 0 0 0 0 0 0
56481 - 0 0 0 0 0 0 0 0 0 0 0 0
56482 - 0 0 0 0 0 0 0 0 0 0 0 0
56483 - 0 0 0 0 0 0 0 0 0 0 0 0
56484 - 0 0 0 0 0 0 0 0 0 10 10 10
56485 - 34 34 34 78 78 78 50 50 50 6 6 6
56486 - 94 70 30 139 102 15 190 146 13 226 184 13
56487 -232 200 30 232 195 16 215 174 15 190 146 13
56488 -168 122 10 192 133 9 210 150 10 213 154 11
56489 -202 150 34 182 157 106 101 98 89 2 2 6
56490 - 2 2 6 78 78 78 116 116 116 58 58 58
56491 - 2 2 6 22 22 22 90 90 90 46 46 46
56492 - 18 18 18 6 6 6 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 0 0 0 0 0 0 0 0 0
56497 - 0 0 0 0 0 0 0 0 0 0 0 0
56498 - 0 0 0 0 0 0 0 0 0 0 0 0
56499 - 0 0 0 0 0 0 0 0 0 0 0 0
56500 - 0 0 0 0 0 0 0 0 0 0 0 0
56501 - 0 0 0 0 0 0 0 0 0 0 0 0
56502 - 0 0 0 0 0 0 0 0 0 0 0 0
56503 - 0 0 0 0 0 0 0 0 0 0 0 0
56504 - 0 0 0 0 0 0 0 0 0 10 10 10
56505 - 38 38 38 86 86 86 50 50 50 6 6 6
56506 -128 128 128 174 154 114 156 107 11 168 122 10
56507 -198 155 10 184 144 12 197 138 11 200 144 11
56508 -206 145 10 206 145 10 197 138 11 188 164 115
56509 -195 195 195 198 198 198 174 174 174 14 14 14
56510 - 2 2 6 22 22 22 116 116 116 116 116 116
56511 - 22 22 22 2 2 6 74 74 74 70 70 70
56512 - 30 30 30 10 10 10 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 0 0 0 0 0 0 0 0 0 0 0 0
56517 - 0 0 0 0 0 0 0 0 0 0 0 0
56518 - 0 0 0 0 0 0 0 0 0 0 0 0
56519 - 0 0 0 0 0 0 0 0 0 0 0 0
56520 - 0 0 0 0 0 0 0 0 0 0 0 0
56521 - 0 0 0 0 0 0 0 0 0 0 0 0
56522 - 0 0 0 0 0 0 0 0 0 0 0 0
56523 - 0 0 0 0 0 0 0 0 0 0 0 0
56524 - 0 0 0 0 0 0 6 6 6 18 18 18
56525 - 50 50 50 101 101 101 26 26 26 10 10 10
56526 -138 138 138 190 190 190 174 154 114 156 107 11
56527 -197 138 11 200 144 11 197 138 11 192 133 9
56528 -180 123 7 190 142 34 190 178 144 187 187 187
56529 -202 202 202 221 221 221 214 214 214 66 66 66
56530 - 2 2 6 2 2 6 50 50 50 62 62 62
56531 - 6 6 6 2 2 6 10 10 10 90 90 90
56532 - 50 50 50 18 18 18 6 6 6 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 0 0 0
56536 - 0 0 0 0 0 0 0 0 0 0 0 0
56537 - 0 0 0 0 0 0 0 0 0 0 0 0
56538 - 0 0 0 0 0 0 0 0 0 0 0 0
56539 - 0 0 0 0 0 0 0 0 0 0 0 0
56540 - 0 0 0 0 0 0 0 0 0 0 0 0
56541 - 0 0 0 0 0 0 0 0 0 0 0 0
56542 - 0 0 0 0 0 0 0 0 0 0 0 0
56543 - 0 0 0 0 0 0 0 0 0 0 0 0
56544 - 0 0 0 0 0 0 10 10 10 34 34 34
56545 - 74 74 74 74 74 74 2 2 6 6 6 6
56546 -144 144 144 198 198 198 190 190 190 178 166 146
56547 -154 121 60 156 107 11 156 107 11 168 124 44
56548 -174 154 114 187 187 187 190 190 190 210 210 210
56549 -246 246 246 253 253 253 253 253 253 182 182 182
56550 - 6 6 6 2 2 6 2 2 6 2 2 6
56551 - 2 2 6 2 2 6 2 2 6 62 62 62
56552 - 74 74 74 34 34 34 14 14 14 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 0 0 0 0 0 0
56556 - 0 0 0 0 0 0 0 0 0 0 0 0
56557 - 0 0 0 0 0 0 0 0 0 0 0 0
56558 - 0 0 0 0 0 0 0 0 0 0 0 0
56559 - 0 0 0 0 0 0 0 0 0 0 0 0
56560 - 0 0 0 0 0 0 0 0 0 0 0 0
56561 - 0 0 0 0 0 0 0 0 0 0 0 0
56562 - 0 0 0 0 0 0 0 0 0 0 0 0
56563 - 0 0 0 0 0 0 0 0 0 0 0 0
56564 - 0 0 0 10 10 10 22 22 22 54 54 54
56565 - 94 94 94 18 18 18 2 2 6 46 46 46
56566 -234 234 234 221 221 221 190 190 190 190 190 190
56567 -190 190 190 187 187 187 187 187 187 190 190 190
56568 -190 190 190 195 195 195 214 214 214 242 242 242
56569 -253 253 253 253 253 253 253 253 253 253 253 253
56570 - 82 82 82 2 2 6 2 2 6 2 2 6
56571 - 2 2 6 2 2 6 2 2 6 14 14 14
56572 - 86 86 86 54 54 54 22 22 22 6 6 6
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 0 0 0 0 0 0 0 0 0
56576 - 0 0 0 0 0 0 0 0 0 0 0 0
56577 - 0 0 0 0 0 0 0 0 0 0 0 0
56578 - 0 0 0 0 0 0 0 0 0 0 0 0
56579 - 0 0 0 0 0 0 0 0 0 0 0 0
56580 - 0 0 0 0 0 0 0 0 0 0 0 0
56581 - 0 0 0 0 0 0 0 0 0 0 0 0
56582 - 0 0 0 0 0 0 0 0 0 0 0 0
56583 - 0 0 0 0 0 0 0 0 0 0 0 0
56584 - 6 6 6 18 18 18 46 46 46 90 90 90
56585 - 46 46 46 18 18 18 6 6 6 182 182 182
56586 -253 253 253 246 246 246 206 206 206 190 190 190
56587 -190 190 190 190 190 190 190 190 190 190 190 190
56588 -206 206 206 231 231 231 250 250 250 253 253 253
56589 -253 253 253 253 253 253 253 253 253 253 253 253
56590 -202 202 202 14 14 14 2 2 6 2 2 6
56591 - 2 2 6 2 2 6 2 2 6 2 2 6
56592 - 42 42 42 86 86 86 42 42 42 18 18 18
56593 - 6 6 6 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 0 0 0 0 0 0 0 0 0 0 0 0
56596 - 0 0 0 0 0 0 0 0 0 0 0 0
56597 - 0 0 0 0 0 0 0 0 0 0 0 0
56598 - 0 0 0 0 0 0 0 0 0 0 0 0
56599 - 0 0 0 0 0 0 0 0 0 0 0 0
56600 - 0 0 0 0 0 0 0 0 0 0 0 0
56601 - 0 0 0 0 0 0 0 0 0 0 0 0
56602 - 0 0 0 0 0 0 0 0 0 0 0 0
56603 - 0 0 0 0 0 0 0 0 0 6 6 6
56604 - 14 14 14 38 38 38 74 74 74 66 66 66
56605 - 2 2 6 6 6 6 90 90 90 250 250 250
56606 -253 253 253 253 253 253 238 238 238 198 198 198
56607 -190 190 190 190 190 190 195 195 195 221 221 221
56608 -246 246 246 253 253 253 253 253 253 253 253 253
56609 -253 253 253 253 253 253 253 253 253 253 253 253
56610 -253 253 253 82 82 82 2 2 6 2 2 6
56611 - 2 2 6 2 2 6 2 2 6 2 2 6
56612 - 2 2 6 78 78 78 70 70 70 34 34 34
56613 - 14 14 14 6 6 6 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 0 0 0 0 0 0 0 0 0 0 0 0
56616 - 0 0 0 0 0 0 0 0 0 0 0 0
56617 - 0 0 0 0 0 0 0 0 0 0 0 0
56618 - 0 0 0 0 0 0 0 0 0 0 0 0
56619 - 0 0 0 0 0 0 0 0 0 0 0 0
56620 - 0 0 0 0 0 0 0 0 0 0 0 0
56621 - 0 0 0 0 0 0 0 0 0 0 0 0
56622 - 0 0 0 0 0 0 0 0 0 0 0 0
56623 - 0 0 0 0 0 0 0 0 0 14 14 14
56624 - 34 34 34 66 66 66 78 78 78 6 6 6
56625 - 2 2 6 18 18 18 218 218 218 253 253 253
56626 -253 253 253 253 253 253 253 253 253 246 246 246
56627 -226 226 226 231 231 231 246 246 246 253 253 253
56628 -253 253 253 253 253 253 253 253 253 253 253 253
56629 -253 253 253 253 253 253 253 253 253 253 253 253
56630 -253 253 253 178 178 178 2 2 6 2 2 6
56631 - 2 2 6 2 2 6 2 2 6 2 2 6
56632 - 2 2 6 18 18 18 90 90 90 62 62 62
56633 - 30 30 30 10 10 10 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 0 0 0 0 0 0 0 0 0 0 0 0
56636 - 0 0 0 0 0 0 0 0 0 0 0 0
56637 - 0 0 0 0 0 0 0 0 0 0 0 0
56638 - 0 0 0 0 0 0 0 0 0 0 0 0
56639 - 0 0 0 0 0 0 0 0 0 0 0 0
56640 - 0 0 0 0 0 0 0 0 0 0 0 0
56641 - 0 0 0 0 0 0 0 0 0 0 0 0
56642 - 0 0 0 0 0 0 0 0 0 0 0 0
56643 - 0 0 0 0 0 0 10 10 10 26 26 26
56644 - 58 58 58 90 90 90 18 18 18 2 2 6
56645 - 2 2 6 110 110 110 253 253 253 253 253 253
56646 -253 253 253 253 253 253 253 253 253 253 253 253
56647 -250 250 250 253 253 253 253 253 253 253 253 253
56648 -253 253 253 253 253 253 253 253 253 253 253 253
56649 -253 253 253 253 253 253 253 253 253 253 253 253
56650 -253 253 253 231 231 231 18 18 18 2 2 6
56651 - 2 2 6 2 2 6 2 2 6 2 2 6
56652 - 2 2 6 2 2 6 18 18 18 94 94 94
56653 - 54 54 54 26 26 26 10 10 10 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 0 0 0
56655 - 0 0 0 0 0 0 0 0 0 0 0 0
56656 - 0 0 0 0 0 0 0 0 0 0 0 0
56657 - 0 0 0 0 0 0 0 0 0 0 0 0
56658 - 0 0 0 0 0 0 0 0 0 0 0 0
56659 - 0 0 0 0 0 0 0 0 0 0 0 0
56660 - 0 0 0 0 0 0 0 0 0 0 0 0
56661 - 0 0 0 0 0 0 0 0 0 0 0 0
56662 - 0 0 0 0 0 0 0 0 0 0 0 0
56663 - 0 0 0 6 6 6 22 22 22 50 50 50
56664 - 90 90 90 26 26 26 2 2 6 2 2 6
56665 - 14 14 14 195 195 195 250 250 250 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 253 253 253 253 253 253
56669 -253 253 253 253 253 253 253 253 253 253 253 253
56670 -250 250 250 242 242 242 54 54 54 2 2 6
56671 - 2 2 6 2 2 6 2 2 6 2 2 6
56672 - 2 2 6 2 2 6 2 2 6 38 38 38
56673 - 86 86 86 50 50 50 22 22 22 6 6 6
56674 - 0 0 0 0 0 0 0 0 0 0 0 0
56675 - 0 0 0 0 0 0 0 0 0 0 0 0
56676 - 0 0 0 0 0 0 0 0 0 0 0 0
56677 - 0 0 0 0 0 0 0 0 0 0 0 0
56678 - 0 0 0 0 0 0 0 0 0 0 0 0
56679 - 0 0 0 0 0 0 0 0 0 0 0 0
56680 - 0 0 0 0 0 0 0 0 0 0 0 0
56681 - 0 0 0 0 0 0 0 0 0 0 0 0
56682 - 0 0 0 0 0 0 0 0 0 0 0 0
56683 - 6 6 6 14 14 14 38 38 38 82 82 82
56684 - 34 34 34 2 2 6 2 2 6 2 2 6
56685 - 42 42 42 195 195 195 246 246 246 253 253 253
56686 -253 253 253 253 253 253 253 253 253 250 250 250
56687 -242 242 242 242 242 242 250 250 250 253 253 253
56688 -253 253 253 253 253 253 253 253 253 253 253 253
56689 -253 253 253 250 250 250 246 246 246 238 238 238
56690 -226 226 226 231 231 231 101 101 101 6 6 6
56691 - 2 2 6 2 2 6 2 2 6 2 2 6
56692 - 2 2 6 2 2 6 2 2 6 2 2 6
56693 - 38 38 38 82 82 82 42 42 42 14 14 14
56694 - 6 6 6 0 0 0 0 0 0 0 0 0
56695 - 0 0 0 0 0 0 0 0 0 0 0 0
56696 - 0 0 0 0 0 0 0 0 0 0 0 0
56697 - 0 0 0 0 0 0 0 0 0 0 0 0
56698 - 0 0 0 0 0 0 0 0 0 0 0 0
56699 - 0 0 0 0 0 0 0 0 0 0 0 0
56700 - 0 0 0 0 0 0 0 0 0 0 0 0
56701 - 0 0 0 0 0 0 0 0 0 0 0 0
56702 - 0 0 0 0 0 0 0 0 0 0 0 0
56703 - 10 10 10 26 26 26 62 62 62 66 66 66
56704 - 2 2 6 2 2 6 2 2 6 6 6 6
56705 - 70 70 70 170 170 170 206 206 206 234 234 234
56706 -246 246 246 250 250 250 250 250 250 238 238 238
56707 -226 226 226 231 231 231 238 238 238 250 250 250
56708 -250 250 250 250 250 250 246 246 246 231 231 231
56709 -214 214 214 206 206 206 202 202 202 202 202 202
56710 -198 198 198 202 202 202 182 182 182 18 18 18
56711 - 2 2 6 2 2 6 2 2 6 2 2 6
56712 - 2 2 6 2 2 6 2 2 6 2 2 6
56713 - 2 2 6 62 62 62 66 66 66 30 30 30
56714 - 10 10 10 0 0 0 0 0 0 0 0 0
56715 - 0 0 0 0 0 0 0 0 0 0 0 0
56716 - 0 0 0 0 0 0 0 0 0 0 0 0
56717 - 0 0 0 0 0 0 0 0 0 0 0 0
56718 - 0 0 0 0 0 0 0 0 0 0 0 0
56719 - 0 0 0 0 0 0 0 0 0 0 0 0
56720 - 0 0 0 0 0 0 0 0 0 0 0 0
56721 - 0 0 0 0 0 0 0 0 0 0 0 0
56722 - 0 0 0 0 0 0 0 0 0 0 0 0
56723 - 14 14 14 42 42 42 82 82 82 18 18 18
56724 - 2 2 6 2 2 6 2 2 6 10 10 10
56725 - 94 94 94 182 182 182 218 218 218 242 242 242
56726 -250 250 250 253 253 253 253 253 253 250 250 250
56727 -234 234 234 253 253 253 253 253 253 253 253 253
56728 -253 253 253 253 253 253 253 253 253 246 246 246
56729 -238 238 238 226 226 226 210 210 210 202 202 202
56730 -195 195 195 195 195 195 210 210 210 158 158 158
56731 - 6 6 6 14 14 14 50 50 50 14 14 14
56732 - 2 2 6 2 2 6 2 2 6 2 2 6
56733 - 2 2 6 6 6 6 86 86 86 46 46 46
56734 - 18 18 18 6 6 6 0 0 0 0 0 0
56735 - 0 0 0 0 0 0 0 0 0 0 0 0
56736 - 0 0 0 0 0 0 0 0 0 0 0 0
56737 - 0 0 0 0 0 0 0 0 0 0 0 0
56738 - 0 0 0 0 0 0 0 0 0 0 0 0
56739 - 0 0 0 0 0 0 0 0 0 0 0 0
56740 - 0 0 0 0 0 0 0 0 0 0 0 0
56741 - 0 0 0 0 0 0 0 0 0 0 0 0
56742 - 0 0 0 0 0 0 0 0 0 6 6 6
56743 - 22 22 22 54 54 54 70 70 70 2 2 6
56744 - 2 2 6 10 10 10 2 2 6 22 22 22
56745 -166 166 166 231 231 231 250 250 250 253 253 253
56746 -253 253 253 253 253 253 253 253 253 250 250 250
56747 -242 242 242 253 253 253 253 253 253 253 253 253
56748 -253 253 253 253 253 253 253 253 253 253 253 253
56749 -253 253 253 253 253 253 253 253 253 246 246 246
56750 -231 231 231 206 206 206 198 198 198 226 226 226
56751 - 94 94 94 2 2 6 6 6 6 38 38 38
56752 - 30 30 30 2 2 6 2 2 6 2 2 6
56753 - 2 2 6 2 2 6 62 62 62 66 66 66
56754 - 26 26 26 10 10 10 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 0 0 0 0 0 0
56757 - 0 0 0 0 0 0 0 0 0 0 0 0
56758 - 0 0 0 0 0 0 0 0 0 0 0 0
56759 - 0 0 0 0 0 0 0 0 0 0 0 0
56760 - 0 0 0 0 0 0 0 0 0 0 0 0
56761 - 0 0 0 0 0 0 0 0 0 0 0 0
56762 - 0 0 0 0 0 0 0 0 0 10 10 10
56763 - 30 30 30 74 74 74 50 50 50 2 2 6
56764 - 26 26 26 26 26 26 2 2 6 106 106 106
56765 -238 238 238 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 253 253 253
56768 -253 253 253 253 253 253 253 253 253 253 253 253
56769 -253 253 253 253 253 253 253 253 253 253 253 253
56770 -253 253 253 246 246 246 218 218 218 202 202 202
56771 -210 210 210 14 14 14 2 2 6 2 2 6
56772 - 30 30 30 22 22 22 2 2 6 2 2 6
56773 - 2 2 6 2 2 6 18 18 18 86 86 86
56774 - 42 42 42 14 14 14 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 0 0 0 0 0 0 0 0 0
56777 - 0 0 0 0 0 0 0 0 0 0 0 0
56778 - 0 0 0 0 0 0 0 0 0 0 0 0
56779 - 0 0 0 0 0 0 0 0 0 0 0 0
56780 - 0 0 0 0 0 0 0 0 0 0 0 0
56781 - 0 0 0 0 0 0 0 0 0 0 0 0
56782 - 0 0 0 0 0 0 0 0 0 14 14 14
56783 - 42 42 42 90 90 90 22 22 22 2 2 6
56784 - 42 42 42 2 2 6 18 18 18 218 218 218
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 253 253 253
56788 -253 253 253 253 253 253 253 253 253 253 253 253
56789 -253 253 253 253 253 253 253 253 253 253 253 253
56790 -253 253 253 253 253 253 250 250 250 221 221 221
56791 -218 218 218 101 101 101 2 2 6 14 14 14
56792 - 18 18 18 38 38 38 10 10 10 2 2 6
56793 - 2 2 6 2 2 6 2 2 6 78 78 78
56794 - 58 58 58 22 22 22 6 6 6 0 0 0
56795 - 0 0 0 0 0 0 0 0 0 0 0 0
56796 - 0 0 0 0 0 0 0 0 0 0 0 0
56797 - 0 0 0 0 0 0 0 0 0 0 0 0
56798 - 0 0 0 0 0 0 0 0 0 0 0 0
56799 - 0 0 0 0 0 0 0 0 0 0 0 0
56800 - 0 0 0 0 0 0 0 0 0 0 0 0
56801 - 0 0 0 0 0 0 0 0 0 0 0 0
56802 - 0 0 0 0 0 0 6 6 6 18 18 18
56803 - 54 54 54 82 82 82 2 2 6 26 26 26
56804 - 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253 253 253 253
56808 -253 253 253 253 253 253 253 253 253 253 253 253
56809 -253 253 253 253 253 253 253 253 253 253 253 253
56810 -253 253 253 253 253 253 253 253 253 250 250 250
56811 -238 238 238 198 198 198 6 6 6 38 38 38
56812 - 58 58 58 26 26 26 38 38 38 2 2 6
56813 - 2 2 6 2 2 6 2 2 6 46 46 46
56814 - 78 78 78 30 30 30 10 10 10 0 0 0
56815 - 0 0 0 0 0 0 0 0 0 0 0 0
56816 - 0 0 0 0 0 0 0 0 0 0 0 0
56817 - 0 0 0 0 0 0 0 0 0 0 0 0
56818 - 0 0 0 0 0 0 0 0 0 0 0 0
56819 - 0 0 0 0 0 0 0 0 0 0 0 0
56820 - 0 0 0 0 0 0 0 0 0 0 0 0
56821 - 0 0 0 0 0 0 0 0 0 0 0 0
56822 - 0 0 0 0 0 0 10 10 10 30 30 30
56823 - 74 74 74 58 58 58 2 2 6 42 42 42
56824 - 2 2 6 22 22 22 231 231 231 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 250 250 250
56827 -253 253 253 253 253 253 253 253 253 253 253 253
56828 -253 253 253 253 253 253 253 253 253 253 253 253
56829 -253 253 253 253 253 253 253 253 253 253 253 253
56830 -253 253 253 253 253 253 253 253 253 253 253 253
56831 -253 253 253 246 246 246 46 46 46 38 38 38
56832 - 42 42 42 14 14 14 38 38 38 14 14 14
56833 - 2 2 6 2 2 6 2 2 6 6 6 6
56834 - 86 86 86 46 46 46 14 14 14 0 0 0
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 0 0 0 0 0 0 0 0 0 0 0 0
56837 - 0 0 0 0 0 0 0 0 0 0 0 0
56838 - 0 0 0 0 0 0 0 0 0 0 0 0
56839 - 0 0 0 0 0 0 0 0 0 0 0 0
56840 - 0 0 0 0 0 0 0 0 0 0 0 0
56841 - 0 0 0 0 0 0 0 0 0 0 0 0
56842 - 0 0 0 6 6 6 14 14 14 42 42 42
56843 - 90 90 90 18 18 18 18 18 18 26 26 26
56844 - 2 2 6 116 116 116 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 250 250 250 238 238 238
56847 -253 253 253 253 253 253 253 253 253 253 253 253
56848 -253 253 253 253 253 253 253 253 253 253 253 253
56849 -253 253 253 253 253 253 253 253 253 253 253 253
56850 -253 253 253 253 253 253 253 253 253 253 253 253
56851 -253 253 253 253 253 253 94 94 94 6 6 6
56852 - 2 2 6 2 2 6 10 10 10 34 34 34
56853 - 2 2 6 2 2 6 2 2 6 2 2 6
56854 - 74 74 74 58 58 58 22 22 22 6 6 6
56855 - 0 0 0 0 0 0 0 0 0 0 0 0
56856 - 0 0 0 0 0 0 0 0 0 0 0 0
56857 - 0 0 0 0 0 0 0 0 0 0 0 0
56858 - 0 0 0 0 0 0 0 0 0 0 0 0
56859 - 0 0 0 0 0 0 0 0 0 0 0 0
56860 - 0 0 0 0 0 0 0 0 0 0 0 0
56861 - 0 0 0 0 0 0 0 0 0 0 0 0
56862 - 0 0 0 10 10 10 26 26 26 66 66 66
56863 - 82 82 82 2 2 6 38 38 38 6 6 6
56864 - 14 14 14 210 210 210 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 246 246 246 242 242 242
56867 -253 253 253 253 253 253 253 253 253 253 253 253
56868 -253 253 253 253 253 253 253 253 253 253 253 253
56869 -253 253 253 253 253 253 253 253 253 253 253 253
56870 -253 253 253 253 253 253 253 253 253 253 253 253
56871 -253 253 253 253 253 253 144 144 144 2 2 6
56872 - 2 2 6 2 2 6 2 2 6 46 46 46
56873 - 2 2 6 2 2 6 2 2 6 2 2 6
56874 - 42 42 42 74 74 74 30 30 30 10 10 10
56875 - 0 0 0 0 0 0 0 0 0 0 0 0
56876 - 0 0 0 0 0 0 0 0 0 0 0 0
56877 - 0 0 0 0 0 0 0 0 0 0 0 0
56878 - 0 0 0 0 0 0 0 0 0 0 0 0
56879 - 0 0 0 0 0 0 0 0 0 0 0 0
56880 - 0 0 0 0 0 0 0 0 0 0 0 0
56881 - 0 0 0 0 0 0 0 0 0 0 0 0
56882 - 6 6 6 14 14 14 42 42 42 90 90 90
56883 - 26 26 26 6 6 6 42 42 42 2 2 6
56884 - 74 74 74 250 250 250 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 242 242 242 242 242 242
56887 -253 253 253 253 253 253 253 253 253 253 253 253
56888 -253 253 253 253 253 253 253 253 253 253 253 253
56889 -253 253 253 253 253 253 253 253 253 253 253 253
56890 -253 253 253 253 253 253 253 253 253 253 253 253
56891 -253 253 253 253 253 253 182 182 182 2 2 6
56892 - 2 2 6 2 2 6 2 2 6 46 46 46
56893 - 2 2 6 2 2 6 2 2 6 2 2 6
56894 - 10 10 10 86 86 86 38 38 38 10 10 10
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 0 0 0 0 0 0 0 0 0 0
56897 - 0 0 0 0 0 0 0 0 0 0 0 0
56898 - 0 0 0 0 0 0 0 0 0 0 0 0
56899 - 0 0 0 0 0 0 0 0 0 0 0 0
56900 - 0 0 0 0 0 0 0 0 0 0 0 0
56901 - 0 0 0 0 0 0 0 0 0 0 0 0
56902 - 10 10 10 26 26 26 66 66 66 82 82 82
56903 - 2 2 6 22 22 22 18 18 18 2 2 6
56904 -149 149 149 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 234 234 234 242 242 242
56907 -253 253 253 253 253 253 253 253 253 253 253 253
56908 -253 253 253 253 253 253 253 253 253 253 253 253
56909 -253 253 253 253 253 253 253 253 253 253 253 253
56910 -253 253 253 253 253 253 253 253 253 253 253 253
56911 -253 253 253 253 253 253 206 206 206 2 2 6
56912 - 2 2 6 2 2 6 2 2 6 38 38 38
56913 - 2 2 6 2 2 6 2 2 6 2 2 6
56914 - 6 6 6 86 86 86 46 46 46 14 14 14
56915 - 0 0 0 0 0 0 0 0 0 0 0 0
56916 - 0 0 0 0 0 0 0 0 0 0 0 0
56917 - 0 0 0 0 0 0 0 0 0 0 0 0
56918 - 0 0 0 0 0 0 0 0 0 0 0 0
56919 - 0 0 0 0 0 0 0 0 0 0 0 0
56920 - 0 0 0 0 0 0 0 0 0 0 0 0
56921 - 0 0 0 0 0 0 0 0 0 6 6 6
56922 - 18 18 18 46 46 46 86 86 86 18 18 18
56923 - 2 2 6 34 34 34 10 10 10 6 6 6
56924 -210 210 210 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 234 234 234 242 242 242
56927 -253 253 253 253 253 253 253 253 253 253 253 253
56928 -253 253 253 253 253 253 253 253 253 253 253 253
56929 -253 253 253 253 253 253 253 253 253 253 253 253
56930 -253 253 253 253 253 253 253 253 253 253 253 253
56931 -253 253 253 253 253 253 221 221 221 6 6 6
56932 - 2 2 6 2 2 6 6 6 6 30 30 30
56933 - 2 2 6 2 2 6 2 2 6 2 2 6
56934 - 2 2 6 82 82 82 54 54 54 18 18 18
56935 - 6 6 6 0 0 0 0 0 0 0 0 0
56936 - 0 0 0 0 0 0 0 0 0 0 0 0
56937 - 0 0 0 0 0 0 0 0 0 0 0 0
56938 - 0 0 0 0 0 0 0 0 0 0 0 0
56939 - 0 0 0 0 0 0 0 0 0 0 0 0
56940 - 0 0 0 0 0 0 0 0 0 0 0 0
56941 - 0 0 0 0 0 0 0 0 0 10 10 10
56942 - 26 26 26 66 66 66 62 62 62 2 2 6
56943 - 2 2 6 38 38 38 10 10 10 26 26 26
56944 -238 238 238 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 231 231 231 238 238 238
56947 -253 253 253 253 253 253 253 253 253 253 253 253
56948 -253 253 253 253 253 253 253 253 253 253 253 253
56949 -253 253 253 253 253 253 253 253 253 253 253 253
56950 -253 253 253 253 253 253 253 253 253 253 253 253
56951 -253 253 253 253 253 253 231 231 231 6 6 6
56952 - 2 2 6 2 2 6 10 10 10 30 30 30
56953 - 2 2 6 2 2 6 2 2 6 2 2 6
56954 - 2 2 6 66 66 66 58 58 58 22 22 22
56955 - 6 6 6 0 0 0 0 0 0 0 0 0
56956 - 0 0 0 0 0 0 0 0 0 0 0 0
56957 - 0 0 0 0 0 0 0 0 0 0 0 0
56958 - 0 0 0 0 0 0 0 0 0 0 0 0
56959 - 0 0 0 0 0 0 0 0 0 0 0 0
56960 - 0 0 0 0 0 0 0 0 0 0 0 0
56961 - 0 0 0 0 0 0 0 0 0 10 10 10
56962 - 38 38 38 78 78 78 6 6 6 2 2 6
56963 - 2 2 6 46 46 46 14 14 14 42 42 42
56964 -246 246 246 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 231 231 231 242 242 242
56967 -253 253 253 253 253 253 253 253 253 253 253 253
56968 -253 253 253 253 253 253 253 253 253 253 253 253
56969 -253 253 253 253 253 253 253 253 253 253 253 253
56970 -253 253 253 253 253 253 253 253 253 253 253 253
56971 -253 253 253 253 253 253 234 234 234 10 10 10
56972 - 2 2 6 2 2 6 22 22 22 14 14 14
56973 - 2 2 6 2 2 6 2 2 6 2 2 6
56974 - 2 2 6 66 66 66 62 62 62 22 22 22
56975 - 6 6 6 0 0 0 0 0 0 0 0 0
56976 - 0 0 0 0 0 0 0 0 0 0 0 0
56977 - 0 0 0 0 0 0 0 0 0 0 0 0
56978 - 0 0 0 0 0 0 0 0 0 0 0 0
56979 - 0 0 0 0 0 0 0 0 0 0 0 0
56980 - 0 0 0 0 0 0 0 0 0 0 0 0
56981 - 0 0 0 0 0 0 6 6 6 18 18 18
56982 - 50 50 50 74 74 74 2 2 6 2 2 6
56983 - 14 14 14 70 70 70 34 34 34 62 62 62
56984 -250 250 250 253 253 253 253 253 253 253 253 253
56985 -253 253 253 253 253 253 253 253 253 253 253 253
56986 -253 253 253 253 253 253 231 231 231 246 246 246
56987 -253 253 253 253 253 253 253 253 253 253 253 253
56988 -253 253 253 253 253 253 253 253 253 253 253 253
56989 -253 253 253 253 253 253 253 253 253 253 253 253
56990 -253 253 253 253 253 253 253 253 253 253 253 253
56991 -253 253 253 253 253 253 234 234 234 14 14 14
56992 - 2 2 6 2 2 6 30 30 30 2 2 6
56993 - 2 2 6 2 2 6 2 2 6 2 2 6
56994 - 2 2 6 66 66 66 62 62 62 22 22 22
56995 - 6 6 6 0 0 0 0 0 0 0 0 0
56996 - 0 0 0 0 0 0 0 0 0 0 0 0
56997 - 0 0 0 0 0 0 0 0 0 0 0 0
56998 - 0 0 0 0 0 0 0 0 0 0 0 0
56999 - 0 0 0 0 0 0 0 0 0 0 0 0
57000 - 0 0 0 0 0 0 0 0 0 0 0 0
57001 - 0 0 0 0 0 0 6 6 6 18 18 18
57002 - 54 54 54 62 62 62 2 2 6 2 2 6
57003 - 2 2 6 30 30 30 46 46 46 70 70 70
57004 -250 250 250 253 253 253 253 253 253 253 253 253
57005 -253 253 253 253 253 253 253 253 253 253 253 253
57006 -253 253 253 253 253 253 231 231 231 246 246 246
57007 -253 253 253 253 253 253 253 253 253 253 253 253
57008 -253 253 253 253 253 253 253 253 253 253 253 253
57009 -253 253 253 253 253 253 253 253 253 253 253 253
57010 -253 253 253 253 253 253 253 253 253 253 253 253
57011 -253 253 253 253 253 253 226 226 226 10 10 10
57012 - 2 2 6 6 6 6 30 30 30 2 2 6
57013 - 2 2 6 2 2 6 2 2 6 2 2 6
57014 - 2 2 6 66 66 66 58 58 58 22 22 22
57015 - 6 6 6 0 0 0 0 0 0 0 0 0
57016 - 0 0 0 0 0 0 0 0 0 0 0 0
57017 - 0 0 0 0 0 0 0 0 0 0 0 0
57018 - 0 0 0 0 0 0 0 0 0 0 0 0
57019 - 0 0 0 0 0 0 0 0 0 0 0 0
57020 - 0 0 0 0 0 0 0 0 0 0 0 0
57021 - 0 0 0 0 0 0 6 6 6 22 22 22
57022 - 58 58 58 62 62 62 2 2 6 2 2 6
57023 - 2 2 6 2 2 6 30 30 30 78 78 78
57024 -250 250 250 253 253 253 253 253 253 253 253 253
57025 -253 253 253 253 253 253 253 253 253 253 253 253
57026 -253 253 253 253 253 253 231 231 231 246 246 246
57027 -253 253 253 253 253 253 253 253 253 253 253 253
57028 -253 253 253 253 253 253 253 253 253 253 253 253
57029 -253 253 253 253 253 253 253 253 253 253 253 253
57030 -253 253 253 253 253 253 253 253 253 253 253 253
57031 -253 253 253 253 253 253 206 206 206 2 2 6
57032 - 22 22 22 34 34 34 18 14 6 22 22 22
57033 - 26 26 26 18 18 18 6 6 6 2 2 6
57034 - 2 2 6 82 82 82 54 54 54 18 18 18
57035 - 6 6 6 0 0 0 0 0 0 0 0 0
57036 - 0 0 0 0 0 0 0 0 0 0 0 0
57037 - 0 0 0 0 0 0 0 0 0 0 0 0
57038 - 0 0 0 0 0 0 0 0 0 0 0 0
57039 - 0 0 0 0 0 0 0 0 0 0 0 0
57040 - 0 0 0 0 0 0 0 0 0 0 0 0
57041 - 0 0 0 0 0 0 6 6 6 26 26 26
57042 - 62 62 62 106 106 106 74 54 14 185 133 11
57043 -210 162 10 121 92 8 6 6 6 62 62 62
57044 -238 238 238 253 253 253 253 253 253 253 253 253
57045 -253 253 253 253 253 253 253 253 253 253 253 253
57046 -253 253 253 253 253 253 231 231 231 246 246 246
57047 -253 253 253 253 253 253 253 253 253 253 253 253
57048 -253 253 253 253 253 253 253 253 253 253 253 253
57049 -253 253 253 253 253 253 253 253 253 253 253 253
57050 -253 253 253 253 253 253 253 253 253 253 253 253
57051 -253 253 253 253 253 253 158 158 158 18 18 18
57052 - 14 14 14 2 2 6 2 2 6 2 2 6
57053 - 6 6 6 18 18 18 66 66 66 38 38 38
57054 - 6 6 6 94 94 94 50 50 50 18 18 18
57055 - 6 6 6 0 0 0 0 0 0 0 0 0
57056 - 0 0 0 0 0 0 0 0 0 0 0 0
57057 - 0 0 0 0 0 0 0 0 0 0 0 0
57058 - 0 0 0 0 0 0 0 0 0 0 0 0
57059 - 0 0 0 0 0 0 0 0 0 0 0 0
57060 - 0 0 0 0 0 0 0 0 0 6 6 6
57061 - 10 10 10 10 10 10 18 18 18 38 38 38
57062 - 78 78 78 142 134 106 216 158 10 242 186 14
57063 -246 190 14 246 190 14 156 118 10 10 10 10
57064 - 90 90 90 238 238 238 253 253 253 253 253 253
57065 -253 253 253 253 253 253 253 253 253 253 253 253
57066 -253 253 253 253 253 253 231 231 231 250 250 250
57067 -253 253 253 253 253 253 253 253 253 253 253 253
57068 -253 253 253 253 253 253 253 253 253 253 253 253
57069 -253 253 253 253 253 253 253 253 253 253 253 253
57070 -253 253 253 253 253 253 253 253 253 246 230 190
57071 -238 204 91 238 204 91 181 142 44 37 26 9
57072 - 2 2 6 2 2 6 2 2 6 2 2 6
57073 - 2 2 6 2 2 6 38 38 38 46 46 46
57074 - 26 26 26 106 106 106 54 54 54 18 18 18
57075 - 6 6 6 0 0 0 0 0 0 0 0 0
57076 - 0 0 0 0 0 0 0 0 0 0 0 0
57077 - 0 0 0 0 0 0 0 0 0 0 0 0
57078 - 0 0 0 0 0 0 0 0 0 0 0 0
57079 - 0 0 0 0 0 0 0 0 0 0 0 0
57080 - 0 0 0 6 6 6 14 14 14 22 22 22
57081 - 30 30 30 38 38 38 50 50 50 70 70 70
57082 -106 106 106 190 142 34 226 170 11 242 186 14
57083 -246 190 14 246 190 14 246 190 14 154 114 10
57084 - 6 6 6 74 74 74 226 226 226 253 253 253
57085 -253 253 253 253 253 253 253 253 253 253 253 253
57086 -253 253 253 253 253 253 231 231 231 250 250 250
57087 -253 253 253 253 253 253 253 253 253 253 253 253
57088 -253 253 253 253 253 253 253 253 253 253 253 253
57089 -253 253 253 253 253 253 253 253 253 253 253 253
57090 -253 253 253 253 253 253 253 253 253 228 184 62
57091 -241 196 14 241 208 19 232 195 16 38 30 10
57092 - 2 2 6 2 2 6 2 2 6 2 2 6
57093 - 2 2 6 6 6 6 30 30 30 26 26 26
57094 -203 166 17 154 142 90 66 66 66 26 26 26
57095 - 6 6 6 0 0 0 0 0 0 0 0 0
57096 - 0 0 0 0 0 0 0 0 0 0 0 0
57097 - 0 0 0 0 0 0 0 0 0 0 0 0
57098 - 0 0 0 0 0 0 0 0 0 0 0 0
57099 - 0 0 0 0 0 0 0 0 0 0 0 0
57100 - 6 6 6 18 18 18 38 38 38 58 58 58
57101 - 78 78 78 86 86 86 101 101 101 123 123 123
57102 -175 146 61 210 150 10 234 174 13 246 186 14
57103 -246 190 14 246 190 14 246 190 14 238 190 10
57104 -102 78 10 2 2 6 46 46 46 198 198 198
57105 -253 253 253 253 253 253 253 253 253 253 253 253
57106 -253 253 253 253 253 253 234 234 234 242 242 242
57107 -253 253 253 253 253 253 253 253 253 253 253 253
57108 -253 253 253 253 253 253 253 253 253 253 253 253
57109 -253 253 253 253 253 253 253 253 253 253 253 253
57110 -253 253 253 253 253 253 253 253 253 224 178 62
57111 -242 186 14 241 196 14 210 166 10 22 18 6
57112 - 2 2 6 2 2 6 2 2 6 2 2 6
57113 - 2 2 6 2 2 6 6 6 6 121 92 8
57114 -238 202 15 232 195 16 82 82 82 34 34 34
57115 - 10 10 10 0 0 0 0 0 0 0 0 0
57116 - 0 0 0 0 0 0 0 0 0 0 0 0
57117 - 0 0 0 0 0 0 0 0 0 0 0 0
57118 - 0 0 0 0 0 0 0 0 0 0 0 0
57119 - 0 0 0 0 0 0 0 0 0 0 0 0
57120 - 14 14 14 38 38 38 70 70 70 154 122 46
57121 -190 142 34 200 144 11 197 138 11 197 138 11
57122 -213 154 11 226 170 11 242 186 14 246 190 14
57123 -246 190 14 246 190 14 246 190 14 246 190 14
57124 -225 175 15 46 32 6 2 2 6 22 22 22
57125 -158 158 158 250 250 250 253 253 253 253 253 253
57126 -253 253 253 253 253 253 253 253 253 253 253 253
57127 -253 253 253 253 253 253 253 253 253 253 253 253
57128 -253 253 253 253 253 253 253 253 253 253 253 253
57129 -253 253 253 253 253 253 253 253 253 253 253 253
57130 -253 253 253 250 250 250 242 242 242 224 178 62
57131 -239 182 13 236 186 11 213 154 11 46 32 6
57132 - 2 2 6 2 2 6 2 2 6 2 2 6
57133 - 2 2 6 2 2 6 61 42 6 225 175 15
57134 -238 190 10 236 186 11 112 100 78 42 42 42
57135 - 14 14 14 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 0 0 0 0 0 0
57138 - 0 0 0 0 0 0 0 0 0 0 0 0
57139 - 0 0 0 0 0 0 0 0 0 6 6 6
57140 - 22 22 22 54 54 54 154 122 46 213 154 11
57141 -226 170 11 230 174 11 226 170 11 226 170 11
57142 -236 178 12 242 186 14 246 190 14 246 190 14
57143 -246 190 14 246 190 14 246 190 14 246 190 14
57144 -241 196 14 184 144 12 10 10 10 2 2 6
57145 - 6 6 6 116 116 116 242 242 242 253 253 253
57146 -253 253 253 253 253 253 253 253 253 253 253 253
57147 -253 253 253 253 253 253 253 253 253 253 253 253
57148 -253 253 253 253 253 253 253 253 253 253 253 253
57149 -253 253 253 253 253 253 253 253 253 253 253 253
57150 -253 253 253 231 231 231 198 198 198 214 170 54
57151 -236 178 12 236 178 12 210 150 10 137 92 6
57152 - 18 14 6 2 2 6 2 2 6 2 2 6
57153 - 6 6 6 70 47 6 200 144 11 236 178 12
57154 -239 182 13 239 182 13 124 112 88 58 58 58
57155 - 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0
57159 - 0 0 0 0 0 0 0 0 0 10 10 10
57160 - 30 30 30 70 70 70 180 133 36 226 170 11
57161 -239 182 13 242 186 14 242 186 14 246 186 14
57162 -246 190 14 246 190 14 246 190 14 246 190 14
57163 -246 190 14 246 190 14 246 190 14 246 190 14
57164 -246 190 14 232 195 16 98 70 6 2 2 6
57165 - 2 2 6 2 2 6 66 66 66 221 221 221
57166 -253 253 253 253 253 253 253 253 253 253 253 253
57167 -253 253 253 253 253 253 253 253 253 253 253 253
57168 -253 253 253 253 253 253 253 253 253 253 253 253
57169 -253 253 253 253 253 253 253 253 253 253 253 253
57170 -253 253 253 206 206 206 198 198 198 214 166 58
57171 -230 174 11 230 174 11 216 158 10 192 133 9
57172 -163 110 8 116 81 8 102 78 10 116 81 8
57173 -167 114 7 197 138 11 226 170 11 239 182 13
57174 -242 186 14 242 186 14 162 146 94 78 78 78
57175 - 34 34 34 14 14 14 6 6 6 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 0 0 0 0 0 0 6 6 6
57180 - 30 30 30 78 78 78 190 142 34 226 170 11
57181 -239 182 13 246 190 14 246 190 14 246 190 14
57182 -246 190 14 246 190 14 246 190 14 246 190 14
57183 -246 190 14 246 190 14 246 190 14 246 190 14
57184 -246 190 14 241 196 14 203 166 17 22 18 6
57185 - 2 2 6 2 2 6 2 2 6 38 38 38
57186 -218 218 218 253 253 253 253 253 253 253 253 253
57187 -253 253 253 253 253 253 253 253 253 253 253 253
57188 -253 253 253 253 253 253 253 253 253 253 253 253
57189 -253 253 253 253 253 253 253 253 253 253 253 253
57190 -250 250 250 206 206 206 198 198 198 202 162 69
57191 -226 170 11 236 178 12 224 166 10 210 150 10
57192 -200 144 11 197 138 11 192 133 9 197 138 11
57193 -210 150 10 226 170 11 242 186 14 246 190 14
57194 -246 190 14 246 186 14 225 175 15 124 112 88
57195 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
57200 - 30 30 30 78 78 78 174 135 50 224 166 10
57201 -239 182 13 246 190 14 246 190 14 246 190 14
57202 -246 190 14 246 190 14 246 190 14 246 190 14
57203 -246 190 14 246 190 14 246 190 14 246 190 14
57204 -246 190 14 246 190 14 241 196 14 139 102 15
57205 - 2 2 6 2 2 6 2 2 6 2 2 6
57206 - 78 78 78 250 250 250 253 253 253 253 253 253
57207 -253 253 253 253 253 253 253 253 253 253 253 253
57208 -253 253 253 253 253 253 253 253 253 253 253 253
57209 -253 253 253 253 253 253 253 253 253 253 253 253
57210 -250 250 250 214 214 214 198 198 198 190 150 46
57211 -219 162 10 236 178 12 234 174 13 224 166 10
57212 -216 158 10 213 154 11 213 154 11 216 158 10
57213 -226 170 11 239 182 13 246 190 14 246 190 14
57214 -246 190 14 246 190 14 242 186 14 206 162 42
57215 -101 101 101 58 58 58 30 30 30 14 14 14
57216 - 6 6 6 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 10 10 10
57220 - 30 30 30 74 74 74 174 135 50 216 158 10
57221 -236 178 12 246 190 14 246 190 14 246 190 14
57222 -246 190 14 246 190 14 246 190 14 246 190 14
57223 -246 190 14 246 190 14 246 190 14 246 190 14
57224 -246 190 14 246 190 14 241 196 14 226 184 13
57225 - 61 42 6 2 2 6 2 2 6 2 2 6
57226 - 22 22 22 238 238 238 253 253 253 253 253 253
57227 -253 253 253 253 253 253 253 253 253 253 253 253
57228 -253 253 253 253 253 253 253 253 253 253 253 253
57229 -253 253 253 253 253 253 253 253 253 253 253 253
57230 -253 253 253 226 226 226 187 187 187 180 133 36
57231 -216 158 10 236 178 12 239 182 13 236 178 12
57232 -230 174 11 226 170 11 226 170 11 230 174 11
57233 -236 178 12 242 186 14 246 190 14 246 190 14
57234 -246 190 14 246 190 14 246 186 14 239 182 13
57235 -206 162 42 106 106 106 66 66 66 34 34 34
57236 - 14 14 14 6 6 6 0 0 0 0 0 0
57237 - 0 0 0 0 0 0 0 0 0 0 0 0
57238 - 0 0 0 0 0 0 0 0 0 0 0 0
57239 - 0 0 0 0 0 0 0 0 0 6 6 6
57240 - 26 26 26 70 70 70 163 133 67 213 154 11
57241 -236 178 12 246 190 14 246 190 14 246 190 14
57242 -246 190 14 246 190 14 246 190 14 246 190 14
57243 -246 190 14 246 190 14 246 190 14 246 190 14
57244 -246 190 14 246 190 14 246 190 14 241 196 14
57245 -190 146 13 18 14 6 2 2 6 2 2 6
57246 - 46 46 46 246 246 246 253 253 253 253 253 253
57247 -253 253 253 253 253 253 253 253 253 253 253 253
57248 -253 253 253 253 253 253 253 253 253 253 253 253
57249 -253 253 253 253 253 253 253 253 253 253 253 253
57250 -253 253 253 221 221 221 86 86 86 156 107 11
57251 -216 158 10 236 178 12 242 186 14 246 186 14
57252 -242 186 14 239 182 13 239 182 13 242 186 14
57253 -242 186 14 246 186 14 246 190 14 246 190 14
57254 -246 190 14 246 190 14 246 190 14 246 190 14
57255 -242 186 14 225 175 15 142 122 72 66 66 66
57256 - 30 30 30 10 10 10 0 0 0 0 0 0
57257 - 0 0 0 0 0 0 0 0 0 0 0 0
57258 - 0 0 0 0 0 0 0 0 0 0 0 0
57259 - 0 0 0 0 0 0 0 0 0 6 6 6
57260 - 26 26 26 70 70 70 163 133 67 210 150 10
57261 -236 178 12 246 190 14 246 190 14 246 190 14
57262 -246 190 14 246 190 14 246 190 14 246 190 14
57263 -246 190 14 246 190 14 246 190 14 246 190 14
57264 -246 190 14 246 190 14 246 190 14 246 190 14
57265 -232 195 16 121 92 8 34 34 34 106 106 106
57266 -221 221 221 253 253 253 253 253 253 253 253 253
57267 -253 253 253 253 253 253 253 253 253 253 253 253
57268 -253 253 253 253 253 253 253 253 253 253 253 253
57269 -253 253 253 253 253 253 253 253 253 253 253 253
57270 -242 242 242 82 82 82 18 14 6 163 110 8
57271 -216 158 10 236 178 12 242 186 14 246 190 14
57272 -246 190 14 246 190 14 246 190 14 246 190 14
57273 -246 190 14 246 190 14 246 190 14 246 190 14
57274 -246 190 14 246 190 14 246 190 14 246 190 14
57275 -246 190 14 246 190 14 242 186 14 163 133 67
57276 - 46 46 46 18 18 18 6 6 6 0 0 0
57277 - 0 0 0 0 0 0 0 0 0 0 0 0
57278 - 0 0 0 0 0 0 0 0 0 0 0 0
57279 - 0 0 0 0 0 0 0 0 0 10 10 10
57280 - 30 30 30 78 78 78 163 133 67 210 150 10
57281 -236 178 12 246 186 14 246 190 14 246 190 14
57282 -246 190 14 246 190 14 246 190 14 246 190 14
57283 -246 190 14 246 190 14 246 190 14 246 190 14
57284 -246 190 14 246 190 14 246 190 14 246 190 14
57285 -241 196 14 215 174 15 190 178 144 253 253 253
57286 -253 253 253 253 253 253 253 253 253 253 253 253
57287 -253 253 253 253 253 253 253 253 253 253 253 253
57288 -253 253 253 253 253 253 253 253 253 253 253 253
57289 -253 253 253 253 253 253 253 253 253 218 218 218
57290 - 58 58 58 2 2 6 22 18 6 167 114 7
57291 -216 158 10 236 178 12 246 186 14 246 190 14
57292 -246 190 14 246 190 14 246 190 14 246 190 14
57293 -246 190 14 246 190 14 246 190 14 246 190 14
57294 -246 190 14 246 190 14 246 190 14 246 190 14
57295 -246 190 14 246 186 14 242 186 14 190 150 46
57296 - 54 54 54 22 22 22 6 6 6 0 0 0
57297 - 0 0 0 0 0 0 0 0 0 0 0 0
57298 - 0 0 0 0 0 0 0 0 0 0 0 0
57299 - 0 0 0 0 0 0 0 0 0 14 14 14
57300 - 38 38 38 86 86 86 180 133 36 213 154 11
57301 -236 178 12 246 186 14 246 190 14 246 190 14
57302 -246 190 14 246 190 14 246 190 14 246 190 14
57303 -246 190 14 246 190 14 246 190 14 246 190 14
57304 -246 190 14 246 190 14 246 190 14 246 190 14
57305 -246 190 14 232 195 16 190 146 13 214 214 214
57306 -253 253 253 253 253 253 253 253 253 253 253 253
57307 -253 253 253 253 253 253 253 253 253 253 253 253
57308 -253 253 253 253 253 253 253 253 253 253 253 253
57309 -253 253 253 250 250 250 170 170 170 26 26 26
57310 - 2 2 6 2 2 6 37 26 9 163 110 8
57311 -219 162 10 239 182 13 246 186 14 246 190 14
57312 -246 190 14 246 190 14 246 190 14 246 190 14
57313 -246 190 14 246 190 14 246 190 14 246 190 14
57314 -246 190 14 246 190 14 246 190 14 246 190 14
57315 -246 186 14 236 178 12 224 166 10 142 122 72
57316 - 46 46 46 18 18 18 6 6 6 0 0 0
57317 - 0 0 0 0 0 0 0 0 0 0 0 0
57318 - 0 0 0 0 0 0 0 0 0 0 0 0
57319 - 0 0 0 0 0 0 6 6 6 18 18 18
57320 - 50 50 50 109 106 95 192 133 9 224 166 10
57321 -242 186 14 246 190 14 246 190 14 246 190 14
57322 -246 190 14 246 190 14 246 190 14 246 190 14
57323 -246 190 14 246 190 14 246 190 14 246 190 14
57324 -246 190 14 246 190 14 246 190 14 246 190 14
57325 -242 186 14 226 184 13 210 162 10 142 110 46
57326 -226 226 226 253 253 253 253 253 253 253 253 253
57327 -253 253 253 253 253 253 253 253 253 253 253 253
57328 -253 253 253 253 253 253 253 253 253 253 253 253
57329 -198 198 198 66 66 66 2 2 6 2 2 6
57330 - 2 2 6 2 2 6 50 34 6 156 107 11
57331 -219 162 10 239 182 13 246 186 14 246 190 14
57332 -246 190 14 246 190 14 246 190 14 246 190 14
57333 -246 190 14 246 190 14 246 190 14 246 190 14
57334 -246 190 14 246 190 14 246 190 14 242 186 14
57335 -234 174 13 213 154 11 154 122 46 66 66 66
57336 - 30 30 30 10 10 10 0 0 0 0 0 0
57337 - 0 0 0 0 0 0 0 0 0 0 0 0
57338 - 0 0 0 0 0 0 0 0 0 0 0 0
57339 - 0 0 0 0 0 0 6 6 6 22 22 22
57340 - 58 58 58 154 121 60 206 145 10 234 174 13
57341 -242 186 14 246 186 14 246 190 14 246 190 14
57342 -246 190 14 246 190 14 246 190 14 246 190 14
57343 -246 190 14 246 190 14 246 190 14 246 190 14
57344 -246 190 14 246 190 14 246 190 14 246 190 14
57345 -246 186 14 236 178 12 210 162 10 163 110 8
57346 - 61 42 6 138 138 138 218 218 218 250 250 250
57347 -253 253 253 253 253 253 253 253 253 250 250 250
57348 -242 242 242 210 210 210 144 144 144 66 66 66
57349 - 6 6 6 2 2 6 2 2 6 2 2 6
57350 - 2 2 6 2 2 6 61 42 6 163 110 8
57351 -216 158 10 236 178 12 246 190 14 246 190 14
57352 -246 190 14 246 190 14 246 190 14 246 190 14
57353 -246 190 14 246 190 14 246 190 14 246 190 14
57354 -246 190 14 239 182 13 230 174 11 216 158 10
57355 -190 142 34 124 112 88 70 70 70 38 38 38
57356 - 18 18 18 6 6 6 0 0 0 0 0 0
57357 - 0 0 0 0 0 0 0 0 0 0 0 0
57358 - 0 0 0 0 0 0 0 0 0 0 0 0
57359 - 0 0 0 0 0 0 6 6 6 22 22 22
57360 - 62 62 62 168 124 44 206 145 10 224 166 10
57361 -236 178 12 239 182 13 242 186 14 242 186 14
57362 -246 186 14 246 190 14 246 190 14 246 190 14
57363 -246 190 14 246 190 14 246 190 14 246 190 14
57364 -246 190 14 246 190 14 246 190 14 246 190 14
57365 -246 190 14 236 178 12 216 158 10 175 118 6
57366 - 80 54 7 2 2 6 6 6 6 30 30 30
57367 - 54 54 54 62 62 62 50 50 50 38 38 38
57368 - 14 14 14 2 2 6 2 2 6 2 2 6
57369 - 2 2 6 2 2 6 2 2 6 2 2 6
57370 - 2 2 6 6 6 6 80 54 7 167 114 7
57371 -213 154 11 236 178 12 246 190 14 246 190 14
57372 -246 190 14 246 190 14 246 190 14 246 190 14
57373 -246 190 14 242 186 14 239 182 13 239 182 13
57374 -230 174 11 210 150 10 174 135 50 124 112 88
57375 - 82 82 82 54 54 54 34 34 34 18 18 18
57376 - 6 6 6 0 0 0 0 0 0 0 0 0
57377 - 0 0 0 0 0 0 0 0 0 0 0 0
57378 - 0 0 0 0 0 0 0 0 0 0 0 0
57379 - 0 0 0 0 0 0 6 6 6 18 18 18
57380 - 50 50 50 158 118 36 192 133 9 200 144 11
57381 -216 158 10 219 162 10 224 166 10 226 170 11
57382 -230 174 11 236 178 12 239 182 13 239 182 13
57383 -242 186 14 246 186 14 246 190 14 246 190 14
57384 -246 190 14 246 190 14 246 190 14 246 190 14
57385 -246 186 14 230 174 11 210 150 10 163 110 8
57386 -104 69 6 10 10 10 2 2 6 2 2 6
57387 - 2 2 6 2 2 6 2 2 6 2 2 6
57388 - 2 2 6 2 2 6 2 2 6 2 2 6
57389 - 2 2 6 2 2 6 2 2 6 2 2 6
57390 - 2 2 6 6 6 6 91 60 6 167 114 7
57391 -206 145 10 230 174 11 242 186 14 246 190 14
57392 -246 190 14 246 190 14 246 186 14 242 186 14
57393 -239 182 13 230 174 11 224 166 10 213 154 11
57394 -180 133 36 124 112 88 86 86 86 58 58 58
57395 - 38 38 38 22 22 22 10 10 10 6 6 6
57396 - 0 0 0 0 0 0 0 0 0 0 0 0
57397 - 0 0 0 0 0 0 0 0 0 0 0 0
57398 - 0 0 0 0 0 0 0 0 0 0 0 0
57399 - 0 0 0 0 0 0 0 0 0 14 14 14
57400 - 34 34 34 70 70 70 138 110 50 158 118 36
57401 -167 114 7 180 123 7 192 133 9 197 138 11
57402 -200 144 11 206 145 10 213 154 11 219 162 10
57403 -224 166 10 230 174 11 239 182 13 242 186 14
57404 -246 186 14 246 186 14 246 186 14 246 186 14
57405 -239 182 13 216 158 10 185 133 11 152 99 6
57406 -104 69 6 18 14 6 2 2 6 2 2 6
57407 - 2 2 6 2 2 6 2 2 6 2 2 6
57408 - 2 2 6 2 2 6 2 2 6 2 2 6
57409 - 2 2 6 2 2 6 2 2 6 2 2 6
57410 - 2 2 6 6 6 6 80 54 7 152 99 6
57411 -192 133 9 219 162 10 236 178 12 239 182 13
57412 -246 186 14 242 186 14 239 182 13 236 178 12
57413 -224 166 10 206 145 10 192 133 9 154 121 60
57414 - 94 94 94 62 62 62 42 42 42 22 22 22
57415 - 14 14 14 6 6 6 0 0 0 0 0 0
57416 - 0 0 0 0 0 0 0 0 0 0 0 0
57417 - 0 0 0 0 0 0 0 0 0 0 0 0
57418 - 0 0 0 0 0 0 0 0 0 0 0 0
57419 - 0 0 0 0 0 0 0 0 0 6 6 6
57420 - 18 18 18 34 34 34 58 58 58 78 78 78
57421 -101 98 89 124 112 88 142 110 46 156 107 11
57422 -163 110 8 167 114 7 175 118 6 180 123 7
57423 -185 133 11 197 138 11 210 150 10 219 162 10
57424 -226 170 11 236 178 12 236 178 12 234 174 13
57425 -219 162 10 197 138 11 163 110 8 130 83 6
57426 - 91 60 6 10 10 10 2 2 6 2 2 6
57427 - 18 18 18 38 38 38 38 38 38 38 38 38
57428 - 38 38 38 38 38 38 38 38 38 38 38 38
57429 - 38 38 38 38 38 38 26 26 26 2 2 6
57430 - 2 2 6 6 6 6 70 47 6 137 92 6
57431 -175 118 6 200 144 11 219 162 10 230 174 11
57432 -234 174 13 230 174 11 219 162 10 210 150 10
57433 -192 133 9 163 110 8 124 112 88 82 82 82
57434 - 50 50 50 30 30 30 14 14 14 6 6 6
57435 - 0 0 0 0 0 0 0 0 0 0 0 0
57436 - 0 0 0 0 0 0 0 0 0 0 0 0
57437 - 0 0 0 0 0 0 0 0 0 0 0 0
57438 - 0 0 0 0 0 0 0 0 0 0 0 0
57439 - 0 0 0 0 0 0 0 0 0 0 0 0
57440 - 6 6 6 14 14 14 22 22 22 34 34 34
57441 - 42 42 42 58 58 58 74 74 74 86 86 86
57442 -101 98 89 122 102 70 130 98 46 121 87 25
57443 -137 92 6 152 99 6 163 110 8 180 123 7
57444 -185 133 11 197 138 11 206 145 10 200 144 11
57445 -180 123 7 156 107 11 130 83 6 104 69 6
57446 - 50 34 6 54 54 54 110 110 110 101 98 89
57447 - 86 86 86 82 82 82 78 78 78 78 78 78
57448 - 78 78 78 78 78 78 78 78 78 78 78 78
57449 - 78 78 78 82 82 82 86 86 86 94 94 94
57450 -106 106 106 101 101 101 86 66 34 124 80 6
57451 -156 107 11 180 123 7 192 133 9 200 144 11
57452 -206 145 10 200 144 11 192 133 9 175 118 6
57453 -139 102 15 109 106 95 70 70 70 42 42 42
57454 - 22 22 22 10 10 10 0 0 0 0 0 0
57455 - 0 0 0 0 0 0 0 0 0 0 0 0
57456 - 0 0 0 0 0 0 0 0 0 0 0 0
57457 - 0 0 0 0 0 0 0 0 0 0 0 0
57458 - 0 0 0 0 0 0 0 0 0 0 0 0
57459 - 0 0 0 0 0 0 0 0 0 0 0 0
57460 - 0 0 0 0 0 0 6 6 6 10 10 10
57461 - 14 14 14 22 22 22 30 30 30 38 38 38
57462 - 50 50 50 62 62 62 74 74 74 90 90 90
57463 -101 98 89 112 100 78 121 87 25 124 80 6
57464 -137 92 6 152 99 6 152 99 6 152 99 6
57465 -138 86 6 124 80 6 98 70 6 86 66 30
57466 -101 98 89 82 82 82 58 58 58 46 46 46
57467 - 38 38 38 34 34 34 34 34 34 34 34 34
57468 - 34 34 34 34 34 34 34 34 34 34 34 34
57469 - 34 34 34 34 34 34 38 38 38 42 42 42
57470 - 54 54 54 82 82 82 94 86 76 91 60 6
57471 -134 86 6 156 107 11 167 114 7 175 118 6
57472 -175 118 6 167 114 7 152 99 6 121 87 25
57473 -101 98 89 62 62 62 34 34 34 18 18 18
57474 - 6 6 6 0 0 0 0 0 0 0 0 0
57475 - 0 0 0 0 0 0 0 0 0 0 0 0
57476 - 0 0 0 0 0 0 0 0 0 0 0 0
57477 - 0 0 0 0 0 0 0 0 0 0 0 0
57478 - 0 0 0 0 0 0 0 0 0 0 0 0
57479 - 0 0 0 0 0 0 0 0 0 0 0 0
57480 - 0 0 0 0 0 0 0 0 0 0 0 0
57481 - 0 0 0 6 6 6 6 6 6 10 10 10
57482 - 18 18 18 22 22 22 30 30 30 42 42 42
57483 - 50 50 50 66 66 66 86 86 86 101 98 89
57484 -106 86 58 98 70 6 104 69 6 104 69 6
57485 -104 69 6 91 60 6 82 62 34 90 90 90
57486 - 62 62 62 38 38 38 22 22 22 14 14 14
57487 - 10 10 10 10 10 10 10 10 10 10 10 10
57488 - 10 10 10 10 10 10 6 6 6 10 10 10
57489 - 10 10 10 10 10 10 10 10 10 14 14 14
57490 - 22 22 22 42 42 42 70 70 70 89 81 66
57491 - 80 54 7 104 69 6 124 80 6 137 92 6
57492 -134 86 6 116 81 8 100 82 52 86 86 86
57493 - 58 58 58 30 30 30 14 14 14 6 6 6
57494 - 0 0 0 0 0 0 0 0 0 0 0 0
57495 - 0 0 0 0 0 0 0 0 0 0 0 0
57496 - 0 0 0 0 0 0 0 0 0 0 0 0
57497 - 0 0 0 0 0 0 0 0 0 0 0 0
57498 - 0 0 0 0 0 0 0 0 0 0 0 0
57499 - 0 0 0 0 0 0 0 0 0 0 0 0
57500 - 0 0 0 0 0 0 0 0 0 0 0 0
57501 - 0 0 0 0 0 0 0 0 0 0 0 0
57502 - 0 0 0 6 6 6 10 10 10 14 14 14
57503 - 18 18 18 26 26 26 38 38 38 54 54 54
57504 - 70 70 70 86 86 86 94 86 76 89 81 66
57505 - 89 81 66 86 86 86 74 74 74 50 50 50
57506 - 30 30 30 14 14 14 6 6 6 0 0 0
57507 - 0 0 0 0 0 0 0 0 0 0 0 0
57508 - 0 0 0 0 0 0 0 0 0 0 0 0
57509 - 0 0 0 0 0 0 0 0 0 0 0 0
57510 - 6 6 6 18 18 18 34 34 34 58 58 58
57511 - 82 82 82 89 81 66 89 81 66 89 81 66
57512 - 94 86 66 94 86 76 74 74 74 50 50 50
57513 - 26 26 26 14 14 14 6 6 6 0 0 0
57514 - 0 0 0 0 0 0 0 0 0 0 0 0
57515 - 0 0 0 0 0 0 0 0 0 0 0 0
57516 - 0 0 0 0 0 0 0 0 0 0 0 0
57517 - 0 0 0 0 0 0 0 0 0 0 0 0
57518 - 0 0 0 0 0 0 0 0 0 0 0 0
57519 - 0 0 0 0 0 0 0 0 0 0 0 0
57520 - 0 0 0 0 0 0 0 0 0 0 0 0
57521 - 0 0 0 0 0 0 0 0 0 0 0 0
57522 - 0 0 0 0 0 0 0 0 0 0 0 0
57523 - 6 6 6 6 6 6 14 14 14 18 18 18
57524 - 30 30 30 38 38 38 46 46 46 54 54 54
57525 - 50 50 50 42 42 42 30 30 30 18 18 18
57526 - 10 10 10 0 0 0 0 0 0 0 0 0
57527 - 0 0 0 0 0 0 0 0 0 0 0 0
57528 - 0 0 0 0 0 0 0 0 0 0 0 0
57529 - 0 0 0 0 0 0 0 0 0 0 0 0
57530 - 0 0 0 6 6 6 14 14 14 26 26 26
57531 - 38 38 38 50 50 50 58 58 58 58 58 58
57532 - 54 54 54 42 42 42 30 30 30 18 18 18
57533 - 10 10 10 0 0 0 0 0 0 0 0 0
57534 - 0 0 0 0 0 0 0 0 0 0 0 0
57535 - 0 0 0 0 0 0 0 0 0 0 0 0
57536 - 0 0 0 0 0 0 0 0 0 0 0 0
57537 - 0 0 0 0 0 0 0 0 0 0 0 0
57538 - 0 0 0 0 0 0 0 0 0 0 0 0
57539 - 0 0 0 0 0 0 0 0 0 0 0 0
57540 - 0 0 0 0 0 0 0 0 0 0 0 0
57541 - 0 0 0 0 0 0 0 0 0 0 0 0
57542 - 0 0 0 0 0 0 0 0 0 0 0 0
57543 - 0 0 0 0 0 0 0 0 0 6 6 6
57544 - 6 6 6 10 10 10 14 14 14 18 18 18
57545 - 18 18 18 14 14 14 10 10 10 6 6 6
57546 - 0 0 0 0 0 0 0 0 0 0 0 0
57547 - 0 0 0 0 0 0 0 0 0 0 0 0
57548 - 0 0 0 0 0 0 0 0 0 0 0 0
57549 - 0 0 0 0 0 0 0 0 0 0 0 0
57550 - 0 0 0 0 0 0 0 0 0 6 6 6
57551 - 14 14 14 18 18 18 22 22 22 22 22 22
57552 - 18 18 18 14 14 14 10 10 10 6 6 6
57553 - 0 0 0 0 0 0 0 0 0 0 0 0
57554 - 0 0 0 0 0 0 0 0 0 0 0 0
57555 - 0 0 0 0 0 0 0 0 0 0 0 0
57556 - 0 0 0 0 0 0 0 0 0 0 0 0
57557 - 0 0 0 0 0 0 0 0 0 0 0 0
57558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57571 +4 4 4 4 4 4
57572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57585 +4 4 4 4 4 4
57586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57599 +4 4 4 4 4 4
57600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57613 +4 4 4 4 4 4
57614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57627 +4 4 4 4 4 4
57628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57641 +4 4 4 4 4 4
57642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57646 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57647 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57651 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57652 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57653 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57655 +4 4 4 4 4 4
57656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57660 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57661 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57662 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57665 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57666 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57667 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57668 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57669 +4 4 4 4 4 4
57670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57674 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57675 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57676 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57679 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57680 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57681 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57682 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57683 +4 4 4 4 4 4
57684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57687 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57688 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57689 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57690 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57692 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57693 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57694 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57695 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57696 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57697 +4 4 4 4 4 4
57698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57701 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57702 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57703 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57704 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57705 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57706 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57707 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57708 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57709 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57710 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57711 +4 4 4 4 4 4
57712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57715 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57716 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57717 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57718 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57719 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57720 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57721 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57722 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57723 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57724 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57725 +4 4 4 4 4 4
57726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57728 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57729 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57730 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57731 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57732 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57733 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57734 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57735 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57736 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57737 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57738 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57739 +4 4 4 4 4 4
57740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57742 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57743 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57744 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57745 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57746 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57747 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57748 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57749 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57750 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57751 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57752 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57753 +4 4 4 4 4 4
57754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57756 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57757 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57758 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57759 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57760 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57761 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57762 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57763 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57764 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57765 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57766 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57767 +4 4 4 4 4 4
57768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57770 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57771 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57772 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57773 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57774 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57775 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57776 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57777 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57778 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57779 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57780 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57781 +4 4 4 4 4 4
57782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57783 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57784 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57785 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57786 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57787 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57788 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57789 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57790 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57791 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57792 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57793 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57794 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57795 +4 4 4 4 4 4
57796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57797 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57798 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57799 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57800 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57801 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57802 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57803 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57804 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57805 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57806 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57807 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57808 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57809 +0 0 0 4 4 4
57810 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57811 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57812 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57813 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57814 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57815 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57816 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57817 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57818 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57819 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57820 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57821 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57822 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57823 +2 0 0 0 0 0
57824 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57825 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57826 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57827 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57828 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57829 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57830 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57831 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57832 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57833 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57834 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57835 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57836 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57837 +37 38 37 0 0 0
57838 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57839 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57840 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57841 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57842 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57843 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57844 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57845 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57846 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57847 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57848 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57849 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57850 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57851 +85 115 134 4 0 0
57852 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57853 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57854 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57855 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57856 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57857 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57858 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57859 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57860 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57861 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57862 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57863 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57864 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57865 +60 73 81 4 0 0
57866 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57867 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57868 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57869 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57870 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57871 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57872 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57873 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57874 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57875 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57876 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57877 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57878 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57879 +16 19 21 4 0 0
57880 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57881 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57882 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57883 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57884 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57885 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57886 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57887 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57888 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57889 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57890 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57891 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57892 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57893 +4 0 0 4 3 3
57894 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57895 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57896 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57898 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57899 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57900 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57901 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57902 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57903 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57904 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57905 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57906 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57907 +3 2 2 4 4 4
57908 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57909 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57910 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57911 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57912 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57913 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57914 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57915 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57916 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57917 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57918 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57919 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57920 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57921 +4 4 4 4 4 4
57922 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57923 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57924 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57925 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57926 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57927 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57928 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57929 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57930 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57931 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57932 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57933 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57934 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57935 +4 4 4 4 4 4
57936 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57937 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57938 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57939 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57940 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57941 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57942 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57943 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57944 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57945 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57946 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57947 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57948 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57949 +5 5 5 5 5 5
57950 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57951 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57952 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57953 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57954 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57955 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57956 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57957 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57958 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57959 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57960 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57961 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57962 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57963 +5 5 5 4 4 4
57964 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57965 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57966 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57967 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57968 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57969 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57970 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57971 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57972 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57973 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57974 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57975 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57977 +4 4 4 4 4 4
57978 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57979 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57980 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57981 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57982 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57983 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57984 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57985 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57986 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57987 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57988 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57989 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57991 +4 4 4 4 4 4
57992 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57993 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57994 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57995 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57996 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57997 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57998 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57999 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58000 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58001 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58002 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58005 +4 4 4 4 4 4
58006 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58007 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58008 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58009 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58010 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58011 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58012 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58013 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58014 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58015 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58016 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58019 +4 4 4 4 4 4
58020 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58021 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58022 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58023 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58024 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58025 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58026 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58027 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58028 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58029 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58030 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58033 +4 4 4 4 4 4
58034 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58035 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58036 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58037 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58038 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58039 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58040 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58041 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58042 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58043 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58044 +6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
58047 +4 4 4 4 4 4
58048 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58049 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58050 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58051 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58052 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58053 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58054 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58055 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58056 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58057 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58058 +4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58061 +4 4 4 4 4 4
58062 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58063 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58064 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58065 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58066 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58067 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58068 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58069 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58070 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58071 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58072 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58075 +4 4 4 4 4 4
58076 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58077 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58078 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58079 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58080 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58081 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58082 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58083 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58084 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58085 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58086 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58089 +4 4 4 4 4 4
58090 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58091 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58092 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58093 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58094 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58095 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58096 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58097 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58098 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58099 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58100 +4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58103 +4 4 4 4 4 4
58104 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58105 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58106 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58107 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58108 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58109 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58110 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58111 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58112 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58113 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58114 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58117 +4 4 4 4 4 4
58118 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58119 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58120 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58121 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58122 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58123 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58124 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58125 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58126 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58127 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58128 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58131 +4 4 4 4 4 4
58132 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58133 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58134 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58135 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58136 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58137 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58138 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58139 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58140 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58141 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58142 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58145 +4 4 4 4 4 4
58146 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58147 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58148 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58149 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58150 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58151 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58152 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58153 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58154 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58155 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58156 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58159 +4 4 4 4 4 4
58160 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58161 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58162 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58163 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58164 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58165 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58166 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58167 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58168 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58169 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58170 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58173 +4 4 4 4 4 4
58174 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58175 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58176 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58177 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58178 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58179 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58180 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58181 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58182 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58183 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58184 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58187 +4 4 4 4 4 4
58188 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58189 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58190 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58191 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58192 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58193 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58194 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58195 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58196 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58197 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58198 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58201 +4 4 4 4 4 4
58202 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58203 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58204 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58205 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58206 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58207 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58208 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58209 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58210 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58211 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58212 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58215 +4 4 4 4 4 4
58216 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58217 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58218 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58219 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58220 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58221 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58222 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58223 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58224 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58225 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58226 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58229 +4 4 4 4 4 4
58230 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58231 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58232 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58233 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58234 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58235 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58236 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58237 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58238 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58239 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58240 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58243 +4 4 4 4 4 4
58244 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58245 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58246 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58247 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58248 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58249 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58250 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58251 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58252 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58253 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58254 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257 +4 4 4 4 4 4
58258 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58259 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58260 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58261 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58262 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58263 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58264 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58265 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58266 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58267 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58268 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271 +4 4 4 4 4 4
58272 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58273 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58274 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58275 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58276 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58277 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58278 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58279 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58280 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58281 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58282 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58285 +4 4 4 4 4 4
58286 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58287 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58288 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58289 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58290 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58291 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58292 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58293 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58294 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58295 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58296 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58299 +4 4 4 4 4 4
58300 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58301 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58302 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58303 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58304 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58305 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58306 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58307 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58308 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58309 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58310 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58313 +4 4 4 4 4 4
58314 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58315 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58316 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58317 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58318 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58319 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58320 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58321 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58322 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58323 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58324 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58327 +4 4 4 4 4 4
58328 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58329 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58330 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58331 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58332 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58333 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58334 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58335 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58336 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58337 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58338 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58341 +4 4 4 4 4 4
58342 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58343 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58344 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58345 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58346 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58347 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58348 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58349 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58350 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58351 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58352 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58355 +4 4 4 4 4 4
58356 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58357 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58358 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58359 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58360 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58361 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58362 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58363 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58364 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58365 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58366 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58369 +4 4 4 4 4 4
58370 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58371 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58372 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58373 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58374 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58375 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58376 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58377 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58378 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58379 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58383 +4 4 4 4 4 4
58384 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58385 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58386 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58387 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58388 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58389 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58390 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58391 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58392 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58393 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58397 +4 4 4 4 4 4
58398 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58399 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58400 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58401 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58402 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58403 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58404 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58405 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58406 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58407 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58411 +4 4 4 4 4 4
58412 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58413 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58414 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58415 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58416 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58417 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58418 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58419 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58420 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58421 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58425 +4 4 4 4 4 4
58426 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58427 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58428 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58429 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58430 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58431 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58432 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58433 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58434 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58439 +4 4 4 4 4 4
58440 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58441 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58442 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58443 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58444 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58445 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58446 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58447 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58448 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58453 +4 4 4 4 4 4
58454 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58455 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58456 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58457 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58458 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58459 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58460 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58461 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58462 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58467 +4 4 4 4 4 4
58468 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58469 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58470 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58471 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58472 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58473 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58474 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58475 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58481 +4 4 4 4 4 4
58482 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58483 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58484 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58485 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58486 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58487 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58488 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58489 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58495 +4 4 4 4 4 4
58496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58497 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58498 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58499 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58500 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58501 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58502 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58503 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58509 +4 4 4 4 4 4
58510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58511 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58512 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58513 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58514 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58515 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58516 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58517 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58523 +4 4 4 4 4 4
58524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58525 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58526 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58527 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58528 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58529 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58530 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58531 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58537 +4 4 4 4 4 4
58538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58540 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58541 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58542 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58543 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58544 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58545 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58551 +4 4 4 4 4 4
58552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58555 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58556 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58557 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58558 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58565 +4 4 4 4 4 4
58566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58569 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58570 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58571 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58572 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58579 +4 4 4 4 4 4
58580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58583 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58584 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58585 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58586 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58593 +4 4 4 4 4 4
58594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58597 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58598 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58599 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58600 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58607 +4 4 4 4 4 4
58608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58612 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58613 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58614 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58621 +4 4 4 4 4 4
58622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58626 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58627 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58628 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58635 +4 4 4 4 4 4
58636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58640 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58641 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58642 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58649 +4 4 4 4 4 4
58650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58654 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58655 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58663 +4 4 4 4 4 4
58664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58668 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58669 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58677 +4 4 4 4 4 4
58678 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58679 index fef20db..d28b1ab 100644
58680 --- a/drivers/xen/xenfs/xenstored.c
58681 +++ b/drivers/xen/xenfs/xenstored.c
58682 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58683 static int xsd_kva_open(struct inode *inode, struct file *file)
58684 {
58685 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58686 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58687 + NULL);
58688 +#else
58689 xen_store_interface);
58690 +#endif
58691 +
58692 if (!file->private_data)
58693 return -ENOMEM;
58694 return 0;
58695 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58696 index cc1cfae..41158ad 100644
58697 --- a/fs/9p/vfs_addr.c
58698 +++ b/fs/9p/vfs_addr.c
58699 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58700
58701 retval = v9fs_file_write_internal(inode,
58702 v9inode->writeback_fid,
58703 - (__force const char __user *)buffer,
58704 + (const char __force_user *)buffer,
58705 len, &offset, 0);
58706 if (retval > 0)
58707 retval = 0;
58708 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58709 index 7fa4f7a..a7ebf8c 100644
58710 --- a/fs/9p/vfs_inode.c
58711 +++ b/fs/9p/vfs_inode.c
58712 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58713 void
58714 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58715 {
58716 - char *s = nd_get_link(nd);
58717 + const char *s = nd_get_link(nd);
58718
58719 p9_debug(P9_DEBUG_VFS, " %s %s\n",
58720 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
58721 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58722 index 370b24c..ff0be7b 100644
58723 --- a/fs/Kconfig.binfmt
58724 +++ b/fs/Kconfig.binfmt
58725 @@ -103,7 +103,7 @@ config HAVE_AOUT
58726
58727 config BINFMT_AOUT
58728 tristate "Kernel support for a.out and ECOFF binaries"
58729 - depends on HAVE_AOUT
58730 + depends on HAVE_AOUT && BROKEN
58731 ---help---
58732 A.out (Assembler.OUTput) is a set of formats for libraries and
58733 executables used in the earliest versions of UNIX. Linux used
58734 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58735 index 2946712..f737435 100644
58736 --- a/fs/afs/inode.c
58737 +++ b/fs/afs/inode.c
58738 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58739 struct afs_vnode *vnode;
58740 struct super_block *sb;
58741 struct inode *inode;
58742 - static atomic_t afs_autocell_ino;
58743 + static atomic_unchecked_t afs_autocell_ino;
58744
58745 _enter("{%x:%u},%*.*s,",
58746 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58747 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58748 data.fid.unique = 0;
58749 data.fid.vnode = 0;
58750
58751 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58752 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58753 afs_iget5_autocell_test, afs_iget5_set,
58754 &data);
58755 if (!inode) {
58756 diff --git a/fs/aio.c b/fs/aio.c
58757 index 0ff7c46..7f5d132 100644
58758 --- a/fs/aio.c
58759 +++ b/fs/aio.c
58760 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58761 size += sizeof(struct io_event) * nr_events;
58762
58763 nr_pages = PFN_UP(size);
58764 - if (nr_pages < 0)
58765 + if (nr_pages <= 0)
58766 return -EINVAL;
58767
58768 file = aio_private_file(ctx, nr_pages);
58769 diff --git a/fs/attr.c b/fs/attr.c
58770 index 6530ced..4a827e2 100644
58771 --- a/fs/attr.c
58772 +++ b/fs/attr.c
58773 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58774 unsigned long limit;
58775
58776 limit = rlimit(RLIMIT_FSIZE);
58777 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58778 if (limit != RLIM_INFINITY && offset > limit)
58779 goto out_sig;
58780 if (offset > inode->i_sb->s_maxbytes)
58781 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58782 index 116fd38..c04182da 100644
58783 --- a/fs/autofs4/waitq.c
58784 +++ b/fs/autofs4/waitq.c
58785 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58786 {
58787 unsigned long sigpipe, flags;
58788 mm_segment_t fs;
58789 - const char *data = (const char *)addr;
58790 + const char __user *data = (const char __force_user *)addr;
58791 ssize_t wr = 0;
58792
58793 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58794 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58795 return 1;
58796 }
58797
58798 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58799 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58800 +#endif
58801 +
58802 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58803 enum autofs_notify notify)
58804 {
58805 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58806
58807 /* If this is a direct mount request create a dummy name */
58808 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58809 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58810 + /* this name does get written to userland via autofs4_write() */
58811 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58812 +#else
58813 qstr.len = sprintf(name, "%p", dentry);
58814 +#endif
58815 else {
58816 qstr.len = autofs4_getpath(sbi, dentry, &name);
58817 if (!qstr.len) {
58818 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58819 index 2722387..56059b5 100644
58820 --- a/fs/befs/endian.h
58821 +++ b/fs/befs/endian.h
58822 @@ -11,7 +11,7 @@
58823
58824 #include <asm/byteorder.h>
58825
58826 -static inline u64
58827 +static inline u64 __intentional_overflow(-1)
58828 fs64_to_cpu(const struct super_block *sb, fs64 n)
58829 {
58830 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58831 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58832 return (__force fs64)cpu_to_be64(n);
58833 }
58834
58835 -static inline u32
58836 +static inline u32 __intentional_overflow(-1)
58837 fs32_to_cpu(const struct super_block *sb, fs32 n)
58838 {
58839 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58840 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58841 return (__force fs32)cpu_to_be32(n);
58842 }
58843
58844 -static inline u16
58845 +static inline u16 __intentional_overflow(-1)
58846 fs16_to_cpu(const struct super_block *sb, fs16 n)
58847 {
58848 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58849 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58850 index ca0ba15..0fa3257 100644
58851 --- a/fs/binfmt_aout.c
58852 +++ b/fs/binfmt_aout.c
58853 @@ -16,6 +16,7 @@
58854 #include <linux/string.h>
58855 #include <linux/fs.h>
58856 #include <linux/file.h>
58857 +#include <linux/security.h>
58858 #include <linux/stat.h>
58859 #include <linux/fcntl.h>
58860 #include <linux/ptrace.h>
58861 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58862 #endif
58863 # define START_STACK(u) ((void __user *)u.start_stack)
58864
58865 + memset(&dump, 0, sizeof(dump));
58866 +
58867 fs = get_fs();
58868 set_fs(KERNEL_DS);
58869 has_dumped = 1;
58870 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58871
58872 /* If the size of the dump file exceeds the rlimit, then see what would happen
58873 if we wrote the stack, but not the data area. */
58874 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58875 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58876 dump.u_dsize = 0;
58877
58878 /* Make sure we have enough room to write the stack and data areas. */
58879 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58880 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58881 dump.u_ssize = 0;
58882
58883 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58884 rlim = rlimit(RLIMIT_DATA);
58885 if (rlim >= RLIM_INFINITY)
58886 rlim = ~0;
58887 +
58888 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58889 if (ex.a_data + ex.a_bss > rlim)
58890 return -ENOMEM;
58891
58892 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58893
58894 install_exec_creds(bprm);
58895
58896 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58897 + current->mm->pax_flags = 0UL;
58898 +#endif
58899 +
58900 +#ifdef CONFIG_PAX_PAGEEXEC
58901 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58902 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58903 +
58904 +#ifdef CONFIG_PAX_EMUTRAMP
58905 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58906 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58907 +#endif
58908 +
58909 +#ifdef CONFIG_PAX_MPROTECT
58910 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58911 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58912 +#endif
58913 +
58914 + }
58915 +#endif
58916 +
58917 if (N_MAGIC(ex) == OMAGIC) {
58918 unsigned long text_addr, map_size;
58919 loff_t pos;
58920 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58921 }
58922
58923 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58924 - PROT_READ | PROT_WRITE | PROT_EXEC,
58925 + PROT_READ | PROT_WRITE,
58926 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58927 fd_offset + ex.a_text);
58928 if (error != N_DATADDR(ex)) {
58929 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58930 index 3892c1a..4e27c04 100644
58931 --- a/fs/binfmt_elf.c
58932 +++ b/fs/binfmt_elf.c
58933 @@ -34,6 +34,7 @@
58934 #include <linux/utsname.h>
58935 #include <linux/coredump.h>
58936 #include <linux/sched.h>
58937 +#include <linux/xattr.h>
58938 #include <asm/uaccess.h>
58939 #include <asm/param.h>
58940 #include <asm/page.h>
58941 @@ -47,7 +48,7 @@
58942
58943 static int load_elf_binary(struct linux_binprm *bprm);
58944 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58945 - int, int, unsigned long);
58946 + int, int, unsigned long) __intentional_overflow(-1);
58947
58948 #ifdef CONFIG_USELIB
58949 static int load_elf_library(struct file *);
58950 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58951 #define elf_core_dump NULL
58952 #endif
58953
58954 +#ifdef CONFIG_PAX_MPROTECT
58955 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58956 +#endif
58957 +
58958 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58959 +static void elf_handle_mmap(struct file *file);
58960 +#endif
58961 +
58962 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58963 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58964 #else
58965 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58966 .load_binary = load_elf_binary,
58967 .load_shlib = load_elf_library,
58968 .core_dump = elf_core_dump,
58969 +
58970 +#ifdef CONFIG_PAX_MPROTECT
58971 + .handle_mprotect= elf_handle_mprotect,
58972 +#endif
58973 +
58974 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58975 + .handle_mmap = elf_handle_mmap,
58976 +#endif
58977 +
58978 .min_coredump = ELF_EXEC_PAGESIZE,
58979 };
58980
58981 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58982
58983 static int set_brk(unsigned long start, unsigned long end)
58984 {
58985 + unsigned long e = end;
58986 +
58987 start = ELF_PAGEALIGN(start);
58988 end = ELF_PAGEALIGN(end);
58989 if (end > start) {
58990 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58991 if (BAD_ADDR(addr))
58992 return addr;
58993 }
58994 - current->mm->start_brk = current->mm->brk = end;
58995 + current->mm->start_brk = current->mm->brk = e;
58996 return 0;
58997 }
58998
58999 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59000 elf_addr_t __user *u_rand_bytes;
59001 const char *k_platform = ELF_PLATFORM;
59002 const char *k_base_platform = ELF_BASE_PLATFORM;
59003 - unsigned char k_rand_bytes[16];
59004 + u32 k_rand_bytes[4];
59005 int items;
59006 elf_addr_t *elf_info;
59007 int ei_index = 0;
59008 const struct cred *cred = current_cred();
59009 struct vm_area_struct *vma;
59010 + unsigned long saved_auxv[AT_VECTOR_SIZE];
59011
59012 /*
59013 * In some cases (e.g. Hyper-Threading), we want to avoid L1
59014 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59015 * Generate 16 random bytes for userspace PRNG seeding.
59016 */
59017 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
59018 - u_rand_bytes = (elf_addr_t __user *)
59019 - STACK_ALLOC(p, sizeof(k_rand_bytes));
59020 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
59021 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
59022 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
59023 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
59024 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
59025 + u_rand_bytes = (elf_addr_t __user *) p;
59026 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
59027 return -EFAULT;
59028
59029 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59030 return -EFAULT;
59031 current->mm->env_end = p;
59032
59033 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
59034 +
59035 /* Put the elf_info on the stack in the right place. */
59036 sp = (elf_addr_t __user *)envp + 1;
59037 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
59038 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
59039 return -EFAULT;
59040 return 0;
59041 }
59042 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
59043 an ELF header */
59044
59045 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59046 - struct file *interpreter, unsigned long *interp_map_addr,
59047 - unsigned long no_base)
59048 + struct file *interpreter, unsigned long no_base)
59049 {
59050 struct elf_phdr *elf_phdata;
59051 struct elf_phdr *eppnt;
59052 - unsigned long load_addr = 0;
59053 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
59054 int load_addr_set = 0;
59055 unsigned long last_bss = 0, elf_bss = 0;
59056 - unsigned long error = ~0UL;
59057 + unsigned long error = -EINVAL;
59058 unsigned long total_size;
59059 int retval, i, size;
59060
59061 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59062 goto out_close;
59063 }
59064
59065 +#ifdef CONFIG_PAX_SEGMEXEC
59066 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59067 + pax_task_size = SEGMEXEC_TASK_SIZE;
59068 +#endif
59069 +
59070 eppnt = elf_phdata;
59071 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59072 if (eppnt->p_type == PT_LOAD) {
59073 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59074 map_addr = elf_map(interpreter, load_addr + vaddr,
59075 eppnt, elf_prot, elf_type, total_size);
59076 total_size = 0;
59077 - if (!*interp_map_addr)
59078 - *interp_map_addr = map_addr;
59079 error = map_addr;
59080 if (BAD_ADDR(map_addr))
59081 goto out_close;
59082 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59083 k = load_addr + eppnt->p_vaddr;
59084 if (BAD_ADDR(k) ||
59085 eppnt->p_filesz > eppnt->p_memsz ||
59086 - eppnt->p_memsz > TASK_SIZE ||
59087 - TASK_SIZE - eppnt->p_memsz < k) {
59088 + eppnt->p_memsz > pax_task_size ||
59089 + pax_task_size - eppnt->p_memsz < k) {
59090 error = -ENOMEM;
59091 goto out_close;
59092 }
59093 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59094 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59095
59096 /* Map the last of the bss segment */
59097 - error = vm_brk(elf_bss, last_bss - elf_bss);
59098 - if (BAD_ADDR(error))
59099 - goto out_close;
59100 + if (last_bss > elf_bss) {
59101 + error = vm_brk(elf_bss, last_bss - elf_bss);
59102 + if (BAD_ADDR(error))
59103 + goto out_close;
59104 + }
59105 }
59106
59107 error = load_addr;
59108 @@ -543,6 +574,336 @@ out:
59109 return error;
59110 }
59111
59112 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59113 +#ifdef CONFIG_PAX_SOFTMODE
59114 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59115 +{
59116 + unsigned long pax_flags = 0UL;
59117 +
59118 +#ifdef CONFIG_PAX_PAGEEXEC
59119 + if (elf_phdata->p_flags & PF_PAGEEXEC)
59120 + pax_flags |= MF_PAX_PAGEEXEC;
59121 +#endif
59122 +
59123 +#ifdef CONFIG_PAX_SEGMEXEC
59124 + if (elf_phdata->p_flags & PF_SEGMEXEC)
59125 + pax_flags |= MF_PAX_SEGMEXEC;
59126 +#endif
59127 +
59128 +#ifdef CONFIG_PAX_EMUTRAMP
59129 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59130 + pax_flags |= MF_PAX_EMUTRAMP;
59131 +#endif
59132 +
59133 +#ifdef CONFIG_PAX_MPROTECT
59134 + if (elf_phdata->p_flags & PF_MPROTECT)
59135 + pax_flags |= MF_PAX_MPROTECT;
59136 +#endif
59137 +
59138 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59139 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59140 + pax_flags |= MF_PAX_RANDMMAP;
59141 +#endif
59142 +
59143 + return pax_flags;
59144 +}
59145 +#endif
59146 +
59147 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59148 +{
59149 + unsigned long pax_flags = 0UL;
59150 +
59151 +#ifdef CONFIG_PAX_PAGEEXEC
59152 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59153 + pax_flags |= MF_PAX_PAGEEXEC;
59154 +#endif
59155 +
59156 +#ifdef CONFIG_PAX_SEGMEXEC
59157 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59158 + pax_flags |= MF_PAX_SEGMEXEC;
59159 +#endif
59160 +
59161 +#ifdef CONFIG_PAX_EMUTRAMP
59162 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59163 + pax_flags |= MF_PAX_EMUTRAMP;
59164 +#endif
59165 +
59166 +#ifdef CONFIG_PAX_MPROTECT
59167 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59168 + pax_flags |= MF_PAX_MPROTECT;
59169 +#endif
59170 +
59171 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59172 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59173 + pax_flags |= MF_PAX_RANDMMAP;
59174 +#endif
59175 +
59176 + return pax_flags;
59177 +}
59178 +#endif
59179 +
59180 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59181 +#ifdef CONFIG_PAX_SOFTMODE
59182 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59183 +{
59184 + unsigned long pax_flags = 0UL;
59185 +
59186 +#ifdef CONFIG_PAX_PAGEEXEC
59187 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59188 + pax_flags |= MF_PAX_PAGEEXEC;
59189 +#endif
59190 +
59191 +#ifdef CONFIG_PAX_SEGMEXEC
59192 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59193 + pax_flags |= MF_PAX_SEGMEXEC;
59194 +#endif
59195 +
59196 +#ifdef CONFIG_PAX_EMUTRAMP
59197 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59198 + pax_flags |= MF_PAX_EMUTRAMP;
59199 +#endif
59200 +
59201 +#ifdef CONFIG_PAX_MPROTECT
59202 + if (pax_flags_softmode & MF_PAX_MPROTECT)
59203 + pax_flags |= MF_PAX_MPROTECT;
59204 +#endif
59205 +
59206 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59207 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59208 + pax_flags |= MF_PAX_RANDMMAP;
59209 +#endif
59210 +
59211 + return pax_flags;
59212 +}
59213 +#endif
59214 +
59215 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59216 +{
59217 + unsigned long pax_flags = 0UL;
59218 +
59219 +#ifdef CONFIG_PAX_PAGEEXEC
59220 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59221 + pax_flags |= MF_PAX_PAGEEXEC;
59222 +#endif
59223 +
59224 +#ifdef CONFIG_PAX_SEGMEXEC
59225 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59226 + pax_flags |= MF_PAX_SEGMEXEC;
59227 +#endif
59228 +
59229 +#ifdef CONFIG_PAX_EMUTRAMP
59230 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59231 + pax_flags |= MF_PAX_EMUTRAMP;
59232 +#endif
59233 +
59234 +#ifdef CONFIG_PAX_MPROTECT
59235 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59236 + pax_flags |= MF_PAX_MPROTECT;
59237 +#endif
59238 +
59239 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59240 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59241 + pax_flags |= MF_PAX_RANDMMAP;
59242 +#endif
59243 +
59244 + return pax_flags;
59245 +}
59246 +#endif
59247 +
59248 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59249 +static unsigned long pax_parse_defaults(void)
59250 +{
59251 + unsigned long pax_flags = 0UL;
59252 +
59253 +#ifdef CONFIG_PAX_SOFTMODE
59254 + if (pax_softmode)
59255 + return pax_flags;
59256 +#endif
59257 +
59258 +#ifdef CONFIG_PAX_PAGEEXEC
59259 + pax_flags |= MF_PAX_PAGEEXEC;
59260 +#endif
59261 +
59262 +#ifdef CONFIG_PAX_SEGMEXEC
59263 + pax_flags |= MF_PAX_SEGMEXEC;
59264 +#endif
59265 +
59266 +#ifdef CONFIG_PAX_MPROTECT
59267 + pax_flags |= MF_PAX_MPROTECT;
59268 +#endif
59269 +
59270 +#ifdef CONFIG_PAX_RANDMMAP
59271 + if (randomize_va_space)
59272 + pax_flags |= MF_PAX_RANDMMAP;
59273 +#endif
59274 +
59275 + return pax_flags;
59276 +}
59277 +
59278 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59279 +{
59280 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59281 +
59282 +#ifdef CONFIG_PAX_EI_PAX
59283 +
59284 +#ifdef CONFIG_PAX_SOFTMODE
59285 + if (pax_softmode)
59286 + return pax_flags;
59287 +#endif
59288 +
59289 + pax_flags = 0UL;
59290 +
59291 +#ifdef CONFIG_PAX_PAGEEXEC
59292 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59293 + pax_flags |= MF_PAX_PAGEEXEC;
59294 +#endif
59295 +
59296 +#ifdef CONFIG_PAX_SEGMEXEC
59297 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59298 + pax_flags |= MF_PAX_SEGMEXEC;
59299 +#endif
59300 +
59301 +#ifdef CONFIG_PAX_EMUTRAMP
59302 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59303 + pax_flags |= MF_PAX_EMUTRAMP;
59304 +#endif
59305 +
59306 +#ifdef CONFIG_PAX_MPROTECT
59307 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59308 + pax_flags |= MF_PAX_MPROTECT;
59309 +#endif
59310 +
59311 +#ifdef CONFIG_PAX_ASLR
59312 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59313 + pax_flags |= MF_PAX_RANDMMAP;
59314 +#endif
59315 +
59316 +#endif
59317 +
59318 + return pax_flags;
59319 +
59320 +}
59321 +
59322 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59323 +{
59324 +
59325 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59326 + unsigned long i;
59327 +
59328 + for (i = 0UL; i < elf_ex->e_phnum; i++)
59329 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59330 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59331 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59332 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59333 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59334 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59335 + return PAX_PARSE_FLAGS_FALLBACK;
59336 +
59337 +#ifdef CONFIG_PAX_SOFTMODE
59338 + if (pax_softmode)
59339 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59340 + else
59341 +#endif
59342 +
59343 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59344 + break;
59345 + }
59346 +#endif
59347 +
59348 + return PAX_PARSE_FLAGS_FALLBACK;
59349 +}
59350 +
59351 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59352 +{
59353 +
59354 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59355 + ssize_t xattr_size, i;
59356 + unsigned char xattr_value[sizeof("pemrs") - 1];
59357 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59358 +
59359 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59360 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59361 + return PAX_PARSE_FLAGS_FALLBACK;
59362 +
59363 + for (i = 0; i < xattr_size; i++)
59364 + switch (xattr_value[i]) {
59365 + default:
59366 + return PAX_PARSE_FLAGS_FALLBACK;
59367 +
59368 +#define parse_flag(option1, option2, flag) \
59369 + case option1: \
59370 + if (pax_flags_hardmode & MF_PAX_##flag) \
59371 + return PAX_PARSE_FLAGS_FALLBACK;\
59372 + pax_flags_hardmode |= MF_PAX_##flag; \
59373 + break; \
59374 + case option2: \
59375 + if (pax_flags_softmode & MF_PAX_##flag) \
59376 + return PAX_PARSE_FLAGS_FALLBACK;\
59377 + pax_flags_softmode |= MF_PAX_##flag; \
59378 + break;
59379 +
59380 + parse_flag('p', 'P', PAGEEXEC);
59381 + parse_flag('e', 'E', EMUTRAMP);
59382 + parse_flag('m', 'M', MPROTECT);
59383 + parse_flag('r', 'R', RANDMMAP);
59384 + parse_flag('s', 'S', SEGMEXEC);
59385 +
59386 +#undef parse_flag
59387 + }
59388 +
59389 + if (pax_flags_hardmode & pax_flags_softmode)
59390 + return PAX_PARSE_FLAGS_FALLBACK;
59391 +
59392 +#ifdef CONFIG_PAX_SOFTMODE
59393 + if (pax_softmode)
59394 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59395 + else
59396 +#endif
59397 +
59398 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59399 +#else
59400 + return PAX_PARSE_FLAGS_FALLBACK;
59401 +#endif
59402 +
59403 +}
59404 +
59405 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59406 +{
59407 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59408 +
59409 + pax_flags = pax_parse_defaults();
59410 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59411 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59412 + xattr_pax_flags = pax_parse_xattr_pax(file);
59413 +
59414 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59415 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59416 + pt_pax_flags != xattr_pax_flags)
59417 + return -EINVAL;
59418 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59419 + pax_flags = xattr_pax_flags;
59420 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59421 + pax_flags = pt_pax_flags;
59422 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59423 + pax_flags = ei_pax_flags;
59424 +
59425 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59426 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59427 + if ((__supported_pte_mask & _PAGE_NX))
59428 + pax_flags &= ~MF_PAX_SEGMEXEC;
59429 + else
59430 + pax_flags &= ~MF_PAX_PAGEEXEC;
59431 + }
59432 +#endif
59433 +
59434 + if (0 > pax_check_flags(&pax_flags))
59435 + return -EINVAL;
59436 +
59437 + current->mm->pax_flags = pax_flags;
59438 + return 0;
59439 +}
59440 +#endif
59441 +
59442 /*
59443 * These are the functions used to load ELF style executables and shared
59444 * libraries. There is no binary dependent code anywhere else.
59445 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59446 {
59447 unsigned int random_variable = 0;
59448
59449 +#ifdef CONFIG_PAX_RANDUSTACK
59450 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59451 + return stack_top - current->mm->delta_stack;
59452 +#endif
59453 +
59454 if ((current->flags & PF_RANDOMIZE) &&
59455 !(current->personality & ADDR_NO_RANDOMIZE)) {
59456 random_variable = get_random_int() & STACK_RND_MASK;
59457 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59458 unsigned long load_addr = 0, load_bias = 0;
59459 int load_addr_set = 0;
59460 char * elf_interpreter = NULL;
59461 - unsigned long error;
59462 + unsigned long error = 0;
59463 struct elf_phdr *elf_ppnt, *elf_phdata;
59464 unsigned long elf_bss, elf_brk;
59465 int retval, i;
59466 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59467 struct elfhdr elf_ex;
59468 struct elfhdr interp_elf_ex;
59469 } *loc;
59470 + unsigned long pax_task_size;
59471
59472 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59473 if (!loc) {
59474 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59475 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59476 may depend on the personality. */
59477 SET_PERSONALITY(loc->elf_ex);
59478 +
59479 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59480 + current->mm->pax_flags = 0UL;
59481 +#endif
59482 +
59483 +#ifdef CONFIG_PAX_DLRESOLVE
59484 + current->mm->call_dl_resolve = 0UL;
59485 +#endif
59486 +
59487 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59488 + current->mm->call_syscall = 0UL;
59489 +#endif
59490 +
59491 +#ifdef CONFIG_PAX_ASLR
59492 + current->mm->delta_mmap = 0UL;
59493 + current->mm->delta_stack = 0UL;
59494 +#endif
59495 +
59496 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59497 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59498 + send_sig(SIGKILL, current, 0);
59499 + goto out_free_dentry;
59500 + }
59501 +#endif
59502 +
59503 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59504 + pax_set_initial_flags(bprm);
59505 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59506 + if (pax_set_initial_flags_func)
59507 + (pax_set_initial_flags_func)(bprm);
59508 +#endif
59509 +
59510 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59511 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59512 + current->mm->context.user_cs_limit = PAGE_SIZE;
59513 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59514 + }
59515 +#endif
59516 +
59517 +#ifdef CONFIG_PAX_SEGMEXEC
59518 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59519 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59520 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59521 + pax_task_size = SEGMEXEC_TASK_SIZE;
59522 + current->mm->def_flags |= VM_NOHUGEPAGE;
59523 + } else
59524 +#endif
59525 +
59526 + pax_task_size = TASK_SIZE;
59527 +
59528 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59529 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59530 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59531 + put_cpu();
59532 + }
59533 +#endif
59534 +
59535 +#ifdef CONFIG_PAX_ASLR
59536 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59537 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59538 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59539 + }
59540 +#endif
59541 +
59542 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59543 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59544 + executable_stack = EXSTACK_DISABLE_X;
59545 + current->personality &= ~READ_IMPLIES_EXEC;
59546 + } else
59547 +#endif
59548 +
59549 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59550 current->personality |= READ_IMPLIES_EXEC;
59551
59552 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59553 #else
59554 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59555 #endif
59556 +
59557 +#ifdef CONFIG_PAX_RANDMMAP
59558 + /* PaX: randomize base address at the default exe base if requested */
59559 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59560 +#ifdef CONFIG_SPARC64
59561 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59562 +#else
59563 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59564 +#endif
59565 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59566 + elf_flags |= MAP_FIXED;
59567 + }
59568 +#endif
59569 +
59570 }
59571
59572 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59573 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59574 * allowed task size. Note that p_filesz must always be
59575 * <= p_memsz so it is only necessary to check p_memsz.
59576 */
59577 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59578 - elf_ppnt->p_memsz > TASK_SIZE ||
59579 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59580 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59581 + elf_ppnt->p_memsz > pax_task_size ||
59582 + pax_task_size - elf_ppnt->p_memsz < k) {
59583 /* set_brk can never work. Avoid overflows. */
59584 send_sig(SIGKILL, current, 0);
59585 retval = -EINVAL;
59586 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
59587 goto out_free_dentry;
59588 }
59589 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59590 - send_sig(SIGSEGV, current, 0);
59591 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59592 - goto out_free_dentry;
59593 + /*
59594 + * This bss-zeroing can fail if the ELF
59595 + * file specifies odd protections. So
59596 + * we don't check the return value
59597 + */
59598 }
59599
59600 +#ifdef CONFIG_PAX_RANDMMAP
59601 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59602 + unsigned long start, size, flags;
59603 + vm_flags_t vm_flags;
59604 +
59605 + start = ELF_PAGEALIGN(elf_brk);
59606 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59607 + flags = MAP_FIXED | MAP_PRIVATE;
59608 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59609 +
59610 + down_write(&current->mm->mmap_sem);
59611 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59612 + retval = -ENOMEM;
59613 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59614 +// if (current->personality & ADDR_NO_RANDOMIZE)
59615 +// vm_flags |= VM_READ | VM_MAYREAD;
59616 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59617 + retval = IS_ERR_VALUE(start) ? start : 0;
59618 + }
59619 + up_write(&current->mm->mmap_sem);
59620 + if (retval == 0)
59621 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59622 + if (retval < 0) {
59623 + send_sig(SIGKILL, current, 0);
59624 + goto out_free_dentry;
59625 + }
59626 + }
59627 +#endif
59628 +
59629 if (elf_interpreter) {
59630 - unsigned long interp_map_addr = 0;
59631 -
59632 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59633 interpreter,
59634 - &interp_map_addr,
59635 load_bias);
59636 if (!IS_ERR((void *)elf_entry)) {
59637 /*
59638 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59639 * Decide what to dump of a segment, part, all or none.
59640 */
59641 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59642 - unsigned long mm_flags)
59643 + unsigned long mm_flags, long signr)
59644 {
59645 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59646
59647 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59648 if (vma->vm_file == NULL)
59649 return 0;
59650
59651 - if (FILTER(MAPPED_PRIVATE))
59652 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59653 goto whole;
59654
59655 /*
59656 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59657 {
59658 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59659 int i = 0;
59660 - do
59661 + do {
59662 i += 2;
59663 - while (auxv[i - 2] != AT_NULL);
59664 + } while (auxv[i - 2] != AT_NULL);
59665 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59666 }
59667
59668 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59669 {
59670 mm_segment_t old_fs = get_fs();
59671 set_fs(KERNEL_DS);
59672 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59673 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59674 set_fs(old_fs);
59675 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59676 }
59677 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59678 }
59679
59680 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59681 - unsigned long mm_flags)
59682 + struct coredump_params *cprm)
59683 {
59684 struct vm_area_struct *vma;
59685 size_t size = 0;
59686
59687 for (vma = first_vma(current, gate_vma); vma != NULL;
59688 vma = next_vma(vma, gate_vma))
59689 - size += vma_dump_size(vma, mm_flags);
59690 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59691 return size;
59692 }
59693
59694 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59695
59696 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59697
59698 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59699 + offset += elf_core_vma_data_size(gate_vma, cprm);
59700 offset += elf_core_extra_data_size();
59701 e_shoff = offset;
59702
59703 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59704 phdr.p_offset = offset;
59705 phdr.p_vaddr = vma->vm_start;
59706 phdr.p_paddr = 0;
59707 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59708 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59709 phdr.p_memsz = vma->vm_end - vma->vm_start;
59710 offset += phdr.p_filesz;
59711 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59712 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59713 unsigned long addr;
59714 unsigned long end;
59715
59716 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59717 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59718
59719 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59720 struct page *page;
59721 @@ -2210,6 +2690,167 @@ out:
59722
59723 #endif /* CONFIG_ELF_CORE */
59724
59725 +#ifdef CONFIG_PAX_MPROTECT
59726 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59727 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59728 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59729 + *
59730 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59731 + * basis because we want to allow the common case and not the special ones.
59732 + */
59733 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59734 +{
59735 + struct elfhdr elf_h;
59736 + struct elf_phdr elf_p;
59737 + unsigned long i;
59738 + unsigned long oldflags;
59739 + bool is_textrel_rw, is_textrel_rx, is_relro;
59740 +
59741 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59742 + return;
59743 +
59744 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59745 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59746 +
59747 +#ifdef CONFIG_PAX_ELFRELOCS
59748 + /* possible TEXTREL */
59749 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59750 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59751 +#else
59752 + is_textrel_rw = false;
59753 + is_textrel_rx = false;
59754 +#endif
59755 +
59756 + /* possible RELRO */
59757 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59758 +
59759 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59760 + return;
59761 +
59762 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59763 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59764 +
59765 +#ifdef CONFIG_PAX_ETEXECRELOCS
59766 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59767 +#else
59768 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59769 +#endif
59770 +
59771 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59772 + !elf_check_arch(&elf_h) ||
59773 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59774 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59775 + return;
59776 +
59777 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59778 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59779 + return;
59780 + switch (elf_p.p_type) {
59781 + case PT_DYNAMIC:
59782 + if (!is_textrel_rw && !is_textrel_rx)
59783 + continue;
59784 + i = 0UL;
59785 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59786 + elf_dyn dyn;
59787 +
59788 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59789 + break;
59790 + if (dyn.d_tag == DT_NULL)
59791 + break;
59792 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59793 + gr_log_textrel(vma);
59794 + if (is_textrel_rw)
59795 + vma->vm_flags |= VM_MAYWRITE;
59796 + else
59797 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59798 + vma->vm_flags &= ~VM_MAYWRITE;
59799 + break;
59800 + }
59801 + i++;
59802 + }
59803 + is_textrel_rw = false;
59804 + is_textrel_rx = false;
59805 + continue;
59806 +
59807 + case PT_GNU_RELRO:
59808 + if (!is_relro)
59809 + continue;
59810 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59811 + vma->vm_flags &= ~VM_MAYWRITE;
59812 + is_relro = false;
59813 + continue;
59814 +
59815 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59816 + case PT_PAX_FLAGS: {
59817 + const char *msg_mprotect = "", *msg_emutramp = "";
59818 + char *buffer_lib, *buffer_exe;
59819 +
59820 + if (elf_p.p_flags & PF_NOMPROTECT)
59821 + msg_mprotect = "MPROTECT disabled";
59822 +
59823 +#ifdef CONFIG_PAX_EMUTRAMP
59824 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59825 + msg_emutramp = "EMUTRAMP enabled";
59826 +#endif
59827 +
59828 + if (!msg_mprotect[0] && !msg_emutramp[0])
59829 + continue;
59830 +
59831 + if (!printk_ratelimit())
59832 + continue;
59833 +
59834 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59835 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59836 + if (buffer_lib && buffer_exe) {
59837 + char *path_lib, *path_exe;
59838 +
59839 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59840 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59841 +
59842 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59843 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59844 +
59845 + }
59846 + free_page((unsigned long)buffer_exe);
59847 + free_page((unsigned long)buffer_lib);
59848 + continue;
59849 + }
59850 +#endif
59851 +
59852 + }
59853 + }
59854 +}
59855 +#endif
59856 +
59857 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59858 +
59859 +extern int grsec_enable_log_rwxmaps;
59860 +
59861 +static void elf_handle_mmap(struct file *file)
59862 +{
59863 + struct elfhdr elf_h;
59864 + struct elf_phdr elf_p;
59865 + unsigned long i;
59866 +
59867 + if (!grsec_enable_log_rwxmaps)
59868 + return;
59869 +
59870 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59871 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59872 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59873 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59874 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59875 + return;
59876 +
59877 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59878 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59879 + return;
59880 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59881 + gr_log_ptgnustack(file);
59882 + }
59883 +}
59884 +#endif
59885 +
59886 static int __init init_elf_binfmt(void)
59887 {
59888 register_binfmt(&elf_format);
59889 diff --git a/fs/block_dev.c b/fs/block_dev.c
59890 index 6d72746..536d1db 100644
59891 --- a/fs/block_dev.c
59892 +++ b/fs/block_dev.c
59893 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59894 else if (bdev->bd_contains == bdev)
59895 return true; /* is a whole device which isn't held */
59896
59897 - else if (whole->bd_holder == bd_may_claim)
59898 + else if (whole->bd_holder == (void *)bd_may_claim)
59899 return true; /* is a partition of a device that is being partitioned */
59900 else if (whole->bd_holder != NULL)
59901 return false; /* is a partition of a held device */
59902 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59903 index 8bbcc24..6f10d78 100644
59904 --- a/fs/btrfs/ctree.c
59905 +++ b/fs/btrfs/ctree.c
59906 @@ -1174,9 +1174,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59907 free_extent_buffer(buf);
59908 add_root_to_dirty_list(root);
59909 } else {
59910 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59911 - parent_start = parent->start;
59912 - else
59913 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59914 + if (parent)
59915 + parent_start = parent->start;
59916 + else
59917 + parent_start = 0;
59918 + } else
59919 parent_start = 0;
59920
59921 WARN_ON(trans->transid != btrfs_header_generation(parent));
59922 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59923 index a2e90f8..5135e5f 100644
59924 --- a/fs/btrfs/delayed-inode.c
59925 +++ b/fs/btrfs/delayed-inode.c
59926 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59927
59928 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59929 {
59930 - int seq = atomic_inc_return(&delayed_root->items_seq);
59931 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59932 if ((atomic_dec_return(&delayed_root->items) <
59933 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59934 waitqueue_active(&delayed_root->wait))
59935 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59936
59937 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59938 {
59939 - int val = atomic_read(&delayed_root->items_seq);
59940 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59941
59942 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59943 return 1;
59944 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59945 int seq;
59946 int ret;
59947
59948 - seq = atomic_read(&delayed_root->items_seq);
59949 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59950
59951 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59952 if (ret)
59953 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59954 index f70119f..ab5894d 100644
59955 --- a/fs/btrfs/delayed-inode.h
59956 +++ b/fs/btrfs/delayed-inode.h
59957 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59958 */
59959 struct list_head prepare_list;
59960 atomic_t items; /* for delayed items */
59961 - atomic_t items_seq; /* for delayed items */
59962 + atomic_unchecked_t items_seq; /* for delayed items */
59963 int nodes; /* for delayed nodes */
59964 wait_queue_head_t wait;
59965 };
59966 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59967 struct btrfs_delayed_root *delayed_root)
59968 {
59969 atomic_set(&delayed_root->items, 0);
59970 - atomic_set(&delayed_root->items_seq, 0);
59971 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59972 delayed_root->nodes = 0;
59973 spin_lock_init(&delayed_root->lock);
59974 init_waitqueue_head(&delayed_root->wait);
59975 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59976 index b765d41..5a8b0c3 100644
59977 --- a/fs/btrfs/ioctl.c
59978 +++ b/fs/btrfs/ioctl.c
59979 @@ -3975,9 +3975,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59980 for (i = 0; i < num_types; i++) {
59981 struct btrfs_space_info *tmp;
59982
59983 + /* Don't copy in more than we allocated */
59984 if (!slot_count)
59985 break;
59986
59987 + slot_count--;
59988 +
59989 info = NULL;
59990 rcu_read_lock();
59991 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59992 @@ -3999,10 +4002,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59993 memcpy(dest, &space, sizeof(space));
59994 dest++;
59995 space_args.total_spaces++;
59996 - slot_count--;
59997 }
59998 - if (!slot_count)
59999 - break;
60000 }
60001 up_read(&info->groups_sem);
60002 }
60003 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
60004 index c4124de..d7613eb6 100644
60005 --- a/fs/btrfs/super.c
60006 +++ b/fs/btrfs/super.c
60007 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
60008 function, line, errstr);
60009 return;
60010 }
60011 - ACCESS_ONCE(trans->transaction->aborted) = errno;
60012 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
60013 /* Wake up anybody who may be waiting on this transaction */
60014 wake_up(&root->fs_info->transaction_wait);
60015 wake_up(&root->fs_info->transaction_blocked_wait);
60016 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
60017 index 12e5355..cdf30c6 100644
60018 --- a/fs/btrfs/sysfs.c
60019 +++ b/fs/btrfs/sysfs.c
60020 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
60021 for (set = 0; set < FEAT_MAX; set++) {
60022 int i;
60023 struct attribute *attrs[2];
60024 - struct attribute_group agroup = {
60025 + attribute_group_no_const agroup = {
60026 .name = "features",
60027 .attrs = attrs,
60028 };
60029 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
60030 index e2e798a..f454c18 100644
60031 --- a/fs/btrfs/tree-log.h
60032 +++ b/fs/btrfs/tree-log.h
60033 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
60034 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
60035 struct btrfs_trans_handle *trans)
60036 {
60037 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
60038 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
60039 }
60040
60041 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
60042 diff --git a/fs/buffer.c b/fs/buffer.c
60043 index 72daaa5..60ffeb9 100644
60044 --- a/fs/buffer.c
60045 +++ b/fs/buffer.c
60046 @@ -3432,7 +3432,7 @@ void __init buffer_init(void)
60047 bh_cachep = kmem_cache_create("buffer_head",
60048 sizeof(struct buffer_head), 0,
60049 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
60050 - SLAB_MEM_SPREAD),
60051 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
60052 NULL);
60053
60054 /*
60055 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60056 index fbb08e9..0fda764 100644
60057 --- a/fs/cachefiles/bind.c
60058 +++ b/fs/cachefiles/bind.c
60059 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60060 args);
60061
60062 /* start by checking things over */
60063 - ASSERT(cache->fstop_percent >= 0 &&
60064 - cache->fstop_percent < cache->fcull_percent &&
60065 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
60066 cache->fcull_percent < cache->frun_percent &&
60067 cache->frun_percent < 100);
60068
60069 - ASSERT(cache->bstop_percent >= 0 &&
60070 - cache->bstop_percent < cache->bcull_percent &&
60071 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
60072 cache->bcull_percent < cache->brun_percent &&
60073 cache->brun_percent < 100);
60074
60075 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60076 index ce1b115..4a6852c 100644
60077 --- a/fs/cachefiles/daemon.c
60078 +++ b/fs/cachefiles/daemon.c
60079 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60080 if (n > buflen)
60081 return -EMSGSIZE;
60082
60083 - if (copy_to_user(_buffer, buffer, n) != 0)
60084 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60085 return -EFAULT;
60086
60087 return n;
60088 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60089 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60090 return -EIO;
60091
60092 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
60093 + if (datalen > PAGE_SIZE - 1)
60094 return -EOPNOTSUPP;
60095
60096 /* drag the command string into the kernel so we can parse it */
60097 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60098 if (args[0] != '%' || args[1] != '\0')
60099 return -EINVAL;
60100
60101 - if (fstop < 0 || fstop >= cache->fcull_percent)
60102 + if (fstop >= cache->fcull_percent)
60103 return cachefiles_daemon_range_error(cache, args);
60104
60105 cache->fstop_percent = fstop;
60106 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60107 if (args[0] != '%' || args[1] != '\0')
60108 return -EINVAL;
60109
60110 - if (bstop < 0 || bstop >= cache->bcull_percent)
60111 + if (bstop >= cache->bcull_percent)
60112 return cachefiles_daemon_range_error(cache, args);
60113
60114 cache->bstop_percent = bstop;
60115 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60116 index 8c52472..c4e3a69 100644
60117 --- a/fs/cachefiles/internal.h
60118 +++ b/fs/cachefiles/internal.h
60119 @@ -66,7 +66,7 @@ struct cachefiles_cache {
60120 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60121 struct rb_root active_nodes; /* active nodes (can't be culled) */
60122 rwlock_t active_lock; /* lock for active_nodes */
60123 - atomic_t gravecounter; /* graveyard uniquifier */
60124 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60125 unsigned frun_percent; /* when to stop culling (% files) */
60126 unsigned fcull_percent; /* when to start culling (% files) */
60127 unsigned fstop_percent; /* when to stop allocating (% files) */
60128 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60129 * proc.c
60130 */
60131 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60132 -extern atomic_t cachefiles_lookup_histogram[HZ];
60133 -extern atomic_t cachefiles_mkdir_histogram[HZ];
60134 -extern atomic_t cachefiles_create_histogram[HZ];
60135 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60136 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60137 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60138
60139 extern int __init cachefiles_proc_init(void);
60140 extern void cachefiles_proc_cleanup(void);
60141 static inline
60142 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60143 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60144 {
60145 unsigned long jif = jiffies - start_jif;
60146 if (jif >= HZ)
60147 jif = HZ - 1;
60148 - atomic_inc(&histogram[jif]);
60149 + atomic_inc_unchecked(&histogram[jif]);
60150 }
60151
60152 #else
60153 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60154 index dad7d95..07475af 100644
60155 --- a/fs/cachefiles/namei.c
60156 +++ b/fs/cachefiles/namei.c
60157 @@ -312,7 +312,7 @@ try_again:
60158 /* first step is to make up a grave dentry in the graveyard */
60159 sprintf(nbuffer, "%08x%08x",
60160 (uint32_t) get_seconds(),
60161 - (uint32_t) atomic_inc_return(&cache->gravecounter));
60162 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60163
60164 /* do the multiway lock magic */
60165 trap = lock_rename(cache->graveyard, dir);
60166 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60167 index eccd339..4c1d995 100644
60168 --- a/fs/cachefiles/proc.c
60169 +++ b/fs/cachefiles/proc.c
60170 @@ -14,9 +14,9 @@
60171 #include <linux/seq_file.h>
60172 #include "internal.h"
60173
60174 -atomic_t cachefiles_lookup_histogram[HZ];
60175 -atomic_t cachefiles_mkdir_histogram[HZ];
60176 -atomic_t cachefiles_create_histogram[HZ];
60177 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60178 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60179 +atomic_unchecked_t cachefiles_create_histogram[HZ];
60180
60181 /*
60182 * display the latency histogram
60183 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60184 return 0;
60185 default:
60186 index = (unsigned long) v - 3;
60187 - x = atomic_read(&cachefiles_lookup_histogram[index]);
60188 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
60189 - z = atomic_read(&cachefiles_create_histogram[index]);
60190 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60191 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60192 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60193 if (x == 0 && y == 0 && z == 0)
60194 return 0;
60195
60196 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60197 index 25e745b..220e604 100644
60198 --- a/fs/cachefiles/rdwr.c
60199 +++ b/fs/cachefiles/rdwr.c
60200 @@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60201 old_fs = get_fs();
60202 set_fs(KERNEL_DS);
60203 ret = file->f_op->write(
60204 - file, (const void __user *) data, len, &pos);
60205 + file, (const void __force_user *) data, len, &pos);
60206 set_fs(old_fs);
60207 kunmap(page);
60208 file_end_write(file);
60209 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60210 index c29d6ae..719b9bb 100644
60211 --- a/fs/ceph/dir.c
60212 +++ b/fs/ceph/dir.c
60213 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60214 struct dentry *dentry, *last;
60215 struct ceph_dentry_info *di;
60216 int err = 0;
60217 + char d_name[DNAME_INLINE_LEN];
60218 + const unsigned char *name;
60219
60220 /* claim ref on last dentry we returned */
60221 last = fi->dentry;
60222 @@ -192,7 +194,12 @@ more:
60223
60224 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60225 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60226 - if (!dir_emit(ctx, dentry->d_name.name,
60227 + name = dentry->d_name.name;
60228 + if (name == dentry->d_iname) {
60229 + memcpy(d_name, name, dentry->d_name.len);
60230 + name = d_name;
60231 + }
60232 + if (!dir_emit(ctx, name,
60233 dentry->d_name.len,
60234 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60235 dentry->d_inode->i_mode >> 12)) {
60236 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60237 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60238 struct ceph_mds_client *mdsc = fsc->mdsc;
60239 unsigned frag = fpos_frag(ctx->pos);
60240 - int off = fpos_off(ctx->pos);
60241 + unsigned int off = fpos_off(ctx->pos);
60242 int err;
60243 u32 ftype;
60244 struct ceph_mds_reply_info_parsed *rinfo;
60245 diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
60246 index a822a6e..4644256 100644
60247 --- a/fs/ceph/ioctl.c
60248 +++ b/fs/ceph/ioctl.c
60249 @@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
60250 /* validate striping parameters */
60251 if ((l->object_size & ~PAGE_MASK) ||
60252 (l->stripe_unit & ~PAGE_MASK) ||
60253 - (l->stripe_unit != 0 &&
60254 + ((unsigned)l->stripe_unit != 0 &&
60255 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
60256 return -EINVAL;
60257
60258 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60259 index f6e1237..796ffd1 100644
60260 --- a/fs/ceph/super.c
60261 +++ b/fs/ceph/super.c
60262 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60263 /*
60264 * construct our own bdi so we can control readahead, etc.
60265 */
60266 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60267 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60268
60269 static int ceph_register_bdi(struct super_block *sb,
60270 struct ceph_fs_client *fsc)
60271 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60272 default_backing_dev_info.ra_pages;
60273
60274 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60275 - atomic_long_inc_return(&bdi_seq));
60276 + atomic_long_inc_return_unchecked(&bdi_seq));
60277 if (!err)
60278 sb->s_bdi = &fsc->backing_dev_info;
60279 return err;
60280 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60281 index 44ec726..bcb06a3 100644
60282 --- a/fs/cifs/cifs_debug.c
60283 +++ b/fs/cifs/cifs_debug.c
60284 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60285
60286 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60287 #ifdef CONFIG_CIFS_STATS2
60288 - atomic_set(&totBufAllocCount, 0);
60289 - atomic_set(&totSmBufAllocCount, 0);
60290 + atomic_set_unchecked(&totBufAllocCount, 0);
60291 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60292 #endif /* CONFIG_CIFS_STATS2 */
60293 spin_lock(&cifs_tcp_ses_lock);
60294 list_for_each(tmp1, &cifs_tcp_ses_list) {
60295 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60296 tcon = list_entry(tmp3,
60297 struct cifs_tcon,
60298 tcon_list);
60299 - atomic_set(&tcon->num_smbs_sent, 0);
60300 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60301 if (server->ops->clear_stats)
60302 server->ops->clear_stats(tcon);
60303 }
60304 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60305 smBufAllocCount.counter, cifs_min_small);
60306 #ifdef CONFIG_CIFS_STATS2
60307 seq_printf(m, "Total Large %d Small %d Allocations\n",
60308 - atomic_read(&totBufAllocCount),
60309 - atomic_read(&totSmBufAllocCount));
60310 + atomic_read_unchecked(&totBufAllocCount),
60311 + atomic_read_unchecked(&totSmBufAllocCount));
60312 #endif /* CONFIG_CIFS_STATS2 */
60313
60314 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60315 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60316 if (tcon->need_reconnect)
60317 seq_puts(m, "\tDISCONNECTED ");
60318 seq_printf(m, "\nSMBs: %d",
60319 - atomic_read(&tcon->num_smbs_sent));
60320 + atomic_read_unchecked(&tcon->num_smbs_sent));
60321 if (server->ops->print_stats)
60322 server->ops->print_stats(m, tcon);
60323 }
60324 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60325 index 889b984..fcb8431 100644
60326 --- a/fs/cifs/cifsfs.c
60327 +++ b/fs/cifs/cifsfs.c
60328 @@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
60329 */
60330 cifs_req_cachep = kmem_cache_create("cifs_request",
60331 CIFSMaxBufSize + max_hdr_size, 0,
60332 - SLAB_HWCACHE_ALIGN, NULL);
60333 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60334 if (cifs_req_cachep == NULL)
60335 return -ENOMEM;
60336
60337 @@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
60338 efficient to alloc 1 per page off the slab compared to 17K (5page)
60339 alloc of large cifs buffers even when page debugging is on */
60340 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60341 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60342 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60343 NULL);
60344 if (cifs_sm_req_cachep == NULL) {
60345 mempool_destroy(cifs_req_poolp);
60346 @@ -1204,8 +1204,8 @@ init_cifs(void)
60347 atomic_set(&bufAllocCount, 0);
60348 atomic_set(&smBufAllocCount, 0);
60349 #ifdef CONFIG_CIFS_STATS2
60350 - atomic_set(&totBufAllocCount, 0);
60351 - atomic_set(&totSmBufAllocCount, 0);
60352 + atomic_set_unchecked(&totBufAllocCount, 0);
60353 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60354 #endif /* CONFIG_CIFS_STATS2 */
60355
60356 atomic_set(&midCount, 0);
60357 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60358 index 25b8392..01e46dc 100644
60359 --- a/fs/cifs/cifsglob.h
60360 +++ b/fs/cifs/cifsglob.h
60361 @@ -821,35 +821,35 @@ struct cifs_tcon {
60362 __u16 Flags; /* optional support bits */
60363 enum statusEnum tidStatus;
60364 #ifdef CONFIG_CIFS_STATS
60365 - atomic_t num_smbs_sent;
60366 + atomic_unchecked_t num_smbs_sent;
60367 union {
60368 struct {
60369 - atomic_t num_writes;
60370 - atomic_t num_reads;
60371 - atomic_t num_flushes;
60372 - atomic_t num_oplock_brks;
60373 - atomic_t num_opens;
60374 - atomic_t num_closes;
60375 - atomic_t num_deletes;
60376 - atomic_t num_mkdirs;
60377 - atomic_t num_posixopens;
60378 - atomic_t num_posixmkdirs;
60379 - atomic_t num_rmdirs;
60380 - atomic_t num_renames;
60381 - atomic_t num_t2renames;
60382 - atomic_t num_ffirst;
60383 - atomic_t num_fnext;
60384 - atomic_t num_fclose;
60385 - atomic_t num_hardlinks;
60386 - atomic_t num_symlinks;
60387 - atomic_t num_locks;
60388 - atomic_t num_acl_get;
60389 - atomic_t num_acl_set;
60390 + atomic_unchecked_t num_writes;
60391 + atomic_unchecked_t num_reads;
60392 + atomic_unchecked_t num_flushes;
60393 + atomic_unchecked_t num_oplock_brks;
60394 + atomic_unchecked_t num_opens;
60395 + atomic_unchecked_t num_closes;
60396 + atomic_unchecked_t num_deletes;
60397 + atomic_unchecked_t num_mkdirs;
60398 + atomic_unchecked_t num_posixopens;
60399 + atomic_unchecked_t num_posixmkdirs;
60400 + atomic_unchecked_t num_rmdirs;
60401 + atomic_unchecked_t num_renames;
60402 + atomic_unchecked_t num_t2renames;
60403 + atomic_unchecked_t num_ffirst;
60404 + atomic_unchecked_t num_fnext;
60405 + atomic_unchecked_t num_fclose;
60406 + atomic_unchecked_t num_hardlinks;
60407 + atomic_unchecked_t num_symlinks;
60408 + atomic_unchecked_t num_locks;
60409 + atomic_unchecked_t num_acl_get;
60410 + atomic_unchecked_t num_acl_set;
60411 } cifs_stats;
60412 #ifdef CONFIG_CIFS_SMB2
60413 struct {
60414 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60415 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60416 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60417 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60418 } smb2_stats;
60419 #endif /* CONFIG_CIFS_SMB2 */
60420 } stats;
60421 @@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60422 }
60423
60424 #ifdef CONFIG_CIFS_STATS
60425 -#define cifs_stats_inc atomic_inc
60426 +#define cifs_stats_inc atomic_inc_unchecked
60427
60428 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60429 unsigned int bytes)
60430 @@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60431 /* Various Debug counters */
60432 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60433 #ifdef CONFIG_CIFS_STATS2
60434 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60435 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60436 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60437 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60438 #endif
60439 GLOBAL_EXTERN atomic_t smBufAllocCount;
60440 GLOBAL_EXTERN atomic_t midCount;
60441 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60442 index 5f29354..359bc0d 100644
60443 --- a/fs/cifs/file.c
60444 +++ b/fs/cifs/file.c
60445 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60446 index = mapping->writeback_index; /* Start from prev offset */
60447 end = -1;
60448 } else {
60449 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60450 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60451 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60452 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60453 range_whole = true;
60454 + index = 0;
60455 + end = ULONG_MAX;
60456 + } else {
60457 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60458 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60459 + }
60460 scanned = true;
60461 }
60462 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60463 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60464 index b7415d5..3984ec0 100644
60465 --- a/fs/cifs/misc.c
60466 +++ b/fs/cifs/misc.c
60467 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60468 memset(ret_buf, 0, buf_size + 3);
60469 atomic_inc(&bufAllocCount);
60470 #ifdef CONFIG_CIFS_STATS2
60471 - atomic_inc(&totBufAllocCount);
60472 + atomic_inc_unchecked(&totBufAllocCount);
60473 #endif /* CONFIG_CIFS_STATS2 */
60474 }
60475
60476 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60477 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60478 atomic_inc(&smBufAllocCount);
60479 #ifdef CONFIG_CIFS_STATS2
60480 - atomic_inc(&totSmBufAllocCount);
60481 + atomic_inc_unchecked(&totSmBufAllocCount);
60482 #endif /* CONFIG_CIFS_STATS2 */
60483
60484 }
60485 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60486 index 52131d8..fd79e97 100644
60487 --- a/fs/cifs/smb1ops.c
60488 +++ b/fs/cifs/smb1ops.c
60489 @@ -626,27 +626,27 @@ static void
60490 cifs_clear_stats(struct cifs_tcon *tcon)
60491 {
60492 #ifdef CONFIG_CIFS_STATS
60493 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60494 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60495 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60496 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60497 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60498 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60499 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60500 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60501 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60502 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60503 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60504 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60505 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60506 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60507 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60508 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60509 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60510 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60511 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60512 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60513 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60514 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60515 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60516 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60517 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60518 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60519 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60520 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60521 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60522 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60523 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60524 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60525 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60526 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60527 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60528 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60529 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60530 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60531 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60532 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60533 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60534 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60535 #endif
60536 }
60537
60538 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60539 {
60540 #ifdef CONFIG_CIFS_STATS
60541 seq_printf(m, " Oplocks breaks: %d",
60542 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60543 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60544 seq_printf(m, "\nReads: %d Bytes: %llu",
60545 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60546 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60547 (long long)(tcon->bytes_read));
60548 seq_printf(m, "\nWrites: %d Bytes: %llu",
60549 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60550 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60551 (long long)(tcon->bytes_written));
60552 seq_printf(m, "\nFlushes: %d",
60553 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60554 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60555 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60556 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60557 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60558 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60559 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60560 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60561 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60562 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60563 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60564 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60565 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60566 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60567 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60568 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60569 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60570 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60571 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60572 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60573 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60574 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60575 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60576 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60577 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60578 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60579 seq_printf(m, "\nRenames: %d T2 Renames %d",
60580 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60581 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60582 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60583 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60584 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60585 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60586 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60587 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60588 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60589 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60590 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60591 #endif
60592 }
60593
60594 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60595 index f522193..586121b 100644
60596 --- a/fs/cifs/smb2ops.c
60597 +++ b/fs/cifs/smb2ops.c
60598 @@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60599 #ifdef CONFIG_CIFS_STATS
60600 int i;
60601 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60602 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60603 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60604 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60605 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60606 }
60607 #endif
60608 }
60609 @@ -455,65 +455,65 @@ static void
60610 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60611 {
60612 #ifdef CONFIG_CIFS_STATS
60613 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60614 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60615 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60616 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60617 seq_printf(m, "\nNegotiates: %d sent %d failed",
60618 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60619 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60620 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60621 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60622 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60623 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60624 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60625 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60626 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60627 seq_printf(m, "\nLogoffs: %d sent %d failed",
60628 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60629 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60630 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60631 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60632 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60633 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60634 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60635 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60636 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60637 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60638 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60639 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60640 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60641 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60642 seq_printf(m, "\nCreates: %d sent %d failed",
60643 - atomic_read(&sent[SMB2_CREATE_HE]),
60644 - atomic_read(&failed[SMB2_CREATE_HE]));
60645 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60646 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60647 seq_printf(m, "\nCloses: %d sent %d failed",
60648 - atomic_read(&sent[SMB2_CLOSE_HE]),
60649 - atomic_read(&failed[SMB2_CLOSE_HE]));
60650 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60651 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60652 seq_printf(m, "\nFlushes: %d sent %d failed",
60653 - atomic_read(&sent[SMB2_FLUSH_HE]),
60654 - atomic_read(&failed[SMB2_FLUSH_HE]));
60655 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60656 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60657 seq_printf(m, "\nReads: %d sent %d failed",
60658 - atomic_read(&sent[SMB2_READ_HE]),
60659 - atomic_read(&failed[SMB2_READ_HE]));
60660 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60661 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60662 seq_printf(m, "\nWrites: %d sent %d failed",
60663 - atomic_read(&sent[SMB2_WRITE_HE]),
60664 - atomic_read(&failed[SMB2_WRITE_HE]));
60665 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60666 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60667 seq_printf(m, "\nLocks: %d sent %d failed",
60668 - atomic_read(&sent[SMB2_LOCK_HE]),
60669 - atomic_read(&failed[SMB2_LOCK_HE]));
60670 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60671 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60672 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60673 - atomic_read(&sent[SMB2_IOCTL_HE]),
60674 - atomic_read(&failed[SMB2_IOCTL_HE]));
60675 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60676 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60677 seq_printf(m, "\nCancels: %d sent %d failed",
60678 - atomic_read(&sent[SMB2_CANCEL_HE]),
60679 - atomic_read(&failed[SMB2_CANCEL_HE]));
60680 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60681 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60682 seq_printf(m, "\nEchos: %d sent %d failed",
60683 - atomic_read(&sent[SMB2_ECHO_HE]),
60684 - atomic_read(&failed[SMB2_ECHO_HE]));
60685 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60686 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60687 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60688 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60689 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60690 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60691 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60692 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60693 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60694 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60695 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60696 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60697 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60698 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60699 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60700 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60701 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60702 seq_printf(m, "\nSetInfos: %d sent %d failed",
60703 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60704 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60705 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60706 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60707 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60708 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60709 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60710 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60711 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60712 #endif
60713 }
60714
60715 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60716 index 74b3a66..0c709f3 100644
60717 --- a/fs/cifs/smb2pdu.c
60718 +++ b/fs/cifs/smb2pdu.c
60719 @@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60720 default:
60721 cifs_dbg(VFS, "info level %u isn't supported\n",
60722 srch_inf->info_level);
60723 - rc = -EINVAL;
60724 - goto qdir_exit;
60725 + return -EINVAL;
60726 }
60727
60728 req->FileIndex = cpu_to_le32(index);
60729 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60730 index 278f8fd..e69c52d 100644
60731 --- a/fs/coda/cache.c
60732 +++ b/fs/coda/cache.c
60733 @@ -24,7 +24,7 @@
60734 #include "coda_linux.h"
60735 #include "coda_cache.h"
60736
60737 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60738 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60739
60740 /* replace or extend an acl cache hit */
60741 void coda_cache_enter(struct inode *inode, int mask)
60742 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60743 struct coda_inode_info *cii = ITOC(inode);
60744
60745 spin_lock(&cii->c_lock);
60746 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60747 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60748 if (!uid_eq(cii->c_uid, current_fsuid())) {
60749 cii->c_uid = current_fsuid();
60750 cii->c_cached_perm = mask;
60751 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60752 {
60753 struct coda_inode_info *cii = ITOC(inode);
60754 spin_lock(&cii->c_lock);
60755 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60756 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60757 spin_unlock(&cii->c_lock);
60758 }
60759
60760 /* remove all acl caches */
60761 void coda_cache_clear_all(struct super_block *sb)
60762 {
60763 - atomic_inc(&permission_epoch);
60764 + atomic_inc_unchecked(&permission_epoch);
60765 }
60766
60767
60768 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60769 spin_lock(&cii->c_lock);
60770 hit = (mask & cii->c_cached_perm) == mask &&
60771 uid_eq(cii->c_uid, current_fsuid()) &&
60772 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60773 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60774 spin_unlock(&cii->c_lock);
60775
60776 return hit;
60777 diff --git a/fs/compat.c b/fs/compat.c
60778 index 66d3d3c..9c10175 100644
60779 --- a/fs/compat.c
60780 +++ b/fs/compat.c
60781 @@ -54,7 +54,7 @@
60782 #include <asm/ioctls.h>
60783 #include "internal.h"
60784
60785 -int compat_log = 1;
60786 +int compat_log = 0;
60787
60788 int compat_printk(const char *fmt, ...)
60789 {
60790 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60791
60792 set_fs(KERNEL_DS);
60793 /* The __user pointer cast is valid because of the set_fs() */
60794 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60795 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60796 set_fs(oldfs);
60797 /* truncating is ok because it's a user address */
60798 if (!ret)
60799 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60800 goto out;
60801
60802 ret = -EINVAL;
60803 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60804 + if (nr_segs > UIO_MAXIOV)
60805 goto out;
60806 if (nr_segs > fast_segs) {
60807 ret = -ENOMEM;
60808 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
60809 struct compat_readdir_callback {
60810 struct dir_context ctx;
60811 struct compat_old_linux_dirent __user *dirent;
60812 + struct file * file;
60813 int result;
60814 };
60815
60816 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60817 buf->result = -EOVERFLOW;
60818 return -EOVERFLOW;
60819 }
60820 +
60821 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60822 + return 0;
60823 +
60824 buf->result++;
60825 dirent = buf->dirent;
60826 if (!access_ok(VERIFY_WRITE, dirent,
60827 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60828 if (!f.file)
60829 return -EBADF;
60830
60831 + buf.file = f.file;
60832 error = iterate_dir(f.file, &buf.ctx);
60833 if (buf.result)
60834 error = buf.result;
60835 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
60836 struct dir_context ctx;
60837 struct compat_linux_dirent __user *current_dir;
60838 struct compat_linux_dirent __user *previous;
60839 + struct file * file;
60840 int count;
60841 int error;
60842 };
60843 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60844 buf->error = -EOVERFLOW;
60845 return -EOVERFLOW;
60846 }
60847 +
60848 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60849 + return 0;
60850 +
60851 dirent = buf->previous;
60852 if (dirent) {
60853 if (__put_user(offset, &dirent->d_off))
60854 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60855 if (!f.file)
60856 return -EBADF;
60857
60858 + buf.file = f.file;
60859 error = iterate_dir(f.file, &buf.ctx);
60860 if (error >= 0)
60861 error = buf.error;
60862 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
60863 struct dir_context ctx;
60864 struct linux_dirent64 __user *current_dir;
60865 struct linux_dirent64 __user *previous;
60866 + struct file * file;
60867 int count;
60868 int error;
60869 };
60870 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60871 buf->error = -EINVAL; /* only used if we fail.. */
60872 if (reclen > buf->count)
60873 return -EINVAL;
60874 +
60875 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60876 + return 0;
60877 +
60878 dirent = buf->previous;
60879
60880 if (dirent) {
60881 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60882 if (!f.file)
60883 return -EBADF;
60884
60885 + buf.file = f.file;
60886 error = iterate_dir(f.file, &buf.ctx);
60887 if (error >= 0)
60888 error = buf.error;
60889 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60890 index 4d24d17..4f8c09e 100644
60891 --- a/fs/compat_binfmt_elf.c
60892 +++ b/fs/compat_binfmt_elf.c
60893 @@ -30,11 +30,13 @@
60894 #undef elf_phdr
60895 #undef elf_shdr
60896 #undef elf_note
60897 +#undef elf_dyn
60898 #undef elf_addr_t
60899 #define elfhdr elf32_hdr
60900 #define elf_phdr elf32_phdr
60901 #define elf_shdr elf32_shdr
60902 #define elf_note elf32_note
60903 +#define elf_dyn Elf32_Dyn
60904 #define elf_addr_t Elf32_Addr
60905
60906 /*
60907 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60908 index afec645..9c65620 100644
60909 --- a/fs/compat_ioctl.c
60910 +++ b/fs/compat_ioctl.c
60911 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60912 return -EFAULT;
60913 if (__get_user(udata, &ss32->iomem_base))
60914 return -EFAULT;
60915 - ss.iomem_base = compat_ptr(udata);
60916 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60917 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60918 __get_user(ss.port_high, &ss32->port_high))
60919 return -EFAULT;
60920 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60921 for (i = 0; i < nmsgs; i++) {
60922 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60923 return -EFAULT;
60924 - if (get_user(datap, &umsgs[i].buf) ||
60925 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60926 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60927 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60928 return -EFAULT;
60929 }
60930 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60931 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60932 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60933 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60934 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60935 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60936 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60937 return -EFAULT;
60938
60939 return ioctl_preallocate(file, p);
60940 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60941 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60942 {
60943 unsigned int a, b;
60944 - a = *(unsigned int *)p;
60945 - b = *(unsigned int *)q;
60946 + a = *(const unsigned int *)p;
60947 + b = *(const unsigned int *)q;
60948 if (a > b)
60949 return 1;
60950 if (a < b)
60951 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60952 index 668dcab..daebcd6 100644
60953 --- a/fs/configfs/dir.c
60954 +++ b/fs/configfs/dir.c
60955 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60956 }
60957 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60958 struct configfs_dirent *next;
60959 - const char *name;
60960 + const unsigned char * name;
60961 + char d_name[sizeof(next->s_dentry->d_iname)];
60962 int len;
60963 struct inode *inode = NULL;
60964
60965 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60966 continue;
60967
60968 name = configfs_get_name(next);
60969 - len = strlen(name);
60970 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60971 + len = next->s_dentry->d_name.len;
60972 + memcpy(d_name, name, len);
60973 + name = d_name;
60974 + } else
60975 + len = strlen(name);
60976
60977 /*
60978 * We'll have a dentry and an inode for
60979 diff --git a/fs/coredump.c b/fs/coredump.c
60980 index a93f7e6..d58bcbe 100644
60981 --- a/fs/coredump.c
60982 +++ b/fs/coredump.c
60983 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
60984 struct pipe_inode_info *pipe = file->private_data;
60985
60986 pipe_lock(pipe);
60987 - pipe->readers++;
60988 - pipe->writers--;
60989 + atomic_inc(&pipe->readers);
60990 + atomic_dec(&pipe->writers);
60991 wake_up_interruptible_sync(&pipe->wait);
60992 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60993 pipe_unlock(pipe);
60994 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
60995 * We actually want wait_event_freezable() but then we need
60996 * to clear TIF_SIGPENDING and improve dump_interrupted().
60997 */
60998 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60999 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
61000
61001 pipe_lock(pipe);
61002 - pipe->readers--;
61003 - pipe->writers++;
61004 + atomic_dec(&pipe->readers);
61005 + atomic_inc(&pipe->writers);
61006 pipe_unlock(pipe);
61007 }
61008
61009 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
61010 struct files_struct *displaced;
61011 bool need_nonrelative = false;
61012 bool core_dumped = false;
61013 - static atomic_t core_dump_count = ATOMIC_INIT(0);
61014 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
61015 + long signr = siginfo->si_signo;
61016 + int dumpable;
61017 struct coredump_params cprm = {
61018 .siginfo = siginfo,
61019 .regs = signal_pt_regs(),
61020 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
61021 .mm_flags = mm->flags,
61022 };
61023
61024 - audit_core_dumps(siginfo->si_signo);
61025 + audit_core_dumps(signr);
61026 +
61027 + dumpable = __get_dumpable(cprm.mm_flags);
61028 +
61029 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
61030 + gr_handle_brute_attach(dumpable);
61031
61032 binfmt = mm->binfmt;
61033 if (!binfmt || !binfmt->core_dump)
61034 goto fail;
61035 - if (!__get_dumpable(cprm.mm_flags))
61036 + if (!dumpable)
61037 goto fail;
61038
61039 cred = prepare_creds();
61040 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
61041 need_nonrelative = true;
61042 }
61043
61044 - retval = coredump_wait(siginfo->si_signo, &core_state);
61045 + retval = coredump_wait(signr, &core_state);
61046 if (retval < 0)
61047 goto fail_creds;
61048
61049 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
61050 }
61051 cprm.limit = RLIM_INFINITY;
61052
61053 - dump_count = atomic_inc_return(&core_dump_count);
61054 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
61055 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61056 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61057 task_tgid_vnr(current), current->comm);
61058 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61059 } else {
61060 struct inode *inode;
61061
61062 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61063 +
61064 if (cprm.limit < binfmt->min_coredump)
61065 goto fail_unlock;
61066
61067 @@ -673,7 +682,7 @@ close_fail:
61068 filp_close(cprm.file, NULL);
61069 fail_dropcount:
61070 if (ispipe)
61071 - atomic_dec(&core_dump_count);
61072 + atomic_dec_unchecked(&core_dump_count);
61073 fail_unlock:
61074 kfree(cn.corename);
61075 coredump_finish(mm, core_dumped);
61076 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61077 struct file *file = cprm->file;
61078 loff_t pos = file->f_pos;
61079 ssize_t n;
61080 +
61081 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61082 if (cprm->written + nr > cprm->limit)
61083 return 0;
61084 while (nr) {
61085 diff --git a/fs/dcache.c b/fs/dcache.c
61086 index 34b40be8..2003532 100644
61087 --- a/fs/dcache.c
61088 +++ b/fs/dcache.c
61089 @@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
61090 * dentry_iput drops the locks, at which point nobody (except
61091 * transient RCU lookups) can reach this dentry.
61092 */
61093 - BUG_ON((int)dentry->d_lockref.count > 0);
61094 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
61095 this_cpu_dec(nr_dentry);
61096 if (dentry->d_op && dentry->d_op->d_release)
61097 dentry->d_op->d_release(dentry);
61098 @@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
61099 struct dentry *parent = dentry->d_parent;
61100 if (IS_ROOT(dentry))
61101 return NULL;
61102 - if (unlikely((int)dentry->d_lockref.count < 0))
61103 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
61104 return NULL;
61105 if (likely(spin_trylock(&parent->d_lock)))
61106 return parent;
61107 @@ -608,7 +608,7 @@ repeat:
61108 dentry->d_flags |= DCACHE_REFERENCED;
61109 dentry_lru_add(dentry);
61110
61111 - dentry->d_lockref.count--;
61112 + __lockref_dec(&dentry->d_lockref);
61113 spin_unlock(&dentry->d_lock);
61114 return;
61115
61116 @@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
61117 * We also need to leave mountpoints alone,
61118 * directory or not.
61119 */
61120 - if (dentry->d_lockref.count > 1 && dentry->d_inode) {
61121 + if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
61122 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
61123 spin_unlock(&dentry->d_lock);
61124 return -EBUSY;
61125 @@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
61126 /* This must be called with d_lock held */
61127 static inline void __dget_dlock(struct dentry *dentry)
61128 {
61129 - dentry->d_lockref.count++;
61130 + __lockref_inc(&dentry->d_lockref);
61131 }
61132
61133 static inline void __dget(struct dentry *dentry)
61134 @@ -720,8 +720,8 @@ repeat:
61135 goto repeat;
61136 }
61137 rcu_read_unlock();
61138 - BUG_ON(!ret->d_lockref.count);
61139 - ret->d_lockref.count++;
61140 + BUG_ON(!__lockref_read(&ret->d_lockref));
61141 + __lockref_inc(&ret->d_lockref);
61142 spin_unlock(&ret->d_lock);
61143 return ret;
61144 }
61145 @@ -798,7 +798,7 @@ restart:
61146 spin_lock(&inode->i_lock);
61147 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
61148 spin_lock(&dentry->d_lock);
61149 - if (!dentry->d_lockref.count) {
61150 + if (!__lockref_read(&dentry->d_lockref)) {
61151 /*
61152 * inform the fs via d_prune that this dentry
61153 * is about to be unhashed and destroyed.
61154 @@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
61155 * We found an inuse dentry which was not removed from
61156 * the LRU because of laziness during lookup. Do not free it.
61157 */
61158 - if ((int)dentry->d_lockref.count > 0) {
61159 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
61160 spin_unlock(&dentry->d_lock);
61161 if (parent)
61162 spin_unlock(&parent->d_lock);
61163 @@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
61164 dentry = parent;
61165 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
61166 parent = lock_parent(dentry);
61167 - if (dentry->d_lockref.count != 1) {
61168 - dentry->d_lockref.count--;
61169 + if (__lockref_read(&dentry->d_lockref) != 1) {
61170 + __lockref_inc(&dentry->d_lockref);
61171 spin_unlock(&dentry->d_lock);
61172 if (parent)
61173 spin_unlock(&parent->d_lock);
61174 @@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
61175 * counts, just remove them from the LRU. Otherwise give them
61176 * another pass through the LRU.
61177 */
61178 - if (dentry->d_lockref.count) {
61179 + if (__lockref_read(&dentry->d_lockref) > 0) {
61180 d_lru_isolate(dentry);
61181 spin_unlock(&dentry->d_lock);
61182 return LRU_REMOVED;
61183 @@ -1149,6 +1149,7 @@ out_unlock:
61184 return;
61185
61186 rename_retry:
61187 + done_seqretry(&rename_lock, seq);
61188 if (!retry)
61189 return;
61190 seq = 1;
61191 @@ -1255,7 +1256,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
61192 } else {
61193 if (dentry->d_flags & DCACHE_LRU_LIST)
61194 d_lru_del(dentry);
61195 - if (!dentry->d_lockref.count) {
61196 + if (!__lockref_read(&dentry->d_lockref)) {
61197 d_shrink_add(dentry, &data->dispose);
61198 data->found++;
61199 }
61200 @@ -1303,7 +1304,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61201 return D_WALK_CONTINUE;
61202
61203 /* root with refcount 1 is fine */
61204 - if (dentry == _data && dentry->d_lockref.count == 1)
61205 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
61206 return D_WALK_CONTINUE;
61207
61208 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
61209 @@ -1312,7 +1313,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61210 dentry->d_inode ?
61211 dentry->d_inode->i_ino : 0UL,
61212 dentry,
61213 - dentry->d_lockref.count,
61214 + __lockref_read(&dentry->d_lockref),
61215 dentry->d_sb->s_type->name,
61216 dentry->d_sb->s_id);
61217 WARN_ON(1);
61218 @@ -1438,7 +1439,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61219 */
61220 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61221 if (name->len > DNAME_INLINE_LEN-1) {
61222 - dname = kmalloc(name->len + 1, GFP_KERNEL);
61223 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61224 if (!dname) {
61225 kmem_cache_free(dentry_cache, dentry);
61226 return NULL;
61227 @@ -1456,7 +1457,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61228 smp_wmb();
61229 dentry->d_name.name = dname;
61230
61231 - dentry->d_lockref.count = 1;
61232 + __lockref_set(&dentry->d_lockref, 1);
61233 dentry->d_flags = 0;
61234 spin_lock_init(&dentry->d_lock);
61235 seqcount_init(&dentry->d_seq);
61236 @@ -2196,7 +2197,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
61237 goto next;
61238 }
61239
61240 - dentry->d_lockref.count++;
61241 + __lockref_inc(&dentry->d_lockref);
61242 found = dentry;
61243 spin_unlock(&dentry->d_lock);
61244 break;
61245 @@ -2295,7 +2296,7 @@ again:
61246 spin_lock(&dentry->d_lock);
61247 inode = dentry->d_inode;
61248 isdir = S_ISDIR(inode->i_mode);
61249 - if (dentry->d_lockref.count == 1) {
61250 + if (__lockref_read(&dentry->d_lockref) == 1) {
61251 if (!spin_trylock(&inode->i_lock)) {
61252 spin_unlock(&dentry->d_lock);
61253 cpu_relax();
61254 @@ -3307,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
61255
61256 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
61257 dentry->d_flags |= DCACHE_GENOCIDE;
61258 - dentry->d_lockref.count--;
61259 + __lockref_dec(&dentry->d_lockref);
61260 }
61261 }
61262 return D_WALK_CONTINUE;
61263 @@ -3423,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
61264 mempages -= reserve;
61265
61266 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61267 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61268 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61269 + SLAB_NO_SANITIZE, NULL);
61270
61271 dcache_init();
61272 inode_init();
61273 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61274 index 1e3b99d..6512101 100644
61275 --- a/fs/debugfs/inode.c
61276 +++ b/fs/debugfs/inode.c
61277 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61278 */
61279 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61280 {
61281 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61282 + return __create_file(name, S_IFDIR | S_IRWXU,
61283 +#else
61284 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61285 +#endif
61286 parent, NULL, NULL);
61287 }
61288 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61289 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61290 index 57ee4c5..ecb13b0 100644
61291 --- a/fs/ecryptfs/inode.c
61292 +++ b/fs/ecryptfs/inode.c
61293 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61294 old_fs = get_fs();
61295 set_fs(get_ds());
61296 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61297 - (char __user *)lower_buf,
61298 + (char __force_user *)lower_buf,
61299 PATH_MAX);
61300 set_fs(old_fs);
61301 if (rc < 0)
61302 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61303 index e4141f2..d8263e8 100644
61304 --- a/fs/ecryptfs/miscdev.c
61305 +++ b/fs/ecryptfs/miscdev.c
61306 @@ -304,7 +304,7 @@ check_list:
61307 goto out_unlock_msg_ctx;
61308 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61309 if (msg_ctx->msg) {
61310 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61311 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61312 goto out_unlock_msg_ctx;
61313 i += packet_length_size;
61314 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61315 diff --git a/fs/exec.c b/fs/exec.c
61316 index a2b42a9..1e924b3 100644
61317 --- a/fs/exec.c
61318 +++ b/fs/exec.c
61319 @@ -56,8 +56,20 @@
61320 #include <linux/pipe_fs_i.h>
61321 #include <linux/oom.h>
61322 #include <linux/compat.h>
61323 +#include <linux/random.h>
61324 +#include <linux/seq_file.h>
61325 +#include <linux/coredump.h>
61326 +#include <linux/mman.h>
61327 +
61328 +#ifdef CONFIG_PAX_REFCOUNT
61329 +#include <linux/kallsyms.h>
61330 +#include <linux/kdebug.h>
61331 +#endif
61332 +
61333 +#include <trace/events/fs.h>
61334
61335 #include <asm/uaccess.h>
61336 +#include <asm/sections.h>
61337 #include <asm/mmu_context.h>
61338 #include <asm/tlb.h>
61339
61340 @@ -66,19 +78,34 @@
61341
61342 #include <trace/events/sched.h>
61343
61344 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61345 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61346 +{
61347 + 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");
61348 +}
61349 +#endif
61350 +
61351 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61352 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61353 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61354 +#endif
61355 +
61356 int suid_dumpable = 0;
61357
61358 static LIST_HEAD(formats);
61359 static DEFINE_RWLOCK(binfmt_lock);
61360
61361 +extern int gr_process_kernel_exec_ban(void);
61362 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61363 +
61364 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61365 {
61366 BUG_ON(!fmt);
61367 if (WARN_ON(!fmt->load_binary))
61368 return;
61369 write_lock(&binfmt_lock);
61370 - insert ? list_add(&fmt->lh, &formats) :
61371 - list_add_tail(&fmt->lh, &formats);
61372 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61373 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61374 write_unlock(&binfmt_lock);
61375 }
61376
61377 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61378 void unregister_binfmt(struct linux_binfmt * fmt)
61379 {
61380 write_lock(&binfmt_lock);
61381 - list_del(&fmt->lh);
61382 + pax_list_del((struct list_head *)&fmt->lh);
61383 write_unlock(&binfmt_lock);
61384 }
61385
61386 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61387 int write)
61388 {
61389 struct page *page;
61390 - int ret;
61391
61392 -#ifdef CONFIG_STACK_GROWSUP
61393 - if (write) {
61394 - ret = expand_downwards(bprm->vma, pos);
61395 - if (ret < 0)
61396 - return NULL;
61397 - }
61398 -#endif
61399 - ret = get_user_pages(current, bprm->mm, pos,
61400 - 1, write, 1, &page, NULL);
61401 - if (ret <= 0)
61402 + if (0 > expand_downwards(bprm->vma, pos))
61403 + return NULL;
61404 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61405 return NULL;
61406
61407 if (write) {
61408 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61409 if (size <= ARG_MAX)
61410 return page;
61411
61412 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61413 + // only allow 512KB for argv+env on suid/sgid binaries
61414 + // to prevent easy ASLR exhaustion
61415 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61416 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61417 + (size > (512 * 1024))) {
61418 + put_page(page);
61419 + return NULL;
61420 + }
61421 +#endif
61422 +
61423 /*
61424 * Limit to 1/4-th the stack size for the argv+env strings.
61425 * This ensures that:
61426 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61427 vma->vm_end = STACK_TOP_MAX;
61428 vma->vm_start = vma->vm_end - PAGE_SIZE;
61429 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61430 +
61431 +#ifdef CONFIG_PAX_SEGMEXEC
61432 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61433 +#endif
61434 +
61435 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61436 INIT_LIST_HEAD(&vma->anon_vma_chain);
61437
61438 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61439 mm->stack_vm = mm->total_vm = 1;
61440 up_write(&mm->mmap_sem);
61441 bprm->p = vma->vm_end - sizeof(void *);
61442 +
61443 +#ifdef CONFIG_PAX_RANDUSTACK
61444 + if (randomize_va_space)
61445 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61446 +#endif
61447 +
61448 return 0;
61449 err:
61450 up_write(&mm->mmap_sem);
61451 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61452 } ptr;
61453 };
61454
61455 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61456 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61457 {
61458 const char __user *native;
61459
61460 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61461 compat_uptr_t compat;
61462
61463 if (get_user(compat, argv.ptr.compat + nr))
61464 - return ERR_PTR(-EFAULT);
61465 + return (const char __force_user *)ERR_PTR(-EFAULT);
61466
61467 return compat_ptr(compat);
61468 }
61469 #endif
61470
61471 if (get_user(native, argv.ptr.native + nr))
61472 - return ERR_PTR(-EFAULT);
61473 + return (const char __force_user *)ERR_PTR(-EFAULT);
61474
61475 return native;
61476 }
61477 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61478 if (!p)
61479 break;
61480
61481 - if (IS_ERR(p))
61482 + if (IS_ERR((const char __force_kernel *)p))
61483 return -EFAULT;
61484
61485 if (i >= max)
61486 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61487
61488 ret = -EFAULT;
61489 str = get_user_arg_ptr(argv, argc);
61490 - if (IS_ERR(str))
61491 + if (IS_ERR((const char __force_kernel *)str))
61492 goto out;
61493
61494 len = strnlen_user(str, MAX_ARG_STRLEN);
61495 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61496 int r;
61497 mm_segment_t oldfs = get_fs();
61498 struct user_arg_ptr argv = {
61499 - .ptr.native = (const char __user *const __user *)__argv,
61500 + .ptr.native = (const char __user * const __force_user *)__argv,
61501 };
61502
61503 set_fs(KERNEL_DS);
61504 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61505 unsigned long new_end = old_end - shift;
61506 struct mmu_gather tlb;
61507
61508 - BUG_ON(new_start > new_end);
61509 + if (new_start >= new_end || new_start < mmap_min_addr)
61510 + return -ENOMEM;
61511
61512 /*
61513 * ensure there are no vmas between where we want to go
61514 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61515 if (vma != find_vma(mm, new_start))
61516 return -EFAULT;
61517
61518 +#ifdef CONFIG_PAX_SEGMEXEC
61519 + BUG_ON(pax_find_mirror_vma(vma));
61520 +#endif
61521 +
61522 /*
61523 * cover the whole range: [new_start, old_end)
61524 */
61525 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61526 stack_top = arch_align_stack(stack_top);
61527 stack_top = PAGE_ALIGN(stack_top);
61528
61529 - if (unlikely(stack_top < mmap_min_addr) ||
61530 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61531 - return -ENOMEM;
61532 -
61533 stack_shift = vma->vm_end - stack_top;
61534
61535 bprm->p -= stack_shift;
61536 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61537 bprm->exec -= stack_shift;
61538
61539 down_write(&mm->mmap_sem);
61540 +
61541 + /* Move stack pages down in memory. */
61542 + if (stack_shift) {
61543 + ret = shift_arg_pages(vma, stack_shift);
61544 + if (ret)
61545 + goto out_unlock;
61546 + }
61547 +
61548 vm_flags = VM_STACK_FLAGS;
61549
61550 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61551 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61552 + vm_flags &= ~VM_EXEC;
61553 +
61554 +#ifdef CONFIG_PAX_MPROTECT
61555 + if (mm->pax_flags & MF_PAX_MPROTECT)
61556 + vm_flags &= ~VM_MAYEXEC;
61557 +#endif
61558 +
61559 + }
61560 +#endif
61561 +
61562 /*
61563 * Adjust stack execute permissions; explicitly enable for
61564 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61565 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61566 goto out_unlock;
61567 BUG_ON(prev != vma);
61568
61569 - /* Move stack pages down in memory. */
61570 - if (stack_shift) {
61571 - ret = shift_arg_pages(vma, stack_shift);
61572 - if (ret)
61573 - goto out_unlock;
61574 - }
61575 -
61576 /* mprotect_fixup is overkill to remove the temporary stack flags */
61577 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61578
61579 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61580 #endif
61581 current->mm->start_stack = bprm->p;
61582 ret = expand_stack(vma, stack_base);
61583 +
61584 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61585 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61586 + unsigned long size;
61587 + vm_flags_t vm_flags;
61588 +
61589 + size = STACK_TOP - vma->vm_end;
61590 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61591 +
61592 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61593 +
61594 +#ifdef CONFIG_X86
61595 + if (!ret) {
61596 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61597 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61598 + }
61599 +#endif
61600 +
61601 + }
61602 +#endif
61603 +
61604 if (ret)
61605 ret = -EFAULT;
61606
61607 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61608
61609 fsnotify_open(file);
61610
61611 + trace_open_exec(name->name);
61612 +
61613 err = deny_write_access(file);
61614 if (err)
61615 goto exit;
61616 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61617 old_fs = get_fs();
61618 set_fs(get_ds());
61619 /* The cast to a user pointer is valid due to the set_fs() */
61620 - result = vfs_read(file, (void __user *)addr, count, &pos);
61621 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61622 set_fs(old_fs);
61623 return result;
61624 }
61625 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61626 tsk->mm = mm;
61627 tsk->active_mm = mm;
61628 activate_mm(active_mm, mm);
61629 + populate_stack();
61630 tsk->mm->vmacache_seqnum = 0;
61631 vmacache_flush(tsk);
61632 task_unlock(tsk);
61633 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61634 }
61635 rcu_read_unlock();
61636
61637 - if (p->fs->users > n_fs)
61638 + if (atomic_read(&p->fs->users) > n_fs)
61639 bprm->unsafe |= LSM_UNSAFE_SHARE;
61640 else
61641 p->fs->in_exec = 1;
61642 @@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61643 return ret;
61644 }
61645
61646 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61647 +static DEFINE_PER_CPU(u64, exec_counter);
61648 +static int __init init_exec_counters(void)
61649 +{
61650 + unsigned int cpu;
61651 +
61652 + for_each_possible_cpu(cpu) {
61653 + per_cpu(exec_counter, cpu) = (u64)cpu;
61654 + }
61655 +
61656 + return 0;
61657 +}
61658 +early_initcall(init_exec_counters);
61659 +static inline void increment_exec_counter(void)
61660 +{
61661 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61662 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61663 +}
61664 +#else
61665 +static inline void increment_exec_counter(void) {}
61666 +#endif
61667 +
61668 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61669 + struct user_arg_ptr argv);
61670 +
61671 /*
61672 * sys_execve() executes a new program.
61673 */
61674 @@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
61675 struct user_arg_ptr argv,
61676 struct user_arg_ptr envp)
61677 {
61678 +#ifdef CONFIG_GRKERNSEC
61679 + struct file *old_exec_file;
61680 + struct acl_subject_label *old_acl;
61681 + struct rlimit old_rlim[RLIM_NLIMITS];
61682 +#endif
61683 struct linux_binprm *bprm;
61684 struct file *file;
61685 struct files_struct *displaced;
61686 @@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
61687 if (IS_ERR(filename))
61688 return PTR_ERR(filename);
61689
61690 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61691 +
61692 /*
61693 * We move the actual failure in case of RLIMIT_NPROC excess from
61694 * set*uid() to execve() because too many poorly written programs
61695 @@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
61696 if (IS_ERR(file))
61697 goto out_unmark;
61698
61699 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61700 + retval = -EPERM;
61701 + goto out_unmark;
61702 + }
61703 +
61704 sched_exec();
61705
61706 bprm->file = file;
61707 bprm->filename = bprm->interp = filename->name;
61708
61709 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61710 + retval = -EACCES;
61711 + goto out_unmark;
61712 + }
61713 +
61714 retval = bprm_mm_init(bprm);
61715 if (retval)
61716 goto out_unmark;
61717 @@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
61718 if (retval < 0)
61719 goto out;
61720
61721 +#ifdef CONFIG_GRKERNSEC
61722 + old_acl = current->acl;
61723 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61724 + old_exec_file = current->exec_file;
61725 + get_file(file);
61726 + current->exec_file = file;
61727 +#endif
61728 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61729 + /* limit suid stack to 8MB
61730 + * we saved the old limits above and will restore them if this exec fails
61731 + */
61732 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61733 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61734 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61735 +#endif
61736 +
61737 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61738 + retval = -EPERM;
61739 + goto out_fail;
61740 + }
61741 +
61742 + if (!gr_tpe_allow(file)) {
61743 + retval = -EACCES;
61744 + goto out_fail;
61745 + }
61746 +
61747 + if (gr_check_crash_exec(file)) {
61748 + retval = -EACCES;
61749 + goto out_fail;
61750 + }
61751 +
61752 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61753 + bprm->unsafe);
61754 + if (retval < 0)
61755 + goto out_fail;
61756 +
61757 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61758 if (retval < 0)
61759 - goto out;
61760 + goto out_fail;
61761
61762 bprm->exec = bprm->p;
61763 retval = copy_strings(bprm->envc, envp, bprm);
61764 if (retval < 0)
61765 - goto out;
61766 + goto out_fail;
61767
61768 retval = copy_strings(bprm->argc, argv, bprm);
61769 if (retval < 0)
61770 - goto out;
61771 + goto out_fail;
61772 +
61773 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61774 +
61775 + gr_handle_exec_args(bprm, argv);
61776
61777 retval = exec_binprm(bprm);
61778 if (retval < 0)
61779 - goto out;
61780 + goto out_fail;
61781 +#ifdef CONFIG_GRKERNSEC
61782 + if (old_exec_file)
61783 + fput(old_exec_file);
61784 +#endif
61785
61786 /* execve succeeded */
61787 +
61788 + increment_exec_counter();
61789 current->fs->in_exec = 0;
61790 current->in_execve = 0;
61791 acct_update_integrals(current);
61792 @@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
61793 put_files_struct(displaced);
61794 return retval;
61795
61796 +out_fail:
61797 +#ifdef CONFIG_GRKERNSEC
61798 + current->acl = old_acl;
61799 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61800 + fput(current->exec_file);
61801 + current->exec_file = old_exec_file;
61802 +#endif
61803 +
61804 out:
61805 if (bprm->mm) {
61806 acct_arg_size(bprm, 0);
61807 @@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61808 return compat_do_execve(getname(filename), argv, envp);
61809 }
61810 #endif
61811 +
61812 +int pax_check_flags(unsigned long *flags)
61813 +{
61814 + int retval = 0;
61815 +
61816 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61817 + if (*flags & MF_PAX_SEGMEXEC)
61818 + {
61819 + *flags &= ~MF_PAX_SEGMEXEC;
61820 + retval = -EINVAL;
61821 + }
61822 +#endif
61823 +
61824 + if ((*flags & MF_PAX_PAGEEXEC)
61825 +
61826 +#ifdef CONFIG_PAX_PAGEEXEC
61827 + && (*flags & MF_PAX_SEGMEXEC)
61828 +#endif
61829 +
61830 + )
61831 + {
61832 + *flags &= ~MF_PAX_PAGEEXEC;
61833 + retval = -EINVAL;
61834 + }
61835 +
61836 + if ((*flags & MF_PAX_MPROTECT)
61837 +
61838 +#ifdef CONFIG_PAX_MPROTECT
61839 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61840 +#endif
61841 +
61842 + )
61843 + {
61844 + *flags &= ~MF_PAX_MPROTECT;
61845 + retval = -EINVAL;
61846 + }
61847 +
61848 + if ((*flags & MF_PAX_EMUTRAMP)
61849 +
61850 +#ifdef CONFIG_PAX_EMUTRAMP
61851 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61852 +#endif
61853 +
61854 + )
61855 + {
61856 + *flags &= ~MF_PAX_EMUTRAMP;
61857 + retval = -EINVAL;
61858 + }
61859 +
61860 + return retval;
61861 +}
61862 +
61863 +EXPORT_SYMBOL(pax_check_flags);
61864 +
61865 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61866 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61867 +{
61868 + char *pathname = d_path(path, buf, buflen);
61869 +
61870 + if (IS_ERR(pathname))
61871 + goto toolong;
61872 +
61873 + pathname = mangle_path(buf, pathname, "\t\n\\");
61874 + if (!pathname)
61875 + goto toolong;
61876 +
61877 + *pathname = 0;
61878 + return buf;
61879 +
61880 +toolong:
61881 + return "<path too long>";
61882 +}
61883 +EXPORT_SYMBOL(pax_get_path);
61884 +
61885 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61886 +{
61887 + struct task_struct *tsk = current;
61888 + struct mm_struct *mm = current->mm;
61889 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61890 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61891 + char *path_exec = NULL;
61892 + char *path_fault = NULL;
61893 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61894 + siginfo_t info = { };
61895 +
61896 + if (buffer_exec && buffer_fault) {
61897 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61898 +
61899 + down_read(&mm->mmap_sem);
61900 + vma = mm->mmap;
61901 + while (vma && (!vma_exec || !vma_fault)) {
61902 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61903 + vma_exec = vma;
61904 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61905 + vma_fault = vma;
61906 + vma = vma->vm_next;
61907 + }
61908 + if (vma_exec)
61909 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61910 + if (vma_fault) {
61911 + start = vma_fault->vm_start;
61912 + end = vma_fault->vm_end;
61913 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61914 + if (vma_fault->vm_file)
61915 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61916 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61917 + path_fault = "<heap>";
61918 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61919 + path_fault = "<stack>";
61920 + else
61921 + path_fault = "<anonymous mapping>";
61922 + }
61923 + up_read(&mm->mmap_sem);
61924 + }
61925 + if (tsk->signal->curr_ip)
61926 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61927 + else
61928 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61929 + 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),
61930 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61931 + free_page((unsigned long)buffer_exec);
61932 + free_page((unsigned long)buffer_fault);
61933 + pax_report_insns(regs, pc, sp);
61934 + info.si_signo = SIGKILL;
61935 + info.si_errno = 0;
61936 + info.si_code = SI_KERNEL;
61937 + info.si_pid = 0;
61938 + info.si_uid = 0;
61939 + do_coredump(&info);
61940 +}
61941 +#endif
61942 +
61943 +#ifdef CONFIG_PAX_REFCOUNT
61944 +void pax_report_refcount_overflow(struct pt_regs *regs)
61945 +{
61946 + if (current->signal->curr_ip)
61947 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61948 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61949 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61950 + else
61951 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61952 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61953 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61954 + preempt_disable();
61955 + show_regs(regs);
61956 + preempt_enable();
61957 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61958 +}
61959 +#endif
61960 +
61961 +#ifdef CONFIG_PAX_USERCOPY
61962 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61963 +static noinline int check_stack_object(const void *obj, unsigned long len)
61964 +{
61965 + const void * const stack = task_stack_page(current);
61966 + const void * const stackend = stack + THREAD_SIZE;
61967 +
61968 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61969 + const void *frame = NULL;
61970 + const void *oldframe;
61971 +#endif
61972 +
61973 + if (obj + len < obj)
61974 + return -1;
61975 +
61976 + if (obj + len <= stack || stackend <= obj)
61977 + return 0;
61978 +
61979 + if (obj < stack || stackend < obj + len)
61980 + return -1;
61981 +
61982 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61983 + oldframe = __builtin_frame_address(1);
61984 + if (oldframe)
61985 + frame = __builtin_frame_address(2);
61986 + /*
61987 + low ----------------------------------------------> high
61988 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61989 + ^----------------^
61990 + allow copies only within here
61991 + */
61992 + while (stack <= frame && frame < stackend) {
61993 + /* if obj + len extends past the last frame, this
61994 + check won't pass and the next frame will be 0,
61995 + causing us to bail out and correctly report
61996 + the copy as invalid
61997 + */
61998 + if (obj + len <= frame)
61999 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
62000 + oldframe = frame;
62001 + frame = *(const void * const *)frame;
62002 + }
62003 + return -1;
62004 +#else
62005 + return 1;
62006 +#endif
62007 +}
62008 +
62009 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
62010 +{
62011 + if (current->signal->curr_ip)
62012 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62013 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62014 + else
62015 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62016 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62017 + dump_stack();
62018 + gr_handle_kernel_exploit();
62019 + do_group_exit(SIGKILL);
62020 +}
62021 +#endif
62022 +
62023 +#ifdef CONFIG_PAX_USERCOPY
62024 +
62025 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
62026 +{
62027 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
62028 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
62029 +#ifdef CONFIG_MODULES
62030 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
62031 +#else
62032 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
62033 +#endif
62034 +
62035 +#else
62036 + unsigned long textlow = (unsigned long)_stext;
62037 + unsigned long texthigh = (unsigned long)_etext;
62038 +
62039 +#ifdef CONFIG_X86_64
62040 + /* check against linear mapping as well */
62041 + if (high > (unsigned long)__va(__pa(textlow)) &&
62042 + low < (unsigned long)__va(__pa(texthigh)))
62043 + return true;
62044 +#endif
62045 +
62046 +#endif
62047 +
62048 + if (high <= textlow || low >= texthigh)
62049 + return false;
62050 + else
62051 + return true;
62052 +}
62053 +#endif
62054 +
62055 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62056 +{
62057 +#ifdef CONFIG_PAX_USERCOPY
62058 + const char *type;
62059 +#endif
62060 +
62061 +#ifndef CONFIG_STACK_GROWSUP
62062 + unsigned long stackstart = (unsigned long)task_stack_page(current);
62063 + unsigned long currentsp = (unsigned long)&stackstart;
62064 + if (unlikely((currentsp < stackstart + 512 ||
62065 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62066 + BUG();
62067 +#endif
62068 +
62069 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
62070 + if (const_size)
62071 + return;
62072 +#endif
62073 +
62074 +#ifdef CONFIG_PAX_USERCOPY
62075 + if (!n)
62076 + return;
62077 +
62078 + type = check_heap_object(ptr, n);
62079 + if (!type) {
62080 + int ret = check_stack_object(ptr, n);
62081 + if (ret == 1 || ret == 2)
62082 + return;
62083 + if (ret == 0) {
62084 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62085 + type = "<kernel text>";
62086 + else
62087 + return;
62088 + } else
62089 + type = "<process stack>";
62090 + }
62091 +
62092 + pax_report_usercopy(ptr, n, to_user, type);
62093 +#endif
62094 +
62095 +}
62096 +EXPORT_SYMBOL(__check_object_size);
62097 +
62098 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62099 +void pax_track_stack(void)
62100 +{
62101 + unsigned long sp = (unsigned long)&sp;
62102 + if (sp < current_thread_info()->lowest_stack &&
62103 + sp > (unsigned long)task_stack_page(current))
62104 + current_thread_info()->lowest_stack = sp;
62105 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62106 + BUG();
62107 +}
62108 +EXPORT_SYMBOL(pax_track_stack);
62109 +#endif
62110 +
62111 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
62112 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62113 +{
62114 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62115 + dump_stack();
62116 + do_group_exit(SIGKILL);
62117 +}
62118 +EXPORT_SYMBOL(report_size_overflow);
62119 +#endif
62120 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62121 index 9f9992b..8b59411 100644
62122 --- a/fs/ext2/balloc.c
62123 +++ b/fs/ext2/balloc.c
62124 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62125
62126 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62127 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62128 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62129 + if (free_blocks < root_blocks + 1 &&
62130 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62131 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62132 - !in_group_p (sbi->s_resgid))) {
62133 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62134 return 0;
62135 }
62136 return 1;
62137 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
62138 index b88edc0..c4088ab 100644
62139 --- a/fs/ext2/super.c
62140 +++ b/fs/ext2/super.c
62141 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
62142 #ifdef CONFIG_EXT2_FS_XATTR
62143 if (test_opt(sb, XATTR_USER))
62144 seq_puts(seq, ",user_xattr");
62145 - if (!test_opt(sb, XATTR_USER) &&
62146 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
62147 + if (!test_opt(sb, XATTR_USER))
62148 seq_puts(seq, ",nouser_xattr");
62149 - }
62150 #endif
62151
62152 #ifdef CONFIG_EXT2_FS_POSIX_ACL
62153 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
62154 if (def_mount_opts & EXT2_DEFM_UID16)
62155 set_opt(sbi->s_mount_opt, NO_UID32);
62156 #ifdef CONFIG_EXT2_FS_XATTR
62157 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
62158 - set_opt(sbi->s_mount_opt, XATTR_USER);
62159 + /* always enable user xattrs */
62160 + set_opt(sbi->s_mount_opt, XATTR_USER);
62161 #endif
62162 #ifdef CONFIG_EXT2_FS_POSIX_ACL
62163 if (def_mount_opts & EXT2_DEFM_ACL)
62164 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62165 index 9142614..97484fa 100644
62166 --- a/fs/ext2/xattr.c
62167 +++ b/fs/ext2/xattr.c
62168 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62169 struct buffer_head *bh = NULL;
62170 struct ext2_xattr_entry *entry;
62171 char *end;
62172 - size_t rest = buffer_size;
62173 + size_t rest = buffer_size, total_size = 0;
62174 int error;
62175
62176 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62177 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62178 buffer += size;
62179 }
62180 rest -= size;
62181 + total_size += size;
62182 }
62183 }
62184 - error = buffer_size - rest; /* total size */
62185 + error = total_size;
62186
62187 cleanup:
62188 brelse(bh);
62189 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62190 index 158b5d4..2432610 100644
62191 --- a/fs/ext3/balloc.c
62192 +++ b/fs/ext3/balloc.c
62193 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62194
62195 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62196 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62197 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62198 + if (free_blocks < root_blocks + 1 &&
62199 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62200 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62201 - !in_group_p (sbi->s_resgid))) {
62202 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62203 return 0;
62204 }
62205 return 1;
62206 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
62207 index 2c42e73..cf5b892 100644
62208 --- a/fs/ext3/super.c
62209 +++ b/fs/ext3/super.c
62210 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
62211 #ifdef CONFIG_EXT3_FS_XATTR
62212 if (test_opt(sb, XATTR_USER))
62213 seq_puts(seq, ",user_xattr");
62214 - if (!test_opt(sb, XATTR_USER) &&
62215 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
62216 + if (!test_opt(sb, XATTR_USER))
62217 seq_puts(seq, ",nouser_xattr");
62218 - }
62219 #endif
62220 #ifdef CONFIG_EXT3_FS_POSIX_ACL
62221 if (test_opt(sb, POSIX_ACL))
62222 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
62223 if (def_mount_opts & EXT3_DEFM_UID16)
62224 set_opt(sbi->s_mount_opt, NO_UID32);
62225 #ifdef CONFIG_EXT3_FS_XATTR
62226 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
62227 - set_opt(sbi->s_mount_opt, XATTR_USER);
62228 + /* always enable user xattrs */
62229 + set_opt(sbi->s_mount_opt, XATTR_USER);
62230 #endif
62231 #ifdef CONFIG_EXT3_FS_POSIX_ACL
62232 if (def_mount_opts & EXT3_DEFM_ACL)
62233 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62234 index c6874be..f8a6ae8 100644
62235 --- a/fs/ext3/xattr.c
62236 +++ b/fs/ext3/xattr.c
62237 @@ -330,7 +330,7 @@ static int
62238 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62239 char *buffer, size_t buffer_size)
62240 {
62241 - size_t rest = buffer_size;
62242 + size_t rest = buffer_size, total_size = 0;
62243
62244 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62245 const struct xattr_handler *handler =
62246 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62247 buffer += size;
62248 }
62249 rest -= size;
62250 + total_size += size;
62251 }
62252 }
62253 - return buffer_size - rest;
62254 + return total_size;
62255 }
62256
62257 static int
62258 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62259 index e069155..b825b08 100644
62260 --- a/fs/ext4/balloc.c
62261 +++ b/fs/ext4/balloc.c
62262 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62263 /* Hm, nope. Are (enough) root reserved clusters available? */
62264 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62265 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62266 - capable(CAP_SYS_RESOURCE) ||
62267 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62268 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62269 + capable_nolog(CAP_SYS_RESOURCE)) {
62270
62271 if (free_clusters >= (nclusters + dirty_clusters +
62272 resv_clusters))
62273 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62274 index 96ac9d3..1c30e7e6 100644
62275 --- a/fs/ext4/ext4.h
62276 +++ b/fs/ext4/ext4.h
62277 @@ -1275,19 +1275,19 @@ struct ext4_sb_info {
62278 unsigned long s_mb_last_start;
62279
62280 /* stats for buddy allocator */
62281 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62282 - atomic_t s_bal_success; /* we found long enough chunks */
62283 - atomic_t s_bal_allocated; /* in blocks */
62284 - atomic_t s_bal_ex_scanned; /* total extents scanned */
62285 - atomic_t s_bal_goals; /* goal hits */
62286 - atomic_t s_bal_breaks; /* too long searches */
62287 - atomic_t s_bal_2orders; /* 2^order hits */
62288 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62289 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62290 + atomic_unchecked_t s_bal_allocated; /* in blocks */
62291 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62292 + atomic_unchecked_t s_bal_goals; /* goal hits */
62293 + atomic_unchecked_t s_bal_breaks; /* too long searches */
62294 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62295 spinlock_t s_bal_lock;
62296 unsigned long s_mb_buddies_generated;
62297 unsigned long long s_mb_generation_time;
62298 - atomic_t s_mb_lost_chunks;
62299 - atomic_t s_mb_preallocated;
62300 - atomic_t s_mb_discarded;
62301 + atomic_unchecked_t s_mb_lost_chunks;
62302 + atomic_unchecked_t s_mb_preallocated;
62303 + atomic_unchecked_t s_mb_discarded;
62304 atomic_t s_lock_busy;
62305
62306 /* locality groups */
62307 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62308 index 8b0f9ef..cb9f620 100644
62309 --- a/fs/ext4/mballoc.c
62310 +++ b/fs/ext4/mballoc.c
62311 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62312 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62313
62314 if (EXT4_SB(sb)->s_mb_stats)
62315 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62316 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62317
62318 break;
62319 }
62320 @@ -2211,7 +2211,7 @@ repeat:
62321 ac->ac_status = AC_STATUS_CONTINUE;
62322 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62323 cr = 3;
62324 - atomic_inc(&sbi->s_mb_lost_chunks);
62325 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62326 goto repeat;
62327 }
62328 }
62329 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62330 if (sbi->s_mb_stats) {
62331 ext4_msg(sb, KERN_INFO,
62332 "mballoc: %u blocks %u reqs (%u success)",
62333 - atomic_read(&sbi->s_bal_allocated),
62334 - atomic_read(&sbi->s_bal_reqs),
62335 - atomic_read(&sbi->s_bal_success));
62336 + atomic_read_unchecked(&sbi->s_bal_allocated),
62337 + atomic_read_unchecked(&sbi->s_bal_reqs),
62338 + atomic_read_unchecked(&sbi->s_bal_success));
62339 ext4_msg(sb, KERN_INFO,
62340 "mballoc: %u extents scanned, %u goal hits, "
62341 "%u 2^N hits, %u breaks, %u lost",
62342 - atomic_read(&sbi->s_bal_ex_scanned),
62343 - atomic_read(&sbi->s_bal_goals),
62344 - atomic_read(&sbi->s_bal_2orders),
62345 - atomic_read(&sbi->s_bal_breaks),
62346 - atomic_read(&sbi->s_mb_lost_chunks));
62347 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62348 + atomic_read_unchecked(&sbi->s_bal_goals),
62349 + atomic_read_unchecked(&sbi->s_bal_2orders),
62350 + atomic_read_unchecked(&sbi->s_bal_breaks),
62351 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62352 ext4_msg(sb, KERN_INFO,
62353 "mballoc: %lu generated and it took %Lu",
62354 sbi->s_mb_buddies_generated,
62355 sbi->s_mb_generation_time);
62356 ext4_msg(sb, KERN_INFO,
62357 "mballoc: %u preallocated, %u discarded",
62358 - atomic_read(&sbi->s_mb_preallocated),
62359 - atomic_read(&sbi->s_mb_discarded));
62360 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62361 + atomic_read_unchecked(&sbi->s_mb_discarded));
62362 }
62363
62364 free_percpu(sbi->s_locality_groups);
62365 @@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62366 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62367
62368 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62369 - atomic_inc(&sbi->s_bal_reqs);
62370 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62371 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62372 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62373 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62374 - atomic_inc(&sbi->s_bal_success);
62375 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62376 + atomic_inc_unchecked(&sbi->s_bal_success);
62377 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62378 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62379 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62380 - atomic_inc(&sbi->s_bal_goals);
62381 + atomic_inc_unchecked(&sbi->s_bal_goals);
62382 if (ac->ac_found > sbi->s_mb_max_to_scan)
62383 - atomic_inc(&sbi->s_bal_breaks);
62384 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62385 }
62386
62387 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62388 @@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62389 trace_ext4_mb_new_inode_pa(ac, pa);
62390
62391 ext4_mb_use_inode_pa(ac, pa);
62392 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62393 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62394
62395 ei = EXT4_I(ac->ac_inode);
62396 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62397 @@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62398 trace_ext4_mb_new_group_pa(ac, pa);
62399
62400 ext4_mb_use_group_pa(ac, pa);
62401 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62402 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62403
62404 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62405 lg = ac->ac_lg;
62406 @@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62407 * from the bitmap and continue.
62408 */
62409 }
62410 - atomic_add(free, &sbi->s_mb_discarded);
62411 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62412
62413 return err;
62414 }
62415 @@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62416 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62417 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62418 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62419 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62420 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62421 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62422
62423 return 0;
62424 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62425 index 8313ca3..8a37d08 100644
62426 --- a/fs/ext4/mmp.c
62427 +++ b/fs/ext4/mmp.c
62428 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62429 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62430 const char *function, unsigned int line, const char *msg)
62431 {
62432 - __ext4_warning(sb, function, line, msg);
62433 + __ext4_warning(sb, function, line, "%s", msg);
62434 __ext4_warning(sb, function, line,
62435 "MMP failure info: last update time: %llu, last update "
62436 "node: %s, last update device: %s\n",
62437 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62438 index b1f0ac7..77e9a05 100644
62439 --- a/fs/ext4/super.c
62440 +++ b/fs/ext4/super.c
62441 @@ -1274,7 +1274,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62442 }
62443
62444 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62445 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62446 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62447 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62448
62449 #ifdef CONFIG_QUOTA
62450 @@ -2454,7 +2454,7 @@ struct ext4_attr {
62451 int offset;
62452 int deprecated_val;
62453 } u;
62454 -};
62455 +} __do_const;
62456
62457 static int parse_strtoull(const char *buf,
62458 unsigned long long max, unsigned long long *value)
62459 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62460 index 2d1e5803..1b082d415 100644
62461 --- a/fs/ext4/xattr.c
62462 +++ b/fs/ext4/xattr.c
62463 @@ -399,7 +399,7 @@ static int
62464 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62465 char *buffer, size_t buffer_size)
62466 {
62467 - size_t rest = buffer_size;
62468 + size_t rest = buffer_size, total_size = 0;
62469
62470 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62471 const struct xattr_handler *handler =
62472 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62473 buffer += size;
62474 }
62475 rest -= size;
62476 + total_size += size;
62477 }
62478 }
62479 - return buffer_size - rest;
62480 + return total_size;
62481 }
62482
62483 static int
62484 diff --git a/fs/fcntl.c b/fs/fcntl.c
62485 index 22d1c3d..600cf7e 100644
62486 --- a/fs/fcntl.c
62487 +++ b/fs/fcntl.c
62488 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62489 if (err)
62490 return err;
62491
62492 + if (gr_handle_chroot_fowner(pid, type))
62493 + return -ENOENT;
62494 + if (gr_check_protected_task_fowner(pid, type))
62495 + return -EACCES;
62496 +
62497 f_modown(filp, pid, type, force);
62498 return 0;
62499 }
62500 diff --git a/fs/fhandle.c b/fs/fhandle.c
62501 index 999ff5c..ac037c9 100644
62502 --- a/fs/fhandle.c
62503 +++ b/fs/fhandle.c
62504 @@ -8,6 +8,7 @@
62505 #include <linux/fs_struct.h>
62506 #include <linux/fsnotify.h>
62507 #include <linux/personality.h>
62508 +#include <linux/grsecurity.h>
62509 #include <asm/uaccess.h>
62510 #include "internal.h"
62511 #include "mount.h"
62512 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62513 } else
62514 retval = 0;
62515 /* copy the mount id */
62516 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62517 - sizeof(*mnt_id)) ||
62518 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62519 copy_to_user(ufh, handle,
62520 sizeof(struct file_handle) + handle_bytes))
62521 retval = -EFAULT;
62522 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62523 * the directory. Ideally we would like CAP_DAC_SEARCH.
62524 * But we don't have that
62525 */
62526 - if (!capable(CAP_DAC_READ_SEARCH)) {
62527 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62528 retval = -EPERM;
62529 goto out_err;
62530 }
62531 diff --git a/fs/file.c b/fs/file.c
62532 index 66923fe..2849783 100644
62533 --- a/fs/file.c
62534 +++ b/fs/file.c
62535 @@ -16,6 +16,7 @@
62536 #include <linux/slab.h>
62537 #include <linux/vmalloc.h>
62538 #include <linux/file.h>
62539 +#include <linux/security.h>
62540 #include <linux/fdtable.h>
62541 #include <linux/bitops.h>
62542 #include <linux/interrupt.h>
62543 @@ -139,7 +140,7 @@ out:
62544 * Return <0 error code on error; 1 on successful completion.
62545 * The files->file_lock should be held on entry, and will be held on exit.
62546 */
62547 -static int expand_fdtable(struct files_struct *files, int nr)
62548 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62549 __releases(files->file_lock)
62550 __acquires(files->file_lock)
62551 {
62552 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62553 * expanded and execution may have blocked.
62554 * The files->file_lock should be held on entry, and will be held on exit.
62555 */
62556 -static int expand_files(struct files_struct *files, int nr)
62557 +static int expand_files(struct files_struct *files, unsigned int nr)
62558 {
62559 struct fdtable *fdt;
62560
62561 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62562 if (!file)
62563 return __close_fd(files, fd);
62564
62565 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62566 if (fd >= rlimit(RLIMIT_NOFILE))
62567 return -EBADF;
62568
62569 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62570 if (unlikely(oldfd == newfd))
62571 return -EINVAL;
62572
62573 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62574 if (newfd >= rlimit(RLIMIT_NOFILE))
62575 return -EBADF;
62576
62577 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62578 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62579 {
62580 int err;
62581 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62582 if (from >= rlimit(RLIMIT_NOFILE))
62583 return -EINVAL;
62584 err = alloc_fd(from, flags);
62585 diff --git a/fs/filesystems.c b/fs/filesystems.c
62586 index 5797d45..7d7d79a 100644
62587 --- a/fs/filesystems.c
62588 +++ b/fs/filesystems.c
62589 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62590 int len = dot ? dot - name : strlen(name);
62591
62592 fs = __get_fs_type(name, len);
62593 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62594 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62595 +#else
62596 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62597 +#endif
62598 fs = __get_fs_type(name, len);
62599
62600 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62601 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62602 index 7dca743..543d620 100644
62603 --- a/fs/fs_struct.c
62604 +++ b/fs/fs_struct.c
62605 @@ -4,6 +4,7 @@
62606 #include <linux/path.h>
62607 #include <linux/slab.h>
62608 #include <linux/fs_struct.h>
62609 +#include <linux/grsecurity.h>
62610 #include "internal.h"
62611
62612 /*
62613 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62614 write_seqcount_begin(&fs->seq);
62615 old_root = fs->root;
62616 fs->root = *path;
62617 + gr_set_chroot_entries(current, path);
62618 write_seqcount_end(&fs->seq);
62619 spin_unlock(&fs->lock);
62620 if (old_root.dentry)
62621 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62622 int hits = 0;
62623 spin_lock(&fs->lock);
62624 write_seqcount_begin(&fs->seq);
62625 + /* this root replacement is only done by pivot_root,
62626 + leave grsec's chroot tagging alone for this task
62627 + so that a pivoted root isn't treated as a chroot
62628 + */
62629 hits += replace_path(&fs->root, old_root, new_root);
62630 hits += replace_path(&fs->pwd, old_root, new_root);
62631 write_seqcount_end(&fs->seq);
62632 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62633 task_lock(tsk);
62634 spin_lock(&fs->lock);
62635 tsk->fs = NULL;
62636 - kill = !--fs->users;
62637 + gr_clear_chroot_entries(tsk);
62638 + kill = !atomic_dec_return(&fs->users);
62639 spin_unlock(&fs->lock);
62640 task_unlock(tsk);
62641 if (kill)
62642 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62643 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62644 /* We don't need to lock fs - think why ;-) */
62645 if (fs) {
62646 - fs->users = 1;
62647 + atomic_set(&fs->users, 1);
62648 fs->in_exec = 0;
62649 spin_lock_init(&fs->lock);
62650 seqcount_init(&fs->seq);
62651 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62652 spin_lock(&old->lock);
62653 fs->root = old->root;
62654 path_get(&fs->root);
62655 + /* instead of calling gr_set_chroot_entries here,
62656 + we call it from every caller of this function
62657 + */
62658 fs->pwd = old->pwd;
62659 path_get(&fs->pwd);
62660 spin_unlock(&old->lock);
62661 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62662
62663 task_lock(current);
62664 spin_lock(&fs->lock);
62665 - kill = !--fs->users;
62666 + kill = !atomic_dec_return(&fs->users);
62667 current->fs = new_fs;
62668 + gr_set_chroot_entries(current, &new_fs->root);
62669 spin_unlock(&fs->lock);
62670 task_unlock(current);
62671
62672 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62673
62674 int current_umask(void)
62675 {
62676 - return current->fs->umask;
62677 + return current->fs->umask | gr_acl_umask();
62678 }
62679 EXPORT_SYMBOL(current_umask);
62680
62681 /* to be mentioned only in INIT_TASK */
62682 struct fs_struct init_fs = {
62683 - .users = 1,
62684 + .users = ATOMIC_INIT(1),
62685 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62686 .seq = SEQCNT_ZERO(init_fs.seq),
62687 .umask = 0022,
62688 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62689 index 89acec7..a575262 100644
62690 --- a/fs/fscache/cookie.c
62691 +++ b/fs/fscache/cookie.c
62692 @@ -19,7 +19,7 @@
62693
62694 struct kmem_cache *fscache_cookie_jar;
62695
62696 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62697 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62698
62699 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62700 static int fscache_alloc_object(struct fscache_cache *cache,
62701 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62702 parent ? (char *) parent->def->name : "<no-parent>",
62703 def->name, netfs_data, enable);
62704
62705 - fscache_stat(&fscache_n_acquires);
62706 + fscache_stat_unchecked(&fscache_n_acquires);
62707
62708 /* if there's no parent cookie, then we don't create one here either */
62709 if (!parent) {
62710 - fscache_stat(&fscache_n_acquires_null);
62711 + fscache_stat_unchecked(&fscache_n_acquires_null);
62712 _leave(" [no parent]");
62713 return NULL;
62714 }
62715 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62716 /* allocate and initialise a cookie */
62717 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62718 if (!cookie) {
62719 - fscache_stat(&fscache_n_acquires_oom);
62720 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62721 _leave(" [ENOMEM]");
62722 return NULL;
62723 }
62724 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62725
62726 switch (cookie->def->type) {
62727 case FSCACHE_COOKIE_TYPE_INDEX:
62728 - fscache_stat(&fscache_n_cookie_index);
62729 + fscache_stat_unchecked(&fscache_n_cookie_index);
62730 break;
62731 case FSCACHE_COOKIE_TYPE_DATAFILE:
62732 - fscache_stat(&fscache_n_cookie_data);
62733 + fscache_stat_unchecked(&fscache_n_cookie_data);
62734 break;
62735 default:
62736 - fscache_stat(&fscache_n_cookie_special);
62737 + fscache_stat_unchecked(&fscache_n_cookie_special);
62738 break;
62739 }
62740
62741 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62742 } else {
62743 atomic_dec(&parent->n_children);
62744 __fscache_cookie_put(cookie);
62745 - fscache_stat(&fscache_n_acquires_nobufs);
62746 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62747 _leave(" = NULL");
62748 return NULL;
62749 }
62750 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62751 }
62752 }
62753
62754 - fscache_stat(&fscache_n_acquires_ok);
62755 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62756 _leave(" = %p", cookie);
62757 return cookie;
62758 }
62759 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62760 cache = fscache_select_cache_for_object(cookie->parent);
62761 if (!cache) {
62762 up_read(&fscache_addremove_sem);
62763 - fscache_stat(&fscache_n_acquires_no_cache);
62764 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62765 _leave(" = -ENOMEDIUM [no cache]");
62766 return -ENOMEDIUM;
62767 }
62768 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62769 object = cache->ops->alloc_object(cache, cookie);
62770 fscache_stat_d(&fscache_n_cop_alloc_object);
62771 if (IS_ERR(object)) {
62772 - fscache_stat(&fscache_n_object_no_alloc);
62773 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62774 ret = PTR_ERR(object);
62775 goto error;
62776 }
62777
62778 - fscache_stat(&fscache_n_object_alloc);
62779 + fscache_stat_unchecked(&fscache_n_object_alloc);
62780
62781 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62782 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62783
62784 _debug("ALLOC OBJ%x: %s {%lx}",
62785 object->debug_id, cookie->def->name, object->events);
62786 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62787
62788 _enter("{%s}", cookie->def->name);
62789
62790 - fscache_stat(&fscache_n_invalidates);
62791 + fscache_stat_unchecked(&fscache_n_invalidates);
62792
62793 /* Only permit invalidation of data files. Invalidating an index will
62794 * require the caller to release all its attachments to the tree rooted
62795 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62796 {
62797 struct fscache_object *object;
62798
62799 - fscache_stat(&fscache_n_updates);
62800 + fscache_stat_unchecked(&fscache_n_updates);
62801
62802 if (!cookie) {
62803 - fscache_stat(&fscache_n_updates_null);
62804 + fscache_stat_unchecked(&fscache_n_updates_null);
62805 _leave(" [no cookie]");
62806 return;
62807 }
62808 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62809 */
62810 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62811 {
62812 - fscache_stat(&fscache_n_relinquishes);
62813 + fscache_stat_unchecked(&fscache_n_relinquishes);
62814 if (retire)
62815 - fscache_stat(&fscache_n_relinquishes_retire);
62816 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62817
62818 if (!cookie) {
62819 - fscache_stat(&fscache_n_relinquishes_null);
62820 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62821 _leave(" [no cookie]");
62822 return;
62823 }
62824 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62825 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62826 goto inconsistent;
62827
62828 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62829 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62830
62831 __fscache_use_cookie(cookie);
62832 if (fscache_submit_op(object, op) < 0)
62833 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62834 index 7872a62..d91b19f 100644
62835 --- a/fs/fscache/internal.h
62836 +++ b/fs/fscache/internal.h
62837 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62838 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62839 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62840 struct fscache_operation *,
62841 - atomic_t *,
62842 - atomic_t *,
62843 + atomic_unchecked_t *,
62844 + atomic_unchecked_t *,
62845 void (*)(struct fscache_operation *));
62846 extern void fscache_invalidate_writes(struct fscache_cookie *);
62847
62848 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62849 * stats.c
62850 */
62851 #ifdef CONFIG_FSCACHE_STATS
62852 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62853 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62854 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62855 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62856
62857 -extern atomic_t fscache_n_op_pend;
62858 -extern atomic_t fscache_n_op_run;
62859 -extern atomic_t fscache_n_op_enqueue;
62860 -extern atomic_t fscache_n_op_deferred_release;
62861 -extern atomic_t fscache_n_op_release;
62862 -extern atomic_t fscache_n_op_gc;
62863 -extern atomic_t fscache_n_op_cancelled;
62864 -extern atomic_t fscache_n_op_rejected;
62865 +extern atomic_unchecked_t fscache_n_op_pend;
62866 +extern atomic_unchecked_t fscache_n_op_run;
62867 +extern atomic_unchecked_t fscache_n_op_enqueue;
62868 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62869 +extern atomic_unchecked_t fscache_n_op_release;
62870 +extern atomic_unchecked_t fscache_n_op_gc;
62871 +extern atomic_unchecked_t fscache_n_op_cancelled;
62872 +extern atomic_unchecked_t fscache_n_op_rejected;
62873
62874 -extern atomic_t fscache_n_attr_changed;
62875 -extern atomic_t fscache_n_attr_changed_ok;
62876 -extern atomic_t fscache_n_attr_changed_nobufs;
62877 -extern atomic_t fscache_n_attr_changed_nomem;
62878 -extern atomic_t fscache_n_attr_changed_calls;
62879 +extern atomic_unchecked_t fscache_n_attr_changed;
62880 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62881 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62882 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62883 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62884
62885 -extern atomic_t fscache_n_allocs;
62886 -extern atomic_t fscache_n_allocs_ok;
62887 -extern atomic_t fscache_n_allocs_wait;
62888 -extern atomic_t fscache_n_allocs_nobufs;
62889 -extern atomic_t fscache_n_allocs_intr;
62890 -extern atomic_t fscache_n_allocs_object_dead;
62891 -extern atomic_t fscache_n_alloc_ops;
62892 -extern atomic_t fscache_n_alloc_op_waits;
62893 +extern atomic_unchecked_t fscache_n_allocs;
62894 +extern atomic_unchecked_t fscache_n_allocs_ok;
62895 +extern atomic_unchecked_t fscache_n_allocs_wait;
62896 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62897 +extern atomic_unchecked_t fscache_n_allocs_intr;
62898 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62899 +extern atomic_unchecked_t fscache_n_alloc_ops;
62900 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62901
62902 -extern atomic_t fscache_n_retrievals;
62903 -extern atomic_t fscache_n_retrievals_ok;
62904 -extern atomic_t fscache_n_retrievals_wait;
62905 -extern atomic_t fscache_n_retrievals_nodata;
62906 -extern atomic_t fscache_n_retrievals_nobufs;
62907 -extern atomic_t fscache_n_retrievals_intr;
62908 -extern atomic_t fscache_n_retrievals_nomem;
62909 -extern atomic_t fscache_n_retrievals_object_dead;
62910 -extern atomic_t fscache_n_retrieval_ops;
62911 -extern atomic_t fscache_n_retrieval_op_waits;
62912 +extern atomic_unchecked_t fscache_n_retrievals;
62913 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62914 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62915 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62916 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62917 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62918 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62919 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62920 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62921 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62922
62923 -extern atomic_t fscache_n_stores;
62924 -extern atomic_t fscache_n_stores_ok;
62925 -extern atomic_t fscache_n_stores_again;
62926 -extern atomic_t fscache_n_stores_nobufs;
62927 -extern atomic_t fscache_n_stores_oom;
62928 -extern atomic_t fscache_n_store_ops;
62929 -extern atomic_t fscache_n_store_calls;
62930 -extern atomic_t fscache_n_store_pages;
62931 -extern atomic_t fscache_n_store_radix_deletes;
62932 -extern atomic_t fscache_n_store_pages_over_limit;
62933 +extern atomic_unchecked_t fscache_n_stores;
62934 +extern atomic_unchecked_t fscache_n_stores_ok;
62935 +extern atomic_unchecked_t fscache_n_stores_again;
62936 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62937 +extern atomic_unchecked_t fscache_n_stores_oom;
62938 +extern atomic_unchecked_t fscache_n_store_ops;
62939 +extern atomic_unchecked_t fscache_n_store_calls;
62940 +extern atomic_unchecked_t fscache_n_store_pages;
62941 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62942 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62943
62944 -extern atomic_t fscache_n_store_vmscan_not_storing;
62945 -extern atomic_t fscache_n_store_vmscan_gone;
62946 -extern atomic_t fscache_n_store_vmscan_busy;
62947 -extern atomic_t fscache_n_store_vmscan_cancelled;
62948 -extern atomic_t fscache_n_store_vmscan_wait;
62949 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62950 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62951 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62952 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62953 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62954
62955 -extern atomic_t fscache_n_marks;
62956 -extern atomic_t fscache_n_uncaches;
62957 +extern atomic_unchecked_t fscache_n_marks;
62958 +extern atomic_unchecked_t fscache_n_uncaches;
62959
62960 -extern atomic_t fscache_n_acquires;
62961 -extern atomic_t fscache_n_acquires_null;
62962 -extern atomic_t fscache_n_acquires_no_cache;
62963 -extern atomic_t fscache_n_acquires_ok;
62964 -extern atomic_t fscache_n_acquires_nobufs;
62965 -extern atomic_t fscache_n_acquires_oom;
62966 +extern atomic_unchecked_t fscache_n_acquires;
62967 +extern atomic_unchecked_t fscache_n_acquires_null;
62968 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62969 +extern atomic_unchecked_t fscache_n_acquires_ok;
62970 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62971 +extern atomic_unchecked_t fscache_n_acquires_oom;
62972
62973 -extern atomic_t fscache_n_invalidates;
62974 -extern atomic_t fscache_n_invalidates_run;
62975 +extern atomic_unchecked_t fscache_n_invalidates;
62976 +extern atomic_unchecked_t fscache_n_invalidates_run;
62977
62978 -extern atomic_t fscache_n_updates;
62979 -extern atomic_t fscache_n_updates_null;
62980 -extern atomic_t fscache_n_updates_run;
62981 +extern atomic_unchecked_t fscache_n_updates;
62982 +extern atomic_unchecked_t fscache_n_updates_null;
62983 +extern atomic_unchecked_t fscache_n_updates_run;
62984
62985 -extern atomic_t fscache_n_relinquishes;
62986 -extern atomic_t fscache_n_relinquishes_null;
62987 -extern atomic_t fscache_n_relinquishes_waitcrt;
62988 -extern atomic_t fscache_n_relinquishes_retire;
62989 +extern atomic_unchecked_t fscache_n_relinquishes;
62990 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62991 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62992 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62993
62994 -extern atomic_t fscache_n_cookie_index;
62995 -extern atomic_t fscache_n_cookie_data;
62996 -extern atomic_t fscache_n_cookie_special;
62997 +extern atomic_unchecked_t fscache_n_cookie_index;
62998 +extern atomic_unchecked_t fscache_n_cookie_data;
62999 +extern atomic_unchecked_t fscache_n_cookie_special;
63000
63001 -extern atomic_t fscache_n_object_alloc;
63002 -extern atomic_t fscache_n_object_no_alloc;
63003 -extern atomic_t fscache_n_object_lookups;
63004 -extern atomic_t fscache_n_object_lookups_negative;
63005 -extern atomic_t fscache_n_object_lookups_positive;
63006 -extern atomic_t fscache_n_object_lookups_timed_out;
63007 -extern atomic_t fscache_n_object_created;
63008 -extern atomic_t fscache_n_object_avail;
63009 -extern atomic_t fscache_n_object_dead;
63010 +extern atomic_unchecked_t fscache_n_object_alloc;
63011 +extern atomic_unchecked_t fscache_n_object_no_alloc;
63012 +extern atomic_unchecked_t fscache_n_object_lookups;
63013 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
63014 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
63015 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
63016 +extern atomic_unchecked_t fscache_n_object_created;
63017 +extern atomic_unchecked_t fscache_n_object_avail;
63018 +extern atomic_unchecked_t fscache_n_object_dead;
63019
63020 -extern atomic_t fscache_n_checkaux_none;
63021 -extern atomic_t fscache_n_checkaux_okay;
63022 -extern atomic_t fscache_n_checkaux_update;
63023 -extern atomic_t fscache_n_checkaux_obsolete;
63024 +extern atomic_unchecked_t fscache_n_checkaux_none;
63025 +extern atomic_unchecked_t fscache_n_checkaux_okay;
63026 +extern atomic_unchecked_t fscache_n_checkaux_update;
63027 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
63028
63029 extern atomic_t fscache_n_cop_alloc_object;
63030 extern atomic_t fscache_n_cop_lookup_object;
63031 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
63032 atomic_inc(stat);
63033 }
63034
63035 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
63036 +{
63037 + atomic_inc_unchecked(stat);
63038 +}
63039 +
63040 static inline void fscache_stat_d(atomic_t *stat)
63041 {
63042 atomic_dec(stat);
63043 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
63044
63045 #define __fscache_stat(stat) (NULL)
63046 #define fscache_stat(stat) do {} while (0)
63047 +#define fscache_stat_unchecked(stat) do {} while (0)
63048 #define fscache_stat_d(stat) do {} while (0)
63049 #endif
63050
63051 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
63052 index da032da..0076ce7 100644
63053 --- a/fs/fscache/object.c
63054 +++ b/fs/fscache/object.c
63055 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63056 _debug("LOOKUP \"%s\" in \"%s\"",
63057 cookie->def->name, object->cache->tag->name);
63058
63059 - fscache_stat(&fscache_n_object_lookups);
63060 + fscache_stat_unchecked(&fscache_n_object_lookups);
63061 fscache_stat(&fscache_n_cop_lookup_object);
63062 ret = object->cache->ops->lookup_object(object);
63063 fscache_stat_d(&fscache_n_cop_lookup_object);
63064 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63065 if (ret == -ETIMEDOUT) {
63066 /* probably stuck behind another object, so move this one to
63067 * the back of the queue */
63068 - fscache_stat(&fscache_n_object_lookups_timed_out);
63069 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
63070 _leave(" [timeout]");
63071 return NO_TRANSIT;
63072 }
63073 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
63074 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
63075
63076 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63077 - fscache_stat(&fscache_n_object_lookups_negative);
63078 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
63079
63080 /* Allow write requests to begin stacking up and read requests to begin
63081 * returning ENODATA.
63082 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
63083 /* if we were still looking up, then we must have a positive lookup
63084 * result, in which case there may be data available */
63085 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63086 - fscache_stat(&fscache_n_object_lookups_positive);
63087 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
63088
63089 /* We do (presumably) have data */
63090 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
63091 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
63092 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
63093 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
63094 } else {
63095 - fscache_stat(&fscache_n_object_created);
63096 + fscache_stat_unchecked(&fscache_n_object_created);
63097 }
63098
63099 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
63100 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
63101 fscache_stat_d(&fscache_n_cop_lookup_complete);
63102
63103 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63104 - fscache_stat(&fscache_n_object_avail);
63105 + fscache_stat_unchecked(&fscache_n_object_avail);
63106
63107 _leave("");
63108 return transit_to(JUMPSTART_DEPS);
63109 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63110
63111 /* this just shifts the object release to the work processor */
63112 fscache_put_object(object);
63113 - fscache_stat(&fscache_n_object_dead);
63114 + fscache_stat_unchecked(&fscache_n_object_dead);
63115
63116 _leave("");
63117 return transit_to(OBJECT_DEAD);
63118 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63119 enum fscache_checkaux result;
63120
63121 if (!object->cookie->def->check_aux) {
63122 - fscache_stat(&fscache_n_checkaux_none);
63123 + fscache_stat_unchecked(&fscache_n_checkaux_none);
63124 return FSCACHE_CHECKAUX_OKAY;
63125 }
63126
63127 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63128 switch (result) {
63129 /* entry okay as is */
63130 case FSCACHE_CHECKAUX_OKAY:
63131 - fscache_stat(&fscache_n_checkaux_okay);
63132 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
63133 break;
63134
63135 /* entry requires update */
63136 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63137 - fscache_stat(&fscache_n_checkaux_update);
63138 + fscache_stat_unchecked(&fscache_n_checkaux_update);
63139 break;
63140
63141 /* entry requires deletion */
63142 case FSCACHE_CHECKAUX_OBSOLETE:
63143 - fscache_stat(&fscache_n_checkaux_obsolete);
63144 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63145 break;
63146
63147 default:
63148 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63149 {
63150 const struct fscache_state *s;
63151
63152 - fscache_stat(&fscache_n_invalidates_run);
63153 + fscache_stat_unchecked(&fscache_n_invalidates_run);
63154 fscache_stat(&fscache_n_cop_invalidate_object);
63155 s = _fscache_invalidate_object(object, event);
63156 fscache_stat_d(&fscache_n_cop_invalidate_object);
63157 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63158 {
63159 _enter("{OBJ%x},%d", object->debug_id, event);
63160
63161 - fscache_stat(&fscache_n_updates_run);
63162 + fscache_stat_unchecked(&fscache_n_updates_run);
63163 fscache_stat(&fscache_n_cop_update_object);
63164 object->cache->ops->update_object(object);
63165 fscache_stat_d(&fscache_n_cop_update_object);
63166 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63167 index e7b87a0..a85d47a 100644
63168 --- a/fs/fscache/operation.c
63169 +++ b/fs/fscache/operation.c
63170 @@ -17,7 +17,7 @@
63171 #include <linux/slab.h>
63172 #include "internal.h"
63173
63174 -atomic_t fscache_op_debug_id;
63175 +atomic_unchecked_t fscache_op_debug_id;
63176 EXPORT_SYMBOL(fscache_op_debug_id);
63177
63178 /**
63179 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63180 ASSERTCMP(atomic_read(&op->usage), >, 0);
63181 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63182
63183 - fscache_stat(&fscache_n_op_enqueue);
63184 + fscache_stat_unchecked(&fscache_n_op_enqueue);
63185 switch (op->flags & FSCACHE_OP_TYPE) {
63186 case FSCACHE_OP_ASYNC:
63187 _debug("queue async");
63188 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63189 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63190 if (op->processor)
63191 fscache_enqueue_operation(op);
63192 - fscache_stat(&fscache_n_op_run);
63193 + fscache_stat_unchecked(&fscache_n_op_run);
63194 }
63195
63196 /*
63197 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63198 if (object->n_in_progress > 0) {
63199 atomic_inc(&op->usage);
63200 list_add_tail(&op->pend_link, &object->pending_ops);
63201 - fscache_stat(&fscache_n_op_pend);
63202 + fscache_stat_unchecked(&fscache_n_op_pend);
63203 } else if (!list_empty(&object->pending_ops)) {
63204 atomic_inc(&op->usage);
63205 list_add_tail(&op->pend_link, &object->pending_ops);
63206 - fscache_stat(&fscache_n_op_pend);
63207 + fscache_stat_unchecked(&fscache_n_op_pend);
63208 fscache_start_operations(object);
63209 } else {
63210 ASSERTCMP(object->n_in_progress, ==, 0);
63211 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63212 object->n_exclusive++; /* reads and writes must wait */
63213 atomic_inc(&op->usage);
63214 list_add_tail(&op->pend_link, &object->pending_ops);
63215 - fscache_stat(&fscache_n_op_pend);
63216 + fscache_stat_unchecked(&fscache_n_op_pend);
63217 ret = 0;
63218 } else {
63219 /* If we're in any other state, there must have been an I/O
63220 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63221 if (object->n_exclusive > 0) {
63222 atomic_inc(&op->usage);
63223 list_add_tail(&op->pend_link, &object->pending_ops);
63224 - fscache_stat(&fscache_n_op_pend);
63225 + fscache_stat_unchecked(&fscache_n_op_pend);
63226 } else if (!list_empty(&object->pending_ops)) {
63227 atomic_inc(&op->usage);
63228 list_add_tail(&op->pend_link, &object->pending_ops);
63229 - fscache_stat(&fscache_n_op_pend);
63230 + fscache_stat_unchecked(&fscache_n_op_pend);
63231 fscache_start_operations(object);
63232 } else {
63233 ASSERTCMP(object->n_exclusive, ==, 0);
63234 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63235 object->n_ops++;
63236 atomic_inc(&op->usage);
63237 list_add_tail(&op->pend_link, &object->pending_ops);
63238 - fscache_stat(&fscache_n_op_pend);
63239 + fscache_stat_unchecked(&fscache_n_op_pend);
63240 ret = 0;
63241 } else if (fscache_object_is_dying(object)) {
63242 - fscache_stat(&fscache_n_op_rejected);
63243 + fscache_stat_unchecked(&fscache_n_op_rejected);
63244 op->state = FSCACHE_OP_ST_CANCELLED;
63245 ret = -ENOBUFS;
63246 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63247 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63248 ret = -EBUSY;
63249 if (op->state == FSCACHE_OP_ST_PENDING) {
63250 ASSERT(!list_empty(&op->pend_link));
63251 - fscache_stat(&fscache_n_op_cancelled);
63252 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63253 list_del_init(&op->pend_link);
63254 if (do_cancel)
63255 do_cancel(op);
63256 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63257 while (!list_empty(&object->pending_ops)) {
63258 op = list_entry(object->pending_ops.next,
63259 struct fscache_operation, pend_link);
63260 - fscache_stat(&fscache_n_op_cancelled);
63261 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63262 list_del_init(&op->pend_link);
63263
63264 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63265 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63266 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63267 op->state = FSCACHE_OP_ST_DEAD;
63268
63269 - fscache_stat(&fscache_n_op_release);
63270 + fscache_stat_unchecked(&fscache_n_op_release);
63271
63272 if (op->release) {
63273 op->release(op);
63274 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63275 * lock, and defer it otherwise */
63276 if (!spin_trylock(&object->lock)) {
63277 _debug("defer put");
63278 - fscache_stat(&fscache_n_op_deferred_release);
63279 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63280
63281 cache = object->cache;
63282 spin_lock(&cache->op_gc_list_lock);
63283 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63284
63285 _debug("GC DEFERRED REL OBJ%x OP%x",
63286 object->debug_id, op->debug_id);
63287 - fscache_stat(&fscache_n_op_gc);
63288 + fscache_stat_unchecked(&fscache_n_op_gc);
63289
63290 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63291 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63292 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63293 index de33b3f..8be4d29 100644
63294 --- a/fs/fscache/page.c
63295 +++ b/fs/fscache/page.c
63296 @@ -74,7 +74,7 @@ try_again:
63297 val = radix_tree_lookup(&cookie->stores, page->index);
63298 if (!val) {
63299 rcu_read_unlock();
63300 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63301 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63302 __fscache_uncache_page(cookie, page);
63303 return true;
63304 }
63305 @@ -104,11 +104,11 @@ try_again:
63306 spin_unlock(&cookie->stores_lock);
63307
63308 if (xpage) {
63309 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63310 - fscache_stat(&fscache_n_store_radix_deletes);
63311 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63312 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63313 ASSERTCMP(xpage, ==, page);
63314 } else {
63315 - fscache_stat(&fscache_n_store_vmscan_gone);
63316 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63317 }
63318
63319 wake_up_bit(&cookie->flags, 0);
63320 @@ -123,11 +123,11 @@ page_busy:
63321 * sleeping on memory allocation, so we may need to impose a timeout
63322 * too. */
63323 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63324 - fscache_stat(&fscache_n_store_vmscan_busy);
63325 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63326 return false;
63327 }
63328
63329 - fscache_stat(&fscache_n_store_vmscan_wait);
63330 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63331 if (!release_page_wait_timeout(cookie, page))
63332 _debug("fscache writeout timeout page: %p{%lx}",
63333 page, page->index);
63334 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63335 FSCACHE_COOKIE_STORING_TAG);
63336 if (!radix_tree_tag_get(&cookie->stores, page->index,
63337 FSCACHE_COOKIE_PENDING_TAG)) {
63338 - fscache_stat(&fscache_n_store_radix_deletes);
63339 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63340 xpage = radix_tree_delete(&cookie->stores, page->index);
63341 }
63342 spin_unlock(&cookie->stores_lock);
63343 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63344
63345 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63346
63347 - fscache_stat(&fscache_n_attr_changed_calls);
63348 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63349
63350 if (fscache_object_is_active(object)) {
63351 fscache_stat(&fscache_n_cop_attr_changed);
63352 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63353
63354 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63355
63356 - fscache_stat(&fscache_n_attr_changed);
63357 + fscache_stat_unchecked(&fscache_n_attr_changed);
63358
63359 op = kzalloc(sizeof(*op), GFP_KERNEL);
63360 if (!op) {
63361 - fscache_stat(&fscache_n_attr_changed_nomem);
63362 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63363 _leave(" = -ENOMEM");
63364 return -ENOMEM;
63365 }
63366 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63367 if (fscache_submit_exclusive_op(object, op) < 0)
63368 goto nobufs_dec;
63369 spin_unlock(&cookie->lock);
63370 - fscache_stat(&fscache_n_attr_changed_ok);
63371 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63372 fscache_put_operation(op);
63373 _leave(" = 0");
63374 return 0;
63375 @@ -242,7 +242,7 @@ nobufs:
63376 kfree(op);
63377 if (wake_cookie)
63378 __fscache_wake_unused_cookie(cookie);
63379 - fscache_stat(&fscache_n_attr_changed_nobufs);
63380 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63381 _leave(" = %d", -ENOBUFS);
63382 return -ENOBUFS;
63383 }
63384 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63385 /* allocate a retrieval operation and attempt to submit it */
63386 op = kzalloc(sizeof(*op), GFP_NOIO);
63387 if (!op) {
63388 - fscache_stat(&fscache_n_retrievals_nomem);
63389 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63390 return NULL;
63391 }
63392
63393 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63394 return 0;
63395 }
63396
63397 - fscache_stat(&fscache_n_retrievals_wait);
63398 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63399
63400 jif = jiffies;
63401 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63402 TASK_INTERRUPTIBLE) != 0) {
63403 - fscache_stat(&fscache_n_retrievals_intr);
63404 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63405 _leave(" = -ERESTARTSYS");
63406 return -ERESTARTSYS;
63407 }
63408 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63409 */
63410 int fscache_wait_for_operation_activation(struct fscache_object *object,
63411 struct fscache_operation *op,
63412 - atomic_t *stat_op_waits,
63413 - atomic_t *stat_object_dead,
63414 + atomic_unchecked_t *stat_op_waits,
63415 + atomic_unchecked_t *stat_object_dead,
63416 void (*do_cancel)(struct fscache_operation *))
63417 {
63418 int ret;
63419 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63420
63421 _debug(">>> WT");
63422 if (stat_op_waits)
63423 - fscache_stat(stat_op_waits);
63424 + fscache_stat_unchecked(stat_op_waits);
63425 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63426 TASK_INTERRUPTIBLE) != 0) {
63427 ret = fscache_cancel_op(op, do_cancel);
63428 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63429 check_if_dead:
63430 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63431 if (stat_object_dead)
63432 - fscache_stat(stat_object_dead);
63433 + fscache_stat_unchecked(stat_object_dead);
63434 _leave(" = -ENOBUFS [cancelled]");
63435 return -ENOBUFS;
63436 }
63437 @@ -381,7 +381,7 @@ check_if_dead:
63438 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63439 fscache_cancel_op(op, do_cancel);
63440 if (stat_object_dead)
63441 - fscache_stat(stat_object_dead);
63442 + fscache_stat_unchecked(stat_object_dead);
63443 return -ENOBUFS;
63444 }
63445 return 0;
63446 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63447
63448 _enter("%p,%p,,,", cookie, page);
63449
63450 - fscache_stat(&fscache_n_retrievals);
63451 + fscache_stat_unchecked(&fscache_n_retrievals);
63452
63453 if (hlist_empty(&cookie->backing_objects))
63454 goto nobufs;
63455 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63456 goto nobufs_unlock_dec;
63457 spin_unlock(&cookie->lock);
63458
63459 - fscache_stat(&fscache_n_retrieval_ops);
63460 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63461
63462 /* pin the netfs read context in case we need to do the actual netfs
63463 * read because we've encountered a cache read failure */
63464 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63465
63466 error:
63467 if (ret == -ENOMEM)
63468 - fscache_stat(&fscache_n_retrievals_nomem);
63469 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63470 else if (ret == -ERESTARTSYS)
63471 - fscache_stat(&fscache_n_retrievals_intr);
63472 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63473 else if (ret == -ENODATA)
63474 - fscache_stat(&fscache_n_retrievals_nodata);
63475 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63476 else if (ret < 0)
63477 - fscache_stat(&fscache_n_retrievals_nobufs);
63478 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63479 else
63480 - fscache_stat(&fscache_n_retrievals_ok);
63481 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63482
63483 fscache_put_retrieval(op);
63484 _leave(" = %d", ret);
63485 @@ -505,7 +505,7 @@ nobufs_unlock:
63486 __fscache_wake_unused_cookie(cookie);
63487 kfree(op);
63488 nobufs:
63489 - fscache_stat(&fscache_n_retrievals_nobufs);
63490 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63491 _leave(" = -ENOBUFS");
63492 return -ENOBUFS;
63493 }
63494 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63495
63496 _enter("%p,,%d,,,", cookie, *nr_pages);
63497
63498 - fscache_stat(&fscache_n_retrievals);
63499 + fscache_stat_unchecked(&fscache_n_retrievals);
63500
63501 if (hlist_empty(&cookie->backing_objects))
63502 goto nobufs;
63503 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63504 goto nobufs_unlock_dec;
63505 spin_unlock(&cookie->lock);
63506
63507 - fscache_stat(&fscache_n_retrieval_ops);
63508 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63509
63510 /* pin the netfs read context in case we need to do the actual netfs
63511 * read because we've encountered a cache read failure */
63512 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63513
63514 error:
63515 if (ret == -ENOMEM)
63516 - fscache_stat(&fscache_n_retrievals_nomem);
63517 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63518 else if (ret == -ERESTARTSYS)
63519 - fscache_stat(&fscache_n_retrievals_intr);
63520 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63521 else if (ret == -ENODATA)
63522 - fscache_stat(&fscache_n_retrievals_nodata);
63523 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63524 else if (ret < 0)
63525 - fscache_stat(&fscache_n_retrievals_nobufs);
63526 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63527 else
63528 - fscache_stat(&fscache_n_retrievals_ok);
63529 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63530
63531 fscache_put_retrieval(op);
63532 _leave(" = %d", ret);
63533 @@ -636,7 +636,7 @@ nobufs_unlock:
63534 if (wake_cookie)
63535 __fscache_wake_unused_cookie(cookie);
63536 nobufs:
63537 - fscache_stat(&fscache_n_retrievals_nobufs);
63538 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63539 _leave(" = -ENOBUFS");
63540 return -ENOBUFS;
63541 }
63542 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63543
63544 _enter("%p,%p,,,", cookie, page);
63545
63546 - fscache_stat(&fscache_n_allocs);
63547 + fscache_stat_unchecked(&fscache_n_allocs);
63548
63549 if (hlist_empty(&cookie->backing_objects))
63550 goto nobufs;
63551 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63552 goto nobufs_unlock_dec;
63553 spin_unlock(&cookie->lock);
63554
63555 - fscache_stat(&fscache_n_alloc_ops);
63556 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63557
63558 ret = fscache_wait_for_operation_activation(
63559 object, &op->op,
63560 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63561
63562 error:
63563 if (ret == -ERESTARTSYS)
63564 - fscache_stat(&fscache_n_allocs_intr);
63565 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63566 else if (ret < 0)
63567 - fscache_stat(&fscache_n_allocs_nobufs);
63568 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63569 else
63570 - fscache_stat(&fscache_n_allocs_ok);
63571 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63572
63573 fscache_put_retrieval(op);
63574 _leave(" = %d", ret);
63575 @@ -730,7 +730,7 @@ nobufs_unlock:
63576 if (wake_cookie)
63577 __fscache_wake_unused_cookie(cookie);
63578 nobufs:
63579 - fscache_stat(&fscache_n_allocs_nobufs);
63580 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63581 _leave(" = -ENOBUFS");
63582 return -ENOBUFS;
63583 }
63584 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63585
63586 spin_lock(&cookie->stores_lock);
63587
63588 - fscache_stat(&fscache_n_store_calls);
63589 + fscache_stat_unchecked(&fscache_n_store_calls);
63590
63591 /* find a page to store */
63592 page = NULL;
63593 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63594 page = results[0];
63595 _debug("gang %d [%lx]", n, page->index);
63596 if (page->index > op->store_limit) {
63597 - fscache_stat(&fscache_n_store_pages_over_limit);
63598 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63599 goto superseded;
63600 }
63601
63602 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63603 spin_unlock(&cookie->stores_lock);
63604 spin_unlock(&object->lock);
63605
63606 - fscache_stat(&fscache_n_store_pages);
63607 + fscache_stat_unchecked(&fscache_n_store_pages);
63608 fscache_stat(&fscache_n_cop_write_page);
63609 ret = object->cache->ops->write_page(op, page);
63610 fscache_stat_d(&fscache_n_cop_write_page);
63611 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63612 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63613 ASSERT(PageFsCache(page));
63614
63615 - fscache_stat(&fscache_n_stores);
63616 + fscache_stat_unchecked(&fscache_n_stores);
63617
63618 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63619 _leave(" = -ENOBUFS [invalidating]");
63620 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63621 spin_unlock(&cookie->stores_lock);
63622 spin_unlock(&object->lock);
63623
63624 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63625 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63626 op->store_limit = object->store_limit;
63627
63628 __fscache_use_cookie(cookie);
63629 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63630
63631 spin_unlock(&cookie->lock);
63632 radix_tree_preload_end();
63633 - fscache_stat(&fscache_n_store_ops);
63634 - fscache_stat(&fscache_n_stores_ok);
63635 + fscache_stat_unchecked(&fscache_n_store_ops);
63636 + fscache_stat_unchecked(&fscache_n_stores_ok);
63637
63638 /* the work queue now carries its own ref on the object */
63639 fscache_put_operation(&op->op);
63640 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63641 return 0;
63642
63643 already_queued:
63644 - fscache_stat(&fscache_n_stores_again);
63645 + fscache_stat_unchecked(&fscache_n_stores_again);
63646 already_pending:
63647 spin_unlock(&cookie->stores_lock);
63648 spin_unlock(&object->lock);
63649 spin_unlock(&cookie->lock);
63650 radix_tree_preload_end();
63651 kfree(op);
63652 - fscache_stat(&fscache_n_stores_ok);
63653 + fscache_stat_unchecked(&fscache_n_stores_ok);
63654 _leave(" = 0");
63655 return 0;
63656
63657 @@ -1039,14 +1039,14 @@ nobufs:
63658 kfree(op);
63659 if (wake_cookie)
63660 __fscache_wake_unused_cookie(cookie);
63661 - fscache_stat(&fscache_n_stores_nobufs);
63662 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63663 _leave(" = -ENOBUFS");
63664 return -ENOBUFS;
63665
63666 nomem_free:
63667 kfree(op);
63668 nomem:
63669 - fscache_stat(&fscache_n_stores_oom);
63670 + fscache_stat_unchecked(&fscache_n_stores_oom);
63671 _leave(" = -ENOMEM");
63672 return -ENOMEM;
63673 }
63674 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63675 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63676 ASSERTCMP(page, !=, NULL);
63677
63678 - fscache_stat(&fscache_n_uncaches);
63679 + fscache_stat_unchecked(&fscache_n_uncaches);
63680
63681 /* cache withdrawal may beat us to it */
63682 if (!PageFsCache(page))
63683 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63684 struct fscache_cookie *cookie = op->op.object->cookie;
63685
63686 #ifdef CONFIG_FSCACHE_STATS
63687 - atomic_inc(&fscache_n_marks);
63688 + atomic_inc_unchecked(&fscache_n_marks);
63689 #endif
63690
63691 _debug("- mark %p{%lx}", page, page->index);
63692 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63693 index 40d13c7..ddf52b9 100644
63694 --- a/fs/fscache/stats.c
63695 +++ b/fs/fscache/stats.c
63696 @@ -18,99 +18,99 @@
63697 /*
63698 * operation counters
63699 */
63700 -atomic_t fscache_n_op_pend;
63701 -atomic_t fscache_n_op_run;
63702 -atomic_t fscache_n_op_enqueue;
63703 -atomic_t fscache_n_op_requeue;
63704 -atomic_t fscache_n_op_deferred_release;
63705 -atomic_t fscache_n_op_release;
63706 -atomic_t fscache_n_op_gc;
63707 -atomic_t fscache_n_op_cancelled;
63708 -atomic_t fscache_n_op_rejected;
63709 +atomic_unchecked_t fscache_n_op_pend;
63710 +atomic_unchecked_t fscache_n_op_run;
63711 +atomic_unchecked_t fscache_n_op_enqueue;
63712 +atomic_unchecked_t fscache_n_op_requeue;
63713 +atomic_unchecked_t fscache_n_op_deferred_release;
63714 +atomic_unchecked_t fscache_n_op_release;
63715 +atomic_unchecked_t fscache_n_op_gc;
63716 +atomic_unchecked_t fscache_n_op_cancelled;
63717 +atomic_unchecked_t fscache_n_op_rejected;
63718
63719 -atomic_t fscache_n_attr_changed;
63720 -atomic_t fscache_n_attr_changed_ok;
63721 -atomic_t fscache_n_attr_changed_nobufs;
63722 -atomic_t fscache_n_attr_changed_nomem;
63723 -atomic_t fscache_n_attr_changed_calls;
63724 +atomic_unchecked_t fscache_n_attr_changed;
63725 +atomic_unchecked_t fscache_n_attr_changed_ok;
63726 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63727 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63728 +atomic_unchecked_t fscache_n_attr_changed_calls;
63729
63730 -atomic_t fscache_n_allocs;
63731 -atomic_t fscache_n_allocs_ok;
63732 -atomic_t fscache_n_allocs_wait;
63733 -atomic_t fscache_n_allocs_nobufs;
63734 -atomic_t fscache_n_allocs_intr;
63735 -atomic_t fscache_n_allocs_object_dead;
63736 -atomic_t fscache_n_alloc_ops;
63737 -atomic_t fscache_n_alloc_op_waits;
63738 +atomic_unchecked_t fscache_n_allocs;
63739 +atomic_unchecked_t fscache_n_allocs_ok;
63740 +atomic_unchecked_t fscache_n_allocs_wait;
63741 +atomic_unchecked_t fscache_n_allocs_nobufs;
63742 +atomic_unchecked_t fscache_n_allocs_intr;
63743 +atomic_unchecked_t fscache_n_allocs_object_dead;
63744 +atomic_unchecked_t fscache_n_alloc_ops;
63745 +atomic_unchecked_t fscache_n_alloc_op_waits;
63746
63747 -atomic_t fscache_n_retrievals;
63748 -atomic_t fscache_n_retrievals_ok;
63749 -atomic_t fscache_n_retrievals_wait;
63750 -atomic_t fscache_n_retrievals_nodata;
63751 -atomic_t fscache_n_retrievals_nobufs;
63752 -atomic_t fscache_n_retrievals_intr;
63753 -atomic_t fscache_n_retrievals_nomem;
63754 -atomic_t fscache_n_retrievals_object_dead;
63755 -atomic_t fscache_n_retrieval_ops;
63756 -atomic_t fscache_n_retrieval_op_waits;
63757 +atomic_unchecked_t fscache_n_retrievals;
63758 +atomic_unchecked_t fscache_n_retrievals_ok;
63759 +atomic_unchecked_t fscache_n_retrievals_wait;
63760 +atomic_unchecked_t fscache_n_retrievals_nodata;
63761 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63762 +atomic_unchecked_t fscache_n_retrievals_intr;
63763 +atomic_unchecked_t fscache_n_retrievals_nomem;
63764 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63765 +atomic_unchecked_t fscache_n_retrieval_ops;
63766 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63767
63768 -atomic_t fscache_n_stores;
63769 -atomic_t fscache_n_stores_ok;
63770 -atomic_t fscache_n_stores_again;
63771 -atomic_t fscache_n_stores_nobufs;
63772 -atomic_t fscache_n_stores_oom;
63773 -atomic_t fscache_n_store_ops;
63774 -atomic_t fscache_n_store_calls;
63775 -atomic_t fscache_n_store_pages;
63776 -atomic_t fscache_n_store_radix_deletes;
63777 -atomic_t fscache_n_store_pages_over_limit;
63778 +atomic_unchecked_t fscache_n_stores;
63779 +atomic_unchecked_t fscache_n_stores_ok;
63780 +atomic_unchecked_t fscache_n_stores_again;
63781 +atomic_unchecked_t fscache_n_stores_nobufs;
63782 +atomic_unchecked_t fscache_n_stores_oom;
63783 +atomic_unchecked_t fscache_n_store_ops;
63784 +atomic_unchecked_t fscache_n_store_calls;
63785 +atomic_unchecked_t fscache_n_store_pages;
63786 +atomic_unchecked_t fscache_n_store_radix_deletes;
63787 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63788
63789 -atomic_t fscache_n_store_vmscan_not_storing;
63790 -atomic_t fscache_n_store_vmscan_gone;
63791 -atomic_t fscache_n_store_vmscan_busy;
63792 -atomic_t fscache_n_store_vmscan_cancelled;
63793 -atomic_t fscache_n_store_vmscan_wait;
63794 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63795 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63796 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63797 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63798 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63799
63800 -atomic_t fscache_n_marks;
63801 -atomic_t fscache_n_uncaches;
63802 +atomic_unchecked_t fscache_n_marks;
63803 +atomic_unchecked_t fscache_n_uncaches;
63804
63805 -atomic_t fscache_n_acquires;
63806 -atomic_t fscache_n_acquires_null;
63807 -atomic_t fscache_n_acquires_no_cache;
63808 -atomic_t fscache_n_acquires_ok;
63809 -atomic_t fscache_n_acquires_nobufs;
63810 -atomic_t fscache_n_acquires_oom;
63811 +atomic_unchecked_t fscache_n_acquires;
63812 +atomic_unchecked_t fscache_n_acquires_null;
63813 +atomic_unchecked_t fscache_n_acquires_no_cache;
63814 +atomic_unchecked_t fscache_n_acquires_ok;
63815 +atomic_unchecked_t fscache_n_acquires_nobufs;
63816 +atomic_unchecked_t fscache_n_acquires_oom;
63817
63818 -atomic_t fscache_n_invalidates;
63819 -atomic_t fscache_n_invalidates_run;
63820 +atomic_unchecked_t fscache_n_invalidates;
63821 +atomic_unchecked_t fscache_n_invalidates_run;
63822
63823 -atomic_t fscache_n_updates;
63824 -atomic_t fscache_n_updates_null;
63825 -atomic_t fscache_n_updates_run;
63826 +atomic_unchecked_t fscache_n_updates;
63827 +atomic_unchecked_t fscache_n_updates_null;
63828 +atomic_unchecked_t fscache_n_updates_run;
63829
63830 -atomic_t fscache_n_relinquishes;
63831 -atomic_t fscache_n_relinquishes_null;
63832 -atomic_t fscache_n_relinquishes_waitcrt;
63833 -atomic_t fscache_n_relinquishes_retire;
63834 +atomic_unchecked_t fscache_n_relinquishes;
63835 +atomic_unchecked_t fscache_n_relinquishes_null;
63836 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63837 +atomic_unchecked_t fscache_n_relinquishes_retire;
63838
63839 -atomic_t fscache_n_cookie_index;
63840 -atomic_t fscache_n_cookie_data;
63841 -atomic_t fscache_n_cookie_special;
63842 +atomic_unchecked_t fscache_n_cookie_index;
63843 +atomic_unchecked_t fscache_n_cookie_data;
63844 +atomic_unchecked_t fscache_n_cookie_special;
63845
63846 -atomic_t fscache_n_object_alloc;
63847 -atomic_t fscache_n_object_no_alloc;
63848 -atomic_t fscache_n_object_lookups;
63849 -atomic_t fscache_n_object_lookups_negative;
63850 -atomic_t fscache_n_object_lookups_positive;
63851 -atomic_t fscache_n_object_lookups_timed_out;
63852 -atomic_t fscache_n_object_created;
63853 -atomic_t fscache_n_object_avail;
63854 -atomic_t fscache_n_object_dead;
63855 +atomic_unchecked_t fscache_n_object_alloc;
63856 +atomic_unchecked_t fscache_n_object_no_alloc;
63857 +atomic_unchecked_t fscache_n_object_lookups;
63858 +atomic_unchecked_t fscache_n_object_lookups_negative;
63859 +atomic_unchecked_t fscache_n_object_lookups_positive;
63860 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63861 +atomic_unchecked_t fscache_n_object_created;
63862 +atomic_unchecked_t fscache_n_object_avail;
63863 +atomic_unchecked_t fscache_n_object_dead;
63864
63865 -atomic_t fscache_n_checkaux_none;
63866 -atomic_t fscache_n_checkaux_okay;
63867 -atomic_t fscache_n_checkaux_update;
63868 -atomic_t fscache_n_checkaux_obsolete;
63869 +atomic_unchecked_t fscache_n_checkaux_none;
63870 +atomic_unchecked_t fscache_n_checkaux_okay;
63871 +atomic_unchecked_t fscache_n_checkaux_update;
63872 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63873
63874 atomic_t fscache_n_cop_alloc_object;
63875 atomic_t fscache_n_cop_lookup_object;
63876 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63877 seq_puts(m, "FS-Cache statistics\n");
63878
63879 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63880 - atomic_read(&fscache_n_cookie_index),
63881 - atomic_read(&fscache_n_cookie_data),
63882 - atomic_read(&fscache_n_cookie_special));
63883 + atomic_read_unchecked(&fscache_n_cookie_index),
63884 + atomic_read_unchecked(&fscache_n_cookie_data),
63885 + atomic_read_unchecked(&fscache_n_cookie_special));
63886
63887 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63888 - atomic_read(&fscache_n_object_alloc),
63889 - atomic_read(&fscache_n_object_no_alloc),
63890 - atomic_read(&fscache_n_object_avail),
63891 - atomic_read(&fscache_n_object_dead));
63892 + atomic_read_unchecked(&fscache_n_object_alloc),
63893 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63894 + atomic_read_unchecked(&fscache_n_object_avail),
63895 + atomic_read_unchecked(&fscache_n_object_dead));
63896 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63897 - atomic_read(&fscache_n_checkaux_none),
63898 - atomic_read(&fscache_n_checkaux_okay),
63899 - atomic_read(&fscache_n_checkaux_update),
63900 - atomic_read(&fscache_n_checkaux_obsolete));
63901 + atomic_read_unchecked(&fscache_n_checkaux_none),
63902 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63903 + atomic_read_unchecked(&fscache_n_checkaux_update),
63904 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63905
63906 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63907 - atomic_read(&fscache_n_marks),
63908 - atomic_read(&fscache_n_uncaches));
63909 + atomic_read_unchecked(&fscache_n_marks),
63910 + atomic_read_unchecked(&fscache_n_uncaches));
63911
63912 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63913 " oom=%u\n",
63914 - atomic_read(&fscache_n_acquires),
63915 - atomic_read(&fscache_n_acquires_null),
63916 - atomic_read(&fscache_n_acquires_no_cache),
63917 - atomic_read(&fscache_n_acquires_ok),
63918 - atomic_read(&fscache_n_acquires_nobufs),
63919 - atomic_read(&fscache_n_acquires_oom));
63920 + atomic_read_unchecked(&fscache_n_acquires),
63921 + atomic_read_unchecked(&fscache_n_acquires_null),
63922 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63923 + atomic_read_unchecked(&fscache_n_acquires_ok),
63924 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63925 + atomic_read_unchecked(&fscache_n_acquires_oom));
63926
63927 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63928 - atomic_read(&fscache_n_object_lookups),
63929 - atomic_read(&fscache_n_object_lookups_negative),
63930 - atomic_read(&fscache_n_object_lookups_positive),
63931 - atomic_read(&fscache_n_object_created),
63932 - atomic_read(&fscache_n_object_lookups_timed_out));
63933 + atomic_read_unchecked(&fscache_n_object_lookups),
63934 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63935 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63936 + atomic_read_unchecked(&fscache_n_object_created),
63937 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63938
63939 seq_printf(m, "Invals : n=%u run=%u\n",
63940 - atomic_read(&fscache_n_invalidates),
63941 - atomic_read(&fscache_n_invalidates_run));
63942 + atomic_read_unchecked(&fscache_n_invalidates),
63943 + atomic_read_unchecked(&fscache_n_invalidates_run));
63944
63945 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63946 - atomic_read(&fscache_n_updates),
63947 - atomic_read(&fscache_n_updates_null),
63948 - atomic_read(&fscache_n_updates_run));
63949 + atomic_read_unchecked(&fscache_n_updates),
63950 + atomic_read_unchecked(&fscache_n_updates_null),
63951 + atomic_read_unchecked(&fscache_n_updates_run));
63952
63953 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63954 - atomic_read(&fscache_n_relinquishes),
63955 - atomic_read(&fscache_n_relinquishes_null),
63956 - atomic_read(&fscache_n_relinquishes_waitcrt),
63957 - atomic_read(&fscache_n_relinquishes_retire));
63958 + atomic_read_unchecked(&fscache_n_relinquishes),
63959 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63960 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63961 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63962
63963 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63964 - atomic_read(&fscache_n_attr_changed),
63965 - atomic_read(&fscache_n_attr_changed_ok),
63966 - atomic_read(&fscache_n_attr_changed_nobufs),
63967 - atomic_read(&fscache_n_attr_changed_nomem),
63968 - atomic_read(&fscache_n_attr_changed_calls));
63969 + atomic_read_unchecked(&fscache_n_attr_changed),
63970 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63971 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63972 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63973 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63974
63975 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63976 - atomic_read(&fscache_n_allocs),
63977 - atomic_read(&fscache_n_allocs_ok),
63978 - atomic_read(&fscache_n_allocs_wait),
63979 - atomic_read(&fscache_n_allocs_nobufs),
63980 - atomic_read(&fscache_n_allocs_intr));
63981 + atomic_read_unchecked(&fscache_n_allocs),
63982 + atomic_read_unchecked(&fscache_n_allocs_ok),
63983 + atomic_read_unchecked(&fscache_n_allocs_wait),
63984 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63985 + atomic_read_unchecked(&fscache_n_allocs_intr));
63986 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63987 - atomic_read(&fscache_n_alloc_ops),
63988 - atomic_read(&fscache_n_alloc_op_waits),
63989 - atomic_read(&fscache_n_allocs_object_dead));
63990 + atomic_read_unchecked(&fscache_n_alloc_ops),
63991 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63992 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63993
63994 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63995 " int=%u oom=%u\n",
63996 - atomic_read(&fscache_n_retrievals),
63997 - atomic_read(&fscache_n_retrievals_ok),
63998 - atomic_read(&fscache_n_retrievals_wait),
63999 - atomic_read(&fscache_n_retrievals_nodata),
64000 - atomic_read(&fscache_n_retrievals_nobufs),
64001 - atomic_read(&fscache_n_retrievals_intr),
64002 - atomic_read(&fscache_n_retrievals_nomem));
64003 + atomic_read_unchecked(&fscache_n_retrievals),
64004 + atomic_read_unchecked(&fscache_n_retrievals_ok),
64005 + atomic_read_unchecked(&fscache_n_retrievals_wait),
64006 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
64007 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
64008 + atomic_read_unchecked(&fscache_n_retrievals_intr),
64009 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
64010 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
64011 - atomic_read(&fscache_n_retrieval_ops),
64012 - atomic_read(&fscache_n_retrieval_op_waits),
64013 - atomic_read(&fscache_n_retrievals_object_dead));
64014 + atomic_read_unchecked(&fscache_n_retrieval_ops),
64015 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
64016 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
64017
64018 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
64019 - atomic_read(&fscache_n_stores),
64020 - atomic_read(&fscache_n_stores_ok),
64021 - atomic_read(&fscache_n_stores_again),
64022 - atomic_read(&fscache_n_stores_nobufs),
64023 - atomic_read(&fscache_n_stores_oom));
64024 + atomic_read_unchecked(&fscache_n_stores),
64025 + atomic_read_unchecked(&fscache_n_stores_ok),
64026 + atomic_read_unchecked(&fscache_n_stores_again),
64027 + atomic_read_unchecked(&fscache_n_stores_nobufs),
64028 + atomic_read_unchecked(&fscache_n_stores_oom));
64029 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
64030 - atomic_read(&fscache_n_store_ops),
64031 - atomic_read(&fscache_n_store_calls),
64032 - atomic_read(&fscache_n_store_pages),
64033 - atomic_read(&fscache_n_store_radix_deletes),
64034 - atomic_read(&fscache_n_store_pages_over_limit));
64035 + atomic_read_unchecked(&fscache_n_store_ops),
64036 + atomic_read_unchecked(&fscache_n_store_calls),
64037 + atomic_read_unchecked(&fscache_n_store_pages),
64038 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
64039 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
64040
64041 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
64042 - atomic_read(&fscache_n_store_vmscan_not_storing),
64043 - atomic_read(&fscache_n_store_vmscan_gone),
64044 - atomic_read(&fscache_n_store_vmscan_busy),
64045 - atomic_read(&fscache_n_store_vmscan_cancelled),
64046 - atomic_read(&fscache_n_store_vmscan_wait));
64047 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
64048 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
64049 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
64050 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
64051 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
64052
64053 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
64054 - atomic_read(&fscache_n_op_pend),
64055 - atomic_read(&fscache_n_op_run),
64056 - atomic_read(&fscache_n_op_enqueue),
64057 - atomic_read(&fscache_n_op_cancelled),
64058 - atomic_read(&fscache_n_op_rejected));
64059 + atomic_read_unchecked(&fscache_n_op_pend),
64060 + atomic_read_unchecked(&fscache_n_op_run),
64061 + atomic_read_unchecked(&fscache_n_op_enqueue),
64062 + atomic_read_unchecked(&fscache_n_op_cancelled),
64063 + atomic_read_unchecked(&fscache_n_op_rejected));
64064 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
64065 - atomic_read(&fscache_n_op_deferred_release),
64066 - atomic_read(&fscache_n_op_release),
64067 - atomic_read(&fscache_n_op_gc));
64068 + atomic_read_unchecked(&fscache_n_op_deferred_release),
64069 + atomic_read_unchecked(&fscache_n_op_release),
64070 + atomic_read_unchecked(&fscache_n_op_gc));
64071
64072 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
64073 atomic_read(&fscache_n_cop_alloc_object),
64074 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
64075 index 966ace8..030a03a 100644
64076 --- a/fs/fuse/cuse.c
64077 +++ b/fs/fuse/cuse.c
64078 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
64079 INIT_LIST_HEAD(&cuse_conntbl[i]);
64080
64081 /* inherit and extend fuse_dev_operations */
64082 - cuse_channel_fops = fuse_dev_operations;
64083 - cuse_channel_fops.owner = THIS_MODULE;
64084 - cuse_channel_fops.open = cuse_channel_open;
64085 - cuse_channel_fops.release = cuse_channel_release;
64086 + pax_open_kernel();
64087 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
64088 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
64089 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
64090 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
64091 + pax_close_kernel();
64092
64093 cuse_class = class_create(THIS_MODULE, "cuse");
64094 if (IS_ERR(cuse_class))
64095 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
64096 index ca88731..8e9c55d 100644
64097 --- a/fs/fuse/dev.c
64098 +++ b/fs/fuse/dev.c
64099 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64100 ret = 0;
64101 pipe_lock(pipe);
64102
64103 - if (!pipe->readers) {
64104 + if (!atomic_read(&pipe->readers)) {
64105 send_sig(SIGPIPE, current, 0);
64106 if (!ret)
64107 ret = -EPIPE;
64108 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64109 page_nr++;
64110 ret += buf->len;
64111
64112 - if (pipe->files)
64113 + if (atomic_read(&pipe->files))
64114 do_wakeup = 1;
64115 }
64116
64117 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64118 index de1d84a..fd69c0c 100644
64119 --- a/fs/fuse/dir.c
64120 +++ b/fs/fuse/dir.c
64121 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
64122 return link;
64123 }
64124
64125 -static void free_link(char *link)
64126 +static void free_link(const char *link)
64127 {
64128 if (!IS_ERR(link))
64129 free_page((unsigned long) link);
64130 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64131 index fd62cae..3494dfa 100644
64132 --- a/fs/hostfs/hostfs_kern.c
64133 +++ b/fs/hostfs/hostfs_kern.c
64134 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64135
64136 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64137 {
64138 - char *s = nd_get_link(nd);
64139 + const char *s = nd_get_link(nd);
64140 if (!IS_ERR(s))
64141 __putname(s);
64142 }
64143 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64144 index 1e2872b..7aea000 100644
64145 --- a/fs/hugetlbfs/inode.c
64146 +++ b/fs/hugetlbfs/inode.c
64147 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64148 struct mm_struct *mm = current->mm;
64149 struct vm_area_struct *vma;
64150 struct hstate *h = hstate_file(file);
64151 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64152 struct vm_unmapped_area_info info;
64153
64154 if (len & ~huge_page_mask(h))
64155 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64156 return addr;
64157 }
64158
64159 +#ifdef CONFIG_PAX_RANDMMAP
64160 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64161 +#endif
64162 +
64163 if (addr) {
64164 addr = ALIGN(addr, huge_page_size(h));
64165 vma = find_vma(mm, addr);
64166 - if (TASK_SIZE - len >= addr &&
64167 - (!vma || addr + len <= vma->vm_start))
64168 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64169 return addr;
64170 }
64171
64172 info.flags = 0;
64173 info.length = len;
64174 info.low_limit = TASK_UNMAPPED_BASE;
64175 +
64176 +#ifdef CONFIG_PAX_RANDMMAP
64177 + if (mm->pax_flags & MF_PAX_RANDMMAP)
64178 + info.low_limit += mm->delta_mmap;
64179 +#endif
64180 +
64181 info.high_limit = TASK_SIZE;
64182 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64183 info.align_offset = 0;
64184 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64185 };
64186 MODULE_ALIAS_FS("hugetlbfs");
64187
64188 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64189 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64190
64191 static int can_do_hugetlb_shm(void)
64192 {
64193 diff --git a/fs/inode.c b/fs/inode.c
64194 index 26753ba..d19eb34 100644
64195 --- a/fs/inode.c
64196 +++ b/fs/inode.c
64197 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
64198 unsigned int *p = &get_cpu_var(last_ino);
64199 unsigned int res = *p;
64200
64201 +start:
64202 +
64203 #ifdef CONFIG_SMP
64204 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64205 - static atomic_t shared_last_ino;
64206 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64207 + static atomic_unchecked_t shared_last_ino;
64208 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64209
64210 res = next - LAST_INO_BATCH;
64211 }
64212 #endif
64213
64214 - *p = ++res;
64215 + if (unlikely(!++res))
64216 + goto start; /* never zero */
64217 + *p = res;
64218 put_cpu_var(last_ino);
64219 return res;
64220 }
64221 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64222 index 4a6cf28..d3a29d3 100644
64223 --- a/fs/jffs2/erase.c
64224 +++ b/fs/jffs2/erase.c
64225 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64226 struct jffs2_unknown_node marker = {
64227 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64228 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64229 - .totlen = cpu_to_je32(c->cleanmarker_size)
64230 + .totlen = cpu_to_je32(c->cleanmarker_size),
64231 + .hdr_crc = cpu_to_je32(0)
64232 };
64233
64234 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64235 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64236 index 09ed551..45684f8 100644
64237 --- a/fs/jffs2/wbuf.c
64238 +++ b/fs/jffs2/wbuf.c
64239 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64240 {
64241 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64242 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64243 - .totlen = constant_cpu_to_je32(8)
64244 + .totlen = constant_cpu_to_je32(8),
64245 + .hdr_crc = constant_cpu_to_je32(0)
64246 };
64247
64248 /*
64249 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64250 index adf8cb0..bb935fa 100644
64251 --- a/fs/jfs/super.c
64252 +++ b/fs/jfs/super.c
64253 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64254
64255 jfs_inode_cachep =
64256 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64257 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64258 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64259 init_once);
64260 if (jfs_inode_cachep == NULL)
64261 return -ENOMEM;
64262 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64263 index a693f5b..82276a1 100644
64264 --- a/fs/kernfs/dir.c
64265 +++ b/fs/kernfs/dir.c
64266 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64267 *
64268 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64269 */
64270 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
64271 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64272 {
64273 unsigned long hash = init_name_hash();
64274 unsigned int len = strlen(name);
64275 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64276 index 4429d6d..9831f52 100644
64277 --- a/fs/kernfs/file.c
64278 +++ b/fs/kernfs/file.c
64279 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64280
64281 struct kernfs_open_node {
64282 atomic_t refcnt;
64283 - atomic_t event;
64284 + atomic_unchecked_t event;
64285 wait_queue_head_t poll;
64286 struct list_head files; /* goes through kernfs_open_file.list */
64287 };
64288 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64289 {
64290 struct kernfs_open_file *of = sf->private;
64291
64292 - of->event = atomic_read(&of->kn->attr.open->event);
64293 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64294
64295 return of->kn->attr.ops->seq_show(sf, v);
64296 }
64297 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64298 return ret;
64299 }
64300
64301 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64302 - void *buf, int len, int write)
64303 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64304 + void *buf, size_t len, int write)
64305 {
64306 struct file *file = vma->vm_file;
64307 struct kernfs_open_file *of = kernfs_of(file);
64308 - int ret;
64309 + ssize_t ret;
64310
64311 if (!of->vm_ops)
64312 return -EINVAL;
64313 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64314 return -ENOMEM;
64315
64316 atomic_set(&new_on->refcnt, 0);
64317 - atomic_set(&new_on->event, 1);
64318 + atomic_set_unchecked(&new_on->event, 1);
64319 init_waitqueue_head(&new_on->poll);
64320 INIT_LIST_HEAD(&new_on->files);
64321 goto retry;
64322 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64323
64324 kernfs_put_active(kn);
64325
64326 - if (of->event != atomic_read(&on->event))
64327 + if (of->event != atomic_read_unchecked(&on->event))
64328 goto trigger;
64329
64330 return DEFAULT_POLLMASK;
64331 @@ -818,7 +818,7 @@ repeat:
64332
64333 on = kn->attr.open;
64334 if (on) {
64335 - atomic_inc(&on->event);
64336 + atomic_inc_unchecked(&on->event);
64337 wake_up_interruptible(&on->poll);
64338 }
64339
64340 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64341 index 8a19889..4c3069a 100644
64342 --- a/fs/kernfs/symlink.c
64343 +++ b/fs/kernfs/symlink.c
64344 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64345 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64346 void *cookie)
64347 {
64348 - char *page = nd_get_link(nd);
64349 + const char *page = nd_get_link(nd);
64350 if (!IS_ERR(page))
64351 free_page((unsigned long)page);
64352 }
64353 diff --git a/fs/libfs.c b/fs/libfs.c
64354 index 88e3e00..979c262 100644
64355 --- a/fs/libfs.c
64356 +++ b/fs/libfs.c
64357 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64358
64359 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64360 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64361 + char d_name[sizeof(next->d_iname)];
64362 + const unsigned char *name;
64363 +
64364 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64365 if (!simple_positive(next)) {
64366 spin_unlock(&next->d_lock);
64367 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64368
64369 spin_unlock(&next->d_lock);
64370 spin_unlock(&dentry->d_lock);
64371 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64372 + name = next->d_name.name;
64373 + if (name == next->d_iname) {
64374 + memcpy(d_name, name, next->d_name.len);
64375 + name = d_name;
64376 + }
64377 + if (!dir_emit(ctx, name, next->d_name.len,
64378 next->d_inode->i_ino, dt_type(next->d_inode)))
64379 return 0;
64380 spin_lock(&dentry->d_lock);
64381 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64382 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64383 void *cookie)
64384 {
64385 - char *s = nd_get_link(nd);
64386 + const char *s = nd_get_link(nd);
64387 if (!IS_ERR(s))
64388 kfree(s);
64389 }
64390 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64391 index acd3947..1f896e2 100644
64392 --- a/fs/lockd/clntproc.c
64393 +++ b/fs/lockd/clntproc.c
64394 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64395 /*
64396 * Cookie counter for NLM requests
64397 */
64398 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64399 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64400
64401 void nlmclnt_next_cookie(struct nlm_cookie *c)
64402 {
64403 - u32 cookie = atomic_inc_return(&nlm_cookie);
64404 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64405
64406 memcpy(c->data, &cookie, 4);
64407 c->len=4;
64408 diff --git a/fs/locks.c b/fs/locks.c
64409 index bb08857..f65e8bf 100644
64410 --- a/fs/locks.c
64411 +++ b/fs/locks.c
64412 @@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
64413 locks_remove_posix(filp, filp);
64414
64415 if (filp->f_op->flock) {
64416 - struct file_lock fl = {
64417 + struct file_lock flock = {
64418 .fl_owner = filp,
64419 .fl_pid = current->tgid,
64420 .fl_file = filp,
64421 @@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
64422 .fl_type = F_UNLCK,
64423 .fl_end = OFFSET_MAX,
64424 };
64425 - filp->f_op->flock(filp, F_SETLKW, &fl);
64426 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64427 - fl.fl_ops->fl_release_private(&fl);
64428 + filp->f_op->flock(filp, F_SETLKW, &flock);
64429 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64430 + flock.fl_ops->fl_release_private(&flock);
64431 }
64432
64433 spin_lock(&inode->i_lock);
64434 diff --git a/fs/mount.h b/fs/mount.h
64435 index 6740a62..ccb472f 100644
64436 --- a/fs/mount.h
64437 +++ b/fs/mount.h
64438 @@ -11,7 +11,7 @@ struct mnt_namespace {
64439 u64 seq; /* Sequence number to prevent loops */
64440 wait_queue_head_t poll;
64441 u64 event;
64442 -};
64443 +} __randomize_layout;
64444
64445 struct mnt_pcp {
64446 int mnt_count;
64447 @@ -57,7 +57,7 @@ struct mount {
64448 int mnt_expiry_mark; /* true if marked for expiry */
64449 struct hlist_head mnt_pins;
64450 struct path mnt_ex_mountpoint;
64451 -};
64452 +} __randomize_layout;
64453
64454 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64455
64456 diff --git a/fs/namei.c b/fs/namei.c
64457 index bb02687..79cba2c 100644
64458 --- a/fs/namei.c
64459 +++ b/fs/namei.c
64460 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64461 if (ret != -EACCES)
64462 return ret;
64463
64464 +#ifdef CONFIG_GRKERNSEC
64465 + /* we'll block if we have to log due to a denied capability use */
64466 + if (mask & MAY_NOT_BLOCK)
64467 + return -ECHILD;
64468 +#endif
64469 +
64470 if (S_ISDIR(inode->i_mode)) {
64471 /* DACs are overridable for directories */
64472 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64473 - return 0;
64474 if (!(mask & MAY_WRITE))
64475 - if (capable_wrt_inode_uidgid(inode,
64476 - CAP_DAC_READ_SEARCH))
64477 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64478 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64479 return 0;
64480 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64481 + return 0;
64482 return -EACCES;
64483 }
64484 /*
64485 + * Searching includes executable on directories, else just read.
64486 + */
64487 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64488 + if (mask == MAY_READ)
64489 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64490 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64491 + return 0;
64492 +
64493 + /*
64494 * Read/write DACs are always overridable.
64495 * Executable DACs are overridable when there is
64496 * at least one exec bit set.
64497 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64498 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64499 return 0;
64500
64501 - /*
64502 - * Searching includes executable on directories, else just read.
64503 - */
64504 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64505 - if (mask == MAY_READ)
64506 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64507 - return 0;
64508 -
64509 return -EACCES;
64510 }
64511 EXPORT_SYMBOL(generic_permission);
64512 @@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64513 {
64514 struct dentry *dentry = link->dentry;
64515 int error;
64516 - char *s;
64517 + const char *s;
64518
64519 BUG_ON(nd->flags & LOOKUP_RCU);
64520
64521 @@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64522 if (error)
64523 goto out_put_nd_path;
64524
64525 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64526 + dentry->d_inode, dentry, nd->path.mnt)) {
64527 + error = -EACCES;
64528 + goto out_put_nd_path;
64529 + }
64530 +
64531 nd->last_type = LAST_BIND;
64532 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64533 error = PTR_ERR(*p);
64534 @@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64535 if (res)
64536 break;
64537 res = walk_component(nd, path, LOOKUP_FOLLOW);
64538 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64539 + res = -EACCES;
64540 put_link(nd, &link, cookie);
64541 } while (res > 0);
64542
64543 @@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
64544 static inline u64 hash_name(const char *name)
64545 {
64546 unsigned long a, b, adata, bdata, mask, hash, len;
64547 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64548 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64549
64550 hash = a = 0;
64551 len = -sizeof(unsigned long);
64552 @@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
64553 if (err)
64554 break;
64555 err = lookup_last(nd, &path);
64556 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64557 + err = -EACCES;
64558 put_link(nd, &link, cookie);
64559 }
64560 }
64561 @@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
64562 if (!err)
64563 err = complete_walk(nd);
64564
64565 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64566 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64567 + path_put(&nd->path);
64568 + err = -ENOENT;
64569 + }
64570 + }
64571 +
64572 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64573 if (!d_can_lookup(nd->path.dentry)) {
64574 path_put(&nd->path);
64575 @@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
64576 retval = path_lookupat(dfd, name->name,
64577 flags | LOOKUP_REVAL, nd);
64578
64579 - if (likely(!retval))
64580 + if (likely(!retval)) {
64581 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64582 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64583 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64584 + path_put(&nd->path);
64585 + return -ENOENT;
64586 + }
64587 + }
64588 + }
64589 return retval;
64590 }
64591
64592 @@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64593 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64594 return -EPERM;
64595
64596 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64597 + return -EPERM;
64598 + if (gr_handle_rawio(inode))
64599 + return -EPERM;
64600 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64601 + return -EACCES;
64602 +
64603 return 0;
64604 }
64605
64606 @@ -2816,7 +2854,7 @@ looked_up:
64607 * cleared otherwise prior to returning.
64608 */
64609 static int lookup_open(struct nameidata *nd, struct path *path,
64610 - struct file *file,
64611 + struct path *link, struct file *file,
64612 const struct open_flags *op,
64613 bool got_write, int *opened)
64614 {
64615 @@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64616 /* Negative dentry, just create the file */
64617 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64618 umode_t mode = op->mode;
64619 +
64620 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64621 + error = -EACCES;
64622 + goto out_dput;
64623 + }
64624 +
64625 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64626 + error = -EACCES;
64627 + goto out_dput;
64628 + }
64629 +
64630 if (!IS_POSIXACL(dir->d_inode))
64631 mode &= ~current_umask();
64632 /*
64633 @@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64634 nd->flags & LOOKUP_EXCL);
64635 if (error)
64636 goto out_dput;
64637 + else
64638 + gr_handle_create(dentry, nd->path.mnt);
64639 }
64640 out_no_open:
64641 path->dentry = dentry;
64642 @@ -2886,7 +2937,7 @@ out_dput:
64643 /*
64644 * Handle the last step of open()
64645 */
64646 -static int do_last(struct nameidata *nd, struct path *path,
64647 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64648 struct file *file, const struct open_flags *op,
64649 int *opened, struct filename *name)
64650 {
64651 @@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64652 if (error)
64653 return error;
64654
64655 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64656 + error = -ENOENT;
64657 + goto out;
64658 + }
64659 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64660 + error = -EACCES;
64661 + goto out;
64662 + }
64663 +
64664 audit_inode(name, dir, LOOKUP_PARENT);
64665 error = -EISDIR;
64666 /* trailing slashes? */
64667 @@ -2955,7 +3015,7 @@ retry_lookup:
64668 */
64669 }
64670 mutex_lock(&dir->d_inode->i_mutex);
64671 - error = lookup_open(nd, path, file, op, got_write, opened);
64672 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64673 mutex_unlock(&dir->d_inode->i_mutex);
64674
64675 if (error <= 0) {
64676 @@ -2979,11 +3039,28 @@ retry_lookup:
64677 goto finish_open_created;
64678 }
64679
64680 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64681 + error = -ENOENT;
64682 + goto exit_dput;
64683 + }
64684 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64685 + error = -EACCES;
64686 + goto exit_dput;
64687 + }
64688 +
64689 /*
64690 * create/update audit record if it already exists.
64691 */
64692 - if (d_is_positive(path->dentry))
64693 + if (d_is_positive(path->dentry)) {
64694 + /* only check if O_CREAT is specified, all other checks need to go
64695 + into may_open */
64696 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64697 + error = -EACCES;
64698 + goto exit_dput;
64699 + }
64700 +
64701 audit_inode(name, path->dentry, 0);
64702 + }
64703
64704 /*
64705 * If atomic_open() acquired write access it is dropped now due to
64706 @@ -3024,6 +3101,11 @@ finish_lookup:
64707 }
64708 }
64709 BUG_ON(inode != path->dentry->d_inode);
64710 + /* if we're resolving a symlink to another symlink */
64711 + if (link && gr_handle_symlink_owner(link, inode)) {
64712 + error = -EACCES;
64713 + goto out;
64714 + }
64715 return 1;
64716 }
64717
64718 @@ -3033,7 +3115,6 @@ finish_lookup:
64719 save_parent.dentry = nd->path.dentry;
64720 save_parent.mnt = mntget(path->mnt);
64721 nd->path.dentry = path->dentry;
64722 -
64723 }
64724 nd->inode = inode;
64725 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
64726 @@ -3043,7 +3124,18 @@ finish_open:
64727 path_put(&save_parent);
64728 return error;
64729 }
64730 +
64731 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64732 + error = -ENOENT;
64733 + goto out;
64734 + }
64735 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64736 + error = -EACCES;
64737 + goto out;
64738 + }
64739 +
64740 audit_inode(name, nd->path.dentry, 0);
64741 +
64742 error = -EISDIR;
64743 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64744 goto out;
64745 @@ -3207,7 +3299,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64746 if (unlikely(error))
64747 goto out;
64748
64749 - error = do_last(nd, &path, file, op, &opened, pathname);
64750 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64751 while (unlikely(error > 0)) { /* trailing symlink */
64752 struct path link = path;
64753 void *cookie;
64754 @@ -3225,7 +3317,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64755 error = follow_link(&link, nd, &cookie);
64756 if (unlikely(error))
64757 break;
64758 - error = do_last(nd, &path, file, op, &opened, pathname);
64759 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64760 put_link(nd, &link, cookie);
64761 }
64762 out:
64763 @@ -3325,9 +3417,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64764 goto unlock;
64765
64766 error = -EEXIST;
64767 - if (d_is_positive(dentry))
64768 + if (d_is_positive(dentry)) {
64769 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64770 + error = -ENOENT;
64771 goto fail;
64772 -
64773 + }
64774 /*
64775 * Special case - lookup gave negative, but... we had foo/bar/
64776 * From the vfs_mknod() POV we just have a negative dentry -
64777 @@ -3379,6 +3473,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64778 }
64779 EXPORT_SYMBOL(user_path_create);
64780
64781 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64782 +{
64783 + struct filename *tmp = getname(pathname);
64784 + struct dentry *res;
64785 + if (IS_ERR(tmp))
64786 + return ERR_CAST(tmp);
64787 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64788 + if (IS_ERR(res))
64789 + putname(tmp);
64790 + else
64791 + *to = tmp;
64792 + return res;
64793 +}
64794 +
64795 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64796 {
64797 int error = may_create(dir, dentry);
64798 @@ -3442,6 +3550,17 @@ retry:
64799
64800 if (!IS_POSIXACL(path.dentry->d_inode))
64801 mode &= ~current_umask();
64802 +
64803 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64804 + error = -EPERM;
64805 + goto out;
64806 + }
64807 +
64808 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64809 + error = -EACCES;
64810 + goto out;
64811 + }
64812 +
64813 error = security_path_mknod(&path, dentry, mode, dev);
64814 if (error)
64815 goto out;
64816 @@ -3457,6 +3576,8 @@ retry:
64817 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64818 break;
64819 }
64820 + if (!error)
64821 + gr_handle_create(dentry, path.mnt);
64822 out:
64823 done_path_create(&path, dentry);
64824 if (retry_estale(error, lookup_flags)) {
64825 @@ -3511,9 +3632,16 @@ retry:
64826
64827 if (!IS_POSIXACL(path.dentry->d_inode))
64828 mode &= ~current_umask();
64829 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64830 + error = -EACCES;
64831 + goto out;
64832 + }
64833 error = security_path_mkdir(&path, dentry, mode);
64834 if (!error)
64835 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64836 + if (!error)
64837 + gr_handle_create(dentry, path.mnt);
64838 +out:
64839 done_path_create(&path, dentry);
64840 if (retry_estale(error, lookup_flags)) {
64841 lookup_flags |= LOOKUP_REVAL;
64842 @@ -3596,6 +3724,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64843 struct filename *name;
64844 struct dentry *dentry;
64845 struct nameidata nd;
64846 + ino_t saved_ino = 0;
64847 + dev_t saved_dev = 0;
64848 unsigned int lookup_flags = 0;
64849 retry:
64850 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64851 @@ -3628,10 +3758,21 @@ retry:
64852 error = -ENOENT;
64853 goto exit3;
64854 }
64855 +
64856 + saved_ino = dentry->d_inode->i_ino;
64857 + saved_dev = gr_get_dev_from_dentry(dentry);
64858 +
64859 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64860 + error = -EACCES;
64861 + goto exit3;
64862 + }
64863 +
64864 error = security_path_rmdir(&nd.path, dentry);
64865 if (error)
64866 goto exit3;
64867 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64868 + if (!error && (saved_dev || saved_ino))
64869 + gr_handle_delete(saved_ino, saved_dev);
64870 exit3:
64871 dput(dentry);
64872 exit2:
64873 @@ -3722,6 +3863,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64874 struct nameidata nd;
64875 struct inode *inode = NULL;
64876 struct inode *delegated_inode = NULL;
64877 + ino_t saved_ino = 0;
64878 + dev_t saved_dev = 0;
64879 unsigned int lookup_flags = 0;
64880 retry:
64881 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64882 @@ -3748,10 +3891,22 @@ retry_deleg:
64883 if (d_is_negative(dentry))
64884 goto slashes;
64885 ihold(inode);
64886 +
64887 + if (inode->i_nlink <= 1) {
64888 + saved_ino = inode->i_ino;
64889 + saved_dev = gr_get_dev_from_dentry(dentry);
64890 + }
64891 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64892 + error = -EACCES;
64893 + goto exit2;
64894 + }
64895 +
64896 error = security_path_unlink(&nd.path, dentry);
64897 if (error)
64898 goto exit2;
64899 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64900 + if (!error && (saved_ino || saved_dev))
64901 + gr_handle_delete(saved_ino, saved_dev);
64902 exit2:
64903 dput(dentry);
64904 }
64905 @@ -3840,9 +3995,17 @@ retry:
64906 if (IS_ERR(dentry))
64907 goto out_putname;
64908
64909 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64910 + error = -EACCES;
64911 + goto out;
64912 + }
64913 +
64914 error = security_path_symlink(&path, dentry, from->name);
64915 if (!error)
64916 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64917 + if (!error)
64918 + gr_handle_create(dentry, path.mnt);
64919 +out:
64920 done_path_create(&path, dentry);
64921 if (retry_estale(error, lookup_flags)) {
64922 lookup_flags |= LOOKUP_REVAL;
64923 @@ -3946,6 +4109,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64924 struct dentry *new_dentry;
64925 struct path old_path, new_path;
64926 struct inode *delegated_inode = NULL;
64927 + struct filename *to = NULL;
64928 int how = 0;
64929 int error;
64930
64931 @@ -3969,7 +4133,7 @@ retry:
64932 if (error)
64933 return error;
64934
64935 - new_dentry = user_path_create(newdfd, newname, &new_path,
64936 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64937 (how & LOOKUP_REVAL));
64938 error = PTR_ERR(new_dentry);
64939 if (IS_ERR(new_dentry))
64940 @@ -3981,11 +4145,28 @@ retry:
64941 error = may_linkat(&old_path);
64942 if (unlikely(error))
64943 goto out_dput;
64944 +
64945 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64946 + old_path.dentry->d_inode,
64947 + old_path.dentry->d_inode->i_mode, to)) {
64948 + error = -EACCES;
64949 + goto out_dput;
64950 + }
64951 +
64952 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64953 + old_path.dentry, old_path.mnt, to)) {
64954 + error = -EACCES;
64955 + goto out_dput;
64956 + }
64957 +
64958 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64959 if (error)
64960 goto out_dput;
64961 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64962 + if (!error)
64963 + gr_handle_create(new_dentry, new_path.mnt);
64964 out_dput:
64965 + putname(to);
64966 done_path_create(&new_path, new_dentry);
64967 if (delegated_inode) {
64968 error = break_deleg_wait(&delegated_inode);
64969 @@ -4296,6 +4477,12 @@ retry_deleg:
64970 if (new_dentry == trap)
64971 goto exit5;
64972
64973 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64974 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64975 + to, flags);
64976 + if (error)
64977 + goto exit5;
64978 +
64979 error = security_path_rename(&oldnd.path, old_dentry,
64980 &newnd.path, new_dentry, flags);
64981 if (error)
64982 @@ -4303,6 +4490,9 @@ retry_deleg:
64983 error = vfs_rename(old_dir->d_inode, old_dentry,
64984 new_dir->d_inode, new_dentry,
64985 &delegated_inode, flags);
64986 + if (!error)
64987 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64988 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64989 exit5:
64990 dput(new_dentry);
64991 exit4:
64992 @@ -4345,14 +4535,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
64993
64994 int readlink_copy(char __user *buffer, int buflen, const char *link)
64995 {
64996 + char tmpbuf[64];
64997 + const char *newlink;
64998 int len = PTR_ERR(link);
64999 +
65000 if (IS_ERR(link))
65001 goto out;
65002
65003 len = strlen(link);
65004 if (len > (unsigned) buflen)
65005 len = buflen;
65006 - if (copy_to_user(buffer, link, len))
65007 +
65008 + if (len < sizeof(tmpbuf)) {
65009 + memcpy(tmpbuf, link, len);
65010 + newlink = tmpbuf;
65011 + } else
65012 + newlink = link;
65013 +
65014 + if (copy_to_user(buffer, newlink, len))
65015 len = -EFAULT;
65016 out:
65017 return len;
65018 diff --git a/fs/namespace.c b/fs/namespace.c
65019 index 550dbff..c4ad324 100644
65020 --- a/fs/namespace.c
65021 +++ b/fs/namespace.c
65022 @@ -1362,6 +1362,9 @@ static int do_umount(struct mount *mnt, int flags)
65023 if (!(sb->s_flags & MS_RDONLY))
65024 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
65025 up_write(&sb->s_umount);
65026 +
65027 + gr_log_remount(mnt->mnt_devname, retval);
65028 +
65029 return retval;
65030 }
65031
65032 @@ -1384,6 +1387,9 @@ static int do_umount(struct mount *mnt, int flags)
65033 }
65034 unlock_mount_hash();
65035 namespace_unlock();
65036 +
65037 + gr_log_unmount(mnt->mnt_devname, retval);
65038 +
65039 return retval;
65040 }
65041
65042 @@ -1403,7 +1409,7 @@ static inline bool may_mount(void)
65043 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
65044 */
65045
65046 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
65047 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
65048 {
65049 struct path path;
65050 struct mount *mnt;
65051 @@ -1445,7 +1451,7 @@ out:
65052 /*
65053 * The 2.0 compatible umount. No flags.
65054 */
65055 -SYSCALL_DEFINE1(oldumount, char __user *, name)
65056 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
65057 {
65058 return sys_umount(name, 0);
65059 }
65060 @@ -2494,6 +2500,16 @@ long do_mount(const char *dev_name, const char *dir_name,
65061 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
65062 MS_STRICTATIME);
65063
65064 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
65065 + retval = -EPERM;
65066 + goto dput_out;
65067 + }
65068 +
65069 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
65070 + retval = -EPERM;
65071 + goto dput_out;
65072 + }
65073 +
65074 if (flags & MS_REMOUNT)
65075 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
65076 data_page);
65077 @@ -2508,6 +2524,9 @@ long do_mount(const char *dev_name, const char *dir_name,
65078 dev_name, data_page);
65079 dput_out:
65080 path_put(&path);
65081 +
65082 + gr_log_mount(dev_name, dir_name, retval);
65083 +
65084 return retval;
65085 }
65086
65087 @@ -2525,7 +2544,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
65088 * number incrementing at 10Ghz will take 12,427 years to wrap which
65089 * is effectively never, so we can ignore the possibility.
65090 */
65091 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
65092 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
65093
65094 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65095 {
65096 @@ -2540,7 +2559,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65097 kfree(new_ns);
65098 return ERR_PTR(ret);
65099 }
65100 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
65101 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65102 atomic_set(&new_ns->count, 1);
65103 new_ns->root = NULL;
65104 INIT_LIST_HEAD(&new_ns->list);
65105 @@ -2550,7 +2569,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65106 return new_ns;
65107 }
65108
65109 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65110 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65111 struct user_namespace *user_ns, struct fs_struct *new_fs)
65112 {
65113 struct mnt_namespace *new_ns;
65114 @@ -2671,8 +2690,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65115 }
65116 EXPORT_SYMBOL(mount_subtree);
65117
65118 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65119 - char __user *, type, unsigned long, flags, void __user *, data)
65120 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65121 + const char __user *, type, unsigned long, flags, void __user *, data)
65122 {
65123 int ret;
65124 char *kernel_type;
65125 @@ -2785,6 +2804,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65126 if (error)
65127 goto out2;
65128
65129 + if (gr_handle_chroot_pivot()) {
65130 + error = -EPERM;
65131 + goto out2;
65132 + }
65133 +
65134 get_fs_root(current->fs, &root);
65135 old_mp = lock_mount(&old);
65136 error = PTR_ERR(old_mp);
65137 @@ -3056,7 +3080,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65138 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65139 return -EPERM;
65140
65141 - if (fs->users != 1)
65142 + if (atomic_read(&fs->users) != 1)
65143 return -EINVAL;
65144
65145 get_mnt_ns(mnt_ns);
65146 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65147 index f4ccfe6..a5cf064 100644
65148 --- a/fs/nfs/callback_xdr.c
65149 +++ b/fs/nfs/callback_xdr.c
65150 @@ -51,7 +51,7 @@ struct callback_op {
65151 callback_decode_arg_t decode_args;
65152 callback_encode_res_t encode_res;
65153 long res_maxsize;
65154 -};
65155 +} __do_const;
65156
65157 static struct callback_op callback_ops[];
65158
65159 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65160 index 0689aa5..299386e 100644
65161 --- a/fs/nfs/inode.c
65162 +++ b/fs/nfs/inode.c
65163 @@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65164 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65165 }
65166
65167 -static atomic_long_t nfs_attr_generation_counter;
65168 +static atomic_long_unchecked_t nfs_attr_generation_counter;
65169
65170 static unsigned long nfs_read_attr_generation_counter(void)
65171 {
65172 - return atomic_long_read(&nfs_attr_generation_counter);
65173 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65174 }
65175
65176 unsigned long nfs_inc_attr_generation_counter(void)
65177 {
65178 - return atomic_long_inc_return(&nfs_attr_generation_counter);
65179 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65180 }
65181
65182 void nfs_fattr_init(struct nfs_fattr *fattr)
65183 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65184 index 1d3cb47..2b8ed89 100644
65185 --- a/fs/nfsd/nfs4proc.c
65186 +++ b/fs/nfsd/nfs4proc.c
65187 @@ -1155,7 +1155,7 @@ struct nfsd4_operation {
65188 nfsd4op_rsize op_rsize_bop;
65189 stateid_getter op_get_currentstateid;
65190 stateid_setter op_set_currentstateid;
65191 -};
65192 +} __do_const;
65193
65194 static struct nfsd4_operation nfsd4_ops[];
65195
65196 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65197 index 353aac8..32035ee 100644
65198 --- a/fs/nfsd/nfs4xdr.c
65199 +++ b/fs/nfsd/nfs4xdr.c
65200 @@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65201
65202 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65203
65204 -static nfsd4_dec nfsd4_dec_ops[] = {
65205 +static const nfsd4_dec nfsd4_dec_ops[] = {
65206 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65207 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65208 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65209 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65210 index ff95676..96cf3f62 100644
65211 --- a/fs/nfsd/nfscache.c
65212 +++ b/fs/nfsd/nfscache.c
65213 @@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65214 {
65215 struct svc_cacherep *rp = rqstp->rq_cacherep;
65216 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65217 - int len;
65218 + long len;
65219 size_t bufsize = 0;
65220
65221 if (!rp)
65222 return;
65223
65224 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65225 - len >>= 2;
65226 + if (statp) {
65227 + len = (char*)statp - (char*)resv->iov_base;
65228 + len = resv->iov_len - len;
65229 + len >>= 2;
65230 + }
65231
65232 /* Don't cache excessive amounts of data and XDR failures */
65233 - if (!statp || len > (256 >> 2)) {
65234 + if (!statp || len > (256 >> 2) || len < 0) {
65235 nfsd_reply_cache_free(rp);
65236 return;
65237 }
65238 @@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65239 switch (cachetype) {
65240 case RC_REPLSTAT:
65241 if (len != 1)
65242 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65243 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65244 rp->c_replstat = *statp;
65245 break;
65246 case RC_REPLBUFF:
65247 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65248 index 6ab077b..5ac7f0b 100644
65249 --- a/fs/nfsd/vfs.c
65250 +++ b/fs/nfsd/vfs.c
65251 @@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65252
65253 oldfs = get_fs();
65254 set_fs(KERNEL_DS);
65255 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65256 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65257 set_fs(oldfs);
65258 return nfsd_finish_read(file, count, host_err);
65259 }
65260 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65261
65262 /* Write the data. */
65263 oldfs = get_fs(); set_fs(KERNEL_DS);
65264 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65265 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65266 set_fs(oldfs);
65267 if (host_err < 0)
65268 goto out_nfserr;
65269 @@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65270 */
65271
65272 oldfs = get_fs(); set_fs(KERNEL_DS);
65273 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65274 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65275 set_fs(oldfs);
65276
65277 if (host_err < 0)
65278 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65279 index 52ccd34..7a6b202 100644
65280 --- a/fs/nls/nls_base.c
65281 +++ b/fs/nls/nls_base.c
65282 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65283
65284 int __register_nls(struct nls_table *nls, struct module *owner)
65285 {
65286 - struct nls_table ** tmp = &tables;
65287 + struct nls_table *tmp = tables;
65288
65289 if (nls->next)
65290 return -EBUSY;
65291
65292 - nls->owner = owner;
65293 + pax_open_kernel();
65294 + *(void **)&nls->owner = owner;
65295 + pax_close_kernel();
65296 spin_lock(&nls_lock);
65297 - while (*tmp) {
65298 - if (nls == *tmp) {
65299 + while (tmp) {
65300 + if (nls == tmp) {
65301 spin_unlock(&nls_lock);
65302 return -EBUSY;
65303 }
65304 - tmp = &(*tmp)->next;
65305 + tmp = tmp->next;
65306 }
65307 - nls->next = tables;
65308 + pax_open_kernel();
65309 + *(struct nls_table **)&nls->next = tables;
65310 + pax_close_kernel();
65311 tables = nls;
65312 spin_unlock(&nls_lock);
65313 return 0;
65314 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65315
65316 int unregister_nls(struct nls_table * nls)
65317 {
65318 - struct nls_table ** tmp = &tables;
65319 + struct nls_table * const * tmp = &tables;
65320
65321 spin_lock(&nls_lock);
65322 while (*tmp) {
65323 if (nls == *tmp) {
65324 - *tmp = nls->next;
65325 + pax_open_kernel();
65326 + *(struct nls_table **)tmp = nls->next;
65327 + pax_close_kernel();
65328 spin_unlock(&nls_lock);
65329 return 0;
65330 }
65331 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65332 return -EINVAL;
65333 }
65334
65335 -static struct nls_table *find_nls(char *charset)
65336 +static struct nls_table *find_nls(const char *charset)
65337 {
65338 struct nls_table *nls;
65339 spin_lock(&nls_lock);
65340 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65341 return nls;
65342 }
65343
65344 -struct nls_table *load_nls(char *charset)
65345 +struct nls_table *load_nls(const char *charset)
65346 {
65347 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65348 }
65349 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65350 index 162b3f1..6076a7c 100644
65351 --- a/fs/nls/nls_euc-jp.c
65352 +++ b/fs/nls/nls_euc-jp.c
65353 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65354 p_nls = load_nls("cp932");
65355
65356 if (p_nls) {
65357 - table.charset2upper = p_nls->charset2upper;
65358 - table.charset2lower = p_nls->charset2lower;
65359 + pax_open_kernel();
65360 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65361 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65362 + pax_close_kernel();
65363 return register_nls(&table);
65364 }
65365
65366 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65367 index a80a741..7b96e1b 100644
65368 --- a/fs/nls/nls_koi8-ru.c
65369 +++ b/fs/nls/nls_koi8-ru.c
65370 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65371 p_nls = load_nls("koi8-u");
65372
65373 if (p_nls) {
65374 - table.charset2upper = p_nls->charset2upper;
65375 - table.charset2lower = p_nls->charset2lower;
65376 + pax_open_kernel();
65377 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65378 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65379 + pax_close_kernel();
65380 return register_nls(&table);
65381 }
65382
65383 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65384 index c991616..5ae51af 100644
65385 --- a/fs/notify/fanotify/fanotify_user.c
65386 +++ b/fs/notify/fanotify/fanotify_user.c
65387 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65388
65389 fd = fanotify_event_metadata.fd;
65390 ret = -EFAULT;
65391 - if (copy_to_user(buf, &fanotify_event_metadata,
65392 - fanotify_event_metadata.event_len))
65393 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65394 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65395 goto out_close_fd;
65396
65397 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65398 diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
65399 index 0f88bc0..7d888d7 100644
65400 --- a/fs/notify/inotify/inotify_fsnotify.c
65401 +++ b/fs/notify/inotify/inotify_fsnotify.c
65402 @@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
65403 /* ideally the idr is empty and we won't hit the BUG in the callback */
65404 idr_for_each(&group->inotify_data.idr, idr_callback, group);
65405 idr_destroy(&group->inotify_data.idr);
65406 - atomic_dec(&group->inotify_data.user->inotify_devs);
65407 - free_uid(group->inotify_data.user);
65408 + if (group->inotify_data.user) {
65409 + atomic_dec(&group->inotify_data.user->inotify_devs);
65410 + free_uid(group->inotify_data.user);
65411 + }
65412 }
65413
65414 static void inotify_free_event(struct fsnotify_event *fsn_event)
65415 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65416 index a95d8e0..a91a5fd 100644
65417 --- a/fs/notify/notification.c
65418 +++ b/fs/notify/notification.c
65419 @@ -48,7 +48,7 @@
65420 #include <linux/fsnotify_backend.h>
65421 #include "fsnotify.h"
65422
65423 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65424 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65425
65426 /**
65427 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65428 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65429 */
65430 u32 fsnotify_get_cookie(void)
65431 {
65432 - return atomic_inc_return(&fsnotify_sync_cookie);
65433 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65434 }
65435 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65436
65437 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65438 index 9e38daf..5727cae 100644
65439 --- a/fs/ntfs/dir.c
65440 +++ b/fs/ntfs/dir.c
65441 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65442 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65443 ~(s64)(ndir->itype.index.block_size - 1)));
65444 /* Bounds checks. */
65445 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65446 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65447 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65448 "inode 0x%lx or driver bug.", vdir->i_ino);
65449 goto err_out;
65450 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65451 index f5ec1ce..807fd78 100644
65452 --- a/fs/ntfs/file.c
65453 +++ b/fs/ntfs/file.c
65454 @@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65455 char *addr;
65456 size_t total = 0;
65457 unsigned len;
65458 - int left;
65459 + unsigned left;
65460
65461 do {
65462 len = PAGE_CACHE_SIZE - ofs;
65463 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65464 index 6c3296e..c0b99f0 100644
65465 --- a/fs/ntfs/super.c
65466 +++ b/fs/ntfs/super.c
65467 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65468 if (!silent)
65469 ntfs_error(sb, "Primary boot sector is invalid.");
65470 } else if (!silent)
65471 - ntfs_error(sb, read_err_str, "primary");
65472 + ntfs_error(sb, read_err_str, "%s", "primary");
65473 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65474 if (bh_primary)
65475 brelse(bh_primary);
65476 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65477 goto hotfix_primary_boot_sector;
65478 brelse(bh_backup);
65479 } else if (!silent)
65480 - ntfs_error(sb, read_err_str, "backup");
65481 + ntfs_error(sb, read_err_str, "%s", "backup");
65482 /* Try to read NT3.51- backup boot sector. */
65483 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65484 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65485 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65486 "sector.");
65487 brelse(bh_backup);
65488 } else if (!silent)
65489 - ntfs_error(sb, read_err_str, "backup");
65490 + ntfs_error(sb, read_err_str, "%s", "backup");
65491 /* We failed. Cleanup and return. */
65492 if (bh_primary)
65493 brelse(bh_primary);
65494 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65495 index 0440134..d52c93a 100644
65496 --- a/fs/ocfs2/localalloc.c
65497 +++ b/fs/ocfs2/localalloc.c
65498 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65499 goto bail;
65500 }
65501
65502 - atomic_inc(&osb->alloc_stats.moves);
65503 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65504
65505 bail:
65506 if (handle)
65507 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
65508 index 8add6f1..b931e04 100644
65509 --- a/fs/ocfs2/namei.c
65510 +++ b/fs/ocfs2/namei.c
65511 @@ -158,7 +158,7 @@ bail_add:
65512 * NOTE: This dentry already has ->d_op set from
65513 * ocfs2_get_parent() and ocfs2_get_dentry()
65514 */
65515 - if (ret)
65516 + if (!IS_ERR_OR_NULL(ret))
65517 dentry = ret;
65518
65519 status = ocfs2_dentry_attach_lock(dentry, inode,
65520 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65521 index bbec539..7b266d5 100644
65522 --- a/fs/ocfs2/ocfs2.h
65523 +++ b/fs/ocfs2/ocfs2.h
65524 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65525
65526 struct ocfs2_alloc_stats
65527 {
65528 - atomic_t moves;
65529 - atomic_t local_data;
65530 - atomic_t bitmap_data;
65531 - atomic_t bg_allocs;
65532 - atomic_t bg_extends;
65533 + atomic_unchecked_t moves;
65534 + atomic_unchecked_t local_data;
65535 + atomic_unchecked_t bitmap_data;
65536 + atomic_unchecked_t bg_allocs;
65537 + atomic_unchecked_t bg_extends;
65538 };
65539
65540 enum ocfs2_local_alloc_state
65541 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65542 index 0cb889a..6a26b24 100644
65543 --- a/fs/ocfs2/suballoc.c
65544 +++ b/fs/ocfs2/suballoc.c
65545 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65546 mlog_errno(status);
65547 goto bail;
65548 }
65549 - atomic_inc(&osb->alloc_stats.bg_extends);
65550 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65551
65552 /* You should never ask for this much metadata */
65553 BUG_ON(bits_wanted >
65554 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65555 mlog_errno(status);
65556 goto bail;
65557 }
65558 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65559 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65560
65561 *suballoc_loc = res.sr_bg_blkno;
65562 *suballoc_bit_start = res.sr_bit_offset;
65563 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65564 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65565 res->sr_bits);
65566
65567 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65568 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65569
65570 BUG_ON(res->sr_bits != 1);
65571
65572 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65573 mlog_errno(status);
65574 goto bail;
65575 }
65576 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65577 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65578
65579 BUG_ON(res.sr_bits != 1);
65580
65581 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65582 cluster_start,
65583 num_clusters);
65584 if (!status)
65585 - atomic_inc(&osb->alloc_stats.local_data);
65586 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65587 } else {
65588 if (min_clusters > (osb->bitmap_cpg - 1)) {
65589 /* The only paths asking for contiguousness
65590 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65591 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65592 res.sr_bg_blkno,
65593 res.sr_bit_offset);
65594 - atomic_inc(&osb->alloc_stats.bitmap_data);
65595 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65596 *num_clusters = res.sr_bits;
65597 }
65598 }
65599 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65600 index 4142546..69375a9 100644
65601 --- a/fs/ocfs2/super.c
65602 +++ b/fs/ocfs2/super.c
65603 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65604 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65605 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65606 "Stats",
65607 - atomic_read(&osb->alloc_stats.bitmap_data),
65608 - atomic_read(&osb->alloc_stats.local_data),
65609 - atomic_read(&osb->alloc_stats.bg_allocs),
65610 - atomic_read(&osb->alloc_stats.moves),
65611 - atomic_read(&osb->alloc_stats.bg_extends));
65612 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65613 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65614 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65615 + atomic_read_unchecked(&osb->alloc_stats.moves),
65616 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65617
65618 out += snprintf(buf + out, len - out,
65619 "%10s => State: %u Descriptor: %llu Size: %u bits "
65620 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65621
65622 mutex_init(&osb->system_file_mutex);
65623
65624 - atomic_set(&osb->alloc_stats.moves, 0);
65625 - atomic_set(&osb->alloc_stats.local_data, 0);
65626 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65627 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65628 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65629 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65630 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65631 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65632 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65633 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65634
65635 /* Copy the blockcheck stats from the superblock probe */
65636 osb->osb_ecc_stats = *stats;
65637 diff --git a/fs/open.c b/fs/open.c
65638 index d6fd3ac..6ccf474 100644
65639 --- a/fs/open.c
65640 +++ b/fs/open.c
65641 @@ -32,6 +32,8 @@
65642 #include <linux/dnotify.h>
65643 #include <linux/compat.h>
65644
65645 +#define CREATE_TRACE_POINTS
65646 +#include <trace/events/fs.h>
65647 #include "internal.h"
65648
65649 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65650 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65651 error = locks_verify_truncate(inode, NULL, length);
65652 if (!error)
65653 error = security_path_truncate(path);
65654 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65655 + error = -EACCES;
65656 if (!error)
65657 error = do_truncate(path->dentry, length, 0, NULL);
65658
65659 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65660 error = locks_verify_truncate(inode, f.file, length);
65661 if (!error)
65662 error = security_path_truncate(&f.file->f_path);
65663 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65664 + error = -EACCES;
65665 if (!error)
65666 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65667 sb_end_write(inode->i_sb);
65668 @@ -380,6 +386,9 @@ retry:
65669 if (__mnt_is_readonly(path.mnt))
65670 res = -EROFS;
65671
65672 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65673 + res = -EACCES;
65674 +
65675 out_path_release:
65676 path_put(&path);
65677 if (retry_estale(res, lookup_flags)) {
65678 @@ -411,6 +420,8 @@ retry:
65679 if (error)
65680 goto dput_and_out;
65681
65682 + gr_log_chdir(path.dentry, path.mnt);
65683 +
65684 set_fs_pwd(current->fs, &path);
65685
65686 dput_and_out:
65687 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65688 goto out_putf;
65689
65690 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65691 +
65692 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65693 + error = -EPERM;
65694 +
65695 + if (!error)
65696 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65697 +
65698 if (!error)
65699 set_fs_pwd(current->fs, &f.file->f_path);
65700 out_putf:
65701 @@ -469,7 +487,13 @@ retry:
65702 if (error)
65703 goto dput_and_out;
65704
65705 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65706 + goto dput_and_out;
65707 +
65708 set_fs_root(current->fs, &path);
65709 +
65710 + gr_handle_chroot_chdir(&path);
65711 +
65712 error = 0;
65713 dput_and_out:
65714 path_put(&path);
65715 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65716 return error;
65717 retry_deleg:
65718 mutex_lock(&inode->i_mutex);
65719 +
65720 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65721 + error = -EACCES;
65722 + goto out_unlock;
65723 + }
65724 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65725 + error = -EACCES;
65726 + goto out_unlock;
65727 + }
65728 +
65729 error = security_path_chmod(path, mode);
65730 if (error)
65731 goto out_unlock;
65732 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65733 uid = make_kuid(current_user_ns(), user);
65734 gid = make_kgid(current_user_ns(), group);
65735
65736 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65737 + return -EACCES;
65738 +
65739 newattrs.ia_valid = ATTR_CTIME;
65740 if (user != (uid_t) -1) {
65741 if (!uid_valid(uid))
65742 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65743 } else {
65744 fsnotify_open(f);
65745 fd_install(fd, f);
65746 + trace_do_sys_open(tmp->name, flags, mode);
65747 }
65748 }
65749 putname(tmp);
65750 diff --git a/fs/pipe.c b/fs/pipe.c
65751 index 21981e5..3d5f55c 100644
65752 --- a/fs/pipe.c
65753 +++ b/fs/pipe.c
65754 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65755
65756 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65757 {
65758 - if (pipe->files)
65759 + if (atomic_read(&pipe->files))
65760 mutex_lock_nested(&pipe->mutex, subclass);
65761 }
65762
65763 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65764
65765 void pipe_unlock(struct pipe_inode_info *pipe)
65766 {
65767 - if (pipe->files)
65768 + if (atomic_read(&pipe->files))
65769 mutex_unlock(&pipe->mutex);
65770 }
65771 EXPORT_SYMBOL(pipe_unlock);
65772 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65773 }
65774 if (bufs) /* More to do? */
65775 continue;
65776 - if (!pipe->writers)
65777 + if (!atomic_read(&pipe->writers))
65778 break;
65779 - if (!pipe->waiting_writers) {
65780 + if (!atomic_read(&pipe->waiting_writers)) {
65781 /* syscall merging: Usually we must not sleep
65782 * if O_NONBLOCK is set, or if we got some data.
65783 * But if a writer sleeps in kernel space, then
65784 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65785
65786 __pipe_lock(pipe);
65787
65788 - if (!pipe->readers) {
65789 + if (!atomic_read(&pipe->readers)) {
65790 send_sig(SIGPIPE, current, 0);
65791 ret = -EPIPE;
65792 goto out;
65793 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65794 for (;;) {
65795 int bufs;
65796
65797 - if (!pipe->readers) {
65798 + if (!atomic_read(&pipe->readers)) {
65799 send_sig(SIGPIPE, current, 0);
65800 if (!ret)
65801 ret = -EPIPE;
65802 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65803 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65804 do_wakeup = 0;
65805 }
65806 - pipe->waiting_writers++;
65807 + atomic_inc(&pipe->waiting_writers);
65808 pipe_wait(pipe);
65809 - pipe->waiting_writers--;
65810 + atomic_dec(&pipe->waiting_writers);
65811 }
65812 out:
65813 __pipe_unlock(pipe);
65814 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65815 mask = 0;
65816 if (filp->f_mode & FMODE_READ) {
65817 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65818 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65819 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65820 mask |= POLLHUP;
65821 }
65822
65823 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65824 * Most Unices do not set POLLERR for FIFOs but on Linux they
65825 * behave exactly like pipes for poll().
65826 */
65827 - if (!pipe->readers)
65828 + if (!atomic_read(&pipe->readers))
65829 mask |= POLLERR;
65830 }
65831
65832 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65833 int kill = 0;
65834
65835 spin_lock(&inode->i_lock);
65836 - if (!--pipe->files) {
65837 + if (atomic_dec_and_test(&pipe->files)) {
65838 inode->i_pipe = NULL;
65839 kill = 1;
65840 }
65841 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65842
65843 __pipe_lock(pipe);
65844 if (file->f_mode & FMODE_READ)
65845 - pipe->readers--;
65846 + atomic_dec(&pipe->readers);
65847 if (file->f_mode & FMODE_WRITE)
65848 - pipe->writers--;
65849 + atomic_dec(&pipe->writers);
65850
65851 - if (pipe->readers || pipe->writers) {
65852 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65853 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65854 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65855 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65856 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65857 kfree(pipe);
65858 }
65859
65860 -static struct vfsmount *pipe_mnt __read_mostly;
65861 +struct vfsmount *pipe_mnt __read_mostly;
65862
65863 /*
65864 * pipefs_dname() is called from d_path().
65865 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65866 goto fail_iput;
65867
65868 inode->i_pipe = pipe;
65869 - pipe->files = 2;
65870 - pipe->readers = pipe->writers = 1;
65871 + atomic_set(&pipe->files, 2);
65872 + atomic_set(&pipe->readers, 1);
65873 + atomic_set(&pipe->writers, 1);
65874 inode->i_fop = &pipefifo_fops;
65875
65876 /*
65877 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65878 spin_lock(&inode->i_lock);
65879 if (inode->i_pipe) {
65880 pipe = inode->i_pipe;
65881 - pipe->files++;
65882 + atomic_inc(&pipe->files);
65883 spin_unlock(&inode->i_lock);
65884 } else {
65885 spin_unlock(&inode->i_lock);
65886 pipe = alloc_pipe_info();
65887 if (!pipe)
65888 return -ENOMEM;
65889 - pipe->files = 1;
65890 + atomic_set(&pipe->files, 1);
65891 spin_lock(&inode->i_lock);
65892 if (unlikely(inode->i_pipe)) {
65893 - inode->i_pipe->files++;
65894 + atomic_inc(&inode->i_pipe->files);
65895 spin_unlock(&inode->i_lock);
65896 free_pipe_info(pipe);
65897 pipe = inode->i_pipe;
65898 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65899 * opened, even when there is no process writing the FIFO.
65900 */
65901 pipe->r_counter++;
65902 - if (pipe->readers++ == 0)
65903 + if (atomic_inc_return(&pipe->readers) == 1)
65904 wake_up_partner(pipe);
65905
65906 - if (!is_pipe && !pipe->writers) {
65907 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65908 if ((filp->f_flags & O_NONBLOCK)) {
65909 /* suppress POLLHUP until we have
65910 * seen a writer */
65911 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65912 * errno=ENXIO when there is no process reading the FIFO.
65913 */
65914 ret = -ENXIO;
65915 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65916 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65917 goto err;
65918
65919 pipe->w_counter++;
65920 - if (!pipe->writers++)
65921 + if (atomic_inc_return(&pipe->writers) == 1)
65922 wake_up_partner(pipe);
65923
65924 - if (!is_pipe && !pipe->readers) {
65925 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65926 if (wait_for_partner(pipe, &pipe->r_counter))
65927 goto err_wr;
65928 }
65929 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65930 * the process can at least talk to itself.
65931 */
65932
65933 - pipe->readers++;
65934 - pipe->writers++;
65935 + atomic_inc(&pipe->readers);
65936 + atomic_inc(&pipe->writers);
65937 pipe->r_counter++;
65938 pipe->w_counter++;
65939 - if (pipe->readers == 1 || pipe->writers == 1)
65940 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65941 wake_up_partner(pipe);
65942 break;
65943
65944 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65945 return 0;
65946
65947 err_rd:
65948 - if (!--pipe->readers)
65949 + if (atomic_dec_and_test(&pipe->readers))
65950 wake_up_interruptible(&pipe->wait);
65951 ret = -ERESTARTSYS;
65952 goto err;
65953
65954 err_wr:
65955 - if (!--pipe->writers)
65956 + if (atomic_dec_and_test(&pipe->writers))
65957 wake_up_interruptible(&pipe->wait);
65958 ret = -ERESTARTSYS;
65959 goto err;
65960 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65961 index 0855f77..6787d50 100644
65962 --- a/fs/posix_acl.c
65963 +++ b/fs/posix_acl.c
65964 @@ -20,6 +20,7 @@
65965 #include <linux/xattr.h>
65966 #include <linux/export.h>
65967 #include <linux/user_namespace.h>
65968 +#include <linux/grsecurity.h>
65969
65970 struct posix_acl **acl_by_type(struct inode *inode, int type)
65971 {
65972 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65973 }
65974 }
65975 if (mode_p)
65976 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65977 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65978 return not_equiv;
65979 }
65980 EXPORT_SYMBOL(posix_acl_equiv_mode);
65981 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65982 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65983 }
65984
65985 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65986 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65987 return not_equiv;
65988 }
65989
65990 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65991 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65992 int err = -ENOMEM;
65993 if (clone) {
65994 + *mode_p &= ~gr_acl_umask();
65995 +
65996 err = posix_acl_create_masq(clone, mode_p);
65997 if (err < 0) {
65998 posix_acl_release(clone);
65999 @@ -659,11 +662,12 @@ struct posix_acl *
66000 posix_acl_from_xattr(struct user_namespace *user_ns,
66001 const void *value, size_t size)
66002 {
66003 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
66004 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
66005 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
66006 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
66007 int count;
66008 struct posix_acl *acl;
66009 struct posix_acl_entry *acl_e;
66010 + umode_t umask = gr_acl_umask();
66011
66012 if (!value)
66013 return NULL;
66014 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66015
66016 switch(acl_e->e_tag) {
66017 case ACL_USER_OBJ:
66018 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66019 + break;
66020 case ACL_GROUP_OBJ:
66021 case ACL_MASK:
66022 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66023 + break;
66024 case ACL_OTHER:
66025 + acl_e->e_perm &= ~(umask & S_IRWXO);
66026 break;
66027
66028 case ACL_USER:
66029 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66030 acl_e->e_uid =
66031 make_kuid(user_ns,
66032 le32_to_cpu(entry->e_id));
66033 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66034 goto fail;
66035 break;
66036 case ACL_GROUP:
66037 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66038 acl_e->e_gid =
66039 make_kgid(user_ns,
66040 le32_to_cpu(entry->e_id));
66041 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
66042 index 2183fcf..3c32a98 100644
66043 --- a/fs/proc/Kconfig
66044 +++ b/fs/proc/Kconfig
66045 @@ -30,7 +30,7 @@ config PROC_FS
66046
66047 config PROC_KCORE
66048 bool "/proc/kcore support" if !ARM
66049 - depends on PROC_FS && MMU
66050 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
66051 help
66052 Provides a virtual ELF core file of the live kernel. This can
66053 be read with gdb and other ELF tools. No modifications can be
66054 @@ -38,8 +38,8 @@ config PROC_KCORE
66055
66056 config PROC_VMCORE
66057 bool "/proc/vmcore support"
66058 - depends on PROC_FS && CRASH_DUMP
66059 - default y
66060 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
66061 + default n
66062 help
66063 Exports the dump image of crashed kernel in ELF format.
66064
66065 @@ -63,8 +63,8 @@ config PROC_SYSCTL
66066 limited in memory.
66067
66068 config PROC_PAGE_MONITOR
66069 - default y
66070 - depends on PROC_FS && MMU
66071 + default n
66072 + depends on PROC_FS && MMU && !GRKERNSEC
66073 bool "Enable /proc page monitoring" if EXPERT
66074 help
66075 Various /proc files exist to monitor process memory utilization:
66076 diff --git a/fs/proc/array.c b/fs/proc/array.c
66077 index cd3653e..9b9b79a 100644
66078 --- a/fs/proc/array.c
66079 +++ b/fs/proc/array.c
66080 @@ -60,6 +60,7 @@
66081 #include <linux/tty.h>
66082 #include <linux/string.h>
66083 #include <linux/mman.h>
66084 +#include <linux/grsecurity.h>
66085 #include <linux/proc_fs.h>
66086 #include <linux/ioport.h>
66087 #include <linux/uaccess.h>
66088 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
66089 seq_putc(m, '\n');
66090 }
66091
66092 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66093 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
66094 +{
66095 + if (p->mm)
66096 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
66097 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
66098 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
66099 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
66100 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
66101 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
66102 + else
66103 + seq_printf(m, "PaX:\t-----\n");
66104 +}
66105 +#endif
66106 +
66107 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66108 struct pid *pid, struct task_struct *task)
66109 {
66110 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66111 task_cpus_allowed(m, task);
66112 cpuset_task_status_allowed(m, task);
66113 task_context_switch_counts(m, task);
66114 +
66115 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66116 + task_pax(m, task);
66117 +#endif
66118 +
66119 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66120 + task_grsec_rbac(m, task);
66121 +#endif
66122 +
66123 return 0;
66124 }
66125
66126 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66127 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66128 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66129 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66130 +#endif
66131 +
66132 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66133 struct pid *pid, struct task_struct *task, int whole)
66134 {
66135 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66136 char tcomm[sizeof(task->comm)];
66137 unsigned long flags;
66138
66139 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66140 + if (current->exec_id != m->exec_id) {
66141 + gr_log_badprocpid("stat");
66142 + return 0;
66143 + }
66144 +#endif
66145 +
66146 state = *get_task_state(task);
66147 vsize = eip = esp = 0;
66148 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66149 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66150 gtime = task_gtime(task);
66151 }
66152
66153 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66154 + if (PAX_RAND_FLAGS(mm)) {
66155 + eip = 0;
66156 + esp = 0;
66157 + wchan = 0;
66158 + }
66159 +#endif
66160 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66161 + wchan = 0;
66162 + eip =0;
66163 + esp =0;
66164 +#endif
66165 +
66166 /* scale priority and nice values from timeslices to -20..20 */
66167 /* to make it look like a "normal" Unix priority/nice value */
66168 priority = task_prio(task);
66169 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66170 seq_put_decimal_ull(m, ' ', vsize);
66171 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66172 seq_put_decimal_ull(m, ' ', rsslim);
66173 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66174 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66175 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66176 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66177 +#else
66178 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66179 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66180 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66181 +#endif
66182 seq_put_decimal_ull(m, ' ', esp);
66183 seq_put_decimal_ull(m, ' ', eip);
66184 /* The signal information here is obsolete.
66185 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66186 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66187 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66188
66189 - if (mm && permitted) {
66190 + if (mm && permitted
66191 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66192 + && !PAX_RAND_FLAGS(mm)
66193 +#endif
66194 + ) {
66195 seq_put_decimal_ull(m, ' ', mm->start_data);
66196 seq_put_decimal_ull(m, ' ', mm->end_data);
66197 seq_put_decimal_ull(m, ' ', mm->start_brk);
66198 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66199 struct pid *pid, struct task_struct *task)
66200 {
66201 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66202 - struct mm_struct *mm = get_task_mm(task);
66203 + struct mm_struct *mm;
66204
66205 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66206 + if (current->exec_id != m->exec_id) {
66207 + gr_log_badprocpid("statm");
66208 + return 0;
66209 + }
66210 +#endif
66211 + mm = get_task_mm(task);
66212 if (mm) {
66213 size = task_statm(mm, &shared, &text, &data, &resident);
66214 mmput(mm);
66215 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66216 return 0;
66217 }
66218
66219 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66220 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
66221 +{
66222 + unsigned long flags;
66223 + u32 curr_ip = 0;
66224 +
66225 + if (lock_task_sighand(task, &flags)) {
66226 + curr_ip = task->signal->curr_ip;
66227 + unlock_task_sighand(task, &flags);
66228 + }
66229 + return seq_printf(m, "%pI4\n", &curr_ip);
66230 +}
66231 +#endif
66232 +
66233 #ifdef CONFIG_CHECKPOINT_RESTORE
66234 static struct pid *
66235 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66236 diff --git a/fs/proc/base.c b/fs/proc/base.c
66237 index baf852b..03fe930 100644
66238 --- a/fs/proc/base.c
66239 +++ b/fs/proc/base.c
66240 @@ -113,6 +113,14 @@ struct pid_entry {
66241 union proc_op op;
66242 };
66243
66244 +struct getdents_callback {
66245 + struct linux_dirent __user * current_dir;
66246 + struct linux_dirent __user * previous;
66247 + struct file * file;
66248 + int count;
66249 + int error;
66250 +};
66251 +
66252 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66253 .name = (NAME), \
66254 .len = sizeof(NAME) - 1, \
66255 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
66256 return 0;
66257 }
66258
66259 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66260 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66261 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66262 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66263 +#endif
66264 +
66265 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66266 struct pid *pid, struct task_struct *task)
66267 {
66268 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66269 if (mm && !IS_ERR(mm)) {
66270 unsigned int nwords = 0;
66271 +
66272 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66273 + /* allow if we're currently ptracing this task */
66274 + if (PAX_RAND_FLAGS(mm) &&
66275 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66276 + mmput(mm);
66277 + return 0;
66278 + }
66279 +#endif
66280 +
66281 do {
66282 nwords += 2;
66283 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66284 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66285 }
66286
66287
66288 -#ifdef CONFIG_KALLSYMS
66289 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66290 /*
66291 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66292 * Returns the resolved symbol. If that fails, simply return the address.
66293 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
66294 mutex_unlock(&task->signal->cred_guard_mutex);
66295 }
66296
66297 -#ifdef CONFIG_STACKTRACE
66298 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66299
66300 #define MAX_STACK_TRACE_DEPTH 64
66301
66302 @@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
66303 return 0;
66304 }
66305
66306 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66307 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66308 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66309 struct pid *pid, struct task_struct *task)
66310 {
66311 @@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66312 /************************************************************************/
66313
66314 /* permission checks */
66315 -static int proc_fd_access_allowed(struct inode *inode)
66316 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66317 {
66318 struct task_struct *task;
66319 int allowed = 0;
66320 @@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66321 */
66322 task = get_proc_task(inode);
66323 if (task) {
66324 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66325 + if (log)
66326 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66327 + else
66328 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66329 put_task_struct(task);
66330 }
66331 return allowed;
66332 @@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66333 struct task_struct *task,
66334 int hide_pid_min)
66335 {
66336 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66337 + return false;
66338 +
66339 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66340 + rcu_read_lock();
66341 + {
66342 + const struct cred *tmpcred = current_cred();
66343 + const struct cred *cred = __task_cred(task);
66344 +
66345 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66346 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66347 + || in_group_p(grsec_proc_gid)
66348 +#endif
66349 + ) {
66350 + rcu_read_unlock();
66351 + return true;
66352 + }
66353 + }
66354 + rcu_read_unlock();
66355 +
66356 + if (!pid->hide_pid)
66357 + return false;
66358 +#endif
66359 +
66360 if (pid->hide_pid < hide_pid_min)
66361 return true;
66362 if (in_group_p(pid->pid_gid))
66363 return true;
66364 +
66365 return ptrace_may_access(task, PTRACE_MODE_READ);
66366 }
66367
66368 @@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66369 put_task_struct(task);
66370
66371 if (!has_perms) {
66372 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66373 + {
66374 +#else
66375 if (pid->hide_pid == 2) {
66376 +#endif
66377 /*
66378 * Let's make getdents(), stat(), and open()
66379 * consistent with each other. If a process
66380 @@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66381 if (!task)
66382 return -ESRCH;
66383
66384 + if (gr_acl_handle_procpidmem(task)) {
66385 + put_task_struct(task);
66386 + return -EPERM;
66387 + }
66388 +
66389 mm = mm_access(task, mode);
66390 put_task_struct(task);
66391
66392 @@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66393
66394 file->private_data = mm;
66395
66396 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66397 + file->f_version = current->exec_id;
66398 +#endif
66399 +
66400 return 0;
66401 }
66402
66403 @@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66404 ssize_t copied;
66405 char *page;
66406
66407 +#ifdef CONFIG_GRKERNSEC
66408 + if (write)
66409 + return -EPERM;
66410 +#endif
66411 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66412 + if (file->f_version != current->exec_id) {
66413 + gr_log_badprocpid("mem");
66414 + return 0;
66415 + }
66416 +#endif
66417 +
66418 if (!mm)
66419 return 0;
66420
66421 @@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66422 goto free;
66423
66424 while (count > 0) {
66425 - int this_len = min_t(int, count, PAGE_SIZE);
66426 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66427
66428 if (write && copy_from_user(page, buf, this_len)) {
66429 copied = -EFAULT;
66430 @@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66431 if (!mm)
66432 return 0;
66433
66434 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66435 + if (file->f_version != current->exec_id) {
66436 + gr_log_badprocpid("environ");
66437 + return 0;
66438 + }
66439 +#endif
66440 +
66441 page = (char *)__get_free_page(GFP_TEMPORARY);
66442 if (!page)
66443 return -ENOMEM;
66444 @@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66445 goto free;
66446 while (count > 0) {
66447 size_t this_len, max_len;
66448 - int retval;
66449 + ssize_t retval;
66450
66451 if (src >= (mm->env_end - mm->env_start))
66452 break;
66453 @@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66454 int error = -EACCES;
66455
66456 /* Are we allowed to snoop on the tasks file descriptors? */
66457 - if (!proc_fd_access_allowed(inode))
66458 + if (!proc_fd_access_allowed(inode, 0))
66459 goto out;
66460
66461 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66462 @@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66463 struct path path;
66464
66465 /* Are we allowed to snoop on the tasks file descriptors? */
66466 - if (!proc_fd_access_allowed(inode))
66467 - goto out;
66468 + /* logging this is needed for learning on chromium to work properly,
66469 + but we don't want to flood the logs from 'ps' which does a readlink
66470 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66471 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66472 + */
66473 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66474 + if (!proc_fd_access_allowed(inode,0))
66475 + goto out;
66476 + } else {
66477 + if (!proc_fd_access_allowed(inode,1))
66478 + goto out;
66479 + }
66480
66481 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66482 if (error)
66483 @@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66484 rcu_read_lock();
66485 cred = __task_cred(task);
66486 inode->i_uid = cred->euid;
66487 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66488 + inode->i_gid = grsec_proc_gid;
66489 +#else
66490 inode->i_gid = cred->egid;
66491 +#endif
66492 rcu_read_unlock();
66493 }
66494 security_task_to_inode(task, inode);
66495 @@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66496 return -ENOENT;
66497 }
66498 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66499 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66500 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66501 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66502 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66503 +#endif
66504 task_dumpable(task)) {
66505 cred = __task_cred(task);
66506 stat->uid = cred->euid;
66507 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66508 + stat->gid = grsec_proc_gid;
66509 +#else
66510 stat->gid = cred->egid;
66511 +#endif
66512 }
66513 }
66514 rcu_read_unlock();
66515 @@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66516
66517 if (task) {
66518 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66519 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66520 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66521 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66522 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66523 +#endif
66524 task_dumpable(task)) {
66525 rcu_read_lock();
66526 cred = __task_cred(task);
66527 inode->i_uid = cred->euid;
66528 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66529 + inode->i_gid = grsec_proc_gid;
66530 +#else
66531 inode->i_gid = cred->egid;
66532 +#endif
66533 rcu_read_unlock();
66534 } else {
66535 inode->i_uid = GLOBAL_ROOT_UID;
66536 @@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66537 if (!task)
66538 goto out_no_task;
66539
66540 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66541 + goto out;
66542 +
66543 /*
66544 * Yes, it does not scale. And it should not. Don't add
66545 * new entries into /proc/<tgid>/ without very good reasons.
66546 @@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66547 if (!task)
66548 return -ENOENT;
66549
66550 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66551 + goto out;
66552 +
66553 if (!dir_emit_dots(file, ctx))
66554 goto out;
66555
66556 @@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66557 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66558 #endif
66559 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66560 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66561 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66562 ONE("syscall", S_IRUSR, proc_pid_syscall),
66563 #endif
66564 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66565 @@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66566 #ifdef CONFIG_SECURITY
66567 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66568 #endif
66569 -#ifdef CONFIG_KALLSYMS
66570 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66571 ONE("wchan", S_IRUGO, proc_pid_wchan),
66572 #endif
66573 -#ifdef CONFIG_STACKTRACE
66574 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66575 ONE("stack", S_IRUSR, proc_pid_stack),
66576 #endif
66577 #ifdef CONFIG_SCHEDSTATS
66578 @@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66579 #ifdef CONFIG_HARDWALL
66580 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66581 #endif
66582 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66583 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66584 +#endif
66585 #ifdef CONFIG_USER_NS
66586 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66587 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66588 @@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
66589 if (!inode)
66590 goto out;
66591
66592 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66593 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66594 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66595 + inode->i_gid = grsec_proc_gid;
66596 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66597 +#else
66598 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66599 +#endif
66600 inode->i_op = &proc_tgid_base_inode_operations;
66601 inode->i_fop = &proc_tgid_base_operations;
66602 inode->i_flags|=S_IMMUTABLE;
66603 @@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66604 if (!task)
66605 goto out;
66606
66607 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66608 + goto out_put_task;
66609 +
66610 result = proc_pid_instantiate(dir, dentry, task, NULL);
66611 +out_put_task:
66612 put_task_struct(task);
66613 out:
66614 return ERR_PTR(result);
66615 @@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
66616 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66617 #endif
66618 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66619 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66620 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66621 ONE("syscall", S_IRUSR, proc_pid_syscall),
66622 #endif
66623 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66624 @@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
66625 #ifdef CONFIG_SECURITY
66626 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66627 #endif
66628 -#ifdef CONFIG_KALLSYMS
66629 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66630 ONE("wchan", S_IRUGO, proc_pid_wchan),
66631 #endif
66632 -#ifdef CONFIG_STACKTRACE
66633 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66634 ONE("stack", S_IRUSR, proc_pid_stack),
66635 #endif
66636 #ifdef CONFIG_SCHEDSTATS
66637 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66638 index cbd82df..c0407d2 100644
66639 --- a/fs/proc/cmdline.c
66640 +++ b/fs/proc/cmdline.c
66641 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66642
66643 static int __init proc_cmdline_init(void)
66644 {
66645 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66646 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66647 +#else
66648 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66649 +#endif
66650 return 0;
66651 }
66652 fs_initcall(proc_cmdline_init);
66653 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66654 index 50493ed..248166b 100644
66655 --- a/fs/proc/devices.c
66656 +++ b/fs/proc/devices.c
66657 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66658
66659 static int __init proc_devices_init(void)
66660 {
66661 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66662 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66663 +#else
66664 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66665 +#endif
66666 return 0;
66667 }
66668 fs_initcall(proc_devices_init);
66669 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66670 index 955bb55..71948bd 100644
66671 --- a/fs/proc/fd.c
66672 +++ b/fs/proc/fd.c
66673 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66674 if (!task)
66675 return -ENOENT;
66676
66677 - files = get_files_struct(task);
66678 + if (!gr_acl_handle_procpidmem(task))
66679 + files = get_files_struct(task);
66680 put_task_struct(task);
66681
66682 if (files) {
66683 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66684 */
66685 int proc_fd_permission(struct inode *inode, int mask)
66686 {
66687 + struct task_struct *task;
66688 int rv = generic_permission(inode, mask);
66689 - if (rv == 0)
66690 - return 0;
66691 +
66692 if (task_tgid(current) == proc_pid(inode))
66693 rv = 0;
66694 +
66695 + task = get_proc_task(inode);
66696 + if (task == NULL)
66697 + return rv;
66698 +
66699 + if (gr_acl_handle_procpidmem(task))
66700 + rv = -EACCES;
66701 +
66702 + put_task_struct(task);
66703 +
66704 return rv;
66705 }
66706
66707 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66708 index 317b726..e329aed 100644
66709 --- a/fs/proc/generic.c
66710 +++ b/fs/proc/generic.c
66711 @@ -23,6 +23,7 @@
66712 #include <linux/bitops.h>
66713 #include <linux/spinlock.h>
66714 #include <linux/completion.h>
66715 +#include <linux/grsecurity.h>
66716 #include <asm/uaccess.h>
66717
66718 #include "internal.h"
66719 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66720 return proc_lookup_de(PDE(dir), dir, dentry);
66721 }
66722
66723 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66724 + unsigned int flags)
66725 +{
66726 + if (gr_proc_is_restricted())
66727 + return ERR_PTR(-EACCES);
66728 +
66729 + return proc_lookup_de(PDE(dir), dir, dentry);
66730 +}
66731 +
66732 /*
66733 * This returns non-zero if at EOF, so that the /proc
66734 * root directory can use this and check if it should
66735 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66736 return proc_readdir_de(PDE(inode), file, ctx);
66737 }
66738
66739 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66740 +{
66741 + struct inode *inode = file_inode(file);
66742 +
66743 + if (gr_proc_is_restricted())
66744 + return -EACCES;
66745 +
66746 + return proc_readdir_de(PDE(inode), file, ctx);
66747 +}
66748 +
66749 /*
66750 * These are the generic /proc directory operations. They
66751 * use the in-memory "struct proc_dir_entry" tree to parse
66752 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66753 .iterate = proc_readdir,
66754 };
66755
66756 +static const struct file_operations proc_dir_restricted_operations = {
66757 + .llseek = generic_file_llseek,
66758 + .read = generic_read_dir,
66759 + .iterate = proc_readdir_restrict,
66760 +};
66761 +
66762 /*
66763 * proc directories can do almost nothing..
66764 */
66765 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66766 .setattr = proc_notify_change,
66767 };
66768
66769 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66770 + .lookup = proc_lookup_restrict,
66771 + .getattr = proc_getattr,
66772 + .setattr = proc_notify_change,
66773 +};
66774 +
66775 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66776 {
66777 struct proc_dir_entry *tmp;
66778 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66779 return ret;
66780
66781 if (S_ISDIR(dp->mode)) {
66782 - dp->proc_fops = &proc_dir_operations;
66783 - dp->proc_iops = &proc_dir_inode_operations;
66784 + if (dp->restricted) {
66785 + dp->proc_fops = &proc_dir_restricted_operations;
66786 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66787 + } else {
66788 + dp->proc_fops = &proc_dir_operations;
66789 + dp->proc_iops = &proc_dir_inode_operations;
66790 + }
66791 dir->nlink++;
66792 } else if (S_ISLNK(dp->mode)) {
66793 dp->proc_iops = &proc_link_inode_operations;
66794 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66795 }
66796 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66797
66798 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66799 + struct proc_dir_entry *parent, void *data)
66800 +{
66801 + struct proc_dir_entry *ent;
66802 +
66803 + if (mode == 0)
66804 + mode = S_IRUGO | S_IXUGO;
66805 +
66806 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66807 + if (ent) {
66808 + ent->data = data;
66809 + ent->restricted = 1;
66810 + if (proc_register(parent, ent) < 0) {
66811 + kfree(ent);
66812 + ent = NULL;
66813 + }
66814 + }
66815 + return ent;
66816 +}
66817 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66818 +
66819 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66820 struct proc_dir_entry *parent)
66821 {
66822 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66823 }
66824 EXPORT_SYMBOL(proc_mkdir);
66825
66826 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66827 + struct proc_dir_entry *parent)
66828 +{
66829 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66830 +}
66831 +EXPORT_SYMBOL(proc_mkdir_restrict);
66832 +
66833 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66834 struct proc_dir_entry *parent,
66835 const struct file_operations *proc_fops,
66836 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66837 index 333080d..0a35ec4 100644
66838 --- a/fs/proc/inode.c
66839 +++ b/fs/proc/inode.c
66840 @@ -23,11 +23,17 @@
66841 #include <linux/slab.h>
66842 #include <linux/mount.h>
66843 #include <linux/magic.h>
66844 +#include <linux/grsecurity.h>
66845
66846 #include <asm/uaccess.h>
66847
66848 #include "internal.h"
66849
66850 +#ifdef CONFIG_PROC_SYSCTL
66851 +extern const struct inode_operations proc_sys_inode_operations;
66852 +extern const struct inode_operations proc_sys_dir_operations;
66853 +#endif
66854 +
66855 static void proc_evict_inode(struct inode *inode)
66856 {
66857 struct proc_dir_entry *de;
66858 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66859 ns = PROC_I(inode)->ns.ns;
66860 if (ns_ops && ns)
66861 ns_ops->put(ns);
66862 +
66863 +#ifdef CONFIG_PROC_SYSCTL
66864 + if (inode->i_op == &proc_sys_inode_operations ||
66865 + inode->i_op == &proc_sys_dir_operations)
66866 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66867 +#endif
66868 +
66869 }
66870
66871 static struct kmem_cache * proc_inode_cachep;
66872 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66873 if (de->mode) {
66874 inode->i_mode = de->mode;
66875 inode->i_uid = de->uid;
66876 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66877 + inode->i_gid = grsec_proc_gid;
66878 +#else
66879 inode->i_gid = de->gid;
66880 +#endif
66881 }
66882 if (de->size)
66883 inode->i_size = de->size;
66884 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66885 index 7da13e4..68d0981 100644
66886 --- a/fs/proc/internal.h
66887 +++ b/fs/proc/internal.h
66888 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66889 struct completion *pde_unload_completion;
66890 struct list_head pde_openers; /* who did ->open, but not ->release */
66891 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66892 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66893 u8 namelen;
66894 char name[];
66895 -};
66896 +} __randomize_layout;
66897
66898 union proc_op {
66899 int (*proc_get_link)(struct dentry *, struct path *);
66900 @@ -66,7 +67,7 @@ struct proc_inode {
66901 struct ctl_table *sysctl_entry;
66902 struct proc_ns ns;
66903 struct inode vfs_inode;
66904 -};
66905 +} __randomize_layout;
66906
66907 /*
66908 * General functions
66909 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66910 struct pid *, struct task_struct *);
66911 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66912 struct pid *, struct task_struct *);
66913 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66914 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66915 + struct pid *, struct task_struct *);
66916 +#endif
66917
66918 /*
66919 * base.c
66920 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66921 * generic.c
66922 */
66923 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66924 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66925 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66926 struct dentry *);
66927 extern int proc_readdir(struct file *, struct dir_context *);
66928 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66929 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66930
66931 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66932 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66933 index a352d57..cb94a5c 100644
66934 --- a/fs/proc/interrupts.c
66935 +++ b/fs/proc/interrupts.c
66936 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66937
66938 static int __init proc_interrupts_init(void)
66939 {
66940 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66941 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66942 +#else
66943 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66944 +#endif
66945 return 0;
66946 }
66947 fs_initcall(proc_interrupts_init);
66948 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66949 index 6df8d07..3321060 100644
66950 --- a/fs/proc/kcore.c
66951 +++ b/fs/proc/kcore.c
66952 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66953 * the addresses in the elf_phdr on our list.
66954 */
66955 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66956 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66957 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66958 + if (tsz > buflen)
66959 tsz = buflen;
66960 -
66961 +
66962 while (buflen) {
66963 struct kcore_list *m;
66964
66965 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66966 kfree(elf_buf);
66967 } else {
66968 if (kern_addr_valid(start)) {
66969 - unsigned long n;
66970 + char *elf_buf;
66971 + mm_segment_t oldfs;
66972
66973 - n = copy_to_user(buffer, (char *)start, tsz);
66974 - /*
66975 - * We cannot distinguish between fault on source
66976 - * and fault on destination. When this happens
66977 - * we clear too and hope it will trigger the
66978 - * EFAULT again.
66979 - */
66980 - if (n) {
66981 - if (clear_user(buffer + tsz - n,
66982 - n))
66983 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66984 + if (!elf_buf)
66985 + return -ENOMEM;
66986 + oldfs = get_fs();
66987 + set_fs(KERNEL_DS);
66988 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66989 + set_fs(oldfs);
66990 + if (copy_to_user(buffer, elf_buf, tsz)) {
66991 + kfree(elf_buf);
66992 return -EFAULT;
66993 + }
66994 }
66995 + set_fs(oldfs);
66996 + kfree(elf_buf);
66997 } else {
66998 if (clear_user(buffer, tsz))
66999 return -EFAULT;
67000 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67001
67002 static int open_kcore(struct inode *inode, struct file *filp)
67003 {
67004 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67005 + return -EPERM;
67006 +#endif
67007 if (!capable(CAP_SYS_RAWIO))
67008 return -EPERM;
67009 if (kcore_need_update)
67010 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
67011 index aa1eee0..03dda72 100644
67012 --- a/fs/proc/meminfo.c
67013 +++ b/fs/proc/meminfo.c
67014 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
67015 vmi.used >> 10,
67016 vmi.largest_chunk >> 10
67017 #ifdef CONFIG_MEMORY_FAILURE
67018 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67019 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67020 #endif
67021 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
67022 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
67023 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
67024 index d4a3574..b421ce9 100644
67025 --- a/fs/proc/nommu.c
67026 +++ b/fs/proc/nommu.c
67027 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
67028
67029 if (file) {
67030 seq_pad(m, ' ');
67031 - seq_path(m, &file->f_path, "");
67032 + seq_path(m, &file->f_path, "\n\\");
67033 }
67034
67035 seq_putc(m, '\n');
67036 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
67037 index a63af3e..b4f262a 100644
67038 --- a/fs/proc/proc_net.c
67039 +++ b/fs/proc/proc_net.c
67040 @@ -23,9 +23,27 @@
67041 #include <linux/nsproxy.h>
67042 #include <net/net_namespace.h>
67043 #include <linux/seq_file.h>
67044 +#include <linux/grsecurity.h>
67045
67046 #include "internal.h"
67047
67048 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67049 +static struct seq_operations *ipv6_seq_ops_addr;
67050 +
67051 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
67052 +{
67053 + ipv6_seq_ops_addr = addr;
67054 +}
67055 +
67056 +void unregister_ipv6_seq_ops_addr(void)
67057 +{
67058 + ipv6_seq_ops_addr = NULL;
67059 +}
67060 +
67061 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
67062 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
67063 +#endif
67064 +
67065 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
67066 {
67067 return pde->parent->data;
67068 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
67069 return maybe_get_net(PDE_NET(PDE(inode)));
67070 }
67071
67072 +extern const struct seq_operations dev_seq_ops;
67073 +
67074 int seq_open_net(struct inode *ino, struct file *f,
67075 const struct seq_operations *ops, int size)
67076 {
67077 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
67078
67079 BUG_ON(size < sizeof(*p));
67080
67081 + /* only permit access to /proc/net/dev */
67082 + if (
67083 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67084 + ops != ipv6_seq_ops_addr &&
67085 +#endif
67086 + ops != &dev_seq_ops && gr_proc_is_restricted())
67087 + return -EACCES;
67088 +
67089 net = get_proc_net(ino);
67090 if (net == NULL)
67091 return -ENXIO;
67092 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
67093 int err;
67094 struct net *net;
67095
67096 + if (gr_proc_is_restricted())
67097 + return -EACCES;
67098 +
67099 err = -ENXIO;
67100 net = get_proc_net(inode);
67101 if (net == NULL)
67102 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
67103 index f92d5dd..26398ac 100644
67104 --- a/fs/proc/proc_sysctl.c
67105 +++ b/fs/proc/proc_sysctl.c
67106 @@ -11,13 +11,21 @@
67107 #include <linux/namei.h>
67108 #include <linux/mm.h>
67109 #include <linux/module.h>
67110 +#include <linux/nsproxy.h>
67111 +#ifdef CONFIG_GRKERNSEC
67112 +#include <net/net_namespace.h>
67113 +#endif
67114 #include "internal.h"
67115
67116 +extern int gr_handle_chroot_sysctl(const int op);
67117 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67118 + const int op);
67119 +
67120 static const struct dentry_operations proc_sys_dentry_operations;
67121 static const struct file_operations proc_sys_file_operations;
67122 -static const struct inode_operations proc_sys_inode_operations;
67123 +const struct inode_operations proc_sys_inode_operations;
67124 static const struct file_operations proc_sys_dir_file_operations;
67125 -static const struct inode_operations proc_sys_dir_operations;
67126 +const struct inode_operations proc_sys_dir_operations;
67127
67128 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67129 {
67130 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67131
67132 err = NULL;
67133 d_set_d_op(dentry, &proc_sys_dentry_operations);
67134 +
67135 + gr_handle_proc_create(dentry, inode);
67136 +
67137 d_add(dentry, inode);
67138
67139 out:
67140 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67141 struct inode *inode = file_inode(filp);
67142 struct ctl_table_header *head = grab_header(inode);
67143 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67144 + int op = write ? MAY_WRITE : MAY_READ;
67145 ssize_t error;
67146 size_t res;
67147
67148 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67149 * and won't be until we finish.
67150 */
67151 error = -EPERM;
67152 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67153 + if (sysctl_perm(head, table, op))
67154 goto out;
67155
67156 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67157 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67158 if (!table->proc_handler)
67159 goto out;
67160
67161 +#ifdef CONFIG_GRKERNSEC
67162 + error = -EPERM;
67163 + if (gr_handle_chroot_sysctl(op))
67164 + goto out;
67165 + dget(filp->f_path.dentry);
67166 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67167 + dput(filp->f_path.dentry);
67168 + goto out;
67169 + }
67170 + dput(filp->f_path.dentry);
67171 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67172 + goto out;
67173 + if (write) {
67174 + if (current->nsproxy->net_ns != table->extra2) {
67175 + if (!capable(CAP_SYS_ADMIN))
67176 + goto out;
67177 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67178 + goto out;
67179 + }
67180 +#endif
67181 +
67182 /* careful: calling conventions are nasty here */
67183 res = count;
67184 error = table->proc_handler(table, write, buf, &res, ppos);
67185 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67186 return false;
67187 } else {
67188 d_set_d_op(child, &proc_sys_dentry_operations);
67189 +
67190 + gr_handle_proc_create(child, inode);
67191 +
67192 d_add(child, inode);
67193 }
67194 } else {
67195 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
67196 if ((*pos)++ < ctx->pos)
67197 return true;
67198
67199 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67200 + return 0;
67201 +
67202 if (unlikely(S_ISLNK(table->mode)))
67203 res = proc_sys_link_fill_cache(file, ctx, head, table);
67204 else
67205 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67206 if (IS_ERR(head))
67207 return PTR_ERR(head);
67208
67209 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67210 + return -ENOENT;
67211 +
67212 generic_fillattr(inode, stat);
67213 if (table)
67214 stat->mode = (stat->mode & S_IFMT) | table->mode;
67215 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67216 .llseek = generic_file_llseek,
67217 };
67218
67219 -static const struct inode_operations proc_sys_inode_operations = {
67220 +const struct inode_operations proc_sys_inode_operations = {
67221 .permission = proc_sys_permission,
67222 .setattr = proc_sys_setattr,
67223 .getattr = proc_sys_getattr,
67224 };
67225
67226 -static const struct inode_operations proc_sys_dir_operations = {
67227 +const struct inode_operations proc_sys_dir_operations = {
67228 .lookup = proc_sys_lookup,
67229 .permission = proc_sys_permission,
67230 .setattr = proc_sys_setattr,
67231 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67232 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67233 const char *name, int namelen)
67234 {
67235 - struct ctl_table *table;
67236 + ctl_table_no_const *table;
67237 struct ctl_dir *new;
67238 struct ctl_node *node;
67239 char *new_name;
67240 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67241 return NULL;
67242
67243 node = (struct ctl_node *)(new + 1);
67244 - table = (struct ctl_table *)(node + 1);
67245 + table = (ctl_table_no_const *)(node + 1);
67246 new_name = (char *)(table + 2);
67247 memcpy(new_name, name, namelen);
67248 new_name[namelen] = '\0';
67249 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67250 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67251 struct ctl_table_root *link_root)
67252 {
67253 - struct ctl_table *link_table, *entry, *link;
67254 + ctl_table_no_const *link_table, *link;
67255 + struct ctl_table *entry;
67256 struct ctl_table_header *links;
67257 struct ctl_node *node;
67258 char *link_name;
67259 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67260 return NULL;
67261
67262 node = (struct ctl_node *)(links + 1);
67263 - link_table = (struct ctl_table *)(node + nr_entries);
67264 + link_table = (ctl_table_no_const *)(node + nr_entries);
67265 link_name = (char *)&link_table[nr_entries + 1];
67266
67267 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67268 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67269 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67270 struct ctl_table *table)
67271 {
67272 - struct ctl_table *ctl_table_arg = NULL;
67273 - struct ctl_table *entry, *files;
67274 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67275 + struct ctl_table *entry;
67276 int nr_files = 0;
67277 int nr_dirs = 0;
67278 int err = -ENOMEM;
67279 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67280 nr_files++;
67281 }
67282
67283 - files = table;
67284 /* If there are mixed files and directories we need a new table */
67285 if (nr_dirs && nr_files) {
67286 - struct ctl_table *new;
67287 + ctl_table_no_const *new;
67288 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67289 GFP_KERNEL);
67290 if (!files)
67291 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67292 /* Register everything except a directory full of subdirectories */
67293 if (nr_files || !nr_dirs) {
67294 struct ctl_table_header *header;
67295 - header = __register_sysctl_table(set, path, files);
67296 + header = __register_sysctl_table(set, path, files ? files : table);
67297 if (!header) {
67298 kfree(ctl_table_arg);
67299 goto out;
67300 diff --git a/fs/proc/root.c b/fs/proc/root.c
67301 index 094e44d..085a877 100644
67302 --- a/fs/proc/root.c
67303 +++ b/fs/proc/root.c
67304 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
67305 proc_mkdir("openprom", NULL);
67306 #endif
67307 proc_tty_init();
67308 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67309 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67310 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67311 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67312 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67313 +#endif
67314 +#else
67315 proc_mkdir("bus", NULL);
67316 +#endif
67317 proc_sys_init();
67318 }
67319
67320 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67321 index bf2d03f..f058f9c 100644
67322 --- a/fs/proc/stat.c
67323 +++ b/fs/proc/stat.c
67324 @@ -11,6 +11,7 @@
67325 #include <linux/irqnr.h>
67326 #include <linux/cputime.h>
67327 #include <linux/tick.h>
67328 +#include <linux/grsecurity.h>
67329
67330 #ifndef arch_irq_stat_cpu
67331 #define arch_irq_stat_cpu(cpu) 0
67332 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67333 u64 sum_softirq = 0;
67334 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67335 struct timespec boottime;
67336 + int unrestricted = 1;
67337 +
67338 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67339 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67340 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67341 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67342 + && !in_group_p(grsec_proc_gid)
67343 +#endif
67344 + )
67345 + unrestricted = 0;
67346 +#endif
67347 +#endif
67348
67349 user = nice = system = idle = iowait =
67350 irq = softirq = steal = 0;
67351 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67352 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67353 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67354 idle += get_idle_time(i);
67355 - iowait += get_iowait_time(i);
67356 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67357 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67358 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67359 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67360 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67361 - sum += kstat_cpu_irqs_sum(i);
67362 - sum += arch_irq_stat_cpu(i);
67363 + if (unrestricted) {
67364 + iowait += get_iowait_time(i);
67365 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67366 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67367 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67368 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67369 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67370 + sum += kstat_cpu_irqs_sum(i);
67371 + sum += arch_irq_stat_cpu(i);
67372 + for (j = 0; j < NR_SOFTIRQS; j++) {
67373 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67374
67375 - for (j = 0; j < NR_SOFTIRQS; j++) {
67376 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67377 -
67378 - per_softirq_sums[j] += softirq_stat;
67379 - sum_softirq += softirq_stat;
67380 + per_softirq_sums[j] += softirq_stat;
67381 + sum_softirq += softirq_stat;
67382 + }
67383 }
67384 }
67385 - sum += arch_irq_stat();
67386 + if (unrestricted)
67387 + sum += arch_irq_stat();
67388
67389 seq_puts(p, "cpu ");
67390 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67391 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67392 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67393 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67394 idle = get_idle_time(i);
67395 - iowait = get_iowait_time(i);
67396 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67397 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67398 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67399 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67400 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67401 + if (unrestricted) {
67402 + iowait = get_iowait_time(i);
67403 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67404 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67405 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67406 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67407 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67408 + }
67409 seq_printf(p, "cpu%d", i);
67410 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67411 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67412 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67413
67414 /* sum again ? it could be updated? */
67415 for_each_irq_nr(j)
67416 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67417 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67418
67419 seq_printf(p,
67420 "\nctxt %llu\n"
67421 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67422 "processes %lu\n"
67423 "procs_running %lu\n"
67424 "procs_blocked %lu\n",
67425 - nr_context_switches(),
67426 + unrestricted ? nr_context_switches() : 0ULL,
67427 (unsigned long)jif,
67428 - total_forks,
67429 - nr_running(),
67430 - nr_iowait());
67431 + unrestricted ? total_forks : 0UL,
67432 + unrestricted ? nr_running() : 0UL,
67433 + unrestricted ? nr_iowait() : 0UL);
67434
67435 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67436
67437 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67438 index c341568..75852a2 100644
67439 --- a/fs/proc/task_mmu.c
67440 +++ b/fs/proc/task_mmu.c
67441 @@ -13,12 +13,19 @@
67442 #include <linux/swap.h>
67443 #include <linux/swapops.h>
67444 #include <linux/mmu_notifier.h>
67445 +#include <linux/grsecurity.h>
67446
67447 #include <asm/elf.h>
67448 #include <asm/uaccess.h>
67449 #include <asm/tlbflush.h>
67450 #include "internal.h"
67451
67452 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67453 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67454 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67455 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67456 +#endif
67457 +
67458 void task_mem(struct seq_file *m, struct mm_struct *mm)
67459 {
67460 unsigned long data, text, lib, swap;
67461 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67462 "VmExe:\t%8lu kB\n"
67463 "VmLib:\t%8lu kB\n"
67464 "VmPTE:\t%8lu kB\n"
67465 - "VmSwap:\t%8lu kB\n",
67466 - hiwater_vm << (PAGE_SHIFT-10),
67467 + "VmSwap:\t%8lu kB\n"
67468 +
67469 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67470 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67471 +#endif
67472 +
67473 + ,hiwater_vm << (PAGE_SHIFT-10),
67474 total_vm << (PAGE_SHIFT-10),
67475 mm->locked_vm << (PAGE_SHIFT-10),
67476 mm->pinned_vm << (PAGE_SHIFT-10),
67477 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67478 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67479 (PTRS_PER_PTE * sizeof(pte_t) *
67480 atomic_long_read(&mm->nr_ptes)) >> 10,
67481 - swap << (PAGE_SHIFT-10));
67482 + swap << (PAGE_SHIFT-10)
67483 +
67484 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67485 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67486 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67487 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67488 +#else
67489 + , mm->context.user_cs_base
67490 + , mm->context.user_cs_limit
67491 +#endif
67492 +#endif
67493 +
67494 + );
67495 }
67496
67497 unsigned long task_vsize(struct mm_struct *mm)
67498 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67499 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67500 }
67501
67502 - /* We don't show the stack guard page in /proc/maps */
67503 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67504 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67505 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67506 +#else
67507 start = vma->vm_start;
67508 - if (stack_guard_page_start(vma, start))
67509 - start += PAGE_SIZE;
67510 end = vma->vm_end;
67511 - if (stack_guard_page_end(vma, end))
67512 - end -= PAGE_SIZE;
67513 +#endif
67514
67515 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67516 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67517 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67518 flags & VM_WRITE ? 'w' : '-',
67519 flags & VM_EXEC ? 'x' : '-',
67520 flags & VM_MAYSHARE ? 's' : 'p',
67521 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67522 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67523 +#else
67524 pgoff,
67525 +#endif
67526 MAJOR(dev), MINOR(dev), ino);
67527
67528 /*
67529 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67530 */
67531 if (file) {
67532 seq_pad(m, ' ');
67533 - seq_path(m, &file->f_path, "\n");
67534 + seq_path(m, &file->f_path, "\n\\");
67535 goto done;
67536 }
67537
67538 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67539 * Thread stack in /proc/PID/task/TID/maps or
67540 * the main process stack.
67541 */
67542 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67543 - vma->vm_end >= mm->start_stack)) {
67544 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67545 + (vma->vm_start <= mm->start_stack &&
67546 + vma->vm_end >= mm->start_stack)) {
67547 name = "[stack]";
67548 } else {
67549 /* Thread stack in /proc/PID/maps */
67550 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67551 struct proc_maps_private *priv = m->private;
67552 struct task_struct *task = priv->task;
67553
67554 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67555 + if (current->exec_id != m->exec_id) {
67556 + gr_log_badprocpid("maps");
67557 + return 0;
67558 + }
67559 +#endif
67560 +
67561 show_map_vma(m, vma, is_pid);
67562
67563 if (m->count < m->size) /* vma is copied successfully */
67564 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67565 .private = &mss,
67566 };
67567
67568 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67569 + if (current->exec_id != m->exec_id) {
67570 + gr_log_badprocpid("smaps");
67571 + return 0;
67572 + }
67573 +#endif
67574 memset(&mss, 0, sizeof mss);
67575 - mss.vma = vma;
67576 - /* mmap_sem is held in m_start */
67577 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67578 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67579 -
67580 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67581 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67582 +#endif
67583 + mss.vma = vma;
67584 + /* mmap_sem is held in m_start */
67585 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67586 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67587 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67588 + }
67589 +#endif
67590 show_map_vma(m, vma, is_pid);
67591
67592 seq_printf(m,
67593 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67594 "KernelPageSize: %8lu kB\n"
67595 "MMUPageSize: %8lu kB\n"
67596 "Locked: %8lu kB\n",
67597 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67598 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67599 +#else
67600 (vma->vm_end - vma->vm_start) >> 10,
67601 +#endif
67602 mss.resident >> 10,
67603 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67604 mss.shared_clean >> 10,
67605 @@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67606 char buffer[64];
67607 int nid;
67608
67609 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67610 + if (current->exec_id != m->exec_id) {
67611 + gr_log_badprocpid("numa_maps");
67612 + return 0;
67613 + }
67614 +#endif
67615 +
67616 if (!mm)
67617 return 0;
67618
67619 @@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67620 mpol_to_str(buffer, sizeof(buffer), pol);
67621 mpol_cond_put(pol);
67622
67623 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67624 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67625 +#else
67626 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67627 +#endif
67628
67629 if (file) {
67630 seq_puts(m, " file=");
67631 - seq_path(m, &file->f_path, "\n\t= ");
67632 + seq_path(m, &file->f_path, "\n\t\\= ");
67633 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67634 seq_puts(m, " heap");
67635 } else {
67636 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67637 index 678455d..ebd3245 100644
67638 --- a/fs/proc/task_nommu.c
67639 +++ b/fs/proc/task_nommu.c
67640 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67641 else
67642 bytes += kobjsize(mm);
67643
67644 - if (current->fs && current->fs->users > 1)
67645 + if (current->fs && atomic_read(&current->fs->users) > 1)
67646 sbytes += kobjsize(current->fs);
67647 else
67648 bytes += kobjsize(current->fs);
67649 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67650
67651 if (file) {
67652 seq_pad(m, ' ');
67653 - seq_path(m, &file->f_path, "");
67654 + seq_path(m, &file->f_path, "\n\\");
67655 } else if (mm) {
67656 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67657
67658 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67659 index a90d6d35..d08047c 100644
67660 --- a/fs/proc/vmcore.c
67661 +++ b/fs/proc/vmcore.c
67662 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67663 nr_bytes = count;
67664
67665 /* If pfn is not ram, return zeros for sparse dump files */
67666 - if (pfn_is_ram(pfn) == 0)
67667 - memset(buf, 0, nr_bytes);
67668 - else {
67669 + if (pfn_is_ram(pfn) == 0) {
67670 + if (userbuf) {
67671 + if (clear_user((char __force_user *)buf, nr_bytes))
67672 + return -EFAULT;
67673 + } else
67674 + memset(buf, 0, nr_bytes);
67675 + } else {
67676 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67677 offset, userbuf);
67678 if (tmp < 0)
67679 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67680 static int copy_to(void *target, void *src, size_t size, int userbuf)
67681 {
67682 if (userbuf) {
67683 - if (copy_to_user((char __user *) target, src, size))
67684 + if (copy_to_user((char __force_user *) target, src, size))
67685 return -EFAULT;
67686 } else {
67687 memcpy(target, src, size);
67688 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67689 if (*fpos < m->offset + m->size) {
67690 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67691 start = m->paddr + *fpos - m->offset;
67692 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67693 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67694 if (tmp < 0)
67695 return tmp;
67696 buflen -= tsz;
67697 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67698 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67699 size_t buflen, loff_t *fpos)
67700 {
67701 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67702 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67703 }
67704
67705 /*
67706 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67707 index d3fb2b6..43a8140 100644
67708 --- a/fs/qnx6/qnx6.h
67709 +++ b/fs/qnx6/qnx6.h
67710 @@ -74,7 +74,7 @@ enum {
67711 BYTESEX_BE,
67712 };
67713
67714 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67715 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67716 {
67717 if (sbi->s_bytesex == BYTESEX_LE)
67718 return le64_to_cpu((__force __le64)n);
67719 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67720 return (__force __fs64)cpu_to_be64(n);
67721 }
67722
67723 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67724 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67725 {
67726 if (sbi->s_bytesex == BYTESEX_LE)
67727 return le32_to_cpu((__force __le32)n);
67728 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67729 index bb2869f..d34ada8 100644
67730 --- a/fs/quota/netlink.c
67731 +++ b/fs/quota/netlink.c
67732 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67733 void quota_send_warning(struct kqid qid, dev_t dev,
67734 const char warntype)
67735 {
67736 - static atomic_t seq;
67737 + static atomic_unchecked_t seq;
67738 struct sk_buff *skb;
67739 void *msg_head;
67740 int ret;
67741 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67742 "VFS: Not enough memory to send quota warning.\n");
67743 return;
67744 }
67745 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67746 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67747 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67748 if (!msg_head) {
67749 printk(KERN_ERR
67750 diff --git a/fs/read_write.c b/fs/read_write.c
67751 index 009d854..16ce214 100644
67752 --- a/fs/read_write.c
67753 +++ b/fs/read_write.c
67754 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67755
67756 old_fs = get_fs();
67757 set_fs(get_ds());
67758 - p = (__force const char __user *)buf;
67759 + p = (const char __force_user *)buf;
67760 if (count > MAX_RW_COUNT)
67761 count = MAX_RW_COUNT;
67762 if (file->f_op->write)
67763 diff --git a/fs/readdir.c b/fs/readdir.c
67764 index 33fd922..e0d6094 100644
67765 --- a/fs/readdir.c
67766 +++ b/fs/readdir.c
67767 @@ -18,6 +18,7 @@
67768 #include <linux/security.h>
67769 #include <linux/syscalls.h>
67770 #include <linux/unistd.h>
67771 +#include <linux/namei.h>
67772
67773 #include <asm/uaccess.h>
67774
67775 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67776 struct readdir_callback {
67777 struct dir_context ctx;
67778 struct old_linux_dirent __user * dirent;
67779 + struct file * file;
67780 int result;
67781 };
67782
67783 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67784 buf->result = -EOVERFLOW;
67785 return -EOVERFLOW;
67786 }
67787 +
67788 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67789 + return 0;
67790 +
67791 buf->result++;
67792 dirent = buf->dirent;
67793 if (!access_ok(VERIFY_WRITE, dirent,
67794 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67795 if (!f.file)
67796 return -EBADF;
67797
67798 + buf.file = f.file;
67799 error = iterate_dir(f.file, &buf.ctx);
67800 if (buf.result)
67801 error = buf.result;
67802 @@ -144,6 +151,7 @@ struct getdents_callback {
67803 struct dir_context ctx;
67804 struct linux_dirent __user * current_dir;
67805 struct linux_dirent __user * previous;
67806 + struct file * file;
67807 int count;
67808 int error;
67809 };
67810 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67811 buf->error = -EOVERFLOW;
67812 return -EOVERFLOW;
67813 }
67814 +
67815 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67816 + return 0;
67817 +
67818 dirent = buf->previous;
67819 if (dirent) {
67820 if (__put_user(offset, &dirent->d_off))
67821 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67822 if (!f.file)
67823 return -EBADF;
67824
67825 + buf.file = f.file;
67826 error = iterate_dir(f.file, &buf.ctx);
67827 if (error >= 0)
67828 error = buf.error;
67829 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67830 struct dir_context ctx;
67831 struct linux_dirent64 __user * current_dir;
67832 struct linux_dirent64 __user * previous;
67833 + struct file *file;
67834 int count;
67835 int error;
67836 };
67837 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67838 buf->error = -EINVAL; /* only used if we fail.. */
67839 if (reclen > buf->count)
67840 return -EINVAL;
67841 +
67842 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67843 + return 0;
67844 +
67845 dirent = buf->previous;
67846 if (dirent) {
67847 if (__put_user(offset, &dirent->d_off))
67848 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67849 if (!f.file)
67850 return -EBADF;
67851
67852 + buf.file = f.file;
67853 error = iterate_dir(f.file, &buf.ctx);
67854 if (error >= 0)
67855 error = buf.error;
67856 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67857 index 9c02d96..6562c10 100644
67858 --- a/fs/reiserfs/do_balan.c
67859 +++ b/fs/reiserfs/do_balan.c
67860 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67861 return;
67862 }
67863
67864 - atomic_inc(&fs_generation(tb->tb_sb));
67865 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67866 do_balance_starts(tb);
67867
67868 /*
67869 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67870 index aca73dd..e3c558d 100644
67871 --- a/fs/reiserfs/item_ops.c
67872 +++ b/fs/reiserfs/item_ops.c
67873 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67874 }
67875
67876 static struct item_operations errcatch_ops = {
67877 - errcatch_bytes_number,
67878 - errcatch_decrement_key,
67879 - errcatch_is_left_mergeable,
67880 - errcatch_print_item,
67881 - errcatch_check_item,
67882 + .bytes_number = errcatch_bytes_number,
67883 + .decrement_key = errcatch_decrement_key,
67884 + .is_left_mergeable = errcatch_is_left_mergeable,
67885 + .print_item = errcatch_print_item,
67886 + .check_item = errcatch_check_item,
67887
67888 - errcatch_create_vi,
67889 - errcatch_check_left,
67890 - errcatch_check_right,
67891 - errcatch_part_size,
67892 - errcatch_unit_num,
67893 - errcatch_print_vi
67894 + .create_vi = errcatch_create_vi,
67895 + .check_left = errcatch_check_left,
67896 + .check_right = errcatch_check_right,
67897 + .part_size = errcatch_part_size,
67898 + .unit_num = errcatch_unit_num,
67899 + .print_vi = errcatch_print_vi
67900 };
67901
67902 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67903 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67904 index 621b9f3..af527fd 100644
67905 --- a/fs/reiserfs/procfs.c
67906 +++ b/fs/reiserfs/procfs.c
67907 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67908 "SMALL_TAILS " : "NO_TAILS ",
67909 replay_only(sb) ? "REPLAY_ONLY " : "",
67910 convert_reiserfs(sb) ? "CONV " : "",
67911 - atomic_read(&r->s_generation_counter),
67912 + atomic_read_unchecked(&r->s_generation_counter),
67913 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67914 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67915 SF(s_good_search_by_key_reada), SF(s_bmaps),
67916 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67917 index 735c2c2..81b91af 100644
67918 --- a/fs/reiserfs/reiserfs.h
67919 +++ b/fs/reiserfs/reiserfs.h
67920 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
67921 /* Comment? -Hans */
67922 wait_queue_head_t s_wait;
67923 /* increased by one every time the tree gets re-balanced */
67924 - atomic_t s_generation_counter;
67925 + atomic_unchecked_t s_generation_counter;
67926
67927 /* File system properties. Currently holds on-disk FS format */
67928 unsigned long s_properties;
67929 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67930 #define REISERFS_USER_MEM 1 /* user memory mode */
67931
67932 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67933 -#define get_generation(s) atomic_read (&fs_generation(s))
67934 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67935 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67936 #define __fs_changed(gen,s) (gen != get_generation (s))
67937 #define fs_changed(gen,s) \
67938 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67939 index d46e88a..1a06a94 100644
67940 --- a/fs/reiserfs/super.c
67941 +++ b/fs/reiserfs/super.c
67942 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67943 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67944 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67945 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67946 +#ifdef CONFIG_REISERFS_FS_XATTR
67947 + /* turn on user xattrs by default */
67948 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67949 +#endif
67950 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67951 sbi->s_alloc_options.preallocmin = 0;
67952 /* Preallocate by 16 blocks (17-1) at once */
67953 diff --git a/fs/select.c b/fs/select.c
67954 index 467bb1c..cf9d65a 100644
67955 --- a/fs/select.c
67956 +++ b/fs/select.c
67957 @@ -20,6 +20,7 @@
67958 #include <linux/export.h>
67959 #include <linux/slab.h>
67960 #include <linux/poll.h>
67961 +#include <linux/security.h>
67962 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67963 #include <linux/file.h>
67964 #include <linux/fdtable.h>
67965 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67966 struct poll_list *walk = head;
67967 unsigned long todo = nfds;
67968
67969 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67970 if (nfds > rlimit(RLIMIT_NOFILE))
67971 return -EINVAL;
67972
67973 diff --git a/fs/seq_file.c b/fs/seq_file.c
67974 index 3857b72..0b7281e 100644
67975 --- a/fs/seq_file.c
67976 +++ b/fs/seq_file.c
67977 @@ -12,6 +12,8 @@
67978 #include <linux/slab.h>
67979 #include <linux/cred.h>
67980 #include <linux/mm.h>
67981 +#include <linux/sched.h>
67982 +#include <linux/grsecurity.h>
67983
67984 #include <asm/uaccess.h>
67985 #include <asm/page.h>
67986 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67987
67988 static void *seq_buf_alloc(unsigned long size)
67989 {
67990 - void *buf;
67991 -
67992 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67993 - if (!buf && size > PAGE_SIZE)
67994 - buf = vmalloc(size);
67995 - return buf;
67996 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67997 }
67998
67999 /**
68000 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
68001 #ifdef CONFIG_USER_NS
68002 p->user_ns = file->f_cred->user_ns;
68003 #endif
68004 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68005 + p->exec_id = current->exec_id;
68006 +#endif
68007
68008 /*
68009 * Wrappers around seq_open(e.g. swaps_open) need to be
68010 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
68011 }
68012 EXPORT_SYMBOL(seq_open);
68013
68014 +
68015 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
68016 +{
68017 + if (gr_proc_is_restricted())
68018 + return -EACCES;
68019 +
68020 + return seq_open(file, op);
68021 +}
68022 +EXPORT_SYMBOL(seq_open_restrict);
68023 +
68024 static int traverse(struct seq_file *m, loff_t offset)
68025 {
68026 loff_t pos = 0, index;
68027 @@ -165,7 +175,7 @@ Eoverflow:
68028 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
68029 {
68030 struct seq_file *m = file->private_data;
68031 - size_t copied = 0;
68032 + ssize_t copied = 0;
68033 loff_t pos;
68034 size_t n;
68035 void *p;
68036 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
68037 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
68038 void *data)
68039 {
68040 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
68041 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
68042 int res = -ENOMEM;
68043
68044 if (op) {
68045 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
68046 }
68047 EXPORT_SYMBOL(single_open_size);
68048
68049 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
68050 + void *data)
68051 +{
68052 + if (gr_proc_is_restricted())
68053 + return -EACCES;
68054 +
68055 + return single_open(file, show, data);
68056 +}
68057 +EXPORT_SYMBOL(single_open_restrict);
68058 +
68059 +
68060 int single_release(struct inode *inode, struct file *file)
68061 {
68062 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
68063 diff --git a/fs/splice.c b/fs/splice.c
68064 index f5cb9ba..8ddb1e9 100644
68065 --- a/fs/splice.c
68066 +++ b/fs/splice.c
68067 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68068 pipe_lock(pipe);
68069
68070 for (;;) {
68071 - if (!pipe->readers) {
68072 + if (!atomic_read(&pipe->readers)) {
68073 send_sig(SIGPIPE, current, 0);
68074 if (!ret)
68075 ret = -EPIPE;
68076 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68077 page_nr++;
68078 ret += buf->len;
68079
68080 - if (pipe->files)
68081 + if (atomic_read(&pipe->files))
68082 do_wakeup = 1;
68083
68084 if (!--spd->nr_pages)
68085 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68086 do_wakeup = 0;
68087 }
68088
68089 - pipe->waiting_writers++;
68090 + atomic_inc(&pipe->waiting_writers);
68091 pipe_wait(pipe);
68092 - pipe->waiting_writers--;
68093 + atomic_dec(&pipe->waiting_writers);
68094 }
68095
68096 pipe_unlock(pipe);
68097 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
68098 old_fs = get_fs();
68099 set_fs(get_ds());
68100 /* The cast to a user pointer is valid due to the set_fs() */
68101 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
68102 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
68103 set_fs(old_fs);
68104
68105 return res;
68106 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
68107 old_fs = get_fs();
68108 set_fs(get_ds());
68109 /* The cast to a user pointer is valid due to the set_fs() */
68110 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
68111 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
68112 set_fs(old_fs);
68113
68114 return res;
68115 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
68116 goto err;
68117
68118 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
68119 - vec[i].iov_base = (void __user *) page_address(page);
68120 + vec[i].iov_base = (void __force_user *) page_address(page);
68121 vec[i].iov_len = this_len;
68122 spd.pages[i] = page;
68123 spd.nr_pages++;
68124 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68125 ops->release(pipe, buf);
68126 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68127 pipe->nrbufs--;
68128 - if (pipe->files)
68129 + if (atomic_read(&pipe->files))
68130 sd->need_wakeup = true;
68131 }
68132
68133 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68134 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68135 {
68136 while (!pipe->nrbufs) {
68137 - if (!pipe->writers)
68138 + if (!atomic_read(&pipe->writers))
68139 return 0;
68140
68141 - if (!pipe->waiting_writers && sd->num_spliced)
68142 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68143 return 0;
68144
68145 if (sd->flags & SPLICE_F_NONBLOCK)
68146 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68147 ops->release(pipe, buf);
68148 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68149 pipe->nrbufs--;
68150 - if (pipe->files)
68151 + if (atomic_read(&pipe->files))
68152 sd.need_wakeup = true;
68153 } else {
68154 buf->offset += ret;
68155 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68156 * out of the pipe right after the splice_to_pipe(). So set
68157 * PIPE_READERS appropriately.
68158 */
68159 - pipe->readers = 1;
68160 + atomic_set(&pipe->readers, 1);
68161
68162 current->splice_pipe = pipe;
68163 }
68164 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68165
68166 partial[buffers].offset = off;
68167 partial[buffers].len = plen;
68168 + partial[buffers].private = 0;
68169
68170 off = 0;
68171 len -= plen;
68172 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68173 ret = -ERESTARTSYS;
68174 break;
68175 }
68176 - if (!pipe->writers)
68177 + if (!atomic_read(&pipe->writers))
68178 break;
68179 - if (!pipe->waiting_writers) {
68180 + if (!atomic_read(&pipe->waiting_writers)) {
68181 if (flags & SPLICE_F_NONBLOCK) {
68182 ret = -EAGAIN;
68183 break;
68184 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68185 pipe_lock(pipe);
68186
68187 while (pipe->nrbufs >= pipe->buffers) {
68188 - if (!pipe->readers) {
68189 + if (!atomic_read(&pipe->readers)) {
68190 send_sig(SIGPIPE, current, 0);
68191 ret = -EPIPE;
68192 break;
68193 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68194 ret = -ERESTARTSYS;
68195 break;
68196 }
68197 - pipe->waiting_writers++;
68198 + atomic_inc(&pipe->waiting_writers);
68199 pipe_wait(pipe);
68200 - pipe->waiting_writers--;
68201 + atomic_dec(&pipe->waiting_writers);
68202 }
68203
68204 pipe_unlock(pipe);
68205 @@ -1817,14 +1818,14 @@ retry:
68206 pipe_double_lock(ipipe, opipe);
68207
68208 do {
68209 - if (!opipe->readers) {
68210 + if (!atomic_read(&opipe->readers)) {
68211 send_sig(SIGPIPE, current, 0);
68212 if (!ret)
68213 ret = -EPIPE;
68214 break;
68215 }
68216
68217 - if (!ipipe->nrbufs && !ipipe->writers)
68218 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68219 break;
68220
68221 /*
68222 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68223 pipe_double_lock(ipipe, opipe);
68224
68225 do {
68226 - if (!opipe->readers) {
68227 + if (!atomic_read(&opipe->readers)) {
68228 send_sig(SIGPIPE, current, 0);
68229 if (!ret)
68230 ret = -EPIPE;
68231 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68232 * return EAGAIN if we have the potential of some data in the
68233 * future, otherwise just return 0
68234 */
68235 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68236 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68237 ret = -EAGAIN;
68238
68239 pipe_unlock(ipipe);
68240 diff --git a/fs/stat.c b/fs/stat.c
68241 index ae0c3ce..9ee641c 100644
68242 --- a/fs/stat.c
68243 +++ b/fs/stat.c
68244 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68245 stat->gid = inode->i_gid;
68246 stat->rdev = inode->i_rdev;
68247 stat->size = i_size_read(inode);
68248 - stat->atime = inode->i_atime;
68249 - stat->mtime = inode->i_mtime;
68250 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68251 + stat->atime = inode->i_ctime;
68252 + stat->mtime = inode->i_ctime;
68253 + } else {
68254 + stat->atime = inode->i_atime;
68255 + stat->mtime = inode->i_mtime;
68256 + }
68257 stat->ctime = inode->i_ctime;
68258 stat->blksize = (1 << inode->i_blkbits);
68259 stat->blocks = inode->i_blocks;
68260 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68261 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68262 {
68263 struct inode *inode = path->dentry->d_inode;
68264 + int retval;
68265
68266 - if (inode->i_op->getattr)
68267 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
68268 + if (inode->i_op->getattr) {
68269 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68270 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68271 + stat->atime = stat->ctime;
68272 + stat->mtime = stat->ctime;
68273 + }
68274 + return retval;
68275 + }
68276
68277 generic_fillattr(inode, stat);
68278 return 0;
68279 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68280 index 0b45ff4..847de5b 100644
68281 --- a/fs/sysfs/dir.c
68282 +++ b/fs/sysfs/dir.c
68283 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68284 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68285 {
68286 struct kernfs_node *parent, *kn;
68287 + const char *name;
68288 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68289 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68290 + const char *parent_name;
68291 +#endif
68292
68293 BUG_ON(!kobj);
68294
68295 + name = kobject_name(kobj);
68296 +
68297 if (kobj->parent)
68298 parent = kobj->parent->sd;
68299 else
68300 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68301 if (!parent)
68302 return -ENOENT;
68303
68304 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68305 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68306 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68307 + parent_name = parent->name;
68308 + mode = S_IRWXU;
68309 +
68310 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68311 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68312 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68313 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68314 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68315 +#endif
68316 +
68317 + kn = kernfs_create_dir_ns(parent, name,
68318 + mode, kobj, ns);
68319 if (IS_ERR(kn)) {
68320 if (PTR_ERR(kn) == -EEXIST)
68321 - sysfs_warn_dup(parent, kobject_name(kobj));
68322 + sysfs_warn_dup(parent, name);
68323 return PTR_ERR(kn);
68324 }
68325
68326 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68327 index 69d4889..a810bd4 100644
68328 --- a/fs/sysv/sysv.h
68329 +++ b/fs/sysv/sysv.h
68330 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68331 #endif
68332 }
68333
68334 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68335 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68336 {
68337 if (sbi->s_bytesex == BYTESEX_PDP)
68338 return PDP_swab((__force __u32)n);
68339 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68340 index fb08b0c..65fcc7e 100644
68341 --- a/fs/ubifs/io.c
68342 +++ b/fs/ubifs/io.c
68343 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68344 return err;
68345 }
68346
68347 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68348 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68349 {
68350 int err;
68351
68352 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68353 index c175b4d..8f36a16 100644
68354 --- a/fs/udf/misc.c
68355 +++ b/fs/udf/misc.c
68356 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68357
68358 u8 udf_tag_checksum(const struct tag *t)
68359 {
68360 - u8 *data = (u8 *)t;
68361 + const u8 *data = (const u8 *)t;
68362 u8 checksum = 0;
68363 int i;
68364 for (i = 0; i < sizeof(struct tag); ++i)
68365 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68366 index 8d974c4..b82f6ec 100644
68367 --- a/fs/ufs/swab.h
68368 +++ b/fs/ufs/swab.h
68369 @@ -22,7 +22,7 @@ enum {
68370 BYTESEX_BE
68371 };
68372
68373 -static inline u64
68374 +static inline u64 __intentional_overflow(-1)
68375 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68376 {
68377 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68378 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68379 return (__force __fs64)cpu_to_be64(n);
68380 }
68381
68382 -static inline u32
68383 +static inline u32 __intentional_overflow(-1)
68384 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68385 {
68386 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68387 diff --git a/fs/utimes.c b/fs/utimes.c
68388 index aa138d6..5f3a811 100644
68389 --- a/fs/utimes.c
68390 +++ b/fs/utimes.c
68391 @@ -1,6 +1,7 @@
68392 #include <linux/compiler.h>
68393 #include <linux/file.h>
68394 #include <linux/fs.h>
68395 +#include <linux/security.h>
68396 #include <linux/linkage.h>
68397 #include <linux/mount.h>
68398 #include <linux/namei.h>
68399 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68400 }
68401 }
68402 retry_deleg:
68403 +
68404 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68405 + error = -EACCES;
68406 + goto mnt_drop_write_and_out;
68407 + }
68408 +
68409 mutex_lock(&inode->i_mutex);
68410 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68411 mutex_unlock(&inode->i_mutex);
68412 diff --git a/fs/xattr.c b/fs/xattr.c
68413 index c69e6d4..cc56af5 100644
68414 --- a/fs/xattr.c
68415 +++ b/fs/xattr.c
68416 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68417 return rc;
68418 }
68419
68420 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68421 +ssize_t
68422 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68423 +{
68424 + struct inode *inode = dentry->d_inode;
68425 + ssize_t error;
68426 +
68427 + error = inode_permission(inode, MAY_EXEC);
68428 + if (error)
68429 + return error;
68430 +
68431 + if (inode->i_op->getxattr)
68432 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68433 + else
68434 + error = -EOPNOTSUPP;
68435 +
68436 + return error;
68437 +}
68438 +EXPORT_SYMBOL(pax_getxattr);
68439 +#endif
68440 +
68441 ssize_t
68442 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68443 {
68444 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68445 * Extended attribute SET operations
68446 */
68447 static long
68448 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68449 +setxattr(struct path *path, const char __user *name, const void __user *value,
68450 size_t size, int flags)
68451 {
68452 int error;
68453 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68454 posix_acl_fix_xattr_from_user(kvalue, size);
68455 }
68456
68457 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68458 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68459 + error = -EACCES;
68460 + goto out;
68461 + }
68462 +
68463 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68464 out:
68465 if (vvalue)
68466 vfree(vvalue);
68467 @@ -377,7 +403,7 @@ retry:
68468 return error;
68469 error = mnt_want_write(path.mnt);
68470 if (!error) {
68471 - error = setxattr(path.dentry, name, value, size, flags);
68472 + error = setxattr(&path, name, value, size, flags);
68473 mnt_drop_write(path.mnt);
68474 }
68475 path_put(&path);
68476 @@ -401,7 +427,7 @@ retry:
68477 return error;
68478 error = mnt_want_write(path.mnt);
68479 if (!error) {
68480 - error = setxattr(path.dentry, name, value, size, flags);
68481 + error = setxattr(&path, name, value, size, flags);
68482 mnt_drop_write(path.mnt);
68483 }
68484 path_put(&path);
68485 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68486 const void __user *,value, size_t, size, int, flags)
68487 {
68488 struct fd f = fdget(fd);
68489 - struct dentry *dentry;
68490 int error = -EBADF;
68491
68492 if (!f.file)
68493 return error;
68494 - dentry = f.file->f_path.dentry;
68495 - audit_inode(NULL, dentry, 0);
68496 + audit_inode(NULL, f.file->f_path.dentry, 0);
68497 error = mnt_want_write_file(f.file);
68498 if (!error) {
68499 - error = setxattr(dentry, name, value, size, flags);
68500 + error = setxattr(&f.file->f_path, name, value, size, flags);
68501 mnt_drop_write_file(f.file);
68502 }
68503 fdput(f);
68504 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68505 * Extended attribute REMOVE operations
68506 */
68507 static long
68508 -removexattr(struct dentry *d, const char __user *name)
68509 +removexattr(struct path *path, const char __user *name)
68510 {
68511 int error;
68512 char kname[XATTR_NAME_MAX + 1];
68513 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68514 if (error < 0)
68515 return error;
68516
68517 - return vfs_removexattr(d, kname);
68518 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68519 + return -EACCES;
68520 +
68521 + return vfs_removexattr(path->dentry, kname);
68522 }
68523
68524 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68525 @@ -652,7 +679,7 @@ retry:
68526 return error;
68527 error = mnt_want_write(path.mnt);
68528 if (!error) {
68529 - error = removexattr(path.dentry, name);
68530 + error = removexattr(&path, name);
68531 mnt_drop_write(path.mnt);
68532 }
68533 path_put(&path);
68534 @@ -675,7 +702,7 @@ retry:
68535 return error;
68536 error = mnt_want_write(path.mnt);
68537 if (!error) {
68538 - error = removexattr(path.dentry, name);
68539 + error = removexattr(&path, name);
68540 mnt_drop_write(path.mnt);
68541 }
68542 path_put(&path);
68543 @@ -689,16 +716,16 @@ retry:
68544 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68545 {
68546 struct fd f = fdget(fd);
68547 - struct dentry *dentry;
68548 + struct path *path;
68549 int error = -EBADF;
68550
68551 if (!f.file)
68552 return error;
68553 - dentry = f.file->f_path.dentry;
68554 - audit_inode(NULL, dentry, 0);
68555 + path = &f.file->f_path;
68556 + audit_inode(NULL, path->dentry, 0);
68557 error = mnt_want_write_file(f.file);
68558 if (!error) {
68559 - error = removexattr(dentry, name);
68560 + error = removexattr(path, name);
68561 mnt_drop_write_file(f.file);
68562 }
68563 fdput(f);
68564 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68565 index 86df952..ac430d6 100644
68566 --- a/fs/xfs/libxfs/xfs_bmap.c
68567 +++ b/fs/xfs/libxfs/xfs_bmap.c
68568 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68569
68570 #else
68571 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68572 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68573 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68574 #endif /* DEBUG */
68575
68576 /*
68577 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68578 index f1b69ed..3d0222f 100644
68579 --- a/fs/xfs/xfs_dir2_readdir.c
68580 +++ b/fs/xfs/xfs_dir2_readdir.c
68581 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68582 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68583 filetype = dp->d_ops->sf_get_ftype(sfep);
68584 ctx->pos = off & 0x7fffffff;
68585 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68586 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68587 + char name[sfep->namelen];
68588 + memcpy(name, sfep->name, sfep->namelen);
68589 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68590 + return 0;
68591 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68592 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68593 return 0;
68594 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68595 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68596 index 3799695..0ddc953 100644
68597 --- a/fs/xfs/xfs_ioctl.c
68598 +++ b/fs/xfs/xfs_ioctl.c
68599 @@ -122,7 +122,7 @@ xfs_find_handle(
68600 }
68601
68602 error = -EFAULT;
68603 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68604 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68605 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68606 goto out_put;
68607
68608 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68609 index d10dc8f..56b3430 100644
68610 --- a/fs/xfs/xfs_linux.h
68611 +++ b/fs/xfs/xfs_linux.h
68612 @@ -230,7 +230,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68613 * of the compiler which do not like us using do_div in the middle
68614 * of large functions.
68615 */
68616 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68617 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68618 {
68619 __u32 mod;
68620
68621 @@ -286,7 +286,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68622 return 0;
68623 }
68624 #else
68625 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68626 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68627 {
68628 __u32 mod;
68629
68630 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68631 new file mode 100644
68632 index 0000000..f27264e
68633 --- /dev/null
68634 +++ b/grsecurity/Kconfig
68635 @@ -0,0 +1,1166 @@
68636 +#
68637 +# grecurity configuration
68638 +#
68639 +menu "Memory Protections"
68640 +depends on GRKERNSEC
68641 +
68642 +config GRKERNSEC_KMEM
68643 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68644 + default y if GRKERNSEC_CONFIG_AUTO
68645 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68646 + help
68647 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68648 + be written to or read from to modify or leak the contents of the running
68649 + kernel. /dev/port will also not be allowed to be opened, writing to
68650 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68651 + If you have module support disabled, enabling this will close up several
68652 + ways that are currently used to insert malicious code into the running
68653 + kernel.
68654 +
68655 + Even with this feature enabled, we still highly recommend that
68656 + you use the RBAC system, as it is still possible for an attacker to
68657 + modify the running kernel through other more obscure methods.
68658 +
68659 + It is highly recommended that you say Y here if you meet all the
68660 + conditions above.
68661 +
68662 +config GRKERNSEC_VM86
68663 + bool "Restrict VM86 mode"
68664 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68665 + depends on X86_32
68666 +
68667 + help
68668 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68669 + make use of a special execution mode on 32bit x86 processors called
68670 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68671 + video cards and will still work with this option enabled. The purpose
68672 + of the option is to prevent exploitation of emulation errors in
68673 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68674 + Nearly all users should be able to enable this option.
68675 +
68676 +config GRKERNSEC_IO
68677 + bool "Disable privileged I/O"
68678 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68679 + depends on X86
68680 + select RTC_CLASS
68681 + select RTC_INTF_DEV
68682 + select RTC_DRV_CMOS
68683 +
68684 + help
68685 + If you say Y here, all ioperm and iopl calls will return an error.
68686 + Ioperm and iopl can be used to modify the running kernel.
68687 + Unfortunately, some programs need this access to operate properly,
68688 + the most notable of which are XFree86 and hwclock. hwclock can be
68689 + remedied by having RTC support in the kernel, so real-time
68690 + clock support is enabled if this option is enabled, to ensure
68691 + that hwclock operates correctly. If hwclock still does not work,
68692 + either update udev or symlink /dev/rtc to /dev/rtc0.
68693 +
68694 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68695 + you may not be able to boot into a graphical environment with this
68696 + option enabled. In this case, you should use the RBAC system instead.
68697 +
68698 +config GRKERNSEC_BPF_HARDEN
68699 + bool "Harden BPF interpreter"
68700 + default y if GRKERNSEC_CONFIG_AUTO
68701 + help
68702 + Unlike previous versions of grsecurity that hardened both the BPF
68703 + interpreted code against corruption at rest as well as the JIT code
68704 + against JIT-spray attacks and attacker-controlled immediate values
68705 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68706 + and will ensure the interpreted code is read-only at rest. This feature
68707 + may be removed at a later time when eBPF stabilizes to entirely revert
68708 + back to the more secure pre-3.16 BPF interpreter/JIT.
68709 +
68710 + If you're using KERNEXEC, it's recommended that you enable this option
68711 + to supplement the hardening of the kernel.
68712 +
68713 +config GRKERNSEC_PERF_HARDEN
68714 + bool "Disable unprivileged PERF_EVENTS usage by default"
68715 + default y if GRKERNSEC_CONFIG_AUTO
68716 + depends on PERF_EVENTS
68717 + help
68718 + If you say Y here, the range of acceptable values for the
68719 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68720 + default to a new value: 3. When the sysctl is set to this value, no
68721 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68722 +
68723 + Though PERF_EVENTS can be used legitimately for performance monitoring
68724 + and low-level application profiling, it is forced on regardless of
68725 + configuration, has been at fault for several vulnerabilities, and
68726 + creates new opportunities for side channels and other information leaks.
68727 +
68728 + This feature puts PERF_EVENTS into a secure default state and permits
68729 + the administrator to change out of it temporarily if unprivileged
68730 + application profiling is needed.
68731 +
68732 +config GRKERNSEC_RAND_THREADSTACK
68733 + bool "Insert random gaps between thread stacks"
68734 + default y if GRKERNSEC_CONFIG_AUTO
68735 + depends on PAX_RANDMMAP && !PPC
68736 + help
68737 + If you say Y here, a random-sized gap will be enforced between allocated
68738 + thread stacks. Glibc's NPTL and other threading libraries that
68739 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68740 + The implementation currently provides 8 bits of entropy for the gap.
68741 +
68742 + Many distributions do not compile threaded remote services with the
68743 + -fstack-check argument to GCC, causing the variable-sized stack-based
68744 + allocator, alloca(), to not probe the stack on allocation. This
68745 + permits an unbounded alloca() to skip over any guard page and potentially
68746 + modify another thread's stack reliably. An enforced random gap
68747 + reduces the reliability of such an attack and increases the chance
68748 + that such a read/write to another thread's stack instead lands in
68749 + an unmapped area, causing a crash and triggering grsecurity's
68750 + anti-bruteforcing logic.
68751 +
68752 +config GRKERNSEC_PROC_MEMMAP
68753 + bool "Harden ASLR against information leaks and entropy reduction"
68754 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68755 + depends on PAX_NOEXEC || PAX_ASLR
68756 + help
68757 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68758 + give no information about the addresses of its mappings if
68759 + PaX features that rely on random addresses are enabled on the task.
68760 + In addition to sanitizing this information and disabling other
68761 + dangerous sources of information, this option causes reads of sensitive
68762 + /proc/<pid> entries where the file descriptor was opened in a different
68763 + task than the one performing the read. Such attempts are logged.
68764 + This option also limits argv/env strings for suid/sgid binaries
68765 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68766 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68767 + binaries to prevent alternative mmap layouts from being abused.
68768 +
68769 + If you use PaX it is essential that you say Y here as it closes up
68770 + several holes that make full ASLR useless locally.
68771 +
68772 +
68773 +config GRKERNSEC_KSTACKOVERFLOW
68774 + bool "Prevent kernel stack overflows"
68775 + default y if GRKERNSEC_CONFIG_AUTO
68776 + depends on !IA64 && 64BIT
68777 + help
68778 + If you say Y here, the kernel's process stacks will be allocated
68779 + with vmalloc instead of the kernel's default allocator. This
68780 + introduces guard pages that in combination with the alloca checking
68781 + of the STACKLEAK feature prevents all forms of kernel process stack
68782 + overflow abuse. Note that this is different from kernel stack
68783 + buffer overflows.
68784 +
68785 +config GRKERNSEC_BRUTE
68786 + bool "Deter exploit bruteforcing"
68787 + default y if GRKERNSEC_CONFIG_AUTO
68788 + help
68789 + If you say Y here, attempts to bruteforce exploits against forking
68790 + daemons such as apache or sshd, as well as against suid/sgid binaries
68791 + will be deterred. When a child of a forking daemon is killed by PaX
68792 + or crashes due to an illegal instruction or other suspicious signal,
68793 + the parent process will be delayed 30 seconds upon every subsequent
68794 + fork until the administrator is able to assess the situation and
68795 + restart the daemon.
68796 + In the suid/sgid case, the attempt is logged, the user has all their
68797 + existing instances of the suid/sgid binary terminated and will
68798 + be unable to execute any suid/sgid binaries for 15 minutes.
68799 +
68800 + It is recommended that you also enable signal logging in the auditing
68801 + section so that logs are generated when a process triggers a suspicious
68802 + signal.
68803 + If the sysctl option is enabled, a sysctl option with name
68804 + "deter_bruteforce" is created.
68805 +
68806 +config GRKERNSEC_MODHARDEN
68807 + bool "Harden module auto-loading"
68808 + default y if GRKERNSEC_CONFIG_AUTO
68809 + depends on MODULES
68810 + help
68811 + If you say Y here, module auto-loading in response to use of some
68812 + feature implemented by an unloaded module will be restricted to
68813 + root users. Enabling this option helps defend against attacks
68814 + by unprivileged users who abuse the auto-loading behavior to
68815 + cause a vulnerable module to load that is then exploited.
68816 +
68817 + If this option prevents a legitimate use of auto-loading for a
68818 + non-root user, the administrator can execute modprobe manually
68819 + with the exact name of the module mentioned in the alert log.
68820 + Alternatively, the administrator can add the module to the list
68821 + of modules loaded at boot by modifying init scripts.
68822 +
68823 + Modification of init scripts will most likely be needed on
68824 + Ubuntu servers with encrypted home directory support enabled,
68825 + as the first non-root user logging in will cause the ecb(aes),
68826 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68827 +
68828 +config GRKERNSEC_HIDESYM
68829 + bool "Hide kernel symbols"
68830 + default y if GRKERNSEC_CONFIG_AUTO
68831 + select PAX_USERCOPY_SLABS
68832 + help
68833 + If you say Y here, getting information on loaded modules, and
68834 + displaying all kernel symbols through a syscall will be restricted
68835 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68836 + /proc/kallsyms will be restricted to the root user. The RBAC
68837 + system can hide that entry even from root.
68838 +
68839 + This option also prevents leaking of kernel addresses through
68840 + several /proc entries.
68841 +
68842 + Note that this option is only effective provided the following
68843 + conditions are met:
68844 + 1) The kernel using grsecurity is not precompiled by some distribution
68845 + 2) You have also enabled GRKERNSEC_DMESG
68846 + 3) You are using the RBAC system and hiding other files such as your
68847 + kernel image and System.map. Alternatively, enabling this option
68848 + causes the permissions on /boot, /lib/modules, and the kernel
68849 + source directory to change at compile time to prevent
68850 + reading by non-root users.
68851 + If the above conditions are met, this option will aid in providing a
68852 + useful protection against local kernel exploitation of overflows
68853 + and arbitrary read/write vulnerabilities.
68854 +
68855 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68856 + in addition to this feature.
68857 +
68858 +config GRKERNSEC_RANDSTRUCT
68859 + bool "Randomize layout of sensitive kernel structures"
68860 + default y if GRKERNSEC_CONFIG_AUTO
68861 + select GRKERNSEC_HIDESYM
68862 + select MODVERSIONS if MODULES
68863 + help
68864 + If you say Y here, the layouts of a number of sensitive kernel
68865 + structures (task, fs, cred, etc) and all structures composed entirely
68866 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68867 + This can introduce the requirement of an additional infoleak
68868 + vulnerability for exploits targeting these structure types.
68869 +
68870 + Enabling this feature will introduce some performance impact, slightly
68871 + increase memory usage, and prevent the use of forensic tools like
68872 + Volatility against the system (unless the kernel source tree isn't
68873 + cleaned after kernel installation).
68874 +
68875 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68876 + It remains after a make clean to allow for external modules to be compiled
68877 + with the existing seed and will be removed by a make mrproper or
68878 + make distclean.
68879 +
68880 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68881 + to install the supporting headers explicitly in addition to the normal
68882 + gcc package.
68883 +
68884 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68885 + bool "Use cacheline-aware structure randomization"
68886 + depends on GRKERNSEC_RANDSTRUCT
68887 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68888 + help
68889 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68890 + at restricting randomization to cacheline-sized groups of elements. It
68891 + will further not randomize bitfields in structures. This reduces the
68892 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68893 +
68894 +config GRKERNSEC_KERN_LOCKOUT
68895 + bool "Active kernel exploit response"
68896 + default y if GRKERNSEC_CONFIG_AUTO
68897 + depends on X86 || ARM || PPC || SPARC
68898 + help
68899 + If you say Y here, when a PaX alert is triggered due to suspicious
68900 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68901 + or an OOPS occurs due to bad memory accesses, instead of just
68902 + terminating the offending process (and potentially allowing
68903 + a subsequent exploit from the same user), we will take one of two
68904 + actions:
68905 + If the user was root, we will panic the system
68906 + If the user was non-root, we will log the attempt, terminate
68907 + all processes owned by the user, then prevent them from creating
68908 + any new processes until the system is restarted
68909 + This deters repeated kernel exploitation/bruteforcing attempts
68910 + and is useful for later forensics.
68911 +
68912 +config GRKERNSEC_OLD_ARM_USERLAND
68913 + bool "Old ARM userland compatibility"
68914 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68915 + help
68916 + If you say Y here, stubs of executable code to perform such operations
68917 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68918 + table. This is unfortunately needed for old ARM userland meant to run
68919 + across a wide range of processors. Without this option enabled,
68920 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68921 + which is enough for Linaro userlands or other userlands designed for v6
68922 + and newer ARM CPUs. It's recommended that you try without this option enabled
68923 + first, and only enable it if your userland does not boot (it will likely fail
68924 + at init time).
68925 +
68926 +endmenu
68927 +menu "Role Based Access Control Options"
68928 +depends on GRKERNSEC
68929 +
68930 +config GRKERNSEC_RBAC_DEBUG
68931 + bool
68932 +
68933 +config GRKERNSEC_NO_RBAC
68934 + bool "Disable RBAC system"
68935 + help
68936 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68937 + preventing the RBAC system from being enabled. You should only say Y
68938 + here if you have no intention of using the RBAC system, so as to prevent
68939 + an attacker with root access from misusing the RBAC system to hide files
68940 + and processes when loadable module support and /dev/[k]mem have been
68941 + locked down.
68942 +
68943 +config GRKERNSEC_ACL_HIDEKERN
68944 + bool "Hide kernel processes"
68945 + help
68946 + If you say Y here, all kernel threads will be hidden to all
68947 + processes but those whose subject has the "view hidden processes"
68948 + flag.
68949 +
68950 +config GRKERNSEC_ACL_MAXTRIES
68951 + int "Maximum tries before password lockout"
68952 + default 3
68953 + help
68954 + This option enforces the maximum number of times a user can attempt
68955 + to authorize themselves with the grsecurity RBAC system before being
68956 + denied the ability to attempt authorization again for a specified time.
68957 + The lower the number, the harder it will be to brute-force a password.
68958 +
68959 +config GRKERNSEC_ACL_TIMEOUT
68960 + int "Time to wait after max password tries, in seconds"
68961 + default 30
68962 + help
68963 + This option specifies the time the user must wait after attempting to
68964 + authorize to the RBAC system with the maximum number of invalid
68965 + passwords. The higher the number, the harder it will be to brute-force
68966 + a password.
68967 +
68968 +endmenu
68969 +menu "Filesystem Protections"
68970 +depends on GRKERNSEC
68971 +
68972 +config GRKERNSEC_PROC
68973 + bool "Proc restrictions"
68974 + default y if GRKERNSEC_CONFIG_AUTO
68975 + help
68976 + If you say Y here, the permissions of the /proc filesystem
68977 + will be altered to enhance system security and privacy. You MUST
68978 + choose either a user only restriction or a user and group restriction.
68979 + Depending upon the option you choose, you can either restrict users to
68980 + see only the processes they themselves run, or choose a group that can
68981 + view all processes and files normally restricted to root if you choose
68982 + the "restrict to user only" option. NOTE: If you're running identd or
68983 + ntpd as a non-root user, you will have to run it as the group you
68984 + specify here.
68985 +
68986 +config GRKERNSEC_PROC_USER
68987 + bool "Restrict /proc to user only"
68988 + depends on GRKERNSEC_PROC
68989 + help
68990 + If you say Y here, non-root users will only be able to view their own
68991 + processes, and restricts them from viewing network-related information,
68992 + and viewing kernel symbol and module information.
68993 +
68994 +config GRKERNSEC_PROC_USERGROUP
68995 + bool "Allow special group"
68996 + default y if GRKERNSEC_CONFIG_AUTO
68997 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68998 + help
68999 + If you say Y here, you will be able to select a group that will be
69000 + able to view all processes and network-related information. If you've
69001 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
69002 + remain hidden. This option is useful if you want to run identd as
69003 + a non-root user. The group you select may also be chosen at boot time
69004 + via "grsec_proc_gid=" on the kernel commandline.
69005 +
69006 +config GRKERNSEC_PROC_GID
69007 + int "GID for special group"
69008 + depends on GRKERNSEC_PROC_USERGROUP
69009 + default 1001
69010 +
69011 +config GRKERNSEC_PROC_ADD
69012 + bool "Additional restrictions"
69013 + default y if GRKERNSEC_CONFIG_AUTO
69014 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
69015 + help
69016 + If you say Y here, additional restrictions will be placed on
69017 + /proc that keep normal users from viewing device information and
69018 + slabinfo information that could be useful for exploits.
69019 +
69020 +config GRKERNSEC_LINK
69021 + bool "Linking restrictions"
69022 + default y if GRKERNSEC_CONFIG_AUTO
69023 + help
69024 + If you say Y here, /tmp race exploits will be prevented, since users
69025 + will no longer be able to follow symlinks owned by other users in
69026 + world-writable +t directories (e.g. /tmp), unless the owner of the
69027 + symlink is the owner of the directory. users will also not be
69028 + able to hardlink to files they do not own. If the sysctl option is
69029 + enabled, a sysctl option with name "linking_restrictions" is created.
69030 +
69031 +config GRKERNSEC_SYMLINKOWN
69032 + bool "Kernel-enforced SymlinksIfOwnerMatch"
69033 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69034 + help
69035 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
69036 + that prevents it from being used as a security feature. As Apache
69037 + verifies the symlink by performing a stat() against the target of
69038 + the symlink before it is followed, an attacker can setup a symlink
69039 + to point to a same-owned file, then replace the symlink with one
69040 + that targets another user's file just after Apache "validates" the
69041 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
69042 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
69043 + will be in place for the group you specify. If the sysctl option
69044 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
69045 + created.
69046 +
69047 +config GRKERNSEC_SYMLINKOWN_GID
69048 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
69049 + depends on GRKERNSEC_SYMLINKOWN
69050 + default 1006
69051 + help
69052 + Setting this GID determines what group kernel-enforced
69053 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
69054 + is enabled, a sysctl option with name "symlinkown_gid" is created.
69055 +
69056 +config GRKERNSEC_FIFO
69057 + bool "FIFO restrictions"
69058 + default y if GRKERNSEC_CONFIG_AUTO
69059 + help
69060 + If you say Y here, users will not be able to write to FIFOs they don't
69061 + own in world-writable +t directories (e.g. /tmp), unless the owner of
69062 + the FIFO is the same owner of the directory it's held in. If the sysctl
69063 + option is enabled, a sysctl option with name "fifo_restrictions" is
69064 + created.
69065 +
69066 +config GRKERNSEC_SYSFS_RESTRICT
69067 + bool "Sysfs/debugfs restriction"
69068 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69069 + depends on SYSFS
69070 + help
69071 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
69072 + any filesystem normally mounted under it (e.g. debugfs) will be
69073 + mostly accessible only by root. These filesystems generally provide access
69074 + to hardware and debug information that isn't appropriate for unprivileged
69075 + users of the system. Sysfs and debugfs have also become a large source
69076 + of new vulnerabilities, ranging from infoleaks to local compromise.
69077 + There has been very little oversight with an eye toward security involved
69078 + in adding new exporters of information to these filesystems, so their
69079 + use is discouraged.
69080 + For reasons of compatibility, a few directories have been whitelisted
69081 + for access by non-root users:
69082 + /sys/fs/selinux
69083 + /sys/fs/fuse
69084 + /sys/devices/system/cpu
69085 +
69086 +config GRKERNSEC_ROFS
69087 + bool "Runtime read-only mount protection"
69088 + depends on SYSCTL
69089 + help
69090 + If you say Y here, a sysctl option with name "romount_protect" will
69091 + be created. By setting this option to 1 at runtime, filesystems
69092 + will be protected in the following ways:
69093 + * No new writable mounts will be allowed
69094 + * Existing read-only mounts won't be able to be remounted read/write
69095 + * Write operations will be denied on all block devices
69096 + This option acts independently of grsec_lock: once it is set to 1,
69097 + it cannot be turned off. Therefore, please be mindful of the resulting
69098 + behavior if this option is enabled in an init script on a read-only
69099 + filesystem.
69100 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
69101 + and GRKERNSEC_IO should be enabled and module loading disabled via
69102 + config or at runtime.
69103 + This feature is mainly intended for secure embedded systems.
69104 +
69105 +
69106 +config GRKERNSEC_DEVICE_SIDECHANNEL
69107 + bool "Eliminate stat/notify-based device sidechannels"
69108 + default y if GRKERNSEC_CONFIG_AUTO
69109 + help
69110 + If you say Y here, timing analyses on block or character
69111 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
69112 + will be thwarted for unprivileged users. If a process without
69113 + CAP_MKNOD stats such a device, the last access and last modify times
69114 + will match the device's create time. No access or modify events
69115 + will be triggered through inotify/dnotify/fanotify for such devices.
69116 + This feature will prevent attacks that may at a minimum
69117 + allow an attacker to determine the administrator's password length.
69118 +
69119 +config GRKERNSEC_CHROOT
69120 + bool "Chroot jail restrictions"
69121 + default y if GRKERNSEC_CONFIG_AUTO
69122 + help
69123 + If you say Y here, you will be able to choose several options that will
69124 + make breaking out of a chrooted jail much more difficult. If you
69125 + encounter no software incompatibilities with the following options, it
69126 + is recommended that you enable each one.
69127 +
69128 + Note that the chroot restrictions are not intended to apply to "chroots"
69129 + to directories that are simple bind mounts of the global root filesystem.
69130 + For several other reasons, a user shouldn't expect any significant
69131 + security by performing such a chroot.
69132 +
69133 +config GRKERNSEC_CHROOT_MOUNT
69134 + bool "Deny mounts"
69135 + default y if GRKERNSEC_CONFIG_AUTO
69136 + depends on GRKERNSEC_CHROOT
69137 + help
69138 + If you say Y here, processes inside a chroot will not be able to
69139 + mount or remount filesystems. If the sysctl option is enabled, a
69140 + sysctl option with name "chroot_deny_mount" is created.
69141 +
69142 +config GRKERNSEC_CHROOT_DOUBLE
69143 + bool "Deny double-chroots"
69144 + default y if GRKERNSEC_CONFIG_AUTO
69145 + depends on GRKERNSEC_CHROOT
69146 + help
69147 + If you say Y here, processes inside a chroot will not be able to chroot
69148 + again outside the chroot. This is a widely used method of breaking
69149 + out of a chroot jail and should not be allowed. If the sysctl
69150 + option is enabled, a sysctl option with name
69151 + "chroot_deny_chroot" is created.
69152 +
69153 +config GRKERNSEC_CHROOT_PIVOT
69154 + bool "Deny pivot_root in chroot"
69155 + default y if GRKERNSEC_CONFIG_AUTO
69156 + depends on GRKERNSEC_CHROOT
69157 + help
69158 + If you say Y here, processes inside a chroot will not be able to use
69159 + a function called pivot_root() that was introduced in Linux 2.3.41. It
69160 + works similar to chroot in that it changes the root filesystem. This
69161 + function could be misused in a chrooted process to attempt to break out
69162 + of the chroot, and therefore should not be allowed. If the sysctl
69163 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
69164 + created.
69165 +
69166 +config GRKERNSEC_CHROOT_CHDIR
69167 + bool "Enforce chdir(\"/\") on all chroots"
69168 + default y if GRKERNSEC_CONFIG_AUTO
69169 + depends on GRKERNSEC_CHROOT
69170 + help
69171 + If you say Y here, the current working directory of all newly-chrooted
69172 + applications will be set to the the root directory of the chroot.
69173 + The man page on chroot(2) states:
69174 + Note that this call does not change the current working
69175 + directory, so that `.' can be outside the tree rooted at
69176 + `/'. In particular, the super-user can escape from a
69177 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69178 +
69179 + It is recommended that you say Y here, since it's not known to break
69180 + any software. If the sysctl option is enabled, a sysctl option with
69181 + name "chroot_enforce_chdir" is created.
69182 +
69183 +config GRKERNSEC_CHROOT_CHMOD
69184 + bool "Deny (f)chmod +s"
69185 + default y if GRKERNSEC_CONFIG_AUTO
69186 + depends on GRKERNSEC_CHROOT
69187 + help
69188 + If you say Y here, processes inside a chroot will not be able to chmod
69189 + or fchmod files to make them have suid or sgid bits. This protects
69190 + against another published method of breaking a chroot. If the sysctl
69191 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
69192 + created.
69193 +
69194 +config GRKERNSEC_CHROOT_FCHDIR
69195 + bool "Deny fchdir and fhandle out of chroot"
69196 + default y if GRKERNSEC_CONFIG_AUTO
69197 + depends on GRKERNSEC_CHROOT
69198 + help
69199 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
69200 + to a file descriptor of the chrooting process that points to a directory
69201 + outside the filesystem will be stopped. Additionally, this option prevents
69202 + use of the recently-created syscall for opening files by a guessable "file
69203 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69204 + with name "chroot_deny_fchdir" is created.
69205 +
69206 +config GRKERNSEC_CHROOT_MKNOD
69207 + bool "Deny mknod"
69208 + default y if GRKERNSEC_CONFIG_AUTO
69209 + depends on GRKERNSEC_CHROOT
69210 + help
69211 + If you say Y here, processes inside a chroot will not be allowed to
69212 + mknod. The problem with using mknod inside a chroot is that it
69213 + would allow an attacker to create a device entry that is the same
69214 + as one on the physical root of your system, which could range from
69215 + anything from the console device to a device for your harddrive (which
69216 + they could then use to wipe the drive or steal data). It is recommended
69217 + that you say Y here, unless you run into software incompatibilities.
69218 + If the sysctl option is enabled, a sysctl option with name
69219 + "chroot_deny_mknod" is created.
69220 +
69221 +config GRKERNSEC_CHROOT_SHMAT
69222 + bool "Deny shmat() out of chroot"
69223 + default y if GRKERNSEC_CONFIG_AUTO
69224 + depends on GRKERNSEC_CHROOT
69225 + help
69226 + If you say Y here, processes inside a chroot will not be able to attach
69227 + to shared memory segments that were created outside of the chroot jail.
69228 + It is recommended that you say Y here. If the sysctl option is enabled,
69229 + a sysctl option with name "chroot_deny_shmat" is created.
69230 +
69231 +config GRKERNSEC_CHROOT_UNIX
69232 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
69233 + default y if GRKERNSEC_CONFIG_AUTO
69234 + depends on GRKERNSEC_CHROOT
69235 + help
69236 + If you say Y here, processes inside a chroot will not be able to
69237 + connect to abstract (meaning not belonging to a filesystem) Unix
69238 + domain sockets that were bound outside of a chroot. It is recommended
69239 + that you say Y here. If the sysctl option is enabled, a sysctl option
69240 + with name "chroot_deny_unix" is created.
69241 +
69242 +config GRKERNSEC_CHROOT_FINDTASK
69243 + bool "Protect outside processes"
69244 + default y if GRKERNSEC_CONFIG_AUTO
69245 + depends on GRKERNSEC_CHROOT
69246 + help
69247 + If you say Y here, processes inside a chroot will not be able to
69248 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69249 + getsid, or view any process outside of the chroot. If the sysctl
69250 + option is enabled, a sysctl option with name "chroot_findtask" is
69251 + created.
69252 +
69253 +config GRKERNSEC_CHROOT_NICE
69254 + bool "Restrict priority changes"
69255 + default y if GRKERNSEC_CONFIG_AUTO
69256 + depends on GRKERNSEC_CHROOT
69257 + help
69258 + If you say Y here, processes inside a chroot will not be able to raise
69259 + the priority of processes in the chroot, or alter the priority of
69260 + processes outside the chroot. This provides more security than simply
69261 + removing CAP_SYS_NICE from the process' capability set. If the
69262 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69263 + is created.
69264 +
69265 +config GRKERNSEC_CHROOT_SYSCTL
69266 + bool "Deny sysctl writes"
69267 + default y if GRKERNSEC_CONFIG_AUTO
69268 + depends on GRKERNSEC_CHROOT
69269 + help
69270 + If you say Y here, an attacker in a chroot will not be able to
69271 + write to sysctl entries, either by sysctl(2) or through a /proc
69272 + interface. It is strongly recommended that you say Y here. If the
69273 + sysctl option is enabled, a sysctl option with name
69274 + "chroot_deny_sysctl" is created.
69275 +
69276 +config GRKERNSEC_CHROOT_CAPS
69277 + bool "Capability restrictions"
69278 + default y if GRKERNSEC_CONFIG_AUTO
69279 + depends on GRKERNSEC_CHROOT
69280 + help
69281 + If you say Y here, the capabilities on all processes within a
69282 + chroot jail will be lowered to stop module insertion, raw i/o,
69283 + system and net admin tasks, rebooting the system, modifying immutable
69284 + files, modifying IPC owned by another, and changing the system time.
69285 + This is left an option because it can break some apps. Disable this
69286 + if your chrooted apps are having problems performing those kinds of
69287 + tasks. If the sysctl option is enabled, a sysctl option with
69288 + name "chroot_caps" is created.
69289 +
69290 +config GRKERNSEC_CHROOT_INITRD
69291 + bool "Exempt initrd tasks from restrictions"
69292 + default y if GRKERNSEC_CONFIG_AUTO
69293 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69294 + help
69295 + If you say Y here, tasks started prior to init will be exempted from
69296 + grsecurity's chroot restrictions. This option is mainly meant to
69297 + resolve Plymouth's performing privileged operations unnecessarily
69298 + in a chroot.
69299 +
69300 +endmenu
69301 +menu "Kernel Auditing"
69302 +depends on GRKERNSEC
69303 +
69304 +config GRKERNSEC_AUDIT_GROUP
69305 + bool "Single group for auditing"
69306 + help
69307 + If you say Y here, the exec and chdir logging features will only operate
69308 + on a group you specify. This option is recommended if you only want to
69309 + watch certain users instead of having a large amount of logs from the
69310 + entire system. If the sysctl option is enabled, a sysctl option with
69311 + name "audit_group" is created.
69312 +
69313 +config GRKERNSEC_AUDIT_GID
69314 + int "GID for auditing"
69315 + depends on GRKERNSEC_AUDIT_GROUP
69316 + default 1007
69317 +
69318 +config GRKERNSEC_EXECLOG
69319 + bool "Exec logging"
69320 + help
69321 + If you say Y here, all execve() calls will be logged (since the
69322 + other exec*() calls are frontends to execve(), all execution
69323 + will be logged). Useful for shell-servers that like to keep track
69324 + of their users. If the sysctl option is enabled, a sysctl option with
69325 + name "exec_logging" is created.
69326 + WARNING: This option when enabled will produce a LOT of logs, especially
69327 + on an active system.
69328 +
69329 +config GRKERNSEC_RESLOG
69330 + bool "Resource logging"
69331 + default y if GRKERNSEC_CONFIG_AUTO
69332 + help
69333 + If you say Y here, all attempts to overstep resource limits will
69334 + be logged with the resource name, the requested size, and the current
69335 + limit. It is highly recommended that you say Y here. If the sysctl
69336 + option is enabled, a sysctl option with name "resource_logging" is
69337 + created. If the RBAC system is enabled, the sysctl value is ignored.
69338 +
69339 +config GRKERNSEC_CHROOT_EXECLOG
69340 + bool "Log execs within chroot"
69341 + help
69342 + If you say Y here, all executions inside a chroot jail will be logged
69343 + to syslog. This can cause a large amount of logs if certain
69344 + applications (eg. djb's daemontools) are installed on the system, and
69345 + is therefore left as an option. If the sysctl option is enabled, a
69346 + sysctl option with name "chroot_execlog" is created.
69347 +
69348 +config GRKERNSEC_AUDIT_PTRACE
69349 + bool "Ptrace logging"
69350 + help
69351 + If you say Y here, all attempts to attach to a process via ptrace
69352 + will be logged. If the sysctl option is enabled, a sysctl option
69353 + with name "audit_ptrace" is created.
69354 +
69355 +config GRKERNSEC_AUDIT_CHDIR
69356 + bool "Chdir logging"
69357 + help
69358 + If you say Y here, all chdir() calls will be logged. If the sysctl
69359 + option is enabled, a sysctl option with name "audit_chdir" is created.
69360 +
69361 +config GRKERNSEC_AUDIT_MOUNT
69362 + bool "(Un)Mount logging"
69363 + help
69364 + If you say Y here, all mounts and unmounts will be logged. If the
69365 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69366 + created.
69367 +
69368 +config GRKERNSEC_SIGNAL
69369 + bool "Signal logging"
69370 + default y if GRKERNSEC_CONFIG_AUTO
69371 + help
69372 + If you say Y here, certain important signals will be logged, such as
69373 + SIGSEGV, which will as a result inform you of when a error in a program
69374 + occurred, which in some cases could mean a possible exploit attempt.
69375 + If the sysctl option is enabled, a sysctl option with name
69376 + "signal_logging" is created.
69377 +
69378 +config GRKERNSEC_FORKFAIL
69379 + bool "Fork failure logging"
69380 + help
69381 + If you say Y here, all failed fork() attempts will be logged.
69382 + This could suggest a fork bomb, or someone attempting to overstep
69383 + their process limit. If the sysctl option is enabled, a sysctl option
69384 + with name "forkfail_logging" is created.
69385 +
69386 +config GRKERNSEC_TIME
69387 + bool "Time change logging"
69388 + default y if GRKERNSEC_CONFIG_AUTO
69389 + help
69390 + If you say Y here, any changes of the system clock will be logged.
69391 + If the sysctl option is enabled, a sysctl option with name
69392 + "timechange_logging" is created.
69393 +
69394 +config GRKERNSEC_PROC_IPADDR
69395 + bool "/proc/<pid>/ipaddr support"
69396 + default y if GRKERNSEC_CONFIG_AUTO
69397 + help
69398 + If you say Y here, a new entry will be added to each /proc/<pid>
69399 + directory that contains the IP address of the person using the task.
69400 + The IP is carried across local TCP and AF_UNIX stream sockets.
69401 + This information can be useful for IDS/IPSes to perform remote response
69402 + to a local attack. The entry is readable by only the owner of the
69403 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69404 + the RBAC system), and thus does not create privacy concerns.
69405 +
69406 +config GRKERNSEC_RWXMAP_LOG
69407 + bool 'Denied RWX mmap/mprotect logging'
69408 + default y if GRKERNSEC_CONFIG_AUTO
69409 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69410 + help
69411 + If you say Y here, calls to mmap() and mprotect() with explicit
69412 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69413 + denied by the PAX_MPROTECT feature. This feature will also
69414 + log other problematic scenarios that can occur when PAX_MPROTECT
69415 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69416 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69417 + is created.
69418 +
69419 +endmenu
69420 +
69421 +menu "Executable Protections"
69422 +depends on GRKERNSEC
69423 +
69424 +config GRKERNSEC_DMESG
69425 + bool "Dmesg(8) restriction"
69426 + default y if GRKERNSEC_CONFIG_AUTO
69427 + help
69428 + If you say Y here, non-root users will not be able to use dmesg(8)
69429 + to view the contents of the kernel's circular log buffer.
69430 + The kernel's log buffer often contains kernel addresses and other
69431 + identifying information useful to an attacker in fingerprinting a
69432 + system for a targeted exploit.
69433 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69434 + created.
69435 +
69436 +config GRKERNSEC_HARDEN_PTRACE
69437 + bool "Deter ptrace-based process snooping"
69438 + default y if GRKERNSEC_CONFIG_AUTO
69439 + help
69440 + If you say Y here, TTY sniffers and other malicious monitoring
69441 + programs implemented through ptrace will be defeated. If you
69442 + have been using the RBAC system, this option has already been
69443 + enabled for several years for all users, with the ability to make
69444 + fine-grained exceptions.
69445 +
69446 + This option only affects the ability of non-root users to ptrace
69447 + processes that are not a descendent of the ptracing process.
69448 + This means that strace ./binary and gdb ./binary will still work,
69449 + but attaching to arbitrary processes will not. If the sysctl
69450 + option is enabled, a sysctl option with name "harden_ptrace" is
69451 + created.
69452 +
69453 +config GRKERNSEC_PTRACE_READEXEC
69454 + bool "Require read access to ptrace sensitive binaries"
69455 + default y if GRKERNSEC_CONFIG_AUTO
69456 + help
69457 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69458 + binaries. This option is useful in environments that
69459 + remove the read bits (e.g. file mode 4711) from suid binaries to
69460 + prevent infoleaking of their contents. This option adds
69461 + consistency to the use of that file mode, as the binary could normally
69462 + be read out when run without privileges while ptracing.
69463 +
69464 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69465 + is created.
69466 +
69467 +config GRKERNSEC_SETXID
69468 + bool "Enforce consistent multithreaded privileges"
69469 + default y if GRKERNSEC_CONFIG_AUTO
69470 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69471 + help
69472 + If you say Y here, a change from a root uid to a non-root uid
69473 + in a multithreaded application will cause the resulting uids,
69474 + gids, supplementary groups, and capabilities in that thread
69475 + to be propagated to the other threads of the process. In most
69476 + cases this is unnecessary, as glibc will emulate this behavior
69477 + on behalf of the application. Other libcs do not act in the
69478 + same way, allowing the other threads of the process to continue
69479 + running with root privileges. If the sysctl option is enabled,
69480 + a sysctl option with name "consistent_setxid" is created.
69481 +
69482 +config GRKERNSEC_HARDEN_IPC
69483 + bool "Disallow access to overly-permissive IPC objects"
69484 + default y if GRKERNSEC_CONFIG_AUTO
69485 + depends on SYSVIPC
69486 + help
69487 + If you say Y here, access to overly-permissive IPC objects (shared
69488 + memory, message queues, and semaphores) will be denied for processes
69489 + given the following criteria beyond normal permission checks:
69490 + 1) If the IPC object is world-accessible and the euid doesn't match
69491 + that of the creator or current uid for the IPC object
69492 + 2) If the IPC object is group-accessible and the egid doesn't
69493 + match that of the creator or current gid for the IPC object
69494 + It's a common error to grant too much permission to these objects,
69495 + with impact ranging from denial of service and information leaking to
69496 + privilege escalation. This feature was developed in response to
69497 + research by Tim Brown:
69498 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69499 + who found hundreds of such insecure usages. Processes with
69500 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69501 + If the sysctl option is enabled, a sysctl option with name
69502 + "harden_ipc" is created.
69503 +
69504 +config GRKERNSEC_TPE
69505 + bool "Trusted Path Execution (TPE)"
69506 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69507 + help
69508 + If you say Y here, you will be able to choose a gid to add to the
69509 + supplementary groups of users you want to mark as "untrusted."
69510 + These users will not be able to execute any files that are not in
69511 + root-owned directories writable only by root. If the sysctl option
69512 + is enabled, a sysctl option with name "tpe" is created.
69513 +
69514 +config GRKERNSEC_TPE_ALL
69515 + bool "Partially restrict all non-root users"
69516 + depends on GRKERNSEC_TPE
69517 + help
69518 + If you say Y here, all non-root users will be covered under
69519 + a weaker TPE restriction. This is separate from, and in addition to,
69520 + the main TPE options that you have selected elsewhere. Thus, if a
69521 + "trusted" GID is chosen, this restriction applies to even that GID.
69522 + Under this restriction, all non-root users will only be allowed to
69523 + execute files in directories they own that are not group or
69524 + world-writable, or in directories owned by root and writable only by
69525 + root. If the sysctl option is enabled, a sysctl option with name
69526 + "tpe_restrict_all" is created.
69527 +
69528 +config GRKERNSEC_TPE_INVERT
69529 + bool "Invert GID option"
69530 + depends on GRKERNSEC_TPE
69531 + help
69532 + If you say Y here, the group you specify in the TPE configuration will
69533 + decide what group TPE restrictions will be *disabled* for. This
69534 + option is useful if you want TPE restrictions to be applied to most
69535 + users on the system. If the sysctl option is enabled, a sysctl option
69536 + with name "tpe_invert" is created. Unlike other sysctl options, this
69537 + entry will default to on for backward-compatibility.
69538 +
69539 +config GRKERNSEC_TPE_GID
69540 + int
69541 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69542 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69543 +
69544 +config GRKERNSEC_TPE_UNTRUSTED_GID
69545 + int "GID for TPE-untrusted users"
69546 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69547 + default 1005
69548 + help
69549 + Setting this GID determines what group TPE restrictions will be
69550 + *enabled* for. If the sysctl option is enabled, a sysctl option
69551 + with name "tpe_gid" is created.
69552 +
69553 +config GRKERNSEC_TPE_TRUSTED_GID
69554 + int "GID for TPE-trusted users"
69555 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69556 + default 1005
69557 + help
69558 + Setting this GID determines what group TPE restrictions will be
69559 + *disabled* for. If the sysctl option is enabled, a sysctl option
69560 + with name "tpe_gid" is created.
69561 +
69562 +endmenu
69563 +menu "Network Protections"
69564 +depends on GRKERNSEC
69565 +
69566 +config GRKERNSEC_BLACKHOLE
69567 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69568 + default y if GRKERNSEC_CONFIG_AUTO
69569 + depends on NET
69570 + help
69571 + If you say Y here, neither TCP resets nor ICMP
69572 + destination-unreachable packets will be sent in response to packets
69573 + sent to ports for which no associated listening process exists.
69574 + It will also prevent the sending of ICMP protocol unreachable packets
69575 + in response to packets with unknown protocols.
69576 + This feature supports both IPV4 and IPV6 and exempts the
69577 + loopback interface from blackholing. Enabling this feature
69578 + makes a host more resilient to DoS attacks and reduces network
69579 + visibility against scanners.
69580 +
69581 + The blackhole feature as-implemented is equivalent to the FreeBSD
69582 + blackhole feature, as it prevents RST responses to all packets, not
69583 + just SYNs. Under most application behavior this causes no
69584 + problems, but applications (like haproxy) may not close certain
69585 + connections in a way that cleanly terminates them on the remote
69586 + end, leaving the remote host in LAST_ACK state. Because of this
69587 + side-effect and to prevent intentional LAST_ACK DoSes, this
69588 + feature also adds automatic mitigation against such attacks.
69589 + The mitigation drastically reduces the amount of time a socket
69590 + can spend in LAST_ACK state. If you're using haproxy and not
69591 + all servers it connects to have this option enabled, consider
69592 + disabling this feature on the haproxy host.
69593 +
69594 + If the sysctl option is enabled, two sysctl options with names
69595 + "ip_blackhole" and "lastack_retries" will be created.
69596 + While "ip_blackhole" takes the standard zero/non-zero on/off
69597 + toggle, "lastack_retries" uses the same kinds of values as
69598 + "tcp_retries1" and "tcp_retries2". The default value of 4
69599 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69600 + state.
69601 +
69602 +config GRKERNSEC_NO_SIMULT_CONNECT
69603 + bool "Disable TCP Simultaneous Connect"
69604 + default y if GRKERNSEC_CONFIG_AUTO
69605 + depends on NET
69606 + help
69607 + If you say Y here, a feature by Willy Tarreau will be enabled that
69608 + removes a weakness in Linux's strict implementation of TCP that
69609 + allows two clients to connect to each other without either entering
69610 + a listening state. The weakness allows an attacker to easily prevent
69611 + a client from connecting to a known server provided the source port
69612 + for the connection is guessed correctly.
69613 +
69614 + As the weakness could be used to prevent an antivirus or IPS from
69615 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69616 + it should be eliminated by enabling this option. Though Linux is
69617 + one of few operating systems supporting simultaneous connect, it
69618 + has no legitimate use in practice and is rarely supported by firewalls.
69619 +
69620 +config GRKERNSEC_SOCKET
69621 + bool "Socket restrictions"
69622 + depends on NET
69623 + help
69624 + If you say Y here, you will be able to choose from several options.
69625 + If you assign a GID on your system and add it to the supplementary
69626 + groups of users you want to restrict socket access to, this patch
69627 + will perform up to three things, based on the option(s) you choose.
69628 +
69629 +config GRKERNSEC_SOCKET_ALL
69630 + bool "Deny any sockets to group"
69631 + depends on GRKERNSEC_SOCKET
69632 + help
69633 + If you say Y here, you will be able to choose a GID of whose users will
69634 + be unable to connect to other hosts from your machine or run server
69635 + applications from your machine. If the sysctl option is enabled, a
69636 + sysctl option with name "socket_all" is created.
69637 +
69638 +config GRKERNSEC_SOCKET_ALL_GID
69639 + int "GID to deny all sockets for"
69640 + depends on GRKERNSEC_SOCKET_ALL
69641 + default 1004
69642 + help
69643 + Here you can choose the GID to disable socket access for. Remember to
69644 + add the users you want socket access disabled for to the GID
69645 + specified here. If the sysctl option is enabled, a sysctl option
69646 + with name "socket_all_gid" is created.
69647 +
69648 +config GRKERNSEC_SOCKET_CLIENT
69649 + bool "Deny client sockets to group"
69650 + depends on GRKERNSEC_SOCKET
69651 + help
69652 + If you say Y here, you will be able to choose a GID of whose users will
69653 + be unable to connect to other hosts from your machine, but will be
69654 + able to run servers. If this option is enabled, all users in the group
69655 + you specify will have to use passive mode when initiating ftp transfers
69656 + from the shell on your machine. If the sysctl option is enabled, a
69657 + sysctl option with name "socket_client" is created.
69658 +
69659 +config GRKERNSEC_SOCKET_CLIENT_GID
69660 + int "GID to deny client sockets for"
69661 + depends on GRKERNSEC_SOCKET_CLIENT
69662 + default 1003
69663 + help
69664 + Here you can choose the GID to disable client socket access for.
69665 + Remember to add the users you want client socket access disabled for to
69666 + the GID specified here. If the sysctl option is enabled, a sysctl
69667 + option with name "socket_client_gid" is created.
69668 +
69669 +config GRKERNSEC_SOCKET_SERVER
69670 + bool "Deny server sockets to group"
69671 + depends on GRKERNSEC_SOCKET
69672 + help
69673 + If you say Y here, you will be able to choose a GID of whose users will
69674 + be unable to run server applications from your machine. If the sysctl
69675 + option is enabled, a sysctl option with name "socket_server" is created.
69676 +
69677 +config GRKERNSEC_SOCKET_SERVER_GID
69678 + int "GID to deny server sockets for"
69679 + depends on GRKERNSEC_SOCKET_SERVER
69680 + default 1002
69681 + help
69682 + Here you can choose the GID to disable server socket access for.
69683 + Remember to add the users you want server socket access disabled for to
69684 + the GID specified here. If the sysctl option is enabled, a sysctl
69685 + option with name "socket_server_gid" is created.
69686 +
69687 +endmenu
69688 +
69689 +menu "Physical Protections"
69690 +depends on GRKERNSEC
69691 +
69692 +config GRKERNSEC_DENYUSB
69693 + bool "Deny new USB connections after toggle"
69694 + default y if GRKERNSEC_CONFIG_AUTO
69695 + depends on SYSCTL && USB_SUPPORT
69696 + help
69697 + If you say Y here, a new sysctl option with name "deny_new_usb"
69698 + will be created. Setting its value to 1 will prevent any new
69699 + USB devices from being recognized by the OS. Any attempted USB
69700 + device insertion will be logged. This option is intended to be
69701 + used against custom USB devices designed to exploit vulnerabilities
69702 + in various USB device drivers.
69703 +
69704 + For greatest effectiveness, this sysctl should be set after any
69705 + relevant init scripts. This option is safe to enable in distros
69706 + as each user can choose whether or not to toggle the sysctl.
69707 +
69708 +config GRKERNSEC_DENYUSB_FORCE
69709 + bool "Reject all USB devices not connected at boot"
69710 + select USB
69711 + depends on GRKERNSEC_DENYUSB
69712 + help
69713 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69714 + that doesn't involve a sysctl entry. This option should only be
69715 + enabled if you're sure you want to deny all new USB connections
69716 + at runtime and don't want to modify init scripts. This should not
69717 + be enabled by distros. It forces the core USB code to be built
69718 + into the kernel image so that all devices connected at boot time
69719 + can be recognized and new USB device connections can be prevented
69720 + prior to init running.
69721 +
69722 +endmenu
69723 +
69724 +menu "Sysctl Support"
69725 +depends on GRKERNSEC && SYSCTL
69726 +
69727 +config GRKERNSEC_SYSCTL
69728 + bool "Sysctl support"
69729 + default y if GRKERNSEC_CONFIG_AUTO
69730 + help
69731 + If you say Y here, you will be able to change the options that
69732 + grsecurity runs with at bootup, without having to recompile your
69733 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69734 + to enable (1) or disable (0) various features. All the sysctl entries
69735 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69736 + All features enabled in the kernel configuration are disabled at boot
69737 + if you do not say Y to the "Turn on features by default" option.
69738 + All options should be set at startup, and the grsec_lock entry should
69739 + be set to a non-zero value after all the options are set.
69740 + *THIS IS EXTREMELY IMPORTANT*
69741 +
69742 +config GRKERNSEC_SYSCTL_DISTRO
69743 + bool "Extra sysctl support for distro makers (READ HELP)"
69744 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69745 + help
69746 + If you say Y here, additional sysctl options will be created
69747 + for features that affect processes running as root. Therefore,
69748 + it is critical when using this option that the grsec_lock entry be
69749 + enabled after boot. Only distros with prebuilt kernel packages
69750 + with this option enabled that can ensure grsec_lock is enabled
69751 + after boot should use this option.
69752 + *Failure to set grsec_lock after boot makes all grsec features
69753 + this option covers useless*
69754 +
69755 + Currently this option creates the following sysctl entries:
69756 + "Disable Privileged I/O": "disable_priv_io"
69757 +
69758 +config GRKERNSEC_SYSCTL_ON
69759 + bool "Turn on features by default"
69760 + default y if GRKERNSEC_CONFIG_AUTO
69761 + depends on GRKERNSEC_SYSCTL
69762 + help
69763 + If you say Y here, instead of having all features enabled in the
69764 + kernel configuration disabled at boot time, the features will be
69765 + enabled at boot time. It is recommended you say Y here unless
69766 + there is some reason you would want all sysctl-tunable features to
69767 + be disabled by default. As mentioned elsewhere, it is important
69768 + to enable the grsec_lock entry once you have finished modifying
69769 + the sysctl entries.
69770 +
69771 +endmenu
69772 +menu "Logging Options"
69773 +depends on GRKERNSEC
69774 +
69775 +config GRKERNSEC_FLOODTIME
69776 + int "Seconds in between log messages (minimum)"
69777 + default 10
69778 + help
69779 + This option allows you to enforce the number of seconds between
69780 + grsecurity log messages. The default should be suitable for most
69781 + people, however, if you choose to change it, choose a value small enough
69782 + to allow informative logs to be produced, but large enough to
69783 + prevent flooding.
69784 +
69785 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69786 + any rate limiting on grsecurity log messages.
69787 +
69788 +config GRKERNSEC_FLOODBURST
69789 + int "Number of messages in a burst (maximum)"
69790 + default 6
69791 + help
69792 + This option allows you to choose the maximum number of messages allowed
69793 + within the flood time interval you chose in a separate option. The
69794 + default should be suitable for most people, however if you find that
69795 + many of your logs are being interpreted as flooding, you may want to
69796 + raise this value.
69797 +
69798 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69799 + any rate limiting on grsecurity log messages.
69800 +
69801 +endmenu
69802 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69803 new file mode 100644
69804 index 0000000..30ababb
69805 --- /dev/null
69806 +++ b/grsecurity/Makefile
69807 @@ -0,0 +1,54 @@
69808 +# grsecurity – access control and security hardening for Linux
69809 +# All code in this directory and various hooks located throughout the Linux kernel are
69810 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69811 +# http://www.grsecurity.net spender@grsecurity.net
69812 +#
69813 +# This program is free software; you can redistribute it and/or
69814 +# modify it under the terms of the GNU General Public License version 2
69815 +# as published by the Free Software Foundation.
69816 +#
69817 +# This program is distributed in the hope that it will be useful,
69818 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69819 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69820 +# GNU General Public License for more details.
69821 +#
69822 +# You should have received a copy of the GNU General Public License
69823 +# along with this program; if not, write to the Free Software
69824 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69825 +
69826 +KBUILD_CFLAGS += -Werror
69827 +
69828 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69829 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69830 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69831 + grsec_usb.o grsec_ipc.o grsec_proc.o
69832 +
69833 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69834 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69835 + gracl_learn.o grsec_log.o gracl_policy.o
69836 +ifdef CONFIG_COMPAT
69837 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69838 +endif
69839 +
69840 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69841 +
69842 +ifdef CONFIG_NET
69843 +obj-y += grsec_sock.o
69844 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69845 +endif
69846 +
69847 +ifndef CONFIG_GRKERNSEC
69848 +obj-y += grsec_disabled.o
69849 +endif
69850 +
69851 +ifdef CONFIG_GRKERNSEC_HIDESYM
69852 +extra-y := grsec_hidesym.o
69853 +$(obj)/grsec_hidesym.o:
69854 + @-chmod -f 500 /boot
69855 + @-chmod -f 500 /lib/modules
69856 + @-chmod -f 500 /lib64/modules
69857 + @-chmod -f 500 /lib32/modules
69858 + @-chmod -f 700 .
69859 + @-chmod -f 700 $(objtree)
69860 + @echo ' grsec: protected kernel image paths'
69861 +endif
69862 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69863 new file mode 100644
69864 index 0000000..6ae3aa0
69865 --- /dev/null
69866 +++ b/grsecurity/gracl.c
69867 @@ -0,0 +1,2703 @@
69868 +#include <linux/kernel.h>
69869 +#include <linux/module.h>
69870 +#include <linux/sched.h>
69871 +#include <linux/mm.h>
69872 +#include <linux/file.h>
69873 +#include <linux/fs.h>
69874 +#include <linux/namei.h>
69875 +#include <linux/mount.h>
69876 +#include <linux/tty.h>
69877 +#include <linux/proc_fs.h>
69878 +#include <linux/lglock.h>
69879 +#include <linux/slab.h>
69880 +#include <linux/vmalloc.h>
69881 +#include <linux/types.h>
69882 +#include <linux/sysctl.h>
69883 +#include <linux/netdevice.h>
69884 +#include <linux/ptrace.h>
69885 +#include <linux/gracl.h>
69886 +#include <linux/gralloc.h>
69887 +#include <linux/security.h>
69888 +#include <linux/grinternal.h>
69889 +#include <linux/pid_namespace.h>
69890 +#include <linux/stop_machine.h>
69891 +#include <linux/fdtable.h>
69892 +#include <linux/percpu.h>
69893 +#include <linux/lglock.h>
69894 +#include <linux/hugetlb.h>
69895 +#include <linux/posix-timers.h>
69896 +#include <linux/prefetch.h>
69897 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69898 +#include <linux/magic.h>
69899 +#include <linux/pagemap.h>
69900 +#include "../fs/btrfs/async-thread.h"
69901 +#include "../fs/btrfs/ctree.h"
69902 +#include "../fs/btrfs/btrfs_inode.h"
69903 +#endif
69904 +#include "../fs/mount.h"
69905 +
69906 +#include <asm/uaccess.h>
69907 +#include <asm/errno.h>
69908 +#include <asm/mman.h>
69909 +
69910 +#define FOR_EACH_ROLE_START(role) \
69911 + role = running_polstate.role_list; \
69912 + while (role) {
69913 +
69914 +#define FOR_EACH_ROLE_END(role) \
69915 + role = role->prev; \
69916 + }
69917 +
69918 +extern struct path gr_real_root;
69919 +
69920 +static struct gr_policy_state running_polstate;
69921 +struct gr_policy_state *polstate = &running_polstate;
69922 +extern struct gr_alloc_state *current_alloc_state;
69923 +
69924 +extern char *gr_shared_page[4];
69925 +DEFINE_RWLOCK(gr_inode_lock);
69926 +
69927 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69928 +
69929 +#ifdef CONFIG_NET
69930 +extern struct vfsmount *sock_mnt;
69931 +#endif
69932 +
69933 +extern struct vfsmount *pipe_mnt;
69934 +extern struct vfsmount *shm_mnt;
69935 +
69936 +#ifdef CONFIG_HUGETLBFS
69937 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69938 +#endif
69939 +
69940 +extern u16 acl_sp_role_value;
69941 +extern struct acl_object_label *fakefs_obj_rw;
69942 +extern struct acl_object_label *fakefs_obj_rwx;
69943 +
69944 +int gr_acl_is_enabled(void)
69945 +{
69946 + return (gr_status & GR_READY);
69947 +}
69948 +
69949 +void gr_enable_rbac_system(void)
69950 +{
69951 + pax_open_kernel();
69952 + gr_status |= GR_READY;
69953 + pax_close_kernel();
69954 +}
69955 +
69956 +int gr_rbac_disable(void *unused)
69957 +{
69958 + pax_open_kernel();
69959 + gr_status &= ~GR_READY;
69960 + pax_close_kernel();
69961 +
69962 + return 0;
69963 +}
69964 +
69965 +static inline dev_t __get_dev(const struct dentry *dentry)
69966 +{
69967 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69968 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69969 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69970 + else
69971 +#endif
69972 + return dentry->d_sb->s_dev;
69973 +}
69974 +
69975 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69976 +{
69977 + return __get_dev(dentry);
69978 +}
69979 +
69980 +static char gr_task_roletype_to_char(struct task_struct *task)
69981 +{
69982 + switch (task->role->roletype &
69983 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69984 + GR_ROLE_SPECIAL)) {
69985 + case GR_ROLE_DEFAULT:
69986 + return 'D';
69987 + case GR_ROLE_USER:
69988 + return 'U';
69989 + case GR_ROLE_GROUP:
69990 + return 'G';
69991 + case GR_ROLE_SPECIAL:
69992 + return 'S';
69993 + }
69994 +
69995 + return 'X';
69996 +}
69997 +
69998 +char gr_roletype_to_char(void)
69999 +{
70000 + return gr_task_roletype_to_char(current);
70001 +}
70002 +
70003 +__inline__ int
70004 +gr_acl_tpe_check(void)
70005 +{
70006 + if (unlikely(!(gr_status & GR_READY)))
70007 + return 0;
70008 + if (current->role->roletype & GR_ROLE_TPE)
70009 + return 1;
70010 + else
70011 + return 0;
70012 +}
70013 +
70014 +int
70015 +gr_handle_rawio(const struct inode *inode)
70016 +{
70017 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70018 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
70019 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
70020 + !capable(CAP_SYS_RAWIO))
70021 + return 1;
70022 +#endif
70023 + return 0;
70024 +}
70025 +
70026 +int
70027 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
70028 +{
70029 + if (likely(lena != lenb))
70030 + return 0;
70031 +
70032 + return !memcmp(a, b, lena);
70033 +}
70034 +
70035 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
70036 +{
70037 + *buflen -= namelen;
70038 + if (*buflen < 0)
70039 + return -ENAMETOOLONG;
70040 + *buffer -= namelen;
70041 + memcpy(*buffer, str, namelen);
70042 + return 0;
70043 +}
70044 +
70045 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
70046 +{
70047 + return prepend(buffer, buflen, name->name, name->len);
70048 +}
70049 +
70050 +static int prepend_path(const struct path *path, struct path *root,
70051 + char **buffer, int *buflen)
70052 +{
70053 + struct dentry *dentry = path->dentry;
70054 + struct vfsmount *vfsmnt = path->mnt;
70055 + struct mount *mnt = real_mount(vfsmnt);
70056 + bool slash = false;
70057 + int error = 0;
70058 +
70059 + while (dentry != root->dentry || vfsmnt != root->mnt) {
70060 + struct dentry * parent;
70061 +
70062 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
70063 + /* Global root? */
70064 + if (!mnt_has_parent(mnt)) {
70065 + goto out;
70066 + }
70067 + dentry = mnt->mnt_mountpoint;
70068 + mnt = mnt->mnt_parent;
70069 + vfsmnt = &mnt->mnt;
70070 + continue;
70071 + }
70072 + parent = dentry->d_parent;
70073 + prefetch(parent);
70074 + spin_lock(&dentry->d_lock);
70075 + error = prepend_name(buffer, buflen, &dentry->d_name);
70076 + spin_unlock(&dentry->d_lock);
70077 + if (!error)
70078 + error = prepend(buffer, buflen, "/", 1);
70079 + if (error)
70080 + break;
70081 +
70082 + slash = true;
70083 + dentry = parent;
70084 + }
70085 +
70086 +out:
70087 + if (!error && !slash)
70088 + error = prepend(buffer, buflen, "/", 1);
70089 +
70090 + return error;
70091 +}
70092 +
70093 +/* this must be called with mount_lock and rename_lock held */
70094 +
70095 +static char *__our_d_path(const struct path *path, struct path *root,
70096 + char *buf, int buflen)
70097 +{
70098 + char *res = buf + buflen;
70099 + int error;
70100 +
70101 + prepend(&res, &buflen, "\0", 1);
70102 + error = prepend_path(path, root, &res, &buflen);
70103 + if (error)
70104 + return ERR_PTR(error);
70105 +
70106 + return res;
70107 +}
70108 +
70109 +static char *
70110 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
70111 +{
70112 + char *retval;
70113 +
70114 + retval = __our_d_path(path, root, buf, buflen);
70115 + if (unlikely(IS_ERR(retval)))
70116 + retval = strcpy(buf, "<path too long>");
70117 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
70118 + retval[1] = '\0';
70119 +
70120 + return retval;
70121 +}
70122 +
70123 +static char *
70124 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70125 + char *buf, int buflen)
70126 +{
70127 + struct path path;
70128 + char *res;
70129 +
70130 + path.dentry = (struct dentry *)dentry;
70131 + path.mnt = (struct vfsmount *)vfsmnt;
70132 +
70133 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70134 + by the RBAC system */
70135 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
70136 +
70137 + return res;
70138 +}
70139 +
70140 +static char *
70141 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70142 + char *buf, int buflen)
70143 +{
70144 + char *res;
70145 + struct path path;
70146 + struct path root;
70147 + struct task_struct *reaper = init_pid_ns.child_reaper;
70148 +
70149 + path.dentry = (struct dentry *)dentry;
70150 + path.mnt = (struct vfsmount *)vfsmnt;
70151 +
70152 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70153 + get_fs_root(reaper->fs, &root);
70154 +
70155 + read_seqlock_excl(&mount_lock);
70156 + write_seqlock(&rename_lock);
70157 + res = gen_full_path(&path, &root, buf, buflen);
70158 + write_sequnlock(&rename_lock);
70159 + read_sequnlock_excl(&mount_lock);
70160 +
70161 + path_put(&root);
70162 + return res;
70163 +}
70164 +
70165 +char *
70166 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70167 +{
70168 + char *ret;
70169 + read_seqlock_excl(&mount_lock);
70170 + write_seqlock(&rename_lock);
70171 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70172 + PAGE_SIZE);
70173 + write_sequnlock(&rename_lock);
70174 + read_sequnlock_excl(&mount_lock);
70175 + return ret;
70176 +}
70177 +
70178 +static char *
70179 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70180 +{
70181 + char *ret;
70182 + char *buf;
70183 + int buflen;
70184 +
70185 + read_seqlock_excl(&mount_lock);
70186 + write_seqlock(&rename_lock);
70187 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70188 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70189 + buflen = (int)(ret - buf);
70190 + if (buflen >= 5)
70191 + prepend(&ret, &buflen, "/proc", 5);
70192 + else
70193 + ret = strcpy(buf, "<path too long>");
70194 + write_sequnlock(&rename_lock);
70195 + read_sequnlock_excl(&mount_lock);
70196 + return ret;
70197 +}
70198 +
70199 +char *
70200 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70201 +{
70202 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70203 + PAGE_SIZE);
70204 +}
70205 +
70206 +char *
70207 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70208 +{
70209 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70210 + PAGE_SIZE);
70211 +}
70212 +
70213 +char *
70214 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70215 +{
70216 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70217 + PAGE_SIZE);
70218 +}
70219 +
70220 +char *
70221 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70222 +{
70223 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70224 + PAGE_SIZE);
70225 +}
70226 +
70227 +char *
70228 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70229 +{
70230 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70231 + PAGE_SIZE);
70232 +}
70233 +
70234 +__inline__ __u32
70235 +to_gr_audit(const __u32 reqmode)
70236 +{
70237 + /* masks off auditable permission flags, then shifts them to create
70238 + auditing flags, and adds the special case of append auditing if
70239 + we're requesting write */
70240 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70241 +}
70242 +
70243 +struct acl_role_label *
70244 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70245 + const gid_t gid)
70246 +{
70247 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70248 + struct acl_role_label *match;
70249 + struct role_allowed_ip *ipp;
70250 + unsigned int x;
70251 + u32 curr_ip = task->signal->saved_ip;
70252 +
70253 + match = state->acl_role_set.r_hash[index];
70254 +
70255 + while (match) {
70256 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70257 + for (x = 0; x < match->domain_child_num; x++) {
70258 + if (match->domain_children[x] == uid)
70259 + goto found;
70260 + }
70261 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70262 + break;
70263 + match = match->next;
70264 + }
70265 +found:
70266 + if (match == NULL) {
70267 + try_group:
70268 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70269 + match = state->acl_role_set.r_hash[index];
70270 +
70271 + while (match) {
70272 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70273 + for (x = 0; x < match->domain_child_num; x++) {
70274 + if (match->domain_children[x] == gid)
70275 + goto found2;
70276 + }
70277 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70278 + break;
70279 + match = match->next;
70280 + }
70281 +found2:
70282 + if (match == NULL)
70283 + match = state->default_role;
70284 + if (match->allowed_ips == NULL)
70285 + return match;
70286 + else {
70287 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70288 + if (likely
70289 + ((ntohl(curr_ip) & ipp->netmask) ==
70290 + (ntohl(ipp->addr) & ipp->netmask)))
70291 + return match;
70292 + }
70293 + match = state->default_role;
70294 + }
70295 + } else if (match->allowed_ips == NULL) {
70296 + return match;
70297 + } else {
70298 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70299 + if (likely
70300 + ((ntohl(curr_ip) & ipp->netmask) ==
70301 + (ntohl(ipp->addr) & ipp->netmask)))
70302 + return match;
70303 + }
70304 + goto try_group;
70305 + }
70306 +
70307 + return match;
70308 +}
70309 +
70310 +static struct acl_role_label *
70311 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70312 + const gid_t gid)
70313 +{
70314 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70315 +}
70316 +
70317 +struct acl_subject_label *
70318 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70319 + const struct acl_role_label *role)
70320 +{
70321 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70322 + struct acl_subject_label *match;
70323 +
70324 + match = role->subj_hash[index];
70325 +
70326 + while (match && (match->inode != ino || match->device != dev ||
70327 + (match->mode & GR_DELETED))) {
70328 + match = match->next;
70329 + }
70330 +
70331 + if (match && !(match->mode & GR_DELETED))
70332 + return match;
70333 + else
70334 + return NULL;
70335 +}
70336 +
70337 +struct acl_subject_label *
70338 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70339 + const struct acl_role_label *role)
70340 +{
70341 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70342 + struct acl_subject_label *match;
70343 +
70344 + match = role->subj_hash[index];
70345 +
70346 + while (match && (match->inode != ino || match->device != dev ||
70347 + !(match->mode & GR_DELETED))) {
70348 + match = match->next;
70349 + }
70350 +
70351 + if (match && (match->mode & GR_DELETED))
70352 + return match;
70353 + else
70354 + return NULL;
70355 +}
70356 +
70357 +static struct acl_object_label *
70358 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70359 + const struct acl_subject_label *subj)
70360 +{
70361 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70362 + struct acl_object_label *match;
70363 +
70364 + match = subj->obj_hash[index];
70365 +
70366 + while (match && (match->inode != ino || match->device != dev ||
70367 + (match->mode & GR_DELETED))) {
70368 + match = match->next;
70369 + }
70370 +
70371 + if (match && !(match->mode & GR_DELETED))
70372 + return match;
70373 + else
70374 + return NULL;
70375 +}
70376 +
70377 +static struct acl_object_label *
70378 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70379 + const struct acl_subject_label *subj)
70380 +{
70381 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70382 + struct acl_object_label *match;
70383 +
70384 + match = subj->obj_hash[index];
70385 +
70386 + while (match && (match->inode != ino || match->device != dev ||
70387 + !(match->mode & GR_DELETED))) {
70388 + match = match->next;
70389 + }
70390 +
70391 + if (match && (match->mode & GR_DELETED))
70392 + return match;
70393 +
70394 + match = subj->obj_hash[index];
70395 +
70396 + while (match && (match->inode != ino || match->device != dev ||
70397 + (match->mode & GR_DELETED))) {
70398 + match = match->next;
70399 + }
70400 +
70401 + if (match && !(match->mode & GR_DELETED))
70402 + return match;
70403 + else
70404 + return NULL;
70405 +}
70406 +
70407 +struct name_entry *
70408 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70409 +{
70410 + unsigned int len = strlen(name);
70411 + unsigned int key = full_name_hash(name, len);
70412 + unsigned int index = key % state->name_set.n_size;
70413 + struct name_entry *match;
70414 +
70415 + match = state->name_set.n_hash[index];
70416 +
70417 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70418 + match = match->next;
70419 +
70420 + return match;
70421 +}
70422 +
70423 +static struct name_entry *
70424 +lookup_name_entry(const char *name)
70425 +{
70426 + return __lookup_name_entry(&running_polstate, name);
70427 +}
70428 +
70429 +static struct name_entry *
70430 +lookup_name_entry_create(const char *name)
70431 +{
70432 + unsigned int len = strlen(name);
70433 + unsigned int key = full_name_hash(name, len);
70434 + unsigned int index = key % running_polstate.name_set.n_size;
70435 + struct name_entry *match;
70436 +
70437 + match = running_polstate.name_set.n_hash[index];
70438 +
70439 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70440 + !match->deleted))
70441 + match = match->next;
70442 +
70443 + if (match && match->deleted)
70444 + return match;
70445 +
70446 + match = running_polstate.name_set.n_hash[index];
70447 +
70448 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70449 + match->deleted))
70450 + match = match->next;
70451 +
70452 + if (match && !match->deleted)
70453 + return match;
70454 + else
70455 + return NULL;
70456 +}
70457 +
70458 +static struct inodev_entry *
70459 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70460 +{
70461 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70462 + struct inodev_entry *match;
70463 +
70464 + match = running_polstate.inodev_set.i_hash[index];
70465 +
70466 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70467 + match = match->next;
70468 +
70469 + return match;
70470 +}
70471 +
70472 +void
70473 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70474 +{
70475 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70476 + state->inodev_set.i_size);
70477 + struct inodev_entry **curr;
70478 +
70479 + entry->prev = NULL;
70480 +
70481 + curr = &state->inodev_set.i_hash[index];
70482 + if (*curr != NULL)
70483 + (*curr)->prev = entry;
70484 +
70485 + entry->next = *curr;
70486 + *curr = entry;
70487 +
70488 + return;
70489 +}
70490 +
70491 +static void
70492 +insert_inodev_entry(struct inodev_entry *entry)
70493 +{
70494 + __insert_inodev_entry(&running_polstate, entry);
70495 +}
70496 +
70497 +void
70498 +insert_acl_obj_label(struct acl_object_label *obj,
70499 + struct acl_subject_label *subj)
70500 +{
70501 + unsigned int index =
70502 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70503 + struct acl_object_label **curr;
70504 +
70505 + obj->prev = NULL;
70506 +
70507 + curr = &subj->obj_hash[index];
70508 + if (*curr != NULL)
70509 + (*curr)->prev = obj;
70510 +
70511 + obj->next = *curr;
70512 + *curr = obj;
70513 +
70514 + return;
70515 +}
70516 +
70517 +void
70518 +insert_acl_subj_label(struct acl_subject_label *obj,
70519 + struct acl_role_label *role)
70520 +{
70521 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70522 + struct acl_subject_label **curr;
70523 +
70524 + obj->prev = NULL;
70525 +
70526 + curr = &role->subj_hash[index];
70527 + if (*curr != NULL)
70528 + (*curr)->prev = obj;
70529 +
70530 + obj->next = *curr;
70531 + *curr = obj;
70532 +
70533 + return;
70534 +}
70535 +
70536 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70537 +
70538 +static int
70539 +glob_match(const char *p, const char *n)
70540 +{
70541 + char c;
70542 +
70543 + while ((c = *p++) != '\0') {
70544 + switch (c) {
70545 + case '?':
70546 + if (*n == '\0')
70547 + return 1;
70548 + else if (*n == '/')
70549 + return 1;
70550 + break;
70551 + case '\\':
70552 + if (*n != c)
70553 + return 1;
70554 + break;
70555 + case '*':
70556 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70557 + if (*n == '/')
70558 + return 1;
70559 + else if (c == '?') {
70560 + if (*n == '\0')
70561 + return 1;
70562 + else
70563 + ++n;
70564 + }
70565 + }
70566 + if (c == '\0') {
70567 + return 0;
70568 + } else {
70569 + const char *endp;
70570 +
70571 + if ((endp = strchr(n, '/')) == NULL)
70572 + endp = n + strlen(n);
70573 +
70574 + if (c == '[') {
70575 + for (--p; n < endp; ++n)
70576 + if (!glob_match(p, n))
70577 + return 0;
70578 + } else if (c == '/') {
70579 + while (*n != '\0' && *n != '/')
70580 + ++n;
70581 + if (*n == '/' && !glob_match(p, n + 1))
70582 + return 0;
70583 + } else {
70584 + for (--p; n < endp; ++n)
70585 + if (*n == c && !glob_match(p, n))
70586 + return 0;
70587 + }
70588 +
70589 + return 1;
70590 + }
70591 + case '[':
70592 + {
70593 + int not;
70594 + char cold;
70595 +
70596 + if (*n == '\0' || *n == '/')
70597 + return 1;
70598 +
70599 + not = (*p == '!' || *p == '^');
70600 + if (not)
70601 + ++p;
70602 +
70603 + c = *p++;
70604 + for (;;) {
70605 + unsigned char fn = (unsigned char)*n;
70606 +
70607 + if (c == '\0')
70608 + return 1;
70609 + else {
70610 + if (c == fn)
70611 + goto matched;
70612 + cold = c;
70613 + c = *p++;
70614 +
70615 + if (c == '-' && *p != ']') {
70616 + unsigned char cend = *p++;
70617 +
70618 + if (cend == '\0')
70619 + return 1;
70620 +
70621 + if (cold <= fn && fn <= cend)
70622 + goto matched;
70623 +
70624 + c = *p++;
70625 + }
70626 + }
70627 +
70628 + if (c == ']')
70629 + break;
70630 + }
70631 + if (!not)
70632 + return 1;
70633 + break;
70634 + matched:
70635 + while (c != ']') {
70636 + if (c == '\0')
70637 + return 1;
70638 +
70639 + c = *p++;
70640 + }
70641 + if (not)
70642 + return 1;
70643 + }
70644 + break;
70645 + default:
70646 + if (c != *n)
70647 + return 1;
70648 + }
70649 +
70650 + ++n;
70651 + }
70652 +
70653 + if (*n == '\0')
70654 + return 0;
70655 +
70656 + if (*n == '/')
70657 + return 0;
70658 +
70659 + return 1;
70660 +}
70661 +
70662 +static struct acl_object_label *
70663 +chk_glob_label(struct acl_object_label *globbed,
70664 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70665 +{
70666 + struct acl_object_label *tmp;
70667 +
70668 + if (*path == NULL)
70669 + *path = gr_to_filename_nolock(dentry, mnt);
70670 +
70671 + tmp = globbed;
70672 +
70673 + while (tmp) {
70674 + if (!glob_match(tmp->filename, *path))
70675 + return tmp;
70676 + tmp = tmp->next;
70677 + }
70678 +
70679 + return NULL;
70680 +}
70681 +
70682 +static struct acl_object_label *
70683 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70684 + const ino_t curr_ino, const dev_t curr_dev,
70685 + const struct acl_subject_label *subj, char **path, const int checkglob)
70686 +{
70687 + struct acl_subject_label *tmpsubj;
70688 + struct acl_object_label *retval;
70689 + struct acl_object_label *retval2;
70690 +
70691 + tmpsubj = (struct acl_subject_label *) subj;
70692 + read_lock(&gr_inode_lock);
70693 + do {
70694 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70695 + if (retval) {
70696 + if (checkglob && retval->globbed) {
70697 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70698 + if (retval2)
70699 + retval = retval2;
70700 + }
70701 + break;
70702 + }
70703 + } while ((tmpsubj = tmpsubj->parent_subject));
70704 + read_unlock(&gr_inode_lock);
70705 +
70706 + return retval;
70707 +}
70708 +
70709 +static __inline__ struct acl_object_label *
70710 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70711 + struct dentry *curr_dentry,
70712 + const struct acl_subject_label *subj, char **path, const int checkglob)
70713 +{
70714 + int newglob = checkglob;
70715 + ino_t inode;
70716 + dev_t device;
70717 +
70718 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70719 + as we don't want a / * rule to match instead of the / object
70720 + don't do this for create lookups that call this function though, since they're looking up
70721 + on the parent and thus need globbing checks on all paths
70722 + */
70723 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70724 + newglob = GR_NO_GLOB;
70725 +
70726 + spin_lock(&curr_dentry->d_lock);
70727 + inode = curr_dentry->d_inode->i_ino;
70728 + device = __get_dev(curr_dentry);
70729 + spin_unlock(&curr_dentry->d_lock);
70730 +
70731 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70732 +}
70733 +
70734 +#ifdef CONFIG_HUGETLBFS
70735 +static inline bool
70736 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70737 +{
70738 + int i;
70739 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70740 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70741 + return true;
70742 + }
70743 +
70744 + return false;
70745 +}
70746 +#endif
70747 +
70748 +static struct acl_object_label *
70749 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70750 + const struct acl_subject_label *subj, char *path, const int checkglob)
70751 +{
70752 + struct dentry *dentry = (struct dentry *) l_dentry;
70753 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70754 + struct mount *real_mnt = real_mount(mnt);
70755 + struct acl_object_label *retval;
70756 + struct dentry *parent;
70757 +
70758 + read_seqlock_excl(&mount_lock);
70759 + write_seqlock(&rename_lock);
70760 +
70761 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70762 +#ifdef CONFIG_NET
70763 + mnt == sock_mnt ||
70764 +#endif
70765 +#ifdef CONFIG_HUGETLBFS
70766 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70767 +#endif
70768 + /* ignore Eric Biederman */
70769 + IS_PRIVATE(l_dentry->d_inode))) {
70770 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70771 + goto out;
70772 + }
70773 +
70774 + for (;;) {
70775 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70776 + break;
70777 +
70778 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70779 + if (!mnt_has_parent(real_mnt))
70780 + break;
70781 +
70782 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70783 + if (retval != NULL)
70784 + goto out;
70785 +
70786 + dentry = real_mnt->mnt_mountpoint;
70787 + real_mnt = real_mnt->mnt_parent;
70788 + mnt = &real_mnt->mnt;
70789 + continue;
70790 + }
70791 +
70792 + parent = dentry->d_parent;
70793 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70794 + if (retval != NULL)
70795 + goto out;
70796 +
70797 + dentry = parent;
70798 + }
70799 +
70800 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70801 +
70802 + /* gr_real_root is pinned so we don't have to hold a reference */
70803 + if (retval == NULL)
70804 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70805 +out:
70806 + write_sequnlock(&rename_lock);
70807 + read_sequnlock_excl(&mount_lock);
70808 +
70809 + BUG_ON(retval == NULL);
70810 +
70811 + return retval;
70812 +}
70813 +
70814 +static __inline__ struct acl_object_label *
70815 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70816 + const struct acl_subject_label *subj)
70817 +{
70818 + char *path = NULL;
70819 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70820 +}
70821 +
70822 +static __inline__ struct acl_object_label *
70823 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70824 + const struct acl_subject_label *subj)
70825 +{
70826 + char *path = NULL;
70827 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70828 +}
70829 +
70830 +static __inline__ struct acl_object_label *
70831 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70832 + const struct acl_subject_label *subj, char *path)
70833 +{
70834 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70835 +}
70836 +
70837 +struct acl_subject_label *
70838 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70839 + const struct acl_role_label *role)
70840 +{
70841 + struct dentry *dentry = (struct dentry *) l_dentry;
70842 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70843 + struct mount *real_mnt = real_mount(mnt);
70844 + struct acl_subject_label *retval;
70845 + struct dentry *parent;
70846 +
70847 + read_seqlock_excl(&mount_lock);
70848 + write_seqlock(&rename_lock);
70849 +
70850 + for (;;) {
70851 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70852 + break;
70853 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70854 + if (!mnt_has_parent(real_mnt))
70855 + break;
70856 +
70857 + spin_lock(&dentry->d_lock);
70858 + read_lock(&gr_inode_lock);
70859 + retval =
70860 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70861 + __get_dev(dentry), role);
70862 + read_unlock(&gr_inode_lock);
70863 + spin_unlock(&dentry->d_lock);
70864 + if (retval != NULL)
70865 + goto out;
70866 +
70867 + dentry = real_mnt->mnt_mountpoint;
70868 + real_mnt = real_mnt->mnt_parent;
70869 + mnt = &real_mnt->mnt;
70870 + continue;
70871 + }
70872 +
70873 + spin_lock(&dentry->d_lock);
70874 + read_lock(&gr_inode_lock);
70875 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70876 + __get_dev(dentry), role);
70877 + read_unlock(&gr_inode_lock);
70878 + parent = dentry->d_parent;
70879 + spin_unlock(&dentry->d_lock);
70880 +
70881 + if (retval != NULL)
70882 + goto out;
70883 +
70884 + dentry = parent;
70885 + }
70886 +
70887 + spin_lock(&dentry->d_lock);
70888 + read_lock(&gr_inode_lock);
70889 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70890 + __get_dev(dentry), role);
70891 + read_unlock(&gr_inode_lock);
70892 + spin_unlock(&dentry->d_lock);
70893 +
70894 + if (unlikely(retval == NULL)) {
70895 + /* gr_real_root is pinned, we don't need to hold a reference */
70896 + read_lock(&gr_inode_lock);
70897 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70898 + __get_dev(gr_real_root.dentry), role);
70899 + read_unlock(&gr_inode_lock);
70900 + }
70901 +out:
70902 + write_sequnlock(&rename_lock);
70903 + read_sequnlock_excl(&mount_lock);
70904 +
70905 + BUG_ON(retval == NULL);
70906 +
70907 + return retval;
70908 +}
70909 +
70910 +void
70911 +assign_special_role(const char *rolename)
70912 +{
70913 + struct acl_object_label *obj;
70914 + struct acl_role_label *r;
70915 + struct acl_role_label *assigned = NULL;
70916 + struct task_struct *tsk;
70917 + struct file *filp;
70918 +
70919 + FOR_EACH_ROLE_START(r)
70920 + if (!strcmp(rolename, r->rolename) &&
70921 + (r->roletype & GR_ROLE_SPECIAL)) {
70922 + assigned = r;
70923 + break;
70924 + }
70925 + FOR_EACH_ROLE_END(r)
70926 +
70927 + if (!assigned)
70928 + return;
70929 +
70930 + read_lock(&tasklist_lock);
70931 + read_lock(&grsec_exec_file_lock);
70932 +
70933 + tsk = current->real_parent;
70934 + if (tsk == NULL)
70935 + goto out_unlock;
70936 +
70937 + filp = tsk->exec_file;
70938 + if (filp == NULL)
70939 + goto out_unlock;
70940 +
70941 + tsk->is_writable = 0;
70942 + tsk->inherited = 0;
70943 +
70944 + tsk->acl_sp_role = 1;
70945 + tsk->acl_role_id = ++acl_sp_role_value;
70946 + tsk->role = assigned;
70947 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70948 +
70949 + /* ignore additional mmap checks for processes that are writable
70950 + by the default ACL */
70951 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70952 + if (unlikely(obj->mode & GR_WRITE))
70953 + tsk->is_writable = 1;
70954 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70955 + if (unlikely(obj->mode & GR_WRITE))
70956 + tsk->is_writable = 1;
70957 +
70958 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70959 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70960 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70961 +#endif
70962 +
70963 +out_unlock:
70964 + read_unlock(&grsec_exec_file_lock);
70965 + read_unlock(&tasklist_lock);
70966 + return;
70967 +}
70968 +
70969 +
70970 +static void
70971 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70972 +{
70973 + struct task_struct *task = current;
70974 + const struct cred *cred = current_cred();
70975 +
70976 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70977 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70978 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70979 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70980 +
70981 + return;
70982 +}
70983 +
70984 +static void
70985 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70986 +{
70987 + struct task_struct *task = current;
70988 + const struct cred *cred = current_cred();
70989 +
70990 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70991 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70992 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70993 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70994 +
70995 + return;
70996 +}
70997 +
70998 +static void
70999 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
71000 +{
71001 + struct task_struct *task = current;
71002 + const struct cred *cred = current_cred();
71003 +
71004 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71005 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71006 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71007 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
71008 +
71009 + return;
71010 +}
71011 +
71012 +static void
71013 +gr_set_proc_res(struct task_struct *task)
71014 +{
71015 + struct acl_subject_label *proc;
71016 + unsigned short i;
71017 +
71018 + proc = task->acl;
71019 +
71020 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
71021 + return;
71022 +
71023 + for (i = 0; i < RLIM_NLIMITS; i++) {
71024 + if (!(proc->resmask & (1U << i)))
71025 + continue;
71026 +
71027 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
71028 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
71029 +
71030 + if (i == RLIMIT_CPU)
71031 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
71032 + }
71033 +
71034 + return;
71035 +}
71036 +
71037 +/* both of the below must be called with
71038 + rcu_read_lock();
71039 + read_lock(&tasklist_lock);
71040 + read_lock(&grsec_exec_file_lock);
71041 +*/
71042 +
71043 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
71044 +{
71045 + char *tmpname;
71046 + struct acl_subject_label *tmpsubj;
71047 + struct file *filp;
71048 + struct name_entry *nmatch;
71049 +
71050 + filp = task->exec_file;
71051 + if (filp == NULL)
71052 + return NULL;
71053 +
71054 + /* the following is to apply the correct subject
71055 + on binaries running when the RBAC system
71056 + is enabled, when the binaries have been
71057 + replaced or deleted since their execution
71058 + -----
71059 + when the RBAC system starts, the inode/dev
71060 + from exec_file will be one the RBAC system
71061 + is unaware of. It only knows the inode/dev
71062 + of the present file on disk, or the absence
71063 + of it.
71064 + */
71065 +
71066 + if (filename)
71067 + nmatch = __lookup_name_entry(state, filename);
71068 + else {
71069 + preempt_disable();
71070 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
71071 +
71072 + nmatch = __lookup_name_entry(state, tmpname);
71073 + preempt_enable();
71074 + }
71075 + tmpsubj = NULL;
71076 + if (nmatch) {
71077 + if (nmatch->deleted)
71078 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
71079 + else
71080 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
71081 + }
71082 + /* this also works for the reload case -- if we don't match a potentially inherited subject
71083 + then we fall back to a normal lookup based on the binary's ino/dev
71084 + */
71085 + if (tmpsubj == NULL)
71086 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
71087 +
71088 + return tmpsubj;
71089 +}
71090 +
71091 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
71092 +{
71093 + return __gr_get_subject_for_task(&running_polstate, task, filename);
71094 +}
71095 +
71096 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
71097 +{
71098 + struct acl_object_label *obj;
71099 + struct file *filp;
71100 +
71101 + filp = task->exec_file;
71102 +
71103 + task->acl = subj;
71104 + task->is_writable = 0;
71105 + /* ignore additional mmap checks for processes that are writable
71106 + by the default ACL */
71107 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
71108 + if (unlikely(obj->mode & GR_WRITE))
71109 + task->is_writable = 1;
71110 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71111 + if (unlikely(obj->mode & GR_WRITE))
71112 + task->is_writable = 1;
71113 +
71114 + gr_set_proc_res(task);
71115 +
71116 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71117 + 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);
71118 +#endif
71119 +}
71120 +
71121 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
71122 +{
71123 + __gr_apply_subject_to_task(&running_polstate, task, subj);
71124 +}
71125 +
71126 +__u32
71127 +gr_search_file(const struct dentry * dentry, const __u32 mode,
71128 + const struct vfsmount * mnt)
71129 +{
71130 + __u32 retval = mode;
71131 + struct acl_subject_label *curracl;
71132 + struct acl_object_label *currobj;
71133 +
71134 + if (unlikely(!(gr_status & GR_READY)))
71135 + return (mode & ~GR_AUDITS);
71136 +
71137 + curracl = current->acl;
71138 +
71139 + currobj = chk_obj_label(dentry, mnt, curracl);
71140 + retval = currobj->mode & mode;
71141 +
71142 + /* if we're opening a specified transfer file for writing
71143 + (e.g. /dev/initctl), then transfer our role to init
71144 + */
71145 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71146 + current->role->roletype & GR_ROLE_PERSIST)) {
71147 + struct task_struct *task = init_pid_ns.child_reaper;
71148 +
71149 + if (task->role != current->role) {
71150 + struct acl_subject_label *subj;
71151 +
71152 + task->acl_sp_role = 0;
71153 + task->acl_role_id = current->acl_role_id;
71154 + task->role = current->role;
71155 + rcu_read_lock();
71156 + read_lock(&grsec_exec_file_lock);
71157 + subj = gr_get_subject_for_task(task, NULL);
71158 + gr_apply_subject_to_task(task, subj);
71159 + read_unlock(&grsec_exec_file_lock);
71160 + rcu_read_unlock();
71161 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71162 + }
71163 + }
71164 +
71165 + if (unlikely
71166 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71167 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71168 + __u32 new_mode = mode;
71169 +
71170 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71171 +
71172 + retval = new_mode;
71173 +
71174 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71175 + new_mode |= GR_INHERIT;
71176 +
71177 + if (!(mode & GR_NOLEARN))
71178 + gr_log_learn(dentry, mnt, new_mode);
71179 + }
71180 +
71181 + return retval;
71182 +}
71183 +
71184 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71185 + const struct dentry *parent,
71186 + const struct vfsmount *mnt)
71187 +{
71188 + struct name_entry *match;
71189 + struct acl_object_label *matchpo;
71190 + struct acl_subject_label *curracl;
71191 + char *path;
71192 +
71193 + if (unlikely(!(gr_status & GR_READY)))
71194 + return NULL;
71195 +
71196 + preempt_disable();
71197 + path = gr_to_filename_rbac(new_dentry, mnt);
71198 + match = lookup_name_entry_create(path);
71199 +
71200 + curracl = current->acl;
71201 +
71202 + if (match) {
71203 + read_lock(&gr_inode_lock);
71204 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71205 + read_unlock(&gr_inode_lock);
71206 +
71207 + if (matchpo) {
71208 + preempt_enable();
71209 + return matchpo;
71210 + }
71211 + }
71212 +
71213 + // lookup parent
71214 +
71215 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71216 +
71217 + preempt_enable();
71218 + return matchpo;
71219 +}
71220 +
71221 +__u32
71222 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71223 + const struct vfsmount * mnt, const __u32 mode)
71224 +{
71225 + struct acl_object_label *matchpo;
71226 + __u32 retval;
71227 +
71228 + if (unlikely(!(gr_status & GR_READY)))
71229 + return (mode & ~GR_AUDITS);
71230 +
71231 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
71232 +
71233 + retval = matchpo->mode & mode;
71234 +
71235 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71236 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71237 + __u32 new_mode = mode;
71238 +
71239 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71240 +
71241 + gr_log_learn(new_dentry, mnt, new_mode);
71242 + return new_mode;
71243 + }
71244 +
71245 + return retval;
71246 +}
71247 +
71248 +__u32
71249 +gr_check_link(const struct dentry * new_dentry,
71250 + const struct dentry * parent_dentry,
71251 + const struct vfsmount * parent_mnt,
71252 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71253 +{
71254 + struct acl_object_label *obj;
71255 + __u32 oldmode, newmode;
71256 + __u32 needmode;
71257 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71258 + GR_DELETE | GR_INHERIT;
71259 +
71260 + if (unlikely(!(gr_status & GR_READY)))
71261 + return (GR_CREATE | GR_LINK);
71262 +
71263 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71264 + oldmode = obj->mode;
71265 +
71266 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71267 + newmode = obj->mode;
71268 +
71269 + needmode = newmode & checkmodes;
71270 +
71271 + // old name for hardlink must have at least the permissions of the new name
71272 + if ((oldmode & needmode) != needmode)
71273 + goto bad;
71274 +
71275 + // if old name had restrictions/auditing, make sure the new name does as well
71276 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71277 +
71278 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71279 + if (is_privileged_binary(old_dentry))
71280 + needmode |= GR_SETID;
71281 +
71282 + if ((newmode & needmode) != needmode)
71283 + goto bad;
71284 +
71285 + // enforce minimum permissions
71286 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71287 + return newmode;
71288 +bad:
71289 + needmode = oldmode;
71290 + if (is_privileged_binary(old_dentry))
71291 + needmode |= GR_SETID;
71292 +
71293 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71294 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71295 + return (GR_CREATE | GR_LINK);
71296 + } else if (newmode & GR_SUPPRESS)
71297 + return GR_SUPPRESS;
71298 + else
71299 + return 0;
71300 +}
71301 +
71302 +int
71303 +gr_check_hidden_task(const struct task_struct *task)
71304 +{
71305 + if (unlikely(!(gr_status & GR_READY)))
71306 + return 0;
71307 +
71308 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71309 + return 1;
71310 +
71311 + return 0;
71312 +}
71313 +
71314 +int
71315 +gr_check_protected_task(const struct task_struct *task)
71316 +{
71317 + if (unlikely(!(gr_status & GR_READY) || !task))
71318 + return 0;
71319 +
71320 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71321 + task->acl != current->acl)
71322 + return 1;
71323 +
71324 + return 0;
71325 +}
71326 +
71327 +int
71328 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71329 +{
71330 + struct task_struct *p;
71331 + int ret = 0;
71332 +
71333 + if (unlikely(!(gr_status & GR_READY) || !pid))
71334 + return ret;
71335 +
71336 + read_lock(&tasklist_lock);
71337 + do_each_pid_task(pid, type, p) {
71338 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71339 + p->acl != current->acl) {
71340 + ret = 1;
71341 + goto out;
71342 + }
71343 + } while_each_pid_task(pid, type, p);
71344 +out:
71345 + read_unlock(&tasklist_lock);
71346 +
71347 + return ret;
71348 +}
71349 +
71350 +void
71351 +gr_copy_label(struct task_struct *tsk)
71352 +{
71353 + struct task_struct *p = current;
71354 +
71355 + tsk->inherited = p->inherited;
71356 + tsk->acl_sp_role = 0;
71357 + tsk->acl_role_id = p->acl_role_id;
71358 + tsk->acl = p->acl;
71359 + tsk->role = p->role;
71360 + tsk->signal->used_accept = 0;
71361 + tsk->signal->curr_ip = p->signal->curr_ip;
71362 + tsk->signal->saved_ip = p->signal->saved_ip;
71363 + if (p->exec_file)
71364 + get_file(p->exec_file);
71365 + tsk->exec_file = p->exec_file;
71366 + tsk->is_writable = p->is_writable;
71367 + if (unlikely(p->signal->used_accept)) {
71368 + p->signal->curr_ip = 0;
71369 + p->signal->saved_ip = 0;
71370 + }
71371 +
71372 + return;
71373 +}
71374 +
71375 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71376 +
71377 +int
71378 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71379 +{
71380 + unsigned int i;
71381 + __u16 num;
71382 + uid_t *uidlist;
71383 + uid_t curuid;
71384 + int realok = 0;
71385 + int effectiveok = 0;
71386 + int fsok = 0;
71387 + uid_t globalreal, globaleffective, globalfs;
71388 +
71389 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71390 + struct user_struct *user;
71391 +
71392 + if (!uid_valid(real))
71393 + goto skipit;
71394 +
71395 + /* find user based on global namespace */
71396 +
71397 + globalreal = GR_GLOBAL_UID(real);
71398 +
71399 + user = find_user(make_kuid(&init_user_ns, globalreal));
71400 + if (user == NULL)
71401 + goto skipit;
71402 +
71403 + if (gr_process_kernel_setuid_ban(user)) {
71404 + /* for find_user */
71405 + free_uid(user);
71406 + return 1;
71407 + }
71408 +
71409 + /* for find_user */
71410 + free_uid(user);
71411 +
71412 +skipit:
71413 +#endif
71414 +
71415 + if (unlikely(!(gr_status & GR_READY)))
71416 + return 0;
71417 +
71418 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71419 + gr_log_learn_uid_change(real, effective, fs);
71420 +
71421 + num = current->acl->user_trans_num;
71422 + uidlist = current->acl->user_transitions;
71423 +
71424 + if (uidlist == NULL)
71425 + return 0;
71426 +
71427 + if (!uid_valid(real)) {
71428 + realok = 1;
71429 + globalreal = (uid_t)-1;
71430 + } else {
71431 + globalreal = GR_GLOBAL_UID(real);
71432 + }
71433 + if (!uid_valid(effective)) {
71434 + effectiveok = 1;
71435 + globaleffective = (uid_t)-1;
71436 + } else {
71437 + globaleffective = GR_GLOBAL_UID(effective);
71438 + }
71439 + if (!uid_valid(fs)) {
71440 + fsok = 1;
71441 + globalfs = (uid_t)-1;
71442 + } else {
71443 + globalfs = GR_GLOBAL_UID(fs);
71444 + }
71445 +
71446 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71447 + for (i = 0; i < num; i++) {
71448 + curuid = uidlist[i];
71449 + if (globalreal == curuid)
71450 + realok = 1;
71451 + if (globaleffective == curuid)
71452 + effectiveok = 1;
71453 + if (globalfs == curuid)
71454 + fsok = 1;
71455 + }
71456 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71457 + for (i = 0; i < num; i++) {
71458 + curuid = uidlist[i];
71459 + if (globalreal == curuid)
71460 + break;
71461 + if (globaleffective == curuid)
71462 + break;
71463 + if (globalfs == curuid)
71464 + break;
71465 + }
71466 + /* not in deny list */
71467 + if (i == num) {
71468 + realok = 1;
71469 + effectiveok = 1;
71470 + fsok = 1;
71471 + }
71472 + }
71473 +
71474 + if (realok && effectiveok && fsok)
71475 + return 0;
71476 + else {
71477 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71478 + return 1;
71479 + }
71480 +}
71481 +
71482 +int
71483 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71484 +{
71485 + unsigned int i;
71486 + __u16 num;
71487 + gid_t *gidlist;
71488 + gid_t curgid;
71489 + int realok = 0;
71490 + int effectiveok = 0;
71491 + int fsok = 0;
71492 + gid_t globalreal, globaleffective, globalfs;
71493 +
71494 + if (unlikely(!(gr_status & GR_READY)))
71495 + return 0;
71496 +
71497 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71498 + gr_log_learn_gid_change(real, effective, fs);
71499 +
71500 + num = current->acl->group_trans_num;
71501 + gidlist = current->acl->group_transitions;
71502 +
71503 + if (gidlist == NULL)
71504 + return 0;
71505 +
71506 + if (!gid_valid(real)) {
71507 + realok = 1;
71508 + globalreal = (gid_t)-1;
71509 + } else {
71510 + globalreal = GR_GLOBAL_GID(real);
71511 + }
71512 + if (!gid_valid(effective)) {
71513 + effectiveok = 1;
71514 + globaleffective = (gid_t)-1;
71515 + } else {
71516 + globaleffective = GR_GLOBAL_GID(effective);
71517 + }
71518 + if (!gid_valid(fs)) {
71519 + fsok = 1;
71520 + globalfs = (gid_t)-1;
71521 + } else {
71522 + globalfs = GR_GLOBAL_GID(fs);
71523 + }
71524 +
71525 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71526 + for (i = 0; i < num; i++) {
71527 + curgid = gidlist[i];
71528 + if (globalreal == curgid)
71529 + realok = 1;
71530 + if (globaleffective == curgid)
71531 + effectiveok = 1;
71532 + if (globalfs == curgid)
71533 + fsok = 1;
71534 + }
71535 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71536 + for (i = 0; i < num; i++) {
71537 + curgid = gidlist[i];
71538 + if (globalreal == curgid)
71539 + break;
71540 + if (globaleffective == curgid)
71541 + break;
71542 + if (globalfs == curgid)
71543 + break;
71544 + }
71545 + /* not in deny list */
71546 + if (i == num) {
71547 + realok = 1;
71548 + effectiveok = 1;
71549 + fsok = 1;
71550 + }
71551 + }
71552 +
71553 + if (realok && effectiveok && fsok)
71554 + return 0;
71555 + else {
71556 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71557 + return 1;
71558 + }
71559 +}
71560 +
71561 +extern int gr_acl_is_capable(const int cap);
71562 +
71563 +void
71564 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71565 +{
71566 + struct acl_role_label *role = task->role;
71567 + struct acl_subject_label *subj = NULL;
71568 + struct acl_object_label *obj;
71569 + struct file *filp;
71570 + uid_t uid;
71571 + gid_t gid;
71572 +
71573 + if (unlikely(!(gr_status & GR_READY)))
71574 + return;
71575 +
71576 + uid = GR_GLOBAL_UID(kuid);
71577 + gid = GR_GLOBAL_GID(kgid);
71578 +
71579 + filp = task->exec_file;
71580 +
71581 + /* kernel process, we'll give them the kernel role */
71582 + if (unlikely(!filp)) {
71583 + task->role = running_polstate.kernel_role;
71584 + task->acl = running_polstate.kernel_role->root_label;
71585 + return;
71586 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71587 + /* save the current ip at time of role lookup so that the proper
71588 + IP will be learned for role_allowed_ip */
71589 + task->signal->saved_ip = task->signal->curr_ip;
71590 + role = lookup_acl_role_label(task, uid, gid);
71591 + }
71592 +
71593 + /* don't change the role if we're not a privileged process */
71594 + if (role && task->role != role &&
71595 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71596 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71597 + return;
71598 +
71599 + /* perform subject lookup in possibly new role
71600 + we can use this result below in the case where role == task->role
71601 + */
71602 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71603 +
71604 + /* if we changed uid/gid, but result in the same role
71605 + and are using inheritance, don't lose the inherited subject
71606 + if current subject is other than what normal lookup
71607 + would result in, we arrived via inheritance, don't
71608 + lose subject
71609 + */
71610 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71611 + (subj == task->acl)))
71612 + task->acl = subj;
71613 +
71614 + /* leave task->inherited unaffected */
71615 +
71616 + task->role = role;
71617 +
71618 + task->is_writable = 0;
71619 +
71620 + /* ignore additional mmap checks for processes that are writable
71621 + by the default ACL */
71622 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71623 + if (unlikely(obj->mode & GR_WRITE))
71624 + task->is_writable = 1;
71625 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71626 + if (unlikely(obj->mode & GR_WRITE))
71627 + task->is_writable = 1;
71628 +
71629 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71630 + 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);
71631 +#endif
71632 +
71633 + gr_set_proc_res(task);
71634 +
71635 + return;
71636 +}
71637 +
71638 +int
71639 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71640 + const int unsafe_flags)
71641 +{
71642 + struct task_struct *task = current;
71643 + struct acl_subject_label *newacl;
71644 + struct acl_object_label *obj;
71645 + __u32 retmode;
71646 +
71647 + if (unlikely(!(gr_status & GR_READY)))
71648 + return 0;
71649 +
71650 + newacl = chk_subj_label(dentry, mnt, task->role);
71651 +
71652 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71653 + did an exec
71654 + */
71655 + rcu_read_lock();
71656 + read_lock(&tasklist_lock);
71657 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71658 + (task->parent->acl->mode & GR_POVERRIDE))) {
71659 + read_unlock(&tasklist_lock);
71660 + rcu_read_unlock();
71661 + goto skip_check;
71662 + }
71663 + read_unlock(&tasklist_lock);
71664 + rcu_read_unlock();
71665 +
71666 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71667 + !(task->role->roletype & GR_ROLE_GOD) &&
71668 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71669 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71670 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71671 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71672 + else
71673 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71674 + return -EACCES;
71675 + }
71676 +
71677 +skip_check:
71678 +
71679 + obj = chk_obj_label(dentry, mnt, task->acl);
71680 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71681 +
71682 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71683 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71684 + if (obj->nested)
71685 + task->acl = obj->nested;
71686 + else
71687 + task->acl = newacl;
71688 + task->inherited = 0;
71689 + } else {
71690 + task->inherited = 1;
71691 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71692 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71693 + }
71694 +
71695 + task->is_writable = 0;
71696 +
71697 + /* ignore additional mmap checks for processes that are writable
71698 + by the default ACL */
71699 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71700 + if (unlikely(obj->mode & GR_WRITE))
71701 + task->is_writable = 1;
71702 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71703 + if (unlikely(obj->mode & GR_WRITE))
71704 + task->is_writable = 1;
71705 +
71706 + gr_set_proc_res(task);
71707 +
71708 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71709 + 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);
71710 +#endif
71711 + return 0;
71712 +}
71713 +
71714 +/* always called with valid inodev ptr */
71715 +static void
71716 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71717 +{
71718 + struct acl_object_label *matchpo;
71719 + struct acl_subject_label *matchps;
71720 + struct acl_subject_label *subj;
71721 + struct acl_role_label *role;
71722 + unsigned int x;
71723 +
71724 + FOR_EACH_ROLE_START(role)
71725 + FOR_EACH_SUBJECT_START(role, subj, x)
71726 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71727 + matchpo->mode |= GR_DELETED;
71728 + FOR_EACH_SUBJECT_END(subj,x)
71729 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71730 + /* nested subjects aren't in the role's subj_hash table */
71731 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71732 + matchpo->mode |= GR_DELETED;
71733 + FOR_EACH_NESTED_SUBJECT_END(subj)
71734 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71735 + matchps->mode |= GR_DELETED;
71736 + FOR_EACH_ROLE_END(role)
71737 +
71738 + inodev->nentry->deleted = 1;
71739 +
71740 + return;
71741 +}
71742 +
71743 +void
71744 +gr_handle_delete(const ino_t ino, const dev_t dev)
71745 +{
71746 + struct inodev_entry *inodev;
71747 +
71748 + if (unlikely(!(gr_status & GR_READY)))
71749 + return;
71750 +
71751 + write_lock(&gr_inode_lock);
71752 + inodev = lookup_inodev_entry(ino, dev);
71753 + if (inodev != NULL)
71754 + do_handle_delete(inodev, ino, dev);
71755 + write_unlock(&gr_inode_lock);
71756 +
71757 + return;
71758 +}
71759 +
71760 +static void
71761 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71762 + const ino_t newinode, const dev_t newdevice,
71763 + struct acl_subject_label *subj)
71764 +{
71765 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71766 + struct acl_object_label *match;
71767 +
71768 + match = subj->obj_hash[index];
71769 +
71770 + while (match && (match->inode != oldinode ||
71771 + match->device != olddevice ||
71772 + !(match->mode & GR_DELETED)))
71773 + match = match->next;
71774 +
71775 + if (match && (match->inode == oldinode)
71776 + && (match->device == olddevice)
71777 + && (match->mode & GR_DELETED)) {
71778 + if (match->prev == NULL) {
71779 + subj->obj_hash[index] = match->next;
71780 + if (match->next != NULL)
71781 + match->next->prev = NULL;
71782 + } else {
71783 + match->prev->next = match->next;
71784 + if (match->next != NULL)
71785 + match->next->prev = match->prev;
71786 + }
71787 + match->prev = NULL;
71788 + match->next = NULL;
71789 + match->inode = newinode;
71790 + match->device = newdevice;
71791 + match->mode &= ~GR_DELETED;
71792 +
71793 + insert_acl_obj_label(match, subj);
71794 + }
71795 +
71796 + return;
71797 +}
71798 +
71799 +static void
71800 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71801 + const ino_t newinode, const dev_t newdevice,
71802 + struct acl_role_label *role)
71803 +{
71804 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71805 + struct acl_subject_label *match;
71806 +
71807 + match = role->subj_hash[index];
71808 +
71809 + while (match && (match->inode != oldinode ||
71810 + match->device != olddevice ||
71811 + !(match->mode & GR_DELETED)))
71812 + match = match->next;
71813 +
71814 + if (match && (match->inode == oldinode)
71815 + && (match->device == olddevice)
71816 + && (match->mode & GR_DELETED)) {
71817 + if (match->prev == NULL) {
71818 + role->subj_hash[index] = match->next;
71819 + if (match->next != NULL)
71820 + match->next->prev = NULL;
71821 + } else {
71822 + match->prev->next = match->next;
71823 + if (match->next != NULL)
71824 + match->next->prev = match->prev;
71825 + }
71826 + match->prev = NULL;
71827 + match->next = NULL;
71828 + match->inode = newinode;
71829 + match->device = newdevice;
71830 + match->mode &= ~GR_DELETED;
71831 +
71832 + insert_acl_subj_label(match, role);
71833 + }
71834 +
71835 + return;
71836 +}
71837 +
71838 +static void
71839 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71840 + const ino_t newinode, const dev_t newdevice)
71841 +{
71842 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71843 + struct inodev_entry *match;
71844 +
71845 + match = running_polstate.inodev_set.i_hash[index];
71846 +
71847 + while (match && (match->nentry->inode != oldinode ||
71848 + match->nentry->device != olddevice || !match->nentry->deleted))
71849 + match = match->next;
71850 +
71851 + if (match && (match->nentry->inode == oldinode)
71852 + && (match->nentry->device == olddevice) &&
71853 + match->nentry->deleted) {
71854 + if (match->prev == NULL) {
71855 + running_polstate.inodev_set.i_hash[index] = match->next;
71856 + if (match->next != NULL)
71857 + match->next->prev = NULL;
71858 + } else {
71859 + match->prev->next = match->next;
71860 + if (match->next != NULL)
71861 + match->next->prev = match->prev;
71862 + }
71863 + match->prev = NULL;
71864 + match->next = NULL;
71865 + match->nentry->inode = newinode;
71866 + match->nentry->device = newdevice;
71867 + match->nentry->deleted = 0;
71868 +
71869 + insert_inodev_entry(match);
71870 + }
71871 +
71872 + return;
71873 +}
71874 +
71875 +static void
71876 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71877 +{
71878 + struct acl_subject_label *subj;
71879 + struct acl_role_label *role;
71880 + unsigned int x;
71881 +
71882 + FOR_EACH_ROLE_START(role)
71883 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71884 +
71885 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71886 + if ((subj->inode == ino) && (subj->device == dev)) {
71887 + subj->inode = ino;
71888 + subj->device = dev;
71889 + }
71890 + /* nested subjects aren't in the role's subj_hash table */
71891 + update_acl_obj_label(matchn->inode, matchn->device,
71892 + ino, dev, subj);
71893 + FOR_EACH_NESTED_SUBJECT_END(subj)
71894 + FOR_EACH_SUBJECT_START(role, subj, x)
71895 + update_acl_obj_label(matchn->inode, matchn->device,
71896 + ino, dev, subj);
71897 + FOR_EACH_SUBJECT_END(subj,x)
71898 + FOR_EACH_ROLE_END(role)
71899 +
71900 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71901 +
71902 + return;
71903 +}
71904 +
71905 +static void
71906 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71907 + const struct vfsmount *mnt)
71908 +{
71909 + ino_t ino = dentry->d_inode->i_ino;
71910 + dev_t dev = __get_dev(dentry);
71911 +
71912 + __do_handle_create(matchn, ino, dev);
71913 +
71914 + return;
71915 +}
71916 +
71917 +void
71918 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71919 +{
71920 + struct name_entry *matchn;
71921 +
71922 + if (unlikely(!(gr_status & GR_READY)))
71923 + return;
71924 +
71925 + preempt_disable();
71926 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71927 +
71928 + if (unlikely((unsigned long)matchn)) {
71929 + write_lock(&gr_inode_lock);
71930 + do_handle_create(matchn, dentry, mnt);
71931 + write_unlock(&gr_inode_lock);
71932 + }
71933 + preempt_enable();
71934 +
71935 + return;
71936 +}
71937 +
71938 +void
71939 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71940 +{
71941 + struct name_entry *matchn;
71942 +
71943 + if (unlikely(!(gr_status & GR_READY)))
71944 + return;
71945 +
71946 + preempt_disable();
71947 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71948 +
71949 + if (unlikely((unsigned long)matchn)) {
71950 + write_lock(&gr_inode_lock);
71951 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71952 + write_unlock(&gr_inode_lock);
71953 + }
71954 + preempt_enable();
71955 +
71956 + return;
71957 +}
71958 +
71959 +void
71960 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71961 + struct dentry *old_dentry,
71962 + struct dentry *new_dentry,
71963 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71964 +{
71965 + struct name_entry *matchn;
71966 + struct name_entry *matchn2 = NULL;
71967 + struct inodev_entry *inodev;
71968 + struct inode *inode = new_dentry->d_inode;
71969 + ino_t old_ino = old_dentry->d_inode->i_ino;
71970 + dev_t old_dev = __get_dev(old_dentry);
71971 + unsigned int exchange = flags & RENAME_EXCHANGE;
71972 +
71973 + /* vfs_rename swaps the name and parent link for old_dentry and
71974 + new_dentry
71975 + at this point, old_dentry has the new name, parent link, and inode
71976 + for the renamed file
71977 + if a file is being replaced by a rename, new_dentry has the inode
71978 + and name for the replaced file
71979 + */
71980 +
71981 + if (unlikely(!(gr_status & GR_READY)))
71982 + return;
71983 +
71984 + preempt_disable();
71985 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71986 +
71987 + /* exchange cases:
71988 + a filename exists for the source, but not dest
71989 + do a recreate on source
71990 + a filename exists for the dest, but not source
71991 + do a recreate on dest
71992 + a filename exists for both source and dest
71993 + delete source and dest, then create source and dest
71994 + a filename exists for neither source nor dest
71995 + no updates needed
71996 +
71997 + the name entry lookups get us the old inode/dev associated with
71998 + each name, so do the deletes first (if possible) so that when
71999 + we do the create, we pick up on the right entries
72000 + */
72001 +
72002 + if (exchange)
72003 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
72004 +
72005 + /* we wouldn't have to check d_inode if it weren't for
72006 + NFS silly-renaming
72007 + */
72008 +
72009 + write_lock(&gr_inode_lock);
72010 + if (unlikely((replace || exchange) && inode)) {
72011 + ino_t new_ino = inode->i_ino;
72012 + dev_t new_dev = __get_dev(new_dentry);
72013 +
72014 + inodev = lookup_inodev_entry(new_ino, new_dev);
72015 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
72016 + do_handle_delete(inodev, new_ino, new_dev);
72017 + }
72018 +
72019 + inodev = lookup_inodev_entry(old_ino, old_dev);
72020 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
72021 + do_handle_delete(inodev, old_ino, old_dev);
72022 +
72023 + if (unlikely(matchn != NULL))
72024 + do_handle_create(matchn, old_dentry, mnt);
72025 +
72026 + if (unlikely(matchn2 != NULL))
72027 + do_handle_create(matchn2, new_dentry, mnt);
72028 +
72029 + write_unlock(&gr_inode_lock);
72030 + preempt_enable();
72031 +
72032 + return;
72033 +}
72034 +
72035 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
72036 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
72037 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
72038 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
72039 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
72040 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
72041 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
72042 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
72043 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
72044 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
72045 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
72046 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
72047 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
72048 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
72049 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
72050 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
72051 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
72052 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
72053 +};
72054 +
72055 +void
72056 +gr_learn_resource(const struct task_struct *task,
72057 + const int res, const unsigned long wanted, const int gt)
72058 +{
72059 + struct acl_subject_label *acl;
72060 + const struct cred *cred;
72061 +
72062 + if (unlikely((gr_status & GR_READY) &&
72063 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
72064 + goto skip_reslog;
72065 +
72066 + gr_log_resource(task, res, wanted, gt);
72067 +skip_reslog:
72068 +
72069 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
72070 + return;
72071 +
72072 + acl = task->acl;
72073 +
72074 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
72075 + !(acl->resmask & (1U << (unsigned short) res))))
72076 + return;
72077 +
72078 + if (wanted >= acl->res[res].rlim_cur) {
72079 + unsigned long res_add;
72080 +
72081 + res_add = wanted + res_learn_bumps[res];
72082 +
72083 + acl->res[res].rlim_cur = res_add;
72084 +
72085 + if (wanted > acl->res[res].rlim_max)
72086 + acl->res[res].rlim_max = res_add;
72087 +
72088 + /* only log the subject filename, since resource logging is supported for
72089 + single-subject learning only */
72090 + rcu_read_lock();
72091 + cred = __task_cred(task);
72092 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72093 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
72094 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
72095 + "", (unsigned long) res, &task->signal->saved_ip);
72096 + rcu_read_unlock();
72097 + }
72098 +
72099 + return;
72100 +}
72101 +EXPORT_SYMBOL_GPL(gr_learn_resource);
72102 +#endif
72103 +
72104 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
72105 +void
72106 +pax_set_initial_flags(struct linux_binprm *bprm)
72107 +{
72108 + struct task_struct *task = current;
72109 + struct acl_subject_label *proc;
72110 + unsigned long flags;
72111 +
72112 + if (unlikely(!(gr_status & GR_READY)))
72113 + return;
72114 +
72115 + flags = pax_get_flags(task);
72116 +
72117 + proc = task->acl;
72118 +
72119 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
72120 + flags &= ~MF_PAX_PAGEEXEC;
72121 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
72122 + flags &= ~MF_PAX_SEGMEXEC;
72123 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
72124 + flags &= ~MF_PAX_RANDMMAP;
72125 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
72126 + flags &= ~MF_PAX_EMUTRAMP;
72127 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
72128 + flags &= ~MF_PAX_MPROTECT;
72129 +
72130 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72131 + flags |= MF_PAX_PAGEEXEC;
72132 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72133 + flags |= MF_PAX_SEGMEXEC;
72134 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72135 + flags |= MF_PAX_RANDMMAP;
72136 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72137 + flags |= MF_PAX_EMUTRAMP;
72138 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72139 + flags |= MF_PAX_MPROTECT;
72140 +
72141 + pax_set_flags(task, flags);
72142 +
72143 + return;
72144 +}
72145 +#endif
72146 +
72147 +int
72148 +gr_handle_proc_ptrace(struct task_struct *task)
72149 +{
72150 + struct file *filp;
72151 + struct task_struct *tmp = task;
72152 + struct task_struct *curtemp = current;
72153 + __u32 retmode;
72154 +
72155 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72156 + if (unlikely(!(gr_status & GR_READY)))
72157 + return 0;
72158 +#endif
72159 +
72160 + read_lock(&tasklist_lock);
72161 + read_lock(&grsec_exec_file_lock);
72162 + filp = task->exec_file;
72163 +
72164 + while (task_pid_nr(tmp) > 0) {
72165 + if (tmp == curtemp)
72166 + break;
72167 + tmp = tmp->real_parent;
72168 + }
72169 +
72170 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72171 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72172 + read_unlock(&grsec_exec_file_lock);
72173 + read_unlock(&tasklist_lock);
72174 + return 1;
72175 + }
72176 +
72177 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72178 + if (!(gr_status & GR_READY)) {
72179 + read_unlock(&grsec_exec_file_lock);
72180 + read_unlock(&tasklist_lock);
72181 + return 0;
72182 + }
72183 +#endif
72184 +
72185 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72186 + read_unlock(&grsec_exec_file_lock);
72187 + read_unlock(&tasklist_lock);
72188 +
72189 + if (retmode & GR_NOPTRACE)
72190 + return 1;
72191 +
72192 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72193 + && (current->acl != task->acl || (current->acl != current->role->root_label
72194 + && task_pid_nr(current) != task_pid_nr(task))))
72195 + return 1;
72196 +
72197 + return 0;
72198 +}
72199 +
72200 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72201 +{
72202 + if (unlikely(!(gr_status & GR_READY)))
72203 + return;
72204 +
72205 + if (!(current->role->roletype & GR_ROLE_GOD))
72206 + return;
72207 +
72208 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72209 + p->role->rolename, gr_task_roletype_to_char(p),
72210 + p->acl->filename);
72211 +}
72212 +
72213 +int
72214 +gr_handle_ptrace(struct task_struct *task, const long request)
72215 +{
72216 + struct task_struct *tmp = task;
72217 + struct task_struct *curtemp = current;
72218 + __u32 retmode;
72219 +
72220 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72221 + if (unlikely(!(gr_status & GR_READY)))
72222 + return 0;
72223 +#endif
72224 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72225 + read_lock(&tasklist_lock);
72226 + while (task_pid_nr(tmp) > 0) {
72227 + if (tmp == curtemp)
72228 + break;
72229 + tmp = tmp->real_parent;
72230 + }
72231 +
72232 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72233 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72234 + read_unlock(&tasklist_lock);
72235 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72236 + return 1;
72237 + }
72238 + read_unlock(&tasklist_lock);
72239 + }
72240 +
72241 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72242 + if (!(gr_status & GR_READY))
72243 + return 0;
72244 +#endif
72245 +
72246 + read_lock(&grsec_exec_file_lock);
72247 + if (unlikely(!task->exec_file)) {
72248 + read_unlock(&grsec_exec_file_lock);
72249 + return 0;
72250 + }
72251 +
72252 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72253 + read_unlock(&grsec_exec_file_lock);
72254 +
72255 + if (retmode & GR_NOPTRACE) {
72256 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72257 + return 1;
72258 + }
72259 +
72260 + if (retmode & GR_PTRACERD) {
72261 + switch (request) {
72262 + case PTRACE_SEIZE:
72263 + case PTRACE_POKETEXT:
72264 + case PTRACE_POKEDATA:
72265 + case PTRACE_POKEUSR:
72266 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72267 + case PTRACE_SETREGS:
72268 + case PTRACE_SETFPREGS:
72269 +#endif
72270 +#ifdef CONFIG_X86
72271 + case PTRACE_SETFPXREGS:
72272 +#endif
72273 +#ifdef CONFIG_ALTIVEC
72274 + case PTRACE_SETVRREGS:
72275 +#endif
72276 + return 1;
72277 + default:
72278 + return 0;
72279 + }
72280 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72281 + !(current->role->roletype & GR_ROLE_GOD) &&
72282 + (current->acl != task->acl)) {
72283 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72284 + return 1;
72285 + }
72286 +
72287 + return 0;
72288 +}
72289 +
72290 +static int is_writable_mmap(const struct file *filp)
72291 +{
72292 + struct task_struct *task = current;
72293 + struct acl_object_label *obj, *obj2;
72294 +
72295 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72296 + !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))) {
72297 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72298 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72299 + task->role->root_label);
72300 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72301 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72302 + return 1;
72303 + }
72304 + }
72305 + return 0;
72306 +}
72307 +
72308 +int
72309 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72310 +{
72311 + __u32 mode;
72312 +
72313 + if (unlikely(!file || !(prot & PROT_EXEC)))
72314 + return 1;
72315 +
72316 + if (is_writable_mmap(file))
72317 + return 0;
72318 +
72319 + mode =
72320 + gr_search_file(file->f_path.dentry,
72321 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72322 + file->f_path.mnt);
72323 +
72324 + if (!gr_tpe_allow(file))
72325 + return 0;
72326 +
72327 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72328 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72329 + return 0;
72330 + } else if (unlikely(!(mode & GR_EXEC))) {
72331 + return 0;
72332 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72333 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72334 + return 1;
72335 + }
72336 +
72337 + return 1;
72338 +}
72339 +
72340 +int
72341 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72342 +{
72343 + __u32 mode;
72344 +
72345 + if (unlikely(!file || !(prot & PROT_EXEC)))
72346 + return 1;
72347 +
72348 + if (is_writable_mmap(file))
72349 + return 0;
72350 +
72351 + mode =
72352 + gr_search_file(file->f_path.dentry,
72353 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72354 + file->f_path.mnt);
72355 +
72356 + if (!gr_tpe_allow(file))
72357 + return 0;
72358 +
72359 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72360 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72361 + return 0;
72362 + } else if (unlikely(!(mode & GR_EXEC))) {
72363 + return 0;
72364 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72365 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72366 + return 1;
72367 + }
72368 +
72369 + return 1;
72370 +}
72371 +
72372 +void
72373 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72374 +{
72375 + unsigned long runtime, cputime;
72376 + cputime_t utime, stime;
72377 + unsigned int wday, cday;
72378 + __u8 whr, chr;
72379 + __u8 wmin, cmin;
72380 + __u8 wsec, csec;
72381 + struct timespec curtime, starttime;
72382 +
72383 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72384 + !(task->acl->mode & GR_PROCACCT)))
72385 + return;
72386 +
72387 + curtime = ns_to_timespec(ktime_get_ns());
72388 + starttime = ns_to_timespec(task->start_time);
72389 + runtime = curtime.tv_sec - starttime.tv_sec;
72390 + wday = runtime / (60 * 60 * 24);
72391 + runtime -= wday * (60 * 60 * 24);
72392 + whr = runtime / (60 * 60);
72393 + runtime -= whr * (60 * 60);
72394 + wmin = runtime / 60;
72395 + runtime -= wmin * 60;
72396 + wsec = runtime;
72397 +
72398 + task_cputime(task, &utime, &stime);
72399 + cputime = cputime_to_secs(utime + stime);
72400 + cday = cputime / (60 * 60 * 24);
72401 + cputime -= cday * (60 * 60 * 24);
72402 + chr = cputime / (60 * 60);
72403 + cputime -= chr * (60 * 60);
72404 + cmin = cputime / 60;
72405 + cputime -= cmin * 60;
72406 + csec = cputime;
72407 +
72408 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72409 +
72410 + return;
72411 +}
72412 +
72413 +#ifdef CONFIG_TASKSTATS
72414 +int gr_is_taskstats_denied(int pid)
72415 +{
72416 + struct task_struct *task;
72417 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72418 + const struct cred *cred;
72419 +#endif
72420 + int ret = 0;
72421 +
72422 + /* restrict taskstats viewing to un-chrooted root users
72423 + who have the 'view' subject flag if the RBAC system is enabled
72424 + */
72425 +
72426 + rcu_read_lock();
72427 + read_lock(&tasklist_lock);
72428 + task = find_task_by_vpid(pid);
72429 + if (task) {
72430 +#ifdef CONFIG_GRKERNSEC_CHROOT
72431 + if (proc_is_chrooted(task))
72432 + ret = -EACCES;
72433 +#endif
72434 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72435 + cred = __task_cred(task);
72436 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72437 + if (gr_is_global_nonroot(cred->uid))
72438 + ret = -EACCES;
72439 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72440 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72441 + ret = -EACCES;
72442 +#endif
72443 +#endif
72444 + if (gr_status & GR_READY) {
72445 + if (!(task->acl->mode & GR_VIEW))
72446 + ret = -EACCES;
72447 + }
72448 + } else
72449 + ret = -ENOENT;
72450 +
72451 + read_unlock(&tasklist_lock);
72452 + rcu_read_unlock();
72453 +
72454 + return ret;
72455 +}
72456 +#endif
72457 +
72458 +/* AUXV entries are filled via a descendant of search_binary_handler
72459 + after we've already applied the subject for the target
72460 +*/
72461 +int gr_acl_enable_at_secure(void)
72462 +{
72463 + if (unlikely(!(gr_status & GR_READY)))
72464 + return 0;
72465 +
72466 + if (current->acl->mode & GR_ATSECURE)
72467 + return 1;
72468 +
72469 + return 0;
72470 +}
72471 +
72472 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72473 +{
72474 + struct task_struct *task = current;
72475 + struct dentry *dentry = file->f_path.dentry;
72476 + struct vfsmount *mnt = file->f_path.mnt;
72477 + struct acl_object_label *obj, *tmp;
72478 + struct acl_subject_label *subj;
72479 + unsigned int bufsize;
72480 + int is_not_root;
72481 + char *path;
72482 + dev_t dev = __get_dev(dentry);
72483 +
72484 + if (unlikely(!(gr_status & GR_READY)))
72485 + return 1;
72486 +
72487 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72488 + return 1;
72489 +
72490 + /* ignore Eric Biederman */
72491 + if (IS_PRIVATE(dentry->d_inode))
72492 + return 1;
72493 +
72494 + subj = task->acl;
72495 + read_lock(&gr_inode_lock);
72496 + do {
72497 + obj = lookup_acl_obj_label(ino, dev, subj);
72498 + if (obj != NULL) {
72499 + read_unlock(&gr_inode_lock);
72500 + return (obj->mode & GR_FIND) ? 1 : 0;
72501 + }
72502 + } while ((subj = subj->parent_subject));
72503 + read_unlock(&gr_inode_lock);
72504 +
72505 + /* this is purely an optimization since we're looking for an object
72506 + for the directory we're doing a readdir on
72507 + if it's possible for any globbed object to match the entry we're
72508 + filling into the directory, then the object we find here will be
72509 + an anchor point with attached globbed objects
72510 + */
72511 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72512 + if (obj->globbed == NULL)
72513 + return (obj->mode & GR_FIND) ? 1 : 0;
72514 +
72515 + is_not_root = ((obj->filename[0] == '/') &&
72516 + (obj->filename[1] == '\0')) ? 0 : 1;
72517 + bufsize = PAGE_SIZE - namelen - is_not_root;
72518 +
72519 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72520 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72521 + return 1;
72522 +
72523 + preempt_disable();
72524 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72525 + bufsize);
72526 +
72527 + bufsize = strlen(path);
72528 +
72529 + /* if base is "/", don't append an additional slash */
72530 + if (is_not_root)
72531 + *(path + bufsize) = '/';
72532 + memcpy(path + bufsize + is_not_root, name, namelen);
72533 + *(path + bufsize + namelen + is_not_root) = '\0';
72534 +
72535 + tmp = obj->globbed;
72536 + while (tmp) {
72537 + if (!glob_match(tmp->filename, path)) {
72538 + preempt_enable();
72539 + return (tmp->mode & GR_FIND) ? 1 : 0;
72540 + }
72541 + tmp = tmp->next;
72542 + }
72543 + preempt_enable();
72544 + return (obj->mode & GR_FIND) ? 1 : 0;
72545 +}
72546 +
72547 +void gr_put_exec_file(struct task_struct *task)
72548 +{
72549 + struct file *filp;
72550 +
72551 + write_lock(&grsec_exec_file_lock);
72552 + filp = task->exec_file;
72553 + task->exec_file = NULL;
72554 + write_unlock(&grsec_exec_file_lock);
72555 +
72556 + if (filp)
72557 + fput(filp);
72558 +
72559 + return;
72560 +}
72561 +
72562 +
72563 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72564 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72565 +#endif
72566 +#ifdef CONFIG_SECURITY
72567 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72568 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72569 +#endif
72570 +
72571 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72572 new file mode 100644
72573 index 0000000..18ffbbd
72574 --- /dev/null
72575 +++ b/grsecurity/gracl_alloc.c
72576 @@ -0,0 +1,105 @@
72577 +#include <linux/kernel.h>
72578 +#include <linux/mm.h>
72579 +#include <linux/slab.h>
72580 +#include <linux/vmalloc.h>
72581 +#include <linux/gracl.h>
72582 +#include <linux/grsecurity.h>
72583 +
72584 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72585 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72586 +
72587 +static __inline__ int
72588 +alloc_pop(void)
72589 +{
72590 + if (current_alloc_state->alloc_stack_next == 1)
72591 + return 0;
72592 +
72593 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72594 +
72595 + current_alloc_state->alloc_stack_next--;
72596 +
72597 + return 1;
72598 +}
72599 +
72600 +static __inline__ int
72601 +alloc_push(void *buf)
72602 +{
72603 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72604 + return 1;
72605 +
72606 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72607 +
72608 + current_alloc_state->alloc_stack_next++;
72609 +
72610 + return 0;
72611 +}
72612 +
72613 +void *
72614 +acl_alloc(unsigned long len)
72615 +{
72616 + void *ret = NULL;
72617 +
72618 + if (!len || len > PAGE_SIZE)
72619 + goto out;
72620 +
72621 + ret = kmalloc(len, GFP_KERNEL);
72622 +
72623 + if (ret) {
72624 + if (alloc_push(ret)) {
72625 + kfree(ret);
72626 + ret = NULL;
72627 + }
72628 + }
72629 +
72630 +out:
72631 + return ret;
72632 +}
72633 +
72634 +void *
72635 +acl_alloc_num(unsigned long num, unsigned long len)
72636 +{
72637 + if (!len || (num > (PAGE_SIZE / len)))
72638 + return NULL;
72639 +
72640 + return acl_alloc(num * len);
72641 +}
72642 +
72643 +void
72644 +acl_free_all(void)
72645 +{
72646 + if (!current_alloc_state->alloc_stack)
72647 + return;
72648 +
72649 + while (alloc_pop()) ;
72650 +
72651 + if (current_alloc_state->alloc_stack) {
72652 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72653 + kfree(current_alloc_state->alloc_stack);
72654 + else
72655 + vfree(current_alloc_state->alloc_stack);
72656 + }
72657 +
72658 + current_alloc_state->alloc_stack = NULL;
72659 + current_alloc_state->alloc_stack_size = 1;
72660 + current_alloc_state->alloc_stack_next = 1;
72661 +
72662 + return;
72663 +}
72664 +
72665 +int
72666 +acl_alloc_stack_init(unsigned long size)
72667 +{
72668 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72669 + current_alloc_state->alloc_stack =
72670 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72671 + else
72672 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72673 +
72674 + current_alloc_state->alloc_stack_size = size;
72675 + current_alloc_state->alloc_stack_next = 1;
72676 +
72677 + if (!current_alloc_state->alloc_stack)
72678 + return 0;
72679 + else
72680 + return 1;
72681 +}
72682 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72683 new file mode 100644
72684 index 0000000..1a94c11
72685 --- /dev/null
72686 +++ b/grsecurity/gracl_cap.c
72687 @@ -0,0 +1,127 @@
72688 +#include <linux/kernel.h>
72689 +#include <linux/module.h>
72690 +#include <linux/sched.h>
72691 +#include <linux/gracl.h>
72692 +#include <linux/grsecurity.h>
72693 +#include <linux/grinternal.h>
72694 +
72695 +extern const char *captab_log[];
72696 +extern int captab_log_entries;
72697 +
72698 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72699 +{
72700 + struct acl_subject_label *curracl;
72701 +
72702 + if (!gr_acl_is_enabled())
72703 + return 1;
72704 +
72705 + curracl = task->acl;
72706 +
72707 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72708 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72709 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72710 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72711 + gr_to_filename(task->exec_file->f_path.dentry,
72712 + task->exec_file->f_path.mnt) : curracl->filename,
72713 + curracl->filename, 0UL,
72714 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72715 + return 1;
72716 + }
72717 +
72718 + return 0;
72719 +}
72720 +
72721 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72722 +{
72723 + struct acl_subject_label *curracl;
72724 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72725 + kernel_cap_t cap_audit = __cap_empty_set;
72726 +
72727 + if (!gr_acl_is_enabled())
72728 + return 1;
72729 +
72730 + curracl = task->acl;
72731 +
72732 + cap_drop = curracl->cap_lower;
72733 + cap_mask = curracl->cap_mask;
72734 + cap_audit = curracl->cap_invert_audit;
72735 +
72736 + while ((curracl = curracl->parent_subject)) {
72737 + /* if the cap isn't specified in the current computed mask but is specified in the
72738 + current level subject, and is lowered in the current level subject, then add
72739 + it to the set of dropped capabilities
72740 + otherwise, add the current level subject's mask to the current computed mask
72741 + */
72742 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72743 + cap_raise(cap_mask, cap);
72744 + if (cap_raised(curracl->cap_lower, cap))
72745 + cap_raise(cap_drop, cap);
72746 + if (cap_raised(curracl->cap_invert_audit, cap))
72747 + cap_raise(cap_audit, cap);
72748 + }
72749 + }
72750 +
72751 + if (!cap_raised(cap_drop, cap)) {
72752 + if (cap_raised(cap_audit, cap))
72753 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72754 + return 1;
72755 + }
72756 +
72757 + /* only learn the capability use if the process has the capability in the
72758 + general case, the two uses in sys.c of gr_learn_cap are an exception
72759 + to this rule to ensure any role transition involves what the full-learned
72760 + policy believes in a privileged process
72761 + */
72762 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72763 + return 1;
72764 +
72765 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72766 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72767 +
72768 + return 0;
72769 +}
72770 +
72771 +int
72772 +gr_acl_is_capable(const int cap)
72773 +{
72774 + return gr_task_acl_is_capable(current, current_cred(), cap);
72775 +}
72776 +
72777 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72778 +{
72779 + struct acl_subject_label *curracl;
72780 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72781 +
72782 + if (!gr_acl_is_enabled())
72783 + return 1;
72784 +
72785 + curracl = task->acl;
72786 +
72787 + cap_drop = curracl->cap_lower;
72788 + cap_mask = curracl->cap_mask;
72789 +
72790 + while ((curracl = curracl->parent_subject)) {
72791 + /* if the cap isn't specified in the current computed mask but is specified in the
72792 + current level subject, and is lowered in the current level subject, then add
72793 + it to the set of dropped capabilities
72794 + otherwise, add the current level subject's mask to the current computed mask
72795 + */
72796 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72797 + cap_raise(cap_mask, cap);
72798 + if (cap_raised(curracl->cap_lower, cap))
72799 + cap_raise(cap_drop, cap);
72800 + }
72801 + }
72802 +
72803 + if (!cap_raised(cap_drop, cap))
72804 + return 1;
72805 +
72806 + return 0;
72807 +}
72808 +
72809 +int
72810 +gr_acl_is_capable_nolog(const int cap)
72811 +{
72812 + return gr_task_acl_is_capable_nolog(current, cap);
72813 +}
72814 +
72815 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72816 new file mode 100644
72817 index 0000000..ca25605
72818 --- /dev/null
72819 +++ b/grsecurity/gracl_compat.c
72820 @@ -0,0 +1,270 @@
72821 +#include <linux/kernel.h>
72822 +#include <linux/gracl.h>
72823 +#include <linux/compat.h>
72824 +#include <linux/gracl_compat.h>
72825 +
72826 +#include <asm/uaccess.h>
72827 +
72828 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72829 +{
72830 + struct gr_arg_wrapper_compat uwrapcompat;
72831 +
72832 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72833 + return -EFAULT;
72834 +
72835 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72836 + (uwrapcompat.version != 0x2901)) ||
72837 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72838 + return -EINVAL;
72839 +
72840 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72841 + uwrap->version = uwrapcompat.version;
72842 + uwrap->size = sizeof(struct gr_arg);
72843 +
72844 + return 0;
72845 +}
72846 +
72847 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72848 +{
72849 + struct gr_arg_compat argcompat;
72850 +
72851 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72852 + return -EFAULT;
72853 +
72854 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72855 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72856 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72857 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72858 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72859 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72860 +
72861 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72862 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72863 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72864 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72865 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72866 + arg->segv_device = argcompat.segv_device;
72867 + arg->segv_inode = argcompat.segv_inode;
72868 + arg->segv_uid = argcompat.segv_uid;
72869 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72870 + arg->mode = argcompat.mode;
72871 +
72872 + return 0;
72873 +}
72874 +
72875 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72876 +{
72877 + struct acl_object_label_compat objcompat;
72878 +
72879 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72880 + return -EFAULT;
72881 +
72882 + obj->filename = compat_ptr(objcompat.filename);
72883 + obj->inode = objcompat.inode;
72884 + obj->device = objcompat.device;
72885 + obj->mode = objcompat.mode;
72886 +
72887 + obj->nested = compat_ptr(objcompat.nested);
72888 + obj->globbed = compat_ptr(objcompat.globbed);
72889 +
72890 + obj->prev = compat_ptr(objcompat.prev);
72891 + obj->next = compat_ptr(objcompat.next);
72892 +
72893 + return 0;
72894 +}
72895 +
72896 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72897 +{
72898 + unsigned int i;
72899 + struct acl_subject_label_compat subjcompat;
72900 +
72901 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72902 + return -EFAULT;
72903 +
72904 + subj->filename = compat_ptr(subjcompat.filename);
72905 + subj->inode = subjcompat.inode;
72906 + subj->device = subjcompat.device;
72907 + subj->mode = subjcompat.mode;
72908 + subj->cap_mask = subjcompat.cap_mask;
72909 + subj->cap_lower = subjcompat.cap_lower;
72910 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72911 +
72912 + for (i = 0; i < GR_NLIMITS; i++) {
72913 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72914 + subj->res[i].rlim_cur = RLIM_INFINITY;
72915 + else
72916 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72917 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72918 + subj->res[i].rlim_max = RLIM_INFINITY;
72919 + else
72920 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72921 + }
72922 + subj->resmask = subjcompat.resmask;
72923 +
72924 + subj->user_trans_type = subjcompat.user_trans_type;
72925 + subj->group_trans_type = subjcompat.group_trans_type;
72926 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72927 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72928 + subj->user_trans_num = subjcompat.user_trans_num;
72929 + subj->group_trans_num = subjcompat.group_trans_num;
72930 +
72931 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72932 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72933 + subj->ip_type = subjcompat.ip_type;
72934 + subj->ips = compat_ptr(subjcompat.ips);
72935 + subj->ip_num = subjcompat.ip_num;
72936 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72937 +
72938 + subj->crashes = subjcompat.crashes;
72939 + subj->expires = subjcompat.expires;
72940 +
72941 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72942 + subj->hash = compat_ptr(subjcompat.hash);
72943 + subj->prev = compat_ptr(subjcompat.prev);
72944 + subj->next = compat_ptr(subjcompat.next);
72945 +
72946 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72947 + subj->obj_hash_size = subjcompat.obj_hash_size;
72948 + subj->pax_flags = subjcompat.pax_flags;
72949 +
72950 + return 0;
72951 +}
72952 +
72953 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72954 +{
72955 + struct acl_role_label_compat rolecompat;
72956 +
72957 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72958 + return -EFAULT;
72959 +
72960 + role->rolename = compat_ptr(rolecompat.rolename);
72961 + role->uidgid = rolecompat.uidgid;
72962 + role->roletype = rolecompat.roletype;
72963 +
72964 + role->auth_attempts = rolecompat.auth_attempts;
72965 + role->expires = rolecompat.expires;
72966 +
72967 + role->root_label = compat_ptr(rolecompat.root_label);
72968 + role->hash = compat_ptr(rolecompat.hash);
72969 +
72970 + role->prev = compat_ptr(rolecompat.prev);
72971 + role->next = compat_ptr(rolecompat.next);
72972 +
72973 + role->transitions = compat_ptr(rolecompat.transitions);
72974 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72975 + role->domain_children = compat_ptr(rolecompat.domain_children);
72976 + role->domain_child_num = rolecompat.domain_child_num;
72977 +
72978 + role->umask = rolecompat.umask;
72979 +
72980 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72981 + role->subj_hash_size = rolecompat.subj_hash_size;
72982 +
72983 + return 0;
72984 +}
72985 +
72986 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72987 +{
72988 + struct role_allowed_ip_compat roleip_compat;
72989 +
72990 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72991 + return -EFAULT;
72992 +
72993 + roleip->addr = roleip_compat.addr;
72994 + roleip->netmask = roleip_compat.netmask;
72995 +
72996 + roleip->prev = compat_ptr(roleip_compat.prev);
72997 + roleip->next = compat_ptr(roleip_compat.next);
72998 +
72999 + return 0;
73000 +}
73001 +
73002 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
73003 +{
73004 + struct role_transition_compat trans_compat;
73005 +
73006 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
73007 + return -EFAULT;
73008 +
73009 + trans->rolename = compat_ptr(trans_compat.rolename);
73010 +
73011 + trans->prev = compat_ptr(trans_compat.prev);
73012 + trans->next = compat_ptr(trans_compat.next);
73013 +
73014 + return 0;
73015 +
73016 +}
73017 +
73018 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73019 +{
73020 + struct gr_hash_struct_compat hash_compat;
73021 +
73022 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
73023 + return -EFAULT;
73024 +
73025 + hash->table = compat_ptr(hash_compat.table);
73026 + hash->nametable = compat_ptr(hash_compat.nametable);
73027 + hash->first = compat_ptr(hash_compat.first);
73028 +
73029 + hash->table_size = hash_compat.table_size;
73030 + hash->used_size = hash_compat.used_size;
73031 +
73032 + hash->type = hash_compat.type;
73033 +
73034 + return 0;
73035 +}
73036 +
73037 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
73038 +{
73039 + compat_uptr_t ptrcompat;
73040 +
73041 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
73042 + return -EFAULT;
73043 +
73044 + *(void **)ptr = compat_ptr(ptrcompat);
73045 +
73046 + return 0;
73047 +}
73048 +
73049 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73050 +{
73051 + struct acl_ip_label_compat ip_compat;
73052 +
73053 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
73054 + return -EFAULT;
73055 +
73056 + ip->iface = compat_ptr(ip_compat.iface);
73057 + ip->addr = ip_compat.addr;
73058 + ip->netmask = ip_compat.netmask;
73059 + ip->low = ip_compat.low;
73060 + ip->high = ip_compat.high;
73061 + ip->mode = ip_compat.mode;
73062 + ip->type = ip_compat.type;
73063 +
73064 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
73065 +
73066 + ip->prev = compat_ptr(ip_compat.prev);
73067 + ip->next = compat_ptr(ip_compat.next);
73068 +
73069 + return 0;
73070 +}
73071 +
73072 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73073 +{
73074 + struct sprole_pw_compat pw_compat;
73075 +
73076 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
73077 + return -EFAULT;
73078 +
73079 + pw->rolename = compat_ptr(pw_compat.rolename);
73080 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
73081 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
73082 +
73083 + return 0;
73084 +}
73085 +
73086 +size_t get_gr_arg_wrapper_size_compat(void)
73087 +{
73088 + return sizeof(struct gr_arg_wrapper_compat);
73089 +}
73090 +
73091 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
73092 new file mode 100644
73093 index 0000000..4008fdc
73094 --- /dev/null
73095 +++ b/grsecurity/gracl_fs.c
73096 @@ -0,0 +1,445 @@
73097 +#include <linux/kernel.h>
73098 +#include <linux/sched.h>
73099 +#include <linux/types.h>
73100 +#include <linux/fs.h>
73101 +#include <linux/file.h>
73102 +#include <linux/stat.h>
73103 +#include <linux/grsecurity.h>
73104 +#include <linux/grinternal.h>
73105 +#include <linux/gracl.h>
73106 +
73107 +umode_t
73108 +gr_acl_umask(void)
73109 +{
73110 + if (unlikely(!gr_acl_is_enabled()))
73111 + return 0;
73112 +
73113 + return current->role->umask;
73114 +}
73115 +
73116 +__u32
73117 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73118 + const struct vfsmount * mnt)
73119 +{
73120 + __u32 mode;
73121 +
73122 + if (unlikely(d_is_negative(dentry)))
73123 + return GR_FIND;
73124 +
73125 + mode =
73126 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
73127 +
73128 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73129 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73130 + return mode;
73131 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73132 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73133 + return 0;
73134 + } else if (unlikely(!(mode & GR_FIND)))
73135 + return 0;
73136 +
73137 + return GR_FIND;
73138 +}
73139 +
73140 +__u32
73141 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73142 + int acc_mode)
73143 +{
73144 + __u32 reqmode = GR_FIND;
73145 + __u32 mode;
73146 +
73147 + if (unlikely(d_is_negative(dentry)))
73148 + return reqmode;
73149 +
73150 + if (acc_mode & MAY_APPEND)
73151 + reqmode |= GR_APPEND;
73152 + else if (acc_mode & MAY_WRITE)
73153 + reqmode |= GR_WRITE;
73154 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73155 + reqmode |= GR_READ;
73156 +
73157 + mode =
73158 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73159 + mnt);
73160 +
73161 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73162 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73163 + reqmode & GR_READ ? " reading" : "",
73164 + reqmode & GR_WRITE ? " writing" : reqmode &
73165 + GR_APPEND ? " appending" : "");
73166 + return reqmode;
73167 + } else
73168 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73169 + {
73170 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73171 + reqmode & GR_READ ? " reading" : "",
73172 + reqmode & GR_WRITE ? " writing" : reqmode &
73173 + GR_APPEND ? " appending" : "");
73174 + return 0;
73175 + } else if (unlikely((mode & reqmode) != reqmode))
73176 + return 0;
73177 +
73178 + return reqmode;
73179 +}
73180 +
73181 +__u32
73182 +gr_acl_handle_creat(const struct dentry * dentry,
73183 + const struct dentry * p_dentry,
73184 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73185 + const int imode)
73186 +{
73187 + __u32 reqmode = GR_WRITE | GR_CREATE;
73188 + __u32 mode;
73189 +
73190 + if (acc_mode & MAY_APPEND)
73191 + reqmode |= GR_APPEND;
73192 + // if a directory was required or the directory already exists, then
73193 + // don't count this open as a read
73194 + if ((acc_mode & MAY_READ) &&
73195 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73196 + reqmode |= GR_READ;
73197 + if ((open_flags & O_CREAT) &&
73198 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73199 + reqmode |= GR_SETID;
73200 +
73201 + mode =
73202 + gr_check_create(dentry, p_dentry, p_mnt,
73203 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73204 +
73205 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73206 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73207 + reqmode & GR_READ ? " reading" : "",
73208 + reqmode & GR_WRITE ? " writing" : reqmode &
73209 + GR_APPEND ? " appending" : "");
73210 + return reqmode;
73211 + } else
73212 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73213 + {
73214 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73215 + reqmode & GR_READ ? " reading" : "",
73216 + reqmode & GR_WRITE ? " writing" : reqmode &
73217 + GR_APPEND ? " appending" : "");
73218 + return 0;
73219 + } else if (unlikely((mode & reqmode) != reqmode))
73220 + return 0;
73221 +
73222 + return reqmode;
73223 +}
73224 +
73225 +__u32
73226 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73227 + const int fmode)
73228 +{
73229 + __u32 mode, reqmode = GR_FIND;
73230 +
73231 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73232 + reqmode |= GR_EXEC;
73233 + if (fmode & S_IWOTH)
73234 + reqmode |= GR_WRITE;
73235 + if (fmode & S_IROTH)
73236 + reqmode |= GR_READ;
73237 +
73238 + mode =
73239 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73240 + mnt);
73241 +
73242 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73243 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73244 + reqmode & GR_READ ? " reading" : "",
73245 + reqmode & GR_WRITE ? " writing" : "",
73246 + reqmode & GR_EXEC ? " executing" : "");
73247 + return reqmode;
73248 + } else
73249 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73250 + {
73251 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73252 + reqmode & GR_READ ? " reading" : "",
73253 + reqmode & GR_WRITE ? " writing" : "",
73254 + reqmode & GR_EXEC ? " executing" : "");
73255 + return 0;
73256 + } else if (unlikely((mode & reqmode) != reqmode))
73257 + return 0;
73258 +
73259 + return reqmode;
73260 +}
73261 +
73262 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73263 +{
73264 + __u32 mode;
73265 +
73266 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73267 +
73268 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73269 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73270 + return mode;
73271 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73272 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73273 + return 0;
73274 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73275 + return 0;
73276 +
73277 + return (reqmode);
73278 +}
73279 +
73280 +__u32
73281 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73282 +{
73283 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73284 +}
73285 +
73286 +__u32
73287 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73288 +{
73289 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73290 +}
73291 +
73292 +__u32
73293 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73294 +{
73295 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73296 +}
73297 +
73298 +__u32
73299 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73300 +{
73301 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73302 +}
73303 +
73304 +__u32
73305 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73306 + umode_t *modeptr)
73307 +{
73308 + umode_t mode;
73309 +
73310 + *modeptr &= ~gr_acl_umask();
73311 + mode = *modeptr;
73312 +
73313 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73314 + return 1;
73315 +
73316 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73317 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73318 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73319 + GR_CHMOD_ACL_MSG);
73320 + } else {
73321 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73322 + }
73323 +}
73324 +
73325 +__u32
73326 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73327 +{
73328 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73329 +}
73330 +
73331 +__u32
73332 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73333 +{
73334 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73335 +}
73336 +
73337 +__u32
73338 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73339 +{
73340 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73341 +}
73342 +
73343 +__u32
73344 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73345 +{
73346 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73347 +}
73348 +
73349 +__u32
73350 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73351 +{
73352 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73353 + GR_UNIXCONNECT_ACL_MSG);
73354 +}
73355 +
73356 +/* hardlinks require at minimum create and link permission,
73357 + any additional privilege required is based on the
73358 + privilege of the file being linked to
73359 +*/
73360 +__u32
73361 +gr_acl_handle_link(const struct dentry * new_dentry,
73362 + const struct dentry * parent_dentry,
73363 + const struct vfsmount * parent_mnt,
73364 + const struct dentry * old_dentry,
73365 + const struct vfsmount * old_mnt, const struct filename *to)
73366 +{
73367 + __u32 mode;
73368 + __u32 needmode = GR_CREATE | GR_LINK;
73369 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73370 +
73371 + mode =
73372 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73373 + old_mnt);
73374 +
73375 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73376 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73377 + return mode;
73378 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73379 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73380 + return 0;
73381 + } else if (unlikely((mode & needmode) != needmode))
73382 + return 0;
73383 +
73384 + return 1;
73385 +}
73386 +
73387 +__u32
73388 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73389 + const struct dentry * parent_dentry,
73390 + const struct vfsmount * parent_mnt, const struct filename *from)
73391 +{
73392 + __u32 needmode = GR_WRITE | GR_CREATE;
73393 + __u32 mode;
73394 +
73395 + mode =
73396 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73397 + GR_CREATE | GR_AUDIT_CREATE |
73398 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73399 +
73400 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73401 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73402 + return mode;
73403 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73404 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73405 + return 0;
73406 + } else if (unlikely((mode & needmode) != needmode))
73407 + return 0;
73408 +
73409 + return (GR_WRITE | GR_CREATE);
73410 +}
73411 +
73412 +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)
73413 +{
73414 + __u32 mode;
73415 +
73416 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73417 +
73418 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73419 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73420 + return mode;
73421 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73422 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73423 + return 0;
73424 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73425 + return 0;
73426 +
73427 + return (reqmode);
73428 +}
73429 +
73430 +__u32
73431 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73432 + const struct dentry * parent_dentry,
73433 + const struct vfsmount * parent_mnt,
73434 + const int mode)
73435 +{
73436 + __u32 reqmode = GR_WRITE | GR_CREATE;
73437 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73438 + reqmode |= GR_SETID;
73439 +
73440 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73441 + reqmode, GR_MKNOD_ACL_MSG);
73442 +}
73443 +
73444 +__u32
73445 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73446 + const struct dentry *parent_dentry,
73447 + const struct vfsmount *parent_mnt)
73448 +{
73449 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73450 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73451 +}
73452 +
73453 +#define RENAME_CHECK_SUCCESS(old, new) \
73454 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73455 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73456 +
73457 +int
73458 +gr_acl_handle_rename(struct dentry *new_dentry,
73459 + struct dentry *parent_dentry,
73460 + const struct vfsmount *parent_mnt,
73461 + struct dentry *old_dentry,
73462 + struct inode *old_parent_inode,
73463 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73464 +{
73465 + __u32 comp1, comp2;
73466 + int error = 0;
73467 +
73468 + if (unlikely(!gr_acl_is_enabled()))
73469 + return 0;
73470 +
73471 + if (flags & RENAME_EXCHANGE) {
73472 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73473 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73474 + GR_SUPPRESS, parent_mnt);
73475 + comp2 =
73476 + gr_search_file(old_dentry,
73477 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73478 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73479 + } else if (d_is_negative(new_dentry)) {
73480 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73481 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73482 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73483 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73484 + GR_DELETE | GR_AUDIT_DELETE |
73485 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73486 + GR_SUPPRESS, old_mnt);
73487 + } else {
73488 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73489 + GR_CREATE | GR_DELETE |
73490 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73491 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73492 + GR_SUPPRESS, parent_mnt);
73493 + comp2 =
73494 + gr_search_file(old_dentry,
73495 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73496 + GR_DELETE | GR_AUDIT_DELETE |
73497 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73498 + }
73499 +
73500 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73501 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73502 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73503 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73504 + && !(comp2 & GR_SUPPRESS)) {
73505 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73506 + error = -EACCES;
73507 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73508 + error = -EACCES;
73509 +
73510 + return error;
73511 +}
73512 +
73513 +void
73514 +gr_acl_handle_exit(void)
73515 +{
73516 + u16 id;
73517 + char *rolename;
73518 +
73519 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73520 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73521 + id = current->acl_role_id;
73522 + rolename = current->role->rolename;
73523 + gr_set_acls(1);
73524 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73525 + }
73526 +
73527 + gr_put_exec_file(current);
73528 + return;
73529 +}
73530 +
73531 +int
73532 +gr_acl_handle_procpidmem(const struct task_struct *task)
73533 +{
73534 + if (unlikely(!gr_acl_is_enabled()))
73535 + return 0;
73536 +
73537 + if (task != current && task->acl->mode & GR_PROTPROCFD)
73538 + return -EACCES;
73539 +
73540 + return 0;
73541 +}
73542 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73543 new file mode 100644
73544 index 0000000..f056b81
73545 --- /dev/null
73546 +++ b/grsecurity/gracl_ip.c
73547 @@ -0,0 +1,386 @@
73548 +#include <linux/kernel.h>
73549 +#include <asm/uaccess.h>
73550 +#include <asm/errno.h>
73551 +#include <net/sock.h>
73552 +#include <linux/file.h>
73553 +#include <linux/fs.h>
73554 +#include <linux/net.h>
73555 +#include <linux/in.h>
73556 +#include <linux/skbuff.h>
73557 +#include <linux/ip.h>
73558 +#include <linux/udp.h>
73559 +#include <linux/types.h>
73560 +#include <linux/sched.h>
73561 +#include <linux/netdevice.h>
73562 +#include <linux/inetdevice.h>
73563 +#include <linux/gracl.h>
73564 +#include <linux/grsecurity.h>
73565 +#include <linux/grinternal.h>
73566 +
73567 +#define GR_BIND 0x01
73568 +#define GR_CONNECT 0x02
73569 +#define GR_INVERT 0x04
73570 +#define GR_BINDOVERRIDE 0x08
73571 +#define GR_CONNECTOVERRIDE 0x10
73572 +#define GR_SOCK_FAMILY 0x20
73573 +
73574 +static const char * gr_protocols[IPPROTO_MAX] = {
73575 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73576 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73577 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73578 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73579 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73580 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73581 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73582 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73583 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73584 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73585 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73586 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73587 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73588 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73589 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73590 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73591 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73592 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73593 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73594 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73595 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73596 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73597 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73598 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73599 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73600 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73601 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73602 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73603 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73604 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73605 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73606 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73607 + };
73608 +
73609 +static const char * gr_socktypes[SOCK_MAX] = {
73610 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73611 + "unknown:7", "unknown:8", "unknown:9", "packet"
73612 + };
73613 +
73614 +static const char * gr_sockfamilies[AF_MAX+1] = {
73615 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73616 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73617 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73618 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73619 + };
73620 +
73621 +const char *
73622 +gr_proto_to_name(unsigned char proto)
73623 +{
73624 + return gr_protocols[proto];
73625 +}
73626 +
73627 +const char *
73628 +gr_socktype_to_name(unsigned char type)
73629 +{
73630 + return gr_socktypes[type];
73631 +}
73632 +
73633 +const char *
73634 +gr_sockfamily_to_name(unsigned char family)
73635 +{
73636 + return gr_sockfamilies[family];
73637 +}
73638 +
73639 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73640 +
73641 +int
73642 +gr_search_socket(const int domain, const int type, const int protocol)
73643 +{
73644 + struct acl_subject_label *curr;
73645 + const struct cred *cred = current_cred();
73646 +
73647 + if (unlikely(!gr_acl_is_enabled()))
73648 + goto exit;
73649 +
73650 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73651 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73652 + goto exit; // let the kernel handle it
73653 +
73654 + curr = current->acl;
73655 +
73656 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73657 + /* the family is allowed, if this is PF_INET allow it only if
73658 + the extra sock type/protocol checks pass */
73659 + if (domain == PF_INET)
73660 + goto inet_check;
73661 + goto exit;
73662 + } else {
73663 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73664 + __u32 fakeip = 0;
73665 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73666 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73667 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73668 + gr_to_filename(current->exec_file->f_path.dentry,
73669 + current->exec_file->f_path.mnt) :
73670 + curr->filename, curr->filename,
73671 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73672 + &current->signal->saved_ip);
73673 + goto exit;
73674 + }
73675 + goto exit_fail;
73676 + }
73677 +
73678 +inet_check:
73679 + /* the rest of this checking is for IPv4 only */
73680 + if (!curr->ips)
73681 + goto exit;
73682 +
73683 + if ((curr->ip_type & (1U << type)) &&
73684 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73685 + goto exit;
73686 +
73687 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73688 + /* we don't place acls on raw sockets , and sometimes
73689 + dgram/ip sockets are opened for ioctl and not
73690 + bind/connect, so we'll fake a bind learn log */
73691 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73692 + __u32 fakeip = 0;
73693 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73694 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73695 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73696 + gr_to_filename(current->exec_file->f_path.dentry,
73697 + current->exec_file->f_path.mnt) :
73698 + curr->filename, curr->filename,
73699 + &fakeip, 0, type,
73700 + protocol, GR_CONNECT, &current->signal->saved_ip);
73701 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73702 + __u32 fakeip = 0;
73703 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73704 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73705 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73706 + gr_to_filename(current->exec_file->f_path.dentry,
73707 + current->exec_file->f_path.mnt) :
73708 + curr->filename, curr->filename,
73709 + &fakeip, 0, type,
73710 + protocol, GR_BIND, &current->signal->saved_ip);
73711 + }
73712 + /* we'll log when they use connect or bind */
73713 + goto exit;
73714 + }
73715 +
73716 +exit_fail:
73717 + if (domain == PF_INET)
73718 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73719 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73720 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73721 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73722 + gr_socktype_to_name(type), protocol);
73723 +
73724 + return 0;
73725 +exit:
73726 + return 1;
73727 +}
73728 +
73729 +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)
73730 +{
73731 + if ((ip->mode & mode) &&
73732 + (ip_port >= ip->low) &&
73733 + (ip_port <= ip->high) &&
73734 + ((ntohl(ip_addr) & our_netmask) ==
73735 + (ntohl(our_addr) & our_netmask))
73736 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73737 + && (ip->type & (1U << type))) {
73738 + if (ip->mode & GR_INVERT)
73739 + return 2; // specifically denied
73740 + else
73741 + return 1; // allowed
73742 + }
73743 +
73744 + return 0; // not specifically allowed, may continue parsing
73745 +}
73746 +
73747 +static int
73748 +gr_search_connectbind(const int full_mode, struct sock *sk,
73749 + struct sockaddr_in *addr, const int type)
73750 +{
73751 + char iface[IFNAMSIZ] = {0};
73752 + struct acl_subject_label *curr;
73753 + struct acl_ip_label *ip;
73754 + struct inet_sock *isk;
73755 + struct net_device *dev;
73756 + struct in_device *idev;
73757 + unsigned long i;
73758 + int ret;
73759 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73760 + __u32 ip_addr = 0;
73761 + __u32 our_addr;
73762 + __u32 our_netmask;
73763 + char *p;
73764 + __u16 ip_port = 0;
73765 + const struct cred *cred = current_cred();
73766 +
73767 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73768 + return 0;
73769 +
73770 + curr = current->acl;
73771 + isk = inet_sk(sk);
73772 +
73773 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73774 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73775 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73776 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73777 + struct sockaddr_in saddr;
73778 + int err;
73779 +
73780 + saddr.sin_family = AF_INET;
73781 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73782 + saddr.sin_port = isk->inet_sport;
73783 +
73784 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73785 + if (err)
73786 + return err;
73787 +
73788 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73789 + if (err)
73790 + return err;
73791 + }
73792 +
73793 + if (!curr->ips)
73794 + return 0;
73795 +
73796 + ip_addr = addr->sin_addr.s_addr;
73797 + ip_port = ntohs(addr->sin_port);
73798 +
73799 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73800 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73801 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73802 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73803 + gr_to_filename(current->exec_file->f_path.dentry,
73804 + current->exec_file->f_path.mnt) :
73805 + curr->filename, curr->filename,
73806 + &ip_addr, ip_port, type,
73807 + sk->sk_protocol, mode, &current->signal->saved_ip);
73808 + return 0;
73809 + }
73810 +
73811 + for (i = 0; i < curr->ip_num; i++) {
73812 + ip = *(curr->ips + i);
73813 + if (ip->iface != NULL) {
73814 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73815 + p = strchr(iface, ':');
73816 + if (p != NULL)
73817 + *p = '\0';
73818 + dev = dev_get_by_name(sock_net(sk), iface);
73819 + if (dev == NULL)
73820 + continue;
73821 + idev = in_dev_get(dev);
73822 + if (idev == NULL) {
73823 + dev_put(dev);
73824 + continue;
73825 + }
73826 + rcu_read_lock();
73827 + for_ifa(idev) {
73828 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73829 + our_addr = ifa->ifa_address;
73830 + our_netmask = 0xffffffff;
73831 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73832 + if (ret == 1) {
73833 + rcu_read_unlock();
73834 + in_dev_put(idev);
73835 + dev_put(dev);
73836 + return 0;
73837 + } else if (ret == 2) {
73838 + rcu_read_unlock();
73839 + in_dev_put(idev);
73840 + dev_put(dev);
73841 + goto denied;
73842 + }
73843 + }
73844 + } endfor_ifa(idev);
73845 + rcu_read_unlock();
73846 + in_dev_put(idev);
73847 + dev_put(dev);
73848 + } else {
73849 + our_addr = ip->addr;
73850 + our_netmask = ip->netmask;
73851 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73852 + if (ret == 1)
73853 + return 0;
73854 + else if (ret == 2)
73855 + goto denied;
73856 + }
73857 + }
73858 +
73859 +denied:
73860 + if (mode == GR_BIND)
73861 + 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));
73862 + else if (mode == GR_CONNECT)
73863 + 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));
73864 +
73865 + return -EACCES;
73866 +}
73867 +
73868 +int
73869 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73870 +{
73871 + /* always allow disconnection of dgram sockets with connect */
73872 + if (addr->sin_family == AF_UNSPEC)
73873 + return 0;
73874 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73875 +}
73876 +
73877 +int
73878 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73879 +{
73880 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73881 +}
73882 +
73883 +int gr_search_listen(struct socket *sock)
73884 +{
73885 + struct sock *sk = sock->sk;
73886 + struct sockaddr_in addr;
73887 +
73888 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73889 + addr.sin_port = inet_sk(sk)->inet_sport;
73890 +
73891 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73892 +}
73893 +
73894 +int gr_search_accept(struct socket *sock)
73895 +{
73896 + struct sock *sk = sock->sk;
73897 + struct sockaddr_in addr;
73898 +
73899 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73900 + addr.sin_port = inet_sk(sk)->inet_sport;
73901 +
73902 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73903 +}
73904 +
73905 +int
73906 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73907 +{
73908 + if (addr)
73909 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73910 + else {
73911 + struct sockaddr_in sin;
73912 + const struct inet_sock *inet = inet_sk(sk);
73913 +
73914 + sin.sin_addr.s_addr = inet->inet_daddr;
73915 + sin.sin_port = inet->inet_dport;
73916 +
73917 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73918 + }
73919 +}
73920 +
73921 +int
73922 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73923 +{
73924 + struct sockaddr_in sin;
73925 +
73926 + if (unlikely(skb->len < sizeof (struct udphdr)))
73927 + return 0; // skip this packet
73928 +
73929 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73930 + sin.sin_port = udp_hdr(skb)->source;
73931 +
73932 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73933 +}
73934 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73935 new file mode 100644
73936 index 0000000..25f54ef
73937 --- /dev/null
73938 +++ b/grsecurity/gracl_learn.c
73939 @@ -0,0 +1,207 @@
73940 +#include <linux/kernel.h>
73941 +#include <linux/mm.h>
73942 +#include <linux/sched.h>
73943 +#include <linux/poll.h>
73944 +#include <linux/string.h>
73945 +#include <linux/file.h>
73946 +#include <linux/types.h>
73947 +#include <linux/vmalloc.h>
73948 +#include <linux/grinternal.h>
73949 +
73950 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73951 + size_t count, loff_t *ppos);
73952 +extern int gr_acl_is_enabled(void);
73953 +
73954 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73955 +static int gr_learn_attached;
73956 +
73957 +/* use a 512k buffer */
73958 +#define LEARN_BUFFER_SIZE (512 * 1024)
73959 +
73960 +static DEFINE_SPINLOCK(gr_learn_lock);
73961 +static DEFINE_MUTEX(gr_learn_user_mutex);
73962 +
73963 +/* we need to maintain two buffers, so that the kernel context of grlearn
73964 + uses a semaphore around the userspace copying, and the other kernel contexts
73965 + use a spinlock when copying into the buffer, since they cannot sleep
73966 +*/
73967 +static char *learn_buffer;
73968 +static char *learn_buffer_user;
73969 +static int learn_buffer_len;
73970 +static int learn_buffer_user_len;
73971 +
73972 +static ssize_t
73973 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73974 +{
73975 + DECLARE_WAITQUEUE(wait, current);
73976 + ssize_t retval = 0;
73977 +
73978 + add_wait_queue(&learn_wait, &wait);
73979 + set_current_state(TASK_INTERRUPTIBLE);
73980 + do {
73981 + mutex_lock(&gr_learn_user_mutex);
73982 + spin_lock(&gr_learn_lock);
73983 + if (learn_buffer_len)
73984 + break;
73985 + spin_unlock(&gr_learn_lock);
73986 + mutex_unlock(&gr_learn_user_mutex);
73987 + if (file->f_flags & O_NONBLOCK) {
73988 + retval = -EAGAIN;
73989 + goto out;
73990 + }
73991 + if (signal_pending(current)) {
73992 + retval = -ERESTARTSYS;
73993 + goto out;
73994 + }
73995 +
73996 + schedule();
73997 + } while (1);
73998 +
73999 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
74000 + learn_buffer_user_len = learn_buffer_len;
74001 + retval = learn_buffer_len;
74002 + learn_buffer_len = 0;
74003 +
74004 + spin_unlock(&gr_learn_lock);
74005 +
74006 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
74007 + retval = -EFAULT;
74008 +
74009 + mutex_unlock(&gr_learn_user_mutex);
74010 +out:
74011 + set_current_state(TASK_RUNNING);
74012 + remove_wait_queue(&learn_wait, &wait);
74013 + return retval;
74014 +}
74015 +
74016 +static unsigned int
74017 +poll_learn(struct file * file, poll_table * wait)
74018 +{
74019 + poll_wait(file, &learn_wait, wait);
74020 +
74021 + if (learn_buffer_len)
74022 + return (POLLIN | POLLRDNORM);
74023 +
74024 + return 0;
74025 +}
74026 +
74027 +void
74028 +gr_clear_learn_entries(void)
74029 +{
74030 + char *tmp;
74031 +
74032 + mutex_lock(&gr_learn_user_mutex);
74033 + spin_lock(&gr_learn_lock);
74034 + tmp = learn_buffer;
74035 + learn_buffer = NULL;
74036 + spin_unlock(&gr_learn_lock);
74037 + if (tmp)
74038 + vfree(tmp);
74039 + if (learn_buffer_user != NULL) {
74040 + vfree(learn_buffer_user);
74041 + learn_buffer_user = NULL;
74042 + }
74043 + learn_buffer_len = 0;
74044 + mutex_unlock(&gr_learn_user_mutex);
74045 +
74046 + return;
74047 +}
74048 +
74049 +void
74050 +gr_add_learn_entry(const char *fmt, ...)
74051 +{
74052 + va_list args;
74053 + unsigned int len;
74054 +
74055 + if (!gr_learn_attached)
74056 + return;
74057 +
74058 + spin_lock(&gr_learn_lock);
74059 +
74060 + /* leave a gap at the end so we know when it's "full" but don't have to
74061 + compute the exact length of the string we're trying to append
74062 + */
74063 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
74064 + spin_unlock(&gr_learn_lock);
74065 + wake_up_interruptible(&learn_wait);
74066 + return;
74067 + }
74068 + if (learn_buffer == NULL) {
74069 + spin_unlock(&gr_learn_lock);
74070 + return;
74071 + }
74072 +
74073 + va_start(args, fmt);
74074 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
74075 + va_end(args);
74076 +
74077 + learn_buffer_len += len + 1;
74078 +
74079 + spin_unlock(&gr_learn_lock);
74080 + wake_up_interruptible(&learn_wait);
74081 +
74082 + return;
74083 +}
74084 +
74085 +static int
74086 +open_learn(struct inode *inode, struct file *file)
74087 +{
74088 + if (file->f_mode & FMODE_READ && gr_learn_attached)
74089 + return -EBUSY;
74090 + if (file->f_mode & FMODE_READ) {
74091 + int retval = 0;
74092 + mutex_lock(&gr_learn_user_mutex);
74093 + if (learn_buffer == NULL)
74094 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
74095 + if (learn_buffer_user == NULL)
74096 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
74097 + if (learn_buffer == NULL) {
74098 + retval = -ENOMEM;
74099 + goto out_error;
74100 + }
74101 + if (learn_buffer_user == NULL) {
74102 + retval = -ENOMEM;
74103 + goto out_error;
74104 + }
74105 + learn_buffer_len = 0;
74106 + learn_buffer_user_len = 0;
74107 + gr_learn_attached = 1;
74108 +out_error:
74109 + mutex_unlock(&gr_learn_user_mutex);
74110 + return retval;
74111 + }
74112 + return 0;
74113 +}
74114 +
74115 +static int
74116 +close_learn(struct inode *inode, struct file *file)
74117 +{
74118 + if (file->f_mode & FMODE_READ) {
74119 + char *tmp = NULL;
74120 + mutex_lock(&gr_learn_user_mutex);
74121 + spin_lock(&gr_learn_lock);
74122 + tmp = learn_buffer;
74123 + learn_buffer = NULL;
74124 + spin_unlock(&gr_learn_lock);
74125 + if (tmp)
74126 + vfree(tmp);
74127 + if (learn_buffer_user != NULL) {
74128 + vfree(learn_buffer_user);
74129 + learn_buffer_user = NULL;
74130 + }
74131 + learn_buffer_len = 0;
74132 + learn_buffer_user_len = 0;
74133 + gr_learn_attached = 0;
74134 + mutex_unlock(&gr_learn_user_mutex);
74135 + }
74136 +
74137 + return 0;
74138 +}
74139 +
74140 +const struct file_operations grsec_fops = {
74141 + .read = read_learn,
74142 + .write = write_grsec_handler,
74143 + .open = open_learn,
74144 + .release = close_learn,
74145 + .poll = poll_learn,
74146 +};
74147 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74148 new file mode 100644
74149 index 0000000..3f8ade0
74150 --- /dev/null
74151 +++ b/grsecurity/gracl_policy.c
74152 @@ -0,0 +1,1782 @@
74153 +#include <linux/kernel.h>
74154 +#include <linux/module.h>
74155 +#include <linux/sched.h>
74156 +#include <linux/mm.h>
74157 +#include <linux/file.h>
74158 +#include <linux/fs.h>
74159 +#include <linux/namei.h>
74160 +#include <linux/mount.h>
74161 +#include <linux/tty.h>
74162 +#include <linux/proc_fs.h>
74163 +#include <linux/lglock.h>
74164 +#include <linux/slab.h>
74165 +#include <linux/vmalloc.h>
74166 +#include <linux/types.h>
74167 +#include <linux/sysctl.h>
74168 +#include <linux/netdevice.h>
74169 +#include <linux/ptrace.h>
74170 +#include <linux/gracl.h>
74171 +#include <linux/gralloc.h>
74172 +#include <linux/security.h>
74173 +#include <linux/grinternal.h>
74174 +#include <linux/pid_namespace.h>
74175 +#include <linux/stop_machine.h>
74176 +#include <linux/fdtable.h>
74177 +#include <linux/percpu.h>
74178 +#include <linux/lglock.h>
74179 +#include <linux/hugetlb.h>
74180 +#include <linux/posix-timers.h>
74181 +#include "../fs/mount.h"
74182 +
74183 +#include <asm/uaccess.h>
74184 +#include <asm/errno.h>
74185 +#include <asm/mman.h>
74186 +
74187 +extern struct gr_policy_state *polstate;
74188 +
74189 +#define FOR_EACH_ROLE_START(role) \
74190 + role = polstate->role_list; \
74191 + while (role) {
74192 +
74193 +#define FOR_EACH_ROLE_END(role) \
74194 + role = role->prev; \
74195 + }
74196 +
74197 +struct path gr_real_root;
74198 +
74199 +extern struct gr_alloc_state *current_alloc_state;
74200 +
74201 +u16 acl_sp_role_value;
74202 +
74203 +static DEFINE_MUTEX(gr_dev_mutex);
74204 +
74205 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74206 +extern void gr_clear_learn_entries(void);
74207 +
74208 +struct gr_arg *gr_usermode __read_only;
74209 +unsigned char *gr_system_salt __read_only;
74210 +unsigned char *gr_system_sum __read_only;
74211 +
74212 +static unsigned int gr_auth_attempts = 0;
74213 +static unsigned long gr_auth_expires = 0UL;
74214 +
74215 +struct acl_object_label *fakefs_obj_rw;
74216 +struct acl_object_label *fakefs_obj_rwx;
74217 +
74218 +extern int gr_init_uidset(void);
74219 +extern void gr_free_uidset(void);
74220 +extern void gr_remove_uid(uid_t uid);
74221 +extern int gr_find_uid(uid_t uid);
74222 +
74223 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74224 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74225 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74226 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74227 +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);
74228 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74229 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74230 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74231 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74232 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74233 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74234 +extern void assign_special_role(const char *rolename);
74235 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74236 +extern int gr_rbac_disable(void *unused);
74237 +extern void gr_enable_rbac_system(void);
74238 +
74239 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74240 +{
74241 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74242 + return -EFAULT;
74243 +
74244 + return 0;
74245 +}
74246 +
74247 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74248 +{
74249 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74250 + return -EFAULT;
74251 +
74252 + return 0;
74253 +}
74254 +
74255 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74256 +{
74257 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74258 + return -EFAULT;
74259 +
74260 + return 0;
74261 +}
74262 +
74263 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74264 +{
74265 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74266 + return -EFAULT;
74267 +
74268 + return 0;
74269 +}
74270 +
74271 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74272 +{
74273 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74274 + return -EFAULT;
74275 +
74276 + return 0;
74277 +}
74278 +
74279 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74280 +{
74281 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74282 + return -EFAULT;
74283 +
74284 + return 0;
74285 +}
74286 +
74287 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74288 +{
74289 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74290 + return -EFAULT;
74291 +
74292 + return 0;
74293 +}
74294 +
74295 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74296 +{
74297 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74298 + return -EFAULT;
74299 +
74300 + return 0;
74301 +}
74302 +
74303 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74304 +{
74305 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74306 + return -EFAULT;
74307 +
74308 + return 0;
74309 +}
74310 +
74311 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74312 +{
74313 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74314 + return -EFAULT;
74315 +
74316 + if (((uwrap->version != GRSECURITY_VERSION) &&
74317 + (uwrap->version != 0x2901)) ||
74318 + (uwrap->size != sizeof(struct gr_arg)))
74319 + return -EINVAL;
74320 +
74321 + return 0;
74322 +}
74323 +
74324 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74325 +{
74326 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74327 + return -EFAULT;
74328 +
74329 + return 0;
74330 +}
74331 +
74332 +static size_t get_gr_arg_wrapper_size_normal(void)
74333 +{
74334 + return sizeof(struct gr_arg_wrapper);
74335 +}
74336 +
74337 +#ifdef CONFIG_COMPAT
74338 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74339 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74340 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74341 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74342 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74343 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74344 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74345 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74346 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74347 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74348 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74349 +extern size_t get_gr_arg_wrapper_size_compat(void);
74350 +
74351 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74352 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74353 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74354 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74355 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74356 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74357 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74358 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74359 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74360 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74361 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74362 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74363 +
74364 +#else
74365 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74366 +#define copy_gr_arg copy_gr_arg_normal
74367 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74368 +#define copy_acl_object_label copy_acl_object_label_normal
74369 +#define copy_acl_subject_label copy_acl_subject_label_normal
74370 +#define copy_acl_role_label copy_acl_role_label_normal
74371 +#define copy_acl_ip_label copy_acl_ip_label_normal
74372 +#define copy_pointer_from_array copy_pointer_from_array_normal
74373 +#define copy_sprole_pw copy_sprole_pw_normal
74374 +#define copy_role_transition copy_role_transition_normal
74375 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74376 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74377 +#endif
74378 +
74379 +static struct acl_subject_label *
74380 +lookup_subject_map(const struct acl_subject_label *userp)
74381 +{
74382 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74383 + struct subject_map *match;
74384 +
74385 + match = polstate->subj_map_set.s_hash[index];
74386 +
74387 + while (match && match->user != userp)
74388 + match = match->next;
74389 +
74390 + if (match != NULL)
74391 + return match->kernel;
74392 + else
74393 + return NULL;
74394 +}
74395 +
74396 +static void
74397 +insert_subj_map_entry(struct subject_map *subjmap)
74398 +{
74399 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74400 + struct subject_map **curr;
74401 +
74402 + subjmap->prev = NULL;
74403 +
74404 + curr = &polstate->subj_map_set.s_hash[index];
74405 + if (*curr != NULL)
74406 + (*curr)->prev = subjmap;
74407 +
74408 + subjmap->next = *curr;
74409 + *curr = subjmap;
74410 +
74411 + return;
74412 +}
74413 +
74414 +static void
74415 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74416 +{
74417 + unsigned int index =
74418 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74419 + struct acl_role_label **curr;
74420 + struct acl_role_label *tmp, *tmp2;
74421 +
74422 + curr = &polstate->acl_role_set.r_hash[index];
74423 +
74424 + /* simple case, slot is empty, just set it to our role */
74425 + if (*curr == NULL) {
74426 + *curr = role;
74427 + } else {
74428 + /* example:
74429 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74430 + 2 -> 3
74431 + */
74432 + /* first check to see if we can already be reached via this slot */
74433 + tmp = *curr;
74434 + while (tmp && tmp != role)
74435 + tmp = tmp->next;
74436 + if (tmp == role) {
74437 + /* we don't need to add ourselves to this slot's chain */
74438 + return;
74439 + }
74440 + /* we need to add ourselves to this chain, two cases */
74441 + if (role->next == NULL) {
74442 + /* simple case, append the current chain to our role */
74443 + role->next = *curr;
74444 + *curr = role;
74445 + } else {
74446 + /* 1 -> 2 -> 3 -> 4
74447 + 2 -> 3 -> 4
74448 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74449 + */
74450 + /* trickier case: walk our role's chain until we find
74451 + the role for the start of the current slot's chain */
74452 + tmp = role;
74453 + tmp2 = *curr;
74454 + while (tmp->next && tmp->next != tmp2)
74455 + tmp = tmp->next;
74456 + if (tmp->next == tmp2) {
74457 + /* from example above, we found 3, so just
74458 + replace this slot's chain with ours */
74459 + *curr = role;
74460 + } else {
74461 + /* we didn't find a subset of our role's chain
74462 + in the current slot's chain, so append their
74463 + chain to ours, and set us as the first role in
74464 + the slot's chain
74465 +
74466 + we could fold this case with the case above,
74467 + but making it explicit for clarity
74468 + */
74469 + tmp->next = tmp2;
74470 + *curr = role;
74471 + }
74472 + }
74473 + }
74474 +
74475 + return;
74476 +}
74477 +
74478 +static void
74479 +insert_acl_role_label(struct acl_role_label *role)
74480 +{
74481 + int i;
74482 +
74483 + if (polstate->role_list == NULL) {
74484 + polstate->role_list = role;
74485 + role->prev = NULL;
74486 + } else {
74487 + role->prev = polstate->role_list;
74488 + polstate->role_list = role;
74489 + }
74490 +
74491 + /* used for hash chains */
74492 + role->next = NULL;
74493 +
74494 + if (role->roletype & GR_ROLE_DOMAIN) {
74495 + for (i = 0; i < role->domain_child_num; i++)
74496 + __insert_acl_role_label(role, role->domain_children[i]);
74497 + } else
74498 + __insert_acl_role_label(role, role->uidgid);
74499 +}
74500 +
74501 +static int
74502 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74503 +{
74504 + struct name_entry **curr, *nentry;
74505 + struct inodev_entry *ientry;
74506 + unsigned int len = strlen(name);
74507 + unsigned int key = full_name_hash(name, len);
74508 + unsigned int index = key % polstate->name_set.n_size;
74509 +
74510 + curr = &polstate->name_set.n_hash[index];
74511 +
74512 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74513 + curr = &((*curr)->next);
74514 +
74515 + if (*curr != NULL)
74516 + return 1;
74517 +
74518 + nentry = acl_alloc(sizeof (struct name_entry));
74519 + if (nentry == NULL)
74520 + return 0;
74521 + ientry = acl_alloc(sizeof (struct inodev_entry));
74522 + if (ientry == NULL)
74523 + return 0;
74524 + ientry->nentry = nentry;
74525 +
74526 + nentry->key = key;
74527 + nentry->name = name;
74528 + nentry->inode = inode;
74529 + nentry->device = device;
74530 + nentry->len = len;
74531 + nentry->deleted = deleted;
74532 +
74533 + nentry->prev = NULL;
74534 + curr = &polstate->name_set.n_hash[index];
74535 + if (*curr != NULL)
74536 + (*curr)->prev = nentry;
74537 + nentry->next = *curr;
74538 + *curr = nentry;
74539 +
74540 + /* insert us into the table searchable by inode/dev */
74541 + __insert_inodev_entry(polstate, ientry);
74542 +
74543 + return 1;
74544 +}
74545 +
74546 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74547 +
74548 +static void *
74549 +create_table(__u32 * len, int elementsize)
74550 +{
74551 + unsigned int table_sizes[] = {
74552 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74553 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74554 + 4194301, 8388593, 16777213, 33554393, 67108859
74555 + };
74556 + void *newtable = NULL;
74557 + unsigned int pwr = 0;
74558 +
74559 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74560 + table_sizes[pwr] <= *len)
74561 + pwr++;
74562 +
74563 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74564 + return newtable;
74565 +
74566 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74567 + newtable =
74568 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74569 + else
74570 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74571 +
74572 + *len = table_sizes[pwr];
74573 +
74574 + return newtable;
74575 +}
74576 +
74577 +static int
74578 +init_variables(const struct gr_arg *arg, bool reload)
74579 +{
74580 + struct task_struct *reaper = init_pid_ns.child_reaper;
74581 + unsigned int stacksize;
74582 +
74583 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74584 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74585 + polstate->name_set.n_size = arg->role_db.num_objects;
74586 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74587 +
74588 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74589 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74590 + return 1;
74591 +
74592 + if (!reload) {
74593 + if (!gr_init_uidset())
74594 + return 1;
74595 + }
74596 +
74597 + /* set up the stack that holds allocation info */
74598 +
74599 + stacksize = arg->role_db.num_pointers + 5;
74600 +
74601 + if (!acl_alloc_stack_init(stacksize))
74602 + return 1;
74603 +
74604 + if (!reload) {
74605 + /* grab reference for the real root dentry and vfsmount */
74606 + get_fs_root(reaper->fs, &gr_real_root);
74607 +
74608 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74609 + 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);
74610 +#endif
74611 +
74612 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74613 + if (fakefs_obj_rw == NULL)
74614 + return 1;
74615 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74616 +
74617 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74618 + if (fakefs_obj_rwx == NULL)
74619 + return 1;
74620 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74621 + }
74622 +
74623 + polstate->subj_map_set.s_hash =
74624 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74625 + polstate->acl_role_set.r_hash =
74626 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74627 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74628 + polstate->inodev_set.i_hash =
74629 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74630 +
74631 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74632 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74633 + return 1;
74634 +
74635 + memset(polstate->subj_map_set.s_hash, 0,
74636 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74637 + memset(polstate->acl_role_set.r_hash, 0,
74638 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74639 + memset(polstate->name_set.n_hash, 0,
74640 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74641 + memset(polstate->inodev_set.i_hash, 0,
74642 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74643 +
74644 + return 0;
74645 +}
74646 +
74647 +/* free information not needed after startup
74648 + currently contains user->kernel pointer mappings for subjects
74649 +*/
74650 +
74651 +static void
74652 +free_init_variables(void)
74653 +{
74654 + __u32 i;
74655 +
74656 + if (polstate->subj_map_set.s_hash) {
74657 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74658 + if (polstate->subj_map_set.s_hash[i]) {
74659 + kfree(polstate->subj_map_set.s_hash[i]);
74660 + polstate->subj_map_set.s_hash[i] = NULL;
74661 + }
74662 + }
74663 +
74664 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74665 + PAGE_SIZE)
74666 + kfree(polstate->subj_map_set.s_hash);
74667 + else
74668 + vfree(polstate->subj_map_set.s_hash);
74669 + }
74670 +
74671 + return;
74672 +}
74673 +
74674 +static void
74675 +free_variables(bool reload)
74676 +{
74677 + struct acl_subject_label *s;
74678 + struct acl_role_label *r;
74679 + struct task_struct *task, *task2;
74680 + unsigned int x;
74681 +
74682 + if (!reload) {
74683 + gr_clear_learn_entries();
74684 +
74685 + read_lock(&tasklist_lock);
74686 + do_each_thread(task2, task) {
74687 + task->acl_sp_role = 0;
74688 + task->acl_role_id = 0;
74689 + task->inherited = 0;
74690 + task->acl = NULL;
74691 + task->role = NULL;
74692 + } while_each_thread(task2, task);
74693 + read_unlock(&tasklist_lock);
74694 +
74695 + kfree(fakefs_obj_rw);
74696 + fakefs_obj_rw = NULL;
74697 + kfree(fakefs_obj_rwx);
74698 + fakefs_obj_rwx = NULL;
74699 +
74700 + /* release the reference to the real root dentry and vfsmount */
74701 + path_put(&gr_real_root);
74702 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74703 + }
74704 +
74705 + /* free all object hash tables */
74706 +
74707 + FOR_EACH_ROLE_START(r)
74708 + if (r->subj_hash == NULL)
74709 + goto next_role;
74710 + FOR_EACH_SUBJECT_START(r, s, x)
74711 + if (s->obj_hash == NULL)
74712 + break;
74713 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74714 + kfree(s->obj_hash);
74715 + else
74716 + vfree(s->obj_hash);
74717 + FOR_EACH_SUBJECT_END(s, x)
74718 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74719 + if (s->obj_hash == NULL)
74720 + break;
74721 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74722 + kfree(s->obj_hash);
74723 + else
74724 + vfree(s->obj_hash);
74725 + FOR_EACH_NESTED_SUBJECT_END(s)
74726 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74727 + kfree(r->subj_hash);
74728 + else
74729 + vfree(r->subj_hash);
74730 + r->subj_hash = NULL;
74731 +next_role:
74732 + FOR_EACH_ROLE_END(r)
74733 +
74734 + acl_free_all();
74735 +
74736 + if (polstate->acl_role_set.r_hash) {
74737 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74738 + PAGE_SIZE)
74739 + kfree(polstate->acl_role_set.r_hash);
74740 + else
74741 + vfree(polstate->acl_role_set.r_hash);
74742 + }
74743 + if (polstate->name_set.n_hash) {
74744 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74745 + PAGE_SIZE)
74746 + kfree(polstate->name_set.n_hash);
74747 + else
74748 + vfree(polstate->name_set.n_hash);
74749 + }
74750 +
74751 + if (polstate->inodev_set.i_hash) {
74752 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74753 + PAGE_SIZE)
74754 + kfree(polstate->inodev_set.i_hash);
74755 + else
74756 + vfree(polstate->inodev_set.i_hash);
74757 + }
74758 +
74759 + if (!reload)
74760 + gr_free_uidset();
74761 +
74762 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74763 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74764 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74765 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74766 +
74767 + polstate->default_role = NULL;
74768 + polstate->kernel_role = NULL;
74769 + polstate->role_list = NULL;
74770 +
74771 + return;
74772 +}
74773 +
74774 +static struct acl_subject_label *
74775 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74776 +
74777 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74778 +{
74779 + unsigned int len = strnlen_user(*name, maxlen);
74780 + char *tmp;
74781 +
74782 + if (!len || len >= maxlen)
74783 + return -EINVAL;
74784 +
74785 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74786 + return -ENOMEM;
74787 +
74788 + if (copy_from_user(tmp, *name, len))
74789 + return -EFAULT;
74790 +
74791 + tmp[len-1] = '\0';
74792 + *name = tmp;
74793 +
74794 + return 0;
74795 +}
74796 +
74797 +static int
74798 +copy_user_glob(struct acl_object_label *obj)
74799 +{
74800 + struct acl_object_label *g_tmp, **guser;
74801 + int error;
74802 +
74803 + if (obj->globbed == NULL)
74804 + return 0;
74805 +
74806 + guser = &obj->globbed;
74807 + while (*guser) {
74808 + g_tmp = (struct acl_object_label *)
74809 + acl_alloc(sizeof (struct acl_object_label));
74810 + if (g_tmp == NULL)
74811 + return -ENOMEM;
74812 +
74813 + if (copy_acl_object_label(g_tmp, *guser))
74814 + return -EFAULT;
74815 +
74816 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74817 + if (error)
74818 + return error;
74819 +
74820 + *guser = g_tmp;
74821 + guser = &(g_tmp->next);
74822 + }
74823 +
74824 + return 0;
74825 +}
74826 +
74827 +static int
74828 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74829 + struct acl_role_label *role)
74830 +{
74831 + struct acl_object_label *o_tmp;
74832 + int ret;
74833 +
74834 + while (userp) {
74835 + if ((o_tmp = (struct acl_object_label *)
74836 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74837 + return -ENOMEM;
74838 +
74839 + if (copy_acl_object_label(o_tmp, userp))
74840 + return -EFAULT;
74841 +
74842 + userp = o_tmp->prev;
74843 +
74844 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74845 + if (ret)
74846 + return ret;
74847 +
74848 + insert_acl_obj_label(o_tmp, subj);
74849 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74850 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74851 + return -ENOMEM;
74852 +
74853 + ret = copy_user_glob(o_tmp);
74854 + if (ret)
74855 + return ret;
74856 +
74857 + if (o_tmp->nested) {
74858 + int already_copied;
74859 +
74860 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74861 + if (IS_ERR(o_tmp->nested))
74862 + return PTR_ERR(o_tmp->nested);
74863 +
74864 + /* insert into nested subject list if we haven't copied this one yet
74865 + to prevent duplicate entries */
74866 + if (!already_copied) {
74867 + o_tmp->nested->next = role->hash->first;
74868 + role->hash->first = o_tmp->nested;
74869 + }
74870 + }
74871 + }
74872 +
74873 + return 0;
74874 +}
74875 +
74876 +static __u32
74877 +count_user_subjs(struct acl_subject_label *userp)
74878 +{
74879 + struct acl_subject_label s_tmp;
74880 + __u32 num = 0;
74881 +
74882 + while (userp) {
74883 + if (copy_acl_subject_label(&s_tmp, userp))
74884 + break;
74885 +
74886 + userp = s_tmp.prev;
74887 + }
74888 +
74889 + return num;
74890 +}
74891 +
74892 +static int
74893 +copy_user_allowedips(struct acl_role_label *rolep)
74894 +{
74895 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74896 +
74897 + ruserip = rolep->allowed_ips;
74898 +
74899 + while (ruserip) {
74900 + rlast = rtmp;
74901 +
74902 + if ((rtmp = (struct role_allowed_ip *)
74903 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74904 + return -ENOMEM;
74905 +
74906 + if (copy_role_allowed_ip(rtmp, ruserip))
74907 + return -EFAULT;
74908 +
74909 + ruserip = rtmp->prev;
74910 +
74911 + if (!rlast) {
74912 + rtmp->prev = NULL;
74913 + rolep->allowed_ips = rtmp;
74914 + } else {
74915 + rlast->next = rtmp;
74916 + rtmp->prev = rlast;
74917 + }
74918 +
74919 + if (!ruserip)
74920 + rtmp->next = NULL;
74921 + }
74922 +
74923 + return 0;
74924 +}
74925 +
74926 +static int
74927 +copy_user_transitions(struct acl_role_label *rolep)
74928 +{
74929 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74930 + int error;
74931 +
74932 + rusertp = rolep->transitions;
74933 +
74934 + while (rusertp) {
74935 + rlast = rtmp;
74936 +
74937 + if ((rtmp = (struct role_transition *)
74938 + acl_alloc(sizeof (struct role_transition))) == NULL)
74939 + return -ENOMEM;
74940 +
74941 + if (copy_role_transition(rtmp, rusertp))
74942 + return -EFAULT;
74943 +
74944 + rusertp = rtmp->prev;
74945 +
74946 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74947 + if (error)
74948 + return error;
74949 +
74950 + if (!rlast) {
74951 + rtmp->prev = NULL;
74952 + rolep->transitions = rtmp;
74953 + } else {
74954 + rlast->next = rtmp;
74955 + rtmp->prev = rlast;
74956 + }
74957 +
74958 + if (!rusertp)
74959 + rtmp->next = NULL;
74960 + }
74961 +
74962 + return 0;
74963 +}
74964 +
74965 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74966 +{
74967 + struct acl_object_label o_tmp;
74968 + __u32 num = 0;
74969 +
74970 + while (userp) {
74971 + if (copy_acl_object_label(&o_tmp, userp))
74972 + break;
74973 +
74974 + userp = o_tmp.prev;
74975 + num++;
74976 + }
74977 +
74978 + return num;
74979 +}
74980 +
74981 +static struct acl_subject_label *
74982 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74983 +{
74984 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74985 + __u32 num_objs;
74986 + struct acl_ip_label **i_tmp, *i_utmp2;
74987 + struct gr_hash_struct ghash;
74988 + struct subject_map *subjmap;
74989 + unsigned int i_num;
74990 + int err;
74991 +
74992 + if (already_copied != NULL)
74993 + *already_copied = 0;
74994 +
74995 + s_tmp = lookup_subject_map(userp);
74996 +
74997 + /* we've already copied this subject into the kernel, just return
74998 + the reference to it, and don't copy it over again
74999 + */
75000 + if (s_tmp) {
75001 + if (already_copied != NULL)
75002 + *already_copied = 1;
75003 + return(s_tmp);
75004 + }
75005 +
75006 + if ((s_tmp = (struct acl_subject_label *)
75007 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
75008 + return ERR_PTR(-ENOMEM);
75009 +
75010 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
75011 + if (subjmap == NULL)
75012 + return ERR_PTR(-ENOMEM);
75013 +
75014 + subjmap->user = userp;
75015 + subjmap->kernel = s_tmp;
75016 + insert_subj_map_entry(subjmap);
75017 +
75018 + if (copy_acl_subject_label(s_tmp, userp))
75019 + return ERR_PTR(-EFAULT);
75020 +
75021 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
75022 + if (err)
75023 + return ERR_PTR(err);
75024 +
75025 + if (!strcmp(s_tmp->filename, "/"))
75026 + role->root_label = s_tmp;
75027 +
75028 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
75029 + return ERR_PTR(-EFAULT);
75030 +
75031 + /* copy user and group transition tables */
75032 +
75033 + if (s_tmp->user_trans_num) {
75034 + uid_t *uidlist;
75035 +
75036 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
75037 + if (uidlist == NULL)
75038 + return ERR_PTR(-ENOMEM);
75039 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
75040 + return ERR_PTR(-EFAULT);
75041 +
75042 + s_tmp->user_transitions = uidlist;
75043 + }
75044 +
75045 + if (s_tmp->group_trans_num) {
75046 + gid_t *gidlist;
75047 +
75048 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
75049 + if (gidlist == NULL)
75050 + return ERR_PTR(-ENOMEM);
75051 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
75052 + return ERR_PTR(-EFAULT);
75053 +
75054 + s_tmp->group_transitions = gidlist;
75055 + }
75056 +
75057 + /* set up object hash table */
75058 + num_objs = count_user_objs(ghash.first);
75059 +
75060 + s_tmp->obj_hash_size = num_objs;
75061 + s_tmp->obj_hash =
75062 + (struct acl_object_label **)
75063 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
75064 +
75065 + if (!s_tmp->obj_hash)
75066 + return ERR_PTR(-ENOMEM);
75067 +
75068 + memset(s_tmp->obj_hash, 0,
75069 + s_tmp->obj_hash_size *
75070 + sizeof (struct acl_object_label *));
75071 +
75072 + /* add in objects */
75073 + err = copy_user_objs(ghash.first, s_tmp, role);
75074 +
75075 + if (err)
75076 + return ERR_PTR(err);
75077 +
75078 + /* set pointer for parent subject */
75079 + if (s_tmp->parent_subject) {
75080 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
75081 +
75082 + if (IS_ERR(s_tmp2))
75083 + return s_tmp2;
75084 +
75085 + s_tmp->parent_subject = s_tmp2;
75086 + }
75087 +
75088 + /* add in ip acls */
75089 +
75090 + if (!s_tmp->ip_num) {
75091 + s_tmp->ips = NULL;
75092 + goto insert;
75093 + }
75094 +
75095 + i_tmp =
75096 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
75097 + sizeof (struct acl_ip_label *));
75098 +
75099 + if (!i_tmp)
75100 + return ERR_PTR(-ENOMEM);
75101 +
75102 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
75103 + *(i_tmp + i_num) =
75104 + (struct acl_ip_label *)
75105 + acl_alloc(sizeof (struct acl_ip_label));
75106 + if (!*(i_tmp + i_num))
75107 + return ERR_PTR(-ENOMEM);
75108 +
75109 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
75110 + return ERR_PTR(-EFAULT);
75111 +
75112 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
75113 + return ERR_PTR(-EFAULT);
75114 +
75115 + if ((*(i_tmp + i_num))->iface == NULL)
75116 + continue;
75117 +
75118 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
75119 + if (err)
75120 + return ERR_PTR(err);
75121 + }
75122 +
75123 + s_tmp->ips = i_tmp;
75124 +
75125 +insert:
75126 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
75127 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
75128 + return ERR_PTR(-ENOMEM);
75129 +
75130 + return s_tmp;
75131 +}
75132 +
75133 +static int
75134 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75135 +{
75136 + struct acl_subject_label s_pre;
75137 + struct acl_subject_label * ret;
75138 + int err;
75139 +
75140 + while (userp) {
75141 + if (copy_acl_subject_label(&s_pre, userp))
75142 + return -EFAULT;
75143 +
75144 + ret = do_copy_user_subj(userp, role, NULL);
75145 +
75146 + err = PTR_ERR(ret);
75147 + if (IS_ERR(ret))
75148 + return err;
75149 +
75150 + insert_acl_subj_label(ret, role);
75151 +
75152 + userp = s_pre.prev;
75153 + }
75154 +
75155 + return 0;
75156 +}
75157 +
75158 +static int
75159 +copy_user_acl(struct gr_arg *arg)
75160 +{
75161 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75162 + struct acl_subject_label *subj_list;
75163 + struct sprole_pw *sptmp;
75164 + struct gr_hash_struct *ghash;
75165 + uid_t *domainlist;
75166 + unsigned int r_num;
75167 + int err = 0;
75168 + __u16 i;
75169 + __u32 num_subjs;
75170 +
75171 + /* we need a default and kernel role */
75172 + if (arg->role_db.num_roles < 2)
75173 + return -EINVAL;
75174 +
75175 + /* copy special role authentication info from userspace */
75176 +
75177 + polstate->num_sprole_pws = arg->num_sprole_pws;
75178 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75179 +
75180 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75181 + return -ENOMEM;
75182 +
75183 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75184 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75185 + if (!sptmp)
75186 + return -ENOMEM;
75187 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75188 + return -EFAULT;
75189 +
75190 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75191 + if (err)
75192 + return err;
75193 +
75194 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75195 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75196 +#endif
75197 +
75198 + polstate->acl_special_roles[i] = sptmp;
75199 + }
75200 +
75201 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75202 +
75203 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75204 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
75205 +
75206 + if (!r_tmp)
75207 + return -ENOMEM;
75208 +
75209 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75210 + return -EFAULT;
75211 +
75212 + if (copy_acl_role_label(r_tmp, r_utmp2))
75213 + return -EFAULT;
75214 +
75215 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75216 + if (err)
75217 + return err;
75218 +
75219 + if (!strcmp(r_tmp->rolename, "default")
75220 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75221 + polstate->default_role = r_tmp;
75222 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75223 + polstate->kernel_role = r_tmp;
75224 + }
75225 +
75226 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75227 + return -ENOMEM;
75228 +
75229 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
75230 + return -EFAULT;
75231 +
75232 + r_tmp->hash = ghash;
75233 +
75234 + num_subjs = count_user_subjs(r_tmp->hash->first);
75235 +
75236 + r_tmp->subj_hash_size = num_subjs;
75237 + r_tmp->subj_hash =
75238 + (struct acl_subject_label **)
75239 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75240 +
75241 + if (!r_tmp->subj_hash)
75242 + return -ENOMEM;
75243 +
75244 + err = copy_user_allowedips(r_tmp);
75245 + if (err)
75246 + return err;
75247 +
75248 + /* copy domain info */
75249 + if (r_tmp->domain_children != NULL) {
75250 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75251 + if (domainlist == NULL)
75252 + return -ENOMEM;
75253 +
75254 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75255 + return -EFAULT;
75256 +
75257 + r_tmp->domain_children = domainlist;
75258 + }
75259 +
75260 + err = copy_user_transitions(r_tmp);
75261 + if (err)
75262 + return err;
75263 +
75264 + memset(r_tmp->subj_hash, 0,
75265 + r_tmp->subj_hash_size *
75266 + sizeof (struct acl_subject_label *));
75267 +
75268 + /* acquire the list of subjects, then NULL out
75269 + the list prior to parsing the subjects for this role,
75270 + as during this parsing the list is replaced with a list
75271 + of *nested* subjects for the role
75272 + */
75273 + subj_list = r_tmp->hash->first;
75274 +
75275 + /* set nested subject list to null */
75276 + r_tmp->hash->first = NULL;
75277 +
75278 + err = copy_user_subjs(subj_list, r_tmp);
75279 +
75280 + if (err)
75281 + return err;
75282 +
75283 + insert_acl_role_label(r_tmp);
75284 + }
75285 +
75286 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75287 + return -EINVAL;
75288 +
75289 + return err;
75290 +}
75291 +
75292 +static int gracl_reload_apply_policies(void *reload)
75293 +{
75294 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75295 + struct task_struct *task, *task2;
75296 + struct acl_role_label *role, *rtmp;
75297 + struct acl_subject_label *subj;
75298 + const struct cred *cred;
75299 + int role_applied;
75300 + int ret = 0;
75301 +
75302 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75303 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75304 +
75305 + /* first make sure we'll be able to apply the new policy cleanly */
75306 + do_each_thread(task2, task) {
75307 + if (task->exec_file == NULL)
75308 + continue;
75309 + role_applied = 0;
75310 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75311 + /* preserve special roles */
75312 + FOR_EACH_ROLE_START(role)
75313 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75314 + rtmp = task->role;
75315 + task->role = role;
75316 + role_applied = 1;
75317 + break;
75318 + }
75319 + FOR_EACH_ROLE_END(role)
75320 + }
75321 + if (!role_applied) {
75322 + cred = __task_cred(task);
75323 + rtmp = task->role;
75324 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75325 + }
75326 + /* this handles non-nested inherited subjects, nested subjects will still
75327 + be dropped currently */
75328 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75329 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75330 + /* change the role back so that we've made no modifications to the policy */
75331 + task->role = rtmp;
75332 +
75333 + if (subj == NULL || task->tmpacl == NULL) {
75334 + ret = -EINVAL;
75335 + goto out;
75336 + }
75337 + } while_each_thread(task2, task);
75338 +
75339 + /* now actually apply the policy */
75340 +
75341 + do_each_thread(task2, task) {
75342 + if (task->exec_file) {
75343 + role_applied = 0;
75344 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75345 + /* preserve special roles */
75346 + FOR_EACH_ROLE_START(role)
75347 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75348 + task->role = role;
75349 + role_applied = 1;
75350 + break;
75351 + }
75352 + FOR_EACH_ROLE_END(role)
75353 + }
75354 + if (!role_applied) {
75355 + cred = __task_cred(task);
75356 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75357 + }
75358 + /* this handles non-nested inherited subjects, nested subjects will still
75359 + be dropped currently */
75360 + if (!reload_state->oldmode && task->inherited)
75361 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75362 + else {
75363 + /* looked up and tagged to the task previously */
75364 + subj = task->tmpacl;
75365 + }
75366 + /* subj will be non-null */
75367 + __gr_apply_subject_to_task(polstate, task, subj);
75368 + if (reload_state->oldmode) {
75369 + task->acl_role_id = 0;
75370 + task->acl_sp_role = 0;
75371 + task->inherited = 0;
75372 + }
75373 + } else {
75374 + // it's a kernel process
75375 + task->role = polstate->kernel_role;
75376 + task->acl = polstate->kernel_role->root_label;
75377 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75378 + task->acl->mode &= ~GR_PROCFIND;
75379 +#endif
75380 + }
75381 + } while_each_thread(task2, task);
75382 +
75383 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75384 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75385 +
75386 +out:
75387 +
75388 + return ret;
75389 +}
75390 +
75391 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75392 +{
75393 + struct gr_reload_state new_reload_state = { };
75394 + int err;
75395 +
75396 + new_reload_state.oldpolicy_ptr = polstate;
75397 + new_reload_state.oldalloc_ptr = current_alloc_state;
75398 + new_reload_state.oldmode = oldmode;
75399 +
75400 + current_alloc_state = &new_reload_state.newalloc;
75401 + polstate = &new_reload_state.newpolicy;
75402 +
75403 + /* everything relevant is now saved off, copy in the new policy */
75404 + if (init_variables(args, true)) {
75405 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75406 + err = -ENOMEM;
75407 + goto error;
75408 + }
75409 +
75410 + err = copy_user_acl(args);
75411 + free_init_variables();
75412 + if (err)
75413 + goto error;
75414 + /* the new policy is copied in, with the old policy available via saved_state
75415 + first go through applying roles, making sure to preserve special roles
75416 + then apply new subjects, making sure to preserve inherited and nested subjects,
75417 + though currently only inherited subjects will be preserved
75418 + */
75419 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75420 + if (err)
75421 + goto error;
75422 +
75423 + /* we've now applied the new policy, so restore the old policy state to free it */
75424 + polstate = &new_reload_state.oldpolicy;
75425 + current_alloc_state = &new_reload_state.oldalloc;
75426 + free_variables(true);
75427 +
75428 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75429 + to running_polstate/current_alloc_state inside stop_machine
75430 + */
75431 + err = 0;
75432 + goto out;
75433 +error:
75434 + /* on error of loading the new policy, we'll just keep the previous
75435 + policy set around
75436 + */
75437 + free_variables(true);
75438 +
75439 + /* doesn't affect runtime, but maintains consistent state */
75440 +out:
75441 + polstate = new_reload_state.oldpolicy_ptr;
75442 + current_alloc_state = new_reload_state.oldalloc_ptr;
75443 +
75444 + return err;
75445 +}
75446 +
75447 +static int
75448 +gracl_init(struct gr_arg *args)
75449 +{
75450 + int error = 0;
75451 +
75452 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75453 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75454 +
75455 + if (init_variables(args, false)) {
75456 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75457 + error = -ENOMEM;
75458 + goto out;
75459 + }
75460 +
75461 + error = copy_user_acl(args);
75462 + free_init_variables();
75463 + if (error)
75464 + goto out;
75465 +
75466 + error = gr_set_acls(0);
75467 + if (error)
75468 + goto out;
75469 +
75470 + gr_enable_rbac_system();
75471 +
75472 + return 0;
75473 +
75474 +out:
75475 + free_variables(false);
75476 + return error;
75477 +}
75478 +
75479 +static int
75480 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75481 + unsigned char **sum)
75482 +{
75483 + struct acl_role_label *r;
75484 + struct role_allowed_ip *ipp;
75485 + struct role_transition *trans;
75486 + unsigned int i;
75487 + int found = 0;
75488 + u32 curr_ip = current->signal->curr_ip;
75489 +
75490 + current->signal->saved_ip = curr_ip;
75491 +
75492 + /* check transition table */
75493 +
75494 + for (trans = current->role->transitions; trans; trans = trans->next) {
75495 + if (!strcmp(rolename, trans->rolename)) {
75496 + found = 1;
75497 + break;
75498 + }
75499 + }
75500 +
75501 + if (!found)
75502 + return 0;
75503 +
75504 + /* handle special roles that do not require authentication
75505 + and check ip */
75506 +
75507 + FOR_EACH_ROLE_START(r)
75508 + if (!strcmp(rolename, r->rolename) &&
75509 + (r->roletype & GR_ROLE_SPECIAL)) {
75510 + found = 0;
75511 + if (r->allowed_ips != NULL) {
75512 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75513 + if ((ntohl(curr_ip) & ipp->netmask) ==
75514 + (ntohl(ipp->addr) & ipp->netmask))
75515 + found = 1;
75516 + }
75517 + } else
75518 + found = 2;
75519 + if (!found)
75520 + return 0;
75521 +
75522 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75523 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75524 + *salt = NULL;
75525 + *sum = NULL;
75526 + return 1;
75527 + }
75528 + }
75529 + FOR_EACH_ROLE_END(r)
75530 +
75531 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75532 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75533 + *salt = polstate->acl_special_roles[i]->salt;
75534 + *sum = polstate->acl_special_roles[i]->sum;
75535 + return 1;
75536 + }
75537 + }
75538 +
75539 + return 0;
75540 +}
75541 +
75542 +int gr_check_secure_terminal(struct task_struct *task)
75543 +{
75544 + struct task_struct *p, *p2, *p3;
75545 + struct files_struct *files;
75546 + struct fdtable *fdt;
75547 + struct file *our_file = NULL, *file;
75548 + int i;
75549 +
75550 + if (task->signal->tty == NULL)
75551 + return 1;
75552 +
75553 + files = get_files_struct(task);
75554 + if (files != NULL) {
75555 + rcu_read_lock();
75556 + fdt = files_fdtable(files);
75557 + for (i=0; i < fdt->max_fds; i++) {
75558 + file = fcheck_files(files, i);
75559 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75560 + get_file(file);
75561 + our_file = file;
75562 + }
75563 + }
75564 + rcu_read_unlock();
75565 + put_files_struct(files);
75566 + }
75567 +
75568 + if (our_file == NULL)
75569 + return 1;
75570 +
75571 + read_lock(&tasklist_lock);
75572 + do_each_thread(p2, p) {
75573 + files = get_files_struct(p);
75574 + if (files == NULL ||
75575 + (p->signal && p->signal->tty == task->signal->tty)) {
75576 + if (files != NULL)
75577 + put_files_struct(files);
75578 + continue;
75579 + }
75580 + rcu_read_lock();
75581 + fdt = files_fdtable(files);
75582 + for (i=0; i < fdt->max_fds; i++) {
75583 + file = fcheck_files(files, i);
75584 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75585 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75586 + p3 = task;
75587 + while (task_pid_nr(p3) > 0) {
75588 + if (p3 == p)
75589 + break;
75590 + p3 = p3->real_parent;
75591 + }
75592 + if (p3 == p)
75593 + break;
75594 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75595 + gr_handle_alertkill(p);
75596 + rcu_read_unlock();
75597 + put_files_struct(files);
75598 + read_unlock(&tasklist_lock);
75599 + fput(our_file);
75600 + return 0;
75601 + }
75602 + }
75603 + rcu_read_unlock();
75604 + put_files_struct(files);
75605 + } while_each_thread(p2, p);
75606 + read_unlock(&tasklist_lock);
75607 +
75608 + fput(our_file);
75609 + return 1;
75610 +}
75611 +
75612 +ssize_t
75613 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75614 +{
75615 + struct gr_arg_wrapper uwrap;
75616 + unsigned char *sprole_salt = NULL;
75617 + unsigned char *sprole_sum = NULL;
75618 + int error = 0;
75619 + int error2 = 0;
75620 + size_t req_count = 0;
75621 + unsigned char oldmode = 0;
75622 +
75623 + mutex_lock(&gr_dev_mutex);
75624 +
75625 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75626 + error = -EPERM;
75627 + goto out;
75628 + }
75629 +
75630 +#ifdef CONFIG_COMPAT
75631 + pax_open_kernel();
75632 + if (is_compat_task()) {
75633 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75634 + copy_gr_arg = &copy_gr_arg_compat;
75635 + copy_acl_object_label = &copy_acl_object_label_compat;
75636 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75637 + copy_acl_role_label = &copy_acl_role_label_compat;
75638 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75639 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75640 + copy_role_transition = &copy_role_transition_compat;
75641 + copy_sprole_pw = &copy_sprole_pw_compat;
75642 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75643 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75644 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75645 + } else {
75646 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75647 + copy_gr_arg = &copy_gr_arg_normal;
75648 + copy_acl_object_label = &copy_acl_object_label_normal;
75649 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75650 + copy_acl_role_label = &copy_acl_role_label_normal;
75651 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75652 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75653 + copy_role_transition = &copy_role_transition_normal;
75654 + copy_sprole_pw = &copy_sprole_pw_normal;
75655 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75656 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75657 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75658 + }
75659 + pax_close_kernel();
75660 +#endif
75661 +
75662 + req_count = get_gr_arg_wrapper_size();
75663 +
75664 + if (count != req_count) {
75665 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75666 + error = -EINVAL;
75667 + goto out;
75668 + }
75669 +
75670 +
75671 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75672 + gr_auth_expires = 0;
75673 + gr_auth_attempts = 0;
75674 + }
75675 +
75676 + error = copy_gr_arg_wrapper(buf, &uwrap);
75677 + if (error)
75678 + goto out;
75679 +
75680 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75681 + if (error)
75682 + goto out;
75683 +
75684 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75685 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75686 + time_after(gr_auth_expires, get_seconds())) {
75687 + error = -EBUSY;
75688 + goto out;
75689 + }
75690 +
75691 + /* if non-root trying to do anything other than use a special role,
75692 + do not attempt authentication, do not count towards authentication
75693 + locking
75694 + */
75695 +
75696 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75697 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75698 + gr_is_global_nonroot(current_uid())) {
75699 + error = -EPERM;
75700 + goto out;
75701 + }
75702 +
75703 + /* ensure pw and special role name are null terminated */
75704 +
75705 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75706 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75707 +
75708 + /* Okay.
75709 + * We have our enough of the argument structure..(we have yet
75710 + * to copy_from_user the tables themselves) . Copy the tables
75711 + * only if we need them, i.e. for loading operations. */
75712 +
75713 + switch (gr_usermode->mode) {
75714 + case GR_STATUS:
75715 + if (gr_acl_is_enabled()) {
75716 + error = 1;
75717 + if (!gr_check_secure_terminal(current))
75718 + error = 3;
75719 + } else
75720 + error = 2;
75721 + goto out;
75722 + case GR_SHUTDOWN:
75723 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75724 + stop_machine(gr_rbac_disable, NULL, NULL);
75725 + free_variables(false);
75726 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75727 + memset(gr_system_salt, 0, GR_SALT_LEN);
75728 + memset(gr_system_sum, 0, GR_SHA_LEN);
75729 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75730 + } else if (gr_acl_is_enabled()) {
75731 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75732 + error = -EPERM;
75733 + } else {
75734 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75735 + error = -EAGAIN;
75736 + }
75737 + break;
75738 + case GR_ENABLE:
75739 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75740 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75741 + else {
75742 + if (gr_acl_is_enabled())
75743 + error = -EAGAIN;
75744 + else
75745 + error = error2;
75746 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75747 + }
75748 + break;
75749 + case GR_OLDRELOAD:
75750 + oldmode = 1;
75751 + case GR_RELOAD:
75752 + if (!gr_acl_is_enabled()) {
75753 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75754 + error = -EAGAIN;
75755 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75756 + error2 = gracl_reload(gr_usermode, oldmode);
75757 + if (!error2)
75758 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75759 + else {
75760 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75761 + error = error2;
75762 + }
75763 + } else {
75764 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75765 + error = -EPERM;
75766 + }
75767 + break;
75768 + case GR_SEGVMOD:
75769 + if (unlikely(!gr_acl_is_enabled())) {
75770 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75771 + error = -EAGAIN;
75772 + break;
75773 + }
75774 +
75775 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75776 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75777 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75778 + struct acl_subject_label *segvacl;
75779 + segvacl =
75780 + lookup_acl_subj_label(gr_usermode->segv_inode,
75781 + gr_usermode->segv_device,
75782 + current->role);
75783 + if (segvacl) {
75784 + segvacl->crashes = 0;
75785 + segvacl->expires = 0;
75786 + }
75787 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75788 + gr_remove_uid(gr_usermode->segv_uid);
75789 + }
75790 + } else {
75791 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75792 + error = -EPERM;
75793 + }
75794 + break;
75795 + case GR_SPROLE:
75796 + case GR_SPROLEPAM:
75797 + if (unlikely(!gr_acl_is_enabled())) {
75798 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75799 + error = -EAGAIN;
75800 + break;
75801 + }
75802 +
75803 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75804 + current->role->expires = 0;
75805 + current->role->auth_attempts = 0;
75806 + }
75807 +
75808 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75809 + time_after(current->role->expires, get_seconds())) {
75810 + error = -EBUSY;
75811 + goto out;
75812 + }
75813 +
75814 + if (lookup_special_role_auth
75815 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75816 + && ((!sprole_salt && !sprole_sum)
75817 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75818 + char *p = "";
75819 + assign_special_role(gr_usermode->sp_role);
75820 + read_lock(&tasklist_lock);
75821 + if (current->real_parent)
75822 + p = current->real_parent->role->rolename;
75823 + read_unlock(&tasklist_lock);
75824 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75825 + p, acl_sp_role_value);
75826 + } else {
75827 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75828 + error = -EPERM;
75829 + if(!(current->role->auth_attempts++))
75830 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75831 +
75832 + goto out;
75833 + }
75834 + break;
75835 + case GR_UNSPROLE:
75836 + if (unlikely(!gr_acl_is_enabled())) {
75837 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75838 + error = -EAGAIN;
75839 + break;
75840 + }
75841 +
75842 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75843 + char *p = "";
75844 + int i = 0;
75845 +
75846 + read_lock(&tasklist_lock);
75847 + if (current->real_parent) {
75848 + p = current->real_parent->role->rolename;
75849 + i = current->real_parent->acl_role_id;
75850 + }
75851 + read_unlock(&tasklist_lock);
75852 +
75853 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75854 + gr_set_acls(1);
75855 + } else {
75856 + error = -EPERM;
75857 + goto out;
75858 + }
75859 + break;
75860 + default:
75861 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75862 + error = -EINVAL;
75863 + break;
75864 + }
75865 +
75866 + if (error != -EPERM)
75867 + goto out;
75868 +
75869 + if(!(gr_auth_attempts++))
75870 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75871 +
75872 + out:
75873 + mutex_unlock(&gr_dev_mutex);
75874 +
75875 + if (!error)
75876 + error = req_count;
75877 +
75878 + return error;
75879 +}
75880 +
75881 +int
75882 +gr_set_acls(const int type)
75883 +{
75884 + struct task_struct *task, *task2;
75885 + struct acl_role_label *role = current->role;
75886 + struct acl_subject_label *subj;
75887 + __u16 acl_role_id = current->acl_role_id;
75888 + const struct cred *cred;
75889 + int ret;
75890 +
75891 + rcu_read_lock();
75892 + read_lock(&tasklist_lock);
75893 + read_lock(&grsec_exec_file_lock);
75894 + do_each_thread(task2, task) {
75895 + /* check to see if we're called from the exit handler,
75896 + if so, only replace ACLs that have inherited the admin
75897 + ACL */
75898 +
75899 + if (type && (task->role != role ||
75900 + task->acl_role_id != acl_role_id))
75901 + continue;
75902 +
75903 + task->acl_role_id = 0;
75904 + task->acl_sp_role = 0;
75905 + task->inherited = 0;
75906 +
75907 + if (task->exec_file) {
75908 + cred = __task_cred(task);
75909 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75910 + subj = __gr_get_subject_for_task(polstate, task, NULL);
75911 + if (subj == NULL) {
75912 + ret = -EINVAL;
75913 + read_unlock(&grsec_exec_file_lock);
75914 + read_unlock(&tasklist_lock);
75915 + rcu_read_unlock();
75916 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75917 + return ret;
75918 + }
75919 + __gr_apply_subject_to_task(polstate, task, subj);
75920 + } else {
75921 + // it's a kernel process
75922 + task->role = polstate->kernel_role;
75923 + task->acl = polstate->kernel_role->root_label;
75924 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75925 + task->acl->mode &= ~GR_PROCFIND;
75926 +#endif
75927 + }
75928 + } while_each_thread(task2, task);
75929 + read_unlock(&grsec_exec_file_lock);
75930 + read_unlock(&tasklist_lock);
75931 + rcu_read_unlock();
75932 +
75933 + return 0;
75934 +}
75935 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75936 new file mode 100644
75937 index 0000000..39645c9
75938 --- /dev/null
75939 +++ b/grsecurity/gracl_res.c
75940 @@ -0,0 +1,68 @@
75941 +#include <linux/kernel.h>
75942 +#include <linux/sched.h>
75943 +#include <linux/gracl.h>
75944 +#include <linux/grinternal.h>
75945 +
75946 +static const char *restab_log[] = {
75947 + [RLIMIT_CPU] = "RLIMIT_CPU",
75948 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75949 + [RLIMIT_DATA] = "RLIMIT_DATA",
75950 + [RLIMIT_STACK] = "RLIMIT_STACK",
75951 + [RLIMIT_CORE] = "RLIMIT_CORE",
75952 + [RLIMIT_RSS] = "RLIMIT_RSS",
75953 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75954 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75955 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75956 + [RLIMIT_AS] = "RLIMIT_AS",
75957 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75958 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75959 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75960 + [RLIMIT_NICE] = "RLIMIT_NICE",
75961 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75962 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75963 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75964 +};
75965 +
75966 +void
75967 +gr_log_resource(const struct task_struct *task,
75968 + const int res, const unsigned long wanted, const int gt)
75969 +{
75970 + const struct cred *cred;
75971 + unsigned long rlim;
75972 +
75973 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75974 + return;
75975 +
75976 + // not yet supported resource
75977 + if (unlikely(!restab_log[res]))
75978 + return;
75979 +
75980 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75981 + rlim = task_rlimit_max(task, res);
75982 + else
75983 + rlim = task_rlimit(task, res);
75984 +
75985 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75986 + return;
75987 +
75988 + rcu_read_lock();
75989 + cred = __task_cred(task);
75990 +
75991 + if (res == RLIMIT_NPROC &&
75992 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75993 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75994 + goto out_rcu_unlock;
75995 + else if (res == RLIMIT_MEMLOCK &&
75996 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75997 + goto out_rcu_unlock;
75998 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75999 + goto out_rcu_unlock;
76000 + rcu_read_unlock();
76001 +
76002 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
76003 +
76004 + return;
76005 +out_rcu_unlock:
76006 + rcu_read_unlock();
76007 + return;
76008 +}
76009 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
76010 new file mode 100644
76011 index 0000000..2040e61
76012 --- /dev/null
76013 +++ b/grsecurity/gracl_segv.c
76014 @@ -0,0 +1,313 @@
76015 +#include <linux/kernel.h>
76016 +#include <linux/mm.h>
76017 +#include <asm/uaccess.h>
76018 +#include <asm/errno.h>
76019 +#include <asm/mman.h>
76020 +#include <net/sock.h>
76021 +#include <linux/file.h>
76022 +#include <linux/fs.h>
76023 +#include <linux/net.h>
76024 +#include <linux/in.h>
76025 +#include <linux/slab.h>
76026 +#include <linux/types.h>
76027 +#include <linux/sched.h>
76028 +#include <linux/timer.h>
76029 +#include <linux/gracl.h>
76030 +#include <linux/grsecurity.h>
76031 +#include <linux/grinternal.h>
76032 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76033 +#include <linux/magic.h>
76034 +#include <linux/pagemap.h>
76035 +#include "../fs/btrfs/async-thread.h"
76036 +#include "../fs/btrfs/ctree.h"
76037 +#include "../fs/btrfs/btrfs_inode.h"
76038 +#endif
76039 +
76040 +static struct crash_uid *uid_set;
76041 +static unsigned short uid_used;
76042 +static DEFINE_SPINLOCK(gr_uid_lock);
76043 +extern rwlock_t gr_inode_lock;
76044 +extern struct acl_subject_label *
76045 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
76046 + struct acl_role_label *role);
76047 +
76048 +static inline dev_t __get_dev(const struct dentry *dentry)
76049 +{
76050 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76051 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
76052 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
76053 + else
76054 +#endif
76055 + return dentry->d_sb->s_dev;
76056 +}
76057 +
76058 +int
76059 +gr_init_uidset(void)
76060 +{
76061 + uid_set =
76062 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
76063 + uid_used = 0;
76064 +
76065 + return uid_set ? 1 : 0;
76066 +}
76067 +
76068 +void
76069 +gr_free_uidset(void)
76070 +{
76071 + if (uid_set) {
76072 + struct crash_uid *tmpset;
76073 + spin_lock(&gr_uid_lock);
76074 + tmpset = uid_set;
76075 + uid_set = NULL;
76076 + uid_used = 0;
76077 + spin_unlock(&gr_uid_lock);
76078 + if (tmpset)
76079 + kfree(tmpset);
76080 + }
76081 +
76082 + return;
76083 +}
76084 +
76085 +int
76086 +gr_find_uid(const uid_t uid)
76087 +{
76088 + struct crash_uid *tmp = uid_set;
76089 + uid_t buid;
76090 + int low = 0, high = uid_used - 1, mid;
76091 +
76092 + while (high >= low) {
76093 + mid = (low + high) >> 1;
76094 + buid = tmp[mid].uid;
76095 + if (buid == uid)
76096 + return mid;
76097 + if (buid > uid)
76098 + high = mid - 1;
76099 + if (buid < uid)
76100 + low = mid + 1;
76101 + }
76102 +
76103 + return -1;
76104 +}
76105 +
76106 +static __inline__ void
76107 +gr_insertsort(void)
76108 +{
76109 + unsigned short i, j;
76110 + struct crash_uid index;
76111 +
76112 + for (i = 1; i < uid_used; i++) {
76113 + index = uid_set[i];
76114 + j = i;
76115 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
76116 + uid_set[j] = uid_set[j - 1];
76117 + j--;
76118 + }
76119 + uid_set[j] = index;
76120 + }
76121 +
76122 + return;
76123 +}
76124 +
76125 +static __inline__ void
76126 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
76127 +{
76128 + int loc;
76129 + uid_t uid = GR_GLOBAL_UID(kuid);
76130 +
76131 + if (uid_used == GR_UIDTABLE_MAX)
76132 + return;
76133 +
76134 + loc = gr_find_uid(uid);
76135 +
76136 + if (loc >= 0) {
76137 + uid_set[loc].expires = expires;
76138 + return;
76139 + }
76140 +
76141 + uid_set[uid_used].uid = uid;
76142 + uid_set[uid_used].expires = expires;
76143 + uid_used++;
76144 +
76145 + gr_insertsort();
76146 +
76147 + return;
76148 +}
76149 +
76150 +void
76151 +gr_remove_uid(const unsigned short loc)
76152 +{
76153 + unsigned short i;
76154 +
76155 + for (i = loc + 1; i < uid_used; i++)
76156 + uid_set[i - 1] = uid_set[i];
76157 +
76158 + uid_used--;
76159 +
76160 + return;
76161 +}
76162 +
76163 +int
76164 +gr_check_crash_uid(const kuid_t kuid)
76165 +{
76166 + int loc;
76167 + int ret = 0;
76168 + uid_t uid;
76169 +
76170 + if (unlikely(!gr_acl_is_enabled()))
76171 + return 0;
76172 +
76173 + uid = GR_GLOBAL_UID(kuid);
76174 +
76175 + spin_lock(&gr_uid_lock);
76176 + loc = gr_find_uid(uid);
76177 +
76178 + if (loc < 0)
76179 + goto out_unlock;
76180 +
76181 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
76182 + gr_remove_uid(loc);
76183 + else
76184 + ret = 1;
76185 +
76186 +out_unlock:
76187 + spin_unlock(&gr_uid_lock);
76188 + return ret;
76189 +}
76190 +
76191 +static __inline__ int
76192 +proc_is_setxid(const struct cred *cred)
76193 +{
76194 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76195 + !uid_eq(cred->uid, cred->fsuid))
76196 + return 1;
76197 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76198 + !gid_eq(cred->gid, cred->fsgid))
76199 + return 1;
76200 +
76201 + return 0;
76202 +}
76203 +
76204 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
76205 +
76206 +void
76207 +gr_handle_crash(struct task_struct *task, const int sig)
76208 +{
76209 + struct acl_subject_label *curr;
76210 + struct task_struct *tsk, *tsk2;
76211 + const struct cred *cred;
76212 + const struct cred *cred2;
76213 +
76214 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76215 + return;
76216 +
76217 + if (unlikely(!gr_acl_is_enabled()))
76218 + return;
76219 +
76220 + curr = task->acl;
76221 +
76222 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
76223 + return;
76224 +
76225 + if (time_before_eq(curr->expires, get_seconds())) {
76226 + curr->expires = 0;
76227 + curr->crashes = 0;
76228 + }
76229 +
76230 + curr->crashes++;
76231 +
76232 + if (!curr->expires)
76233 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76234 +
76235 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76236 + time_after(curr->expires, get_seconds())) {
76237 + rcu_read_lock();
76238 + cred = __task_cred(task);
76239 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76240 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76241 + spin_lock(&gr_uid_lock);
76242 + gr_insert_uid(cred->uid, curr->expires);
76243 + spin_unlock(&gr_uid_lock);
76244 + curr->expires = 0;
76245 + curr->crashes = 0;
76246 + read_lock(&tasklist_lock);
76247 + do_each_thread(tsk2, tsk) {
76248 + cred2 = __task_cred(tsk);
76249 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76250 + gr_fake_force_sig(SIGKILL, tsk);
76251 + } while_each_thread(tsk2, tsk);
76252 + read_unlock(&tasklist_lock);
76253 + } else {
76254 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76255 + read_lock(&tasklist_lock);
76256 + read_lock(&grsec_exec_file_lock);
76257 + do_each_thread(tsk2, tsk) {
76258 + if (likely(tsk != task)) {
76259 + // if this thread has the same subject as the one that triggered
76260 + // RES_CRASH and it's the same binary, kill it
76261 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76262 + gr_fake_force_sig(SIGKILL, tsk);
76263 + }
76264 + } while_each_thread(tsk2, tsk);
76265 + read_unlock(&grsec_exec_file_lock);
76266 + read_unlock(&tasklist_lock);
76267 + }
76268 + rcu_read_unlock();
76269 + }
76270 +
76271 + return;
76272 +}
76273 +
76274 +int
76275 +gr_check_crash_exec(const struct file *filp)
76276 +{
76277 + struct acl_subject_label *curr;
76278 +
76279 + if (unlikely(!gr_acl_is_enabled()))
76280 + return 0;
76281 +
76282 + read_lock(&gr_inode_lock);
76283 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76284 + __get_dev(filp->f_path.dentry),
76285 + current->role);
76286 + read_unlock(&gr_inode_lock);
76287 +
76288 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76289 + (!curr->crashes && !curr->expires))
76290 + return 0;
76291 +
76292 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76293 + time_after(curr->expires, get_seconds()))
76294 + return 1;
76295 + else if (time_before_eq(curr->expires, get_seconds())) {
76296 + curr->crashes = 0;
76297 + curr->expires = 0;
76298 + }
76299 +
76300 + return 0;
76301 +}
76302 +
76303 +void
76304 +gr_handle_alertkill(struct task_struct *task)
76305 +{
76306 + struct acl_subject_label *curracl;
76307 + __u32 curr_ip;
76308 + struct task_struct *p, *p2;
76309 +
76310 + if (unlikely(!gr_acl_is_enabled()))
76311 + return;
76312 +
76313 + curracl = task->acl;
76314 + curr_ip = task->signal->curr_ip;
76315 +
76316 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76317 + read_lock(&tasklist_lock);
76318 + do_each_thread(p2, p) {
76319 + if (p->signal->curr_ip == curr_ip)
76320 + gr_fake_force_sig(SIGKILL, p);
76321 + } while_each_thread(p2, p);
76322 + read_unlock(&tasklist_lock);
76323 + } else if (curracl->mode & GR_KILLPROC)
76324 + gr_fake_force_sig(SIGKILL, task);
76325 +
76326 + return;
76327 +}
76328 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76329 new file mode 100644
76330 index 0000000..6b0c9cc
76331 --- /dev/null
76332 +++ b/grsecurity/gracl_shm.c
76333 @@ -0,0 +1,40 @@
76334 +#include <linux/kernel.h>
76335 +#include <linux/mm.h>
76336 +#include <linux/sched.h>
76337 +#include <linux/file.h>
76338 +#include <linux/ipc.h>
76339 +#include <linux/gracl.h>
76340 +#include <linux/grsecurity.h>
76341 +#include <linux/grinternal.h>
76342 +
76343 +int
76344 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76345 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76346 +{
76347 + struct task_struct *task;
76348 +
76349 + if (!gr_acl_is_enabled())
76350 + return 1;
76351 +
76352 + rcu_read_lock();
76353 + read_lock(&tasklist_lock);
76354 +
76355 + task = find_task_by_vpid(shm_cprid);
76356 +
76357 + if (unlikely(!task))
76358 + task = find_task_by_vpid(shm_lapid);
76359 +
76360 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76361 + (task_pid_nr(task) == shm_lapid)) &&
76362 + (task->acl->mode & GR_PROTSHM) &&
76363 + (task->acl != current->acl))) {
76364 + read_unlock(&tasklist_lock);
76365 + rcu_read_unlock();
76366 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76367 + return 0;
76368 + }
76369 + read_unlock(&tasklist_lock);
76370 + rcu_read_unlock();
76371 +
76372 + return 1;
76373 +}
76374 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76375 new file mode 100644
76376 index 0000000..bc0be01
76377 --- /dev/null
76378 +++ b/grsecurity/grsec_chdir.c
76379 @@ -0,0 +1,19 @@
76380 +#include <linux/kernel.h>
76381 +#include <linux/sched.h>
76382 +#include <linux/fs.h>
76383 +#include <linux/file.h>
76384 +#include <linux/grsecurity.h>
76385 +#include <linux/grinternal.h>
76386 +
76387 +void
76388 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76389 +{
76390 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76391 + if ((grsec_enable_chdir && grsec_enable_group &&
76392 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76393 + !grsec_enable_group)) {
76394 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76395 + }
76396 +#endif
76397 + return;
76398 +}
76399 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76400 new file mode 100644
76401 index 0000000..6d99cec
76402 --- /dev/null
76403 +++ b/grsecurity/grsec_chroot.c
76404 @@ -0,0 +1,385 @@
76405 +#include <linux/kernel.h>
76406 +#include <linux/module.h>
76407 +#include <linux/sched.h>
76408 +#include <linux/file.h>
76409 +#include <linux/fs.h>
76410 +#include <linux/mount.h>
76411 +#include <linux/types.h>
76412 +#include "../fs/mount.h"
76413 +#include <linux/grsecurity.h>
76414 +#include <linux/grinternal.h>
76415 +
76416 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76417 +int gr_init_ran;
76418 +#endif
76419 +
76420 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76421 +{
76422 +#ifdef CONFIG_GRKERNSEC
76423 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76424 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76425 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76426 + && gr_init_ran
76427 +#endif
76428 + )
76429 + task->gr_is_chrooted = 1;
76430 + else {
76431 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76432 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76433 + gr_init_ran = 1;
76434 +#endif
76435 + task->gr_is_chrooted = 0;
76436 + }
76437 +
76438 + task->gr_chroot_dentry = path->dentry;
76439 +#endif
76440 + return;
76441 +}
76442 +
76443 +void gr_clear_chroot_entries(struct task_struct *task)
76444 +{
76445 +#ifdef CONFIG_GRKERNSEC
76446 + task->gr_is_chrooted = 0;
76447 + task->gr_chroot_dentry = NULL;
76448 +#endif
76449 + return;
76450 +}
76451 +
76452 +int
76453 +gr_handle_chroot_unix(const pid_t pid)
76454 +{
76455 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76456 + struct task_struct *p;
76457 +
76458 + if (unlikely(!grsec_enable_chroot_unix))
76459 + return 1;
76460 +
76461 + if (likely(!proc_is_chrooted(current)))
76462 + return 1;
76463 +
76464 + rcu_read_lock();
76465 + read_lock(&tasklist_lock);
76466 + p = find_task_by_vpid_unrestricted(pid);
76467 + if (unlikely(p && !have_same_root(current, p))) {
76468 + read_unlock(&tasklist_lock);
76469 + rcu_read_unlock();
76470 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76471 + return 0;
76472 + }
76473 + read_unlock(&tasklist_lock);
76474 + rcu_read_unlock();
76475 +#endif
76476 + return 1;
76477 +}
76478 +
76479 +int
76480 +gr_handle_chroot_nice(void)
76481 +{
76482 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76483 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76484 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76485 + return -EPERM;
76486 + }
76487 +#endif
76488 + return 0;
76489 +}
76490 +
76491 +int
76492 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76493 +{
76494 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76495 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76496 + && proc_is_chrooted(current)) {
76497 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76498 + return -EACCES;
76499 + }
76500 +#endif
76501 + return 0;
76502 +}
76503 +
76504 +int
76505 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76506 +{
76507 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76508 + struct task_struct *p;
76509 + int ret = 0;
76510 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76511 + return ret;
76512 +
76513 + read_lock(&tasklist_lock);
76514 + do_each_pid_task(pid, type, p) {
76515 + if (!have_same_root(current, p)) {
76516 + ret = 1;
76517 + goto out;
76518 + }
76519 + } while_each_pid_task(pid, type, p);
76520 +out:
76521 + read_unlock(&tasklist_lock);
76522 + return ret;
76523 +#endif
76524 + return 0;
76525 +}
76526 +
76527 +int
76528 +gr_pid_is_chrooted(struct task_struct *p)
76529 +{
76530 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76531 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76532 + return 0;
76533 +
76534 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76535 + !have_same_root(current, p)) {
76536 + return 1;
76537 + }
76538 +#endif
76539 + return 0;
76540 +}
76541 +
76542 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76543 +
76544 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76545 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76546 +{
76547 + struct path path, currentroot;
76548 + int ret = 0;
76549 +
76550 + path.dentry = (struct dentry *)u_dentry;
76551 + path.mnt = (struct vfsmount *)u_mnt;
76552 + get_fs_root(current->fs, &currentroot);
76553 + if (path_is_under(&path, &currentroot))
76554 + ret = 1;
76555 + path_put(&currentroot);
76556 +
76557 + return ret;
76558 +}
76559 +#endif
76560 +
76561 +int
76562 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76563 +{
76564 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76565 + if (!grsec_enable_chroot_fchdir)
76566 + return 1;
76567 +
76568 + if (!proc_is_chrooted(current))
76569 + return 1;
76570 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76571 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76572 + return 0;
76573 + }
76574 +#endif
76575 + return 1;
76576 +}
76577 +
76578 +int
76579 +gr_chroot_fhandle(void)
76580 +{
76581 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76582 + if (!grsec_enable_chroot_fchdir)
76583 + return 1;
76584 +
76585 + if (!proc_is_chrooted(current))
76586 + return 1;
76587 + else {
76588 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76589 + return 0;
76590 + }
76591 +#endif
76592 + return 1;
76593 +}
76594 +
76595 +int
76596 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76597 + const u64 shm_createtime)
76598 +{
76599 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76600 + struct task_struct *p;
76601 +
76602 + if (unlikely(!grsec_enable_chroot_shmat))
76603 + return 1;
76604 +
76605 + if (likely(!proc_is_chrooted(current)))
76606 + return 1;
76607 +
76608 + rcu_read_lock();
76609 + read_lock(&tasklist_lock);
76610 +
76611 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76612 + if (time_before_eq64(p->start_time, shm_createtime)) {
76613 + if (have_same_root(current, p)) {
76614 + goto allow;
76615 + } else {
76616 + read_unlock(&tasklist_lock);
76617 + rcu_read_unlock();
76618 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76619 + return 0;
76620 + }
76621 + }
76622 + /* creator exited, pid reuse, fall through to next check */
76623 + }
76624 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76625 + if (unlikely(!have_same_root(current, p))) {
76626 + read_unlock(&tasklist_lock);
76627 + rcu_read_unlock();
76628 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76629 + return 0;
76630 + }
76631 + }
76632 +
76633 +allow:
76634 + read_unlock(&tasklist_lock);
76635 + rcu_read_unlock();
76636 +#endif
76637 + return 1;
76638 +}
76639 +
76640 +void
76641 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76642 +{
76643 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76644 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76645 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76646 +#endif
76647 + return;
76648 +}
76649 +
76650 +int
76651 +gr_handle_chroot_mknod(const struct dentry *dentry,
76652 + const struct vfsmount *mnt, const int mode)
76653 +{
76654 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76655 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76656 + proc_is_chrooted(current)) {
76657 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76658 + return -EPERM;
76659 + }
76660 +#endif
76661 + return 0;
76662 +}
76663 +
76664 +int
76665 +gr_handle_chroot_mount(const struct dentry *dentry,
76666 + const struct vfsmount *mnt, const char *dev_name)
76667 +{
76668 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76669 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76670 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76671 + return -EPERM;
76672 + }
76673 +#endif
76674 + return 0;
76675 +}
76676 +
76677 +int
76678 +gr_handle_chroot_pivot(void)
76679 +{
76680 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76681 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76682 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76683 + return -EPERM;
76684 + }
76685 +#endif
76686 + return 0;
76687 +}
76688 +
76689 +int
76690 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76691 +{
76692 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76693 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76694 + !gr_is_outside_chroot(dentry, mnt)) {
76695 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76696 + return -EPERM;
76697 + }
76698 +#endif
76699 + return 0;
76700 +}
76701 +
76702 +extern const char *captab_log[];
76703 +extern int captab_log_entries;
76704 +
76705 +int
76706 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76707 +{
76708 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76709 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76710 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76711 + if (cap_raised(chroot_caps, cap)) {
76712 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76713 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76714 + }
76715 + return 0;
76716 + }
76717 + }
76718 +#endif
76719 + return 1;
76720 +}
76721 +
76722 +int
76723 +gr_chroot_is_capable(const int cap)
76724 +{
76725 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76726 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76727 +#endif
76728 + return 1;
76729 +}
76730 +
76731 +int
76732 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76733 +{
76734 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76735 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76736 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76737 + if (cap_raised(chroot_caps, cap)) {
76738 + return 0;
76739 + }
76740 + }
76741 +#endif
76742 + return 1;
76743 +}
76744 +
76745 +int
76746 +gr_chroot_is_capable_nolog(const int cap)
76747 +{
76748 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76749 + return gr_task_chroot_is_capable_nolog(current, cap);
76750 +#endif
76751 + return 1;
76752 +}
76753 +
76754 +int
76755 +gr_handle_chroot_sysctl(const int op)
76756 +{
76757 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76758 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76759 + proc_is_chrooted(current))
76760 + return -EACCES;
76761 +#endif
76762 + return 0;
76763 +}
76764 +
76765 +void
76766 +gr_handle_chroot_chdir(const struct path *path)
76767 +{
76768 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76769 + if (grsec_enable_chroot_chdir)
76770 + set_fs_pwd(current->fs, path);
76771 +#endif
76772 + return;
76773 +}
76774 +
76775 +int
76776 +gr_handle_chroot_chmod(const struct dentry *dentry,
76777 + const struct vfsmount *mnt, const int mode)
76778 +{
76779 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76780 + /* allow chmod +s on directories, but not files */
76781 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76782 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76783 + proc_is_chrooted(current)) {
76784 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76785 + return -EPERM;
76786 + }
76787 +#endif
76788 + return 0;
76789 +}
76790 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76791 new file mode 100644
76792 index 0000000..0f9ac91
76793 --- /dev/null
76794 +++ b/grsecurity/grsec_disabled.c
76795 @@ -0,0 +1,440 @@
76796 +#include <linux/kernel.h>
76797 +#include <linux/module.h>
76798 +#include <linux/sched.h>
76799 +#include <linux/file.h>
76800 +#include <linux/fs.h>
76801 +#include <linux/kdev_t.h>
76802 +#include <linux/net.h>
76803 +#include <linux/in.h>
76804 +#include <linux/ip.h>
76805 +#include <linux/skbuff.h>
76806 +#include <linux/sysctl.h>
76807 +
76808 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76809 +void
76810 +pax_set_initial_flags(struct linux_binprm *bprm)
76811 +{
76812 + return;
76813 +}
76814 +#endif
76815 +
76816 +#ifdef CONFIG_SYSCTL
76817 +__u32
76818 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76819 +{
76820 + return 0;
76821 +}
76822 +#endif
76823 +
76824 +#ifdef CONFIG_TASKSTATS
76825 +int gr_is_taskstats_denied(int pid)
76826 +{
76827 + return 0;
76828 +}
76829 +#endif
76830 +
76831 +int
76832 +gr_acl_is_enabled(void)
76833 +{
76834 + return 0;
76835 +}
76836 +
76837 +int
76838 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76839 +{
76840 + return 0;
76841 +}
76842 +
76843 +void
76844 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76845 +{
76846 + return;
76847 +}
76848 +
76849 +int
76850 +gr_handle_rawio(const struct inode *inode)
76851 +{
76852 + return 0;
76853 +}
76854 +
76855 +void
76856 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76857 +{
76858 + return;
76859 +}
76860 +
76861 +int
76862 +gr_handle_ptrace(struct task_struct *task, const long request)
76863 +{
76864 + return 0;
76865 +}
76866 +
76867 +int
76868 +gr_handle_proc_ptrace(struct task_struct *task)
76869 +{
76870 + return 0;
76871 +}
76872 +
76873 +int
76874 +gr_set_acls(const int type)
76875 +{
76876 + return 0;
76877 +}
76878 +
76879 +int
76880 +gr_check_hidden_task(const struct task_struct *tsk)
76881 +{
76882 + return 0;
76883 +}
76884 +
76885 +int
76886 +gr_check_protected_task(const struct task_struct *task)
76887 +{
76888 + return 0;
76889 +}
76890 +
76891 +int
76892 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76893 +{
76894 + return 0;
76895 +}
76896 +
76897 +void
76898 +gr_copy_label(struct task_struct *tsk)
76899 +{
76900 + return;
76901 +}
76902 +
76903 +void
76904 +gr_set_pax_flags(struct task_struct *task)
76905 +{
76906 + return;
76907 +}
76908 +
76909 +int
76910 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76911 + const int unsafe_share)
76912 +{
76913 + return 0;
76914 +}
76915 +
76916 +void
76917 +gr_handle_delete(const ino_t ino, const dev_t dev)
76918 +{
76919 + return;
76920 +}
76921 +
76922 +void
76923 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76924 +{
76925 + return;
76926 +}
76927 +
76928 +void
76929 +gr_handle_crash(struct task_struct *task, const int sig)
76930 +{
76931 + return;
76932 +}
76933 +
76934 +int
76935 +gr_check_crash_exec(const struct file *filp)
76936 +{
76937 + return 0;
76938 +}
76939 +
76940 +int
76941 +gr_check_crash_uid(const kuid_t uid)
76942 +{
76943 + return 0;
76944 +}
76945 +
76946 +void
76947 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76948 + struct dentry *old_dentry,
76949 + struct dentry *new_dentry,
76950 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76951 +{
76952 + return;
76953 +}
76954 +
76955 +int
76956 +gr_search_socket(const int family, const int type, const int protocol)
76957 +{
76958 + return 1;
76959 +}
76960 +
76961 +int
76962 +gr_search_connectbind(const int mode, const struct socket *sock,
76963 + const struct sockaddr_in *addr)
76964 +{
76965 + return 0;
76966 +}
76967 +
76968 +void
76969 +gr_handle_alertkill(struct task_struct *task)
76970 +{
76971 + return;
76972 +}
76973 +
76974 +__u32
76975 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76976 +{
76977 + return 1;
76978 +}
76979 +
76980 +__u32
76981 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76982 + const struct vfsmount * mnt)
76983 +{
76984 + return 1;
76985 +}
76986 +
76987 +__u32
76988 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76989 + int acc_mode)
76990 +{
76991 + return 1;
76992 +}
76993 +
76994 +__u32
76995 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76996 +{
76997 + return 1;
76998 +}
76999 +
77000 +__u32
77001 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
77002 +{
77003 + return 1;
77004 +}
77005 +
77006 +int
77007 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
77008 + unsigned int *vm_flags)
77009 +{
77010 + return 1;
77011 +}
77012 +
77013 +__u32
77014 +gr_acl_handle_truncate(const struct dentry * dentry,
77015 + const struct vfsmount * mnt)
77016 +{
77017 + return 1;
77018 +}
77019 +
77020 +__u32
77021 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
77022 +{
77023 + return 1;
77024 +}
77025 +
77026 +__u32
77027 +gr_acl_handle_access(const struct dentry * dentry,
77028 + const struct vfsmount * mnt, const int fmode)
77029 +{
77030 + return 1;
77031 +}
77032 +
77033 +__u32
77034 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
77035 + umode_t *mode)
77036 +{
77037 + return 1;
77038 +}
77039 +
77040 +__u32
77041 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
77042 +{
77043 + return 1;
77044 +}
77045 +
77046 +__u32
77047 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
77048 +{
77049 + return 1;
77050 +}
77051 +
77052 +__u32
77053 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
77054 +{
77055 + return 1;
77056 +}
77057 +
77058 +void
77059 +grsecurity_init(void)
77060 +{
77061 + return;
77062 +}
77063 +
77064 +umode_t gr_acl_umask(void)
77065 +{
77066 + return 0;
77067 +}
77068 +
77069 +__u32
77070 +gr_acl_handle_mknod(const struct dentry * new_dentry,
77071 + const struct dentry * parent_dentry,
77072 + const struct vfsmount * parent_mnt,
77073 + const int mode)
77074 +{
77075 + return 1;
77076 +}
77077 +
77078 +__u32
77079 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
77080 + const struct dentry * parent_dentry,
77081 + const struct vfsmount * parent_mnt)
77082 +{
77083 + return 1;
77084 +}
77085 +
77086 +__u32
77087 +gr_acl_handle_symlink(const struct dentry * new_dentry,
77088 + const struct dentry * parent_dentry,
77089 + const struct vfsmount * parent_mnt, const struct filename *from)
77090 +{
77091 + return 1;
77092 +}
77093 +
77094 +__u32
77095 +gr_acl_handle_link(const struct dentry * new_dentry,
77096 + const struct dentry * parent_dentry,
77097 + const struct vfsmount * parent_mnt,
77098 + const struct dentry * old_dentry,
77099 + const struct vfsmount * old_mnt, const struct filename *to)
77100 +{
77101 + return 1;
77102 +}
77103 +
77104 +int
77105 +gr_acl_handle_rename(const struct dentry *new_dentry,
77106 + const struct dentry *parent_dentry,
77107 + const struct vfsmount *parent_mnt,
77108 + const struct dentry *old_dentry,
77109 + const struct inode *old_parent_inode,
77110 + const struct vfsmount *old_mnt, const struct filename *newname,
77111 + unsigned int flags)
77112 +{
77113 + return 0;
77114 +}
77115 +
77116 +int
77117 +gr_acl_handle_filldir(const struct file *file, const char *name,
77118 + const int namelen, const ino_t ino)
77119 +{
77120 + return 1;
77121 +}
77122 +
77123 +int
77124 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77125 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
77126 +{
77127 + return 1;
77128 +}
77129 +
77130 +int
77131 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77132 +{
77133 + return 0;
77134 +}
77135 +
77136 +int
77137 +gr_search_accept(const struct socket *sock)
77138 +{
77139 + return 0;
77140 +}
77141 +
77142 +int
77143 +gr_search_listen(const struct socket *sock)
77144 +{
77145 + return 0;
77146 +}
77147 +
77148 +int
77149 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77150 +{
77151 + return 0;
77152 +}
77153 +
77154 +__u32
77155 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77156 +{
77157 + return 1;
77158 +}
77159 +
77160 +__u32
77161 +gr_acl_handle_creat(const struct dentry * dentry,
77162 + const struct dentry * p_dentry,
77163 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77164 + const int imode)
77165 +{
77166 + return 1;
77167 +}
77168 +
77169 +void
77170 +gr_acl_handle_exit(void)
77171 +{
77172 + return;
77173 +}
77174 +
77175 +int
77176 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77177 +{
77178 + return 1;
77179 +}
77180 +
77181 +void
77182 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77183 +{
77184 + return;
77185 +}
77186 +
77187 +int
77188 +gr_acl_handle_procpidmem(const struct task_struct *task)
77189 +{
77190 + return 0;
77191 +}
77192 +
77193 +int
77194 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77195 +{
77196 + return 0;
77197 +}
77198 +
77199 +int
77200 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77201 +{
77202 + return 0;
77203 +}
77204 +
77205 +int
77206 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77207 +{
77208 + return 0;
77209 +}
77210 +
77211 +int
77212 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77213 +{
77214 + return 0;
77215 +}
77216 +
77217 +int gr_acl_enable_at_secure(void)
77218 +{
77219 + return 0;
77220 +}
77221 +
77222 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77223 +{
77224 + return dentry->d_sb->s_dev;
77225 +}
77226 +
77227 +void gr_put_exec_file(struct task_struct *task)
77228 +{
77229 + return;
77230 +}
77231 +
77232 +#ifdef CONFIG_SECURITY
77233 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77234 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77235 +#endif
77236 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77237 new file mode 100644
77238 index 0000000..14638ff
77239 --- /dev/null
77240 +++ b/grsecurity/grsec_exec.c
77241 @@ -0,0 +1,188 @@
77242 +#include <linux/kernel.h>
77243 +#include <linux/sched.h>
77244 +#include <linux/file.h>
77245 +#include <linux/binfmts.h>
77246 +#include <linux/fs.h>
77247 +#include <linux/types.h>
77248 +#include <linux/grdefs.h>
77249 +#include <linux/grsecurity.h>
77250 +#include <linux/grinternal.h>
77251 +#include <linux/capability.h>
77252 +#include <linux/module.h>
77253 +#include <linux/compat.h>
77254 +
77255 +#include <asm/uaccess.h>
77256 +
77257 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77258 +static char gr_exec_arg_buf[132];
77259 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77260 +#endif
77261 +
77262 +struct user_arg_ptr {
77263 +#ifdef CONFIG_COMPAT
77264 + bool is_compat;
77265 +#endif
77266 + union {
77267 + const char __user *const __user *native;
77268 +#ifdef CONFIG_COMPAT
77269 + const compat_uptr_t __user *compat;
77270 +#endif
77271 + } ptr;
77272 +};
77273 +
77274 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77275 +
77276 +void
77277 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77278 +{
77279 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77280 + char *grarg = gr_exec_arg_buf;
77281 + unsigned int i, x, execlen = 0;
77282 + char c;
77283 +
77284 + if (!((grsec_enable_execlog && grsec_enable_group &&
77285 + in_group_p(grsec_audit_gid))
77286 + || (grsec_enable_execlog && !grsec_enable_group)))
77287 + return;
77288 +
77289 + mutex_lock(&gr_exec_arg_mutex);
77290 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77291 +
77292 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77293 + const char __user *p;
77294 + unsigned int len;
77295 +
77296 + p = get_user_arg_ptr(argv, i);
77297 + if (IS_ERR(p))
77298 + goto log;
77299 +
77300 + len = strnlen_user(p, 128 - execlen);
77301 + if (len > 128 - execlen)
77302 + len = 128 - execlen;
77303 + else if (len > 0)
77304 + len--;
77305 + if (copy_from_user(grarg + execlen, p, len))
77306 + goto log;
77307 +
77308 + /* rewrite unprintable characters */
77309 + for (x = 0; x < len; x++) {
77310 + c = *(grarg + execlen + x);
77311 + if (c < 32 || c > 126)
77312 + *(grarg + execlen + x) = ' ';
77313 + }
77314 +
77315 + execlen += len;
77316 + *(grarg + execlen) = ' ';
77317 + *(grarg + execlen + 1) = '\0';
77318 + execlen++;
77319 + }
77320 +
77321 + log:
77322 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77323 + bprm->file->f_path.mnt, grarg);
77324 + mutex_unlock(&gr_exec_arg_mutex);
77325 +#endif
77326 + return;
77327 +}
77328 +
77329 +#ifdef CONFIG_GRKERNSEC
77330 +extern int gr_acl_is_capable(const int cap);
77331 +extern int gr_acl_is_capable_nolog(const int cap);
77332 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77333 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77334 +extern int gr_chroot_is_capable(const int cap);
77335 +extern int gr_chroot_is_capable_nolog(const int cap);
77336 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77337 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77338 +#endif
77339 +
77340 +const char *captab_log[] = {
77341 + "CAP_CHOWN",
77342 + "CAP_DAC_OVERRIDE",
77343 + "CAP_DAC_READ_SEARCH",
77344 + "CAP_FOWNER",
77345 + "CAP_FSETID",
77346 + "CAP_KILL",
77347 + "CAP_SETGID",
77348 + "CAP_SETUID",
77349 + "CAP_SETPCAP",
77350 + "CAP_LINUX_IMMUTABLE",
77351 + "CAP_NET_BIND_SERVICE",
77352 + "CAP_NET_BROADCAST",
77353 + "CAP_NET_ADMIN",
77354 + "CAP_NET_RAW",
77355 + "CAP_IPC_LOCK",
77356 + "CAP_IPC_OWNER",
77357 + "CAP_SYS_MODULE",
77358 + "CAP_SYS_RAWIO",
77359 + "CAP_SYS_CHROOT",
77360 + "CAP_SYS_PTRACE",
77361 + "CAP_SYS_PACCT",
77362 + "CAP_SYS_ADMIN",
77363 + "CAP_SYS_BOOT",
77364 + "CAP_SYS_NICE",
77365 + "CAP_SYS_RESOURCE",
77366 + "CAP_SYS_TIME",
77367 + "CAP_SYS_TTY_CONFIG",
77368 + "CAP_MKNOD",
77369 + "CAP_LEASE",
77370 + "CAP_AUDIT_WRITE",
77371 + "CAP_AUDIT_CONTROL",
77372 + "CAP_SETFCAP",
77373 + "CAP_MAC_OVERRIDE",
77374 + "CAP_MAC_ADMIN",
77375 + "CAP_SYSLOG",
77376 + "CAP_WAKE_ALARM",
77377 + "CAP_BLOCK_SUSPEND"
77378 +};
77379 +
77380 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77381 +
77382 +int gr_is_capable(const int cap)
77383 +{
77384 +#ifdef CONFIG_GRKERNSEC
77385 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77386 + return 1;
77387 + return 0;
77388 +#else
77389 + return 1;
77390 +#endif
77391 +}
77392 +
77393 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77394 +{
77395 +#ifdef CONFIG_GRKERNSEC
77396 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77397 + return 1;
77398 + return 0;
77399 +#else
77400 + return 1;
77401 +#endif
77402 +}
77403 +
77404 +int gr_is_capable_nolog(const int cap)
77405 +{
77406 +#ifdef CONFIG_GRKERNSEC
77407 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77408 + return 1;
77409 + return 0;
77410 +#else
77411 + return 1;
77412 +#endif
77413 +}
77414 +
77415 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77416 +{
77417 +#ifdef CONFIG_GRKERNSEC
77418 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77419 + return 1;
77420 + return 0;
77421 +#else
77422 + return 1;
77423 +#endif
77424 +}
77425 +
77426 +EXPORT_SYMBOL_GPL(gr_is_capable);
77427 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77428 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77429 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77430 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77431 new file mode 100644
77432 index 0000000..06cc6ea
77433 --- /dev/null
77434 +++ b/grsecurity/grsec_fifo.c
77435 @@ -0,0 +1,24 @@
77436 +#include <linux/kernel.h>
77437 +#include <linux/sched.h>
77438 +#include <linux/fs.h>
77439 +#include <linux/file.h>
77440 +#include <linux/grinternal.h>
77441 +
77442 +int
77443 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77444 + const struct dentry *dir, const int flag, const int acc_mode)
77445 +{
77446 +#ifdef CONFIG_GRKERNSEC_FIFO
77447 + const struct cred *cred = current_cred();
77448 +
77449 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77450 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77451 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77452 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77453 + if (!inode_permission(dentry->d_inode, acc_mode))
77454 + 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));
77455 + return -EACCES;
77456 + }
77457 +#endif
77458 + return 0;
77459 +}
77460 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77461 new file mode 100644
77462 index 0000000..8ca18bf
77463 --- /dev/null
77464 +++ b/grsecurity/grsec_fork.c
77465 @@ -0,0 +1,23 @@
77466 +#include <linux/kernel.h>
77467 +#include <linux/sched.h>
77468 +#include <linux/grsecurity.h>
77469 +#include <linux/grinternal.h>
77470 +#include <linux/errno.h>
77471 +
77472 +void
77473 +gr_log_forkfail(const int retval)
77474 +{
77475 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77476 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77477 + switch (retval) {
77478 + case -EAGAIN:
77479 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77480 + break;
77481 + case -ENOMEM:
77482 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77483 + break;
77484 + }
77485 + }
77486 +#endif
77487 + return;
77488 +}
77489 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77490 new file mode 100644
77491 index 0000000..b7cb191
77492 --- /dev/null
77493 +++ b/grsecurity/grsec_init.c
77494 @@ -0,0 +1,286 @@
77495 +#include <linux/kernel.h>
77496 +#include <linux/sched.h>
77497 +#include <linux/mm.h>
77498 +#include <linux/gracl.h>
77499 +#include <linux/slab.h>
77500 +#include <linux/vmalloc.h>
77501 +#include <linux/percpu.h>
77502 +#include <linux/module.h>
77503 +
77504 +int grsec_enable_ptrace_readexec;
77505 +int grsec_enable_setxid;
77506 +int grsec_enable_symlinkown;
77507 +kgid_t grsec_symlinkown_gid;
77508 +int grsec_enable_brute;
77509 +int grsec_enable_link;
77510 +int grsec_enable_dmesg;
77511 +int grsec_enable_harden_ptrace;
77512 +int grsec_enable_harden_ipc;
77513 +int grsec_enable_fifo;
77514 +int grsec_enable_execlog;
77515 +int grsec_enable_signal;
77516 +int grsec_enable_forkfail;
77517 +int grsec_enable_audit_ptrace;
77518 +int grsec_enable_time;
77519 +int grsec_enable_group;
77520 +kgid_t grsec_audit_gid;
77521 +int grsec_enable_chdir;
77522 +int grsec_enable_mount;
77523 +int grsec_enable_rofs;
77524 +int grsec_deny_new_usb;
77525 +int grsec_enable_chroot_findtask;
77526 +int grsec_enable_chroot_mount;
77527 +int grsec_enable_chroot_shmat;
77528 +int grsec_enable_chroot_fchdir;
77529 +int grsec_enable_chroot_double;
77530 +int grsec_enable_chroot_pivot;
77531 +int grsec_enable_chroot_chdir;
77532 +int grsec_enable_chroot_chmod;
77533 +int grsec_enable_chroot_mknod;
77534 +int grsec_enable_chroot_nice;
77535 +int grsec_enable_chroot_execlog;
77536 +int grsec_enable_chroot_caps;
77537 +int grsec_enable_chroot_sysctl;
77538 +int grsec_enable_chroot_unix;
77539 +int grsec_enable_tpe;
77540 +kgid_t grsec_tpe_gid;
77541 +int grsec_enable_blackhole;
77542 +#ifdef CONFIG_IPV6_MODULE
77543 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77544 +#endif
77545 +int grsec_lastack_retries;
77546 +int grsec_enable_tpe_all;
77547 +int grsec_enable_tpe_invert;
77548 +int grsec_enable_socket_all;
77549 +kgid_t grsec_socket_all_gid;
77550 +int grsec_enable_socket_client;
77551 +kgid_t grsec_socket_client_gid;
77552 +int grsec_enable_socket_server;
77553 +kgid_t grsec_socket_server_gid;
77554 +int grsec_resource_logging;
77555 +int grsec_disable_privio;
77556 +int grsec_enable_log_rwxmaps;
77557 +int grsec_lock;
77558 +
77559 +DEFINE_SPINLOCK(grsec_alert_lock);
77560 +unsigned long grsec_alert_wtime = 0;
77561 +unsigned long grsec_alert_fyet = 0;
77562 +
77563 +DEFINE_SPINLOCK(grsec_audit_lock);
77564 +
77565 +DEFINE_RWLOCK(grsec_exec_file_lock);
77566 +
77567 +char *gr_shared_page[4];
77568 +
77569 +char *gr_alert_log_fmt;
77570 +char *gr_audit_log_fmt;
77571 +char *gr_alert_log_buf;
77572 +char *gr_audit_log_buf;
77573 +
77574 +extern struct gr_arg *gr_usermode;
77575 +extern unsigned char *gr_system_salt;
77576 +extern unsigned char *gr_system_sum;
77577 +
77578 +void __init
77579 +grsecurity_init(void)
77580 +{
77581 + int j;
77582 + /* create the per-cpu shared pages */
77583 +
77584 +#ifdef CONFIG_X86
77585 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77586 +#endif
77587 +
77588 + for (j = 0; j < 4; j++) {
77589 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77590 + if (gr_shared_page[j] == NULL) {
77591 + panic("Unable to allocate grsecurity shared page");
77592 + return;
77593 + }
77594 + }
77595 +
77596 + /* allocate log buffers */
77597 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77598 + if (!gr_alert_log_fmt) {
77599 + panic("Unable to allocate grsecurity alert log format buffer");
77600 + return;
77601 + }
77602 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77603 + if (!gr_audit_log_fmt) {
77604 + panic("Unable to allocate grsecurity audit log format buffer");
77605 + return;
77606 + }
77607 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77608 + if (!gr_alert_log_buf) {
77609 + panic("Unable to allocate grsecurity alert log buffer");
77610 + return;
77611 + }
77612 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77613 + if (!gr_audit_log_buf) {
77614 + panic("Unable to allocate grsecurity audit log buffer");
77615 + return;
77616 + }
77617 +
77618 + /* allocate memory for authentication structure */
77619 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77620 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77621 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77622 +
77623 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77624 + panic("Unable to allocate grsecurity authentication structure");
77625 + return;
77626 + }
77627 +
77628 +#ifdef CONFIG_GRKERNSEC_IO
77629 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77630 + grsec_disable_privio = 1;
77631 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77632 + grsec_disable_privio = 1;
77633 +#else
77634 + grsec_disable_privio = 0;
77635 +#endif
77636 +#endif
77637 +
77638 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77639 + /* for backward compatibility, tpe_invert always defaults to on if
77640 + enabled in the kernel
77641 + */
77642 + grsec_enable_tpe_invert = 1;
77643 +#endif
77644 +
77645 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77646 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77647 + grsec_lock = 1;
77648 +#endif
77649 +
77650 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77651 + grsec_enable_log_rwxmaps = 1;
77652 +#endif
77653 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77654 + grsec_enable_group = 1;
77655 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77656 +#endif
77657 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77658 + grsec_enable_ptrace_readexec = 1;
77659 +#endif
77660 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77661 + grsec_enable_chdir = 1;
77662 +#endif
77663 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77664 + grsec_enable_harden_ptrace = 1;
77665 +#endif
77666 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77667 + grsec_enable_harden_ipc = 1;
77668 +#endif
77669 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77670 + grsec_enable_mount = 1;
77671 +#endif
77672 +#ifdef CONFIG_GRKERNSEC_LINK
77673 + grsec_enable_link = 1;
77674 +#endif
77675 +#ifdef CONFIG_GRKERNSEC_BRUTE
77676 + grsec_enable_brute = 1;
77677 +#endif
77678 +#ifdef CONFIG_GRKERNSEC_DMESG
77679 + grsec_enable_dmesg = 1;
77680 +#endif
77681 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77682 + grsec_enable_blackhole = 1;
77683 + grsec_lastack_retries = 4;
77684 +#endif
77685 +#ifdef CONFIG_GRKERNSEC_FIFO
77686 + grsec_enable_fifo = 1;
77687 +#endif
77688 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77689 + grsec_enable_execlog = 1;
77690 +#endif
77691 +#ifdef CONFIG_GRKERNSEC_SETXID
77692 + grsec_enable_setxid = 1;
77693 +#endif
77694 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77695 + grsec_enable_signal = 1;
77696 +#endif
77697 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77698 + grsec_enable_forkfail = 1;
77699 +#endif
77700 +#ifdef CONFIG_GRKERNSEC_TIME
77701 + grsec_enable_time = 1;
77702 +#endif
77703 +#ifdef CONFIG_GRKERNSEC_RESLOG
77704 + grsec_resource_logging = 1;
77705 +#endif
77706 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77707 + grsec_enable_chroot_findtask = 1;
77708 +#endif
77709 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77710 + grsec_enable_chroot_unix = 1;
77711 +#endif
77712 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77713 + grsec_enable_chroot_mount = 1;
77714 +#endif
77715 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77716 + grsec_enable_chroot_fchdir = 1;
77717 +#endif
77718 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77719 + grsec_enable_chroot_shmat = 1;
77720 +#endif
77721 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77722 + grsec_enable_audit_ptrace = 1;
77723 +#endif
77724 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77725 + grsec_enable_chroot_double = 1;
77726 +#endif
77727 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77728 + grsec_enable_chroot_pivot = 1;
77729 +#endif
77730 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77731 + grsec_enable_chroot_chdir = 1;
77732 +#endif
77733 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77734 + grsec_enable_chroot_chmod = 1;
77735 +#endif
77736 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77737 + grsec_enable_chroot_mknod = 1;
77738 +#endif
77739 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77740 + grsec_enable_chroot_nice = 1;
77741 +#endif
77742 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77743 + grsec_enable_chroot_execlog = 1;
77744 +#endif
77745 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77746 + grsec_enable_chroot_caps = 1;
77747 +#endif
77748 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77749 + grsec_enable_chroot_sysctl = 1;
77750 +#endif
77751 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77752 + grsec_enable_symlinkown = 1;
77753 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77754 +#endif
77755 +#ifdef CONFIG_GRKERNSEC_TPE
77756 + grsec_enable_tpe = 1;
77757 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77758 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77759 + grsec_enable_tpe_all = 1;
77760 +#endif
77761 +#endif
77762 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77763 + grsec_enable_socket_all = 1;
77764 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77765 +#endif
77766 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77767 + grsec_enable_socket_client = 1;
77768 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77769 +#endif
77770 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77771 + grsec_enable_socket_server = 1;
77772 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77773 +#endif
77774 +#endif
77775 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77776 + grsec_deny_new_usb = 1;
77777 +#endif
77778 +
77779 + return;
77780 +}
77781 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77782 new file mode 100644
77783 index 0000000..1773300
77784 --- /dev/null
77785 +++ b/grsecurity/grsec_ipc.c
77786 @@ -0,0 +1,48 @@
77787 +#include <linux/kernel.h>
77788 +#include <linux/mm.h>
77789 +#include <linux/sched.h>
77790 +#include <linux/file.h>
77791 +#include <linux/ipc.h>
77792 +#include <linux/ipc_namespace.h>
77793 +#include <linux/grsecurity.h>
77794 +#include <linux/grinternal.h>
77795 +
77796 +int
77797 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77798 +{
77799 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77800 + int write;
77801 + int orig_granted_mode;
77802 + kuid_t euid;
77803 + kgid_t egid;
77804 +
77805 + if (!grsec_enable_harden_ipc)
77806 + return 1;
77807 +
77808 + euid = current_euid();
77809 + egid = current_egid();
77810 +
77811 + write = requested_mode & 00002;
77812 + orig_granted_mode = ipcp->mode;
77813 +
77814 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77815 + orig_granted_mode >>= 6;
77816 + else {
77817 + /* if likely wrong permissions, lock to user */
77818 + if (orig_granted_mode & 0007)
77819 + orig_granted_mode = 0;
77820 + /* otherwise do a egid-only check */
77821 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77822 + orig_granted_mode >>= 3;
77823 + /* otherwise, no access */
77824 + else
77825 + orig_granted_mode = 0;
77826 + }
77827 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77828 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77829 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77830 + return 0;
77831 + }
77832 +#endif
77833 + return 1;
77834 +}
77835 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77836 new file mode 100644
77837 index 0000000..5e05e20
77838 --- /dev/null
77839 +++ b/grsecurity/grsec_link.c
77840 @@ -0,0 +1,58 @@
77841 +#include <linux/kernel.h>
77842 +#include <linux/sched.h>
77843 +#include <linux/fs.h>
77844 +#include <linux/file.h>
77845 +#include <linux/grinternal.h>
77846 +
77847 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77848 +{
77849 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77850 + const struct inode *link_inode = link->dentry->d_inode;
77851 +
77852 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77853 + /* ignore root-owned links, e.g. /proc/self */
77854 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77855 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77856 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77857 + return 1;
77858 + }
77859 +#endif
77860 + return 0;
77861 +}
77862 +
77863 +int
77864 +gr_handle_follow_link(const struct inode *parent,
77865 + const struct inode *inode,
77866 + const struct dentry *dentry, const struct vfsmount *mnt)
77867 +{
77868 +#ifdef CONFIG_GRKERNSEC_LINK
77869 + const struct cred *cred = current_cred();
77870 +
77871 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77872 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77873 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77874 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77875 + return -EACCES;
77876 + }
77877 +#endif
77878 + return 0;
77879 +}
77880 +
77881 +int
77882 +gr_handle_hardlink(const struct dentry *dentry,
77883 + const struct vfsmount *mnt,
77884 + struct inode *inode, const int mode, const struct filename *to)
77885 +{
77886 +#ifdef CONFIG_GRKERNSEC_LINK
77887 + const struct cred *cred = current_cred();
77888 +
77889 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77890 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77891 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77892 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77893 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77894 + return -EPERM;
77895 + }
77896 +#endif
77897 + return 0;
77898 +}
77899 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77900 new file mode 100644
77901 index 0000000..dbe0a6b
77902 --- /dev/null
77903 +++ b/grsecurity/grsec_log.c
77904 @@ -0,0 +1,341 @@
77905 +#include <linux/kernel.h>
77906 +#include <linux/sched.h>
77907 +#include <linux/file.h>
77908 +#include <linux/tty.h>
77909 +#include <linux/fs.h>
77910 +#include <linux/mm.h>
77911 +#include <linux/grinternal.h>
77912 +
77913 +#ifdef CONFIG_TREE_PREEMPT_RCU
77914 +#define DISABLE_PREEMPT() preempt_disable()
77915 +#define ENABLE_PREEMPT() preempt_enable()
77916 +#else
77917 +#define DISABLE_PREEMPT()
77918 +#define ENABLE_PREEMPT()
77919 +#endif
77920 +
77921 +#define BEGIN_LOCKS(x) \
77922 + DISABLE_PREEMPT(); \
77923 + rcu_read_lock(); \
77924 + read_lock(&tasklist_lock); \
77925 + read_lock(&grsec_exec_file_lock); \
77926 + if (x != GR_DO_AUDIT) \
77927 + spin_lock(&grsec_alert_lock); \
77928 + else \
77929 + spin_lock(&grsec_audit_lock)
77930 +
77931 +#define END_LOCKS(x) \
77932 + if (x != GR_DO_AUDIT) \
77933 + spin_unlock(&grsec_alert_lock); \
77934 + else \
77935 + spin_unlock(&grsec_audit_lock); \
77936 + read_unlock(&grsec_exec_file_lock); \
77937 + read_unlock(&tasklist_lock); \
77938 + rcu_read_unlock(); \
77939 + ENABLE_PREEMPT(); \
77940 + if (x == GR_DONT_AUDIT) \
77941 + gr_handle_alertkill(current)
77942 +
77943 +enum {
77944 + FLOODING,
77945 + NO_FLOODING
77946 +};
77947 +
77948 +extern char *gr_alert_log_fmt;
77949 +extern char *gr_audit_log_fmt;
77950 +extern char *gr_alert_log_buf;
77951 +extern char *gr_audit_log_buf;
77952 +
77953 +static int gr_log_start(int audit)
77954 +{
77955 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77956 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77957 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77958 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77959 + unsigned long curr_secs = get_seconds();
77960 +
77961 + if (audit == GR_DO_AUDIT)
77962 + goto set_fmt;
77963 +
77964 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77965 + grsec_alert_wtime = curr_secs;
77966 + grsec_alert_fyet = 0;
77967 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77968 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77969 + grsec_alert_fyet++;
77970 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77971 + grsec_alert_wtime = curr_secs;
77972 + grsec_alert_fyet++;
77973 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77974 + return FLOODING;
77975 + }
77976 + else return FLOODING;
77977 +
77978 +set_fmt:
77979 +#endif
77980 + memset(buf, 0, PAGE_SIZE);
77981 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77982 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77983 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77984 + } else if (current->signal->curr_ip) {
77985 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77986 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77987 + } else if (gr_acl_is_enabled()) {
77988 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77989 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77990 + } else {
77991 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77992 + strcpy(buf, fmt);
77993 + }
77994 +
77995 + return NO_FLOODING;
77996 +}
77997 +
77998 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77999 + __attribute__ ((format (printf, 2, 0)));
78000 +
78001 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78002 +{
78003 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78004 + unsigned int len = strlen(buf);
78005 +
78006 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78007 +
78008 + return;
78009 +}
78010 +
78011 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78012 + __attribute__ ((format (printf, 2, 3)));
78013 +
78014 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78015 +{
78016 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78017 + unsigned int len = strlen(buf);
78018 + va_list ap;
78019 +
78020 + va_start(ap, msg);
78021 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78022 + va_end(ap);
78023 +
78024 + return;
78025 +}
78026 +
78027 +static void gr_log_end(int audit, int append_default)
78028 +{
78029 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78030 + if (append_default) {
78031 + struct task_struct *task = current;
78032 + struct task_struct *parent = task->real_parent;
78033 + const struct cred *cred = __task_cred(task);
78034 + const struct cred *pcred = __task_cred(parent);
78035 + unsigned int len = strlen(buf);
78036 +
78037 + 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));
78038 + }
78039 +
78040 + printk("%s\n", buf);
78041 +
78042 + return;
78043 +}
78044 +
78045 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
78046 +{
78047 + int logtype;
78048 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
78049 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
78050 + void *voidptr = NULL;
78051 + int num1 = 0, num2 = 0;
78052 + unsigned long ulong1 = 0, ulong2 = 0;
78053 + struct dentry *dentry = NULL;
78054 + struct vfsmount *mnt = NULL;
78055 + struct file *file = NULL;
78056 + struct task_struct *task = NULL;
78057 + struct vm_area_struct *vma = NULL;
78058 + const struct cred *cred, *pcred;
78059 + va_list ap;
78060 +
78061 + BEGIN_LOCKS(audit);
78062 + logtype = gr_log_start(audit);
78063 + if (logtype == FLOODING) {
78064 + END_LOCKS(audit);
78065 + return;
78066 + }
78067 + va_start(ap, argtypes);
78068 + switch (argtypes) {
78069 + case GR_TTYSNIFF:
78070 + task = va_arg(ap, struct task_struct *);
78071 + 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));
78072 + break;
78073 + case GR_SYSCTL_HIDDEN:
78074 + str1 = va_arg(ap, char *);
78075 + gr_log_middle_varargs(audit, msg, result, str1);
78076 + break;
78077 + case GR_RBAC:
78078 + dentry = va_arg(ap, struct dentry *);
78079 + mnt = va_arg(ap, struct vfsmount *);
78080 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
78081 + break;
78082 + case GR_RBAC_STR:
78083 + dentry = va_arg(ap, struct dentry *);
78084 + mnt = va_arg(ap, struct vfsmount *);
78085 + str1 = va_arg(ap, char *);
78086 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
78087 + break;
78088 + case GR_STR_RBAC:
78089 + str1 = va_arg(ap, char *);
78090 + dentry = va_arg(ap, struct dentry *);
78091 + mnt = va_arg(ap, struct vfsmount *);
78092 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
78093 + break;
78094 + case GR_RBAC_MODE2:
78095 + dentry = va_arg(ap, struct dentry *);
78096 + mnt = va_arg(ap, struct vfsmount *);
78097 + str1 = va_arg(ap, char *);
78098 + str2 = va_arg(ap, char *);
78099 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
78100 + break;
78101 + case GR_RBAC_MODE3:
78102 + dentry = va_arg(ap, struct dentry *);
78103 + mnt = va_arg(ap, struct vfsmount *);
78104 + str1 = va_arg(ap, char *);
78105 + str2 = va_arg(ap, char *);
78106 + str3 = va_arg(ap, char *);
78107 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
78108 + break;
78109 + case GR_FILENAME:
78110 + dentry = va_arg(ap, struct dentry *);
78111 + mnt = va_arg(ap, struct vfsmount *);
78112 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
78113 + break;
78114 + case GR_STR_FILENAME:
78115 + str1 = va_arg(ap, char *);
78116 + dentry = va_arg(ap, struct dentry *);
78117 + mnt = va_arg(ap, struct vfsmount *);
78118 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78119 + break;
78120 + case GR_FILENAME_STR:
78121 + dentry = va_arg(ap, struct dentry *);
78122 + mnt = va_arg(ap, struct vfsmount *);
78123 + str1 = va_arg(ap, char *);
78124 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78125 + break;
78126 + case GR_FILENAME_TWO_INT:
78127 + dentry = va_arg(ap, struct dentry *);
78128 + mnt = va_arg(ap, struct vfsmount *);
78129 + num1 = va_arg(ap, int);
78130 + num2 = va_arg(ap, int);
78131 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78132 + break;
78133 + case GR_FILENAME_TWO_INT_STR:
78134 + dentry = va_arg(ap, struct dentry *);
78135 + mnt = va_arg(ap, struct vfsmount *);
78136 + num1 = va_arg(ap, int);
78137 + num2 = va_arg(ap, int);
78138 + str1 = va_arg(ap, char *);
78139 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78140 + break;
78141 + case GR_TEXTREL:
78142 + file = va_arg(ap, struct file *);
78143 + ulong1 = va_arg(ap, unsigned long);
78144 + ulong2 = va_arg(ap, unsigned long);
78145 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78146 + break;
78147 + case GR_PTRACE:
78148 + task = va_arg(ap, struct task_struct *);
78149 + 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));
78150 + break;
78151 + case GR_RESOURCE:
78152 + task = va_arg(ap, struct task_struct *);
78153 + cred = __task_cred(task);
78154 + pcred = __task_cred(task->real_parent);
78155 + ulong1 = va_arg(ap, unsigned long);
78156 + str1 = va_arg(ap, char *);
78157 + ulong2 = va_arg(ap, unsigned long);
78158 + 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));
78159 + break;
78160 + case GR_CAP:
78161 + task = va_arg(ap, struct task_struct *);
78162 + cred = __task_cred(task);
78163 + pcred = __task_cred(task->real_parent);
78164 + str1 = va_arg(ap, char *);
78165 + 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));
78166 + break;
78167 + case GR_SIG:
78168 + str1 = va_arg(ap, char *);
78169 + voidptr = va_arg(ap, void *);
78170 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78171 + break;
78172 + case GR_SIG2:
78173 + task = va_arg(ap, struct task_struct *);
78174 + cred = __task_cred(task);
78175 + pcred = __task_cred(task->real_parent);
78176 + num1 = va_arg(ap, int);
78177 + 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));
78178 + break;
78179 + case GR_CRASH1:
78180 + task = va_arg(ap, struct task_struct *);
78181 + cred = __task_cred(task);
78182 + pcred = __task_cred(task->real_parent);
78183 + ulong1 = va_arg(ap, unsigned long);
78184 + 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);
78185 + break;
78186 + case GR_CRASH2:
78187 + task = va_arg(ap, struct task_struct *);
78188 + cred = __task_cred(task);
78189 + pcred = __task_cred(task->real_parent);
78190 + ulong1 = va_arg(ap, unsigned long);
78191 + 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);
78192 + break;
78193 + case GR_RWXMAP:
78194 + file = va_arg(ap, struct file *);
78195 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78196 + break;
78197 + case GR_RWXMAPVMA:
78198 + vma = va_arg(ap, struct vm_area_struct *);
78199 + if (vma->vm_file)
78200 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78201 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78202 + str1 = "<stack>";
78203 + else if (vma->vm_start <= current->mm->brk &&
78204 + vma->vm_end >= current->mm->start_brk)
78205 + str1 = "<heap>";
78206 + else
78207 + str1 = "<anonymous mapping>";
78208 + gr_log_middle_varargs(audit, msg, str1);
78209 + break;
78210 + case GR_PSACCT:
78211 + {
78212 + unsigned int wday, cday;
78213 + __u8 whr, chr;
78214 + __u8 wmin, cmin;
78215 + __u8 wsec, csec;
78216 + char cur_tty[64] = { 0 };
78217 + char parent_tty[64] = { 0 };
78218 +
78219 + task = va_arg(ap, struct task_struct *);
78220 + wday = va_arg(ap, unsigned int);
78221 + cday = va_arg(ap, unsigned int);
78222 + whr = va_arg(ap, int);
78223 + chr = va_arg(ap, int);
78224 + wmin = va_arg(ap, int);
78225 + cmin = va_arg(ap, int);
78226 + wsec = va_arg(ap, int);
78227 + csec = va_arg(ap, int);
78228 + ulong1 = va_arg(ap, unsigned long);
78229 + cred = __task_cred(task);
78230 + pcred = __task_cred(task->real_parent);
78231 +
78232 + 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));
78233 + }
78234 + break;
78235 + default:
78236 + gr_log_middle(audit, msg, ap);
78237 + }
78238 + va_end(ap);
78239 + // these don't need DEFAULTSECARGS printed on the end
78240 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78241 + gr_log_end(audit, 0);
78242 + else
78243 + gr_log_end(audit, 1);
78244 + END_LOCKS(audit);
78245 +}
78246 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78247 new file mode 100644
78248 index 0000000..0e39d8c
78249 --- /dev/null
78250 +++ b/grsecurity/grsec_mem.c
78251 @@ -0,0 +1,48 @@
78252 +#include <linux/kernel.h>
78253 +#include <linux/sched.h>
78254 +#include <linux/mm.h>
78255 +#include <linux/mman.h>
78256 +#include <linux/module.h>
78257 +#include <linux/grinternal.h>
78258 +
78259 +void gr_handle_msr_write(void)
78260 +{
78261 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78262 + return;
78263 +}
78264 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78265 +
78266 +void
78267 +gr_handle_ioperm(void)
78268 +{
78269 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78270 + return;
78271 +}
78272 +
78273 +void
78274 +gr_handle_iopl(void)
78275 +{
78276 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78277 + return;
78278 +}
78279 +
78280 +void
78281 +gr_handle_mem_readwrite(u64 from, u64 to)
78282 +{
78283 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78284 + return;
78285 +}
78286 +
78287 +void
78288 +gr_handle_vm86(void)
78289 +{
78290 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78291 + return;
78292 +}
78293 +
78294 +void
78295 +gr_log_badprocpid(const char *entry)
78296 +{
78297 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78298 + return;
78299 +}
78300 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78301 new file mode 100644
78302 index 0000000..cd9e124
78303 --- /dev/null
78304 +++ b/grsecurity/grsec_mount.c
78305 @@ -0,0 +1,65 @@
78306 +#include <linux/kernel.h>
78307 +#include <linux/sched.h>
78308 +#include <linux/mount.h>
78309 +#include <linux/major.h>
78310 +#include <linux/grsecurity.h>
78311 +#include <linux/grinternal.h>
78312 +
78313 +void
78314 +gr_log_remount(const char *devname, const int retval)
78315 +{
78316 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78317 + if (grsec_enable_mount && (retval >= 0))
78318 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78319 +#endif
78320 + return;
78321 +}
78322 +
78323 +void
78324 +gr_log_unmount(const char *devname, const int retval)
78325 +{
78326 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78327 + if (grsec_enable_mount && (retval >= 0))
78328 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78329 +#endif
78330 + return;
78331 +}
78332 +
78333 +void
78334 +gr_log_mount(const char *from, const char *to, const int retval)
78335 +{
78336 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78337 + if (grsec_enable_mount && (retval >= 0))
78338 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78339 +#endif
78340 + return;
78341 +}
78342 +
78343 +int
78344 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78345 +{
78346 +#ifdef CONFIG_GRKERNSEC_ROFS
78347 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78348 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78349 + return -EPERM;
78350 + } else
78351 + return 0;
78352 +#endif
78353 + return 0;
78354 +}
78355 +
78356 +int
78357 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78358 +{
78359 +#ifdef CONFIG_GRKERNSEC_ROFS
78360 + struct inode *inode = dentry->d_inode;
78361 +
78362 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78363 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78364 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78365 + return -EPERM;
78366 + } else
78367 + return 0;
78368 +#endif
78369 + return 0;
78370 +}
78371 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78372 new file mode 100644
78373 index 0000000..6ee9d50
78374 --- /dev/null
78375 +++ b/grsecurity/grsec_pax.c
78376 @@ -0,0 +1,45 @@
78377 +#include <linux/kernel.h>
78378 +#include <linux/sched.h>
78379 +#include <linux/mm.h>
78380 +#include <linux/file.h>
78381 +#include <linux/grinternal.h>
78382 +#include <linux/grsecurity.h>
78383 +
78384 +void
78385 +gr_log_textrel(struct vm_area_struct * vma)
78386 +{
78387 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78388 + if (grsec_enable_log_rwxmaps)
78389 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78390 +#endif
78391 + return;
78392 +}
78393 +
78394 +void gr_log_ptgnustack(struct file *file)
78395 +{
78396 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78397 + if (grsec_enable_log_rwxmaps)
78398 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78399 +#endif
78400 + return;
78401 +}
78402 +
78403 +void
78404 +gr_log_rwxmmap(struct file *file)
78405 +{
78406 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78407 + if (grsec_enable_log_rwxmaps)
78408 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78409 +#endif
78410 + return;
78411 +}
78412 +
78413 +void
78414 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78415 +{
78416 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78417 + if (grsec_enable_log_rwxmaps)
78418 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78419 +#endif
78420 + return;
78421 +}
78422 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78423 new file mode 100644
78424 index 0000000..2005a3a
78425 --- /dev/null
78426 +++ b/grsecurity/grsec_proc.c
78427 @@ -0,0 +1,20 @@
78428 +#include <linux/kernel.h>
78429 +#include <linux/sched.h>
78430 +#include <linux/grsecurity.h>
78431 +#include <linux/grinternal.h>
78432 +
78433 +int gr_proc_is_restricted(void)
78434 +{
78435 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78436 + const struct cred *cred = current_cred();
78437 +#endif
78438 +
78439 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78440 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78441 + return -EACCES;
78442 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78443 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78444 + return -EACCES;
78445 +#endif
78446 + return 0;
78447 +}
78448 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78449 new file mode 100644
78450 index 0000000..f7f29aa
78451 --- /dev/null
78452 +++ b/grsecurity/grsec_ptrace.c
78453 @@ -0,0 +1,30 @@
78454 +#include <linux/kernel.h>
78455 +#include <linux/sched.h>
78456 +#include <linux/grinternal.h>
78457 +#include <linux/security.h>
78458 +
78459 +void
78460 +gr_audit_ptrace(struct task_struct *task)
78461 +{
78462 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78463 + if (grsec_enable_audit_ptrace)
78464 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78465 +#endif
78466 + return;
78467 +}
78468 +
78469 +int
78470 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78471 +{
78472 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78473 + const struct dentry *dentry = file->f_path.dentry;
78474 + const struct vfsmount *mnt = file->f_path.mnt;
78475 +
78476 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78477 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78478 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78479 + return -EACCES;
78480 + }
78481 +#endif
78482 + return 0;
78483 +}
78484 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78485 new file mode 100644
78486 index 0000000..3860c7e
78487 --- /dev/null
78488 +++ b/grsecurity/grsec_sig.c
78489 @@ -0,0 +1,236 @@
78490 +#include <linux/kernel.h>
78491 +#include <linux/sched.h>
78492 +#include <linux/fs.h>
78493 +#include <linux/delay.h>
78494 +#include <linux/grsecurity.h>
78495 +#include <linux/grinternal.h>
78496 +#include <linux/hardirq.h>
78497 +
78498 +char *signames[] = {
78499 + [SIGSEGV] = "Segmentation fault",
78500 + [SIGILL] = "Illegal instruction",
78501 + [SIGABRT] = "Abort",
78502 + [SIGBUS] = "Invalid alignment/Bus error"
78503 +};
78504 +
78505 +void
78506 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78507 +{
78508 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78509 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78510 + (sig == SIGABRT) || (sig == SIGBUS))) {
78511 + if (task_pid_nr(t) == task_pid_nr(current)) {
78512 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78513 + } else {
78514 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78515 + }
78516 + }
78517 +#endif
78518 + return;
78519 +}
78520 +
78521 +int
78522 +gr_handle_signal(const struct task_struct *p, const int sig)
78523 +{
78524 +#ifdef CONFIG_GRKERNSEC
78525 + /* ignore the 0 signal for protected task checks */
78526 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78527 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78528 + return -EPERM;
78529 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78530 + return -EPERM;
78531 + }
78532 +#endif
78533 + return 0;
78534 +}
78535 +
78536 +#ifdef CONFIG_GRKERNSEC
78537 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78538 +
78539 +int gr_fake_force_sig(int sig, struct task_struct *t)
78540 +{
78541 + unsigned long int flags;
78542 + int ret, blocked, ignored;
78543 + struct k_sigaction *action;
78544 +
78545 + spin_lock_irqsave(&t->sighand->siglock, flags);
78546 + action = &t->sighand->action[sig-1];
78547 + ignored = action->sa.sa_handler == SIG_IGN;
78548 + blocked = sigismember(&t->blocked, sig);
78549 + if (blocked || ignored) {
78550 + action->sa.sa_handler = SIG_DFL;
78551 + if (blocked) {
78552 + sigdelset(&t->blocked, sig);
78553 + recalc_sigpending_and_wake(t);
78554 + }
78555 + }
78556 + if (action->sa.sa_handler == SIG_DFL)
78557 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78558 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78559 +
78560 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78561 +
78562 + return ret;
78563 +}
78564 +#endif
78565 +
78566 +#define GR_USER_BAN_TIME (15 * 60)
78567 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78568 +
78569 +void gr_handle_brute_attach(int dumpable)
78570 +{
78571 +#ifdef CONFIG_GRKERNSEC_BRUTE
78572 + struct task_struct *p = current;
78573 + kuid_t uid = GLOBAL_ROOT_UID;
78574 + int daemon = 0;
78575 +
78576 + if (!grsec_enable_brute)
78577 + return;
78578 +
78579 + rcu_read_lock();
78580 + read_lock(&tasklist_lock);
78581 + read_lock(&grsec_exec_file_lock);
78582 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78583 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78584 + p->real_parent->brute = 1;
78585 + daemon = 1;
78586 + } else {
78587 + const struct cred *cred = __task_cred(p), *cred2;
78588 + struct task_struct *tsk, *tsk2;
78589 +
78590 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78591 + struct user_struct *user;
78592 +
78593 + uid = cred->uid;
78594 +
78595 + /* this is put upon execution past expiration */
78596 + user = find_user(uid);
78597 + if (user == NULL)
78598 + goto unlock;
78599 + user->suid_banned = 1;
78600 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78601 + if (user->suid_ban_expires == ~0UL)
78602 + user->suid_ban_expires--;
78603 +
78604 + /* only kill other threads of the same binary, from the same user */
78605 + do_each_thread(tsk2, tsk) {
78606 + cred2 = __task_cred(tsk);
78607 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78608 + gr_fake_force_sig(SIGKILL, tsk);
78609 + } while_each_thread(tsk2, tsk);
78610 + }
78611 + }
78612 +unlock:
78613 + read_unlock(&grsec_exec_file_lock);
78614 + read_unlock(&tasklist_lock);
78615 + rcu_read_unlock();
78616 +
78617 + if (gr_is_global_nonroot(uid))
78618 + 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);
78619 + else if (daemon)
78620 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78621 +
78622 +#endif
78623 + return;
78624 +}
78625 +
78626 +void gr_handle_brute_check(void)
78627 +{
78628 +#ifdef CONFIG_GRKERNSEC_BRUTE
78629 + struct task_struct *p = current;
78630 +
78631 + if (unlikely(p->brute)) {
78632 + if (!grsec_enable_brute)
78633 + p->brute = 0;
78634 + else if (time_before(get_seconds(), p->brute_expires))
78635 + msleep(30 * 1000);
78636 + }
78637 +#endif
78638 + return;
78639 +}
78640 +
78641 +void gr_handle_kernel_exploit(void)
78642 +{
78643 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78644 + const struct cred *cred;
78645 + struct task_struct *tsk, *tsk2;
78646 + struct user_struct *user;
78647 + kuid_t uid;
78648 +
78649 + if (in_irq() || in_serving_softirq() || in_nmi())
78650 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78651 +
78652 + uid = current_uid();
78653 +
78654 + if (gr_is_global_root(uid))
78655 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78656 + else {
78657 + /* kill all the processes of this user, hold a reference
78658 + to their creds struct, and prevent them from creating
78659 + another process until system reset
78660 + */
78661 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78662 + GR_GLOBAL_UID(uid));
78663 + /* we intentionally leak this ref */
78664 + user = get_uid(current->cred->user);
78665 + if (user)
78666 + user->kernel_banned = 1;
78667 +
78668 + /* kill all processes of this user */
78669 + read_lock(&tasklist_lock);
78670 + do_each_thread(tsk2, tsk) {
78671 + cred = __task_cred(tsk);
78672 + if (uid_eq(cred->uid, uid))
78673 + gr_fake_force_sig(SIGKILL, tsk);
78674 + } while_each_thread(tsk2, tsk);
78675 + read_unlock(&tasklist_lock);
78676 + }
78677 +#endif
78678 +}
78679 +
78680 +#ifdef CONFIG_GRKERNSEC_BRUTE
78681 +static bool suid_ban_expired(struct user_struct *user)
78682 +{
78683 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78684 + user->suid_banned = 0;
78685 + user->suid_ban_expires = 0;
78686 + free_uid(user);
78687 + return true;
78688 + }
78689 +
78690 + return false;
78691 +}
78692 +#endif
78693 +
78694 +int gr_process_kernel_exec_ban(void)
78695 +{
78696 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78697 + if (unlikely(current->cred->user->kernel_banned))
78698 + return -EPERM;
78699 +#endif
78700 + return 0;
78701 +}
78702 +
78703 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78704 +{
78705 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78706 + if (unlikely(user->kernel_banned))
78707 + gr_fake_force_sig(SIGKILL, current);
78708 +#endif
78709 + return 0;
78710 +}
78711 +
78712 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78713 +{
78714 +#ifdef CONFIG_GRKERNSEC_BRUTE
78715 + struct user_struct *user = current->cred->user;
78716 + if (unlikely(user->suid_banned)) {
78717 + if (suid_ban_expired(user))
78718 + return 0;
78719 + /* disallow execution of suid binaries only */
78720 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78721 + return -EPERM;
78722 + }
78723 +#endif
78724 + return 0;
78725 +}
78726 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78727 new file mode 100644
78728 index 0000000..e3650b6
78729 --- /dev/null
78730 +++ b/grsecurity/grsec_sock.c
78731 @@ -0,0 +1,244 @@
78732 +#include <linux/kernel.h>
78733 +#include <linux/module.h>
78734 +#include <linux/sched.h>
78735 +#include <linux/file.h>
78736 +#include <linux/net.h>
78737 +#include <linux/in.h>
78738 +#include <linux/ip.h>
78739 +#include <net/sock.h>
78740 +#include <net/inet_sock.h>
78741 +#include <linux/grsecurity.h>
78742 +#include <linux/grinternal.h>
78743 +#include <linux/gracl.h>
78744 +
78745 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78746 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78747 +
78748 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78749 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78750 +
78751 +#ifdef CONFIG_UNIX_MODULE
78752 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78753 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78754 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78755 +EXPORT_SYMBOL_GPL(gr_handle_create);
78756 +#endif
78757 +
78758 +#ifdef CONFIG_GRKERNSEC
78759 +#define gr_conn_table_size 32749
78760 +struct conn_table_entry {
78761 + struct conn_table_entry *next;
78762 + struct signal_struct *sig;
78763 +};
78764 +
78765 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78766 +DEFINE_SPINLOCK(gr_conn_table_lock);
78767 +
78768 +extern const char * gr_socktype_to_name(unsigned char type);
78769 +extern const char * gr_proto_to_name(unsigned char proto);
78770 +extern const char * gr_sockfamily_to_name(unsigned char family);
78771 +
78772 +static __inline__ int
78773 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78774 +{
78775 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78776 +}
78777 +
78778 +static __inline__ int
78779 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78780 + __u16 sport, __u16 dport)
78781 +{
78782 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78783 + sig->gr_sport == sport && sig->gr_dport == dport))
78784 + return 1;
78785 + else
78786 + return 0;
78787 +}
78788 +
78789 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78790 +{
78791 + struct conn_table_entry **match;
78792 + unsigned int index;
78793 +
78794 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78795 + sig->gr_sport, sig->gr_dport,
78796 + gr_conn_table_size);
78797 +
78798 + newent->sig = sig;
78799 +
78800 + match = &gr_conn_table[index];
78801 + newent->next = *match;
78802 + *match = newent;
78803 +
78804 + return;
78805 +}
78806 +
78807 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78808 +{
78809 + struct conn_table_entry *match, *last = NULL;
78810 + unsigned int index;
78811 +
78812 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78813 + sig->gr_sport, sig->gr_dport,
78814 + gr_conn_table_size);
78815 +
78816 + match = gr_conn_table[index];
78817 + while (match && !conn_match(match->sig,
78818 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78819 + sig->gr_dport)) {
78820 + last = match;
78821 + match = match->next;
78822 + }
78823 +
78824 + if (match) {
78825 + if (last)
78826 + last->next = match->next;
78827 + else
78828 + gr_conn_table[index] = NULL;
78829 + kfree(match);
78830 + }
78831 +
78832 + return;
78833 +}
78834 +
78835 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78836 + __u16 sport, __u16 dport)
78837 +{
78838 + struct conn_table_entry *match;
78839 + unsigned int index;
78840 +
78841 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78842 +
78843 + match = gr_conn_table[index];
78844 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78845 + match = match->next;
78846 +
78847 + if (match)
78848 + return match->sig;
78849 + else
78850 + return NULL;
78851 +}
78852 +
78853 +#endif
78854 +
78855 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78856 +{
78857 +#ifdef CONFIG_GRKERNSEC
78858 + struct signal_struct *sig = current->signal;
78859 + struct conn_table_entry *newent;
78860 +
78861 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78862 + if (newent == NULL)
78863 + return;
78864 + /* no bh lock needed since we are called with bh disabled */
78865 + spin_lock(&gr_conn_table_lock);
78866 + gr_del_task_from_ip_table_nolock(sig);
78867 + sig->gr_saddr = inet->inet_rcv_saddr;
78868 + sig->gr_daddr = inet->inet_daddr;
78869 + sig->gr_sport = inet->inet_sport;
78870 + sig->gr_dport = inet->inet_dport;
78871 + gr_add_to_task_ip_table_nolock(sig, newent);
78872 + spin_unlock(&gr_conn_table_lock);
78873 +#endif
78874 + return;
78875 +}
78876 +
78877 +void gr_del_task_from_ip_table(struct task_struct *task)
78878 +{
78879 +#ifdef CONFIG_GRKERNSEC
78880 + spin_lock_bh(&gr_conn_table_lock);
78881 + gr_del_task_from_ip_table_nolock(task->signal);
78882 + spin_unlock_bh(&gr_conn_table_lock);
78883 +#endif
78884 + return;
78885 +}
78886 +
78887 +void
78888 +gr_attach_curr_ip(const struct sock *sk)
78889 +{
78890 +#ifdef CONFIG_GRKERNSEC
78891 + struct signal_struct *p, *set;
78892 + const struct inet_sock *inet = inet_sk(sk);
78893 +
78894 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78895 + return;
78896 +
78897 + set = current->signal;
78898 +
78899 + spin_lock_bh(&gr_conn_table_lock);
78900 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78901 + inet->inet_dport, inet->inet_sport);
78902 + if (unlikely(p != NULL)) {
78903 + set->curr_ip = p->curr_ip;
78904 + set->used_accept = 1;
78905 + gr_del_task_from_ip_table_nolock(p);
78906 + spin_unlock_bh(&gr_conn_table_lock);
78907 + return;
78908 + }
78909 + spin_unlock_bh(&gr_conn_table_lock);
78910 +
78911 + set->curr_ip = inet->inet_daddr;
78912 + set->used_accept = 1;
78913 +#endif
78914 + return;
78915 +}
78916 +
78917 +int
78918 +gr_handle_sock_all(const int family, const int type, const int protocol)
78919 +{
78920 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78921 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78922 + (family != AF_UNIX)) {
78923 + if (family == AF_INET)
78924 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78925 + else
78926 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78927 + return -EACCES;
78928 + }
78929 +#endif
78930 + return 0;
78931 +}
78932 +
78933 +int
78934 +gr_handle_sock_server(const struct sockaddr *sck)
78935 +{
78936 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78937 + if (grsec_enable_socket_server &&
78938 + in_group_p(grsec_socket_server_gid) &&
78939 + sck && (sck->sa_family != AF_UNIX) &&
78940 + (sck->sa_family != AF_LOCAL)) {
78941 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78942 + return -EACCES;
78943 + }
78944 +#endif
78945 + return 0;
78946 +}
78947 +
78948 +int
78949 +gr_handle_sock_server_other(const struct sock *sck)
78950 +{
78951 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78952 + if (grsec_enable_socket_server &&
78953 + in_group_p(grsec_socket_server_gid) &&
78954 + sck && (sck->sk_family != AF_UNIX) &&
78955 + (sck->sk_family != AF_LOCAL)) {
78956 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78957 + return -EACCES;
78958 + }
78959 +#endif
78960 + return 0;
78961 +}
78962 +
78963 +int
78964 +gr_handle_sock_client(const struct sockaddr *sck)
78965 +{
78966 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78967 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78968 + sck && (sck->sa_family != AF_UNIX) &&
78969 + (sck->sa_family != AF_LOCAL)) {
78970 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78971 + return -EACCES;
78972 + }
78973 +#endif
78974 + return 0;
78975 +}
78976 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78977 new file mode 100644
78978 index 0000000..8159888
78979 --- /dev/null
78980 +++ b/grsecurity/grsec_sysctl.c
78981 @@ -0,0 +1,479 @@
78982 +#include <linux/kernel.h>
78983 +#include <linux/sched.h>
78984 +#include <linux/sysctl.h>
78985 +#include <linux/grsecurity.h>
78986 +#include <linux/grinternal.h>
78987 +
78988 +int
78989 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78990 +{
78991 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78992 + if (dirname == NULL || name == NULL)
78993 + return 0;
78994 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78995 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78996 + return -EACCES;
78997 + }
78998 +#endif
78999 + return 0;
79000 +}
79001 +
79002 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
79003 +static int __maybe_unused __read_only one = 1;
79004 +#endif
79005 +
79006 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
79007 + defined(CONFIG_GRKERNSEC_DENYUSB)
79008 +struct ctl_table grsecurity_table[] = {
79009 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79010 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
79011 +#ifdef CONFIG_GRKERNSEC_IO
79012 + {
79013 + .procname = "disable_priv_io",
79014 + .data = &grsec_disable_privio,
79015 + .maxlen = sizeof(int),
79016 + .mode = 0600,
79017 + .proc_handler = &proc_dointvec,
79018 + },
79019 +#endif
79020 +#endif
79021 +#ifdef CONFIG_GRKERNSEC_LINK
79022 + {
79023 + .procname = "linking_restrictions",
79024 + .data = &grsec_enable_link,
79025 + .maxlen = sizeof(int),
79026 + .mode = 0600,
79027 + .proc_handler = &proc_dointvec,
79028 + },
79029 +#endif
79030 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79031 + {
79032 + .procname = "enforce_symlinksifowner",
79033 + .data = &grsec_enable_symlinkown,
79034 + .maxlen = sizeof(int),
79035 + .mode = 0600,
79036 + .proc_handler = &proc_dointvec,
79037 + },
79038 + {
79039 + .procname = "symlinkown_gid",
79040 + .data = &grsec_symlinkown_gid,
79041 + .maxlen = sizeof(int),
79042 + .mode = 0600,
79043 + .proc_handler = &proc_dointvec,
79044 + },
79045 +#endif
79046 +#ifdef CONFIG_GRKERNSEC_BRUTE
79047 + {
79048 + .procname = "deter_bruteforce",
79049 + .data = &grsec_enable_brute,
79050 + .maxlen = sizeof(int),
79051 + .mode = 0600,
79052 + .proc_handler = &proc_dointvec,
79053 + },
79054 +#endif
79055 +#ifdef CONFIG_GRKERNSEC_FIFO
79056 + {
79057 + .procname = "fifo_restrictions",
79058 + .data = &grsec_enable_fifo,
79059 + .maxlen = sizeof(int),
79060 + .mode = 0600,
79061 + .proc_handler = &proc_dointvec,
79062 + },
79063 +#endif
79064 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79065 + {
79066 + .procname = "ptrace_readexec",
79067 + .data = &grsec_enable_ptrace_readexec,
79068 + .maxlen = sizeof(int),
79069 + .mode = 0600,
79070 + .proc_handler = &proc_dointvec,
79071 + },
79072 +#endif
79073 +#ifdef CONFIG_GRKERNSEC_SETXID
79074 + {
79075 + .procname = "consistent_setxid",
79076 + .data = &grsec_enable_setxid,
79077 + .maxlen = sizeof(int),
79078 + .mode = 0600,
79079 + .proc_handler = &proc_dointvec,
79080 + },
79081 +#endif
79082 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79083 + {
79084 + .procname = "ip_blackhole",
79085 + .data = &grsec_enable_blackhole,
79086 + .maxlen = sizeof(int),
79087 + .mode = 0600,
79088 + .proc_handler = &proc_dointvec,
79089 + },
79090 + {
79091 + .procname = "lastack_retries",
79092 + .data = &grsec_lastack_retries,
79093 + .maxlen = sizeof(int),
79094 + .mode = 0600,
79095 + .proc_handler = &proc_dointvec,
79096 + },
79097 +#endif
79098 +#ifdef CONFIG_GRKERNSEC_EXECLOG
79099 + {
79100 + .procname = "exec_logging",
79101 + .data = &grsec_enable_execlog,
79102 + .maxlen = sizeof(int),
79103 + .mode = 0600,
79104 + .proc_handler = &proc_dointvec,
79105 + },
79106 +#endif
79107 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79108 + {
79109 + .procname = "rwxmap_logging",
79110 + .data = &grsec_enable_log_rwxmaps,
79111 + .maxlen = sizeof(int),
79112 + .mode = 0600,
79113 + .proc_handler = &proc_dointvec,
79114 + },
79115 +#endif
79116 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79117 + {
79118 + .procname = "signal_logging",
79119 + .data = &grsec_enable_signal,
79120 + .maxlen = sizeof(int),
79121 + .mode = 0600,
79122 + .proc_handler = &proc_dointvec,
79123 + },
79124 +#endif
79125 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
79126 + {
79127 + .procname = "forkfail_logging",
79128 + .data = &grsec_enable_forkfail,
79129 + .maxlen = sizeof(int),
79130 + .mode = 0600,
79131 + .proc_handler = &proc_dointvec,
79132 + },
79133 +#endif
79134 +#ifdef CONFIG_GRKERNSEC_TIME
79135 + {
79136 + .procname = "timechange_logging",
79137 + .data = &grsec_enable_time,
79138 + .maxlen = sizeof(int),
79139 + .mode = 0600,
79140 + .proc_handler = &proc_dointvec,
79141 + },
79142 +#endif
79143 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79144 + {
79145 + .procname = "chroot_deny_shmat",
79146 + .data = &grsec_enable_chroot_shmat,
79147 + .maxlen = sizeof(int),
79148 + .mode = 0600,
79149 + .proc_handler = &proc_dointvec,
79150 + },
79151 +#endif
79152 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79153 + {
79154 + .procname = "chroot_deny_unix",
79155 + .data = &grsec_enable_chroot_unix,
79156 + .maxlen = sizeof(int),
79157 + .mode = 0600,
79158 + .proc_handler = &proc_dointvec,
79159 + },
79160 +#endif
79161 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79162 + {
79163 + .procname = "chroot_deny_mount",
79164 + .data = &grsec_enable_chroot_mount,
79165 + .maxlen = sizeof(int),
79166 + .mode = 0600,
79167 + .proc_handler = &proc_dointvec,
79168 + },
79169 +#endif
79170 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79171 + {
79172 + .procname = "chroot_deny_fchdir",
79173 + .data = &grsec_enable_chroot_fchdir,
79174 + .maxlen = sizeof(int),
79175 + .mode = 0600,
79176 + .proc_handler = &proc_dointvec,
79177 + },
79178 +#endif
79179 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79180 + {
79181 + .procname = "chroot_deny_chroot",
79182 + .data = &grsec_enable_chroot_double,
79183 + .maxlen = sizeof(int),
79184 + .mode = 0600,
79185 + .proc_handler = &proc_dointvec,
79186 + },
79187 +#endif
79188 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79189 + {
79190 + .procname = "chroot_deny_pivot",
79191 + .data = &grsec_enable_chroot_pivot,
79192 + .maxlen = sizeof(int),
79193 + .mode = 0600,
79194 + .proc_handler = &proc_dointvec,
79195 + },
79196 +#endif
79197 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79198 + {
79199 + .procname = "chroot_enforce_chdir",
79200 + .data = &grsec_enable_chroot_chdir,
79201 + .maxlen = sizeof(int),
79202 + .mode = 0600,
79203 + .proc_handler = &proc_dointvec,
79204 + },
79205 +#endif
79206 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79207 + {
79208 + .procname = "chroot_deny_chmod",
79209 + .data = &grsec_enable_chroot_chmod,
79210 + .maxlen = sizeof(int),
79211 + .mode = 0600,
79212 + .proc_handler = &proc_dointvec,
79213 + },
79214 +#endif
79215 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79216 + {
79217 + .procname = "chroot_deny_mknod",
79218 + .data = &grsec_enable_chroot_mknod,
79219 + .maxlen = sizeof(int),
79220 + .mode = 0600,
79221 + .proc_handler = &proc_dointvec,
79222 + },
79223 +#endif
79224 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79225 + {
79226 + .procname = "chroot_restrict_nice",
79227 + .data = &grsec_enable_chroot_nice,
79228 + .maxlen = sizeof(int),
79229 + .mode = 0600,
79230 + .proc_handler = &proc_dointvec,
79231 + },
79232 +#endif
79233 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79234 + {
79235 + .procname = "chroot_execlog",
79236 + .data = &grsec_enable_chroot_execlog,
79237 + .maxlen = sizeof(int),
79238 + .mode = 0600,
79239 + .proc_handler = &proc_dointvec,
79240 + },
79241 +#endif
79242 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79243 + {
79244 + .procname = "chroot_caps",
79245 + .data = &grsec_enable_chroot_caps,
79246 + .maxlen = sizeof(int),
79247 + .mode = 0600,
79248 + .proc_handler = &proc_dointvec,
79249 + },
79250 +#endif
79251 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79252 + {
79253 + .procname = "chroot_deny_sysctl",
79254 + .data = &grsec_enable_chroot_sysctl,
79255 + .maxlen = sizeof(int),
79256 + .mode = 0600,
79257 + .proc_handler = &proc_dointvec,
79258 + },
79259 +#endif
79260 +#ifdef CONFIG_GRKERNSEC_TPE
79261 + {
79262 + .procname = "tpe",
79263 + .data = &grsec_enable_tpe,
79264 + .maxlen = sizeof(int),
79265 + .mode = 0600,
79266 + .proc_handler = &proc_dointvec,
79267 + },
79268 + {
79269 + .procname = "tpe_gid",
79270 + .data = &grsec_tpe_gid,
79271 + .maxlen = sizeof(int),
79272 + .mode = 0600,
79273 + .proc_handler = &proc_dointvec,
79274 + },
79275 +#endif
79276 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79277 + {
79278 + .procname = "tpe_invert",
79279 + .data = &grsec_enable_tpe_invert,
79280 + .maxlen = sizeof(int),
79281 + .mode = 0600,
79282 + .proc_handler = &proc_dointvec,
79283 + },
79284 +#endif
79285 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79286 + {
79287 + .procname = "tpe_restrict_all",
79288 + .data = &grsec_enable_tpe_all,
79289 + .maxlen = sizeof(int),
79290 + .mode = 0600,
79291 + .proc_handler = &proc_dointvec,
79292 + },
79293 +#endif
79294 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79295 + {
79296 + .procname = "socket_all",
79297 + .data = &grsec_enable_socket_all,
79298 + .maxlen = sizeof(int),
79299 + .mode = 0600,
79300 + .proc_handler = &proc_dointvec,
79301 + },
79302 + {
79303 + .procname = "socket_all_gid",
79304 + .data = &grsec_socket_all_gid,
79305 + .maxlen = sizeof(int),
79306 + .mode = 0600,
79307 + .proc_handler = &proc_dointvec,
79308 + },
79309 +#endif
79310 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79311 + {
79312 + .procname = "socket_client",
79313 + .data = &grsec_enable_socket_client,
79314 + .maxlen = sizeof(int),
79315 + .mode = 0600,
79316 + .proc_handler = &proc_dointvec,
79317 + },
79318 + {
79319 + .procname = "socket_client_gid",
79320 + .data = &grsec_socket_client_gid,
79321 + .maxlen = sizeof(int),
79322 + .mode = 0600,
79323 + .proc_handler = &proc_dointvec,
79324 + },
79325 +#endif
79326 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79327 + {
79328 + .procname = "socket_server",
79329 + .data = &grsec_enable_socket_server,
79330 + .maxlen = sizeof(int),
79331 + .mode = 0600,
79332 + .proc_handler = &proc_dointvec,
79333 + },
79334 + {
79335 + .procname = "socket_server_gid",
79336 + .data = &grsec_socket_server_gid,
79337 + .maxlen = sizeof(int),
79338 + .mode = 0600,
79339 + .proc_handler = &proc_dointvec,
79340 + },
79341 +#endif
79342 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79343 + {
79344 + .procname = "audit_group",
79345 + .data = &grsec_enable_group,
79346 + .maxlen = sizeof(int),
79347 + .mode = 0600,
79348 + .proc_handler = &proc_dointvec,
79349 + },
79350 + {
79351 + .procname = "audit_gid",
79352 + .data = &grsec_audit_gid,
79353 + .maxlen = sizeof(int),
79354 + .mode = 0600,
79355 + .proc_handler = &proc_dointvec,
79356 + },
79357 +#endif
79358 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79359 + {
79360 + .procname = "audit_chdir",
79361 + .data = &grsec_enable_chdir,
79362 + .maxlen = sizeof(int),
79363 + .mode = 0600,
79364 + .proc_handler = &proc_dointvec,
79365 + },
79366 +#endif
79367 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79368 + {
79369 + .procname = "audit_mount",
79370 + .data = &grsec_enable_mount,
79371 + .maxlen = sizeof(int),
79372 + .mode = 0600,
79373 + .proc_handler = &proc_dointvec,
79374 + },
79375 +#endif
79376 +#ifdef CONFIG_GRKERNSEC_DMESG
79377 + {
79378 + .procname = "dmesg",
79379 + .data = &grsec_enable_dmesg,
79380 + .maxlen = sizeof(int),
79381 + .mode = 0600,
79382 + .proc_handler = &proc_dointvec,
79383 + },
79384 +#endif
79385 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79386 + {
79387 + .procname = "chroot_findtask",
79388 + .data = &grsec_enable_chroot_findtask,
79389 + .maxlen = sizeof(int),
79390 + .mode = 0600,
79391 + .proc_handler = &proc_dointvec,
79392 + },
79393 +#endif
79394 +#ifdef CONFIG_GRKERNSEC_RESLOG
79395 + {
79396 + .procname = "resource_logging",
79397 + .data = &grsec_resource_logging,
79398 + .maxlen = sizeof(int),
79399 + .mode = 0600,
79400 + .proc_handler = &proc_dointvec,
79401 + },
79402 +#endif
79403 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79404 + {
79405 + .procname = "audit_ptrace",
79406 + .data = &grsec_enable_audit_ptrace,
79407 + .maxlen = sizeof(int),
79408 + .mode = 0600,
79409 + .proc_handler = &proc_dointvec,
79410 + },
79411 +#endif
79412 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79413 + {
79414 + .procname = "harden_ptrace",
79415 + .data = &grsec_enable_harden_ptrace,
79416 + .maxlen = sizeof(int),
79417 + .mode = 0600,
79418 + .proc_handler = &proc_dointvec,
79419 + },
79420 +#endif
79421 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79422 + {
79423 + .procname = "harden_ipc",
79424 + .data = &grsec_enable_harden_ipc,
79425 + .maxlen = sizeof(int),
79426 + .mode = 0600,
79427 + .proc_handler = &proc_dointvec,
79428 + },
79429 +#endif
79430 + {
79431 + .procname = "grsec_lock",
79432 + .data = &grsec_lock,
79433 + .maxlen = sizeof(int),
79434 + .mode = 0600,
79435 + .proc_handler = &proc_dointvec,
79436 + },
79437 +#endif
79438 +#ifdef CONFIG_GRKERNSEC_ROFS
79439 + {
79440 + .procname = "romount_protect",
79441 + .data = &grsec_enable_rofs,
79442 + .maxlen = sizeof(int),
79443 + .mode = 0600,
79444 + .proc_handler = &proc_dointvec_minmax,
79445 + .extra1 = &one,
79446 + .extra2 = &one,
79447 + },
79448 +#endif
79449 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79450 + {
79451 + .procname = "deny_new_usb",
79452 + .data = &grsec_deny_new_usb,
79453 + .maxlen = sizeof(int),
79454 + .mode = 0600,
79455 + .proc_handler = &proc_dointvec,
79456 + },
79457 +#endif
79458 + { }
79459 +};
79460 +#endif
79461 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79462 new file mode 100644
79463 index 0000000..61b514e
79464 --- /dev/null
79465 +++ b/grsecurity/grsec_time.c
79466 @@ -0,0 +1,16 @@
79467 +#include <linux/kernel.h>
79468 +#include <linux/sched.h>
79469 +#include <linux/grinternal.h>
79470 +#include <linux/module.h>
79471 +
79472 +void
79473 +gr_log_timechange(void)
79474 +{
79475 +#ifdef CONFIG_GRKERNSEC_TIME
79476 + if (grsec_enable_time)
79477 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79478 +#endif
79479 + return;
79480 +}
79481 +
79482 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79483 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79484 new file mode 100644
79485 index 0000000..d1953de
79486 --- /dev/null
79487 +++ b/grsecurity/grsec_tpe.c
79488 @@ -0,0 +1,78 @@
79489 +#include <linux/kernel.h>
79490 +#include <linux/sched.h>
79491 +#include <linux/file.h>
79492 +#include <linux/fs.h>
79493 +#include <linux/grinternal.h>
79494 +
79495 +extern int gr_acl_tpe_check(void);
79496 +
79497 +int
79498 +gr_tpe_allow(const struct file *file)
79499 +{
79500 +#ifdef CONFIG_GRKERNSEC
79501 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79502 + struct inode *file_inode = file->f_path.dentry->d_inode;
79503 + const struct cred *cred = current_cred();
79504 + char *msg = NULL;
79505 + char *msg2 = NULL;
79506 +
79507 + // never restrict root
79508 + if (gr_is_global_root(cred->uid))
79509 + return 1;
79510 +
79511 + if (grsec_enable_tpe) {
79512 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79513 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79514 + msg = "not being in trusted group";
79515 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79516 + msg = "being in untrusted group";
79517 +#else
79518 + if (in_group_p(grsec_tpe_gid))
79519 + msg = "being in untrusted group";
79520 +#endif
79521 + }
79522 + if (!msg && gr_acl_tpe_check())
79523 + msg = "being in untrusted role";
79524 +
79525 + // not in any affected group/role
79526 + if (!msg)
79527 + goto next_check;
79528 +
79529 + if (gr_is_global_nonroot(inode->i_uid))
79530 + msg2 = "file in non-root-owned directory";
79531 + else if (inode->i_mode & S_IWOTH)
79532 + msg2 = "file in world-writable directory";
79533 + else if (inode->i_mode & S_IWGRP)
79534 + msg2 = "file in group-writable directory";
79535 + else if (file_inode->i_mode & S_IWOTH)
79536 + msg2 = "file is world-writable";
79537 +
79538 + if (msg && msg2) {
79539 + char fullmsg[70] = {0};
79540 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79541 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79542 + return 0;
79543 + }
79544 + msg = NULL;
79545 +next_check:
79546 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79547 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79548 + return 1;
79549 +
79550 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79551 + msg = "directory not owned by user";
79552 + else if (inode->i_mode & S_IWOTH)
79553 + msg = "file in world-writable directory";
79554 + else if (inode->i_mode & S_IWGRP)
79555 + msg = "file in group-writable directory";
79556 + else if (file_inode->i_mode & S_IWOTH)
79557 + msg = "file is world-writable";
79558 +
79559 + if (msg) {
79560 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79561 + return 0;
79562 + }
79563 +#endif
79564 +#endif
79565 + return 1;
79566 +}
79567 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79568 new file mode 100644
79569 index 0000000..ae02d8e
79570 --- /dev/null
79571 +++ b/grsecurity/grsec_usb.c
79572 @@ -0,0 +1,15 @@
79573 +#include <linux/kernel.h>
79574 +#include <linux/grinternal.h>
79575 +#include <linux/module.h>
79576 +
79577 +int gr_handle_new_usb(void)
79578 +{
79579 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79580 + if (grsec_deny_new_usb) {
79581 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79582 + return 1;
79583 + }
79584 +#endif
79585 + return 0;
79586 +}
79587 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79588 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79589 new file mode 100644
79590 index 0000000..158b330
79591 --- /dev/null
79592 +++ b/grsecurity/grsum.c
79593 @@ -0,0 +1,64 @@
79594 +#include <linux/err.h>
79595 +#include <linux/kernel.h>
79596 +#include <linux/sched.h>
79597 +#include <linux/mm.h>
79598 +#include <linux/scatterlist.h>
79599 +#include <linux/crypto.h>
79600 +#include <linux/gracl.h>
79601 +
79602 +
79603 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79604 +#error "crypto and sha256 must be built into the kernel"
79605 +#endif
79606 +
79607 +int
79608 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79609 +{
79610 + struct crypto_hash *tfm;
79611 + struct hash_desc desc;
79612 + struct scatterlist sg[2];
79613 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79614 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79615 + unsigned long *sumptr = (unsigned long *)sum;
79616 + int cryptres;
79617 + int retval = 1;
79618 + volatile int mismatched = 0;
79619 + volatile int dummy = 0;
79620 + unsigned int i;
79621 +
79622 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79623 + if (IS_ERR(tfm)) {
79624 + /* should never happen, since sha256 should be built in */
79625 + memset(entry->pw, 0, GR_PW_LEN);
79626 + return 1;
79627 + }
79628 +
79629 + sg_init_table(sg, 2);
79630 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79631 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79632 +
79633 + desc.tfm = tfm;
79634 + desc.flags = 0;
79635 +
79636 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79637 + temp_sum);
79638 +
79639 + memset(entry->pw, 0, GR_PW_LEN);
79640 +
79641 + if (cryptres)
79642 + goto out;
79643 +
79644 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79645 + if (sumptr[i] != tmpsumptr[i])
79646 + mismatched = 1;
79647 + else
79648 + dummy = 1; // waste a cycle
79649 +
79650 + if (!mismatched)
79651 + retval = dummy - 1;
79652 +
79653 +out:
79654 + crypto_free_hash(tfm);
79655 +
79656 + return retval;
79657 +}
79658 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79659 index 77ff547..181834f 100644
79660 --- a/include/asm-generic/4level-fixup.h
79661 +++ b/include/asm-generic/4level-fixup.h
79662 @@ -13,8 +13,10 @@
79663 #define pmd_alloc(mm, pud, address) \
79664 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79665 NULL: pmd_offset(pud, address))
79666 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79667
79668 #define pud_alloc(mm, pgd, address) (pgd)
79669 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79670 #define pud_offset(pgd, start) (pgd)
79671 #define pud_none(pud) 0
79672 #define pud_bad(pud) 0
79673 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79674 index b7babf0..1e4b4f1 100644
79675 --- a/include/asm-generic/atomic-long.h
79676 +++ b/include/asm-generic/atomic-long.h
79677 @@ -22,6 +22,12 @@
79678
79679 typedef atomic64_t atomic_long_t;
79680
79681 +#ifdef CONFIG_PAX_REFCOUNT
79682 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79683 +#else
79684 +typedef atomic64_t atomic_long_unchecked_t;
79685 +#endif
79686 +
79687 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79688
79689 static inline long atomic_long_read(atomic_long_t *l)
79690 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79691 return (long)atomic64_read(v);
79692 }
79693
79694 +#ifdef CONFIG_PAX_REFCOUNT
79695 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79696 +{
79697 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79698 +
79699 + return (long)atomic64_read_unchecked(v);
79700 +}
79701 +#endif
79702 +
79703 static inline void atomic_long_set(atomic_long_t *l, long i)
79704 {
79705 atomic64_t *v = (atomic64_t *)l;
79706 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79707 atomic64_set(v, i);
79708 }
79709
79710 +#ifdef CONFIG_PAX_REFCOUNT
79711 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79712 +{
79713 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79714 +
79715 + atomic64_set_unchecked(v, i);
79716 +}
79717 +#endif
79718 +
79719 static inline void atomic_long_inc(atomic_long_t *l)
79720 {
79721 atomic64_t *v = (atomic64_t *)l;
79722 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79723 atomic64_inc(v);
79724 }
79725
79726 +#ifdef CONFIG_PAX_REFCOUNT
79727 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79728 +{
79729 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79730 +
79731 + atomic64_inc_unchecked(v);
79732 +}
79733 +#endif
79734 +
79735 static inline void atomic_long_dec(atomic_long_t *l)
79736 {
79737 atomic64_t *v = (atomic64_t *)l;
79738 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79739 atomic64_dec(v);
79740 }
79741
79742 +#ifdef CONFIG_PAX_REFCOUNT
79743 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79744 +{
79745 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79746 +
79747 + atomic64_dec_unchecked(v);
79748 +}
79749 +#endif
79750 +
79751 static inline void atomic_long_add(long i, atomic_long_t *l)
79752 {
79753 atomic64_t *v = (atomic64_t *)l;
79754 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79755 atomic64_add(i, v);
79756 }
79757
79758 +#ifdef CONFIG_PAX_REFCOUNT
79759 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79760 +{
79761 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79762 +
79763 + atomic64_add_unchecked(i, v);
79764 +}
79765 +#endif
79766 +
79767 static inline void atomic_long_sub(long i, atomic_long_t *l)
79768 {
79769 atomic64_t *v = (atomic64_t *)l;
79770 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79771 atomic64_sub(i, v);
79772 }
79773
79774 +#ifdef CONFIG_PAX_REFCOUNT
79775 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79776 +{
79777 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79778 +
79779 + atomic64_sub_unchecked(i, v);
79780 +}
79781 +#endif
79782 +
79783 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79784 {
79785 atomic64_t *v = (atomic64_t *)l;
79786 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79787 return atomic64_add_negative(i, v);
79788 }
79789
79790 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79791 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79792 {
79793 atomic64_t *v = (atomic64_t *)l;
79794
79795 return (long)atomic64_add_return(i, v);
79796 }
79797
79798 +#ifdef CONFIG_PAX_REFCOUNT
79799 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79800 +{
79801 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79802 +
79803 + return (long)atomic64_add_return_unchecked(i, v);
79804 +}
79805 +#endif
79806 +
79807 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79808 {
79809 atomic64_t *v = (atomic64_t *)l;
79810 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79811 return (long)atomic64_inc_return(v);
79812 }
79813
79814 +#ifdef CONFIG_PAX_REFCOUNT
79815 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79816 +{
79817 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79818 +
79819 + return (long)atomic64_inc_return_unchecked(v);
79820 +}
79821 +#endif
79822 +
79823 static inline long atomic_long_dec_return(atomic_long_t *l)
79824 {
79825 atomic64_t *v = (atomic64_t *)l;
79826 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79827
79828 typedef atomic_t atomic_long_t;
79829
79830 +#ifdef CONFIG_PAX_REFCOUNT
79831 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79832 +#else
79833 +typedef atomic_t atomic_long_unchecked_t;
79834 +#endif
79835 +
79836 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79837 static inline long atomic_long_read(atomic_long_t *l)
79838 {
79839 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79840 return (long)atomic_read(v);
79841 }
79842
79843 +#ifdef CONFIG_PAX_REFCOUNT
79844 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79845 +{
79846 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79847 +
79848 + return (long)atomic_read_unchecked(v);
79849 +}
79850 +#endif
79851 +
79852 static inline void atomic_long_set(atomic_long_t *l, long i)
79853 {
79854 atomic_t *v = (atomic_t *)l;
79855 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79856 atomic_set(v, i);
79857 }
79858
79859 +#ifdef CONFIG_PAX_REFCOUNT
79860 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79861 +{
79862 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79863 +
79864 + atomic_set_unchecked(v, i);
79865 +}
79866 +#endif
79867 +
79868 static inline void atomic_long_inc(atomic_long_t *l)
79869 {
79870 atomic_t *v = (atomic_t *)l;
79871 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79872 atomic_inc(v);
79873 }
79874
79875 +#ifdef CONFIG_PAX_REFCOUNT
79876 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79877 +{
79878 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79879 +
79880 + atomic_inc_unchecked(v);
79881 +}
79882 +#endif
79883 +
79884 static inline void atomic_long_dec(atomic_long_t *l)
79885 {
79886 atomic_t *v = (atomic_t *)l;
79887 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79888 atomic_dec(v);
79889 }
79890
79891 +#ifdef CONFIG_PAX_REFCOUNT
79892 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79893 +{
79894 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79895 +
79896 + atomic_dec_unchecked(v);
79897 +}
79898 +#endif
79899 +
79900 static inline void atomic_long_add(long i, atomic_long_t *l)
79901 {
79902 atomic_t *v = (atomic_t *)l;
79903 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79904 atomic_add(i, v);
79905 }
79906
79907 +#ifdef CONFIG_PAX_REFCOUNT
79908 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79909 +{
79910 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79911 +
79912 + atomic_add_unchecked(i, v);
79913 +}
79914 +#endif
79915 +
79916 static inline void atomic_long_sub(long i, atomic_long_t *l)
79917 {
79918 atomic_t *v = (atomic_t *)l;
79919 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79920 atomic_sub(i, v);
79921 }
79922
79923 +#ifdef CONFIG_PAX_REFCOUNT
79924 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79925 +{
79926 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79927 +
79928 + atomic_sub_unchecked(i, v);
79929 +}
79930 +#endif
79931 +
79932 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79933 {
79934 atomic_t *v = (atomic_t *)l;
79935 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79936 return atomic_add_negative(i, v);
79937 }
79938
79939 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79940 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79941 {
79942 atomic_t *v = (atomic_t *)l;
79943
79944 return (long)atomic_add_return(i, v);
79945 }
79946
79947 +#ifdef CONFIG_PAX_REFCOUNT
79948 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79949 +{
79950 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79951 +
79952 + return (long)atomic_add_return_unchecked(i, v);
79953 +}
79954 +
79955 +#endif
79956 +
79957 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79958 {
79959 atomic_t *v = (atomic_t *)l;
79960 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79961 return (long)atomic_inc_return(v);
79962 }
79963
79964 +#ifdef CONFIG_PAX_REFCOUNT
79965 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79966 +{
79967 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79968 +
79969 + return (long)atomic_inc_return_unchecked(v);
79970 +}
79971 +#endif
79972 +
79973 static inline long atomic_long_dec_return(atomic_long_t *l)
79974 {
79975 atomic_t *v = (atomic_t *)l;
79976 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79977
79978 #endif /* BITS_PER_LONG == 64 */
79979
79980 +#ifdef CONFIG_PAX_REFCOUNT
79981 +static inline void pax_refcount_needs_these_functions(void)
79982 +{
79983 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79984 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79985 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79986 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79987 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79988 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79989 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79990 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79991 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79992 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79993 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79994 +#ifdef CONFIG_X86
79995 + atomic_clear_mask_unchecked(0, NULL);
79996 + atomic_set_mask_unchecked(0, NULL);
79997 +#endif
79998 +
79999 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
80000 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
80001 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
80002 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
80003 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
80004 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
80005 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
80006 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
80007 +}
80008 +#else
80009 +#define atomic_read_unchecked(v) atomic_read(v)
80010 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
80011 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
80012 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
80013 +#define atomic_inc_unchecked(v) atomic_inc(v)
80014 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
80015 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
80016 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
80017 +#define atomic_dec_unchecked(v) atomic_dec(v)
80018 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
80019 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
80020 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
80021 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
80022 +
80023 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
80024 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
80025 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
80026 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
80027 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
80028 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
80029 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
80030 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
80031 +#endif
80032 +
80033 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
80034 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
80035 index 9c79e76..9f7827d 100644
80036 --- a/include/asm-generic/atomic.h
80037 +++ b/include/asm-generic/atomic.h
80038 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
80039 * Atomically clears the bits set in @mask from @v
80040 */
80041 #ifndef atomic_clear_mask
80042 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
80043 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80044 {
80045 unsigned long flags;
80046
80047 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
80048 index b18ce4f..2ee2843 100644
80049 --- a/include/asm-generic/atomic64.h
80050 +++ b/include/asm-generic/atomic64.h
80051 @@ -16,6 +16,8 @@ typedef struct {
80052 long long counter;
80053 } atomic64_t;
80054
80055 +typedef atomic64_t atomic64_unchecked_t;
80056 +
80057 #define ATOMIC64_INIT(i) { (i) }
80058
80059 extern long long atomic64_read(const atomic64_t *v);
80060 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
80061 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
80062 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
80063
80064 +#define atomic64_read_unchecked(v) atomic64_read(v)
80065 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
80066 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
80067 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
80068 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
80069 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
80070 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
80071 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
80072 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
80073 +
80074 #endif /* _ASM_GENERIC_ATOMIC64_H */
80075 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
80076 index 1402fa8..025a736 100644
80077 --- a/include/asm-generic/barrier.h
80078 +++ b/include/asm-generic/barrier.h
80079 @@ -74,7 +74,7 @@
80080 do { \
80081 compiletime_assert_atomic_type(*p); \
80082 smp_mb(); \
80083 - ACCESS_ONCE(*p) = (v); \
80084 + ACCESS_ONCE_RW(*p) = (v); \
80085 } while (0)
80086
80087 #define smp_load_acquire(p) \
80088 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
80089 index a60a7cc..0fe12f2 100644
80090 --- a/include/asm-generic/bitops/__fls.h
80091 +++ b/include/asm-generic/bitops/__fls.h
80092 @@ -9,7 +9,7 @@
80093 *
80094 * Undefined if no set bit exists, so code should check against 0 first.
80095 */
80096 -static __always_inline unsigned long __fls(unsigned long word)
80097 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
80098 {
80099 int num = BITS_PER_LONG - 1;
80100
80101 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
80102 index 0576d1f..dad6c71 100644
80103 --- a/include/asm-generic/bitops/fls.h
80104 +++ b/include/asm-generic/bitops/fls.h
80105 @@ -9,7 +9,7 @@
80106 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
80107 */
80108
80109 -static __always_inline int fls(int x)
80110 +static __always_inline int __intentional_overflow(-1) fls(int x)
80111 {
80112 int r = 32;
80113
80114 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
80115 index b097cf8..3d40e14 100644
80116 --- a/include/asm-generic/bitops/fls64.h
80117 +++ b/include/asm-generic/bitops/fls64.h
80118 @@ -15,7 +15,7 @@
80119 * at position 64.
80120 */
80121 #if BITS_PER_LONG == 32
80122 -static __always_inline int fls64(__u64 x)
80123 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80124 {
80125 __u32 h = x >> 32;
80126 if (h)
80127 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80128 return fls(x);
80129 }
80130 #elif BITS_PER_LONG == 64
80131 -static __always_inline int fls64(__u64 x)
80132 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80133 {
80134 if (x == 0)
80135 return 0;
80136 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80137 index 1bfcfe5..e04c5c9 100644
80138 --- a/include/asm-generic/cache.h
80139 +++ b/include/asm-generic/cache.h
80140 @@ -6,7 +6,7 @@
80141 * cache lines need to provide their own cache.h.
80142 */
80143
80144 -#define L1_CACHE_SHIFT 5
80145 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80146 +#define L1_CACHE_SHIFT 5UL
80147 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80148
80149 #endif /* __ASM_GENERIC_CACHE_H */
80150 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80151 index 0d68a1e..b74a761 100644
80152 --- a/include/asm-generic/emergency-restart.h
80153 +++ b/include/asm-generic/emergency-restart.h
80154 @@ -1,7 +1,7 @@
80155 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80156 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80157
80158 -static inline void machine_emergency_restart(void)
80159 +static inline __noreturn void machine_emergency_restart(void)
80160 {
80161 machine_restart(NULL);
80162 }
80163 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80164 index 975e1cc..0b8a083 100644
80165 --- a/include/asm-generic/io.h
80166 +++ b/include/asm-generic/io.h
80167 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80168 * These are pretty trivial
80169 */
80170 #ifndef virt_to_phys
80171 -static inline unsigned long virt_to_phys(volatile void *address)
80172 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80173 {
80174 return __pa((unsigned long)address);
80175 }
80176 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80177 index 90f99c7..00ce236 100644
80178 --- a/include/asm-generic/kmap_types.h
80179 +++ b/include/asm-generic/kmap_types.h
80180 @@ -2,9 +2,9 @@
80181 #define _ASM_GENERIC_KMAP_TYPES_H
80182
80183 #ifdef __WITH_KM_FENCE
80184 -# define KM_TYPE_NR 41
80185 +# define KM_TYPE_NR 42
80186 #else
80187 -# define KM_TYPE_NR 20
80188 +# define KM_TYPE_NR 21
80189 #endif
80190
80191 #endif
80192 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80193 index 9ceb03b..62b0b8f 100644
80194 --- a/include/asm-generic/local.h
80195 +++ b/include/asm-generic/local.h
80196 @@ -23,24 +23,37 @@ typedef struct
80197 atomic_long_t a;
80198 } local_t;
80199
80200 +typedef struct {
80201 + atomic_long_unchecked_t a;
80202 +} local_unchecked_t;
80203 +
80204 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80205
80206 #define local_read(l) atomic_long_read(&(l)->a)
80207 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80208 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80209 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80210 #define local_inc(l) atomic_long_inc(&(l)->a)
80211 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80212 #define local_dec(l) atomic_long_dec(&(l)->a)
80213 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80214 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80215 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80216 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80217 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80218
80219 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80220 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80221 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80222 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80223 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80224 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80225 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80226 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80227 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80228
80229 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80230 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80231 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80232 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80233 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80234 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80235 index 725612b..9cc513a 100644
80236 --- a/include/asm-generic/pgtable-nopmd.h
80237 +++ b/include/asm-generic/pgtable-nopmd.h
80238 @@ -1,14 +1,19 @@
80239 #ifndef _PGTABLE_NOPMD_H
80240 #define _PGTABLE_NOPMD_H
80241
80242 -#ifndef __ASSEMBLY__
80243 -
80244 #include <asm-generic/pgtable-nopud.h>
80245
80246 -struct mm_struct;
80247 -
80248 #define __PAGETABLE_PMD_FOLDED
80249
80250 +#define PMD_SHIFT PUD_SHIFT
80251 +#define PTRS_PER_PMD 1
80252 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80253 +#define PMD_MASK (~(PMD_SIZE-1))
80254 +
80255 +#ifndef __ASSEMBLY__
80256 +
80257 +struct mm_struct;
80258 +
80259 /*
80260 * Having the pmd type consist of a pud gets the size right, and allows
80261 * us to conceptually access the pud entry that this pmd is folded into
80262 @@ -16,11 +21,6 @@ struct mm_struct;
80263 */
80264 typedef struct { pud_t pud; } pmd_t;
80265
80266 -#define PMD_SHIFT PUD_SHIFT
80267 -#define PTRS_PER_PMD 1
80268 -#define PMD_SIZE (1UL << PMD_SHIFT)
80269 -#define PMD_MASK (~(PMD_SIZE-1))
80270 -
80271 /*
80272 * The "pud_xxx()" functions here are trivial for a folded two-level
80273 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80274 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80275 index 810431d..0ec4804f 100644
80276 --- a/include/asm-generic/pgtable-nopud.h
80277 +++ b/include/asm-generic/pgtable-nopud.h
80278 @@ -1,10 +1,15 @@
80279 #ifndef _PGTABLE_NOPUD_H
80280 #define _PGTABLE_NOPUD_H
80281
80282 -#ifndef __ASSEMBLY__
80283 -
80284 #define __PAGETABLE_PUD_FOLDED
80285
80286 +#define PUD_SHIFT PGDIR_SHIFT
80287 +#define PTRS_PER_PUD 1
80288 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80289 +#define PUD_MASK (~(PUD_SIZE-1))
80290 +
80291 +#ifndef __ASSEMBLY__
80292 +
80293 /*
80294 * Having the pud type consist of a pgd gets the size right, and allows
80295 * us to conceptually access the pgd entry that this pud is folded into
80296 @@ -12,11 +17,6 @@
80297 */
80298 typedef struct { pgd_t pgd; } pud_t;
80299
80300 -#define PUD_SHIFT PGDIR_SHIFT
80301 -#define PTRS_PER_PUD 1
80302 -#define PUD_SIZE (1UL << PUD_SHIFT)
80303 -#define PUD_MASK (~(PUD_SIZE-1))
80304 -
80305 /*
80306 * The "pgd_xxx()" functions here are trivial for a folded two-level
80307 * setup: the pud is never bad, and a pud always exists (as it's folded
80308 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80309 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80310
80311 #define pgd_populate(mm, pgd, pud) do { } while (0)
80312 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80313 /*
80314 * (puds are folded into pgds so this doesn't get actually called,
80315 * but the define is needed for a generic inline function.)
80316 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80317 index 53b2acc..f4568e7 100644
80318 --- a/include/asm-generic/pgtable.h
80319 +++ b/include/asm-generic/pgtable.h
80320 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80321 }
80322 #endif /* CONFIG_NUMA_BALANCING */
80323
80324 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80325 +#ifdef CONFIG_PAX_KERNEXEC
80326 +#error KERNEXEC requires pax_open_kernel
80327 +#else
80328 +static inline unsigned long pax_open_kernel(void) { return 0; }
80329 +#endif
80330 +#endif
80331 +
80332 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80333 +#ifdef CONFIG_PAX_KERNEXEC
80334 +#error KERNEXEC requires pax_close_kernel
80335 +#else
80336 +static inline unsigned long pax_close_kernel(void) { return 0; }
80337 +#endif
80338 +#endif
80339 +
80340 #endif /* CONFIG_MMU */
80341
80342 #endif /* !__ASSEMBLY__ */
80343 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80344 index 72d8803..cb9749c 100644
80345 --- a/include/asm-generic/uaccess.h
80346 +++ b/include/asm-generic/uaccess.h
80347 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80348 return __clear_user(to, n);
80349 }
80350
80351 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80352 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80353 +#error UDEREF requires pax_open_userland
80354 +#else
80355 +static inline unsigned long pax_open_userland(void) { return 0; }
80356 +#endif
80357 +#endif
80358 +
80359 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80361 +#error UDEREF requires pax_close_userland
80362 +#else
80363 +static inline unsigned long pax_close_userland(void) { return 0; }
80364 +#endif
80365 +#endif
80366 +
80367 #endif /* __ASM_GENERIC_UACCESS_H */
80368 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80369 index 5ba0360..e85c934 100644
80370 --- a/include/asm-generic/vmlinux.lds.h
80371 +++ b/include/asm-generic/vmlinux.lds.h
80372 @@ -231,6 +231,7 @@
80373 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80374 VMLINUX_SYMBOL(__start_rodata) = .; \
80375 *(.rodata) *(.rodata.*) \
80376 + *(.data..read_only) \
80377 *(__vermagic) /* Kernel version magic */ \
80378 . = ALIGN(8); \
80379 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80380 @@ -722,17 +723,18 @@
80381 * section in the linker script will go there too. @phdr should have
80382 * a leading colon.
80383 *
80384 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80385 + * Note that this macros defines per_cpu_load as an absolute symbol.
80386 * If there is no need to put the percpu section at a predetermined
80387 * address, use PERCPU_SECTION.
80388 */
80389 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80390 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80391 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80392 + per_cpu_load = .; \
80393 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80394 - LOAD_OFFSET) { \
80395 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80396 PERCPU_INPUT(cacheline) \
80397 } phdr \
80398 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80399 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80400
80401 /**
80402 * PERCPU_SECTION - define output section for percpu area, simple version
80403 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80404 index 623a59c..1e79ab9 100644
80405 --- a/include/crypto/algapi.h
80406 +++ b/include/crypto/algapi.h
80407 @@ -34,7 +34,7 @@ struct crypto_type {
80408 unsigned int maskclear;
80409 unsigned int maskset;
80410 unsigned int tfmsize;
80411 -};
80412 +} __do_const;
80413
80414 struct crypto_instance {
80415 struct crypto_alg alg;
80416 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80417 index 1968907..7d9ed9f 100644
80418 --- a/include/drm/drmP.h
80419 +++ b/include/drm/drmP.h
80420 @@ -68,6 +68,7 @@
80421 #include <linux/workqueue.h>
80422 #include <linux/poll.h>
80423 #include <asm/pgalloc.h>
80424 +#include <asm/local.h>
80425 #include <drm/drm.h>
80426 #include <drm/drm_sarea.h>
80427 #include <drm/drm_vma_manager.h>
80428 @@ -260,10 +261,12 @@ do { \
80429 * \param cmd command.
80430 * \param arg argument.
80431 */
80432 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80433 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80434 + struct drm_file *file_priv);
80435 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80436 struct drm_file *file_priv);
80437
80438 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80439 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80440 unsigned long arg);
80441
80442 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80443 @@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80444 struct drm_ioctl_desc {
80445 unsigned int cmd;
80446 int flags;
80447 - drm_ioctl_t *func;
80448 + drm_ioctl_t func;
80449 unsigned int cmd_drv;
80450 const char *name;
80451 -};
80452 +} __do_const;
80453
80454 /**
80455 * Creates a driver or general drm_ioctl_desc array entry for the given
80456 @@ -946,7 +949,8 @@ struct drm_info_list {
80457 int (*show)(struct seq_file*, void*); /** show callback */
80458 u32 driver_features; /**< Required driver features for this entry */
80459 void *data;
80460 -};
80461 +} __do_const;
80462 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80463
80464 /**
80465 * debugfs node structure. This structure represents a debugfs file.
80466 @@ -1030,7 +1034,7 @@ struct drm_device {
80467
80468 /** \name Usage Counters */
80469 /*@{ */
80470 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80471 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80472 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80473 int buf_use; /**< Buffers in use -- cannot alloc */
80474 atomic_t buf_alloc; /**< Buffer allocation in progress */
80475 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80476 index a3d75fe..6802f9c 100644
80477 --- a/include/drm/drm_crtc_helper.h
80478 +++ b/include/drm/drm_crtc_helper.h
80479 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80480 struct drm_connector *connector);
80481 /* disable encoder when not in use - more explicit than dpms off */
80482 void (*disable)(struct drm_encoder *encoder);
80483 -};
80484 +} __no_const;
80485
80486 /**
80487 * drm_connector_helper_funcs - helper operations for connectors
80488 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80489 index a70d456..6ea07cd 100644
80490 --- a/include/drm/i915_pciids.h
80491 +++ b/include/drm/i915_pciids.h
80492 @@ -37,7 +37,7 @@
80493 */
80494 #define INTEL_VGA_DEVICE(id, info) { \
80495 0x8086, id, \
80496 - ~0, ~0, \
80497 + PCI_ANY_ID, PCI_ANY_ID, \
80498 0x030000, 0xff0000, \
80499 (unsigned long) info }
80500
80501 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80502 index 72dcbe8..8db58d7 100644
80503 --- a/include/drm/ttm/ttm_memory.h
80504 +++ b/include/drm/ttm/ttm_memory.h
80505 @@ -48,7 +48,7 @@
80506
80507 struct ttm_mem_shrink {
80508 int (*do_shrink) (struct ttm_mem_shrink *);
80509 -};
80510 +} __no_const;
80511
80512 /**
80513 * struct ttm_mem_global - Global memory accounting structure.
80514 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80515 index 49a8284..9643967 100644
80516 --- a/include/drm/ttm/ttm_page_alloc.h
80517 +++ b/include/drm/ttm/ttm_page_alloc.h
80518 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80519 */
80520 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80521
80522 +struct device;
80523 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80524 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80525
80526 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80527 index 4b840e8..155d235 100644
80528 --- a/include/keys/asymmetric-subtype.h
80529 +++ b/include/keys/asymmetric-subtype.h
80530 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80531 /* Verify the signature on a key of this subtype (optional) */
80532 int (*verify_signature)(const struct key *key,
80533 const struct public_key_signature *sig);
80534 -};
80535 +} __do_const;
80536
80537 /**
80538 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80539 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80540 index c1da539..1dcec55 100644
80541 --- a/include/linux/atmdev.h
80542 +++ b/include/linux/atmdev.h
80543 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80544 #endif
80545
80546 struct k_atm_aal_stats {
80547 -#define __HANDLE_ITEM(i) atomic_t i
80548 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80549 __AAL_STAT_ITEMS
80550 #undef __HANDLE_ITEM
80551 };
80552 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80553 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80554 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80555 struct module *owner;
80556 -};
80557 +} __do_const ;
80558
80559 struct atmphy_ops {
80560 int (*start)(struct atm_dev *dev);
80561 diff --git a/include/linux/audit.h b/include/linux/audit.h
80562 index 22cfddb..1514eef 100644
80563 --- a/include/linux/audit.h
80564 +++ b/include/linux/audit.h
80565 @@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
80566 extern unsigned compat_chattr_class[];
80567 extern unsigned compat_signal_class[];
80568
80569 -extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
80570 +extern int audit_classify_compat_syscall(int abi, unsigned syscall);
80571
80572 /* audit_names->type values */
80573 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
80574 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80575 extern unsigned int audit_serial(void);
80576 extern int auditsc_get_stamp(struct audit_context *ctx,
80577 struct timespec *t, unsigned int *serial);
80578 -extern int audit_set_loginuid(kuid_t loginuid);
80579 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80580
80581 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80582 {
80583 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80584 index 61f29e5..e67c658 100644
80585 --- a/include/linux/binfmts.h
80586 +++ b/include/linux/binfmts.h
80587 @@ -44,7 +44,7 @@ struct linux_binprm {
80588 unsigned interp_flags;
80589 unsigned interp_data;
80590 unsigned long loader, exec;
80591 -};
80592 +} __randomize_layout;
80593
80594 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80595 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80596 @@ -73,8 +73,10 @@ struct linux_binfmt {
80597 int (*load_binary)(struct linux_binprm *);
80598 int (*load_shlib)(struct file *);
80599 int (*core_dump)(struct coredump_params *cprm);
80600 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80601 + void (*handle_mmap)(struct file *);
80602 unsigned long min_coredump; /* minimal dump size */
80603 -};
80604 +} __do_const __randomize_layout;
80605
80606 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80607
80608 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80609 index 38b5f5c..645018c 100644
80610 --- a/include/linux/bitops.h
80611 +++ b/include/linux/bitops.h
80612 @@ -125,7 +125,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80613 * @word: value to rotate
80614 * @shift: bits to roll
80615 */
80616 -static inline __u32 rol32(__u32 word, unsigned int shift)
80617 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80618 {
80619 return (word << shift) | (word >> (32 - shift));
80620 }
80621 @@ -135,7 +135,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80622 * @word: value to rotate
80623 * @shift: bits to roll
80624 */
80625 -static inline __u32 ror32(__u32 word, unsigned int shift)
80626 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80627 {
80628 return (word >> shift) | (word << (32 - shift));
80629 }
80630 @@ -191,7 +191,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80631 return (__s32)(value << shift) >> shift;
80632 }
80633
80634 -static inline unsigned fls_long(unsigned long l)
80635 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80636 {
80637 if (sizeof(l) == 4)
80638 return fls(l);
80639 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80640 index f2057ff8..59dfa2d 100644
80641 --- a/include/linux/blkdev.h
80642 +++ b/include/linux/blkdev.h
80643 @@ -1625,7 +1625,7 @@ struct block_device_operations {
80644 /* this callback is with swap_lock and sometimes page table lock held */
80645 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80646 struct module *owner;
80647 -};
80648 +} __do_const;
80649
80650 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80651 unsigned long);
80652 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80653 index afc1343..9735539 100644
80654 --- a/include/linux/blktrace_api.h
80655 +++ b/include/linux/blktrace_api.h
80656 @@ -25,7 +25,7 @@ struct blk_trace {
80657 struct dentry *dropped_file;
80658 struct dentry *msg_file;
80659 struct list_head running_list;
80660 - atomic_t dropped;
80661 + atomic_unchecked_t dropped;
80662 };
80663
80664 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80665 diff --git a/include/linux/cache.h b/include/linux/cache.h
80666 index 17e7e82..1d7da26 100644
80667 --- a/include/linux/cache.h
80668 +++ b/include/linux/cache.h
80669 @@ -16,6 +16,14 @@
80670 #define __read_mostly
80671 #endif
80672
80673 +#ifndef __read_only
80674 +#ifdef CONFIG_PAX_KERNEXEC
80675 +#error KERNEXEC requires __read_only
80676 +#else
80677 +#define __read_only __read_mostly
80678 +#endif
80679 +#endif
80680 +
80681 #ifndef ____cacheline_aligned
80682 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80683 #endif
80684 diff --git a/include/linux/capability.h b/include/linux/capability.h
80685 index aa93e5e..985a1b0 100644
80686 --- a/include/linux/capability.h
80687 +++ b/include/linux/capability.h
80688 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80689 extern bool capable(int cap);
80690 extern bool ns_capable(struct user_namespace *ns, int cap);
80691 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80692 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80693 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80694 +extern bool capable_nolog(int cap);
80695 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80696
80697 /* audit system wants to get cap info from files as well */
80698 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80699
80700 +extern int is_privileged_binary(const struct dentry *dentry);
80701 +
80702 #endif /* !_LINUX_CAPABILITY_H */
80703 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80704 index 8609d57..86e4d79 100644
80705 --- a/include/linux/cdrom.h
80706 +++ b/include/linux/cdrom.h
80707 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80708
80709 /* driver specifications */
80710 const int capability; /* capability flags */
80711 - int n_minors; /* number of active minor devices */
80712 /* handle uniform packets for scsi type devices (scsi,atapi) */
80713 int (*generic_packet) (struct cdrom_device_info *,
80714 struct packet_command *);
80715 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80716 index 4ce9056..86caac6 100644
80717 --- a/include/linux/cleancache.h
80718 +++ b/include/linux/cleancache.h
80719 @@ -31,7 +31,7 @@ struct cleancache_ops {
80720 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80721 void (*invalidate_inode)(int, struct cleancache_filekey);
80722 void (*invalidate_fs)(int);
80723 -};
80724 +} __no_const;
80725
80726 extern struct cleancache_ops *
80727 cleancache_register_ops(struct cleancache_ops *ops);
80728 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80729 index da6996e..9d13d5f 100644
80730 --- a/include/linux/clk-provider.h
80731 +++ b/include/linux/clk-provider.h
80732 @@ -180,6 +180,7 @@ struct clk_ops {
80733 void (*init)(struct clk_hw *hw);
80734 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80735 };
80736 +typedef struct clk_ops __no_const clk_ops_no_const;
80737
80738 /**
80739 * struct clk_init_data - holds init data that's common to all clocks and is
80740 diff --git a/include/linux/compat.h b/include/linux/compat.h
80741 index e649426..a74047b 100644
80742 --- a/include/linux/compat.h
80743 +++ b/include/linux/compat.h
80744 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80745 compat_size_t __user *len_ptr);
80746
80747 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80748 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80749 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80750 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80751 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80752 compat_ssize_t msgsz, int msgflg);
80753 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80754 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80755 compat_ulong_t addr, compat_ulong_t data);
80756 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80757 - compat_long_t addr, compat_long_t data);
80758 + compat_ulong_t addr, compat_ulong_t data);
80759
80760 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80761 /*
80762 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80763 index 2507fd2..55203f8 100644
80764 --- a/include/linux/compiler-gcc4.h
80765 +++ b/include/linux/compiler-gcc4.h
80766 @@ -39,9 +39,34 @@
80767 # define __compiletime_warning(message) __attribute__((warning(message)))
80768 # define __compiletime_error(message) __attribute__((error(message)))
80769 #endif /* __CHECKER__ */
80770 +
80771 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80772 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80773 +#define __bos0(ptr) __bos((ptr), 0)
80774 +#define __bos1(ptr) __bos((ptr), 1)
80775 #endif /* GCC_VERSION >= 40300 */
80776
80777 #if GCC_VERSION >= 40500
80778 +
80779 +#ifdef RANDSTRUCT_PLUGIN
80780 +#define __randomize_layout __attribute__((randomize_layout))
80781 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80782 +#endif
80783 +
80784 +#ifdef CONSTIFY_PLUGIN
80785 +#define __no_const __attribute__((no_const))
80786 +#define __do_const __attribute__((do_const))
80787 +#endif
80788 +
80789 +#ifdef SIZE_OVERFLOW_PLUGIN
80790 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80791 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80792 +#endif
80793 +
80794 +#ifdef LATENT_ENTROPY_PLUGIN
80795 +#define __latent_entropy __attribute__((latent_entropy))
80796 +#endif
80797 +
80798 /*
80799 * Mark a position in code as unreachable. This can be used to
80800 * suppress control flow warnings after asm blocks that transfer
80801 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80802 index d5ad7b1..3b74638 100644
80803 --- a/include/linux/compiler.h
80804 +++ b/include/linux/compiler.h
80805 @@ -5,11 +5,14 @@
80806
80807 #ifdef __CHECKER__
80808 # define __user __attribute__((noderef, address_space(1)))
80809 +# define __force_user __force __user
80810 # define __kernel __attribute__((address_space(0)))
80811 +# define __force_kernel __force __kernel
80812 # define __safe __attribute__((safe))
80813 # define __force __attribute__((force))
80814 # define __nocast __attribute__((nocast))
80815 # define __iomem __attribute__((noderef, address_space(2)))
80816 +# define __force_iomem __force __iomem
80817 # define __must_hold(x) __attribute__((context(x,1,1)))
80818 # define __acquires(x) __attribute__((context(x,0,1)))
80819 # define __releases(x) __attribute__((context(x,1,0)))
80820 @@ -17,20 +20,37 @@
80821 # define __release(x) __context__(x,-1)
80822 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80823 # define __percpu __attribute__((noderef, address_space(3)))
80824 +# define __force_percpu __force __percpu
80825 #ifdef CONFIG_SPARSE_RCU_POINTER
80826 # define __rcu __attribute__((noderef, address_space(4)))
80827 +# define __force_rcu __force __rcu
80828 #else
80829 # define __rcu
80830 +# define __force_rcu
80831 #endif
80832 extern void __chk_user_ptr(const volatile void __user *);
80833 extern void __chk_io_ptr(const volatile void __iomem *);
80834 #else
80835 -# define __user
80836 -# define __kernel
80837 +# ifdef CHECKER_PLUGIN
80838 +//# define __user
80839 +//# define __force_user
80840 +//# define __kernel
80841 +//# define __force_kernel
80842 +# else
80843 +# ifdef STRUCTLEAK_PLUGIN
80844 +# define __user __attribute__((user))
80845 +# else
80846 +# define __user
80847 +# endif
80848 +# define __force_user
80849 +# define __kernel
80850 +# define __force_kernel
80851 +# endif
80852 # define __safe
80853 # define __force
80854 # define __nocast
80855 # define __iomem
80856 +# define __force_iomem
80857 # define __chk_user_ptr(x) (void)0
80858 # define __chk_io_ptr(x) (void)0
80859 # define __builtin_warning(x, y...) (1)
80860 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80861 # define __release(x) (void)0
80862 # define __cond_lock(x,c) (c)
80863 # define __percpu
80864 +# define __force_percpu
80865 # define __rcu
80866 +# define __force_rcu
80867 #endif
80868
80869 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80870 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80871 # define __attribute_const__ /* unimplemented */
80872 #endif
80873
80874 +#ifndef __randomize_layout
80875 +# define __randomize_layout
80876 +#endif
80877 +
80878 +#ifndef __no_randomize_layout
80879 +# define __no_randomize_layout
80880 +#endif
80881 +
80882 +#ifndef __no_const
80883 +# define __no_const
80884 +#endif
80885 +
80886 +#ifndef __do_const
80887 +# define __do_const
80888 +#endif
80889 +
80890 +#ifndef __size_overflow
80891 +# define __size_overflow(...)
80892 +#endif
80893 +
80894 +#ifndef __intentional_overflow
80895 +# define __intentional_overflow(...)
80896 +#endif
80897 +
80898 +#ifndef __latent_entropy
80899 +# define __latent_entropy
80900 +#endif
80901 +
80902 /*
80903 * Tell gcc if a function is cold. The compiler will assume any path
80904 * directly leading to the call is unlikely.
80905 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80906 #define __cold
80907 #endif
80908
80909 +#ifndef __alloc_size
80910 +#define __alloc_size(...)
80911 +#endif
80912 +
80913 +#ifndef __bos
80914 +#define __bos(ptr, arg)
80915 +#endif
80916 +
80917 +#ifndef __bos0
80918 +#define __bos0(ptr)
80919 +#endif
80920 +
80921 +#ifndef __bos1
80922 +#define __bos1(ptr)
80923 +#endif
80924 +
80925 /* Simple shorthand for a section definition */
80926 #ifndef __section
80927 # define __section(S) __attribute__ ((__section__(#S)))
80928 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80929 * use is to mediate communication between process-level code and irq/NMI
80930 * handlers, all running on the same CPU.
80931 */
80932 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80933 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80934 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80935
80936 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80937 #ifdef CONFIG_KPROBES
80938 diff --git a/include/linux/completion.h b/include/linux/completion.h
80939 index 5d5aaae..0ea9b84 100644
80940 --- a/include/linux/completion.h
80941 +++ b/include/linux/completion.h
80942 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80943
80944 extern void wait_for_completion(struct completion *);
80945 extern void wait_for_completion_io(struct completion *);
80946 -extern int wait_for_completion_interruptible(struct completion *x);
80947 -extern int wait_for_completion_killable(struct completion *x);
80948 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80949 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80950 extern unsigned long wait_for_completion_timeout(struct completion *x,
80951 - unsigned long timeout);
80952 + unsigned long timeout) __intentional_overflow(-1);
80953 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80954 - unsigned long timeout);
80955 + unsigned long timeout) __intentional_overflow(-1);
80956 extern long wait_for_completion_interruptible_timeout(
80957 - struct completion *x, unsigned long timeout);
80958 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80959 extern long wait_for_completion_killable_timeout(
80960 - struct completion *x, unsigned long timeout);
80961 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80962 extern bool try_wait_for_completion(struct completion *x);
80963 extern bool completion_done(struct completion *x);
80964
80965 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80966 index 34025df..d94bbbc 100644
80967 --- a/include/linux/configfs.h
80968 +++ b/include/linux/configfs.h
80969 @@ -125,7 +125,7 @@ struct configfs_attribute {
80970 const char *ca_name;
80971 struct module *ca_owner;
80972 umode_t ca_mode;
80973 -};
80974 +} __do_const;
80975
80976 /*
80977 * Users often need to create attribute structures for their configurable
80978 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80979 index 7d1955a..d86a3ca 100644
80980 --- a/include/linux/cpufreq.h
80981 +++ b/include/linux/cpufreq.h
80982 @@ -203,6 +203,7 @@ struct global_attr {
80983 ssize_t (*store)(struct kobject *a, struct attribute *b,
80984 const char *c, size_t count);
80985 };
80986 +typedef struct global_attr __no_const global_attr_no_const;
80987
80988 #define define_one_global_ro(_name) \
80989 static struct global_attr _name = \
80990 @@ -269,7 +270,7 @@ struct cpufreq_driver {
80991 bool boost_supported;
80992 bool boost_enabled;
80993 int (*set_boost) (int state);
80994 -};
80995 +} __do_const;
80996
80997 /* flags */
80998 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80999 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
81000 index 25e0df6..952dffd 100644
81001 --- a/include/linux/cpuidle.h
81002 +++ b/include/linux/cpuidle.h
81003 @@ -50,7 +50,8 @@ struct cpuidle_state {
81004 int index);
81005
81006 int (*enter_dead) (struct cpuidle_device *dev, int index);
81007 -};
81008 +} __do_const;
81009 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
81010
81011 /* Idle State Flags */
81012 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
81013 @@ -209,7 +210,7 @@ struct cpuidle_governor {
81014 void (*reflect) (struct cpuidle_device *dev, int index);
81015
81016 struct module *owner;
81017 -};
81018 +} __do_const;
81019
81020 #ifdef CONFIG_CPU_IDLE
81021 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
81022 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
81023 index 2997af6..424ddc1 100644
81024 --- a/include/linux/cpumask.h
81025 +++ b/include/linux/cpumask.h
81026 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81027 }
81028
81029 /* Valid inputs for n are -1 and 0. */
81030 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81031 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81032 {
81033 return n+1;
81034 }
81035
81036 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81037 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81038 {
81039 return n+1;
81040 }
81041
81042 -static inline unsigned int cpumask_next_and(int n,
81043 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
81044 const struct cpumask *srcp,
81045 const struct cpumask *andp)
81046 {
81047 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81048 *
81049 * Returns >= nr_cpu_ids if no further cpus set.
81050 */
81051 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81052 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81053 {
81054 /* -1 is a legal arg here. */
81055 if (n != -1)
81056 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81057 *
81058 * Returns >= nr_cpu_ids if no further cpus unset.
81059 */
81060 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81061 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81062 {
81063 /* -1 is a legal arg here. */
81064 if (n != -1)
81065 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81066 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
81067 }
81068
81069 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
81070 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
81071 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
81072 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
81073
81074 diff --git a/include/linux/cred.h b/include/linux/cred.h
81075 index b2d0820..2ecafd3 100644
81076 --- a/include/linux/cred.h
81077 +++ b/include/linux/cred.h
81078 @@ -35,7 +35,7 @@ struct group_info {
81079 int nblocks;
81080 kgid_t small_block[NGROUPS_SMALL];
81081 kgid_t *blocks[0];
81082 -};
81083 +} __randomize_layout;
81084
81085 /**
81086 * get_group_info - Get a reference to a group info structure
81087 @@ -136,7 +136,7 @@ struct cred {
81088 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
81089 struct group_info *group_info; /* supplementary groups for euid/fsgid */
81090 struct rcu_head rcu; /* RCU deletion hook */
81091 -};
81092 +} __randomize_layout;
81093
81094 extern void __put_cred(struct cred *);
81095 extern void exit_creds(struct task_struct *);
81096 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81097 static inline void validate_process_creds(void)
81098 {
81099 }
81100 +static inline void validate_task_creds(struct task_struct *task)
81101 +{
81102 +}
81103 #endif
81104
81105 /**
81106 @@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
81107
81108 #define task_uid(task) (task_cred_xxx((task), uid))
81109 #define task_euid(task) (task_cred_xxx((task), euid))
81110 +#define task_securebits(task) (task_cred_xxx((task), securebits))
81111
81112 #define current_cred_xxx(xxx) \
81113 ({ \
81114 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81115 index d45e949..51cf5ea 100644
81116 --- a/include/linux/crypto.h
81117 +++ b/include/linux/crypto.h
81118 @@ -373,7 +373,7 @@ struct cipher_tfm {
81119 const u8 *key, unsigned int keylen);
81120 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81121 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81122 -};
81123 +} __no_const;
81124
81125 struct hash_tfm {
81126 int (*init)(struct hash_desc *desc);
81127 @@ -394,13 +394,13 @@ struct compress_tfm {
81128 int (*cot_decompress)(struct crypto_tfm *tfm,
81129 const u8 *src, unsigned int slen,
81130 u8 *dst, unsigned int *dlen);
81131 -};
81132 +} __no_const;
81133
81134 struct rng_tfm {
81135 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81136 unsigned int dlen);
81137 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81138 -};
81139 +} __no_const;
81140
81141 #define crt_ablkcipher crt_u.ablkcipher
81142 #define crt_aead crt_u.aead
81143 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81144 index 653589e..4ef254a 100644
81145 --- a/include/linux/ctype.h
81146 +++ b/include/linux/ctype.h
81147 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81148 * Fast implementation of tolower() for internal usage. Do not use in your
81149 * code.
81150 */
81151 -static inline char _tolower(const char c)
81152 +static inline unsigned char _tolower(const unsigned char c)
81153 {
81154 return c | 0x20;
81155 }
81156 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81157 index 75a227c..1456987 100644
81158 --- a/include/linux/dcache.h
81159 +++ b/include/linux/dcache.h
81160 @@ -134,7 +134,7 @@ struct dentry {
81161 } d_u;
81162 struct list_head d_subdirs; /* our children */
81163 struct hlist_node d_alias; /* inode alias list */
81164 -};
81165 +} __randomize_layout;
81166
81167 /*
81168 * dentry->d_lock spinlock nesting subclasses:
81169 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81170 index 7925bf0..d5143d2 100644
81171 --- a/include/linux/decompress/mm.h
81172 +++ b/include/linux/decompress/mm.h
81173 @@ -77,7 +77,7 @@ static void free(void *where)
81174 * warnings when not needed (indeed large_malloc / large_free are not
81175 * needed by inflate */
81176
81177 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81178 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81179 #define free(a) kfree(a)
81180
81181 #define large_malloc(a) vmalloc(a)
81182 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81183 index f1863dc..5c26074 100644
81184 --- a/include/linux/devfreq.h
81185 +++ b/include/linux/devfreq.h
81186 @@ -114,7 +114,7 @@ struct devfreq_governor {
81187 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81188 int (*event_handler)(struct devfreq *devfreq,
81189 unsigned int event, void *data);
81190 -};
81191 +} __do_const;
81192
81193 /**
81194 * struct devfreq - Device devfreq structure
81195 diff --git a/include/linux/device.h b/include/linux/device.h
81196 index 43d183a..03b6ba2 100644
81197 --- a/include/linux/device.h
81198 +++ b/include/linux/device.h
81199 @@ -310,7 +310,7 @@ struct subsys_interface {
81200 struct list_head node;
81201 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81202 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81203 -};
81204 +} __do_const;
81205
81206 int subsys_interface_register(struct subsys_interface *sif);
81207 void subsys_interface_unregister(struct subsys_interface *sif);
81208 @@ -506,7 +506,7 @@ struct device_type {
81209 void (*release)(struct device *dev);
81210
81211 const struct dev_pm_ops *pm;
81212 -};
81213 +} __do_const;
81214
81215 /* interface for exporting device attributes */
81216 struct device_attribute {
81217 @@ -516,11 +516,12 @@ struct device_attribute {
81218 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81219 const char *buf, size_t count);
81220 };
81221 +typedef struct device_attribute __no_const device_attribute_no_const;
81222
81223 struct dev_ext_attribute {
81224 struct device_attribute attr;
81225 void *var;
81226 -};
81227 +} __do_const;
81228
81229 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81230 char *buf);
81231 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81232 index 931b709..89b2d89 100644
81233 --- a/include/linux/dma-mapping.h
81234 +++ b/include/linux/dma-mapping.h
81235 @@ -60,7 +60,7 @@ struct dma_map_ops {
81236 u64 (*get_required_mask)(struct device *dev);
81237 #endif
81238 int is_phys;
81239 -};
81240 +} __do_const;
81241
81242 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81243
81244 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81245 index 1f9e642..39e4263 100644
81246 --- a/include/linux/dmaengine.h
81247 +++ b/include/linux/dmaengine.h
81248 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81249 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81250 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81251
81252 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81253 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81254 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81255 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81256 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81257 struct dma_pinned_list *pinned_list, struct page *page,
81258 unsigned int offset, size_t len);
81259
81260 diff --git a/include/linux/efi.h b/include/linux/efi.h
81261 index 45cb4ff..c9b4912 100644
81262 --- a/include/linux/efi.h
81263 +++ b/include/linux/efi.h
81264 @@ -1036,6 +1036,7 @@ struct efivar_operations {
81265 efi_set_variable_t *set_variable;
81266 efi_query_variable_store_t *query_variable_store;
81267 };
81268 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81269
81270 struct efivars {
81271 /*
81272 diff --git a/include/linux/elf.h b/include/linux/elf.h
81273 index 67a5fa7..b817372 100644
81274 --- a/include/linux/elf.h
81275 +++ b/include/linux/elf.h
81276 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81277 #define elf_note elf32_note
81278 #define elf_addr_t Elf32_Off
81279 #define Elf_Half Elf32_Half
81280 +#define elf_dyn Elf32_Dyn
81281
81282 #else
81283
81284 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81285 #define elf_note elf64_note
81286 #define elf_addr_t Elf64_Off
81287 #define Elf_Half Elf64_Half
81288 +#define elf_dyn Elf64_Dyn
81289
81290 #endif
81291
81292 diff --git a/include/linux/err.h b/include/linux/err.h
81293 index a729120..6ede2c9 100644
81294 --- a/include/linux/err.h
81295 +++ b/include/linux/err.h
81296 @@ -20,12 +20,12 @@
81297
81298 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81299
81300 -static inline void * __must_check ERR_PTR(long error)
81301 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81302 {
81303 return (void *) error;
81304 }
81305
81306 -static inline long __must_check PTR_ERR(__force const void *ptr)
81307 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81308 {
81309 return (long) ptr;
81310 }
81311 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81312 index 36f49c4..a2a1f4c 100644
81313 --- a/include/linux/extcon.h
81314 +++ b/include/linux/extcon.h
81315 @@ -135,7 +135,7 @@ struct extcon_dev {
81316 /* /sys/class/extcon/.../mutually_exclusive/... */
81317 struct attribute_group attr_g_muex;
81318 struct attribute **attrs_muex;
81319 - struct device_attribute *d_attrs_muex;
81320 + device_attribute_no_const *d_attrs_muex;
81321 };
81322
81323 /**
81324 diff --git a/include/linux/fb.h b/include/linux/fb.h
81325 index 09bb7a1..d98870a 100644
81326 --- a/include/linux/fb.h
81327 +++ b/include/linux/fb.h
81328 @@ -305,7 +305,7 @@ struct fb_ops {
81329 /* called at KDB enter and leave time to prepare the console */
81330 int (*fb_debug_enter)(struct fb_info *info);
81331 int (*fb_debug_leave)(struct fb_info *info);
81332 -};
81333 +} __do_const;
81334
81335 #ifdef CONFIG_FB_TILEBLITTING
81336 #define FB_TILE_CURSOR_NONE 0
81337 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81338 index 230f87b..1fd0485 100644
81339 --- a/include/linux/fdtable.h
81340 +++ b/include/linux/fdtable.h
81341 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81342 void put_files_struct(struct files_struct *fs);
81343 void reset_files_struct(struct files_struct *);
81344 int unshare_files(struct files_struct **);
81345 -struct files_struct *dup_fd(struct files_struct *, int *);
81346 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81347 void do_close_on_exec(struct files_struct *);
81348 int iterate_fd(struct files_struct *, unsigned,
81349 int (*)(const void *, struct file *, unsigned),
81350 diff --git a/include/linux/filter.h b/include/linux/filter.h
81351 index a5227ab..c789945 100644
81352 --- a/include/linux/filter.h
81353 +++ b/include/linux/filter.h
81354 @@ -9,6 +9,11 @@
81355 #include <linux/skbuff.h>
81356 #include <linux/workqueue.h>
81357 #include <uapi/linux/filter.h>
81358 +#include <asm/cacheflush.h>
81359 +
81360 +struct sk_buff;
81361 +struct sock;
81362 +struct seccomp_data;
81363
81364 /* Internally used and optimized filter representation with extended
81365 * instruction set based on top of classic BPF.
81366 @@ -320,20 +325,23 @@ struct sock_fprog_kern {
81367 struct sock_filter *filter;
81368 };
81369
81370 -struct sk_buff;
81371 -struct sock;
81372 -struct seccomp_data;
81373 +struct bpf_work_struct {
81374 + struct bpf_prog *prog;
81375 + struct work_struct work;
81376 +};
81377
81378 struct bpf_prog {
81379 + u32 pages; /* Number of allocated pages */
81380 u32 jited:1, /* Is our filter JIT'ed? */
81381 len:31; /* Number of filter blocks */
81382 struct sock_fprog_kern *orig_prog; /* Original BPF program */
81383 + struct bpf_work_struct *work; /* Deferred free work struct */
81384 unsigned int (*bpf_func)(const struct sk_buff *skb,
81385 const struct bpf_insn *filter);
81386 + /* Instructions for interpreter */
81387 union {
81388 struct sock_filter insns[0];
81389 struct bpf_insn insnsi[0];
81390 - struct work_struct work;
81391 };
81392 };
81393
81394 @@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
81395
81396 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
81397
81398 +#ifdef CONFIG_DEBUG_SET_MODULE_RONX
81399 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81400 +{
81401 + set_memory_ro((unsigned long)fp, fp->pages);
81402 +}
81403 +
81404 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81405 +{
81406 + set_memory_rw((unsigned long)fp, fp->pages);
81407 +}
81408 +#else
81409 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81410 +{
81411 +}
81412 +
81413 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81414 +{
81415 +}
81416 +#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
81417 +
81418 int sk_filter(struct sock *sk, struct sk_buff *skb);
81419
81420 void bpf_prog_select_runtime(struct bpf_prog *fp);
81421 @@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
81422 int bpf_convert_filter(struct sock_filter *prog, int len,
81423 struct bpf_insn *new_prog, int *new_len);
81424
81425 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
81426 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
81427 + gfp_t gfp_extra_flags);
81428 +void __bpf_prog_free(struct bpf_prog *fp);
81429 +
81430 +static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
81431 +{
81432 + bpf_prog_unlock_ro(fp);
81433 + __bpf_prog_free(fp);
81434 +}
81435 +
81436 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
81437 void bpf_prog_destroy(struct bpf_prog *fp);
81438
81439 @@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
81440
81441 static inline void bpf_jit_free(struct bpf_prog *fp)
81442 {
81443 - kfree(fp);
81444 + bpf_prog_unlock_free(fp);
81445 }
81446 #endif /* CONFIG_BPF_JIT */
81447
81448 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81449 index 8293262..2b3b8bd 100644
81450 --- a/include/linux/frontswap.h
81451 +++ b/include/linux/frontswap.h
81452 @@ -11,7 +11,7 @@ struct frontswap_ops {
81453 int (*load)(unsigned, pgoff_t, struct page *);
81454 void (*invalidate_page)(unsigned, pgoff_t);
81455 void (*invalidate_area)(unsigned);
81456 -};
81457 +} __no_const;
81458
81459 extern bool frontswap_enabled;
81460 extern struct frontswap_ops *
81461 diff --git a/include/linux/fs.h b/include/linux/fs.h
81462 index 9418772..0155807 100644
81463 --- a/include/linux/fs.h
81464 +++ b/include/linux/fs.h
81465 @@ -401,7 +401,7 @@ struct address_space {
81466 spinlock_t private_lock; /* for use by the address_space */
81467 struct list_head private_list; /* ditto */
81468 void *private_data; /* ditto */
81469 -} __attribute__((aligned(sizeof(long))));
81470 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81471 /*
81472 * On most architectures that alignment is already the case; but
81473 * must be enforced here for CRIS, to let the least significant bit
81474 @@ -444,7 +444,7 @@ struct block_device {
81475 int bd_fsfreeze_count;
81476 /* Mutex for freeze */
81477 struct mutex bd_fsfreeze_mutex;
81478 -};
81479 +} __randomize_layout;
81480
81481 /*
81482 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81483 @@ -613,7 +613,7 @@ struct inode {
81484 #endif
81485
81486 void *i_private; /* fs or device private pointer */
81487 -};
81488 +} __randomize_layout;
81489
81490 static inline int inode_unhashed(struct inode *inode)
81491 {
81492 @@ -806,7 +806,7 @@ struct file {
81493 struct list_head f_tfile_llink;
81494 #endif /* #ifdef CONFIG_EPOLL */
81495 struct address_space *f_mapping;
81496 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81497 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81498
81499 struct file_handle {
81500 __u32 handle_bytes;
81501 @@ -934,7 +934,7 @@ struct file_lock {
81502 int state; /* state of grant or error if -ve */
81503 } afs;
81504 } fl_u;
81505 -};
81506 +} __randomize_layout;
81507
81508 /* The following constant reflects the upper bound of the file/locking space */
81509 #ifndef OFFSET_MAX
81510 @@ -1284,7 +1284,7 @@ struct super_block {
81511 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
81512 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
81513 struct rcu_head rcu;
81514 -};
81515 +} __randomize_layout;
81516
81517 extern struct timespec current_fs_time(struct super_block *sb);
81518
81519 @@ -1510,7 +1510,8 @@ struct file_operations {
81520 long (*fallocate)(struct file *file, int mode, loff_t offset,
81521 loff_t len);
81522 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81523 -};
81524 +} __do_const __randomize_layout;
81525 +typedef struct file_operations __no_const file_operations_no_const;
81526
81527 struct inode_operations {
81528 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81529 @@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
81530 return !IS_DEADDIR(inode);
81531 }
81532
81533 +static inline bool is_sidechannel_device(const struct inode *inode)
81534 +{
81535 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81536 + umode_t mode = inode->i_mode;
81537 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81538 +#else
81539 + return false;
81540 +#endif
81541 +}
81542 +
81543 #endif /* _LINUX_FS_H */
81544 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81545 index 0efc3e6..fd23610 100644
81546 --- a/include/linux/fs_struct.h
81547 +++ b/include/linux/fs_struct.h
81548 @@ -6,13 +6,13 @@
81549 #include <linux/seqlock.h>
81550
81551 struct fs_struct {
81552 - int users;
81553 + atomic_t users;
81554 spinlock_t lock;
81555 seqcount_t seq;
81556 int umask;
81557 int in_exec;
81558 struct path root, pwd;
81559 -};
81560 +} __randomize_layout;
81561
81562 extern struct kmem_cache *fs_cachep;
81563
81564 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81565 index 7714849..a4a5c7a 100644
81566 --- a/include/linux/fscache-cache.h
81567 +++ b/include/linux/fscache-cache.h
81568 @@ -113,7 +113,7 @@ struct fscache_operation {
81569 fscache_operation_release_t release;
81570 };
81571
81572 -extern atomic_t fscache_op_debug_id;
81573 +extern atomic_unchecked_t fscache_op_debug_id;
81574 extern void fscache_op_work_func(struct work_struct *work);
81575
81576 extern void fscache_enqueue_operation(struct fscache_operation *);
81577 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81578 INIT_WORK(&op->work, fscache_op_work_func);
81579 atomic_set(&op->usage, 1);
81580 op->state = FSCACHE_OP_ST_INITIALISED;
81581 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81582 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81583 op->processor = processor;
81584 op->release = release;
81585 INIT_LIST_HEAD(&op->pend_link);
81586 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81587 index 115bb81..e7b812b 100644
81588 --- a/include/linux/fscache.h
81589 +++ b/include/linux/fscache.h
81590 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81591 * - this is mandatory for any object that may have data
81592 */
81593 void (*now_uncached)(void *cookie_netfs_data);
81594 -};
81595 +} __do_const;
81596
81597 /*
81598 * fscache cached network filesystem type
81599 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81600 index 1c804b0..1432c2b 100644
81601 --- a/include/linux/fsnotify.h
81602 +++ b/include/linux/fsnotify.h
81603 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81604 struct inode *inode = file_inode(file);
81605 __u32 mask = FS_ACCESS;
81606
81607 + if (is_sidechannel_device(inode))
81608 + return;
81609 +
81610 if (S_ISDIR(inode->i_mode))
81611 mask |= FS_ISDIR;
81612
81613 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81614 struct inode *inode = file_inode(file);
81615 __u32 mask = FS_MODIFY;
81616
81617 + if (is_sidechannel_device(inode))
81618 + return;
81619 +
81620 if (S_ISDIR(inode->i_mode))
81621 mask |= FS_ISDIR;
81622
81623 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81624 */
81625 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81626 {
81627 - return kstrdup(name, GFP_KERNEL);
81628 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81629 }
81630
81631 /*
81632 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81633 index ec274e0..e678159 100644
81634 --- a/include/linux/genhd.h
81635 +++ b/include/linux/genhd.h
81636 @@ -194,7 +194,7 @@ struct gendisk {
81637 struct kobject *slave_dir;
81638
81639 struct timer_rand_state *random;
81640 - atomic_t sync_io; /* RAID */
81641 + atomic_unchecked_t sync_io; /* RAID */
81642 struct disk_events *ev;
81643 #ifdef CONFIG_BLK_DEV_INTEGRITY
81644 struct blk_integrity *integrity;
81645 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81646 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81647
81648 /* drivers/char/random.c */
81649 -extern void add_disk_randomness(struct gendisk *disk);
81650 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81651 extern void rand_initialize_disk(struct gendisk *disk);
81652
81653 static inline sector_t get_start_sect(struct block_device *bdev)
81654 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81655 index c0894dd..2fbf10c 100644
81656 --- a/include/linux/genl_magic_func.h
81657 +++ b/include/linux/genl_magic_func.h
81658 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81659 },
81660
81661 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81662 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81663 +static struct genl_ops ZZZ_genl_ops[] = {
81664 #include GENL_MAGIC_INCLUDE_FILE
81665 };
81666
81667 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81668 index 5e7219d..b1ed627 100644
81669 --- a/include/linux/gfp.h
81670 +++ b/include/linux/gfp.h
81671 @@ -34,6 +34,13 @@ struct vm_area_struct;
81672 #define ___GFP_NO_KSWAPD 0x400000u
81673 #define ___GFP_OTHER_NODE 0x800000u
81674 #define ___GFP_WRITE 0x1000000u
81675 +
81676 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81677 +#define ___GFP_USERCOPY 0x2000000u
81678 +#else
81679 +#define ___GFP_USERCOPY 0
81680 +#endif
81681 +
81682 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81683
81684 /*
81685 @@ -90,6 +97,7 @@ struct vm_area_struct;
81686 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81687 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81688 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81689 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81690
81691 /*
81692 * This may seem redundant, but it's a way of annotating false positives vs.
81693 @@ -97,7 +105,7 @@ struct vm_area_struct;
81694 */
81695 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81696
81697 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81698 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81699 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81700
81701 /* This equals 0, but use constants in case they ever change */
81702 @@ -155,6 +163,8 @@ struct vm_area_struct;
81703 /* 4GB DMA on some platforms */
81704 #define GFP_DMA32 __GFP_DMA32
81705
81706 +#define GFP_USERCOPY __GFP_USERCOPY
81707 +
81708 /* Convert GFP flags to their corresponding migrate type */
81709 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
81710 {
81711 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81712 new file mode 100644
81713 index 0000000..edb2cb6
81714 --- /dev/null
81715 +++ b/include/linux/gracl.h
81716 @@ -0,0 +1,340 @@
81717 +#ifndef GR_ACL_H
81718 +#define GR_ACL_H
81719 +
81720 +#include <linux/grdefs.h>
81721 +#include <linux/resource.h>
81722 +#include <linux/capability.h>
81723 +#include <linux/dcache.h>
81724 +#include <asm/resource.h>
81725 +
81726 +/* Major status information */
81727 +
81728 +#define GR_VERSION "grsecurity 3.0"
81729 +#define GRSECURITY_VERSION 0x3000
81730 +
81731 +enum {
81732 + GR_SHUTDOWN = 0,
81733 + GR_ENABLE = 1,
81734 + GR_SPROLE = 2,
81735 + GR_OLDRELOAD = 3,
81736 + GR_SEGVMOD = 4,
81737 + GR_STATUS = 5,
81738 + GR_UNSPROLE = 6,
81739 + GR_PASSSET = 7,
81740 + GR_SPROLEPAM = 8,
81741 + GR_RELOAD = 9,
81742 +};
81743 +
81744 +/* Password setup definitions
81745 + * kernel/grhash.c */
81746 +enum {
81747 + GR_PW_LEN = 128,
81748 + GR_SALT_LEN = 16,
81749 + GR_SHA_LEN = 32,
81750 +};
81751 +
81752 +enum {
81753 + GR_SPROLE_LEN = 64,
81754 +};
81755 +
81756 +enum {
81757 + GR_NO_GLOB = 0,
81758 + GR_REG_GLOB,
81759 + GR_CREATE_GLOB
81760 +};
81761 +
81762 +#define GR_NLIMITS 32
81763 +
81764 +/* Begin Data Structures */
81765 +
81766 +struct sprole_pw {
81767 + unsigned char *rolename;
81768 + unsigned char salt[GR_SALT_LEN];
81769 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81770 +};
81771 +
81772 +struct name_entry {
81773 + __u32 key;
81774 + ino_t inode;
81775 + dev_t device;
81776 + char *name;
81777 + __u16 len;
81778 + __u8 deleted;
81779 + struct name_entry *prev;
81780 + struct name_entry *next;
81781 +};
81782 +
81783 +struct inodev_entry {
81784 + struct name_entry *nentry;
81785 + struct inodev_entry *prev;
81786 + struct inodev_entry *next;
81787 +};
81788 +
81789 +struct acl_role_db {
81790 + struct acl_role_label **r_hash;
81791 + __u32 r_size;
81792 +};
81793 +
81794 +struct inodev_db {
81795 + struct inodev_entry **i_hash;
81796 + __u32 i_size;
81797 +};
81798 +
81799 +struct name_db {
81800 + struct name_entry **n_hash;
81801 + __u32 n_size;
81802 +};
81803 +
81804 +struct crash_uid {
81805 + uid_t uid;
81806 + unsigned long expires;
81807 +};
81808 +
81809 +struct gr_hash_struct {
81810 + void **table;
81811 + void **nametable;
81812 + void *first;
81813 + __u32 table_size;
81814 + __u32 used_size;
81815 + int type;
81816 +};
81817 +
81818 +/* Userspace Grsecurity ACL data structures */
81819 +
81820 +struct acl_subject_label {
81821 + char *filename;
81822 + ino_t inode;
81823 + dev_t device;
81824 + __u32 mode;
81825 + kernel_cap_t cap_mask;
81826 + kernel_cap_t cap_lower;
81827 + kernel_cap_t cap_invert_audit;
81828 +
81829 + struct rlimit res[GR_NLIMITS];
81830 + __u32 resmask;
81831 +
81832 + __u8 user_trans_type;
81833 + __u8 group_trans_type;
81834 + uid_t *user_transitions;
81835 + gid_t *group_transitions;
81836 + __u16 user_trans_num;
81837 + __u16 group_trans_num;
81838 +
81839 + __u32 sock_families[2];
81840 + __u32 ip_proto[8];
81841 + __u32 ip_type;
81842 + struct acl_ip_label **ips;
81843 + __u32 ip_num;
81844 + __u32 inaddr_any_override;
81845 +
81846 + __u32 crashes;
81847 + unsigned long expires;
81848 +
81849 + struct acl_subject_label *parent_subject;
81850 + struct gr_hash_struct *hash;
81851 + struct acl_subject_label *prev;
81852 + struct acl_subject_label *next;
81853 +
81854 + struct acl_object_label **obj_hash;
81855 + __u32 obj_hash_size;
81856 + __u16 pax_flags;
81857 +};
81858 +
81859 +struct role_allowed_ip {
81860 + __u32 addr;
81861 + __u32 netmask;
81862 +
81863 + struct role_allowed_ip *prev;
81864 + struct role_allowed_ip *next;
81865 +};
81866 +
81867 +struct role_transition {
81868 + char *rolename;
81869 +
81870 + struct role_transition *prev;
81871 + struct role_transition *next;
81872 +};
81873 +
81874 +struct acl_role_label {
81875 + char *rolename;
81876 + uid_t uidgid;
81877 + __u16 roletype;
81878 +
81879 + __u16 auth_attempts;
81880 + unsigned long expires;
81881 +
81882 + struct acl_subject_label *root_label;
81883 + struct gr_hash_struct *hash;
81884 +
81885 + struct acl_role_label *prev;
81886 + struct acl_role_label *next;
81887 +
81888 + struct role_transition *transitions;
81889 + struct role_allowed_ip *allowed_ips;
81890 + uid_t *domain_children;
81891 + __u16 domain_child_num;
81892 +
81893 + umode_t umask;
81894 +
81895 + struct acl_subject_label **subj_hash;
81896 + __u32 subj_hash_size;
81897 +};
81898 +
81899 +struct user_acl_role_db {
81900 + struct acl_role_label **r_table;
81901 + __u32 num_pointers; /* Number of allocations to track */
81902 + __u32 num_roles; /* Number of roles */
81903 + __u32 num_domain_children; /* Number of domain children */
81904 + __u32 num_subjects; /* Number of subjects */
81905 + __u32 num_objects; /* Number of objects */
81906 +};
81907 +
81908 +struct acl_object_label {
81909 + char *filename;
81910 + ino_t inode;
81911 + dev_t device;
81912 + __u32 mode;
81913 +
81914 + struct acl_subject_label *nested;
81915 + struct acl_object_label *globbed;
81916 +
81917 + /* next two structures not used */
81918 +
81919 + struct acl_object_label *prev;
81920 + struct acl_object_label *next;
81921 +};
81922 +
81923 +struct acl_ip_label {
81924 + char *iface;
81925 + __u32 addr;
81926 + __u32 netmask;
81927 + __u16 low, high;
81928 + __u8 mode;
81929 + __u32 type;
81930 + __u32 proto[8];
81931 +
81932 + /* next two structures not used */
81933 +
81934 + struct acl_ip_label *prev;
81935 + struct acl_ip_label *next;
81936 +};
81937 +
81938 +struct gr_arg {
81939 + struct user_acl_role_db role_db;
81940 + unsigned char pw[GR_PW_LEN];
81941 + unsigned char salt[GR_SALT_LEN];
81942 + unsigned char sum[GR_SHA_LEN];
81943 + unsigned char sp_role[GR_SPROLE_LEN];
81944 + struct sprole_pw *sprole_pws;
81945 + dev_t segv_device;
81946 + ino_t segv_inode;
81947 + uid_t segv_uid;
81948 + __u16 num_sprole_pws;
81949 + __u16 mode;
81950 +};
81951 +
81952 +struct gr_arg_wrapper {
81953 + struct gr_arg *arg;
81954 + __u32 version;
81955 + __u32 size;
81956 +};
81957 +
81958 +struct subject_map {
81959 + struct acl_subject_label *user;
81960 + struct acl_subject_label *kernel;
81961 + struct subject_map *prev;
81962 + struct subject_map *next;
81963 +};
81964 +
81965 +struct acl_subj_map_db {
81966 + struct subject_map **s_hash;
81967 + __u32 s_size;
81968 +};
81969 +
81970 +struct gr_policy_state {
81971 + struct sprole_pw **acl_special_roles;
81972 + __u16 num_sprole_pws;
81973 + struct acl_role_label *kernel_role;
81974 + struct acl_role_label *role_list;
81975 + struct acl_role_label *default_role;
81976 + struct acl_role_db acl_role_set;
81977 + struct acl_subj_map_db subj_map_set;
81978 + struct name_db name_set;
81979 + struct inodev_db inodev_set;
81980 +};
81981 +
81982 +struct gr_alloc_state {
81983 + unsigned long alloc_stack_next;
81984 + unsigned long alloc_stack_size;
81985 + void **alloc_stack;
81986 +};
81987 +
81988 +struct gr_reload_state {
81989 + struct gr_policy_state oldpolicy;
81990 + struct gr_alloc_state oldalloc;
81991 + struct gr_policy_state newpolicy;
81992 + struct gr_alloc_state newalloc;
81993 + struct gr_policy_state *oldpolicy_ptr;
81994 + struct gr_alloc_state *oldalloc_ptr;
81995 + unsigned char oldmode;
81996 +};
81997 +
81998 +/* End Data Structures Section */
81999 +
82000 +/* Hash functions generated by empirical testing by Brad Spengler
82001 + Makes good use of the low bits of the inode. Generally 0-1 times
82002 + in loop for successful match. 0-3 for unsuccessful match.
82003 + Shift/add algorithm with modulus of table size and an XOR*/
82004 +
82005 +static __inline__ unsigned int
82006 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
82007 +{
82008 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
82009 +}
82010 +
82011 + static __inline__ unsigned int
82012 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
82013 +{
82014 + return ((const unsigned long)userp % sz);
82015 +}
82016 +
82017 +static __inline__ unsigned int
82018 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
82019 +{
82020 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
82021 +}
82022 +
82023 +static __inline__ unsigned int
82024 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
82025 +{
82026 + return full_name_hash((const unsigned char *)name, len) % sz;
82027 +}
82028 +
82029 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
82030 + subj = NULL; \
82031 + iter = 0; \
82032 + while (iter < role->subj_hash_size) { \
82033 + if (subj == NULL) \
82034 + subj = role->subj_hash[iter]; \
82035 + if (subj == NULL) { \
82036 + iter++; \
82037 + continue; \
82038 + }
82039 +
82040 +#define FOR_EACH_SUBJECT_END(subj,iter) \
82041 + subj = subj->next; \
82042 + if (subj == NULL) \
82043 + iter++; \
82044 + }
82045 +
82046 +
82047 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
82048 + subj = role->hash->first; \
82049 + while (subj != NULL) {
82050 +
82051 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
82052 + subj = subj->next; \
82053 + }
82054 +
82055 +#endif
82056 +
82057 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
82058 new file mode 100644
82059 index 0000000..33ebd1f
82060 --- /dev/null
82061 +++ b/include/linux/gracl_compat.h
82062 @@ -0,0 +1,156 @@
82063 +#ifndef GR_ACL_COMPAT_H
82064 +#define GR_ACL_COMPAT_H
82065 +
82066 +#include <linux/resource.h>
82067 +#include <asm/resource.h>
82068 +
82069 +struct sprole_pw_compat {
82070 + compat_uptr_t rolename;
82071 + unsigned char salt[GR_SALT_LEN];
82072 + unsigned char sum[GR_SHA_LEN];
82073 +};
82074 +
82075 +struct gr_hash_struct_compat {
82076 + compat_uptr_t table;
82077 + compat_uptr_t nametable;
82078 + compat_uptr_t first;
82079 + __u32 table_size;
82080 + __u32 used_size;
82081 + int type;
82082 +};
82083 +
82084 +struct acl_subject_label_compat {
82085 + compat_uptr_t filename;
82086 + compat_ino_t inode;
82087 + __u32 device;
82088 + __u32 mode;
82089 + kernel_cap_t cap_mask;
82090 + kernel_cap_t cap_lower;
82091 + kernel_cap_t cap_invert_audit;
82092 +
82093 + struct compat_rlimit res[GR_NLIMITS];
82094 + __u32 resmask;
82095 +
82096 + __u8 user_trans_type;
82097 + __u8 group_trans_type;
82098 + compat_uptr_t user_transitions;
82099 + compat_uptr_t group_transitions;
82100 + __u16 user_trans_num;
82101 + __u16 group_trans_num;
82102 +
82103 + __u32 sock_families[2];
82104 + __u32 ip_proto[8];
82105 + __u32 ip_type;
82106 + compat_uptr_t ips;
82107 + __u32 ip_num;
82108 + __u32 inaddr_any_override;
82109 +
82110 + __u32 crashes;
82111 + compat_ulong_t expires;
82112 +
82113 + compat_uptr_t parent_subject;
82114 + compat_uptr_t hash;
82115 + compat_uptr_t prev;
82116 + compat_uptr_t next;
82117 +
82118 + compat_uptr_t obj_hash;
82119 + __u32 obj_hash_size;
82120 + __u16 pax_flags;
82121 +};
82122 +
82123 +struct role_allowed_ip_compat {
82124 + __u32 addr;
82125 + __u32 netmask;
82126 +
82127 + compat_uptr_t prev;
82128 + compat_uptr_t next;
82129 +};
82130 +
82131 +struct role_transition_compat {
82132 + compat_uptr_t rolename;
82133 +
82134 + compat_uptr_t prev;
82135 + compat_uptr_t next;
82136 +};
82137 +
82138 +struct acl_role_label_compat {
82139 + compat_uptr_t rolename;
82140 + uid_t uidgid;
82141 + __u16 roletype;
82142 +
82143 + __u16 auth_attempts;
82144 + compat_ulong_t expires;
82145 +
82146 + compat_uptr_t root_label;
82147 + compat_uptr_t hash;
82148 +
82149 + compat_uptr_t prev;
82150 + compat_uptr_t next;
82151 +
82152 + compat_uptr_t transitions;
82153 + compat_uptr_t allowed_ips;
82154 + compat_uptr_t domain_children;
82155 + __u16 domain_child_num;
82156 +
82157 + umode_t umask;
82158 +
82159 + compat_uptr_t subj_hash;
82160 + __u32 subj_hash_size;
82161 +};
82162 +
82163 +struct user_acl_role_db_compat {
82164 + compat_uptr_t r_table;
82165 + __u32 num_pointers;
82166 + __u32 num_roles;
82167 + __u32 num_domain_children;
82168 + __u32 num_subjects;
82169 + __u32 num_objects;
82170 +};
82171 +
82172 +struct acl_object_label_compat {
82173 + compat_uptr_t filename;
82174 + compat_ino_t inode;
82175 + __u32 device;
82176 + __u32 mode;
82177 +
82178 + compat_uptr_t nested;
82179 + compat_uptr_t globbed;
82180 +
82181 + compat_uptr_t prev;
82182 + compat_uptr_t next;
82183 +};
82184 +
82185 +struct acl_ip_label_compat {
82186 + compat_uptr_t iface;
82187 + __u32 addr;
82188 + __u32 netmask;
82189 + __u16 low, high;
82190 + __u8 mode;
82191 + __u32 type;
82192 + __u32 proto[8];
82193 +
82194 + compat_uptr_t prev;
82195 + compat_uptr_t next;
82196 +};
82197 +
82198 +struct gr_arg_compat {
82199 + struct user_acl_role_db_compat role_db;
82200 + unsigned char pw[GR_PW_LEN];
82201 + unsigned char salt[GR_SALT_LEN];
82202 + unsigned char sum[GR_SHA_LEN];
82203 + unsigned char sp_role[GR_SPROLE_LEN];
82204 + compat_uptr_t sprole_pws;
82205 + __u32 segv_device;
82206 + compat_ino_t segv_inode;
82207 + uid_t segv_uid;
82208 + __u16 num_sprole_pws;
82209 + __u16 mode;
82210 +};
82211 +
82212 +struct gr_arg_wrapper_compat {
82213 + compat_uptr_t arg;
82214 + __u32 version;
82215 + __u32 size;
82216 +};
82217 +
82218 +#endif
82219 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82220 new file mode 100644
82221 index 0000000..323ecf2
82222 --- /dev/null
82223 +++ b/include/linux/gralloc.h
82224 @@ -0,0 +1,9 @@
82225 +#ifndef __GRALLOC_H
82226 +#define __GRALLOC_H
82227 +
82228 +void acl_free_all(void);
82229 +int acl_alloc_stack_init(unsigned long size);
82230 +void *acl_alloc(unsigned long len);
82231 +void *acl_alloc_num(unsigned long num, unsigned long len);
82232 +
82233 +#endif
82234 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82235 new file mode 100644
82236 index 0000000..be66033
82237 --- /dev/null
82238 +++ b/include/linux/grdefs.h
82239 @@ -0,0 +1,140 @@
82240 +#ifndef GRDEFS_H
82241 +#define GRDEFS_H
82242 +
82243 +/* Begin grsecurity status declarations */
82244 +
82245 +enum {
82246 + GR_READY = 0x01,
82247 + GR_STATUS_INIT = 0x00 // disabled state
82248 +};
82249 +
82250 +/* Begin ACL declarations */
82251 +
82252 +/* Role flags */
82253 +
82254 +enum {
82255 + GR_ROLE_USER = 0x0001,
82256 + GR_ROLE_GROUP = 0x0002,
82257 + GR_ROLE_DEFAULT = 0x0004,
82258 + GR_ROLE_SPECIAL = 0x0008,
82259 + GR_ROLE_AUTH = 0x0010,
82260 + GR_ROLE_NOPW = 0x0020,
82261 + GR_ROLE_GOD = 0x0040,
82262 + GR_ROLE_LEARN = 0x0080,
82263 + GR_ROLE_TPE = 0x0100,
82264 + GR_ROLE_DOMAIN = 0x0200,
82265 + GR_ROLE_PAM = 0x0400,
82266 + GR_ROLE_PERSIST = 0x0800
82267 +};
82268 +
82269 +/* ACL Subject and Object mode flags */
82270 +enum {
82271 + GR_DELETED = 0x80000000
82272 +};
82273 +
82274 +/* ACL Object-only mode flags */
82275 +enum {
82276 + GR_READ = 0x00000001,
82277 + GR_APPEND = 0x00000002,
82278 + GR_WRITE = 0x00000004,
82279 + GR_EXEC = 0x00000008,
82280 + GR_FIND = 0x00000010,
82281 + GR_INHERIT = 0x00000020,
82282 + GR_SETID = 0x00000040,
82283 + GR_CREATE = 0x00000080,
82284 + GR_DELETE = 0x00000100,
82285 + GR_LINK = 0x00000200,
82286 + GR_AUDIT_READ = 0x00000400,
82287 + GR_AUDIT_APPEND = 0x00000800,
82288 + GR_AUDIT_WRITE = 0x00001000,
82289 + GR_AUDIT_EXEC = 0x00002000,
82290 + GR_AUDIT_FIND = 0x00004000,
82291 + GR_AUDIT_INHERIT= 0x00008000,
82292 + GR_AUDIT_SETID = 0x00010000,
82293 + GR_AUDIT_CREATE = 0x00020000,
82294 + GR_AUDIT_DELETE = 0x00040000,
82295 + GR_AUDIT_LINK = 0x00080000,
82296 + GR_PTRACERD = 0x00100000,
82297 + GR_NOPTRACE = 0x00200000,
82298 + GR_SUPPRESS = 0x00400000,
82299 + GR_NOLEARN = 0x00800000,
82300 + GR_INIT_TRANSFER= 0x01000000
82301 +};
82302 +
82303 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82304 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82305 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82306 +
82307 +/* ACL subject-only mode flags */
82308 +enum {
82309 + GR_KILL = 0x00000001,
82310 + GR_VIEW = 0x00000002,
82311 + GR_PROTECTED = 0x00000004,
82312 + GR_LEARN = 0x00000008,
82313 + GR_OVERRIDE = 0x00000010,
82314 + /* just a placeholder, this mode is only used in userspace */
82315 + GR_DUMMY = 0x00000020,
82316 + GR_PROTSHM = 0x00000040,
82317 + GR_KILLPROC = 0x00000080,
82318 + GR_KILLIPPROC = 0x00000100,
82319 + /* just a placeholder, this mode is only used in userspace */
82320 + GR_NOTROJAN = 0x00000200,
82321 + GR_PROTPROCFD = 0x00000400,
82322 + GR_PROCACCT = 0x00000800,
82323 + GR_RELAXPTRACE = 0x00001000,
82324 + //GR_NESTED = 0x00002000,
82325 + GR_INHERITLEARN = 0x00004000,
82326 + GR_PROCFIND = 0x00008000,
82327 + GR_POVERRIDE = 0x00010000,
82328 + GR_KERNELAUTH = 0x00020000,
82329 + GR_ATSECURE = 0x00040000,
82330 + GR_SHMEXEC = 0x00080000
82331 +};
82332 +
82333 +enum {
82334 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82335 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82336 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82337 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82338 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82339 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82340 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82341 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82342 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82343 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82344 +};
82345 +
82346 +enum {
82347 + GR_ID_USER = 0x01,
82348 + GR_ID_GROUP = 0x02,
82349 +};
82350 +
82351 +enum {
82352 + GR_ID_ALLOW = 0x01,
82353 + GR_ID_DENY = 0x02,
82354 +};
82355 +
82356 +#define GR_CRASH_RES 31
82357 +#define GR_UIDTABLE_MAX 500
82358 +
82359 +/* begin resource learning section */
82360 +enum {
82361 + GR_RLIM_CPU_BUMP = 60,
82362 + GR_RLIM_FSIZE_BUMP = 50000,
82363 + GR_RLIM_DATA_BUMP = 10000,
82364 + GR_RLIM_STACK_BUMP = 1000,
82365 + GR_RLIM_CORE_BUMP = 10000,
82366 + GR_RLIM_RSS_BUMP = 500000,
82367 + GR_RLIM_NPROC_BUMP = 1,
82368 + GR_RLIM_NOFILE_BUMP = 5,
82369 + GR_RLIM_MEMLOCK_BUMP = 50000,
82370 + GR_RLIM_AS_BUMP = 500000,
82371 + GR_RLIM_LOCKS_BUMP = 2,
82372 + GR_RLIM_SIGPENDING_BUMP = 5,
82373 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82374 + GR_RLIM_NICE_BUMP = 1,
82375 + GR_RLIM_RTPRIO_BUMP = 1,
82376 + GR_RLIM_RTTIME_BUMP = 1000000
82377 +};
82378 +
82379 +#endif
82380 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82381 new file mode 100644
82382 index 0000000..d25522e
82383 --- /dev/null
82384 +++ b/include/linux/grinternal.h
82385 @@ -0,0 +1,229 @@
82386 +#ifndef __GRINTERNAL_H
82387 +#define __GRINTERNAL_H
82388 +
82389 +#ifdef CONFIG_GRKERNSEC
82390 +
82391 +#include <linux/fs.h>
82392 +#include <linux/mnt_namespace.h>
82393 +#include <linux/nsproxy.h>
82394 +#include <linux/gracl.h>
82395 +#include <linux/grdefs.h>
82396 +#include <linux/grmsg.h>
82397 +
82398 +void gr_add_learn_entry(const char *fmt, ...)
82399 + __attribute__ ((format (printf, 1, 2)));
82400 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82401 + const struct vfsmount *mnt);
82402 +__u32 gr_check_create(const struct dentry *new_dentry,
82403 + const struct dentry *parent,
82404 + const struct vfsmount *mnt, const __u32 mode);
82405 +int gr_check_protected_task(const struct task_struct *task);
82406 +__u32 to_gr_audit(const __u32 reqmode);
82407 +int gr_set_acls(const int type);
82408 +int gr_acl_is_enabled(void);
82409 +char gr_roletype_to_char(void);
82410 +
82411 +void gr_handle_alertkill(struct task_struct *task);
82412 +char *gr_to_filename(const struct dentry *dentry,
82413 + const struct vfsmount *mnt);
82414 +char *gr_to_filename1(const struct dentry *dentry,
82415 + const struct vfsmount *mnt);
82416 +char *gr_to_filename2(const struct dentry *dentry,
82417 + const struct vfsmount *mnt);
82418 +char *gr_to_filename3(const struct dentry *dentry,
82419 + const struct vfsmount *mnt);
82420 +
82421 +extern int grsec_enable_ptrace_readexec;
82422 +extern int grsec_enable_harden_ptrace;
82423 +extern int grsec_enable_link;
82424 +extern int grsec_enable_fifo;
82425 +extern int grsec_enable_execve;
82426 +extern int grsec_enable_shm;
82427 +extern int grsec_enable_execlog;
82428 +extern int grsec_enable_signal;
82429 +extern int grsec_enable_audit_ptrace;
82430 +extern int grsec_enable_forkfail;
82431 +extern int grsec_enable_time;
82432 +extern int grsec_enable_rofs;
82433 +extern int grsec_deny_new_usb;
82434 +extern int grsec_enable_chroot_shmat;
82435 +extern int grsec_enable_chroot_mount;
82436 +extern int grsec_enable_chroot_double;
82437 +extern int grsec_enable_chroot_pivot;
82438 +extern int grsec_enable_chroot_chdir;
82439 +extern int grsec_enable_chroot_chmod;
82440 +extern int grsec_enable_chroot_mknod;
82441 +extern int grsec_enable_chroot_fchdir;
82442 +extern int grsec_enable_chroot_nice;
82443 +extern int grsec_enable_chroot_execlog;
82444 +extern int grsec_enable_chroot_caps;
82445 +extern int grsec_enable_chroot_sysctl;
82446 +extern int grsec_enable_chroot_unix;
82447 +extern int grsec_enable_symlinkown;
82448 +extern kgid_t grsec_symlinkown_gid;
82449 +extern int grsec_enable_tpe;
82450 +extern kgid_t grsec_tpe_gid;
82451 +extern int grsec_enable_tpe_all;
82452 +extern int grsec_enable_tpe_invert;
82453 +extern int grsec_enable_socket_all;
82454 +extern kgid_t grsec_socket_all_gid;
82455 +extern int grsec_enable_socket_client;
82456 +extern kgid_t grsec_socket_client_gid;
82457 +extern int grsec_enable_socket_server;
82458 +extern kgid_t grsec_socket_server_gid;
82459 +extern kgid_t grsec_audit_gid;
82460 +extern int grsec_enable_group;
82461 +extern int grsec_enable_log_rwxmaps;
82462 +extern int grsec_enable_mount;
82463 +extern int grsec_enable_chdir;
82464 +extern int grsec_resource_logging;
82465 +extern int grsec_enable_blackhole;
82466 +extern int grsec_lastack_retries;
82467 +extern int grsec_enable_brute;
82468 +extern int grsec_enable_harden_ipc;
82469 +extern int grsec_lock;
82470 +
82471 +extern spinlock_t grsec_alert_lock;
82472 +extern unsigned long grsec_alert_wtime;
82473 +extern unsigned long grsec_alert_fyet;
82474 +
82475 +extern spinlock_t grsec_audit_lock;
82476 +
82477 +extern rwlock_t grsec_exec_file_lock;
82478 +
82479 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82480 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82481 + (tsk)->exec_file->f_path.mnt) : "/")
82482 +
82483 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82484 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82485 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82486 +
82487 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82488 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82489 + (tsk)->exec_file->f_path.mnt) : "/")
82490 +
82491 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82492 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82493 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82494 +
82495 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82496 +
82497 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82498 +
82499 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82500 +{
82501 + if (file1 && file2) {
82502 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82503 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82504 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82505 + return true;
82506 + }
82507 +
82508 + return false;
82509 +}
82510 +
82511 +#define GR_CHROOT_CAPS {{ \
82512 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82513 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82514 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82515 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82516 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82517 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82518 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82519 +
82520 +#define security_learn(normal_msg,args...) \
82521 +({ \
82522 + read_lock(&grsec_exec_file_lock); \
82523 + gr_add_learn_entry(normal_msg "\n", ## args); \
82524 + read_unlock(&grsec_exec_file_lock); \
82525 +})
82526 +
82527 +enum {
82528 + GR_DO_AUDIT,
82529 + GR_DONT_AUDIT,
82530 + /* used for non-audit messages that we shouldn't kill the task on */
82531 + GR_DONT_AUDIT_GOOD
82532 +};
82533 +
82534 +enum {
82535 + GR_TTYSNIFF,
82536 + GR_RBAC,
82537 + GR_RBAC_STR,
82538 + GR_STR_RBAC,
82539 + GR_RBAC_MODE2,
82540 + GR_RBAC_MODE3,
82541 + GR_FILENAME,
82542 + GR_SYSCTL_HIDDEN,
82543 + GR_NOARGS,
82544 + GR_ONE_INT,
82545 + GR_ONE_INT_TWO_STR,
82546 + GR_ONE_STR,
82547 + GR_STR_INT,
82548 + GR_TWO_STR_INT,
82549 + GR_TWO_INT,
82550 + GR_TWO_U64,
82551 + GR_THREE_INT,
82552 + GR_FIVE_INT_TWO_STR,
82553 + GR_TWO_STR,
82554 + GR_THREE_STR,
82555 + GR_FOUR_STR,
82556 + GR_STR_FILENAME,
82557 + GR_FILENAME_STR,
82558 + GR_FILENAME_TWO_INT,
82559 + GR_FILENAME_TWO_INT_STR,
82560 + GR_TEXTREL,
82561 + GR_PTRACE,
82562 + GR_RESOURCE,
82563 + GR_CAP,
82564 + GR_SIG,
82565 + GR_SIG2,
82566 + GR_CRASH1,
82567 + GR_CRASH2,
82568 + GR_PSACCT,
82569 + GR_RWXMAP,
82570 + GR_RWXMAPVMA
82571 +};
82572 +
82573 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82574 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82575 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82576 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82577 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82578 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82579 +#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)
82580 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82581 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82582 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82583 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82584 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82585 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82586 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82587 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82588 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82589 +#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)
82590 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82591 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82592 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82593 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82594 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82595 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82596 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82597 +#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)
82598 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82599 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82600 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82601 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82602 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82603 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82604 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82605 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82606 +#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)
82607 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82608 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82609 +
82610 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82611 +
82612 +#endif
82613 +
82614 +#endif
82615 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82616 new file mode 100644
82617 index 0000000..b02ba9d
82618 --- /dev/null
82619 +++ b/include/linux/grmsg.h
82620 @@ -0,0 +1,117 @@
82621 +#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"
82622 +#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"
82623 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82624 +#define GR_STOPMOD_MSG "denied modification of module state by "
82625 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82626 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82627 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82628 +#define GR_IOPL_MSG "denied use of iopl() by "
82629 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82630 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82631 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82632 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82633 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82634 +#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"
82635 +#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"
82636 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82637 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82638 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82639 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82640 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82641 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82642 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82643 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82644 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82645 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82646 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82647 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82648 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82649 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82650 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82651 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82652 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82653 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82654 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82655 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82656 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82657 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82658 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82659 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82660 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82661 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82662 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82663 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82664 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82665 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82666 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82667 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82668 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82669 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82670 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82671 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82672 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82673 +#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"
82674 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82675 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82676 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82677 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82678 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82679 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82680 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82681 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82682 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82683 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82684 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82685 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82686 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82687 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82688 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82689 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82690 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82691 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82692 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82693 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82694 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82695 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82696 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82697 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82698 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82699 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82700 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82701 +#define GR_TIME_MSG "time set by "
82702 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82703 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82704 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82705 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82706 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82707 +#define GR_BIND_MSG "denied bind() by "
82708 +#define GR_CONNECT_MSG "denied connect() by "
82709 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82710 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82711 +#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"
82712 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82713 +#define GR_CAP_ACL_MSG "use of %s denied for "
82714 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82715 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82716 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82717 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82718 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82719 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82720 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82721 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82722 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82723 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82724 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82725 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82726 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82727 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82728 +#define GR_VM86_MSG "denied use of vm86 by "
82729 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82730 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82731 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82732 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82733 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82734 +#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 "
82735 +#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 "
82736 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82737 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82738 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82739 new file mode 100644
82740 index 0000000..10b9635
82741 --- /dev/null
82742 +++ b/include/linux/grsecurity.h
82743 @@ -0,0 +1,254 @@
82744 +#ifndef GR_SECURITY_H
82745 +#define GR_SECURITY_H
82746 +#include <linux/fs.h>
82747 +#include <linux/fs_struct.h>
82748 +#include <linux/binfmts.h>
82749 +#include <linux/gracl.h>
82750 +
82751 +/* notify of brain-dead configs */
82752 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82753 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82754 +#endif
82755 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82756 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82757 +#endif
82758 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82759 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82760 +#endif
82761 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82762 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82763 +#endif
82764 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82765 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82766 +#endif
82767 +
82768 +int gr_handle_new_usb(void);
82769 +
82770 +void gr_handle_brute_attach(int dumpable);
82771 +void gr_handle_brute_check(void);
82772 +void gr_handle_kernel_exploit(void);
82773 +
82774 +char gr_roletype_to_char(void);
82775 +
82776 +int gr_proc_is_restricted(void);
82777 +
82778 +int gr_acl_enable_at_secure(void);
82779 +
82780 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82781 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82782 +
82783 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82784 +
82785 +void gr_del_task_from_ip_table(struct task_struct *p);
82786 +
82787 +int gr_pid_is_chrooted(struct task_struct *p);
82788 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82789 +int gr_handle_chroot_nice(void);
82790 +int gr_handle_chroot_sysctl(const int op);
82791 +int gr_handle_chroot_setpriority(struct task_struct *p,
82792 + const int niceval);
82793 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82794 +int gr_chroot_fhandle(void);
82795 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82796 + const struct vfsmount *mnt);
82797 +void gr_handle_chroot_chdir(const struct path *path);
82798 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82799 + const struct vfsmount *mnt, const int mode);
82800 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82801 + const struct vfsmount *mnt, const int mode);
82802 +int gr_handle_chroot_mount(const struct dentry *dentry,
82803 + const struct vfsmount *mnt,
82804 + const char *dev_name);
82805 +int gr_handle_chroot_pivot(void);
82806 +int gr_handle_chroot_unix(const pid_t pid);
82807 +
82808 +int gr_handle_rawio(const struct inode *inode);
82809 +
82810 +void gr_handle_ioperm(void);
82811 +void gr_handle_iopl(void);
82812 +void gr_handle_msr_write(void);
82813 +
82814 +umode_t gr_acl_umask(void);
82815 +
82816 +int gr_tpe_allow(const struct file *file);
82817 +
82818 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82819 +void gr_clear_chroot_entries(struct task_struct *task);
82820 +
82821 +void gr_log_forkfail(const int retval);
82822 +void gr_log_timechange(void);
82823 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82824 +void gr_log_chdir(const struct dentry *dentry,
82825 + const struct vfsmount *mnt);
82826 +void gr_log_chroot_exec(const struct dentry *dentry,
82827 + const struct vfsmount *mnt);
82828 +void gr_log_remount(const char *devname, const int retval);
82829 +void gr_log_unmount(const char *devname, const int retval);
82830 +void gr_log_mount(const char *from, const char *to, const int retval);
82831 +void gr_log_textrel(struct vm_area_struct *vma);
82832 +void gr_log_ptgnustack(struct file *file);
82833 +void gr_log_rwxmmap(struct file *file);
82834 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82835 +
82836 +int gr_handle_follow_link(const struct inode *parent,
82837 + const struct inode *inode,
82838 + const struct dentry *dentry,
82839 + const struct vfsmount *mnt);
82840 +int gr_handle_fifo(const struct dentry *dentry,
82841 + const struct vfsmount *mnt,
82842 + const struct dentry *dir, const int flag,
82843 + const int acc_mode);
82844 +int gr_handle_hardlink(const struct dentry *dentry,
82845 + const struct vfsmount *mnt,
82846 + struct inode *inode,
82847 + const int mode, const struct filename *to);
82848 +
82849 +int gr_is_capable(const int cap);
82850 +int gr_is_capable_nolog(const int cap);
82851 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82852 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82853 +
82854 +void gr_copy_label(struct task_struct *tsk);
82855 +void gr_handle_crash(struct task_struct *task, const int sig);
82856 +int gr_handle_signal(const struct task_struct *p, const int sig);
82857 +int gr_check_crash_uid(const kuid_t uid);
82858 +int gr_check_protected_task(const struct task_struct *task);
82859 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82860 +int gr_acl_handle_mmap(const struct file *file,
82861 + const unsigned long prot);
82862 +int gr_acl_handle_mprotect(const struct file *file,
82863 + const unsigned long prot);
82864 +int gr_check_hidden_task(const struct task_struct *tsk);
82865 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82866 + const struct vfsmount *mnt);
82867 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82868 + const struct vfsmount *mnt);
82869 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82870 + const struct vfsmount *mnt, const int fmode);
82871 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82872 + const struct vfsmount *mnt, umode_t *mode);
82873 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82874 + const struct vfsmount *mnt);
82875 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82876 + const struct vfsmount *mnt);
82877 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82878 + const struct vfsmount *mnt);
82879 +int gr_handle_ptrace(struct task_struct *task, const long request);
82880 +int gr_handle_proc_ptrace(struct task_struct *task);
82881 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82882 + const struct vfsmount *mnt);
82883 +int gr_check_crash_exec(const struct file *filp);
82884 +int gr_acl_is_enabled(void);
82885 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82886 + const kgid_t gid);
82887 +int gr_set_proc_label(const struct dentry *dentry,
82888 + const struct vfsmount *mnt,
82889 + const int unsafe_flags);
82890 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82891 + const struct vfsmount *mnt);
82892 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82893 + const struct vfsmount *mnt, int acc_mode);
82894 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82895 + const struct dentry *p_dentry,
82896 + const struct vfsmount *p_mnt,
82897 + int open_flags, int acc_mode, const int imode);
82898 +void gr_handle_create(const struct dentry *dentry,
82899 + const struct vfsmount *mnt);
82900 +void gr_handle_proc_create(const struct dentry *dentry,
82901 + const struct inode *inode);
82902 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82903 + const struct dentry *parent_dentry,
82904 + const struct vfsmount *parent_mnt,
82905 + const int mode);
82906 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82907 + const struct dentry *parent_dentry,
82908 + const struct vfsmount *parent_mnt);
82909 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82910 + const struct vfsmount *mnt);
82911 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82912 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82913 + const struct vfsmount *mnt);
82914 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82915 + const struct dentry *parent_dentry,
82916 + const struct vfsmount *parent_mnt,
82917 + const struct filename *from);
82918 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82919 + const struct dentry *parent_dentry,
82920 + const struct vfsmount *parent_mnt,
82921 + const struct dentry *old_dentry,
82922 + const struct vfsmount *old_mnt, const struct filename *to);
82923 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82924 +int gr_acl_handle_rename(struct dentry *new_dentry,
82925 + struct dentry *parent_dentry,
82926 + const struct vfsmount *parent_mnt,
82927 + struct dentry *old_dentry,
82928 + struct inode *old_parent_inode,
82929 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82930 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82931 + struct dentry *old_dentry,
82932 + struct dentry *new_dentry,
82933 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82934 +__u32 gr_check_link(const struct dentry *new_dentry,
82935 + const struct dentry *parent_dentry,
82936 + const struct vfsmount *parent_mnt,
82937 + const struct dentry *old_dentry,
82938 + const struct vfsmount *old_mnt);
82939 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82940 + const unsigned int namelen, const ino_t ino);
82941 +
82942 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82943 + const struct vfsmount *mnt);
82944 +void gr_acl_handle_exit(void);
82945 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82946 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82947 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82948 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82949 +void gr_audit_ptrace(struct task_struct *task);
82950 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82951 +void gr_put_exec_file(struct task_struct *task);
82952 +
82953 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82954 +
82955 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82956 +extern void gr_learn_resource(const struct task_struct *task, const int res,
82957 + const unsigned long wanted, const int gt);
82958 +#else
82959 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
82960 + const unsigned long wanted, const int gt)
82961 +{
82962 +}
82963 +#endif
82964 +
82965 +#ifdef CONFIG_GRKERNSEC_RESLOG
82966 +extern void gr_log_resource(const struct task_struct *task, const int res,
82967 + const unsigned long wanted, const int gt);
82968 +#else
82969 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82970 + const unsigned long wanted, const int gt)
82971 +{
82972 +}
82973 +#endif
82974 +
82975 +#ifdef CONFIG_GRKERNSEC
82976 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82977 +void gr_handle_vm86(void);
82978 +void gr_handle_mem_readwrite(u64 from, u64 to);
82979 +
82980 +void gr_log_badprocpid(const char *entry);
82981 +
82982 +extern int grsec_enable_dmesg;
82983 +extern int grsec_disable_privio;
82984 +
82985 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82986 +extern kgid_t grsec_proc_gid;
82987 +#endif
82988 +
82989 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82990 +extern int grsec_enable_chroot_findtask;
82991 +#endif
82992 +#ifdef CONFIG_GRKERNSEC_SETXID
82993 +extern int grsec_enable_setxid;
82994 +#endif
82995 +#endif
82996 +
82997 +#endif
82998 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82999 new file mode 100644
83000 index 0000000..e7ffaaf
83001 --- /dev/null
83002 +++ b/include/linux/grsock.h
83003 @@ -0,0 +1,19 @@
83004 +#ifndef __GRSOCK_H
83005 +#define __GRSOCK_H
83006 +
83007 +extern void gr_attach_curr_ip(const struct sock *sk);
83008 +extern int gr_handle_sock_all(const int family, const int type,
83009 + const int protocol);
83010 +extern int gr_handle_sock_server(const struct sockaddr *sck);
83011 +extern int gr_handle_sock_server_other(const struct sock *sck);
83012 +extern int gr_handle_sock_client(const struct sockaddr *sck);
83013 +extern int gr_search_connect(struct socket * sock,
83014 + struct sockaddr_in * addr);
83015 +extern int gr_search_bind(struct socket * sock,
83016 + struct sockaddr_in * addr);
83017 +extern int gr_search_listen(struct socket * sock);
83018 +extern int gr_search_accept(struct socket * sock);
83019 +extern int gr_search_socket(const int domain, const int type,
83020 + const int protocol);
83021 +
83022 +#endif
83023 diff --git a/include/linux/hash.h b/include/linux/hash.h
83024 index d0494c3..69b7715 100644
83025 --- a/include/linux/hash.h
83026 +++ b/include/linux/hash.h
83027 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
83028 struct fast_hash_ops {
83029 u32 (*hash)(const void *data, u32 len, u32 seed);
83030 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
83031 -};
83032 +} __no_const;
83033
83034 /**
83035 * arch_fast_hash - Caclulates a hash over a given buffer that can have
83036 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
83037 index 9286a46..373f27f 100644
83038 --- a/include/linux/highmem.h
83039 +++ b/include/linux/highmem.h
83040 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
83041 kunmap_atomic(kaddr);
83042 }
83043
83044 +static inline void sanitize_highpage(struct page *page)
83045 +{
83046 + void *kaddr;
83047 + unsigned long flags;
83048 +
83049 + local_irq_save(flags);
83050 + kaddr = kmap_atomic(page);
83051 + clear_page(kaddr);
83052 + kunmap_atomic(kaddr);
83053 + local_irq_restore(flags);
83054 +}
83055 +
83056 static inline void zero_user_segments(struct page *page,
83057 unsigned start1, unsigned end1,
83058 unsigned start2, unsigned end2)
83059 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
83060 index 1c7b89a..7dda400 100644
83061 --- a/include/linux/hwmon-sysfs.h
83062 +++ b/include/linux/hwmon-sysfs.h
83063 @@ -25,7 +25,8 @@
83064 struct sensor_device_attribute{
83065 struct device_attribute dev_attr;
83066 int index;
83067 -};
83068 +} __do_const;
83069 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
83070 #define to_sensor_dev_attr(_dev_attr) \
83071 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
83072
83073 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
83074 struct device_attribute dev_attr;
83075 u8 index;
83076 u8 nr;
83077 -};
83078 +} __do_const;
83079 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
83080 #define to_sensor_dev_attr_2(_dev_attr) \
83081 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
83082
83083 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
83084 index b556e0a..c10a515 100644
83085 --- a/include/linux/i2c.h
83086 +++ b/include/linux/i2c.h
83087 @@ -378,6 +378,7 @@ struct i2c_algorithm {
83088 /* To determine what the adapter supports */
83089 u32 (*functionality) (struct i2c_adapter *);
83090 };
83091 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
83092
83093 /**
83094 * struct i2c_bus_recovery_info - I2C bus recovery information
83095 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
83096 index d23c3c2..eb63c81 100644
83097 --- a/include/linux/i2o.h
83098 +++ b/include/linux/i2o.h
83099 @@ -565,7 +565,7 @@ struct i2o_controller {
83100 struct i2o_device *exec; /* Executive */
83101 #if BITS_PER_LONG == 64
83102 spinlock_t context_list_lock; /* lock for context_list */
83103 - atomic_t context_list_counter; /* needed for unique contexts */
83104 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
83105 struct list_head context_list; /* list of context id's
83106 and pointers */
83107 #endif
83108 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
83109 index aff7ad8..3942bbd 100644
83110 --- a/include/linux/if_pppox.h
83111 +++ b/include/linux/if_pppox.h
83112 @@ -76,7 +76,7 @@ struct pppox_proto {
83113 int (*ioctl)(struct socket *sock, unsigned int cmd,
83114 unsigned long arg);
83115 struct module *owner;
83116 -};
83117 +} __do_const;
83118
83119 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
83120 extern void unregister_pppox_proto(int proto_num);
83121 diff --git a/include/linux/init.h b/include/linux/init.h
83122 index 2df8e8d..3e1280d 100644
83123 --- a/include/linux/init.h
83124 +++ b/include/linux/init.h
83125 @@ -37,9 +37,17 @@
83126 * section.
83127 */
83128
83129 +#define add_init_latent_entropy __latent_entropy
83130 +
83131 +#ifdef CONFIG_MEMORY_HOTPLUG
83132 +#define add_meminit_latent_entropy
83133 +#else
83134 +#define add_meminit_latent_entropy __latent_entropy
83135 +#endif
83136 +
83137 /* These are for everybody (although not all archs will actually
83138 discard it in modules) */
83139 -#define __init __section(.init.text) __cold notrace
83140 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
83141 #define __initdata __section(.init.data)
83142 #define __initconst __constsection(.init.rodata)
83143 #define __exitdata __section(.exit.data)
83144 @@ -100,7 +108,7 @@
83145 #define __cpuexitconst
83146
83147 /* Used for MEMORY_HOTPLUG */
83148 -#define __meminit __section(.meminit.text) __cold notrace
83149 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
83150 #define __meminitdata __section(.meminit.data)
83151 #define __meminitconst __constsection(.meminit.rodata)
83152 #define __memexit __section(.memexit.text) __exitused __cold notrace
83153 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
83154 index 2bb4c4f3..e0fac69 100644
83155 --- a/include/linux/init_task.h
83156 +++ b/include/linux/init_task.h
83157 @@ -149,6 +149,12 @@ extern struct task_group root_task_group;
83158
83159 #define INIT_TASK_COMM "swapper"
83160
83161 +#ifdef CONFIG_X86
83162 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
83163 +#else
83164 +#define INIT_TASK_THREAD_INFO
83165 +#endif
83166 +
83167 #ifdef CONFIG_RT_MUTEXES
83168 # define INIT_RT_MUTEXES(tsk) \
83169 .pi_waiters = RB_ROOT, \
83170 @@ -196,6 +202,7 @@ extern struct task_group root_task_group;
83171 RCU_POINTER_INITIALIZER(cred, &init_cred), \
83172 .comm = INIT_TASK_COMM, \
83173 .thread = INIT_THREAD, \
83174 + INIT_TASK_THREAD_INFO \
83175 .fs = &init_fs, \
83176 .files = &init_files, \
83177 .signal = &init_signals, \
83178 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
83179 index 698ad05..8601bb7 100644
83180 --- a/include/linux/interrupt.h
83181 +++ b/include/linux/interrupt.h
83182 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
83183
83184 struct softirq_action
83185 {
83186 - void (*action)(struct softirq_action *);
83187 -};
83188 + void (*action)(void);
83189 +} __no_const;
83190
83191 asmlinkage void do_softirq(void);
83192 asmlinkage void __do_softirq(void);
83193 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
83194 }
83195 #endif
83196
83197 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
83198 +extern void open_softirq(int nr, void (*action)(void));
83199 extern void softirq_init(void);
83200 extern void __raise_softirq_irqoff(unsigned int nr);
83201
83202 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
83203 index 20f9a52..63ee2e3 100644
83204 --- a/include/linux/iommu.h
83205 +++ b/include/linux/iommu.h
83206 @@ -131,7 +131,7 @@ struct iommu_ops {
83207 u32 (*domain_get_windows)(struct iommu_domain *domain);
83208
83209 unsigned long pgsize_bitmap;
83210 -};
83211 +} __do_const;
83212
83213 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83214 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83215 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83216 index 142ec54..873e033 100644
83217 --- a/include/linux/ioport.h
83218 +++ b/include/linux/ioport.h
83219 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83220 int adjust_resource(struct resource *res, resource_size_t start,
83221 resource_size_t size);
83222 resource_size_t resource_alignment(struct resource *res);
83223 -static inline resource_size_t resource_size(const struct resource *res)
83224 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83225 {
83226 return res->end - res->start + 1;
83227 }
83228 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83229 index 35e7eca..6afb7ad 100644
83230 --- a/include/linux/ipc_namespace.h
83231 +++ b/include/linux/ipc_namespace.h
83232 @@ -69,7 +69,7 @@ struct ipc_namespace {
83233 struct user_namespace *user_ns;
83234
83235 unsigned int proc_inum;
83236 -};
83237 +} __randomize_layout;
83238
83239 extern struct ipc_namespace init_ipc_ns;
83240 extern atomic_t nr_ipc_ns;
83241 diff --git a/include/linux/irq.h b/include/linux/irq.h
83242 index 62af592..cc3b0d0 100644
83243 --- a/include/linux/irq.h
83244 +++ b/include/linux/irq.h
83245 @@ -344,7 +344,8 @@ struct irq_chip {
83246 void (*irq_release_resources)(struct irq_data *data);
83247
83248 unsigned long flags;
83249 -};
83250 +} __do_const;
83251 +typedef struct irq_chip __no_const irq_chip_no_const;
83252
83253 /*
83254 * irq_chip specific flags
83255 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83256 index 45e2d8c..26d85da 100644
83257 --- a/include/linux/irqchip/arm-gic.h
83258 +++ b/include/linux/irqchip/arm-gic.h
83259 @@ -75,9 +75,11 @@
83260
83261 #ifndef __ASSEMBLY__
83262
83263 +#include <linux/irq.h>
83264 +
83265 struct device_node;
83266
83267 -extern struct irq_chip gic_arch_extn;
83268 +extern irq_chip_no_const gic_arch_extn;
83269
83270 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83271 u32 offset, struct device_node *);
83272 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83273 index c367cbd..c9b79e6 100644
83274 --- a/include/linux/jiffies.h
83275 +++ b/include/linux/jiffies.h
83276 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
83277 /*
83278 * Convert various time units to each other:
83279 */
83280 -extern unsigned int jiffies_to_msecs(const unsigned long j);
83281 -extern unsigned int jiffies_to_usecs(const unsigned long j);
83282 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83283 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83284
83285 -static inline u64 jiffies_to_nsecs(const unsigned long j)
83286 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83287 {
83288 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83289 }
83290
83291 -extern unsigned long msecs_to_jiffies(const unsigned int m);
83292 -extern unsigned long usecs_to_jiffies(const unsigned int u);
83293 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83294 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83295 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83296 extern void jiffies_to_timespec(const unsigned long jiffies,
83297 - struct timespec *value);
83298 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
83299 + struct timespec *value) __intentional_overflow(-1);
83300 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83301 extern void jiffies_to_timeval(const unsigned long jiffies,
83302 struct timeval *value);
83303
83304 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83305 index 6883e19..e854fcb 100644
83306 --- a/include/linux/kallsyms.h
83307 +++ b/include/linux/kallsyms.h
83308 @@ -15,7 +15,8 @@
83309
83310 struct module;
83311
83312 -#ifdef CONFIG_KALLSYMS
83313 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83314 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83315 /* Lookup the address for a symbol. Returns 0 if not found. */
83316 unsigned long kallsyms_lookup_name(const char *name);
83317
83318 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83319 /* Stupid that this does nothing, but I didn't create this mess. */
83320 #define __print_symbol(fmt, addr)
83321 #endif /*CONFIG_KALLSYMS*/
83322 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83323 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83324 +extern unsigned long kallsyms_lookup_name(const char *name);
83325 +extern void __print_symbol(const char *fmt, unsigned long address);
83326 +extern int sprint_backtrace(char *buffer, unsigned long address);
83327 +extern int sprint_symbol(char *buffer, unsigned long address);
83328 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83329 +const char *kallsyms_lookup(unsigned long addr,
83330 + unsigned long *symbolsize,
83331 + unsigned long *offset,
83332 + char **modname, char *namebuf);
83333 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83334 + unsigned long *symbolsize,
83335 + unsigned long *offset);
83336 +#endif
83337
83338 /* This macro allows us to keep printk typechecking */
83339 static __printf(1, 2)
83340 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83341 index 44792ee..6172f2a 100644
83342 --- a/include/linux/key-type.h
83343 +++ b/include/linux/key-type.h
83344 @@ -132,7 +132,7 @@ struct key_type {
83345 /* internal fields */
83346 struct list_head link; /* link in types list */
83347 struct lock_class_key lock_class; /* key->sem lock class */
83348 -};
83349 +} __do_const;
83350
83351 extern struct key_type key_type_keyring;
83352
83353 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83354 index e465bb1..19f605f 100644
83355 --- a/include/linux/kgdb.h
83356 +++ b/include/linux/kgdb.h
83357 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83358 extern int kgdb_io_module_registered;
83359
83360 extern atomic_t kgdb_setting_breakpoint;
83361 -extern atomic_t kgdb_cpu_doing_single_step;
83362 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83363
83364 extern struct task_struct *kgdb_usethread;
83365 extern struct task_struct *kgdb_contthread;
83366 @@ -254,7 +254,7 @@ struct kgdb_arch {
83367 void (*correct_hw_break)(void);
83368
83369 void (*enable_nmi)(bool on);
83370 -};
83371 +} __do_const;
83372
83373 /**
83374 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83375 @@ -279,7 +279,7 @@ struct kgdb_io {
83376 void (*pre_exception) (void);
83377 void (*post_exception) (void);
83378 int is_console;
83379 -};
83380 +} __do_const;
83381
83382 extern struct kgdb_arch arch_kgdb_ops;
83383
83384 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83385 index 0555cc6..40116ce 100644
83386 --- a/include/linux/kmod.h
83387 +++ b/include/linux/kmod.h
83388 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83389 * usually useless though. */
83390 extern __printf(2, 3)
83391 int __request_module(bool wait, const char *name, ...);
83392 +extern __printf(3, 4)
83393 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83394 #define request_module(mod...) __request_module(true, mod)
83395 #define request_module_nowait(mod...) __request_module(false, mod)
83396 #define try_then_request_module(x, mod...) \
83397 @@ -57,6 +59,9 @@ struct subprocess_info {
83398 struct work_struct work;
83399 struct completion *complete;
83400 char *path;
83401 +#ifdef CONFIG_GRKERNSEC
83402 + char *origpath;
83403 +#endif
83404 char **argv;
83405 char **envp;
83406 int wait;
83407 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83408 index 2d61b90..a1d0a13 100644
83409 --- a/include/linux/kobject.h
83410 +++ b/include/linux/kobject.h
83411 @@ -118,7 +118,7 @@ struct kobj_type {
83412 struct attribute **default_attrs;
83413 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83414 const void *(*namespace)(struct kobject *kobj);
83415 -};
83416 +} __do_const;
83417
83418 struct kobj_uevent_env {
83419 char *argv[3];
83420 @@ -142,6 +142,7 @@ struct kobj_attribute {
83421 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83422 const char *buf, size_t count);
83423 };
83424 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83425
83426 extern const struct sysfs_ops kobj_sysfs_ops;
83427
83428 @@ -169,7 +170,7 @@ struct kset {
83429 spinlock_t list_lock;
83430 struct kobject kobj;
83431 const struct kset_uevent_ops *uevent_ops;
83432 -};
83433 +} __randomize_layout;
83434
83435 extern void kset_init(struct kset *kset);
83436 extern int __must_check kset_register(struct kset *kset);
83437 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83438 index df32d25..fb52e27 100644
83439 --- a/include/linux/kobject_ns.h
83440 +++ b/include/linux/kobject_ns.h
83441 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83442 const void *(*netlink_ns)(struct sock *sk);
83443 const void *(*initial_ns)(void);
83444 void (*drop_ns)(void *);
83445 -};
83446 +} __do_const;
83447
83448 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83449 int kobj_ns_type_registered(enum kobj_ns_type type);
83450 diff --git a/include/linux/kref.h b/include/linux/kref.h
83451 index 484604d..0f6c5b6 100644
83452 --- a/include/linux/kref.h
83453 +++ b/include/linux/kref.h
83454 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83455 static inline int kref_sub(struct kref *kref, unsigned int count,
83456 void (*release)(struct kref *kref))
83457 {
83458 - WARN_ON(release == NULL);
83459 + BUG_ON(release == NULL);
83460
83461 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83462 release(kref);
83463 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83464 index a4c33b3..e854710 100644
83465 --- a/include/linux/kvm_host.h
83466 +++ b/include/linux/kvm_host.h
83467 @@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
83468 {
83469 }
83470 #endif
83471 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83472 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83473 struct module *module);
83474 void kvm_exit(void);
83475
83476 @@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83477 struct kvm_guest_debug *dbg);
83478 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83479
83480 -int kvm_arch_init(void *opaque);
83481 +int kvm_arch_init(const void *opaque);
83482 void kvm_arch_exit(void);
83483
83484 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83485 diff --git a/include/linux/libata.h b/include/linux/libata.h
83486 index 92abb49..e7fff2a 100644
83487 --- a/include/linux/libata.h
83488 +++ b/include/linux/libata.h
83489 @@ -976,7 +976,7 @@ struct ata_port_operations {
83490 * fields must be pointers.
83491 */
83492 const struct ata_port_operations *inherits;
83493 -};
83494 +} __do_const;
83495
83496 struct ata_port_info {
83497 unsigned long flags;
83498 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83499 index a6a42dd..6c5ebce 100644
83500 --- a/include/linux/linkage.h
83501 +++ b/include/linux/linkage.h
83502 @@ -36,6 +36,7 @@
83503 #endif
83504
83505 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83506 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83507 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83508
83509 /*
83510 diff --git a/include/linux/list.h b/include/linux/list.h
83511 index cbbb96f..602d023 100644
83512 --- a/include/linux/list.h
83513 +++ b/include/linux/list.h
83514 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
83515 extern void list_del(struct list_head *entry);
83516 #endif
83517
83518 +extern void __pax_list_add(struct list_head *new,
83519 + struct list_head *prev,
83520 + struct list_head *next);
83521 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83522 +{
83523 + __pax_list_add(new, head, head->next);
83524 +}
83525 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83526 +{
83527 + __pax_list_add(new, head->prev, head);
83528 +}
83529 +extern void pax_list_del(struct list_head *entry);
83530 +
83531 /**
83532 * list_replace - replace old entry by new one
83533 * @old : the element to be replaced
83534 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
83535 INIT_LIST_HEAD(entry);
83536 }
83537
83538 +extern void pax_list_del_init(struct list_head *entry);
83539 +
83540 /**
83541 * list_move - delete from one list and add as another's head
83542 * @list: the entry to move
83543 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83544 index 4bfde0e..d6e2e09 100644
83545 --- a/include/linux/lockref.h
83546 +++ b/include/linux/lockref.h
83547 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83548 return ((int)l->count < 0);
83549 }
83550
83551 +static inline unsigned int __lockref_read(struct lockref *lockref)
83552 +{
83553 + return lockref->count;
83554 +}
83555 +
83556 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83557 +{
83558 + lockref->count = count;
83559 +}
83560 +
83561 +static inline void __lockref_inc(struct lockref *lockref)
83562 +{
83563 +
83564 +#ifdef CONFIG_PAX_REFCOUNT
83565 + atomic_inc((atomic_t *)&lockref->count);
83566 +#else
83567 + lockref->count++;
83568 +#endif
83569 +
83570 +}
83571 +
83572 +static inline void __lockref_dec(struct lockref *lockref)
83573 +{
83574 +
83575 +#ifdef CONFIG_PAX_REFCOUNT
83576 + atomic_dec((atomic_t *)&lockref->count);
83577 +#else
83578 + lockref->count--;
83579 +#endif
83580 +
83581 +}
83582 +
83583 #endif /* __LINUX_LOCKREF_H */
83584 diff --git a/include/linux/math64.h b/include/linux/math64.h
83585 index c45c089..298841c 100644
83586 --- a/include/linux/math64.h
83587 +++ b/include/linux/math64.h
83588 @@ -15,7 +15,7 @@
83589 * This is commonly provided by 32bit archs to provide an optimized 64bit
83590 * divide.
83591 */
83592 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83593 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83594 {
83595 *remainder = dividend % divisor;
83596 return dividend / divisor;
83597 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83598 /**
83599 * div64_u64 - unsigned 64bit divide with 64bit divisor
83600 */
83601 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83602 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83603 {
83604 return dividend / divisor;
83605 }
83606 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83607 #define div64_ul(x, y) div_u64((x), (y))
83608
83609 #ifndef div_u64_rem
83610 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83611 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83612 {
83613 *remainder = do_div(dividend, divisor);
83614 return dividend;
83615 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83616 #endif
83617
83618 #ifndef div64_u64
83619 -extern u64 div64_u64(u64 dividend, u64 divisor);
83620 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83621 #endif
83622
83623 #ifndef div64_s64
83624 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83625 * divide.
83626 */
83627 #ifndef div_u64
83628 -static inline u64 div_u64(u64 dividend, u32 divisor)
83629 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83630 {
83631 u32 remainder;
83632 return div_u64_rem(dividend, divisor, &remainder);
83633 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83634 index f230a97..714c006 100644
83635 --- a/include/linux/mempolicy.h
83636 +++ b/include/linux/mempolicy.h
83637 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83638 }
83639
83640 #define vma_policy(vma) ((vma)->vm_policy)
83641 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83642 +{
83643 + vma->vm_policy = pol;
83644 +}
83645
83646 static inline void mpol_get(struct mempolicy *pol)
83647 {
83648 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83649 }
83650
83651 #define vma_policy(vma) NULL
83652 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83653 +{
83654 +}
83655
83656 static inline int
83657 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83658 diff --git a/include/linux/mm.h b/include/linux/mm.h
83659 index f952cc8..b9f6135 100644
83660 --- a/include/linux/mm.h
83661 +++ b/include/linux/mm.h
83662 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
83663 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83664 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83665 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83666 +
83667 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83668 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83669 +#endif
83670 +
83671 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83672
83673 #ifdef CONFIG_MEM_SOFT_DIRTY
83674 @@ -237,8 +242,8 @@ struct vm_operations_struct {
83675 /* called by access_process_vm when get_user_pages() fails, typically
83676 * for use by special VMAs that can switch between memory and hardware
83677 */
83678 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83679 - void *buf, int len, int write);
83680 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83681 + void *buf, size_t len, int write);
83682
83683 /* Called by the /proc/PID/maps code to ask the vma whether it
83684 * has a special name. Returning non-NULL will also cause this
83685 @@ -274,6 +279,7 @@ struct vm_operations_struct {
83686 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83687 unsigned long size, pgoff_t pgoff);
83688 };
83689 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83690
83691 struct mmu_gather;
83692 struct inode;
83693 @@ -1163,8 +1169,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83694 unsigned long *pfn);
83695 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83696 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83697 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83698 - void *buf, int len, int write);
83699 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83700 + void *buf, size_t len, int write);
83701
83702 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83703 loff_t const holebegin, loff_t const holelen)
83704 @@ -1204,9 +1210,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83705 }
83706 #endif
83707
83708 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83709 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83710 - void *buf, int len, int write);
83711 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83712 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83713 + void *buf, size_t len, int write);
83714
83715 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83716 unsigned long start, unsigned long nr_pages,
83717 @@ -1238,34 +1244,6 @@ int set_page_dirty_lock(struct page *page);
83718 int clear_page_dirty_for_io(struct page *page);
83719 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83720
83721 -/* Is the vma a continuation of the stack vma above it? */
83722 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83723 -{
83724 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83725 -}
83726 -
83727 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83728 - unsigned long addr)
83729 -{
83730 - return (vma->vm_flags & VM_GROWSDOWN) &&
83731 - (vma->vm_start == addr) &&
83732 - !vma_growsdown(vma->vm_prev, addr);
83733 -}
83734 -
83735 -/* Is the vma a continuation of the stack vma below it? */
83736 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83737 -{
83738 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83739 -}
83740 -
83741 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83742 - unsigned long addr)
83743 -{
83744 - return (vma->vm_flags & VM_GROWSUP) &&
83745 - (vma->vm_end == addr) &&
83746 - !vma_growsup(vma->vm_next, addr);
83747 -}
83748 -
83749 extern pid_t
83750 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
83751
83752 @@ -1365,6 +1343,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
83753 }
83754 #endif
83755
83756 +#ifdef CONFIG_MMU
83757 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83758 +#else
83759 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83760 +{
83761 + return __pgprot(0);
83762 +}
83763 +#endif
83764 +
83765 int vma_wants_writenotify(struct vm_area_struct *vma);
83766
83767 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
83768 @@ -1383,8 +1370,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83769 {
83770 return 0;
83771 }
83772 +
83773 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83774 + unsigned long address)
83775 +{
83776 + return 0;
83777 +}
83778 #else
83779 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83780 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83781 #endif
83782
83783 #ifdef __PAGETABLE_PMD_FOLDED
83784 @@ -1393,8 +1387,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83785 {
83786 return 0;
83787 }
83788 +
83789 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83790 + unsigned long address)
83791 +{
83792 + return 0;
83793 +}
83794 #else
83795 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83796 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83797 #endif
83798
83799 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83800 @@ -1412,11 +1413,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83801 NULL: pud_offset(pgd, address);
83802 }
83803
83804 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83805 +{
83806 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83807 + NULL: pud_offset(pgd, address);
83808 +}
83809 +
83810 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83811 {
83812 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83813 NULL: pmd_offset(pud, address);
83814 }
83815 +
83816 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83817 +{
83818 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83819 + NULL: pmd_offset(pud, address);
83820 +}
83821 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83822
83823 #if USE_SPLIT_PTE_PTLOCKS
83824 @@ -1815,7 +1828,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83825 unsigned long addr, unsigned long len,
83826 unsigned long flags, struct page **pages);
83827
83828 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83829 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83830
83831 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83832 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83833 @@ -1823,6 +1836,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83834 unsigned long len, unsigned long prot, unsigned long flags,
83835 unsigned long pgoff, unsigned long *populate);
83836 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83837 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83838
83839 #ifdef CONFIG_MMU
83840 extern int __mm_populate(unsigned long addr, unsigned long len,
83841 @@ -1851,10 +1865,11 @@ struct vm_unmapped_area_info {
83842 unsigned long high_limit;
83843 unsigned long align_mask;
83844 unsigned long align_offset;
83845 + unsigned long threadstack_offset;
83846 };
83847
83848 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83849 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83850 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83851 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83852
83853 /*
83854 * Search for an unmapped address range.
83855 @@ -1866,7 +1881,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83856 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83857 */
83858 static inline unsigned long
83859 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83860 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83861 {
83862 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83863 return unmapped_area(info);
83864 @@ -1928,6 +1943,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83865 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83866 struct vm_area_struct **pprev);
83867
83868 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83869 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83870 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83871 +
83872 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83873 NULL if none. Assume start_addr < end_addr. */
83874 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83875 @@ -1956,15 +1975,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83876 return vma;
83877 }
83878
83879 -#ifdef CONFIG_MMU
83880 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83881 -#else
83882 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83883 -{
83884 - return __pgprot(0);
83885 -}
83886 -#endif
83887 -
83888 #ifdef CONFIG_NUMA_BALANCING
83889 unsigned long change_prot_numa(struct vm_area_struct *vma,
83890 unsigned long start, unsigned long end);
83891 @@ -2016,6 +2026,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83892 static inline void vm_stat_account(struct mm_struct *mm,
83893 unsigned long flags, struct file *file, long pages)
83894 {
83895 +
83896 +#ifdef CONFIG_PAX_RANDMMAP
83897 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83898 +#endif
83899 +
83900 mm->total_vm += pages;
83901 }
83902 #endif /* CONFIG_PROC_FS */
83903 @@ -2104,7 +2119,7 @@ extern int unpoison_memory(unsigned long pfn);
83904 extern int sysctl_memory_failure_early_kill;
83905 extern int sysctl_memory_failure_recovery;
83906 extern void shake_page(struct page *p, int access);
83907 -extern atomic_long_t num_poisoned_pages;
83908 +extern atomic_long_unchecked_t num_poisoned_pages;
83909 extern int soft_offline_page(struct page *page, int flags);
83910
83911 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83912 @@ -2139,5 +2154,11 @@ void __init setup_nr_node_ids(void);
83913 static inline void setup_nr_node_ids(void) {}
83914 #endif
83915
83916 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83917 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83918 +#else
83919 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83920 +#endif
83921 +
83922 #endif /* __KERNEL__ */
83923 #endif /* _LINUX_MM_H */
83924 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83925 index 6e0b286..90d9c0d 100644
83926 --- a/include/linux/mm_types.h
83927 +++ b/include/linux/mm_types.h
83928 @@ -308,7 +308,9 @@ struct vm_area_struct {
83929 #ifdef CONFIG_NUMA
83930 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83931 #endif
83932 -};
83933 +
83934 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83935 +} __randomize_layout;
83936
83937 struct core_thread {
83938 struct task_struct *task;
83939 @@ -454,7 +456,25 @@ struct mm_struct {
83940 bool tlb_flush_pending;
83941 #endif
83942 struct uprobes_state uprobes_state;
83943 -};
83944 +
83945 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83946 + unsigned long pax_flags;
83947 +#endif
83948 +
83949 +#ifdef CONFIG_PAX_DLRESOLVE
83950 + unsigned long call_dl_resolve;
83951 +#endif
83952 +
83953 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83954 + unsigned long call_syscall;
83955 +#endif
83956 +
83957 +#ifdef CONFIG_PAX_ASLR
83958 + unsigned long delta_mmap; /* randomized offset */
83959 + unsigned long delta_stack; /* randomized offset */
83960 +#endif
83961 +
83962 +} __randomize_layout;
83963
83964 static inline void mm_init_cpumask(struct mm_struct *mm)
83965 {
83966 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83967 index c5d5278..f0b68c8 100644
83968 --- a/include/linux/mmiotrace.h
83969 +++ b/include/linux/mmiotrace.h
83970 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83971 /* Called from ioremap.c */
83972 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83973 void __iomem *addr);
83974 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83975 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83976
83977 /* For anyone to insert markers. Remember trailing newline. */
83978 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83979 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83980 {
83981 }
83982
83983 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83984 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83985 {
83986 }
83987
83988 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83989 index b21bac4..94142ca 100644
83990 --- a/include/linux/mmzone.h
83991 +++ b/include/linux/mmzone.h
83992 @@ -527,7 +527,7 @@ struct zone {
83993
83994 ZONE_PADDING(_pad3_)
83995 /* Zone statistics */
83996 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83997 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83998 } ____cacheline_internodealigned_in_smp;
83999
84000 typedef enum {
84001 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
84002 index 44eeef0..a92d3f9 100644
84003 --- a/include/linux/mod_devicetable.h
84004 +++ b/include/linux/mod_devicetable.h
84005 @@ -139,7 +139,7 @@ struct usb_device_id {
84006 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
84007 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
84008
84009 -#define HID_ANY_ID (~0)
84010 +#define HID_ANY_ID (~0U)
84011 #define HID_BUS_ANY 0xffff
84012 #define HID_GROUP_ANY 0x0000
84013
84014 @@ -475,7 +475,7 @@ struct dmi_system_id {
84015 const char *ident;
84016 struct dmi_strmatch matches[4];
84017 void *driver_data;
84018 -};
84019 +} __do_const;
84020 /*
84021 * struct dmi_device_id appears during expansion of
84022 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
84023 diff --git a/include/linux/module.h b/include/linux/module.h
84024 index 71f282a..b2387e2 100644
84025 --- a/include/linux/module.h
84026 +++ b/include/linux/module.h
84027 @@ -17,9 +17,11 @@
84028 #include <linux/moduleparam.h>
84029 #include <linux/jump_label.h>
84030 #include <linux/export.h>
84031 +#include <linux/fs.h>
84032
84033 #include <linux/percpu.h>
84034 #include <asm/module.h>
84035 +#include <asm/pgtable.h>
84036
84037 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
84038 #define MODULE_SIG_STRING "~Module signature appended~\n"
84039 @@ -42,7 +44,7 @@ struct module_kobject {
84040 struct kobject *drivers_dir;
84041 struct module_param_attrs *mp;
84042 struct completion *kobj_completion;
84043 -};
84044 +} __randomize_layout;
84045
84046 struct module_attribute {
84047 struct attribute attr;
84048 @@ -54,12 +56,13 @@ struct module_attribute {
84049 int (*test)(struct module *);
84050 void (*free)(struct module *);
84051 };
84052 +typedef struct module_attribute __no_const module_attribute_no_const;
84053
84054 struct module_version_attribute {
84055 struct module_attribute mattr;
84056 const char *module_name;
84057 const char *version;
84058 -} __attribute__ ((__aligned__(sizeof(void *))));
84059 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
84060
84061 extern ssize_t __modver_version_show(struct module_attribute *,
84062 struct module_kobject *, char *);
84063 @@ -235,7 +238,7 @@ struct module {
84064
84065 /* Sysfs stuff. */
84066 struct module_kobject mkobj;
84067 - struct module_attribute *modinfo_attrs;
84068 + module_attribute_no_const *modinfo_attrs;
84069 const char *version;
84070 const char *srcversion;
84071 struct kobject *holders_dir;
84072 @@ -284,19 +287,16 @@ struct module {
84073 int (*init)(void);
84074
84075 /* If this is non-NULL, vfree after init() returns */
84076 - void *module_init;
84077 + void *module_init_rx, *module_init_rw;
84078
84079 /* Here is the actual code + data, vfree'd on unload. */
84080 - void *module_core;
84081 + void *module_core_rx, *module_core_rw;
84082
84083 /* Here are the sizes of the init and core sections */
84084 - unsigned int init_size, core_size;
84085 + unsigned int init_size_rw, core_size_rw;
84086
84087 /* The size of the executable code in each section. */
84088 - unsigned int init_text_size, core_text_size;
84089 -
84090 - /* Size of RO sections of the module (text+rodata) */
84091 - unsigned int init_ro_size, core_ro_size;
84092 + unsigned int init_size_rx, core_size_rx;
84093
84094 /* Arch-specific module values */
84095 struct mod_arch_specific arch;
84096 @@ -352,6 +352,10 @@ struct module {
84097 #ifdef CONFIG_EVENT_TRACING
84098 struct ftrace_event_call **trace_events;
84099 unsigned int num_trace_events;
84100 + struct file_operations trace_id;
84101 + struct file_operations trace_enable;
84102 + struct file_operations trace_format;
84103 + struct file_operations trace_filter;
84104 #endif
84105 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
84106 unsigned int num_ftrace_callsites;
84107 @@ -375,7 +379,7 @@ struct module {
84108 ctor_fn_t *ctors;
84109 unsigned int num_ctors;
84110 #endif
84111 -};
84112 +} __randomize_layout;
84113 #ifndef MODULE_ARCH_INIT
84114 #define MODULE_ARCH_INIT {}
84115 #endif
84116 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
84117 bool is_module_percpu_address(unsigned long addr);
84118 bool is_module_text_address(unsigned long addr);
84119
84120 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
84121 +{
84122 +
84123 +#ifdef CONFIG_PAX_KERNEXEC
84124 + if (ktla_ktva(addr) >= (unsigned long)start &&
84125 + ktla_ktva(addr) < (unsigned long)start + size)
84126 + return 1;
84127 +#endif
84128 +
84129 + return ((void *)addr >= start && (void *)addr < start + size);
84130 +}
84131 +
84132 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
84133 +{
84134 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
84135 +}
84136 +
84137 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
84138 +{
84139 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
84140 +}
84141 +
84142 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
84143 +{
84144 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
84145 +}
84146 +
84147 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
84148 +{
84149 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
84150 +}
84151 +
84152 static inline bool within_module_core(unsigned long addr,
84153 const struct module *mod)
84154 {
84155 - return (unsigned long)mod->module_core <= addr &&
84156 - addr < (unsigned long)mod->module_core + mod->core_size;
84157 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
84158 }
84159
84160 static inline bool within_module_init(unsigned long addr,
84161 const struct module *mod)
84162 {
84163 - return (unsigned long)mod->module_init <= addr &&
84164 - addr < (unsigned long)mod->module_init + mod->init_size;
84165 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
84166 }
84167
84168 static inline bool within_module(unsigned long addr, const struct module *mod)
84169 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
84170 index 7eeb9bb..68f37e0 100644
84171 --- a/include/linux/moduleloader.h
84172 +++ b/include/linux/moduleloader.h
84173 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
84174 sections. Returns NULL on failure. */
84175 void *module_alloc(unsigned long size);
84176
84177 +#ifdef CONFIG_PAX_KERNEXEC
84178 +void *module_alloc_exec(unsigned long size);
84179 +#else
84180 +#define module_alloc_exec(x) module_alloc(x)
84181 +#endif
84182 +
84183 /* Free memory returned from module_alloc. */
84184 void module_free(struct module *mod, void *module_region);
84185
84186 +#ifdef CONFIG_PAX_KERNEXEC
84187 +void module_free_exec(struct module *mod, void *module_region);
84188 +#else
84189 +#define module_free_exec(x, y) module_free((x), (y))
84190 +#endif
84191 +
84192 /*
84193 * Apply the given relocation to the (simplified) ELF. Return -error
84194 * or 0.
84195 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84196 unsigned int relsec,
84197 struct module *me)
84198 {
84199 +#ifdef CONFIG_MODULES
84200 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84201 module_name(me));
84202 +#endif
84203 return -ENOEXEC;
84204 }
84205 #endif
84206 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84207 unsigned int relsec,
84208 struct module *me)
84209 {
84210 +#ifdef CONFIG_MODULES
84211 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84212 module_name(me));
84213 +#endif
84214 return -ENOEXEC;
84215 }
84216 #endif
84217 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84218 index 494f99e..5059f63 100644
84219 --- a/include/linux/moduleparam.h
84220 +++ b/include/linux/moduleparam.h
84221 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
84222 * @len is usually just sizeof(string).
84223 */
84224 #define module_param_string(name, string, len, perm) \
84225 - static const struct kparam_string __param_string_##name \
84226 + static const struct kparam_string __param_string_##name __used \
84227 = { len, string }; \
84228 __module_param_call(MODULE_PARAM_PREFIX, name, \
84229 &param_ops_string, \
84230 @@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84231 */
84232 #define module_param_array_named(name, array, type, nump, perm) \
84233 param_check_##type(name, &(array)[0]); \
84234 - static const struct kparam_array __param_arr_##name \
84235 + static const struct kparam_array __param_arr_##name __used \
84236 = { .max = ARRAY_SIZE(array), .num = nump, \
84237 .ops = &param_ops_##type, \
84238 .elemsize = sizeof(array[0]), .elem = array }; \
84239 diff --git a/include/linux/mount.h b/include/linux/mount.h
84240 index 9262e4b..0a45f98 100644
84241 --- a/include/linux/mount.h
84242 +++ b/include/linux/mount.h
84243 @@ -66,7 +66,7 @@ struct vfsmount {
84244 struct dentry *mnt_root; /* root of the mounted tree */
84245 struct super_block *mnt_sb; /* pointer to superblock */
84246 int mnt_flags;
84247 -};
84248 +} __randomize_layout;
84249
84250 struct file; /* forward dec */
84251 struct path;
84252 diff --git a/include/linux/namei.h b/include/linux/namei.h
84253 index 492de72..1bddcd4 100644
84254 --- a/include/linux/namei.h
84255 +++ b/include/linux/namei.h
84256 @@ -19,7 +19,7 @@ struct nameidata {
84257 unsigned seq, m_seq;
84258 int last_type;
84259 unsigned depth;
84260 - char *saved_names[MAX_NESTED_LINKS + 1];
84261 + const char *saved_names[MAX_NESTED_LINKS + 1];
84262 };
84263
84264 /*
84265 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84266
84267 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84268
84269 -static inline void nd_set_link(struct nameidata *nd, char *path)
84270 +static inline void nd_set_link(struct nameidata *nd, const char *path)
84271 {
84272 nd->saved_names[nd->depth] = path;
84273 }
84274
84275 -static inline char *nd_get_link(struct nameidata *nd)
84276 +static inline const char *nd_get_link(const struct nameidata *nd)
84277 {
84278 return nd->saved_names[nd->depth];
84279 }
84280 diff --git a/include/linux/net.h b/include/linux/net.h
84281 index 17d8339..81656c0 100644
84282 --- a/include/linux/net.h
84283 +++ b/include/linux/net.h
84284 @@ -192,7 +192,7 @@ struct net_proto_family {
84285 int (*create)(struct net *net, struct socket *sock,
84286 int protocol, int kern);
84287 struct module *owner;
84288 -};
84289 +} __do_const;
84290
84291 struct iovec;
84292 struct kvec;
84293 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84294 index c8e388e..5d8cd9b 100644
84295 --- a/include/linux/netdevice.h
84296 +++ b/include/linux/netdevice.h
84297 @@ -1147,6 +1147,7 @@ struct net_device_ops {
84298 void *priv);
84299 int (*ndo_get_lock_subclass)(struct net_device *dev);
84300 };
84301 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84302
84303 /**
84304 * enum net_device_priv_flags - &struct net_device priv_flags
84305 @@ -1485,10 +1486,10 @@ struct net_device {
84306
84307 struct net_device_stats stats;
84308
84309 - atomic_long_t rx_dropped;
84310 - atomic_long_t tx_dropped;
84311 + atomic_long_unchecked_t rx_dropped;
84312 + atomic_long_unchecked_t tx_dropped;
84313
84314 - atomic_t carrier_changes;
84315 + atomic_unchecked_t carrier_changes;
84316
84317 #ifdef CONFIG_WIRELESS_EXT
84318 const struct iw_handler_def * wireless_handlers;
84319 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84320 index 2517ece..0bbfcfb 100644
84321 --- a/include/linux/netfilter.h
84322 +++ b/include/linux/netfilter.h
84323 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84324 #endif
84325 /* Use the module struct to lock set/get code in place */
84326 struct module *owner;
84327 -};
84328 +} __do_const;
84329
84330 /* Function to register/unregister hook points. */
84331 int nf_register_hook(struct nf_hook_ops *reg);
84332 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84333 index e955d47..04a5338 100644
84334 --- a/include/linux/netfilter/nfnetlink.h
84335 +++ b/include/linux/netfilter/nfnetlink.h
84336 @@ -19,7 +19,7 @@ struct nfnl_callback {
84337 const struct nlattr * const cda[]);
84338 const struct nla_policy *policy; /* netlink attribute policy */
84339 const u_int16_t attr_count; /* number of nlattr's */
84340 -};
84341 +} __do_const;
84342
84343 struct nfnetlink_subsystem {
84344 const char *name;
84345 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84346 new file mode 100644
84347 index 0000000..33f4af8
84348 --- /dev/null
84349 +++ b/include/linux/netfilter/xt_gradm.h
84350 @@ -0,0 +1,9 @@
84351 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84352 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84353 +
84354 +struct xt_gradm_mtinfo {
84355 + __u16 flags;
84356 + __u16 invflags;
84357 +};
84358 +
84359 +#endif
84360 diff --git a/include/linux/nls.h b/include/linux/nls.h
84361 index 520681b..2b7fabb 100644
84362 --- a/include/linux/nls.h
84363 +++ b/include/linux/nls.h
84364 @@ -31,7 +31,7 @@ struct nls_table {
84365 const unsigned char *charset2upper;
84366 struct module *owner;
84367 struct nls_table *next;
84368 -};
84369 +} __do_const;
84370
84371 /* this value hold the maximum octet of charset */
84372 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84373 @@ -46,7 +46,7 @@ enum utf16_endian {
84374 /* nls_base.c */
84375 extern int __register_nls(struct nls_table *, struct module *);
84376 extern int unregister_nls(struct nls_table *);
84377 -extern struct nls_table *load_nls(char *);
84378 +extern struct nls_table *load_nls(const char *);
84379 extern void unload_nls(struct nls_table *);
84380 extern struct nls_table *load_nls_default(void);
84381 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84382 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84383 index d14a4c3..a078786 100644
84384 --- a/include/linux/notifier.h
84385 +++ b/include/linux/notifier.h
84386 @@ -54,7 +54,8 @@ struct notifier_block {
84387 notifier_fn_t notifier_call;
84388 struct notifier_block __rcu *next;
84389 int priority;
84390 -};
84391 +} __do_const;
84392 +typedef struct notifier_block __no_const notifier_block_no_const;
84393
84394 struct atomic_notifier_head {
84395 spinlock_t lock;
84396 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84397 index b2a0f15..4d7da32 100644
84398 --- a/include/linux/oprofile.h
84399 +++ b/include/linux/oprofile.h
84400 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84401 int oprofilefs_create_ro_ulong(struct dentry * root,
84402 char const * name, ulong * val);
84403
84404 -/** Create a file for read-only access to an atomic_t. */
84405 +/** Create a file for read-only access to an atomic_unchecked_t. */
84406 int oprofilefs_create_ro_atomic(struct dentry * root,
84407 - char const * name, atomic_t * val);
84408 + char const * name, atomic_unchecked_t * val);
84409
84410 /** create a directory */
84411 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84412 diff --git a/include/linux/padata.h b/include/linux/padata.h
84413 index 4386946..f50c615 100644
84414 --- a/include/linux/padata.h
84415 +++ b/include/linux/padata.h
84416 @@ -129,7 +129,7 @@ struct parallel_data {
84417 struct padata_serial_queue __percpu *squeue;
84418 atomic_t reorder_objects;
84419 atomic_t refcnt;
84420 - atomic_t seq_nr;
84421 + atomic_unchecked_t seq_nr;
84422 struct padata_cpumask cpumask;
84423 spinlock_t lock ____cacheline_aligned;
84424 unsigned int processed;
84425 diff --git a/include/linux/path.h b/include/linux/path.h
84426 index d137218..be0c176 100644
84427 --- a/include/linux/path.h
84428 +++ b/include/linux/path.h
84429 @@ -1,13 +1,15 @@
84430 #ifndef _LINUX_PATH_H
84431 #define _LINUX_PATH_H
84432
84433 +#include <linux/compiler.h>
84434 +
84435 struct dentry;
84436 struct vfsmount;
84437
84438 struct path {
84439 struct vfsmount *mnt;
84440 struct dentry *dentry;
84441 -};
84442 +} __randomize_layout;
84443
84444 extern void path_get(const struct path *);
84445 extern void path_put(const struct path *);
84446 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84447 index 5f2e559..7d59314 100644
84448 --- a/include/linux/pci_hotplug.h
84449 +++ b/include/linux/pci_hotplug.h
84450 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84451 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84452 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84453 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84454 -};
84455 +} __do_const;
84456 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84457
84458 /**
84459 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84460 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84461 index 707617a..28a2e7e 100644
84462 --- a/include/linux/perf_event.h
84463 +++ b/include/linux/perf_event.h
84464 @@ -339,8 +339,8 @@ struct perf_event {
84465
84466 enum perf_event_active_state state;
84467 unsigned int attach_state;
84468 - local64_t count;
84469 - atomic64_t child_count;
84470 + local64_t count; /* PaX: fix it one day */
84471 + atomic64_unchecked_t child_count;
84472
84473 /*
84474 * These are the total time in nanoseconds that the event
84475 @@ -391,8 +391,8 @@ struct perf_event {
84476 * These accumulate total time (in nanoseconds) that children
84477 * events have been enabled and running, respectively.
84478 */
84479 - atomic64_t child_total_time_enabled;
84480 - atomic64_t child_total_time_running;
84481 + atomic64_unchecked_t child_total_time_enabled;
84482 + atomic64_unchecked_t child_total_time_running;
84483
84484 /*
84485 * Protect attach/detach and child_list:
84486 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84487 entry->ip[entry->nr++] = ip;
84488 }
84489
84490 -extern int sysctl_perf_event_paranoid;
84491 +extern int sysctl_perf_event_legitimately_concerned;
84492 extern int sysctl_perf_event_mlock;
84493 extern int sysctl_perf_event_sample_rate;
84494 extern int sysctl_perf_cpu_time_max_percent;
84495 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84496 loff_t *ppos);
84497
84498
84499 +static inline bool perf_paranoid_any(void)
84500 +{
84501 + return sysctl_perf_event_legitimately_concerned > 2;
84502 +}
84503 +
84504 static inline bool perf_paranoid_tracepoint_raw(void)
84505 {
84506 - return sysctl_perf_event_paranoid > -1;
84507 + return sysctl_perf_event_legitimately_concerned > -1;
84508 }
84509
84510 static inline bool perf_paranoid_cpu(void)
84511 {
84512 - return sysctl_perf_event_paranoid > 0;
84513 + return sysctl_perf_event_legitimately_concerned > 0;
84514 }
84515
84516 static inline bool perf_paranoid_kernel(void)
84517 {
84518 - return sysctl_perf_event_paranoid > 1;
84519 + return sysctl_perf_event_legitimately_concerned > 1;
84520 }
84521
84522 extern void perf_event_init(void);
84523 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
84524 struct device_attribute attr;
84525 u64 id;
84526 const char *event_str;
84527 -};
84528 +} __do_const;
84529
84530 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84531 static struct perf_pmu_events_attr _var = { \
84532 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84533 index 1997ffc..4f1f44d 100644
84534 --- a/include/linux/pid_namespace.h
84535 +++ b/include/linux/pid_namespace.h
84536 @@ -44,7 +44,7 @@ struct pid_namespace {
84537 int hide_pid;
84538 int reboot; /* group exit code if this pidns was rebooted */
84539 unsigned int proc_inum;
84540 -};
84541 +} __randomize_layout;
84542
84543 extern struct pid_namespace init_pid_ns;
84544
84545 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84546 index eb8b8ac..62649e1 100644
84547 --- a/include/linux/pipe_fs_i.h
84548 +++ b/include/linux/pipe_fs_i.h
84549 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84550 struct mutex mutex;
84551 wait_queue_head_t wait;
84552 unsigned int nrbufs, curbuf, buffers;
84553 - unsigned int readers;
84554 - unsigned int writers;
84555 - unsigned int files;
84556 - unsigned int waiting_writers;
84557 + atomic_t readers;
84558 + atomic_t writers;
84559 + atomic_t files;
84560 + atomic_t waiting_writers;
84561 unsigned int r_counter;
84562 unsigned int w_counter;
84563 struct page *tmp_page;
84564 diff --git a/include/linux/pm.h b/include/linux/pm.h
84565 index 72c0fe0..26918ed 100644
84566 --- a/include/linux/pm.h
84567 +++ b/include/linux/pm.h
84568 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
84569 struct dev_pm_domain {
84570 struct dev_pm_ops ops;
84571 };
84572 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84573
84574 /*
84575 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84576 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84577 index ebc4c76..7fab7b0 100644
84578 --- a/include/linux/pm_domain.h
84579 +++ b/include/linux/pm_domain.h
84580 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
84581 int (*thaw_early)(struct device *dev);
84582 int (*thaw)(struct device *dev);
84583 bool (*active_wakeup)(struct device *dev);
84584 -};
84585 +} __no_const;
84586
84587 struct gpd_cpu_data {
84588 unsigned int saved_exit_latency;
84589 - struct cpuidle_state *idle_state;
84590 + cpuidle_state_no_const *idle_state;
84591 };
84592
84593 struct generic_pm_domain {
84594 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84595 index 367f49b..d2f5a14 100644
84596 --- a/include/linux/pm_runtime.h
84597 +++ b/include/linux/pm_runtime.h
84598 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84599
84600 static inline void pm_runtime_mark_last_busy(struct device *dev)
84601 {
84602 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84603 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84604 }
84605
84606 #else /* !CONFIG_PM_RUNTIME */
84607 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84608 index 195aafc..49a7bc2 100644
84609 --- a/include/linux/pnp.h
84610 +++ b/include/linux/pnp.h
84611 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84612 struct pnp_fixup {
84613 char id[7];
84614 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84615 -};
84616 +} __do_const;
84617
84618 /* config parameters */
84619 #define PNP_CONFIG_NORMAL 0x0001
84620 diff --git a/include/linux/poison.h b/include/linux/poison.h
84621 index 2110a81..13a11bb 100644
84622 --- a/include/linux/poison.h
84623 +++ b/include/linux/poison.h
84624 @@ -19,8 +19,8 @@
84625 * under normal circumstances, used to verify that nobody uses
84626 * non-initialized list entries.
84627 */
84628 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84629 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84630 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84631 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84632
84633 /********** include/linux/timer.h **********/
84634 /*
84635 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84636 index d8b187c3..9a9257a 100644
84637 --- a/include/linux/power/smartreflex.h
84638 +++ b/include/linux/power/smartreflex.h
84639 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84640 int (*notify)(struct omap_sr *sr, u32 status);
84641 u8 notify_flags;
84642 u8 class_type;
84643 -};
84644 +} __do_const;
84645
84646 /**
84647 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84648 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84649 index 4ea1d37..80f4b33 100644
84650 --- a/include/linux/ppp-comp.h
84651 +++ b/include/linux/ppp-comp.h
84652 @@ -84,7 +84,7 @@ struct compressor {
84653 struct module *owner;
84654 /* Extra skb space needed by the compressor algorithm */
84655 unsigned int comp_extra;
84656 -};
84657 +} __do_const;
84658
84659 /*
84660 * The return value from decompress routine is the length of the
84661 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84662 index de83b4e..c4b997d 100644
84663 --- a/include/linux/preempt.h
84664 +++ b/include/linux/preempt.h
84665 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84666 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84667 #endif
84668
84669 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84670 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84671 +
84672 #define __preempt_count_inc() __preempt_count_add(1)
84673 #define __preempt_count_dec() __preempt_count_sub(1)
84674
84675 #define preempt_count_inc() preempt_count_add(1)
84676 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84677 #define preempt_count_dec() preempt_count_sub(1)
84678 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84679
84680 #ifdef CONFIG_PREEMPT_COUNT
84681
84682 @@ -41,6 +46,12 @@ do { \
84683 barrier(); \
84684 } while (0)
84685
84686 +#define raw_preempt_disable() \
84687 +do { \
84688 + raw_preempt_count_inc(); \
84689 + barrier(); \
84690 +} while (0)
84691 +
84692 #define sched_preempt_enable_no_resched() \
84693 do { \
84694 barrier(); \
84695 @@ -49,6 +60,12 @@ do { \
84696
84697 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84698
84699 +#define raw_preempt_enable_no_resched() \
84700 +do { \
84701 + barrier(); \
84702 + raw_preempt_count_dec(); \
84703 +} while (0)
84704 +
84705 #ifdef CONFIG_PREEMPT
84706 #define preempt_enable() \
84707 do { \
84708 @@ -113,8 +130,10 @@ do { \
84709 * region.
84710 */
84711 #define preempt_disable() barrier()
84712 +#define raw_preempt_disable() barrier()
84713 #define sched_preempt_enable_no_resched() barrier()
84714 #define preempt_enable_no_resched() barrier()
84715 +#define raw_preempt_enable_no_resched() barrier()
84716 #define preempt_enable() barrier()
84717 #define preempt_check_resched() do { } while (0)
84718
84719 @@ -128,11 +147,13 @@ do { \
84720 /*
84721 * Modules have no business playing preemption tricks.
84722 */
84723 +#ifndef CONFIG_PAX_KERNEXEC
84724 #undef sched_preempt_enable_no_resched
84725 #undef preempt_enable_no_resched
84726 #undef preempt_enable_no_resched_notrace
84727 #undef preempt_check_resched
84728 #endif
84729 +#endif
84730
84731 #define preempt_set_need_resched() \
84732 do { \
84733 diff --git a/include/linux/printk.h b/include/linux/printk.h
84734 index d78125f..7f36596 100644
84735 --- a/include/linux/printk.h
84736 +++ b/include/linux/printk.h
84737 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84738 void early_printk(const char *s, ...) { }
84739 #endif
84740
84741 +extern int kptr_restrict;
84742 +
84743 #ifdef CONFIG_PRINTK
84744 asmlinkage __printf(5, 0)
84745 int vprintk_emit(int facility, int level,
84746 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84747
84748 extern int printk_delay_msec;
84749 extern int dmesg_restrict;
84750 -extern int kptr_restrict;
84751
84752 extern void wake_up_klogd(void);
84753
84754 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84755 index 9d117f6..d832b31 100644
84756 --- a/include/linux/proc_fs.h
84757 +++ b/include/linux/proc_fs.h
84758 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84759 extern struct proc_dir_entry *proc_symlink(const char *,
84760 struct proc_dir_entry *, const char *);
84761 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84762 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84763 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84764 struct proc_dir_entry *, void *);
84765 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84766 + struct proc_dir_entry *, void *);
84767 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84768 struct proc_dir_entry *);
84769
84770 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84771 return proc_create_data(name, mode, parent, proc_fops, NULL);
84772 }
84773
84774 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84775 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84776 +{
84777 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84778 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84779 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84780 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84781 +#else
84782 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84783 +#endif
84784 +}
84785 +
84786 +
84787 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84788 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84789 extern void *PDE_DATA(const struct inode *);
84790 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84791 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84792 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84793 struct proc_dir_entry *parent) {return NULL;}
84794 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84795 + struct proc_dir_entry *parent) { return NULL; }
84796 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84797 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84798 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84799 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84800 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84801 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84802 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84803 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
84804 static inline struct proc_dir_entry *proc_net_mkdir(
84805 struct net *net, const char *name, struct proc_dir_entry *parent)
84806 {
84807 - return proc_mkdir_data(name, 0, parent, net);
84808 + return proc_mkdir_data_restrict(name, 0, parent, net);
84809 }
84810
84811 #endif /* _LINUX_PROC_FS_H */
84812 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84813 index 34a1e10..70f6bde 100644
84814 --- a/include/linux/proc_ns.h
84815 +++ b/include/linux/proc_ns.h
84816 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84817 void (*put)(void *ns);
84818 int (*install)(struct nsproxy *nsproxy, void *ns);
84819 unsigned int (*inum)(void *ns);
84820 -};
84821 +} __do_const __randomize_layout;
84822
84823 struct proc_ns {
84824 void *ns;
84825 diff --git a/include/linux/quota.h b/include/linux/quota.h
84826 index 80d345a..9e89a9a 100644
84827 --- a/include/linux/quota.h
84828 +++ b/include/linux/quota.h
84829 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84830
84831 extern bool qid_eq(struct kqid left, struct kqid right);
84832 extern bool qid_lt(struct kqid left, struct kqid right);
84833 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84834 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84835 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84836 extern bool qid_valid(struct kqid qid);
84837
84838 diff --git a/include/linux/random.h b/include/linux/random.h
84839 index 57fbbff..2170304 100644
84840 --- a/include/linux/random.h
84841 +++ b/include/linux/random.h
84842 @@ -9,9 +9,19 @@
84843 #include <uapi/linux/random.h>
84844
84845 extern void add_device_randomness(const void *, unsigned int);
84846 +
84847 +static inline void add_latent_entropy(void)
84848 +{
84849 +
84850 +#ifdef LATENT_ENTROPY_PLUGIN
84851 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84852 +#endif
84853 +
84854 +}
84855 +
84856 extern void add_input_randomness(unsigned int type, unsigned int code,
84857 - unsigned int value);
84858 -extern void add_interrupt_randomness(int irq, int irq_flags);
84859 + unsigned int value) __latent_entropy;
84860 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84861
84862 extern void get_random_bytes(void *buf, int nbytes);
84863 extern void get_random_bytes_arch(void *buf, int nbytes);
84864 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84865 extern const struct file_operations random_fops, urandom_fops;
84866 #endif
84867
84868 -unsigned int get_random_int(void);
84869 +unsigned int __intentional_overflow(-1) get_random_int(void);
84870 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84871
84872 -u32 prandom_u32(void);
84873 +u32 prandom_u32(void) __intentional_overflow(-1);
84874 void prandom_bytes(void *buf, int nbytes);
84875 void prandom_seed(u32 seed);
84876 void prandom_reseed_late(void);
84877 @@ -37,6 +47,11 @@ struct rnd_state {
84878 u32 prandom_u32_state(struct rnd_state *state);
84879 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84880
84881 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84882 +{
84883 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84884 +}
84885 +
84886 /**
84887 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84888 * @ep_ro: right open interval endpoint
84889 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84890 *
84891 * Returns: pseudo-random number in interval [0, ep_ro)
84892 */
84893 -static inline u32 prandom_u32_max(u32 ep_ro)
84894 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84895 {
84896 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84897 }
84898 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84899 index fea49b5..2ac22bb 100644
84900 --- a/include/linux/rbtree_augmented.h
84901 +++ b/include/linux/rbtree_augmented.h
84902 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84903 old->rbaugmented = rbcompute(old); \
84904 } \
84905 rbstatic const struct rb_augment_callbacks rbname = { \
84906 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84907 + .propagate = rbname ## _propagate, \
84908 + .copy = rbname ## _copy, \
84909 + .rotate = rbname ## _rotate \
84910 };
84911
84912
84913 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84914 index 372ad5e..d4373f8 100644
84915 --- a/include/linux/rculist.h
84916 +++ b/include/linux/rculist.h
84917 @@ -29,8 +29,8 @@
84918 */
84919 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84920 {
84921 - ACCESS_ONCE(list->next) = list;
84922 - ACCESS_ONCE(list->prev) = list;
84923 + ACCESS_ONCE_RW(list->next) = list;
84924 + ACCESS_ONCE_RW(list->prev) = list;
84925 }
84926
84927 /*
84928 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84929 struct list_head *prev, struct list_head *next);
84930 #endif
84931
84932 +void __pax_list_add_rcu(struct list_head *new,
84933 + struct list_head *prev, struct list_head *next);
84934 +
84935 /**
84936 * list_add_rcu - add a new entry to rcu-protected list
84937 * @new: new entry to be added
84938 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84939 __list_add_rcu(new, head, head->next);
84940 }
84941
84942 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84943 +{
84944 + __pax_list_add_rcu(new, head, head->next);
84945 +}
84946 +
84947 /**
84948 * list_add_tail_rcu - add a new entry to rcu-protected list
84949 * @new: new entry to be added
84950 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84951 __list_add_rcu(new, head->prev, head);
84952 }
84953
84954 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84955 + struct list_head *head)
84956 +{
84957 + __pax_list_add_rcu(new, head->prev, head);
84958 +}
84959 +
84960 /**
84961 * list_del_rcu - deletes entry from list without re-initialization
84962 * @entry: the element to delete from the list.
84963 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84964 entry->prev = LIST_POISON2;
84965 }
84966
84967 +extern void pax_list_del_rcu(struct list_head *entry);
84968 +
84969 /**
84970 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84971 * @n: the element to delete from the hash list.
84972 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84973 index 48bf152..d38b785 100644
84974 --- a/include/linux/reboot.h
84975 +++ b/include/linux/reboot.h
84976 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
84977 */
84978
84979 extern void migrate_to_reboot_cpu(void);
84980 -extern void machine_restart(char *cmd);
84981 -extern void machine_halt(void);
84982 -extern void machine_power_off(void);
84983 +extern void machine_restart(char *cmd) __noreturn;
84984 +extern void machine_halt(void) __noreturn;
84985 +extern void machine_power_off(void) __noreturn;
84986
84987 extern void machine_shutdown(void);
84988 struct pt_regs;
84989 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84990 */
84991
84992 extern void kernel_restart_prepare(char *cmd);
84993 -extern void kernel_restart(char *cmd);
84994 -extern void kernel_halt(void);
84995 -extern void kernel_power_off(void);
84996 +extern void kernel_restart(char *cmd) __noreturn;
84997 +extern void kernel_halt(void) __noreturn;
84998 +extern void kernel_power_off(void) __noreturn;
84999
85000 extern int C_A_D; /* for sysctl */
85001 void ctrl_alt_del(void);
85002 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
85003 * Emergency restart, callable from an interrupt handler.
85004 */
85005
85006 -extern void emergency_restart(void);
85007 +extern void emergency_restart(void) __noreturn;
85008 #include <asm/emergency-restart.h>
85009
85010 #endif /* _LINUX_REBOOT_H */
85011 diff --git a/include/linux/regset.h b/include/linux/regset.h
85012 index 8e0c9fe..ac4d221 100644
85013 --- a/include/linux/regset.h
85014 +++ b/include/linux/regset.h
85015 @@ -161,7 +161,8 @@ struct user_regset {
85016 unsigned int align;
85017 unsigned int bias;
85018 unsigned int core_note_type;
85019 -};
85020 +} __do_const;
85021 +typedef struct user_regset __no_const user_regset_no_const;
85022
85023 /**
85024 * struct user_regset_view - available regsets
85025 diff --git a/include/linux/relay.h b/include/linux/relay.h
85026 index d7c8359..818daf5 100644
85027 --- a/include/linux/relay.h
85028 +++ b/include/linux/relay.h
85029 @@ -157,7 +157,7 @@ struct rchan_callbacks
85030 * The callback should return 0 if successful, negative if not.
85031 */
85032 int (*remove_buf_file)(struct dentry *dentry);
85033 -};
85034 +} __no_const;
85035
85036 /*
85037 * CONFIG_RELAY kernel API, kernel/relay.c
85038 diff --git a/include/linux/rio.h b/include/linux/rio.h
85039 index 6bda06f..bf39a9b 100644
85040 --- a/include/linux/rio.h
85041 +++ b/include/linux/rio.h
85042 @@ -358,7 +358,7 @@ struct rio_ops {
85043 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
85044 u64 rstart, u32 size, u32 flags);
85045 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
85046 -};
85047 +} __no_const;
85048
85049 #define RIO_RESOURCE_MEM 0x00000100
85050 #define RIO_RESOURCE_DOORBELL 0x00000200
85051 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
85052 index be57450..31cf65e 100644
85053 --- a/include/linux/rmap.h
85054 +++ b/include/linux/rmap.h
85055 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
85056 void anon_vma_init(void); /* create anon_vma_cachep */
85057 int anon_vma_prepare(struct vm_area_struct *);
85058 void unlink_anon_vmas(struct vm_area_struct *);
85059 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
85060 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
85061 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
85062 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
85063
85064 static inline void anon_vma_merge(struct vm_area_struct *vma,
85065 struct vm_area_struct *next)
85066 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
85067 index ed8f9e7..999bc96 100644
85068 --- a/include/linux/scatterlist.h
85069 +++ b/include/linux/scatterlist.h
85070 @@ -1,6 +1,7 @@
85071 #ifndef _LINUX_SCATTERLIST_H
85072 #define _LINUX_SCATTERLIST_H
85073
85074 +#include <linux/sched.h>
85075 #include <linux/string.h>
85076 #include <linux/bug.h>
85077 #include <linux/mm.h>
85078 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
85079 #ifdef CONFIG_DEBUG_SG
85080 BUG_ON(!virt_addr_valid(buf));
85081 #endif
85082 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85083 + if (object_starts_on_stack(buf)) {
85084 + void *adjbuf = buf - current->stack + current->lowmem_stack;
85085 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
85086 + } else
85087 +#endif
85088 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
85089 }
85090
85091 diff --git a/include/linux/sched.h b/include/linux/sched.h
85092 index 2b1d9e9..7fd5067 100644
85093 --- a/include/linux/sched.h
85094 +++ b/include/linux/sched.h
85095 @@ -132,6 +132,7 @@ struct fs_struct;
85096 struct perf_event_context;
85097 struct blk_plug;
85098 struct filename;
85099 +struct linux_binprm;
85100
85101 #define VMACACHE_BITS 2
85102 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
85103 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
85104 extern int in_sched_functions(unsigned long addr);
85105
85106 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
85107 -extern signed long schedule_timeout(signed long timeout);
85108 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
85109 extern signed long schedule_timeout_interruptible(signed long timeout);
85110 extern signed long schedule_timeout_killable(signed long timeout);
85111 extern signed long schedule_timeout_uninterruptible(signed long timeout);
85112 @@ -385,6 +386,19 @@ struct nsproxy;
85113 struct user_namespace;
85114
85115 #ifdef CONFIG_MMU
85116 +
85117 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
85118 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
85119 +#else
85120 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
85121 +{
85122 + return 0;
85123 +}
85124 +#endif
85125 +
85126 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
85127 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
85128 +
85129 extern void arch_pick_mmap_layout(struct mm_struct *mm);
85130 extern unsigned long
85131 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
85132 @@ -682,6 +696,17 @@ struct signal_struct {
85133 #ifdef CONFIG_TASKSTATS
85134 struct taskstats *stats;
85135 #endif
85136 +
85137 +#ifdef CONFIG_GRKERNSEC
85138 + u32 curr_ip;
85139 + u32 saved_ip;
85140 + u32 gr_saddr;
85141 + u32 gr_daddr;
85142 + u16 gr_sport;
85143 + u16 gr_dport;
85144 + u8 used_accept:1;
85145 +#endif
85146 +
85147 #ifdef CONFIG_AUDIT
85148 unsigned audit_tty;
85149 unsigned audit_tty_log_passwd;
85150 @@ -708,7 +733,7 @@ struct signal_struct {
85151 struct mutex cred_guard_mutex; /* guard against foreign influences on
85152 * credential calculations
85153 * (notably. ptrace) */
85154 -};
85155 +} __randomize_layout;
85156
85157 /*
85158 * Bits in flags field of signal_struct.
85159 @@ -761,6 +786,14 @@ struct user_struct {
85160 struct key *session_keyring; /* UID's default session keyring */
85161 #endif
85162
85163 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
85164 + unsigned char kernel_banned;
85165 +#endif
85166 +#ifdef CONFIG_GRKERNSEC_BRUTE
85167 + unsigned char suid_banned;
85168 + unsigned long suid_ban_expires;
85169 +#endif
85170 +
85171 /* Hash table maintenance information */
85172 struct hlist_node uidhash_node;
85173 kuid_t uid;
85174 @@ -768,7 +801,7 @@ struct user_struct {
85175 #ifdef CONFIG_PERF_EVENTS
85176 atomic_long_t locked_vm;
85177 #endif
85178 -};
85179 +} __randomize_layout;
85180
85181 extern int uids_sysfs_init(void);
85182
85183 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
85184 struct task_struct {
85185 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85186 void *stack;
85187 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85188 + void *lowmem_stack;
85189 +#endif
85190 atomic_t usage;
85191 unsigned int flags; /* per process flags, defined below */
85192 unsigned int ptrace;
85193 @@ -1345,8 +1381,8 @@ struct task_struct {
85194 struct list_head thread_node;
85195
85196 struct completion *vfork_done; /* for vfork() */
85197 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85198 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85199 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85200 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85201
85202 cputime_t utime, stime, utimescaled, stimescaled;
85203 cputime_t gtime;
85204 @@ -1371,11 +1407,6 @@ struct task_struct {
85205 struct task_cputime cputime_expires;
85206 struct list_head cpu_timers[3];
85207
85208 -/* process credentials */
85209 - const struct cred __rcu *real_cred; /* objective and real subjective task
85210 - * credentials (COW) */
85211 - const struct cred __rcu *cred; /* effective (overridable) subjective task
85212 - * credentials (COW) */
85213 char comm[TASK_COMM_LEN]; /* executable name excluding path
85214 - access with [gs]et_task_comm (which lock
85215 it with task_lock())
85216 @@ -1393,6 +1424,10 @@ struct task_struct {
85217 #endif
85218 /* CPU-specific state of this task */
85219 struct thread_struct thread;
85220 +/* thread_info moved to task_struct */
85221 +#ifdef CONFIG_X86
85222 + struct thread_info tinfo;
85223 +#endif
85224 /* filesystem information */
85225 struct fs_struct *fs;
85226 /* open file information */
85227 @@ -1467,6 +1502,10 @@ struct task_struct {
85228 gfp_t lockdep_reclaim_gfp;
85229 #endif
85230
85231 +/* process credentials */
85232 + const struct cred __rcu *real_cred; /* objective and real subjective task
85233 + * credentials (COW) */
85234 +
85235 /* journalling filesystem info */
85236 void *journal_info;
85237
85238 @@ -1505,6 +1544,10 @@ struct task_struct {
85239 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85240 struct list_head cg_list;
85241 #endif
85242 +
85243 + const struct cred __rcu *cred; /* effective (overridable) subjective task
85244 + * credentials (COW) */
85245 +
85246 #ifdef CONFIG_FUTEX
85247 struct robust_list_head __user *robust_list;
85248 #ifdef CONFIG_COMPAT
85249 @@ -1618,7 +1661,7 @@ struct task_struct {
85250 * Number of functions that haven't been traced
85251 * because of depth overrun.
85252 */
85253 - atomic_t trace_overrun;
85254 + atomic_unchecked_t trace_overrun;
85255 /* Pause for the tracing */
85256 atomic_t tracing_graph_pause;
85257 #endif
85258 @@ -1644,7 +1687,78 @@ struct task_struct {
85259 unsigned int sequential_io;
85260 unsigned int sequential_io_avg;
85261 #endif
85262 -};
85263 +
85264 +#ifdef CONFIG_GRKERNSEC
85265 + /* grsecurity */
85266 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85267 + u64 exec_id;
85268 +#endif
85269 +#ifdef CONFIG_GRKERNSEC_SETXID
85270 + const struct cred *delayed_cred;
85271 +#endif
85272 + struct dentry *gr_chroot_dentry;
85273 + struct acl_subject_label *acl;
85274 + struct acl_subject_label *tmpacl;
85275 + struct acl_role_label *role;
85276 + struct file *exec_file;
85277 + unsigned long brute_expires;
85278 + u16 acl_role_id;
85279 + u8 inherited;
85280 + /* is this the task that authenticated to the special role */
85281 + u8 acl_sp_role;
85282 + u8 is_writable;
85283 + u8 brute;
85284 + u8 gr_is_chrooted;
85285 +#endif
85286 +
85287 +} __randomize_layout;
85288 +
85289 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85290 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85291 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85292 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85293 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85294 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85295 +
85296 +#ifdef CONFIG_PAX_SOFTMODE
85297 +extern int pax_softmode;
85298 +#endif
85299 +
85300 +extern int pax_check_flags(unsigned long *);
85301 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85302 +
85303 +/* if tsk != current then task_lock must be held on it */
85304 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85305 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85306 +{
85307 + if (likely(tsk->mm))
85308 + return tsk->mm->pax_flags;
85309 + else
85310 + return 0UL;
85311 +}
85312 +
85313 +/* if tsk != current then task_lock must be held on it */
85314 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85315 +{
85316 + if (likely(tsk->mm)) {
85317 + tsk->mm->pax_flags = flags;
85318 + return 0;
85319 + }
85320 + return -EINVAL;
85321 +}
85322 +#endif
85323 +
85324 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85325 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85326 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85327 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85328 +#endif
85329 +
85330 +struct path;
85331 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85332 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85333 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85334 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85335
85336 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85337 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85338 @@ -1726,7 +1840,7 @@ struct pid_namespace;
85339 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85340 struct pid_namespace *ns);
85341
85342 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85343 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85344 {
85345 return tsk->pid;
85346 }
85347 @@ -2097,6 +2211,25 @@ extern u64 sched_clock_cpu(int cpu);
85348
85349 extern void sched_clock_init(void);
85350
85351 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85352 +static inline void populate_stack(void)
85353 +{
85354 + struct task_struct *curtask = current;
85355 + int c;
85356 + int *ptr = curtask->stack;
85357 + int *end = curtask->stack + THREAD_SIZE;
85358 +
85359 + while (ptr < end) {
85360 + c = *(volatile int *)ptr;
85361 + ptr += PAGE_SIZE/sizeof(int);
85362 + }
85363 +}
85364 +#else
85365 +static inline void populate_stack(void)
85366 +{
85367 +}
85368 +#endif
85369 +
85370 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85371 static inline void sched_clock_tick(void)
85372 {
85373 @@ -2230,7 +2363,9 @@ void yield(void);
85374 extern struct exec_domain default_exec_domain;
85375
85376 union thread_union {
85377 +#ifndef CONFIG_X86
85378 struct thread_info thread_info;
85379 +#endif
85380 unsigned long stack[THREAD_SIZE/sizeof(long)];
85381 };
85382
85383 @@ -2263,6 +2398,7 @@ extern struct pid_namespace init_pid_ns;
85384 */
85385
85386 extern struct task_struct *find_task_by_vpid(pid_t nr);
85387 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85388 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85389 struct pid_namespace *ns);
85390
85391 @@ -2427,7 +2563,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85392 extern void exit_itimers(struct signal_struct *);
85393 extern void flush_itimer_signals(void);
85394
85395 -extern void do_group_exit(int);
85396 +extern __noreturn void do_group_exit(int);
85397
85398 extern int do_execve(struct filename *,
85399 const char __user * const __user *,
85400 @@ -2642,9 +2778,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85401
85402 #endif
85403
85404 -static inline int object_is_on_stack(void *obj)
85405 +static inline int object_starts_on_stack(const void *obj)
85406 {
85407 - void *stack = task_stack_page(current);
85408 + const void *stack = task_stack_page(current);
85409
85410 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85411 }
85412 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85413 index 596a0e0..bea77ec 100644
85414 --- a/include/linux/sched/sysctl.h
85415 +++ b/include/linux/sched/sysctl.h
85416 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85417 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85418
85419 extern int sysctl_max_map_count;
85420 +extern unsigned long sysctl_heap_stack_gap;
85421
85422 extern unsigned int sysctl_sched_latency;
85423 extern unsigned int sysctl_sched_min_granularity;
85424 diff --git a/include/linux/security.h b/include/linux/security.h
85425 index 623f90e..90b39da 100644
85426 --- a/include/linux/security.h
85427 +++ b/include/linux/security.h
85428 @@ -27,6 +27,7 @@
85429 #include <linux/slab.h>
85430 #include <linux/err.h>
85431 #include <linux/string.h>
85432 +#include <linux/grsecurity.h>
85433
85434 struct linux_binprm;
85435 struct cred;
85436 @@ -116,8 +117,6 @@ struct seq_file;
85437
85438 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85439
85440 -void reset_security_ops(void);
85441 -
85442 #ifdef CONFIG_MMU
85443 extern unsigned long mmap_min_addr;
85444 extern unsigned long dac_mmap_min_addr;
85445 @@ -1729,7 +1728,7 @@ struct security_operations {
85446 struct audit_context *actx);
85447 void (*audit_rule_free) (void *lsmrule);
85448 #endif /* CONFIG_AUDIT */
85449 -};
85450 +} __randomize_layout;
85451
85452 /* prototypes */
85453 extern int security_init(void);
85454 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85455 index dc368b8..e895209 100644
85456 --- a/include/linux/semaphore.h
85457 +++ b/include/linux/semaphore.h
85458 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85459 }
85460
85461 extern void down(struct semaphore *sem);
85462 -extern int __must_check down_interruptible(struct semaphore *sem);
85463 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85464 extern int __must_check down_killable(struct semaphore *sem);
85465 extern int __must_check down_trylock(struct semaphore *sem);
85466 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85467 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85468 index 52e0097..383f21d 100644
85469 --- a/include/linux/seq_file.h
85470 +++ b/include/linux/seq_file.h
85471 @@ -27,6 +27,9 @@ struct seq_file {
85472 struct mutex lock;
85473 const struct seq_operations *op;
85474 int poll_event;
85475 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85476 + u64 exec_id;
85477 +#endif
85478 #ifdef CONFIG_USER_NS
85479 struct user_namespace *user_ns;
85480 #endif
85481 @@ -39,6 +42,7 @@ struct seq_operations {
85482 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85483 int (*show) (struct seq_file *m, void *v);
85484 };
85485 +typedef struct seq_operations __no_const seq_operations_no_const;
85486
85487 #define SEQ_SKIP 1
85488
85489 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85490
85491 char *mangle_path(char *s, const char *p, const char *esc);
85492 int seq_open(struct file *, const struct seq_operations *);
85493 +int seq_open_restrict(struct file *, const struct seq_operations *);
85494 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85495 loff_t seq_lseek(struct file *, loff_t, int);
85496 int seq_release(struct inode *, struct file *);
85497 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85498 }
85499
85500 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85501 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85502 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85503 int single_release(struct inode *, struct file *);
85504 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85505 diff --git a/include/linux/shm.h b/include/linux/shm.h
85506 index 6fb8016..ab4465e 100644
85507 --- a/include/linux/shm.h
85508 +++ b/include/linux/shm.h
85509 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85510 /* The task created the shm object. NULL if the task is dead. */
85511 struct task_struct *shm_creator;
85512 struct list_head shm_clist; /* list by creator */
85513 +#ifdef CONFIG_GRKERNSEC
85514 + u64 shm_createtime;
85515 + pid_t shm_lapid;
85516 +#endif
85517 };
85518
85519 /* shm_mode upper byte flags */
85520 diff --git a/include/linux/signal.h b/include/linux/signal.h
85521 index 750196f..ae7a3a4 100644
85522 --- a/include/linux/signal.h
85523 +++ b/include/linux/signal.h
85524 @@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
85525 * know it'll be handled, so that they don't get converted to
85526 * SIGKILL or just silently dropped.
85527 */
85528 - kernel_sigaction(sig, (__force __sighandler_t)2);
85529 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85530 }
85531
85532 static inline void disallow_signal(int sig)
85533 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85534 index abde271..bc9ece1 100644
85535 --- a/include/linux/skbuff.h
85536 +++ b/include/linux/skbuff.h
85537 @@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85538 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85539 int node);
85540 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85541 -static inline struct sk_buff *alloc_skb(unsigned int size,
85542 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85543 gfp_t priority)
85544 {
85545 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85546 @@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85547 return skb->inner_transport_header - skb->inner_network_header;
85548 }
85549
85550 -static inline int skb_network_offset(const struct sk_buff *skb)
85551 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85552 {
85553 return skb_network_header(skb) - skb->data;
85554 }
85555 @@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
85556 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85557 */
85558 #ifndef NET_SKB_PAD
85559 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85560 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85561 #endif
85562
85563 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85564 @@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85565 int *err);
85566 unsigned int datagram_poll(struct file *file, struct socket *sock,
85567 struct poll_table_struct *wait);
85568 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85569 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85570 struct iovec *to, int size);
85571 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85572 struct iovec *iov);
85573 @@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
85574 nf_bridge_put(skb->nf_bridge);
85575 skb->nf_bridge = NULL;
85576 #endif
85577 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85578 + skb->nf_trace = 0;
85579 +#endif
85580 }
85581
85582 static inline void nf_reset_trace(struct sk_buff *skb)
85583 diff --git a/include/linux/slab.h b/include/linux/slab.h
85584 index 1d9abb7..b1e8b10 100644
85585 --- a/include/linux/slab.h
85586 +++ b/include/linux/slab.h
85587 @@ -14,15 +14,29 @@
85588 #include <linux/gfp.h>
85589 #include <linux/types.h>
85590 #include <linux/workqueue.h>
85591 -
85592 +#include <linux/err.h>
85593
85594 /*
85595 * Flags to pass to kmem_cache_create().
85596 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85597 */
85598 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85599 +
85600 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85601 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85602 +#else
85603 +#define SLAB_USERCOPY 0x00000000UL
85604 +#endif
85605 +
85606 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85607 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85608 +
85609 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85610 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85611 +#else
85612 +#define SLAB_NO_SANITIZE 0x00000000UL
85613 +#endif
85614 +
85615 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85616 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85617 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85618 @@ -98,10 +112,13 @@
85619 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85620 * Both make kfree a no-op.
85621 */
85622 -#define ZERO_SIZE_PTR ((void *)16)
85623 +#define ZERO_SIZE_PTR \
85624 +({ \
85625 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85626 + (void *)(-MAX_ERRNO-1L); \
85627 +})
85628
85629 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85630 - (unsigned long)ZERO_SIZE_PTR)
85631 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85632
85633 #include <linux/kmemleak.h>
85634
85635 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85636 void kfree(const void *);
85637 void kzfree(const void *);
85638 size_t ksize(const void *);
85639 +const char *check_heap_object(const void *ptr, unsigned long n);
85640 +bool is_usercopy_object(const void *ptr);
85641
85642 /*
85643 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85644 @@ -176,7 +195,7 @@ struct kmem_cache {
85645 unsigned int align; /* Alignment as calculated */
85646 unsigned long flags; /* Active flags on the slab */
85647 const char *name; /* Slab name for sysfs */
85648 - int refcount; /* Use counter */
85649 + atomic_t refcount; /* Use counter */
85650 void (*ctor)(void *); /* Called on object slot creation */
85651 struct list_head list; /* List of all slab caches on the system */
85652 };
85653 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85654 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85655 #endif
85656
85657 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85658 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85659 +#endif
85660 +
85661 /*
85662 * Figure out which kmalloc slab an allocation of a certain size
85663 * belongs to.
85664 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85665 * 2 = 120 .. 192 bytes
85666 * n = 2^(n-1) .. 2^n -1
85667 */
85668 -static __always_inline int kmalloc_index(size_t size)
85669 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85670 {
85671 if (!size)
85672 return 0;
85673 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
85674 }
85675 #endif /* !CONFIG_SLOB */
85676
85677 -void *__kmalloc(size_t size, gfp_t flags);
85678 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85679 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85680
85681 #ifdef CONFIG_NUMA
85682 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85683 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85684 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85685 #else
85686 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85687 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85688 index 8235dfb..47ce586 100644
85689 --- a/include/linux/slab_def.h
85690 +++ b/include/linux/slab_def.h
85691 @@ -38,7 +38,7 @@ struct kmem_cache {
85692 /* 4) cache creation/removal */
85693 const char *name;
85694 struct list_head list;
85695 - int refcount;
85696 + atomic_t refcount;
85697 int object_size;
85698 int align;
85699
85700 @@ -54,10 +54,14 @@ struct kmem_cache {
85701 unsigned long node_allocs;
85702 unsigned long node_frees;
85703 unsigned long node_overflow;
85704 - atomic_t allochit;
85705 - atomic_t allocmiss;
85706 - atomic_t freehit;
85707 - atomic_t freemiss;
85708 + atomic_unchecked_t allochit;
85709 + atomic_unchecked_t allocmiss;
85710 + atomic_unchecked_t freehit;
85711 + atomic_unchecked_t freemiss;
85712 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85713 + atomic_unchecked_t sanitized;
85714 + atomic_unchecked_t not_sanitized;
85715 +#endif
85716
85717 /*
85718 * If debugging is enabled, then the allocator can add additional
85719 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85720 index d82abd4..408c3a0 100644
85721 --- a/include/linux/slub_def.h
85722 +++ b/include/linux/slub_def.h
85723 @@ -74,7 +74,7 @@ struct kmem_cache {
85724 struct kmem_cache_order_objects max;
85725 struct kmem_cache_order_objects min;
85726 gfp_t allocflags; /* gfp flags to use on each alloc */
85727 - int refcount; /* Refcount for slab cache destroy */
85728 + atomic_t refcount; /* Refcount for slab cache destroy */
85729 void (*ctor)(void *);
85730 int inuse; /* Offset to metadata */
85731 int align; /* Alignment */
85732 diff --git a/include/linux/smp.h b/include/linux/smp.h
85733 index 34347f2..8739978 100644
85734 --- a/include/linux/smp.h
85735 +++ b/include/linux/smp.h
85736 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
85737 #endif
85738
85739 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85740 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85741 #define put_cpu() preempt_enable()
85742 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85743
85744 /*
85745 * Callback to arch code if there's nosmp or maxcpus=0 on the
85746 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85747 index 46cca4c..3323536 100644
85748 --- a/include/linux/sock_diag.h
85749 +++ b/include/linux/sock_diag.h
85750 @@ -11,7 +11,7 @@ struct sock;
85751 struct sock_diag_handler {
85752 __u8 family;
85753 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85754 -};
85755 +} __do_const;
85756
85757 int sock_diag_register(const struct sock_diag_handler *h);
85758 void sock_diag_unregister(const struct sock_diag_handler *h);
85759 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85760 index 680f9a3..f13aeb0 100644
85761 --- a/include/linux/sonet.h
85762 +++ b/include/linux/sonet.h
85763 @@ -7,7 +7,7 @@
85764 #include <uapi/linux/sonet.h>
85765
85766 struct k_sonet_stats {
85767 -#define __HANDLE_ITEM(i) atomic_t i
85768 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85769 __SONET_ITEMS
85770 #undef __HANDLE_ITEM
85771 };
85772 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85773 index 07d8e53..dc934c9 100644
85774 --- a/include/linux/sunrpc/addr.h
85775 +++ b/include/linux/sunrpc/addr.h
85776 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85777 {
85778 switch (sap->sa_family) {
85779 case AF_INET:
85780 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85781 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85782 case AF_INET6:
85783 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85784 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85785 }
85786 return 0;
85787 }
85788 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85789 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85790 const struct sockaddr *src)
85791 {
85792 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85793 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85794 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85795
85796 dsin->sin_family = ssin->sin_family;
85797 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85798 if (sa->sa_family != AF_INET6)
85799 return 0;
85800
85801 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85802 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85803 }
85804
85805 #endif /* _LINUX_SUNRPC_ADDR_H */
85806 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85807 index 70736b9..37f33db 100644
85808 --- a/include/linux/sunrpc/clnt.h
85809 +++ b/include/linux/sunrpc/clnt.h
85810 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85811 unsigned int p_timer; /* Which RTT timer to use */
85812 u32 p_statidx; /* Which procedure to account */
85813 const char * p_name; /* name of procedure */
85814 -};
85815 +} __do_const;
85816
85817 #ifdef __KERNEL__
85818
85819 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85820 index cf61ecd..a4a9bc0 100644
85821 --- a/include/linux/sunrpc/svc.h
85822 +++ b/include/linux/sunrpc/svc.h
85823 @@ -417,7 +417,7 @@ struct svc_procedure {
85824 unsigned int pc_count; /* call count */
85825 unsigned int pc_cachetype; /* cache info (NFS) */
85826 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85827 -};
85828 +} __do_const;
85829
85830 /*
85831 * Function prototypes.
85832 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85833 index 975da75..318c083 100644
85834 --- a/include/linux/sunrpc/svc_rdma.h
85835 +++ b/include/linux/sunrpc/svc_rdma.h
85836 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85837 extern unsigned int svcrdma_max_requests;
85838 extern unsigned int svcrdma_max_req_size;
85839
85840 -extern atomic_t rdma_stat_recv;
85841 -extern atomic_t rdma_stat_read;
85842 -extern atomic_t rdma_stat_write;
85843 -extern atomic_t rdma_stat_sq_starve;
85844 -extern atomic_t rdma_stat_rq_starve;
85845 -extern atomic_t rdma_stat_rq_poll;
85846 -extern atomic_t rdma_stat_rq_prod;
85847 -extern atomic_t rdma_stat_sq_poll;
85848 -extern atomic_t rdma_stat_sq_prod;
85849 +extern atomic_unchecked_t rdma_stat_recv;
85850 +extern atomic_unchecked_t rdma_stat_read;
85851 +extern atomic_unchecked_t rdma_stat_write;
85852 +extern atomic_unchecked_t rdma_stat_sq_starve;
85853 +extern atomic_unchecked_t rdma_stat_rq_starve;
85854 +extern atomic_unchecked_t rdma_stat_rq_poll;
85855 +extern atomic_unchecked_t rdma_stat_rq_prod;
85856 +extern atomic_unchecked_t rdma_stat_sq_poll;
85857 +extern atomic_unchecked_t rdma_stat_sq_prod;
85858
85859 #define RPCRDMA_VERSION 1
85860
85861 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85862 index 8d71d65..f79586e 100644
85863 --- a/include/linux/sunrpc/svcauth.h
85864 +++ b/include/linux/sunrpc/svcauth.h
85865 @@ -120,7 +120,7 @@ struct auth_ops {
85866 int (*release)(struct svc_rqst *rq);
85867 void (*domain_release)(struct auth_domain *);
85868 int (*set_client)(struct svc_rqst *rq);
85869 -};
85870 +} __do_const;
85871
85872 #define SVC_GARBAGE 1
85873 #define SVC_SYSERR 2
85874 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85875 index e7a018e..49f8b17 100644
85876 --- a/include/linux/swiotlb.h
85877 +++ b/include/linux/swiotlb.h
85878 @@ -60,7 +60,8 @@ extern void
85879
85880 extern void
85881 swiotlb_free_coherent(struct device *hwdev, size_t size,
85882 - void *vaddr, dma_addr_t dma_handle);
85883 + void *vaddr, dma_addr_t dma_handle,
85884 + struct dma_attrs *attrs);
85885
85886 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85887 unsigned long offset, size_t size,
85888 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85889 index 0f86d85..dff3419 100644
85890 --- a/include/linux/syscalls.h
85891 +++ b/include/linux/syscalls.h
85892 @@ -98,10 +98,16 @@ struct sigaltstack;
85893 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85894
85895 #define __SC_DECL(t, a) t a
85896 +#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))
85897 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85898 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85899 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85900 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85901 +#define __SC_LONG(t, a) __typeof( \
85902 + __builtin_choose_expr( \
85903 + sizeof(t) > sizeof(int), \
85904 + (t) 0, \
85905 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85906 + )) a
85907 #define __SC_CAST(t, a) (t) a
85908 #define __SC_ARGS(t, a) a
85909 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85910 @@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
85911 asmlinkage long sys_fsync(unsigned int fd);
85912 asmlinkage long sys_fdatasync(unsigned int fd);
85913 asmlinkage long sys_bdflush(int func, long data);
85914 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85915 - char __user *type, unsigned long flags,
85916 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85917 + const char __user *type, unsigned long flags,
85918 void __user *data);
85919 -asmlinkage long sys_umount(char __user *name, int flags);
85920 -asmlinkage long sys_oldumount(char __user *name);
85921 +asmlinkage long sys_umount(const char __user *name, int flags);
85922 +asmlinkage long sys_oldumount(const char __user *name);
85923 asmlinkage long sys_truncate(const char __user *path, long length);
85924 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85925 asmlinkage long sys_stat(const char __user *filename,
85926 @@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85927 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85928 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85929 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85930 - struct sockaddr __user *, int);
85931 + struct sockaddr __user *, int) __intentional_overflow(0);
85932 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85933 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85934 unsigned int vlen, unsigned flags);
85935 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85936 index 27b3b0b..e093dd9 100644
85937 --- a/include/linux/syscore_ops.h
85938 +++ b/include/linux/syscore_ops.h
85939 @@ -16,7 +16,7 @@ struct syscore_ops {
85940 int (*suspend)(void);
85941 void (*resume)(void);
85942 void (*shutdown)(void);
85943 -};
85944 +} __do_const;
85945
85946 extern void register_syscore_ops(struct syscore_ops *ops);
85947 extern void unregister_syscore_ops(struct syscore_ops *ops);
85948 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85949 index b7361f8..341a15a 100644
85950 --- a/include/linux/sysctl.h
85951 +++ b/include/linux/sysctl.h
85952 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85953
85954 extern int proc_dostring(struct ctl_table *, int,
85955 void __user *, size_t *, loff_t *);
85956 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85957 + void __user *, size_t *, loff_t *);
85958 extern int proc_dointvec(struct ctl_table *, int,
85959 void __user *, size_t *, loff_t *);
85960 extern int proc_dointvec_minmax(struct ctl_table *, int,
85961 @@ -113,7 +115,8 @@ struct ctl_table
85962 struct ctl_table_poll *poll;
85963 void *extra1;
85964 void *extra2;
85965 -};
85966 +} __do_const __randomize_layout;
85967 +typedef struct ctl_table __no_const ctl_table_no_const;
85968
85969 struct ctl_node {
85970 struct rb_node node;
85971 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85972 index f97d0db..c1187dc 100644
85973 --- a/include/linux/sysfs.h
85974 +++ b/include/linux/sysfs.h
85975 @@ -34,7 +34,8 @@ struct attribute {
85976 struct lock_class_key *key;
85977 struct lock_class_key skey;
85978 #endif
85979 -};
85980 +} __do_const;
85981 +typedef struct attribute __no_const attribute_no_const;
85982
85983 /**
85984 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85985 @@ -63,7 +64,8 @@ struct attribute_group {
85986 struct attribute *, int);
85987 struct attribute **attrs;
85988 struct bin_attribute **bin_attrs;
85989 -};
85990 +} __do_const;
85991 +typedef struct attribute_group __no_const attribute_group_no_const;
85992
85993 /**
85994 * Use these macros to make defining attributes easier. See include/linux/device.h
85995 @@ -128,7 +130,8 @@ struct bin_attribute {
85996 char *, loff_t, size_t);
85997 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85998 struct vm_area_struct *vma);
85999 -};
86000 +} __do_const;
86001 +typedef struct bin_attribute __no_const bin_attribute_no_const;
86002
86003 /**
86004 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
86005 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
86006 index 387fa7d..3fcde6b 100644
86007 --- a/include/linux/sysrq.h
86008 +++ b/include/linux/sysrq.h
86009 @@ -16,6 +16,7 @@
86010
86011 #include <linux/errno.h>
86012 #include <linux/types.h>
86013 +#include <linux/compiler.h>
86014
86015 /* Possible values of bitmask for enabling sysrq functions */
86016 /* 0x0001 is reserved for enable everything */
86017 @@ -33,7 +34,7 @@ struct sysrq_key_op {
86018 char *help_msg;
86019 char *action_msg;
86020 int enable_mask;
86021 -};
86022 +} __do_const;
86023
86024 #ifdef CONFIG_MAGIC_SYSRQ
86025
86026 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
86027 index ff307b5..f1a4468 100644
86028 --- a/include/linux/thread_info.h
86029 +++ b/include/linux/thread_info.h
86030 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
86031 #error "no set_restore_sigmask() provided and default one won't work"
86032 #endif
86033
86034 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
86035 +
86036 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
86037 +{
86038 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
86039 +}
86040 +
86041 #endif /* __KERNEL__ */
86042
86043 #endif /* _LINUX_THREAD_INFO_H */
86044 diff --git a/include/linux/tty.h b/include/linux/tty.h
86045 index 8413294..44391c7 100644
86046 --- a/include/linux/tty.h
86047 +++ b/include/linux/tty.h
86048 @@ -202,7 +202,7 @@ struct tty_port {
86049 const struct tty_port_operations *ops; /* Port operations */
86050 spinlock_t lock; /* Lock protecting tty field */
86051 int blocked_open; /* Waiting to open */
86052 - int count; /* Usage count */
86053 + atomic_t count; /* Usage count */
86054 wait_queue_head_t open_wait; /* Open waiters */
86055 wait_queue_head_t close_wait; /* Close waiters */
86056 wait_queue_head_t delta_msr_wait; /* Modem status change */
86057 @@ -284,7 +284,7 @@ struct tty_struct {
86058 /* If the tty has a pending do_SAK, queue it here - akpm */
86059 struct work_struct SAK_work;
86060 struct tty_port *port;
86061 -};
86062 +} __randomize_layout;
86063
86064 /* Each of a tty's open files has private_data pointing to tty_file_private */
86065 struct tty_file_private {
86066 @@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
86067 struct tty_struct *tty, struct file *filp);
86068 static inline int tty_port_users(struct tty_port *port)
86069 {
86070 - return port->count + port->blocked_open;
86071 + return atomic_read(&port->count) + port->blocked_open;
86072 }
86073
86074 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
86075 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
86076 index e48c608..6a19af2 100644
86077 --- a/include/linux/tty_driver.h
86078 +++ b/include/linux/tty_driver.h
86079 @@ -287,7 +287,7 @@ struct tty_operations {
86080 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
86081 #endif
86082 const struct file_operations *proc_fops;
86083 -};
86084 +} __do_const __randomize_layout;
86085
86086 struct tty_driver {
86087 int magic; /* magic number for this structure */
86088 @@ -321,7 +321,7 @@ struct tty_driver {
86089
86090 const struct tty_operations *ops;
86091 struct list_head tty_drivers;
86092 -};
86093 +} __randomize_layout;
86094
86095 extern struct list_head tty_drivers;
86096
86097 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
86098 index 00c9d68..bc0188b 100644
86099 --- a/include/linux/tty_ldisc.h
86100 +++ b/include/linux/tty_ldisc.h
86101 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
86102
86103 struct module *owner;
86104
86105 - int refcount;
86106 + atomic_t refcount;
86107 };
86108
86109 struct tty_ldisc {
86110 diff --git a/include/linux/types.h b/include/linux/types.h
86111 index a0bb704..f511c77 100644
86112 --- a/include/linux/types.h
86113 +++ b/include/linux/types.h
86114 @@ -177,10 +177,26 @@ typedef struct {
86115 int counter;
86116 } atomic_t;
86117
86118 +#ifdef CONFIG_PAX_REFCOUNT
86119 +typedef struct {
86120 + int counter;
86121 +} atomic_unchecked_t;
86122 +#else
86123 +typedef atomic_t atomic_unchecked_t;
86124 +#endif
86125 +
86126 #ifdef CONFIG_64BIT
86127 typedef struct {
86128 long counter;
86129 } atomic64_t;
86130 +
86131 +#ifdef CONFIG_PAX_REFCOUNT
86132 +typedef struct {
86133 + long counter;
86134 +} atomic64_unchecked_t;
86135 +#else
86136 +typedef atomic64_t atomic64_unchecked_t;
86137 +#endif
86138 #endif
86139
86140 struct list_head {
86141 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
86142 index ecd3319..8a36ded 100644
86143 --- a/include/linux/uaccess.h
86144 +++ b/include/linux/uaccess.h
86145 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
86146 long ret; \
86147 mm_segment_t old_fs = get_fs(); \
86148 \
86149 - set_fs(KERNEL_DS); \
86150 pagefault_disable(); \
86151 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
86152 - pagefault_enable(); \
86153 + set_fs(KERNEL_DS); \
86154 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
86155 set_fs(old_fs); \
86156 + pagefault_enable(); \
86157 ret; \
86158 })
86159
86160 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
86161 index 2d1f9b6..d7a9fce 100644
86162 --- a/include/linux/uidgid.h
86163 +++ b/include/linux/uidgid.h
86164 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
86165
86166 #endif /* CONFIG_USER_NS */
86167
86168 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
86169 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
86170 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
86171 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
86172 +
86173 #endif /* _LINUX_UIDGID_H */
86174 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86175 index 99c1b4d..562e6f3 100644
86176 --- a/include/linux/unaligned/access_ok.h
86177 +++ b/include/linux/unaligned/access_ok.h
86178 @@ -4,34 +4,34 @@
86179 #include <linux/kernel.h>
86180 #include <asm/byteorder.h>
86181
86182 -static inline u16 get_unaligned_le16(const void *p)
86183 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86184 {
86185 - return le16_to_cpup((__le16 *)p);
86186 + return le16_to_cpup((const __le16 *)p);
86187 }
86188
86189 -static inline u32 get_unaligned_le32(const void *p)
86190 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86191 {
86192 - return le32_to_cpup((__le32 *)p);
86193 + return le32_to_cpup((const __le32 *)p);
86194 }
86195
86196 -static inline u64 get_unaligned_le64(const void *p)
86197 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86198 {
86199 - return le64_to_cpup((__le64 *)p);
86200 + return le64_to_cpup((const __le64 *)p);
86201 }
86202
86203 -static inline u16 get_unaligned_be16(const void *p)
86204 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86205 {
86206 - return be16_to_cpup((__be16 *)p);
86207 + return be16_to_cpup((const __be16 *)p);
86208 }
86209
86210 -static inline u32 get_unaligned_be32(const void *p)
86211 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86212 {
86213 - return be32_to_cpup((__be32 *)p);
86214 + return be32_to_cpup((const __be32 *)p);
86215 }
86216
86217 -static inline u64 get_unaligned_be64(const void *p)
86218 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86219 {
86220 - return be64_to_cpup((__be64 *)p);
86221 + return be64_to_cpup((const __be64 *)p);
86222 }
86223
86224 static inline void put_unaligned_le16(u16 val, void *p)
86225 diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
86226 index 4f844c6..60beb5d 100644
86227 --- a/include/linux/uprobes.h
86228 +++ b/include/linux/uprobes.h
86229 @@ -98,11 +98,11 @@ struct uprobes_state {
86230 struct xol_area *xol_area;
86231 };
86232
86233 -extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86234 -extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86235 -extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
86236 -extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
86237 -extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
86238 +extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86239 +extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86240 +extern bool is_swbp_insn(uprobe_opcode_t *insn);
86241 +extern bool is_trap_insn(uprobe_opcode_t *insn);
86242 +extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
86243 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
86244 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
86245 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
86246 @@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
86247 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
86248 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
86249 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
86250 -extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86251 -extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86252 +extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86253 +extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86254 void *src, unsigned long len);
86255 #else /* !CONFIG_UPROBES */
86256 struct uprobes_state {
86257 diff --git a/include/linux/usb.h b/include/linux/usb.h
86258 index d2465bc..5256de4 100644
86259 --- a/include/linux/usb.h
86260 +++ b/include/linux/usb.h
86261 @@ -571,7 +571,7 @@ struct usb_device {
86262 int maxchild;
86263
86264 u32 quirks;
86265 - atomic_t urbnum;
86266 + atomic_unchecked_t urbnum;
86267
86268 unsigned long active_duration;
86269
86270 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
86271
86272 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
86273 __u8 request, __u8 requesttype, __u16 value, __u16 index,
86274 - void *data, __u16 size, int timeout);
86275 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
86276 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
86277 void *data, int len, int *actual_length, int timeout);
86278 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
86279 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
86280 index d5952bb..9a626d4 100644
86281 --- a/include/linux/usb/renesas_usbhs.h
86282 +++ b/include/linux/usb/renesas_usbhs.h
86283 @@ -39,7 +39,7 @@ enum {
86284 */
86285 struct renesas_usbhs_driver_callback {
86286 int (*notify_hotplug)(struct platform_device *pdev);
86287 -};
86288 +} __no_const;
86289
86290 /*
86291 * callback functions for platform
86292 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
86293 index e953726..8edb26a 100644
86294 --- a/include/linux/user_namespace.h
86295 +++ b/include/linux/user_namespace.h
86296 @@ -33,7 +33,7 @@ struct user_namespace {
86297 struct key *persistent_keyring_register;
86298 struct rw_semaphore persistent_keyring_register_sem;
86299 #endif
86300 -};
86301 +} __randomize_layout;
86302
86303 extern struct user_namespace init_user_ns;
86304
86305 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86306 index 239e277..22a5cf5 100644
86307 --- a/include/linux/utsname.h
86308 +++ b/include/linux/utsname.h
86309 @@ -24,7 +24,7 @@ struct uts_namespace {
86310 struct new_utsname name;
86311 struct user_namespace *user_ns;
86312 unsigned int proc_inum;
86313 -};
86314 +} __randomize_layout;
86315 extern struct uts_namespace init_uts_ns;
86316
86317 #ifdef CONFIG_UTS_NS
86318 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86319 index 6f8fbcf..4efc177 100644
86320 --- a/include/linux/vermagic.h
86321 +++ b/include/linux/vermagic.h
86322 @@ -25,9 +25,42 @@
86323 #define MODULE_ARCH_VERMAGIC ""
86324 #endif
86325
86326 +#ifdef CONFIG_PAX_REFCOUNT
86327 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86328 +#else
86329 +#define MODULE_PAX_REFCOUNT ""
86330 +#endif
86331 +
86332 +#ifdef CONSTIFY_PLUGIN
86333 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86334 +#else
86335 +#define MODULE_CONSTIFY_PLUGIN ""
86336 +#endif
86337 +
86338 +#ifdef STACKLEAK_PLUGIN
86339 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86340 +#else
86341 +#define MODULE_STACKLEAK_PLUGIN ""
86342 +#endif
86343 +
86344 +#ifdef RANDSTRUCT_PLUGIN
86345 +#include <generated/randomize_layout_hash.h>
86346 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86347 +#else
86348 +#define MODULE_RANDSTRUCT_PLUGIN
86349 +#endif
86350 +
86351 +#ifdef CONFIG_GRKERNSEC
86352 +#define MODULE_GRSEC "GRSEC "
86353 +#else
86354 +#define MODULE_GRSEC ""
86355 +#endif
86356 +
86357 #define VERMAGIC_STRING \
86358 UTS_RELEASE " " \
86359 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86360 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86361 - MODULE_ARCH_VERMAGIC
86362 + MODULE_ARCH_VERMAGIC \
86363 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86364 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86365
86366 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86367 index b483abd..af305ad 100644
86368 --- a/include/linux/vga_switcheroo.h
86369 +++ b/include/linux/vga_switcheroo.h
86370 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86371
86372 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86373
86374 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86375 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86376 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86377 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86378 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86379 #else
86380
86381 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86382 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86383
86384 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86385
86386 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86387 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86388 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86389 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86390 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86391
86392 #endif
86393 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86394 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86395 index b87696f..1d11de7 100644
86396 --- a/include/linux/vmalloc.h
86397 +++ b/include/linux/vmalloc.h
86398 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86399 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86400 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86401 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86402 +
86403 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86404 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86405 +#endif
86406 +
86407 /* bits [20..32] reserved for arch specific ioremap internals */
86408
86409 /*
86410 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86411 unsigned long flags, pgprot_t prot);
86412 extern void vunmap(const void *addr);
86413
86414 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86415 +extern void unmap_process_stacks(struct task_struct *task);
86416 +#endif
86417 +
86418 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86419 unsigned long uaddr, void *kaddr,
86420 unsigned long size);
86421 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86422
86423 /* for /dev/kmem */
86424 extern long vread(char *buf, char *addr, unsigned long count);
86425 -extern long vwrite(char *buf, char *addr, unsigned long count);
86426 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86427
86428 /*
86429 * Internals. Dont't use..
86430 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86431 index 82e7db7..f8ce3d0 100644
86432 --- a/include/linux/vmstat.h
86433 +++ b/include/linux/vmstat.h
86434 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86435 /*
86436 * Zone based page accounting with per cpu differentials.
86437 */
86438 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86439 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86440
86441 static inline void zone_page_state_add(long x, struct zone *zone,
86442 enum zone_stat_item item)
86443 {
86444 - atomic_long_add(x, &zone->vm_stat[item]);
86445 - atomic_long_add(x, &vm_stat[item]);
86446 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86447 + atomic_long_add_unchecked(x, &vm_stat[item]);
86448 }
86449
86450 -static inline unsigned long global_page_state(enum zone_stat_item item)
86451 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86452 {
86453 - long x = atomic_long_read(&vm_stat[item]);
86454 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86455 #ifdef CONFIG_SMP
86456 if (x < 0)
86457 x = 0;
86458 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86459 return x;
86460 }
86461
86462 -static inline unsigned long zone_page_state(struct zone *zone,
86463 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86464 enum zone_stat_item item)
86465 {
86466 - long x = atomic_long_read(&zone->vm_stat[item]);
86467 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86468 #ifdef CONFIG_SMP
86469 if (x < 0)
86470 x = 0;
86471 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86472 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86473 enum zone_stat_item item)
86474 {
86475 - long x = atomic_long_read(&zone->vm_stat[item]);
86476 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86477
86478 #ifdef CONFIG_SMP
86479 int cpu;
86480 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86481
86482 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86483 {
86484 - atomic_long_inc(&zone->vm_stat[item]);
86485 - atomic_long_inc(&vm_stat[item]);
86486 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86487 + atomic_long_inc_unchecked(&vm_stat[item]);
86488 }
86489
86490 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86491 {
86492 - atomic_long_dec(&zone->vm_stat[item]);
86493 - atomic_long_dec(&vm_stat[item]);
86494 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86495 + atomic_long_dec_unchecked(&vm_stat[item]);
86496 }
86497
86498 static inline void __inc_zone_page_state(struct page *page,
86499 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86500 index 91b0a68..0e9adf6 100644
86501 --- a/include/linux/xattr.h
86502 +++ b/include/linux/xattr.h
86503 @@ -28,7 +28,7 @@ struct xattr_handler {
86504 size_t size, int handler_flags);
86505 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86506 size_t size, int flags, int handler_flags);
86507 -};
86508 +} __do_const;
86509
86510 struct xattr {
86511 const char *name;
86512 @@ -37,6 +37,9 @@ struct xattr {
86513 };
86514
86515 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86516 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86517 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86518 +#endif
86519 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86520 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86521 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86522 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86523 index 92dbbd3..13ab0b3 100644
86524 --- a/include/linux/zlib.h
86525 +++ b/include/linux/zlib.h
86526 @@ -31,6 +31,7 @@
86527 #define _ZLIB_H
86528
86529 #include <linux/zconf.h>
86530 +#include <linux/compiler.h>
86531
86532 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86533 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86534 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86535
86536 /* basic functions */
86537
86538 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86539 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86540 /*
86541 Returns the number of bytes that needs to be allocated for a per-
86542 stream workspace with the specified parameters. A pointer to this
86543 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86544 index eb76cfd..9fd0e7c 100644
86545 --- a/include/media/v4l2-dev.h
86546 +++ b/include/media/v4l2-dev.h
86547 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86548 int (*mmap) (struct file *, struct vm_area_struct *);
86549 int (*open) (struct file *);
86550 int (*release) (struct file *);
86551 -};
86552 +} __do_const;
86553
86554 /*
86555 * Newer version of video_device, handled by videodev2.c
86556 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86557 index ffb69da..040393e 100644
86558 --- a/include/media/v4l2-device.h
86559 +++ b/include/media/v4l2-device.h
86560 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86561 this function returns 0. If the name ends with a digit (e.g. cx18),
86562 then the name will be set to cx18-0 since cx180 looks really odd. */
86563 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86564 - atomic_t *instance);
86565 + atomic_unchecked_t *instance);
86566
86567 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86568 Since the parent disappears this ensures that v4l2_dev doesn't have an
86569 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86570 index d9fa68f..45c88d1 100644
86571 --- a/include/net/9p/transport.h
86572 +++ b/include/net/9p/transport.h
86573 @@ -63,7 +63,7 @@ struct p9_trans_module {
86574 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86575 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86576 char *, char *, int , int, int, int);
86577 -};
86578 +} __do_const;
86579
86580 void v9fs_register_trans(struct p9_trans_module *m);
86581 void v9fs_unregister_trans(struct p9_trans_module *m);
86582 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86583 index a175ba4..196eb8242 100644
86584 --- a/include/net/af_unix.h
86585 +++ b/include/net/af_unix.h
86586 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86587 u32 secid; /* Security ID */
86588 #endif
86589 u32 consumed;
86590 -};
86591 +} __randomize_layout;
86592
86593 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86594 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86595 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86596 index 8df15ad..837fbedd 100644
86597 --- a/include/net/bluetooth/l2cap.h
86598 +++ b/include/net/bluetooth/l2cap.h
86599 @@ -608,7 +608,7 @@ struct l2cap_ops {
86600 unsigned char *kdata,
86601 struct iovec *iov,
86602 int len);
86603 -};
86604 +} __do_const;
86605
86606 struct l2cap_conn {
86607 struct hci_conn *hcon;
86608 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86609 index f2ae33d..c457cf0 100644
86610 --- a/include/net/caif/cfctrl.h
86611 +++ b/include/net/caif/cfctrl.h
86612 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86613 void (*radioset_rsp)(void);
86614 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86615 struct cflayer *client_layer);
86616 -};
86617 +} __no_const;
86618
86619 /* Link Setup Parameters for CAIF-Links. */
86620 struct cfctrl_link_param {
86621 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86622 struct cfctrl {
86623 struct cfsrvl serv;
86624 struct cfctrl_rsp res;
86625 - atomic_t req_seq_no;
86626 - atomic_t rsp_seq_no;
86627 + atomic_unchecked_t req_seq_no;
86628 + atomic_unchecked_t rsp_seq_no;
86629 struct list_head list;
86630 /* Protects from simultaneous access to first_req list */
86631 spinlock_t info_list_lock;
86632 diff --git a/include/net/flow.h b/include/net/flow.h
86633 index 8109a15..504466d 100644
86634 --- a/include/net/flow.h
86635 +++ b/include/net/flow.h
86636 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86637
86638 void flow_cache_flush(struct net *net);
86639 void flow_cache_flush_deferred(struct net *net);
86640 -extern atomic_t flow_cache_genid;
86641 +extern atomic_unchecked_t flow_cache_genid;
86642
86643 #endif
86644 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86645 index af10c2c..a431cc5 100644
86646 --- a/include/net/genetlink.h
86647 +++ b/include/net/genetlink.h
86648 @@ -120,7 +120,7 @@ struct genl_ops {
86649 u8 cmd;
86650 u8 internal_flags;
86651 u8 flags;
86652 -};
86653 +} __do_const;
86654
86655 int __genl_register_family(struct genl_family *family);
86656
86657 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86658 index 734d9b5..48a9a4b 100644
86659 --- a/include/net/gro_cells.h
86660 +++ b/include/net/gro_cells.h
86661 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86662 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86663
86664 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86665 - atomic_long_inc(&dev->rx_dropped);
86666 + atomic_long_inc_unchecked(&dev->rx_dropped);
86667 kfree_skb(skb);
86668 return;
86669 }
86670 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86671 index 5fbe656..9ed3d8b 100644
86672 --- a/include/net/inet_connection_sock.h
86673 +++ b/include/net/inet_connection_sock.h
86674 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86675 int (*bind_conflict)(const struct sock *sk,
86676 const struct inet_bind_bucket *tb, bool relax);
86677 void (*mtu_reduced)(struct sock *sk);
86678 -};
86679 +} __do_const;
86680
86681 /** inet_connection_sock - INET connection oriented sock
86682 *
86683 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86684 index 01d590e..f69c61d 100644
86685 --- a/include/net/inetpeer.h
86686 +++ b/include/net/inetpeer.h
86687 @@ -47,7 +47,7 @@ struct inet_peer {
86688 */
86689 union {
86690 struct {
86691 - atomic_t rid; /* Frag reception counter */
86692 + atomic_unchecked_t rid; /* Frag reception counter */
86693 };
86694 struct rcu_head rcu;
86695 struct inet_peer *gc_next;
86696 diff --git a/include/net/ip.h b/include/net/ip.h
86697 index db4a771..965a42a 100644
86698 --- a/include/net/ip.h
86699 +++ b/include/net/ip.h
86700 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86701 }
86702 }
86703
86704 -u32 ip_idents_reserve(u32 hash, int segs);
86705 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86706 void __ip_select_ident(struct iphdr *iph, int segs);
86707
86708 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86709 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86710 index 9922093..a1755d6 100644
86711 --- a/include/net/ip_fib.h
86712 +++ b/include/net/ip_fib.h
86713 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86714
86715 #define FIB_RES_SADDR(net, res) \
86716 ((FIB_RES_NH(res).nh_saddr_genid == \
86717 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86718 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86719 FIB_RES_NH(res).nh_saddr : \
86720 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86721 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86722 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86723 index 624a8a5..b1e2a24 100644
86724 --- a/include/net/ip_vs.h
86725 +++ b/include/net/ip_vs.h
86726 @@ -558,7 +558,7 @@ struct ip_vs_conn {
86727 struct ip_vs_conn *control; /* Master control connection */
86728 atomic_t n_control; /* Number of controlled ones */
86729 struct ip_vs_dest *dest; /* real server */
86730 - atomic_t in_pkts; /* incoming packet counter */
86731 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86732
86733 /* packet transmitter for different forwarding methods. If it
86734 mangles the packet, it must return NF_DROP or better NF_STOLEN,
86735 @@ -705,7 +705,7 @@ struct ip_vs_dest {
86736 __be16 port; /* port number of the server */
86737 union nf_inet_addr addr; /* IP address of the server */
86738 volatile unsigned int flags; /* dest status flags */
86739 - atomic_t conn_flags; /* flags to copy to conn */
86740 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86741 atomic_t weight; /* server weight */
86742
86743 atomic_t refcnt; /* reference counter */
86744 @@ -960,11 +960,11 @@ struct netns_ipvs {
86745 /* ip_vs_lblc */
86746 int sysctl_lblc_expiration;
86747 struct ctl_table_header *lblc_ctl_header;
86748 - struct ctl_table *lblc_ctl_table;
86749 + ctl_table_no_const *lblc_ctl_table;
86750 /* ip_vs_lblcr */
86751 int sysctl_lblcr_expiration;
86752 struct ctl_table_header *lblcr_ctl_header;
86753 - struct ctl_table *lblcr_ctl_table;
86754 + ctl_table_no_const *lblcr_ctl_table;
86755 /* ip_vs_est */
86756 struct list_head est_list; /* estimator list */
86757 spinlock_t est_lock;
86758 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86759 index 8d4f588..2e37ad2 100644
86760 --- a/include/net/irda/ircomm_tty.h
86761 +++ b/include/net/irda/ircomm_tty.h
86762 @@ -33,6 +33,7 @@
86763 #include <linux/termios.h>
86764 #include <linux/timer.h>
86765 #include <linux/tty.h> /* struct tty_struct */
86766 +#include <asm/local.h>
86767
86768 #include <net/irda/irias_object.h>
86769 #include <net/irda/ircomm_core.h>
86770 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86771 index 714cc9a..ea05f3e 100644
86772 --- a/include/net/iucv/af_iucv.h
86773 +++ b/include/net/iucv/af_iucv.h
86774 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86775 struct iucv_sock_list {
86776 struct hlist_head head;
86777 rwlock_t lock;
86778 - atomic_t autobind_name;
86779 + atomic_unchecked_t autobind_name;
86780 };
86781
86782 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86783 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86784 index f3be818..bf46196 100644
86785 --- a/include/net/llc_c_ac.h
86786 +++ b/include/net/llc_c_ac.h
86787 @@ -87,7 +87,7 @@
86788 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86789 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86790
86791 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86792 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86793
86794 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86795 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86796 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86797 index 3948cf1..83b28c4 100644
86798 --- a/include/net/llc_c_ev.h
86799 +++ b/include/net/llc_c_ev.h
86800 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86801 return (struct llc_conn_state_ev *)skb->cb;
86802 }
86803
86804 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86805 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86806 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86807 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86808
86809 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86810 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86811 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86812 index 0e79cfb..f46db31 100644
86813 --- a/include/net/llc_c_st.h
86814 +++ b/include/net/llc_c_st.h
86815 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86816 u8 next_state;
86817 llc_conn_ev_qfyr_t *ev_qualifiers;
86818 llc_conn_action_t *ev_actions;
86819 -};
86820 +} __do_const;
86821
86822 struct llc_conn_state {
86823 u8 current_state;
86824 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86825 index a61b98c..aade1eb 100644
86826 --- a/include/net/llc_s_ac.h
86827 +++ b/include/net/llc_s_ac.h
86828 @@ -23,7 +23,7 @@
86829 #define SAP_ACT_TEST_IND 9
86830
86831 /* All action functions must look like this */
86832 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86833 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86834
86835 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86836 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86837 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86838 index 567c681..cd73ac02 100644
86839 --- a/include/net/llc_s_st.h
86840 +++ b/include/net/llc_s_st.h
86841 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86842 llc_sap_ev_t ev;
86843 u8 next_state;
86844 llc_sap_action_t *ev_actions;
86845 -};
86846 +} __do_const;
86847
86848 struct llc_sap_state {
86849 u8 curr_state;
86850 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86851 index dae2e24..89336e6 100644
86852 --- a/include/net/mac80211.h
86853 +++ b/include/net/mac80211.h
86854 @@ -4650,7 +4650,7 @@ struct rate_control_ops {
86855 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86856
86857 u32 (*get_expected_throughput)(void *priv_sta);
86858 -};
86859 +} __do_const;
86860
86861 static inline int rate_supported(struct ieee80211_sta *sta,
86862 enum ieee80211_band band,
86863 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86864 index 47f4254..fd095bc 100644
86865 --- a/include/net/neighbour.h
86866 +++ b/include/net/neighbour.h
86867 @@ -163,7 +163,7 @@ struct neigh_ops {
86868 void (*error_report)(struct neighbour *, struct sk_buff *);
86869 int (*output)(struct neighbour *, struct sk_buff *);
86870 int (*connected_output)(struct neighbour *, struct sk_buff *);
86871 -};
86872 +} __do_const;
86873
86874 struct pneigh_entry {
86875 struct pneigh_entry *next;
86876 @@ -217,7 +217,7 @@ struct neigh_table {
86877 struct neigh_statistics __percpu *stats;
86878 struct neigh_hash_table __rcu *nht;
86879 struct pneigh_entry **phash_buckets;
86880 -};
86881 +} __randomize_layout;
86882
86883 static inline int neigh_parms_family(struct neigh_parms *p)
86884 {
86885 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86886 index e0d6466..e2f3003 100644
86887 --- a/include/net/net_namespace.h
86888 +++ b/include/net/net_namespace.h
86889 @@ -129,8 +129,8 @@ struct net {
86890 struct netns_ipvs *ipvs;
86891 #endif
86892 struct sock *diag_nlsk;
86893 - atomic_t fnhe_genid;
86894 -};
86895 + atomic_unchecked_t fnhe_genid;
86896 +} __randomize_layout;
86897
86898 #include <linux/seq_file_net.h>
86899
86900 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86901 #define __net_init __init
86902 #define __net_exit __exit_refok
86903 #define __net_initdata __initdata
86904 +#ifdef CONSTIFY_PLUGIN
86905 #define __net_initconst __initconst
86906 +#else
86907 +#define __net_initconst __initdata
86908 +#endif
86909 #endif
86910
86911 struct pernet_operations {
86912 @@ -296,7 +300,7 @@ struct pernet_operations {
86913 void (*exit_batch)(struct list_head *net_exit_list);
86914 int *id;
86915 size_t size;
86916 -};
86917 +} __do_const;
86918
86919 /*
86920 * Use these carefully. If you implement a network device and it
86921 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86922
86923 static inline int rt_genid_ipv4(struct net *net)
86924 {
86925 - return atomic_read(&net->ipv4.rt_genid);
86926 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86927 }
86928
86929 static inline void rt_genid_bump_ipv4(struct net *net)
86930 {
86931 - atomic_inc(&net->ipv4.rt_genid);
86932 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86933 }
86934
86935 extern void (*__fib6_flush_trees)(struct net *net);
86936 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86937
86938 static inline int fnhe_genid(struct net *net)
86939 {
86940 - return atomic_read(&net->fnhe_genid);
86941 + return atomic_read_unchecked(&net->fnhe_genid);
86942 }
86943
86944 static inline void fnhe_genid_bump(struct net *net)
86945 {
86946 - atomic_inc(&net->fnhe_genid);
86947 + atomic_inc_unchecked(&net->fnhe_genid);
86948 }
86949
86950 #endif /* __NET_NET_NAMESPACE_H */
86951 diff --git a/include/net/netdma.h b/include/net/netdma.h
86952 index 8ba8ce2..99b7fff 100644
86953 --- a/include/net/netdma.h
86954 +++ b/include/net/netdma.h
86955 @@ -24,7 +24,7 @@
86956 #include <linux/dmaengine.h>
86957 #include <linux/skbuff.h>
86958
86959 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86960 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86961 struct sk_buff *skb, int offset, struct iovec *to,
86962 size_t len, struct dma_pinned_list *pinned_list);
86963
86964 diff --git a/include/net/netlink.h b/include/net/netlink.h
86965 index 6c10762..3e5de0c 100644
86966 --- a/include/net/netlink.h
86967 +++ b/include/net/netlink.h
86968 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86969 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86970 {
86971 if (mark)
86972 - skb_trim(skb, (unsigned char *) mark - skb->data);
86973 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86974 }
86975
86976 /**
86977 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86978 index 29d6a94..235d3d84 100644
86979 --- a/include/net/netns/conntrack.h
86980 +++ b/include/net/netns/conntrack.h
86981 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86982 struct nf_proto_net {
86983 #ifdef CONFIG_SYSCTL
86984 struct ctl_table_header *ctl_table_header;
86985 - struct ctl_table *ctl_table;
86986 + ctl_table_no_const *ctl_table;
86987 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86988 struct ctl_table_header *ctl_compat_header;
86989 - struct ctl_table *ctl_compat_table;
86990 + ctl_table_no_const *ctl_compat_table;
86991 #endif
86992 #endif
86993 unsigned int users;
86994 @@ -60,7 +60,7 @@ struct nf_ip_net {
86995 struct nf_icmp_net icmpv6;
86996 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86997 struct ctl_table_header *ctl_table_header;
86998 - struct ctl_table *ctl_table;
86999 + ctl_table_no_const *ctl_table;
87000 #endif
87001 };
87002
87003 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
87004 index aec5e12..807233f 100644
87005 --- a/include/net/netns/ipv4.h
87006 +++ b/include/net/netns/ipv4.h
87007 @@ -82,7 +82,7 @@ struct netns_ipv4 {
87008
87009 struct ping_group_range ping_group_range;
87010
87011 - atomic_t dev_addr_genid;
87012 + atomic_unchecked_t dev_addr_genid;
87013
87014 #ifdef CONFIG_SYSCTL
87015 unsigned long *sysctl_local_reserved_ports;
87016 @@ -96,6 +96,6 @@ struct netns_ipv4 {
87017 struct fib_rules_ops *mr_rules_ops;
87018 #endif
87019 #endif
87020 - atomic_t rt_genid;
87021 + atomic_unchecked_t rt_genid;
87022 };
87023 #endif
87024 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
87025 index eade27a..42894dd 100644
87026 --- a/include/net/netns/ipv6.h
87027 +++ b/include/net/netns/ipv6.h
87028 @@ -75,8 +75,8 @@ struct netns_ipv6 {
87029 struct fib_rules_ops *mr6_rules_ops;
87030 #endif
87031 #endif
87032 - atomic_t dev_addr_genid;
87033 - atomic_t rt_genid;
87034 + atomic_unchecked_t dev_addr_genid;
87035 + atomic_unchecked_t rt_genid;
87036 };
87037
87038 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
87039 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
87040 index 3492434..209f58c 100644
87041 --- a/include/net/netns/xfrm.h
87042 +++ b/include/net/netns/xfrm.h
87043 @@ -64,7 +64,7 @@ struct netns_xfrm {
87044
87045 /* flow cache part */
87046 struct flow_cache flow_cache_global;
87047 - atomic_t flow_cache_genid;
87048 + atomic_unchecked_t flow_cache_genid;
87049 struct list_head flow_cache_gc_list;
87050 spinlock_t flow_cache_gc_lock;
87051 struct work_struct flow_cache_gc_work;
87052 diff --git a/include/net/ping.h b/include/net/ping.h
87053 index 026479b..d9b2829 100644
87054 --- a/include/net/ping.h
87055 +++ b/include/net/ping.h
87056 @@ -54,7 +54,7 @@ struct ping_iter_state {
87057
87058 extern struct proto ping_prot;
87059 #if IS_ENABLED(CONFIG_IPV6)
87060 -extern struct pingv6_ops pingv6_ops;
87061 +extern struct pingv6_ops *pingv6_ops;
87062 #endif
87063
87064 struct pingfakehdr {
87065 diff --git a/include/net/protocol.h b/include/net/protocol.h
87066 index d6fcc1f..ca277058 100644
87067 --- a/include/net/protocol.h
87068 +++ b/include/net/protocol.h
87069 @@ -49,7 +49,7 @@ struct net_protocol {
87070 * socket lookup?
87071 */
87072 icmp_strict_tag_validation:1;
87073 -};
87074 +} __do_const;
87075
87076 #if IS_ENABLED(CONFIG_IPV6)
87077 struct inet6_protocol {
87078 @@ -62,7 +62,7 @@ struct inet6_protocol {
87079 u8 type, u8 code, int offset,
87080 __be32 info);
87081 unsigned int flags; /* INET6_PROTO_xxx */
87082 -};
87083 +} __do_const;
87084
87085 #define INET6_PROTO_NOPOLICY 0x1
87086 #define INET6_PROTO_FINAL 0x2
87087 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
87088 index e21b9f9..0191ef0 100644
87089 --- a/include/net/rtnetlink.h
87090 +++ b/include/net/rtnetlink.h
87091 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
87092 int (*fill_slave_info)(struct sk_buff *skb,
87093 const struct net_device *dev,
87094 const struct net_device *slave_dev);
87095 -};
87096 +} __do_const;
87097
87098 int __rtnl_link_register(struct rtnl_link_ops *ops);
87099 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
87100 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
87101 index 4a5b9a3..ca27d73 100644
87102 --- a/include/net/sctp/checksum.h
87103 +++ b/include/net/sctp/checksum.h
87104 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
87105 unsigned int offset)
87106 {
87107 struct sctphdr *sh = sctp_hdr(skb);
87108 - __le32 ret, old = sh->checksum;
87109 - const struct skb_checksum_ops ops = {
87110 + __le32 ret, old = sh->checksum;
87111 + static const struct skb_checksum_ops ops = {
87112 .update = sctp_csum_update,
87113 .combine = sctp_csum_combine,
87114 };
87115 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
87116 index 72a31db..aaa63d9 100644
87117 --- a/include/net/sctp/sm.h
87118 +++ b/include/net/sctp/sm.h
87119 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
87120 typedef struct {
87121 sctp_state_fn_t *fn;
87122 const char *name;
87123 -} sctp_sm_table_entry_t;
87124 +} __do_const sctp_sm_table_entry_t;
87125
87126 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
87127 * currently in use.
87128 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
87129 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
87130
87131 /* Extern declarations for major data structures. */
87132 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87133 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87134
87135
87136 /* Get the size of a DATA chunk payload. */
87137 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
87138 index 4ff3f67..89ae38e 100644
87139 --- a/include/net/sctp/structs.h
87140 +++ b/include/net/sctp/structs.h
87141 @@ -509,7 +509,7 @@ struct sctp_pf {
87142 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
87143 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
87144 struct sctp_af *af;
87145 -};
87146 +} __do_const;
87147
87148
87149 /* Structure to track chunk fragments that have been acked, but peer
87150 diff --git a/include/net/sock.h b/include/net/sock.h
87151 index b9a5bd0..dcd5f3c 100644
87152 --- a/include/net/sock.h
87153 +++ b/include/net/sock.h
87154 @@ -356,7 +356,7 @@ struct sock {
87155 unsigned int sk_napi_id;
87156 unsigned int sk_ll_usec;
87157 #endif
87158 - atomic_t sk_drops;
87159 + atomic_unchecked_t sk_drops;
87160 int sk_rcvbuf;
87161
87162 struct sk_filter __rcu *sk_filter;
87163 @@ -1053,7 +1053,7 @@ struct proto {
87164 void (*destroy_cgroup)(struct mem_cgroup *memcg);
87165 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
87166 #endif
87167 -};
87168 +} __randomize_layout;
87169
87170 /*
87171 * Bits in struct cg_proto.flags
87172 @@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87173 return ret >> PAGE_SHIFT;
87174 }
87175
87176 -static inline long
87177 +static inline long __intentional_overflow(-1)
87178 sk_memory_allocated(const struct sock *sk)
87179 {
87180 struct proto *prot = sk->sk_prot;
87181 @@ -1385,7 +1385,7 @@ struct sock_iocb {
87182 struct scm_cookie *scm;
87183 struct msghdr *msg, async_msg;
87184 struct kiocb *kiocb;
87185 -};
87186 +} __randomize_layout;
87187
87188 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87189 {
87190 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87191 }
87192
87193 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87194 - char __user *from, char *to,
87195 + char __user *from, unsigned char *to,
87196 int copy, int offset)
87197 {
87198 if (skb->ip_summed == CHECKSUM_NONE) {
87199 @@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87200 }
87201 }
87202
87203 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87204 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87205
87206 /**
87207 * sk_page_frag - return an appropriate page_frag
87208 diff --git a/include/net/tcp.h b/include/net/tcp.h
87209 index 590e01a..76498f3 100644
87210 --- a/include/net/tcp.h
87211 +++ b/include/net/tcp.h
87212 @@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
87213 void tcp_xmit_retransmit_queue(struct sock *);
87214 void tcp_simple_retransmit(struct sock *);
87215 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87216 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87217 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87218
87219 void tcp_send_probe0(struct sock *);
87220 void tcp_send_partial(struct sock *);
87221 @@ -696,8 +696,8 @@ struct tcp_skb_cb {
87222 struct inet6_skb_parm h6;
87223 #endif
87224 } header; /* For incoming frames */
87225 - __u32 seq; /* Starting sequence number */
87226 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
87227 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
87228 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
87229 __u32 when; /* used to compute rtt's */
87230 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
87231
87232 @@ -713,7 +713,7 @@ struct tcp_skb_cb {
87233
87234 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
87235 /* 1 byte hole */
87236 - __u32 ack_seq; /* Sequence number ACK'd */
87237 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
87238 };
87239
87240 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
87241 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
87242 index 721e9c3b..3c81bbf 100644
87243 --- a/include/net/xfrm.h
87244 +++ b/include/net/xfrm.h
87245 @@ -285,7 +285,6 @@ struct xfrm_dst;
87246 struct xfrm_policy_afinfo {
87247 unsigned short family;
87248 struct dst_ops *dst_ops;
87249 - void (*garbage_collect)(struct net *net);
87250 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
87251 const xfrm_address_t *saddr,
87252 const xfrm_address_t *daddr);
87253 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
87254 struct net_device *dev,
87255 const struct flowi *fl);
87256 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
87257 -};
87258 +} __do_const;
87259
87260 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
87261 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
87262 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
87263 int (*transport_finish)(struct sk_buff *skb,
87264 int async);
87265 void (*local_error)(struct sk_buff *skb, u32 mtu);
87266 -};
87267 +} __do_const;
87268
87269 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87270 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87271 @@ -437,7 +436,7 @@ struct xfrm_mode {
87272 struct module *owner;
87273 unsigned int encap;
87274 int flags;
87275 -};
87276 +} __do_const;
87277
87278 /* Flags for xfrm_mode. */
87279 enum {
87280 @@ -534,7 +533,7 @@ struct xfrm_policy {
87281 struct timer_list timer;
87282
87283 struct flow_cache_object flo;
87284 - atomic_t genid;
87285 + atomic_unchecked_t genid;
87286 u32 priority;
87287 u32 index;
87288 struct xfrm_mark mark;
87289 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87290 }
87291
87292 void xfrm_garbage_collect(struct net *net);
87293 +void xfrm_garbage_collect_deferred(struct net *net);
87294
87295 #else
87296
87297 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87298 static inline void xfrm_garbage_collect(struct net *net)
87299 {
87300 }
87301 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87302 +{
87303 +}
87304 #endif
87305
87306 static __inline__
87307 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87308 index 1017e0b..227aa4d 100644
87309 --- a/include/rdma/iw_cm.h
87310 +++ b/include/rdma/iw_cm.h
87311 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87312 int backlog);
87313
87314 int (*destroy_listen)(struct iw_cm_id *cm_id);
87315 -};
87316 +} __no_const;
87317
87318 /**
87319 * iw_create_cm_id - Create an IW CM identifier.
87320 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87321 index 52beadf..598734c 100644
87322 --- a/include/scsi/libfc.h
87323 +++ b/include/scsi/libfc.h
87324 @@ -771,6 +771,7 @@ struct libfc_function_template {
87325 */
87326 void (*disc_stop_final) (struct fc_lport *);
87327 };
87328 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87329
87330 /**
87331 * struct fc_disc - Discovery context
87332 @@ -875,7 +876,7 @@ struct fc_lport {
87333 struct fc_vport *vport;
87334
87335 /* Operational Information */
87336 - struct libfc_function_template tt;
87337 + libfc_function_template_no_const tt;
87338 u8 link_up;
87339 u8 qfull;
87340 enum fc_lport_state state;
87341 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87342 index 1a0d184..4fb841f 100644
87343 --- a/include/scsi/scsi_device.h
87344 +++ b/include/scsi/scsi_device.h
87345 @@ -185,9 +185,9 @@ struct scsi_device {
87346 unsigned int max_device_blocked; /* what device_blocked counts down from */
87347 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87348
87349 - atomic_t iorequest_cnt;
87350 - atomic_t iodone_cnt;
87351 - atomic_t ioerr_cnt;
87352 + atomic_unchecked_t iorequest_cnt;
87353 + atomic_unchecked_t iodone_cnt;
87354 + atomic_unchecked_t ioerr_cnt;
87355
87356 struct device sdev_gendev,
87357 sdev_dev;
87358 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87359 index 007a0bc..7188db8 100644
87360 --- a/include/scsi/scsi_transport_fc.h
87361 +++ b/include/scsi/scsi_transport_fc.h
87362 @@ -756,7 +756,8 @@ struct fc_function_template {
87363 unsigned long show_host_system_hostname:1;
87364
87365 unsigned long disable_target_scan:1;
87366 -};
87367 +} __do_const;
87368 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87369
87370
87371 /**
87372 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87373 index ae6c3b8..fd748ac 100644
87374 --- a/include/sound/compress_driver.h
87375 +++ b/include/sound/compress_driver.h
87376 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87377 struct snd_compr_caps *caps);
87378 int (*get_codec_caps) (struct snd_compr_stream *stream,
87379 struct snd_compr_codec_caps *codec);
87380 -};
87381 +} __no_const;
87382
87383 /**
87384 * struct snd_compr: Compressed device
87385 diff --git a/include/sound/soc.h b/include/sound/soc.h
87386 index c83a334..27c8038 100644
87387 --- a/include/sound/soc.h
87388 +++ b/include/sound/soc.h
87389 @@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
87390 /* probe ordering - for components with runtime dependencies */
87391 int probe_order;
87392 int remove_order;
87393 -};
87394 +} __do_const;
87395
87396 /* SoC platform interface */
87397 struct snd_soc_platform_driver {
87398 @@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
87399 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
87400 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
87401 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87402 -};
87403 +} __do_const;
87404
87405 struct snd_soc_dai_link_component {
87406 const char *name;
87407 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87408 index 9ec9864..e2ee1ee 100644
87409 --- a/include/target/target_core_base.h
87410 +++ b/include/target/target_core_base.h
87411 @@ -761,7 +761,7 @@ struct se_device {
87412 atomic_long_t write_bytes;
87413 /* Active commands on this virtual SE device */
87414 atomic_t simple_cmds;
87415 - atomic_t dev_ordered_id;
87416 + atomic_unchecked_t dev_ordered_id;
87417 atomic_t dev_ordered_sync;
87418 atomic_t dev_qf_count;
87419 int export_count;
87420 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87421 new file mode 100644
87422 index 0000000..fb634b7
87423 --- /dev/null
87424 +++ b/include/trace/events/fs.h
87425 @@ -0,0 +1,53 @@
87426 +#undef TRACE_SYSTEM
87427 +#define TRACE_SYSTEM fs
87428 +
87429 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87430 +#define _TRACE_FS_H
87431 +
87432 +#include <linux/fs.h>
87433 +#include <linux/tracepoint.h>
87434 +
87435 +TRACE_EVENT(do_sys_open,
87436 +
87437 + TP_PROTO(const char *filename, int flags, int mode),
87438 +
87439 + TP_ARGS(filename, flags, mode),
87440 +
87441 + TP_STRUCT__entry(
87442 + __string( filename, filename )
87443 + __field( int, flags )
87444 + __field( int, mode )
87445 + ),
87446 +
87447 + TP_fast_assign(
87448 + __assign_str(filename, filename);
87449 + __entry->flags = flags;
87450 + __entry->mode = mode;
87451 + ),
87452 +
87453 + TP_printk("\"%s\" %x %o",
87454 + __get_str(filename), __entry->flags, __entry->mode)
87455 +);
87456 +
87457 +TRACE_EVENT(open_exec,
87458 +
87459 + TP_PROTO(const char *filename),
87460 +
87461 + TP_ARGS(filename),
87462 +
87463 + TP_STRUCT__entry(
87464 + __string( filename, filename )
87465 + ),
87466 +
87467 + TP_fast_assign(
87468 + __assign_str(filename, filename);
87469 + ),
87470 +
87471 + TP_printk("\"%s\"",
87472 + __get_str(filename))
87473 +);
87474 +
87475 +#endif /* _TRACE_FS_H */
87476 +
87477 +/* This part must be outside protection */
87478 +#include <trace/define_trace.h>
87479 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87480 index 3608beb..df39d8a 100644
87481 --- a/include/trace/events/irq.h
87482 +++ b/include/trace/events/irq.h
87483 @@ -36,7 +36,7 @@ struct softirq_action;
87484 */
87485 TRACE_EVENT(irq_handler_entry,
87486
87487 - TP_PROTO(int irq, struct irqaction *action),
87488 + TP_PROTO(int irq, const struct irqaction *action),
87489
87490 TP_ARGS(irq, action),
87491
87492 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87493 */
87494 TRACE_EVENT(irq_handler_exit,
87495
87496 - TP_PROTO(int irq, struct irqaction *action, int ret),
87497 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87498
87499 TP_ARGS(irq, action, ret),
87500
87501 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87502 index 7caf44c..23c6f27 100644
87503 --- a/include/uapi/linux/a.out.h
87504 +++ b/include/uapi/linux/a.out.h
87505 @@ -39,6 +39,14 @@ enum machine_type {
87506 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87507 };
87508
87509 +/* Constants for the N_FLAGS field */
87510 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87511 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87512 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87513 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87514 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87515 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87516 +
87517 #if !defined (N_MAGIC)
87518 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87519 #endif
87520 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87521 index 22b6ad3..aeba37e 100644
87522 --- a/include/uapi/linux/bcache.h
87523 +++ b/include/uapi/linux/bcache.h
87524 @@ -5,6 +5,7 @@
87525 * Bcache on disk data structures
87526 */
87527
87528 +#include <linux/compiler.h>
87529 #include <asm/types.h>
87530
87531 #define BITMASK(name, type, field, offset, size) \
87532 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87533 /* Btree keys - all units are in sectors */
87534
87535 struct bkey {
87536 - __u64 high;
87537 - __u64 low;
87538 + __u64 high __intentional_overflow(-1);
87539 + __u64 low __intentional_overflow(-1);
87540 __u64 ptr[];
87541 };
87542
87543 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87544 index d876736..ccce5c0 100644
87545 --- a/include/uapi/linux/byteorder/little_endian.h
87546 +++ b/include/uapi/linux/byteorder/little_endian.h
87547 @@ -42,51 +42,51 @@
87548
87549 static inline __le64 __cpu_to_le64p(const __u64 *p)
87550 {
87551 - return (__force __le64)*p;
87552 + return (__force const __le64)*p;
87553 }
87554 -static inline __u64 __le64_to_cpup(const __le64 *p)
87555 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87556 {
87557 - return (__force __u64)*p;
87558 + return (__force const __u64)*p;
87559 }
87560 static inline __le32 __cpu_to_le32p(const __u32 *p)
87561 {
87562 - return (__force __le32)*p;
87563 + return (__force const __le32)*p;
87564 }
87565 static inline __u32 __le32_to_cpup(const __le32 *p)
87566 {
87567 - return (__force __u32)*p;
87568 + return (__force const __u32)*p;
87569 }
87570 static inline __le16 __cpu_to_le16p(const __u16 *p)
87571 {
87572 - return (__force __le16)*p;
87573 + return (__force const __le16)*p;
87574 }
87575 static inline __u16 __le16_to_cpup(const __le16 *p)
87576 {
87577 - return (__force __u16)*p;
87578 + return (__force const __u16)*p;
87579 }
87580 static inline __be64 __cpu_to_be64p(const __u64 *p)
87581 {
87582 - return (__force __be64)__swab64p(p);
87583 + return (__force const __be64)__swab64p(p);
87584 }
87585 static inline __u64 __be64_to_cpup(const __be64 *p)
87586 {
87587 - return __swab64p((__u64 *)p);
87588 + return __swab64p((const __u64 *)p);
87589 }
87590 static inline __be32 __cpu_to_be32p(const __u32 *p)
87591 {
87592 - return (__force __be32)__swab32p(p);
87593 + return (__force const __be32)__swab32p(p);
87594 }
87595 -static inline __u32 __be32_to_cpup(const __be32 *p)
87596 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87597 {
87598 - return __swab32p((__u32 *)p);
87599 + return __swab32p((const __u32 *)p);
87600 }
87601 static inline __be16 __cpu_to_be16p(const __u16 *p)
87602 {
87603 - return (__force __be16)__swab16p(p);
87604 + return (__force const __be16)__swab16p(p);
87605 }
87606 static inline __u16 __be16_to_cpup(const __be16 *p)
87607 {
87608 - return __swab16p((__u16 *)p);
87609 + return __swab16p((const __u16 *)p);
87610 }
87611 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87612 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87613 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87614 index ef6103b..d4e65dd 100644
87615 --- a/include/uapi/linux/elf.h
87616 +++ b/include/uapi/linux/elf.h
87617 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87618 #define PT_GNU_EH_FRAME 0x6474e550
87619
87620 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87621 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87622 +
87623 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87624 +
87625 +/* Constants for the e_flags field */
87626 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87627 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87628 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87629 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87630 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87631 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87632
87633 /*
87634 * Extended Numbering
87635 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87636 #define DT_DEBUG 21
87637 #define DT_TEXTREL 22
87638 #define DT_JMPREL 23
87639 +#define DT_FLAGS 30
87640 + #define DF_TEXTREL 0x00000004
87641 #define DT_ENCODING 32
87642 #define OLD_DT_LOOS 0x60000000
87643 #define DT_LOOS 0x6000000d
87644 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87645 #define PF_W 0x2
87646 #define PF_X 0x1
87647
87648 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87649 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87650 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87651 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87652 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87653 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87654 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87655 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87656 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87657 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87658 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87659 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87660 +
87661 typedef struct elf32_phdr{
87662 Elf32_Word p_type;
87663 Elf32_Off p_offset;
87664 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87665 #define EI_OSABI 7
87666 #define EI_PAD 8
87667
87668 +#define EI_PAX 14
87669 +
87670 #define ELFMAG0 0x7f /* EI_MAG */
87671 #define ELFMAG1 'E'
87672 #define ELFMAG2 'L'
87673 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87674 index aa169c4..6a2771d 100644
87675 --- a/include/uapi/linux/personality.h
87676 +++ b/include/uapi/linux/personality.h
87677 @@ -30,6 +30,7 @@ enum {
87678 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87679 ADDR_NO_RANDOMIZE | \
87680 ADDR_COMPAT_LAYOUT | \
87681 + ADDR_LIMIT_3GB | \
87682 MMAP_PAGE_ZERO)
87683
87684 /*
87685 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87686 index 7530e74..e714828 100644
87687 --- a/include/uapi/linux/screen_info.h
87688 +++ b/include/uapi/linux/screen_info.h
87689 @@ -43,7 +43,8 @@ struct screen_info {
87690 __u16 pages; /* 0x32 */
87691 __u16 vesa_attributes; /* 0x34 */
87692 __u32 capabilities; /* 0x36 */
87693 - __u8 _reserved[6]; /* 0x3a */
87694 + __u16 vesapm_size; /* 0x3a */
87695 + __u8 _reserved[4]; /* 0x3c */
87696 } __attribute__((packed));
87697
87698 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87699 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87700 index 0e011eb..82681b1 100644
87701 --- a/include/uapi/linux/swab.h
87702 +++ b/include/uapi/linux/swab.h
87703 @@ -43,7 +43,7 @@
87704 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87705 */
87706
87707 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87708 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87709 {
87710 #ifdef __HAVE_BUILTIN_BSWAP16__
87711 return __builtin_bswap16(val);
87712 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87713 #endif
87714 }
87715
87716 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87717 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87718 {
87719 #ifdef __HAVE_BUILTIN_BSWAP32__
87720 return __builtin_bswap32(val);
87721 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87722 #endif
87723 }
87724
87725 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87726 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87727 {
87728 #ifdef __HAVE_BUILTIN_BSWAP64__
87729 return __builtin_bswap64(val);
87730 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87731 index 43aaba1..1c30b48 100644
87732 --- a/include/uapi/linux/sysctl.h
87733 +++ b/include/uapi/linux/sysctl.h
87734 @@ -155,8 +155,6 @@ enum
87735 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87736 };
87737
87738 -
87739 -
87740 /* CTL_VM names: */
87741 enum
87742 {
87743 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
87744 index 778a329..1416ffb 100644
87745 --- a/include/uapi/linux/videodev2.h
87746 +++ b/include/uapi/linux/videodev2.h
87747 @@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
87748 union {
87749 __s32 value;
87750 __s64 value64;
87751 - char *string;
87752 + char __user *string;
87753 __u8 *p_u8;
87754 __u16 *p_u16;
87755 __u32 *p_u32;
87756 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87757 index 1590c49..5eab462 100644
87758 --- a/include/uapi/linux/xattr.h
87759 +++ b/include/uapi/linux/xattr.h
87760 @@ -73,5 +73,9 @@
87761 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87762 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87763
87764 +/* User namespace */
87765 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87766 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87767 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87768
87769 #endif /* _UAPI_LINUX_XATTR_H */
87770 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87771 index f9466fa..f4e2b81 100644
87772 --- a/include/video/udlfb.h
87773 +++ b/include/video/udlfb.h
87774 @@ -53,10 +53,10 @@ struct dlfb_data {
87775 u32 pseudo_palette[256];
87776 int blank_mode; /*one of FB_BLANK_ */
87777 /* blit-only rendering path metrics, exposed through sysfs */
87778 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87779 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87780 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87781 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87782 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87783 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87784 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87785 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87786 };
87787
87788 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87789 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87790 index 30f5362..8ed8ac9 100644
87791 --- a/include/video/uvesafb.h
87792 +++ b/include/video/uvesafb.h
87793 @@ -122,6 +122,7 @@ struct uvesafb_par {
87794 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87795 u8 pmi_setpal; /* PMI for palette changes */
87796 u16 *pmi_base; /* protected mode interface location */
87797 + u8 *pmi_code; /* protected mode code location */
87798 void *pmi_start;
87799 void *pmi_pal;
87800 u8 *vbe_state_orig; /*
87801 diff --git a/init/Kconfig b/init/Kconfig
87802 index 80a6907..baf7d53 100644
87803 --- a/init/Kconfig
87804 +++ b/init/Kconfig
87805 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87806
87807 config CHECKPOINT_RESTORE
87808 bool "Checkpoint/restore support" if EXPERT
87809 + depends on !GRKERNSEC
87810 default n
87811 help
87812 Enables additional kernel features in a sake of checkpoint/restore.
87813 @@ -1635,7 +1636,7 @@ config SLUB_DEBUG
87814
87815 config COMPAT_BRK
87816 bool "Disable heap randomization"
87817 - default y
87818 + default n
87819 help
87820 Randomizing heap placement makes heap exploits harder, but it
87821 also breaks ancient binaries (including anything libc5 based).
87822 @@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
87823 config STOP_MACHINE
87824 bool
87825 default y
87826 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87827 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87828 help
87829 Need stop_machine() primitive.
87830
87831 diff --git a/init/Makefile b/init/Makefile
87832 index 7bc47ee..6da2dc7 100644
87833 --- a/init/Makefile
87834 +++ b/init/Makefile
87835 @@ -2,6 +2,9 @@
87836 # Makefile for the linux kernel.
87837 #
87838
87839 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87840 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87841 +
87842 obj-y := main.o version.o mounts.o
87843 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87844 obj-y += noinitramfs.o
87845 diff --git a/init/do_mounts.c b/init/do_mounts.c
87846 index 82f2288..ea1430a 100644
87847 --- a/init/do_mounts.c
87848 +++ b/init/do_mounts.c
87849 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
87850 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87851 {
87852 struct super_block *s;
87853 - int err = sys_mount(name, "/root", fs, flags, data);
87854 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87855 if (err)
87856 return err;
87857
87858 - sys_chdir("/root");
87859 + sys_chdir((const char __force_user *)"/root");
87860 s = current->fs->pwd.dentry->d_sb;
87861 ROOT_DEV = s->s_dev;
87862 printk(KERN_INFO
87863 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
87864 va_start(args, fmt);
87865 vsprintf(buf, fmt, args);
87866 va_end(args);
87867 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87868 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87869 if (fd >= 0) {
87870 sys_ioctl(fd, FDEJECT, 0);
87871 sys_close(fd);
87872 }
87873 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87874 - fd = sys_open("/dev/console", O_RDWR, 0);
87875 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87876 if (fd >= 0) {
87877 sys_ioctl(fd, TCGETS, (long)&termios);
87878 termios.c_lflag &= ~ICANON;
87879 sys_ioctl(fd, TCSETSF, (long)&termios);
87880 - sys_read(fd, &c, 1);
87881 + sys_read(fd, (char __user *)&c, 1);
87882 termios.c_lflag |= ICANON;
87883 sys_ioctl(fd, TCSETSF, (long)&termios);
87884 sys_close(fd);
87885 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
87886 mount_root();
87887 out:
87888 devtmpfs_mount("dev");
87889 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87890 - sys_chroot(".");
87891 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87892 + sys_chroot((const char __force_user *)".");
87893 }
87894
87895 static bool is_tmpfs;
87896 diff --git a/init/do_mounts.h b/init/do_mounts.h
87897 index f5b978a..69dbfe8 100644
87898 --- a/init/do_mounts.h
87899 +++ b/init/do_mounts.h
87900 @@ -15,15 +15,15 @@ extern int root_mountflags;
87901
87902 static inline int create_dev(char *name, dev_t dev)
87903 {
87904 - sys_unlink(name);
87905 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87906 + sys_unlink((char __force_user *)name);
87907 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87908 }
87909
87910 #if BITS_PER_LONG == 32
87911 static inline u32 bstat(char *name)
87912 {
87913 struct stat64 stat;
87914 - if (sys_stat64(name, &stat) != 0)
87915 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87916 return 0;
87917 if (!S_ISBLK(stat.st_mode))
87918 return 0;
87919 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87920 static inline u32 bstat(char *name)
87921 {
87922 struct stat stat;
87923 - if (sys_newstat(name, &stat) != 0)
87924 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87925 return 0;
87926 if (!S_ISBLK(stat.st_mode))
87927 return 0;
87928 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87929 index 3e0878e..8a9d7a0 100644
87930 --- a/init/do_mounts_initrd.c
87931 +++ b/init/do_mounts_initrd.c
87932 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87933 {
87934 sys_unshare(CLONE_FS | CLONE_FILES);
87935 /* stdin/stdout/stderr for /linuxrc */
87936 - sys_open("/dev/console", O_RDWR, 0);
87937 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87938 sys_dup(0);
87939 sys_dup(0);
87940 /* move initrd over / and chdir/chroot in initrd root */
87941 - sys_chdir("/root");
87942 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87943 - sys_chroot(".");
87944 + sys_chdir((const char __force_user *)"/root");
87945 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87946 + sys_chroot((const char __force_user *)".");
87947 sys_setsid();
87948 return 0;
87949 }
87950 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87951 create_dev("/dev/root.old", Root_RAM0);
87952 /* mount initrd on rootfs' /root */
87953 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87954 - sys_mkdir("/old", 0700);
87955 - sys_chdir("/old");
87956 + sys_mkdir((const char __force_user *)"/old", 0700);
87957 + sys_chdir((const char __force_user *)"/old");
87958
87959 /* try loading default modules from initrd */
87960 load_default_modules();
87961 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87962 current->flags &= ~PF_FREEZER_SKIP;
87963
87964 /* move initrd to rootfs' /old */
87965 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87966 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87967 /* switch root and cwd back to / of rootfs */
87968 - sys_chroot("..");
87969 + sys_chroot((const char __force_user *)"..");
87970
87971 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87972 - sys_chdir("/old");
87973 + sys_chdir((const char __force_user *)"/old");
87974 return;
87975 }
87976
87977 - sys_chdir("/");
87978 + sys_chdir((const char __force_user *)"/");
87979 ROOT_DEV = new_decode_dev(real_root_dev);
87980 mount_root();
87981
87982 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87983 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87984 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87985 if (!error)
87986 printk("okay\n");
87987 else {
87988 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87989 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87990 if (error == -ENOENT)
87991 printk("/initrd does not exist. Ignored.\n");
87992 else
87993 printk("failed\n");
87994 printk(KERN_NOTICE "Unmounting old root\n");
87995 - sys_umount("/old", MNT_DETACH);
87996 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87997 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87998 if (fd < 0) {
87999 error = fd;
88000 @@ -127,11 +127,11 @@ int __init initrd_load(void)
88001 * mounted in the normal path.
88002 */
88003 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
88004 - sys_unlink("/initrd.image");
88005 + sys_unlink((const char __force_user *)"/initrd.image");
88006 handle_initrd();
88007 return 1;
88008 }
88009 }
88010 - sys_unlink("/initrd.image");
88011 + sys_unlink((const char __force_user *)"/initrd.image");
88012 return 0;
88013 }
88014 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
88015 index 8cb6db5..d729f50 100644
88016 --- a/init/do_mounts_md.c
88017 +++ b/init/do_mounts_md.c
88018 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
88019 partitioned ? "_d" : "", minor,
88020 md_setup_args[ent].device_names);
88021
88022 - fd = sys_open(name, 0, 0);
88023 + fd = sys_open((char __force_user *)name, 0, 0);
88024 if (fd < 0) {
88025 printk(KERN_ERR "md: open failed - cannot start "
88026 "array %s\n", name);
88027 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
88028 * array without it
88029 */
88030 sys_close(fd);
88031 - fd = sys_open(name, 0, 0);
88032 + fd = sys_open((char __force_user *)name, 0, 0);
88033 sys_ioctl(fd, BLKRRPART, 0);
88034 }
88035 sys_close(fd);
88036 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
88037
88038 wait_for_device_probe();
88039
88040 - fd = sys_open("/dev/md0", 0, 0);
88041 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
88042 if (fd >= 0) {
88043 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
88044 sys_close(fd);
88045 diff --git a/init/init_task.c b/init/init_task.c
88046 index ba0a7f36..2bcf1d5 100644
88047 --- a/init/init_task.c
88048 +++ b/init/init_task.c
88049 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
88050 * Initial thread structure. Alignment of this is handled by a special
88051 * linker map entry.
88052 */
88053 +#ifdef CONFIG_X86
88054 +union thread_union init_thread_union __init_task_data;
88055 +#else
88056 union thread_union init_thread_union __init_task_data =
88057 { INIT_THREAD_INFO(init_task) };
88058 +#endif
88059 diff --git a/init/initramfs.c b/init/initramfs.c
88060 index bece48c..e911bd8 100644
88061 --- a/init/initramfs.c
88062 +++ b/init/initramfs.c
88063 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
88064
88065 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
88066 while (count) {
88067 - ssize_t rv = sys_write(fd, p, count);
88068 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
88069
88070 if (rv < 0) {
88071 if (rv == -EINTR || rv == -EAGAIN)
88072 @@ -107,7 +107,7 @@ static void __init free_hash(void)
88073 }
88074 }
88075
88076 -static long __init do_utime(char *filename, time_t mtime)
88077 +static long __init do_utime(char __force_user *filename, time_t mtime)
88078 {
88079 struct timespec t[2];
88080
88081 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
88082 struct dir_entry *de, *tmp;
88083 list_for_each_entry_safe(de, tmp, &dir_list, list) {
88084 list_del(&de->list);
88085 - do_utime(de->name, de->mtime);
88086 + do_utime((char __force_user *)de->name, de->mtime);
88087 kfree(de->name);
88088 kfree(de);
88089 }
88090 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
88091 if (nlink >= 2) {
88092 char *old = find_link(major, minor, ino, mode, collected);
88093 if (old)
88094 - return (sys_link(old, collected) < 0) ? -1 : 1;
88095 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
88096 }
88097 return 0;
88098 }
88099 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
88100 {
88101 struct stat st;
88102
88103 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
88104 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
88105 if (S_ISDIR(st.st_mode))
88106 - sys_rmdir(path);
88107 + sys_rmdir((char __force_user *)path);
88108 else
88109 - sys_unlink(path);
88110 + sys_unlink((char __force_user *)path);
88111 }
88112 }
88113
88114 @@ -338,7 +338,7 @@ static int __init do_name(void)
88115 int openflags = O_WRONLY|O_CREAT;
88116 if (ml != 1)
88117 openflags |= O_TRUNC;
88118 - wfd = sys_open(collected, openflags, mode);
88119 + wfd = sys_open((char __force_user *)collected, openflags, mode);
88120
88121 if (wfd >= 0) {
88122 sys_fchown(wfd, uid, gid);
88123 @@ -350,17 +350,17 @@ static int __init do_name(void)
88124 }
88125 }
88126 } else if (S_ISDIR(mode)) {
88127 - sys_mkdir(collected, mode);
88128 - sys_chown(collected, uid, gid);
88129 - sys_chmod(collected, mode);
88130 + sys_mkdir((char __force_user *)collected, mode);
88131 + sys_chown((char __force_user *)collected, uid, gid);
88132 + sys_chmod((char __force_user *)collected, mode);
88133 dir_add(collected, mtime);
88134 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
88135 S_ISFIFO(mode) || S_ISSOCK(mode)) {
88136 if (maybe_link() == 0) {
88137 - sys_mknod(collected, mode, rdev);
88138 - sys_chown(collected, uid, gid);
88139 - sys_chmod(collected, mode);
88140 - do_utime(collected, mtime);
88141 + sys_mknod((char __force_user *)collected, mode, rdev);
88142 + sys_chown((char __force_user *)collected, uid, gid);
88143 + sys_chmod((char __force_user *)collected, mode);
88144 + do_utime((char __force_user *)collected, mtime);
88145 }
88146 }
88147 return 0;
88148 @@ -372,7 +372,7 @@ static int __init do_copy(void)
88149 if (xwrite(wfd, victim, body_len) != body_len)
88150 error("write error");
88151 sys_close(wfd);
88152 - do_utime(vcollected, mtime);
88153 + do_utime((char __force_user *)vcollected, mtime);
88154 kfree(vcollected);
88155 eat(body_len);
88156 state = SkipIt;
88157 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
88158 {
88159 collected[N_ALIGN(name_len) + body_len] = '\0';
88160 clean_path(collected, 0);
88161 - sys_symlink(collected + N_ALIGN(name_len), collected);
88162 - sys_lchown(collected, uid, gid);
88163 - do_utime(collected, mtime);
88164 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
88165 + sys_lchown((char __force_user *)collected, uid, gid);
88166 + do_utime((char __force_user *)collected, mtime);
88167 state = SkipIt;
88168 next_state = Reset;
88169 return 0;
88170 diff --git a/init/main.c b/init/main.c
88171 index d0f4b59..0c4b184 100644
88172 --- a/init/main.c
88173 +++ b/init/main.c
88174 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
88175 static inline void mark_rodata_ro(void) { }
88176 #endif
88177
88178 +extern void grsecurity_init(void);
88179 +
88180 /*
88181 * Debug helper: via this flag we know that we are in 'early bootup code'
88182 * where only the boot processor is running with IRQ disabled. This means
88183 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88184
88185 __setup("reset_devices", set_reset_devices);
88186
88187 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88188 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88189 +static int __init setup_grsec_proc_gid(char *str)
88190 +{
88191 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88192 + return 1;
88193 +}
88194 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88195 +#endif
88196 +
88197 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88198 +unsigned long pax_user_shadow_base __read_only;
88199 +EXPORT_SYMBOL(pax_user_shadow_base);
88200 +extern char pax_enter_kernel_user[];
88201 +extern char pax_exit_kernel_user[];
88202 +#endif
88203 +
88204 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88205 +static int __init setup_pax_nouderef(char *str)
88206 +{
88207 +#ifdef CONFIG_X86_32
88208 + unsigned int cpu;
88209 + struct desc_struct *gdt;
88210 +
88211 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88212 + gdt = get_cpu_gdt_table(cpu);
88213 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88214 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88215 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88216 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88217 + }
88218 + loadsegment(ds, __KERNEL_DS);
88219 + loadsegment(es, __KERNEL_DS);
88220 + loadsegment(ss, __KERNEL_DS);
88221 +#else
88222 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
88223 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
88224 + clone_pgd_mask = ~(pgdval_t)0UL;
88225 + pax_user_shadow_base = 0UL;
88226 + setup_clear_cpu_cap(X86_FEATURE_PCID);
88227 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
88228 +#endif
88229 +
88230 + return 0;
88231 +}
88232 +early_param("pax_nouderef", setup_pax_nouderef);
88233 +
88234 +#ifdef CONFIG_X86_64
88235 +static int __init setup_pax_weakuderef(char *str)
88236 +{
88237 + if (clone_pgd_mask != ~(pgdval_t)0UL)
88238 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
88239 + return 1;
88240 +}
88241 +__setup("pax_weakuderef", setup_pax_weakuderef);
88242 +#endif
88243 +#endif
88244 +
88245 +#ifdef CONFIG_PAX_SOFTMODE
88246 +int pax_softmode;
88247 +
88248 +static int __init setup_pax_softmode(char *str)
88249 +{
88250 + get_option(&str, &pax_softmode);
88251 + return 1;
88252 +}
88253 +__setup("pax_softmode=", setup_pax_softmode);
88254 +#endif
88255 +
88256 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
88257 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
88258 static const char *panic_later, *panic_param;
88259 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
88260 struct blacklist_entry *entry;
88261 char *fn_name;
88262
88263 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
88264 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
88265 if (!fn_name)
88266 return false;
88267
88268 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
88269 {
88270 int count = preempt_count();
88271 int ret;
88272 - char msgbuf[64];
88273 + const char *msg1 = "", *msg2 = "";
88274
88275 if (initcall_blacklisted(fn))
88276 return -EPERM;
88277 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88278 else
88279 ret = fn();
88280
88281 - msgbuf[0] = 0;
88282 -
88283 if (preempt_count() != count) {
88284 - sprintf(msgbuf, "preemption imbalance ");
88285 + msg1 = " preemption imbalance";
88286 preempt_count_set(count);
88287 }
88288 if (irqs_disabled()) {
88289 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88290 + msg2 = " disabled interrupts";
88291 local_irq_enable();
88292 }
88293 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88294 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88295
88296 + add_latent_entropy();
88297 return ret;
88298 }
88299
88300 @@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
88301 {
88302 argv_init[0] = init_filename;
88303 return do_execve(getname_kernel(init_filename),
88304 - (const char __user *const __user *)argv_init,
88305 - (const char __user *const __user *)envp_init);
88306 + (const char __user *const __force_user *)argv_init,
88307 + (const char __user *const __force_user *)envp_init);
88308 }
88309
88310 static int try_to_run_init_process(const char *init_filename)
88311 @@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
88312 return ret;
88313 }
88314
88315 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88316 +extern int gr_init_ran;
88317 +#endif
88318 +
88319 static noinline void __init kernel_init_freeable(void);
88320
88321 static int __ref kernel_init(void *unused)
88322 @@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
88323 ramdisk_execute_command, ret);
88324 }
88325
88326 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88327 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88328 + gr_init_ran = 1;
88329 +#endif
88330 +
88331 /*
88332 * We try each of these until one succeeds.
88333 *
88334 @@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
88335 do_basic_setup();
88336
88337 /* Open the /dev/console on the rootfs, this should never fail */
88338 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88339 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88340 pr_err("Warning: unable to open an initial console.\n");
88341
88342 (void) sys_dup(0);
88343 @@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
88344 if (!ramdisk_execute_command)
88345 ramdisk_execute_command = "/init";
88346
88347 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88348 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88349 ramdisk_execute_command = NULL;
88350 prepare_namespace();
88351 }
88352
88353 + grsecurity_init();
88354 +
88355 /*
88356 * Ok, we have completed the initial bootup, and
88357 * we're essentially up and running. Get rid of the
88358 diff --git a/ipc/compat.c b/ipc/compat.c
88359 index b5ef4f7..ff31d87 100644
88360 --- a/ipc/compat.c
88361 +++ b/ipc/compat.c
88362 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88363 COMPAT_SHMLBA);
88364 if (err < 0)
88365 return err;
88366 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88367 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88368 }
88369 case SHMDT:
88370 return sys_shmdt(compat_ptr(ptr));
88371 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88372 index e8075b2..76f2c6a 100644
88373 --- a/ipc/ipc_sysctl.c
88374 +++ b/ipc/ipc_sysctl.c
88375 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88376 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88377 void __user *buffer, size_t *lenp, loff_t *ppos)
88378 {
88379 - struct ctl_table ipc_table;
88380 + ctl_table_no_const ipc_table;
88381
88382 memcpy(&ipc_table, table, sizeof(ipc_table));
88383 ipc_table.data = get_ipc(table);
88384 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88385 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88386 void __user *buffer, size_t *lenp, loff_t *ppos)
88387 {
88388 - struct ctl_table ipc_table;
88389 + ctl_table_no_const ipc_table;
88390
88391 memcpy(&ipc_table, table, sizeof(ipc_table));
88392 ipc_table.data = get_ipc(table);
88393 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88394 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88395 void __user *buffer, size_t *lenp, loff_t *ppos)
88396 {
88397 - struct ctl_table ipc_table;
88398 + ctl_table_no_const ipc_table;
88399 size_t lenp_bef = *lenp;
88400 int rc;
88401
88402 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88403 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88404 void __user *buffer, size_t *lenp, loff_t *ppos)
88405 {
88406 - struct ctl_table ipc_table;
88407 + ctl_table_no_const ipc_table;
88408 memcpy(&ipc_table, table, sizeof(ipc_table));
88409 ipc_table.data = get_ipc(table);
88410
88411 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88412 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88413 void __user *buffer, size_t *lenp, loff_t *ppos)
88414 {
88415 - struct ctl_table ipc_table;
88416 + ctl_table_no_const ipc_table;
88417 int oldval;
88418 int rc;
88419
88420 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88421 index 68d4e95..1477ded 100644
88422 --- a/ipc/mq_sysctl.c
88423 +++ b/ipc/mq_sysctl.c
88424 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88425 static int proc_mq_dointvec(struct ctl_table *table, int write,
88426 void __user *buffer, size_t *lenp, loff_t *ppos)
88427 {
88428 - struct ctl_table mq_table;
88429 + ctl_table_no_const mq_table;
88430 memcpy(&mq_table, table, sizeof(mq_table));
88431 mq_table.data = get_mq(table);
88432
88433 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88434 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88435 void __user *buffer, size_t *lenp, loff_t *ppos)
88436 {
88437 - struct ctl_table mq_table;
88438 + ctl_table_no_const mq_table;
88439 memcpy(&mq_table, table, sizeof(mq_table));
88440 mq_table.data = get_mq(table);
88441
88442 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88443 index 4fcf39a..d3cc2ec 100644
88444 --- a/ipc/mqueue.c
88445 +++ b/ipc/mqueue.c
88446 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88447 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88448 info->attr.mq_msgsize);
88449
88450 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88451 spin_lock(&mq_lock);
88452 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88453 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88454 diff --git a/ipc/shm.c b/ipc/shm.c
88455 index 7fc9f9f..95e201f 100644
88456 --- a/ipc/shm.c
88457 +++ b/ipc/shm.c
88458 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88459 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88460 #endif
88461
88462 +#ifdef CONFIG_GRKERNSEC
88463 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88464 + const u64 shm_createtime, const kuid_t cuid,
88465 + const int shmid);
88466 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88467 + const u64 shm_createtime);
88468 +#endif
88469 +
88470 void shm_init_ns(struct ipc_namespace *ns)
88471 {
88472 ns->shm_ctlmax = SHMMAX;
88473 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88474 shp->shm_lprid = 0;
88475 shp->shm_atim = shp->shm_dtim = 0;
88476 shp->shm_ctim = get_seconds();
88477 +#ifdef CONFIG_GRKERNSEC
88478 + shp->shm_createtime = ktime_get_ns();
88479 +#endif
88480 shp->shm_segsz = size;
88481 shp->shm_nattch = 0;
88482 shp->shm_file = file;
88483 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88484 f_mode = FMODE_READ | FMODE_WRITE;
88485 }
88486 if (shmflg & SHM_EXEC) {
88487 +
88488 +#ifdef CONFIG_PAX_MPROTECT
88489 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88490 + goto out;
88491 +#endif
88492 +
88493 prot |= PROT_EXEC;
88494 acc_mode |= S_IXUGO;
88495 }
88496 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88497 if (err)
88498 goto out_unlock;
88499
88500 +#ifdef CONFIG_GRKERNSEC
88501 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88502 + shp->shm_perm.cuid, shmid) ||
88503 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88504 + err = -EACCES;
88505 + goto out_unlock;
88506 + }
88507 +#endif
88508 +
88509 ipc_lock_object(&shp->shm_perm);
88510
88511 /* check if shm_destroy() is tearing down shp */
88512 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88513 path = shp->shm_file->f_path;
88514 path_get(&path);
88515 shp->shm_nattch++;
88516 +#ifdef CONFIG_GRKERNSEC
88517 + shp->shm_lapid = current->pid;
88518 +#endif
88519 size = i_size_read(path.dentry->d_inode);
88520 ipc_unlock_object(&shp->shm_perm);
88521 rcu_read_unlock();
88522 diff --git a/ipc/util.c b/ipc/util.c
88523 index 27d74e6..8be0be2 100644
88524 --- a/ipc/util.c
88525 +++ b/ipc/util.c
88526 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88527 int (*show)(struct seq_file *, void *);
88528 };
88529
88530 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88531 +
88532 static void ipc_memory_notifier(struct work_struct *work)
88533 {
88534 ipcns_notify(IPCNS_MEMCHANGED);
88535 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88536 granted_mode >>= 6;
88537 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88538 granted_mode >>= 3;
88539 +
88540 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88541 + return -1;
88542 +
88543 /* is there some bit set in requested_mode but not in granted_mode? */
88544 if ((requested_mode & ~granted_mode & 0007) &&
88545 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88546 diff --git a/kernel/audit.c b/kernel/audit.c
88547 index 6726aa6..bb864a9 100644
88548 --- a/kernel/audit.c
88549 +++ b/kernel/audit.c
88550 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88551 3) suppressed due to audit_rate_limit
88552 4) suppressed due to audit_backlog_limit
88553 */
88554 -static atomic_t audit_lost = ATOMIC_INIT(0);
88555 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88556
88557 /* The netlink socket. */
88558 static struct sock *audit_sock;
88559 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88560 unsigned long now;
88561 int print;
88562
88563 - atomic_inc(&audit_lost);
88564 + atomic_inc_unchecked(&audit_lost);
88565
88566 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88567
88568 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88569 if (print) {
88570 if (printk_ratelimit())
88571 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88572 - atomic_read(&audit_lost),
88573 + atomic_read_unchecked(&audit_lost),
88574 audit_rate_limit,
88575 audit_backlog_limit);
88576 audit_panic(message);
88577 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88578 s.pid = audit_pid;
88579 s.rate_limit = audit_rate_limit;
88580 s.backlog_limit = audit_backlog_limit;
88581 - s.lost = atomic_read(&audit_lost);
88582 + s.lost = atomic_read_unchecked(&audit_lost);
88583 s.backlog = skb_queue_len(&audit_skb_queue);
88584 s.version = AUDIT_VERSION_LATEST;
88585 s.backlog_wait_time = audit_backlog_wait_time;
88586 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88587 index 21eae3c..66db239 100644
88588 --- a/kernel/auditsc.c
88589 +++ b/kernel/auditsc.c
88590 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88591 }
88592
88593 /* global counter which is incremented every time something logs in */
88594 -static atomic_t session_id = ATOMIC_INIT(0);
88595 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88596
88597 static int audit_set_loginuid_perm(kuid_t loginuid)
88598 {
88599 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
88600
88601 /* are we setting or clearing? */
88602 if (uid_valid(loginuid))
88603 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88604 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88605
88606 task->sessionid = sessionid;
88607 task->loginuid = loginuid;
88608 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88609 index 7f0dbcb..b54bb2c 100644
88610 --- a/kernel/bpf/core.c
88611 +++ b/kernel/bpf/core.c
88612 @@ -22,6 +22,7 @@
88613 */
88614 #include <linux/filter.h>
88615 #include <linux/skbuff.h>
88616 +#include <linux/vmalloc.h>
88617 #include <asm/unaligned.h>
88618
88619 /* Registers */
88620 @@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
88621 return NULL;
88622 }
88623
88624 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
88625 +{
88626 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88627 + gfp_extra_flags;
88628 + struct bpf_work_struct *ws;
88629 + struct bpf_prog *fp;
88630 +
88631 + size = round_up(size, PAGE_SIZE);
88632 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88633 + if (fp == NULL)
88634 + return NULL;
88635 +
88636 + ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
88637 + if (ws == NULL) {
88638 + vfree(fp);
88639 + return NULL;
88640 + }
88641 +
88642 + fp->pages = size / PAGE_SIZE;
88643 + fp->work = ws;
88644 +
88645 + return fp;
88646 +}
88647 +EXPORT_SYMBOL_GPL(bpf_prog_alloc);
88648 +
88649 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
88650 + gfp_t gfp_extra_flags)
88651 +{
88652 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88653 + gfp_extra_flags;
88654 + struct bpf_prog *fp;
88655 +
88656 + BUG_ON(fp_old == NULL);
88657 +
88658 + size = round_up(size, PAGE_SIZE);
88659 + if (size <= fp_old->pages * PAGE_SIZE)
88660 + return fp_old;
88661 +
88662 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88663 + if (fp != NULL) {
88664 + memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
88665 + fp->pages = size / PAGE_SIZE;
88666 +
88667 + /* We keep fp->work from fp_old around in the new
88668 + * reallocated structure.
88669 + */
88670 + fp_old->work = NULL;
88671 + __bpf_prog_free(fp_old);
88672 + }
88673 +
88674 + return fp;
88675 +}
88676 +EXPORT_SYMBOL_GPL(bpf_prog_realloc);
88677 +
88678 +void __bpf_prog_free(struct bpf_prog *fp)
88679 +{
88680 + kfree(fp->work);
88681 + vfree(fp);
88682 +}
88683 +EXPORT_SYMBOL_GPL(__bpf_prog_free);
88684 +
88685 /* Base function for offset calculation. Needs to go into .text section,
88686 * therefore keeping it non-static as well; will also be used by JITs
88687 * anyway later on, so do not let the compiler omit it.
88688 @@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
88689
88690 /* Probe if internal BPF can be JITed */
88691 bpf_int_jit_compile(fp);
88692 + /* Lock whole bpf_prog as read-only */
88693 + bpf_prog_lock_ro(fp);
88694 }
88695 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
88696
88697 -/* free internal BPF program */
88698 +static void bpf_prog_free_deferred(struct work_struct *work)
88699 +{
88700 + struct bpf_work_struct *ws;
88701 +
88702 + ws = container_of(work, struct bpf_work_struct, work);
88703 + bpf_jit_free(ws->prog);
88704 +}
88705 +
88706 +/* Free internal BPF program */
88707 void bpf_prog_free(struct bpf_prog *fp)
88708 {
88709 - bpf_jit_free(fp);
88710 + struct bpf_work_struct *ws = fp->work;
88711 +
88712 + INIT_WORK(&ws->work, bpf_prog_free_deferred);
88713 + ws->prog = fp;
88714 + schedule_work(&ws->work);
88715 }
88716 EXPORT_SYMBOL_GPL(bpf_prog_free);
88717 diff --git a/kernel/capability.c b/kernel/capability.c
88718 index 989f5bf..d317ca0 100644
88719 --- a/kernel/capability.c
88720 +++ b/kernel/capability.c
88721 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88722 * before modification is attempted and the application
88723 * fails.
88724 */
88725 + if (tocopy > ARRAY_SIZE(kdata))
88726 + return -EFAULT;
88727 +
88728 if (copy_to_user(dataptr, kdata, tocopy
88729 * sizeof(struct __user_cap_data_struct))) {
88730 return -EFAULT;
88731 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88732 int ret;
88733
88734 rcu_read_lock();
88735 - ret = security_capable(__task_cred(t), ns, cap);
88736 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88737 + gr_task_is_capable(t, __task_cred(t), cap);
88738 rcu_read_unlock();
88739
88740 - return (ret == 0);
88741 + return ret;
88742 }
88743
88744 /**
88745 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88746 int ret;
88747
88748 rcu_read_lock();
88749 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88750 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88751 rcu_read_unlock();
88752
88753 - return (ret == 0);
88754 + return ret;
88755 }
88756
88757 /**
88758 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88759 BUG();
88760 }
88761
88762 - if (security_capable(current_cred(), ns, cap) == 0) {
88763 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88764 current->flags |= PF_SUPERPRIV;
88765 return true;
88766 }
88767 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88768 }
88769 EXPORT_SYMBOL(ns_capable);
88770
88771 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88772 +{
88773 + if (unlikely(!cap_valid(cap))) {
88774 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88775 + BUG();
88776 + }
88777 +
88778 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88779 + current->flags |= PF_SUPERPRIV;
88780 + return true;
88781 + }
88782 + return false;
88783 +}
88784 +EXPORT_SYMBOL(ns_capable_nolog);
88785 +
88786 /**
88787 * file_ns_capable - Determine if the file's opener had a capability in effect
88788 * @file: The file we want to check
88789 @@ -427,6 +446,12 @@ bool capable(int cap)
88790 }
88791 EXPORT_SYMBOL(capable);
88792
88793 +bool capable_nolog(int cap)
88794 +{
88795 + return ns_capable_nolog(&init_user_ns, cap);
88796 +}
88797 +EXPORT_SYMBOL(capable_nolog);
88798 +
88799 /**
88800 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88801 * @inode: The inode in question
88802 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88803 kgid_has_mapping(ns, inode->i_gid);
88804 }
88805 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88806 +
88807 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88808 +{
88809 + struct user_namespace *ns = current_user_ns();
88810 +
88811 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88812 + kgid_has_mapping(ns, inode->i_gid);
88813 +}
88814 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88815 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88816 index 3a73f99..4f29fea 100644
88817 --- a/kernel/cgroup.c
88818 +++ b/kernel/cgroup.c
88819 @@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
88820 release_list);
88821 list_del_init(&cgrp->release_list);
88822 raw_spin_unlock(&release_list_lock);
88823 +
88824 + /*
88825 + * don't bother calling call_usermodehelper if we haven't
88826 + * configured a binary to execute
88827 + */
88828 + if (cgrp->root->release_agent_path[0] == '\0')
88829 + goto continue_free;
88830 +
88831 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
88832 if (!pathbuf)
88833 goto continue_free;
88834 @@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88835 struct task_struct *task;
88836 int count = 0;
88837
88838 - seq_printf(seq, "css_set %p\n", cset);
88839 + seq_printf(seq, "css_set %pK\n", cset);
88840
88841 list_for_each_entry(task, &cset->tasks, cg_list) {
88842 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88843 diff --git a/kernel/compat.c b/kernel/compat.c
88844 index ebb3c36..1df606e 100644
88845 --- a/kernel/compat.c
88846 +++ b/kernel/compat.c
88847 @@ -13,6 +13,7 @@
88848
88849 #include <linux/linkage.h>
88850 #include <linux/compat.h>
88851 +#include <linux/module.h>
88852 #include <linux/errno.h>
88853 #include <linux/time.h>
88854 #include <linux/signal.h>
88855 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88856 mm_segment_t oldfs;
88857 long ret;
88858
88859 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88860 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88861 oldfs = get_fs();
88862 set_fs(KERNEL_DS);
88863 ret = hrtimer_nanosleep_restart(restart);
88864 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88865 oldfs = get_fs();
88866 set_fs(KERNEL_DS);
88867 ret = hrtimer_nanosleep(&tu,
88868 - rmtp ? (struct timespec __user *)&rmt : NULL,
88869 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88870 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88871 set_fs(oldfs);
88872
88873 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88874 mm_segment_t old_fs = get_fs();
88875
88876 set_fs(KERNEL_DS);
88877 - ret = sys_sigpending((old_sigset_t __user *) &s);
88878 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88879 set_fs(old_fs);
88880 if (ret == 0)
88881 ret = put_user(s, set);
88882 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88883 mm_segment_t old_fs = get_fs();
88884
88885 set_fs(KERNEL_DS);
88886 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88887 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88888 set_fs(old_fs);
88889
88890 if (!ret) {
88891 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88892 set_fs (KERNEL_DS);
88893 ret = sys_wait4(pid,
88894 (stat_addr ?
88895 - (unsigned int __user *) &status : NULL),
88896 - options, (struct rusage __user *) &r);
88897 + (unsigned int __force_user *) &status : NULL),
88898 + options, (struct rusage __force_user *) &r);
88899 set_fs (old_fs);
88900
88901 if (ret > 0) {
88902 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88903 memset(&info, 0, sizeof(info));
88904
88905 set_fs(KERNEL_DS);
88906 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88907 - uru ? (struct rusage __user *)&ru : NULL);
88908 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88909 + uru ? (struct rusage __force_user *)&ru : NULL);
88910 set_fs(old_fs);
88911
88912 if ((ret < 0) || (info.si_signo == 0))
88913 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88914 oldfs = get_fs();
88915 set_fs(KERNEL_DS);
88916 err = sys_timer_settime(timer_id, flags,
88917 - (struct itimerspec __user *) &newts,
88918 - (struct itimerspec __user *) &oldts);
88919 + (struct itimerspec __force_user *) &newts,
88920 + (struct itimerspec __force_user *) &oldts);
88921 set_fs(oldfs);
88922 if (!err && old && put_compat_itimerspec(old, &oldts))
88923 return -EFAULT;
88924 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88925 oldfs = get_fs();
88926 set_fs(KERNEL_DS);
88927 err = sys_timer_gettime(timer_id,
88928 - (struct itimerspec __user *) &ts);
88929 + (struct itimerspec __force_user *) &ts);
88930 set_fs(oldfs);
88931 if (!err && put_compat_itimerspec(setting, &ts))
88932 return -EFAULT;
88933 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88934 oldfs = get_fs();
88935 set_fs(KERNEL_DS);
88936 err = sys_clock_settime(which_clock,
88937 - (struct timespec __user *) &ts);
88938 + (struct timespec __force_user *) &ts);
88939 set_fs(oldfs);
88940 return err;
88941 }
88942 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88943 oldfs = get_fs();
88944 set_fs(KERNEL_DS);
88945 err = sys_clock_gettime(which_clock,
88946 - (struct timespec __user *) &ts);
88947 + (struct timespec __force_user *) &ts);
88948 set_fs(oldfs);
88949 if (!err && compat_put_timespec(&ts, tp))
88950 return -EFAULT;
88951 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88952
88953 oldfs = get_fs();
88954 set_fs(KERNEL_DS);
88955 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88956 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88957 set_fs(oldfs);
88958
88959 err = compat_put_timex(utp, &txc);
88960 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88961 oldfs = get_fs();
88962 set_fs(KERNEL_DS);
88963 err = sys_clock_getres(which_clock,
88964 - (struct timespec __user *) &ts);
88965 + (struct timespec __force_user *) &ts);
88966 set_fs(oldfs);
88967 if (!err && tp && compat_put_timespec(&ts, tp))
88968 return -EFAULT;
88969 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88970 struct timespec tu;
88971 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88972
88973 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88974 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88975 oldfs = get_fs();
88976 set_fs(KERNEL_DS);
88977 err = clock_nanosleep_restart(restart);
88978 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88979 oldfs = get_fs();
88980 set_fs(KERNEL_DS);
88981 err = sys_clock_nanosleep(which_clock, flags,
88982 - (struct timespec __user *) &in,
88983 - (struct timespec __user *) &out);
88984 + (struct timespec __force_user *) &in,
88985 + (struct timespec __force_user *) &out);
88986 set_fs(oldfs);
88987
88988 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88989 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88990 mm_segment_t old_fs = get_fs();
88991
88992 set_fs(KERNEL_DS);
88993 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88994 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88995 set_fs(old_fs);
88996 if (compat_put_timespec(&t, interval))
88997 return -EFAULT;
88998 diff --git a/kernel/configs.c b/kernel/configs.c
88999 index c18b1f1..b9a0132 100644
89000 --- a/kernel/configs.c
89001 +++ b/kernel/configs.c
89002 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
89003 struct proc_dir_entry *entry;
89004
89005 /* create the current config file */
89006 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
89007 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
89008 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
89009 + &ikconfig_file_ops);
89010 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89011 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
89012 + &ikconfig_file_ops);
89013 +#endif
89014 +#else
89015 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
89016 &ikconfig_file_ops);
89017 +#endif
89018 +
89019 if (!entry)
89020 return -ENOMEM;
89021
89022 diff --git a/kernel/cred.c b/kernel/cred.c
89023 index e0573a4..26c0fd3 100644
89024 --- a/kernel/cred.c
89025 +++ b/kernel/cred.c
89026 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
89027 validate_creds(cred);
89028 alter_cred_subscribers(cred, -1);
89029 put_cred(cred);
89030 +
89031 +#ifdef CONFIG_GRKERNSEC_SETXID
89032 + cred = (struct cred *) tsk->delayed_cred;
89033 + if (cred != NULL) {
89034 + tsk->delayed_cred = NULL;
89035 + validate_creds(cred);
89036 + alter_cred_subscribers(cred, -1);
89037 + put_cred(cred);
89038 + }
89039 +#endif
89040 }
89041
89042 /**
89043 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
89044 * Always returns 0 thus allowing this function to be tail-called at the end
89045 * of, say, sys_setgid().
89046 */
89047 -int commit_creds(struct cred *new)
89048 +static int __commit_creds(struct cred *new)
89049 {
89050 struct task_struct *task = current;
89051 const struct cred *old = task->real_cred;
89052 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
89053
89054 get_cred(new); /* we will require a ref for the subj creds too */
89055
89056 + gr_set_role_label(task, new->uid, new->gid);
89057 +
89058 /* dumpability changes */
89059 if (!uid_eq(old->euid, new->euid) ||
89060 !gid_eq(old->egid, new->egid) ||
89061 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
89062 put_cred(old);
89063 return 0;
89064 }
89065 +#ifdef CONFIG_GRKERNSEC_SETXID
89066 +extern int set_user(struct cred *new);
89067 +
89068 +void gr_delayed_cred_worker(void)
89069 +{
89070 + const struct cred *new = current->delayed_cred;
89071 + struct cred *ncred;
89072 +
89073 + current->delayed_cred = NULL;
89074 +
89075 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
89076 + // from doing get_cred on it when queueing this
89077 + put_cred(new);
89078 + return;
89079 + } else if (new == NULL)
89080 + return;
89081 +
89082 + ncred = prepare_creds();
89083 + if (!ncred)
89084 + goto die;
89085 + // uids
89086 + ncred->uid = new->uid;
89087 + ncred->euid = new->euid;
89088 + ncred->suid = new->suid;
89089 + ncred->fsuid = new->fsuid;
89090 + // gids
89091 + ncred->gid = new->gid;
89092 + ncred->egid = new->egid;
89093 + ncred->sgid = new->sgid;
89094 + ncred->fsgid = new->fsgid;
89095 + // groups
89096 + set_groups(ncred, new->group_info);
89097 + // caps
89098 + ncred->securebits = new->securebits;
89099 + ncred->cap_inheritable = new->cap_inheritable;
89100 + ncred->cap_permitted = new->cap_permitted;
89101 + ncred->cap_effective = new->cap_effective;
89102 + ncred->cap_bset = new->cap_bset;
89103 +
89104 + if (set_user(ncred)) {
89105 + abort_creds(ncred);
89106 + goto die;
89107 + }
89108 +
89109 + // from doing get_cred on it when queueing this
89110 + put_cred(new);
89111 +
89112 + __commit_creds(ncred);
89113 + return;
89114 +die:
89115 + // from doing get_cred on it when queueing this
89116 + put_cred(new);
89117 + do_group_exit(SIGKILL);
89118 +}
89119 +#endif
89120 +
89121 +int commit_creds(struct cred *new)
89122 +{
89123 +#ifdef CONFIG_GRKERNSEC_SETXID
89124 + int ret;
89125 + int schedule_it = 0;
89126 + struct task_struct *t;
89127 + unsigned oldsecurebits = current_cred()->securebits;
89128 +
89129 + /* we won't get called with tasklist_lock held for writing
89130 + and interrupts disabled as the cred struct in that case is
89131 + init_cred
89132 + */
89133 + if (grsec_enable_setxid && !current_is_single_threaded() &&
89134 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
89135 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
89136 + schedule_it = 1;
89137 + }
89138 + ret = __commit_creds(new);
89139 + if (schedule_it) {
89140 + rcu_read_lock();
89141 + read_lock(&tasklist_lock);
89142 + for (t = next_thread(current); t != current;
89143 + t = next_thread(t)) {
89144 + /* we'll check if the thread has uid 0 in
89145 + * the delayed worker routine
89146 + */
89147 + if (task_securebits(t) == oldsecurebits &&
89148 + t->delayed_cred == NULL) {
89149 + t->delayed_cred = get_cred(new);
89150 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
89151 + set_tsk_need_resched(t);
89152 + }
89153 + }
89154 + read_unlock(&tasklist_lock);
89155 + rcu_read_unlock();
89156 + }
89157 +
89158 + return ret;
89159 +#else
89160 + return __commit_creds(new);
89161 +#endif
89162 +}
89163 +
89164 EXPORT_SYMBOL(commit_creds);
89165
89166 /**
89167 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
89168 index 1adf62b..7736e06 100644
89169 --- a/kernel/debug/debug_core.c
89170 +++ b/kernel/debug/debug_core.c
89171 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
89172 */
89173 static atomic_t masters_in_kgdb;
89174 static atomic_t slaves_in_kgdb;
89175 -static atomic_t kgdb_break_tasklet_var;
89176 +static atomic_unchecked_t kgdb_break_tasklet_var;
89177 atomic_t kgdb_setting_breakpoint;
89178
89179 struct task_struct *kgdb_usethread;
89180 @@ -134,7 +134,7 @@ int kgdb_single_step;
89181 static pid_t kgdb_sstep_pid;
89182
89183 /* to keep track of the CPU which is doing the single stepping*/
89184 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89185 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89186
89187 /*
89188 * If you are debugging a problem where roundup (the collection of
89189 @@ -549,7 +549,7 @@ return_normal:
89190 * kernel will only try for the value of sstep_tries before
89191 * giving up and continuing on.
89192 */
89193 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
89194 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
89195 (kgdb_info[cpu].task &&
89196 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
89197 atomic_set(&kgdb_active, -1);
89198 @@ -647,8 +647,8 @@ cpu_master_loop:
89199 }
89200
89201 kgdb_restore:
89202 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
89203 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
89204 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
89205 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
89206 if (kgdb_info[sstep_cpu].task)
89207 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
89208 else
89209 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
89210 static void kgdb_tasklet_bpt(unsigned long ing)
89211 {
89212 kgdb_breakpoint();
89213 - atomic_set(&kgdb_break_tasklet_var, 0);
89214 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
89215 }
89216
89217 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
89218
89219 void kgdb_schedule_breakpoint(void)
89220 {
89221 - if (atomic_read(&kgdb_break_tasklet_var) ||
89222 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
89223 atomic_read(&kgdb_active) != -1 ||
89224 atomic_read(&kgdb_setting_breakpoint))
89225 return;
89226 - atomic_inc(&kgdb_break_tasklet_var);
89227 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
89228 tasklet_schedule(&kgdb_tasklet_breakpoint);
89229 }
89230 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
89231 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
89232 index 379650b..30c5180 100644
89233 --- a/kernel/debug/kdb/kdb_main.c
89234 +++ b/kernel/debug/kdb/kdb_main.c
89235 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
89236 continue;
89237
89238 kdb_printf("%-20s%8u 0x%p ", mod->name,
89239 - mod->core_size, (void *)mod);
89240 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
89241 #ifdef CONFIG_MODULE_UNLOAD
89242 kdb_printf("%4ld ", module_refcount(mod));
89243 #endif
89244 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89245 kdb_printf(" (Loading)");
89246 else
89247 kdb_printf(" (Live)");
89248 - kdb_printf(" 0x%p", mod->module_core);
89249 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89250
89251 #ifdef CONFIG_MODULE_UNLOAD
89252 {
89253 diff --git a/kernel/events/core.c b/kernel/events/core.c
89254 index 658f232..32e9595 100644
89255 --- a/kernel/events/core.c
89256 +++ b/kernel/events/core.c
89257 @@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
89258 * 0 - disallow raw tracepoint access for unpriv
89259 * 1 - disallow cpu events for unpriv
89260 * 2 - disallow kernel profiling for unpriv
89261 + * 3 - disallow all unpriv perf event use
89262 */
89263 -int sysctl_perf_event_paranoid __read_mostly = 1;
89264 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89265 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89266 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89267 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89268 +#else
89269 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89270 +#endif
89271
89272 /* Minimum for 512 kiB + 1 user control page */
89273 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89274 @@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
89275
89276 tmp *= sysctl_perf_cpu_time_max_percent;
89277 do_div(tmp, 100);
89278 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89279 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89280 }
89281
89282 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89283 @@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89284 }
89285 }
89286
89287 -static atomic64_t perf_event_id;
89288 +static atomic64_unchecked_t perf_event_id;
89289
89290 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89291 enum event_type_t event_type);
89292 @@ -3051,7 +3058,7 @@ static void __perf_event_read(void *info)
89293
89294 static inline u64 perf_event_count(struct perf_event *event)
89295 {
89296 - return local64_read(&event->count) + atomic64_read(&event->child_count);
89297 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89298 }
89299
89300 static u64 perf_event_read(struct perf_event *event)
89301 @@ -3430,9 +3437,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89302 mutex_lock(&event->child_mutex);
89303 total += perf_event_read(event);
89304 *enabled += event->total_time_enabled +
89305 - atomic64_read(&event->child_total_time_enabled);
89306 + atomic64_read_unchecked(&event->child_total_time_enabled);
89307 *running += event->total_time_running +
89308 - atomic64_read(&event->child_total_time_running);
89309 + atomic64_read_unchecked(&event->child_total_time_running);
89310
89311 list_for_each_entry(child, &event->child_list, child_list) {
89312 total += perf_event_read(child);
89313 @@ -3881,10 +3888,10 @@ void perf_event_update_userpage(struct perf_event *event)
89314 userpg->offset -= local64_read(&event->hw.prev_count);
89315
89316 userpg->time_enabled = enabled +
89317 - atomic64_read(&event->child_total_time_enabled);
89318 + atomic64_read_unchecked(&event->child_total_time_enabled);
89319
89320 userpg->time_running = running +
89321 - atomic64_read(&event->child_total_time_running);
89322 + atomic64_read_unchecked(&event->child_total_time_running);
89323
89324 arch_perf_update_userpage(userpg, now);
89325
89326 @@ -4448,7 +4455,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89327
89328 /* Data. */
89329 sp = perf_user_stack_pointer(regs);
89330 - rem = __output_copy_user(handle, (void *) sp, dump_size);
89331 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89332 dyn_size = dump_size - rem;
89333
89334 perf_output_skip(handle, rem);
89335 @@ -4539,11 +4546,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89336 values[n++] = perf_event_count(event);
89337 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89338 values[n++] = enabled +
89339 - atomic64_read(&event->child_total_time_enabled);
89340 + atomic64_read_unchecked(&event->child_total_time_enabled);
89341 }
89342 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89343 values[n++] = running +
89344 - atomic64_read(&event->child_total_time_running);
89345 + atomic64_read_unchecked(&event->child_total_time_running);
89346 }
89347 if (read_format & PERF_FORMAT_ID)
89348 values[n++] = primary_event_id(event);
89349 @@ -6858,7 +6865,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89350 event->parent = parent_event;
89351
89352 event->ns = get_pid_ns(task_active_pid_ns(current));
89353 - event->id = atomic64_inc_return(&perf_event_id);
89354 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89355
89356 event->state = PERF_EVENT_STATE_INACTIVE;
89357
89358 @@ -7137,6 +7144,11 @@ SYSCALL_DEFINE5(perf_event_open,
89359 if (flags & ~PERF_FLAG_ALL)
89360 return -EINVAL;
89361
89362 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89363 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89364 + return -EACCES;
89365 +#endif
89366 +
89367 err = perf_copy_attr(attr_uptr, &attr);
89368 if (err)
89369 return err;
89370 @@ -7489,10 +7501,10 @@ static void sync_child_event(struct perf_event *child_event,
89371 /*
89372 * Add back the child's count to the parent's count:
89373 */
89374 - atomic64_add(child_val, &parent_event->child_count);
89375 - atomic64_add(child_event->total_time_enabled,
89376 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89377 + atomic64_add_unchecked(child_event->total_time_enabled,
89378 &parent_event->child_total_time_enabled);
89379 - atomic64_add(child_event->total_time_running,
89380 + atomic64_add_unchecked(child_event->total_time_running,
89381 &parent_event->child_total_time_running);
89382
89383 /*
89384 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89385 index 569b2187..19940d9 100644
89386 --- a/kernel/events/internal.h
89387 +++ b/kernel/events/internal.h
89388 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89389 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89390 }
89391
89392 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89393 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89394 static inline unsigned long \
89395 func_name(struct perf_output_handle *handle, \
89396 - const void *buf, unsigned long len) \
89397 + const void user *buf, unsigned long len) \
89398 { \
89399 unsigned long size, written; \
89400 \
89401 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89402 return 0;
89403 }
89404
89405 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89406 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89407
89408 static inline unsigned long
89409 memcpy_skip(void *dst, const void *src, unsigned long n)
89410 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89411 return 0;
89412 }
89413
89414 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89415 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89416
89417 #ifndef arch_perf_out_copy_user
89418 #define arch_perf_out_copy_user arch_perf_out_copy_user
89419 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89420 }
89421 #endif
89422
89423 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89424 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89425
89426 /* Callchain handling */
89427 extern struct perf_callchain_entry *
89428 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89429 index ed8f2cd..fe8030c 100644
89430 --- a/kernel/events/uprobes.c
89431 +++ b/kernel/events/uprobes.c
89432 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89433 {
89434 struct page *page;
89435 uprobe_opcode_t opcode;
89436 - int result;
89437 + long result;
89438
89439 pagefault_disable();
89440 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89441 diff --git a/kernel/exit.c b/kernel/exit.c
89442 index 32c58f7..9eb6907 100644
89443 --- a/kernel/exit.c
89444 +++ b/kernel/exit.c
89445 @@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
89446 struct task_struct *leader;
89447 int zap_leader;
89448 repeat:
89449 +#ifdef CONFIG_NET
89450 + gr_del_task_from_ip_table(p);
89451 +#endif
89452 +
89453 /* don't need to get the RCU readlock here - the process is dead and
89454 * can't be modifying its own credentials. But shut RCU-lockdep up */
89455 rcu_read_lock();
89456 @@ -668,6 +672,8 @@ void do_exit(long code)
89457 struct task_struct *tsk = current;
89458 int group_dead;
89459
89460 + set_fs(USER_DS);
89461 +
89462 profile_task_exit(tsk);
89463
89464 WARN_ON(blk_needs_flush_plug(tsk));
89465 @@ -684,7 +690,6 @@ void do_exit(long code)
89466 * mm_release()->clear_child_tid() from writing to a user-controlled
89467 * kernel address.
89468 */
89469 - set_fs(USER_DS);
89470
89471 ptrace_event(PTRACE_EVENT_EXIT, code);
89472
89473 @@ -742,6 +747,9 @@ void do_exit(long code)
89474 tsk->exit_code = code;
89475 taskstats_exit(tsk, group_dead);
89476
89477 + gr_acl_handle_psacct(tsk, code);
89478 + gr_acl_handle_exit();
89479 +
89480 exit_mm(tsk);
89481
89482 if (group_dead)
89483 @@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89484 * Take down every thread in the group. This is called by fatal signals
89485 * as well as by sys_exit_group (below).
89486 */
89487 -void
89488 +__noreturn void
89489 do_group_exit(int exit_code)
89490 {
89491 struct signal_struct *sig = current->signal;
89492 diff --git a/kernel/fork.c b/kernel/fork.c
89493 index a91e47d..71c9064 100644
89494 --- a/kernel/fork.c
89495 +++ b/kernel/fork.c
89496 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89497 # endif
89498 #endif
89499
89500 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89501 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89502 + int node, void **lowmem_stack)
89503 +{
89504 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89505 + void *ret = NULL;
89506 + unsigned int i;
89507 +
89508 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89509 + if (*lowmem_stack == NULL)
89510 + goto out;
89511 +
89512 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89513 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89514 +
89515 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89516 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89517 + if (ret == NULL) {
89518 + free_thread_info(*lowmem_stack);
89519 + *lowmem_stack = NULL;
89520 + }
89521 +
89522 +out:
89523 + return ret;
89524 +}
89525 +
89526 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89527 +{
89528 + unmap_process_stacks(tsk);
89529 +}
89530 +#else
89531 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89532 + int node, void **lowmem_stack)
89533 +{
89534 + return alloc_thread_info_node(tsk, node);
89535 +}
89536 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89537 +{
89538 + free_thread_info(ti);
89539 +}
89540 +#endif
89541 +
89542 /* SLAB cache for signal_struct structures (tsk->signal) */
89543 static struct kmem_cache *signal_cachep;
89544
89545 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89546 /* SLAB cache for mm_struct structures (tsk->mm) */
89547 static struct kmem_cache *mm_cachep;
89548
89549 -static void account_kernel_stack(struct thread_info *ti, int account)
89550 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89551 {
89552 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89553 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89554 +#else
89555 struct zone *zone = page_zone(virt_to_page(ti));
89556 +#endif
89557
89558 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89559 }
89560
89561 void free_task(struct task_struct *tsk)
89562 {
89563 - account_kernel_stack(tsk->stack, -1);
89564 + account_kernel_stack(tsk, tsk->stack, -1);
89565 arch_release_thread_info(tsk->stack);
89566 - free_thread_info(tsk->stack);
89567 + gr_free_thread_info(tsk, tsk->stack);
89568 rt_mutex_debug_task_free(tsk);
89569 ftrace_graph_exit_task(tsk);
89570 put_seccomp_filter(tsk);
89571 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89572 struct task_struct *tsk;
89573 struct thread_info *ti;
89574 unsigned long *stackend;
89575 + void *lowmem_stack;
89576 int node = tsk_fork_get_node(orig);
89577 int err;
89578
89579 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89580 if (!tsk)
89581 return NULL;
89582
89583 - ti = alloc_thread_info_node(tsk, node);
89584 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89585 if (!ti)
89586 goto free_tsk;
89587
89588 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89589 goto free_ti;
89590
89591 tsk->stack = ti;
89592 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89593 + tsk->lowmem_stack = lowmem_stack;
89594 +#endif
89595 #ifdef CONFIG_SECCOMP
89596 /*
89597 * We must handle setting up seccomp filters once we're under
89598 @@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89599 *stackend = STACK_END_MAGIC; /* for overflow detection */
89600
89601 #ifdef CONFIG_CC_STACKPROTECTOR
89602 - tsk->stack_canary = get_random_int();
89603 + tsk->stack_canary = pax_get_random_long();
89604 #endif
89605
89606 /*
89607 @@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89608 tsk->splice_pipe = NULL;
89609 tsk->task_frag.page = NULL;
89610
89611 - account_kernel_stack(ti, 1);
89612 + account_kernel_stack(tsk, ti, 1);
89613
89614 return tsk;
89615
89616 free_ti:
89617 - free_thread_info(ti);
89618 + gr_free_thread_info(tsk, ti);
89619 free_tsk:
89620 free_task_struct(tsk);
89621 return NULL;
89622 }
89623
89624 #ifdef CONFIG_MMU
89625 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89626 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89627 +{
89628 + struct vm_area_struct *tmp;
89629 + unsigned long charge;
89630 + struct file *file;
89631 + int retval;
89632 +
89633 + charge = 0;
89634 + if (mpnt->vm_flags & VM_ACCOUNT) {
89635 + unsigned long len = vma_pages(mpnt);
89636 +
89637 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89638 + goto fail_nomem;
89639 + charge = len;
89640 + }
89641 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89642 + if (!tmp)
89643 + goto fail_nomem;
89644 + *tmp = *mpnt;
89645 + tmp->vm_mm = mm;
89646 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89647 + retval = vma_dup_policy(mpnt, tmp);
89648 + if (retval)
89649 + goto fail_nomem_policy;
89650 + if (anon_vma_fork(tmp, mpnt))
89651 + goto fail_nomem_anon_vma_fork;
89652 + tmp->vm_flags &= ~VM_LOCKED;
89653 + tmp->vm_next = tmp->vm_prev = NULL;
89654 + tmp->vm_mirror = NULL;
89655 + file = tmp->vm_file;
89656 + if (file) {
89657 + struct inode *inode = file_inode(file);
89658 + struct address_space *mapping = file->f_mapping;
89659 +
89660 + get_file(file);
89661 + if (tmp->vm_flags & VM_DENYWRITE)
89662 + atomic_dec(&inode->i_writecount);
89663 + mutex_lock(&mapping->i_mmap_mutex);
89664 + if (tmp->vm_flags & VM_SHARED)
89665 + atomic_inc(&mapping->i_mmap_writable);
89666 + flush_dcache_mmap_lock(mapping);
89667 + /* insert tmp into the share list, just after mpnt */
89668 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89669 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89670 + else
89671 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89672 + flush_dcache_mmap_unlock(mapping);
89673 + mutex_unlock(&mapping->i_mmap_mutex);
89674 + }
89675 +
89676 + /*
89677 + * Clear hugetlb-related page reserves for children. This only
89678 + * affects MAP_PRIVATE mappings. Faults generated by the child
89679 + * are not guaranteed to succeed, even if read-only
89680 + */
89681 + if (is_vm_hugetlb_page(tmp))
89682 + reset_vma_resv_huge_pages(tmp);
89683 +
89684 + return tmp;
89685 +
89686 +fail_nomem_anon_vma_fork:
89687 + mpol_put(vma_policy(tmp));
89688 +fail_nomem_policy:
89689 + kmem_cache_free(vm_area_cachep, tmp);
89690 +fail_nomem:
89691 + vm_unacct_memory(charge);
89692 + return NULL;
89693 +}
89694 +
89695 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89696 {
89697 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89698 struct rb_node **rb_link, *rb_parent;
89699 int retval;
89700 - unsigned long charge;
89701
89702 uprobe_start_dup_mmap();
89703 down_write(&oldmm->mmap_sem);
89704 @@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89705
89706 prev = NULL;
89707 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89708 - struct file *file;
89709 -
89710 if (mpnt->vm_flags & VM_DONTCOPY) {
89711 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89712 -vma_pages(mpnt));
89713 continue;
89714 }
89715 - charge = 0;
89716 - if (mpnt->vm_flags & VM_ACCOUNT) {
89717 - unsigned long len = vma_pages(mpnt);
89718 -
89719 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89720 - goto fail_nomem;
89721 - charge = len;
89722 - }
89723 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89724 - if (!tmp)
89725 - goto fail_nomem;
89726 - *tmp = *mpnt;
89727 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89728 - retval = vma_dup_policy(mpnt, tmp);
89729 - if (retval)
89730 - goto fail_nomem_policy;
89731 - tmp->vm_mm = mm;
89732 - if (anon_vma_fork(tmp, mpnt))
89733 - goto fail_nomem_anon_vma_fork;
89734 - tmp->vm_flags &= ~VM_LOCKED;
89735 - tmp->vm_next = tmp->vm_prev = NULL;
89736 - file = tmp->vm_file;
89737 - if (file) {
89738 - struct inode *inode = file_inode(file);
89739 - struct address_space *mapping = file->f_mapping;
89740 -
89741 - get_file(file);
89742 - if (tmp->vm_flags & VM_DENYWRITE)
89743 - atomic_dec(&inode->i_writecount);
89744 - mutex_lock(&mapping->i_mmap_mutex);
89745 - if (tmp->vm_flags & VM_SHARED)
89746 - atomic_inc(&mapping->i_mmap_writable);
89747 - flush_dcache_mmap_lock(mapping);
89748 - /* insert tmp into the share list, just after mpnt */
89749 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89750 - vma_nonlinear_insert(tmp,
89751 - &mapping->i_mmap_nonlinear);
89752 - else
89753 - vma_interval_tree_insert_after(tmp, mpnt,
89754 - &mapping->i_mmap);
89755 - flush_dcache_mmap_unlock(mapping);
89756 - mutex_unlock(&mapping->i_mmap_mutex);
89757 + tmp = dup_vma(mm, oldmm, mpnt);
89758 + if (!tmp) {
89759 + retval = -ENOMEM;
89760 + goto out;
89761 }
89762
89763 /*
89764 @@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89765 if (retval)
89766 goto out;
89767 }
89768 +
89769 +#ifdef CONFIG_PAX_SEGMEXEC
89770 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89771 + struct vm_area_struct *mpnt_m;
89772 +
89773 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89774 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89775 +
89776 + if (!mpnt->vm_mirror)
89777 + continue;
89778 +
89779 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89780 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89781 + mpnt->vm_mirror = mpnt_m;
89782 + } else {
89783 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89784 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89785 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89786 + mpnt->vm_mirror->vm_mirror = mpnt;
89787 + }
89788 + }
89789 + BUG_ON(mpnt_m);
89790 + }
89791 +#endif
89792 +
89793 /* a new mm has just been created */
89794 arch_dup_mmap(oldmm, mm);
89795 retval = 0;
89796 @@ -480,14 +583,6 @@ out:
89797 up_write(&oldmm->mmap_sem);
89798 uprobe_end_dup_mmap();
89799 return retval;
89800 -fail_nomem_anon_vma_fork:
89801 - mpol_put(vma_policy(tmp));
89802 -fail_nomem_policy:
89803 - kmem_cache_free(vm_area_cachep, tmp);
89804 -fail_nomem:
89805 - retval = -ENOMEM;
89806 - vm_unacct_memory(charge);
89807 - goto out;
89808 }
89809
89810 static inline int mm_alloc_pgd(struct mm_struct *mm)
89811 @@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89812 return ERR_PTR(err);
89813
89814 mm = get_task_mm(task);
89815 - if (mm && mm != current->mm &&
89816 - !ptrace_may_access(task, mode)) {
89817 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89818 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89819 mmput(mm);
89820 mm = ERR_PTR(-EACCES);
89821 }
89822 @@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89823 spin_unlock(&fs->lock);
89824 return -EAGAIN;
89825 }
89826 - fs->users++;
89827 + atomic_inc(&fs->users);
89828 spin_unlock(&fs->lock);
89829 return 0;
89830 }
89831 tsk->fs = copy_fs_struct(fs);
89832 if (!tsk->fs)
89833 return -ENOMEM;
89834 + /* Carry through gr_chroot_dentry and is_chrooted instead
89835 + of recomputing it here. Already copied when the task struct
89836 + is duplicated. This allows pivot_root to not be treated as
89837 + a chroot
89838 + */
89839 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89840 +
89841 return 0;
89842 }
89843
89844 @@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89845 * parts of the process environment (as per the clone
89846 * flags). The actual kick-off is left to the caller.
89847 */
89848 -static struct task_struct *copy_process(unsigned long clone_flags,
89849 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89850 unsigned long stack_start,
89851 unsigned long stack_size,
89852 int __user *child_tidptr,
89853 @@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89854 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89855 #endif
89856 retval = -EAGAIN;
89857 +
89858 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89859 +
89860 if (atomic_read(&p->real_cred->user->processes) >=
89861 task_rlimit(p, RLIMIT_NPROC)) {
89862 if (p->real_cred->user != INIT_USER &&
89863 @@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89864 goto bad_fork_free_pid;
89865 }
89866
89867 + /* synchronizes with gr_set_acls()
89868 + we need to call this past the point of no return for fork()
89869 + */
89870 + gr_copy_label(p);
89871 +
89872 if (likely(p->pid)) {
89873 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89874
89875 @@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
89876 bad_fork_free:
89877 free_task(p);
89878 fork_out:
89879 + gr_log_forkfail(retval);
89880 +
89881 return ERR_PTR(retval);
89882 }
89883
89884 @@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
89885
89886 p = copy_process(clone_flags, stack_start, stack_size,
89887 child_tidptr, NULL, trace);
89888 + add_latent_entropy();
89889 /*
89890 * Do this prior waking up the new thread - the thread pointer
89891 * might get invalid after that point, if the thread exits quickly.
89892 @@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
89893 if (clone_flags & CLONE_PARENT_SETTID)
89894 put_user(nr, parent_tidptr);
89895
89896 + gr_handle_brute_check();
89897 +
89898 if (clone_flags & CLONE_VFORK) {
89899 p->vfork_done = &vfork;
89900 init_completion(&vfork);
89901 @@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
89902 mm_cachep = kmem_cache_create("mm_struct",
89903 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89904 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89905 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89906 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89907 mmap_init();
89908 nsproxy_cache_init();
89909 }
89910 @@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89911 return 0;
89912
89913 /* don't need lock here; in the worst case we'll do useless copy */
89914 - if (fs->users == 1)
89915 + if (atomic_read(&fs->users) == 1)
89916 return 0;
89917
89918 *new_fsp = copy_fs_struct(fs);
89919 @@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89920 fs = current->fs;
89921 spin_lock(&fs->lock);
89922 current->fs = new_fs;
89923 - if (--fs->users)
89924 + gr_set_chroot_entries(current, &current->fs->root);
89925 + if (atomic_dec_return(&fs->users))
89926 new_fs = NULL;
89927 else
89928 new_fs = fs;
89929 diff --git a/kernel/futex.c b/kernel/futex.c
89930 index 22b3f1b..6820bc0 100644
89931 --- a/kernel/futex.c
89932 +++ b/kernel/futex.c
89933 @@ -202,7 +202,7 @@ struct futex_pi_state {
89934 atomic_t refcount;
89935
89936 union futex_key key;
89937 -};
89938 +} __randomize_layout;
89939
89940 /**
89941 * struct futex_q - The hashed futex queue entry, one per waiting task
89942 @@ -236,7 +236,7 @@ struct futex_q {
89943 struct rt_mutex_waiter *rt_waiter;
89944 union futex_key *requeue_pi_key;
89945 u32 bitset;
89946 -};
89947 +} __randomize_layout;
89948
89949 static const struct futex_q futex_q_init = {
89950 /* list gets initialized in queue_me()*/
89951 @@ -396,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89952 struct page *page, *page_head;
89953 int err, ro = 0;
89954
89955 +#ifdef CONFIG_PAX_SEGMEXEC
89956 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89957 + return -EFAULT;
89958 +#endif
89959 +
89960 /*
89961 * The futex address must be "naturally" aligned.
89962 */
89963 @@ -595,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89964
89965 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89966 {
89967 - int ret;
89968 + unsigned long ret;
89969
89970 pagefault_disable();
89971 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89972 @@ -3000,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
89973 {
89974 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89975 u32 curval;
89976 + mm_segment_t oldfs;
89977
89978 /*
89979 * This will fail and we want it. Some arch implementations do
89980 @@ -3011,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
89981 * implementation, the non-functional ones will return
89982 * -ENOSYS.
89983 */
89984 + oldfs = get_fs();
89985 + set_fs(USER_DS);
89986 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89987 futex_cmpxchg_enabled = 1;
89988 + set_fs(oldfs);
89989 #endif
89990 }
89991
89992 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89993 index 55c8c93..9ba7ad6 100644
89994 --- a/kernel/futex_compat.c
89995 +++ b/kernel/futex_compat.c
89996 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89997 return 0;
89998 }
89999
90000 -static void __user *futex_uaddr(struct robust_list __user *entry,
90001 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
90002 compat_long_t futex_offset)
90003 {
90004 compat_uptr_t base = ptr_to_compat(entry);
90005 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
90006 index b358a80..fc25240 100644
90007 --- a/kernel/gcov/base.c
90008 +++ b/kernel/gcov/base.c
90009 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
90010 }
90011
90012 #ifdef CONFIG_MODULES
90013 -static inline int within(void *addr, void *start, unsigned long size)
90014 -{
90015 - return ((addr >= start) && (addr < start + size));
90016 -}
90017 -
90018 /* Update list and generate events when modules are unloaded. */
90019 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90020 void *data)
90021 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90022
90023 /* Remove entries located in module from linked list. */
90024 while ((info = gcov_info_next(info))) {
90025 - if (within(info, mod->module_core, mod->core_size)) {
90026 + if (within_module_core_rw((unsigned long)info, mod)) {
90027 gcov_info_unlink(prev, info);
90028 if (gcov_events_enabled)
90029 gcov_event(GCOV_REMOVE, info);
90030 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
90031 index 9019f15..9a3c42e 100644
90032 --- a/kernel/jump_label.c
90033 +++ b/kernel/jump_label.c
90034 @@ -14,6 +14,7 @@
90035 #include <linux/err.h>
90036 #include <linux/static_key.h>
90037 #include <linux/jump_label_ratelimit.h>
90038 +#include <linux/mm.h>
90039
90040 #ifdef HAVE_JUMP_LABEL
90041
90042 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
90043
90044 size = (((unsigned long)stop - (unsigned long)start)
90045 / sizeof(struct jump_entry));
90046 + pax_open_kernel();
90047 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
90048 + pax_close_kernel();
90049 }
90050
90051 static void jump_label_update(struct static_key *key, int enable);
90052 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
90053 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
90054 struct jump_entry *iter;
90055
90056 + pax_open_kernel();
90057 for (iter = iter_start; iter < iter_stop; iter++) {
90058 if (within_module_init(iter->code, mod))
90059 iter->code = 0;
90060 }
90061 + pax_close_kernel();
90062 }
90063
90064 static int
90065 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
90066 index ae51670..c1a9796 100644
90067 --- a/kernel/kallsyms.c
90068 +++ b/kernel/kallsyms.c
90069 @@ -11,6 +11,9 @@
90070 * Changed the compression method from stem compression to "table lookup"
90071 * compression (see scripts/kallsyms.c for a more complete description)
90072 */
90073 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90074 +#define __INCLUDED_BY_HIDESYM 1
90075 +#endif
90076 #include <linux/kallsyms.h>
90077 #include <linux/module.h>
90078 #include <linux/init.h>
90079 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
90080
90081 static inline int is_kernel_inittext(unsigned long addr)
90082 {
90083 + if (system_state != SYSTEM_BOOTING)
90084 + return 0;
90085 +
90086 if (addr >= (unsigned long)_sinittext
90087 && addr <= (unsigned long)_einittext)
90088 return 1;
90089 return 0;
90090 }
90091
90092 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90093 +#ifdef CONFIG_MODULES
90094 +static inline int is_module_text(unsigned long addr)
90095 +{
90096 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
90097 + return 1;
90098 +
90099 + addr = ktla_ktva(addr);
90100 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
90101 +}
90102 +#else
90103 +static inline int is_module_text(unsigned long addr)
90104 +{
90105 + return 0;
90106 +}
90107 +#endif
90108 +#endif
90109 +
90110 static inline int is_kernel_text(unsigned long addr)
90111 {
90112 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
90113 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
90114
90115 static inline int is_kernel(unsigned long addr)
90116 {
90117 +
90118 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90119 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
90120 + return 1;
90121 +
90122 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
90123 +#else
90124 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
90125 +#endif
90126 +
90127 return 1;
90128 return in_gate_area_no_mm(addr);
90129 }
90130
90131 static int is_ksym_addr(unsigned long addr)
90132 {
90133 +
90134 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90135 + if (is_module_text(addr))
90136 + return 0;
90137 +#endif
90138 +
90139 if (all_var)
90140 return is_kernel(addr);
90141
90142 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
90143
90144 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
90145 {
90146 - iter->name[0] = '\0';
90147 iter->nameoff = get_symbol_offset(new_pos);
90148 iter->pos = new_pos;
90149 }
90150 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
90151 {
90152 struct kallsym_iter *iter = m->private;
90153
90154 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90155 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
90156 + return 0;
90157 +#endif
90158 +
90159 /* Some debugging symbols have no name. Ignore them. */
90160 if (!iter->name[0])
90161 return 0;
90162 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
90163 */
90164 type = iter->exported ? toupper(iter->type) :
90165 tolower(iter->type);
90166 +
90167 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
90168 type, iter->name, iter->module_name);
90169 } else
90170 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
90171 struct kallsym_iter *iter;
90172 int ret;
90173
90174 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
90175 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
90176 if (!iter)
90177 return -ENOMEM;
90178 reset_iter(iter, 0);
90179 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
90180 index 0aa69ea..a7fcafb 100644
90181 --- a/kernel/kcmp.c
90182 +++ b/kernel/kcmp.c
90183 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
90184 struct task_struct *task1, *task2;
90185 int ret;
90186
90187 +#ifdef CONFIG_GRKERNSEC
90188 + return -ENOSYS;
90189 +#endif
90190 +
90191 rcu_read_lock();
90192
90193 /*
90194 diff --git a/kernel/kexec.c b/kernel/kexec.c
90195 index 2bee072..8979af8 100644
90196 --- a/kernel/kexec.c
90197 +++ b/kernel/kexec.c
90198 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
90199 compat_ulong_t, flags)
90200 {
90201 struct compat_kexec_segment in;
90202 - struct kexec_segment out, __user *ksegments;
90203 + struct kexec_segment out;
90204 + struct kexec_segment __user *ksegments;
90205 unsigned long i, result;
90206
90207 /* Don't allow clients that don't understand the native
90208 diff --git a/kernel/kmod.c b/kernel/kmod.c
90209 index 8637e04..8b1d0d8 100644
90210 --- a/kernel/kmod.c
90211 +++ b/kernel/kmod.c
90212 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
90213 kfree(info->argv);
90214 }
90215
90216 -static int call_modprobe(char *module_name, int wait)
90217 +static int call_modprobe(char *module_name, char *module_param, int wait)
90218 {
90219 struct subprocess_info *info;
90220 static char *envp[] = {
90221 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
90222 NULL
90223 };
90224
90225 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90226 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90227 if (!argv)
90228 goto out;
90229
90230 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90231 argv[1] = "-q";
90232 argv[2] = "--";
90233 argv[3] = module_name; /* check free_modprobe_argv() */
90234 - argv[4] = NULL;
90235 + argv[4] = module_param;
90236 + argv[5] = NULL;
90237
90238 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90239 NULL, free_modprobe_argv, NULL);
90240 @@ -129,9 +130,8 @@ out:
90241 * If module auto-loading support is disabled then this function
90242 * becomes a no-operation.
90243 */
90244 -int __request_module(bool wait, const char *fmt, ...)
90245 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90246 {
90247 - va_list args;
90248 char module_name[MODULE_NAME_LEN];
90249 unsigned int max_modprobes;
90250 int ret;
90251 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90252 if (!modprobe_path[0])
90253 return 0;
90254
90255 - va_start(args, fmt);
90256 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90257 - va_end(args);
90258 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90259 if (ret >= MODULE_NAME_LEN)
90260 return -ENAMETOOLONG;
90261
90262 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90263 if (ret)
90264 return ret;
90265
90266 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90267 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90268 + /* hack to workaround consolekit/udisks stupidity */
90269 + read_lock(&tasklist_lock);
90270 + if (!strcmp(current->comm, "mount") &&
90271 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90272 + read_unlock(&tasklist_lock);
90273 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90274 + return -EPERM;
90275 + }
90276 + read_unlock(&tasklist_lock);
90277 + }
90278 +#endif
90279 +
90280 /* If modprobe needs a service that is in a module, we get a recursive
90281 * loop. Limit the number of running kmod threads to max_threads/2 or
90282 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90283 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
90284
90285 trace_module_request(module_name, wait, _RET_IP_);
90286
90287 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90288 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90289
90290 atomic_dec(&kmod_concurrent);
90291 return ret;
90292 }
90293 +
90294 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90295 +{
90296 + va_list args;
90297 + int ret;
90298 +
90299 + va_start(args, fmt);
90300 + ret = ____request_module(wait, module_param, fmt, args);
90301 + va_end(args);
90302 +
90303 + return ret;
90304 +}
90305 +
90306 +int __request_module(bool wait, const char *fmt, ...)
90307 +{
90308 + va_list args;
90309 + int ret;
90310 +
90311 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90312 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90313 + char module_param[MODULE_NAME_LEN];
90314 +
90315 + memset(module_param, 0, sizeof(module_param));
90316 +
90317 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90318 +
90319 + va_start(args, fmt);
90320 + ret = ____request_module(wait, module_param, fmt, args);
90321 + va_end(args);
90322 +
90323 + return ret;
90324 + }
90325 +#endif
90326 +
90327 + va_start(args, fmt);
90328 + ret = ____request_module(wait, NULL, fmt, args);
90329 + va_end(args);
90330 +
90331 + return ret;
90332 +}
90333 +
90334 EXPORT_SYMBOL(__request_module);
90335 #endif /* CONFIG_MODULES */
90336
90337 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
90338 */
90339 set_user_nice(current, 0);
90340
90341 +#ifdef CONFIG_GRKERNSEC
90342 + /* this is race-free as far as userland is concerned as we copied
90343 + out the path to be used prior to this point and are now operating
90344 + on that copy
90345 + */
90346 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90347 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90348 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90349 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90350 + retval = -EPERM;
90351 + goto fail;
90352 + }
90353 +#endif
90354 +
90355 retval = -ENOMEM;
90356 new = prepare_kernel_cred(current);
90357 if (!new)
90358 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
90359 commit_creds(new);
90360
90361 retval = do_execve(getname_kernel(sub_info->path),
90362 - (const char __user *const __user *)sub_info->argv,
90363 - (const char __user *const __user *)sub_info->envp);
90364 + (const char __user *const __force_user *)sub_info->argv,
90365 + (const char __user *const __force_user *)sub_info->envp);
90366 if (!retval)
90367 return 0;
90368
90369 @@ -260,6 +327,10 @@ static int call_helper(void *data)
90370
90371 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90372 {
90373 +#ifdef CONFIG_GRKERNSEC
90374 + kfree(info->path);
90375 + info->path = info->origpath;
90376 +#endif
90377 if (info->cleanup)
90378 (*info->cleanup)(info);
90379 kfree(info);
90380 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
90381 *
90382 * Thus the __user pointer cast is valid here.
90383 */
90384 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90385 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90386
90387 /*
90388 * If ret is 0, either ____call_usermodehelper failed and the
90389 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90390 goto out;
90391
90392 INIT_WORK(&sub_info->work, __call_usermodehelper);
90393 +#ifdef CONFIG_GRKERNSEC
90394 + sub_info->origpath = path;
90395 + sub_info->path = kstrdup(path, gfp_mask);
90396 +#else
90397 sub_info->path = path;
90398 +#endif
90399 sub_info->argv = argv;
90400 sub_info->envp = envp;
90401
90402 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90403 static int proc_cap_handler(struct ctl_table *table, int write,
90404 void __user *buffer, size_t *lenp, loff_t *ppos)
90405 {
90406 - struct ctl_table t;
90407 + ctl_table_no_const t;
90408 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90409 kernel_cap_t new_cap;
90410 int err, i;
90411 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90412 index 3995f54..e247879 100644
90413 --- a/kernel/kprobes.c
90414 +++ b/kernel/kprobes.c
90415 @@ -31,6 +31,9 @@
90416 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90417 * <prasanna@in.ibm.com> added function-return probes.
90418 */
90419 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90420 +#define __INCLUDED_BY_HIDESYM 1
90421 +#endif
90422 #include <linux/kprobes.h>
90423 #include <linux/hash.h>
90424 #include <linux/init.h>
90425 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90426
90427 static void *alloc_insn_page(void)
90428 {
90429 - return module_alloc(PAGE_SIZE);
90430 + return module_alloc_exec(PAGE_SIZE);
90431 }
90432
90433 static void free_insn_page(void *page)
90434 {
90435 - module_free(NULL, page);
90436 + module_free_exec(NULL, page);
90437 }
90438
90439 struct kprobe_insn_cache kprobe_insn_slots = {
90440 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90441 kprobe_type = "k";
90442
90443 if (sym)
90444 - seq_printf(pi, "%p %s %s+0x%x %s ",
90445 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90446 p->addr, kprobe_type, sym, offset,
90447 (modname ? modname : " "));
90448 else
90449 - seq_printf(pi, "%p %s %p ",
90450 + seq_printf(pi, "%pK %s %pK ",
90451 p->addr, kprobe_type, p->addr);
90452
90453 if (!pp)
90454 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90455 index 6683cce..daf8999 100644
90456 --- a/kernel/ksysfs.c
90457 +++ b/kernel/ksysfs.c
90458 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90459 {
90460 if (count+1 > UEVENT_HELPER_PATH_LEN)
90461 return -ENOENT;
90462 + if (!capable(CAP_SYS_ADMIN))
90463 + return -EPERM;
90464 memcpy(uevent_helper, buf, count);
90465 uevent_helper[count] = '\0';
90466 if (count && uevent_helper[count-1] == '\n')
90467 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90468 return count;
90469 }
90470
90471 -static struct bin_attribute notes_attr = {
90472 +static bin_attribute_no_const notes_attr __read_only = {
90473 .attr = {
90474 .name = "notes",
90475 .mode = S_IRUGO,
90476 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90477 index 88d0d44..e9ce0ee 100644
90478 --- a/kernel/locking/lockdep.c
90479 +++ b/kernel/locking/lockdep.c
90480 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90481 end = (unsigned long) &_end,
90482 addr = (unsigned long) obj;
90483
90484 +#ifdef CONFIG_PAX_KERNEXEC
90485 + start = ktla_ktva(start);
90486 +#endif
90487 +
90488 /*
90489 * static variable?
90490 */
90491 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90492 if (!static_obj(lock->key)) {
90493 debug_locks_off();
90494 printk("INFO: trying to register non-static key.\n");
90495 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90496 printk("the code is fine but needs lockdep annotation.\n");
90497 printk("turning off the locking correctness validator.\n");
90498 dump_stack();
90499 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90500 if (!class)
90501 return 0;
90502 }
90503 - atomic_inc((atomic_t *)&class->ops);
90504 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90505 if (very_verbose(class)) {
90506 printk("\nacquire class [%p] %s", class->key, class->name);
90507 if (class->name_version > 1)
90508 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90509 index ef43ac4..2720dfa 100644
90510 --- a/kernel/locking/lockdep_proc.c
90511 +++ b/kernel/locking/lockdep_proc.c
90512 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90513 return 0;
90514 }
90515
90516 - seq_printf(m, "%p", class->key);
90517 + seq_printf(m, "%pK", class->key);
90518 #ifdef CONFIG_DEBUG_LOCKDEP
90519 seq_printf(m, " OPS:%8ld", class->ops);
90520 #endif
90521 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90522
90523 list_for_each_entry(entry, &class->locks_after, entry) {
90524 if (entry->distance == 1) {
90525 - seq_printf(m, " -> [%p] ", entry->class->key);
90526 + seq_printf(m, " -> [%pK] ", entry->class->key);
90527 print_name(m, entry->class);
90528 seq_puts(m, "\n");
90529 }
90530 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90531 if (!class->key)
90532 continue;
90533
90534 - seq_printf(m, "[%p] ", class->key);
90535 + seq_printf(m, "[%pK] ", class->key);
90536 print_name(m, class);
90537 seq_puts(m, "\n");
90538 }
90539 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90540 if (!i)
90541 seq_line(m, '-', 40-namelen, namelen);
90542
90543 - snprintf(ip, sizeof(ip), "[<%p>]",
90544 + snprintf(ip, sizeof(ip), "[<%pK>]",
90545 (void *)class->contention_point[i]);
90546 seq_printf(m, "%40s %14lu %29s %pS\n",
90547 name, stats->contention_point[i],
90548 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90549 if (!i)
90550 seq_line(m, '-', 40-namelen, namelen);
90551
90552 - snprintf(ip, sizeof(ip), "[<%p>]",
90553 + snprintf(ip, sizeof(ip), "[<%pK>]",
90554 (void *)class->contending_point[i]);
90555 seq_printf(m, "%40s %14lu %29s %pS\n",
90556 name, stats->contending_point[i],
90557 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90558 index 9887a90..0cd2b1d 100644
90559 --- a/kernel/locking/mcs_spinlock.c
90560 +++ b/kernel/locking/mcs_spinlock.c
90561 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90562
90563 prev = decode_cpu(old);
90564 node->prev = prev;
90565 - ACCESS_ONCE(prev->next) = node;
90566 + ACCESS_ONCE_RW(prev->next) = node;
90567
90568 /*
90569 * Normally @prev is untouchable after the above store; because at that
90570 @@ -172,8 +172,8 @@ unqueue:
90571 * it will wait in Step-A.
90572 */
90573
90574 - ACCESS_ONCE(next->prev) = prev;
90575 - ACCESS_ONCE(prev->next) = next;
90576 + ACCESS_ONCE_RW(next->prev) = prev;
90577 + ACCESS_ONCE_RW(prev->next) = next;
90578
90579 return false;
90580 }
90581 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90582 node = this_cpu_ptr(&osq_node);
90583 next = xchg(&node->next, NULL);
90584 if (next) {
90585 - ACCESS_ONCE(next->locked) = 1;
90586 + ACCESS_ONCE_RW(next->locked) = 1;
90587 return;
90588 }
90589
90590 next = osq_wait_next(lock, node, NULL);
90591 if (next)
90592 - ACCESS_ONCE(next->locked) = 1;
90593 + ACCESS_ONCE_RW(next->locked) = 1;
90594 }
90595
90596 #endif
90597 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90598 index 23e89c5..8558eac 100644
90599 --- a/kernel/locking/mcs_spinlock.h
90600 +++ b/kernel/locking/mcs_spinlock.h
90601 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90602 */
90603 return;
90604 }
90605 - ACCESS_ONCE(prev->next) = node;
90606 + ACCESS_ONCE_RW(prev->next) = node;
90607
90608 /* Wait until the lock holder passes the lock down. */
90609 arch_mcs_spin_lock_contended(&node->locked);
90610 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90611 index 5cf6731..ce3bc5a 100644
90612 --- a/kernel/locking/mutex-debug.c
90613 +++ b/kernel/locking/mutex-debug.c
90614 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90615 }
90616
90617 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90618 - struct thread_info *ti)
90619 + struct task_struct *task)
90620 {
90621 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90622
90623 /* Mark the current thread as blocked on the lock: */
90624 - ti->task->blocked_on = waiter;
90625 + task->blocked_on = waiter;
90626 }
90627
90628 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90629 - struct thread_info *ti)
90630 + struct task_struct *task)
90631 {
90632 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90633 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90634 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90635 - ti->task->blocked_on = NULL;
90636 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90637 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90638 + task->blocked_on = NULL;
90639
90640 list_del_init(&waiter->list);
90641 waiter->task = NULL;
90642 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90643 index 0799fd3..d06ae3b 100644
90644 --- a/kernel/locking/mutex-debug.h
90645 +++ b/kernel/locking/mutex-debug.h
90646 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90647 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90648 extern void debug_mutex_add_waiter(struct mutex *lock,
90649 struct mutex_waiter *waiter,
90650 - struct thread_info *ti);
90651 + struct task_struct *task);
90652 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90653 - struct thread_info *ti);
90654 + struct task_struct *task);
90655 extern void debug_mutex_unlock(struct mutex *lock);
90656 extern void debug_mutex_init(struct mutex *lock, const char *name,
90657 struct lock_class_key *key);
90658 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90659 index ae712b2..d0d4a41 100644
90660 --- a/kernel/locking/mutex.c
90661 +++ b/kernel/locking/mutex.c
90662 @@ -486,7 +486,7 @@ slowpath:
90663 goto skip_wait;
90664
90665 debug_mutex_lock_common(lock, &waiter);
90666 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90667 + debug_mutex_add_waiter(lock, &waiter, task);
90668
90669 /* add waiting tasks to the end of the waitqueue (FIFO): */
90670 list_add_tail(&waiter.list, &lock->wait_list);
90671 @@ -531,7 +531,7 @@ slowpath:
90672 schedule_preempt_disabled();
90673 spin_lock_mutex(&lock->wait_lock, flags);
90674 }
90675 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90676 + mutex_remove_waiter(lock, &waiter, task);
90677 /* set it to 0 if there are no waiters left: */
90678 if (likely(list_empty(&lock->wait_list)))
90679 atomic_set(&lock->count, 0);
90680 @@ -568,7 +568,7 @@ skip_wait:
90681 return 0;
90682
90683 err:
90684 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90685 + mutex_remove_waiter(lock, &waiter, task);
90686 spin_unlock_mutex(&lock->wait_lock, flags);
90687 debug_mutex_free_waiter(&waiter);
90688 mutex_release(&lock->dep_map, 1, ip);
90689 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90690 index 1d96dd0..994ff19 100644
90691 --- a/kernel/locking/rtmutex-tester.c
90692 +++ b/kernel/locking/rtmutex-tester.c
90693 @@ -22,7 +22,7 @@
90694 #define MAX_RT_TEST_MUTEXES 8
90695
90696 static spinlock_t rttest_lock;
90697 -static atomic_t rttest_event;
90698 +static atomic_unchecked_t rttest_event;
90699
90700 struct test_thread_data {
90701 int opcode;
90702 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90703
90704 case RTTEST_LOCKCONT:
90705 td->mutexes[td->opdata] = 1;
90706 - td->event = atomic_add_return(1, &rttest_event);
90707 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90708 return 0;
90709
90710 case RTTEST_RESET:
90711 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90712 return 0;
90713
90714 case RTTEST_RESETEVENT:
90715 - atomic_set(&rttest_event, 0);
90716 + atomic_set_unchecked(&rttest_event, 0);
90717 return 0;
90718
90719 default:
90720 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90721 return ret;
90722
90723 td->mutexes[id] = 1;
90724 - td->event = atomic_add_return(1, &rttest_event);
90725 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90726 rt_mutex_lock(&mutexes[id]);
90727 - td->event = atomic_add_return(1, &rttest_event);
90728 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90729 td->mutexes[id] = 4;
90730 return 0;
90731
90732 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90733 return ret;
90734
90735 td->mutexes[id] = 1;
90736 - td->event = atomic_add_return(1, &rttest_event);
90737 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90738 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90739 - td->event = atomic_add_return(1, &rttest_event);
90740 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90741 td->mutexes[id] = ret ? 0 : 4;
90742 return ret ? -EINTR : 0;
90743
90744 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90745 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90746 return ret;
90747
90748 - td->event = atomic_add_return(1, &rttest_event);
90749 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90750 rt_mutex_unlock(&mutexes[id]);
90751 - td->event = atomic_add_return(1, &rttest_event);
90752 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90753 td->mutexes[id] = 0;
90754 return 0;
90755
90756 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90757 break;
90758
90759 td->mutexes[dat] = 2;
90760 - td->event = atomic_add_return(1, &rttest_event);
90761 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90762 break;
90763
90764 default:
90765 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90766 return;
90767
90768 td->mutexes[dat] = 3;
90769 - td->event = atomic_add_return(1, &rttest_event);
90770 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90771 break;
90772
90773 case RTTEST_LOCKNOWAIT:
90774 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90775 return;
90776
90777 td->mutexes[dat] = 1;
90778 - td->event = atomic_add_return(1, &rttest_event);
90779 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90780 return;
90781
90782 default:
90783 diff --git a/kernel/module.c b/kernel/module.c
90784 index 1c47139..6242887 100644
90785 --- a/kernel/module.c
90786 +++ b/kernel/module.c
90787 @@ -60,6 +60,7 @@
90788 #include <linux/jump_label.h>
90789 #include <linux/pfn.h>
90790 #include <linux/bsearch.h>
90791 +#include <linux/grsecurity.h>
90792 #include <uapi/linux/module.h>
90793 #include "module-internal.h"
90794
90795 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90796
90797 /* Bounds of module allocation, for speeding __module_address.
90798 * Protected by module_mutex. */
90799 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90800 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90801 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90802
90803 int register_module_notifier(struct notifier_block * nb)
90804 {
90805 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90806 return true;
90807
90808 list_for_each_entry_rcu(mod, &modules, list) {
90809 - struct symsearch arr[] = {
90810 + struct symsearch modarr[] = {
90811 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90812 NOT_GPL_ONLY, false },
90813 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90814 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90815 if (mod->state == MODULE_STATE_UNFORMED)
90816 continue;
90817
90818 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90819 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90820 return true;
90821 }
90822 return false;
90823 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90824 if (!pcpusec->sh_size)
90825 return 0;
90826
90827 - if (align > PAGE_SIZE) {
90828 + if (align-1 >= PAGE_SIZE) {
90829 pr_warn("%s: per-cpu alignment %li > %li\n",
90830 mod->name, align, PAGE_SIZE);
90831 align = PAGE_SIZE;
90832 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90833 static ssize_t show_coresize(struct module_attribute *mattr,
90834 struct module_kobject *mk, char *buffer)
90835 {
90836 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90837 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90838 }
90839
90840 static struct module_attribute modinfo_coresize =
90841 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90842 static ssize_t show_initsize(struct module_attribute *mattr,
90843 struct module_kobject *mk, char *buffer)
90844 {
90845 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90846 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90847 }
90848
90849 static struct module_attribute modinfo_initsize =
90850 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90851 goto bad_version;
90852 }
90853
90854 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90855 + /*
90856 + * avoid potentially printing jibberish on attempted load
90857 + * of a module randomized with a different seed
90858 + */
90859 + pr_warn("no symbol version for %s\n", symname);
90860 +#else
90861 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90862 +#endif
90863 return 0;
90864
90865 bad_version:
90866 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90867 + /*
90868 + * avoid potentially printing jibberish on attempted load
90869 + * of a module randomized with a different seed
90870 + */
90871 + printk("attempted module disagrees about version of symbol %s\n",
90872 + symname);
90873 +#else
90874 printk("%s: disagrees about version of symbol %s\n",
90875 mod->name, symname);
90876 +#endif
90877 return 0;
90878 }
90879
90880 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90881 */
90882 #ifdef CONFIG_SYSFS
90883
90884 -#ifdef CONFIG_KALLSYMS
90885 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90886 static inline bool sect_empty(const Elf_Shdr *sect)
90887 {
90888 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90889 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90890 {
90891 unsigned int notes, loaded, i;
90892 struct module_notes_attrs *notes_attrs;
90893 - struct bin_attribute *nattr;
90894 + bin_attribute_no_const *nattr;
90895
90896 /* failed to create section attributes, so can't create notes */
90897 if (!mod->sect_attrs)
90898 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90899 static int module_add_modinfo_attrs(struct module *mod)
90900 {
90901 struct module_attribute *attr;
90902 - struct module_attribute *temp_attr;
90903 + module_attribute_no_const *temp_attr;
90904 int error = 0;
90905 int i;
90906
90907 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90908
90909 static void unset_module_core_ro_nx(struct module *mod)
90910 {
90911 - set_page_attributes(mod->module_core + mod->core_text_size,
90912 - mod->module_core + mod->core_size,
90913 + set_page_attributes(mod->module_core_rw,
90914 + mod->module_core_rw + mod->core_size_rw,
90915 set_memory_x);
90916 - set_page_attributes(mod->module_core,
90917 - mod->module_core + mod->core_ro_size,
90918 + set_page_attributes(mod->module_core_rx,
90919 + mod->module_core_rx + mod->core_size_rx,
90920 set_memory_rw);
90921 }
90922
90923 static void unset_module_init_ro_nx(struct module *mod)
90924 {
90925 - set_page_attributes(mod->module_init + mod->init_text_size,
90926 - mod->module_init + mod->init_size,
90927 + set_page_attributes(mod->module_init_rw,
90928 + mod->module_init_rw + mod->init_size_rw,
90929 set_memory_x);
90930 - set_page_attributes(mod->module_init,
90931 - mod->module_init + mod->init_ro_size,
90932 + set_page_attributes(mod->module_init_rx,
90933 + mod->module_init_rx + mod->init_size_rx,
90934 set_memory_rw);
90935 }
90936
90937 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90938 list_for_each_entry_rcu(mod, &modules, list) {
90939 if (mod->state == MODULE_STATE_UNFORMED)
90940 continue;
90941 - if ((mod->module_core) && (mod->core_text_size)) {
90942 - set_page_attributes(mod->module_core,
90943 - mod->module_core + mod->core_text_size,
90944 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90945 + set_page_attributes(mod->module_core_rx,
90946 + mod->module_core_rx + mod->core_size_rx,
90947 set_memory_rw);
90948 }
90949 - if ((mod->module_init) && (mod->init_text_size)) {
90950 - set_page_attributes(mod->module_init,
90951 - mod->module_init + mod->init_text_size,
90952 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90953 + set_page_attributes(mod->module_init_rx,
90954 + mod->module_init_rx + mod->init_size_rx,
90955 set_memory_rw);
90956 }
90957 }
90958 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90959 list_for_each_entry_rcu(mod, &modules, list) {
90960 if (mod->state == MODULE_STATE_UNFORMED)
90961 continue;
90962 - if ((mod->module_core) && (mod->core_text_size)) {
90963 - set_page_attributes(mod->module_core,
90964 - mod->module_core + mod->core_text_size,
90965 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90966 + set_page_attributes(mod->module_core_rx,
90967 + mod->module_core_rx + mod->core_size_rx,
90968 set_memory_ro);
90969 }
90970 - if ((mod->module_init) && (mod->init_text_size)) {
90971 - set_page_attributes(mod->module_init,
90972 - mod->module_init + mod->init_text_size,
90973 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90974 + set_page_attributes(mod->module_init_rx,
90975 + mod->module_init_rx + mod->init_size_rx,
90976 set_memory_ro);
90977 }
90978 }
90979 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90980
90981 /* This may be NULL, but that's OK */
90982 unset_module_init_ro_nx(mod);
90983 - module_free(mod, mod->module_init);
90984 + module_free(mod, mod->module_init_rw);
90985 + module_free_exec(mod, mod->module_init_rx);
90986 kfree(mod->args);
90987 percpu_modfree(mod);
90988
90989 /* Free lock-classes: */
90990 - lockdep_free_key_range(mod->module_core, mod->core_size);
90991 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90992 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90993
90994 /* Finally, free the core (containing the module structure) */
90995 unset_module_core_ro_nx(mod);
90996 - module_free(mod, mod->module_core);
90997 + module_free_exec(mod, mod->module_core_rx);
90998 + module_free(mod, mod->module_core_rw);
90999
91000 #ifdef CONFIG_MPU
91001 update_protections(current->mm);
91002 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91003 int ret = 0;
91004 const struct kernel_symbol *ksym;
91005
91006 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91007 + int is_fs_load = 0;
91008 + int register_filesystem_found = 0;
91009 + char *p;
91010 +
91011 + p = strstr(mod->args, "grsec_modharden_fs");
91012 + if (p) {
91013 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
91014 + /* copy \0 as well */
91015 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
91016 + is_fs_load = 1;
91017 + }
91018 +#endif
91019 +
91020 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
91021 const char *name = info->strtab + sym[i].st_name;
91022
91023 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91024 + /* it's a real shame this will never get ripped and copied
91025 + upstream! ;(
91026 + */
91027 + if (is_fs_load && !strcmp(name, "register_filesystem"))
91028 + register_filesystem_found = 1;
91029 +#endif
91030 +
91031 switch (sym[i].st_shndx) {
91032 case SHN_COMMON:
91033 /* Ignore common symbols */
91034 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91035 ksym = resolve_symbol_wait(mod, info, name);
91036 /* Ok if resolved. */
91037 if (ksym && !IS_ERR(ksym)) {
91038 + pax_open_kernel();
91039 sym[i].st_value = ksym->value;
91040 + pax_close_kernel();
91041 break;
91042 }
91043
91044 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91045 secbase = (unsigned long)mod_percpu(mod);
91046 else
91047 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
91048 + pax_open_kernel();
91049 sym[i].st_value += secbase;
91050 + pax_close_kernel();
91051 break;
91052 }
91053 }
91054
91055 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91056 + if (is_fs_load && !register_filesystem_found) {
91057 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
91058 + ret = -EPERM;
91059 + }
91060 +#endif
91061 +
91062 return ret;
91063 }
91064
91065 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
91066 || s->sh_entsize != ~0UL
91067 || strstarts(sname, ".init"))
91068 continue;
91069 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
91070 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91071 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
91072 + else
91073 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
91074 pr_debug("\t%s\n", sname);
91075 }
91076 - switch (m) {
91077 - case 0: /* executable */
91078 - mod->core_size = debug_align(mod->core_size);
91079 - mod->core_text_size = mod->core_size;
91080 - break;
91081 - case 1: /* RO: text and ro-data */
91082 - mod->core_size = debug_align(mod->core_size);
91083 - mod->core_ro_size = mod->core_size;
91084 - break;
91085 - case 3: /* whole core */
91086 - mod->core_size = debug_align(mod->core_size);
91087 - break;
91088 - }
91089 }
91090
91091 pr_debug("Init section allocation order:\n");
91092 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
91093 || s->sh_entsize != ~0UL
91094 || !strstarts(sname, ".init"))
91095 continue;
91096 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
91097 - | INIT_OFFSET_MASK);
91098 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91099 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
91100 + else
91101 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
91102 + s->sh_entsize |= INIT_OFFSET_MASK;
91103 pr_debug("\t%s\n", sname);
91104 }
91105 - switch (m) {
91106 - case 0: /* executable */
91107 - mod->init_size = debug_align(mod->init_size);
91108 - mod->init_text_size = mod->init_size;
91109 - break;
91110 - case 1: /* RO: text and ro-data */
91111 - mod->init_size = debug_align(mod->init_size);
91112 - mod->init_ro_size = mod->init_size;
91113 - break;
91114 - case 3: /* whole init */
91115 - mod->init_size = debug_align(mod->init_size);
91116 - break;
91117 - }
91118 }
91119 }
91120
91121 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91122
91123 /* Put symbol section at end of init part of module. */
91124 symsect->sh_flags |= SHF_ALLOC;
91125 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
91126 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
91127 info->index.sym) | INIT_OFFSET_MASK;
91128 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
91129
91130 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91131 }
91132
91133 /* Append room for core symbols at end of core part. */
91134 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
91135 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
91136 - mod->core_size += strtab_size;
91137 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
91138 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
91139 + mod->core_size_rx += strtab_size;
91140
91141 /* Put string table section at end of init part of module. */
91142 strsect->sh_flags |= SHF_ALLOC;
91143 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
91144 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
91145 info->index.str) | INIT_OFFSET_MASK;
91146 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
91147 }
91148 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91149 /* Make sure we get permanent strtab: don't use info->strtab. */
91150 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
91151
91152 + pax_open_kernel();
91153 +
91154 /* Set types up while we still have access to sections. */
91155 for (i = 0; i < mod->num_symtab; i++)
91156 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
91157
91158 - mod->core_symtab = dst = mod->module_core + info->symoffs;
91159 - mod->core_strtab = s = mod->module_core + info->stroffs;
91160 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
91161 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
91162 src = mod->symtab;
91163 for (ndst = i = 0; i < mod->num_symtab; i++) {
91164 if (i == 0 ||
91165 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91166 }
91167 }
91168 mod->core_num_syms = ndst;
91169 +
91170 + pax_close_kernel();
91171 }
91172 #else
91173 static inline void layout_symtab(struct module *mod, struct load_info *info)
91174 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
91175 return vmalloc_exec(size);
91176 }
91177
91178 -static void *module_alloc_update_bounds(unsigned long size)
91179 +static void *module_alloc_update_bounds_rw(unsigned long size)
91180 {
91181 void *ret = module_alloc(size);
91182
91183 if (ret) {
91184 mutex_lock(&module_mutex);
91185 /* Update module bounds. */
91186 - if ((unsigned long)ret < module_addr_min)
91187 - module_addr_min = (unsigned long)ret;
91188 - if ((unsigned long)ret + size > module_addr_max)
91189 - module_addr_max = (unsigned long)ret + size;
91190 + if ((unsigned long)ret < module_addr_min_rw)
91191 + module_addr_min_rw = (unsigned long)ret;
91192 + if ((unsigned long)ret + size > module_addr_max_rw)
91193 + module_addr_max_rw = (unsigned long)ret + size;
91194 + mutex_unlock(&module_mutex);
91195 + }
91196 + return ret;
91197 +}
91198 +
91199 +static void *module_alloc_update_bounds_rx(unsigned long size)
91200 +{
91201 + void *ret = module_alloc_exec(size);
91202 +
91203 + if (ret) {
91204 + mutex_lock(&module_mutex);
91205 + /* Update module bounds. */
91206 + if ((unsigned long)ret < module_addr_min_rx)
91207 + module_addr_min_rx = (unsigned long)ret;
91208 + if ((unsigned long)ret + size > module_addr_max_rx)
91209 + module_addr_max_rx = (unsigned long)ret + size;
91210 mutex_unlock(&module_mutex);
91211 }
91212 return ret;
91213 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91214 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
91215
91216 if (info->index.sym == 0) {
91217 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91218 + /*
91219 + * avoid potentially printing jibberish on attempted load
91220 + * of a module randomized with a different seed
91221 + */
91222 + pr_warn("module has no symbols (stripped?)\n");
91223 +#else
91224 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
91225 +#endif
91226 return ERR_PTR(-ENOEXEC);
91227 }
91228
91229 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91230 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91231 {
91232 const char *modmagic = get_modinfo(info, "vermagic");
91233 + const char *license = get_modinfo(info, "license");
91234 int err;
91235
91236 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91237 + if (!license || !license_is_gpl_compatible(license))
91238 + return -ENOEXEC;
91239 +#endif
91240 +
91241 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91242 modmagic = NULL;
91243
91244 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91245 }
91246
91247 /* Set up license info based on the info section */
91248 - set_license(mod, get_modinfo(info, "license"));
91249 + set_license(mod, license);
91250
91251 return 0;
91252 }
91253 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
91254 void *ptr;
91255
91256 /* Do the allocs. */
91257 - ptr = module_alloc_update_bounds(mod->core_size);
91258 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91259 /*
91260 * The pointer to this block is stored in the module structure
91261 * which is inside the block. Just mark it as not being a
91262 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
91263 if (!ptr)
91264 return -ENOMEM;
91265
91266 - memset(ptr, 0, mod->core_size);
91267 - mod->module_core = ptr;
91268 + memset(ptr, 0, mod->core_size_rw);
91269 + mod->module_core_rw = ptr;
91270
91271 - if (mod->init_size) {
91272 - ptr = module_alloc_update_bounds(mod->init_size);
91273 + if (mod->init_size_rw) {
91274 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91275 /*
91276 * The pointer to this block is stored in the module structure
91277 * which is inside the block. This block doesn't need to be
91278 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91279 */
91280 kmemleak_ignore(ptr);
91281 if (!ptr) {
91282 - module_free(mod, mod->module_core);
91283 + module_free(mod, mod->module_core_rw);
91284 return -ENOMEM;
91285 }
91286 - memset(ptr, 0, mod->init_size);
91287 - mod->module_init = ptr;
91288 + memset(ptr, 0, mod->init_size_rw);
91289 + mod->module_init_rw = ptr;
91290 } else
91291 - mod->module_init = NULL;
91292 + mod->module_init_rw = NULL;
91293 +
91294 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91295 + kmemleak_not_leak(ptr);
91296 + if (!ptr) {
91297 + if (mod->module_init_rw)
91298 + module_free(mod, mod->module_init_rw);
91299 + module_free(mod, mod->module_core_rw);
91300 + return -ENOMEM;
91301 + }
91302 +
91303 + pax_open_kernel();
91304 + memset(ptr, 0, mod->core_size_rx);
91305 + pax_close_kernel();
91306 + mod->module_core_rx = ptr;
91307 +
91308 + if (mod->init_size_rx) {
91309 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91310 + kmemleak_ignore(ptr);
91311 + if (!ptr && mod->init_size_rx) {
91312 + module_free_exec(mod, mod->module_core_rx);
91313 + if (mod->module_init_rw)
91314 + module_free(mod, mod->module_init_rw);
91315 + module_free(mod, mod->module_core_rw);
91316 + return -ENOMEM;
91317 + }
91318 +
91319 + pax_open_kernel();
91320 + memset(ptr, 0, mod->init_size_rx);
91321 + pax_close_kernel();
91322 + mod->module_init_rx = ptr;
91323 + } else
91324 + mod->module_init_rx = NULL;
91325
91326 /* Transfer each section which specifies SHF_ALLOC */
91327 pr_debug("final section addresses:\n");
91328 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91329 if (!(shdr->sh_flags & SHF_ALLOC))
91330 continue;
91331
91332 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
91333 - dest = mod->module_init
91334 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91335 - else
91336 - dest = mod->module_core + shdr->sh_entsize;
91337 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91338 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91339 + dest = mod->module_init_rw
91340 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91341 + else
91342 + dest = mod->module_init_rx
91343 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91344 + } else {
91345 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91346 + dest = mod->module_core_rw + shdr->sh_entsize;
91347 + else
91348 + dest = mod->module_core_rx + shdr->sh_entsize;
91349 + }
91350 +
91351 + if (shdr->sh_type != SHT_NOBITS) {
91352 +
91353 +#ifdef CONFIG_PAX_KERNEXEC
91354 +#ifdef CONFIG_X86_64
91355 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91356 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91357 +#endif
91358 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91359 + pax_open_kernel();
91360 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91361 + pax_close_kernel();
91362 + } else
91363 +#endif
91364
91365 - if (shdr->sh_type != SHT_NOBITS)
91366 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91367 + }
91368 /* Update sh_addr to point to copy in image. */
91369 - shdr->sh_addr = (unsigned long)dest;
91370 +
91371 +#ifdef CONFIG_PAX_KERNEXEC
91372 + if (shdr->sh_flags & SHF_EXECINSTR)
91373 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91374 + else
91375 +#endif
91376 +
91377 + shdr->sh_addr = (unsigned long)dest;
91378 pr_debug("\t0x%lx %s\n",
91379 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91380 }
91381 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91382 * Do it before processing of module parameters, so the module
91383 * can provide parameter accessor functions of its own.
91384 */
91385 - if (mod->module_init)
91386 - flush_icache_range((unsigned long)mod->module_init,
91387 - (unsigned long)mod->module_init
91388 - + mod->init_size);
91389 - flush_icache_range((unsigned long)mod->module_core,
91390 - (unsigned long)mod->module_core + mod->core_size);
91391 + if (mod->module_init_rx)
91392 + flush_icache_range((unsigned long)mod->module_init_rx,
91393 + (unsigned long)mod->module_init_rx
91394 + + mod->init_size_rx);
91395 + flush_icache_range((unsigned long)mod->module_core_rx,
91396 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91397
91398 set_fs(old_fs);
91399 }
91400 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91401 static void module_deallocate(struct module *mod, struct load_info *info)
91402 {
91403 percpu_modfree(mod);
91404 - module_free(mod, mod->module_init);
91405 - module_free(mod, mod->module_core);
91406 + module_free_exec(mod, mod->module_init_rx);
91407 + module_free_exec(mod, mod->module_core_rx);
91408 + module_free(mod, mod->module_init_rw);
91409 + module_free(mod, mod->module_core_rw);
91410 }
91411
91412 int __weak module_finalize(const Elf_Ehdr *hdr,
91413 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91414 static int post_relocation(struct module *mod, const struct load_info *info)
91415 {
91416 /* Sort exception table now relocations are done. */
91417 + pax_open_kernel();
91418 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91419 + pax_close_kernel();
91420
91421 /* Copy relocated percpu area over. */
91422 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91423 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91424 mod->strtab = mod->core_strtab;
91425 #endif
91426 unset_module_init_ro_nx(mod);
91427 - module_free(mod, mod->module_init);
91428 - mod->module_init = NULL;
91429 - mod->init_size = 0;
91430 - mod->init_ro_size = 0;
91431 - mod->init_text_size = 0;
91432 + module_free(mod, mod->module_init_rw);
91433 + module_free_exec(mod, mod->module_init_rx);
91434 + mod->module_init_rw = NULL;
91435 + mod->module_init_rx = NULL;
91436 + mod->init_size_rw = 0;
91437 + mod->init_size_rx = 0;
91438 mutex_unlock(&module_mutex);
91439 wake_up_all(&module_wq);
91440
91441 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91442 module_bug_finalize(info->hdr, info->sechdrs, mod);
91443
91444 /* Set RO and NX regions for core */
91445 - set_section_ro_nx(mod->module_core,
91446 - mod->core_text_size,
91447 - mod->core_ro_size,
91448 - mod->core_size);
91449 + set_section_ro_nx(mod->module_core_rx,
91450 + mod->core_size_rx,
91451 + mod->core_size_rx,
91452 + mod->core_size_rx);
91453
91454 /* Set RO and NX regions for init */
91455 - set_section_ro_nx(mod->module_init,
91456 - mod->init_text_size,
91457 - mod->init_ro_size,
91458 - mod->init_size);
91459 + set_section_ro_nx(mod->module_init_rx,
91460 + mod->init_size_rx,
91461 + mod->init_size_rx,
91462 + mod->init_size_rx);
91463
91464 /* Mark state as coming so strong_try_module_get() ignores us,
91465 * but kallsyms etc. can see us. */
91466 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91467 if (err)
91468 goto free_unload;
91469
91470 + /* Now copy in args */
91471 + mod->args = strndup_user(uargs, ~0UL >> 1);
91472 + if (IS_ERR(mod->args)) {
91473 + err = PTR_ERR(mod->args);
91474 + goto free_unload;
91475 + }
91476 +
91477 /* Set up MODINFO_ATTR fields */
91478 setup_modinfo(mod, info);
91479
91480 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91481 + {
91482 + char *p, *p2;
91483 +
91484 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91485 + 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);
91486 + err = -EPERM;
91487 + goto free_modinfo;
91488 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91489 + p += sizeof("grsec_modharden_normal") - 1;
91490 + p2 = strstr(p, "_");
91491 + if (p2) {
91492 + *p2 = '\0';
91493 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91494 + *p2 = '_';
91495 + }
91496 + err = -EPERM;
91497 + goto free_modinfo;
91498 + }
91499 + }
91500 +#endif
91501 +
91502 /* Fix up syms, so that st_value is a pointer to location. */
91503 err = simplify_symbols(mod, info);
91504 if (err < 0)
91505 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91506
91507 flush_module_icache(mod);
91508
91509 - /* Now copy in args */
91510 - mod->args = strndup_user(uargs, ~0UL >> 1);
91511 - if (IS_ERR(mod->args)) {
91512 - err = PTR_ERR(mod->args);
91513 - goto free_arch_cleanup;
91514 - }
91515 -
91516 dynamic_debug_setup(info->debug, info->num_debug);
91517
91518 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91519 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91520 ddebug_cleanup:
91521 dynamic_debug_remove(info->debug);
91522 synchronize_sched();
91523 - kfree(mod->args);
91524 - free_arch_cleanup:
91525 module_arch_cleanup(mod);
91526 free_modinfo:
91527 free_modinfo(mod);
91528 + kfree(mod->args);
91529 free_unload:
91530 module_unload_free(mod);
91531 unlink_mod:
91532 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91533 unsigned long nextval;
91534
91535 /* At worse, next value is at end of module */
91536 - if (within_module_init(addr, mod))
91537 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91538 + if (within_module_init_rx(addr, mod))
91539 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91540 + else if (within_module_init_rw(addr, mod))
91541 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91542 + else if (within_module_core_rx(addr, mod))
91543 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91544 + else if (within_module_core_rw(addr, mod))
91545 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91546 else
91547 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91548 + return NULL;
91549
91550 /* Scan for closest preceding symbol, and next symbol. (ELF
91551 starts real symbols at 1). */
91552 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91553 return 0;
91554
91555 seq_printf(m, "%s %u",
91556 - mod->name, mod->init_size + mod->core_size);
91557 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91558 print_unload_info(m, mod);
91559
91560 /* Informative for users. */
91561 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91562 mod->state == MODULE_STATE_COMING ? "Loading":
91563 "Live");
91564 /* Used by oprofile and other similar tools. */
91565 - seq_printf(m, " 0x%pK", mod->module_core);
91566 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91567
91568 /* Taints info */
91569 if (mod->taints)
91570 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91571
91572 static int __init proc_modules_init(void)
91573 {
91574 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91575 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91576 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91577 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91578 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91579 +#else
91580 proc_create("modules", 0, NULL, &proc_modules_operations);
91581 +#endif
91582 +#else
91583 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91584 +#endif
91585 return 0;
91586 }
91587 module_init(proc_modules_init);
91588 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91589 {
91590 struct module *mod;
91591
91592 - if (addr < module_addr_min || addr > module_addr_max)
91593 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91594 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91595 return NULL;
91596
91597 list_for_each_entry_rcu(mod, &modules, list) {
91598 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91599 */
91600 struct module *__module_text_address(unsigned long addr)
91601 {
91602 - struct module *mod = __module_address(addr);
91603 + struct module *mod;
91604 +
91605 +#ifdef CONFIG_X86_32
91606 + addr = ktla_ktva(addr);
91607 +#endif
91608 +
91609 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91610 + return NULL;
91611 +
91612 + mod = __module_address(addr);
91613 +
91614 if (mod) {
91615 /* Make sure it's within the text section. */
91616 - if (!within(addr, mod->module_init, mod->init_text_size)
91617 - && !within(addr, mod->module_core, mod->core_text_size))
91618 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91619 mod = NULL;
91620 }
91621 return mod;
91622 diff --git a/kernel/notifier.c b/kernel/notifier.c
91623 index 4803da6..1c5eea6 100644
91624 --- a/kernel/notifier.c
91625 +++ b/kernel/notifier.c
91626 @@ -5,6 +5,7 @@
91627 #include <linux/rcupdate.h>
91628 #include <linux/vmalloc.h>
91629 #include <linux/reboot.h>
91630 +#include <linux/mm.h>
91631
91632 /*
91633 * Notifier list for kernel code which wants to be called
91634 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91635 while ((*nl) != NULL) {
91636 if (n->priority > (*nl)->priority)
91637 break;
91638 - nl = &((*nl)->next);
91639 + nl = (struct notifier_block **)&((*nl)->next);
91640 }
91641 - n->next = *nl;
91642 + pax_open_kernel();
91643 + *(const void **)&n->next = *nl;
91644 rcu_assign_pointer(*nl, n);
91645 + pax_close_kernel();
91646 return 0;
91647 }
91648
91649 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91650 return 0;
91651 if (n->priority > (*nl)->priority)
91652 break;
91653 - nl = &((*nl)->next);
91654 + nl = (struct notifier_block **)&((*nl)->next);
91655 }
91656 - n->next = *nl;
91657 + pax_open_kernel();
91658 + *(const void **)&n->next = *nl;
91659 rcu_assign_pointer(*nl, n);
91660 + pax_close_kernel();
91661 return 0;
91662 }
91663
91664 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91665 {
91666 while ((*nl) != NULL) {
91667 if ((*nl) == n) {
91668 + pax_open_kernel();
91669 rcu_assign_pointer(*nl, n->next);
91670 + pax_close_kernel();
91671 return 0;
91672 }
91673 - nl = &((*nl)->next);
91674 + nl = (struct notifier_block **)&((*nl)->next);
91675 }
91676 return -ENOENT;
91677 }
91678 diff --git a/kernel/padata.c b/kernel/padata.c
91679 index 161402f..598814c 100644
91680 --- a/kernel/padata.c
91681 +++ b/kernel/padata.c
91682 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91683 * seq_nr mod. number of cpus in use.
91684 */
91685
91686 - seq_nr = atomic_inc_return(&pd->seq_nr);
91687 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91688 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91689
91690 return padata_index_to_cpu(pd, cpu_index);
91691 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91692 padata_init_pqueues(pd);
91693 padata_init_squeues(pd);
91694 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91695 - atomic_set(&pd->seq_nr, -1);
91696 + atomic_set_unchecked(&pd->seq_nr, -1);
91697 atomic_set(&pd->reorder_objects, 0);
91698 atomic_set(&pd->refcnt, 0);
91699 pd->pinst = pinst;
91700 diff --git a/kernel/panic.c b/kernel/panic.c
91701 index d09dc5c..9abbdff 100644
91702 --- a/kernel/panic.c
91703 +++ b/kernel/panic.c
91704 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91705 /*
91706 * Stop ourself in panic -- architecture code may override this
91707 */
91708 -void __weak panic_smp_self_stop(void)
91709 +void __weak __noreturn panic_smp_self_stop(void)
91710 {
91711 while (1)
91712 cpu_relax();
91713 @@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91714 disable_trace_on_warning();
91715
91716 pr_warn("------------[ cut here ]------------\n");
91717 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91718 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91719 raw_smp_processor_id(), current->pid, file, line, caller);
91720
91721 if (args)
91722 @@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91723 */
91724 __visible void __stack_chk_fail(void)
91725 {
91726 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91727 + dump_stack();
91728 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91729 __builtin_return_address(0));
91730 }
91731 EXPORT_SYMBOL(__stack_chk_fail);
91732 diff --git a/kernel/pid.c b/kernel/pid.c
91733 index 9b9a266..c20ef80 100644
91734 --- a/kernel/pid.c
91735 +++ b/kernel/pid.c
91736 @@ -33,6 +33,7 @@
91737 #include <linux/rculist.h>
91738 #include <linux/bootmem.h>
91739 #include <linux/hash.h>
91740 +#include <linux/security.h>
91741 #include <linux/pid_namespace.h>
91742 #include <linux/init_task.h>
91743 #include <linux/syscalls.h>
91744 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91745
91746 int pid_max = PID_MAX_DEFAULT;
91747
91748 -#define RESERVED_PIDS 300
91749 +#define RESERVED_PIDS 500
91750
91751 int pid_max_min = RESERVED_PIDS + 1;
91752 int pid_max_max = PID_MAX_LIMIT;
91753 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91754 */
91755 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91756 {
91757 + struct task_struct *task;
91758 +
91759 rcu_lockdep_assert(rcu_read_lock_held(),
91760 "find_task_by_pid_ns() needs rcu_read_lock()"
91761 " protection");
91762 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91763 +
91764 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91765 +
91766 + if (gr_pid_is_chrooted(task))
91767 + return NULL;
91768 +
91769 + return task;
91770 }
91771
91772 struct task_struct *find_task_by_vpid(pid_t vnr)
91773 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91774 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91775 }
91776
91777 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91778 +{
91779 + rcu_lockdep_assert(rcu_read_lock_held(),
91780 + "find_task_by_pid_ns() needs rcu_read_lock()"
91781 + " protection");
91782 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91783 +}
91784 +
91785 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91786 {
91787 struct pid *pid;
91788 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91789 index db95d8e..a0ca23f 100644
91790 --- a/kernel/pid_namespace.c
91791 +++ b/kernel/pid_namespace.c
91792 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91793 void __user *buffer, size_t *lenp, loff_t *ppos)
91794 {
91795 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91796 - struct ctl_table tmp = *table;
91797 + ctl_table_no_const tmp = *table;
91798
91799 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91800 return -EPERM;
91801 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91802 index e4e4121..71faf14 100644
91803 --- a/kernel/power/Kconfig
91804 +++ b/kernel/power/Kconfig
91805 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91806 config HIBERNATION
91807 bool "Hibernation (aka 'suspend to disk')"
91808 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91809 + depends on !GRKERNSEC_KMEM
91810 + depends on !PAX_MEMORY_SANITIZE
91811 select HIBERNATE_CALLBACKS
91812 select LZO_COMPRESS
91813 select LZO_DECOMPRESS
91814 diff --git a/kernel/power/process.c b/kernel/power/process.c
91815 index 7a37cf3..3e4c1c8 100644
91816 --- a/kernel/power/process.c
91817 +++ b/kernel/power/process.c
91818 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91819 unsigned int elapsed_msecs;
91820 bool wakeup = false;
91821 int sleep_usecs = USEC_PER_MSEC;
91822 + bool timedout = false;
91823
91824 do_gettimeofday(&start);
91825
91826 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91827
91828 while (true) {
91829 todo = 0;
91830 + if (time_after(jiffies, end_time))
91831 + timedout = true;
91832 read_lock(&tasklist_lock);
91833 do_each_thread(g, p) {
91834 if (p == current || !freeze_task(p))
91835 continue;
91836
91837 - if (!freezer_should_skip(p))
91838 + if (!freezer_should_skip(p)) {
91839 todo++;
91840 + if (timedout) {
91841 + printk(KERN_ERR "Task refusing to freeze:\n");
91842 + sched_show_task(p);
91843 + }
91844 + }
91845 } while_each_thread(g, p);
91846 read_unlock(&tasklist_lock);
91847
91848 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91849 todo += wq_busy;
91850 }
91851
91852 - if (!todo || time_after(jiffies, end_time))
91853 + if (!todo || timedout)
91854 break;
91855
91856 if (pm_wakeup_pending()) {
91857 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91858 index 1ce7706..3b07c49 100644
91859 --- a/kernel/printk/printk.c
91860 +++ b/kernel/printk/printk.c
91861 @@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
91862 if (from_file && type != SYSLOG_ACTION_OPEN)
91863 return 0;
91864
91865 +#ifdef CONFIG_GRKERNSEC_DMESG
91866 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91867 + return -EPERM;
91868 +#endif
91869 +
91870 if (syslog_action_restricted(type)) {
91871 if (capable(CAP_SYSLOG))
91872 return 0;
91873 diff --git a/kernel/profile.c b/kernel/profile.c
91874 index 54bf5ba..df6e0a2 100644
91875 --- a/kernel/profile.c
91876 +++ b/kernel/profile.c
91877 @@ -37,7 +37,7 @@ struct profile_hit {
91878 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91879 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91880
91881 -static atomic_t *prof_buffer;
91882 +static atomic_unchecked_t *prof_buffer;
91883 static unsigned long prof_len, prof_shift;
91884
91885 int prof_on __read_mostly;
91886 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91887 hits[i].pc = 0;
91888 continue;
91889 }
91890 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91891 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91892 hits[i].hits = hits[i].pc = 0;
91893 }
91894 }
91895 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91896 * Add the current hit(s) and flush the write-queue out
91897 * to the global buffer:
91898 */
91899 - atomic_add(nr_hits, &prof_buffer[pc]);
91900 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91901 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91902 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91903 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91904 hits[i].pc = hits[i].hits = 0;
91905 }
91906 out:
91907 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91908 {
91909 unsigned long pc;
91910 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91911 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91912 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91913 }
91914 #endif /* !CONFIG_SMP */
91915
91916 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91917 return -EFAULT;
91918 buf++; p++; count--; read++;
91919 }
91920 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91921 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91922 if (copy_to_user(buf, (void *)pnt, count))
91923 return -EFAULT;
91924 read += count;
91925 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91926 }
91927 #endif
91928 profile_discard_flip_buffers();
91929 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91930 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91931 return count;
91932 }
91933
91934 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91935 index 54e7522..5b82dd6 100644
91936 --- a/kernel/ptrace.c
91937 +++ b/kernel/ptrace.c
91938 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91939 if (seize)
91940 flags |= PT_SEIZED;
91941 rcu_read_lock();
91942 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91943 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91944 flags |= PT_PTRACE_CAP;
91945 rcu_read_unlock();
91946 task->ptrace = flags;
91947 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91948 break;
91949 return -EIO;
91950 }
91951 - if (copy_to_user(dst, buf, retval))
91952 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91953 return -EFAULT;
91954 copied += retval;
91955 src += retval;
91956 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91957 bool seized = child->ptrace & PT_SEIZED;
91958 int ret = -EIO;
91959 siginfo_t siginfo, *si;
91960 - void __user *datavp = (void __user *) data;
91961 + void __user *datavp = (__force void __user *) data;
91962 unsigned long __user *datalp = datavp;
91963 unsigned long flags;
91964
91965 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91966 goto out;
91967 }
91968
91969 + if (gr_handle_ptrace(child, request)) {
91970 + ret = -EPERM;
91971 + goto out_put_task_struct;
91972 + }
91973 +
91974 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91975 ret = ptrace_attach(child, request, addr, data);
91976 /*
91977 * Some architectures need to do book-keeping after
91978 * a ptrace attach.
91979 */
91980 - if (!ret)
91981 + if (!ret) {
91982 arch_ptrace_attach(child);
91983 + gr_audit_ptrace(child);
91984 + }
91985 goto out_put_task_struct;
91986 }
91987
91988 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91989 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91990 if (copied != sizeof(tmp))
91991 return -EIO;
91992 - return put_user(tmp, (unsigned long __user *)data);
91993 + return put_user(tmp, (__force unsigned long __user *)data);
91994 }
91995
91996 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91997 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91998 }
91999
92000 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92001 - compat_long_t, addr, compat_long_t, data)
92002 + compat_ulong_t, addr, compat_ulong_t, data)
92003 {
92004 struct task_struct *child;
92005 long ret;
92006 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92007 goto out;
92008 }
92009
92010 + if (gr_handle_ptrace(child, request)) {
92011 + ret = -EPERM;
92012 + goto out_put_task_struct;
92013 + }
92014 +
92015 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92016 ret = ptrace_attach(child, request, addr, data);
92017 /*
92018 * Some architectures need to do book-keeping after
92019 * a ptrace attach.
92020 */
92021 - if (!ret)
92022 + if (!ret) {
92023 arch_ptrace_attach(child);
92024 + gr_audit_ptrace(child);
92025 + }
92026 goto out_put_task_struct;
92027 }
92028
92029 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
92030 index 948a769..5ca842b 100644
92031 --- a/kernel/rcu/rcutorture.c
92032 +++ b/kernel/rcu/rcutorture.c
92033 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92034 rcu_torture_count) = { 0 };
92035 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92036 rcu_torture_batch) = { 0 };
92037 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92038 -static atomic_t n_rcu_torture_alloc;
92039 -static atomic_t n_rcu_torture_alloc_fail;
92040 -static atomic_t n_rcu_torture_free;
92041 -static atomic_t n_rcu_torture_mberror;
92042 -static atomic_t n_rcu_torture_error;
92043 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92044 +static atomic_unchecked_t n_rcu_torture_alloc;
92045 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
92046 +static atomic_unchecked_t n_rcu_torture_free;
92047 +static atomic_unchecked_t n_rcu_torture_mberror;
92048 +static atomic_unchecked_t n_rcu_torture_error;
92049 static long n_rcu_torture_barrier_error;
92050 static long n_rcu_torture_boost_ktrerror;
92051 static long n_rcu_torture_boost_rterror;
92052 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
92053
92054 spin_lock_bh(&rcu_torture_lock);
92055 if (list_empty(&rcu_torture_freelist)) {
92056 - atomic_inc(&n_rcu_torture_alloc_fail);
92057 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
92058 spin_unlock_bh(&rcu_torture_lock);
92059 return NULL;
92060 }
92061 - atomic_inc(&n_rcu_torture_alloc);
92062 + atomic_inc_unchecked(&n_rcu_torture_alloc);
92063 p = rcu_torture_freelist.next;
92064 list_del_init(p);
92065 spin_unlock_bh(&rcu_torture_lock);
92066 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
92067 static void
92068 rcu_torture_free(struct rcu_torture *p)
92069 {
92070 - atomic_inc(&n_rcu_torture_free);
92071 + atomic_inc_unchecked(&n_rcu_torture_free);
92072 spin_lock_bh(&rcu_torture_lock);
92073 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
92074 spin_unlock_bh(&rcu_torture_lock);
92075 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
92076 i = rp->rtort_pipe_count;
92077 if (i > RCU_TORTURE_PIPE_LEN)
92078 i = RCU_TORTURE_PIPE_LEN;
92079 - atomic_inc(&rcu_torture_wcount[i]);
92080 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92081 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
92082 rp->rtort_mbtest = 0;
92083 return true;
92084 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
92085 i = old_rp->rtort_pipe_count;
92086 if (i > RCU_TORTURE_PIPE_LEN)
92087 i = RCU_TORTURE_PIPE_LEN;
92088 - atomic_inc(&rcu_torture_wcount[i]);
92089 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92090 old_rp->rtort_pipe_count++;
92091 switch (synctype[torture_random(&rand) % nsynctypes]) {
92092 case RTWS_DEF_FREE:
92093 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
92094 return;
92095 }
92096 if (p->rtort_mbtest == 0)
92097 - atomic_inc(&n_rcu_torture_mberror);
92098 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92099 spin_lock(&rand_lock);
92100 cur_ops->read_delay(&rand);
92101 n_rcu_torture_timers++;
92102 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
92103 continue;
92104 }
92105 if (p->rtort_mbtest == 0)
92106 - atomic_inc(&n_rcu_torture_mberror);
92107 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92108 cur_ops->read_delay(&rand);
92109 preempt_disable();
92110 pipe_count = p->rtort_pipe_count;
92111 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
92112 }
92113 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
92114 page += sprintf(page,
92115 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92116 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92117 rcu_torture_current,
92118 rcu_torture_current_version,
92119 list_empty(&rcu_torture_freelist),
92120 - atomic_read(&n_rcu_torture_alloc),
92121 - atomic_read(&n_rcu_torture_alloc_fail),
92122 - atomic_read(&n_rcu_torture_free));
92123 + atomic_read_unchecked(&n_rcu_torture_alloc),
92124 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
92125 + atomic_read_unchecked(&n_rcu_torture_free));
92126 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
92127 - atomic_read(&n_rcu_torture_mberror),
92128 + atomic_read_unchecked(&n_rcu_torture_mberror),
92129 n_rcu_torture_boost_ktrerror,
92130 n_rcu_torture_boost_rterror);
92131 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
92132 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
92133 n_barrier_attempts,
92134 n_rcu_torture_barrier_error);
92135 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
92136 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
92137 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
92138 n_rcu_torture_barrier_error != 0 ||
92139 n_rcu_torture_boost_ktrerror != 0 ||
92140 n_rcu_torture_boost_rterror != 0 ||
92141 n_rcu_torture_boost_failure != 0 ||
92142 i > 1) {
92143 page += sprintf(page, "!!! ");
92144 - atomic_inc(&n_rcu_torture_error);
92145 + atomic_inc_unchecked(&n_rcu_torture_error);
92146 WARN_ON_ONCE(1);
92147 }
92148 page += sprintf(page, "Reader Pipe: ");
92149 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
92150 page += sprintf(page, "Free-Block Circulation: ");
92151 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92152 page += sprintf(page, " %d",
92153 - atomic_read(&rcu_torture_wcount[i]));
92154 + atomic_read_unchecked(&rcu_torture_wcount[i]));
92155 }
92156 page += sprintf(page, "\n");
92157 if (cur_ops->stats)
92158 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
92159
92160 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
92161
92162 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92163 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92164 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
92165 else if (torture_onoff_failures())
92166 rcu_torture_print_module_parms(cur_ops,
92167 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
92168
92169 rcu_torture_current = NULL;
92170 rcu_torture_current_version = 0;
92171 - atomic_set(&n_rcu_torture_alloc, 0);
92172 - atomic_set(&n_rcu_torture_alloc_fail, 0);
92173 - atomic_set(&n_rcu_torture_free, 0);
92174 - atomic_set(&n_rcu_torture_mberror, 0);
92175 - atomic_set(&n_rcu_torture_error, 0);
92176 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
92177 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
92178 + atomic_set_unchecked(&n_rcu_torture_free, 0);
92179 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
92180 + atomic_set_unchecked(&n_rcu_torture_error, 0);
92181 n_rcu_torture_barrier_error = 0;
92182 n_rcu_torture_boost_ktrerror = 0;
92183 n_rcu_torture_boost_rterror = 0;
92184 n_rcu_torture_boost_failure = 0;
92185 n_rcu_torture_boosts = 0;
92186 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
92187 - atomic_set(&rcu_torture_wcount[i], 0);
92188 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
92189 for_each_possible_cpu(cpu) {
92190 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92191 per_cpu(rcu_torture_count, cpu)[i] = 0;
92192 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
92193 index d9efcc1..ea543e9 100644
92194 --- a/kernel/rcu/tiny.c
92195 +++ b/kernel/rcu/tiny.c
92196 @@ -42,7 +42,7 @@
92197 /* Forward declarations for tiny_plugin.h. */
92198 struct rcu_ctrlblk;
92199 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
92200 -static void rcu_process_callbacks(struct softirq_action *unused);
92201 +static void rcu_process_callbacks(void);
92202 static void __call_rcu(struct rcu_head *head,
92203 void (*func)(struct rcu_head *rcu),
92204 struct rcu_ctrlblk *rcp);
92205 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
92206 false));
92207 }
92208
92209 -static void rcu_process_callbacks(struct softirq_action *unused)
92210 +static __latent_entropy void rcu_process_callbacks(void)
92211 {
92212 __rcu_process_callbacks(&rcu_sched_ctrlblk);
92213 __rcu_process_callbacks(&rcu_bh_ctrlblk);
92214 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
92215 index 858c565..7efd915 100644
92216 --- a/kernel/rcu/tiny_plugin.h
92217 +++ b/kernel/rcu/tiny_plugin.h
92218 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
92219 dump_stack();
92220 }
92221 if (*rcp->curtail && ULONG_CMP_GE(j, js))
92222 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
92223 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
92224 3 * rcu_jiffies_till_stall_check() + 3;
92225 else if (ULONG_CMP_GE(j, js))
92226 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92227 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92228 }
92229
92230 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
92231 {
92232 rcp->ticks_this_gp = 0;
92233 rcp->gp_start = jiffies;
92234 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92235 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92236 }
92237
92238 static void check_cpu_stalls(void)
92239 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
92240 index 89a404a..f42a019 100644
92241 --- a/kernel/rcu/tree.c
92242 +++ b/kernel/rcu/tree.c
92243 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
92244 */
92245 rdtp = this_cpu_ptr(&rcu_dynticks);
92246 smp_mb__before_atomic(); /* Earlier stuff before QS. */
92247 - atomic_add(2, &rdtp->dynticks); /* QS. */
92248 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
92249 smp_mb__after_atomic(); /* Later stuff after QS. */
92250 break;
92251 }
92252 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
92253 rcu_prepare_for_idle(smp_processor_id());
92254 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92255 smp_mb__before_atomic(); /* See above. */
92256 - atomic_inc(&rdtp->dynticks);
92257 + atomic_inc_unchecked(&rdtp->dynticks);
92258 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
92259 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92260 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92261
92262 /*
92263 * It is illegal to enter an extended quiescent state while
92264 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
92265 int user)
92266 {
92267 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
92268 - atomic_inc(&rdtp->dynticks);
92269 + atomic_inc_unchecked(&rdtp->dynticks);
92270 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92271 smp_mb__after_atomic(); /* See above. */
92272 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92273 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92274 rcu_cleanup_after_idle(smp_processor_id());
92275 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
92276 if (!user && !is_idle_task(current)) {
92277 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
92278 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92279
92280 if (rdtp->dynticks_nmi_nesting == 0 &&
92281 - (atomic_read(&rdtp->dynticks) & 0x1))
92282 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92283 return;
92284 rdtp->dynticks_nmi_nesting++;
92285 smp_mb__before_atomic(); /* Force delay from prior write. */
92286 - atomic_inc(&rdtp->dynticks);
92287 + atomic_inc_unchecked(&rdtp->dynticks);
92288 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92289 smp_mb__after_atomic(); /* See above. */
92290 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92291 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92292 }
92293
92294 /**
92295 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
92296 return;
92297 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92298 smp_mb__before_atomic(); /* See above. */
92299 - atomic_inc(&rdtp->dynticks);
92300 + atomic_inc_unchecked(&rdtp->dynticks);
92301 smp_mb__after_atomic(); /* Force delay to next write. */
92302 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92303 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92304 }
92305
92306 /**
92307 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
92308 */
92309 bool notrace __rcu_is_watching(void)
92310 {
92311 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92312 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92313 }
92314
92315 /**
92316 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92317 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92318 bool *isidle, unsigned long *maxj)
92319 {
92320 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92321 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92322 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92323 if ((rdp->dynticks_snap & 0x1) == 0) {
92324 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92325 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92326 int *rcrmp;
92327 unsigned int snap;
92328
92329 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92330 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92331 snap = (unsigned int)rdp->dynticks_snap;
92332
92333 /*
92334 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92335 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92336 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92337 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92338 - ACCESS_ONCE(rdp->cond_resched_completed) =
92339 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92340 ACCESS_ONCE(rdp->mynode->completed);
92341 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92342 - ACCESS_ONCE(*rcrmp) =
92343 + ACCESS_ONCE_RW(*rcrmp) =
92344 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92345 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92346 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92347 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92348 rsp->gp_start = j;
92349 smp_wmb(); /* Record start time before stall time. */
92350 j1 = rcu_jiffies_till_stall_check();
92351 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92352 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92353 rsp->jiffies_resched = j + j1 / 2;
92354 }
92355
92356 @@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92357 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92358 return;
92359 }
92360 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92361 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92362 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92363
92364 /*
92365 @@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92366
92367 raw_spin_lock_irqsave(&rnp->lock, flags);
92368 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92369 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92370 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92371 3 * rcu_jiffies_till_stall_check() + 3;
92372 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92373
92374 @@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
92375 struct rcu_state *rsp;
92376
92377 for_each_rcu_flavor(rsp)
92378 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92379 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92380 }
92381
92382 /*
92383 @@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92384 raw_spin_unlock_irq(&rnp->lock);
92385 return 0;
92386 }
92387 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92388 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92389
92390 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92391 /*
92392 @@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92393 rdp = this_cpu_ptr(rsp->rda);
92394 rcu_preempt_check_blocked_tasks(rnp);
92395 rnp->qsmask = rnp->qsmaskinit;
92396 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92397 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92398 WARN_ON_ONCE(rnp->completed != rsp->completed);
92399 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92400 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92401 if (rnp == rdp->mynode)
92402 (void)__note_gp_changes(rsp, rnp, rdp);
92403 rcu_preempt_boost_start_gp(rnp);
92404 @@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92405 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92406 raw_spin_lock_irq(&rnp->lock);
92407 smp_mb__after_unlock_lock();
92408 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92409 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92410 raw_spin_unlock_irq(&rnp->lock);
92411 }
92412 return fqs_state;
92413 @@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92414 rcu_for_each_node_breadth_first(rsp, rnp) {
92415 raw_spin_lock_irq(&rnp->lock);
92416 smp_mb__after_unlock_lock();
92417 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92418 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92419 rdp = this_cpu_ptr(rsp->rda);
92420 if (rnp == rdp->mynode)
92421 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92422 @@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92423 rcu_nocb_gp_set(rnp, nocb);
92424
92425 /* Declare grace period done. */
92426 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92427 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92428 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92429 rsp->fqs_state = RCU_GP_IDLE;
92430 rdp = this_cpu_ptr(rsp->rda);
92431 /* Advance CBs to reduce false positives below. */
92432 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92433 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92434 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92435 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92436 trace_rcu_grace_period(rsp->name,
92437 ACCESS_ONCE(rsp->gpnum),
92438 TPS("newreq"));
92439 @@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92440 */
92441 return false;
92442 }
92443 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92444 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92445 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92446 TPS("newreq"));
92447
92448 @@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92449 rsp->qlen += rdp->qlen;
92450 rdp->n_cbs_orphaned += rdp->qlen;
92451 rdp->qlen_lazy = 0;
92452 - ACCESS_ONCE(rdp->qlen) = 0;
92453 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92454 }
92455
92456 /*
92457 @@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92458 }
92459 smp_mb(); /* List handling before counting for rcu_barrier(). */
92460 rdp->qlen_lazy -= count_lazy;
92461 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92462 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92463 rdp->n_cbs_invoked += count;
92464
92465 /* Reinstate batch limit if we have worked down the excess. */
92466 @@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92467 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92468 return; /* Someone beat us to it. */
92469 }
92470 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92471 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92472 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92473 rcu_gp_kthread_wake(rsp);
92474 }
92475 @@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92476 /*
92477 * Do RCU core processing for the current CPU.
92478 */
92479 -static void rcu_process_callbacks(struct softirq_action *unused)
92480 +static void rcu_process_callbacks(void)
92481 {
92482 struct rcu_state *rsp;
92483
92484 @@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92485 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92486 if (debug_rcu_head_queue(head)) {
92487 /* Probable double call_rcu(), so leak the callback. */
92488 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92489 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92490 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92491 return;
92492 }
92493 @@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92494 local_irq_restore(flags);
92495 return;
92496 }
92497 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92498 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92499 if (lazy)
92500 rdp->qlen_lazy++;
92501 else
92502 @@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
92503 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92504 * course be required on a 64-bit system.
92505 */
92506 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92507 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92508 (ulong)atomic_long_read(&rsp->expedited_done) +
92509 ULONG_MAX / 8)) {
92510 synchronize_sched();
92511 - atomic_long_inc(&rsp->expedited_wrap);
92512 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92513 return;
92514 }
92515
92516 @@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
92517 * Take a ticket. Note that atomic_inc_return() implies a
92518 * full memory barrier.
92519 */
92520 - snap = atomic_long_inc_return(&rsp->expedited_start);
92521 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92522 firstsnap = snap;
92523 get_online_cpus();
92524 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92525 @@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
92526 synchronize_sched_expedited_cpu_stop,
92527 NULL) == -EAGAIN) {
92528 put_online_cpus();
92529 - atomic_long_inc(&rsp->expedited_tryfail);
92530 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92531
92532 /* Check to see if someone else did our work for us. */
92533 s = atomic_long_read(&rsp->expedited_done);
92534 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92535 /* ensure test happens before caller kfree */
92536 smp_mb__before_atomic(); /* ^^^ */
92537 - atomic_long_inc(&rsp->expedited_workdone1);
92538 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92539 return;
92540 }
92541
92542 @@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
92543 udelay(trycount * num_online_cpus());
92544 } else {
92545 wait_rcu_gp(call_rcu_sched);
92546 - atomic_long_inc(&rsp->expedited_normal);
92547 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92548 return;
92549 }
92550
92551 @@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
92552 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92553 /* ensure test happens before caller kfree */
92554 smp_mb__before_atomic(); /* ^^^ */
92555 - atomic_long_inc(&rsp->expedited_workdone2);
92556 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92557 return;
92558 }
92559
92560 @@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
92561 * period works for us.
92562 */
92563 get_online_cpus();
92564 - snap = atomic_long_read(&rsp->expedited_start);
92565 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92566 smp_mb(); /* ensure read is before try_stop_cpus(). */
92567 }
92568 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92569 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92570
92571 /*
92572 * Everyone up to our most recent fetch is covered by our grace
92573 @@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
92574 * than we did already did their update.
92575 */
92576 do {
92577 - atomic_long_inc(&rsp->expedited_done_tries);
92578 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92579 s = atomic_long_read(&rsp->expedited_done);
92580 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92581 /* ensure test happens before caller kfree */
92582 smp_mb__before_atomic(); /* ^^^ */
92583 - atomic_long_inc(&rsp->expedited_done_lost);
92584 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92585 break;
92586 }
92587 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92588 - atomic_long_inc(&rsp->expedited_done_exit);
92589 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92590
92591 put_online_cpus();
92592 }
92593 @@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92594 * ACCESS_ONCE() to prevent the compiler from speculating
92595 * the increment to precede the early-exit check.
92596 */
92597 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92598 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92599 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92600 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92601 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92602 @@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92603
92604 /* Increment ->n_barrier_done to prevent duplicate work. */
92605 smp_mb(); /* Keep increment after above mechanism. */
92606 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92607 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92608 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92609 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92610 smp_mb(); /* Keep increment before caller's subsequent code. */
92611 @@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92612 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92613 init_callback_list(rdp);
92614 rdp->qlen_lazy = 0;
92615 - ACCESS_ONCE(rdp->qlen) = 0;
92616 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92617 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92618 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92619 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92620 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92621 rdp->cpu = cpu;
92622 rdp->rsp = rsp;
92623 rcu_boot_init_nocb_percpu_data(rdp);
92624 @@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92625 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92626 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92627 rcu_sysidle_init_percpu_data(rdp->dynticks);
92628 - atomic_set(&rdp->dynticks->dynticks,
92629 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92630 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92631 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92632 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92633
92634 /* Add CPU to rcu_node bitmasks. */
92635 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92636 index 6a86eb7..022b506 100644
92637 --- a/kernel/rcu/tree.h
92638 +++ b/kernel/rcu/tree.h
92639 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92640 long long dynticks_nesting; /* Track irq/process nesting level. */
92641 /* Process level is worth LLONG_MAX/2. */
92642 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92643 - atomic_t dynticks; /* Even value for idle, else odd. */
92644 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92645 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92646 long long dynticks_idle_nesting;
92647 /* irq/process nesting level from idle. */
92648 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92649 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92650 /* "Idle" excludes userspace execution. */
92651 unsigned long dynticks_idle_jiffies;
92652 /* End of last non-NMI non-idle period. */
92653 @@ -461,17 +461,17 @@ struct rcu_state {
92654 /* _rcu_barrier(). */
92655 /* End of fields guarded by barrier_mutex. */
92656
92657 - atomic_long_t expedited_start; /* Starting ticket. */
92658 - atomic_long_t expedited_done; /* Done ticket. */
92659 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92660 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92661 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92662 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92663 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92664 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92665 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92666 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92667 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92668 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92669 + atomic_long_t expedited_done; /* Done ticket. */
92670 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92671 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92672 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92673 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92674 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92675 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92676 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92677 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92678 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92679
92680 unsigned long jiffies_force_qs; /* Time at which to invoke */
92681 /* force_quiescent_state(). */
92682 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92683 index a7997e2..9787c9e 100644
92684 --- a/kernel/rcu/tree_plugin.h
92685 +++ b/kernel/rcu/tree_plugin.h
92686 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92687 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92688 {
92689 return !rcu_preempted_readers_exp(rnp) &&
92690 - ACCESS_ONCE(rnp->expmask) == 0;
92691 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92692 }
92693
92694 /*
92695 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
92696
92697 /* Clean up and exit. */
92698 smp_mb(); /* ensure expedited GP seen before counter increment. */
92699 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
92700 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
92701 unlock_mb_ret:
92702 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92703 mb_ret:
92704 @@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92705 free_cpumask_var(cm);
92706 }
92707
92708 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92709 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92710 .store = &rcu_cpu_kthread_task,
92711 .thread_should_run = rcu_cpu_kthread_should_run,
92712 .thread_fn = rcu_cpu_kthread,
92713 @@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92714 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92715 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92716 cpu, ticks_value, ticks_title,
92717 - atomic_read(&rdtp->dynticks) & 0xfff,
92718 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92719 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92720 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92721 fast_no_hz);
92722 @@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92723 return;
92724 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92725 /* Prior xchg orders against prior callback enqueue. */
92726 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92727 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92728 wake_up(&rdp_leader->nocb_wq);
92729 }
92730 }
92731 @@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92732
92733 /* Enqueue the callback on the nocb list and update counts. */
92734 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92735 - ACCESS_ONCE(*old_rhpp) = rhp;
92736 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92737 atomic_long_add(rhcount, &rdp->nocb_q_count);
92738 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92739
92740 @@ -2272,7 +2272,7 @@ wait_again:
92741 continue; /* No CBs here, try next follower. */
92742
92743 /* Move callbacks to wait-for-GP list, which is empty. */
92744 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92745 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92746 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92747 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92748 rdp->nocb_gp_count_lazy =
92749 @@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
92750 list = ACCESS_ONCE(rdp->nocb_follower_head);
92751 BUG_ON(!list);
92752 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92753 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92754 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92755 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92756 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92757 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92758 @@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
92759 list = next;
92760 }
92761 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92762 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
92763 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
92764 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
92765 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
92766 rdp->n_nocbs_invoked += c;
92767 }
92768 return 0;
92769 @@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92770 {
92771 if (!rcu_nocb_need_deferred_wakeup(rdp))
92772 return;
92773 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
92774 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
92775 wake_nocb_leader(rdp, false);
92776 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
92777 }
92778 @@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
92779 t = kthread_run(rcu_nocb_kthread, rdp,
92780 "rcuo%c/%d", rsp->abbr, cpu);
92781 BUG_ON(IS_ERR(t));
92782 - ACCESS_ONCE(rdp->nocb_kthread) = t;
92783 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
92784 }
92785 }
92786
92787 @@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92788
92789 /* Record start of fully idle period. */
92790 j = jiffies;
92791 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92792 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92793 smp_mb__before_atomic();
92794 - atomic_inc(&rdtp->dynticks_idle);
92795 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92796 smp_mb__after_atomic();
92797 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92798 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92799 }
92800
92801 /*
92802 @@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92803
92804 /* Record end of idle period. */
92805 smp_mb__before_atomic();
92806 - atomic_inc(&rdtp->dynticks_idle);
92807 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92808 smp_mb__after_atomic();
92809 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92810 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92811
92812 /*
92813 * If we are the timekeeping CPU, we are permitted to be non-idle
92814 @@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92815 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92816
92817 /* Pick up current idle and NMI-nesting counter and check. */
92818 - cur = atomic_read(&rdtp->dynticks_idle);
92819 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92820 if (cur & 0x1) {
92821 *isidle = false; /* We are not idle! */
92822 return;
92823 @@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
92824 case RCU_SYSIDLE_NOT:
92825
92826 /* First time all are idle, so note a short idle period. */
92827 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92828 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92829 break;
92830
92831 case RCU_SYSIDLE_SHORT:
92832 @@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
92833 {
92834 smp_mb();
92835 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92836 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92837 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92838 }
92839
92840 /*
92841 @@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92842 smp_mb(); /* grace period precedes setting inuse. */
92843
92844 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92845 - ACCESS_ONCE(rshp->inuse) = 0;
92846 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92847 }
92848
92849 /*
92850 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92851 index 5cdc62e..cc52e88 100644
92852 --- a/kernel/rcu/tree_trace.c
92853 +++ b/kernel/rcu/tree_trace.c
92854 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92855 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92856 rdp->passed_quiesce, rdp->qs_pending);
92857 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92858 - atomic_read(&rdp->dynticks->dynticks),
92859 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92860 rdp->dynticks->dynticks_nesting,
92861 rdp->dynticks->dynticks_nmi_nesting,
92862 rdp->dynticks_fqs);
92863 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92864 struct rcu_state *rsp = (struct rcu_state *)m->private;
92865
92866 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",
92867 - atomic_long_read(&rsp->expedited_start),
92868 + atomic_long_read_unchecked(&rsp->expedited_start),
92869 atomic_long_read(&rsp->expedited_done),
92870 - atomic_long_read(&rsp->expedited_wrap),
92871 - atomic_long_read(&rsp->expedited_tryfail),
92872 - atomic_long_read(&rsp->expedited_workdone1),
92873 - atomic_long_read(&rsp->expedited_workdone2),
92874 - atomic_long_read(&rsp->expedited_normal),
92875 - atomic_long_read(&rsp->expedited_stoppedcpus),
92876 - atomic_long_read(&rsp->expedited_done_tries),
92877 - atomic_long_read(&rsp->expedited_done_lost),
92878 - atomic_long_read(&rsp->expedited_done_exit));
92879 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92880 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92881 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92882 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92883 + atomic_long_read_unchecked(&rsp->expedited_normal),
92884 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92885 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92886 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92887 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92888 return 0;
92889 }
92890
92891 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92892 index 4056d79..c11741a 100644
92893 --- a/kernel/rcu/update.c
92894 +++ b/kernel/rcu/update.c
92895 @@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
92896 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92897 */
92898 if (till_stall_check < 3) {
92899 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92900 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92901 till_stall_check = 3;
92902 } else if (till_stall_check > 300) {
92903 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92904 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92905 till_stall_check = 300;
92906 }
92907 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92908 diff --git a/kernel/resource.c b/kernel/resource.c
92909 index 60c5a38..ed77193 100644
92910 --- a/kernel/resource.c
92911 +++ b/kernel/resource.c
92912 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92913
92914 static int __init ioresources_init(void)
92915 {
92916 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92917 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92918 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92919 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92920 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92921 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92922 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92923 +#endif
92924 +#else
92925 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92926 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92927 +#endif
92928 return 0;
92929 }
92930 __initcall(ioresources_init);
92931 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92932 index e73efba..c9bfbd4 100644
92933 --- a/kernel/sched/auto_group.c
92934 +++ b/kernel/sched/auto_group.c
92935 @@ -11,7 +11,7 @@
92936
92937 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92938 static struct autogroup autogroup_default;
92939 -static atomic_t autogroup_seq_nr;
92940 +static atomic_unchecked_t autogroup_seq_nr;
92941
92942 void __init autogroup_init(struct task_struct *init_task)
92943 {
92944 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92945
92946 kref_init(&ag->kref);
92947 init_rwsem(&ag->lock);
92948 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92949 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92950 ag->tg = tg;
92951 #ifdef CONFIG_RT_GROUP_SCHED
92952 /*
92953 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92954 index a63f4dc..349bbb0 100644
92955 --- a/kernel/sched/completion.c
92956 +++ b/kernel/sched/completion.c
92957 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92958 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92959 * or number of jiffies left till timeout) if completed.
92960 */
92961 -long __sched
92962 +long __sched __intentional_overflow(-1)
92963 wait_for_completion_interruptible_timeout(struct completion *x,
92964 unsigned long timeout)
92965 {
92966 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92967 *
92968 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92969 */
92970 -int __sched wait_for_completion_killable(struct completion *x)
92971 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92972 {
92973 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92974 if (t == -ERESTARTSYS)
92975 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92976 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92977 * or number of jiffies left till timeout) if completed.
92978 */
92979 -long __sched
92980 +long __sched __intentional_overflow(-1)
92981 wait_for_completion_killable_timeout(struct completion *x,
92982 unsigned long timeout)
92983 {
92984 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92985 index 6d7cb91..420f2d2 100644
92986 --- a/kernel/sched/core.c
92987 +++ b/kernel/sched/core.c
92988 @@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
92989 int sysctl_numa_balancing(struct ctl_table *table, int write,
92990 void __user *buffer, size_t *lenp, loff_t *ppos)
92991 {
92992 - struct ctl_table t;
92993 + ctl_table_no_const t;
92994 int err;
92995 int state = numabalancing_enabled;
92996
92997 @@ -2324,8 +2324,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92998 next->active_mm = oldmm;
92999 atomic_inc(&oldmm->mm_count);
93000 enter_lazy_tlb(oldmm, next);
93001 - } else
93002 + } else {
93003 switch_mm(oldmm, mm, next);
93004 + populate_stack();
93005 + }
93006
93007 if (!prev->mm) {
93008 prev->active_mm = NULL;
93009 @@ -3107,6 +3109,8 @@ int can_nice(const struct task_struct *p, const int nice)
93010 /* convert nice value [19,-20] to rlimit style value [1,40] */
93011 int nice_rlim = nice_to_rlimit(nice);
93012
93013 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
93014 +
93015 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
93016 capable(CAP_SYS_NICE));
93017 }
93018 @@ -3133,7 +3137,8 @@ SYSCALL_DEFINE1(nice, int, increment)
93019 nice = task_nice(current) + increment;
93020
93021 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
93022 - if (increment < 0 && !can_nice(current, nice))
93023 + if (increment < 0 && (!can_nice(current, nice) ||
93024 + gr_handle_chroot_nice()))
93025 return -EPERM;
93026
93027 retval = security_task_setnice(current, nice);
93028 @@ -3412,6 +3417,7 @@ recheck:
93029 if (policy != p->policy && !rlim_rtprio)
93030 return -EPERM;
93031
93032 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
93033 /* can't increase priority */
93034 if (attr->sched_priority > p->rt_priority &&
93035 attr->sched_priority > rlim_rtprio)
93036 @@ -4802,6 +4808,7 @@ void idle_task_exit(void)
93037
93038 if (mm != &init_mm) {
93039 switch_mm(mm, &init_mm, current);
93040 + populate_stack();
93041 finish_arch_post_lock_switch();
93042 }
93043 mmdrop(mm);
93044 @@ -4897,7 +4904,7 @@ static void migrate_tasks(unsigned int dead_cpu)
93045
93046 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
93047
93048 -static struct ctl_table sd_ctl_dir[] = {
93049 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
93050 {
93051 .procname = "sched_domain",
93052 .mode = 0555,
93053 @@ -4914,17 +4921,17 @@ static struct ctl_table sd_ctl_root[] = {
93054 {}
93055 };
93056
93057 -static struct ctl_table *sd_alloc_ctl_entry(int n)
93058 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
93059 {
93060 - struct ctl_table *entry =
93061 + ctl_table_no_const *entry =
93062 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
93063
93064 return entry;
93065 }
93066
93067 -static void sd_free_ctl_entry(struct ctl_table **tablep)
93068 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
93069 {
93070 - struct ctl_table *entry;
93071 + ctl_table_no_const *entry;
93072
93073 /*
93074 * In the intermediate directories, both the child directory and
93075 @@ -4932,22 +4939,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
93076 * will always be set. In the lowest directory the names are
93077 * static strings and all have proc handlers.
93078 */
93079 - for (entry = *tablep; entry->mode; entry++) {
93080 - if (entry->child)
93081 - sd_free_ctl_entry(&entry->child);
93082 + for (entry = tablep; entry->mode; entry++) {
93083 + if (entry->child) {
93084 + sd_free_ctl_entry(entry->child);
93085 + pax_open_kernel();
93086 + entry->child = NULL;
93087 + pax_close_kernel();
93088 + }
93089 if (entry->proc_handler == NULL)
93090 kfree(entry->procname);
93091 }
93092
93093 - kfree(*tablep);
93094 - *tablep = NULL;
93095 + kfree(tablep);
93096 }
93097
93098 static int min_load_idx = 0;
93099 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
93100
93101 static void
93102 -set_table_entry(struct ctl_table *entry,
93103 +set_table_entry(ctl_table_no_const *entry,
93104 const char *procname, void *data, int maxlen,
93105 umode_t mode, proc_handler *proc_handler,
93106 bool load_idx)
93107 @@ -4967,7 +4977,7 @@ set_table_entry(struct ctl_table *entry,
93108 static struct ctl_table *
93109 sd_alloc_ctl_domain_table(struct sched_domain *sd)
93110 {
93111 - struct ctl_table *table = sd_alloc_ctl_entry(14);
93112 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
93113
93114 if (table == NULL)
93115 return NULL;
93116 @@ -5005,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
93117 return table;
93118 }
93119
93120 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
93121 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
93122 {
93123 - struct ctl_table *entry, *table;
93124 + ctl_table_no_const *entry, *table;
93125 struct sched_domain *sd;
93126 int domain_num = 0, i;
93127 char buf[32];
93128 @@ -5034,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
93129 static void register_sched_domain_sysctl(void)
93130 {
93131 int i, cpu_num = num_possible_cpus();
93132 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
93133 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
93134 char buf[32];
93135
93136 WARN_ON(sd_ctl_dir[0].child);
93137 + pax_open_kernel();
93138 sd_ctl_dir[0].child = entry;
93139 + pax_close_kernel();
93140
93141 if (entry == NULL)
93142 return;
93143 @@ -5061,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
93144 if (sd_sysctl_header)
93145 unregister_sysctl_table(sd_sysctl_header);
93146 sd_sysctl_header = NULL;
93147 - if (sd_ctl_dir[0].child)
93148 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
93149 + if (sd_ctl_dir[0].child) {
93150 + sd_free_ctl_entry(sd_ctl_dir[0].child);
93151 + pax_open_kernel();
93152 + sd_ctl_dir[0].child = NULL;
93153 + pax_close_kernel();
93154 + }
93155 }
93156 #else
93157 static void register_sched_domain_sysctl(void)
93158 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
93159 index bfa3c86..e58767c 100644
93160 --- a/kernel/sched/fair.c
93161 +++ b/kernel/sched/fair.c
93162 @@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
93163
93164 static void reset_ptenuma_scan(struct task_struct *p)
93165 {
93166 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
93167 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
93168 p->mm->numa_scan_offset = 0;
93169 }
93170
93171 @@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
93172 * run_rebalance_domains is triggered when needed from the scheduler tick.
93173 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
93174 */
93175 -static void run_rebalance_domains(struct softirq_action *h)
93176 +static __latent_entropy void run_rebalance_domains(void)
93177 {
93178 struct rq *this_rq = this_rq();
93179 enum cpu_idle_type idle = this_rq->idle_balance ?
93180 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
93181 index 579712f..a338a9d 100644
93182 --- a/kernel/sched/sched.h
93183 +++ b/kernel/sched/sched.h
93184 @@ -1146,7 +1146,7 @@ struct sched_class {
93185 #ifdef CONFIG_FAIR_GROUP_SCHED
93186 void (*task_move_group) (struct task_struct *p, int on_rq);
93187 #endif
93188 -};
93189 +} __do_const;
93190
93191 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
93192 {
93193 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
93194 index 44eb005..84922be 100644
93195 --- a/kernel/seccomp.c
93196 +++ b/kernel/seccomp.c
93197 @@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93198 if (!filter)
93199 goto free_prog;
93200
93201 - filter->prog = kzalloc(bpf_prog_size(new_len),
93202 - GFP_KERNEL|__GFP_NOWARN);
93203 + filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
93204 if (!filter->prog)
93205 goto free_filter;
93206
93207 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
93208 if (ret)
93209 goto free_filter_prog;
93210 - kfree(fp);
93211
93212 + kfree(fp);
93213 atomic_set(&filter->usage, 1);
93214 filter->prog->len = new_len;
93215
93216 @@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93217 return filter;
93218
93219 free_filter_prog:
93220 - kfree(filter->prog);
93221 + __bpf_prog_free(filter->prog);
93222 free_filter:
93223 kfree(filter);
93224 free_prog:
93225 diff --git a/kernel/signal.c b/kernel/signal.c
93226 index 8f0876f..1153a5a 100644
93227 --- a/kernel/signal.c
93228 +++ b/kernel/signal.c
93229 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
93230
93231 int print_fatal_signals __read_mostly;
93232
93233 -static void __user *sig_handler(struct task_struct *t, int sig)
93234 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
93235 {
93236 return t->sighand->action[sig - 1].sa.sa_handler;
93237 }
93238
93239 -static int sig_handler_ignored(void __user *handler, int sig)
93240 +static int sig_handler_ignored(__sighandler_t handler, int sig)
93241 {
93242 /* Is it explicitly or implicitly ignored? */
93243 return handler == SIG_IGN ||
93244 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
93245
93246 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
93247 {
93248 - void __user *handler;
93249 + __sighandler_t handler;
93250
93251 handler = sig_handler(t, sig);
93252
93253 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
93254 atomic_inc(&user->sigpending);
93255 rcu_read_unlock();
93256
93257 + if (!override_rlimit)
93258 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
93259 +
93260 if (override_rlimit ||
93261 atomic_read(&user->sigpending) <=
93262 task_rlimit(t, RLIMIT_SIGPENDING)) {
93263 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
93264
93265 int unhandled_signal(struct task_struct *tsk, int sig)
93266 {
93267 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
93268 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
93269 if (is_global_init(tsk))
93270 return 1;
93271 if (handler != SIG_IGN && handler != SIG_DFL)
93272 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
93273 }
93274 }
93275
93276 + /* allow glibc communication via tgkill to other threads in our
93277 + thread group */
93278 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93279 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93280 + && gr_handle_signal(t, sig))
93281 + return -EPERM;
93282 +
93283 return security_task_kill(t, info, sig, 0);
93284 }
93285
93286 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93287 return send_signal(sig, info, p, 1);
93288 }
93289
93290 -static int
93291 +int
93292 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93293 {
93294 return send_signal(sig, info, t, 0);
93295 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93296 unsigned long int flags;
93297 int ret, blocked, ignored;
93298 struct k_sigaction *action;
93299 + int is_unhandled = 0;
93300
93301 spin_lock_irqsave(&t->sighand->siglock, flags);
93302 action = &t->sighand->action[sig-1];
93303 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93304 }
93305 if (action->sa.sa_handler == SIG_DFL)
93306 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93307 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93308 + is_unhandled = 1;
93309 ret = specific_send_sig_info(sig, info, t);
93310 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93311
93312 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93313 + normal operation */
93314 + if (is_unhandled) {
93315 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93316 + gr_handle_crash(t, sig);
93317 + }
93318 +
93319 return ret;
93320 }
93321
93322 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93323 ret = check_kill_permission(sig, info, p);
93324 rcu_read_unlock();
93325
93326 - if (!ret && sig)
93327 + if (!ret && sig) {
93328 ret = do_send_sig_info(sig, info, p, true);
93329 + if (!ret)
93330 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93331 + }
93332
93333 return ret;
93334 }
93335 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93336 int error = -ESRCH;
93337
93338 rcu_read_lock();
93339 - p = find_task_by_vpid(pid);
93340 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93341 + /* allow glibc communication via tgkill to other threads in our
93342 + thread group */
93343 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93344 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93345 + p = find_task_by_vpid_unrestricted(pid);
93346 + else
93347 +#endif
93348 + p = find_task_by_vpid(pid);
93349 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93350 error = check_kill_permission(sig, info, p);
93351 /*
93352 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93353 }
93354 seg = get_fs();
93355 set_fs(KERNEL_DS);
93356 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93357 - (stack_t __force __user *) &uoss,
93358 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93359 + (stack_t __force_user *) &uoss,
93360 compat_user_stack_pointer());
93361 set_fs(seg);
93362 if (ret >= 0 && uoss_ptr) {
93363 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93364 index eb89e18..a4e6792 100644
93365 --- a/kernel/smpboot.c
93366 +++ b/kernel/smpboot.c
93367 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93368 }
93369 smpboot_unpark_thread(plug_thread, cpu);
93370 }
93371 - list_add(&plug_thread->list, &hotplug_threads);
93372 + pax_list_add(&plug_thread->list, &hotplug_threads);
93373 out:
93374 mutex_unlock(&smpboot_threads_lock);
93375 return ret;
93376 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93377 {
93378 get_online_cpus();
93379 mutex_lock(&smpboot_threads_lock);
93380 - list_del(&plug_thread->list);
93381 + pax_list_del(&plug_thread->list);
93382 smpboot_destroy_threads(plug_thread);
93383 mutex_unlock(&smpboot_threads_lock);
93384 put_online_cpus();
93385 diff --git a/kernel/softirq.c b/kernel/softirq.c
93386 index 5918d22..e95d1926 100644
93387 --- a/kernel/softirq.c
93388 +++ b/kernel/softirq.c
93389 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93390 EXPORT_SYMBOL(irq_stat);
93391 #endif
93392
93393 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93394 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93395
93396 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93397
93398 @@ -266,7 +266,7 @@ restart:
93399 kstat_incr_softirqs_this_cpu(vec_nr);
93400
93401 trace_softirq_entry(vec_nr);
93402 - h->action(h);
93403 + h->action();
93404 trace_softirq_exit(vec_nr);
93405 if (unlikely(prev_count != preempt_count())) {
93406 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93407 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93408 or_softirq_pending(1UL << nr);
93409 }
93410
93411 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93412 +void __init open_softirq(int nr, void (*action)(void))
93413 {
93414 softirq_vec[nr].action = action;
93415 }
93416 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93417 }
93418 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93419
93420 -static void tasklet_action(struct softirq_action *a)
93421 +static void tasklet_action(void)
93422 {
93423 struct tasklet_struct *list;
93424
93425 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93426 }
93427 }
93428
93429 -static void tasklet_hi_action(struct softirq_action *a)
93430 +static __latent_entropy void tasklet_hi_action(void)
93431 {
93432 struct tasklet_struct *list;
93433
93434 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93435 .notifier_call = cpu_callback
93436 };
93437
93438 -static struct smp_hotplug_thread softirq_threads = {
93439 +static struct smp_hotplug_thread softirq_threads __read_only = {
93440 .store = &ksoftirqd,
93441 .thread_should_run = ksoftirqd_should_run,
93442 .thread_fn = run_ksoftirqd,
93443 diff --git a/kernel/sys.c b/kernel/sys.c
93444 index ce81291..df2ca85 100644
93445 --- a/kernel/sys.c
93446 +++ b/kernel/sys.c
93447 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93448 error = -EACCES;
93449 goto out;
93450 }
93451 +
93452 + if (gr_handle_chroot_setpriority(p, niceval)) {
93453 + error = -EACCES;
93454 + goto out;
93455 + }
93456 +
93457 no_nice = security_task_setnice(p, niceval);
93458 if (no_nice) {
93459 error = no_nice;
93460 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93461 goto error;
93462 }
93463
93464 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93465 + goto error;
93466 +
93467 + if (!gid_eq(new->gid, old->gid)) {
93468 + /* make sure we generate a learn log for what will
93469 + end up being a role transition after a full-learning
93470 + policy is generated
93471 + CAP_SETGID is required to perform a transition
93472 + we may not log a CAP_SETGID check above, e.g.
93473 + in the case where new rgid = old egid
93474 + */
93475 + gr_learn_cap(current, new, CAP_SETGID);
93476 + }
93477 +
93478 if (rgid != (gid_t) -1 ||
93479 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93480 new->sgid = new->egid;
93481 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93482 old = current_cred();
93483
93484 retval = -EPERM;
93485 +
93486 + if (gr_check_group_change(kgid, kgid, kgid))
93487 + goto error;
93488 +
93489 if (ns_capable(old->user_ns, CAP_SETGID))
93490 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93491 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93492 @@ -403,7 +427,7 @@ error:
93493 /*
93494 * change the user struct in a credentials set to match the new UID
93495 */
93496 -static int set_user(struct cred *new)
93497 +int set_user(struct cred *new)
93498 {
93499 struct user_struct *new_user;
93500
93501 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93502 goto error;
93503 }
93504
93505 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93506 + goto error;
93507 +
93508 if (!uid_eq(new->uid, old->uid)) {
93509 + /* make sure we generate a learn log for what will
93510 + end up being a role transition after a full-learning
93511 + policy is generated
93512 + CAP_SETUID is required to perform a transition
93513 + we may not log a CAP_SETUID check above, e.g.
93514 + in the case where new ruid = old euid
93515 + */
93516 + gr_learn_cap(current, new, CAP_SETUID);
93517 retval = set_user(new);
93518 if (retval < 0)
93519 goto error;
93520 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93521 old = current_cred();
93522
93523 retval = -EPERM;
93524 +
93525 + if (gr_check_crash_uid(kuid))
93526 + goto error;
93527 + if (gr_check_user_change(kuid, kuid, kuid))
93528 + goto error;
93529 +
93530 if (ns_capable(old->user_ns, CAP_SETUID)) {
93531 new->suid = new->uid = kuid;
93532 if (!uid_eq(kuid, old->uid)) {
93533 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93534 goto error;
93535 }
93536
93537 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93538 + goto error;
93539 +
93540 if (ruid != (uid_t) -1) {
93541 new->uid = kruid;
93542 if (!uid_eq(kruid, old->uid)) {
93543 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93544 goto error;
93545 }
93546
93547 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93548 + goto error;
93549 +
93550 if (rgid != (gid_t) -1)
93551 new->gid = krgid;
93552 if (egid != (gid_t) -1)
93553 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93554 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93555 ns_capable(old->user_ns, CAP_SETUID)) {
93556 if (!uid_eq(kuid, old->fsuid)) {
93557 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93558 + goto error;
93559 +
93560 new->fsuid = kuid;
93561 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93562 goto change_okay;
93563 }
93564 }
93565
93566 +error:
93567 abort_creds(new);
93568 return old_fsuid;
93569
93570 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93571 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93572 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93573 ns_capable(old->user_ns, CAP_SETGID)) {
93574 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93575 + goto error;
93576 +
93577 if (!gid_eq(kgid, old->fsgid)) {
93578 new->fsgid = kgid;
93579 goto change_okay;
93580 }
93581 }
93582
93583 +error:
93584 abort_creds(new);
93585 return old_fsgid;
93586
93587 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93588 return -EFAULT;
93589
93590 down_read(&uts_sem);
93591 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93592 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93593 __OLD_UTS_LEN);
93594 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93595 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93596 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93597 __OLD_UTS_LEN);
93598 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93599 - error |= __copy_to_user(&name->release, &utsname()->release,
93600 + error |= __copy_to_user(name->release, &utsname()->release,
93601 __OLD_UTS_LEN);
93602 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93603 - error |= __copy_to_user(&name->version, &utsname()->version,
93604 + error |= __copy_to_user(name->version, &utsname()->version,
93605 __OLD_UTS_LEN);
93606 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93607 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93608 + error |= __copy_to_user(name->machine, &utsname()->machine,
93609 __OLD_UTS_LEN);
93610 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93611 up_read(&uts_sem);
93612 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93613 */
93614 new_rlim->rlim_cur = 1;
93615 }
93616 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93617 + is changed to a lower value. Since tasks can be created by the same
93618 + user in between this limit change and an execve by this task, force
93619 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93620 + */
93621 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93622 + tsk->flags |= PF_NPROC_EXCEEDED;
93623 }
93624 if (!retval) {
93625 if (old_rlim)
93626 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93627 index 75875a7..cd8e838 100644
93628 --- a/kernel/sysctl.c
93629 +++ b/kernel/sysctl.c
93630 @@ -94,7 +94,6 @@
93631
93632
93633 #if defined(CONFIG_SYSCTL)
93634 -
93635 /* External variables not in a header file. */
93636 extern int max_threads;
93637 extern int suid_dumpable;
93638 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93639
93640 /* Constants used for minimum and maximum */
93641 #ifdef CONFIG_LOCKUP_DETECTOR
93642 -static int sixty = 60;
93643 +static int sixty __read_only = 60;
93644 #endif
93645
93646 -static int __maybe_unused neg_one = -1;
93647 +static int __maybe_unused neg_one __read_only = -1;
93648
93649 -static int zero;
93650 -static int __maybe_unused one = 1;
93651 -static int __maybe_unused two = 2;
93652 -static int __maybe_unused four = 4;
93653 -static unsigned long one_ul = 1;
93654 -static int one_hundred = 100;
93655 +static int zero __read_only = 0;
93656 +static int __maybe_unused one __read_only = 1;
93657 +static int __maybe_unused two __read_only = 2;
93658 +static int __maybe_unused three __read_only = 3;
93659 +static int __maybe_unused four __read_only = 4;
93660 +static unsigned long one_ul __read_only = 1;
93661 +static int one_hundred __read_only = 100;
93662 #ifdef CONFIG_PRINTK
93663 -static int ten_thousand = 10000;
93664 +static int ten_thousand __read_only = 10000;
93665 #endif
93666
93667 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93668 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93669 void __user *buffer, size_t *lenp, loff_t *ppos);
93670 #endif
93671
93672 -#ifdef CONFIG_PRINTK
93673 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93674 void __user *buffer, size_t *lenp, loff_t *ppos);
93675 -#endif
93676
93677 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93678 void __user *buffer, size_t *lenp, loff_t *ppos);
93679 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93680
93681 #endif
93682
93683 +extern struct ctl_table grsecurity_table[];
93684 +
93685 static struct ctl_table kern_table[];
93686 static struct ctl_table vm_table[];
93687 static struct ctl_table fs_table[];
93688 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93689 int sysctl_legacy_va_layout;
93690 #endif
93691
93692 +#ifdef CONFIG_PAX_SOFTMODE
93693 +static struct ctl_table pax_table[] = {
93694 + {
93695 + .procname = "softmode",
93696 + .data = &pax_softmode,
93697 + .maxlen = sizeof(unsigned int),
93698 + .mode = 0600,
93699 + .proc_handler = &proc_dointvec,
93700 + },
93701 +
93702 + { }
93703 +};
93704 +#endif
93705 +
93706 /* The default sysctl tables: */
93707
93708 static struct ctl_table sysctl_base_table[] = {
93709 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93710 #endif
93711
93712 static struct ctl_table kern_table[] = {
93713 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93714 + {
93715 + .procname = "grsecurity",
93716 + .mode = 0500,
93717 + .child = grsecurity_table,
93718 + },
93719 +#endif
93720 +
93721 +#ifdef CONFIG_PAX_SOFTMODE
93722 + {
93723 + .procname = "pax",
93724 + .mode = 0500,
93725 + .child = pax_table,
93726 + },
93727 +#endif
93728 +
93729 {
93730 .procname = "sched_child_runs_first",
93731 .data = &sysctl_sched_child_runs_first,
93732 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
93733 .data = &modprobe_path,
93734 .maxlen = KMOD_PATH_LEN,
93735 .mode = 0644,
93736 - .proc_handler = proc_dostring,
93737 + .proc_handler = proc_dostring_modpriv,
93738 },
93739 {
93740 .procname = "modules_disabled",
93741 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
93742 .extra1 = &zero,
93743 .extra2 = &one,
93744 },
93745 +#endif
93746 {
93747 .procname = "kptr_restrict",
93748 .data = &kptr_restrict,
93749 .maxlen = sizeof(int),
93750 .mode = 0644,
93751 .proc_handler = proc_dointvec_minmax_sysadmin,
93752 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93753 + .extra1 = &two,
93754 +#else
93755 .extra1 = &zero,
93756 +#endif
93757 .extra2 = &two,
93758 },
93759 -#endif
93760 {
93761 .procname = "ngroups_max",
93762 .data = &ngroups_max,
93763 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
93764 */
93765 {
93766 .procname = "perf_event_paranoid",
93767 - .data = &sysctl_perf_event_paranoid,
93768 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93769 + .data = &sysctl_perf_event_legitimately_concerned,
93770 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93771 .mode = 0644,
93772 - .proc_handler = proc_dointvec,
93773 + /* go ahead, be a hero */
93774 + .proc_handler = proc_dointvec_minmax_sysadmin,
93775 + .extra1 = &neg_one,
93776 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93777 + .extra2 = &three,
93778 +#else
93779 + .extra2 = &two,
93780 +#endif
93781 },
93782 {
93783 .procname = "perf_event_mlock_kb",
93784 @@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
93785 .proc_handler = proc_dointvec_minmax,
93786 .extra1 = &zero,
93787 },
93788 + {
93789 + .procname = "heap_stack_gap",
93790 + .data = &sysctl_heap_stack_gap,
93791 + .maxlen = sizeof(sysctl_heap_stack_gap),
93792 + .mode = 0644,
93793 + .proc_handler = proc_doulongvec_minmax,
93794 + },
93795 #else
93796 {
93797 .procname = "nr_trim_pages",
93798 @@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
93799 (char __user *)buffer, lenp, ppos);
93800 }
93801
93802 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93803 + void __user *buffer, size_t *lenp, loff_t *ppos)
93804 +{
93805 + if (write && !capable(CAP_SYS_MODULE))
93806 + return -EPERM;
93807 +
93808 + return _proc_do_string(table->data, table->maxlen, write,
93809 + buffer, lenp, ppos);
93810 +}
93811 +
93812 static size_t proc_skip_spaces(char **buf)
93813 {
93814 size_t ret;
93815 @@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93816 len = strlen(tmp);
93817 if (len > *size)
93818 len = *size;
93819 + if (len > sizeof(tmp))
93820 + len = sizeof(tmp);
93821 if (copy_to_user(*buf, tmp, len))
93822 return -EFAULT;
93823 *size -= len;
93824 @@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93825 static int proc_taint(struct ctl_table *table, int write,
93826 void __user *buffer, size_t *lenp, loff_t *ppos)
93827 {
93828 - struct ctl_table t;
93829 + ctl_table_no_const t;
93830 unsigned long tmptaint = get_taint();
93831 int err;
93832
93833 @@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
93834 return err;
93835 }
93836
93837 -#ifdef CONFIG_PRINTK
93838 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93839 void __user *buffer, size_t *lenp, loff_t *ppos)
93840 {
93841 @@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93842
93843 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93844 }
93845 -#endif
93846
93847 struct do_proc_dointvec_minmax_conv_param {
93848 int *min;
93849 @@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
93850 return -ENOSYS;
93851 }
93852
93853 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93854 + void __user *buffer, size_t *lenp, loff_t *ppos)
93855 +{
93856 + return -ENOSYS;
93857 +}
93858 +
93859 int proc_dointvec(struct ctl_table *table, int write,
93860 void __user *buffer, size_t *lenp, loff_t *ppos)
93861 {
93862 @@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93863 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93864 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93865 EXPORT_SYMBOL(proc_dostring);
93866 +EXPORT_SYMBOL(proc_dostring_modpriv);
93867 EXPORT_SYMBOL(proc_doulongvec_minmax);
93868 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93869 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93870 index 13d2f7c..c93d0b0 100644
93871 --- a/kernel/taskstats.c
93872 +++ b/kernel/taskstats.c
93873 @@ -28,9 +28,12 @@
93874 #include <linux/fs.h>
93875 #include <linux/file.h>
93876 #include <linux/pid_namespace.h>
93877 +#include <linux/grsecurity.h>
93878 #include <net/genetlink.h>
93879 #include <linux/atomic.h>
93880
93881 +extern int gr_is_taskstats_denied(int pid);
93882 +
93883 /*
93884 * Maximum length of a cpumask that can be specified in
93885 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93886 @@ -576,6 +579,9 @@ err:
93887
93888 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93889 {
93890 + if (gr_is_taskstats_denied(current->pid))
93891 + return -EACCES;
93892 +
93893 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93894 return cmd_attr_register_cpumask(info);
93895 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93896 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93897 index a7077d3..dd48a49 100644
93898 --- a/kernel/time/alarmtimer.c
93899 +++ b/kernel/time/alarmtimer.c
93900 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93901 struct platform_device *pdev;
93902 int error = 0;
93903 int i;
93904 - struct k_clock alarm_clock = {
93905 + static struct k_clock alarm_clock = {
93906 .clock_getres = alarm_clock_getres,
93907 .clock_get = alarm_clock_get,
93908 .timer_create = alarm_timer_create,
93909 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93910 index 1c2fe7d..ce7483d 100644
93911 --- a/kernel/time/hrtimer.c
93912 +++ b/kernel/time/hrtimer.c
93913 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93914 local_irq_restore(flags);
93915 }
93916
93917 -static void run_hrtimer_softirq(struct softirq_action *h)
93918 +static __latent_entropy void run_hrtimer_softirq(void)
93919 {
93920 hrtimer_peek_ahead_timers();
93921 }
93922 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93923 index 3b89464..5e38379 100644
93924 --- a/kernel/time/posix-cpu-timers.c
93925 +++ b/kernel/time/posix-cpu-timers.c
93926 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93927
93928 static __init int init_posix_cpu_timers(void)
93929 {
93930 - struct k_clock process = {
93931 + static struct k_clock process = {
93932 .clock_getres = process_cpu_clock_getres,
93933 .clock_get = process_cpu_clock_get,
93934 .timer_create = process_cpu_timer_create,
93935 .nsleep = process_cpu_nsleep,
93936 .nsleep_restart = process_cpu_nsleep_restart,
93937 };
93938 - struct k_clock thread = {
93939 + static struct k_clock thread = {
93940 .clock_getres = thread_cpu_clock_getres,
93941 .clock_get = thread_cpu_clock_get,
93942 .timer_create = thread_cpu_timer_create,
93943 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93944 index 31ea01f..7fc61ef 100644
93945 --- a/kernel/time/posix-timers.c
93946 +++ b/kernel/time/posix-timers.c
93947 @@ -43,6 +43,7 @@
93948 #include <linux/hash.h>
93949 #include <linux/posix-clock.h>
93950 #include <linux/posix-timers.h>
93951 +#include <linux/grsecurity.h>
93952 #include <linux/syscalls.h>
93953 #include <linux/wait.h>
93954 #include <linux/workqueue.h>
93955 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93956 * which we beg off on and pass to do_sys_settimeofday().
93957 */
93958
93959 -static struct k_clock posix_clocks[MAX_CLOCKS];
93960 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93961
93962 /*
93963 * These ones are defined below.
93964 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93965 */
93966 static __init int init_posix_timers(void)
93967 {
93968 - struct k_clock clock_realtime = {
93969 + static struct k_clock clock_realtime = {
93970 .clock_getres = hrtimer_get_res,
93971 .clock_get = posix_clock_realtime_get,
93972 .clock_set = posix_clock_realtime_set,
93973 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93974 .timer_get = common_timer_get,
93975 .timer_del = common_timer_del,
93976 };
93977 - struct k_clock clock_monotonic = {
93978 + static struct k_clock clock_monotonic = {
93979 .clock_getres = hrtimer_get_res,
93980 .clock_get = posix_ktime_get_ts,
93981 .nsleep = common_nsleep,
93982 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93983 .timer_get = common_timer_get,
93984 .timer_del = common_timer_del,
93985 };
93986 - struct k_clock clock_monotonic_raw = {
93987 + static struct k_clock clock_monotonic_raw = {
93988 .clock_getres = hrtimer_get_res,
93989 .clock_get = posix_get_monotonic_raw,
93990 };
93991 - struct k_clock clock_realtime_coarse = {
93992 + static struct k_clock clock_realtime_coarse = {
93993 .clock_getres = posix_get_coarse_res,
93994 .clock_get = posix_get_realtime_coarse,
93995 };
93996 - struct k_clock clock_monotonic_coarse = {
93997 + static struct k_clock clock_monotonic_coarse = {
93998 .clock_getres = posix_get_coarse_res,
93999 .clock_get = posix_get_monotonic_coarse,
94000 };
94001 - struct k_clock clock_tai = {
94002 + static struct k_clock clock_tai = {
94003 .clock_getres = hrtimer_get_res,
94004 .clock_get = posix_get_tai,
94005 .nsleep = common_nsleep,
94006 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
94007 .timer_get = common_timer_get,
94008 .timer_del = common_timer_del,
94009 };
94010 - struct k_clock clock_boottime = {
94011 + static struct k_clock clock_boottime = {
94012 .clock_getres = hrtimer_get_res,
94013 .clock_get = posix_get_boottime,
94014 .nsleep = common_nsleep,
94015 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
94016 return;
94017 }
94018
94019 - posix_clocks[clock_id] = *new_clock;
94020 + posix_clocks[clock_id] = new_clock;
94021 }
94022 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
94023
94024 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
94025 return (id & CLOCKFD_MASK) == CLOCKFD ?
94026 &clock_posix_dynamic : &clock_posix_cpu;
94027
94028 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
94029 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
94030 return NULL;
94031 - return &posix_clocks[id];
94032 + return posix_clocks[id];
94033 }
94034
94035 static int common_timer_create(struct k_itimer *new_timer)
94036 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
94037 struct k_clock *kc = clockid_to_kclock(which_clock);
94038 struct k_itimer *new_timer;
94039 int error, new_timer_id;
94040 - sigevent_t event;
94041 + sigevent_t event = { };
94042 int it_id_set = IT_ID_NOT_SET;
94043
94044 if (!kc)
94045 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
94046 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
94047 return -EFAULT;
94048
94049 + /* only the CLOCK_REALTIME clock can be set, all other clocks
94050 + have their clock_set fptr set to a nosettime dummy function
94051 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
94052 + call common_clock_set, which calls do_sys_settimeofday, which
94053 + we hook
94054 + */
94055 +
94056 return kc->clock_set(which_clock, &new_tp);
94057 }
94058
94059 diff --git a/kernel/time/time.c b/kernel/time/time.c
94060 index a9ae20f..d3fbde7 100644
94061 --- a/kernel/time/time.c
94062 +++ b/kernel/time/time.c
94063 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
94064 return error;
94065
94066 if (tz) {
94067 + /* we log in do_settimeofday called below, so don't log twice
94068 + */
94069 + if (!tv)
94070 + gr_log_timechange();
94071 +
94072 sys_tz = *tz;
94073 update_vsyscall_tz();
94074 if (firsttime) {
94075 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
94076 index ec1791f..6a086cd 100644
94077 --- a/kernel/time/timekeeping.c
94078 +++ b/kernel/time/timekeeping.c
94079 @@ -15,6 +15,7 @@
94080 #include <linux/init.h>
94081 #include <linux/mm.h>
94082 #include <linux/sched.h>
94083 +#include <linux/grsecurity.h>
94084 #include <linux/syscore_ops.h>
94085 #include <linux/clocksource.h>
94086 #include <linux/jiffies.h>
94087 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
94088 if (!timespec_valid_strict(tv))
94089 return -EINVAL;
94090
94091 + gr_log_timechange();
94092 +
94093 raw_spin_lock_irqsave(&timekeeper_lock, flags);
94094 write_seqcount_begin(&tk_core.seq);
94095
94096 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
94097 index 9bbb834..3caa8ed 100644
94098 --- a/kernel/time/timer.c
94099 +++ b/kernel/time/timer.c
94100 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
94101 /*
94102 * This function runs timers and the timer-tq in bottom half context.
94103 */
94104 -static void run_timer_softirq(struct softirq_action *h)
94105 +static __latent_entropy void run_timer_softirq(void)
94106 {
94107 struct tvec_base *base = __this_cpu_read(tvec_bases);
94108
94109 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
94110 *
94111 * In all cases the return value is guaranteed to be non-negative.
94112 */
94113 -signed long __sched schedule_timeout(signed long timeout)
94114 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
94115 {
94116 struct timer_list timer;
94117 unsigned long expire;
94118 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
94119 index 61ed862..3b52c65 100644
94120 --- a/kernel/time/timer_list.c
94121 +++ b/kernel/time/timer_list.c
94122 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
94123
94124 static void print_name_offset(struct seq_file *m, void *sym)
94125 {
94126 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94127 + SEQ_printf(m, "<%p>", NULL);
94128 +#else
94129 char symname[KSYM_NAME_LEN];
94130
94131 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
94132 SEQ_printf(m, "<%pK>", sym);
94133 else
94134 SEQ_printf(m, "%s", symname);
94135 +#endif
94136 }
94137
94138 static void
94139 @@ -119,7 +123,11 @@ next_one:
94140 static void
94141 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
94142 {
94143 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94144 + SEQ_printf(m, " .base: %p\n", NULL);
94145 +#else
94146 SEQ_printf(m, " .base: %pK\n", base);
94147 +#endif
94148 SEQ_printf(m, " .index: %d\n",
94149 base->index);
94150 SEQ_printf(m, " .resolution: %Lu nsecs\n",
94151 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
94152 {
94153 struct proc_dir_entry *pe;
94154
94155 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94156 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
94157 +#else
94158 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
94159 +#endif
94160 if (!pe)
94161 return -ENOMEM;
94162 return 0;
94163 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
94164 index 1fb08f2..ca4bb1e 100644
94165 --- a/kernel/time/timer_stats.c
94166 +++ b/kernel/time/timer_stats.c
94167 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
94168 static unsigned long nr_entries;
94169 static struct entry entries[MAX_ENTRIES];
94170
94171 -static atomic_t overflow_count;
94172 +static atomic_unchecked_t overflow_count;
94173
94174 /*
94175 * The entries are in a hash-table, for fast lookup:
94176 @@ -140,7 +140,7 @@ static void reset_entries(void)
94177 nr_entries = 0;
94178 memset(entries, 0, sizeof(entries));
94179 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
94180 - atomic_set(&overflow_count, 0);
94181 + atomic_set_unchecked(&overflow_count, 0);
94182 }
94183
94184 static struct entry *alloc_entry(void)
94185 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94186 if (likely(entry))
94187 entry->count++;
94188 else
94189 - atomic_inc(&overflow_count);
94190 + atomic_inc_unchecked(&overflow_count);
94191
94192 out_unlock:
94193 raw_spin_unlock_irqrestore(lock, flags);
94194 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94195
94196 static void print_name_offset(struct seq_file *m, unsigned long addr)
94197 {
94198 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94199 + seq_printf(m, "<%p>", NULL);
94200 +#else
94201 char symname[KSYM_NAME_LEN];
94202
94203 if (lookup_symbol_name(addr, symname) < 0)
94204 - seq_printf(m, "<%p>", (void *)addr);
94205 + seq_printf(m, "<%pK>", (void *)addr);
94206 else
94207 seq_printf(m, "%s", symname);
94208 +#endif
94209 }
94210
94211 static int tstats_show(struct seq_file *m, void *v)
94212 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
94213
94214 seq_puts(m, "Timer Stats Version: v0.3\n");
94215 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
94216 - if (atomic_read(&overflow_count))
94217 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
94218 + if (atomic_read_unchecked(&overflow_count))
94219 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
94220 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
94221
94222 for (i = 0; i < nr_entries; i++) {
94223 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
94224 {
94225 struct proc_dir_entry *pe;
94226
94227 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94228 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
94229 +#else
94230 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
94231 +#endif
94232 if (!pe)
94233 return -ENOMEM;
94234 return 0;
94235 diff --git a/kernel/torture.c b/kernel/torture.c
94236 index d600af2..27a4e9d 100644
94237 --- a/kernel/torture.c
94238 +++ b/kernel/torture.c
94239 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
94240 mutex_lock(&fullstop_mutex);
94241 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
94242 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
94243 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
94244 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
94245 } else {
94246 pr_warn("Concurrent rmmod and shutdown illegal!\n");
94247 }
94248 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
94249 if (!torture_must_stop()) {
94250 if (stutter > 1) {
94251 schedule_timeout_interruptible(stutter - 1);
94252 - ACCESS_ONCE(stutter_pause_test) = 2;
94253 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
94254 }
94255 schedule_timeout_interruptible(1);
94256 - ACCESS_ONCE(stutter_pause_test) = 1;
94257 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
94258 }
94259 if (!torture_must_stop())
94260 schedule_timeout_interruptible(stutter);
94261 - ACCESS_ONCE(stutter_pause_test) = 0;
94262 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
94263 torture_shutdown_absorb("torture_stutter");
94264 } while (!torture_must_stop());
94265 torture_kthread_stopping("torture_stutter");
94266 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
94267 schedule_timeout_uninterruptible(10);
94268 return true;
94269 }
94270 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
94271 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
94272 mutex_unlock(&fullstop_mutex);
94273 torture_shutdown_cleanup();
94274 torture_shuffle_cleanup();
94275 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94276 index c1bd4ad..4b861dc 100644
94277 --- a/kernel/trace/blktrace.c
94278 +++ b/kernel/trace/blktrace.c
94279 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94280 struct blk_trace *bt = filp->private_data;
94281 char buf[16];
94282
94283 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94284 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94285
94286 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94287 }
94288 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94289 return 1;
94290
94291 bt = buf->chan->private_data;
94292 - atomic_inc(&bt->dropped);
94293 + atomic_inc_unchecked(&bt->dropped);
94294 return 0;
94295 }
94296
94297 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94298
94299 bt->dir = dir;
94300 bt->dev = dev;
94301 - atomic_set(&bt->dropped, 0);
94302 + atomic_set_unchecked(&bt->dropped, 0);
94303 INIT_LIST_HEAD(&bt->running_list);
94304
94305 ret = -EIO;
94306 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94307 index 5916a8e..220c9c2 100644
94308 --- a/kernel/trace/ftrace.c
94309 +++ b/kernel/trace/ftrace.c
94310 @@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94311 if (unlikely(ftrace_disabled))
94312 return 0;
94313
94314 + ret = ftrace_arch_code_modify_prepare();
94315 + FTRACE_WARN_ON(ret);
94316 + if (ret)
94317 + return 0;
94318 +
94319 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94320 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94321 if (ret) {
94322 ftrace_bug(ret, ip);
94323 - return 0;
94324 }
94325 - return 1;
94326 + return ret ? 0 : 1;
94327 }
94328
94329 /*
94330 @@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
94331 if (!count)
94332 return 0;
94333
94334 + pax_open_kernel();
94335 sort(start, count, sizeof(*start),
94336 ftrace_cmp_ips, ftrace_swap_ips);
94337 + pax_close_kernel();
94338
94339 start_pg = ftrace_allocate_pages(count);
94340 if (!start_pg)
94341 @@ -5254,7 +5261,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94342
94343 if (t->ret_stack == NULL) {
94344 atomic_set(&t->tracing_graph_pause, 0);
94345 - atomic_set(&t->trace_overrun, 0);
94346 + atomic_set_unchecked(&t->trace_overrun, 0);
94347 t->curr_ret_stack = -1;
94348 /* Make sure the tasks see the -1 first: */
94349 smp_wmb();
94350 @@ -5467,7 +5474,7 @@ static void
94351 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94352 {
94353 atomic_set(&t->tracing_graph_pause, 0);
94354 - atomic_set(&t->trace_overrun, 0);
94355 + atomic_set_unchecked(&t->trace_overrun, 0);
94356 t->ftrace_timestamp = 0;
94357 /* make curr_ret_stack visible before we add the ret_stack */
94358 smp_wmb();
94359 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94360 index a56e07c..d46f0ba 100644
94361 --- a/kernel/trace/ring_buffer.c
94362 +++ b/kernel/trace/ring_buffer.c
94363 @@ -352,9 +352,9 @@ struct buffer_data_page {
94364 */
94365 struct buffer_page {
94366 struct list_head list; /* list of buffer pages */
94367 - local_t write; /* index for next write */
94368 + local_unchecked_t write; /* index for next write */
94369 unsigned read; /* index for next read */
94370 - local_t entries; /* entries on this page */
94371 + local_unchecked_t entries; /* entries on this page */
94372 unsigned long real_end; /* real end of data */
94373 struct buffer_data_page *page; /* Actual data page */
94374 };
94375 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94376 unsigned long last_overrun;
94377 local_t entries_bytes;
94378 local_t entries;
94379 - local_t overrun;
94380 - local_t commit_overrun;
94381 + local_unchecked_t overrun;
94382 + local_unchecked_t commit_overrun;
94383 local_t dropped_events;
94384 local_t committing;
94385 local_t commits;
94386 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94387 *
94388 * We add a counter to the write field to denote this.
94389 */
94390 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94391 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94392 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94393 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94394
94395 /*
94396 * Just make sure we have seen our old_write and synchronize
94397 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94398 * cmpxchg to only update if an interrupt did not already
94399 * do it for us. If the cmpxchg fails, we don't care.
94400 */
94401 - (void)local_cmpxchg(&next_page->write, old_write, val);
94402 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94403 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94404 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94405
94406 /*
94407 * No need to worry about races with clearing out the commit.
94408 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94409
94410 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94411 {
94412 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94413 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94414 }
94415
94416 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94417 {
94418 - return local_read(&bpage->write) & RB_WRITE_MASK;
94419 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94420 }
94421
94422 static int
94423 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94424 * bytes consumed in ring buffer from here.
94425 * Increment overrun to account for the lost events.
94426 */
94427 - local_add(page_entries, &cpu_buffer->overrun);
94428 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94429 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94430 }
94431
94432 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94433 * it is our responsibility to update
94434 * the counters.
94435 */
94436 - local_add(entries, &cpu_buffer->overrun);
94437 + local_add_unchecked(entries, &cpu_buffer->overrun);
94438 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94439
94440 /*
94441 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94442 if (tail == BUF_PAGE_SIZE)
94443 tail_page->real_end = 0;
94444
94445 - local_sub(length, &tail_page->write);
94446 + local_sub_unchecked(length, &tail_page->write);
94447 return;
94448 }
94449
94450 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94451 rb_event_set_padding(event);
94452
94453 /* Set the write back to the previous setting */
94454 - local_sub(length, &tail_page->write);
94455 + local_sub_unchecked(length, &tail_page->write);
94456 return;
94457 }
94458
94459 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94460
94461 /* Set write to end of buffer */
94462 length = (tail + length) - BUF_PAGE_SIZE;
94463 - local_sub(length, &tail_page->write);
94464 + local_sub_unchecked(length, &tail_page->write);
94465 }
94466
94467 /*
94468 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94469 * about it.
94470 */
94471 if (unlikely(next_page == commit_page)) {
94472 - local_inc(&cpu_buffer->commit_overrun);
94473 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94474 goto out_reset;
94475 }
94476
94477 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94478 cpu_buffer->tail_page) &&
94479 (cpu_buffer->commit_page ==
94480 cpu_buffer->reader_page))) {
94481 - local_inc(&cpu_buffer->commit_overrun);
94482 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94483 goto out_reset;
94484 }
94485 }
94486 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94487 length += RB_LEN_TIME_EXTEND;
94488
94489 tail_page = cpu_buffer->tail_page;
94490 - write = local_add_return(length, &tail_page->write);
94491 + write = local_add_return_unchecked(length, &tail_page->write);
94492
94493 /* set write to only the index of the write */
94494 write &= RB_WRITE_MASK;
94495 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94496 kmemcheck_annotate_bitfield(event, bitfield);
94497 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94498
94499 - local_inc(&tail_page->entries);
94500 + local_inc_unchecked(&tail_page->entries);
94501
94502 /*
94503 * If this is the first commit on the page, then update
94504 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94505
94506 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94507 unsigned long write_mask =
94508 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94509 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94510 unsigned long event_length = rb_event_length(event);
94511 /*
94512 * This is on the tail page. It is possible that
94513 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94514 */
94515 old_index += write_mask;
94516 new_index += write_mask;
94517 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94518 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94519 if (index == old_index) {
94520 /* update counters */
94521 local_sub(event_length, &cpu_buffer->entries_bytes);
94522 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94523
94524 /* Do the likely case first */
94525 if (likely(bpage->page == (void *)addr)) {
94526 - local_dec(&bpage->entries);
94527 + local_dec_unchecked(&bpage->entries);
94528 return;
94529 }
94530
94531 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94532 start = bpage;
94533 do {
94534 if (bpage->page == (void *)addr) {
94535 - local_dec(&bpage->entries);
94536 + local_dec_unchecked(&bpage->entries);
94537 return;
94538 }
94539 rb_inc_page(cpu_buffer, &bpage);
94540 @@ -3173,7 +3173,7 @@ static inline unsigned long
94541 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94542 {
94543 return local_read(&cpu_buffer->entries) -
94544 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94545 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94546 }
94547
94548 /**
94549 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94550 return 0;
94551
94552 cpu_buffer = buffer->buffers[cpu];
94553 - ret = local_read(&cpu_buffer->overrun);
94554 + ret = local_read_unchecked(&cpu_buffer->overrun);
94555
94556 return ret;
94557 }
94558 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94559 return 0;
94560
94561 cpu_buffer = buffer->buffers[cpu];
94562 - ret = local_read(&cpu_buffer->commit_overrun);
94563 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94564
94565 return ret;
94566 }
94567 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94568 /* if you care about this being correct, lock the buffer */
94569 for_each_buffer_cpu(buffer, cpu) {
94570 cpu_buffer = buffer->buffers[cpu];
94571 - overruns += local_read(&cpu_buffer->overrun);
94572 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94573 }
94574
94575 return overruns;
94576 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94577 /*
94578 * Reset the reader page to size zero.
94579 */
94580 - local_set(&cpu_buffer->reader_page->write, 0);
94581 - local_set(&cpu_buffer->reader_page->entries, 0);
94582 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94583 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94584 local_set(&cpu_buffer->reader_page->page->commit, 0);
94585 cpu_buffer->reader_page->real_end = 0;
94586
94587 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94588 * want to compare with the last_overrun.
94589 */
94590 smp_mb();
94591 - overwrite = local_read(&(cpu_buffer->overrun));
94592 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94593
94594 /*
94595 * Here's the tricky part.
94596 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94597
94598 cpu_buffer->head_page
94599 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94600 - local_set(&cpu_buffer->head_page->write, 0);
94601 - local_set(&cpu_buffer->head_page->entries, 0);
94602 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94603 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94604 local_set(&cpu_buffer->head_page->page->commit, 0);
94605
94606 cpu_buffer->head_page->read = 0;
94607 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94608
94609 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94610 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94611 - local_set(&cpu_buffer->reader_page->write, 0);
94612 - local_set(&cpu_buffer->reader_page->entries, 0);
94613 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94614 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94615 local_set(&cpu_buffer->reader_page->page->commit, 0);
94616 cpu_buffer->reader_page->read = 0;
94617
94618 local_set(&cpu_buffer->entries_bytes, 0);
94619 - local_set(&cpu_buffer->overrun, 0);
94620 - local_set(&cpu_buffer->commit_overrun, 0);
94621 + local_set_unchecked(&cpu_buffer->overrun, 0);
94622 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94623 local_set(&cpu_buffer->dropped_events, 0);
94624 local_set(&cpu_buffer->entries, 0);
94625 local_set(&cpu_buffer->committing, 0);
94626 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94627 rb_init_page(bpage);
94628 bpage = reader->page;
94629 reader->page = *data_page;
94630 - local_set(&reader->write, 0);
94631 - local_set(&reader->entries, 0);
94632 + local_set_unchecked(&reader->write, 0);
94633 + local_set_unchecked(&reader->entries, 0);
94634 reader->read = 0;
94635 *data_page = bpage;
94636
94637 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94638 index 1520933..c651ebc 100644
94639 --- a/kernel/trace/trace.c
94640 +++ b/kernel/trace/trace.c
94641 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94642 return 0;
94643 }
94644
94645 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94646 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94647 {
94648 /* do nothing if flag is already set */
94649 if (!!(trace_flags & mask) == !!enabled)
94650 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94651 index 385391f..8d2250f 100644
94652 --- a/kernel/trace/trace.h
94653 +++ b/kernel/trace/trace.h
94654 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94655 void trace_printk_init_buffers(void);
94656 void trace_printk_start_comm(void);
94657 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94658 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94659 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94660
94661 /*
94662 * Normal trace_printk() and friends allocates special buffers
94663 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94664 index 57b67b1..66082a9 100644
94665 --- a/kernel/trace/trace_clock.c
94666 +++ b/kernel/trace/trace_clock.c
94667 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94668 return now;
94669 }
94670
94671 -static atomic64_t trace_counter;
94672 +static atomic64_unchecked_t trace_counter;
94673
94674 /*
94675 * trace_clock_counter(): simply an atomic counter.
94676 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94677 */
94678 u64 notrace trace_clock_counter(void)
94679 {
94680 - return atomic64_add_return(1, &trace_counter);
94681 + return atomic64_inc_return_unchecked(&trace_counter);
94682 }
94683 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94684 index ef06ce7..3ea161d 100644
94685 --- a/kernel/trace/trace_events.c
94686 +++ b/kernel/trace/trace_events.c
94687 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94688 return 0;
94689 }
94690
94691 -struct ftrace_module_file_ops;
94692 static void __add_event_to_tracers(struct ftrace_event_call *call);
94693
94694 /* Add an additional event_call dynamically */
94695 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94696 index f0a0c98..3692dc8 100644
94697 --- a/kernel/trace/trace_functions_graph.c
94698 +++ b/kernel/trace/trace_functions_graph.c
94699 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94700
94701 /* The return trace stack is full */
94702 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94703 - atomic_inc(&current->trace_overrun);
94704 + atomic_inc_unchecked(&current->trace_overrun);
94705 return -EBUSY;
94706 }
94707
94708 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94709 *ret = current->ret_stack[index].ret;
94710 trace->func = current->ret_stack[index].func;
94711 trace->calltime = current->ret_stack[index].calltime;
94712 - trace->overrun = atomic_read(&current->trace_overrun);
94713 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94714 trace->depth = index;
94715 }
94716
94717 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94718 index 0abd9b8..6a663a2 100644
94719 --- a/kernel/trace/trace_mmiotrace.c
94720 +++ b/kernel/trace/trace_mmiotrace.c
94721 @@ -24,7 +24,7 @@ struct header_iter {
94722 static struct trace_array *mmio_trace_array;
94723 static bool overrun_detected;
94724 static unsigned long prev_overruns;
94725 -static atomic_t dropped_count;
94726 +static atomic_unchecked_t dropped_count;
94727
94728 static void mmio_reset_data(struct trace_array *tr)
94729 {
94730 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94731
94732 static unsigned long count_overruns(struct trace_iterator *iter)
94733 {
94734 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94735 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94736 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94737
94738 if (over > prev_overruns)
94739 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94740 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94741 sizeof(*entry), 0, pc);
94742 if (!event) {
94743 - atomic_inc(&dropped_count);
94744 + atomic_inc_unchecked(&dropped_count);
94745 return;
94746 }
94747 entry = ring_buffer_event_data(event);
94748 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94749 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94750 sizeof(*entry), 0, pc);
94751 if (!event) {
94752 - atomic_inc(&dropped_count);
94753 + atomic_inc_unchecked(&dropped_count);
94754 return;
94755 }
94756 entry = ring_buffer_event_data(event);
94757 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94758 index c6977d5..d243785 100644
94759 --- a/kernel/trace/trace_output.c
94760 +++ b/kernel/trace/trace_output.c
94761 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94762 goto out;
94763 }
94764
94765 + pax_open_kernel();
94766 if (event->funcs->trace == NULL)
94767 - event->funcs->trace = trace_nop_print;
94768 + *(void **)&event->funcs->trace = trace_nop_print;
94769 if (event->funcs->raw == NULL)
94770 - event->funcs->raw = trace_nop_print;
94771 + *(void **)&event->funcs->raw = trace_nop_print;
94772 if (event->funcs->hex == NULL)
94773 - event->funcs->hex = trace_nop_print;
94774 + *(void **)&event->funcs->hex = trace_nop_print;
94775 if (event->funcs->binary == NULL)
94776 - event->funcs->binary = trace_nop_print;
94777 + *(void **)&event->funcs->binary = trace_nop_print;
94778 + pax_close_kernel();
94779
94780 key = event->type & (EVENT_HASHSIZE - 1);
94781
94782 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94783 index 1f24ed9..10407ec 100644
94784 --- a/kernel/trace/trace_seq.c
94785 +++ b/kernel/trace/trace_seq.c
94786 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94787
94788 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94789 if (!IS_ERR(p)) {
94790 - p = mangle_path(s->buffer + s->len, p, "\n");
94791 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94792 if (p) {
94793 s->len = p - s->buffer;
94794 return 1;
94795 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94796 index 8a4e5cb..64f270d 100644
94797 --- a/kernel/trace/trace_stack.c
94798 +++ b/kernel/trace/trace_stack.c
94799 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94800 return;
94801
94802 /* we do not handle interrupt stacks yet */
94803 - if (!object_is_on_stack(stack))
94804 + if (!object_starts_on_stack(stack))
94805 return;
94806
94807 local_irq_save(flags);
94808 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94809 index 7e3cd7a..5156a5fe 100644
94810 --- a/kernel/trace/trace_syscalls.c
94811 +++ b/kernel/trace/trace_syscalls.c
94812 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94813 int num;
94814
94815 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94816 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94817 + return -EINVAL;
94818
94819 mutex_lock(&syscall_trace_lock);
94820 if (!sys_perf_refcount_enter)
94821 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94822 int num;
94823
94824 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94825 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94826 + return;
94827
94828 mutex_lock(&syscall_trace_lock);
94829 sys_perf_refcount_enter--;
94830 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94831 int num;
94832
94833 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94834 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94835 + return -EINVAL;
94836
94837 mutex_lock(&syscall_trace_lock);
94838 if (!sys_perf_refcount_exit)
94839 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94840 int num;
94841
94842 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94843 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94844 + return;
94845
94846 mutex_lock(&syscall_trace_lock);
94847 sys_perf_refcount_exit--;
94848 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94849 index aa312b0..395f343 100644
94850 --- a/kernel/user_namespace.c
94851 +++ b/kernel/user_namespace.c
94852 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94853 !kgid_has_mapping(parent_ns, group))
94854 return -EPERM;
94855
94856 +#ifdef CONFIG_GRKERNSEC
94857 + /*
94858 + * This doesn't really inspire confidence:
94859 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94860 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94861 + * Increases kernel attack surface in areas developers
94862 + * previously cared little about ("low importance due
94863 + * to requiring "root" capability")
94864 + * To be removed when this code receives *proper* review
94865 + */
94866 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94867 + !capable(CAP_SETGID))
94868 + return -EPERM;
94869 +#endif
94870 +
94871 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94872 if (!ns)
94873 return -ENOMEM;
94874 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94875 if (atomic_read(&current->mm->mm_users) > 1)
94876 return -EINVAL;
94877
94878 - if (current->fs->users != 1)
94879 + if (atomic_read(&current->fs->users) != 1)
94880 return -EINVAL;
94881
94882 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94883 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94884 index c8eac43..4b5f08f 100644
94885 --- a/kernel/utsname_sysctl.c
94886 +++ b/kernel/utsname_sysctl.c
94887 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94888 static int proc_do_uts_string(struct ctl_table *table, int write,
94889 void __user *buffer, size_t *lenp, loff_t *ppos)
94890 {
94891 - struct ctl_table uts_table;
94892 + ctl_table_no_const uts_table;
94893 int r;
94894 memcpy(&uts_table, table, sizeof(uts_table));
94895 uts_table.data = get_uts(table, write);
94896 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94897 index a8d6914..8fbdb13 100644
94898 --- a/kernel/watchdog.c
94899 +++ b/kernel/watchdog.c
94900 @@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94901 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94902 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94903
94904 -static struct smp_hotplug_thread watchdog_threads = {
94905 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94906 .store = &softlockup_watchdog,
94907 .thread_should_run = watchdog_should_run,
94908 .thread_fn = watchdog,
94909 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94910 index 5dbe22a..872413c 100644
94911 --- a/kernel/workqueue.c
94912 +++ b/kernel/workqueue.c
94913 @@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
94914 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94915 worker_flags |= WORKER_REBOUND;
94916 worker_flags &= ~WORKER_UNBOUND;
94917 - ACCESS_ONCE(worker->flags) = worker_flags;
94918 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94919 }
94920
94921 spin_unlock_irq(&pool->lock);
94922 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94923 index a285900..5e3b26b 100644
94924 --- a/lib/Kconfig.debug
94925 +++ b/lib/Kconfig.debug
94926 @@ -882,7 +882,7 @@ config DEBUG_MUTEXES
94927
94928 config DEBUG_WW_MUTEX_SLOWPATH
94929 bool "Wait/wound mutex debugging: Slowpath testing"
94930 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94931 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94932 select DEBUG_LOCK_ALLOC
94933 select DEBUG_SPINLOCK
94934 select DEBUG_MUTEXES
94935 @@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94936
94937 config DEBUG_LOCK_ALLOC
94938 bool "Lock debugging: detect incorrect freeing of live locks"
94939 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94940 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94941 select DEBUG_SPINLOCK
94942 select DEBUG_MUTEXES
94943 select LOCKDEP
94944 @@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
94945
94946 config PROVE_LOCKING
94947 bool "Lock debugging: prove locking correctness"
94948 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94949 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94950 select LOCKDEP
94951 select DEBUG_SPINLOCK
94952 select DEBUG_MUTEXES
94953 @@ -964,7 +964,7 @@ config LOCKDEP
94954
94955 config LOCK_STAT
94956 bool "Lock usage statistics"
94957 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94958 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94959 select LOCKDEP
94960 select DEBUG_SPINLOCK
94961 select DEBUG_MUTEXES
94962 @@ -1437,6 +1437,7 @@ config LATENCYTOP
94963 depends on DEBUG_KERNEL
94964 depends on STACKTRACE_SUPPORT
94965 depends on PROC_FS
94966 + depends on !GRKERNSEC_HIDESYM
94967 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94968 select KALLSYMS
94969 select KALLSYMS_ALL
94970 @@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94971 config DEBUG_STRICT_USER_COPY_CHECKS
94972 bool "Strict user copy size checks"
94973 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94974 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94975 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94976 help
94977 Enabling this option turns a certain set of sanity checks for user
94978 copy operations into compile time failures.
94979 @@ -1581,7 +1582,7 @@ endmenu # runtime tests
94980
94981 config PROVIDE_OHCI1394_DMA_INIT
94982 bool "Remote debugging over FireWire early on boot"
94983 - depends on PCI && X86
94984 + depends on PCI && X86 && !GRKERNSEC
94985 help
94986 If you want to debug problems which hang or crash the kernel early
94987 on boot and the crashing machine has a FireWire port, you can use
94988 diff --git a/lib/Makefile b/lib/Makefile
94989 index d6b4bc4..a3724eb 100644
94990 --- a/lib/Makefile
94991 +++ b/lib/Makefile
94992 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94993 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94994 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94995 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94996 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94997 +obj-y += list_debug.o
94998 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94999
95000 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
95001 diff --git a/lib/average.c b/lib/average.c
95002 index 114d1be..ab0350c 100644
95003 --- a/lib/average.c
95004 +++ b/lib/average.c
95005 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
95006 {
95007 unsigned long internal = ACCESS_ONCE(avg->internal);
95008
95009 - ACCESS_ONCE(avg->internal) = internal ?
95010 + ACCESS_ONCE_RW(avg->internal) = internal ?
95011 (((internal << avg->weight) - internal) +
95012 (val << avg->factor)) >> avg->weight :
95013 (val << avg->factor);
95014 diff --git a/lib/bitmap.c b/lib/bitmap.c
95015 index 33ce011..89e3d6f 100644
95016 --- a/lib/bitmap.c
95017 +++ b/lib/bitmap.c
95018 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
95019 {
95020 int c, old_c, totaldigits, ndigits, nchunks, nbits;
95021 u32 chunk;
95022 - const char __user __force *ubuf = (const char __user __force *)buf;
95023 + const char __user *ubuf = (const char __force_user *)buf;
95024
95025 bitmap_zero(maskp, nmaskbits);
95026
95027 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
95028 {
95029 if (!access_ok(VERIFY_READ, ubuf, ulen))
95030 return -EFAULT;
95031 - return __bitmap_parse((const char __force *)ubuf,
95032 + return __bitmap_parse((const char __force_kernel *)ubuf,
95033 ulen, 1, maskp, nmaskbits);
95034
95035 }
95036 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
95037 {
95038 unsigned a, b;
95039 int c, old_c, totaldigits;
95040 - const char __user __force *ubuf = (const char __user __force *)buf;
95041 + const char __user *ubuf = (const char __force_user *)buf;
95042 int exp_digit, in_range;
95043
95044 totaldigits = c = 0;
95045 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
95046 {
95047 if (!access_ok(VERIFY_READ, ubuf, ulen))
95048 return -EFAULT;
95049 - return __bitmap_parselist((const char __force *)ubuf,
95050 + return __bitmap_parselist((const char __force_kernel *)ubuf,
95051 ulen, 1, maskp, nmaskbits);
95052 }
95053 EXPORT_SYMBOL(bitmap_parselist_user);
95054 diff --git a/lib/bug.c b/lib/bug.c
95055 index d1d7c78..b354235 100644
95056 --- a/lib/bug.c
95057 +++ b/lib/bug.c
95058 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
95059 return BUG_TRAP_TYPE_NONE;
95060
95061 bug = find_bug(bugaddr);
95062 + if (!bug)
95063 + return BUG_TRAP_TYPE_NONE;
95064
95065 file = NULL;
95066 line = 0;
95067 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
95068 index 547f7f9..a6d4ba0 100644
95069 --- a/lib/debugobjects.c
95070 +++ b/lib/debugobjects.c
95071 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
95072 if (limit > 4)
95073 return;
95074
95075 - is_on_stack = object_is_on_stack(addr);
95076 + is_on_stack = object_starts_on_stack(addr);
95077 if (is_on_stack == onstack)
95078 return;
95079
95080 diff --git a/lib/div64.c b/lib/div64.c
95081 index 4382ad7..08aa558 100644
95082 --- a/lib/div64.c
95083 +++ b/lib/div64.c
95084 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
95085 EXPORT_SYMBOL(__div64_32);
95086
95087 #ifndef div_s64_rem
95088 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
95089 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
95090 {
95091 u64 quotient;
95092
95093 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
95094 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
95095 */
95096 #ifndef div64_u64
95097 -u64 div64_u64(u64 dividend, u64 divisor)
95098 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
95099 {
95100 u32 high = divisor >> 32;
95101 u64 quot;
95102 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
95103 index 98f2d7e..899da5c 100644
95104 --- a/lib/dma-debug.c
95105 +++ b/lib/dma-debug.c
95106 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
95107
95108 void dma_debug_add_bus(struct bus_type *bus)
95109 {
95110 - struct notifier_block *nb;
95111 + notifier_block_no_const *nb;
95112
95113 if (global_disable)
95114 return;
95115 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
95116
95117 static void check_for_stack(struct device *dev, void *addr)
95118 {
95119 - if (object_is_on_stack(addr))
95120 + if (object_starts_on_stack(addr))
95121 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
95122 "stack [addr=%p]\n", addr);
95123 }
95124 diff --git a/lib/hash.c b/lib/hash.c
95125 index fea973f..386626f 100644
95126 --- a/lib/hash.c
95127 +++ b/lib/hash.c
95128 @@ -14,7 +14,7 @@
95129 #include <linux/hash.h>
95130 #include <linux/cache.h>
95131
95132 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
95133 +static struct fast_hash_ops arch_hash_ops __read_only = {
95134 .hash = jhash,
95135 .hash2 = jhash2,
95136 };
95137 diff --git a/lib/inflate.c b/lib/inflate.c
95138 index 013a761..c28f3fc 100644
95139 --- a/lib/inflate.c
95140 +++ b/lib/inflate.c
95141 @@ -269,7 +269,7 @@ static void free(void *where)
95142 malloc_ptr = free_mem_ptr;
95143 }
95144 #else
95145 -#define malloc(a) kmalloc(a, GFP_KERNEL)
95146 +#define malloc(a) kmalloc((a), GFP_KERNEL)
95147 #define free(a) kfree(a)
95148 #endif
95149
95150 diff --git a/lib/ioremap.c b/lib/ioremap.c
95151 index 0c9216c..863bd89 100644
95152 --- a/lib/ioremap.c
95153 +++ b/lib/ioremap.c
95154 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
95155 unsigned long next;
95156
95157 phys_addr -= addr;
95158 - pmd = pmd_alloc(&init_mm, pud, addr);
95159 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95160 if (!pmd)
95161 return -ENOMEM;
95162 do {
95163 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
95164 unsigned long next;
95165
95166 phys_addr -= addr;
95167 - pud = pud_alloc(&init_mm, pgd, addr);
95168 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95169 if (!pud)
95170 return -ENOMEM;
95171 do {
95172 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
95173 index bd2bea9..6b3c95e 100644
95174 --- a/lib/is_single_threaded.c
95175 +++ b/lib/is_single_threaded.c
95176 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
95177 struct task_struct *p, *t;
95178 bool ret;
95179
95180 + if (!mm)
95181 + return true;
95182 +
95183 if (atomic_read(&task->signal->live) != 1)
95184 return false;
95185
95186 diff --git a/lib/kobject.c b/lib/kobject.c
95187 index 58751bb..93a1853 100644
95188 --- a/lib/kobject.c
95189 +++ b/lib/kobject.c
95190 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
95191
95192
95193 static DEFINE_SPINLOCK(kobj_ns_type_lock);
95194 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
95195 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
95196
95197 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95198 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95199 {
95200 enum kobj_ns_type type = ops->type;
95201 int error;
95202 diff --git a/lib/list_debug.c b/lib/list_debug.c
95203 index c24c2f7..f0296f4 100644
95204 --- a/lib/list_debug.c
95205 +++ b/lib/list_debug.c
95206 @@ -11,7 +11,9 @@
95207 #include <linux/bug.h>
95208 #include <linux/kernel.h>
95209 #include <linux/rculist.h>
95210 +#include <linux/mm.h>
95211
95212 +#ifdef CONFIG_DEBUG_LIST
95213 /*
95214 * Insert a new entry between two known consecutive entries.
95215 *
95216 @@ -19,21 +21,40 @@
95217 * the prev/next entries already!
95218 */
95219
95220 +static bool __list_add_debug(struct list_head *new,
95221 + struct list_head *prev,
95222 + struct list_head *next)
95223 +{
95224 + if (unlikely(next->prev != prev)) {
95225 + printk(KERN_ERR "list_add corruption. next->prev should be "
95226 + "prev (%p), but was %p. (next=%p).\n",
95227 + prev, next->prev, next);
95228 + BUG();
95229 + return false;
95230 + }
95231 + if (unlikely(prev->next != next)) {
95232 + printk(KERN_ERR "list_add corruption. prev->next should be "
95233 + "next (%p), but was %p. (prev=%p).\n",
95234 + next, prev->next, prev);
95235 + BUG();
95236 + return false;
95237 + }
95238 + if (unlikely(new == prev || new == next)) {
95239 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
95240 + new, prev, next);
95241 + BUG();
95242 + return false;
95243 + }
95244 + return true;
95245 +}
95246 +
95247 void __list_add(struct list_head *new,
95248 - struct list_head *prev,
95249 - struct list_head *next)
95250 + struct list_head *prev,
95251 + struct list_head *next)
95252 {
95253 - WARN(next->prev != prev,
95254 - "list_add corruption. next->prev should be "
95255 - "prev (%p), but was %p. (next=%p).\n",
95256 - prev, next->prev, next);
95257 - WARN(prev->next != next,
95258 - "list_add corruption. prev->next should be "
95259 - "next (%p), but was %p. (prev=%p).\n",
95260 - next, prev->next, prev);
95261 - WARN(new == prev || new == next,
95262 - "list_add double add: new=%p, prev=%p, next=%p.\n",
95263 - new, prev, next);
95264 + if (!__list_add_debug(new, prev, next))
95265 + return;
95266 +
95267 next->prev = new;
95268 new->next = next;
95269 new->prev = prev;
95270 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
95271 }
95272 EXPORT_SYMBOL(__list_add);
95273
95274 -void __list_del_entry(struct list_head *entry)
95275 +static bool __list_del_entry_debug(struct list_head *entry)
95276 {
95277 struct list_head *prev, *next;
95278
95279 prev = entry->prev;
95280 next = entry->next;
95281
95282 - if (WARN(next == LIST_POISON1,
95283 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95284 - entry, LIST_POISON1) ||
95285 - WARN(prev == LIST_POISON2,
95286 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95287 - entry, LIST_POISON2) ||
95288 - WARN(prev->next != entry,
95289 - "list_del corruption. prev->next should be %p, "
95290 - "but was %p\n", entry, prev->next) ||
95291 - WARN(next->prev != entry,
95292 - "list_del corruption. next->prev should be %p, "
95293 - "but was %p\n", entry, next->prev))
95294 + if (unlikely(next == LIST_POISON1)) {
95295 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95296 + entry, LIST_POISON1);
95297 + BUG();
95298 + return false;
95299 + }
95300 + if (unlikely(prev == LIST_POISON2)) {
95301 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95302 + entry, LIST_POISON2);
95303 + BUG();
95304 + return false;
95305 + }
95306 + if (unlikely(entry->prev->next != entry)) {
95307 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95308 + "but was %p\n", entry, prev->next);
95309 + BUG();
95310 + return false;
95311 + }
95312 + if (unlikely(entry->next->prev != entry)) {
95313 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95314 + "but was %p\n", entry, next->prev);
95315 + BUG();
95316 + return false;
95317 + }
95318 + return true;
95319 +}
95320 +
95321 +void __list_del_entry(struct list_head *entry)
95322 +{
95323 + if (!__list_del_entry_debug(entry))
95324 return;
95325
95326 - __list_del(prev, next);
95327 + __list_del(entry->prev, entry->next);
95328 }
95329 EXPORT_SYMBOL(__list_del_entry);
95330
95331 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95332 void __list_add_rcu(struct list_head *new,
95333 struct list_head *prev, struct list_head *next)
95334 {
95335 - WARN(next->prev != prev,
95336 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95337 - prev, next->prev, next);
95338 - WARN(prev->next != next,
95339 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95340 - next, prev->next, prev);
95341 + if (!__list_add_debug(new, prev, next))
95342 + return;
95343 +
95344 new->next = next;
95345 new->prev = prev;
95346 rcu_assign_pointer(list_next_rcu(prev), new);
95347 next->prev = new;
95348 }
95349 EXPORT_SYMBOL(__list_add_rcu);
95350 +#endif
95351 +
95352 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95353 +{
95354 +#ifdef CONFIG_DEBUG_LIST
95355 + if (!__list_add_debug(new, prev, next))
95356 + return;
95357 +#endif
95358 +
95359 + pax_open_kernel();
95360 + next->prev = new;
95361 + new->next = next;
95362 + new->prev = prev;
95363 + prev->next = new;
95364 + pax_close_kernel();
95365 +}
95366 +EXPORT_SYMBOL(__pax_list_add);
95367 +
95368 +void pax_list_del(struct list_head *entry)
95369 +{
95370 +#ifdef CONFIG_DEBUG_LIST
95371 + if (!__list_del_entry_debug(entry))
95372 + return;
95373 +#endif
95374 +
95375 + pax_open_kernel();
95376 + __list_del(entry->prev, entry->next);
95377 + entry->next = LIST_POISON1;
95378 + entry->prev = LIST_POISON2;
95379 + pax_close_kernel();
95380 +}
95381 +EXPORT_SYMBOL(pax_list_del);
95382 +
95383 +void pax_list_del_init(struct list_head *entry)
95384 +{
95385 + pax_open_kernel();
95386 + __list_del(entry->prev, entry->next);
95387 + INIT_LIST_HEAD(entry);
95388 + pax_close_kernel();
95389 +}
95390 +EXPORT_SYMBOL(pax_list_del_init);
95391 +
95392 +void __pax_list_add_rcu(struct list_head *new,
95393 + struct list_head *prev, struct list_head *next)
95394 +{
95395 +#ifdef CONFIG_DEBUG_LIST
95396 + if (!__list_add_debug(new, prev, next))
95397 + return;
95398 +#endif
95399 +
95400 + pax_open_kernel();
95401 + new->next = next;
95402 + new->prev = prev;
95403 + rcu_assign_pointer(list_next_rcu(prev), new);
95404 + next->prev = new;
95405 + pax_close_kernel();
95406 +}
95407 +EXPORT_SYMBOL(__pax_list_add_rcu);
95408 +
95409 +void pax_list_del_rcu(struct list_head *entry)
95410 +{
95411 +#ifdef CONFIG_DEBUG_LIST
95412 + if (!__list_del_entry_debug(entry))
95413 + return;
95414 +#endif
95415 +
95416 + pax_open_kernel();
95417 + __list_del(entry->prev, entry->next);
95418 + entry->next = LIST_POISON1;
95419 + entry->prev = LIST_POISON2;
95420 + pax_close_kernel();
95421 +}
95422 +EXPORT_SYMBOL(pax_list_del_rcu);
95423 diff --git a/lib/lockref.c b/lib/lockref.c
95424 index d2233de..fa1a2f6 100644
95425 --- a/lib/lockref.c
95426 +++ b/lib/lockref.c
95427 @@ -48,13 +48,13 @@
95428 void lockref_get(struct lockref *lockref)
95429 {
95430 CMPXCHG_LOOP(
95431 - new.count++;
95432 + __lockref_inc(&new);
95433 ,
95434 return;
95435 );
95436
95437 spin_lock(&lockref->lock);
95438 - lockref->count++;
95439 + __lockref_inc(lockref);
95440 spin_unlock(&lockref->lock);
95441 }
95442 EXPORT_SYMBOL(lockref_get);
95443 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95444 int retval;
95445
95446 CMPXCHG_LOOP(
95447 - new.count++;
95448 + __lockref_inc(&new);
95449 if (!old.count)
95450 return 0;
95451 ,
95452 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95453 spin_lock(&lockref->lock);
95454 retval = 0;
95455 if (lockref->count) {
95456 - lockref->count++;
95457 + __lockref_inc(lockref);
95458 retval = 1;
95459 }
95460 spin_unlock(&lockref->lock);
95461 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95462 int lockref_get_or_lock(struct lockref *lockref)
95463 {
95464 CMPXCHG_LOOP(
95465 - new.count++;
95466 + __lockref_inc(&new);
95467 if (!old.count)
95468 break;
95469 ,
95470 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95471 spin_lock(&lockref->lock);
95472 if (!lockref->count)
95473 return 0;
95474 - lockref->count++;
95475 + __lockref_inc(lockref);
95476 spin_unlock(&lockref->lock);
95477 return 1;
95478 }
95479 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95480 int lockref_put_or_lock(struct lockref *lockref)
95481 {
95482 CMPXCHG_LOOP(
95483 - new.count--;
95484 + __lockref_dec(&new);
95485 if (old.count <= 1)
95486 break;
95487 ,
95488 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95489 spin_lock(&lockref->lock);
95490 if (lockref->count <= 1)
95491 return 0;
95492 - lockref->count--;
95493 + __lockref_dec(lockref);
95494 spin_unlock(&lockref->lock);
95495 return 1;
95496 }
95497 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95498 int retval;
95499
95500 CMPXCHG_LOOP(
95501 - new.count++;
95502 + __lockref_inc(&new);
95503 if ((int)old.count < 0)
95504 return 0;
95505 ,
95506 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95507 spin_lock(&lockref->lock);
95508 retval = 0;
95509 if ((int) lockref->count >= 0) {
95510 - lockref->count++;
95511 + __lockref_inc(lockref);
95512 retval = 1;
95513 }
95514 spin_unlock(&lockref->lock);
95515 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95516 index a89cf09..1a42c2d 100644
95517 --- a/lib/percpu-refcount.c
95518 +++ b/lib/percpu-refcount.c
95519 @@ -29,7 +29,7 @@
95520 * can't hit 0 before we've added up all the percpu refs.
95521 */
95522
95523 -#define PCPU_COUNT_BIAS (1U << 31)
95524 +#define PCPU_COUNT_BIAS (1U << 30)
95525
95526 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
95527 {
95528 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95529 index 3291a8e..346a91e 100644
95530 --- a/lib/radix-tree.c
95531 +++ b/lib/radix-tree.c
95532 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95533 int nr;
95534 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95535 };
95536 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95537 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95538
95539 static inline void *ptr_to_indirect(void *ptr)
95540 {
95541 diff --git a/lib/random32.c b/lib/random32.c
95542 index c9b6bf3..4752c6d4 100644
95543 --- a/lib/random32.c
95544 +++ b/lib/random32.c
95545 @@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
95546 }
95547 #endif
95548
95549 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95550 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95551
95552 /**
95553 * prandom_u32_state - seeded pseudo-random number generator.
95554 diff --git a/lib/rbtree.c b/lib/rbtree.c
95555 index c16c81a..4dcbda1 100644
95556 --- a/lib/rbtree.c
95557 +++ b/lib/rbtree.c
95558 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95559 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95560
95561 static const struct rb_augment_callbacks dummy_callbacks = {
95562 - dummy_propagate, dummy_copy, dummy_rotate
95563 + .propagate = dummy_propagate,
95564 + .copy = dummy_copy,
95565 + .rotate = dummy_rotate
95566 };
95567
95568 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95569 diff --git a/lib/show_mem.c b/lib/show_mem.c
95570 index 0922579..9d7adb9 100644
95571 --- a/lib/show_mem.c
95572 +++ b/lib/show_mem.c
95573 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95574 quicklist_total_size());
95575 #endif
95576 #ifdef CONFIG_MEMORY_FAILURE
95577 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95578 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95579 #endif
95580 }
95581 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95582 index bb2b201..46abaf9 100644
95583 --- a/lib/strncpy_from_user.c
95584 +++ b/lib/strncpy_from_user.c
95585 @@ -21,7 +21,7 @@
95586 */
95587 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95588 {
95589 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95590 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95591 long res = 0;
95592
95593 /*
95594 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95595 index a28df52..3d55877 100644
95596 --- a/lib/strnlen_user.c
95597 +++ b/lib/strnlen_user.c
95598 @@ -26,7 +26,7 @@
95599 */
95600 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95601 {
95602 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95603 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95604 long align, res = 0;
95605 unsigned long c;
95606
95607 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95608 index 4abda07..b9d3765 100644
95609 --- a/lib/swiotlb.c
95610 +++ b/lib/swiotlb.c
95611 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95612
95613 void
95614 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95615 - dma_addr_t dev_addr)
95616 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95617 {
95618 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95619
95620 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
95621 index 89e0345..3347efe 100644
95622 --- a/lib/test_bpf.c
95623 +++ b/lib/test_bpf.c
95624 @@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
95625 break;
95626
95627 case INTERNAL:
95628 - fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
95629 + fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
95630 if (fp == NULL) {
95631 pr_cont("UNEXPECTED_FAIL no memory left\n");
95632 *err = -ENOMEM;
95633 diff --git a/lib/usercopy.c b/lib/usercopy.c
95634 index 4f5b1dd..7cab418 100644
95635 --- a/lib/usercopy.c
95636 +++ b/lib/usercopy.c
95637 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95638 WARN(1, "Buffer overflow detected!\n");
95639 }
95640 EXPORT_SYMBOL(copy_from_user_overflow);
95641 +
95642 +void copy_to_user_overflow(void)
95643 +{
95644 + WARN(1, "Buffer overflow detected!\n");
95645 +}
95646 +EXPORT_SYMBOL(copy_to_user_overflow);
95647 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95648 index 6fe2c84..2fe5ec6 100644
95649 --- a/lib/vsprintf.c
95650 +++ b/lib/vsprintf.c
95651 @@ -16,6 +16,9 @@
95652 * - scnprintf and vscnprintf
95653 */
95654
95655 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95656 +#define __INCLUDED_BY_HIDESYM 1
95657 +#endif
95658 #include <stdarg.h>
95659 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95660 #include <linux/types.h>
95661 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95662 #ifdef CONFIG_KALLSYMS
95663 if (*fmt == 'B')
95664 sprint_backtrace(sym, value);
95665 - else if (*fmt != 'f' && *fmt != 's')
95666 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95667 sprint_symbol(sym, value);
95668 else
95669 sprint_symbol_no_offset(sym, value);
95670 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
95671 return number(buf, end, num, spec);
95672 }
95673
95674 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95675 +int kptr_restrict __read_mostly = 2;
95676 +#else
95677 int kptr_restrict __read_mostly;
95678 +#endif
95679
95680 /*
95681 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95682 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
95683 *
95684 * - 'F' For symbolic function descriptor pointers with offset
95685 * - 'f' For simple symbolic function names without offset
95686 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95687 * - 'S' For symbolic direct pointers with offset
95688 * - 's' For symbolic direct pointers without offset
95689 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95690 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95691 * - 'B' For backtraced symbolic direct pointers with offset
95692 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95693 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95694
95695 if (!ptr && *fmt != 'K') {
95696 /*
95697 - * Print (null) with the same width as a pointer so it makes
95698 + * Print (nil) with the same width as a pointer so it makes
95699 * tabular output look nice.
95700 */
95701 if (spec.field_width == -1)
95702 spec.field_width = default_width;
95703 - return string(buf, end, "(null)", spec);
95704 + return string(buf, end, "(nil)", spec);
95705 }
95706
95707 switch (*fmt) {
95708 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95709 /* Fallthrough */
95710 case 'S':
95711 case 's':
95712 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95713 + break;
95714 +#else
95715 + return symbol_string(buf, end, ptr, spec, fmt);
95716 +#endif
95717 + case 'X':
95718 + ptr = dereference_function_descriptor(ptr);
95719 + case 'A':
95720 case 'B':
95721 return symbol_string(buf, end, ptr, spec, fmt);
95722 case 'R':
95723 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95724 va_end(va);
95725 return buf;
95726 }
95727 + case 'P':
95728 + break;
95729 case 'K':
95730 /*
95731 * %pK cannot be used in IRQ context because its test
95732 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95733 ((const struct file *)ptr)->f_path.dentry,
95734 spec, fmt);
95735 }
95736 +
95737 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95738 + /* 'P' = approved pointers to copy to userland,
95739 + as in the /proc/kallsyms case, as we make it display nothing
95740 + for non-root users, and the real contents for root users
95741 + 'X' = approved simple symbols
95742 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95743 + above
95744 + */
95745 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95746 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95747 + dump_stack();
95748 + ptr = NULL;
95749 + }
95750 +#endif
95751 +
95752 spec.flags |= SMALL;
95753 if (spec.field_width == -1) {
95754 spec.field_width = default_width;
95755 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95756 typeof(type) value; \
95757 if (sizeof(type) == 8) { \
95758 args = PTR_ALIGN(args, sizeof(u32)); \
95759 - *(u32 *)&value = *(u32 *)args; \
95760 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95761 + *(u32 *)&value = *(const u32 *)args; \
95762 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95763 } else { \
95764 args = PTR_ALIGN(args, sizeof(type)); \
95765 - value = *(typeof(type) *)args; \
95766 + value = *(const typeof(type) *)args; \
95767 } \
95768 args += sizeof(type); \
95769 value; \
95770 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95771 case FORMAT_TYPE_STR: {
95772 const char *str_arg = args;
95773 args += strlen(str_arg) + 1;
95774 - str = string(str, end, (char *)str_arg, spec);
95775 + str = string(str, end, str_arg, spec);
95776 break;
95777 }
95778
95779 diff --git a/localversion-grsec b/localversion-grsec
95780 new file mode 100644
95781 index 0000000..7cd6065
95782 --- /dev/null
95783 +++ b/localversion-grsec
95784 @@ -0,0 +1 @@
95785 +-grsec
95786 diff --git a/mm/Kconfig b/mm/Kconfig
95787 index 886db21..f514de2 100644
95788 --- a/mm/Kconfig
95789 +++ b/mm/Kconfig
95790 @@ -333,10 +333,11 @@ config KSM
95791 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95792
95793 config DEFAULT_MMAP_MIN_ADDR
95794 - int "Low address space to protect from user allocation"
95795 + int "Low address space to protect from user allocation"
95796 depends on MMU
95797 - default 4096
95798 - help
95799 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95800 + default 65536
95801 + help
95802 This is the portion of low virtual memory which should be protected
95803 from userspace allocation. Keeping a user from writing to low pages
95804 can help reduce the impact of kernel NULL pointer bugs.
95805 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
95806
95807 config HWPOISON_INJECT
95808 tristate "HWPoison pages injector"
95809 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95810 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95811 select PROC_PAGE_MONITOR
95812
95813 config NOMMU_INITIAL_TRIM_EXCESS
95814 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95815 index 1706cbb..f89dbca 100644
95816 --- a/mm/backing-dev.c
95817 +++ b/mm/backing-dev.c
95818 @@ -12,7 +12,7 @@
95819 #include <linux/device.h>
95820 #include <trace/events/writeback.h>
95821
95822 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95823 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95824
95825 struct backing_dev_info default_backing_dev_info = {
95826 .name = "default",
95827 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95828 return err;
95829
95830 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95831 - atomic_long_inc_return(&bdi_seq));
95832 + atomic_long_inc_return_unchecked(&bdi_seq));
95833 if (err) {
95834 bdi_destroy(bdi);
95835 return err;
95836 diff --git a/mm/filemap.c b/mm/filemap.c
95837 index 90effcd..539aa64 100644
95838 --- a/mm/filemap.c
95839 +++ b/mm/filemap.c
95840 @@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95841 struct address_space *mapping = file->f_mapping;
95842
95843 if (!mapping->a_ops->readpage)
95844 - return -ENOEXEC;
95845 + return -ENODEV;
95846 file_accessed(file);
95847 vma->vm_ops = &generic_file_vm_ops;
95848 return 0;
95849 @@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95850 *pos = i_size_read(inode);
95851
95852 if (limit != RLIM_INFINITY) {
95853 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95854 if (*pos >= limit) {
95855 send_sig(SIGXFSZ, current, 0);
95856 return -EFBIG;
95857 diff --git a/mm/fremap.c b/mm/fremap.c
95858 index 72b8fa3..c5b39f1 100644
95859 --- a/mm/fremap.c
95860 +++ b/mm/fremap.c
95861 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95862 retry:
95863 vma = find_vma(mm, start);
95864
95865 +#ifdef CONFIG_PAX_SEGMEXEC
95866 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95867 + goto out;
95868 +#endif
95869 +
95870 /*
95871 * Make sure the vma is shared, that it supports prefaulting,
95872 * and that the remapped range is valid and fully within
95873 diff --git a/mm/gup.c b/mm/gup.c
95874 index 91d044b..a58ecf6 100644
95875 --- a/mm/gup.c
95876 +++ b/mm/gup.c
95877 @@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95878 unsigned int fault_flags = 0;
95879 int ret;
95880
95881 - /* For mlock, just skip the stack guard page. */
95882 - if ((*flags & FOLL_MLOCK) &&
95883 - (stack_guard_page_start(vma, address) ||
95884 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95885 - return -ENOENT;
95886 if (*flags & FOLL_WRITE)
95887 fault_flags |= FAULT_FLAG_WRITE;
95888 if (nonblocking)
95889 @@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95890 if (!(gup_flags & FOLL_FORCE))
95891 gup_flags |= FOLL_NUMA;
95892
95893 - do {
95894 + while (nr_pages) {
95895 struct page *page;
95896 unsigned int foll_flags = gup_flags;
95897 unsigned int page_increm;
95898
95899 /* first iteration or cross vma bound */
95900 if (!vma || start >= vma->vm_end) {
95901 - vma = find_extend_vma(mm, start);
95902 + vma = find_vma(mm, start);
95903 if (!vma && in_gate_area(mm, start)) {
95904 int ret;
95905 ret = get_gate_page(mm, start & PAGE_MASK,
95906 @@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95907 goto next_page;
95908 }
95909
95910 - if (!vma || check_vma_flags(vma, gup_flags))
95911 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95912 return i ? : -EFAULT;
95913 if (is_vm_hugetlb_page(vma)) {
95914 i = follow_hugetlb_page(mm, vma, pages, vmas,
95915 @@ -510,7 +505,7 @@ next_page:
95916 i += page_increm;
95917 start += page_increm * PAGE_SIZE;
95918 nr_pages -= page_increm;
95919 - } while (nr_pages);
95920 + }
95921 return i;
95922 }
95923 EXPORT_SYMBOL(__get_user_pages);
95924 diff --git a/mm/highmem.c b/mm/highmem.c
95925 index 123bcd3..0de52ba 100644
95926 --- a/mm/highmem.c
95927 +++ b/mm/highmem.c
95928 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95929 * So no dangers, even with speculative execution.
95930 */
95931 page = pte_page(pkmap_page_table[i]);
95932 + pax_open_kernel();
95933 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95934 -
95935 + pax_close_kernel();
95936 set_page_address(page, NULL);
95937 need_flush = 1;
95938 }
95939 @@ -259,9 +260,11 @@ start:
95940 }
95941 }
95942 vaddr = PKMAP_ADDR(last_pkmap_nr);
95943 +
95944 + pax_open_kernel();
95945 set_pte_at(&init_mm, vaddr,
95946 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95947 -
95948 + pax_close_kernel();
95949 pkmap_count[last_pkmap_nr] = 1;
95950 set_page_address(page, (void *)vaddr);
95951
95952 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95953 index eeceeeb..a209d58 100644
95954 --- a/mm/hugetlb.c
95955 +++ b/mm/hugetlb.c
95956 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95957 struct ctl_table *table, int write,
95958 void __user *buffer, size_t *length, loff_t *ppos)
95959 {
95960 + ctl_table_no_const t;
95961 struct hstate *h = &default_hstate;
95962 unsigned long tmp = h->max_huge_pages;
95963 int ret;
95964 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95965 if (!hugepages_supported())
95966 return -ENOTSUPP;
95967
95968 - table->data = &tmp;
95969 - table->maxlen = sizeof(unsigned long);
95970 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95971 + t = *table;
95972 + t.data = &tmp;
95973 + t.maxlen = sizeof(unsigned long);
95974 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95975 if (ret)
95976 goto out;
95977
95978 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95979 struct hstate *h = &default_hstate;
95980 unsigned long tmp;
95981 int ret;
95982 + ctl_table_no_const hugetlb_table;
95983
95984 if (!hugepages_supported())
95985 return -ENOTSUPP;
95986 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95987 if (write && hstate_is_gigantic(h))
95988 return -EINVAL;
95989
95990 - table->data = &tmp;
95991 - table->maxlen = sizeof(unsigned long);
95992 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95993 + hugetlb_table = *table;
95994 + hugetlb_table.data = &tmp;
95995 + hugetlb_table.maxlen = sizeof(unsigned long);
95996 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95997 if (ret)
95998 goto out;
95999
96000 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
96001 mutex_unlock(&mapping->i_mmap_mutex);
96002 }
96003
96004 +#ifdef CONFIG_PAX_SEGMEXEC
96005 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
96006 +{
96007 + struct mm_struct *mm = vma->vm_mm;
96008 + struct vm_area_struct *vma_m;
96009 + unsigned long address_m;
96010 + pte_t *ptep_m;
96011 +
96012 + vma_m = pax_find_mirror_vma(vma);
96013 + if (!vma_m)
96014 + return;
96015 +
96016 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96017 + address_m = address + SEGMEXEC_TASK_SIZE;
96018 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
96019 + get_page(page_m);
96020 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
96021 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
96022 +}
96023 +#endif
96024 +
96025 /*
96026 * Hugetlb_cow() should be called with page lock of the original hugepage held.
96027 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
96028 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
96029 make_huge_pte(vma, new_page, 1));
96030 page_remove_rmap(old_page);
96031 hugepage_add_new_anon_rmap(new_page, vma, address);
96032 +
96033 +#ifdef CONFIG_PAX_SEGMEXEC
96034 + pax_mirror_huge_pte(vma, address, new_page);
96035 +#endif
96036 +
96037 /* Make the old page be freed below */
96038 new_page = old_page;
96039 }
96040 @@ -3063,6 +3093,10 @@ retry:
96041 && (vma->vm_flags & VM_SHARED)));
96042 set_huge_pte_at(mm, address, ptep, new_pte);
96043
96044 +#ifdef CONFIG_PAX_SEGMEXEC
96045 + pax_mirror_huge_pte(vma, address, page);
96046 +#endif
96047 +
96048 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
96049 /* Optimization, do the COW without a second fault */
96050 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
96051 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96052 struct hstate *h = hstate_vma(vma);
96053 struct address_space *mapping;
96054
96055 +#ifdef CONFIG_PAX_SEGMEXEC
96056 + struct vm_area_struct *vma_m;
96057 +#endif
96058 +
96059 address &= huge_page_mask(h);
96060
96061 ptep = huge_pte_offset(mm, address);
96062 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96063 VM_FAULT_SET_HINDEX(hstate_index(h));
96064 }
96065
96066 +#ifdef CONFIG_PAX_SEGMEXEC
96067 + vma_m = pax_find_mirror_vma(vma);
96068 + if (vma_m) {
96069 + unsigned long address_m;
96070 +
96071 + if (vma->vm_start > vma_m->vm_start) {
96072 + address_m = address;
96073 + address -= SEGMEXEC_TASK_SIZE;
96074 + vma = vma_m;
96075 + h = hstate_vma(vma);
96076 + } else
96077 + address_m = address + SEGMEXEC_TASK_SIZE;
96078 +
96079 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
96080 + return VM_FAULT_OOM;
96081 + address_m &= HPAGE_MASK;
96082 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
96083 + }
96084 +#endif
96085 +
96086 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
96087 if (!ptep)
96088 return VM_FAULT_OOM;
96089 diff --git a/mm/internal.h b/mm/internal.h
96090 index 5f2772f..4c3882c 100644
96091 --- a/mm/internal.h
96092 +++ b/mm/internal.h
96093 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
96094
96095 extern int __isolate_free_page(struct page *page, unsigned int order);
96096 extern void __free_pages_bootmem(struct page *page, unsigned int order);
96097 +extern void free_compound_page(struct page *page);
96098 extern void prep_compound_page(struct page *page, unsigned long order);
96099 #ifdef CONFIG_MEMORY_FAILURE
96100 extern bool is_free_buddy_page(struct page *page);
96101 @@ -376,7 +377,7 @@ extern u32 hwpoison_filter_enable;
96102
96103 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
96104 unsigned long, unsigned long,
96105 - unsigned long, unsigned long);
96106 + unsigned long, unsigned long) __intentional_overflow(-1);
96107
96108 extern void set_pageblock_order(void);
96109 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
96110 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
96111 index 141dcf7..7327fd3 100644
96112 --- a/mm/iov_iter.c
96113 +++ b/mm/iov_iter.c
96114 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
96115
96116 while (bytes) {
96117 char __user *buf = iov->iov_base + base;
96118 - int copy = min(bytes, iov->iov_len - base);
96119 + size_t copy = min(bytes, iov->iov_len - base);
96120
96121 base = 0;
96122 left = __copy_from_user_inatomic(vaddr, buf, copy);
96123 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
96124
96125 kaddr = kmap_atomic(page);
96126 if (likely(i->nr_segs == 1)) {
96127 - int left;
96128 + size_t left;
96129 char __user *buf = i->iov->iov_base + i->iov_offset;
96130 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
96131 copied = bytes - left;
96132 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
96133 * zero-length segments (without overruning the iovec).
96134 */
96135 while (bytes || unlikely(i->count && !iov->iov_len)) {
96136 - int copy;
96137 + size_t copy;
96138
96139 copy = min(bytes, iov->iov_len - base);
96140 BUG_ON(!i->count || i->count < copy);
96141 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
96142 index 3cda50c..032ba634 100644
96143 --- a/mm/kmemleak.c
96144 +++ b/mm/kmemleak.c
96145 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
96146
96147 for (i = 0; i < object->trace_len; i++) {
96148 void *ptr = (void *)object->trace[i];
96149 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
96150 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
96151 }
96152 }
96153
96154 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
96155 return -ENOMEM;
96156 }
96157
96158 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
96159 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
96160 &kmemleak_fops);
96161 if (!dentry)
96162 pr_warning("Failed to create the debugfs kmemleak file\n");
96163 diff --git a/mm/maccess.c b/mm/maccess.c
96164 index d53adf9..03a24bf 100644
96165 --- a/mm/maccess.c
96166 +++ b/mm/maccess.c
96167 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
96168 set_fs(KERNEL_DS);
96169 pagefault_disable();
96170 ret = __copy_from_user_inatomic(dst,
96171 - (__force const void __user *)src, size);
96172 + (const void __force_user *)src, size);
96173 pagefault_enable();
96174 set_fs(old_fs);
96175
96176 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
96177
96178 set_fs(KERNEL_DS);
96179 pagefault_disable();
96180 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
96181 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
96182 pagefault_enable();
96183 set_fs(old_fs);
96184
96185 diff --git a/mm/madvise.c b/mm/madvise.c
96186 index 0938b30..199abe8 100644
96187 --- a/mm/madvise.c
96188 +++ b/mm/madvise.c
96189 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
96190 pgoff_t pgoff;
96191 unsigned long new_flags = vma->vm_flags;
96192
96193 +#ifdef CONFIG_PAX_SEGMEXEC
96194 + struct vm_area_struct *vma_m;
96195 +#endif
96196 +
96197 switch (behavior) {
96198 case MADV_NORMAL:
96199 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
96200 @@ -126,6 +130,13 @@ success:
96201 /*
96202 * vm_flags is protected by the mmap_sem held in write mode.
96203 */
96204 +
96205 +#ifdef CONFIG_PAX_SEGMEXEC
96206 + vma_m = pax_find_mirror_vma(vma);
96207 + if (vma_m)
96208 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
96209 +#endif
96210 +
96211 vma->vm_flags = new_flags;
96212
96213 out:
96214 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96215 struct vm_area_struct **prev,
96216 unsigned long start, unsigned long end)
96217 {
96218 +
96219 +#ifdef CONFIG_PAX_SEGMEXEC
96220 + struct vm_area_struct *vma_m;
96221 +#endif
96222 +
96223 *prev = vma;
96224 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
96225 return -EINVAL;
96226 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96227 zap_page_range(vma, start, end - start, &details);
96228 } else
96229 zap_page_range(vma, start, end - start, NULL);
96230 +
96231 +#ifdef CONFIG_PAX_SEGMEXEC
96232 + vma_m = pax_find_mirror_vma(vma);
96233 + if (vma_m) {
96234 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
96235 + struct zap_details details = {
96236 + .nonlinear_vma = vma_m,
96237 + .last_index = ULONG_MAX,
96238 + };
96239 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
96240 + } else
96241 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
96242 + }
96243 +#endif
96244 +
96245 return 0;
96246 }
96247
96248 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
96249 if (end < start)
96250 return error;
96251
96252 +#ifdef CONFIG_PAX_SEGMEXEC
96253 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
96254 + if (end > SEGMEXEC_TASK_SIZE)
96255 + return error;
96256 + } else
96257 +#endif
96258 +
96259 + if (end > TASK_SIZE)
96260 + return error;
96261 +
96262 error = 0;
96263 if (end == start)
96264 return error;
96265 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
96266 index 44c6bd2..60369dc3 100644
96267 --- a/mm/memory-failure.c
96268 +++ b/mm/memory-failure.c
96269 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
96270
96271 int sysctl_memory_failure_recovery __read_mostly = 1;
96272
96273 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96274 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96275
96276 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
96277
96278 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
96279 pfn, t->comm, t->pid);
96280 si.si_signo = SIGBUS;
96281 si.si_errno = 0;
96282 - si.si_addr = (void *)addr;
96283 + si.si_addr = (void __user *)addr;
96284 #ifdef __ARCH_SI_TRAPNO
96285 si.si_trapno = trapno;
96286 #endif
96287 @@ -791,7 +791,7 @@ static struct page_state {
96288 unsigned long res;
96289 char *msg;
96290 int (*action)(struct page *p, unsigned long pfn);
96291 -} error_states[] = {
96292 +} __do_const error_states[] = {
96293 { reserved, reserved, "reserved kernel", me_kernel },
96294 /*
96295 * free pages are specially detected outside this table:
96296 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96297 nr_pages = 1 << compound_order(hpage);
96298 else /* normal page or thp */
96299 nr_pages = 1;
96300 - atomic_long_add(nr_pages, &num_poisoned_pages);
96301 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96302
96303 /*
96304 * We need/can do nothing about count=0 pages.
96305 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96306 if (PageHWPoison(hpage)) {
96307 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96308 || (p != hpage && TestSetPageHWPoison(hpage))) {
96309 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96310 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96311 unlock_page(hpage);
96312 return 0;
96313 }
96314 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96315 */
96316 if (!PageHWPoison(p)) {
96317 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96318 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96319 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96320 put_page(hpage);
96321 res = 0;
96322 goto out;
96323 }
96324 if (hwpoison_filter(p)) {
96325 if (TestClearPageHWPoison(p))
96326 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96327 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96328 unlock_page(hpage);
96329 put_page(hpage);
96330 return 0;
96331 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96332 return 0;
96333 }
96334 if (TestClearPageHWPoison(p))
96335 - atomic_long_dec(&num_poisoned_pages);
96336 + atomic_long_dec_unchecked(&num_poisoned_pages);
96337 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96338 return 0;
96339 }
96340 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96341 */
96342 if (TestClearPageHWPoison(page)) {
96343 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96344 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96345 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96346 freeit = 1;
96347 if (PageHuge(page))
96348 clear_page_hwpoison_huge_page(page);
96349 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96350 if (PageHuge(page)) {
96351 set_page_hwpoison_huge_page(hpage);
96352 dequeue_hwpoisoned_huge_page(hpage);
96353 - atomic_long_add(1 << compound_order(hpage),
96354 + atomic_long_add_unchecked(1 << compound_order(hpage),
96355 &num_poisoned_pages);
96356 } else {
96357 SetPageHWPoison(page);
96358 - atomic_long_inc(&num_poisoned_pages);
96359 + atomic_long_inc_unchecked(&num_poisoned_pages);
96360 }
96361 }
96362 return ret;
96363 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96364 put_page(page);
96365 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96366 SetPageHWPoison(page);
96367 - atomic_long_inc(&num_poisoned_pages);
96368 + atomic_long_inc_unchecked(&num_poisoned_pages);
96369 return 0;
96370 }
96371
96372 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96373 if (!is_free_buddy_page(page))
96374 pr_info("soft offline: %#lx: page leaked\n",
96375 pfn);
96376 - atomic_long_inc(&num_poisoned_pages);
96377 + atomic_long_inc_unchecked(&num_poisoned_pages);
96378 }
96379 } else {
96380 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96381 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96382 if (PageHuge(page)) {
96383 set_page_hwpoison_huge_page(hpage);
96384 dequeue_hwpoisoned_huge_page(hpage);
96385 - atomic_long_add(1 << compound_order(hpage),
96386 + atomic_long_add_unchecked(1 << compound_order(hpage),
96387 &num_poisoned_pages);
96388 } else {
96389 SetPageHWPoison(page);
96390 - atomic_long_inc(&num_poisoned_pages);
96391 + atomic_long_inc_unchecked(&num_poisoned_pages);
96392 }
96393 }
96394 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96395 diff --git a/mm/memory.c b/mm/memory.c
96396 index e497def..9cdef79 100644
96397 --- a/mm/memory.c
96398 +++ b/mm/memory.c
96399 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96400 free_pte_range(tlb, pmd, addr);
96401 } while (pmd++, addr = next, addr != end);
96402
96403 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96404 start &= PUD_MASK;
96405 if (start < floor)
96406 return;
96407 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96408 pmd = pmd_offset(pud, start);
96409 pud_clear(pud);
96410 pmd_free_tlb(tlb, pmd, start);
96411 +#endif
96412 +
96413 }
96414
96415 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96416 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96417 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96418 } while (pud++, addr = next, addr != end);
96419
96420 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96421 start &= PGDIR_MASK;
96422 if (start < floor)
96423 return;
96424 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96425 pud = pud_offset(pgd, start);
96426 pgd_clear(pgd);
96427 pud_free_tlb(tlb, pud, start);
96428 +#endif
96429 +
96430 }
96431
96432 /*
96433 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96434 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96435 */
96436 if (vma->vm_ops)
96437 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96438 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96439 vma->vm_ops->fault);
96440 if (vma->vm_file)
96441 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96442 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96443 vma->vm_file->f_op->mmap);
96444 dump_stack();
96445 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96446 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96447 page_add_file_rmap(page);
96448 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96449
96450 +#ifdef CONFIG_PAX_SEGMEXEC
96451 + pax_mirror_file_pte(vma, addr, page, ptl);
96452 +#endif
96453 +
96454 retval = 0;
96455 pte_unmap_unlock(pte, ptl);
96456 return retval;
96457 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96458 if (!page_count(page))
96459 return -EINVAL;
96460 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96461 +
96462 +#ifdef CONFIG_PAX_SEGMEXEC
96463 + struct vm_area_struct *vma_m;
96464 +#endif
96465 +
96466 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96467 BUG_ON(vma->vm_flags & VM_PFNMAP);
96468 vma->vm_flags |= VM_MIXEDMAP;
96469 +
96470 +#ifdef CONFIG_PAX_SEGMEXEC
96471 + vma_m = pax_find_mirror_vma(vma);
96472 + if (vma_m)
96473 + vma_m->vm_flags |= VM_MIXEDMAP;
96474 +#endif
96475 +
96476 }
96477 return insert_page(vma, addr, page, vma->vm_page_prot);
96478 }
96479 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96480 unsigned long pfn)
96481 {
96482 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96483 + BUG_ON(vma->vm_mirror);
96484
96485 if (addr < vma->vm_start || addr >= vma->vm_end)
96486 return -EFAULT;
96487 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96488
96489 BUG_ON(pud_huge(*pud));
96490
96491 - pmd = pmd_alloc(mm, pud, addr);
96492 + pmd = (mm == &init_mm) ?
96493 + pmd_alloc_kernel(mm, pud, addr) :
96494 + pmd_alloc(mm, pud, addr);
96495 if (!pmd)
96496 return -ENOMEM;
96497 do {
96498 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96499 unsigned long next;
96500 int err;
96501
96502 - pud = pud_alloc(mm, pgd, addr);
96503 + pud = (mm == &init_mm) ?
96504 + pud_alloc_kernel(mm, pgd, addr) :
96505 + pud_alloc(mm, pgd, addr);
96506 if (!pud)
96507 return -ENOMEM;
96508 do {
96509 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96510 return ret;
96511 }
96512
96513 +#ifdef CONFIG_PAX_SEGMEXEC
96514 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96515 +{
96516 + struct mm_struct *mm = vma->vm_mm;
96517 + spinlock_t *ptl;
96518 + pte_t *pte, entry;
96519 +
96520 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96521 + entry = *pte;
96522 + if (!pte_present(entry)) {
96523 + if (!pte_none(entry)) {
96524 + BUG_ON(pte_file(entry));
96525 + free_swap_and_cache(pte_to_swp_entry(entry));
96526 + pte_clear_not_present_full(mm, address, pte, 0);
96527 + }
96528 + } else {
96529 + struct page *page;
96530 +
96531 + flush_cache_page(vma, address, pte_pfn(entry));
96532 + entry = ptep_clear_flush(vma, address, pte);
96533 + BUG_ON(pte_dirty(entry));
96534 + page = vm_normal_page(vma, address, entry);
96535 + if (page) {
96536 + update_hiwater_rss(mm);
96537 + if (PageAnon(page))
96538 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96539 + else
96540 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96541 + page_remove_rmap(page);
96542 + page_cache_release(page);
96543 + }
96544 + }
96545 + pte_unmap_unlock(pte, ptl);
96546 +}
96547 +
96548 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96549 + *
96550 + * the ptl of the lower mapped page is held on entry and is not released on exit
96551 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96552 + */
96553 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96554 +{
96555 + struct mm_struct *mm = vma->vm_mm;
96556 + unsigned long address_m;
96557 + spinlock_t *ptl_m;
96558 + struct vm_area_struct *vma_m;
96559 + pmd_t *pmd_m;
96560 + pte_t *pte_m, entry_m;
96561 +
96562 + BUG_ON(!page_m || !PageAnon(page_m));
96563 +
96564 + vma_m = pax_find_mirror_vma(vma);
96565 + if (!vma_m)
96566 + return;
96567 +
96568 + BUG_ON(!PageLocked(page_m));
96569 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96570 + address_m = address + SEGMEXEC_TASK_SIZE;
96571 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96572 + pte_m = pte_offset_map(pmd_m, address_m);
96573 + ptl_m = pte_lockptr(mm, pmd_m);
96574 + if (ptl != ptl_m) {
96575 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96576 + if (!pte_none(*pte_m))
96577 + goto out;
96578 + }
96579 +
96580 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96581 + page_cache_get(page_m);
96582 + page_add_anon_rmap(page_m, vma_m, address_m);
96583 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96584 + set_pte_at(mm, address_m, pte_m, entry_m);
96585 + update_mmu_cache(vma_m, address_m, pte_m);
96586 +out:
96587 + if (ptl != ptl_m)
96588 + spin_unlock(ptl_m);
96589 + pte_unmap(pte_m);
96590 + unlock_page(page_m);
96591 +}
96592 +
96593 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96594 +{
96595 + struct mm_struct *mm = vma->vm_mm;
96596 + unsigned long address_m;
96597 + spinlock_t *ptl_m;
96598 + struct vm_area_struct *vma_m;
96599 + pmd_t *pmd_m;
96600 + pte_t *pte_m, entry_m;
96601 +
96602 + BUG_ON(!page_m || PageAnon(page_m));
96603 +
96604 + vma_m = pax_find_mirror_vma(vma);
96605 + if (!vma_m)
96606 + return;
96607 +
96608 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96609 + address_m = address + SEGMEXEC_TASK_SIZE;
96610 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96611 + pte_m = pte_offset_map(pmd_m, address_m);
96612 + ptl_m = pte_lockptr(mm, pmd_m);
96613 + if (ptl != ptl_m) {
96614 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96615 + if (!pte_none(*pte_m))
96616 + goto out;
96617 + }
96618 +
96619 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96620 + page_cache_get(page_m);
96621 + page_add_file_rmap(page_m);
96622 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96623 + set_pte_at(mm, address_m, pte_m, entry_m);
96624 + update_mmu_cache(vma_m, address_m, pte_m);
96625 +out:
96626 + if (ptl != ptl_m)
96627 + spin_unlock(ptl_m);
96628 + pte_unmap(pte_m);
96629 +}
96630 +
96631 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96632 +{
96633 + struct mm_struct *mm = vma->vm_mm;
96634 + unsigned long address_m;
96635 + spinlock_t *ptl_m;
96636 + struct vm_area_struct *vma_m;
96637 + pmd_t *pmd_m;
96638 + pte_t *pte_m, entry_m;
96639 +
96640 + vma_m = pax_find_mirror_vma(vma);
96641 + if (!vma_m)
96642 + return;
96643 +
96644 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96645 + address_m = address + SEGMEXEC_TASK_SIZE;
96646 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96647 + pte_m = pte_offset_map(pmd_m, address_m);
96648 + ptl_m = pte_lockptr(mm, pmd_m);
96649 + if (ptl != ptl_m) {
96650 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96651 + if (!pte_none(*pte_m))
96652 + goto out;
96653 + }
96654 +
96655 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96656 + set_pte_at(mm, address_m, pte_m, entry_m);
96657 +out:
96658 + if (ptl != ptl_m)
96659 + spin_unlock(ptl_m);
96660 + pte_unmap(pte_m);
96661 +}
96662 +
96663 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96664 +{
96665 + struct page *page_m;
96666 + pte_t entry;
96667 +
96668 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96669 + goto out;
96670 +
96671 + entry = *pte;
96672 + page_m = vm_normal_page(vma, address, entry);
96673 + if (!page_m)
96674 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96675 + else if (PageAnon(page_m)) {
96676 + if (pax_find_mirror_vma(vma)) {
96677 + pte_unmap_unlock(pte, ptl);
96678 + lock_page(page_m);
96679 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96680 + if (pte_same(entry, *pte))
96681 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96682 + else
96683 + unlock_page(page_m);
96684 + }
96685 + } else
96686 + pax_mirror_file_pte(vma, address, page_m, ptl);
96687 +
96688 +out:
96689 + pte_unmap_unlock(pte, ptl);
96690 +}
96691 +#endif
96692 +
96693 /*
96694 * This routine handles present pages, when users try to write
96695 * to a shared page. It is done by copying the page to a new address
96696 @@ -2217,6 +2424,12 @@ gotten:
96697 */
96698 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96699 if (likely(pte_same(*page_table, orig_pte))) {
96700 +
96701 +#ifdef CONFIG_PAX_SEGMEXEC
96702 + if (pax_find_mirror_vma(vma))
96703 + BUG_ON(!trylock_page(new_page));
96704 +#endif
96705 +
96706 if (old_page) {
96707 if (!PageAnon(old_page)) {
96708 dec_mm_counter_fast(mm, MM_FILEPAGES);
96709 @@ -2270,6 +2483,10 @@ gotten:
96710 page_remove_rmap(old_page);
96711 }
96712
96713 +#ifdef CONFIG_PAX_SEGMEXEC
96714 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96715 +#endif
96716 +
96717 /* Free the old page.. */
96718 new_page = old_page;
96719 ret |= VM_FAULT_WRITE;
96720 @@ -2544,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96721 swap_free(entry);
96722 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96723 try_to_free_swap(page);
96724 +
96725 +#ifdef CONFIG_PAX_SEGMEXEC
96726 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96727 +#endif
96728 +
96729 unlock_page(page);
96730 if (page != swapcache) {
96731 /*
96732 @@ -2567,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96733
96734 /* No need to invalidate - it was non-present before */
96735 update_mmu_cache(vma, address, page_table);
96736 +
96737 +#ifdef CONFIG_PAX_SEGMEXEC
96738 + pax_mirror_anon_pte(vma, address, page, ptl);
96739 +#endif
96740 +
96741 unlock:
96742 pte_unmap_unlock(page_table, ptl);
96743 out:
96744 @@ -2586,40 +2813,6 @@ out_release:
96745 }
96746
96747 /*
96748 - * This is like a special single-page "expand_{down|up}wards()",
96749 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96750 - * doesn't hit another vma.
96751 - */
96752 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96753 -{
96754 - address &= PAGE_MASK;
96755 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96756 - struct vm_area_struct *prev = vma->vm_prev;
96757 -
96758 - /*
96759 - * Is there a mapping abutting this one below?
96760 - *
96761 - * That's only ok if it's the same stack mapping
96762 - * that has gotten split..
96763 - */
96764 - if (prev && prev->vm_end == address)
96765 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96766 -
96767 - expand_downwards(vma, address - PAGE_SIZE);
96768 - }
96769 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96770 - struct vm_area_struct *next = vma->vm_next;
96771 -
96772 - /* As VM_GROWSDOWN but s/below/above/ */
96773 - if (next && next->vm_start == address + PAGE_SIZE)
96774 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96775 -
96776 - expand_upwards(vma, address + PAGE_SIZE);
96777 - }
96778 - return 0;
96779 -}
96780 -
96781 -/*
96782 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96783 * but allow concurrent faults), and pte mapped but not yet locked.
96784 * We return with mmap_sem still held, but pte unmapped and unlocked.
96785 @@ -2629,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96786 unsigned int flags)
96787 {
96788 struct mem_cgroup *memcg;
96789 - struct page *page;
96790 + struct page *page = NULL;
96791 spinlock_t *ptl;
96792 pte_t entry;
96793
96794 - pte_unmap(page_table);
96795 -
96796 - /* Check if we need to add a guard page to the stack */
96797 - if (check_stack_guard_page(vma, address) < 0)
96798 - return VM_FAULT_SIGBUS;
96799 -
96800 - /* Use the zero-page for reads */
96801 if (!(flags & FAULT_FLAG_WRITE)) {
96802 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96803 vma->vm_page_prot));
96804 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96805 + ptl = pte_lockptr(mm, pmd);
96806 + spin_lock(ptl);
96807 if (!pte_none(*page_table))
96808 goto unlock;
96809 goto setpte;
96810 }
96811
96812 /* Allocate our own private page. */
96813 + pte_unmap(page_table);
96814 +
96815 if (unlikely(anon_vma_prepare(vma)))
96816 goto oom;
96817 page = alloc_zeroed_user_highpage_movable(vma, address);
96818 @@ -2673,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96819 if (!pte_none(*page_table))
96820 goto release;
96821
96822 +#ifdef CONFIG_PAX_SEGMEXEC
96823 + if (pax_find_mirror_vma(vma))
96824 + BUG_ON(!trylock_page(page));
96825 +#endif
96826 +
96827 inc_mm_counter_fast(mm, MM_ANONPAGES);
96828 page_add_new_anon_rmap(page, vma, address);
96829 mem_cgroup_commit_charge(page, memcg, false);
96830 @@ -2682,6 +2876,12 @@ setpte:
96831
96832 /* No need to invalidate - it was non-present before */
96833 update_mmu_cache(vma, address, page_table);
96834 +
96835 +#ifdef CONFIG_PAX_SEGMEXEC
96836 + if (page)
96837 + pax_mirror_anon_pte(vma, address, page, ptl);
96838 +#endif
96839 +
96840 unlock:
96841 pte_unmap_unlock(page_table, ptl);
96842 return 0;
96843 @@ -2912,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96844 return ret;
96845 }
96846 do_set_pte(vma, address, fault_page, pte, false, false);
96847 +
96848 +#ifdef CONFIG_PAX_SEGMEXEC
96849 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96850 +#endif
96851 +
96852 unlock_page(fault_page);
96853 unlock_out:
96854 pte_unmap_unlock(pte, ptl);
96855 @@ -2954,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96856 page_cache_release(fault_page);
96857 goto uncharge_out;
96858 }
96859 +
96860 +#ifdef CONFIG_PAX_SEGMEXEC
96861 + if (pax_find_mirror_vma(vma))
96862 + BUG_ON(!trylock_page(new_page));
96863 +#endif
96864 +
96865 do_set_pte(vma, address, new_page, pte, true, true);
96866 +
96867 +#ifdef CONFIG_PAX_SEGMEXEC
96868 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96869 +#endif
96870 +
96871 mem_cgroup_commit_charge(new_page, memcg, false);
96872 lru_cache_add_active_or_unevictable(new_page, vma);
96873 pte_unmap_unlock(pte, ptl);
96874 @@ -3004,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96875 return ret;
96876 }
96877 do_set_pte(vma, address, fault_page, pte, true, false);
96878 +
96879 +#ifdef CONFIG_PAX_SEGMEXEC
96880 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96881 +#endif
96882 +
96883 pte_unmap_unlock(pte, ptl);
96884
96885 if (set_page_dirty(fault_page))
96886 @@ -3245,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96887 if (flags & FAULT_FLAG_WRITE)
96888 flush_tlb_fix_spurious_fault(vma, address);
96889 }
96890 +
96891 +#ifdef CONFIG_PAX_SEGMEXEC
96892 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96893 + return 0;
96894 +#endif
96895 +
96896 unlock:
96897 pte_unmap_unlock(pte, ptl);
96898 return 0;
96899 @@ -3264,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96900 pmd_t *pmd;
96901 pte_t *pte;
96902
96903 +#ifdef CONFIG_PAX_SEGMEXEC
96904 + struct vm_area_struct *vma_m;
96905 +#endif
96906 +
96907 if (unlikely(is_vm_hugetlb_page(vma)))
96908 return hugetlb_fault(mm, vma, address, flags);
96909
96910 +#ifdef CONFIG_PAX_SEGMEXEC
96911 + vma_m = pax_find_mirror_vma(vma);
96912 + if (vma_m) {
96913 + unsigned long address_m;
96914 + pgd_t *pgd_m;
96915 + pud_t *pud_m;
96916 + pmd_t *pmd_m;
96917 +
96918 + if (vma->vm_start > vma_m->vm_start) {
96919 + address_m = address;
96920 + address -= SEGMEXEC_TASK_SIZE;
96921 + vma = vma_m;
96922 + } else
96923 + address_m = address + SEGMEXEC_TASK_SIZE;
96924 +
96925 + pgd_m = pgd_offset(mm, address_m);
96926 + pud_m = pud_alloc(mm, pgd_m, address_m);
96927 + if (!pud_m)
96928 + return VM_FAULT_OOM;
96929 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96930 + if (!pmd_m)
96931 + return VM_FAULT_OOM;
96932 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96933 + return VM_FAULT_OOM;
96934 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96935 + }
96936 +#endif
96937 +
96938 pgd = pgd_offset(mm, address);
96939 pud = pud_alloc(mm, pgd, address);
96940 if (!pud)
96941 @@ -3400,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96942 spin_unlock(&mm->page_table_lock);
96943 return 0;
96944 }
96945 +
96946 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96947 +{
96948 + pud_t *new = pud_alloc_one(mm, address);
96949 + if (!new)
96950 + return -ENOMEM;
96951 +
96952 + smp_wmb(); /* See comment in __pte_alloc */
96953 +
96954 + spin_lock(&mm->page_table_lock);
96955 + if (pgd_present(*pgd)) /* Another has populated it */
96956 + pud_free(mm, new);
96957 + else
96958 + pgd_populate_kernel(mm, pgd, new);
96959 + spin_unlock(&mm->page_table_lock);
96960 + return 0;
96961 +}
96962 #endif /* __PAGETABLE_PUD_FOLDED */
96963
96964 #ifndef __PAGETABLE_PMD_FOLDED
96965 @@ -3430,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96966 spin_unlock(&mm->page_table_lock);
96967 return 0;
96968 }
96969 +
96970 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96971 +{
96972 + pmd_t *new = pmd_alloc_one(mm, address);
96973 + if (!new)
96974 + return -ENOMEM;
96975 +
96976 + smp_wmb(); /* See comment in __pte_alloc */
96977 +
96978 + spin_lock(&mm->page_table_lock);
96979 +#ifndef __ARCH_HAS_4LEVEL_HACK
96980 + if (pud_present(*pud)) /* Another has populated it */
96981 + pmd_free(mm, new);
96982 + else
96983 + pud_populate_kernel(mm, pud, new);
96984 +#else
96985 + if (pgd_present(*pud)) /* Another has populated it */
96986 + pmd_free(mm, new);
96987 + else
96988 + pgd_populate_kernel(mm, pud, new);
96989 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96990 + spin_unlock(&mm->page_table_lock);
96991 + return 0;
96992 +}
96993 #endif /* __PAGETABLE_PMD_FOLDED */
96994
96995 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96996 @@ -3539,8 +3839,8 @@ out:
96997 return ret;
96998 }
96999
97000 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
97001 - void *buf, int len, int write)
97002 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
97003 + void *buf, size_t len, int write)
97004 {
97005 resource_size_t phys_addr;
97006 unsigned long prot = 0;
97007 @@ -3566,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
97008 * Access another process' address space as given in mm. If non-NULL, use the
97009 * given task for page fault accounting.
97010 */
97011 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97012 - unsigned long addr, void *buf, int len, int write)
97013 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97014 + unsigned long addr, void *buf, size_t len, int write)
97015 {
97016 struct vm_area_struct *vma;
97017 void *old_buf = buf;
97018 @@ -3575,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97019 down_read(&mm->mmap_sem);
97020 /* ignore errors, just check how much was successfully transferred */
97021 while (len) {
97022 - int bytes, ret, offset;
97023 + ssize_t bytes, ret, offset;
97024 void *maddr;
97025 struct page *page = NULL;
97026
97027 @@ -3636,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97028 *
97029 * The caller must hold a reference on @mm.
97030 */
97031 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97032 - void *buf, int len, int write)
97033 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
97034 + void *buf, size_t len, int write)
97035 {
97036 return __access_remote_vm(NULL, mm, addr, buf, len, write);
97037 }
97038 @@ -3647,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97039 * Source/target buffer must be kernel space,
97040 * Do not walk the page table directly, use get_user_pages
97041 */
97042 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
97043 - void *buf, int len, int write)
97044 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
97045 + void *buf, size_t len, int write)
97046 {
97047 struct mm_struct *mm;
97048 - int ret;
97049 + ssize_t ret;
97050
97051 mm = get_task_mm(tsk);
97052 if (!mm)
97053 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
97054 index 8f5330d..b41914b 100644
97055 --- a/mm/mempolicy.c
97056 +++ b/mm/mempolicy.c
97057 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
97058 unsigned long vmstart;
97059 unsigned long vmend;
97060
97061 +#ifdef CONFIG_PAX_SEGMEXEC
97062 + struct vm_area_struct *vma_m;
97063 +#endif
97064 +
97065 vma = find_vma(mm, start);
97066 if (!vma || vma->vm_start > start)
97067 return -EFAULT;
97068 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
97069 err = vma_replace_policy(vma, new_pol);
97070 if (err)
97071 goto out;
97072 +
97073 +#ifdef CONFIG_PAX_SEGMEXEC
97074 + vma_m = pax_find_mirror_vma(vma);
97075 + if (vma_m) {
97076 + err = vma_replace_policy(vma_m, new_pol);
97077 + if (err)
97078 + goto out;
97079 + }
97080 +#endif
97081 +
97082 }
97083
97084 out:
97085 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
97086
97087 if (end < start)
97088 return -EINVAL;
97089 +
97090 +#ifdef CONFIG_PAX_SEGMEXEC
97091 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97092 + if (end > SEGMEXEC_TASK_SIZE)
97093 + return -EINVAL;
97094 + } else
97095 +#endif
97096 +
97097 + if (end > TASK_SIZE)
97098 + return -EINVAL;
97099 +
97100 if (end == start)
97101 return 0;
97102
97103 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97104 */
97105 tcred = __task_cred(task);
97106 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97107 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97108 - !capable(CAP_SYS_NICE)) {
97109 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97110 rcu_read_unlock();
97111 err = -EPERM;
97112 goto out_put;
97113 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97114 goto out;
97115 }
97116
97117 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97118 + if (mm != current->mm &&
97119 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
97120 + mmput(mm);
97121 + err = -EPERM;
97122 + goto out;
97123 + }
97124 +#endif
97125 +
97126 err = do_migrate_pages(mm, old, new,
97127 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
97128
97129 diff --git a/mm/migrate.c b/mm/migrate.c
97130 index 0143995..b294728 100644
97131 --- a/mm/migrate.c
97132 +++ b/mm/migrate.c
97133 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
97134 */
97135 tcred = __task_cred(task);
97136 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97137 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97138 - !capable(CAP_SYS_NICE)) {
97139 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97140 rcu_read_unlock();
97141 err = -EPERM;
97142 goto out;
97143 diff --git a/mm/mlock.c b/mm/mlock.c
97144 index ce84cb0..6d5a9aa 100644
97145 --- a/mm/mlock.c
97146 +++ b/mm/mlock.c
97147 @@ -14,6 +14,7 @@
97148 #include <linux/pagevec.h>
97149 #include <linux/mempolicy.h>
97150 #include <linux/syscalls.h>
97151 +#include <linux/security.h>
97152 #include <linux/sched.h>
97153 #include <linux/export.h>
97154 #include <linux/rmap.h>
97155 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
97156 {
97157 unsigned long nstart, end, tmp;
97158 struct vm_area_struct * vma, * prev;
97159 - int error;
97160 + int error = 0;
97161
97162 VM_BUG_ON(start & ~PAGE_MASK);
97163 VM_BUG_ON(len != PAGE_ALIGN(len));
97164 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
97165 return -EINVAL;
97166 if (end == start)
97167 return 0;
97168 + if (end > TASK_SIZE)
97169 + return -EINVAL;
97170 +
97171 vma = find_vma(current->mm, start);
97172 if (!vma || vma->vm_start > start)
97173 return -ENOMEM;
97174 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
97175 for (nstart = start ; ; ) {
97176 vm_flags_t newflags;
97177
97178 +#ifdef CONFIG_PAX_SEGMEXEC
97179 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97180 + break;
97181 +#endif
97182 +
97183 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
97184
97185 newflags = vma->vm_flags & ~VM_LOCKED;
97186 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
97187 locked += current->mm->locked_vm;
97188
97189 /* check against resource limits */
97190 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
97191 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
97192 error = do_mlock(start, len, 1);
97193
97194 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
97195 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
97196 vm_flags_t newflags;
97197
97198 +#ifdef CONFIG_PAX_SEGMEXEC
97199 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97200 + break;
97201 +#endif
97202 +
97203 newflags = vma->vm_flags & ~VM_LOCKED;
97204 if (flags & MCL_CURRENT)
97205 newflags |= VM_LOCKED;
97206 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
97207 lock_limit >>= PAGE_SHIFT;
97208
97209 ret = -ENOMEM;
97210 +
97211 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
97212 +
97213 down_write(&current->mm->mmap_sem);
97214 -
97215 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
97216 capable(CAP_IPC_LOCK))
97217 ret = do_mlockall(flags);
97218 diff --git a/mm/mmap.c b/mm/mmap.c
97219 index a226d31..9135e65 100644
97220 --- a/mm/mmap.c
97221 +++ b/mm/mmap.c
97222 @@ -41,6 +41,7 @@
97223 #include <linux/notifier.h>
97224 #include <linux/memory.h>
97225 #include <linux/printk.h>
97226 +#include <linux/random.h>
97227
97228 #include <asm/uaccess.h>
97229 #include <asm/cacheflush.h>
97230 @@ -57,6 +58,16 @@
97231 #define arch_rebalance_pgtables(addr, len) (addr)
97232 #endif
97233
97234 +static inline void verify_mm_writelocked(struct mm_struct *mm)
97235 +{
97236 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
97237 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97238 + up_read(&mm->mmap_sem);
97239 + BUG();
97240 + }
97241 +#endif
97242 +}
97243 +
97244 static void unmap_region(struct mm_struct *mm,
97245 struct vm_area_struct *vma, struct vm_area_struct *prev,
97246 unsigned long start, unsigned long end);
97247 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
97248 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
97249 *
97250 */
97251 -pgprot_t protection_map[16] = {
97252 +pgprot_t protection_map[16] __read_only = {
97253 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
97254 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
97255 };
97256
97257 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
97258 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
97259 {
97260 - return __pgprot(pgprot_val(protection_map[vm_flags &
97261 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
97262 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
97263 pgprot_val(arch_vm_get_page_prot(vm_flags)));
97264 +
97265 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97266 + if (!(__supported_pte_mask & _PAGE_NX) &&
97267 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
97268 + (vm_flags & (VM_READ | VM_WRITE)))
97269 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
97270 +#endif
97271 +
97272 + return prot;
97273 }
97274 EXPORT_SYMBOL(vm_get_page_prot);
97275
97276 @@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
97277 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
97278 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97279 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97280 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
97281 /*
97282 * Make sure vm_committed_as in one cacheline and not cacheline shared with
97283 * other variables. It can be updated by several CPUs frequently.
97284 @@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97285 struct vm_area_struct *next = vma->vm_next;
97286
97287 might_sleep();
97288 + BUG_ON(vma->vm_mirror);
97289 if (vma->vm_ops && vma->vm_ops->close)
97290 vma->vm_ops->close(vma);
97291 if (vma->vm_file)
97292 @@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97293 * not page aligned -Ram Gupta
97294 */
97295 rlim = rlimit(RLIMIT_DATA);
97296 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97297 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97298 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97299 + rlim = 4096 * PAGE_SIZE;
97300 +#endif
97301 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
97302 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
97303 (mm->end_data - mm->start_data) > rlim)
97304 goto out;
97305 @@ -952,6 +980,12 @@ static int
97306 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97307 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97308 {
97309 +
97310 +#ifdef CONFIG_PAX_SEGMEXEC
97311 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97312 + return 0;
97313 +#endif
97314 +
97315 if (is_mergeable_vma(vma, file, vm_flags) &&
97316 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97317 if (vma->vm_pgoff == vm_pgoff)
97318 @@ -971,6 +1005,12 @@ static int
97319 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97320 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97321 {
97322 +
97323 +#ifdef CONFIG_PAX_SEGMEXEC
97324 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97325 + return 0;
97326 +#endif
97327 +
97328 if (is_mergeable_vma(vma, file, vm_flags) &&
97329 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97330 pgoff_t vm_pglen;
97331 @@ -1013,13 +1053,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97332 struct vm_area_struct *vma_merge(struct mm_struct *mm,
97333 struct vm_area_struct *prev, unsigned long addr,
97334 unsigned long end, unsigned long vm_flags,
97335 - struct anon_vma *anon_vma, struct file *file,
97336 + struct anon_vma *anon_vma, struct file *file,
97337 pgoff_t pgoff, struct mempolicy *policy)
97338 {
97339 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
97340 struct vm_area_struct *area, *next;
97341 int err;
97342
97343 +#ifdef CONFIG_PAX_SEGMEXEC
97344 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97345 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97346 +
97347 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97348 +#endif
97349 +
97350 /*
97351 * We later require that vma->vm_flags == vm_flags,
97352 * so this tests vma->vm_flags & VM_SPECIAL, too.
97353 @@ -1035,6 +1082,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97354 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97355 next = next->vm_next;
97356
97357 +#ifdef CONFIG_PAX_SEGMEXEC
97358 + if (prev)
97359 + prev_m = pax_find_mirror_vma(prev);
97360 + if (area)
97361 + area_m = pax_find_mirror_vma(area);
97362 + if (next)
97363 + next_m = pax_find_mirror_vma(next);
97364 +#endif
97365 +
97366 /*
97367 * Can it merge with the predecessor?
97368 */
97369 @@ -1054,9 +1110,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97370 /* cases 1, 6 */
97371 err = vma_adjust(prev, prev->vm_start,
97372 next->vm_end, prev->vm_pgoff, NULL);
97373 - } else /* cases 2, 5, 7 */
97374 +
97375 +#ifdef CONFIG_PAX_SEGMEXEC
97376 + if (!err && prev_m)
97377 + err = vma_adjust(prev_m, prev_m->vm_start,
97378 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97379 +#endif
97380 +
97381 + } else { /* cases 2, 5, 7 */
97382 err = vma_adjust(prev, prev->vm_start,
97383 end, prev->vm_pgoff, NULL);
97384 +
97385 +#ifdef CONFIG_PAX_SEGMEXEC
97386 + if (!err && prev_m)
97387 + err = vma_adjust(prev_m, prev_m->vm_start,
97388 + end_m, prev_m->vm_pgoff, NULL);
97389 +#endif
97390 +
97391 + }
97392 if (err)
97393 return NULL;
97394 khugepaged_enter_vma_merge(prev, vm_flags);
97395 @@ -1070,12 +1141,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97396 mpol_equal(policy, vma_policy(next)) &&
97397 can_vma_merge_before(next, vm_flags,
97398 anon_vma, file, pgoff+pglen)) {
97399 - if (prev && addr < prev->vm_end) /* case 4 */
97400 + if (prev && addr < prev->vm_end) { /* case 4 */
97401 err = vma_adjust(prev, prev->vm_start,
97402 addr, prev->vm_pgoff, NULL);
97403 - else /* cases 3, 8 */
97404 +
97405 +#ifdef CONFIG_PAX_SEGMEXEC
97406 + if (!err && prev_m)
97407 + err = vma_adjust(prev_m, prev_m->vm_start,
97408 + addr_m, prev_m->vm_pgoff, NULL);
97409 +#endif
97410 +
97411 + } else { /* cases 3, 8 */
97412 err = vma_adjust(area, addr, next->vm_end,
97413 next->vm_pgoff - pglen, NULL);
97414 +
97415 +#ifdef CONFIG_PAX_SEGMEXEC
97416 + if (!err && area_m)
97417 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97418 + next_m->vm_pgoff - pglen, NULL);
97419 +#endif
97420 +
97421 + }
97422 if (err)
97423 return NULL;
97424 khugepaged_enter_vma_merge(area, vm_flags);
97425 @@ -1184,8 +1270,10 @@ none:
97426 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97427 struct file *file, long pages)
97428 {
97429 - const unsigned long stack_flags
97430 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97431 +
97432 +#ifdef CONFIG_PAX_RANDMMAP
97433 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97434 +#endif
97435
97436 mm->total_vm += pages;
97437
97438 @@ -1193,7 +1281,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97439 mm->shared_vm += pages;
97440 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97441 mm->exec_vm += pages;
97442 - } else if (flags & stack_flags)
97443 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97444 mm->stack_vm += pages;
97445 }
97446 #endif /* CONFIG_PROC_FS */
97447 @@ -1223,6 +1311,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97448 locked += mm->locked_vm;
97449 lock_limit = rlimit(RLIMIT_MEMLOCK);
97450 lock_limit >>= PAGE_SHIFT;
97451 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97452 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97453 return -EAGAIN;
97454 }
97455 @@ -1249,7 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97456 * (the exception is when the underlying filesystem is noexec
97457 * mounted, in which case we dont add PROT_EXEC.)
97458 */
97459 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97460 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97461 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97462 prot |= PROT_EXEC;
97463
97464 @@ -1275,7 +1364,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97465 /* Obtain the address to map to. we verify (or select) it and ensure
97466 * that it represents a valid section of the address space.
97467 */
97468 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97469 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97470 if (addr & ~PAGE_MASK)
97471 return addr;
97472
97473 @@ -1286,6 +1375,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97474 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97475 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97476
97477 +#ifdef CONFIG_PAX_MPROTECT
97478 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97479 +
97480 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97481 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97482 + mm->binfmt->handle_mmap)
97483 + mm->binfmt->handle_mmap(file);
97484 +#endif
97485 +
97486 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97487 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97488 + gr_log_rwxmmap(file);
97489 +
97490 +#ifdef CONFIG_PAX_EMUPLT
97491 + vm_flags &= ~VM_EXEC;
97492 +#else
97493 + return -EPERM;
97494 +#endif
97495 +
97496 + }
97497 +
97498 + if (!(vm_flags & VM_EXEC))
97499 + vm_flags &= ~VM_MAYEXEC;
97500 +#else
97501 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97502 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97503 +#endif
97504 + else
97505 + vm_flags &= ~VM_MAYWRITE;
97506 + }
97507 +#endif
97508 +
97509 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97510 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97511 + vm_flags &= ~VM_PAGEEXEC;
97512 +#endif
97513 +
97514 if (flags & MAP_LOCKED)
97515 if (!can_do_mlock())
97516 return -EPERM;
97517 @@ -1373,6 +1499,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97518 vm_flags |= VM_NORESERVE;
97519 }
97520
97521 + if (!gr_acl_handle_mmap(file, prot))
97522 + return -EACCES;
97523 +
97524 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97525 if (!IS_ERR_VALUE(addr) &&
97526 ((vm_flags & VM_LOCKED) ||
97527 @@ -1466,7 +1595,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97528 vm_flags_t vm_flags = vma->vm_flags;
97529
97530 /* If it was private or non-writable, the write bit is already clear */
97531 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97532 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97533 return 0;
97534
97535 /* The backer wishes to know when pages are first written to? */
97536 @@ -1512,7 +1641,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97537 struct rb_node **rb_link, *rb_parent;
97538 unsigned long charged = 0;
97539
97540 +#ifdef CONFIG_PAX_SEGMEXEC
97541 + struct vm_area_struct *vma_m = NULL;
97542 +#endif
97543 +
97544 + /*
97545 + * mm->mmap_sem is required to protect against another thread
97546 + * changing the mappings in case we sleep.
97547 + */
97548 + verify_mm_writelocked(mm);
97549 +
97550 /* Check against address space limit. */
97551 +
97552 +#ifdef CONFIG_PAX_RANDMMAP
97553 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97554 +#endif
97555 +
97556 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97557 unsigned long nr_pages;
97558
97559 @@ -1531,11 +1675,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97560
97561 /* Clear old maps */
97562 error = -ENOMEM;
97563 -munmap_back:
97564 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97565 if (do_munmap(mm, addr, len))
97566 return -ENOMEM;
97567 - goto munmap_back;
97568 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97569 }
97570
97571 /*
97572 @@ -1566,6 +1709,16 @@ munmap_back:
97573 goto unacct_error;
97574 }
97575
97576 +#ifdef CONFIG_PAX_SEGMEXEC
97577 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97578 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97579 + if (!vma_m) {
97580 + error = -ENOMEM;
97581 + goto free_vma;
97582 + }
97583 + }
97584 +#endif
97585 +
97586 vma->vm_mm = mm;
97587 vma->vm_start = addr;
97588 vma->vm_end = addr + len;
97589 @@ -1596,6 +1749,13 @@ munmap_back:
97590 if (error)
97591 goto unmap_and_free_vma;
97592
97593 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97594 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97595 + vma->vm_flags |= VM_PAGEEXEC;
97596 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97597 + }
97598 +#endif
97599 +
97600 /* Can addr have changed??
97601 *
97602 * Answer: Yes, several device drivers can do it in their
97603 @@ -1629,6 +1789,12 @@ munmap_back:
97604 }
97605
97606 vma_link(mm, vma, prev, rb_link, rb_parent);
97607 +
97608 +#ifdef CONFIG_PAX_SEGMEXEC
97609 + if (vma_m)
97610 + BUG_ON(pax_mirror_vma(vma_m, vma));
97611 +#endif
97612 +
97613 /* Once vma denies write, undo our temporary denial count */
97614 if (file) {
97615 if (vm_flags & VM_SHARED)
97616 @@ -1641,6 +1807,7 @@ out:
97617 perf_event_mmap(vma);
97618
97619 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97620 + track_exec_limit(mm, addr, addr + len, vm_flags);
97621 if (vm_flags & VM_LOCKED) {
97622 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97623 vma == get_gate_vma(current->mm)))
97624 @@ -1676,6 +1843,12 @@ allow_write_and_free_vma:
97625 if (vm_flags & VM_DENYWRITE)
97626 allow_write_access(file);
97627 free_vma:
97628 +
97629 +#ifdef CONFIG_PAX_SEGMEXEC
97630 + if (vma_m)
97631 + kmem_cache_free(vm_area_cachep, vma_m);
97632 +#endif
97633 +
97634 kmem_cache_free(vm_area_cachep, vma);
97635 unacct_error:
97636 if (charged)
97637 @@ -1683,7 +1856,63 @@ unacct_error:
97638 return error;
97639 }
97640
97641 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97642 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97643 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97644 +{
97645 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97646 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97647 +
97648 + return 0;
97649 +}
97650 +#endif
97651 +
97652 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97653 +{
97654 + if (!vma) {
97655 +#ifdef CONFIG_STACK_GROWSUP
97656 + if (addr > sysctl_heap_stack_gap)
97657 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97658 + else
97659 + vma = find_vma(current->mm, 0);
97660 + if (vma && (vma->vm_flags & VM_GROWSUP))
97661 + return false;
97662 +#endif
97663 + return true;
97664 + }
97665 +
97666 + if (addr + len > vma->vm_start)
97667 + return false;
97668 +
97669 + if (vma->vm_flags & VM_GROWSDOWN)
97670 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97671 +#ifdef CONFIG_STACK_GROWSUP
97672 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97673 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97674 +#endif
97675 + else if (offset)
97676 + return offset <= vma->vm_start - addr - len;
97677 +
97678 + return true;
97679 +}
97680 +
97681 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97682 +{
97683 + if (vma->vm_start < len)
97684 + return -ENOMEM;
97685 +
97686 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97687 + if (offset <= vma->vm_start - len)
97688 + return vma->vm_start - len - offset;
97689 + else
97690 + return -ENOMEM;
97691 + }
97692 +
97693 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97694 + return vma->vm_start - len - sysctl_heap_stack_gap;
97695 + return -ENOMEM;
97696 +}
97697 +
97698 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97699 {
97700 /*
97701 * We implement the search by looking for an rbtree node that
97702 @@ -1731,11 +1960,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97703 }
97704 }
97705
97706 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97707 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97708 check_current:
97709 /* Check if current node has a suitable gap */
97710 if (gap_start > high_limit)
97711 return -ENOMEM;
97712 +
97713 + if (gap_end - gap_start > info->threadstack_offset)
97714 + gap_start += info->threadstack_offset;
97715 + else
97716 + gap_start = gap_end;
97717 +
97718 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97719 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97720 + gap_start += sysctl_heap_stack_gap;
97721 + else
97722 + gap_start = gap_end;
97723 + }
97724 + if (vma->vm_flags & VM_GROWSDOWN) {
97725 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97726 + gap_end -= sysctl_heap_stack_gap;
97727 + else
97728 + gap_end = gap_start;
97729 + }
97730 if (gap_end >= low_limit && gap_end - gap_start >= length)
97731 goto found;
97732
97733 @@ -1785,7 +2032,7 @@ found:
97734 return gap_start;
97735 }
97736
97737 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97738 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97739 {
97740 struct mm_struct *mm = current->mm;
97741 struct vm_area_struct *vma;
97742 @@ -1839,6 +2086,24 @@ check_current:
97743 gap_end = vma->vm_start;
97744 if (gap_end < low_limit)
97745 return -ENOMEM;
97746 +
97747 + if (gap_end - gap_start > info->threadstack_offset)
97748 + gap_end -= info->threadstack_offset;
97749 + else
97750 + gap_end = gap_start;
97751 +
97752 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97753 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97754 + gap_start += sysctl_heap_stack_gap;
97755 + else
97756 + gap_start = gap_end;
97757 + }
97758 + if (vma->vm_flags & VM_GROWSDOWN) {
97759 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97760 + gap_end -= sysctl_heap_stack_gap;
97761 + else
97762 + gap_end = gap_start;
97763 + }
97764 if (gap_start <= high_limit && gap_end - gap_start >= length)
97765 goto found;
97766
97767 @@ -1902,6 +2167,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97768 struct mm_struct *mm = current->mm;
97769 struct vm_area_struct *vma;
97770 struct vm_unmapped_area_info info;
97771 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97772
97773 if (len > TASK_SIZE - mmap_min_addr)
97774 return -ENOMEM;
97775 @@ -1909,11 +2175,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97776 if (flags & MAP_FIXED)
97777 return addr;
97778
97779 +#ifdef CONFIG_PAX_RANDMMAP
97780 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97781 +#endif
97782 +
97783 if (addr) {
97784 addr = PAGE_ALIGN(addr);
97785 vma = find_vma(mm, addr);
97786 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97787 - (!vma || addr + len <= vma->vm_start))
97788 + check_heap_stack_gap(vma, addr, len, offset))
97789 return addr;
97790 }
97791
97792 @@ -1922,6 +2192,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97793 info.low_limit = mm->mmap_base;
97794 info.high_limit = TASK_SIZE;
97795 info.align_mask = 0;
97796 + info.threadstack_offset = offset;
97797 return vm_unmapped_area(&info);
97798 }
97799 #endif
97800 @@ -1940,6 +2211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97801 struct mm_struct *mm = current->mm;
97802 unsigned long addr = addr0;
97803 struct vm_unmapped_area_info info;
97804 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97805
97806 /* requested length too big for entire address space */
97807 if (len > TASK_SIZE - mmap_min_addr)
97808 @@ -1948,12 +2220,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97809 if (flags & MAP_FIXED)
97810 return addr;
97811
97812 +#ifdef CONFIG_PAX_RANDMMAP
97813 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97814 +#endif
97815 +
97816 /* requesting a specific address */
97817 if (addr) {
97818 addr = PAGE_ALIGN(addr);
97819 vma = find_vma(mm, addr);
97820 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97821 - (!vma || addr + len <= vma->vm_start))
97822 + check_heap_stack_gap(vma, addr, len, offset))
97823 return addr;
97824 }
97825
97826 @@ -1962,6 +2238,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97827 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97828 info.high_limit = mm->mmap_base;
97829 info.align_mask = 0;
97830 + info.threadstack_offset = offset;
97831 addr = vm_unmapped_area(&info);
97832
97833 /*
97834 @@ -1974,6 +2251,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97835 VM_BUG_ON(addr != -ENOMEM);
97836 info.flags = 0;
97837 info.low_limit = TASK_UNMAPPED_BASE;
97838 +
97839 +#ifdef CONFIG_PAX_RANDMMAP
97840 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97841 + info.low_limit += mm->delta_mmap;
97842 +#endif
97843 +
97844 info.high_limit = TASK_SIZE;
97845 addr = vm_unmapped_area(&info);
97846 }
97847 @@ -2074,6 +2357,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97848 return vma;
97849 }
97850
97851 +#ifdef CONFIG_PAX_SEGMEXEC
97852 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97853 +{
97854 + struct vm_area_struct *vma_m;
97855 +
97856 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97857 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97858 + BUG_ON(vma->vm_mirror);
97859 + return NULL;
97860 + }
97861 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97862 + vma_m = vma->vm_mirror;
97863 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97864 + BUG_ON(vma->vm_file != vma_m->vm_file);
97865 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97866 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97867 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97868 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97869 + return vma_m;
97870 +}
97871 +#endif
97872 +
97873 /*
97874 * Verify that the stack growth is acceptable and
97875 * update accounting. This is shared with both the
97876 @@ -2090,6 +2395,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97877 return -ENOMEM;
97878
97879 /* Stack limit test */
97880 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
97881 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97882 return -ENOMEM;
97883
97884 @@ -2100,6 +2406,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97885 locked = mm->locked_vm + grow;
97886 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97887 limit >>= PAGE_SHIFT;
97888 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97889 if (locked > limit && !capable(CAP_IPC_LOCK))
97890 return -ENOMEM;
97891 }
97892 @@ -2129,37 +2436,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97893 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97894 * vma is the last one with address > vma->vm_end. Have to extend vma.
97895 */
97896 +#ifndef CONFIG_IA64
97897 +static
97898 +#endif
97899 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97900 {
97901 int error;
97902 + bool locknext;
97903
97904 if (!(vma->vm_flags & VM_GROWSUP))
97905 return -EFAULT;
97906
97907 + /* Also guard against wrapping around to address 0. */
97908 + if (address < PAGE_ALIGN(address+1))
97909 + address = PAGE_ALIGN(address+1);
97910 + else
97911 + return -ENOMEM;
97912 +
97913 /*
97914 * We must make sure the anon_vma is allocated
97915 * so that the anon_vma locking is not a noop.
97916 */
97917 if (unlikely(anon_vma_prepare(vma)))
97918 return -ENOMEM;
97919 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97920 + if (locknext && anon_vma_prepare(vma->vm_next))
97921 + return -ENOMEM;
97922 vma_lock_anon_vma(vma);
97923 + if (locknext)
97924 + vma_lock_anon_vma(vma->vm_next);
97925
97926 /*
97927 * vma->vm_start/vm_end cannot change under us because the caller
97928 * is required to hold the mmap_sem in read mode. We need the
97929 - * anon_vma lock to serialize against concurrent expand_stacks.
97930 - * Also guard against wrapping around to address 0.
97931 + * anon_vma locks to serialize against concurrent expand_stacks
97932 + * and expand_upwards.
97933 */
97934 - if (address < PAGE_ALIGN(address+4))
97935 - address = PAGE_ALIGN(address+4);
97936 - else {
97937 - vma_unlock_anon_vma(vma);
97938 - return -ENOMEM;
97939 - }
97940 error = 0;
97941
97942 /* Somebody else might have raced and expanded it already */
97943 - if (address > vma->vm_end) {
97944 + 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)
97945 + error = -ENOMEM;
97946 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97947 unsigned long size, grow;
97948
97949 size = address - vma->vm_start;
97950 @@ -2194,6 +2512,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97951 }
97952 }
97953 }
97954 + if (locknext)
97955 + vma_unlock_anon_vma(vma->vm_next);
97956 vma_unlock_anon_vma(vma);
97957 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97958 validate_mm(vma->vm_mm);
97959 @@ -2208,6 +2528,8 @@ int expand_downwards(struct vm_area_struct *vma,
97960 unsigned long address)
97961 {
97962 int error;
97963 + bool lockprev = false;
97964 + struct vm_area_struct *prev;
97965
97966 /*
97967 * We must make sure the anon_vma is allocated
97968 @@ -2221,6 +2543,15 @@ int expand_downwards(struct vm_area_struct *vma,
97969 if (error)
97970 return error;
97971
97972 + prev = vma->vm_prev;
97973 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97974 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97975 +#endif
97976 + if (lockprev && anon_vma_prepare(prev))
97977 + return -ENOMEM;
97978 + if (lockprev)
97979 + vma_lock_anon_vma(prev);
97980 +
97981 vma_lock_anon_vma(vma);
97982
97983 /*
97984 @@ -2230,9 +2561,17 @@ int expand_downwards(struct vm_area_struct *vma,
97985 */
97986
97987 /* Somebody else might have raced and expanded it already */
97988 - if (address < vma->vm_start) {
97989 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97990 + error = -ENOMEM;
97991 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97992 unsigned long size, grow;
97993
97994 +#ifdef CONFIG_PAX_SEGMEXEC
97995 + struct vm_area_struct *vma_m;
97996 +
97997 + vma_m = pax_find_mirror_vma(vma);
97998 +#endif
97999 +
98000 size = vma->vm_end - address;
98001 grow = (vma->vm_start - address) >> PAGE_SHIFT;
98002
98003 @@ -2257,13 +2596,27 @@ int expand_downwards(struct vm_area_struct *vma,
98004 vma->vm_pgoff -= grow;
98005 anon_vma_interval_tree_post_update_vma(vma);
98006 vma_gap_update(vma);
98007 +
98008 +#ifdef CONFIG_PAX_SEGMEXEC
98009 + if (vma_m) {
98010 + anon_vma_interval_tree_pre_update_vma(vma_m);
98011 + vma_m->vm_start -= grow << PAGE_SHIFT;
98012 + vma_m->vm_pgoff -= grow;
98013 + anon_vma_interval_tree_post_update_vma(vma_m);
98014 + vma_gap_update(vma_m);
98015 + }
98016 +#endif
98017 +
98018 spin_unlock(&vma->vm_mm->page_table_lock);
98019
98020 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
98021 perf_event_mmap(vma);
98022 }
98023 }
98024 }
98025 vma_unlock_anon_vma(vma);
98026 + if (lockprev)
98027 + vma_unlock_anon_vma(prev);
98028 khugepaged_enter_vma_merge(vma, vma->vm_flags);
98029 validate_mm(vma->vm_mm);
98030 return error;
98031 @@ -2361,6 +2714,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
98032 do {
98033 long nrpages = vma_pages(vma);
98034
98035 +#ifdef CONFIG_PAX_SEGMEXEC
98036 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
98037 + vma = remove_vma(vma);
98038 + continue;
98039 + }
98040 +#endif
98041 +
98042 if (vma->vm_flags & VM_ACCOUNT)
98043 nr_accounted += nrpages;
98044 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
98045 @@ -2405,6 +2765,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
98046 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
98047 vma->vm_prev = NULL;
98048 do {
98049 +
98050 +#ifdef CONFIG_PAX_SEGMEXEC
98051 + if (vma->vm_mirror) {
98052 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
98053 + vma->vm_mirror->vm_mirror = NULL;
98054 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
98055 + vma->vm_mirror = NULL;
98056 + }
98057 +#endif
98058 +
98059 vma_rb_erase(vma, &mm->mm_rb);
98060 mm->map_count--;
98061 tail_vma = vma;
98062 @@ -2432,14 +2802,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98063 struct vm_area_struct *new;
98064 int err = -ENOMEM;
98065
98066 +#ifdef CONFIG_PAX_SEGMEXEC
98067 + struct vm_area_struct *vma_m, *new_m = NULL;
98068 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
98069 +#endif
98070 +
98071 if (is_vm_hugetlb_page(vma) && (addr &
98072 ~(huge_page_mask(hstate_vma(vma)))))
98073 return -EINVAL;
98074
98075 +#ifdef CONFIG_PAX_SEGMEXEC
98076 + vma_m = pax_find_mirror_vma(vma);
98077 +#endif
98078 +
98079 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
98080 if (!new)
98081 goto out_err;
98082
98083 +#ifdef CONFIG_PAX_SEGMEXEC
98084 + if (vma_m) {
98085 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
98086 + if (!new_m) {
98087 + kmem_cache_free(vm_area_cachep, new);
98088 + goto out_err;
98089 + }
98090 + }
98091 +#endif
98092 +
98093 /* most fields are the same, copy all, and then fixup */
98094 *new = *vma;
98095
98096 @@ -2452,6 +2841,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98097 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
98098 }
98099
98100 +#ifdef CONFIG_PAX_SEGMEXEC
98101 + if (vma_m) {
98102 + *new_m = *vma_m;
98103 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
98104 + new_m->vm_mirror = new;
98105 + new->vm_mirror = new_m;
98106 +
98107 + if (new_below)
98108 + new_m->vm_end = addr_m;
98109 + else {
98110 + new_m->vm_start = addr_m;
98111 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
98112 + }
98113 + }
98114 +#endif
98115 +
98116 err = vma_dup_policy(vma, new);
98117 if (err)
98118 goto out_free_vma;
98119 @@ -2472,6 +2877,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98120 else
98121 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
98122
98123 +#ifdef CONFIG_PAX_SEGMEXEC
98124 + if (!err && vma_m) {
98125 + struct mempolicy *pol = vma_policy(new);
98126 +
98127 + if (anon_vma_clone(new_m, vma_m))
98128 + goto out_free_mpol;
98129 +
98130 + mpol_get(pol);
98131 + set_vma_policy(new_m, pol);
98132 +
98133 + if (new_m->vm_file)
98134 + get_file(new_m->vm_file);
98135 +
98136 + if (new_m->vm_ops && new_m->vm_ops->open)
98137 + new_m->vm_ops->open(new_m);
98138 +
98139 + if (new_below)
98140 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
98141 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
98142 + else
98143 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
98144 +
98145 + if (err) {
98146 + if (new_m->vm_ops && new_m->vm_ops->close)
98147 + new_m->vm_ops->close(new_m);
98148 + if (new_m->vm_file)
98149 + fput(new_m->vm_file);
98150 + mpol_put(pol);
98151 + }
98152 + }
98153 +#endif
98154 +
98155 /* Success. */
98156 if (!err)
98157 return 0;
98158 @@ -2481,10 +2918,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98159 new->vm_ops->close(new);
98160 if (new->vm_file)
98161 fput(new->vm_file);
98162 - unlink_anon_vmas(new);
98163 out_free_mpol:
98164 mpol_put(vma_policy(new));
98165 out_free_vma:
98166 +
98167 +#ifdef CONFIG_PAX_SEGMEXEC
98168 + if (new_m) {
98169 + unlink_anon_vmas(new_m);
98170 + kmem_cache_free(vm_area_cachep, new_m);
98171 + }
98172 +#endif
98173 +
98174 + unlink_anon_vmas(new);
98175 kmem_cache_free(vm_area_cachep, new);
98176 out_err:
98177 return err;
98178 @@ -2497,6 +2942,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98179 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98180 unsigned long addr, int new_below)
98181 {
98182 +
98183 +#ifdef CONFIG_PAX_SEGMEXEC
98184 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
98185 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
98186 + if (mm->map_count >= sysctl_max_map_count-1)
98187 + return -ENOMEM;
98188 + } else
98189 +#endif
98190 +
98191 if (mm->map_count >= sysctl_max_map_count)
98192 return -ENOMEM;
98193
98194 @@ -2508,11 +2962,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98195 * work. This now handles partial unmappings.
98196 * Jeremy Fitzhardinge <jeremy@goop.org>
98197 */
98198 +#ifdef CONFIG_PAX_SEGMEXEC
98199 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98200 {
98201 + int ret = __do_munmap(mm, start, len);
98202 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
98203 + return ret;
98204 +
98205 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
98206 +}
98207 +
98208 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98209 +#else
98210 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98211 +#endif
98212 +{
98213 unsigned long end;
98214 struct vm_area_struct *vma, *prev, *last;
98215
98216 + /*
98217 + * mm->mmap_sem is required to protect against another thread
98218 + * changing the mappings in case we sleep.
98219 + */
98220 + verify_mm_writelocked(mm);
98221 +
98222 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
98223 return -EINVAL;
98224
98225 @@ -2587,6 +3060,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98226 /* Fix up all other VM information */
98227 remove_vma_list(mm, vma);
98228
98229 + track_exec_limit(mm, start, end, 0UL);
98230 +
98231 return 0;
98232 }
98233
98234 @@ -2595,6 +3070,13 @@ int vm_munmap(unsigned long start, size_t len)
98235 int ret;
98236 struct mm_struct *mm = current->mm;
98237
98238 +
98239 +#ifdef CONFIG_PAX_SEGMEXEC
98240 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
98241 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
98242 + return -EINVAL;
98243 +#endif
98244 +
98245 down_write(&mm->mmap_sem);
98246 ret = do_munmap(mm, start, len);
98247 up_write(&mm->mmap_sem);
98248 @@ -2608,16 +3090,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
98249 return vm_munmap(addr, len);
98250 }
98251
98252 -static inline void verify_mm_writelocked(struct mm_struct *mm)
98253 -{
98254 -#ifdef CONFIG_DEBUG_VM
98255 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
98256 - WARN_ON(1);
98257 - up_read(&mm->mmap_sem);
98258 - }
98259 -#endif
98260 -}
98261 -
98262 /*
98263 * this is really a simplified "do_mmap". it only handles
98264 * anonymous maps. eventually we may be able to do some
98265 @@ -2631,6 +3103,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98266 struct rb_node ** rb_link, * rb_parent;
98267 pgoff_t pgoff = addr >> PAGE_SHIFT;
98268 int error;
98269 + unsigned long charged;
98270
98271 len = PAGE_ALIGN(len);
98272 if (!len)
98273 @@ -2638,10 +3111,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98274
98275 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98276
98277 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98278 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98279 + flags &= ~VM_EXEC;
98280 +
98281 +#ifdef CONFIG_PAX_MPROTECT
98282 + if (mm->pax_flags & MF_PAX_MPROTECT)
98283 + flags &= ~VM_MAYEXEC;
98284 +#endif
98285 +
98286 + }
98287 +#endif
98288 +
98289 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98290 if (error & ~PAGE_MASK)
98291 return error;
98292
98293 + charged = len >> PAGE_SHIFT;
98294 +
98295 error = mlock_future_check(mm, mm->def_flags, len);
98296 if (error)
98297 return error;
98298 @@ -2655,21 +3142,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98299 /*
98300 * Clear old maps. this also does some error checking for us
98301 */
98302 - munmap_back:
98303 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98304 if (do_munmap(mm, addr, len))
98305 return -ENOMEM;
98306 - goto munmap_back;
98307 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98308 }
98309
98310 /* Check against address space limits *after* clearing old maps... */
98311 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98312 + if (!may_expand_vm(mm, charged))
98313 return -ENOMEM;
98314
98315 if (mm->map_count > sysctl_max_map_count)
98316 return -ENOMEM;
98317
98318 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98319 + if (security_vm_enough_memory_mm(mm, charged))
98320 return -ENOMEM;
98321
98322 /* Can we just expand an old private anonymous mapping? */
98323 @@ -2683,7 +3169,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98324 */
98325 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98326 if (!vma) {
98327 - vm_unacct_memory(len >> PAGE_SHIFT);
98328 + vm_unacct_memory(charged);
98329 return -ENOMEM;
98330 }
98331
98332 @@ -2697,10 +3183,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98333 vma_link(mm, vma, prev, rb_link, rb_parent);
98334 out:
98335 perf_event_mmap(vma);
98336 - mm->total_vm += len >> PAGE_SHIFT;
98337 + mm->total_vm += charged;
98338 if (flags & VM_LOCKED)
98339 - mm->locked_vm += (len >> PAGE_SHIFT);
98340 + mm->locked_vm += charged;
98341 vma->vm_flags |= VM_SOFTDIRTY;
98342 + track_exec_limit(mm, addr, addr + len, flags);
98343 return addr;
98344 }
98345
98346 @@ -2762,6 +3249,7 @@ void exit_mmap(struct mm_struct *mm)
98347 while (vma) {
98348 if (vma->vm_flags & VM_ACCOUNT)
98349 nr_accounted += vma_pages(vma);
98350 + vma->vm_mirror = NULL;
98351 vma = remove_vma(vma);
98352 }
98353 vm_unacct_memory(nr_accounted);
98354 @@ -2779,6 +3267,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98355 struct vm_area_struct *prev;
98356 struct rb_node **rb_link, *rb_parent;
98357
98358 +#ifdef CONFIG_PAX_SEGMEXEC
98359 + struct vm_area_struct *vma_m = NULL;
98360 +#endif
98361 +
98362 + if (security_mmap_addr(vma->vm_start))
98363 + return -EPERM;
98364 +
98365 /*
98366 * The vm_pgoff of a purely anonymous vma should be irrelevant
98367 * until its first write fault, when page's anon_vma and index
98368 @@ -2802,7 +3297,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98369 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98370 return -ENOMEM;
98371
98372 +#ifdef CONFIG_PAX_SEGMEXEC
98373 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98374 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98375 + if (!vma_m)
98376 + return -ENOMEM;
98377 + }
98378 +#endif
98379 +
98380 vma_link(mm, vma, prev, rb_link, rb_parent);
98381 +
98382 +#ifdef CONFIG_PAX_SEGMEXEC
98383 + if (vma_m)
98384 + BUG_ON(pax_mirror_vma(vma_m, vma));
98385 +#endif
98386 +
98387 return 0;
98388 }
98389
98390 @@ -2821,6 +3330,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98391 struct rb_node **rb_link, *rb_parent;
98392 bool faulted_in_anon_vma = true;
98393
98394 + BUG_ON(vma->vm_mirror);
98395 +
98396 /*
98397 * If anonymous vma has not yet been faulted, update new pgoff
98398 * to match new location, to increase its chance of merging.
98399 @@ -2885,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98400 return NULL;
98401 }
98402
98403 +#ifdef CONFIG_PAX_SEGMEXEC
98404 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98405 +{
98406 + struct vm_area_struct *prev_m;
98407 + struct rb_node **rb_link_m, *rb_parent_m;
98408 + struct mempolicy *pol_m;
98409 +
98410 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98411 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98412 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98413 + *vma_m = *vma;
98414 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98415 + if (anon_vma_clone(vma_m, vma))
98416 + return -ENOMEM;
98417 + pol_m = vma_policy(vma_m);
98418 + mpol_get(pol_m);
98419 + set_vma_policy(vma_m, pol_m);
98420 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98421 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98422 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98423 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98424 + if (vma_m->vm_file)
98425 + get_file(vma_m->vm_file);
98426 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98427 + vma_m->vm_ops->open(vma_m);
98428 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98429 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98430 + vma_m->vm_mirror = vma;
98431 + vma->vm_mirror = vma_m;
98432 + return 0;
98433 +}
98434 +#endif
98435 +
98436 /*
98437 * Return true if the calling process may expand its vm space by the passed
98438 * number of pages
98439 @@ -2896,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98440
98441 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98442
98443 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98444 if (cur + npages > lim)
98445 return 0;
98446 return 1;
98447 @@ -2978,6 +3523,22 @@ static struct vm_area_struct *__install_special_mapping(
98448 vma->vm_start = addr;
98449 vma->vm_end = addr + len;
98450
98451 +#ifdef CONFIG_PAX_MPROTECT
98452 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98453 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98454 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98455 + return ERR_PTR(-EPERM);
98456 + if (!(vm_flags & VM_EXEC))
98457 + vm_flags &= ~VM_MAYEXEC;
98458 +#else
98459 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98460 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98461 +#endif
98462 + else
98463 + vm_flags &= ~VM_MAYWRITE;
98464 + }
98465 +#endif
98466 +
98467 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98468 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98469
98470 diff --git a/mm/mprotect.c b/mm/mprotect.c
98471 index c43d557..0b7ccd2 100644
98472 --- a/mm/mprotect.c
98473 +++ b/mm/mprotect.c
98474 @@ -24,10 +24,18 @@
98475 #include <linux/migrate.h>
98476 #include <linux/perf_event.h>
98477 #include <linux/ksm.h>
98478 +#include <linux/sched/sysctl.h>
98479 +
98480 +#ifdef CONFIG_PAX_MPROTECT
98481 +#include <linux/elf.h>
98482 +#include <linux/binfmts.h>
98483 +#endif
98484 +
98485 #include <asm/uaccess.h>
98486 #include <asm/pgtable.h>
98487 #include <asm/cacheflush.h>
98488 #include <asm/tlbflush.h>
98489 +#include <asm/mmu_context.h>
98490
98491 #ifndef pgprot_modify
98492 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
98493 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98494 return pages;
98495 }
98496
98497 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98498 +/* called while holding the mmap semaphor for writing except stack expansion */
98499 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98500 +{
98501 + unsigned long oldlimit, newlimit = 0UL;
98502 +
98503 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98504 + return;
98505 +
98506 + spin_lock(&mm->page_table_lock);
98507 + oldlimit = mm->context.user_cs_limit;
98508 + if ((prot & VM_EXEC) && oldlimit < end)
98509 + /* USER_CS limit moved up */
98510 + newlimit = end;
98511 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98512 + /* USER_CS limit moved down */
98513 + newlimit = start;
98514 +
98515 + if (newlimit) {
98516 + mm->context.user_cs_limit = newlimit;
98517 +
98518 +#ifdef CONFIG_SMP
98519 + wmb();
98520 + cpus_clear(mm->context.cpu_user_cs_mask);
98521 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98522 +#endif
98523 +
98524 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98525 + }
98526 + spin_unlock(&mm->page_table_lock);
98527 + if (newlimit == end) {
98528 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98529 +
98530 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98531 + if (is_vm_hugetlb_page(vma))
98532 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98533 + else
98534 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98535 + }
98536 +}
98537 +#endif
98538 +
98539 int
98540 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98541 unsigned long start, unsigned long end, unsigned long newflags)
98542 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98543 int error;
98544 int dirty_accountable = 0;
98545
98546 +#ifdef CONFIG_PAX_SEGMEXEC
98547 + struct vm_area_struct *vma_m = NULL;
98548 + unsigned long start_m, end_m;
98549 +
98550 + start_m = start + SEGMEXEC_TASK_SIZE;
98551 + end_m = end + SEGMEXEC_TASK_SIZE;
98552 +#endif
98553 +
98554 if (newflags == oldflags) {
98555 *pprev = vma;
98556 return 0;
98557 }
98558
98559 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98560 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98561 +
98562 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98563 + return -ENOMEM;
98564 +
98565 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98566 + return -ENOMEM;
98567 + }
98568 +
98569 /*
98570 * If we make a private mapping writable we increase our commit;
98571 * but (without finer accounting) cannot reduce our commit if we
98572 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98573 }
98574 }
98575
98576 +#ifdef CONFIG_PAX_SEGMEXEC
98577 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98578 + if (start != vma->vm_start) {
98579 + error = split_vma(mm, vma, start, 1);
98580 + if (error)
98581 + goto fail;
98582 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98583 + *pprev = (*pprev)->vm_next;
98584 + }
98585 +
98586 + if (end != vma->vm_end) {
98587 + error = split_vma(mm, vma, end, 0);
98588 + if (error)
98589 + goto fail;
98590 + }
98591 +
98592 + if (pax_find_mirror_vma(vma)) {
98593 + error = __do_munmap(mm, start_m, end_m - start_m);
98594 + if (error)
98595 + goto fail;
98596 + } else {
98597 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98598 + if (!vma_m) {
98599 + error = -ENOMEM;
98600 + goto fail;
98601 + }
98602 + vma->vm_flags = newflags;
98603 + error = pax_mirror_vma(vma_m, vma);
98604 + if (error) {
98605 + vma->vm_flags = oldflags;
98606 + goto fail;
98607 + }
98608 + }
98609 + }
98610 +#endif
98611 +
98612 /*
98613 * First try to merge with previous and/or next vma.
98614 */
98615 @@ -319,9 +423,21 @@ success:
98616 * vm_flags and vm_page_prot are protected by the mmap_sem
98617 * held in write mode.
98618 */
98619 +
98620 +#ifdef CONFIG_PAX_SEGMEXEC
98621 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98622 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98623 +#endif
98624 +
98625 vma->vm_flags = newflags;
98626 +
98627 +#ifdef CONFIG_PAX_MPROTECT
98628 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98629 + mm->binfmt->handle_mprotect(vma, newflags);
98630 +#endif
98631 +
98632 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
98633 - vm_get_page_prot(newflags));
98634 + vm_get_page_prot(vma->vm_flags));
98635
98636 if (vma_wants_writenotify(vma)) {
98637 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
98638 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98639 end = start + len;
98640 if (end <= start)
98641 return -ENOMEM;
98642 +
98643 +#ifdef CONFIG_PAX_SEGMEXEC
98644 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98645 + if (end > SEGMEXEC_TASK_SIZE)
98646 + return -EINVAL;
98647 + } else
98648 +#endif
98649 +
98650 + if (end > TASK_SIZE)
98651 + return -EINVAL;
98652 +
98653 if (!arch_validate_prot(prot))
98654 return -EINVAL;
98655
98656 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98657 /*
98658 * Does the application expect PROT_READ to imply PROT_EXEC:
98659 */
98660 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98661 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98662 prot |= PROT_EXEC;
98663
98664 vm_flags = calc_vm_prot_bits(prot);
98665 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98666 if (start > vma->vm_start)
98667 prev = vma;
98668
98669 +#ifdef CONFIG_PAX_MPROTECT
98670 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98671 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98672 +#endif
98673 +
98674 for (nstart = start ; ; ) {
98675 unsigned long newflags;
98676
98677 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98678
98679 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98680 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98681 + if (prot & (PROT_WRITE | PROT_EXEC))
98682 + gr_log_rwxmprotect(vma);
98683 +
98684 + error = -EACCES;
98685 + goto out;
98686 + }
98687 +
98688 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98689 error = -EACCES;
98690 goto out;
98691 }
98692 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98693 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98694 if (error)
98695 goto out;
98696 +
98697 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98698 +
98699 nstart = tmp;
98700
98701 if (nstart < prev->vm_end)
98702 diff --git a/mm/mremap.c b/mm/mremap.c
98703 index 05f1180..c3cde48 100644
98704 --- a/mm/mremap.c
98705 +++ b/mm/mremap.c
98706 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98707 continue;
98708 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98709 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98710 +
98711 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98712 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98713 + pte = pte_exprotect(pte);
98714 +#endif
98715 +
98716 pte = move_soft_dirty_pte(pte);
98717 set_pte_at(mm, new_addr, new_pte, pte);
98718 }
98719 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98720 if (is_vm_hugetlb_page(vma))
98721 goto Einval;
98722
98723 +#ifdef CONFIG_PAX_SEGMEXEC
98724 + if (pax_find_mirror_vma(vma))
98725 + goto Einval;
98726 +#endif
98727 +
98728 /* We can't remap across vm area boundaries */
98729 if (old_len > vma->vm_end - addr)
98730 goto Efault;
98731 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98732 unsigned long ret = -EINVAL;
98733 unsigned long charged = 0;
98734 unsigned long map_flags;
98735 + unsigned long pax_task_size = TASK_SIZE;
98736
98737 if (new_addr & ~PAGE_MASK)
98738 goto out;
98739
98740 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98741 +#ifdef CONFIG_PAX_SEGMEXEC
98742 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98743 + pax_task_size = SEGMEXEC_TASK_SIZE;
98744 +#endif
98745 +
98746 + pax_task_size -= PAGE_SIZE;
98747 +
98748 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98749 goto out;
98750
98751 /* Check if the location we're moving into overlaps the
98752 * old location at all, and fail if it does.
98753 */
98754 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98755 - goto out;
98756 -
98757 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98758 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98759 goto out;
98760
98761 ret = do_munmap(mm, new_addr, new_len);
98762 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98763 unsigned long ret = -EINVAL;
98764 unsigned long charged = 0;
98765 bool locked = false;
98766 + unsigned long pax_task_size = TASK_SIZE;
98767
98768 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98769 return ret;
98770 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98771 if (!new_len)
98772 return ret;
98773
98774 +#ifdef CONFIG_PAX_SEGMEXEC
98775 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98776 + pax_task_size = SEGMEXEC_TASK_SIZE;
98777 +#endif
98778 +
98779 + pax_task_size -= PAGE_SIZE;
98780 +
98781 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98782 + old_len > pax_task_size || addr > pax_task_size-old_len)
98783 + return ret;
98784 +
98785 down_write(&current->mm->mmap_sem);
98786
98787 if (flags & MREMAP_FIXED) {
98788 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98789 new_addr = addr;
98790 }
98791 ret = addr;
98792 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98793 goto out;
98794 }
98795 }
98796 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98797 goto out;
98798 }
98799
98800 + map_flags = vma->vm_flags;
98801 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98802 + if (!(ret & ~PAGE_MASK)) {
98803 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98804 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98805 + }
98806 }
98807 out:
98808 if (ret & ~PAGE_MASK)
98809 diff --git a/mm/nommu.c b/mm/nommu.c
98810 index a881d96..e5932cd 100644
98811 --- a/mm/nommu.c
98812 +++ b/mm/nommu.c
98813 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98814 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98815 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98816 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98817 -int heap_stack_gap = 0;
98818
98819 atomic_long_t mmap_pages_allocated;
98820
98821 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98822 EXPORT_SYMBOL(find_vma);
98823
98824 /*
98825 - * find a VMA
98826 - * - we don't extend stack VMAs under NOMMU conditions
98827 - */
98828 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98829 -{
98830 - return find_vma(mm, addr);
98831 -}
98832 -
98833 -/*
98834 * expand a stack to a given address
98835 * - not supported under NOMMU conditions
98836 */
98837 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98838
98839 /* most fields are the same, copy all, and then fixup */
98840 *new = *vma;
98841 + INIT_LIST_HEAD(&new->anon_vma_chain);
98842 *region = *vma->vm_region;
98843 new->vm_region = region;
98844
98845 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98846 }
98847 EXPORT_SYMBOL(generic_file_remap_pages);
98848
98849 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98850 - unsigned long addr, void *buf, int len, int write)
98851 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98852 + unsigned long addr, void *buf, size_t len, int write)
98853 {
98854 struct vm_area_struct *vma;
98855
98856 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98857 *
98858 * The caller must hold a reference on @mm.
98859 */
98860 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98861 - void *buf, int len, int write)
98862 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98863 + void *buf, size_t len, int write)
98864 {
98865 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98866 }
98867 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98868 * Access another process' address space.
98869 * - source/target buffer must be kernel space
98870 */
98871 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98872 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98873 {
98874 struct mm_struct *mm;
98875
98876 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98877 index ba5fd97..5a95869 100644
98878 --- a/mm/page-writeback.c
98879 +++ b/mm/page-writeback.c
98880 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98881 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98882 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98883 */
98884 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98885 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98886 unsigned long thresh,
98887 unsigned long bg_thresh,
98888 unsigned long dirty,
98889 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98890 index c5fe124..2cf7f17 100644
98891 --- a/mm/page_alloc.c
98892 +++ b/mm/page_alloc.c
98893 @@ -61,6 +61,7 @@
98894 #include <linux/page-debug-flags.h>
98895 #include <linux/hugetlb.h>
98896 #include <linux/sched/rt.h>
98897 +#include <linux/random.h>
98898
98899 #include <asm/sections.h>
98900 #include <asm/tlbflush.h>
98901 @@ -357,7 +358,7 @@ out:
98902 * This usage means that zero-order pages may not be compound.
98903 */
98904
98905 -static void free_compound_page(struct page *page)
98906 +void free_compound_page(struct page *page)
98907 {
98908 __free_pages_ok(page, compound_order(page));
98909 }
98910 @@ -740,6 +741,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98911 int i;
98912 int bad = 0;
98913
98914 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98915 + unsigned long index = 1UL << order;
98916 +#endif
98917 +
98918 trace_mm_page_free(page, order);
98919 kmemcheck_free_shadow(page, order);
98920
98921 @@ -756,6 +761,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98922 debug_check_no_obj_freed(page_address(page),
98923 PAGE_SIZE << order);
98924 }
98925 +
98926 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98927 + for (; index; --index)
98928 + sanitize_highpage(page + index - 1);
98929 +#endif
98930 +
98931 arch_free_page(page, order);
98932 kernel_map_pages(page, 1 << order, 0);
98933
98934 @@ -779,6 +790,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98935 local_irq_restore(flags);
98936 }
98937
98938 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98939 +bool __meminitdata extra_latent_entropy;
98940 +
98941 +static int __init setup_pax_extra_latent_entropy(char *str)
98942 +{
98943 + extra_latent_entropy = true;
98944 + return 0;
98945 +}
98946 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98947 +
98948 +volatile u64 latent_entropy __latent_entropy;
98949 +EXPORT_SYMBOL(latent_entropy);
98950 +#endif
98951 +
98952 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98953 {
98954 unsigned int nr_pages = 1 << order;
98955 @@ -794,6 +819,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98956 __ClearPageReserved(p);
98957 set_page_count(p, 0);
98958
98959 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98960 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98961 + u64 hash = 0;
98962 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98963 + const u64 *data = lowmem_page_address(page);
98964 +
98965 + for (index = 0; index < end; index++)
98966 + hash ^= hash + data[index];
98967 + latent_entropy ^= hash;
98968 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98969 + }
98970 +#endif
98971 +
98972 page_zone(page)->managed_pages += nr_pages;
98973 set_page_refcounted(page);
98974 __free_pages(page, order);
98975 @@ -922,8 +960,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98976 arch_alloc_page(page, order);
98977 kernel_map_pages(page, 1 << order, 1);
98978
98979 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98980 if (gfp_flags & __GFP_ZERO)
98981 prep_zero_page(page, order, gfp_flags);
98982 +#endif
98983
98984 if (order && (gfp_flags & __GFP_COMP))
98985 prep_compound_page(page, order);
98986 @@ -1601,7 +1641,7 @@ again:
98987 }
98988
98989 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98990 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98991 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98992 !zone_is_fair_depleted(zone))
98993 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
98994
98995 @@ -1922,7 +1962,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98996 do {
98997 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98998 high_wmark_pages(zone) - low_wmark_pages(zone) -
98999 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
99000 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
99001 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
99002 } while (zone++ != preferred_zone);
99003 }
99004 @@ -5699,7 +5739,7 @@ static void __setup_per_zone_wmarks(void)
99005
99006 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
99007 high_wmark_pages(zone) - low_wmark_pages(zone) -
99008 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
99009 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
99010
99011 setup_zone_migrate_reserve(zone);
99012 spin_unlock_irqrestore(&zone->lock, flags);
99013 diff --git a/mm/percpu.c b/mm/percpu.c
99014 index 2139e30..1d45bce 100644
99015 --- a/mm/percpu.c
99016 +++ b/mm/percpu.c
99017 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
99018 static unsigned int pcpu_high_unit_cpu __read_mostly;
99019
99020 /* the address of the first chunk which starts with the kernel static area */
99021 -void *pcpu_base_addr __read_mostly;
99022 +void *pcpu_base_addr __read_only;
99023 EXPORT_SYMBOL_GPL(pcpu_base_addr);
99024
99025 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
99026 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
99027 index 5077afc..846c9ef 100644
99028 --- a/mm/process_vm_access.c
99029 +++ b/mm/process_vm_access.c
99030 @@ -13,6 +13,7 @@
99031 #include <linux/uio.h>
99032 #include <linux/sched.h>
99033 #include <linux/highmem.h>
99034 +#include <linux/security.h>
99035 #include <linux/ptrace.h>
99036 #include <linux/slab.h>
99037 #include <linux/syscalls.h>
99038 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
99039 ssize_t iov_len;
99040 size_t total_len = iov_iter_count(iter);
99041
99042 + return -ENOSYS; // PaX: until properly audited
99043 +
99044 /*
99045 * Work out how many pages of struct pages we're going to need
99046 * when eventually calling get_user_pages
99047 */
99048 for (i = 0; i < riovcnt; i++) {
99049 iov_len = rvec[i].iov_len;
99050 - if (iov_len > 0) {
99051 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
99052 - + iov_len)
99053 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
99054 - / PAGE_SIZE + 1;
99055 - nr_pages = max(nr_pages, nr_pages_iov);
99056 - }
99057 + if (iov_len <= 0)
99058 + continue;
99059 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
99060 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
99061 + nr_pages = max(nr_pages, nr_pages_iov);
99062 }
99063
99064 if (nr_pages == 0)
99065 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
99066 goto free_proc_pages;
99067 }
99068
99069 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
99070 + rc = -EPERM;
99071 + goto put_task_struct;
99072 + }
99073 +
99074 mm = mm_access(task, PTRACE_MODE_ATTACH);
99075 if (!mm || IS_ERR(mm)) {
99076 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
99077 diff --git a/mm/rmap.c b/mm/rmap.c
99078 index 1807ca3..7a532bd 100644
99079 --- a/mm/rmap.c
99080 +++ b/mm/rmap.c
99081 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99082 struct anon_vma *anon_vma = vma->anon_vma;
99083 struct anon_vma_chain *avc;
99084
99085 +#ifdef CONFIG_PAX_SEGMEXEC
99086 + struct anon_vma_chain *avc_m = NULL;
99087 +#endif
99088 +
99089 might_sleep();
99090 if (unlikely(!anon_vma)) {
99091 struct mm_struct *mm = vma->vm_mm;
99092 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99093 if (!avc)
99094 goto out_enomem;
99095
99096 +#ifdef CONFIG_PAX_SEGMEXEC
99097 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
99098 + if (!avc_m)
99099 + goto out_enomem_free_avc;
99100 +#endif
99101 +
99102 anon_vma = find_mergeable_anon_vma(vma);
99103 allocated = NULL;
99104 if (!anon_vma) {
99105 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99106 /* page_table_lock to protect against threads */
99107 spin_lock(&mm->page_table_lock);
99108 if (likely(!vma->anon_vma)) {
99109 +
99110 +#ifdef CONFIG_PAX_SEGMEXEC
99111 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
99112 +
99113 + if (vma_m) {
99114 + BUG_ON(vma_m->anon_vma);
99115 + vma_m->anon_vma = anon_vma;
99116 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
99117 + avc_m = NULL;
99118 + }
99119 +#endif
99120 +
99121 vma->anon_vma = anon_vma;
99122 anon_vma_chain_link(vma, avc, anon_vma);
99123 allocated = NULL;
99124 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99125
99126 if (unlikely(allocated))
99127 put_anon_vma(allocated);
99128 +
99129 +#ifdef CONFIG_PAX_SEGMEXEC
99130 + if (unlikely(avc_m))
99131 + anon_vma_chain_free(avc_m);
99132 +#endif
99133 +
99134 if (unlikely(avc))
99135 anon_vma_chain_free(avc);
99136 }
99137 return 0;
99138
99139 out_enomem_free_avc:
99140 +
99141 +#ifdef CONFIG_PAX_SEGMEXEC
99142 + if (avc_m)
99143 + anon_vma_chain_free(avc_m);
99144 +#endif
99145 +
99146 anon_vma_chain_free(avc);
99147 out_enomem:
99148 return -ENOMEM;
99149 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
99150 * Attach the anon_vmas from src to dst.
99151 * Returns 0 on success, -ENOMEM on failure.
99152 */
99153 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99154 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
99155 {
99156 struct anon_vma_chain *avc, *pavc;
99157 struct anon_vma *root = NULL;
99158 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99159 * the corresponding VMA in the parent process is attached to.
99160 * Returns 0 on success, non-zero on failure.
99161 */
99162 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99163 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
99164 {
99165 struct anon_vma_chain *avc;
99166 struct anon_vma *anon_vma;
99167 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
99168 void __init anon_vma_init(void)
99169 {
99170 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
99171 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
99172 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
99173 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
99174 + anon_vma_ctor);
99175 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
99176 + SLAB_PANIC|SLAB_NO_SANITIZE);
99177 }
99178
99179 /*
99180 diff --git a/mm/shmem.c b/mm/shmem.c
99181 index 469f90d..34a09ee 100644
99182 --- a/mm/shmem.c
99183 +++ b/mm/shmem.c
99184 @@ -33,7 +33,7 @@
99185 #include <linux/swap.h>
99186 #include <linux/aio.h>
99187
99188 -static struct vfsmount *shm_mnt;
99189 +struct vfsmount *shm_mnt;
99190
99191 #ifdef CONFIG_SHMEM
99192 /*
99193 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
99194 #define BOGO_DIRENT_SIZE 20
99195
99196 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
99197 -#define SHORT_SYMLINK_LEN 128
99198 +#define SHORT_SYMLINK_LEN 64
99199
99200 /*
99201 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
99202 @@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
99203 static int shmem_xattr_validate(const char *name)
99204 {
99205 struct { const char *prefix; size_t len; } arr[] = {
99206 +
99207 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99208 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
99209 +#endif
99210 +
99211 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
99212 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
99213 };
99214 @@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
99215 if (err)
99216 return err;
99217
99218 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99219 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
99220 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
99221 + return -EOPNOTSUPP;
99222 + if (size > 8)
99223 + return -EINVAL;
99224 + }
99225 +#endif
99226 +
99227 return simple_xattr_set(&info->xattrs, name, value, size, flags);
99228 }
99229
99230 @@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
99231 int err = -ENOMEM;
99232
99233 /* Round up to L1_CACHE_BYTES to resist false sharing */
99234 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
99235 - L1_CACHE_BYTES), GFP_KERNEL);
99236 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
99237 if (!sbinfo)
99238 return -ENOMEM;
99239
99240 diff --git a/mm/slab.c b/mm/slab.c
99241 index cc91c1e..0676592 100644
99242 --- a/mm/slab.c
99243 +++ b/mm/slab.c
99244 @@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99245 if ((x)->max_freeable < i) \
99246 (x)->max_freeable = i; \
99247 } while (0)
99248 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
99249 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
99250 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99251 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99252 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99253 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99254 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99255 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99256 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99257 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99258 #else
99259 #define STATS_INC_ACTIVE(x) do { } while (0)
99260 #define STATS_DEC_ACTIVE(x) do { } while (0)
99261 @@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99262 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99263 #define STATS_INC_FREEHIT(x) do { } while (0)
99264 #define STATS_INC_FREEMISS(x) do { } while (0)
99265 +#define STATS_INC_SANITIZED(x) do { } while (0)
99266 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99267 #endif
99268
99269 #if DEBUG
99270 @@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99271 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99272 */
99273 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99274 - const struct page *page, void *obj)
99275 + const struct page *page, const void *obj)
99276 {
99277 u32 offset = (obj - page->s_mem);
99278 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99279 @@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
99280 */
99281
99282 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
99283 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
99284 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99285
99286 if (INDEX_AC != INDEX_NODE)
99287 kmalloc_caches[INDEX_NODE] =
99288 create_kmalloc_cache("kmalloc-node",
99289 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99290 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99291
99292 slab_early_init = 0;
99293
99294 @@ -3384,6 +3388,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99295 struct array_cache *ac = cpu_cache_get(cachep);
99296
99297 check_irq_off();
99298 +
99299 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99300 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99301 + STATS_INC_NOT_SANITIZED(cachep);
99302 + else {
99303 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99304 +
99305 + if (cachep->ctor)
99306 + cachep->ctor(objp);
99307 +
99308 + STATS_INC_SANITIZED(cachep);
99309 + }
99310 +#endif
99311 +
99312 kmemleak_free_recursive(objp, cachep->flags);
99313 objp = cache_free_debugcheck(cachep, objp, caller);
99314
99315 @@ -3607,6 +3625,7 @@ void kfree(const void *objp)
99316
99317 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99318 return;
99319 + VM_BUG_ON(!virt_addr_valid(objp));
99320 local_irq_save(flags);
99321 kfree_debugcheck(objp);
99322 c = virt_to_cache(objp);
99323 @@ -4056,14 +4075,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99324 }
99325 /* cpu stats */
99326 {
99327 - unsigned long allochit = atomic_read(&cachep->allochit);
99328 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99329 - unsigned long freehit = atomic_read(&cachep->freehit);
99330 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99331 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99332 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99333 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99334 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99335
99336 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99337 allochit, allocmiss, freehit, freemiss);
99338 }
99339 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99340 + {
99341 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99342 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99343 +
99344 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99345 + }
99346 +#endif
99347 #endif
99348 }
99349
99350 @@ -4281,13 +4308,69 @@ static const struct file_operations proc_slabstats_operations = {
99351 static int __init slab_proc_init(void)
99352 {
99353 #ifdef CONFIG_DEBUG_SLAB_LEAK
99354 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99355 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99356 #endif
99357 return 0;
99358 }
99359 module_init(slab_proc_init);
99360 #endif
99361
99362 +bool is_usercopy_object(const void *ptr)
99363 +{
99364 + struct page *page;
99365 + struct kmem_cache *cachep;
99366 +
99367 + if (ZERO_OR_NULL_PTR(ptr))
99368 + return false;
99369 +
99370 + if (!slab_is_available())
99371 + return false;
99372 +
99373 + if (!virt_addr_valid(ptr))
99374 + return false;
99375 +
99376 + page = virt_to_head_page(ptr);
99377 +
99378 + if (!PageSlab(page))
99379 + return false;
99380 +
99381 + cachep = page->slab_cache;
99382 + return cachep->flags & SLAB_USERCOPY;
99383 +}
99384 +
99385 +#ifdef CONFIG_PAX_USERCOPY
99386 +const char *check_heap_object(const void *ptr, unsigned long n)
99387 +{
99388 + struct page *page;
99389 + struct kmem_cache *cachep;
99390 + unsigned int objnr;
99391 + unsigned long offset;
99392 +
99393 + if (ZERO_OR_NULL_PTR(ptr))
99394 + return "<null>";
99395 +
99396 + if (!virt_addr_valid(ptr))
99397 + return NULL;
99398 +
99399 + page = virt_to_head_page(ptr);
99400 +
99401 + if (!PageSlab(page))
99402 + return NULL;
99403 +
99404 + cachep = page->slab_cache;
99405 + if (!(cachep->flags & SLAB_USERCOPY))
99406 + return cachep->name;
99407 +
99408 + objnr = obj_to_index(cachep, page, ptr);
99409 + BUG_ON(objnr >= cachep->num);
99410 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99411 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99412 + return NULL;
99413 +
99414 + return cachep->name;
99415 +}
99416 +#endif
99417 +
99418 /**
99419 * ksize - get the actual amount of memory allocated for a given object
99420 * @objp: Pointer to the object
99421 diff --git a/mm/slab.h b/mm/slab.h
99422 index 0e0fdd3..d0fd761 100644
99423 --- a/mm/slab.h
99424 +++ b/mm/slab.h
99425 @@ -32,6 +32,20 @@ extern struct list_head slab_caches;
99426 /* The slab cache that manages slab cache information */
99427 extern struct kmem_cache *kmem_cache;
99428
99429 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99430 +#ifdef CONFIG_X86_64
99431 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99432 +#else
99433 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99434 +#endif
99435 +enum pax_sanitize_mode {
99436 + PAX_SANITIZE_SLAB_OFF = 0,
99437 + PAX_SANITIZE_SLAB_FAST,
99438 + PAX_SANITIZE_SLAB_FULL,
99439 +};
99440 +extern enum pax_sanitize_mode pax_sanitize_slab;
99441 +#endif
99442 +
99443 unsigned long calculate_alignment(unsigned long flags,
99444 unsigned long align, unsigned long size);
99445
99446 @@ -67,7 +81,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99447
99448 /* Legal flag mask for kmem_cache_create(), for various configurations */
99449 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99450 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99451 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99452 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99453
99454 #if defined(CONFIG_DEBUG_SLAB)
99455 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99456 @@ -251,6 +266,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99457 return s;
99458
99459 page = virt_to_head_page(x);
99460 +
99461 + BUG_ON(!PageSlab(page));
99462 +
99463 cachep = page->slab_cache;
99464 if (slab_equal_or_root(cachep, s))
99465 return cachep;
99466 diff --git a/mm/slab_common.c b/mm/slab_common.c
99467 index d319502..da7714e 100644
99468 --- a/mm/slab_common.c
99469 +++ b/mm/slab_common.c
99470 @@ -25,11 +25,35 @@
99471
99472 #include "slab.h"
99473
99474 -enum slab_state slab_state;
99475 +enum slab_state slab_state __read_only;
99476 LIST_HEAD(slab_caches);
99477 DEFINE_MUTEX(slab_mutex);
99478 struct kmem_cache *kmem_cache;
99479
99480 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99481 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99482 +static int __init pax_sanitize_slab_setup(char *str)
99483 +{
99484 + if (!str)
99485 + return 0;
99486 +
99487 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99488 + pr_info("PaX slab sanitization: %s\n", "disabled");
99489 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99490 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99491 + pr_info("PaX slab sanitization: %s\n", "fast");
99492 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99493 + } else if (!strcmp(str, "full")) {
99494 + pr_info("PaX slab sanitization: %s\n", "full");
99495 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99496 + } else
99497 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99498 +
99499 + return 0;
99500 +}
99501 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99502 +#endif
99503 +
99504 #ifdef CONFIG_DEBUG_VM
99505 static int kmem_cache_sanity_check(const char *name, size_t size)
99506 {
99507 @@ -160,7 +184,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99508 if (err)
99509 goto out_free_cache;
99510
99511 - s->refcount = 1;
99512 + atomic_set(&s->refcount, 1);
99513 list_add(&s->list, &slab_caches);
99514 out:
99515 if (err)
99516 @@ -222,6 +246,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99517 */
99518 flags &= CACHE_CREATE_MASK;
99519
99520 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99521 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99522 + flags |= SLAB_NO_SANITIZE;
99523 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99524 + flags &= ~SLAB_NO_SANITIZE;
99525 +#endif
99526 +
99527 s = __kmem_cache_alias(name, size, align, flags, ctor);
99528 if (s)
99529 goto out_unlock;
99530 @@ -341,8 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99531
99532 mutex_lock(&slab_mutex);
99533
99534 - s->refcount--;
99535 - if (s->refcount)
99536 + if (!atomic_dec_and_test(&s->refcount))
99537 goto out_unlock;
99538
99539 if (memcg_cleanup_cache_params(s) != 0)
99540 @@ -362,7 +392,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99541 rcu_barrier();
99542
99543 memcg_free_cache_params(s);
99544 -#ifdef SLAB_SUPPORTS_SYSFS
99545 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99546 sysfs_slab_remove(s);
99547 #else
99548 slab_kmem_cache_release(s);
99549 @@ -418,7 +448,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99550 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99551 name, size, err);
99552
99553 - s->refcount = -1; /* Exempt from merging for now */
99554 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99555 }
99556
99557 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99558 @@ -431,7 +461,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99559
99560 create_boot_cache(s, name, size, flags);
99561 list_add(&s->list, &slab_caches);
99562 - s->refcount = 1;
99563 + atomic_set(&s->refcount, 1);
99564 return s;
99565 }
99566
99567 @@ -443,6 +473,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99568 EXPORT_SYMBOL(kmalloc_dma_caches);
99569 #endif
99570
99571 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99572 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99573 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99574 +#endif
99575 +
99576 /*
99577 * Conversion table for small slabs sizes / 8 to the index in the
99578 * kmalloc array. This is necessary for slabs < 192 since we have non power
99579 @@ -507,6 +542,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99580 return kmalloc_dma_caches[index];
99581
99582 #endif
99583 +
99584 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99585 + if (unlikely((flags & GFP_USERCOPY)))
99586 + return kmalloc_usercopy_caches[index];
99587 +
99588 +#endif
99589 +
99590 return kmalloc_caches[index];
99591 }
99592
99593 @@ -563,7 +605,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99594 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99595 if (!kmalloc_caches[i]) {
99596 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99597 - 1 << i, flags);
99598 + 1 << i, SLAB_USERCOPY | flags);
99599 }
99600
99601 /*
99602 @@ -572,10 +614,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99603 * earlier power of two caches
99604 */
99605 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99606 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99607 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99608
99609 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99610 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99611 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99612 }
99613
99614 /* Kmalloc array is now usable */
99615 @@ -608,6 +650,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99616 }
99617 }
99618 #endif
99619 +
99620 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99621 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99622 + struct kmem_cache *s = kmalloc_caches[i];
99623 +
99624 + if (s) {
99625 + int size = kmalloc_size(i);
99626 + char *n = kasprintf(GFP_NOWAIT,
99627 + "usercopy-kmalloc-%d", size);
99628 +
99629 + BUG_ON(!n);
99630 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99631 + size, SLAB_USERCOPY | flags);
99632 + }
99633 + }
99634 +#endif
99635 +
99636 }
99637 #endif /* !CONFIG_SLOB */
99638
99639 @@ -666,6 +725,9 @@ void print_slabinfo_header(struct seq_file *m)
99640 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99641 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99642 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99643 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99644 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99645 +#endif
99646 #endif
99647 seq_putc(m, '\n');
99648 }
99649 diff --git a/mm/slob.c b/mm/slob.c
99650 index 21980e0..975f1bf 100644
99651 --- a/mm/slob.c
99652 +++ b/mm/slob.c
99653 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99654 /*
99655 * Return the size of a slob block.
99656 */
99657 -static slobidx_t slob_units(slob_t *s)
99658 +static slobidx_t slob_units(const slob_t *s)
99659 {
99660 if (s->units > 0)
99661 return s->units;
99662 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99663 /*
99664 * Return the next free slob block pointer after this one.
99665 */
99666 -static slob_t *slob_next(slob_t *s)
99667 +static slob_t *slob_next(const slob_t *s)
99668 {
99669 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99670 slobidx_t next;
99671 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99672 /*
99673 * Returns true if s is the last free block in its page.
99674 */
99675 -static int slob_last(slob_t *s)
99676 +static int slob_last(const slob_t *s)
99677 {
99678 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99679 }
99680
99681 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99682 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99683 {
99684 - void *page;
99685 + struct page *page;
99686
99687 #ifdef CONFIG_NUMA
99688 if (node != NUMA_NO_NODE)
99689 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99690 if (!page)
99691 return NULL;
99692
99693 - return page_address(page);
99694 + __SetPageSlab(page);
99695 + return page;
99696 }
99697
99698 -static void slob_free_pages(void *b, int order)
99699 +static void slob_free_pages(struct page *sp, int order)
99700 {
99701 if (current->reclaim_state)
99702 current->reclaim_state->reclaimed_slab += 1 << order;
99703 - free_pages((unsigned long)b, order);
99704 + __ClearPageSlab(sp);
99705 + page_mapcount_reset(sp);
99706 + sp->private = 0;
99707 + __free_pages(sp, order);
99708 }
99709
99710 /*
99711 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99712
99713 /* Not enough space: must allocate a new page */
99714 if (!b) {
99715 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99716 - if (!b)
99717 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99718 + if (!sp)
99719 return NULL;
99720 - sp = virt_to_page(b);
99721 - __SetPageSlab(sp);
99722 + b = page_address(sp);
99723
99724 spin_lock_irqsave(&slob_lock, flags);
99725 sp->units = SLOB_UNITS(PAGE_SIZE);
99726 sp->freelist = b;
99727 + sp->private = 0;
99728 INIT_LIST_HEAD(&sp->lru);
99729 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99730 set_slob_page_free(sp, slob_list);
99731 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99732 /*
99733 * slob_free: entry point into the slob allocator.
99734 */
99735 -static void slob_free(void *block, int size)
99736 +static void slob_free(struct kmem_cache *c, void *block, int size)
99737 {
99738 struct page *sp;
99739 slob_t *prev, *next, *b = (slob_t *)block;
99740 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99741 if (slob_page_free(sp))
99742 clear_slob_page_free(sp);
99743 spin_unlock_irqrestore(&slob_lock, flags);
99744 - __ClearPageSlab(sp);
99745 - page_mapcount_reset(sp);
99746 - slob_free_pages(b, 0);
99747 + slob_free_pages(sp, 0);
99748 return;
99749 }
99750
99751 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99752 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99753 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99754 +#endif
99755 +
99756 if (!slob_page_free(sp)) {
99757 /* This slob page is about to become partially free. Easy! */
99758 sp->units = units;
99759 @@ -424,11 +431,10 @@ out:
99760 */
99761
99762 static __always_inline void *
99763 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99764 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99765 {
99766 - unsigned int *m;
99767 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99768 - void *ret;
99769 + slob_t *m;
99770 + void *ret = NULL;
99771
99772 gfp &= gfp_allowed_mask;
99773
99774 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99775
99776 if (!m)
99777 return NULL;
99778 - *m = size;
99779 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99780 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99781 + m[0].units = size;
99782 + m[1].units = align;
99783 ret = (void *)m + align;
99784
99785 trace_kmalloc_node(caller, ret,
99786 size, size + align, gfp, node);
99787 } else {
99788 unsigned int order = get_order(size);
99789 + struct page *page;
99790
99791 if (likely(order))
99792 gfp |= __GFP_COMP;
99793 - ret = slob_new_pages(gfp, order, node);
99794 + page = slob_new_pages(gfp, order, node);
99795 + if (page) {
99796 + ret = page_address(page);
99797 + page->private = size;
99798 + }
99799
99800 trace_kmalloc_node(caller, ret,
99801 size, PAGE_SIZE << order, gfp, node);
99802 }
99803
99804 - kmemleak_alloc(ret, size, 1, gfp);
99805 + return ret;
99806 +}
99807 +
99808 +static __always_inline void *
99809 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99810 +{
99811 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99812 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99813 +
99814 + if (!ZERO_OR_NULL_PTR(ret))
99815 + kmemleak_alloc(ret, size, 1, gfp);
99816 return ret;
99817 }
99818
99819 @@ -493,34 +517,112 @@ void kfree(const void *block)
99820 return;
99821 kmemleak_free(block);
99822
99823 + VM_BUG_ON(!virt_addr_valid(block));
99824 sp = virt_to_page(block);
99825 - if (PageSlab(sp)) {
99826 + VM_BUG_ON(!PageSlab(sp));
99827 + if (!sp->private) {
99828 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99829 - unsigned int *m = (unsigned int *)(block - align);
99830 - slob_free(m, *m + align);
99831 - } else
99832 + slob_t *m = (slob_t *)(block - align);
99833 + slob_free(NULL, m, m[0].units + align);
99834 + } else {
99835 + __ClearPageSlab(sp);
99836 + page_mapcount_reset(sp);
99837 + sp->private = 0;
99838 __free_pages(sp, compound_order(sp));
99839 + }
99840 }
99841 EXPORT_SYMBOL(kfree);
99842
99843 +bool is_usercopy_object(const void *ptr)
99844 +{
99845 + if (!slab_is_available())
99846 + return false;
99847 +
99848 + // PAX: TODO
99849 +
99850 + return false;
99851 +}
99852 +
99853 +#ifdef CONFIG_PAX_USERCOPY
99854 +const char *check_heap_object(const void *ptr, unsigned long n)
99855 +{
99856 + struct page *page;
99857 + const slob_t *free;
99858 + const void *base;
99859 + unsigned long flags;
99860 +
99861 + if (ZERO_OR_NULL_PTR(ptr))
99862 + return "<null>";
99863 +
99864 + if (!virt_addr_valid(ptr))
99865 + return NULL;
99866 +
99867 + page = virt_to_head_page(ptr);
99868 + if (!PageSlab(page))
99869 + return NULL;
99870 +
99871 + if (page->private) {
99872 + base = page;
99873 + if (base <= ptr && n <= page->private - (ptr - base))
99874 + return NULL;
99875 + return "<slob>";
99876 + }
99877 +
99878 + /* some tricky double walking to find the chunk */
99879 + spin_lock_irqsave(&slob_lock, flags);
99880 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99881 + free = page->freelist;
99882 +
99883 + while (!slob_last(free) && (void *)free <= ptr) {
99884 + base = free + slob_units(free);
99885 + free = slob_next(free);
99886 + }
99887 +
99888 + while (base < (void *)free) {
99889 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99890 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99891 + int offset;
99892 +
99893 + if (ptr < base + align)
99894 + break;
99895 +
99896 + offset = ptr - base - align;
99897 + if (offset >= m) {
99898 + base += size;
99899 + continue;
99900 + }
99901 +
99902 + if (n > m - offset)
99903 + break;
99904 +
99905 + spin_unlock_irqrestore(&slob_lock, flags);
99906 + return NULL;
99907 + }
99908 +
99909 + spin_unlock_irqrestore(&slob_lock, flags);
99910 + return "<slob>";
99911 +}
99912 +#endif
99913 +
99914 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99915 size_t ksize(const void *block)
99916 {
99917 struct page *sp;
99918 int align;
99919 - unsigned int *m;
99920 + slob_t *m;
99921
99922 BUG_ON(!block);
99923 if (unlikely(block == ZERO_SIZE_PTR))
99924 return 0;
99925
99926 sp = virt_to_page(block);
99927 - if (unlikely(!PageSlab(sp)))
99928 - return PAGE_SIZE << compound_order(sp);
99929 + VM_BUG_ON(!PageSlab(sp));
99930 + if (sp->private)
99931 + return sp->private;
99932
99933 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99934 - m = (unsigned int *)(block - align);
99935 - return SLOB_UNITS(*m) * SLOB_UNIT;
99936 + m = (slob_t *)(block - align);
99937 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99938 }
99939 EXPORT_SYMBOL(ksize);
99940
99941 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99942
99943 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99944 {
99945 - void *b;
99946 + void *b = NULL;
99947
99948 flags &= gfp_allowed_mask;
99949
99950 lockdep_trace_alloc(flags);
99951
99952 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99953 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99954 +#else
99955 if (c->size < PAGE_SIZE) {
99956 b = slob_alloc(c->size, flags, c->align, node);
99957 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99958 SLOB_UNITS(c->size) * SLOB_UNIT,
99959 flags, node);
99960 } else {
99961 - b = slob_new_pages(flags, get_order(c->size), node);
99962 + struct page *sp;
99963 +
99964 + sp = slob_new_pages(flags, get_order(c->size), node);
99965 + if (sp) {
99966 + b = page_address(sp);
99967 + sp->private = c->size;
99968 + }
99969 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99970 PAGE_SIZE << get_order(c->size),
99971 flags, node);
99972 }
99973 +#endif
99974
99975 if (b && c->ctor)
99976 c->ctor(b);
99977 @@ -582,12 +694,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99978 EXPORT_SYMBOL(kmem_cache_alloc_node);
99979 #endif
99980
99981 -static void __kmem_cache_free(void *b, int size)
99982 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99983 {
99984 - if (size < PAGE_SIZE)
99985 - slob_free(b, size);
99986 + struct page *sp;
99987 +
99988 + sp = virt_to_page(b);
99989 + BUG_ON(!PageSlab(sp));
99990 + if (!sp->private)
99991 + slob_free(c, b, size);
99992 else
99993 - slob_free_pages(b, get_order(size));
99994 + slob_free_pages(sp, get_order(size));
99995 }
99996
99997 static void kmem_rcu_free(struct rcu_head *head)
99998 @@ -595,22 +711,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99999 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
100000 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
100001
100002 - __kmem_cache_free(b, slob_rcu->size);
100003 + __kmem_cache_free(NULL, b, slob_rcu->size);
100004 }
100005
100006 void kmem_cache_free(struct kmem_cache *c, void *b)
100007 {
100008 + int size = c->size;
100009 +
100010 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100011 + if (size + c->align < PAGE_SIZE) {
100012 + size += c->align;
100013 + b -= c->align;
100014 + }
100015 +#endif
100016 +
100017 kmemleak_free_recursive(b, c->flags);
100018 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
100019 struct slob_rcu *slob_rcu;
100020 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
100021 - slob_rcu->size = c->size;
100022 + slob_rcu = b + (size - sizeof(struct slob_rcu));
100023 + slob_rcu->size = size;
100024 call_rcu(&slob_rcu->head, kmem_rcu_free);
100025 } else {
100026 - __kmem_cache_free(b, c->size);
100027 + __kmem_cache_free(c, b, size);
100028 }
100029
100030 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100031 + trace_kfree(_RET_IP_, b);
100032 +#else
100033 trace_kmem_cache_free(_RET_IP_, b);
100034 +#endif
100035 +
100036 }
100037 EXPORT_SYMBOL(kmem_cache_free);
100038
100039 diff --git a/mm/slub.c b/mm/slub.c
100040 index 3e8afcc..d6e2c89 100644
100041 --- a/mm/slub.c
100042 +++ b/mm/slub.c
100043 @@ -207,7 +207,7 @@ struct track {
100044
100045 enum track_item { TRACK_ALLOC, TRACK_FREE };
100046
100047 -#ifdef CONFIG_SYSFS
100048 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100049 static int sysfs_slab_add(struct kmem_cache *);
100050 static int sysfs_slab_alias(struct kmem_cache *, const char *);
100051 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
100052 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
100053 if (!t->addr)
100054 return;
100055
100056 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
100057 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
100058 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
100059 #ifdef CONFIG_STACKTRACE
100060 {
100061 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
100062
100063 slab_free_hook(s, x);
100064
100065 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100066 + if (!(s->flags & SLAB_NO_SANITIZE)) {
100067 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
100068 + if (s->ctor)
100069 + s->ctor(x);
100070 + }
100071 +#endif
100072 +
100073 redo:
100074 /*
100075 * Determine the currently cpus per cpu slab.
100076 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
100077 * Merge control. If this is set then no merging of slab caches will occur.
100078 * (Could be removed. This was introduced to pacify the merge skeptics.)
100079 */
100080 -static int slub_nomerge;
100081 +static int slub_nomerge = 1;
100082
100083 /*
100084 * Calculate the order of allocation given an slab object size.
100085 @@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
100086 s->inuse = size;
100087
100088 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
100089 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100090 + (!(flags & SLAB_NO_SANITIZE)) ||
100091 +#endif
100092 s->ctor)) {
100093 /*
100094 * Relocate free pointer after the object if it is not
100095 @@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
100096 EXPORT_SYMBOL(__kmalloc_node);
100097 #endif
100098
100099 +bool is_usercopy_object(const void *ptr)
100100 +{
100101 + struct page *page;
100102 + struct kmem_cache *s;
100103 +
100104 + if (ZERO_OR_NULL_PTR(ptr))
100105 + return false;
100106 +
100107 + if (!slab_is_available())
100108 + return false;
100109 +
100110 + if (!virt_addr_valid(ptr))
100111 + return false;
100112 +
100113 + page = virt_to_head_page(ptr);
100114 +
100115 + if (!PageSlab(page))
100116 + return false;
100117 +
100118 + s = page->slab_cache;
100119 + return s->flags & SLAB_USERCOPY;
100120 +}
100121 +
100122 +#ifdef CONFIG_PAX_USERCOPY
100123 +const char *check_heap_object(const void *ptr, unsigned long n)
100124 +{
100125 + struct page *page;
100126 + struct kmem_cache *s;
100127 + unsigned long offset;
100128 +
100129 + if (ZERO_OR_NULL_PTR(ptr))
100130 + return "<null>";
100131 +
100132 + if (!virt_addr_valid(ptr))
100133 + return NULL;
100134 +
100135 + page = virt_to_head_page(ptr);
100136 +
100137 + if (!PageSlab(page))
100138 + return NULL;
100139 +
100140 + s = page->slab_cache;
100141 + if (!(s->flags & SLAB_USERCOPY))
100142 + return s->name;
100143 +
100144 + offset = (ptr - page_address(page)) % s->size;
100145 + if (offset <= s->object_size && n <= s->object_size - offset)
100146 + return NULL;
100147 +
100148 + return s->name;
100149 +}
100150 +#endif
100151 +
100152 size_t ksize(const void *object)
100153 {
100154 struct page *page;
100155 @@ -3341,6 +3405,7 @@ void kfree(const void *x)
100156 if (unlikely(ZERO_OR_NULL_PTR(x)))
100157 return;
100158
100159 + VM_BUG_ON(!virt_addr_valid(x));
100160 page = virt_to_head_page(x);
100161 if (unlikely(!PageSlab(page))) {
100162 BUG_ON(!PageCompound(page));
100163 @@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
100164 /*
100165 * We may have set a slab to be unmergeable during bootstrap.
100166 */
100167 - if (s->refcount < 0)
100168 + if (atomic_read(&s->refcount) < 0)
100169 return 1;
100170
100171 return 0;
100172 @@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100173 int i;
100174 struct kmem_cache *c;
100175
100176 - s->refcount++;
100177 + atomic_inc(&s->refcount);
100178
100179 /*
100180 * Adjust the object sizes so that we clear
100181 @@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100182 }
100183
100184 if (sysfs_slab_alias(s, name)) {
100185 - s->refcount--;
100186 + atomic_dec(&s->refcount);
100187 s = NULL;
100188 }
100189 }
100190 @@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
100191 }
100192 #endif
100193
100194 -#ifdef CONFIG_SYSFS
100195 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100196 static int count_inuse(struct page *page)
100197 {
100198 return page->inuse;
100199 @@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
100200 len += sprintf(buf + len, "%7ld ", l->count);
100201
100202 if (l->addr)
100203 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100204 + len += sprintf(buf + len, "%pS", NULL);
100205 +#else
100206 len += sprintf(buf + len, "%pS", (void *)l->addr);
100207 +#endif
100208 else
100209 len += sprintf(buf + len, "<not-available>");
100210
100211 @@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
100212 validate_slab_cache(kmalloc_caches[9]);
100213 }
100214 #else
100215 -#ifdef CONFIG_SYSFS
100216 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100217 static void resiliency_test(void) {};
100218 #endif
100219 #endif
100220
100221 -#ifdef CONFIG_SYSFS
100222 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100223 enum slab_stat_type {
100224 SL_ALL, /* All slabs */
100225 SL_PARTIAL, /* Only partially allocated slabs */
100226 @@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
100227 {
100228 if (!s->ctor)
100229 return 0;
100230 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100231 + return sprintf(buf, "%pS\n", NULL);
100232 +#else
100233 return sprintf(buf, "%pS\n", s->ctor);
100234 +#endif
100235 }
100236 SLAB_ATTR_RO(ctor);
100237
100238 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100239 {
100240 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100241 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100242 }
100243 SLAB_ATTR_RO(aliases);
100244
100245 @@ -4554,6 +4627,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100246 SLAB_ATTR_RO(cache_dma);
100247 #endif
100248
100249 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100250 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100251 +{
100252 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100253 +}
100254 +SLAB_ATTR_RO(usercopy);
100255 +#endif
100256 +
100257 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100258 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
100259 +{
100260 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
100261 +}
100262 +SLAB_ATTR_RO(sanitize);
100263 +#endif
100264 +
100265 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100266 {
100267 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100268 @@ -4888,6 +4977,12 @@ static struct attribute *slab_attrs[] = {
100269 #ifdef CONFIG_ZONE_DMA
100270 &cache_dma_attr.attr,
100271 #endif
100272 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100273 + &usercopy_attr.attr,
100274 +#endif
100275 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100276 + &sanitize_attr.attr,
100277 +#endif
100278 #ifdef CONFIG_NUMA
100279 &remote_node_defrag_ratio_attr.attr,
100280 #endif
100281 @@ -5132,6 +5227,7 @@ static char *create_unique_id(struct kmem_cache *s)
100282 return name;
100283 }
100284
100285 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100286 static int sysfs_slab_add(struct kmem_cache *s)
100287 {
100288 int err;
100289 @@ -5205,6 +5301,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100290 kobject_del(&s->kobj);
100291 kobject_put(&s->kobj);
100292 }
100293 +#endif
100294
100295 /*
100296 * Need to buffer aliases during bootup until sysfs becomes
100297 @@ -5218,6 +5315,7 @@ struct saved_alias {
100298
100299 static struct saved_alias *alias_list;
100300
100301 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100302 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100303 {
100304 struct saved_alias *al;
100305 @@ -5240,6 +5338,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100306 alias_list = al;
100307 return 0;
100308 }
100309 +#endif
100310
100311 static int __init slab_sysfs_init(void)
100312 {
100313 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100314 index 4cba9c2..b4f9fcc 100644
100315 --- a/mm/sparse-vmemmap.c
100316 +++ b/mm/sparse-vmemmap.c
100317 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100318 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100319 if (!p)
100320 return NULL;
100321 - pud_populate(&init_mm, pud, p);
100322 + pud_populate_kernel(&init_mm, pud, p);
100323 }
100324 return pud;
100325 }
100326 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100327 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100328 if (!p)
100329 return NULL;
100330 - pgd_populate(&init_mm, pgd, p);
100331 + pgd_populate_kernel(&init_mm, pgd, p);
100332 }
100333 return pgd;
100334 }
100335 diff --git a/mm/sparse.c b/mm/sparse.c
100336 index d1b48b6..6e8590e 100644
100337 --- a/mm/sparse.c
100338 +++ b/mm/sparse.c
100339 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100340
100341 for (i = 0; i < PAGES_PER_SECTION; i++) {
100342 if (PageHWPoison(&memmap[i])) {
100343 - atomic_long_sub(1, &num_poisoned_pages);
100344 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100345 ClearPageHWPoison(&memmap[i]);
100346 }
100347 }
100348 diff --git a/mm/swap.c b/mm/swap.c
100349 index 6b2dc38..46b79ba 100644
100350 --- a/mm/swap.c
100351 +++ b/mm/swap.c
100352 @@ -31,6 +31,7 @@
100353 #include <linux/memcontrol.h>
100354 #include <linux/gfp.h>
100355 #include <linux/uio.h>
100356 +#include <linux/hugetlb.h>
100357
100358 #include "internal.h"
100359
100360 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100361
100362 __page_cache_release(page);
100363 dtor = get_compound_page_dtor(page);
100364 + if (!PageHuge(page))
100365 + BUG_ON(dtor != free_compound_page);
100366 (*dtor)(page);
100367 }
100368
100369 diff --git a/mm/swapfile.c b/mm/swapfile.c
100370 index 8798b2e..348f9dd 100644
100371 --- a/mm/swapfile.c
100372 +++ b/mm/swapfile.c
100373 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100374
100375 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100376 /* Activity counter to indicate that a swapon or swapoff has occurred */
100377 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100378 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100379
100380 static inline unsigned char swap_count(unsigned char ent)
100381 {
100382 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100383 spin_unlock(&swap_lock);
100384
100385 err = 0;
100386 - atomic_inc(&proc_poll_event);
100387 + atomic_inc_unchecked(&proc_poll_event);
100388 wake_up_interruptible(&proc_poll_wait);
100389
100390 out_dput:
100391 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100392
100393 poll_wait(file, &proc_poll_wait, wait);
100394
100395 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100396 - seq->poll_event = atomic_read(&proc_poll_event);
100397 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100398 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100399 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100400 }
100401
100402 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100403 return ret;
100404
100405 seq = file->private_data;
100406 - seq->poll_event = atomic_read(&proc_poll_event);
100407 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100408 return 0;
100409 }
100410
100411 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100412 (frontswap_map) ? "FS" : "");
100413
100414 mutex_unlock(&swapon_mutex);
100415 - atomic_inc(&proc_poll_event);
100416 + atomic_inc_unchecked(&proc_poll_event);
100417 wake_up_interruptible(&proc_poll_wait);
100418
100419 if (S_ISREG(inode->i_mode))
100420 diff --git a/mm/util.c b/mm/util.c
100421 index 093c973..b70a268 100644
100422 --- a/mm/util.c
100423 +++ b/mm/util.c
100424 @@ -202,6 +202,12 @@ done:
100425 void arch_pick_mmap_layout(struct mm_struct *mm)
100426 {
100427 mm->mmap_base = TASK_UNMAPPED_BASE;
100428 +
100429 +#ifdef CONFIG_PAX_RANDMMAP
100430 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100431 + mm->mmap_base += mm->delta_mmap;
100432 +#endif
100433 +
100434 mm->get_unmapped_area = arch_get_unmapped_area;
100435 }
100436 #endif
100437 @@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100438 if (!mm->arg_end)
100439 goto out_mm; /* Shh! No looking before we're done */
100440
100441 + if (gr_acl_handle_procpidmem(task))
100442 + goto out_mm;
100443 +
100444 len = mm->arg_end - mm->arg_start;
100445
100446 if (len > buflen)
100447 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100448 index 2b0aa54..b451f74 100644
100449 --- a/mm/vmalloc.c
100450 +++ b/mm/vmalloc.c
100451 @@ -40,6 +40,21 @@ struct vfree_deferred {
100452 };
100453 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100454
100455 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100456 +struct stack_deferred_llist {
100457 + struct llist_head list;
100458 + void *stack;
100459 + void *lowmem_stack;
100460 +};
100461 +
100462 +struct stack_deferred {
100463 + struct stack_deferred_llist list;
100464 + struct work_struct wq;
100465 +};
100466 +
100467 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100468 +#endif
100469 +
100470 static void __vunmap(const void *, int);
100471
100472 static void free_work(struct work_struct *w)
100473 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100474 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100475 struct llist_node *llnode = llist_del_all(&p->list);
100476 while (llnode) {
100477 - void *p = llnode;
100478 + void *x = llnode;
100479 llnode = llist_next(llnode);
100480 - __vunmap(p, 1);
100481 + __vunmap(x, 1);
100482 }
100483 }
100484
100485 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100486 +static void unmap_work(struct work_struct *w)
100487 +{
100488 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100489 + struct llist_node *llnode = llist_del_all(&p->list.list);
100490 + while (llnode) {
100491 + struct stack_deferred_llist *x =
100492 + llist_entry((struct llist_head *)llnode,
100493 + struct stack_deferred_llist, list);
100494 + void *stack = ACCESS_ONCE(x->stack);
100495 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100496 + llnode = llist_next(llnode);
100497 + __vunmap(stack, 0);
100498 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100499 + }
100500 +}
100501 +#endif
100502 +
100503 /*** Page table manipulation functions ***/
100504
100505 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100506 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100507
100508 pte = pte_offset_kernel(pmd, addr);
100509 do {
100510 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100511 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100512 +
100513 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100514 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100515 + BUG_ON(!pte_exec(*pte));
100516 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100517 + continue;
100518 + }
100519 +#endif
100520 +
100521 + {
100522 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100523 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100524 + }
100525 } while (pte++, addr += PAGE_SIZE, addr != end);
100526 }
100527
100528 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100529 pte = pte_alloc_kernel(pmd, addr);
100530 if (!pte)
100531 return -ENOMEM;
100532 +
100533 + pax_open_kernel();
100534 do {
100535 struct page *page = pages[*nr];
100536
100537 - if (WARN_ON(!pte_none(*pte)))
100538 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100539 + if (pgprot_val(prot) & _PAGE_NX)
100540 +#endif
100541 +
100542 + if (!pte_none(*pte)) {
100543 + pax_close_kernel();
100544 + WARN_ON(1);
100545 return -EBUSY;
100546 - if (WARN_ON(!page))
100547 + }
100548 + if (!page) {
100549 + pax_close_kernel();
100550 + WARN_ON(1);
100551 return -ENOMEM;
100552 + }
100553 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100554 (*nr)++;
100555 } while (pte++, addr += PAGE_SIZE, addr != end);
100556 + pax_close_kernel();
100557 return 0;
100558 }
100559
100560 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100561 pmd_t *pmd;
100562 unsigned long next;
100563
100564 - pmd = pmd_alloc(&init_mm, pud, addr);
100565 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100566 if (!pmd)
100567 return -ENOMEM;
100568 do {
100569 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100570 pud_t *pud;
100571 unsigned long next;
100572
100573 - pud = pud_alloc(&init_mm, pgd, addr);
100574 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100575 if (!pud)
100576 return -ENOMEM;
100577 do {
100578 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100579 if (addr >= MODULES_VADDR && addr < MODULES_END)
100580 return 1;
100581 #endif
100582 +
100583 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100584 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100585 + return 1;
100586 +#endif
100587 +
100588 return is_vmalloc_addr(x);
100589 }
100590
100591 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100592
100593 if (!pgd_none(*pgd)) {
100594 pud_t *pud = pud_offset(pgd, addr);
100595 +#ifdef CONFIG_X86
100596 + if (!pud_large(*pud))
100597 +#endif
100598 if (!pud_none(*pud)) {
100599 pmd_t *pmd = pmd_offset(pud, addr);
100600 +#ifdef CONFIG_X86
100601 + if (!pmd_large(*pmd))
100602 +#endif
100603 if (!pmd_none(*pmd)) {
100604 pte_t *ptep, pte;
100605
100606 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100607 for_each_possible_cpu(i) {
100608 struct vmap_block_queue *vbq;
100609 struct vfree_deferred *p;
100610 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100611 + struct stack_deferred *p2;
100612 +#endif
100613
100614 vbq = &per_cpu(vmap_block_queue, i);
100615 spin_lock_init(&vbq->lock);
100616 INIT_LIST_HEAD(&vbq->free);
100617 +
100618 p = &per_cpu(vfree_deferred, i);
100619 init_llist_head(&p->list);
100620 INIT_WORK(&p->wq, free_work);
100621 +
100622 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100623 + p2 = &per_cpu(stack_deferred, i);
100624 + init_llist_head(&p2->list.list);
100625 + INIT_WORK(&p2->wq, unmap_work);
100626 +#endif
100627 }
100628
100629 /* Import existing vmlist entries. */
100630 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100631 struct vm_struct *area;
100632
100633 BUG_ON(in_interrupt());
100634 +
100635 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100636 + if (flags & VM_KERNEXEC) {
100637 + if (start != VMALLOC_START || end != VMALLOC_END)
100638 + return NULL;
100639 + start = (unsigned long)MODULES_EXEC_VADDR;
100640 + end = (unsigned long)MODULES_EXEC_END;
100641 + }
100642 +#endif
100643 +
100644 if (flags & VM_IOREMAP)
100645 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100646
100647 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100648 }
100649 EXPORT_SYMBOL(vunmap);
100650
100651 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100652 +void unmap_process_stacks(struct task_struct *task)
100653 +{
100654 + if (unlikely(in_interrupt())) {
100655 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100656 + struct stack_deferred_llist *list = task->stack;
100657 + list->stack = task->stack;
100658 + list->lowmem_stack = task->lowmem_stack;
100659 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100660 + schedule_work(&p->wq);
100661 + } else {
100662 + __vunmap(task->stack, 0);
100663 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100664 + }
100665 +}
100666 +#endif
100667 +
100668 /**
100669 * vmap - map an array of pages into virtually contiguous space
100670 * @pages: array of page pointers
100671 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100672 if (count > totalram_pages)
100673 return NULL;
100674
100675 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100676 + if (!(pgprot_val(prot) & _PAGE_NX))
100677 + flags |= VM_KERNEXEC;
100678 +#endif
100679 +
100680 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100681 __builtin_return_address(0));
100682 if (!area)
100683 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100684 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100685 goto fail;
100686
100687 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100688 + if (!(pgprot_val(prot) & _PAGE_NX))
100689 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100690 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100691 + else
100692 +#endif
100693 +
100694 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100695 start, end, node, gfp_mask, caller);
100696 if (!area)
100697 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100698 * For tight control over page level allocator and protection flags
100699 * use __vmalloc() instead.
100700 */
100701 -
100702 void *vmalloc_exec(unsigned long size)
100703 {
100704 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100705 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100706 NUMA_NO_NODE, __builtin_return_address(0));
100707 }
100708
100709 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100710 {
100711 struct vm_struct *area;
100712
100713 + BUG_ON(vma->vm_mirror);
100714 +
100715 size = PAGE_ALIGN(size);
100716
100717 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100718 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100719 v->addr, v->addr + v->size, v->size);
100720
100721 if (v->caller)
100722 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100723 + seq_printf(m, " %pK", v->caller);
100724 +#else
100725 seq_printf(m, " %pS", v->caller);
100726 +#endif
100727
100728 if (v->nr_pages)
100729 seq_printf(m, " pages=%d", v->nr_pages);
100730 diff --git a/mm/vmstat.c b/mm/vmstat.c
100731 index e9ab104..de275bd 100644
100732 --- a/mm/vmstat.c
100733 +++ b/mm/vmstat.c
100734 @@ -20,6 +20,7 @@
100735 #include <linux/writeback.h>
100736 #include <linux/compaction.h>
100737 #include <linux/mm_inline.h>
100738 +#include <linux/grsecurity.h>
100739
100740 #include "internal.h"
100741
100742 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
100743 *
100744 * vm_stat contains the global counters
100745 */
100746 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100747 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100748 EXPORT_SYMBOL(vm_stat);
100749
100750 #ifdef CONFIG_SMP
100751 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
100752
100753 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100754 if (diff[i])
100755 - atomic_long_add(diff[i], &vm_stat[i]);
100756 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100757 }
100758
100759 /*
100760 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
100761 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100762 if (v) {
100763
100764 - atomic_long_add(v, &zone->vm_stat[i]);
100765 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100766 global_diff[i] += v;
100767 #ifdef CONFIG_NUMA
100768 /* 3 seconds idle till flush */
100769 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
100770
100771 v = p->vm_stat_diff[i];
100772 p->vm_stat_diff[i] = 0;
100773 - atomic_long_add(v, &zone->vm_stat[i]);
100774 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100775 global_diff[i] += v;
100776 }
100777 }
100778 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100779 if (pset->vm_stat_diff[i]) {
100780 int v = pset->vm_stat_diff[i];
100781 pset->vm_stat_diff[i] = 0;
100782 - atomic_long_add(v, &zone->vm_stat[i]);
100783 - atomic_long_add(v, &vm_stat[i]);
100784 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100785 + atomic_long_add_unchecked(v, &vm_stat[i]);
100786 }
100787 }
100788 #endif
100789 @@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100790 stat_items_size += sizeof(struct vm_event_state);
100791 #endif
100792
100793 - v = kmalloc(stat_items_size, GFP_KERNEL);
100794 + v = kzalloc(stat_items_size, GFP_KERNEL);
100795 m->private = v;
100796 if (!v)
100797 return ERR_PTR(-ENOMEM);
100798 +
100799 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100800 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100801 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100802 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100803 + && !in_group_p(grsec_proc_gid)
100804 +#endif
100805 + )
100806 + return (unsigned long *)m->private + *pos;
100807 +#endif
100808 +#endif
100809 +
100810 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100811 v[i] = global_page_state(i);
100812 v += NR_VM_ZONE_STAT_ITEMS;
100813 @@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
100814 cpu_notifier_register_done();
100815 #endif
100816 #ifdef CONFIG_PROC_FS
100817 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100818 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100819 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100820 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100821 + {
100822 + mode_t gr_mode = S_IRUGO;
100823 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100824 + gr_mode = S_IRUSR;
100825 +#endif
100826 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100827 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100828 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100829 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100830 + }
100831 #endif
100832 return 0;
100833 }
100834 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100835 index 64c6bed..b79a5de 100644
100836 --- a/net/8021q/vlan.c
100837 +++ b/net/8021q/vlan.c
100838 @@ -481,7 +481,7 @@ out:
100839 return NOTIFY_DONE;
100840 }
100841
100842 -static struct notifier_block vlan_notifier_block __read_mostly = {
100843 +static struct notifier_block vlan_notifier_block = {
100844 .notifier_call = vlan_device_event,
100845 };
100846
100847 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100848 err = -EPERM;
100849 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100850 break;
100851 - if ((args.u.name_type >= 0) &&
100852 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100853 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100854 struct vlan_net *vn;
100855
100856 vn = net_generic(net, vlan_net_id);
100857 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100858 index 8ac8a5c..991defc 100644
100859 --- a/net/8021q/vlan_netlink.c
100860 +++ b/net/8021q/vlan_netlink.c
100861 @@ -238,7 +238,7 @@ nla_put_failure:
100862 return -EMSGSIZE;
100863 }
100864
100865 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
100866 +struct rtnl_link_ops vlan_link_ops = {
100867 .kind = "vlan",
100868 .maxtype = IFLA_VLAN_MAX,
100869 .policy = vlan_policy,
100870 diff --git a/net/9p/client.c b/net/9p/client.c
100871 index e86a9bea..e91f70e 100644
100872 --- a/net/9p/client.c
100873 +++ b/net/9p/client.c
100874 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100875 len - inline_len);
100876 } else {
100877 err = copy_from_user(ename + inline_len,
100878 - uidata, len - inline_len);
100879 + (char __force_user *)uidata, len - inline_len);
100880 if (err) {
100881 err = -EFAULT;
100882 goto out_err;
100883 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100884 kernel_buf = 1;
100885 indata = data;
100886 } else
100887 - indata = (__force char *)udata;
100888 + indata = (__force_kernel char *)udata;
100889 /*
100890 * response header len is 11
100891 * PDU Header(7) + IO Size (4)
100892 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100893 kernel_buf = 1;
100894 odata = data;
100895 } else
100896 - odata = (char *)udata;
100897 + odata = (char __force_kernel *)udata;
100898 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100899 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100900 fid->fid, offset, rsize);
100901 diff --git a/net/9p/mod.c b/net/9p/mod.c
100902 index 6ab36ae..6f1841b 100644
100903 --- a/net/9p/mod.c
100904 +++ b/net/9p/mod.c
100905 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100906 void v9fs_register_trans(struct p9_trans_module *m)
100907 {
100908 spin_lock(&v9fs_trans_lock);
100909 - list_add_tail(&m->list, &v9fs_trans_list);
100910 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100911 spin_unlock(&v9fs_trans_lock);
100912 }
100913 EXPORT_SYMBOL(v9fs_register_trans);
100914 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100915 void v9fs_unregister_trans(struct p9_trans_module *m)
100916 {
100917 spin_lock(&v9fs_trans_lock);
100918 - list_del_init(&m->list);
100919 + pax_list_del_init((struct list_head *)&m->list);
100920 spin_unlock(&v9fs_trans_lock);
100921 }
100922 EXPORT_SYMBOL(v9fs_unregister_trans);
100923 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100924 index 80d08f6..de63fd1 100644
100925 --- a/net/9p/trans_fd.c
100926 +++ b/net/9p/trans_fd.c
100927 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100928 oldfs = get_fs();
100929 set_fs(get_ds());
100930 /* The cast to a user pointer is valid due to the set_fs() */
100931 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100932 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100933 set_fs(oldfs);
100934
100935 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100936 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100937 index af46bc4..f9adfcd 100644
100938 --- a/net/appletalk/atalk_proc.c
100939 +++ b/net/appletalk/atalk_proc.c
100940 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100941 struct proc_dir_entry *p;
100942 int rc = -ENOMEM;
100943
100944 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100945 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100946 if (!atalk_proc_dir)
100947 goto out;
100948
100949 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100950 index 876fbe8..8bbea9f 100644
100951 --- a/net/atm/atm_misc.c
100952 +++ b/net/atm/atm_misc.c
100953 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100954 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100955 return 1;
100956 atm_return(vcc, truesize);
100957 - atomic_inc(&vcc->stats->rx_drop);
100958 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100959 return 0;
100960 }
100961 EXPORT_SYMBOL(atm_charge);
100962 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100963 }
100964 }
100965 atm_return(vcc, guess);
100966 - atomic_inc(&vcc->stats->rx_drop);
100967 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100968 return NULL;
100969 }
100970 EXPORT_SYMBOL(atm_alloc_charge);
100971 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100972
100973 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100974 {
100975 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100976 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100977 __SONET_ITEMS
100978 #undef __HANDLE_ITEM
100979 }
100980 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100981
100982 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100983 {
100984 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100985 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100986 __SONET_ITEMS
100987 #undef __HANDLE_ITEM
100988 }
100989 diff --git a/net/atm/lec.c b/net/atm/lec.c
100990 index 4b98f89..5a2f6cb 100644
100991 --- a/net/atm/lec.c
100992 +++ b/net/atm/lec.c
100993 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100994 }
100995
100996 static struct lane2_ops lane2_ops = {
100997 - lane2_resolve, /* resolve, spec 3.1.3 */
100998 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100999 - NULL /* associate indicator, spec 3.1.5 */
101000 + .resolve = lane2_resolve,
101001 + .associate_req = lane2_associate_req,
101002 + .associate_indicator = NULL
101003 };
101004
101005 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
101006 diff --git a/net/atm/lec.h b/net/atm/lec.h
101007 index 4149db1..f2ab682 100644
101008 --- a/net/atm/lec.h
101009 +++ b/net/atm/lec.h
101010 @@ -48,7 +48,7 @@ struct lane2_ops {
101011 const u8 *tlvs, u32 sizeoftlvs);
101012 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
101013 const u8 *tlvs, u32 sizeoftlvs);
101014 -};
101015 +} __no_const;
101016
101017 /*
101018 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
101019 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
101020 index d1b2d9a..d549f7f 100644
101021 --- a/net/atm/mpoa_caches.c
101022 +++ b/net/atm/mpoa_caches.c
101023 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
101024
101025
101026 static struct in_cache_ops ingress_ops = {
101027 - in_cache_add_entry, /* add_entry */
101028 - in_cache_get, /* get */
101029 - in_cache_get_with_mask, /* get_with_mask */
101030 - in_cache_get_by_vcc, /* get_by_vcc */
101031 - in_cache_put, /* put */
101032 - in_cache_remove_entry, /* remove_entry */
101033 - cache_hit, /* cache_hit */
101034 - clear_count_and_expired, /* clear_count */
101035 - check_resolving_entries, /* check_resolving */
101036 - refresh_entries, /* refresh */
101037 - in_destroy_cache /* destroy_cache */
101038 + .add_entry = in_cache_add_entry,
101039 + .get = in_cache_get,
101040 + .get_with_mask = in_cache_get_with_mask,
101041 + .get_by_vcc = in_cache_get_by_vcc,
101042 + .put = in_cache_put,
101043 + .remove_entry = in_cache_remove_entry,
101044 + .cache_hit = cache_hit,
101045 + .clear_count = clear_count_and_expired,
101046 + .check_resolving = check_resolving_entries,
101047 + .refresh = refresh_entries,
101048 + .destroy_cache = in_destroy_cache
101049 };
101050
101051 static struct eg_cache_ops egress_ops = {
101052 - eg_cache_add_entry, /* add_entry */
101053 - eg_cache_get_by_cache_id, /* get_by_cache_id */
101054 - eg_cache_get_by_tag, /* get_by_tag */
101055 - eg_cache_get_by_vcc, /* get_by_vcc */
101056 - eg_cache_get_by_src_ip, /* get_by_src_ip */
101057 - eg_cache_put, /* put */
101058 - eg_cache_remove_entry, /* remove_entry */
101059 - update_eg_cache_entry, /* update */
101060 - clear_expired, /* clear_expired */
101061 - eg_destroy_cache /* destroy_cache */
101062 + .add_entry = eg_cache_add_entry,
101063 + .get_by_cache_id = eg_cache_get_by_cache_id,
101064 + .get_by_tag = eg_cache_get_by_tag,
101065 + .get_by_vcc = eg_cache_get_by_vcc,
101066 + .get_by_src_ip = eg_cache_get_by_src_ip,
101067 + .put = eg_cache_put,
101068 + .remove_entry = eg_cache_remove_entry,
101069 + .update = update_eg_cache_entry,
101070 + .clear_expired = clear_expired,
101071 + .destroy_cache = eg_destroy_cache
101072 };
101073
101074
101075 diff --git a/net/atm/proc.c b/net/atm/proc.c
101076 index bbb6461..cf04016 100644
101077 --- a/net/atm/proc.c
101078 +++ b/net/atm/proc.c
101079 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
101080 const struct k_atm_aal_stats *stats)
101081 {
101082 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
101083 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
101084 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
101085 - atomic_read(&stats->rx_drop));
101086 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
101087 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
101088 + atomic_read_unchecked(&stats->rx_drop));
101089 }
101090
101091 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
101092 diff --git a/net/atm/resources.c b/net/atm/resources.c
101093 index 0447d5d..3cf4728 100644
101094 --- a/net/atm/resources.c
101095 +++ b/net/atm/resources.c
101096 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
101097 static void copy_aal_stats(struct k_atm_aal_stats *from,
101098 struct atm_aal_stats *to)
101099 {
101100 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101101 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101102 __AAL_STAT_ITEMS
101103 #undef __HANDLE_ITEM
101104 }
101105 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
101106 static void subtract_aal_stats(struct k_atm_aal_stats *from,
101107 struct atm_aal_stats *to)
101108 {
101109 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101110 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
101111 __AAL_STAT_ITEMS
101112 #undef __HANDLE_ITEM
101113 }
101114 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
101115 index 919a5ce..cc6b444 100644
101116 --- a/net/ax25/sysctl_net_ax25.c
101117 +++ b/net/ax25/sysctl_net_ax25.c
101118 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
101119 {
101120 char path[sizeof("net/ax25/") + IFNAMSIZ];
101121 int k;
101122 - struct ctl_table *table;
101123 + ctl_table_no_const *table;
101124
101125 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
101126 if (!table)
101127 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
101128 index 1e80539..676c37a 100644
101129 --- a/net/batman-adv/bat_iv_ogm.c
101130 +++ b/net/batman-adv/bat_iv_ogm.c
101131 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
101132
101133 /* randomize initial seqno to avoid collision */
101134 get_random_bytes(&random_seqno, sizeof(random_seqno));
101135 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101136 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101137
101138 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
101139 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
101140 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
101141 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
101142
101143 /* change sequence number to network order */
101144 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
101145 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
101146 batadv_ogm_packet->seqno = htonl(seqno);
101147 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
101148 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
101149
101150 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
101151
101152 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
101153 return;
101154
101155 /* could be changed by schedule_own_packet() */
101156 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
101157 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
101158
101159 if (ogm_packet->flags & BATADV_DIRECTLINK)
101160 has_directlink_flag = true;
101161 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
101162 index fc1835c..eead856 100644
101163 --- a/net/batman-adv/fragmentation.c
101164 +++ b/net/batman-adv/fragmentation.c
101165 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
101166 frag_header.packet_type = BATADV_UNICAST_FRAG;
101167 frag_header.version = BATADV_COMPAT_VERSION;
101168 frag_header.ttl = BATADV_TTL;
101169 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
101170 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
101171 frag_header.reserved = 0;
101172 frag_header.no = 0;
101173 frag_header.total_size = htons(skb->len);
101174 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
101175 index 5467955..75ad4e3 100644
101176 --- a/net/batman-adv/soft-interface.c
101177 +++ b/net/batman-adv/soft-interface.c
101178 @@ -296,7 +296,7 @@ send:
101179 primary_if->net_dev->dev_addr);
101180
101181 /* set broadcast sequence number */
101182 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
101183 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
101184 bcast_packet->seqno = htonl(seqno);
101185
101186 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
101187 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101188 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
101189
101190 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
101191 - atomic_set(&bat_priv->bcast_seqno, 1);
101192 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
101193 atomic_set(&bat_priv->tt.vn, 0);
101194 atomic_set(&bat_priv->tt.local_changes, 0);
101195 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
101196 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101197
101198 /* randomize initial seqno to avoid collision */
101199 get_random_bytes(&random_seqno, sizeof(random_seqno));
101200 - atomic_set(&bat_priv->frag_seqno, random_seqno);
101201 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
101202
101203 bat_priv->primary_if = NULL;
101204 bat_priv->num_ifaces = 0;
101205 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
101206 return 0;
101207 }
101208
101209 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
101210 +struct rtnl_link_ops batadv_link_ops = {
101211 .kind = "batadv",
101212 .priv_size = sizeof(struct batadv_priv),
101213 .setup = batadv_softif_init_early,
101214 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
101215 index 8854c05..ee5d5497 100644
101216 --- a/net/batman-adv/types.h
101217 +++ b/net/batman-adv/types.h
101218 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
101219 struct batadv_hard_iface_bat_iv {
101220 unsigned char *ogm_buff;
101221 int ogm_buff_len;
101222 - atomic_t ogm_seqno;
101223 + atomic_unchecked_t ogm_seqno;
101224 };
101225
101226 /**
101227 @@ -768,7 +768,7 @@ struct batadv_priv {
101228 atomic_t bonding;
101229 atomic_t fragmentation;
101230 atomic_t packet_size_max;
101231 - atomic_t frag_seqno;
101232 + atomic_unchecked_t frag_seqno;
101233 #ifdef CONFIG_BATMAN_ADV_BLA
101234 atomic_t bridge_loop_avoidance;
101235 #endif
101236 @@ -787,7 +787,7 @@ struct batadv_priv {
101237 #endif
101238 uint32_t isolation_mark;
101239 uint32_t isolation_mark_mask;
101240 - atomic_t bcast_seqno;
101241 + atomic_unchecked_t bcast_seqno;
101242 atomic_t bcast_queue_left;
101243 atomic_t batman_queue_left;
101244 char num_ifaces;
101245 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101246 index 115f149..f0ba286 100644
101247 --- a/net/bluetooth/hci_sock.c
101248 +++ b/net/bluetooth/hci_sock.c
101249 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101250 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101251 }
101252
101253 - len = min_t(unsigned int, len, sizeof(uf));
101254 + len = min((size_t)len, sizeof(uf));
101255 if (copy_from_user(&uf, optval, len)) {
101256 err = -EFAULT;
101257 break;
101258 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101259 index 14ca8ae..262d49a 100644
101260 --- a/net/bluetooth/l2cap_core.c
101261 +++ b/net/bluetooth/l2cap_core.c
101262 @@ -3565,8 +3565,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101263 break;
101264
101265 case L2CAP_CONF_RFC:
101266 - if (olen == sizeof(rfc))
101267 - memcpy(&rfc, (void *)val, olen);
101268 + if (olen != sizeof(rfc))
101269 + break;
101270 +
101271 + memcpy(&rfc, (void *)val, olen);
101272
101273 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101274 rfc.mode != chan->mode)
101275 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101276 index 1884f72..b3b71f9 100644
101277 --- a/net/bluetooth/l2cap_sock.c
101278 +++ b/net/bluetooth/l2cap_sock.c
101279 @@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101280 struct sock *sk = sock->sk;
101281 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101282 struct l2cap_options opts;
101283 - int len, err = 0;
101284 + int err = 0;
101285 + size_t len = optlen;
101286 u32 opt;
101287
101288 BT_DBG("sk %p", sk);
101289 @@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101290 opts.max_tx = chan->max_tx;
101291 opts.txwin_size = chan->tx_win;
101292
101293 - len = min_t(unsigned int, sizeof(opts), optlen);
101294 + len = min(sizeof(opts), len);
101295 if (copy_from_user((char *) &opts, optval, len)) {
101296 err = -EFAULT;
101297 break;
101298 @@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101299 struct bt_security sec;
101300 struct bt_power pwr;
101301 struct l2cap_conn *conn;
101302 - int len, err = 0;
101303 + int err = 0;
101304 + size_t len = optlen;
101305 u32 opt;
101306
101307 BT_DBG("sk %p", sk);
101308 @@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101309
101310 sec.level = BT_SECURITY_LOW;
101311
101312 - len = min_t(unsigned int, sizeof(sec), optlen);
101313 + len = min(sizeof(sec), len);
101314 if (copy_from_user((char *) &sec, optval, len)) {
101315 err = -EFAULT;
101316 break;
101317 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101318
101319 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101320
101321 - len = min_t(unsigned int, sizeof(pwr), optlen);
101322 + len = min(sizeof(pwr), len);
101323 if (copy_from_user((char *) &pwr, optval, len)) {
101324 err = -EFAULT;
101325 break;
101326 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101327 index 8bbbb5e..6fc0950 100644
101328 --- a/net/bluetooth/rfcomm/sock.c
101329 +++ b/net/bluetooth/rfcomm/sock.c
101330 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101331 struct sock *sk = sock->sk;
101332 struct bt_security sec;
101333 int err = 0;
101334 - size_t len;
101335 + size_t len = optlen;
101336 u32 opt;
101337
101338 BT_DBG("sk %p", sk);
101339 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101340
101341 sec.level = BT_SECURITY_LOW;
101342
101343 - len = min_t(unsigned int, sizeof(sec), optlen);
101344 + len = min(sizeof(sec), len);
101345 if (copy_from_user((char *) &sec, optval, len)) {
101346 err = -EFAULT;
101347 break;
101348 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101349 index 8e385a0..a5bdd8e 100644
101350 --- a/net/bluetooth/rfcomm/tty.c
101351 +++ b/net/bluetooth/rfcomm/tty.c
101352 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101353 BT_DBG("tty %p id %d", tty, tty->index);
101354
101355 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101356 - dev->channel, dev->port.count);
101357 + dev->channel, atomic_read(&dev->port.count));
101358
101359 err = tty_port_open(&dev->port, tty, filp);
101360 if (err)
101361 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101362 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101363
101364 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101365 - dev->port.count);
101366 + atomic_read(&dev->port.count));
101367
101368 tty_port_close(&dev->port, tty, filp);
101369 }
101370 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101371 index cb5fcf6..ad0a1a5 100644
101372 --- a/net/bridge/br_netlink.c
101373 +++ b/net/bridge/br_netlink.c
101374 @@ -484,7 +484,7 @@ static struct rtnl_af_ops br_af_ops = {
101375 .get_link_af_size = br_get_link_af_size,
101376 };
101377
101378 -struct rtnl_link_ops br_link_ops __read_mostly = {
101379 +struct rtnl_link_ops br_link_ops = {
101380 .kind = "bridge",
101381 .priv_size = sizeof(struct net_bridge),
101382 .setup = br_dev_setup,
101383 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101384 index 6d69631..b8fdc85 100644
101385 --- a/net/bridge/netfilter/ebtables.c
101386 +++ b/net/bridge/netfilter/ebtables.c
101387 @@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101388 tmp.valid_hooks = t->table->valid_hooks;
101389 }
101390 mutex_unlock(&ebt_mutex);
101391 - if (copy_to_user(user, &tmp, *len) != 0) {
101392 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101393 BUGPRINT("c2u Didn't work\n");
101394 ret = -EFAULT;
101395 break;
101396 @@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101397 goto out;
101398 tmp.valid_hooks = t->valid_hooks;
101399
101400 - if (copy_to_user(user, &tmp, *len) != 0) {
101401 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101402 ret = -EFAULT;
101403 break;
101404 }
101405 @@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101406 tmp.entries_size = t->table->entries_size;
101407 tmp.valid_hooks = t->table->valid_hooks;
101408
101409 - if (copy_to_user(user, &tmp, *len) != 0) {
101410 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101411 ret = -EFAULT;
101412 break;
101413 }
101414 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101415 index f5afda1..dcf770a 100644
101416 --- a/net/caif/cfctrl.c
101417 +++ b/net/caif/cfctrl.c
101418 @@ -10,6 +10,7 @@
101419 #include <linux/spinlock.h>
101420 #include <linux/slab.h>
101421 #include <linux/pkt_sched.h>
101422 +#include <linux/sched.h>
101423 #include <net/caif/caif_layer.h>
101424 #include <net/caif/cfpkt.h>
101425 #include <net/caif/cfctrl.h>
101426 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101427 memset(&dev_info, 0, sizeof(dev_info));
101428 dev_info.id = 0xff;
101429 cfsrvl_init(&this->serv, 0, &dev_info, false);
101430 - atomic_set(&this->req_seq_no, 1);
101431 - atomic_set(&this->rsp_seq_no, 1);
101432 + atomic_set_unchecked(&this->req_seq_no, 1);
101433 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101434 this->serv.layer.receive = cfctrl_recv;
101435 sprintf(this->serv.layer.name, "ctrl");
101436 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101437 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101438 struct cfctrl_request_info *req)
101439 {
101440 spin_lock_bh(&ctrl->info_list_lock);
101441 - atomic_inc(&ctrl->req_seq_no);
101442 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101443 + atomic_inc_unchecked(&ctrl->req_seq_no);
101444 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101445 list_add_tail(&req->list, &ctrl->list);
101446 spin_unlock_bh(&ctrl->info_list_lock);
101447 }
101448 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101449 if (p != first)
101450 pr_warn("Requests are not received in order\n");
101451
101452 - atomic_set(&ctrl->rsp_seq_no,
101453 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101454 p->sequence_no);
101455 list_del(&p->list);
101456 goto out;
101457 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101458 index 4589ff67..46d6b8f 100644
101459 --- a/net/caif/chnl_net.c
101460 +++ b/net/caif/chnl_net.c
101461 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101462 };
101463
101464
101465 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101466 +static struct rtnl_link_ops ipcaif_link_ops = {
101467 .kind = "caif",
101468 .priv_size = sizeof(struct chnl_net),
101469 .setup = ipcaif_net_setup,
101470 diff --git a/net/can/af_can.c b/net/can/af_can.c
101471 index ce82337..5d17b4d 100644
101472 --- a/net/can/af_can.c
101473 +++ b/net/can/af_can.c
101474 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101475 };
101476
101477 /* notifier block for netdevice event */
101478 -static struct notifier_block can_netdev_notifier __read_mostly = {
101479 +static struct notifier_block can_netdev_notifier = {
101480 .notifier_call = can_notifier,
101481 };
101482
101483 diff --git a/net/can/bcm.c b/net/can/bcm.c
101484 index dcb75c0..24b1b43 100644
101485 --- a/net/can/bcm.c
101486 +++ b/net/can/bcm.c
101487 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101488 }
101489
101490 /* create /proc/net/can-bcm directory */
101491 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101492 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101493 return 0;
101494 }
101495
101496 diff --git a/net/can/gw.c b/net/can/gw.c
101497 index 050a211..bb9fe33 100644
101498 --- a/net/can/gw.c
101499 +++ b/net/can/gw.c
101500 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101501 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101502
101503 static HLIST_HEAD(cgw_list);
101504 -static struct notifier_block notifier;
101505
101506 static struct kmem_cache *cgw_cache __read_mostly;
101507
101508 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101509 return err;
101510 }
101511
101512 +static struct notifier_block notifier = {
101513 + .notifier_call = cgw_notifier
101514 +};
101515 +
101516 static __init int cgw_module_init(void)
101517 {
101518 /* sanitize given module parameter */
101519 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101520 return -ENOMEM;
101521
101522 /* set notifier */
101523 - notifier.notifier_call = cgw_notifier;
101524 register_netdevice_notifier(&notifier);
101525
101526 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101527 diff --git a/net/can/proc.c b/net/can/proc.c
101528 index 1a19b98..df2b4ec 100644
101529 --- a/net/can/proc.c
101530 +++ b/net/can/proc.c
101531 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101532 void can_init_proc(void)
101533 {
101534 /* create /proc/net/can directory */
101535 - can_dir = proc_mkdir("can", init_net.proc_net);
101536 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101537
101538 if (!can_dir) {
101539 printk(KERN_INFO "can: failed to create /proc/net/can . "
101540 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101541 index 9f02369..e6160e9 100644
101542 --- a/net/ceph/messenger.c
101543 +++ b/net/ceph/messenger.c
101544 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101545 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101546
101547 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101548 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101549 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101550
101551 static struct page *zero_page; /* used in certain error cases */
101552
101553 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101554 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101555 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101556
101557 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101558 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101559 s = addr_str[i];
101560
101561 switch (ss->ss_family) {
101562 diff --git a/net/compat.c b/net/compat.c
101563 index bc8aeef..f9c070c 100644
101564 --- a/net/compat.c
101565 +++ b/net/compat.c
101566 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101567 return -EFAULT;
101568 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101569 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101570 - kmsg->msg_name = compat_ptr(tmp1);
101571 - kmsg->msg_iov = compat_ptr(tmp2);
101572 - kmsg->msg_control = compat_ptr(tmp3);
101573 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101574 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101575 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101576 return 0;
101577 }
101578
101579 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101580
101581 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101582 if (mode == VERIFY_READ) {
101583 - int err = move_addr_to_kernel(kern_msg->msg_name,
101584 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101585 kern_msg->msg_namelen,
101586 kern_address);
101587 if (err < 0)
101588 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101589 }
101590
101591 tot_len = iov_from_user_compat_to_kern(kern_iov,
101592 - (struct compat_iovec __user *)kern_msg->msg_iov,
101593 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101594 kern_msg->msg_iovlen);
101595 if (tot_len >= 0)
101596 kern_msg->msg_iov = kern_iov;
101597 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101598
101599 #define CMSG_COMPAT_FIRSTHDR(msg) \
101600 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101601 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101602 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101603 (struct compat_cmsghdr __user *)NULL)
101604
101605 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101606 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101607 (ucmlen) <= (unsigned long) \
101608 ((mhdr)->msg_controllen - \
101609 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101610 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101611
101612 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101613 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101614 {
101615 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101616 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101617 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101618 msg->msg_controllen)
101619 return NULL;
101620 return (struct compat_cmsghdr __user *)ptr;
101621 @@ -223,7 +223,7 @@ Efault:
101622
101623 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101624 {
101625 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101626 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101627 struct compat_cmsghdr cmhdr;
101628 struct compat_timeval ctv;
101629 struct compat_timespec cts[3];
101630 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101631
101632 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101633 {
101634 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101635 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101636 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101637 int fdnum = scm->fp->count;
101638 struct file **fp = scm->fp->fp;
101639 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101640 return -EFAULT;
101641 old_fs = get_fs();
101642 set_fs(KERNEL_DS);
101643 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101644 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101645 set_fs(old_fs);
101646
101647 return err;
101648 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101649 len = sizeof(ktime);
101650 old_fs = get_fs();
101651 set_fs(KERNEL_DS);
101652 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101653 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101654 set_fs(old_fs);
101655
101656 if (!err) {
101657 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101658 case MCAST_JOIN_GROUP:
101659 case MCAST_LEAVE_GROUP:
101660 {
101661 - struct compat_group_req __user *gr32 = (void *)optval;
101662 + struct compat_group_req __user *gr32 = (void __user *)optval;
101663 struct group_req __user *kgr =
101664 compat_alloc_user_space(sizeof(struct group_req));
101665 u32 interface;
101666 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101667 case MCAST_BLOCK_SOURCE:
101668 case MCAST_UNBLOCK_SOURCE:
101669 {
101670 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101671 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101672 struct group_source_req __user *kgsr = compat_alloc_user_space(
101673 sizeof(struct group_source_req));
101674 u32 interface;
101675 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101676 }
101677 case MCAST_MSFILTER:
101678 {
101679 - struct compat_group_filter __user *gf32 = (void *)optval;
101680 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101681 struct group_filter __user *kgf;
101682 u32 interface, fmode, numsrc;
101683
101684 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101685 char __user *optval, int __user *optlen,
101686 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101687 {
101688 - struct compat_group_filter __user *gf32 = (void *)optval;
101689 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101690 struct group_filter __user *kgf;
101691 int __user *koptlen;
101692 u32 interface, fmode, numsrc;
101693 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101694
101695 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101696 return -EINVAL;
101697 - if (copy_from_user(a, args, nas[call]))
101698 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101699 return -EFAULT;
101700 a0 = a[0];
101701 a1 = a[1];
101702 diff --git a/net/core/datagram.c b/net/core/datagram.c
101703 index fdbc9a8..cd6972c 100644
101704 --- a/net/core/datagram.c
101705 +++ b/net/core/datagram.c
101706 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101707 }
101708
101709 kfree_skb(skb);
101710 - atomic_inc(&sk->sk_drops);
101711 + atomic_inc_unchecked(&sk->sk_drops);
101712 sk_mem_reclaim_partial(sk);
101713
101714 return err;
101715 diff --git a/net/core/dev.c b/net/core/dev.c
101716 index cf8a95f..2837211 100644
101717 --- a/net/core/dev.c
101718 +++ b/net/core/dev.c
101719 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101720 {
101721 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101722 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101723 - atomic_long_inc(&dev->rx_dropped);
101724 + atomic_long_inc_unchecked(&dev->rx_dropped);
101725 kfree_skb(skb);
101726 return NET_RX_DROP;
101727 }
101728 }
101729
101730 if (unlikely(!is_skb_forwardable(dev, skb))) {
101731 - atomic_long_inc(&dev->rx_dropped);
101732 + atomic_long_inc_unchecked(&dev->rx_dropped);
101733 kfree_skb(skb);
101734 return NET_RX_DROP;
101735 }
101736 @@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
101737
101738 struct dev_gso_cb {
101739 void (*destructor)(struct sk_buff *skb);
101740 -};
101741 +} __no_const;
101742
101743 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
101744
101745 @@ -2952,7 +2952,7 @@ recursion_alert:
101746 rc = -ENETDOWN;
101747 rcu_read_unlock_bh();
101748
101749 - atomic_long_inc(&dev->tx_dropped);
101750 + atomic_long_inc_unchecked(&dev->tx_dropped);
101751 kfree_skb(skb);
101752 return rc;
101753 out:
101754 @@ -3296,7 +3296,7 @@ enqueue:
101755
101756 local_irq_restore(flags);
101757
101758 - atomic_long_inc(&skb->dev->rx_dropped);
101759 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101760 kfree_skb(skb);
101761 return NET_RX_DROP;
101762 }
101763 @@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
101764 }
101765 EXPORT_SYMBOL(netif_rx_ni);
101766
101767 -static void net_tx_action(struct softirq_action *h)
101768 +static __latent_entropy void net_tx_action(void)
101769 {
101770 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101771
101772 @@ -3706,7 +3706,7 @@ ncls:
101773 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101774 } else {
101775 drop:
101776 - atomic_long_inc(&skb->dev->rx_dropped);
101777 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101778 kfree_skb(skb);
101779 /* Jamal, now you will not able to escape explaining
101780 * me how you were going to use this. :-)
101781 @@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
101782 }
101783 EXPORT_SYMBOL(netif_napi_del);
101784
101785 -static void net_rx_action(struct softirq_action *h)
101786 +static __latent_entropy void net_rx_action(void)
101787 {
101788 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101789 unsigned long time_limit = jiffies + 2;
101790 @@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101791 } else {
101792 netdev_stats_to_stats64(storage, &dev->stats);
101793 }
101794 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101795 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101796 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101797 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101798 return storage;
101799 }
101800 EXPORT_SYMBOL(dev_get_stats);
101801 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101802 index cf999e0..c59a9754 100644
101803 --- a/net/core/dev_ioctl.c
101804 +++ b/net/core/dev_ioctl.c
101805 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
101806 if (no_module && capable(CAP_NET_ADMIN))
101807 no_module = request_module("netdev-%s", name);
101808 if (no_module && capable(CAP_SYS_MODULE)) {
101809 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101810 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101811 +#else
101812 if (!request_module("%s", name))
101813 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
101814 name);
101815 +#endif
101816 }
101817 }
101818 EXPORT_SYMBOL(dev_load);
101819 diff --git a/net/core/filter.c b/net/core/filter.c
101820 index d814b8a..b5ab778 100644
101821 --- a/net/core/filter.c
101822 +++ b/net/core/filter.c
101823 @@ -559,7 +559,11 @@ do_pass:
101824
101825 /* Unkown instruction. */
101826 default:
101827 - goto err;
101828 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101829 + fp->code, fp->jt, fp->jf, fp->k);
101830 + kfree(addrs);
101831 + BUG();
101832 + return -EINVAL;
101833 }
101834
101835 insn++;
101836 @@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101837 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101838 int pc, ret = 0;
101839
101840 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101841 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101842
101843 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101844 if (!masks)
101845 @@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
101846
101847 /* Expand fp for appending the new filter representation. */
101848 old_fp = fp;
101849 - fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
101850 + fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
101851 if (!fp) {
101852 /* The old_fp is still around in case we couldn't
101853 * allocate new memory, so uncharge on that one.
101854 @@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101855 if (fprog->filter == NULL)
101856 return -EINVAL;
101857
101858 - fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
101859 + fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
101860 if (!fp)
101861 return -ENOMEM;
101862
101863 - memcpy(fp->insns, fprog->filter, fsize);
101864 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101865
101866 fp->len = fprog->len;
101867 /* Since unattached filters are not copied back to user
101868 @@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101869 if (fprog->filter == NULL)
101870 return -EINVAL;
101871
101872 - prog = kmalloc(bpf_fsize, GFP_KERNEL);
101873 + prog = bpf_prog_alloc(bpf_fsize, 0);
101874 if (!prog)
101875 return -ENOMEM;
101876
101877 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
101878 - kfree(prog);
101879 + __bpf_prog_free(prog);
101880 return -EFAULT;
101881 }
101882
101883 @@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101884
101885 err = bpf_prog_store_orig_filter(prog, fprog);
101886 if (err) {
101887 - kfree(prog);
101888 + __bpf_prog_free(prog);
101889 return -ENOMEM;
101890 }
101891
101892 diff --git a/net/core/flow.c b/net/core/flow.c
101893 index a0348fd..6951c76 100644
101894 --- a/net/core/flow.c
101895 +++ b/net/core/flow.c
101896 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101897 static int flow_entry_valid(struct flow_cache_entry *fle,
101898 struct netns_xfrm *xfrm)
101899 {
101900 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101901 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101902 return 0;
101903 if (fle->object && !fle->object->ops->check(fle->object))
101904 return 0;
101905 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101906 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101907 fcp->hash_count++;
101908 }
101909 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101910 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101911 flo = fle->object;
101912 if (!flo)
101913 goto ret_object;
101914 @@ -263,7 +263,7 @@ nocache:
101915 }
101916 flo = resolver(net, key, family, dir, flo, ctx);
101917 if (fle) {
101918 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101919 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101920 if (!IS_ERR(flo))
101921 fle->object = flo;
101922 else
101923 diff --git a/net/core/iovec.c b/net/core/iovec.c
101924 index e1ec45a..e5c6f16 100644
101925 --- a/net/core/iovec.c
101926 +++ b/net/core/iovec.c
101927 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101928 if (m->msg_name && m->msg_namelen) {
101929 if (mode == VERIFY_READ) {
101930 void __user *namep;
101931 - namep = (void __user __force *) m->msg_name;
101932 + namep = (void __force_user *) m->msg_name;
101933 err = move_addr_to_kernel(namep, m->msg_namelen,
101934 address);
101935 if (err < 0)
101936 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101937 }
101938
101939 size = m->msg_iovlen * sizeof(struct iovec);
101940 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101941 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101942 return -EFAULT;
101943
101944 m->msg_iov = iov;
101945 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101946 index ef31fef..8be66d9 100644
101947 --- a/net/core/neighbour.c
101948 +++ b/net/core/neighbour.c
101949 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101950 void __user *buffer, size_t *lenp, loff_t *ppos)
101951 {
101952 int size, ret;
101953 - struct ctl_table tmp = *ctl;
101954 + ctl_table_no_const tmp = *ctl;
101955
101956 tmp.extra1 = &zero;
101957 tmp.extra2 = &unres_qlen_max;
101958 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101959 void __user *buffer,
101960 size_t *lenp, loff_t *ppos)
101961 {
101962 - struct ctl_table tmp = *ctl;
101963 + ctl_table_no_const tmp = *ctl;
101964 int ret;
101965
101966 tmp.extra1 = &zero;
101967 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101968 index 2bf8329..2eb1423 100644
101969 --- a/net/core/net-procfs.c
101970 +++ b/net/core/net-procfs.c
101971 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101972 struct rtnl_link_stats64 temp;
101973 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101974
101975 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101976 + if (gr_proc_is_restricted())
101977 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101978 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101979 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101980 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101981 + else
101982 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101983 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101984 dev->name, stats->rx_bytes, stats->rx_packets,
101985 stats->rx_errors,
101986 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101987 return 0;
101988 }
101989
101990 -static const struct seq_operations dev_seq_ops = {
101991 +const struct seq_operations dev_seq_ops = {
101992 .start = dev_seq_start,
101993 .next = dev_seq_next,
101994 .stop = dev_seq_stop,
101995 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101996
101997 static int softnet_seq_open(struct inode *inode, struct file *file)
101998 {
101999 - return seq_open(file, &softnet_seq_ops);
102000 + return seq_open_restrict(file, &softnet_seq_ops);
102001 }
102002
102003 static const struct file_operations softnet_seq_fops = {
102004 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
102005 else
102006 seq_printf(seq, "%04x", ntohs(pt->type));
102007
102008 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102009 + seq_printf(seq, " %-8s %pf\n",
102010 + pt->dev ? pt->dev->name : "", NULL);
102011 +#else
102012 seq_printf(seq, " %-8s %pf\n",
102013 pt->dev ? pt->dev->name : "", pt->func);
102014 +#endif
102015 }
102016
102017 return 0;
102018 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
102019 index 9dd0669..c52fb1b 100644
102020 --- a/net/core/net-sysfs.c
102021 +++ b/net/core/net-sysfs.c
102022 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
102023 {
102024 struct net_device *netdev = to_net_dev(dev);
102025 return sprintf(buf, fmt_dec,
102026 - atomic_read(&netdev->carrier_changes));
102027 + atomic_read_unchecked(&netdev->carrier_changes));
102028 }
102029 static DEVICE_ATTR_RO(carrier_changes);
102030
102031 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
102032 index 7c6b51a..e9dd57f 100644
102033 --- a/net/core/net_namespace.c
102034 +++ b/net/core/net_namespace.c
102035 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
102036 int error;
102037 LIST_HEAD(net_exit_list);
102038
102039 - list_add_tail(&ops->list, list);
102040 + pax_list_add_tail((struct list_head *)&ops->list, list);
102041 if (ops->init || (ops->id && ops->size)) {
102042 for_each_net(net) {
102043 error = ops_init(ops, net);
102044 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
102045
102046 out_undo:
102047 /* If I have an error cleanup all namespaces I initialized */
102048 - list_del(&ops->list);
102049 + pax_list_del((struct list_head *)&ops->list);
102050 ops_exit_list(ops, &net_exit_list);
102051 ops_free_list(ops, &net_exit_list);
102052 return error;
102053 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
102054 struct net *net;
102055 LIST_HEAD(net_exit_list);
102056
102057 - list_del(&ops->list);
102058 + pax_list_del((struct list_head *)&ops->list);
102059 for_each_net(net)
102060 list_add_tail(&net->exit_list, &net_exit_list);
102061 ops_exit_list(ops, &net_exit_list);
102062 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
102063 mutex_lock(&net_mutex);
102064 error = register_pernet_operations(&pernet_list, ops);
102065 if (!error && (first_device == &pernet_list))
102066 - first_device = &ops->list;
102067 + first_device = (struct list_head *)&ops->list;
102068 mutex_unlock(&net_mutex);
102069 return error;
102070 }
102071 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
102072 index 907fb5e..8260f040b 100644
102073 --- a/net/core/netpoll.c
102074 +++ b/net/core/netpoll.c
102075 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102076 struct udphdr *udph;
102077 struct iphdr *iph;
102078 struct ethhdr *eth;
102079 - static atomic_t ip_ident;
102080 + static atomic_unchecked_t ip_ident;
102081 struct ipv6hdr *ip6h;
102082
102083 udp_len = len + sizeof(*udph);
102084 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102085 put_unaligned(0x45, (unsigned char *)iph);
102086 iph->tos = 0;
102087 put_unaligned(htons(ip_len), &(iph->tot_len));
102088 - iph->id = htons(atomic_inc_return(&ip_ident));
102089 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
102090 iph->frag_off = 0;
102091 iph->ttl = 64;
102092 iph->protocol = IPPROTO_UDP;
102093 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
102094 index 8b849dd..cd88bfc 100644
102095 --- a/net/core/pktgen.c
102096 +++ b/net/core/pktgen.c
102097 @@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
102098 pn->net = net;
102099 INIT_LIST_HEAD(&pn->pktgen_threads);
102100 pn->pktgen_exiting = false;
102101 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
102102 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
102103 if (!pn->proc_dir) {
102104 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
102105 return -ENODEV;
102106 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
102107 index 4921b65..7cb175e 100644
102108 --- a/net/core/rtnetlink.c
102109 +++ b/net/core/rtnetlink.c
102110 @@ -58,7 +58,7 @@ struct rtnl_link {
102111 rtnl_doit_func doit;
102112 rtnl_dumpit_func dumpit;
102113 rtnl_calcit_func calcit;
102114 -};
102115 +} __no_const;
102116
102117 static DEFINE_MUTEX(rtnl_mutex);
102118
102119 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
102120 * to use the ops for creating device. So do not
102121 * fill up dellink as well. That disables rtnl_dellink.
102122 */
102123 - if (ops->setup && !ops->dellink)
102124 - ops->dellink = unregister_netdevice_queue;
102125 + if (ops->setup && !ops->dellink) {
102126 + pax_open_kernel();
102127 + *(void **)&ops->dellink = unregister_netdevice_queue;
102128 + pax_close_kernel();
102129 + }
102130
102131 - list_add_tail(&ops->list, &link_ops);
102132 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
102133 return 0;
102134 }
102135 EXPORT_SYMBOL_GPL(__rtnl_link_register);
102136 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
102137 for_each_net(net) {
102138 __rtnl_kill_links(net, ops);
102139 }
102140 - list_del(&ops->list);
102141 + pax_list_del((struct list_head *)&ops->list);
102142 }
102143 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
102144
102145 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
102146 (dev->ifalias &&
102147 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
102148 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
102149 - atomic_read(&dev->carrier_changes)))
102150 + atomic_read_unchecked(&dev->carrier_changes)))
102151 goto nla_put_failure;
102152
102153 if (1) {
102154 @@ -2781,6 +2784,9 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
102155 if (br_spec) {
102156 nla_for_each_nested(attr, br_spec, rem) {
102157 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
102158 + if (nla_len(attr) < sizeof(flags))
102159 + return -EINVAL;
102160 +
102161 have_flags = true;
102162 flags = nla_get_u16(attr);
102163 break;
102164 @@ -2851,6 +2857,9 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
102165 if (br_spec) {
102166 nla_for_each_nested(attr, br_spec, rem) {
102167 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
102168 + if (nla_len(attr) < sizeof(flags))
102169 + return -EINVAL;
102170 +
102171 have_flags = true;
102172 flags = nla_get_u16(attr);
102173 break;
102174 diff --git a/net/core/scm.c b/net/core/scm.c
102175 index b442e7e..6f5b5a2 100644
102176 --- a/net/core/scm.c
102177 +++ b/net/core/scm.c
102178 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
102179 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102180 {
102181 struct cmsghdr __user *cm
102182 - = (__force struct cmsghdr __user *)msg->msg_control;
102183 + = (struct cmsghdr __force_user *)msg->msg_control;
102184 struct cmsghdr cmhdr;
102185 int cmlen = CMSG_LEN(len);
102186 int err;
102187 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102188 err = -EFAULT;
102189 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
102190 goto out;
102191 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102192 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102193 goto out;
102194 cmlen = CMSG_SPACE(len);
102195 if (msg->msg_controllen < cmlen)
102196 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102197 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102198 {
102199 struct cmsghdr __user *cm
102200 - = (__force struct cmsghdr __user*)msg->msg_control;
102201 + = (struct cmsghdr __force_user *)msg->msg_control;
102202
102203 int fdmax = 0;
102204 int fdnum = scm->fp->count;
102205 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102206 if (fdnum < fdmax)
102207 fdmax = fdnum;
102208
102209 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102210 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102211 i++, cmfptr++)
102212 {
102213 struct socket *sock;
102214 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102215 index 8d28969..4d36260 100644
102216 --- a/net/core/skbuff.c
102217 +++ b/net/core/skbuff.c
102218 @@ -360,18 +360,29 @@ refill:
102219 goto end;
102220 }
102221 nc->frag.size = PAGE_SIZE << order;
102222 -recycle:
102223 - atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
102224 + /* Even if we own the page, we do not use atomic_set().
102225 + * This would break get_page_unless_zero() users.
102226 + */
102227 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
102228 + &nc->frag.page->_count);
102229 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102230 nc->frag.offset = 0;
102231 }
102232
102233 if (nc->frag.offset + fragsz > nc->frag.size) {
102234 - /* avoid unnecessary locked operations if possible */
102235 - if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
102236 - atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
102237 - goto recycle;
102238 - goto refill;
102239 + if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
102240 + if (!atomic_sub_and_test(nc->pagecnt_bias,
102241 + &nc->frag.page->_count))
102242 + goto refill;
102243 + /* OK, page count is 0, we can safely set it */
102244 + atomic_set(&nc->frag.page->_count,
102245 + NETDEV_PAGECNT_MAX_BIAS);
102246 + } else {
102247 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
102248 + &nc->frag.page->_count);
102249 + }
102250 + nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102251 + nc->frag.offset = 0;
102252 }
102253
102254 data = page_address(nc->frag.page) + nc->frag.offset;
102255 @@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
102256 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102257 int len, __wsum csum)
102258 {
102259 - const struct skb_checksum_ops ops = {
102260 + static const struct skb_checksum_ops ops = {
102261 .update = csum_partial_ext,
102262 .combine = csum_block_add_ext,
102263 };
102264 @@ -3237,13 +3248,15 @@ void __init skb_init(void)
102265 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102266 sizeof(struct sk_buff),
102267 0,
102268 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102269 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102270 + SLAB_NO_SANITIZE,
102271 NULL);
102272 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102273 (2*sizeof(struct sk_buff)) +
102274 sizeof(atomic_t),
102275 0,
102276 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102277 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102278 + SLAB_NO_SANITIZE,
102279 NULL);
102280 }
102281
102282 diff --git a/net/core/sock.c b/net/core/sock.c
102283 index 9c3f823..bd8c884 100644
102284 --- a/net/core/sock.c
102285 +++ b/net/core/sock.c
102286 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102287 struct sk_buff_head *list = &sk->sk_receive_queue;
102288
102289 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102290 - atomic_inc(&sk->sk_drops);
102291 + atomic_inc_unchecked(&sk->sk_drops);
102292 trace_sock_rcvqueue_full(sk, skb);
102293 return -ENOMEM;
102294 }
102295 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102296 return err;
102297
102298 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102299 - atomic_inc(&sk->sk_drops);
102300 + atomic_inc_unchecked(&sk->sk_drops);
102301 return -ENOBUFS;
102302 }
102303
102304 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102305 skb_dst_force(skb);
102306
102307 spin_lock_irqsave(&list->lock, flags);
102308 - skb->dropcount = atomic_read(&sk->sk_drops);
102309 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102310 __skb_queue_tail(list, skb);
102311 spin_unlock_irqrestore(&list->lock, flags);
102312
102313 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102314 skb->dev = NULL;
102315
102316 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102317 - atomic_inc(&sk->sk_drops);
102318 + atomic_inc_unchecked(&sk->sk_drops);
102319 goto discard_and_relse;
102320 }
102321 if (nested)
102322 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102323 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102324 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102325 bh_unlock_sock(sk);
102326 - atomic_inc(&sk->sk_drops);
102327 + atomic_inc_unchecked(&sk->sk_drops);
102328 goto discard_and_relse;
102329 }
102330
102331 @@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102332 struct timeval tm;
102333 } v;
102334
102335 - int lv = sizeof(int);
102336 - int len;
102337 + unsigned int lv = sizeof(int);
102338 + unsigned int len;
102339
102340 if (get_user(len, optlen))
102341 return -EFAULT;
102342 - if (len < 0)
102343 + if (len > INT_MAX)
102344 return -EINVAL;
102345
102346 memset(&v, 0, sizeof(v));
102347 @@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102348
102349 case SO_PEERNAME:
102350 {
102351 - char address[128];
102352 + char address[_K_SS_MAXSIZE];
102353
102354 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102355 return -ENOTCONN;
102356 - if (lv < len)
102357 + if (lv < len || sizeof address < len)
102358 return -EINVAL;
102359 if (copy_to_user(optval, address, len))
102360 return -EFAULT;
102361 @@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102362
102363 if (len > lv)
102364 len = lv;
102365 - if (copy_to_user(optval, &v, len))
102366 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102367 return -EFAULT;
102368 lenout:
102369 if (put_user(len, optlen))
102370 @@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
102371 */
102372 void sock_kfree_s(struct sock *sk, void *mem, int size)
102373 {
102374 + if (WARN_ON_ONCE(!mem))
102375 + return;
102376 kfree(mem);
102377 atomic_sub(size, &sk->sk_omem_alloc);
102378 }
102379 @@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102380 */
102381 smp_wmb();
102382 atomic_set(&sk->sk_refcnt, 1);
102383 - atomic_set(&sk->sk_drops, 0);
102384 + atomic_set_unchecked(&sk->sk_drops, 0);
102385 }
102386 EXPORT_SYMBOL(sock_init_data);
102387
102388 @@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102389 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102390 int level, int type)
102391 {
102392 + struct sock_extended_err ee;
102393 struct sock_exterr_skb *serr;
102394 struct sk_buff *skb, *skb2;
102395 int copied, err;
102396 @@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102397 sock_recv_timestamp(msg, sk, skb);
102398
102399 serr = SKB_EXT_ERR(skb);
102400 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102401 + ee = serr->ee;
102402 + put_cmsg(msg, level, type, sizeof ee, &ee);
102403
102404 msg->msg_flags |= MSG_ERRQUEUE;
102405 err = copied;
102406 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102407 index ad704c7..ca48aff 100644
102408 --- a/net/core/sock_diag.c
102409 +++ b/net/core/sock_diag.c
102410 @@ -9,26 +9,33 @@
102411 #include <linux/inet_diag.h>
102412 #include <linux/sock_diag.h>
102413
102414 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102415 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102416 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102417 static DEFINE_MUTEX(sock_diag_table_mutex);
102418
102419 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102420 {
102421 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102422 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102423 cookie[1] != INET_DIAG_NOCOOKIE) &&
102424 ((u32)(unsigned long)sk != cookie[0] ||
102425 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102426 return -ESTALE;
102427 else
102428 +#endif
102429 return 0;
102430 }
102431 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102432
102433 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102434 {
102435 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102436 + cookie[0] = 0;
102437 + cookie[1] = 0;
102438 +#else
102439 cookie[0] = (u32)(unsigned long)sk;
102440 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102441 +#endif
102442 }
102443 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102444
102445 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102446 mutex_lock(&sock_diag_table_mutex);
102447 if (sock_diag_handlers[hndl->family])
102448 err = -EBUSY;
102449 - else
102450 + else {
102451 + pax_open_kernel();
102452 sock_diag_handlers[hndl->family] = hndl;
102453 + pax_close_kernel();
102454 + }
102455 mutex_unlock(&sock_diag_table_mutex);
102456
102457 return err;
102458 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102459
102460 mutex_lock(&sock_diag_table_mutex);
102461 BUG_ON(sock_diag_handlers[family] != hnld);
102462 + pax_open_kernel();
102463 sock_diag_handlers[family] = NULL;
102464 + pax_close_kernel();
102465 mutex_unlock(&sock_diag_table_mutex);
102466 }
102467 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102468 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102469 index cf9cd13..50683950 100644
102470 --- a/net/core/sysctl_net_core.c
102471 +++ b/net/core/sysctl_net_core.c
102472 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102473 {
102474 unsigned int orig_size, size;
102475 int ret, i;
102476 - struct ctl_table tmp = {
102477 + ctl_table_no_const tmp = {
102478 .data = &size,
102479 .maxlen = sizeof(size),
102480 .mode = table->mode
102481 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102482 void __user *buffer, size_t *lenp, loff_t *ppos)
102483 {
102484 char id[IFNAMSIZ];
102485 - struct ctl_table tbl = {
102486 + ctl_table_no_const tbl = {
102487 .data = id,
102488 .maxlen = IFNAMSIZ,
102489 };
102490 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102491 .mode = 0644,
102492 .proc_handler = proc_dointvec
102493 },
102494 -#ifdef CONFIG_BPF_JIT
102495 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102496 {
102497 .procname = "bpf_jit_enable",
102498 .data = &bpf_jit_enable,
102499 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102500
102501 static __net_init int sysctl_core_net_init(struct net *net)
102502 {
102503 - struct ctl_table *tbl;
102504 + ctl_table_no_const *tbl = NULL;
102505
102506 net->core.sysctl_somaxconn = SOMAXCONN;
102507
102508 - tbl = netns_core_table;
102509 if (!net_eq(net, &init_net)) {
102510 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102511 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102512 if (tbl == NULL)
102513 goto err_dup;
102514
102515 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102516 if (net->user_ns != &init_user_ns) {
102517 tbl[0].procname = NULL;
102518 }
102519 - }
102520 -
102521 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102522 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102523 + } else
102524 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102525 if (net->core.sysctl_hdr == NULL)
102526 goto err_reg;
102527
102528 return 0;
102529
102530 err_reg:
102531 - if (tbl != netns_core_table)
102532 - kfree(tbl);
102533 + kfree(tbl);
102534 err_dup:
102535 return -ENOMEM;
102536 }
102537 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102538 kfree(tbl);
102539 }
102540
102541 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102542 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102543 .init = sysctl_core_net_init,
102544 .exit = sysctl_core_net_exit,
102545 };
102546 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102547 index ae011b4..d2d18bf 100644
102548 --- a/net/decnet/af_decnet.c
102549 +++ b/net/decnet/af_decnet.c
102550 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
102551 .sysctl_rmem = sysctl_decnet_rmem,
102552 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102553 .obj_size = sizeof(struct dn_sock),
102554 + .slab_flags = SLAB_USERCOPY,
102555 };
102556
102557 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102558 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102559 index 3b726f3..1af6368 100644
102560 --- a/net/decnet/dn_dev.c
102561 +++ b/net/decnet/dn_dev.c
102562 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
102563 .extra1 = &min_t3,
102564 .extra2 = &max_t3
102565 },
102566 - {0}
102567 + { }
102568 },
102569 };
102570
102571 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102572 index 5325b54..a0d4d69 100644
102573 --- a/net/decnet/sysctl_net_decnet.c
102574 +++ b/net/decnet/sysctl_net_decnet.c
102575 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102576
102577 if (len > *lenp) len = *lenp;
102578
102579 - if (copy_to_user(buffer, addr, len))
102580 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102581 return -EFAULT;
102582
102583 *lenp = len;
102584 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102585
102586 if (len > *lenp) len = *lenp;
102587
102588 - if (copy_to_user(buffer, devname, len))
102589 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102590 return -EFAULT;
102591
102592 *lenp = len;
102593 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102594 index a2c7e4c..3dc9f67 100644
102595 --- a/net/hsr/hsr_netlink.c
102596 +++ b/net/hsr/hsr_netlink.c
102597 @@ -102,7 +102,7 @@ nla_put_failure:
102598 return -EMSGSIZE;
102599 }
102600
102601 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102602 +static struct rtnl_link_ops hsr_link_ops = {
102603 .kind = "hsr",
102604 .maxtype = IFLA_HSR_MAX,
102605 .policy = hsr_policy,
102606 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102607 index 6591d27..499b971 100644
102608 --- a/net/ieee802154/6lowpan_rtnl.c
102609 +++ b/net/ieee802154/6lowpan_rtnl.c
102610 @@ -590,7 +590,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102611 dev_put(real_dev);
102612 }
102613
102614 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102615 +static struct rtnl_link_ops lowpan_link_ops = {
102616 .kind = "lowpan",
102617 .priv_size = sizeof(struct lowpan_dev_info),
102618 .setup = lowpan_setup,
102619 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102620 index 32755cb..236d827 100644
102621 --- a/net/ieee802154/reassembly.c
102622 +++ b/net/ieee802154/reassembly.c
102623 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102624
102625 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102626 {
102627 - struct ctl_table *table;
102628 + ctl_table_no_const *table = NULL;
102629 struct ctl_table_header *hdr;
102630 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102631 net_ieee802154_lowpan(net);
102632
102633 - table = lowpan_frags_ns_ctl_table;
102634 if (!net_eq(net, &init_net)) {
102635 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102636 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102637 GFP_KERNEL);
102638 if (table == NULL)
102639 goto err_alloc;
102640 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102641 /* Don't export sysctls to unprivileged users */
102642 if (net->user_ns != &init_user_ns)
102643 table[0].procname = NULL;
102644 - }
102645 -
102646 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102647 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102648 + } else
102649 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102650 if (hdr == NULL)
102651 goto err_reg;
102652
102653 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102654 return 0;
102655
102656 err_reg:
102657 - if (!net_eq(net, &init_net))
102658 - kfree(table);
102659 + kfree(table);
102660 err_alloc:
102661 return -ENOMEM;
102662 }
102663 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102664 index bf78bc3..f6dbf03 100644
102665 --- a/net/ipv4/af_inet.c
102666 +++ b/net/ipv4/af_inet.c
102667 @@ -1427,7 +1427,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102668 return ip_recv_error(sk, msg, len, addr_len);
102669 #if IS_ENABLED(CONFIG_IPV6)
102670 if (sk->sk_family == AF_INET6)
102671 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102672 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102673 #endif
102674 return -EINVAL;
102675 }
102676 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102677 index 214882e..ec032f6 100644
102678 --- a/net/ipv4/devinet.c
102679 +++ b/net/ipv4/devinet.c
102680 @@ -69,7 +69,8 @@
102681
102682 static struct ipv4_devconf ipv4_devconf = {
102683 .data = {
102684 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102685 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102686 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102687 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102688 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102689 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102690 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102691
102692 static struct ipv4_devconf ipv4_devconf_dflt = {
102693 .data = {
102694 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102695 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102696 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102697 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102698 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102699 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102700 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102701 idx = 0;
102702 head = &net->dev_index_head[h];
102703 rcu_read_lock();
102704 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102705 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102706 net->dev_base_seq;
102707 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102708 if (idx < s_idx)
102709 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102710 idx = 0;
102711 head = &net->dev_index_head[h];
102712 rcu_read_lock();
102713 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102714 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102715 net->dev_base_seq;
102716 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102717 if (idx < s_idx)
102718 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102719 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102720 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102721
102722 -static struct devinet_sysctl_table {
102723 +static const struct devinet_sysctl_table {
102724 struct ctl_table_header *sysctl_header;
102725 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102726 } devinet_sysctl = {
102727 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102728 int err;
102729 struct ipv4_devconf *all, *dflt;
102730 #ifdef CONFIG_SYSCTL
102731 - struct ctl_table *tbl = ctl_forward_entry;
102732 + ctl_table_no_const *tbl = NULL;
102733 struct ctl_table_header *forw_hdr;
102734 #endif
102735
102736 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102737 goto err_alloc_dflt;
102738
102739 #ifdef CONFIG_SYSCTL
102740 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102741 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102742 if (tbl == NULL)
102743 goto err_alloc_ctl;
102744
102745 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102746 goto err_reg_dflt;
102747
102748 err = -ENOMEM;
102749 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102750 + if (!net_eq(net, &init_net))
102751 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102752 + else
102753 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102754 if (forw_hdr == NULL)
102755 goto err_reg_ctl;
102756 net->ipv4.forw_hdr = forw_hdr;
102757 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102758 err_reg_dflt:
102759 __devinet_sysctl_unregister(all);
102760 err_reg_all:
102761 - if (tbl != ctl_forward_entry)
102762 - kfree(tbl);
102763 + kfree(tbl);
102764 err_alloc_ctl:
102765 #endif
102766 if (dflt != &ipv4_devconf_dflt)
102767 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102768 index 255aa99..45c78f8 100644
102769 --- a/net/ipv4/fib_frontend.c
102770 +++ b/net/ipv4/fib_frontend.c
102771 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102772 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102773 fib_sync_up(dev);
102774 #endif
102775 - atomic_inc(&net->ipv4.dev_addr_genid);
102776 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102777 rt_cache_flush(dev_net(dev));
102778 break;
102779 case NETDEV_DOWN:
102780 fib_del_ifaddr(ifa, NULL);
102781 - atomic_inc(&net->ipv4.dev_addr_genid);
102782 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102783 if (ifa->ifa_dev->ifa_list == NULL) {
102784 /* Last address was deleted from this interface.
102785 * Disable IP.
102786 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102787 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102788 fib_sync_up(dev);
102789 #endif
102790 - atomic_inc(&net->ipv4.dev_addr_genid);
102791 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102792 rt_cache_flush(net);
102793 break;
102794 case NETDEV_DOWN:
102795 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102796 index 4a74ea8..32335a7 100644
102797 --- a/net/ipv4/fib_semantics.c
102798 +++ b/net/ipv4/fib_semantics.c
102799 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102800 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102801 nh->nh_gw,
102802 nh->nh_parent->fib_scope);
102803 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102804 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102805
102806 return nh->nh_saddr;
102807 }
102808 diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
102809 index 657d80c..0ad744a 100644
102810 --- a/net/ipv4/gre_offload.c
102811 +++ b/net/ipv4/gre_offload.c
102812 @@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
102813 if (csum)
102814 skb->encap_hdr_csum = 1;
102815
102816 - if (unlikely(!pskb_may_pull(skb, ghl)))
102817 - goto out;
102818 -
102819 /* setup inner skb. */
102820 skb->protocol = greh->protocol;
102821 skb->encapsulation = 0;
102822
102823 + if (unlikely(!pskb_may_pull(skb, ghl)))
102824 + goto out;
102825 +
102826 __skb_pull(skb, ghl);
102827 skb_reset_mac_header(skb);
102828 skb_set_network_header(skb, skb_inner_network_offset(skb));
102829 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102830 index 43116e8..ba0916a8 100644
102831 --- a/net/ipv4/inet_hashtables.c
102832 +++ b/net/ipv4/inet_hashtables.c
102833 @@ -18,6 +18,7 @@
102834 #include <linux/sched.h>
102835 #include <linux/slab.h>
102836 #include <linux/wait.h>
102837 +#include <linux/security.h>
102838
102839 #include <net/inet_connection_sock.h>
102840 #include <net/inet_hashtables.h>
102841 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102842 return inet_ehashfn(net, laddr, lport, faddr, fport);
102843 }
102844
102845 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102846 +
102847 /*
102848 * Allocate and initialize a new local port bind bucket.
102849 * The bindhash mutex for snum's hash chain must be held here.
102850 @@ -554,6 +557,8 @@ ok:
102851 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102852 spin_unlock(&head->lock);
102853
102854 + gr_update_task_in_ip_table(inet_sk(sk));
102855 +
102856 if (tw) {
102857 inet_twsk_deschedule(tw, death_row);
102858 while (twrefcnt) {
102859 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102860 index bd5f592..e80e605 100644
102861 --- a/net/ipv4/inetpeer.c
102862 +++ b/net/ipv4/inetpeer.c
102863 @@ -482,7 +482,7 @@ relookup:
102864 if (p) {
102865 p->daddr = *daddr;
102866 atomic_set(&p->refcnt, 1);
102867 - atomic_set(&p->rid, 0);
102868 + atomic_set_unchecked(&p->rid, 0);
102869 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102870 p->rate_tokens = 0;
102871 /* 60*HZ is arbitrary, but chosen enough high so that the first
102872 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102873 index 15f0e2b..8cf8177 100644
102874 --- a/net/ipv4/ip_fragment.c
102875 +++ b/net/ipv4/ip_fragment.c
102876 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102877 return 0;
102878
102879 start = qp->rid;
102880 - end = atomic_inc_return(&peer->rid);
102881 + end = atomic_inc_return_unchecked(&peer->rid);
102882 qp->rid = end;
102883
102884 rc = qp->q.fragments && (end - start) > max;
102885 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102886
102887 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102888 {
102889 - struct ctl_table *table;
102890 + ctl_table_no_const *table = NULL;
102891 struct ctl_table_header *hdr;
102892
102893 - table = ip4_frags_ns_ctl_table;
102894 if (!net_eq(net, &init_net)) {
102895 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102896 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102897 if (table == NULL)
102898 goto err_alloc;
102899
102900 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102901 /* Don't export sysctls to unprivileged users */
102902 if (net->user_ns != &init_user_ns)
102903 table[0].procname = NULL;
102904 - }
102905 + hdr = register_net_sysctl(net, "net/ipv4", table);
102906 + } else
102907 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102908
102909 - hdr = register_net_sysctl(net, "net/ipv4", table);
102910 if (hdr == NULL)
102911 goto err_reg;
102912
102913 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102914 return 0;
102915
102916 err_reg:
102917 - if (!net_eq(net, &init_net))
102918 - kfree(table);
102919 + kfree(table);
102920 err_alloc:
102921 return -ENOMEM;
102922 }
102923 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102924 index 9b84254..c776611 100644
102925 --- a/net/ipv4/ip_gre.c
102926 +++ b/net/ipv4/ip_gre.c
102927 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102928 module_param(log_ecn_error, bool, 0644);
102929 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102930
102931 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102932 +static struct rtnl_link_ops ipgre_link_ops;
102933 static int ipgre_tunnel_init(struct net_device *dev);
102934
102935 static int ipgre_net_id __read_mostly;
102936 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102937 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
102938 };
102939
102940 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102941 +static struct rtnl_link_ops ipgre_link_ops = {
102942 .kind = "gre",
102943 .maxtype = IFLA_GRE_MAX,
102944 .policy = ipgre_policy,
102945 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102946 .fill_info = ipgre_fill_info,
102947 };
102948
102949 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102950 +static struct rtnl_link_ops ipgre_tap_ops = {
102951 .kind = "gretap",
102952 .maxtype = IFLA_GRE_MAX,
102953 .policy = ipgre_policy,
102954 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102955 index 3d4da2c..40f9c29 100644
102956 --- a/net/ipv4/ip_input.c
102957 +++ b/net/ipv4/ip_input.c
102958 @@ -147,6 +147,10 @@
102959 #include <linux/mroute.h>
102960 #include <linux/netlink.h>
102961
102962 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102963 +extern int grsec_enable_blackhole;
102964 +#endif
102965 +
102966 /*
102967 * Process Router Attention IP option (RFC 2113)
102968 */
102969 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102970 if (!raw) {
102971 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102972 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102973 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102974 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102975 +#endif
102976 icmp_send(skb, ICMP_DEST_UNREACH,
102977 ICMP_PROT_UNREACH, 0);
102978 }
102979 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102980 index c43a1e2..73cbbe1 100644
102981 --- a/net/ipv4/ip_output.c
102982 +++ b/net/ipv4/ip_output.c
102983 @@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
102984 */
102985 features = netif_skb_features(skb);
102986 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
102987 - if (IS_ERR(segs)) {
102988 + if (IS_ERR_OR_NULL(segs)) {
102989 kfree_skb(skb);
102990 return -ENOMEM;
102991 }
102992 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102993 index 2407e5d..edc2f1a 100644
102994 --- a/net/ipv4/ip_sockglue.c
102995 +++ b/net/ipv4/ip_sockglue.c
102996 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102997 len = min_t(unsigned int, len, opt->optlen);
102998 if (put_user(len, optlen))
102999 return -EFAULT;
103000 - if (copy_to_user(optval, opt->__data, len))
103001 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
103002 + copy_to_user(optval, opt->__data, len))
103003 return -EFAULT;
103004 return 0;
103005 }
103006 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
103007 if (sk->sk_type != SOCK_STREAM)
103008 return -ENOPROTOOPT;
103009
103010 - msg.msg_control = (__force void *) optval;
103011 + msg.msg_control = (__force_kernel void *) optval;
103012 msg.msg_controllen = len;
103013 msg.msg_flags = flags;
103014
103015 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
103016 index 6073952..8449cf5 100644
103017 --- a/net/ipv4/ip_vti.c
103018 +++ b/net/ipv4/ip_vti.c
103019 @@ -45,7 +45,7 @@
103020 #include <net/net_namespace.h>
103021 #include <net/netns/generic.h>
103022
103023 -static struct rtnl_link_ops vti_link_ops __read_mostly;
103024 +static struct rtnl_link_ops vti_link_ops;
103025
103026 static int vti_net_id __read_mostly;
103027 static int vti_tunnel_init(struct net_device *dev);
103028 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
103029 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
103030 };
103031
103032 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
103033 +static struct rtnl_link_ops vti_link_ops = {
103034 .kind = "vti",
103035 .maxtype = IFLA_VTI_MAX,
103036 .policy = vti_policy,
103037 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
103038 index 5bbef4f..5bc4fb6 100644
103039 --- a/net/ipv4/ipconfig.c
103040 +++ b/net/ipv4/ipconfig.c
103041 @@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
103042
103043 mm_segment_t oldfs = get_fs();
103044 set_fs(get_ds());
103045 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
103046 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
103047 set_fs(oldfs);
103048 return res;
103049 }
103050 @@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
103051
103052 mm_segment_t oldfs = get_fs();
103053 set_fs(get_ds());
103054 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
103055 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
103056 set_fs(oldfs);
103057 return res;
103058 }
103059 @@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
103060
103061 mm_segment_t oldfs = get_fs();
103062 set_fs(get_ds());
103063 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
103064 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
103065 set_fs(oldfs);
103066 return res;
103067 }
103068 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
103069 index 62eaa00..29b2dc2 100644
103070 --- a/net/ipv4/ipip.c
103071 +++ b/net/ipv4/ipip.c
103072 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
103073 static int ipip_net_id __read_mostly;
103074
103075 static int ipip_tunnel_init(struct net_device *dev);
103076 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
103077 +static struct rtnl_link_ops ipip_link_ops;
103078
103079 static int ipip_err(struct sk_buff *skb, u32 info)
103080 {
103081 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
103082 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
103083 };
103084
103085 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
103086 +static struct rtnl_link_ops ipip_link_ops = {
103087 .kind = "ipip",
103088 .maxtype = IFLA_IPTUN_MAX,
103089 .policy = ipip_policy,
103090 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
103091 index f95b6f9..2ee2097 100644
103092 --- a/net/ipv4/netfilter/arp_tables.c
103093 +++ b/net/ipv4/netfilter/arp_tables.c
103094 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
103095 #endif
103096
103097 static int get_info(struct net *net, void __user *user,
103098 - const int *len, int compat)
103099 + int len, int compat)
103100 {
103101 char name[XT_TABLE_MAXNAMELEN];
103102 struct xt_table *t;
103103 int ret;
103104
103105 - if (*len != sizeof(struct arpt_getinfo)) {
103106 - duprintf("length %u != %Zu\n", *len,
103107 + if (len != sizeof(struct arpt_getinfo)) {
103108 + duprintf("length %u != %Zu\n", len,
103109 sizeof(struct arpt_getinfo));
103110 return -EINVAL;
103111 }
103112 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
103113 info.size = private->size;
103114 strcpy(info.name, name);
103115
103116 - if (copy_to_user(user, &info, *len) != 0)
103117 + if (copy_to_user(user, &info, len) != 0)
103118 ret = -EFAULT;
103119 else
103120 ret = 0;
103121 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
103122
103123 switch (cmd) {
103124 case ARPT_SO_GET_INFO:
103125 - ret = get_info(sock_net(sk), user, len, 1);
103126 + ret = get_info(sock_net(sk), user, *len, 1);
103127 break;
103128 case ARPT_SO_GET_ENTRIES:
103129 ret = compat_get_entries(sock_net(sk), user, len);
103130 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
103131
103132 switch (cmd) {
103133 case ARPT_SO_GET_INFO:
103134 - ret = get_info(sock_net(sk), user, len, 0);
103135 + ret = get_info(sock_net(sk), user, *len, 0);
103136 break;
103137
103138 case ARPT_SO_GET_ENTRIES:
103139 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
103140 index 99e810f..3711b81 100644
103141 --- a/net/ipv4/netfilter/ip_tables.c
103142 +++ b/net/ipv4/netfilter/ip_tables.c
103143 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
103144 #endif
103145
103146 static int get_info(struct net *net, void __user *user,
103147 - const int *len, int compat)
103148 + int len, int compat)
103149 {
103150 char name[XT_TABLE_MAXNAMELEN];
103151 struct xt_table *t;
103152 int ret;
103153
103154 - if (*len != sizeof(struct ipt_getinfo)) {
103155 - duprintf("length %u != %zu\n", *len,
103156 + if (len != sizeof(struct ipt_getinfo)) {
103157 + duprintf("length %u != %zu\n", len,
103158 sizeof(struct ipt_getinfo));
103159 return -EINVAL;
103160 }
103161 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
103162 info.size = private->size;
103163 strcpy(info.name, name);
103164
103165 - if (copy_to_user(user, &info, *len) != 0)
103166 + if (copy_to_user(user, &info, len) != 0)
103167 ret = -EFAULT;
103168 else
103169 ret = 0;
103170 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103171
103172 switch (cmd) {
103173 case IPT_SO_GET_INFO:
103174 - ret = get_info(sock_net(sk), user, len, 1);
103175 + ret = get_info(sock_net(sk), user, *len, 1);
103176 break;
103177 case IPT_SO_GET_ENTRIES:
103178 ret = compat_get_entries(sock_net(sk), user, len);
103179 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103180
103181 switch (cmd) {
103182 case IPT_SO_GET_INFO:
103183 - ret = get_info(sock_net(sk), user, len, 0);
103184 + ret = get_info(sock_net(sk), user, *len, 0);
103185 break;
103186
103187 case IPT_SO_GET_ENTRIES:
103188 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103189 index 2510c02..cfb34fa 100644
103190 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
103191 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103192 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
103193 spin_lock_init(&cn->lock);
103194
103195 #ifdef CONFIG_PROC_FS
103196 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
103197 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
103198 if (!cn->procdir) {
103199 pr_err("Unable to proc dir entry\n");
103200 return -ENOMEM;
103201 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
103202 index b503a30..c43e3e1 100644
103203 --- a/net/ipv4/ping.c
103204 +++ b/net/ipv4/ping.c
103205 @@ -59,7 +59,7 @@ struct ping_table {
103206 };
103207
103208 static struct ping_table ping_table;
103209 -struct pingv6_ops pingv6_ops;
103210 +struct pingv6_ops *pingv6_ops;
103211 EXPORT_SYMBOL_GPL(pingv6_ops);
103212
103213 static u16 ping_port_rover;
103214 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103215 return -ENODEV;
103216 }
103217 }
103218 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
103219 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
103220 scoped);
103221 rcu_read_unlock();
103222
103223 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103224 }
103225 #if IS_ENABLED(CONFIG_IPV6)
103226 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103227 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103228 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103229 #endif
103230 }
103231
103232 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103233 info, (u8 *)icmph);
103234 #if IS_ENABLED(CONFIG_IPV6)
103235 } else if (family == AF_INET6) {
103236 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103237 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103238 info, (u8 *)icmph);
103239 #endif
103240 }
103241 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103242 }
103243
103244 if (inet6_sk(sk)->rxopt.all)
103245 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103246 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103247 if (skb->protocol == htons(ETH_P_IPV6) &&
103248 inet6_sk(sk)->rxopt.all)
103249 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103250 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103251 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103252 ip_cmsg_recv(msg, skb);
103253 #endif
103254 @@ -1105,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103255 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103256 0, sock_i_ino(sp),
103257 atomic_read(&sp->sk_refcnt), sp,
103258 - atomic_read(&sp->sk_drops));
103259 + atomic_read_unchecked(&sp->sk_drops));
103260 }
103261
103262 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103263 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103264 index 739db31..74f0210 100644
103265 --- a/net/ipv4/raw.c
103266 +++ b/net/ipv4/raw.c
103267 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103268 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103269 {
103270 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103271 - atomic_inc(&sk->sk_drops);
103272 + atomic_inc_unchecked(&sk->sk_drops);
103273 kfree_skb(skb);
103274 return NET_RX_DROP;
103275 }
103276 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103277
103278 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103279 {
103280 + struct icmp_filter filter;
103281 +
103282 if (optlen > sizeof(struct icmp_filter))
103283 optlen = sizeof(struct icmp_filter);
103284 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103285 + if (copy_from_user(&filter, optval, optlen))
103286 return -EFAULT;
103287 + raw_sk(sk)->filter = filter;
103288 return 0;
103289 }
103290
103291 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103292 {
103293 int len, ret = -EFAULT;
103294 + struct icmp_filter filter;
103295
103296 if (get_user(len, optlen))
103297 goto out;
103298 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103299 if (len > sizeof(struct icmp_filter))
103300 len = sizeof(struct icmp_filter);
103301 ret = -EFAULT;
103302 - if (put_user(len, optlen) ||
103303 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103304 + filter = raw_sk(sk)->filter;
103305 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103306 goto out;
103307 ret = 0;
103308 out: return ret;
103309 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103310 0, 0L, 0,
103311 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103312 0, sock_i_ino(sp),
103313 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103314 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103315 }
103316
103317 static int raw_seq_show(struct seq_file *seq, void *v)
103318 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103319 index 29836f8..bd1e2ba 100644
103320 --- a/net/ipv4/route.c
103321 +++ b/net/ipv4/route.c
103322 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103323
103324 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103325 {
103326 - return seq_open(file, &rt_cache_seq_ops);
103327 + return seq_open_restrict(file, &rt_cache_seq_ops);
103328 }
103329
103330 static const struct file_operations rt_cache_seq_fops = {
103331 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103332
103333 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103334 {
103335 - return seq_open(file, &rt_cpu_seq_ops);
103336 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103337 }
103338
103339 static const struct file_operations rt_cpu_seq_fops = {
103340 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103341
103342 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103343 {
103344 - return single_open(file, rt_acct_proc_show, NULL);
103345 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103346 }
103347
103348 static const struct file_operations rt_acct_proc_fops = {
103349 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103350
103351 #define IP_IDENTS_SZ 2048u
103352 struct ip_ident_bucket {
103353 - atomic_t id;
103354 + atomic_unchecked_t id;
103355 u32 stamp32;
103356 };
103357
103358 -static struct ip_ident_bucket *ip_idents __read_mostly;
103359 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103360
103361 /* In order to protect privacy, we add a perturbation to identifiers
103362 * if one generator is seldom used. This makes hard for an attacker
103363 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103364 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103365 delta = prandom_u32_max(now - old);
103366
103367 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103368 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103369 }
103370 EXPORT_SYMBOL(ip_idents_reserve);
103371
103372 @@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103373 .maxlen = sizeof(int),
103374 .mode = 0200,
103375 .proc_handler = ipv4_sysctl_rtcache_flush,
103376 + .extra1 = &init_net,
103377 },
103378 { },
103379 };
103380
103381 static __net_init int sysctl_route_net_init(struct net *net)
103382 {
103383 - struct ctl_table *tbl;
103384 + ctl_table_no_const *tbl = NULL;
103385
103386 - tbl = ipv4_route_flush_table;
103387 if (!net_eq(net, &init_net)) {
103388 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103389 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103390 if (tbl == NULL)
103391 goto err_dup;
103392
103393 /* Don't export sysctls to unprivileged users */
103394 if (net->user_ns != &init_user_ns)
103395 tbl[0].procname = NULL;
103396 - }
103397 - tbl[0].extra1 = net;
103398 + tbl[0].extra1 = net;
103399 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103400 + } else
103401 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103402
103403 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103404 if (net->ipv4.route_hdr == NULL)
103405 goto err_reg;
103406 return 0;
103407
103408 err_reg:
103409 - if (tbl != ipv4_route_flush_table)
103410 - kfree(tbl);
103411 + kfree(tbl);
103412 err_dup:
103413 return -ENOMEM;
103414 }
103415 @@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103416
103417 static __net_init int rt_genid_init(struct net *net)
103418 {
103419 - atomic_set(&net->ipv4.rt_genid, 0);
103420 - atomic_set(&net->fnhe_genid, 0);
103421 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103422 + atomic_set_unchecked(&net->fnhe_genid, 0);
103423 get_random_bytes(&net->ipv4.dev_addr_genid,
103424 sizeof(net->ipv4.dev_addr_genid));
103425 return 0;
103426 @@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
103427 {
103428 int rc = 0;
103429
103430 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103431 - if (!ip_idents)
103432 - panic("IP: failed to allocate ip_idents\n");
103433 -
103434 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103435 + prandom_bytes(ip_idents, sizeof(ip_idents));
103436
103437 #ifdef CONFIG_IP_ROUTE_CLASSID
103438 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103439 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103440 index 79a007c..5023029 100644
103441 --- a/net/ipv4/sysctl_net_ipv4.c
103442 +++ b/net/ipv4/sysctl_net_ipv4.c
103443 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103444 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103445 int ret;
103446 int range[2];
103447 - struct ctl_table tmp = {
103448 + ctl_table_no_const tmp = {
103449 .data = &range,
103450 .maxlen = sizeof(range),
103451 .mode = table->mode,
103452 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103453 int ret;
103454 gid_t urange[2];
103455 kgid_t low, high;
103456 - struct ctl_table tmp = {
103457 + ctl_table_no_const tmp = {
103458 .data = &urange,
103459 .maxlen = sizeof(urange),
103460 .mode = table->mode,
103461 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103462 void __user *buffer, size_t *lenp, loff_t *ppos)
103463 {
103464 char val[TCP_CA_NAME_MAX];
103465 - struct ctl_table tbl = {
103466 + ctl_table_no_const tbl = {
103467 .data = val,
103468 .maxlen = TCP_CA_NAME_MAX,
103469 };
103470 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103471 void __user *buffer, size_t *lenp,
103472 loff_t *ppos)
103473 {
103474 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103475 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103476 int ret;
103477
103478 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103479 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103480 void __user *buffer, size_t *lenp,
103481 loff_t *ppos)
103482 {
103483 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103484 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103485 int ret;
103486
103487 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103488 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103489 void __user *buffer, size_t *lenp,
103490 loff_t *ppos)
103491 {
103492 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103493 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103494 struct tcp_fastopen_context *ctxt;
103495 int ret;
103496 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103497 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
103498
103499 static __net_init int ipv4_sysctl_init_net(struct net *net)
103500 {
103501 - struct ctl_table *table;
103502 + ctl_table_no_const *table = NULL;
103503
103504 - table = ipv4_net_table;
103505 if (!net_eq(net, &init_net)) {
103506 int i;
103507
103508 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103509 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103510 if (table == NULL)
103511 goto err_alloc;
103512
103513 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103514 table[i].data += (void *)net - (void *)&init_net;
103515 }
103516
103517 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103518 + if (!net_eq(net, &init_net))
103519 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103520 + else
103521 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103522 if (net->ipv4.ipv4_hdr == NULL)
103523 goto err_reg;
103524
103525 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103526 index a906e02..f3b6a0f 100644
103527 --- a/net/ipv4/tcp_input.c
103528 +++ b/net/ipv4/tcp_input.c
103529 @@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103530 * without any lock. We want to make sure compiler wont store
103531 * intermediate values in this location.
103532 */
103533 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103534 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103535 sk->sk_max_pacing_rate);
103536 }
103537
103538 @@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103539 * simplifies code)
103540 */
103541 static void
103542 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103543 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103544 struct sk_buff *head, struct sk_buff *tail,
103545 u32 start, u32 end)
103546 {
103547 @@ -5546,6 +5546,7 @@ discard:
103548 tcp_paws_reject(&tp->rx_opt, 0))
103549 goto discard_and_undo;
103550
103551 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103552 if (th->syn) {
103553 /* We see SYN without ACK. It is attempt of
103554 * simultaneous connect with crossed SYNs.
103555 @@ -5596,6 +5597,7 @@ discard:
103556 goto discard;
103557 #endif
103558 }
103559 +#endif
103560 /* "fifth, if neither of the SYN or RST bits is set then
103561 * drop the segment and return."
103562 */
103563 @@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103564 goto discard;
103565
103566 if (th->syn) {
103567 - if (th->fin)
103568 + if (th->fin || th->urg || th->psh)
103569 goto discard;
103570 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103571 return 1;
103572 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103573 index 3f49eae..bde687a 100644
103574 --- a/net/ipv4/tcp_ipv4.c
103575 +++ b/net/ipv4/tcp_ipv4.c
103576 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
103577 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103578
103579
103580 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103581 +extern int grsec_enable_blackhole;
103582 +#endif
103583 +
103584 #ifdef CONFIG_TCP_MD5SIG
103585 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103586 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103587 @@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103588 return 0;
103589
103590 reset:
103591 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103592 + if (!grsec_enable_blackhole)
103593 +#endif
103594 tcp_v4_send_reset(rsk, skb);
103595 discard:
103596 kfree_skb(skb);
103597 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103598 TCP_SKB_CB(skb)->sacked = 0;
103599
103600 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103601 - if (!sk)
103602 + if (!sk) {
103603 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103604 + ret = 1;
103605 +#endif
103606 goto no_tcp_socket;
103607 -
103608 + }
103609 process:
103610 - if (sk->sk_state == TCP_TIME_WAIT)
103611 + if (sk->sk_state == TCP_TIME_WAIT) {
103612 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103613 + ret = 2;
103614 +#endif
103615 goto do_time_wait;
103616 + }
103617
103618 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103619 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103620 @@ -1704,6 +1718,10 @@ csum_error:
103621 bad_packet:
103622 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103623 } else {
103624 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103625 + if (!grsec_enable_blackhole || (ret == 1 &&
103626 + (skb->dev->flags & IFF_LOOPBACK)))
103627 +#endif
103628 tcp_v4_send_reset(NULL, skb);
103629 }
103630
103631 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103632 index 1649988..6251843 100644
103633 --- a/net/ipv4/tcp_minisocks.c
103634 +++ b/net/ipv4/tcp_minisocks.c
103635 @@ -27,6 +27,10 @@
103636 #include <net/inet_common.h>
103637 #include <net/xfrm.h>
103638
103639 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103640 +extern int grsec_enable_blackhole;
103641 +#endif
103642 +
103643 int sysctl_tcp_syncookies __read_mostly = 1;
103644 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103645
103646 @@ -740,7 +744,10 @@ embryonic_reset:
103647 * avoid becoming vulnerable to outside attack aiming at
103648 * resetting legit local connections.
103649 */
103650 - req->rsk_ops->send_reset(sk, skb);
103651 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103652 + if (!grsec_enable_blackhole)
103653 +#endif
103654 + req->rsk_ops->send_reset(sk, skb);
103655 } else if (fastopen) { /* received a valid RST pkt */
103656 reqsk_fastopen_remove(sk, req, true);
103657 tcp_reset(sk);
103658 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103659 index 3b66610..bfbe23a 100644
103660 --- a/net/ipv4/tcp_probe.c
103661 +++ b/net/ipv4/tcp_probe.c
103662 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103663 if (cnt + width >= len)
103664 break;
103665
103666 - if (copy_to_user(buf + cnt, tbuf, width))
103667 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103668 return -EFAULT;
103669 cnt += width;
103670 }
103671 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103672 index df90cd1..9ab2c9b 100644
103673 --- a/net/ipv4/tcp_timer.c
103674 +++ b/net/ipv4/tcp_timer.c
103675 @@ -22,6 +22,10 @@
103676 #include <linux/gfp.h>
103677 #include <net/tcp.h>
103678
103679 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103680 +extern int grsec_lastack_retries;
103681 +#endif
103682 +
103683 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103684 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103685 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103686 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
103687 }
103688 }
103689
103690 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103691 + if ((sk->sk_state == TCP_LAST_ACK) &&
103692 + (grsec_lastack_retries > 0) &&
103693 + (grsec_lastack_retries < retry_until))
103694 + retry_until = grsec_lastack_retries;
103695 +#endif
103696 +
103697 if (retransmits_timed_out(sk, retry_until,
103698 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103699 /* Has it gone just too far? */
103700 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103701 index f57c0e4..cf24bd0 100644
103702 --- a/net/ipv4/udp.c
103703 +++ b/net/ipv4/udp.c
103704 @@ -87,6 +87,7 @@
103705 #include <linux/types.h>
103706 #include <linux/fcntl.h>
103707 #include <linux/module.h>
103708 +#include <linux/security.h>
103709 #include <linux/socket.h>
103710 #include <linux/sockios.h>
103711 #include <linux/igmp.h>
103712 @@ -113,6 +114,10 @@
103713 #include <net/busy_poll.h>
103714 #include "udp_impl.h"
103715
103716 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103717 +extern int grsec_enable_blackhole;
103718 +#endif
103719 +
103720 struct udp_table udp_table __read_mostly;
103721 EXPORT_SYMBOL(udp_table);
103722
103723 @@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103724 return true;
103725 }
103726
103727 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103728 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103729 +
103730 /*
103731 * This routine is called by the ICMP module when it gets some
103732 * sort of error condition. If err < 0 then the socket should
103733 @@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103734 dport = usin->sin_port;
103735 if (dport == 0)
103736 return -EINVAL;
103737 +
103738 + err = gr_search_udp_sendmsg(sk, usin);
103739 + if (err)
103740 + return err;
103741 } else {
103742 if (sk->sk_state != TCP_ESTABLISHED)
103743 return -EDESTADDRREQ;
103744 +
103745 + err = gr_search_udp_sendmsg(sk, NULL);
103746 + if (err)
103747 + return err;
103748 +
103749 daddr = inet->inet_daddr;
103750 dport = inet->inet_dport;
103751 /* Open fast path for connected socket.
103752 @@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
103753 IS_UDPLITE(sk));
103754 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103755 IS_UDPLITE(sk));
103756 - atomic_inc(&sk->sk_drops);
103757 + atomic_inc_unchecked(&sk->sk_drops);
103758 __skb_unlink(skb, rcvq);
103759 __skb_queue_tail(&list_kill, skb);
103760 }
103761 @@ -1261,6 +1278,10 @@ try_again:
103762 if (!skb)
103763 goto out;
103764
103765 + err = gr_search_udp_recvmsg(sk, skb);
103766 + if (err)
103767 + goto out_free;
103768 +
103769 ulen = skb->len - sizeof(struct udphdr);
103770 copied = len;
103771 if (copied > ulen)
103772 @@ -1294,7 +1315,7 @@ try_again:
103773 if (unlikely(err)) {
103774 trace_kfree_skb(skb, udp_recvmsg);
103775 if (!peeked) {
103776 - atomic_inc(&sk->sk_drops);
103777 + atomic_inc_unchecked(&sk->sk_drops);
103778 UDP_INC_STATS_USER(sock_net(sk),
103779 UDP_MIB_INERRORS, is_udplite);
103780 }
103781 @@ -1591,7 +1612,7 @@ csum_error:
103782 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103783 drop:
103784 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103785 - atomic_inc(&sk->sk_drops);
103786 + atomic_inc_unchecked(&sk->sk_drops);
103787 kfree_skb(skb);
103788 return -1;
103789 }
103790 @@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103791 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103792
103793 if (!skb1) {
103794 - atomic_inc(&sk->sk_drops);
103795 + atomic_inc_unchecked(&sk->sk_drops);
103796 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103797 IS_UDPLITE(sk));
103798 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103799 @@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103800 goto csum_error;
103801
103802 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103803 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103804 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103805 +#endif
103806 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103807
103808 /*
103809 @@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103810 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103811 0, sock_i_ino(sp),
103812 atomic_read(&sp->sk_refcnt), sp,
103813 - atomic_read(&sp->sk_drops));
103814 + atomic_read_unchecked(&sp->sk_drops));
103815 }
103816
103817 int udp4_seq_show(struct seq_file *seq, void *v)
103818 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103819 index 6156f68..d6ab46d 100644
103820 --- a/net/ipv4/xfrm4_policy.c
103821 +++ b/net/ipv4/xfrm4_policy.c
103822 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103823 fl4->flowi4_tos = iph->tos;
103824 }
103825
103826 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103827 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103828 {
103829 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103830
103831 - xfrm4_policy_afinfo.garbage_collect(net);
103832 + xfrm_garbage_collect_deferred(net);
103833 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103834 }
103835
103836 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103837
103838 static int __net_init xfrm4_net_init(struct net *net)
103839 {
103840 - struct ctl_table *table;
103841 + ctl_table_no_const *table = NULL;
103842 struct ctl_table_header *hdr;
103843
103844 - table = xfrm4_policy_table;
103845 if (!net_eq(net, &init_net)) {
103846 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103847 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103848 if (!table)
103849 goto err_alloc;
103850
103851 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103852 - }
103853 -
103854 - hdr = register_net_sysctl(net, "net/ipv4", table);
103855 + hdr = register_net_sysctl(net, "net/ipv4", table);
103856 + } else
103857 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103858 if (!hdr)
103859 goto err_reg;
103860
103861 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103862 return 0;
103863
103864 err_reg:
103865 - if (!net_eq(net, &init_net))
103866 - kfree(table);
103867 + kfree(table);
103868 err_alloc:
103869 return -ENOMEM;
103870 }
103871 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103872 index 3e118df..288a0d1 100644
103873 --- a/net/ipv6/addrconf.c
103874 +++ b/net/ipv6/addrconf.c
103875 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103876 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103877 .mtu6 = IPV6_MIN_MTU,
103878 .accept_ra = 1,
103879 - .accept_redirects = 1,
103880 + .accept_redirects = 0,
103881 .autoconf = 1,
103882 .force_mld_version = 0,
103883 .mldv1_unsolicited_report_interval = 10 * HZ,
103884 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103885 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103886 .mtu6 = IPV6_MIN_MTU,
103887 .accept_ra = 1,
103888 - .accept_redirects = 1,
103889 + .accept_redirects = 0,
103890 .autoconf = 1,
103891 .force_mld_version = 0,
103892 .mldv1_unsolicited_report_interval = 10 * HZ,
103893 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103894 idx = 0;
103895 head = &net->dev_index_head[h];
103896 rcu_read_lock();
103897 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103898 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103899 net->dev_base_seq;
103900 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103901 if (idx < s_idx)
103902 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103903 p.iph.ihl = 5;
103904 p.iph.protocol = IPPROTO_IPV6;
103905 p.iph.ttl = 64;
103906 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103907 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103908
103909 if (ops->ndo_do_ioctl) {
103910 mm_segment_t oldfs = get_fs();
103911 @@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
103912 .release = seq_release_net,
103913 };
103914
103915 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103916 +extern void unregister_ipv6_seq_ops_addr(void);
103917 +
103918 static int __net_init if6_proc_net_init(struct net *net)
103919 {
103920 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103921 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103922 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103923 + unregister_ipv6_seq_ops_addr();
103924 return -ENOMEM;
103925 + }
103926 return 0;
103927 }
103928
103929 static void __net_exit if6_proc_net_exit(struct net *net)
103930 {
103931 remove_proc_entry("if_inet6", net->proc_net);
103932 + unregister_ipv6_seq_ops_addr();
103933 }
103934
103935 static struct pernet_operations if6_proc_net_ops = {
103936 @@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103937 s_ip_idx = ip_idx = cb->args[2];
103938
103939 rcu_read_lock();
103940 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103941 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103942 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103943 idx = 0;
103944 head = &net->dev_index_head[h];
103945 @@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103946 rt_genid_bump_ipv6(net);
103947 break;
103948 }
103949 - atomic_inc(&net->ipv6.dev_addr_genid);
103950 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103951 }
103952
103953 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103954 @@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103955 int *valp = ctl->data;
103956 int val = *valp;
103957 loff_t pos = *ppos;
103958 - struct ctl_table lctl;
103959 + ctl_table_no_const lctl;
103960 int ret;
103961
103962 /*
103963 @@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103964 int *valp = ctl->data;
103965 int val = *valp;
103966 loff_t pos = *ppos;
103967 - struct ctl_table lctl;
103968 + ctl_table_no_const lctl;
103969 int ret;
103970
103971 /*
103972 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103973 index 2daa3a1..341066c 100644
103974 --- a/net/ipv6/af_inet6.c
103975 +++ b/net/ipv6/af_inet6.c
103976 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103977 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103978 net->ipv6.sysctl.flowlabel_consistency = 1;
103979 net->ipv6.sysctl.auto_flowlabels = 0;
103980 - atomic_set(&net->ipv6.rt_genid, 0);
103981 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
103982
103983 err = ipv6_init_mibs(net);
103984 if (err)
103985 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103986 index 2753319..b7e625c 100644
103987 --- a/net/ipv6/datagram.c
103988 +++ b/net/ipv6/datagram.c
103989 @@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103990 0,
103991 sock_i_ino(sp),
103992 atomic_read(&sp->sk_refcnt), sp,
103993 - atomic_read(&sp->sk_drops));
103994 + atomic_read_unchecked(&sp->sk_drops));
103995 }
103996 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103997 index 06ba3e5..5c08d38 100644
103998 --- a/net/ipv6/icmp.c
103999 +++ b/net/ipv6/icmp.c
104000 @@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
104001
104002 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
104003 {
104004 - struct ctl_table *table;
104005 + ctl_table_no_const *table;
104006
104007 table = kmemdup(ipv6_icmp_table_template,
104008 sizeof(ipv6_icmp_table_template),
104009 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
104010 index 33d08ab..585b825 100644
104011 --- a/net/ipv6/ip6_gre.c
104012 +++ b/net/ipv6/ip6_gre.c
104013 @@ -71,8 +71,8 @@ struct ip6gre_net {
104014 struct net_device *fb_tunnel_dev;
104015 };
104016
104017 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
104018 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
104019 +static struct rtnl_link_ops ip6gre_link_ops;
104020 +static struct rtnl_link_ops ip6gre_tap_ops;
104021 static int ip6gre_tunnel_init(struct net_device *dev);
104022 static void ip6gre_tunnel_setup(struct net_device *dev);
104023 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
104024 @@ -1285,7 +1285,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
104025 }
104026
104027
104028 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
104029 +static struct inet6_protocol ip6gre_protocol = {
104030 .handler = ip6gre_rcv,
104031 .err_handler = ip6gre_err,
104032 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
104033 @@ -1646,7 +1646,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
104034 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
104035 };
104036
104037 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104038 +static struct rtnl_link_ops ip6gre_link_ops = {
104039 .kind = "ip6gre",
104040 .maxtype = IFLA_GRE_MAX,
104041 .policy = ip6gre_policy,
104042 @@ -1660,7 +1660,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104043 .fill_info = ip6gre_fill_info,
104044 };
104045
104046 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
104047 +static struct rtnl_link_ops ip6gre_tap_ops = {
104048 .kind = "ip6gretap",
104049 .maxtype = IFLA_GRE_MAX,
104050 .policy = ip6gre_policy,
104051 diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
104052 index 65eda2a..620a102 100644
104053 --- a/net/ipv6/ip6_offload.c
104054 +++ b/net/ipv6/ip6_offload.c
104055 @@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
104056 if (unlikely(!pskb_may_pull(skb, len)))
104057 break;
104058
104059 + opth = (void *)skb->data;
104060 proto = opth->nexthdr;
104061 __skb_pull(skb, len);
104062 }
104063 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
104064 index d2eeb3b..c186e9a 100644
104065 --- a/net/ipv6/ip6_tunnel.c
104066 +++ b/net/ipv6/ip6_tunnel.c
104067 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104068
104069 static int ip6_tnl_dev_init(struct net_device *dev);
104070 static void ip6_tnl_dev_setup(struct net_device *dev);
104071 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
104072 +static struct rtnl_link_ops ip6_link_ops;
104073
104074 static int ip6_tnl_net_id __read_mostly;
104075 struct ip6_tnl_net {
104076 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
104077 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
104078 };
104079
104080 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
104081 +static struct rtnl_link_ops ip6_link_ops = {
104082 .kind = "ip6tnl",
104083 .maxtype = IFLA_IPTUN_MAX,
104084 .policy = ip6_tnl_policy,
104085 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
104086 index 3abcd4a..cefa215 100644
104087 --- a/net/ipv6/ip6_vti.c
104088 +++ b/net/ipv6/ip6_vti.c
104089 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104090
104091 static int vti6_dev_init(struct net_device *dev);
104092 static void vti6_dev_setup(struct net_device *dev);
104093 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
104094 +static struct rtnl_link_ops vti6_link_ops;
104095
104096 static int vti6_net_id __read_mostly;
104097 struct vti6_net {
104098 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
104099 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
104100 };
104101
104102 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
104103 +static struct rtnl_link_ops vti6_link_ops = {
104104 .kind = "vti6",
104105 .maxtype = IFLA_VTI_MAX,
104106 .policy = vti6_policy,
104107 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
104108 index 0c28998..d0a2ecd 100644
104109 --- a/net/ipv6/ipv6_sockglue.c
104110 +++ b/net/ipv6/ipv6_sockglue.c
104111 @@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
104112 if (sk->sk_type != SOCK_STREAM)
104113 return -ENOPROTOOPT;
104114
104115 - msg.msg_control = optval;
104116 + msg.msg_control = (void __force_kernel *)optval;
104117 msg.msg_controllen = len;
104118 msg.msg_flags = flags;
104119
104120 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
104121 index e080fbb..412b3cf 100644
104122 --- a/net/ipv6/netfilter/ip6_tables.c
104123 +++ b/net/ipv6/netfilter/ip6_tables.c
104124 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
104125 #endif
104126
104127 static int get_info(struct net *net, void __user *user,
104128 - const int *len, int compat)
104129 + int len, int compat)
104130 {
104131 char name[XT_TABLE_MAXNAMELEN];
104132 struct xt_table *t;
104133 int ret;
104134
104135 - if (*len != sizeof(struct ip6t_getinfo)) {
104136 - duprintf("length %u != %zu\n", *len,
104137 + if (len != sizeof(struct ip6t_getinfo)) {
104138 + duprintf("length %u != %zu\n", len,
104139 sizeof(struct ip6t_getinfo));
104140 return -EINVAL;
104141 }
104142 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104143 info.size = private->size;
104144 strcpy(info.name, name);
104145
104146 - if (copy_to_user(user, &info, *len) != 0)
104147 + if (copy_to_user(user, &info, len) != 0)
104148 ret = -EFAULT;
104149 else
104150 ret = 0;
104151 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104152
104153 switch (cmd) {
104154 case IP6T_SO_GET_INFO:
104155 - ret = get_info(sock_net(sk), user, len, 1);
104156 + ret = get_info(sock_net(sk), user, *len, 1);
104157 break;
104158 case IP6T_SO_GET_ENTRIES:
104159 ret = compat_get_entries(sock_net(sk), user, len);
104160 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104161
104162 switch (cmd) {
104163 case IP6T_SO_GET_INFO:
104164 - ret = get_info(sock_net(sk), user, len, 0);
104165 + ret = get_info(sock_net(sk), user, *len, 0);
104166 break;
104167
104168 case IP6T_SO_GET_ENTRIES:
104169 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104170 index 6f187c8..34b367f 100644
104171 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104172 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104173 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104174
104175 static int nf_ct_frag6_sysctl_register(struct net *net)
104176 {
104177 - struct ctl_table *table;
104178 + ctl_table_no_const *table = NULL;
104179 struct ctl_table_header *hdr;
104180
104181 - table = nf_ct_frag6_sysctl_table;
104182 if (!net_eq(net, &init_net)) {
104183 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104184 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104185 GFP_KERNEL);
104186 if (table == NULL)
104187 goto err_alloc;
104188 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104189 table[2].data = &net->nf_frag.frags.high_thresh;
104190 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104191 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104192 - }
104193 -
104194 - hdr = register_net_sysctl(net, "net/netfilter", table);
104195 + hdr = register_net_sysctl(net, "net/netfilter", table);
104196 + } else
104197 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104198 if (hdr == NULL)
104199 goto err_reg;
104200
104201 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104202 return 0;
104203
104204 err_reg:
104205 - if (!net_eq(net, &init_net))
104206 - kfree(table);
104207 + kfree(table);
104208 err_alloc:
104209 return -ENOMEM;
104210 }
104211 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104212 index 5b7a1ed..d9da205 100644
104213 --- a/net/ipv6/ping.c
104214 +++ b/net/ipv6/ping.c
104215 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104216 };
104217 #endif
104218
104219 +static struct pingv6_ops real_pingv6_ops = {
104220 + .ipv6_recv_error = ipv6_recv_error,
104221 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104222 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104223 + .icmpv6_err_convert = icmpv6_err_convert,
104224 + .ipv6_icmp_error = ipv6_icmp_error,
104225 + .ipv6_chk_addr = ipv6_chk_addr,
104226 +};
104227 +
104228 +static struct pingv6_ops dummy_pingv6_ops = {
104229 + .ipv6_recv_error = dummy_ipv6_recv_error,
104230 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104231 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104232 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
104233 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
104234 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
104235 +};
104236 +
104237 int __init pingv6_init(void)
104238 {
104239 #ifdef CONFIG_PROC_FS
104240 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
104241 if (ret)
104242 return ret;
104243 #endif
104244 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104245 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104246 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104247 - ip6_datagram_recv_specific_ctl;
104248 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104249 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104250 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104251 + pingv6_ops = &real_pingv6_ops;
104252 return inet6_register_protosw(&pingv6_protosw);
104253 }
104254
104255 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
104256 */
104257 void pingv6_exit(void)
104258 {
104259 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104260 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104261 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104262 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104263 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104264 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104265 #ifdef CONFIG_PROC_FS
104266 unregister_pernet_subsys(&ping_v6_net_ops);
104267 #endif
104268 + pingv6_ops = &dummy_pingv6_ops;
104269 inet6_unregister_protosw(&pingv6_protosw);
104270 }
104271 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104272 index 2d6f860..b0165f5 100644
104273 --- a/net/ipv6/proc.c
104274 +++ b/net/ipv6/proc.c
104275 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104276 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104277 goto proc_snmp6_fail;
104278
104279 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104280 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104281 if (!net->mib.proc_net_devsnmp6)
104282 goto proc_dev_snmp6_fail;
104283 return 0;
104284 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104285 index 39d4422..b0979547 100644
104286 --- a/net/ipv6/raw.c
104287 +++ b/net/ipv6/raw.c
104288 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104289 {
104290 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104291 skb_checksum_complete(skb)) {
104292 - atomic_inc(&sk->sk_drops);
104293 + atomic_inc_unchecked(&sk->sk_drops);
104294 kfree_skb(skb);
104295 return NET_RX_DROP;
104296 }
104297 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104298 struct raw6_sock *rp = raw6_sk(sk);
104299
104300 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104301 - atomic_inc(&sk->sk_drops);
104302 + atomic_inc_unchecked(&sk->sk_drops);
104303 kfree_skb(skb);
104304 return NET_RX_DROP;
104305 }
104306 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104307
104308 if (inet->hdrincl) {
104309 if (skb_checksum_complete(skb)) {
104310 - atomic_inc(&sk->sk_drops);
104311 + atomic_inc_unchecked(&sk->sk_drops);
104312 kfree_skb(skb);
104313 return NET_RX_DROP;
104314 }
104315 @@ -608,7 +608,7 @@ out:
104316 return err;
104317 }
104318
104319 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104320 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104321 struct flowi6 *fl6, struct dst_entry **dstp,
104322 unsigned int flags)
104323 {
104324 @@ -914,12 +914,15 @@ do_confirm:
104325 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104326 char __user *optval, int optlen)
104327 {
104328 + struct icmp6_filter filter;
104329 +
104330 switch (optname) {
104331 case ICMPV6_FILTER:
104332 if (optlen > sizeof(struct icmp6_filter))
104333 optlen = sizeof(struct icmp6_filter);
104334 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104335 + if (copy_from_user(&filter, optval, optlen))
104336 return -EFAULT;
104337 + raw6_sk(sk)->filter = filter;
104338 return 0;
104339 default:
104340 return -ENOPROTOOPT;
104341 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104342 char __user *optval, int __user *optlen)
104343 {
104344 int len;
104345 + struct icmp6_filter filter;
104346
104347 switch (optname) {
104348 case ICMPV6_FILTER:
104349 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104350 len = sizeof(struct icmp6_filter);
104351 if (put_user(len, optlen))
104352 return -EFAULT;
104353 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104354 + filter = raw6_sk(sk)->filter;
104355 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104356 return -EFAULT;
104357 return 0;
104358 default:
104359 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104360 index c6557d9..173e728 100644
104361 --- a/net/ipv6/reassembly.c
104362 +++ b/net/ipv6/reassembly.c
104363 @@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104364
104365 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104366 {
104367 - struct ctl_table *table;
104368 + ctl_table_no_const *table = NULL;
104369 struct ctl_table_header *hdr;
104370
104371 - table = ip6_frags_ns_ctl_table;
104372 if (!net_eq(net, &init_net)) {
104373 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104374 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104375 if (table == NULL)
104376 goto err_alloc;
104377
104378 @@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104379 /* Don't export sysctls to unprivileged users */
104380 if (net->user_ns != &init_user_ns)
104381 table[0].procname = NULL;
104382 - }
104383 + hdr = register_net_sysctl(net, "net/ipv6", table);
104384 + } else
104385 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104386
104387 - hdr = register_net_sysctl(net, "net/ipv6", table);
104388 if (hdr == NULL)
104389 goto err_reg;
104390
104391 @@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104392 return 0;
104393
104394 err_reg:
104395 - if (!net_eq(net, &init_net))
104396 - kfree(table);
104397 + kfree(table);
104398 err_alloc:
104399 return -ENOMEM;
104400 }
104401 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104402 index bafde82..af2c91f 100644
104403 --- a/net/ipv6/route.c
104404 +++ b/net/ipv6/route.c
104405 @@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
104406
104407 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104408 {
104409 - struct ctl_table *table;
104410 + ctl_table_no_const *table;
104411
104412 table = kmemdup(ipv6_route_table_template,
104413 sizeof(ipv6_route_table_template),
104414 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104415 index ca1c7c4..37fba59 100644
104416 --- a/net/ipv6/sit.c
104417 +++ b/net/ipv6/sit.c
104418 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104419 static void ipip6_dev_free(struct net_device *dev);
104420 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104421 __be32 *v4dst);
104422 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104423 +static struct rtnl_link_ops sit_link_ops;
104424
104425 static int sit_net_id __read_mostly;
104426 struct sit_net {
104427 @@ -484,11 +484,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
104428 */
104429 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104430 {
104431 - const struct iphdr *iph = (const struct iphdr *) skb->data;
104432 + int ihl = ((const struct iphdr *)skb->data)->ihl*4;
104433 struct rt6_info *rt;
104434 struct sk_buff *skb2;
104435
104436 - if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
104437 + if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
104438 return 1;
104439
104440 skb2 = skb_clone(skb, GFP_ATOMIC);
104441 @@ -497,7 +497,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104442 return 1;
104443
104444 skb_dst_drop(skb2);
104445 - skb_pull(skb2, iph->ihl * 4);
104446 + skb_pull(skb2, ihl);
104447 skb_reset_network_header(skb2);
104448
104449 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
104450 @@ -1659,7 +1659,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104451 unregister_netdevice_queue(dev, head);
104452 }
104453
104454 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104455 +static struct rtnl_link_ops sit_link_ops = {
104456 .kind = "sit",
104457 .maxtype = IFLA_IPTUN_MAX,
104458 .policy = ipip6_policy,
104459 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104460 index 0c56c93..ece50df 100644
104461 --- a/net/ipv6/sysctl_net_ipv6.c
104462 +++ b/net/ipv6/sysctl_net_ipv6.c
104463 @@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
104464
104465 static int __net_init ipv6_sysctl_net_init(struct net *net)
104466 {
104467 - struct ctl_table *ipv6_table;
104468 + ctl_table_no_const *ipv6_table;
104469 struct ctl_table *ipv6_route_table;
104470 struct ctl_table *ipv6_icmp_table;
104471 int err;
104472 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104473 index 264c0f2..b6512c6 100644
104474 --- a/net/ipv6/tcp_ipv6.c
104475 +++ b/net/ipv6/tcp_ipv6.c
104476 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104477 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
104478 }
104479
104480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104481 +extern int grsec_enable_blackhole;
104482 +#endif
104483 +
104484 static void tcp_v6_hash(struct sock *sk)
104485 {
104486 if (sk->sk_state != TCP_CLOSE) {
104487 @@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104488 return 0;
104489
104490 reset:
104491 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104492 + if (!grsec_enable_blackhole)
104493 +#endif
104494 tcp_v6_send_reset(sk, skb);
104495 discard:
104496 if (opt_skb)
104497 @@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104498 TCP_SKB_CB(skb)->sacked = 0;
104499
104500 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
104501 - if (!sk)
104502 + if (!sk) {
104503 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104504 + ret = 1;
104505 +#endif
104506 goto no_tcp_socket;
104507 + }
104508
104509 process:
104510 - if (sk->sk_state == TCP_TIME_WAIT)
104511 + if (sk->sk_state == TCP_TIME_WAIT) {
104512 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104513 + ret = 2;
104514 +#endif
104515 goto do_time_wait;
104516 + }
104517
104518 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104519 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104520 @@ -1479,6 +1494,10 @@ csum_error:
104521 bad_packet:
104522 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104523 } else {
104524 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104525 + if (!grsec_enable_blackhole || (ret == 1 &&
104526 + (skb->dev->flags & IFF_LOOPBACK)))
104527 +#endif
104528 tcp_v6_send_reset(NULL, skb);
104529 }
104530
104531 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104532 index 4836af8..0e52bbd 100644
104533 --- a/net/ipv6/udp.c
104534 +++ b/net/ipv6/udp.c
104535 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104536 udp_ipv6_hash_secret + net_hash_mix(net));
104537 }
104538
104539 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104540 +extern int grsec_enable_blackhole;
104541 +#endif
104542 +
104543 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104544 {
104545 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104546 @@ -434,7 +438,7 @@ try_again:
104547 if (unlikely(err)) {
104548 trace_kfree_skb(skb, udpv6_recvmsg);
104549 if (!peeked) {
104550 - atomic_inc(&sk->sk_drops);
104551 + atomic_inc_unchecked(&sk->sk_drops);
104552 if (is_udp4)
104553 UDP_INC_STATS_USER(sock_net(sk),
104554 UDP_MIB_INERRORS,
104555 @@ -701,7 +705,7 @@ csum_error:
104556 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104557 drop:
104558 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104559 - atomic_inc(&sk->sk_drops);
104560 + atomic_inc_unchecked(&sk->sk_drops);
104561 kfree_skb(skb);
104562 return -1;
104563 }
104564 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104565 if (likely(skb1 == NULL))
104566 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104567 if (!skb1) {
104568 - atomic_inc(&sk->sk_drops);
104569 + atomic_inc_unchecked(&sk->sk_drops);
104570 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104571 IS_UDPLITE(sk));
104572 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104573 @@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104574 goto csum_error;
104575
104576 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104577 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104578 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104579 +#endif
104580 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104581
104582 kfree_skb(skb);
104583 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104584 index 2a0bbda..fcd5396 100644
104585 --- a/net/ipv6/xfrm6_policy.c
104586 +++ b/net/ipv6/xfrm6_policy.c
104587 @@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104588 {
104589 struct flowi6 *fl6 = &fl->u.ip6;
104590 int onlyproto = 0;
104591 - u16 offset = skb_network_header_len(skb);
104592 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104593 + u16 offset = sizeof(*hdr);
104594 struct ipv6_opt_hdr *exthdr;
104595 const unsigned char *nh = skb_network_header(skb);
104596 u8 nexthdr = nh[IP6CB(skb)->nhoff];
104597 @@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104598 case IPPROTO_DCCP:
104599 if (!onlyproto && (nh + offset + 4 < skb->data ||
104600 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
104601 - __be16 *ports = (__be16 *)exthdr;
104602 + __be16 *ports;
104603
104604 + nh = skb_network_header(skb);
104605 + ports = (__be16 *)(nh + offset);
104606 fl6->fl6_sport = ports[!!reverse];
104607 fl6->fl6_dport = ports[!reverse];
104608 }
104609 @@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104610
104611 case IPPROTO_ICMPV6:
104612 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
104613 - u8 *icmp = (u8 *)exthdr;
104614 + u8 *icmp;
104615
104616 + nh = skb_network_header(skb);
104617 + icmp = (u8 *)(nh + offset);
104618 fl6->fl6_icmp_type = icmp[0];
104619 fl6->fl6_icmp_code = icmp[1];
104620 }
104621 @@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104622 case IPPROTO_MH:
104623 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
104624 struct ip6_mh *mh;
104625 - mh = (struct ip6_mh *)exthdr;
104626
104627 + nh = skb_network_header(skb);
104628 + mh = (struct ip6_mh *)(nh + offset);
104629 fl6->fl6_mh_type = mh->ip6mh_type;
104630 }
104631 fl6->flowi6_proto = nexthdr;
104632 @@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104633 }
104634 }
104635
104636 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104637 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104638 {
104639 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104640
104641 - xfrm6_policy_afinfo.garbage_collect(net);
104642 + xfrm_garbage_collect_deferred(net);
104643 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104644 }
104645
104646 @@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104647
104648 static int __net_init xfrm6_net_init(struct net *net)
104649 {
104650 - struct ctl_table *table;
104651 + ctl_table_no_const *table = NULL;
104652 struct ctl_table_header *hdr;
104653
104654 - table = xfrm6_policy_table;
104655 if (!net_eq(net, &init_net)) {
104656 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104657 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104658 if (!table)
104659 goto err_alloc;
104660
104661 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104662 - }
104663 + hdr = register_net_sysctl(net, "net/ipv6", table);
104664 + } else
104665 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104666
104667 - hdr = register_net_sysctl(net, "net/ipv6", table);
104668 if (!hdr)
104669 goto err_reg;
104670
104671 @@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104672 return 0;
104673
104674 err_reg:
104675 - if (!net_eq(net, &init_net))
104676 - kfree(table);
104677 + kfree(table);
104678 err_alloc:
104679 return -ENOMEM;
104680 }
104681 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104682 index e15c16a..7cf07aa 100644
104683 --- a/net/ipx/ipx_proc.c
104684 +++ b/net/ipx/ipx_proc.c
104685 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104686 struct proc_dir_entry *p;
104687 int rc = -ENOMEM;
104688
104689 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104690 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104691
104692 if (!ipx_proc_dir)
104693 goto out;
104694 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104695 index 61ceb4c..e788eb8 100644
104696 --- a/net/irda/ircomm/ircomm_tty.c
104697 +++ b/net/irda/ircomm/ircomm_tty.c
104698 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104699 add_wait_queue(&port->open_wait, &wait);
104700
104701 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104702 - __FILE__, __LINE__, tty->driver->name, port->count);
104703 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104704
104705 spin_lock_irqsave(&port->lock, flags);
104706 - port->count--;
104707 + atomic_dec(&port->count);
104708 port->blocked_open++;
104709 spin_unlock_irqrestore(&port->lock, flags);
104710
104711 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104712 }
104713
104714 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104715 - __FILE__, __LINE__, tty->driver->name, port->count);
104716 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104717
104718 schedule();
104719 }
104720 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104721
104722 spin_lock_irqsave(&port->lock, flags);
104723 if (!tty_hung_up_p(filp))
104724 - port->count++;
104725 + atomic_inc(&port->count);
104726 port->blocked_open--;
104727 spin_unlock_irqrestore(&port->lock, flags);
104728
104729 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104730 - __FILE__, __LINE__, tty->driver->name, port->count);
104731 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104732
104733 if (!retval)
104734 port->flags |= ASYNC_NORMAL_ACTIVE;
104735 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104736
104737 /* ++ is not atomic, so this should be protected - Jean II */
104738 spin_lock_irqsave(&self->port.lock, flags);
104739 - self->port.count++;
104740 + atomic_inc(&self->port.count);
104741 spin_unlock_irqrestore(&self->port.lock, flags);
104742 tty_port_tty_set(&self->port, tty);
104743
104744 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104745 - self->line, self->port.count);
104746 + self->line, atomic_read(&self->port.count));
104747
104748 /* Not really used by us, but lets do it anyway */
104749 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104750 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104751 tty_kref_put(port->tty);
104752 }
104753 port->tty = NULL;
104754 - port->count = 0;
104755 + atomic_set(&port->count, 0);
104756 spin_unlock_irqrestore(&port->lock, flags);
104757
104758 wake_up_interruptible(&port->open_wait);
104759 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104760 seq_putc(m, '\n');
104761
104762 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104763 - seq_printf(m, "Open count: %d\n", self->port.count);
104764 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104765 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104766 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104767
104768 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104769 index b9ac598..f88cc56 100644
104770 --- a/net/irda/irproc.c
104771 +++ b/net/irda/irproc.c
104772 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104773 {
104774 int i;
104775
104776 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104777 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104778 if (proc_irda == NULL)
104779 return;
104780
104781 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104782 index a089b6b..3ca3b60 100644
104783 --- a/net/iucv/af_iucv.c
104784 +++ b/net/iucv/af_iucv.c
104785 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104786 {
104787 char name[12];
104788
104789 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104790 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104791 while (__iucv_get_sock_by_name(name)) {
104792 sprintf(name, "%08x",
104793 - atomic_inc_return(&iucv_sk_list.autobind_name));
104794 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104795 }
104796 memcpy(iucv->src_name, name, 8);
104797 }
104798 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104799 index da78793..bdd78cf 100644
104800 --- a/net/iucv/iucv.c
104801 +++ b/net/iucv/iucv.c
104802 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104803 return NOTIFY_OK;
104804 }
104805
104806 -static struct notifier_block __refdata iucv_cpu_notifier = {
104807 +static struct notifier_block iucv_cpu_notifier = {
104808 .notifier_call = iucv_cpu_notify,
104809 };
104810
104811 diff --git a/net/key/af_key.c b/net/key/af_key.c
104812 index 1847ec4..26ef732 100644
104813 --- a/net/key/af_key.c
104814 +++ b/net/key/af_key.c
104815 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104816 static u32 get_acqseq(void)
104817 {
104818 u32 res;
104819 - static atomic_t acqseq;
104820 + static atomic_unchecked_t acqseq;
104821
104822 do {
104823 - res = atomic_inc_return(&acqseq);
104824 + res = atomic_inc_return_unchecked(&acqseq);
104825 } while (!res);
104826 return res;
104827 }
104828 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104829 index edb78e6..8dc654a 100644
104830 --- a/net/l2tp/l2tp_eth.c
104831 +++ b/net/l2tp/l2tp_eth.c
104832 @@ -42,12 +42,12 @@ struct l2tp_eth {
104833 struct sock *tunnel_sock;
104834 struct l2tp_session *session;
104835 struct list_head list;
104836 - atomic_long_t tx_bytes;
104837 - atomic_long_t tx_packets;
104838 - atomic_long_t tx_dropped;
104839 - atomic_long_t rx_bytes;
104840 - atomic_long_t rx_packets;
104841 - atomic_long_t rx_errors;
104842 + atomic_long_unchecked_t tx_bytes;
104843 + atomic_long_unchecked_t tx_packets;
104844 + atomic_long_unchecked_t tx_dropped;
104845 + atomic_long_unchecked_t rx_bytes;
104846 + atomic_long_unchecked_t rx_packets;
104847 + atomic_long_unchecked_t rx_errors;
104848 };
104849
104850 /* via l2tp_session_priv() */
104851 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104852 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104853
104854 if (likely(ret == NET_XMIT_SUCCESS)) {
104855 - atomic_long_add(len, &priv->tx_bytes);
104856 - atomic_long_inc(&priv->tx_packets);
104857 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104858 + atomic_long_inc_unchecked(&priv->tx_packets);
104859 } else {
104860 - atomic_long_inc(&priv->tx_dropped);
104861 + atomic_long_inc_unchecked(&priv->tx_dropped);
104862 }
104863 return NETDEV_TX_OK;
104864 }
104865 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104866 {
104867 struct l2tp_eth *priv = netdev_priv(dev);
104868
104869 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104870 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104871 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104872 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104873 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104874 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104875 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104876 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104877 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104878 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104879 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104880 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104881 return stats;
104882 }
104883
104884 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104885 nf_reset(skb);
104886
104887 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104888 - atomic_long_inc(&priv->rx_packets);
104889 - atomic_long_add(data_len, &priv->rx_bytes);
104890 + atomic_long_inc_unchecked(&priv->rx_packets);
104891 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104892 } else {
104893 - atomic_long_inc(&priv->rx_errors);
104894 + atomic_long_inc_unchecked(&priv->rx_errors);
104895 }
104896 return;
104897
104898 error:
104899 - atomic_long_inc(&priv->rx_errors);
104900 + atomic_long_inc_unchecked(&priv->rx_errors);
104901 kfree_skb(skb);
104902 }
104903
104904 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104905 index 1a3c7e0..80f8b0c 100644
104906 --- a/net/llc/llc_proc.c
104907 +++ b/net/llc/llc_proc.c
104908 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104909 int rc = -ENOMEM;
104910 struct proc_dir_entry *p;
104911
104912 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104913 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104914 if (!llc_proc_dir)
104915 goto out;
104916
104917 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104918 index 927b4ea..88a30e2 100644
104919 --- a/net/mac80211/cfg.c
104920 +++ b/net/mac80211/cfg.c
104921 @@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104922 ret = ieee80211_vif_use_channel(sdata, chandef,
104923 IEEE80211_CHANCTX_EXCLUSIVE);
104924 }
104925 - } else if (local->open_count == local->monitors) {
104926 + } else if (local_read(&local->open_count) == local->monitors) {
104927 local->_oper_chandef = *chandef;
104928 ieee80211_hw_config(local, 0);
104929 }
104930 @@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104931 else
104932 local->probe_req_reg--;
104933
104934 - if (!local->open_count)
104935 + if (!local_read(&local->open_count))
104936 break;
104937
104938 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104939 @@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104940 if (chanctx_conf) {
104941 *chandef = chanctx_conf->def;
104942 ret = 0;
104943 - } else if (local->open_count > 0 &&
104944 - local->open_count == local->monitors &&
104945 + } else if (local_read(&local->open_count) > 0 &&
104946 + local_read(&local->open_count) == local->monitors &&
104947 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104948 if (local->use_chanctx)
104949 *chandef = local->monitor_chandef;
104950 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104951 index 5d102b5..6199fca 100644
104952 --- a/net/mac80211/ieee80211_i.h
104953 +++ b/net/mac80211/ieee80211_i.h
104954 @@ -28,6 +28,7 @@
104955 #include <net/ieee80211_radiotap.h>
104956 #include <net/cfg80211.h>
104957 #include <net/mac80211.h>
104958 +#include <asm/local.h>
104959 #include "key.h"
104960 #include "sta_info.h"
104961 #include "debug.h"
104962 @@ -1055,7 +1056,7 @@ struct ieee80211_local {
104963 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104964 spinlock_t queue_stop_reason_lock;
104965
104966 - int open_count;
104967 + local_t open_count;
104968 int monitors, cooked_mntrs;
104969 /* number of interfaces with corresponding FIF_ flags */
104970 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104971 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104972 index 3538e5e..0aa7879 100644
104973 --- a/net/mac80211/iface.c
104974 +++ b/net/mac80211/iface.c
104975 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104976 break;
104977 }
104978
104979 - if (local->open_count == 0) {
104980 + if (local_read(&local->open_count) == 0) {
104981 res = drv_start(local);
104982 if (res)
104983 goto err_del_bss;
104984 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104985 res = drv_add_interface(local, sdata);
104986 if (res)
104987 goto err_stop;
104988 - } else if (local->monitors == 0 && local->open_count == 0) {
104989 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104990 res = ieee80211_add_virtual_monitor(local);
104991 if (res)
104992 goto err_stop;
104993 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104994 atomic_inc(&local->iff_promiscs);
104995
104996 if (coming_up)
104997 - local->open_count++;
104998 + local_inc(&local->open_count);
104999
105000 if (hw_reconf_flags)
105001 ieee80211_hw_config(local, hw_reconf_flags);
105002 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105003 err_del_interface:
105004 drv_remove_interface(local, sdata);
105005 err_stop:
105006 - if (!local->open_count)
105007 + if (!local_read(&local->open_count))
105008 drv_stop(local);
105009 err_del_bss:
105010 sdata->bss = NULL;
105011 @@ -891,7 +891,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105012 }
105013
105014 if (going_down)
105015 - local->open_count--;
105016 + local_dec(&local->open_count);
105017
105018 switch (sdata->vif.type) {
105019 case NL80211_IFTYPE_AP_VLAN:
105020 @@ -952,7 +952,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105021 }
105022 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
105023
105024 - if (local->open_count == 0)
105025 + if (local_read(&local->open_count) == 0)
105026 ieee80211_clear_tx_pending(local);
105027
105028 /*
105029 @@ -995,7 +995,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105030 if (cancel_scan)
105031 flush_delayed_work(&local->scan_work);
105032
105033 - if (local->open_count == 0) {
105034 + if (local_read(&local->open_count) == 0) {
105035 ieee80211_stop_device(local);
105036
105037 /* no reconfiguring after stop! */
105038 @@ -1006,7 +1006,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105039 ieee80211_configure_filter(local);
105040 ieee80211_hw_config(local, hw_reconf_flags);
105041
105042 - if (local->monitors == local->open_count)
105043 + if (local->monitors == local_read(&local->open_count))
105044 ieee80211_add_virtual_monitor(local);
105045 }
105046
105047 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
105048 index e0ab432..36b7b94 100644
105049 --- a/net/mac80211/main.c
105050 +++ b/net/mac80211/main.c
105051 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
105052 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
105053 IEEE80211_CONF_CHANGE_POWER);
105054
105055 - if (changed && local->open_count) {
105056 + if (changed && local_read(&local->open_count)) {
105057 ret = drv_config(local, changed);
105058 /*
105059 * Goal:
105060 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
105061 index 4c5192e..04cc0d8 100644
105062 --- a/net/mac80211/pm.c
105063 +++ b/net/mac80211/pm.c
105064 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105065 struct ieee80211_sub_if_data *sdata;
105066 struct sta_info *sta;
105067
105068 - if (!local->open_count)
105069 + if (!local_read(&local->open_count))
105070 goto suspend;
105071
105072 ieee80211_scan_cancel(local);
105073 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105074 cancel_work_sync(&local->dynamic_ps_enable_work);
105075 del_timer_sync(&local->dynamic_ps_timer);
105076
105077 - local->wowlan = wowlan && local->open_count;
105078 + local->wowlan = wowlan && local_read(&local->open_count);
105079 if (local->wowlan) {
105080 int err = drv_suspend(local, wowlan);
105081 if (err < 0) {
105082 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105083 WARN_ON(!list_empty(&local->chanctx_list));
105084
105085 /* stop hardware - this must stop RX */
105086 - if (local->open_count)
105087 + if (local_read(&local->open_count))
105088 ieee80211_stop_device(local);
105089
105090 suspend:
105091 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
105092 index 6081329..ab23834 100644
105093 --- a/net/mac80211/rate.c
105094 +++ b/net/mac80211/rate.c
105095 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
105096
105097 ASSERT_RTNL();
105098
105099 - if (local->open_count)
105100 + if (local_read(&local->open_count))
105101 return -EBUSY;
105102
105103 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
105104 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
105105 index 725af7a..a21a20a 100644
105106 --- a/net/mac80211/util.c
105107 +++ b/net/mac80211/util.c
105108 @@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105109 }
105110 #endif
105111 /* everything else happens only if HW was up & running */
105112 - if (!local->open_count)
105113 + if (!local_read(&local->open_count))
105114 goto wake_up;
105115
105116 /*
105117 @@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105118 local->in_reconfig = false;
105119 barrier();
105120
105121 - if (local->monitors == local->open_count && local->monitors > 0)
105122 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
105123 ieee80211_add_virtual_monitor(local);
105124
105125 /*
105126 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
105127 index 6d77cce..36e2fc3 100644
105128 --- a/net/netfilter/Kconfig
105129 +++ b/net/netfilter/Kconfig
105130 @@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
105131
105132 To compile it as a module, choose M here. If unsure, say N.
105133
105134 +config NETFILTER_XT_MATCH_GRADM
105135 + tristate '"gradm" match support'
105136 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
105137 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
105138 + ---help---
105139 + The gradm match allows to match on grsecurity RBAC being enabled.
105140 + It is useful when iptables rules are applied early on bootup to
105141 + prevent connections to the machine (except from a trusted host)
105142 + while the RBAC system is disabled.
105143 +
105144 config NETFILTER_XT_MATCH_HASHLIMIT
105145 tristate '"hashlimit" match support'
105146 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105147 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105148 index fad5fdb..ba3672a 100644
105149 --- a/net/netfilter/Makefile
105150 +++ b/net/netfilter/Makefile
105151 @@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105152 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105153 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105154 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105155 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105156 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105157 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105158 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105159 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105160 index 6582dce..a911da7 100644
105161 --- a/net/netfilter/ipset/ip_set_core.c
105162 +++ b/net/netfilter/ipset/ip_set_core.c
105163 @@ -1921,7 +1921,7 @@ done:
105164 return ret;
105165 }
105166
105167 -static struct nf_sockopt_ops so_set __read_mostly = {
105168 +static struct nf_sockopt_ops so_set = {
105169 .pf = PF_INET,
105170 .get_optmin = SO_IP_SET,
105171 .get_optmax = SO_IP_SET + 1,
105172 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105173 index 610e19c..08d0c3f 100644
105174 --- a/net/netfilter/ipvs/ip_vs_conn.c
105175 +++ b/net/netfilter/ipvs/ip_vs_conn.c
105176 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105177 /* Increase the refcnt counter of the dest */
105178 ip_vs_dest_hold(dest);
105179
105180 - conn_flags = atomic_read(&dest->conn_flags);
105181 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
105182 if (cp->protocol != IPPROTO_UDP)
105183 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105184 flags = cp->flags;
105185 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
105186
105187 cp->control = NULL;
105188 atomic_set(&cp->n_control, 0);
105189 - atomic_set(&cp->in_pkts, 0);
105190 + atomic_set_unchecked(&cp->in_pkts, 0);
105191
105192 cp->packet_xmit = NULL;
105193 cp->app = NULL;
105194 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105195
105196 /* Don't drop the entry if its number of incoming packets is not
105197 located in [0, 8] */
105198 - i = atomic_read(&cp->in_pkts);
105199 + i = atomic_read_unchecked(&cp->in_pkts);
105200 if (i > 8 || i < 0) return 0;
105201
105202 if (!todrop_rate[i]) return 0;
105203 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105204 index 5c34e8d..0d8eb7f 100644
105205 --- a/net/netfilter/ipvs/ip_vs_core.c
105206 +++ b/net/netfilter/ipvs/ip_vs_core.c
105207 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105208 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105209 /* do not touch skb anymore */
105210
105211 - atomic_inc(&cp->in_pkts);
105212 + atomic_inc_unchecked(&cp->in_pkts);
105213 ip_vs_conn_put(cp);
105214 return ret;
105215 }
105216 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105217 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105218 pkts = sysctl_sync_threshold(ipvs);
105219 else
105220 - pkts = atomic_add_return(1, &cp->in_pkts);
105221 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105222
105223 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105224 ip_vs_sync_conn(net, cp, pkts);
105225 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105226 index fd3f444..ab28fa24 100644
105227 --- a/net/netfilter/ipvs/ip_vs_ctl.c
105228 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
105229 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105230 */
105231 ip_vs_rs_hash(ipvs, dest);
105232 }
105233 - atomic_set(&dest->conn_flags, conn_flags);
105234 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
105235
105236 /* bind the service */
105237 old_svc = rcu_dereference_protected(dest->svc, 1);
105238 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105239 * align with netns init in ip_vs_control_net_init()
105240 */
105241
105242 -static struct ctl_table vs_vars[] = {
105243 +static ctl_table_no_const vs_vars[] __read_only = {
105244 {
105245 .procname = "amemthresh",
105246 .maxlen = sizeof(int),
105247 @@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105248 " %-7s %-6d %-10d %-10d\n",
105249 &dest->addr.in6,
105250 ntohs(dest->port),
105251 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105252 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105253 atomic_read(&dest->weight),
105254 atomic_read(&dest->activeconns),
105255 atomic_read(&dest->inactconns));
105256 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105257 "%-7s %-6d %-10d %-10d\n",
105258 ntohl(dest->addr.ip),
105259 ntohs(dest->port),
105260 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105261 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105262 atomic_read(&dest->weight),
105263 atomic_read(&dest->activeconns),
105264 atomic_read(&dest->inactconns));
105265 @@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105266
105267 entry.addr = dest->addr.ip;
105268 entry.port = dest->port;
105269 - entry.conn_flags = atomic_read(&dest->conn_flags);
105270 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105271 entry.weight = atomic_read(&dest->weight);
105272 entry.u_threshold = dest->u_threshold;
105273 entry.l_threshold = dest->l_threshold;
105274 @@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105275 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105276 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105277 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105278 - (atomic_read(&dest->conn_flags) &
105279 + (atomic_read_unchecked(&dest->conn_flags) &
105280 IP_VS_CONN_F_FWD_MASK)) ||
105281 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105282 atomic_read(&dest->weight)) ||
105283 @@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105284 {
105285 int idx;
105286 struct netns_ipvs *ipvs = net_ipvs(net);
105287 - struct ctl_table *tbl;
105288 + ctl_table_no_const *tbl;
105289
105290 atomic_set(&ipvs->dropentry, 0);
105291 spin_lock_init(&ipvs->dropentry_lock);
105292 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105293 index 547ff33..c8c8117 100644
105294 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105295 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105296 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105297 * IPVS LBLC sysctl table
105298 */
105299 #ifdef CONFIG_SYSCTL
105300 -static struct ctl_table vs_vars_table[] = {
105301 +static ctl_table_no_const vs_vars_table[] __read_only = {
105302 {
105303 .procname = "lblc_expiration",
105304 .data = NULL,
105305 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105306 index 3f21a2f..a112e85 100644
105307 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105308 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105309 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105310 * IPVS LBLCR sysctl table
105311 */
105312
105313 -static struct ctl_table vs_vars_table[] = {
105314 +static ctl_table_no_const vs_vars_table[] __read_only = {
105315 {
105316 .procname = "lblcr_expiration",
105317 .data = NULL,
105318 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105319 index eadffb2..c2feeae 100644
105320 --- a/net/netfilter/ipvs/ip_vs_sync.c
105321 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105322 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105323 cp = cp->control;
105324 if (cp) {
105325 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105326 - pkts = atomic_add_return(1, &cp->in_pkts);
105327 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105328 else
105329 pkts = sysctl_sync_threshold(ipvs);
105330 ip_vs_sync_conn(net, cp->control, pkts);
105331 @@ -771,7 +771,7 @@ control:
105332 if (!cp)
105333 return;
105334 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105335 - pkts = atomic_add_return(1, &cp->in_pkts);
105336 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105337 else
105338 pkts = sysctl_sync_threshold(ipvs);
105339 goto sloop;
105340 @@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105341
105342 if (opt)
105343 memcpy(&cp->in_seq, opt, sizeof(*opt));
105344 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105345 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105346 cp->state = state;
105347 cp->old_state = cp->state;
105348 /*
105349 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105350 index 56896a4..dfe3806 100644
105351 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105352 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105353 @@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105354 else
105355 rc = NF_ACCEPT;
105356 /* do not touch skb anymore */
105357 - atomic_inc(&cp->in_pkts);
105358 + atomic_inc_unchecked(&cp->in_pkts);
105359 goto out;
105360 }
105361
105362 @@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105363 else
105364 rc = NF_ACCEPT;
105365 /* do not touch skb anymore */
105366 - atomic_inc(&cp->in_pkts);
105367 + atomic_inc_unchecked(&cp->in_pkts);
105368 goto out;
105369 }
105370
105371 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105372 index a4b5e2a..13b1de3 100644
105373 --- a/net/netfilter/nf_conntrack_acct.c
105374 +++ b/net/netfilter/nf_conntrack_acct.c
105375 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105376 #ifdef CONFIG_SYSCTL
105377 static int nf_conntrack_acct_init_sysctl(struct net *net)
105378 {
105379 - struct ctl_table *table;
105380 + ctl_table_no_const *table;
105381
105382 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105383 GFP_KERNEL);
105384 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105385 index de88c4a..ec84234 100644
105386 --- a/net/netfilter/nf_conntrack_core.c
105387 +++ b/net/netfilter/nf_conntrack_core.c
105388 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
105389 #define DYING_NULLS_VAL ((1<<30)+1)
105390 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105391
105392 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105393 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105394 +#endif
105395 +
105396 int nf_conntrack_init_net(struct net *net)
105397 {
105398 int ret = -ENOMEM;
105399 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
105400 if (!net->ct.stat)
105401 goto err_pcpu_lists;
105402
105403 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105404 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105405 +#else
105406 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105407 +#endif
105408 if (!net->ct.slabname)
105409 goto err_slabname;
105410
105411 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105412 index 4e78c57..ec8fb74 100644
105413 --- a/net/netfilter/nf_conntrack_ecache.c
105414 +++ b/net/netfilter/nf_conntrack_ecache.c
105415 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105416 #ifdef CONFIG_SYSCTL
105417 static int nf_conntrack_event_init_sysctl(struct net *net)
105418 {
105419 - struct ctl_table *table;
105420 + ctl_table_no_const *table;
105421
105422 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105423 GFP_KERNEL);
105424 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105425 index 5b3eae7..dd4b8fe 100644
105426 --- a/net/netfilter/nf_conntrack_helper.c
105427 +++ b/net/netfilter/nf_conntrack_helper.c
105428 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105429
105430 static int nf_conntrack_helper_init_sysctl(struct net *net)
105431 {
105432 - struct ctl_table *table;
105433 + ctl_table_no_const *table;
105434
105435 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105436 GFP_KERNEL);
105437 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105438 index b65d586..beec902 100644
105439 --- a/net/netfilter/nf_conntrack_proto.c
105440 +++ b/net/netfilter/nf_conntrack_proto.c
105441 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105442
105443 static void
105444 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105445 - struct ctl_table **table,
105446 + ctl_table_no_const **table,
105447 unsigned int users)
105448 {
105449 if (users > 0)
105450 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105451 index f641751..d3c5b51 100644
105452 --- a/net/netfilter/nf_conntrack_standalone.c
105453 +++ b/net/netfilter/nf_conntrack_standalone.c
105454 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105455
105456 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105457 {
105458 - struct ctl_table *table;
105459 + ctl_table_no_const *table;
105460
105461 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105462 GFP_KERNEL);
105463 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105464 index 7a394df..bd91a8a 100644
105465 --- a/net/netfilter/nf_conntrack_timestamp.c
105466 +++ b/net/netfilter/nf_conntrack_timestamp.c
105467 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105468 #ifdef CONFIG_SYSCTL
105469 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105470 {
105471 - struct ctl_table *table;
105472 + ctl_table_no_const *table;
105473
105474 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105475 GFP_KERNEL);
105476 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105477 index daad602..384be13 100644
105478 --- a/net/netfilter/nf_log.c
105479 +++ b/net/netfilter/nf_log.c
105480 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105481
105482 #ifdef CONFIG_SYSCTL
105483 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105484 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105485 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105486
105487 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105488 void __user *buffer, size_t *lenp, loff_t *ppos)
105489 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105490 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105491 mutex_unlock(&nf_log_mutex);
105492 } else {
105493 + ctl_table_no_const nf_log_table = *table;
105494 +
105495 mutex_lock(&nf_log_mutex);
105496 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105497 lockdep_is_held(&nf_log_mutex));
105498 if (!logger)
105499 - table->data = "NONE";
105500 + nf_log_table.data = "NONE";
105501 else
105502 - table->data = logger->name;
105503 - r = proc_dostring(table, write, buffer, lenp, ppos);
105504 + nf_log_table.data = logger->name;
105505 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105506 mutex_unlock(&nf_log_mutex);
105507 }
105508
105509 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105510 index c68c1e5..8b5d670 100644
105511 --- a/net/netfilter/nf_sockopt.c
105512 +++ b/net/netfilter/nf_sockopt.c
105513 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105514 }
105515 }
105516
105517 - list_add(&reg->list, &nf_sockopts);
105518 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105519 out:
105520 mutex_unlock(&nf_sockopt_mutex);
105521 return ret;
105522 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105523 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105524 {
105525 mutex_lock(&nf_sockopt_mutex);
105526 - list_del(&reg->list);
105527 + pax_list_del((struct list_head *)&reg->list);
105528 mutex_unlock(&nf_sockopt_mutex);
105529 }
105530 EXPORT_SYMBOL(nf_unregister_sockopt);
105531 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105532 index 3250735..1fac969 100644
105533 --- a/net/netfilter/nfnetlink_log.c
105534 +++ b/net/netfilter/nfnetlink_log.c
105535 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105536 struct nfnl_log_net {
105537 spinlock_t instances_lock;
105538 struct hlist_head instance_table[INSTANCE_BUCKETS];
105539 - atomic_t global_seq;
105540 + atomic_unchecked_t global_seq;
105541 };
105542
105543 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105544 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105545 /* global sequence number */
105546 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105547 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105548 - htonl(atomic_inc_return(&log->global_seq))))
105549 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105550 goto nla_put_failure;
105551
105552 if (data_len) {
105553 diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
105554 index 108120f..5b169db 100644
105555 --- a/net/netfilter/nfnetlink_queue_core.c
105556 +++ b/net/netfilter/nfnetlink_queue_core.c
105557 @@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
105558 * returned by nf_queue. For instance, callers rely on -ECANCELED to
105559 * mean 'ignore this hook'.
105560 */
105561 - if (IS_ERR(segs))
105562 + if (IS_ERR_OR_NULL(segs))
105563 goto out_err;
105564 queued = 0;
105565 err = 0;
105566 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
105567 index 5b5ab9e..fc1015c 100644
105568 --- a/net/netfilter/nft_compat.c
105569 +++ b/net/netfilter/nft_compat.c
105570 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
105571 /* We want to reuse existing compat_to_user */
105572 old_fs = get_fs();
105573 set_fs(KERNEL_DS);
105574 - t->compat_to_user(out, in);
105575 + t->compat_to_user((void __force_user *)out, in);
105576 set_fs(old_fs);
105577 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
105578 kfree(out);
105579 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
105580 /* We want to reuse existing compat_to_user */
105581 old_fs = get_fs();
105582 set_fs(KERNEL_DS);
105583 - m->compat_to_user(out, in);
105584 + m->compat_to_user((void __force_user *)out, in);
105585 set_fs(old_fs);
105586 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
105587 kfree(out);
105588 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105589 new file mode 100644
105590 index 0000000..c566332
105591 --- /dev/null
105592 +++ b/net/netfilter/xt_gradm.c
105593 @@ -0,0 +1,51 @@
105594 +/*
105595 + * gradm match for netfilter
105596 + * Copyright © Zbigniew Krzystolik, 2010
105597 + *
105598 + * This program is free software; you can redistribute it and/or modify
105599 + * it under the terms of the GNU General Public License; either version
105600 + * 2 or 3 as published by the Free Software Foundation.
105601 + */
105602 +#include <linux/module.h>
105603 +#include <linux/moduleparam.h>
105604 +#include <linux/skbuff.h>
105605 +#include <linux/netfilter/x_tables.h>
105606 +#include <linux/grsecurity.h>
105607 +#include <linux/netfilter/xt_gradm.h>
105608 +
105609 +static bool
105610 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105611 +{
105612 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105613 + bool retval = false;
105614 + if (gr_acl_is_enabled())
105615 + retval = true;
105616 + return retval ^ info->invflags;
105617 +}
105618 +
105619 +static struct xt_match gradm_mt_reg __read_mostly = {
105620 + .name = "gradm",
105621 + .revision = 0,
105622 + .family = NFPROTO_UNSPEC,
105623 + .match = gradm_mt,
105624 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105625 + .me = THIS_MODULE,
105626 +};
105627 +
105628 +static int __init gradm_mt_init(void)
105629 +{
105630 + return xt_register_match(&gradm_mt_reg);
105631 +}
105632 +
105633 +static void __exit gradm_mt_exit(void)
105634 +{
105635 + xt_unregister_match(&gradm_mt_reg);
105636 +}
105637 +
105638 +module_init(gradm_mt_init);
105639 +module_exit(gradm_mt_exit);
105640 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105641 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105642 +MODULE_LICENSE("GPL");
105643 +MODULE_ALIAS("ipt_gradm");
105644 +MODULE_ALIAS("ip6t_gradm");
105645 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105646 index 47dc683..2e0d52c 100644
105647 --- a/net/netfilter/xt_hashlimit.c
105648 +++ b/net/netfilter/xt_hashlimit.c
105649 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105650 {
105651 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105652
105653 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105654 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105655 if (!hashlimit_net->ipt_hashlimit)
105656 return -ENOMEM;
105657 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105658 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105659 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105660 if (!hashlimit_net->ip6t_hashlimit) {
105661 remove_proc_entry("ipt_hashlimit", net->proc_net);
105662 return -ENOMEM;
105663 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105664 index a9faae8..1ea30e0 100644
105665 --- a/net/netfilter/xt_recent.c
105666 +++ b/net/netfilter/xt_recent.c
105667 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105668 {
105669 struct recent_net *recent_net = recent_pernet(net);
105670
105671 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105672 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105673 if (!recent_net->xt_recent)
105674 return -ENOMEM;
105675 return 0;
105676 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105677 index 11de55e..f25e448 100644
105678 --- a/net/netfilter/xt_statistic.c
105679 +++ b/net/netfilter/xt_statistic.c
105680 @@ -19,7 +19,7 @@
105681 #include <linux/module.h>
105682
105683 struct xt_statistic_priv {
105684 - atomic_t count;
105685 + atomic_unchecked_t count;
105686 } ____cacheline_aligned_in_smp;
105687
105688 MODULE_LICENSE("GPL");
105689 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105690 break;
105691 case XT_STATISTIC_MODE_NTH:
105692 do {
105693 - oval = atomic_read(&info->master->count);
105694 + oval = atomic_read_unchecked(&info->master->count);
105695 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105696 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105697 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105698 if (nval == 0)
105699 ret = !ret;
105700 break;
105701 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105702 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105703 if (info->master == NULL)
105704 return -ENOMEM;
105705 - atomic_set(&info->master->count, info->u.nth.count);
105706 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105707
105708 return 0;
105709 }
105710 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105711 index b6bf8e8..7884ddf 100644
105712 --- a/net/netlink/af_netlink.c
105713 +++ b/net/netlink/af_netlink.c
105714 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105715 sk->sk_error_report(sk);
105716 }
105717 }
105718 - atomic_inc(&sk->sk_drops);
105719 + atomic_inc_unchecked(&sk->sk_drops);
105720 }
105721
105722 static void netlink_rcv_wake(struct sock *sk)
105723 @@ -3010,7 +3010,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105724 sk_wmem_alloc_get(s),
105725 nlk->cb_running,
105726 atomic_read(&s->sk_refcnt),
105727 - atomic_read(&s->sk_drops),
105728 + atomic_read_unchecked(&s->sk_drops),
105729 sock_i_ino(s)
105730 );
105731
105732 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
105733 index 64dc864..7a9e2a4 100644
105734 --- a/net/openvswitch/datapath.c
105735 +++ b/net/openvswitch/datapath.c
105736 @@ -332,6 +332,8 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
105737 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
105738 if (IS_ERR(segs))
105739 return PTR_ERR(segs);
105740 + if (segs == NULL)
105741 + return -EINVAL;
105742
105743 /* Queue all of the segments. */
105744 skb = segs;
105745 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
105746 index 8451612..c8872bc 100644
105747 --- a/net/openvswitch/vport-internal_dev.c
105748 +++ b/net/openvswitch/vport-internal_dev.c
105749 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
105750 .ndo_get_stats64 = internal_dev_get_stats,
105751 };
105752
105753 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
105754 +static struct rtnl_link_ops internal_dev_link_ops = {
105755 .kind = "openvswitch",
105756 };
105757
105758 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105759 index 93896d2..b701c88 100644
105760 --- a/net/packet/af_packet.c
105761 +++ b/net/packet/af_packet.c
105762 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105763
105764 return ret;
105765 drop:
105766 - atomic_long_inc(&dev->tx_dropped);
105767 + atomic_long_inc_unchecked(&dev->tx_dropped);
105768 kfree_skb(skb);
105769 return NET_XMIT_DROP;
105770 }
105771 @@ -1842,7 +1842,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105772
105773 spin_lock(&sk->sk_receive_queue.lock);
105774 po->stats.stats1.tp_packets++;
105775 - skb->dropcount = atomic_read(&sk->sk_drops);
105776 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105777 __skb_queue_tail(&sk->sk_receive_queue, skb);
105778 spin_unlock(&sk->sk_receive_queue.lock);
105779 sk->sk_data_ready(sk);
105780 @@ -1851,7 +1851,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105781 drop_n_acct:
105782 spin_lock(&sk->sk_receive_queue.lock);
105783 po->stats.stats1.tp_drops++;
105784 - atomic_inc(&sk->sk_drops);
105785 + atomic_inc_unchecked(&sk->sk_drops);
105786 spin_unlock(&sk->sk_receive_queue.lock);
105787
105788 drop_n_restore:
105789 @@ -3466,7 +3466,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105790 case PACKET_HDRLEN:
105791 if (len > sizeof(int))
105792 len = sizeof(int);
105793 - if (copy_from_user(&val, optval, len))
105794 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105795 return -EFAULT;
105796 switch (val) {
105797 case TPACKET_V1:
105798 @@ -3512,7 +3512,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105799 len = lv;
105800 if (put_user(len, optlen))
105801 return -EFAULT;
105802 - if (copy_to_user(optval, data, len))
105803 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105804 return -EFAULT;
105805 return 0;
105806 }
105807 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105808 index 70a547e..23477fe 100644
105809 --- a/net/phonet/pep.c
105810 +++ b/net/phonet/pep.c
105811 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105812
105813 case PNS_PEP_CTRL_REQ:
105814 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105815 - atomic_inc(&sk->sk_drops);
105816 + atomic_inc_unchecked(&sk->sk_drops);
105817 break;
105818 }
105819 __skb_pull(skb, 4);
105820 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105821 }
105822
105823 if (pn->rx_credits == 0) {
105824 - atomic_inc(&sk->sk_drops);
105825 + atomic_inc_unchecked(&sk->sk_drops);
105826 err = -ENOBUFS;
105827 break;
105828 }
105829 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105830 }
105831
105832 if (pn->rx_credits == 0) {
105833 - atomic_inc(&sk->sk_drops);
105834 + atomic_inc_unchecked(&sk->sk_drops);
105835 err = NET_RX_DROP;
105836 break;
105837 }
105838 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105839 index 008214a..bb68240 100644
105840 --- a/net/phonet/socket.c
105841 +++ b/net/phonet/socket.c
105842 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105843 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105844 sock_i_ino(sk),
105845 atomic_read(&sk->sk_refcnt), sk,
105846 - atomic_read(&sk->sk_drops));
105847 + atomic_read_unchecked(&sk->sk_drops));
105848 }
105849 seq_pad(seq, '\n');
105850 return 0;
105851 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105852 index c02a8c4..3c5b600 100644
105853 --- a/net/phonet/sysctl.c
105854 +++ b/net/phonet/sysctl.c
105855 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105856 {
105857 int ret;
105858 int range[2] = {local_port_range[0], local_port_range[1]};
105859 - struct ctl_table tmp = {
105860 + ctl_table_no_const tmp = {
105861 .data = &range,
105862 .maxlen = sizeof(range),
105863 .mode = table->mode,
105864 diff --git a/net/rds/cong.c b/net/rds/cong.c
105865 index e5b65ac..f3b6fb7 100644
105866 --- a/net/rds/cong.c
105867 +++ b/net/rds/cong.c
105868 @@ -78,7 +78,7 @@
105869 * finds that the saved generation number is smaller than the global generation
105870 * number, it wakes up the process.
105871 */
105872 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105873 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105874
105875 /*
105876 * Congestion monitoring
105877 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105878 rdsdebug("waking map %p for %pI4\n",
105879 map, &map->m_addr);
105880 rds_stats_inc(s_cong_update_received);
105881 - atomic_inc(&rds_cong_generation);
105882 + atomic_inc_unchecked(&rds_cong_generation);
105883 if (waitqueue_active(&map->m_waitq))
105884 wake_up(&map->m_waitq);
105885 if (waitqueue_active(&rds_poll_waitq))
105886 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105887
105888 int rds_cong_updated_since(unsigned long *recent)
105889 {
105890 - unsigned long gen = atomic_read(&rds_cong_generation);
105891 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105892
105893 if (likely(*recent == gen))
105894 return 0;
105895 diff --git a/net/rds/ib.h b/net/rds/ib.h
105896 index 7280ab8..e04f4ea 100644
105897 --- a/net/rds/ib.h
105898 +++ b/net/rds/ib.h
105899 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105900 /* sending acks */
105901 unsigned long i_ack_flags;
105902 #ifdef KERNEL_HAS_ATOMIC64
105903 - atomic64_t i_ack_next; /* next ACK to send */
105904 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105905 #else
105906 spinlock_t i_ack_lock; /* protect i_ack_next */
105907 u64 i_ack_next; /* next ACK to send */
105908 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105909 index 31b74f5..dc1fbfa 100644
105910 --- a/net/rds/ib_cm.c
105911 +++ b/net/rds/ib_cm.c
105912 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105913 /* Clear the ACK state */
105914 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105915 #ifdef KERNEL_HAS_ATOMIC64
105916 - atomic64_set(&ic->i_ack_next, 0);
105917 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105918 #else
105919 ic->i_ack_next = 0;
105920 #endif
105921 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105922 index d67de45..73dbf51 100644
105923 --- a/net/rds/ib_recv.c
105924 +++ b/net/rds/ib_recv.c
105925 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105926 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105927 int ack_required)
105928 {
105929 - atomic64_set(&ic->i_ack_next, seq);
105930 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105931 if (ack_required) {
105932 smp_mb__before_atomic();
105933 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105934 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105935 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105936 smp_mb__after_atomic();
105937
105938 - return atomic64_read(&ic->i_ack_next);
105939 + return atomic64_read_unchecked(&ic->i_ack_next);
105940 }
105941 #endif
105942
105943 diff --git a/net/rds/iw.h b/net/rds/iw.h
105944 index 04ce3b1..48119a6 100644
105945 --- a/net/rds/iw.h
105946 +++ b/net/rds/iw.h
105947 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105948 /* sending acks */
105949 unsigned long i_ack_flags;
105950 #ifdef KERNEL_HAS_ATOMIC64
105951 - atomic64_t i_ack_next; /* next ACK to send */
105952 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105953 #else
105954 spinlock_t i_ack_lock; /* protect i_ack_next */
105955 u64 i_ack_next; /* next ACK to send */
105956 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105957 index a91e1db..cf3053f 100644
105958 --- a/net/rds/iw_cm.c
105959 +++ b/net/rds/iw_cm.c
105960 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105961 /* Clear the ACK state */
105962 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105963 #ifdef KERNEL_HAS_ATOMIC64
105964 - atomic64_set(&ic->i_ack_next, 0);
105965 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105966 #else
105967 ic->i_ack_next = 0;
105968 #endif
105969 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105970 index aa8bf67..b70133c 100644
105971 --- a/net/rds/iw_recv.c
105972 +++ b/net/rds/iw_recv.c
105973 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105974 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105975 int ack_required)
105976 {
105977 - atomic64_set(&ic->i_ack_next, seq);
105978 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105979 if (ack_required) {
105980 smp_mb__before_atomic();
105981 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105982 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105983 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105984 smp_mb__after_atomic();
105985
105986 - return atomic64_read(&ic->i_ack_next);
105987 + return atomic64_read_unchecked(&ic->i_ack_next);
105988 }
105989 #endif
105990
105991 diff --git a/net/rds/rdma.c b/net/rds/rdma.c
105992 index 4e37c1c..40084d8 100644
105993 --- a/net/rds/rdma.c
105994 +++ b/net/rds/rdma.c
105995 @@ -564,12 +564,12 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105996
105997 if (rs->rs_bound_addr == 0) {
105998 ret = -ENOTCONN; /* XXX not a great errno */
105999 - goto out;
106000 + goto out_ret;
106001 }
106002
106003 if (args->nr_local > UIO_MAXIOV) {
106004 ret = -EMSGSIZE;
106005 - goto out;
106006 + goto out_ret;
106007 }
106008
106009 /* Check whether to allocate the iovec area */
106010 @@ -578,7 +578,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
106011 iovs = sock_kmalloc(rds_rs_to_sk(rs), iov_size, GFP_KERNEL);
106012 if (!iovs) {
106013 ret = -ENOMEM;
106014 - goto out;
106015 + goto out_ret;
106016 }
106017 }
106018
106019 @@ -696,6 +696,7 @@ out:
106020 if (iovs != iovstack)
106021 sock_kfree_s(rds_rs_to_sk(rs), iovs, iov_size);
106022 kfree(pages);
106023 +out_ret:
106024 if (ret)
106025 rds_rdma_free_op(op);
106026 else
106027 diff --git a/net/rds/rds.h b/net/rds/rds.h
106028 index 48f8ffc..0ef3eec 100644
106029 --- a/net/rds/rds.h
106030 +++ b/net/rds/rds.h
106031 @@ -449,7 +449,7 @@ struct rds_transport {
106032 void (*sync_mr)(void *trans_private, int direction);
106033 void (*free_mr)(void *trans_private, int invalidate);
106034 void (*flush_mrs)(void);
106035 -};
106036 +} __do_const;
106037
106038 struct rds_sock {
106039 struct sock rs_sk;
106040 diff --git a/net/rds/send.c b/net/rds/send.c
106041 index 2371816..0a64541 100644
106042 --- a/net/rds/send.c
106043 +++ b/net/rds/send.c
106044 @@ -593,8 +593,11 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
106045 sock_put(rds_rs_to_sk(rs));
106046 }
106047 rs = rm->m_rs;
106048 - sock_hold(rds_rs_to_sk(rs));
106049 + if (rs)
106050 + sock_hold(rds_rs_to_sk(rs));
106051 }
106052 + if (!rs)
106053 + goto unlock_and_drop;
106054 spin_lock(&rs->rs_lock);
106055
106056 if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) {
106057 @@ -638,9 +641,6 @@ unlock_and_drop:
106058 * queue. This means that in the TCP case, the message may not have been
106059 * assigned the m_ack_seq yet - but that's fine as long as tcp_is_acked
106060 * checks the RDS_MSG_HAS_ACK_SEQ bit.
106061 - *
106062 - * XXX It's not clear to me how this is safely serialized with socket
106063 - * destruction. Maybe it should bail if it sees SOCK_DEAD.
106064 */
106065 void rds_send_drop_acked(struct rds_connection *conn, u64 ack,
106066 is_acked_func is_acked)
106067 @@ -711,6 +711,9 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
106068 */
106069 if (!test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) {
106070 spin_unlock_irqrestore(&conn->c_lock, flags);
106071 + spin_lock_irqsave(&rm->m_rs_lock, flags);
106072 + rm->m_rs = NULL;
106073 + spin_unlock_irqrestore(&rm->m_rs_lock, flags);
106074 continue;
106075 }
106076 list_del_init(&rm->m_conn_item);
106077 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
106078 index edac9ef..16bcb98 100644
106079 --- a/net/rds/tcp.c
106080 +++ b/net/rds/tcp.c
106081 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
106082 int val = 1;
106083
106084 set_fs(KERNEL_DS);
106085 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
106086 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
106087 sizeof(val));
106088 set_fs(oldfs);
106089 }
106090 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
106091 index 53b17ca..45463e7 100644
106092 --- a/net/rds/tcp_send.c
106093 +++ b/net/rds/tcp_send.c
106094 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
106095
106096 oldfs = get_fs();
106097 set_fs(KERNEL_DS);
106098 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
106099 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
106100 sizeof(val));
106101 set_fs(oldfs);
106102 }
106103 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
106104 index 7b16704..9628ec6 100644
106105 --- a/net/rxrpc/af_rxrpc.c
106106 +++ b/net/rxrpc/af_rxrpc.c
106107 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
106108 __be32 rxrpc_epoch;
106109
106110 /* current debugging ID */
106111 -atomic_t rxrpc_debug_id;
106112 +atomic_unchecked_t rxrpc_debug_id;
106113
106114 /* count of skbs currently in use */
106115 atomic_t rxrpc_n_skbs;
106116 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
106117 index c6be17a..2a6200a 100644
106118 --- a/net/rxrpc/ar-ack.c
106119 +++ b/net/rxrpc/ar-ack.c
106120 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106121
106122 _enter("{%d,%d,%d,%d},",
106123 call->acks_hard, call->acks_unacked,
106124 - atomic_read(&call->sequence),
106125 + atomic_read_unchecked(&call->sequence),
106126 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
106127
106128 stop = 0;
106129 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106130
106131 /* each Tx packet has a new serial number */
106132 sp->hdr.serial =
106133 - htonl(atomic_inc_return(&call->conn->serial));
106134 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
106135
106136 hdr = (struct rxrpc_header *) txb->head;
106137 hdr->serial = sp->hdr.serial;
106138 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
106139 */
106140 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
106141 {
106142 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
106143 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
106144 }
106145
106146 /*
106147 @@ -677,7 +677,7 @@ process_further:
106148
106149 latest = ntohl(sp->hdr.serial);
106150 hard = ntohl(ack.firstPacket);
106151 - tx = atomic_read(&call->sequence);
106152 + tx = atomic_read_unchecked(&call->sequence);
106153
106154 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106155 latest,
106156 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
106157 goto maybe_reschedule;
106158
106159 send_ACK_with_skew:
106160 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
106161 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
106162 ntohl(ack.serial));
106163 send_ACK:
106164 mtu = call->conn->trans->peer->if_mtu;
106165 @@ -1221,7 +1221,7 @@ send_ACK:
106166 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
106167 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
106168
106169 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106170 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106171 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106172 ntohl(hdr.serial),
106173 ntohs(ack.maxSkew),
106174 @@ -1239,7 +1239,7 @@ send_ACK:
106175 send_message:
106176 _debug("send message");
106177
106178 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106179 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106180 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
106181 send_message_2:
106182
106183 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
106184 index a9e05db..194e793 100644
106185 --- a/net/rxrpc/ar-call.c
106186 +++ b/net/rxrpc/ar-call.c
106187 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
106188 spin_lock_init(&call->lock);
106189 rwlock_init(&call->state_lock);
106190 atomic_set(&call->usage, 1);
106191 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
106192 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106193 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
106194
106195 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
106196 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
106197 index 6631f4f..bfdf056 100644
106198 --- a/net/rxrpc/ar-connection.c
106199 +++ b/net/rxrpc/ar-connection.c
106200 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
106201 rwlock_init(&conn->lock);
106202 spin_lock_init(&conn->state_lock);
106203 atomic_set(&conn->usage, 1);
106204 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
106205 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106206 conn->avail_calls = RXRPC_MAXCALLS;
106207 conn->size_align = 4;
106208 conn->header_size = sizeof(struct rxrpc_header);
106209 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
106210 index e7ed43a..6afa140 100644
106211 --- a/net/rxrpc/ar-connevent.c
106212 +++ b/net/rxrpc/ar-connevent.c
106213 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
106214
106215 len = iov[0].iov_len + iov[1].iov_len;
106216
106217 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106218 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106219 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
106220
106221 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106222 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
106223 index 63b21e5..330232e 100644
106224 --- a/net/rxrpc/ar-input.c
106225 +++ b/net/rxrpc/ar-input.c
106226 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
106227 /* track the latest serial number on this connection for ACK packet
106228 * information */
106229 serial = ntohl(sp->hdr.serial);
106230 - hi_serial = atomic_read(&call->conn->hi_serial);
106231 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
106232 while (serial > hi_serial)
106233 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
106234 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
106235 serial);
106236
106237 /* request ACK generation for any ACK or DATA packet that requests
106238 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
106239 index ba9fd36..9bbfe01 100644
106240 --- a/net/rxrpc/ar-internal.h
106241 +++ b/net/rxrpc/ar-internal.h
106242 @@ -272,8 +272,8 @@ struct rxrpc_connection {
106243 int error; /* error code for local abort */
106244 int debug_id; /* debug ID for printks */
106245 unsigned int call_counter; /* call ID counter */
106246 - atomic_t serial; /* packet serial number counter */
106247 - atomic_t hi_serial; /* highest serial number received */
106248 + atomic_unchecked_t serial; /* packet serial number counter */
106249 + atomic_unchecked_t hi_serial; /* highest serial number received */
106250 u8 avail_calls; /* number of calls available */
106251 u8 size_align; /* data size alignment (for security) */
106252 u8 header_size; /* rxrpc + security header size */
106253 @@ -346,7 +346,7 @@ struct rxrpc_call {
106254 spinlock_t lock;
106255 rwlock_t state_lock; /* lock for state transition */
106256 atomic_t usage;
106257 - atomic_t sequence; /* Tx data packet sequence counter */
106258 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106259 u32 abort_code; /* local/remote abort code */
106260 enum { /* current state of call */
106261 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106262 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106263 */
106264 extern atomic_t rxrpc_n_skbs;
106265 extern __be32 rxrpc_epoch;
106266 -extern atomic_t rxrpc_debug_id;
106267 +extern atomic_unchecked_t rxrpc_debug_id;
106268 extern struct workqueue_struct *rxrpc_workqueue;
106269
106270 /*
106271 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106272 index 87f7135..74d3703 100644
106273 --- a/net/rxrpc/ar-local.c
106274 +++ b/net/rxrpc/ar-local.c
106275 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106276 spin_lock_init(&local->lock);
106277 rwlock_init(&local->services_lock);
106278 atomic_set(&local->usage, 1);
106279 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106280 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106281 memcpy(&local->srx, srx, sizeof(*srx));
106282 }
106283
106284 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106285 index 0b4b9a7..966ffbb 100644
106286 --- a/net/rxrpc/ar-output.c
106287 +++ b/net/rxrpc/ar-output.c
106288 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106289 memset(skb_put(skb, pad), 0, pad);
106290 }
106291
106292 - seq = atomic_inc_return(&call->sequence);
106293 + seq = atomic_inc_return_unchecked(&call->sequence);
106294
106295 sp->hdr.epoch = conn->epoch;
106296 sp->hdr.cid = call->cid;
106297 sp->hdr.callNumber = call->call_id;
106298 sp->hdr.seq = htonl(seq);
106299 sp->hdr.serial =
106300 - htonl(atomic_inc_return(&conn->serial));
106301 + htonl(atomic_inc_return_unchecked(&conn->serial));
106302 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106303 sp->hdr.userStatus = 0;
106304 sp->hdr.securityIndex = conn->security_ix;
106305 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106306 index bebaa43..2644591 100644
106307 --- a/net/rxrpc/ar-peer.c
106308 +++ b/net/rxrpc/ar-peer.c
106309 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106310 INIT_LIST_HEAD(&peer->error_targets);
106311 spin_lock_init(&peer->lock);
106312 atomic_set(&peer->usage, 1);
106313 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106314 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106315 memcpy(&peer->srx, srx, sizeof(*srx));
106316
106317 rxrpc_assess_MTU_size(peer);
106318 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106319 index 38047f7..9f48511 100644
106320 --- a/net/rxrpc/ar-proc.c
106321 +++ b/net/rxrpc/ar-proc.c
106322 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106323 atomic_read(&conn->usage),
106324 rxrpc_conn_states[conn->state],
106325 key_serial(conn->key),
106326 - atomic_read(&conn->serial),
106327 - atomic_read(&conn->hi_serial));
106328 + atomic_read_unchecked(&conn->serial),
106329 + atomic_read_unchecked(&conn->hi_serial));
106330
106331 return 0;
106332 }
106333 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106334 index 1976dec..aa70be5 100644
106335 --- a/net/rxrpc/ar-transport.c
106336 +++ b/net/rxrpc/ar-transport.c
106337 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106338 spin_lock_init(&trans->client_lock);
106339 rwlock_init(&trans->conn_lock);
106340 atomic_set(&trans->usage, 1);
106341 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106342 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106343
106344 if (peer->srx.transport.family == AF_INET) {
106345 switch (peer->srx.transport_type) {
106346 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106347 index f226709..0e735a8 100644
106348 --- a/net/rxrpc/rxkad.c
106349 +++ b/net/rxrpc/rxkad.c
106350 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106351
106352 len = iov[0].iov_len + iov[1].iov_len;
106353
106354 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106355 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106356 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106357
106358 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106359 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106360
106361 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106362
106363 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106364 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106365 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106366
106367 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106368 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106369 index fc04fe9..8167357 100644
106370 --- a/net/sched/sch_generic.c
106371 +++ b/net/sched/sch_generic.c
106372 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
106373 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106374 if (dev->reg_state == NETREG_UNINITIALIZED)
106375 return;
106376 - atomic_inc(&dev->carrier_changes);
106377 + atomic_inc_unchecked(&dev->carrier_changes);
106378 linkwatch_fire_event(dev);
106379 if (netif_running(dev))
106380 __netdev_watchdog_up(dev);
106381 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
106382 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106383 if (dev->reg_state == NETREG_UNINITIALIZED)
106384 return;
106385 - atomic_inc(&dev->carrier_changes);
106386 + atomic_inc_unchecked(&dev->carrier_changes);
106387 linkwatch_fire_event(dev);
106388 }
106389 }
106390 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106391 index 0e4198e..f94193e 100644
106392 --- a/net/sctp/ipv6.c
106393 +++ b/net/sctp/ipv6.c
106394 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106395 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106396 };
106397
106398 -static struct sctp_af sctp_af_inet6 = {
106399 +static struct sctp_af sctp_af_inet6 __read_only = {
106400 .sa_family = AF_INET6,
106401 .sctp_xmit = sctp_v6_xmit,
106402 .setsockopt = ipv6_setsockopt,
106403 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106404 #endif
106405 };
106406
106407 -static struct sctp_pf sctp_pf_inet6 = {
106408 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106409 .event_msgname = sctp_inet6_event_msgname,
106410 .skb_msgname = sctp_inet6_skb_msgname,
106411 .af_supported = sctp_inet6_af_supported,
106412 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106413
106414 void sctp_v6_pf_exit(void)
106415 {
106416 - list_del(&sctp_af_inet6.list);
106417 + pax_list_del(&sctp_af_inet6.list);
106418 }
106419
106420 /* Initialize IPv6 support and register with socket layer. */
106421 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106422 index 6240834..cac4b52 100644
106423 --- a/net/sctp/protocol.c
106424 +++ b/net/sctp/protocol.c
106425 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106426 return 0;
106427 }
106428
106429 + pax_open_kernel();
106430 INIT_LIST_HEAD(&af->list);
106431 - list_add_tail(&af->list, &sctp_address_families);
106432 + pax_close_kernel();
106433 + pax_list_add_tail(&af->list, &sctp_address_families);
106434 return 1;
106435 }
106436
106437 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106438
106439 static struct sctp_af sctp_af_inet;
106440
106441 -static struct sctp_pf sctp_pf_inet = {
106442 +static struct sctp_pf sctp_pf_inet __read_only = {
106443 .event_msgname = sctp_inet_event_msgname,
106444 .skb_msgname = sctp_inet_skb_msgname,
106445 .af_supported = sctp_inet_af_supported,
106446 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106447 };
106448
106449 /* IPv4 address related functions. */
106450 -static struct sctp_af sctp_af_inet = {
106451 +static struct sctp_af sctp_af_inet __read_only = {
106452 .sa_family = AF_INET,
106453 .sctp_xmit = sctp_v4_xmit,
106454 .setsockopt = ip_setsockopt,
106455 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106456
106457 static void sctp_v4_pf_exit(void)
106458 {
106459 - list_del(&sctp_af_inet.list);
106460 + pax_list_del(&sctp_af_inet.list);
106461 }
106462
106463 static int sctp_v4_protosw_init(void)
106464 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106465 index fef2acd..c705c4f 100644
106466 --- a/net/sctp/sm_sideeffect.c
106467 +++ b/net/sctp/sm_sideeffect.c
106468 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106469 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106470 }
106471
106472 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106473 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106474 NULL,
106475 sctp_generate_t1_cookie_event,
106476 sctp_generate_t1_init_event,
106477 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106478 index 634a2ab..8e93929 100644
106479 --- a/net/sctp/socket.c
106480 +++ b/net/sctp/socket.c
106481 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106482 {
106483 struct sctp_association *asoc;
106484 struct sctp_ulpevent *event;
106485 + struct sctp_event_subscribe subscribe;
106486
106487 if (optlen > sizeof(struct sctp_event_subscribe))
106488 return -EINVAL;
106489 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106490 + if (copy_from_user(&subscribe, optval, optlen))
106491 return -EFAULT;
106492 + sctp_sk(sk)->subscribe = subscribe;
106493
106494 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106495 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106496 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106497 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106498 int __user *optlen)
106499 {
106500 + struct sctp_event_subscribe subscribe;
106501 +
106502 if (len <= 0)
106503 return -EINVAL;
106504 if (len > sizeof(struct sctp_event_subscribe))
106505 len = sizeof(struct sctp_event_subscribe);
106506 if (put_user(len, optlen))
106507 return -EFAULT;
106508 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106509 + subscribe = sctp_sk(sk)->subscribe;
106510 + if (copy_to_user(optval, &subscribe, len))
106511 return -EFAULT;
106512 return 0;
106513 }
106514 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106515 */
106516 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106517 {
106518 + __u32 autoclose;
106519 +
106520 /* Applicable to UDP-style socket only */
106521 if (sctp_style(sk, TCP))
106522 return -EOPNOTSUPP;
106523 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106524 len = sizeof(int);
106525 if (put_user(len, optlen))
106526 return -EFAULT;
106527 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106528 + autoclose = sctp_sk(sk)->autoclose;
106529 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106530 return -EFAULT;
106531 return 0;
106532 }
106533 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106534 */
106535 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106536 {
106537 + struct sctp_initmsg initmsg;
106538 +
106539 if (len < sizeof(struct sctp_initmsg))
106540 return -EINVAL;
106541 len = sizeof(struct sctp_initmsg);
106542 if (put_user(len, optlen))
106543 return -EFAULT;
106544 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106545 + initmsg = sctp_sk(sk)->initmsg;
106546 + if (copy_to_user(optval, &initmsg, len))
106547 return -EFAULT;
106548 return 0;
106549 }
106550 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106551 ->addr_to_user(sp, &temp);
106552 if (space_left < addrlen)
106553 return -ENOMEM;
106554 + if (addrlen > sizeof(temp) || addrlen < 0)
106555 + return -EFAULT;
106556 if (copy_to_user(to, &temp, addrlen))
106557 return -EFAULT;
106558 to += addrlen;
106559 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106560 index 2e9ada1..40f425d 100644
106561 --- a/net/sctp/sysctl.c
106562 +++ b/net/sctp/sysctl.c
106563 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106564 loff_t *ppos)
106565 {
106566 struct net *net = current->nsproxy->net_ns;
106567 - struct ctl_table tbl;
106568 + ctl_table_no_const tbl;
106569 bool changed = false;
106570 char *none = "none";
106571 char tmp[8];
106572 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106573 struct net *net = current->nsproxy->net_ns;
106574 unsigned int min = *(unsigned int *) ctl->extra1;
106575 unsigned int max = *(unsigned int *) ctl->extra2;
106576 - struct ctl_table tbl;
106577 + ctl_table_no_const tbl;
106578 int ret, new_value;
106579
106580 memset(&tbl, 0, sizeof(struct ctl_table));
106581 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106582 struct net *net = current->nsproxy->net_ns;
106583 unsigned int min = *(unsigned int *) ctl->extra1;
106584 unsigned int max = *(unsigned int *) ctl->extra2;
106585 - struct ctl_table tbl;
106586 + ctl_table_no_const tbl;
106587 int ret, new_value;
106588
106589 memset(&tbl, 0, sizeof(struct ctl_table));
106590 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106591 loff_t *ppos)
106592 {
106593 struct net *net = current->nsproxy->net_ns;
106594 - struct ctl_table tbl;
106595 + ctl_table_no_const tbl;
106596 int new_value, ret;
106597
106598 memset(&tbl, 0, sizeof(struct ctl_table));
106599 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106600
106601 int sctp_sysctl_net_register(struct net *net)
106602 {
106603 - struct ctl_table *table;
106604 + ctl_table_no_const *table;
106605 int i;
106606
106607 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106608 diff --git a/net/socket.c b/net/socket.c
106609 index 4cdbc10..f075204 100644
106610 --- a/net/socket.c
106611 +++ b/net/socket.c
106612 @@ -89,6 +89,7 @@
106613 #include <linux/magic.h>
106614 #include <linux/slab.h>
106615 #include <linux/xattr.h>
106616 +#include <linux/in.h>
106617
106618 #include <asm/uaccess.h>
106619 #include <asm/unistd.h>
106620 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106621 unsigned int sysctl_net_busy_poll __read_mostly;
106622 #endif
106623
106624 +#include <linux/grsock.h>
106625 +
106626 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106627 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106628 unsigned long nr_segs, loff_t pos);
106629 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106630 */
106631
106632 static DEFINE_SPINLOCK(net_family_lock);
106633 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106634 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106635
106636 /*
106637 * Statistics counters of the socket lists
106638 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106639 &sockfs_dentry_operations, SOCKFS_MAGIC);
106640 }
106641
106642 -static struct vfsmount *sock_mnt __read_mostly;
106643 +struct vfsmount *sock_mnt __read_mostly;
106644
106645 static struct file_system_type sock_fs_type = {
106646 .name = "sockfs",
106647 @@ -1265,6 +1268,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106648 return -EAFNOSUPPORT;
106649 if (type < 0 || type >= SOCK_MAX)
106650 return -EINVAL;
106651 + if (protocol < 0)
106652 + return -EINVAL;
106653
106654 /* Compatibility.
106655
106656 @@ -1285,6 +1290,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106657 if (err)
106658 return err;
106659
106660 + if(!kern && !gr_search_socket(family, type, protocol)) {
106661 + if (rcu_access_pointer(net_families[family]) == NULL)
106662 + return -EAFNOSUPPORT;
106663 + else
106664 + return -EACCES;
106665 + }
106666 +
106667 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106668 + if (rcu_access_pointer(net_families[family]) == NULL)
106669 + return -EAFNOSUPPORT;
106670 + else
106671 + return -EACCES;
106672 + }
106673 +
106674 /*
106675 * Allocate the socket and allow the family to set things up. if
106676 * the protocol is 0, the family is instructed to select an appropriate
106677 @@ -1536,6 +1555,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106678 if (sock) {
106679 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106680 if (err >= 0) {
106681 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106682 + err = -EACCES;
106683 + goto error;
106684 + }
106685 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106686 + if (err)
106687 + goto error;
106688 +
106689 err = security_socket_bind(sock,
106690 (struct sockaddr *)&address,
106691 addrlen);
106692 @@ -1544,6 +1571,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106693 (struct sockaddr *)
106694 &address, addrlen);
106695 }
106696 +error:
106697 fput_light(sock->file, fput_needed);
106698 }
106699 return err;
106700 @@ -1567,10 +1595,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106701 if ((unsigned int)backlog > somaxconn)
106702 backlog = somaxconn;
106703
106704 + if (gr_handle_sock_server_other(sock->sk)) {
106705 + err = -EPERM;
106706 + goto error;
106707 + }
106708 +
106709 + err = gr_search_listen(sock);
106710 + if (err)
106711 + goto error;
106712 +
106713 err = security_socket_listen(sock, backlog);
106714 if (!err)
106715 err = sock->ops->listen(sock, backlog);
106716
106717 +error:
106718 fput_light(sock->file, fput_needed);
106719 }
106720 return err;
106721 @@ -1614,6 +1652,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106722 newsock->type = sock->type;
106723 newsock->ops = sock->ops;
106724
106725 + if (gr_handle_sock_server_other(sock->sk)) {
106726 + err = -EPERM;
106727 + sock_release(newsock);
106728 + goto out_put;
106729 + }
106730 +
106731 + err = gr_search_accept(sock);
106732 + if (err) {
106733 + sock_release(newsock);
106734 + goto out_put;
106735 + }
106736 +
106737 /*
106738 * We don't need try_module_get here, as the listening socket (sock)
106739 * has the protocol module (sock->ops->owner) held.
106740 @@ -1659,6 +1709,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106741 fd_install(newfd, newfile);
106742 err = newfd;
106743
106744 + gr_attach_curr_ip(newsock->sk);
106745 +
106746 out_put:
106747 fput_light(sock->file, fput_needed);
106748 out:
106749 @@ -1691,6 +1743,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106750 int, addrlen)
106751 {
106752 struct socket *sock;
106753 + struct sockaddr *sck;
106754 struct sockaddr_storage address;
106755 int err, fput_needed;
106756
106757 @@ -1701,6 +1754,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106758 if (err < 0)
106759 goto out_put;
106760
106761 + sck = (struct sockaddr *)&address;
106762 +
106763 + if (gr_handle_sock_client(sck)) {
106764 + err = -EACCES;
106765 + goto out_put;
106766 + }
106767 +
106768 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106769 + if (err)
106770 + goto out_put;
106771 +
106772 err =
106773 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106774 if (err)
106775 @@ -1782,6 +1846,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106776 * the protocol.
106777 */
106778
106779 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106780 +
106781 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106782 unsigned int, flags, struct sockaddr __user *, addr,
106783 int, addr_len)
106784 @@ -1848,7 +1914,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106785 struct socket *sock;
106786 struct iovec iov;
106787 struct msghdr msg;
106788 - struct sockaddr_storage address;
106789 + struct sockaddr_storage address = { };
106790 int err, err2;
106791 int fput_needed;
106792
106793 @@ -2077,7 +2143,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106794 * checking falls down on this.
106795 */
106796 if (copy_from_user(ctl_buf,
106797 - (void __user __force *)msg_sys->msg_control,
106798 + (void __force_user *)msg_sys->msg_control,
106799 ctl_len))
106800 goto out_freectl;
106801 msg_sys->msg_control = ctl_buf;
106802 @@ -2228,7 +2294,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106803 int err, total_len, len;
106804
106805 /* kernel mode address */
106806 - struct sockaddr_storage addr;
106807 + struct sockaddr_storage addr = { };
106808
106809 /* user mode address pointers */
106810 struct sockaddr __user *uaddr;
106811 @@ -2257,7 +2323,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106812 /* Save the user-mode address (verify_iovec will change the
106813 * kernel msghdr to use the kernel address space)
106814 */
106815 - uaddr = (__force void __user *)msg_sys->msg_name;
106816 + uaddr = (void __force_user *)msg_sys->msg_name;
106817 uaddr_len = COMPAT_NAMELEN(msg);
106818 if (MSG_CMSG_COMPAT & flags)
106819 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106820 @@ -2898,7 +2964,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106821 ifr = compat_alloc_user_space(buf_size);
106822 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106823
106824 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106825 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106826 return -EFAULT;
106827
106828 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106829 @@ -3009,7 +3075,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106830 old_fs = get_fs();
106831 set_fs(KERNEL_DS);
106832 err = dev_ioctl(net, cmd,
106833 - (struct ifreq __user __force *) &kifr);
106834 + (struct ifreq __force_user *) &kifr);
106835 set_fs(old_fs);
106836
106837 return err;
106838 @@ -3102,7 +3168,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106839
106840 old_fs = get_fs();
106841 set_fs(KERNEL_DS);
106842 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106843 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106844 set_fs(old_fs);
106845
106846 if (cmd == SIOCGIFMAP && !err) {
106847 @@ -3186,7 +3252,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106848 ret |= get_user(rtdev, &(ur4->rt_dev));
106849 if (rtdev) {
106850 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106851 - r4.rt_dev = (char __user __force *)devname;
106852 + r4.rt_dev = (char __force_user *)devname;
106853 devname[15] = 0;
106854 } else
106855 r4.rt_dev = NULL;
106856 @@ -3413,8 +3479,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106857 int __user *uoptlen;
106858 int err;
106859
106860 - uoptval = (char __user __force *) optval;
106861 - uoptlen = (int __user __force *) optlen;
106862 + uoptval = (char __force_user *) optval;
106863 + uoptlen = (int __force_user *) optlen;
106864
106865 set_fs(KERNEL_DS);
106866 if (level == SOL_SOCKET)
106867 @@ -3434,7 +3500,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106868 char __user *uoptval;
106869 int err;
106870
106871 - uoptval = (char __user __force *) optval;
106872 + uoptval = (char __force_user *) optval;
106873
106874 set_fs(KERNEL_DS);
106875 if (level == SOL_SOCKET)
106876 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106877 index c548ab2..4e1b68b 100644
106878 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106879 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106880 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106881 uint64_t *handle)
106882 {
106883 struct rsc rsci, *rscp = NULL;
106884 - static atomic64_t ctxhctr;
106885 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106886 long long ctxh;
106887 struct gss_api_mech *gm = NULL;
106888 time_t expiry;
106889 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106890 status = -ENOMEM;
106891 /* the handle needs to be just a unique id,
106892 * use a static counter */
106893 - ctxh = atomic64_inc_return(&ctxhctr);
106894 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106895
106896 /* make a copy for the caller */
106897 *handle = ctxh;
106898 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106899 index 0663621..c4928d4 100644
106900 --- a/net/sunrpc/cache.c
106901 +++ b/net/sunrpc/cache.c
106902 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106903 struct sunrpc_net *sn;
106904
106905 sn = net_generic(net, sunrpc_net_id);
106906 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106907 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106908 if (cd->u.procfs.proc_ent == NULL)
106909 goto out_nomem;
106910 cd->u.procfs.channel_ent = NULL;
106911 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106912 index e0b94ce..6135813 100644
106913 --- a/net/sunrpc/clnt.c
106914 +++ b/net/sunrpc/clnt.c
106915 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106916 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106917
106918 /* Increment call count */
106919 - task->tk_msg.rpc_proc->p_count++;
106920 + pax_open_kernel();
106921 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106922 + pax_close_kernel();
106923 clnt->cl_stats->rpccnt++;
106924 task->tk_action = call_reserve;
106925 }
106926 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106927 index 9358c79..22d0a5b 100644
106928 --- a/net/sunrpc/sched.c
106929 +++ b/net/sunrpc/sched.c
106930 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106931 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106932 static void rpc_task_set_debuginfo(struct rpc_task *task)
106933 {
106934 - static atomic_t rpc_pid;
106935 + static atomic_unchecked_t rpc_pid;
106936
106937 - task->tk_pid = atomic_inc_return(&rpc_pid);
106938 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106939 }
106940 #else
106941 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106942 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106943 index 5453049..465669a 100644
106944 --- a/net/sunrpc/stats.c
106945 +++ b/net/sunrpc/stats.c
106946 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106947
106948 dprintk("RPC: registering /proc/net/rpc\n");
106949 sn = net_generic(net, sunrpc_net_id);
106950 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106951 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106952 if (sn->proc_net_rpc == NULL)
106953 return -ENOMEM;
106954
106955 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106956 index 1db5007..6e66296 100644
106957 --- a/net/sunrpc/svc.c
106958 +++ b/net/sunrpc/svc.c
106959 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106960 svc_putnl(resv, RPC_SUCCESS);
106961
106962 /* Bump per-procedure stats counter */
106963 - procp->pc_count++;
106964 + pax_open_kernel();
106965 + (*(unsigned int *)&procp->pc_count)++;
106966 + pax_close_kernel();
106967
106968 /* Initialize storage for argp and resp */
106969 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106970 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106971 index 621ca7b..59421dd 100644
106972 --- a/net/sunrpc/svcauth_unix.c
106973 +++ b/net/sunrpc/svcauth_unix.c
106974 @@ -414,7 +414,7 @@ struct unix_gid {
106975 struct group_info *gi;
106976 };
106977
106978 -static int unix_gid_hash(kuid_t uid)
106979 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106980 {
106981 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106982 }
106983 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106984 (*bpp)[-1] = '\n';
106985 }
106986
106987 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106988 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106989
106990 static int unix_gid_parse(struct cache_detail *cd,
106991 char *mesg, int mlen)
106992 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106993 index c1b6270..05089c1 100644
106994 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106995 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106996 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106997 static unsigned int min_max_inline = 4096;
106998 static unsigned int max_max_inline = 65536;
106999
107000 -atomic_t rdma_stat_recv;
107001 -atomic_t rdma_stat_read;
107002 -atomic_t rdma_stat_write;
107003 -atomic_t rdma_stat_sq_starve;
107004 -atomic_t rdma_stat_rq_starve;
107005 -atomic_t rdma_stat_rq_poll;
107006 -atomic_t rdma_stat_rq_prod;
107007 -atomic_t rdma_stat_sq_poll;
107008 -atomic_t rdma_stat_sq_prod;
107009 +atomic_unchecked_t rdma_stat_recv;
107010 +atomic_unchecked_t rdma_stat_read;
107011 +atomic_unchecked_t rdma_stat_write;
107012 +atomic_unchecked_t rdma_stat_sq_starve;
107013 +atomic_unchecked_t rdma_stat_rq_starve;
107014 +atomic_unchecked_t rdma_stat_rq_poll;
107015 +atomic_unchecked_t rdma_stat_rq_prod;
107016 +atomic_unchecked_t rdma_stat_sq_poll;
107017 +atomic_unchecked_t rdma_stat_sq_prod;
107018
107019 /* Temporary NFS request map and context caches */
107020 struct kmem_cache *svc_rdma_map_cachep;
107021 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
107022 len -= *ppos;
107023 if (len > *lenp)
107024 len = *lenp;
107025 - if (len && copy_to_user(buffer, str_buf, len))
107026 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
107027 return -EFAULT;
107028 *lenp = len;
107029 *ppos += len;
107030 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
107031 {
107032 .procname = "rdma_stat_read",
107033 .data = &rdma_stat_read,
107034 - .maxlen = sizeof(atomic_t),
107035 + .maxlen = sizeof(atomic_unchecked_t),
107036 .mode = 0644,
107037 .proc_handler = read_reset_stat,
107038 },
107039 {
107040 .procname = "rdma_stat_recv",
107041 .data = &rdma_stat_recv,
107042 - .maxlen = sizeof(atomic_t),
107043 + .maxlen = sizeof(atomic_unchecked_t),
107044 .mode = 0644,
107045 .proc_handler = read_reset_stat,
107046 },
107047 {
107048 .procname = "rdma_stat_write",
107049 .data = &rdma_stat_write,
107050 - .maxlen = sizeof(atomic_t),
107051 + .maxlen = sizeof(atomic_unchecked_t),
107052 .mode = 0644,
107053 .proc_handler = read_reset_stat,
107054 },
107055 {
107056 .procname = "rdma_stat_sq_starve",
107057 .data = &rdma_stat_sq_starve,
107058 - .maxlen = sizeof(atomic_t),
107059 + .maxlen = sizeof(atomic_unchecked_t),
107060 .mode = 0644,
107061 .proc_handler = read_reset_stat,
107062 },
107063 {
107064 .procname = "rdma_stat_rq_starve",
107065 .data = &rdma_stat_rq_starve,
107066 - .maxlen = sizeof(atomic_t),
107067 + .maxlen = sizeof(atomic_unchecked_t),
107068 .mode = 0644,
107069 .proc_handler = read_reset_stat,
107070 },
107071 {
107072 .procname = "rdma_stat_rq_poll",
107073 .data = &rdma_stat_rq_poll,
107074 - .maxlen = sizeof(atomic_t),
107075 + .maxlen = sizeof(atomic_unchecked_t),
107076 .mode = 0644,
107077 .proc_handler = read_reset_stat,
107078 },
107079 {
107080 .procname = "rdma_stat_rq_prod",
107081 .data = &rdma_stat_rq_prod,
107082 - .maxlen = sizeof(atomic_t),
107083 + .maxlen = sizeof(atomic_unchecked_t),
107084 .mode = 0644,
107085 .proc_handler = read_reset_stat,
107086 },
107087 {
107088 .procname = "rdma_stat_sq_poll",
107089 .data = &rdma_stat_sq_poll,
107090 - .maxlen = sizeof(atomic_t),
107091 + .maxlen = sizeof(atomic_unchecked_t),
107092 .mode = 0644,
107093 .proc_handler = read_reset_stat,
107094 },
107095 {
107096 .procname = "rdma_stat_sq_prod",
107097 .data = &rdma_stat_sq_prod,
107098 - .maxlen = sizeof(atomic_t),
107099 + .maxlen = sizeof(atomic_unchecked_t),
107100 .mode = 0644,
107101 .proc_handler = read_reset_stat,
107102 },
107103 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107104 index e011027..9d3c4e1 100644
107105 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107106 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107107 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
107108 *page_no = pg_no;
107109 *page_offset = pg_off;
107110 ret = read;
107111 - atomic_inc(&rdma_stat_read);
107112 + atomic_inc_unchecked(&rdma_stat_read);
107113 return ret;
107114 err:
107115 svc_rdma_unmap_dma(ctxt);
107116 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
107117 *page_no = pg_no;
107118 *page_offset = pg_off;
107119 ret = read;
107120 - atomic_inc(&rdma_stat_read);
107121 + atomic_inc_unchecked(&rdma_stat_read);
107122 return ret;
107123 err:
107124 svc_rdma_unmap_dma(ctxt);
107125 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107126 dto_q);
107127 list_del_init(&ctxt->dto_q);
107128 } else {
107129 - atomic_inc(&rdma_stat_rq_starve);
107130 + atomic_inc_unchecked(&rdma_stat_rq_starve);
107131 clear_bit(XPT_DATA, &xprt->xpt_flags);
107132 ctxt = NULL;
107133 }
107134 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107135 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
107136 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
107137 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
107138 - atomic_inc(&rdma_stat_recv);
107139 + atomic_inc_unchecked(&rdma_stat_recv);
107140
107141 /* Build up the XDR from the receive buffers. */
107142 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
107143 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107144 index 9f1b506..2e0b321 100644
107145 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107146 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107147 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
107148 write_wr.wr.rdma.remote_addr = to;
107149
107150 /* Post It */
107151 - atomic_inc(&rdma_stat_write);
107152 + atomic_inc_unchecked(&rdma_stat_write);
107153 if (svc_rdma_send(xprt, &write_wr))
107154 goto err;
107155 return write_len - bc;
107156 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107157 index 374feb4..46487d5 100644
107158 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
107159 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107160 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107161 return;
107162
107163 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
107164 - atomic_inc(&rdma_stat_rq_poll);
107165 + atomic_inc_unchecked(&rdma_stat_rq_poll);
107166
107167 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
107168 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
107169 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107170 }
107171
107172 if (ctxt)
107173 - atomic_inc(&rdma_stat_rq_prod);
107174 + atomic_inc_unchecked(&rdma_stat_rq_prod);
107175
107176 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
107177 /*
107178 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107179 return;
107180
107181 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
107182 - atomic_inc(&rdma_stat_sq_poll);
107183 + atomic_inc_unchecked(&rdma_stat_sq_poll);
107184 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
107185 int i;
107186
107187 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107188 }
107189
107190 if (ctxt)
107191 - atomic_inc(&rdma_stat_sq_prod);
107192 + atomic_inc_unchecked(&rdma_stat_sq_prod);
107193 }
107194
107195 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
107196 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
107197 spin_lock_bh(&xprt->sc_lock);
107198 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
107199 spin_unlock_bh(&xprt->sc_lock);
107200 - atomic_inc(&rdma_stat_sq_starve);
107201 + atomic_inc_unchecked(&rdma_stat_sq_starve);
107202
107203 /* See if we can opportunistically reap SQ WR to make room */
107204 sq_cq_reap(xprt);
107205 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
107206 index e7000be..e3b0ba7 100644
107207 --- a/net/sysctl_net.c
107208 +++ b/net/sysctl_net.c
107209 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
107210 kgid_t root_gid = make_kgid(net->user_ns, 0);
107211
107212 /* Allow network administrator to have same access as root. */
107213 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
107214 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
107215 uid_eq(root_uid, current_euid())) {
107216 int mode = (table->mode >> 6) & 7;
107217 return (mode << 6) | (mode << 3) | mode;
107218 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
107219 index 6424372..afd36e9 100644
107220 --- a/net/tipc/subscr.c
107221 +++ b/net/tipc/subscr.c
107222 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
107223 struct tipc_subscriber *subscriber = sub->subscriber;
107224 struct kvec msg_sect;
107225
107226 - msg_sect.iov_base = (void *)&sub->evt;
107227 + msg_sect.iov_base = &sub->evt;
107228 msg_sect.iov_len = sizeof(struct tipc_event);
107229 sub->evt.event = htohl(event, sub->swap);
107230 sub->evt.found_lower = htohl(found_lower, sub->swap);
107231 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
107232 index e968843..bc95776 100644
107233 --- a/net/unix/af_unix.c
107234 +++ b/net/unix/af_unix.c
107235 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
107236 err = -ECONNREFUSED;
107237 if (!S_ISSOCK(inode->i_mode))
107238 goto put_fail;
107239 +
107240 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
107241 + err = -EACCES;
107242 + goto put_fail;
107243 + }
107244 +
107245 u = unix_find_socket_byinode(inode);
107246 if (!u)
107247 goto put_fail;
107248 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
107249 if (u) {
107250 struct dentry *dentry;
107251 dentry = unix_sk(u)->path.dentry;
107252 +
107253 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107254 + err = -EPERM;
107255 + sock_put(u);
107256 + goto fail;
107257 + }
107258 +
107259 if (dentry)
107260 touch_atime(&unix_sk(u)->path);
107261 } else
107262 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107263 */
107264 err = security_path_mknod(&path, dentry, mode, 0);
107265 if (!err) {
107266 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107267 + err = -EACCES;
107268 + goto out;
107269 + }
107270 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107271 if (!err) {
107272 res->mnt = mntget(path.mnt);
107273 res->dentry = dget(dentry);
107274 + gr_handle_create(dentry, path.mnt);
107275 }
107276 }
107277 +out:
107278 done_path_create(&path, dentry);
107279 return err;
107280 }
107281 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107282 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107283 "Inode Path\n");
107284 else {
107285 - struct sock *s = v;
107286 + struct sock *s = v, *peer;
107287 struct unix_sock *u = unix_sk(s);
107288 unix_state_lock(s);
107289 + peer = unix_peer(s);
107290 + unix_state_unlock(s);
107291 +
107292 + unix_state_double_lock(s, peer);
107293
107294 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107295 s,
107296 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107297 }
107298 for ( ; i < len; i++)
107299 seq_putc(seq, u->addr->name->sun_path[i]);
107300 - }
107301 - unix_state_unlock(s);
107302 + } else if (peer)
107303 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107304 +
107305 + unix_state_double_unlock(s, peer);
107306 seq_putc(seq, '\n');
107307 }
107308
107309 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107310 index b3d5150..ff3a837 100644
107311 --- a/net/unix/sysctl_net_unix.c
107312 +++ b/net/unix/sysctl_net_unix.c
107313 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107314
107315 int __net_init unix_sysctl_register(struct net *net)
107316 {
107317 - struct ctl_table *table;
107318 + ctl_table_no_const *table;
107319
107320 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107321 if (table == NULL)
107322 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107323 index 9b7f207..2596621 100644
107324 --- a/net/vmw_vsock/vmci_transport_notify.c
107325 +++ b/net/vmw_vsock/vmci_transport_notify.c
107326 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107327
107328 /* Socket control packet based operations. */
107329 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107330 - vmci_transport_notify_pkt_socket_init,
107331 - vmci_transport_notify_pkt_socket_destruct,
107332 - vmci_transport_notify_pkt_poll_in,
107333 - vmci_transport_notify_pkt_poll_out,
107334 - vmci_transport_notify_pkt_handle_pkt,
107335 - vmci_transport_notify_pkt_recv_init,
107336 - vmci_transport_notify_pkt_recv_pre_block,
107337 - vmci_transport_notify_pkt_recv_pre_dequeue,
107338 - vmci_transport_notify_pkt_recv_post_dequeue,
107339 - vmci_transport_notify_pkt_send_init,
107340 - vmci_transport_notify_pkt_send_pre_block,
107341 - vmci_transport_notify_pkt_send_pre_enqueue,
107342 - vmci_transport_notify_pkt_send_post_enqueue,
107343 - vmci_transport_notify_pkt_process_request,
107344 - vmci_transport_notify_pkt_process_negotiate,
107345 + .socket_init = vmci_transport_notify_pkt_socket_init,
107346 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107347 + .poll_in = vmci_transport_notify_pkt_poll_in,
107348 + .poll_out = vmci_transport_notify_pkt_poll_out,
107349 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107350 + .recv_init = vmci_transport_notify_pkt_recv_init,
107351 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107352 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107353 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107354 + .send_init = vmci_transport_notify_pkt_send_init,
107355 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107356 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107357 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107358 + .process_request = vmci_transport_notify_pkt_process_request,
107359 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107360 };
107361 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107362 index dc9c792..3089de0 100644
107363 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107364 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107365 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107366
107367 /* Socket always on control packet based operations. */
107368 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107369 - vmci_transport_notify_pkt_socket_init,
107370 - vmci_transport_notify_pkt_socket_destruct,
107371 - vmci_transport_notify_pkt_poll_in,
107372 - vmci_transport_notify_pkt_poll_out,
107373 - vmci_transport_notify_pkt_handle_pkt,
107374 - vmci_transport_notify_pkt_recv_init,
107375 - vmci_transport_notify_pkt_recv_pre_block,
107376 - vmci_transport_notify_pkt_recv_pre_dequeue,
107377 - vmci_transport_notify_pkt_recv_post_dequeue,
107378 - vmci_transport_notify_pkt_send_init,
107379 - vmci_transport_notify_pkt_send_pre_block,
107380 - vmci_transport_notify_pkt_send_pre_enqueue,
107381 - vmci_transport_notify_pkt_send_post_enqueue,
107382 - vmci_transport_notify_pkt_process_request,
107383 - vmci_transport_notify_pkt_process_negotiate,
107384 + .socket_init = vmci_transport_notify_pkt_socket_init,
107385 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107386 + .poll_in = vmci_transport_notify_pkt_poll_in,
107387 + .poll_out = vmci_transport_notify_pkt_poll_out,
107388 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107389 + .recv_init = vmci_transport_notify_pkt_recv_init,
107390 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107391 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107392 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107393 + .send_init = vmci_transport_notify_pkt_send_init,
107394 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107395 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107396 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107397 + .process_request = vmci_transport_notify_pkt_process_request,
107398 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107399 };
107400 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107401 index c8717c1..08539f5 100644
107402 --- a/net/wireless/wext-core.c
107403 +++ b/net/wireless/wext-core.c
107404 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107405 */
107406
107407 /* Support for very large requests */
107408 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107409 - (user_length > descr->max_tokens)) {
107410 + if (user_length > descr->max_tokens) {
107411 /* Allow userspace to GET more than max so
107412 * we can support any size GET requests.
107413 * There is still a limit : -ENOMEM.
107414 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107415 }
107416 }
107417
107418 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107419 - /*
107420 - * If this is a GET, but not NOMAX, it means that the extra
107421 - * data is not bounded by userspace, but by max_tokens. Thus
107422 - * set the length to max_tokens. This matches the extra data
107423 - * allocation.
107424 - * The driver should fill it with the number of tokens it
107425 - * provided, and it may check iwp->length rather than having
107426 - * knowledge of max_tokens. If the driver doesn't change the
107427 - * iwp->length, this ioctl just copies back max_token tokens
107428 - * filled with zeroes. Hopefully the driver isn't claiming
107429 - * them to be valid data.
107430 - */
107431 - iwp->length = descr->max_tokens;
107432 - }
107433 -
107434 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107435
107436 iwp->length += essid_compat;
107437 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107438 index 4323952..a06dfe1 100644
107439 --- a/net/x25/sysctl_net_x25.c
107440 +++ b/net/x25/sysctl_net_x25.c
107441 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107442 .mode = 0644,
107443 .proc_handler = proc_dointvec,
107444 },
107445 - { 0, },
107446 + { },
107447 };
107448
107449 void __init x25_register_sysctl(void)
107450 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107451 index 0917f04..f4e3d8c 100644
107452 --- a/net/x25/x25_proc.c
107453 +++ b/net/x25/x25_proc.c
107454 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107455
107456 int __init x25_proc_init(void)
107457 {
107458 - if (!proc_mkdir("x25", init_net.proc_net))
107459 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107460 return -ENOMEM;
107461
107462 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107463 diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
107464 index c51e8f7b..e44f360 100644
107465 --- a/net/xfrm/xfrm_output.c
107466 +++ b/net/xfrm/xfrm_output.c
107467 @@ -157,6 +157,8 @@ static int xfrm_output_gso(struct sk_buff *skb)
107468 kfree_skb(skb);
107469 if (IS_ERR(segs))
107470 return PTR_ERR(segs);
107471 + if (segs == NULL)
107472 + return -EINVAL;
107473
107474 do {
107475 struct sk_buff *nskb = segs->next;
107476 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107477 index fdde51f..4839450 100644
107478 --- a/net/xfrm/xfrm_policy.c
107479 +++ b/net/xfrm/xfrm_policy.c
107480 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107481 {
107482 policy->walk.dead = 1;
107483
107484 - atomic_inc(&policy->genid);
107485 + atomic_inc_unchecked(&policy->genid);
107486
107487 if (del_timer(&policy->polq.hold_timer))
107488 xfrm_pol_put(policy);
107489 @@ -664,7 +664,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107490 hlist_add_head(&policy->bydst, chain);
107491 xfrm_pol_hold(policy);
107492 net->xfrm.policy_count[dir]++;
107493 - atomic_inc(&net->xfrm.flow_cache_genid);
107494 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107495
107496 /* After previous checking, family can either be AF_INET or AF_INET6 */
107497 if (policy->family == AF_INET)
107498 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107499
107500 xdst->num_pols = num_pols;
107501 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107502 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107503 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107504
107505 return xdst;
107506 }
107507 @@ -2570,10 +2570,11 @@ void xfrm_garbage_collect(struct net *net)
107508 }
107509 EXPORT_SYMBOL(xfrm_garbage_collect);
107510
107511 -static void xfrm_garbage_collect_deferred(struct net *net)
107512 +void xfrm_garbage_collect_deferred(struct net *net)
107513 {
107514 flow_cache_flush_deferred(net);
107515 }
107516 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107517
107518 static void xfrm_init_pmtu(struct dst_entry *dst)
107519 {
107520 @@ -2623,7 +2624,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107521 if (xdst->xfrm_genid != dst->xfrm->genid)
107522 return 0;
107523 if (xdst->num_pols > 0 &&
107524 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107525 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107526 return 0;
107527
107528 mtu = dst_mtu(dst->child);
107529 @@ -2711,8 +2712,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107530 dst_ops->link_failure = xfrm_link_failure;
107531 if (likely(dst_ops->neigh_lookup == NULL))
107532 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107533 - if (likely(afinfo->garbage_collect == NULL))
107534 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107535 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107536 }
107537 spin_unlock(&xfrm_policy_afinfo_lock);
107538 @@ -2766,7 +2765,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107539 dst_ops->check = NULL;
107540 dst_ops->negative_advice = NULL;
107541 dst_ops->link_failure = NULL;
107542 - afinfo->garbage_collect = NULL;
107543 }
107544 return err;
107545 }
107546 @@ -3151,7 +3149,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107547 sizeof(pol->xfrm_vec[i].saddr));
107548 pol->xfrm_vec[i].encap_family = mp->new_family;
107549 /* flush bundles */
107550 - atomic_inc(&pol->genid);
107551 + atomic_inc_unchecked(&pol->genid);
107552 }
107553 }
107554
107555 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107556 index 0ab5413..73dd2cf 100644
107557 --- a/net/xfrm/xfrm_state.c
107558 +++ b/net/xfrm/xfrm_state.c
107559 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107560
107561 if (unlikely(afinfo == NULL))
107562 return -EAFNOSUPPORT;
107563 - typemap = afinfo->type_map;
107564 + typemap = (const struct xfrm_type **)afinfo->type_map;
107565 spin_lock_bh(&xfrm_type_lock);
107566
107567 - if (likely(typemap[type->proto] == NULL))
107568 + if (likely(typemap[type->proto] == NULL)) {
107569 + pax_open_kernel();
107570 typemap[type->proto] = type;
107571 - else
107572 + pax_close_kernel();
107573 + } else
107574 err = -EEXIST;
107575 spin_unlock_bh(&xfrm_type_lock);
107576 xfrm_state_put_afinfo(afinfo);
107577 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107578
107579 if (unlikely(afinfo == NULL))
107580 return -EAFNOSUPPORT;
107581 - typemap = afinfo->type_map;
107582 + typemap = (const struct xfrm_type **)afinfo->type_map;
107583 spin_lock_bh(&xfrm_type_lock);
107584
107585 if (unlikely(typemap[type->proto] != type))
107586 err = -ENOENT;
107587 - else
107588 + else {
107589 + pax_open_kernel();
107590 typemap[type->proto] = NULL;
107591 + pax_close_kernel();
107592 + }
107593 spin_unlock_bh(&xfrm_type_lock);
107594 xfrm_state_put_afinfo(afinfo);
107595 return err;
107596 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107597 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107598 {
107599 struct xfrm_state_afinfo *afinfo;
107600 - const struct xfrm_type **typemap;
107601 const struct xfrm_type *type;
107602 int modload_attempted = 0;
107603
107604 @@ -218,9 +222,8 @@ retry:
107605 afinfo = xfrm_state_get_afinfo(family);
107606 if (unlikely(afinfo == NULL))
107607 return NULL;
107608 - typemap = afinfo->type_map;
107609
107610 - type = typemap[proto];
107611 + type = afinfo->type_map[proto];
107612 if (unlikely(type && !try_module_get(type->owner)))
107613 type = NULL;
107614 if (!type && !modload_attempted) {
107615 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107616 return -EAFNOSUPPORT;
107617
107618 err = -EEXIST;
107619 - modemap = afinfo->mode_map;
107620 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107621 spin_lock_bh(&xfrm_mode_lock);
107622 if (modemap[mode->encap])
107623 goto out;
107624 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107625 if (!try_module_get(afinfo->owner))
107626 goto out;
107627
107628 - mode->afinfo = afinfo;
107629 + pax_open_kernel();
107630 + *(const void **)&mode->afinfo = afinfo;
107631 modemap[mode->encap] = mode;
107632 + pax_close_kernel();
107633 err = 0;
107634
107635 out:
107636 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107637 return -EAFNOSUPPORT;
107638
107639 err = -ENOENT;
107640 - modemap = afinfo->mode_map;
107641 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107642 spin_lock_bh(&xfrm_mode_lock);
107643 if (likely(modemap[mode->encap] == mode)) {
107644 + pax_open_kernel();
107645 modemap[mode->encap] = NULL;
107646 + pax_close_kernel();
107647 module_put(mode->afinfo->owner);
107648 err = 0;
107649 }
107650 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107651 u32 xfrm_get_acqseq(void)
107652 {
107653 u32 res;
107654 - static atomic_t acqseq;
107655 + static atomic_unchecked_t acqseq;
107656
107657 do {
107658 - res = atomic_inc_return(&acqseq);
107659 + res = atomic_inc_return_unchecked(&acqseq);
107660 } while (!res);
107661
107662 return res;
107663 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107664 index 05a6e3d..6716ec9 100644
107665 --- a/net/xfrm/xfrm_sysctl.c
107666 +++ b/net/xfrm/xfrm_sysctl.c
107667 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107668
107669 int __net_init xfrm_sysctl_init(struct net *net)
107670 {
107671 - struct ctl_table *table;
107672 + ctl_table_no_const *table;
107673
107674 __xfrm_sysctl_init(net);
107675
107676 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107677 index bf3e677..c7d426e 100644
107678 --- a/scripts/Makefile.build
107679 +++ b/scripts/Makefile.build
107680 @@ -60,7 +60,7 @@ endif
107681 endif
107682
107683 # Do not include host rules unless needed
107684 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107685 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107686 include scripts/Makefile.host
107687 endif
107688
107689 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107690 index a651cee..6b3b9a3 100644
107691 --- a/scripts/Makefile.clean
107692 +++ b/scripts/Makefile.clean
107693 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107694 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107695 $(always) $(targets) $(clean-files) \
107696 $(host-progs) \
107697 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107698 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107699 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107700
107701 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107702
107703 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107704 index ab5980f..85fd3e1 100644
107705 --- a/scripts/Makefile.host
107706 +++ b/scripts/Makefile.host
107707 @@ -20,7 +20,19 @@
107708 # Will compile qconf as a C++ program, and menu as a C program.
107709 # They are linked as C++ code to the executable qconf
107710
107711 +# hostprogs-y := conf
107712 +# conf-objs := conf.o libkconfig.so
107713 +# libkconfig-objs := expr.o type.o
107714 +# Will create a shared library named libkconfig.so that consists of
107715 +# expr.o and type.o (they are both compiled as C code and the object files
107716 +# are made as position independent code).
107717 +# conf.c is compiled as a C program, and conf.o is linked together with
107718 +# libkconfig.so as the executable conf.
107719 +# Note: Shared libraries consisting of C++ files are not supported
107720 +
107721 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107722 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107723 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107724
107725 # C code
107726 # Executables compiled from a single .c file
107727 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107728 # C++ Object (.o) files compiled from .cc files
107729 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107730
107731 +# Shared libaries (only .c supported)
107732 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107733 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107734 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107735 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107736 +# Remove .so files from "xxx-objs"
107737 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107738 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107739 +
107740 +# Object (.o) files used by the shared libaries
107741 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107742 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107743 +
107744 # output directory for programs/.o files
107745 # hostprogs-y := tools/build may have been specified.
107746 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107747 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107748 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107749 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107750 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107751 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107752 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107753 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107754 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107755 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107756
107757 obj-dirs += $(host-objdirs)
107758 @@ -96,7 +125,7 @@ quiet_cmd_host-cmulti = HOSTLD $@
107759 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
107760 $(addprefix $(obj)/,$($(@F)-objs)) \
107761 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107762 -$(host-cmulti): $(obj)/%: $(host-cobjs) FORCE
107763 +$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE
107764 $(call if_changed,host-cmulti)
107765
107766 # Create .o file from a single .c file
107767 @@ -113,7 +142,7 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
107768 $(foreach o,objs cxxobjs,\
107769 $(addprefix $(obj)/,$($(@F)-$(o)))) \
107770 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107771 -$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) FORCE
107772 +$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
107773 $(call if_changed,host-cxxmulti)
107774
107775 # Create .o file from a single .cc (C++) file
107776 @@ -122,5 +151,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107777 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107778 $(call if_changed_dep,host-cxxobjs)
107779
107780 +# Compile .c file, create position independent .o file
107781 +# host-cshobjs -> .o
107782 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107783 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107784 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107785 + $(call if_changed_dep,host-cshobjs)
107786 +
107787 +# Compile .c file, create position independent .o file
107788 +# host-cxxshobjs -> .o
107789 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107790 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107791 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107792 + $(call if_changed_dep,host-cxxshobjs)
107793 +
107794 +# Link a shared library, based on position independent .o files
107795 +# *.o -> .so shared library (host-cshlib)
107796 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107797 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107798 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107799 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107800 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107801 + $(call if_changed,host-cshlib)
107802 +
107803 +# Link a shared library, based on position independent .o files
107804 +# *.o -> .so shared library (host-cxxshlib)
107805 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107806 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107807 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107808 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107809 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107810 + $(call if_changed,host-cxxshlib)
107811 +
107812 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107813 - $(host-cxxmulti) $(host-cxxobjs)
107814 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107815 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107816 index b304068..462d24e 100644
107817 --- a/scripts/basic/fixdep.c
107818 +++ b/scripts/basic/fixdep.c
107819 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107820 /*
107821 * Lookup a value in the configuration string.
107822 */
107823 -static int is_defined_config(const char *name, int len, unsigned int hash)
107824 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107825 {
107826 struct item *aux;
107827
107828 @@ -211,10 +211,10 @@ static void clear_config(void)
107829 /*
107830 * Record the use of a CONFIG_* word.
107831 */
107832 -static void use_config(const char *m, int slen)
107833 +static void use_config(const char *m, unsigned int slen)
107834 {
107835 unsigned int hash = strhash(m, slen);
107836 - int c, i;
107837 + unsigned int c, i;
107838
107839 if (is_defined_config(m, slen, hash))
107840 return;
107841 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107842
107843 static void parse_config_file(const char *map, size_t len)
107844 {
107845 - const int *end = (const int *) (map + len);
107846 + const unsigned int *end = (const unsigned int *) (map + len);
107847 /* start at +1, so that p can never be < map */
107848 - const int *m = (const int *) map + 1;
107849 + const unsigned int *m = (const unsigned int *) map + 1;
107850 const char *p, *q;
107851
107852 for (; m < end; m++) {
107853 @@ -435,7 +435,7 @@ static void print_deps(void)
107854 static void traps(void)
107855 {
107856 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107857 - int *p = (int *)test;
107858 + unsigned int *p = (unsigned int *)test;
107859
107860 if (*p != INT_CONF) {
107861 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107862 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107863 new file mode 100644
107864 index 0000000..42018ed
107865 --- /dev/null
107866 +++ b/scripts/gcc-plugin.sh
107867 @@ -0,0 +1,51 @@
107868 +#!/bin/sh
107869 +srctree=$(dirname "$0")
107870 +gccplugins_dir=$($3 -print-file-name=plugin)
107871 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107872 +#include "gcc-common.h"
107873 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107874 +#warning $2 CXX
107875 +#else
107876 +#warning $1 CC
107877 +#endif
107878 +EOF
107879 +)
107880 +
107881 +if [ $? -ne 0 ]
107882 +then
107883 + exit 1
107884 +fi
107885 +
107886 +case "$plugincc" in
107887 + *"$1 CC"*)
107888 + echo "$1"
107889 + exit 0
107890 + ;;
107891 +
107892 + *"$2 CXX"*)
107893 + # the c++ compiler needs another test, see below
107894 + ;;
107895 +
107896 + *)
107897 + exit 1
107898 + ;;
107899 +esac
107900 +
107901 +# we need a c++ compiler that supports the designated initializer GNU extension
107902 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107903 +#include "gcc-common.h"
107904 +class test {
107905 +public:
107906 + int test;
107907 +} test = {
107908 + .test = 1
107909 +};
107910 +EOF
107911 +)
107912 +
107913 +if [ $? -eq 0 ]
107914 +then
107915 + echo "$2"
107916 + exit 0
107917 +fi
107918 +exit 1
107919 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107920 index 5de5660..d3deb89 100644
107921 --- a/scripts/headers_install.sh
107922 +++ b/scripts/headers_install.sh
107923 @@ -32,6 +32,7 @@ do
107924 FILE="$(basename "$i")"
107925 sed -r \
107926 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107927 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107928 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107929 -e 's@^#include <linux/compiler.h>@@' \
107930 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107931 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107932 index 86a4fe7..99e91f9 100644
107933 --- a/scripts/link-vmlinux.sh
107934 +++ b/scripts/link-vmlinux.sh
107935 @@ -166,7 +166,7 @@ else
107936 fi;
107937
107938 # final build of init/
107939 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107940 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107941
107942 kallsymso=""
107943 kallsyms_vmlinux=""
107944 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107945 index e614ef6..d9d2b01 100644
107946 --- a/scripts/mod/file2alias.c
107947 +++ b/scripts/mod/file2alias.c
107948 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107949 unsigned long size, unsigned long id_size,
107950 void *symval)
107951 {
107952 - int i;
107953 + unsigned int i;
107954
107955 if (size % id_size || size < id_size) {
107956 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107957 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107958 /* USB is special because the bcdDevice can be matched against a numeric range */
107959 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107960 static void do_usb_entry(void *symval,
107961 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107962 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107963 unsigned char range_lo, unsigned char range_hi,
107964 unsigned char max, struct module *mod)
107965 {
107966 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107967 {
107968 unsigned int devlo, devhi;
107969 unsigned char chi, clo, max;
107970 - int ndigits;
107971 + unsigned int ndigits;
107972
107973 DEF_FIELD(symval, usb_device_id, match_flags);
107974 DEF_FIELD(symval, usb_device_id, idVendor);
107975 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107976 for (i = 0; i < count; i++) {
107977 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107978 char acpi_id[sizeof(*id)];
107979 - int j;
107980 + unsigned int j;
107981
107982 buf_printf(&mod->dev_table_buf,
107983 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107984 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107985
107986 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107987 const char *id = (char *)(*devs)[j].id;
107988 - int i2, j2;
107989 + unsigned int i2, j2;
107990 int dup = 0;
107991
107992 if (!id[0])
107993 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107994 /* add an individual alias for every device entry */
107995 if (!dup) {
107996 char acpi_id[PNP_ID_LEN];
107997 - int k;
107998 + unsigned int k;
107999
108000 buf_printf(&mod->dev_table_buf,
108001 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
108002 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
108003 static int do_dmi_entry(const char *filename, void *symval,
108004 char *alias)
108005 {
108006 - int i, j;
108007 + unsigned int i, j;
108008 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
108009 sprintf(alias, "dmi*");
108010
108011 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
108012 index 091d905..77b88c7 100644
108013 --- a/scripts/mod/modpost.c
108014 +++ b/scripts/mod/modpost.c
108015 @@ -920,6 +920,7 @@ enum mismatch {
108016 ANY_INIT_TO_ANY_EXIT,
108017 ANY_EXIT_TO_ANY_INIT,
108018 EXPORT_TO_INIT_EXIT,
108019 + DATA_TO_TEXT
108020 };
108021
108022 struct sectioncheck {
108023 @@ -1006,6 +1007,12 @@ const struct sectioncheck sectioncheck[] = {
108024 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
108025 .mismatch = EXPORT_TO_INIT_EXIT,
108026 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
108027 +},
108028 +/* Do not reference code from writable data */
108029 +{
108030 + .fromsec = { DATA_SECTIONS, NULL },
108031 + .tosec = { TEXT_SECTIONS, NULL },
108032 + .mismatch = DATA_TO_TEXT
108033 }
108034 };
108035
108036 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
108037 continue;
108038 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
108039 continue;
108040 - if (sym->st_value == addr)
108041 - return sym;
108042 /* Find a symbol nearby - addr are maybe negative */
108043 d = sym->st_value - addr;
108044 + if (d == 0)
108045 + return sym;
108046 if (d < 0)
108047 d = addr - sym->st_value;
108048 if (d < distance) {
108049 @@ -1407,6 +1414,14 @@ static void report_sec_mismatch(const char *modname,
108050 tosym, prl_to, prl_to, tosym);
108051 free(prl_to);
108052 break;
108053 + case DATA_TO_TEXT:
108054 +#if 0
108055 + fprintf(stderr,
108056 + "The %s %s:%s references\n"
108057 + "the %s %s:%s%s\n",
108058 + from, fromsec, fromsym, to, tosec, tosym, to_p);
108059 +#endif
108060 + break;
108061 }
108062 fprintf(stderr, "\n");
108063 }
108064 @@ -1658,7 +1673,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
108065 static void check_sec_ref(struct module *mod, const char *modname,
108066 struct elf_info *elf)
108067 {
108068 - int i;
108069 + unsigned int i;
108070 Elf_Shdr *sechdrs = elf->sechdrs;
108071
108072 /* Walk through all sections */
108073 @@ -1789,7 +1804,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
108074 va_end(ap);
108075 }
108076
108077 -void buf_write(struct buffer *buf, const char *s, int len)
108078 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
108079 {
108080 if (buf->size - buf->pos < len) {
108081 buf->size += len + SZ;
108082 @@ -2008,7 +2023,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
108083 if (fstat(fileno(file), &st) < 0)
108084 goto close_write;
108085
108086 - if (st.st_size != b->pos)
108087 + if (st.st_size != (off_t)b->pos)
108088 goto close_write;
108089
108090 tmp = NOFAIL(malloc(b->pos));
108091 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
108092 index 168b43d..77914bf 100644
108093 --- a/scripts/mod/modpost.h
108094 +++ b/scripts/mod/modpost.h
108095 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
108096
108097 struct buffer {
108098 char *p;
108099 - int pos;
108100 - int size;
108101 + unsigned int pos;
108102 + unsigned int size;
108103 };
108104
108105 void __attribute__((format(printf, 2, 3)))
108106 buf_printf(struct buffer *buf, const char *fmt, ...);
108107
108108 void
108109 -buf_write(struct buffer *buf, const char *s, int len);
108110 +buf_write(struct buffer *buf, const char *s, unsigned int len);
108111
108112 struct module {
108113 struct module *next;
108114 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
108115 index 944418d..15291e4 100644
108116 --- a/scripts/mod/sumversion.c
108117 +++ b/scripts/mod/sumversion.c
108118 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
108119 goto out;
108120 }
108121
108122 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
108123 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
108124 warn("writing sum in %s failed: %s\n",
108125 filename, strerror(errno));
108126 goto out;
108127 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
108128 index 0865b3e..7235dd4 100644
108129 --- a/scripts/module-common.lds
108130 +++ b/scripts/module-common.lds
108131 @@ -6,6 +6,10 @@
108132 SECTIONS {
108133 /DISCARD/ : { *(.discard) }
108134
108135 + .rodata : {
108136 + *(.rodata) *(.rodata.*)
108137 + *(.data..read_only)
108138 + }
108139 __ksymtab : { *(SORT(___ksymtab+*)) }
108140 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
108141 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
108142 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
108143 index 99ca6e7..3a1a1a1 100644
108144 --- a/scripts/package/Makefile
108145 +++ b/scripts/package/Makefile
108146 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
108147 ln -sf $(srctree) $(KERNELPATH)
108148 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
108149 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
108150 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108151 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108152 rm $(KERNELPATH)
108153 rm -f $(objtree)/.scmversion
108154 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
108155 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
108156 index 7c0e6e4..bf2c90e 100644
108157 --- a/scripts/package/builddeb
108158 +++ b/scripts/package/builddeb
108159 @@ -293,6 +293,7 @@ fi
108160 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
108161 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
108162 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
108163 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
108164 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
108165 mkdir -p "$destdir"
108166 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
108167 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
108168 index 1395760..6ceef68 100755
108169 --- a/scripts/package/mkspec
108170 +++ b/scripts/package/mkspec
108171 @@ -121,14 +121,27 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
108172 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
108173 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\""
108174 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
108175 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
108176 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
108177 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
108178
108179 echo ""
108180 echo "%clean"
108181 echo 'rm -rf $RPM_BUILD_ROOT'
108182 echo ""
108183 +echo "%pre"
108184 +echo 'chmod -f 0500 /boot'
108185 +echo 'if [ -d /lib/modules ]; then'
108186 +echo 'chmod -f 0500 /lib/modules'
108187 +echo 'fi'
108188 +echo 'if [ -d /lib32/modules ]; then'
108189 +echo 'chmod -f 0500 /lib32/modules'
108190 +echo 'fi'
108191 +echo 'if [ -d /lib64/modules ]; then'
108192 +echo 'chmod -f 0500 /lib64/modules'
108193 +echo 'fi'
108194 +echo ""
108195 +echo "%post devel"
108196 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
108197 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
108198 +echo ""
108199 echo "%post"
108200 echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
108201 echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
108202 @@ -139,11 +152,11 @@ echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm
108203 echo "fi"
108204 echo ""
108205 echo "%files"
108206 -echo '%defattr (-, root, root)'
108207 +echo '%defattr (400, root, root, 500)'
108208 echo "%dir /lib/modules"
108209 -echo "/lib/modules/$KERNELRELEASE"
108210 echo "%exclude /lib/modules/$KERNELRELEASE/build"
108211 echo "%exclude /lib/modules/$KERNELRELEASE/source"
108212 +echo "/lib/modules/$KERNELRELEASE"
108213 echo "/lib/firmware/$KERNELRELEASE"
108214 echo "/boot/*"
108215 echo ""
108216 @@ -152,8 +165,7 @@ echo '%defattr (-, root, root)'
108217 echo "/usr/include"
108218 echo ""
108219 echo "%files devel"
108220 -echo '%defattr (-, root, root)'
108221 +echo '%defattr (400, root, root, 500)'
108222 +echo "%dir /lib/modules/$KERNELRELEASE"
108223 echo "/usr/src/kernels/$KERNELRELEASE"
108224 -echo "/lib/modules/$KERNELRELEASE/build"
108225 -echo "/lib/modules/$KERNELRELEASE/source"
108226 echo ""
108227 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
108228 index 4718d78..9220d58 100644
108229 --- a/scripts/pnmtologo.c
108230 +++ b/scripts/pnmtologo.c
108231 @@ -244,14 +244,14 @@ static void write_header(void)
108232 fprintf(out, " * Linux logo %s\n", logoname);
108233 fputs(" */\n\n", out);
108234 fputs("#include <linux/linux_logo.h>\n\n", out);
108235 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
108236 + fprintf(out, "static unsigned char %s_data[] = {\n",
108237 logoname);
108238 }
108239
108240 static void write_footer(void)
108241 {
108242 fputs("\n};\n\n", out);
108243 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
108244 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
108245 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
108246 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
108247 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
108248 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
108249 fputs("\n};\n\n", out);
108250
108251 /* write logo clut */
108252 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
108253 + fprintf(out, "static unsigned char %s_clut[] = {\n",
108254 logoname);
108255 write_hex_cnt = 0;
108256 for (i = 0; i < logo_clutsize; i++) {
108257 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
108258 index 8fac3fd..32ff38d 100644
108259 --- a/scripts/sortextable.h
108260 +++ b/scripts/sortextable.h
108261 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
108262 const char *secstrtab;
108263 const char *strtab;
108264 char *extab_image;
108265 - int extab_index = 0;
108266 - int i;
108267 - int idx;
108268 + unsigned int extab_index = 0;
108269 + unsigned int i;
108270 + unsigned int idx;
108271 unsigned int num_sections;
108272 unsigned int secindex_strings;
108273
108274 diff --git a/scripts/tags.sh b/scripts/tags.sh
108275 index 293828b..9fbe696 100755
108276 --- a/scripts/tags.sh
108277 +++ b/scripts/tags.sh
108278 @@ -26,7 +26,7 @@ else
108279 fi
108280
108281 # ignore userspace tools
108282 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
108283 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
108284
108285 # Find all available archs
108286 find_all_archs()
108287 diff --git a/security/Kconfig b/security/Kconfig
108288 index beb86b5..1a953b1 100644
108289 --- a/security/Kconfig
108290 +++ b/security/Kconfig
108291 @@ -4,6 +4,974 @@
108292
108293 menu "Security options"
108294
108295 +menu "Grsecurity"
108296 +
108297 + config ARCH_TRACK_EXEC_LIMIT
108298 + bool
108299 +
108300 + config PAX_KERNEXEC_PLUGIN
108301 + bool
108302 +
108303 + config PAX_PER_CPU_PGD
108304 + bool
108305 +
108306 + config TASK_SIZE_MAX_SHIFT
108307 + int
108308 + depends on X86_64
108309 + default 47 if !PAX_PER_CPU_PGD
108310 + default 42 if PAX_PER_CPU_PGD
108311 +
108312 + config PAX_ENABLE_PAE
108313 + bool
108314 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
108315 +
108316 + config PAX_USERCOPY_SLABS
108317 + bool
108318 +
108319 +config GRKERNSEC
108320 + bool "Grsecurity"
108321 + select CRYPTO
108322 + select CRYPTO_SHA256
108323 + select PROC_FS
108324 + select STOP_MACHINE
108325 + select TTY
108326 + select DEBUG_KERNEL
108327 + select DEBUG_LIST
108328 + help
108329 + If you say Y here, you will be able to configure many features
108330 + that will enhance the security of your system. It is highly
108331 + recommended that you say Y here and read through the help
108332 + for each option so that you fully understand the features and
108333 + can evaluate their usefulness for your machine.
108334 +
108335 +choice
108336 + prompt "Configuration Method"
108337 + depends on GRKERNSEC
108338 + default GRKERNSEC_CONFIG_CUSTOM
108339 + help
108340 +
108341 +config GRKERNSEC_CONFIG_AUTO
108342 + bool "Automatic"
108343 + help
108344 + If you choose this configuration method, you'll be able to answer a small
108345 + number of simple questions about how you plan to use this kernel.
108346 + The settings of grsecurity and PaX will be automatically configured for
108347 + the highest commonly-used settings within the provided constraints.
108348 +
108349 + If you require additional configuration, custom changes can still be made
108350 + from the "custom configuration" menu.
108351 +
108352 +config GRKERNSEC_CONFIG_CUSTOM
108353 + bool "Custom"
108354 + help
108355 + If you choose this configuration method, you'll be able to configure all
108356 + grsecurity and PaX settings manually. Via this method, no options are
108357 + automatically enabled.
108358 +
108359 +endchoice
108360 +
108361 +choice
108362 + prompt "Usage Type"
108363 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108364 + default GRKERNSEC_CONFIG_SERVER
108365 + help
108366 +
108367 +config GRKERNSEC_CONFIG_SERVER
108368 + bool "Server"
108369 + help
108370 + Choose this option if you plan to use this kernel on a server.
108371 +
108372 +config GRKERNSEC_CONFIG_DESKTOP
108373 + bool "Desktop"
108374 + help
108375 + Choose this option if you plan to use this kernel on a desktop.
108376 +
108377 +endchoice
108378 +
108379 +choice
108380 + prompt "Virtualization Type"
108381 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108382 + default GRKERNSEC_CONFIG_VIRT_NONE
108383 + help
108384 +
108385 +config GRKERNSEC_CONFIG_VIRT_NONE
108386 + bool "None"
108387 + help
108388 + Choose this option if this kernel will be run on bare metal.
108389 +
108390 +config GRKERNSEC_CONFIG_VIRT_GUEST
108391 + bool "Guest"
108392 + help
108393 + Choose this option if this kernel will be run as a VM guest.
108394 +
108395 +config GRKERNSEC_CONFIG_VIRT_HOST
108396 + bool "Host"
108397 + help
108398 + Choose this option if this kernel will be run as a VM host.
108399 +
108400 +endchoice
108401 +
108402 +choice
108403 + prompt "Virtualization Hardware"
108404 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108405 + help
108406 +
108407 +config GRKERNSEC_CONFIG_VIRT_EPT
108408 + bool "EPT/RVI Processor Support"
108409 + depends on X86
108410 + help
108411 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108412 + hardware virtualization. This allows for additional kernel hardening protections
108413 + to operate without additional performance impact.
108414 +
108415 + To see if your Intel processor supports EPT, see:
108416 + http://ark.intel.com/Products/VirtualizationTechnology
108417 + (Most Core i3/5/7 support EPT)
108418 +
108419 + To see if your AMD processor supports RVI, see:
108420 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108421 +
108422 +config GRKERNSEC_CONFIG_VIRT_SOFT
108423 + bool "First-gen/No Hardware Virtualization"
108424 + help
108425 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108426 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108427 +
108428 +endchoice
108429 +
108430 +choice
108431 + prompt "Virtualization Software"
108432 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108433 + help
108434 +
108435 +config GRKERNSEC_CONFIG_VIRT_XEN
108436 + bool "Xen"
108437 + help
108438 + Choose this option if this kernel is running as a Xen guest or host.
108439 +
108440 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108441 + bool "VMWare"
108442 + help
108443 + Choose this option if this kernel is running as a VMWare guest or host.
108444 +
108445 +config GRKERNSEC_CONFIG_VIRT_KVM
108446 + bool "KVM"
108447 + help
108448 + Choose this option if this kernel is running as a KVM guest or host.
108449 +
108450 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108451 + bool "VirtualBox"
108452 + help
108453 + Choose this option if this kernel is running as a VirtualBox guest or host.
108454 +
108455 +config GRKERNSEC_CONFIG_VIRT_HYPERV
108456 + bool "Hyper-V"
108457 + help
108458 + Choose this option if this kernel is running as a Hyper-V guest.
108459 +
108460 +endchoice
108461 +
108462 +choice
108463 + prompt "Required Priorities"
108464 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108465 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108466 + help
108467 +
108468 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108469 + bool "Performance"
108470 + help
108471 + Choose this option if performance is of highest priority for this deployment
108472 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108473 + clearing of structures intended for userland, and freed memory sanitizing will
108474 + be disabled.
108475 +
108476 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108477 + bool "Security"
108478 + help
108479 + Choose this option if security is of highest priority for this deployment of
108480 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108481 + for userland, and freed memory sanitizing will be enabled for this kernel.
108482 + In a worst-case scenario, these features can introduce a 20% performance hit
108483 + (UDEREF on x64 contributing half of this hit).
108484 +
108485 +endchoice
108486 +
108487 +menu "Default Special Groups"
108488 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108489 +
108490 +config GRKERNSEC_PROC_GID
108491 + int "GID exempted from /proc restrictions"
108492 + default 1001
108493 + help
108494 + Setting this GID determines which group will be exempted from
108495 + grsecurity's /proc restrictions, allowing users of the specified
108496 + group to view network statistics and the existence of other users'
108497 + processes on the system. This GID may also be chosen at boot time
108498 + via "grsec_proc_gid=" on the kernel commandline.
108499 +
108500 +config GRKERNSEC_TPE_UNTRUSTED_GID
108501 + int "GID for TPE-untrusted users"
108502 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108503 + default 1005
108504 + help
108505 + Setting this GID determines which group untrusted users should
108506 + be added to. These users will be placed under grsecurity's Trusted Path
108507 + Execution mechanism, preventing them from executing their own binaries.
108508 + The users will only be able to execute binaries in directories owned and
108509 + writable only by the root user. If the sysctl option is enabled, a sysctl
108510 + option with name "tpe_gid" is created.
108511 +
108512 +config GRKERNSEC_TPE_TRUSTED_GID
108513 + int "GID for TPE-trusted users"
108514 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108515 + default 1005
108516 + help
108517 + Setting this GID determines what group TPE restrictions will be
108518 + *disabled* for. If the sysctl option is enabled, a sysctl option
108519 + with name "tpe_gid" is created.
108520 +
108521 +config GRKERNSEC_SYMLINKOWN_GID
108522 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108523 + depends on GRKERNSEC_CONFIG_SERVER
108524 + default 1006
108525 + help
108526 + Setting this GID determines what group kernel-enforced
108527 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108528 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108529 +
108530 +
108531 +endmenu
108532 +
108533 +menu "Customize Configuration"
108534 +depends on GRKERNSEC
108535 +
108536 +menu "PaX"
108537 +
108538 +config PAX
108539 + bool "Enable various PaX features"
108540 + default y if GRKERNSEC_CONFIG_AUTO
108541 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108542 + help
108543 + This allows you to enable various PaX features. PaX adds
108544 + intrusion prevention mechanisms to the kernel that reduce
108545 + the risks posed by exploitable memory corruption bugs.
108546 +
108547 +menu "PaX Control"
108548 + depends on PAX
108549 +
108550 +config PAX_SOFTMODE
108551 + bool 'Support soft mode'
108552 + help
108553 + Enabling this option will allow you to run PaX in soft mode, that
108554 + is, PaX features will not be enforced by default, only on executables
108555 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108556 + support as they are the only way to mark executables for soft mode use.
108557 +
108558 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108559 + line option on boot. Furthermore you can control various PaX features
108560 + at runtime via the entries in /proc/sys/kernel/pax.
108561 +
108562 +config PAX_EI_PAX
108563 + bool 'Use legacy ELF header marking'
108564 + default y if GRKERNSEC_CONFIG_AUTO
108565 + help
108566 + Enabling this option will allow you to control PaX features on
108567 + a per executable basis via the 'chpax' utility available at
108568 + http://pax.grsecurity.net/. The control flags will be read from
108569 + an otherwise reserved part of the ELF header. This marking has
108570 + numerous drawbacks (no support for soft-mode, toolchain does not
108571 + know about the non-standard use of the ELF header) therefore it
108572 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108573 + support.
108574 +
108575 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108576 + support as well, they will override the legacy EI_PAX marks.
108577 +
108578 + If you enable none of the marking options then all applications
108579 + will run with PaX enabled on them by default.
108580 +
108581 +config PAX_PT_PAX_FLAGS
108582 + bool 'Use ELF program header marking'
108583 + default y if GRKERNSEC_CONFIG_AUTO
108584 + help
108585 + Enabling this option will allow you to control PaX features on
108586 + a per executable basis via the 'paxctl' utility available at
108587 + http://pax.grsecurity.net/. The control flags will be read from
108588 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108589 + has the benefits of supporting both soft mode and being fully
108590 + integrated into the toolchain (the binutils patch is available
108591 + from http://pax.grsecurity.net).
108592 +
108593 + Note that if you enable the legacy EI_PAX marking support as well,
108594 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108595 +
108596 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108597 + must make sure that the marks are the same if a binary has both marks.
108598 +
108599 + If you enable none of the marking options then all applications
108600 + will run with PaX enabled on them by default.
108601 +
108602 +config PAX_XATTR_PAX_FLAGS
108603 + bool 'Use filesystem extended attributes marking'
108604 + default y if GRKERNSEC_CONFIG_AUTO
108605 + select CIFS_XATTR if CIFS
108606 + select F2FS_FS_XATTR if F2FS_FS
108607 + select EXT2_FS_XATTR if EXT2_FS
108608 + select EXT3_FS_XATTR if EXT3_FS
108609 + select JFFS2_FS_XATTR if JFFS2_FS
108610 + select REISERFS_FS_XATTR if REISERFS_FS
108611 + select SQUASHFS_XATTR if SQUASHFS
108612 + select TMPFS_XATTR if TMPFS
108613 + help
108614 + Enabling this option will allow you to control PaX features on
108615 + a per executable basis via the 'setfattr' utility. The control
108616 + flags will be read from the user.pax.flags extended attribute of
108617 + the file. This marking has the benefit of supporting binary-only
108618 + applications that self-check themselves (e.g., skype) and would
108619 + not tolerate chpax/paxctl changes. The main drawback is that
108620 + extended attributes are not supported by some filesystems (e.g.,
108621 + isofs, udf, vfat) so copying files through such filesystems will
108622 + lose the extended attributes and these PaX markings.
108623 +
108624 + Note that if you enable the legacy EI_PAX marking support as well,
108625 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108626 +
108627 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108628 + must make sure that the marks are the same if a binary has both marks.
108629 +
108630 + If you enable none of the marking options then all applications
108631 + will run with PaX enabled on them by default.
108632 +
108633 +choice
108634 + prompt 'MAC system integration'
108635 + default PAX_HAVE_ACL_FLAGS
108636 + help
108637 + Mandatory Access Control systems have the option of controlling
108638 + PaX flags on a per executable basis, choose the method supported
108639 + by your particular system.
108640 +
108641 + - "none": if your MAC system does not interact with PaX,
108642 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108643 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108644 +
108645 + NOTE: this option is for developers/integrators only.
108646 +
108647 + config PAX_NO_ACL_FLAGS
108648 + bool 'none'
108649 +
108650 + config PAX_HAVE_ACL_FLAGS
108651 + bool 'direct'
108652 +
108653 + config PAX_HOOK_ACL_FLAGS
108654 + bool 'hook'
108655 +endchoice
108656 +
108657 +endmenu
108658 +
108659 +menu "Non-executable pages"
108660 + depends on PAX
108661 +
108662 +config PAX_NOEXEC
108663 + bool "Enforce non-executable pages"
108664 + default y if GRKERNSEC_CONFIG_AUTO
108665 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108666 + help
108667 + By design some architectures do not allow for protecting memory
108668 + pages against execution or even if they do, Linux does not make
108669 + use of this feature. In practice this means that if a page is
108670 + readable (such as the stack or heap) it is also executable.
108671 +
108672 + There is a well known exploit technique that makes use of this
108673 + fact and a common programming mistake where an attacker can
108674 + introduce code of his choice somewhere in the attacked program's
108675 + memory (typically the stack or the heap) and then execute it.
108676 +
108677 + If the attacked program was running with different (typically
108678 + higher) privileges than that of the attacker, then he can elevate
108679 + his own privilege level (e.g. get a root shell, write to files for
108680 + which he does not have write access to, etc).
108681 +
108682 + Enabling this option will let you choose from various features
108683 + that prevent the injection and execution of 'foreign' code in
108684 + a program.
108685 +
108686 + This will also break programs that rely on the old behaviour and
108687 + expect that dynamically allocated memory via the malloc() family
108688 + of functions is executable (which it is not). Notable examples
108689 + are the XFree86 4.x server, the java runtime and wine.
108690 +
108691 +config PAX_PAGEEXEC
108692 + bool "Paging based non-executable pages"
108693 + default y if GRKERNSEC_CONFIG_AUTO
108694 + 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)
108695 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108696 + help
108697 + This implementation is based on the paging feature of the CPU.
108698 + On i386 without hardware non-executable bit support there is a
108699 + variable but usually low performance impact, however on Intel's
108700 + P4 core based CPUs it is very high so you should not enable this
108701 + for kernels meant to be used on such CPUs.
108702 +
108703 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108704 + with hardware non-executable bit support there is no performance
108705 + impact, on ppc the impact is negligible.
108706 +
108707 + Note that several architectures require various emulations due to
108708 + badly designed userland ABIs, this will cause a performance impact
108709 + but will disappear as soon as userland is fixed. For example, ppc
108710 + userland MUST have been built with secure-plt by a recent toolchain.
108711 +
108712 +config PAX_SEGMEXEC
108713 + bool "Segmentation based non-executable pages"
108714 + default y if GRKERNSEC_CONFIG_AUTO
108715 + depends on PAX_NOEXEC && X86_32
108716 + help
108717 + This implementation is based on the segmentation feature of the
108718 + CPU and has a very small performance impact, however applications
108719 + will be limited to a 1.5 GB address space instead of the normal
108720 + 3 GB.
108721 +
108722 +config PAX_EMUTRAMP
108723 + bool "Emulate trampolines"
108724 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108725 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108726 + help
108727 + There are some programs and libraries that for one reason or
108728 + another attempt to execute special small code snippets from
108729 + non-executable memory pages. Most notable examples are the
108730 + signal handler return code generated by the kernel itself and
108731 + the GCC trampolines.
108732 +
108733 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108734 + such programs will no longer work under your kernel.
108735 +
108736 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108737 + utilities to enable trampoline emulation for the affected programs
108738 + yet still have the protection provided by the non-executable pages.
108739 +
108740 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108741 + your system will not even boot.
108742 +
108743 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108744 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108745 + for the affected files.
108746 +
108747 + NOTE: enabling this feature *may* open up a loophole in the
108748 + protection provided by non-executable pages that an attacker
108749 + could abuse. Therefore the best solution is to not have any
108750 + files on your system that would require this option. This can
108751 + be achieved by not using libc5 (which relies on the kernel
108752 + signal handler return code) and not using or rewriting programs
108753 + that make use of the nested function implementation of GCC.
108754 + Skilled users can just fix GCC itself so that it implements
108755 + nested function calls in a way that does not interfere with PaX.
108756 +
108757 +config PAX_EMUSIGRT
108758 + bool "Automatically emulate sigreturn trampolines"
108759 + depends on PAX_EMUTRAMP && PARISC
108760 + default y
108761 + help
108762 + Enabling this option will have the kernel automatically detect
108763 + and emulate signal return trampolines executing on the stack
108764 + that would otherwise lead to task termination.
108765 +
108766 + This solution is intended as a temporary one for users with
108767 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108768 + Modula-3 runtime, etc) or executables linked to such, basically
108769 + everything that does not specify its own SA_RESTORER function in
108770 + normal executable memory like glibc 2.1+ does.
108771 +
108772 + On parisc you MUST enable this option, otherwise your system will
108773 + not even boot.
108774 +
108775 + NOTE: this feature cannot be disabled on a per executable basis
108776 + and since it *does* open up a loophole in the protection provided
108777 + by non-executable pages, the best solution is to not have any
108778 + files on your system that would require this option.
108779 +
108780 +config PAX_MPROTECT
108781 + bool "Restrict mprotect()"
108782 + default y if GRKERNSEC_CONFIG_AUTO
108783 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108784 + help
108785 + Enabling this option will prevent programs from
108786 + - changing the executable status of memory pages that were
108787 + not originally created as executable,
108788 + - making read-only executable pages writable again,
108789 + - creating executable pages from anonymous memory,
108790 + - making read-only-after-relocations (RELRO) data pages writable again.
108791 +
108792 + You should say Y here to complete the protection provided by
108793 + the enforcement of non-executable pages.
108794 +
108795 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108796 + this feature on a per file basis.
108797 +
108798 +config PAX_MPROTECT_COMPAT
108799 + bool "Use legacy/compat protection demoting (read help)"
108800 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108801 + depends on PAX_MPROTECT
108802 + help
108803 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108804 + by sending the proper error code to the application. For some broken
108805 + userland, this can cause problems with Python or other applications. The
108806 + current implementation however allows for applications like clamav to
108807 + detect if JIT compilation/execution is allowed and to fall back gracefully
108808 + to an interpreter-based mode if it does not. While we encourage everyone
108809 + to use the current implementation as-is and push upstream to fix broken
108810 + userland (note that the RWX logging option can assist with this), in some
108811 + environments this may not be possible. Having to disable MPROTECT
108812 + completely on certain binaries reduces the security benefit of PaX,
108813 + so this option is provided for those environments to revert to the old
108814 + behavior.
108815 +
108816 +config PAX_ELFRELOCS
108817 + bool "Allow ELF text relocations (read help)"
108818 + depends on PAX_MPROTECT
108819 + default n
108820 + help
108821 + Non-executable pages and mprotect() restrictions are effective
108822 + in preventing the introduction of new executable code into an
108823 + attacked task's address space. There remain only two venues
108824 + for this kind of attack: if the attacker can execute already
108825 + existing code in the attacked task then he can either have it
108826 + create and mmap() a file containing his code or have it mmap()
108827 + an already existing ELF library that does not have position
108828 + independent code in it and use mprotect() on it to make it
108829 + writable and copy his code there. While protecting against
108830 + the former approach is beyond PaX, the latter can be prevented
108831 + by having only PIC ELF libraries on one's system (which do not
108832 + need to relocate their code). If you are sure this is your case,
108833 + as is the case with all modern Linux distributions, then leave
108834 + this option disabled. You should say 'n' here.
108835 +
108836 +config PAX_ETEXECRELOCS
108837 + bool "Allow ELF ET_EXEC text relocations"
108838 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108839 + select PAX_ELFRELOCS
108840 + default y
108841 + help
108842 + On some architectures there are incorrectly created applications
108843 + that require text relocations and would not work without enabling
108844 + this option. If you are an alpha, ia64 or parisc user, you should
108845 + enable this option and disable it once you have made sure that
108846 + none of your applications need it.
108847 +
108848 +config PAX_EMUPLT
108849 + bool "Automatically emulate ELF PLT"
108850 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108851 + default y
108852 + help
108853 + Enabling this option will have the kernel automatically detect
108854 + and emulate the Procedure Linkage Table entries in ELF files.
108855 + On some architectures such entries are in writable memory, and
108856 + become non-executable leading to task termination. Therefore
108857 + it is mandatory that you enable this option on alpha, parisc,
108858 + sparc and sparc64, otherwise your system would not even boot.
108859 +
108860 + NOTE: this feature *does* open up a loophole in the protection
108861 + provided by the non-executable pages, therefore the proper
108862 + solution is to modify the toolchain to produce a PLT that does
108863 + not need to be writable.
108864 +
108865 +config PAX_DLRESOLVE
108866 + bool 'Emulate old glibc resolver stub'
108867 + depends on PAX_EMUPLT && SPARC
108868 + default n
108869 + help
108870 + This option is needed if userland has an old glibc (before 2.4)
108871 + that puts a 'save' instruction into the runtime generated resolver
108872 + stub that needs special emulation.
108873 +
108874 +config PAX_KERNEXEC
108875 + bool "Enforce non-executable kernel pages"
108876 + 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))
108877 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108878 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108879 + select PAX_KERNEXEC_PLUGIN if X86_64
108880 + help
108881 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108882 + that is, enabling this option will make it harder to inject
108883 + and execute 'foreign' code in kernel memory itself.
108884 +
108885 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108886 + the kernel command-line will result in an RWX physical map.
108887 +
108888 + Likewise, the EFI runtime services are necessarily mapped as
108889 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108890 + is recommended that you boot with "noefi" on the kernel
108891 + command-line if possible to eliminate the mapping.
108892 +
108893 +choice
108894 + prompt "Return Address Instrumentation Method"
108895 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108896 + depends on PAX_KERNEXEC_PLUGIN
108897 + help
108898 + Select the method used to instrument function pointer dereferences.
108899 + Note that binary modules cannot be instrumented by this approach.
108900 +
108901 + Note that the implementation requires a gcc with plugin support,
108902 + i.e., gcc 4.5 or newer. You may need to install the supporting
108903 + headers explicitly in addition to the normal gcc package.
108904 +
108905 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108906 + bool "bts"
108907 + help
108908 + This method is compatible with binary only modules but has
108909 + a higher runtime overhead.
108910 +
108911 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108912 + bool "or"
108913 + depends on !PARAVIRT
108914 + help
108915 + This method is incompatible with binary only modules but has
108916 + a lower runtime overhead.
108917 +endchoice
108918 +
108919 +config PAX_KERNEXEC_PLUGIN_METHOD
108920 + string
108921 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108922 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108923 + default ""
108924 +
108925 +config PAX_KERNEXEC_MODULE_TEXT
108926 + int "Minimum amount of memory reserved for module code"
108927 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108928 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108929 + depends on PAX_KERNEXEC && X86_32
108930 + help
108931 + Due to implementation details the kernel must reserve a fixed
108932 + amount of memory for runtime allocated code (such as modules)
108933 + at compile time that cannot be changed at runtime. Here you
108934 + can specify the minimum amount in MB that will be reserved.
108935 + Due to the same implementation details this size will always
108936 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108937 + the actually available memory for runtime allocated code will
108938 + usually be more than this minimum.
108939 +
108940 + The default 4 MB should be enough for most users but if you have
108941 + an excessive number of modules (e.g., most distribution configs
108942 + compile many drivers as modules) or use huge modules such as
108943 + nvidia's kernel driver, you will need to adjust this amount.
108944 + A good rule of thumb is to look at your currently loaded kernel
108945 + modules and add up their sizes.
108946 +
108947 +endmenu
108948 +
108949 +menu "Address Space Layout Randomization"
108950 + depends on PAX
108951 +
108952 +config PAX_ASLR
108953 + bool "Address Space Layout Randomization"
108954 + default y if GRKERNSEC_CONFIG_AUTO
108955 + help
108956 + Many if not most exploit techniques rely on the knowledge of
108957 + certain addresses in the attacked program. The following options
108958 + will allow the kernel to apply a certain amount of randomization
108959 + to specific parts of the program thereby forcing an attacker to
108960 + guess them in most cases. Any failed guess will most likely crash
108961 + the attacked program which allows the kernel to detect such attempts
108962 + and react on them. PaX itself provides no reaction mechanisms,
108963 + instead it is strongly encouraged that you make use of grsecurity's
108964 + (http://www.grsecurity.net/) built-in crash detection features or
108965 + develop one yourself.
108966 +
108967 + By saying Y here you can choose to randomize the following areas:
108968 + - top of the task's kernel stack
108969 + - top of the task's userland stack
108970 + - base address for mmap() requests that do not specify one
108971 + (this includes all libraries)
108972 + - base address of the main executable
108973 +
108974 + It is strongly recommended to say Y here as address space layout
108975 + randomization has negligible impact on performance yet it provides
108976 + a very effective protection.
108977 +
108978 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108979 + this feature on a per file basis.
108980 +
108981 +config PAX_RANDKSTACK
108982 + bool "Randomize kernel stack base"
108983 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108984 + depends on X86_TSC && X86
108985 + help
108986 + By saying Y here the kernel will randomize every task's kernel
108987 + stack on every system call. This will not only force an attacker
108988 + to guess it but also prevent him from making use of possible
108989 + leaked information about it.
108990 +
108991 + Since the kernel stack is a rather scarce resource, randomization
108992 + may cause unexpected stack overflows, therefore you should very
108993 + carefully test your system. Note that once enabled in the kernel
108994 + configuration, this feature cannot be disabled on a per file basis.
108995 +
108996 +config PAX_RANDUSTACK
108997 + bool
108998 +
108999 +config PAX_RANDMMAP
109000 + bool "Randomize user stack and mmap() bases"
109001 + default y if GRKERNSEC_CONFIG_AUTO
109002 + depends on PAX_ASLR
109003 + select PAX_RANDUSTACK
109004 + help
109005 + By saying Y here the kernel will randomize every task's userland
109006 + stack and use a randomized base address for mmap() requests that
109007 + do not specify one themselves.
109008 +
109009 + The stack randomization is done in two steps where the second
109010 + one may apply a big amount of shift to the top of the stack and
109011 + cause problems for programs that want to use lots of memory (more
109012 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
109013 +
109014 + As a result of mmap randomization all dynamically loaded libraries
109015 + will appear at random addresses and therefore be harder to exploit
109016 + by a technique where an attacker attempts to execute library code
109017 + for his purposes (e.g. spawn a shell from an exploited program that
109018 + is running at an elevated privilege level).
109019 +
109020 + Furthermore, if a program is relinked as a dynamic ELF file, its
109021 + base address will be randomized as well, completing the full
109022 + randomization of the address space layout. Attacking such programs
109023 + becomes a guess game. You can find an example of doing this at
109024 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
109025 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
109026 +
109027 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
109028 + feature on a per file basis.
109029 +
109030 +endmenu
109031 +
109032 +menu "Miscellaneous hardening features"
109033 +
109034 +config PAX_MEMORY_SANITIZE
109035 + bool "Sanitize all freed memory"
109036 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109037 + help
109038 + By saying Y here the kernel will erase memory pages and slab objects
109039 + as soon as they are freed. This in turn reduces the lifetime of data
109040 + stored in them, making it less likely that sensitive information such
109041 + as passwords, cryptographic secrets, etc stay in memory for too long.
109042 +
109043 + This is especially useful for programs whose runtime is short, long
109044 + lived processes and the kernel itself benefit from this as long as
109045 + they ensure timely freeing of memory that may hold sensitive
109046 + information.
109047 +
109048 + A nice side effect of the sanitization of slab objects is the
109049 + reduction of possible info leaks caused by padding bytes within the
109050 + leaky structures. Use-after-free bugs for structures containing
109051 + pointers can also be detected as dereferencing the sanitized pointer
109052 + will generate an access violation.
109053 +
109054 + The tradeoff is performance impact, on a single CPU system kernel
109055 + compilation sees a 3% slowdown, other systems and workloads may vary
109056 + and you are advised to test this feature on your expected workload
109057 + before deploying it.
109058 +
109059 + The slab sanitization feature excludes a few slab caches per default
109060 + for performance reasons. To extend the feature to cover those as
109061 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
109062 +
109063 + To reduce the performance penalty by sanitizing pages only, albeit
109064 + limiting the effectiveness of this feature at the same time, slab
109065 + sanitization can be disabled with the kernel command line parameter
109066 + "pax_sanitize_slab=off".
109067 +
109068 + Note that this feature does not protect data stored in live pages,
109069 + e.g., process memory swapped to disk may stay there for a long time.
109070 +
109071 +config PAX_MEMORY_STACKLEAK
109072 + bool "Sanitize kernel stack"
109073 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109074 + depends on X86
109075 + help
109076 + By saying Y here the kernel will erase the kernel stack before it
109077 + returns from a system call. This in turn reduces the information
109078 + that a kernel stack leak bug can reveal.
109079 +
109080 + Note that such a bug can still leak information that was put on
109081 + the stack by the current system call (the one eventually triggering
109082 + the bug) but traces of earlier system calls on the kernel stack
109083 + cannot leak anymore.
109084 +
109085 + The tradeoff is performance impact: on a single CPU system kernel
109086 + compilation sees a 1% slowdown, other systems and workloads may vary
109087 + and you are advised to test this feature on your expected workload
109088 + before deploying it.
109089 +
109090 + Note that the full feature requires a gcc with plugin support,
109091 + i.e., gcc 4.5 or newer. You may need to install the supporting
109092 + headers explicitly in addition to the normal gcc package. Using
109093 + older gcc versions means that functions with large enough stack
109094 + frames may leave uninitialized memory behind that may be exposed
109095 + to a later syscall leaking the stack.
109096 +
109097 +config PAX_MEMORY_STRUCTLEAK
109098 + bool "Forcibly initialize local variables copied to userland"
109099 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109100 + help
109101 + By saying Y here the kernel will zero initialize some local
109102 + variables that are going to be copied to userland. This in
109103 + turn prevents unintended information leakage from the kernel
109104 + stack should later code forget to explicitly set all parts of
109105 + the copied variable.
109106 +
109107 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
109108 + at a much smaller coverage.
109109 +
109110 + Note that the implementation requires a gcc with plugin support,
109111 + i.e., gcc 4.5 or newer. You may need to install the supporting
109112 + headers explicitly in addition to the normal gcc package.
109113 +
109114 +config PAX_MEMORY_UDEREF
109115 + bool "Prevent invalid userland pointer dereference"
109116 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
109117 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
109118 + select PAX_PER_CPU_PGD if X86_64
109119 + help
109120 + By saying Y here the kernel will be prevented from dereferencing
109121 + userland pointers in contexts where the kernel expects only kernel
109122 + pointers. This is both a useful runtime debugging feature and a
109123 + security measure that prevents exploiting a class of kernel bugs.
109124 +
109125 + The tradeoff is that some virtualization solutions may experience
109126 + a huge slowdown and therefore you should not enable this feature
109127 + for kernels meant to run in such environments. Whether a given VM
109128 + solution is affected or not is best determined by simply trying it
109129 + out, the performance impact will be obvious right on boot as this
109130 + mechanism engages from very early on. A good rule of thumb is that
109131 + VMs running on CPUs without hardware virtualization support (i.e.,
109132 + the majority of IA-32 CPUs) will likely experience the slowdown.
109133 +
109134 + On X86_64 the kernel will make use of PCID support when available
109135 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
109136 + or performance impact. Pass pax_weakuderef on the kernel command
109137 + line to choose the latter.
109138 +
109139 +config PAX_REFCOUNT
109140 + bool "Prevent various kernel object reference counter overflows"
109141 + default y if GRKERNSEC_CONFIG_AUTO
109142 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
109143 + help
109144 + By saying Y here the kernel will detect and prevent overflowing
109145 + various (but not all) kinds of object reference counters. Such
109146 + overflows can normally occur due to bugs only and are often, if
109147 + not always, exploitable.
109148 +
109149 + The tradeoff is that data structures protected by an overflowed
109150 + refcount will never be freed and therefore will leak memory. Note
109151 + that this leak also happens even without this protection but in
109152 + that case the overflow can eventually trigger the freeing of the
109153 + data structure while it is still being used elsewhere, resulting
109154 + in the exploitable situation that this feature prevents.
109155 +
109156 + Since this has a negligible performance impact, you should enable
109157 + this feature.
109158 +
109159 +config PAX_CONSTIFY_PLUGIN
109160 + bool "Automatically constify eligible structures"
109161 + default y
109162 + depends on !UML && PAX_KERNEXEC
109163 + help
109164 + By saying Y here the compiler will automatically constify a class
109165 + of types that contain only function pointers. This reduces the
109166 + kernel's attack surface and also produces a better memory layout.
109167 +
109168 + Note that the implementation requires a gcc with plugin support,
109169 + i.e., gcc 4.5 or newer. You may need to install the supporting
109170 + headers explicitly in addition to the normal gcc package.
109171 +
109172 + Note that if some code really has to modify constified variables
109173 + then the source code will have to be patched to allow it. Examples
109174 + can be found in PaX itself (the no_const attribute) and for some
109175 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
109176 +
109177 +config PAX_USERCOPY
109178 + bool "Harden heap object copies between kernel and userland"
109179 + default y if GRKERNSEC_CONFIG_AUTO
109180 + depends on ARM || IA64 || PPC || SPARC || X86
109181 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
109182 + select PAX_USERCOPY_SLABS
109183 + help
109184 + By saying Y here the kernel will enforce the size of heap objects
109185 + when they are copied in either direction between the kernel and
109186 + userland, even if only a part of the heap object is copied.
109187 +
109188 + Specifically, this checking prevents information leaking from the
109189 + kernel heap during kernel to userland copies (if the kernel heap
109190 + object is otherwise fully initialized) and prevents kernel heap
109191 + overflows during userland to kernel copies.
109192 +
109193 + Note that the current implementation provides the strictest bounds
109194 + checks for the SLUB allocator.
109195 +
109196 + Enabling this option also enables per-slab cache protection against
109197 + data in a given cache being copied into/out of via userland
109198 + accessors. Though the whitelist of regions will be reduced over
109199 + time, it notably protects important data structures like task structs.
109200 +
109201 + If frame pointers are enabled on x86, this option will also restrict
109202 + copies into and out of the kernel stack to local variables within a
109203 + single frame.
109204 +
109205 + Since this has a negligible performance impact, you should enable
109206 + this feature.
109207 +
109208 +config PAX_USERCOPY_DEBUG
109209 + bool
109210 + depends on X86 && PAX_USERCOPY
109211 + default n
109212 +
109213 +config PAX_SIZE_OVERFLOW
109214 + bool "Prevent various integer overflows in function size parameters"
109215 + default y if GRKERNSEC_CONFIG_AUTO
109216 + depends on X86
109217 + help
109218 + By saying Y here the kernel recomputes expressions of function
109219 + arguments marked by a size_overflow attribute with double integer
109220 + precision (DImode/TImode for 32/64 bit integer types).
109221 +
109222 + The recomputed argument is checked against TYPE_MAX and an event
109223 + is logged on overflow and the triggering process is killed.
109224 +
109225 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
109226 +
109227 + Note that the implementation requires a gcc with plugin support,
109228 + i.e., gcc 4.5 or newer. You may need to install the supporting
109229 + headers explicitly in addition to the normal gcc package.
109230 +
109231 +config PAX_LATENT_ENTROPY
109232 + bool "Generate some entropy during boot and runtime"
109233 + default y if GRKERNSEC_CONFIG_AUTO
109234 + help
109235 + By saying Y here the kernel will instrument some kernel code to
109236 + extract some entropy from both original and artificially created
109237 + program state. This will help especially embedded systems where
109238 + there is little 'natural' source of entropy normally. The cost
109239 + is some slowdown of the boot process and fork and irq processing.
109240 +
109241 + When pax_extra_latent_entropy is passed on the kernel command line,
109242 + entropy will be extracted from up to the first 4GB of RAM while the
109243 + runtime memory allocator is being initialized. This costs even more
109244 + slowdown of the boot process.
109245 +
109246 + Note that the implementation requires a gcc with plugin support,
109247 + i.e., gcc 4.5 or newer. You may need to install the supporting
109248 + headers explicitly in addition to the normal gcc package.
109249 +
109250 + Note that entropy extracted this way is not cryptographically
109251 + secure!
109252 +
109253 +endmenu
109254 +
109255 +endmenu
109256 +
109257 +source grsecurity/Kconfig
109258 +
109259 +endmenu
109260 +
109261 +endmenu
109262 +
109263 source security/keys/Kconfig
109264
109265 config SECURITY_DMESG_RESTRICT
109266 @@ -103,7 +1071,7 @@ config INTEL_TXT
109267 config LSM_MMAP_MIN_ADDR
109268 int "Low address space for LSM to protect from user allocation"
109269 depends on SECURITY && SECURITY_SELINUX
109270 - default 32768 if ARM || (ARM64 && COMPAT)
109271 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
109272 default 65536
109273 help
109274 This is the portion of low virtual memory which should be protected
109275 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
109276 index fdaa50c..2761dcb 100644
109277 --- a/security/apparmor/file.c
109278 +++ b/security/apparmor/file.c
109279 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
109280 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
109281 struct path *new_dir, struct dentry *new_dentry)
109282 {
109283 - struct path link = { new_dir->mnt, new_dentry };
109284 - struct path target = { new_dir->mnt, old_dentry };
109285 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
109286 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
109287 struct path_cond cond = {
109288 old_dentry->d_inode->i_uid,
109289 old_dentry->d_inode->i_mode
109290 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
109291 index 9981000..eb21356 100644
109292 --- a/security/apparmor/lsm.c
109293 +++ b/security/apparmor/lsm.c
109294 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109295 struct dentry *dentry, u32 mask,
109296 struct path_cond *cond)
109297 {
109298 - struct path path = { dir->mnt, dentry };
109299 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
109300
109301 return common_perm(op, &path, mask, cond);
109302 }
109303 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109304 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
109305 struct dentry *dentry, u32 mask)
109306 {
109307 - struct path path = { mnt, dentry };
109308 + struct path path = { .mnt = mnt, .dentry = dentry };
109309 struct path_cond cond = { dentry->d_inode->i_uid,
109310 dentry->d_inode->i_mode
109311 };
109312 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
109313
109314 profile = aa_current_profile();
109315 if (!unconfined(profile)) {
109316 - struct path old_path = { old_dir->mnt, old_dentry };
109317 - struct path new_path = { new_dir->mnt, new_dentry };
109318 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
109319 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
109320 struct path_cond cond = { old_dentry->d_inode->i_uid,
109321 old_dentry->d_inode->i_mode
109322 };
109323 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
109324 return error;
109325 }
109326
109327 -static struct security_operations apparmor_ops = {
109328 +static struct security_operations apparmor_ops __read_only = {
109329 .name = "apparmor",
109330
109331 .ptrace_access_check = apparmor_ptrace_access_check,
109332 diff --git a/security/commoncap.c b/security/commoncap.c
109333 index bab0611..f9a0ff5 100644
109334 --- a/security/commoncap.c
109335 +++ b/security/commoncap.c
109336 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109337 return 0;
109338 }
109339
109340 +/* returns:
109341 + 1 for suid privilege
109342 + 2 for sgid privilege
109343 + 3 for fscap privilege
109344 +*/
109345 +int is_privileged_binary(const struct dentry *dentry)
109346 +{
109347 + struct cpu_vfs_cap_data capdata;
109348 + struct inode *inode = dentry->d_inode;
109349 +
109350 + if (!inode || S_ISDIR(inode->i_mode))
109351 + return 0;
109352 +
109353 + if (inode->i_mode & S_ISUID)
109354 + return 1;
109355 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109356 + return 2;
109357 +
109358 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109359 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109360 + return 3;
109361 + }
109362 +
109363 + return 0;
109364 +}
109365 +
109366 /*
109367 * Attempt to get the on-exec apply capability sets for an executable file from
109368 * its xattrs and, if present, apply them to the proposed credentials being
109369 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109370 const struct cred *cred = current_cred();
109371 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109372
109373 + if (gr_acl_enable_at_secure())
109374 + return 1;
109375 +
109376 if (!uid_eq(cred->uid, root_uid)) {
109377 if (bprm->cap_effective)
109378 return 1;
109379 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109380 index 0fb456c..83711f9 100644
109381 --- a/security/integrity/ima/ima.h
109382 +++ b/security/integrity/ima/ima.h
109383 @@ -118,8 +118,8 @@ int ima_init_template(void);
109384 extern spinlock_t ima_queue_lock;
109385
109386 struct ima_h_table {
109387 - atomic_long_t len; /* number of stored measurements in the list */
109388 - atomic_long_t violations;
109389 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109390 + atomic_long_unchecked_t violations;
109391 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109392 };
109393 extern struct ima_h_table ima_htable;
109394 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109395 index d9cd5ce..c5c29ac 100644
109396 --- a/security/integrity/ima/ima_api.c
109397 +++ b/security/integrity/ima/ima_api.c
109398 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109399 int result;
109400
109401 /* can overflow, only indicator */
109402 - atomic_long_inc(&ima_htable.violations);
109403 + atomic_long_inc_unchecked(&ima_htable.violations);
109404
109405 result = ima_alloc_init_template(NULL, file, filename,
109406 NULL, 0, &entry);
109407 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109408 index da92fcc..8a5d390 100644
109409 --- a/security/integrity/ima/ima_fs.c
109410 +++ b/security/integrity/ima/ima_fs.c
109411 @@ -28,12 +28,12 @@
109412 static int valid_policy = 1;
109413 #define TMPBUFLEN 12
109414 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109415 - loff_t *ppos, atomic_long_t *val)
109416 + loff_t *ppos, atomic_long_unchecked_t *val)
109417 {
109418 char tmpbuf[TMPBUFLEN];
109419 ssize_t len;
109420
109421 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109422 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109423 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109424 }
109425
109426 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109427 index 552705d..9920f4fb 100644
109428 --- a/security/integrity/ima/ima_queue.c
109429 +++ b/security/integrity/ima/ima_queue.c
109430 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109431 INIT_LIST_HEAD(&qe->later);
109432 list_add_tail_rcu(&qe->later, &ima_measurements);
109433
109434 - atomic_long_inc(&ima_htable.len);
109435 + atomic_long_inc_unchecked(&ima_htable.len);
109436 key = ima_hash_key(entry->digest);
109437 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109438 return 0;
109439 diff --git a/security/keys/compat.c b/security/keys/compat.c
109440 index 3478965..ec7bb9e 100644
109441 --- a/security/keys/compat.c
109442 +++ b/security/keys/compat.c
109443 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109444 if (ret == 0)
109445 goto no_payload_free;
109446
109447 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109448 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109449 err:
109450 if (iov != iovstack)
109451 kfree(iov);
109452 diff --git a/security/keys/internal.h b/security/keys/internal.h
109453 index 5f20da0..444ccf1 100644
109454 --- a/security/keys/internal.h
109455 +++ b/security/keys/internal.h
109456 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109457 extern long keyctl_invalidate_key(key_serial_t);
109458
109459 extern long keyctl_instantiate_key_common(key_serial_t,
109460 - const struct iovec *,
109461 + const struct iovec __user *,
109462 unsigned, size_t, key_serial_t);
109463 #ifdef CONFIG_PERSISTENT_KEYRINGS
109464 extern long keyctl_get_persistent(uid_t, key_serial_t);
109465 diff --git a/security/keys/key.c b/security/keys/key.c
109466 index 6d0cad1..8f957df 100644
109467 --- a/security/keys/key.c
109468 +++ b/security/keys/key.c
109469 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109470
109471 atomic_set(&key->usage, 1);
109472 init_rwsem(&key->sem);
109473 - lockdep_set_class(&key->sem, &type->lock_class);
109474 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109475 key->index_key.type = type;
109476 key->user = user;
109477 key->quotalen = quotalen;
109478 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109479 struct key_type *p;
109480 int ret;
109481
109482 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109483 + pax_open_kernel();
109484 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109485 + pax_close_kernel();
109486
109487 ret = -EEXIST;
109488 down_write(&key_types_sem);
109489 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109490 }
109491
109492 /* store the type */
109493 - list_add(&ktype->link, &key_types_list);
109494 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109495
109496 pr_notice("Key type %s registered\n", ktype->name);
109497 ret = 0;
109498 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109499 void unregister_key_type(struct key_type *ktype)
109500 {
109501 down_write(&key_types_sem);
109502 - list_del_init(&ktype->link);
109503 + pax_list_del_init((struct list_head *)&ktype->link);
109504 downgrade_write(&key_types_sem);
109505 key_gc_keytype(ktype);
109506 pr_notice("Key type %s unregistered\n", ktype->name);
109507 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109508 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109509
109510 /* add the special key types */
109511 - list_add_tail(&key_type_keyring.link, &key_types_list);
109512 - list_add_tail(&key_type_dead.link, &key_types_list);
109513 - list_add_tail(&key_type_user.link, &key_types_list);
109514 - list_add_tail(&key_type_logon.link, &key_types_list);
109515 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109516 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109517 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109518 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109519
109520 /* record the root user tracking */
109521 rb_link_node(&root_key_user.node,
109522 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109523 index eff88a5..51d35ef 100644
109524 --- a/security/keys/keyctl.c
109525 +++ b/security/keys/keyctl.c
109526 @@ -1004,7 +1004,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109527 /*
109528 * Copy the iovec data from userspace
109529 */
109530 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109531 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109532 unsigned ioc)
109533 {
109534 for (; ioc > 0; ioc--) {
109535 @@ -1026,7 +1026,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109536 * If successful, 0 will be returned.
109537 */
109538 long keyctl_instantiate_key_common(key_serial_t id,
109539 - const struct iovec *payload_iov,
109540 + const struct iovec __user *payload_iov,
109541 unsigned ioc,
109542 size_t plen,
109543 key_serial_t ringid)
109544 @@ -1121,7 +1121,7 @@ long keyctl_instantiate_key(key_serial_t id,
109545 [0].iov_len = plen
109546 };
109547
109548 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109549 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109550 }
109551
109552 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109553 @@ -1154,7 +1154,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109554 if (ret == 0)
109555 goto no_payload_free;
109556
109557 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109558 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109559 err:
109560 if (iov != iovstack)
109561 kfree(iov);
109562 diff --git a/security/min_addr.c b/security/min_addr.c
109563 index f728728..6457a0c 100644
109564 --- a/security/min_addr.c
109565 +++ b/security/min_addr.c
109566 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109567 */
109568 static void update_mmap_min_addr(void)
109569 {
109570 +#ifndef SPARC
109571 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109572 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109573 mmap_min_addr = dac_mmap_min_addr;
109574 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109575 #else
109576 mmap_min_addr = dac_mmap_min_addr;
109577 #endif
109578 +#endif
109579 }
109580
109581 /*
109582 diff --git a/security/security.c b/security/security.c
109583 index e41b1a8..b66a558 100644
109584 --- a/security/security.c
109585 +++ b/security/security.c
109586 @@ -33,8 +33,8 @@
109587 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109588 CONFIG_DEFAULT_SECURITY;
109589
109590 -static struct security_operations *security_ops;
109591 -static struct security_operations default_security_ops = {
109592 +struct security_operations *security_ops __read_only;
109593 +struct security_operations default_security_ops __read_only = {
109594 .name = "default",
109595 };
109596
109597 @@ -73,11 +73,6 @@ int __init security_init(void)
109598 return 0;
109599 }
109600
109601 -void reset_security_ops(void)
109602 -{
109603 - security_ops = &default_security_ops;
109604 -}
109605 -
109606 /* Save user chosen LSM */
109607 static int __init choose_lsm(char *str)
109608 {
109609 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109610 index a18f1fa..c9b9fc4 100644
109611 --- a/security/selinux/avc.c
109612 +++ b/security/selinux/avc.c
109613 @@ -59,7 +59,7 @@ struct avc_node {
109614 struct avc_cache {
109615 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109616 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109617 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109618 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109619 atomic_t active_nodes;
109620 u32 latest_notif; /* latest revocation notification */
109621 };
109622 @@ -167,7 +167,7 @@ void __init avc_init(void)
109623 spin_lock_init(&avc_cache.slots_lock[i]);
109624 }
109625 atomic_set(&avc_cache.active_nodes, 0);
109626 - atomic_set(&avc_cache.lru_hint, 0);
109627 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109628
109629 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109630 0, SLAB_PANIC, NULL);
109631 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109632 spinlock_t *lock;
109633
109634 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109635 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109636 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109637 head = &avc_cache.slots[hvalue];
109638 lock = &avc_cache.slots_lock[hvalue];
109639
109640 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109641 index e03bad5..b15da09 100644
109642 --- a/security/selinux/hooks.c
109643 +++ b/security/selinux/hooks.c
109644 @@ -95,8 +95,6 @@
109645 #include "audit.h"
109646 #include "avc_ss.h"
109647
109648 -extern struct security_operations *security_ops;
109649 -
109650 /* SECMARK reference count */
109651 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109652
109653 @@ -5772,7 +5770,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109654
109655 #endif
109656
109657 -static struct security_operations selinux_ops = {
109658 +static struct security_operations selinux_ops __read_only = {
109659 .name = "selinux",
109660
109661 .ptrace_access_check = selinux_ptrace_access_check,
109662 @@ -6128,6 +6126,9 @@ static void selinux_nf_ip_exit(void)
109663 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109664 static int selinux_disabled;
109665
109666 +extern struct security_operations *security_ops;
109667 +extern struct security_operations default_security_ops;
109668 +
109669 int selinux_disable(void)
109670 {
109671 if (ss_initialized) {
109672 @@ -6145,7 +6146,9 @@ int selinux_disable(void)
109673 selinux_disabled = 1;
109674 selinux_enabled = 0;
109675
109676 - reset_security_ops();
109677 + pax_open_kernel();
109678 + security_ops = &default_security_ops;
109679 + pax_close_kernel();
109680
109681 /* Try to destroy the avc node cache */
109682 avc_disable();
109683 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109684 index 1450f85..a91e0bc 100644
109685 --- a/security/selinux/include/xfrm.h
109686 +++ b/security/selinux/include/xfrm.h
109687 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109688
109689 rtnl_lock();
109690 for_each_net(net) {
109691 - atomic_inc(&net->xfrm.flow_cache_genid);
109692 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109693 rt_genid_bump_all(net);
109694 }
109695 rtnl_unlock();
109696 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109697 index e6ab307..2008c98 100644
109698 --- a/security/smack/smack_lsm.c
109699 +++ b/security/smack/smack_lsm.c
109700 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109701 return 0;
109702 }
109703
109704 -struct security_operations smack_ops = {
109705 +struct security_operations smack_ops __read_only = {
109706 .name = "smack",
109707
109708 .ptrace_access_check = smack_ptrace_access_check,
109709 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109710 index 4003907..13a2b55 100644
109711 --- a/security/tomoyo/file.c
109712 +++ b/security/tomoyo/file.c
109713 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109714 {
109715 struct tomoyo_request_info r;
109716 struct tomoyo_obj_info obj = {
109717 - .path1 = *path,
109718 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109719 };
109720 int error = -ENOMEM;
109721 struct tomoyo_path_info buf;
109722 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109723 struct tomoyo_path_info buf;
109724 struct tomoyo_request_info r;
109725 struct tomoyo_obj_info obj = {
109726 - .path1 = *path,
109727 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109728 };
109729 int idx;
109730
109731 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109732 {
109733 struct tomoyo_request_info r;
109734 struct tomoyo_obj_info obj = {
109735 - .path1 = *path,
109736 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109737 };
109738 int error;
109739 struct tomoyo_path_info buf;
109740 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109741 {
109742 struct tomoyo_request_info r;
109743 struct tomoyo_obj_info obj = {
109744 - .path1 = *path,
109745 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109746 };
109747 int error = -ENOMEM;
109748 struct tomoyo_path_info buf;
109749 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109750 struct tomoyo_path_info buf2;
109751 struct tomoyo_request_info r;
109752 struct tomoyo_obj_info obj = {
109753 - .path1 = *path1,
109754 - .path2 = *path2,
109755 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109756 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109757 };
109758 int idx;
109759
109760 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109761 index 390c646..f2f8db3 100644
109762 --- a/security/tomoyo/mount.c
109763 +++ b/security/tomoyo/mount.c
109764 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109765 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109766 need_dev = -1; /* dev_name is a directory */
109767 } else {
109768 + if (!capable(CAP_SYS_ADMIN)) {
109769 + error = -EPERM;
109770 + goto out;
109771 + }
109772 fstype = get_fs_type(type);
109773 if (!fstype) {
109774 error = -ENODEV;
109775 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109776 index f0b756e..8aa497b 100644
109777 --- a/security/tomoyo/tomoyo.c
109778 +++ b/security/tomoyo/tomoyo.c
109779 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109780 */
109781 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109782 {
109783 - struct path path = { mnt, dentry };
109784 + struct path path = { .mnt = mnt, .dentry = dentry };
109785 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109786 }
109787
109788 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109789 */
109790 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109791 {
109792 - struct path path = { parent->mnt, dentry };
109793 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109794 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109795 }
109796
109797 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109798 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109799 umode_t mode)
109800 {
109801 - struct path path = { parent->mnt, dentry };
109802 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109803 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109804 mode & S_IALLUGO);
109805 }
109806 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109807 */
109808 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109809 {
109810 - struct path path = { parent->mnt, dentry };
109811 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109812 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109813 }
109814
109815 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109816 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109817 const char *old_name)
109818 {
109819 - struct path path = { parent->mnt, dentry };
109820 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109821 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109822 }
109823
109824 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109825 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109826 umode_t mode, unsigned int dev)
109827 {
109828 - struct path path = { parent->mnt, dentry };
109829 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109830 int type = TOMOYO_TYPE_CREATE;
109831 const unsigned int perm = mode & S_IALLUGO;
109832
109833 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109834 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109835 struct dentry *new_dentry)
109836 {
109837 - struct path path1 = { new_dir->mnt, old_dentry };
109838 - struct path path2 = { new_dir->mnt, new_dentry };
109839 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109840 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109841 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109842 }
109843
109844 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109845 struct path *new_parent,
109846 struct dentry *new_dentry)
109847 {
109848 - struct path path1 = { old_parent->mnt, old_dentry };
109849 - struct path path2 = { new_parent->mnt, new_dentry };
109850 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109851 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109852 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109853 }
109854
109855 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109856 */
109857 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109858 {
109859 - struct path path = { mnt, mnt->mnt_root };
109860 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109861 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109862 }
109863
109864 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109865 * tomoyo_security_ops is a "struct security_operations" which is used for
109866 * registering TOMOYO.
109867 */
109868 -static struct security_operations tomoyo_security_ops = {
109869 +static struct security_operations tomoyo_security_ops __read_only = {
109870 .name = "tomoyo",
109871 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109872 .cred_prepare = tomoyo_cred_prepare,
109873 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109874 index 20ef514..4182bed 100644
109875 --- a/security/yama/Kconfig
109876 +++ b/security/yama/Kconfig
109877 @@ -1,6 +1,6 @@
109878 config SECURITY_YAMA
109879 bool "Yama support"
109880 - depends on SECURITY
109881 + depends on SECURITY && !GRKERNSEC
109882 select SECURITYFS
109883 select SECURITY_PATH
109884 default n
109885 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109886 index 13c88fbc..f8c115e 100644
109887 --- a/security/yama/yama_lsm.c
109888 +++ b/security/yama/yama_lsm.c
109889 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109890 }
109891
109892 #ifndef CONFIG_SECURITY_YAMA_STACKED
109893 -static struct security_operations yama_ops = {
109894 +static struct security_operations yama_ops __read_only = {
109895 .name = "yama",
109896
109897 .ptrace_access_check = yama_ptrace_access_check,
109898 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109899 #endif
109900
109901 #ifdef CONFIG_SYSCTL
109902 +static int zero __read_only;
109903 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109904 +
109905 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109906 void __user *buffer, size_t *lenp, loff_t *ppos)
109907 {
109908 - int rc;
109909 + ctl_table_no_const yama_table;
109910
109911 if (write && !capable(CAP_SYS_PTRACE))
109912 return -EPERM;
109913
109914 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109915 - if (rc)
109916 - return rc;
109917 -
109918 + yama_table = *table;
109919 /* Lock the max value if it ever gets set. */
109920 - if (write && *(int *)table->data == *(int *)table->extra2)
109921 - table->extra1 = table->extra2;
109922 -
109923 - return rc;
109924 + if (ptrace_scope == max_scope)
109925 + yama_table.extra1 = &max_scope;
109926 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109927 }
109928
109929 -static int zero;
109930 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109931 -
109932 struct ctl_path yama_sysctl_path[] = {
109933 { .procname = "kernel", },
109934 { .procname = "yama", },
109935 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109936 index 401107b..b9c47c6 100644
109937 --- a/sound/aoa/codecs/onyx.c
109938 +++ b/sound/aoa/codecs/onyx.c
109939 @@ -54,7 +54,7 @@ struct onyx {
109940 spdif_locked:1,
109941 analog_locked:1,
109942 original_mute:2;
109943 - int open_count;
109944 + local_t open_count;
109945 struct codec_info *codec_info;
109946
109947 /* mutex serializes concurrent access to the device
109948 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109949 struct onyx *onyx = cii->codec_data;
109950
109951 mutex_lock(&onyx->mutex);
109952 - onyx->open_count++;
109953 + local_inc(&onyx->open_count);
109954 mutex_unlock(&onyx->mutex);
109955
109956 return 0;
109957 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109958 struct onyx *onyx = cii->codec_data;
109959
109960 mutex_lock(&onyx->mutex);
109961 - onyx->open_count--;
109962 - if (!onyx->open_count)
109963 + if (local_dec_and_test(&onyx->open_count))
109964 onyx->spdif_locked = onyx->analog_locked = 0;
109965 mutex_unlock(&onyx->mutex);
109966
109967 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109968 index ffd2025..df062c9 100644
109969 --- a/sound/aoa/codecs/onyx.h
109970 +++ b/sound/aoa/codecs/onyx.h
109971 @@ -11,6 +11,7 @@
109972 #include <linux/i2c.h>
109973 #include <asm/pmac_low_i2c.h>
109974 #include <asm/prom.h>
109975 +#include <asm/local.h>
109976
109977 /* PCM3052 register definitions */
109978
109979 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109980 index ada69d7..5f65386 100644
109981 --- a/sound/core/oss/pcm_oss.c
109982 +++ b/sound/core/oss/pcm_oss.c
109983 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109984 if (in_kernel) {
109985 mm_segment_t fs;
109986 fs = snd_enter_user();
109987 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109988 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109989 snd_leave_user(fs);
109990 } else {
109991 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109992 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109993 }
109994 if (ret != -EPIPE && ret != -ESTRPIPE)
109995 break;
109996 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109997 if (in_kernel) {
109998 mm_segment_t fs;
109999 fs = snd_enter_user();
110000 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110001 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110002 snd_leave_user(fs);
110003 } else {
110004 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110005 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110006 }
110007 if (ret == -EPIPE) {
110008 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
110009 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
110010 struct snd_pcm_plugin_channel *channels;
110011 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
110012 if (!in_kernel) {
110013 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
110014 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
110015 return -EFAULT;
110016 buf = runtime->oss.buffer;
110017 }
110018 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
110019 }
110020 } else {
110021 tmp = snd_pcm_oss_write2(substream,
110022 - (const char __force *)buf,
110023 + (const char __force_kernel *)buf,
110024 runtime->oss.period_bytes, 0);
110025 if (tmp <= 0)
110026 goto err;
110027 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
110028 struct snd_pcm_runtime *runtime = substream->runtime;
110029 snd_pcm_sframes_t frames, frames1;
110030 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
110031 - char __user *final_dst = (char __force __user *)buf;
110032 + char __user *final_dst = (char __force_user *)buf;
110033 if (runtime->oss.plugin_first) {
110034 struct snd_pcm_plugin_channel *channels;
110035 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
110036 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
110037 xfer += tmp;
110038 runtime->oss.buffer_used -= tmp;
110039 } else {
110040 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
110041 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
110042 runtime->oss.period_bytes, 0);
110043 if (tmp <= 0)
110044 goto err;
110045 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
110046 size1);
110047 size1 /= runtime->channels; /* frames */
110048 fs = snd_enter_user();
110049 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
110050 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
110051 snd_leave_user(fs);
110052 }
110053 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
110054 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
110055 index 2d957ba..fda022c 100644
110056 --- a/sound/core/pcm_compat.c
110057 +++ b/sound/core/pcm_compat.c
110058 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
110059 int err;
110060
110061 fs = snd_enter_user();
110062 - err = snd_pcm_delay(substream, &delay);
110063 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
110064 snd_leave_user(fs);
110065 if (err < 0)
110066 return err;
110067 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
110068 index a95356f..0f5eabf 100644
110069 --- a/sound/core/pcm_native.c
110070 +++ b/sound/core/pcm_native.c
110071 @@ -2815,11 +2815,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
110072 switch (substream->stream) {
110073 case SNDRV_PCM_STREAM_PLAYBACK:
110074 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
110075 - (void __user *)arg);
110076 + (void __force_user *)arg);
110077 break;
110078 case SNDRV_PCM_STREAM_CAPTURE:
110079 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
110080 - (void __user *)arg);
110081 + (void __force_user *)arg);
110082 break;
110083 default:
110084 result = -EINVAL;
110085 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
110086 index 16d4267..fe8b49b 100644
110087 --- a/sound/core/seq/oss/seq_oss.c
110088 +++ b/sound/core/seq/oss/seq_oss.c
110089 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
110090 {
110091 int rc;
110092 static struct snd_seq_dev_ops ops = {
110093 - snd_seq_oss_synth_register,
110094 - snd_seq_oss_synth_unregister,
110095 + .init_device = snd_seq_oss_synth_register,
110096 + .free_device = snd_seq_oss_synth_unregister,
110097 };
110098
110099 snd_seq_autoload_lock();
110100 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
110101 index 91a786a..4c07ed4 100644
110102 --- a/sound/core/seq/seq_device.c
110103 +++ b/sound/core/seq/seq_device.c
110104 @@ -64,7 +64,7 @@ struct ops_list {
110105 int argsize; /* argument size */
110106
110107 /* operators */
110108 - struct snd_seq_dev_ops ops;
110109 + struct snd_seq_dev_ops *ops;
110110
110111 /* registered devices */
110112 struct list_head dev_list; /* list of devices */
110113 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
110114
110115 mutex_lock(&ops->reg_mutex);
110116 /* copy driver operators */
110117 - ops->ops = *entry;
110118 + ops->ops = entry;
110119 ops->driver |= DRIVER_LOADED;
110120 ops->argsize = argsize;
110121
110122 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
110123 dev->name, ops->id, ops->argsize, dev->argsize);
110124 return -EINVAL;
110125 }
110126 - if (ops->ops.init_device(dev) >= 0) {
110127 + if (ops->ops->init_device(dev) >= 0) {
110128 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
110129 ops->num_init_devices++;
110130 } else {
110131 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
110132 dev->name, ops->id, ops->argsize, dev->argsize);
110133 return -EINVAL;
110134 }
110135 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
110136 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
110137 dev->status = SNDRV_SEQ_DEVICE_FREE;
110138 dev->driver_data = NULL;
110139 ops->num_init_devices--;
110140 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
110141 index a1fd77a..69cd659 100644
110142 --- a/sound/core/seq/seq_midi.c
110143 +++ b/sound/core/seq/seq_midi.c
110144 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
110145 static int __init alsa_seq_midi_init(void)
110146 {
110147 static struct snd_seq_dev_ops ops = {
110148 - snd_seq_midisynth_register_port,
110149 - snd_seq_midisynth_unregister_port,
110150 + .init_device = snd_seq_midisynth_register_port,
110151 + .free_device = snd_seq_midisynth_unregister_port,
110152 };
110153 memset(&synths, 0, sizeof(synths));
110154 snd_seq_autoload_lock();
110155 diff --git a/sound/core/sound.c b/sound/core/sound.c
110156 index 38ad1a0..5010a40 100644
110157 --- a/sound/core/sound.c
110158 +++ b/sound/core/sound.c
110159 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
110160 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
110161 default: return;
110162 }
110163 - request_module(str);
110164 + request_module("%s", str);
110165 }
110166
110167 #endif /* modular kernel */
110168 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
110169 index f5fd448..6ae276da 100644
110170 --- a/sound/drivers/mts64.c
110171 +++ b/sound/drivers/mts64.c
110172 @@ -29,6 +29,7 @@
110173 #include <sound/initval.h>
110174 #include <sound/rawmidi.h>
110175 #include <sound/control.h>
110176 +#include <asm/local.h>
110177
110178 #define CARD_NAME "Miditerminal 4140"
110179 #define DRIVER_NAME "MTS64"
110180 @@ -67,7 +68,7 @@ struct mts64 {
110181 struct pardevice *pardev;
110182 int pardev_claimed;
110183
110184 - int open_count;
110185 + local_t open_count;
110186 int current_midi_output_port;
110187 int current_midi_input_port;
110188 u8 mode[MTS64_NUM_INPUT_PORTS];
110189 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110190 {
110191 struct mts64 *mts = substream->rmidi->private_data;
110192
110193 - if (mts->open_count == 0) {
110194 + if (local_read(&mts->open_count) == 0) {
110195 /* We don't need a spinlock here, because this is just called
110196 if the device has not been opened before.
110197 So there aren't any IRQs from the device */
110198 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110199
110200 msleep(50);
110201 }
110202 - ++(mts->open_count);
110203 + local_inc(&mts->open_count);
110204
110205 return 0;
110206 }
110207 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110208 struct mts64 *mts = substream->rmidi->private_data;
110209 unsigned long flags;
110210
110211 - --(mts->open_count);
110212 - if (mts->open_count == 0) {
110213 + if (local_dec_return(&mts->open_count) == 0) {
110214 /* We need the spinlock_irqsave here because we can still
110215 have IRQs at this point */
110216 spin_lock_irqsave(&mts->lock, flags);
110217 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110218
110219 msleep(500);
110220
110221 - } else if (mts->open_count < 0)
110222 - mts->open_count = 0;
110223 + } else if (local_read(&mts->open_count) < 0)
110224 + local_set(&mts->open_count, 0);
110225
110226 return 0;
110227 }
110228 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
110229 index 6839953..7a0f4b9 100644
110230 --- a/sound/drivers/opl3/opl3_seq.c
110231 +++ b/sound/drivers/opl3/opl3_seq.c
110232 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
110233 {
110234 static struct snd_seq_dev_ops ops =
110235 {
110236 - snd_opl3_seq_new_device,
110237 - snd_opl3_seq_delete_device
110238 + .init_device = snd_opl3_seq_new_device,
110239 + .free_device = snd_opl3_seq_delete_device
110240 };
110241
110242 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
110243 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
110244 index b953fb4..1999c01 100644
110245 --- a/sound/drivers/opl4/opl4_lib.c
110246 +++ b/sound/drivers/opl4/opl4_lib.c
110247 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
110248 MODULE_DESCRIPTION("OPL4 driver");
110249 MODULE_LICENSE("GPL");
110250
110251 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
110252 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
110253 {
110254 int timeout = 10;
110255 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
110256 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
110257 index 9919769..d7de36c 100644
110258 --- a/sound/drivers/opl4/opl4_seq.c
110259 +++ b/sound/drivers/opl4/opl4_seq.c
110260 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
110261 static int __init alsa_opl4_synth_init(void)
110262 {
110263 static struct snd_seq_dev_ops ops = {
110264 - snd_opl4_seq_new_device,
110265 - snd_opl4_seq_delete_device
110266 + .init_device = snd_opl4_seq_new_device,
110267 + .free_device = snd_opl4_seq_delete_device
110268 };
110269
110270 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
110271 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
110272 index 78ccfa4..7a0857b 100644
110273 --- a/sound/drivers/portman2x4.c
110274 +++ b/sound/drivers/portman2x4.c
110275 @@ -48,6 +48,7 @@
110276 #include <sound/initval.h>
110277 #include <sound/rawmidi.h>
110278 #include <sound/control.h>
110279 +#include <asm/local.h>
110280
110281 #define CARD_NAME "Portman 2x4"
110282 #define DRIVER_NAME "portman"
110283 @@ -85,7 +86,7 @@ struct portman {
110284 struct pardevice *pardev;
110285 int pardev_claimed;
110286
110287 - int open_count;
110288 + local_t open_count;
110289 int mode[PORTMAN_NUM_INPUT_PORTS];
110290 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
110291 };
110292 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
110293 index 95fc2eaf..ea5d6a7 100644
110294 --- a/sound/firewire/amdtp.c
110295 +++ b/sound/firewire/amdtp.c
110296 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
110297 ptr = s->pcm_buffer_pointer + frames;
110298 if (ptr >= pcm->runtime->buffer_size)
110299 ptr -= pcm->runtime->buffer_size;
110300 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
110301 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
110302
110303 s->pcm_period_pointer += frames;
110304 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
110305 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
110306 */
110307 void amdtp_stream_update(struct amdtp_stream *s)
110308 {
110309 - ACCESS_ONCE(s->source_node_id_field) =
110310 + ACCESS_ONCE_RW(s->source_node_id_field) =
110311 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
110312 }
110313 EXPORT_SYMBOL(amdtp_stream_update);
110314 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
110315 index 4823c08..47a5f7c 100644
110316 --- a/sound/firewire/amdtp.h
110317 +++ b/sound/firewire/amdtp.h
110318 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110319 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110320 struct snd_pcm_substream *pcm)
110321 {
110322 - ACCESS_ONCE(s->pcm) = pcm;
110323 + ACCESS_ONCE_RW(s->pcm) = pcm;
110324 }
110325
110326 /**
110327 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110328 struct snd_rawmidi_substream *midi)
110329 {
110330 if (port < s->midi_ports)
110331 - ACCESS_ONCE(s->midi[port]) = midi;
110332 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110333 }
110334
110335 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110336 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110337 index 7ac9443..0ec6274 100644
110338 --- a/sound/firewire/isight.c
110339 +++ b/sound/firewire/isight.c
110340 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110341 ptr += count;
110342 if (ptr >= runtime->buffer_size)
110343 ptr -= runtime->buffer_size;
110344 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110345 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110346
110347 isight->period_counter += count;
110348 if (isight->period_counter >= runtime->period_size) {
110349 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110350 if (err < 0)
110351 return err;
110352
110353 - ACCESS_ONCE(isight->pcm_active) = true;
110354 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110355
110356 return 0;
110357 }
110358 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110359 {
110360 struct isight *isight = substream->private_data;
110361
110362 - ACCESS_ONCE(isight->pcm_active) = false;
110363 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110364
110365 mutex_lock(&isight->mutex);
110366 isight_stop_streaming(isight);
110367 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110368
110369 switch (cmd) {
110370 case SNDRV_PCM_TRIGGER_START:
110371 - ACCESS_ONCE(isight->pcm_running) = true;
110372 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110373 break;
110374 case SNDRV_PCM_TRIGGER_STOP:
110375 - ACCESS_ONCE(isight->pcm_running) = false;
110376 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110377 break;
110378 default:
110379 return -EINVAL;
110380 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110381 index 2dba848..c682aef 100644
110382 --- a/sound/firewire/scs1x.c
110383 +++ b/sound/firewire/scs1x.c
110384 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110385 {
110386 struct scs *scs = stream->rmidi->private_data;
110387
110388 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110389 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110390 if (up) {
110391 scs->output_idle = false;
110392 tasklet_schedule(&scs->tasklet);
110393 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110394 {
110395 struct scs *scs = stream->rmidi->private_data;
110396
110397 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110398 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110399 }
110400
110401 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110402 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110403
110404 snd_card_disconnect(scs->card);
110405
110406 - ACCESS_ONCE(scs->output) = NULL;
110407 - ACCESS_ONCE(scs->input) = NULL;
110408 + ACCESS_ONCE_RW(scs->output) = NULL;
110409 + ACCESS_ONCE_RW(scs->input) = NULL;
110410
110411 wait_event(scs->idle_wait, scs->output_idle);
110412
110413 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110414 index 4e3fcfb..ab45a9d 100644
110415 --- a/sound/isa/sb/emu8000_synth.c
110416 +++ b/sound/isa/sb/emu8000_synth.c
110417 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110418 {
110419
110420 static struct snd_seq_dev_ops ops = {
110421 - snd_emu8000_new_device,
110422 - snd_emu8000_delete_device,
110423 + .init_device = snd_emu8000_new_device,
110424 + .free_device = snd_emu8000_delete_device,
110425 };
110426 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110427 sizeof(struct snd_emu8000*));
110428 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110429 index 048439a..3be9f6f 100644
110430 --- a/sound/oss/sb_audio.c
110431 +++ b/sound/oss/sb_audio.c
110432 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110433 buf16 = (signed short *)(localbuf + localoffs);
110434 while (c)
110435 {
110436 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110437 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110438 if (copy_from_user(lbuf8,
110439 userbuf+useroffs + p,
110440 locallen))
110441 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110442 index a33e8ce..2262303 100644
110443 --- a/sound/oss/swarm_cs4297a.c
110444 +++ b/sound/oss/swarm_cs4297a.c
110445 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110446 {
110447 struct cs4297a_state *s;
110448 u32 pwr, id;
110449 - mm_segment_t fs;
110450 int rval;
110451 u64 cfg;
110452 int mdio_val;
110453 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110454 if (!rval) {
110455 char *sb1250_duart_present;
110456
110457 +#if 0
110458 + mm_segment_t fs;
110459 fs = get_fs();
110460 set_fs(KERNEL_DS);
110461 -#if 0
110462 val = SOUND_MASK_LINE;
110463 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110464 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110465 val = initvol[i].vol;
110466 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110467 }
110468 + set_fs(fs);
110469 // cs4297a_write_ac97(s, 0x18, 0x0808);
110470 #else
110471 // cs4297a_write_ac97(s, 0x5e, 0x180);
110472 cs4297a_write_ac97(s, 0x02, 0x0808);
110473 cs4297a_write_ac97(s, 0x18, 0x0808);
110474 #endif
110475 - set_fs(fs);
110476
110477 list_add(&s->list, &cs4297a_devs);
110478
110479 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110480 index 4c41c90..37f3631 100644
110481 --- a/sound/pci/emu10k1/emu10k1_synth.c
110482 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110483 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110484 {
110485
110486 static struct snd_seq_dev_ops ops = {
110487 - snd_emu10k1_synth_new_device,
110488 - snd_emu10k1_synth_delete_device,
110489 + .init_device = snd_emu10k1_synth_new_device,
110490 + .free_device = snd_emu10k1_synth_delete_device,
110491 };
110492 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110493 sizeof(struct snd_emu10k1_synth_arg));
110494 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110495 index ec6a7d0..4e578f7 100644
110496 --- a/sound/pci/hda/hda_codec.c
110497 +++ b/sound/pci/hda/hda_codec.c
110498 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
110499 mutex_unlock(&preset_mutex);
110500
110501 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110502 - char name[32];
110503 if (!mod_requested)
110504 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110505 - codec->vendor_id);
110506 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110507 else
110508 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110509 - (codec->vendor_id >> 16) & 0xffff);
110510 - request_module(name);
110511 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110512 mod_requested++;
110513 goto again;
110514 }
110515 @@ -2780,7 +2776,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110516 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110517 mm_segment_t fs = get_fs();
110518 set_fs(get_ds());
110519 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110520 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110521 tlv = _tlv;
110522 set_fs(fs);
110523 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110524 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110525 index 4631a23..001ae57 100644
110526 --- a/sound/pci/ymfpci/ymfpci.h
110527 +++ b/sound/pci/ymfpci/ymfpci.h
110528 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110529 spinlock_t reg_lock;
110530 spinlock_t voice_lock;
110531 wait_queue_head_t interrupt_sleep;
110532 - atomic_t interrupt_sleep_count;
110533 + atomic_unchecked_t interrupt_sleep_count;
110534 struct snd_info_entry *proc_entry;
110535 const struct firmware *dsp_microcode;
110536 const struct firmware *controller_microcode;
110537 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110538 index 81c916a..516f0bf 100644
110539 --- a/sound/pci/ymfpci/ymfpci_main.c
110540 +++ b/sound/pci/ymfpci/ymfpci_main.c
110541 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110542 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110543 break;
110544 }
110545 - if (atomic_read(&chip->interrupt_sleep_count)) {
110546 - atomic_set(&chip->interrupt_sleep_count, 0);
110547 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110548 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110549 wake_up(&chip->interrupt_sleep);
110550 }
110551 __end:
110552 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110553 continue;
110554 init_waitqueue_entry(&wait, current);
110555 add_wait_queue(&chip->interrupt_sleep, &wait);
110556 - atomic_inc(&chip->interrupt_sleep_count);
110557 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110558 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110559 remove_wait_queue(&chip->interrupt_sleep, &wait);
110560 }
110561 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110562 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110563 spin_unlock(&chip->reg_lock);
110564
110565 - if (atomic_read(&chip->interrupt_sleep_count)) {
110566 - atomic_set(&chip->interrupt_sleep_count, 0);
110567 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110568 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110569 wake_up(&chip->interrupt_sleep);
110570 }
110571 }
110572 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110573 spin_lock_init(&chip->reg_lock);
110574 spin_lock_init(&chip->voice_lock);
110575 init_waitqueue_head(&chip->interrupt_sleep);
110576 - atomic_set(&chip->interrupt_sleep_count, 0);
110577 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110578 chip->card = card;
110579 chip->pci = pci;
110580 chip->irq = -1;
110581 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110582 index a3e0a0d..ab98399 100644
110583 --- a/sound/soc/soc-core.c
110584 +++ b/sound/soc/soc-core.c
110585 @@ -2286,8 +2286,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110586 if (ret)
110587 return ret;
110588
110589 - ops->warm_reset = snd_soc_ac97_warm_reset;
110590 - ops->reset = snd_soc_ac97_reset;
110591 + pax_open_kernel();
110592 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110593 + *(void **)&ops->reset = snd_soc_ac97_reset;
110594 + pax_close_kernel();
110595
110596 snd_ac97_rst_cfg = cfg;
110597 return 0;
110598 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110599 index 7778b8e..3d619fc 100644
110600 --- a/sound/synth/emux/emux_seq.c
110601 +++ b/sound/synth/emux/emux_seq.c
110602 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110603 * MIDI emulation operators
110604 */
110605 static struct snd_midi_op emux_ops = {
110606 - snd_emux_note_on,
110607 - snd_emux_note_off,
110608 - snd_emux_key_press,
110609 - snd_emux_terminate_note,
110610 - snd_emux_control,
110611 - snd_emux_nrpn,
110612 - snd_emux_sysex,
110613 + .note_on = snd_emux_note_on,
110614 + .note_off = snd_emux_note_off,
110615 + .key_press = snd_emux_key_press,
110616 + .note_terminate = snd_emux_terminate_note,
110617 + .control = snd_emux_control,
110618 + .nrpn = snd_emux_nrpn,
110619 + .sysex = snd_emux_sysex,
110620 };
110621
110622
110623 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110624 new file mode 100644
110625 index 0000000..de92ed9
110626 --- /dev/null
110627 +++ b/tools/gcc/.gitignore
110628 @@ -0,0 +1 @@
110629 +randomize_layout_seed.h
110630 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110631 new file mode 100644
110632 index 0000000..7b8921f
110633 --- /dev/null
110634 +++ b/tools/gcc/Makefile
110635 @@ -0,0 +1,52 @@
110636 +#CC := gcc
110637 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110638 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110639 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110640 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110641 +
110642 +ifeq ($(PLUGINCC),$(HOSTCC))
110643 +HOSTLIBS := hostlibs
110644 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110645 +export HOST_EXTRACFLAGS
110646 +else
110647 +HOSTLIBS := hostcxxlibs
110648 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110649 +export HOST_EXTRACXXFLAGS
110650 +endif
110651 +
110652 +export GCCPLUGINS_DIR HOSTLIBS
110653 +
110654 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110655 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110656 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110657 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110658 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110659 +$(HOSTLIBS)-y += colorize_plugin.so
110660 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110661 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110662 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110663 +
110664 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110665 +subdir- += size_overflow_plugin
110666 +
110667 +always := $($(HOSTLIBS)-y)
110668 +
110669 +constify_plugin-objs := constify_plugin.o
110670 +stackleak_plugin-objs := stackleak_plugin.o
110671 +kallocstat_plugin-objs := kallocstat_plugin.o
110672 +kernexec_plugin-objs := kernexec_plugin.o
110673 +checker_plugin-objs := checker_plugin.o
110674 +colorize_plugin-objs := colorize_plugin.o
110675 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110676 +structleak_plugin-objs := structleak_plugin.o
110677 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110678 +
110679 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110680 +
110681 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110682 + cmd_create_randomize_layout_seed = \
110683 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110684 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110685 + $(call if_changed,create_randomize_layout_seed)
110686 +
110687 +targets += randomize_layout_seed.h randomize_layout_hash.h
110688 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110689 new file mode 100644
110690 index 0000000..5452feea
110691 --- /dev/null
110692 +++ b/tools/gcc/checker_plugin.c
110693 @@ -0,0 +1,150 @@
110694 +/*
110695 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110696 + * Licensed under the GPL v2
110697 + *
110698 + * Note: the choice of the license means that the compilation process is
110699 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110700 + * but for the kernel it doesn't matter since it doesn't link against
110701 + * any of the gcc libraries
110702 + *
110703 + * gcc plugin to implement various sparse (source code checker) features
110704 + *
110705 + * TODO:
110706 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110707 + *
110708 + * BUGS:
110709 + * - none known
110710 + */
110711 +
110712 +#include "gcc-common.h"
110713 +
110714 +extern void c_register_addr_space (const char *str, addr_space_t as);
110715 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110716 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110717 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110718 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110719 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110720 +
110721 +int plugin_is_GPL_compatible;
110722 +
110723 +static struct plugin_info checker_plugin_info = {
110724 + .version = "201304082245",
110725 + .help = NULL,
110726 +};
110727 +
110728 +#define ADDR_SPACE_KERNEL 0
110729 +#define ADDR_SPACE_FORCE_KERNEL 1
110730 +#define ADDR_SPACE_USER 2
110731 +#define ADDR_SPACE_FORCE_USER 3
110732 +#define ADDR_SPACE_IOMEM 0
110733 +#define ADDR_SPACE_FORCE_IOMEM 0
110734 +#define ADDR_SPACE_PERCPU 0
110735 +#define ADDR_SPACE_FORCE_PERCPU 0
110736 +#define ADDR_SPACE_RCU 0
110737 +#define ADDR_SPACE_FORCE_RCU 0
110738 +
110739 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110740 +{
110741 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110742 +}
110743 +
110744 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110745 +{
110746 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110747 +}
110748 +
110749 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110750 +{
110751 + return default_addr_space_valid_pointer_mode(mode, as);
110752 +}
110753 +
110754 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110755 +{
110756 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110757 +}
110758 +
110759 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110760 +{
110761 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110762 +}
110763 +
110764 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110765 +{
110766 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110767 + return true;
110768 +
110769 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110770 + return true;
110771 +
110772 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110773 + return true;
110774 +
110775 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110776 + return true;
110777 +
110778 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110779 + return true;
110780 +
110781 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110782 + return true;
110783 +
110784 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110785 + return true;
110786 +
110787 + return subset == superset;
110788 +}
110789 +
110790 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110791 +{
110792 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110793 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110794 +
110795 + return op;
110796 +}
110797 +
110798 +static void register_checker_address_spaces(void *event_data, void *data)
110799 +{
110800 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110801 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110802 + c_register_addr_space("__user", ADDR_SPACE_USER);
110803 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110804 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110805 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110806 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110807 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110808 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110809 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110810 +
110811 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110812 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110813 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110814 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110815 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110816 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110817 + targetm.addr_space.convert = checker_addr_space_convert;
110818 +}
110819 +
110820 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110821 +{
110822 + const char * const plugin_name = plugin_info->base_name;
110823 + const int argc = plugin_info->argc;
110824 + const struct plugin_argument * const argv = plugin_info->argv;
110825 + int i;
110826 +
110827 + if (!plugin_default_version_check(version, &gcc_version)) {
110828 + error(G_("incompatible gcc/plugin versions"));
110829 + return 1;
110830 + }
110831 +
110832 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110833 +
110834 + for (i = 0; i < argc; ++i)
110835 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110836 +
110837 + if (TARGET_64BIT == 0)
110838 + return 0;
110839 +
110840 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110841 +
110842 + return 0;
110843 +}
110844 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110845 new file mode 100644
110846 index 0000000..54461af
110847 --- /dev/null
110848 +++ b/tools/gcc/colorize_plugin.c
110849 @@ -0,0 +1,210 @@
110850 +/*
110851 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110852 + * Licensed under the GPL v2
110853 + *
110854 + * Note: the choice of the license means that the compilation process is
110855 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110856 + * but for the kernel it doesn't matter since it doesn't link against
110857 + * any of the gcc libraries
110858 + *
110859 + * gcc plugin to colorize diagnostic output
110860 + *
110861 + */
110862 +
110863 +#include "gcc-common.h"
110864 +
110865 +int plugin_is_GPL_compatible;
110866 +
110867 +static struct plugin_info colorize_plugin_info = {
110868 + .version = "201404202350",
110869 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110870 +};
110871 +
110872 +#define GREEN "\033[32m\033[K"
110873 +#define LIGHTGREEN "\033[1;32m\033[K"
110874 +#define YELLOW "\033[33m\033[K"
110875 +#define LIGHTYELLOW "\033[1;33m\033[K"
110876 +#define RED "\033[31m\033[K"
110877 +#define LIGHTRED "\033[1;31m\033[K"
110878 +#define BLUE "\033[34m\033[K"
110879 +#define LIGHTBLUE "\033[1;34m\033[K"
110880 +#define BRIGHT "\033[1;m\033[K"
110881 +#define NORMAL "\033[m\033[K"
110882 +
110883 +static diagnostic_starter_fn old_starter;
110884 +static diagnostic_finalizer_fn old_finalizer;
110885 +
110886 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110887 +{
110888 + const char *color;
110889 + char *newprefix;
110890 +
110891 + switch (diagnostic->kind) {
110892 + case DK_NOTE:
110893 + color = LIGHTBLUE;
110894 + break;
110895 +
110896 + case DK_PEDWARN:
110897 + case DK_WARNING:
110898 + color = LIGHTYELLOW;
110899 + break;
110900 +
110901 + case DK_ERROR:
110902 + case DK_FATAL:
110903 + case DK_ICE:
110904 + case DK_PERMERROR:
110905 + case DK_SORRY:
110906 + color = LIGHTRED;
110907 + break;
110908 +
110909 + default:
110910 + color = NORMAL;
110911 + }
110912 +
110913 + old_starter(context, diagnostic);
110914 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110915 + return;
110916 + pp_destroy_prefix(context->printer);
110917 + pp_set_prefix(context->printer, newprefix);
110918 +}
110919 +
110920 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110921 +{
110922 + old_finalizer(context, diagnostic);
110923 +}
110924 +
110925 +static void colorize_arm(void)
110926 +{
110927 + old_starter = diagnostic_starter(global_dc);
110928 + old_finalizer = diagnostic_finalizer(global_dc);
110929 +
110930 + diagnostic_starter(global_dc) = start_colorize;
110931 + diagnostic_finalizer(global_dc) = finalize_colorize;
110932 +}
110933 +
110934 +static unsigned int execute_colorize_rearm(void)
110935 +{
110936 + if (diagnostic_starter(global_dc) == start_colorize)
110937 + return 0;
110938 +
110939 + colorize_arm();
110940 + return 0;
110941 +}
110942 +
110943 +#if BUILDING_GCC_VERSION >= 4009
110944 +static const struct pass_data colorize_rearm_pass_data = {
110945 +#else
110946 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110947 + .pass = {
110948 +#endif
110949 + .type = SIMPLE_IPA_PASS,
110950 + .name = "colorize_rearm",
110951 +#if BUILDING_GCC_VERSION >= 4008
110952 + .optinfo_flags = OPTGROUP_NONE,
110953 +#endif
110954 +#if BUILDING_GCC_VERSION >= 4009
110955 + .has_gate = false,
110956 + .has_execute = true,
110957 +#else
110958 + .gate = NULL,
110959 + .execute = execute_colorize_rearm,
110960 + .sub = NULL,
110961 + .next = NULL,
110962 + .static_pass_number = 0,
110963 +#endif
110964 + .tv_id = TV_NONE,
110965 + .properties_required = 0,
110966 + .properties_provided = 0,
110967 + .properties_destroyed = 0,
110968 + .todo_flags_start = 0,
110969 + .todo_flags_finish = 0
110970 +#if BUILDING_GCC_VERSION < 4009
110971 + }
110972 +#endif
110973 +};
110974 +
110975 +#if BUILDING_GCC_VERSION >= 4009
110976 +namespace {
110977 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110978 +public:
110979 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110980 + unsigned int execute() { return execute_colorize_rearm(); }
110981 +};
110982 +}
110983 +
110984 +static opt_pass *make_colorize_rearm_pass(void)
110985 +{
110986 + return new colorize_rearm_pass();
110987 +}
110988 +#else
110989 +static struct opt_pass *make_colorize_rearm_pass(void)
110990 +{
110991 + return &colorize_rearm_pass.pass;
110992 +}
110993 +#endif
110994 +
110995 +static void colorize_start_unit(void *gcc_data, void *user_data)
110996 +{
110997 + colorize_arm();
110998 +}
110999 +
111000 +static bool should_colorize(void)
111001 +{
111002 +#if BUILDING_GCC_VERSION >= 4009
111003 + return false;
111004 +#else
111005 + char const *t = getenv("TERM");
111006 +
111007 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
111008 +#endif
111009 +}
111010 +
111011 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111012 +{
111013 + const char * const plugin_name = plugin_info->base_name;
111014 + const int argc = plugin_info->argc;
111015 + const struct plugin_argument * const argv = plugin_info->argv;
111016 + int i;
111017 + struct register_pass_info colorize_rearm_pass_info;
111018 + bool colorize;
111019 +
111020 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
111021 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
111022 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
111023 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111024 +
111025 + if (!plugin_default_version_check(version, &gcc_version)) {
111026 + error(G_("incompatible gcc/plugin versions"));
111027 + return 1;
111028 + }
111029 +
111030 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
111031 +
111032 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
111033 +
111034 + for (i = 0; i < argc; ++i) {
111035 + if (!strcmp(argv[i].key, "color")) {
111036 + if (!argv[i].value) {
111037 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111038 + continue;
111039 + }
111040 + if (!strcmp(argv[i].value, "always"))
111041 + colorize = true;
111042 + else if (!strcmp(argv[i].value, "never"))
111043 + colorize = false;
111044 + else if (!strcmp(argv[i].value, "auto"))
111045 + colorize = should_colorize();
111046 + else
111047 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111048 + continue;
111049 + }
111050 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111051 + }
111052 +
111053 + if (colorize) {
111054 + // TODO: parse GCC_COLORS as used by gcc 4.9+
111055 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
111056 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
111057 + }
111058 + return 0;
111059 +}
111060 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
111061 new file mode 100644
111062 index 0000000..82bc5a8
111063 --- /dev/null
111064 +++ b/tools/gcc/constify_plugin.c
111065 @@ -0,0 +1,557 @@
111066 +/*
111067 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
111068 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
111069 + * Licensed under the GPL v2, or (at your option) v3
111070 + *
111071 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
111072 + *
111073 + * Homepage:
111074 + * http://www.grsecurity.net/~ephox/const_plugin/
111075 + *
111076 + * Usage:
111077 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
111078 + * $ gcc -fplugin=constify_plugin.so test.c -O2
111079 + */
111080 +
111081 +#include "gcc-common.h"
111082 +
111083 +// unused C type flag in all versions 4.5-4.9
111084 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
111085 +
111086 +int plugin_is_GPL_compatible;
111087 +
111088 +static struct plugin_info const_plugin_info = {
111089 + .version = "201401270210",
111090 + .help = "no-constify\tturn off constification\n",
111091 +};
111092 +
111093 +typedef struct {
111094 + bool has_fptr_field;
111095 + bool has_writable_field;
111096 + bool has_do_const_field;
111097 + bool has_no_const_field;
111098 +} constify_info;
111099 +
111100 +static const_tree get_field_type(const_tree field)
111101 +{
111102 + return strip_array_types(TREE_TYPE(field));
111103 +}
111104 +
111105 +static bool is_fptr(const_tree field)
111106 +{
111107 + const_tree ptr = get_field_type(field);
111108 +
111109 + if (TREE_CODE(ptr) != POINTER_TYPE)
111110 + return false;
111111 +
111112 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
111113 +}
111114 +
111115 +/*
111116 + * determine whether the given structure type meets the requirements for automatic constification,
111117 + * including the constification attributes on nested structure types
111118 + */
111119 +static void constifiable(const_tree node, constify_info *cinfo)
111120 +{
111121 + const_tree field;
111122 +
111123 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111124 +
111125 + // e.g., pointer to structure fields while still constructing the structure type
111126 + if (TYPE_FIELDS(node) == NULL_TREE)
111127 + return;
111128 +
111129 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
111130 + const_tree type = get_field_type(field);
111131 + enum tree_code code = TREE_CODE(type);
111132 +
111133 + if (node == type)
111134 + continue;
111135 +
111136 + if (is_fptr(field))
111137 + cinfo->has_fptr_field = true;
111138 + else if (!TREE_READONLY(field))
111139 + cinfo->has_writable_field = true;
111140 +
111141 + if (code == RECORD_TYPE || code == UNION_TYPE) {
111142 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111143 + cinfo->has_do_const_field = true;
111144 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
111145 + cinfo->has_no_const_field = true;
111146 + else
111147 + constifiable(type, cinfo);
111148 + }
111149 + }
111150 +}
111151 +
111152 +static bool constified(const_tree node)
111153 +{
111154 + constify_info cinfo = {
111155 + .has_fptr_field = false,
111156 + .has_writable_field = false,
111157 + .has_do_const_field = false,
111158 + .has_no_const_field = false
111159 + };
111160 +
111161 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111162 +
111163 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
111164 +// gcc_assert(!TYPE_READONLY(node));
111165 + return false;
111166 + }
111167 +
111168 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
111169 + gcc_assert(TYPE_READONLY(node));
111170 + return true;
111171 + }
111172 +
111173 + constifiable(node, &cinfo);
111174 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
111175 + return false;
111176 +
111177 + return TYPE_READONLY(node);
111178 +}
111179 +
111180 +static void deconstify_tree(tree node);
111181 +
111182 +static void deconstify_type(tree type)
111183 +{
111184 + tree field;
111185 +
111186 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
111187 +
111188 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111189 + const_tree fieldtype = get_field_type(field);
111190 +
111191 + // special case handling of simple ptr-to-same-array-type members
111192 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
111193 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
111194 +
111195 + if (TREE_TYPE(TREE_TYPE(field)) == type)
111196 + continue;
111197 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
111198 + continue;
111199 + if (!constified(ptrtype))
111200 + continue;
111201 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
111202 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
111203 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
111204 + }
111205 + continue;
111206 + }
111207 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
111208 + continue;
111209 + if (!constified(fieldtype))
111210 + continue;
111211 +
111212 + deconstify_tree(field);
111213 + TREE_READONLY(field) = 0;
111214 + }
111215 + TYPE_READONLY(type) = 0;
111216 + C_TYPE_FIELDS_READONLY(type) = 0;
111217 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111218 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111219 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
111220 + }
111221 +}
111222 +
111223 +static void deconstify_tree(tree node)
111224 +{
111225 + tree old_type, new_type, field;
111226 +
111227 + old_type = TREE_TYPE(node);
111228 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
111229 + node = TREE_TYPE(node) = copy_node(old_type);
111230 + old_type = TREE_TYPE(old_type);
111231 + }
111232 +
111233 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
111234 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
111235 +
111236 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
111237 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
111238 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
111239 + DECL_FIELD_CONTEXT(field) = new_type;
111240 +
111241 + deconstify_type(new_type);
111242 +
111243 + TREE_TYPE(node) = new_type;
111244 +}
111245 +
111246 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111247 +{
111248 + tree type;
111249 + constify_info cinfo = {
111250 + .has_fptr_field = false,
111251 + .has_writable_field = false,
111252 + .has_do_const_field = false,
111253 + .has_no_const_field = false
111254 + };
111255 +
111256 + *no_add_attrs = true;
111257 + if (TREE_CODE(*node) == FUNCTION_DECL) {
111258 + error("%qE attribute does not apply to functions (%qF)", name, *node);
111259 + return NULL_TREE;
111260 + }
111261 +
111262 + if (TREE_CODE(*node) == PARM_DECL) {
111263 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
111264 + return NULL_TREE;
111265 + }
111266 +
111267 + if (TREE_CODE(*node) == VAR_DECL) {
111268 + error("%qE attribute does not apply to variables (%qD)", name, *node);
111269 + return NULL_TREE;
111270 + }
111271 +
111272 + if (TYPE_P(*node)) {
111273 + type = *node;
111274 + } else {
111275 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
111276 + type = TREE_TYPE(*node);
111277 + }
111278 +
111279 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
111280 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
111281 + return NULL_TREE;
111282 + }
111283 +
111284 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
111285 + error("%qE attribute is already applied to the type %qT", name, type);
111286 + return NULL_TREE;
111287 + }
111288 +
111289 + if (TYPE_P(*node)) {
111290 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111291 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
111292 + else
111293 + *no_add_attrs = false;
111294 + return NULL_TREE;
111295 + }
111296 +
111297 + constifiable(type, &cinfo);
111298 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111299 + deconstify_tree(*node);
111300 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
111301 + return NULL_TREE;
111302 + }
111303 +
111304 + error("%qE attribute used on type %qT that is not constified", name, type);
111305 + return NULL_TREE;
111306 +}
111307 +
111308 +static void constify_type(tree type)
111309 +{
111310 + TYPE_READONLY(type) = 1;
111311 + C_TYPE_FIELDS_READONLY(type) = 1;
111312 + TYPE_CONSTIFY_VISITED(type) = 1;
111313 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111314 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
111315 +}
111316 +
111317 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111318 +{
111319 + *no_add_attrs = true;
111320 + if (!TYPE_P(*node)) {
111321 + error("%qE attribute applies to types only (%qD)", name, *node);
111322 + return NULL_TREE;
111323 + }
111324 +
111325 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111326 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111327 + return NULL_TREE;
111328 + }
111329 +
111330 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111331 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111332 + return NULL_TREE;
111333 + }
111334 +
111335 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111336 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111337 + return NULL_TREE;
111338 + }
111339 +
111340 + *no_add_attrs = false;
111341 + return NULL_TREE;
111342 +}
111343 +
111344 +static struct attribute_spec no_const_attr = {
111345 + .name = "no_const",
111346 + .min_length = 0,
111347 + .max_length = 0,
111348 + .decl_required = false,
111349 + .type_required = false,
111350 + .function_type_required = false,
111351 + .handler = handle_no_const_attribute,
111352 +#if BUILDING_GCC_VERSION >= 4007
111353 + .affects_type_identity = true
111354 +#endif
111355 +};
111356 +
111357 +static struct attribute_spec do_const_attr = {
111358 + .name = "do_const",
111359 + .min_length = 0,
111360 + .max_length = 0,
111361 + .decl_required = false,
111362 + .type_required = false,
111363 + .function_type_required = false,
111364 + .handler = handle_do_const_attribute,
111365 +#if BUILDING_GCC_VERSION >= 4007
111366 + .affects_type_identity = true
111367 +#endif
111368 +};
111369 +
111370 +static void register_attributes(void *event_data, void *data)
111371 +{
111372 + register_attribute(&no_const_attr);
111373 + register_attribute(&do_const_attr);
111374 +}
111375 +
111376 +static void finish_type(void *event_data, void *data)
111377 +{
111378 + tree type = (tree)event_data;
111379 + constify_info cinfo = {
111380 + .has_fptr_field = false,
111381 + .has_writable_field = false,
111382 + .has_do_const_field = false,
111383 + .has_no_const_field = false
111384 + };
111385 +
111386 + if (type == NULL_TREE || type == error_mark_node)
111387 + return;
111388 +
111389 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111390 + return;
111391 +
111392 + constifiable(type, &cinfo);
111393 +
111394 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111395 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111396 + deconstify_type(type);
111397 + TYPE_CONSTIFY_VISITED(type) = 1;
111398 + } else
111399 + error("'no_const' attribute used on type %qT that is not constified", type);
111400 + return;
111401 + }
111402 +
111403 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111404 + if (!cinfo.has_writable_field) {
111405 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111406 + return;
111407 + }
111408 + constify_type(type);
111409 + return;
111410 + }
111411 +
111412 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111413 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111414 + error("'do_const' attribute used on type %qT that is constified", type);
111415 + return;
111416 + }
111417 + constify_type(type);
111418 + return;
111419 + }
111420 +
111421 + deconstify_type(type);
111422 + TYPE_CONSTIFY_VISITED(type) = 1;
111423 +}
111424 +
111425 +static void check_global_variables(void *event_data, void *data)
111426 +{
111427 +#if BUILDING_GCC_VERSION >= 4009
111428 + varpool_node *node;
111429 +#else
111430 + struct varpool_node *node;
111431 +#endif
111432 +
111433 + FOR_EACH_VARIABLE(node) {
111434 + tree var = NODE_DECL(node);
111435 + tree type = TREE_TYPE(var);
111436 +
111437 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111438 + continue;
111439 +
111440 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111441 + continue;
111442 +
111443 + if (!TYPE_CONSTIFY_VISITED(type))
111444 + continue;
111445 +
111446 + if (DECL_EXTERNAL(var))
111447 + continue;
111448 +
111449 + if (DECL_INITIAL(var))
111450 + continue;
111451 +
111452 + // this works around a gcc bug/feature where uninitialized globals
111453 + // are moved into the .bss section regardless of any constification
111454 + DECL_INITIAL(var) = build_constructor(type, NULL);
111455 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111456 + }
111457 +}
111458 +
111459 +static unsigned int check_local_variables(void)
111460 +{
111461 + unsigned int ret = 0;
111462 + tree var;
111463 +
111464 + unsigned int i;
111465 +
111466 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111467 + tree type = TREE_TYPE(var);
111468 +
111469 + gcc_assert(DECL_P(var));
111470 + if (is_global_var(var))
111471 + continue;
111472 +
111473 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111474 + continue;
111475 +
111476 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111477 + continue;
111478 +
111479 + if (!TYPE_CONSTIFY_VISITED(type))
111480 + continue;
111481 +
111482 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111483 + ret = 1;
111484 + }
111485 + return ret;
111486 +}
111487 +
111488 +#if BUILDING_GCC_VERSION >= 4009
111489 +static const struct pass_data check_local_variables_pass_data = {
111490 +#else
111491 +static struct gimple_opt_pass check_local_variables_pass = {
111492 + .pass = {
111493 +#endif
111494 + .type = GIMPLE_PASS,
111495 + .name = "check_local_variables",
111496 +#if BUILDING_GCC_VERSION >= 4008
111497 + .optinfo_flags = OPTGROUP_NONE,
111498 +#endif
111499 +#if BUILDING_GCC_VERSION >= 4009
111500 + .has_gate = false,
111501 + .has_execute = true,
111502 +#else
111503 + .gate = NULL,
111504 + .execute = check_local_variables,
111505 + .sub = NULL,
111506 + .next = NULL,
111507 + .static_pass_number = 0,
111508 +#endif
111509 + .tv_id = TV_NONE,
111510 + .properties_required = 0,
111511 + .properties_provided = 0,
111512 + .properties_destroyed = 0,
111513 + .todo_flags_start = 0,
111514 + .todo_flags_finish = 0
111515 +#if BUILDING_GCC_VERSION < 4009
111516 + }
111517 +#endif
111518 +};
111519 +
111520 +#if BUILDING_GCC_VERSION >= 4009
111521 +namespace {
111522 +class check_local_variables_pass : public gimple_opt_pass {
111523 +public:
111524 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111525 + unsigned int execute() { return check_local_variables(); }
111526 +};
111527 +}
111528 +
111529 +static opt_pass *make_check_local_variables_pass(void)
111530 +{
111531 + return new check_local_variables_pass();
111532 +}
111533 +#else
111534 +static struct opt_pass *make_check_local_variables_pass(void)
111535 +{
111536 + return &check_local_variables_pass.pass;
111537 +}
111538 +#endif
111539 +
111540 +static struct {
111541 + const char *name;
111542 + const char *asm_op;
111543 +} sections[] = {
111544 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111545 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111546 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111547 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111548 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111549 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111550 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111551 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111552 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111553 +};
111554 +
111555 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111556 +
111557 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111558 +{
111559 + size_t i;
111560 +
111561 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111562 + if (!strcmp(sections[i].name, name))
111563 + return 0;
111564 + return old_section_type_flags(decl, name, reloc);
111565 +}
111566 +
111567 +static void constify_start_unit(void *gcc_data, void *user_data)
111568 +{
111569 +// size_t i;
111570 +
111571 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111572 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111573 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111574 +
111575 + old_section_type_flags = targetm.section_type_flags;
111576 + targetm.section_type_flags = constify_section_type_flags;
111577 +}
111578 +
111579 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111580 +{
111581 + const char * const plugin_name = plugin_info->base_name;
111582 + const int argc = plugin_info->argc;
111583 + const struct plugin_argument * const argv = plugin_info->argv;
111584 + int i;
111585 + bool constify = true;
111586 +
111587 + struct register_pass_info check_local_variables_pass_info;
111588 +
111589 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111590 + check_local_variables_pass_info.reference_pass_name = "ssa";
111591 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111592 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111593 +
111594 + if (!plugin_default_version_check(version, &gcc_version)) {
111595 + error(G_("incompatible gcc/plugin versions"));
111596 + return 1;
111597 + }
111598 +
111599 + for (i = 0; i < argc; ++i) {
111600 + if (!(strcmp(argv[i].key, "no-constify"))) {
111601 + constify = false;
111602 + continue;
111603 + }
111604 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111605 + }
111606 +
111607 + if (strcmp(lang_hooks.name, "GNU C")) {
111608 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
111609 + constify = false;
111610 + }
111611 +
111612 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111613 + if (constify) {
111614 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111615 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111616 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111617 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111618 + }
111619 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111620 +
111621 + return 0;
111622 +}
111623 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111624 new file mode 100644
111625 index 0000000..e90c205
111626 --- /dev/null
111627 +++ b/tools/gcc/gcc-common.h
111628 @@ -0,0 +1,295 @@
111629 +#ifndef GCC_COMMON_H_INCLUDED
111630 +#define GCC_COMMON_H_INCLUDED
111631 +
111632 +#include "plugin.h"
111633 +#include "bversion.h"
111634 +#include "plugin-version.h"
111635 +#include "config.h"
111636 +#include "system.h"
111637 +#include "coretypes.h"
111638 +#include "tm.h"
111639 +#include "line-map.h"
111640 +#include "input.h"
111641 +#include "tree.h"
111642 +
111643 +#include "tree-inline.h"
111644 +#include "version.h"
111645 +#include "rtl.h"
111646 +#include "tm_p.h"
111647 +#include "flags.h"
111648 +//#include "insn-attr.h"
111649 +//#include "insn-config.h"
111650 +//#include "insn-flags.h"
111651 +#include "hard-reg-set.h"
111652 +//#include "recog.h"
111653 +#include "output.h"
111654 +#include "except.h"
111655 +#include "function.h"
111656 +#include "toplev.h"
111657 +//#include "expr.h"
111658 +#include "basic-block.h"
111659 +#include "intl.h"
111660 +#include "ggc.h"
111661 +//#include "regs.h"
111662 +#include "timevar.h"
111663 +
111664 +#include "params.h"
111665 +#include "pointer-set.h"
111666 +#include "emit-rtl.h"
111667 +//#include "reload.h"
111668 +//#include "ira.h"
111669 +//#include "dwarf2asm.h"
111670 +#include "debug.h"
111671 +#include "target.h"
111672 +#include "langhooks.h"
111673 +#include "cfgloop.h"
111674 +//#include "hosthooks.h"
111675 +#include "cgraph.h"
111676 +#include "opts.h"
111677 +//#include "coverage.h"
111678 +//#include "value-prof.h"
111679 +
111680 +#if BUILDING_GCC_VERSION >= 4007
111681 +#include "tree-pretty-print.h"
111682 +#include "gimple-pretty-print.h"
111683 +#include "c-tree.h"
111684 +//#include "alloc-pool.h"
111685 +#endif
111686 +
111687 +#if BUILDING_GCC_VERSION <= 4008
111688 +#include "tree-flow.h"
111689 +#else
111690 +#include "tree-cfgcleanup.h"
111691 +#endif
111692 +
111693 +#include "diagnostic.h"
111694 +//#include "tree-diagnostic.h"
111695 +#include "tree-dump.h"
111696 +#include "tree-pass.h"
111697 +//#include "df.h"
111698 +#include "predict.h"
111699 +#include "ipa-utils.h"
111700 +
111701 +#if BUILDING_GCC_VERSION >= 4009
111702 +#include "varasm.h"
111703 +#include "stor-layout.h"
111704 +#include "internal-fn.h"
111705 +#include "gimple-expr.h"
111706 +//#include "diagnostic-color.h"
111707 +#include "context.h"
111708 +#include "tree-ssa-alias.h"
111709 +#include "stringpool.h"
111710 +#include "tree-ssanames.h"
111711 +#include "print-tree.h"
111712 +#include "tree-eh.h"
111713 +#include "stmt.h"
111714 +#endif
111715 +
111716 +#include "gimple.h"
111717 +
111718 +#if BUILDING_GCC_VERSION >= 4009
111719 +#include "tree-ssa-operands.h"
111720 +#include "tree-phinodes.h"
111721 +#include "tree-cfg.h"
111722 +#include "gimple-iterator.h"
111723 +#include "gimple-ssa.h"
111724 +#include "ssa-iterators.h"
111725 +#endif
111726 +
111727 +//#include "lto/lto.h"
111728 +//#include "data-streamer.h"
111729 +//#include "lto-compress.h"
111730 +
111731 +//#include "expr.h" where are you...
111732 +extern rtx emit_move_insn(rtx x, rtx y);
111733 +
111734 +// missing from basic_block.h...
111735 +extern void debug_dominance_info(enum cdi_direction dir);
111736 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111737 +
111738 +#define __unused __attribute__((__unused__))
111739 +
111740 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111741 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111742 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111743 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111744 +
111745 +#if BUILDING_GCC_VERSION == 4005
111746 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111747 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111748 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111749 +#define TODO_rebuild_cgraph_edges 0
111750 +
111751 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111752 +{
111753 + tree fndecl;
111754 +
111755 + if (!is_gimple_call(stmt))
111756 + return false;
111757 + fndecl = gimple_call_fndecl(stmt);
111758 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111759 + return false;
111760 +// print_node(stderr, "pax", fndecl, 4);
111761 + return DECL_FUNCTION_CODE(fndecl) == code;
111762 +}
111763 +
111764 +static inline bool is_simple_builtin(tree decl)
111765 +{
111766 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111767 + return false;
111768 +
111769 + switch (DECL_FUNCTION_CODE(decl)) {
111770 + /* Builtins that expand to constants. */
111771 + case BUILT_IN_CONSTANT_P:
111772 + case BUILT_IN_EXPECT:
111773 + case BUILT_IN_OBJECT_SIZE:
111774 + case BUILT_IN_UNREACHABLE:
111775 + /* Simple register moves or loads from stack. */
111776 + case BUILT_IN_RETURN_ADDRESS:
111777 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111778 + case BUILT_IN_FROB_RETURN_ADDR:
111779 + case BUILT_IN_RETURN:
111780 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111781 + case BUILT_IN_FRAME_ADDRESS:
111782 + case BUILT_IN_VA_END:
111783 + case BUILT_IN_STACK_SAVE:
111784 + case BUILT_IN_STACK_RESTORE:
111785 + /* Exception state returns or moves registers around. */
111786 + case BUILT_IN_EH_FILTER:
111787 + case BUILT_IN_EH_POINTER:
111788 + case BUILT_IN_EH_COPY_VALUES:
111789 + return true;
111790 +
111791 + default:
111792 + return false;
111793 + }
111794 +}
111795 +#endif
111796 +
111797 +#if BUILDING_GCC_VERSION <= 4006
111798 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111799 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111800 +
111801 +// should come from c-tree.h if only it were installed for gcc 4.5...
111802 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111803 +
111804 +#define get_random_seed(noinit) ({ \
111805 + unsigned HOST_WIDE_INT seed; \
111806 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111807 + seed * seed; })
111808 +
111809 +static inline bool gimple_clobber_p(gimple s)
111810 +{
111811 + return false;
111812 +}
111813 +
111814 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111815 +{
111816 + return implicit_built_in_decls[fncode];
111817 +}
111818 +
111819 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111820 +{
111821 + struct cgraph_node *node = cgraph_get_node(decl);
111822 +
111823 + return node ? node : cgraph_node(decl);
111824 +}
111825 +
111826 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111827 +{
111828 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111829 +}
111830 +
111831 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111832 +{
111833 + struct cgraph_node *node;
111834 +
111835 + for (node = cgraph_nodes; node; node = node->next)
111836 + if (cgraph_function_with_gimple_body_p(node))
111837 + return node;
111838 + return NULL;
111839 +}
111840 +
111841 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111842 +{
111843 + for (node = node->next; node; node = node->next)
111844 + if (cgraph_function_with_gimple_body_p(node))
111845 + return node;
111846 + return NULL;
111847 +}
111848 +
111849 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111850 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111851 + (node) = cgraph_next_function_with_gimple_body(node))
111852 +#endif
111853 +
111854 +#if BUILDING_GCC_VERSION == 4006
111855 +extern void debug_gimple_stmt(gimple);
111856 +extern void debug_gimple_seq(gimple_seq);
111857 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111858 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111859 +extern void print_gimple_expr(FILE *, gimple, int, int);
111860 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111861 +#endif
111862 +
111863 +#if BUILDING_GCC_VERSION <= 4007
111864 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111865 +#define PROP_loops 0
111866 +
111867 +static inline int bb_loop_depth(const_basic_block bb)
111868 +{
111869 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111870 +}
111871 +
111872 +static inline bool gimple_store_p(gimple gs)
111873 +{
111874 + tree lhs = gimple_get_lhs(gs);
111875 + return lhs && !is_gimple_reg(lhs);
111876 +}
111877 +#endif
111878 +
111879 +#if BUILDING_GCC_VERSION >= 4007
111880 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111881 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111882 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111883 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111884 +#endif
111885 +
111886 +#if BUILDING_GCC_VERSION <= 4008
111887 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111888 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111889 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111890 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111891 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111892 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111893 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111894 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111895 +
111896 +static inline const char *get_tree_code_name(enum tree_code code)
111897 +{
111898 + gcc_assert(code < MAX_TREE_CODES);
111899 + return tree_code_name[code];
111900 +}
111901 +
111902 +#define ipa_remove_stmt_references(cnode, stmt)
111903 +#endif
111904 +
111905 +#if BUILDING_GCC_VERSION == 4008
111906 +#define NODE_DECL(node) node->symbol.decl
111907 +#else
111908 +#define NODE_DECL(node) node->decl
111909 +#endif
111910 +
111911 +#if BUILDING_GCC_VERSION >= 4008
111912 +#define add_referenced_var(var)
111913 +#define mark_sym_for_renaming(var)
111914 +#define varpool_mark_needed_node(node)
111915 +#define TODO_dump_func 0
111916 +#define TODO_dump_cgraph 0
111917 +#endif
111918 +
111919 +#if BUILDING_GCC_VERSION >= 4009
111920 +#define TODO_ggc_collect 0
111921 +#endif
111922 +
111923 +#endif
111924 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111925 new file mode 100644
111926 index 0000000..7514850
111927 --- /dev/null
111928 +++ b/tools/gcc/gen-random-seed.sh
111929 @@ -0,0 +1,8 @@
111930 +#!/bin/sh
111931 +
111932 +if [ ! -f "$1" ]; then
111933 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111934 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111935 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111936 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111937 +fi
111938 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111939 new file mode 100644
111940 index 0000000..d81c094
111941 --- /dev/null
111942 +++ b/tools/gcc/kallocstat_plugin.c
111943 @@ -0,0 +1,183 @@
111944 +/*
111945 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111946 + * Licensed under the GPL v2
111947 + *
111948 + * Note: the choice of the license means that the compilation process is
111949 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111950 + * but for the kernel it doesn't matter since it doesn't link against
111951 + * any of the gcc libraries
111952 + *
111953 + * gcc plugin to find the distribution of k*alloc sizes
111954 + *
111955 + * TODO:
111956 + *
111957 + * BUGS:
111958 + * - none known
111959 + */
111960 +
111961 +#include "gcc-common.h"
111962 +
111963 +int plugin_is_GPL_compatible;
111964 +
111965 +static struct plugin_info kallocstat_plugin_info = {
111966 + .version = "201401260140",
111967 + .help = NULL
111968 +};
111969 +
111970 +static const char * const kalloc_functions[] = {
111971 + "__kmalloc",
111972 + "kmalloc",
111973 + "kmalloc_large",
111974 + "kmalloc_node",
111975 + "kmalloc_order",
111976 + "kmalloc_order_trace",
111977 + "kmalloc_slab",
111978 + "kzalloc",
111979 + "kzalloc_node",
111980 +};
111981 +
111982 +static bool is_kalloc(const char *fnname)
111983 +{
111984 + size_t i;
111985 +
111986 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111987 + if (!strcmp(fnname, kalloc_functions[i]))
111988 + return true;
111989 + return false;
111990 +}
111991 +
111992 +static unsigned int execute_kallocstat(void)
111993 +{
111994 + basic_block bb;
111995 +
111996 + // 1. loop through BBs and GIMPLE statements
111997 + FOR_EACH_BB_FN(bb, cfun) {
111998 + gimple_stmt_iterator gsi;
111999 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112000 + // gimple match:
112001 + tree fndecl, size;
112002 + gimple stmt;
112003 + const char *fnname;
112004 +
112005 + // is it a call
112006 + stmt = gsi_stmt(gsi);
112007 + if (!is_gimple_call(stmt))
112008 + continue;
112009 + fndecl = gimple_call_fndecl(stmt);
112010 + if (fndecl == NULL_TREE)
112011 + continue;
112012 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
112013 + continue;
112014 +
112015 + // is it a call to k*alloc
112016 + fnname = DECL_NAME_POINTER(fndecl);
112017 + if (!is_kalloc(fnname))
112018 + continue;
112019 +
112020 + // is the size arg const or the result of a simple const assignment
112021 + size = gimple_call_arg(stmt, 0);
112022 + while (true) {
112023 + expanded_location xloc;
112024 + size_t size_val;
112025 +
112026 + if (TREE_CONSTANT(size)) {
112027 + xloc = expand_location(gimple_location(stmt));
112028 + if (!xloc.file)
112029 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112030 + size_val = TREE_INT_CST_LOW(size);
112031 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
112032 + break;
112033 + }
112034 +
112035 + if (TREE_CODE(size) != SSA_NAME)
112036 + break;
112037 + stmt = SSA_NAME_DEF_STMT(size);
112038 +//debug_gimple_stmt(stmt);
112039 +//debug_tree(size);
112040 + if (!stmt || !is_gimple_assign(stmt))
112041 + break;
112042 + if (gimple_num_ops(stmt) != 2)
112043 + break;
112044 + size = gimple_assign_rhs1(stmt);
112045 + }
112046 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112047 +//debug_tree(gimple_call_fn(call_stmt));
112048 +//print_node(stderr, "pax", fndecl, 4);
112049 + }
112050 + }
112051 +
112052 + return 0;
112053 +}
112054 +
112055 +#if BUILDING_GCC_VERSION >= 4009
112056 +static const struct pass_data kallocstat_pass_data = {
112057 +#else
112058 +static struct gimple_opt_pass kallocstat_pass = {
112059 + .pass = {
112060 +#endif
112061 + .type = GIMPLE_PASS,
112062 + .name = "kallocstat",
112063 +#if BUILDING_GCC_VERSION >= 4008
112064 + .optinfo_flags = OPTGROUP_NONE,
112065 +#endif
112066 +#if BUILDING_GCC_VERSION >= 4009
112067 + .has_gate = false,
112068 + .has_execute = true,
112069 +#else
112070 + .gate = NULL,
112071 + .execute = execute_kallocstat,
112072 + .sub = NULL,
112073 + .next = NULL,
112074 + .static_pass_number = 0,
112075 +#endif
112076 + .tv_id = TV_NONE,
112077 + .properties_required = 0,
112078 + .properties_provided = 0,
112079 + .properties_destroyed = 0,
112080 + .todo_flags_start = 0,
112081 + .todo_flags_finish = 0
112082 +#if BUILDING_GCC_VERSION < 4009
112083 + }
112084 +#endif
112085 +};
112086 +
112087 +#if BUILDING_GCC_VERSION >= 4009
112088 +namespace {
112089 +class kallocstat_pass : public gimple_opt_pass {
112090 +public:
112091 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
112092 + unsigned int execute() { return execute_kallocstat(); }
112093 +};
112094 +}
112095 +
112096 +static opt_pass *make_kallocstat_pass(void)
112097 +{
112098 + return new kallocstat_pass();
112099 +}
112100 +#else
112101 +static struct opt_pass *make_kallocstat_pass(void)
112102 +{
112103 + return &kallocstat_pass.pass;
112104 +}
112105 +#endif
112106 +
112107 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112108 +{
112109 + const char * const plugin_name = plugin_info->base_name;
112110 + struct register_pass_info kallocstat_pass_info;
112111 +
112112 + kallocstat_pass_info.pass = make_kallocstat_pass();
112113 + kallocstat_pass_info.reference_pass_name = "ssa";
112114 + kallocstat_pass_info.ref_pass_instance_number = 1;
112115 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112116 +
112117 + if (!plugin_default_version_check(version, &gcc_version)) {
112118 + error(G_("incompatible gcc/plugin versions"));
112119 + return 1;
112120 + }
112121 +
112122 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
112123 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
112124 +
112125 + return 0;
112126 +}
112127 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
112128 new file mode 100644
112129 index 0000000..89f256d
112130 --- /dev/null
112131 +++ b/tools/gcc/kernexec_plugin.c
112132 @@ -0,0 +1,522 @@
112133 +/*
112134 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112135 + * Licensed under the GPL v2
112136 + *
112137 + * Note: the choice of the license means that the compilation process is
112138 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112139 + * but for the kernel it doesn't matter since it doesn't link against
112140 + * any of the gcc libraries
112141 + *
112142 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
112143 + *
112144 + * TODO:
112145 + *
112146 + * BUGS:
112147 + * - none known
112148 + */
112149 +
112150 +#include "gcc-common.h"
112151 +
112152 +int plugin_is_GPL_compatible;
112153 +
112154 +static struct plugin_info kernexec_plugin_info = {
112155 + .version = "201401260140",
112156 + .help = "method=[bts|or]\tinstrumentation method\n"
112157 +};
112158 +
112159 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
112160 +static void (*kernexec_instrument_retaddr)(rtx);
112161 +
112162 +/*
112163 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
112164 + */
112165 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
112166 +{
112167 + gimple asm_movabs_stmt;
112168 +
112169 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
112170 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
112171 + gimple_asm_set_volatile(asm_movabs_stmt, true);
112172 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
112173 + update_stmt(asm_movabs_stmt);
112174 +}
112175 +
112176 +/*
112177 + * find all asm() stmts that clobber r12 and add a reload of r12
112178 + */
112179 +static unsigned int execute_kernexec_reload(void)
112180 +{
112181 + basic_block bb;
112182 +
112183 + // 1. loop through BBs and GIMPLE statements
112184 + FOR_EACH_BB_FN(bb, cfun) {
112185 + gimple_stmt_iterator gsi;
112186 +
112187 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112188 + // gimple match: __asm__ ("" : : : "r12");
112189 + gimple asm_stmt;
112190 + size_t nclobbers;
112191 +
112192 + // is it an asm ...
112193 + asm_stmt = gsi_stmt(gsi);
112194 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
112195 + continue;
112196 +
112197 + // ... clobbering r12
112198 + nclobbers = gimple_asm_nclobbers(asm_stmt);
112199 + while (nclobbers--) {
112200 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
112201 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
112202 + continue;
112203 + kernexec_reload_fptr_mask(&gsi);
112204 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
112205 + break;
112206 + }
112207 + }
112208 + }
112209 +
112210 + return 0;
112211 +}
112212 +
112213 +/*
112214 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
112215 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
112216 + */
112217 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
112218 +{
112219 + gimple assign_intptr, assign_new_fptr, call_stmt;
112220 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
112221 +
112222 + call_stmt = gsi_stmt(*gsi);
112223 + old_fptr = gimple_call_fn(call_stmt);
112224 +
112225 + // create temporary unsigned long variable used for bitops and cast fptr to it
112226 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
112227 + add_referenced_var(intptr);
112228 + intptr = make_ssa_name(intptr, NULL);
112229 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
112230 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112231 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112232 + update_stmt(assign_intptr);
112233 +
112234 + // apply logical or to temporary unsigned long and bitmask
112235 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
112236 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
112237 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
112238 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
112239 + assign_intptr = gimple_build_assign(intptr, orptr);
112240 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112241 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112242 + update_stmt(assign_intptr);
112243 +
112244 + // cast temporary unsigned long back to a temporary fptr variable
112245 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
112246 + add_referenced_var(new_fptr);
112247 + new_fptr = make_ssa_name(new_fptr, NULL);
112248 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
112249 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
112250 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
112251 + update_stmt(assign_new_fptr);
112252 +
112253 + // replace call stmt fn with the new fptr
112254 + gimple_call_set_fn(call_stmt, new_fptr);
112255 + update_stmt(call_stmt);
112256 +}
112257 +
112258 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
112259 +{
112260 + gimple asm_or_stmt, call_stmt;
112261 + tree old_fptr, new_fptr, input, output;
112262 +#if BUILDING_GCC_VERSION <= 4007
112263 + VEC(tree, gc) *inputs = NULL;
112264 + VEC(tree, gc) *outputs = NULL;
112265 +#else
112266 + vec<tree, va_gc> *inputs = NULL;
112267 + vec<tree, va_gc> *outputs = NULL;
112268 +#endif
112269 +
112270 + call_stmt = gsi_stmt(*gsi);
112271 + old_fptr = gimple_call_fn(call_stmt);
112272 +
112273 + // create temporary fptr variable
112274 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
112275 + add_referenced_var(new_fptr);
112276 + new_fptr = make_ssa_name(new_fptr, NULL);
112277 +
112278 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
112279 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
112280 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
112281 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
112282 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
112283 +#if BUILDING_GCC_VERSION <= 4007
112284 + VEC_safe_push(tree, gc, inputs, input);
112285 + VEC_safe_push(tree, gc, outputs, output);
112286 +#else
112287 + vec_safe_push(inputs, input);
112288 + vec_safe_push(outputs, output);
112289 +#endif
112290 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
112291 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
112292 + gimple_asm_set_volatile(asm_or_stmt, true);
112293 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
112294 + update_stmt(asm_or_stmt);
112295 +
112296 + // replace call stmt fn with the new fptr
112297 + gimple_call_set_fn(call_stmt, new_fptr);
112298 + update_stmt(call_stmt);
112299 +}
112300 +
112301 +/*
112302 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
112303 + */
112304 +static unsigned int execute_kernexec_fptr(void)
112305 +{
112306 + basic_block bb;
112307 +
112308 + // 1. loop through BBs and GIMPLE statements
112309 + FOR_EACH_BB_FN(bb, cfun) {
112310 + gimple_stmt_iterator gsi;
112311 +
112312 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112313 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
112314 + tree fn;
112315 + gimple call_stmt;
112316 +
112317 + // is it a call ...
112318 + call_stmt = gsi_stmt(gsi);
112319 + if (!is_gimple_call(call_stmt))
112320 + continue;
112321 + fn = gimple_call_fn(call_stmt);
112322 + if (TREE_CODE(fn) == ADDR_EXPR)
112323 + continue;
112324 + if (TREE_CODE(fn) != SSA_NAME)
112325 + gcc_unreachable();
112326 +
112327 + // ... through a function pointer
112328 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112329 + fn = SSA_NAME_VAR(fn);
112330 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112331 + debug_tree(fn);
112332 + gcc_unreachable();
112333 + }
112334 + }
112335 + fn = TREE_TYPE(fn);
112336 + if (TREE_CODE(fn) != POINTER_TYPE)
112337 + continue;
112338 + fn = TREE_TYPE(fn);
112339 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112340 + continue;
112341 +
112342 + kernexec_instrument_fptr(&gsi);
112343 +
112344 +//debug_tree(gimple_call_fn(call_stmt));
112345 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112346 + }
112347 + }
112348 +
112349 + return 0;
112350 +}
112351 +
112352 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112353 +static void kernexec_instrument_retaddr_bts(rtx insn)
112354 +{
112355 + rtx btsq;
112356 + rtvec argvec, constraintvec, labelvec;
112357 + int line;
112358 +
112359 + // create asm volatile("btsq $63,(%%rsp)":::)
112360 + argvec = rtvec_alloc(0);
112361 + constraintvec = rtvec_alloc(0);
112362 + labelvec = rtvec_alloc(0);
112363 + line = expand_location(RTL_LOCATION(insn)).line;
112364 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112365 + MEM_VOLATILE_P(btsq) = 1;
112366 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112367 + emit_insn_before(btsq, insn);
112368 +}
112369 +
112370 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112371 +static void kernexec_instrument_retaddr_or(rtx insn)
112372 +{
112373 + rtx orq;
112374 + rtvec argvec, constraintvec, labelvec;
112375 + int line;
112376 +
112377 + // create asm volatile("orq %%r12,(%%rsp)":::)
112378 + argvec = rtvec_alloc(0);
112379 + constraintvec = rtvec_alloc(0);
112380 + labelvec = rtvec_alloc(0);
112381 + line = expand_location(RTL_LOCATION(insn)).line;
112382 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112383 + MEM_VOLATILE_P(orq) = 1;
112384 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112385 + emit_insn_before(orq, insn);
112386 +}
112387 +
112388 +/*
112389 + * find all asm level function returns and forcibly set the highest bit of the return address
112390 + */
112391 +static unsigned int execute_kernexec_retaddr(void)
112392 +{
112393 + rtx insn;
112394 +
112395 +// if (stack_realign_drap)
112396 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112397 +
112398 + // 1. find function returns
112399 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112400 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112401 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112402 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112403 + rtx body;
112404 +
112405 + // is it a retn
112406 + if (!JUMP_P(insn))
112407 + continue;
112408 + body = PATTERN(insn);
112409 + if (GET_CODE(body) == PARALLEL)
112410 + body = XVECEXP(body, 0, 0);
112411 + if (!ANY_RETURN_P(body))
112412 + continue;
112413 + kernexec_instrument_retaddr(insn);
112414 + }
112415 +
112416 +// print_simple_rtl(stderr, get_insns());
112417 +// print_rtl(stderr, get_insns());
112418 +
112419 + return 0;
112420 +}
112421 +
112422 +static bool kernexec_cmodel_check(void)
112423 +{
112424 + tree section;
112425 +
112426 + if (ix86_cmodel != CM_KERNEL)
112427 + return false;
112428 +
112429 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112430 + if (!section || !TREE_VALUE(section))
112431 + return true;
112432 +
112433 + section = TREE_VALUE(TREE_VALUE(section));
112434 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112435 + return true;
112436 +
112437 + return false;
112438 +}
112439 +
112440 +#if BUILDING_GCC_VERSION >= 4009
112441 +static const struct pass_data kernexec_reload_pass_data = {
112442 +#else
112443 +static struct gimple_opt_pass kernexec_reload_pass = {
112444 + .pass = {
112445 +#endif
112446 + .type = GIMPLE_PASS,
112447 + .name = "kernexec_reload",
112448 +#if BUILDING_GCC_VERSION >= 4008
112449 + .optinfo_flags = OPTGROUP_NONE,
112450 +#endif
112451 +#if BUILDING_GCC_VERSION >= 4009
112452 + .has_gate = true,
112453 + .has_execute = true,
112454 +#else
112455 + .gate = kernexec_cmodel_check,
112456 + .execute = execute_kernexec_reload,
112457 + .sub = NULL,
112458 + .next = NULL,
112459 + .static_pass_number = 0,
112460 +#endif
112461 + .tv_id = TV_NONE,
112462 + .properties_required = 0,
112463 + .properties_provided = 0,
112464 + .properties_destroyed = 0,
112465 + .todo_flags_start = 0,
112466 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112467 +#if BUILDING_GCC_VERSION < 4009
112468 + }
112469 +#endif
112470 +};
112471 +
112472 +#if BUILDING_GCC_VERSION >= 4009
112473 +static const struct pass_data kernexec_fptr_pass_data = {
112474 +#else
112475 +static struct gimple_opt_pass kernexec_fptr_pass = {
112476 + .pass = {
112477 +#endif
112478 + .type = GIMPLE_PASS,
112479 + .name = "kernexec_fptr",
112480 +#if BUILDING_GCC_VERSION >= 4008
112481 + .optinfo_flags = OPTGROUP_NONE,
112482 +#endif
112483 +#if BUILDING_GCC_VERSION >= 4009
112484 + .has_gate = true,
112485 + .has_execute = true,
112486 +#else
112487 + .gate = kernexec_cmodel_check,
112488 + .execute = execute_kernexec_fptr,
112489 + .sub = NULL,
112490 + .next = NULL,
112491 + .static_pass_number = 0,
112492 +#endif
112493 + .tv_id = TV_NONE,
112494 + .properties_required = 0,
112495 + .properties_provided = 0,
112496 + .properties_destroyed = 0,
112497 + .todo_flags_start = 0,
112498 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112499 +#if BUILDING_GCC_VERSION < 4009
112500 + }
112501 +#endif
112502 +};
112503 +
112504 +#if BUILDING_GCC_VERSION >= 4009
112505 +static const struct pass_data kernexec_retaddr_pass_data = {
112506 +#else
112507 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112508 + .pass = {
112509 +#endif
112510 + .type = RTL_PASS,
112511 + .name = "kernexec_retaddr",
112512 +#if BUILDING_GCC_VERSION >= 4008
112513 + .optinfo_flags = OPTGROUP_NONE,
112514 +#endif
112515 +#if BUILDING_GCC_VERSION >= 4009
112516 + .has_gate = true,
112517 + .has_execute = true,
112518 +#else
112519 + .gate = kernexec_cmodel_check,
112520 + .execute = execute_kernexec_retaddr,
112521 + .sub = NULL,
112522 + .next = NULL,
112523 + .static_pass_number = 0,
112524 +#endif
112525 + .tv_id = TV_NONE,
112526 + .properties_required = 0,
112527 + .properties_provided = 0,
112528 + .properties_destroyed = 0,
112529 + .todo_flags_start = 0,
112530 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112531 +#if BUILDING_GCC_VERSION < 4009
112532 + }
112533 +#endif
112534 +};
112535 +
112536 +#if BUILDING_GCC_VERSION >= 4009
112537 +namespace {
112538 +class kernexec_reload_pass : public gimple_opt_pass {
112539 +public:
112540 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112541 + bool gate() { return kernexec_cmodel_check(); }
112542 + unsigned int execute() { return execute_kernexec_reload(); }
112543 +};
112544 +
112545 +class kernexec_fptr_pass : public gimple_opt_pass {
112546 +public:
112547 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112548 + bool gate() { return kernexec_cmodel_check(); }
112549 + unsigned int execute() { return execute_kernexec_fptr(); }
112550 +};
112551 +
112552 +class kernexec_retaddr_pass : public rtl_opt_pass {
112553 +public:
112554 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112555 + bool gate() { return kernexec_cmodel_check(); }
112556 + unsigned int execute() { return execute_kernexec_retaddr(); }
112557 +};
112558 +}
112559 +
112560 +static opt_pass *make_kernexec_reload_pass(void)
112561 +{
112562 + return new kernexec_reload_pass();
112563 +}
112564 +
112565 +static opt_pass *make_kernexec_fptr_pass(void)
112566 +{
112567 + return new kernexec_fptr_pass();
112568 +}
112569 +
112570 +static opt_pass *make_kernexec_retaddr_pass(void)
112571 +{
112572 + return new kernexec_retaddr_pass();
112573 +}
112574 +#else
112575 +static struct opt_pass *make_kernexec_reload_pass(void)
112576 +{
112577 + return &kernexec_reload_pass.pass;
112578 +}
112579 +
112580 +static struct opt_pass *make_kernexec_fptr_pass(void)
112581 +{
112582 + return &kernexec_fptr_pass.pass;
112583 +}
112584 +
112585 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112586 +{
112587 + return &kernexec_retaddr_pass.pass;
112588 +}
112589 +#endif
112590 +
112591 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112592 +{
112593 + const char * const plugin_name = plugin_info->base_name;
112594 + const int argc = plugin_info->argc;
112595 + const struct plugin_argument * const argv = plugin_info->argv;
112596 + int i;
112597 + struct register_pass_info kernexec_reload_pass_info;
112598 + struct register_pass_info kernexec_fptr_pass_info;
112599 + struct register_pass_info kernexec_retaddr_pass_info;
112600 +
112601 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112602 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112603 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112604 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112605 +
112606 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112607 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112608 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112609 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112610 +
112611 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112612 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112613 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112614 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112615 +
112616 + if (!plugin_default_version_check(version, &gcc_version)) {
112617 + error(G_("incompatible gcc/plugin versions"));
112618 + return 1;
112619 + }
112620 +
112621 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112622 +
112623 + if (TARGET_64BIT == 0)
112624 + return 0;
112625 +
112626 + for (i = 0; i < argc; ++i) {
112627 + if (!strcmp(argv[i].key, "method")) {
112628 + if (!argv[i].value) {
112629 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112630 + continue;
112631 + }
112632 + if (!strcmp(argv[i].value, "bts")) {
112633 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112634 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112635 + } else if (!strcmp(argv[i].value, "or")) {
112636 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112637 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112638 + fix_register("r12", 1, 1);
112639 + } else
112640 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112641 + continue;
112642 + }
112643 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112644 + }
112645 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112646 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112647 +
112648 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112649 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112650 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112651 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112652 +
112653 + return 0;
112654 +}
112655 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112656 new file mode 100644
112657 index 0000000..e48b323
112658 --- /dev/null
112659 +++ b/tools/gcc/latent_entropy_plugin.c
112660 @@ -0,0 +1,466 @@
112661 +/*
112662 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112663 + * Licensed under the GPL v2
112664 + *
112665 + * Note: the choice of the license means that the compilation process is
112666 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112667 + * but for the kernel it doesn't matter since it doesn't link against
112668 + * any of the gcc libraries
112669 + *
112670 + * gcc plugin to help generate a little bit of entropy from program state,
112671 + * used throughout the uptime of the kernel
112672 + *
112673 + * TODO:
112674 + * - add ipa pass to identify not explicitly marked candidate functions
112675 + * - mix in more program state (function arguments/return values, loop variables, etc)
112676 + * - more instrumentation control via attribute parameters
112677 + *
112678 + * BUGS:
112679 + * - LTO needs -flto-partition=none for now
112680 + */
112681 +
112682 +#include "gcc-common.h"
112683 +
112684 +int plugin_is_GPL_compatible;
112685 +
112686 +static tree latent_entropy_decl;
112687 +
112688 +static struct plugin_info latent_entropy_plugin_info = {
112689 + .version = "201409101820",
112690 + .help = NULL
112691 +};
112692 +
112693 +static unsigned HOST_WIDE_INT seed;
112694 +static unsigned HOST_WIDE_INT get_random_const(void)
112695 +{
112696 + unsigned int i;
112697 + unsigned HOST_WIDE_INT ret = 0;
112698 +
112699 + for (i = 0; i < 8 * sizeof ret; i++) {
112700 + ret = (ret << 1) | (seed & 1);
112701 + seed >>= 1;
112702 + if (ret & 1)
112703 + seed ^= 0xD800000000000000ULL;
112704 + }
112705 +
112706 + return ret;
112707 +}
112708 +
112709 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112710 +{
112711 + tree type;
112712 + unsigned long long mask;
112713 +#if BUILDING_GCC_VERSION <= 4007
112714 + VEC(constructor_elt, gc) *vals;
112715 +#else
112716 + vec<constructor_elt, va_gc> *vals;
112717 +#endif
112718 +
112719 + switch (TREE_CODE(*node)) {
112720 + default:
112721 + *no_add_attrs = true;
112722 + error("%qE attribute only applies to functions and variables", name);
112723 + break;
112724 +
112725 + case VAR_DECL:
112726 + if (DECL_INITIAL(*node)) {
112727 + *no_add_attrs = true;
112728 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112729 + break;
112730 + }
112731 +
112732 + if (!TREE_STATIC(*node)) {
112733 + *no_add_attrs = true;
112734 + error("variable %qD with %qE attribute must not be local", *node, name);
112735 + break;
112736 + }
112737 +
112738 + type = TREE_TYPE(*node);
112739 + switch (TREE_CODE(type)) {
112740 + default:
112741 + *no_add_attrs = true;
112742 + 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);
112743 + break;
112744 +
112745 + case RECORD_TYPE: {
112746 + tree field;
112747 + unsigned int nelt = 0;
112748 +
112749 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112750 + tree fieldtype;
112751 +
112752 + fieldtype = TREE_TYPE(field);
112753 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112754 + *no_add_attrs = true;
112755 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112756 + break;
112757 + }
112758 + }
112759 +
112760 + if (field)
112761 + break;
112762 +
112763 +#if BUILDING_GCC_VERSION <= 4007
112764 + vals = VEC_alloc(constructor_elt, gc, nelt);
112765 +#else
112766 + vec_alloc(vals, nelt);
112767 +#endif
112768 +
112769 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112770 + tree fieldtype;
112771 +
112772 + fieldtype = TREE_TYPE(field);
112773 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112774 + mask = 2 * (mask - 1) + 1;
112775 +
112776 + if (TYPE_UNSIGNED(fieldtype))
112777 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112778 + else
112779 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112780 + }
112781 +
112782 + DECL_INITIAL(*node) = build_constructor(type, vals);
112783 +//debug_tree(DECL_INITIAL(*node));
112784 + break;
112785 + }
112786 +
112787 + case INTEGER_TYPE:
112788 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112789 + mask = 2 * (mask - 1) + 1;
112790 +
112791 + if (TYPE_UNSIGNED(type))
112792 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112793 + else
112794 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112795 + break;
112796 +
112797 + case ARRAY_TYPE: {
112798 + tree elt_type, array_size, elt_size;
112799 + unsigned int i, nelt;
112800 +
112801 + elt_type = TREE_TYPE(type);
112802 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112803 + array_size = TYPE_SIZE_UNIT(type);
112804 +
112805 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112806 + *no_add_attrs = true;
112807 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112808 + break;
112809 + }
112810 +
112811 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112812 +#if BUILDING_GCC_VERSION <= 4007
112813 + vals = VEC_alloc(constructor_elt, gc, nelt);
112814 +#else
112815 + vec_alloc(vals, nelt);
112816 +#endif
112817 +
112818 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112819 + mask = 2 * (mask - 1) + 1;
112820 +
112821 + for (i = 0; i < nelt; i++)
112822 + if (TYPE_UNSIGNED(elt_type))
112823 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112824 + else
112825 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112826 +
112827 + DECL_INITIAL(*node) = build_constructor(type, vals);
112828 +//debug_tree(DECL_INITIAL(*node));
112829 + break;
112830 + }
112831 + }
112832 + break;
112833 +
112834 + case FUNCTION_DECL:
112835 + break;
112836 + }
112837 +
112838 + return NULL_TREE;
112839 +}
112840 +
112841 +static struct attribute_spec latent_entropy_attr = {
112842 + .name = "latent_entropy",
112843 + .min_length = 0,
112844 + .max_length = 0,
112845 + .decl_required = true,
112846 + .type_required = false,
112847 + .function_type_required = false,
112848 + .handler = handle_latent_entropy_attribute,
112849 +#if BUILDING_GCC_VERSION >= 4007
112850 + .affects_type_identity = false
112851 +#endif
112852 +};
112853 +
112854 +static void register_attributes(void *event_data, void *data)
112855 +{
112856 + register_attribute(&latent_entropy_attr);
112857 +}
112858 +
112859 +static bool gate_latent_entropy(void)
112860 +{
112861 + // don't bother with noreturn functions for now
112862 + if (TREE_THIS_VOLATILE(current_function_decl))
112863 + return false;
112864 +
112865 + // gcc-4.5 doesn't discover some trivial noreturn functions
112866 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112867 + return false;
112868 +
112869 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112870 +}
112871 +
112872 +static enum tree_code get_op(tree *rhs)
112873 +{
112874 + static enum tree_code op;
112875 + unsigned HOST_WIDE_INT random_const;
112876 +
112877 + random_const = get_random_const();
112878 +
112879 + switch (op) {
112880 + case BIT_XOR_EXPR:
112881 + op = PLUS_EXPR;
112882 + break;
112883 +
112884 + case PLUS_EXPR:
112885 + if (rhs) {
112886 + op = LROTATE_EXPR;
112887 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112888 + break;
112889 + }
112890 +
112891 + case LROTATE_EXPR:
112892 + default:
112893 + op = BIT_XOR_EXPR;
112894 + break;
112895 + }
112896 + if (rhs)
112897 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112898 + return op;
112899 +}
112900 +
112901 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112902 +{
112903 + gimple_stmt_iterator gsi;
112904 + gimple assign;
112905 + tree addxorrol, rhs;
112906 + enum tree_code op;
112907 +
112908 + op = get_op(&rhs);
112909 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112910 + assign = gimple_build_assign(local_entropy, addxorrol);
112911 + gsi = gsi_after_labels(bb);
112912 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112913 + update_stmt(assign);
112914 +//debug_bb(bb);
112915 +}
112916 +
112917 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112918 +{
112919 + gimple_stmt_iterator gsi;
112920 + gimple assign;
112921 + tree addxorrol, temp;
112922 +
112923 + // 1. create temporary copy of latent_entropy
112924 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112925 + add_referenced_var(temp);
112926 +
112927 + // 2. read...
112928 + temp = make_ssa_name(temp, NULL);
112929 + assign = gimple_build_assign(temp, latent_entropy_decl);
112930 + SSA_NAME_DEF_STMT(temp) = assign;
112931 + add_referenced_var(latent_entropy_decl);
112932 + gsi = gsi_after_labels(bb);
112933 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112934 + update_stmt(assign);
112935 +
112936 + // 3. ...modify...
112937 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112938 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112939 + assign = gimple_build_assign(temp, addxorrol);
112940 + SSA_NAME_DEF_STMT(temp) = assign;
112941 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112942 + update_stmt(assign);
112943 +
112944 + // 4. ...write latent_entropy
112945 + assign = gimple_build_assign(latent_entropy_decl, temp);
112946 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112947 + update_stmt(assign);
112948 +}
112949 +
112950 +static unsigned int execute_latent_entropy(void)
112951 +{
112952 + basic_block bb;
112953 + gimple assign;
112954 + gimple_stmt_iterator gsi;
112955 + tree local_entropy;
112956 +
112957 + if (!latent_entropy_decl) {
112958 +#if BUILDING_GCC_VERSION >= 4009
112959 + varpool_node *node;
112960 +#else
112961 + struct varpool_node *node;
112962 +#endif
112963 +
112964 + FOR_EACH_VARIABLE(node) {
112965 + tree var = NODE_DECL(node);
112966 +
112967 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112968 + continue;
112969 + latent_entropy_decl = var;
112970 +// debug_tree(var);
112971 + break;
112972 + }
112973 + if (!latent_entropy_decl) {
112974 +// debug_tree(current_function_decl);
112975 + return 0;
112976 + }
112977 + }
112978 +
112979 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112980 +
112981 + // 1. create local entropy variable
112982 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112983 + add_referenced_var(local_entropy);
112984 + mark_sym_for_renaming(local_entropy);
112985 +
112986 + // 2. initialize local entropy variable
112987 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112988 + if (dom_info_available_p(CDI_DOMINATORS))
112989 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112990 + gsi = gsi_start_bb(bb);
112991 +
112992 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112993 +// gimple_set_location(assign, loc);
112994 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112995 + update_stmt(assign);
112996 +//debug_bb(bb);
112997 + gcc_assert(single_succ_p(bb));
112998 + bb = single_succ(bb);
112999 +
113000 + // 3. instrument each BB with an operation on the local entropy variable
113001 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
113002 + perturb_local_entropy(bb, local_entropy);
113003 +//debug_bb(bb);
113004 + bb = bb->next_bb;
113005 + };
113006 +
113007 + // 4. mix local entropy into the global entropy variable
113008 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113009 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
113010 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113011 + return 0;
113012 +}
113013 +
113014 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
113015 +{
113016 + tree latent_entropy_type;
113017 +
113018 + seed = get_random_seed(false);
113019 +
113020 + if (in_lto_p)
113021 + return;
113022 +
113023 + // extern volatile u64 latent_entropy
113024 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
113025 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
113026 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
113027 +
113028 + TREE_STATIC(latent_entropy_decl) = 1;
113029 + TREE_PUBLIC(latent_entropy_decl) = 1;
113030 + TREE_USED(latent_entropy_decl) = 1;
113031 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
113032 + DECL_EXTERNAL(latent_entropy_decl) = 1;
113033 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
113034 + lang_hooks.decls.pushdecl(latent_entropy_decl);
113035 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
113036 +// varpool_finalize_decl(latent_entropy_decl);
113037 +// varpool_mark_needed_node(latent_entropy_decl);
113038 +}
113039 +
113040 +#if BUILDING_GCC_VERSION >= 4009
113041 +static const struct pass_data latent_entropy_pass_data = {
113042 +#else
113043 +static struct gimple_opt_pass latent_entropy_pass = {
113044 + .pass = {
113045 +#endif
113046 + .type = GIMPLE_PASS,
113047 + .name = "latent_entropy",
113048 +#if BUILDING_GCC_VERSION >= 4008
113049 + .optinfo_flags = OPTGROUP_NONE,
113050 +#endif
113051 +#if BUILDING_GCC_VERSION >= 4009
113052 + .has_gate = true,
113053 + .has_execute = true,
113054 +#else
113055 + .gate = gate_latent_entropy,
113056 + .execute = execute_latent_entropy,
113057 + .sub = NULL,
113058 + .next = NULL,
113059 + .static_pass_number = 0,
113060 +#endif
113061 + .tv_id = TV_NONE,
113062 + .properties_required = PROP_gimple_leh | PROP_cfg,
113063 + .properties_provided = 0,
113064 + .properties_destroyed = 0,
113065 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
113066 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
113067 +#if BUILDING_GCC_VERSION < 4009
113068 + }
113069 +#endif
113070 +};
113071 +
113072 +#if BUILDING_GCC_VERSION >= 4009
113073 +namespace {
113074 +class latent_entropy_pass : public gimple_opt_pass {
113075 +public:
113076 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
113077 + bool gate() { return gate_latent_entropy(); }
113078 + unsigned int execute() { return execute_latent_entropy(); }
113079 +};
113080 +}
113081 +
113082 +static opt_pass *make_latent_entropy_pass(void)
113083 +{
113084 + return new latent_entropy_pass();
113085 +}
113086 +#else
113087 +static struct opt_pass *make_latent_entropy_pass(void)
113088 +{
113089 + return &latent_entropy_pass.pass;
113090 +}
113091 +#endif
113092 +
113093 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113094 +{
113095 + const char * const plugin_name = plugin_info->base_name;
113096 + struct register_pass_info latent_entropy_pass_info;
113097 +
113098 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
113099 + latent_entropy_pass_info.reference_pass_name = "optimized";
113100 + latent_entropy_pass_info.ref_pass_instance_number = 1;
113101 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
113102 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
113103 + {
113104 + .base = &latent_entropy_decl,
113105 + .nelt = 1,
113106 + .stride = sizeof(latent_entropy_decl),
113107 + .cb = &gt_ggc_mx_tree_node,
113108 + .pchw = &gt_pch_nx_tree_node
113109 + },
113110 + LAST_GGC_ROOT_TAB
113111 + };
113112 +
113113 + if (!plugin_default_version_check(version, &gcc_version)) {
113114 + error(G_("incompatible gcc/plugin versions"));
113115 + return 1;
113116 + }
113117 +
113118 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
113119 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
113120 + if (!in_lto_p)
113121 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
113122 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
113123 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113124 +
113125 + return 0;
113126 +}
113127 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
113128 new file mode 100644
113129 index 0000000..a5cb46b
113130 --- /dev/null
113131 +++ b/tools/gcc/randomize_layout_plugin.c
113132 @@ -0,0 +1,915 @@
113133 +/*
113134 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
113135 + * and PaX Team <pageexec@freemail.hu>
113136 + * Licensed under the GPL v2
113137 + *
113138 + * Usage:
113139 + * $ # for 4.5/4.6/C based 4.7
113140 + * $ 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
113141 + * $ # for C++ based 4.7/4.8+
113142 + * $ 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
113143 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
113144 + */
113145 +
113146 +#include "gcc-common.h"
113147 +#include "randomize_layout_seed.h"
113148 +
113149 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
113150 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
113151 +#endif
113152 +
113153 +#define ORIG_TYPE_NAME(node) \
113154 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
113155 +
113156 +int plugin_is_GPL_compatible;
113157 +
113158 +static int performance_mode;
113159 +
113160 +static struct plugin_info randomize_layout_plugin_info = {
113161 + .version = "201402201816",
113162 + .help = "disable\t\t\tdo not activate plugin\n"
113163 + "performance-mode\tenable cacheline-aware layout randomization\n"
113164 +};
113165 +
113166 +/* from old Linux dcache.h */
113167 +static inline unsigned long
113168 +partial_name_hash(unsigned long c, unsigned long prevhash)
113169 +{
113170 + return (prevhash + (c << 4) + (c >> 4)) * 11;
113171 +}
113172 +static inline unsigned int
113173 +name_hash(const unsigned char *name)
113174 +{
113175 + unsigned long hash = 0;
113176 + unsigned int len = strlen((const char *)name);
113177 + while (len--)
113178 + hash = partial_name_hash(*name++, hash);
113179 + return (unsigned int)hash;
113180 +}
113181 +
113182 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113183 +{
113184 + tree type;
113185 +
113186 + *no_add_attrs = true;
113187 + if (TREE_CODE(*node) == FUNCTION_DECL) {
113188 + error("%qE attribute does not apply to functions (%qF)", name, *node);
113189 + return NULL_TREE;
113190 + }
113191 +
113192 + if (TREE_CODE(*node) == PARM_DECL) {
113193 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
113194 + return NULL_TREE;
113195 + }
113196 +
113197 + if (TREE_CODE(*node) == VAR_DECL) {
113198 + error("%qE attribute does not apply to variables (%qD)", name, *node);
113199 + return NULL_TREE;
113200 + }
113201 +
113202 + if (TYPE_P(*node)) {
113203 + type = *node;
113204 + } else {
113205 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
113206 + type = TREE_TYPE(*node);
113207 + }
113208 +
113209 + if (TREE_CODE(type) != RECORD_TYPE) {
113210 + error("%qE attribute used on %qT applies to struct types only", name, type);
113211 + return NULL_TREE;
113212 + }
113213 +
113214 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
113215 + error("%qE attribute is already applied to the type %qT", name, type);
113216 + return NULL_TREE;
113217 + }
113218 +
113219 + *no_add_attrs = false;
113220 +
113221 + return NULL_TREE;
113222 +}
113223 +
113224 +/* set on complete types that we don't need to inspect further at all */
113225 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113226 +{
113227 + *no_add_attrs = false;
113228 + return NULL_TREE;
113229 +}
113230 +
113231 +/*
113232 + * set on types that we've performed a shuffle on, to prevent re-shuffling
113233 + * this does not preclude us from inspecting its fields for potential shuffles
113234 + */
113235 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113236 +{
113237 + *no_add_attrs = false;
113238 + return NULL_TREE;
113239 +}
113240 +
113241 +/*
113242 + * 64bit variant of Bob Jenkins' public domain PRNG
113243 + * 256 bits of internal state
113244 + */
113245 +
113246 +typedef unsigned long long u64;
113247 +
113248 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
113249 +
113250 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
113251 +static u64 ranval(ranctx *x) {
113252 + u64 e = x->a - rot(x->b, 7);
113253 + x->a = x->b ^ rot(x->c, 13);
113254 + x->b = x->c + rot(x->d, 37);
113255 + x->c = x->d + e;
113256 + x->d = e + x->a;
113257 + return x->d;
113258 +}
113259 +
113260 +static void raninit(ranctx *x, u64 *seed) {
113261 + int i;
113262 +
113263 + x->a = seed[0];
113264 + x->b = seed[1];
113265 + x->c = seed[2];
113266 + x->d = seed[3];
113267 +
113268 + for (i=0; i < 30; ++i)
113269 + (void)ranval(x);
113270 +}
113271 +
113272 +static u64 shuffle_seed[4];
113273 +
113274 +struct partition_group {
113275 + tree tree_start;
113276 + unsigned long start;
113277 + unsigned long length;
113278 +};
113279 +
113280 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
113281 +{
113282 + unsigned long i;
113283 + unsigned long accum_size = 0;
113284 + unsigned long accum_length = 0;
113285 + unsigned long group_idx = 0;
113286 +
113287 + gcc_assert(length < INT_MAX);
113288 +
113289 + memset(size_groups, 0, sizeof(struct partition_group) * length);
113290 +
113291 + for (i = 0; i < length; i++) {
113292 + if (size_groups[group_idx].tree_start == NULL_TREE) {
113293 + size_groups[group_idx].tree_start = fields[i];
113294 + size_groups[group_idx].start = i;
113295 + accum_length = 0;
113296 + accum_size = 0;
113297 + }
113298 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
113299 + accum_length++;
113300 + if (accum_size >= 64) {
113301 + size_groups[group_idx].length = accum_length;
113302 + accum_length = 0;
113303 + group_idx++;
113304 + }
113305 + }
113306 +
113307 + if (size_groups[group_idx].tree_start != NULL_TREE &&
113308 + !size_groups[group_idx].length) {
113309 + size_groups[group_idx].length = accum_length;
113310 + group_idx++;
113311 + }
113312 +
113313 + *num_groups = group_idx;
113314 +}
113315 +
113316 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113317 +{
113318 + unsigned long i, x;
113319 + struct partition_group size_group[length];
113320 + unsigned long num_groups = 0;
113321 + unsigned long randnum;
113322 +
113323 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113324 + for (i = num_groups - 1; i > 0; i--) {
113325 + struct partition_group tmp;
113326 + randnum = ranval(prng_state) % (i + 1);
113327 + tmp = size_group[i];
113328 + size_group[i] = size_group[randnum];
113329 + size_group[randnum] = tmp;
113330 + }
113331 +
113332 + for (x = 0; x < num_groups; x++) {
113333 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113334 + tree tmp;
113335 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113336 + continue;
113337 + randnum = ranval(prng_state) % (i + 1);
113338 + // we could handle this case differently if desired
113339 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113340 + continue;
113341 + tmp = newtree[i];
113342 + newtree[i] = newtree[randnum];
113343 + newtree[randnum] = tmp;
113344 + }
113345 + }
113346 +}
113347 +
113348 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113349 +{
113350 + unsigned long i, randnum;
113351 +
113352 + for (i = length - 1; i > 0; i--) {
113353 + tree tmp;
113354 + randnum = ranval(prng_state) % (i + 1);
113355 + tmp = newtree[i];
113356 + newtree[i] = newtree[randnum];
113357 + newtree[randnum] = tmp;
113358 + }
113359 +}
113360 +
113361 +/* modern in-place Fisher-Yates shuffle */
113362 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113363 +{
113364 + unsigned long i;
113365 + u64 seed[4];
113366 + ranctx prng_state;
113367 + const unsigned char *structname;
113368 +
113369 + if (length == 0)
113370 + return;
113371 +
113372 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113373 +
113374 + structname = ORIG_TYPE_NAME(type);
113375 +
113376 +#ifdef __DEBUG_PLUGIN
113377 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113378 +#ifdef __DEBUG_VERBOSE
113379 + debug_tree((tree)type);
113380 +#endif
113381 +#endif
113382 +
113383 + for (i = 0; i < 4; i++) {
113384 + seed[i] = shuffle_seed[i];
113385 + seed[i] ^= name_hash(structname);
113386 + }
113387 +
113388 + raninit(&prng_state, (u64 *)&seed);
113389 +
113390 + if (performance_mode)
113391 + performance_shuffle(newtree, length, &prng_state);
113392 + else
113393 + full_shuffle(newtree, length, &prng_state);
113394 +}
113395 +
113396 +static bool is_flexible_array(const_tree field)
113397 +{
113398 + const_tree fieldtype;
113399 + const_tree typesize;
113400 + const_tree elemtype;
113401 + const_tree elemsize;
113402 +
113403 + fieldtype = TREE_TYPE(field);
113404 + typesize = TYPE_SIZE(fieldtype);
113405 +
113406 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113407 + return false;
113408 +
113409 + elemtype = TREE_TYPE(fieldtype);
113410 + elemsize = TYPE_SIZE(elemtype);
113411 +
113412 + /* size of type is represented in bits */
113413 +
113414 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113415 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113416 + return true;
113417 +
113418 + if (typesize != NULL_TREE &&
113419 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113420 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113421 + return true;
113422 +
113423 + return false;
113424 +}
113425 +
113426 +static int relayout_struct(tree type)
113427 +{
113428 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113429 + unsigned long shuffle_length = num_fields;
113430 + tree field;
113431 + tree newtree[num_fields];
113432 + unsigned long i;
113433 + tree list;
113434 + tree variant;
113435 + expanded_location xloc;
113436 +
113437 + if (TYPE_FIELDS(type) == NULL_TREE)
113438 + return 0;
113439 +
113440 + if (num_fields < 2)
113441 + return 0;
113442 +
113443 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113444 +
113445 + gcc_assert(num_fields < INT_MAX);
113446 +
113447 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113448 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113449 + return 0;
113450 +
113451 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113452 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113453 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113454 + return 0;
113455 +
113456 + /* throw out any structs in uapi */
113457 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113458 +
113459 + if (strstr(xloc.file, "/uapi/"))
113460 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113461 +
113462 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113463 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113464 + newtree[i] = field;
113465 + }
113466 +
113467 + /*
113468 + * enforce that we don't randomize the layout of the last
113469 + * element of a struct if it's a 0 or 1-length array
113470 + * or a proper flexible array
113471 + */
113472 + if (is_flexible_array(newtree[num_fields - 1]))
113473 + shuffle_length--;
113474 +
113475 + shuffle(type, (tree *)newtree, shuffle_length);
113476 +
113477 + /*
113478 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113479 + * as gcc provides no other way to detect such code
113480 + */
113481 + list = make_node(FIELD_DECL);
113482 + TREE_CHAIN(list) = newtree[0];
113483 + TREE_TYPE(list) = void_type_node;
113484 + DECL_SIZE(list) = bitsize_zero_node;
113485 + DECL_NONADDRESSABLE_P(list) = 1;
113486 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113487 + DECL_SIZE_UNIT(list) = size_zero_node;
113488 + DECL_FIELD_OFFSET(list) = size_zero_node;
113489 + // to satisfy the constify plugin
113490 + TREE_READONLY(list) = 1;
113491 +
113492 + for (i = 0; i < num_fields - 1; i++)
113493 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113494 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113495 +
113496 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113497 + TYPE_FIELDS(variant) = list;
113498 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113499 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113500 + // force a re-layout
113501 + TYPE_SIZE(variant) = NULL_TREE;
113502 + layout_type(variant);
113503 + }
113504 +
113505 + return 1;
113506 +}
113507 +
113508 +/* from constify plugin */
113509 +static const_tree get_field_type(const_tree field)
113510 +{
113511 + return strip_array_types(TREE_TYPE(field));
113512 +}
113513 +
113514 +/* from constify plugin */
113515 +static bool is_fptr(const_tree fieldtype)
113516 +{
113517 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113518 + return false;
113519 +
113520 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113521 +}
113522 +
113523 +/* derived from constify plugin */
113524 +static int is_pure_ops_struct(const_tree node)
113525 +{
113526 + const_tree field;
113527 +
113528 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113529 +
113530 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113531 + const_tree fieldtype = get_field_type(field);
113532 + enum tree_code code = TREE_CODE(fieldtype);
113533 +
113534 + if (node == fieldtype)
113535 + continue;
113536 +
113537 + if (!is_fptr(fieldtype))
113538 + return 0;
113539 +
113540 + if (code != RECORD_TYPE && code != UNION_TYPE)
113541 + continue;
113542 +
113543 + if (!is_pure_ops_struct(fieldtype))
113544 + return 0;
113545 + }
113546 +
113547 + return 1;
113548 +}
113549 +
113550 +static void randomize_type(tree type)
113551 +{
113552 + tree variant;
113553 +
113554 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113555 +
113556 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113557 + return;
113558 +
113559 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113560 + relayout_struct(type);
113561 +
113562 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113563 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113564 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113565 + }
113566 +#ifdef __DEBUG_PLUGIN
113567 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113568 +#ifdef __DEBUG_VERBOSE
113569 + debug_tree(type);
113570 +#endif
113571 +#endif
113572 +}
113573 +
113574 +static void randomize_layout_finish_decl(void *event_data, void *data)
113575 +{
113576 + tree decl = (tree)event_data;
113577 + tree type;
113578 +
113579 + if (decl == NULL_TREE || decl == error_mark_node)
113580 + return;
113581 +
113582 + type = TREE_TYPE(decl);
113583 +
113584 + if (TREE_CODE(decl) != VAR_DECL)
113585 + return;
113586 +
113587 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113588 + return;
113589 +
113590 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113591 + return;
113592 +
113593 + relayout_decl(decl);
113594 +}
113595 +
113596 +static void finish_type(void *event_data, void *data)
113597 +{
113598 + tree type = (tree)event_data;
113599 +
113600 + if (type == NULL_TREE || type == error_mark_node)
113601 + return;
113602 +
113603 + if (TREE_CODE(type) != RECORD_TYPE)
113604 + return;
113605 +
113606 + if (TYPE_FIELDS(type) == NULL_TREE)
113607 + return;
113608 +
113609 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113610 + return;
113611 +
113612 +#ifdef __DEBUG_PLUGIN
113613 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113614 +#endif
113615 +#ifdef __DEBUG_VERBOSE
113616 + debug_tree(type);
113617 +#endif
113618 + randomize_type(type);
113619 +
113620 + return;
113621 +}
113622 +
113623 +static struct attribute_spec randomize_layout_attr = {
113624 + .name = "randomize_layout",
113625 + // related to args
113626 + .min_length = 0,
113627 + .max_length = 0,
113628 + .decl_required = false,
113629 + // need type declaration
113630 + .type_required = true,
113631 + .function_type_required = false,
113632 + .handler = handle_randomize_layout_attr,
113633 +#if BUILDING_GCC_VERSION >= 4007
113634 + .affects_type_identity = true
113635 +#endif
113636 +};
113637 +
113638 +static struct attribute_spec no_randomize_layout_attr = {
113639 + .name = "no_randomize_layout",
113640 + // related to args
113641 + .min_length = 0,
113642 + .max_length = 0,
113643 + .decl_required = false,
113644 + // need type declaration
113645 + .type_required = true,
113646 + .function_type_required = false,
113647 + .handler = handle_randomize_layout_attr,
113648 +#if BUILDING_GCC_VERSION >= 4007
113649 + .affects_type_identity = true
113650 +#endif
113651 +};
113652 +
113653 +static struct attribute_spec randomize_considered_attr = {
113654 + .name = "randomize_considered",
113655 + // related to args
113656 + .min_length = 0,
113657 + .max_length = 0,
113658 + .decl_required = false,
113659 + // need type declaration
113660 + .type_required = true,
113661 + .function_type_required = false,
113662 + .handler = handle_randomize_considered_attr,
113663 +#if BUILDING_GCC_VERSION >= 4007
113664 + .affects_type_identity = false
113665 +#endif
113666 +};
113667 +
113668 +static struct attribute_spec randomize_performed_attr = {
113669 + .name = "randomize_performed",
113670 + // related to args
113671 + .min_length = 0,
113672 + .max_length = 0,
113673 + .decl_required = false,
113674 + // need type declaration
113675 + .type_required = true,
113676 + .function_type_required = false,
113677 + .handler = handle_randomize_performed_attr,
113678 +#if BUILDING_GCC_VERSION >= 4007
113679 + .affects_type_identity = false
113680 +#endif
113681 +};
113682 +
113683 +static void register_attributes(void *event_data, void *data)
113684 +{
113685 + register_attribute(&randomize_layout_attr);
113686 + register_attribute(&no_randomize_layout_attr);
113687 + register_attribute(&randomize_considered_attr);
113688 + register_attribute(&randomize_performed_attr);
113689 +}
113690 +
113691 +static void check_bad_casts_in_constructor(tree var, tree init)
113692 +{
113693 + unsigned HOST_WIDE_INT idx;
113694 + tree field, val;
113695 + tree field_type, val_type;
113696 +
113697 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113698 + if (TREE_CODE(val) == CONSTRUCTOR) {
113699 + check_bad_casts_in_constructor(var, val);
113700 + continue;
113701 + }
113702 +
113703 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113704 + normal code which all have valid 'field' trees. work around this */
113705 + if (field == NULL_TREE)
113706 + continue;
113707 + field_type = TREE_TYPE(field);
113708 + val_type = TREE_TYPE(val);
113709 +
113710 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113711 + continue;
113712 +
113713 + if (field_type == val_type)
113714 + continue;
113715 +
113716 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113717 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113718 +
113719 + if (field_type == void_type_node)
113720 + continue;
113721 + if (field_type == val_type)
113722 + continue;
113723 + if (TREE_CODE(val_type) != RECORD_TYPE)
113724 + continue;
113725 +
113726 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113727 + continue;
113728 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113729 + }
113730 +}
113731 +
113732 +/* derived from the constify plugin */
113733 +static void check_global_variables(void *event_data, void *data)
113734 +{
113735 + struct varpool_node *node;
113736 + tree init;
113737 +
113738 + FOR_EACH_VARIABLE(node) {
113739 + tree var = NODE_DECL(node);
113740 + init = DECL_INITIAL(var);
113741 + if (init == NULL_TREE)
113742 + continue;
113743 +
113744 + if (TREE_CODE(init) != CONSTRUCTOR)
113745 + continue;
113746 +
113747 + check_bad_casts_in_constructor(var, init);
113748 + }
113749 +}
113750 +
113751 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113752 +{
113753 + basic_block dom;
113754 + gimple dom_stmt;
113755 + gimple call_stmt;
113756 + const_tree dom_lhs;
113757 + const_tree poss_is_err_cond;
113758 + const_tree poss_is_err_func;
113759 + const_tree is_err_arg;
113760 +
113761 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113762 + if (!dom)
113763 + return false;
113764 +
113765 + dom_stmt = last_stmt(dom);
113766 + if (!dom_stmt)
113767 + return false;
113768 +
113769 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113770 + return false;
113771 +
113772 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113773 + return false;
113774 +
113775 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113776 + return false;
113777 +
113778 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113779 +
113780 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113781 + return false;
113782 +
113783 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113784 +
113785 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113786 + return false;
113787 +
113788 + dom_lhs = gimple_get_lhs(call_stmt);
113789 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113790 + if (!poss_is_err_func)
113791 + return false;
113792 + if (dom_lhs != poss_is_err_cond)
113793 + return false;
113794 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113795 + return false;
113796 +
113797 + is_err_arg = gimple_call_arg(call_stmt, 0);
113798 + if (!is_err_arg)
113799 + return false;
113800 +
113801 + if (is_err_arg != rhs)
113802 + return false;
113803 +
113804 + return true;
113805 +}
113806 +
113807 +static void handle_local_var_initializers(void)
113808 +{
113809 + tree var;
113810 + unsigned int i;
113811 +
113812 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113813 + tree init = DECL_INITIAL(var);
113814 + if (!init)
113815 + continue;
113816 + if (TREE_CODE(init) != CONSTRUCTOR)
113817 + continue;
113818 + check_bad_casts_in_constructor(var, init);
113819 + }
113820 +}
113821 +
113822 +/*
113823 + * iterate over all statements to find "bad" casts:
113824 + * those where the address of the start of a structure is cast
113825 + * to a pointer of a structure of a different type, or a
113826 + * structure pointer type is cast to a different structure pointer type
113827 + */
113828 +static unsigned int find_bad_casts(void)
113829 +{
113830 + basic_block bb;
113831 +
113832 + handle_local_var_initializers();
113833 +
113834 + FOR_ALL_BB_FN(bb, cfun) {
113835 + gimple_stmt_iterator gsi;
113836 +
113837 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113838 + gimple stmt;
113839 + const_tree lhs;
113840 + const_tree lhs_type;
113841 + const_tree rhs1;
113842 + const_tree rhs_type;
113843 + const_tree ptr_lhs_type;
113844 + const_tree ptr_rhs_type;
113845 + const_tree op0;
113846 + const_tree op0_type;
113847 + enum tree_code rhs_code;
113848 +
113849 + stmt = gsi_stmt(gsi);
113850 +
113851 +#ifdef __DEBUG_PLUGIN
113852 +#ifdef __DEBUG_VERBOSE
113853 + debug_gimple_stmt(stmt);
113854 + debug_tree(gimple_get_lhs(stmt));
113855 +#endif
113856 +#endif
113857 +
113858 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113859 + continue;
113860 +
113861 +#ifdef __DEBUG_PLUGIN
113862 +#ifdef __DEBUG_VERBOSE
113863 + debug_tree(gimple_assign_rhs1(stmt));
113864 +#endif
113865 +#endif
113866 +
113867 + rhs_code = gimple_assign_rhs_code(stmt);
113868 +
113869 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113870 + continue;
113871 +
113872 + lhs = gimple_get_lhs(stmt);
113873 + lhs_type = TREE_TYPE(lhs);
113874 + rhs1 = gimple_assign_rhs1(stmt);
113875 + rhs_type = TREE_TYPE(rhs1);
113876 +
113877 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113878 + TREE_CODE(lhs_type) != POINTER_TYPE)
113879 + continue;
113880 +
113881 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113882 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113883 +
113884 + if (ptr_rhs_type == void_type_node)
113885 + continue;
113886 +
113887 + if (ptr_lhs_type == void_type_node)
113888 + continue;
113889 +
113890 + if (dominated_by_is_err(rhs1, bb))
113891 + continue;
113892 +
113893 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113894 +#ifndef __DEBUG_PLUGIN
113895 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113896 +#endif
113897 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113898 + continue;
113899 + }
113900 +
113901 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113902 + continue;
113903 +
113904 + if (rhs_code == ADDR_EXPR) {
113905 + op0 = TREE_OPERAND(rhs1, 0);
113906 +
113907 + if (op0 == NULL_TREE)
113908 + continue;
113909 +
113910 + if (TREE_CODE(op0) != VAR_DECL)
113911 + continue;
113912 +
113913 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113914 + if (op0_type == ptr_lhs_type)
113915 + continue;
113916 +
113917 +#ifndef __DEBUG_PLUGIN
113918 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113919 +#endif
113920 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113921 + } else {
113922 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113923 + /* skip bogus type casts introduced by container_of */
113924 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113925 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113926 + continue;
113927 +#ifndef __DEBUG_PLUGIN
113928 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113929 +#endif
113930 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113931 + }
113932 +
113933 + }
113934 + }
113935 + return 0;
113936 +}
113937 +
113938 +#if BUILDING_GCC_VERSION >= 4009
113939 +static const struct pass_data randomize_layout_bad_cast_data = {
113940 +#else
113941 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113942 + .pass = {
113943 +#endif
113944 + .type = GIMPLE_PASS,
113945 + .name = "randomize_layout_bad_cast",
113946 +#if BUILDING_GCC_VERSION >= 4008
113947 + .optinfo_flags = OPTGROUP_NONE,
113948 +#endif
113949 +#if BUILDING_GCC_VERSION >= 4009
113950 + .has_gate = false,
113951 + .has_execute = true,
113952 +#else
113953 + .gate = NULL,
113954 + .execute = find_bad_casts,
113955 + .sub = NULL,
113956 + .next = NULL,
113957 + .static_pass_number = 0,
113958 +#endif
113959 + .tv_id = TV_NONE,
113960 + .properties_required = PROP_cfg,
113961 + .properties_provided = 0,
113962 + .properties_destroyed = 0,
113963 + .todo_flags_start = 0,
113964 + .todo_flags_finish = TODO_dump_func
113965 +#if BUILDING_GCC_VERSION < 4009
113966 + }
113967 +#endif
113968 +};
113969 +
113970 +#if BUILDING_GCC_VERSION >= 4009
113971 +namespace {
113972 +class randomize_layout_bad_cast : public gimple_opt_pass {
113973 +public:
113974 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113975 + unsigned int execute() { return find_bad_casts(); }
113976 +};
113977 +}
113978 +#endif
113979 +
113980 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113981 +{
113982 +#if BUILDING_GCC_VERSION >= 4009
113983 + return new randomize_layout_bad_cast();
113984 +#else
113985 + return &randomize_layout_bad_cast.pass;
113986 +#endif
113987 +}
113988 +
113989 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113990 +{
113991 + int i;
113992 + const char * const plugin_name = plugin_info->base_name;
113993 + const int argc = plugin_info->argc;
113994 + const struct plugin_argument * const argv = plugin_info->argv;
113995 + bool enable = true;
113996 + int obtained_seed = 0;
113997 + struct register_pass_info randomize_layout_bad_cast_info;
113998 +
113999 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
114000 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
114001 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
114002 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
114003 +
114004 + if (!plugin_default_version_check(version, &gcc_version)) {
114005 + error(G_("incompatible gcc/plugin versions"));
114006 + return 1;
114007 + }
114008 +
114009 + if (strcmp(lang_hooks.name, "GNU C")) {
114010 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
114011 + enable = false;
114012 + }
114013 +
114014 + for (i = 0; i < argc; ++i) {
114015 + if (!strcmp(argv[i].key, "disable")) {
114016 + enable = false;
114017 + continue;
114018 + }
114019 + if (!strcmp(argv[i].key, "performance-mode")) {
114020 + performance_mode = 1;
114021 + continue;
114022 + }
114023 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
114024 + }
114025 +
114026 + if (strlen(randstruct_seed) != 64) {
114027 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
114028 + return 1;
114029 + }
114030 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
114031 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
114032 + if (obtained_seed != 4) {
114033 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
114034 + return 1;
114035 + }
114036 +
114037 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
114038 + if (enable) {
114039 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
114040 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
114041 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
114042 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
114043 + }
114044 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
114045 +
114046 + return 0;
114047 +}
114048 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
114049 new file mode 100644
114050 index 0000000..1f0214f
114051 --- /dev/null
114052 +++ b/tools/gcc/size_overflow_plugin/.gitignore
114053 @@ -0,0 +1,3 @@
114054 +randomize_layout_seed.h
114055 +size_overflow_hash.h
114056 +size_overflow_hash_aux.h
114057 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
114058 new file mode 100644
114059 index 0000000..1ae2ed5
114060 --- /dev/null
114061 +++ b/tools/gcc/size_overflow_plugin/Makefile
114062 @@ -0,0 +1,20 @@
114063 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
114064 +always := $($(HOSTLIBS)-y)
114065 +
114066 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
114067 +
114068 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
114069 +
114070 +quiet_cmd_build_size_overflow_hash = GENHASH $@
114071 + cmd_build_size_overflow_hash = \
114072 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
114073 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
114074 + $(call if_changed,build_size_overflow_hash)
114075 +
114076 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
114077 + cmd_build_size_overflow_hash_aux = \
114078 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
114079 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
114080 + $(call if_changed,build_size_overflow_hash_aux)
114081 +
114082 +targets += size_overflow_hash.h size_overflow_hash_aux.h
114083 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114084 new file mode 100644
114085 index 0000000..12b1e3b
114086 --- /dev/null
114087 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114088 @@ -0,0 +1,102 @@
114089 +#!/bin/bash
114090 +
114091 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
114092 +
114093 +header1="size_overflow_hash.h"
114094 +database="size_overflow_hash.data"
114095 +n=65536
114096 +hashtable_name="size_overflow_hash"
114097 +
114098 +usage() {
114099 +cat <<EOF
114100 +usage: $0 options
114101 +OPTIONS:
114102 + -h|--help help
114103 + -o header file
114104 + -d database file
114105 + -n hash array size
114106 + -s name of the hash table
114107 +EOF
114108 + return 0
114109 +}
114110 +
114111 +while true
114112 +do
114113 + case "$1" in
114114 + -h|--help) usage && exit 0;;
114115 + -n) n=$2; shift 2;;
114116 + -o) header1="$2"; shift 2;;
114117 + -d) database="$2"; shift 2;;
114118 + -s) hashtable_name="$2"; shift 2;;
114119 + --) shift 1; break ;;
114120 + *) break ;;
114121 + esac
114122 +done
114123 +
114124 +create_defines() {
114125 + for i in `seq 0 31`
114126 + do
114127 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
114128 + done
114129 + echo >> "$header1"
114130 +}
114131 +
114132 +create_structs() {
114133 + rm -f "$header1"
114134 +
114135 + create_defines
114136 +
114137 + cat "$database" | while read data
114138 + do
114139 + data_array=($data)
114140 + struct_hash_name="${data_array[0]}"
114141 + funcn="${data_array[1]}"
114142 + params="${data_array[2]}"
114143 + next="${data_array[4]}"
114144 +
114145 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
114146 +
114147 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
114148 + echo -en "\t.param\t= " >> "$header1"
114149 + line=
114150 + for param_num in ${params//-/ };
114151 + do
114152 + line="${line}PARAM"$param_num"|"
114153 + done
114154 +
114155 + echo -e "${line%?},\n};\n" >> "$header1"
114156 + done
114157 +}
114158 +
114159 +create_headers() {
114160 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
114161 +}
114162 +
114163 +create_array_elements() {
114164 + index=0
114165 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
114166 + do
114167 + data_array=($data)
114168 + i="${data_array[3]}"
114169 + hash="${data_array[0]}"
114170 + while [[ $index -lt $i ]]
114171 + do
114172 + echo -e "\t["$index"]\t= NULL," >> "$header1"
114173 + index=$(($index + 1))
114174 + done
114175 + index=$(($index + 1))
114176 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
114177 + done
114178 + echo '};' >> $header1
114179 +}
114180 +
114181 +size_overflow_plugin_dir=`dirname $header1`
114182 +if [ "$size_overflow_plugin_dir" != '.' ]; then
114183 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
114184 +fi
114185 +
114186 +create_structs
114187 +create_headers
114188 +create_array_elements
114189 +
114190 +exit 0
114191 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114192 new file mode 100644
114193 index 0000000..c43901f
114194 --- /dev/null
114195 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114196 @@ -0,0 +1,748 @@
114197 +/*
114198 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114199 + * Licensed under the GPL v2, or (at your option) v3
114200 + *
114201 + * Homepage:
114202 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114203 + *
114204 + * Documentation:
114205 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114206 + *
114207 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114208 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114209 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114210 + *
114211 + * Usage:
114212 + * $ make
114213 + * $ make run
114214 + */
114215 +
114216 +#include "gcc-common.h"
114217 +#include "size_overflow.h"
114218 +
114219 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114220 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114221 +
114222 +// data for the size_overflow asm stmt
114223 +struct asm_data {
114224 + gimple def_stmt;
114225 + tree input;
114226 + tree output;
114227 +};
114228 +
114229 +#if BUILDING_GCC_VERSION <= 4007
114230 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
114231 +#else
114232 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
114233 +#endif
114234 +{
114235 + tree list;
114236 +#if BUILDING_GCC_VERSION <= 4007
114237 + VEC(tree, gc) *vec_list = NULL;
114238 +#else
114239 + vec<tree, va_gc> *vec_list = NULL;
114240 +#endif
114241 +
114242 + list = build_tree_list(NULL_TREE, string);
114243 + list = chainon(NULL_TREE, build_tree_list(list, io));
114244 +#if BUILDING_GCC_VERSION <= 4007
114245 + VEC_safe_push(tree, gc, vec_list, list);
114246 +#else
114247 + vec_safe_push(vec_list, list);
114248 +#endif
114249 + return vec_list;
114250 +}
114251 +
114252 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
114253 +{
114254 + gimple asm_stmt;
114255 + gimple_stmt_iterator gsi;
114256 +#if BUILDING_GCC_VERSION <= 4007
114257 + VEC(tree, gc) *input, *output = NULL;
114258 +#else
114259 + vec<tree, va_gc> *input, *output = NULL;
114260 +#endif
114261 +
114262 + input = create_asm_io_list(str_input, asm_data->input);
114263 +
114264 + if (asm_data->output)
114265 + output = create_asm_io_list(str_output, asm_data->output);
114266 +
114267 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
114268 + gsi = gsi_for_stmt(asm_data->def_stmt);
114269 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
114270 +
114271 + if (asm_data->output)
114272 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
114273 +}
114274 +
114275 +static void replace_call_lhs(const struct asm_data *asm_data)
114276 +{
114277 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
114278 + update_stmt(asm_data->def_stmt);
114279 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
114280 +}
114281 +
114282 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
114283 +{
114284 + enum mark cur_fndecl_attr;
114285 + gimple phi = get_def_stmt(result);
114286 + unsigned int i, n = gimple_phi_num_args(phi);
114287 +
114288 + pointer_set_insert(visited, phi);
114289 + for (i = 0; i < n; i++) {
114290 + tree arg = gimple_phi_arg_def(phi, i);
114291 +
114292 + cur_fndecl_attr = search_intentional(visited, arg);
114293 + if (cur_fndecl_attr != MARK_NO)
114294 + return cur_fndecl_attr;
114295 + }
114296 + return MARK_NO;
114297 +}
114298 +
114299 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
114300 +{
114301 + enum mark cur_fndecl_attr;
114302 + const_tree rhs1, rhs2;
114303 + gimple def_stmt = get_def_stmt(lhs);
114304 +
114305 + rhs1 = gimple_assign_rhs1(def_stmt);
114306 + rhs2 = gimple_assign_rhs2(def_stmt);
114307 +
114308 + cur_fndecl_attr = search_intentional(visited, rhs1);
114309 + if (cur_fndecl_attr != MARK_NO)
114310 + return cur_fndecl_attr;
114311 + return search_intentional(visited, rhs2);
114312 +}
114313 +
114314 +// Look up the intentional_overflow attribute on the caller and the callee functions.
114315 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
114316 +{
114317 + const_gimple def_stmt;
114318 +
114319 + if (TREE_CODE(lhs) != SSA_NAME)
114320 + return get_intentional_attr_type(lhs);
114321 +
114322 + def_stmt = get_def_stmt(lhs);
114323 + if (!def_stmt)
114324 + return MARK_NO;
114325 +
114326 + if (pointer_set_contains(visited, def_stmt))
114327 + return MARK_NO;
114328 +
114329 + switch (gimple_code(def_stmt)) {
114330 + case GIMPLE_NOP:
114331 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114332 + case GIMPLE_ASM:
114333 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114334 + return MARK_TURN_OFF;
114335 + return MARK_NO;
114336 + case GIMPLE_CALL:
114337 + return MARK_NO;
114338 + case GIMPLE_PHI:
114339 + return search_intentional_phi(visited, lhs);
114340 + case GIMPLE_ASSIGN:
114341 + switch (gimple_num_ops(def_stmt)) {
114342 + case 2:
114343 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114344 + case 3:
114345 + return search_intentional_binary(visited, lhs);
114346 + }
114347 + case GIMPLE_RETURN:
114348 + return MARK_NO;
114349 + default:
114350 + debug_gimple_stmt((gimple)def_stmt);
114351 + error("%s: unknown gimple code", __func__);
114352 + gcc_unreachable();
114353 + }
114354 +}
114355 +
114356 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114357 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114358 +{
114359 + const_tree fndecl;
114360 + struct pointer_set_t *visited;
114361 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114362 +
114363 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114364 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114365 + decl_attr = MARK_NOT_INTENTIONAL;
114366 + else if (is_yes_intentional_attr(fndecl, argnum))
114367 + decl_attr = MARK_YES;
114368 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114369 + return MARK_TURN_OFF;
114370 + }
114371 +
114372 + visited = pointer_set_create();
114373 + cur_fndecl_attr = search_intentional(visited, arg);
114374 + pointer_set_destroy(visited);
114375 +
114376 + switch (cur_fndecl_attr) {
114377 + case MARK_NO:
114378 + case MARK_TURN_OFF:
114379 + return cur_fndecl_attr;
114380 + default:
114381 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114382 + return MARK_YES;
114383 + }
114384 +}
114385 +
114386 +static void check_missing_size_overflow_attribute(tree var)
114387 +{
114388 + tree orig_fndecl;
114389 + unsigned int num;
114390 +
114391 + if (is_a_return_check(var))
114392 + orig_fndecl = DECL_ORIGIN(var);
114393 + else
114394 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114395 +
114396 + num = get_function_num(var, orig_fndecl);
114397 + if (num == CANNOT_FIND_ARG)
114398 + return;
114399 +
114400 + is_missing_function(orig_fndecl, num);
114401 +}
114402 +
114403 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114404 +{
114405 + gimple phi = get_def_stmt(result);
114406 + unsigned int i, n = gimple_phi_num_args(phi);
114407 +
114408 + pointer_set_insert(visited, phi);
114409 + for (i = 0; i < n; i++) {
114410 + tree arg = gimple_phi_arg_def(phi, i);
114411 +
114412 + search_size_overflow_attribute(visited, arg);
114413 + }
114414 +}
114415 +
114416 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114417 +{
114418 + const_gimple def_stmt = get_def_stmt(lhs);
114419 + tree rhs1, rhs2;
114420 +
114421 + rhs1 = gimple_assign_rhs1(def_stmt);
114422 + rhs2 = gimple_assign_rhs2(def_stmt);
114423 +
114424 + search_size_overflow_attribute(visited, rhs1);
114425 + search_size_overflow_attribute(visited, rhs2);
114426 +}
114427 +
114428 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114429 +{
114430 + const_gimple def_stmt;
114431 +
114432 + if (TREE_CODE(lhs) == PARM_DECL) {
114433 + check_missing_size_overflow_attribute(lhs);
114434 + return;
114435 + }
114436 +
114437 + def_stmt = get_def_stmt(lhs);
114438 + if (!def_stmt)
114439 + return;
114440 +
114441 + if (pointer_set_insert(visited, def_stmt))
114442 + return;
114443 +
114444 + switch (gimple_code(def_stmt)) {
114445 + case GIMPLE_NOP:
114446 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114447 + case GIMPLE_ASM:
114448 + return;
114449 + case GIMPLE_CALL: {
114450 + tree fndecl = gimple_call_fndecl(def_stmt);
114451 +
114452 + if (fndecl == NULL_TREE)
114453 + return;
114454 + check_missing_size_overflow_attribute(fndecl);
114455 + return;
114456 + }
114457 + case GIMPLE_PHI:
114458 + return search_size_overflow_attribute_phi(visited, lhs);
114459 + case GIMPLE_ASSIGN:
114460 + switch (gimple_num_ops(def_stmt)) {
114461 + case 2:
114462 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114463 + case 3:
114464 + return search_size_overflow_attribute_binary(visited, lhs);
114465 + }
114466 + default:
114467 + debug_gimple_stmt((gimple)def_stmt);
114468 + error("%s: unknown gimple code", __func__);
114469 + gcc_unreachable();
114470 + }
114471 +}
114472 +
114473 +// Search missing entries in the hash table (invoked from the gimple pass)
114474 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114475 +{
114476 + tree fndecl = NULL_TREE;
114477 + tree lhs;
114478 + struct pointer_set_t *visited;
114479 +
114480 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114481 + return;
114482 +
114483 + if (num == 0) {
114484 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114485 + lhs = gimple_return_retval(stmt);
114486 + } else {
114487 + gcc_assert(is_gimple_call(stmt));
114488 + lhs = gimple_call_arg(stmt, num - 1);
114489 + fndecl = gimple_call_fndecl(stmt);
114490 + }
114491 +
114492 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114493 + return;
114494 +
114495 + visited = pointer_set_create();
114496 + search_size_overflow_attribute(visited, lhs);
114497 + pointer_set_destroy(visited);
114498 +}
114499 +
114500 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114501 +{
114502 + gimple_stmt_iterator gsi;
114503 + gimple assign;
114504 +
114505 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114506 + gsi = gsi_for_stmt(stmt);
114507 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114508 + asm_data->def_stmt = assign;
114509 +
114510 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114511 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114512 + if (gimple_code(stmt) == GIMPLE_RETURN)
114513 + gimple_return_set_retval(stmt, asm_data->output);
114514 + else
114515 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114516 + update_stmt(stmt);
114517 +}
114518 +
114519 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114520 +{
114521 + const char *fn_name;
114522 + char *asm_comment;
114523 + unsigned int len;
114524 +
114525 + if (argnum == 0)
114526 + fn_name = DECL_NAME_POINTER(current_function_decl);
114527 + else
114528 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114529 +
114530 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114531 + gcc_assert(len > 0);
114532 +
114533 + return asm_comment;
114534 +}
114535 +
114536 +static const char *convert_mark_to_str(enum mark mark)
114537 +{
114538 + switch (mark) {
114539 + case MARK_NO:
114540 + return OK_ASM_STR;
114541 + case MARK_YES:
114542 + case MARK_NOT_INTENTIONAL:
114543 + return YES_ASM_STR;
114544 + case MARK_TURN_OFF:
114545 + return TURN_OFF_ASM_STR;
114546 + }
114547 +
114548 + gcc_unreachable();
114549 +}
114550 +
114551 +/* Create the input of the size_overflow asm stmt.
114552 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114553 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114554 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114555 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114556 + */
114557 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114558 +{
114559 + if (!asm_data->def_stmt) {
114560 + asm_data->input = NULL_TREE;
114561 + return;
114562 + }
114563 +
114564 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114565 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114566 +
114567 + switch (gimple_code(asm_data->def_stmt)) {
114568 + case GIMPLE_ASSIGN:
114569 + case GIMPLE_CALL:
114570 + replace_call_lhs(asm_data);
114571 + break;
114572 + case GIMPLE_PHI:
114573 + create_output_from_phi(stmt, argnum, asm_data);
114574 + break;
114575 + case GIMPLE_NOP: {
114576 + enum mark mark;
114577 + const char *mark_str;
114578 + char *asm_comment;
114579 +
114580 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114581 +
114582 + asm_data->input = asm_data->output;
114583 + asm_data->output = NULL;
114584 + asm_data->def_stmt = stmt;
114585 +
114586 + mark_str = convert_mark_to_str(mark);
114587 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114588 +
114589 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114590 + free(asm_comment);
114591 + asm_data->input = NULL_TREE;
114592 + break;
114593 + }
114594 + case GIMPLE_ASM:
114595 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114596 + asm_data->input = NULL_TREE;
114597 + break;
114598 + }
114599 + default:
114600 + debug_gimple_stmt(asm_data->def_stmt);
114601 + gcc_unreachable();
114602 + }
114603 +}
114604 +
114605 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114606 + * is of the right kind create the appropriate size_overflow asm stmts:
114607 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114608 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114609 + */
114610 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114611 +{
114612 + struct asm_data asm_data;
114613 + const char *mark_str;
114614 + char *asm_comment;
114615 + enum mark mark;
114616 +
114617 + if (is_gimple_constant(output_node))
114618 + return;
114619 +
114620 + asm_data.output = output_node;
114621 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114622 + if (mark != MARK_TURN_OFF)
114623 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114624 +
114625 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114626 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114627 + return;
114628 +
114629 + create_asm_input(stmt, argnum, &asm_data);
114630 + if (asm_data.input == NULL_TREE)
114631 + return;
114632 +
114633 + mark_str = convert_mark_to_str(mark);
114634 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114635 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114636 + free(asm_comment);
114637 +}
114638 +
114639 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114640 +static bool create_mark_asm(gimple stmt, enum mark mark)
114641 +{
114642 + struct asm_data asm_data;
114643 + const char *asm_str;
114644 +
114645 + switch (mark) {
114646 + case MARK_TURN_OFF:
114647 + asm_str = TURN_OFF_ASM_STR;
114648 + break;
114649 + case MARK_NOT_INTENTIONAL:
114650 + case MARK_YES:
114651 + asm_str = YES_ASM_STR;
114652 + break;
114653 + default:
114654 + gcc_unreachable();
114655 + }
114656 +
114657 + asm_data.def_stmt = stmt;
114658 + asm_data.output = gimple_call_lhs(stmt);
114659 +
114660 + if (asm_data.output == NULL_TREE) {
114661 + asm_data.input = gimple_call_arg(stmt, 0);
114662 + if (is_gimple_constant(asm_data.input))
114663 + return false;
114664 + asm_data.output = NULL;
114665 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114666 + return true;
114667 + }
114668 +
114669 + create_asm_input(stmt, 0, &asm_data);
114670 + gcc_assert(asm_data.input != NULL_TREE);
114671 +
114672 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114673 + return true;
114674 +}
114675 +
114676 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114677 +{
114678 + gimple def_stmt;
114679 +
114680 + def_stmt = get_def_stmt(lhs);
114681 + if (!def_stmt)
114682 + return;
114683 +
114684 + if (pointer_set_insert(visited, def_stmt))
114685 + return;
114686 +
114687 + switch (gimple_code(def_stmt)) {
114688 + case GIMPLE_NOP:
114689 + case GIMPLE_ASM:
114690 + case GIMPLE_CALL:
114691 + break;
114692 + case GIMPLE_PHI: {
114693 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114694 +
114695 + pointer_set_insert(visited, def_stmt);
114696 +
114697 + for (i = 0; i < n; i++) {
114698 + tree arg = gimple_phi_arg_def(def_stmt, i);
114699 +
114700 + walk_use_def_ptr(visited, arg);
114701 + }
114702 + }
114703 + case GIMPLE_ASSIGN:
114704 + switch (gimple_num_ops(def_stmt)) {
114705 + case 2:
114706 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114707 + return;
114708 + case 3:
114709 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114710 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114711 + return;
114712 + default:
114713 + return;
114714 + }
114715 + default:
114716 + debug_gimple_stmt((gimple)def_stmt);
114717 + error("%s: unknown gimple code", __func__);
114718 + gcc_unreachable();
114719 + }
114720 +}
114721 +
114722 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114723 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114724 +{
114725 + struct pointer_set_t *visited;
114726 +
114727 + visited = pointer_set_create();
114728 + walk_use_def_ptr(visited, arg);
114729 + pointer_set_destroy(visited);
114730 +}
114731 +
114732 +// Determine the return value and insert the asm stmt to mark the return stmt.
114733 +static void insert_asm_ret(gimple stmt)
114734 +{
114735 + tree ret;
114736 +
114737 + ret = gimple_return_retval(stmt);
114738 + create_size_overflow_asm(stmt, ret, 0);
114739 +}
114740 +
114741 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114742 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114743 +{
114744 + tree arg;
114745 + unsigned int argnum;
114746 +
114747 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114748 + gcc_assert(argnum != 0);
114749 + if (argnum == CANNOT_FIND_ARG)
114750 + return;
114751 +
114752 + arg = gimple_call_arg(stmt, argnum - 1);
114753 + gcc_assert(arg != NULL_TREE);
114754 +
114755 + // skip all ptr - ptr expressions
114756 + insert_mark_not_intentional_asm_at_ptr(arg);
114757 +
114758 + create_size_overflow_asm(stmt, arg, argnum);
114759 +}
114760 +
114761 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114762 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114763 +{
114764 + unsigned int argnum;
114765 + tree attr_value;
114766 +
114767 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114768 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114769 + argnums[argnum] = true;
114770 + }
114771 +}
114772 +
114773 +// If a function arg or the return value is in the hash table then set its index in the array.
114774 +static void set_argnum_hash(tree fndecl, bool *argnums)
114775 +{
114776 + unsigned int num;
114777 + const struct size_overflow_hash *hash;
114778 +
114779 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114780 + if (!hash)
114781 + return;
114782 +
114783 + for (num = 0; num <= MAX_PARAM; num++) {
114784 + if (!(hash->param & (1U << num)))
114785 + continue;
114786 +
114787 + argnums[num] = true;
114788 + }
114789 +}
114790 +
114791 +static bool is_all_the_argnums_empty(bool *argnums)
114792 +{
114793 + unsigned int i;
114794 +
114795 + for (i = 0; i <= MAX_PARAM; i++)
114796 + if (argnums[i])
114797 + return false;
114798 + return true;
114799 +}
114800 +
114801 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114802 +static void search_interesting_args(tree fndecl, bool *argnums)
114803 +{
114804 + const_tree attr;
114805 +
114806 + set_argnum_hash(fndecl, argnums);
114807 + if (!is_all_the_argnums_empty(argnums))
114808 + return;
114809 +
114810 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114811 + if (attr && TREE_VALUE(attr))
114812 + set_argnum_attribute(attr, argnums);
114813 +}
114814 +
114815 +/*
114816 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114817 + * on the callee function.
114818 + */
114819 +static bool is_mark_turn_off_attribute(gimple stmt)
114820 +{
114821 + enum mark mark;
114822 + const_tree fndecl = gimple_call_fndecl(stmt);
114823 +
114824 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114825 + if (mark == MARK_TURN_OFF)
114826 + return true;
114827 + return false;
114828 +}
114829 +
114830 +// 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
114831 +static void handle_interesting_function(gimple stmt)
114832 +{
114833 + unsigned int argnum;
114834 + tree fndecl;
114835 + bool orig_argnums[MAX_PARAM + 1] = {false};
114836 +
114837 + if (gimple_call_num_args(stmt) == 0)
114838 + return;
114839 + fndecl = gimple_call_fndecl(stmt);
114840 + if (fndecl == NULL_TREE)
114841 + return;
114842 + fndecl = DECL_ORIGIN(fndecl);
114843 +
114844 + if (is_mark_turn_off_attribute(stmt)) {
114845 + create_mark_asm(stmt, MARK_TURN_OFF);
114846 + return;
114847 + }
114848 +
114849 + search_interesting_args(fndecl, orig_argnums);
114850 +
114851 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114852 + if (orig_argnums[argnum])
114853 + insert_asm_arg(stmt, argnum);
114854 +}
114855 +
114856 +// 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
114857 +static void handle_interesting_ret(gimple stmt)
114858 +{
114859 + bool orig_argnums[MAX_PARAM + 1] = {false};
114860 +
114861 + search_interesting_args(current_function_decl, orig_argnums);
114862 +
114863 + if (orig_argnums[0])
114864 + insert_asm_ret(stmt);
114865 +}
114866 +
114867 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114868 +static unsigned int search_interesting_functions(void)
114869 +{
114870 + basic_block bb;
114871 +
114872 + FOR_ALL_BB_FN(bb, cfun) {
114873 + gimple_stmt_iterator gsi;
114874 +
114875 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114876 + gimple stmt = gsi_stmt(gsi);
114877 +
114878 + if (is_size_overflow_asm(stmt))
114879 + continue;
114880 +
114881 + if (is_gimple_call(stmt))
114882 + handle_interesting_function(stmt);
114883 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114884 + handle_interesting_ret(stmt);
114885 + }
114886 + }
114887 + return 0;
114888 +}
114889 +
114890 +/*
114891 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114892 + * this pass inserts asm stmts to mark the interesting args
114893 + * that the ipa pass will detect and insert the size overflow checks for.
114894 + */
114895 +#if BUILDING_GCC_VERSION >= 4009
114896 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114897 +#else
114898 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114899 + .pass = {
114900 +#endif
114901 + .type = GIMPLE_PASS,
114902 + .name = "insert_size_overflow_asm",
114903 +#if BUILDING_GCC_VERSION >= 4008
114904 + .optinfo_flags = OPTGROUP_NONE,
114905 +#endif
114906 +#if BUILDING_GCC_VERSION >= 4009
114907 + .has_gate = false,
114908 + .has_execute = true,
114909 +#else
114910 + .gate = NULL,
114911 + .execute = search_interesting_functions,
114912 + .sub = NULL,
114913 + .next = NULL,
114914 + .static_pass_number = 0,
114915 +#endif
114916 + .tv_id = TV_NONE,
114917 + .properties_required = PROP_cfg,
114918 + .properties_provided = 0,
114919 + .properties_destroyed = 0,
114920 + .todo_flags_start = 0,
114921 + .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
114922 +#if BUILDING_GCC_VERSION < 4009
114923 + }
114924 +#endif
114925 +};
114926 +
114927 +#if BUILDING_GCC_VERSION >= 4009
114928 +namespace {
114929 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114930 +public:
114931 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114932 + unsigned int execute() { return search_interesting_functions(); }
114933 +};
114934 +}
114935 +#endif
114936 +
114937 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114938 +{
114939 +#if BUILDING_GCC_VERSION >= 4009
114940 + return new insert_size_overflow_asm_pass();
114941 +#else
114942 + return &insert_size_overflow_asm_pass.pass;
114943 +#endif
114944 +}
114945 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
114946 new file mode 100644
114947 index 0000000..73f0a12
114948 --- /dev/null
114949 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114950 @@ -0,0 +1,943 @@
114951 +/*
114952 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114953 + * Licensed under the GPL v2, or (at your option) v3
114954 + *
114955 + * Homepage:
114956 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114957 + *
114958 + * Documentation:
114959 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114960 + *
114961 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114962 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114963 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114964 + *
114965 + * Usage:
114966 + * $ make
114967 + * $ make run
114968 + */
114969 +
114970 +#include "gcc-common.h"
114971 +#include "size_overflow.h"
114972 +
114973 +#define MIN_CHECK true
114974 +#define MAX_CHECK false
114975 +
114976 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114977 +{
114978 + const_tree type;
114979 + tree new_type;
114980 +
114981 + gcc_assert(node != NULL_TREE);
114982 +
114983 + type = TREE_TYPE(node);
114984 +
114985 + if (pointer_set_contains(visited->my_stmts, stmt))
114986 + return TREE_TYPE(node);
114987 +
114988 + switch (TYPE_MODE(type)) {
114989 + case QImode:
114990 + new_type = size_overflow_type_HI;
114991 + break;
114992 + case HImode:
114993 + new_type = size_overflow_type_SI;
114994 + break;
114995 + case SImode:
114996 + new_type = size_overflow_type_DI;
114997 + break;
114998 + case DImode:
114999 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115000 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
115001 + else
115002 + new_type = size_overflow_type_TI;
115003 + break;
115004 + case TImode:
115005 + gcc_assert(!TYPE_UNSIGNED(type));
115006 + new_type = size_overflow_type_TI;
115007 + break;
115008 + default:
115009 + debug_tree((tree)node);
115010 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
115011 + gcc_unreachable();
115012 + }
115013 +
115014 + if (TYPE_QUALS(type) != 0)
115015 + return build_qualified_type(new_type, TYPE_QUALS(type));
115016 + return new_type;
115017 +}
115018 +
115019 +static tree get_lhs(const_gimple stmt)
115020 +{
115021 + switch (gimple_code(stmt)) {
115022 + case GIMPLE_ASSIGN:
115023 + case GIMPLE_CALL:
115024 + return gimple_get_lhs(stmt);
115025 + case GIMPLE_PHI:
115026 + return gimple_phi_result(stmt);
115027 + default:
115028 + return NULL_TREE;
115029 + }
115030 +}
115031 +
115032 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
115033 +{
115034 + gimple_stmt_iterator gsi;
115035 + tree lhs;
115036 + gimple new_stmt;
115037 +
115038 + if (rhs == NULL_TREE)
115039 + return NULL_TREE;
115040 +
115041 + gsi = gsi_for_stmt(stmt);
115042 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115043 + pointer_set_insert(visited->my_stmts, new_stmt);
115044 +
115045 + lhs = get_lhs(new_stmt);
115046 + gcc_assert(lhs != NULL_TREE);
115047 + return lhs;
115048 +}
115049 +
115050 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
115051 +{
115052 + tree lhs, dst_type;
115053 + gimple_stmt_iterator gsi;
115054 +
115055 + if (rhs1 == NULL_TREE) {
115056 + debug_gimple_stmt(oldstmt);
115057 + error("%s: rhs1 is NULL_TREE", __func__);
115058 + gcc_unreachable();
115059 + }
115060 +
115061 + switch (gimple_code(oldstmt)) {
115062 + case GIMPLE_ASM:
115063 + lhs = rhs1;
115064 + break;
115065 + case GIMPLE_CALL:
115066 + case GIMPLE_ASSIGN:
115067 + lhs = gimple_get_lhs(oldstmt);
115068 + break;
115069 + default:
115070 + debug_gimple_stmt(oldstmt);
115071 + gcc_unreachable();
115072 + }
115073 +
115074 + gsi = gsi_for_stmt(oldstmt);
115075 + pointer_set_insert(visited->stmts, oldstmt);
115076 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115077 + basic_block next_bb, cur_bb;
115078 + const_edge e;
115079 +
115080 + gcc_assert(before == false);
115081 + gcc_assert(stmt_can_throw_internal(oldstmt));
115082 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115083 + gcc_assert(!gsi_end_p(gsi));
115084 +
115085 + cur_bb = gimple_bb(oldstmt);
115086 + next_bb = cur_bb->next_bb;
115087 + e = find_edge(cur_bb, next_bb);
115088 + gcc_assert(e != NULL);
115089 + gcc_assert(e->flags & EDGE_FALLTHRU);
115090 +
115091 + gsi = gsi_after_labels(next_bb);
115092 + gcc_assert(!gsi_end_p(gsi));
115093 +
115094 + before = true;
115095 + oldstmt = gsi_stmt(gsi);
115096 + }
115097 +
115098 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
115099 +
115100 + if (is_gimple_constant(rhs1))
115101 + return cast_a_tree(dst_type, rhs1);
115102 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
115103 +}
115104 +
115105 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115106 +{
115107 + gimple stmt;
115108 + gimple_stmt_iterator gsi;
115109 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115110 +
115111 + if (pointer_set_contains(visited->my_stmts, oldstmt))
115112 + return lhs;
115113 +
115114 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115115 + rhs1 = gimple_assign_rhs1(oldstmt);
115116 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115117 + }
115118 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115119 + rhs2 = gimple_assign_rhs2(oldstmt);
115120 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115121 + }
115122 +
115123 + stmt = gimple_copy(oldstmt);
115124 + gimple_set_location(stmt, gimple_location(oldstmt));
115125 + pointer_set_insert(visited->my_stmts, stmt);
115126 +
115127 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115128 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115129 +
115130 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
115131 +
115132 + new_var = create_new_var(size_overflow_type);
115133 + new_var = make_ssa_name(new_var, stmt);
115134 + gimple_assign_set_lhs(stmt, new_var);
115135 +
115136 + if (rhs1 != NULL_TREE)
115137 + gimple_assign_set_rhs1(stmt, rhs1);
115138 +
115139 + if (rhs2 != NULL_TREE)
115140 + gimple_assign_set_rhs2(stmt, rhs2);
115141 +#if BUILDING_GCC_VERSION >= 4006
115142 + if (rhs3 != NULL_TREE)
115143 + gimple_assign_set_rhs3(stmt, rhs3);
115144 +#endif
115145 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115146 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115147 +
115148 + gsi = gsi_for_stmt(oldstmt);
115149 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115150 + update_stmt(stmt);
115151 + pointer_set_insert(visited->stmts, oldstmt);
115152 + return gimple_assign_lhs(stmt);
115153 +}
115154 +
115155 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115156 +{
115157 + gimple assign;
115158 + gimple_stmt_iterator gsi;
115159 + basic_block first_bb;
115160 +
115161 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115162 +
115163 + if (bb->index == 0) {
115164 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115165 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115166 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115167 + bb = first_bb;
115168 + }
115169 +
115170 + gsi = gsi_after_labels(bb);
115171 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115172 + pointer_set_insert(visited->my_stmts, assign);
115173 +
115174 + return gimple_assign_lhs(assign);
115175 +}
115176 +
115177 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
115178 +{
115179 + gimple_stmt_iterator gsi;
115180 + gimple assign, def_stmt = get_def_stmt(new_arg);
115181 +
115182 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115183 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115184 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115185 + } else {
115186 + gsi = gsi_for_stmt(def_stmt);
115187 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115188 + }
115189 +
115190 + pointer_set_insert(visited->my_stmts, assign);
115191 + return gimple_assign_lhs(assign);
115192 +}
115193 +
115194 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
115195 +{
115196 + basic_block bb;
115197 + gimple_stmt_iterator gsi;
115198 + const_gimple def_stmt;
115199 + gimple assign;
115200 +
115201 + def_stmt = get_def_stmt(arg);
115202 + bb = gimple_bb(def_stmt);
115203 + gcc_assert(bb->index != 0);
115204 + gsi = gsi_after_labels(bb);
115205 +
115206 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115207 + pointer_set_insert(visited->my_stmts, assign);
115208 + return gimple_assign_lhs(assign);
115209 +}
115210 +
115211 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115212 +{
115213 + tree size_overflow_type;
115214 + tree arg;
115215 + const_gimple def_stmt;
115216 +
115217 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115218 + return new_arg;
115219 +
115220 + arg = gimple_phi_arg_def(oldstmt, i);
115221 + def_stmt = get_def_stmt(arg);
115222 + gcc_assert(def_stmt != NULL);
115223 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115224 +
115225 + switch (gimple_code(def_stmt)) {
115226 + case GIMPLE_PHI:
115227 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
115228 + case GIMPLE_NOP: {
115229 + basic_block bb;
115230 +
115231 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115232 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
115233 + }
115234 + case GIMPLE_ASM: {
115235 + gimple_stmt_iterator gsi;
115236 + gimple assign, stmt = get_def_stmt(arg);
115237 +
115238 + gsi = gsi_for_stmt(stmt);
115239 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115240 + pointer_set_insert(visited->my_stmts, assign);
115241 + return gimple_assign_lhs(assign);
115242 + }
115243 + default:
115244 + gcc_assert(new_arg != NULL_TREE);
115245 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115246 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
115247 + }
115248 +}
115249 +
115250 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
115251 +{
115252 + basic_block bb;
115253 + gimple phi;
115254 + gimple_seq seq;
115255 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115256 +
115257 + bb = gsi_bb(gsi);
115258 +
115259 + if (result == NULL_TREE) {
115260 + tree old_result = gimple_phi_result(oldstmt);
115261 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
115262 +
115263 + result = create_new_var(size_overflow_type);
115264 + }
115265 +
115266 + phi = create_phi_node(result, bb);
115267 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115268 + seq = phi_nodes(bb);
115269 + gsi = gsi_last(seq);
115270 + gsi_remove(&gsi, false);
115271 +
115272 + gsi = gsi_for_stmt(oldstmt);
115273 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115274 + gimple_set_bb(phi, bb);
115275 + return phi;
115276 +}
115277 +
115278 +#if BUILDING_GCC_VERSION <= 4007
115279 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115280 +#else
115281 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115282 +#endif
115283 +{
115284 + gimple new_phi;
115285 + unsigned int i;
115286 + tree arg, result;
115287 + location_t loc = gimple_location(oldstmt);
115288 +
115289 +#if BUILDING_GCC_VERSION <= 4007
115290 + gcc_assert(!VEC_empty(tree, *args));
115291 +#else
115292 + gcc_assert(!args->is_empty());
115293 +#endif
115294 +
115295 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
115296 + result = gimple_phi_result(new_phi);
115297 + ssa_name_var = SSA_NAME_VAR(result);
115298 +
115299 +#if BUILDING_GCC_VERSION <= 4007
115300 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115301 +#else
115302 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115303 +#endif
115304 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
115305 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115306 + }
115307 +
115308 +#if BUILDING_GCC_VERSION <= 4007
115309 + VEC_free(tree, heap, *args);
115310 +#else
115311 + vec_free(args);
115312 +#endif
115313 + update_stmt(new_phi);
115314 + pointer_set_insert(visited->my_stmts, new_phi);
115315 + return result;
115316 +}
115317 +
115318 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115319 +{
115320 + tree ssa_name_var = NULL_TREE;
115321 +#if BUILDING_GCC_VERSION <= 4007
115322 + VEC(tree, heap) *args = NULL;
115323 +#else
115324 + vec<tree, va_heap, vl_embed> *args = NULL;
115325 +#endif
115326 + gimple oldstmt = get_def_stmt(orig_result);
115327 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115328 +
115329 + pointer_set_insert(visited->stmts, oldstmt);
115330 + for (i = 0; i < len; i++) {
115331 + tree arg, new_arg;
115332 +
115333 + arg = gimple_phi_arg_def(oldstmt, i);
115334 + new_arg = expand(visited, caller_node, arg);
115335 +
115336 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115337 + ssa_name_var = SSA_NAME_VAR(new_arg);
115338 +
115339 + if (is_gimple_constant(arg)) {
115340 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115341 +
115342 + new_arg = cast_a_tree(size_overflow_type, arg);
115343 + }
115344 +
115345 +#if BUILDING_GCC_VERSION <= 4007
115346 + VEC_safe_push(tree, heap, args, new_arg);
115347 +#else
115348 + vec_safe_push(args, new_arg);
115349 +#endif
115350 + }
115351 +
115352 +#if BUILDING_GCC_VERSION <= 4007
115353 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115354 +#else
115355 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115356 +#endif
115357 +}
115358 +
115359 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115360 +{
115361 + tree rhs1 = gimple_assign_rhs1(stmt);
115362 + tree lhs = gimple_assign_lhs(stmt);
115363 + const_tree rhs1_type = TREE_TYPE(rhs1);
115364 + const_tree lhs_type = TREE_TYPE(lhs);
115365 +
115366 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115367 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115368 +
115369 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115370 +}
115371 +
115372 +static bool skip_lhs_cast_check(const_gimple stmt)
115373 +{
115374 + const_tree rhs = gimple_assign_rhs1(stmt);
115375 + const_gimple def_stmt = get_def_stmt(rhs);
115376 +
115377 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115378 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115379 + return true;
115380 +
115381 + if (is_const_plus_unsigned_signed_truncation(rhs))
115382 + return true;
115383 +
115384 + return false;
115385 +}
115386 +
115387 +static tree create_string_param(tree string)
115388 +{
115389 + tree i_type, a_type;
115390 + const int length = TREE_STRING_LENGTH(string);
115391 +
115392 + gcc_assert(length > 0);
115393 +
115394 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115395 + a_type = build_array_type(char_type_node, i_type);
115396 +
115397 + TREE_TYPE(string) = a_type;
115398 + TREE_CONSTANT(string) = 1;
115399 + TREE_READONLY(string) = 1;
115400 +
115401 + return build1(ADDR_EXPR, ptr_type_node, string);
115402 +}
115403 +
115404 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115405 +{
115406 + gimple cond_stmt;
115407 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115408 +
115409 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115410 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115411 + update_stmt(cond_stmt);
115412 +}
115413 +
115414 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115415 +{
115416 + gimple func_stmt;
115417 + const_gimple def_stmt;
115418 + const_tree loc_line;
115419 + tree loc_file, ssa_name, current_func;
115420 + expanded_location xloc;
115421 + char *ssa_name_buf;
115422 + int len;
115423 + struct cgraph_edge *edge;
115424 + struct cgraph_node *callee_node;
115425 + int frequency;
115426 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115427 +
115428 + def_stmt = get_def_stmt(arg);
115429 + xloc = expand_location(gimple_location(def_stmt));
115430 +
115431 + if (!gimple_has_location(def_stmt)) {
115432 + xloc = expand_location(gimple_location(stmt));
115433 + if (!gimple_has_location(stmt))
115434 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115435 + }
115436 +
115437 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115438 +
115439 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115440 + loc_file = create_string_param(loc_file);
115441 +
115442 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115443 + current_func = create_string_param(current_func);
115444 +
115445 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115446 + call_count++;
115447 + 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);
115448 + gcc_assert(len > 0);
115449 + ssa_name = build_string(len + 1, ssa_name_buf);
115450 + free(ssa_name_buf);
115451 + ssa_name = create_string_param(ssa_name);
115452 +
115453 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115454 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115455 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115456 +
115457 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115458 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115459 +
115460 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115461 + gcc_assert(edge != NULL);
115462 +}
115463 +
115464 +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)
115465 +{
115466 + basic_block cond_bb, join_bb, bb_true;
115467 + edge e;
115468 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115469 +
115470 + cond_bb = gimple_bb(stmt);
115471 + if (before)
115472 + gsi_prev(&gsi);
115473 + if (gsi_end_p(gsi))
115474 + e = split_block_after_labels(cond_bb);
115475 + else
115476 + e = split_block(cond_bb, gsi_stmt(gsi));
115477 + cond_bb = e->src;
115478 + join_bb = e->dest;
115479 + e->flags = EDGE_FALSE_VALUE;
115480 + e->probability = REG_BR_PROB_BASE;
115481 +
115482 + bb_true = create_empty_bb(cond_bb);
115483 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115484 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115485 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115486 +
115487 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115488 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115489 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115490 +
115491 + if (current_loops != NULL) {
115492 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115493 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115494 + }
115495 +
115496 + insert_cond(cond_bb, arg, cond_code, type_value);
115497 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115498 +
115499 +// print_the_code_insertions(stmt);
115500 +}
115501 +
115502 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115503 +{
115504 + const_tree rhs_type = TREE_TYPE(rhs);
115505 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115506 +
115507 + gcc_assert(rhs_type != NULL_TREE);
115508 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115509 + return;
115510 +
115511 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115512 +
115513 + if (is_const_plus_unsigned_signed_truncation(rhs))
115514 + return;
115515 +
115516 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115517 + // typemax (-1) < typemin (0)
115518 + if (TREE_OVERFLOW(type_max))
115519 + return;
115520 +
115521 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115522 +
115523 + cast_rhs_type = TREE_TYPE(cast_rhs);
115524 + type_max_type = TREE_TYPE(type_max);
115525 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115526 +
115527 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115528 +
115529 + // special case: get_size_overflow_type(), 32, u64->s
115530 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115531 + return;
115532 +
115533 + type_min_type = TREE_TYPE(type_min);
115534 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115535 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115536 +}
115537 +
115538 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115539 +{
115540 + bool cast_lhs, cast_rhs;
115541 + tree lhs = gimple_assign_lhs(stmt);
115542 + tree rhs = gimple_assign_rhs1(stmt);
115543 + const_tree lhs_type = TREE_TYPE(lhs);
115544 + const_tree rhs_type = TREE_TYPE(rhs);
115545 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115546 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115547 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115548 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115549 +
115550 + static bool check_lhs[3][4] = {
115551 + // ss su us uu
115552 + { false, true, true, false }, // lhs > rhs
115553 + { false, false, false, false }, // lhs = rhs
115554 + { true, true, true, true }, // lhs < rhs
115555 + };
115556 +
115557 + static bool check_rhs[3][4] = {
115558 + // ss su us uu
115559 + { true, false, true, true }, // lhs > rhs
115560 + { true, false, true, true }, // lhs = rhs
115561 + { true, false, true, true }, // lhs < rhs
115562 + };
115563 +
115564 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115565 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115566 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115567 +
115568 + if (lhs_size > rhs_size) {
115569 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115570 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115571 + } else if (lhs_size == rhs_size) {
115572 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115573 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115574 + } else {
115575 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115576 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115577 + }
115578 +
115579 + if (!cast_lhs && !cast_rhs)
115580 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115581 +
115582 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115583 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115584 +
115585 + if (cast_rhs)
115586 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115587 +
115588 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115589 +}
115590 +
115591 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115592 +{
115593 + enum tree_code rhs_code;
115594 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115595 +
115596 + if (pointer_set_contains(visited->my_stmts, stmt))
115597 + return lhs;
115598 +
115599 + rhs1 = gimple_assign_rhs1(stmt);
115600 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115601 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115602 +
115603 + new_rhs1 = expand(visited, caller_node, rhs1);
115604 +
115605 + if (new_rhs1 == NULL_TREE)
115606 + return create_cast_assign(visited, stmt);
115607 +
115608 + if (pointer_set_contains(visited->no_cast_check, stmt))
115609 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115610 +
115611 + rhs_code = gimple_assign_rhs_code(stmt);
115612 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115613 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115614 +
115615 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115616 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115617 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115618 + }
115619 +
115620 + if (!gimple_assign_cast_p(stmt))
115621 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115622 +
115623 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115624 +}
115625 +
115626 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115627 +{
115628 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115629 + gimple def_stmt = get_def_stmt(lhs);
115630 +
115631 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115632 + rhs1 = gimple_assign_rhs1(def_stmt);
115633 +
115634 + if (is_gimple_constant(rhs1))
115635 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115636 +
115637 + switch (TREE_CODE(rhs1)) {
115638 + case SSA_NAME: {
115639 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115640 +
115641 + if (gimple_assign_cast_p(stmt))
115642 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115643 + return ret;
115644 + }
115645 + case ARRAY_REF:
115646 + case BIT_FIELD_REF:
115647 + case ADDR_EXPR:
115648 + case COMPONENT_REF:
115649 + case INDIRECT_REF:
115650 +#if BUILDING_GCC_VERSION >= 4006
115651 + case MEM_REF:
115652 +#endif
115653 + case TARGET_MEM_REF:
115654 + case VIEW_CONVERT_EXPR:
115655 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115656 + case PARM_DECL:
115657 + case VAR_DECL:
115658 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115659 +
115660 + default:
115661 + debug_gimple_stmt(def_stmt);
115662 + debug_tree(rhs1);
115663 + gcc_unreachable();
115664 + }
115665 +}
115666 +
115667 +static void __unused print_the_code_insertions(const_gimple stmt)
115668 +{
115669 + location_t loc = gimple_location(stmt);
115670 +
115671 + inform(loc, "Integer size_overflow check applied here.");
115672 +}
115673 +
115674 +static bool is_from_cast(const_tree node)
115675 +{
115676 + gimple def_stmt = get_def_stmt(node);
115677 +
115678 + if (!def_stmt)
115679 + return false;
115680 +
115681 + if (gimple_assign_cast_p(def_stmt))
115682 + return true;
115683 +
115684 + return false;
115685 +}
115686 +
115687 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115688 +static bool is_a_ptr_minus(gimple stmt)
115689 +{
115690 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115691 +
115692 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115693 + return false;
115694 +
115695 + rhs1 = gimple_assign_rhs1(stmt);
115696 + if (!is_from_cast(rhs1))
115697 + return false;
115698 +
115699 + rhs2 = gimple_assign_rhs2(stmt);
115700 + if (!is_from_cast(rhs2))
115701 + return false;
115702 +
115703 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115704 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115705 +
115706 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115707 + return false;
115708 +
115709 + return true;
115710 +}
115711 +
115712 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115713 +{
115714 + enum intentional_overflow_type res;
115715 + tree rhs1, rhs2, new_lhs;
115716 + gimple def_stmt = get_def_stmt(lhs);
115717 + tree new_rhs1 = NULL_TREE;
115718 + tree new_rhs2 = NULL_TREE;
115719 +
115720 + if (is_a_ptr_minus(def_stmt))
115721 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115722 +
115723 + rhs1 = gimple_assign_rhs1(def_stmt);
115724 + rhs2 = gimple_assign_rhs2(def_stmt);
115725 +
115726 + /* no DImode/TImode division in the 32/64 bit kernel */
115727 + switch (gimple_assign_rhs_code(def_stmt)) {
115728 + case RDIV_EXPR:
115729 + case TRUNC_DIV_EXPR:
115730 + case CEIL_DIV_EXPR:
115731 + case FLOOR_DIV_EXPR:
115732 + case ROUND_DIV_EXPR:
115733 + case TRUNC_MOD_EXPR:
115734 + case CEIL_MOD_EXPR:
115735 + case FLOOR_MOD_EXPR:
115736 + case ROUND_MOD_EXPR:
115737 + case EXACT_DIV_EXPR:
115738 + case POINTER_PLUS_EXPR:
115739 + case BIT_AND_EXPR:
115740 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115741 + default:
115742 + break;
115743 + }
115744 +
115745 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115746 + if (new_lhs != NULL_TREE)
115747 + return new_lhs;
115748 +
115749 + if (TREE_CODE(rhs1) == SSA_NAME)
115750 + new_rhs1 = expand(visited, caller_node, rhs1);
115751 + if (TREE_CODE(rhs2) == SSA_NAME)
115752 + new_rhs2 = expand(visited, caller_node, rhs2);
115753 +
115754 + res = add_mul_intentional_overflow(def_stmt);
115755 + if (res != NO_INTENTIONAL_OVERFLOW) {
115756 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115757 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115758 + return new_lhs;
115759 + }
115760 +
115761 + if (skip_expr_on_double_type(def_stmt)) {
115762 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115763 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115764 + return new_lhs;
115765 + }
115766 +
115767 + if (is_a_neg_overflow(def_stmt, rhs2))
115768 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115769 + if (is_a_neg_overflow(def_stmt, rhs1))
115770 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115771 +
115772 +
115773 + if (is_a_constant_overflow(def_stmt, rhs2))
115774 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115775 + if (is_a_constant_overflow(def_stmt, rhs1))
115776 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115777 +
115778 + // the const is between 0 and (signed) MAX
115779 + if (is_gimple_constant(rhs1))
115780 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115781 + if (is_gimple_constant(rhs2))
115782 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115783 +
115784 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115785 +}
115786 +
115787 +#if BUILDING_GCC_VERSION >= 4006
115788 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115789 +{
115790 + if (is_gimple_constant(rhs))
115791 + return cast_a_tree(size_overflow_type, rhs);
115792 + if (TREE_CODE(rhs) != SSA_NAME)
115793 + return NULL_TREE;
115794 + return expand(visited, caller_node, rhs);
115795 +}
115796 +
115797 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115798 +{
115799 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115800 + gimple def_stmt = get_def_stmt(lhs);
115801 +
115802 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115803 +
115804 + rhs1 = gimple_assign_rhs1(def_stmt);
115805 + rhs2 = gimple_assign_rhs2(def_stmt);
115806 + rhs3 = gimple_assign_rhs3(def_stmt);
115807 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115808 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115809 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115810 +
115811 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115812 +}
115813 +#endif
115814 +
115815 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115816 +{
115817 + gimple_stmt_iterator gsi;
115818 + gimple next_stmt = NULL;
115819 +
115820 + gsi = gsi_for_stmt(stmt);
115821 +
115822 + do {
115823 + gsi_next(&gsi);
115824 + next_stmt = gsi_stmt(gsi);
115825 +
115826 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115827 + return NULL_TREE;
115828 +
115829 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115830 + break;
115831 +
115832 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115833 + } while (!gsi_end_p(gsi));
115834 +
115835 + gcc_assert(next_stmt);
115836 + return get_lhs(next_stmt);
115837 +}
115838 +
115839 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115840 +{
115841 + gimple_stmt_iterator gsi;
115842 + enum gimple_code code = gimple_code(def_stmt);
115843 +
115844 + if (code == GIMPLE_ASM)
115845 + return NULL_TREE;
115846 +
115847 + gsi = gsi_for_stmt(def_stmt);
115848 + gsi_next(&gsi);
115849 +
115850 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115851 + return NULL_TREE;
115852 + return get_my_stmt_lhs(visited, def_stmt);
115853 +}
115854 +
115855 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115856 +{
115857 + gimple def_stmt;
115858 +
115859 + def_stmt = get_def_stmt(lhs);
115860 +
115861 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115862 + return NULL_TREE;
115863 +
115864 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115865 + return lhs;
115866 +
115867 + if (pointer_set_contains(visited->stmts, def_stmt))
115868 + return expand_visited(visited, def_stmt);
115869 +
115870 + switch (gimple_code(def_stmt)) {
115871 + case GIMPLE_PHI:
115872 + return handle_phi(visited, caller_node, lhs);
115873 + case GIMPLE_CALL:
115874 + case GIMPLE_ASM:
115875 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115876 + case GIMPLE_ASSIGN:
115877 + switch (gimple_num_ops(def_stmt)) {
115878 + case 2:
115879 + return handle_unary_ops(visited, caller_node, def_stmt);
115880 + case 3:
115881 + return handle_binary_ops(visited, caller_node, lhs);
115882 +#if BUILDING_GCC_VERSION >= 4006
115883 + case 4:
115884 + return handle_ternary_ops(visited, caller_node, lhs);
115885 +#endif
115886 + }
115887 + default:
115888 + debug_gimple_stmt(def_stmt);
115889 + error("%s: unknown gimple code", __func__);
115890 + gcc_unreachable();
115891 + }
115892 +}
115893 +
115894 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
115895 new file mode 100644
115896 index 0000000..df50164
115897 --- /dev/null
115898 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115899 @@ -0,0 +1,1141 @@
115900 +/*
115901 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115902 + * Licensed under the GPL v2, or (at your option) v3
115903 + *
115904 + * Homepage:
115905 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115906 + *
115907 + * Documentation:
115908 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115909 + *
115910 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115911 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115912 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115913 + *
115914 + * Usage:
115915 + * $ make
115916 + * $ make run
115917 + */
115918 +
115919 +#include "gcc-common.h"
115920 +#include "size_overflow.h"
115921 +
115922 +#define VEC_LEN 128
115923 +#define RET_CHECK NULL_TREE
115924 +#define WRONG_NODE 32
115925 +#define NOT_INTENTIONAL_ASM NULL
115926 +
115927 +unsigned int call_count;
115928 +
115929 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115930 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115931 +
115932 +struct visited_fns {
115933 + struct visited_fns *next;
115934 + const_tree fndecl;
115935 + unsigned int num;
115936 + const_gimple first_stmt;
115937 +};
115938 +
115939 +struct next_cgraph_node {
115940 + struct next_cgraph_node *next;
115941 + struct cgraph_node *current_function;
115942 + tree callee_fndecl;
115943 + unsigned int num;
115944 +};
115945 +
115946 +// Don't want to duplicate entries in next_cgraph_node
115947 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115948 +{
115949 + const_tree new_callee_fndecl;
115950 + struct next_cgraph_node *cur_node;
115951 +
115952 + if (fndecl == RET_CHECK)
115953 + new_callee_fndecl = NODE_DECL(node);
115954 + else
115955 + new_callee_fndecl = fndecl;
115956 +
115957 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115958 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115959 + continue;
115960 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115961 + continue;
115962 + if (num == cur_node->num)
115963 + return true;
115964 + }
115965 + return false;
115966 +}
115967 +
115968 +/* Add a next_cgraph_node into the list for handle_function().
115969 + * handle_function() iterates over all the next cgraph nodes and
115970 + * starts the overflow check insertion process.
115971 + */
115972 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115973 +{
115974 + struct next_cgraph_node *new_node;
115975 +
115976 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115977 + return head;
115978 +
115979 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115980 + new_node->current_function = node;
115981 + new_node->next = NULL;
115982 + new_node->num = num;
115983 + if (fndecl == RET_CHECK)
115984 + new_node->callee_fndecl = NODE_DECL(node);
115985 + else
115986 + new_node->callee_fndecl = fndecl;
115987 +
115988 + if (!head)
115989 + return new_node;
115990 +
115991 + new_node->next = head;
115992 + return new_node;
115993 +}
115994 +
115995 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115996 +{
115997 + struct cgraph_edge *e;
115998 +
115999 + if (num == 0)
116000 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116001 +
116002 + for (e = node->callers; e; e = e->next_caller) {
116003 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116004 +
116005 + gcc_assert(fndecl != NULL_TREE);
116006 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116007 + }
116008 +
116009 + return head;
116010 +}
116011 +
116012 +struct missing_functions {
116013 + struct missing_functions *next;
116014 + const_tree node;
116015 + tree fndecl;
116016 +};
116017 +
116018 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116019 +{
116020 + struct missing_functions *new_function;
116021 +
116022 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116023 + new_function->node = node;
116024 + new_function->next = NULL;
116025 +
116026 + if (TREE_CODE(node) == FUNCTION_DECL)
116027 + new_function->fndecl = node;
116028 + else
116029 + new_function->fndecl = current_function_decl;
116030 + gcc_assert(new_function->fndecl);
116031 +
116032 + if (!missing_fn_head)
116033 + return new_function;
116034 +
116035 + new_function->next = missing_fn_head;
116036 + return new_function;
116037 +}
116038 +
116039 +/* If the function is missing from the hash table and it is a static function
116040 + * then create a next_cgraph_node from it for handle_function()
116041 + */
116042 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116043 +{
116044 + unsigned int num;
116045 + const_tree orig_fndecl;
116046 + struct cgraph_node *next_node = NULL;
116047 +
116048 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116049 +
116050 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116051 + if (num == CANNOT_FIND_ARG)
116052 + return cnodes;
116053 +
116054 + if (!is_missing_function(orig_fndecl, num))
116055 + return cnodes;
116056 +
116057 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116058 + if (next_node && next_node->local.local)
116059 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116060 + return cnodes;
116061 +}
116062 +
116063 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116064 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116065 + */
116066 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116067 +{
116068 + unsigned int i;
116069 + tree node;
116070 + struct missing_functions *cur, *missing_fn_head = NULL;
116071 +
116072 +#if BUILDING_GCC_VERSION <= 4007
116073 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116074 +#else
116075 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116076 +#endif
116077 + switch (TREE_CODE(node)) {
116078 + case PARM_DECL:
116079 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116080 + break;
116081 + case FUNCTION_DECL:
116082 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116083 + break;
116084 + default:
116085 + break;
116086 + }
116087 + }
116088 +
116089 + while (missing_fn_head) {
116090 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116091 +
116092 + cur = missing_fn_head->next;
116093 + free(missing_fn_head);
116094 + missing_fn_head = cur;
116095 + }
116096 +
116097 + return cnodes;
116098 +}
116099 +
116100 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116101 +{
116102 + gimple phi = get_def_stmt(result);
116103 + unsigned int i, n = gimple_phi_num_args(phi);
116104 +
116105 + pointer_set_insert(visited, phi);
116106 + for (i = 0; i < n; i++) {
116107 + const_tree arg = gimple_phi_arg_def(phi, i);
116108 +
116109 + set_conditions(visited, interesting_conditions, arg);
116110 + }
116111 +}
116112 +
116113 +enum conditions {
116114 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
116115 +};
116116 +
116117 +// Search for constants, cast assignments and binary/ternary assignments
116118 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116119 +{
116120 + gimple def_stmt = get_def_stmt(lhs);
116121 +
116122 + if (is_gimple_constant(lhs)) {
116123 + interesting_conditions[FROM_CONST] = true;
116124 + return;
116125 + }
116126 +
116127 + if (!def_stmt)
116128 + return;
116129 +
116130 + if (pointer_set_contains(visited, def_stmt))
116131 + return;
116132 +
116133 + switch (gimple_code(def_stmt)) {
116134 + case GIMPLE_CALL:
116135 + if (lhs == gimple_call_lhs(def_stmt))
116136 + interesting_conditions[RET] = true;
116137 + return;
116138 + case GIMPLE_NOP:
116139 + case GIMPLE_ASM:
116140 + return;
116141 + case GIMPLE_PHI:
116142 + interesting_conditions[PHI] = true;
116143 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116144 + case GIMPLE_ASSIGN:
116145 + if (gimple_num_ops(def_stmt) == 2) {
116146 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116147 +
116148 + if (gimple_assign_cast_p(def_stmt))
116149 + interesting_conditions[CAST] = true;
116150 +
116151 + return set_conditions(visited, interesting_conditions, rhs);
116152 + } else {
116153 + interesting_conditions[NOT_UNARY] = true;
116154 + return;
116155 + }
116156 + default:
116157 + debug_gimple_stmt(def_stmt);
116158 + gcc_unreachable();
116159 + }
116160 +}
116161 +
116162 +// determine whether duplication will be necessary or not.
116163 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116164 +{
116165 + struct pointer_set_t *visited;
116166 +
116167 + if (gimple_assign_cast_p(cur_node->first_stmt))
116168 + interesting_conditions[CAST] = true;
116169 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116170 + interesting_conditions[NOT_UNARY] = true;
116171 +
116172 + visited = pointer_set_create();
116173 + set_conditions(visited, interesting_conditions, cur_node->node);
116174 + pointer_set_destroy(visited);
116175 +}
116176 +
116177 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116178 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116179 +{
116180 + gimple assign;
116181 + gimple_stmt_iterator gsi;
116182 +
116183 + // already removed
116184 + if (gimple_bb(asm_stmt) == NULL)
116185 + return;
116186 + gsi = gsi_for_stmt(asm_stmt);
116187 +
116188 + assign = gimple_build_assign(lhs, rhs);
116189 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116190 + SSA_NAME_DEF_STMT(lhs) = assign;
116191 +
116192 + gsi_remove(&gsi, true);
116193 +}
116194 +
116195 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116196 + * stmt is a return otherwise it is the callee function.
116197 + */
116198 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116199 +{
116200 + const_tree fndecl;
116201 +
116202 + if (argnum == 0)
116203 + fndecl = current_function_decl;
116204 + else
116205 + fndecl = gimple_call_fndecl(stmt);
116206 +
116207 + if (fndecl == NULL_TREE)
116208 + return NULL_TREE;
116209 +
116210 + return DECL_ORIGIN(fndecl);
116211 +}
116212 +
116213 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116214 +static bool skip_asm(const_tree arg)
116215 +{
116216 + gimple def_stmt = get_def_stmt(arg);
116217 +
116218 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116219 + return false;
116220 +
116221 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116222 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116223 +}
116224 +
116225 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116226 +{
116227 + gimple phi = get_def_stmt(result);
116228 + unsigned int i, n = gimple_phi_num_args(phi);
116229 +
116230 + pointer_set_insert(visited, phi);
116231 + for (i = 0; i < n; i++) {
116232 + tree arg = gimple_phi_arg_def(phi, i);
116233 +
116234 + walk_use_def(visited, cur_node, arg);
116235 + }
116236 +}
116237 +
116238 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116239 +{
116240 + gimple def_stmt = get_def_stmt(lhs);
116241 + tree rhs1, rhs2;
116242 +
116243 + rhs1 = gimple_assign_rhs1(def_stmt);
116244 + rhs2 = gimple_assign_rhs2(def_stmt);
116245 +
116246 + walk_use_def(visited, cur_node, rhs1);
116247 + walk_use_def(visited, cur_node, rhs2);
116248 +}
116249 +
116250 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116251 +{
116252 + unsigned int i;
116253 + tree element;
116254 + enum tree_code code;
116255 +
116256 + gcc_assert(node != NULL_TREE);
116257 +
116258 + if (is_gimple_constant(node))
116259 + return;
116260 +
116261 + code = TREE_CODE(node);
116262 + if (code == VAR_DECL) {
116263 + node = DECL_ORIGIN(node);
116264 + code = TREE_CODE(node);
116265 + }
116266 +
116267 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116268 + return;
116269 +
116270 +#if BUILDING_GCC_VERSION <= 4007
116271 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116272 +#else
116273 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116274 +#endif
116275 + if (operand_equal_p(node, element, 0))
116276 + return;
116277 + }
116278 +
116279 +#if BUILDING_GCC_VERSION <= 4007
116280 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116281 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116282 +#else
116283 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116284 + vec_safe_push(cur_node->last_nodes, node);
116285 +#endif
116286 +}
116287 +
116288 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116289 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116290 +{
116291 + if (!is_size_overflow_asm(stmt))
116292 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116293 +}
116294 +
116295 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116296 + * and component refs (for checking the intentional_overflow attribute).
116297 + */
116298 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116299 +{
116300 + const_gimple def_stmt;
116301 +
116302 + if (TREE_CODE(lhs) != SSA_NAME) {
116303 + insert_last_node(cur_node, lhs);
116304 + return;
116305 + }
116306 +
116307 + def_stmt = get_def_stmt(lhs);
116308 + if (!def_stmt)
116309 + return;
116310 +
116311 + if (pointer_set_insert(visited, def_stmt))
116312 + return;
116313 +
116314 + switch (gimple_code(def_stmt)) {
116315 + case GIMPLE_NOP:
116316 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116317 + case GIMPLE_ASM:
116318 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116319 + case GIMPLE_CALL: {
116320 + tree fndecl = gimple_call_fndecl(def_stmt);
116321 +
116322 + if (fndecl == NULL_TREE)
116323 + return;
116324 + insert_last_node(cur_node, fndecl);
116325 + return;
116326 + }
116327 + case GIMPLE_PHI:
116328 + return walk_use_def_phi(visited, cur_node, lhs);
116329 + case GIMPLE_ASSIGN:
116330 + switch (gimple_num_ops(def_stmt)) {
116331 + case 2:
116332 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116333 + case 3:
116334 + return walk_use_def_binary(visited, cur_node, lhs);
116335 + }
116336 + default:
116337 + debug_gimple_stmt((gimple)def_stmt);
116338 + error("%s: unknown gimple code", __func__);
116339 + gcc_unreachable();
116340 + }
116341 +}
116342 +
116343 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116344 +static void set_last_nodes(struct interesting_node *cur_node)
116345 +{
116346 + struct pointer_set_t *visited;
116347 +
116348 + visited = pointer_set_create();
116349 + walk_use_def(visited, cur_node, cur_node->node);
116350 + pointer_set_destroy(visited);
116351 +}
116352 +
116353 +enum precond {
116354 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116355 +};
116356 +
116357 +/* 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.
116358 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116359 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116360 + * It skips the possible error codes too.
116361 + */
116362 +static enum precond check_preconditions(struct interesting_node *cur_node)
116363 +{
116364 + bool interesting_conditions[5] = {false, false, false, false, false};
116365 +
116366 + set_last_nodes(cur_node);
116367 +
116368 + check_intentional_attribute_ipa(cur_node);
116369 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116370 + return NO_ATTRIBUTE_SEARCH;
116371 +
116372 + search_interesting_conditions(cur_node, interesting_conditions);
116373 +
116374 + // error code: a phi, unary assign (not cast) and returns only
116375 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116376 + return NO_ATTRIBUTE_SEARCH;
116377 +
116378 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116379 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116380 + return NO_ATTRIBUTE_SEARCH;
116381 +
116382 + // unnecessary overflow check
116383 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116384 + return NO_CHECK_INSERT;
116385 +
116386 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116387 + return NO_CHECK_INSERT;
116388 +
116389 + return NONE;
116390 +}
116391 +
116392 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116393 +{
116394 + const_gimple assign;
116395 + tree orig_type = TREE_TYPE(orig_node);
116396 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116397 +
116398 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116399 + return gimple_assign_lhs(assign);
116400 +}
116401 +
116402 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116403 +{
116404 + void (*set_rhs)(gimple, tree);
116405 + gimple stmt = cur_node->first_stmt;
116406 + const_tree orig_node = cur_node->node;
116407 +
116408 + switch (gimple_code(stmt)) {
116409 + case GIMPLE_RETURN:
116410 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116411 + break;
116412 + case GIMPLE_CALL:
116413 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116414 + break;
116415 + case GIMPLE_ASSIGN:
116416 + switch (cur_node->num) {
116417 + case 1:
116418 + set_rhs = &gimple_assign_set_rhs1;
116419 + break;
116420 + case 2:
116421 + set_rhs = &gimple_assign_set_rhs2;
116422 + break;
116423 +#if BUILDING_GCC_VERSION >= 4006
116424 + case 3:
116425 + set_rhs = &gimple_assign_set_rhs3;
116426 + break;
116427 +#endif
116428 + default:
116429 + gcc_unreachable();
116430 + }
116431 +
116432 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116433 + break;
116434 + default:
116435 + debug_gimple_stmt(stmt);
116436 + gcc_unreachable();
116437 + }
116438 +
116439 + update_stmt(stmt);
116440 +}
116441 +
116442 +static struct visited *create_visited(void)
116443 +{
116444 + struct visited *new_node;
116445 +
116446 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116447 + new_node->stmts = pointer_set_create();
116448 + new_node->my_stmts = pointer_set_create();
116449 + new_node->skip_expr_casts = pointer_set_create();
116450 + new_node->no_cast_check = pointer_set_create();
116451 + return new_node;
116452 +}
116453 +
116454 +static void free_visited(struct visited *visited)
116455 +{
116456 + pointer_set_destroy(visited->stmts);
116457 + pointer_set_destroy(visited->my_stmts);
116458 + pointer_set_destroy(visited->skip_expr_casts);
116459 + pointer_set_destroy(visited->no_cast_check);
116460 +
116461 + free(visited);
116462 +}
116463 +
116464 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116465 + * 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
116466 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116467 + */
116468 +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)
116469 +{
116470 + enum precond ret;
116471 + tree new_node, orig_node = cur_node->node;
116472 +
116473 + ret = check_preconditions(cur_node);
116474 + if (ret == NO_ATTRIBUTE_SEARCH)
116475 + return cnodes;
116476 +
116477 + cnodes = search_overflow_attribute(cnodes, cur_node);
116478 +
116479 + if (ret == NO_CHECK_INSERT)
116480 + return cnodes;
116481 +
116482 + new_node = expand(visited, caller_node, orig_node);
116483 + if (new_node == NULL_TREE)
116484 + return cnodes;
116485 +
116486 + change_orig_node(visited, cur_node, new_node);
116487 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116488 +
116489 + return cnodes;
116490 +}
116491 +
116492 +// Check visited_fns interesting nodes.
116493 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116494 +{
116495 + struct interesting_node *cur;
116496 +
116497 + for (cur = head; cur; cur = cur->next) {
116498 + if (!operand_equal_p(node, cur->node, 0))
116499 + continue;
116500 + if (num != cur->num)
116501 + continue;
116502 + if (first_stmt == cur->first_stmt)
116503 + return true;
116504 + }
116505 + return false;
116506 +}
116507 +
116508 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116509 + 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
116510 + 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
116511 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116512 + num: arg count of a call stmt or 0 when it is a ret
116513 + node: the recursion starts from here, it is a call arg or a return value
116514 + 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.
116515 + intentional_attr_decl: intentional_overflow attribute of the callee function
116516 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116517 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116518 + */
116519 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116520 +{
116521 + struct interesting_node *new_node;
116522 + tree fndecl;
116523 + enum gimple_code code;
116524 +
116525 + gcc_assert(node != NULL_TREE);
116526 + code = gimple_code(first_stmt);
116527 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116528 +
116529 + if (num == CANNOT_FIND_ARG)
116530 + return head;
116531 +
116532 + if (skip_types(node))
116533 + return head;
116534 +
116535 + if (skip_asm(node))
116536 + return head;
116537 +
116538 + if (is_gimple_call(first_stmt))
116539 + fndecl = gimple_call_fndecl(first_stmt);
116540 + else
116541 + fndecl = current_function_decl;
116542 +
116543 + if (fndecl == NULL_TREE)
116544 + return head;
116545 +
116546 + if (is_in_interesting_node(head, first_stmt, node, num))
116547 + return head;
116548 +
116549 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116550 +
116551 + new_node->next = NULL;
116552 + new_node->first_stmt = first_stmt;
116553 +#if BUILDING_GCC_VERSION <= 4007
116554 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116555 +#else
116556 + vec_alloc(new_node->last_nodes, VEC_LEN);
116557 +#endif
116558 + new_node->num = num;
116559 + new_node->node = node;
116560 + new_node->fndecl = fndecl;
116561 + new_node->intentional_attr_decl = MARK_NO;
116562 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116563 + new_node->intentional_mark_from_gimple = asm_stmt;
116564 +
116565 + if (!head)
116566 + return new_node;
116567 +
116568 + new_node->next = head;
116569 + return new_node;
116570 +}
116571 +
116572 +/* 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).
116573 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116574 + */
116575 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116576 +{
116577 + struct next_cgraph_node *cur_node;
116578 + tree ret = gimple_return_retval(stmt);
116579 +
116580 + if (ret == NULL_TREE)
116581 + return head;
116582 +
116583 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116584 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116585 + continue;
116586 + if (cur_node->num == 0)
116587 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116588 + }
116589 +
116590 + return head;
116591 +}
116592 +
116593 +/* 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).
116594 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116595 + */
116596 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116597 +{
116598 + unsigned int argnum;
116599 + tree arg;
116600 + const_tree fndecl;
116601 + struct next_cgraph_node *cur_node;
116602 +
116603 + fndecl = gimple_call_fndecl(stmt);
116604 + if (fndecl == NULL_TREE)
116605 + return head;
116606 +
116607 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116608 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116609 + continue;
116610 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116611 + gcc_assert(argnum != CANNOT_FIND_ARG);
116612 + if (argnum == 0)
116613 + continue;
116614 +
116615 + arg = gimple_call_arg(stmt, argnum - 1);
116616 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116617 + }
116618 +
116619 + return head;
116620 +}
116621 +
116622 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116623 +{
116624 + if (!operand_equal_p(orig_node, node, 0))
116625 + return WRONG_NODE;
116626 + if (skip_types(node))
116627 + return WRONG_NODE;
116628 + return ret_count;
116629 +}
116630 +
116631 +// Get the index of the rhs node in an assignment
116632 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116633 +{
116634 + const_tree rhs1, rhs2;
116635 + unsigned int ret;
116636 +
116637 + gcc_assert(stmt);
116638 + gcc_assert(is_gimple_assign(stmt));
116639 +
116640 + rhs1 = gimple_assign_rhs1(stmt);
116641 + gcc_assert(rhs1 != NULL_TREE);
116642 +
116643 + switch (gimple_num_ops(stmt)) {
116644 + case 2:
116645 + return check_ops(node, rhs1, 1);
116646 + case 3:
116647 + ret = check_ops(node, rhs1, 1);
116648 + if (ret != WRONG_NODE)
116649 + return ret;
116650 +
116651 + rhs2 = gimple_assign_rhs2(stmt);
116652 + gcc_assert(rhs2 != NULL_TREE);
116653 + return check_ops(node, rhs2, 2);
116654 + default:
116655 + gcc_unreachable();
116656 + }
116657 +}
116658 +
116659 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116660 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116661 +{
116662 + unsigned int i;
116663 +
116664 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116665 + return CANNOT_FIND_ARG;
116666 +
116667 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116668 + tree node;
116669 +
116670 + node = gimple_call_arg(stmt, i);
116671 + if (!operand_equal_p(arg, node, 0))
116672 + continue;
116673 + if (!skip_types(node))
116674 + return i + 1;
116675 + }
116676 +
116677 + return CANNOT_FIND_ARG;
116678 +}
116679 +
116680 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116681 + * any of return, call or assignment stmts (because of inlining).
116682 + */
116683 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116684 +{
116685 + use_operand_p use_p;
116686 + imm_use_iterator imm_iter;
116687 + unsigned int argnum;
116688 +
116689 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116690 +
116691 + if (pointer_set_insert(visited, node))
116692 + return head;
116693 +
116694 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116695 + gimple stmt = USE_STMT(use_p);
116696 +
116697 + if (stmt == NULL)
116698 + return head;
116699 + if (is_gimple_debug(stmt))
116700 + continue;
116701 +
116702 + switch (gimple_code(stmt)) {
116703 + case GIMPLE_CALL:
116704 + argnum = find_arg_number_gimple(node, stmt);
116705 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116706 + break;
116707 + case GIMPLE_RETURN:
116708 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116709 + break;
116710 + case GIMPLE_ASSIGN:
116711 + argnum = get_assign_ops_count(stmt, node);
116712 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116713 + break;
116714 + case GIMPLE_PHI: {
116715 + tree result = gimple_phi_result(stmt);
116716 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116717 + break;
116718 + }
116719 + case GIMPLE_ASM:
116720 + if (gimple_asm_noutputs(stmt) != 0)
116721 + break;
116722 + if (!is_size_overflow_asm(stmt))
116723 + break;
116724 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116725 + break;
116726 + case GIMPLE_COND:
116727 + case GIMPLE_SWITCH:
116728 + break;
116729 + default:
116730 + debug_gimple_stmt(stmt);
116731 + gcc_unreachable();
116732 + break;
116733 + }
116734 + }
116735 + return head;
116736 +}
116737 +
116738 +static void remove_size_overflow_asm(gimple stmt)
116739 +{
116740 + gimple_stmt_iterator gsi;
116741 + tree input, output;
116742 +
116743 + if (!is_size_overflow_asm(stmt))
116744 + return;
116745 +
116746 + if (gimple_asm_noutputs(stmt) == 0) {
116747 + gsi = gsi_for_stmt(stmt);
116748 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116749 + gsi_remove(&gsi, true);
116750 + return;
116751 + }
116752 +
116753 + input = gimple_asm_input_op(stmt, 0);
116754 + output = gimple_asm_output_op(stmt, 0);
116755 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116756 +}
116757 +
116758 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116759 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116760 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116761 + */
116762 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116763 +{
116764 + const_tree output;
116765 + struct pointer_set_t *visited;
116766 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116767 +
116768 + if (!is_size_overflow_asm(stmt))
116769 + return head;
116770 +
116771 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116772 + intentional_asm = stmt;
116773 +
116774 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116775 +
116776 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116777 + return head;
116778 +
116779 + if (gimple_asm_noutputs(stmt) == 0) {
116780 + const_tree input;
116781 +
116782 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116783 + return head;
116784 +
116785 + input = gimple_asm_input_op(stmt, 0);
116786 + remove_size_overflow_asm(stmt);
116787 + if (is_gimple_constant(TREE_VALUE(input)))
116788 + return head;
116789 + visited = pointer_set_create();
116790 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116791 + pointer_set_destroy(visited);
116792 + return head;
116793 + }
116794 +
116795 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116796 + remove_size_overflow_asm(stmt);
116797 +
116798 + visited = pointer_set_create();
116799 + output = gimple_asm_output_op(stmt, 0);
116800 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116801 + pointer_set_destroy(visited);
116802 + return head;
116803 +}
116804 +
116805 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116806 + * or a call stmt or a return stmt and store them in the interesting_node list
116807 + */
116808 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116809 +{
116810 + basic_block bb;
116811 + struct interesting_node *head = NULL;
116812 +
116813 + FOR_ALL_BB_FN(bb, cfun) {
116814 + gimple_stmt_iterator gsi;
116815 +
116816 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116817 + enum gimple_code code;
116818 + gimple stmt = gsi_stmt(gsi);
116819 +
116820 + code = gimple_code(stmt);
116821 +
116822 + if (code == GIMPLE_ASM)
116823 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116824 +
116825 + if (!next_node)
116826 + continue;
116827 + if (code == GIMPLE_CALL)
116828 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116829 + if (code == GIMPLE_RETURN)
116830 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116831 + }
116832 + }
116833 + return head;
116834 +}
116835 +
116836 +static void free_interesting_node(struct interesting_node *head)
116837 +{
116838 + struct interesting_node *cur;
116839 +
116840 + while (head) {
116841 + cur = head->next;
116842 +#if BUILDING_GCC_VERSION <= 4007
116843 + VEC_free(tree, gc, head->last_nodes);
116844 +#else
116845 + vec_free(head->last_nodes);
116846 +#endif
116847 + free(head);
116848 + head = cur;
116849 + }
116850 +}
116851 +
116852 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116853 +{
116854 + struct visited_fns *new_visited_fns;
116855 +
116856 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116857 + new_visited_fns->fndecl = cur_node->fndecl;
116858 + new_visited_fns->num = cur_node->num;
116859 + new_visited_fns->first_stmt = cur_node->first_stmt;
116860 + new_visited_fns->next = NULL;
116861 +
116862 + if (!head)
116863 + return new_visited_fns;
116864 +
116865 + new_visited_fns->next = head;
116866 + return new_visited_fns;
116867 +}
116868 +
116869 +/* 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
116870 + * it is a visited_fns function.
116871 + */
116872 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116873 +{
116874 + struct visited_fns *cur;
116875 +
116876 + if (!head)
116877 + return false;
116878 +
116879 + for (cur = head; cur; cur = cur->next) {
116880 + if (cur_node->first_stmt != cur->first_stmt)
116881 + continue;
116882 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116883 + continue;
116884 + if (cur_node->num == cur->num)
116885 + return true;
116886 + }
116887 + return false;
116888 +}
116889 +
116890 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116891 +{
116892 + struct next_cgraph_node *cur;
116893 +
116894 + while (head) {
116895 + cur = head->next;
116896 + free(head);
116897 + head = cur;
116898 + }
116899 +}
116900 +
116901 +static void remove_all_size_overflow_asm(void)
116902 +{
116903 + basic_block bb;
116904 +
116905 + FOR_ALL_BB_FN(bb, cfun) {
116906 + gimple_stmt_iterator si;
116907 +
116908 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116909 + remove_size_overflow_asm(gsi_stmt(si));
116910 + }
116911 +}
116912 +
116913 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116914 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116915 + * the newly collected interesting functions (they are interesting if there is control flow between
116916 + * the interesting stmts and them).
116917 + */
116918 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116919 +{
116920 + struct visited *visited;
116921 + struct interesting_node *head, *cur_node;
116922 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116923 +
116924 + set_current_function_decl(NODE_DECL(node));
116925 + call_count = 0;
116926 +
116927 + head = collect_interesting_stmts(next_node);
116928 +
116929 + visited = create_visited();
116930 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116931 + if (is_visited_fns_function(visited_fns, cur_node))
116932 + continue;
116933 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116934 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116935 + }
116936 +
116937 + free_visited(visited);
116938 + free_interesting_node(head);
116939 + remove_all_size_overflow_asm();
116940 + unset_current_function_decl();
116941 +
116942 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116943 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116944 +
116945 + free_next_cgraph_node(cnodes_head);
116946 + return visited_fns;
116947 +}
116948 +
116949 +static void free_visited_fns(struct visited_fns *head)
116950 +{
116951 + struct visited_fns *cur;
116952 +
116953 + while (head) {
116954 + cur = head->next;
116955 + free(head);
116956 + head = cur;
116957 + }
116958 +}
116959 +
116960 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116961 +unsigned int search_function(void)
116962 +{
116963 + struct cgraph_node *node;
116964 + struct visited_fns *visited_fns = NULL;
116965 +
116966 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116967 + gcc_assert(cgraph_function_flags_ready);
116968 +#if BUILDING_GCC_VERSION <= 4007
116969 + gcc_assert(node->reachable);
116970 +#endif
116971 +
116972 + visited_fns = handle_function(node, NULL, visited_fns);
116973 + }
116974 +
116975 + free_visited_fns(visited_fns);
116976 + return 0;
116977 +}
116978 +
116979 +#if BUILDING_GCC_VERSION >= 4009
116980 +static const struct pass_data insert_size_overflow_check_data = {
116981 +#else
116982 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116983 + .pass = {
116984 +#endif
116985 + .type = SIMPLE_IPA_PASS,
116986 + .name = "size_overflow",
116987 +#if BUILDING_GCC_VERSION >= 4008
116988 + .optinfo_flags = OPTGROUP_NONE,
116989 +#endif
116990 +#if BUILDING_GCC_VERSION >= 4009
116991 + .has_gate = false,
116992 + .has_execute = true,
116993 +#else
116994 + .gate = NULL,
116995 + .execute = search_function,
116996 + .sub = NULL,
116997 + .next = NULL,
116998 + .static_pass_number = 0,
116999 +#endif
117000 + .tv_id = TV_NONE,
117001 + .properties_required = 0,
117002 + .properties_provided = 0,
117003 + .properties_destroyed = 0,
117004 + .todo_flags_start = 0,
117005 + .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,
117006 +#if BUILDING_GCC_VERSION < 4009
117007 + },
117008 + .generate_summary = NULL,
117009 + .write_summary = NULL,
117010 + .read_summary = NULL,
117011 +#if BUILDING_GCC_VERSION >= 4006
117012 + .write_optimization_summary = NULL,
117013 + .read_optimization_summary = NULL,
117014 +#endif
117015 + .stmt_fixup = NULL,
117016 + .function_transform_todo_flags_start = 0,
117017 + .function_transform = NULL,
117018 + .variable_transform = NULL,
117019 +#endif
117020 +};
117021 +
117022 +#if BUILDING_GCC_VERSION >= 4009
117023 +namespace {
117024 +class insert_size_overflow_check : public ipa_opt_pass_d {
117025 +public:
117026 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117027 + unsigned int execute() { return search_function(); }
117028 +};
117029 +}
117030 +#endif
117031 +
117032 +struct opt_pass *make_insert_size_overflow_check(void)
117033 +{
117034 +#if BUILDING_GCC_VERSION >= 4009
117035 + return new insert_size_overflow_check();
117036 +#else
117037 + return &insert_size_overflow_check.pass;
117038 +#endif
117039 +}
117040 +
117041 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117042 new file mode 100644
117043 index 0000000..d71d72a
117044 --- /dev/null
117045 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117046 @@ -0,0 +1,736 @@
117047 +/*
117048 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117049 + * Licensed under the GPL v2, or (at your option) v3
117050 + *
117051 + * Homepage:
117052 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117053 + *
117054 + * Documentation:
117055 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117056 + *
117057 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117058 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117059 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117060 + *
117061 + * Usage:
117062 + * $ make
117063 + * $ make run
117064 + */
117065 +
117066 +#include "gcc-common.h"
117067 +#include "size_overflow.h"
117068 +
117069 +/* Get the param of the intentional_overflow attribute.
117070 + * * 0: MARK_NOT_INTENTIONAL
117071 + * * 1..MAX_PARAM: MARK_YES
117072 + * * -1: MARK_TURN_OFF
117073 + */
117074 +static tree get_attribute_param(const_tree decl)
117075 +{
117076 + const_tree attr;
117077 +
117078 + if (decl == NULL_TREE)
117079 + return NULL_TREE;
117080 +
117081 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
117082 + if (!attr || !TREE_VALUE(attr))
117083 + return NULL_TREE;
117084 +
117085 + return TREE_VALUE(attr);
117086 +}
117087 +
117088 +// MARK_TURN_OFF
117089 +bool is_turn_off_intentional_attr(const_tree decl)
117090 +{
117091 + const_tree param_head;
117092 +
117093 + param_head = get_attribute_param(decl);
117094 + if (param_head == NULL_TREE)
117095 + return false;
117096 +
117097 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
117098 + return true;
117099 + return false;
117100 +}
117101 +
117102 +// MARK_NOT_INTENTIONAL
117103 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
117104 +{
117105 + const_tree param_head;
117106 +
117107 + if (argnum == 0)
117108 + return false;
117109 +
117110 + param_head = get_attribute_param(decl);
117111 + if (param_head == NULL_TREE)
117112 + return false;
117113 +
117114 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
117115 + return true;
117116 + return false;
117117 +}
117118 +
117119 +// MARK_YES
117120 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
117121 +{
117122 + tree param, param_head;
117123 +
117124 + if (argnum == 0)
117125 + return false;
117126 +
117127 + param_head = get_attribute_param(decl);
117128 + for (param = param_head; param; param = TREE_CHAIN(param))
117129 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117130 + return true;
117131 + return false;
117132 +}
117133 +
117134 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117135 +{
117136 + location_t loc;
117137 +
117138 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117139 + return;
117140 +
117141 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117142 + return;
117143 +
117144 + loc = DECL_SOURCE_LOCATION(decl);
117145 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117146 +}
117147 +
117148 +// Get the field decl of a component ref for intentional_overflow checking
117149 +static const_tree search_field_decl(const_tree comp_ref)
117150 +{
117151 + const_tree field = NULL_TREE;
117152 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
117153 +
117154 + for (i = 0; i < len; i++) {
117155 + field = TREE_OPERAND(comp_ref, i);
117156 + if (TREE_CODE(field) == FIELD_DECL)
117157 + break;
117158 + }
117159 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
117160 + return field;
117161 +}
117162 +
117163 +/* Get the type of the intentional_overflow attribute of a node
117164 + * * MARK_TURN_OFF
117165 + * * MARK_YES
117166 + * * MARK_NO
117167 + * * MARK_NOT_INTENTIONAL
117168 + */
117169 +enum mark get_intentional_attr_type(const_tree node)
117170 +{
117171 + const_tree cur_decl;
117172 +
117173 + if (node == NULL_TREE)
117174 + return MARK_NO;
117175 +
117176 + switch (TREE_CODE(node)) {
117177 + case COMPONENT_REF:
117178 + cur_decl = search_field_decl(node);
117179 + if (is_turn_off_intentional_attr(cur_decl))
117180 + return MARK_TURN_OFF;
117181 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117182 + return MARK_YES;
117183 + break;
117184 + case PARM_DECL: {
117185 + unsigned int argnum;
117186 +
117187 + cur_decl = DECL_ORIGIN(current_function_decl);
117188 + argnum = find_arg_number_tree(node, cur_decl);
117189 + if (argnum == CANNOT_FIND_ARG)
117190 + return MARK_NO;
117191 + if (is_yes_intentional_attr(cur_decl, argnum))
117192 + return MARK_YES;
117193 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117194 + return MARK_NOT_INTENTIONAL;
117195 + break;
117196 + }
117197 + case FUNCTION_DECL:
117198 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117199 + return MARK_TURN_OFF;
117200 + break;
117201 + default:
117202 + break;
117203 + }
117204 + return MARK_NO;
117205 +}
117206 +
117207 +// Search for the intentional_overflow attribute on the last nodes
117208 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117209 +{
117210 + unsigned int i;
117211 + tree last_node;
117212 + enum mark mark = MARK_NO;
117213 +
117214 +#if BUILDING_GCC_VERSION <= 4007
117215 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117216 +#else
117217 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117218 +#endif
117219 + mark = get_intentional_attr_type(last_node);
117220 + if (mark != MARK_NO)
117221 + break;
117222 + }
117223 + return mark;
117224 +}
117225 +
117226 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117227 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117228 + */
117229 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117230 +{
117231 + if (!cur_node->intentional_mark_from_gimple)
117232 + return false;
117233 +
117234 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117235 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117236 + else
117237 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117238 +
117239 + // skip param decls
117240 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117241 + return true;
117242 + return true;
117243 +}
117244 +
117245 +/* Search intentional_overflow attribute on caller and on callee too.
117246 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117247 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117248 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117249 +*/
117250 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117251 +{
117252 + const_tree fndecl;
117253 +
117254 + if (is_intentional_attribute_from_gimple(cur_node))
117255 + return;
117256 +
117257 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117258 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117259 + return;
117260 + }
117261 +
117262 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117263 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117264 + return;
117265 + }
117266 +
117267 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117268 + return;
117269 +
117270 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117271 + if (is_turn_off_intentional_attr(fndecl)) {
117272 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117273 + return;
117274 + }
117275 +
117276 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117277 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117278 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117279 + cur_node->intentional_attr_decl = MARK_YES;
117280 +
117281 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117282 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117283 +}
117284 +
117285 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
117286 +{
117287 + const_tree rhs1, lhs, rhs1_type, lhs_type;
117288 + enum machine_mode lhs_mode, rhs_mode;
117289 + gimple def_stmt = get_def_stmt(no_const_rhs);
117290 +
117291 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117292 + return false;
117293 +
117294 + rhs1 = gimple_assign_rhs1(def_stmt);
117295 + lhs = gimple_assign_lhs(def_stmt);
117296 + rhs1_type = TREE_TYPE(rhs1);
117297 + lhs_type = TREE_TYPE(lhs);
117298 + rhs_mode = TYPE_MODE(rhs1_type);
117299 + lhs_mode = TYPE_MODE(lhs_type);
117300 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
117301 + return false;
117302 +
117303 + return true;
117304 +}
117305 +
117306 +static unsigned int uses_num(tree node)
117307 +{
117308 + imm_use_iterator imm_iter;
117309 + use_operand_p use_p;
117310 + unsigned int num = 0;
117311 +
117312 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117313 + gimple use_stmt = USE_STMT(use_p);
117314 +
117315 + if (use_stmt == NULL)
117316 + return num;
117317 + if (is_gimple_debug(use_stmt))
117318 + continue;
117319 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117320 + continue;
117321 + num++;
117322 + }
117323 + return num;
117324 +}
117325 +
117326 +static bool no_uses(tree node)
117327 +{
117328 + return !uses_num(node);
117329 +}
117330 +
117331 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117332 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117333 +{
117334 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117335 + gimple def_stmt = get_def_stmt(lhs);
117336 +
117337 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117338 + return false;
117339 +
117340 + rhs1 = gimple_assign_rhs1(def_stmt);
117341 + rhs_type = TREE_TYPE(rhs1);
117342 + lhs_type = TREE_TYPE(lhs);
117343 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117344 + return false;
117345 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117346 + return false;
117347 +
117348 + def_stmt = get_def_stmt(rhs1);
117349 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117350 + return false;
117351 +
117352 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117353 + return false;
117354 +
117355 + rhs1 = gimple_assign_rhs1(def_stmt);
117356 + rhs2 = gimple_assign_rhs2(def_stmt);
117357 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117358 + return false;
117359 +
117360 + if (is_gimple_constant(rhs2))
117361 + not_const_rhs = rhs1;
117362 + else
117363 + not_const_rhs = rhs2;
117364 +
117365 + return no_uses(not_const_rhs);
117366 +}
117367 +
117368 +static bool is_lt_signed_type_max(const_tree rhs)
117369 +{
117370 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117371 +
117372 + if (!TYPE_UNSIGNED(type))
117373 + return true;
117374 +
117375 + switch (TYPE_MODE(type)) {
117376 + case QImode:
117377 + new_type = intQI_type_node;
117378 + break;
117379 + case HImode:
117380 + new_type = intHI_type_node;
117381 + break;
117382 + case SImode:
117383 + new_type = intSI_type_node;
117384 + break;
117385 + case DImode:
117386 + new_type = intDI_type_node;
117387 + break;
117388 + default:
117389 + debug_tree((tree)type);
117390 + gcc_unreachable();
117391 + }
117392 +
117393 + type_max = TYPE_MAX_VALUE(new_type);
117394 + if (!tree_int_cst_lt(type_max, rhs))
117395 + return true;
117396 +
117397 + return false;
117398 +}
117399 +
117400 +static bool is_gt_zero(const_tree rhs)
117401 +{
117402 + const_tree type = TREE_TYPE(rhs);
117403 +
117404 + if (TYPE_UNSIGNED(type))
117405 + return true;
117406 +
117407 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117408 + return true;
117409 +
117410 + return false;
117411 +}
117412 +
117413 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117414 +{
117415 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117416 + return false;
117417 + if (!is_gimple_constant(rhs))
117418 + return false;
117419 +
117420 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117421 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117422 + return false;
117423 +
117424 + return true;
117425 +}
117426 +
117427 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117428 +{
117429 + gimple assign;
117430 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117431 + tree origtype = TREE_TYPE(orig_rhs);
117432 +
117433 + gcc_assert(is_gimple_assign(stmt));
117434 +
117435 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117436 + pointer_set_insert(visited->my_stmts, assign);
117437 + return gimple_assign_lhs(assign);
117438 +}
117439 +
117440 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117441 +{
117442 + tree new_rhs, orig_rhs;
117443 + void (*gimple_assign_set_rhs)(gimple, tree);
117444 + tree rhs1 = gimple_assign_rhs1(stmt);
117445 + tree rhs2 = gimple_assign_rhs2(stmt);
117446 + tree lhs = gimple_assign_lhs(stmt);
117447 +
117448 + if (!check_overflow)
117449 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117450 +
117451 + if (change_rhs == NULL_TREE)
117452 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117453 +
117454 + if (new_rhs2 == NULL_TREE) {
117455 + orig_rhs = rhs1;
117456 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117457 + } else {
117458 + orig_rhs = rhs2;
117459 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117460 + }
117461 +
117462 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117463 +
117464 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117465 + gimple_assign_set_rhs(stmt, new_rhs);
117466 + update_stmt(stmt);
117467 +
117468 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117469 +}
117470 +
117471 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117472 +{
117473 + gimple rhs1_def_stmt, rhs2_def_stmt;
117474 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117475 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117476 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117477 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117478 +
117479 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117480 + return false;
117481 +
117482 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117483 +
117484 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117485 + return false;
117486 +
117487 + rhs1_def_stmt = get_def_stmt(rhs1);
117488 + rhs2_def_stmt = get_def_stmt(rhs2);
117489 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117490 + return false;
117491 +
117492 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117493 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117494 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117495 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117496 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117497 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117498 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117499 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117500 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117501 + return false;
117502 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117503 + return false;
117504 +
117505 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117506 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117507 + return true;
117508 +}
117509 +
117510 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117511 +{
117512 + gimple assign;
117513 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117514 + tree type = TREE_TYPE(rhs1);
117515 + tree lhs = create_new_var(type);
117516 +
117517 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117518 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117519 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117520 +
117521 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117522 + update_stmt(assign);
117523 + pointer_set_insert(visited->my_stmts, assign);
117524 + return assign;
117525 +}
117526 +
117527 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117528 +{
117529 + gimple_stmt_iterator gsi;
117530 + gimple cast_stmt;
117531 + tree type = TREE_TYPE(node);
117532 +
117533 + if (types_compatible_p(type, intTI_type_node))
117534 + return node;
117535 +
117536 + gsi = gsi_for_stmt(stmt);
117537 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117538 + pointer_set_insert(visited->my_stmts, cast_stmt);
117539 + return gimple_assign_lhs(cast_stmt);
117540 +}
117541 +
117542 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117543 +{
117544 + tree rhs1, def_stmt_rhs1;
117545 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117546 +
117547 + def_stmt = get_def_stmt(var);
117548 + if (!gimple_assign_cast_p(def_stmt))
117549 + return NULL_TREE;
117550 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117551 +
117552 + rhs1 = gimple_assign_rhs1(def_stmt);
117553 + rhs1_def_stmt = get_def_stmt(rhs1);
117554 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117555 + return rhs1;
117556 +
117557 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117558 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117559 +
117560 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117561 + case GIMPLE_CALL:
117562 + case GIMPLE_NOP:
117563 + case GIMPLE_ASM:
117564 + case GIMPLE_PHI:
117565 + return def_stmt_rhs1;
117566 + case GIMPLE_ASSIGN:
117567 + return rhs1;
117568 + default:
117569 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117570 + gcc_unreachable();
117571 + }
117572 +}
117573 +
117574 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117575 +{
117576 + tree new_rhs1, new_rhs2;
117577 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117578 + gimple assign, stmt = get_def_stmt(lhs);
117579 + tree rhs1 = gimple_assign_rhs1(stmt);
117580 + tree rhs2 = gimple_assign_rhs2(stmt);
117581 +
117582 + if (!is_subtraction_special(visited, stmt))
117583 + return NULL_TREE;
117584 +
117585 + new_rhs1 = expand(visited, caller_node, rhs1);
117586 + new_rhs2 = expand(visited, caller_node, rhs2);
117587 +
117588 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117589 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117590 +
117591 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117592 + return NULL_TREE;
117593 +
117594 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117595 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117596 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117597 + }
117598 +
117599 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117600 + new_lhs = gimple_assign_lhs(assign);
117601 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117602 +
117603 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117604 +}
117605 +
117606 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117607 +{
117608 + const_gimple def_stmt;
117609 +
117610 + if (TREE_CODE(rhs) != SSA_NAME)
117611 + return false;
117612 +
117613 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117614 + return false;
117615 +
117616 + def_stmt = get_def_stmt(rhs);
117617 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117618 + return false;
117619 +
117620 + return true;
117621 +}
117622 +
117623 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117624 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117625 + * fffffff * 16 > signed max -> truncate
117626 + */
117627 +static bool look_for_mult_and_add(const_gimple stmt)
117628 +{
117629 + const_tree res;
117630 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117631 + const_gimple def_stmt;
117632 +
117633 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117634 + return false;
117635 + if (!is_gimple_assign(stmt))
117636 + return false;
117637 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117638 + return false;
117639 +
117640 + rhs1 = gimple_assign_rhs1(stmt);
117641 + rhs2 = gimple_assign_rhs2(stmt);
117642 + if (is_gimple_constant(rhs1)) {
117643 + const_rhs = rhs1;
117644 + def_stmt = get_def_stmt(rhs2);
117645 + } else if (is_gimple_constant(rhs2)) {
117646 + const_rhs = rhs2;
117647 + def_stmt = get_def_stmt(rhs1);
117648 + } else
117649 + return false;
117650 +
117651 + if (!is_gimple_assign(def_stmt))
117652 + return false;
117653 +
117654 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117655 + return false;
117656 +
117657 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117658 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117659 + if (is_gimple_constant(def_rhs1))
117660 + def_const_rhs = def_rhs1;
117661 + else if (is_gimple_constant(def_rhs2))
117662 + def_const_rhs = def_rhs2;
117663 + else
117664 + return false;
117665 +
117666 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117667 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117668 + return false;
117669 + return true;
117670 +}
117671 +
117672 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117673 +{
117674 + const_gimple def_stmt_1, def_stmt_2;
117675 + const_tree rhs1, rhs2;
117676 + bool add_mul_rhs1, add_mul_rhs2;
117677 +
117678 + rhs1 = gimple_assign_rhs1(stmt);
117679 + def_stmt_1 = get_def_stmt(rhs1);
117680 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117681 +
117682 + rhs2 = gimple_assign_rhs2(stmt);
117683 + def_stmt_2 = get_def_stmt(rhs2);
117684 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117685 +
117686 + if (add_mul_rhs1)
117687 + return RHS1_INTENTIONAL_OVERFLOW;
117688 + if (add_mul_rhs2)
117689 + return RHS2_INTENTIONAL_OVERFLOW;
117690 + return NO_INTENTIONAL_OVERFLOW;
117691 +}
117692 +
117693 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117694 +{
117695 + gimple my_stmt;
117696 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117697 +
117698 + gsi_next(&gsi);
117699 + my_stmt = gsi_stmt(gsi);
117700 +
117701 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117702 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117703 +
117704 + return my_stmt;
117705 +}
117706 +
117707 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117708 + * unsigned type cast to signed type, unsigned type: no more uses
117709 + * e.g., lib/vsprintf.c:simple_strtol()
117710 + * _10 = (unsigned long int) _9
117711 + * _11 = -_10;
117712 + * _12 = (long int) _11; (_11_ no more uses)
117713 + */
117714 +static bool is_call_or_cast(gimple stmt)
117715 +{
117716 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117717 +}
117718 +
117719 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117720 +{
117721 + const_tree rhs;
117722 + gimple def_stmt;
117723 +
117724 + if (node == NULL_TREE)
117725 + return true;
117726 + if (is_gimple_constant(node))
117727 + return true;
117728 +
117729 + def_stmt = get_def_stmt(node);
117730 + if (!def_stmt)
117731 + return false;
117732 +
117733 + if (is_call_or_cast(def_stmt))
117734 + return true;
117735 +
117736 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117737 + return false;
117738 + rhs = gimple_assign_rhs1(def_stmt);
117739 + def_stmt = get_def_stmt(rhs);
117740 + if (!def_stmt)
117741 + return false;
117742 + return is_call_or_cast(def_stmt);
117743 +}
117744 +
117745 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117746 +{
117747 + unsigned int use_num;
117748 + gimple so_stmt;
117749 + const_gimple def_stmt;
117750 + const_tree rhs1, rhs2;
117751 + tree rhs = gimple_assign_rhs1(stmt);
117752 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117753 + const_tree rhs_type = TREE_TYPE(rhs);
117754 +
117755 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117756 + return;
117757 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117758 + return;
117759 + use_num = uses_num(rhs);
117760 + if (use_num != 1)
117761 + return;
117762 +
117763 + def_stmt = get_def_stmt(rhs);
117764 + if (!def_stmt)
117765 + return;
117766 + if (!is_gimple_assign(def_stmt))
117767 + return;
117768 +
117769 + rhs1 = gimple_assign_rhs1(def_stmt);
117770 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117771 + return;
117772 +
117773 + rhs2 = gimple_assign_rhs2(def_stmt);
117774 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117775 + return;
117776 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117777 + return;
117778 +
117779 + so_stmt = get_dup_stmt(visited, stmt);
117780 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117781 +}
117782 +
117783 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117784 new file mode 100644
117785 index 0000000..4bddad2
117786 --- /dev/null
117787 +++ b/tools/gcc/size_overflow_plugin/misc.c
117788 @@ -0,0 +1,203 @@
117789 +/*
117790 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117791 + * Licensed under the GPL v2, or (at your option) v3
117792 + *
117793 + * Homepage:
117794 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117795 + *
117796 + * Documentation:
117797 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117798 + *
117799 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117800 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117801 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117802 + *
117803 + * Usage:
117804 + * $ make
117805 + * $ make run
117806 + */
117807 +
117808 +#include "gcc-common.h"
117809 +#include "size_overflow.h"
117810 +
117811 +void set_current_function_decl(tree fndecl)
117812 +{
117813 + gcc_assert(fndecl != NULL_TREE);
117814 +
117815 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117816 + calculate_dominance_info(CDI_DOMINATORS);
117817 + current_function_decl = fndecl;
117818 +}
117819 +
117820 +void unset_current_function_decl(void)
117821 +{
117822 + free_dominance_info(CDI_DOMINATORS);
117823 + pop_cfun();
117824 + current_function_decl = NULL_TREE;
117825 +}
117826 +
117827 +static bool is_bool(const_tree node)
117828 +{
117829 + const_tree type;
117830 +
117831 + if (node == NULL_TREE)
117832 + return false;
117833 +
117834 + type = TREE_TYPE(node);
117835 + if (!INTEGRAL_TYPE_P(type))
117836 + return false;
117837 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117838 + return true;
117839 + if (TYPE_PRECISION(type) == 1)
117840 + return true;
117841 + return false;
117842 +}
117843 +
117844 +bool skip_types(const_tree var)
117845 +{
117846 + tree type;
117847 + enum tree_code code;
117848 +
117849 + if (is_gimple_constant(var))
117850 + return true;
117851 +
117852 + switch (TREE_CODE(var)) {
117853 + case ADDR_EXPR:
117854 +#if BUILDING_GCC_VERSION >= 4006
117855 + case MEM_REF:
117856 +#endif
117857 + case ARRAY_REF:
117858 + case BIT_FIELD_REF:
117859 + case INDIRECT_REF:
117860 + case TARGET_MEM_REF:
117861 + case COMPONENT_REF:
117862 + case VAR_DECL:
117863 + case VIEW_CONVERT_EXPR:
117864 + return true;
117865 + default:
117866 + break;
117867 + }
117868 +
117869 + code = TREE_CODE(var);
117870 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117871 +
117872 + type = TREE_TYPE(var);
117873 + switch (TREE_CODE(type)) {
117874 + case INTEGER_TYPE:
117875 + case ENUMERAL_TYPE:
117876 + return false;
117877 + case BOOLEAN_TYPE:
117878 + return is_bool(var);
117879 + default:
117880 + return true;
117881 + }
117882 +}
117883 +
117884 +gimple get_def_stmt(const_tree node)
117885 +{
117886 + gcc_assert(node != NULL_TREE);
117887 +
117888 + if (skip_types(node))
117889 + return NULL;
117890 +
117891 + if (TREE_CODE(node) != SSA_NAME)
117892 + return NULL;
117893 + return SSA_NAME_DEF_STMT(node);
117894 +}
117895 +
117896 +tree create_new_var(tree type)
117897 +{
117898 + tree new_var = create_tmp_var(type, "cicus");
117899 +
117900 + add_referenced_var(new_var);
117901 + return new_var;
117902 +}
117903 +
117904 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117905 +{
117906 + const_gimple def_stmt = get_def_stmt(rhs);
117907 +
117908 + if (force)
117909 + return false;
117910 +
117911 + if (is_gimple_constant(rhs))
117912 + return false;
117913 +
117914 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117915 + return false;
117916 +
117917 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117918 + return false;
117919 +
117920 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117921 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117922 + return false;
117923 +
117924 + return true;
117925 +}
117926 +
117927 +tree cast_a_tree(tree type, tree var)
117928 +{
117929 + gcc_assert(type != NULL_TREE);
117930 + gcc_assert(var != NULL_TREE);
117931 + gcc_assert(fold_convertible_p(type, var));
117932 +
117933 + return fold_convert(type, var);
117934 +}
117935 +
117936 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117937 +{
117938 + gimple assign, def_stmt;
117939 +
117940 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117941 + gcc_assert(!is_gimple_constant(rhs));
117942 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117943 + gcc_unreachable();
117944 +
117945 + def_stmt = get_def_stmt(rhs);
117946 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117947 + return def_stmt;
117948 +
117949 + if (lhs == CREATE_NEW_VAR)
117950 + lhs = create_new_var(dst_type);
117951 +
117952 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117953 +
117954 + if (!gsi_end_p(*gsi)) {
117955 + location_t loc = gimple_location(gsi_stmt(*gsi));
117956 + gimple_set_location(assign, loc);
117957 + }
117958 +
117959 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117960 +
117961 + if (before)
117962 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117963 + else
117964 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117965 + update_stmt(assign);
117966 + return assign;
117967 +}
117968 +
117969 +bool is_size_overflow_type(const_tree var)
117970 +{
117971 + const char *name;
117972 + const_tree type_name, type;
117973 +
117974 + if (var == NULL_TREE)
117975 + return false;
117976 +
117977 + type = TREE_TYPE(var);
117978 + type_name = TYPE_NAME(type);
117979 + if (type_name == NULL_TREE)
117980 + return false;
117981 +
117982 + if (DECL_P(type_name))
117983 + name = DECL_NAME_POINTER(type_name);
117984 + else
117985 + name = IDENTIFIER_POINTER(type_name);
117986 +
117987 + if (!strncmp(name, "size_overflow_type", 18))
117988 + return true;
117989 + return false;
117990 +}
117991 +
117992 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117993 new file mode 100644
117994 index 0000000..7c9e6d1
117995 --- /dev/null
117996 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117997 @@ -0,0 +1,138 @@
117998 +/*
117999 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118000 + * Licensed under the GPL v2, or (at your option) v3
118001 + *
118002 + * Homepage:
118003 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118004 + *
118005 + * Documentation:
118006 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118007 + *
118008 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118009 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118010 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118011 + *
118012 + * Usage:
118013 + * $ make
118014 + * $ make run
118015 + */
118016 +
118017 +#include "gcc-common.h"
118018 +#include "size_overflow.h"
118019 +
118020 +bool skip_expr_on_double_type(const_gimple stmt)
118021 +{
118022 + enum tree_code code = gimple_assign_rhs_code(stmt);
118023 +
118024 + switch (code) {
118025 + case RSHIFT_EXPR:
118026 + case TRUNC_DIV_EXPR:
118027 + case CEIL_DIV_EXPR:
118028 + case FLOOR_DIV_EXPR:
118029 + case ROUND_DIV_EXPR:
118030 + case EXACT_DIV_EXPR:
118031 + case RDIV_EXPR:
118032 + case TRUNC_MOD_EXPR:
118033 + case CEIL_MOD_EXPR:
118034 + case FLOOR_MOD_EXPR:
118035 + case ROUND_MOD_EXPR:
118036 + return true;
118037 + default:
118038 + return false;
118039 + }
118040 +}
118041 +
118042 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
118043 +{
118044 + const_tree orig_rhs1;
118045 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
118046 + gimple down_cast, up_cast;
118047 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
118048 +
118049 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118050 + down_lhs = gimple_assign_lhs(down_cast);
118051 +
118052 + gsi = gsi_for_stmt(use_stmt);
118053 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118054 + new_lhs = gimple_assign_lhs(up_cast);
118055 +
118056 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
118057 + if (operand_equal_p(orig_rhs1, rhs, 0))
118058 + gimple_assign_set_rhs1(use_stmt, new_lhs);
118059 + else
118060 + gimple_assign_set_rhs2(use_stmt, new_lhs);
118061 + update_stmt(use_stmt);
118062 +
118063 + pointer_set_insert(visited->my_stmts, up_cast);
118064 + pointer_set_insert(visited->my_stmts, down_cast);
118065 + pointer_set_insert(visited->skip_expr_casts, up_cast);
118066 + pointer_set_insert(visited->skip_expr_casts, down_cast);
118067 +}
118068 +
118069 +static tree get_proper_unsigned_half_type(const_tree node)
118070 +{
118071 + tree new_type, type;
118072 +
118073 + gcc_assert(is_size_overflow_type(node));
118074 +
118075 + type = TREE_TYPE(node);
118076 + switch (TYPE_MODE(type)) {
118077 + case HImode:
118078 + new_type = unsigned_intQI_type_node;
118079 + break;
118080 + case SImode:
118081 + new_type = unsigned_intHI_type_node;
118082 + break;
118083 + case DImode:
118084 + new_type = unsigned_intSI_type_node;
118085 + break;
118086 + case TImode:
118087 + new_type = unsigned_intDI_type_node;
118088 + break;
118089 + default:
118090 + gcc_unreachable();
118091 + }
118092 +
118093 + if (TYPE_QUALS(type) != 0)
118094 + return build_qualified_type(new_type, TYPE_QUALS(type));
118095 + return new_type;
118096 +}
118097 +
118098 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
118099 +{
118100 + tree type;
118101 +
118102 + if (rhs == NULL_TREE)
118103 + return;
118104 + if (!is_size_overflow_type(rhs))
118105 + return;
118106 +
118107 + type = get_proper_unsigned_half_type(rhs);
118108 + if (is_gimple_constant(rhs))
118109 + return;
118110 + create_up_and_down_cast(visited, stmt, type, rhs);
118111 +}
118112 +
118113 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
118114 +{
118115 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
118116 + return;
118117 + gcc_assert(is_size_overflow_type(rhs));
118118 + insert_cast_rhs(visited, stmt, rhs);
118119 +}
118120 +
118121 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
118122 +{
118123 + tree rhs1, rhs2;
118124 +
118125 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
118126 + rhs1 = gimple_assign_rhs1(stmt);
118127 + insert_cast(visited, stmt, rhs1);
118128 + }
118129 +
118130 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
118131 + rhs2 = gimple_assign_rhs2(stmt);
118132 + insert_cast(visited, stmt, rhs2);
118133 + }
118134 +}
118135 +
118136 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
118137 new file mode 100644
118138 index 0000000..e5b4e50
118139 --- /dev/null
118140 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
118141 @@ -0,0 +1,127 @@
118142 +#ifndef SIZE_OVERFLOW_H
118143 +#define SIZE_OVERFLOW_H
118144 +
118145 +#define CREATE_NEW_VAR NULL_TREE
118146 +#define CANNOT_FIND_ARG 32
118147 +#define MAX_PARAM 31
118148 +#define BEFORE_STMT true
118149 +#define AFTER_STMT false
118150 +
118151 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
118152 +#define YES_ASM_STR "# size_overflow MARK_YES "
118153 +#define OK_ASM_STR "# size_overflow "
118154 +
118155 +enum mark {
118156 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
118157 +};
118158 +
118159 +enum intentional_overflow_type {
118160 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
118161 +};
118162 +
118163 +struct visited {
118164 + struct pointer_set_t *stmts;
118165 + struct pointer_set_t *my_stmts;
118166 + struct pointer_set_t *skip_expr_casts;
118167 + struct pointer_set_t *no_cast_check;
118168 +};
118169 +
118170 +// size_overflow_plugin.c
118171 +extern tree report_size_overflow_decl;
118172 +extern tree size_overflow_type_HI;
118173 +extern tree size_overflow_type_SI;
118174 +extern tree size_overflow_type_DI;
118175 +extern tree size_overflow_type_TI;
118176 +
118177 +
118178 +// size_overflow_plugin_hash.c
118179 +struct size_overflow_hash {
118180 + const struct size_overflow_hash * const next;
118181 + const char * const name;
118182 + const unsigned int param;
118183 +};
118184 +
118185 +struct interesting_node {
118186 + struct interesting_node *next;
118187 + gimple first_stmt;
118188 + const_tree fndecl;
118189 + tree node;
118190 +#if BUILDING_GCC_VERSION <= 4007
118191 + VEC(tree, gc) *last_nodes;
118192 +#else
118193 + vec<tree, va_gc> *last_nodes;
118194 +#endif
118195 + unsigned int num;
118196 + enum mark intentional_attr_decl;
118197 + enum mark intentional_attr_cur_fndecl;
118198 + gimple intentional_mark_from_gimple;
118199 +};
118200 +
118201 +extern bool is_size_overflow_asm(const_gimple stmt);
118202 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
118203 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
118204 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
118205 +extern bool is_a_return_check(const_tree node);
118206 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
118207 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
118208 +
118209 +
118210 +// size_overflow_debug.c
118211 +extern struct opt_pass *make_dump_pass(void);
118212 +
118213 +
118214 +// intentional_overflow.c
118215 +extern enum mark get_intentional_attr_type(const_tree node);
118216 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
118217 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
118218 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
118219 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
118220 +extern bool is_turn_off_intentional_attr(const_tree decl);
118221 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
118222 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
118223 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
118224 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
118225 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
118226 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
118227 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
118228 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
118229 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
118230 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
118231 +
118232 +
118233 +// insert_size_overflow_check_ipa.c
118234 +extern unsigned int search_function(void);
118235 +extern unsigned int call_count;
118236 +extern struct opt_pass *make_insert_size_overflow_check(void);
118237 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
118238 +
118239 +
118240 +// insert_size_overflow_asm.c
118241 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
118242 +
118243 +
118244 +// misc.c
118245 +extern void set_current_function_decl(tree fndecl);
118246 +extern void unset_current_function_decl(void);
118247 +extern gimple get_def_stmt(const_tree node);
118248 +extern tree create_new_var(tree type);
118249 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
118250 +extern bool skip_types(const_tree var);
118251 +extern tree cast_a_tree(tree type, tree var);
118252 +extern bool is_size_overflow_type(const_tree var);
118253 +
118254 +
118255 +// insert_size_overflow_check_core.c
118256 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
118257 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
118258 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
118259 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
118260 +
118261 +
118262 +// remove_unnecessary_dup.c
118263 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
118264 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
118265 +extern bool skip_expr_on_double_type(const_gimple stmt);
118266 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
118267 +
118268 +#endif
118269 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118270 new file mode 100644
118271 index 0000000..4378111
118272 --- /dev/null
118273 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118274 @@ -0,0 +1,116 @@
118275 +/*
118276 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118277 + * Licensed under the GPL v2, or (at your option) v3
118278 + *
118279 + * Homepage:
118280 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118281 + *
118282 + * Documentation:
118283 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118284 + *
118285 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118286 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118287 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118288 + *
118289 + * Usage:
118290 + * $ make
118291 + * $ make run
118292 + */
118293 +
118294 +#include "gcc-common.h"
118295 +
118296 +static unsigned int dump_functions(void)
118297 +{
118298 + struct cgraph_node *node;
118299 +
118300 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118301 + basic_block bb;
118302 +
118303 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118304 + current_function_decl = NODE_DECL(node);
118305 +
118306 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118307 +
118308 + FOR_ALL_BB_FN(bb, cfun) {
118309 + gimple_stmt_iterator si;
118310 +
118311 + fprintf(stderr, "<bb %u>:\n", bb->index);
118312 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118313 + debug_gimple_stmt(gsi_stmt(si));
118314 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118315 + debug_gimple_stmt(gsi_stmt(si));
118316 + fprintf(stderr, "\n");
118317 + }
118318 +
118319 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118320 +
118321 + pop_cfun();
118322 + current_function_decl = NULL_TREE;
118323 + }
118324 +
118325 + fprintf(stderr, "###############################################################################\n");
118326 +
118327 + return 0;
118328 +}
118329 +
118330 +#if BUILDING_GCC_VERSION >= 4009
118331 +static const struct pass_data dump_pass_data = {
118332 +#else
118333 +static struct ipa_opt_pass_d dump_pass = {
118334 + .pass = {
118335 +#endif
118336 + .type = SIMPLE_IPA_PASS,
118337 + .name = "dump",
118338 +#if BUILDING_GCC_VERSION >= 4008
118339 + .optinfo_flags = OPTGROUP_NONE,
118340 +#endif
118341 +#if BUILDING_GCC_VERSION >= 4009
118342 + .has_gate = false,
118343 + .has_execute = true,
118344 +#else
118345 + .gate = NULL,
118346 + .execute = dump_functions,
118347 + .sub = NULL,
118348 + .next = NULL,
118349 + .static_pass_number = 0,
118350 +#endif
118351 + .tv_id = TV_NONE,
118352 + .properties_required = 0,
118353 + .properties_provided = 0,
118354 + .properties_destroyed = 0,
118355 + .todo_flags_start = 0,
118356 + .todo_flags_finish = 0,
118357 +#if BUILDING_GCC_VERSION < 4009
118358 + },
118359 + .generate_summary = NULL,
118360 + .write_summary = NULL,
118361 + .read_summary = NULL,
118362 +#if BUILDING_GCC_VERSION >= 4006
118363 + .write_optimization_summary = NULL,
118364 + .read_optimization_summary = NULL,
118365 +#endif
118366 + .stmt_fixup = NULL,
118367 + .function_transform_todo_flags_start = 0,
118368 + .function_transform = NULL,
118369 + .variable_transform = NULL,
118370 +#endif
118371 +};
118372 +
118373 +#if BUILDING_GCC_VERSION >= 4009
118374 +namespace {
118375 +class dump_pass : public ipa_opt_pass_d {
118376 +public:
118377 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118378 + unsigned int execute() { return dump_functions(); }
118379 +};
118380 +}
118381 +#endif
118382 +
118383 +struct opt_pass *make_dump_pass(void)
118384 +{
118385 +#if BUILDING_GCC_VERSION >= 4009
118386 + return new dump_pass();
118387 +#else
118388 + return &dump_pass.pass;
118389 +#endif
118390 +}
118391 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118392 new file mode 100644
118393 index 0000000..9addbd7
118394 --- /dev/null
118395 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118396 @@ -0,0 +1,5912 @@
118397 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118398 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118399 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118400 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118401 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118402 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118403 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118404 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118405 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118406 +load_msg_95 load_msg 2 95 NULL
118407 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118408 +init_q_132 init_q 4 132 NULL
118409 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118410 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118411 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118412 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118413 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118414 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118415 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118416 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118417 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118418 +br_port_info_size_268 br_port_info_size 0 268 NULL
118419 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118420 +SYSC_connect_304 SYSC_connect 3 304 NULL
118421 +syslog_print_307 syslog_print 2 307 NULL
118422 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118423 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118424 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118425 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118426 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118427 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118428 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118429 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118430 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118431 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118432 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118433 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118434 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118435 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118436 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118437 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118438 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118439 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118440 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118441 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118442 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118443 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118444 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118445 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118446 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118447 +unlink_queued_645 unlink_queued 4 645 NULL
118448 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118449 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118450 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118451 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118452 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118453 +dvb_video_write_754 dvb_video_write 3 754 NULL
118454 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118455 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118456 +if_writecmd_815 if_writecmd 2 815 NULL
118457 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118458 +error_state_read_859 error_state_read 6 859 NULL
118459 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118460 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118461 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118462 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118463 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118464 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118465 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118466 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118467 +readreg_1017 readreg 0-1 1017 NULL
118468 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118469 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118470 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118471 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118472 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118473 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118474 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118475 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118476 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118477 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118478 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118479 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118480 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118481 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118482 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118483 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118484 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118485 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118486 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118487 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118488 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118489 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118490 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118491 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118492 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118493 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118494 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118495 +ffs_1322 ffs 0 1322 NULL
118496 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118497 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118498 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118499 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118500 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118501 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118502 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118503 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118504 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118505 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118506 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118507 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118508 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118509 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118510 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118511 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118512 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118513 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118514 +fpregs_set_1497 fpregs_set 4 1497 NULL
118515 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118516 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118517 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118518 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118519 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118520 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118521 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118522 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118523 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118524 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118525 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118526 +rmap_add_1677 rmap_add 3 1677 NULL
118527 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118528 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118529 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118530 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118531 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118532 +internal_create_group_1733 internal_create_group 0 1733 NULL
118533 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118534 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118535 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118536 +cosa_write_1774 cosa_write 3 1774 NULL
118537 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118538 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118539 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118540 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118541 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118542 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118543 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118544 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118545 +azx_get_position_1927 azx_get_position 0 1927 NULL
118546 +bdev_erase_1933 bdev_erase 3 1933 NULL
118547 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118548 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118549 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118550 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118551 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118552 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118553 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118554 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118555 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118556 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118557 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118558 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118559 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118560 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118561 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118562 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118563 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118564 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118565 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118566 +audit_expand_2098 audit_expand 0 2098 NULL
118567 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118568 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118569 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118570 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118571 +enable_read_2117 enable_read 3 2117 NULL
118572 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118573 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118574 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118575 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118576 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118577 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118578 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118579 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118580 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118581 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118582 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118583 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118584 +do_update_counters_2259 do_update_counters 4 2259 NULL
118585 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118586 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118587 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118588 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118589 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118590 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118591 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118592 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118593 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118594 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118595 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118596 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118597 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118598 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118599 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118600 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118601 +raid1_size_2419 raid1_size 0-2 2419 NULL
118602 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118603 +wiphy_new_2482 wiphy_new 2 2482 NULL
118604 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118605 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118606 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118607 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118608 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118609 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118610 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118611 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118612 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118613 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118614 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118615 +slot_bytes_2609 slot_bytes 0 2609 NULL
118616 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118617 +switch_status_2629 switch_status 5 2629 NULL
118618 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118619 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118620 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118621 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118622 +oti6858_write_2692 oti6858_write 4 2692 NULL
118623 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118624 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118625 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118626 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118627 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118628 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118629 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118630 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118631 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118632 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118633 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118634 +sock_create_2838 sock_create 0 2838 NULL
118635 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118636 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118637 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118638 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118639 +nla_padlen_2883 nla_padlen 1 2883 NULL
118640 +cmm_write_2896 cmm_write 3 2896 NULL
118641 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118642 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118643 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118644 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118645 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118646 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118647 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118648 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118649 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118650 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118651 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118652 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118653 +depth_write_3021 depth_write 3 3021 NULL
118654 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118655 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118656 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118657 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118658 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118659 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118660 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118661 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118662 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118663 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118664 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118665 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118666 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118667 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118668 +rb_alloc_3102 rb_alloc 1 3102 NULL
118669 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118670 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118671 +print_time_3132 print_time 0 3132 NULL
118672 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118673 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118674 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118675 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118676 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118677 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118678 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118679 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118680 +alloc_context_3194 alloc_context 1 3194 NULL
118681 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118682 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118683 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118684 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118685 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118686 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118687 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118688 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118689 +key_key_read_3241 key_key_read 3 3241 NULL
118690 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118691 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118692 +cgroup_name_3300 cgroup_name 3 3300 NULL
118693 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118694 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118695 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118696 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118697 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118698 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118699 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118700 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118701 +scnprintf_3360 scnprintf 0-2 3360 NULL
118702 +sr_read_3366 sr_read 3 3366 NULL
118703 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118704 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118705 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118706 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118707 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118708 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118709 +softsynth_write_3455 softsynth_write 3 3455 NULL
118710 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118711 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118712 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118713 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118714 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118715 +SyS_readv_3539 SyS_readv 3 3539 NULL
118716 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118717 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118718 +evtchn_read_3569 evtchn_read 3 3569 NULL
118719 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118720 +vc_resize_3585 vc_resize 3-2 3585 NULL
118721 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118722 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118723 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118724 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118725 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118726 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118727 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118728 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118729 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118730 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118731 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118732 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118733 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118734 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118735 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118736 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118737 +get_fd_set_3866 get_fd_set 1 3866 NULL
118738 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118739 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118740 +nvram_write_3894 nvram_write 3 3894 NULL
118741 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118742 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118743 +vcs_write_3910 vcs_write 3 3910 NULL
118744 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118745 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118746 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118747 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118748 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118749 +do_add_counters_3992 do_add_counters 3 3992 NULL
118750 +userspace_status_4004 userspace_status 4 4004 NULL
118751 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118752 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118753 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118754 +blk_end_request_4024 blk_end_request 3 4024 NULL
118755 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118756 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118757 +read_file_queues_4078 read_file_queues 3 4078 NULL
118758 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118759 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118760 +tm6000_read_4151 tm6000_read 3 4151 NULL
118761 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118762 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118763 +get_alua_req_4166 get_alua_req 3 4166 NULL
118764 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118765 +read_file_bool_4180 read_file_bool 3 4180 NULL
118766 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118767 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118768 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118769 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118770 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118771 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118772 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118773 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118774 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118775 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118776 +count_strings_4315 count_strings 0 4315 NULL
118777 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118778 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118779 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118780 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118781 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118782 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118783 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118784 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118785 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118786 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118787 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118788 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118789 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118790 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118791 +set_link_security_4502 set_link_security 4 4502 NULL
118792 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118793 +tty_register_device_4544 tty_register_device 2 4544 NULL
118794 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118795 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118796 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118797 +bch_alloc_4593 bch_alloc 1 4593 NULL
118798 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118799 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118800 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118801 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118802 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118803 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118804 +kone_receive_4690 kone_receive 4 4690 NULL
118805 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118806 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118807 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118808 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118809 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118810 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118811 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118812 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118813 +create_subvol_4791 create_subvol 4 4791 NULL
118814 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118815 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118816 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118817 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118818 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118819 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118820 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118821 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118822 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118823 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118824 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118825 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118826 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118827 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118828 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118829 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118830 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118831 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118832 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118833 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118834 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118835 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118836 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118837 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118838 +sound_write_5102 sound_write 3 5102 NULL
118839 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118840 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118841 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118842 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118843 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118844 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118845 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118846 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118847 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118848 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118849 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118850 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118851 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118852 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118853 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118854 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118855 +cq_free_res_5355 cq_free_res 5 5355 NULL
118856 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118857 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118858 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118859 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118860 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118861 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118862 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118863 +tty_write_5494 tty_write 3 5494 NULL
118864 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118865 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118866 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118867 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118868 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118869 +le_readq_5557 le_readq 0 5557 NULL
118870 +inw_5558 inw 0 5558 NULL
118871 +bioset_create_5580 bioset_create 1 5580 NULL
118872 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118873 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118874 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118875 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118876 +get_arg_5694 get_arg 3 5694 NULL
118877 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118878 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118879 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118880 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118881 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118882 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
118883 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118884 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118885 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118886 +setup_req_5848 setup_req 3 5848 NULL
118887 +ria_page_count_5849 ria_page_count 0 5849 NULL
118888 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118889 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118890 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118891 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118892 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118893 +port_show_regs_5904 port_show_regs 3 5904 NULL
118894 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118895 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118896 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118897 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118898 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118899 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118900 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118901 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118902 +SyS_semop_5980 SyS_semop 3 5980 NULL
118903 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118904 +alloc_msg_6072 alloc_msg 1 6072 NULL
118905 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118906 +_random_read_6098 _random_read 3 6098 NULL
118907 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118908 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118909 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118910 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118911 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118912 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118913 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118914 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118915 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118916 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118917 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118918 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118919 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118920 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118921 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118922 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118923 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118924 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118925 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118926 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118927 +serial_port_in_6291 serial_port_in 0 6291 NULL
118928 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118929 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118930 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118931 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118932 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118933 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118934 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118935 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118936 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118937 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118938 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118939 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118940 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118941 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118942 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118943 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118944 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118945 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118946 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118947 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118948 +mei_read_6507 mei_read 3 6507 NULL
118949 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118950 +wdm_read_6549 wdm_read 3 6549 NULL
118951 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118952 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118953 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118954 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118955 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118956 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118957 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118958 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118959 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118960 +mpeg_read_6708 mpeg_read 3 6708 NULL
118961 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118962 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118963 +video_proc_write_6724 video_proc_write 3 6724 NULL
118964 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118965 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
118966 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118967 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118968 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118969 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118970 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118971 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118972 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118973 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118974 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118975 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118976 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118977 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118978 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118979 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118980 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118981 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118982 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118983 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118984 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118985 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118986 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
118987 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118988 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118989 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118990 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118991 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118992 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118993 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118994 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118995 +request_key_async_6990 request_key_async 4 6990 NULL
118996 +tpl_write_6998 tpl_write 3 6998 NULL
118997 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118998 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118999 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
119000 +wimax_msg_7030 wimax_msg 4 7030 NULL
119001 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
119002 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
119003 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
119004 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
119005 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
119006 +event_enable_read_7074 event_enable_read 3 7074 NULL
119007 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
119008 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
119009 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
119010 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
119011 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
119012 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
119013 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
119014 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
119015 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
119016 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
119017 +get_string_7302 get_string 0 7302 NULL
119018 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
119019 +mgmt_control_7349 mgmt_control 3 7349 NULL
119020 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
119021 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
119022 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
119023 +hweight_long_7388 hweight_long 0-1 7388 NULL
119024 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
119025 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
119026 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
119027 +readb_7401 readb 0 7401 NULL
119028 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
119029 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
119030 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
119031 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
119032 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
119033 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
119034 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
119035 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
119036 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
119037 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
119038 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
119039 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
119040 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
119041 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
119042 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
119043 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
119044 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
119045 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
119046 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
119047 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
119048 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
119049 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
119050 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
119051 +dev_write_7708 dev_write 3 7708 NULL
119052 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
119053 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
119054 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
119055 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
119056 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
119057 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
119058 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
119059 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
119060 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
119061 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
119062 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
119063 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
119064 +config_desc_7878 config_desc 0 7878 NULL
119065 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
119066 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
119067 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
119068 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
119069 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
119070 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
119071 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
119072 +vcs_read_8017 vcs_read 3 8017 NULL
119073 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
119074 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
119075 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
119076 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
119077 +venus_lookup_8121 venus_lookup 4 8121 NULL
119078 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
119079 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
119080 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
119081 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
119082 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
119083 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
119084 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
119085 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
119086 +play_iframe_8219 play_iframe 3 8219 NULL
119087 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
119088 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
119089 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
119090 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
119091 +init_cdev_8274 init_cdev 1 8274 NULL
119092 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
119093 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
119094 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
119095 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
119096 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
119097 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
119098 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
119099 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
119100 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
119101 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
119102 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
119103 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
119104 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
119105 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
119106 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
119107 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
119108 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
119109 +dev_config_8506 dev_config 3 8506 NULL
119110 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
119111 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
119112 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
119113 +user_on_off_8552 user_on_off 2 8552 NULL
119114 +profile_remove_8556 profile_remove 3 8556 NULL
119115 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
119116 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
119117 +tower_write_8580 tower_write 3 8580 NULL
119118 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
119119 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
119120 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
119121 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
119122 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
119123 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
119124 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
119125 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
119126 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
119127 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
119128 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
119129 +arcfb_write_8702 arcfb_write 3 8702 NULL
119130 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
119131 +init_header_8703 init_header 0 8703 &i_size_read_8703
119132 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
119133 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
119134 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
119135 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
119136 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
119137 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
119138 +compound_order_8750 compound_order 0 8750 NULL
119139 +yurex_write_8761 yurex_write 3 8761 NULL
119140 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
119141 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
119142 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
119143 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
119144 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
119145 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
119146 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
119147 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
119148 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
119149 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
119150 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
119151 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
119152 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
119153 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
119154 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
119155 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
119156 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
119157 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
119158 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
119159 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
119160 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
119161 +write_file_ani_8918 write_file_ani 3 8918 NULL
119162 +layout_commit_8926 layout_commit 3 8926 NULL
119163 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
119164 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
119165 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
119166 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
119167 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
119168 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
119169 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
119170 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
119171 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
119172 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
119173 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
119174 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
119175 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
119176 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
119177 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
119178 +nla_put_9042 nla_put 3 9042 NULL
119179 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
119180 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
119181 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
119182 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
119183 +create_queues_9088 create_queues 2-3 9088 NULL
119184 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
119185 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
119186 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
119187 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
119188 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
119189 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
119190 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
119191 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
119192 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
119193 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
119194 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
119195 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
119196 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
119197 +card_send_command_9215 card_send_command 3 9215 NULL
119198 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
119199 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
119200 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
119201 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
119202 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
119203 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
119204 +flakey_status_9274 flakey_status 5 9274 NULL
119205 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
119206 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
119207 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
119208 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
119209 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
119210 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
119211 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
119212 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
119213 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
119214 +read_9397 read 3 9397 NULL
119215 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
119216 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
119217 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
119218 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
119219 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
119220 +get_registers_9470 get_registers 4 9470 NULL nohasharray
119221 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
119222 +crypt_status_9492 crypt_status 5 9492 NULL
119223 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
119224 +lp_write_9511 lp_write 3 9511 NULL
119225 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
119226 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
119227 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
119228 +read_file_dma_9530 read_file_dma 3 9530 NULL
119229 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
119230 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
119231 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
119232 +fw_node_create_9559 fw_node_create 2 9559 NULL
119233 +kobj_map_9566 kobj_map 2-3 9566 NULL
119234 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
119235 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
119236 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
119237 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
119238 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
119239 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
119240 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
119241 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
119242 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
119243 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
119244 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
119245 +dns_query_9676 dns_query 3 9676 NULL
119246 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
119247 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
119248 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
119249 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
119250 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
119251 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
119252 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
119253 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
119254 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
119255 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
119256 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
119257 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
119258 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
119259 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
119260 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
119261 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
119262 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
119263 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
119264 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
119265 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
119266 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
119267 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
119268 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
119269 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
119270 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
119271 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
119272 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
119273 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
119274 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
119275 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
119276 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
119277 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
119278 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
119279 +read_file_misc_9948 read_file_misc 3 9948 NULL
119280 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
119281 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
119282 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
119283 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
119284 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
119285 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
119286 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
119287 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
119288 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
119289 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
119290 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
119291 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
119292 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
119293 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
119294 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
119295 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
119296 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
119297 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
119298 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
119299 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
119300 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
119301 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
119302 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
119303 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
119304 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
119305 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
119306 +read_emulate_10310 read_emulate 2-4 10310 NULL
119307 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
119308 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
119309 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
119310 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
119311 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
119312 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
119313 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
119314 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
119315 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
119316 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
119317 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
119318 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
119319 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
119320 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
119321 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
119322 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
119323 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
119324 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
119325 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119326 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119327 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119328 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119329 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119330 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119331 +otp_read_10594 otp_read 2-4-5 10594 NULL
119332 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119333 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119334 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119335 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119336 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119337 +parport_write_10669 parport_write 0 10669 NULL
119338 +edge_write_10692 edge_write 4 10692 NULL
119339 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119340 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119341 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119342 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119343 +spi_sync_10731 spi_sync 0 10731 NULL
119344 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119345 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119346 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119347 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119348 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119349 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119350 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119351 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119352 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119353 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119354 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119355 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119356 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119357 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119358 +get_scq_10897 get_scq 2 10897 NULL
119359 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119360 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119361 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119362 +kobject_add_10919 kobject_add 0 10919 NULL
119363 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119364 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119365 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119366 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119367 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119368 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119369 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119370 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119371 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119372 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
119373 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
119374 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119375 +count_argc_11083 count_argc 0 11083 NULL
119376 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119377 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119378 +page_offset_11120 page_offset 0 11120 NULL
119379 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119380 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119381 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119382 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119383 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119384 +of_irq_count_11253 of_irq_count 0 11253 NULL
119385 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119386 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119387 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119388 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119389 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119390 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119391 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119392 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119393 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119394 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119395 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119396 +next_segment_11330 next_segment 0-2-1 11330 NULL
119397 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119398 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119399 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119400 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119401 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119402 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119403 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119404 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119405 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119406 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119407 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119408 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119409 +str_to_user_11411 str_to_user 2 11411 NULL
119410 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119411 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119412 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119413 +trace_options_read_11419 trace_options_read 3 11419 NULL
119414 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119415 +bttv_read_11432 bttv_read 3 11432 NULL
119416 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119417 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119418 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119419 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119420 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119421 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119422 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119423 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119424 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119425 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119426 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119427 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119428 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119429 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119430 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119431 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119432 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119433 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119434 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119435 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119436 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119437 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119438 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119439 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119440 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119441 +split_11691 split 2 11691 NULL
119442 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119443 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119444 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119445 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119446 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119447 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119448 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119449 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119450 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119451 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119452 +umc_device_register_11824 umc_device_register 0 11824 NULL
119453 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119454 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119455 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119456 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119457 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119458 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119459 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119460 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119461 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119462 +ti_write_11916 ti_write 4 11916 NULL
119463 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119464 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119465 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119466 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119467 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119468 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119469 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119470 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119471 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119472 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119473 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119474 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119475 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119476 +set_powered_12129 set_powered 4 12129 NULL
119477 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119478 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119479 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119480 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119481 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119482 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119483 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119484 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119485 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119486 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119487 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119488 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119489 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119490 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119491 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119492 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119493 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119494 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119495 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119496 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119497 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119498 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119499 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119500 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119501 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119502 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119503 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119504 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119505 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119506 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119507 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119508 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119509 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119510 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119511 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119512 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119513 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119514 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119515 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119516 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119517 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119518 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119519 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119520 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119521 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119522 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119523 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119524 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119525 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119526 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119527 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119528 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119529 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119530 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119531 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119532 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119533 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119534 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119535 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119536 +ivtv_write_12721 ivtv_write 3 12721 NULL
119537 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119538 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119539 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119540 +listxattr_12769 listxattr 3 12769 NULL
119541 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119542 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119543 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119544 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119545 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119546 +spidev_sync_12842 spidev_sync 0 12842 NULL
119547 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119548 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119549 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119550 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119551 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119552 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119553 +bm_status_write_12964 bm_status_write 3 12964 NULL
119554 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119555 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119556 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119557 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119558 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119559 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119560 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119561 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119562 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119563 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119564 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119565 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119566 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119567 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119568 +blk_update_request_13146 blk_update_request 3 13146 NULL
119569 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119570 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119571 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119572 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119573 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119574 +comedi_read_13199 comedi_read 3 13199 NULL
119575 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119576 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119577 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119578 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119579 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119580 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119581 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119582 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119583 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119584 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119585 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119586 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119587 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119588 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119589 +sd_major_13294 sd_major 0-1 13294 NULL
119590 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119591 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119592 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119593 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119594 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119595 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119596 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119597 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119598 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119599 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119600 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119601 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119602 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119603 +data_read_13494 data_read 3 13494 NULL nohasharray
119604 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119605 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119606 +core_status_13515 core_status 4 13515 NULL
119607 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119608 +bm_init_13529 bm_init 2 13529 NULL
119609 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119610 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119611 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119612 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119613 +cache_write_13589 cache_write 3 13589 NULL
119614 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119615 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119616 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119617 +packet_snd_13634 packet_snd 3 13634 NULL
119618 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119619 +cache_downcall_13666 cache_downcall 3 13666 NULL
119620 +usb_get_string_13693 usb_get_string 0 13693 NULL
119621 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119622 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119623 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119624 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119625 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119626 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119627 +random_read_13815 random_read 3 13815 NULL
119628 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119629 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119630 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119631 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119632 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119633 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119634 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119635 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119636 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119637 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119638 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119639 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119640 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119641 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119642 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119643 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119644 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119645 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119646 +qcam_read_13977 qcam_read 3 13977 NULL
119647 +dsp_read_13980 dsp_read 2 13980 NULL
119648 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119649 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119650 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119651 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119652 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119653 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119654 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119655 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119656 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119657 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119658 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119659 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119660 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119661 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119662 +em_canid_change_14150 em_canid_change 3 14150 NULL
119663 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119664 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119665 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119666 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119667 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119668 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119669 +alloc_async_14208 alloc_async 1 14208 NULL
119670 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119671 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119672 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119673 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119674 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119675 +rr_status_14293 rr_status 5 14293 NULL
119676 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119677 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119678 +oo_objects_14319 oo_objects 0 14319 NULL
119679 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119680 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119681 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119682 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119683 +lowpan_read_14369 lowpan_read 3 14369 NULL
119684 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119685 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119686 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119687 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119688 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119689 +block_size_14443 block_size 0 14443 NULL
119690 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119691 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119692 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119693 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119694 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119695 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119696 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119697 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119698 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119699 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119700 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119701 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119702 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119703 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119704 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119705 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119706 +dbJoin_14644 dbJoin 0 14644 NULL
119707 +profile_replace_14652 profile_replace 3 14652 NULL
119708 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119709 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119710 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119711 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119712 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119713 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119714 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119715 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119716 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119717 +vfd_write_14717 vfd_write 3 14717 NULL
119718 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119719 +raid1_resize_14740 raid1_resize 2 14740 NULL
119720 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119721 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119722 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119723 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119724 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119725 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119726 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119727 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119728 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119729 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119730 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119731 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119732 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119733 +lcd_write_14857 lcd_write 3 14857 NULL
119734 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119735 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119736 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119737 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119738 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119739 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119740 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119741 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119742 +queue_cnt_14951 queue_cnt 0 14951 NULL
119743 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119744 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119745 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119746 +setkey_14987 setkey 3 14987 NULL nohasharray
119747 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119748 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119749 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119750 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119751 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119752 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119753 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119754 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119755 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119756 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119757 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119758 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119759 +start_port_15124 start_port 0 15124 NULL
119760 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119761 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119762 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119763 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119764 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119765 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119766 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119767 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119768 +simple_strtol_15273 simple_strtol 0 15273 NULL
119769 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119770 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119771 +ioread16_15342 ioread16 0 15342 NULL
119772 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119773 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119774 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119775 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119776 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119777 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119778 +get_modalias_15406 get_modalias 2 15406 NULL
119779 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119780 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119781 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119782 +memweight_15450 memweight 2 15450 NULL
119783 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119784 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119785 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119786 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119787 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119788 +persistent_status_15574 persistent_status 4 15574 NULL
119789 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119790 +vme_user_write_15587 vme_user_write 3 15587 NULL
119791 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119792 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119793 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119794 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119795 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119796 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119797 +fs_path_add_15648 fs_path_add 3 15648 NULL
119798 +xsd_read_15653 xsd_read 3 15653 NULL
119799 +unix_bind_15668 unix_bind 3 15668 NULL
119800 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119801 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119802 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119803 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119804 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119805 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119806 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119807 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119808 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119809 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119810 +table_size_15851 table_size 0-1-2 15851 NULL
119811 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119812 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119813 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119814 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119815 +power_read_15939 power_read 3 15939 NULL
119816 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119817 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119818 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119819 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119820 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119821 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119822 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119823 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119824 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119825 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119826 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119827 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119828 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119829 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119830 +fsm_init_16134 fsm_init 2 16134 NULL
119831 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119832 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119833 +mapping_level_16188 mapping_level 2-0 16188 NULL
119834 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119835 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119836 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119837 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119838 +create_table_16213 create_table 2 16213 NULL
119839 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119840 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119841 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119842 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119843 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119844 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119845 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119846 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119847 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119848 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119849 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119850 +account_16283 account 0-4-2 16283 NULL nohasharray
119851 +mirror_status_16283 mirror_status 5 16283 &account_16283
119852 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119853 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119854 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119855 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119856 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119857 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119858 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119859 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119860 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119861 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119862 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119863 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119864 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119865 +cmdline_store_16442 cmdline_store 4 16442 NULL
119866 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119867 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119868 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119869 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119870 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119871 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119872 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119873 +raid10_resize_16537 raid10_resize 2 16537 NULL
119874 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119875 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119876 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119877 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119878 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119879 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119880 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119881 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119882 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119883 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119884 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119885 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119886 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119887 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119888 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119889 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119890 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119891 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119892 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119893 +st_write_16874 st_write 3 16874 NULL
119894 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119895 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119896 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119897 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119898 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119899 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119900 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119901 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119902 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119903 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119904 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119905 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119906 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119907 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119908 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119909 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119910 +entry_length_17093 entry_length 0 17093 NULL
119911 +write_mem_17114 write_mem 3 17114 NULL
119912 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119913 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119914 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119915 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119916 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119917 +sep_read_17161 sep_read 3 17161 NULL
119918 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119919 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119920 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119921 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119922 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119923 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119924 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119925 +sync_request_17208 sync_request 2 17208 NULL
119926 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119927 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119928 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119929 +alloc_ep_17269 alloc_ep 1 17269 NULL
119930 +pg_read_17276 pg_read 3 17276 NULL
119931 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119932 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119933 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119934 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119935 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119936 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119937 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119938 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119939 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119940 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119941 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119942 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119943 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119944 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119945 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119946 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119947 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119948 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119949 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119950 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119951 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119952 +qp_free_res_17541 qp_free_res 5 17541 NULL
119953 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119954 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119955 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119956 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119957 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119958 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119959 +osst_execute_17607 osst_execute 7-6 17607 NULL
119960 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119961 +dma_map_page_17628 dma_map_page 0 17628 NULL
119962 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119963 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119964 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119965 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119966 +venus_rename_17707 venus_rename 4-5 17707 NULL
119967 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119968 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119969 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119970 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119971 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119972 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119973 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119974 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119975 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119976 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119977 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119978 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119979 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119980 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119981 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119982 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119983 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119984 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119985 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119986 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119987 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119988 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119989 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119990 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119991 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119992 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119993 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119994 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119995 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119996 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119997 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
119998 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
119999 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
120000 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
120001 +fpregs_get_18066 fpregs_get 4 18066 NULL
120002 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
120003 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
120004 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
120005 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
120006 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
120007 +svc_getnl_18120 svc_getnl 0 18120 NULL
120008 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
120009 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
120010 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
120011 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
120012 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
120013 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
120014 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
120015 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
120016 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
120017 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
120018 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
120019 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
120020 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
120021 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
120022 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
120023 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
120024 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
120025 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
120026 +um_idi_write_18293 um_idi_write 3 18293 NULL
120027 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
120028 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
120029 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
120030 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
120031 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
120032 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
120033 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
120034 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
120035 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
120036 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
120037 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
120038 +ep_io_18367 ep_io 0 18367 NULL
120039 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
120040 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
120041 +ci_role_write_18388 ci_role_write 3 18388 NULL
120042 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
120043 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
120044 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
120045 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
120046 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
120047 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
120048 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
120049 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
120050 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
120051 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
120052 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
120053 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
120054 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
120055 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
120056 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
120057 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
120058 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
120059 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
120060 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
120061 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
120062 +debug_output_18575 debug_output 3 18575 NULL
120063 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
120064 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
120065 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
120066 +from_buffer_18625 from_buffer 3 18625 NULL
120067 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
120068 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
120069 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
120070 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
120071 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
120072 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
120073 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
120074 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
120075 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
120076 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
120077 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
120078 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
120079 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
120080 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
120081 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
120082 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
120083 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
120084 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
120085 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
120086 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
120087 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
120088 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
120089 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
120090 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
120091 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
120092 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
120093 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
120094 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
120095 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
120096 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
120097 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
120098 +huge_page_size_19008 huge_page_size 0 19008 NULL
120099 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
120100 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
120101 +revalidate_19043 revalidate 2 19043 NULL
120102 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
120103 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
120104 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
120105 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
120106 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
120107 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
120108 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
120109 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
120110 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
120111 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
120112 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
120113 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
120114 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
120115 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
120116 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
120117 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
120118 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
120119 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
120120 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
120121 +ucma_query_19260 ucma_query 4 19260 NULL
120122 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
120123 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
120124 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
120125 +qc_capture_19298 qc_capture 3 19298 NULL
120126 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
120127 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
120128 +debug_read_19322 debug_read 3 19322 NULL
120129 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
120130 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
120131 +closure_sub_19359 closure_sub 2 19359 NULL
120132 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
120133 +read_zero_19366 read_zero 3 19366 NULL
120134 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
120135 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
120136 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
120137 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
120138 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
120139 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
120140 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
120141 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
120142 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
120143 +sky2_read16_19475 sky2_read16 0 19475 NULL
120144 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
120145 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
120146 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
120147 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
120148 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
120149 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
120150 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
120151 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
120152 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
120153 +nfsd_read_19568 nfsd_read 5 19568 NULL
120154 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
120155 +bm_status_read_19583 bm_status_read 3 19583 NULL
120156 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
120157 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
120158 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
120159 +parser_init_19651 parser_init 2 19651 NULL
120160 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
120161 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
120162 +read_reg_19723 read_reg 0 19723 NULL
120163 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
120164 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
120165 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
120166 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
120167 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
120168 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
120169 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
120170 +readhscx_19769 readhscx 0 19769 NULL
120171 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
120172 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
120173 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
120174 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
120175 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
120176 +__nla_put_19857 __nla_put 3 19857 NULL
120177 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
120178 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
120179 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
120180 +mangle_name_19923 mangle_name 0 19923 NULL
120181 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
120182 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
120183 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
120184 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
120185 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
120186 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
120187 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
120188 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
120189 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
120190 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
120191 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
120192 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
120193 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
120194 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
120195 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
120196 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
120197 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
120198 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
120199 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
120200 +target_message_20072 target_message 2 20072 NULL
120201 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
120202 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
120203 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
120204 +team_options_register_20091 team_options_register 3 20091 NULL
120205 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
120206 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
120207 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
120208 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
120209 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
120210 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
120211 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
120212 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
120213 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
120214 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
120215 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
120216 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
120217 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
120218 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
120219 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
120220 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
120221 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
120222 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
120223 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
120224 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
120225 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
120226 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
120227 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
120228 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
120229 +read_buf_20469 read_buf 2 20469 NULL
120230 +bio_trim_20472 bio_trim 2 20472 NULL
120231 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
120232 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
120233 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
120234 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
120235 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
120236 +venus_create_20555 venus_create 4 20555 NULL
120237 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
120238 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
120239 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
120240 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
120241 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
120242 +lirc_write_20604 lirc_write 3 20604 NULL
120243 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
120244 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
120245 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
120246 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
120247 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
120248 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
120249 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
120250 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
120251 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
120252 +cpumask_size_20683 cpumask_size 0 20683 NULL
120253 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
120254 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
120255 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
120256 +__maestro_read_20700 __maestro_read 0 20700 NULL
120257 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
120258 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
120259 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
120260 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
120261 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
120262 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
120263 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
120264 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
120265 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
120266 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
120267 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
120268 +edid_write_20797 edid_write 3 20797 NULL
120269 +lowpan_write_20800 lowpan_write 3 20800 NULL
120270 +strndup_user_20819 strndup_user 2 20819 NULL
120271 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
120272 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
120273 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
120274 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
120275 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
120276 +get_name_20855 get_name 4 20855 NULL
120277 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
120278 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
120279 +srq_free_res_20868 srq_free_res 5 20868 NULL
120280 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
120281 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
120282 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
120283 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
120284 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
120285 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
120286 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
120287 +htable_bits_20933 htable_bits 0 20933 NULL
120288 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
120289 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
120290 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
120291 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
120292 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
120293 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
120294 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
120295 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
120296 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
120297 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
120298 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
120299 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
120300 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
120301 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
120302 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
120303 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
120304 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
120305 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
120306 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
120307 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
120308 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
120309 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
120310 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
120311 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
120312 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
120313 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
120314 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
120315 +input_ff_create_21240 input_ff_create 2 21240 NULL
120316 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
120317 +fru_length_21257 fru_length 0 21257 NULL
120318 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
120319 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
120320 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
120321 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
120322 +add_res_range_21310 add_res_range 4 21310 NULL
120323 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
120324 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
120325 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
120326 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
120327 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
120328 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
120329 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
120330 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
120331 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
120332 +insert_ptr_21386 insert_ptr 6 21386 NULL
120333 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
120334 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
120335 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
120336 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120337 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120338 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120339 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120340 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120341 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120342 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120343 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120344 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120345 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120346 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120347 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120348 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120349 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120350 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120351 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120352 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
120353 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120354 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120355 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120356 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120357 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
120358 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120359 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120360 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120361 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120362 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120363 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120364 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120365 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120366 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120367 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120368 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120369 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120370 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120371 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120372 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120373 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
120374 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120375 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120376 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120377 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120378 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120379 +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
120380 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120381 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120382 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120383 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120384 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120385 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120386 +mem_rw_22085 mem_rw 3 22085 NULL
120387 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120388 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120389 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120390 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120391 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120392 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120393 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120394 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120395 +mem_write_22232 mem_write 3 22232 NULL
120396 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120397 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120398 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120399 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120400 +add_res_tree_22263 add_res_tree 7 22263 NULL
120401 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120402 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120403 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120404 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120405 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120406 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120407 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
120408 +atomic_read_22342 atomic_read 0 22342 NULL
120409 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120410 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120411 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120412 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120413 +zoran_write_22404 zoran_write 3 22404 NULL
120414 +queue_reply_22416 queue_reply 3 22416 NULL
120415 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120416 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120417 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120418 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120419 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
120420 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120421 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120422 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120423 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120424 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120425 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120426 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120427 +snapshot_read_22601 snapshot_read 3 22601 NULL
120428 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120429 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120430 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120431 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120432 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120433 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
120434 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120435 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120436 +reg_umr_22686 reg_umr 5 22686 NULL
120437 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120438 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120439 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120440 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120441 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120442 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120443 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120444 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120445 +print_frame_22769 print_frame 0 22769 NULL
120446 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120447 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120448 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120449 +create_attr_set_22861 create_attr_set 1 22861 NULL
120450 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120451 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120452 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120453 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120454 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120455 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120456 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120457 +__set_xattr_22923 __set_xattr 0 22923 NULL
120458 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120459 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120460 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120461 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120462 +vme_get_size_22964 vme_get_size 0 22964 NULL
120463 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120464 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120465 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120466 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120467 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120468 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120469 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
120470 +st_status_23032 st_status 5 23032 NULL
120471 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120472 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
120473 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120474 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120475 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120476 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120477 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120478 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120479 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120480 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120481 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120482 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120483 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120484 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120485 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120486 +__clear_user_23118 __clear_user 0-2 23118 NULL
120487 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120488 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120489 +read_file_ani_23161 read_file_ani 3 23161 NULL
120490 +usblp_write_23178 usblp_write 3 23178 NULL
120491 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120492 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120493 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120494 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120495 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120496 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120497 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120498 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120499 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120500 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120501 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120502 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120503 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120504 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120505 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120506 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120507 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120508 +page_readlink_23346 page_readlink 3 23346 NULL
120509 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120510 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120511 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120512 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120513 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120514 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120515 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120516 +linear_conf_23485 linear_conf 2 23485 NULL
120517 +event_filter_read_23494 event_filter_read 3 23494 NULL
120518 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120519 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120520 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120521 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120522 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120523 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120524 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120525 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120526 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120527 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120528 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120529 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120530 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120531 +sInW_23663 sInW 0 23663 NULL
120532 +SyS_connect_23669 SyS_connect 3 23669 NULL
120533 +cx18_read_23699 cx18_read 3 23699 NULL
120534 +at_get_23708 at_get 0 23708 NULL
120535 +get_conn_info_23723 get_conn_info 4 23723 NULL
120536 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120537 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120538 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120539 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120540 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120541 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120542 +map_write_23795 map_write 3 23795 NULL
120543 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120544 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120545 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120546 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120547 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120548 +p54_init_common_23850 p54_init_common 1 23850 NULL
120549 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120550 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120551 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120552 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120553 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120554 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120555 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120556 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120557 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120558 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120559 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120560 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120561 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120562 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120563 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120564 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120565 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120566 +give_pages_24021 give_pages 3 24021 NULL
120567 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120568 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120569 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120570 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120571 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120572 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120573 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120574 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120575 +lov_brw_24122 lov_brw 4 24122 NULL
120576 +mpu401_read_24126 mpu401_read 3 24126 NULL
120577 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120578 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120579 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120580 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120581 +adu_read_24177 adu_read 3 24177 NULL
120582 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120583 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120584 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120585 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120586 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120587 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120588 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120589 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120590 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120591 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120592 +thin_status_24278 thin_status 5 24278 NULL
120593 +msg_size_24288 msg_size 0 24288 NULL
120594 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120595 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120596 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120597 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120598 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120599 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120600 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120601 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120602 +igetword_24373 igetword 0 24373 NULL
120603 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120604 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120605 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120606 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120607 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120608 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120609 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120610 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120611 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120612 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120613 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120614 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120615 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120616 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120617 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120618 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120619 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120620 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120621 +pd_video_read_24510 pd_video_read 3 24510 NULL
120622 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120623 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120624 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120625 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120626 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120627 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120628 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120629 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
120630 +SyS_poll_24620 SyS_poll 2 24620 NULL
120631 +context_alloc_24645 context_alloc 3 24645 NULL
120632 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120633 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120634 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120635 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120636 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120637 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120638 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120639 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120640 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120641 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120642 +cache_read_24790 cache_read 3 24790 NULL
120643 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120644 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120645 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120646 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120647 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120648 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120649 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120650 +queues_read_24877 queues_read 3 24877 NULL
120651 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120652 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120653 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120654 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120655 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120656 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120657 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120658 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
120659 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120660 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120661 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120662 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120663 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120664 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120665 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120666 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120667 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120668 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120669 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120670 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120671 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120672 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120673 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120674 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120675 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120676 +stripe_status_25259 stripe_status 5 25259 NULL
120677 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120678 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120679 +vfs_writev_25278 vfs_writev 3 25278 NULL
120680 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120681 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120682 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120683 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120684 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120685 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120686 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120687 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120688 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120689 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120690 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120691 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120692 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120693 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120694 +sb_permission_25523 sb_permission 0 25523 NULL
120695 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120696 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120697 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120698 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120699 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120700 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120701 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120702 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120703 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120704 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120705 +__direct_map_25647 __direct_map 6-5 25647 NULL
120706 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120707 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120708 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120709 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120710 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120711 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120712 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120713 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120714 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120715 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120716 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120717 +sg_read_25799 sg_read 3 25799 NULL
120718 +system_enable_read_25815 system_enable_read 3 25815 NULL
120719 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120720 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120721 +parport_read_25855 parport_read 0 25855 NULL
120722 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120723 +key_attr_size_25865 key_attr_size 0 25865 NULL
120724 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120725 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120726 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120727 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120728 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120729 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120730 +rcname_read_25919 rcname_read 3 25919 NULL
120731 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120732 +key_flags_read_25931 key_flags_read 3 25931 NULL
120733 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120734 +flush_25957 flush 2 25957 NULL
120735 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120736 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120737 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120738 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120739 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120740 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120741 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120742 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120743 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120744 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120745 +read_sb_page_26119 read_sb_page 5 26119 NULL
120746 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120747 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120748 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120749 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120750 +disk_devt_26180 disk_devt 0 26180 NULL
120751 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120752 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120753 +mce_write_26201 mce_write 3 26201 NULL
120754 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120755 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120756 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120757 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120758 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120759 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120760 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120761 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120762 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120763 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120764 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120765 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120766 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120767 +ntty_write_26404 ntty_write 3 26404 NULL
120768 +firmware_store_26408 firmware_store 4 26408 NULL
120769 +pagemap_read_26441 pagemap_read 3 26441 NULL
120770 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120771 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120772 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120773 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120774 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
120775 +read_vmcore_26501 read_vmcore 3 26501 NULL
120776 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120777 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120778 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120779 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120780 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120781 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120782 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120783 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120784 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120785 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120786 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120787 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120788 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120789 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120790 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120791 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120792 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120793 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120794 +bos_desc_26752 bos_desc 0 26752 NULL
120795 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120796 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120797 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120798 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120799 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120800 +smk_write_load_26829 smk_write_load 3 26829 NULL
120801 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120802 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120803 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120804 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120805 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120806 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120807 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120808 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120809 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120810 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120811 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120812 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120813 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120814 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120815 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120816 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120817 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120818 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120819 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120820 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120821 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120822 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120823 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120824 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120825 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120826 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120827 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120828 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120829 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120830 +pms_capture_27142 pms_capture 4 27142 NULL
120831 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120832 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120833 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120834 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120835 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120836 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120837 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120838 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120839 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120840 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120841 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120842 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120843 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120844 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120845 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120846 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120847 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120848 +seq_read_27411 seq_read 3 27411 NULL
120849 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120850 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120851 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120852 +cypress_write_27423 cypress_write 4 27423 NULL
120853 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120854 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120855 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120856 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120857 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120858 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
120859 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120860 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120861 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120862 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120863 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120864 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120865 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120866 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120867 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120868 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120869 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120870 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120871 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120872 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120873 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120874 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120875 +evm_write_key_27715 evm_write_key 3 27715 NULL
120876 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120877 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120878 +load_scode_27738 load_scode 2 27738 NULL
120879 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120880 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120881 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120882 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120883 +SyS_readv_27804 SyS_readv 3 27804 NULL
120884 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120885 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120886 +init_header_complete_27833 init_header_complete 0 27833 NULL
120887 +read_profile_27859 read_profile 3 27859 NULL
120888 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120889 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120890 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120891 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120892 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120893 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120894 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120895 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120896 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120897 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120898 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120899 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120900 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120901 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120902 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120903 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120904 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120905 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120906 +pool_status_28055 pool_status 5 28055 NULL
120907 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120908 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120909 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120910 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120911 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120912 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120913 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120914 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120915 +video_read_28148 video_read 3 28148 NULL
120916 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120917 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120918 +vread_28173 vread 0-3 28173 NULL
120919 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120920 +counter_free_res_28187 counter_free_res 5 28187 NULL
120921 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120922 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120923 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120924 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120925 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120926 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120927 +usemap_size_28281 usemap_size 0 28281 NULL
120928 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120929 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120930 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120931 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120932 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120933 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120934 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120935 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120936 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120937 +snapshot_write_28351 snapshot_write 3 28351 NULL
120938 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120939 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120940 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120941 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120942 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120943 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120944 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120945 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120946 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120947 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120948 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120949 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120950 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120951 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120952 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120953 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120954 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120955 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120956 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120957 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120958 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120959 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120960 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120961 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120962 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120963 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120964 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120965 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120966 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120967 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120968 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120969 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120970 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120971 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120972 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120973 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
120974 +spi_execute_28736 spi_execute 5 28736 NULL
120975 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
120976 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
120977 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
120978 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
120979 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
120980 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
120981 +sel_write_member_28800 sel_write_member 3 28800 NULL
120982 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
120983 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
120984 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
120985 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
120986 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
120987 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
120988 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
120989 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
120990 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
120991 +push_rx_28939 push_rx 3 28939 NULL
120992 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
120993 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
120994 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
120995 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
120996 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
120997 +bin_uuid_28999 bin_uuid 3 28999 NULL
120998 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
120999 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
121000 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
121001 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
121002 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
121003 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
121004 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
121005 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
121006 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
121007 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
121008 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
121009 +snprintf_29125 snprintf 0 29125 NULL
121010 +iov_shorten_29130 iov_shorten 0 29130 NULL
121011 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
121012 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
121013 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
121014 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
121015 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
121016 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
121017 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
121018 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
121019 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
121020 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
121021 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
121022 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
121023 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
121024 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
121025 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
121026 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
121027 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
121028 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
121029 +tun_put_user_29337 tun_put_user 5 29337 NULL
121030 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
121031 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
121032 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
121033 +mempool_create_29437 mempool_create 1 29437 NULL
121034 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
121035 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
121036 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
121037 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
121038 +do_register_entry_29478 do_register_entry 4 29478 NULL
121039 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
121040 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
121041 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
121042 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
121043 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
121044 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
121045 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
121046 +ftrace_write_29551 ftrace_write 3 29551 NULL
121047 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
121048 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
121049 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
121050 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
121051 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
121052 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
121053 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
121054 +slots_per_page_29601 slots_per_page 0 29601 NULL
121055 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
121056 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
121057 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
121058 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
121059 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
121060 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
121061 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
121062 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
121063 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
121064 +probes_write_29711 probes_write 3 29711 NULL
121065 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
121066 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
121067 +std_nic_write_29752 std_nic_write 3 29752 NULL
121068 +static_key_count_29771 static_key_count 0 29771 NULL
121069 +dbAlloc_29794 dbAlloc 0 29794 NULL
121070 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
121071 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
121072 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
121073 +count_partial_29850 count_partial 0 29850 NULL
121074 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
121075 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
121076 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
121077 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
121078 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
121079 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
121080 +write_file_queue_29922 write_file_queue 3 29922 NULL
121081 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
121082 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
121083 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
121084 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
121085 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
121086 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
121087 +drp_wmove_30043 drp_wmove 4 30043 NULL
121088 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
121089 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
121090 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
121091 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
121092 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
121093 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
121094 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
121095 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
121096 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
121097 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
121098 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
121099 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
121100 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
121101 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
121102 +SyS_semop_30227 SyS_semop 3 30227 NULL
121103 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
121104 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
121105 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
121106 +compat_readv_30273 compat_readv 3 30273 NULL
121107 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
121108 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
121109 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
121110 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
121111 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
121112 +i8254_read_30330 i8254_read 0 30330 NULL
121113 +resource_from_user_30341 resource_from_user 3 30341 NULL
121114 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
121115 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
121116 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
121117 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
121118 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
121119 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
121120 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
121121 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
121122 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
121123 +enable_write_30456 enable_write 3 30456 NULL
121124 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
121125 +urandom_read_30462 urandom_read 3 30462 NULL
121126 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
121127 +adu_write_30487 adu_write 3 30487 NULL
121128 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
121129 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
121130 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
121131 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
121132 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
121133 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
121134 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
121135 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
121136 +set_le_30581 set_le 4 30581 NULL
121137 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
121138 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
121139 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
121140 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
121141 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
121142 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
121143 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
121144 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
121145 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
121146 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
121147 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
121148 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
121149 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
121150 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
121151 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
121152 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
121153 +snapshot_status_30744 snapshot_status 5 30744 NULL
121154 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
121155 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
121156 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
121157 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
121158 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
121159 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
121160 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
121161 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
121162 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
121163 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
121164 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
121165 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
121166 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
121167 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
121168 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
121169 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
121170 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
121171 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
121172 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
121173 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
121174 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
121175 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
121176 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
121177 +depth_read_31112 depth_read 3 31112 NULL
121178 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
121179 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
121180 +size_inside_page_31141 size_inside_page 0 31141 NULL
121181 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
121182 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
121183 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
121184 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
121185 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
121186 +__read_reg_31216 __read_reg 0 31216 NULL
121187 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
121188 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
121189 +cyy_readb_31240 cyy_readb 0 31240 NULL
121190 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
121191 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
121192 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
121193 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
121194 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
121195 +command_file_write_31318 command_file_write 3 31318 NULL
121196 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
121197 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
121198 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
121199 +outlen_write_31358 outlen_write 3 31358 NULL
121200 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
121201 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
121202 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
121203 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
121204 +inb_31388 inb 0 31388 NULL
121205 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
121206 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
121207 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
121208 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
121209 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
121210 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
121211 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
121212 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
121213 +alg_setkey_31485 alg_setkey 3 31485 NULL
121214 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
121215 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
121216 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
121217 +hidraw_write_31536 hidraw_write 3 31536 NULL
121218 +usbvision_read_31555 usbvision_read 3 31555 NULL
121219 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
121220 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
121221 +osst_write_31581 osst_write 3 31581 NULL
121222 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
121223 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
121224 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
121225 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
121226 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
121227 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
121228 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
121229 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
121230 +__lgread_31668 __lgread 4 31668 NULL
121231 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
121232 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
121233 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
121234 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
121235 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
121236 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
121237 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
121238 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
121239 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
121240 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
121241 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
121242 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
121243 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
121244 +get_count_order_31800 get_count_order 0 31800 NULL
121245 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
121246 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
121247 +data_write_31805 data_write 3 31805 NULL
121248 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
121249 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
121250 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
121251 +clone_bio_31854 clone_bio 4-3 31854 NULL
121252 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
121253 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
121254 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
121255 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
121256 +xattr_permission_31907 xattr_permission 0 31907 NULL
121257 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
121258 +new_dir_31919 new_dir 3 31919 NULL
121259 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
121260 +era_status_31934 era_status 5 31934 NULL
121261 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
121262 +read_mem_31942 read_mem 3 31942 NULL
121263 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
121264 +vb2_write_31948 vb2_write 3 31948 NULL
121265 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
121266 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
121267 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
121268 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
121269 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
121270 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
121271 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
121272 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
121273 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
121274 +calc_hmac_32010 calc_hmac 3 32010 NULL
121275 +aead_len_32021 aead_len 0 32021 NULL
121276 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
121277 +stk_read_32038 stk_read 3 32038 NULL
121278 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
121279 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
121280 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
121281 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
121282 +bio_alloc_32095 bio_alloc 2 32095 NULL
121283 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
121284 +disk_status_32120 disk_status 4 32120 NULL
121285 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
121286 +venus_link_32165 venus_link 5 32165 NULL
121287 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
121288 +do_writepages_32173 do_writepages 0 32173 NULL
121289 +del_ptr_32197 del_ptr 4 32197 NULL
121290 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
121291 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
121292 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
121293 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
121294 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
121295 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
121296 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
121297 +SyS_select_32319 SyS_select 1 32319 NULL
121298 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
121299 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
121300 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
121301 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
121302 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
121303 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
121304 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
121305 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
121306 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
121307 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
121308 +cache_status_32462 cache_status 5 32462 NULL
121309 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
121310 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
121311 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
121312 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
121313 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
121314 +disconnect_32521 disconnect 4 32521 NULL
121315 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
121316 +ilo_read_32531 ilo_read 3 32531 NULL
121317 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
121318 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
121319 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
121320 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
121321 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
121322 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
121323 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
121324 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
121325 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
121326 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
121327 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
121328 +kvmalloc_32646 kvmalloc 1 32646 NULL
121329 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
121330 +generic_readlink_32654 generic_readlink 3 32654 NULL
121331 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
121332 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
121333 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
121334 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
121335 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
121336 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
121337 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
121338 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
121339 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
121340 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
121341 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
121342 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
121343 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
121344 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
121345 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
121346 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
121347 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
121348 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
121349 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
121350 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121351 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121352 +compat_filldir_32999 compat_filldir 3 32999 NULL
121353 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121354 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121355 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121356 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121357 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121358 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121359 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121360 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121361 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121362 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121363 +alloc_tio_33077 alloc_tio 3 33077 NULL
121364 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121365 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121366 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121367 +SyS_poll_33152 SyS_poll 2 33152 NULL
121368 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121369 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121370 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121371 +pp_read_33210 pp_read 3 33210 NULL
121372 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121373 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121374 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121375 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121376 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121377 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121378 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121379 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121380 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121381 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121382 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121383 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121384 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121385 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121386 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121387 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121388 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121389 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121390 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121391 +message_stats_list_33440 message_stats_list 5 33440 NULL
121392 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121393 +create_entry_33479 create_entry 2 33479 NULL
121394 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121395 +res_counter_read_33499 res_counter_read 4 33499 NULL
121396 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121397 +fb_read_33506 fb_read 3 33506 NULL
121398 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121399 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121400 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121401 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121402 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121403 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121404 +count_subheaders_33591 count_subheaders 0 33591 NULL
121405 +scsi_execute_33596 scsi_execute 5 33596 NULL
121406 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121407 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121408 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121409 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121410 +stride_page_count_33641 stride_page_count 2 33641 NULL
121411 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121412 +inw_p_33668 inw_p 0 33668 NULL
121413 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121414 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121415 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121416 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121417 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121418 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121419 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121420 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121421 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121422 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121423 +hashtab_create_33769 hashtab_create 3 33769 NULL
121424 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121425 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121426 +filter_write_33819 filter_write 3 33819 NULL
121427 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121428 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121429 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121430 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121431 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121432 +get_user_pages_33908 get_user_pages 0 33908 NULL
121433 +sg_nents_33909 sg_nents 0 33909 NULL
121434 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121435 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121436 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121437 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121438 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121439 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121440 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121441 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121442 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121443 +ppp_write_34034 ppp_write 3 34034 NULL
121444 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121445 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121446 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121447 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121448 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121449 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121450 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121451 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121452 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121453 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121454 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121455 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121456 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
121457 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121458 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121459 +device_private_init_34279 device_private_init 0 34279 NULL
121460 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121461 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121462 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121463 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121464 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121465 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121466 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121467 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121468 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121469 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121470 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121471 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121472 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121473 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121474 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121475 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121476 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121477 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121478 +security_socket_create_34439 security_socket_create 0 34439 NULL
121479 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121480 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121481 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121482 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121483 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121484 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121485 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121486 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121487 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121488 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121489 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121490 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121491 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121492 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121493 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121494 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121495 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121496 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121497 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121498 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121499 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121500 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121501 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121502 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121503 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121504 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121505 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121506 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121507 +port_print_34704 port_print 3 34704 NULL
121508 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121509 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121510 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121511 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121512 +bootmode_store_34762 bootmode_store 4 34762 NULL
121513 +device_add_34766 device_add 0 34766 NULL
121514 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121515 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121516 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121517 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121518 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121519 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121520 +file_page_index_34820 file_page_index 0-2 34820 NULL
121521 +bio_segments_34832 bio_segments 0 34832 NULL
121522 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121523 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121524 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121525 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121526 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121527 +msg_print_text_34889 msg_print_text 0 34889 NULL
121528 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121529 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121530 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121531 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121532 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121533 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121534 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121535 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121536 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121537 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121538 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121539 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121540 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121541 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121542 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121543 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121544 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121545 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121546 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121547 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121548 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121549 +message_stats_print_35158 message_stats_print 6 35158 NULL
121550 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121551 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121552 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121553 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121554 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121555 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121556 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121557 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121558 +set_fd_set_35249 set_fd_set 1 35249 NULL
121559 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121560 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121561 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121562 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121563 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121564 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
121565 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121566 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121567 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121568 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121569 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121570 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121571 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121572 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121573 +read_kmem_35372 read_kmem 3 35372 NULL
121574 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121575 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121576 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121577 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121578 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121579 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121580 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121581 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121582 +async_setkey_35521 async_setkey 3 35521 NULL
121583 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121584 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121585 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121586 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121587 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121588 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121589 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121590 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121591 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121592 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121593 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121594 +kernel_readv_35617 kernel_readv 3 35617 NULL
121595 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121596 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121597 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121598 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121599 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121600 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121601 +md_super_write_35703 md_super_write 4 35703 NULL
121602 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121603 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121604 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121605 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121606 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121607 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121608 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121609 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121610 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121611 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121612 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121613 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121614 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121615 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121616 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121617 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121618 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121619 +acl_alloc_35979 acl_alloc 1 35979 NULL
121620 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121621 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121622 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121623 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121624 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121625 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121626 +account_shadowed_36048 account_shadowed 2 36048 NULL
121627 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121628 +write_emulate_36065 write_emulate 2-4 36065 NULL
121629 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121630 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121631 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121632 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121633 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121634 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121635 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121636 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121637 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121638 +twl_set_36154 twl_set 2 36154 NULL
121639 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121640 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121641 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121642 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121643 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121644 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121645 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121646 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121647 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121648 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121649 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121650 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121651 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121652 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121653 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121654 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121655 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121656 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121657 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121658 +lc_create_36332 lc_create 4 36332 NULL
121659 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121660 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121661 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121662 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121663 +to_sector_36361 to_sector 0-1 36361 NULL
121664 +tunables_read_36385 tunables_read 3 36385 NULL
121665 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121666 +sierra_write_36402 sierra_write 4 36402 NULL
121667 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121668 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121669 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121670 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121671 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121672 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121673 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121674 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121675 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121676 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121677 +cmd_loop_36491 cmd_loop 0 36491 NULL
121678 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121679 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121680 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121681 +get_param_l_36518 get_param_l 0 36518 NULL
121682 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121683 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121684 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121685 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121686 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121687 +__erst_read_36579 __erst_read 0 36579 NULL
121688 +put_cmsg_36589 put_cmsg 4 36589 NULL
121689 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121690 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121691 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121692 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121693 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121694 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121695 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121696 +xillybus_read_36678 xillybus_read 3 36678 NULL
121697 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121698 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121699 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121700 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121701 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121702 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121703 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121704 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121705 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121706 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121707 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121708 +cm_write_36858 cm_write 3 36858 NULL
121709 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121710 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121711 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121712 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121713 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121714 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121715 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121716 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121717 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121718 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121719 +setxattr_37006 setxattr 4 37006 NULL
121720 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121721 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121722 +command_file_read_37038 command_file_read 3 37038 NULL
121723 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121724 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121725 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121726 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121727 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121728 +parse_command_37079 parse_command 2 37079 NULL
121729 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121730 +tun_get_user_37094 tun_get_user 5 37094 NULL
121731 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121732 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121733 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121734 +msg_word_37164 msg_word 0 37164 NULL
121735 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121736 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121737 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121738 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121739 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121740 +__do_replace_37227 __do_replace 5 37227 NULL
121741 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121742 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121743 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121744 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121745 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121746 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121747 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121748 +tipc_send_37315 tipc_send 3 37315 NULL
121749 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121750 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121751 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121752 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121753 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121754 +seek_firmware_37372 seek_firmware 2 37372 NULL
121755 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121756 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121757 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121758 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121759 +fru_alloc_37442 fru_alloc 1 37442 NULL
121760 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121761 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121762 +get_est_timing_37484 get_est_timing 0 37484 NULL
121763 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121764 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121765 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121766 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121767 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121768 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121769 +hdr_size_37536 hdr_size 0 37536 NULL
121770 +extent_map_end_37550 extent_map_end 0 37550 NULL
121771 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121772 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121773 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121774 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121775 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121776 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121777 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121778 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121779 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121780 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121781 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121782 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121783 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121784 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121785 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121786 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121787 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121788 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121789 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121790 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121791 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121792 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121793 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121794 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121795 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121796 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121797 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121798 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121799 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121800 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121801 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121802 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121803 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121804 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121805 +write_file_bool_37957 write_file_bool 3 37957 NULL
121806 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121807 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121808 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121809 +vfs_readv_38011 vfs_readv 3 38011 NULL
121810 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121811 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121812 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121813 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121814 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121815 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121816 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121817 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121818 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121819 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121820 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121821 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121822 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121823 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121824 +ep0_read_38095 ep0_read 3 38095 NULL
121825 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121826 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121827 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121828 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121829 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121830 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121831 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121832 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121833 +cdev_add_38176 cdev_add 2-3 38176 NULL
121834 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121835 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121836 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121837 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121838 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121839 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121840 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121841 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121842 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121843 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121844 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121845 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121846 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121847 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121848 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121849 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121850 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121851 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121852 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121853 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121854 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121855 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121856 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121857 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121858 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121859 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121860 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121861 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121862 +dev_names_read_38509 dev_names_read 3 38509 NULL
121863 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121864 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121865 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121866 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121867 +kuc_len_38557 kuc_len 0-1 38557 NULL
121868 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121869 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121870 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121871 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121872 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121873 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121874 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121875 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121876 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121877 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121878 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121879 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121880 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121881 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121882 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121883 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121884 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121885 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121886 +udf_readpages_38761 udf_readpages 4 38761 NULL
121887 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121888 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121889 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121890 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121891 +err_decode_38804 err_decode 2 38804 NULL
121892 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121893 +direct_entry_38836 direct_entry 3 38836 NULL
121894 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121895 +interfaces_38859 interfaces 2 38859 NULL
121896 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121897 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121898 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121899 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121900 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121901 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121902 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121903 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121904 +get_nodes_39012 get_nodes 3 39012 NULL
121905 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121906 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121907 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121908 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121909 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121910 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121911 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121912 +ea_foreach_39133 ea_foreach 0 39133 NULL
121913 +generic_permission_39150 generic_permission 0 39150 NULL
121914 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121915 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121916 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121917 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121918 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121919 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121920 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121921 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121922 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121923 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121924 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121925 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121926 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121927 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121928 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121929 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121930 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121931 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121932 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121933 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121934 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121935 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121936 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121937 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121938 +__send_to_port_39386 __send_to_port 3 39386 NULL
121939 +user_power_read_39414 user_power_read 3 39414 NULL
121940 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121941 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121942 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121943 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121944 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121945 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121946 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121947 +int_proc_write_39542 int_proc_write 3 39542 NULL
121948 +pp_write_39554 pp_write 3 39554 NULL
121949 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121950 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121951 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121952 +ext_depth_39607 ext_depth 0 39607 NULL
121953 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121954 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121955 +sdio_readb_39618 sdio_readb 0 39618 NULL
121956 +set_dev_class_39645 set_dev_class 4 39645 NULL
121957 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
121958 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
121959 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
121960 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
121961 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
121962 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
121963 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
121964 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
121965 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
121966 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
121967 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
121968 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
121969 +pkt_add_39897 pkt_add 3 39897 NULL
121970 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
121971 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
121972 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
121973 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
121974 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
121975 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
121976 +__spi_async_39932 __spi_async 0 39932 NULL
121977 +__get_order_39935 __get_order 0 39935 NULL
121978 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
121979 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
121980 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
121981 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
121982 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
121983 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
121984 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
121985 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
121986 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
121987 +server_name2svname_39998 server_name2svname 4 39998 NULL
121988 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
121989 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
121990 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
121991 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
121992 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
121993 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
121994 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
121995 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
121996 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
121997 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
121998 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
121999 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
122000 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
122001 +pt_write_40159 pt_write 3 40159 NULL
122002 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
122003 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
122004 +allocate_probes_40204 allocate_probes 1 40204 NULL
122005 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
122006 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
122007 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
122008 +osst_read_40237 osst_read 3 40237 NULL
122009 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
122010 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
122011 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
122012 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
122013 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
122014 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
122015 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
122016 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
122017 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
122018 +SyS_bind_40303 SyS_bind 3 40303 NULL
122019 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
122020 +mmio_read_40348 mmio_read 4 40348 NULL
122021 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
122022 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
122023 +get_chars_40373 get_chars 3 40373 NULL
122024 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
122025 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
122026 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
122027 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
122028 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
122029 +SyS_writev_40467 SyS_writev 3 40467 NULL
122030 +SyS_select_40473 SyS_select 1 40473 NULL
122031 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
122032 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
122033 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
122034 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
122035 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
122036 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
122037 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
122038 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
122039 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
122040 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
122041 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
122042 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
122043 +fops_read_40672 fops_read 3 40672 NULL
122044 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
122045 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
122046 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
122047 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
122048 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
122049 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
122050 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
122051 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
122052 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
122053 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
122054 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
122055 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
122056 +card_send_command_40757 card_send_command 3 40757 NULL
122057 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
122058 +pg_write_40766 pg_write 3 40766 NULL
122059 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
122060 +show_list_40775 show_list 3-0 40775 NULL
122061 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
122062 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
122063 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
122064 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
122065 +add_action_40811 add_action 4 40811 NULL
122066 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
122067 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
122068 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
122069 +read_file_queue_40895 read_file_queue 3 40895 NULL
122070 +waiters_read_40902 waiters_read 3 40902 NULL
122071 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
122072 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
122073 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
122074 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
122075 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
122076 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
122077 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
122078 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
122079 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
122080 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
122081 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
122082 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
122083 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
122084 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
122085 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
122086 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
122087 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
122088 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
122089 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
122090 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
122091 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
122092 +dma_attach_41094 dma_attach 5-6 41094 NULL
122093 +provide_user_output_41105 provide_user_output 3 41105 NULL
122094 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
122095 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
122096 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
122097 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
122098 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
122099 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
122100 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
122101 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
122102 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
122103 +erst_read_41260 erst_read 0 41260 NULL
122104 +alloc_context_41283 alloc_context 1 41283 NULL
122105 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
122106 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
122107 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
122108 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
122109 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
122110 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
122111 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
122112 +kmp_init_41373 kmp_init 2 41373 NULL
122113 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
122114 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
122115 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
122116 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
122117 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
122118 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
122119 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
122120 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
122121 +se_io_cb_41461 se_io_cb 3 41461 NULL
122122 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
122123 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
122124 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
122125 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
122126 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
122127 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
122128 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
122129 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
122130 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
122131 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
122132 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
122133 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
122134 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
122135 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
122136 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
122137 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
122138 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
122139 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
122140 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
122141 +a2mp_send_41615 a2mp_send 4 41615 NULL
122142 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
122143 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
122144 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
122145 +get_std_timing_41654 get_std_timing 0 41654 NULL
122146 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
122147 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
122148 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
122149 +connector_write_41709 connector_write 3 41709 NULL
122150 +fillonedir_41746 fillonedir 3 41746 NULL
122151 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
122152 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
122153 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
122154 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
122155 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
122156 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
122157 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
122158 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
122159 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
122160 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
122161 +pci_map_single_41869 pci_map_single 0 41869 NULL
122162 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
122163 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
122164 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
122165 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
122166 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
122167 +read_gssp_41947 read_gssp 3 41947 NULL
122168 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
122169 +portnames_read_41958 portnames_read 3 41958 NULL
122170 +dst_mtu_41969 dst_mtu 0 41969 NULL
122171 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
122172 +pool_allocate_42012 pool_allocate 3 42012 NULL
122173 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
122174 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
122175 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
122176 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
122177 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
122178 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
122179 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
122180 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
122181 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
122182 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
122183 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
122184 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
122185 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
122186 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
122187 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
122188 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
122189 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
122190 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
122191 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
122192 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
122193 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
122194 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
122195 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
122196 +find_last_bit_42260 find_last_bit 0 42260 NULL
122197 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
122198 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
122199 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
122200 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
122201 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
122202 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
122203 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
122204 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
122205 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
122206 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
122207 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
122208 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
122209 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
122210 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
122211 +krng_get_random_42420 krng_get_random 3 42420 NULL
122212 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
122213 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
122214 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
122215 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
122216 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
122217 +kuc_free_42455 kuc_free 2 42455 NULL
122218 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
122219 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
122220 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
122221 +bypass_write_42498 bypass_write 3 42498 NULL
122222 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
122223 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
122224 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
122225 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
122226 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
122227 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
122228 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
122229 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
122230 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
122231 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
122232 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
122233 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
122234 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
122235 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
122236 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
122237 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
122238 +vb2_read_42703 vb2_read 3 42703 NULL
122239 +read_status_42722 read_status 0 42722 NULL
122240 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
122241 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
122242 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
122243 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
122244 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
122245 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
122246 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
122247 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
122248 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
122249 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
122250 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
122251 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
122252 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
122253 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
122254 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
122255 +set_arg_42824 set_arg 3 42824 NULL
122256 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
122257 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
122258 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
122259 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
122260 +hd_end_request_42904 hd_end_request 2 42904 NULL
122261 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
122262 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
122263 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
122264 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
122265 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
122266 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
122267 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
122268 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
122269 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
122270 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
122271 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
122272 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
122273 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
122274 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
122275 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
122276 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
122277 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
122278 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
122279 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
122280 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
122281 +uio_write_43202 uio_write 3 43202 NULL
122282 +iso_callback_43208 iso_callback 3 43208 NULL
122283 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
122284 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
122285 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
122286 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
122287 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
122288 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
122289 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
122290 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
122291 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
122292 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
122293 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
122294 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
122295 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
122296 +xenfb_write_43412 xenfb_write 3 43412 NULL
122297 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
122298 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
122299 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
122300 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
122301 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
122302 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
122303 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
122304 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
122305 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
122306 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
122307 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
122308 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
122309 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
122310 +read_events_43534 read_events 3 43534 NULL
122311 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
122312 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
122313 +request_resource_43548 request_resource 0 43548 NULL
122314 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
122315 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
122316 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
122317 +proc_read_43614 proc_read 3 43614 NULL
122318 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
122319 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
122320 +random_write_43656 random_write 3 43656 NULL
122321 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
122322 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
122323 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
122324 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
122325 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
122326 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
122327 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
122328 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
122329 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
122330 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
122331 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
122332 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
122333 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
122334 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
122335 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
122336 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
122337 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
122338 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
122339 +read_flush_43851 read_flush 3 43851 NULL
122340 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
122341 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
122342 +SendString_43928 SendString 3 43928 NULL
122343 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
122344 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
122345 +nla_reserve_43984 nla_reserve 3 43984 NULL
122346 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
122347 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
122348 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
122349 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
122350 +emit_flags_44006 emit_flags 4-3 44006 NULL
122351 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
122352 +fru_strlen_44046 fru_strlen 0 44046 NULL
122353 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
122354 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
122355 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
122356 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
122357 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
122358 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
122359 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
122360 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
122361 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
122362 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122363 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122364 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122365 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122366 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122367 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122368 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122369 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122370 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122371 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122372 +device_create_file_44285 device_create_file 0 44285 NULL
122373 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122374 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122375 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122376 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122377 +rs_init_44327 rs_init 1 44327 NULL
122378 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122379 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122380 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122381 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122382 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122383 +strlcpy_44400 strlcpy 3 44400 NULL
122384 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122385 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122386 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122387 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122388 +write_file_debug_44476 write_file_debug 3 44476 NULL
122389 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122390 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122391 +bio_advance_44496 bio_advance 2 44496 NULL
122392 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122393 +ac_register_board_44504 ac_register_board 3 44504 NULL
122394 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122395 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122396 +spidev_write_44510 spidev_write 3 44510 NULL
122397 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122398 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122399 +comm_write_44537 comm_write 3 44537 NULL
122400 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122401 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122402 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122403 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122404 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122405 +mpi_resize_44674 mpi_resize 2 44674 NULL
122406 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122407 +ts_read_44687 ts_read 3 44687 NULL
122408 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122409 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122410 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122411 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122412 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122413 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122414 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122415 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122416 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122417 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122418 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122419 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122420 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122421 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122422 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122423 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122424 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122425 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122426 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122427 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122428 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122429 +sisusb_write_44834 sisusb_write 3 44834 NULL
122430 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122431 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122432 +copydesc_user_44855 copydesc_user 3 44855 NULL
122433 +set_advertising_44870 set_advertising 4 44870 NULL
122434 +init_rs_44873 init_rs 1 44873 NULL
122435 +skb_availroom_44883 skb_availroom 0 44883 NULL
122436 +do_tty_write_44896 do_tty_write 5 44896 NULL
122437 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122438 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122439 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122440 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122441 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122442 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122443 +sel_write_user_45060 sel_write_user 3 45060 NULL
122444 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122445 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122446 +snd_card_new_45104 snd_card_new 5 45104 NULL
122447 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122448 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122449 +usbdev_read_45114 usbdev_read 3 45114 NULL
122450 +send_to_tty_45141 send_to_tty 3 45141 NULL
122451 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122452 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122453 +device_write_45156 device_write 3 45156 NULL nohasharray
122454 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
122455 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122456 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122457 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122458 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122459 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122460 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122461 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122462 +event_enable_write_45238 event_enable_write 3 45238 NULL
122463 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122464 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122465 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122466 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122467 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122468 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122469 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122470 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122471 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122472 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122473 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122474 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122475 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122476 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122477 +__node_remap_45458 __node_remap 4 45458 NULL
122478 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122479 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122480 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122481 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122482 +copy_macs_45534 copy_macs 4 45534 NULL
122483 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122484 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122485 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122486 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122487 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122488 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122489 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122490 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122491 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122492 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122493 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122494 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122495 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122496 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122497 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122498 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122499 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122500 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122501 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122502 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122503 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122504 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122505 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122506 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122507 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122508 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122509 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122510 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122511 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122512 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122513 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122514 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122515 +isdn_write_45863 isdn_write 3 45863 NULL
122516 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122517 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122518 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122519 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122520 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122521 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122522 +alloc_mr_45935 alloc_mr 1 45935 NULL
122523 +copy_to_45969 copy_to 3 45969 NULL
122524 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122525 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122526 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122527 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122528 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122529 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122530 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122531 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122532 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122533 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122534 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122535 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122536 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122537 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122538 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122539 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122540 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122541 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122542 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122543 +fq_resize_46195 fq_resize 2 46195 NULL
122544 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122545 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122546 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122547 +dsp_write_46218 dsp_write 2 46218 NULL
122548 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122549 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122550 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122551 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122552 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122553 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122554 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122555 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122556 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122557 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122558 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122559 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122560 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122561 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122562 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122563 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122564 +filldir64_46469 filldir64 3 46469 NULL
122565 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122566 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122567 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122568 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122569 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122570 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122571 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122572 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122573 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122574 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122575 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122576 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122577 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122578 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122579 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122580 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122581 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122582 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122583 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122584 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122585 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122586 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122587 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122588 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122589 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122590 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122591 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122592 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122593 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122594 +readreg_46845 readreg 0 46845 NULL
122595 +spi_async_46857 spi_async 0 46857 NULL
122596 +vsnprintf_46863 vsnprintf 0 46863 NULL
122597 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122598 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122599 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122600 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122601 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122602 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122603 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122604 +fb_write_46924 fb_write 3 46924 NULL
122605 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122606 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122607 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122608 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122609 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122610 +strlcat_46985 strlcat 3 46985 NULL
122611 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122612 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122613 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122614 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122615 +fs_path_len_47060 fs_path_len 0 47060 NULL
122616 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122617 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122618 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122619 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122620 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122621 +mousedev_read_47123 mousedev_read 3 47123 NULL
122622 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122623 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122624 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122625 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122626 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122627 +options_write_47243 options_write 3 47243 NULL
122628 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122629 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122630 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122631 +vsnprintf_47291 vsnprintf 0 47291 NULL
122632 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122633 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122634 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122635 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122636 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122637 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122638 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122639 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122640 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122641 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122642 +nametbl_list_47391 nametbl_list 2 47391 NULL
122643 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122644 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122645 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122646 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122647 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122648 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122649 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122650 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122651 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122652 +newpart_47485 newpart 6-4 47485 NULL
122653 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122654 +core_sys_select_47494 core_sys_select 1 47494 NULL
122655 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122656 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122657 +unlink_simple_47506 unlink_simple 3 47506 NULL
122658 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122659 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122660 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122661 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122662 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122663 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122664 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122665 +read_ldt_47570 read_ldt 2 47570 NULL
122666 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122667 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122668 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122669 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122670 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122671 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122672 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122673 +get_size_47644 get_size 1-2 47644 NULL
122674 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122675 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122676 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122677 +save_microcode_47717 save_microcode 3 47717 NULL
122678 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122679 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122680 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122681 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122682 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122683 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122684 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122685 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122686 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122687 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122688 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122689 +lov_packmd_47810 lov_packmd 0 47810 NULL
122690 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122691 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122692 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122693 +vhci_read_47878 vhci_read 3 47878 NULL
122694 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122695 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122696 +comedi_write_47926 comedi_write 3 47926 NULL
122697 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122698 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122699 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122700 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122701 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122702 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122703 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122704 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122705 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122706 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122707 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122708 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122709 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122710 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122711 +disc_write_48070 disc_write 3 48070 NULL
122712 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122713 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122714 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122715 +load_firmware_48128 load_firmware 2 48128 NULL
122716 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122717 +set_discoverable_48141 set_discoverable 4 48141 NULL
122718 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122719 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122720 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122721 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122722 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122723 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122724 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122725 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122726 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122727 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122728 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122729 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122730 +read_file_recv_48232 read_file_recv 3 48232 NULL
122731 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122732 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122733 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122734 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122735 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122736 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122737 +trace_options_write_48275 trace_options_write 3 48275 NULL
122738 +send_set_info_48288 send_set_info 7 48288 NULL
122739 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122740 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122741 +hash_setkey_48310 hash_setkey 3 48310 NULL
122742 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122743 +skb_add_data_48363 skb_add_data 3 48363 NULL
122744 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122745 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122746 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122747 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122748 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122749 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122750 +print_filtered_48442 print_filtered 2-0 48442 NULL
122751 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122752 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122753 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122754 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122755 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122756 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122757 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122758 +send_control_msg_48498 send_control_msg 6 48498 NULL
122759 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122760 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122761 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122762 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122763 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122764 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122765 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122766 +llog_data_len_48607 llog_data_len 1 48607 NULL
122767 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122768 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122769 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122770 +mtd_read_48655 mtd_read 0 48655 NULL
122771 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122772 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122773 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122774 +altera_drscan_48698 altera_drscan 2 48698 NULL
122775 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122776 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122777 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122778 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122779 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122780 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122781 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122782 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122783 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122784 +azx_get_position_48841 azx_get_position 0 48841 NULL
122785 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122786 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122787 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122788 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122789 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122790 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122791 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122792 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122793 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122794 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122795 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122796 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122797 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122798 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122799 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122800 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122801 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122802 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122803 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122804 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122805 +transient_status_49027 transient_status 4 49027 NULL
122806 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122807 +scsi_register_49094 scsi_register 2 49094 NULL
122808 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122809 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122810 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122811 +pt_read_49136 pt_read 3 49136 NULL
122812 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122813 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122814 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122815 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122816 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122817 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122818 +print_queue_49191 print_queue 0-4 49191 NULL
122819 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122820 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122821 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122822 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122823 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122824 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122825 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122826 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122827 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122828 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122829 +uio_read_49300 uio_read 3 49300 NULL
122830 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122831 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122832 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122833 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122834 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122835 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122836 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122837 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122838 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122839 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122840 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122841 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122842 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122843 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122844 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122845 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122846 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122847 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122848 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122849 +smk_write_access_49561 smk_write_access 3 49561 NULL
122850 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122851 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122852 +readfifo_49583 readfifo 1 49583 NULL
122853 +tap_write_49595 tap_write 3 49595 NULL
122854 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122855 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122856 +heap_init_49617 heap_init 2 49617 NULL
122857 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122858 +port_fops_read_49626 port_fops_read 3 49626 NULL
122859 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122860 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122861 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122862 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122863 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122864 +write_pool_49718 write_pool 3 49718 NULL
122865 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122866 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122867 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122868 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122869 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122870 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122871 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122872 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122873 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122874 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122875 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122876 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122877 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122878 +add_uuid_49831 add_uuid 4 49831 NULL
122879 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122880 +twl4030_write_49846 twl4030_write 2 49846 NULL
122881 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122882 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122883 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122884 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122885 +osc_brw_49896 osc_brw 4 49896 NULL
122886 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122887 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122888 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122889 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122890 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122891 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122892 +isdn_read_50021 isdn_read 3 50021 NULL
122893 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122894 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122895 +ioread8_50049 ioread8 0 50049 NULL
122896 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122897 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122898 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122899 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122900 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122901 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122902 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122903 +read_file_slot_50111 read_file_slot 3 50111 NULL
122904 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122905 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122906 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122907 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122908 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122909 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122910 +odev_update_50169 odev_update 2 50169 NULL
122911 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122912 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122913 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122914 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122915 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122916 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122917 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122918 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122919 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122920 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122921 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122922 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122923 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122924 +do_launder_page_50329 do_launder_page 0 50329 NULL
122925 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122926 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122927 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122928 +tpm_read_50344 tpm_read 3 50344 NULL
122929 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122930 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122931 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122932 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122933 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122934 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122935 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122936 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122937 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122938 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
122939 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
122940 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
122941 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
122942 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
122943 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
122944 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
122945 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
122946 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
122947 +fat_readpages_50582 fat_readpages 4 50582 NULL
122948 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
122949 +xillybus_write_50605 xillybus_write 3 50605 NULL
122950 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
122951 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
122952 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
122953 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
122954 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
122955 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
122956 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
122957 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
122958 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
122959 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
122960 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
122961 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
122962 +tpm_write_50798 tpm_write 3 50798 NULL
122963 +tun_do_read_50800 tun_do_read 4 50800 NULL
122964 +write_flush_50803 write_flush 3 50803 NULL
122965 +dvb_play_50814 dvb_play 3 50814 NULL
122966 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
122967 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
122968 +SetArea_50835 SetArea 4 50835 NULL
122969 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
122970 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
122971 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
122972 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
122973 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
122974 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
122975 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
122976 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
122977 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
122978 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
122979 +show_device_status_50947 show_device_status 0 50947 NULL
122980 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
122981 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
122982 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
122983 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
122984 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
122985 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
122986 +timeout_write_50991 timeout_write 3 50991 NULL
122987 +proc_write_51003 proc_write 3 51003 NULL
122988 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
122989 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
122990 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
122991 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
122992 +dump_midi_51040 dump_midi 3 51040 NULL
122993 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
122994 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
122995 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
122996 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
122997 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
122998 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
122999 +ti_recv_51110 ti_recv 3 51110 NULL
123000 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
123001 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
123002 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
123003 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
123004 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
123005 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
123006 +drm_property_create_51239 drm_property_create 4 51239 NULL
123007 +st_read_51251 st_read 3 51251 NULL
123008 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
123009 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
123010 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
123011 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
123012 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
123013 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
123014 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
123015 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
123016 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
123017 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
123018 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
123019 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
123020 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
123021 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
123022 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
123023 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
123024 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
123025 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
123026 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
123027 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
123028 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
123029 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
123030 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
123031 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
123032 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
123033 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
123034 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
123035 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
123036 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
123037 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
123038 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
123039 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
123040 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
123041 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
123042 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
123043 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
123044 +sel_write_access_51704 sel_write_access 3 51704 NULL
123045 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
123046 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
123047 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
123048 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
123049 +str_read_51731 str_read 4 51731 NULL
123050 +cm4040_read_51732 cm4040_read 3 51732 NULL
123051 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
123052 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
123053 +if_write_51756 if_write 3 51756 NULL
123054 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
123055 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
123056 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
123057 +ioread32_51847 ioread32 0 51847 NULL nohasharray
123058 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
123059 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
123060 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
123061 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
123062 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
123063 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
123064 +user_read_51881 user_read 3 51881 NULL
123065 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
123066 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
123067 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
123068 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
123069 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
123070 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
123071 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
123072 +get_clock_info_51952 get_clock_info 4 51952 NULL
123073 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
123074 +get_zone_51981 get_zone 0-1 51981 NULL
123075 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
123076 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
123077 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
123078 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
123079 +rdmalt_52022 rdmalt 0 52022 NULL
123080 +override_release_52032 override_release 2 52032 NULL
123081 +end_port_52042 end_port 0 52042 NULL
123082 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
123083 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
123084 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
123085 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
123086 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
123087 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
123088 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
123089 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
123090 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
123091 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
123092 +retry_count_read_52129 retry_count_read 3 52129 NULL
123093 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
123094 +sub_alloc_52140 sub_alloc 0 52140 NULL
123095 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
123096 +htable_size_52148 htable_size 0-1 52148 NULL
123097 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
123098 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
123099 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
123100 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
123101 +print_prefix_52176 print_prefix 0 52176 NULL
123102 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
123103 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
123104 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
123105 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
123106 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
123107 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
123108 +shrink_slab_52261 shrink_slab 2 52261 NULL
123109 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
123110 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
123111 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
123112 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
123113 +read_file_reset_52310 read_file_reset 3 52310 NULL
123114 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
123115 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
123116 +hwflags_read_52318 hwflags_read 3 52318 NULL
123117 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
123118 +hur_len_52339 hur_len 0 52339 NULL
123119 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
123120 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
123121 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
123122 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
123123 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
123124 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
123125 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
123126 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
123127 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
123128 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
123129 +delay_status_52431 delay_status 5 52431 NULL
123130 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
123131 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
123132 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
123133 +bt_alloc_52457 bt_alloc 2 52457 NULL
123134 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
123135 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
123136 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
123137 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
123138 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
123139 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
123140 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
123141 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
123142 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
123143 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
123144 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
123145 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
123146 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
123147 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
123148 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
123149 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
123150 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
123151 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
123152 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
123153 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
123154 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
123155 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
123156 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
123157 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
123158 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
123159 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
123160 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
123161 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
123162 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
123163 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
123164 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
123165 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
123166 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
123167 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
123168 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
123169 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
123170 +twlreg_write_52880 twlreg_write 3 52880 NULL
123171 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
123172 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
123173 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
123174 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
123175 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
123176 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
123177 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
123178 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
123179 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
123180 +num_node_state_52989 num_node_state 0 52989 NULL
123181 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
123182 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
123183 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
123184 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
123185 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
123186 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
123187 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
123188 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
123189 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
123190 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
123191 +verity_status_53120 verity_status 5 53120 NULL
123192 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
123193 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
123194 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
123195 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
123196 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
123197 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
123198 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
123199 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
123200 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
123201 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
123202 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
123203 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
123204 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
123205 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
123206 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
123207 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
123208 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
123209 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
123210 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
123211 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
123212 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
123213 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
123214 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
123215 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
123216 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
123217 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
123218 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
123219 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
123220 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
123221 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
123222 +check_acl_53512 check_acl 0 53512 NULL nohasharray
123223 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
123224 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
123225 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
123226 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
123227 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
123228 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
123229 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
123230 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
123231 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
123232 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
123233 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
123234 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
123235 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
123236 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
123237 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
123238 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
123239 +wdm_write_53735 wdm_write 3 53735 NULL
123240 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
123241 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
123242 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
123243 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
123244 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
123245 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
123246 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
123247 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
123248 +setup_data_read_53822 setup_data_read 3 53822 NULL
123249 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
123250 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
123251 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
123252 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
123253 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
123254 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
123255 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
123256 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
123257 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
123258 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
123259 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
123260 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
123261 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
123262 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
123263 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
123264 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
123265 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
123266 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
123267 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
123268 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
123269 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
123270 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
123271 +strn_len_54122 strn_len 0 54122 NULL
123272 +isku_receive_54130 isku_receive 4 54130 NULL
123273 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
123274 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
123275 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
123276 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
123277 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
123278 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
123279 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
123280 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
123281 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
123282 +reada_add_block_54247 reada_add_block 2 54247 NULL
123283 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
123284 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
123285 +audio_write_54261 audio_write 4 54261 NULL nohasharray
123286 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
123287 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
123288 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
123289 +sizeof_long_54276 sizeof_long 0 54276 NULL
123290 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
123291 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
123292 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
123293 +sprintf_54306 sprintf 0 54306 NULL
123294 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
123295 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
123296 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
123297 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
123298 +readlink_copy_54366 readlink_copy 2 54366 NULL
123299 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
123300 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
123301 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
123302 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
123303 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
123304 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
123305 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
123306 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
123307 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
123308 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
123309 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
123310 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
123311 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
123312 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
123313 +viacam_read_54526 viacam_read 3 54526 NULL
123314 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
123315 +setsockopt_54539 setsockopt 5 54539 NULL
123316 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
123317 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
123318 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
123319 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
123320 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
123321 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
123322 +port_fops_write_54627 port_fops_write 3 54627 NULL
123323 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
123324 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
123325 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
123326 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
123327 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
123328 +bus_add_device_54665 bus_add_device 0 54665 NULL
123329 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
123330 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
123331 +evm_read_key_54674 evm_read_key 3 54674 NULL
123332 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
123333 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
123334 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
123335 +kzalloc_54740 kzalloc 1 54740 NULL
123336 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
123337 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
123338 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
123339 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
123340 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
123341 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
123342 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
123343 +nfsd_write_54809 nfsd_write 6 54809 NULL
123344 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
123345 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
123346 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
123347 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
123348 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
123349 +write_rio_54837 write_rio 3 54837 NULL
123350 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
123351 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
123352 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
123353 +printer_read_54851 printer_read 3 54851 NULL
123354 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
123355 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
123356 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
123357 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
123358 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
123359 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
123360 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
123361 +add_port_54941 add_port 2 54941 NULL
123362 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
123363 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
123364 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
123365 +c4_add_card_54968 c4_add_card 3 54968 NULL
123366 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
123367 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123368 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123369 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123370 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123371 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123372 +read_dma_55086 read_dma 3 55086 NULL
123373 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123374 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123375 +filldir_55137 filldir 3 55137 NULL
123376 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123377 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123378 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123379 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123380 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123381 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123382 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123383 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123384 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123385 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123386 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123387 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123388 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123389 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123390 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123391 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123392 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123393 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123394 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123395 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123396 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123397 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123398 +vme_user_read_55338 vme_user_read 3 55338 NULL
123399 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123400 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123401 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123402 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123403 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123404 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123405 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123406 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123407 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123408 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123409 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123410 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123411 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123412 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123413 +ea_get_55522 ea_get 3-0 55522 NULL
123414 +buffer_size_55534 buffer_size 0 55534 NULL
123415 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123416 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123417 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123418 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123419 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123420 +add_partition_55588 add_partition 2 55588 NULL
123421 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123422 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123423 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123424 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123425 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123426 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123427 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123428 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123429 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123430 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123431 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123432 +get_info_55681 get_info 3 55681 NULL
123433 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123434 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123435 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123436 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123437 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123438 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123439 +set_local_name_55757 set_local_name 4 55757 NULL
123440 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123441 +strlen_55778 strlen 0 55778 NULL
123442 +set_spte_55783 set_spte 4-5 55783 NULL
123443 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123444 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123445 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123446 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123447 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123448 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123449 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123450 +hsc_write_55875 hsc_write 3 55875 NULL
123451 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123452 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123453 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123454 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123455 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123456 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123457 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123458 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123459 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123460 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123461 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123462 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123463 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123464 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123465 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123466 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123467 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123468 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123469 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123470 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123471 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123472 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123473 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123474 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123475 +fd_copyin_56247 fd_copyin 3 56247 NULL
123476 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123477 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123478 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123479 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123480 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123481 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123482 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123483 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123484 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123485 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123486 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123487 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123488 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123489 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123490 +dev_read_56369 dev_read 3 56369 NULL
123491 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123492 +lnet_ping_56378 lnet_ping 4 56378 NULL
123493 +write_gssp_56404 write_gssp 3 56404 NULL
123494 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123495 +store_msg_56417 store_msg 3 56417 NULL
123496 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123497 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
123498 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123499 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123500 +fl_create_56435 fl_create 5 56435 NULL
123501 +gnttab_map_56439 gnttab_map 2 56439 NULL
123502 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123503 +set_connectable_56458 set_connectable 4 56458 NULL
123504 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123505 +putused_user_56467 putused_user 3 56467 NULL
123506 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123507 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123508 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123509 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123510 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123511 +init_map_ip_56508 init_map_ip 5 56508 NULL
123512 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123513 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123514 +ip_options_get_56538 ip_options_get 4 56538 NULL
123515 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123516 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123517 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123518 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123519 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123520 +event_filter_write_56609 event_filter_write 3 56609 NULL
123521 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123522 +gather_array_56641 gather_array 3 56641 NULL
123523 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123524 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123525 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123526 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123527 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123528 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123529 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123530 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123531 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123532 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123533 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123534 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123535 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123536 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123537 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123538 +do_syslog_56807 do_syslog 3 56807 NULL
123539 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123540 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123541 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123542 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123543 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123544 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123545 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123546 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123547 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123548 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123549 +strcspn_56913 strcspn 0 56913 NULL
123550 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123551 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123552 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123553 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123554 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123555 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123556 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123557 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123558 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123559 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123560 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123561 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123562 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123563 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123564 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123565 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123566 +altera_get_note_57099 altera_get_note 6 57099 NULL
123567 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123568 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123569 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123570 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123571 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123572 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123573 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123574 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123575 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123576 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123577 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123578 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123579 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123580 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123581 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123582 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123583 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123584 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123585 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123586 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123587 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123588 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123589 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123590 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123591 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123592 +write_file_regval_57313 write_file_regval 3 57313 NULL
123593 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123594 +usblp_read_57342 usblp_read 3 57342 NULL
123595 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123596 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123597 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123598 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123599 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123600 +read_file_blob_57406 read_file_blob 3 57406 NULL
123601 +enclosure_register_57412 enclosure_register 3 57412 NULL
123602 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123603 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123604 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123605 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123606 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123607 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123608 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123609 +skb_headlen_57501 skb_headlen 0 57501 NULL
123610 +copy_in_user_57502 copy_in_user 3 57502 NULL
123611 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123612 +init_tag_map_57515 init_tag_map 3 57515 NULL
123613 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123614 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123615 +cmm_read_57520 cmm_read 3 57520 NULL
123616 +inode_permission_57531 inode_permission 0 57531 NULL
123617 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123618 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123619 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123620 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123621 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123622 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123623 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123624 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123625 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123626 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123627 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123628 +mem_read_57631 mem_read 3 57631 NULL
123629 +r3964_write_57662 r3964_write 4 57662 NULL
123630 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123631 +__lgwrite_57669 __lgwrite 4 57669 NULL
123632 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123633 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123634 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123635 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123636 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123637 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123638 +ld2_57794 ld2 0 57794 NULL
123639 +ivtv_read_57796 ivtv_read 3 57796 NULL
123640 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123641 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123642 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123643 +flash_read_57843 flash_read 3 57843 NULL
123644 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123645 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123646 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123647 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123648 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123649 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123650 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123651 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123652 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123653 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123654 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123655 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123656 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123657 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123658 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123659 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123660 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123661 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123662 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123663 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123664 +mce_async_out_58056 mce_async_out 3 58056 NULL
123665 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123666 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123667 +cm4040_write_58079 cm4040_write 3 58079 NULL
123668 +savemem_58129 savemem 3 58129 NULL
123669 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123670 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123671 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123672 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123673 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123674 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123675 +read_file_debug_58256 read_file_debug 3 58256 NULL
123676 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123677 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123678 +profile_load_58267 profile_load 3 58267 NULL
123679 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123680 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123681 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123682 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123683 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123684 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123685 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123686 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123687 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123688 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123689 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123690 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123691 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123692 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123693 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123694 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123695 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123696 +capabilities_read_58457 capabilities_read 3 58457 NULL
123697 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123698 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123699 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123700 +nv_rd08_58472 nv_rd08 0 58472 NULL
123701 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123702 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123703 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123704 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123705 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123706 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123707 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123708 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123709 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123710 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123711 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123712 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123713 +xip_file_read_58592 xip_file_read 3 58592 NULL
123714 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123715 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123716 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123717 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123718 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123719 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123720 +find_zero_58685 find_zero 0-1 58685 NULL
123721 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123722 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123723 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123724 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123725 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123726 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123727 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123728 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123729 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123730 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123731 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123732 +ep_read_58813 ep_read 3 58813 NULL
123733 +command_write_58841 command_write 3 58841 NULL
123734 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123735 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123736 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123737 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123738 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123739 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123740 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123741 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123742 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123743 +init_list_set_59005 init_list_set 3 59005 NULL
123744 +ep_write_59008 ep_write 3 59008 NULL
123745 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123746 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123747 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123748 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123749 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123750 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123751 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123752 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123753 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123754 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123755 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123756 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123757 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123758 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123759 +ksize_59176 ksize 0 59176 NULL
123760 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123761 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123762 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123763 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123764 +dt3155_read_59226 dt3155_read 3 59226 NULL
123765 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123766 +nla_len_59258 nla_len 0 59258 NULL
123767 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123768 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123769 +fd_copyout_59323 fd_copyout 3 59323 NULL
123770 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123771 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123772 +__map_request_59350 __map_request 0 59350 NULL
123773 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123774 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123775 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123776 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123777 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123778 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123779 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123780 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123781 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123782 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123783 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123784 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123785 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123786 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123787 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123788 +tunables_write_59563 tunables_write 3 59563 NULL
123789 +bio_split_59564 bio_split 2 59564 NULL
123790 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123791 +write_pbl_59583 write_pbl 4 59583 NULL
123792 +memdup_user_59590 memdup_user 2 59590 NULL
123793 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123794 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123795 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123796 +mtrr_write_59622 mtrr_write 3 59622 NULL
123797 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123798 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123799 +hidraw_read_59650 hidraw_read 3 59650 NULL
123800 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123801 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123802 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123803 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123804 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123805 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123806 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123807 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123808 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123809 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123810 +strnlen_59746 strnlen 0 59746 NULL
123811 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123812 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123813 +venus_remove_59781 venus_remove 4 59781 NULL
123814 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123815 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123816 +ipw_write_59807 ipw_write 3 59807 NULL
123817 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123818 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123819 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123820 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123821 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123822 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123823 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123824 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123825 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123826 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123827 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123828 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123829 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123830 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123831 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123832 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123833 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123834 +copy_items_60009 copy_items 7 60009 NULL
123835 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123836 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123837 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123838 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123839 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123840 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123841 +vcs_size_60050 vcs_size 0 60050 NULL
123842 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123843 +compat_writev_60063 compat_writev 3 60063 NULL
123844 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123845 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123846 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123847 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123848 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123849 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123850 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123851 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123852 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123853 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123854 +init_state_60165 init_state 2 60165 NULL
123855 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123856 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123857 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123858 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
123859 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123860 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123861 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123862 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123863 +printer_write_60276 printer_write 3 60276 NULL
123864 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123865 +getDataLength_60301 getDataLength 0 60301 NULL
123866 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123867 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123868 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123869 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123870 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123871 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123872 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123873 +driver_names_read_60399 driver_names_read 3 60399 NULL
123874 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123875 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123876 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123877 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123878 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123879 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123880 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123881 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123882 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123883 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123884 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123885 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123886 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123887 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123888 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123889 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123890 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123891 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123892 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123893 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123894 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123895 +raid_status_60755 raid_status 5 60755 NULL
123896 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123897 +opticon_write_60775 opticon_write 4 60775 NULL
123898 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123899 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123900 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123901 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123902 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123903 +generic_writepages_60871 generic_writepages 0 60871 NULL
123904 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123905 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123906 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123907 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123908 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123909 +pti_char_write_60960 pti_char_write 3 60960 NULL
123910 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123911 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123912 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123913 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123914 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123915 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123916 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123917 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123918 +symtab_init_61050 symtab_init 2 61050 NULL
123919 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
123920 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
123921 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
123922 +get_derived_key_61100 get_derived_key 4 61100 NULL
123923 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
123924 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
123925 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
123926 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
123927 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
123928 +pair_device_61175 pair_device 4 61175 NULL nohasharray
123929 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
123930 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
123931 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
123932 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
123933 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
123934 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
123935 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
123936 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
123937 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
123938 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
123939 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
123940 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
123941 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
123942 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
123943 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
123944 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
123945 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
123946 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
123947 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
123948 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
123949 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
123950 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
123951 +system_enable_write_61396 system_enable_write 3 61396 NULL
123952 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
123953 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
123954 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
123955 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
123956 +erst_errno_61526 erst_errno 0 61526 NULL
123957 +proc_write_device_61541 proc_write_device 3 61541 NULL
123958 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
123959 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
123960 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
123961 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
123962 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
123963 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
123964 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
123965 +seq_open_private_61589 seq_open_private 3 61589 NULL
123966 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
123967 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
123968 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
123969 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
123970 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
123971 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
123972 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
123973 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
123974 +resize_stripes_61650 resize_stripes 2 61650 NULL
123975 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
123976 +insert_one_name_61668 insert_one_name 7 61668 NULL
123977 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
123978 +lock_loop_61681 lock_loop 1 61681 NULL
123979 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
123980 +filter_read_61692 filter_read 3 61692 NULL
123981 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
123982 +iov_length_61716 iov_length 0 61716 NULL
123983 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
123984 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
123985 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
123986 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
123987 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
123988 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
123989 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
123990 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
123991 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
123992 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
123993 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
123994 +get_fw_name_61874 get_fw_name 3 61874 NULL
123995 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
123996 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
123997 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
123998 +kernfs_name_61910 kernfs_name 3 61910 NULL
123999 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
124000 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
124001 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
124002 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
124003 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
124004 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
124005 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
124006 +fix_read_error_61965 fix_read_error 4 61965 NULL
124007 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
124008 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
124009 +cow_file_range_61979 cow_file_range 3 61979 NULL
124010 +dequeue_event_62000 dequeue_event 3 62000 NULL
124011 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
124012 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
124013 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
124014 +SYSC_select_62024 SYSC_select 1 62024 NULL
124015 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
124016 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
124017 +do_pselect_62061 do_pselect 1 62061 NULL
124018 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
124019 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
124020 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
124021 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
124022 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
124023 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
124024 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
124025 +ql_status_62135 ql_status 5 62135 NULL nohasharray
124026 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
124027 +video_usercopy_62151 video_usercopy 2 62151 NULL
124028 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
124029 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
124030 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
124031 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
124032 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
124033 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
124034 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
124035 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
124036 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
124037 +get_random_int_62279 get_random_int 0 62279 NULL
124038 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
124039 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
124040 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
124041 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
124042 +subseq_list_62332 subseq_list 3-0 62332 NULL
124043 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
124044 +flash_write_62354 flash_write 3 62354 NULL
124045 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
124046 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
124047 +altera_irscan_62396 altera_irscan 2 62396 NULL
124048 +set_ssp_62411 set_ssp 4 62411 NULL
124049 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
124050 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
124051 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
124052 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
124053 +debugfs_read_62535 debugfs_read 3 62535 NULL
124054 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
124055 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
124056 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
124057 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
124058 +get_subdir_62581 get_subdir 3 62581 NULL
124059 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
124060 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
124061 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
124062 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
124063 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
124064 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
124065 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
124066 +rdm_62719 rdm 0 62719 NULL
124067 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
124068 +key_replays_read_62746 key_replays_read 3 62746 NULL
124069 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
124070 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
124071 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
124072 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
124073 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
124074 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
124075 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
124076 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
124077 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
124078 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
124079 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
124080 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
124081 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
124082 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
124083 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
124084 +aoechr_write_62883 aoechr_write 3 62883 NULL
124085 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
124086 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
124087 +getdqbuf_62908 getdqbuf 1 62908 NULL
124088 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
124089 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
124090 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
124091 +hwdep_read_62992 hwdep_read 3 62992 NULL
124092 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
124093 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
124094 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
124095 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
124096 +unlink1_63059 unlink1 3 63059 NULL
124097 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
124098 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
124099 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
124100 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
124101 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
124102 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
124103 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
124104 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
124105 +vme_master_read_63221 vme_master_read 0 63221 NULL
124106 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
124107 +ptp_read_63251 ptp_read 4 63251 NULL
124108 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
124109 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
124110 +raid5_resize_63306 raid5_resize 2 63306 NULL
124111 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
124112 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
124113 +proc_info_read_63344 proc_info_read 3 63344 NULL
124114 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
124115 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
124116 +idmouse_read_63374 idmouse_read 3 63374 NULL
124117 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
124118 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
124119 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
124120 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
124121 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
124122 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
124123 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
124124 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
124125 +read_kcore_63488 read_kcore 3 63488 NULL
124126 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
124127 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
124128 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
124129 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
124130 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
124131 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
124132 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
124133 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
124134 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
124135 +write_debug_level_63613 write_debug_level 3 63613 NULL
124136 +__spi_validate_63618 __spi_validate 0 63618 NULL
124137 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
124138 +hid_report_len_63637 hid_report_len 0 63637 NULL
124139 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
124140 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
124141 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
124142 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
124143 +vbi_read_63673 vbi_read 3 63673 NULL
124144 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
124145 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
124146 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
124147 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
124148 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
124149 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
124150 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
124151 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
124152 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
124153 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
124154 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
124155 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
124156 +sel_write_load_63830 sel_write_load 3 63830 NULL
124157 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
124158 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
124159 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
124160 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
124161 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
124162 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
124163 +__team_options_register_63941 __team_options_register 3 63941 NULL
124164 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
124165 +set_bredr_63975 set_bredr 4 63975 NULL
124166 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
124167 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
124168 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
124169 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
124170 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
124171 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
124172 +__sock_create_64069 __sock_create 0 64069 NULL
124173 +get_u8_64076 get_u8 0 64076 NULL
124174 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
124175 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
124176 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
124177 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
124178 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
124179 +to_bytes_64103 to_bytes 0-1 64103 NULL
124180 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
124181 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
124182 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
124183 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
124184 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
124185 +init_bch_64130 init_bch 1-2 64130 NULL
124186 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
124187 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
124188 +number_of_tds_64156 number_of_tds 0 64156 NULL
124189 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
124190 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
124191 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
124192 +read_pulse_64227 read_pulse 0-3 64227 NULL
124193 +ea_len_64229 ea_len 0 64229 NULL
124194 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
124195 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
124196 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
124197 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
124198 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
124199 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
124200 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
124201 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
124202 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
124203 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
124204 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
124205 +ts_write_64336 ts_write 3 64336 NULL
124206 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
124207 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
124208 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
124209 +reg_create_64372 reg_create 5 64372 NULL
124210 +ilo_write_64378 ilo_write 3 64378 NULL
124211 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
124212 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
124213 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
124214 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
124215 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
124216 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
124217 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
124218 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
124219 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
124220 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
124221 +single_open_size_64483 single_open_size 4 64483 NULL
124222 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
124223 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
124224 +remove_uuid_64505 remove_uuid 4 64505 NULL
124225 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
124226 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
124227 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
124228 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
124229 +SyS_bind_64544 SyS_bind 3 64544 NULL
124230 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
124231 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
124232 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
124233 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
124234 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
124235 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
124236 +do_erase_64574 do_erase 4 64574 NULL
124237 +fanotify_write_64623 fanotify_write 3 64623 NULL
124238 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
124239 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
124240 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
124241 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
124242 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
124243 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
124244 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
124245 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
124246 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
124247 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
124248 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
124249 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
124250 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
124251 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
124252 +hwdep_write_64776 hwdep_write 3 64776 NULL
124253 +message_for_md_64777 message_for_md 5 64777 NULL
124254 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
124255 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
124256 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
124257 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
124258 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
124259 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
124260 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
124261 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
124262 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
124263 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
124264 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
124265 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
124266 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
124267 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
124268 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
124269 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
124270 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
124271 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
124272 +insert_dent_65034 insert_dent 7 65034 NULL
124273 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
124274 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
124275 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
124276 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
124277 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
124278 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
124279 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
124280 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
124281 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
124282 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
124283 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
124284 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
124285 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
124286 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
124287 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
124288 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
124289 +get_var_len_65304 get_var_len 0 65304 NULL
124290 +unpack_array_65318 unpack_array 0 65318 NULL
124291 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
124292 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
124293 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
124294 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
124295 +SyS_writev_65372 SyS_writev 3 65372 NULL
124296 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
124297 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
124298 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
124299 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
124300 +device_add_groups_65423 device_add_groups 0 65423 NULL
124301 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
124302 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
124303 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
124304 +clear_user_65470 clear_user 2 65470 NULL
124305 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
124306 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
124307 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
124308 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
124309 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124310 new file mode 100644
124311 index 0000000..560cd7b
124312 --- /dev/null
124313 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124314 @@ -0,0 +1,92 @@
124315 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
124316 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
124317 +mappedread_2627 mappedread 2 2627 NULL
124318 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
124319 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
124320 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
124321 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
124322 +dmu_write_6048 dmu_write 4-3 6048 NULL
124323 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
124324 +update_pages_6225 update_pages 2-3 6225 NULL
124325 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
124326 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
124327 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
124328 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
124329 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
124330 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
124331 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
124332 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
124333 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
124334 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
124335 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
124336 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
124337 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
124338 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
124339 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
124340 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
124341 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
124342 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
124343 +uiocopy_18680 uiocopy 2 18680 NULL
124344 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
124345 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
124346 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
124347 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
124348 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
124349 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
124350 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
124351 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
124352 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
124353 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
124354 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
124355 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
124356 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
124357 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
124358 +splat_write_30943 splat_write 3 30943 NULL
124359 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
124360 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
124361 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
124362 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
124363 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
124364 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
124365 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
124366 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
124367 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
124368 +copyinstr_36980 copyinstr 3 36980 NULL
124369 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
124370 +splat_read_38116 splat_read 3 38116 NULL
124371 +sa_setup_38756 sa_setup 4 38756 NULL
124372 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
124373 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
124374 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
124375 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
124376 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
124377 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124378 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124379 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124380 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124381 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124382 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124383 +kcopy_write_43683 kcopy_write 3 43683 NULL
124384 +uiomove_44355 uiomove 2 44355 NULL
124385 +dmu_read_44418 dmu_read 4-3 44418 NULL
124386 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124387 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124388 +copyin_45945 copyin 3 45945 NULL
124389 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124390 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124391 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124392 +spa_history_write_49650 spa_history_write 3 49650 NULL
124393 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124394 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124395 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124396 +copyout_51409 copyout 3 51409 NULL
124397 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124398 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124399 +get_nvlist_56685 get_nvlist 2 56685 NULL
124400 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124401 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124402 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124403 +zpios_write_61823 zpios_write 3 61823 NULL
124404 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124405 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124406 +zpios_read_64734 zpios_read 3 64734 NULL
124407 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124408 new file mode 100644
124409 index 0000000..95f7abd
124410 --- /dev/null
124411 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124412 @@ -0,0 +1,259 @@
124413 +/*
124414 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124415 + * Licensed under the GPL v2, or (at your option) v3
124416 + *
124417 + * Homepage:
124418 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124419 + *
124420 + * Documentation:
124421 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124422 + *
124423 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124424 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124425 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124426 + *
124427 + * Usage:
124428 + * $ make
124429 + * $ make run
124430 + */
124431 +
124432 +#include "gcc-common.h"
124433 +#include "size_overflow.h"
124434 +
124435 +int plugin_is_GPL_compatible;
124436 +
124437 +tree report_size_overflow_decl;
124438 +
124439 +tree size_overflow_type_HI;
124440 +tree size_overflow_type_SI;
124441 +tree size_overflow_type_DI;
124442 +tree size_overflow_type_TI;
124443 +
124444 +static struct plugin_info size_overflow_plugin_info = {
124445 + .version = "20140725",
124446 + .help = "no-size-overflow\tturn off size overflow checking\n",
124447 +};
124448 +
124449 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124450 +{
124451 + unsigned int arg_count;
124452 + enum tree_code code = TREE_CODE(*node);
124453 +
124454 + switch (code) {
124455 + case FUNCTION_DECL:
124456 + arg_count = type_num_arguments(TREE_TYPE(*node));
124457 + break;
124458 + case FUNCTION_TYPE:
124459 + case METHOD_TYPE:
124460 + arg_count = type_num_arguments(*node);
124461 + break;
124462 + default:
124463 + *no_add_attrs = true;
124464 + error("%s: %qE attribute only applies to functions", __func__, name);
124465 + return NULL_TREE;
124466 + }
124467 +
124468 + for (; args; args = TREE_CHAIN(args)) {
124469 + tree position = TREE_VALUE(args);
124470 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124471 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124472 + *no_add_attrs = true;
124473 + }
124474 + }
124475 + return NULL_TREE;
124476 +}
124477 +
124478 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124479 +{
124480 + unsigned int arg_count;
124481 + enum tree_code code = TREE_CODE(*node);
124482 +
124483 + switch (code) {
124484 + case FUNCTION_DECL:
124485 + arg_count = type_num_arguments(TREE_TYPE(*node));
124486 + break;
124487 + case FUNCTION_TYPE:
124488 + case METHOD_TYPE:
124489 + arg_count = type_num_arguments(*node);
124490 + break;
124491 + case FIELD_DECL:
124492 + return NULL_TREE;
124493 + default:
124494 + *no_add_attrs = true;
124495 + error("%qE attribute only applies to functions", name);
124496 + return NULL_TREE;
124497 + }
124498 +
124499 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124500 + return NULL_TREE;
124501 +
124502 + for (; args; args = TREE_CHAIN(args)) {
124503 + tree position = TREE_VALUE(args);
124504 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124505 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124506 + *no_add_attrs = true;
124507 + }
124508 + }
124509 + return NULL_TREE;
124510 +}
124511 +
124512 +static struct attribute_spec size_overflow_attr = {
124513 + .name = "size_overflow",
124514 + .min_length = 1,
124515 + .max_length = -1,
124516 + .decl_required = true,
124517 + .type_required = false,
124518 + .function_type_required = false,
124519 + .handler = handle_size_overflow_attribute,
124520 +#if BUILDING_GCC_VERSION >= 4007
124521 + .affects_type_identity = false
124522 +#endif
124523 +};
124524 +
124525 +static struct attribute_spec intentional_overflow_attr = {
124526 + .name = "intentional_overflow",
124527 + .min_length = 1,
124528 + .max_length = -1,
124529 + .decl_required = true,
124530 + .type_required = false,
124531 + .function_type_required = false,
124532 + .handler = handle_intentional_overflow_attribute,
124533 +#if BUILDING_GCC_VERSION >= 4007
124534 + .affects_type_identity = false
124535 +#endif
124536 +};
124537 +
124538 +static void register_attributes(void __unused *event_data, void __unused *data)
124539 +{
124540 + register_attribute(&size_overflow_attr);
124541 + register_attribute(&intentional_overflow_attr);
124542 +}
124543 +
124544 +static tree create_typedef(tree type, const char* ident)
124545 +{
124546 + tree new_type, decl;
124547 +
124548 + new_type = build_variant_type_copy(type);
124549 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124550 + DECL_ORIGINAL_TYPE(decl) = type;
124551 + TYPE_NAME(new_type) = decl;
124552 + return new_type;
124553 +}
124554 +
124555 +// Create the noreturn report_size_overflow() function decl.
124556 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124557 +{
124558 + tree const_char_ptr_type_node;
124559 + tree fntype;
124560 +
124561 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124562 +
124563 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124564 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124565 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124566 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124567 +
124568 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124569 + fntype = build_function_type_list(void_type_node,
124570 + const_char_ptr_type_node,
124571 + unsigned_type_node,
124572 + const_char_ptr_type_node,
124573 + const_char_ptr_type_node,
124574 + NULL_TREE);
124575 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124576 +
124577 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124578 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124579 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124580 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124581 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124582 +}
124583 +
124584 +
124585 +extern struct gimple_opt_pass pass_dce;
124586 +
124587 +static struct opt_pass *make_dce_pass(void)
124588 +{
124589 +#if BUILDING_GCC_VERSION >= 4009
124590 + return make_pass_dce(g);
124591 +#else
124592 + return &pass_dce.pass;
124593 +#endif
124594 +}
124595 +
124596 +
124597 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124598 +{
124599 + int i;
124600 + const char * const plugin_name = plugin_info->base_name;
124601 + const int argc = plugin_info->argc;
124602 + const struct plugin_argument * const argv = plugin_info->argv;
124603 + bool enable = true;
124604 + struct register_pass_info insert_size_overflow_asm_pass_info;
124605 + struct register_pass_info __unused dump_before_pass_info;
124606 + struct register_pass_info __unused dump_after_pass_info;
124607 + struct register_pass_info insert_size_overflow_check_info;
124608 + struct register_pass_info dce_pass_info;
124609 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124610 + {
124611 + .base = &report_size_overflow_decl,
124612 + .nelt = 1,
124613 + .stride = sizeof(report_size_overflow_decl),
124614 + .cb = &gt_ggc_mx_tree_node,
124615 + .pchw = &gt_pch_nx_tree_node
124616 + },
124617 + LAST_GGC_ROOT_TAB
124618 + };
124619 +
124620 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124621 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124622 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124623 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124624 +
124625 + dump_before_pass_info.pass = make_dump_pass();
124626 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124627 + dump_before_pass_info.ref_pass_instance_number = 1;
124628 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124629 +
124630 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124631 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124632 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124633 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124634 +
124635 + dump_after_pass_info.pass = make_dump_pass();
124636 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124637 + dump_after_pass_info.ref_pass_instance_number = 1;
124638 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124639 +
124640 + dce_pass_info.pass = make_dce_pass();
124641 + dce_pass_info.reference_pass_name = "vrp";
124642 + dce_pass_info.ref_pass_instance_number = 1;
124643 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124644 +
124645 + if (!plugin_default_version_check(version, &gcc_version)) {
124646 + error(G_("incompatible gcc/plugin versions"));
124647 + return 1;
124648 + }
124649 +
124650 + for (i = 0; i < argc; ++i) {
124651 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124652 + enable = false;
124653 + continue;
124654 + }
124655 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124656 + }
124657 +
124658 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124659 + if (enable) {
124660 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124661 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124662 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124663 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124664 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124665 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124666 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124667 + }
124668 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124669 +
124670 + return 0;
124671 +}
124672 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124673 new file mode 100644
124674 index 0000000..0888f6c
124675 --- /dev/null
124676 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124677 @@ -0,0 +1,364 @@
124678 +/*
124679 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124680 + * Licensed under the GPL v2, or (at your option) v3
124681 + *
124682 + * Homepage:
124683 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124684 + *
124685 + * Documentation:
124686 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124687 + *
124688 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124689 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124690 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124691 + *
124692 + * Usage:
124693 + * $ make
124694 + * $ make run
124695 + */
124696 +
124697 +#include "gcc-common.h"
124698 +#include "size_overflow.h"
124699 +
124700 +#include "size_overflow_hash.h"
124701 +#include "size_overflow_hash_aux.h"
124702 +
124703 +#define CODES_LIMIT 32
124704 +
124705 +static unsigned char get_tree_code(const_tree type)
124706 +{
124707 + switch (TREE_CODE(type)) {
124708 + case ARRAY_TYPE:
124709 + return 0;
124710 + case BOOLEAN_TYPE:
124711 + return 1;
124712 + case ENUMERAL_TYPE:
124713 + return 2;
124714 + case FUNCTION_TYPE:
124715 + return 3;
124716 + case INTEGER_TYPE:
124717 + return 4;
124718 + case POINTER_TYPE:
124719 + return 5;
124720 + case RECORD_TYPE:
124721 + return 6;
124722 + case UNION_TYPE:
124723 + return 7;
124724 + case VOID_TYPE:
124725 + return 8;
124726 + case REAL_TYPE:
124727 + return 9;
124728 + case VECTOR_TYPE:
124729 + return 10;
124730 + case REFERENCE_TYPE:
124731 + return 11;
124732 + case OFFSET_TYPE:
124733 + return 12;
124734 + case COMPLEX_TYPE:
124735 + return 13;
124736 + default:
124737 + debug_tree((tree)type);
124738 + gcc_unreachable();
124739 + }
124740 +}
124741 +
124742 +struct function_hash {
124743 + size_t tree_codes_len;
124744 + unsigned char tree_codes[CODES_LIMIT];
124745 + const_tree fndecl;
124746 + unsigned int hash;
124747 +};
124748 +
124749 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124750 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124751 +{
124752 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124753 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124754 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124755 +
124756 + unsigned int m = 0x57559429;
124757 + unsigned int n = 0x5052acdb;
124758 + const unsigned int *key4 = (const unsigned int *)key;
124759 + unsigned int h = len;
124760 + unsigned int k = len + seed + n;
124761 + unsigned long long p;
124762 +
124763 + while (len >= 8) {
124764 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124765 + len -= 8;
124766 + }
124767 + if (len >= 4) {
124768 + cwmixb(key4[0]) key4 += 1;
124769 + len -= 4;
124770 + }
124771 + if (len)
124772 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124773 + cwmixb(h ^ (k + n));
124774 + return k ^ h;
124775 +
124776 +#undef cwfold
124777 +#undef cwmixa
124778 +#undef cwmixb
124779 +}
124780 +
124781 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124782 +{
124783 + unsigned int fn, codes, seed = 0;
124784 +
124785 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124786 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124787 +
124788 + fn_hash_data->hash = fn ^ codes;
124789 +}
124790 +
124791 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124792 +{
124793 + gcc_assert(type != NULL_TREE);
124794 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124795 +
124796 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124797 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124798 + fn_hash_data->tree_codes_len++;
124799 + type = TREE_TYPE(type);
124800 + }
124801 +}
124802 +
124803 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124804 +{
124805 + const_tree result;
124806 +
124807 + gcc_assert(node != NULL_TREE);
124808 +
124809 + if (DECL_P(node)) {
124810 + result = DECL_RESULT(node);
124811 + if (result != NULL_TREE)
124812 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124813 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124814 + }
124815 +
124816 + gcc_assert(TYPE_P(node));
124817 +
124818 + if (TREE_CODE(node) == FUNCTION_TYPE)
124819 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124820 +
124821 + return set_node_codes(node, fn_hash_data);
124822 +}
124823 +
124824 +static void set_function_codes(struct function_hash *fn_hash_data)
124825 +{
124826 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124827 + enum tree_code code = TREE_CODE(type);
124828 +
124829 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124830 +
124831 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124832 +
124833 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124834 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124835 +}
124836 +
124837 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124838 +{
124839 + while (entry) {
124840 + if (!strcmp(entry->name, func_name))
124841 + return entry;
124842 + entry = entry->next;
124843 + }
124844 + return NULL;
124845 +}
124846 +
124847 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124848 +{
124849 + const struct size_overflow_hash *entry;
124850 + struct function_hash fn_hash_data;
124851 + const char *func_name;
124852 +
124853 + // skip builtins __builtin_constant_p
124854 + if (DECL_BUILT_IN(fndecl))
124855 + return NULL;
124856 +
124857 + fn_hash_data.fndecl = fndecl;
124858 + fn_hash_data.tree_codes_len = 0;
124859 +
124860 + set_function_codes(&fn_hash_data);
124861 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124862 +
124863 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124864 + set_hash(func_name, &fn_hash_data);
124865 +
124866 + entry = size_overflow_hash[fn_hash_data.hash];
124867 + entry = get_proper_hash_chain(entry, func_name);
124868 + if (entry)
124869 + return entry;
124870 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124871 + return get_proper_hash_chain(entry, func_name);
124872 +}
124873 +
124874 +static void print_missing_msg(const_tree func, unsigned int argnum)
124875 +{
124876 + location_t loc;
124877 + const char *curfunc;
124878 + struct function_hash fn_hash_data;
124879 +
124880 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124881 + fn_hash_data.tree_codes_len = 0;
124882 +
124883 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124884 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124885 +
124886 + set_function_codes(&fn_hash_data);
124887 + set_hash(curfunc, &fn_hash_data);
124888 +
124889 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124890 +}
124891 +
124892 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124893 +{
124894 + tree var;
124895 + unsigned int argnum = 1;
124896 +
124897 + if (TREE_CODE(arg) == SSA_NAME)
124898 + arg = SSA_NAME_VAR(arg);
124899 +
124900 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124901 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124902 + continue;
124903 + if (!skip_types(var))
124904 + return argnum;
124905 + }
124906 +
124907 + return CANNOT_FIND_ARG;
124908 +}
124909 +
124910 +static const char *get_asm_string(const_gimple stmt)
124911 +{
124912 + if (!stmt)
124913 + return NULL;
124914 + if (gimple_code(stmt) != GIMPLE_ASM)
124915 + return NULL;
124916 +
124917 + return gimple_asm_string(stmt);
124918 +}
124919 +
124920 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
124921 +{
124922 + const char *str;
124923 +
124924 + str = get_asm_string(stmt);
124925 + if (!str)
124926 + return false;
124927 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
124928 +}
124929 +
124930 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
124931 +{
124932 + const char *str;
124933 +
124934 + str = get_asm_string(stmt);
124935 + if (!str)
124936 + return false;
124937 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
124938 +}
124939 +
124940 +bool is_size_overflow_asm(const_gimple stmt)
124941 +{
124942 + const char *str;
124943 +
124944 + str = get_asm_string(stmt);
124945 + if (!str)
124946 + return false;
124947 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
124948 +}
124949 +
124950 +bool is_a_return_check(const_tree node)
124951 +{
124952 + if (TREE_CODE(node) == FUNCTION_DECL)
124953 + return true;
124954 +
124955 + gcc_assert(TREE_CODE(node) == PARM_DECL);
124956 + return false;
124957 +}
124958 +
124959 +// Get the argnum of a function decl, if node is a return then the argnum is 0
124960 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
124961 +{
124962 + if (is_a_return_check(node))
124963 + return 0;
124964 + else
124965 + return find_arg_number_tree(node, orig_fndecl);
124966 +}
124967 +
124968 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
124969 +{
124970 + const struct size_overflow_hash *hash;
124971 + unsigned int new_argnum;
124972 + tree arg;
124973 + const_tree origarg;
124974 +
124975 + if (argnum == 0)
124976 + return argnum;
124977 +
124978 + hash = get_function_hash(fndecl);
124979 + if (hash && hash->param & (1U << argnum))
124980 + return argnum;
124981 +
124982 + if (DECL_EXTERNAL(fndecl))
124983 + return argnum;
124984 +
124985 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
124986 + argnum--;
124987 + while (origarg && argnum) {
124988 + origarg = TREE_CHAIN(origarg);
124989 + argnum--;
124990 + }
124991 + gcc_assert(argnum == 0);
124992 + gcc_assert(origarg != NULL_TREE);
124993 +
124994 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
124995 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
124996 + return new_argnum;
124997 +
124998 + return CANNOT_FIND_ARG;
124999 +}
125000 +
125001 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
125002 +{
125003 + const struct size_overflow_hash *hash;
125004 +
125005 + hash = get_function_hash(fndecl);
125006 + if (hash && (hash->param & (1U << num)))
125007 + return true;
125008 + return false;
125009 +}
125010 +
125011 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
125012 + * If the function is missing everywhere then print the missing message into stderr.
125013 + */
125014 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
125015 +{
125016 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
125017 +#if BUILDING_GCC_VERSION >= 4008
125018 + case BUILT_IN_BSWAP16:
125019 +#endif
125020 + case BUILT_IN_BSWAP32:
125021 + case BUILT_IN_BSWAP64:
125022 + case BUILT_IN_EXPECT:
125023 + case BUILT_IN_MEMCMP:
125024 + return false;
125025 + default:
125026 + break;
125027 + }
125028 +
125029 + // skip test.c
125030 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
125031 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
125032 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
125033 + }
125034 +
125035 + if (is_in_hash_table(orig_fndecl, num))
125036 + return false;
125037 +
125038 + print_missing_msg(orig_fndecl, num);
125039 + return true;
125040 +}
125041 +
125042 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
125043 new file mode 100644
125044 index 0000000..924652b
125045 --- /dev/null
125046 +++ b/tools/gcc/stackleak_plugin.c
125047 @@ -0,0 +1,395 @@
125048 +/*
125049 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
125050 + * Licensed under the GPL v2
125051 + *
125052 + * Note: the choice of the license means that the compilation process is
125053 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125054 + * but for the kernel it doesn't matter since it doesn't link against
125055 + * any of the gcc libraries
125056 + *
125057 + * gcc plugin to help implement various PaX features
125058 + *
125059 + * - track lowest stack pointer
125060 + *
125061 + * TODO:
125062 + * - initialize all local variables
125063 + *
125064 + * BUGS:
125065 + * - none known
125066 + */
125067 +
125068 +#include "gcc-common.h"
125069 +
125070 +int plugin_is_GPL_compatible;
125071 +
125072 +static int track_frame_size = -1;
125073 +static const char track_function[] = "pax_track_stack";
125074 +static const char check_function[] = "pax_check_alloca";
125075 +static tree track_function_decl, check_function_decl;
125076 +static bool init_locals;
125077 +
125078 +static struct plugin_info stackleak_plugin_info = {
125079 + .version = "201408011900",
125080 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
125081 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
125082 +};
125083 +
125084 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
125085 +{
125086 + gimple check_alloca;
125087 + tree alloca_size;
125088 +
125089 + // insert call to void pax_check_alloca(unsigned long size)
125090 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
125091 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
125092 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
125093 +}
125094 +
125095 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
125096 +{
125097 + gimple track_stack;
125098 +
125099 + // insert call to void pax_track_stack(void)
125100 + track_stack = gimple_build_call(track_function_decl, 0);
125101 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
125102 +}
125103 +
125104 +static bool is_alloca(gimple stmt)
125105 +{
125106 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
125107 + return true;
125108 +
125109 +#if BUILDING_GCC_VERSION >= 4007
125110 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
125111 + return true;
125112 +#endif
125113 +
125114 + return false;
125115 +}
125116 +
125117 +static unsigned int execute_stackleak_tree_instrument(void)
125118 +{
125119 + basic_block bb, entry_bb;
125120 + bool prologue_instrumented = false, is_leaf = true;
125121 +
125122 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
125123 +
125124 + // 1. loop through BBs and GIMPLE statements
125125 + FOR_EACH_BB_FN(bb, cfun) {
125126 + gimple_stmt_iterator gsi;
125127 +
125128 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125129 + gimple stmt;
125130 +
125131 + stmt = gsi_stmt(gsi);
125132 +
125133 + if (is_gimple_call(stmt))
125134 + is_leaf = false;
125135 +
125136 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
125137 + if (!is_alloca(stmt))
125138 + continue;
125139 +
125140 + // 2. insert stack overflow check before each __builtin_alloca call
125141 + stackleak_check_alloca(&gsi);
125142 +
125143 + // 3. insert track call after each __builtin_alloca call
125144 + stackleak_add_instrumentation(&gsi);
125145 + if (bb == entry_bb)
125146 + prologue_instrumented = true;
125147 + }
125148 + }
125149 +
125150 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
125151 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
125152 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
125153 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
125154 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
125155 + return 0;
125156 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
125157 + return 0;
125158 +
125159 + // 4. insert track call at the beginning
125160 + if (!prologue_instrumented) {
125161 + gimple_stmt_iterator gsi;
125162 +
125163 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125164 + if (dom_info_available_p(CDI_DOMINATORS))
125165 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125166 + gsi = gsi_start_bb(bb);
125167 + stackleak_add_instrumentation(&gsi);
125168 + }
125169 +
125170 + return 0;
125171 +}
125172 +
125173 +static unsigned int execute_stackleak_final(void)
125174 +{
125175 + rtx insn, next;
125176 +
125177 + if (cfun->calls_alloca)
125178 + return 0;
125179 +
125180 + // keep calls only if function frame is big enough
125181 + if (get_frame_size() >= track_frame_size)
125182 + return 0;
125183 +
125184 + // 1. find pax_track_stack calls
125185 + for (insn = get_insns(); insn; insn = next) {
125186 + // 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))
125187 + rtx body;
125188 +
125189 + next = NEXT_INSN(insn);
125190 + if (!CALL_P(insn))
125191 + continue;
125192 + body = PATTERN(insn);
125193 + if (GET_CODE(body) != CALL)
125194 + continue;
125195 + body = XEXP(body, 0);
125196 + if (GET_CODE(body) != MEM)
125197 + continue;
125198 + body = XEXP(body, 0);
125199 + if (GET_CODE(body) != SYMBOL_REF)
125200 + continue;
125201 +// if (strcmp(XSTR(body, 0), track_function))
125202 + if (SYMBOL_REF_DECL(body) != track_function_decl)
125203 + continue;
125204 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125205 + // 2. delete call
125206 + delete_insn_and_edges(insn);
125207 +#if BUILDING_GCC_VERSION >= 4007
125208 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
125209 + insn = next;
125210 + next = NEXT_INSN(insn);
125211 + delete_insn_and_edges(insn);
125212 + }
125213 +#endif
125214 + }
125215 +
125216 +// print_simple_rtl(stderr, get_insns());
125217 +// print_rtl(stderr, get_insns());
125218 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125219 +
125220 + return 0;
125221 +}
125222 +
125223 +static bool gate_stackleak_track_stack(void)
125224 +{
125225 + tree section;
125226 +
125227 + if (ix86_cmodel != CM_KERNEL)
125228 + return false;
125229 +
125230 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
125231 + if (section && TREE_VALUE(section)) {
125232 + section = TREE_VALUE(TREE_VALUE(section));
125233 +
125234 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
125235 + return false;
125236 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
125237 + return false;
125238 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
125239 + return false;
125240 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
125241 + return false;
125242 + }
125243 +
125244 + return track_frame_size >= 0;
125245 +}
125246 +
125247 +static void stackleak_start_unit(void *gcc_data, void *user_data)
125248 +{
125249 + tree fntype;
125250 +
125251 + // void pax_track_stack(void)
125252 + fntype = build_function_type_list(void_type_node, NULL_TREE);
125253 + track_function_decl = build_fn_decl(track_function, fntype);
125254 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
125255 + TREE_PUBLIC(track_function_decl) = 1;
125256 + DECL_EXTERNAL(track_function_decl) = 1;
125257 + DECL_ARTIFICIAL(track_function_decl) = 1;
125258 +
125259 + // void pax_check_alloca(unsigned long)
125260 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
125261 + check_function_decl = build_fn_decl(check_function, fntype);
125262 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
125263 + TREE_PUBLIC(check_function_decl) = 1;
125264 + DECL_EXTERNAL(check_function_decl) = 1;
125265 + DECL_ARTIFICIAL(check_function_decl) = 1;
125266 +}
125267 +
125268 +#if BUILDING_GCC_VERSION >= 4009
125269 +static const struct pass_data stackleak_tree_instrument_pass_data = {
125270 +#else
125271 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
125272 + .pass = {
125273 +#endif
125274 + .type = GIMPLE_PASS,
125275 + .name = "stackleak_tree_instrument",
125276 +#if BUILDING_GCC_VERSION >= 4008
125277 + .optinfo_flags = OPTGROUP_NONE,
125278 +#endif
125279 +#if BUILDING_GCC_VERSION >= 4009
125280 + .has_gate = true,
125281 + .has_execute = true,
125282 +#else
125283 + .gate = gate_stackleak_track_stack,
125284 + .execute = execute_stackleak_tree_instrument,
125285 + .sub = NULL,
125286 + .next = NULL,
125287 + .static_pass_number = 0,
125288 +#endif
125289 + .tv_id = TV_NONE,
125290 + .properties_required = PROP_gimple_leh | PROP_cfg,
125291 + .properties_provided = 0,
125292 + .properties_destroyed = 0,
125293 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
125294 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
125295 +#if BUILDING_GCC_VERSION < 4009
125296 + }
125297 +#endif
125298 +};
125299 +
125300 +#if BUILDING_GCC_VERSION >= 4009
125301 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
125302 +#else
125303 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
125304 + .pass = {
125305 +#endif
125306 + .type = RTL_PASS,
125307 + .name = "stackleak_final",
125308 +#if BUILDING_GCC_VERSION >= 4008
125309 + .optinfo_flags = OPTGROUP_NONE,
125310 +#endif
125311 +#if BUILDING_GCC_VERSION >= 4009
125312 + .has_gate = true,
125313 + .has_execute = true,
125314 +#else
125315 + .gate = gate_stackleak_track_stack,
125316 + .execute = execute_stackleak_final,
125317 + .sub = NULL,
125318 + .next = NULL,
125319 + .static_pass_number = 0,
125320 +#endif
125321 + .tv_id = TV_NONE,
125322 + .properties_required = 0,
125323 + .properties_provided = 0,
125324 + .properties_destroyed = 0,
125325 + .todo_flags_start = 0,
125326 + .todo_flags_finish = TODO_dump_func
125327 +#if BUILDING_GCC_VERSION < 4009
125328 + }
125329 +#endif
125330 +};
125331 +
125332 +#if BUILDING_GCC_VERSION >= 4009
125333 +namespace {
125334 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
125335 +public:
125336 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
125337 + bool gate() { return gate_stackleak_track_stack(); }
125338 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
125339 +};
125340 +
125341 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
125342 +public:
125343 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
125344 + bool gate() { return gate_stackleak_track_stack(); }
125345 + unsigned int execute() { return execute_stackleak_final(); }
125346 +};
125347 +}
125348 +
125349 +static opt_pass *make_stackleak_tree_instrument_pass(void)
125350 +{
125351 + return new stackleak_tree_instrument_pass();
125352 +}
125353 +
125354 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
125355 +{
125356 + return new stackleak_final_rtl_opt_pass();
125357 +}
125358 +#else
125359 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
125360 +{
125361 + return &stackleak_tree_instrument_pass.pass;
125362 +}
125363 +
125364 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
125365 +{
125366 + return &stackleak_final_rtl_opt_pass.pass;
125367 +}
125368 +#endif
125369 +
125370 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125371 +{
125372 + const char * const plugin_name = plugin_info->base_name;
125373 + const int argc = plugin_info->argc;
125374 + const struct plugin_argument * const argv = plugin_info->argv;
125375 + int i;
125376 + struct register_pass_info stackleak_tree_instrument_pass_info;
125377 + struct register_pass_info stackleak_final_pass_info;
125378 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125379 + {
125380 + .base = &track_function_decl,
125381 + .nelt = 1,
125382 + .stride = sizeof(track_function_decl),
125383 + .cb = &gt_ggc_mx_tree_node,
125384 + .pchw = &gt_pch_nx_tree_node
125385 + },
125386 + {
125387 + .base = &check_function_decl,
125388 + .nelt = 1,
125389 + .stride = sizeof(check_function_decl),
125390 + .cb = &gt_ggc_mx_tree_node,
125391 + .pchw = &gt_pch_nx_tree_node
125392 + },
125393 + LAST_GGC_ROOT_TAB
125394 + };
125395 +
125396 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125397 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125398 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125399 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125400 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125401 +
125402 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125403 + stackleak_final_pass_info.reference_pass_name = "final";
125404 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125405 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125406 +
125407 + if (!plugin_default_version_check(version, &gcc_version)) {
125408 + error(G_("incompatible gcc/plugin versions"));
125409 + return 1;
125410 + }
125411 +
125412 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125413 +
125414 + for (i = 0; i < argc; ++i) {
125415 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125416 + if (!argv[i].value) {
125417 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125418 + continue;
125419 + }
125420 + track_frame_size = atoi(argv[i].value);
125421 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125422 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125423 + continue;
125424 + }
125425 + if (!strcmp(argv[i].key, "initialize-locals")) {
125426 + if (argv[i].value) {
125427 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125428 + continue;
125429 + }
125430 + init_locals = true;
125431 + continue;
125432 + }
125433 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125434 + }
125435 +
125436 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125437 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125438 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125439 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125440 +
125441 + return 0;
125442 +}
125443 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125444 new file mode 100644
125445 index 0000000..4ee2231
125446 --- /dev/null
125447 +++ b/tools/gcc/structleak_plugin.c
125448 @@ -0,0 +1,274 @@
125449 +/*
125450 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125451 + * Licensed under the GPL v2
125452 + *
125453 + * Note: the choice of the license means that the compilation process is
125454 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125455 + * but for the kernel it doesn't matter since it doesn't link against
125456 + * any of the gcc libraries
125457 + *
125458 + * gcc plugin to forcibly initialize certain local variables that could
125459 + * otherwise leak kernel stack to userland if they aren't properly initialized
125460 + * by later code
125461 + *
125462 + * Homepage: http://pax.grsecurity.net/
125463 + *
125464 + * Usage:
125465 + * $ # for 4.5/4.6/C based 4.7
125466 + * $ 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
125467 + * $ # for C++ based 4.7/4.8+
125468 + * $ 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
125469 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125470 + *
125471 + * TODO: eliminate redundant initializers
125472 + * increase type coverage
125473 + */
125474 +
125475 +#include "gcc-common.h"
125476 +
125477 +// unused C type flag in all versions 4.5-4.9
125478 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125479 +
125480 +int plugin_is_GPL_compatible;
125481 +
125482 +static struct plugin_info structleak_plugin_info = {
125483 + .version = "201401260140",
125484 + .help = "disable\tdo not activate plugin\n",
125485 +};
125486 +
125487 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125488 +{
125489 + *no_add_attrs = true;
125490 +
125491 + // check for types? for now accept everything linux has to offer
125492 + if (TREE_CODE(*node) != FIELD_DECL)
125493 + return NULL_TREE;
125494 +
125495 + *no_add_attrs = false;
125496 + return NULL_TREE;
125497 +}
125498 +
125499 +static struct attribute_spec user_attr = {
125500 + .name = "user",
125501 + .min_length = 0,
125502 + .max_length = 0,
125503 + .decl_required = false,
125504 + .type_required = false,
125505 + .function_type_required = false,
125506 + .handler = handle_user_attribute,
125507 +#if BUILDING_GCC_VERSION >= 4007
125508 + .affects_type_identity = true
125509 +#endif
125510 +};
125511 +
125512 +static void register_attributes(void *event_data, void *data)
125513 +{
125514 + register_attribute(&user_attr);
125515 +// register_attribute(&force_attr);
125516 +}
125517 +
125518 +static tree get_field_type(tree field)
125519 +{
125520 + return strip_array_types(TREE_TYPE(field));
125521 +}
125522 +
125523 +static bool is_userspace_type(tree type)
125524 +{
125525 + tree field;
125526 +
125527 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125528 + tree fieldtype = get_field_type(field);
125529 + enum tree_code code = TREE_CODE(fieldtype);
125530 +
125531 + if (code == RECORD_TYPE || code == UNION_TYPE)
125532 + if (is_userspace_type(fieldtype))
125533 + return true;
125534 +
125535 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125536 + return true;
125537 + }
125538 + return false;
125539 +}
125540 +
125541 +static void finish_type(void *event_data, void *data)
125542 +{
125543 + tree type = (tree)event_data;
125544 +
125545 + if (TYPE_USERSPACE(type))
125546 + return;
125547 +
125548 + if (is_userspace_type(type))
125549 + TYPE_USERSPACE(type) = 1;
125550 +}
125551 +
125552 +static void initialize(tree var)
125553 +{
125554 + basic_block bb;
125555 + gimple_stmt_iterator gsi;
125556 + tree initializer;
125557 + gimple init_stmt;
125558 +
125559 + // this is the original entry bb before the forced split
125560 + // TODO: check further BBs in case more splits occured before us
125561 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125562 +
125563 + // first check if the variable is already initialized, warn otherwise
125564 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125565 + gimple stmt = gsi_stmt(gsi);
125566 + tree rhs1;
125567 +
125568 + // we're looking for an assignment of a single rhs...
125569 + if (!gimple_assign_single_p(stmt))
125570 + continue;
125571 + rhs1 = gimple_assign_rhs1(stmt);
125572 +#if BUILDING_GCC_VERSION >= 4007
125573 + // ... of a non-clobbering expression...
125574 + if (TREE_CLOBBER_P(rhs1))
125575 + continue;
125576 +#endif
125577 + // ... to our variable...
125578 + if (gimple_get_lhs(stmt) != var)
125579 + continue;
125580 + // if it's an initializer then we're good
125581 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125582 + return;
125583 + }
125584 +
125585 + // these aren't the 0days you're looking for
125586 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125587 +
125588 + // build the initializer expression
125589 + initializer = build_constructor(TREE_TYPE(var), NULL);
125590 +
125591 + // build the initializer stmt
125592 + init_stmt = gimple_build_assign(var, initializer);
125593 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125594 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125595 + update_stmt(init_stmt);
125596 +}
125597 +
125598 +static unsigned int handle_function(void)
125599 +{
125600 + basic_block bb;
125601 + unsigned int ret = 0;
125602 + tree var;
125603 + unsigned int i;
125604 +
125605 + // split the first bb where we can put the forced initializers
125606 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125607 + if (dom_info_available_p(CDI_DOMINATORS))
125608 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125609 +
125610 + // enumarate all local variables and forcibly initialize our targets
125611 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125612 + tree type = TREE_TYPE(var);
125613 +
125614 + gcc_assert(DECL_P(var));
125615 + if (!auto_var_in_fn_p(var, current_function_decl))
125616 + continue;
125617 +
125618 + // only care about structure types
125619 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125620 + continue;
125621 +
125622 + // if the type is of interest, examine the variable
125623 + if (TYPE_USERSPACE(type))
125624 + initialize(var);
125625 + }
125626 +
125627 + return ret;
125628 +}
125629 +
125630 +#if BUILDING_GCC_VERSION >= 4009
125631 +static const struct pass_data structleak_pass_data = {
125632 +#else
125633 +static struct gimple_opt_pass structleak_pass = {
125634 + .pass = {
125635 +#endif
125636 + .type = GIMPLE_PASS,
125637 + .name = "structleak",
125638 +#if BUILDING_GCC_VERSION >= 4008
125639 + .optinfo_flags = OPTGROUP_NONE,
125640 +#endif
125641 +#if BUILDING_GCC_VERSION >= 4009
125642 + .has_gate = false,
125643 + .has_execute = true,
125644 +#else
125645 + .gate = NULL,
125646 + .execute = handle_function,
125647 + .sub = NULL,
125648 + .next = NULL,
125649 + .static_pass_number = 0,
125650 +#endif
125651 + .tv_id = TV_NONE,
125652 + .properties_required = PROP_cfg,
125653 + .properties_provided = 0,
125654 + .properties_destroyed = 0,
125655 + .todo_flags_start = 0,
125656 + .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
125657 +#if BUILDING_GCC_VERSION < 4009
125658 + }
125659 +#endif
125660 +};
125661 +
125662 +#if BUILDING_GCC_VERSION >= 4009
125663 +namespace {
125664 +class structleak_pass : public gimple_opt_pass {
125665 +public:
125666 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125667 + unsigned int execute() { return handle_function(); }
125668 +};
125669 +}
125670 +
125671 +static opt_pass *make_structleak_pass(void)
125672 +{
125673 + return new structleak_pass();
125674 +}
125675 +#else
125676 +static struct opt_pass *make_structleak_pass(void)
125677 +{
125678 + return &structleak_pass.pass;
125679 +}
125680 +#endif
125681 +
125682 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125683 +{
125684 + int i;
125685 + const char * const plugin_name = plugin_info->base_name;
125686 + const int argc = plugin_info->argc;
125687 + const struct plugin_argument * const argv = plugin_info->argv;
125688 + bool enable = true;
125689 + struct register_pass_info structleak_pass_info;
125690 +
125691 + structleak_pass_info.pass = make_structleak_pass();
125692 + structleak_pass_info.reference_pass_name = "ssa";
125693 + structleak_pass_info.ref_pass_instance_number = 1;
125694 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125695 +
125696 + if (!plugin_default_version_check(version, &gcc_version)) {
125697 + error(G_("incompatible gcc/plugin versions"));
125698 + return 1;
125699 + }
125700 +
125701 + if (strcmp(lang_hooks.name, "GNU C")) {
125702 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125703 + enable = false;
125704 + }
125705 +
125706 + for (i = 0; i < argc; ++i) {
125707 + if (!strcmp(argv[i].key, "disable")) {
125708 + enable = false;
125709 + continue;
125710 + }
125711 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125712 + }
125713 +
125714 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125715 + if (enable) {
125716 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125717 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125718 + }
125719 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125720 +
125721 + return 0;
125722 +}
125723 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125724 index 88461f0..6fb70a0 100644
125725 --- a/tools/include/linux/compiler.h
125726 +++ b/tools/include/linux/compiler.h
125727 @@ -35,6 +35,14 @@
125728 # define unlikely(x) __builtin_expect(!!(x), 0)
125729 #endif
125730
125731 +#ifndef __size_overflow
125732 +# define __size_overflow(...)
125733 +#endif
125734 +
125735 +#ifndef __intentional_overflow
125736 +# define __intentional_overflow(...)
125737 +#endif
125738 +
125739 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125740
125741 #endif /* _TOOLS_LINUX_COMPILER_H */
125742 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125743 index ce00f7e..0aca5e4 100644
125744 --- a/tools/lib/api/Makefile
125745 +++ b/tools/lib/api/Makefile
125746 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
125747
125748 LIBFILE = libapikfs.a
125749
125750 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125751 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125752 EXTLIBS = -lelf -lpthread -lrt -lm
125753 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125754 ALL_LDFLAGS = $(LDFLAGS)
125755 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125756 index 6789d788..4afd019e 100644
125757 --- a/tools/perf/util/include/asm/alternative-asm.h
125758 +++ b/tools/perf/util/include/asm/alternative-asm.h
125759 @@ -5,4 +5,7 @@
125760
125761 #define altinstruction_entry #
125762
125763 + .macro pax_force_retaddr rip=0, reload=0
125764 + .endm
125765 +
125766 #endif
125767 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125768 index 0a578fe..b81f62d 100644
125769 --- a/tools/virtio/linux/uaccess.h
125770 +++ b/tools/virtio/linux/uaccess.h
125771 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125772 ({ \
125773 typeof(ptr) __pu_ptr = (ptr); \
125774 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125775 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125776 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125777 0; \
125778 })
125779
125780 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125781 index 6a3f29b..a1d2e93 100644
125782 --- a/virt/kvm/kvm_main.c
125783 +++ b/virt/kvm/kvm_main.c
125784 @@ -77,12 +77,17 @@ LIST_HEAD(vm_list);
125785
125786 static cpumask_var_t cpus_hardware_enabled;
125787 static int kvm_usage_count = 0;
125788 -static atomic_t hardware_enable_failed;
125789 +static atomic_unchecked_t hardware_enable_failed;
125790
125791 struct kmem_cache *kvm_vcpu_cache;
125792 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125793
125794 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125795 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125796 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125797 +static struct preempt_ops kvm_preempt_ops = {
125798 + .sched_in = kvm_sched_in,
125799 + .sched_out = kvm_sched_out,
125800 +};
125801
125802 struct dentry *kvm_debugfs_dir;
125803
125804 @@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125805 /* We can read the guest memory with __xxx_user() later on. */
125806 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125807 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125808 - !access_ok(VERIFY_WRITE,
125809 + !access_ok_noprefault(VERIFY_WRITE,
125810 (void __user *)(unsigned long)mem->userspace_addr,
125811 mem->memory_size)))
125812 goto out;
125813 @@ -1637,9 +1642,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125814
125815 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125816 {
125817 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125818 + int r;
125819 + unsigned long addr;
125820
125821 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125822 + addr = gfn_to_hva(kvm, gfn);
125823 + if (kvm_is_error_hva(addr))
125824 + return -EFAULT;
125825 + r = __clear_user((void __user *)addr + offset, len);
125826 + if (r)
125827 + return -EFAULT;
125828 + mark_page_dirty(kvm, gfn);
125829 + return 0;
125830 }
125831 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125832
125833 @@ -1889,7 +1902,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125834 return 0;
125835 }
125836
125837 -static struct file_operations kvm_vcpu_fops = {
125838 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125839 .release = kvm_vcpu_release,
125840 .unlocked_ioctl = kvm_vcpu_ioctl,
125841 #ifdef CONFIG_COMPAT
125842 @@ -2593,7 +2606,7 @@ out:
125843 }
125844 #endif
125845
125846 -static struct file_operations kvm_vm_fops = {
125847 +static file_operations_no_const kvm_vm_fops __read_only = {
125848 .release = kvm_vm_release,
125849 .unlocked_ioctl = kvm_vm_ioctl,
125850 #ifdef CONFIG_COMPAT
125851 @@ -2666,7 +2679,7 @@ out:
125852 return r;
125853 }
125854
125855 -static struct file_operations kvm_chardev_ops = {
125856 +static file_operations_no_const kvm_chardev_ops __read_only = {
125857 .unlocked_ioctl = kvm_dev_ioctl,
125858 .compat_ioctl = kvm_dev_ioctl,
125859 .llseek = noop_llseek,
125860 @@ -2692,7 +2705,7 @@ static void hardware_enable_nolock(void *junk)
125861
125862 if (r) {
125863 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125864 - atomic_inc(&hardware_enable_failed);
125865 + atomic_inc_unchecked(&hardware_enable_failed);
125866 printk(KERN_INFO "kvm: enabling virtualization on "
125867 "CPU%d failed\n", cpu);
125868 }
125869 @@ -2748,10 +2761,10 @@ static int hardware_enable_all(void)
125870
125871 kvm_usage_count++;
125872 if (kvm_usage_count == 1) {
125873 - atomic_set(&hardware_enable_failed, 0);
125874 + atomic_set_unchecked(&hardware_enable_failed, 0);
125875 on_each_cpu(hardware_enable_nolock, NULL, 1);
125876
125877 - if (atomic_read(&hardware_enable_failed)) {
125878 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125879 hardware_disable_all_nolock();
125880 r = -EBUSY;
125881 }
125882 @@ -3156,7 +3169,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125883 kvm_arch_vcpu_put(vcpu);
125884 }
125885
125886 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125887 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125888 struct module *module)
125889 {
125890 int r;
125891 @@ -3203,7 +3216,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125892 if (!vcpu_align)
125893 vcpu_align = __alignof__(struct kvm_vcpu);
125894 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125895 - 0, NULL);
125896 + SLAB_USERCOPY, NULL);
125897 if (!kvm_vcpu_cache) {
125898 r = -ENOMEM;
125899 goto out_free_3;
125900 @@ -3213,9 +3226,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125901 if (r)
125902 goto out_free;
125903
125904 + pax_open_kernel();
125905 kvm_chardev_ops.owner = module;
125906 kvm_vm_fops.owner = module;
125907 kvm_vcpu_fops.owner = module;
125908 + pax_close_kernel();
125909
125910 r = misc_register(&kvm_dev);
125911 if (r) {
125912 @@ -3225,9 +3240,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125913
125914 register_syscore_ops(&kvm_syscore_ops);
125915
125916 - kvm_preempt_ops.sched_in = kvm_sched_in;
125917 - kvm_preempt_ops.sched_out = kvm_sched_out;
125918 -
125919 r = kvm_init_debug();
125920 if (r) {
125921 printk(KERN_ERR "kvm: create debugfs files failed\n");