]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - kernel/patches/grsecurity-3.0-3.17.4-201411220955.patch
kernel: Update to 3.17.4
[people/ms/ipfire-3.x.git] / kernel / patches / grsecurity-3.0-3.17.4-201411220955.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238 index 764f599..c600e2f 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index 1edd5fd..107ff46 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1155,6 +1155,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2175,6 +2179,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334 + nopcid [X86-64]
335 + Disable PCID (Process-Context IDentifier) even if it
336 + is supported by the processor.
337 +
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341 @@ -2467,6 +2475,30 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
342 the specified number of seconds. This is to be used if
343 your oopses keep scrolling off the screen.
344
345 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
346 + virtualization environments that don't cope well with the
347 + expand down segment used by UDEREF on X86-32 or the frequent
348 + page table updates on X86-64.
349 +
350 + pax_sanitize_slab=
351 + Format: { 0 | 1 | off | fast | full }
352 + Options '0' and '1' are only provided for backward
353 + compatibility, 'off' or 'fast' should be used instead.
354 + 0|off : disable slab object sanitization
355 + 1|fast: enable slab object sanitization excluding
356 + whitelisted slabs (default)
357 + full : sanitize all slabs, even the whitelisted ones
358 +
359 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
360 +
361 + pax_extra_latent_entropy
362 + Enable a very simple form of latent entropy extraction
363 + from the first 4GB of memory as the bootmem allocator
364 + passes the memory pages to the buddy allocator.
365 +
366 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
367 + when the processor supports PCID.
368 +
369 pcbit= [HW,ISDN]
370
371 pcd. [PARIDE]
372 diff --git a/Makefile b/Makefile
373 index b60b64d..33b7ec8 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377
378 HOSTCC = gcc
379 HOSTCXX = g++
380 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
381 -HOSTCXXFLAGS = -O2
382 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
383 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
384 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
385
386 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
387 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
388 @@ -450,8 +451,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
389 # Rules shared between *config targets and build targets
390
391 # Basic helpers built in scripts/
392 -PHONY += scripts_basic
393 -scripts_basic:
394 +PHONY += scripts_basic gcc-plugins
395 +scripts_basic: gcc-plugins
396 $(Q)$(MAKE) $(build)=scripts/basic
397 $(Q)rm -f .tmp_quiet_recordmcount
398
399 @@ -625,6 +626,72 @@ endif
400 # Tell gcc to never replace conditional load with a non-conditional one
401 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
402
403 +ifndef DISABLE_PAX_PLUGINS
404 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
405 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
406 +else
407 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
408 +endif
409 +ifneq ($(PLUGINCC),)
410 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
411 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
412 +endif
413 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
414 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
415 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
416 +endif
417 +ifdef CONFIG_KALLOCSTAT_PLUGIN
418 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
419 +endif
420 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
421 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
422 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
423 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
424 +endif
425 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
426 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
427 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
428 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
429 +endif
430 +endif
431 +ifdef CONFIG_CHECKER_PLUGIN
432 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
433 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
434 +endif
435 +endif
436 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
437 +ifdef CONFIG_PAX_SIZE_OVERFLOW
438 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
439 +endif
440 +ifdef CONFIG_PAX_LATENT_ENTROPY
441 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
442 +endif
443 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
444 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
445 +endif
446 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
450 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
451 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
452 +ifeq ($(KBUILD_EXTMOD),)
453 +gcc-plugins:
454 + $(Q)$(MAKE) $(build)=tools/gcc
455 +else
456 +gcc-plugins: ;
457 +endif
458 +else
459 +gcc-plugins:
460 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
461 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
462 +else
463 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
464 +endif
465 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
466 +endif
467 +endif
468 +
469 ifdef CONFIG_READABLE_ASM
470 # Disable optimizations that make assembler listings hard to read.
471 # reorder blocks reorders the control in the function
472 @@ -717,7 +784,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
473 else
474 KBUILD_CFLAGS += -g
475 endif
476 -KBUILD_AFLAGS += -Wa,-gdwarf-2
477 +KBUILD_AFLAGS += -Wa,--gdwarf-2
478 endif
479 ifdef CONFIG_DEBUG_INFO_DWARF4
480 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
481 @@ -867,7 +934,7 @@ export mod_sign_cmd
482
483
484 ifeq ($(KBUILD_EXTMOD),)
485 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
486 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
487
488 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
489 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
490 @@ -916,6 +983,8 @@ endif
491
492 # The actual objects are generated when descending,
493 # make sure no implicit rule kicks in
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
495 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
496 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
497
498 # Handle descending into subdirectories listed in $(vmlinux-dirs)
499 @@ -925,7 +994,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
500 # Error messages still appears in the original language
501
502 PHONY += $(vmlinux-dirs)
503 -$(vmlinux-dirs): prepare scripts
504 +$(vmlinux-dirs): gcc-plugins prepare scripts
505 $(Q)$(MAKE) $(build)=$@
506
507 define filechk_kernel.release
508 @@ -968,10 +1037,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
509
510 archprepare: archheaders archscripts prepare1 scripts_basic
511
512 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 prepare0: archprepare FORCE
515 $(Q)$(MAKE) $(build)=.
516
517 # All the preparing..
518 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
519 prepare: prepare0
520
521 # Generate some files
522 @@ -1086,6 +1158,8 @@ all: modules
523 # using awk while concatenating to the final file.
524
525 PHONY += modules
526 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
527 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
528 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
529 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
530 @$(kecho) ' Building modules, stage 2.';
531 @@ -1101,7 +1175,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
532
533 # Target to prepare building external modules
534 PHONY += modules_prepare
535 -modules_prepare: prepare scripts
536 +modules_prepare: gcc-plugins prepare scripts
537
538 # Target to install modules
539 PHONY += modules_install
540 @@ -1167,7 +1241,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
541 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
542 signing_key.priv signing_key.x509 x509.genkey \
543 extra_certificates signing_key.x509.keyid \
544 - signing_key.x509.signer include/linux/version.h
545 + signing_key.x509.signer include/linux/version.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
547 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
548 + tools/gcc/randomize_layout_seed.h
549
550 # clean - Delete most, but leave enough to build external modules
551 #
552 @@ -1206,7 +1283,7 @@ distclean: mrproper
553 @find $(srctree) $(RCS_FIND_IGNORE) \
554 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
555 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
556 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
557 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
558 -type f -print | xargs rm -f
559
560
561 @@ -1372,6 +1449,8 @@ PHONY += $(module-dirs) modules
562 $(module-dirs): crmodverdir $(objtree)/Module.symvers
563 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
564
565 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
566 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
567 modules: $(module-dirs)
568 @$(kecho) ' Building modules, stage 2.';
569 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
570 @@ -1512,17 +1591,21 @@ else
571 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
572 endif
573
574 -%.s: %.c prepare scripts FORCE
575 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
576 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
577 +%.s: %.c gcc-plugins prepare scripts FORCE
578 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
579 %.i: %.c prepare scripts FORCE
580 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
581 -%.o: %.c prepare scripts FORCE
582 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
583 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
584 +%.o: %.c gcc-plugins prepare scripts FORCE
585 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
586 %.lst: %.c prepare scripts FORCE
587 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
588 -%.s: %.S prepare scripts FORCE
589 +%.s: %.S gcc-plugins prepare scripts FORCE
590 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
591 -%.o: %.S prepare scripts FORCE
592 +%.o: %.S gcc-plugins prepare scripts FORCE
593 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
594 %.symtypes: %.c prepare scripts FORCE
595 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
596 @@ -1532,11 +1615,15 @@ endif
597 $(cmd_crmodverdir)
598 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
599 $(build)=$(build-dir)
600 -%/: prepare scripts FORCE
601 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
602 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
603 +%/: gcc-plugins prepare scripts FORCE
604 $(cmd_crmodverdir)
605 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
606 $(build)=$(build-dir)
607 -%.ko: prepare scripts FORCE
608 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
609 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
610 +%.ko: gcc-plugins prepare scripts FORCE
611 $(cmd_crmodverdir)
612 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
613 $(build)=$(build-dir) $(@:.ko=.o)
614 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
615 index ed60a1e..47f1a55 100644
616 --- a/arch/alpha/include/asm/atomic.h
617 +++ b/arch/alpha/include/asm/atomic.h
618 @@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
619 #define atomic_dec(v) atomic_sub(1,(v))
620 #define atomic64_dec(v) atomic64_sub(1,(v))
621
622 +#define atomic64_read_unchecked(v) atomic64_read(v)
623 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
624 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
625 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
626 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
627 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
628 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
629 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
630 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
631 +
632 #endif /* _ALPHA_ATOMIC_H */
633 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
634 index ad368a9..fbe0f25 100644
635 --- a/arch/alpha/include/asm/cache.h
636 +++ b/arch/alpha/include/asm/cache.h
637 @@ -4,19 +4,19 @@
638 #ifndef __ARCH_ALPHA_CACHE_H
639 #define __ARCH_ALPHA_CACHE_H
640
641 +#include <linux/const.h>
642
643 /* Bytes per L1 (data) cache line. */
644 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
645 -# define L1_CACHE_BYTES 64
646 # define L1_CACHE_SHIFT 6
647 #else
648 /* Both EV4 and EV5 are write-through, read-allocate,
649 direct-mapped, physical.
650 */
651 -# define L1_CACHE_BYTES 32
652 # define L1_CACHE_SHIFT 5
653 #endif
654
655 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
656 #define SMP_CACHE_BYTES L1_CACHE_BYTES
657
658 #endif
659 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
660 index 968d999..d36b2df 100644
661 --- a/arch/alpha/include/asm/elf.h
662 +++ b/arch/alpha/include/asm/elf.h
663 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
664
665 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
666
667 +#ifdef CONFIG_PAX_ASLR
668 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
669 +
670 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
671 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
672 +#endif
673 +
674 /* $0 is set by ld.so to a pointer to a function which might be
675 registered using atexit. This provides a mean for the dynamic
676 linker to call DT_FINI functions for shared libraries that have
677 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
678 index aab14a0..b4fa3e7 100644
679 --- a/arch/alpha/include/asm/pgalloc.h
680 +++ b/arch/alpha/include/asm/pgalloc.h
681 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
682 pgd_set(pgd, pmd);
683 }
684
685 +static inline void
686 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
687 +{
688 + pgd_populate(mm, pgd, pmd);
689 +}
690 +
691 extern pgd_t *pgd_alloc(struct mm_struct *mm);
692
693 static inline void
694 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
695 index d8f9b7e..f6222fa 100644
696 --- a/arch/alpha/include/asm/pgtable.h
697 +++ b/arch/alpha/include/asm/pgtable.h
698 @@ -102,6 +102,17 @@ struct vm_area_struct;
699 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
700 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
702 +
703 +#ifdef CONFIG_PAX_PAGEEXEC
704 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
705 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
707 +#else
708 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
709 +# define PAGE_COPY_NOEXEC PAGE_COPY
710 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
711 +#endif
712 +
713 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
714
715 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
716 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
717 index 2fd00b7..cfd5069 100644
718 --- a/arch/alpha/kernel/module.c
719 +++ b/arch/alpha/kernel/module.c
720 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
721
722 /* The small sections were sorted to the end of the segment.
723 The following should definitely cover them. */
724 - gp = (u64)me->module_core + me->core_size - 0x8000;
725 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
726 got = sechdrs[me->arch.gotsecindex].sh_addr;
727
728 for (i = 0; i < n; i++) {
729 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
730 index 1402fcc..0b1abd2 100644
731 --- a/arch/alpha/kernel/osf_sys.c
732 +++ b/arch/alpha/kernel/osf_sys.c
733 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
734 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
735
736 static unsigned long
737 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
738 - unsigned long limit)
739 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
740 + unsigned long limit, unsigned long flags)
741 {
742 struct vm_unmapped_area_info info;
743 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
744
745 info.flags = 0;
746 info.length = len;
747 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
748 info.high_limit = limit;
749 info.align_mask = 0;
750 info.align_offset = 0;
751 + info.threadstack_offset = offset;
752 return vm_unmapped_area(&info);
753 }
754
755 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
756 merely specific addresses, but regions of memory -- perhaps
757 this feature should be incorporated into all ports? */
758
759 +#ifdef CONFIG_PAX_RANDMMAP
760 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
761 +#endif
762 +
763 if (addr) {
764 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
765 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
766 if (addr != (unsigned long) -ENOMEM)
767 return addr;
768 }
769
770 /* Next, try allocating at TASK_UNMAPPED_BASE. */
771 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
772 - len, limit);
773 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
774 +
775 if (addr != (unsigned long) -ENOMEM)
776 return addr;
777
778 /* Finally, try allocating in low memory. */
779 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
780 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
781
782 return addr;
783 }
784 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
785 index 98838a0..b304fb4 100644
786 --- a/arch/alpha/mm/fault.c
787 +++ b/arch/alpha/mm/fault.c
788 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
789 __reload_thread(pcb);
790 }
791
792 +#ifdef CONFIG_PAX_PAGEEXEC
793 +/*
794 + * PaX: decide what to do with offenders (regs->pc = fault address)
795 + *
796 + * returns 1 when task should be killed
797 + * 2 when patched PLT trampoline was detected
798 + * 3 when unpatched PLT trampoline was detected
799 + */
800 +static int pax_handle_fetch_fault(struct pt_regs *regs)
801 +{
802 +
803 +#ifdef CONFIG_PAX_EMUPLT
804 + int err;
805 +
806 + do { /* PaX: patched PLT emulation #1 */
807 + unsigned int ldah, ldq, jmp;
808 +
809 + err = get_user(ldah, (unsigned int *)regs->pc);
810 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
811 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
812 +
813 + if (err)
814 + break;
815 +
816 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
817 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
818 + jmp == 0x6BFB0000U)
819 + {
820 + unsigned long r27, addr;
821 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
822 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
823 +
824 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
825 + err = get_user(r27, (unsigned long *)addr);
826 + if (err)
827 + break;
828 +
829 + regs->r27 = r27;
830 + regs->pc = r27;
831 + return 2;
832 + }
833 + } while (0);
834 +
835 + do { /* PaX: patched PLT emulation #2 */
836 + unsigned int ldah, lda, br;
837 +
838 + err = get_user(ldah, (unsigned int *)regs->pc);
839 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
840 + err |= get_user(br, (unsigned int *)(regs->pc+8));
841 +
842 + if (err)
843 + break;
844 +
845 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
846 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
847 + (br & 0xFFE00000U) == 0xC3E00000U)
848 + {
849 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
850 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
851 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
852 +
853 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
854 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
855 + return 2;
856 + }
857 + } while (0);
858 +
859 + do { /* PaX: unpatched PLT emulation */
860 + unsigned int br;
861 +
862 + err = get_user(br, (unsigned int *)regs->pc);
863 +
864 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
865 + unsigned int br2, ldq, nop, jmp;
866 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
867 +
868 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
869 + err = get_user(br2, (unsigned int *)addr);
870 + err |= get_user(ldq, (unsigned int *)(addr+4));
871 + err |= get_user(nop, (unsigned int *)(addr+8));
872 + err |= get_user(jmp, (unsigned int *)(addr+12));
873 + err |= get_user(resolver, (unsigned long *)(addr+16));
874 +
875 + if (err)
876 + break;
877 +
878 + if (br2 == 0xC3600000U &&
879 + ldq == 0xA77B000CU &&
880 + nop == 0x47FF041FU &&
881 + jmp == 0x6B7B0000U)
882 + {
883 + regs->r28 = regs->pc+4;
884 + regs->r27 = addr+16;
885 + regs->pc = resolver;
886 + return 3;
887 + }
888 + }
889 + } while (0);
890 +#endif
891 +
892 + return 1;
893 +}
894 +
895 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
896 +{
897 + unsigned long i;
898 +
899 + printk(KERN_ERR "PAX: bytes at PC: ");
900 + for (i = 0; i < 5; i++) {
901 + unsigned int c;
902 + if (get_user(c, (unsigned int *)pc+i))
903 + printk(KERN_CONT "???????? ");
904 + else
905 + printk(KERN_CONT "%08x ", c);
906 + }
907 + printk("\n");
908 +}
909 +#endif
910
911 /*
912 * This routine handles page faults. It determines the address,
913 @@ -133,8 +251,29 @@ retry:
914 good_area:
915 si_code = SEGV_ACCERR;
916 if (cause < 0) {
917 - if (!(vma->vm_flags & VM_EXEC))
918 + if (!(vma->vm_flags & VM_EXEC)) {
919 +
920 +#ifdef CONFIG_PAX_PAGEEXEC
921 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
922 + goto bad_area;
923 +
924 + up_read(&mm->mmap_sem);
925 + switch (pax_handle_fetch_fault(regs)) {
926 +
927 +#ifdef CONFIG_PAX_EMUPLT
928 + case 2:
929 + case 3:
930 + return;
931 +#endif
932 +
933 + }
934 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
935 + do_group_exit(SIGKILL);
936 +#else
937 goto bad_area;
938 +#endif
939 +
940 + }
941 } else if (!cause) {
942 /* Allow reads even for write-only mappings */
943 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
944 diff --git a/arch/arc/kernel/kgdb.c b/arch/arc/kernel/kgdb.c
945 index a2ff5c5..ecf6a78 100644
946 --- a/arch/arc/kernel/kgdb.c
947 +++ b/arch/arc/kernel/kgdb.c
948 @@ -158,11 +158,6 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
949 return -1;
950 }
951
952 -unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
953 -{
954 - return instruction_pointer(regs);
955 -}
956 -
957 int kgdb_arch_init(void)
958 {
959 single_step_data.armed = 0;
960 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
961 index 32cbbd5..c102df9 100644
962 --- a/arch/arm/Kconfig
963 +++ b/arch/arm/Kconfig
964 @@ -1719,7 +1719,7 @@ config ALIGNMENT_TRAP
965
966 config UACCESS_WITH_MEMCPY
967 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
968 - depends on MMU
969 + depends on MMU && !PAX_MEMORY_UDEREF
970 default y if CPU_FEROCEON
971 help
972 Implement faster copy_to_user and clear_user methods for CPU
973 @@ -1983,6 +1983,7 @@ config XIP_PHYS_ADDR
974 config KEXEC
975 bool "Kexec system call (EXPERIMENTAL)"
976 depends on (!SMP || PM_SLEEP_SMP)
977 + depends on !GRKERNSEC_KMEM
978 help
979 kexec is a system call that implements the ability to shutdown your
980 current kernel, and to start another kernel. It is like a reboot
981 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
982 index 3040359..a494fa3 100644
983 --- a/arch/arm/include/asm/atomic.h
984 +++ b/arch/arm/include/asm/atomic.h
985 @@ -18,17 +18,41 @@
986 #include <asm/barrier.h>
987 #include <asm/cmpxchg.h>
988
989 +#ifdef CONFIG_GENERIC_ATOMIC64
990 +#include <asm-generic/atomic64.h>
991 +#endif
992 +
993 #define ATOMIC_INIT(i) { (i) }
994
995 #ifdef __KERNEL__
996
997 +#ifdef CONFIG_THUMB2_KERNEL
998 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
999 +#else
1000 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
1001 +#endif
1002 +
1003 +#define _ASM_EXTABLE(from, to) \
1004 +" .pushsection __ex_table,\"a\"\n"\
1005 +" .align 3\n" \
1006 +" .long " #from ", " #to"\n" \
1007 +" .popsection"
1008 +
1009 /*
1010 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1011 * strex/ldrex monitor on some implementations. The reason we can use it for
1012 * atomic_set() is the clrex or dummy strex done on every exception return.
1013 */
1014 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1015 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1016 +{
1017 + return v->counter;
1018 +}
1019 #define atomic_set(v,i) (((v)->counter) = (i))
1020 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1021 +{
1022 + v->counter = i;
1023 +}
1024
1025 #if __LINUX_ARM_ARCH__ >= 6
1026
1027 @@ -44,6 +68,36 @@ static inline void atomic_add(int i, atomic_t *v)
1028
1029 prefetchw(&v->counter);
1030 __asm__ __volatile__("@ atomic_add\n"
1031 +"1: ldrex %1, [%3]\n"
1032 +" adds %0, %1, %4\n"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +" bvc 3f\n"
1036 +"2: " REFCOUNT_TRAP_INSN "\n"
1037 +"3:\n"
1038 +#endif
1039 +
1040 +" strex %1, %0, [%3]\n"
1041 +" teq %1, #0\n"
1042 +" bne 1b"
1043 +
1044 +#ifdef CONFIG_PAX_REFCOUNT
1045 +"\n4:\n"
1046 + _ASM_EXTABLE(2b, 4b)
1047 +#endif
1048 +
1049 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1050 + : "r" (&v->counter), "Ir" (i)
1051 + : "cc");
1052 +}
1053 +
1054 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1055 +{
1056 + unsigned long tmp;
1057 + int result;
1058 +
1059 + prefetchw(&v->counter);
1060 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1061 "1: ldrex %0, [%3]\n"
1062 " add %0, %0, %4\n"
1063 " strex %1, %0, [%3]\n"
1064 @@ -63,6 +117,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065 prefetchw(&v->counter);
1066
1067 __asm__ __volatile__("@ atomic_add_return\n"
1068 +"1: ldrex %1, [%3]\n"
1069 +" adds %0, %1, %4\n"
1070 +
1071 +#ifdef CONFIG_PAX_REFCOUNT
1072 +" bvc 3f\n"
1073 +" mov %0, %1\n"
1074 +"2: " REFCOUNT_TRAP_INSN "\n"
1075 +"3:\n"
1076 +#endif
1077 +
1078 +" strex %1, %0, [%3]\n"
1079 +" teq %1, #0\n"
1080 +" bne 1b"
1081 +
1082 +#ifdef CONFIG_PAX_REFCOUNT
1083 +"\n4:\n"
1084 + _ASM_EXTABLE(2b, 4b)
1085 +#endif
1086 +
1087 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1088 + : "r" (&v->counter), "Ir" (i)
1089 + : "cc");
1090 +
1091 + smp_mb();
1092 +
1093 + return result;
1094 +}
1095 +
1096 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1097 +{
1098 + unsigned long tmp;
1099 + int result;
1100 +
1101 + smp_mb();
1102 + prefetchw(&v->counter);
1103 +
1104 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1105 "1: ldrex %0, [%3]\n"
1106 " add %0, %0, %4\n"
1107 " strex %1, %0, [%3]\n"
1108 @@ -84,6 +175,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1109
1110 prefetchw(&v->counter);
1111 __asm__ __volatile__("@ atomic_sub\n"
1112 +"1: ldrex %1, [%3]\n"
1113 +" subs %0, %1, %4\n"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 +" bvc 3f\n"
1117 +"2: " REFCOUNT_TRAP_INSN "\n"
1118 +"3:\n"
1119 +#endif
1120 +
1121 +" strex %1, %0, [%3]\n"
1122 +" teq %1, #0\n"
1123 +" bne 1b"
1124 +
1125 +#ifdef CONFIG_PAX_REFCOUNT
1126 +"\n4:\n"
1127 + _ASM_EXTABLE(2b, 4b)
1128 +#endif
1129 +
1130 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1131 + : "r" (&v->counter), "Ir" (i)
1132 + : "cc");
1133 +}
1134 +
1135 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1136 +{
1137 + unsigned long tmp;
1138 + int result;
1139 +
1140 + prefetchw(&v->counter);
1141 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1142 "1: ldrex %0, [%3]\n"
1143 " sub %0, %0, %4\n"
1144 " strex %1, %0, [%3]\n"
1145 @@ -103,11 +224,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1146 prefetchw(&v->counter);
1147
1148 __asm__ __volatile__("@ atomic_sub_return\n"
1149 -"1: ldrex %0, [%3]\n"
1150 -" sub %0, %0, %4\n"
1151 +"1: ldrex %1, [%3]\n"
1152 +" subs %0, %1, %4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +" mov %0, %1\n"
1157 +"2: " REFCOUNT_TRAP_INSN "\n"
1158 +"3:\n"
1159 +#endif
1160 +
1161 " strex %1, %0, [%3]\n"
1162 " teq %1, #0\n"
1163 " bne 1b"
1164 +
1165 +#ifdef CONFIG_PAX_REFCOUNT
1166 +"\n4:\n"
1167 + _ASM_EXTABLE(2b, 4b)
1168 +#endif
1169 +
1170 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1171 : "r" (&v->counter), "Ir" (i)
1172 : "cc");
1173 @@ -152,12 +287,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1174 __asm__ __volatile__ ("@ atomic_add_unless\n"
1175 "1: ldrex %0, [%4]\n"
1176 " teq %0, %5\n"
1177 -" beq 2f\n"
1178 -" add %1, %0, %6\n"
1179 +" beq 4f\n"
1180 +" adds %1, %0, %6\n"
1181 +
1182 +#ifdef CONFIG_PAX_REFCOUNT
1183 +" bvc 3f\n"
1184 +"2: " REFCOUNT_TRAP_INSN "\n"
1185 +"3:\n"
1186 +#endif
1187 +
1188 " strex %2, %1, [%4]\n"
1189 " teq %2, #0\n"
1190 " bne 1b\n"
1191 -"2:"
1192 +"4:"
1193 +
1194 +#ifdef CONFIG_PAX_REFCOUNT
1195 + _ASM_EXTABLE(2b, 4b)
1196 +#endif
1197 +
1198 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1199 : "r" (&v->counter), "r" (u), "r" (a)
1200 : "cc");
1201 @@ -168,6 +315,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1202 return oldval;
1203 }
1204
1205 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1206 +{
1207 + unsigned long oldval, res;
1208 +
1209 + smp_mb();
1210 +
1211 + do {
1212 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1213 + "ldrex %1, [%3]\n"
1214 + "mov %0, #0\n"
1215 + "teq %1, %4\n"
1216 + "strexeq %0, %5, [%3]\n"
1217 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1218 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1219 + : "cc");
1220 + } while (res);
1221 +
1222 + smp_mb();
1223 +
1224 + return oldval;
1225 +}
1226 +
1227 #else /* ARM_ARCH_6 */
1228
1229 #ifdef CONFIG_SMP
1230 @@ -186,7 +355,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1231
1232 return val;
1233 }
1234 +
1235 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1236 +{
1237 + return atomic_add_return(i, v);
1238 +}
1239 +
1240 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1241 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1242 +{
1243 + (void) atomic_add_return(i, v);
1244 +}
1245
1246 static inline int atomic_sub_return(int i, atomic_t *v)
1247 {
1248 @@ -201,6 +380,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1249 return val;
1250 }
1251 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1252 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1253 +{
1254 + (void) atomic_sub_return(i, v);
1255 +}
1256
1257 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1258 {
1259 @@ -216,6 +399,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1260 return ret;
1261 }
1262
1263 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1264 +{
1265 + return atomic_cmpxchg(v, old, new);
1266 +}
1267 +
1268 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1269 {
1270 int c, old;
1271 @@ -229,13 +417,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1272 #endif /* __LINUX_ARM_ARCH__ */
1273
1274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1275 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1276 +{
1277 + return xchg(&v->counter, new);
1278 +}
1279
1280 #define atomic_inc(v) atomic_add(1, v)
1281 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1282 +{
1283 + atomic_add_unchecked(1, v);
1284 +}
1285 #define atomic_dec(v) atomic_sub(1, v)
1286 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1287 +{
1288 + atomic_sub_unchecked(1, v);
1289 +}
1290
1291 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1292 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1293 +{
1294 + return atomic_add_return_unchecked(1, v) == 0;
1295 +}
1296 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1297 #define atomic_inc_return(v) (atomic_add_return(1, v))
1298 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1299 +{
1300 + return atomic_add_return_unchecked(1, v);
1301 +}
1302 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1303 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1304
1305 @@ -246,6 +454,14 @@ typedef struct {
1306 long long counter;
1307 } atomic64_t;
1308
1309 +#ifdef CONFIG_PAX_REFCOUNT
1310 +typedef struct {
1311 + long long counter;
1312 +} atomic64_unchecked_t;
1313 +#else
1314 +typedef atomic64_t atomic64_unchecked_t;
1315 +#endif
1316 +
1317 #define ATOMIC64_INIT(i) { (i) }
1318
1319 #ifdef CONFIG_ARM_LPAE
1320 @@ -262,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1321 return result;
1322 }
1323
1324 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1325 +{
1326 + long long result;
1327 +
1328 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1329 +" ldrd %0, %H0, [%1]"
1330 + : "=&r" (result)
1331 + : "r" (&v->counter), "Qo" (v->counter)
1332 + );
1333 +
1334 + return result;
1335 +}
1336 +
1337 static inline void atomic64_set(atomic64_t *v, long long i)
1338 {
1339 __asm__ __volatile__("@ atomic64_set\n"
1340 @@ -270,6 +499,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1341 : "r" (&v->counter), "r" (i)
1342 );
1343 }
1344 +
1345 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1346 +{
1347 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1348 +" strd %2, %H2, [%1]"
1349 + : "=Qo" (v->counter)
1350 + : "r" (&v->counter), "r" (i)
1351 + );
1352 +}
1353 #else
1354 static inline long long atomic64_read(const atomic64_t *v)
1355 {
1356 @@ -284,6 +522,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1357 return result;
1358 }
1359
1360 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1361 +{
1362 + long long result;
1363 +
1364 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1365 +" ldrexd %0, %H0, [%1]"
1366 + : "=&r" (result)
1367 + : "r" (&v->counter), "Qo" (v->counter)
1368 + );
1369 +
1370 + return result;
1371 +}
1372 +
1373 static inline void atomic64_set(atomic64_t *v, long long i)
1374 {
1375 long long tmp;
1376 @@ -298,6 +549,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1377 : "r" (&v->counter), "r" (i)
1378 : "cc");
1379 }
1380 +
1381 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1382 +{
1383 + long long tmp;
1384 +
1385 + prefetchw(&v->counter);
1386 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1387 +"1: ldrexd %0, %H0, [%2]\n"
1388 +" strexd %0, %3, %H3, [%2]\n"
1389 +" teq %0, #0\n"
1390 +" bne 1b"
1391 + : "=&r" (tmp), "=Qo" (v->counter)
1392 + : "r" (&v->counter), "r" (i)
1393 + : "cc");
1394 +}
1395 #endif
1396
1397 static inline void atomic64_add(long long i, atomic64_t *v)
1398 @@ -309,6 +575,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1399 __asm__ __volatile__("@ atomic64_add\n"
1400 "1: ldrexd %0, %H0, [%3]\n"
1401 " adds %Q0, %Q0, %Q4\n"
1402 +" adcs %R0, %R0, %R4\n"
1403 +
1404 +#ifdef CONFIG_PAX_REFCOUNT
1405 +" bvc 3f\n"
1406 +"2: " REFCOUNT_TRAP_INSN "\n"
1407 +"3:\n"
1408 +#endif
1409 +
1410 +" strexd %1, %0, %H0, [%3]\n"
1411 +" teq %1, #0\n"
1412 +" bne 1b"
1413 +
1414 +#ifdef CONFIG_PAX_REFCOUNT
1415 +"\n4:\n"
1416 + _ASM_EXTABLE(2b, 4b)
1417 +#endif
1418 +
1419 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1420 + : "r" (&v->counter), "r" (i)
1421 + : "cc");
1422 +}
1423 +
1424 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1425 +{
1426 + long long result;
1427 + unsigned long tmp;
1428 +
1429 + prefetchw(&v->counter);
1430 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1431 +"1: ldrexd %0, %H0, [%3]\n"
1432 +" adds %Q0, %Q0, %Q4\n"
1433 " adc %R0, %R0, %R4\n"
1434 " strexd %1, %0, %H0, [%3]\n"
1435 " teq %1, #0\n"
1436 @@ -329,6 +626,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1437 __asm__ __volatile__("@ atomic64_add_return\n"
1438 "1: ldrexd %0, %H0, [%3]\n"
1439 " adds %Q0, %Q0, %Q4\n"
1440 +" adcs %R0, %R0, %R4\n"
1441 +
1442 +#ifdef CONFIG_PAX_REFCOUNT
1443 +" bvc 3f\n"
1444 +" mov %0, %1\n"
1445 +" mov %H0, %H1\n"
1446 +"2: " REFCOUNT_TRAP_INSN "\n"
1447 +"3:\n"
1448 +#endif
1449 +
1450 +" strexd %1, %0, %H0, [%3]\n"
1451 +" teq %1, #0\n"
1452 +" bne 1b"
1453 +
1454 +#ifdef CONFIG_PAX_REFCOUNT
1455 +"\n4:\n"
1456 + _ASM_EXTABLE(2b, 4b)
1457 +#endif
1458 +
1459 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1460 + : "r" (&v->counter), "r" (i)
1461 + : "cc");
1462 +
1463 + smp_mb();
1464 +
1465 + return result;
1466 +}
1467 +
1468 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1469 +{
1470 + long long result;
1471 + unsigned long tmp;
1472 +
1473 + smp_mb();
1474 +
1475 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1476 +"1: ldrexd %0, %H0, [%3]\n"
1477 +" adds %Q0, %Q0, %Q4\n"
1478 " adc %R0, %R0, %R4\n"
1479 " strexd %1, %0, %H0, [%3]\n"
1480 " teq %1, #0\n"
1481 @@ -351,6 +686,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1482 __asm__ __volatile__("@ atomic64_sub\n"
1483 "1: ldrexd %0, %H0, [%3]\n"
1484 " subs %Q0, %Q0, %Q4\n"
1485 +" sbcs %R0, %R0, %R4\n"
1486 +
1487 +#ifdef CONFIG_PAX_REFCOUNT
1488 +" bvc 3f\n"
1489 +"2: " REFCOUNT_TRAP_INSN "\n"
1490 +"3:\n"
1491 +#endif
1492 +
1493 +" strexd %1, %0, %H0, [%3]\n"
1494 +" teq %1, #0\n"
1495 +" bne 1b"
1496 +
1497 +#ifdef CONFIG_PAX_REFCOUNT
1498 +"\n4:\n"
1499 + _ASM_EXTABLE(2b, 4b)
1500 +#endif
1501 +
1502 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1503 + : "r" (&v->counter), "r" (i)
1504 + : "cc");
1505 +}
1506 +
1507 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1508 +{
1509 + long long result;
1510 + unsigned long tmp;
1511 +
1512 + prefetchw(&v->counter);
1513 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1514 +"1: ldrexd %0, %H0, [%3]\n"
1515 +" subs %Q0, %Q0, %Q4\n"
1516 " sbc %R0, %R0, %R4\n"
1517 " strexd %1, %0, %H0, [%3]\n"
1518 " teq %1, #0\n"
1519 @@ -371,10 +737,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1520 __asm__ __volatile__("@ atomic64_sub_return\n"
1521 "1: ldrexd %0, %H0, [%3]\n"
1522 " subs %Q0, %Q0, %Q4\n"
1523 -" sbc %R0, %R0, %R4\n"
1524 +" sbcs %R0, %R0, %R4\n"
1525 +
1526 +#ifdef CONFIG_PAX_REFCOUNT
1527 +" bvc 3f\n"
1528 +" mov %0, %1\n"
1529 +" mov %H0, %H1\n"
1530 +"2: " REFCOUNT_TRAP_INSN "\n"
1531 +"3:\n"
1532 +#endif
1533 +
1534 " strexd %1, %0, %H0, [%3]\n"
1535 " teq %1, #0\n"
1536 " bne 1b"
1537 +
1538 +#ifdef CONFIG_PAX_REFCOUNT
1539 +"\n4:\n"
1540 + _ASM_EXTABLE(2b, 4b)
1541 +#endif
1542 +
1543 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (i)
1545 : "cc");
1546 @@ -410,6 +791,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1547 return oldval;
1548 }
1549
1550 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1551 + long long new)
1552 +{
1553 + long long oldval;
1554 + unsigned long res;
1555 +
1556 + smp_mb();
1557 +
1558 + do {
1559 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1560 + "ldrexd %1, %H1, [%3]\n"
1561 + "mov %0, #0\n"
1562 + "teq %1, %4\n"
1563 + "teqeq %H1, %H4\n"
1564 + "strexdeq %0, %5, %H5, [%3]"
1565 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1566 + : "r" (&ptr->counter), "r" (old), "r" (new)
1567 + : "cc");
1568 + } while (res);
1569 +
1570 + smp_mb();
1571 +
1572 + return oldval;
1573 +}
1574 +
1575 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1576 {
1577 long long result;
1578 @@ -435,21 +841,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1579 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1580 {
1581 long long result;
1582 - unsigned long tmp;
1583 + u64 tmp;
1584
1585 smp_mb();
1586 prefetchw(&v->counter);
1587
1588 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1589 -"1: ldrexd %0, %H0, [%3]\n"
1590 -" subs %Q0, %Q0, #1\n"
1591 -" sbc %R0, %R0, #0\n"
1592 +"1: ldrexd %1, %H1, [%3]\n"
1593 +" subs %Q0, %Q1, #1\n"
1594 +" sbcs %R0, %R1, #0\n"
1595 +
1596 +#ifdef CONFIG_PAX_REFCOUNT
1597 +" bvc 3f\n"
1598 +" mov %Q0, %Q1\n"
1599 +" mov %R0, %R1\n"
1600 +"2: " REFCOUNT_TRAP_INSN "\n"
1601 +"3:\n"
1602 +#endif
1603 +
1604 " teq %R0, #0\n"
1605 -" bmi 2f\n"
1606 +" bmi 4f\n"
1607 " strexd %1, %0, %H0, [%3]\n"
1608 " teq %1, #0\n"
1609 " bne 1b\n"
1610 -"2:"
1611 +"4:\n"
1612 +
1613 +#ifdef CONFIG_PAX_REFCOUNT
1614 + _ASM_EXTABLE(2b, 4b)
1615 +#endif
1616 +
1617 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1618 : "r" (&v->counter)
1619 : "cc");
1620 @@ -473,13 +893,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1621 " teq %0, %5\n"
1622 " teqeq %H0, %H5\n"
1623 " moveq %1, #0\n"
1624 -" beq 2f\n"
1625 +" beq 4f\n"
1626 " adds %Q0, %Q0, %Q6\n"
1627 -" adc %R0, %R0, %R6\n"
1628 +" adcs %R0, %R0, %R6\n"
1629 +
1630 +#ifdef CONFIG_PAX_REFCOUNT
1631 +" bvc 3f\n"
1632 +"2: " REFCOUNT_TRAP_INSN "\n"
1633 +"3:\n"
1634 +#endif
1635 +
1636 " strexd %2, %0, %H0, [%4]\n"
1637 " teq %2, #0\n"
1638 " bne 1b\n"
1639 -"2:"
1640 +"4:\n"
1641 +
1642 +#ifdef CONFIG_PAX_REFCOUNT
1643 + _ASM_EXTABLE(2b, 4b)
1644 +#endif
1645 +
1646 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1647 : "r" (&v->counter), "r" (u), "r" (a)
1648 : "cc");
1649 @@ -492,10 +924,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1650
1651 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1652 #define atomic64_inc(v) atomic64_add(1LL, (v))
1653 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1654 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1655 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1656 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1657 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1658 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1659 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1660 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1661 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1663 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1664 index c6a3e73..35cca85 100644
1665 --- a/arch/arm/include/asm/barrier.h
1666 +++ b/arch/arm/include/asm/barrier.h
1667 @@ -63,7 +63,7 @@
1668 do { \
1669 compiletime_assert_atomic_type(*p); \
1670 smp_mb(); \
1671 - ACCESS_ONCE(*p) = (v); \
1672 + ACCESS_ONCE_RW(*p) = (v); \
1673 } while (0)
1674
1675 #define smp_load_acquire(p) \
1676 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1677 index 75fe66b..ba3dee4 100644
1678 --- a/arch/arm/include/asm/cache.h
1679 +++ b/arch/arm/include/asm/cache.h
1680 @@ -4,8 +4,10 @@
1681 #ifndef __ASMARM_CACHE_H
1682 #define __ASMARM_CACHE_H
1683
1684 +#include <linux/const.h>
1685 +
1686 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1689
1690 /*
1691 * Memory returned by kmalloc() may be used for DMA, so we must make
1692 @@ -24,5 +26,6 @@
1693 #endif
1694
1695 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1696 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1697
1698 #endif
1699 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1700 index 10e78d0..dc8505d 100644
1701 --- a/arch/arm/include/asm/cacheflush.h
1702 +++ b/arch/arm/include/asm/cacheflush.h
1703 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1704 void (*dma_unmap_area)(const void *, size_t, int);
1705
1706 void (*dma_flush_range)(const void *, const void *);
1707 -};
1708 +} __no_const;
1709
1710 /*
1711 * Select the calling method
1712 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1713 index 5233151..87a71fa 100644
1714 --- a/arch/arm/include/asm/checksum.h
1715 +++ b/arch/arm/include/asm/checksum.h
1716 @@ -37,7 +37,19 @@ __wsum
1717 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1718
1719 __wsum
1720 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1721 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1722 +
1723 +static inline __wsum
1724 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1725 +{
1726 + __wsum ret;
1727 + pax_open_userland();
1728 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1729 + pax_close_userland();
1730 + return ret;
1731 +}
1732 +
1733 +
1734
1735 /*
1736 * Fold a partial checksum without adding pseudo headers
1737 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1738 index abb2c37..96db950 100644
1739 --- a/arch/arm/include/asm/cmpxchg.h
1740 +++ b/arch/arm/include/asm/cmpxchg.h
1741 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1742
1743 #define xchg(ptr,x) \
1744 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1745 +#define xchg_unchecked(ptr,x) \
1746 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1747
1748 #include <asm-generic/cmpxchg-local.h>
1749
1750 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1751 index 6ddbe44..b5e38b1 100644
1752 --- a/arch/arm/include/asm/domain.h
1753 +++ b/arch/arm/include/asm/domain.h
1754 @@ -48,18 +48,37 @@
1755 * Domain types
1756 */
1757 #define DOMAIN_NOACCESS 0
1758 -#define DOMAIN_CLIENT 1
1759 #ifdef CONFIG_CPU_USE_DOMAINS
1760 +#define DOMAIN_USERCLIENT 1
1761 +#define DOMAIN_KERNELCLIENT 1
1762 #define DOMAIN_MANAGER 3
1763 +#define DOMAIN_VECTORS DOMAIN_USER
1764 #else
1765 +
1766 +#ifdef CONFIG_PAX_KERNEXEC
1767 #define DOMAIN_MANAGER 1
1768 +#define DOMAIN_KERNEXEC 3
1769 +#else
1770 +#define DOMAIN_MANAGER 1
1771 +#endif
1772 +
1773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1774 +#define DOMAIN_USERCLIENT 0
1775 +#define DOMAIN_UDEREF 1
1776 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1777 +#else
1778 +#define DOMAIN_USERCLIENT 1
1779 +#define DOMAIN_VECTORS DOMAIN_USER
1780 +#endif
1781 +#define DOMAIN_KERNELCLIENT 1
1782 +
1783 #endif
1784
1785 #define domain_val(dom,type) ((type) << (2*(dom)))
1786
1787 #ifndef __ASSEMBLY__
1788
1789 -#ifdef CONFIG_CPU_USE_DOMAINS
1790 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1791 static inline void set_domain(unsigned val)
1792 {
1793 asm volatile(
1794 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1795 isb();
1796 }
1797
1798 -#define modify_domain(dom,type) \
1799 - do { \
1800 - struct thread_info *thread = current_thread_info(); \
1801 - unsigned int domain = thread->cpu_domain; \
1802 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1803 - thread->cpu_domain = domain | domain_val(dom, type); \
1804 - set_domain(thread->cpu_domain); \
1805 - } while (0)
1806 -
1807 +extern void modify_domain(unsigned int dom, unsigned int type);
1808 #else
1809 static inline void set_domain(unsigned val) { }
1810 static inline void modify_domain(unsigned dom, unsigned type) { }
1811 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1812 index afb9caf..9a0bac0 100644
1813 --- a/arch/arm/include/asm/elf.h
1814 +++ b/arch/arm/include/asm/elf.h
1815 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1816 the loader. We need to make sure that it is out of the way of the program
1817 that it will "exec", and that there is sufficient room for the brk. */
1818
1819 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1820 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1821 +
1822 +#ifdef CONFIG_PAX_ASLR
1823 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1824 +
1825 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1826 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1827 +#endif
1828
1829 /* When the program starts, a1 contains a pointer to a function to be
1830 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1831 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1832 extern void elf_set_personality(const struct elf32_hdr *);
1833 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1834
1835 -struct mm_struct;
1836 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1837 -#define arch_randomize_brk arch_randomize_brk
1838 -
1839 #ifdef CONFIG_MMU
1840 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1841 struct linux_binprm;
1842 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1843 index de53547..52b9a28 100644
1844 --- a/arch/arm/include/asm/fncpy.h
1845 +++ b/arch/arm/include/asm/fncpy.h
1846 @@ -81,7 +81,9 @@
1847 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1848 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1849 \
1850 + pax_open_kernel(); \
1851 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1852 + pax_close_kernel(); \
1853 flush_icache_range((unsigned long)(dest_buf), \
1854 (unsigned long)(dest_buf) + (size)); \
1855 \
1856 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1857 index 53e69da..3fdc896 100644
1858 --- a/arch/arm/include/asm/futex.h
1859 +++ b/arch/arm/include/asm/futex.h
1860 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1861 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1862 return -EFAULT;
1863
1864 + pax_open_userland();
1865 +
1866 smp_mb();
1867 /* Prefetching cannot fault */
1868 prefetchw(uaddr);
1869 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1870 : "cc", "memory");
1871 smp_mb();
1872
1873 + pax_close_userland();
1874 +
1875 *uval = val;
1876 return ret;
1877 }
1878 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1879 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1880 return -EFAULT;
1881
1882 + pax_open_userland();
1883 +
1884 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1885 "1: " TUSER(ldr) " %1, [%4]\n"
1886 " teq %1, %2\n"
1887 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1888 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1889 : "cc", "memory");
1890
1891 + pax_close_userland();
1892 +
1893 *uval = val;
1894 return ret;
1895 }
1896 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1897 return -EFAULT;
1898
1899 pagefault_disable(); /* implies preempt_disable() */
1900 + pax_open_userland();
1901
1902 switch (op) {
1903 case FUTEX_OP_SET:
1904 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1905 ret = -ENOSYS;
1906 }
1907
1908 + pax_close_userland();
1909 pagefault_enable(); /* subsumes preempt_enable() */
1910
1911 if (!ret) {
1912 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1913 index 83eb2f7..ed77159 100644
1914 --- a/arch/arm/include/asm/kmap_types.h
1915 +++ b/arch/arm/include/asm/kmap_types.h
1916 @@ -4,6 +4,6 @@
1917 /*
1918 * This is the "bare minimum". AIO seems to require this.
1919 */
1920 -#define KM_TYPE_NR 16
1921 +#define KM_TYPE_NR 17
1922
1923 #endif
1924 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1925 index 9e614a1..3302cca 100644
1926 --- a/arch/arm/include/asm/mach/dma.h
1927 +++ b/arch/arm/include/asm/mach/dma.h
1928 @@ -22,7 +22,7 @@ struct dma_ops {
1929 int (*residue)(unsigned int, dma_t *); /* optional */
1930 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1931 const char *type;
1932 -};
1933 +} __do_const;
1934
1935 struct dma_struct {
1936 void *addr; /* single DMA address */
1937 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1938 index f98c7f3..e5c626d 100644
1939 --- a/arch/arm/include/asm/mach/map.h
1940 +++ b/arch/arm/include/asm/mach/map.h
1941 @@ -23,17 +23,19 @@ struct map_desc {
1942
1943 /* types 0-3 are defined in asm/io.h */
1944 enum {
1945 - MT_UNCACHED = 4,
1946 - MT_CACHECLEAN,
1947 - MT_MINICLEAN,
1948 + MT_UNCACHED_RW = 4,
1949 + MT_CACHECLEAN_RO,
1950 + MT_MINICLEAN_RO,
1951 MT_LOW_VECTORS,
1952 MT_HIGH_VECTORS,
1953 - MT_MEMORY_RWX,
1954 + __MT_MEMORY_RWX,
1955 MT_MEMORY_RW,
1956 - MT_ROM,
1957 - MT_MEMORY_RWX_NONCACHED,
1958 + MT_MEMORY_RX,
1959 + MT_ROM_RX,
1960 + MT_MEMORY_RW_NONCACHED,
1961 + MT_MEMORY_RX_NONCACHED,
1962 MT_MEMORY_RW_DTCM,
1963 - MT_MEMORY_RWX_ITCM,
1964 + MT_MEMORY_RX_ITCM,
1965 MT_MEMORY_RW_SO,
1966 MT_MEMORY_DMA_READY,
1967 };
1968 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1969 index 891a56b..48f337e 100644
1970 --- a/arch/arm/include/asm/outercache.h
1971 +++ b/arch/arm/include/asm/outercache.h
1972 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1973
1974 /* This is an ARM L2C thing */
1975 void (*write_sec)(unsigned long, unsigned);
1976 -};
1977 +} __no_const;
1978
1979 extern struct outer_cache_fns outer_cache;
1980
1981 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1982 index 4355f0e..cd9168e 100644
1983 --- a/arch/arm/include/asm/page.h
1984 +++ b/arch/arm/include/asm/page.h
1985 @@ -23,6 +23,7 @@
1986
1987 #else
1988
1989 +#include <linux/compiler.h>
1990 #include <asm/glue.h>
1991
1992 /*
1993 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1994 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1995 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1996 unsigned long vaddr, struct vm_area_struct *vma);
1997 -};
1998 +} __no_const;
1999
2000 #ifdef MULTI_USER
2001 extern struct cpu_user_fns cpu_user;
2002 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2003 index 78a7793..e3dc06c 100644
2004 --- a/arch/arm/include/asm/pgalloc.h
2005 +++ b/arch/arm/include/asm/pgalloc.h
2006 @@ -17,6 +17,7 @@
2007 #include <asm/processor.h>
2008 #include <asm/cacheflush.h>
2009 #include <asm/tlbflush.h>
2010 +#include <asm/system_info.h>
2011
2012 #define check_pgt_cache() do { } while (0)
2013
2014 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2015 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2016 }
2017
2018 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2019 +{
2020 + pud_populate(mm, pud, pmd);
2021 +}
2022 +
2023 #else /* !CONFIG_ARM_LPAE */
2024
2025 /*
2026 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2027 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2028 #define pmd_free(mm, pmd) do { } while (0)
2029 #define pud_populate(mm,pmd,pte) BUG()
2030 +#define pud_populate_kernel(mm,pmd,pte) BUG()
2031
2032 #endif /* CONFIG_ARM_LPAE */
2033
2034 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2035 __free_page(pte);
2036 }
2037
2038 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2039 +{
2040 +#ifdef CONFIG_ARM_LPAE
2041 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2042 +#else
2043 + if (addr & SECTION_SIZE)
2044 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2045 + else
2046 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2047 +#endif
2048 + flush_pmd_entry(pmdp);
2049 +}
2050 +
2051 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2052 pmdval_t prot)
2053 {
2054 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2055 static inline void
2056 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2057 {
2058 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2059 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2060 }
2061 #define pmd_pgtable(pmd) pmd_page(pmd)
2062
2063 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2064 index 5cfba15..f415e1a 100644
2065 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2066 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2067 @@ -20,12 +20,15 @@
2068 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2069 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2070 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2071 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2072 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2073 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2074 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2075 +
2076 /*
2077 * - section
2078 */
2079 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2080 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2081 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2082 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2083 @@ -37,6 +40,7 @@
2084 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2085 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2086 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2087 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2088
2089 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2090 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2091 @@ -66,6 +70,7 @@
2092 * - extended small page/tiny page
2093 */
2094 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2095 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2096 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2097 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2098 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2099 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2100 index 219ac88..73ec32a 100644
2101 --- a/arch/arm/include/asm/pgtable-2level.h
2102 +++ b/arch/arm/include/asm/pgtable-2level.h
2103 @@ -126,6 +126,9 @@
2104 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2105 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2106
2107 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2108 +#define L_PTE_PXN (_AT(pteval_t, 0))
2109 +
2110 /*
2111 * These are the memory types, defined to be compatible with
2112 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2113 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2114 index 9fd61c7..f8f1cff 100644
2115 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2116 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2117 @@ -76,6 +76,7 @@
2118 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2119 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2120 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2121 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2122 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2123
2124 /*
2125 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2126 index 06e0bc0..c65bca8 100644
2127 --- a/arch/arm/include/asm/pgtable-3level.h
2128 +++ b/arch/arm/include/asm/pgtable-3level.h
2129 @@ -81,6 +81,7 @@
2130 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
2131 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2132 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2133 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2134 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2135 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2136 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2137 @@ -92,10 +93,12 @@
2138 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2139 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2140 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2141 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2142
2143 /*
2144 * To be used in assembly code with the upper page attributes.
2145 */
2146 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2147 #define L_PTE_XN_HIGH (1 << (54 - 32))
2148 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2149
2150 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2151 index 01baef0..73c156e 100644
2152 --- a/arch/arm/include/asm/pgtable.h
2153 +++ b/arch/arm/include/asm/pgtable.h
2154 @@ -33,6 +33,9 @@
2155 #include <asm/pgtable-2level.h>
2156 #endif
2157
2158 +#define ktla_ktva(addr) (addr)
2159 +#define ktva_ktla(addr) (addr)
2160 +
2161 /*
2162 * Just any arbitrary offset to the start of the vmalloc VM area: the
2163 * current 8MB value just means that there will be a 8MB "hole" after the
2164 @@ -48,6 +51,9 @@
2165 #define LIBRARY_TEXT_START 0x0c000000
2166
2167 #ifndef __ASSEMBLY__
2168 +extern pteval_t __supported_pte_mask;
2169 +extern pmdval_t __supported_pmd_mask;
2170 +
2171 extern void __pte_error(const char *file, int line, pte_t);
2172 extern void __pmd_error(const char *file, int line, pmd_t);
2173 extern void __pgd_error(const char *file, int line, pgd_t);
2174 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2175 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2176 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2177
2178 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2179 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2180 +
2181 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2182 +#include <asm/domain.h>
2183 +#include <linux/thread_info.h>
2184 +#include <linux/preempt.h>
2185 +
2186 +static inline int test_domain(int domain, int domaintype)
2187 +{
2188 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2189 +}
2190 +#endif
2191 +
2192 +#ifdef CONFIG_PAX_KERNEXEC
2193 +static inline unsigned long pax_open_kernel(void) {
2194 +#ifdef CONFIG_ARM_LPAE
2195 + /* TODO */
2196 +#else
2197 + preempt_disable();
2198 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2199 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2200 +#endif
2201 + return 0;
2202 +}
2203 +
2204 +static inline unsigned long pax_close_kernel(void) {
2205 +#ifdef CONFIG_ARM_LPAE
2206 + /* TODO */
2207 +#else
2208 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2209 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2210 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2211 + preempt_enable_no_resched();
2212 +#endif
2213 + return 0;
2214 +}
2215 +#else
2216 +static inline unsigned long pax_open_kernel(void) { return 0; }
2217 +static inline unsigned long pax_close_kernel(void) { return 0; }
2218 +#endif
2219 +
2220 /*
2221 * This is the lowest virtual address we can permit any user space
2222 * mapping to be mapped at. This is particularly important for
2223 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2224 /*
2225 * The pgprot_* and protection_map entries will be fixed up in runtime
2226 * to include the cachable and bufferable bits based on memory policy,
2227 - * as well as any architecture dependent bits like global/ASID and SMP
2228 - * shared mapping bits.
2229 + * as well as any architecture dependent bits like global/ASID, PXN,
2230 + * and SMP shared mapping bits.
2231 */
2232 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2233
2234 @@ -269,7 +317,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2235 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2236 {
2237 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2238 - L_PTE_NONE | L_PTE_VALID;
2239 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2240 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2241 return pte;
2242 }
2243 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2244 index c25ef3e..735f14b 100644
2245 --- a/arch/arm/include/asm/psci.h
2246 +++ b/arch/arm/include/asm/psci.h
2247 @@ -32,7 +32,7 @@ struct psci_operations {
2248 int (*affinity_info)(unsigned long target_affinity,
2249 unsigned long lowest_affinity_level);
2250 int (*migrate_info_type)(void);
2251 -};
2252 +} __no_const;
2253
2254 extern struct psci_operations psci_ops;
2255 extern struct smp_operations psci_smp_ops;
2256 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2257 index 2ec765c..beb1fe16 100644
2258 --- a/arch/arm/include/asm/smp.h
2259 +++ b/arch/arm/include/asm/smp.h
2260 @@ -113,7 +113,7 @@ struct smp_operations {
2261 int (*cpu_disable)(unsigned int cpu);
2262 #endif
2263 #endif
2264 -};
2265 +} __no_const;
2266
2267 struct of_cpu_method {
2268 const char *method;
2269 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2270 index fc44d37..acc63c4 100644
2271 --- a/arch/arm/include/asm/thread_info.h
2272 +++ b/arch/arm/include/asm/thread_info.h
2273 @@ -89,9 +89,9 @@ struct thread_info {
2274 .flags = 0, \
2275 .preempt_count = INIT_PREEMPT_COUNT, \
2276 .addr_limit = KERNEL_DS, \
2277 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2278 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2279 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2280 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2281 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2282 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2283 .restart_block = { \
2284 .fn = do_no_restart_syscall, \
2285 }, \
2286 @@ -165,7 +165,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2287 #define TIF_SYSCALL_AUDIT 9
2288 #define TIF_SYSCALL_TRACEPOINT 10
2289 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2290 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2291 +/* within 8 bits of TIF_SYSCALL_TRACE
2292 + * to meet flexible second operand requirements
2293 + */
2294 +#define TIF_GRSEC_SETXID 12
2295 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2296 #define TIF_USING_IWMMXT 17
2297 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2298 #define TIF_RESTORE_SIGMASK 20
2299 @@ -179,10 +183,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2300 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2301 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2302 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2303 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2304
2305 /* Checks for any syscall work in entry-common.S */
2306 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2307 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2308 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2309
2310 /*
2311 * Change these and you break ASM code in entry-common.S
2312 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2313 index 5f833f7..76e6644 100644
2314 --- a/arch/arm/include/asm/tls.h
2315 +++ b/arch/arm/include/asm/tls.h
2316 @@ -3,6 +3,7 @@
2317
2318 #include <linux/compiler.h>
2319 #include <asm/thread_info.h>
2320 +#include <asm/pgtable.h>
2321
2322 #ifdef __ASSEMBLY__
2323 #include <asm/asm-offsets.h>
2324 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2325 * at 0xffff0fe0 must be used instead. (see
2326 * entry-armv.S for details)
2327 */
2328 + pax_open_kernel();
2329 *((unsigned int *)0xffff0ff0) = val;
2330 + pax_close_kernel();
2331 #endif
2332 }
2333
2334 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2335 index 4767eb9..bf00668 100644
2336 --- a/arch/arm/include/asm/uaccess.h
2337 +++ b/arch/arm/include/asm/uaccess.h
2338 @@ -18,6 +18,7 @@
2339 #include <asm/domain.h>
2340 #include <asm/unified.h>
2341 #include <asm/compiler.h>
2342 +#include <asm/pgtable.h>
2343
2344 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2345 #include <asm-generic/uaccess-unaligned.h>
2346 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2347 static inline void set_fs(mm_segment_t fs)
2348 {
2349 current_thread_info()->addr_limit = fs;
2350 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2351 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2352 }
2353
2354 #define segment_eq(a,b) ((a) == (b))
2355
2356 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2357 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2358 +
2359 +static inline void pax_open_userland(void)
2360 +{
2361 +
2362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2363 + if (segment_eq(get_fs(), USER_DS)) {
2364 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2365 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2366 + }
2367 +#endif
2368 +
2369 +}
2370 +
2371 +static inline void pax_close_userland(void)
2372 +{
2373 +
2374 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2375 + if (segment_eq(get_fs(), USER_DS)) {
2376 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2377 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2378 + }
2379 +#endif
2380 +
2381 +}
2382 +
2383 #define __addr_ok(addr) ({ \
2384 unsigned long flag; \
2385 __asm__("cmp %2, %0; movlo %0, #0" \
2386 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2387
2388 #define get_user(x,p) \
2389 ({ \
2390 + int __e; \
2391 might_fault(); \
2392 - __get_user_check(x,p); \
2393 + pax_open_userland(); \
2394 + __e = __get_user_check(x,p); \
2395 + pax_close_userland(); \
2396 + __e; \
2397 })
2398
2399 extern int __put_user_1(void *, unsigned int);
2400 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2401
2402 #define put_user(x,p) \
2403 ({ \
2404 + int __e; \
2405 might_fault(); \
2406 - __put_user_check(x,p); \
2407 + pax_open_userland(); \
2408 + __e = __put_user_check(x,p); \
2409 + pax_close_userland(); \
2410 + __e; \
2411 })
2412
2413 #else /* CONFIG_MMU */
2414 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2415
2416 #endif /* CONFIG_MMU */
2417
2418 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2419 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2420
2421 #define user_addr_max() \
2422 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2423 #define __get_user(x,ptr) \
2424 ({ \
2425 long __gu_err = 0; \
2426 + pax_open_userland(); \
2427 __get_user_err((x),(ptr),__gu_err); \
2428 + pax_close_userland(); \
2429 __gu_err; \
2430 })
2431
2432 #define __get_user_error(x,ptr,err) \
2433 ({ \
2434 + pax_open_userland(); \
2435 __get_user_err((x),(ptr),err); \
2436 + pax_close_userland(); \
2437 (void) 0; \
2438 })
2439
2440 @@ -368,13 +409,17 @@ do { \
2441 #define __put_user(x,ptr) \
2442 ({ \
2443 long __pu_err = 0; \
2444 + pax_open_userland(); \
2445 __put_user_err((x),(ptr),__pu_err); \
2446 + pax_close_userland(); \
2447 __pu_err; \
2448 })
2449
2450 #define __put_user_error(x,ptr,err) \
2451 ({ \
2452 + pax_open_userland(); \
2453 __put_user_err((x),(ptr),err); \
2454 + pax_close_userland(); \
2455 (void) 0; \
2456 })
2457
2458 @@ -474,11 +519,44 @@ do { \
2459
2460
2461 #ifdef CONFIG_MMU
2462 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2463 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2464 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2465 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2466 +
2467 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2468 +{
2469 + unsigned long ret;
2470 +
2471 + check_object_size(to, n, false);
2472 + pax_open_userland();
2473 + ret = ___copy_from_user(to, from, n);
2474 + pax_close_userland();
2475 + return ret;
2476 +}
2477 +
2478 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2479 +{
2480 + unsigned long ret;
2481 +
2482 + check_object_size(from, n, true);
2483 + pax_open_userland();
2484 + ret = ___copy_to_user(to, from, n);
2485 + pax_close_userland();
2486 + return ret;
2487 +}
2488 +
2489 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2490 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2491 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2492 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2493 +
2494 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2495 +{
2496 + unsigned long ret;
2497 + pax_open_userland();
2498 + ret = ___clear_user(addr, n);
2499 + pax_close_userland();
2500 + return ret;
2501 +}
2502 +
2503 #else
2504 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2505 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2506 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2507
2508 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2509 {
2510 + if ((long)n < 0)
2511 + return n;
2512 +
2513 if (access_ok(VERIFY_READ, from, n))
2514 n = __copy_from_user(to, from, n);
2515 else /* security hole - plug it */
2516 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2517
2518 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2519 {
2520 + if ((long)n < 0)
2521 + return n;
2522 +
2523 if (access_ok(VERIFY_WRITE, to, n))
2524 n = __copy_to_user(to, from, n);
2525 return n;
2526 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2527 index 5af0ed1..cea83883 100644
2528 --- a/arch/arm/include/uapi/asm/ptrace.h
2529 +++ b/arch/arm/include/uapi/asm/ptrace.h
2530 @@ -92,7 +92,7 @@
2531 * ARMv7 groups of PSR bits
2532 */
2533 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2534 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2535 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2536 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2537 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2538
2539 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2540 index a88671c..1cc895e 100644
2541 --- a/arch/arm/kernel/armksyms.c
2542 +++ b/arch/arm/kernel/armksyms.c
2543 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2544
2545 /* networking */
2546 EXPORT_SYMBOL(csum_partial);
2547 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2548 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2549 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2550 EXPORT_SYMBOL(__csum_ipv6_magic);
2551
2552 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2553 #ifdef CONFIG_MMU
2554 EXPORT_SYMBOL(copy_page);
2555
2556 -EXPORT_SYMBOL(__copy_from_user);
2557 -EXPORT_SYMBOL(__copy_to_user);
2558 -EXPORT_SYMBOL(__clear_user);
2559 +EXPORT_SYMBOL(___copy_from_user);
2560 +EXPORT_SYMBOL(___copy_to_user);
2561 +EXPORT_SYMBOL(___clear_user);
2562
2563 EXPORT_SYMBOL(__get_user_1);
2564 EXPORT_SYMBOL(__get_user_2);
2565 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2566 index 36276cd..9d7b13b 100644
2567 --- a/arch/arm/kernel/entry-armv.S
2568 +++ b/arch/arm/kernel/entry-armv.S
2569 @@ -47,6 +47,87 @@
2570 9997:
2571 .endm
2572
2573 + .macro pax_enter_kernel
2574 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2575 + @ make aligned space for saved DACR
2576 + sub sp, sp, #8
2577 + @ save regs
2578 + stmdb sp!, {r1, r2}
2579 + @ read DACR from cpu_domain into r1
2580 + mov r2, sp
2581 + @ assume 8K pages, since we have to split the immediate in two
2582 + bic r2, r2, #(0x1fc0)
2583 + bic r2, r2, #(0x3f)
2584 + ldr r1, [r2, #TI_CPU_DOMAIN]
2585 + @ store old DACR on stack
2586 + str r1, [sp, #8]
2587 +#ifdef CONFIG_PAX_KERNEXEC
2588 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2589 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2590 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2591 +#endif
2592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2593 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2594 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2595 +#endif
2596 + @ write r1 to current_thread_info()->cpu_domain
2597 + str r1, [r2, #TI_CPU_DOMAIN]
2598 + @ write r1 to DACR
2599 + mcr p15, 0, r1, c3, c0, 0
2600 + @ instruction sync
2601 + instr_sync
2602 + @ restore regs
2603 + ldmia sp!, {r1, r2}
2604 +#endif
2605 + .endm
2606 +
2607 + .macro pax_open_userland
2608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2609 + @ save regs
2610 + stmdb sp!, {r0, r1}
2611 + @ read DACR from cpu_domain into r1
2612 + mov r0, sp
2613 + @ assume 8K pages, since we have to split the immediate in two
2614 + bic r0, r0, #(0x1fc0)
2615 + bic r0, r0, #(0x3f)
2616 + ldr r1, [r0, #TI_CPU_DOMAIN]
2617 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2618 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2619 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2620 + @ write r1 to current_thread_info()->cpu_domain
2621 + str r1, [r0, #TI_CPU_DOMAIN]
2622 + @ write r1 to DACR
2623 + mcr p15, 0, r1, c3, c0, 0
2624 + @ instruction sync
2625 + instr_sync
2626 + @ restore regs
2627 + ldmia sp!, {r0, r1}
2628 +#endif
2629 + .endm
2630 +
2631 + .macro pax_close_userland
2632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2633 + @ save regs
2634 + stmdb sp!, {r0, r1}
2635 + @ read DACR from cpu_domain into r1
2636 + mov r0, sp
2637 + @ assume 8K pages, since we have to split the immediate in two
2638 + bic r0, r0, #(0x1fc0)
2639 + bic r0, r0, #(0x3f)
2640 + ldr r1, [r0, #TI_CPU_DOMAIN]
2641 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643 + @ write r1 to current_thread_info()->cpu_domain
2644 + str r1, [r0, #TI_CPU_DOMAIN]
2645 + @ write r1 to DACR
2646 + mcr p15, 0, r1, c3, c0, 0
2647 + @ instruction sync
2648 + instr_sync
2649 + @ restore regs
2650 + ldmia sp!, {r0, r1}
2651 +#endif
2652 + .endm
2653 +
2654 .macro pabt_helper
2655 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2656 #ifdef MULTI_PABORT
2657 @@ -89,11 +170,15 @@
2658 * Invalid mode handlers
2659 */
2660 .macro inv_entry, reason
2661 +
2662 + pax_enter_kernel
2663 +
2664 sub sp, sp, #S_FRAME_SIZE
2665 ARM( stmib sp, {r1 - lr} )
2666 THUMB( stmia sp, {r0 - r12} )
2667 THUMB( str sp, [sp, #S_SP] )
2668 THUMB( str lr, [sp, #S_LR] )
2669 +
2670 mov r1, #\reason
2671 .endm
2672
2673 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2674 .macro svc_entry, stack_hole=0
2675 UNWIND(.fnstart )
2676 UNWIND(.save {r0 - pc} )
2677 +
2678 + pax_enter_kernel
2679 +
2680 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2681 +
2682 #ifdef CONFIG_THUMB2_KERNEL
2683 SPFIX( str r0, [sp] ) @ temporarily saved
2684 SPFIX( mov r0, sp )
2685 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2686 ldmia r0, {r3 - r5}
2687 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2688 mov r6, #-1 @ "" "" "" ""
2689 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2690 + @ offset sp by 8 as done in pax_enter_kernel
2691 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2692 +#else
2693 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2694 +#endif
2695 SPFIX( addeq r2, r2, #4 )
2696 str r3, [sp, #-4]! @ save the "real" r0 copied
2697 @ from the exception stack
2698 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2699 .macro usr_entry
2700 UNWIND(.fnstart )
2701 UNWIND(.cantunwind ) @ don't unwind the user space
2702 +
2703 + pax_enter_kernel_user
2704 +
2705 sub sp, sp, #S_FRAME_SIZE
2706 ARM( stmib sp, {r1 - r12} )
2707 THUMB( stmia sp, {r0 - r12} )
2708 @@ -421,7 +518,9 @@ __und_usr:
2709 tst r3, #PSR_T_BIT @ Thumb mode?
2710 bne __und_usr_thumb
2711 sub r4, r2, #4 @ ARM instr at LR - 4
2712 + pax_open_userland
2713 1: ldrt r0, [r4]
2714 + pax_close_userland
2715 ARM_BE8(rev r0, r0) @ little endian instruction
2716
2717 @ r0 = 32-bit ARM instruction which caused the exception
2718 @@ -455,11 +554,15 @@ __und_usr_thumb:
2719 */
2720 .arch armv6t2
2721 #endif
2722 + pax_open_userland
2723 2: ldrht r5, [r4]
2724 + pax_close_userland
2725 ARM_BE8(rev16 r5, r5) @ little endian instruction
2726 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2727 blo __und_usr_fault_16 @ 16bit undefined instruction
2728 + pax_open_userland
2729 3: ldrht r0, [r2]
2730 + pax_close_userland
2731 ARM_BE8(rev16 r0, r0) @ little endian instruction
2732 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2733 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2734 @@ -489,7 +592,8 @@ ENDPROC(__und_usr)
2735 */
2736 .pushsection .fixup, "ax"
2737 .align 2
2738 -4: str r4, [sp, #S_PC] @ retry current instruction
2739 +4: pax_close_userland
2740 + str r4, [sp, #S_PC] @ retry current instruction
2741 ret r9
2742 .popsection
2743 .pushsection __ex_table,"a"
2744 @@ -698,7 +802,7 @@ ENTRY(__switch_to)
2745 THUMB( str lr, [ip], #4 )
2746 ldr r4, [r2, #TI_TP_VALUE]
2747 ldr r5, [r2, #TI_TP_VALUE + 4]
2748 -#ifdef CONFIG_CPU_USE_DOMAINS
2749 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2750 ldr r6, [r2, #TI_CPU_DOMAIN]
2751 #endif
2752 switch_tls r1, r4, r5, r3, r7
2753 @@ -707,7 +811,7 @@ ENTRY(__switch_to)
2754 ldr r8, =__stack_chk_guard
2755 ldr r7, [r7, #TSK_STACK_CANARY]
2756 #endif
2757 -#ifdef CONFIG_CPU_USE_DOMAINS
2758 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2759 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2760 #endif
2761 mov r5, r0
2762 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2763 index e52fe5a..1b0a924 100644
2764 --- a/arch/arm/kernel/entry-common.S
2765 +++ b/arch/arm/kernel/entry-common.S
2766 @@ -11,18 +11,46 @@
2767 #include <asm/assembler.h>
2768 #include <asm/unistd.h>
2769 #include <asm/ftrace.h>
2770 +#include <asm/domain.h>
2771 #include <asm/unwind.h>
2772
2773 +#include "entry-header.S"
2774 +
2775 #ifdef CONFIG_NEED_RET_TO_USER
2776 #include <mach/entry-macro.S>
2777 #else
2778 .macro arch_ret_to_user, tmp1, tmp2
2779 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2780 + @ save regs
2781 + stmdb sp!, {r1, r2}
2782 + @ read DACR from cpu_domain into r1
2783 + mov r2, sp
2784 + @ assume 8K pages, since we have to split the immediate in two
2785 + bic r2, r2, #(0x1fc0)
2786 + bic r2, r2, #(0x3f)
2787 + ldr r1, [r2, #TI_CPU_DOMAIN]
2788 +#ifdef CONFIG_PAX_KERNEXEC
2789 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2790 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2791 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2792 +#endif
2793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2794 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2795 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2796 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2797 +#endif
2798 + @ write r1 to current_thread_info()->cpu_domain
2799 + str r1, [r2, #TI_CPU_DOMAIN]
2800 + @ write r1 to DACR
2801 + mcr p15, 0, r1, c3, c0, 0
2802 + @ instruction sync
2803 + instr_sync
2804 + @ restore regs
2805 + ldmia sp!, {r1, r2}
2806 +#endif
2807 .endm
2808 #endif
2809
2810 -#include "entry-header.S"
2811 -
2812 -
2813 .align 5
2814 /*
2815 * This is the fast syscall return path. We do as little as
2816 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2817 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2818 #endif
2819
2820 + /*
2821 + * do this here to avoid a performance hit of wrapping the code above
2822 + * that directly dereferences userland to parse the SWI instruction
2823 + */
2824 + pax_enter_kernel_user
2825 +
2826 adr tbl, sys_call_table @ load syscall table pointer
2827
2828 #if defined(CONFIG_OABI_COMPAT)
2829 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2830 index 2fdf867..6e909e4 100644
2831 --- a/arch/arm/kernel/entry-header.S
2832 +++ b/arch/arm/kernel/entry-header.S
2833 @@ -188,6 +188,60 @@
2834 msr cpsr_c, \rtemp @ switch back to the SVC mode
2835 .endm
2836
2837 + .macro pax_enter_kernel_user
2838 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2839 + @ save regs
2840 + stmdb sp!, {r0, r1}
2841 + @ read DACR from cpu_domain into r1
2842 + mov r0, sp
2843 + @ assume 8K pages, since we have to split the immediate in two
2844 + bic r0, r0, #(0x1fc0)
2845 + bic r0, r0, #(0x3f)
2846 + ldr r1, [r0, #TI_CPU_DOMAIN]
2847 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2848 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2849 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2850 +#endif
2851 +#ifdef CONFIG_PAX_KERNEXEC
2852 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2853 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2854 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2855 +#endif
2856 + @ write r1 to current_thread_info()->cpu_domain
2857 + str r1, [r0, #TI_CPU_DOMAIN]
2858 + @ write r1 to DACR
2859 + mcr p15, 0, r1, c3, c0, 0
2860 + @ instruction sync
2861 + instr_sync
2862 + @ restore regs
2863 + ldmia sp!, {r0, r1}
2864 +#endif
2865 + .endm
2866 +
2867 + .macro pax_exit_kernel
2868 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2869 + @ save regs
2870 + stmdb sp!, {r0, r1}
2871 + @ read old DACR from stack into r1
2872 + ldr r1, [sp, #(8 + S_SP)]
2873 + sub r1, r1, #8
2874 + ldr r1, [r1]
2875 +
2876 + @ write r1 to current_thread_info()->cpu_domain
2877 + mov r0, sp
2878 + @ assume 8K pages, since we have to split the immediate in two
2879 + bic r0, r0, #(0x1fc0)
2880 + bic r0, r0, #(0x3f)
2881 + str r1, [r0, #TI_CPU_DOMAIN]
2882 + @ write r1 to DACR
2883 + mcr p15, 0, r1, c3, c0, 0
2884 + @ instruction sync
2885 + instr_sync
2886 + @ restore regs
2887 + ldmia sp!, {r0, r1}
2888 +#endif
2889 + .endm
2890 +
2891 #ifndef CONFIG_THUMB2_KERNEL
2892 .macro svc_exit, rpsr, irq = 0
2893 .if \irq != 0
2894 @@ -207,6 +261,9 @@
2895 blne trace_hardirqs_off
2896 #endif
2897 .endif
2898 +
2899 + pax_exit_kernel
2900 +
2901 msr spsr_cxsf, \rpsr
2902 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2903 @ We must avoid clrex due to Cortex-A15 erratum #830321
2904 @@ -254,6 +311,9 @@
2905 blne trace_hardirqs_off
2906 #endif
2907 .endif
2908 +
2909 + pax_exit_kernel
2910 +
2911 ldr lr, [sp, #S_SP] @ top of the stack
2912 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2913
2914 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2915 index 918875d..cd5fa27 100644
2916 --- a/arch/arm/kernel/fiq.c
2917 +++ b/arch/arm/kernel/fiq.c
2918 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2919 void *base = vectors_page;
2920 unsigned offset = FIQ_OFFSET;
2921
2922 + pax_open_kernel();
2923 memcpy(base + offset, start, length);
2924 + pax_close_kernel();
2925 +
2926 if (!cache_is_vipt_nonaliasing())
2927 flush_icache_range((unsigned long)base + offset, offset +
2928 length);
2929 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2930 index 664eee8..f470938 100644
2931 --- a/arch/arm/kernel/head.S
2932 +++ b/arch/arm/kernel/head.S
2933 @@ -437,7 +437,7 @@ __enable_mmu:
2934 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2935 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2936 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2937 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2938 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2939 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2940 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2941 #endif
2942 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2943 index 6a4dffe..4a86a70 100644
2944 --- a/arch/arm/kernel/module.c
2945 +++ b/arch/arm/kernel/module.c
2946 @@ -38,12 +38,39 @@
2947 #endif
2948
2949 #ifdef CONFIG_MMU
2950 -void *module_alloc(unsigned long size)
2951 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2952 {
2953 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2954 + return NULL;
2955 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2956 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2957 + GFP_KERNEL, prot, NUMA_NO_NODE,
2958 __builtin_return_address(0));
2959 }
2960 +
2961 +void *module_alloc(unsigned long size)
2962 +{
2963 +
2964 +#ifdef CONFIG_PAX_KERNEXEC
2965 + return __module_alloc(size, PAGE_KERNEL);
2966 +#else
2967 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2968 +#endif
2969 +
2970 +}
2971 +
2972 +#ifdef CONFIG_PAX_KERNEXEC
2973 +void module_free_exec(struct module *mod, void *module_region)
2974 +{
2975 + module_free(mod, module_region);
2976 +}
2977 +EXPORT_SYMBOL(module_free_exec);
2978 +
2979 +void *module_alloc_exec(unsigned long size)
2980 +{
2981 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2982 +}
2983 +EXPORT_SYMBOL(module_alloc_exec);
2984 +#endif
2985 #endif
2986
2987 int
2988 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2989 index 07314af..c46655c 100644
2990 --- a/arch/arm/kernel/patch.c
2991 +++ b/arch/arm/kernel/patch.c
2992 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2993 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2994 int size;
2995
2996 + pax_open_kernel();
2997 if (thumb2 && __opcode_is_thumb16(insn)) {
2998 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2999 size = sizeof(u16);
3000 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3001 *(u32 *)addr = insn;
3002 size = sizeof(u32);
3003 }
3004 + pax_close_kernel();
3005
3006 flush_icache_range((uintptr_t)(addr),
3007 (uintptr_t)(addr) + size);
3008 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3009 index a35f6eb..7af43a0 100644
3010 --- a/arch/arm/kernel/process.c
3011 +++ b/arch/arm/kernel/process.c
3012 @@ -212,6 +212,7 @@ void machine_power_off(void)
3013
3014 if (pm_power_off)
3015 pm_power_off();
3016 + BUG();
3017 }
3018
3019 /*
3020 @@ -225,7 +226,7 @@ void machine_power_off(void)
3021 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3022 * to use. Implementing such co-ordination would be essentially impossible.
3023 */
3024 -void machine_restart(char *cmd)
3025 +__noreturn void machine_restart(char *cmd)
3026 {
3027 local_irq_disable();
3028 smp_send_stop();
3029 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3030
3031 show_regs_print_info(KERN_DEFAULT);
3032
3033 - print_symbol("PC is at %s\n", instruction_pointer(regs));
3034 - print_symbol("LR is at %s\n", regs->ARM_lr);
3035 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3036 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
3037 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3038 "sp : %08lx ip : %08lx fp : %08lx\n",
3039 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3040 @@ -427,12 +428,6 @@ unsigned long get_wchan(struct task_struct *p)
3041 return 0;
3042 }
3043
3044 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3045 -{
3046 - unsigned long range_end = mm->brk + 0x02000000;
3047 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3048 -}
3049 -
3050 #ifdef CONFIG_MMU
3051 #ifdef CONFIG_KUSER_HELPERS
3052 /*
3053 @@ -448,7 +443,7 @@ static struct vm_area_struct gate_vma = {
3054
3055 static int __init gate_vma_init(void)
3056 {
3057 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3058 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3059 return 0;
3060 }
3061 arch_initcall(gate_vma_init);
3062 @@ -474,41 +469,16 @@ int in_gate_area_no_mm(unsigned long addr)
3063
3064 const char *arch_vma_name(struct vm_area_struct *vma)
3065 {
3066 - return is_gate_vma(vma) ? "[vectors]" :
3067 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3068 - "[sigpage]" : NULL;
3069 + return is_gate_vma(vma) ? "[vectors]" : NULL;
3070 }
3071
3072 -static struct page *signal_page;
3073 -extern struct page *get_signal_page(void);
3074 -
3075 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3076 {
3077 struct mm_struct *mm = current->mm;
3078 - unsigned long addr;
3079 - int ret;
3080 -
3081 - if (!signal_page)
3082 - signal_page = get_signal_page();
3083 - if (!signal_page)
3084 - return -ENOMEM;
3085
3086 down_write(&mm->mmap_sem);
3087 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3088 - if (IS_ERR_VALUE(addr)) {
3089 - ret = addr;
3090 - goto up_fail;
3091 - }
3092 -
3093 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
3094 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3095 - &signal_page);
3096 -
3097 - if (ret == 0)
3098 - mm->context.sigpage = addr;
3099 -
3100 - up_fail:
3101 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3102 up_write(&mm->mmap_sem);
3103 - return ret;
3104 + return 0;
3105 }
3106 #endif
3107 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3108 index f73891b..cf3004e 100644
3109 --- a/arch/arm/kernel/psci.c
3110 +++ b/arch/arm/kernel/psci.c
3111 @@ -28,7 +28,7 @@
3112 #include <asm/psci.h>
3113 #include <asm/system_misc.h>
3114
3115 -struct psci_operations psci_ops;
3116 +struct psci_operations psci_ops __read_only;
3117
3118 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3119 typedef int (*psci_initcall_t)(const struct device_node *);
3120 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3121 index 0c27ed6..b67388e 100644
3122 --- a/arch/arm/kernel/ptrace.c
3123 +++ b/arch/arm/kernel/ptrace.c
3124 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3125 regs->ARM_ip = ip;
3126 }
3127
3128 +#ifdef CONFIG_GRKERNSEC_SETXID
3129 +extern void gr_delayed_cred_worker(void);
3130 +#endif
3131 +
3132 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3133 {
3134 current_thread_info()->syscall = scno;
3135
3136 +#ifdef CONFIG_GRKERNSEC_SETXID
3137 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3138 + gr_delayed_cred_worker();
3139 +#endif
3140 +
3141 /* Do the secure computing check first; failures should be fast. */
3142 if (secure_computing(scno) == -1)
3143 return -1;
3144 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3145 index 84db893d..bd8213a 100644
3146 --- a/arch/arm/kernel/setup.c
3147 +++ b/arch/arm/kernel/setup.c
3148 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3149 unsigned int elf_hwcap2 __read_mostly;
3150 EXPORT_SYMBOL(elf_hwcap2);
3151
3152 +pteval_t __supported_pte_mask __read_only;
3153 +pmdval_t __supported_pmd_mask __read_only;
3154
3155 #ifdef MULTI_CPU
3156 -struct processor processor __read_mostly;
3157 +struct processor processor __read_only;
3158 #endif
3159 #ifdef MULTI_TLB
3160 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3161 +struct cpu_tlb_fns cpu_tlb __read_only;
3162 #endif
3163 #ifdef MULTI_USER
3164 -struct cpu_user_fns cpu_user __read_mostly;
3165 +struct cpu_user_fns cpu_user __read_only;
3166 #endif
3167 #ifdef MULTI_CACHE
3168 -struct cpu_cache_fns cpu_cache __read_mostly;
3169 +struct cpu_cache_fns cpu_cache __read_only;
3170 #endif
3171 #ifdef CONFIG_OUTER_CACHE
3172 -struct outer_cache_fns outer_cache __read_mostly;
3173 +struct outer_cache_fns outer_cache __read_only;
3174 EXPORT_SYMBOL(outer_cache);
3175 #endif
3176
3177 @@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3178 asm("mrc p15, 0, %0, c0, c1, 4"
3179 : "=r" (mmfr0));
3180 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3181 - (mmfr0 & 0x000000f0) >= 0x00000030)
3182 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3183 cpu_arch = CPU_ARCH_ARMv7;
3184 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3185 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3186 + __supported_pte_mask |= L_PTE_PXN;
3187 + __supported_pmd_mask |= PMD_PXNTABLE;
3188 + }
3189 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3190 (mmfr0 & 0x000000f0) == 0x00000020)
3191 cpu_arch = CPU_ARCH_ARMv6;
3192 else
3193 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3194 index bd19834..e4d8c66 100644
3195 --- a/arch/arm/kernel/signal.c
3196 +++ b/arch/arm/kernel/signal.c
3197 @@ -24,8 +24,6 @@
3198
3199 extern const unsigned long sigreturn_codes[7];
3200
3201 -static unsigned long signal_return_offset;
3202 -
3203 #ifdef CONFIG_CRUNCH
3204 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3205 {
3206 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3207 * except when the MPU has protected the vectors
3208 * page from PL0
3209 */
3210 - retcode = mm->context.sigpage + signal_return_offset +
3211 - (idx << 2) + thumb;
3212 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3213 } else
3214 #endif
3215 {
3216 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3217 } while (thread_flags & _TIF_WORK_MASK);
3218 return 0;
3219 }
3220 -
3221 -struct page *get_signal_page(void)
3222 -{
3223 - unsigned long ptr;
3224 - unsigned offset;
3225 - struct page *page;
3226 - void *addr;
3227 -
3228 - page = alloc_pages(GFP_KERNEL, 0);
3229 -
3230 - if (!page)
3231 - return NULL;
3232 -
3233 - addr = page_address(page);
3234 -
3235 - /* Give the signal return code some randomness */
3236 - offset = 0x200 + (get_random_int() & 0x7fc);
3237 - signal_return_offset = offset;
3238 -
3239 - /*
3240 - * Copy signal return handlers into the vector page, and
3241 - * set sigreturn to be a pointer to these.
3242 - */
3243 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3244 -
3245 - ptr = (unsigned long)addr + offset;
3246 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3247 -
3248 - return page;
3249 -}
3250 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3251 index bbe22fc..d7737f5 100644
3252 --- a/arch/arm/kernel/smp.c
3253 +++ b/arch/arm/kernel/smp.c
3254 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3255
3256 static DECLARE_COMPLETION(cpu_running);
3257
3258 -static struct smp_operations smp_ops;
3259 +static struct smp_operations smp_ops __read_only;
3260
3261 void __init smp_set_ops(struct smp_operations *ops)
3262 {
3263 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3264 index 7a3be1d..b00c7de 100644
3265 --- a/arch/arm/kernel/tcm.c
3266 +++ b/arch/arm/kernel/tcm.c
3267 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3268 .virtual = ITCM_OFFSET,
3269 .pfn = __phys_to_pfn(ITCM_OFFSET),
3270 .length = 0,
3271 - .type = MT_MEMORY_RWX_ITCM,
3272 + .type = MT_MEMORY_RX_ITCM,
3273 }
3274 };
3275
3276 @@ -267,7 +267,9 @@ no_dtcm:
3277 start = &__sitcm_text;
3278 end = &__eitcm_text;
3279 ram = &__itcm_start;
3280 + pax_open_kernel();
3281 memcpy(start, ram, itcm_code_sz);
3282 + pax_close_kernel();
3283 pr_debug("CPU ITCM: copied code from %p - %p\n",
3284 start, end);
3285 itcm_present = true;
3286 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3287 index a964c9f..cf2a5b1 100644
3288 --- a/arch/arm/kernel/traps.c
3289 +++ b/arch/arm/kernel/traps.c
3290 @@ -64,7 +64,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3291 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3292 {
3293 #ifdef CONFIG_KALLSYMS
3294 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3295 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3296 #else
3297 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3298 #endif
3299 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3300 static int die_owner = -1;
3301 static unsigned int die_nest_count;
3302
3303 +extern void gr_handle_kernel_exploit(void);
3304 +
3305 static unsigned long oops_begin(void)
3306 {
3307 int cpu;
3308 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3309 panic("Fatal exception in interrupt");
3310 if (panic_on_oops)
3311 panic("Fatal exception");
3312 +
3313 + gr_handle_kernel_exploit();
3314 +
3315 if (signr)
3316 do_exit(signr);
3317 }
3318 @@ -887,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3319 kuser_init(vectors_base);
3320
3321 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3322 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3323 +
3324 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3325 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3326 +#endif
3327 +
3328 #else /* ifndef CONFIG_CPU_V7M */
3329 /*
3330 * on V7-M there is no need to copy the vector table to a dedicated
3331 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3332 index 6f57cb9..645f8c4 100644
3333 --- a/arch/arm/kernel/vmlinux.lds.S
3334 +++ b/arch/arm/kernel/vmlinux.lds.S
3335 @@ -8,7 +8,11 @@
3336 #include <asm/thread_info.h>
3337 #include <asm/memory.h>
3338 #include <asm/page.h>
3339 -
3340 +
3341 +#ifdef CONFIG_PAX_KERNEXEC
3342 +#include <asm/pgtable.h>
3343 +#endif
3344 +
3345 #define PROC_INFO \
3346 . = ALIGN(4); \
3347 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3348 @@ -34,7 +38,7 @@
3349 #endif
3350
3351 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3352 - defined(CONFIG_GENERIC_BUG)
3353 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3354 #define ARM_EXIT_KEEP(x) x
3355 #define ARM_EXIT_DISCARD(x)
3356 #else
3357 @@ -90,6 +94,11 @@ SECTIONS
3358 _text = .;
3359 HEAD_TEXT
3360 }
3361 +
3362 +#ifdef CONFIG_PAX_KERNEXEC
3363 + . = ALIGN(1<<SECTION_SHIFT);
3364 +#endif
3365 +
3366 .text : { /* Real text segment */
3367 _stext = .; /* Text and read-only data */
3368 __exception_text_start = .;
3369 @@ -112,6 +121,8 @@ SECTIONS
3370 ARM_CPU_KEEP(PROC_INFO)
3371 }
3372
3373 + _etext = .; /* End of text section */
3374 +
3375 RO_DATA(PAGE_SIZE)
3376
3377 . = ALIGN(4);
3378 @@ -142,7 +153,9 @@ SECTIONS
3379
3380 NOTES
3381
3382 - _etext = .; /* End of text and rodata section */
3383 +#ifdef CONFIG_PAX_KERNEXEC
3384 + . = ALIGN(1<<SECTION_SHIFT);
3385 +#endif
3386
3387 #ifndef CONFIG_XIP_KERNEL
3388 . = ALIGN(PAGE_SIZE);
3389 @@ -220,6 +233,11 @@ SECTIONS
3390 . = PAGE_OFFSET + TEXT_OFFSET;
3391 #else
3392 __init_end = .;
3393 +
3394 +#ifdef CONFIG_PAX_KERNEXEC
3395 + . = ALIGN(1<<SECTION_SHIFT);
3396 +#endif
3397 +
3398 . = ALIGN(THREAD_SIZE);
3399 __data_loc = .;
3400 #endif
3401 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3402 index a99e0cd..ab56421d 100644
3403 --- a/arch/arm/kvm/arm.c
3404 +++ b/arch/arm/kvm/arm.c
3405 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3406 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3407
3408 /* The VMID used in the VTTBR */
3409 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3410 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3411 static u8 kvm_next_vmid;
3412 static DEFINE_SPINLOCK(kvm_vmid_lock);
3413
3414 @@ -372,7 +372,7 @@ void force_vm_exit(const cpumask_t *mask)
3415 */
3416 static bool need_new_vmid_gen(struct kvm *kvm)
3417 {
3418 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3419 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3420 }
3421
3422 /**
3423 @@ -405,7 +405,7 @@ static void update_vttbr(struct kvm *kvm)
3424
3425 /* First user of a new VMID generation? */
3426 if (unlikely(kvm_next_vmid == 0)) {
3427 - atomic64_inc(&kvm_vmid_gen);
3428 + atomic64_inc_unchecked(&kvm_vmid_gen);
3429 kvm_next_vmid = 1;
3430
3431 /*
3432 @@ -422,7 +422,7 @@ static void update_vttbr(struct kvm *kvm)
3433 kvm_call_hyp(__kvm_flush_vm_context);
3434 }
3435
3436 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3437 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3438 kvm->arch.vmid = kvm_next_vmid;
3439 kvm_next_vmid++;
3440
3441 @@ -997,7 +997,7 @@ static void check_kvm_target_cpu(void *ret)
3442 /**
3443 * Initialize Hyp-mode and memory mappings on all CPUs.
3444 */
3445 -int kvm_arch_init(void *opaque)
3446 +int kvm_arch_init(const void *opaque)
3447 {
3448 int err;
3449 int ret, cpu;
3450 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3451 index 14a0d98..7771a7d 100644
3452 --- a/arch/arm/lib/clear_user.S
3453 +++ b/arch/arm/lib/clear_user.S
3454 @@ -12,14 +12,14 @@
3455
3456 .text
3457
3458 -/* Prototype: int __clear_user(void *addr, size_t sz)
3459 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3460 * Purpose : clear some user memory
3461 * Params : addr - user memory address to clear
3462 * : sz - number of bytes to clear
3463 * Returns : number of bytes NOT cleared
3464 */
3465 ENTRY(__clear_user_std)
3466 -WEAK(__clear_user)
3467 +WEAK(___clear_user)
3468 stmfd sp!, {r1, lr}
3469 mov r2, #0
3470 cmp r1, #4
3471 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3472 USER( strnebt r2, [r0])
3473 mov r0, #0
3474 ldmfd sp!, {r1, pc}
3475 -ENDPROC(__clear_user)
3476 +ENDPROC(___clear_user)
3477 ENDPROC(__clear_user_std)
3478
3479 .pushsection .fixup,"ax"
3480 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3481 index 66a477a..bee61d3 100644
3482 --- a/arch/arm/lib/copy_from_user.S
3483 +++ b/arch/arm/lib/copy_from_user.S
3484 @@ -16,7 +16,7 @@
3485 /*
3486 * Prototype:
3487 *
3488 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3489 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3490 *
3491 * Purpose:
3492 *
3493 @@ -84,11 +84,11 @@
3494
3495 .text
3496
3497 -ENTRY(__copy_from_user)
3498 +ENTRY(___copy_from_user)
3499
3500 #include "copy_template.S"
3501
3502 -ENDPROC(__copy_from_user)
3503 +ENDPROC(___copy_from_user)
3504
3505 .pushsection .fixup,"ax"
3506 .align 0
3507 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3508 index 6ee2f67..d1cce76 100644
3509 --- a/arch/arm/lib/copy_page.S
3510 +++ b/arch/arm/lib/copy_page.S
3511 @@ -10,6 +10,7 @@
3512 * ASM optimised string functions
3513 */
3514 #include <linux/linkage.h>
3515 +#include <linux/const.h>
3516 #include <asm/assembler.h>
3517 #include <asm/asm-offsets.h>
3518 #include <asm/cache.h>
3519 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3520 index d066df6..df28194 100644
3521 --- a/arch/arm/lib/copy_to_user.S
3522 +++ b/arch/arm/lib/copy_to_user.S
3523 @@ -16,7 +16,7 @@
3524 /*
3525 * Prototype:
3526 *
3527 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3528 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3529 *
3530 * Purpose:
3531 *
3532 @@ -88,11 +88,11 @@
3533 .text
3534
3535 ENTRY(__copy_to_user_std)
3536 -WEAK(__copy_to_user)
3537 +WEAK(___copy_to_user)
3538
3539 #include "copy_template.S"
3540
3541 -ENDPROC(__copy_to_user)
3542 +ENDPROC(___copy_to_user)
3543 ENDPROC(__copy_to_user_std)
3544
3545 .pushsection .fixup,"ax"
3546 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3547 index 7d08b43..f7ca7ea 100644
3548 --- a/arch/arm/lib/csumpartialcopyuser.S
3549 +++ b/arch/arm/lib/csumpartialcopyuser.S
3550 @@ -57,8 +57,8 @@
3551 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3552 */
3553
3554 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3555 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3556 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3557 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3558
3559 #include "csumpartialcopygeneric.S"
3560
3561 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3562 index 312d43e..21d2322 100644
3563 --- a/arch/arm/lib/delay.c
3564 +++ b/arch/arm/lib/delay.c
3565 @@ -29,7 +29,7 @@
3566 /*
3567 * Default to the loop-based delay implementation.
3568 */
3569 -struct arm_delay_ops arm_delay_ops = {
3570 +struct arm_delay_ops arm_delay_ops __read_only = {
3571 .delay = __loop_delay,
3572 .const_udelay = __loop_const_udelay,
3573 .udelay = __loop_udelay,
3574 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3575 index 3e58d71..029817c 100644
3576 --- a/arch/arm/lib/uaccess_with_memcpy.c
3577 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3578 @@ -136,7 +136,7 @@ out:
3579 }
3580
3581 unsigned long
3582 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3583 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3584 {
3585 /*
3586 * This test is stubbed out of the main function above to keep
3587 @@ -190,7 +190,7 @@ out:
3588 return n;
3589 }
3590
3591 -unsigned long __clear_user(void __user *addr, unsigned long n)
3592 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3593 {
3594 /* See rational for this in __copy_to_user() above. */
3595 if (n < 64)
3596 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3597 index f7a07a5..258e1f7 100644
3598 --- a/arch/arm/mach-at91/setup.c
3599 +++ b/arch/arm/mach-at91/setup.c
3600 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3601
3602 desc->pfn = __phys_to_pfn(base);
3603 desc->length = length;
3604 - desc->type = MT_MEMORY_RWX_NONCACHED;
3605 + desc->type = MT_MEMORY_RW_NONCACHED;
3606
3607 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3608 base, length, desc->virtual);
3609 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3610 index 7f352de..6dc0929 100644
3611 --- a/arch/arm/mach-keystone/keystone.c
3612 +++ b/arch/arm/mach-keystone/keystone.c
3613 @@ -27,7 +27,7 @@
3614
3615 #include "keystone.h"
3616
3617 -static struct notifier_block platform_nb;
3618 +static notifier_block_no_const platform_nb;
3619 static unsigned long keystone_dma_pfn_offset __read_mostly;
3620
3621 static int keystone_platform_notifier(struct notifier_block *nb,
3622 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3623 index 2bdc323..cf1c607 100644
3624 --- a/arch/arm/mach-mvebu/coherency.c
3625 +++ b/arch/arm/mach-mvebu/coherency.c
3626 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3627
3628 /*
3629 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3630 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3631 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3632 * is needed as a workaround for a deadlock issue between the PCIe
3633 * interface and the cache controller.
3634 */
3635 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3636 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3637
3638 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3639 - mtype = MT_UNCACHED;
3640 + mtype = MT_UNCACHED_RW;
3641
3642 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3643 }
3644 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3645 index aead77a..a2253fa 100644
3646 --- a/arch/arm/mach-omap2/board-n8x0.c
3647 +++ b/arch/arm/mach-omap2/board-n8x0.c
3648 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3649 }
3650 #endif
3651
3652 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3653 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3654 .late_init = n8x0_menelaus_late_init,
3655 };
3656
3657 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3658 index 2f97228..6ce10e1 100644
3659 --- a/arch/arm/mach-omap2/gpmc.c
3660 +++ b/arch/arm/mach-omap2/gpmc.c
3661 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3662 };
3663
3664 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3665 -static struct irq_chip gpmc_irq_chip;
3666 static int gpmc_irq_start;
3667
3668 static struct resource gpmc_mem_root;
3669 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3670
3671 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3672
3673 +static struct irq_chip gpmc_irq_chip = {
3674 + .name = "gpmc",
3675 + .irq_startup = gpmc_irq_noop_ret,
3676 + .irq_enable = gpmc_irq_enable,
3677 + .irq_disable = gpmc_irq_disable,
3678 + .irq_shutdown = gpmc_irq_noop,
3679 + .irq_ack = gpmc_irq_noop,
3680 + .irq_mask = gpmc_irq_noop,
3681 + .irq_unmask = gpmc_irq_noop,
3682 +
3683 +};
3684 +
3685 static int gpmc_setup_irq(void)
3686 {
3687 int i;
3688 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3689 return gpmc_irq_start;
3690 }
3691
3692 - gpmc_irq_chip.name = "gpmc";
3693 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3694 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3695 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3696 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3697 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3698 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3699 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3700 -
3701 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3702 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3703
3704 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3705 index 4001325..b14e2a0 100644
3706 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3707 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3708 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3709 int (*finish_suspend)(unsigned long cpu_state);
3710 void (*resume)(void);
3711 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3712 -};
3713 +} __no_const;
3714
3715 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3716 static struct powerdomain *mpuss_pd;
3717 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3718 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3719 {}
3720
3721 -struct cpu_pm_ops omap_pm_ops = {
3722 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3723 .finish_suspend = default_finish_suspend,
3724 .resume = dummy_cpu_resume,
3725 .scu_prepare = dummy_scu_prepare,
3726 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3727 index 37843a7..a98df13 100644
3728 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3729 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3730 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3731 return NOTIFY_OK;
3732 }
3733
3734 -static struct notifier_block __refdata irq_hotplug_notifier = {
3735 +static struct notifier_block irq_hotplug_notifier = {
3736 .notifier_call = irq_cpu_hotplug_notify,
3737 };
3738
3739 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3740 index d22c30d..23697a1 100644
3741 --- a/arch/arm/mach-omap2/omap_device.c
3742 +++ b/arch/arm/mach-omap2/omap_device.c
3743 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3744 struct platform_device __init *omap_device_build(const char *pdev_name,
3745 int pdev_id,
3746 struct omap_hwmod *oh,
3747 - void *pdata, int pdata_len)
3748 + const void *pdata, int pdata_len)
3749 {
3750 struct omap_hwmod *ohs[] = { oh };
3751
3752 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3753 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3754 int pdev_id,
3755 struct omap_hwmod **ohs,
3756 - int oh_cnt, void *pdata,
3757 + int oh_cnt, const void *pdata,
3758 int pdata_len)
3759 {
3760 int ret = -ENOMEM;
3761 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3762 index 78c02b3..c94109a 100644
3763 --- a/arch/arm/mach-omap2/omap_device.h
3764 +++ b/arch/arm/mach-omap2/omap_device.h
3765 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3766 /* Core code interface */
3767
3768 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3769 - struct omap_hwmod *oh, void *pdata,
3770 + struct omap_hwmod *oh, const void *pdata,
3771 int pdata_len);
3772
3773 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3774 struct omap_hwmod **oh, int oh_cnt,
3775 - void *pdata, int pdata_len);
3776 + const void *pdata, int pdata_len);
3777
3778 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3779 struct omap_hwmod **ohs, int oh_cnt);
3780 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3781 index 9e91a4e..357ed0d 100644
3782 --- a/arch/arm/mach-omap2/omap_hwmod.c
3783 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3784 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3785 int (*init_clkdm)(struct omap_hwmod *oh);
3786 void (*update_context_lost)(struct omap_hwmod *oh);
3787 int (*get_context_lost)(struct omap_hwmod *oh);
3788 -};
3789 +} __no_const;
3790
3791 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3792 -static struct omap_hwmod_soc_ops soc_ops;
3793 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3794
3795 /* omap_hwmod_list contains all registered struct omap_hwmods */
3796 static LIST_HEAD(omap_hwmod_list);
3797 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3798 index 95fee54..cfa9cf1 100644
3799 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3800 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3801 @@ -10,6 +10,7 @@
3802
3803 #include <linux/kernel.h>
3804 #include <linux/init.h>
3805 +#include <asm/pgtable.h>
3806
3807 #include "powerdomain.h"
3808
3809 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3810
3811 void __init am43xx_powerdomains_init(void)
3812 {
3813 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3814 + pax_open_kernel();
3815 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3816 + pax_close_kernel();
3817 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3818 pwrdm_register_pwrdms(powerdomains_am43xx);
3819 pwrdm_complete_init();
3820 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3821 index 97d6607..8429d14 100644
3822 --- a/arch/arm/mach-omap2/wd_timer.c
3823 +++ b/arch/arm/mach-omap2/wd_timer.c
3824 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3825 struct omap_hwmod *oh;
3826 char *oh_name = "wd_timer2";
3827 char *dev_name = "omap_wdt";
3828 - struct omap_wd_timer_platform_data pdata;
3829 + static struct omap_wd_timer_platform_data pdata = {
3830 + .read_reset_sources = prm_read_reset_sources
3831 + };
3832
3833 if (!cpu_class_is_omap2() || of_have_populated_dt())
3834 return 0;
3835 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3836 return -EINVAL;
3837 }
3838
3839 - pdata.read_reset_sources = prm_read_reset_sources;
3840 -
3841 pdev = omap_device_build(dev_name, id, oh, &pdata,
3842 sizeof(struct omap_wd_timer_platform_data));
3843 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3844 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3845 index b30bf5c..d0825bf 100644
3846 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3847 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3848 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3849 bool entered_lp2 = false;
3850
3851 if (tegra_pending_sgi())
3852 - ACCESS_ONCE(abort_flag) = true;
3853 + ACCESS_ONCE_RW(abort_flag) = true;
3854
3855 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3856
3857 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3858 index 2dea8b5..6499da2 100644
3859 --- a/arch/arm/mach-ux500/setup.h
3860 +++ b/arch/arm/mach-ux500/setup.h
3861 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3862 .type = MT_DEVICE, \
3863 }
3864
3865 -#define __MEM_DEV_DESC(x, sz) { \
3866 - .virtual = IO_ADDRESS(x), \
3867 - .pfn = __phys_to_pfn(x), \
3868 - .length = sz, \
3869 - .type = MT_MEMORY_RWX, \
3870 -}
3871 -
3872 extern struct smp_operations ux500_smp_ops;
3873 extern void ux500_cpu_die(unsigned int cpu);
3874
3875 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3876 index 7eb94e6..799ad3e 100644
3877 --- a/arch/arm/mm/Kconfig
3878 +++ b/arch/arm/mm/Kconfig
3879 @@ -446,6 +446,7 @@ config CPU_32v5
3880
3881 config CPU_32v6
3882 bool
3883 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3884 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3885
3886 config CPU_32v6K
3887 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3888
3889 config CPU_USE_DOMAINS
3890 bool
3891 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3892 help
3893 This option enables or disables the use of domain switching
3894 via the set_fs() function.
3895 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3896
3897 config KUSER_HELPERS
3898 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3899 - depends on MMU
3900 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3901 default y
3902 help
3903 Warning: disabling this option may break user programs.
3904 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3905 See Documentation/arm/kernel_user_helpers.txt for details.
3906
3907 However, the fixed address nature of these helpers can be used
3908 - by ROP (return orientated programming) authors when creating
3909 + by ROP (Return Oriented Programming) authors when creating
3910 exploits.
3911
3912 If all of the binaries and libraries which run on your platform
3913 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3914 index 83792f4..c25d36b 100644
3915 --- a/arch/arm/mm/alignment.c
3916 +++ b/arch/arm/mm/alignment.c
3917 @@ -216,10 +216,12 @@ union offset_union {
3918 #define __get16_unaligned_check(ins,val,addr) \
3919 do { \
3920 unsigned int err = 0, v, a = addr; \
3921 + pax_open_userland(); \
3922 __get8_unaligned_check(ins,v,a,err); \
3923 val = v << ((BE) ? 8 : 0); \
3924 __get8_unaligned_check(ins,v,a,err); \
3925 val |= v << ((BE) ? 0 : 8); \
3926 + pax_close_userland(); \
3927 if (err) \
3928 goto fault; \
3929 } while (0)
3930 @@ -233,6 +235,7 @@ union offset_union {
3931 #define __get32_unaligned_check(ins,val,addr) \
3932 do { \
3933 unsigned int err = 0, v, a = addr; \
3934 + pax_open_userland(); \
3935 __get8_unaligned_check(ins,v,a,err); \
3936 val = v << ((BE) ? 24 : 0); \
3937 __get8_unaligned_check(ins,v,a,err); \
3938 @@ -241,6 +244,7 @@ union offset_union {
3939 val |= v << ((BE) ? 8 : 16); \
3940 __get8_unaligned_check(ins,v,a,err); \
3941 val |= v << ((BE) ? 0 : 24); \
3942 + pax_close_userland(); \
3943 if (err) \
3944 goto fault; \
3945 } while (0)
3946 @@ -254,6 +258,7 @@ union offset_union {
3947 #define __put16_unaligned_check(ins,val,addr) \
3948 do { \
3949 unsigned int err = 0, v = val, a = addr; \
3950 + pax_open_userland(); \
3951 __asm__( FIRST_BYTE_16 \
3952 ARM( "1: "ins" %1, [%2], #1\n" ) \
3953 THUMB( "1: "ins" %1, [%2]\n" ) \
3954 @@ -273,6 +278,7 @@ union offset_union {
3955 " .popsection\n" \
3956 : "=r" (err), "=&r" (v), "=&r" (a) \
3957 : "0" (err), "1" (v), "2" (a)); \
3958 + pax_close_userland(); \
3959 if (err) \
3960 goto fault; \
3961 } while (0)
3962 @@ -286,6 +292,7 @@ union offset_union {
3963 #define __put32_unaligned_check(ins,val,addr) \
3964 do { \
3965 unsigned int err = 0, v = val, a = addr; \
3966 + pax_open_userland(); \
3967 __asm__( FIRST_BYTE_32 \
3968 ARM( "1: "ins" %1, [%2], #1\n" ) \
3969 THUMB( "1: "ins" %1, [%2]\n" ) \
3970 @@ -315,6 +322,7 @@ union offset_union {
3971 " .popsection\n" \
3972 : "=r" (err), "=&r" (v), "=&r" (a) \
3973 : "0" (err), "1" (v), "2" (a)); \
3974 + pax_close_userland(); \
3975 if (err) \
3976 goto fault; \
3977 } while (0)
3978 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3979 index 5f2c988..221412d 100644
3980 --- a/arch/arm/mm/cache-l2x0.c
3981 +++ b/arch/arm/mm/cache-l2x0.c
3982 @@ -41,7 +41,7 @@ struct l2c_init_data {
3983 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3984 void (*save)(void __iomem *);
3985 struct outer_cache_fns outer_cache;
3986 -};
3987 +} __do_const;
3988
3989 #define CACHE_LINE_SIZE 32
3990
3991 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3992 index 6eb97b3..ac509f6 100644
3993 --- a/arch/arm/mm/context.c
3994 +++ b/arch/arm/mm/context.c
3995 @@ -43,7 +43,7 @@
3996 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3997
3998 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3999 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4000 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4001 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4002
4003 static DEFINE_PER_CPU(atomic64_t, active_asids);
4004 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4005 {
4006 static u32 cur_idx = 1;
4007 u64 asid = atomic64_read(&mm->context.id);
4008 - u64 generation = atomic64_read(&asid_generation);
4009 + u64 generation = atomic64_read_unchecked(&asid_generation);
4010
4011 if (asid != 0 && is_reserved_asid(asid)) {
4012 /*
4013 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4014 */
4015 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4016 if (asid == NUM_USER_ASIDS) {
4017 - generation = atomic64_add_return(ASID_FIRST_VERSION,
4018 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4019 &asid_generation);
4020 flush_context(cpu);
4021 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4022 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4023 cpu_set_reserved_ttbr0();
4024
4025 asid = atomic64_read(&mm->context.id);
4026 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4027 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4028 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4029 goto switch_mm_fastpath;
4030
4031 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4032 /* Check that our ASID belongs to the current generation. */
4033 asid = atomic64_read(&mm->context.id);
4034 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4035 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4036 asid = new_context(mm, cpu);
4037 atomic64_set(&mm->context.id, asid);
4038 }
4039 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4040 index eb8830a..e8ff52e 100644
4041 --- a/arch/arm/mm/fault.c
4042 +++ b/arch/arm/mm/fault.c
4043 @@ -25,6 +25,7 @@
4044 #include <asm/system_misc.h>
4045 #include <asm/system_info.h>
4046 #include <asm/tlbflush.h>
4047 +#include <asm/sections.h>
4048
4049 #include "fault.h"
4050
4051 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4052 if (fixup_exception(regs))
4053 return;
4054
4055 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4056 + if (addr < TASK_SIZE) {
4057 + if (current->signal->curr_ip)
4058 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4059 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4060 + else
4061 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4062 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4063 + }
4064 +#endif
4065 +
4066 +#ifdef CONFIG_PAX_KERNEXEC
4067 + if ((fsr & FSR_WRITE) &&
4068 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4069 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4070 + {
4071 + if (current->signal->curr_ip)
4072 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4073 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4074 + else
4075 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4076 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4077 + }
4078 +#endif
4079 +
4080 /*
4081 * No handler, we'll have to terminate things with extreme prejudice.
4082 */
4083 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4084 }
4085 #endif
4086
4087 +#ifdef CONFIG_PAX_PAGEEXEC
4088 + if (fsr & FSR_LNX_PF) {
4089 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4090 + do_group_exit(SIGKILL);
4091 + }
4092 +#endif
4093 +
4094 tsk->thread.address = addr;
4095 tsk->thread.error_code = fsr;
4096 tsk->thread.trap_no = 14;
4097 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4098 }
4099 #endif /* CONFIG_MMU */
4100
4101 +#ifdef CONFIG_PAX_PAGEEXEC
4102 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4103 +{
4104 + long i;
4105 +
4106 + printk(KERN_ERR "PAX: bytes at PC: ");
4107 + for (i = 0; i < 20; i++) {
4108 + unsigned char c;
4109 + if (get_user(c, (__force unsigned char __user *)pc+i))
4110 + printk(KERN_CONT "?? ");
4111 + else
4112 + printk(KERN_CONT "%02x ", c);
4113 + }
4114 + printk("\n");
4115 +
4116 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4117 + for (i = -1; i < 20; i++) {
4118 + unsigned long c;
4119 + if (get_user(c, (__force unsigned long __user *)sp+i))
4120 + printk(KERN_CONT "???????? ");
4121 + else
4122 + printk(KERN_CONT "%08lx ", c);
4123 + }
4124 + printk("\n");
4125 +}
4126 +#endif
4127 +
4128 /*
4129 * First Level Translation Fault Handler
4130 *
4131 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4132 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4133 struct siginfo info;
4134
4135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4136 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4137 + if (current->signal->curr_ip)
4138 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4139 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4140 + else
4141 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4142 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4143 + goto die;
4144 + }
4145 +#endif
4146 +
4147 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4148 return;
4149
4150 +die:
4151 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4152 inf->name, fsr, addr);
4153
4154 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4155 ifsr_info[nr].name = name;
4156 }
4157
4158 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4159 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4160 +
4161 asmlinkage void __exception
4162 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4163 {
4164 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4165 struct siginfo info;
4166 + unsigned long pc = instruction_pointer(regs);
4167 +
4168 + if (user_mode(regs)) {
4169 + unsigned long sigpage = current->mm->context.sigpage;
4170 +
4171 + if (sigpage <= pc && pc < sigpage + 7*4) {
4172 + if (pc < sigpage + 3*4)
4173 + sys_sigreturn(regs);
4174 + else
4175 + sys_rt_sigreturn(regs);
4176 + return;
4177 + }
4178 + if (pc == 0xffff0f60UL) {
4179 + /*
4180 + * PaX: __kuser_cmpxchg64 emulation
4181 + */
4182 + // TODO
4183 + //regs->ARM_pc = regs->ARM_lr;
4184 + //return;
4185 + }
4186 + if (pc == 0xffff0fa0UL) {
4187 + /*
4188 + * PaX: __kuser_memory_barrier emulation
4189 + */
4190 + // dmb(); implied by the exception
4191 + regs->ARM_pc = regs->ARM_lr;
4192 + return;
4193 + }
4194 + if (pc == 0xffff0fc0UL) {
4195 + /*
4196 + * PaX: __kuser_cmpxchg emulation
4197 + */
4198 + // TODO
4199 + //long new;
4200 + //int op;
4201 +
4202 + //op = FUTEX_OP_SET << 28;
4203 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4204 + //regs->ARM_r0 = old != new;
4205 + //regs->ARM_pc = regs->ARM_lr;
4206 + //return;
4207 + }
4208 + if (pc == 0xffff0fe0UL) {
4209 + /*
4210 + * PaX: __kuser_get_tls emulation
4211 + */
4212 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4213 + regs->ARM_pc = regs->ARM_lr;
4214 + return;
4215 + }
4216 + }
4217 +
4218 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4219 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4220 + if (current->signal->curr_ip)
4221 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4222 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4223 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4224 + else
4225 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4226 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4227 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4228 + goto die;
4229 + }
4230 +#endif
4231 +
4232 +#ifdef CONFIG_PAX_REFCOUNT
4233 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4234 +#ifdef CONFIG_THUMB2_KERNEL
4235 + unsigned short bkpt;
4236 +
4237 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4238 +#else
4239 + unsigned int bkpt;
4240 +
4241 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4242 +#endif
4243 + current->thread.error_code = ifsr;
4244 + current->thread.trap_no = 0;
4245 + pax_report_refcount_overflow(regs);
4246 + fixup_exception(regs);
4247 + return;
4248 + }
4249 + }
4250 +#endif
4251
4252 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4253 return;
4254
4255 +die:
4256 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4257 inf->name, ifsr, addr);
4258
4259 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4260 index cf08bdf..772656c 100644
4261 --- a/arch/arm/mm/fault.h
4262 +++ b/arch/arm/mm/fault.h
4263 @@ -3,6 +3,7 @@
4264
4265 /*
4266 * Fault status register encodings. We steal bit 31 for our own purposes.
4267 + * Set when the FSR value is from an instruction fault.
4268 */
4269 #define FSR_LNX_PF (1 << 31)
4270 #define FSR_WRITE (1 << 11)
4271 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4272 }
4273 #endif
4274
4275 +/* valid for LPAE and !LPAE */
4276 +static inline int is_xn_fault(unsigned int fsr)
4277 +{
4278 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4279 +}
4280 +
4281 +static inline int is_domain_fault(unsigned int fsr)
4282 +{
4283 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4284 +}
4285 +
4286 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4287 unsigned long search_exception_table(unsigned long addr);
4288
4289 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4290 index 659c75d..6f8c029 100644
4291 --- a/arch/arm/mm/init.c
4292 +++ b/arch/arm/mm/init.c
4293 @@ -31,6 +31,8 @@
4294 #include <asm/setup.h>
4295 #include <asm/tlb.h>
4296 #include <asm/fixmap.h>
4297 +#include <asm/system_info.h>
4298 +#include <asm/cp15.h>
4299
4300 #include <asm/mach/arch.h>
4301 #include <asm/mach/map.h>
4302 @@ -619,7 +621,46 @@ void free_initmem(void)
4303 {
4304 #ifdef CONFIG_HAVE_TCM
4305 extern char __tcm_start, __tcm_end;
4306 +#endif
4307
4308 +#ifdef CONFIG_PAX_KERNEXEC
4309 + unsigned long addr;
4310 + pgd_t *pgd;
4311 + pud_t *pud;
4312 + pmd_t *pmd;
4313 + int cpu_arch = cpu_architecture();
4314 + unsigned int cr = get_cr();
4315 +
4316 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4317 + /* make pages tables, etc before .text NX */
4318 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4319 + pgd = pgd_offset_k(addr);
4320 + pud = pud_offset(pgd, addr);
4321 + pmd = pmd_offset(pud, addr);
4322 + __section_update(pmd, addr, PMD_SECT_XN);
4323 + }
4324 + /* make init NX */
4325 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4326 + pgd = pgd_offset_k(addr);
4327 + pud = pud_offset(pgd, addr);
4328 + pmd = pmd_offset(pud, addr);
4329 + __section_update(pmd, addr, PMD_SECT_XN);
4330 + }
4331 + /* make kernel code/rodata RX */
4332 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4333 + pgd = pgd_offset_k(addr);
4334 + pud = pud_offset(pgd, addr);
4335 + pmd = pmd_offset(pud, addr);
4336 +#ifdef CONFIG_ARM_LPAE
4337 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4338 +#else
4339 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4340 +#endif
4341 + }
4342 + }
4343 +#endif
4344 +
4345 +#ifdef CONFIG_HAVE_TCM
4346 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4347 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4348 #endif
4349 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4350 index d1e5ad7..84dcbf2 100644
4351 --- a/arch/arm/mm/ioremap.c
4352 +++ b/arch/arm/mm/ioremap.c
4353 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4354 unsigned int mtype;
4355
4356 if (cached)
4357 - mtype = MT_MEMORY_RWX;
4358 + mtype = MT_MEMORY_RX;
4359 else
4360 - mtype = MT_MEMORY_RWX_NONCACHED;
4361 + mtype = MT_MEMORY_RX_NONCACHED;
4362
4363 return __arm_ioremap_caller(phys_addr, size, mtype,
4364 __builtin_return_address(0));
4365 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4366 index 5e85ed3..b10a7ed 100644
4367 --- a/arch/arm/mm/mmap.c
4368 +++ b/arch/arm/mm/mmap.c
4369 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4370 struct vm_area_struct *vma;
4371 int do_align = 0;
4372 int aliasing = cache_is_vipt_aliasing();
4373 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4374 struct vm_unmapped_area_info info;
4375
4376 /*
4377 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4378 if (len > TASK_SIZE)
4379 return -ENOMEM;
4380
4381 +#ifdef CONFIG_PAX_RANDMMAP
4382 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4383 +#endif
4384 +
4385 if (addr) {
4386 if (do_align)
4387 addr = COLOUR_ALIGN(addr, pgoff);
4388 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4389 addr = PAGE_ALIGN(addr);
4390
4391 vma = find_vma(mm, addr);
4392 - if (TASK_SIZE - len >= addr &&
4393 - (!vma || addr + len <= vma->vm_start))
4394 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4395 return addr;
4396 }
4397
4398 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4399 info.high_limit = TASK_SIZE;
4400 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4401 info.align_offset = pgoff << PAGE_SHIFT;
4402 + info.threadstack_offset = offset;
4403 return vm_unmapped_area(&info);
4404 }
4405
4406 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4407 unsigned long addr = addr0;
4408 int do_align = 0;
4409 int aliasing = cache_is_vipt_aliasing();
4410 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4411 struct vm_unmapped_area_info info;
4412
4413 /*
4414 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4415 return addr;
4416 }
4417
4418 +#ifdef CONFIG_PAX_RANDMMAP
4419 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4420 +#endif
4421 +
4422 /* requesting a specific address */
4423 if (addr) {
4424 if (do_align)
4425 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4426 else
4427 addr = PAGE_ALIGN(addr);
4428 vma = find_vma(mm, addr);
4429 - if (TASK_SIZE - len >= addr &&
4430 - (!vma || addr + len <= vma->vm_start))
4431 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4432 return addr;
4433 }
4434
4435 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4436 info.high_limit = mm->mmap_base;
4437 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4438 info.align_offset = pgoff << PAGE_SHIFT;
4439 + info.threadstack_offset = offset;
4440 addr = vm_unmapped_area(&info);
4441
4442 /*
4443 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4444 {
4445 unsigned long random_factor = 0UL;
4446
4447 +#ifdef CONFIG_PAX_RANDMMAP
4448 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4449 +#endif
4450 +
4451 /* 8 bits of randomness in 20 address space bits */
4452 if ((current->flags & PF_RANDOMIZE) &&
4453 !(current->personality & ADDR_NO_RANDOMIZE))
4454 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4455
4456 if (mmap_is_legacy()) {
4457 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4458 +
4459 +#ifdef CONFIG_PAX_RANDMMAP
4460 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4461 + mm->mmap_base += mm->delta_mmap;
4462 +#endif
4463 +
4464 mm->get_unmapped_area = arch_get_unmapped_area;
4465 } else {
4466 mm->mmap_base = mmap_base(random_factor);
4467 +
4468 +#ifdef CONFIG_PAX_RANDMMAP
4469 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4470 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4471 +#endif
4472 +
4473 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4474 }
4475 }
4476 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4477 index 8348ed6..b73a807 100644
4478 --- a/arch/arm/mm/mmu.c
4479 +++ b/arch/arm/mm/mmu.c
4480 @@ -40,6 +40,22 @@
4481 #include "mm.h"
4482 #include "tcm.h"
4483
4484 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4485 +void modify_domain(unsigned int dom, unsigned int type)
4486 +{
4487 + struct thread_info *thread = current_thread_info();
4488 + unsigned int domain = thread->cpu_domain;
4489 + /*
4490 + * DOMAIN_MANAGER might be defined to some other value,
4491 + * use the arch-defined constant
4492 + */
4493 + domain &= ~domain_val(dom, 3);
4494 + thread->cpu_domain = domain | domain_val(dom, type);
4495 + set_domain(thread->cpu_domain);
4496 +}
4497 +EXPORT_SYMBOL(modify_domain);
4498 +#endif
4499 +
4500 /*
4501 * empty_zero_page is a special page that is used for
4502 * zero-initialized data and COW.
4503 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4504 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4505 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4506
4507 -static struct mem_type mem_types[] = {
4508 +#ifdef CONFIG_PAX_KERNEXEC
4509 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4510 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4511 +#else
4512 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4513 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4514 +#endif
4515 +
4516 +static struct mem_type mem_types[] __read_only = {
4517 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4518 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4519 L_PTE_SHARED,
4520 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4521 .prot_sect = PROT_SECT_DEVICE,
4522 .domain = DOMAIN_IO,
4523 },
4524 - [MT_UNCACHED] = {
4525 + [MT_UNCACHED_RW] = {
4526 .prot_pte = PROT_PTE_DEVICE,
4527 .prot_l1 = PMD_TYPE_TABLE,
4528 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4529 .domain = DOMAIN_IO,
4530 },
4531 - [MT_CACHECLEAN] = {
4532 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4533 + [MT_CACHECLEAN_RO] = {
4534 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4535 .domain = DOMAIN_KERNEL,
4536 },
4537 #ifndef CONFIG_ARM_LPAE
4538 - [MT_MINICLEAN] = {
4539 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4540 + [MT_MINICLEAN_RO] = {
4541 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4542 .domain = DOMAIN_KERNEL,
4543 },
4544 #endif
4545 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4546 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4547 L_PTE_RDONLY,
4548 .prot_l1 = PMD_TYPE_TABLE,
4549 - .domain = DOMAIN_USER,
4550 + .domain = DOMAIN_VECTORS,
4551 },
4552 [MT_HIGH_VECTORS] = {
4553 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4554 L_PTE_USER | L_PTE_RDONLY,
4555 .prot_l1 = PMD_TYPE_TABLE,
4556 - .domain = DOMAIN_USER,
4557 + .domain = DOMAIN_VECTORS,
4558 },
4559 - [MT_MEMORY_RWX] = {
4560 + [__MT_MEMORY_RWX] = {
4561 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4562 .prot_l1 = PMD_TYPE_TABLE,
4563 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4564 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4565 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4566 .domain = DOMAIN_KERNEL,
4567 },
4568 - [MT_ROM] = {
4569 - .prot_sect = PMD_TYPE_SECT,
4570 + [MT_MEMORY_RX] = {
4571 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4572 + .prot_l1 = PMD_TYPE_TABLE,
4573 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4574 + .domain = DOMAIN_KERNEL,
4575 + },
4576 + [MT_ROM_RX] = {
4577 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4578 .domain = DOMAIN_KERNEL,
4579 },
4580 - [MT_MEMORY_RWX_NONCACHED] = {
4581 + [MT_MEMORY_RW_NONCACHED] = {
4582 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4583 L_PTE_MT_BUFFERABLE,
4584 .prot_l1 = PMD_TYPE_TABLE,
4585 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4586 .domain = DOMAIN_KERNEL,
4587 },
4588 + [MT_MEMORY_RX_NONCACHED] = {
4589 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4590 + L_PTE_MT_BUFFERABLE,
4591 + .prot_l1 = PMD_TYPE_TABLE,
4592 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4593 + .domain = DOMAIN_KERNEL,
4594 + },
4595 [MT_MEMORY_RW_DTCM] = {
4596 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4597 L_PTE_XN,
4598 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4599 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4600 .domain = DOMAIN_KERNEL,
4601 },
4602 - [MT_MEMORY_RWX_ITCM] = {
4603 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4604 + [MT_MEMORY_RX_ITCM] = {
4605 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4606 .prot_l1 = PMD_TYPE_TABLE,
4607 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4608 .domain = DOMAIN_KERNEL,
4609 },
4610 [MT_MEMORY_RW_SO] = {
4611 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4612 * Mark cache clean areas and XIP ROM read only
4613 * from SVC mode and no access from userspace.
4614 */
4615 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4616 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4617 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4618 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4619 +#ifdef CONFIG_PAX_KERNEXEC
4620 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4621 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4622 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4623 +#endif
4624 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4625 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4626 #endif
4627
4628 /*
4629 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4630 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4631 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4632 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4633 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4634 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4635 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4636 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4637 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4638 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4639 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4640 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4641 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4642 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4643 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4644 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4645 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4646 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4647 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4648 }
4649 }
4650
4651 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4652 if (cpu_arch >= CPU_ARCH_ARMv6) {
4653 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4654 /* Non-cacheable Normal is XCB = 001 */
4655 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4656 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4657 + PMD_SECT_BUFFERED;
4658 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4659 PMD_SECT_BUFFERED;
4660 } else {
4661 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4662 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4663 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4664 + PMD_SECT_TEX(1);
4665 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4666 PMD_SECT_TEX(1);
4667 }
4668 } else {
4669 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4670 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4671 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4672 }
4673
4674 #ifdef CONFIG_ARM_LPAE
4675 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4676 vecs_pgprot |= PTE_EXT_AF;
4677 #endif
4678
4679 + user_pgprot |= __supported_pte_mask;
4680 +
4681 for (i = 0; i < 16; i++) {
4682 pteval_t v = pgprot_val(protection_map[i]);
4683 protection_map[i] = __pgprot(v | user_pgprot);
4684 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4685
4686 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4687 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4688 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4689 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4690 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4691 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4692 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4693 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4694 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4695 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4696 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4697 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4698 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4699 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4700 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4701 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4702
4703 switch (cp->pmd) {
4704 case PMD_SECT_WT:
4705 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4706 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4707 break;
4708 case PMD_SECT_WB:
4709 case PMD_SECT_WBWA:
4710 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4711 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4712 break;
4713 }
4714 pr_info("Memory policy: %sData cache %s\n",
4715 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4716 return;
4717 }
4718
4719 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4720 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4721 md->virtual >= PAGE_OFFSET &&
4722 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4723 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4724 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4725 * called function. This means you can't use any function or debugging
4726 * method which may touch any device, otherwise the kernel _will_ crash.
4727 */
4728 +
4729 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4730 +
4731 static void __init devicemaps_init(const struct machine_desc *mdesc)
4732 {
4733 struct map_desc map;
4734 unsigned long addr;
4735 - void *vectors;
4736
4737 - /*
4738 - * Allocate the vector page early.
4739 - */
4740 - vectors = early_alloc(PAGE_SIZE * 2);
4741 -
4742 - early_trap_init(vectors);
4743 + early_trap_init(&vectors);
4744
4745 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4746 pmd_clear(pmd_off_k(addr));
4747 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4748 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4749 map.virtual = MODULES_VADDR;
4750 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4751 - map.type = MT_ROM;
4752 + map.type = MT_ROM_RX;
4753 create_mapping(&map);
4754 #endif
4755
4756 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4757 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4758 map.virtual = FLUSH_BASE;
4759 map.length = SZ_1M;
4760 - map.type = MT_CACHECLEAN;
4761 + map.type = MT_CACHECLEAN_RO;
4762 create_mapping(&map);
4763 #endif
4764 #ifdef FLUSH_BASE_MINICACHE
4765 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4766 map.virtual = FLUSH_BASE_MINICACHE;
4767 map.length = SZ_1M;
4768 - map.type = MT_MINICLEAN;
4769 + map.type = MT_MINICLEAN_RO;
4770 create_mapping(&map);
4771 #endif
4772
4773 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4774 * location (0xffff0000). If we aren't using high-vectors, also
4775 * create a mapping at the low-vectors virtual address.
4776 */
4777 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4778 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4779 map.virtual = 0xffff0000;
4780 map.length = PAGE_SIZE;
4781 #ifdef CONFIG_KUSER_HELPERS
4782 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4783 static void __init map_lowmem(void)
4784 {
4785 struct memblock_region *reg;
4786 +#ifndef CONFIG_PAX_KERNEXEC
4787 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4788 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4789 +#endif
4790
4791 /* Map all the lowmem memory banks. */
4792 for_each_memblock(memory, reg) {
4793 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4794 if (start >= end)
4795 break;
4796
4797 +#ifdef CONFIG_PAX_KERNEXEC
4798 + map.pfn = __phys_to_pfn(start);
4799 + map.virtual = __phys_to_virt(start);
4800 + map.length = end - start;
4801 +
4802 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4803 + struct map_desc kernel;
4804 + struct map_desc initmap;
4805 +
4806 + /* when freeing initmem we will make this RW */
4807 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4808 + initmap.virtual = (unsigned long)__init_begin;
4809 + initmap.length = _sdata - __init_begin;
4810 + initmap.type = __MT_MEMORY_RWX;
4811 + create_mapping(&initmap);
4812 +
4813 + /* when freeing initmem we will make this RX */
4814 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4815 + kernel.virtual = (unsigned long)_stext;
4816 + kernel.length = __init_begin - _stext;
4817 + kernel.type = __MT_MEMORY_RWX;
4818 + create_mapping(&kernel);
4819 +
4820 + if (map.virtual < (unsigned long)_stext) {
4821 + map.length = (unsigned long)_stext - map.virtual;
4822 + map.type = __MT_MEMORY_RWX;
4823 + create_mapping(&map);
4824 + }
4825 +
4826 + map.pfn = __phys_to_pfn(__pa(_sdata));
4827 + map.virtual = (unsigned long)_sdata;
4828 + map.length = end - __pa(_sdata);
4829 + }
4830 +
4831 + map.type = MT_MEMORY_RW;
4832 + create_mapping(&map);
4833 +#else
4834 if (end < kernel_x_start || start >= kernel_x_end) {
4835 map.pfn = __phys_to_pfn(start);
4836 map.virtual = __phys_to_virt(start);
4837 map.length = end - start;
4838 - map.type = MT_MEMORY_RWX;
4839 + map.type = __MT_MEMORY_RWX;
4840
4841 create_mapping(&map);
4842 } else {
4843 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4844 map.pfn = __phys_to_pfn(kernel_x_start);
4845 map.virtual = __phys_to_virt(kernel_x_start);
4846 map.length = kernel_x_end - kernel_x_start;
4847 - map.type = MT_MEMORY_RWX;
4848 + map.type = __MT_MEMORY_RWX;
4849
4850 create_mapping(&map);
4851
4852 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4853 create_mapping(&map);
4854 }
4855 }
4856 +#endif
4857 }
4858 }
4859
4860 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4861 index a37b989..5c9ae75 100644
4862 --- a/arch/arm/net/bpf_jit_32.c
4863 +++ b/arch/arm/net/bpf_jit_32.c
4864 @@ -71,7 +71,11 @@ struct jit_ctx {
4865 #endif
4866 };
4867
4868 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4869 +int bpf_jit_enable __read_only;
4870 +#else
4871 int bpf_jit_enable __read_mostly;
4872 +#endif
4873
4874 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4875 {
4876 @@ -930,5 +934,6 @@ void bpf_jit_free(struct bpf_prog *fp)
4877 {
4878 if (fp->jited)
4879 module_free(NULL, fp->bpf_func);
4880 - kfree(fp);
4881 +
4882 + bpf_prog_unlock_free(fp);
4883 }
4884 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4885 index 5b217f4..c23f40e 100644
4886 --- a/arch/arm/plat-iop/setup.c
4887 +++ b/arch/arm/plat-iop/setup.c
4888 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4889 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4890 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4891 .length = IOP3XX_PERIPHERAL_SIZE,
4892 - .type = MT_UNCACHED,
4893 + .type = MT_UNCACHED_RW,
4894 },
4895 };
4896
4897 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4898 index a5bc92d..0bb4730 100644
4899 --- a/arch/arm/plat-omap/sram.c
4900 +++ b/arch/arm/plat-omap/sram.c
4901 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4902 * Looks like we need to preserve some bootloader code at the
4903 * beginning of SRAM for jumping to flash for reboot to work...
4904 */
4905 + pax_open_kernel();
4906 memset_io(omap_sram_base + omap_sram_skip, 0,
4907 omap_sram_size - omap_sram_skip);
4908 + pax_close_kernel();
4909 }
4910 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4911 index ce6d763..cfea917 100644
4912 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4913 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4914 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4915 int (*started)(unsigned ch);
4916 int (*flush)(unsigned ch);
4917 int (*stop)(unsigned ch);
4918 -};
4919 +} __no_const;
4920
4921 extern void *samsung_dmadev_get_ops(void);
4922 extern void *s3c_dma_get_ops(void);
4923 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4924 index 6389d60..b5d3bdd 100644
4925 --- a/arch/arm64/include/asm/barrier.h
4926 +++ b/arch/arm64/include/asm/barrier.h
4927 @@ -41,7 +41,7 @@
4928 do { \
4929 compiletime_assert_atomic_type(*p); \
4930 barrier(); \
4931 - ACCESS_ONCE(*p) = (v); \
4932 + ACCESS_ONCE_RW(*p) = (v); \
4933 } while (0)
4934
4935 #define smp_load_acquire(p) \
4936 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4937 index 3bf8f4e..5dd5491 100644
4938 --- a/arch/arm64/include/asm/uaccess.h
4939 +++ b/arch/arm64/include/asm/uaccess.h
4940 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4941 flag; \
4942 })
4943
4944 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4945 #define access_ok(type, addr, size) __range_ok(addr, size)
4946 #define user_addr_max get_fs
4947
4948 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4949 index c3a58a1..78fbf54 100644
4950 --- a/arch/avr32/include/asm/cache.h
4951 +++ b/arch/avr32/include/asm/cache.h
4952 @@ -1,8 +1,10 @@
4953 #ifndef __ASM_AVR32_CACHE_H
4954 #define __ASM_AVR32_CACHE_H
4955
4956 +#include <linux/const.h>
4957 +
4958 #define L1_CACHE_SHIFT 5
4959 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4960 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 /*
4963 * Memory returned by kmalloc() may be used for DMA, so we must make
4964 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4965 index d232888..87c8df1 100644
4966 --- a/arch/avr32/include/asm/elf.h
4967 +++ b/arch/avr32/include/asm/elf.h
4968 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4969 the loader. We need to make sure that it is out of the way of the program
4970 that it will "exec", and that there is sufficient room for the brk. */
4971
4972 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4973 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4974
4975 +#ifdef CONFIG_PAX_ASLR
4976 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4977 +
4978 +#define PAX_DELTA_MMAP_LEN 15
4979 +#define PAX_DELTA_STACK_LEN 15
4980 +#endif
4981
4982 /* This yields a mask that user programs can use to figure out what
4983 instruction set this CPU supports. This could be done in user space,
4984 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4985 index 479330b..53717a8 100644
4986 --- a/arch/avr32/include/asm/kmap_types.h
4987 +++ b/arch/avr32/include/asm/kmap_types.h
4988 @@ -2,9 +2,9 @@
4989 #define __ASM_AVR32_KMAP_TYPES_H
4990
4991 #ifdef CONFIG_DEBUG_HIGHMEM
4992 -# define KM_TYPE_NR 29
4993 +# define KM_TYPE_NR 30
4994 #else
4995 -# define KM_TYPE_NR 14
4996 +# define KM_TYPE_NR 15
4997 #endif
4998
4999 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5000 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5001 index 0eca933..eb78c7b 100644
5002 --- a/arch/avr32/mm/fault.c
5003 +++ b/arch/avr32/mm/fault.c
5004 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5005
5006 int exception_trace = 1;
5007
5008 +#ifdef CONFIG_PAX_PAGEEXEC
5009 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5010 +{
5011 + unsigned long i;
5012 +
5013 + printk(KERN_ERR "PAX: bytes at PC: ");
5014 + for (i = 0; i < 20; i++) {
5015 + unsigned char c;
5016 + if (get_user(c, (unsigned char *)pc+i))
5017 + printk(KERN_CONT "???????? ");
5018 + else
5019 + printk(KERN_CONT "%02x ", c);
5020 + }
5021 + printk("\n");
5022 +}
5023 +#endif
5024 +
5025 /*
5026 * This routine handles page faults. It determines the address and the
5027 * problem, and then passes it off to one of the appropriate routines.
5028 @@ -176,6 +193,16 @@ bad_area:
5029 up_read(&mm->mmap_sem);
5030
5031 if (user_mode(regs)) {
5032 +
5033 +#ifdef CONFIG_PAX_PAGEEXEC
5034 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5035 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5036 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5037 + do_group_exit(SIGKILL);
5038 + }
5039 + }
5040 +#endif
5041 +
5042 if (exception_trace && printk_ratelimit())
5043 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5044 "sp %08lx ecr %lu\n",
5045 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5046 index 568885a..f8008df 100644
5047 --- a/arch/blackfin/include/asm/cache.h
5048 +++ b/arch/blackfin/include/asm/cache.h
5049 @@ -7,6 +7,7 @@
5050 #ifndef __ARCH_BLACKFIN_CACHE_H
5051 #define __ARCH_BLACKFIN_CACHE_H
5052
5053 +#include <linux/const.h>
5054 #include <linux/linkage.h> /* for asmlinkage */
5055
5056 /*
5057 @@ -14,7 +15,7 @@
5058 * Blackfin loads 32 bytes for cache
5059 */
5060 #define L1_CACHE_SHIFT 5
5061 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5062 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5063 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5064
5065 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5066 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5067 index aea2718..3639a60 100644
5068 --- a/arch/cris/include/arch-v10/arch/cache.h
5069 +++ b/arch/cris/include/arch-v10/arch/cache.h
5070 @@ -1,8 +1,9 @@
5071 #ifndef _ASM_ARCH_CACHE_H
5072 #define _ASM_ARCH_CACHE_H
5073
5074 +#include <linux/const.h>
5075 /* Etrax 100LX have 32-byte cache-lines. */
5076 -#define L1_CACHE_BYTES 32
5077 #define L1_CACHE_SHIFT 5
5078 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5079
5080 #endif /* _ASM_ARCH_CACHE_H */
5081 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5082 index 7caf25d..ee65ac5 100644
5083 --- a/arch/cris/include/arch-v32/arch/cache.h
5084 +++ b/arch/cris/include/arch-v32/arch/cache.h
5085 @@ -1,11 +1,12 @@
5086 #ifndef _ASM_CRIS_ARCH_CACHE_H
5087 #define _ASM_CRIS_ARCH_CACHE_H
5088
5089 +#include <linux/const.h>
5090 #include <arch/hwregs/dma.h>
5091
5092 /* A cache-line is 32 bytes. */
5093 -#define L1_CACHE_BYTES 32
5094 #define L1_CACHE_SHIFT 5
5095 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5096
5097 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5098
5099 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5100 index f6c3a16..cd422a4 100644
5101 --- a/arch/frv/include/asm/atomic.h
5102 +++ b/arch/frv/include/asm/atomic.h
5103 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5104 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5105 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5106
5107 +#define atomic64_read_unchecked(v) atomic64_read(v)
5108 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5109 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5110 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5111 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5112 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5113 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5114 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5115 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5116 +
5117 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5118 {
5119 int c, old;
5120 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5121 index 2797163..c2a401df9 100644
5122 --- a/arch/frv/include/asm/cache.h
5123 +++ b/arch/frv/include/asm/cache.h
5124 @@ -12,10 +12,11 @@
5125 #ifndef __ASM_CACHE_H
5126 #define __ASM_CACHE_H
5127
5128 +#include <linux/const.h>
5129
5130 /* bytes per L1 cache line */
5131 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5132 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5133 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5134
5135 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5136 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5137 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5138 index 43901f2..0d8b865 100644
5139 --- a/arch/frv/include/asm/kmap_types.h
5140 +++ b/arch/frv/include/asm/kmap_types.h
5141 @@ -2,6 +2,6 @@
5142 #ifndef _ASM_KMAP_TYPES_H
5143 #define _ASM_KMAP_TYPES_H
5144
5145 -#define KM_TYPE_NR 17
5146 +#define KM_TYPE_NR 18
5147
5148 #endif
5149 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5150 index 836f147..4cf23f5 100644
5151 --- a/arch/frv/mm/elf-fdpic.c
5152 +++ b/arch/frv/mm/elf-fdpic.c
5153 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5154 {
5155 struct vm_area_struct *vma;
5156 struct vm_unmapped_area_info info;
5157 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5158
5159 if (len > TASK_SIZE)
5160 return -ENOMEM;
5161 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5162 if (addr) {
5163 addr = PAGE_ALIGN(addr);
5164 vma = find_vma(current->mm, addr);
5165 - if (TASK_SIZE - len >= addr &&
5166 - (!vma || addr + len <= vma->vm_start))
5167 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5168 goto success;
5169 }
5170
5171 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5172 info.high_limit = (current->mm->start_stack - 0x00200000);
5173 info.align_mask = 0;
5174 info.align_offset = 0;
5175 + info.threadstack_offset = offset;
5176 addr = vm_unmapped_area(&info);
5177 if (!(addr & ~PAGE_MASK))
5178 goto success;
5179 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5180 index 2635117..fa223cb 100644
5181 --- a/arch/hexagon/include/asm/cache.h
5182 +++ b/arch/hexagon/include/asm/cache.h
5183 @@ -21,9 +21,11 @@
5184 #ifndef __ASM_CACHE_H
5185 #define __ASM_CACHE_H
5186
5187 +#include <linux/const.h>
5188 +
5189 /* Bytes per L1 cache line */
5190 -#define L1_CACHE_SHIFT (5)
5191 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5192 +#define L1_CACHE_SHIFT 5
5193 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5194
5195 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5196 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5197 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5198 index c84c88b..2a6e1ba 100644
5199 --- a/arch/ia64/Kconfig
5200 +++ b/arch/ia64/Kconfig
5201 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5202 config KEXEC
5203 bool "kexec system call"
5204 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5205 + depends on !GRKERNSEC_KMEM
5206 help
5207 kexec is a system call that implements the ability to shutdown your
5208 current kernel, and to start another kernel. It is like a reboot
5209 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5210 index 5441b14..039a446 100644
5211 --- a/arch/ia64/Makefile
5212 +++ b/arch/ia64/Makefile
5213 @@ -99,5 +99,6 @@ endef
5214 archprepare: make_nr_irqs_h FORCE
5215 PHONY += make_nr_irqs_h FORCE
5216
5217 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5218 make_nr_irqs_h: FORCE
5219 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5220 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5221 index 0f8bf48..40ea950 100644
5222 --- a/arch/ia64/include/asm/atomic.h
5223 +++ b/arch/ia64/include/asm/atomic.h
5224 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5225 #define atomic64_inc(v) atomic64_add(1, (v))
5226 #define atomic64_dec(v) atomic64_sub(1, (v))
5227
5228 +#define atomic64_read_unchecked(v) atomic64_read(v)
5229 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5230 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5231 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5232 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5233 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5234 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5235 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5236 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5237 +
5238 #endif /* _ASM_IA64_ATOMIC_H */
5239 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5240 index a48957c..e097b56 100644
5241 --- a/arch/ia64/include/asm/barrier.h
5242 +++ b/arch/ia64/include/asm/barrier.h
5243 @@ -67,7 +67,7 @@
5244 do { \
5245 compiletime_assert_atomic_type(*p); \
5246 barrier(); \
5247 - ACCESS_ONCE(*p) = (v); \
5248 + ACCESS_ONCE_RW(*p) = (v); \
5249 } while (0)
5250
5251 #define smp_load_acquire(p) \
5252 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5253 index 988254a..e1ee885 100644
5254 --- a/arch/ia64/include/asm/cache.h
5255 +++ b/arch/ia64/include/asm/cache.h
5256 @@ -1,6 +1,7 @@
5257 #ifndef _ASM_IA64_CACHE_H
5258 #define _ASM_IA64_CACHE_H
5259
5260 +#include <linux/const.h>
5261
5262 /*
5263 * Copyright (C) 1998-2000 Hewlett-Packard Co
5264 @@ -9,7 +10,7 @@
5265
5266 /* Bytes per L1 (data) cache line. */
5267 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5268 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5269 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5270
5271 #ifdef CONFIG_SMP
5272 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5273 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5274 index 5a83c5c..4d7f553 100644
5275 --- a/arch/ia64/include/asm/elf.h
5276 +++ b/arch/ia64/include/asm/elf.h
5277 @@ -42,6 +42,13 @@
5278 */
5279 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5280
5281 +#ifdef CONFIG_PAX_ASLR
5282 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5283 +
5284 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5285 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5286 +#endif
5287 +
5288 #define PT_IA_64_UNWIND 0x70000001
5289
5290 /* IA-64 relocations: */
5291 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5292 index 5767cdf..7462574 100644
5293 --- a/arch/ia64/include/asm/pgalloc.h
5294 +++ b/arch/ia64/include/asm/pgalloc.h
5295 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5296 pgd_val(*pgd_entry) = __pa(pud);
5297 }
5298
5299 +static inline void
5300 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5301 +{
5302 + pgd_populate(mm, pgd_entry, pud);
5303 +}
5304 +
5305 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5306 {
5307 return quicklist_alloc(0, GFP_KERNEL, NULL);
5308 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5309 pud_val(*pud_entry) = __pa(pmd);
5310 }
5311
5312 +static inline void
5313 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5314 +{
5315 + pud_populate(mm, pud_entry, pmd);
5316 +}
5317 +
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5319 {
5320 return quicklist_alloc(0, GFP_KERNEL, NULL);
5321 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5322 index 7935115..c0eca6a 100644
5323 --- a/arch/ia64/include/asm/pgtable.h
5324 +++ b/arch/ia64/include/asm/pgtable.h
5325 @@ -12,7 +12,7 @@
5326 * David Mosberger-Tang <davidm@hpl.hp.com>
5327 */
5328
5329 -
5330 +#include <linux/const.h>
5331 #include <asm/mman.h>
5332 #include <asm/page.h>
5333 #include <asm/processor.h>
5334 @@ -142,6 +142,17 @@
5335 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5336 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5337 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5338 +
5339 +#ifdef CONFIG_PAX_PAGEEXEC
5340 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5341 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5342 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5343 +#else
5344 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5345 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5346 +# define PAGE_COPY_NOEXEC PAGE_COPY
5347 +#endif
5348 +
5349 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5350 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5351 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5352 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5353 index 45698cd..e8e2dbc 100644
5354 --- a/arch/ia64/include/asm/spinlock.h
5355 +++ b/arch/ia64/include/asm/spinlock.h
5356 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5357 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5358
5359 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5360 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5361 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5362 }
5363
5364 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5365 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5366 index 449c8c0..3d4b1e9 100644
5367 --- a/arch/ia64/include/asm/uaccess.h
5368 +++ b/arch/ia64/include/asm/uaccess.h
5369 @@ -70,6 +70,7 @@
5370 && ((segment).seg == KERNEL_DS.seg \
5371 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5372 })
5373 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5374 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5375
5376 /*
5377 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5378 static inline unsigned long
5379 __copy_to_user (void __user *to, const void *from, unsigned long count)
5380 {
5381 + if (count > INT_MAX)
5382 + return count;
5383 +
5384 + if (!__builtin_constant_p(count))
5385 + check_object_size(from, count, true);
5386 +
5387 return __copy_user(to, (__force void __user *) from, count);
5388 }
5389
5390 static inline unsigned long
5391 __copy_from_user (void *to, const void __user *from, unsigned long count)
5392 {
5393 + if (count > INT_MAX)
5394 + return count;
5395 +
5396 + if (!__builtin_constant_p(count))
5397 + check_object_size(to, count, false);
5398 +
5399 return __copy_user((__force void __user *) to, from, count);
5400 }
5401
5402 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5403 ({ \
5404 void __user *__cu_to = (to); \
5405 const void *__cu_from = (from); \
5406 - long __cu_len = (n); \
5407 + unsigned long __cu_len = (n); \
5408 \
5409 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5410 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5411 + if (!__builtin_constant_p(n)) \
5412 + check_object_size(__cu_from, __cu_len, true); \
5413 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5414 + } \
5415 __cu_len; \
5416 })
5417
5418 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5419 ({ \
5420 void *__cu_to = (to); \
5421 const void __user *__cu_from = (from); \
5422 - long __cu_len = (n); \
5423 + unsigned long __cu_len = (n); \
5424 \
5425 __chk_user_ptr(__cu_from); \
5426 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5427 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5428 + if (!__builtin_constant_p(n)) \
5429 + check_object_size(__cu_to, __cu_len, false); \
5430 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5431 + } \
5432 __cu_len; \
5433 })
5434
5435 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5436 index 24603be..948052d 100644
5437 --- a/arch/ia64/kernel/module.c
5438 +++ b/arch/ia64/kernel/module.c
5439 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5440 void
5441 module_free (struct module *mod, void *module_region)
5442 {
5443 - if (mod && mod->arch.init_unw_table &&
5444 - module_region == mod->module_init) {
5445 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5446 unw_remove_unwind_table(mod->arch.init_unw_table);
5447 mod->arch.init_unw_table = NULL;
5448 }
5449 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5450 }
5451
5452 static inline int
5453 +in_init_rx (const struct module *mod, uint64_t addr)
5454 +{
5455 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5456 +}
5457 +
5458 +static inline int
5459 +in_init_rw (const struct module *mod, uint64_t addr)
5460 +{
5461 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5462 +}
5463 +
5464 +static inline int
5465 in_init (const struct module *mod, uint64_t addr)
5466 {
5467 - return addr - (uint64_t) mod->module_init < mod->init_size;
5468 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5469 +}
5470 +
5471 +static inline int
5472 +in_core_rx (const struct module *mod, uint64_t addr)
5473 +{
5474 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5475 +}
5476 +
5477 +static inline int
5478 +in_core_rw (const struct module *mod, uint64_t addr)
5479 +{
5480 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5481 }
5482
5483 static inline int
5484 in_core (const struct module *mod, uint64_t addr)
5485 {
5486 - return addr - (uint64_t) mod->module_core < mod->core_size;
5487 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5488 }
5489
5490 static inline int
5491 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5492 break;
5493
5494 case RV_BDREL:
5495 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5496 + if (in_init_rx(mod, val))
5497 + val -= (uint64_t) mod->module_init_rx;
5498 + else if (in_init_rw(mod, val))
5499 + val -= (uint64_t) mod->module_init_rw;
5500 + else if (in_core_rx(mod, val))
5501 + val -= (uint64_t) mod->module_core_rx;
5502 + else if (in_core_rw(mod, val))
5503 + val -= (uint64_t) mod->module_core_rw;
5504 break;
5505
5506 case RV_LTV:
5507 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5508 * addresses have been selected...
5509 */
5510 uint64_t gp;
5511 - if (mod->core_size > MAX_LTOFF)
5512 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5513 /*
5514 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5515 * at the end of the module.
5516 */
5517 - gp = mod->core_size - MAX_LTOFF / 2;
5518 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5519 else
5520 - gp = mod->core_size / 2;
5521 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5522 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5523 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5524 mod->arch.gp = gp;
5525 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5526 }
5527 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5528 index c39c3cd..3c77738 100644
5529 --- a/arch/ia64/kernel/palinfo.c
5530 +++ b/arch/ia64/kernel/palinfo.c
5531 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5532 return NOTIFY_OK;
5533 }
5534
5535 -static struct notifier_block __refdata palinfo_cpu_notifier =
5536 +static struct notifier_block palinfo_cpu_notifier =
5537 {
5538 .notifier_call = palinfo_cpu_callback,
5539 .priority = 0,
5540 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5541 index 41e33f8..65180b2a 100644
5542 --- a/arch/ia64/kernel/sys_ia64.c
5543 +++ b/arch/ia64/kernel/sys_ia64.c
5544 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5545 unsigned long align_mask = 0;
5546 struct mm_struct *mm = current->mm;
5547 struct vm_unmapped_area_info info;
5548 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5549
5550 if (len > RGN_MAP_LIMIT)
5551 return -ENOMEM;
5552 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5553 if (REGION_NUMBER(addr) == RGN_HPAGE)
5554 addr = 0;
5555 #endif
5556 +
5557 +#ifdef CONFIG_PAX_RANDMMAP
5558 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5559 + addr = mm->free_area_cache;
5560 + else
5561 +#endif
5562 +
5563 if (!addr)
5564 addr = TASK_UNMAPPED_BASE;
5565
5566 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5567 info.high_limit = TASK_SIZE;
5568 info.align_mask = align_mask;
5569 info.align_offset = 0;
5570 + info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5575 index 84f8a52..7c76178 100644
5576 --- a/arch/ia64/kernel/vmlinux.lds.S
5577 +++ b/arch/ia64/kernel/vmlinux.lds.S
5578 @@ -192,7 +192,7 @@ SECTIONS {
5579 /* Per-cpu data: */
5580 . = ALIGN(PERCPU_PAGE_SIZE);
5581 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5582 - __phys_per_cpu_start = __per_cpu_load;
5583 + __phys_per_cpu_start = per_cpu_load;
5584 /*
5585 * ensure percpu data fits
5586 * into percpu page size
5587 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5588 index 7225dad..2a7c8256 100644
5589 --- a/arch/ia64/mm/fault.c
5590 +++ b/arch/ia64/mm/fault.c
5591 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5592 return pte_present(pte);
5593 }
5594
5595 +#ifdef CONFIG_PAX_PAGEEXEC
5596 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5597 +{
5598 + unsigned long i;
5599 +
5600 + printk(KERN_ERR "PAX: bytes at PC: ");
5601 + for (i = 0; i < 8; i++) {
5602 + unsigned int c;
5603 + if (get_user(c, (unsigned int *)pc+i))
5604 + printk(KERN_CONT "???????? ");
5605 + else
5606 + printk(KERN_CONT "%08x ", c);
5607 + }
5608 + printk("\n");
5609 +}
5610 +#endif
5611 +
5612 # define VM_READ_BIT 0
5613 # define VM_WRITE_BIT 1
5614 # define VM_EXEC_BIT 2
5615 @@ -151,8 +168,21 @@ retry:
5616 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5617 goto bad_area;
5618
5619 - if ((vma->vm_flags & mask) != mask)
5620 + if ((vma->vm_flags & mask) != mask) {
5621 +
5622 +#ifdef CONFIG_PAX_PAGEEXEC
5623 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5624 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5625 + goto bad_area;
5626 +
5627 + up_read(&mm->mmap_sem);
5628 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5629 + do_group_exit(SIGKILL);
5630 + }
5631 +#endif
5632 +
5633 goto bad_area;
5634 + }
5635
5636 /*
5637 * If for any reason at all we couldn't handle the fault, make
5638 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5639 index 76069c1..c2aa816 100644
5640 --- a/arch/ia64/mm/hugetlbpage.c
5641 +++ b/arch/ia64/mm/hugetlbpage.c
5642 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5643 unsigned long pgoff, unsigned long flags)
5644 {
5645 struct vm_unmapped_area_info info;
5646 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5647
5648 if (len > RGN_MAP_LIMIT)
5649 return -ENOMEM;
5650 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5651 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5652 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5653 info.align_offset = 0;
5654 + info.threadstack_offset = offset;
5655 return vm_unmapped_area(&info);
5656 }
5657
5658 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5659 index 6b33457..88b5124 100644
5660 --- a/arch/ia64/mm/init.c
5661 +++ b/arch/ia64/mm/init.c
5662 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5663 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5664 vma->vm_end = vma->vm_start + PAGE_SIZE;
5665 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5666 +
5667 +#ifdef CONFIG_PAX_PAGEEXEC
5668 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5669 + vma->vm_flags &= ~VM_EXEC;
5670 +
5671 +#ifdef CONFIG_PAX_MPROTECT
5672 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5673 + vma->vm_flags &= ~VM_MAYEXEC;
5674 +#endif
5675 +
5676 + }
5677 +#endif
5678 +
5679 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5680 down_write(&current->mm->mmap_sem);
5681 if (insert_vm_struct(current->mm, vma)) {
5682 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5683 gate_vma.vm_start = FIXADDR_USER_START;
5684 gate_vma.vm_end = FIXADDR_USER_END;
5685 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5686 - gate_vma.vm_page_prot = __P101;
5687 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5688
5689 return 0;
5690 }
5691 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5692 index 40b3ee9..8c2c112 100644
5693 --- a/arch/m32r/include/asm/cache.h
5694 +++ b/arch/m32r/include/asm/cache.h
5695 @@ -1,8 +1,10 @@
5696 #ifndef _ASM_M32R_CACHE_H
5697 #define _ASM_M32R_CACHE_H
5698
5699 +#include <linux/const.h>
5700 +
5701 /* L1 cache line size */
5702 #define L1_CACHE_SHIFT 4
5703 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5704 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5705
5706 #endif /* _ASM_M32R_CACHE_H */
5707 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5708 index 82abd15..d95ae5d 100644
5709 --- a/arch/m32r/lib/usercopy.c
5710 +++ b/arch/m32r/lib/usercopy.c
5711 @@ -14,6 +14,9 @@
5712 unsigned long
5713 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5714 {
5715 + if ((long)n < 0)
5716 + return n;
5717 +
5718 prefetch(from);
5719 if (access_ok(VERIFY_WRITE, to, n))
5720 __copy_user(to,from,n);
5721 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5722 unsigned long
5723 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5724 {
5725 + if ((long)n < 0)
5726 + return n;
5727 +
5728 prefetchw(to);
5729 if (access_ok(VERIFY_READ, from, n))
5730 __copy_user_zeroing(to,from,n);
5731 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5732 index 0395c51..5f26031 100644
5733 --- a/arch/m68k/include/asm/cache.h
5734 +++ b/arch/m68k/include/asm/cache.h
5735 @@ -4,9 +4,11 @@
5736 #ifndef __ARCH_M68K_CACHE_H
5737 #define __ARCH_M68K_CACHE_H
5738
5739 +#include <linux/const.h>
5740 +
5741 /* bytes per L1 cache line */
5742 #define L1_CACHE_SHIFT 4
5743 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5744 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5745
5746 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5747
5748 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5749 index c7591e8..ecef036 100644
5750 --- a/arch/metag/include/asm/barrier.h
5751 +++ b/arch/metag/include/asm/barrier.h
5752 @@ -89,7 +89,7 @@ static inline void fence(void)
5753 do { \
5754 compiletime_assert_atomic_type(*p); \
5755 smp_mb(); \
5756 - ACCESS_ONCE(*p) = (v); \
5757 + ACCESS_ONCE_RW(*p) = (v); \
5758 } while (0)
5759
5760 #define smp_load_acquire(p) \
5761 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5762 index 3c32075..ae0ae75 100644
5763 --- a/arch/metag/mm/hugetlbpage.c
5764 +++ b/arch/metag/mm/hugetlbpage.c
5765 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5766 info.high_limit = TASK_SIZE;
5767 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5768 info.align_offset = 0;
5769 + info.threadstack_offset = 0;
5770 return vm_unmapped_area(&info);
5771 }
5772
5773 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5774 index 4efe96a..60e8699 100644
5775 --- a/arch/microblaze/include/asm/cache.h
5776 +++ b/arch/microblaze/include/asm/cache.h
5777 @@ -13,11 +13,12 @@
5778 #ifndef _ASM_MICROBLAZE_CACHE_H
5779 #define _ASM_MICROBLAZE_CACHE_H
5780
5781 +#include <linux/const.h>
5782 #include <asm/registers.h>
5783
5784 #define L1_CACHE_SHIFT 5
5785 /* word-granular cache in microblaze */
5786 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5787 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5788
5789 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5790
5791 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5792 index 574c430..470200d 100644
5793 --- a/arch/mips/Kconfig
5794 +++ b/arch/mips/Kconfig
5795 @@ -2399,6 +2399,7 @@ source "kernel/Kconfig.preempt"
5796
5797 config KEXEC
5798 bool "Kexec system call"
5799 + depends on !GRKERNSEC_KMEM
5800 help
5801 kexec is a system call that implements the ability to shutdown your
5802 current kernel, and to start another kernel. It is like a reboot
5803 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5804 index 02f2444..506969c 100644
5805 --- a/arch/mips/cavium-octeon/dma-octeon.c
5806 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5807 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5808 if (dma_release_from_coherent(dev, order, vaddr))
5809 return;
5810
5811 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5812 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5813 }
5814
5815 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5816 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5817 index 37b2bef..02122b8 100644
5818 --- a/arch/mips/include/asm/atomic.h
5819 +++ b/arch/mips/include/asm/atomic.h
5820 @@ -21,15 +21,39 @@
5821 #include <asm/cmpxchg.h>
5822 #include <asm/war.h>
5823
5824 +#ifdef CONFIG_GENERIC_ATOMIC64
5825 +#include <asm-generic/atomic64.h>
5826 +#endif
5827 +
5828 #define ATOMIC_INIT(i) { (i) }
5829
5830 +#ifdef CONFIG_64BIT
5831 +#define _ASM_EXTABLE(from, to) \
5832 +" .section __ex_table,\"a\"\n" \
5833 +" .dword " #from ", " #to"\n" \
5834 +" .previous\n"
5835 +#else
5836 +#define _ASM_EXTABLE(from, to) \
5837 +" .section __ex_table,\"a\"\n" \
5838 +" .word " #from ", " #to"\n" \
5839 +" .previous\n"
5840 +#endif
5841 +
5842 /*
5843 * atomic_read - read atomic variable
5844 * @v: pointer of type atomic_t
5845 *
5846 * Atomically reads the value of @v.
5847 */
5848 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5849 +static inline int atomic_read(const atomic_t *v)
5850 +{
5851 + return (*(volatile const int *) &v->counter);
5852 +}
5853 +
5854 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5855 +{
5856 + return (*(volatile const int *) &v->counter);
5857 +}
5858
5859 /*
5860 * atomic_set - set atomic variable
5861 @@ -38,7 +62,15 @@
5862 *
5863 * Atomically sets the value of @v to @i.
5864 */
5865 -#define atomic_set(v, i) ((v)->counter = (i))
5866 +static inline void atomic_set(atomic_t *v, int i)
5867 +{
5868 + v->counter = i;
5869 +}
5870 +
5871 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5872 +{
5873 + v->counter = i;
5874 +}
5875
5876 /*
5877 * atomic_add - add integer to atomic variable
5878 @@ -47,7 +79,67 @@
5879 *
5880 * Atomically adds @i to @v.
5881 */
5882 -static __inline__ void atomic_add(int i, atomic_t * v)
5883 +static __inline__ void atomic_add(int i, atomic_t *v)
5884 +{
5885 + int temp;
5886 +
5887 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5888 + __asm__ __volatile__(
5889 + " .set mips3 \n"
5890 + "1: ll %0, %1 # atomic_add \n"
5891 +#ifdef CONFIG_PAX_REFCOUNT
5892 + /* Exception on overflow. */
5893 + "2: add %0, %2 \n"
5894 +#else
5895 + " addu %0, %2 \n"
5896 +#endif
5897 + " sc %0, %1 \n"
5898 + " beqzl %0, 1b \n"
5899 +#ifdef CONFIG_PAX_REFCOUNT
5900 + "3: \n"
5901 + _ASM_EXTABLE(2b, 3b)
5902 +#endif
5903 + " .set mips0 \n"
5904 + : "=&r" (temp), "+m" (v->counter)
5905 + : "Ir" (i));
5906 + } else if (kernel_uses_llsc) {
5907 + __asm__ __volatile__(
5908 + " .set mips3 \n"
5909 + "1: ll %0, %1 # atomic_add \n"
5910 +#ifdef CONFIG_PAX_REFCOUNT
5911 + /* Exception on overflow. */
5912 + "2: add %0, %2 \n"
5913 +#else
5914 + " addu %0, %2 \n"
5915 +#endif
5916 + " sc %0, %1 \n"
5917 + " beqz %0, 1b \n"
5918 +#ifdef CONFIG_PAX_REFCOUNT
5919 + "3: \n"
5920 + _ASM_EXTABLE(2b, 3b)
5921 +#endif
5922 + " .set mips0 \n"
5923 + : "=&r" (temp), "+m" (v->counter)
5924 + : "Ir" (i));
5925 + } else {
5926 + unsigned long flags;
5927 +
5928 + raw_local_irq_save(flags);
5929 + __asm__ __volatile__(
5930 +#ifdef CONFIG_PAX_REFCOUNT
5931 + /* Exception on overflow. */
5932 + "1: add %0, %1 \n"
5933 + "2: \n"
5934 + _ASM_EXTABLE(1b, 2b)
5935 +#else
5936 + " addu %0, %1 \n"
5937 +#endif
5938 + : "+r" (v->counter) : "Ir" (i));
5939 + raw_local_irq_restore(flags);
5940 + }
5941 +}
5942 +
5943 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5944 {
5945 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5946 int temp;
5947 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5948 *
5949 * Atomically subtracts @i from @v.
5950 */
5951 -static __inline__ void atomic_sub(int i, atomic_t * v)
5952 +static __inline__ void atomic_sub(int i, atomic_t *v)
5953 +{
5954 + int temp;
5955 +
5956 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5957 + __asm__ __volatile__(
5958 + " .set mips3 \n"
5959 + "1: ll %0, %1 # atomic64_sub \n"
5960 +#ifdef CONFIG_PAX_REFCOUNT
5961 + /* Exception on overflow. */
5962 + "2: sub %0, %2 \n"
5963 +#else
5964 + " subu %0, %2 \n"
5965 +#endif
5966 + " sc %0, %1 \n"
5967 + " beqzl %0, 1b \n"
5968 +#ifdef CONFIG_PAX_REFCOUNT
5969 + "3: \n"
5970 + _ASM_EXTABLE(2b, 3b)
5971 +#endif
5972 + " .set mips0 \n"
5973 + : "=&r" (temp), "+m" (v->counter)
5974 + : "Ir" (i));
5975 + } else if (kernel_uses_llsc) {
5976 + __asm__ __volatile__(
5977 + " .set mips3 \n"
5978 + "1: ll %0, %1 # atomic64_sub \n"
5979 +#ifdef CONFIG_PAX_REFCOUNT
5980 + /* Exception on overflow. */
5981 + "2: sub %0, %2 \n"
5982 +#else
5983 + " subu %0, %2 \n"
5984 +#endif
5985 + " sc %0, %1 \n"
5986 + " beqz %0, 1b \n"
5987 +#ifdef CONFIG_PAX_REFCOUNT
5988 + "3: \n"
5989 + _ASM_EXTABLE(2b, 3b)
5990 +#endif
5991 + " .set mips0 \n"
5992 + : "=&r" (temp), "+m" (v->counter)
5993 + : "Ir" (i));
5994 + } else {
5995 + unsigned long flags;
5996 +
5997 + raw_local_irq_save(flags);
5998 + __asm__ __volatile__(
5999 +#ifdef CONFIG_PAX_REFCOUNT
6000 + /* Exception on overflow. */
6001 + "1: sub %0, %1 \n"
6002 + "2: \n"
6003 + _ASM_EXTABLE(1b, 2b)
6004 +#else
6005 + " subu %0, %1 \n"
6006 +#endif
6007 + : "+r" (v->counter) : "Ir" (i));
6008 + raw_local_irq_restore(flags);
6009 + }
6010 +}
6011 +
6012 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6013 {
6014 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6015 int temp;
6016 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6017 /*
6018 * Same as above, but return the result value
6019 */
6020 -static __inline__ int atomic_add_return(int i, atomic_t * v)
6021 +static __inline__ int atomic_add_return(int i, atomic_t *v)
6022 +{
6023 + int result;
6024 + int temp;
6025 +
6026 + smp_mb__before_llsc();
6027 +
6028 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6029 + __asm__ __volatile__(
6030 + " .set mips3 \n"
6031 + "1: ll %1, %2 # atomic_add_return \n"
6032 +#ifdef CONFIG_PAX_REFCOUNT
6033 + "2: add %0, %1, %3 \n"
6034 +#else
6035 + " addu %0, %1, %3 \n"
6036 +#endif
6037 + " sc %0, %2 \n"
6038 + " beqzl %0, 1b \n"
6039 +#ifdef CONFIG_PAX_REFCOUNT
6040 + " b 4f \n"
6041 + " .set noreorder \n"
6042 + "3: b 5f \n"
6043 + " move %0, %1 \n"
6044 + " .set reorder \n"
6045 + _ASM_EXTABLE(2b, 3b)
6046 +#endif
6047 + "4: addu %0, %1, %3 \n"
6048 +#ifdef CONFIG_PAX_REFCOUNT
6049 + "5: \n"
6050 +#endif
6051 + " .set mips0 \n"
6052 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6053 + : "Ir" (i));
6054 + } else if (kernel_uses_llsc) {
6055 + __asm__ __volatile__(
6056 + " .set mips3 \n"
6057 + "1: ll %1, %2 # atomic_add_return \n"
6058 +#ifdef CONFIG_PAX_REFCOUNT
6059 + "2: add %0, %1, %3 \n"
6060 +#else
6061 + " addu %0, %1, %3 \n"
6062 +#endif
6063 + " sc %0, %2 \n"
6064 + " bnez %0, 4f \n"
6065 + " b 1b \n"
6066 +#ifdef CONFIG_PAX_REFCOUNT
6067 + " .set noreorder \n"
6068 + "3: b 5f \n"
6069 + " move %0, %1 \n"
6070 + " .set reorder \n"
6071 + _ASM_EXTABLE(2b, 3b)
6072 +#endif
6073 + "4: addu %0, %1, %3 \n"
6074 +#ifdef CONFIG_PAX_REFCOUNT
6075 + "5: \n"
6076 +#endif
6077 + " .set mips0 \n"
6078 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6079 + : "Ir" (i));
6080 + } else {
6081 + unsigned long flags;
6082 +
6083 + raw_local_irq_save(flags);
6084 + __asm__ __volatile__(
6085 + " lw %0, %1 \n"
6086 +#ifdef CONFIG_PAX_REFCOUNT
6087 + /* Exception on overflow. */
6088 + "1: add %0, %2 \n"
6089 +#else
6090 + " addu %0, %2 \n"
6091 +#endif
6092 + " sw %0, %1 \n"
6093 +#ifdef CONFIG_PAX_REFCOUNT
6094 + /* Note: Dest reg is not modified on overflow */
6095 + "2: \n"
6096 + _ASM_EXTABLE(1b, 2b)
6097 +#endif
6098 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6099 + raw_local_irq_restore(flags);
6100 + }
6101 +
6102 + smp_llsc_mb();
6103 +
6104 + return result;
6105 +}
6106 +
6107 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6108 {
6109 int result;
6110
6111 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6112 return result;
6113 }
6114
6115 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6116 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6117 +{
6118 + int result;
6119 + int temp;
6120 +
6121 + smp_mb__before_llsc();
6122 +
6123 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6124 + __asm__ __volatile__(
6125 + " .set mips3 \n"
6126 + "1: ll %1, %2 # atomic_sub_return \n"
6127 +#ifdef CONFIG_PAX_REFCOUNT
6128 + "2: sub %0, %1, %3 \n"
6129 +#else
6130 + " subu %0, %1, %3 \n"
6131 +#endif
6132 + " sc %0, %2 \n"
6133 + " beqzl %0, 1b \n"
6134 +#ifdef CONFIG_PAX_REFCOUNT
6135 + " b 4f \n"
6136 + " .set noreorder \n"
6137 + "3: b 5f \n"
6138 + " move %0, %1 \n"
6139 + " .set reorder \n"
6140 + _ASM_EXTABLE(2b, 3b)
6141 +#endif
6142 + "4: subu %0, %1, %3 \n"
6143 +#ifdef CONFIG_PAX_REFCOUNT
6144 + "5: \n"
6145 +#endif
6146 + " .set mips0 \n"
6147 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6148 + : "Ir" (i), "m" (v->counter)
6149 + : "memory");
6150 + } else if (kernel_uses_llsc) {
6151 + __asm__ __volatile__(
6152 + " .set mips3 \n"
6153 + "1: ll %1, %2 # atomic_sub_return \n"
6154 +#ifdef CONFIG_PAX_REFCOUNT
6155 + "2: sub %0, %1, %3 \n"
6156 +#else
6157 + " subu %0, %1, %3 \n"
6158 +#endif
6159 + " sc %0, %2 \n"
6160 + " bnez %0, 4f \n"
6161 + " b 1b \n"
6162 +#ifdef CONFIG_PAX_REFCOUNT
6163 + " .set noreorder \n"
6164 + "3: b 5f \n"
6165 + " move %0, %1 \n"
6166 + " .set reorder \n"
6167 + _ASM_EXTABLE(2b, 3b)
6168 +#endif
6169 + "4: subu %0, %1, %3 \n"
6170 +#ifdef CONFIG_PAX_REFCOUNT
6171 + "5: \n"
6172 +#endif
6173 + " .set mips0 \n"
6174 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6175 + : "Ir" (i));
6176 + } else {
6177 + unsigned long flags;
6178 +
6179 + raw_local_irq_save(flags);
6180 + __asm__ __volatile__(
6181 + " lw %0, %1 \n"
6182 +#ifdef CONFIG_PAX_REFCOUNT
6183 + /* Exception on overflow. */
6184 + "1: sub %0, %2 \n"
6185 +#else
6186 + " subu %0, %2 \n"
6187 +#endif
6188 + " sw %0, %1 \n"
6189 +#ifdef CONFIG_PAX_REFCOUNT
6190 + /* Note: Dest reg is not modified on overflow */
6191 + "2: \n"
6192 + _ASM_EXTABLE(1b, 2b)
6193 +#endif
6194 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6195 + raw_local_irq_restore(flags);
6196 + }
6197 +
6198 + smp_llsc_mb();
6199 +
6200 + return result;
6201 +}
6202 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6203 {
6204 int result;
6205
6206 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6207 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6208 * The function returns the old value of @v minus @i.
6209 */
6210 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6211 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6212 {
6213 int result;
6214
6215 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6216 return result;
6217 }
6218
6219 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6220 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6221 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6222 +{
6223 + return cmpxchg(&v->counter, old, new);
6224 +}
6225 +
6226 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6227 + int new)
6228 +{
6229 + return cmpxchg(&(v->counter), old, new);
6230 +}
6231 +
6232 +static inline int atomic_xchg(atomic_t *v, int new)
6233 +{
6234 + return xchg(&v->counter, new);
6235 +}
6236 +
6237 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6238 +{
6239 + return xchg(&(v->counter), new);
6240 +}
6241
6242 /**
6243 * __atomic_add_unless - add unless the number is a given value
6244 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6245
6246 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6247 #define atomic_inc_return(v) atomic_add_return(1, (v))
6248 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6249 +{
6250 + return atomic_add_return_unchecked(1, v);
6251 +}
6252
6253 /*
6254 * atomic_sub_and_test - subtract value from variable and test result
6255 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6256 * other cases.
6257 */
6258 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6259 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6260 +{
6261 + return atomic_add_return_unchecked(1, v) == 0;
6262 +}
6263
6264 /*
6265 * atomic_dec_and_test - decrement by 1 and test
6266 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6267 * Atomically increments @v by 1.
6268 */
6269 #define atomic_inc(v) atomic_add(1, (v))
6270 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6271 +{
6272 + atomic_add_unchecked(1, v);
6273 +}
6274
6275 /*
6276 * atomic_dec - decrement and test
6277 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6278 * Atomically decrements @v by 1.
6279 */
6280 #define atomic_dec(v) atomic_sub(1, (v))
6281 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6282 +{
6283 + atomic_sub_unchecked(1, v);
6284 +}
6285
6286 /*
6287 * atomic_add_negative - add and test if negative
6288 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6289 * @v: pointer of type atomic64_t
6290 *
6291 */
6292 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6293 +static inline long atomic64_read(const atomic64_t *v)
6294 +{
6295 + return (*(volatile const long *) &v->counter);
6296 +}
6297 +
6298 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6299 +{
6300 + return (*(volatile const long *) &v->counter);
6301 +}
6302
6303 /*
6304 * atomic64_set - set atomic variable
6305 * @v: pointer of type atomic64_t
6306 * @i: required value
6307 */
6308 -#define atomic64_set(v, i) ((v)->counter = (i))
6309 +static inline void atomic64_set(atomic64_t *v, long i)
6310 +{
6311 + v->counter = i;
6312 +}
6313 +
6314 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6315 +{
6316 + v->counter = i;
6317 +}
6318
6319 /*
6320 * atomic64_add - add integer to atomic variable
6321 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6322 *
6323 * Atomically adds @i to @v.
6324 */
6325 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6326 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6327 +{
6328 + long temp;
6329 +
6330 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6331 + __asm__ __volatile__(
6332 + " .set mips3 \n"
6333 + "1: lld %0, %1 # atomic64_add \n"
6334 +#ifdef CONFIG_PAX_REFCOUNT
6335 + /* Exception on overflow. */
6336 + "2: dadd %0, %2 \n"
6337 +#else
6338 + " daddu %0, %2 \n"
6339 +#endif
6340 + " scd %0, %1 \n"
6341 + " beqzl %0, 1b \n"
6342 +#ifdef CONFIG_PAX_REFCOUNT
6343 + "3: \n"
6344 + _ASM_EXTABLE(2b, 3b)
6345 +#endif
6346 + " .set mips0 \n"
6347 + : "=&r" (temp), "+m" (v->counter)
6348 + : "Ir" (i));
6349 + } else if (kernel_uses_llsc) {
6350 + __asm__ __volatile__(
6351 + " .set mips3 \n"
6352 + "1: lld %0, %1 # atomic64_add \n"
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + /* Exception on overflow. */
6355 + "2: dadd %0, %2 \n"
6356 +#else
6357 + " daddu %0, %2 \n"
6358 +#endif
6359 + " scd %0, %1 \n"
6360 + " beqz %0, 1b \n"
6361 +#ifdef CONFIG_PAX_REFCOUNT
6362 + "3: \n"
6363 + _ASM_EXTABLE(2b, 3b)
6364 +#endif
6365 + " .set mips0 \n"
6366 + : "=&r" (temp), "+m" (v->counter)
6367 + : "Ir" (i));
6368 + } else {
6369 + unsigned long flags;
6370 +
6371 + raw_local_irq_save(flags);
6372 + __asm__ __volatile__(
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + /* Exception on overflow. */
6375 + "1: dadd %0, %1 \n"
6376 + "2: \n"
6377 + _ASM_EXTABLE(1b, 2b)
6378 +#else
6379 + " daddu %0, %1 \n"
6380 +#endif
6381 + : "+r" (v->counter) : "Ir" (i));
6382 + raw_local_irq_restore(flags);
6383 + }
6384 +}
6385 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6388 long temp;
6389 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6390 *
6391 * Atomically subtracts @i from @v.
6392 */
6393 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6394 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6395 +{
6396 + long temp;
6397 +
6398 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6399 + __asm__ __volatile__(
6400 + " .set mips3 \n"
6401 + "1: lld %0, %1 # atomic64_sub \n"
6402 +#ifdef CONFIG_PAX_REFCOUNT
6403 + /* Exception on overflow. */
6404 + "2: dsub %0, %2 \n"
6405 +#else
6406 + " dsubu %0, %2 \n"
6407 +#endif
6408 + " scd %0, %1 \n"
6409 + " beqzl %0, 1b \n"
6410 +#ifdef CONFIG_PAX_REFCOUNT
6411 + "3: \n"
6412 + _ASM_EXTABLE(2b, 3b)
6413 +#endif
6414 + " .set mips0 \n"
6415 + : "=&r" (temp), "+m" (v->counter)
6416 + : "Ir" (i));
6417 + } else if (kernel_uses_llsc) {
6418 + __asm__ __volatile__(
6419 + " .set mips3 \n"
6420 + "1: lld %0, %1 # atomic64_sub \n"
6421 +#ifdef CONFIG_PAX_REFCOUNT
6422 + /* Exception on overflow. */
6423 + "2: dsub %0, %2 \n"
6424 +#else
6425 + " dsubu %0, %2 \n"
6426 +#endif
6427 + " scd %0, %1 \n"
6428 + " beqz %0, 1b \n"
6429 +#ifdef CONFIG_PAX_REFCOUNT
6430 + "3: \n"
6431 + _ASM_EXTABLE(2b, 3b)
6432 +#endif
6433 + " .set mips0 \n"
6434 + : "=&r" (temp), "+m" (v->counter)
6435 + : "Ir" (i));
6436 + } else {
6437 + unsigned long flags;
6438 +
6439 + raw_local_irq_save(flags);
6440 + __asm__ __volatile__(
6441 +#ifdef CONFIG_PAX_REFCOUNT
6442 + /* Exception on overflow. */
6443 + "1: dsub %0, %1 \n"
6444 + "2: \n"
6445 + _ASM_EXTABLE(1b, 2b)
6446 +#else
6447 + " dsubu %0, %1 \n"
6448 +#endif
6449 + : "+r" (v->counter) : "Ir" (i));
6450 + raw_local_irq_restore(flags);
6451 + }
6452 +}
6453 +
6454 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6455 {
6456 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6457 long temp;
6458 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6459 /*
6460 * Same as above, but return the result value
6461 */
6462 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6463 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6464 +{
6465 + long result;
6466 + long temp;
6467 +
6468 + smp_mb__before_llsc();
6469 +
6470 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6471 + __asm__ __volatile__(
6472 + " .set mips3 \n"
6473 + "1: lld %1, %2 # atomic64_add_return \n"
6474 +#ifdef CONFIG_PAX_REFCOUNT
6475 + "2: dadd %0, %1, %3 \n"
6476 +#else
6477 + " daddu %0, %1, %3 \n"
6478 +#endif
6479 + " scd %0, %2 \n"
6480 + " beqzl %0, 1b \n"
6481 +#ifdef CONFIG_PAX_REFCOUNT
6482 + " b 4f \n"
6483 + " .set noreorder \n"
6484 + "3: b 5f \n"
6485 + " move %0, %1 \n"
6486 + " .set reorder \n"
6487 + _ASM_EXTABLE(2b, 3b)
6488 +#endif
6489 + "4: daddu %0, %1, %3 \n"
6490 +#ifdef CONFIG_PAX_REFCOUNT
6491 + "5: \n"
6492 +#endif
6493 + " .set mips0 \n"
6494 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6495 + : "Ir" (i));
6496 + } else if (kernel_uses_llsc) {
6497 + __asm__ __volatile__(
6498 + " .set mips3 \n"
6499 + "1: lld %1, %2 # atomic64_add_return \n"
6500 +#ifdef CONFIG_PAX_REFCOUNT
6501 + "2: dadd %0, %1, %3 \n"
6502 +#else
6503 + " daddu %0, %1, %3 \n"
6504 +#endif
6505 + " scd %0, %2 \n"
6506 + " bnez %0, 4f \n"
6507 + " b 1b \n"
6508 +#ifdef CONFIG_PAX_REFCOUNT
6509 + " .set noreorder \n"
6510 + "3: b 5f \n"
6511 + " move %0, %1 \n"
6512 + " .set reorder \n"
6513 + _ASM_EXTABLE(2b, 3b)
6514 +#endif
6515 + "4: daddu %0, %1, %3 \n"
6516 +#ifdef CONFIG_PAX_REFCOUNT
6517 + "5: \n"
6518 +#endif
6519 + " .set mips0 \n"
6520 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6521 + : "Ir" (i), "m" (v->counter)
6522 + : "memory");
6523 + } else {
6524 + unsigned long flags;
6525 +
6526 + raw_local_irq_save(flags);
6527 + __asm__ __volatile__(
6528 + " ld %0, %1 \n"
6529 +#ifdef CONFIG_PAX_REFCOUNT
6530 + /* Exception on overflow. */
6531 + "1: dadd %0, %2 \n"
6532 +#else
6533 + " daddu %0, %2 \n"
6534 +#endif
6535 + " sd %0, %1 \n"
6536 +#ifdef CONFIG_PAX_REFCOUNT
6537 + /* Note: Dest reg is not modified on overflow */
6538 + "2: \n"
6539 + _ASM_EXTABLE(1b, 2b)
6540 +#endif
6541 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6542 + raw_local_irq_restore(flags);
6543 + }
6544 +
6545 + smp_llsc_mb();
6546 +
6547 + return result;
6548 +}
6549 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6550 {
6551 long result;
6552
6553 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6554 return result;
6555 }
6556
6557 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6558 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6559 +{
6560 + long result;
6561 + long temp;
6562 +
6563 + smp_mb__before_llsc();
6564 +
6565 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566 + long temp;
6567 +
6568 + __asm__ __volatile__(
6569 + " .set mips3 \n"
6570 + "1: lld %1, %2 # atomic64_sub_return \n"
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 + "2: dsub %0, %1, %3 \n"
6573 +#else
6574 + " dsubu %0, %1, %3 \n"
6575 +#endif
6576 + " scd %0, %2 \n"
6577 + " beqzl %0, 1b \n"
6578 +#ifdef CONFIG_PAX_REFCOUNT
6579 + " b 4f \n"
6580 + " .set noreorder \n"
6581 + "3: b 5f \n"
6582 + " move %0, %1 \n"
6583 + " .set reorder \n"
6584 + _ASM_EXTABLE(2b, 3b)
6585 +#endif
6586 + "4: dsubu %0, %1, %3 \n"
6587 +#ifdef CONFIG_PAX_REFCOUNT
6588 + "5: \n"
6589 +#endif
6590 + " .set mips0 \n"
6591 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6592 + : "Ir" (i), "m" (v->counter)
6593 + : "memory");
6594 + } else if (kernel_uses_llsc) {
6595 + __asm__ __volatile__(
6596 + " .set mips3 \n"
6597 + "1: lld %1, %2 # atomic64_sub_return \n"
6598 +#ifdef CONFIG_PAX_REFCOUNT
6599 + "2: dsub %0, %1, %3 \n"
6600 +#else
6601 + " dsubu %0, %1, %3 \n"
6602 +#endif
6603 + " scd %0, %2 \n"
6604 + " bnez %0, 4f \n"
6605 + " b 1b \n"
6606 +#ifdef CONFIG_PAX_REFCOUNT
6607 + " .set noreorder \n"
6608 + "3: b 5f \n"
6609 + " move %0, %1 \n"
6610 + " .set reorder \n"
6611 + _ASM_EXTABLE(2b, 3b)
6612 +#endif
6613 + "4: dsubu %0, %1, %3 \n"
6614 +#ifdef CONFIG_PAX_REFCOUNT
6615 + "5: \n"
6616 +#endif
6617 + " .set mips0 \n"
6618 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6619 + : "Ir" (i), "m" (v->counter)
6620 + : "memory");
6621 + } else {
6622 + unsigned long flags;
6623 +
6624 + raw_local_irq_save(flags);
6625 + __asm__ __volatile__(
6626 + " ld %0, %1 \n"
6627 +#ifdef CONFIG_PAX_REFCOUNT
6628 + /* Exception on overflow. */
6629 + "1: dsub %0, %2 \n"
6630 +#else
6631 + " dsubu %0, %2 \n"
6632 +#endif
6633 + " sd %0, %1 \n"
6634 +#ifdef CONFIG_PAX_REFCOUNT
6635 + /* Note: Dest reg is not modified on overflow */
6636 + "2: \n"
6637 + _ASM_EXTABLE(1b, 2b)
6638 +#endif
6639 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6640 + raw_local_irq_restore(flags);
6641 + }
6642 +
6643 + smp_llsc_mb();
6644 +
6645 + return result;
6646 +}
6647 +
6648 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6649 {
6650 long result;
6651
6652 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6653 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6654 * The function returns the old value of @v minus @i.
6655 */
6656 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6657 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6658 {
6659 long result;
6660
6661 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6662 return result;
6663 }
6664
6665 -#define atomic64_cmpxchg(v, o, n) \
6666 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6667 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6668 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6669 +{
6670 + return cmpxchg(&v->counter, old, new);
6671 +}
6672 +
6673 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6674 + long new)
6675 +{
6676 + return cmpxchg(&(v->counter), old, new);
6677 +}
6678 +
6679 +static inline long atomic64_xchg(atomic64_t *v, long new)
6680 +{
6681 + return xchg(&v->counter, new);
6682 +}
6683 +
6684 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6685 +{
6686 + return xchg(&(v->counter), new);
6687 +}
6688
6689 /**
6690 * atomic64_add_unless - add unless the number is a given value
6691 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6692
6693 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6694 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6695 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6696
6697 /*
6698 * atomic64_sub_and_test - subtract value from variable and test result
6699 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6700 * other cases.
6701 */
6702 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6703 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6704
6705 /*
6706 * atomic64_dec_and_test - decrement by 1 and test
6707 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6708 * Atomically increments @v by 1.
6709 */
6710 #define atomic64_inc(v) atomic64_add(1, (v))
6711 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6712
6713 /*
6714 * atomic64_dec - decrement and test
6715 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6716 * Atomically decrements @v by 1.
6717 */
6718 #define atomic64_dec(v) atomic64_sub(1, (v))
6719 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6720
6721 /*
6722 * atomic64_add_negative - add and test if negative
6723 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6724 index d0101dd..266982c 100644
6725 --- a/arch/mips/include/asm/barrier.h
6726 +++ b/arch/mips/include/asm/barrier.h
6727 @@ -184,7 +184,7 @@
6728 do { \
6729 compiletime_assert_atomic_type(*p); \
6730 smp_mb(); \
6731 - ACCESS_ONCE(*p) = (v); \
6732 + ACCESS_ONCE_RW(*p) = (v); \
6733 } while (0)
6734
6735 #define smp_load_acquire(p) \
6736 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6737 index b4db69f..8f3b093 100644
6738 --- a/arch/mips/include/asm/cache.h
6739 +++ b/arch/mips/include/asm/cache.h
6740 @@ -9,10 +9,11 @@
6741 #ifndef _ASM_CACHE_H
6742 #define _ASM_CACHE_H
6743
6744 +#include <linux/const.h>
6745 #include <kmalloc.h>
6746
6747 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6748 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6749 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6750
6751 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6752 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6753 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6754 index 1d38fe0..9beabc9 100644
6755 --- a/arch/mips/include/asm/elf.h
6756 +++ b/arch/mips/include/asm/elf.h
6757 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6758 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6759 #endif
6760
6761 +#ifdef CONFIG_PAX_ASLR
6762 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6763 +
6764 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6765 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6766 +#endif
6767 +
6768 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6769 struct linux_binprm;
6770 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6771 int uses_interp);
6772
6773 -struct mm_struct;
6774 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6775 -#define arch_randomize_brk arch_randomize_brk
6776 -
6777 #endif /* _ASM_ELF_H */
6778 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6779 index c1f6afa..38cc6e9 100644
6780 --- a/arch/mips/include/asm/exec.h
6781 +++ b/arch/mips/include/asm/exec.h
6782 @@ -12,6 +12,6 @@
6783 #ifndef _ASM_EXEC_H
6784 #define _ASM_EXEC_H
6785
6786 -extern unsigned long arch_align_stack(unsigned long sp);
6787 +#define arch_align_stack(x) ((x) & ~0xfUL)
6788
6789 #endif /* _ASM_EXEC_H */
6790 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6791 index 9e8ef59..1139d6b 100644
6792 --- a/arch/mips/include/asm/hw_irq.h
6793 +++ b/arch/mips/include/asm/hw_irq.h
6794 @@ -10,7 +10,7 @@
6795
6796 #include <linux/atomic.h>
6797
6798 -extern atomic_t irq_err_count;
6799 +extern atomic_unchecked_t irq_err_count;
6800
6801 /*
6802 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6803 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6804 index 46dfc3c..a16b13a 100644
6805 --- a/arch/mips/include/asm/local.h
6806 +++ b/arch/mips/include/asm/local.h
6807 @@ -12,15 +12,25 @@ typedef struct
6808 atomic_long_t a;
6809 } local_t;
6810
6811 +typedef struct {
6812 + atomic_long_unchecked_t a;
6813 +} local_unchecked_t;
6814 +
6815 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6816
6817 #define local_read(l) atomic_long_read(&(l)->a)
6818 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6819 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6820 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6821
6822 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6823 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6824 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6825 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6826 #define local_inc(l) atomic_long_inc(&(l)->a)
6827 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6828 #define local_dec(l) atomic_long_dec(&(l)->a)
6829 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6830
6831 /*
6832 * Same as above, but return the result value
6833 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6834 return result;
6835 }
6836
6837 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6838 +{
6839 + unsigned long result;
6840 +
6841 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6842 + unsigned long temp;
6843 +
6844 + __asm__ __volatile__(
6845 + " .set mips3 \n"
6846 + "1:" __LL "%1, %2 # local_add_return \n"
6847 + " addu %0, %1, %3 \n"
6848 + __SC "%0, %2 \n"
6849 + " beqzl %0, 1b \n"
6850 + " addu %0, %1, %3 \n"
6851 + " .set mips0 \n"
6852 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6853 + : "Ir" (i), "m" (l->a.counter)
6854 + : "memory");
6855 + } else if (kernel_uses_llsc) {
6856 + unsigned long temp;
6857 +
6858 + __asm__ __volatile__(
6859 + " .set mips3 \n"
6860 + "1:" __LL "%1, %2 # local_add_return \n"
6861 + " addu %0, %1, %3 \n"
6862 + __SC "%0, %2 \n"
6863 + " beqz %0, 1b \n"
6864 + " addu %0, %1, %3 \n"
6865 + " .set mips0 \n"
6866 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6867 + : "Ir" (i), "m" (l->a.counter)
6868 + : "memory");
6869 + } else {
6870 + unsigned long flags;
6871 +
6872 + local_irq_save(flags);
6873 + result = l->a.counter;
6874 + result += i;
6875 + l->a.counter = result;
6876 + local_irq_restore(flags);
6877 + }
6878 +
6879 + return result;
6880 +}
6881 +
6882 static __inline__ long local_sub_return(long i, local_t * l)
6883 {
6884 unsigned long result;
6885 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6886
6887 #define local_cmpxchg(l, o, n) \
6888 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6889 +#define local_cmpxchg_unchecked(l, o, n) \
6890 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6891 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6892
6893 /**
6894 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6895 index 3be8180..c4798d5 100644
6896 --- a/arch/mips/include/asm/page.h
6897 +++ b/arch/mips/include/asm/page.h
6898 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6899 #ifdef CONFIG_CPU_MIPS32
6900 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6901 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6902 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6903 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6904 #else
6905 typedef struct { unsigned long long pte; } pte_t;
6906 #define pte_val(x) ((x).pte)
6907 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6908 index b336037..5b874cc 100644
6909 --- a/arch/mips/include/asm/pgalloc.h
6910 +++ b/arch/mips/include/asm/pgalloc.h
6911 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6912 {
6913 set_pud(pud, __pud((unsigned long)pmd));
6914 }
6915 +
6916 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6917 +{
6918 + pud_populate(mm, pud, pmd);
6919 +}
6920 #endif
6921
6922 /*
6923 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6924 index df49a30..c0d3dd6 100644
6925 --- a/arch/mips/include/asm/pgtable.h
6926 +++ b/arch/mips/include/asm/pgtable.h
6927 @@ -20,6 +20,9 @@
6928 #include <asm/io.h>
6929 #include <asm/pgtable-bits.h>
6930
6931 +#define ktla_ktva(addr) (addr)
6932 +#define ktva_ktla(addr) (addr)
6933 +
6934 struct mm_struct;
6935 struct vm_area_struct;
6936
6937 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6938 index 7de8658..c109224 100644
6939 --- a/arch/mips/include/asm/thread_info.h
6940 +++ b/arch/mips/include/asm/thread_info.h
6941 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6942 #define TIF_SECCOMP 4 /* secure computing */
6943 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6944 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6945 +/* li takes a 32bit immediate */
6946 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6947 +
6948 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6949 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6950 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6951 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6952 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6953 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6954 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6955 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6956
6957 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6958 _TIF_SYSCALL_AUDIT | \
6959 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6960 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6961 + _TIF_GRSEC_SETXID)
6962
6963 /* work to do in syscall_trace_leave() */
6964 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6965 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6966 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6967
6968 /* work to do on interrupt/exception return */
6969 #define _TIF_WORK_MASK \
6970 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6971 /* work to do on any return to u-space */
6972 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6973 _TIF_WORK_SYSCALL_EXIT | \
6974 - _TIF_SYSCALL_TRACEPOINT)
6975 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6976
6977 /*
6978 * We stash processor id into a COP0 register to retrieve it fast
6979 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6980 index a109510..0a764f7 100644
6981 --- a/arch/mips/include/asm/uaccess.h
6982 +++ b/arch/mips/include/asm/uaccess.h
6983 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6984 __ok == 0; \
6985 })
6986
6987 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6988 #define access_ok(type, addr, size) \
6989 likely(__access_ok((addr), (size), __access_mask))
6990
6991 @@ -301,7 +302,8 @@ do { \
6992 __get_kernel_common((x), size, __gu_ptr); \
6993 else \
6994 __get_user_common((x), size, __gu_ptr); \
6995 - } \
6996 + } else \
6997 + (x) = 0; \
6998 \
6999 __gu_err; \
7000 })
7001 @@ -316,6 +318,7 @@ do { \
7002 " .insn \n" \
7003 " .section .fixup,\"ax\" \n" \
7004 "3: li %0, %4 \n" \
7005 + " move %1, $0 \n" \
7006 " j 2b \n" \
7007 " .previous \n" \
7008 " .section __ex_table,\"a\" \n" \
7009 @@ -630,6 +633,7 @@ do { \
7010 " .insn \n" \
7011 " .section .fixup,\"ax\" \n" \
7012 "3: li %0, %4 \n" \
7013 + " move %1, $0 \n" \
7014 " j 2b \n" \
7015 " .previous \n" \
7016 " .section __ex_table,\"a\" \n" \
7017 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7018 index 1188e00..41cf144 100644
7019 --- a/arch/mips/kernel/binfmt_elfn32.c
7020 +++ b/arch/mips/kernel/binfmt_elfn32.c
7021 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7022 #undef ELF_ET_DYN_BASE
7023 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7024
7025 +#ifdef CONFIG_PAX_ASLR
7026 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7027 +
7028 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7029 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7030 +#endif
7031 +
7032 #include <asm/processor.h>
7033 #include <linux/module.h>
7034 #include <linux/elfcore.h>
7035 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7036 index 9287678..f870e47 100644
7037 --- a/arch/mips/kernel/binfmt_elfo32.c
7038 +++ b/arch/mips/kernel/binfmt_elfo32.c
7039 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7040 #undef ELF_ET_DYN_BASE
7041 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7042
7043 +#ifdef CONFIG_PAX_ASLR
7044 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7045 +
7046 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7047 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7048 +#endif
7049 +
7050 #include <asm/processor.h>
7051
7052 #include <linux/module.h>
7053 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7054 index 50b3648..c2f3cec 100644
7055 --- a/arch/mips/kernel/i8259.c
7056 +++ b/arch/mips/kernel/i8259.c
7057 @@ -201,7 +201,7 @@ spurious_8259A_irq:
7058 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7059 spurious_irq_mask |= irqmask;
7060 }
7061 - atomic_inc(&irq_err_count);
7062 + atomic_inc_unchecked(&irq_err_count);
7063 /*
7064 * Theoretically we do not have to handle this IRQ,
7065 * but in Linux this does not cause problems and is
7066 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7067 index 44a1f79..2bd6aa3 100644
7068 --- a/arch/mips/kernel/irq-gt641xx.c
7069 +++ b/arch/mips/kernel/irq-gt641xx.c
7070 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7071 }
7072 }
7073
7074 - atomic_inc(&irq_err_count);
7075 + atomic_inc_unchecked(&irq_err_count);
7076 }
7077
7078 void __init gt641xx_irq_init(void)
7079 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7080 index d2bfbc2..a8eacd2 100644
7081 --- a/arch/mips/kernel/irq.c
7082 +++ b/arch/mips/kernel/irq.c
7083 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7084 printk("unexpected IRQ # %d\n", irq);
7085 }
7086
7087 -atomic_t irq_err_count;
7088 +atomic_unchecked_t irq_err_count;
7089
7090 int arch_show_interrupts(struct seq_file *p, int prec)
7091 {
7092 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7093 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7094 return 0;
7095 }
7096
7097 asmlinkage void spurious_interrupt(void)
7098 {
7099 - atomic_inc(&irq_err_count);
7100 + atomic_inc_unchecked(&irq_err_count);
7101 }
7102
7103 void __init init_IRQ(void)
7104 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7105 #endif
7106 }
7107
7108 +
7109 #ifdef DEBUG_STACKOVERFLOW
7110 +extern void gr_handle_kernel_exploit(void);
7111 +
7112 static inline void check_stack_overflow(void)
7113 {
7114 unsigned long sp;
7115 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7116 printk("do_IRQ: stack overflow: %ld\n",
7117 sp - sizeof(struct thread_info));
7118 dump_stack();
7119 + gr_handle_kernel_exploit();
7120 }
7121 }
7122 #else
7123 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7124 index 0614717..002fa43 100644
7125 --- a/arch/mips/kernel/pm-cps.c
7126 +++ b/arch/mips/kernel/pm-cps.c
7127 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7128 nc_core_ready_count = nc_addr;
7129
7130 /* Ensure ready_count is zero-initialised before the assembly runs */
7131 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7132 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7133 coupled_barrier(&per_cpu(pm_barrier, core), online);
7134
7135 /* Run the generated entry code */
7136 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7137 index 636b074..8fbb91f 100644
7138 --- a/arch/mips/kernel/process.c
7139 +++ b/arch/mips/kernel/process.c
7140 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
7141 out:
7142 return pc;
7143 }
7144 -
7145 -/*
7146 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7147 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7148 - */
7149 -unsigned long arch_align_stack(unsigned long sp)
7150 -{
7151 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7152 - sp -= get_random_int() & ~PAGE_MASK;
7153 -
7154 - return sp & ALMASK;
7155 -}
7156 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7157 index 645b3c4..909c75a 100644
7158 --- a/arch/mips/kernel/ptrace.c
7159 +++ b/arch/mips/kernel/ptrace.c
7160 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
7161 return ret;
7162 }
7163
7164 +#ifdef CONFIG_GRKERNSEC_SETXID
7165 +extern void gr_delayed_cred_worker(void);
7166 +#endif
7167 +
7168 /*
7169 * Notification of system call entry/exit
7170 * - triggered by current->work.syscall_trace
7171 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7172 tracehook_report_syscall_entry(regs))
7173 ret = -1;
7174
7175 +#ifdef CONFIG_GRKERNSEC_SETXID
7176 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7177 + gr_delayed_cred_worker();
7178 +#endif
7179 +
7180 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7181 trace_sys_enter(regs, regs->regs[2]);
7182
7183 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7184 index 07fc524..b9d7f28 100644
7185 --- a/arch/mips/kernel/reset.c
7186 +++ b/arch/mips/kernel/reset.c
7187 @@ -13,6 +13,7 @@
7188 #include <linux/reboot.h>
7189
7190 #include <asm/reboot.h>
7191 +#include <asm/bug.h>
7192
7193 /*
7194 * Urgs ... Too many MIPS machines to handle this in a generic way.
7195 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7196 {
7197 if (_machine_restart)
7198 _machine_restart(command);
7199 + BUG();
7200 }
7201
7202 void machine_halt(void)
7203 {
7204 if (_machine_halt)
7205 _machine_halt();
7206 + BUG();
7207 }
7208
7209 void machine_power_off(void)
7210 {
7211 if (pm_power_off)
7212 pm_power_off();
7213 + BUG();
7214 }
7215 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7216 index 2242bdd..b284048 100644
7217 --- a/arch/mips/kernel/sync-r4k.c
7218 +++ b/arch/mips/kernel/sync-r4k.c
7219 @@ -18,8 +18,8 @@
7220 #include <asm/mipsregs.h>
7221
7222 static atomic_t count_start_flag = ATOMIC_INIT(0);
7223 -static atomic_t count_count_start = ATOMIC_INIT(0);
7224 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7225 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7226 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7227 static atomic_t count_reference = ATOMIC_INIT(0);
7228
7229 #define COUNTON 100
7230 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7231
7232 for (i = 0; i < NR_LOOPS; i++) {
7233 /* slaves loop on '!= 2' */
7234 - while (atomic_read(&count_count_start) != 1)
7235 + while (atomic_read_unchecked(&count_count_start) != 1)
7236 mb();
7237 - atomic_set(&count_count_stop, 0);
7238 + atomic_set_unchecked(&count_count_stop, 0);
7239 smp_wmb();
7240
7241 /* this lets the slaves write their count register */
7242 - atomic_inc(&count_count_start);
7243 + atomic_inc_unchecked(&count_count_start);
7244
7245 /*
7246 * Everyone initialises count in the last loop:
7247 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7248 /*
7249 * Wait for all slaves to leave the synchronization point:
7250 */
7251 - while (atomic_read(&count_count_stop) != 1)
7252 + while (atomic_read_unchecked(&count_count_stop) != 1)
7253 mb();
7254 - atomic_set(&count_count_start, 0);
7255 + atomic_set_unchecked(&count_count_start, 0);
7256 smp_wmb();
7257 - atomic_inc(&count_count_stop);
7258 + atomic_inc_unchecked(&count_count_stop);
7259 }
7260 /* Arrange for an interrupt in a short while */
7261 write_c0_compare(read_c0_count() + COUNTON);
7262 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7263 initcount = atomic_read(&count_reference);
7264
7265 for (i = 0; i < NR_LOOPS; i++) {
7266 - atomic_inc(&count_count_start);
7267 - while (atomic_read(&count_count_start) != 2)
7268 + atomic_inc_unchecked(&count_count_start);
7269 + while (atomic_read_unchecked(&count_count_start) != 2)
7270 mb();
7271
7272 /*
7273 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7274 if (i == NR_LOOPS-1)
7275 write_c0_count(initcount);
7276
7277 - atomic_inc(&count_count_stop);
7278 - while (atomic_read(&count_count_stop) != 2)
7279 + atomic_inc_unchecked(&count_count_stop);
7280 + while (atomic_read_unchecked(&count_count_stop) != 2)
7281 mb();
7282 }
7283 /* Arrange for an interrupt in a short while */
7284 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7285 index 22b19c2..c5cc8c4 100644
7286 --- a/arch/mips/kernel/traps.c
7287 +++ b/arch/mips/kernel/traps.c
7288 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7289 siginfo_t info;
7290
7291 prev_state = exception_enter();
7292 - die_if_kernel("Integer overflow", regs);
7293 + if (unlikely(!user_mode(regs))) {
7294 +
7295 +#ifdef CONFIG_PAX_REFCOUNT
7296 + if (fixup_exception(regs)) {
7297 + pax_report_refcount_overflow(regs);
7298 + exception_exit(prev_state);
7299 + return;
7300 + }
7301 +#endif
7302 +
7303 + die("Integer overflow", regs);
7304 + }
7305
7306 info.si_code = FPE_INTOVF;
7307 info.si_signo = SIGFPE;
7308 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
7309 index cd71141..e02c4df 100644
7310 --- a/arch/mips/kvm/mips.c
7311 +++ b/arch/mips/kvm/mips.c
7312 @@ -839,7 +839,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7313 return r;
7314 }
7315
7316 -int kvm_arch_init(void *opaque)
7317 +int kvm_arch_init(const void *opaque)
7318 {
7319 if (kvm_mips_callbacks) {
7320 kvm_err("kvm: module already exists\n");
7321 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7322 index becc42b..9e43d4b 100644
7323 --- a/arch/mips/mm/fault.c
7324 +++ b/arch/mips/mm/fault.c
7325 @@ -28,6 +28,23 @@
7326 #include <asm/highmem.h> /* For VMALLOC_END */
7327 #include <linux/kdebug.h>
7328
7329 +#ifdef CONFIG_PAX_PAGEEXEC
7330 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7331 +{
7332 + unsigned long i;
7333 +
7334 + printk(KERN_ERR "PAX: bytes at PC: ");
7335 + for (i = 0; i < 5; i++) {
7336 + unsigned int c;
7337 + if (get_user(c, (unsigned int *)pc+i))
7338 + printk(KERN_CONT "???????? ");
7339 + else
7340 + printk(KERN_CONT "%08x ", c);
7341 + }
7342 + printk("\n");
7343 +}
7344 +#endif
7345 +
7346 /*
7347 * This routine handles page faults. It determines the address,
7348 * and the problem, and then passes it off to one of the appropriate
7349 @@ -199,6 +216,14 @@ bad_area:
7350 bad_area_nosemaphore:
7351 /* User mode accesses just cause a SIGSEGV */
7352 if (user_mode(regs)) {
7353 +
7354 +#ifdef CONFIG_PAX_PAGEEXEC
7355 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7356 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7357 + do_group_exit(SIGKILL);
7358 + }
7359 +#endif
7360 +
7361 tsk->thread.cp0_badvaddr = address;
7362 tsk->thread.error_code = write;
7363 #if 0
7364 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7365 index f1baadd..5472dca 100644
7366 --- a/arch/mips/mm/mmap.c
7367 +++ b/arch/mips/mm/mmap.c
7368 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7369 struct vm_area_struct *vma;
7370 unsigned long addr = addr0;
7371 int do_color_align;
7372 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7373 struct vm_unmapped_area_info info;
7374
7375 if (unlikely(len > TASK_SIZE))
7376 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7377 do_color_align = 1;
7378
7379 /* requesting a specific address */
7380 +
7381 +#ifdef CONFIG_PAX_RANDMMAP
7382 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7383 +#endif
7384 +
7385 if (addr) {
7386 if (do_color_align)
7387 addr = COLOUR_ALIGN(addr, pgoff);
7388 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7389 addr = PAGE_ALIGN(addr);
7390
7391 vma = find_vma(mm, addr);
7392 - if (TASK_SIZE - len >= addr &&
7393 - (!vma || addr + len <= vma->vm_start))
7394 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7395 return addr;
7396 }
7397
7398 info.length = len;
7399 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7400 info.align_offset = pgoff << PAGE_SHIFT;
7401 + info.threadstack_offset = offset;
7402
7403 if (dir == DOWN) {
7404 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7405 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7406 {
7407 unsigned long random_factor = 0UL;
7408
7409 +#ifdef CONFIG_PAX_RANDMMAP
7410 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7411 +#endif
7412 +
7413 if (current->flags & PF_RANDOMIZE) {
7414 random_factor = get_random_int();
7415 random_factor = random_factor << PAGE_SHIFT;
7416 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7417
7418 if (mmap_is_legacy()) {
7419 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7420 +
7421 +#ifdef CONFIG_PAX_RANDMMAP
7422 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7423 + mm->mmap_base += mm->delta_mmap;
7424 +#endif
7425 +
7426 mm->get_unmapped_area = arch_get_unmapped_area;
7427 } else {
7428 mm->mmap_base = mmap_base(random_factor);
7429 +
7430 +#ifdef CONFIG_PAX_RANDMMAP
7431 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7432 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7433 +#endif
7434 +
7435 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7436 }
7437 }
7438
7439 -static inline unsigned long brk_rnd(void)
7440 -{
7441 - unsigned long rnd = get_random_int();
7442 -
7443 - rnd = rnd << PAGE_SHIFT;
7444 - /* 8MB for 32bit, 256MB for 64bit */
7445 - if (TASK_IS_32BIT_ADDR)
7446 - rnd = rnd & 0x7ffffful;
7447 - else
7448 - rnd = rnd & 0xffffffful;
7449 -
7450 - return rnd;
7451 -}
7452 -
7453 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7454 -{
7455 - unsigned long base = mm->brk;
7456 - unsigned long ret;
7457 -
7458 - ret = PAGE_ALIGN(base + brk_rnd());
7459 -
7460 - if (ret < mm->brk)
7461 - return mm->brk;
7462 -
7463 - return ret;
7464 -}
7465 -
7466 int __virt_addr_valid(const volatile void *kaddr)
7467 {
7468 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7469 diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
7470 index 9f7ecbd..6e370fc 100644
7471 --- a/arch/mips/net/bpf_jit.c
7472 +++ b/arch/mips/net/bpf_jit.c
7473 @@ -1428,5 +1428,6 @@ void bpf_jit_free(struct bpf_prog *fp)
7474 {
7475 if (fp->jited)
7476 module_free(NULL, fp->bpf_func);
7477 - kfree(fp);
7478 +
7479 + bpf_prog_unlock_free(fp);
7480 }
7481 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7482 index 59cccd9..f39ac2f 100644
7483 --- a/arch/mips/pci/pci-octeon.c
7484 +++ b/arch/mips/pci/pci-octeon.c
7485 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7486
7487
7488 static struct pci_ops octeon_pci_ops = {
7489 - octeon_read_config,
7490 - octeon_write_config,
7491 + .read = octeon_read_config,
7492 + .write = octeon_write_config,
7493 };
7494
7495 static struct resource octeon_pci_mem_resource = {
7496 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7497 index 5e36c33..eb4a17b 100644
7498 --- a/arch/mips/pci/pcie-octeon.c
7499 +++ b/arch/mips/pci/pcie-octeon.c
7500 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7501 }
7502
7503 static struct pci_ops octeon_pcie0_ops = {
7504 - octeon_pcie0_read_config,
7505 - octeon_pcie0_write_config,
7506 + .read = octeon_pcie0_read_config,
7507 + .write = octeon_pcie0_write_config,
7508 };
7509
7510 static struct resource octeon_pcie0_mem_resource = {
7511 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7512 };
7513
7514 static struct pci_ops octeon_pcie1_ops = {
7515 - octeon_pcie1_read_config,
7516 - octeon_pcie1_write_config,
7517 + .read = octeon_pcie1_read_config,
7518 + .write = octeon_pcie1_write_config,
7519 };
7520
7521 static struct resource octeon_pcie1_mem_resource = {
7522 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7523 };
7524
7525 static struct pci_ops octeon_dummy_ops = {
7526 - octeon_dummy_read_config,
7527 - octeon_dummy_write_config,
7528 + .read = octeon_dummy_read_config,
7529 + .write = octeon_dummy_write_config,
7530 };
7531
7532 static struct resource octeon_dummy_mem_resource = {
7533 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7534 index a2358b4..7cead4f 100644
7535 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7536 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7537 @@ -187,9 +187,9 @@ void
7538 cont_nmi_dump(void)
7539 {
7540 #ifndef REAL_NMI_SIGNAL
7541 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7542 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7543
7544 - atomic_inc(&nmied_cpus);
7545 + atomic_inc_unchecked(&nmied_cpus);
7546 #endif
7547 /*
7548 * Only allow 1 cpu to proceed
7549 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7550 udelay(10000);
7551 }
7552 #else
7553 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7554 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7555 #endif
7556
7557 /*
7558 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7559 index a046b30..6799527 100644
7560 --- a/arch/mips/sni/rm200.c
7561 +++ b/arch/mips/sni/rm200.c
7562 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7563 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7564 spurious_irq_mask |= irqmask;
7565 }
7566 - atomic_inc(&irq_err_count);
7567 + atomic_inc_unchecked(&irq_err_count);
7568 /*
7569 * Theoretically we do not have to handle this IRQ,
7570 * but in Linux this does not cause problems and is
7571 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7572 index 41e873b..34d33a7 100644
7573 --- a/arch/mips/vr41xx/common/icu.c
7574 +++ b/arch/mips/vr41xx/common/icu.c
7575 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7576
7577 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7578
7579 - atomic_inc(&irq_err_count);
7580 + atomic_inc_unchecked(&irq_err_count);
7581
7582 return -1;
7583 }
7584 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7585 index ae0e4ee..e8f0692 100644
7586 --- a/arch/mips/vr41xx/common/irq.c
7587 +++ b/arch/mips/vr41xx/common/irq.c
7588 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7589 irq_cascade_t *cascade;
7590
7591 if (irq >= NR_IRQS) {
7592 - atomic_inc(&irq_err_count);
7593 + atomic_inc_unchecked(&irq_err_count);
7594 return;
7595 }
7596
7597 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7598 ret = cascade->get_irq(irq);
7599 irq = ret;
7600 if (ret < 0)
7601 - atomic_inc(&irq_err_count);
7602 + atomic_inc_unchecked(&irq_err_count);
7603 else
7604 irq_dispatch(irq);
7605 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7606 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7607 index 967d144..db12197 100644
7608 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7609 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7610 @@ -11,12 +11,14 @@
7611 #ifndef _ASM_PROC_CACHE_H
7612 #define _ASM_PROC_CACHE_H
7613
7614 +#include <linux/const.h>
7615 +
7616 /* L1 cache */
7617
7618 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7619 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7620 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7621 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7622 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7623 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7624
7625 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7626 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7627 index bcb5df2..84fabd2 100644
7628 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7629 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7630 @@ -16,13 +16,15 @@
7631 #ifndef _ASM_PROC_CACHE_H
7632 #define _ASM_PROC_CACHE_H
7633
7634 +#include <linux/const.h>
7635 +
7636 /*
7637 * L1 cache
7638 */
7639 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7640 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7641 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7642 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7643 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7644 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7645
7646 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7647 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7648 index 4ce7a01..449202a 100644
7649 --- a/arch/openrisc/include/asm/cache.h
7650 +++ b/arch/openrisc/include/asm/cache.h
7651 @@ -19,11 +19,13 @@
7652 #ifndef __ASM_OPENRISC_CACHE_H
7653 #define __ASM_OPENRISC_CACHE_H
7654
7655 +#include <linux/const.h>
7656 +
7657 /* FIXME: How can we replace these with values from the CPU...
7658 * they shouldn't be hard-coded!
7659 */
7660
7661 -#define L1_CACHE_BYTES 16
7662 #define L1_CACHE_SHIFT 4
7663 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7664
7665 #endif /* __ASM_OPENRISC_CACHE_H */
7666 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7667 index 0be2db2..1b0f26d 100644
7668 --- a/arch/parisc/include/asm/atomic.h
7669 +++ b/arch/parisc/include/asm/atomic.h
7670 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7671 return dec;
7672 }
7673
7674 +#define atomic64_read_unchecked(v) atomic64_read(v)
7675 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7676 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7677 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7678 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7679 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7680 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7681 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7682 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7683 +
7684 #endif /* !CONFIG_64BIT */
7685
7686
7687 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7688 index 47f11c7..3420df2 100644
7689 --- a/arch/parisc/include/asm/cache.h
7690 +++ b/arch/parisc/include/asm/cache.h
7691 @@ -5,6 +5,7 @@
7692 #ifndef __ARCH_PARISC_CACHE_H
7693 #define __ARCH_PARISC_CACHE_H
7694
7695 +#include <linux/const.h>
7696
7697 /*
7698 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7699 @@ -15,13 +16,13 @@
7700 * just ruin performance.
7701 */
7702 #ifdef CONFIG_PA20
7703 -#define L1_CACHE_BYTES 64
7704 #define L1_CACHE_SHIFT 6
7705 #else
7706 -#define L1_CACHE_BYTES 32
7707 #define L1_CACHE_SHIFT 5
7708 #endif
7709
7710 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7711 +
7712 #ifndef __ASSEMBLY__
7713
7714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7715 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7716 index 3391d06..c23a2cc 100644
7717 --- a/arch/parisc/include/asm/elf.h
7718 +++ b/arch/parisc/include/asm/elf.h
7719 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7720
7721 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7722
7723 +#ifdef CONFIG_PAX_ASLR
7724 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7725 +
7726 +#define PAX_DELTA_MMAP_LEN 16
7727 +#define PAX_DELTA_STACK_LEN 16
7728 +#endif
7729 +
7730 /* This yields a mask that user programs can use to figure out what
7731 instruction set this CPU supports. This could be done in user space,
7732 but it's not easy, and we've already done it here. */
7733 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7734 index f213f5b..0af3e8e 100644
7735 --- a/arch/parisc/include/asm/pgalloc.h
7736 +++ b/arch/parisc/include/asm/pgalloc.h
7737 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7738 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7739 }
7740
7741 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7742 +{
7743 + pgd_populate(mm, pgd, pmd);
7744 +}
7745 +
7746 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7747 {
7748 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7749 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7750 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7751 #define pmd_free(mm, x) do { } while (0)
7752 #define pgd_populate(mm, pmd, pte) BUG()
7753 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7754
7755 #endif
7756
7757 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7758 index 22b89d1..ce34230 100644
7759 --- a/arch/parisc/include/asm/pgtable.h
7760 +++ b/arch/parisc/include/asm/pgtable.h
7761 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7762 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7763 #define PAGE_COPY PAGE_EXECREAD
7764 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7765 +
7766 +#ifdef CONFIG_PAX_PAGEEXEC
7767 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7768 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7769 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7770 +#else
7771 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7772 +# define PAGE_COPY_NOEXEC PAGE_COPY
7773 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7774 +#endif
7775 +
7776 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7777 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7778 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7779 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7780 index 4006964..fcb3cc2 100644
7781 --- a/arch/parisc/include/asm/uaccess.h
7782 +++ b/arch/parisc/include/asm/uaccess.h
7783 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7784 const void __user *from,
7785 unsigned long n)
7786 {
7787 - int sz = __compiletime_object_size(to);
7788 + size_t sz = __compiletime_object_size(to);
7789 int ret = -EFAULT;
7790
7791 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7792 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7793 ret = __copy_from_user(to, from, n);
7794 else
7795 copy_from_user_overflow();
7796 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7797 index 50dfafc..b9fc230 100644
7798 --- a/arch/parisc/kernel/module.c
7799 +++ b/arch/parisc/kernel/module.c
7800 @@ -98,16 +98,38 @@
7801
7802 /* three functions to determine where in the module core
7803 * or init pieces the location is */
7804 +static inline int in_init_rx(struct module *me, void *loc)
7805 +{
7806 + return (loc >= me->module_init_rx &&
7807 + loc < (me->module_init_rx + me->init_size_rx));
7808 +}
7809 +
7810 +static inline int in_init_rw(struct module *me, void *loc)
7811 +{
7812 + return (loc >= me->module_init_rw &&
7813 + loc < (me->module_init_rw + me->init_size_rw));
7814 +}
7815 +
7816 static inline int in_init(struct module *me, void *loc)
7817 {
7818 - return (loc >= me->module_init &&
7819 - loc <= (me->module_init + me->init_size));
7820 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7821 +}
7822 +
7823 +static inline int in_core_rx(struct module *me, void *loc)
7824 +{
7825 + return (loc >= me->module_core_rx &&
7826 + loc < (me->module_core_rx + me->core_size_rx));
7827 +}
7828 +
7829 +static inline int in_core_rw(struct module *me, void *loc)
7830 +{
7831 + return (loc >= me->module_core_rw &&
7832 + loc < (me->module_core_rw + me->core_size_rw));
7833 }
7834
7835 static inline int in_core(struct module *me, void *loc)
7836 {
7837 - return (loc >= me->module_core &&
7838 - loc <= (me->module_core + me->core_size));
7839 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7840 }
7841
7842 static inline int in_local(struct module *me, void *loc)
7843 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7844 }
7845
7846 /* align things a bit */
7847 - me->core_size = ALIGN(me->core_size, 16);
7848 - me->arch.got_offset = me->core_size;
7849 - me->core_size += gots * sizeof(struct got_entry);
7850 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7851 + me->arch.got_offset = me->core_size_rw;
7852 + me->core_size_rw += gots * sizeof(struct got_entry);
7853
7854 - me->core_size = ALIGN(me->core_size, 16);
7855 - me->arch.fdesc_offset = me->core_size;
7856 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7857 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7858 + me->arch.fdesc_offset = me->core_size_rw;
7859 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7860
7861 me->arch.got_max = gots;
7862 me->arch.fdesc_max = fdescs;
7863 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7864
7865 BUG_ON(value == 0);
7866
7867 - got = me->module_core + me->arch.got_offset;
7868 + got = me->module_core_rw + me->arch.got_offset;
7869 for (i = 0; got[i].addr; i++)
7870 if (got[i].addr == value)
7871 goto out;
7872 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7873 #ifdef CONFIG_64BIT
7874 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7875 {
7876 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7877 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7878
7879 if (!value) {
7880 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7881 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7882
7883 /* Create new one */
7884 fdesc->addr = value;
7885 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7886 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7887 return (Elf_Addr)fdesc;
7888 }
7889 #endif /* CONFIG_64BIT */
7890 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7891
7892 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7893 end = table + sechdrs[me->arch.unwind_section].sh_size;
7894 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7895 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7896
7897 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7898 me->arch.unwind_section, table, end, gp);
7899 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7900 index e1ffea2..46ed66e 100644
7901 --- a/arch/parisc/kernel/sys_parisc.c
7902 +++ b/arch/parisc/kernel/sys_parisc.c
7903 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7904 unsigned long task_size = TASK_SIZE;
7905 int do_color_align, last_mmap;
7906 struct vm_unmapped_area_info info;
7907 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7908
7909 if (len > task_size)
7910 return -ENOMEM;
7911 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7912 goto found_addr;
7913 }
7914
7915 +#ifdef CONFIG_PAX_RANDMMAP
7916 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7917 +#endif
7918 +
7919 if (addr) {
7920 if (do_color_align && last_mmap)
7921 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7922 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7923 info.high_limit = mmap_upper_limit();
7924 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7925 info.align_offset = shared_align_offset(last_mmap, pgoff);
7926 + info.threadstack_offset = offset;
7927 addr = vm_unmapped_area(&info);
7928
7929 found_addr:
7930 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7931 unsigned long addr = addr0;
7932 int do_color_align, last_mmap;
7933 struct vm_unmapped_area_info info;
7934 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7935
7936 #ifdef CONFIG_64BIT
7937 /* This should only ever run for 32-bit processes. */
7938 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7939 }
7940
7941 /* requesting a specific address */
7942 +#ifdef CONFIG_PAX_RANDMMAP
7943 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7944 +#endif
7945 +
7946 if (addr) {
7947 if (do_color_align && last_mmap)
7948 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7949 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7950 info.high_limit = mm->mmap_base;
7951 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7952 info.align_offset = shared_align_offset(last_mmap, pgoff);
7953 + info.threadstack_offset = offset;
7954 addr = vm_unmapped_area(&info);
7955 if (!(addr & ~PAGE_MASK))
7956 goto found_addr;
7957 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7958 mm->mmap_legacy_base = mmap_legacy_base();
7959 mm->mmap_base = mmap_upper_limit();
7960
7961 +#ifdef CONFIG_PAX_RANDMMAP
7962 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7963 + mm->mmap_legacy_base += mm->delta_mmap;
7964 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7965 + }
7966 +#endif
7967 +
7968 if (mmap_is_legacy()) {
7969 mm->mmap_base = mm->mmap_legacy_base;
7970 mm->get_unmapped_area = arch_get_unmapped_area;
7971 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7972 index 47ee620..1107387 100644
7973 --- a/arch/parisc/kernel/traps.c
7974 +++ b/arch/parisc/kernel/traps.c
7975 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7976
7977 down_read(&current->mm->mmap_sem);
7978 vma = find_vma(current->mm,regs->iaoq[0]);
7979 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7980 - && (vma->vm_flags & VM_EXEC)) {
7981 -
7982 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7983 fault_address = regs->iaoq[0];
7984 fault_space = regs->iasq[0];
7985
7986 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7987 index 3ca9c11..d163ef7 100644
7988 --- a/arch/parisc/mm/fault.c
7989 +++ b/arch/parisc/mm/fault.c
7990 @@ -15,6 +15,7 @@
7991 #include <linux/sched.h>
7992 #include <linux/interrupt.h>
7993 #include <linux/module.h>
7994 +#include <linux/unistd.h>
7995
7996 #include <asm/uaccess.h>
7997 #include <asm/traps.h>
7998 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7999 static unsigned long
8000 parisc_acctyp(unsigned long code, unsigned int inst)
8001 {
8002 - if (code == 6 || code == 16)
8003 + if (code == 6 || code == 7 || code == 16)
8004 return VM_EXEC;
8005
8006 switch (inst & 0xf0000000) {
8007 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8008 }
8009 #endif
8010
8011 +#ifdef CONFIG_PAX_PAGEEXEC
8012 +/*
8013 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8014 + *
8015 + * returns 1 when task should be killed
8016 + * 2 when rt_sigreturn trampoline was detected
8017 + * 3 when unpatched PLT trampoline was detected
8018 + */
8019 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8020 +{
8021 +
8022 +#ifdef CONFIG_PAX_EMUPLT
8023 + int err;
8024 +
8025 + do { /* PaX: unpatched PLT emulation */
8026 + unsigned int bl, depwi;
8027 +
8028 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8029 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8030 +
8031 + if (err)
8032 + break;
8033 +
8034 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8035 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8036 +
8037 + err = get_user(ldw, (unsigned int *)addr);
8038 + err |= get_user(bv, (unsigned int *)(addr+4));
8039 + err |= get_user(ldw2, (unsigned int *)(addr+8));
8040 +
8041 + if (err)
8042 + break;
8043 +
8044 + if (ldw == 0x0E801096U &&
8045 + bv == 0xEAC0C000U &&
8046 + ldw2 == 0x0E881095U)
8047 + {
8048 + unsigned int resolver, map;
8049 +
8050 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8051 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8052 + if (err)
8053 + break;
8054 +
8055 + regs->gr[20] = instruction_pointer(regs)+8;
8056 + regs->gr[21] = map;
8057 + regs->gr[22] = resolver;
8058 + regs->iaoq[0] = resolver | 3UL;
8059 + regs->iaoq[1] = regs->iaoq[0] + 4;
8060 + return 3;
8061 + }
8062 + }
8063 + } while (0);
8064 +#endif
8065 +
8066 +#ifdef CONFIG_PAX_EMUTRAMP
8067 +
8068 +#ifndef CONFIG_PAX_EMUSIGRT
8069 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8070 + return 1;
8071 +#endif
8072 +
8073 + do { /* PaX: rt_sigreturn emulation */
8074 + unsigned int ldi1, ldi2, bel, nop;
8075 +
8076 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8077 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8078 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8079 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8080 +
8081 + if (err)
8082 + break;
8083 +
8084 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8085 + ldi2 == 0x3414015AU &&
8086 + bel == 0xE4008200U &&
8087 + nop == 0x08000240U)
8088 + {
8089 + regs->gr[25] = (ldi1 & 2) >> 1;
8090 + regs->gr[20] = __NR_rt_sigreturn;
8091 + regs->gr[31] = regs->iaoq[1] + 16;
8092 + regs->sr[0] = regs->iasq[1];
8093 + regs->iaoq[0] = 0x100UL;
8094 + regs->iaoq[1] = regs->iaoq[0] + 4;
8095 + regs->iasq[0] = regs->sr[2];
8096 + regs->iasq[1] = regs->sr[2];
8097 + return 2;
8098 + }
8099 + } while (0);
8100 +#endif
8101 +
8102 + return 1;
8103 +}
8104 +
8105 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8106 +{
8107 + unsigned long i;
8108 +
8109 + printk(KERN_ERR "PAX: bytes at PC: ");
8110 + for (i = 0; i < 5; i++) {
8111 + unsigned int c;
8112 + if (get_user(c, (unsigned int *)pc+i))
8113 + printk(KERN_CONT "???????? ");
8114 + else
8115 + printk(KERN_CONT "%08x ", c);
8116 + }
8117 + printk("\n");
8118 +}
8119 +#endif
8120 +
8121 int fixup_exception(struct pt_regs *regs)
8122 {
8123 const struct exception_table_entry *fix;
8124 @@ -234,8 +345,33 @@ retry:
8125
8126 good_area:
8127
8128 - if ((vma->vm_flags & acc_type) != acc_type)
8129 + if ((vma->vm_flags & acc_type) != acc_type) {
8130 +
8131 +#ifdef CONFIG_PAX_PAGEEXEC
8132 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8133 + (address & ~3UL) == instruction_pointer(regs))
8134 + {
8135 + up_read(&mm->mmap_sem);
8136 + switch (pax_handle_fetch_fault(regs)) {
8137 +
8138 +#ifdef CONFIG_PAX_EMUPLT
8139 + case 3:
8140 + return;
8141 +#endif
8142 +
8143 +#ifdef CONFIG_PAX_EMUTRAMP
8144 + case 2:
8145 + return;
8146 +#endif
8147 +
8148 + }
8149 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8150 + do_group_exit(SIGKILL);
8151 + }
8152 +#endif
8153 +
8154 goto bad_area;
8155 + }
8156
8157 /*
8158 * If for any reason at all we couldn't handle the fault, make
8159 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8160 index 4bc7b62..107e0b2 100644
8161 --- a/arch/powerpc/Kconfig
8162 +++ b/arch/powerpc/Kconfig
8163 @@ -399,6 +399,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8164 config KEXEC
8165 bool "kexec system call"
8166 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8167 + depends on !GRKERNSEC_KMEM
8168 help
8169 kexec is a system call that implements the ability to shutdown your
8170 current kernel, and to start another kernel. It is like a reboot
8171 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8172 index 28992d0..434c881 100644
8173 --- a/arch/powerpc/include/asm/atomic.h
8174 +++ b/arch/powerpc/include/asm/atomic.h
8175 @@ -12,6 +12,11 @@
8176
8177 #define ATOMIC_INIT(i) { (i) }
8178
8179 +#define _ASM_EXTABLE(from, to) \
8180 +" .section __ex_table,\"a\"\n" \
8181 + PPC_LONG" " #from ", " #to"\n" \
8182 +" .previous\n"
8183 +
8184 static __inline__ int atomic_read(const atomic_t *v)
8185 {
8186 int t;
8187 @@ -21,16 +26,61 @@ static __inline__ int atomic_read(const atomic_t *v)
8188 return t;
8189 }
8190
8191 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
8192 +{
8193 + int t;
8194 +
8195 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8196 +
8197 + return t;
8198 +}
8199 +
8200 static __inline__ void atomic_set(atomic_t *v, int i)
8201 {
8202 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8203 }
8204
8205 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8206 +{
8207 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8208 +}
8209 +
8210 static __inline__ void atomic_add(int a, atomic_t *v)
8211 {
8212 int t;
8213
8214 __asm__ __volatile__(
8215 +"1: lwarx %0,0,%3 # atomic_add\n"
8216 +
8217 +#ifdef CONFIG_PAX_REFCOUNT
8218 +" mcrxr cr0\n"
8219 +" addo. %0,%2,%0\n"
8220 +" bf 4*cr0+so, 3f\n"
8221 +"2:.long " "0x00c00b00""\n"
8222 +#else
8223 +" add %0,%2,%0\n"
8224 +#endif
8225 +
8226 +"3:\n"
8227 + PPC405_ERR77(0,%3)
8228 +" stwcx. %0,0,%3 \n\
8229 + bne- 1b"
8230 +
8231 +#ifdef CONFIG_PAX_REFCOUNT
8232 +"\n4:\n"
8233 + _ASM_EXTABLE(2b, 4b)
8234 +#endif
8235 +
8236 + : "=&r" (t), "+m" (v->counter)
8237 + : "r" (a), "r" (&v->counter)
8238 + : "cc");
8239 +}
8240 +
8241 +static __inline__ void atomic_add_unchecked(int a, atomic_unchecked_t *v)
8242 +{
8243 + int t;
8244 +
8245 + __asm__ __volatile__(
8246 "1: lwarx %0,0,%3 # atomic_add\n\
8247 add %0,%2,%0\n"
8248 PPC405_ERR77(0,%3)
8249 @@ -41,12 +91,49 @@ static __inline__ void atomic_add(int a, atomic_t *v)
8250 : "cc");
8251 }
8252
8253 +/* Same as atomic_add but return the value */
8254 static __inline__ int atomic_add_return(int a, atomic_t *v)
8255 {
8256 int t;
8257
8258 __asm__ __volatile__(
8259 PPC_ATOMIC_ENTRY_BARRIER
8260 +"1: lwarx %0,0,%2 # atomic_add_return\n"
8261 +
8262 +#ifdef CONFIG_PAX_REFCOUNT
8263 +" mcrxr cr0\n"
8264 +" addo. %0,%1,%0\n"
8265 +" bf 4*cr0+so, 3f\n"
8266 +"2:.long " "0x00c00b00""\n"
8267 +#else
8268 +" add %0,%1,%0\n"
8269 +#endif
8270 +
8271 +"3:\n"
8272 + PPC405_ERR77(0,%2)
8273 +" stwcx. %0,0,%2 \n\
8274 + bne- 1b\n"
8275 +"4:"
8276 +
8277 +#ifdef CONFIG_PAX_REFCOUNT
8278 + _ASM_EXTABLE(2b, 4b)
8279 +#endif
8280 +
8281 + PPC_ATOMIC_EXIT_BARRIER
8282 + : "=&r" (t)
8283 + : "r" (a), "r" (&v->counter)
8284 + : "cc", "memory");
8285 +
8286 + return t;
8287 +}
8288 +
8289 +/* Same as atomic_add_unchecked but return the value */
8290 +static __inline__ int atomic_add_return_unchecked(int a, atomic_unchecked_t *v)
8291 +{
8292 + int t;
8293 +
8294 + __asm__ __volatile__(
8295 + PPC_ATOMIC_ENTRY_BARRIER
8296 "1: lwarx %0,0,%2 # atomic_add_return\n\
8297 add %0,%1,%0\n"
8298 PPC405_ERR77(0,%2)
8299 @@ -67,6 +154,37 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8300 int t;
8301
8302 __asm__ __volatile__(
8303 +"1: lwarx %0,0,%3 # atomic_sub\n"
8304 +
8305 +#ifdef CONFIG_PAX_REFCOUNT
8306 +" mcrxr cr0\n"
8307 +" subfo. %0,%2,%0\n"
8308 +" bf 4*cr0+so, 3f\n"
8309 +"2:.long " "0x00c00b00""\n"
8310 +#else
8311 +" subf %0,%2,%0\n"
8312 +#endif
8313 +
8314 +"3:\n"
8315 + PPC405_ERR77(0,%3)
8316 +" stwcx. %0,0,%3 \n\
8317 + bne- 1b\n"
8318 +"4:"
8319 +
8320 +#ifdef CONFIG_PAX_REFCOUNT
8321 + _ASM_EXTABLE(2b, 4b)
8322 +#endif
8323 +
8324 + : "=&r" (t), "+m" (v->counter)
8325 + : "r" (a), "r" (&v->counter)
8326 + : "cc");
8327 +}
8328 +
8329 +static __inline__ void atomic_sub_unchecked(int a, atomic_unchecked_t *v)
8330 +{
8331 + int t;
8332 +
8333 + __asm__ __volatile__(
8334 "1: lwarx %0,0,%3 # atomic_sub\n\
8335 subf %0,%2,%0\n"
8336 PPC405_ERR77(0,%3)
8337 @@ -77,12 +195,49 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8338 : "cc");
8339 }
8340
8341 +/* Same as atomic_sub but return the value */
8342 static __inline__ int atomic_sub_return(int a, atomic_t *v)
8343 {
8344 int t;
8345
8346 __asm__ __volatile__(
8347 PPC_ATOMIC_ENTRY_BARRIER
8348 +"1: lwarx %0,0,%2 # atomic_sub_return\n"
8349 +
8350 +#ifdef CONFIG_PAX_REFCOUNT
8351 +" mcrxr cr0\n"
8352 +" subfo. %0,%1,%0\n"
8353 +" bf 4*cr0+so, 3f\n"
8354 +"2:.long " "0x00c00b00""\n"
8355 +#else
8356 +" subf %0,%1,%0\n"
8357 +#endif
8358 +
8359 +"3:\n"
8360 + PPC405_ERR77(0,%2)
8361 +" stwcx. %0,0,%2 \n\
8362 + bne- 1b\n"
8363 + PPC_ATOMIC_EXIT_BARRIER
8364 +"4:"
8365 +
8366 +#ifdef CONFIG_PAX_REFCOUNT
8367 + _ASM_EXTABLE(2b, 4b)
8368 +#endif
8369 +
8370 + : "=&r" (t)
8371 + : "r" (a), "r" (&v->counter)
8372 + : "cc", "memory");
8373 +
8374 + return t;
8375 +}
8376 +
8377 +/* Same as atomic_sub_unchecked but return the value */
8378 +static __inline__ int atomic_sub_return_unchecked(int a, atomic_unchecked_t *v)
8379 +{
8380 + int t;
8381 +
8382 + __asm__ __volatile__(
8383 + PPC_ATOMIC_ENTRY_BARRIER
8384 "1: lwarx %0,0,%2 # atomic_sub_return\n\
8385 subf %0,%1,%0\n"
8386 PPC405_ERR77(0,%2)
8387 @@ -96,38 +251,23 @@ static __inline__ int atomic_sub_return(int a, atomic_t *v)
8388 return t;
8389 }
8390
8391 -static __inline__ void atomic_inc(atomic_t *v)
8392 -{
8393 - int t;
8394 +/*
8395 + * atomic_inc - increment atomic variable
8396 + * @v: pointer of type atomic_t
8397 + *
8398 + * Automatically increments @v by 1
8399 + */
8400 +#define atomic_inc(v) atomic_add(1, (v))
8401 +#define atomic_inc_return(v) atomic_add_return(1, (v))
8402
8403 - __asm__ __volatile__(
8404 -"1: lwarx %0,0,%2 # atomic_inc\n\
8405 - addic %0,%0,1\n"
8406 - PPC405_ERR77(0,%2)
8407 -" stwcx. %0,0,%2 \n\
8408 - bne- 1b"
8409 - : "=&r" (t), "+m" (v->counter)
8410 - : "r" (&v->counter)
8411 - : "cc", "xer");
8412 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
8413 +{
8414 + atomic_add_unchecked(1, v);
8415 }
8416
8417 -static __inline__ int atomic_inc_return(atomic_t *v)
8418 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8419 {
8420 - int t;
8421 -
8422 - __asm__ __volatile__(
8423 - PPC_ATOMIC_ENTRY_BARRIER
8424 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
8425 - addic %0,%0,1\n"
8426 - PPC405_ERR77(0,%1)
8427 -" stwcx. %0,0,%1 \n\
8428 - bne- 1b"
8429 - PPC_ATOMIC_EXIT_BARRIER
8430 - : "=&r" (t)
8431 - : "r" (&v->counter)
8432 - : "cc", "xer", "memory");
8433 -
8434 - return t;
8435 + return atomic_add_return_unchecked(1, v);
8436 }
8437
8438 /*
8439 @@ -140,43 +280,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
8440 */
8441 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8442
8443 -static __inline__ void atomic_dec(atomic_t *v)
8444 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8445 {
8446 - int t;
8447 -
8448 - __asm__ __volatile__(
8449 -"1: lwarx %0,0,%2 # atomic_dec\n\
8450 - addic %0,%0,-1\n"
8451 - PPC405_ERR77(0,%2)\
8452 -" stwcx. %0,0,%2\n\
8453 - bne- 1b"
8454 - : "=&r" (t), "+m" (v->counter)
8455 - : "r" (&v->counter)
8456 - : "cc", "xer");
8457 + return atomic_add_return_unchecked(1, v) == 0;
8458 }
8459
8460 -static __inline__ int atomic_dec_return(atomic_t *v)
8461 +/*
8462 + * atomic_dec - decrement atomic variable
8463 + * @v: pointer of type atomic_t
8464 + *
8465 + * Atomically decrements @v by 1
8466 + */
8467 +#define atomic_dec(v) atomic_sub(1, (v))
8468 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
8469 +
8470 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
8471 {
8472 - int t;
8473 -
8474 - __asm__ __volatile__(
8475 - PPC_ATOMIC_ENTRY_BARRIER
8476 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
8477 - addic %0,%0,-1\n"
8478 - PPC405_ERR77(0,%1)
8479 -" stwcx. %0,0,%1\n\
8480 - bne- 1b"
8481 - PPC_ATOMIC_EXIT_BARRIER
8482 - : "=&r" (t)
8483 - : "r" (&v->counter)
8484 - : "cc", "xer", "memory");
8485 -
8486 - return t;
8487 + atomic_sub_unchecked(1, v);
8488 }
8489
8490 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8491 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8492
8493 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8494 +{
8495 + return cmpxchg(&(v->counter), old, new);
8496 +}
8497 +
8498 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8499 +{
8500 + return xchg(&(v->counter), new);
8501 +}
8502 +
8503 /**
8504 * __atomic_add_unless - add unless the number is a given value
8505 * @v: pointer of type atomic_t
8506 @@ -271,6 +406,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8507 }
8508 #define atomic_dec_if_positive atomic_dec_if_positive
8509
8510 +#define smp_mb__before_atomic_dec() smp_mb()
8511 +#define smp_mb__after_atomic_dec() smp_mb()
8512 +#define smp_mb__before_atomic_inc() smp_mb()
8513 +#define smp_mb__after_atomic_inc() smp_mb()
8514 +
8515 #ifdef __powerpc64__
8516
8517 #define ATOMIC64_INIT(i) { (i) }
8518 @@ -284,11 +424,25 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8519 return t;
8520 }
8521
8522 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8523 +{
8524 + long t;
8525 +
8526 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8527 +
8528 + return t;
8529 +}
8530 +
8531 static __inline__ void atomic64_set(atomic64_t *v, long i)
8532 {
8533 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8534 }
8535
8536 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8537 +{
8538 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8539 +}
8540 +
8541 static __inline__ void atomic64_add(long a, atomic64_t *v)
8542 {
8543 long t;
8544 @@ -303,12 +457,76 @@ static __inline__ void atomic64_add(long a, atomic64_t *v)
8545 : "cc");
8546 }
8547
8548 +static __inline__ void atomic64_add_unchecked(long a, atomic64_unchecked_t *v)
8549 +{
8550 + long t;
8551 +
8552 + __asm__ __volatile__(
8553 +"1: ldarx %0,0,%3 # atomic64_add\n"
8554 +
8555 +#ifdef CONFIG_PAX_REFCOUNT
8556 +" mcrxr cr0\n"
8557 +" addo. %0,%2,%0\n"
8558 +" bf 4*cr0+so, 3f\n"
8559 +"2:.long " "0x00c00b00""\n"
8560 +#else
8561 +" add %0,%2,%0\n"
8562 +#endif
8563 +
8564 +"3:\n"
8565 +" stdcx. %0,0,%3 \n\
8566 + bne- 1b\n"
8567 +"4:"
8568 +
8569 +#ifdef CONFIG_PAX_REFCOUNT
8570 + _ASM_EXTABLE(2b, 4b)
8571 +#endif
8572 +
8573 + : "=&r" (t), "+m" (v->counter)
8574 + : "r" (a), "r" (&v->counter)
8575 + : "cc");
8576 +}
8577 +
8578 static __inline__ long atomic64_add_return(long a, atomic64_t *v)
8579 {
8580 long t;
8581
8582 __asm__ __volatile__(
8583 PPC_ATOMIC_ENTRY_BARRIER
8584 +"1: ldarx %0,0,%2 # atomic64_add_return\n"
8585 +
8586 +#ifdef CONFIG_PAX_REFCOUNT
8587 +" mcrxr cr0\n"
8588 +" addo. %0,%1,%0\n"
8589 +" bf 4*cr0+so, 3f\n"
8590 +"2:.long " "0x00c00b00""\n"
8591 +#else
8592 +" add %0,%1,%0\n"
8593 +#endif
8594 +
8595 +"3:\n"
8596 +" stdcx. %0,0,%2 \n\
8597 + bne- 1b\n"
8598 + PPC_ATOMIC_EXIT_BARRIER
8599 +"4:"
8600 +
8601 +#ifdef CONFIG_PAX_REFCOUNT
8602 + _ASM_EXTABLE(2b, 4b)
8603 +#endif
8604 +
8605 + : "=&r" (t)
8606 + : "r" (a), "r" (&v->counter)
8607 + : "cc", "memory");
8608 +
8609 + return t;
8610 +}
8611 +
8612 +static __inline__ long atomic64_add_return_unchecked(long a, atomic64_unchecked_t *v)
8613 +{
8614 + long t;
8615 +
8616 + __asm__ __volatile__(
8617 + PPC_ATOMIC_ENTRY_BARRIER
8618 "1: ldarx %0,0,%2 # atomic64_add_return\n\
8619 add %0,%1,%0\n\
8620 stdcx. %0,0,%2 \n\
8621 @@ -328,6 +546,36 @@ static __inline__ void atomic64_sub(long a, atomic64_t *v)
8622 long t;
8623
8624 __asm__ __volatile__(
8625 +"1: ldarx %0,0,%3 # atomic64_sub\n"
8626 +
8627 +#ifdef CONFIG_PAX_REFCOUNT
8628 +" mcrxr cr0\n"
8629 +" subfo. %0,%2,%0\n"
8630 +" bf 4*cr0+so, 3f\n"
8631 +"2:.long " "0x00c00b00""\n"
8632 +#else
8633 +" subf %0,%2,%0\n"
8634 +#endif
8635 +
8636 +"3:\n"
8637 +" stdcx. %0,0,%3 \n\
8638 + bne- 1b"
8639 +"4:"
8640 +
8641 +#ifdef CONFIG_PAX_REFCOUNT
8642 + _ASM_EXTABLE(2b, 4b)
8643 +#endif
8644 +
8645 + : "=&r" (t), "+m" (v->counter)
8646 + : "r" (a), "r" (&v->counter)
8647 + : "cc");
8648 +}
8649 +
8650 +static __inline__ void atomic64_sub_unchecked(long a, atomic64_unchecked_t *v)
8651 +{
8652 + long t;
8653 +
8654 + __asm__ __volatile__(
8655 "1: ldarx %0,0,%3 # atomic64_sub\n\
8656 subf %0,%2,%0\n\
8657 stdcx. %0,0,%3 \n\
8658 @@ -343,6 +591,40 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8659
8660 __asm__ __volatile__(
8661 PPC_ATOMIC_ENTRY_BARRIER
8662 +"1: ldarx %0,0,%2 # atomic64_sub_return\n"
8663 +
8664 +#ifdef CONFIG_PAX_REFCOUNT
8665 +" mcrxr cr0\n"
8666 +" subfo. %0,%1,%0\n"
8667 +" bf 4*cr0+so, 3f\n"
8668 +"2:.long " "0x00c00b00""\n"
8669 +#else
8670 +" subf %0,%1,%0\n"
8671 +#endif
8672 +
8673 +"3:\n"
8674 +" stdcx. %0,0,%2 \n\
8675 + bne- 1b\n"
8676 + PPC_ATOMIC_EXIT_BARRIER
8677 +"4:"
8678 +
8679 +#ifdef CONFIG_PAX_REFCOUNT
8680 + _ASM_EXTABLE(2b, 4b)
8681 +#endif
8682 +
8683 + : "=&r" (t)
8684 + : "r" (a), "r" (&v->counter)
8685 + : "cc", "memory");
8686 +
8687 + return t;
8688 +}
8689 +
8690 +static __inline__ long atomic64_sub_return_unchecked(long a, atomic64_unchecked_t *v)
8691 +{
8692 + long t;
8693 +
8694 + __asm__ __volatile__(
8695 + PPC_ATOMIC_ENTRY_BARRIER
8696 "1: ldarx %0,0,%2 # atomic64_sub_return\n\
8697 subf %0,%1,%0\n\
8698 stdcx. %0,0,%2 \n\
8699 @@ -355,36 +637,23 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8700 return t;
8701 }
8702
8703 -static __inline__ void atomic64_inc(atomic64_t *v)
8704 -{
8705 - long t;
8706 +/*
8707 + * atomic64_inc - increment atomic variable
8708 + * @v: pointer of type atomic64_t
8709 + *
8710 + * Automatically increments @v by 1
8711 + */
8712 +#define atomic64_inc(v) atomic64_add(1, (v))
8713 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8714
8715 - __asm__ __volatile__(
8716 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8717 - addic %0,%0,1\n\
8718 - stdcx. %0,0,%2 \n\
8719 - bne- 1b"
8720 - : "=&r" (t), "+m" (v->counter)
8721 - : "r" (&v->counter)
8722 - : "cc", "xer");
8723 +static __inline__ void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8724 +{
8725 + atomic64_add_unchecked(1, v);
8726 }
8727
8728 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8729 +static __inline__ int atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8730 {
8731 - long t;
8732 -
8733 - __asm__ __volatile__(
8734 - PPC_ATOMIC_ENTRY_BARRIER
8735 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8736 - addic %0,%0,1\n\
8737 - stdcx. %0,0,%1 \n\
8738 - bne- 1b"
8739 - PPC_ATOMIC_EXIT_BARRIER
8740 - : "=&r" (t)
8741 - : "r" (&v->counter)
8742 - : "cc", "xer", "memory");
8743 -
8744 - return t;
8745 + return atomic64_add_return_unchecked(1, v);
8746 }
8747
8748 /*
8749 @@ -397,36 +666,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8750 */
8751 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8752
8753 -static __inline__ void atomic64_dec(atomic64_t *v)
8754 +/*
8755 + * atomic64_dec - decrement atomic variable
8756 + * @v: pointer of type atomic64_t
8757 + *
8758 + * Atomically decrements @v by 1
8759 + */
8760 +#define atomic64_dec(v) atomic64_sub(1, (v))
8761 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8762 +
8763 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8764 {
8765 - long t;
8766 -
8767 - __asm__ __volatile__(
8768 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8769 - addic %0,%0,-1\n\
8770 - stdcx. %0,0,%2\n\
8771 - bne- 1b"
8772 - : "=&r" (t), "+m" (v->counter)
8773 - : "r" (&v->counter)
8774 - : "cc", "xer");
8775 -}
8776 -
8777 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8778 -{
8779 - long t;
8780 -
8781 - __asm__ __volatile__(
8782 - PPC_ATOMIC_ENTRY_BARRIER
8783 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8784 - addic %0,%0,-1\n\
8785 - stdcx. %0,0,%1\n\
8786 - bne- 1b"
8787 - PPC_ATOMIC_EXIT_BARRIER
8788 - : "=&r" (t)
8789 - : "r" (&v->counter)
8790 - : "cc", "xer", "memory");
8791 -
8792 - return t;
8793 + atomic64_sub_unchecked(1, v);
8794 }
8795
8796 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8797 @@ -459,6 +710,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8798 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8799 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8800
8801 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8802 +{
8803 + return cmpxchg(&(v->counter), old, new);
8804 +}
8805 +
8806 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8807 +{
8808 + return xchg(&(v->counter), new);
8809 +}
8810 +
8811 /**
8812 * atomic64_add_unless - add unless the number is a given value
8813 * @v: pointer of type atomic64_t
8814 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8815 index bab79a1..4a3eabc 100644
8816 --- a/arch/powerpc/include/asm/barrier.h
8817 +++ b/arch/powerpc/include/asm/barrier.h
8818 @@ -73,7 +73,7 @@
8819 do { \
8820 compiletime_assert_atomic_type(*p); \
8821 __lwsync(); \
8822 - ACCESS_ONCE(*p) = (v); \
8823 + ACCESS_ONCE_RW(*p) = (v); \
8824 } while (0)
8825
8826 #define smp_load_acquire(p) \
8827 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8828 index 34a05a1..a1f2c67 100644
8829 --- a/arch/powerpc/include/asm/cache.h
8830 +++ b/arch/powerpc/include/asm/cache.h
8831 @@ -4,6 +4,7 @@
8832 #ifdef __KERNEL__
8833
8834 #include <asm/reg.h>
8835 +#include <linux/const.h>
8836
8837 /* bytes per L1 cache line */
8838 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8839 @@ -23,7 +24,7 @@
8840 #define L1_CACHE_SHIFT 7
8841 #endif
8842
8843 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8844 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8845
8846 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8847
8848 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8849 index 888d8f3..66f581c 100644
8850 --- a/arch/powerpc/include/asm/elf.h
8851 +++ b/arch/powerpc/include/asm/elf.h
8852 @@ -28,8 +28,19 @@
8853 the loader. We need to make sure that it is out of the way of the program
8854 that it will "exec", and that there is sufficient room for the brk. */
8855
8856 -extern unsigned long randomize_et_dyn(unsigned long base);
8857 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8858 +#define ELF_ET_DYN_BASE (0x20000000)
8859 +
8860 +#ifdef CONFIG_PAX_ASLR
8861 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8862 +
8863 +#ifdef __powerpc64__
8864 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8865 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8866 +#else
8867 +#define PAX_DELTA_MMAP_LEN 15
8868 +#define PAX_DELTA_STACK_LEN 15
8869 +#endif
8870 +#endif
8871
8872 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8873
8874 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8875 (0x7ff >> (PAGE_SHIFT - 12)) : \
8876 (0x3ffff >> (PAGE_SHIFT - 12)))
8877
8878 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8879 -#define arch_randomize_brk arch_randomize_brk
8880 -
8881 -
8882 #ifdef CONFIG_SPU_BASE
8883 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8884 #define NT_SPU 1
8885 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8886 index 8196e9c..d83a9f3 100644
8887 --- a/arch/powerpc/include/asm/exec.h
8888 +++ b/arch/powerpc/include/asm/exec.h
8889 @@ -4,6 +4,6 @@
8890 #ifndef _ASM_POWERPC_EXEC_H
8891 #define _ASM_POWERPC_EXEC_H
8892
8893 -extern unsigned long arch_align_stack(unsigned long sp);
8894 +#define arch_align_stack(x) ((x) & ~0xfUL)
8895
8896 #endif /* _ASM_POWERPC_EXEC_H */
8897 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8898 index 5acabbd..7ea14fa 100644
8899 --- a/arch/powerpc/include/asm/kmap_types.h
8900 +++ b/arch/powerpc/include/asm/kmap_types.h
8901 @@ -10,7 +10,7 @@
8902 * 2 of the License, or (at your option) any later version.
8903 */
8904
8905 -#define KM_TYPE_NR 16
8906 +#define KM_TYPE_NR 17
8907
8908 #endif /* __KERNEL__ */
8909 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8910 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8911 index b8da913..c02b593 100644
8912 --- a/arch/powerpc/include/asm/local.h
8913 +++ b/arch/powerpc/include/asm/local.h
8914 @@ -9,21 +9,65 @@ typedef struct
8915 atomic_long_t a;
8916 } local_t;
8917
8918 +typedef struct
8919 +{
8920 + atomic_long_unchecked_t a;
8921 +} local_unchecked_t;
8922 +
8923 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8924
8925 #define local_read(l) atomic_long_read(&(l)->a)
8926 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8927 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8928 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8929
8930 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8931 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8932 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8933 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8934 #define local_inc(l) atomic_long_inc(&(l)->a)
8935 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8936 #define local_dec(l) atomic_long_dec(&(l)->a)
8937 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8938
8939 static __inline__ long local_add_return(long a, local_t *l)
8940 {
8941 long t;
8942
8943 __asm__ __volatile__(
8944 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8945 +
8946 +#ifdef CONFIG_PAX_REFCOUNT
8947 +" mcrxr cr0\n"
8948 +" addo. %0,%1,%0\n"
8949 +" bf 4*cr0+so, 3f\n"
8950 +"2:.long " "0x00c00b00""\n"
8951 +#else
8952 +" add %0,%1,%0\n"
8953 +#endif
8954 +
8955 +"3:\n"
8956 + PPC405_ERR77(0,%2)
8957 + PPC_STLCX "%0,0,%2 \n\
8958 + bne- 1b"
8959 +
8960 +#ifdef CONFIG_PAX_REFCOUNT
8961 +"\n4:\n"
8962 + _ASM_EXTABLE(2b, 4b)
8963 +#endif
8964 +
8965 + : "=&r" (t)
8966 + : "r" (a), "r" (&(l->a.counter))
8967 + : "cc", "memory");
8968 +
8969 + return t;
8970 +}
8971 +
8972 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8973 +{
8974 + long t;
8975 +
8976 + __asm__ __volatile__(
8977 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8978 add %0,%1,%0\n"
8979 PPC405_ERR77(0,%2)
8980 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8981
8982 #define local_cmpxchg(l, o, n) \
8983 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8984 +#define local_cmpxchg_unchecked(l, o, n) \
8985 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8986 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8987
8988 /**
8989 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8990 index 8565c25..2865190 100644
8991 --- a/arch/powerpc/include/asm/mman.h
8992 +++ b/arch/powerpc/include/asm/mman.h
8993 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8994 }
8995 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8996
8997 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8998 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8999 {
9000 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
9001 }
9002 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
9003 index 26fe1ae..987ffc5 100644
9004 --- a/arch/powerpc/include/asm/page.h
9005 +++ b/arch/powerpc/include/asm/page.h
9006 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
9007 * and needs to be executable. This means the whole heap ends
9008 * up being executable.
9009 */
9010 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9011 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9012 +#define VM_DATA_DEFAULT_FLAGS32 \
9013 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9014 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9015
9016 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9017 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9018 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
9019 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
9020 #endif
9021
9022 +#define ktla_ktva(addr) (addr)
9023 +#define ktva_ktla(addr) (addr)
9024 +
9025 #ifndef CONFIG_PPC_BOOK3S_64
9026 /*
9027 * Use the top bit of the higher-level page table entries to indicate whether
9028 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
9029 index 88693ce..ac6f9ab 100644
9030 --- a/arch/powerpc/include/asm/page_64.h
9031 +++ b/arch/powerpc/include/asm/page_64.h
9032 @@ -153,15 +153,18 @@ do { \
9033 * stack by default, so in the absence of a PT_GNU_STACK program header
9034 * we turn execute permission off.
9035 */
9036 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9037 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9038 +#define VM_STACK_DEFAULT_FLAGS32 \
9039 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9040 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9041
9042 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9043 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9044
9045 +#ifndef CONFIG_PAX_PAGEEXEC
9046 #define VM_STACK_DEFAULT_FLAGS \
9047 (is_32bit_task() ? \
9048 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
9049 +#endif
9050
9051 #include <asm-generic/getorder.h>
9052
9053 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
9054 index 4b0be20..c15a27d 100644
9055 --- a/arch/powerpc/include/asm/pgalloc-64.h
9056 +++ b/arch/powerpc/include/asm/pgalloc-64.h
9057 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9058 #ifndef CONFIG_PPC_64K_PAGES
9059
9060 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
9061 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
9062
9063 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
9064 {
9065 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9066 pud_set(pud, (unsigned long)pmd);
9067 }
9068
9069 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9070 +{
9071 + pud_populate(mm, pud, pmd);
9072 +}
9073 +
9074 #define pmd_populate(mm, pmd, pte_page) \
9075 pmd_populate_kernel(mm, pmd, page_address(pte_page))
9076 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
9077 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
9078 #endif
9079
9080 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
9081 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9082
9083 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
9084 pte_t *pte)
9085 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
9086 index d98c1ec..9f61569 100644
9087 --- a/arch/powerpc/include/asm/pgtable.h
9088 +++ b/arch/powerpc/include/asm/pgtable.h
9089 @@ -2,6 +2,7 @@
9090 #define _ASM_POWERPC_PGTABLE_H
9091 #ifdef __KERNEL__
9092
9093 +#include <linux/const.h>
9094 #ifndef __ASSEMBLY__
9095 #include <linux/mmdebug.h>
9096 #include <asm/processor.h> /* For TASK_SIZE */
9097 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
9098 index 4aad413..85d86bf 100644
9099 --- a/arch/powerpc/include/asm/pte-hash32.h
9100 +++ b/arch/powerpc/include/asm/pte-hash32.h
9101 @@ -21,6 +21,7 @@
9102 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
9103 #define _PAGE_USER 0x004 /* usermode access allowed */
9104 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
9105 +#define _PAGE_EXEC _PAGE_GUARDED
9106 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
9107 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
9108 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
9109 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
9110 index 0c05059..7e056e4 100644
9111 --- a/arch/powerpc/include/asm/reg.h
9112 +++ b/arch/powerpc/include/asm/reg.h
9113 @@ -251,6 +251,7 @@
9114 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
9115 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
9116 #define DSISR_NOHPTE 0x40000000 /* no translation found */
9117 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
9118 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
9119 #define DSISR_ISSTORE 0x02000000 /* access was a store */
9120 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
9121 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
9122 index 5a6614a..d89995d1 100644
9123 --- a/arch/powerpc/include/asm/smp.h
9124 +++ b/arch/powerpc/include/asm/smp.h
9125 @@ -51,7 +51,7 @@ struct smp_ops_t {
9126 int (*cpu_disable)(void);
9127 void (*cpu_die)(unsigned int nr);
9128 int (*cpu_bootable)(unsigned int nr);
9129 -};
9130 +} __no_const;
9131
9132 extern void smp_send_debugger_break(void);
9133 extern void start_secondary_resume(void);
9134 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
9135 index 4dbe072..b803275 100644
9136 --- a/arch/powerpc/include/asm/spinlock.h
9137 +++ b/arch/powerpc/include/asm/spinlock.h
9138 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
9139 __asm__ __volatile__(
9140 "1: " PPC_LWARX(%0,0,%1,1) "\n"
9141 __DO_SIGN_EXTEND
9142 -" addic. %0,%0,1\n\
9143 - ble- 2f\n"
9144 +
9145 +#ifdef CONFIG_PAX_REFCOUNT
9146 +" mcrxr cr0\n"
9147 +" addico. %0,%0,1\n"
9148 +" bf 4*cr0+so, 3f\n"
9149 +"2:.long " "0x00c00b00""\n"
9150 +#else
9151 +" addic. %0,%0,1\n"
9152 +#endif
9153 +
9154 +"3:\n"
9155 + "ble- 4f\n"
9156 PPC405_ERR77(0,%1)
9157 " stwcx. %0,0,%1\n\
9158 bne- 1b\n"
9159 PPC_ACQUIRE_BARRIER
9160 -"2:" : "=&r" (tmp)
9161 +"4:"
9162 +
9163 +#ifdef CONFIG_PAX_REFCOUNT
9164 + _ASM_EXTABLE(2b,4b)
9165 +#endif
9166 +
9167 + : "=&r" (tmp)
9168 : "r" (&rw->lock)
9169 : "cr0", "xer", "memory");
9170
9171 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
9172 __asm__ __volatile__(
9173 "# read_unlock\n\t"
9174 PPC_RELEASE_BARRIER
9175 -"1: lwarx %0,0,%1\n\
9176 - addic %0,%0,-1\n"
9177 +"1: lwarx %0,0,%1\n"
9178 +
9179 +#ifdef CONFIG_PAX_REFCOUNT
9180 +" mcrxr cr0\n"
9181 +" addico. %0,%0,-1\n"
9182 +" bf 4*cr0+so, 3f\n"
9183 +"2:.long " "0x00c00b00""\n"
9184 +#else
9185 +" addic. %0,%0,-1\n"
9186 +#endif
9187 +
9188 +"3:\n"
9189 PPC405_ERR77(0,%1)
9190 " stwcx. %0,0,%1\n\
9191 bne- 1b"
9192 +
9193 +#ifdef CONFIG_PAX_REFCOUNT
9194 +"\n4:\n"
9195 + _ASM_EXTABLE(2b, 4b)
9196 +#endif
9197 +
9198 : "=&r"(tmp)
9199 : "r"(&rw->lock)
9200 : "cr0", "xer", "memory");
9201 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
9202 index b034ecd..af7e31f 100644
9203 --- a/arch/powerpc/include/asm/thread_info.h
9204 +++ b/arch/powerpc/include/asm/thread_info.h
9205 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
9206 #if defined(CONFIG_PPC64)
9207 #define TIF_ELF2ABI 18 /* function descriptors must die! */
9208 #endif
9209 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
9210 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9211
9212 /* as above, but as bit values */
9213 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9214 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
9215 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9216 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
9217 #define _TIF_NOHZ (1<<TIF_NOHZ)
9218 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9219 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
9220 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
9221 - _TIF_NOHZ)
9222 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
9223
9224 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
9225 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
9226 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
9227 index 9485b43..3bd3c16 100644
9228 --- a/arch/powerpc/include/asm/uaccess.h
9229 +++ b/arch/powerpc/include/asm/uaccess.h
9230 @@ -58,6 +58,7 @@
9231
9232 #endif
9233
9234 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9235 #define access_ok(type, addr, size) \
9236 (__chk_user_ptr(addr), \
9237 __access_ok((__force unsigned long)(addr), (size), get_fs()))
9238 @@ -318,52 +319,6 @@ do { \
9239 extern unsigned long __copy_tofrom_user(void __user *to,
9240 const void __user *from, unsigned long size);
9241
9242 -#ifndef __powerpc64__
9243 -
9244 -static inline unsigned long copy_from_user(void *to,
9245 - const void __user *from, unsigned long n)
9246 -{
9247 - unsigned long over;
9248 -
9249 - if (access_ok(VERIFY_READ, from, n))
9250 - return __copy_tofrom_user((__force void __user *)to, from, n);
9251 - if ((unsigned long)from < TASK_SIZE) {
9252 - over = (unsigned long)from + n - TASK_SIZE;
9253 - return __copy_tofrom_user((__force void __user *)to, from,
9254 - n - over) + over;
9255 - }
9256 - return n;
9257 -}
9258 -
9259 -static inline unsigned long copy_to_user(void __user *to,
9260 - const void *from, unsigned long n)
9261 -{
9262 - unsigned long over;
9263 -
9264 - if (access_ok(VERIFY_WRITE, to, n))
9265 - return __copy_tofrom_user(to, (__force void __user *)from, n);
9266 - if ((unsigned long)to < TASK_SIZE) {
9267 - over = (unsigned long)to + n - TASK_SIZE;
9268 - return __copy_tofrom_user(to, (__force void __user *)from,
9269 - n - over) + over;
9270 - }
9271 - return n;
9272 -}
9273 -
9274 -#else /* __powerpc64__ */
9275 -
9276 -#define __copy_in_user(to, from, size) \
9277 - __copy_tofrom_user((to), (from), (size))
9278 -
9279 -extern unsigned long copy_from_user(void *to, const void __user *from,
9280 - unsigned long n);
9281 -extern unsigned long copy_to_user(void __user *to, const void *from,
9282 - unsigned long n);
9283 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
9284 - unsigned long n);
9285 -
9286 -#endif /* __powerpc64__ */
9287 -
9288 static inline unsigned long __copy_from_user_inatomic(void *to,
9289 const void __user *from, unsigned long n)
9290 {
9291 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
9292 if (ret == 0)
9293 return 0;
9294 }
9295 +
9296 + if (!__builtin_constant_p(n))
9297 + check_object_size(to, n, false);
9298 +
9299 return __copy_tofrom_user((__force void __user *)to, from, n);
9300 }
9301
9302 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
9303 if (ret == 0)
9304 return 0;
9305 }
9306 +
9307 + if (!__builtin_constant_p(n))
9308 + check_object_size(from, n, true);
9309 +
9310 return __copy_tofrom_user(to, (__force const void __user *)from, n);
9311 }
9312
9313 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
9314 return __copy_to_user_inatomic(to, from, size);
9315 }
9316
9317 +#ifndef __powerpc64__
9318 +
9319 +static inline unsigned long __must_check copy_from_user(void *to,
9320 + const void __user *from, unsigned long n)
9321 +{
9322 + unsigned long over;
9323 +
9324 + if ((long)n < 0)
9325 + return n;
9326 +
9327 + if (access_ok(VERIFY_READ, from, n)) {
9328 + if (!__builtin_constant_p(n))
9329 + check_object_size(to, n, false);
9330 + return __copy_tofrom_user((__force void __user *)to, from, n);
9331 + }
9332 + if ((unsigned long)from < TASK_SIZE) {
9333 + over = (unsigned long)from + n - TASK_SIZE;
9334 + if (!__builtin_constant_p(n - over))
9335 + check_object_size(to, n - over, false);
9336 + return __copy_tofrom_user((__force void __user *)to, from,
9337 + n - over) + over;
9338 + }
9339 + return n;
9340 +}
9341 +
9342 +static inline unsigned long __must_check copy_to_user(void __user *to,
9343 + const void *from, unsigned long n)
9344 +{
9345 + unsigned long over;
9346 +
9347 + if ((long)n < 0)
9348 + return n;
9349 +
9350 + if (access_ok(VERIFY_WRITE, to, n)) {
9351 + if (!__builtin_constant_p(n))
9352 + check_object_size(from, n, true);
9353 + return __copy_tofrom_user(to, (__force void __user *)from, n);
9354 + }
9355 + if ((unsigned long)to < TASK_SIZE) {
9356 + over = (unsigned long)to + n - TASK_SIZE;
9357 + if (!__builtin_constant_p(n))
9358 + check_object_size(from, n - over, true);
9359 + return __copy_tofrom_user(to, (__force void __user *)from,
9360 + n - over) + over;
9361 + }
9362 + return n;
9363 +}
9364 +
9365 +#else /* __powerpc64__ */
9366 +
9367 +#define __copy_in_user(to, from, size) \
9368 + __copy_tofrom_user((to), (from), (size))
9369 +
9370 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
9371 +{
9372 + if ((long)n < 0 || n > INT_MAX)
9373 + return n;
9374 +
9375 + if (!__builtin_constant_p(n))
9376 + check_object_size(to, n, false);
9377 +
9378 + if (likely(access_ok(VERIFY_READ, from, n)))
9379 + n = __copy_from_user(to, from, n);
9380 + else
9381 + memset(to, 0, n);
9382 + return n;
9383 +}
9384 +
9385 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
9386 +{
9387 + if ((long)n < 0 || n > INT_MAX)
9388 + return n;
9389 +
9390 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
9391 + if (!__builtin_constant_p(n))
9392 + check_object_size(from, n, true);
9393 + n = __copy_to_user(to, from, n);
9394 + }
9395 + return n;
9396 +}
9397 +
9398 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
9399 + unsigned long n);
9400 +
9401 +#endif /* __powerpc64__ */
9402 +
9403 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9404
9405 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9406 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9407 index 670c312..60c2b52 100644
9408 --- a/arch/powerpc/kernel/Makefile
9409 +++ b/arch/powerpc/kernel/Makefile
9410 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9411 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9412 endif
9413
9414 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9415 +
9416 obj-y := cputable.o ptrace.o syscalls.o \
9417 irq.o align.o signal_32.o pmc.o vdso.o \
9418 process.o systbl.o idle.o \
9419 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9420 index bb9cac6..5181202 100644
9421 --- a/arch/powerpc/kernel/exceptions-64e.S
9422 +++ b/arch/powerpc/kernel/exceptions-64e.S
9423 @@ -1010,6 +1010,7 @@ storage_fault_common:
9424 std r14,_DAR(r1)
9425 std r15,_DSISR(r1)
9426 addi r3,r1,STACK_FRAME_OVERHEAD
9427 + bl save_nvgprs
9428 mr r4,r14
9429 mr r5,r15
9430 ld r14,PACA_EXGEN+EX_R14(r13)
9431 @@ -1018,8 +1019,7 @@ storage_fault_common:
9432 cmpdi r3,0
9433 bne- 1f
9434 b ret_from_except_lite
9435 -1: bl save_nvgprs
9436 - mr r5,r3
9437 +1: mr r5,r3
9438 addi r3,r1,STACK_FRAME_OVERHEAD
9439 ld r4,_DAR(r1)
9440 bl bad_page_fault
9441 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9442 index 050f79a..f385bfe 100644
9443 --- a/arch/powerpc/kernel/exceptions-64s.S
9444 +++ b/arch/powerpc/kernel/exceptions-64s.S
9445 @@ -1593,10 +1593,10 @@ handle_page_fault:
9446 11: ld r4,_DAR(r1)
9447 ld r5,_DSISR(r1)
9448 addi r3,r1,STACK_FRAME_OVERHEAD
9449 + bl save_nvgprs
9450 bl do_page_fault
9451 cmpdi r3,0
9452 beq+ 12f
9453 - bl save_nvgprs
9454 mr r5,r3
9455 addi r3,r1,STACK_FRAME_OVERHEAD
9456 lwz r4,_DAR(r1)
9457 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9458 index 4c5891d..a5d88bb 100644
9459 --- a/arch/powerpc/kernel/irq.c
9460 +++ b/arch/powerpc/kernel/irq.c
9461 @@ -461,6 +461,8 @@ void migrate_irqs(void)
9462 }
9463 #endif
9464
9465 +extern void gr_handle_kernel_exploit(void);
9466 +
9467 static inline void check_stack_overflow(void)
9468 {
9469 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9470 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
9471 printk("do_IRQ: stack overflow: %ld\n",
9472 sp - sizeof(struct thread_info));
9473 dump_stack();
9474 + gr_handle_kernel_exploit();
9475 }
9476 #endif
9477 }
9478 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9479 index 6cff040..74ac5d1b 100644
9480 --- a/arch/powerpc/kernel/module_32.c
9481 +++ b/arch/powerpc/kernel/module_32.c
9482 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9483 me->arch.core_plt_section = i;
9484 }
9485 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9486 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9487 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9488 return -ENOEXEC;
9489 }
9490
9491 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9492
9493 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9494 /* Init, or core PLT? */
9495 - if (location >= mod->module_core
9496 - && location < mod->module_core + mod->core_size)
9497 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9498 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9499 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9500 - else
9501 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9502 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9503 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9504 + else {
9505 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9506 + return ~0UL;
9507 + }
9508
9509 /* Find this entry, or if that fails, the next avail. entry */
9510 while (entry->jump[0]) {
9511 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9512 }
9513 #ifdef CONFIG_DYNAMIC_FTRACE
9514 module->arch.tramp =
9515 - do_plt_call(module->module_core,
9516 + do_plt_call(module->module_core_rx,
9517 (unsigned long)ftrace_caller,
9518 sechdrs, module);
9519 #endif
9520 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9521 index bf44ae9..6d2ce71 100644
9522 --- a/arch/powerpc/kernel/process.c
9523 +++ b/arch/powerpc/kernel/process.c
9524 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9525 * Lookup NIP late so we have the best change of getting the
9526 * above info out without failing
9527 */
9528 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9529 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9530 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9531 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9532 #endif
9533 show_stack(current, (unsigned long *) regs->gpr[1]);
9534 if (!user_mode(regs))
9535 @@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9536 newsp = stack[0];
9537 ip = stack[STACK_FRAME_LR_SAVE];
9538 if (!firstframe || ip != lr) {
9539 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9540 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9541 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9542 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9543 - printk(" (%pS)",
9544 + printk(" (%pA)",
9545 (void *)current->ret_stack[curr_frame].ret);
9546 curr_frame--;
9547 }
9548 @@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9549 struct pt_regs *regs = (struct pt_regs *)
9550 (sp + STACK_FRAME_OVERHEAD);
9551 lr = regs->link;
9552 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9553 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9554 regs->trap, (void *)regs->nip, (void *)lr);
9555 firstframe = 1;
9556 }
9557 @@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
9558 mtspr(SPRN_CTRLT, ctrl);
9559 }
9560 #endif /* CONFIG_PPC64 */
9561 -
9562 -unsigned long arch_align_stack(unsigned long sp)
9563 -{
9564 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9565 - sp -= get_random_int() & ~PAGE_MASK;
9566 - return sp & ~0xf;
9567 -}
9568 -
9569 -static inline unsigned long brk_rnd(void)
9570 -{
9571 - unsigned long rnd = 0;
9572 -
9573 - /* 8MB for 32bit, 1GB for 64bit */
9574 - if (is_32bit_task())
9575 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9576 - else
9577 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9578 -
9579 - return rnd << PAGE_SHIFT;
9580 -}
9581 -
9582 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9583 -{
9584 - unsigned long base = mm->brk;
9585 - unsigned long ret;
9586 -
9587 -#ifdef CONFIG_PPC_STD_MMU_64
9588 - /*
9589 - * If we are using 1TB segments and we are allowed to randomise
9590 - * the heap, we can put it above 1TB so it is backed by a 1TB
9591 - * segment. Otherwise the heap will be in the bottom 1TB
9592 - * which always uses 256MB segments and this may result in a
9593 - * performance penalty.
9594 - */
9595 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9596 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9597 -#endif
9598 -
9599 - ret = PAGE_ALIGN(base + brk_rnd());
9600 -
9601 - if (ret < mm->brk)
9602 - return mm->brk;
9603 -
9604 - return ret;
9605 -}
9606 -
9607 -unsigned long randomize_et_dyn(unsigned long base)
9608 -{
9609 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9610 -
9611 - if (ret < base)
9612 - return base;
9613 -
9614 - return ret;
9615 -}
9616 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9617 index 2e3d2bf..35df241 100644
9618 --- a/arch/powerpc/kernel/ptrace.c
9619 +++ b/arch/powerpc/kernel/ptrace.c
9620 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9621 return ret;
9622 }
9623
9624 +#ifdef CONFIG_GRKERNSEC_SETXID
9625 +extern void gr_delayed_cred_worker(void);
9626 +#endif
9627 +
9628 /*
9629 * We must return the syscall number to actually look up in the table.
9630 * This can be -1L to skip running any syscall at all.
9631 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9632
9633 secure_computing_strict(regs->gpr[0]);
9634
9635 +#ifdef CONFIG_GRKERNSEC_SETXID
9636 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9637 + gr_delayed_cred_worker();
9638 +#endif
9639 +
9640 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9641 tracehook_report_syscall_entry(regs))
9642 /*
9643 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9644 {
9645 int step;
9646
9647 +#ifdef CONFIG_GRKERNSEC_SETXID
9648 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9649 + gr_delayed_cred_worker();
9650 +#endif
9651 +
9652 audit_syscall_exit(regs);
9653
9654 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9655 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9656 index b171001..4ac7ac5 100644
9657 --- a/arch/powerpc/kernel/signal_32.c
9658 +++ b/arch/powerpc/kernel/signal_32.c
9659 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9660 /* Save user registers on the stack */
9661 frame = &rt_sf->uc.uc_mcontext;
9662 addr = frame;
9663 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9664 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9665 sigret = 0;
9666 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9667 } else {
9668 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9669 index 2cb0c94..c0c0bc9 100644
9670 --- a/arch/powerpc/kernel/signal_64.c
9671 +++ b/arch/powerpc/kernel/signal_64.c
9672 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9673 current->thread.fp_state.fpscr = 0;
9674
9675 /* Set up to return from userspace. */
9676 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9677 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9678 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9679 } else {
9680 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9681 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9682 index 0dc43f9..a885d33 100644
9683 --- a/arch/powerpc/kernel/traps.c
9684 +++ b/arch/powerpc/kernel/traps.c
9685 @@ -36,6 +36,7 @@
9686 #include <linux/debugfs.h>
9687 #include <linux/ratelimit.h>
9688 #include <linux/context_tracking.h>
9689 +#include <linux/uaccess.h>
9690
9691 #include <asm/emulated_ops.h>
9692 #include <asm/pgtable.h>
9693 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9694 return flags;
9695 }
9696
9697 +extern void gr_handle_kernel_exploit(void);
9698 +
9699 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9700 int signr)
9701 {
9702 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9703 panic("Fatal exception in interrupt");
9704 if (panic_on_oops)
9705 panic("Fatal exception");
9706 +
9707 + gr_handle_kernel_exploit();
9708 +
9709 do_exit(signr);
9710 }
9711
9712 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9713 enum ctx_state prev_state = exception_enter();
9714 unsigned int reason = get_reason(regs);
9715
9716 +#ifdef CONFIG_PAX_REFCOUNT
9717 + unsigned int bkpt;
9718 + const struct exception_table_entry *entry;
9719 +
9720 + if (reason & REASON_ILLEGAL) {
9721 + /* Check if PaX bad instruction */
9722 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9723 + current->thread.trap_nr = 0;
9724 + pax_report_refcount_overflow(regs);
9725 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9726 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9727 + regs->nip = entry->fixup;
9728 + return;
9729 + }
9730 + /* fixup_exception() could not handle */
9731 + goto bail;
9732 + }
9733 + }
9734 +#endif
9735 +
9736 /* We can now get here via a FP Unavailable exception if the core
9737 * has no FPU, in that case the reason flags will be 0 */
9738
9739 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9740 index f174351..5722009 100644
9741 --- a/arch/powerpc/kernel/vdso.c
9742 +++ b/arch/powerpc/kernel/vdso.c
9743 @@ -35,6 +35,7 @@
9744 #include <asm/vdso.h>
9745 #include <asm/vdso_datapage.h>
9746 #include <asm/setup.h>
9747 +#include <asm/mman.h>
9748
9749 #undef DEBUG
9750
9751 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9752 vdso_base = VDSO32_MBASE;
9753 #endif
9754
9755 - current->mm->context.vdso_base = 0;
9756 + current->mm->context.vdso_base = ~0UL;
9757
9758 /* vDSO has a problem and was disabled, just don't "enable" it for the
9759 * process
9760 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9761 vdso_base = get_unmapped_area(NULL, vdso_base,
9762 (vdso_pages << PAGE_SHIFT) +
9763 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9764 - 0, 0);
9765 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9766 if (IS_ERR_VALUE(vdso_base)) {
9767 rc = vdso_base;
9768 goto fail_mmapsem;
9769 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9770 index 4c79284..0e462c3 100644
9771 --- a/arch/powerpc/kvm/powerpc.c
9772 +++ b/arch/powerpc/kvm/powerpc.c
9773 @@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9774 }
9775 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9776
9777 -int kvm_arch_init(void *opaque)
9778 +int kvm_arch_init(const void *opaque)
9779 {
9780 return 0;
9781 }
9782 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9783 index 5eea6f3..5d10396 100644
9784 --- a/arch/powerpc/lib/usercopy_64.c
9785 +++ b/arch/powerpc/lib/usercopy_64.c
9786 @@ -9,22 +9,6 @@
9787 #include <linux/module.h>
9788 #include <asm/uaccess.h>
9789
9790 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9791 -{
9792 - if (likely(access_ok(VERIFY_READ, from, n)))
9793 - n = __copy_from_user(to, from, n);
9794 - else
9795 - memset(to, 0, n);
9796 - return n;
9797 -}
9798 -
9799 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9800 -{
9801 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9802 - n = __copy_to_user(to, from, n);
9803 - return n;
9804 -}
9805 -
9806 unsigned long copy_in_user(void __user *to, const void __user *from,
9807 unsigned long n)
9808 {
9809 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9810 return n;
9811 }
9812
9813 -EXPORT_SYMBOL(copy_from_user);
9814 -EXPORT_SYMBOL(copy_to_user);
9815 EXPORT_SYMBOL(copy_in_user);
9816
9817 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9818 index 51ab9e7..7d3c78b 100644
9819 --- a/arch/powerpc/mm/fault.c
9820 +++ b/arch/powerpc/mm/fault.c
9821 @@ -33,6 +33,10 @@
9822 #include <linux/magic.h>
9823 #include <linux/ratelimit.h>
9824 #include <linux/context_tracking.h>
9825 +#include <linux/slab.h>
9826 +#include <linux/pagemap.h>
9827 +#include <linux/compiler.h>
9828 +#include <linux/unistd.h>
9829
9830 #include <asm/firmware.h>
9831 #include <asm/page.h>
9832 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9833 }
9834 #endif
9835
9836 +#ifdef CONFIG_PAX_PAGEEXEC
9837 +/*
9838 + * PaX: decide what to do with offenders (regs->nip = fault address)
9839 + *
9840 + * returns 1 when task should be killed
9841 + */
9842 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9843 +{
9844 + return 1;
9845 +}
9846 +
9847 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9848 +{
9849 + unsigned long i;
9850 +
9851 + printk(KERN_ERR "PAX: bytes at PC: ");
9852 + for (i = 0; i < 5; i++) {
9853 + unsigned int c;
9854 + if (get_user(c, (unsigned int __user *)pc+i))
9855 + printk(KERN_CONT "???????? ");
9856 + else
9857 + printk(KERN_CONT "%08x ", c);
9858 + }
9859 + printk("\n");
9860 +}
9861 +#endif
9862 +
9863 /*
9864 * Check whether the instruction at regs->nip is a store using
9865 * an update addressing form which will update r1.
9866 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9867 * indicate errors in DSISR but can validly be set in SRR1.
9868 */
9869 if (trap == 0x400)
9870 - error_code &= 0x48200000;
9871 + error_code &= 0x58200000;
9872 else
9873 is_write = error_code & DSISR_ISSTORE;
9874 #else
9875 @@ -378,7 +409,7 @@ good_area:
9876 * "undefined". Of those that can be set, this is the only
9877 * one which seems bad.
9878 */
9879 - if (error_code & 0x10000000)
9880 + if (error_code & DSISR_GUARDED)
9881 /* Guarded storage error. */
9882 goto bad_area;
9883 #endif /* CONFIG_8xx */
9884 @@ -393,7 +424,7 @@ good_area:
9885 * processors use the same I/D cache coherency mechanism
9886 * as embedded.
9887 */
9888 - if (error_code & DSISR_PROTFAULT)
9889 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9890 goto bad_area;
9891 #endif /* CONFIG_PPC_STD_MMU */
9892
9893 @@ -483,6 +514,23 @@ bad_area:
9894 bad_area_nosemaphore:
9895 /* User mode accesses cause a SIGSEGV */
9896 if (user_mode(regs)) {
9897 +
9898 +#ifdef CONFIG_PAX_PAGEEXEC
9899 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9900 +#ifdef CONFIG_PPC_STD_MMU
9901 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9902 +#else
9903 + if (is_exec && regs->nip == address) {
9904 +#endif
9905 + switch (pax_handle_fetch_fault(regs)) {
9906 + }
9907 +
9908 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9909 + do_group_exit(SIGKILL);
9910 + }
9911 + }
9912 +#endif
9913 +
9914 _exception(SIGSEGV, regs, code, address);
9915 goto bail;
9916 }
9917 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9918 index cb8bdbe..cde4bc7 100644
9919 --- a/arch/powerpc/mm/mmap.c
9920 +++ b/arch/powerpc/mm/mmap.c
9921 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9922 return sysctl_legacy_va_layout;
9923 }
9924
9925 -static unsigned long mmap_rnd(void)
9926 +static unsigned long mmap_rnd(struct mm_struct *mm)
9927 {
9928 unsigned long rnd = 0;
9929
9930 +#ifdef CONFIG_PAX_RANDMMAP
9931 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9932 +#endif
9933 +
9934 if (current->flags & PF_RANDOMIZE) {
9935 /* 8MB for 32bit, 1GB for 64bit */
9936 if (is_32bit_task())
9937 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9938 return rnd << PAGE_SHIFT;
9939 }
9940
9941 -static inline unsigned long mmap_base(void)
9942 +static inline unsigned long mmap_base(struct mm_struct *mm)
9943 {
9944 unsigned long gap = rlimit(RLIMIT_STACK);
9945
9946 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9947 else if (gap > MAX_GAP)
9948 gap = MAX_GAP;
9949
9950 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9951 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9952 }
9953
9954 /*
9955 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9956 */
9957 if (mmap_is_legacy()) {
9958 mm->mmap_base = TASK_UNMAPPED_BASE;
9959 +
9960 +#ifdef CONFIG_PAX_RANDMMAP
9961 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9962 + mm->mmap_base += mm->delta_mmap;
9963 +#endif
9964 +
9965 mm->get_unmapped_area = arch_get_unmapped_area;
9966 } else {
9967 - mm->mmap_base = mmap_base();
9968 + mm->mmap_base = mmap_base(mm);
9969 +
9970 +#ifdef CONFIG_PAX_RANDMMAP
9971 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9972 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9973 +#endif
9974 +
9975 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9976 }
9977 }
9978 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9979 index b0c75cc..ef7fb93 100644
9980 --- a/arch/powerpc/mm/slice.c
9981 +++ b/arch/powerpc/mm/slice.c
9982 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9983 if ((mm->task_size - len) < addr)
9984 return 0;
9985 vma = find_vma(mm, addr);
9986 - return (!vma || (addr + len) <= vma->vm_start);
9987 + return check_heap_stack_gap(vma, addr, len, 0);
9988 }
9989
9990 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9991 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9992 info.align_offset = 0;
9993
9994 addr = TASK_UNMAPPED_BASE;
9995 +
9996 +#ifdef CONFIG_PAX_RANDMMAP
9997 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9998 + addr += mm->delta_mmap;
9999 +#endif
10000 +
10001 while (addr < TASK_SIZE) {
10002 info.low_limit = addr;
10003 if (!slice_scan_available(addr, available, 1, &addr))
10004 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
10005 if (fixed && addr > (mm->task_size - len))
10006 return -ENOMEM;
10007
10008 +#ifdef CONFIG_PAX_RANDMMAP
10009 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
10010 + addr = 0;
10011 +#endif
10012 +
10013 /* If hint, make sure it matches our alignment restrictions */
10014 if (!fixed && addr) {
10015 addr = _ALIGN_UP(addr, 1ul << pshift);
10016 diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
10017 index 3afa6f4..40c53ff 100644
10018 --- a/arch/powerpc/net/bpf_jit_comp.c
10019 +++ b/arch/powerpc/net/bpf_jit_comp.c
10020 @@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
10021 {
10022 if (fp->jited)
10023 module_free(NULL, fp->bpf_func);
10024 - kfree(fp);
10025 +
10026 + bpf_prog_unlock_free(fp);
10027 }
10028 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10029 index 4278acf..67fd0e6 100644
10030 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10031 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10032 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
10033 }
10034
10035 static struct pci_ops scc_pciex_pci_ops = {
10036 - scc_pciex_read_config,
10037 - scc_pciex_write_config,
10038 + .read = scc_pciex_read_config,
10039 + .write = scc_pciex_write_config,
10040 };
10041
10042 static void pciex_clear_intr_all(unsigned int __iomem *base)
10043 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
10044 index d966bbe..372124a 100644
10045 --- a/arch/powerpc/platforms/cell/spufs/file.c
10046 +++ b/arch/powerpc/platforms/cell/spufs/file.c
10047 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10048 return VM_FAULT_NOPAGE;
10049 }
10050
10051 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
10052 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
10053 unsigned long address,
10054 - void *buf, int len, int write)
10055 + void *buf, size_t len, int write)
10056 {
10057 struct spu_context *ctx = vma->vm_file->private_data;
10058 unsigned long offset = address - vma->vm_start;
10059 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
10060 index fa934fe..c296056 100644
10061 --- a/arch/s390/include/asm/atomic.h
10062 +++ b/arch/s390/include/asm/atomic.h
10063 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
10064 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
10065 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10066
10067 +#define atomic64_read_unchecked(v) atomic64_read(v)
10068 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10069 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10070 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10071 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10072 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
10073 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10074 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
10075 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10076 +
10077 #endif /* __ARCH_S390_ATOMIC__ */
10078 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
10079 index 19ff956..8d39cb1 100644
10080 --- a/arch/s390/include/asm/barrier.h
10081 +++ b/arch/s390/include/asm/barrier.h
10082 @@ -37,7 +37,7 @@
10083 do { \
10084 compiletime_assert_atomic_type(*p); \
10085 barrier(); \
10086 - ACCESS_ONCE(*p) = (v); \
10087 + ACCESS_ONCE_RW(*p) = (v); \
10088 } while (0)
10089
10090 #define smp_load_acquire(p) \
10091 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
10092 index 4d7ccac..d03d0ad 100644
10093 --- a/arch/s390/include/asm/cache.h
10094 +++ b/arch/s390/include/asm/cache.h
10095 @@ -9,8 +9,10 @@
10096 #ifndef __ARCH_S390_CACHE_H
10097 #define __ARCH_S390_CACHE_H
10098
10099 -#define L1_CACHE_BYTES 256
10100 +#include <linux/const.h>
10101 +
10102 #define L1_CACHE_SHIFT 8
10103 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10104 #define NET_SKB_PAD 32
10105
10106 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10107 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
10108 index 78f4f87..598ce39 100644
10109 --- a/arch/s390/include/asm/elf.h
10110 +++ b/arch/s390/include/asm/elf.h
10111 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
10112 the loader. We need to make sure that it is out of the way of the program
10113 that it will "exec", and that there is sufficient room for the brk. */
10114
10115 -extern unsigned long randomize_et_dyn(unsigned long base);
10116 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
10117 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
10118 +
10119 +#ifdef CONFIG_PAX_ASLR
10120 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
10121 +
10122 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10123 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10124 +#endif
10125
10126 /* This yields a mask that user programs can use to figure out what
10127 instruction set this CPU supports. */
10128 @@ -222,9 +228,6 @@ struct linux_binprm;
10129 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
10130 int arch_setup_additional_pages(struct linux_binprm *, int);
10131
10132 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10133 -#define arch_randomize_brk arch_randomize_brk
10134 -
10135 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
10136
10137 #endif
10138 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
10139 index c4a93d6..4d2a9b4 100644
10140 --- a/arch/s390/include/asm/exec.h
10141 +++ b/arch/s390/include/asm/exec.h
10142 @@ -7,6 +7,6 @@
10143 #ifndef __ASM_EXEC_H
10144 #define __ASM_EXEC_H
10145
10146 -extern unsigned long arch_align_stack(unsigned long sp);
10147 +#define arch_align_stack(x) ((x) & ~0xfUL)
10148
10149 #endif /* __ASM_EXEC_H */
10150 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
10151 index cd4c68e..6764641 100644
10152 --- a/arch/s390/include/asm/uaccess.h
10153 +++ b/arch/s390/include/asm/uaccess.h
10154 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
10155 __range_ok((unsigned long)(addr), (size)); \
10156 })
10157
10158 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
10159 #define access_ok(type, addr, size) __access_ok(addr, size)
10160
10161 /*
10162 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
10163 copy_to_user(void __user *to, const void *from, unsigned long n)
10164 {
10165 might_fault();
10166 +
10167 + if ((long)n < 0)
10168 + return n;
10169 +
10170 return __copy_to_user(to, from, n);
10171 }
10172
10173 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
10174 static inline unsigned long __must_check
10175 copy_from_user(void *to, const void __user *from, unsigned long n)
10176 {
10177 - unsigned int sz = __compiletime_object_size(to);
10178 + size_t sz = __compiletime_object_size(to);
10179
10180 might_fault();
10181 - if (unlikely(sz != -1 && sz < n)) {
10182 +
10183 + if ((long)n < 0)
10184 + return n;
10185 +
10186 + if (unlikely(sz != (size_t)-1 && sz < n)) {
10187 copy_from_user_overflow();
10188 return n;
10189 }
10190 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
10191 index b89b591..fd9609d 100644
10192 --- a/arch/s390/kernel/module.c
10193 +++ b/arch/s390/kernel/module.c
10194 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
10195
10196 /* Increase core size by size of got & plt and set start
10197 offsets for got and plt. */
10198 - me->core_size = ALIGN(me->core_size, 4);
10199 - me->arch.got_offset = me->core_size;
10200 - me->core_size += me->arch.got_size;
10201 - me->arch.plt_offset = me->core_size;
10202 - me->core_size += me->arch.plt_size;
10203 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
10204 + me->arch.got_offset = me->core_size_rw;
10205 + me->core_size_rw += me->arch.got_size;
10206 + me->arch.plt_offset = me->core_size_rx;
10207 + me->core_size_rx += me->arch.plt_size;
10208 return 0;
10209 }
10210
10211 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10212 if (info->got_initialized == 0) {
10213 Elf_Addr *gotent;
10214
10215 - gotent = me->module_core + me->arch.got_offset +
10216 + gotent = me->module_core_rw + me->arch.got_offset +
10217 info->got_offset;
10218 *gotent = val;
10219 info->got_initialized = 1;
10220 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10221 rc = apply_rela_bits(loc, val, 0, 64, 0);
10222 else if (r_type == R_390_GOTENT ||
10223 r_type == R_390_GOTPLTENT) {
10224 - val += (Elf_Addr) me->module_core - loc;
10225 + val += (Elf_Addr) me->module_core_rw - loc;
10226 rc = apply_rela_bits(loc, val, 1, 32, 1);
10227 }
10228 break;
10229 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10230 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
10231 if (info->plt_initialized == 0) {
10232 unsigned int *ip;
10233 - ip = me->module_core + me->arch.plt_offset +
10234 + ip = me->module_core_rx + me->arch.plt_offset +
10235 info->plt_offset;
10236 #ifndef CONFIG_64BIT
10237 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
10238 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10239 val - loc + 0xffffUL < 0x1ffffeUL) ||
10240 (r_type == R_390_PLT32DBL &&
10241 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
10242 - val = (Elf_Addr) me->module_core +
10243 + val = (Elf_Addr) me->module_core_rx +
10244 me->arch.plt_offset +
10245 info->plt_offset;
10246 val += rela->r_addend - loc;
10247 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10248 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
10249 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
10250 val = val + rela->r_addend -
10251 - ((Elf_Addr) me->module_core + me->arch.got_offset);
10252 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
10253 if (r_type == R_390_GOTOFF16)
10254 rc = apply_rela_bits(loc, val, 0, 16, 0);
10255 else if (r_type == R_390_GOTOFF32)
10256 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10257 break;
10258 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
10259 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
10260 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
10261 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
10262 rela->r_addend - loc;
10263 if (r_type == R_390_GOTPC)
10264 rc = apply_rela_bits(loc, val, 1, 32, 0);
10265 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
10266 index 93b9ca4..4ea1454 100644
10267 --- a/arch/s390/kernel/process.c
10268 +++ b/arch/s390/kernel/process.c
10269 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
10270 }
10271 return 0;
10272 }
10273 -
10274 -unsigned long arch_align_stack(unsigned long sp)
10275 -{
10276 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10277 - sp -= get_random_int() & ~PAGE_MASK;
10278 - return sp & ~0xf;
10279 -}
10280 -
10281 -static inline unsigned long brk_rnd(void)
10282 -{
10283 - /* 8MB for 32bit, 1GB for 64bit */
10284 - if (is_32bit_task())
10285 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
10286 - else
10287 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
10288 -}
10289 -
10290 -unsigned long arch_randomize_brk(struct mm_struct *mm)
10291 -{
10292 - unsigned long ret;
10293 -
10294 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
10295 - return (ret > mm->brk) ? ret : mm->brk;
10296 -}
10297 -
10298 -unsigned long randomize_et_dyn(unsigned long base)
10299 -{
10300 - unsigned long ret;
10301 -
10302 - if (!(current->flags & PF_RANDOMIZE))
10303 - return base;
10304 - ret = PAGE_ALIGN(base + brk_rnd());
10305 - return (ret > base) ? ret : base;
10306 -}
10307 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
10308 index 9b436c2..54fbf0a 100644
10309 --- a/arch/s390/mm/mmap.c
10310 +++ b/arch/s390/mm/mmap.c
10311 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10312 */
10313 if (mmap_is_legacy()) {
10314 mm->mmap_base = mmap_base_legacy();
10315 +
10316 +#ifdef CONFIG_PAX_RANDMMAP
10317 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10318 + mm->mmap_base += mm->delta_mmap;
10319 +#endif
10320 +
10321 mm->get_unmapped_area = arch_get_unmapped_area;
10322 } else {
10323 mm->mmap_base = mmap_base();
10324 +
10325 +#ifdef CONFIG_PAX_RANDMMAP
10326 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10327 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10328 +#endif
10329 +
10330 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10331 }
10332 }
10333 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10334 */
10335 if (mmap_is_legacy()) {
10336 mm->mmap_base = mmap_base_legacy();
10337 +
10338 +#ifdef CONFIG_PAX_RANDMMAP
10339 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10340 + mm->mmap_base += mm->delta_mmap;
10341 +#endif
10342 +
10343 mm->get_unmapped_area = s390_get_unmapped_area;
10344 } else {
10345 mm->mmap_base = mmap_base();
10346 +
10347 +#ifdef CONFIG_PAX_RANDMMAP
10348 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10349 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10350 +#endif
10351 +
10352 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
10353 }
10354 }
10355 diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
10356 index 61e45b7..f2833c5 100644
10357 --- a/arch/s390/net/bpf_jit_comp.c
10358 +++ b/arch/s390/net/bpf_jit_comp.c
10359 @@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
10360 module_free(NULL, header);
10361
10362 free_filter:
10363 - kfree(fp);
10364 + bpf_prog_unlock_free(fp);
10365 }
10366 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
10367 index ae3d59f..f65f075 100644
10368 --- a/arch/score/include/asm/cache.h
10369 +++ b/arch/score/include/asm/cache.h
10370 @@ -1,7 +1,9 @@
10371 #ifndef _ASM_SCORE_CACHE_H
10372 #define _ASM_SCORE_CACHE_H
10373
10374 +#include <linux/const.h>
10375 +
10376 #define L1_CACHE_SHIFT 4
10377 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10378 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10379
10380 #endif /* _ASM_SCORE_CACHE_H */
10381 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
10382 index f9f3cd5..58ff438 100644
10383 --- a/arch/score/include/asm/exec.h
10384 +++ b/arch/score/include/asm/exec.h
10385 @@ -1,6 +1,6 @@
10386 #ifndef _ASM_SCORE_EXEC_H
10387 #define _ASM_SCORE_EXEC_H
10388
10389 -extern unsigned long arch_align_stack(unsigned long sp);
10390 +#define arch_align_stack(x) (x)
10391
10392 #endif /* _ASM_SCORE_EXEC_H */
10393 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
10394 index a1519ad3..e8ac1ff 100644
10395 --- a/arch/score/kernel/process.c
10396 +++ b/arch/score/kernel/process.c
10397 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
10398
10399 return task_pt_regs(task)->cp0_epc;
10400 }
10401 -
10402 -unsigned long arch_align_stack(unsigned long sp)
10403 -{
10404 - return sp;
10405 -}
10406 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
10407 index ef9e555..331bd29 100644
10408 --- a/arch/sh/include/asm/cache.h
10409 +++ b/arch/sh/include/asm/cache.h
10410 @@ -9,10 +9,11 @@
10411 #define __ASM_SH_CACHE_H
10412 #ifdef __KERNEL__
10413
10414 +#include <linux/const.h>
10415 #include <linux/init.h>
10416 #include <cpu/cache.h>
10417
10418 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10419 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10420
10421 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10422
10423 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
10424 index 6777177..cb5e44f 100644
10425 --- a/arch/sh/mm/mmap.c
10426 +++ b/arch/sh/mm/mmap.c
10427 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10428 struct mm_struct *mm = current->mm;
10429 struct vm_area_struct *vma;
10430 int do_colour_align;
10431 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10432 struct vm_unmapped_area_info info;
10433
10434 if (flags & MAP_FIXED) {
10435 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10436 if (filp || (flags & MAP_SHARED))
10437 do_colour_align = 1;
10438
10439 +#ifdef CONFIG_PAX_RANDMMAP
10440 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10441 +#endif
10442 +
10443 if (addr) {
10444 if (do_colour_align)
10445 addr = COLOUR_ALIGN(addr, pgoff);
10446 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10447 addr = PAGE_ALIGN(addr);
10448
10449 vma = find_vma(mm, addr);
10450 - if (TASK_SIZE - len >= addr &&
10451 - (!vma || addr + len <= vma->vm_start))
10452 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10453 return addr;
10454 }
10455
10456 info.flags = 0;
10457 info.length = len;
10458 - info.low_limit = TASK_UNMAPPED_BASE;
10459 + info.low_limit = mm->mmap_base;
10460 info.high_limit = TASK_SIZE;
10461 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10462 info.align_offset = pgoff << PAGE_SHIFT;
10463 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10464 struct mm_struct *mm = current->mm;
10465 unsigned long addr = addr0;
10466 int do_colour_align;
10467 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10468 struct vm_unmapped_area_info info;
10469
10470 if (flags & MAP_FIXED) {
10471 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10472 if (filp || (flags & MAP_SHARED))
10473 do_colour_align = 1;
10474
10475 +#ifdef CONFIG_PAX_RANDMMAP
10476 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10477 +#endif
10478 +
10479 /* requesting a specific address */
10480 if (addr) {
10481 if (do_colour_align)
10482 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10483 addr = PAGE_ALIGN(addr);
10484
10485 vma = find_vma(mm, addr);
10486 - if (TASK_SIZE - len >= addr &&
10487 - (!vma || addr + len <= vma->vm_start))
10488 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10489 return addr;
10490 }
10491
10492 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10493 VM_BUG_ON(addr != -ENOMEM);
10494 info.flags = 0;
10495 info.low_limit = TASK_UNMAPPED_BASE;
10496 +
10497 +#ifdef CONFIG_PAX_RANDMMAP
10498 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10499 + info.low_limit += mm->delta_mmap;
10500 +#endif
10501 +
10502 info.high_limit = TASK_SIZE;
10503 addr = vm_unmapped_area(&info);
10504 }
10505 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10506 index bb894c8..8141d5c 100644
10507 --- a/arch/sparc/include/asm/atomic_64.h
10508 +++ b/arch/sparc/include/asm/atomic_64.h
10509 @@ -15,18 +15,40 @@
10510 #define ATOMIC64_INIT(i) { (i) }
10511
10512 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10513 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10514 +{
10515 + return v->counter;
10516 +}
10517 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10518 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10519 +{
10520 + return v->counter;
10521 +}
10522
10523 #define atomic_set(v, i) (((v)->counter) = i)
10524 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10525 +{
10526 + v->counter = i;
10527 +}
10528 #define atomic64_set(v, i) (((v)->counter) = i)
10529 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10530 +{
10531 + v->counter = i;
10532 +}
10533
10534 void atomic_add(int, atomic_t *);
10535 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10536 void atomic64_add(long, atomic64_t *);
10537 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10538 void atomic_sub(int, atomic_t *);
10539 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10540 void atomic64_sub(long, atomic64_t *);
10541 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10542
10543 int atomic_add_ret(int, atomic_t *);
10544 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10545 long atomic64_add_ret(long, atomic64_t *);
10546 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10547 int atomic_sub_ret(int, atomic_t *);
10548 long atomic64_sub_ret(long, atomic64_t *);
10549
10550 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10551 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10552
10553 #define atomic_inc_return(v) atomic_add_ret(1, v)
10554 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10555 +{
10556 + return atomic_add_ret_unchecked(1, v);
10557 +}
10558 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10559 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10560 +{
10561 + return atomic64_add_ret_unchecked(1, v);
10562 +}
10563
10564 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10565 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10566
10567 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10568 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10569 +{
10570 + return atomic_add_ret_unchecked(i, v);
10571 +}
10572 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10573 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10574 +{
10575 + return atomic64_add_ret_unchecked(i, v);
10576 +}
10577
10578 /*
10579 * atomic_inc_and_test - increment and test
10580 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10581 * other cases.
10582 */
10583 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10584 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10585 +{
10586 + return atomic_inc_return_unchecked(v) == 0;
10587 +}
10588 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10589
10590 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10591 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10592 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10593
10594 #define atomic_inc(v) atomic_add(1, v)
10595 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10596 +{
10597 + atomic_add_unchecked(1, v);
10598 +}
10599 #define atomic64_inc(v) atomic64_add(1, v)
10600 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10601 +{
10602 + atomic64_add_unchecked(1, v);
10603 +}
10604
10605 #define atomic_dec(v) atomic_sub(1, v)
10606 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10607 +{
10608 + atomic_sub_unchecked(1, v);
10609 +}
10610 #define atomic64_dec(v) atomic64_sub(1, v)
10611 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10612 +{
10613 + atomic64_sub_unchecked(1, v);
10614 +}
10615
10616 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10617 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10618
10619 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10620 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10621 +{
10622 + return cmpxchg(&v->counter, old, new);
10623 +}
10624 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10625 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10626 +{
10627 + return xchg(&v->counter, new);
10628 +}
10629
10630 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10631 {
10632 - int c, old;
10633 + int c, old, new;
10634 c = atomic_read(v);
10635 for (;;) {
10636 - if (unlikely(c == (u)))
10637 + if (unlikely(c == u))
10638 break;
10639 - old = atomic_cmpxchg((v), c, c + (a));
10640 +
10641 + asm volatile("addcc %2, %0, %0\n"
10642 +
10643 +#ifdef CONFIG_PAX_REFCOUNT
10644 + "tvs %%icc, 6\n"
10645 +#endif
10646 +
10647 + : "=r" (new)
10648 + : "0" (c), "ir" (a)
10649 + : "cc");
10650 +
10651 + old = atomic_cmpxchg(v, c, new);
10652 if (likely(old == c))
10653 break;
10654 c = old;
10655 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10656 #define atomic64_cmpxchg(v, o, n) \
10657 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10658 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10659 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10660 +{
10661 + return xchg(&v->counter, new);
10662 +}
10663
10664 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10665 {
10666 - long c, old;
10667 + long c, old, new;
10668 c = atomic64_read(v);
10669 for (;;) {
10670 - if (unlikely(c == (u)))
10671 + if (unlikely(c == u))
10672 break;
10673 - old = atomic64_cmpxchg((v), c, c + (a));
10674 +
10675 + asm volatile("addcc %2, %0, %0\n"
10676 +
10677 +#ifdef CONFIG_PAX_REFCOUNT
10678 + "tvs %%xcc, 6\n"
10679 +#endif
10680 +
10681 + : "=r" (new)
10682 + : "0" (c), "ir" (a)
10683 + : "cc");
10684 +
10685 + old = atomic64_cmpxchg(v, c, new);
10686 if (likely(old == c))
10687 break;
10688 c = old;
10689 }
10690 - return c != (u);
10691 + return c != u;
10692 }
10693
10694 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10695 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10696 index 305dcc3..7835030 100644
10697 --- a/arch/sparc/include/asm/barrier_64.h
10698 +++ b/arch/sparc/include/asm/barrier_64.h
10699 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10700 do { \
10701 compiletime_assert_atomic_type(*p); \
10702 barrier(); \
10703 - ACCESS_ONCE(*p) = (v); \
10704 + ACCESS_ONCE_RW(*p) = (v); \
10705 } while (0)
10706
10707 #define smp_load_acquire(p) \
10708 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10709 index 5bb6991..5c2132e 100644
10710 --- a/arch/sparc/include/asm/cache.h
10711 +++ b/arch/sparc/include/asm/cache.h
10712 @@ -7,10 +7,12 @@
10713 #ifndef _SPARC_CACHE_H
10714 #define _SPARC_CACHE_H
10715
10716 +#include <linux/const.h>
10717 +
10718 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10719
10720 #define L1_CACHE_SHIFT 5
10721 -#define L1_CACHE_BYTES 32
10722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10723
10724 #ifdef CONFIG_SPARC32
10725 #define SMP_CACHE_BYTES_SHIFT 5
10726 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10727 index a24e41f..47677ff 100644
10728 --- a/arch/sparc/include/asm/elf_32.h
10729 +++ b/arch/sparc/include/asm/elf_32.h
10730 @@ -114,6 +114,13 @@ typedef struct {
10731
10732 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10733
10734 +#ifdef CONFIG_PAX_ASLR
10735 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10736 +
10737 +#define PAX_DELTA_MMAP_LEN 16
10738 +#define PAX_DELTA_STACK_LEN 16
10739 +#endif
10740 +
10741 /* This yields a mask that user programs can use to figure out what
10742 instruction set this cpu supports. This can NOT be done in userspace
10743 on Sparc. */
10744 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10745 index 370ca1e..d4f4a98 100644
10746 --- a/arch/sparc/include/asm/elf_64.h
10747 +++ b/arch/sparc/include/asm/elf_64.h
10748 @@ -189,6 +189,13 @@ typedef struct {
10749 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10750 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10751
10752 +#ifdef CONFIG_PAX_ASLR
10753 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10754 +
10755 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10756 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10757 +#endif
10758 +
10759 extern unsigned long sparc64_elf_hwcap;
10760 #define ELF_HWCAP sparc64_elf_hwcap
10761
10762 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10763 index a3890da..f6a408e 100644
10764 --- a/arch/sparc/include/asm/pgalloc_32.h
10765 +++ b/arch/sparc/include/asm/pgalloc_32.h
10766 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10767 }
10768
10769 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10770 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10771
10772 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10773 unsigned long address)
10774 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10775 index 5e31871..b71c9d7 100644
10776 --- a/arch/sparc/include/asm/pgalloc_64.h
10777 +++ b/arch/sparc/include/asm/pgalloc_64.h
10778 @@ -38,6 +38,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10779 }
10780
10781 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10782 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10783
10784 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10785 {
10786 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10787 index 59ba6f6..4518128 100644
10788 --- a/arch/sparc/include/asm/pgtable.h
10789 +++ b/arch/sparc/include/asm/pgtable.h
10790 @@ -5,4 +5,8 @@
10791 #else
10792 #include <asm/pgtable_32.h>
10793 #endif
10794 +
10795 +#define ktla_ktva(addr) (addr)
10796 +#define ktva_ktla(addr) (addr)
10797 +
10798 #endif
10799 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10800 index b9b91ae..950b91e 100644
10801 --- a/arch/sparc/include/asm/pgtable_32.h
10802 +++ b/arch/sparc/include/asm/pgtable_32.h
10803 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10804 #define PAGE_SHARED SRMMU_PAGE_SHARED
10805 #define PAGE_COPY SRMMU_PAGE_COPY
10806 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10807 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10808 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10809 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10810 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10811
10812 /* Top-level page directory - dummy used by init-mm.
10813 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10814
10815 /* xwr */
10816 #define __P000 PAGE_NONE
10817 -#define __P001 PAGE_READONLY
10818 -#define __P010 PAGE_COPY
10819 -#define __P011 PAGE_COPY
10820 +#define __P001 PAGE_READONLY_NOEXEC
10821 +#define __P010 PAGE_COPY_NOEXEC
10822 +#define __P011 PAGE_COPY_NOEXEC
10823 #define __P100 PAGE_READONLY
10824 #define __P101 PAGE_READONLY
10825 #define __P110 PAGE_COPY
10826 #define __P111 PAGE_COPY
10827
10828 #define __S000 PAGE_NONE
10829 -#define __S001 PAGE_READONLY
10830 -#define __S010 PAGE_SHARED
10831 -#define __S011 PAGE_SHARED
10832 +#define __S001 PAGE_READONLY_NOEXEC
10833 +#define __S010 PAGE_SHARED_NOEXEC
10834 +#define __S011 PAGE_SHARED_NOEXEC
10835 #define __S100 PAGE_READONLY
10836 #define __S101 PAGE_READONLY
10837 #define __S110 PAGE_SHARED
10838 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10839 index 79da178..c2eede8 100644
10840 --- a/arch/sparc/include/asm/pgtsrmmu.h
10841 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10842 @@ -115,6 +115,11 @@
10843 SRMMU_EXEC | SRMMU_REF)
10844 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10845 SRMMU_EXEC | SRMMU_REF)
10846 +
10847 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10848 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10849 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10850 +
10851 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10852 SRMMU_DIRTY | SRMMU_REF)
10853
10854 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10855 index 29d64b1..4272fe8 100644
10856 --- a/arch/sparc/include/asm/setup.h
10857 +++ b/arch/sparc/include/asm/setup.h
10858 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10859 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10860
10861 /* init_64.c */
10862 -extern atomic_t dcpage_flushes;
10863 -extern atomic_t dcpage_flushes_xcall;
10864 +extern atomic_unchecked_t dcpage_flushes;
10865 +extern atomic_unchecked_t dcpage_flushes_xcall;
10866
10867 extern int sysctl_tsb_ratio;
10868 #endif
10869 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10870 index 9689176..63c18ea 100644
10871 --- a/arch/sparc/include/asm/spinlock_64.h
10872 +++ b/arch/sparc/include/asm/spinlock_64.h
10873 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10874
10875 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10876
10877 -static void inline arch_read_lock(arch_rwlock_t *lock)
10878 +static inline void arch_read_lock(arch_rwlock_t *lock)
10879 {
10880 unsigned long tmp1, tmp2;
10881
10882 __asm__ __volatile__ (
10883 "1: ldsw [%2], %0\n"
10884 " brlz,pn %0, 2f\n"
10885 -"4: add %0, 1, %1\n"
10886 +"4: addcc %0, 1, %1\n"
10887 +
10888 +#ifdef CONFIG_PAX_REFCOUNT
10889 +" tvs %%icc, 6\n"
10890 +#endif
10891 +
10892 " cas [%2], %0, %1\n"
10893 " cmp %0, %1\n"
10894 " bne,pn %%icc, 1b\n"
10895 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10896 " .previous"
10897 : "=&r" (tmp1), "=&r" (tmp2)
10898 : "r" (lock)
10899 - : "memory");
10900 + : "memory", "cc");
10901 }
10902
10903 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10904 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10905 {
10906 int tmp1, tmp2;
10907
10908 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10909 "1: ldsw [%2], %0\n"
10910 " brlz,a,pn %0, 2f\n"
10911 " mov 0, %0\n"
10912 -" add %0, 1, %1\n"
10913 +" addcc %0, 1, %1\n"
10914 +
10915 +#ifdef CONFIG_PAX_REFCOUNT
10916 +" tvs %%icc, 6\n"
10917 +#endif
10918 +
10919 " cas [%2], %0, %1\n"
10920 " cmp %0, %1\n"
10921 " bne,pn %%icc, 1b\n"
10922 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10923 return tmp1;
10924 }
10925
10926 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10927 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10928 {
10929 unsigned long tmp1, tmp2;
10930
10931 __asm__ __volatile__(
10932 "1: lduw [%2], %0\n"
10933 -" sub %0, 1, %1\n"
10934 +" subcc %0, 1, %1\n"
10935 +
10936 +#ifdef CONFIG_PAX_REFCOUNT
10937 +" tvs %%icc, 6\n"
10938 +#endif
10939 +
10940 " cas [%2], %0, %1\n"
10941 " cmp %0, %1\n"
10942 " bne,pn %%xcc, 1b\n"
10943 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10944 : "memory");
10945 }
10946
10947 -static void inline arch_write_lock(arch_rwlock_t *lock)
10948 +static inline void arch_write_lock(arch_rwlock_t *lock)
10949 {
10950 unsigned long mask, tmp1, tmp2;
10951
10952 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10953 : "memory");
10954 }
10955
10956 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10957 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10958 {
10959 __asm__ __volatile__(
10960 " stw %%g0, [%0]"
10961 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10962 : "memory");
10963 }
10964
10965 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10966 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10967 {
10968 unsigned long mask, tmp1, tmp2, result;
10969
10970 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10971 index 96efa7a..16858bf 100644
10972 --- a/arch/sparc/include/asm/thread_info_32.h
10973 +++ b/arch/sparc/include/asm/thread_info_32.h
10974 @@ -49,6 +49,8 @@ struct thread_info {
10975 unsigned long w_saved;
10976
10977 struct restart_block restart_block;
10978 +
10979 + unsigned long lowest_stack;
10980 };
10981
10982 /*
10983 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10984 index cc6275c..7eb8e21 100644
10985 --- a/arch/sparc/include/asm/thread_info_64.h
10986 +++ b/arch/sparc/include/asm/thread_info_64.h
10987 @@ -63,6 +63,8 @@ struct thread_info {
10988 struct pt_regs *kern_una_regs;
10989 unsigned int kern_una_insn;
10990
10991 + unsigned long lowest_stack;
10992 +
10993 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10994 __attribute__ ((aligned(64)));
10995 };
10996 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10997 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10998 /* flag bit 4 is available */
10999 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
11000 -/* flag bit 6 is available */
11001 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
11002 #define TIF_32BIT 7 /* 32-bit binary */
11003 #define TIF_NOHZ 8 /* in adaptive nohz mode */
11004 #define TIF_SECCOMP 9 /* secure computing */
11005 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
11006 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
11007 +
11008 /* NOTE: Thread flags >= 12 should be ones we have no interest
11009 * in using in assembly, else we can't use the mask as
11010 * an immediate value in instructions such as andcc.
11011 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
11012 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
11013 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
11014 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
11015 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
11016
11017 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
11018 _TIF_DO_NOTIFY_RESUME_MASK | \
11019 _TIF_NEED_RESCHED)
11020 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
11021
11022 +#define _TIF_WORK_SYSCALL \
11023 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
11024 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
11025 +
11026 +
11027 /*
11028 * Thread-synchronous status.
11029 *
11030 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
11031 index bd56c28..4b63d83 100644
11032 --- a/arch/sparc/include/asm/uaccess.h
11033 +++ b/arch/sparc/include/asm/uaccess.h
11034 @@ -1,5 +1,6 @@
11035 #ifndef ___ASM_SPARC_UACCESS_H
11036 #define ___ASM_SPARC_UACCESS_H
11037 +
11038 #if defined(__sparc__) && defined(__arch64__)
11039 #include <asm/uaccess_64.h>
11040 #else
11041 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
11042 index 9634d08..f55fe4f 100644
11043 --- a/arch/sparc/include/asm/uaccess_32.h
11044 +++ b/arch/sparc/include/asm/uaccess_32.h
11045 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
11046
11047 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
11048 {
11049 - if (n && __access_ok((unsigned long) to, n))
11050 + if ((long)n < 0)
11051 + return n;
11052 +
11053 + if (n && __access_ok((unsigned long) to, n)) {
11054 + if (!__builtin_constant_p(n))
11055 + check_object_size(from, n, true);
11056 return __copy_user(to, (__force void __user *) from, n);
11057 - else
11058 + } else
11059 return n;
11060 }
11061
11062 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
11063 {
11064 + if ((long)n < 0)
11065 + return n;
11066 +
11067 + if (!__builtin_constant_p(n))
11068 + check_object_size(from, n, true);
11069 +
11070 return __copy_user(to, (__force void __user *) from, n);
11071 }
11072
11073 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
11074 {
11075 - if (n && __access_ok((unsigned long) from, n))
11076 + if ((long)n < 0)
11077 + return n;
11078 +
11079 + if (n && __access_ok((unsigned long) from, n)) {
11080 + if (!__builtin_constant_p(n))
11081 + check_object_size(to, n, false);
11082 return __copy_user((__force void __user *) to, from, n);
11083 - else
11084 + } else
11085 return n;
11086 }
11087
11088 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
11089 {
11090 + if ((long)n < 0)
11091 + return n;
11092 +
11093 return __copy_user((__force void __user *) to, from, n);
11094 }
11095
11096 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
11097 index c990a5e..f17b9c1 100644
11098 --- a/arch/sparc/include/asm/uaccess_64.h
11099 +++ b/arch/sparc/include/asm/uaccess_64.h
11100 @@ -10,6 +10,7 @@
11101 #include <linux/compiler.h>
11102 #include <linux/string.h>
11103 #include <linux/thread_info.h>
11104 +#include <linux/kernel.h>
11105 #include <asm/asi.h>
11106 #include <asm/spitfire.h>
11107 #include <asm-generic/uaccess-unaligned.h>
11108 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
11109 static inline unsigned long __must_check
11110 copy_from_user(void *to, const void __user *from, unsigned long size)
11111 {
11112 - unsigned long ret = ___copy_from_user(to, from, size);
11113 + unsigned long ret;
11114
11115 + if ((long)size < 0 || size > INT_MAX)
11116 + return size;
11117 +
11118 + if (!__builtin_constant_p(size))
11119 + check_object_size(to, size, false);
11120 +
11121 + ret = ___copy_from_user(to, from, size);
11122 if (unlikely(ret))
11123 ret = copy_from_user_fixup(to, from, size);
11124
11125 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
11126 static inline unsigned long __must_check
11127 copy_to_user(void __user *to, const void *from, unsigned long size)
11128 {
11129 - unsigned long ret = ___copy_to_user(to, from, size);
11130 + unsigned long ret;
11131
11132 + if ((long)size < 0 || size > INT_MAX)
11133 + return size;
11134 +
11135 + if (!__builtin_constant_p(size))
11136 + check_object_size(from, size, true);
11137 +
11138 + ret = ___copy_to_user(to, from, size);
11139 if (unlikely(ret))
11140 ret = copy_to_user_fixup(to, from, size);
11141 return ret;
11142 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
11143 index 7cf9c6e..6206648 100644
11144 --- a/arch/sparc/kernel/Makefile
11145 +++ b/arch/sparc/kernel/Makefile
11146 @@ -4,7 +4,7 @@
11147 #
11148
11149 asflags-y := -ansi
11150 -ccflags-y := -Werror
11151 +#ccflags-y := -Werror
11152
11153 extra-y := head_$(BITS).o
11154
11155 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
11156 index 50e7b62..79fae35 100644
11157 --- a/arch/sparc/kernel/process_32.c
11158 +++ b/arch/sparc/kernel/process_32.c
11159 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
11160
11161 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
11162 r->psr, r->pc, r->npc, r->y, print_tainted());
11163 - printk("PC: <%pS>\n", (void *) r->pc);
11164 + printk("PC: <%pA>\n", (void *) r->pc);
11165 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11166 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
11167 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
11168 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11169 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
11170 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
11171 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
11172 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
11173
11174 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11175 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
11176 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11177 rw = (struct reg_window32 *) fp;
11178 pc = rw->ins[7];
11179 printk("[%08lx : ", pc);
11180 - printk("%pS ] ", (void *) pc);
11181 + printk("%pA ] ", (void *) pc);
11182 fp = rw->ins[6];
11183 } while (++count < 16);
11184 printk("\n");
11185 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
11186 index 0be7bf9..2b1cba8 100644
11187 --- a/arch/sparc/kernel/process_64.c
11188 +++ b/arch/sparc/kernel/process_64.c
11189 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
11190 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
11191 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
11192 if (regs->tstate & TSTATE_PRIV)
11193 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
11194 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
11195 }
11196
11197 void show_regs(struct pt_regs *regs)
11198 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
11199
11200 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
11201 regs->tpc, regs->tnpc, regs->y, print_tainted());
11202 - printk("TPC: <%pS>\n", (void *) regs->tpc);
11203 + printk("TPC: <%pA>\n", (void *) regs->tpc);
11204 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
11205 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
11206 regs->u_regs[3]);
11207 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
11208 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
11209 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
11210 regs->u_regs[15]);
11211 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
11212 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
11213 show_regwindow(regs);
11214 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
11215 }
11216 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
11217 ((tp && tp->task) ? tp->task->pid : -1));
11218
11219 if (gp->tstate & TSTATE_PRIV) {
11220 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
11221 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
11222 (void *) gp->tpc,
11223 (void *) gp->o7,
11224 (void *) gp->i7,
11225 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
11226 index 79cc0d1..ec62734 100644
11227 --- a/arch/sparc/kernel/prom_common.c
11228 +++ b/arch/sparc/kernel/prom_common.c
11229 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
11230
11231 unsigned int prom_early_allocated __initdata;
11232
11233 -static struct of_pdt_ops prom_sparc_ops __initdata = {
11234 +static struct of_pdt_ops prom_sparc_ops __initconst = {
11235 .nextprop = prom_common_nextprop,
11236 .getproplen = prom_getproplen,
11237 .getproperty = prom_getproperty,
11238 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
11239 index c13c9f2..d572c34 100644
11240 --- a/arch/sparc/kernel/ptrace_64.c
11241 +++ b/arch/sparc/kernel/ptrace_64.c
11242 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
11243 return ret;
11244 }
11245
11246 +#ifdef CONFIG_GRKERNSEC_SETXID
11247 +extern void gr_delayed_cred_worker(void);
11248 +#endif
11249 +
11250 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11251 {
11252 int ret = 0;
11253 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11254 if (test_thread_flag(TIF_NOHZ))
11255 user_exit();
11256
11257 +#ifdef CONFIG_GRKERNSEC_SETXID
11258 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11259 + gr_delayed_cred_worker();
11260 +#endif
11261 +
11262 if (test_thread_flag(TIF_SYSCALL_TRACE))
11263 ret = tracehook_report_syscall_entry(regs);
11264
11265 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
11266 if (test_thread_flag(TIF_NOHZ))
11267 user_exit();
11268
11269 +#ifdef CONFIG_GRKERNSEC_SETXID
11270 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11271 + gr_delayed_cred_worker();
11272 +#endif
11273 +
11274 audit_syscall_exit(regs);
11275
11276 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
11277 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
11278 index 81954ee..6cfaa98 100644
11279 --- a/arch/sparc/kernel/smp_64.c
11280 +++ b/arch/sparc/kernel/smp_64.c
11281 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11282 return;
11283
11284 #ifdef CONFIG_DEBUG_DCFLUSH
11285 - atomic_inc(&dcpage_flushes);
11286 + atomic_inc_unchecked(&dcpage_flushes);
11287 #endif
11288
11289 this_cpu = get_cpu();
11290 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11291 xcall_deliver(data0, __pa(pg_addr),
11292 (u64) pg_addr, cpumask_of(cpu));
11293 #ifdef CONFIG_DEBUG_DCFLUSH
11294 - atomic_inc(&dcpage_flushes_xcall);
11295 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11296 #endif
11297 }
11298 }
11299 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11300 preempt_disable();
11301
11302 #ifdef CONFIG_DEBUG_DCFLUSH
11303 - atomic_inc(&dcpage_flushes);
11304 + atomic_inc_unchecked(&dcpage_flushes);
11305 #endif
11306 data0 = 0;
11307 pg_addr = page_address(page);
11308 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11309 xcall_deliver(data0, __pa(pg_addr),
11310 (u64) pg_addr, cpu_online_mask);
11311 #ifdef CONFIG_DEBUG_DCFLUSH
11312 - atomic_inc(&dcpage_flushes_xcall);
11313 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11314 #endif
11315 }
11316 __local_flush_dcache_page(page);
11317 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
11318 index 646988d..b88905f 100644
11319 --- a/arch/sparc/kernel/sys_sparc_32.c
11320 +++ b/arch/sparc/kernel/sys_sparc_32.c
11321 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11322 if (len > TASK_SIZE - PAGE_SIZE)
11323 return -ENOMEM;
11324 if (!addr)
11325 - addr = TASK_UNMAPPED_BASE;
11326 + addr = current->mm->mmap_base;
11327
11328 info.flags = 0;
11329 info.length = len;
11330 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
11331 index c85403d..6af95c9 100644
11332 --- a/arch/sparc/kernel/sys_sparc_64.c
11333 +++ b/arch/sparc/kernel/sys_sparc_64.c
11334 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11335 struct vm_area_struct * vma;
11336 unsigned long task_size = TASK_SIZE;
11337 int do_color_align;
11338 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11339 struct vm_unmapped_area_info info;
11340
11341 if (flags & MAP_FIXED) {
11342 /* We do not accept a shared mapping if it would violate
11343 * cache aliasing constraints.
11344 */
11345 - if ((flags & MAP_SHARED) &&
11346 + if ((filp || (flags & MAP_SHARED)) &&
11347 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11348 return -EINVAL;
11349 return addr;
11350 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11351 if (filp || (flags & MAP_SHARED))
11352 do_color_align = 1;
11353
11354 +#ifdef CONFIG_PAX_RANDMMAP
11355 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11356 +#endif
11357 +
11358 if (addr) {
11359 if (do_color_align)
11360 addr = COLOR_ALIGN(addr, pgoff);
11361 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11362 addr = PAGE_ALIGN(addr);
11363
11364 vma = find_vma(mm, addr);
11365 - if (task_size - len >= addr &&
11366 - (!vma || addr + len <= vma->vm_start))
11367 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11368 return addr;
11369 }
11370
11371 info.flags = 0;
11372 info.length = len;
11373 - info.low_limit = TASK_UNMAPPED_BASE;
11374 + info.low_limit = mm->mmap_base;
11375 info.high_limit = min(task_size, VA_EXCLUDE_START);
11376 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11377 info.align_offset = pgoff << PAGE_SHIFT;
11378 + info.threadstack_offset = offset;
11379 addr = vm_unmapped_area(&info);
11380
11381 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11382 VM_BUG_ON(addr != -ENOMEM);
11383 info.low_limit = VA_EXCLUDE_END;
11384 +
11385 +#ifdef CONFIG_PAX_RANDMMAP
11386 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11387 + info.low_limit += mm->delta_mmap;
11388 +#endif
11389 +
11390 info.high_limit = task_size;
11391 addr = vm_unmapped_area(&info);
11392 }
11393 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11394 unsigned long task_size = STACK_TOP32;
11395 unsigned long addr = addr0;
11396 int do_color_align;
11397 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11398 struct vm_unmapped_area_info info;
11399
11400 /* This should only ever run for 32-bit processes. */
11401 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11402 /* We do not accept a shared mapping if it would violate
11403 * cache aliasing constraints.
11404 */
11405 - if ((flags & MAP_SHARED) &&
11406 + if ((filp || (flags & MAP_SHARED)) &&
11407 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11408 return -EINVAL;
11409 return addr;
11410 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11411 if (filp || (flags & MAP_SHARED))
11412 do_color_align = 1;
11413
11414 +#ifdef CONFIG_PAX_RANDMMAP
11415 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11416 +#endif
11417 +
11418 /* requesting a specific address */
11419 if (addr) {
11420 if (do_color_align)
11421 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11422 addr = PAGE_ALIGN(addr);
11423
11424 vma = find_vma(mm, addr);
11425 - if (task_size - len >= addr &&
11426 - (!vma || addr + len <= vma->vm_start))
11427 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11428 return addr;
11429 }
11430
11431 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11432 info.high_limit = mm->mmap_base;
11433 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11434 info.align_offset = pgoff << PAGE_SHIFT;
11435 + info.threadstack_offset = offset;
11436 addr = vm_unmapped_area(&info);
11437
11438 /*
11439 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11440 VM_BUG_ON(addr != -ENOMEM);
11441 info.flags = 0;
11442 info.low_limit = TASK_UNMAPPED_BASE;
11443 +
11444 +#ifdef CONFIG_PAX_RANDMMAP
11445 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11446 + info.low_limit += mm->delta_mmap;
11447 +#endif
11448 +
11449 info.high_limit = STACK_TOP32;
11450 addr = vm_unmapped_area(&info);
11451 }
11452 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11453 EXPORT_SYMBOL(get_fb_unmapped_area);
11454
11455 /* Essentially the same as PowerPC. */
11456 -static unsigned long mmap_rnd(void)
11457 +static unsigned long mmap_rnd(struct mm_struct *mm)
11458 {
11459 unsigned long rnd = 0UL;
11460
11461 +#ifdef CONFIG_PAX_RANDMMAP
11462 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11463 +#endif
11464 +
11465 if (current->flags & PF_RANDOMIZE) {
11466 unsigned long val = get_random_int();
11467 if (test_thread_flag(TIF_32BIT))
11468 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11469
11470 void arch_pick_mmap_layout(struct mm_struct *mm)
11471 {
11472 - unsigned long random_factor = mmap_rnd();
11473 + unsigned long random_factor = mmap_rnd(mm);
11474 unsigned long gap;
11475
11476 /*
11477 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11478 gap == RLIM_INFINITY ||
11479 sysctl_legacy_va_layout) {
11480 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11481 +
11482 +#ifdef CONFIG_PAX_RANDMMAP
11483 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11484 + mm->mmap_base += mm->delta_mmap;
11485 +#endif
11486 +
11487 mm->get_unmapped_area = arch_get_unmapped_area;
11488 } else {
11489 /* We know it's 32-bit */
11490 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11491 gap = (task_size / 6 * 5);
11492
11493 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11494 +
11495 +#ifdef CONFIG_PAX_RANDMMAP
11496 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11497 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11498 +#endif
11499 +
11500 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11501 }
11502 }
11503 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11504 index 33a17e7..d87fb1f 100644
11505 --- a/arch/sparc/kernel/syscalls.S
11506 +++ b/arch/sparc/kernel/syscalls.S
11507 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11508 #endif
11509 .align 32
11510 1: ldx [%g6 + TI_FLAGS], %l5
11511 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11512 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11513 be,pt %icc, rtrap
11514 nop
11515 call syscall_trace_leave
11516 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11517
11518 srl %i3, 0, %o3 ! IEU0
11519 srl %i2, 0, %o2 ! IEU0 Group
11520 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11521 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11522 bne,pn %icc, linux_syscall_trace32 ! CTI
11523 mov %i0, %l5 ! IEU1
11524 5: call %l7 ! CTI Group brk forced
11525 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11526
11527 mov %i3, %o3 ! IEU1
11528 mov %i4, %o4 ! IEU0 Group
11529 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11530 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11531 bne,pn %icc, linux_syscall_trace ! CTI Group
11532 mov %i0, %l5 ! IEU0
11533 2: call %l7 ! CTI Group brk forced
11534 @@ -223,7 +223,7 @@ ret_sys_call:
11535
11536 cmp %o0, -ERESTART_RESTARTBLOCK
11537 bgeu,pn %xcc, 1f
11538 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11539 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11540 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11541
11542 2:
11543 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11544 index 6fd386c5..6907d81 100644
11545 --- a/arch/sparc/kernel/traps_32.c
11546 +++ b/arch/sparc/kernel/traps_32.c
11547 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11548 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11549 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11550
11551 +extern void gr_handle_kernel_exploit(void);
11552 +
11553 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11554 {
11555 static int die_counter;
11556 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11557 count++ < 30 &&
11558 (((unsigned long) rw) >= PAGE_OFFSET) &&
11559 !(((unsigned long) rw) & 0x7)) {
11560 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11561 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11562 (void *) rw->ins[7]);
11563 rw = (struct reg_window32 *)rw->ins[6];
11564 }
11565 }
11566 printk("Instruction DUMP:");
11567 instruction_dump ((unsigned long *) regs->pc);
11568 - if(regs->psr & PSR_PS)
11569 + if(regs->psr & PSR_PS) {
11570 + gr_handle_kernel_exploit();
11571 do_exit(SIGKILL);
11572 + }
11573 do_exit(SIGSEGV);
11574 }
11575
11576 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11577 index 981a769..d906eda 100644
11578 --- a/arch/sparc/kernel/traps_64.c
11579 +++ b/arch/sparc/kernel/traps_64.c
11580 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11581 i + 1,
11582 p->trapstack[i].tstate, p->trapstack[i].tpc,
11583 p->trapstack[i].tnpc, p->trapstack[i].tt);
11584 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11585 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11586 }
11587 }
11588
11589 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11590
11591 lvl -= 0x100;
11592 if (regs->tstate & TSTATE_PRIV) {
11593 +
11594 +#ifdef CONFIG_PAX_REFCOUNT
11595 + if (lvl == 6)
11596 + pax_report_refcount_overflow(regs);
11597 +#endif
11598 +
11599 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11600 die_if_kernel(buffer, regs);
11601 }
11602 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11603 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11604 {
11605 char buffer[32];
11606 -
11607 +
11608 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11609 0, lvl, SIGTRAP) == NOTIFY_STOP)
11610 return;
11611
11612 +#ifdef CONFIG_PAX_REFCOUNT
11613 + if (lvl == 6)
11614 + pax_report_refcount_overflow(regs);
11615 +#endif
11616 +
11617 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11618
11619 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11620 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11621 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11622 printk("%s" "ERROR(%d): ",
11623 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11624 - printk("TPC<%pS>\n", (void *) regs->tpc);
11625 + printk("TPC<%pA>\n", (void *) regs->tpc);
11626 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11627 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11628 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11629 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11630 smp_processor_id(),
11631 (type & 0x1) ? 'I' : 'D',
11632 regs->tpc);
11633 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11634 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11635 panic("Irrecoverable Cheetah+ parity error.");
11636 }
11637
11638 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11639 smp_processor_id(),
11640 (type & 0x1) ? 'I' : 'D',
11641 regs->tpc);
11642 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11643 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11644 }
11645
11646 struct sun4v_error_entry {
11647 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11648 /*0x38*/u64 reserved_5;
11649 };
11650
11651 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11652 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11653 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11654 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11655
11656 static const char *sun4v_err_type_to_str(u8 type)
11657 {
11658 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11659 }
11660
11661 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11662 - int cpu, const char *pfx, atomic_t *ocnt)
11663 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11664 {
11665 u64 *raw_ptr = (u64 *) ent;
11666 u32 attrs;
11667 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11668
11669 show_regs(regs);
11670
11671 - if ((cnt = atomic_read(ocnt)) != 0) {
11672 - atomic_set(ocnt, 0);
11673 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11674 + atomic_set_unchecked(ocnt, 0);
11675 wmb();
11676 printk("%s: Queue overflowed %d times.\n",
11677 pfx, cnt);
11678 @@ -2048,7 +2059,7 @@ out:
11679 */
11680 void sun4v_resum_overflow(struct pt_regs *regs)
11681 {
11682 - atomic_inc(&sun4v_resum_oflow_cnt);
11683 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11684 }
11685
11686 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11687 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11688 /* XXX Actually even this can make not that much sense. Perhaps
11689 * XXX we should just pull the plug and panic directly from here?
11690 */
11691 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11692 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11693 }
11694
11695 static void sun4v_tlb_error(struct pt_regs *regs)
11696 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11697
11698 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11699 regs->tpc, tl);
11700 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11701 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11702 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11703 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11704 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11705 (void *) regs->u_regs[UREG_I7]);
11706 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11707 "pte[%lx] error[%lx]\n",
11708 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11709
11710 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11711 regs->tpc, tl);
11712 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11713 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11714 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11715 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11716 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11717 (void *) regs->u_regs[UREG_I7]);
11718 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11719 "pte[%lx] error[%lx]\n",
11720 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11721 fp = (unsigned long)sf->fp + STACK_BIAS;
11722 }
11723
11724 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11725 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11726 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11727 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11728 int index = tsk->curr_ret_stack;
11729 if (tsk->ret_stack && index >= graph) {
11730 pc = tsk->ret_stack[index - graph].ret;
11731 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11732 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11733 graph++;
11734 }
11735 }
11736 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11737 return (struct reg_window *) (fp + STACK_BIAS);
11738 }
11739
11740 +extern void gr_handle_kernel_exploit(void);
11741 +
11742 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11743 {
11744 static int die_counter;
11745 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11746 while (rw &&
11747 count++ < 30 &&
11748 kstack_valid(tp, (unsigned long) rw)) {
11749 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11750 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11751 (void *) rw->ins[7]);
11752
11753 rw = kernel_stack_up(rw);
11754 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11755 }
11756 user_instruction_dump ((unsigned int __user *) regs->tpc);
11757 }
11758 - if (regs->tstate & TSTATE_PRIV)
11759 + if (regs->tstate & TSTATE_PRIV) {
11760 + gr_handle_kernel_exploit();
11761 do_exit(SIGKILL);
11762 + }
11763 do_exit(SIGSEGV);
11764 }
11765 EXPORT_SYMBOL(die_if_kernel);
11766 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11767 index 62098a8..547ab2c 100644
11768 --- a/arch/sparc/kernel/unaligned_64.c
11769 +++ b/arch/sparc/kernel/unaligned_64.c
11770 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11771 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11772
11773 if (__ratelimit(&ratelimit)) {
11774 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11775 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11776 regs->tpc, (void *) regs->tpc);
11777 }
11778 }
11779 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11780 index 3269b02..64f5231 100644
11781 --- a/arch/sparc/lib/Makefile
11782 +++ b/arch/sparc/lib/Makefile
11783 @@ -2,7 +2,7 @@
11784 #
11785
11786 asflags-y := -ansi -DST_DIV0=0x02
11787 -ccflags-y := -Werror
11788 +#ccflags-y := -Werror
11789
11790 lib-$(CONFIG_SPARC32) += ashrdi3.o
11791 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11792 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11793 index 85c233d..68500e0 100644
11794 --- a/arch/sparc/lib/atomic_64.S
11795 +++ b/arch/sparc/lib/atomic_64.S
11796 @@ -17,7 +17,12 @@
11797 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11798 BACKOFF_SETUP(%o2)
11799 1: lduw [%o1], %g1
11800 - add %g1, %o0, %g7
11801 + addcc %g1, %o0, %g7
11802 +
11803 +#ifdef CONFIG_PAX_REFCOUNT
11804 + tvs %icc, 6
11805 +#endif
11806 +
11807 cas [%o1], %g1, %g7
11808 cmp %g1, %g7
11809 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11810 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11811 2: BACKOFF_SPIN(%o2, %o3, 1b)
11812 ENDPROC(atomic_add)
11813
11814 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11815 + BACKOFF_SETUP(%o2)
11816 +1: lduw [%o1], %g1
11817 + add %g1, %o0, %g7
11818 + cas [%o1], %g1, %g7
11819 + cmp %g1, %g7
11820 + bne,pn %icc, 2f
11821 + nop
11822 + retl
11823 + nop
11824 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11825 +ENDPROC(atomic_add_unchecked)
11826 +
11827 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11828 BACKOFF_SETUP(%o2)
11829 1: lduw [%o1], %g1
11830 - sub %g1, %o0, %g7
11831 + subcc %g1, %o0, %g7
11832 +
11833 +#ifdef CONFIG_PAX_REFCOUNT
11834 + tvs %icc, 6
11835 +#endif
11836 +
11837 cas [%o1], %g1, %g7
11838 cmp %g1, %g7
11839 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11840 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11841 2: BACKOFF_SPIN(%o2, %o3, 1b)
11842 ENDPROC(atomic_sub)
11843
11844 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11845 + BACKOFF_SETUP(%o2)
11846 +1: lduw [%o1], %g1
11847 + sub %g1, %o0, %g7
11848 + cas [%o1], %g1, %g7
11849 + cmp %g1, %g7
11850 + bne,pn %icc, 2f
11851 + nop
11852 + retl
11853 + nop
11854 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11855 +ENDPROC(atomic_sub_unchecked)
11856 +
11857 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11858 BACKOFF_SETUP(%o2)
11859 1: lduw [%o1], %g1
11860 - add %g1, %o0, %g7
11861 + addcc %g1, %o0, %g7
11862 +
11863 +#ifdef CONFIG_PAX_REFCOUNT
11864 + tvs %icc, 6
11865 +#endif
11866 +
11867 cas [%o1], %g1, %g7
11868 cmp %g1, %g7
11869 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11870 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11871 2: BACKOFF_SPIN(%o2, %o3, 1b)
11872 ENDPROC(atomic_add_ret)
11873
11874 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11875 + BACKOFF_SETUP(%o2)
11876 +1: lduw [%o1], %g1
11877 + addcc %g1, %o0, %g7
11878 + cas [%o1], %g1, %g7
11879 + cmp %g1, %g7
11880 + bne,pn %icc, 2f
11881 + add %g7, %o0, %g7
11882 + sra %g7, 0, %o0
11883 + retl
11884 + nop
11885 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11886 +ENDPROC(atomic_add_ret_unchecked)
11887 +
11888 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11889 BACKOFF_SETUP(%o2)
11890 1: lduw [%o1], %g1
11891 - sub %g1, %o0, %g7
11892 + subcc %g1, %o0, %g7
11893 +
11894 +#ifdef CONFIG_PAX_REFCOUNT
11895 + tvs %icc, 6
11896 +#endif
11897 +
11898 cas [%o1], %g1, %g7
11899 cmp %g1, %g7
11900 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11901 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11902 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11903 BACKOFF_SETUP(%o2)
11904 1: ldx [%o1], %g1
11905 - add %g1, %o0, %g7
11906 + addcc %g1, %o0, %g7
11907 +
11908 +#ifdef CONFIG_PAX_REFCOUNT
11909 + tvs %xcc, 6
11910 +#endif
11911 +
11912 casx [%o1], %g1, %g7
11913 cmp %g1, %g7
11914 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11915 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11916 2: BACKOFF_SPIN(%o2, %o3, 1b)
11917 ENDPROC(atomic64_add)
11918
11919 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11920 + BACKOFF_SETUP(%o2)
11921 +1: ldx [%o1], %g1
11922 + addcc %g1, %o0, %g7
11923 + casx [%o1], %g1, %g7
11924 + cmp %g1, %g7
11925 + bne,pn %xcc, 2f
11926 + nop
11927 + retl
11928 + nop
11929 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11930 +ENDPROC(atomic64_add_unchecked)
11931 +
11932 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11933 BACKOFF_SETUP(%o2)
11934 1: ldx [%o1], %g1
11935 - sub %g1, %o0, %g7
11936 + subcc %g1, %o0, %g7
11937 +
11938 +#ifdef CONFIG_PAX_REFCOUNT
11939 + tvs %xcc, 6
11940 +#endif
11941 +
11942 casx [%o1], %g1, %g7
11943 cmp %g1, %g7
11944 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11945 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11946 2: BACKOFF_SPIN(%o2, %o3, 1b)
11947 ENDPROC(atomic64_sub)
11948
11949 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11950 + BACKOFF_SETUP(%o2)
11951 +1: ldx [%o1], %g1
11952 + subcc %g1, %o0, %g7
11953 + casx [%o1], %g1, %g7
11954 + cmp %g1, %g7
11955 + bne,pn %xcc, 2f
11956 + nop
11957 + retl
11958 + nop
11959 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11960 +ENDPROC(atomic64_sub_unchecked)
11961 +
11962 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11963 BACKOFF_SETUP(%o2)
11964 1: ldx [%o1], %g1
11965 - add %g1, %o0, %g7
11966 + addcc %g1, %o0, %g7
11967 +
11968 +#ifdef CONFIG_PAX_REFCOUNT
11969 + tvs %xcc, 6
11970 +#endif
11971 +
11972 casx [%o1], %g1, %g7
11973 cmp %g1, %g7
11974 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11975 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11976 2: BACKOFF_SPIN(%o2, %o3, 1b)
11977 ENDPROC(atomic64_add_ret)
11978
11979 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11980 + BACKOFF_SETUP(%o2)
11981 +1: ldx [%o1], %g1
11982 + addcc %g1, %o0, %g7
11983 + casx [%o1], %g1, %g7
11984 + cmp %g1, %g7
11985 + bne,pn %xcc, 2f
11986 + add %g7, %o0, %g7
11987 + mov %g7, %o0
11988 + retl
11989 + nop
11990 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11991 +ENDPROC(atomic64_add_ret_unchecked)
11992 +
11993 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11994 BACKOFF_SETUP(%o2)
11995 1: ldx [%o1], %g1
11996 - sub %g1, %o0, %g7
11997 + subcc %g1, %o0, %g7
11998 +
11999 +#ifdef CONFIG_PAX_REFCOUNT
12000 + tvs %xcc, 6
12001 +#endif
12002 +
12003 casx [%o1], %g1, %g7
12004 cmp %g1, %g7
12005 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12006 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
12007 index 323335b..ed85ea2 100644
12008 --- a/arch/sparc/lib/ksyms.c
12009 +++ b/arch/sparc/lib/ksyms.c
12010 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
12011
12012 /* Atomic counter implementation. */
12013 EXPORT_SYMBOL(atomic_add);
12014 +EXPORT_SYMBOL(atomic_add_unchecked);
12015 EXPORT_SYMBOL(atomic_add_ret);
12016 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
12017 EXPORT_SYMBOL(atomic_sub);
12018 +EXPORT_SYMBOL(atomic_sub_unchecked);
12019 EXPORT_SYMBOL(atomic_sub_ret);
12020 EXPORT_SYMBOL(atomic64_add);
12021 +EXPORT_SYMBOL(atomic64_add_unchecked);
12022 EXPORT_SYMBOL(atomic64_add_ret);
12023 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
12024 EXPORT_SYMBOL(atomic64_sub);
12025 +EXPORT_SYMBOL(atomic64_sub_unchecked);
12026 EXPORT_SYMBOL(atomic64_sub_ret);
12027 EXPORT_SYMBOL(atomic64_dec_if_positive);
12028
12029 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
12030 index 30c3ecc..736f015 100644
12031 --- a/arch/sparc/mm/Makefile
12032 +++ b/arch/sparc/mm/Makefile
12033 @@ -2,7 +2,7 @@
12034 #
12035
12036 asflags-y := -ansi
12037 -ccflags-y := -Werror
12038 +#ccflags-y := -Werror
12039
12040 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
12041 obj-y += fault_$(BITS).o
12042 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
12043 index 908e8c1..1524793 100644
12044 --- a/arch/sparc/mm/fault_32.c
12045 +++ b/arch/sparc/mm/fault_32.c
12046 @@ -21,6 +21,9 @@
12047 #include <linux/perf_event.h>
12048 #include <linux/interrupt.h>
12049 #include <linux/kdebug.h>
12050 +#include <linux/slab.h>
12051 +#include <linux/pagemap.h>
12052 +#include <linux/compiler.h>
12053
12054 #include <asm/page.h>
12055 #include <asm/pgtable.h>
12056 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
12057 return safe_compute_effective_address(regs, insn);
12058 }
12059
12060 +#ifdef CONFIG_PAX_PAGEEXEC
12061 +#ifdef CONFIG_PAX_DLRESOLVE
12062 +static void pax_emuplt_close(struct vm_area_struct *vma)
12063 +{
12064 + vma->vm_mm->call_dl_resolve = 0UL;
12065 +}
12066 +
12067 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12068 +{
12069 + unsigned int *kaddr;
12070 +
12071 + vmf->page = alloc_page(GFP_HIGHUSER);
12072 + if (!vmf->page)
12073 + return VM_FAULT_OOM;
12074 +
12075 + kaddr = kmap(vmf->page);
12076 + memset(kaddr, 0, PAGE_SIZE);
12077 + kaddr[0] = 0x9DE3BFA8U; /* save */
12078 + flush_dcache_page(vmf->page);
12079 + kunmap(vmf->page);
12080 + return VM_FAULT_MAJOR;
12081 +}
12082 +
12083 +static const struct vm_operations_struct pax_vm_ops = {
12084 + .close = pax_emuplt_close,
12085 + .fault = pax_emuplt_fault
12086 +};
12087 +
12088 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12089 +{
12090 + int ret;
12091 +
12092 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12093 + vma->vm_mm = current->mm;
12094 + vma->vm_start = addr;
12095 + vma->vm_end = addr + PAGE_SIZE;
12096 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12097 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12098 + vma->vm_ops = &pax_vm_ops;
12099 +
12100 + ret = insert_vm_struct(current->mm, vma);
12101 + if (ret)
12102 + return ret;
12103 +
12104 + ++current->mm->total_vm;
12105 + return 0;
12106 +}
12107 +#endif
12108 +
12109 +/*
12110 + * PaX: decide what to do with offenders (regs->pc = fault address)
12111 + *
12112 + * returns 1 when task should be killed
12113 + * 2 when patched PLT trampoline was detected
12114 + * 3 when unpatched PLT trampoline was detected
12115 + */
12116 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12117 +{
12118 +
12119 +#ifdef CONFIG_PAX_EMUPLT
12120 + int err;
12121 +
12122 + do { /* PaX: patched PLT emulation #1 */
12123 + unsigned int sethi1, sethi2, jmpl;
12124 +
12125 + err = get_user(sethi1, (unsigned int *)regs->pc);
12126 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
12127 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
12128 +
12129 + if (err)
12130 + break;
12131 +
12132 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12133 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12134 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12135 + {
12136 + unsigned int addr;
12137 +
12138 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12139 + addr = regs->u_regs[UREG_G1];
12140 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12141 + regs->pc = addr;
12142 + regs->npc = addr+4;
12143 + return 2;
12144 + }
12145 + } while (0);
12146 +
12147 + do { /* PaX: patched PLT emulation #2 */
12148 + unsigned int ba;
12149 +
12150 + err = get_user(ba, (unsigned int *)regs->pc);
12151 +
12152 + if (err)
12153 + break;
12154 +
12155 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12156 + unsigned int addr;
12157 +
12158 + if ((ba & 0xFFC00000U) == 0x30800000U)
12159 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12160 + else
12161 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12162 + regs->pc = addr;
12163 + regs->npc = addr+4;
12164 + return 2;
12165 + }
12166 + } while (0);
12167 +
12168 + do { /* PaX: patched PLT emulation #3 */
12169 + unsigned int sethi, bajmpl, nop;
12170 +
12171 + err = get_user(sethi, (unsigned int *)regs->pc);
12172 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
12173 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12174 +
12175 + if (err)
12176 + break;
12177 +
12178 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12179 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12180 + nop == 0x01000000U)
12181 + {
12182 + unsigned int addr;
12183 +
12184 + addr = (sethi & 0x003FFFFFU) << 10;
12185 + regs->u_regs[UREG_G1] = addr;
12186 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12187 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12188 + else
12189 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12190 + regs->pc = addr;
12191 + regs->npc = addr+4;
12192 + return 2;
12193 + }
12194 + } while (0);
12195 +
12196 + do { /* PaX: unpatched PLT emulation step 1 */
12197 + unsigned int sethi, ba, nop;
12198 +
12199 + err = get_user(sethi, (unsigned int *)regs->pc);
12200 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
12201 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12202 +
12203 + if (err)
12204 + break;
12205 +
12206 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12207 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12208 + nop == 0x01000000U)
12209 + {
12210 + unsigned int addr, save, call;
12211 +
12212 + if ((ba & 0xFFC00000U) == 0x30800000U)
12213 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12214 + else
12215 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12216 +
12217 + err = get_user(save, (unsigned int *)addr);
12218 + err |= get_user(call, (unsigned int *)(addr+4));
12219 + err |= get_user(nop, (unsigned int *)(addr+8));
12220 + if (err)
12221 + break;
12222 +
12223 +#ifdef CONFIG_PAX_DLRESOLVE
12224 + if (save == 0x9DE3BFA8U &&
12225 + (call & 0xC0000000U) == 0x40000000U &&
12226 + nop == 0x01000000U)
12227 + {
12228 + struct vm_area_struct *vma;
12229 + unsigned long call_dl_resolve;
12230 +
12231 + down_read(&current->mm->mmap_sem);
12232 + call_dl_resolve = current->mm->call_dl_resolve;
12233 + up_read(&current->mm->mmap_sem);
12234 + if (likely(call_dl_resolve))
12235 + goto emulate;
12236 +
12237 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12238 +
12239 + down_write(&current->mm->mmap_sem);
12240 + if (current->mm->call_dl_resolve) {
12241 + call_dl_resolve = current->mm->call_dl_resolve;
12242 + up_write(&current->mm->mmap_sem);
12243 + if (vma)
12244 + kmem_cache_free(vm_area_cachep, vma);
12245 + goto emulate;
12246 + }
12247 +
12248 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12249 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12250 + up_write(&current->mm->mmap_sem);
12251 + if (vma)
12252 + kmem_cache_free(vm_area_cachep, vma);
12253 + return 1;
12254 + }
12255 +
12256 + if (pax_insert_vma(vma, call_dl_resolve)) {
12257 + up_write(&current->mm->mmap_sem);
12258 + kmem_cache_free(vm_area_cachep, vma);
12259 + return 1;
12260 + }
12261 +
12262 + current->mm->call_dl_resolve = call_dl_resolve;
12263 + up_write(&current->mm->mmap_sem);
12264 +
12265 +emulate:
12266 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12267 + regs->pc = call_dl_resolve;
12268 + regs->npc = addr+4;
12269 + return 3;
12270 + }
12271 +#endif
12272 +
12273 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12274 + if ((save & 0xFFC00000U) == 0x05000000U &&
12275 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12276 + nop == 0x01000000U)
12277 + {
12278 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12279 + regs->u_regs[UREG_G2] = addr + 4;
12280 + addr = (save & 0x003FFFFFU) << 10;
12281 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12282 + regs->pc = addr;
12283 + regs->npc = addr+4;
12284 + return 3;
12285 + }
12286 + }
12287 + } while (0);
12288 +
12289 + do { /* PaX: unpatched PLT emulation step 2 */
12290 + unsigned int save, call, nop;
12291 +
12292 + err = get_user(save, (unsigned int *)(regs->pc-4));
12293 + err |= get_user(call, (unsigned int *)regs->pc);
12294 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
12295 + if (err)
12296 + break;
12297 +
12298 + if (save == 0x9DE3BFA8U &&
12299 + (call & 0xC0000000U) == 0x40000000U &&
12300 + nop == 0x01000000U)
12301 + {
12302 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
12303 +
12304 + regs->u_regs[UREG_RETPC] = regs->pc;
12305 + regs->pc = dl_resolve;
12306 + regs->npc = dl_resolve+4;
12307 + return 3;
12308 + }
12309 + } while (0);
12310 +#endif
12311 +
12312 + return 1;
12313 +}
12314 +
12315 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12316 +{
12317 + unsigned long i;
12318 +
12319 + printk(KERN_ERR "PAX: bytes at PC: ");
12320 + for (i = 0; i < 8; i++) {
12321 + unsigned int c;
12322 + if (get_user(c, (unsigned int *)pc+i))
12323 + printk(KERN_CONT "???????? ");
12324 + else
12325 + printk(KERN_CONT "%08x ", c);
12326 + }
12327 + printk("\n");
12328 +}
12329 +#endif
12330 +
12331 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
12332 int text_fault)
12333 {
12334 @@ -226,6 +500,24 @@ good_area:
12335 if (!(vma->vm_flags & VM_WRITE))
12336 goto bad_area;
12337 } else {
12338 +
12339 +#ifdef CONFIG_PAX_PAGEEXEC
12340 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
12341 + up_read(&mm->mmap_sem);
12342 + switch (pax_handle_fetch_fault(regs)) {
12343 +
12344 +#ifdef CONFIG_PAX_EMUPLT
12345 + case 2:
12346 + case 3:
12347 + return;
12348 +#endif
12349 +
12350 + }
12351 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
12352 + do_group_exit(SIGKILL);
12353 + }
12354 +#endif
12355 +
12356 /* Allow reads even for write-only mappings */
12357 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
12358 goto bad_area;
12359 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
12360 index 18fcd71..e4fe821 100644
12361 --- a/arch/sparc/mm/fault_64.c
12362 +++ b/arch/sparc/mm/fault_64.c
12363 @@ -22,6 +22,9 @@
12364 #include <linux/kdebug.h>
12365 #include <linux/percpu.h>
12366 #include <linux/context_tracking.h>
12367 +#include <linux/slab.h>
12368 +#include <linux/pagemap.h>
12369 +#include <linux/compiler.h>
12370
12371 #include <asm/page.h>
12372 #include <asm/pgtable.h>
12373 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
12374 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
12375 regs->tpc);
12376 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
12377 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
12378 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
12379 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
12380 dump_stack();
12381 unhandled_fault(regs->tpc, current, regs);
12382 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
12383 show_regs(regs);
12384 }
12385
12386 +#ifdef CONFIG_PAX_PAGEEXEC
12387 +#ifdef CONFIG_PAX_DLRESOLVE
12388 +static void pax_emuplt_close(struct vm_area_struct *vma)
12389 +{
12390 + vma->vm_mm->call_dl_resolve = 0UL;
12391 +}
12392 +
12393 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12394 +{
12395 + unsigned int *kaddr;
12396 +
12397 + vmf->page = alloc_page(GFP_HIGHUSER);
12398 + if (!vmf->page)
12399 + return VM_FAULT_OOM;
12400 +
12401 + kaddr = kmap(vmf->page);
12402 + memset(kaddr, 0, PAGE_SIZE);
12403 + kaddr[0] = 0x9DE3BFA8U; /* save */
12404 + flush_dcache_page(vmf->page);
12405 + kunmap(vmf->page);
12406 + return VM_FAULT_MAJOR;
12407 +}
12408 +
12409 +static const struct vm_operations_struct pax_vm_ops = {
12410 + .close = pax_emuplt_close,
12411 + .fault = pax_emuplt_fault
12412 +};
12413 +
12414 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12415 +{
12416 + int ret;
12417 +
12418 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12419 + vma->vm_mm = current->mm;
12420 + vma->vm_start = addr;
12421 + vma->vm_end = addr + PAGE_SIZE;
12422 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12423 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12424 + vma->vm_ops = &pax_vm_ops;
12425 +
12426 + ret = insert_vm_struct(current->mm, vma);
12427 + if (ret)
12428 + return ret;
12429 +
12430 + ++current->mm->total_vm;
12431 + return 0;
12432 +}
12433 +#endif
12434 +
12435 +/*
12436 + * PaX: decide what to do with offenders (regs->tpc = fault address)
12437 + *
12438 + * returns 1 when task should be killed
12439 + * 2 when patched PLT trampoline was detected
12440 + * 3 when unpatched PLT trampoline was detected
12441 + */
12442 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12443 +{
12444 +
12445 +#ifdef CONFIG_PAX_EMUPLT
12446 + int err;
12447 +
12448 + do { /* PaX: patched PLT emulation #1 */
12449 + unsigned int sethi1, sethi2, jmpl;
12450 +
12451 + err = get_user(sethi1, (unsigned int *)regs->tpc);
12452 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12453 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12454 +
12455 + if (err)
12456 + break;
12457 +
12458 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12459 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12460 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12461 + {
12462 + unsigned long addr;
12463 +
12464 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12465 + addr = regs->u_regs[UREG_G1];
12466 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12467 +
12468 + if (test_thread_flag(TIF_32BIT))
12469 + addr &= 0xFFFFFFFFUL;
12470 +
12471 + regs->tpc = addr;
12472 + regs->tnpc = addr+4;
12473 + return 2;
12474 + }
12475 + } while (0);
12476 +
12477 + do { /* PaX: patched PLT emulation #2 */
12478 + unsigned int ba;
12479 +
12480 + err = get_user(ba, (unsigned int *)regs->tpc);
12481 +
12482 + if (err)
12483 + break;
12484 +
12485 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12486 + unsigned long addr;
12487 +
12488 + if ((ba & 0xFFC00000U) == 0x30800000U)
12489 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12490 + else
12491 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12492 +
12493 + if (test_thread_flag(TIF_32BIT))
12494 + addr &= 0xFFFFFFFFUL;
12495 +
12496 + regs->tpc = addr;
12497 + regs->tnpc = addr+4;
12498 + return 2;
12499 + }
12500 + } while (0);
12501 +
12502 + do { /* PaX: patched PLT emulation #3 */
12503 + unsigned int sethi, bajmpl, nop;
12504 +
12505 + err = get_user(sethi, (unsigned int *)regs->tpc);
12506 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12507 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12508 +
12509 + if (err)
12510 + break;
12511 +
12512 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12513 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12514 + nop == 0x01000000U)
12515 + {
12516 + unsigned long addr;
12517 +
12518 + addr = (sethi & 0x003FFFFFU) << 10;
12519 + regs->u_regs[UREG_G1] = addr;
12520 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12521 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12522 + else
12523 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12524 +
12525 + if (test_thread_flag(TIF_32BIT))
12526 + addr &= 0xFFFFFFFFUL;
12527 +
12528 + regs->tpc = addr;
12529 + regs->tnpc = addr+4;
12530 + return 2;
12531 + }
12532 + } while (0);
12533 +
12534 + do { /* PaX: patched PLT emulation #4 */
12535 + unsigned int sethi, mov1, call, mov2;
12536 +
12537 + err = get_user(sethi, (unsigned int *)regs->tpc);
12538 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12539 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12540 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12541 +
12542 + if (err)
12543 + break;
12544 +
12545 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12546 + mov1 == 0x8210000FU &&
12547 + (call & 0xC0000000U) == 0x40000000U &&
12548 + mov2 == 0x9E100001U)
12549 + {
12550 + unsigned long addr;
12551 +
12552 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12553 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12554 +
12555 + if (test_thread_flag(TIF_32BIT))
12556 + addr &= 0xFFFFFFFFUL;
12557 +
12558 + regs->tpc = addr;
12559 + regs->tnpc = addr+4;
12560 + return 2;
12561 + }
12562 + } while (0);
12563 +
12564 + do { /* PaX: patched PLT emulation #5 */
12565 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12566 +
12567 + err = get_user(sethi, (unsigned int *)regs->tpc);
12568 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12569 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12570 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12571 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12572 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12573 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12574 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12575 +
12576 + if (err)
12577 + break;
12578 +
12579 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12580 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12581 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12582 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12583 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12584 + sllx == 0x83287020U &&
12585 + jmpl == 0x81C04005U &&
12586 + nop == 0x01000000U)
12587 + {
12588 + unsigned long addr;
12589 +
12590 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12591 + regs->u_regs[UREG_G1] <<= 32;
12592 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12593 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12594 + regs->tpc = addr;
12595 + regs->tnpc = addr+4;
12596 + return 2;
12597 + }
12598 + } while (0);
12599 +
12600 + do { /* PaX: patched PLT emulation #6 */
12601 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12602 +
12603 + err = get_user(sethi, (unsigned int *)regs->tpc);
12604 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12605 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12606 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12607 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12608 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12609 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12610 +
12611 + if (err)
12612 + break;
12613 +
12614 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12615 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12616 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12617 + sllx == 0x83287020U &&
12618 + (or & 0xFFFFE000U) == 0x8A116000U &&
12619 + jmpl == 0x81C04005U &&
12620 + nop == 0x01000000U)
12621 + {
12622 + unsigned long addr;
12623 +
12624 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12625 + regs->u_regs[UREG_G1] <<= 32;
12626 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12627 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12628 + regs->tpc = addr;
12629 + regs->tnpc = addr+4;
12630 + return 2;
12631 + }
12632 + } while (0);
12633 +
12634 + do { /* PaX: unpatched PLT emulation step 1 */
12635 + unsigned int sethi, ba, nop;
12636 +
12637 + err = get_user(sethi, (unsigned int *)regs->tpc);
12638 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12639 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12640 +
12641 + if (err)
12642 + break;
12643 +
12644 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12645 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12646 + nop == 0x01000000U)
12647 + {
12648 + unsigned long addr;
12649 + unsigned int save, call;
12650 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12651 +
12652 + if ((ba & 0xFFC00000U) == 0x30800000U)
12653 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12654 + else
12655 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12656 +
12657 + if (test_thread_flag(TIF_32BIT))
12658 + addr &= 0xFFFFFFFFUL;
12659 +
12660 + err = get_user(save, (unsigned int *)addr);
12661 + err |= get_user(call, (unsigned int *)(addr+4));
12662 + err |= get_user(nop, (unsigned int *)(addr+8));
12663 + if (err)
12664 + break;
12665 +
12666 +#ifdef CONFIG_PAX_DLRESOLVE
12667 + if (save == 0x9DE3BFA8U &&
12668 + (call & 0xC0000000U) == 0x40000000U &&
12669 + nop == 0x01000000U)
12670 + {
12671 + struct vm_area_struct *vma;
12672 + unsigned long call_dl_resolve;
12673 +
12674 + down_read(&current->mm->mmap_sem);
12675 + call_dl_resolve = current->mm->call_dl_resolve;
12676 + up_read(&current->mm->mmap_sem);
12677 + if (likely(call_dl_resolve))
12678 + goto emulate;
12679 +
12680 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12681 +
12682 + down_write(&current->mm->mmap_sem);
12683 + if (current->mm->call_dl_resolve) {
12684 + call_dl_resolve = current->mm->call_dl_resolve;
12685 + up_write(&current->mm->mmap_sem);
12686 + if (vma)
12687 + kmem_cache_free(vm_area_cachep, vma);
12688 + goto emulate;
12689 + }
12690 +
12691 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12692 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12693 + up_write(&current->mm->mmap_sem);
12694 + if (vma)
12695 + kmem_cache_free(vm_area_cachep, vma);
12696 + return 1;
12697 + }
12698 +
12699 + if (pax_insert_vma(vma, call_dl_resolve)) {
12700 + up_write(&current->mm->mmap_sem);
12701 + kmem_cache_free(vm_area_cachep, vma);
12702 + return 1;
12703 + }
12704 +
12705 + current->mm->call_dl_resolve = call_dl_resolve;
12706 + up_write(&current->mm->mmap_sem);
12707 +
12708 +emulate:
12709 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12710 + regs->tpc = call_dl_resolve;
12711 + regs->tnpc = addr+4;
12712 + return 3;
12713 + }
12714 +#endif
12715 +
12716 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12717 + if ((save & 0xFFC00000U) == 0x05000000U &&
12718 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12719 + nop == 0x01000000U)
12720 + {
12721 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12722 + regs->u_regs[UREG_G2] = addr + 4;
12723 + addr = (save & 0x003FFFFFU) << 10;
12724 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12725 +
12726 + if (test_thread_flag(TIF_32BIT))
12727 + addr &= 0xFFFFFFFFUL;
12728 +
12729 + regs->tpc = addr;
12730 + regs->tnpc = addr+4;
12731 + return 3;
12732 + }
12733 +
12734 + /* PaX: 64-bit PLT stub */
12735 + err = get_user(sethi1, (unsigned int *)addr);
12736 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12737 + err |= get_user(or1, (unsigned int *)(addr+8));
12738 + err |= get_user(or2, (unsigned int *)(addr+12));
12739 + err |= get_user(sllx, (unsigned int *)(addr+16));
12740 + err |= get_user(add, (unsigned int *)(addr+20));
12741 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12742 + err |= get_user(nop, (unsigned int *)(addr+28));
12743 + if (err)
12744 + break;
12745 +
12746 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12747 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12748 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12749 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12750 + sllx == 0x89293020U &&
12751 + add == 0x8A010005U &&
12752 + jmpl == 0x89C14000U &&
12753 + nop == 0x01000000U)
12754 + {
12755 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12756 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12757 + regs->u_regs[UREG_G4] <<= 32;
12758 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12759 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12760 + regs->u_regs[UREG_G4] = addr + 24;
12761 + addr = regs->u_regs[UREG_G5];
12762 + regs->tpc = addr;
12763 + regs->tnpc = addr+4;
12764 + return 3;
12765 + }
12766 + }
12767 + } while (0);
12768 +
12769 +#ifdef CONFIG_PAX_DLRESOLVE
12770 + do { /* PaX: unpatched PLT emulation step 2 */
12771 + unsigned int save, call, nop;
12772 +
12773 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12774 + err |= get_user(call, (unsigned int *)regs->tpc);
12775 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12776 + if (err)
12777 + break;
12778 +
12779 + if (save == 0x9DE3BFA8U &&
12780 + (call & 0xC0000000U) == 0x40000000U &&
12781 + nop == 0x01000000U)
12782 + {
12783 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12784 +
12785 + if (test_thread_flag(TIF_32BIT))
12786 + dl_resolve &= 0xFFFFFFFFUL;
12787 +
12788 + regs->u_regs[UREG_RETPC] = regs->tpc;
12789 + regs->tpc = dl_resolve;
12790 + regs->tnpc = dl_resolve+4;
12791 + return 3;
12792 + }
12793 + } while (0);
12794 +#endif
12795 +
12796 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12797 + unsigned int sethi, ba, nop;
12798 +
12799 + err = get_user(sethi, (unsigned int *)regs->tpc);
12800 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12801 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12802 +
12803 + if (err)
12804 + break;
12805 +
12806 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12807 + (ba & 0xFFF00000U) == 0x30600000U &&
12808 + nop == 0x01000000U)
12809 + {
12810 + unsigned long addr;
12811 +
12812 + addr = (sethi & 0x003FFFFFU) << 10;
12813 + regs->u_regs[UREG_G1] = addr;
12814 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12815 +
12816 + if (test_thread_flag(TIF_32BIT))
12817 + addr &= 0xFFFFFFFFUL;
12818 +
12819 + regs->tpc = addr;
12820 + regs->tnpc = addr+4;
12821 + return 2;
12822 + }
12823 + } while (0);
12824 +
12825 +#endif
12826 +
12827 + return 1;
12828 +}
12829 +
12830 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12831 +{
12832 + unsigned long i;
12833 +
12834 + printk(KERN_ERR "PAX: bytes at PC: ");
12835 + for (i = 0; i < 8; i++) {
12836 + unsigned int c;
12837 + if (get_user(c, (unsigned int *)pc+i))
12838 + printk(KERN_CONT "???????? ");
12839 + else
12840 + printk(KERN_CONT "%08x ", c);
12841 + }
12842 + printk("\n");
12843 +}
12844 +#endif
12845 +
12846 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12847 {
12848 enum ctx_state prev_state = exception_enter();
12849 @@ -353,6 +816,29 @@ retry:
12850 if (!vma)
12851 goto bad_area;
12852
12853 +#ifdef CONFIG_PAX_PAGEEXEC
12854 + /* PaX: detect ITLB misses on non-exec pages */
12855 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12856 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12857 + {
12858 + if (address != regs->tpc)
12859 + goto good_area;
12860 +
12861 + up_read(&mm->mmap_sem);
12862 + switch (pax_handle_fetch_fault(regs)) {
12863 +
12864 +#ifdef CONFIG_PAX_EMUPLT
12865 + case 2:
12866 + case 3:
12867 + return;
12868 +#endif
12869 +
12870 + }
12871 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12872 + do_group_exit(SIGKILL);
12873 + }
12874 +#endif
12875 +
12876 /* Pure DTLB misses do not tell us whether the fault causing
12877 * load/store/atomic was a write or not, it only says that there
12878 * was no match. So in such a case we (carefully) read the
12879 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12880 index d329537..2c3746a 100644
12881 --- a/arch/sparc/mm/hugetlbpage.c
12882 +++ b/arch/sparc/mm/hugetlbpage.c
12883 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12884 unsigned long addr,
12885 unsigned long len,
12886 unsigned long pgoff,
12887 - unsigned long flags)
12888 + unsigned long flags,
12889 + unsigned long offset)
12890 {
12891 + struct mm_struct *mm = current->mm;
12892 unsigned long task_size = TASK_SIZE;
12893 struct vm_unmapped_area_info info;
12894
12895 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12896
12897 info.flags = 0;
12898 info.length = len;
12899 - info.low_limit = TASK_UNMAPPED_BASE;
12900 + info.low_limit = mm->mmap_base;
12901 info.high_limit = min(task_size, VA_EXCLUDE_START);
12902 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12903 info.align_offset = 0;
12904 + info.threadstack_offset = offset;
12905 addr = vm_unmapped_area(&info);
12906
12907 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12908 VM_BUG_ON(addr != -ENOMEM);
12909 info.low_limit = VA_EXCLUDE_END;
12910 +
12911 +#ifdef CONFIG_PAX_RANDMMAP
12912 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12913 + info.low_limit += mm->delta_mmap;
12914 +#endif
12915 +
12916 info.high_limit = task_size;
12917 addr = vm_unmapped_area(&info);
12918 }
12919 @@ -55,7 +64,8 @@ static unsigned long
12920 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12921 const unsigned long len,
12922 const unsigned long pgoff,
12923 - const unsigned long flags)
12924 + const unsigned long flags,
12925 + const unsigned long offset)
12926 {
12927 struct mm_struct *mm = current->mm;
12928 unsigned long addr = addr0;
12929 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12930 info.high_limit = mm->mmap_base;
12931 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12932 info.align_offset = 0;
12933 + info.threadstack_offset = offset;
12934 addr = vm_unmapped_area(&info);
12935
12936 /*
12937 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12938 VM_BUG_ON(addr != -ENOMEM);
12939 info.flags = 0;
12940 info.low_limit = TASK_UNMAPPED_BASE;
12941 +
12942 +#ifdef CONFIG_PAX_RANDMMAP
12943 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12944 + info.low_limit += mm->delta_mmap;
12945 +#endif
12946 +
12947 info.high_limit = STACK_TOP32;
12948 addr = vm_unmapped_area(&info);
12949 }
12950 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12951 struct mm_struct *mm = current->mm;
12952 struct vm_area_struct *vma;
12953 unsigned long task_size = TASK_SIZE;
12954 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12955
12956 if (test_thread_flag(TIF_32BIT))
12957 task_size = STACK_TOP32;
12958 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12959 return addr;
12960 }
12961
12962 +#ifdef CONFIG_PAX_RANDMMAP
12963 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12964 +#endif
12965 +
12966 if (addr) {
12967 addr = ALIGN(addr, HPAGE_SIZE);
12968 vma = find_vma(mm, addr);
12969 - if (task_size - len >= addr &&
12970 - (!vma || addr + len <= vma->vm_start))
12971 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12972 return addr;
12973 }
12974 if (mm->get_unmapped_area == arch_get_unmapped_area)
12975 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12976 - pgoff, flags);
12977 + pgoff, flags, offset);
12978 else
12979 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12980 - pgoff, flags);
12981 + pgoff, flags, offset);
12982 }
12983
12984 pte_t *huge_pte_alloc(struct mm_struct *mm,
12985 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12986 index 04bc826..0fefab9 100644
12987 --- a/arch/sparc/mm/init_64.c
12988 +++ b/arch/sparc/mm/init_64.c
12989 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12990 int num_kernel_image_mappings;
12991
12992 #ifdef CONFIG_DEBUG_DCFLUSH
12993 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12994 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12995 #ifdef CONFIG_SMP
12996 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12997 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12998 #endif
12999 #endif
13000
13001 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
13002 {
13003 BUG_ON(tlb_type == hypervisor);
13004 #ifdef CONFIG_DEBUG_DCFLUSH
13005 - atomic_inc(&dcpage_flushes);
13006 + atomic_inc_unchecked(&dcpage_flushes);
13007 #endif
13008
13009 #ifdef DCACHE_ALIASING_POSSIBLE
13010 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
13011
13012 #ifdef CONFIG_DEBUG_DCFLUSH
13013 seq_printf(m, "DCPageFlushes\t: %d\n",
13014 - atomic_read(&dcpage_flushes));
13015 + atomic_read_unchecked(&dcpage_flushes));
13016 #ifdef CONFIG_SMP
13017 seq_printf(m, "DCPageFlushesXC\t: %d\n",
13018 - atomic_read(&dcpage_flushes_xcall));
13019 + atomic_read_unchecked(&dcpage_flushes_xcall));
13020 #endif /* CONFIG_SMP */
13021 #endif /* CONFIG_DEBUG_DCFLUSH */
13022 }
13023 diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
13024 index ece4af0..f04b862 100644
13025 --- a/arch/sparc/net/bpf_jit_comp.c
13026 +++ b/arch/sparc/net/bpf_jit_comp.c
13027 @@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
13028 {
13029 if (fp->jited)
13030 module_free(NULL, fp->bpf_func);
13031 - kfree(fp);
13032 +
13033 + bpf_prog_unlock_free(fp);
13034 }
13035 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
13036 index 7fcd492..1311074 100644
13037 --- a/arch/tile/Kconfig
13038 +++ b/arch/tile/Kconfig
13039 @@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
13040
13041 config KEXEC
13042 bool "kexec system call"
13043 + depends on !GRKERNSEC_KMEM
13044 ---help---
13045 kexec is a system call that implements the ability to shutdown your
13046 current kernel, and to start another kernel. It is like a reboot
13047 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
13048 index 7b11c5f..755a026 100644
13049 --- a/arch/tile/include/asm/atomic_64.h
13050 +++ b/arch/tile/include/asm/atomic_64.h
13051 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
13052
13053 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13054
13055 +#define atomic64_read_unchecked(v) atomic64_read(v)
13056 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
13057 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
13058 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
13059 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
13060 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
13061 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
13062 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
13063 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
13064 +
13065 /* Define this to indicate that cmpxchg is an efficient operation. */
13066 #define __HAVE_ARCH_CMPXCHG
13067
13068 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
13069 index 6160761..00cac88 100644
13070 --- a/arch/tile/include/asm/cache.h
13071 +++ b/arch/tile/include/asm/cache.h
13072 @@ -15,11 +15,12 @@
13073 #ifndef _ASM_TILE_CACHE_H
13074 #define _ASM_TILE_CACHE_H
13075
13076 +#include <linux/const.h>
13077 #include <arch/chip.h>
13078
13079 /* bytes per L1 data cache line */
13080 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
13081 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13082 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13083
13084 /* bytes per L2 cache line */
13085 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
13086 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
13087 index b6cde32..c0cb736 100644
13088 --- a/arch/tile/include/asm/uaccess.h
13089 +++ b/arch/tile/include/asm/uaccess.h
13090 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
13091 const void __user *from,
13092 unsigned long n)
13093 {
13094 - int sz = __compiletime_object_size(to);
13095 + size_t sz = __compiletime_object_size(to);
13096
13097 - if (likely(sz == -1 || sz >= n))
13098 + if (likely(sz == (size_t)-1 || sz >= n))
13099 n = _copy_from_user(to, from, n);
13100 else
13101 copy_from_user_overflow();
13102 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
13103 index e514899..f8743c4 100644
13104 --- a/arch/tile/mm/hugetlbpage.c
13105 +++ b/arch/tile/mm/hugetlbpage.c
13106 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
13107 info.high_limit = TASK_SIZE;
13108 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13109 info.align_offset = 0;
13110 + info.threadstack_offset = 0;
13111 return vm_unmapped_area(&info);
13112 }
13113
13114 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
13115 info.high_limit = current->mm->mmap_base;
13116 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13117 info.align_offset = 0;
13118 + info.threadstack_offset = 0;
13119 addr = vm_unmapped_area(&info);
13120
13121 /*
13122 diff --git a/arch/um/Makefile b/arch/um/Makefile
13123 index e4b1a96..16162f8 100644
13124 --- a/arch/um/Makefile
13125 +++ b/arch/um/Makefile
13126 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
13127 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
13128 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
13129
13130 +ifdef CONSTIFY_PLUGIN
13131 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13132 +endif
13133 +
13134 #This will adjust *FLAGS accordingly to the platform.
13135 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
13136
13137 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
13138 index 19e1bdd..3665b77 100644
13139 --- a/arch/um/include/asm/cache.h
13140 +++ b/arch/um/include/asm/cache.h
13141 @@ -1,6 +1,7 @@
13142 #ifndef __UM_CACHE_H
13143 #define __UM_CACHE_H
13144
13145 +#include <linux/const.h>
13146
13147 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
13148 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13149 @@ -12,6 +13,6 @@
13150 # define L1_CACHE_SHIFT 5
13151 #endif
13152
13153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13154 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13155
13156 #endif
13157 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
13158 index 2e0a6b1..a64d0f5 100644
13159 --- a/arch/um/include/asm/kmap_types.h
13160 +++ b/arch/um/include/asm/kmap_types.h
13161 @@ -8,6 +8,6 @@
13162
13163 /* No more #include "asm/arch/kmap_types.h" ! */
13164
13165 -#define KM_TYPE_NR 14
13166 +#define KM_TYPE_NR 15
13167
13168 #endif
13169 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
13170 index 71c5d13..4c7b9f1 100644
13171 --- a/arch/um/include/asm/page.h
13172 +++ b/arch/um/include/asm/page.h
13173 @@ -14,6 +14,9 @@
13174 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
13175 #define PAGE_MASK (~(PAGE_SIZE-1))
13176
13177 +#define ktla_ktva(addr) (addr)
13178 +#define ktva_ktla(addr) (addr)
13179 +
13180 #ifndef __ASSEMBLY__
13181
13182 struct page;
13183 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
13184 index 0032f92..cd151e0 100644
13185 --- a/arch/um/include/asm/pgtable-3level.h
13186 +++ b/arch/um/include/asm/pgtable-3level.h
13187 @@ -58,6 +58,7 @@
13188 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
13189 #define pud_populate(mm, pud, pmd) \
13190 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
13191 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
13192
13193 #ifdef CONFIG_64BIT
13194 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
13195 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
13196 index f17bca8..48adb87 100644
13197 --- a/arch/um/kernel/process.c
13198 +++ b/arch/um/kernel/process.c
13199 @@ -356,22 +356,6 @@ int singlestepping(void * t)
13200 return 2;
13201 }
13202
13203 -/*
13204 - * Only x86 and x86_64 have an arch_align_stack().
13205 - * All other arches have "#define arch_align_stack(x) (x)"
13206 - * in their asm/exec.h
13207 - * As this is included in UML from asm-um/system-generic.h,
13208 - * we can use it to behave as the subarch does.
13209 - */
13210 -#ifndef arch_align_stack
13211 -unsigned long arch_align_stack(unsigned long sp)
13212 -{
13213 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13214 - sp -= get_random_int() % 8192;
13215 - return sp & ~0xf;
13216 -}
13217 -#endif
13218 -
13219 unsigned long get_wchan(struct task_struct *p)
13220 {
13221 unsigned long stack_page, sp, ip;
13222 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
13223 index ad8f795..2c7eec6 100644
13224 --- a/arch/unicore32/include/asm/cache.h
13225 +++ b/arch/unicore32/include/asm/cache.h
13226 @@ -12,8 +12,10 @@
13227 #ifndef __UNICORE_CACHE_H__
13228 #define __UNICORE_CACHE_H__
13229
13230 -#define L1_CACHE_SHIFT (5)
13231 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13232 +#include <linux/const.h>
13233 +
13234 +#define L1_CACHE_SHIFT 5
13235 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13236
13237 /*
13238 * Memory returned by kmalloc() may be used for DMA, so we must make
13239 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
13240 index 3632743..630a8bb 100644
13241 --- a/arch/x86/Kconfig
13242 +++ b/arch/x86/Kconfig
13243 @@ -130,7 +130,7 @@ config X86
13244 select RTC_LIB
13245 select HAVE_DEBUG_STACKOVERFLOW
13246 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
13247 - select HAVE_CC_STACKPROTECTOR
13248 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
13249 select GENERIC_CPU_AUTOPROBE
13250 select HAVE_ARCH_AUDITSYSCALL
13251 select ARCH_SUPPORTS_ATOMIC_RMW
13252 @@ -258,7 +258,7 @@ config X86_HT
13253
13254 config X86_32_LAZY_GS
13255 def_bool y
13256 - depends on X86_32 && !CC_STACKPROTECTOR
13257 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
13258
13259 config ARCH_HWEIGHT_CFLAGS
13260 string
13261 @@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
13262
13263 menuconfig HYPERVISOR_GUEST
13264 bool "Linux guest support"
13265 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
13266 ---help---
13267 Say Y here to enable options for running Linux under various hyper-
13268 visors. This option enables basic hypervisor detection and platform
13269 @@ -1083,6 +1084,7 @@ choice
13270
13271 config NOHIGHMEM
13272 bool "off"
13273 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13274 ---help---
13275 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
13276 However, the address space of 32-bit x86 processors is only 4
13277 @@ -1119,6 +1121,7 @@ config NOHIGHMEM
13278
13279 config HIGHMEM4G
13280 bool "4GB"
13281 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13282 ---help---
13283 Select this if you have a 32-bit processor and between 1 and 4
13284 gigabytes of physical RAM.
13285 @@ -1171,7 +1174,7 @@ config PAGE_OFFSET
13286 hex
13287 default 0xB0000000 if VMSPLIT_3G_OPT
13288 default 0x80000000 if VMSPLIT_2G
13289 - default 0x78000000 if VMSPLIT_2G_OPT
13290 + default 0x70000000 if VMSPLIT_2G_OPT
13291 default 0x40000000 if VMSPLIT_1G
13292 default 0xC0000000
13293 depends on X86_32
13294 @@ -1586,6 +1589,7 @@ source kernel/Kconfig.hz
13295
13296 config KEXEC
13297 bool "kexec system call"
13298 + depends on !GRKERNSEC_KMEM
13299 ---help---
13300 kexec is a system call that implements the ability to shutdown your
13301 current kernel, and to start another kernel. It is like a reboot
13302 @@ -1771,7 +1775,9 @@ config X86_NEED_RELOCS
13303
13304 config PHYSICAL_ALIGN
13305 hex "Alignment value to which kernel should be aligned"
13306 - default "0x200000"
13307 + default "0x1000000"
13308 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
13309 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
13310 range 0x2000 0x1000000 if X86_32
13311 range 0x200000 0x1000000 if X86_64
13312 ---help---
13313 @@ -1854,6 +1860,7 @@ config COMPAT_VDSO
13314 def_bool n
13315 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
13316 depends on X86_32 || IA32_EMULATION
13317 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
13318 ---help---
13319 Certain buggy versions of glibc will crash if they are
13320 presented with a 32-bit vDSO that is not mapped at the address
13321 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
13322 index 6983314..54ad7e8 100644
13323 --- a/arch/x86/Kconfig.cpu
13324 +++ b/arch/x86/Kconfig.cpu
13325 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
13326
13327 config X86_F00F_BUG
13328 def_bool y
13329 - depends on M586MMX || M586TSC || M586 || M486
13330 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
13331
13332 config X86_INVD_BUG
13333 def_bool y
13334 @@ -327,7 +327,7 @@ config X86_INVD_BUG
13335
13336 config X86_ALIGNMENT_16
13337 def_bool y
13338 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13339 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13340
13341 config X86_INTEL_USERCOPY
13342 def_bool y
13343 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
13344 # generates cmov.
13345 config X86_CMOV
13346 def_bool y
13347 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13348 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13349
13350 config X86_MINIMUM_CPU_FAMILY
13351 int
13352 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
13353 index 61bd2ad..50b625d 100644
13354 --- a/arch/x86/Kconfig.debug
13355 +++ b/arch/x86/Kconfig.debug
13356 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
13357 config DEBUG_RODATA
13358 bool "Write protect kernel read-only data structures"
13359 default y
13360 - depends on DEBUG_KERNEL
13361 + depends on DEBUG_KERNEL && BROKEN
13362 ---help---
13363 Mark the kernel read-only data as write-protected in the pagetables,
13364 in order to catch accidental (and incorrect) writes to such const
13365 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
13366
13367 config DEBUG_SET_MODULE_RONX
13368 bool "Set loadable kernel module data as NX and text as RO"
13369 - depends on MODULES
13370 + depends on MODULES && BROKEN
13371 ---help---
13372 This option helps catch unintended modifications to loadable
13373 kernel module's text and read-only data. It also prevents execution
13374 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
13375 index 60087ca..9d9500e 100644
13376 --- a/arch/x86/Makefile
13377 +++ b/arch/x86/Makefile
13378 @@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
13379 # CPU-specific tuning. Anything which can be shared with UML should go here.
13380 include $(srctree)/arch/x86/Makefile_32.cpu
13381 KBUILD_CFLAGS += $(cflags-y)
13382 -
13383 - # temporary until string.h is fixed
13384 - KBUILD_CFLAGS += -ffreestanding
13385 else
13386 BITS := 64
13387 UTS_MACHINE := x86_64
13388 @@ -111,6 +108,9 @@ else
13389 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
13390 endif
13391
13392 +# temporary until string.h is fixed
13393 +KBUILD_CFLAGS += -ffreestanding
13394 +
13395 # Make sure compiler does not have buggy stack-protector support.
13396 ifdef CONFIG_CC_STACKPROTECTOR
13397 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
13398 @@ -184,6 +184,7 @@ archheaders:
13399 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
13400
13401 archprepare:
13402 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
13403 ifeq ($(CONFIG_KEXEC_FILE),y)
13404 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
13405 endif
13406 @@ -274,3 +275,9 @@ define archhelp
13407 echo ' FDINITRD=file initrd for the booted kernel'
13408 echo ' kvmconfig - Enable additional options for guest kernel support'
13409 endef
13410 +
13411 +define OLD_LD
13412 +
13413 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
13414 +*** Please upgrade your binutils to 2.18 or newer
13415 +endef
13416 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
13417 index dbe8dd2..2f0a98f 100644
13418 --- a/arch/x86/boot/Makefile
13419 +++ b/arch/x86/boot/Makefile
13420 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
13421 # ---------------------------------------------------------------------------
13422
13423 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
13424 +ifdef CONSTIFY_PLUGIN
13425 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13426 +endif
13427 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13428 GCOV_PROFILE := n
13429
13430 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
13431 index 878e4b9..20537ab 100644
13432 --- a/arch/x86/boot/bitops.h
13433 +++ b/arch/x86/boot/bitops.h
13434 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13435 u8 v;
13436 const u32 *p = (const u32 *)addr;
13437
13438 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13439 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13440 return v;
13441 }
13442
13443 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13444
13445 static inline void set_bit(int nr, void *addr)
13446 {
13447 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13448 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13449 }
13450
13451 #endif /* BOOT_BITOPS_H */
13452 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
13453 index bd49ec6..94c7f58 100644
13454 --- a/arch/x86/boot/boot.h
13455 +++ b/arch/x86/boot/boot.h
13456 @@ -84,7 +84,7 @@ static inline void io_delay(void)
13457 static inline u16 ds(void)
13458 {
13459 u16 seg;
13460 - asm("movw %%ds,%0" : "=rm" (seg));
13461 + asm volatile("movw %%ds,%0" : "=rm" (seg));
13462 return seg;
13463 }
13464
13465 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13466 index 14fe7cb..829b962 100644
13467 --- a/arch/x86/boot/compressed/Makefile
13468 +++ b/arch/x86/boot/compressed/Makefile
13469 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13470 KBUILD_CFLAGS += -mno-mmx -mno-sse
13471 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13472 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13473 +ifdef CONSTIFY_PLUGIN
13474 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13475 +endif
13476
13477 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13478 GCOV_PROFILE := n
13479 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13480 index a53440e..c3dbf1e 100644
13481 --- a/arch/x86/boot/compressed/efi_stub_32.S
13482 +++ b/arch/x86/boot/compressed/efi_stub_32.S
13483 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13484 * parameter 2, ..., param n. To make things easy, we save the return
13485 * address of efi_call_phys in a global variable.
13486 */
13487 - popl %ecx
13488 - movl %ecx, saved_return_addr(%edx)
13489 - /* get the function pointer into ECX*/
13490 - popl %ecx
13491 - movl %ecx, efi_rt_function_ptr(%edx)
13492 + popl saved_return_addr(%edx)
13493 + popl efi_rt_function_ptr(%edx)
13494
13495 /*
13496 * 3. Call the physical function.
13497 */
13498 - call *%ecx
13499 + call *efi_rt_function_ptr(%edx)
13500
13501 /*
13502 * 4. Balance the stack. And because EAX contain the return value,
13503 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13504 1: popl %edx
13505 subl $1b, %edx
13506
13507 - movl efi_rt_function_ptr(%edx), %ecx
13508 - pushl %ecx
13509 + pushl efi_rt_function_ptr(%edx)
13510
13511 /*
13512 * 10. Push the saved return address onto the stack and return.
13513 */
13514 - movl saved_return_addr(%edx), %ecx
13515 - pushl %ecx
13516 - ret
13517 + jmpl *saved_return_addr(%edx)
13518 ENDPROC(efi_call_phys)
13519 .previous
13520
13521 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13522 index 1d7fbbc..36ecd58 100644
13523 --- a/arch/x86/boot/compressed/head_32.S
13524 +++ b/arch/x86/boot/compressed/head_32.S
13525 @@ -140,10 +140,10 @@ preferred_addr:
13526 addl %eax, %ebx
13527 notl %eax
13528 andl %eax, %ebx
13529 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13530 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13531 jge 1f
13532 #endif
13533 - movl $LOAD_PHYSICAL_ADDR, %ebx
13534 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13535 1:
13536
13537 /* Target address to relocate to for decompression */
13538 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13539 index 6b1766c..ad465c9 100644
13540 --- a/arch/x86/boot/compressed/head_64.S
13541 +++ b/arch/x86/boot/compressed/head_64.S
13542 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13543 addl %eax, %ebx
13544 notl %eax
13545 andl %eax, %ebx
13546 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13547 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13548 jge 1f
13549 #endif
13550 - movl $LOAD_PHYSICAL_ADDR, %ebx
13551 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13552 1:
13553
13554 /* Target address to relocate to for decompression */
13555 @@ -322,10 +322,10 @@ preferred_addr:
13556 addq %rax, %rbp
13557 notq %rax
13558 andq %rax, %rbp
13559 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13560 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13561 jge 1f
13562 #endif
13563 - movq $LOAD_PHYSICAL_ADDR, %rbp
13564 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13565 1:
13566
13567 /* Target address to relocate to for decompression */
13568 @@ -434,8 +434,8 @@ gdt:
13569 .long gdt
13570 .word 0
13571 .quad 0x0000000000000000 /* NULL descriptor */
13572 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13573 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13574 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13575 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13576 .quad 0x0080890000000000 /* TS descriptor */
13577 .quad 0x0000000000000000 /* TS continued */
13578 gdt_end:
13579 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13580 index 30dd59a..cd9edc3 100644
13581 --- a/arch/x86/boot/compressed/misc.c
13582 +++ b/arch/x86/boot/compressed/misc.c
13583 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13584 * Calculate the delta between where vmlinux was linked to load
13585 * and where it was actually loaded.
13586 */
13587 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13588 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13589 if (!delta) {
13590 debug_putstr("No relocation needed... ");
13591 return;
13592 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13593 Elf32_Ehdr ehdr;
13594 Elf32_Phdr *phdrs, *phdr;
13595 #endif
13596 - void *dest;
13597 + void *dest, *prev;
13598 int i;
13599
13600 memcpy(&ehdr, output, sizeof(ehdr));
13601 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13602 case PT_LOAD:
13603 #ifdef CONFIG_RELOCATABLE
13604 dest = output;
13605 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13606 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13607 #else
13608 dest = (void *)(phdr->p_paddr);
13609 #endif
13610 memcpy(dest,
13611 output + phdr->p_offset,
13612 phdr->p_filesz);
13613 + if (i)
13614 + memset(prev, 0xff, dest - prev);
13615 + prev = dest + phdr->p_filesz;
13616 break;
13617 default: /* Ignore other PT_* */ break;
13618 }
13619 @@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13620 error("Destination address too large");
13621 #endif
13622 #ifndef CONFIG_RELOCATABLE
13623 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13624 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13625 error("Wrong destination address");
13626 #endif
13627
13628 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13629 index 1fd7d57..0f7d096 100644
13630 --- a/arch/x86/boot/cpucheck.c
13631 +++ b/arch/x86/boot/cpucheck.c
13632 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13633 u32 ecx = MSR_K7_HWCR;
13634 u32 eax, edx;
13635
13636 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13637 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13638 eax &= ~(1 << 15);
13639 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13640 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13641
13642 get_cpuflags(); /* Make sure it really did something */
13643 err = check_cpuflags();
13644 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13645 u32 ecx = MSR_VIA_FCR;
13646 u32 eax, edx;
13647
13648 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13649 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13650 eax |= (1<<1)|(1<<7);
13651 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13652 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13653
13654 set_bit(X86_FEATURE_CX8, cpu.flags);
13655 err = check_cpuflags();
13656 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13657 u32 eax, edx;
13658 u32 level = 1;
13659
13660 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13661 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13662 - asm("cpuid"
13663 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13664 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13665 + asm volatile("cpuid"
13666 : "+a" (level), "=d" (cpu.flags[0])
13667 : : "ecx", "ebx");
13668 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13669 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13670
13671 err = check_cpuflags();
13672 } else if (err == 0x01 &&
13673 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13674 index 16ef025..91e033b 100644
13675 --- a/arch/x86/boot/header.S
13676 +++ b/arch/x86/boot/header.S
13677 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13678 # single linked list of
13679 # struct setup_data
13680
13681 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13682 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13683
13684 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13685 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13686 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13687 +#else
13688 #define VO_INIT_SIZE (VO__end - VO__text)
13689 +#endif
13690 #if ZO_INIT_SIZE > VO_INIT_SIZE
13691 #define INIT_SIZE ZO_INIT_SIZE
13692 #else
13693 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13694 index db75d07..8e6d0af 100644
13695 --- a/arch/x86/boot/memory.c
13696 +++ b/arch/x86/boot/memory.c
13697 @@ -19,7 +19,7 @@
13698
13699 static int detect_memory_e820(void)
13700 {
13701 - int count = 0;
13702 + unsigned int count = 0;
13703 struct biosregs ireg, oreg;
13704 struct e820entry *desc = boot_params.e820_map;
13705 static struct e820entry buf; /* static so it is zeroed */
13706 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13707 index ba3e100..6501b8f 100644
13708 --- a/arch/x86/boot/video-vesa.c
13709 +++ b/arch/x86/boot/video-vesa.c
13710 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13711
13712 boot_params.screen_info.vesapm_seg = oreg.es;
13713 boot_params.screen_info.vesapm_off = oreg.di;
13714 + boot_params.screen_info.vesapm_size = oreg.cx;
13715 }
13716
13717 /*
13718 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13719 index 43eda28..5ab5fdb 100644
13720 --- a/arch/x86/boot/video.c
13721 +++ b/arch/x86/boot/video.c
13722 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13723 static unsigned int get_entry(void)
13724 {
13725 char entry_buf[4];
13726 - int i, len = 0;
13727 + unsigned int i, len = 0;
13728 int key;
13729 unsigned int v;
13730
13731 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13732 index 9105655..41779c1 100644
13733 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13734 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13735 @@ -8,6 +8,8 @@
13736 * including this sentence is retained in full.
13737 */
13738
13739 +#include <asm/alternative-asm.h>
13740 +
13741 .extern crypto_ft_tab
13742 .extern crypto_it_tab
13743 .extern crypto_fl_tab
13744 @@ -70,6 +72,8 @@
13745 je B192; \
13746 leaq 32(r9),r9;
13747
13748 +#define ret pax_force_retaddr; ret
13749 +
13750 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13751 movq r1,r2; \
13752 movq r3,r4; \
13753 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13754 index 477e9d7..c92c7d8 100644
13755 --- a/arch/x86/crypto/aesni-intel_asm.S
13756 +++ b/arch/x86/crypto/aesni-intel_asm.S
13757 @@ -31,6 +31,7 @@
13758
13759 #include <linux/linkage.h>
13760 #include <asm/inst.h>
13761 +#include <asm/alternative-asm.h>
13762
13763 #ifdef __x86_64__
13764 .data
13765 @@ -205,7 +206,7 @@ enc: .octa 0x2
13766 * num_initial_blocks = b mod 4
13767 * encrypt the initial num_initial_blocks blocks and apply ghash on
13768 * the ciphertext
13769 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13770 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13771 * are clobbered
13772 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13773 */
13774 @@ -214,8 +215,8 @@ enc: .octa 0x2
13775 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13776 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13777 mov arg7, %r10 # %r10 = AAD
13778 - mov arg8, %r12 # %r12 = aadLen
13779 - mov %r12, %r11
13780 + mov arg8, %r15 # %r15 = aadLen
13781 + mov %r15, %r11
13782 pxor %xmm\i, %xmm\i
13783 _get_AAD_loop\num_initial_blocks\operation:
13784 movd (%r10), \TMP1
13785 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13786 psrldq $4, %xmm\i
13787 pxor \TMP1, %xmm\i
13788 add $4, %r10
13789 - sub $4, %r12
13790 + sub $4, %r15
13791 jne _get_AAD_loop\num_initial_blocks\operation
13792 cmp $16, %r11
13793 je _get_AAD_loop2_done\num_initial_blocks\operation
13794 - mov $16, %r12
13795 + mov $16, %r15
13796 _get_AAD_loop2\num_initial_blocks\operation:
13797 psrldq $4, %xmm\i
13798 - sub $4, %r12
13799 - cmp %r11, %r12
13800 + sub $4, %r15
13801 + cmp %r11, %r15
13802 jne _get_AAD_loop2\num_initial_blocks\operation
13803 _get_AAD_loop2_done\num_initial_blocks\operation:
13804 movdqa SHUF_MASK(%rip), %xmm14
13805 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13806 * num_initial_blocks = b mod 4
13807 * encrypt the initial num_initial_blocks blocks and apply ghash on
13808 * the ciphertext
13809 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13810 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13811 * are clobbered
13812 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13813 */
13814 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13815 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13816 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13817 mov arg7, %r10 # %r10 = AAD
13818 - mov arg8, %r12 # %r12 = aadLen
13819 - mov %r12, %r11
13820 + mov arg8, %r15 # %r15 = aadLen
13821 + mov %r15, %r11
13822 pxor %xmm\i, %xmm\i
13823 _get_AAD_loop\num_initial_blocks\operation:
13824 movd (%r10), \TMP1
13825 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13826 psrldq $4, %xmm\i
13827 pxor \TMP1, %xmm\i
13828 add $4, %r10
13829 - sub $4, %r12
13830 + sub $4, %r15
13831 jne _get_AAD_loop\num_initial_blocks\operation
13832 cmp $16, %r11
13833 je _get_AAD_loop2_done\num_initial_blocks\operation
13834 - mov $16, %r12
13835 + mov $16, %r15
13836 _get_AAD_loop2\num_initial_blocks\operation:
13837 psrldq $4, %xmm\i
13838 - sub $4, %r12
13839 - cmp %r11, %r12
13840 + sub $4, %r15
13841 + cmp %r11, %r15
13842 jne _get_AAD_loop2\num_initial_blocks\operation
13843 _get_AAD_loop2_done\num_initial_blocks\operation:
13844 movdqa SHUF_MASK(%rip), %xmm14
13845 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13846 *
13847 *****************************************************************************/
13848 ENTRY(aesni_gcm_dec)
13849 - push %r12
13850 + push %r15
13851 push %r13
13852 push %r14
13853 mov %rsp, %r14
13854 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13855 */
13856 sub $VARIABLE_OFFSET, %rsp
13857 and $~63, %rsp # align rsp to 64 bytes
13858 - mov %arg6, %r12
13859 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13860 + mov %arg6, %r15
13861 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13862 movdqa SHUF_MASK(%rip), %xmm2
13863 PSHUFB_XMM %xmm2, %xmm13
13864
13865 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13866 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13867 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13868 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13869 - mov %r13, %r12
13870 - and $(3<<4), %r12
13871 + mov %r13, %r15
13872 + and $(3<<4), %r15
13873 jz _initial_num_blocks_is_0_decrypt
13874 - cmp $(2<<4), %r12
13875 + cmp $(2<<4), %r15
13876 jb _initial_num_blocks_is_1_decrypt
13877 je _initial_num_blocks_is_2_decrypt
13878 _initial_num_blocks_is_3_decrypt:
13879 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13880 sub $16, %r11
13881 add %r13, %r11
13882 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13883 - lea SHIFT_MASK+16(%rip), %r12
13884 - sub %r13, %r12
13885 + lea SHIFT_MASK+16(%rip), %r15
13886 + sub %r13, %r15
13887 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13888 # (%r13 is the number of bytes in plaintext mod 16)
13889 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13890 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13891 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13892
13893 movdqa %xmm1, %xmm2
13894 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13895 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13896 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13897 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13898 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13899 pand %xmm1, %xmm2
13900 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13901 sub $1, %r13
13902 jne _less_than_8_bytes_left_decrypt
13903 _multiple_of_16_bytes_decrypt:
13904 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13905 - shl $3, %r12 # convert into number of bits
13906 - movd %r12d, %xmm15 # len(A) in %xmm15
13907 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13908 + shl $3, %r15 # convert into number of bits
13909 + movd %r15d, %xmm15 # len(A) in %xmm15
13910 shl $3, %arg4 # len(C) in bits (*128)
13911 MOVQ_R64_XMM %arg4, %xmm1
13912 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13913 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13914 mov %r14, %rsp
13915 pop %r14
13916 pop %r13
13917 - pop %r12
13918 + pop %r15
13919 + pax_force_retaddr
13920 ret
13921 ENDPROC(aesni_gcm_dec)
13922
13923 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13924 * poly = x^128 + x^127 + x^126 + x^121 + 1
13925 ***************************************************************************/
13926 ENTRY(aesni_gcm_enc)
13927 - push %r12
13928 + push %r15
13929 push %r13
13930 push %r14
13931 mov %rsp, %r14
13932 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13933 #
13934 sub $VARIABLE_OFFSET, %rsp
13935 and $~63, %rsp
13936 - mov %arg6, %r12
13937 - movdqu (%r12), %xmm13
13938 + mov %arg6, %r15
13939 + movdqu (%r15), %xmm13
13940 movdqa SHUF_MASK(%rip), %xmm2
13941 PSHUFB_XMM %xmm2, %xmm13
13942
13943 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13944 movdqa %xmm13, HashKey(%rsp)
13945 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13946 and $-16, %r13
13947 - mov %r13, %r12
13948 + mov %r13, %r15
13949
13950 # Encrypt first few blocks
13951
13952 - and $(3<<4), %r12
13953 + and $(3<<4), %r15
13954 jz _initial_num_blocks_is_0_encrypt
13955 - cmp $(2<<4), %r12
13956 + cmp $(2<<4), %r15
13957 jb _initial_num_blocks_is_1_encrypt
13958 je _initial_num_blocks_is_2_encrypt
13959 _initial_num_blocks_is_3_encrypt:
13960 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13961 sub $16, %r11
13962 add %r13, %r11
13963 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13964 - lea SHIFT_MASK+16(%rip), %r12
13965 - sub %r13, %r12
13966 + lea SHIFT_MASK+16(%rip), %r15
13967 + sub %r13, %r15
13968 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13969 # (%r13 is the number of bytes in plaintext mod 16)
13970 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13971 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13972 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13973 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13974 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13975 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13976 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13977 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13978 movdqa SHUF_MASK(%rip), %xmm10
13979 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13980 sub $1, %r13
13981 jne _less_than_8_bytes_left_encrypt
13982 _multiple_of_16_bytes_encrypt:
13983 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13984 - shl $3, %r12
13985 - movd %r12d, %xmm15 # len(A) in %xmm15
13986 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13987 + shl $3, %r15
13988 + movd %r15d, %xmm15 # len(A) in %xmm15
13989 shl $3, %arg4 # len(C) in bits (*128)
13990 MOVQ_R64_XMM %arg4, %xmm1
13991 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13992 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13993 mov %r14, %rsp
13994 pop %r14
13995 pop %r13
13996 - pop %r12
13997 + pop %r15
13998 + pax_force_retaddr
13999 ret
14000 ENDPROC(aesni_gcm_enc)
14001
14002 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
14003 pxor %xmm1, %xmm0
14004 movaps %xmm0, (TKEYP)
14005 add $0x10, TKEYP
14006 + pax_force_retaddr
14007 ret
14008 ENDPROC(_key_expansion_128)
14009 ENDPROC(_key_expansion_256a)
14010 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
14011 shufps $0b01001110, %xmm2, %xmm1
14012 movaps %xmm1, 0x10(TKEYP)
14013 add $0x20, TKEYP
14014 + pax_force_retaddr
14015 ret
14016 ENDPROC(_key_expansion_192a)
14017
14018 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
14019
14020 movaps %xmm0, (TKEYP)
14021 add $0x10, TKEYP
14022 + pax_force_retaddr
14023 ret
14024 ENDPROC(_key_expansion_192b)
14025
14026 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
14027 pxor %xmm1, %xmm2
14028 movaps %xmm2, (TKEYP)
14029 add $0x10, TKEYP
14030 + pax_force_retaddr
14031 ret
14032 ENDPROC(_key_expansion_256b)
14033
14034 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
14035 #ifndef __x86_64__
14036 popl KEYP
14037 #endif
14038 + pax_force_retaddr
14039 ret
14040 ENDPROC(aesni_set_key)
14041
14042 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
14043 popl KLEN
14044 popl KEYP
14045 #endif
14046 + pax_force_retaddr
14047 ret
14048 ENDPROC(aesni_enc)
14049
14050 @@ -1974,6 +1983,7 @@ _aesni_enc1:
14051 AESENC KEY STATE
14052 movaps 0x70(TKEYP), KEY
14053 AESENCLAST KEY STATE
14054 + pax_force_retaddr
14055 ret
14056 ENDPROC(_aesni_enc1)
14057
14058 @@ -2083,6 +2093,7 @@ _aesni_enc4:
14059 AESENCLAST KEY STATE2
14060 AESENCLAST KEY STATE3
14061 AESENCLAST KEY STATE4
14062 + pax_force_retaddr
14063 ret
14064 ENDPROC(_aesni_enc4)
14065
14066 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
14067 popl KLEN
14068 popl KEYP
14069 #endif
14070 + pax_force_retaddr
14071 ret
14072 ENDPROC(aesni_dec)
14073
14074 @@ -2164,6 +2176,7 @@ _aesni_dec1:
14075 AESDEC KEY STATE
14076 movaps 0x70(TKEYP), KEY
14077 AESDECLAST KEY STATE
14078 + pax_force_retaddr
14079 ret
14080 ENDPROC(_aesni_dec1)
14081
14082 @@ -2273,6 +2286,7 @@ _aesni_dec4:
14083 AESDECLAST KEY STATE2
14084 AESDECLAST KEY STATE3
14085 AESDECLAST KEY STATE4
14086 + pax_force_retaddr
14087 ret
14088 ENDPROC(_aesni_dec4)
14089
14090 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
14091 popl KEYP
14092 popl LEN
14093 #endif
14094 + pax_force_retaddr
14095 ret
14096 ENDPROC(aesni_ecb_enc)
14097
14098 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
14099 popl KEYP
14100 popl LEN
14101 #endif
14102 + pax_force_retaddr
14103 ret
14104 ENDPROC(aesni_ecb_dec)
14105
14106 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
14107 popl LEN
14108 popl IVP
14109 #endif
14110 + pax_force_retaddr
14111 ret
14112 ENDPROC(aesni_cbc_enc)
14113
14114 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
14115 popl LEN
14116 popl IVP
14117 #endif
14118 + pax_force_retaddr
14119 ret
14120 ENDPROC(aesni_cbc_dec)
14121
14122 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
14123 mov $1, TCTR_LOW
14124 MOVQ_R64_XMM TCTR_LOW INC
14125 MOVQ_R64_XMM CTR TCTR_LOW
14126 + pax_force_retaddr
14127 ret
14128 ENDPROC(_aesni_inc_init)
14129
14130 @@ -2579,6 +2598,7 @@ _aesni_inc:
14131 .Linc_low:
14132 movaps CTR, IV
14133 PSHUFB_XMM BSWAP_MASK IV
14134 + pax_force_retaddr
14135 ret
14136 ENDPROC(_aesni_inc)
14137
14138 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
14139 .Lctr_enc_ret:
14140 movups IV, (IVP)
14141 .Lctr_enc_just_ret:
14142 + pax_force_retaddr
14143 ret
14144 ENDPROC(aesni_ctr_enc)
14145
14146 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
14147 pxor INC, STATE4
14148 movdqu STATE4, 0x70(OUTP)
14149
14150 + pax_force_retaddr
14151 ret
14152 ENDPROC(aesni_xts_crypt8)
14153
14154 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14155 index 246c670..466e2d6 100644
14156 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
14157 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14158 @@ -21,6 +21,7 @@
14159 */
14160
14161 #include <linux/linkage.h>
14162 +#include <asm/alternative-asm.h>
14163
14164 .file "blowfish-x86_64-asm.S"
14165 .text
14166 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
14167 jnz .L__enc_xor;
14168
14169 write_block();
14170 + pax_force_retaddr
14171 ret;
14172 .L__enc_xor:
14173 xor_block();
14174 + pax_force_retaddr
14175 ret;
14176 ENDPROC(__blowfish_enc_blk)
14177
14178 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
14179
14180 movq %r11, %rbp;
14181
14182 + pax_force_retaddr
14183 ret;
14184 ENDPROC(blowfish_dec_blk)
14185
14186 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
14187
14188 popq %rbx;
14189 popq %rbp;
14190 + pax_force_retaddr
14191 ret;
14192
14193 .L__enc_xor4:
14194 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
14195
14196 popq %rbx;
14197 popq %rbp;
14198 + pax_force_retaddr
14199 ret;
14200 ENDPROC(__blowfish_enc_blk_4way)
14201
14202 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
14203 popq %rbx;
14204 popq %rbp;
14205
14206 + pax_force_retaddr
14207 ret;
14208 ENDPROC(blowfish_dec_blk_4way)
14209 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14210 index ce71f92..1dce7ec 100644
14211 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14212 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14213 @@ -16,6 +16,7 @@
14214 */
14215
14216 #include <linux/linkage.h>
14217 +#include <asm/alternative-asm.h>
14218
14219 #define CAMELLIA_TABLE_BYTE_LEN 272
14220
14221 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14222 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
14223 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
14224 %rcx, (%r9));
14225 + pax_force_retaddr
14226 ret;
14227 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14228
14229 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14230 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
14231 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
14232 %rax, (%r9));
14233 + pax_force_retaddr
14234 ret;
14235 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14236
14237 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
14238 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14239 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
14240
14241 + pax_force_retaddr
14242 ret;
14243
14244 .align 8
14245 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
14246 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14247 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
14248
14249 + pax_force_retaddr
14250 ret;
14251
14252 .align 8
14253 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
14254 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14255 %xmm8, %rsi);
14256
14257 + pax_force_retaddr
14258 ret;
14259 ENDPROC(camellia_ecb_enc_16way)
14260
14261 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
14262 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14263 %xmm8, %rsi);
14264
14265 + pax_force_retaddr
14266 ret;
14267 ENDPROC(camellia_ecb_dec_16way)
14268
14269 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
14270 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14271 %xmm8, %rsi);
14272
14273 + pax_force_retaddr
14274 ret;
14275 ENDPROC(camellia_cbc_dec_16way)
14276
14277 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
14278 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14279 %xmm8, %rsi);
14280
14281 + pax_force_retaddr
14282 ret;
14283 ENDPROC(camellia_ctr_16way)
14284
14285 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
14286 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14287 %xmm8, %rsi);
14288
14289 + pax_force_retaddr
14290 ret;
14291 ENDPROC(camellia_xts_crypt_16way)
14292
14293 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14294 index 0e0b886..5a3123c 100644
14295 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14296 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14297 @@ -11,6 +11,7 @@
14298 */
14299
14300 #include <linux/linkage.h>
14301 +#include <asm/alternative-asm.h>
14302
14303 #define CAMELLIA_TABLE_BYTE_LEN 272
14304
14305 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14306 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
14307 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
14308 %rcx, (%r9));
14309 + pax_force_retaddr
14310 ret;
14311 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14312
14313 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14314 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
14315 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
14316 %rax, (%r9));
14317 + pax_force_retaddr
14318 ret;
14319 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14320
14321 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
14322 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14323 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
14324
14325 + pax_force_retaddr
14326 ret;
14327
14328 .align 8
14329 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
14330 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14331 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
14332
14333 + pax_force_retaddr
14334 ret;
14335
14336 .align 8
14337 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
14338
14339 vzeroupper;
14340
14341 + pax_force_retaddr
14342 ret;
14343 ENDPROC(camellia_ecb_enc_32way)
14344
14345 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
14346
14347 vzeroupper;
14348
14349 + pax_force_retaddr
14350 ret;
14351 ENDPROC(camellia_ecb_dec_32way)
14352
14353 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
14354
14355 vzeroupper;
14356
14357 + pax_force_retaddr
14358 ret;
14359 ENDPROC(camellia_cbc_dec_32way)
14360
14361 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
14362
14363 vzeroupper;
14364
14365 + pax_force_retaddr
14366 ret;
14367 ENDPROC(camellia_ctr_32way)
14368
14369 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
14370
14371 vzeroupper;
14372
14373 + pax_force_retaddr
14374 ret;
14375 ENDPROC(camellia_xts_crypt_32way)
14376
14377 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
14378 index 310319c..db3d7b5 100644
14379 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
14380 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
14381 @@ -21,6 +21,7 @@
14382 */
14383
14384 #include <linux/linkage.h>
14385 +#include <asm/alternative-asm.h>
14386
14387 .file "camellia-x86_64-asm_64.S"
14388 .text
14389 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
14390 enc_outunpack(mov, RT1);
14391
14392 movq RRBP, %rbp;
14393 + pax_force_retaddr
14394 ret;
14395
14396 .L__enc_xor:
14397 enc_outunpack(xor, RT1);
14398
14399 movq RRBP, %rbp;
14400 + pax_force_retaddr
14401 ret;
14402 ENDPROC(__camellia_enc_blk)
14403
14404 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
14405 dec_outunpack();
14406
14407 movq RRBP, %rbp;
14408 + pax_force_retaddr
14409 ret;
14410 ENDPROC(camellia_dec_blk)
14411
14412 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
14413
14414 movq RRBP, %rbp;
14415 popq %rbx;
14416 + pax_force_retaddr
14417 ret;
14418
14419 .L__enc2_xor:
14420 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
14421
14422 movq RRBP, %rbp;
14423 popq %rbx;
14424 + pax_force_retaddr
14425 ret;
14426 ENDPROC(__camellia_enc_blk_2way)
14427
14428 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
14429
14430 movq RRBP, %rbp;
14431 movq RXOR, %rbx;
14432 + pax_force_retaddr
14433 ret;
14434 ENDPROC(camellia_dec_blk_2way)
14435 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14436 index c35fd5d..2d8c7db 100644
14437 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14438 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14439 @@ -24,6 +24,7 @@
14440 */
14441
14442 #include <linux/linkage.h>
14443 +#include <asm/alternative-asm.h>
14444
14445 .file "cast5-avx-x86_64-asm_64.S"
14446
14447 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
14448 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14449 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14450
14451 + pax_force_retaddr
14452 ret;
14453 ENDPROC(__cast5_enc_blk16)
14454
14455 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
14456 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14457 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14458
14459 + pax_force_retaddr
14460 ret;
14461
14462 .L__skip_dec:
14463 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14464 vmovdqu RR4, (6*4*4)(%r11);
14465 vmovdqu RL4, (7*4*4)(%r11);
14466
14467 + pax_force_retaddr
14468 ret;
14469 ENDPROC(cast5_ecb_enc_16way)
14470
14471 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14472 vmovdqu RR4, (6*4*4)(%r11);
14473 vmovdqu RL4, (7*4*4)(%r11);
14474
14475 + pax_force_retaddr
14476 ret;
14477 ENDPROC(cast5_ecb_dec_16way)
14478
14479 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14480 * %rdx: src
14481 */
14482
14483 - pushq %r12;
14484 + pushq %r14;
14485
14486 movq %rsi, %r11;
14487 - movq %rdx, %r12;
14488 + movq %rdx, %r14;
14489
14490 vmovdqu (0*16)(%rdx), RL1;
14491 vmovdqu (1*16)(%rdx), RR1;
14492 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14493 call __cast5_dec_blk16;
14494
14495 /* xor with src */
14496 - vmovq (%r12), RX;
14497 + vmovq (%r14), RX;
14498 vpshufd $0x4f, RX, RX;
14499 vpxor RX, RR1, RR1;
14500 - vpxor 0*16+8(%r12), RL1, RL1;
14501 - vpxor 1*16+8(%r12), RR2, RR2;
14502 - vpxor 2*16+8(%r12), RL2, RL2;
14503 - vpxor 3*16+8(%r12), RR3, RR3;
14504 - vpxor 4*16+8(%r12), RL3, RL3;
14505 - vpxor 5*16+8(%r12), RR4, RR4;
14506 - vpxor 6*16+8(%r12), RL4, RL4;
14507 + vpxor 0*16+8(%r14), RL1, RL1;
14508 + vpxor 1*16+8(%r14), RR2, RR2;
14509 + vpxor 2*16+8(%r14), RL2, RL2;
14510 + vpxor 3*16+8(%r14), RR3, RR3;
14511 + vpxor 4*16+8(%r14), RL3, RL3;
14512 + vpxor 5*16+8(%r14), RR4, RR4;
14513 + vpxor 6*16+8(%r14), RL4, RL4;
14514
14515 vmovdqu RR1, (0*16)(%r11);
14516 vmovdqu RL1, (1*16)(%r11);
14517 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14518 vmovdqu RR4, (6*16)(%r11);
14519 vmovdqu RL4, (7*16)(%r11);
14520
14521 - popq %r12;
14522 + popq %r14;
14523
14524 + pax_force_retaddr
14525 ret;
14526 ENDPROC(cast5_cbc_dec_16way)
14527
14528 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14529 * %rcx: iv (big endian, 64bit)
14530 */
14531
14532 - pushq %r12;
14533 + pushq %r14;
14534
14535 movq %rsi, %r11;
14536 - movq %rdx, %r12;
14537 + movq %rdx, %r14;
14538
14539 vpcmpeqd RTMP, RTMP, RTMP;
14540 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14541 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14542 call __cast5_enc_blk16;
14543
14544 /* dst = src ^ iv */
14545 - vpxor (0*16)(%r12), RR1, RR1;
14546 - vpxor (1*16)(%r12), RL1, RL1;
14547 - vpxor (2*16)(%r12), RR2, RR2;
14548 - vpxor (3*16)(%r12), RL2, RL2;
14549 - vpxor (4*16)(%r12), RR3, RR3;
14550 - vpxor (5*16)(%r12), RL3, RL3;
14551 - vpxor (6*16)(%r12), RR4, RR4;
14552 - vpxor (7*16)(%r12), RL4, RL4;
14553 + vpxor (0*16)(%r14), RR1, RR1;
14554 + vpxor (1*16)(%r14), RL1, RL1;
14555 + vpxor (2*16)(%r14), RR2, RR2;
14556 + vpxor (3*16)(%r14), RL2, RL2;
14557 + vpxor (4*16)(%r14), RR3, RR3;
14558 + vpxor (5*16)(%r14), RL3, RL3;
14559 + vpxor (6*16)(%r14), RR4, RR4;
14560 + vpxor (7*16)(%r14), RL4, RL4;
14561 vmovdqu RR1, (0*16)(%r11);
14562 vmovdqu RL1, (1*16)(%r11);
14563 vmovdqu RR2, (2*16)(%r11);
14564 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14565 vmovdqu RR4, (6*16)(%r11);
14566 vmovdqu RL4, (7*16)(%r11);
14567
14568 - popq %r12;
14569 + popq %r14;
14570
14571 + pax_force_retaddr
14572 ret;
14573 ENDPROC(cast5_ctr_16way)
14574 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14575 index e3531f8..e123f35 100644
14576 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14577 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14578 @@ -24,6 +24,7 @@
14579 */
14580
14581 #include <linux/linkage.h>
14582 +#include <asm/alternative-asm.h>
14583 #include "glue_helper-asm-avx.S"
14584
14585 .file "cast6-avx-x86_64-asm_64.S"
14586 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14587 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14588 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14589
14590 + pax_force_retaddr
14591 ret;
14592 ENDPROC(__cast6_enc_blk8)
14593
14594 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14595 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14596 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14597
14598 + pax_force_retaddr
14599 ret;
14600 ENDPROC(__cast6_dec_blk8)
14601
14602 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14603
14604 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14605
14606 + pax_force_retaddr
14607 ret;
14608 ENDPROC(cast6_ecb_enc_8way)
14609
14610 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14611
14612 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14613
14614 + pax_force_retaddr
14615 ret;
14616 ENDPROC(cast6_ecb_dec_8way)
14617
14618 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14619 * %rdx: src
14620 */
14621
14622 - pushq %r12;
14623 + pushq %r14;
14624
14625 movq %rsi, %r11;
14626 - movq %rdx, %r12;
14627 + movq %rdx, %r14;
14628
14629 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14630
14631 call __cast6_dec_blk8;
14632
14633 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14634 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14635
14636 - popq %r12;
14637 + popq %r14;
14638
14639 + pax_force_retaddr
14640 ret;
14641 ENDPROC(cast6_cbc_dec_8way)
14642
14643 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14644 * %rcx: iv (little endian, 128bit)
14645 */
14646
14647 - pushq %r12;
14648 + pushq %r14;
14649
14650 movq %rsi, %r11;
14651 - movq %rdx, %r12;
14652 + movq %rdx, %r14;
14653
14654 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14655 RD2, RX, RKR, RKM);
14656
14657 call __cast6_enc_blk8;
14658
14659 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14660 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14661
14662 - popq %r12;
14663 + popq %r14;
14664
14665 + pax_force_retaddr
14666 ret;
14667 ENDPROC(cast6_ctr_8way)
14668
14669 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14670 /* dst <= regs xor IVs(in dst) */
14671 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14672
14673 + pax_force_retaddr
14674 ret;
14675 ENDPROC(cast6_xts_enc_8way)
14676
14677 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14678 /* dst <= regs xor IVs(in dst) */
14679 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14680
14681 + pax_force_retaddr
14682 ret;
14683 ENDPROC(cast6_xts_dec_8way)
14684 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14685 index 26d49eb..c0a8c84 100644
14686 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14687 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14688 @@ -45,6 +45,7 @@
14689
14690 #include <asm/inst.h>
14691 #include <linux/linkage.h>
14692 +#include <asm/alternative-asm.h>
14693
14694 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14695
14696 @@ -309,6 +310,7 @@ do_return:
14697 popq %rsi
14698 popq %rdi
14699 popq %rbx
14700 + pax_force_retaddr
14701 ret
14702
14703 ################################################################
14704 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14705 index 5d1e007..098cb4f 100644
14706 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14707 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14708 @@ -18,6 +18,7 @@
14709
14710 #include <linux/linkage.h>
14711 #include <asm/inst.h>
14712 +#include <asm/alternative-asm.h>
14713
14714 .data
14715
14716 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14717 psrlq $1, T2
14718 pxor T2, T1
14719 pxor T1, DATA
14720 + pax_force_retaddr
14721 ret
14722 ENDPROC(__clmul_gf128mul_ble)
14723
14724 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14725 call __clmul_gf128mul_ble
14726 PSHUFB_XMM BSWAP DATA
14727 movups DATA, (%rdi)
14728 + pax_force_retaddr
14729 ret
14730 ENDPROC(clmul_ghash_mul)
14731
14732 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14733 PSHUFB_XMM BSWAP DATA
14734 movups DATA, (%rdi)
14735 .Lupdate_just_ret:
14736 + pax_force_retaddr
14737 ret
14738 ENDPROC(clmul_ghash_update)
14739 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14740 index 9279e0b..c4b3d2c 100644
14741 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14742 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14743 @@ -1,4 +1,5 @@
14744 #include <linux/linkage.h>
14745 +#include <asm/alternative-asm.h>
14746
14747 # enter salsa20_encrypt_bytes
14748 ENTRY(salsa20_encrypt_bytes)
14749 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14750 add %r11,%rsp
14751 mov %rdi,%rax
14752 mov %rsi,%rdx
14753 + pax_force_retaddr
14754 ret
14755 # bytesatleast65:
14756 ._bytesatleast65:
14757 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14758 add %r11,%rsp
14759 mov %rdi,%rax
14760 mov %rsi,%rdx
14761 + pax_force_retaddr
14762 ret
14763 ENDPROC(salsa20_keysetup)
14764
14765 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14766 add %r11,%rsp
14767 mov %rdi,%rax
14768 mov %rsi,%rdx
14769 + pax_force_retaddr
14770 ret
14771 ENDPROC(salsa20_ivsetup)
14772 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14773 index 2f202f4..d9164d6 100644
14774 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14775 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14776 @@ -24,6 +24,7 @@
14777 */
14778
14779 #include <linux/linkage.h>
14780 +#include <asm/alternative-asm.h>
14781 #include "glue_helper-asm-avx.S"
14782
14783 .file "serpent-avx-x86_64-asm_64.S"
14784 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14785 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14786 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14787
14788 + pax_force_retaddr
14789 ret;
14790 ENDPROC(__serpent_enc_blk8_avx)
14791
14792 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14793 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14794 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14795
14796 + pax_force_retaddr
14797 ret;
14798 ENDPROC(__serpent_dec_blk8_avx)
14799
14800 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14801
14802 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14803
14804 + pax_force_retaddr
14805 ret;
14806 ENDPROC(serpent_ecb_enc_8way_avx)
14807
14808 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14809
14810 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14811
14812 + pax_force_retaddr
14813 ret;
14814 ENDPROC(serpent_ecb_dec_8way_avx)
14815
14816 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14817
14818 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14819
14820 + pax_force_retaddr
14821 ret;
14822 ENDPROC(serpent_cbc_dec_8way_avx)
14823
14824 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14825
14826 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14827
14828 + pax_force_retaddr
14829 ret;
14830 ENDPROC(serpent_ctr_8way_avx)
14831
14832 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14833 /* dst <= regs xor IVs(in dst) */
14834 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14835
14836 + pax_force_retaddr
14837 ret;
14838 ENDPROC(serpent_xts_enc_8way_avx)
14839
14840 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14841 /* dst <= regs xor IVs(in dst) */
14842 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14843
14844 + pax_force_retaddr
14845 ret;
14846 ENDPROC(serpent_xts_dec_8way_avx)
14847 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14848 index b222085..abd483c 100644
14849 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14850 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14851 @@ -15,6 +15,7 @@
14852 */
14853
14854 #include <linux/linkage.h>
14855 +#include <asm/alternative-asm.h>
14856 #include "glue_helper-asm-avx2.S"
14857
14858 .file "serpent-avx2-asm_64.S"
14859 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14860 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14861 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14862
14863 + pax_force_retaddr
14864 ret;
14865 ENDPROC(__serpent_enc_blk16)
14866
14867 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14868 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14869 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14870
14871 + pax_force_retaddr
14872 ret;
14873 ENDPROC(__serpent_dec_blk16)
14874
14875 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14876
14877 vzeroupper;
14878
14879 + pax_force_retaddr
14880 ret;
14881 ENDPROC(serpent_ecb_enc_16way)
14882
14883 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14884
14885 vzeroupper;
14886
14887 + pax_force_retaddr
14888 ret;
14889 ENDPROC(serpent_ecb_dec_16way)
14890
14891 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14892
14893 vzeroupper;
14894
14895 + pax_force_retaddr
14896 ret;
14897 ENDPROC(serpent_cbc_dec_16way)
14898
14899 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14900
14901 vzeroupper;
14902
14903 + pax_force_retaddr
14904 ret;
14905 ENDPROC(serpent_ctr_16way)
14906
14907 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14908
14909 vzeroupper;
14910
14911 + pax_force_retaddr
14912 ret;
14913 ENDPROC(serpent_xts_enc_16way)
14914
14915 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14916
14917 vzeroupper;
14918
14919 + pax_force_retaddr
14920 ret;
14921 ENDPROC(serpent_xts_dec_16way)
14922 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14923 index acc066c..1559cc4 100644
14924 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14925 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14926 @@ -25,6 +25,7 @@
14927 */
14928
14929 #include <linux/linkage.h>
14930 +#include <asm/alternative-asm.h>
14931
14932 .file "serpent-sse2-x86_64-asm_64.S"
14933 .text
14934 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14935 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14936 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14937
14938 + pax_force_retaddr
14939 ret;
14940
14941 .L__enc_xor8:
14942 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14943 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14944
14945 + pax_force_retaddr
14946 ret;
14947 ENDPROC(__serpent_enc_blk_8way)
14948
14949 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14950 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14951 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14952
14953 + pax_force_retaddr
14954 ret;
14955 ENDPROC(serpent_dec_blk_8way)
14956 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14957 index a410950..9dfe7ad 100644
14958 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14959 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14960 @@ -29,6 +29,7 @@
14961 */
14962
14963 #include <linux/linkage.h>
14964 +#include <asm/alternative-asm.h>
14965
14966 #define CTX %rdi // arg1
14967 #define BUF %rsi // arg2
14968 @@ -75,9 +76,9 @@
14969
14970 push %rbx
14971 push %rbp
14972 - push %r12
14973 + push %r14
14974
14975 - mov %rsp, %r12
14976 + mov %rsp, %r14
14977 sub $64, %rsp # allocate workspace
14978 and $~15, %rsp # align stack
14979
14980 @@ -99,11 +100,12 @@
14981 xor %rax, %rax
14982 rep stosq
14983
14984 - mov %r12, %rsp # deallocate workspace
14985 + mov %r14, %rsp # deallocate workspace
14986
14987 - pop %r12
14988 + pop %r14
14989 pop %rbp
14990 pop %rbx
14991 + pax_force_retaddr
14992 ret
14993
14994 ENDPROC(\name)
14995 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14996 index 642f156..51a513c 100644
14997 --- a/arch/x86/crypto/sha256-avx-asm.S
14998 +++ b/arch/x86/crypto/sha256-avx-asm.S
14999 @@ -49,6 +49,7 @@
15000
15001 #ifdef CONFIG_AS_AVX
15002 #include <linux/linkage.h>
15003 +#include <asm/alternative-asm.h>
15004
15005 ## assume buffers not aligned
15006 #define VMOVDQ vmovdqu
15007 @@ -460,6 +461,7 @@ done_hash:
15008 popq %r13
15009 popq %rbp
15010 popq %rbx
15011 + pax_force_retaddr
15012 ret
15013 ENDPROC(sha256_transform_avx)
15014
15015 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
15016 index 9e86944..3795e6a 100644
15017 --- a/arch/x86/crypto/sha256-avx2-asm.S
15018 +++ b/arch/x86/crypto/sha256-avx2-asm.S
15019 @@ -50,6 +50,7 @@
15020
15021 #ifdef CONFIG_AS_AVX2
15022 #include <linux/linkage.h>
15023 +#include <asm/alternative-asm.h>
15024
15025 ## assume buffers not aligned
15026 #define VMOVDQ vmovdqu
15027 @@ -720,6 +721,7 @@ done_hash:
15028 popq %r12
15029 popq %rbp
15030 popq %rbx
15031 + pax_force_retaddr
15032 ret
15033 ENDPROC(sha256_transform_rorx)
15034
15035 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
15036 index f833b74..8c62a9e 100644
15037 --- a/arch/x86/crypto/sha256-ssse3-asm.S
15038 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
15039 @@ -47,6 +47,7 @@
15040 ########################################################################
15041
15042 #include <linux/linkage.h>
15043 +#include <asm/alternative-asm.h>
15044
15045 ## assume buffers not aligned
15046 #define MOVDQ movdqu
15047 @@ -471,6 +472,7 @@ done_hash:
15048 popq %rbp
15049 popq %rbx
15050
15051 + pax_force_retaddr
15052 ret
15053 ENDPROC(sha256_transform_ssse3)
15054
15055 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
15056 index 974dde9..a823ff9 100644
15057 --- a/arch/x86/crypto/sha512-avx-asm.S
15058 +++ b/arch/x86/crypto/sha512-avx-asm.S
15059 @@ -49,6 +49,7 @@
15060
15061 #ifdef CONFIG_AS_AVX
15062 #include <linux/linkage.h>
15063 +#include <asm/alternative-asm.h>
15064
15065 .text
15066
15067 @@ -364,6 +365,7 @@ updateblock:
15068 mov frame_RSPSAVE(%rsp), %rsp
15069
15070 nowork:
15071 + pax_force_retaddr
15072 ret
15073 ENDPROC(sha512_transform_avx)
15074
15075 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
15076 index 568b961..ed20c37 100644
15077 --- a/arch/x86/crypto/sha512-avx2-asm.S
15078 +++ b/arch/x86/crypto/sha512-avx2-asm.S
15079 @@ -51,6 +51,7 @@
15080
15081 #ifdef CONFIG_AS_AVX2
15082 #include <linux/linkage.h>
15083 +#include <asm/alternative-asm.h>
15084
15085 .text
15086
15087 @@ -678,6 +679,7 @@ done_hash:
15088
15089 # Restore Stack Pointer
15090 mov frame_RSPSAVE(%rsp), %rsp
15091 + pax_force_retaddr
15092 ret
15093 ENDPROC(sha512_transform_rorx)
15094
15095 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
15096 index fb56855..6edd768 100644
15097 --- a/arch/x86/crypto/sha512-ssse3-asm.S
15098 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
15099 @@ -48,6 +48,7 @@
15100 ########################################################################
15101
15102 #include <linux/linkage.h>
15103 +#include <asm/alternative-asm.h>
15104
15105 .text
15106
15107 @@ -363,6 +364,7 @@ updateblock:
15108 mov frame_RSPSAVE(%rsp), %rsp
15109
15110 nowork:
15111 + pax_force_retaddr
15112 ret
15113 ENDPROC(sha512_transform_ssse3)
15114
15115 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15116 index 0505813..b067311 100644
15117 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15118 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15119 @@ -24,6 +24,7 @@
15120 */
15121
15122 #include <linux/linkage.h>
15123 +#include <asm/alternative-asm.h>
15124 #include "glue_helper-asm-avx.S"
15125
15126 .file "twofish-avx-x86_64-asm_64.S"
15127 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
15128 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
15129 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
15130
15131 + pax_force_retaddr
15132 ret;
15133 ENDPROC(__twofish_enc_blk8)
15134
15135 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
15136 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
15137 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
15138
15139 + pax_force_retaddr
15140 ret;
15141 ENDPROC(__twofish_dec_blk8)
15142
15143 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
15144
15145 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15146
15147 + pax_force_retaddr
15148 ret;
15149 ENDPROC(twofish_ecb_enc_8way)
15150
15151 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
15152
15153 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15154
15155 + pax_force_retaddr
15156 ret;
15157 ENDPROC(twofish_ecb_dec_8way)
15158
15159 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
15160 * %rdx: src
15161 */
15162
15163 - pushq %r12;
15164 + pushq %r14;
15165
15166 movq %rsi, %r11;
15167 - movq %rdx, %r12;
15168 + movq %rdx, %r14;
15169
15170 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15171
15172 call __twofish_dec_blk8;
15173
15174 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15175 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15176
15177 - popq %r12;
15178 + popq %r14;
15179
15180 + pax_force_retaddr
15181 ret;
15182 ENDPROC(twofish_cbc_dec_8way)
15183
15184 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
15185 * %rcx: iv (little endian, 128bit)
15186 */
15187
15188 - pushq %r12;
15189 + pushq %r14;
15190
15191 movq %rsi, %r11;
15192 - movq %rdx, %r12;
15193 + movq %rdx, %r14;
15194
15195 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
15196 RD2, RX0, RX1, RY0);
15197
15198 call __twofish_enc_blk8;
15199
15200 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15201 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15202
15203 - popq %r12;
15204 + popq %r14;
15205
15206 + pax_force_retaddr
15207 ret;
15208 ENDPROC(twofish_ctr_8way)
15209
15210 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
15211 /* dst <= regs xor IVs(in dst) */
15212 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15213
15214 + pax_force_retaddr
15215 ret;
15216 ENDPROC(twofish_xts_enc_8way)
15217
15218 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
15219 /* dst <= regs xor IVs(in dst) */
15220 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15221
15222 + pax_force_retaddr
15223 ret;
15224 ENDPROC(twofish_xts_dec_8way)
15225 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15226 index 1c3b7ce..02f578d 100644
15227 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15228 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15229 @@ -21,6 +21,7 @@
15230 */
15231
15232 #include <linux/linkage.h>
15233 +#include <asm/alternative-asm.h>
15234
15235 .file "twofish-x86_64-asm-3way.S"
15236 .text
15237 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
15238 popq %r13;
15239 popq %r14;
15240 popq %r15;
15241 + pax_force_retaddr
15242 ret;
15243
15244 .L__enc_xor3:
15245 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
15246 popq %r13;
15247 popq %r14;
15248 popq %r15;
15249 + pax_force_retaddr
15250 ret;
15251 ENDPROC(__twofish_enc_blk_3way)
15252
15253 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
15254 popq %r13;
15255 popq %r14;
15256 popq %r15;
15257 + pax_force_retaddr
15258 ret;
15259 ENDPROC(twofish_dec_blk_3way)
15260 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
15261 index a039d21..524b8b2 100644
15262 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
15263 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
15264 @@ -22,6 +22,7 @@
15265
15266 #include <linux/linkage.h>
15267 #include <asm/asm-offsets.h>
15268 +#include <asm/alternative-asm.h>
15269
15270 #define a_offset 0
15271 #define b_offset 4
15272 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
15273
15274 popq R1
15275 movq $1,%rax
15276 + pax_force_retaddr
15277 ret
15278 ENDPROC(twofish_enc_blk)
15279
15280 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
15281
15282 popq R1
15283 movq $1,%rax
15284 + pax_force_retaddr
15285 ret
15286 ENDPROC(twofish_dec_blk)
15287 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
15288 index d21ff89..6da8e6e 100644
15289 --- a/arch/x86/ia32/ia32_aout.c
15290 +++ b/arch/x86/ia32/ia32_aout.c
15291 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
15292 unsigned long dump_start, dump_size;
15293 struct user32 dump;
15294
15295 + memset(&dump, 0, sizeof(dump));
15296 +
15297 fs = get_fs();
15298 set_fs(KERNEL_DS);
15299 has_dumped = 1;
15300 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
15301 index f9e181a..db313b5 100644
15302 --- a/arch/x86/ia32/ia32_signal.c
15303 +++ b/arch/x86/ia32/ia32_signal.c
15304 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
15305 if (__get_user(set.sig[0], &frame->sc.oldmask)
15306 || (_COMPAT_NSIG_WORDS > 1
15307 && __copy_from_user((((char *) &set.sig) + 4),
15308 - &frame->extramask,
15309 + frame->extramask,
15310 sizeof(frame->extramask))))
15311 goto badframe;
15312
15313 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
15314 sp -= frame_size;
15315 /* Align the stack pointer according to the i386 ABI,
15316 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
15317 - sp = ((sp + 4) & -16ul) - 4;
15318 + sp = ((sp - 12) & -16ul) - 4;
15319 return (void __user *) sp;
15320 }
15321
15322 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15323 } else {
15324 /* Return stub is in 32bit vsyscall page */
15325 if (current->mm->context.vdso)
15326 - restorer = current->mm->context.vdso +
15327 - selected_vdso32->sym___kernel_sigreturn;
15328 + restorer = (void __force_user *)(current->mm->context.vdso +
15329 + selected_vdso32->sym___kernel_sigreturn);
15330 else
15331 - restorer = &frame->retcode;
15332 + restorer = frame->retcode;
15333 }
15334
15335 put_user_try {
15336 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15337 * These are actually not used anymore, but left because some
15338 * gdb versions depend on them as a marker.
15339 */
15340 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15341 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15342 } put_user_catch(err);
15343
15344 if (err)
15345 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15346 0xb8,
15347 __NR_ia32_rt_sigreturn,
15348 0x80cd,
15349 - 0,
15350 + 0
15351 };
15352
15353 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
15354 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15355
15356 if (ksig->ka.sa.sa_flags & SA_RESTORER)
15357 restorer = ksig->ka.sa.sa_restorer;
15358 - else
15359 + else if (current->mm->context.vdso)
15360 + /* Return stub is in 32bit vsyscall page */
15361 restorer = current->mm->context.vdso +
15362 selected_vdso32->sym___kernel_rt_sigreturn;
15363 + else
15364 + restorer = frame->retcode;
15365 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
15366
15367 /*
15368 * Not actually used anymore, but left because some gdb
15369 * versions need it.
15370 */
15371 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15372 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15373 } put_user_catch(err);
15374
15375 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
15376 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
15377 index 92a2e93..cd4d95f 100644
15378 --- a/arch/x86/ia32/ia32entry.S
15379 +++ b/arch/x86/ia32/ia32entry.S
15380 @@ -15,8 +15,10 @@
15381 #include <asm/irqflags.h>
15382 #include <asm/asm.h>
15383 #include <asm/smap.h>
15384 +#include <asm/pgtable.h>
15385 #include <linux/linkage.h>
15386 #include <linux/err.h>
15387 +#include <asm/alternative-asm.h>
15388
15389 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15390 #include <linux/elf-em.h>
15391 @@ -62,12 +64,12 @@
15392 */
15393 .macro LOAD_ARGS32 offset, _r9=0
15394 .if \_r9
15395 - movl \offset+16(%rsp),%r9d
15396 + movl \offset+R9(%rsp),%r9d
15397 .endif
15398 - movl \offset+40(%rsp),%ecx
15399 - movl \offset+48(%rsp),%edx
15400 - movl \offset+56(%rsp),%esi
15401 - movl \offset+64(%rsp),%edi
15402 + movl \offset+RCX(%rsp),%ecx
15403 + movl \offset+RDX(%rsp),%edx
15404 + movl \offset+RSI(%rsp),%esi
15405 + movl \offset+RDI(%rsp),%edi
15406 movl %eax,%eax /* zero extension */
15407 .endm
15408
15409 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
15410 ENDPROC(native_irq_enable_sysexit)
15411 #endif
15412
15413 + .macro pax_enter_kernel_user
15414 + pax_set_fptr_mask
15415 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15416 + call pax_enter_kernel_user
15417 +#endif
15418 + .endm
15419 +
15420 + .macro pax_exit_kernel_user
15421 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15422 + call pax_exit_kernel_user
15423 +#endif
15424 +#ifdef CONFIG_PAX_RANDKSTACK
15425 + pushq %rax
15426 + pushq %r11
15427 + call pax_randomize_kstack
15428 + popq %r11
15429 + popq %rax
15430 +#endif
15431 + .endm
15432 +
15433 + .macro pax_erase_kstack
15434 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15435 + call pax_erase_kstack
15436 +#endif
15437 + .endm
15438 +
15439 /*
15440 * 32bit SYSENTER instruction entry.
15441 *
15442 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
15443 CFI_REGISTER rsp,rbp
15444 SWAPGS_UNSAFE_STACK
15445 movq PER_CPU_VAR(kernel_stack), %rsp
15446 - addq $(KERNEL_STACK_OFFSET),%rsp
15447 - /*
15448 - * No need to follow this irqs on/off section: the syscall
15449 - * disabled irqs, here we enable it straight after entry:
15450 - */
15451 - ENABLE_INTERRUPTS(CLBR_NONE)
15452 movl %ebp,%ebp /* zero extension */
15453 pushq_cfi $__USER32_DS
15454 /*CFI_REL_OFFSET ss,0*/
15455 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
15456 CFI_REL_OFFSET rsp,0
15457 pushfq_cfi
15458 /*CFI_REL_OFFSET rflags,0*/
15459 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15460 - CFI_REGISTER rip,r10
15461 + orl $X86_EFLAGS_IF,(%rsp)
15462 + GET_THREAD_INFO(%r11)
15463 + movl TI_sysenter_return(%r11), %r11d
15464 + CFI_REGISTER rip,r11
15465 pushq_cfi $__USER32_CS
15466 /*CFI_REL_OFFSET cs,0*/
15467 movl %eax, %eax
15468 - pushq_cfi %r10
15469 + pushq_cfi %r11
15470 CFI_REL_OFFSET rip,0
15471 pushq_cfi %rax
15472 cld
15473 SAVE_ARGS 0,1,0
15474 + pax_enter_kernel_user
15475 +
15476 +#ifdef CONFIG_PAX_RANDKSTACK
15477 + pax_erase_kstack
15478 +#endif
15479 +
15480 + /*
15481 + * No need to follow this irqs on/off section: the syscall
15482 + * disabled irqs, here we enable it straight after entry:
15483 + */
15484 + ENABLE_INTERRUPTS(CLBR_NONE)
15485 /* no need to do an access_ok check here because rbp has been
15486 32bit zero extended */
15487 +
15488 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15489 + addq pax_user_shadow_base,%rbp
15490 + ASM_PAX_OPEN_USERLAND
15491 +#endif
15492 +
15493 ASM_STAC
15494 1: movl (%rbp),%ebp
15495 _ASM_EXTABLE(1b,ia32_badarg)
15496 ASM_CLAC
15497
15498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15499 + ASM_PAX_CLOSE_USERLAND
15500 +#endif
15501 +
15502 /*
15503 * Sysenter doesn't filter flags, so we need to clear NT
15504 * ourselves. To save a few cycles, we can check whether
15505 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
15506 jnz sysenter_fix_flags
15507 sysenter_flags_fixed:
15508
15509 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15510 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15511 + GET_THREAD_INFO(%r11)
15512 + orl $TS_COMPAT,TI_status(%r11)
15513 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15514 CFI_REMEMBER_STATE
15515 jnz sysenter_tracesys
15516 cmpq $(IA32_NR_syscalls-1),%rax
15517 @@ -172,15 +218,18 @@ sysenter_do_call:
15518 sysenter_dispatch:
15519 call *ia32_sys_call_table(,%rax,8)
15520 movq %rax,RAX-ARGOFFSET(%rsp)
15521 + GET_THREAD_INFO(%r11)
15522 DISABLE_INTERRUPTS(CLBR_NONE)
15523 TRACE_IRQS_OFF
15524 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15525 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15526 jnz sysexit_audit
15527 sysexit_from_sys_call:
15528 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15529 + pax_exit_kernel_user
15530 + pax_erase_kstack
15531 + andl $~TS_COMPAT,TI_status(%r11)
15532 /* clear IF, that popfq doesn't enable interrupts early */
15533 - andl $~0x200,EFLAGS-R11(%rsp)
15534 - movl RIP-R11(%rsp),%edx /* User %eip */
15535 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15536 + movl RIP(%rsp),%edx /* User %eip */
15537 CFI_REGISTER rip,rdx
15538 RESTORE_ARGS 0,24,0,0,0,0
15539 xorq %r8,%r8
15540 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
15541 movl %eax,%esi /* 2nd arg: syscall number */
15542 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15543 call __audit_syscall_entry
15544 +
15545 + pax_erase_kstack
15546 +
15547 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15548 cmpq $(IA32_NR_syscalls-1),%rax
15549 ja ia32_badsys
15550 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
15551 .endm
15552
15553 .macro auditsys_exit exit
15554 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15555 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15556 jnz ia32_ret_from_sys_call
15557 TRACE_IRQS_ON
15558 ENABLE_INTERRUPTS(CLBR_NONE)
15559 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
15560 1: setbe %al /* 1 if error, 0 if not */
15561 movzbl %al,%edi /* zero-extend that into %edi */
15562 call __audit_syscall_exit
15563 + GET_THREAD_INFO(%r11)
15564 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15565 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15566 DISABLE_INTERRUPTS(CLBR_NONE)
15567 TRACE_IRQS_OFF
15568 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15569 + testl %edi,TI_flags(%r11)
15570 jz \exit
15571 CLEAR_RREGS -ARGOFFSET
15572 jmp int_with_check
15573 @@ -253,7 +306,7 @@ sysenter_fix_flags:
15574
15575 sysenter_tracesys:
15576 #ifdef CONFIG_AUDITSYSCALL
15577 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15578 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15579 jz sysenter_auditsys
15580 #endif
15581 SAVE_REST
15582 @@ -265,6 +318,9 @@ sysenter_tracesys:
15583 RESTORE_REST
15584 cmpq $(IA32_NR_syscalls-1),%rax
15585 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15586 +
15587 + pax_erase_kstack
15588 +
15589 jmp sysenter_do_call
15590 CFI_ENDPROC
15591 ENDPROC(ia32_sysenter_target)
15592 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
15593 ENTRY(ia32_cstar_target)
15594 CFI_STARTPROC32 simple
15595 CFI_SIGNAL_FRAME
15596 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15597 + CFI_DEF_CFA rsp,0
15598 CFI_REGISTER rip,rcx
15599 /*CFI_REGISTER rflags,r11*/
15600 SWAPGS_UNSAFE_STACK
15601 movl %esp,%r8d
15602 CFI_REGISTER rsp,r8
15603 movq PER_CPU_VAR(kernel_stack),%rsp
15604 + SAVE_ARGS 8*6,0,0
15605 + pax_enter_kernel_user
15606 +
15607 +#ifdef CONFIG_PAX_RANDKSTACK
15608 + pax_erase_kstack
15609 +#endif
15610 +
15611 /*
15612 * No need to follow this irqs on/off section: the syscall
15613 * disabled irqs and here we enable it straight after entry:
15614 */
15615 ENABLE_INTERRUPTS(CLBR_NONE)
15616 - SAVE_ARGS 8,0,0
15617 movl %eax,%eax /* zero extension */
15618 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15619 movq %rcx,RIP-ARGOFFSET(%rsp)
15620 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
15621 /* no need to do an access_ok check here because r8 has been
15622 32bit zero extended */
15623 /* hardware stack frame is complete now */
15624 +
15625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15626 + ASM_PAX_OPEN_USERLAND
15627 + movq pax_user_shadow_base,%r8
15628 + addq RSP-ARGOFFSET(%rsp),%r8
15629 +#endif
15630 +
15631 ASM_STAC
15632 1: movl (%r8),%r9d
15633 _ASM_EXTABLE(1b,ia32_badarg)
15634 ASM_CLAC
15635 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15636 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15637 +
15638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15639 + ASM_PAX_CLOSE_USERLAND
15640 +#endif
15641 +
15642 + GET_THREAD_INFO(%r11)
15643 + orl $TS_COMPAT,TI_status(%r11)
15644 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15645 CFI_REMEMBER_STATE
15646 jnz cstar_tracesys
15647 cmpq $IA32_NR_syscalls-1,%rax
15648 @@ -335,13 +410,16 @@ cstar_do_call:
15649 cstar_dispatch:
15650 call *ia32_sys_call_table(,%rax,8)
15651 movq %rax,RAX-ARGOFFSET(%rsp)
15652 + GET_THREAD_INFO(%r11)
15653 DISABLE_INTERRUPTS(CLBR_NONE)
15654 TRACE_IRQS_OFF
15655 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15656 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15657 jnz sysretl_audit
15658 sysretl_from_sys_call:
15659 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15660 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15661 + pax_exit_kernel_user
15662 + pax_erase_kstack
15663 + andl $~TS_COMPAT,TI_status(%r11)
15664 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15665 movl RIP-ARGOFFSET(%rsp),%ecx
15666 CFI_REGISTER rip,rcx
15667 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15668 @@ -368,7 +446,7 @@ sysretl_audit:
15669
15670 cstar_tracesys:
15671 #ifdef CONFIG_AUDITSYSCALL
15672 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15673 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15674 jz cstar_auditsys
15675 #endif
15676 xchgl %r9d,%ebp
15677 @@ -382,11 +460,19 @@ cstar_tracesys:
15678 xchgl %ebp,%r9d
15679 cmpq $(IA32_NR_syscalls-1),%rax
15680 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15681 +
15682 + pax_erase_kstack
15683 +
15684 jmp cstar_do_call
15685 END(ia32_cstar_target)
15686
15687 ia32_badarg:
15688 ASM_CLAC
15689 +
15690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15691 + ASM_PAX_CLOSE_USERLAND
15692 +#endif
15693 +
15694 movq $-EFAULT,%rax
15695 jmp ia32_sysret
15696 CFI_ENDPROC
15697 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15698 CFI_REL_OFFSET rip,RIP-RIP
15699 PARAVIRT_ADJUST_EXCEPTION_FRAME
15700 SWAPGS
15701 - /*
15702 - * No need to follow this irqs on/off section: the syscall
15703 - * disabled irqs and here we enable it straight after entry:
15704 - */
15705 - ENABLE_INTERRUPTS(CLBR_NONE)
15706 movl %eax,%eax
15707 pushq_cfi %rax
15708 cld
15709 /* note the registers are not zero extended to the sf.
15710 this could be a problem. */
15711 SAVE_ARGS 0,1,0
15712 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15713 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15714 + pax_enter_kernel_user
15715 +
15716 +#ifdef CONFIG_PAX_RANDKSTACK
15717 + pax_erase_kstack
15718 +#endif
15719 +
15720 + /*
15721 + * No need to follow this irqs on/off section: the syscall
15722 + * disabled irqs and here we enable it straight after entry:
15723 + */
15724 + ENABLE_INTERRUPTS(CLBR_NONE)
15725 + GET_THREAD_INFO(%r11)
15726 + orl $TS_COMPAT,TI_status(%r11)
15727 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15728 jnz ia32_tracesys
15729 cmpq $(IA32_NR_syscalls-1),%rax
15730 ja ia32_badsys
15731 @@ -458,6 +551,9 @@ ia32_tracesys:
15732 RESTORE_REST
15733 cmpq $(IA32_NR_syscalls-1),%rax
15734 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15735 +
15736 + pax_erase_kstack
15737 +
15738 jmp ia32_do_call
15739 END(ia32_syscall)
15740
15741 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15742 index 8e0ceec..af13504 100644
15743 --- a/arch/x86/ia32/sys_ia32.c
15744 +++ b/arch/x86/ia32/sys_ia32.c
15745 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15746 */
15747 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15748 {
15749 - typeof(ubuf->st_uid) uid = 0;
15750 - typeof(ubuf->st_gid) gid = 0;
15751 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15752 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15753 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15754 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15755 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15756 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15757 index 372231c..51b537d 100644
15758 --- a/arch/x86/include/asm/alternative-asm.h
15759 +++ b/arch/x86/include/asm/alternative-asm.h
15760 @@ -18,6 +18,45 @@
15761 .endm
15762 #endif
15763
15764 +#ifdef KERNEXEC_PLUGIN
15765 + .macro pax_force_retaddr_bts rip=0
15766 + btsq $63,\rip(%rsp)
15767 + .endm
15768 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15769 + .macro pax_force_retaddr rip=0, reload=0
15770 + btsq $63,\rip(%rsp)
15771 + .endm
15772 + .macro pax_force_fptr ptr
15773 + btsq $63,\ptr
15774 + .endm
15775 + .macro pax_set_fptr_mask
15776 + .endm
15777 +#endif
15778 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15779 + .macro pax_force_retaddr rip=0, reload=0
15780 + .if \reload
15781 + pax_set_fptr_mask
15782 + .endif
15783 + orq %r12,\rip(%rsp)
15784 + .endm
15785 + .macro pax_force_fptr ptr
15786 + orq %r12,\ptr
15787 + .endm
15788 + .macro pax_set_fptr_mask
15789 + movabs $0x8000000000000000,%r12
15790 + .endm
15791 +#endif
15792 +#else
15793 + .macro pax_force_retaddr rip=0, reload=0
15794 + .endm
15795 + .macro pax_force_fptr ptr
15796 + .endm
15797 + .macro pax_force_retaddr_bts rip=0
15798 + .endm
15799 + .macro pax_set_fptr_mask
15800 + .endm
15801 +#endif
15802 +
15803 .macro altinstruction_entry orig alt feature orig_len alt_len
15804 .long \orig - .
15805 .long \alt - .
15806 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15807 index 473bdbe..b1e3377 100644
15808 --- a/arch/x86/include/asm/alternative.h
15809 +++ b/arch/x86/include/asm/alternative.h
15810 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15811 ".pushsection .discard,\"aw\",@progbits\n" \
15812 DISCARD_ENTRY(1) \
15813 ".popsection\n" \
15814 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15815 + ".pushsection .altinstr_replacement, \"a\"\n" \
15816 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15817 ".popsection"
15818
15819 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15820 DISCARD_ENTRY(1) \
15821 DISCARD_ENTRY(2) \
15822 ".popsection\n" \
15823 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15824 + ".pushsection .altinstr_replacement, \"a\"\n" \
15825 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15826 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15827 ".popsection"
15828 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15829 index 465b309..ab7e51f 100644
15830 --- a/arch/x86/include/asm/apic.h
15831 +++ b/arch/x86/include/asm/apic.h
15832 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15833
15834 #ifdef CONFIG_X86_LOCAL_APIC
15835
15836 -extern unsigned int apic_verbosity;
15837 +extern int apic_verbosity;
15838 extern int local_apic_timer_c2_ok;
15839
15840 extern int disable_apic;
15841 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15842 index 20370c6..a2eb9b0 100644
15843 --- a/arch/x86/include/asm/apm.h
15844 +++ b/arch/x86/include/asm/apm.h
15845 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15846 __asm__ __volatile__(APM_DO_ZERO_SEGS
15847 "pushl %%edi\n\t"
15848 "pushl %%ebp\n\t"
15849 - "lcall *%%cs:apm_bios_entry\n\t"
15850 + "lcall *%%ss:apm_bios_entry\n\t"
15851 "setc %%al\n\t"
15852 "popl %%ebp\n\t"
15853 "popl %%edi\n\t"
15854 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15855 __asm__ __volatile__(APM_DO_ZERO_SEGS
15856 "pushl %%edi\n\t"
15857 "pushl %%ebp\n\t"
15858 - "lcall *%%cs:apm_bios_entry\n\t"
15859 + "lcall *%%ss:apm_bios_entry\n\t"
15860 "setc %%bl\n\t"
15861 "popl %%ebp\n\t"
15862 "popl %%edi\n\t"
15863 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15864 index 6dd1c7dd..2edd216 100644
15865 --- a/arch/x86/include/asm/atomic.h
15866 +++ b/arch/x86/include/asm/atomic.h
15867 @@ -24,7 +24,18 @@
15868 */
15869 static inline int atomic_read(const atomic_t *v)
15870 {
15871 - return (*(volatile int *)&(v)->counter);
15872 + return (*(volatile const int *)&(v)->counter);
15873 +}
15874 +
15875 +/**
15876 + * atomic_read_unchecked - read atomic variable
15877 + * @v: pointer of type atomic_unchecked_t
15878 + *
15879 + * Atomically reads the value of @v.
15880 + */
15881 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15882 +{
15883 + return (*(volatile const int *)&(v)->counter);
15884 }
15885
15886 /**
15887 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15888 }
15889
15890 /**
15891 + * atomic_set_unchecked - set atomic variable
15892 + * @v: pointer of type atomic_unchecked_t
15893 + * @i: required value
15894 + *
15895 + * Atomically sets the value of @v to @i.
15896 + */
15897 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15898 +{
15899 + v->counter = i;
15900 +}
15901 +
15902 +/**
15903 * atomic_add - add integer to atomic variable
15904 * @i: integer value to add
15905 * @v: pointer of type atomic_t
15906 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15907 */
15908 static inline void atomic_add(int i, atomic_t *v)
15909 {
15910 - asm volatile(LOCK_PREFIX "addl %1,%0"
15911 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15912 +
15913 +#ifdef CONFIG_PAX_REFCOUNT
15914 + "jno 0f\n"
15915 + LOCK_PREFIX "subl %1,%0\n"
15916 + "int $4\n0:\n"
15917 + _ASM_EXTABLE(0b, 0b)
15918 +#endif
15919 +
15920 + : "+m" (v->counter)
15921 + : "ir" (i));
15922 +}
15923 +
15924 +/**
15925 + * atomic_add_unchecked - add integer to atomic variable
15926 + * @i: integer value to add
15927 + * @v: pointer of type atomic_unchecked_t
15928 + *
15929 + * Atomically adds @i to @v.
15930 + */
15931 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15932 +{
15933 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15934 : "+m" (v->counter)
15935 : "ir" (i));
15936 }
15937 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15938 */
15939 static inline void atomic_sub(int i, atomic_t *v)
15940 {
15941 - asm volatile(LOCK_PREFIX "subl %1,%0"
15942 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15943 +
15944 +#ifdef CONFIG_PAX_REFCOUNT
15945 + "jno 0f\n"
15946 + LOCK_PREFIX "addl %1,%0\n"
15947 + "int $4\n0:\n"
15948 + _ASM_EXTABLE(0b, 0b)
15949 +#endif
15950 +
15951 + : "+m" (v->counter)
15952 + : "ir" (i));
15953 +}
15954 +
15955 +/**
15956 + * atomic_sub_unchecked - subtract integer from atomic variable
15957 + * @i: integer value to subtract
15958 + * @v: pointer of type atomic_unchecked_t
15959 + *
15960 + * Atomically subtracts @i from @v.
15961 + */
15962 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15963 +{
15964 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15965 : "+m" (v->counter)
15966 : "ir" (i));
15967 }
15968 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15969 */
15970 static inline int atomic_sub_and_test(int i, atomic_t *v)
15971 {
15972 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15973 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15974 }
15975
15976 /**
15977 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15978 */
15979 static inline void atomic_inc(atomic_t *v)
15980 {
15981 - asm volatile(LOCK_PREFIX "incl %0"
15982 + asm volatile(LOCK_PREFIX "incl %0\n"
15983 +
15984 +#ifdef CONFIG_PAX_REFCOUNT
15985 + "jno 0f\n"
15986 + LOCK_PREFIX "decl %0\n"
15987 + "int $4\n0:\n"
15988 + _ASM_EXTABLE(0b, 0b)
15989 +#endif
15990 +
15991 + : "+m" (v->counter));
15992 +}
15993 +
15994 +/**
15995 + * atomic_inc_unchecked - increment atomic variable
15996 + * @v: pointer of type atomic_unchecked_t
15997 + *
15998 + * Atomically increments @v by 1.
15999 + */
16000 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
16001 +{
16002 + asm volatile(LOCK_PREFIX "incl %0\n"
16003 : "+m" (v->counter));
16004 }
16005
16006 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
16007 */
16008 static inline void atomic_dec(atomic_t *v)
16009 {
16010 - asm volatile(LOCK_PREFIX "decl %0"
16011 + asm volatile(LOCK_PREFIX "decl %0\n"
16012 +
16013 +#ifdef CONFIG_PAX_REFCOUNT
16014 + "jno 0f\n"
16015 + LOCK_PREFIX "incl %0\n"
16016 + "int $4\n0:\n"
16017 + _ASM_EXTABLE(0b, 0b)
16018 +#endif
16019 +
16020 + : "+m" (v->counter));
16021 +}
16022 +
16023 +/**
16024 + * atomic_dec_unchecked - decrement atomic variable
16025 + * @v: pointer of type atomic_unchecked_t
16026 + *
16027 + * Atomically decrements @v by 1.
16028 + */
16029 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
16030 +{
16031 + asm volatile(LOCK_PREFIX "decl %0\n"
16032 : "+m" (v->counter));
16033 }
16034
16035 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
16036 */
16037 static inline int atomic_dec_and_test(atomic_t *v)
16038 {
16039 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
16040 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
16041 }
16042
16043 /**
16044 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
16045 */
16046 static inline int atomic_inc_and_test(atomic_t *v)
16047 {
16048 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
16049 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
16050 +}
16051 +
16052 +/**
16053 + * atomic_inc_and_test_unchecked - increment and test
16054 + * @v: pointer of type atomic_unchecked_t
16055 + *
16056 + * Atomically increments @v by 1
16057 + * and returns true if the result is zero, or false for all
16058 + * other cases.
16059 + */
16060 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
16061 +{
16062 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
16063 }
16064
16065 /**
16066 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
16067 */
16068 static inline int atomic_add_negative(int i, atomic_t *v)
16069 {
16070 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
16071 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
16072 }
16073
16074 /**
16075 @@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
16076 */
16077 static inline int atomic_add_return(int i, atomic_t *v)
16078 {
16079 + return i + xadd_check_overflow(&v->counter, i);
16080 +}
16081 +
16082 +/**
16083 + * atomic_add_return_unchecked - add integer and return
16084 + * @i: integer value to add
16085 + * @v: pointer of type atomic_unchecked_t
16086 + *
16087 + * Atomically adds @i to @v and returns @i + @v
16088 + */
16089 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
16090 +{
16091 return i + xadd(&v->counter, i);
16092 }
16093
16094 @@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
16095 }
16096
16097 #define atomic_inc_return(v) (atomic_add_return(1, v))
16098 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
16099 +{
16100 + return atomic_add_return_unchecked(1, v);
16101 +}
16102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
16103
16104 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
16105 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
16106 +{
16107 + return cmpxchg(&v->counter, old, new);
16108 +}
16109 +
16110 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
16111 {
16112 return cmpxchg(&v->counter, old, new);
16113 }
16114 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
16115 return xchg(&v->counter, new);
16116 }
16117
16118 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
16119 +{
16120 + return xchg(&v->counter, new);
16121 +}
16122 +
16123 /**
16124 * __atomic_add_unless - add unless the number is already a given value
16125 * @v: pointer of type atomic_t
16126 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
16127 * Atomically adds @a to @v, so long as @v was not already @u.
16128 * Returns the old value of @v.
16129 */
16130 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16131 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
16132 {
16133 - int c, old;
16134 + int c, old, new;
16135 c = atomic_read(v);
16136 for (;;) {
16137 - if (unlikely(c == (u)))
16138 + if (unlikely(c == u))
16139 break;
16140 - old = atomic_cmpxchg((v), c, c + (a));
16141 +
16142 + asm volatile("addl %2,%0\n"
16143 +
16144 +#ifdef CONFIG_PAX_REFCOUNT
16145 + "jno 0f\n"
16146 + "subl %2,%0\n"
16147 + "int $4\n0:\n"
16148 + _ASM_EXTABLE(0b, 0b)
16149 +#endif
16150 +
16151 + : "=r" (new)
16152 + : "0" (c), "ir" (a));
16153 +
16154 + old = atomic_cmpxchg(v, c, new);
16155 if (likely(old == c))
16156 break;
16157 c = old;
16158 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16159 }
16160
16161 /**
16162 + * atomic_inc_not_zero_hint - increment if not null
16163 + * @v: pointer of type atomic_t
16164 + * @hint: probable value of the atomic before the increment
16165 + *
16166 + * This version of atomic_inc_not_zero() gives a hint of probable
16167 + * value of the atomic. This helps processor to not read the memory
16168 + * before doing the atomic read/modify/write cycle, lowering
16169 + * number of bus transactions on some arches.
16170 + *
16171 + * Returns: 0 if increment was not done, 1 otherwise.
16172 + */
16173 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
16174 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
16175 +{
16176 + int val, c = hint, new;
16177 +
16178 + /* sanity test, should be removed by compiler if hint is a constant */
16179 + if (!hint)
16180 + return __atomic_add_unless(v, 1, 0);
16181 +
16182 + do {
16183 + asm volatile("incl %0\n"
16184 +
16185 +#ifdef CONFIG_PAX_REFCOUNT
16186 + "jno 0f\n"
16187 + "decl %0\n"
16188 + "int $4\n0:\n"
16189 + _ASM_EXTABLE(0b, 0b)
16190 +#endif
16191 +
16192 + : "=r" (new)
16193 + : "0" (c));
16194 +
16195 + val = atomic_cmpxchg(v, c, new);
16196 + if (val == c)
16197 + return 1;
16198 + c = val;
16199 + } while (c);
16200 +
16201 + return 0;
16202 +}
16203 +
16204 +/**
16205 * atomic_inc_short - increment of a short integer
16206 * @v: pointer to type int
16207 *
16208 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
16209 #endif
16210
16211 /* These are x86-specific, used by some header files */
16212 -#define atomic_clear_mask(mask, addr) \
16213 - asm volatile(LOCK_PREFIX "andl %0,%1" \
16214 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
16215 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
16216 +{
16217 + asm volatile(LOCK_PREFIX "andl %1,%0"
16218 + : "+m" (v->counter)
16219 + : "r" (~(mask))
16220 + : "memory");
16221 +}
16222
16223 -#define atomic_set_mask(mask, addr) \
16224 - asm volatile(LOCK_PREFIX "orl %0,%1" \
16225 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
16226 - : "memory")
16227 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16228 +{
16229 + asm volatile(LOCK_PREFIX "andl %1,%0"
16230 + : "+m" (v->counter)
16231 + : "r" (~(mask))
16232 + : "memory");
16233 +}
16234 +
16235 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
16236 +{
16237 + asm volatile(LOCK_PREFIX "orl %1,%0"
16238 + : "+m" (v->counter)
16239 + : "r" (mask)
16240 + : "memory");
16241 +}
16242 +
16243 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16244 +{
16245 + asm volatile(LOCK_PREFIX "orl %1,%0"
16246 + : "+m" (v->counter)
16247 + : "r" (mask)
16248 + : "memory");
16249 +}
16250
16251 #ifdef CONFIG_X86_32
16252 # include <asm/atomic64_32.h>
16253 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
16254 index b154de7..bf18a5a 100644
16255 --- a/arch/x86/include/asm/atomic64_32.h
16256 +++ b/arch/x86/include/asm/atomic64_32.h
16257 @@ -12,6 +12,14 @@ typedef struct {
16258 u64 __aligned(8) counter;
16259 } atomic64_t;
16260
16261 +#ifdef CONFIG_PAX_REFCOUNT
16262 +typedef struct {
16263 + u64 __aligned(8) counter;
16264 +} atomic64_unchecked_t;
16265 +#else
16266 +typedef atomic64_t atomic64_unchecked_t;
16267 +#endif
16268 +
16269 #define ATOMIC64_INIT(val) { (val) }
16270
16271 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
16272 @@ -37,21 +45,31 @@ typedef struct {
16273 ATOMIC64_DECL_ONE(sym##_386)
16274
16275 ATOMIC64_DECL_ONE(add_386);
16276 +ATOMIC64_DECL_ONE(add_unchecked_386);
16277 ATOMIC64_DECL_ONE(sub_386);
16278 +ATOMIC64_DECL_ONE(sub_unchecked_386);
16279 ATOMIC64_DECL_ONE(inc_386);
16280 +ATOMIC64_DECL_ONE(inc_unchecked_386);
16281 ATOMIC64_DECL_ONE(dec_386);
16282 +ATOMIC64_DECL_ONE(dec_unchecked_386);
16283 #endif
16284
16285 #define alternative_atomic64(f, out, in...) \
16286 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
16287
16288 ATOMIC64_DECL(read);
16289 +ATOMIC64_DECL(read_unchecked);
16290 ATOMIC64_DECL(set);
16291 +ATOMIC64_DECL(set_unchecked);
16292 ATOMIC64_DECL(xchg);
16293 ATOMIC64_DECL(add_return);
16294 +ATOMIC64_DECL(add_return_unchecked);
16295 ATOMIC64_DECL(sub_return);
16296 +ATOMIC64_DECL(sub_return_unchecked);
16297 ATOMIC64_DECL(inc_return);
16298 +ATOMIC64_DECL(inc_return_unchecked);
16299 ATOMIC64_DECL(dec_return);
16300 +ATOMIC64_DECL(dec_return_unchecked);
16301 ATOMIC64_DECL(dec_if_positive);
16302 ATOMIC64_DECL(inc_not_zero);
16303 ATOMIC64_DECL(add_unless);
16304 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
16305 }
16306
16307 /**
16308 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
16309 + * @p: pointer to type atomic64_unchecked_t
16310 + * @o: expected value
16311 + * @n: new value
16312 + *
16313 + * Atomically sets @v to @n if it was equal to @o and returns
16314 + * the old value.
16315 + */
16316 +
16317 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
16318 +{
16319 + return cmpxchg64(&v->counter, o, n);
16320 +}
16321 +
16322 +/**
16323 * atomic64_xchg - xchg atomic64 variable
16324 * @v: pointer to type atomic64_t
16325 * @n: value to assign
16326 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
16327 }
16328
16329 /**
16330 + * atomic64_set_unchecked - set atomic64 variable
16331 + * @v: pointer to type atomic64_unchecked_t
16332 + * @n: value to assign
16333 + *
16334 + * Atomically sets the value of @v to @n.
16335 + */
16336 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
16337 +{
16338 + unsigned high = (unsigned)(i >> 32);
16339 + unsigned low = (unsigned)i;
16340 + alternative_atomic64(set, /* no output */,
16341 + "S" (v), "b" (low), "c" (high)
16342 + : "eax", "edx", "memory");
16343 +}
16344 +
16345 +/**
16346 * atomic64_read - read atomic64 variable
16347 * @v: pointer to type atomic64_t
16348 *
16349 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
16350 }
16351
16352 /**
16353 + * atomic64_read_unchecked - read atomic64 variable
16354 + * @v: pointer to type atomic64_unchecked_t
16355 + *
16356 + * Atomically reads the value of @v and returns it.
16357 + */
16358 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
16359 +{
16360 + long long r;
16361 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
16362 + return r;
16363 + }
16364 +
16365 +/**
16366 * atomic64_add_return - add and return
16367 * @i: integer value to add
16368 * @v: pointer to type atomic64_t
16369 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
16370 return i;
16371 }
16372
16373 +/**
16374 + * atomic64_add_return_unchecked - add and return
16375 + * @i: integer value to add
16376 + * @v: pointer to type atomic64_unchecked_t
16377 + *
16378 + * Atomically adds @i to @v and returns @i + *@v
16379 + */
16380 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
16381 +{
16382 + alternative_atomic64(add_return_unchecked,
16383 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16384 + ASM_NO_INPUT_CLOBBER("memory"));
16385 + return i;
16386 +}
16387 +
16388 /*
16389 * Other variants with different arithmetic operators:
16390 */
16391 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
16392 return a;
16393 }
16394
16395 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16396 +{
16397 + long long a;
16398 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
16399 + "S" (v) : "memory", "ecx");
16400 + return a;
16401 +}
16402 +
16403 static inline long long atomic64_dec_return(atomic64_t *v)
16404 {
16405 long long a;
16406 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
16407 }
16408
16409 /**
16410 + * atomic64_add_unchecked - add integer to atomic64 variable
16411 + * @i: integer value to add
16412 + * @v: pointer to type atomic64_unchecked_t
16413 + *
16414 + * Atomically adds @i to @v.
16415 + */
16416 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
16417 +{
16418 + __alternative_atomic64(add_unchecked, add_return_unchecked,
16419 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16420 + ASM_NO_INPUT_CLOBBER("memory"));
16421 + return i;
16422 +}
16423 +
16424 +/**
16425 * atomic64_sub - subtract the atomic64 variable
16426 * @i: integer value to subtract
16427 * @v: pointer to type atomic64_t
16428 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
16429 index 46e9052..ae45136 100644
16430 --- a/arch/x86/include/asm/atomic64_64.h
16431 +++ b/arch/x86/include/asm/atomic64_64.h
16432 @@ -18,7 +18,19 @@
16433 */
16434 static inline long atomic64_read(const atomic64_t *v)
16435 {
16436 - return (*(volatile long *)&(v)->counter);
16437 + return (*(volatile const long *)&(v)->counter);
16438 +}
16439 +
16440 +/**
16441 + * atomic64_read_unchecked - read atomic64 variable
16442 + * @v: pointer of type atomic64_unchecked_t
16443 + *
16444 + * Atomically reads the value of @v.
16445 + * Doesn't imply a read memory barrier.
16446 + */
16447 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
16448 +{
16449 + return (*(volatile const long *)&(v)->counter);
16450 }
16451
16452 /**
16453 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
16454 }
16455
16456 /**
16457 + * atomic64_set_unchecked - set atomic64 variable
16458 + * @v: pointer to type atomic64_unchecked_t
16459 + * @i: required value
16460 + *
16461 + * Atomically sets the value of @v to @i.
16462 + */
16463 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
16464 +{
16465 + v->counter = i;
16466 +}
16467 +
16468 +/**
16469 * atomic64_add - add integer to atomic64 variable
16470 * @i: integer value to add
16471 * @v: pointer to type atomic64_t
16472 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16473 */
16474 static inline void atomic64_add(long i, atomic64_t *v)
16475 {
16476 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
16477 +
16478 +#ifdef CONFIG_PAX_REFCOUNT
16479 + "jno 0f\n"
16480 + LOCK_PREFIX "subq %1,%0\n"
16481 + "int $4\n0:\n"
16482 + _ASM_EXTABLE(0b, 0b)
16483 +#endif
16484 +
16485 + : "=m" (v->counter)
16486 + : "er" (i), "m" (v->counter));
16487 +}
16488 +
16489 +/**
16490 + * atomic64_add_unchecked - add integer to atomic64 variable
16491 + * @i: integer value to add
16492 + * @v: pointer to type atomic64_unchecked_t
16493 + *
16494 + * Atomically adds @i to @v.
16495 + */
16496 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16497 +{
16498 asm volatile(LOCK_PREFIX "addq %1,%0"
16499 : "=m" (v->counter)
16500 : "er" (i), "m" (v->counter));
16501 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16502 */
16503 static inline void atomic64_sub(long i, atomic64_t *v)
16504 {
16505 - asm volatile(LOCK_PREFIX "subq %1,%0"
16506 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16507 +
16508 +#ifdef CONFIG_PAX_REFCOUNT
16509 + "jno 0f\n"
16510 + LOCK_PREFIX "addq %1,%0\n"
16511 + "int $4\n0:\n"
16512 + _ASM_EXTABLE(0b, 0b)
16513 +#endif
16514 +
16515 + : "=m" (v->counter)
16516 + : "er" (i), "m" (v->counter));
16517 +}
16518 +
16519 +/**
16520 + * atomic64_sub_unchecked - subtract the atomic64 variable
16521 + * @i: integer value to subtract
16522 + * @v: pointer to type atomic64_unchecked_t
16523 + *
16524 + * Atomically subtracts @i from @v.
16525 + */
16526 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16527 +{
16528 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16529 : "=m" (v->counter)
16530 : "er" (i), "m" (v->counter));
16531 }
16532 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16533 */
16534 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16535 {
16536 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16537 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16538 }
16539
16540 /**
16541 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16542 */
16543 static inline void atomic64_inc(atomic64_t *v)
16544 {
16545 + asm volatile(LOCK_PREFIX "incq %0\n"
16546 +
16547 +#ifdef CONFIG_PAX_REFCOUNT
16548 + "jno 0f\n"
16549 + LOCK_PREFIX "decq %0\n"
16550 + "int $4\n0:\n"
16551 + _ASM_EXTABLE(0b, 0b)
16552 +#endif
16553 +
16554 + : "=m" (v->counter)
16555 + : "m" (v->counter));
16556 +}
16557 +
16558 +/**
16559 + * atomic64_inc_unchecked - increment atomic64 variable
16560 + * @v: pointer to type atomic64_unchecked_t
16561 + *
16562 + * Atomically increments @v by 1.
16563 + */
16564 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16565 +{
16566 asm volatile(LOCK_PREFIX "incq %0"
16567 : "=m" (v->counter)
16568 : "m" (v->counter));
16569 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16570 */
16571 static inline void atomic64_dec(atomic64_t *v)
16572 {
16573 - asm volatile(LOCK_PREFIX "decq %0"
16574 + asm volatile(LOCK_PREFIX "decq %0\n"
16575 +
16576 +#ifdef CONFIG_PAX_REFCOUNT
16577 + "jno 0f\n"
16578 + LOCK_PREFIX "incq %0\n"
16579 + "int $4\n0:\n"
16580 + _ASM_EXTABLE(0b, 0b)
16581 +#endif
16582 +
16583 + : "=m" (v->counter)
16584 + : "m" (v->counter));
16585 +}
16586 +
16587 +/**
16588 + * atomic64_dec_unchecked - decrement atomic64 variable
16589 + * @v: pointer to type atomic64_t
16590 + *
16591 + * Atomically decrements @v by 1.
16592 + */
16593 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16594 +{
16595 + asm volatile(LOCK_PREFIX "decq %0\n"
16596 : "=m" (v->counter)
16597 : "m" (v->counter));
16598 }
16599 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16600 */
16601 static inline int atomic64_dec_and_test(atomic64_t *v)
16602 {
16603 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16604 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16605 }
16606
16607 /**
16608 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16609 */
16610 static inline int atomic64_inc_and_test(atomic64_t *v)
16611 {
16612 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16613 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16614 }
16615
16616 /**
16617 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16618 */
16619 static inline int atomic64_add_negative(long i, atomic64_t *v)
16620 {
16621 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16622 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16623 }
16624
16625 /**
16626 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16627 */
16628 static inline long atomic64_add_return(long i, atomic64_t *v)
16629 {
16630 + return i + xadd_check_overflow(&v->counter, i);
16631 +}
16632 +
16633 +/**
16634 + * atomic64_add_return_unchecked - add and return
16635 + * @i: integer value to add
16636 + * @v: pointer to type atomic64_unchecked_t
16637 + *
16638 + * Atomically adds @i to @v and returns @i + @v
16639 + */
16640 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16641 +{
16642 return i + xadd(&v->counter, i);
16643 }
16644
16645 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16646 }
16647
16648 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16649 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16650 +{
16651 + return atomic64_add_return_unchecked(1, v);
16652 +}
16653 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16654
16655 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16656 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16657 return cmpxchg(&v->counter, old, new);
16658 }
16659
16660 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16661 +{
16662 + return cmpxchg(&v->counter, old, new);
16663 +}
16664 +
16665 static inline long atomic64_xchg(atomic64_t *v, long new)
16666 {
16667 return xchg(&v->counter, new);
16668 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16669 */
16670 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16671 {
16672 - long c, old;
16673 + long c, old, new;
16674 c = atomic64_read(v);
16675 for (;;) {
16676 - if (unlikely(c == (u)))
16677 + if (unlikely(c == u))
16678 break;
16679 - old = atomic64_cmpxchg((v), c, c + (a));
16680 +
16681 + asm volatile("add %2,%0\n"
16682 +
16683 +#ifdef CONFIG_PAX_REFCOUNT
16684 + "jno 0f\n"
16685 + "sub %2,%0\n"
16686 + "int $4\n0:\n"
16687 + _ASM_EXTABLE(0b, 0b)
16688 +#endif
16689 +
16690 + : "=r" (new)
16691 + : "0" (c), "ir" (a));
16692 +
16693 + old = atomic64_cmpxchg(v, c, new);
16694 if (likely(old == c))
16695 break;
16696 c = old;
16697 }
16698 - return c != (u);
16699 + return c != u;
16700 }
16701
16702 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16703 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16704 index 0f4460b..fa1ee19 100644
16705 --- a/arch/x86/include/asm/barrier.h
16706 +++ b/arch/x86/include/asm/barrier.h
16707 @@ -107,7 +107,7 @@
16708 do { \
16709 compiletime_assert_atomic_type(*p); \
16710 smp_mb(); \
16711 - ACCESS_ONCE(*p) = (v); \
16712 + ACCESS_ONCE_RW(*p) = (v); \
16713 } while (0)
16714
16715 #define smp_load_acquire(p) \
16716 @@ -124,7 +124,7 @@ do { \
16717 do { \
16718 compiletime_assert_atomic_type(*p); \
16719 barrier(); \
16720 - ACCESS_ONCE(*p) = (v); \
16721 + ACCESS_ONCE_RW(*p) = (v); \
16722 } while (0)
16723
16724 #define smp_load_acquire(p) \
16725 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16726 index cfe3b95..d01b118 100644
16727 --- a/arch/x86/include/asm/bitops.h
16728 +++ b/arch/x86/include/asm/bitops.h
16729 @@ -50,7 +50,7 @@
16730 * a mask operation on a byte.
16731 */
16732 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16733 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16734 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16735 #define CONST_MASK(nr) (1 << ((nr) & 7))
16736
16737 /**
16738 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16739 */
16740 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16741 {
16742 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16743 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16744 }
16745
16746 /**
16747 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16748 */
16749 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16750 {
16751 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16752 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16753 }
16754
16755 /**
16756 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16757 */
16758 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16759 {
16760 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16761 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16762 }
16763
16764 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16765 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16766 *
16767 * Undefined if no bit exists, so code should check against 0 first.
16768 */
16769 -static inline unsigned long __ffs(unsigned long word)
16770 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16771 {
16772 asm("rep; bsf %1,%0"
16773 : "=r" (word)
16774 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16775 *
16776 * Undefined if no zero exists, so code should check against ~0UL first.
16777 */
16778 -static inline unsigned long ffz(unsigned long word)
16779 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16780 {
16781 asm("rep; bsf %1,%0"
16782 : "=r" (word)
16783 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16784 *
16785 * Undefined if no set bit exists, so code should check against 0 first.
16786 */
16787 -static inline unsigned long __fls(unsigned long word)
16788 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16789 {
16790 asm("bsr %1,%0"
16791 : "=r" (word)
16792 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16793 * set bit if value is nonzero. The last (most significant) bit is
16794 * at position 32.
16795 */
16796 -static inline int fls(int x)
16797 +static inline int __intentional_overflow(-1) fls(int x)
16798 {
16799 int r;
16800
16801 @@ -476,7 +476,7 @@ static inline int fls(int x)
16802 * at position 64.
16803 */
16804 #ifdef CONFIG_X86_64
16805 -static __always_inline int fls64(__u64 x)
16806 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16807 {
16808 int bitpos = -1;
16809 /*
16810 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16811 index 4fa687a..60f2d39 100644
16812 --- a/arch/x86/include/asm/boot.h
16813 +++ b/arch/x86/include/asm/boot.h
16814 @@ -6,10 +6,15 @@
16815 #include <uapi/asm/boot.h>
16816
16817 /* Physical address where kernel should be loaded. */
16818 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16819 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16820 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16821 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16822
16823 +#ifndef __ASSEMBLY__
16824 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16825 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16826 +#endif
16827 +
16828 /* Minimum kernel alignment, as a power of two */
16829 #ifdef CONFIG_X86_64
16830 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16831 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16832 index 48f99f1..d78ebf9 100644
16833 --- a/arch/x86/include/asm/cache.h
16834 +++ b/arch/x86/include/asm/cache.h
16835 @@ -5,12 +5,13 @@
16836
16837 /* L1 cache line size */
16838 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16839 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16840 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16841
16842 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16843 +#define __read_only __attribute__((__section__(".data..read_only")))
16844
16845 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16846 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16847 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16848
16849 #ifdef CONFIG_X86_VSMP
16850 #ifdef CONFIG_SMP
16851 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16852 index 9863ee3..4a1f8e1 100644
16853 --- a/arch/x86/include/asm/cacheflush.h
16854 +++ b/arch/x86/include/asm/cacheflush.h
16855 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16856 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16857
16858 if (pg_flags == _PGMT_DEFAULT)
16859 - return -1;
16860 + return ~0UL;
16861 else if (pg_flags == _PGMT_WC)
16862 return _PAGE_CACHE_WC;
16863 else if (pg_flags == _PGMT_UC_MINUS)
16864 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16865 index cb4c73b..c473c29 100644
16866 --- a/arch/x86/include/asm/calling.h
16867 +++ b/arch/x86/include/asm/calling.h
16868 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16869 #define RSP 152
16870 #define SS 160
16871
16872 -#define ARGOFFSET R11
16873 -#define SWFRAME ORIG_RAX
16874 +#define ARGOFFSET R15
16875
16876 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16877 - subq $9*8+\addskip, %rsp
16878 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16879 - movq_cfi rdi, 8*8
16880 - movq_cfi rsi, 7*8
16881 - movq_cfi rdx, 6*8
16882 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16883 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16884 + movq_cfi rdi, RDI
16885 + movq_cfi rsi, RSI
16886 + movq_cfi rdx, RDX
16887
16888 .if \save_rcx
16889 - movq_cfi rcx, 5*8
16890 + movq_cfi rcx, RCX
16891 .endif
16892
16893 - movq_cfi rax, 4*8
16894 + movq_cfi rax, RAX
16895
16896 .if \save_r891011
16897 - movq_cfi r8, 3*8
16898 - movq_cfi r9, 2*8
16899 - movq_cfi r10, 1*8
16900 - movq_cfi r11, 0*8
16901 + movq_cfi r8, R8
16902 + movq_cfi r9, R9
16903 + movq_cfi r10, R10
16904 + movq_cfi r11, R11
16905 .endif
16906
16907 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16908 + movq_cfi r12, R12
16909 +#endif
16910 +
16911 .endm
16912
16913 -#define ARG_SKIP (9*8)
16914 +#define ARG_SKIP ORIG_RAX
16915
16916 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16917 rstor_r8910=1, rstor_rdx=1
16918 +
16919 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16920 + movq_cfi_restore R12, r12
16921 +#endif
16922 +
16923 .if \rstor_r11
16924 - movq_cfi_restore 0*8, r11
16925 + movq_cfi_restore R11, r11
16926 .endif
16927
16928 .if \rstor_r8910
16929 - movq_cfi_restore 1*8, r10
16930 - movq_cfi_restore 2*8, r9
16931 - movq_cfi_restore 3*8, r8
16932 + movq_cfi_restore R10, r10
16933 + movq_cfi_restore R9, r9
16934 + movq_cfi_restore R8, r8
16935 .endif
16936
16937 .if \rstor_rax
16938 - movq_cfi_restore 4*8, rax
16939 + movq_cfi_restore RAX, rax
16940 .endif
16941
16942 .if \rstor_rcx
16943 - movq_cfi_restore 5*8, rcx
16944 + movq_cfi_restore RCX, rcx
16945 .endif
16946
16947 .if \rstor_rdx
16948 - movq_cfi_restore 6*8, rdx
16949 + movq_cfi_restore RDX, rdx
16950 .endif
16951
16952 - movq_cfi_restore 7*8, rsi
16953 - movq_cfi_restore 8*8, rdi
16954 + movq_cfi_restore RSI, rsi
16955 + movq_cfi_restore RDI, rdi
16956
16957 - .if ARG_SKIP+\addskip > 0
16958 - addq $ARG_SKIP+\addskip, %rsp
16959 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16960 + .if ORIG_RAX+\addskip > 0
16961 + addq $ORIG_RAX+\addskip, %rsp
16962 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16963 .endif
16964 .endm
16965
16966 - .macro LOAD_ARGS offset, skiprax=0
16967 - movq \offset(%rsp), %r11
16968 - movq \offset+8(%rsp), %r10
16969 - movq \offset+16(%rsp), %r9
16970 - movq \offset+24(%rsp), %r8
16971 - movq \offset+40(%rsp), %rcx
16972 - movq \offset+48(%rsp), %rdx
16973 - movq \offset+56(%rsp), %rsi
16974 - movq \offset+64(%rsp), %rdi
16975 + .macro LOAD_ARGS skiprax=0
16976 + movq R11(%rsp), %r11
16977 + movq R10(%rsp), %r10
16978 + movq R9(%rsp), %r9
16979 + movq R8(%rsp), %r8
16980 + movq RCX(%rsp), %rcx
16981 + movq RDX(%rsp), %rdx
16982 + movq RSI(%rsp), %rsi
16983 + movq RDI(%rsp), %rdi
16984 .if \skiprax
16985 .else
16986 - movq \offset+72(%rsp), %rax
16987 + movq RAX(%rsp), %rax
16988 .endif
16989 .endm
16990
16991 -#define REST_SKIP (6*8)
16992 -
16993 .macro SAVE_REST
16994 - subq $REST_SKIP, %rsp
16995 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16996 - movq_cfi rbx, 5*8
16997 - movq_cfi rbp, 4*8
16998 - movq_cfi r12, 3*8
16999 - movq_cfi r13, 2*8
17000 - movq_cfi r14, 1*8
17001 - movq_cfi r15, 0*8
17002 + movq_cfi rbx, RBX
17003 + movq_cfi rbp, RBP
17004 +
17005 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17006 + movq_cfi r12, R12
17007 +#endif
17008 +
17009 + movq_cfi r13, R13
17010 + movq_cfi r14, R14
17011 + movq_cfi r15, R15
17012 .endm
17013
17014 .macro RESTORE_REST
17015 - movq_cfi_restore 0*8, r15
17016 - movq_cfi_restore 1*8, r14
17017 - movq_cfi_restore 2*8, r13
17018 - movq_cfi_restore 3*8, r12
17019 - movq_cfi_restore 4*8, rbp
17020 - movq_cfi_restore 5*8, rbx
17021 - addq $REST_SKIP, %rsp
17022 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
17023 + movq_cfi_restore R15, r15
17024 + movq_cfi_restore R14, r14
17025 + movq_cfi_restore R13, r13
17026 +
17027 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17028 + movq_cfi_restore R12, r12
17029 +#endif
17030 +
17031 + movq_cfi_restore RBP, rbp
17032 + movq_cfi_restore RBX, rbx
17033 .endm
17034
17035 .macro SAVE_ALL
17036 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
17037 index f50de69..2b0a458 100644
17038 --- a/arch/x86/include/asm/checksum_32.h
17039 +++ b/arch/x86/include/asm/checksum_32.h
17040 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
17041 int len, __wsum sum,
17042 int *src_err_ptr, int *dst_err_ptr);
17043
17044 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
17045 + int len, __wsum sum,
17046 + int *src_err_ptr, int *dst_err_ptr);
17047 +
17048 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
17049 + int len, __wsum sum,
17050 + int *src_err_ptr, int *dst_err_ptr);
17051 +
17052 /*
17053 * Note: when you get a NULL pointer exception here this means someone
17054 * passed in an incorrect kernel address to one of these functions.
17055 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
17056
17057 might_sleep();
17058 stac();
17059 - ret = csum_partial_copy_generic((__force void *)src, dst,
17060 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
17061 len, sum, err_ptr, NULL);
17062 clac();
17063
17064 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
17065 might_sleep();
17066 if (access_ok(VERIFY_WRITE, dst, len)) {
17067 stac();
17068 - ret = csum_partial_copy_generic(src, (__force void *)dst,
17069 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
17070 len, sum, NULL, err_ptr);
17071 clac();
17072 return ret;
17073 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
17074 index 99c105d7..2f667ac 100644
17075 --- a/arch/x86/include/asm/cmpxchg.h
17076 +++ b/arch/x86/include/asm/cmpxchg.h
17077 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
17078 __compiletime_error("Bad argument size for cmpxchg");
17079 extern void __xadd_wrong_size(void)
17080 __compiletime_error("Bad argument size for xadd");
17081 +extern void __xadd_check_overflow_wrong_size(void)
17082 + __compiletime_error("Bad argument size for xadd_check_overflow");
17083 extern void __add_wrong_size(void)
17084 __compiletime_error("Bad argument size for add");
17085 +extern void __add_check_overflow_wrong_size(void)
17086 + __compiletime_error("Bad argument size for add_check_overflow");
17087
17088 /*
17089 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
17090 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
17091 __ret; \
17092 })
17093
17094 +#ifdef CONFIG_PAX_REFCOUNT
17095 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
17096 + ({ \
17097 + __typeof__ (*(ptr)) __ret = (arg); \
17098 + switch (sizeof(*(ptr))) { \
17099 + case __X86_CASE_L: \
17100 + asm volatile (lock #op "l %0, %1\n" \
17101 + "jno 0f\n" \
17102 + "mov %0,%1\n" \
17103 + "int $4\n0:\n" \
17104 + _ASM_EXTABLE(0b, 0b) \
17105 + : "+r" (__ret), "+m" (*(ptr)) \
17106 + : : "memory", "cc"); \
17107 + break; \
17108 + case __X86_CASE_Q: \
17109 + asm volatile (lock #op "q %q0, %1\n" \
17110 + "jno 0f\n" \
17111 + "mov %0,%1\n" \
17112 + "int $4\n0:\n" \
17113 + _ASM_EXTABLE(0b, 0b) \
17114 + : "+r" (__ret), "+m" (*(ptr)) \
17115 + : : "memory", "cc"); \
17116 + break; \
17117 + default: \
17118 + __ ## op ## _check_overflow_wrong_size(); \
17119 + } \
17120 + __ret; \
17121 + })
17122 +#else
17123 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
17124 +#endif
17125 +
17126 /*
17127 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
17128 * Since this is generally used to protect other memory information, we
17129 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
17130 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
17131 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
17132
17133 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
17134 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
17135 +
17136 #define __add(ptr, inc, lock) \
17137 ({ \
17138 __typeof__ (*(ptr)) __ret = (inc); \
17139 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
17140 index 59c6c40..5e0b22c 100644
17141 --- a/arch/x86/include/asm/compat.h
17142 +++ b/arch/x86/include/asm/compat.h
17143 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
17144 typedef u32 compat_uint_t;
17145 typedef u32 compat_ulong_t;
17146 typedef u64 __attribute__((aligned(4))) compat_u64;
17147 -typedef u32 compat_uptr_t;
17148 +typedef u32 __user compat_uptr_t;
17149
17150 struct compat_timespec {
17151 compat_time_t tv_sec;
17152 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
17153 index bb9b258..5fad1bf 100644
17154 --- a/arch/x86/include/asm/cpufeature.h
17155 +++ b/arch/x86/include/asm/cpufeature.h
17156 @@ -203,14 +203,14 @@
17157 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
17158 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
17159
17160 -
17161 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
17162 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
17163 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
17164 #define X86_FEATURE_TSC_ADJUST ( 9*32+ 1) /* TSC adjustment MSR 0x3b */
17165 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
17166 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
17167 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
17168 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
17169 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
17170 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
17171 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
17172 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
17173 @@ -370,6 +370,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
17174 #undef cpu_has_centaur_mcr
17175 #define cpu_has_centaur_mcr 0
17176
17177 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
17178 #endif /* CONFIG_X86_64 */
17179
17180 #if __GNUC__ >= 4
17181 @@ -422,7 +423,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17182
17183 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
17184 t_warn:
17185 - warn_pre_alternatives();
17186 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
17187 + warn_pre_alternatives();
17188 return false;
17189 #endif
17190
17191 @@ -442,7 +444,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17192 ".section .discard,\"aw\",@progbits\n"
17193 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17194 ".previous\n"
17195 - ".section .altinstr_replacement,\"ax\"\n"
17196 + ".section .altinstr_replacement,\"a\"\n"
17197 "3: movb $1,%0\n"
17198 "4:\n"
17199 ".previous\n"
17200 @@ -479,7 +481,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17201 " .byte 2b - 1b\n" /* src len */
17202 " .byte 4f - 3f\n" /* repl len */
17203 ".previous\n"
17204 - ".section .altinstr_replacement,\"ax\"\n"
17205 + ".section .altinstr_replacement,\"a\"\n"
17206 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
17207 "4:\n"
17208 ".previous\n"
17209 @@ -512,7 +514,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17210 ".section .discard,\"aw\",@progbits\n"
17211 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17212 ".previous\n"
17213 - ".section .altinstr_replacement,\"ax\"\n"
17214 + ".section .altinstr_replacement,\"a\"\n"
17215 "3: movb $0,%0\n"
17216 "4:\n"
17217 ".previous\n"
17218 @@ -526,7 +528,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17219 ".section .discard,\"aw\",@progbits\n"
17220 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
17221 ".previous\n"
17222 - ".section .altinstr_replacement,\"ax\"\n"
17223 + ".section .altinstr_replacement,\"a\"\n"
17224 "5: movb $1,%0\n"
17225 "6:\n"
17226 ".previous\n"
17227 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
17228 index 50d033a..37deb26 100644
17229 --- a/arch/x86/include/asm/desc.h
17230 +++ b/arch/x86/include/asm/desc.h
17231 @@ -4,6 +4,7 @@
17232 #include <asm/desc_defs.h>
17233 #include <asm/ldt.h>
17234 #include <asm/mmu.h>
17235 +#include <asm/pgtable.h>
17236
17237 #include <linux/smp.h>
17238 #include <linux/percpu.h>
17239 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17240
17241 desc->type = (info->read_exec_only ^ 1) << 1;
17242 desc->type |= info->contents << 2;
17243 + desc->type |= info->seg_not_present ^ 1;
17244
17245 desc->s = 1;
17246 desc->dpl = 0x3;
17247 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17248 }
17249
17250 extern struct desc_ptr idt_descr;
17251 -extern gate_desc idt_table[];
17252 -extern struct desc_ptr debug_idt_descr;
17253 -extern gate_desc debug_idt_table[];
17254 -
17255 -struct gdt_page {
17256 - struct desc_struct gdt[GDT_ENTRIES];
17257 -} __attribute__((aligned(PAGE_SIZE)));
17258 -
17259 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
17260 +extern gate_desc idt_table[IDT_ENTRIES];
17261 +extern const struct desc_ptr debug_idt_descr;
17262 +extern gate_desc debug_idt_table[IDT_ENTRIES];
17263
17264 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
17265 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
17266 {
17267 - return per_cpu(gdt_page, cpu).gdt;
17268 + return cpu_gdt_table[cpu];
17269 }
17270
17271 #ifdef CONFIG_X86_64
17272 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
17273 unsigned long base, unsigned dpl, unsigned flags,
17274 unsigned short seg)
17275 {
17276 - gate->a = (seg << 16) | (base & 0xffff);
17277 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
17278 + gate->gate.offset_low = base;
17279 + gate->gate.seg = seg;
17280 + gate->gate.reserved = 0;
17281 + gate->gate.type = type;
17282 + gate->gate.s = 0;
17283 + gate->gate.dpl = dpl;
17284 + gate->gate.p = 1;
17285 + gate->gate.offset_high = base >> 16;
17286 }
17287
17288 #endif
17289 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
17290
17291 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
17292 {
17293 + pax_open_kernel();
17294 memcpy(&idt[entry], gate, sizeof(*gate));
17295 + pax_close_kernel();
17296 }
17297
17298 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
17299 {
17300 + pax_open_kernel();
17301 memcpy(&ldt[entry], desc, 8);
17302 + pax_close_kernel();
17303 }
17304
17305 static inline void
17306 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
17307 default: size = sizeof(*gdt); break;
17308 }
17309
17310 + pax_open_kernel();
17311 memcpy(&gdt[entry], desc, size);
17312 + pax_close_kernel();
17313 }
17314
17315 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
17316 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
17317
17318 static inline void native_load_tr_desc(void)
17319 {
17320 + pax_open_kernel();
17321 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
17322 + pax_close_kernel();
17323 }
17324
17325 static inline void native_load_gdt(const struct desc_ptr *dtr)
17326 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
17327 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
17328 unsigned int i;
17329
17330 + pax_open_kernel();
17331 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
17332 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
17333 + pax_close_kernel();
17334 }
17335
17336 #define _LDT_empty(info) \
17337 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
17338 preempt_enable();
17339 }
17340
17341 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
17342 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
17343 {
17344 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
17345 }
17346 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
17347 }
17348
17349 #ifdef CONFIG_X86_64
17350 -static inline void set_nmi_gate(int gate, void *addr)
17351 +static inline void set_nmi_gate(int gate, const void *addr)
17352 {
17353 gate_desc s;
17354
17355 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
17356 #endif
17357
17358 #ifdef CONFIG_TRACING
17359 -extern struct desc_ptr trace_idt_descr;
17360 -extern gate_desc trace_idt_table[];
17361 +extern const struct desc_ptr trace_idt_descr;
17362 +extern gate_desc trace_idt_table[IDT_ENTRIES];
17363 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17364 {
17365 write_idt_entry(trace_idt_table, entry, gate);
17366 }
17367
17368 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
17369 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
17370 unsigned dpl, unsigned ist, unsigned seg)
17371 {
17372 gate_desc s;
17373 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17374 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
17375 #endif
17376
17377 -static inline void _set_gate(int gate, unsigned type, void *addr,
17378 +static inline void _set_gate(int gate, unsigned type, const void *addr,
17379 unsigned dpl, unsigned ist, unsigned seg)
17380 {
17381 gate_desc s;
17382 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
17383 #define set_intr_gate(n, addr) \
17384 do { \
17385 BUG_ON((unsigned)n > 0xFF); \
17386 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
17387 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
17388 __KERNEL_CS); \
17389 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
17390 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
17391 0, 0, __KERNEL_CS); \
17392 } while (0)
17393
17394 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
17395 /*
17396 * This routine sets up an interrupt gate at directory privilege level 3.
17397 */
17398 -static inline void set_system_intr_gate(unsigned int n, void *addr)
17399 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
17400 {
17401 BUG_ON((unsigned)n > 0xFF);
17402 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
17403 }
17404
17405 -static inline void set_system_trap_gate(unsigned int n, void *addr)
17406 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
17407 {
17408 BUG_ON((unsigned)n > 0xFF);
17409 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
17410 }
17411
17412 -static inline void set_trap_gate(unsigned int n, void *addr)
17413 +static inline void set_trap_gate(unsigned int n, const void *addr)
17414 {
17415 BUG_ON((unsigned)n > 0xFF);
17416 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
17417 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
17418 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
17419 {
17420 BUG_ON((unsigned)n > 0xFF);
17421 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
17422 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
17423 }
17424
17425 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
17426 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
17427 {
17428 BUG_ON((unsigned)n > 0xFF);
17429 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
17430 }
17431
17432 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
17433 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
17434 {
17435 BUG_ON((unsigned)n > 0xFF);
17436 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
17437 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
17438 else
17439 load_idt((const struct desc_ptr *)&idt_descr);
17440 }
17441 +
17442 +#ifdef CONFIG_X86_32
17443 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
17444 +{
17445 + struct desc_struct d;
17446 +
17447 + if (likely(limit))
17448 + limit = (limit - 1UL) >> PAGE_SHIFT;
17449 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
17450 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
17451 +}
17452 +#endif
17453 +
17454 #endif /* _ASM_X86_DESC_H */
17455 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17456 index 278441f..b95a174 100644
17457 --- a/arch/x86/include/asm/desc_defs.h
17458 +++ b/arch/x86/include/asm/desc_defs.h
17459 @@ -31,6 +31,12 @@ struct desc_struct {
17460 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17461 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17462 };
17463 + struct {
17464 + u16 offset_low;
17465 + u16 seg;
17466 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17467 + unsigned offset_high: 16;
17468 + } gate;
17469 };
17470 } __attribute__((packed));
17471
17472 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17473 index ced283a..ffe04cc 100644
17474 --- a/arch/x86/include/asm/div64.h
17475 +++ b/arch/x86/include/asm/div64.h
17476 @@ -39,7 +39,7 @@
17477 __mod; \
17478 })
17479
17480 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17481 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17482 {
17483 union {
17484 u64 v64;
17485 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17486 index ca3347a..1a5082a 100644
17487 --- a/arch/x86/include/asm/elf.h
17488 +++ b/arch/x86/include/asm/elf.h
17489 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17490
17491 #include <asm/vdso.h>
17492
17493 -#ifdef CONFIG_X86_64
17494 -extern unsigned int vdso64_enabled;
17495 -#endif
17496 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17497 extern unsigned int vdso32_enabled;
17498 #endif
17499 @@ -249,7 +246,25 @@ extern int force_personality32;
17500 the loader. We need to make sure that it is out of the way of the program
17501 that it will "exec", and that there is sufficient room for the brk. */
17502
17503 +#ifdef CONFIG_PAX_SEGMEXEC
17504 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17505 +#else
17506 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17507 +#endif
17508 +
17509 +#ifdef CONFIG_PAX_ASLR
17510 +#ifdef CONFIG_X86_32
17511 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17512 +
17513 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17514 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17515 +#else
17516 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17517 +
17518 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17519 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17520 +#endif
17521 +#endif
17522
17523 /* This yields a mask that user programs can use to figure out what
17524 instruction set this CPU supports. This could be done in user space,
17525 @@ -298,17 +313,13 @@ do { \
17526
17527 #define ARCH_DLINFO \
17528 do { \
17529 - if (vdso64_enabled) \
17530 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17531 - (unsigned long __force)current->mm->context.vdso); \
17532 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17533 } while (0)
17534
17535 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17536 #define ARCH_DLINFO_X32 \
17537 do { \
17538 - if (vdso64_enabled) \
17539 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17540 - (unsigned long __force)current->mm->context.vdso); \
17541 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17542 } while (0)
17543
17544 #define AT_SYSINFO 32
17545 @@ -323,10 +334,10 @@ else \
17546
17547 #endif /* !CONFIG_X86_32 */
17548
17549 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17550 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17551
17552 #define VDSO_ENTRY \
17553 - ((unsigned long)current->mm->context.vdso + \
17554 + (current->mm->context.vdso + \
17555 selected_vdso32->sym___kernel_vsyscall)
17556
17557 struct linux_binprm;
17558 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17559 int uses_interp);
17560 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17561
17562 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17563 -#define arch_randomize_brk arch_randomize_brk
17564 -
17565 /*
17566 * True on X86_32 or when emulating IA32 on X86_64
17567 */
17568 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17569 index 77a99ac..39ff7f5 100644
17570 --- a/arch/x86/include/asm/emergency-restart.h
17571 +++ b/arch/x86/include/asm/emergency-restart.h
17572 @@ -1,6 +1,6 @@
17573 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17574 #define _ASM_X86_EMERGENCY_RESTART_H
17575
17576 -extern void machine_emergency_restart(void);
17577 +extern void machine_emergency_restart(void) __noreturn;
17578
17579 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17580 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17581 index 1c7eefe..d0e4702 100644
17582 --- a/arch/x86/include/asm/floppy.h
17583 +++ b/arch/x86/include/asm/floppy.h
17584 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17585 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17586 } fd_routine[] = {
17587 {
17588 - request_dma,
17589 - free_dma,
17590 - get_dma_residue,
17591 - dma_mem_alloc,
17592 - hard_dma_setup
17593 + ._request_dma = request_dma,
17594 + ._free_dma = free_dma,
17595 + ._get_dma_residue = get_dma_residue,
17596 + ._dma_mem_alloc = dma_mem_alloc,
17597 + ._dma_setup = hard_dma_setup
17598 },
17599 {
17600 - vdma_request_dma,
17601 - vdma_nop,
17602 - vdma_get_dma_residue,
17603 - vdma_mem_alloc,
17604 - vdma_dma_setup
17605 + ._request_dma = vdma_request_dma,
17606 + ._free_dma = vdma_nop,
17607 + ._get_dma_residue = vdma_get_dma_residue,
17608 + ._dma_mem_alloc = vdma_mem_alloc,
17609 + ._dma_setup = vdma_dma_setup
17610 }
17611 };
17612
17613 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17614 index 412ecec..c1ea43a 100644
17615 --- a/arch/x86/include/asm/fpu-internal.h
17616 +++ b/arch/x86/include/asm/fpu-internal.h
17617 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17618 #define user_insn(insn, output, input...) \
17619 ({ \
17620 int err; \
17621 + pax_open_userland(); \
17622 asm volatile(ASM_STAC "\n" \
17623 - "1:" #insn "\n\t" \
17624 + "1:" \
17625 + __copyuser_seg \
17626 + #insn "\n\t" \
17627 "2: " ASM_CLAC "\n" \
17628 ".section .fixup,\"ax\"\n" \
17629 "3: movl $-1,%[err]\n" \
17630 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17631 _ASM_EXTABLE(1b, 3b) \
17632 : [err] "=r" (err), output \
17633 : "0"(0), input); \
17634 + pax_close_userland(); \
17635 err; \
17636 })
17637
17638 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17639 "fnclex\n\t"
17640 "emms\n\t"
17641 "fildl %P[addr]" /* set F?P to defined value */
17642 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17643 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17644 }
17645
17646 return fpu_restore_checking(&tsk->thread.fpu);
17647 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17648 index b4c1f54..e290c08 100644
17649 --- a/arch/x86/include/asm/futex.h
17650 +++ b/arch/x86/include/asm/futex.h
17651 @@ -12,6 +12,7 @@
17652 #include <asm/smap.h>
17653
17654 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17655 + typecheck(u32 __user *, uaddr); \
17656 asm volatile("\t" ASM_STAC "\n" \
17657 "1:\t" insn "\n" \
17658 "2:\t" ASM_CLAC "\n" \
17659 @@ -20,15 +21,16 @@
17660 "\tjmp\t2b\n" \
17661 "\t.previous\n" \
17662 _ASM_EXTABLE(1b, 3b) \
17663 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17664 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17665 : "i" (-EFAULT), "0" (oparg), "1" (0))
17666
17667 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17668 + typecheck(u32 __user *, uaddr); \
17669 asm volatile("\t" ASM_STAC "\n" \
17670 "1:\tmovl %2, %0\n" \
17671 "\tmovl\t%0, %3\n" \
17672 "\t" insn "\n" \
17673 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17674 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17675 "\tjnz\t1b\n" \
17676 "3:\t" ASM_CLAC "\n" \
17677 "\t.section .fixup,\"ax\"\n" \
17678 @@ -38,7 +40,7 @@
17679 _ASM_EXTABLE(1b, 4b) \
17680 _ASM_EXTABLE(2b, 4b) \
17681 : "=&a" (oldval), "=&r" (ret), \
17682 - "+m" (*uaddr), "=&r" (tem) \
17683 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17684 : "r" (oparg), "i" (-EFAULT), "1" (0))
17685
17686 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17687 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17688
17689 pagefault_disable();
17690
17691 + pax_open_userland();
17692 switch (op) {
17693 case FUTEX_OP_SET:
17694 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17695 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17696 break;
17697 case FUTEX_OP_ADD:
17698 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17699 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17700 uaddr, oparg);
17701 break;
17702 case FUTEX_OP_OR:
17703 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17704 default:
17705 ret = -ENOSYS;
17706 }
17707 + pax_close_userland();
17708
17709 pagefault_enable();
17710
17711 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17712 index 4615906..788c817 100644
17713 --- a/arch/x86/include/asm/hw_irq.h
17714 +++ b/arch/x86/include/asm/hw_irq.h
17715 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17716 extern void enable_IO_APIC(void);
17717
17718 /* Statistics */
17719 -extern atomic_t irq_err_count;
17720 -extern atomic_t irq_mis_count;
17721 +extern atomic_unchecked_t irq_err_count;
17722 +extern atomic_unchecked_t irq_mis_count;
17723
17724 /* EISA */
17725 extern void eisa_set_level_irq(unsigned int irq);
17726 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17727 index ccffa53..3c90c87 100644
17728 --- a/arch/x86/include/asm/i8259.h
17729 +++ b/arch/x86/include/asm/i8259.h
17730 @@ -62,7 +62,7 @@ struct legacy_pic {
17731 void (*init)(int auto_eoi);
17732 int (*irq_pending)(unsigned int irq);
17733 void (*make_irq)(unsigned int irq);
17734 -};
17735 +} __do_const;
17736
17737 extern struct legacy_pic *legacy_pic;
17738 extern struct legacy_pic null_legacy_pic;
17739 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17740 index b8237d8..3e8864e 100644
17741 --- a/arch/x86/include/asm/io.h
17742 +++ b/arch/x86/include/asm/io.h
17743 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17744 "m" (*(volatile type __force *)addr) barrier); }
17745
17746 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17747 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17748 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17749 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17750 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17751
17752 build_mmio_read(__readb, "b", unsigned char, "=q", )
17753 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17754 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17755 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17756 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17757
17758 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17759 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17760 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17761 * this function
17762 */
17763
17764 -static inline phys_addr_t virt_to_phys(volatile void *address)
17765 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17766 {
17767 return __pa(address);
17768 }
17769 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17770 return ioremap_nocache(offset, size);
17771 }
17772
17773 -extern void iounmap(volatile void __iomem *addr);
17774 +extern void iounmap(const volatile void __iomem *addr);
17775
17776 extern void set_iounmap_nonlazy(void);
17777
17778 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17779
17780 #include <linux/vmalloc.h>
17781
17782 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17783 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17784 +{
17785 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17786 +}
17787 +
17788 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17789 +{
17790 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17791 +}
17792 +
17793 /*
17794 * Convert a virtual cached pointer to an uncached pointer
17795 */
17796 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17797 index 0a8b519..80e7d5b 100644
17798 --- a/arch/x86/include/asm/irqflags.h
17799 +++ b/arch/x86/include/asm/irqflags.h
17800 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17801 sti; \
17802 sysexit
17803
17804 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17805 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17806 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17807 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17808 +
17809 #else
17810 #define INTERRUPT_RETURN iret
17811 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17812 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17813 index 53cdfb2..d1369e6 100644
17814 --- a/arch/x86/include/asm/kprobes.h
17815 +++ b/arch/x86/include/asm/kprobes.h
17816 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17817 #define RELATIVEJUMP_SIZE 5
17818 #define RELATIVECALL_OPCODE 0xe8
17819 #define RELATIVE_ADDR_SIZE 4
17820 -#define MAX_STACK_SIZE 64
17821 -#define MIN_STACK_SIZE(ADDR) \
17822 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17823 - THREAD_SIZE - (unsigned long)(ADDR))) \
17824 - ? (MAX_STACK_SIZE) \
17825 - : (((unsigned long)current_thread_info()) + \
17826 - THREAD_SIZE - (unsigned long)(ADDR)))
17827 +#define MAX_STACK_SIZE 64UL
17828 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17829
17830 #define flush_insn_slot(p) do { } while (0)
17831
17832 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17833 index 4ad6560..75c7bdd 100644
17834 --- a/arch/x86/include/asm/local.h
17835 +++ b/arch/x86/include/asm/local.h
17836 @@ -10,33 +10,97 @@ typedef struct {
17837 atomic_long_t a;
17838 } local_t;
17839
17840 +typedef struct {
17841 + atomic_long_unchecked_t a;
17842 +} local_unchecked_t;
17843 +
17844 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17845
17846 #define local_read(l) atomic_long_read(&(l)->a)
17847 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17848 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17849 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17850
17851 static inline void local_inc(local_t *l)
17852 {
17853 - asm volatile(_ASM_INC "%0"
17854 + asm volatile(_ASM_INC "%0\n"
17855 +
17856 +#ifdef CONFIG_PAX_REFCOUNT
17857 + "jno 0f\n"
17858 + _ASM_DEC "%0\n"
17859 + "int $4\n0:\n"
17860 + _ASM_EXTABLE(0b, 0b)
17861 +#endif
17862 +
17863 + : "+m" (l->a.counter));
17864 +}
17865 +
17866 +static inline void local_inc_unchecked(local_unchecked_t *l)
17867 +{
17868 + asm volatile(_ASM_INC "%0\n"
17869 : "+m" (l->a.counter));
17870 }
17871
17872 static inline void local_dec(local_t *l)
17873 {
17874 - asm volatile(_ASM_DEC "%0"
17875 + asm volatile(_ASM_DEC "%0\n"
17876 +
17877 +#ifdef CONFIG_PAX_REFCOUNT
17878 + "jno 0f\n"
17879 + _ASM_INC "%0\n"
17880 + "int $4\n0:\n"
17881 + _ASM_EXTABLE(0b, 0b)
17882 +#endif
17883 +
17884 + : "+m" (l->a.counter));
17885 +}
17886 +
17887 +static inline void local_dec_unchecked(local_unchecked_t *l)
17888 +{
17889 + asm volatile(_ASM_DEC "%0\n"
17890 : "+m" (l->a.counter));
17891 }
17892
17893 static inline void local_add(long i, local_t *l)
17894 {
17895 - asm volatile(_ASM_ADD "%1,%0"
17896 + asm volatile(_ASM_ADD "%1,%0\n"
17897 +
17898 +#ifdef CONFIG_PAX_REFCOUNT
17899 + "jno 0f\n"
17900 + _ASM_SUB "%1,%0\n"
17901 + "int $4\n0:\n"
17902 + _ASM_EXTABLE(0b, 0b)
17903 +#endif
17904 +
17905 + : "+m" (l->a.counter)
17906 + : "ir" (i));
17907 +}
17908 +
17909 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17910 +{
17911 + asm volatile(_ASM_ADD "%1,%0\n"
17912 : "+m" (l->a.counter)
17913 : "ir" (i));
17914 }
17915
17916 static inline void local_sub(long i, local_t *l)
17917 {
17918 - asm volatile(_ASM_SUB "%1,%0"
17919 + asm volatile(_ASM_SUB "%1,%0\n"
17920 +
17921 +#ifdef CONFIG_PAX_REFCOUNT
17922 + "jno 0f\n"
17923 + _ASM_ADD "%1,%0\n"
17924 + "int $4\n0:\n"
17925 + _ASM_EXTABLE(0b, 0b)
17926 +#endif
17927 +
17928 + : "+m" (l->a.counter)
17929 + : "ir" (i));
17930 +}
17931 +
17932 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17933 +{
17934 + asm volatile(_ASM_SUB "%1,%0\n"
17935 : "+m" (l->a.counter)
17936 : "ir" (i));
17937 }
17938 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17939 */
17940 static inline int local_sub_and_test(long i, local_t *l)
17941 {
17942 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17943 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17944 }
17945
17946 /**
17947 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17948 */
17949 static inline int local_dec_and_test(local_t *l)
17950 {
17951 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17952 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17953 }
17954
17955 /**
17956 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17957 */
17958 static inline int local_inc_and_test(local_t *l)
17959 {
17960 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17961 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17962 }
17963
17964 /**
17965 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17966 */
17967 static inline int local_add_negative(long i, local_t *l)
17968 {
17969 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17970 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17971 }
17972
17973 /**
17974 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17975 static inline long local_add_return(long i, local_t *l)
17976 {
17977 long __i = i;
17978 + asm volatile(_ASM_XADD "%0, %1\n"
17979 +
17980 +#ifdef CONFIG_PAX_REFCOUNT
17981 + "jno 0f\n"
17982 + _ASM_MOV "%0,%1\n"
17983 + "int $4\n0:\n"
17984 + _ASM_EXTABLE(0b, 0b)
17985 +#endif
17986 +
17987 + : "+r" (i), "+m" (l->a.counter)
17988 + : : "memory");
17989 + return i + __i;
17990 +}
17991 +
17992 +/**
17993 + * local_add_return_unchecked - add and return
17994 + * @i: integer value to add
17995 + * @l: pointer to type local_unchecked_t
17996 + *
17997 + * Atomically adds @i to @l and returns @i + @l
17998 + */
17999 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
18000 +{
18001 + long __i = i;
18002 asm volatile(_ASM_XADD "%0, %1;"
18003 : "+r" (i), "+m" (l->a.counter)
18004 : : "memory");
18005 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
18006
18007 #define local_cmpxchg(l, o, n) \
18008 (cmpxchg_local(&((l)->a.counter), (o), (n)))
18009 +#define local_cmpxchg_unchecked(l, o, n) \
18010 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
18011 /* Always has a lock prefix */
18012 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
18013
18014 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
18015 new file mode 100644
18016 index 0000000..2bfd3ba
18017 --- /dev/null
18018 +++ b/arch/x86/include/asm/mman.h
18019 @@ -0,0 +1,15 @@
18020 +#ifndef _X86_MMAN_H
18021 +#define _X86_MMAN_H
18022 +
18023 +#include <uapi/asm/mman.h>
18024 +
18025 +#ifdef __KERNEL__
18026 +#ifndef __ASSEMBLY__
18027 +#ifdef CONFIG_X86_32
18028 +#define arch_mmap_check i386_mmap_check
18029 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
18030 +#endif
18031 +#endif
18032 +#endif
18033 +
18034 +#endif /* X86_MMAN_H */
18035 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
18036 index 876e74e..e20bfb1 100644
18037 --- a/arch/x86/include/asm/mmu.h
18038 +++ b/arch/x86/include/asm/mmu.h
18039 @@ -9,7 +9,7 @@
18040 * we put the segment information here.
18041 */
18042 typedef struct {
18043 - void *ldt;
18044 + struct desc_struct *ldt;
18045 int size;
18046
18047 #ifdef CONFIG_X86_64
18048 @@ -18,7 +18,19 @@ typedef struct {
18049 #endif
18050
18051 struct mutex lock;
18052 - void __user *vdso;
18053 + unsigned long vdso;
18054 +
18055 +#ifdef CONFIG_X86_32
18056 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18057 + unsigned long user_cs_base;
18058 + unsigned long user_cs_limit;
18059 +
18060 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18061 + cpumask_t cpu_user_cs_mask;
18062 +#endif
18063 +
18064 +#endif
18065 +#endif
18066 } mm_context_t;
18067
18068 #ifdef CONFIG_SMP
18069 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
18070 index 166af2a..648c200 100644
18071 --- a/arch/x86/include/asm/mmu_context.h
18072 +++ b/arch/x86/include/asm/mmu_context.h
18073 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
18074
18075 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
18076 {
18077 +
18078 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18079 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
18080 + unsigned int i;
18081 + pgd_t *pgd;
18082 +
18083 + pax_open_kernel();
18084 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
18085 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
18086 + set_pgd_batched(pgd+i, native_make_pgd(0));
18087 + pax_close_kernel();
18088 + }
18089 +#endif
18090 +
18091 #ifdef CONFIG_SMP
18092 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
18093 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
18094 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18095 struct task_struct *tsk)
18096 {
18097 unsigned cpu = smp_processor_id();
18098 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18099 + int tlbstate = TLBSTATE_OK;
18100 +#endif
18101
18102 if (likely(prev != next)) {
18103 #ifdef CONFIG_SMP
18104 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18105 + tlbstate = this_cpu_read(cpu_tlbstate.state);
18106 +#endif
18107 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18108 this_cpu_write(cpu_tlbstate.active_mm, next);
18109 #endif
18110 cpumask_set_cpu(cpu, mm_cpumask(next));
18111
18112 /* Re-load page tables */
18113 +#ifdef CONFIG_PAX_PER_CPU_PGD
18114 + pax_open_kernel();
18115 +
18116 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18117 + if (static_cpu_has(X86_FEATURE_PCID))
18118 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18119 + else
18120 +#endif
18121 +
18122 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18123 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18124 + pax_close_kernel();
18125 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
18126 +
18127 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18128 + if (static_cpu_has(X86_FEATURE_PCID)) {
18129 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18130 + u64 descriptor[2];
18131 + descriptor[0] = PCID_USER;
18132 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18133 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18134 + descriptor[0] = PCID_KERNEL;
18135 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18136 + }
18137 + } else {
18138 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18139 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18140 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18141 + else
18142 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18143 + }
18144 + } else
18145 +#endif
18146 +
18147 + load_cr3(get_cpu_pgd(cpu, kernel));
18148 +#else
18149 load_cr3(next->pgd);
18150 +#endif
18151 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18152
18153 /* Stop flush ipis for the previous mm */
18154 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18155 /* Load the LDT, if the LDT is different: */
18156 if (unlikely(prev->context.ldt != next->context.ldt))
18157 load_LDT_nolock(&next->context);
18158 +
18159 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18160 + if (!(__supported_pte_mask & _PAGE_NX)) {
18161 + smp_mb__before_atomic();
18162 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
18163 + smp_mb__after_atomic();
18164 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18165 + }
18166 +#endif
18167 +
18168 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18169 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
18170 + prev->context.user_cs_limit != next->context.user_cs_limit))
18171 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18172 +#ifdef CONFIG_SMP
18173 + else if (unlikely(tlbstate != TLBSTATE_OK))
18174 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18175 +#endif
18176 +#endif
18177 +
18178 }
18179 + else {
18180 +
18181 +#ifdef CONFIG_PAX_PER_CPU_PGD
18182 + pax_open_kernel();
18183 +
18184 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18185 + if (static_cpu_has(X86_FEATURE_PCID))
18186 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18187 + else
18188 +#endif
18189 +
18190 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18191 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18192 + pax_close_kernel();
18193 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
18194 +
18195 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18196 + if (static_cpu_has(X86_FEATURE_PCID)) {
18197 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18198 + u64 descriptor[2];
18199 + descriptor[0] = PCID_USER;
18200 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18201 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18202 + descriptor[0] = PCID_KERNEL;
18203 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18204 + }
18205 + } else {
18206 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18207 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18208 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18209 + else
18210 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18211 + }
18212 + } else
18213 +#endif
18214 +
18215 + load_cr3(get_cpu_pgd(cpu, kernel));
18216 +#endif
18217 +
18218 #ifdef CONFIG_SMP
18219 - else {
18220 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18221 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
18222
18223 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18224 * tlb flush IPI delivery. We must reload CR3
18225 * to make sure to use no freed page tables.
18226 */
18227 +
18228 +#ifndef CONFIG_PAX_PER_CPU_PGD
18229 load_cr3(next->pgd);
18230 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18231 +#endif
18232 +
18233 load_LDT_nolock(&next->context);
18234 +
18235 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18236 + if (!(__supported_pte_mask & _PAGE_NX))
18237 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18238 +#endif
18239 +
18240 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18241 +#ifdef CONFIG_PAX_PAGEEXEC
18242 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
18243 +#endif
18244 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18245 +#endif
18246 +
18247 }
18248 +#endif
18249 }
18250 -#endif
18251 }
18252
18253 #define activate_mm(prev, next) \
18254 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
18255 index e3b7819..b257c64 100644
18256 --- a/arch/x86/include/asm/module.h
18257 +++ b/arch/x86/include/asm/module.h
18258 @@ -5,6 +5,7 @@
18259
18260 #ifdef CONFIG_X86_64
18261 /* X86_64 does not define MODULE_PROC_FAMILY */
18262 +#define MODULE_PROC_FAMILY ""
18263 #elif defined CONFIG_M486
18264 #define MODULE_PROC_FAMILY "486 "
18265 #elif defined CONFIG_M586
18266 @@ -57,8 +58,20 @@
18267 #error unknown processor family
18268 #endif
18269
18270 -#ifdef CONFIG_X86_32
18271 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
18272 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
18273 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
18274 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
18275 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
18276 +#else
18277 +#define MODULE_PAX_KERNEXEC ""
18278 #endif
18279
18280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18281 +#define MODULE_PAX_UDEREF "UDEREF "
18282 +#else
18283 +#define MODULE_PAX_UDEREF ""
18284 +#endif
18285 +
18286 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
18287 +
18288 #endif /* _ASM_X86_MODULE_H */
18289 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
18290 index 5f2fc44..106caa6 100644
18291 --- a/arch/x86/include/asm/nmi.h
18292 +++ b/arch/x86/include/asm/nmi.h
18293 @@ -36,26 +36,35 @@ enum {
18294
18295 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
18296
18297 +struct nmiaction;
18298 +
18299 +struct nmiwork {
18300 + const struct nmiaction *action;
18301 + u64 max_duration;
18302 + struct irq_work irq_work;
18303 +};
18304 +
18305 struct nmiaction {
18306 struct list_head list;
18307 nmi_handler_t handler;
18308 - u64 max_duration;
18309 - struct irq_work irq_work;
18310 unsigned long flags;
18311 const char *name;
18312 -};
18313 + struct nmiwork *work;
18314 +} __do_const;
18315
18316 #define register_nmi_handler(t, fn, fg, n, init...) \
18317 ({ \
18318 - static struct nmiaction init fn##_na = { \
18319 + static struct nmiwork fn##_nw; \
18320 + static const struct nmiaction init fn##_na = { \
18321 .handler = (fn), \
18322 .name = (n), \
18323 .flags = (fg), \
18324 + .work = &fn##_nw, \
18325 }; \
18326 __register_nmi_handler((t), &fn##_na); \
18327 })
18328
18329 -int __register_nmi_handler(unsigned int, struct nmiaction *);
18330 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
18331
18332 void unregister_nmi_handler(unsigned int, const char *);
18333
18334 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
18335 index 802dde3..9183e68 100644
18336 --- a/arch/x86/include/asm/page.h
18337 +++ b/arch/x86/include/asm/page.h
18338 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18339 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
18340
18341 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
18342 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
18343
18344 #define __boot_va(x) __va(x)
18345 #define __boot_pa(x) __pa(x)
18346 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18347 * virt_to_page(kaddr) returns a valid pointer if and only if
18348 * virt_addr_valid(kaddr) returns true.
18349 */
18350 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18351 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
18352 extern bool __virt_addr_valid(unsigned long kaddr);
18353 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
18354
18355 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
18356 +#define virt_to_page(kaddr) \
18357 + ({ \
18358 + const void *__kaddr = (const void *)(kaddr); \
18359 + BUG_ON(!virt_addr_valid(__kaddr)); \
18360 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
18361 + })
18362 +#else
18363 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18364 +#endif
18365 +
18366 #endif /* __ASSEMBLY__ */
18367
18368 #include <asm-generic/memory_model.h>
18369 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
18370 index f408caf..4a0455e 100644
18371 --- a/arch/x86/include/asm/page_64.h
18372 +++ b/arch/x86/include/asm/page_64.h
18373 @@ -7,9 +7,9 @@
18374
18375 /* duplicated to the one in bootmem.h */
18376 extern unsigned long max_pfn;
18377 -extern unsigned long phys_base;
18378 +extern const unsigned long phys_base;
18379
18380 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
18381 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
18382 {
18383 unsigned long y = x - __START_KERNEL_map;
18384
18385 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
18386 index cd6e1610..70f4418 100644
18387 --- a/arch/x86/include/asm/paravirt.h
18388 +++ b/arch/x86/include/asm/paravirt.h
18389 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
18390 return (pmd_t) { ret };
18391 }
18392
18393 -static inline pmdval_t pmd_val(pmd_t pmd)
18394 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
18395 {
18396 pmdval_t ret;
18397
18398 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
18399 val);
18400 }
18401
18402 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18403 +{
18404 + pgdval_t val = native_pgd_val(pgd);
18405 +
18406 + if (sizeof(pgdval_t) > sizeof(long))
18407 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
18408 + val, (u64)val >> 32);
18409 + else
18410 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
18411 + val);
18412 +}
18413 +
18414 static inline void pgd_clear(pgd_t *pgdp)
18415 {
18416 set_pgd(pgdp, __pgd(0));
18417 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
18418 pv_mmu_ops.set_fixmap(idx, phys, flags);
18419 }
18420
18421 +#ifdef CONFIG_PAX_KERNEXEC
18422 +static inline unsigned long pax_open_kernel(void)
18423 +{
18424 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
18425 +}
18426 +
18427 +static inline unsigned long pax_close_kernel(void)
18428 +{
18429 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
18430 +}
18431 +#else
18432 +static inline unsigned long pax_open_kernel(void) { return 0; }
18433 +static inline unsigned long pax_close_kernel(void) { return 0; }
18434 +#endif
18435 +
18436 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
18437
18438 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
18439 @@ -906,7 +933,7 @@ extern void default_banner(void);
18440
18441 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
18442 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
18443 -#define PARA_INDIRECT(addr) *%cs:addr
18444 +#define PARA_INDIRECT(addr) *%ss:addr
18445 #endif
18446
18447 #define INTERRUPT_RETURN \
18448 @@ -981,6 +1008,21 @@ extern void default_banner(void);
18449 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
18450 CLBR_NONE, \
18451 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
18452 +
18453 +#define GET_CR0_INTO_RDI \
18454 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
18455 + mov %rax,%rdi
18456 +
18457 +#define SET_RDI_INTO_CR0 \
18458 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18459 +
18460 +#define GET_CR3_INTO_RDI \
18461 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18462 + mov %rax,%rdi
18463 +
18464 +#define SET_RDI_INTO_CR3 \
18465 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18466 +
18467 #endif /* CONFIG_X86_32 */
18468
18469 #endif /* __ASSEMBLY__ */
18470 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18471 index 7549b8b..f0edfda 100644
18472 --- a/arch/x86/include/asm/paravirt_types.h
18473 +++ b/arch/x86/include/asm/paravirt_types.h
18474 @@ -84,7 +84,7 @@ struct pv_init_ops {
18475 */
18476 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18477 unsigned long addr, unsigned len);
18478 -};
18479 +} __no_const __no_randomize_layout;
18480
18481
18482 struct pv_lazy_ops {
18483 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
18484 void (*enter)(void);
18485 void (*leave)(void);
18486 void (*flush)(void);
18487 -};
18488 +} __no_randomize_layout;
18489
18490 struct pv_time_ops {
18491 unsigned long long (*sched_clock)(void);
18492 unsigned long long (*steal_clock)(int cpu);
18493 unsigned long (*get_tsc_khz)(void);
18494 -};
18495 +} __no_const __no_randomize_layout;
18496
18497 struct pv_cpu_ops {
18498 /* hooks for various privileged instructions */
18499 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18500
18501 void (*start_context_switch)(struct task_struct *prev);
18502 void (*end_context_switch)(struct task_struct *next);
18503 -};
18504 +} __no_const __no_randomize_layout;
18505
18506 struct pv_irq_ops {
18507 /*
18508 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18509 #ifdef CONFIG_X86_64
18510 void (*adjust_exception_frame)(void);
18511 #endif
18512 -};
18513 +} __no_randomize_layout;
18514
18515 struct pv_apic_ops {
18516 #ifdef CONFIG_X86_LOCAL_APIC
18517 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18518 unsigned long start_eip,
18519 unsigned long start_esp);
18520 #endif
18521 -};
18522 +} __no_const __no_randomize_layout;
18523
18524 struct pv_mmu_ops {
18525 unsigned long (*read_cr2)(void);
18526 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18527 struct paravirt_callee_save make_pud;
18528
18529 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18530 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18531 #endif /* PAGETABLE_LEVELS == 4 */
18532 #endif /* PAGETABLE_LEVELS >= 3 */
18533
18534 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18535 an mfn. We can tell which is which from the index. */
18536 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18537 phys_addr_t phys, pgprot_t flags);
18538 -};
18539 +
18540 +#ifdef CONFIG_PAX_KERNEXEC
18541 + unsigned long (*pax_open_kernel)(void);
18542 + unsigned long (*pax_close_kernel)(void);
18543 +#endif
18544 +
18545 +} __no_randomize_layout;
18546
18547 struct arch_spinlock;
18548 #ifdef CONFIG_SMP
18549 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18550 struct pv_lock_ops {
18551 struct paravirt_callee_save lock_spinning;
18552 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18553 -};
18554 +} __no_randomize_layout;
18555
18556 /* This contains all the paravirt structures: we get a convenient
18557 * number for each function using the offset which we use to indicate
18558 - * what to patch. */
18559 + * what to patch.
18560 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18561 + */
18562 +
18563 struct paravirt_patch_template {
18564 struct pv_init_ops pv_init_ops;
18565 struct pv_time_ops pv_time_ops;
18566 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18567 struct pv_apic_ops pv_apic_ops;
18568 struct pv_mmu_ops pv_mmu_ops;
18569 struct pv_lock_ops pv_lock_ops;
18570 -};
18571 +} __no_randomize_layout;
18572
18573 extern struct pv_info pv_info;
18574 extern struct pv_init_ops pv_init_ops;
18575 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18576 index c4412e9..90e88c5 100644
18577 --- a/arch/x86/include/asm/pgalloc.h
18578 +++ b/arch/x86/include/asm/pgalloc.h
18579 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18580 pmd_t *pmd, pte_t *pte)
18581 {
18582 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18583 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18584 +}
18585 +
18586 +static inline void pmd_populate_user(struct mm_struct *mm,
18587 + pmd_t *pmd, pte_t *pte)
18588 +{
18589 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18590 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18591 }
18592
18593 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18594
18595 #ifdef CONFIG_X86_PAE
18596 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18597 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18598 +{
18599 + pud_populate(mm, pudp, pmd);
18600 +}
18601 #else /* !CONFIG_X86_PAE */
18602 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18603 {
18604 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18605 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18606 }
18607 +
18608 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18609 +{
18610 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18611 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18612 +}
18613 #endif /* CONFIG_X86_PAE */
18614
18615 #if PAGETABLE_LEVELS > 3
18616 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18617 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18618 }
18619
18620 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18621 +{
18622 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18623 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18624 +}
18625 +
18626 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18627 {
18628 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18629 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18630 index 206a87f..1623b06 100644
18631 --- a/arch/x86/include/asm/pgtable-2level.h
18632 +++ b/arch/x86/include/asm/pgtable-2level.h
18633 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18634
18635 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18636 {
18637 + pax_open_kernel();
18638 *pmdp = pmd;
18639 + pax_close_kernel();
18640 }
18641
18642 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18643 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18644 index 81bb91b..9392125 100644
18645 --- a/arch/x86/include/asm/pgtable-3level.h
18646 +++ b/arch/x86/include/asm/pgtable-3level.h
18647 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18648
18649 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18650 {
18651 + pax_open_kernel();
18652 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18653 + pax_close_kernel();
18654 }
18655
18656 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18657 {
18658 + pax_open_kernel();
18659 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18660 + pax_close_kernel();
18661 }
18662
18663 /*
18664 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18665 index aa97a07..5c53c32 100644
18666 --- a/arch/x86/include/asm/pgtable.h
18667 +++ b/arch/x86/include/asm/pgtable.h
18668 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18669
18670 #ifndef __PAGETABLE_PUD_FOLDED
18671 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18672 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18673 #define pgd_clear(pgd) native_pgd_clear(pgd)
18674 #endif
18675
18676 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18677
18678 #define arch_end_context_switch(prev) do {} while(0)
18679
18680 +#define pax_open_kernel() native_pax_open_kernel()
18681 +#define pax_close_kernel() native_pax_close_kernel()
18682 #endif /* CONFIG_PARAVIRT */
18683
18684 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18685 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18686 +
18687 +#ifdef CONFIG_PAX_KERNEXEC
18688 +static inline unsigned long native_pax_open_kernel(void)
18689 +{
18690 + unsigned long cr0;
18691 +
18692 + preempt_disable();
18693 + barrier();
18694 + cr0 = read_cr0() ^ X86_CR0_WP;
18695 + BUG_ON(cr0 & X86_CR0_WP);
18696 + write_cr0(cr0);
18697 + barrier();
18698 + return cr0 ^ X86_CR0_WP;
18699 +}
18700 +
18701 +static inline unsigned long native_pax_close_kernel(void)
18702 +{
18703 + unsigned long cr0;
18704 +
18705 + barrier();
18706 + cr0 = read_cr0() ^ X86_CR0_WP;
18707 + BUG_ON(!(cr0 & X86_CR0_WP));
18708 + write_cr0(cr0);
18709 + barrier();
18710 + preempt_enable_no_resched();
18711 + return cr0 ^ X86_CR0_WP;
18712 +}
18713 +#else
18714 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18715 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18716 +#endif
18717 +
18718 /*
18719 * The following only work if pte_present() is true.
18720 * Undefined behaviour if not..
18721 */
18722 +static inline int pte_user(pte_t pte)
18723 +{
18724 + return pte_val(pte) & _PAGE_USER;
18725 +}
18726 +
18727 static inline int pte_dirty(pte_t pte)
18728 {
18729 return pte_flags(pte) & _PAGE_DIRTY;
18730 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18731 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18732 }
18733
18734 +static inline unsigned long pgd_pfn(pgd_t pgd)
18735 +{
18736 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18737 +}
18738 +
18739 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18740
18741 static inline int pmd_large(pmd_t pte)
18742 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18743 return pte_clear_flags(pte, _PAGE_RW);
18744 }
18745
18746 +static inline pte_t pte_mkread(pte_t pte)
18747 +{
18748 + return __pte(pte_val(pte) | _PAGE_USER);
18749 +}
18750 +
18751 static inline pte_t pte_mkexec(pte_t pte)
18752 {
18753 - return pte_clear_flags(pte, _PAGE_NX);
18754 +#ifdef CONFIG_X86_PAE
18755 + if (__supported_pte_mask & _PAGE_NX)
18756 + return pte_clear_flags(pte, _PAGE_NX);
18757 + else
18758 +#endif
18759 + return pte_set_flags(pte, _PAGE_USER);
18760 +}
18761 +
18762 +static inline pte_t pte_exprotect(pte_t pte)
18763 +{
18764 +#ifdef CONFIG_X86_PAE
18765 + if (__supported_pte_mask & _PAGE_NX)
18766 + return pte_set_flags(pte, _PAGE_NX);
18767 + else
18768 +#endif
18769 + return pte_clear_flags(pte, _PAGE_USER);
18770 }
18771
18772 static inline pte_t pte_mkdirty(pte_t pte)
18773 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18774 #endif
18775
18776 #ifndef __ASSEMBLY__
18777 +
18778 +#ifdef CONFIG_PAX_PER_CPU_PGD
18779 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18780 +enum cpu_pgd_type {kernel = 0, user = 1};
18781 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18782 +{
18783 + return cpu_pgd[cpu][type];
18784 +}
18785 +#endif
18786 +
18787 #include <linux/mm_types.h>
18788 #include <linux/mmdebug.h>
18789 #include <linux/log2.h>
18790 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18791 * Currently stuck as a macro due to indirect forward reference to
18792 * linux/mmzone.h's __section_mem_map_addr() definition:
18793 */
18794 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18795 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18796
18797 /* Find an entry in the second-level page table.. */
18798 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18799 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18800 * Currently stuck as a macro due to indirect forward reference to
18801 * linux/mmzone.h's __section_mem_map_addr() definition:
18802 */
18803 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18804 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18805
18806 /* to find an entry in a page-table-directory. */
18807 static inline unsigned long pud_index(unsigned long address)
18808 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18809
18810 static inline int pgd_bad(pgd_t pgd)
18811 {
18812 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18813 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18814 }
18815
18816 static inline int pgd_none(pgd_t pgd)
18817 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18818 * pgd_offset() returns a (pgd_t *)
18819 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18820 */
18821 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18822 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18823 +
18824 +#ifdef CONFIG_PAX_PER_CPU_PGD
18825 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18826 +#endif
18827 +
18828 /*
18829 * a shortcut which implies the use of the kernel's pgd, instead
18830 * of a process's
18831 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18832 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18833 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18834
18835 +#ifdef CONFIG_X86_32
18836 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18837 +#else
18838 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18839 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18840 +
18841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18842 +#ifdef __ASSEMBLY__
18843 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18844 +#else
18845 +extern unsigned long pax_user_shadow_base;
18846 +extern pgdval_t clone_pgd_mask;
18847 +#endif
18848 +#endif
18849 +
18850 +#endif
18851 +
18852 #ifndef __ASSEMBLY__
18853
18854 extern int direct_gbpages;
18855 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18856 * dst and src can be on the same page, but the range must not overlap,
18857 * and must not cross a page boundary.
18858 */
18859 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18860 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18861 {
18862 - memcpy(dst, src, count * sizeof(pgd_t));
18863 + pax_open_kernel();
18864 + while (count--)
18865 + *dst++ = *src++;
18866 + pax_close_kernel();
18867 }
18868
18869 +#ifdef CONFIG_PAX_PER_CPU_PGD
18870 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18871 +#endif
18872 +
18873 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18874 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18875 +#else
18876 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18877 +#endif
18878 +
18879 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18880 static inline int page_level_shift(enum pg_level level)
18881 {
18882 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18883 index 9ee3221..b979c6b 100644
18884 --- a/arch/x86/include/asm/pgtable_32.h
18885 +++ b/arch/x86/include/asm/pgtable_32.h
18886 @@ -25,9 +25,6 @@
18887 struct mm_struct;
18888 struct vm_area_struct;
18889
18890 -extern pgd_t swapper_pg_dir[1024];
18891 -extern pgd_t initial_page_table[1024];
18892 -
18893 static inline void pgtable_cache_init(void) { }
18894 static inline void check_pgt_cache(void) { }
18895 void paging_init(void);
18896 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18897 # include <asm/pgtable-2level.h>
18898 #endif
18899
18900 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18901 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18902 +#ifdef CONFIG_X86_PAE
18903 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18904 +#endif
18905 +
18906 #if defined(CONFIG_HIGHPTE)
18907 #define pte_offset_map(dir, address) \
18908 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18909 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18910 /* Clear a kernel PTE and flush it from the TLB */
18911 #define kpte_clear_flush(ptep, vaddr) \
18912 do { \
18913 + pax_open_kernel(); \
18914 pte_clear(&init_mm, (vaddr), (ptep)); \
18915 + pax_close_kernel(); \
18916 __flush_tlb_one((vaddr)); \
18917 } while (0)
18918
18919 #endif /* !__ASSEMBLY__ */
18920
18921 +#define HAVE_ARCH_UNMAPPED_AREA
18922 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18923 +
18924 /*
18925 * kern_addr_valid() is (1) for FLATMEM and (0) for
18926 * SPARSEMEM and DISCONTIGMEM
18927 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18928 index ed5903b..c7fe163 100644
18929 --- a/arch/x86/include/asm/pgtable_32_types.h
18930 +++ b/arch/x86/include/asm/pgtable_32_types.h
18931 @@ -8,7 +8,7 @@
18932 */
18933 #ifdef CONFIG_X86_PAE
18934 # include <asm/pgtable-3level_types.h>
18935 -# define PMD_SIZE (1UL << PMD_SHIFT)
18936 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18937 # define PMD_MASK (~(PMD_SIZE - 1))
18938 #else
18939 # include <asm/pgtable-2level_types.h>
18940 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18941 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18942 #endif
18943
18944 +#ifdef CONFIG_PAX_KERNEXEC
18945 +#ifndef __ASSEMBLY__
18946 +extern unsigned char MODULES_EXEC_VADDR[];
18947 +extern unsigned char MODULES_EXEC_END[];
18948 +#endif
18949 +#include <asm/boot.h>
18950 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18951 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18952 +#else
18953 +#define ktla_ktva(addr) (addr)
18954 +#define ktva_ktla(addr) (addr)
18955 +#endif
18956 +
18957 #define MODULES_VADDR VMALLOC_START
18958 #define MODULES_END VMALLOC_END
18959 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18960 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18961 index 3874693..d7906ac 100644
18962 --- a/arch/x86/include/asm/pgtable_64.h
18963 +++ b/arch/x86/include/asm/pgtable_64.h
18964 @@ -16,11 +16,16 @@
18965
18966 extern pud_t level3_kernel_pgt[512];
18967 extern pud_t level3_ident_pgt[512];
18968 +extern pud_t level3_vmalloc_start_pgt[512];
18969 +extern pud_t level3_vmalloc_end_pgt[512];
18970 +extern pud_t level3_vmemmap_pgt[512];
18971 +extern pud_t level2_vmemmap_pgt[512];
18972 extern pmd_t level2_kernel_pgt[512];
18973 extern pmd_t level2_fixmap_pgt[512];
18974 -extern pmd_t level2_ident_pgt[512];
18975 +extern pmd_t level2_ident_pgt[512*2];
18976 extern pte_t level1_fixmap_pgt[512];
18977 -extern pgd_t init_level4_pgt[];
18978 +extern pte_t level1_vsyscall_pgt[512];
18979 +extern pgd_t init_level4_pgt[512];
18980
18981 #define swapper_pg_dir init_level4_pgt
18982
18983 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18984
18985 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18986 {
18987 + pax_open_kernel();
18988 *pmdp = pmd;
18989 + pax_close_kernel();
18990 }
18991
18992 static inline void native_pmd_clear(pmd_t *pmd)
18993 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18994
18995 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18996 {
18997 + pax_open_kernel();
18998 *pudp = pud;
18999 + pax_close_kernel();
19000 }
19001
19002 static inline void native_pud_clear(pud_t *pud)
19003 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
19004
19005 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
19006 {
19007 + pax_open_kernel();
19008 + *pgdp = pgd;
19009 + pax_close_kernel();
19010 +}
19011 +
19012 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
19013 +{
19014 *pgdp = pgd;
19015 }
19016
19017 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
19018 index 7166e25..baaa6fe 100644
19019 --- a/arch/x86/include/asm/pgtable_64_types.h
19020 +++ b/arch/x86/include/asm/pgtable_64_types.h
19021 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
19022 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
19023 #define MODULES_END _AC(0xffffffffff000000, UL)
19024 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
19025 +#define MODULES_EXEC_VADDR MODULES_VADDR
19026 +#define MODULES_EXEC_END MODULES_END
19027 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
19028 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
19029
19030 +#define ktla_ktva(addr) (addr)
19031 +#define ktva_ktla(addr) (addr)
19032 +
19033 #define EARLY_DYNAMIC_PAGE_TABLES 64
19034
19035 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
19036 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
19037 index f216963..6bd7c21 100644
19038 --- a/arch/x86/include/asm/pgtable_types.h
19039 +++ b/arch/x86/include/asm/pgtable_types.h
19040 @@ -111,8 +111,10 @@
19041
19042 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19043 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
19044 -#else
19045 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
19046 #define _PAGE_NX (_AT(pteval_t, 0))
19047 +#else
19048 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
19049 #endif
19050
19051 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
19052 @@ -151,6 +153,9 @@
19053 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
19054 _PAGE_ACCESSED)
19055
19056 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
19057 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
19058 +
19059 #define __PAGE_KERNEL_EXEC \
19060 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
19061 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
19062 @@ -161,7 +166,7 @@
19063 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
19064 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
19065 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
19066 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
19067 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
19068 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
19069 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
19070 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
19071 @@ -218,7 +223,7 @@
19072 #ifdef CONFIG_X86_64
19073 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
19074 #else
19075 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
19076 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19077 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19078 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
19079 #endif
19080 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
19081 {
19082 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
19083 }
19084 +#endif
19085
19086 +#if PAGETABLE_LEVELS == 3
19087 +#include <asm-generic/pgtable-nopud.h>
19088 +#endif
19089 +
19090 +#if PAGETABLE_LEVELS == 2
19091 +#include <asm-generic/pgtable-nopmd.h>
19092 +#endif
19093 +
19094 +#ifndef __ASSEMBLY__
19095 #if PAGETABLE_LEVELS > 3
19096 typedef struct { pudval_t pud; } pud_t;
19097
19098 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
19099 return pud.pud;
19100 }
19101 #else
19102 -#include <asm-generic/pgtable-nopud.h>
19103 -
19104 static inline pudval_t native_pud_val(pud_t pud)
19105 {
19106 return native_pgd_val(pud.pgd);
19107 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
19108 return pmd.pmd;
19109 }
19110 #else
19111 -#include <asm-generic/pgtable-nopmd.h>
19112 -
19113 static inline pmdval_t native_pmd_val(pmd_t pmd)
19114 {
19115 return native_pgd_val(pmd.pud.pgd);
19116 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
19117
19118 extern pteval_t __supported_pte_mask;
19119 extern void set_nx(void);
19120 -extern int nx_enabled;
19121
19122 #define pgprot_writecombine pgprot_writecombine
19123 extern pgprot_t pgprot_writecombine(pgprot_t prot);
19124 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
19125 index 7024c12..71c46b9 100644
19126 --- a/arch/x86/include/asm/preempt.h
19127 +++ b/arch/x86/include/asm/preempt.h
19128 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
19129 */
19130 static __always_inline bool __preempt_count_dec_and_test(void)
19131 {
19132 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
19133 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
19134 }
19135
19136 /*
19137 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
19138 index eb71ec7..f06532a 100644
19139 --- a/arch/x86/include/asm/processor.h
19140 +++ b/arch/x86/include/asm/processor.h
19141 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
19142 /* Index into per_cpu list: */
19143 u16 cpu_index;
19144 u32 microcode;
19145 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
19146 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
19147
19148 #define X86_VENDOR_INTEL 0
19149 #define X86_VENDOR_CYRIX 1
19150 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
19151 : "memory");
19152 }
19153
19154 +/* invpcid (%rdx),%rax */
19155 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
19156 +
19157 +#define INVPCID_SINGLE_ADDRESS 0UL
19158 +#define INVPCID_SINGLE_CONTEXT 1UL
19159 +#define INVPCID_ALL_GLOBAL 2UL
19160 +#define INVPCID_ALL_NONGLOBAL 3UL
19161 +
19162 +#define PCID_KERNEL 0UL
19163 +#define PCID_USER 1UL
19164 +#define PCID_NOFLUSH (1UL << 63)
19165 +
19166 static inline void load_cr3(pgd_t *pgdir)
19167 {
19168 - write_cr3(__pa(pgdir));
19169 + write_cr3(__pa(pgdir) | PCID_KERNEL);
19170 }
19171
19172 #ifdef CONFIG_X86_32
19173 @@ -282,7 +294,7 @@ struct tss_struct {
19174
19175 } ____cacheline_aligned;
19176
19177 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
19178 +extern struct tss_struct init_tss[NR_CPUS];
19179
19180 /*
19181 * Save the original ist values for checking stack pointers during debugging
19182 @@ -478,6 +490,7 @@ struct thread_struct {
19183 unsigned short ds;
19184 unsigned short fsindex;
19185 unsigned short gsindex;
19186 + unsigned short ss;
19187 #endif
19188 #ifdef CONFIG_X86_32
19189 unsigned long ip;
19190 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
19191 extern unsigned long mmu_cr4_features;
19192 extern u32 *trampoline_cr4_features;
19193
19194 -static inline void set_in_cr4(unsigned long mask)
19195 -{
19196 - unsigned long cr4;
19197 -
19198 - mmu_cr4_features |= mask;
19199 - if (trampoline_cr4_features)
19200 - *trampoline_cr4_features = mmu_cr4_features;
19201 - cr4 = read_cr4();
19202 - cr4 |= mask;
19203 - write_cr4(cr4);
19204 -}
19205 -
19206 -static inline void clear_in_cr4(unsigned long mask)
19207 -{
19208 - unsigned long cr4;
19209 -
19210 - mmu_cr4_features &= ~mask;
19211 - if (trampoline_cr4_features)
19212 - *trampoline_cr4_features = mmu_cr4_features;
19213 - cr4 = read_cr4();
19214 - cr4 &= ~mask;
19215 - write_cr4(cr4);
19216 -}
19217 +extern void set_in_cr4(unsigned long mask);
19218 +extern void clear_in_cr4(unsigned long mask);
19219
19220 typedef struct {
19221 unsigned long seg;
19222 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
19223 */
19224 #define TASK_SIZE PAGE_OFFSET
19225 #define TASK_SIZE_MAX TASK_SIZE
19226 +
19227 +#ifdef CONFIG_PAX_SEGMEXEC
19228 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
19229 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
19230 +#else
19231 #define STACK_TOP TASK_SIZE
19232 -#define STACK_TOP_MAX STACK_TOP
19233 +#endif
19234 +
19235 +#define STACK_TOP_MAX TASK_SIZE
19236
19237 #define INIT_THREAD { \
19238 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19239 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19240 .vm86_info = NULL, \
19241 .sysenter_cs = __KERNEL_CS, \
19242 .io_bitmap_ptr = NULL, \
19243 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
19244 */
19245 #define INIT_TSS { \
19246 .x86_tss = { \
19247 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19248 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19249 .ss0 = __KERNEL_DS, \
19250 .ss1 = __KERNEL_CS, \
19251 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
19252 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
19253 extern unsigned long thread_saved_pc(struct task_struct *tsk);
19254
19255 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
19256 -#define KSTK_TOP(info) \
19257 -({ \
19258 - unsigned long *__ptr = (unsigned long *)(info); \
19259 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
19260 -})
19261 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
19262
19263 /*
19264 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
19265 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19266 #define task_pt_regs(task) \
19267 ({ \
19268 struct pt_regs *__regs__; \
19269 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
19270 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
19271 __regs__ - 1; \
19272 })
19273
19274 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19275 /*
19276 * User space process size. 47bits minus one guard page.
19277 */
19278 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
19279 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
19280
19281 /* This decides where the kernel will search for a free chunk of vm
19282 * space during mmap's.
19283 */
19284 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
19285 - 0xc0000000 : 0xFFFFe000)
19286 + 0xc0000000 : 0xFFFFf000)
19287
19288 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
19289 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
19290 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19291 #define STACK_TOP_MAX TASK_SIZE_MAX
19292
19293 #define INIT_THREAD { \
19294 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19295 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19296 }
19297
19298 #define INIT_TSS { \
19299 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19300 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19301 }
19302
19303 /*
19304 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
19305 */
19306 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
19307
19308 +#ifdef CONFIG_PAX_SEGMEXEC
19309 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
19310 +#endif
19311 +
19312 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
19313
19314 /* Get/set a process' ability to use the timestamp counter instruction */
19315 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
19316 return 0;
19317 }
19318
19319 -extern unsigned long arch_align_stack(unsigned long sp);
19320 +#define arch_align_stack(x) ((x) & ~0xfUL)
19321 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
19322
19323 void default_idle(void);
19324 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
19325 #define xen_set_default_idle 0
19326 #endif
19327
19328 -void stop_this_cpu(void *dummy);
19329 +void stop_this_cpu(void *dummy) __noreturn;
19330 void df_debug(struct pt_regs *regs, long error_code);
19331 #endif /* _ASM_X86_PROCESSOR_H */
19332 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
19333 index 6205f0c..688a3a9 100644
19334 --- a/arch/x86/include/asm/ptrace.h
19335 +++ b/arch/x86/include/asm/ptrace.h
19336 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
19337 }
19338
19339 /*
19340 - * user_mode_vm(regs) determines whether a register set came from user mode.
19341 + * user_mode(regs) determines whether a register set came from user mode.
19342 * This is true if V8086 mode was enabled OR if the register set was from
19343 * protected mode with RPL-3 CS value. This tricky test checks that with
19344 * one comparison. Many places in the kernel can bypass this full check
19345 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
19346 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
19347 + * be used.
19348 */
19349 -static inline int user_mode(struct pt_regs *regs)
19350 +static inline int user_mode_novm(struct pt_regs *regs)
19351 {
19352 #ifdef CONFIG_X86_32
19353 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
19354 #else
19355 - return !!(regs->cs & 3);
19356 + return !!(regs->cs & SEGMENT_RPL_MASK);
19357 #endif
19358 }
19359
19360 -static inline int user_mode_vm(struct pt_regs *regs)
19361 +static inline int user_mode(struct pt_regs *regs)
19362 {
19363 #ifdef CONFIG_X86_32
19364 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
19365 USER_RPL;
19366 #else
19367 - return user_mode(regs);
19368 + return user_mode_novm(regs);
19369 #endif
19370 }
19371
19372 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
19373 #ifdef CONFIG_X86_64
19374 static inline bool user_64bit_mode(struct pt_regs *regs)
19375 {
19376 + unsigned long cs = regs->cs & 0xffff;
19377 #ifndef CONFIG_PARAVIRT
19378 /*
19379 * On non-paravirt systems, this is the only long mode CPL 3
19380 * selector. We do not allow long mode selectors in the LDT.
19381 */
19382 - return regs->cs == __USER_CS;
19383 + return cs == __USER_CS;
19384 #else
19385 /* Headers are too twisted for this to go in paravirt.h. */
19386 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
19387 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
19388 #endif
19389 }
19390
19391 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
19392 * Traps from the kernel do not save sp and ss.
19393 * Use the helper function to retrieve sp.
19394 */
19395 - if (offset == offsetof(struct pt_regs, sp) &&
19396 - regs->cs == __KERNEL_CS)
19397 - return kernel_stack_pointer(regs);
19398 + if (offset == offsetof(struct pt_regs, sp)) {
19399 + unsigned long cs = regs->cs & 0xffff;
19400 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
19401 + return kernel_stack_pointer(regs);
19402 + }
19403 #endif
19404 return *(unsigned long *)((unsigned long)regs + offset);
19405 }
19406 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
19407 index ae0e241..e80b10b 100644
19408 --- a/arch/x86/include/asm/qrwlock.h
19409 +++ b/arch/x86/include/asm/qrwlock.h
19410 @@ -7,8 +7,8 @@
19411 #define queue_write_unlock queue_write_unlock
19412 static inline void queue_write_unlock(struct qrwlock *lock)
19413 {
19414 - barrier();
19415 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
19416 + barrier();
19417 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
19418 }
19419 #endif
19420
19421 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
19422 index 9c6b890..5305f53 100644
19423 --- a/arch/x86/include/asm/realmode.h
19424 +++ b/arch/x86/include/asm/realmode.h
19425 @@ -22,16 +22,14 @@ struct real_mode_header {
19426 #endif
19427 /* APM/BIOS reboot */
19428 u32 machine_real_restart_asm;
19429 -#ifdef CONFIG_X86_64
19430 u32 machine_real_restart_seg;
19431 -#endif
19432 };
19433
19434 /* This must match data at trampoline_32/64.S */
19435 struct trampoline_header {
19436 #ifdef CONFIG_X86_32
19437 u32 start;
19438 - u16 gdt_pad;
19439 + u16 boot_cs;
19440 u16 gdt_limit;
19441 u32 gdt_base;
19442 #else
19443 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
19444 index a82c4f1..ac45053 100644
19445 --- a/arch/x86/include/asm/reboot.h
19446 +++ b/arch/x86/include/asm/reboot.h
19447 @@ -6,13 +6,13 @@
19448 struct pt_regs;
19449
19450 struct machine_ops {
19451 - void (*restart)(char *cmd);
19452 - void (*halt)(void);
19453 - void (*power_off)(void);
19454 + void (* __noreturn restart)(char *cmd);
19455 + void (* __noreturn halt)(void);
19456 + void (* __noreturn power_off)(void);
19457 void (*shutdown)(void);
19458 void (*crash_shutdown)(struct pt_regs *);
19459 - void (*emergency_restart)(void);
19460 -};
19461 + void (* __noreturn emergency_restart)(void);
19462 +} __no_const;
19463
19464 extern struct machine_ops machine_ops;
19465
19466 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19467 index 8f7866a..e442f20 100644
19468 --- a/arch/x86/include/asm/rmwcc.h
19469 +++ b/arch/x86/include/asm/rmwcc.h
19470 @@ -3,7 +3,34 @@
19471
19472 #ifdef CC_HAVE_ASM_GOTO
19473
19474 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19475 +#ifdef CONFIG_PAX_REFCOUNT
19476 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19477 +do { \
19478 + asm_volatile_goto (fullop \
19479 + ";jno 0f\n" \
19480 + fullantiop \
19481 + ";int $4\n0:\n" \
19482 + _ASM_EXTABLE(0b, 0b) \
19483 + ";j" cc " %l[cc_label]" \
19484 + : : "m" (var), ## __VA_ARGS__ \
19485 + : "memory" : cc_label); \
19486 + return 0; \
19487 +cc_label: \
19488 + return 1; \
19489 +} while (0)
19490 +#else
19491 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19492 +do { \
19493 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19494 + : : "m" (var), ## __VA_ARGS__ \
19495 + : "memory" : cc_label); \
19496 + return 0; \
19497 +cc_label: \
19498 + return 1; \
19499 +} while (0)
19500 +#endif
19501 +
19502 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19503 do { \
19504 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19505 : : "m" (var), ## __VA_ARGS__ \
19506 @@ -13,15 +40,46 @@ cc_label: \
19507 return 1; \
19508 } while (0)
19509
19510 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19511 - __GEN_RMWcc(op " " arg0, var, cc)
19512 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19513 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19514
19515 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19516 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19517 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19518 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19519 +
19520 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19521 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19522 +
19523 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19524 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19525
19526 #else /* !CC_HAVE_ASM_GOTO */
19527
19528 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19529 +#ifdef CONFIG_PAX_REFCOUNT
19530 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19531 +do { \
19532 + char c; \
19533 + asm volatile (fullop \
19534 + ";jno 0f\n" \
19535 + fullantiop \
19536 + ";int $4\n0:\n" \
19537 + _ASM_EXTABLE(0b, 0b) \
19538 + "; set" cc " %1" \
19539 + : "+m" (var), "=qm" (c) \
19540 + : __VA_ARGS__ : "memory"); \
19541 + return c != 0; \
19542 +} while (0)
19543 +#else
19544 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19545 +do { \
19546 + char c; \
19547 + asm volatile (fullop "; set" cc " %1" \
19548 + : "+m" (var), "=qm" (c) \
19549 + : __VA_ARGS__ : "memory"); \
19550 + return c != 0; \
19551 +} while (0)
19552 +#endif
19553 +
19554 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19555 do { \
19556 char c; \
19557 asm volatile (fullop "; set" cc " %1" \
19558 @@ -30,11 +88,17 @@ do { \
19559 return c != 0; \
19560 } while (0)
19561
19562 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19563 - __GEN_RMWcc(op " " arg0, var, cc)
19564 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19565 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19566 +
19567 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19568 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19569 +
19570 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19571 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19572
19573 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19574 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19575 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19576 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19577
19578 #endif /* CC_HAVE_ASM_GOTO */
19579
19580 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19581 index cad82c9..2e5c5c1 100644
19582 --- a/arch/x86/include/asm/rwsem.h
19583 +++ b/arch/x86/include/asm/rwsem.h
19584 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19585 {
19586 asm volatile("# beginning down_read\n\t"
19587 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19588 +
19589 +#ifdef CONFIG_PAX_REFCOUNT
19590 + "jno 0f\n"
19591 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19592 + "int $4\n0:\n"
19593 + _ASM_EXTABLE(0b, 0b)
19594 +#endif
19595 +
19596 /* adds 0x00000001 */
19597 " jns 1f\n"
19598 " call call_rwsem_down_read_failed\n"
19599 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19600 "1:\n\t"
19601 " mov %1,%2\n\t"
19602 " add %3,%2\n\t"
19603 +
19604 +#ifdef CONFIG_PAX_REFCOUNT
19605 + "jno 0f\n"
19606 + "sub %3,%2\n"
19607 + "int $4\n0:\n"
19608 + _ASM_EXTABLE(0b, 0b)
19609 +#endif
19610 +
19611 " jle 2f\n\t"
19612 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19613 " jnz 1b\n\t"
19614 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19615 long tmp;
19616 asm volatile("# beginning down_write\n\t"
19617 LOCK_PREFIX " xadd %1,(%2)\n\t"
19618 +
19619 +#ifdef CONFIG_PAX_REFCOUNT
19620 + "jno 0f\n"
19621 + "mov %1,(%2)\n"
19622 + "int $4\n0:\n"
19623 + _ASM_EXTABLE(0b, 0b)
19624 +#endif
19625 +
19626 /* adds 0xffff0001, returns the old value */
19627 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19628 /* was the active mask 0 before? */
19629 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19630 long tmp;
19631 asm volatile("# beginning __up_read\n\t"
19632 LOCK_PREFIX " xadd %1,(%2)\n\t"
19633 +
19634 +#ifdef CONFIG_PAX_REFCOUNT
19635 + "jno 0f\n"
19636 + "mov %1,(%2)\n"
19637 + "int $4\n0:\n"
19638 + _ASM_EXTABLE(0b, 0b)
19639 +#endif
19640 +
19641 /* subtracts 1, returns the old value */
19642 " jns 1f\n\t"
19643 " call call_rwsem_wake\n" /* expects old value in %edx */
19644 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19645 long tmp;
19646 asm volatile("# beginning __up_write\n\t"
19647 LOCK_PREFIX " xadd %1,(%2)\n\t"
19648 +
19649 +#ifdef CONFIG_PAX_REFCOUNT
19650 + "jno 0f\n"
19651 + "mov %1,(%2)\n"
19652 + "int $4\n0:\n"
19653 + _ASM_EXTABLE(0b, 0b)
19654 +#endif
19655 +
19656 /* subtracts 0xffff0001, returns the old value */
19657 " jns 1f\n\t"
19658 " call call_rwsem_wake\n" /* expects old value in %edx */
19659 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19660 {
19661 asm volatile("# beginning __downgrade_write\n\t"
19662 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19663 +
19664 +#ifdef CONFIG_PAX_REFCOUNT
19665 + "jno 0f\n"
19666 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19667 + "int $4\n0:\n"
19668 + _ASM_EXTABLE(0b, 0b)
19669 +#endif
19670 +
19671 /*
19672 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19673 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19674 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19675 */
19676 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19677 {
19678 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19679 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19680 +
19681 +#ifdef CONFIG_PAX_REFCOUNT
19682 + "jno 0f\n"
19683 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19684 + "int $4\n0:\n"
19685 + _ASM_EXTABLE(0b, 0b)
19686 +#endif
19687 +
19688 : "+m" (sem->count)
19689 : "er" (delta));
19690 }
19691 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19692 */
19693 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19694 {
19695 - return delta + xadd(&sem->count, delta);
19696 + return delta + xadd_check_overflow(&sem->count, delta);
19697 }
19698
19699 #endif /* __KERNEL__ */
19700 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19701 index 6f1c3a8..7744f19 100644
19702 --- a/arch/x86/include/asm/segment.h
19703 +++ b/arch/x86/include/asm/segment.h
19704 @@ -64,10 +64,15 @@
19705 * 26 - ESPFIX small SS
19706 * 27 - per-cpu [ offset to per-cpu data area ]
19707 * 28 - stack_canary-20 [ for stack protector ]
19708 - * 29 - unused
19709 - * 30 - unused
19710 + * 29 - PCI BIOS CS
19711 + * 30 - PCI BIOS DS
19712 * 31 - TSS for double fault handler
19713 */
19714 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19715 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19716 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19717 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19718 +
19719 #define GDT_ENTRY_TLS_MIN 6
19720 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19721
19722 @@ -79,6 +84,8 @@
19723
19724 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19725
19726 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19727 +
19728 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19729
19730 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19731 @@ -104,6 +111,12 @@
19732 #define __KERNEL_STACK_CANARY 0
19733 #endif
19734
19735 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19736 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19737 +
19738 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19739 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19740 +
19741 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19742
19743 /*
19744 @@ -141,7 +154,7 @@
19745 */
19746
19747 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19748 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19749 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19750
19751
19752 #else
19753 @@ -165,6 +178,8 @@
19754 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19755 #define __USER32_DS __USER_DS
19756
19757 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19758 +
19759 #define GDT_ENTRY_TSS 8 /* needs two entries */
19760 #define GDT_ENTRY_LDT 10 /* needs two entries */
19761 #define GDT_ENTRY_TLS_MIN 12
19762 @@ -173,6 +188,8 @@
19763 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19764 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19765
19766 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19767 +
19768 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19769 #define FS_TLS 0
19770 #define GS_TLS 1
19771 @@ -180,12 +197,14 @@
19772 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19773 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19774
19775 -#define GDT_ENTRIES 16
19776 +#define GDT_ENTRIES 17
19777
19778 #endif
19779
19780 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19781 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19782 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19783 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19784 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19785 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19786 #ifndef CONFIG_PARAVIRT
19787 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19788 {
19789 unsigned long __limit;
19790 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19791 - return __limit + 1;
19792 + return __limit;
19793 }
19794
19795 #endif /* !__ASSEMBLY__ */
19796 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19797 index 8d3120f..352b440 100644
19798 --- a/arch/x86/include/asm/smap.h
19799 +++ b/arch/x86/include/asm/smap.h
19800 @@ -25,11 +25,40 @@
19801
19802 #include <asm/alternative-asm.h>
19803
19804 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19805 +#define ASM_PAX_OPEN_USERLAND \
19806 + 661: jmp 663f; \
19807 + .pushsection .altinstr_replacement, "a" ; \
19808 + 662: pushq %rax; nop; \
19809 + .popsection ; \
19810 + .pushsection .altinstructions, "a" ; \
19811 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19812 + .popsection ; \
19813 + call __pax_open_userland; \
19814 + popq %rax; \
19815 + 663:
19816 +
19817 +#define ASM_PAX_CLOSE_USERLAND \
19818 + 661: jmp 663f; \
19819 + .pushsection .altinstr_replacement, "a" ; \
19820 + 662: pushq %rax; nop; \
19821 + .popsection; \
19822 + .pushsection .altinstructions, "a" ; \
19823 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19824 + .popsection; \
19825 + call __pax_close_userland; \
19826 + popq %rax; \
19827 + 663:
19828 +#else
19829 +#define ASM_PAX_OPEN_USERLAND
19830 +#define ASM_PAX_CLOSE_USERLAND
19831 +#endif
19832 +
19833 #ifdef CONFIG_X86_SMAP
19834
19835 #define ASM_CLAC \
19836 661: ASM_NOP3 ; \
19837 - .pushsection .altinstr_replacement, "ax" ; \
19838 + .pushsection .altinstr_replacement, "a" ; \
19839 662: __ASM_CLAC ; \
19840 .popsection ; \
19841 .pushsection .altinstructions, "a" ; \
19842 @@ -38,7 +67,7 @@
19843
19844 #define ASM_STAC \
19845 661: ASM_NOP3 ; \
19846 - .pushsection .altinstr_replacement, "ax" ; \
19847 + .pushsection .altinstr_replacement, "a" ; \
19848 662: __ASM_STAC ; \
19849 .popsection ; \
19850 .pushsection .altinstructions, "a" ; \
19851 @@ -56,6 +85,37 @@
19852
19853 #include <asm/alternative.h>
19854
19855 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19856 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19857 +
19858 +extern void __pax_open_userland(void);
19859 +static __always_inline unsigned long pax_open_userland(void)
19860 +{
19861 +
19862 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19863 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19864 + :
19865 + : [open] "i" (__pax_open_userland)
19866 + : "memory", "rax");
19867 +#endif
19868 +
19869 + return 0;
19870 +}
19871 +
19872 +extern void __pax_close_userland(void);
19873 +static __always_inline unsigned long pax_close_userland(void)
19874 +{
19875 +
19876 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19877 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19878 + :
19879 + : [close] "i" (__pax_close_userland)
19880 + : "memory", "rax");
19881 +#endif
19882 +
19883 + return 0;
19884 +}
19885 +
19886 #ifdef CONFIG_X86_SMAP
19887
19888 static __always_inline void clac(void)
19889 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19890 index 8cd27e0..7f05ec8 100644
19891 --- a/arch/x86/include/asm/smp.h
19892 +++ b/arch/x86/include/asm/smp.h
19893 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19894 /* cpus sharing the last level cache: */
19895 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19896 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19897 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19898 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19899
19900 static inline struct cpumask *cpu_sibling_mask(int cpu)
19901 {
19902 @@ -78,7 +78,7 @@ struct smp_ops {
19903
19904 void (*send_call_func_ipi)(const struct cpumask *mask);
19905 void (*send_call_func_single_ipi)(int cpu);
19906 -};
19907 +} __no_const;
19908
19909 /* Globals due to paravirt */
19910 extern void set_cpu_sibling_map(int cpu);
19911 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19912 extern int safe_smp_processor_id(void);
19913
19914 #elif defined(CONFIG_X86_64_SMP)
19915 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19916 -
19917 -#define stack_smp_processor_id() \
19918 -({ \
19919 - struct thread_info *ti; \
19920 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19921 - ti->cpu; \
19922 -})
19923 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19924 +#define stack_smp_processor_id() raw_smp_processor_id()
19925 #define safe_smp_processor_id() smp_processor_id()
19926
19927 #endif
19928 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19929 index 54f1c80..39362a5 100644
19930 --- a/arch/x86/include/asm/spinlock.h
19931 +++ b/arch/x86/include/asm/spinlock.h
19932 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19933 static inline void arch_read_lock(arch_rwlock_t *rw)
19934 {
19935 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19936 +
19937 +#ifdef CONFIG_PAX_REFCOUNT
19938 + "jno 0f\n"
19939 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19940 + "int $4\n0:\n"
19941 + _ASM_EXTABLE(0b, 0b)
19942 +#endif
19943 +
19944 "jns 1f\n"
19945 "call __read_lock_failed\n\t"
19946 "1:\n"
19947 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19948 static inline void arch_write_lock(arch_rwlock_t *rw)
19949 {
19950 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19951 +
19952 +#ifdef CONFIG_PAX_REFCOUNT
19953 + "jno 0f\n"
19954 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19955 + "int $4\n0:\n"
19956 + _ASM_EXTABLE(0b, 0b)
19957 +#endif
19958 +
19959 "jz 1f\n"
19960 "call __write_lock_failed\n\t"
19961 "1:\n"
19962 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19963
19964 static inline void arch_read_unlock(arch_rwlock_t *rw)
19965 {
19966 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19967 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19968 +
19969 +#ifdef CONFIG_PAX_REFCOUNT
19970 + "jno 0f\n"
19971 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19972 + "int $4\n0:\n"
19973 + _ASM_EXTABLE(0b, 0b)
19974 +#endif
19975 +
19976 :"+m" (rw->lock) : : "memory");
19977 }
19978
19979 static inline void arch_write_unlock(arch_rwlock_t *rw)
19980 {
19981 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19982 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19983 +
19984 +#ifdef CONFIG_PAX_REFCOUNT
19985 + "jno 0f\n"
19986 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19987 + "int $4\n0:\n"
19988 + _ASM_EXTABLE(0b, 0b)
19989 +#endif
19990 +
19991 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19992 }
19993 #else
19994 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19995 index 6a99859..03cb807 100644
19996 --- a/arch/x86/include/asm/stackprotector.h
19997 +++ b/arch/x86/include/asm/stackprotector.h
19998 @@ -47,7 +47,7 @@
19999 * head_32 for boot CPU and setup_per_cpu_areas() for others.
20000 */
20001 #define GDT_STACK_CANARY_INIT \
20002 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
20003 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
20004
20005 /*
20006 * Initialize the stackprotector canary value.
20007 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
20008
20009 static inline void load_stack_canary_segment(void)
20010 {
20011 -#ifdef CONFIG_X86_32
20012 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
20013 asm volatile ("mov %0, %%gs" : : "r" (0));
20014 #endif
20015 }
20016 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
20017 index 70bbe39..4ae2bd4 100644
20018 --- a/arch/x86/include/asm/stacktrace.h
20019 +++ b/arch/x86/include/asm/stacktrace.h
20020 @@ -11,28 +11,20 @@
20021
20022 extern int kstack_depth_to_print;
20023
20024 -struct thread_info;
20025 +struct task_struct;
20026 struct stacktrace_ops;
20027
20028 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
20029 - unsigned long *stack,
20030 - unsigned long bp,
20031 - const struct stacktrace_ops *ops,
20032 - void *data,
20033 - unsigned long *end,
20034 - int *graph);
20035 +typedef unsigned long walk_stack_t(struct task_struct *task,
20036 + void *stack_start,
20037 + unsigned long *stack,
20038 + unsigned long bp,
20039 + const struct stacktrace_ops *ops,
20040 + void *data,
20041 + unsigned long *end,
20042 + int *graph);
20043
20044 -extern unsigned long
20045 -print_context_stack(struct thread_info *tinfo,
20046 - unsigned long *stack, unsigned long bp,
20047 - const struct stacktrace_ops *ops, void *data,
20048 - unsigned long *end, int *graph);
20049 -
20050 -extern unsigned long
20051 -print_context_stack_bp(struct thread_info *tinfo,
20052 - unsigned long *stack, unsigned long bp,
20053 - const struct stacktrace_ops *ops, void *data,
20054 - unsigned long *end, int *graph);
20055 +extern walk_stack_t print_context_stack;
20056 +extern walk_stack_t print_context_stack_bp;
20057
20058 /* Generic stack tracer with callbacks */
20059
20060 @@ -40,7 +32,7 @@ struct stacktrace_ops {
20061 void (*address)(void *data, unsigned long address, int reliable);
20062 /* On negative return stop dumping */
20063 int (*stack)(void *data, char *name);
20064 - walk_stack_t walk_stack;
20065 + walk_stack_t *walk_stack;
20066 };
20067
20068 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
20069 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
20070 index d7f3b3b..3cc39f1 100644
20071 --- a/arch/x86/include/asm/switch_to.h
20072 +++ b/arch/x86/include/asm/switch_to.h
20073 @@ -108,7 +108,7 @@ do { \
20074 "call __switch_to\n\t" \
20075 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
20076 __switch_canary \
20077 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
20078 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
20079 "movq %%rax,%%rdi\n\t" \
20080 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
20081 "jnz ret_from_fork\n\t" \
20082 @@ -119,7 +119,7 @@ do { \
20083 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
20084 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
20085 [_tif_fork] "i" (_TIF_FORK), \
20086 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
20087 + [thread_info] "m" (current_tinfo), \
20088 [current_task] "m" (current_task) \
20089 __switch_canary_iparam \
20090 : "memory", "cc" __EXTRA_CLOBBER)
20091 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
20092 index 8540538..4b0b5e9 100644
20093 --- a/arch/x86/include/asm/thread_info.h
20094 +++ b/arch/x86/include/asm/thread_info.h
20095 @@ -24,7 +24,6 @@ struct exec_domain;
20096 #include <linux/atomic.h>
20097
20098 struct thread_info {
20099 - struct task_struct *task; /* main task structure */
20100 struct exec_domain *exec_domain; /* execution domain */
20101 __u32 flags; /* low level flags */
20102 __u32 status; /* thread synchronous flags */
20103 @@ -33,13 +32,13 @@ struct thread_info {
20104 mm_segment_t addr_limit;
20105 struct restart_block restart_block;
20106 void __user *sysenter_return;
20107 + unsigned long lowest_stack;
20108 unsigned int sig_on_uaccess_error:1;
20109 unsigned int uaccess_err:1; /* uaccess failed */
20110 };
20111
20112 -#define INIT_THREAD_INFO(tsk) \
20113 +#define INIT_THREAD_INFO \
20114 { \
20115 - .task = &tsk, \
20116 .exec_domain = &default_exec_domain, \
20117 .flags = 0, \
20118 .cpu = 0, \
20119 @@ -50,7 +49,7 @@ struct thread_info {
20120 }, \
20121 }
20122
20123 -#define init_thread_info (init_thread_union.thread_info)
20124 +#define init_thread_info (init_thread_union.stack)
20125 #define init_stack (init_thread_union.stack)
20126
20127 #else /* !__ASSEMBLY__ */
20128 @@ -91,6 +90,7 @@ struct thread_info {
20129 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
20130 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
20131 #define TIF_X32 30 /* 32-bit native x86-64 binary */
20132 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
20133
20134 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
20135 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
20136 @@ -115,17 +115,18 @@ struct thread_info {
20137 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
20138 #define _TIF_ADDR32 (1 << TIF_ADDR32)
20139 #define _TIF_X32 (1 << TIF_X32)
20140 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
20141
20142 /* work to do in syscall_trace_enter() */
20143 #define _TIF_WORK_SYSCALL_ENTRY \
20144 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
20145 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
20146 - _TIF_NOHZ)
20147 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20148
20149 /* work to do in syscall_trace_leave() */
20150 #define _TIF_WORK_SYSCALL_EXIT \
20151 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
20152 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
20153 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
20154
20155 /* work to do on interrupt/exception return */
20156 #define _TIF_WORK_MASK \
20157 @@ -136,7 +137,7 @@ struct thread_info {
20158 /* work to do on any return to user space */
20159 #define _TIF_ALLWORK_MASK \
20160 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
20161 - _TIF_NOHZ)
20162 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20163
20164 /* Only used for 64 bit */
20165 #define _TIF_DO_NOTIFY_MASK \
20166 @@ -151,7 +152,6 @@ struct thread_info {
20167 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
20168
20169 #define STACK_WARN (THREAD_SIZE/8)
20170 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
20171
20172 /*
20173 * macros/functions for gaining access to the thread information structure
20174 @@ -162,26 +162,18 @@ struct thread_info {
20175
20176 DECLARE_PER_CPU(unsigned long, kernel_stack);
20177
20178 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
20179 +
20180 static inline struct thread_info *current_thread_info(void)
20181 {
20182 - struct thread_info *ti;
20183 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
20184 - KERNEL_STACK_OFFSET - THREAD_SIZE);
20185 - return ti;
20186 + return this_cpu_read_stable(current_tinfo);
20187 }
20188
20189 #else /* !__ASSEMBLY__ */
20190
20191 /* how to get the thread information struct from ASM */
20192 #define GET_THREAD_INFO(reg) \
20193 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
20194 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
20195 -
20196 -/*
20197 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
20198 - * a certain register (to be used in assembler memory operands).
20199 - */
20200 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
20201 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
20202
20203 #endif
20204
20205 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
20206 extern void arch_task_cache_init(void);
20207 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
20208 extern void arch_release_task_struct(struct task_struct *tsk);
20209 +
20210 +#define __HAVE_THREAD_FUNCTIONS
20211 +#define task_thread_info(task) (&(task)->tinfo)
20212 +#define task_stack_page(task) ((task)->stack)
20213 +#define setup_thread_stack(p, org) do {} while (0)
20214 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
20215 +
20216 #endif
20217 #endif /* _ASM_X86_THREAD_INFO_H */
20218 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
20219 index 04905bf..1178cdf 100644
20220 --- a/arch/x86/include/asm/tlbflush.h
20221 +++ b/arch/x86/include/asm/tlbflush.h
20222 @@ -17,18 +17,44 @@
20223
20224 static inline void __native_flush_tlb(void)
20225 {
20226 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20227 + u64 descriptor[2];
20228 +
20229 + descriptor[0] = PCID_KERNEL;
20230 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
20231 + return;
20232 + }
20233 +
20234 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20235 + if (static_cpu_has(X86_FEATURE_PCID)) {
20236 + unsigned int cpu = raw_get_cpu();
20237 +
20238 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
20239 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
20240 + raw_put_cpu_no_resched();
20241 + return;
20242 + }
20243 +#endif
20244 +
20245 native_write_cr3(native_read_cr3());
20246 }
20247
20248 static inline void __native_flush_tlb_global_irq_disabled(void)
20249 {
20250 - unsigned long cr4;
20251 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20252 + u64 descriptor[2];
20253
20254 - cr4 = native_read_cr4();
20255 - /* clear PGE */
20256 - native_write_cr4(cr4 & ~X86_CR4_PGE);
20257 - /* write old PGE again and flush TLBs */
20258 - native_write_cr4(cr4);
20259 + descriptor[0] = PCID_KERNEL;
20260 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
20261 + } else {
20262 + unsigned long cr4;
20263 +
20264 + cr4 = native_read_cr4();
20265 + /* clear PGE */
20266 + native_write_cr4(cr4 & ~X86_CR4_PGE);
20267 + /* write old PGE again and flush TLBs */
20268 + native_write_cr4(cr4);
20269 + }
20270 }
20271
20272 static inline void __native_flush_tlb_global(void)
20273 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
20274
20275 static inline void __native_flush_tlb_single(unsigned long addr)
20276 {
20277 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20278 + u64 descriptor[2];
20279 +
20280 + descriptor[0] = PCID_KERNEL;
20281 + descriptor[1] = addr;
20282 +
20283 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20284 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
20285 + if (addr < TASK_SIZE_MAX)
20286 + descriptor[1] += pax_user_shadow_base;
20287 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20288 + }
20289 +
20290 + descriptor[0] = PCID_USER;
20291 + descriptor[1] = addr;
20292 +#endif
20293 +
20294 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20295 + return;
20296 + }
20297 +
20298 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20299 + if (static_cpu_has(X86_FEATURE_PCID)) {
20300 + unsigned int cpu = raw_get_cpu();
20301 +
20302 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
20303 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20304 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
20305 + raw_put_cpu_no_resched();
20306 +
20307 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
20308 + addr += pax_user_shadow_base;
20309 + }
20310 +#endif
20311 +
20312 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20313 }
20314
20315 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
20316 index 0d592e0..526f797 100644
20317 --- a/arch/x86/include/asm/uaccess.h
20318 +++ b/arch/x86/include/asm/uaccess.h
20319 @@ -7,6 +7,7 @@
20320 #include <linux/compiler.h>
20321 #include <linux/thread_info.h>
20322 #include <linux/string.h>
20323 +#include <linux/spinlock.h>
20324 #include <asm/asm.h>
20325 #include <asm/page.h>
20326 #include <asm/smap.h>
20327 @@ -29,7 +30,12 @@
20328
20329 #define get_ds() (KERNEL_DS)
20330 #define get_fs() (current_thread_info()->addr_limit)
20331 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20332 +void __set_fs(mm_segment_t x);
20333 +void set_fs(mm_segment_t x);
20334 +#else
20335 #define set_fs(x) (current_thread_info()->addr_limit = (x))
20336 +#endif
20337
20338 #define segment_eq(a, b) ((a).seg == (b).seg)
20339
20340 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
20341 * checks that the pointer is in the user space range - after calling
20342 * this function, memory access functions may still return -EFAULT.
20343 */
20344 -#define access_ok(type, addr, size) \
20345 - likely(!__range_not_ok(addr, size, user_addr_max()))
20346 +extern int _cond_resched(void);
20347 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
20348 +#define access_ok(type, addr, size) \
20349 +({ \
20350 + unsigned long __size = size; \
20351 + unsigned long __addr = (unsigned long)addr; \
20352 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
20353 + if (__ret_ao && __size) { \
20354 + unsigned long __addr_ao = __addr & PAGE_MASK; \
20355 + unsigned long __end_ao = __addr + __size - 1; \
20356 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
20357 + while (__addr_ao <= __end_ao) { \
20358 + char __c_ao; \
20359 + __addr_ao += PAGE_SIZE; \
20360 + if (__size > PAGE_SIZE) \
20361 + _cond_resched(); \
20362 + if (__get_user(__c_ao, (char __user *)__addr)) \
20363 + break; \
20364 + if (type != VERIFY_WRITE) { \
20365 + __addr = __addr_ao; \
20366 + continue; \
20367 + } \
20368 + if (__put_user(__c_ao, (char __user *)__addr)) \
20369 + break; \
20370 + __addr = __addr_ao; \
20371 + } \
20372 + } \
20373 + } \
20374 + __ret_ao; \
20375 +})
20376
20377 /*
20378 * The exception table consists of pairs of addresses relative to the
20379 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20380 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
20381 __chk_user_ptr(ptr); \
20382 might_fault(); \
20383 + pax_open_userland(); \
20384 asm volatile("call __get_user_%P3" \
20385 : "=a" (__ret_gu), "=r" (__val_gu) \
20386 : "0" (ptr), "i" (sizeof(*(ptr)))); \
20387 (x) = (__typeof__(*(ptr))) __val_gu; \
20388 + pax_close_userland(); \
20389 __ret_gu; \
20390 })
20391
20392 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20393 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
20394 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
20395
20396 -
20397 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20398 +#define __copyuser_seg "gs;"
20399 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
20400 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
20401 +#else
20402 +#define __copyuser_seg
20403 +#define __COPYUSER_SET_ES
20404 +#define __COPYUSER_RESTORE_ES
20405 +#endif
20406
20407 #ifdef CONFIG_X86_32
20408 #define __put_user_asm_u64(x, addr, err, errret) \
20409 asm volatile(ASM_STAC "\n" \
20410 - "1: movl %%eax,0(%2)\n" \
20411 - "2: movl %%edx,4(%2)\n" \
20412 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
20413 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
20414 "3: " ASM_CLAC "\n" \
20415 ".section .fixup,\"ax\"\n" \
20416 "4: movl %3,%0\n" \
20417 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20418
20419 #define __put_user_asm_ex_u64(x, addr) \
20420 asm volatile(ASM_STAC "\n" \
20421 - "1: movl %%eax,0(%1)\n" \
20422 - "2: movl %%edx,4(%1)\n" \
20423 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
20424 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
20425 "3: " ASM_CLAC "\n" \
20426 _ASM_EXTABLE_EX(1b, 2b) \
20427 _ASM_EXTABLE_EX(2b, 3b) \
20428 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
20429 __typeof__(*(ptr)) __pu_val; \
20430 __chk_user_ptr(ptr); \
20431 might_fault(); \
20432 - __pu_val = x; \
20433 + __pu_val = (x); \
20434 + pax_open_userland(); \
20435 switch (sizeof(*(ptr))) { \
20436 case 1: \
20437 __put_user_x(1, __pu_val, ptr, __ret_pu); \
20438 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
20439 __put_user_x(X, __pu_val, ptr, __ret_pu); \
20440 break; \
20441 } \
20442 + pax_close_userland(); \
20443 __ret_pu; \
20444 })
20445
20446 @@ -355,8 +401,10 @@ do { \
20447 } while (0)
20448
20449 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20450 +do { \
20451 + pax_open_userland(); \
20452 asm volatile(ASM_STAC "\n" \
20453 - "1: mov"itype" %2,%"rtype"1\n" \
20454 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
20455 "2: " ASM_CLAC "\n" \
20456 ".section .fixup,\"ax\"\n" \
20457 "3: mov %3,%0\n" \
20458 @@ -364,8 +412,10 @@ do { \
20459 " jmp 2b\n" \
20460 ".previous\n" \
20461 _ASM_EXTABLE(1b, 3b) \
20462 - : "=r" (err), ltype(x) \
20463 - : "m" (__m(addr)), "i" (errret), "0" (err))
20464 + : "=r" (err), ltype (x) \
20465 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
20466 + pax_close_userland(); \
20467 +} while (0)
20468
20469 #define __get_user_size_ex(x, ptr, size) \
20470 do { \
20471 @@ -389,7 +439,7 @@ do { \
20472 } while (0)
20473
20474 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20475 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20476 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20477 "2:\n" \
20478 _ASM_EXTABLE_EX(1b, 2b) \
20479 : ltype(x) : "m" (__m(addr)))
20480 @@ -406,13 +456,24 @@ do { \
20481 int __gu_err; \
20482 unsigned long __gu_val; \
20483 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20484 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
20485 + (x) = (__typeof__(*(ptr)))__gu_val; \
20486 __gu_err; \
20487 })
20488
20489 /* FIXME: this hack is definitely wrong -AK */
20490 struct __large_struct { unsigned long buf[100]; };
20491 -#define __m(x) (*(struct __large_struct __user *)(x))
20492 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20493 +#define ____m(x) \
20494 +({ \
20495 + unsigned long ____x = (unsigned long)(x); \
20496 + if (____x < pax_user_shadow_base) \
20497 + ____x += pax_user_shadow_base; \
20498 + (typeof(x))____x; \
20499 +})
20500 +#else
20501 +#define ____m(x) (x)
20502 +#endif
20503 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20504
20505 /*
20506 * Tell gcc we read from memory instead of writing: this is because
20507 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20508 * aliasing issues.
20509 */
20510 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20511 +do { \
20512 + pax_open_userland(); \
20513 asm volatile(ASM_STAC "\n" \
20514 - "1: mov"itype" %"rtype"1,%2\n" \
20515 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20516 "2: " ASM_CLAC "\n" \
20517 ".section .fixup,\"ax\"\n" \
20518 "3: mov %3,%0\n" \
20519 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20520 ".previous\n" \
20521 _ASM_EXTABLE(1b, 3b) \
20522 : "=r"(err) \
20523 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20524 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20525 + pax_close_userland(); \
20526 +} while (0)
20527
20528 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20529 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20530 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20531 "2:\n" \
20532 _ASM_EXTABLE_EX(1b, 2b) \
20533 : : ltype(x), "m" (__m(addr)))
20534 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20535 */
20536 #define uaccess_try do { \
20537 current_thread_info()->uaccess_err = 0; \
20538 + pax_open_userland(); \
20539 stac(); \
20540 barrier();
20541
20542 #define uaccess_catch(err) \
20543 clac(); \
20544 + pax_close_userland(); \
20545 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20546 } while (0)
20547
20548 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20549 * On error, the variable @x is set to zero.
20550 */
20551
20552 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20553 +#define __get_user(x, ptr) get_user((x), (ptr))
20554 +#else
20555 #define __get_user(x, ptr) \
20556 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20557 +#endif
20558
20559 /**
20560 * __put_user: - Write a simple value into user space, with less checking.
20561 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20562 * Returns zero on success, or -EFAULT on error.
20563 */
20564
20565 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20566 +#define __put_user(x, ptr) put_user((x), (ptr))
20567 +#else
20568 #define __put_user(x, ptr) \
20569 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20570 +#endif
20571
20572 #define __get_user_unaligned __get_user
20573 #define __put_user_unaligned __put_user
20574 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20575 #define get_user_ex(x, ptr) do { \
20576 unsigned long __gue_val; \
20577 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20578 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20579 + (x) = (__typeof__(*(ptr)))__gue_val; \
20580 } while (0)
20581
20582 #define put_user_try uaccess_try
20583 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20584 __typeof__(ptr) __uval = (uval); \
20585 __typeof__(*(ptr)) __old = (old); \
20586 __typeof__(*(ptr)) __new = (new); \
20587 + pax_open_userland(); \
20588 switch (size) { \
20589 case 1: \
20590 { \
20591 asm volatile("\t" ASM_STAC "\n" \
20592 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20593 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20594 "2:\t" ASM_CLAC "\n" \
20595 "\t.section .fixup, \"ax\"\n" \
20596 "3:\tmov %3, %0\n" \
20597 "\tjmp 2b\n" \
20598 "\t.previous\n" \
20599 _ASM_EXTABLE(1b, 3b) \
20600 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20601 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20602 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20603 : "memory" \
20604 ); \
20605 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20606 case 2: \
20607 { \
20608 asm volatile("\t" ASM_STAC "\n" \
20609 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20610 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20611 "2:\t" ASM_CLAC "\n" \
20612 "\t.section .fixup, \"ax\"\n" \
20613 "3:\tmov %3, %0\n" \
20614 "\tjmp 2b\n" \
20615 "\t.previous\n" \
20616 _ASM_EXTABLE(1b, 3b) \
20617 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20618 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20619 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20620 : "memory" \
20621 ); \
20622 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20623 case 4: \
20624 { \
20625 asm volatile("\t" ASM_STAC "\n" \
20626 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20627 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20628 "2:\t" ASM_CLAC "\n" \
20629 "\t.section .fixup, \"ax\"\n" \
20630 "3:\tmov %3, %0\n" \
20631 "\tjmp 2b\n" \
20632 "\t.previous\n" \
20633 _ASM_EXTABLE(1b, 3b) \
20634 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20635 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20636 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20637 : "memory" \
20638 ); \
20639 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20640 __cmpxchg_wrong_size(); \
20641 \
20642 asm volatile("\t" ASM_STAC "\n" \
20643 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20644 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20645 "2:\t" ASM_CLAC "\n" \
20646 "\t.section .fixup, \"ax\"\n" \
20647 "3:\tmov %3, %0\n" \
20648 "\tjmp 2b\n" \
20649 "\t.previous\n" \
20650 _ASM_EXTABLE(1b, 3b) \
20651 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20652 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20653 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20654 : "memory" \
20655 ); \
20656 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20657 default: \
20658 __cmpxchg_wrong_size(); \
20659 } \
20660 + pax_close_userland(); \
20661 *__uval = __old; \
20662 __ret; \
20663 })
20664 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20665
20666 #define ARCH_HAS_NOCACHE_UACCESS 1
20667
20668 -#ifdef CONFIG_X86_32
20669 -# include <asm/uaccess_32.h>
20670 -#else
20671 -# include <asm/uaccess_64.h>
20672 -#endif
20673 -
20674 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20675 - unsigned n);
20676 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20677 - unsigned n);
20678 -
20679 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20680 # define copy_user_diag __compiletime_error
20681 #else
20682 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20683 extern void copy_user_diag("copy_from_user() buffer size is too small")
20684 copy_from_user_overflow(void);
20685 extern void copy_user_diag("copy_to_user() buffer size is too small")
20686 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20687 +copy_to_user_overflow(void);
20688
20689 #undef copy_user_diag
20690
20691 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20692
20693 extern void
20694 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20695 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20696 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20697 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20698
20699 #else
20700 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20701
20702 #endif
20703
20704 +#ifdef CONFIG_X86_32
20705 +# include <asm/uaccess_32.h>
20706 +#else
20707 +# include <asm/uaccess_64.h>
20708 +#endif
20709 +
20710 static inline unsigned long __must_check
20711 copy_from_user(void *to, const void __user *from, unsigned long n)
20712 {
20713 - int sz = __compiletime_object_size(to);
20714 + size_t sz = __compiletime_object_size(to);
20715
20716 might_fault();
20717
20718 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20719 * case, and do only runtime checking for non-constant sizes.
20720 */
20721
20722 - if (likely(sz < 0 || sz >= n))
20723 - n = _copy_from_user(to, from, n);
20724 - else if(__builtin_constant_p(n))
20725 - copy_from_user_overflow();
20726 - else
20727 - __copy_from_user_overflow(sz, n);
20728 + if (likely(sz != (size_t)-1 && sz < n)) {
20729 + if(__builtin_constant_p(n))
20730 + copy_from_user_overflow();
20731 + else
20732 + __copy_from_user_overflow(sz, n);
20733 + } else if (access_ok(VERIFY_READ, from, n))
20734 + n = __copy_from_user(to, from, n);
20735 + else if ((long)n > 0)
20736 + memset(to, 0, n);
20737
20738 return n;
20739 }
20740 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20741 static inline unsigned long __must_check
20742 copy_to_user(void __user *to, const void *from, unsigned long n)
20743 {
20744 - int sz = __compiletime_object_size(from);
20745 + size_t sz = __compiletime_object_size(from);
20746
20747 might_fault();
20748
20749 /* See the comment in copy_from_user() above. */
20750 - if (likely(sz < 0 || sz >= n))
20751 - n = _copy_to_user(to, from, n);
20752 - else if(__builtin_constant_p(n))
20753 - copy_to_user_overflow();
20754 - else
20755 - __copy_to_user_overflow(sz, n);
20756 + if (likely(sz != (size_t)-1 && sz < n)) {
20757 + if(__builtin_constant_p(n))
20758 + copy_to_user_overflow();
20759 + else
20760 + __copy_to_user_overflow(sz, n);
20761 + } else if (access_ok(VERIFY_WRITE, to, n))
20762 + n = __copy_to_user(to, from, n);
20763
20764 return n;
20765 }
20766 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20767 index 3c03a5d..1071638 100644
20768 --- a/arch/x86/include/asm/uaccess_32.h
20769 +++ b/arch/x86/include/asm/uaccess_32.h
20770 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20771 static __always_inline unsigned long __must_check
20772 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20773 {
20774 + if ((long)n < 0)
20775 + return n;
20776 +
20777 + check_object_size(from, n, true);
20778 +
20779 if (__builtin_constant_p(n)) {
20780 unsigned long ret;
20781
20782 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20783 __copy_to_user(void __user *to, const void *from, unsigned long n)
20784 {
20785 might_fault();
20786 +
20787 return __copy_to_user_inatomic(to, from, n);
20788 }
20789
20790 static __always_inline unsigned long
20791 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20792 {
20793 + if ((long)n < 0)
20794 + return n;
20795 +
20796 /* Avoid zeroing the tail if the copy fails..
20797 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20798 * but as the zeroing behaviour is only significant when n is not
20799 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20800 __copy_from_user(void *to, const void __user *from, unsigned long n)
20801 {
20802 might_fault();
20803 +
20804 + if ((long)n < 0)
20805 + return n;
20806 +
20807 + check_object_size(to, n, false);
20808 +
20809 if (__builtin_constant_p(n)) {
20810 unsigned long ret;
20811
20812 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20813 const void __user *from, unsigned long n)
20814 {
20815 might_fault();
20816 +
20817 + if ((long)n < 0)
20818 + return n;
20819 +
20820 if (__builtin_constant_p(n)) {
20821 unsigned long ret;
20822
20823 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20824 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20825 unsigned long n)
20826 {
20827 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20828 + if ((long)n < 0)
20829 + return n;
20830 +
20831 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20832 }
20833
20834 #endif /* _ASM_X86_UACCESS_32_H */
20835 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20836 index 12a26b9..206c200 100644
20837 --- a/arch/x86/include/asm/uaccess_64.h
20838 +++ b/arch/x86/include/asm/uaccess_64.h
20839 @@ -10,6 +10,9 @@
20840 #include <asm/alternative.h>
20841 #include <asm/cpufeature.h>
20842 #include <asm/page.h>
20843 +#include <asm/pgtable.h>
20844 +
20845 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20846
20847 /*
20848 * Copy To/From Userspace
20849 @@ -17,14 +20,14 @@
20850
20851 /* Handles exceptions in both to and from, but doesn't do access_ok */
20852 __must_check unsigned long
20853 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20854 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20855 __must_check unsigned long
20856 -copy_user_generic_string(void *to, const void *from, unsigned len);
20857 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20858 __must_check unsigned long
20859 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20860 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20861
20862 static __always_inline __must_check unsigned long
20863 -copy_user_generic(void *to, const void *from, unsigned len)
20864 +copy_user_generic(void *to, const void *from, unsigned long len)
20865 {
20866 unsigned ret;
20867
20868 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20869 }
20870
20871 __must_check unsigned long
20872 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20873 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20874
20875 static __always_inline __must_check
20876 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20877 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20878 {
20879 - int ret = 0;
20880 + size_t sz = __compiletime_object_size(dst);
20881 + unsigned ret = 0;
20882 +
20883 + if (size > INT_MAX)
20884 + return size;
20885 +
20886 + check_object_size(dst, size, false);
20887 +
20888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20889 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20890 + return size;
20891 +#endif
20892 +
20893 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20894 + if(__builtin_constant_p(size))
20895 + copy_from_user_overflow();
20896 + else
20897 + __copy_from_user_overflow(sz, size);
20898 + return size;
20899 + }
20900
20901 if (!__builtin_constant_p(size))
20902 - return copy_user_generic(dst, (__force void *)src, size);
20903 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20904 switch (size) {
20905 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20906 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20907 ret, "b", "b", "=q", 1);
20908 return ret;
20909 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20910 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20911 ret, "w", "w", "=r", 2);
20912 return ret;
20913 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20914 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20915 ret, "l", "k", "=r", 4);
20916 return ret;
20917 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20918 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20919 ret, "q", "", "=r", 8);
20920 return ret;
20921 case 10:
20922 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20923 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20924 ret, "q", "", "=r", 10);
20925 if (unlikely(ret))
20926 return ret;
20927 __get_user_asm(*(u16 *)(8 + (char *)dst),
20928 - (u16 __user *)(8 + (char __user *)src),
20929 + (const u16 __user *)(8 + (const char __user *)src),
20930 ret, "w", "w", "=r", 2);
20931 return ret;
20932 case 16:
20933 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20934 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20935 ret, "q", "", "=r", 16);
20936 if (unlikely(ret))
20937 return ret;
20938 __get_user_asm(*(u64 *)(8 + (char *)dst),
20939 - (u64 __user *)(8 + (char __user *)src),
20940 + (const u64 __user *)(8 + (const char __user *)src),
20941 ret, "q", "", "=r", 8);
20942 return ret;
20943 default:
20944 - return copy_user_generic(dst, (__force void *)src, size);
20945 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20946 }
20947 }
20948
20949 static __always_inline __must_check
20950 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20951 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20952 {
20953 might_fault();
20954 return __copy_from_user_nocheck(dst, src, size);
20955 }
20956
20957 static __always_inline __must_check
20958 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20959 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20960 {
20961 - int ret = 0;
20962 + size_t sz = __compiletime_object_size(src);
20963 + unsigned ret = 0;
20964 +
20965 + if (size > INT_MAX)
20966 + return size;
20967 +
20968 + check_object_size(src, size, true);
20969 +
20970 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20971 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20972 + return size;
20973 +#endif
20974 +
20975 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20976 + if(__builtin_constant_p(size))
20977 + copy_to_user_overflow();
20978 + else
20979 + __copy_to_user_overflow(sz, size);
20980 + return size;
20981 + }
20982
20983 if (!__builtin_constant_p(size))
20984 - return copy_user_generic((__force void *)dst, src, size);
20985 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20986 switch (size) {
20987 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20988 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20989 ret, "b", "b", "iq", 1);
20990 return ret;
20991 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20992 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20993 ret, "w", "w", "ir", 2);
20994 return ret;
20995 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20996 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20997 ret, "l", "k", "ir", 4);
20998 return ret;
20999 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
21000 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21001 ret, "q", "", "er", 8);
21002 return ret;
21003 case 10:
21004 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21005 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21006 ret, "q", "", "er", 10);
21007 if (unlikely(ret))
21008 return ret;
21009 asm("":::"memory");
21010 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
21011 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
21012 ret, "w", "w", "ir", 2);
21013 return ret;
21014 case 16:
21015 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21016 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21017 ret, "q", "", "er", 16);
21018 if (unlikely(ret))
21019 return ret;
21020 asm("":::"memory");
21021 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
21022 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
21023 ret, "q", "", "er", 8);
21024 return ret;
21025 default:
21026 - return copy_user_generic((__force void *)dst, src, size);
21027 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21028 }
21029 }
21030
21031 static __always_inline __must_check
21032 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
21033 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
21034 {
21035 might_fault();
21036 return __copy_to_user_nocheck(dst, src, size);
21037 }
21038
21039 static __always_inline __must_check
21040 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21041 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21042 {
21043 - int ret = 0;
21044 + unsigned ret = 0;
21045
21046 might_fault();
21047 +
21048 + if (size > INT_MAX)
21049 + return size;
21050 +
21051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21052 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21053 + return size;
21054 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21055 + return size;
21056 +#endif
21057 +
21058 if (!__builtin_constant_p(size))
21059 - return copy_user_generic((__force void *)dst,
21060 - (__force void *)src, size);
21061 + return copy_user_generic((__force_kernel void *)____m(dst),
21062 + (__force_kernel const void *)____m(src), size);
21063 switch (size) {
21064 case 1: {
21065 u8 tmp;
21066 - __get_user_asm(tmp, (u8 __user *)src,
21067 + __get_user_asm(tmp, (const u8 __user *)src,
21068 ret, "b", "b", "=q", 1);
21069 if (likely(!ret))
21070 __put_user_asm(tmp, (u8 __user *)dst,
21071 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21072 }
21073 case 2: {
21074 u16 tmp;
21075 - __get_user_asm(tmp, (u16 __user *)src,
21076 + __get_user_asm(tmp, (const u16 __user *)src,
21077 ret, "w", "w", "=r", 2);
21078 if (likely(!ret))
21079 __put_user_asm(tmp, (u16 __user *)dst,
21080 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21081
21082 case 4: {
21083 u32 tmp;
21084 - __get_user_asm(tmp, (u32 __user *)src,
21085 + __get_user_asm(tmp, (const u32 __user *)src,
21086 ret, "l", "k", "=r", 4);
21087 if (likely(!ret))
21088 __put_user_asm(tmp, (u32 __user *)dst,
21089 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21090 }
21091 case 8: {
21092 u64 tmp;
21093 - __get_user_asm(tmp, (u64 __user *)src,
21094 + __get_user_asm(tmp, (const u64 __user *)src,
21095 ret, "q", "", "=r", 8);
21096 if (likely(!ret))
21097 __put_user_asm(tmp, (u64 __user *)dst,
21098 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21099 return ret;
21100 }
21101 default:
21102 - return copy_user_generic((__force void *)dst,
21103 - (__force void *)src, size);
21104 + return copy_user_generic((__force_kernel void *)____m(dst),
21105 + (__force_kernel const void *)____m(src), size);
21106 }
21107 }
21108
21109 -static __must_check __always_inline int
21110 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
21111 +static __must_check __always_inline unsigned long
21112 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
21113 {
21114 return __copy_from_user_nocheck(dst, src, size);
21115 }
21116
21117 -static __must_check __always_inline int
21118 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
21119 +static __must_check __always_inline unsigned long
21120 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
21121 {
21122 return __copy_to_user_nocheck(dst, src, size);
21123 }
21124
21125 -extern long __copy_user_nocache(void *dst, const void __user *src,
21126 - unsigned size, int zerorest);
21127 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
21128 + unsigned long size, int zerorest);
21129
21130 -static inline int
21131 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
21132 +static inline unsigned long
21133 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
21134 {
21135 might_fault();
21136 +
21137 + if (size > INT_MAX)
21138 + return size;
21139 +
21140 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21141 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21142 + return size;
21143 +#endif
21144 +
21145 return __copy_user_nocache(dst, src, size, 1);
21146 }
21147
21148 -static inline int
21149 +static inline unsigned long
21150 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
21151 - unsigned size)
21152 + unsigned long size)
21153 {
21154 + if (size > INT_MAX)
21155 + return size;
21156 +
21157 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21158 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21159 + return size;
21160 +#endif
21161 +
21162 return __copy_user_nocache(dst, src, size, 0);
21163 }
21164
21165 unsigned long
21166 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
21167 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
21168
21169 #endif /* _ASM_X86_UACCESS_64_H */
21170 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
21171 index 5b238981..77fdd78 100644
21172 --- a/arch/x86/include/asm/word-at-a-time.h
21173 +++ b/arch/x86/include/asm/word-at-a-time.h
21174 @@ -11,7 +11,7 @@
21175 * and shift, for example.
21176 */
21177 struct word_at_a_time {
21178 - const unsigned long one_bits, high_bits;
21179 + unsigned long one_bits, high_bits;
21180 };
21181
21182 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
21183 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
21184 index e45e4da..44e8572 100644
21185 --- a/arch/x86/include/asm/x86_init.h
21186 +++ b/arch/x86/include/asm/x86_init.h
21187 @@ -129,7 +129,7 @@ struct x86_init_ops {
21188 struct x86_init_timers timers;
21189 struct x86_init_iommu iommu;
21190 struct x86_init_pci pci;
21191 -};
21192 +} __no_const;
21193
21194 /**
21195 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
21196 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
21197 void (*setup_percpu_clockev)(void);
21198 void (*early_percpu_clock_init)(void);
21199 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
21200 -};
21201 +} __no_const;
21202
21203 struct timespec;
21204
21205 @@ -168,7 +168,7 @@ struct x86_platform_ops {
21206 void (*save_sched_clock_state)(void);
21207 void (*restore_sched_clock_state)(void);
21208 void (*apic_post_init)(void);
21209 -};
21210 +} __no_const;
21211
21212 struct pci_dev;
21213 struct msi_msg;
21214 @@ -185,7 +185,7 @@ struct x86_msi_ops {
21215 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
21216 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
21217 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
21218 -};
21219 +} __no_const;
21220
21221 struct IO_APIC_route_entry;
21222 struct io_apic_irq_attr;
21223 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
21224 unsigned int destination, int vector,
21225 struct io_apic_irq_attr *attr);
21226 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
21227 -};
21228 +} __no_const;
21229
21230 extern struct x86_init_ops x86_init;
21231 extern struct x86_cpuinit_ops x86_cpuinit;
21232 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
21233 index c949923..c22bfa4 100644
21234 --- a/arch/x86/include/asm/xen/page.h
21235 +++ b/arch/x86/include/asm/xen/page.h
21236 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
21237 extern struct page *m2p_find_override(unsigned long mfn);
21238 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
21239
21240 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
21241 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
21242 {
21243 unsigned long mfn;
21244
21245 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
21246 index 7e7a79a..0824666 100644
21247 --- a/arch/x86/include/asm/xsave.h
21248 +++ b/arch/x86/include/asm/xsave.h
21249 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21250 if (unlikely(err))
21251 return -EFAULT;
21252
21253 + pax_open_userland();
21254 __asm__ __volatile__(ASM_STAC "\n"
21255 - "1:"XSAVE"\n"
21256 + "1:"
21257 + __copyuser_seg
21258 + XSAVE"\n"
21259 "2: " ASM_CLAC "\n"
21260 xstate_fault
21261 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
21262 : "memory");
21263 + pax_close_userland();
21264 return err;
21265 }
21266
21267 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21268 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
21269 {
21270 int err = 0;
21271 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
21272 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
21273 u32 lmask = mask;
21274 u32 hmask = mask >> 32;
21275
21276 + pax_open_userland();
21277 __asm__ __volatile__(ASM_STAC "\n"
21278 - "1:"XRSTOR"\n"
21279 + "1:"
21280 + __copyuser_seg
21281 + XRSTOR"\n"
21282 "2: " ASM_CLAC "\n"
21283 xstate_fault
21284 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
21285 : "memory"); /* memory required? */
21286 + pax_close_userland();
21287 return err;
21288 }
21289
21290 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
21291 index bbae024..e1528f9 100644
21292 --- a/arch/x86/include/uapi/asm/e820.h
21293 +++ b/arch/x86/include/uapi/asm/e820.h
21294 @@ -63,7 +63,7 @@ struct e820map {
21295 #define ISA_START_ADDRESS 0xa0000
21296 #define ISA_END_ADDRESS 0x100000
21297
21298 -#define BIOS_BEGIN 0x000a0000
21299 +#define BIOS_BEGIN 0x000c0000
21300 #define BIOS_END 0x00100000
21301
21302 #define BIOS_ROM_BASE 0xffe00000
21303 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
21304 index 7b0a55a..ad115bf 100644
21305 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
21306 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
21307 @@ -49,7 +49,6 @@
21308 #define EFLAGS 144
21309 #define RSP 152
21310 #define SS 160
21311 -#define ARGOFFSET R11
21312 #endif /* __ASSEMBLY__ */
21313
21314 /* top of stack page */
21315 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
21316 index ada2e2d..ca69e16 100644
21317 --- a/arch/x86/kernel/Makefile
21318 +++ b/arch/x86/kernel/Makefile
21319 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
21320 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
21321 obj-$(CONFIG_IRQ_WORK) += irq_work.o
21322 obj-y += probe_roms.o
21323 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
21324 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
21325 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
21326 obj-$(CONFIG_X86_64) += mcount_64.o
21327 obj-y += syscall_$(BITS).o vsyscall_gtod.o
21328 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
21329 index a142e77..6222cdd 100644
21330 --- a/arch/x86/kernel/acpi/boot.c
21331 +++ b/arch/x86/kernel/acpi/boot.c
21332 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
21333 * If your system is blacklisted here, but you find that acpi=force
21334 * works for you, please contact linux-acpi@vger.kernel.org
21335 */
21336 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
21337 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
21338 /*
21339 * Boxes that need ACPI disabled
21340 */
21341 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
21342 };
21343
21344 /* second table for DMI checks that should run after early-quirks */
21345 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
21346 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
21347 /*
21348 * HP laptops which use a DSDT reporting as HP/SB400/10000,
21349 * which includes some code which overrides all temperature
21350 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
21351 index 3136820..e2c6577 100644
21352 --- a/arch/x86/kernel/acpi/sleep.c
21353 +++ b/arch/x86/kernel/acpi/sleep.c
21354 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
21355 #else /* CONFIG_64BIT */
21356 #ifdef CONFIG_SMP
21357 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
21358 +
21359 + pax_open_kernel();
21360 early_gdt_descr.address =
21361 (unsigned long)get_cpu_gdt_table(smp_processor_id());
21362 + pax_close_kernel();
21363 +
21364 initial_gs = per_cpu_offset(smp_processor_id());
21365 #endif
21366 initial_code = (unsigned long)wakeup_long64;
21367 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
21368 index 665c6b7..eae4d56 100644
21369 --- a/arch/x86/kernel/acpi/wakeup_32.S
21370 +++ b/arch/x86/kernel/acpi/wakeup_32.S
21371 @@ -29,13 +29,11 @@ wakeup_pmode_return:
21372 # and restore the stack ... but you need gdt for this to work
21373 movl saved_context_esp, %esp
21374
21375 - movl %cs:saved_magic, %eax
21376 - cmpl $0x12345678, %eax
21377 + cmpl $0x12345678, saved_magic
21378 jne bogus_magic
21379
21380 # jump to place where we left off
21381 - movl saved_eip, %eax
21382 - jmp *%eax
21383 + jmp *(saved_eip)
21384
21385 bogus_magic:
21386 jmp bogus_magic
21387 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
21388 index 703130f..27a155d 100644
21389 --- a/arch/x86/kernel/alternative.c
21390 +++ b/arch/x86/kernel/alternative.c
21391 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21392 */
21393 for (a = start; a < end; a++) {
21394 instr = (u8 *)&a->instr_offset + a->instr_offset;
21395 +
21396 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21397 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21398 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21399 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21400 +#endif
21401 +
21402 replacement = (u8 *)&a->repl_offset + a->repl_offset;
21403 BUG_ON(a->replacementlen > a->instrlen);
21404 BUG_ON(a->instrlen > sizeof(insnbuf));
21405 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21406 add_nops(insnbuf + a->replacementlen,
21407 a->instrlen - a->replacementlen);
21408
21409 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21410 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21411 + instr = ktva_ktla(instr);
21412 +#endif
21413 +
21414 text_poke_early(instr, insnbuf, a->instrlen);
21415 }
21416 }
21417 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
21418 for (poff = start; poff < end; poff++) {
21419 u8 *ptr = (u8 *)poff + *poff;
21420
21421 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21422 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21423 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21424 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21425 +#endif
21426 +
21427 if (!*poff || ptr < text || ptr >= text_end)
21428 continue;
21429 /* turn DS segment override prefix into lock prefix */
21430 - if (*ptr == 0x3e)
21431 + if (*ktla_ktva(ptr) == 0x3e)
21432 text_poke(ptr, ((unsigned char []){0xf0}), 1);
21433 }
21434 mutex_unlock(&text_mutex);
21435 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
21436 for (poff = start; poff < end; poff++) {
21437 u8 *ptr = (u8 *)poff + *poff;
21438
21439 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21440 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21441 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21442 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21443 +#endif
21444 +
21445 if (!*poff || ptr < text || ptr >= text_end)
21446 continue;
21447 /* turn lock prefix into DS segment override prefix */
21448 - if (*ptr == 0xf0)
21449 + if (*ktla_ktva(ptr) == 0xf0)
21450 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21451 }
21452 mutex_unlock(&text_mutex);
21453 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21454
21455 BUG_ON(p->len > MAX_PATCH_LEN);
21456 /* prep the buffer with the original instructions */
21457 - memcpy(insnbuf, p->instr, p->len);
21458 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21459 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21460 (unsigned long)p->instr, p->len);
21461
21462 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21463 if (!uniproc_patched || num_possible_cpus() == 1)
21464 free_init_pages("SMP alternatives",
21465 (unsigned long)__smp_locks,
21466 - (unsigned long)__smp_locks_end);
21467 + PAGE_ALIGN((unsigned long)__smp_locks_end));
21468 #endif
21469
21470 apply_paravirt(__parainstructions, __parainstructions_end);
21471 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21472 * instructions. And on the local CPU you need to be protected again NMI or MCE
21473 * handlers seeing an inconsistent instruction while you patch.
21474 */
21475 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
21476 +void *__kprobes text_poke_early(void *addr, const void *opcode,
21477 size_t len)
21478 {
21479 unsigned long flags;
21480 local_irq_save(flags);
21481 - memcpy(addr, opcode, len);
21482 +
21483 + pax_open_kernel();
21484 + memcpy(ktla_ktva(addr), opcode, len);
21485 sync_core();
21486 + pax_close_kernel();
21487 +
21488 local_irq_restore(flags);
21489 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21490 that causes hangs on some VIA CPUs. */
21491 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21492 */
21493 void *text_poke(void *addr, const void *opcode, size_t len)
21494 {
21495 - unsigned long flags;
21496 - char *vaddr;
21497 + unsigned char *vaddr = ktla_ktva(addr);
21498 struct page *pages[2];
21499 - int i;
21500 + size_t i;
21501
21502 if (!core_kernel_text((unsigned long)addr)) {
21503 - pages[0] = vmalloc_to_page(addr);
21504 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21505 + pages[0] = vmalloc_to_page(vaddr);
21506 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21507 } else {
21508 - pages[0] = virt_to_page(addr);
21509 + pages[0] = virt_to_page(vaddr);
21510 WARN_ON(!PageReserved(pages[0]));
21511 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21512 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21513 }
21514 BUG_ON(!pages[0]);
21515 - local_irq_save(flags);
21516 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21517 - if (pages[1])
21518 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21519 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21520 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21521 - clear_fixmap(FIX_TEXT_POKE0);
21522 - if (pages[1])
21523 - clear_fixmap(FIX_TEXT_POKE1);
21524 - local_flush_tlb();
21525 - sync_core();
21526 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21527 - that causes hangs on some VIA CPUs. */
21528 + text_poke_early(addr, opcode, len);
21529 for (i = 0; i < len; i++)
21530 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21531 - local_irq_restore(flags);
21532 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21533 return addr;
21534 }
21535
21536 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21537 if (likely(!bp_patching_in_progress))
21538 return 0;
21539
21540 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21541 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21542 return 0;
21543
21544 /* set up the specified breakpoint handler */
21545 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21546 */
21547 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21548 {
21549 - unsigned char int3 = 0xcc;
21550 + const unsigned char int3 = 0xcc;
21551
21552 bp_int3_handler = handler;
21553 bp_int3_addr = (u8 *)addr + sizeof(int3);
21554 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21555 index 24b5894..6d9701b 100644
21556 --- a/arch/x86/kernel/apic/apic.c
21557 +++ b/arch/x86/kernel/apic/apic.c
21558 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21559 /*
21560 * Debug level, exported for io_apic.c
21561 */
21562 -unsigned int apic_verbosity;
21563 +int apic_verbosity;
21564
21565 int pic_mode;
21566
21567 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21568 apic_write(APIC_ESR, 0);
21569 v = apic_read(APIC_ESR);
21570 ack_APIC_irq();
21571 - atomic_inc(&irq_err_count);
21572 + atomic_inc_unchecked(&irq_err_count);
21573
21574 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21575 smp_processor_id(), v);
21576 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21577 index de918c4..32eed23 100644
21578 --- a/arch/x86/kernel/apic/apic_flat_64.c
21579 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21580 @@ -154,7 +154,7 @@ static int flat_probe(void)
21581 return 1;
21582 }
21583
21584 -static struct apic apic_flat = {
21585 +static struct apic apic_flat __read_only = {
21586 .name = "flat",
21587 .probe = flat_probe,
21588 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21589 @@ -260,7 +260,7 @@ static int physflat_probe(void)
21590 return 0;
21591 }
21592
21593 -static struct apic apic_physflat = {
21594 +static struct apic apic_physflat __read_only = {
21595
21596 .name = "physical flat",
21597 .probe = physflat_probe,
21598 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21599 index b205cdb..d8503ff 100644
21600 --- a/arch/x86/kernel/apic/apic_noop.c
21601 +++ b/arch/x86/kernel/apic/apic_noop.c
21602 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21603 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21604 }
21605
21606 -struct apic apic_noop = {
21607 +struct apic apic_noop __read_only = {
21608 .name = "noop",
21609 .probe = noop_probe,
21610 .acpi_madt_oem_check = NULL,
21611 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21612 index c4a8d63..fe893ac 100644
21613 --- a/arch/x86/kernel/apic/bigsmp_32.c
21614 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21615 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21616 return dmi_bigsmp;
21617 }
21618
21619 -static struct apic apic_bigsmp = {
21620 +static struct apic apic_bigsmp __read_only = {
21621
21622 .name = "bigsmp",
21623 .probe = probe_bigsmp,
21624 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21625 index 337ce5a..c8d98b4 100644
21626 --- a/arch/x86/kernel/apic/io_apic.c
21627 +++ b/arch/x86/kernel/apic/io_apic.c
21628 @@ -1230,7 +1230,7 @@ out:
21629 }
21630 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21631
21632 -void lock_vector_lock(void)
21633 +void lock_vector_lock(void) __acquires(vector_lock)
21634 {
21635 /* Used to the online set of cpus does not change
21636 * during assign_irq_vector.
21637 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21638 raw_spin_lock(&vector_lock);
21639 }
21640
21641 -void unlock_vector_lock(void)
21642 +void unlock_vector_lock(void) __releases(vector_lock)
21643 {
21644 raw_spin_unlock(&vector_lock);
21645 }
21646 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21647 ack_APIC_irq();
21648 }
21649
21650 -atomic_t irq_mis_count;
21651 +atomic_unchecked_t irq_mis_count;
21652
21653 #ifdef CONFIG_GENERIC_PENDING_IRQ
21654 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21655 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21656 * at the cpu.
21657 */
21658 if (!(v & (1 << (i & 0x1f)))) {
21659 - atomic_inc(&irq_mis_count);
21660 + atomic_inc_unchecked(&irq_mis_count);
21661
21662 eoi_ioapic_irq(irq, cfg);
21663 }
21664 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21665 index bda4886..f9c7195 100644
21666 --- a/arch/x86/kernel/apic/probe_32.c
21667 +++ b/arch/x86/kernel/apic/probe_32.c
21668 @@ -72,7 +72,7 @@ static int probe_default(void)
21669 return 1;
21670 }
21671
21672 -static struct apic apic_default = {
21673 +static struct apic apic_default __read_only = {
21674
21675 .name = "default",
21676 .probe = probe_default,
21677 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21678 index 6ce600f..cb44af8 100644
21679 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21680 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21681 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21682 return notifier_from_errno(err);
21683 }
21684
21685 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21686 +static struct notifier_block x2apic_cpu_notifier = {
21687 .notifier_call = update_clusterinfo,
21688 };
21689
21690 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21691 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21692 }
21693
21694 -static struct apic apic_x2apic_cluster = {
21695 +static struct apic apic_x2apic_cluster __read_only = {
21696
21697 .name = "cluster x2apic",
21698 .probe = x2apic_cluster_probe,
21699 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21700 index 6fae733..5ca17af 100644
21701 --- a/arch/x86/kernel/apic/x2apic_phys.c
21702 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21703 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21704 return apic == &apic_x2apic_phys;
21705 }
21706
21707 -static struct apic apic_x2apic_phys = {
21708 +static struct apic apic_x2apic_phys __read_only = {
21709
21710 .name = "physical x2apic",
21711 .probe = x2apic_phys_probe,
21712 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21713 index 004f017..8fbc8b5 100644
21714 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21715 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21716 @@ -350,7 +350,7 @@ static int uv_probe(void)
21717 return apic == &apic_x2apic_uv_x;
21718 }
21719
21720 -static struct apic __refdata apic_x2apic_uv_x = {
21721 +static struct apic apic_x2apic_uv_x __read_only = {
21722
21723 .name = "UV large system",
21724 .probe = uv_probe,
21725 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21726 index 5848744..56cb598 100644
21727 --- a/arch/x86/kernel/apm_32.c
21728 +++ b/arch/x86/kernel/apm_32.c
21729 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21730 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21731 * even though they are called in protected mode.
21732 */
21733 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21734 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21735 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21736
21737 static const char driver_version[] = "1.16ac"; /* no spaces */
21738 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21739 BUG_ON(cpu != 0);
21740 gdt = get_cpu_gdt_table(cpu);
21741 save_desc_40 = gdt[0x40 / 8];
21742 +
21743 + pax_open_kernel();
21744 gdt[0x40 / 8] = bad_bios_desc;
21745 + pax_close_kernel();
21746
21747 apm_irq_save(flags);
21748 APM_DO_SAVE_SEGS;
21749 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21750 &call->esi);
21751 APM_DO_RESTORE_SEGS;
21752 apm_irq_restore(flags);
21753 +
21754 + pax_open_kernel();
21755 gdt[0x40 / 8] = save_desc_40;
21756 + pax_close_kernel();
21757 +
21758 put_cpu();
21759
21760 return call->eax & 0xff;
21761 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21762 BUG_ON(cpu != 0);
21763 gdt = get_cpu_gdt_table(cpu);
21764 save_desc_40 = gdt[0x40 / 8];
21765 +
21766 + pax_open_kernel();
21767 gdt[0x40 / 8] = bad_bios_desc;
21768 + pax_close_kernel();
21769
21770 apm_irq_save(flags);
21771 APM_DO_SAVE_SEGS;
21772 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21773 &call->eax);
21774 APM_DO_RESTORE_SEGS;
21775 apm_irq_restore(flags);
21776 +
21777 + pax_open_kernel();
21778 gdt[0x40 / 8] = save_desc_40;
21779 + pax_close_kernel();
21780 +
21781 put_cpu();
21782 return error;
21783 }
21784 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21785 * code to that CPU.
21786 */
21787 gdt = get_cpu_gdt_table(0);
21788 +
21789 + pax_open_kernel();
21790 set_desc_base(&gdt[APM_CS >> 3],
21791 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21792 set_desc_base(&gdt[APM_CS_16 >> 3],
21793 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21794 set_desc_base(&gdt[APM_DS >> 3],
21795 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21796 + pax_close_kernel();
21797
21798 proc_create("apm", 0, NULL, &apm_file_ops);
21799
21800 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21801 index 9f6b934..cf5ffb3 100644
21802 --- a/arch/x86/kernel/asm-offsets.c
21803 +++ b/arch/x86/kernel/asm-offsets.c
21804 @@ -32,6 +32,8 @@ void common(void) {
21805 OFFSET(TI_flags, thread_info, flags);
21806 OFFSET(TI_status, thread_info, status);
21807 OFFSET(TI_addr_limit, thread_info, addr_limit);
21808 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21809 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21810
21811 BLANK();
21812 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21813 @@ -52,8 +54,26 @@ void common(void) {
21814 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21815 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21816 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21817 +
21818 +#ifdef CONFIG_PAX_KERNEXEC
21819 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21820 #endif
21821
21822 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21823 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21824 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21825 +#ifdef CONFIG_X86_64
21826 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21827 +#endif
21828 +#endif
21829 +
21830 +#endif
21831 +
21832 + BLANK();
21833 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21834 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21835 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21836 +
21837 #ifdef CONFIG_XEN
21838 BLANK();
21839 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21840 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21841 index e7c798b..2b2019b 100644
21842 --- a/arch/x86/kernel/asm-offsets_64.c
21843 +++ b/arch/x86/kernel/asm-offsets_64.c
21844 @@ -77,6 +77,7 @@ int main(void)
21845 BLANK();
21846 #undef ENTRY
21847
21848 + DEFINE(TSS_size, sizeof(struct tss_struct));
21849 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21850 BLANK();
21851
21852 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21853 index 7fd54f0..0691410 100644
21854 --- a/arch/x86/kernel/cpu/Makefile
21855 +++ b/arch/x86/kernel/cpu/Makefile
21856 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21857 CFLAGS_REMOVE_perf_event.o = -pg
21858 endif
21859
21860 -# Make sure load_percpu_segment has no stackprotector
21861 -nostackp := $(call cc-option, -fno-stack-protector)
21862 -CFLAGS_common.o := $(nostackp)
21863 -
21864 obj-y := intel_cacheinfo.o scattered.o topology.o
21865 obj-y += proc.o capflags.o powerflags.o common.o
21866 obj-y += rdrand.o
21867 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21868 index 60e5497..8efbd2f 100644
21869 --- a/arch/x86/kernel/cpu/amd.c
21870 +++ b/arch/x86/kernel/cpu/amd.c
21871 @@ -711,7 +711,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21872 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21873 {
21874 /* AMD errata T13 (order #21922) */
21875 - if ((c->x86 == 6)) {
21876 + if (c->x86 == 6) {
21877 /* Duron Rev A0 */
21878 if (c->x86_model == 3 && c->x86_mask == 0)
21879 size = 64;
21880 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21881 index 3126558..a1028f6 100644
21882 --- a/arch/x86/kernel/cpu/common.c
21883 +++ b/arch/x86/kernel/cpu/common.c
21884 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21885
21886 static const struct cpu_dev *this_cpu = &default_cpu;
21887
21888 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21889 -#ifdef CONFIG_X86_64
21890 - /*
21891 - * We need valid kernel segments for data and code in long mode too
21892 - * IRET will check the segment types kkeil 2000/10/28
21893 - * Also sysret mandates a special GDT layout
21894 - *
21895 - * TLS descriptors are currently at a different place compared to i386.
21896 - * Hopefully nobody expects them at a fixed place (Wine?)
21897 - */
21898 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21899 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21900 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21901 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21902 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21903 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21904 -#else
21905 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21906 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21907 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21908 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21909 - /*
21910 - * Segments used for calling PnP BIOS have byte granularity.
21911 - * They code segments and data segments have fixed 64k limits,
21912 - * the transfer segment sizes are set at run time.
21913 - */
21914 - /* 32-bit code */
21915 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21916 - /* 16-bit code */
21917 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21918 - /* 16-bit data */
21919 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21920 - /* 16-bit data */
21921 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21922 - /* 16-bit data */
21923 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21924 - /*
21925 - * The APM segments have byte granularity and their bases
21926 - * are set at run time. All have 64k limits.
21927 - */
21928 - /* 32-bit code */
21929 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21930 - /* 16-bit code */
21931 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21932 - /* data */
21933 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21934 -
21935 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21936 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21937 - GDT_STACK_CANARY_INIT
21938 -#endif
21939 -} };
21940 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21941 -
21942 static int __init x86_xsave_setup(char *s)
21943 {
21944 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21945 @@ -303,6 +249,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21946 }
21947 }
21948
21949 +#ifdef CONFIG_X86_64
21950 +static __init int setup_disable_pcid(char *arg)
21951 +{
21952 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21953 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21954 +
21955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21956 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21957 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21958 +#endif
21959 +
21960 + return 1;
21961 +}
21962 +__setup("nopcid", setup_disable_pcid);
21963 +
21964 +static void setup_pcid(struct cpuinfo_x86 *c)
21965 +{
21966 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21967 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21968 +
21969 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21970 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21971 + pax_open_kernel();
21972 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21973 + pax_close_kernel();
21974 + printk("PAX: slow and weak UDEREF enabled\n");
21975 + } else
21976 + printk("PAX: UDEREF disabled\n");
21977 +#endif
21978 +
21979 + return;
21980 + }
21981 +
21982 + printk("PAX: PCID detected\n");
21983 + set_in_cr4(X86_CR4_PCIDE);
21984 +
21985 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21986 + pax_open_kernel();
21987 + clone_pgd_mask = ~(pgdval_t)0UL;
21988 + pax_close_kernel();
21989 + if (pax_user_shadow_base)
21990 + printk("PAX: weak UDEREF enabled\n");
21991 + else {
21992 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21993 + printk("PAX: strong UDEREF enabled\n");
21994 + }
21995 +#endif
21996 +
21997 + if (cpu_has(c, X86_FEATURE_INVPCID))
21998 + printk("PAX: INVPCID detected\n");
21999 +}
22000 +#endif
22001 +
22002 /*
22003 * Some CPU features depend on higher CPUID levels, which may not always
22004 * be available due to CPUID level capping or broken virtualization
22005 @@ -403,7 +402,7 @@ void switch_to_new_gdt(int cpu)
22006 {
22007 struct desc_ptr gdt_descr;
22008
22009 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
22010 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22011 gdt_descr.size = GDT_SIZE - 1;
22012 load_gdt(&gdt_descr);
22013 /* Reload the per-cpu base */
22014 @@ -893,6 +892,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22015 setup_smep(c);
22016 setup_smap(c);
22017
22018 +#ifdef CONFIG_X86_64
22019 + setup_pcid(c);
22020 +#endif
22021 +
22022 /*
22023 * The vendor-specific functions might have changed features.
22024 * Now we do "generic changes."
22025 @@ -901,6 +904,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22026 /* Filter out anything that depends on CPUID levels we don't have */
22027 filter_cpuid_features(c, true);
22028
22029 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22030 + setup_clear_cpu_cap(X86_FEATURE_SEP);
22031 +#endif
22032 +
22033 /* If the model name is still unset, do table lookup. */
22034 if (!c->x86_model_id[0]) {
22035 const char *p;
22036 @@ -981,7 +988,7 @@ static void syscall32_cpu_init(void)
22037 void enable_sep_cpu(void)
22038 {
22039 int cpu = get_cpu();
22040 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
22041 + struct tss_struct *tss = init_tss + cpu;
22042
22043 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22044 put_cpu();
22045 @@ -1121,14 +1128,16 @@ static __init int setup_disablecpuid(char *arg)
22046 }
22047 __setup("clearcpuid=", setup_disablecpuid);
22048
22049 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
22050 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
22051 +
22052 DEFINE_PER_CPU(unsigned long, kernel_stack) =
22053 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
22054 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
22055 EXPORT_PER_CPU_SYMBOL(kernel_stack);
22056
22057 #ifdef CONFIG_X86_64
22058 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22059 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
22060 - (unsigned long) debug_idt_table };
22061 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22062 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
22063
22064 DEFINE_PER_CPU_FIRST(union irq_stack_union,
22065 irq_stack_union) __aligned(PAGE_SIZE) __visible;
22066 @@ -1291,7 +1300,7 @@ void cpu_init(void)
22067 load_ucode_ap();
22068
22069 cpu = stack_smp_processor_id();
22070 - t = &per_cpu(init_tss, cpu);
22071 + t = init_tss + cpu;
22072 oist = &per_cpu(orig_ist, cpu);
22073
22074 #ifdef CONFIG_NUMA
22075 @@ -1326,7 +1335,6 @@ void cpu_init(void)
22076 wrmsrl(MSR_KERNEL_GS_BASE, 0);
22077 barrier();
22078
22079 - x86_configure_nx();
22080 enable_x2apic();
22081
22082 /*
22083 @@ -1378,7 +1386,7 @@ void cpu_init(void)
22084 {
22085 int cpu = smp_processor_id();
22086 struct task_struct *curr = current;
22087 - struct tss_struct *t = &per_cpu(init_tss, cpu);
22088 + struct tss_struct *t = init_tss + cpu;
22089 struct thread_struct *thread = &curr->thread;
22090
22091 show_ucode_info_early();
22092 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
22093 index c703507..28535e3 100644
22094 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
22095 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
22096 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
22097 };
22098
22099 #ifdef CONFIG_AMD_NB
22100 +static struct attribute *default_attrs_amd_nb[] = {
22101 + &type.attr,
22102 + &level.attr,
22103 + &coherency_line_size.attr,
22104 + &physical_line_partition.attr,
22105 + &ways_of_associativity.attr,
22106 + &number_of_sets.attr,
22107 + &size.attr,
22108 + &shared_cpu_map.attr,
22109 + &shared_cpu_list.attr,
22110 + NULL,
22111 + NULL,
22112 + NULL,
22113 + NULL
22114 +};
22115 +
22116 static struct attribute **amd_l3_attrs(void)
22117 {
22118 static struct attribute **attrs;
22119 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
22120
22121 n = ARRAY_SIZE(default_attrs);
22122
22123 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
22124 - n += 2;
22125 -
22126 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
22127 - n += 1;
22128 -
22129 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
22130 - if (attrs == NULL)
22131 - return attrs = default_attrs;
22132 -
22133 - for (n = 0; default_attrs[n]; n++)
22134 - attrs[n] = default_attrs[n];
22135 + attrs = default_attrs_amd_nb;
22136
22137 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
22138 attrs[n++] = &cache_disable_0.attr;
22139 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
22140 .default_attrs = default_attrs,
22141 };
22142
22143 +#ifdef CONFIG_AMD_NB
22144 +static struct kobj_type ktype_cache_amd_nb = {
22145 + .sysfs_ops = &sysfs_ops,
22146 + .default_attrs = default_attrs_amd_nb,
22147 +};
22148 +#endif
22149 +
22150 static struct kobj_type ktype_percpu_entry = {
22151 .sysfs_ops = &sysfs_ops,
22152 };
22153 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
22154 return retval;
22155 }
22156
22157 +#ifdef CONFIG_AMD_NB
22158 + amd_l3_attrs();
22159 +#endif
22160 +
22161 for (i = 0; i < num_cache_leaves; i++) {
22162 + struct kobj_type *ktype;
22163 +
22164 this_object = INDEX_KOBJECT_PTR(cpu, i);
22165 this_object->cpu = cpu;
22166 this_object->index = i;
22167
22168 this_leaf = CPUID4_INFO_IDX(cpu, i);
22169
22170 - ktype_cache.default_attrs = default_attrs;
22171 + ktype = &ktype_cache;
22172 #ifdef CONFIG_AMD_NB
22173 if (this_leaf->base.nb)
22174 - ktype_cache.default_attrs = amd_l3_attrs();
22175 + ktype = &ktype_cache_amd_nb;
22176 #endif
22177 retval = kobject_init_and_add(&(this_object->kobj),
22178 - &ktype_cache,
22179 + ktype,
22180 per_cpu(ici_cache_kobject, cpu),
22181 "index%1lu", i);
22182 if (unlikely(retval)) {
22183 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
22184 index bd9ccda..38314e7 100644
22185 --- a/arch/x86/kernel/cpu/mcheck/mce.c
22186 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
22187 @@ -45,6 +45,7 @@
22188 #include <asm/processor.h>
22189 #include <asm/mce.h>
22190 #include <asm/msr.h>
22191 +#include <asm/local.h>
22192
22193 #include "mce-internal.h"
22194
22195 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
22196 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
22197 m->cs, m->ip);
22198
22199 - if (m->cs == __KERNEL_CS)
22200 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
22201 print_symbol("{%s}", m->ip);
22202 pr_cont("\n");
22203 }
22204 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
22205
22206 #define PANIC_TIMEOUT 5 /* 5 seconds */
22207
22208 -static atomic_t mce_paniced;
22209 +static atomic_unchecked_t mce_paniced;
22210
22211 static int fake_panic;
22212 -static atomic_t mce_fake_paniced;
22213 +static atomic_unchecked_t mce_fake_paniced;
22214
22215 /* Panic in progress. Enable interrupts and wait for final IPI */
22216 static void wait_for_panic(void)
22217 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22218 /*
22219 * Make sure only one CPU runs in machine check panic
22220 */
22221 - if (atomic_inc_return(&mce_paniced) > 1)
22222 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
22223 wait_for_panic();
22224 barrier();
22225
22226 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22227 console_verbose();
22228 } else {
22229 /* Don't log too much for fake panic */
22230 - if (atomic_inc_return(&mce_fake_paniced) > 1)
22231 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
22232 return;
22233 }
22234 /* First print corrected ones that are still unlogged */
22235 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22236 if (!fake_panic) {
22237 if (panic_timeout == 0)
22238 panic_timeout = mca_cfg.panic_timeout;
22239 - panic(msg);
22240 + panic("%s", msg);
22241 } else
22242 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
22243 }
22244 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
22245 * might have been modified by someone else.
22246 */
22247 rmb();
22248 - if (atomic_read(&mce_paniced))
22249 + if (atomic_read_unchecked(&mce_paniced))
22250 wait_for_panic();
22251 if (!mca_cfg.monarch_timeout)
22252 goto out;
22253 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
22254 }
22255
22256 /* Call the installed machine check handler for this CPU setup. */
22257 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
22258 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
22259 unexpected_machine_check;
22260
22261 /*
22262 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22263 return;
22264 }
22265
22266 + pax_open_kernel();
22267 machine_check_vector = do_machine_check;
22268 + pax_close_kernel();
22269
22270 __mcheck_cpu_init_generic();
22271 __mcheck_cpu_init_vendor(c);
22272 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22273 */
22274
22275 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
22276 -static int mce_chrdev_open_count; /* #times opened */
22277 +static local_t mce_chrdev_open_count; /* #times opened */
22278 static int mce_chrdev_open_exclu; /* already open exclusive? */
22279
22280 static int mce_chrdev_open(struct inode *inode, struct file *file)
22281 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22282 spin_lock(&mce_chrdev_state_lock);
22283
22284 if (mce_chrdev_open_exclu ||
22285 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
22286 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
22287 spin_unlock(&mce_chrdev_state_lock);
22288
22289 return -EBUSY;
22290 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22291
22292 if (file->f_flags & O_EXCL)
22293 mce_chrdev_open_exclu = 1;
22294 - mce_chrdev_open_count++;
22295 + local_inc(&mce_chrdev_open_count);
22296
22297 spin_unlock(&mce_chrdev_state_lock);
22298
22299 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
22300 {
22301 spin_lock(&mce_chrdev_state_lock);
22302
22303 - mce_chrdev_open_count--;
22304 + local_dec(&mce_chrdev_open_count);
22305 mce_chrdev_open_exclu = 0;
22306
22307 spin_unlock(&mce_chrdev_state_lock);
22308 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
22309
22310 for (i = 0; i < mca_cfg.banks; i++) {
22311 struct mce_bank *b = &mce_banks[i];
22312 - struct device_attribute *a = &b->attr;
22313 + device_attribute_no_const *a = &b->attr;
22314
22315 sysfs_attr_init(&a->attr);
22316 a->attr.name = b->attrname;
22317 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
22318 static void mce_reset(void)
22319 {
22320 cpu_missing = 0;
22321 - atomic_set(&mce_fake_paniced, 0);
22322 + atomic_set_unchecked(&mce_fake_paniced, 0);
22323 atomic_set(&mce_executing, 0);
22324 atomic_set(&mce_callin, 0);
22325 atomic_set(&global_nwo, 0);
22326 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
22327 index a304298..49b6d06 100644
22328 --- a/arch/x86/kernel/cpu/mcheck/p5.c
22329 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
22330 @@ -10,6 +10,7 @@
22331 #include <asm/processor.h>
22332 #include <asm/mce.h>
22333 #include <asm/msr.h>
22334 +#include <asm/pgtable.h>
22335
22336 /* By default disabled */
22337 int mce_p5_enabled __read_mostly;
22338 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
22339 if (!cpu_has(c, X86_FEATURE_MCE))
22340 return;
22341
22342 + pax_open_kernel();
22343 machine_check_vector = pentium_machine_check;
22344 + pax_close_kernel();
22345 /* Make sure the vector pointer is visible before we enable MCEs: */
22346 wmb();
22347
22348 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
22349 index 7dc5564..1273569 100644
22350 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
22351 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
22352 @@ -9,6 +9,7 @@
22353 #include <asm/processor.h>
22354 #include <asm/mce.h>
22355 #include <asm/msr.h>
22356 +#include <asm/pgtable.h>
22357
22358 /* Machine check handler for WinChip C6: */
22359 static void winchip_machine_check(struct pt_regs *regs, long error_code)
22360 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
22361 {
22362 u32 lo, hi;
22363
22364 + pax_open_kernel();
22365 machine_check_vector = winchip_machine_check;
22366 + pax_close_kernel();
22367 /* Make sure the vector pointer is visible before we enable MCEs: */
22368 wmb();
22369
22370 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
22371 index dd9d619..86e1d81 100644
22372 --- a/arch/x86/kernel/cpu/microcode/core.c
22373 +++ b/arch/x86/kernel/cpu/microcode/core.c
22374 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22375 return NOTIFY_OK;
22376 }
22377
22378 -static struct notifier_block __refdata mc_cpu_notifier = {
22379 +static struct notifier_block mc_cpu_notifier = {
22380 .notifier_call = mc_cpu_callback,
22381 };
22382
22383 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
22384 index a276fa7..e66810f 100644
22385 --- a/arch/x86/kernel/cpu/microcode/intel.c
22386 +++ b/arch/x86/kernel/cpu/microcode/intel.c
22387 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22388
22389 static int get_ucode_user(void *to, const void *from, size_t n)
22390 {
22391 - return copy_from_user(to, from, n);
22392 + return copy_from_user(to, (const void __force_user *)from, n);
22393 }
22394
22395 static enum ucode_state
22396 request_microcode_user(int cpu, const void __user *buf, size_t size)
22397 {
22398 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22399 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22400 }
22401
22402 static void microcode_fini_cpu(int cpu)
22403 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
22404 index f961de9..8a9d332 100644
22405 --- a/arch/x86/kernel/cpu/mtrr/main.c
22406 +++ b/arch/x86/kernel/cpu/mtrr/main.c
22407 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
22408 u64 size_or_mask, size_and_mask;
22409 static bool mtrr_aps_delayed_init;
22410
22411 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
22412 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
22413
22414 const struct mtrr_ops *mtrr_if;
22415
22416 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
22417 index df5e41f..816c719 100644
22418 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
22419 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
22420 @@ -25,7 +25,7 @@ struct mtrr_ops {
22421 int (*validate_add_page)(unsigned long base, unsigned long size,
22422 unsigned int type);
22423 int (*have_wrcomb)(void);
22424 -};
22425 +} __do_const;
22426
22427 extern int generic_get_free_region(unsigned long base, unsigned long size,
22428 int replace_reg);
22429 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
22430 index 2879ecd..bb8c80b 100644
22431 --- a/arch/x86/kernel/cpu/perf_event.c
22432 +++ b/arch/x86/kernel/cpu/perf_event.c
22433 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
22434
22435 }
22436
22437 -static struct attribute_group x86_pmu_format_group = {
22438 +static attribute_group_no_const x86_pmu_format_group = {
22439 .name = "format",
22440 .attrs = NULL,
22441 };
22442 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22443 NULL,
22444 };
22445
22446 -static struct attribute_group x86_pmu_events_group = {
22447 +static attribute_group_no_const x86_pmu_events_group = {
22448 .name = "events",
22449 .attrs = events_attr,
22450 };
22451 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22452 if (idx > GDT_ENTRIES)
22453 return 0;
22454
22455 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22456 + desc = get_cpu_gdt_table(smp_processor_id());
22457 }
22458
22459 return get_desc_base(desc + idx);
22460 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22461 break;
22462
22463 perf_callchain_store(entry, frame.return_address);
22464 - fp = frame.next_frame;
22465 + fp = (const void __force_user *)frame.next_frame;
22466 }
22467 }
22468
22469 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22470 index 639d128..e92d7e5 100644
22471 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22472 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22473 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22474 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22475 {
22476 struct attribute **attrs;
22477 - struct attribute_group *attr_group;
22478 + attribute_group_no_const *attr_group;
22479 int i = 0, j;
22480
22481 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22482 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22483 index 2502d0d..e5cc05c 100644
22484 --- a/arch/x86/kernel/cpu/perf_event_intel.c
22485 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
22486 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22487 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22488
22489 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22490 - u64 capabilities;
22491 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22492
22493 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22494 - x86_pmu.intel_cap.capabilities = capabilities;
22495 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22496 + x86_pmu.intel_cap.capabilities = capabilities;
22497 }
22498
22499 intel_ds_init();
22500 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22501 index 619f769..d510008 100644
22502 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22503 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22504 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22505 NULL,
22506 };
22507
22508 -static struct attribute_group rapl_pmu_events_group = {
22509 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22510 .name = "events",
22511 .attrs = NULL, /* patched at runtime */
22512 };
22513 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22514 index 0939f86..69730af 100644
22515 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22516 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22517 @@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22518 static int __init uncore_type_init(struct intel_uncore_type *type)
22519 {
22520 struct intel_uncore_pmu *pmus;
22521 - struct attribute_group *attr_group;
22522 + attribute_group_no_const *attr_group;
22523 struct attribute **attrs;
22524 int i, j;
22525
22526 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22527 index 90236f0..54cb20d 100644
22528 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22529 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22530 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22531 struct uncore_event_desc {
22532 struct kobj_attribute attr;
22533 const char *config;
22534 -};
22535 +} __do_const;
22536
22537 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22538 { \
22539 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22540 index 3225ae6c..ee3c6db 100644
22541 --- a/arch/x86/kernel/cpuid.c
22542 +++ b/arch/x86/kernel/cpuid.c
22543 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22544 return notifier_from_errno(err);
22545 }
22546
22547 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22548 +static struct notifier_block cpuid_class_cpu_notifier =
22549 {
22550 .notifier_call = cpuid_class_cpu_callback,
22551 };
22552 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22553 index a618fcd..200e95b 100644
22554 --- a/arch/x86/kernel/crash.c
22555 +++ b/arch/x86/kernel/crash.c
22556 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22557 #ifdef CONFIG_X86_32
22558 struct pt_regs fixed_regs;
22559
22560 - if (!user_mode_vm(regs)) {
22561 + if (!user_mode(regs)) {
22562 crash_fixup_ss_esp(&fixed_regs, regs);
22563 regs = &fixed_regs;
22564 }
22565 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22566 index afa64ad..dce67dd 100644
22567 --- a/arch/x86/kernel/crash_dump_64.c
22568 +++ b/arch/x86/kernel/crash_dump_64.c
22569 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22570 return -ENOMEM;
22571
22572 if (userbuf) {
22573 - if (copy_to_user(buf, vaddr + offset, csize)) {
22574 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22575 iounmap(vaddr);
22576 return -EFAULT;
22577 }
22578 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22579 index f6dfd93..892ade4 100644
22580 --- a/arch/x86/kernel/doublefault.c
22581 +++ b/arch/x86/kernel/doublefault.c
22582 @@ -12,7 +12,7 @@
22583
22584 #define DOUBLEFAULT_STACKSIZE (1024)
22585 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22586 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22587 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22588
22589 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22590
22591 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22592 unsigned long gdt, tss;
22593
22594 native_store_gdt(&gdt_desc);
22595 - gdt = gdt_desc.address;
22596 + gdt = (unsigned long)gdt_desc.address;
22597
22598 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22599
22600 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22601 /* 0x2 bit is always set */
22602 .flags = X86_EFLAGS_SF | 0x2,
22603 .sp = STACK_START,
22604 - .es = __USER_DS,
22605 + .es = __KERNEL_DS,
22606 .cs = __KERNEL_CS,
22607 .ss = __KERNEL_DS,
22608 - .ds = __USER_DS,
22609 + .ds = __KERNEL_DS,
22610 .fs = __KERNEL_PERCPU,
22611
22612 .__cr3 = __pa_nodebug(swapper_pg_dir),
22613 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22614 index b74ebc7..2c95874 100644
22615 --- a/arch/x86/kernel/dumpstack.c
22616 +++ b/arch/x86/kernel/dumpstack.c
22617 @@ -2,6 +2,9 @@
22618 * Copyright (C) 1991, 1992 Linus Torvalds
22619 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22620 */
22621 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22622 +#define __INCLUDED_BY_HIDESYM 1
22623 +#endif
22624 #include <linux/kallsyms.h>
22625 #include <linux/kprobes.h>
22626 #include <linux/uaccess.h>
22627 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22628
22629 void printk_address(unsigned long address)
22630 {
22631 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22632 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22633 }
22634
22635 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22636 static void
22637 print_ftrace_graph_addr(unsigned long addr, void *data,
22638 const struct stacktrace_ops *ops,
22639 - struct thread_info *tinfo, int *graph)
22640 + struct task_struct *task, int *graph)
22641 {
22642 - struct task_struct *task;
22643 unsigned long ret_addr;
22644 int index;
22645
22646 if (addr != (unsigned long)return_to_handler)
22647 return;
22648
22649 - task = tinfo->task;
22650 index = task->curr_ret_stack;
22651
22652 if (!task->ret_stack || index < *graph)
22653 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22654 static inline void
22655 print_ftrace_graph_addr(unsigned long addr, void *data,
22656 const struct stacktrace_ops *ops,
22657 - struct thread_info *tinfo, int *graph)
22658 + struct task_struct *task, int *graph)
22659 { }
22660 #endif
22661
22662 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22663 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22664 */
22665
22666 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22667 - void *p, unsigned int size, void *end)
22668 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22669 {
22670 - void *t = tinfo;
22671 if (end) {
22672 if (p < end && p >= (end-THREAD_SIZE))
22673 return 1;
22674 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22675 }
22676
22677 unsigned long
22678 -print_context_stack(struct thread_info *tinfo,
22679 +print_context_stack(struct task_struct *task, void *stack_start,
22680 unsigned long *stack, unsigned long bp,
22681 const struct stacktrace_ops *ops, void *data,
22682 unsigned long *end, int *graph)
22683 {
22684 struct stack_frame *frame = (struct stack_frame *)bp;
22685
22686 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22687 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22688 unsigned long addr;
22689
22690 addr = *stack;
22691 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22692 } else {
22693 ops->address(data, addr, 0);
22694 }
22695 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22696 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22697 }
22698 stack++;
22699 }
22700 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22701 EXPORT_SYMBOL_GPL(print_context_stack);
22702
22703 unsigned long
22704 -print_context_stack_bp(struct thread_info *tinfo,
22705 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22706 unsigned long *stack, unsigned long bp,
22707 const struct stacktrace_ops *ops, void *data,
22708 unsigned long *end, int *graph)
22709 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22710 struct stack_frame *frame = (struct stack_frame *)bp;
22711 unsigned long *ret_addr = &frame->return_address;
22712
22713 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22714 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22715 unsigned long addr = *ret_addr;
22716
22717 if (!__kernel_text_address(addr))
22718 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22719 ops->address(data, addr, 1);
22720 frame = frame->next_frame;
22721 ret_addr = &frame->return_address;
22722 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22723 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22724 }
22725
22726 return (unsigned long)frame;
22727 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22728 static void print_trace_address(void *data, unsigned long addr, int reliable)
22729 {
22730 touch_nmi_watchdog();
22731 - printk(data);
22732 + printk("%s", (char *)data);
22733 printk_stack_address(addr, reliable);
22734 }
22735
22736 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22737 EXPORT_SYMBOL_GPL(oops_begin);
22738 NOKPROBE_SYMBOL(oops_begin);
22739
22740 +extern void gr_handle_kernel_exploit(void);
22741 +
22742 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22743 {
22744 if (regs && kexec_should_crash(current))
22745 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22746 panic("Fatal exception in interrupt");
22747 if (panic_on_oops)
22748 panic("Fatal exception");
22749 - do_exit(signr);
22750 +
22751 + gr_handle_kernel_exploit();
22752 +
22753 + do_group_exit(signr);
22754 }
22755 NOKPROBE_SYMBOL(oops_end);
22756
22757 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22758 print_modules();
22759 show_regs(regs);
22760 #ifdef CONFIG_X86_32
22761 - if (user_mode_vm(regs)) {
22762 + if (user_mode(regs)) {
22763 sp = regs->sp;
22764 ss = regs->ss & 0xffff;
22765 } else {
22766 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22767 unsigned long flags = oops_begin();
22768 int sig = SIGSEGV;
22769
22770 - if (!user_mode_vm(regs))
22771 + if (!user_mode(regs))
22772 report_bug(regs->ip, regs);
22773
22774 if (__die(str, regs, err))
22775 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22776 index 5abd4cd..c65733b 100644
22777 --- a/arch/x86/kernel/dumpstack_32.c
22778 +++ b/arch/x86/kernel/dumpstack_32.c
22779 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22780 bp = stack_frame(task, regs);
22781
22782 for (;;) {
22783 - struct thread_info *context;
22784 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22785 void *end_stack;
22786
22787 end_stack = is_hardirq_stack(stack, cpu);
22788 if (!end_stack)
22789 end_stack = is_softirq_stack(stack, cpu);
22790
22791 - context = task_thread_info(task);
22792 - bp = ops->walk_stack(context, stack, bp, ops, data,
22793 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22794 end_stack, &graph);
22795
22796 /* Stop if not on irq stack */
22797 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22798 int i;
22799
22800 show_regs_print_info(KERN_EMERG);
22801 - __show_regs(regs, !user_mode_vm(regs));
22802 + __show_regs(regs, !user_mode(regs));
22803
22804 /*
22805 * When in-kernel, we also print out the stack and code at the
22806 * time of the fault..
22807 */
22808 - if (!user_mode_vm(regs)) {
22809 + if (!user_mode(regs)) {
22810 unsigned int code_prologue = code_bytes * 43 / 64;
22811 unsigned int code_len = code_bytes;
22812 unsigned char c;
22813 u8 *ip;
22814 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22815
22816 pr_emerg("Stack:\n");
22817 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22818
22819 pr_emerg("Code:");
22820
22821 - ip = (u8 *)regs->ip - code_prologue;
22822 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22823 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22824 /* try starting at IP */
22825 - ip = (u8 *)regs->ip;
22826 + ip = (u8 *)regs->ip + cs_base;
22827 code_len = code_len - code_prologue + 1;
22828 }
22829 for (i = 0; i < code_len; i++, ip++) {
22830 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22831 pr_cont(" Bad EIP value.");
22832 break;
22833 }
22834 - if (ip == (u8 *)regs->ip)
22835 + if (ip == (u8 *)regs->ip + cs_base)
22836 pr_cont(" <%02x>", c);
22837 else
22838 pr_cont(" %02x", c);
22839 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22840 {
22841 unsigned short ud2;
22842
22843 + ip = ktla_ktva(ip);
22844 if (ip < PAGE_OFFSET)
22845 return 0;
22846 if (probe_kernel_address((unsigned short *)ip, ud2))
22847 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22848
22849 return ud2 == 0x0b0f;
22850 }
22851 +
22852 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22853 +void pax_check_alloca(unsigned long size)
22854 +{
22855 + unsigned long sp = (unsigned long)&sp, stack_left;
22856 +
22857 + /* all kernel stacks are of the same size */
22858 + stack_left = sp & (THREAD_SIZE - 1);
22859 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22860 +}
22861 +EXPORT_SYMBOL(pax_check_alloca);
22862 +#endif
22863 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22864 index 1abcb50..6c8d702 100644
22865 --- a/arch/x86/kernel/dumpstack_64.c
22866 +++ b/arch/x86/kernel/dumpstack_64.c
22867 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22868 const struct stacktrace_ops *ops, void *data)
22869 {
22870 const unsigned cpu = get_cpu();
22871 - struct thread_info *tinfo;
22872 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22873 unsigned long dummy;
22874 unsigned used = 0;
22875 int graph = 0;
22876 int done = 0;
22877 + void *stack_start;
22878
22879 if (!task)
22880 task = current;
22881 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22882 * current stack address. If the stacks consist of nested
22883 * exceptions
22884 */
22885 - tinfo = task_thread_info(task);
22886 while (!done) {
22887 unsigned long *stack_end;
22888 enum stack_type stype;
22889 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22890 if (ops->stack(data, id) < 0)
22891 break;
22892
22893 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22894 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22895 data, stack_end, &graph);
22896 ops->stack(data, "<EOE>");
22897 /*
22898 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22899 * second-to-last pointer (index -2 to end) in the
22900 * exception stack:
22901 */
22902 + if ((u16)stack_end[-1] != __KERNEL_DS)
22903 + goto out;
22904 stack = (unsigned long *) stack_end[-2];
22905 done = 0;
22906 break;
22907 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22908
22909 if (ops->stack(data, "IRQ") < 0)
22910 break;
22911 - bp = ops->walk_stack(tinfo, stack, bp,
22912 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22913 ops, data, stack_end, &graph);
22914 /*
22915 * We link to the next stack (which would be
22916 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22917 /*
22918 * This handles the process stack:
22919 */
22920 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22921 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22922 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22923 +out:
22924 put_cpu();
22925 }
22926 EXPORT_SYMBOL(dump_trace);
22927 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22928
22929 return ud2 == 0x0b0f;
22930 }
22931 +
22932 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22933 +void pax_check_alloca(unsigned long size)
22934 +{
22935 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22936 + unsigned cpu, used;
22937 + char *id;
22938 +
22939 + /* check the process stack first */
22940 + stack_start = (unsigned long)task_stack_page(current);
22941 + stack_end = stack_start + THREAD_SIZE;
22942 + if (likely(stack_start <= sp && sp < stack_end)) {
22943 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22944 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22945 + return;
22946 + }
22947 +
22948 + cpu = get_cpu();
22949 +
22950 + /* check the irq stacks */
22951 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22952 + stack_start = stack_end - IRQ_STACK_SIZE;
22953 + if (stack_start <= sp && sp < stack_end) {
22954 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22955 + put_cpu();
22956 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22957 + return;
22958 + }
22959 +
22960 + /* check the exception stacks */
22961 + used = 0;
22962 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22963 + stack_start = stack_end - EXCEPTION_STKSZ;
22964 + if (stack_end && stack_start <= sp && sp < stack_end) {
22965 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22966 + put_cpu();
22967 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22968 + return;
22969 + }
22970 +
22971 + put_cpu();
22972 +
22973 + /* unknown stack */
22974 + BUG();
22975 +}
22976 +EXPORT_SYMBOL(pax_check_alloca);
22977 +#endif
22978 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22979 index 988c00a..4f673b6 100644
22980 --- a/arch/x86/kernel/e820.c
22981 +++ b/arch/x86/kernel/e820.c
22982 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22983
22984 static void early_panic(char *msg)
22985 {
22986 - early_printk(msg);
22987 - panic(msg);
22988 + early_printk("%s", msg);
22989 + panic("%s", msg);
22990 }
22991
22992 static int userdef __initdata;
22993 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22994 index 01d1c18..8073693 100644
22995 --- a/arch/x86/kernel/early_printk.c
22996 +++ b/arch/x86/kernel/early_printk.c
22997 @@ -7,6 +7,7 @@
22998 #include <linux/pci_regs.h>
22999 #include <linux/pci_ids.h>
23000 #include <linux/errno.h>
23001 +#include <linux/sched.h>
23002 #include <asm/io.h>
23003 #include <asm/processor.h>
23004 #include <asm/fcntl.h>
23005 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
23006 index 4b0e1df..884b67e 100644
23007 --- a/arch/x86/kernel/entry_32.S
23008 +++ b/arch/x86/kernel/entry_32.S
23009 @@ -177,13 +177,153 @@
23010 /*CFI_REL_OFFSET gs, PT_GS*/
23011 .endm
23012 .macro SET_KERNEL_GS reg
23013 +
23014 +#ifdef CONFIG_CC_STACKPROTECTOR
23015 movl $(__KERNEL_STACK_CANARY), \reg
23016 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23017 + movl $(__USER_DS), \reg
23018 +#else
23019 + xorl \reg, \reg
23020 +#endif
23021 +
23022 movl \reg, %gs
23023 .endm
23024
23025 #endif /* CONFIG_X86_32_LAZY_GS */
23026
23027 -.macro SAVE_ALL
23028 +.macro pax_enter_kernel
23029 +#ifdef CONFIG_PAX_KERNEXEC
23030 + call pax_enter_kernel
23031 +#endif
23032 +.endm
23033 +
23034 +.macro pax_exit_kernel
23035 +#ifdef CONFIG_PAX_KERNEXEC
23036 + call pax_exit_kernel
23037 +#endif
23038 +.endm
23039 +
23040 +#ifdef CONFIG_PAX_KERNEXEC
23041 +ENTRY(pax_enter_kernel)
23042 +#ifdef CONFIG_PARAVIRT
23043 + pushl %eax
23044 + pushl %ecx
23045 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
23046 + mov %eax, %esi
23047 +#else
23048 + mov %cr0, %esi
23049 +#endif
23050 + bts $16, %esi
23051 + jnc 1f
23052 + mov %cs, %esi
23053 + cmp $__KERNEL_CS, %esi
23054 + jz 3f
23055 + ljmp $__KERNEL_CS, $3f
23056 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
23057 +2:
23058 +#ifdef CONFIG_PARAVIRT
23059 + mov %esi, %eax
23060 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
23061 +#else
23062 + mov %esi, %cr0
23063 +#endif
23064 +3:
23065 +#ifdef CONFIG_PARAVIRT
23066 + popl %ecx
23067 + popl %eax
23068 +#endif
23069 + ret
23070 +ENDPROC(pax_enter_kernel)
23071 +
23072 +ENTRY(pax_exit_kernel)
23073 +#ifdef CONFIG_PARAVIRT
23074 + pushl %eax
23075 + pushl %ecx
23076 +#endif
23077 + mov %cs, %esi
23078 + cmp $__KERNEXEC_KERNEL_CS, %esi
23079 + jnz 2f
23080 +#ifdef CONFIG_PARAVIRT
23081 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
23082 + mov %eax, %esi
23083 +#else
23084 + mov %cr0, %esi
23085 +#endif
23086 + btr $16, %esi
23087 + ljmp $__KERNEL_CS, $1f
23088 +1:
23089 +#ifdef CONFIG_PARAVIRT
23090 + mov %esi, %eax
23091 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
23092 +#else
23093 + mov %esi, %cr0
23094 +#endif
23095 +2:
23096 +#ifdef CONFIG_PARAVIRT
23097 + popl %ecx
23098 + popl %eax
23099 +#endif
23100 + ret
23101 +ENDPROC(pax_exit_kernel)
23102 +#endif
23103 +
23104 + .macro pax_erase_kstack
23105 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23106 + call pax_erase_kstack
23107 +#endif
23108 + .endm
23109 +
23110 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23111 +/*
23112 + * ebp: thread_info
23113 + */
23114 +ENTRY(pax_erase_kstack)
23115 + pushl %edi
23116 + pushl %ecx
23117 + pushl %eax
23118 +
23119 + mov TI_lowest_stack(%ebp), %edi
23120 + mov $-0xBEEF, %eax
23121 + std
23122 +
23123 +1: mov %edi, %ecx
23124 + and $THREAD_SIZE_asm - 1, %ecx
23125 + shr $2, %ecx
23126 + repne scasl
23127 + jecxz 2f
23128 +
23129 + cmp $2*16, %ecx
23130 + jc 2f
23131 +
23132 + mov $2*16, %ecx
23133 + repe scasl
23134 + jecxz 2f
23135 + jne 1b
23136 +
23137 +2: cld
23138 + mov %esp, %ecx
23139 + sub %edi, %ecx
23140 +
23141 + cmp $THREAD_SIZE_asm, %ecx
23142 + jb 3f
23143 + ud2
23144 +3:
23145 +
23146 + shr $2, %ecx
23147 + rep stosl
23148 +
23149 + mov TI_task_thread_sp0(%ebp), %edi
23150 + sub $128, %edi
23151 + mov %edi, TI_lowest_stack(%ebp)
23152 +
23153 + popl %eax
23154 + popl %ecx
23155 + popl %edi
23156 + ret
23157 +ENDPROC(pax_erase_kstack)
23158 +#endif
23159 +
23160 +.macro __SAVE_ALL _DS
23161 cld
23162 PUSH_GS
23163 pushl_cfi %fs
23164 @@ -206,7 +346,7 @@
23165 CFI_REL_OFFSET ecx, 0
23166 pushl_cfi %ebx
23167 CFI_REL_OFFSET ebx, 0
23168 - movl $(__USER_DS), %edx
23169 + movl $\_DS, %edx
23170 movl %edx, %ds
23171 movl %edx, %es
23172 movl $(__KERNEL_PERCPU), %edx
23173 @@ -214,6 +354,15 @@
23174 SET_KERNEL_GS %edx
23175 .endm
23176
23177 +.macro SAVE_ALL
23178 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23179 + __SAVE_ALL __KERNEL_DS
23180 + pax_enter_kernel
23181 +#else
23182 + __SAVE_ALL __USER_DS
23183 +#endif
23184 +.endm
23185 +
23186 .macro RESTORE_INT_REGS
23187 popl_cfi %ebx
23188 CFI_RESTORE ebx
23189 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
23190 popfl_cfi
23191 jmp syscall_exit
23192 CFI_ENDPROC
23193 -END(ret_from_fork)
23194 +ENDPROC(ret_from_fork)
23195
23196 ENTRY(ret_from_kernel_thread)
23197 CFI_STARTPROC
23198 @@ -340,7 +489,15 @@ ret_from_intr:
23199 andl $SEGMENT_RPL_MASK, %eax
23200 #endif
23201 cmpl $USER_RPL, %eax
23202 +
23203 +#ifdef CONFIG_PAX_KERNEXEC
23204 + jae resume_userspace
23205 +
23206 + pax_exit_kernel
23207 + jmp resume_kernel
23208 +#else
23209 jb resume_kernel # not returning to v8086 or userspace
23210 +#endif
23211
23212 ENTRY(resume_userspace)
23213 LOCKDEP_SYS_EXIT
23214 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
23215 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
23216 # int/exception return?
23217 jne work_pending
23218 - jmp restore_all
23219 -END(ret_from_exception)
23220 + jmp restore_all_pax
23221 +ENDPROC(ret_from_exception)
23222
23223 #ifdef CONFIG_PREEMPT
23224 ENTRY(resume_kernel)
23225 @@ -365,7 +522,7 @@ need_resched:
23226 jz restore_all
23227 call preempt_schedule_irq
23228 jmp need_resched
23229 -END(resume_kernel)
23230 +ENDPROC(resume_kernel)
23231 #endif
23232 CFI_ENDPROC
23233
23234 @@ -395,30 +552,45 @@ sysenter_past_esp:
23235 /*CFI_REL_OFFSET cs, 0*/
23236 /*
23237 * Push current_thread_info()->sysenter_return to the stack.
23238 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
23239 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
23240 */
23241 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
23242 + pushl_cfi $0
23243 CFI_REL_OFFSET eip, 0
23244
23245 pushl_cfi %eax
23246 SAVE_ALL
23247 + GET_THREAD_INFO(%ebp)
23248 + movl TI_sysenter_return(%ebp),%ebp
23249 + movl %ebp,PT_EIP(%esp)
23250 ENABLE_INTERRUPTS(CLBR_NONE)
23251
23252 /*
23253 * Load the potential sixth argument from user stack.
23254 * Careful about security.
23255 */
23256 + movl PT_OLDESP(%esp),%ebp
23257 +
23258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23259 + mov PT_OLDSS(%esp),%ds
23260 +1: movl %ds:(%ebp),%ebp
23261 + push %ss
23262 + pop %ds
23263 +#else
23264 cmpl $__PAGE_OFFSET-3,%ebp
23265 jae syscall_fault
23266 ASM_STAC
23267 1: movl (%ebp),%ebp
23268 ASM_CLAC
23269 +#endif
23270 +
23271 movl %ebp,PT_EBP(%esp)
23272 _ASM_EXTABLE(1b,syscall_fault)
23273
23274 GET_THREAD_INFO(%ebp)
23275
23276 +#ifdef CONFIG_PAX_RANDKSTACK
23277 + pax_erase_kstack
23278 +#endif
23279 +
23280 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23281 jnz sysenter_audit
23282 sysenter_do_call:
23283 @@ -434,12 +606,24 @@ sysenter_after_call:
23284 testl $_TIF_ALLWORK_MASK, %ecx
23285 jne sysexit_audit
23286 sysenter_exit:
23287 +
23288 +#ifdef CONFIG_PAX_RANDKSTACK
23289 + pushl_cfi %eax
23290 + movl %esp, %eax
23291 + call pax_randomize_kstack
23292 + popl_cfi %eax
23293 +#endif
23294 +
23295 + pax_erase_kstack
23296 +
23297 /* if something modifies registers it must also disable sysexit */
23298 movl PT_EIP(%esp), %edx
23299 movl PT_OLDESP(%esp), %ecx
23300 xorl %ebp,%ebp
23301 TRACE_IRQS_ON
23302 1: mov PT_FS(%esp), %fs
23303 +2: mov PT_DS(%esp), %ds
23304 +3: mov PT_ES(%esp), %es
23305 PTGS_TO_GS
23306 ENABLE_INTERRUPTS_SYSEXIT
23307
23308 @@ -456,6 +640,9 @@ sysenter_audit:
23309 movl %eax,%edx /* 2nd arg: syscall number */
23310 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
23311 call __audit_syscall_entry
23312 +
23313 + pax_erase_kstack
23314 +
23315 pushl_cfi %ebx
23316 movl PT_EAX(%esp),%eax /* reload syscall number */
23317 jmp sysenter_do_call
23318 @@ -481,10 +668,16 @@ sysexit_audit:
23319
23320 CFI_ENDPROC
23321 .pushsection .fixup,"ax"
23322 -2: movl $0,PT_FS(%esp)
23323 +4: movl $0,PT_FS(%esp)
23324 + jmp 1b
23325 +5: movl $0,PT_DS(%esp)
23326 + jmp 1b
23327 +6: movl $0,PT_ES(%esp)
23328 jmp 1b
23329 .popsection
23330 - _ASM_EXTABLE(1b,2b)
23331 + _ASM_EXTABLE(1b,4b)
23332 + _ASM_EXTABLE(2b,5b)
23333 + _ASM_EXTABLE(3b,6b)
23334 PTGS_TO_GS_EX
23335 ENDPROC(ia32_sysenter_target)
23336
23337 @@ -495,6 +688,11 @@ ENTRY(system_call)
23338 pushl_cfi %eax # save orig_eax
23339 SAVE_ALL
23340 GET_THREAD_INFO(%ebp)
23341 +
23342 +#ifdef CONFIG_PAX_RANDKSTACK
23343 + pax_erase_kstack
23344 +#endif
23345 +
23346 # system call tracing in operation / emulation
23347 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23348 jnz syscall_trace_entry
23349 @@ -514,6 +712,15 @@ syscall_exit:
23350 testl $_TIF_ALLWORK_MASK, %ecx # current->work
23351 jne syscall_exit_work
23352
23353 +restore_all_pax:
23354 +
23355 +#ifdef CONFIG_PAX_RANDKSTACK
23356 + movl %esp, %eax
23357 + call pax_randomize_kstack
23358 +#endif
23359 +
23360 + pax_erase_kstack
23361 +
23362 restore_all:
23363 TRACE_IRQS_IRET
23364 restore_all_notrace:
23365 @@ -568,14 +775,34 @@ ldt_ss:
23366 * compensating for the offset by changing to the ESPFIX segment with
23367 * a base address that matches for the difference.
23368 */
23369 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
23370 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
23371 mov %esp, %edx /* load kernel esp */
23372 mov PT_OLDESP(%esp), %eax /* load userspace esp */
23373 mov %dx, %ax /* eax: new kernel esp */
23374 sub %eax, %edx /* offset (low word is 0) */
23375 +#ifdef CONFIG_SMP
23376 + movl PER_CPU_VAR(cpu_number), %ebx
23377 + shll $PAGE_SHIFT_asm, %ebx
23378 + addl $cpu_gdt_table, %ebx
23379 +#else
23380 + movl $cpu_gdt_table, %ebx
23381 +#endif
23382 shr $16, %edx
23383 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
23384 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
23385 +
23386 +#ifdef CONFIG_PAX_KERNEXEC
23387 + mov %cr0, %esi
23388 + btr $16, %esi
23389 + mov %esi, %cr0
23390 +#endif
23391 +
23392 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
23393 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
23394 +
23395 +#ifdef CONFIG_PAX_KERNEXEC
23396 + bts $16, %esi
23397 + mov %esi, %cr0
23398 +#endif
23399 +
23400 pushl_cfi $__ESPFIX_SS
23401 pushl_cfi %eax /* new kernel esp */
23402 /* Disable interrupts, but do not irqtrace this section: we
23403 @@ -605,20 +832,18 @@ work_resched:
23404 movl TI_flags(%ebp), %ecx
23405 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
23406 # than syscall tracing?
23407 - jz restore_all
23408 + jz restore_all_pax
23409 testb $_TIF_NEED_RESCHED, %cl
23410 jnz work_resched
23411
23412 work_notifysig: # deal with pending signals and
23413 # notify-resume requests
23414 + movl %esp, %eax
23415 #ifdef CONFIG_VM86
23416 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
23417 - movl %esp, %eax
23418 jne work_notifysig_v86 # returning to kernel-space or
23419 # vm86-space
23420 1:
23421 -#else
23422 - movl %esp, %eax
23423 #endif
23424 TRACE_IRQS_ON
23425 ENABLE_INTERRUPTS(CLBR_NONE)
23426 @@ -639,7 +864,7 @@ work_notifysig_v86:
23427 movl %eax, %esp
23428 jmp 1b
23429 #endif
23430 -END(work_pending)
23431 +ENDPROC(work_pending)
23432
23433 # perform syscall exit tracing
23434 ALIGN
23435 @@ -647,11 +872,14 @@ syscall_trace_entry:
23436 movl $-ENOSYS,PT_EAX(%esp)
23437 movl %esp, %eax
23438 call syscall_trace_enter
23439 +
23440 + pax_erase_kstack
23441 +
23442 /* What it returned is what we'll actually use. */
23443 cmpl $(NR_syscalls), %eax
23444 jnae syscall_call
23445 jmp syscall_exit
23446 -END(syscall_trace_entry)
23447 +ENDPROC(syscall_trace_entry)
23448
23449 # perform syscall exit tracing
23450 ALIGN
23451 @@ -664,26 +892,30 @@ syscall_exit_work:
23452 movl %esp, %eax
23453 call syscall_trace_leave
23454 jmp resume_userspace
23455 -END(syscall_exit_work)
23456 +ENDPROC(syscall_exit_work)
23457 CFI_ENDPROC
23458
23459 RING0_INT_FRAME # can't unwind into user space anyway
23460 syscall_fault:
23461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23462 + push %ss
23463 + pop %ds
23464 +#endif
23465 ASM_CLAC
23466 GET_THREAD_INFO(%ebp)
23467 movl $-EFAULT,PT_EAX(%esp)
23468 jmp resume_userspace
23469 -END(syscall_fault)
23470 +ENDPROC(syscall_fault)
23471
23472 syscall_badsys:
23473 movl $-ENOSYS,%eax
23474 jmp syscall_after_call
23475 -END(syscall_badsys)
23476 +ENDPROC(syscall_badsys)
23477
23478 sysenter_badsys:
23479 movl $-ENOSYS,%eax
23480 jmp sysenter_after_call
23481 -END(sysenter_badsys)
23482 +ENDPROC(sysenter_badsys)
23483 CFI_ENDPROC
23484
23485 .macro FIXUP_ESPFIX_STACK
23486 @@ -696,8 +928,15 @@ END(sysenter_badsys)
23487 */
23488 #ifdef CONFIG_X86_ESPFIX32
23489 /* fixup the stack */
23490 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23491 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23492 +#ifdef CONFIG_SMP
23493 + movl PER_CPU_VAR(cpu_number), %ebx
23494 + shll $PAGE_SHIFT_asm, %ebx
23495 + addl $cpu_gdt_table, %ebx
23496 +#else
23497 + movl $cpu_gdt_table, %ebx
23498 +#endif
23499 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23500 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23501 shl $16, %eax
23502 addl %esp, %eax /* the adjusted stack pointer */
23503 pushl_cfi $__KERNEL_DS
23504 @@ -753,7 +992,7 @@ vector=vector+1
23505 .endr
23506 2: jmp common_interrupt
23507 .endr
23508 -END(irq_entries_start)
23509 +ENDPROC(irq_entries_start)
23510
23511 .previous
23512 END(interrupt)
23513 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23514 pushl_cfi $do_coprocessor_error
23515 jmp error_code
23516 CFI_ENDPROC
23517 -END(coprocessor_error)
23518 +ENDPROC(coprocessor_error)
23519
23520 ENTRY(simd_coprocessor_error)
23521 RING0_INT_FRAME
23522 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23523 .section .altinstructions,"a"
23524 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23525 .previous
23526 -.section .altinstr_replacement,"ax"
23527 +.section .altinstr_replacement,"a"
23528 663: pushl $do_simd_coprocessor_error
23529 664:
23530 .previous
23531 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23532 #endif
23533 jmp error_code
23534 CFI_ENDPROC
23535 -END(simd_coprocessor_error)
23536 +ENDPROC(simd_coprocessor_error)
23537
23538 ENTRY(device_not_available)
23539 RING0_INT_FRAME
23540 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23541 pushl_cfi $do_device_not_available
23542 jmp error_code
23543 CFI_ENDPROC
23544 -END(device_not_available)
23545 +ENDPROC(device_not_available)
23546
23547 #ifdef CONFIG_PARAVIRT
23548 ENTRY(native_iret)
23549 iret
23550 _ASM_EXTABLE(native_iret, iret_exc)
23551 -END(native_iret)
23552 +ENDPROC(native_iret)
23553
23554 ENTRY(native_irq_enable_sysexit)
23555 sti
23556 sysexit
23557 -END(native_irq_enable_sysexit)
23558 +ENDPROC(native_irq_enable_sysexit)
23559 #endif
23560
23561 ENTRY(overflow)
23562 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23563 pushl_cfi $do_overflow
23564 jmp error_code
23565 CFI_ENDPROC
23566 -END(overflow)
23567 +ENDPROC(overflow)
23568
23569 ENTRY(bounds)
23570 RING0_INT_FRAME
23571 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23572 pushl_cfi $do_bounds
23573 jmp error_code
23574 CFI_ENDPROC
23575 -END(bounds)
23576 +ENDPROC(bounds)
23577
23578 ENTRY(invalid_op)
23579 RING0_INT_FRAME
23580 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23581 pushl_cfi $do_invalid_op
23582 jmp error_code
23583 CFI_ENDPROC
23584 -END(invalid_op)
23585 +ENDPROC(invalid_op)
23586
23587 ENTRY(coprocessor_segment_overrun)
23588 RING0_INT_FRAME
23589 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23590 pushl_cfi $do_coprocessor_segment_overrun
23591 jmp error_code
23592 CFI_ENDPROC
23593 -END(coprocessor_segment_overrun)
23594 +ENDPROC(coprocessor_segment_overrun)
23595
23596 ENTRY(invalid_TSS)
23597 RING0_EC_FRAME
23598 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23599 pushl_cfi $do_invalid_TSS
23600 jmp error_code
23601 CFI_ENDPROC
23602 -END(invalid_TSS)
23603 +ENDPROC(invalid_TSS)
23604
23605 ENTRY(segment_not_present)
23606 RING0_EC_FRAME
23607 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23608 pushl_cfi $do_segment_not_present
23609 jmp error_code
23610 CFI_ENDPROC
23611 -END(segment_not_present)
23612 +ENDPROC(segment_not_present)
23613
23614 ENTRY(stack_segment)
23615 RING0_EC_FRAME
23616 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23617 pushl_cfi $do_stack_segment
23618 jmp error_code
23619 CFI_ENDPROC
23620 -END(stack_segment)
23621 +ENDPROC(stack_segment)
23622
23623 ENTRY(alignment_check)
23624 RING0_EC_FRAME
23625 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23626 pushl_cfi $do_alignment_check
23627 jmp error_code
23628 CFI_ENDPROC
23629 -END(alignment_check)
23630 +ENDPROC(alignment_check)
23631
23632 ENTRY(divide_error)
23633 RING0_INT_FRAME
23634 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23635 pushl_cfi $do_divide_error
23636 jmp error_code
23637 CFI_ENDPROC
23638 -END(divide_error)
23639 +ENDPROC(divide_error)
23640
23641 #ifdef CONFIG_X86_MCE
23642 ENTRY(machine_check)
23643 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23644 pushl_cfi machine_check_vector
23645 jmp error_code
23646 CFI_ENDPROC
23647 -END(machine_check)
23648 +ENDPROC(machine_check)
23649 #endif
23650
23651 ENTRY(spurious_interrupt_bug)
23652 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23653 pushl_cfi $do_spurious_interrupt_bug
23654 jmp error_code
23655 CFI_ENDPROC
23656 -END(spurious_interrupt_bug)
23657 +ENDPROC(spurious_interrupt_bug)
23658
23659 #ifdef CONFIG_XEN
23660 /* Xen doesn't set %esp to be precisely what the normal sysenter
23661 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23662
23663 ENTRY(mcount)
23664 ret
23665 -END(mcount)
23666 +ENDPROC(mcount)
23667
23668 ENTRY(ftrace_caller)
23669 pushl %eax
23670 @@ -1086,7 +1325,7 @@ ftrace_graph_call:
23671 .globl ftrace_stub
23672 ftrace_stub:
23673 ret
23674 -END(ftrace_caller)
23675 +ENDPROC(ftrace_caller)
23676
23677 ENTRY(ftrace_regs_caller)
23678 pushf /* push flags before compare (in cs location) */
23679 @@ -1184,7 +1423,7 @@ trace:
23680 popl %ecx
23681 popl %eax
23682 jmp ftrace_stub
23683 -END(mcount)
23684 +ENDPROC(mcount)
23685 #endif /* CONFIG_DYNAMIC_FTRACE */
23686 #endif /* CONFIG_FUNCTION_TRACER */
23687
23688 @@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23689 popl %ecx
23690 popl %eax
23691 ret
23692 -END(ftrace_graph_caller)
23693 +ENDPROC(ftrace_graph_caller)
23694
23695 .globl return_to_handler
23696 return_to_handler:
23697 @@ -1263,15 +1502,18 @@ error_code:
23698 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23699 REG_TO_PTGS %ecx
23700 SET_KERNEL_GS %ecx
23701 - movl $(__USER_DS), %ecx
23702 + movl $(__KERNEL_DS), %ecx
23703 movl %ecx, %ds
23704 movl %ecx, %es
23705 +
23706 + pax_enter_kernel
23707 +
23708 TRACE_IRQS_OFF
23709 movl %esp,%eax # pt_regs pointer
23710 call *%edi
23711 jmp ret_from_exception
23712 CFI_ENDPROC
23713 -END(page_fault)
23714 +ENDPROC(page_fault)
23715
23716 /*
23717 * Debug traps and NMI can happen at the one SYSENTER instruction
23718 @@ -1314,7 +1556,7 @@ debug_stack_correct:
23719 call do_debug
23720 jmp ret_from_exception
23721 CFI_ENDPROC
23722 -END(debug)
23723 +ENDPROC(debug)
23724
23725 /*
23726 * NMI is doubly nasty. It can happen _while_ we're handling
23727 @@ -1354,6 +1596,9 @@ nmi_stack_correct:
23728 xorl %edx,%edx # zero error code
23729 movl %esp,%eax # pt_regs pointer
23730 call do_nmi
23731 +
23732 + pax_exit_kernel
23733 +
23734 jmp restore_all_notrace
23735 CFI_ENDPROC
23736
23737 @@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23738 FIXUP_ESPFIX_STACK # %eax == %esp
23739 xorl %edx,%edx # zero error code
23740 call do_nmi
23741 +
23742 + pax_exit_kernel
23743 +
23744 RESTORE_REGS
23745 lss 12+4(%esp), %esp # back to espfix stack
23746 CFI_ADJUST_CFA_OFFSET -24
23747 jmp irq_return
23748 #endif
23749 CFI_ENDPROC
23750 -END(nmi)
23751 +ENDPROC(nmi)
23752
23753 ENTRY(int3)
23754 RING0_INT_FRAME
23755 @@ -1410,14 +1658,14 @@ ENTRY(int3)
23756 call do_int3
23757 jmp ret_from_exception
23758 CFI_ENDPROC
23759 -END(int3)
23760 +ENDPROC(int3)
23761
23762 ENTRY(general_protection)
23763 RING0_EC_FRAME
23764 pushl_cfi $do_general_protection
23765 jmp error_code
23766 CFI_ENDPROC
23767 -END(general_protection)
23768 +ENDPROC(general_protection)
23769
23770 #ifdef CONFIG_KVM_GUEST
23771 ENTRY(async_page_fault)
23772 @@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23773 pushl_cfi $do_async_page_fault
23774 jmp error_code
23775 CFI_ENDPROC
23776 -END(async_page_fault)
23777 +ENDPROC(async_page_fault)
23778 #endif
23779
23780 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23781 index 2fac134..b020fca 100644
23782 --- a/arch/x86/kernel/entry_64.S
23783 +++ b/arch/x86/kernel/entry_64.S
23784 @@ -59,6 +59,8 @@
23785 #include <asm/smap.h>
23786 #include <asm/pgtable_types.h>
23787 #include <linux/err.h>
23788 +#include <asm/pgtable.h>
23789 +#include <asm/alternative-asm.h>
23790
23791 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23792 #include <linux/elf-em.h>
23793 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23794 ENDPROC(native_usergs_sysret64)
23795 #endif /* CONFIG_PARAVIRT */
23796
23797 + .macro ljmpq sel, off
23798 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23799 + .byte 0x48; ljmp *1234f(%rip)
23800 + .pushsection .rodata
23801 + .align 16
23802 + 1234: .quad \off; .word \sel
23803 + .popsection
23804 +#else
23805 + pushq $\sel
23806 + pushq $\off
23807 + lretq
23808 +#endif
23809 + .endm
23810 +
23811 + .macro pax_enter_kernel
23812 + pax_set_fptr_mask
23813 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23814 + call pax_enter_kernel
23815 +#endif
23816 + .endm
23817 +
23818 + .macro pax_exit_kernel
23819 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23820 + call pax_exit_kernel
23821 +#endif
23822 +
23823 + .endm
23824 +
23825 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23826 +ENTRY(pax_enter_kernel)
23827 + pushq %rdi
23828 +
23829 +#ifdef CONFIG_PARAVIRT
23830 + PV_SAVE_REGS(CLBR_RDI)
23831 +#endif
23832 +
23833 +#ifdef CONFIG_PAX_KERNEXEC
23834 + GET_CR0_INTO_RDI
23835 + bts $16,%rdi
23836 + jnc 3f
23837 + mov %cs,%edi
23838 + cmp $__KERNEL_CS,%edi
23839 + jnz 2f
23840 +1:
23841 +#endif
23842 +
23843 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23844 + 661: jmp 111f
23845 + .pushsection .altinstr_replacement, "a"
23846 + 662: ASM_NOP2
23847 + .popsection
23848 + .pushsection .altinstructions, "a"
23849 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23850 + .popsection
23851 + GET_CR3_INTO_RDI
23852 + cmp $0,%dil
23853 + jnz 112f
23854 + mov $__KERNEL_DS,%edi
23855 + mov %edi,%ss
23856 + jmp 111f
23857 +112: cmp $1,%dil
23858 + jz 113f
23859 + ud2
23860 +113: sub $4097,%rdi
23861 + bts $63,%rdi
23862 + SET_RDI_INTO_CR3
23863 + mov $__UDEREF_KERNEL_DS,%edi
23864 + mov %edi,%ss
23865 +111:
23866 +#endif
23867 +
23868 +#ifdef CONFIG_PARAVIRT
23869 + PV_RESTORE_REGS(CLBR_RDI)
23870 +#endif
23871 +
23872 + popq %rdi
23873 + pax_force_retaddr
23874 + retq
23875 +
23876 +#ifdef CONFIG_PAX_KERNEXEC
23877 +2: ljmpq __KERNEL_CS,1b
23878 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23879 +4: SET_RDI_INTO_CR0
23880 + jmp 1b
23881 +#endif
23882 +ENDPROC(pax_enter_kernel)
23883 +
23884 +ENTRY(pax_exit_kernel)
23885 + pushq %rdi
23886 +
23887 +#ifdef CONFIG_PARAVIRT
23888 + PV_SAVE_REGS(CLBR_RDI)
23889 +#endif
23890 +
23891 +#ifdef CONFIG_PAX_KERNEXEC
23892 + mov %cs,%rdi
23893 + cmp $__KERNEXEC_KERNEL_CS,%edi
23894 + jz 2f
23895 + GET_CR0_INTO_RDI
23896 + bts $16,%rdi
23897 + jnc 4f
23898 +1:
23899 +#endif
23900 +
23901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23902 + 661: jmp 111f
23903 + .pushsection .altinstr_replacement, "a"
23904 + 662: ASM_NOP2
23905 + .popsection
23906 + .pushsection .altinstructions, "a"
23907 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23908 + .popsection
23909 + mov %ss,%edi
23910 + cmp $__UDEREF_KERNEL_DS,%edi
23911 + jnz 111f
23912 + GET_CR3_INTO_RDI
23913 + cmp $0,%dil
23914 + jz 112f
23915 + ud2
23916 +112: add $4097,%rdi
23917 + bts $63,%rdi
23918 + SET_RDI_INTO_CR3
23919 + mov $__KERNEL_DS,%edi
23920 + mov %edi,%ss
23921 +111:
23922 +#endif
23923 +
23924 +#ifdef CONFIG_PARAVIRT
23925 + PV_RESTORE_REGS(CLBR_RDI);
23926 +#endif
23927 +
23928 + popq %rdi
23929 + pax_force_retaddr
23930 + retq
23931 +
23932 +#ifdef CONFIG_PAX_KERNEXEC
23933 +2: GET_CR0_INTO_RDI
23934 + btr $16,%rdi
23935 + jnc 4f
23936 + ljmpq __KERNEL_CS,3f
23937 +3: SET_RDI_INTO_CR0
23938 + jmp 1b
23939 +4: ud2
23940 + jmp 4b
23941 +#endif
23942 +ENDPROC(pax_exit_kernel)
23943 +#endif
23944 +
23945 + .macro pax_enter_kernel_user
23946 + pax_set_fptr_mask
23947 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23948 + call pax_enter_kernel_user
23949 +#endif
23950 + .endm
23951 +
23952 + .macro pax_exit_kernel_user
23953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23954 + call pax_exit_kernel_user
23955 +#endif
23956 +#ifdef CONFIG_PAX_RANDKSTACK
23957 + pushq %rax
23958 + pushq %r11
23959 + call pax_randomize_kstack
23960 + popq %r11
23961 + popq %rax
23962 +#endif
23963 + .endm
23964 +
23965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23966 +ENTRY(pax_enter_kernel_user)
23967 + pushq %rdi
23968 + pushq %rbx
23969 +
23970 +#ifdef CONFIG_PARAVIRT
23971 + PV_SAVE_REGS(CLBR_RDI)
23972 +#endif
23973 +
23974 + 661: jmp 111f
23975 + .pushsection .altinstr_replacement, "a"
23976 + 662: ASM_NOP2
23977 + .popsection
23978 + .pushsection .altinstructions, "a"
23979 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23980 + .popsection
23981 + GET_CR3_INTO_RDI
23982 + cmp $1,%dil
23983 + jnz 4f
23984 + sub $4097,%rdi
23985 + bts $63,%rdi
23986 + SET_RDI_INTO_CR3
23987 + jmp 3f
23988 +111:
23989 +
23990 + GET_CR3_INTO_RDI
23991 + mov %rdi,%rbx
23992 + add $__START_KERNEL_map,%rbx
23993 + sub phys_base(%rip),%rbx
23994 +
23995 +#ifdef CONFIG_PARAVIRT
23996 + cmpl $0, pv_info+PARAVIRT_enabled
23997 + jz 1f
23998 + pushq %rdi
23999 + i = 0
24000 + .rept USER_PGD_PTRS
24001 + mov i*8(%rbx),%rsi
24002 + mov $0,%sil
24003 + lea i*8(%rbx),%rdi
24004 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24005 + i = i + 1
24006 + .endr
24007 + popq %rdi
24008 + jmp 2f
24009 +1:
24010 +#endif
24011 +
24012 + i = 0
24013 + .rept USER_PGD_PTRS
24014 + movb $0,i*8(%rbx)
24015 + i = i + 1
24016 + .endr
24017 +
24018 +2: SET_RDI_INTO_CR3
24019 +
24020 +#ifdef CONFIG_PAX_KERNEXEC
24021 + GET_CR0_INTO_RDI
24022 + bts $16,%rdi
24023 + SET_RDI_INTO_CR0
24024 +#endif
24025 +
24026 +3:
24027 +
24028 +#ifdef CONFIG_PARAVIRT
24029 + PV_RESTORE_REGS(CLBR_RDI)
24030 +#endif
24031 +
24032 + popq %rbx
24033 + popq %rdi
24034 + pax_force_retaddr
24035 + retq
24036 +4: ud2
24037 +ENDPROC(pax_enter_kernel_user)
24038 +
24039 +ENTRY(pax_exit_kernel_user)
24040 + pushq %rdi
24041 + pushq %rbx
24042 +
24043 +#ifdef CONFIG_PARAVIRT
24044 + PV_SAVE_REGS(CLBR_RDI)
24045 +#endif
24046 +
24047 + GET_CR3_INTO_RDI
24048 + 661: jmp 1f
24049 + .pushsection .altinstr_replacement, "a"
24050 + 662: ASM_NOP2
24051 + .popsection
24052 + .pushsection .altinstructions, "a"
24053 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24054 + .popsection
24055 + cmp $0,%dil
24056 + jnz 3f
24057 + add $4097,%rdi
24058 + bts $63,%rdi
24059 + SET_RDI_INTO_CR3
24060 + jmp 2f
24061 +1:
24062 +
24063 + mov %rdi,%rbx
24064 +
24065 +#ifdef CONFIG_PAX_KERNEXEC
24066 + GET_CR0_INTO_RDI
24067 + btr $16,%rdi
24068 + jnc 3f
24069 + SET_RDI_INTO_CR0
24070 +#endif
24071 +
24072 + add $__START_KERNEL_map,%rbx
24073 + sub phys_base(%rip),%rbx
24074 +
24075 +#ifdef CONFIG_PARAVIRT
24076 + cmpl $0, pv_info+PARAVIRT_enabled
24077 + jz 1f
24078 + i = 0
24079 + .rept USER_PGD_PTRS
24080 + mov i*8(%rbx),%rsi
24081 + mov $0x67,%sil
24082 + lea i*8(%rbx),%rdi
24083 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24084 + i = i + 1
24085 + .endr
24086 + jmp 2f
24087 +1:
24088 +#endif
24089 +
24090 + i = 0
24091 + .rept USER_PGD_PTRS
24092 + movb $0x67,i*8(%rbx)
24093 + i = i + 1
24094 + .endr
24095 +2:
24096 +
24097 +#ifdef CONFIG_PARAVIRT
24098 + PV_RESTORE_REGS(CLBR_RDI)
24099 +#endif
24100 +
24101 + popq %rbx
24102 + popq %rdi
24103 + pax_force_retaddr
24104 + retq
24105 +3: ud2
24106 +ENDPROC(pax_exit_kernel_user)
24107 +#endif
24108 +
24109 + .macro pax_enter_kernel_nmi
24110 + pax_set_fptr_mask
24111 +
24112 +#ifdef CONFIG_PAX_KERNEXEC
24113 + GET_CR0_INTO_RDI
24114 + bts $16,%rdi
24115 + jc 110f
24116 + SET_RDI_INTO_CR0
24117 + or $2,%ebx
24118 +110:
24119 +#endif
24120 +
24121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24122 + 661: jmp 111f
24123 + .pushsection .altinstr_replacement, "a"
24124 + 662: ASM_NOP2
24125 + .popsection
24126 + .pushsection .altinstructions, "a"
24127 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24128 + .popsection
24129 + GET_CR3_INTO_RDI
24130 + cmp $0,%dil
24131 + jz 111f
24132 + sub $4097,%rdi
24133 + or $4,%ebx
24134 + bts $63,%rdi
24135 + SET_RDI_INTO_CR3
24136 + mov $__UDEREF_KERNEL_DS,%edi
24137 + mov %edi,%ss
24138 +111:
24139 +#endif
24140 + .endm
24141 +
24142 + .macro pax_exit_kernel_nmi
24143 +#ifdef CONFIG_PAX_KERNEXEC
24144 + btr $1,%ebx
24145 + jnc 110f
24146 + GET_CR0_INTO_RDI
24147 + btr $16,%rdi
24148 + SET_RDI_INTO_CR0
24149 +110:
24150 +#endif
24151 +
24152 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24153 + btr $2,%ebx
24154 + jnc 111f
24155 + GET_CR3_INTO_RDI
24156 + add $4097,%rdi
24157 + bts $63,%rdi
24158 + SET_RDI_INTO_CR3
24159 + mov $__KERNEL_DS,%edi
24160 + mov %edi,%ss
24161 +111:
24162 +#endif
24163 + .endm
24164 +
24165 + .macro pax_erase_kstack
24166 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24167 + call pax_erase_kstack
24168 +#endif
24169 + .endm
24170 +
24171 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24172 +ENTRY(pax_erase_kstack)
24173 + pushq %rdi
24174 + pushq %rcx
24175 + pushq %rax
24176 + pushq %r11
24177 +
24178 + GET_THREAD_INFO(%r11)
24179 + mov TI_lowest_stack(%r11), %rdi
24180 + mov $-0xBEEF, %rax
24181 + std
24182 +
24183 +1: mov %edi, %ecx
24184 + and $THREAD_SIZE_asm - 1, %ecx
24185 + shr $3, %ecx
24186 + repne scasq
24187 + jecxz 2f
24188 +
24189 + cmp $2*8, %ecx
24190 + jc 2f
24191 +
24192 + mov $2*8, %ecx
24193 + repe scasq
24194 + jecxz 2f
24195 + jne 1b
24196 +
24197 +2: cld
24198 + mov %esp, %ecx
24199 + sub %edi, %ecx
24200 +
24201 + cmp $THREAD_SIZE_asm, %rcx
24202 + jb 3f
24203 + ud2
24204 +3:
24205 +
24206 + shr $3, %ecx
24207 + rep stosq
24208 +
24209 + mov TI_task_thread_sp0(%r11), %rdi
24210 + sub $256, %rdi
24211 + mov %rdi, TI_lowest_stack(%r11)
24212 +
24213 + popq %r11
24214 + popq %rax
24215 + popq %rcx
24216 + popq %rdi
24217 + pax_force_retaddr
24218 + ret
24219 +ENDPROC(pax_erase_kstack)
24220 +#endif
24221
24222 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
24223 #ifdef CONFIG_TRACE_IRQFLAGS
24224 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
24225 .endm
24226
24227 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
24228 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
24229 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
24230 jnc 1f
24231 TRACE_IRQS_ON_DEBUG
24232 1:
24233 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
24234 movq \tmp,R11+\offset(%rsp)
24235 .endm
24236
24237 - .macro FAKE_STACK_FRAME child_rip
24238 - /* push in order ss, rsp, eflags, cs, rip */
24239 - xorl %eax, %eax
24240 - pushq_cfi $__KERNEL_DS /* ss */
24241 - /*CFI_REL_OFFSET ss,0*/
24242 - pushq_cfi %rax /* rsp */
24243 - CFI_REL_OFFSET rsp,0
24244 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
24245 - /*CFI_REL_OFFSET rflags,0*/
24246 - pushq_cfi $__KERNEL_CS /* cs */
24247 - /*CFI_REL_OFFSET cs,0*/
24248 - pushq_cfi \child_rip /* rip */
24249 - CFI_REL_OFFSET rip,0
24250 - pushq_cfi %rax /* orig rax */
24251 - .endm
24252 -
24253 - .macro UNFAKE_STACK_FRAME
24254 - addq $8*6, %rsp
24255 - CFI_ADJUST_CFA_OFFSET -(6*8)
24256 - .endm
24257 -
24258 /*
24259 * initial frame state for interrupts (and exceptions without error code)
24260 */
24261 @@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
24262 /* save partial stack frame */
24263 .macro SAVE_ARGS_IRQ
24264 cld
24265 - /* start from rbp in pt_regs and jump over */
24266 - movq_cfi rdi, (RDI-RBP)
24267 - movq_cfi rsi, (RSI-RBP)
24268 - movq_cfi rdx, (RDX-RBP)
24269 - movq_cfi rcx, (RCX-RBP)
24270 - movq_cfi rax, (RAX-RBP)
24271 - movq_cfi r8, (R8-RBP)
24272 - movq_cfi r9, (R9-RBP)
24273 - movq_cfi r10, (R10-RBP)
24274 - movq_cfi r11, (R11-RBP)
24275 + /* start from r15 in pt_regs and jump over */
24276 + movq_cfi rdi, RDI
24277 + movq_cfi rsi, RSI
24278 + movq_cfi rdx, RDX
24279 + movq_cfi rcx, RCX
24280 + movq_cfi rax, RAX
24281 + movq_cfi r8, R8
24282 + movq_cfi r9, R9
24283 + movq_cfi r10, R10
24284 + movq_cfi r11, R11
24285 + movq_cfi r12, R12
24286
24287 /* Save rbp so that we can unwind from get_irq_regs() */
24288 - movq_cfi rbp, 0
24289 + movq_cfi rbp, RBP
24290
24291 /* Save previous stack value */
24292 movq %rsp, %rsi
24293
24294 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
24295 - testl $3, CS-RBP(%rsi)
24296 + movq %rsp,%rdi /* arg1 for handler */
24297 + testb $3, CS(%rsi)
24298 je 1f
24299 SWAPGS
24300 /*
24301 @@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
24302 0x06 /* DW_OP_deref */, \
24303 0x08 /* DW_OP_const1u */, SS+8-RBP, \
24304 0x22 /* DW_OP_plus */
24305 +
24306 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24307 + testb $3, CS(%rdi)
24308 + jnz 1f
24309 + pax_enter_kernel
24310 + jmp 2f
24311 +1: pax_enter_kernel_user
24312 +2:
24313 +#else
24314 + pax_enter_kernel
24315 +#endif
24316 +
24317 /* We entered an interrupt context - irqs are off: */
24318 TRACE_IRQS_OFF
24319 .endm
24320 @@ -308,9 +726,52 @@ ENTRY(save_paranoid)
24321 js 1f /* negative -> in kernel */
24322 SWAPGS
24323 xorl %ebx,%ebx
24324 -1: ret
24325 +1:
24326 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24327 + testb $3, CS+8(%rsp)
24328 + jnz 1f
24329 + pax_enter_kernel
24330 + jmp 2f
24331 +1: pax_enter_kernel_user
24332 +2:
24333 +#else
24334 + pax_enter_kernel
24335 +#endif
24336 + pax_force_retaddr
24337 + ret
24338 CFI_ENDPROC
24339 -END(save_paranoid)
24340 +ENDPROC(save_paranoid)
24341 +
24342 +ENTRY(save_paranoid_nmi)
24343 + XCPT_FRAME 1 RDI+8
24344 + cld
24345 + movq_cfi rdi, RDI+8
24346 + movq_cfi rsi, RSI+8
24347 + movq_cfi rdx, RDX+8
24348 + movq_cfi rcx, RCX+8
24349 + movq_cfi rax, RAX+8
24350 + movq_cfi r8, R8+8
24351 + movq_cfi r9, R9+8
24352 + movq_cfi r10, R10+8
24353 + movq_cfi r11, R11+8
24354 + movq_cfi rbx, RBX+8
24355 + movq_cfi rbp, RBP+8
24356 + movq_cfi r12, R12+8
24357 + movq_cfi r13, R13+8
24358 + movq_cfi r14, R14+8
24359 + movq_cfi r15, R15+8
24360 + movl $1,%ebx
24361 + movl $MSR_GS_BASE,%ecx
24362 + rdmsr
24363 + testl %edx,%edx
24364 + js 1f /* negative -> in kernel */
24365 + SWAPGS
24366 + xorl %ebx,%ebx
24367 +1: pax_enter_kernel_nmi
24368 + pax_force_retaddr
24369 + ret
24370 + CFI_ENDPROC
24371 +ENDPROC(save_paranoid_nmi)
24372
24373 /*
24374 * A newly forked process directly context switches into this address.
24375 @@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
24376
24377 RESTORE_REST
24378
24379 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24380 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24381 jz 1f
24382
24383 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
24384 @@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
24385 jmp ret_from_sys_call # go to the SYSRET fastpath
24386
24387 1:
24388 - subq $REST_SKIP, %rsp # leave space for volatiles
24389 - CFI_ADJUST_CFA_OFFSET REST_SKIP
24390 movq %rbp, %rdi
24391 call *%rbx
24392 movl $0, RAX(%rsp)
24393 RESTORE_REST
24394 jmp int_ret_from_sys_call
24395 CFI_ENDPROC
24396 -END(ret_from_fork)
24397 +ENDPROC(ret_from_fork)
24398
24399 /*
24400 * System call entry. Up to 6 arguments in registers are supported.
24401 @@ -386,7 +845,7 @@ END(ret_from_fork)
24402 ENTRY(system_call)
24403 CFI_STARTPROC simple
24404 CFI_SIGNAL_FRAME
24405 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
24406 + CFI_DEF_CFA rsp,0
24407 CFI_REGISTER rip,rcx
24408 /*CFI_REGISTER rflags,r11*/
24409 SWAPGS_UNSAFE_STACK
24410 @@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
24411
24412 movq %rsp,PER_CPU_VAR(old_rsp)
24413 movq PER_CPU_VAR(kernel_stack),%rsp
24414 + SAVE_ARGS 8*6,0
24415 + pax_enter_kernel_user
24416 +
24417 +#ifdef CONFIG_PAX_RANDKSTACK
24418 + pax_erase_kstack
24419 +#endif
24420 +
24421 /*
24422 * No need to follow this irqs off/on section - it's straight
24423 * and short:
24424 */
24425 ENABLE_INTERRUPTS(CLBR_NONE)
24426 - SAVE_ARGS 8,0
24427 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
24428 movq %rcx,RIP-ARGOFFSET(%rsp)
24429 CFI_REL_OFFSET rip,RIP-ARGOFFSET
24430 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24431 + GET_THREAD_INFO(%rcx)
24432 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
24433 jnz tracesys
24434 system_call_fastpath:
24435 #if __SYSCALL_MASK == ~0
24436 @@ -432,10 +898,13 @@ sysret_check:
24437 LOCKDEP_SYS_EXIT
24438 DISABLE_INTERRUPTS(CLBR_NONE)
24439 TRACE_IRQS_OFF
24440 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24441 + GET_THREAD_INFO(%rcx)
24442 + movl TI_flags(%rcx),%edx
24443 andl %edi,%edx
24444 jnz sysret_careful
24445 CFI_REMEMBER_STATE
24446 + pax_exit_kernel_user
24447 + pax_erase_kstack
24448 /*
24449 * sysretq will re-enable interrupts:
24450 */
24451 @@ -494,6 +963,9 @@ auditsys:
24452 movq %rax,%rsi /* 2nd arg: syscall number */
24453 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24454 call __audit_syscall_entry
24455 +
24456 + pax_erase_kstack
24457 +
24458 LOAD_ARGS 0 /* reload call-clobbered registers */
24459 jmp system_call_fastpath
24460
24461 @@ -515,7 +987,7 @@ sysret_audit:
24462 /* Do syscall tracing */
24463 tracesys:
24464 #ifdef CONFIG_AUDITSYSCALL
24465 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24466 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24467 jz auditsys
24468 #endif
24469 SAVE_REST
24470 @@ -523,12 +995,15 @@ tracesys:
24471 FIXUP_TOP_OF_STACK %rdi
24472 movq %rsp,%rdi
24473 call syscall_trace_enter
24474 +
24475 + pax_erase_kstack
24476 +
24477 /*
24478 * Reload arg registers from stack in case ptrace changed them.
24479 * We don't reload %rax because syscall_trace_enter() returned
24480 * the value it wants us to use in the table lookup.
24481 */
24482 - LOAD_ARGS ARGOFFSET, 1
24483 + LOAD_ARGS 1
24484 RESTORE_REST
24485 #if __SYSCALL_MASK == ~0
24486 cmpq $__NR_syscall_max,%rax
24487 @@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24488 andl %edi,%edx
24489 jnz int_careful
24490 andl $~TS_COMPAT,TI_status(%rcx)
24491 - jmp retint_swapgs
24492 + pax_exit_kernel_user
24493 + pax_erase_kstack
24494 + jmp retint_swapgs_pax
24495
24496 /* Either reschedule or signal or syscall exit tracking needed. */
24497 /* First do a reschedule test. */
24498 @@ -604,7 +1081,7 @@ int_restore_rest:
24499 TRACE_IRQS_OFF
24500 jmp int_with_check
24501 CFI_ENDPROC
24502 -END(system_call)
24503 +ENDPROC(system_call)
24504
24505 .macro FORK_LIKE func
24506 ENTRY(stub_\func)
24507 @@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24508 DEFAULT_FRAME 0 8 /* offset 8: return address */
24509 call sys_\func
24510 RESTORE_TOP_OF_STACK %r11, 8
24511 - ret $REST_SKIP /* pop extended registers */
24512 + pax_force_retaddr
24513 + ret
24514 CFI_ENDPROC
24515 -END(stub_\func)
24516 +ENDPROC(stub_\func)
24517 .endm
24518
24519 .macro FIXED_FRAME label,func
24520 @@ -629,9 +1107,10 @@ ENTRY(\label)
24521 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24522 call \func
24523 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24524 + pax_force_retaddr
24525 ret
24526 CFI_ENDPROC
24527 -END(\label)
24528 +ENDPROC(\label)
24529 .endm
24530
24531 FORK_LIKE clone
24532 @@ -639,19 +1118,6 @@ END(\label)
24533 FORK_LIKE vfork
24534 FIXED_FRAME stub_iopl, sys_iopl
24535
24536 -ENTRY(ptregscall_common)
24537 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24538 - RESTORE_TOP_OF_STACK %r11, 8
24539 - movq_cfi_restore R15+8, r15
24540 - movq_cfi_restore R14+8, r14
24541 - movq_cfi_restore R13+8, r13
24542 - movq_cfi_restore R12+8, r12
24543 - movq_cfi_restore RBP+8, rbp
24544 - movq_cfi_restore RBX+8, rbx
24545 - ret $REST_SKIP /* pop extended registers */
24546 - CFI_ENDPROC
24547 -END(ptregscall_common)
24548 -
24549 ENTRY(stub_execve)
24550 CFI_STARTPROC
24551 addq $8, %rsp
24552 @@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24553 RESTORE_REST
24554 jmp int_ret_from_sys_call
24555 CFI_ENDPROC
24556 -END(stub_execve)
24557 +ENDPROC(stub_execve)
24558
24559 /*
24560 * sigreturn is special because it needs to restore all registers on return.
24561 @@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24562 RESTORE_REST
24563 jmp int_ret_from_sys_call
24564 CFI_ENDPROC
24565 -END(stub_rt_sigreturn)
24566 +ENDPROC(stub_rt_sigreturn)
24567
24568 #ifdef CONFIG_X86_X32_ABI
24569 ENTRY(stub_x32_rt_sigreturn)
24570 @@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24571 RESTORE_REST
24572 jmp int_ret_from_sys_call
24573 CFI_ENDPROC
24574 -END(stub_x32_rt_sigreturn)
24575 +ENDPROC(stub_x32_rt_sigreturn)
24576
24577 ENTRY(stub_x32_execve)
24578 CFI_STARTPROC
24579 @@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24580 RESTORE_REST
24581 jmp int_ret_from_sys_call
24582 CFI_ENDPROC
24583 -END(stub_x32_execve)
24584 +ENDPROC(stub_x32_execve)
24585
24586 #endif
24587
24588 @@ -745,7 +1211,7 @@ vector=vector+1
24589 2: jmp common_interrupt
24590 .endr
24591 CFI_ENDPROC
24592 -END(irq_entries_start)
24593 +ENDPROC(irq_entries_start)
24594
24595 .previous
24596 END(interrupt)
24597 @@ -762,8 +1228,8 @@ END(interrupt)
24598 /* 0(%rsp): ~(interrupt number) */
24599 .macro interrupt func
24600 /* reserve pt_regs for scratch regs and rbp */
24601 - subq $ORIG_RAX-RBP, %rsp
24602 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24603 + subq $ORIG_RAX, %rsp
24604 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24605 SAVE_ARGS_IRQ
24606 call \func
24607 .endm
24608 @@ -786,14 +1252,14 @@ ret_from_intr:
24609
24610 /* Restore saved previous stack */
24611 popq %rsi
24612 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24613 - leaq ARGOFFSET-RBP(%rsi), %rsp
24614 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24615 + movq %rsi, %rsp
24616 CFI_DEF_CFA_REGISTER rsp
24617 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24618 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24619
24620 exit_intr:
24621 GET_THREAD_INFO(%rcx)
24622 - testl $3,CS-ARGOFFSET(%rsp)
24623 + testb $3,CS-ARGOFFSET(%rsp)
24624 je retint_kernel
24625
24626 /* Interrupt came from user space */
24627 @@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24628 * The iretq could re-enable interrupts:
24629 */
24630 DISABLE_INTERRUPTS(CLBR_ANY)
24631 + pax_exit_kernel_user
24632 +retint_swapgs_pax:
24633 TRACE_IRQS_IRETQ
24634 SWAPGS
24635 jmp restore_args
24636
24637 retint_restore_args: /* return to kernel space */
24638 DISABLE_INTERRUPTS(CLBR_ANY)
24639 + pax_exit_kernel
24640 +
24641 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24642 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24643 + * namely calling EFI runtime services with a phys mapping. We're
24644 + * starting off with NOPs and patch in the real instrumentation
24645 + * (BTS/OR) before starting any userland process; even before starting
24646 + * up the APs.
24647 + */
24648 + .pushsection .altinstr_replacement, "a"
24649 + 601: pax_force_retaddr (RIP-ARGOFFSET)
24650 + 602:
24651 + .popsection
24652 + 603: .fill 602b-601b, 1, 0x90
24653 + .pushsection .altinstructions, "a"
24654 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24655 + .popsection
24656 +#else
24657 + pax_force_retaddr (RIP-ARGOFFSET)
24658 +#endif
24659 +
24660 /*
24661 * The iretq could re-enable interrupts:
24662 */
24663 @@ -933,7 +1422,7 @@ ENTRY(retint_kernel)
24664 jmp exit_intr
24665 #endif
24666 CFI_ENDPROC
24667 -END(common_interrupt)
24668 +ENDPROC(common_interrupt)
24669
24670 /*
24671 * If IRET takes a fault on the espfix stack, then we
24672 @@ -955,13 +1444,13 @@ __do_double_fault:
24673 cmpq $native_irq_return_iret,%rax
24674 jne do_double_fault /* This shouldn't happen... */
24675 movq PER_CPU_VAR(kernel_stack),%rax
24676 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24677 + subq $(6*8),%rax /* Reset to original stack */
24678 movq %rax,RSP(%rdi)
24679 movq $0,(%rax) /* Missing (lost) #GP error code */
24680 movq $general_protection,RIP(%rdi)
24681 retq
24682 CFI_ENDPROC
24683 -END(__do_double_fault)
24684 +ENDPROC(__do_double_fault)
24685 #else
24686 # define __do_double_fault do_double_fault
24687 #endif
24688 @@ -978,7 +1467,7 @@ ENTRY(\sym)
24689 interrupt \do_sym
24690 jmp ret_from_intr
24691 CFI_ENDPROC
24692 -END(\sym)
24693 +ENDPROC(\sym)
24694 .endm
24695
24696 #ifdef CONFIG_TRACING
24697 @@ -1051,7 +1540,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24698 /*
24699 * Exception entry points.
24700 */
24701 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24702 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24703
24704 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24705 ENTRY(\sym)
24706 @@ -1102,6 +1591,12 @@ ENTRY(\sym)
24707 .endif
24708
24709 .if \shift_ist != -1
24710 +#ifdef CONFIG_SMP
24711 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24712 + lea init_tss(%r13), %r13
24713 +#else
24714 + lea init_tss(%rip), %r13
24715 +#endif
24716 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24717 .endif
24718
24719 @@ -1118,7 +1613,7 @@ ENTRY(\sym)
24720 .endif
24721
24722 CFI_ENDPROC
24723 -END(\sym)
24724 +ENDPROC(\sym)
24725 .endm
24726
24727 #ifdef CONFIG_TRACING
24728 @@ -1159,9 +1654,10 @@ gs_change:
24729 2: mfence /* workaround */
24730 SWAPGS
24731 popfq_cfi
24732 + pax_force_retaddr
24733 ret
24734 CFI_ENDPROC
24735 -END(native_load_gs_index)
24736 +ENDPROC(native_load_gs_index)
24737
24738 _ASM_EXTABLE(gs_change,bad_gs)
24739 .section .fixup,"ax"
24740 @@ -1189,9 +1685,10 @@ ENTRY(do_softirq_own_stack)
24741 CFI_DEF_CFA_REGISTER rsp
24742 CFI_ADJUST_CFA_OFFSET -8
24743 decl PER_CPU_VAR(irq_count)
24744 + pax_force_retaddr
24745 ret
24746 CFI_ENDPROC
24747 -END(do_softirq_own_stack)
24748 +ENDPROC(do_softirq_own_stack)
24749
24750 #ifdef CONFIG_XEN
24751 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24752 @@ -1229,7 +1726,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24753 decl PER_CPU_VAR(irq_count)
24754 jmp error_exit
24755 CFI_ENDPROC
24756 -END(xen_do_hypervisor_callback)
24757 +ENDPROC(xen_do_hypervisor_callback)
24758
24759 /*
24760 * Hypervisor uses this for application faults while it executes.
24761 @@ -1288,7 +1785,7 @@ ENTRY(xen_failsafe_callback)
24762 SAVE_ALL
24763 jmp error_exit
24764 CFI_ENDPROC
24765 -END(xen_failsafe_callback)
24766 +ENDPROC(xen_failsafe_callback)
24767
24768 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24769 xen_hvm_callback_vector xen_evtchn_do_upcall
24770 @@ -1335,18 +1832,33 @@ ENTRY(paranoid_exit)
24771 DEFAULT_FRAME
24772 DISABLE_INTERRUPTS(CLBR_NONE)
24773 TRACE_IRQS_OFF_DEBUG
24774 - testl %ebx,%ebx /* swapgs needed? */
24775 + testl $1,%ebx /* swapgs needed? */
24776 jnz paranoid_restore
24777 - testl $3,CS(%rsp)
24778 + testb $3,CS(%rsp)
24779 jnz paranoid_userspace
24780 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24781 + pax_exit_kernel
24782 + TRACE_IRQS_IRETQ 0
24783 + SWAPGS_UNSAFE_STACK
24784 + RESTORE_ALL 8
24785 + pax_force_retaddr_bts
24786 + jmp irq_return
24787 +#endif
24788 paranoid_swapgs:
24789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24790 + pax_exit_kernel_user
24791 +#else
24792 + pax_exit_kernel
24793 +#endif
24794 TRACE_IRQS_IRETQ 0
24795 SWAPGS_UNSAFE_STACK
24796 RESTORE_ALL 8
24797 jmp irq_return
24798 paranoid_restore:
24799 + pax_exit_kernel
24800 TRACE_IRQS_IRETQ_DEBUG 0
24801 RESTORE_ALL 8
24802 + pax_force_retaddr_bts
24803 jmp irq_return
24804 paranoid_userspace:
24805 GET_THREAD_INFO(%rcx)
24806 @@ -1375,7 +1887,7 @@ paranoid_schedule:
24807 TRACE_IRQS_OFF
24808 jmp paranoid_userspace
24809 CFI_ENDPROC
24810 -END(paranoid_exit)
24811 +ENDPROC(paranoid_exit)
24812
24813 /*
24814 * Exception entry point. This expects an error code/orig_rax on the stack.
24815 @@ -1402,12 +1914,23 @@ ENTRY(error_entry)
24816 movq %r14, R14+8(%rsp)
24817 movq %r15, R15+8(%rsp)
24818 xorl %ebx,%ebx
24819 - testl $3,CS+8(%rsp)
24820 + testb $3,CS+8(%rsp)
24821 je error_kernelspace
24822 error_swapgs:
24823 SWAPGS
24824 error_sti:
24825 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24826 + testb $3, CS+8(%rsp)
24827 + jnz 1f
24828 + pax_enter_kernel
24829 + jmp 2f
24830 +1: pax_enter_kernel_user
24831 +2:
24832 +#else
24833 + pax_enter_kernel
24834 +#endif
24835 TRACE_IRQS_OFF
24836 + pax_force_retaddr
24837 ret
24838
24839 /*
24840 @@ -1435,7 +1958,7 @@ bstep_iret:
24841 movq %rcx,RIP+8(%rsp)
24842 jmp error_swapgs
24843 CFI_ENDPROC
24844 -END(error_entry)
24845 +ENDPROC(error_entry)
24846
24847
24848 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24849 @@ -1446,7 +1969,7 @@ ENTRY(error_exit)
24850 DISABLE_INTERRUPTS(CLBR_NONE)
24851 TRACE_IRQS_OFF
24852 GET_THREAD_INFO(%rcx)
24853 - testl %eax,%eax
24854 + testl $1,%eax
24855 jne retint_kernel
24856 LOCKDEP_SYS_EXIT_IRQ
24857 movl TI_flags(%rcx),%edx
24858 @@ -1455,7 +1978,7 @@ ENTRY(error_exit)
24859 jnz retint_careful
24860 jmp retint_swapgs
24861 CFI_ENDPROC
24862 -END(error_exit)
24863 +ENDPROC(error_exit)
24864
24865 /*
24866 * Test if a given stack is an NMI stack or not.
24867 @@ -1513,9 +2036,11 @@ ENTRY(nmi)
24868 * If %cs was not the kernel segment, then the NMI triggered in user
24869 * space, which means it is definitely not nested.
24870 */
24871 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24872 + je 1f
24873 cmpl $__KERNEL_CS, 16(%rsp)
24874 jne first_nmi
24875 -
24876 +1:
24877 /*
24878 * Check the special variable on the stack to see if NMIs are
24879 * executing.
24880 @@ -1549,8 +2074,7 @@ nested_nmi:
24881
24882 1:
24883 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24884 - leaq -1*8(%rsp), %rdx
24885 - movq %rdx, %rsp
24886 + subq $8, %rsp
24887 CFI_ADJUST_CFA_OFFSET 1*8
24888 leaq -10*8(%rsp), %rdx
24889 pushq_cfi $__KERNEL_DS
24890 @@ -1568,6 +2092,7 @@ nested_nmi_out:
24891 CFI_RESTORE rdx
24892
24893 /* No need to check faults here */
24894 +# pax_force_retaddr_bts
24895 INTERRUPT_RETURN
24896
24897 CFI_RESTORE_STATE
24898 @@ -1664,13 +2189,13 @@ end_repeat_nmi:
24899 subq $ORIG_RAX-R15, %rsp
24900 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24901 /*
24902 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24903 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24904 * as we should not be calling schedule in NMI context.
24905 * Even with normal interrupts enabled. An NMI should not be
24906 * setting NEED_RESCHED or anything that normal interrupts and
24907 * exceptions might do.
24908 */
24909 - call save_paranoid
24910 + call save_paranoid_nmi
24911 DEFAULT_FRAME 0
24912
24913 /*
24914 @@ -1680,9 +2205,9 @@ end_repeat_nmi:
24915 * NMI itself takes a page fault, the page fault that was preempted
24916 * will read the information from the NMI page fault and not the
24917 * origin fault. Save it off and restore it if it changes.
24918 - * Use the r12 callee-saved register.
24919 + * Use the r13 callee-saved register.
24920 */
24921 - movq %cr2, %r12
24922 + movq %cr2, %r13
24923
24924 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24925 movq %rsp,%rdi
24926 @@ -1691,29 +2216,34 @@ end_repeat_nmi:
24927
24928 /* Did the NMI take a page fault? Restore cr2 if it did */
24929 movq %cr2, %rcx
24930 - cmpq %rcx, %r12
24931 + cmpq %rcx, %r13
24932 je 1f
24933 - movq %r12, %cr2
24934 + movq %r13, %cr2
24935 1:
24936
24937 - testl %ebx,%ebx /* swapgs needed? */
24938 + testl $1,%ebx /* swapgs needed? */
24939 jnz nmi_restore
24940 nmi_swapgs:
24941 SWAPGS_UNSAFE_STACK
24942 nmi_restore:
24943 + pax_exit_kernel_nmi
24944 /* Pop the extra iret frame at once */
24945 RESTORE_ALL 6*8
24946 + testb $3, 8(%rsp)
24947 + jnz 1f
24948 + pax_force_retaddr_bts
24949 +1:
24950
24951 /* Clear the NMI executing stack variable */
24952 movq $0, 5*8(%rsp)
24953 jmp irq_return
24954 CFI_ENDPROC
24955 -END(nmi)
24956 +ENDPROC(nmi)
24957
24958 ENTRY(ignore_sysret)
24959 CFI_STARTPROC
24960 mov $-ENOSYS,%eax
24961 sysret
24962 CFI_ENDPROC
24963 -END(ignore_sysret)
24964 +ENDPROC(ignore_sysret)
24965
24966 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24967 index 94d857f..bf1f0bf 100644
24968 --- a/arch/x86/kernel/espfix_64.c
24969 +++ b/arch/x86/kernel/espfix_64.c
24970 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24971 set_pte(&pte_p[n*PTE_STRIDE], pte);
24972
24973 /* Job is done for this CPU and any CPU which shares this page */
24974 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24975 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24976
24977 unlock_done:
24978 mutex_unlock(&espfix_init_mutex);
24979 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24980 index 3386dc9..28bdf81 100644
24981 --- a/arch/x86/kernel/ftrace.c
24982 +++ b/arch/x86/kernel/ftrace.c
24983 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24984 * kernel identity mapping to modify code.
24985 */
24986 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24987 - ip = (unsigned long)__va(__pa_symbol(ip));
24988 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24989
24990 return ip;
24991 }
24992 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24993 {
24994 unsigned char replaced[MCOUNT_INSN_SIZE];
24995
24996 + ip = ktla_ktva(ip);
24997 +
24998 /*
24999 * Note: Due to modules and __init, code can
25000 * disappear and change, we need to protect against faulting
25001 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
25002 unsigned char old[MCOUNT_INSN_SIZE];
25003 int ret;
25004
25005 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
25006 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
25007
25008 ftrace_update_func = ip;
25009 /* Make sure the breakpoints see the ftrace_update_func update */
25010 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
25011 unsigned char replaced[MCOUNT_INSN_SIZE];
25012 unsigned char brk = BREAKPOINT_INSTRUCTION;
25013
25014 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
25015 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
25016 return -EFAULT;
25017
25018 /* Make sure it is what we expect it to be */
25019 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
25020 index eda1a86..8f6df48 100644
25021 --- a/arch/x86/kernel/head64.c
25022 +++ b/arch/x86/kernel/head64.c
25023 @@ -67,12 +67,12 @@ again:
25024 pgd = *pgd_p;
25025
25026 /*
25027 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
25028 - * critical -- __PAGE_OFFSET would point us back into the dynamic
25029 + * The use of __early_va rather than __va here is critical:
25030 + * __va would point us back into the dynamic
25031 * range and we might end up looping forever...
25032 */
25033 if (pgd)
25034 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25035 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
25036 else {
25037 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25038 reset_early_page_tables();
25039 @@ -82,13 +82,13 @@ again:
25040 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
25041 for (i = 0; i < PTRS_PER_PUD; i++)
25042 pud_p[i] = 0;
25043 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25044 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
25045 }
25046 pud_p += pud_index(address);
25047 pud = *pud_p;
25048
25049 if (pud)
25050 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25051 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
25052 else {
25053 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25054 reset_early_page_tables();
25055 @@ -98,7 +98,7 @@ again:
25056 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
25057 for (i = 0; i < PTRS_PER_PMD; i++)
25058 pmd_p[i] = 0;
25059 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25060 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
25061 }
25062 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
25063 pmd_p[pmd_index(address)] = pmd;
25064 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
25065 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
25066 early_printk("Kernel alive\n");
25067
25068 - clear_page(init_level4_pgt);
25069 /* set init_level4_pgt kernel high mapping*/
25070 init_level4_pgt[511] = early_level4_pgt[511];
25071
25072 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
25073 index f36bd42..0ab4474 100644
25074 --- a/arch/x86/kernel/head_32.S
25075 +++ b/arch/x86/kernel/head_32.S
25076 @@ -26,6 +26,12 @@
25077 /* Physical address */
25078 #define pa(X) ((X) - __PAGE_OFFSET)
25079
25080 +#ifdef CONFIG_PAX_KERNEXEC
25081 +#define ta(X) (X)
25082 +#else
25083 +#define ta(X) ((X) - __PAGE_OFFSET)
25084 +#endif
25085 +
25086 /*
25087 * References to members of the new_cpu_data structure.
25088 */
25089 @@ -55,11 +61,7 @@
25090 * and small than max_low_pfn, otherwise will waste some page table entries
25091 */
25092
25093 -#if PTRS_PER_PMD > 1
25094 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
25095 -#else
25096 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
25097 -#endif
25098 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
25099
25100 /* Number of possible pages in the lowmem region */
25101 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
25102 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
25103 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25104
25105 /*
25106 + * Real beginning of normal "text" segment
25107 + */
25108 +ENTRY(stext)
25109 +ENTRY(_stext)
25110 +
25111 +/*
25112 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
25113 * %esi points to the real-mode code as a 32-bit pointer.
25114 * CS and DS must be 4 GB flat segments, but we don't depend on
25115 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25116 * can.
25117 */
25118 __HEAD
25119 +
25120 +#ifdef CONFIG_PAX_KERNEXEC
25121 + jmp startup_32
25122 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
25123 +.fill PAGE_SIZE-5,1,0xcc
25124 +#endif
25125 +
25126 ENTRY(startup_32)
25127 movl pa(stack_start),%ecx
25128
25129 @@ -106,6 +121,59 @@ ENTRY(startup_32)
25130 2:
25131 leal -__PAGE_OFFSET(%ecx),%esp
25132
25133 +#ifdef CONFIG_SMP
25134 + movl $pa(cpu_gdt_table),%edi
25135 + movl $__per_cpu_load,%eax
25136 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
25137 + rorl $16,%eax
25138 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
25139 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
25140 + movl $__per_cpu_end - 1,%eax
25141 + subl $__per_cpu_start,%eax
25142 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
25143 +#endif
25144 +
25145 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25146 + movl $NR_CPUS,%ecx
25147 + movl $pa(cpu_gdt_table),%edi
25148 +1:
25149 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
25150 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
25151 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
25152 + addl $PAGE_SIZE_asm,%edi
25153 + loop 1b
25154 +#endif
25155 +
25156 +#ifdef CONFIG_PAX_KERNEXEC
25157 + movl $pa(boot_gdt),%edi
25158 + movl $__LOAD_PHYSICAL_ADDR,%eax
25159 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
25160 + rorl $16,%eax
25161 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
25162 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
25163 + rorl $16,%eax
25164 +
25165 + ljmp $(__BOOT_CS),$1f
25166 +1:
25167 +
25168 + movl $NR_CPUS,%ecx
25169 + movl $pa(cpu_gdt_table),%edi
25170 + addl $__PAGE_OFFSET,%eax
25171 +1:
25172 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
25173 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
25174 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
25175 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
25176 + rorl $16,%eax
25177 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
25178 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
25179 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
25180 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
25181 + rorl $16,%eax
25182 + addl $PAGE_SIZE_asm,%edi
25183 + loop 1b
25184 +#endif
25185 +
25186 /*
25187 * Clear BSS first so that there are no surprises...
25188 */
25189 @@ -201,8 +269,11 @@ ENTRY(startup_32)
25190 movl %eax, pa(max_pfn_mapped)
25191
25192 /* Do early initialization of the fixmap area */
25193 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25194 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
25195 +#ifdef CONFIG_COMPAT_VDSO
25196 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
25197 +#else
25198 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
25199 +#endif
25200 #else /* Not PAE */
25201
25202 page_pde_offset = (__PAGE_OFFSET >> 20);
25203 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25204 movl %eax, pa(max_pfn_mapped)
25205
25206 /* Do early initialization of the fixmap area */
25207 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25208 - movl %eax,pa(initial_page_table+0xffc)
25209 +#ifdef CONFIG_COMPAT_VDSO
25210 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
25211 +#else
25212 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
25213 +#endif
25214 #endif
25215
25216 #ifdef CONFIG_PARAVIRT
25217 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25218 cmpl $num_subarch_entries, %eax
25219 jae bad_subarch
25220
25221 - movl pa(subarch_entries)(,%eax,4), %eax
25222 - subl $__PAGE_OFFSET, %eax
25223 - jmp *%eax
25224 + jmp *pa(subarch_entries)(,%eax,4)
25225
25226 bad_subarch:
25227 WEAK(lguest_entry)
25228 @@ -261,10 +333,10 @@ WEAK(xen_entry)
25229 __INITDATA
25230
25231 subarch_entries:
25232 - .long default_entry /* normal x86/PC */
25233 - .long lguest_entry /* lguest hypervisor */
25234 - .long xen_entry /* Xen hypervisor */
25235 - .long default_entry /* Moorestown MID */
25236 + .long ta(default_entry) /* normal x86/PC */
25237 + .long ta(lguest_entry) /* lguest hypervisor */
25238 + .long ta(xen_entry) /* Xen hypervisor */
25239 + .long ta(default_entry) /* Moorestown MID */
25240 num_subarch_entries = (. - subarch_entries) / 4
25241 .previous
25242 #else
25243 @@ -354,6 +426,7 @@ default_entry:
25244 movl pa(mmu_cr4_features),%eax
25245 movl %eax,%cr4
25246
25247 +#ifdef CONFIG_X86_PAE
25248 testb $X86_CR4_PAE, %al # check if PAE is enabled
25249 jz enable_paging
25250
25251 @@ -382,6 +455,9 @@ default_entry:
25252 /* Make changes effective */
25253 wrmsr
25254
25255 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
25256 +#endif
25257 +
25258 enable_paging:
25259
25260 /*
25261 @@ -449,14 +525,20 @@ is486:
25262 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
25263 movl %eax,%ss # after changing gdt.
25264
25265 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
25266 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
25267 movl %eax,%ds
25268 movl %eax,%es
25269
25270 movl $(__KERNEL_PERCPU), %eax
25271 movl %eax,%fs # set this cpu's percpu
25272
25273 +#ifdef CONFIG_CC_STACKPROTECTOR
25274 movl $(__KERNEL_STACK_CANARY),%eax
25275 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
25276 + movl $(__USER_DS),%eax
25277 +#else
25278 + xorl %eax,%eax
25279 +#endif
25280 movl %eax,%gs
25281
25282 xorl %eax,%eax # Clear LDT
25283 @@ -512,8 +594,11 @@ setup_once:
25284 * relocation. Manually set base address in stack canary
25285 * segment descriptor.
25286 */
25287 - movl $gdt_page,%eax
25288 + movl $cpu_gdt_table,%eax
25289 movl $stack_canary,%ecx
25290 +#ifdef CONFIG_SMP
25291 + addl $__per_cpu_load,%ecx
25292 +#endif
25293 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
25294 shrl $16, %ecx
25295 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
25296 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
25297 cmpl $2,(%esp) # X86_TRAP_NMI
25298 je is_nmi # Ignore NMI
25299
25300 - cmpl $2,%ss:early_recursion_flag
25301 + cmpl $1,%ss:early_recursion_flag
25302 je hlt_loop
25303 incl %ss:early_recursion_flag
25304
25305 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
25306 pushl (20+6*4)(%esp) /* trapno */
25307 pushl $fault_msg
25308 call printk
25309 -#endif
25310 call dump_stack
25311 +#endif
25312 hlt_loop:
25313 hlt
25314 jmp hlt_loop
25315 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
25316 /* This is the default interrupt "handler" :-) */
25317 ALIGN
25318 ignore_int:
25319 - cld
25320 #ifdef CONFIG_PRINTK
25321 + cmpl $2,%ss:early_recursion_flag
25322 + je hlt_loop
25323 + incl %ss:early_recursion_flag
25324 + cld
25325 pushl %eax
25326 pushl %ecx
25327 pushl %edx
25328 @@ -617,9 +705,6 @@ ignore_int:
25329 movl $(__KERNEL_DS),%eax
25330 movl %eax,%ds
25331 movl %eax,%es
25332 - cmpl $2,early_recursion_flag
25333 - je hlt_loop
25334 - incl early_recursion_flag
25335 pushl 16(%esp)
25336 pushl 24(%esp)
25337 pushl 32(%esp)
25338 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
25339 /*
25340 * BSS section
25341 */
25342 -__PAGE_ALIGNED_BSS
25343 - .align PAGE_SIZE
25344 #ifdef CONFIG_X86_PAE
25345 +.section .initial_pg_pmd,"a",@progbits
25346 initial_pg_pmd:
25347 .fill 1024*KPMDS,4,0
25348 #else
25349 +.section .initial_page_table,"a",@progbits
25350 ENTRY(initial_page_table)
25351 .fill 1024,4,0
25352 #endif
25353 +.section .initial_pg_fixmap,"a",@progbits
25354 initial_pg_fixmap:
25355 .fill 1024,4,0
25356 +.section .empty_zero_page,"a",@progbits
25357 ENTRY(empty_zero_page)
25358 .fill 4096,1,0
25359 +.section .swapper_pg_dir,"a",@progbits
25360 ENTRY(swapper_pg_dir)
25361 +#ifdef CONFIG_X86_PAE
25362 + .fill 4,8,0
25363 +#else
25364 .fill 1024,4,0
25365 +#endif
25366
25367 /*
25368 * This starts the data section.
25369 */
25370 #ifdef CONFIG_X86_PAE
25371 -__PAGE_ALIGNED_DATA
25372 - /* Page-aligned for the benefit of paravirt? */
25373 - .align PAGE_SIZE
25374 +.section .initial_page_table,"a",@progbits
25375 ENTRY(initial_page_table)
25376 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
25377 # if KPMDS == 3
25378 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
25379 # error "Kernel PMDs should be 1, 2 or 3"
25380 # endif
25381 .align PAGE_SIZE /* needs to be page-sized too */
25382 +
25383 +#ifdef CONFIG_PAX_PER_CPU_PGD
25384 +ENTRY(cpu_pgd)
25385 + .rept 2*NR_CPUS
25386 + .fill 4,8,0
25387 + .endr
25388 +#endif
25389 +
25390 #endif
25391
25392 .data
25393 .balign 4
25394 ENTRY(stack_start)
25395 - .long init_thread_union+THREAD_SIZE
25396 + .long init_thread_union+THREAD_SIZE-8
25397
25398 __INITRODATA
25399 int_msg:
25400 @@ -727,7 +825,7 @@ fault_msg:
25401 * segment size, and 32-bit linear address value:
25402 */
25403
25404 - .data
25405 +.section .rodata,"a",@progbits
25406 .globl boot_gdt_descr
25407 .globl idt_descr
25408
25409 @@ -736,7 +834,7 @@ fault_msg:
25410 .word 0 # 32 bit align gdt_desc.address
25411 boot_gdt_descr:
25412 .word __BOOT_DS+7
25413 - .long boot_gdt - __PAGE_OFFSET
25414 + .long pa(boot_gdt)
25415
25416 .word 0 # 32-bit align idt_desc.address
25417 idt_descr:
25418 @@ -747,7 +845,7 @@ idt_descr:
25419 .word 0 # 32 bit align gdt_desc.address
25420 ENTRY(early_gdt_descr)
25421 .word GDT_ENTRIES*8-1
25422 - .long gdt_page /* Overwritten for secondary CPUs */
25423 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
25424
25425 /*
25426 * The boot_gdt must mirror the equivalent in setup.S and is
25427 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
25428 .align L1_CACHE_BYTES
25429 ENTRY(boot_gdt)
25430 .fill GDT_ENTRY_BOOT_CS,8,0
25431 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
25432 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
25433 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
25434 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
25435 +
25436 + .align PAGE_SIZE_asm
25437 +ENTRY(cpu_gdt_table)
25438 + .rept NR_CPUS
25439 + .quad 0x0000000000000000 /* NULL descriptor */
25440 + .quad 0x0000000000000000 /* 0x0b reserved */
25441 + .quad 0x0000000000000000 /* 0x13 reserved */
25442 + .quad 0x0000000000000000 /* 0x1b reserved */
25443 +
25444 +#ifdef CONFIG_PAX_KERNEXEC
25445 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25446 +#else
25447 + .quad 0x0000000000000000 /* 0x20 unused */
25448 +#endif
25449 +
25450 + .quad 0x0000000000000000 /* 0x28 unused */
25451 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25452 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25453 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25454 + .quad 0x0000000000000000 /* 0x4b reserved */
25455 + .quad 0x0000000000000000 /* 0x53 reserved */
25456 + .quad 0x0000000000000000 /* 0x5b reserved */
25457 +
25458 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25459 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25460 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25461 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25462 +
25463 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25464 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25465 +
25466 + /*
25467 + * Segments used for calling PnP BIOS have byte granularity.
25468 + * The code segments and data segments have fixed 64k limits,
25469 + * the transfer segment sizes are set at run time.
25470 + */
25471 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
25472 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
25473 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
25474 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
25475 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
25476 +
25477 + /*
25478 + * The APM segments have byte granularity and their bases
25479 + * are set at run time. All have 64k limits.
25480 + */
25481 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25482 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25483 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
25484 +
25485 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25486 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25487 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25488 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25489 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25490 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25491 +
25492 + /* Be sure this is zeroed to avoid false validations in Xen */
25493 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25494 + .endr
25495 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25496 index a468c0a..8b5a879 100644
25497 --- a/arch/x86/kernel/head_64.S
25498 +++ b/arch/x86/kernel/head_64.S
25499 @@ -20,6 +20,8 @@
25500 #include <asm/processor-flags.h>
25501 #include <asm/percpu.h>
25502 #include <asm/nops.h>
25503 +#include <asm/cpufeature.h>
25504 +#include <asm/alternative-asm.h>
25505
25506 #ifdef CONFIG_PARAVIRT
25507 #include <asm/asm-offsets.h>
25508 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25509 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25510 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25511 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25512 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
25513 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25514 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25515 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25516 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25517 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25518
25519 .text
25520 __HEAD
25521 @@ -89,11 +97,24 @@ startup_64:
25522 * Fixup the physical addresses in the page table
25523 */
25524 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25525 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25526 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25527 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25528 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25529 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25530
25531 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25532 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25533 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25534 +#ifndef CONFIG_XEN
25535 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25536 +#endif
25537 +
25538 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25539 +
25540 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25541 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25542
25543 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25544 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25545
25546 /*
25547 * Set up the identity mapping for the switchover. These
25548 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25549 * after the boot processor executes this code.
25550 */
25551
25552 + orq $-1, %rbp
25553 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25554 1:
25555
25556 - /* Enable PAE mode and PGE */
25557 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25558 + /* Enable PAE mode and PSE/PGE */
25559 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25560 movq %rcx, %cr4
25561
25562 /* Setup early boot stage 4 level pagetables. */
25563 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25564 movl $MSR_EFER, %ecx
25565 rdmsr
25566 btsl $_EFER_SCE, %eax /* Enable System Call */
25567 - btl $20,%edi /* No Execute supported? */
25568 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25569 jnc 1f
25570 btsl $_EFER_NX, %eax
25571 + cmpq $-1, %rbp
25572 + je 1f
25573 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25574 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25575 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25576 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25577 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25578 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25579 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25580 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25581 1: wrmsr /* Make changes effective */
25582
25583 /* Setup cr0 */
25584 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25585 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25586 * address given in m16:64.
25587 */
25588 + pax_set_fptr_mask
25589 movq initial_code(%rip),%rax
25590 pushq $0 # fake return address to stop unwinder
25591 pushq $__KERNEL_CS # set correct cs
25592 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25593 .quad INIT_PER_CPU_VAR(irq_stack_union)
25594
25595 GLOBAL(stack_start)
25596 - .quad init_thread_union+THREAD_SIZE-8
25597 + .quad init_thread_union+THREAD_SIZE-16
25598 .word 0
25599 __FINITDATA
25600
25601 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25602 call dump_stack
25603 #ifdef CONFIG_KALLSYMS
25604 leaq early_idt_ripmsg(%rip),%rdi
25605 - movq 40(%rsp),%rsi # %rip again
25606 + movq 88(%rsp),%rsi # %rip again
25607 call __print_symbol
25608 #endif
25609 #endif /* EARLY_PRINTK */
25610 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25611 early_recursion_flag:
25612 .long 0
25613
25614 + .section .rodata,"a",@progbits
25615 #ifdef CONFIG_EARLY_PRINTK
25616 early_idt_msg:
25617 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25618 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25619 NEXT_PAGE(early_dynamic_pgts)
25620 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25621
25622 - .data
25623 + .section .rodata,"a",@progbits
25624
25625 -#ifndef CONFIG_XEN
25626 NEXT_PAGE(init_level4_pgt)
25627 - .fill 512,8,0
25628 -#else
25629 -NEXT_PAGE(init_level4_pgt)
25630 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25631 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25632 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25633 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25634 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25635 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25636 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25637 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25638 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25639 .org init_level4_pgt + L4_START_KERNEL*8, 0
25640 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25641 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25642
25643 +#ifdef CONFIG_PAX_PER_CPU_PGD
25644 +NEXT_PAGE(cpu_pgd)
25645 + .rept 2*NR_CPUS
25646 + .fill 512,8,0
25647 + .endr
25648 +#endif
25649 +
25650 NEXT_PAGE(level3_ident_pgt)
25651 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25652 +#ifdef CONFIG_XEN
25653 .fill 511, 8, 0
25654 +#else
25655 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25656 + .fill 510,8,0
25657 +#endif
25658 +
25659 +NEXT_PAGE(level3_vmalloc_start_pgt)
25660 + .fill 512,8,0
25661 +
25662 +NEXT_PAGE(level3_vmalloc_end_pgt)
25663 + .fill 512,8,0
25664 +
25665 +NEXT_PAGE(level3_vmemmap_pgt)
25666 + .fill L3_VMEMMAP_START,8,0
25667 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25668 +
25669 NEXT_PAGE(level2_ident_pgt)
25670 - /* Since I easily can, map the first 1G.
25671 + /* Since I easily can, map the first 2G.
25672 * Don't set NX because code runs from these pages.
25673 */
25674 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25675 -#endif
25676 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25677
25678 NEXT_PAGE(level3_kernel_pgt)
25679 .fill L3_START_KERNEL,8,0
25680 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25681 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25682 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25683
25684 +NEXT_PAGE(level2_vmemmap_pgt)
25685 + .fill 512,8,0
25686 +
25687 NEXT_PAGE(level2_kernel_pgt)
25688 /*
25689 * 512 MB kernel mapping. We spend a full page on this pagetable
25690 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25691 NEXT_PAGE(level2_fixmap_pgt)
25692 .fill 506,8,0
25693 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25694 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25695 - .fill 5,8,0
25696 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25697 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25698 + .fill 4,8,0
25699
25700 NEXT_PAGE(level1_fixmap_pgt)
25701 .fill 512,8,0
25702
25703 +NEXT_PAGE(level1_vsyscall_pgt)
25704 + .fill 512,8,0
25705 +
25706 #undef PMDS
25707
25708 - .data
25709 + .align PAGE_SIZE
25710 +ENTRY(cpu_gdt_table)
25711 + .rept NR_CPUS
25712 + .quad 0x0000000000000000 /* NULL descriptor */
25713 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25714 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25715 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25716 + .quad 0x00cffb000000ffff /* __USER32_CS */
25717 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25718 + .quad 0x00affb000000ffff /* __USER_CS */
25719 +
25720 +#ifdef CONFIG_PAX_KERNEXEC
25721 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25722 +#else
25723 + .quad 0x0 /* unused */
25724 +#endif
25725 +
25726 + .quad 0,0 /* TSS */
25727 + .quad 0,0 /* LDT */
25728 + .quad 0,0,0 /* three TLS descriptors */
25729 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25730 + /* asm/segment.h:GDT_ENTRIES must match this */
25731 +
25732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25733 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25734 +#else
25735 + .quad 0x0 /* unused */
25736 +#endif
25737 +
25738 + /* zero the remaining page */
25739 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25740 + .endr
25741 +
25742 .align 16
25743 .globl early_gdt_descr
25744 early_gdt_descr:
25745 .word GDT_ENTRIES*8-1
25746 early_gdt_descr_base:
25747 - .quad INIT_PER_CPU_VAR(gdt_page)
25748 + .quad cpu_gdt_table
25749
25750 ENTRY(phys_base)
25751 /* This must match the first entry in level2_kernel_pgt */
25752 .quad 0x0000000000000000
25753
25754 #include "../../x86/xen/xen-head.S"
25755 -
25756 - __PAGE_ALIGNED_BSS
25757 +
25758 + .section .rodata,"a",@progbits
25759 NEXT_PAGE(empty_zero_page)
25760 .skip PAGE_SIZE
25761 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25762 index 05fd74f..c3548b1 100644
25763 --- a/arch/x86/kernel/i386_ksyms_32.c
25764 +++ b/arch/x86/kernel/i386_ksyms_32.c
25765 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25766 EXPORT_SYMBOL(cmpxchg8b_emu);
25767 #endif
25768
25769 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25770 +
25771 /* Networking helper routines. */
25772 EXPORT_SYMBOL(csum_partial_copy_generic);
25773 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25774 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25775
25776 EXPORT_SYMBOL(__get_user_1);
25777 EXPORT_SYMBOL(__get_user_2);
25778 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25779 EXPORT_SYMBOL(___preempt_schedule_context);
25780 #endif
25781 #endif
25782 +
25783 +#ifdef CONFIG_PAX_KERNEXEC
25784 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25785 +#endif
25786 +
25787 +#ifdef CONFIG_PAX_PER_CPU_PGD
25788 +EXPORT_SYMBOL(cpu_pgd);
25789 +#endif
25790 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25791 index a9a4229..6f4d476 100644
25792 --- a/arch/x86/kernel/i387.c
25793 +++ b/arch/x86/kernel/i387.c
25794 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25795 static inline bool interrupted_user_mode(void)
25796 {
25797 struct pt_regs *regs = get_irq_regs();
25798 - return regs && user_mode_vm(regs);
25799 + return regs && user_mode(regs);
25800 }
25801
25802 /*
25803 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25804 index 8af8171..f8c1169 100644
25805 --- a/arch/x86/kernel/i8259.c
25806 +++ b/arch/x86/kernel/i8259.c
25807 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25808 static void make_8259A_irq(unsigned int irq)
25809 {
25810 disable_irq_nosync(irq);
25811 - io_apic_irqs &= ~(1<<irq);
25812 + io_apic_irqs &= ~(1UL<<irq);
25813 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25814 i8259A_chip.name);
25815 enable_irq(irq);
25816 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25817 "spurious 8259A interrupt: IRQ%d.\n", irq);
25818 spurious_irq_mask |= irqmask;
25819 }
25820 - atomic_inc(&irq_err_count);
25821 + atomic_inc_unchecked(&irq_err_count);
25822 /*
25823 * Theoretically we do not have to handle this IRQ,
25824 * but in Linux this does not cause problems and is
25825 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25826 /* (slave's support for AEOI in flat mode is to be investigated) */
25827 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25828
25829 + pax_open_kernel();
25830 if (auto_eoi)
25831 /*
25832 * In AEOI mode we just have to mask the interrupt
25833 * when acking.
25834 */
25835 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25836 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25837 else
25838 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25839 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25840 + pax_close_kernel();
25841
25842 udelay(100); /* wait for 8259A to initialize */
25843
25844 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25845 index a979b5b..1d6db75 100644
25846 --- a/arch/x86/kernel/io_delay.c
25847 +++ b/arch/x86/kernel/io_delay.c
25848 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25849 * Quirk table for systems that misbehave (lock up, etc.) if port
25850 * 0x80 is used:
25851 */
25852 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25853 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25854 {
25855 .callback = dmi_io_delay_0xed_port,
25856 .ident = "Compaq Presario V6000",
25857 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25858 index 4ddaf66..49d5c18 100644
25859 --- a/arch/x86/kernel/ioport.c
25860 +++ b/arch/x86/kernel/ioport.c
25861 @@ -6,6 +6,7 @@
25862 #include <linux/sched.h>
25863 #include <linux/kernel.h>
25864 #include <linux/capability.h>
25865 +#include <linux/security.h>
25866 #include <linux/errno.h>
25867 #include <linux/types.h>
25868 #include <linux/ioport.h>
25869 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25870 return -EINVAL;
25871 if (turn_on && !capable(CAP_SYS_RAWIO))
25872 return -EPERM;
25873 +#ifdef CONFIG_GRKERNSEC_IO
25874 + if (turn_on && grsec_disable_privio) {
25875 + gr_handle_ioperm();
25876 + return -ENODEV;
25877 + }
25878 +#endif
25879
25880 /*
25881 * If it's the first ioperm() call in this thread's lifetime, set the
25882 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25883 * because the ->io_bitmap_max value must match the bitmap
25884 * contents:
25885 */
25886 - tss = &per_cpu(init_tss, get_cpu());
25887 + tss = init_tss + get_cpu();
25888
25889 if (turn_on)
25890 bitmap_clear(t->io_bitmap_ptr, from, num);
25891 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25892 if (level > old) {
25893 if (!capable(CAP_SYS_RAWIO))
25894 return -EPERM;
25895 +#ifdef CONFIG_GRKERNSEC_IO
25896 + if (grsec_disable_privio) {
25897 + gr_handle_iopl();
25898 + return -ENODEV;
25899 + }
25900 +#endif
25901 }
25902 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25903 t->iopl = level << 12;
25904 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25905 index 922d285..6d20692 100644
25906 --- a/arch/x86/kernel/irq.c
25907 +++ b/arch/x86/kernel/irq.c
25908 @@ -22,7 +22,7 @@
25909 #define CREATE_TRACE_POINTS
25910 #include <asm/trace/irq_vectors.h>
25911
25912 -atomic_t irq_err_count;
25913 +atomic_unchecked_t irq_err_count;
25914
25915 /* Function pointer for generic interrupt vector handling */
25916 void (*x86_platform_ipi_callback)(void) = NULL;
25917 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25918 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25919 seq_printf(p, " Hypervisor callback interrupts\n");
25920 #endif
25921 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25922 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25923 #if defined(CONFIG_X86_IO_APIC)
25924 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25925 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25926 #endif
25927 return 0;
25928 }
25929 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25930
25931 u64 arch_irq_stat(void)
25932 {
25933 - u64 sum = atomic_read(&irq_err_count);
25934 + u64 sum = atomic_read_unchecked(&irq_err_count);
25935 return sum;
25936 }
25937
25938 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25939 index 63ce838..2ea3e06 100644
25940 --- a/arch/x86/kernel/irq_32.c
25941 +++ b/arch/x86/kernel/irq_32.c
25942 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25943
25944 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25945
25946 +extern void gr_handle_kernel_exploit(void);
25947 +
25948 int sysctl_panic_on_stackoverflow __read_mostly;
25949
25950 /* Debugging check for stack overflow: is there less than 1KB free? */
25951 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25952 __asm__ __volatile__("andl %%esp,%0" :
25953 "=r" (sp) : "0" (THREAD_SIZE - 1));
25954
25955 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25956 + return sp < STACK_WARN;
25957 }
25958
25959 static void print_stack_overflow(void)
25960 {
25961 printk(KERN_WARNING "low stack detected by irq handler\n");
25962 dump_stack();
25963 + gr_handle_kernel_exploit();
25964 if (sysctl_panic_on_stackoverflow)
25965 panic("low stack detected by irq handler - check messages\n");
25966 }
25967 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25968 static inline int
25969 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25970 {
25971 - struct irq_stack *curstk, *irqstk;
25972 + struct irq_stack *irqstk;
25973 u32 *isp, *prev_esp, arg1, arg2;
25974
25975 - curstk = (struct irq_stack *) current_stack();
25976 irqstk = __this_cpu_read(hardirq_stack);
25977
25978 /*
25979 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25980 * handler) we can't do that and just have to keep using the
25981 * current stack (which is the irq stack already after all)
25982 */
25983 - if (unlikely(curstk == irqstk))
25984 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25985 return 0;
25986
25987 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25988 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25989
25990 /* Save the next esp at the bottom of the stack */
25991 prev_esp = (u32 *)irqstk;
25992 *prev_esp = current_stack_pointer;
25993
25994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25995 + __set_fs(MAKE_MM_SEG(0));
25996 +#endif
25997 +
25998 if (unlikely(overflow))
25999 call_on_stack(print_stack_overflow, isp);
26000
26001 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26002 : "0" (irq), "1" (desc), "2" (isp),
26003 "D" (desc->handle_irq)
26004 : "memory", "cc", "ecx");
26005 +
26006 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26007 + __set_fs(current_thread_info()->addr_limit);
26008 +#endif
26009 +
26010 return 1;
26011 }
26012
26013 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26014 */
26015 void irq_ctx_init(int cpu)
26016 {
26017 - struct irq_stack *irqstk;
26018 -
26019 if (per_cpu(hardirq_stack, cpu))
26020 return;
26021
26022 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26023 - THREADINFO_GFP,
26024 - THREAD_SIZE_ORDER));
26025 - per_cpu(hardirq_stack, cpu) = irqstk;
26026 -
26027 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26028 - THREADINFO_GFP,
26029 - THREAD_SIZE_ORDER));
26030 - per_cpu(softirq_stack, cpu) = irqstk;
26031 -
26032 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
26033 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
26034 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26035 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26036 }
26037
26038 void do_softirq_own_stack(void)
26039 {
26040 - struct thread_info *curstk;
26041 struct irq_stack *irqstk;
26042 u32 *isp, *prev_esp;
26043
26044 - curstk = current_stack();
26045 irqstk = __this_cpu_read(softirq_stack);
26046
26047 /* build the stack frame on the softirq stack */
26048 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
26049 prev_esp = (u32 *)irqstk;
26050 *prev_esp = current_stack_pointer;
26051
26052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26053 + __set_fs(MAKE_MM_SEG(0));
26054 +#endif
26055 +
26056 call_on_stack(__do_softirq, isp);
26057 +
26058 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26059 + __set_fs(current_thread_info()->addr_limit);
26060 +#endif
26061 +
26062 }
26063
26064 bool handle_irq(unsigned irq, struct pt_regs *regs)
26065 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
26066 if (unlikely(!desc))
26067 return false;
26068
26069 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26070 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26071 if (unlikely(overflow))
26072 print_stack_overflow();
26073 desc->handle_irq(irq, desc);
26074 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
26075 index 4d1c746..55a22d6 100644
26076 --- a/arch/x86/kernel/irq_64.c
26077 +++ b/arch/x86/kernel/irq_64.c
26078 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
26079 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26080 EXPORT_PER_CPU_SYMBOL(irq_regs);
26081
26082 +extern void gr_handle_kernel_exploit(void);
26083 +
26084 int sysctl_panic_on_stackoverflow;
26085
26086 /*
26087 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26088 u64 estack_top, estack_bottom;
26089 u64 curbase = (u64)task_stack_page(current);
26090
26091 - if (user_mode_vm(regs))
26092 + if (user_mode(regs))
26093 return;
26094
26095 if (regs->sp >= curbase + sizeof(struct thread_info) +
26096 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26097 irq_stack_top, irq_stack_bottom,
26098 estack_top, estack_bottom);
26099
26100 + gr_handle_kernel_exploit();
26101 +
26102 if (sysctl_panic_on_stackoverflow)
26103 panic("low stack detected by irq handler - check messages\n");
26104 #endif
26105 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
26106 index 26d5a55..a01160a 100644
26107 --- a/arch/x86/kernel/jump_label.c
26108 +++ b/arch/x86/kernel/jump_label.c
26109 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26110 * Jump label is enabled for the first time.
26111 * So we expect a default_nop...
26112 */
26113 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
26114 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
26115 != 0))
26116 bug_at((void *)entry->code, __LINE__);
26117 } else {
26118 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26119 * ...otherwise expect an ideal_nop. Otherwise
26120 * something went horribly wrong.
26121 */
26122 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
26123 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
26124 != 0))
26125 bug_at((void *)entry->code, __LINE__);
26126 }
26127 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
26128 * are converting the default nop to the ideal nop.
26129 */
26130 if (init) {
26131 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
26132 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
26133 bug_at((void *)entry->code, __LINE__);
26134 } else {
26135 code.jump = 0xe9;
26136 code.offset = entry->target -
26137 (entry->code + JUMP_LABEL_NOP_SIZE);
26138 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
26139 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
26140 bug_at((void *)entry->code, __LINE__);
26141 }
26142 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
26143 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
26144 index 7ec1d5f..5a7d130 100644
26145 --- a/arch/x86/kernel/kgdb.c
26146 +++ b/arch/x86/kernel/kgdb.c
26147 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
26148 #ifdef CONFIG_X86_32
26149 switch (regno) {
26150 case GDB_SS:
26151 - if (!user_mode_vm(regs))
26152 + if (!user_mode(regs))
26153 *(unsigned long *)mem = __KERNEL_DS;
26154 break;
26155 case GDB_SP:
26156 - if (!user_mode_vm(regs))
26157 + if (!user_mode(regs))
26158 *(unsigned long *)mem = kernel_stack_pointer(regs);
26159 break;
26160 case GDB_GS:
26161 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
26162 bp->attr.bp_addr = breakinfo[breakno].addr;
26163 bp->attr.bp_len = breakinfo[breakno].len;
26164 bp->attr.bp_type = breakinfo[breakno].type;
26165 - info->address = breakinfo[breakno].addr;
26166 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
26167 + info->address = ktla_ktva(breakinfo[breakno].addr);
26168 + else
26169 + info->address = breakinfo[breakno].addr;
26170 info->len = breakinfo[breakno].len;
26171 info->type = breakinfo[breakno].type;
26172 val = arch_install_hw_breakpoint(bp);
26173 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
26174 case 'k':
26175 /* clear the trace bit */
26176 linux_regs->flags &= ~X86_EFLAGS_TF;
26177 - atomic_set(&kgdb_cpu_doing_single_step, -1);
26178 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
26179
26180 /* set the trace bit if we're stepping */
26181 if (remcomInBuffer[0] == 's') {
26182 linux_regs->flags |= X86_EFLAGS_TF;
26183 - atomic_set(&kgdb_cpu_doing_single_step,
26184 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
26185 raw_smp_processor_id());
26186 }
26187
26188 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
26189
26190 switch (cmd) {
26191 case DIE_DEBUG:
26192 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
26193 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
26194 if (user_mode(regs))
26195 return single_step_cont(regs, args);
26196 break;
26197 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26198 #endif /* CONFIG_DEBUG_RODATA */
26199
26200 bpt->type = BP_BREAKPOINT;
26201 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
26202 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
26203 BREAK_INSTR_SIZE);
26204 if (err)
26205 return err;
26206 - err = probe_kernel_write((char *)bpt->bpt_addr,
26207 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26208 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
26209 #ifdef CONFIG_DEBUG_RODATA
26210 if (!err)
26211 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26212 return -EBUSY;
26213 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
26214 BREAK_INSTR_SIZE);
26215 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26216 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26217 if (err)
26218 return err;
26219 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
26220 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
26221 if (mutex_is_locked(&text_mutex))
26222 goto knl_write;
26223 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
26224 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26225 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26226 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
26227 goto knl_write;
26228 return err;
26229 knl_write:
26230 #endif /* CONFIG_DEBUG_RODATA */
26231 - return probe_kernel_write((char *)bpt->bpt_addr,
26232 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26233 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
26234 }
26235
26236 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
26237 index 67e6d19..731ed28 100644
26238 --- a/arch/x86/kernel/kprobes/core.c
26239 +++ b/arch/x86/kernel/kprobes/core.c
26240 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
26241 s32 raddr;
26242 } __packed *insn;
26243
26244 - insn = (struct __arch_relative_insn *)from;
26245 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
26246 +
26247 + pax_open_kernel();
26248 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
26249 insn->op = op;
26250 + pax_close_kernel();
26251 }
26252
26253 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
26254 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
26255 kprobe_opcode_t opcode;
26256 kprobe_opcode_t *orig_opcodes = opcodes;
26257
26258 - if (search_exception_tables((unsigned long)opcodes))
26259 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
26260 return 0; /* Page fault may occur on this address. */
26261
26262 retry:
26263 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
26264 * for the first byte, we can recover the original instruction
26265 * from it and kp->opcode.
26266 */
26267 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26268 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26269 buf[0] = kp->opcode;
26270 - return (unsigned long)buf;
26271 + return ktva_ktla((unsigned long)buf);
26272 }
26273
26274 /*
26275 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26276 /* Another subsystem puts a breakpoint, failed to recover */
26277 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
26278 return 0;
26279 + pax_open_kernel();
26280 memcpy(dest, insn.kaddr, insn.length);
26281 + pax_close_kernel();
26282
26283 #ifdef CONFIG_X86_64
26284 if (insn_rip_relative(&insn)) {
26285 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26286 return 0;
26287 }
26288 disp = (u8 *) dest + insn_offset_displacement(&insn);
26289 + pax_open_kernel();
26290 *(s32 *) disp = (s32) newdisp;
26291 + pax_close_kernel();
26292 }
26293 #endif
26294 return insn.length;
26295 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26296 * nor set current_kprobe, because it doesn't use single
26297 * stepping.
26298 */
26299 - regs->ip = (unsigned long)p->ainsn.insn;
26300 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26301 preempt_enable_no_resched();
26302 return;
26303 }
26304 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26305 regs->flags &= ~X86_EFLAGS_IF;
26306 /* single step inline if the instruction is an int3 */
26307 if (p->opcode == BREAKPOINT_INSTRUCTION)
26308 - regs->ip = (unsigned long)p->addr;
26309 + regs->ip = ktla_ktva((unsigned long)p->addr);
26310 else
26311 - regs->ip = (unsigned long)p->ainsn.insn;
26312 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26313 }
26314 NOKPROBE_SYMBOL(setup_singlestep);
26315
26316 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26317 struct kprobe *p;
26318 struct kprobe_ctlblk *kcb;
26319
26320 - if (user_mode_vm(regs))
26321 + if (user_mode(regs))
26322 return 0;
26323
26324 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
26325 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26326 setup_singlestep(p, regs, kcb, 0);
26327 return 1;
26328 }
26329 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
26330 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
26331 /*
26332 * The breakpoint instruction was removed right
26333 * after we hit it. Another cpu has removed
26334 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
26335 " movq %rax, 152(%rsp)\n"
26336 RESTORE_REGS_STRING
26337 " popfq\n"
26338 +#ifdef KERNEXEC_PLUGIN
26339 + " btsq $63,(%rsp)\n"
26340 +#endif
26341 #else
26342 " pushf\n"
26343 SAVE_REGS_STRING
26344 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
26345 struct kprobe_ctlblk *kcb)
26346 {
26347 unsigned long *tos = stack_addr(regs);
26348 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
26349 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
26350 unsigned long orig_ip = (unsigned long)p->addr;
26351 kprobe_opcode_t *insn = p->ainsn.insn;
26352
26353 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
26354 struct die_args *args = data;
26355 int ret = NOTIFY_DONE;
26356
26357 - if (args->regs && user_mode_vm(args->regs))
26358 + if (args->regs && user_mode(args->regs))
26359 return ret;
26360
26361 if (val == DIE_GPF) {
26362 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
26363 index f1314d0..15f3154 100644
26364 --- a/arch/x86/kernel/kprobes/opt.c
26365 +++ b/arch/x86/kernel/kprobes/opt.c
26366 @@ -79,6 +79,7 @@ found:
26367 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
26368 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26369 {
26370 + pax_open_kernel();
26371 #ifdef CONFIG_X86_64
26372 *addr++ = 0x48;
26373 *addr++ = 0xbf;
26374 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26375 *addr++ = 0xb8;
26376 #endif
26377 *(unsigned long *)addr = val;
26378 + pax_close_kernel();
26379 }
26380
26381 asm (
26382 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26383 * Verify if the address gap is in 2GB range, because this uses
26384 * a relative jump.
26385 */
26386 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
26387 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
26388 if (abs(rel) > 0x7fffffff) {
26389 __arch_remove_optimized_kprobe(op, 0);
26390 return -ERANGE;
26391 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26392 op->optinsn.size = ret;
26393
26394 /* Copy arch-dep-instance from template */
26395 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
26396 + pax_open_kernel();
26397 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
26398 + pax_close_kernel();
26399
26400 /* Set probe information */
26401 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
26402
26403 /* Set probe function call */
26404 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
26405 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
26406
26407 /* Set returning jmp instruction at the tail of out-of-line buffer */
26408 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
26409 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
26410 (u8 *)op->kp.addr + op->optinsn.size);
26411
26412 flush_icache_range((unsigned long) buf,
26413 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
26414 WARN_ON(kprobe_disabled(&op->kp));
26415
26416 /* Backup instructions which will be replaced by jump address */
26417 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
26418 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
26419 RELATIVE_ADDR_SIZE);
26420
26421 insn_buf[0] = RELATIVEJUMP_OPCODE;
26422 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
26423 /* This kprobe is really able to run optimized path. */
26424 op = container_of(p, struct optimized_kprobe, kp);
26425 /* Detour through copied instructions */
26426 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
26427 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
26428 if (!reenter)
26429 reset_current_kprobe();
26430 preempt_enable_no_resched();
26431 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
26432 index c2bedae..25e7ab60 100644
26433 --- a/arch/x86/kernel/ksysfs.c
26434 +++ b/arch/x86/kernel/ksysfs.c
26435 @@ -184,7 +184,7 @@ out:
26436
26437 static struct kobj_attribute type_attr = __ATTR_RO(type);
26438
26439 -static struct bin_attribute data_attr = {
26440 +static bin_attribute_no_const data_attr __read_only = {
26441 .attr = {
26442 .name = "data",
26443 .mode = S_IRUGO,
26444 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26445 index c37886d..d851d32 100644
26446 --- a/arch/x86/kernel/ldt.c
26447 +++ b/arch/x86/kernel/ldt.c
26448 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26449 if (reload) {
26450 #ifdef CONFIG_SMP
26451 preempt_disable();
26452 - load_LDT(pc);
26453 + load_LDT_nolock(pc);
26454 if (!cpumask_equal(mm_cpumask(current->mm),
26455 cpumask_of(smp_processor_id())))
26456 smp_call_function(flush_ldt, current->mm, 1);
26457 preempt_enable();
26458 #else
26459 - load_LDT(pc);
26460 + load_LDT_nolock(pc);
26461 #endif
26462 }
26463 if (oldsize) {
26464 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26465 return err;
26466
26467 for (i = 0; i < old->size; i++)
26468 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26469 + write_ldt_entry(new->ldt, i, old->ldt + i);
26470 return 0;
26471 }
26472
26473 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26474 retval = copy_ldt(&mm->context, &old_mm->context);
26475 mutex_unlock(&old_mm->context.lock);
26476 }
26477 +
26478 + if (tsk == current) {
26479 + mm->context.vdso = 0;
26480 +
26481 +#ifdef CONFIG_X86_32
26482 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26483 + mm->context.user_cs_base = 0UL;
26484 + mm->context.user_cs_limit = ~0UL;
26485 +
26486 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26487 + cpus_clear(mm->context.cpu_user_cs_mask);
26488 +#endif
26489 +
26490 +#endif
26491 +#endif
26492 +
26493 + }
26494 +
26495 return retval;
26496 }
26497
26498 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26499 }
26500 }
26501
26502 +#ifdef CONFIG_PAX_SEGMEXEC
26503 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26504 + error = -EINVAL;
26505 + goto out_unlock;
26506 + }
26507 +#endif
26508 +
26509 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26510 error = -EINVAL;
26511 goto out_unlock;
26512 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26513 index 1667b1d..16492c5 100644
26514 --- a/arch/x86/kernel/machine_kexec_32.c
26515 +++ b/arch/x86/kernel/machine_kexec_32.c
26516 @@ -25,7 +25,7 @@
26517 #include <asm/cacheflush.h>
26518 #include <asm/debugreg.h>
26519
26520 -static void set_idt(void *newidt, __u16 limit)
26521 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26522 {
26523 struct desc_ptr curidt;
26524
26525 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26526 }
26527
26528
26529 -static void set_gdt(void *newgdt, __u16 limit)
26530 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26531 {
26532 struct desc_ptr curgdt;
26533
26534 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26535 }
26536
26537 control_page = page_address(image->control_code_page);
26538 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26539 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26540
26541 relocate_kernel_ptr = control_page;
26542 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26543 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26544 index c73aecf..4c63630 100644
26545 --- a/arch/x86/kernel/mcount_64.S
26546 +++ b/arch/x86/kernel/mcount_64.S
26547 @@ -7,7 +7,7 @@
26548 #include <linux/linkage.h>
26549 #include <asm/ptrace.h>
26550 #include <asm/ftrace.h>
26551 -
26552 +#include <asm/alternative-asm.h>
26553
26554 .code64
26555 .section .entry.text, "ax"
26556 @@ -24,8 +24,9 @@
26557 #ifdef CONFIG_DYNAMIC_FTRACE
26558
26559 ENTRY(function_hook)
26560 + pax_force_retaddr
26561 retq
26562 -END(function_hook)
26563 +ENDPROC(function_hook)
26564
26565 /* skip is set if stack has been adjusted */
26566 .macro ftrace_caller_setup skip=0
26567 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26568 #endif
26569
26570 GLOBAL(ftrace_stub)
26571 + pax_force_retaddr
26572 retq
26573 -END(ftrace_caller)
26574 +ENDPROC(ftrace_caller)
26575
26576 ENTRY(ftrace_regs_caller)
26577 /* Save the current flags before compare (in SS location)*/
26578 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26579 popfq
26580 jmp ftrace_stub
26581
26582 -END(ftrace_regs_caller)
26583 +ENDPROC(ftrace_regs_caller)
26584
26585
26586 #else /* ! CONFIG_DYNAMIC_FTRACE */
26587 @@ -145,6 +147,7 @@ ENTRY(function_hook)
26588 #endif
26589
26590 GLOBAL(ftrace_stub)
26591 + pax_force_retaddr
26592 retq
26593
26594 trace:
26595 @@ -158,12 +161,13 @@ trace:
26596 #endif
26597 subq $MCOUNT_INSN_SIZE, %rdi
26598
26599 + pax_force_fptr ftrace_trace_function
26600 call *ftrace_trace_function
26601
26602 MCOUNT_RESTORE_FRAME
26603
26604 jmp ftrace_stub
26605 -END(function_hook)
26606 +ENDPROC(function_hook)
26607 #endif /* CONFIG_DYNAMIC_FTRACE */
26608 #endif /* CONFIG_FUNCTION_TRACER */
26609
26610 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26611
26612 MCOUNT_RESTORE_FRAME
26613
26614 + pax_force_retaddr
26615 retq
26616 -END(ftrace_graph_caller)
26617 +ENDPROC(ftrace_graph_caller)
26618
26619 GLOBAL(return_to_handler)
26620 subq $24, %rsp
26621 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26622 movq 8(%rsp), %rdx
26623 movq (%rsp), %rax
26624 addq $24, %rsp
26625 + pax_force_fptr %rdi
26626 jmp *%rdi
26627 +ENDPROC(return_to_handler)
26628 #endif
26629 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26630 index e69f988..da078ea 100644
26631 --- a/arch/x86/kernel/module.c
26632 +++ b/arch/x86/kernel/module.c
26633 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26634 }
26635 #endif
26636
26637 -void *module_alloc(unsigned long size)
26638 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26639 {
26640 - if (PAGE_ALIGN(size) > MODULES_LEN)
26641 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26642 return NULL;
26643 return __vmalloc_node_range(size, 1,
26644 MODULES_VADDR + get_module_load_offset(),
26645 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26646 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26647 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26648 + prot, NUMA_NO_NODE,
26649 __builtin_return_address(0));
26650 }
26651
26652 +void *module_alloc(unsigned long size)
26653 +{
26654 +
26655 +#ifdef CONFIG_PAX_KERNEXEC
26656 + return __module_alloc(size, PAGE_KERNEL);
26657 +#else
26658 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26659 +#endif
26660 +
26661 +}
26662 +
26663 +#ifdef CONFIG_PAX_KERNEXEC
26664 +#ifdef CONFIG_X86_32
26665 +void *module_alloc_exec(unsigned long size)
26666 +{
26667 + struct vm_struct *area;
26668 +
26669 + if (size == 0)
26670 + return NULL;
26671 +
26672 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26673 +return area ? area->addr : NULL;
26674 +}
26675 +EXPORT_SYMBOL(module_alloc_exec);
26676 +
26677 +void module_free_exec(struct module *mod, void *module_region)
26678 +{
26679 + vunmap(module_region);
26680 +}
26681 +EXPORT_SYMBOL(module_free_exec);
26682 +#else
26683 +void module_free_exec(struct module *mod, void *module_region)
26684 +{
26685 + module_free(mod, module_region);
26686 +}
26687 +EXPORT_SYMBOL(module_free_exec);
26688 +
26689 +void *module_alloc_exec(unsigned long size)
26690 +{
26691 + return __module_alloc(size, PAGE_KERNEL_RX);
26692 +}
26693 +EXPORT_SYMBOL(module_alloc_exec);
26694 +#endif
26695 +#endif
26696 +
26697 #ifdef CONFIG_X86_32
26698 int apply_relocate(Elf32_Shdr *sechdrs,
26699 const char *strtab,
26700 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26701 unsigned int i;
26702 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26703 Elf32_Sym *sym;
26704 - uint32_t *location;
26705 + uint32_t *plocation, location;
26706
26707 DEBUGP("Applying relocate section %u to %u\n",
26708 relsec, sechdrs[relsec].sh_info);
26709 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26710 /* This is where to make the change */
26711 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26712 - + rel[i].r_offset;
26713 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26714 + location = (uint32_t)plocation;
26715 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26716 + plocation = ktla_ktva((void *)plocation);
26717 /* This is the symbol it is referring to. Note that all
26718 undefined symbols have been resolved. */
26719 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26720 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26721 switch (ELF32_R_TYPE(rel[i].r_info)) {
26722 case R_386_32:
26723 /* We add the value into the location given */
26724 - *location += sym->st_value;
26725 + pax_open_kernel();
26726 + *plocation += sym->st_value;
26727 + pax_close_kernel();
26728 break;
26729 case R_386_PC32:
26730 /* Add the value, subtract its position */
26731 - *location += sym->st_value - (uint32_t)location;
26732 + pax_open_kernel();
26733 + *plocation += sym->st_value - location;
26734 + pax_close_kernel();
26735 break;
26736 default:
26737 pr_err("%s: Unknown relocation: %u\n",
26738 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26739 case R_X86_64_NONE:
26740 break;
26741 case R_X86_64_64:
26742 + pax_open_kernel();
26743 *(u64 *)loc = val;
26744 + pax_close_kernel();
26745 break;
26746 case R_X86_64_32:
26747 + pax_open_kernel();
26748 *(u32 *)loc = val;
26749 + pax_close_kernel();
26750 if (val != *(u32 *)loc)
26751 goto overflow;
26752 break;
26753 case R_X86_64_32S:
26754 + pax_open_kernel();
26755 *(s32 *)loc = val;
26756 + pax_close_kernel();
26757 if ((s64)val != *(s32 *)loc)
26758 goto overflow;
26759 break;
26760 case R_X86_64_PC32:
26761 val -= (u64)loc;
26762 + pax_open_kernel();
26763 *(u32 *)loc = val;
26764 + pax_close_kernel();
26765 +
26766 #if 0
26767 if ((s64)val != *(s32 *)loc)
26768 goto overflow;
26769 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26770 index c9603ac..9f88728 100644
26771 --- a/arch/x86/kernel/msr.c
26772 +++ b/arch/x86/kernel/msr.c
26773 @@ -37,6 +37,7 @@
26774 #include <linux/notifier.h>
26775 #include <linux/uaccess.h>
26776 #include <linux/gfp.h>
26777 +#include <linux/grsecurity.h>
26778
26779 #include <asm/processor.h>
26780 #include <asm/msr.h>
26781 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26782 int err = 0;
26783 ssize_t bytes = 0;
26784
26785 +#ifdef CONFIG_GRKERNSEC_KMEM
26786 + gr_handle_msr_write();
26787 + return -EPERM;
26788 +#endif
26789 +
26790 if (count % 8)
26791 return -EINVAL; /* Invalid chunk size */
26792
26793 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26794 err = -EBADF;
26795 break;
26796 }
26797 +#ifdef CONFIG_GRKERNSEC_KMEM
26798 + gr_handle_msr_write();
26799 + return -EPERM;
26800 +#endif
26801 if (copy_from_user(&regs, uregs, sizeof regs)) {
26802 err = -EFAULT;
26803 break;
26804 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26805 return notifier_from_errno(err);
26806 }
26807
26808 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26809 +static struct notifier_block msr_class_cpu_notifier = {
26810 .notifier_call = msr_class_cpu_callback,
26811 };
26812
26813 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26814 index c3e985d..110a36a 100644
26815 --- a/arch/x86/kernel/nmi.c
26816 +++ b/arch/x86/kernel/nmi.c
26817 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26818
26819 static void nmi_max_handler(struct irq_work *w)
26820 {
26821 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26822 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26823 int remainder_ns, decimal_msecs;
26824 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26825 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26826
26827 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26828 decimal_msecs = remainder_ns / 1000;
26829
26830 printk_ratelimited(KERN_INFO
26831 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26832 - a->handler, whole_msecs, decimal_msecs);
26833 + n->action->handler, whole_msecs, decimal_msecs);
26834 }
26835
26836 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26837 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26838 delta = sched_clock() - delta;
26839 trace_nmi_handler(a->handler, (int)delta, thishandled);
26840
26841 - if (delta < nmi_longest_ns || delta < a->max_duration)
26842 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26843 continue;
26844
26845 - a->max_duration = delta;
26846 - irq_work_queue(&a->irq_work);
26847 + a->work->max_duration = delta;
26848 + irq_work_queue(&a->work->irq_work);
26849 }
26850
26851 rcu_read_unlock();
26852 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26853 }
26854 NOKPROBE_SYMBOL(nmi_handle);
26855
26856 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26857 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26858 {
26859 struct nmi_desc *desc = nmi_to_desc(type);
26860 unsigned long flags;
26861 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26862 if (!action->handler)
26863 return -EINVAL;
26864
26865 - init_irq_work(&action->irq_work, nmi_max_handler);
26866 + action->work->action = action;
26867 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26868
26869 spin_lock_irqsave(&desc->lock, flags);
26870
26871 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26872 * event confuses some handlers (kdump uses this flag)
26873 */
26874 if (action->flags & NMI_FLAG_FIRST)
26875 - list_add_rcu(&action->list, &desc->head);
26876 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26877 else
26878 - list_add_tail_rcu(&action->list, &desc->head);
26879 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26880
26881 spin_unlock_irqrestore(&desc->lock, flags);
26882 return 0;
26883 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26884 if (!strcmp(n->name, name)) {
26885 WARN(in_nmi(),
26886 "Trying to free NMI (%s) from NMI context!\n", n->name);
26887 - list_del_rcu(&n->list);
26888 + pax_list_del_rcu((struct list_head *)&n->list);
26889 break;
26890 }
26891 }
26892 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26893 dotraplinkage notrace void
26894 do_nmi(struct pt_regs *regs, long error_code)
26895 {
26896 +
26897 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26898 + if (!user_mode(regs)) {
26899 + unsigned long cs = regs->cs & 0xFFFF;
26900 + unsigned long ip = ktva_ktla(regs->ip);
26901 +
26902 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26903 + regs->ip = ip;
26904 + }
26905 +#endif
26906 +
26907 nmi_nesting_preprocess(regs);
26908
26909 nmi_enter();
26910 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26911 index 6d9582e..f746287 100644
26912 --- a/arch/x86/kernel/nmi_selftest.c
26913 +++ b/arch/x86/kernel/nmi_selftest.c
26914 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26915 {
26916 /* trap all the unknown NMIs we may generate */
26917 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26918 - __initdata);
26919 + __initconst);
26920 }
26921
26922 static void __init cleanup_nmi_testsuite(void)
26923 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26924 unsigned long timeout;
26925
26926 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26927 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26928 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26929 nmi_fail = FAILURE;
26930 return;
26931 }
26932 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26933 index bbb6c73..24a58ef 100644
26934 --- a/arch/x86/kernel/paravirt-spinlocks.c
26935 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26936 @@ -8,7 +8,7 @@
26937
26938 #include <asm/paravirt.h>
26939
26940 -struct pv_lock_ops pv_lock_ops = {
26941 +struct pv_lock_ops pv_lock_ops __read_only = {
26942 #ifdef CONFIG_SMP
26943 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26944 .unlock_kick = paravirt_nop,
26945 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26946 index 548d25f..f8fb99c 100644
26947 --- a/arch/x86/kernel/paravirt.c
26948 +++ b/arch/x86/kernel/paravirt.c
26949 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26950 {
26951 return x;
26952 }
26953 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26954 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26955 +#endif
26956
26957 void __init default_banner(void)
26958 {
26959 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26960
26961 if (opfunc == NULL)
26962 /* If there's no function, patch it with a ud2a (BUG) */
26963 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26964 - else if (opfunc == _paravirt_nop)
26965 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26966 + else if (opfunc == (void *)_paravirt_nop)
26967 /* If the operation is a nop, then nop the callsite */
26968 ret = paravirt_patch_nop();
26969
26970 /* identity functions just return their single argument */
26971 - else if (opfunc == _paravirt_ident_32)
26972 + else if (opfunc == (void *)_paravirt_ident_32)
26973 ret = paravirt_patch_ident_32(insnbuf, len);
26974 - else if (opfunc == _paravirt_ident_64)
26975 + else if (opfunc == (void *)_paravirt_ident_64)
26976 ret = paravirt_patch_ident_64(insnbuf, len);
26977 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26978 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26979 + ret = paravirt_patch_ident_64(insnbuf, len);
26980 +#endif
26981
26982 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26983 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26984 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26985 if (insn_len > len || start == NULL)
26986 insn_len = len;
26987 else
26988 - memcpy(insnbuf, start, insn_len);
26989 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26990
26991 return insn_len;
26992 }
26993 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26994 return this_cpu_read(paravirt_lazy_mode);
26995 }
26996
26997 -struct pv_info pv_info = {
26998 +struct pv_info pv_info __read_only = {
26999 .name = "bare hardware",
27000 .paravirt_enabled = 0,
27001 .kernel_rpl = 0,
27002 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
27003 #endif
27004 };
27005
27006 -struct pv_init_ops pv_init_ops = {
27007 +struct pv_init_ops pv_init_ops __read_only = {
27008 .patch = native_patch,
27009 };
27010
27011 -struct pv_time_ops pv_time_ops = {
27012 +struct pv_time_ops pv_time_ops __read_only = {
27013 .sched_clock = native_sched_clock,
27014 .steal_clock = native_steal_clock,
27015 };
27016
27017 -__visible struct pv_irq_ops pv_irq_ops = {
27018 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
27019 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
27020 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
27021 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
27022 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
27023 #endif
27024 };
27025
27026 -__visible struct pv_cpu_ops pv_cpu_ops = {
27027 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
27028 .cpuid = native_cpuid,
27029 .get_debugreg = native_get_debugreg,
27030 .set_debugreg = native_set_debugreg,
27031 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
27032 NOKPROBE_SYMBOL(native_set_debugreg);
27033 NOKPROBE_SYMBOL(native_load_idt);
27034
27035 -struct pv_apic_ops pv_apic_ops = {
27036 +struct pv_apic_ops pv_apic_ops __read_only= {
27037 #ifdef CONFIG_X86_LOCAL_APIC
27038 .startup_ipi_hook = paravirt_nop,
27039 #endif
27040 };
27041
27042 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
27043 +#ifdef CONFIG_X86_32
27044 +#ifdef CONFIG_X86_PAE
27045 +/* 64-bit pagetable entries */
27046 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
27047 +#else
27048 /* 32-bit pagetable entries */
27049 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
27050 +#endif
27051 #else
27052 /* 64-bit pagetable entries */
27053 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
27054 #endif
27055
27056 -struct pv_mmu_ops pv_mmu_ops = {
27057 +struct pv_mmu_ops pv_mmu_ops __read_only = {
27058
27059 .read_cr2 = native_read_cr2,
27060 .write_cr2 = native_write_cr2,
27061 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
27062 .make_pud = PTE_IDENT,
27063
27064 .set_pgd = native_set_pgd,
27065 + .set_pgd_batched = native_set_pgd_batched,
27066 #endif
27067 #endif /* PAGETABLE_LEVELS >= 3 */
27068
27069 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
27070 },
27071
27072 .set_fixmap = native_set_fixmap,
27073 +
27074 +#ifdef CONFIG_PAX_KERNEXEC
27075 + .pax_open_kernel = native_pax_open_kernel,
27076 + .pax_close_kernel = native_pax_close_kernel,
27077 +#endif
27078 +
27079 };
27080
27081 EXPORT_SYMBOL_GPL(pv_time_ops);
27082 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
27083 index 0497f71..7186c0d 100644
27084 --- a/arch/x86/kernel/pci-calgary_64.c
27085 +++ b/arch/x86/kernel/pci-calgary_64.c
27086 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
27087 tce_space = be64_to_cpu(readq(target));
27088 tce_space = tce_space & TAR_SW_BITS;
27089
27090 - tce_space = tce_space & (~specified_table_size);
27091 + tce_space = tce_space & (~(unsigned long)specified_table_size);
27092 info->tce_space = (u64 *)__va(tce_space);
27093 }
27094 }
27095 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
27096 index 35ccf75..7a15747 100644
27097 --- a/arch/x86/kernel/pci-iommu_table.c
27098 +++ b/arch/x86/kernel/pci-iommu_table.c
27099 @@ -2,7 +2,7 @@
27100 #include <asm/iommu_table.h>
27101 #include <linux/string.h>
27102 #include <linux/kallsyms.h>
27103 -
27104 +#include <linux/sched.h>
27105
27106 #define DEBUG 1
27107
27108 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
27109 index 77dd0ad..9ec4723 100644
27110 --- a/arch/x86/kernel/pci-swiotlb.c
27111 +++ b/arch/x86/kernel/pci-swiotlb.c
27112 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
27113 struct dma_attrs *attrs)
27114 {
27115 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
27116 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
27117 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
27118 else
27119 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
27120 }
27121 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
27122 index ca7f0d5..8996469 100644
27123 --- a/arch/x86/kernel/preempt.S
27124 +++ b/arch/x86/kernel/preempt.S
27125 @@ -3,12 +3,14 @@
27126 #include <asm/dwarf2.h>
27127 #include <asm/asm.h>
27128 #include <asm/calling.h>
27129 +#include <asm/alternative-asm.h>
27130
27131 ENTRY(___preempt_schedule)
27132 CFI_STARTPROC
27133 SAVE_ALL
27134 call preempt_schedule
27135 RESTORE_ALL
27136 + pax_force_retaddr
27137 ret
27138 CFI_ENDPROC
27139
27140 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
27141 SAVE_ALL
27142 call preempt_schedule_context
27143 RESTORE_ALL
27144 + pax_force_retaddr
27145 ret
27146 CFI_ENDPROC
27147
27148 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
27149 index f804dc9..7c62095 100644
27150 --- a/arch/x86/kernel/process.c
27151 +++ b/arch/x86/kernel/process.c
27152 @@ -36,7 +36,8 @@
27153 * section. Since TSS's are completely CPU-local, we want them
27154 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
27155 */
27156 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
27157 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
27158 +EXPORT_SYMBOL(init_tss);
27159
27160 #ifdef CONFIG_X86_64
27161 static DEFINE_PER_CPU(unsigned char, is_idle);
27162 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
27163 task_xstate_cachep =
27164 kmem_cache_create("task_xstate", xstate_size,
27165 __alignof__(union thread_xstate),
27166 - SLAB_PANIC | SLAB_NOTRACK, NULL);
27167 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
27168 setup_xstate_comp();
27169 }
27170
27171 @@ -106,7 +107,7 @@ void exit_thread(void)
27172 unsigned long *bp = t->io_bitmap_ptr;
27173
27174 if (bp) {
27175 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
27176 + struct tss_struct *tss = init_tss + get_cpu();
27177
27178 t->io_bitmap_ptr = NULL;
27179 clear_thread_flag(TIF_IO_BITMAP);
27180 @@ -126,6 +127,9 @@ void flush_thread(void)
27181 {
27182 struct task_struct *tsk = current;
27183
27184 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
27185 + loadsegment(gs, 0);
27186 +#endif
27187 flush_ptrace_hw_breakpoint(tsk);
27188 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
27189 drop_init_fpu(tsk);
27190 @@ -272,7 +276,7 @@ static void __exit_idle(void)
27191 void exit_idle(void)
27192 {
27193 /* idle loop has pid 0 */
27194 - if (current->pid)
27195 + if (task_pid_nr(current))
27196 return;
27197 __exit_idle();
27198 }
27199 @@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
27200 return ret;
27201 }
27202 #endif
27203 -void stop_this_cpu(void *dummy)
27204 +__noreturn void stop_this_cpu(void *dummy)
27205 {
27206 local_irq_disable();
27207 /*
27208 @@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
27209 }
27210 early_param("idle", idle_setup);
27211
27212 -unsigned long arch_align_stack(unsigned long sp)
27213 +#ifdef CONFIG_PAX_RANDKSTACK
27214 +void pax_randomize_kstack(struct pt_regs *regs)
27215 {
27216 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
27217 - sp -= get_random_int() % 8192;
27218 - return sp & ~0xf;
27219 -}
27220 + struct thread_struct *thread = &current->thread;
27221 + unsigned long time;
27222
27223 -unsigned long arch_randomize_brk(struct mm_struct *mm)
27224 -{
27225 - unsigned long range_end = mm->brk + 0x02000000;
27226 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
27227 -}
27228 + if (!randomize_va_space)
27229 + return;
27230 +
27231 + if (v8086_mode(regs))
27232 + return;
27233
27234 + rdtscl(time);
27235 +
27236 + /* P4 seems to return a 0 LSB, ignore it */
27237 +#ifdef CONFIG_MPENTIUM4
27238 + time &= 0x3EUL;
27239 + time <<= 2;
27240 +#elif defined(CONFIG_X86_64)
27241 + time &= 0xFUL;
27242 + time <<= 4;
27243 +#else
27244 + time &= 0x1FUL;
27245 + time <<= 3;
27246 +#endif
27247 +
27248 + thread->sp0 ^= time;
27249 + load_sp0(init_tss + smp_processor_id(), thread);
27250 +
27251 +#ifdef CONFIG_X86_64
27252 + this_cpu_write(kernel_stack, thread->sp0);
27253 +#endif
27254 +}
27255 +#endif
27256 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
27257 index 7bc86bb..0ea06e8 100644
27258 --- a/arch/x86/kernel/process_32.c
27259 +++ b/arch/x86/kernel/process_32.c
27260 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
27261 unsigned long thread_saved_pc(struct task_struct *tsk)
27262 {
27263 return ((unsigned long *)tsk->thread.sp)[3];
27264 +//XXX return tsk->thread.eip;
27265 }
27266
27267 void __show_regs(struct pt_regs *regs, int all)
27268 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
27269 unsigned long sp;
27270 unsigned short ss, gs;
27271
27272 - if (user_mode_vm(regs)) {
27273 + if (user_mode(regs)) {
27274 sp = regs->sp;
27275 ss = regs->ss & 0xffff;
27276 - gs = get_user_gs(regs);
27277 } else {
27278 sp = kernel_stack_pointer(regs);
27279 savesegment(ss, ss);
27280 - savesegment(gs, gs);
27281 }
27282 + gs = get_user_gs(regs);
27283
27284 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
27285 (u16)regs->cs, regs->ip, regs->flags,
27286 - smp_processor_id());
27287 + raw_smp_processor_id());
27288 print_symbol("EIP is at %s\n", regs->ip);
27289
27290 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27291 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
27292 int copy_thread(unsigned long clone_flags, unsigned long sp,
27293 unsigned long arg, struct task_struct *p)
27294 {
27295 - struct pt_regs *childregs = task_pt_regs(p);
27296 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
27297 struct task_struct *tsk;
27298 int err;
27299
27300 p->thread.sp = (unsigned long) childregs;
27301 p->thread.sp0 = (unsigned long) (childregs+1);
27302 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27303
27304 if (unlikely(p->flags & PF_KTHREAD)) {
27305 /* kernel thread */
27306 memset(childregs, 0, sizeof(struct pt_regs));
27307 p->thread.ip = (unsigned long) ret_from_kernel_thread;
27308 - task_user_gs(p) = __KERNEL_STACK_CANARY;
27309 - childregs->ds = __USER_DS;
27310 - childregs->es = __USER_DS;
27311 + savesegment(gs, childregs->gs);
27312 + childregs->ds = __KERNEL_DS;
27313 + childregs->es = __KERNEL_DS;
27314 childregs->fs = __KERNEL_PERCPU;
27315 childregs->bx = sp; /* function */
27316 childregs->bp = arg;
27317 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27318 struct thread_struct *prev = &prev_p->thread,
27319 *next = &next_p->thread;
27320 int cpu = smp_processor_id();
27321 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27322 + struct tss_struct *tss = init_tss + cpu;
27323 fpu_switch_t fpu;
27324
27325 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
27326 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27327 */
27328 lazy_save_gs(prev->gs);
27329
27330 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27331 + __set_fs(task_thread_info(next_p)->addr_limit);
27332 +#endif
27333 +
27334 /*
27335 * Load the per-thread Thread-Local Storage descriptor.
27336 */
27337 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27338 */
27339 arch_end_context_switch(next_p);
27340
27341 - this_cpu_write(kernel_stack,
27342 - (unsigned long)task_stack_page(next_p) +
27343 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27344 + this_cpu_write(current_task, next_p);
27345 + this_cpu_write(current_tinfo, &next_p->tinfo);
27346 + this_cpu_write(kernel_stack, next->sp0);
27347
27348 /*
27349 * Restore %gs if needed (which is common)
27350 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27351
27352 switch_fpu_finish(next_p, fpu);
27353
27354 - this_cpu_write(current_task, next_p);
27355 -
27356 return prev_p;
27357 }
27358
27359 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
27360 } while (count++ < 16);
27361 return 0;
27362 }
27363 -
27364 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
27365 index ca5b02d..c0b2f6a 100644
27366 --- a/arch/x86/kernel/process_64.c
27367 +++ b/arch/x86/kernel/process_64.c
27368 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27369 struct pt_regs *childregs;
27370 struct task_struct *me = current;
27371
27372 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
27373 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
27374 childregs = task_pt_regs(p);
27375 p->thread.sp = (unsigned long) childregs;
27376 p->thread.usersp = me->thread.usersp;
27377 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27378 set_tsk_thread_flag(p, TIF_FORK);
27379 p->thread.fpu_counter = 0;
27380 p->thread.io_bitmap_ptr = NULL;
27381 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27382 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
27383 savesegment(es, p->thread.es);
27384 savesegment(ds, p->thread.ds);
27385 + savesegment(ss, p->thread.ss);
27386 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
27387 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
27388
27389 if (unlikely(p->flags & PF_KTHREAD)) {
27390 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27391 struct thread_struct *prev = &prev_p->thread;
27392 struct thread_struct *next = &next_p->thread;
27393 int cpu = smp_processor_id();
27394 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27395 + struct tss_struct *tss = init_tss + cpu;
27396 unsigned fsindex, gsindex;
27397 fpu_switch_t fpu;
27398
27399 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27400 if (unlikely(next->ds | prev->ds))
27401 loadsegment(ds, next->ds);
27402
27403 + savesegment(ss, prev->ss);
27404 + if (unlikely(next->ss != prev->ss))
27405 + loadsegment(ss, next->ss);
27406
27407 /* We must save %fs and %gs before load_TLS() because
27408 * %fs and %gs may be cleared by load_TLS().
27409 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27410 prev->usersp = this_cpu_read(old_rsp);
27411 this_cpu_write(old_rsp, next->usersp);
27412 this_cpu_write(current_task, next_p);
27413 + this_cpu_write(current_tinfo, &next_p->tinfo);
27414
27415 /*
27416 * If it were not for PREEMPT_ACTIVE we could guarantee that the
27417 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27418 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
27419 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
27420
27421 - this_cpu_write(kernel_stack,
27422 - (unsigned long)task_stack_page(next_p) +
27423 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27424 + this_cpu_write(kernel_stack, next->sp0);
27425
27426 /*
27427 * Now maybe reload the debug registers and handle I/O bitmaps
27428 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
27429 if (!p || p == current || p->state == TASK_RUNNING)
27430 return 0;
27431 stack = (unsigned long)task_stack_page(p);
27432 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
27433 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
27434 return 0;
27435 fp = *(u64 *)(p->thread.sp);
27436 do {
27437 - if (fp < (unsigned long)stack ||
27438 - fp >= (unsigned long)stack+THREAD_SIZE)
27439 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27440 return 0;
27441 ip = *(u64 *)(fp+8);
27442 if (!in_sched_functions(ip))
27443 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27444 index b1a5dfa..ed94526 100644
27445 --- a/arch/x86/kernel/ptrace.c
27446 +++ b/arch/x86/kernel/ptrace.c
27447 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27448 unsigned long sp = (unsigned long)&regs->sp;
27449 u32 *prev_esp;
27450
27451 - if (context == (sp & ~(THREAD_SIZE - 1)))
27452 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27453 return sp;
27454
27455 - prev_esp = (u32 *)(context);
27456 + prev_esp = *(u32 **)(context);
27457 if (prev_esp)
27458 return (unsigned long)prev_esp;
27459
27460 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27461 if (child->thread.gs != value)
27462 return do_arch_prctl(child, ARCH_SET_GS, value);
27463 return 0;
27464 +
27465 + case offsetof(struct user_regs_struct,ip):
27466 + /*
27467 + * Protect against any attempt to set ip to an
27468 + * impossible address. There are dragons lurking if the
27469 + * address is noncanonical. (This explicitly allows
27470 + * setting ip to TASK_SIZE_MAX, because user code can do
27471 + * that all by itself by running off the end of its
27472 + * address space.
27473 + */
27474 + if (value > TASK_SIZE_MAX)
27475 + return -EIO;
27476 + break;
27477 +
27478 #endif
27479 }
27480
27481 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27482 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27483 {
27484 int i;
27485 - int dr7 = 0;
27486 + unsigned long dr7 = 0;
27487 struct arch_hw_breakpoint *info;
27488
27489 for (i = 0; i < HBP_NUM; i++) {
27490 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27491 unsigned long addr, unsigned long data)
27492 {
27493 int ret;
27494 - unsigned long __user *datap = (unsigned long __user *)data;
27495 + unsigned long __user *datap = (__force unsigned long __user *)data;
27496
27497 switch (request) {
27498 /* read the word at location addr in the USER area. */
27499 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27500 if ((int) addr < 0)
27501 return -EIO;
27502 ret = do_get_thread_area(child, addr,
27503 - (struct user_desc __user *)data);
27504 + (__force struct user_desc __user *) data);
27505 break;
27506
27507 case PTRACE_SET_THREAD_AREA:
27508 if ((int) addr < 0)
27509 return -EIO;
27510 ret = do_set_thread_area(child, addr,
27511 - (struct user_desc __user *)data, 0);
27512 + (__force struct user_desc __user *) data, 0);
27513 break;
27514 #endif
27515
27516 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27517
27518 #ifdef CONFIG_X86_64
27519
27520 -static struct user_regset x86_64_regsets[] __read_mostly = {
27521 +static user_regset_no_const x86_64_regsets[] __read_only = {
27522 [REGSET_GENERAL] = {
27523 .core_note_type = NT_PRSTATUS,
27524 .n = sizeof(struct user_regs_struct) / sizeof(long),
27525 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27526 #endif /* CONFIG_X86_64 */
27527
27528 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27529 -static struct user_regset x86_32_regsets[] __read_mostly = {
27530 +static user_regset_no_const x86_32_regsets[] __read_only = {
27531 [REGSET_GENERAL] = {
27532 .core_note_type = NT_PRSTATUS,
27533 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27534 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27535 */
27536 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27537
27538 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27539 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27540 {
27541 #ifdef CONFIG_X86_64
27542 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27543 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27544 memset(info, 0, sizeof(*info));
27545 info->si_signo = SIGTRAP;
27546 info->si_code = si_code;
27547 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27548 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27549 }
27550
27551 void user_single_step_siginfo(struct task_struct *tsk,
27552 @@ -1441,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27553 force_sig_info(SIGTRAP, &info, tsk);
27554 }
27555
27556 +#ifdef CONFIG_GRKERNSEC_SETXID
27557 +extern void gr_delayed_cred_worker(void);
27558 +#endif
27559 +
27560 /*
27561 * We must return the syscall number to actually look up in the table.
27562 * This can be -1L to skip running any syscall at all.
27563 @@ -1451,6 +1469,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27564
27565 user_exit();
27566
27567 +#ifdef CONFIG_GRKERNSEC_SETXID
27568 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27569 + gr_delayed_cred_worker();
27570 +#endif
27571 +
27572 /*
27573 * If we stepped into a sysenter/syscall insn, it trapped in
27574 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27575 @@ -1506,6 +1529,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27576 */
27577 user_exit();
27578
27579 +#ifdef CONFIG_GRKERNSEC_SETXID
27580 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27581 + gr_delayed_cred_worker();
27582 +#endif
27583 +
27584 audit_syscall_exit(regs);
27585
27586 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27587 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27588 index 2f355d2..e75ed0a 100644
27589 --- a/arch/x86/kernel/pvclock.c
27590 +++ b/arch/x86/kernel/pvclock.c
27591 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27592 reset_hung_task_detector();
27593 }
27594
27595 -static atomic64_t last_value = ATOMIC64_INIT(0);
27596 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27597
27598 void pvclock_resume(void)
27599 {
27600 - atomic64_set(&last_value, 0);
27601 + atomic64_set_unchecked(&last_value, 0);
27602 }
27603
27604 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27605 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27606 * updating at the same time, and one of them could be slightly behind,
27607 * making the assumption that last_value always go forward fail to hold.
27608 */
27609 - last = atomic64_read(&last_value);
27610 + last = atomic64_read_unchecked(&last_value);
27611 do {
27612 if (ret < last)
27613 return last;
27614 - last = atomic64_cmpxchg(&last_value, last, ret);
27615 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27616 } while (unlikely(last != ret));
27617
27618 return ret;
27619 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27620 index 17962e6..47f55db 100644
27621 --- a/arch/x86/kernel/reboot.c
27622 +++ b/arch/x86/kernel/reboot.c
27623 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27624
27625 void __noreturn machine_real_restart(unsigned int type)
27626 {
27627 +
27628 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27629 + struct desc_struct *gdt;
27630 +#endif
27631 +
27632 local_irq_disable();
27633
27634 /*
27635 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27636
27637 /* Jump to the identity-mapped low memory code */
27638 #ifdef CONFIG_X86_32
27639 - asm volatile("jmpl *%0" : :
27640 +
27641 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27642 + gdt = get_cpu_gdt_table(smp_processor_id());
27643 + pax_open_kernel();
27644 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27645 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27646 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27647 + loadsegment(ds, __KERNEL_DS);
27648 + loadsegment(es, __KERNEL_DS);
27649 + loadsegment(ss, __KERNEL_DS);
27650 +#endif
27651 +#ifdef CONFIG_PAX_KERNEXEC
27652 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27653 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27654 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27655 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27656 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27657 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27658 +#endif
27659 + pax_close_kernel();
27660 +#endif
27661 +
27662 + asm volatile("ljmpl *%0" : :
27663 "rm" (real_mode_header->machine_real_restart_asm),
27664 "a" (type));
27665 #else
27666 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27667 * This means that this function can never return, it can misbehave
27668 * by not rebooting properly and hanging.
27669 */
27670 -static void native_machine_emergency_restart(void)
27671 +static void __noreturn native_machine_emergency_restart(void)
27672 {
27673 int i;
27674 int attempt = 0;
27675 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27676 #endif
27677 }
27678
27679 -static void __machine_emergency_restart(int emergency)
27680 +static void __noreturn __machine_emergency_restart(int emergency)
27681 {
27682 reboot_emergency = emergency;
27683 machine_ops.emergency_restart();
27684 }
27685
27686 -static void native_machine_restart(char *__unused)
27687 +static void __noreturn native_machine_restart(char *__unused)
27688 {
27689 pr_notice("machine restart\n");
27690
27691 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27692 __machine_emergency_restart(0);
27693 }
27694
27695 -static void native_machine_halt(void)
27696 +static void __noreturn native_machine_halt(void)
27697 {
27698 /* Stop other cpus and apics */
27699 machine_shutdown();
27700 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27701 stop_this_cpu(NULL);
27702 }
27703
27704 -static void native_machine_power_off(void)
27705 +static void __noreturn native_machine_power_off(void)
27706 {
27707 if (pm_power_off) {
27708 if (!reboot_force)
27709 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27710 }
27711 /* A fallback in case there is no PM info available */
27712 tboot_shutdown(TB_SHUTDOWN_HALT);
27713 + unreachable();
27714 }
27715
27716 -struct machine_ops machine_ops = {
27717 +struct machine_ops machine_ops __read_only = {
27718 .power_off = native_machine_power_off,
27719 .shutdown = native_machine_shutdown,
27720 .emergency_restart = native_machine_emergency_restart,
27721 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27722 index c8e41e9..64049ef 100644
27723 --- a/arch/x86/kernel/reboot_fixups_32.c
27724 +++ b/arch/x86/kernel/reboot_fixups_32.c
27725 @@ -57,7 +57,7 @@ struct device_fixup {
27726 unsigned int vendor;
27727 unsigned int device;
27728 void (*reboot_fixup)(struct pci_dev *);
27729 -};
27730 +} __do_const;
27731
27732 /*
27733 * PCI ids solely used for fixups_table go here
27734 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27735 index 3fd2c69..a444264 100644
27736 --- a/arch/x86/kernel/relocate_kernel_64.S
27737 +++ b/arch/x86/kernel/relocate_kernel_64.S
27738 @@ -96,8 +96,7 @@ relocate_kernel:
27739
27740 /* jump to identity mapped page */
27741 addq $(identity_mapped - relocate_kernel), %r8
27742 - pushq %r8
27743 - ret
27744 + jmp *%r8
27745
27746 identity_mapped:
27747 /* set return address to 0 if not preserving context */
27748 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27749 index 41ead8d..7ccde23 100644
27750 --- a/arch/x86/kernel/setup.c
27751 +++ b/arch/x86/kernel/setup.c
27752 @@ -110,6 +110,7 @@
27753 #include <asm/mce.h>
27754 #include <asm/alternative.h>
27755 #include <asm/prom.h>
27756 +#include <asm/boot.h>
27757
27758 /*
27759 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27760 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27761 #endif
27762
27763
27764 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27765 -__visible unsigned long mmu_cr4_features;
27766 +#ifdef CONFIG_X86_64
27767 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27768 +#elif defined(CONFIG_X86_PAE)
27769 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27770 #else
27771 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27772 +__visible unsigned long mmu_cr4_features __read_only;
27773 #endif
27774
27775 +void set_in_cr4(unsigned long mask)
27776 +{
27777 + unsigned long cr4 = read_cr4();
27778 +
27779 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27780 + return;
27781 +
27782 + pax_open_kernel();
27783 + mmu_cr4_features |= mask;
27784 + pax_close_kernel();
27785 +
27786 + if (trampoline_cr4_features)
27787 + *trampoline_cr4_features = mmu_cr4_features;
27788 + cr4 |= mask;
27789 + write_cr4(cr4);
27790 +}
27791 +EXPORT_SYMBOL(set_in_cr4);
27792 +
27793 +void clear_in_cr4(unsigned long mask)
27794 +{
27795 + unsigned long cr4 = read_cr4();
27796 +
27797 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27798 + return;
27799 +
27800 + pax_open_kernel();
27801 + mmu_cr4_features &= ~mask;
27802 + pax_close_kernel();
27803 +
27804 + if (trampoline_cr4_features)
27805 + *trampoline_cr4_features = mmu_cr4_features;
27806 + cr4 &= ~mask;
27807 + write_cr4(cr4);
27808 +}
27809 +EXPORT_SYMBOL(clear_in_cr4);
27810 +
27811 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27812 int bootloader_type, bootloader_version;
27813
27814 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27815 * area (640->1Mb) as ram even though it is not.
27816 * take them out.
27817 */
27818 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27819 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27820
27821 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27822 }
27823 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27824 /* called before trim_bios_range() to spare extra sanitize */
27825 static void __init e820_add_kernel_range(void)
27826 {
27827 - u64 start = __pa_symbol(_text);
27828 + u64 start = __pa_symbol(ktla_ktva(_text));
27829 u64 size = __pa_symbol(_end) - start;
27830
27831 /*
27832 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27833
27834 void __init setup_arch(char **cmdline_p)
27835 {
27836 +#ifdef CONFIG_X86_32
27837 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27838 +#else
27839 memblock_reserve(__pa_symbol(_text),
27840 (unsigned long)__bss_stop - (unsigned long)_text);
27841 +#endif
27842
27843 early_reserve_initrd();
27844
27845 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27846
27847 if (!boot_params.hdr.root_flags)
27848 root_mountflags &= ~MS_RDONLY;
27849 - init_mm.start_code = (unsigned long) _text;
27850 - init_mm.end_code = (unsigned long) _etext;
27851 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27852 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27853 init_mm.end_data = (unsigned long) _edata;
27854 init_mm.brk = _brk_end;
27855
27856 - code_resource.start = __pa_symbol(_text);
27857 - code_resource.end = __pa_symbol(_etext)-1;
27858 - data_resource.start = __pa_symbol(_etext);
27859 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27860 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27861 + data_resource.start = __pa_symbol(_sdata);
27862 data_resource.end = __pa_symbol(_edata)-1;
27863 bss_resource.start = __pa_symbol(__bss_start);
27864 bss_resource.end = __pa_symbol(__bss_stop)-1;
27865 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27866 index 5cdff03..80fa283 100644
27867 --- a/arch/x86/kernel/setup_percpu.c
27868 +++ b/arch/x86/kernel/setup_percpu.c
27869 @@ -21,19 +21,17 @@
27870 #include <asm/cpu.h>
27871 #include <asm/stackprotector.h>
27872
27873 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27874 +#ifdef CONFIG_SMP
27875 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27876 EXPORT_PER_CPU_SYMBOL(cpu_number);
27877 +#endif
27878
27879 -#ifdef CONFIG_X86_64
27880 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27881 -#else
27882 -#define BOOT_PERCPU_OFFSET 0
27883 -#endif
27884
27885 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27886 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27887
27888 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27889 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27890 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27891 };
27892 EXPORT_SYMBOL(__per_cpu_offset);
27893 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27894 {
27895 #ifdef CONFIG_NEED_MULTIPLE_NODES
27896 pg_data_t *last = NULL;
27897 - unsigned int cpu;
27898 + int cpu;
27899
27900 for_each_possible_cpu(cpu) {
27901 int node = early_cpu_to_node(cpu);
27902 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27903 {
27904 #ifdef CONFIG_X86_32
27905 struct desc_struct gdt;
27906 + unsigned long base = per_cpu_offset(cpu);
27907
27908 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27909 - 0x2 | DESCTYPE_S, 0x8);
27910 - gdt.s = 1;
27911 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27912 + 0x83 | DESCTYPE_S, 0xC);
27913 write_gdt_entry(get_cpu_gdt_table(cpu),
27914 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27915 #endif
27916 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27917 /* alrighty, percpu areas up and running */
27918 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27919 for_each_possible_cpu(cpu) {
27920 +#ifdef CONFIG_CC_STACKPROTECTOR
27921 +#ifdef CONFIG_X86_32
27922 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27923 +#endif
27924 +#endif
27925 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27926 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27927 per_cpu(cpu_number, cpu) = cpu;
27928 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27929 */
27930 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27931 #endif
27932 +#ifdef CONFIG_CC_STACKPROTECTOR
27933 +#ifdef CONFIG_X86_32
27934 + if (!cpu)
27935 + per_cpu(stack_canary.canary, cpu) = canary;
27936 +#endif
27937 +#endif
27938 /*
27939 * Up to this point, the boot CPU has been using .init.data
27940 * area. Reload any changed state for the boot CPU.
27941 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27942 index ed37a76..39f936e 100644
27943 --- a/arch/x86/kernel/signal.c
27944 +++ b/arch/x86/kernel/signal.c
27945 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27946 * Align the stack pointer according to the i386 ABI,
27947 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27948 */
27949 - sp = ((sp + 4) & -16ul) - 4;
27950 + sp = ((sp - 12) & -16ul) - 4;
27951 #else /* !CONFIG_X86_32 */
27952 sp = round_down(sp, 16) - 8;
27953 #endif
27954 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27955 }
27956
27957 if (current->mm->context.vdso)
27958 - restorer = current->mm->context.vdso +
27959 - selected_vdso32->sym___kernel_sigreturn;
27960 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27961 else
27962 - restorer = &frame->retcode;
27963 + restorer = (void __user *)&frame->retcode;
27964 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27965 restorer = ksig->ka.sa.sa_restorer;
27966
27967 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27968 * reasons and because gdb uses it as a signature to notice
27969 * signal handler stack frames.
27970 */
27971 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27972 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27973
27974 if (err)
27975 return -EFAULT;
27976 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27977 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27978
27979 /* Set up to return from userspace. */
27980 - restorer = current->mm->context.vdso +
27981 - selected_vdso32->sym___kernel_rt_sigreturn;
27982 + if (current->mm->context.vdso)
27983 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27984 + else
27985 + restorer = (void __user *)&frame->retcode;
27986 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27987 restorer = ksig->ka.sa.sa_restorer;
27988 put_user_ex(restorer, &frame->pretcode);
27989 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27990 * reasons and because gdb uses it as a signature to notice
27991 * signal handler stack frames.
27992 */
27993 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27994 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27995 } put_user_catch(err);
27996
27997 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27998 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27999 {
28000 int usig = signr_convert(ksig->sig);
28001 sigset_t *set = sigmask_to_save();
28002 - compat_sigset_t *cset = (compat_sigset_t *) set;
28003 + sigset_t sigcopy;
28004 + compat_sigset_t *cset;
28005 +
28006 + sigcopy = *set;
28007 +
28008 + cset = (compat_sigset_t *) &sigcopy;
28009
28010 /* Set up the stack frame */
28011 if (is_ia32_frame()) {
28012 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28013 } else if (is_x32_frame()) {
28014 return x32_setup_rt_frame(ksig, cset, regs);
28015 } else {
28016 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
28017 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
28018 }
28019 }
28020
28021 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
28022 index be8e1bd..a3d93fa 100644
28023 --- a/arch/x86/kernel/smp.c
28024 +++ b/arch/x86/kernel/smp.c
28025 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
28026
28027 __setup("nonmi_ipi", nonmi_ipi_setup);
28028
28029 -struct smp_ops smp_ops = {
28030 +struct smp_ops smp_ops __read_only = {
28031 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
28032 .smp_prepare_cpus = native_smp_prepare_cpus,
28033 .smp_cpus_done = native_smp_cpus_done,
28034 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
28035 index 42a2dca..35a07aa 100644
28036 --- a/arch/x86/kernel/smpboot.c
28037 +++ b/arch/x86/kernel/smpboot.c
28038 @@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
28039
28040 enable_start_cpu0 = 0;
28041
28042 -#ifdef CONFIG_X86_32
28043 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
28044 + barrier();
28045 +
28046 /* switch away from the initial page table */
28047 +#ifdef CONFIG_PAX_PER_CPU_PGD
28048 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
28049 +#else
28050 load_cr3(swapper_pg_dir);
28051 +#endif
28052 __flush_tlb_all();
28053 -#endif
28054
28055 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
28056 - barrier();
28057 /*
28058 * Check TSC synchronization with the BP:
28059 */
28060 @@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28061 alternatives_enable_smp();
28062
28063 idle->thread.sp = (unsigned long) (((struct pt_regs *)
28064 - (THREAD_SIZE + task_stack_page(idle))) - 1);
28065 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
28066 per_cpu(current_task, cpu) = idle;
28067 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
28068
28069 #ifdef CONFIG_X86_32
28070 /* Stack for startup_32 can be just as for start_secondary onwards */
28071 @@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28072 clear_tsk_thread_flag(idle, TIF_FORK);
28073 initial_gs = per_cpu_offset(cpu);
28074 #endif
28075 - per_cpu(kernel_stack, cpu) =
28076 - (unsigned long)task_stack_page(idle) -
28077 - KERNEL_STACK_OFFSET + THREAD_SIZE;
28078 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28079 + pax_open_kernel();
28080 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
28081 + pax_close_kernel();
28082 initial_code = (unsigned long)start_secondary;
28083 stack_start = idle->thread.sp;
28084
28085 @@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
28086 /* the FPU context is blank, nobody can own it */
28087 __cpu_disable_lazy_restore(cpu);
28088
28089 +#ifdef CONFIG_PAX_PER_CPU_PGD
28090 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
28091 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28092 + KERNEL_PGD_PTRS);
28093 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
28094 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28095 + KERNEL_PGD_PTRS);
28096 +#endif
28097 +
28098 err = do_boot_cpu(apicid, cpu, tidle);
28099 if (err) {
28100 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
28101 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
28102 index 9b4d51d..5d28b58 100644
28103 --- a/arch/x86/kernel/step.c
28104 +++ b/arch/x86/kernel/step.c
28105 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28106 struct desc_struct *desc;
28107 unsigned long base;
28108
28109 - seg &= ~7UL;
28110 + seg >>= 3;
28111
28112 mutex_lock(&child->mm->context.lock);
28113 - if (unlikely((seg >> 3) >= child->mm->context.size))
28114 + if (unlikely(seg >= child->mm->context.size))
28115 addr = -1L; /* bogus selector, access would fault */
28116 else {
28117 desc = child->mm->context.ldt + seg;
28118 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28119 addr += base;
28120 }
28121 mutex_unlock(&child->mm->context.lock);
28122 - }
28123 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
28124 + addr = ktla_ktva(addr);
28125
28126 return addr;
28127 }
28128 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
28129 unsigned char opcode[15];
28130 unsigned long addr = convert_ip_to_linear(child, regs);
28131
28132 + if (addr == -EINVAL)
28133 + return 0;
28134 +
28135 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
28136 for (i = 0; i < copied; i++) {
28137 switch (opcode[i]) {
28138 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
28139 new file mode 100644
28140 index 0000000..5877189
28141 --- /dev/null
28142 +++ b/arch/x86/kernel/sys_i386_32.c
28143 @@ -0,0 +1,189 @@
28144 +/*
28145 + * This file contains various random system calls that
28146 + * have a non-standard calling sequence on the Linux/i386
28147 + * platform.
28148 + */
28149 +
28150 +#include <linux/errno.h>
28151 +#include <linux/sched.h>
28152 +#include <linux/mm.h>
28153 +#include <linux/fs.h>
28154 +#include <linux/smp.h>
28155 +#include <linux/sem.h>
28156 +#include <linux/msg.h>
28157 +#include <linux/shm.h>
28158 +#include <linux/stat.h>
28159 +#include <linux/syscalls.h>
28160 +#include <linux/mman.h>
28161 +#include <linux/file.h>
28162 +#include <linux/utsname.h>
28163 +#include <linux/ipc.h>
28164 +#include <linux/elf.h>
28165 +
28166 +#include <linux/uaccess.h>
28167 +#include <linux/unistd.h>
28168 +
28169 +#include <asm/syscalls.h>
28170 +
28171 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
28172 +{
28173 + unsigned long pax_task_size = TASK_SIZE;
28174 +
28175 +#ifdef CONFIG_PAX_SEGMEXEC
28176 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
28177 + pax_task_size = SEGMEXEC_TASK_SIZE;
28178 +#endif
28179 +
28180 + if (flags & MAP_FIXED)
28181 + if (len > pax_task_size || addr > pax_task_size - len)
28182 + return -EINVAL;
28183 +
28184 + return 0;
28185 +}
28186 +
28187 +/*
28188 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
28189 + */
28190 +static unsigned long get_align_mask(void)
28191 +{
28192 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
28193 + return 0;
28194 +
28195 + if (!(current->flags & PF_RANDOMIZE))
28196 + return 0;
28197 +
28198 + return va_align.mask;
28199 +}
28200 +
28201 +unsigned long
28202 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
28203 + unsigned long len, unsigned long pgoff, unsigned long flags)
28204 +{
28205 + struct mm_struct *mm = current->mm;
28206 + struct vm_area_struct *vma;
28207 + unsigned long pax_task_size = TASK_SIZE;
28208 + struct vm_unmapped_area_info info;
28209 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28210 +
28211 +#ifdef CONFIG_PAX_SEGMEXEC
28212 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28213 + pax_task_size = SEGMEXEC_TASK_SIZE;
28214 +#endif
28215 +
28216 + pax_task_size -= PAGE_SIZE;
28217 +
28218 + if (len > pax_task_size)
28219 + return -ENOMEM;
28220 +
28221 + if (flags & MAP_FIXED)
28222 + return addr;
28223 +
28224 +#ifdef CONFIG_PAX_RANDMMAP
28225 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28226 +#endif
28227 +
28228 + if (addr) {
28229 + addr = PAGE_ALIGN(addr);
28230 + if (pax_task_size - len >= addr) {
28231 + vma = find_vma(mm, addr);
28232 + if (check_heap_stack_gap(vma, addr, len, offset))
28233 + return addr;
28234 + }
28235 + }
28236 +
28237 + info.flags = 0;
28238 + info.length = len;
28239 + info.align_mask = filp ? get_align_mask() : 0;
28240 + info.align_offset = pgoff << PAGE_SHIFT;
28241 + info.threadstack_offset = offset;
28242 +
28243 +#ifdef CONFIG_PAX_PAGEEXEC
28244 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
28245 + info.low_limit = 0x00110000UL;
28246 + info.high_limit = mm->start_code;
28247 +
28248 +#ifdef CONFIG_PAX_RANDMMAP
28249 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28250 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
28251 +#endif
28252 +
28253 + if (info.low_limit < info.high_limit) {
28254 + addr = vm_unmapped_area(&info);
28255 + if (!IS_ERR_VALUE(addr))
28256 + return addr;
28257 + }
28258 + } else
28259 +#endif
28260 +
28261 + info.low_limit = mm->mmap_base;
28262 + info.high_limit = pax_task_size;
28263 +
28264 + return vm_unmapped_area(&info);
28265 +}
28266 +
28267 +unsigned long
28268 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28269 + const unsigned long len, const unsigned long pgoff,
28270 + const unsigned long flags)
28271 +{
28272 + struct vm_area_struct *vma;
28273 + struct mm_struct *mm = current->mm;
28274 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
28275 + struct vm_unmapped_area_info info;
28276 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28277 +
28278 +#ifdef CONFIG_PAX_SEGMEXEC
28279 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28280 + pax_task_size = SEGMEXEC_TASK_SIZE;
28281 +#endif
28282 +
28283 + pax_task_size -= PAGE_SIZE;
28284 +
28285 + /* requested length too big for entire address space */
28286 + if (len > pax_task_size)
28287 + return -ENOMEM;
28288 +
28289 + if (flags & MAP_FIXED)
28290 + return addr;
28291 +
28292 +#ifdef CONFIG_PAX_PAGEEXEC
28293 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
28294 + goto bottomup;
28295 +#endif
28296 +
28297 +#ifdef CONFIG_PAX_RANDMMAP
28298 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28299 +#endif
28300 +
28301 + /* requesting a specific address */
28302 + if (addr) {
28303 + addr = PAGE_ALIGN(addr);
28304 + if (pax_task_size - len >= addr) {
28305 + vma = find_vma(mm, addr);
28306 + if (check_heap_stack_gap(vma, addr, len, offset))
28307 + return addr;
28308 + }
28309 + }
28310 +
28311 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
28312 + info.length = len;
28313 + info.low_limit = PAGE_SIZE;
28314 + info.high_limit = mm->mmap_base;
28315 + info.align_mask = filp ? get_align_mask() : 0;
28316 + info.align_offset = pgoff << PAGE_SHIFT;
28317 + info.threadstack_offset = offset;
28318 +
28319 + addr = vm_unmapped_area(&info);
28320 + if (!(addr & ~PAGE_MASK))
28321 + return addr;
28322 + VM_BUG_ON(addr != -ENOMEM);
28323 +
28324 +bottomup:
28325 + /*
28326 + * A failed mmap() very likely causes application failure,
28327 + * so fall back to the bottom-up function here. This scenario
28328 + * can happen with large stack limits and large mmap()
28329 + * allocations.
28330 + */
28331 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
28332 +}
28333 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
28334 index 30277e2..5664a29 100644
28335 --- a/arch/x86/kernel/sys_x86_64.c
28336 +++ b/arch/x86/kernel/sys_x86_64.c
28337 @@ -81,8 +81,8 @@ out:
28338 return error;
28339 }
28340
28341 -static void find_start_end(unsigned long flags, unsigned long *begin,
28342 - unsigned long *end)
28343 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
28344 + unsigned long *begin, unsigned long *end)
28345 {
28346 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
28347 unsigned long new_begin;
28348 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
28349 *begin = new_begin;
28350 }
28351 } else {
28352 - *begin = current->mm->mmap_legacy_base;
28353 + *begin = mm->mmap_legacy_base;
28354 *end = TASK_SIZE;
28355 }
28356 }
28357 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28358 struct vm_area_struct *vma;
28359 struct vm_unmapped_area_info info;
28360 unsigned long begin, end;
28361 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28362
28363 if (flags & MAP_FIXED)
28364 return addr;
28365
28366 - find_start_end(flags, &begin, &end);
28367 + find_start_end(mm, flags, &begin, &end);
28368
28369 if (len > end)
28370 return -ENOMEM;
28371
28372 +#ifdef CONFIG_PAX_RANDMMAP
28373 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28374 +#endif
28375 +
28376 if (addr) {
28377 addr = PAGE_ALIGN(addr);
28378 vma = find_vma(mm, addr);
28379 - if (end - len >= addr &&
28380 - (!vma || addr + len <= vma->vm_start))
28381 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28382 return addr;
28383 }
28384
28385 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28386 info.high_limit = end;
28387 info.align_mask = filp ? get_align_mask() : 0;
28388 info.align_offset = pgoff << PAGE_SHIFT;
28389 + info.threadstack_offset = offset;
28390 return vm_unmapped_area(&info);
28391 }
28392
28393 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28394 struct mm_struct *mm = current->mm;
28395 unsigned long addr = addr0;
28396 struct vm_unmapped_area_info info;
28397 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28398
28399 /* requested length too big for entire address space */
28400 if (len > TASK_SIZE)
28401 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28402 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
28403 goto bottomup;
28404
28405 +#ifdef CONFIG_PAX_RANDMMAP
28406 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28407 +#endif
28408 +
28409 /* requesting a specific address */
28410 if (addr) {
28411 addr = PAGE_ALIGN(addr);
28412 vma = find_vma(mm, addr);
28413 - if (TASK_SIZE - len >= addr &&
28414 - (!vma || addr + len <= vma->vm_start))
28415 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28416 return addr;
28417 }
28418
28419 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28420 info.high_limit = mm->mmap_base;
28421 info.align_mask = filp ? get_align_mask() : 0;
28422 info.align_offset = pgoff << PAGE_SHIFT;
28423 + info.threadstack_offset = offset;
28424 addr = vm_unmapped_area(&info);
28425 if (!(addr & ~PAGE_MASK))
28426 return addr;
28427 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
28428 index 91a4496..bb87552 100644
28429 --- a/arch/x86/kernel/tboot.c
28430 +++ b/arch/x86/kernel/tboot.c
28431 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
28432
28433 void tboot_shutdown(u32 shutdown_type)
28434 {
28435 - void (*shutdown)(void);
28436 + void (* __noreturn shutdown)(void);
28437
28438 if (!tboot_enabled())
28439 return;
28440 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28441
28442 switch_to_tboot_pt();
28443
28444 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28445 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28446 shutdown();
28447
28448 /* should not reach here */
28449 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28450 return -ENODEV;
28451 }
28452
28453 -static atomic_t ap_wfs_count;
28454 +static atomic_unchecked_t ap_wfs_count;
28455
28456 static int tboot_wait_for_aps(int num_aps)
28457 {
28458 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28459 {
28460 switch (action) {
28461 case CPU_DYING:
28462 - atomic_inc(&ap_wfs_count);
28463 + atomic_inc_unchecked(&ap_wfs_count);
28464 if (num_online_cpus() == 1)
28465 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28466 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28467 return NOTIFY_BAD;
28468 break;
28469 }
28470 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28471
28472 tboot_create_trampoline();
28473
28474 - atomic_set(&ap_wfs_count, 0);
28475 + atomic_set_unchecked(&ap_wfs_count, 0);
28476 register_hotcpu_notifier(&tboot_cpu_notifier);
28477
28478 #ifdef CONFIG_DEBUG_FS
28479 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28480 index 0fa2960..91eabbe 100644
28481 --- a/arch/x86/kernel/time.c
28482 +++ b/arch/x86/kernel/time.c
28483 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28484 {
28485 unsigned long pc = instruction_pointer(regs);
28486
28487 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28488 + if (!user_mode(regs) && in_lock_functions(pc)) {
28489 #ifdef CONFIG_FRAME_POINTER
28490 - return *(unsigned long *)(regs->bp + sizeof(long));
28491 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28492 #else
28493 unsigned long *sp =
28494 (unsigned long *)kernel_stack_pointer(regs);
28495 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28496 * or above a saved flags. Eflags has bits 22-31 zero,
28497 * kernel addresses don't.
28498 */
28499 +
28500 +#ifdef CONFIG_PAX_KERNEXEC
28501 + return ktla_ktva(sp[0]);
28502 +#else
28503 if (sp[0] >> 22)
28504 return sp[0];
28505 if (sp[1] >> 22)
28506 return sp[1];
28507 #endif
28508 +
28509 +#endif
28510 }
28511 return pc;
28512 }
28513 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28514 index f7fec09..9991981 100644
28515 --- a/arch/x86/kernel/tls.c
28516 +++ b/arch/x86/kernel/tls.c
28517 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28518 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28519 return -EINVAL;
28520
28521 +#ifdef CONFIG_PAX_SEGMEXEC
28522 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28523 + return -EINVAL;
28524 +#endif
28525 +
28526 set_tls_desc(p, idx, &info, 1);
28527
28528 return 0;
28529 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28530
28531 if (kbuf)
28532 info = kbuf;
28533 - else if (__copy_from_user(infobuf, ubuf, count))
28534 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28535 return -EFAULT;
28536 else
28537 info = infobuf;
28538 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28539 index 1c113db..287b42e 100644
28540 --- a/arch/x86/kernel/tracepoint.c
28541 +++ b/arch/x86/kernel/tracepoint.c
28542 @@ -9,11 +9,11 @@
28543 #include <linux/atomic.h>
28544
28545 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28546 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28547 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28548 (unsigned long) trace_idt_table };
28549
28550 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28551 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28552 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28553
28554 static int trace_irq_vector_refcount;
28555 static DEFINE_MUTEX(irq_vector_mutex);
28556 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28557 index 0d0e922..0886373 100644
28558 --- a/arch/x86/kernel/traps.c
28559 +++ b/arch/x86/kernel/traps.c
28560 @@ -67,7 +67,7 @@
28561 #include <asm/proto.h>
28562
28563 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28564 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28565 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28566 #else
28567 #include <asm/processor-flags.h>
28568 #include <asm/setup.h>
28569 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28570 #endif
28571
28572 /* Must be page-aligned because the real IDT is used in a fixmap. */
28573 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28574 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28575
28576 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28577 EXPORT_SYMBOL_GPL(used_vectors);
28578 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28579 }
28580
28581 static nokprobe_inline int
28582 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28583 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28584 struct pt_regs *regs, long error_code)
28585 {
28586 #ifdef CONFIG_X86_32
28587 - if (regs->flags & X86_VM_MASK) {
28588 + if (v8086_mode(regs)) {
28589 /*
28590 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28591 * On nmi (interrupt 2), do_trap should not be called.
28592 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28593 return -1;
28594 }
28595 #endif
28596 - if (!user_mode(regs)) {
28597 + if (!user_mode_novm(regs)) {
28598 if (!fixup_exception(regs)) {
28599 tsk->thread.error_code = error_code;
28600 tsk->thread.trap_nr = trapnr;
28601 +
28602 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28603 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28604 + str = "PAX: suspicious stack segment fault";
28605 +#endif
28606 +
28607 die(str, regs, error_code);
28608 }
28609 +
28610 +#ifdef CONFIG_PAX_REFCOUNT
28611 + if (trapnr == X86_TRAP_OF)
28612 + pax_report_refcount_overflow(regs);
28613 +#endif
28614 +
28615 return 0;
28616 }
28617
28618 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28619 }
28620
28621 static void
28622 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28623 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28624 long error_code, siginfo_t *info)
28625 {
28626 struct task_struct *tsk = current;
28627 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28628 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28629 printk_ratelimit()) {
28630 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28631 - tsk->comm, tsk->pid, str,
28632 + tsk->comm, task_pid_nr(tsk), str,
28633 regs->ip, regs->sp, error_code);
28634 print_vma_addr(" in ", regs->ip);
28635 pr_cont("\n");
28636 @@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28637 tsk->thread.error_code = error_code;
28638 tsk->thread.trap_nr = X86_TRAP_DF;
28639
28640 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28641 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28642 + die("grsec: kernel stack overflow detected", regs, error_code);
28643 +#endif
28644 +
28645 #ifdef CONFIG_DOUBLEFAULT
28646 df_debug(regs, error_code);
28647 #endif
28648 @@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28649 conditional_sti(regs);
28650
28651 #ifdef CONFIG_X86_32
28652 - if (regs->flags & X86_VM_MASK) {
28653 + if (v8086_mode(regs)) {
28654 local_irq_enable();
28655 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28656 goto exit;
28657 @@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28658 #endif
28659
28660 tsk = current;
28661 - if (!user_mode(regs)) {
28662 + if (!user_mode_novm(regs)) {
28663 if (fixup_exception(regs))
28664 goto exit;
28665
28666 tsk->thread.error_code = error_code;
28667 tsk->thread.trap_nr = X86_TRAP_GP;
28668 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28669 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28670 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28671 +
28672 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28673 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28674 + die("PAX: suspicious general protection fault", regs, error_code);
28675 + else
28676 +#endif
28677 +
28678 die("general protection fault", regs, error_code);
28679 + }
28680 goto exit;
28681 }
28682
28683 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28684 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28685 + struct mm_struct *mm = tsk->mm;
28686 + unsigned long limit;
28687 +
28688 + down_write(&mm->mmap_sem);
28689 + limit = mm->context.user_cs_limit;
28690 + if (limit < TASK_SIZE) {
28691 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28692 + up_write(&mm->mmap_sem);
28693 + return;
28694 + }
28695 + up_write(&mm->mmap_sem);
28696 + }
28697 +#endif
28698 +
28699 tsk->thread.error_code = error_code;
28700 tsk->thread.trap_nr = X86_TRAP_GP;
28701
28702 @@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28703 /* It's safe to allow irq's after DR6 has been saved */
28704 preempt_conditional_sti(regs);
28705
28706 - if (regs->flags & X86_VM_MASK) {
28707 + if (v8086_mode(regs)) {
28708 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28709 X86_TRAP_DB);
28710 preempt_conditional_cli(regs);
28711 @@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28712 * We already checked v86 mode above, so we can check for kernel mode
28713 * by just checking the CPL of CS.
28714 */
28715 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28716 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28717 tsk->thread.debugreg6 &= ~DR_STEP;
28718 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28719 regs->flags &= ~X86_EFLAGS_TF;
28720 @@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28721 return;
28722 conditional_sti(regs);
28723
28724 - if (!user_mode_vm(regs))
28725 + if (!user_mode(regs))
28726 {
28727 if (!fixup_exception(regs)) {
28728 task->thread.error_code = error_code;
28729 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28730 index b7e50bb..f4a93ae 100644
28731 --- a/arch/x86/kernel/tsc.c
28732 +++ b/arch/x86/kernel/tsc.c
28733 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28734 */
28735 smp_wmb();
28736
28737 - ACCESS_ONCE(c2n->head) = data;
28738 + ACCESS_ONCE_RW(c2n->head) = data;
28739 }
28740
28741 /*
28742 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28743 index 5d1cbfe..2a21feb 100644
28744 --- a/arch/x86/kernel/uprobes.c
28745 +++ b/arch/x86/kernel/uprobes.c
28746 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28747 int ret = NOTIFY_DONE;
28748
28749 /* We are only interested in userspace traps */
28750 - if (regs && !user_mode_vm(regs))
28751 + if (regs && !user_mode(regs))
28752 return NOTIFY_DONE;
28753
28754 switch (val) {
28755 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28756
28757 if (nleft != rasize) {
28758 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28759 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28760 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28761
28762 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28763 }
28764 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28765 index b9242ba..50c5edd 100644
28766 --- a/arch/x86/kernel/verify_cpu.S
28767 +++ b/arch/x86/kernel/verify_cpu.S
28768 @@ -20,6 +20,7 @@
28769 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28770 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28771 * arch/x86/kernel/head_32.S: processor startup
28772 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28773 *
28774 * verify_cpu, returns the status of longmode and SSE in register %eax.
28775 * 0: Success 1: Failure
28776 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28777 index e8edcf5..27f9344 100644
28778 --- a/arch/x86/kernel/vm86_32.c
28779 +++ b/arch/x86/kernel/vm86_32.c
28780 @@ -44,6 +44,7 @@
28781 #include <linux/ptrace.h>
28782 #include <linux/audit.h>
28783 #include <linux/stddef.h>
28784 +#include <linux/grsecurity.h>
28785
28786 #include <asm/uaccess.h>
28787 #include <asm/io.h>
28788 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28789 do_exit(SIGSEGV);
28790 }
28791
28792 - tss = &per_cpu(init_tss, get_cpu());
28793 + tss = init_tss + get_cpu();
28794 current->thread.sp0 = current->thread.saved_sp0;
28795 current->thread.sysenter_cs = __KERNEL_CS;
28796 load_sp0(tss, &current->thread);
28797 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28798
28799 if (tsk->thread.saved_sp0)
28800 return -EPERM;
28801 +
28802 +#ifdef CONFIG_GRKERNSEC_VM86
28803 + if (!capable(CAP_SYS_RAWIO)) {
28804 + gr_handle_vm86();
28805 + return -EPERM;
28806 + }
28807 +#endif
28808 +
28809 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28810 offsetof(struct kernel_vm86_struct, vm86plus) -
28811 sizeof(info.regs));
28812 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28813 int tmp;
28814 struct vm86plus_struct __user *v86;
28815
28816 +#ifdef CONFIG_GRKERNSEC_VM86
28817 + if (!capable(CAP_SYS_RAWIO)) {
28818 + gr_handle_vm86();
28819 + return -EPERM;
28820 + }
28821 +#endif
28822 +
28823 tsk = current;
28824 switch (cmd) {
28825 case VM86_REQUEST_IRQ:
28826 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28827 tsk->thread.saved_fs = info->regs32->fs;
28828 tsk->thread.saved_gs = get_user_gs(info->regs32);
28829
28830 - tss = &per_cpu(init_tss, get_cpu());
28831 + tss = init_tss + get_cpu();
28832 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28833 if (cpu_has_sep)
28834 tsk->thread.sysenter_cs = 0;
28835 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28836 goto cannot_handle;
28837 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28838 goto cannot_handle;
28839 - intr_ptr = (unsigned long __user *) (i << 2);
28840 + intr_ptr = (__force unsigned long __user *) (i << 2);
28841 if (get_user(segoffs, intr_ptr))
28842 goto cannot_handle;
28843 if ((segoffs >> 16) == BIOSSEG)
28844 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28845 index 49edf2d..c0d1362 100644
28846 --- a/arch/x86/kernel/vmlinux.lds.S
28847 +++ b/arch/x86/kernel/vmlinux.lds.S
28848 @@ -26,6 +26,13 @@
28849 #include <asm/page_types.h>
28850 #include <asm/cache.h>
28851 #include <asm/boot.h>
28852 +#include <asm/segment.h>
28853 +
28854 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28855 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28856 +#else
28857 +#define __KERNEL_TEXT_OFFSET 0
28858 +#endif
28859
28860 #undef i386 /* in case the preprocessor is a 32bit one */
28861
28862 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28863
28864 PHDRS {
28865 text PT_LOAD FLAGS(5); /* R_E */
28866 +#ifdef CONFIG_X86_32
28867 + module PT_LOAD FLAGS(5); /* R_E */
28868 +#endif
28869 +#ifdef CONFIG_XEN
28870 + rodata PT_LOAD FLAGS(5); /* R_E */
28871 +#else
28872 + rodata PT_LOAD FLAGS(4); /* R__ */
28873 +#endif
28874 data PT_LOAD FLAGS(6); /* RW_ */
28875 -#ifdef CONFIG_X86_64
28876 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28877 #ifdef CONFIG_SMP
28878 percpu PT_LOAD FLAGS(6); /* RW_ */
28879 #endif
28880 + text.init PT_LOAD FLAGS(5); /* R_E */
28881 + text.exit PT_LOAD FLAGS(5); /* R_E */
28882 init PT_LOAD FLAGS(7); /* RWE */
28883 -#endif
28884 note PT_NOTE FLAGS(0); /* ___ */
28885 }
28886
28887 SECTIONS
28888 {
28889 #ifdef CONFIG_X86_32
28890 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28891 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28892 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28893 #else
28894 - . = __START_KERNEL;
28895 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28896 + . = __START_KERNEL;
28897 #endif
28898
28899 /* Text and read-only data */
28900 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28901 - _text = .;
28902 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28903 /* bootstrapping code */
28904 +#ifdef CONFIG_X86_32
28905 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28906 +#else
28907 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28908 +#endif
28909 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28910 + _text = .;
28911 HEAD_TEXT
28912 . = ALIGN(8);
28913 _stext = .;
28914 @@ -104,13 +124,47 @@ SECTIONS
28915 IRQENTRY_TEXT
28916 *(.fixup)
28917 *(.gnu.warning)
28918 - /* End of text section */
28919 - _etext = .;
28920 } :text = 0x9090
28921
28922 - NOTES :text :note
28923 + . += __KERNEL_TEXT_OFFSET;
28924
28925 - EXCEPTION_TABLE(16) :text = 0x9090
28926 +#ifdef CONFIG_X86_32
28927 + . = ALIGN(PAGE_SIZE);
28928 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28929 +
28930 +#ifdef CONFIG_PAX_KERNEXEC
28931 + MODULES_EXEC_VADDR = .;
28932 + BYTE(0)
28933 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28934 + . = ALIGN(HPAGE_SIZE) - 1;
28935 + MODULES_EXEC_END = .;
28936 +#endif
28937 +
28938 + } :module
28939 +#endif
28940 +
28941 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28942 + /* End of text section */
28943 + BYTE(0)
28944 + _etext = . - __KERNEL_TEXT_OFFSET;
28945 + }
28946 +
28947 +#ifdef CONFIG_X86_32
28948 + . = ALIGN(PAGE_SIZE);
28949 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28950 + . = ALIGN(PAGE_SIZE);
28951 + *(.empty_zero_page)
28952 + *(.initial_pg_fixmap)
28953 + *(.initial_pg_pmd)
28954 + *(.initial_page_table)
28955 + *(.swapper_pg_dir)
28956 + } :rodata
28957 +#endif
28958 +
28959 + . = ALIGN(PAGE_SIZE);
28960 + NOTES :rodata :note
28961 +
28962 + EXCEPTION_TABLE(16) :rodata
28963
28964 #if defined(CONFIG_DEBUG_RODATA)
28965 /* .text should occupy whole number of pages */
28966 @@ -122,16 +176,20 @@ SECTIONS
28967
28968 /* Data */
28969 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28970 +
28971 +#ifdef CONFIG_PAX_KERNEXEC
28972 + . = ALIGN(HPAGE_SIZE);
28973 +#else
28974 + . = ALIGN(PAGE_SIZE);
28975 +#endif
28976 +
28977 /* Start of data section */
28978 _sdata = .;
28979
28980 /* init_task */
28981 INIT_TASK_DATA(THREAD_SIZE)
28982
28983 -#ifdef CONFIG_X86_32
28984 - /* 32 bit has nosave before _edata */
28985 NOSAVE_DATA
28986 -#endif
28987
28988 PAGE_ALIGNED_DATA(PAGE_SIZE)
28989
28990 @@ -174,12 +232,19 @@ SECTIONS
28991 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28992
28993 /* Init code and data - will be freed after init */
28994 - . = ALIGN(PAGE_SIZE);
28995 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28996 + BYTE(0)
28997 +
28998 +#ifdef CONFIG_PAX_KERNEXEC
28999 + . = ALIGN(HPAGE_SIZE);
29000 +#else
29001 + . = ALIGN(PAGE_SIZE);
29002 +#endif
29003 +
29004 __init_begin = .; /* paired with __init_end */
29005 - }
29006 + } :init.begin
29007
29008 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
29009 +#ifdef CONFIG_SMP
29010 /*
29011 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
29012 * output PHDR, so the next output section - .init.text - should
29013 @@ -188,12 +253,27 @@ SECTIONS
29014 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
29015 #endif
29016
29017 - INIT_TEXT_SECTION(PAGE_SIZE)
29018 -#ifdef CONFIG_X86_64
29019 - :init
29020 -#endif
29021 + . = ALIGN(PAGE_SIZE);
29022 + init_begin = .;
29023 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
29024 + VMLINUX_SYMBOL(_sinittext) = .;
29025 + INIT_TEXT
29026 + VMLINUX_SYMBOL(_einittext) = .;
29027 + . = ALIGN(PAGE_SIZE);
29028 + } :text.init
29029
29030 - INIT_DATA_SECTION(16)
29031 + /*
29032 + * .exit.text is discard at runtime, not link time, to deal with
29033 + * references from .altinstructions and .eh_frame
29034 + */
29035 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29036 + EXIT_TEXT
29037 + . = ALIGN(16);
29038 + } :text.exit
29039 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
29040 +
29041 + . = ALIGN(PAGE_SIZE);
29042 + INIT_DATA_SECTION(16) :init
29043
29044 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
29045 __x86_cpu_dev_start = .;
29046 @@ -264,19 +344,12 @@ SECTIONS
29047 }
29048
29049 . = ALIGN(8);
29050 - /*
29051 - * .exit.text is discard at runtime, not link time, to deal with
29052 - * references from .altinstructions and .eh_frame
29053 - */
29054 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
29055 - EXIT_TEXT
29056 - }
29057
29058 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
29059 EXIT_DATA
29060 }
29061
29062 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
29063 +#ifndef CONFIG_SMP
29064 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
29065 #endif
29066
29067 @@ -295,16 +368,10 @@ SECTIONS
29068 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
29069 __smp_locks = .;
29070 *(.smp_locks)
29071 - . = ALIGN(PAGE_SIZE);
29072 __smp_locks_end = .;
29073 + . = ALIGN(PAGE_SIZE);
29074 }
29075
29076 -#ifdef CONFIG_X86_64
29077 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
29078 - NOSAVE_DATA
29079 - }
29080 -#endif
29081 -
29082 /* BSS */
29083 . = ALIGN(PAGE_SIZE);
29084 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
29085 @@ -320,6 +387,7 @@ SECTIONS
29086 __brk_base = .;
29087 . += 64 * 1024; /* 64k alignment slop space */
29088 *(.brk_reservation) /* areas brk users have reserved */
29089 + . = ALIGN(HPAGE_SIZE);
29090 __brk_limit = .;
29091 }
29092
29093 @@ -346,13 +414,12 @@ SECTIONS
29094 * for the boot processor.
29095 */
29096 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
29097 -INIT_PER_CPU(gdt_page);
29098 INIT_PER_CPU(irq_stack_union);
29099
29100 /*
29101 * Build-time check on the image size:
29102 */
29103 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
29104 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
29105 "kernel image bigger than KERNEL_IMAGE_SIZE");
29106
29107 #ifdef CONFIG_SMP
29108 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
29109 index e1e1e80..1400089 100644
29110 --- a/arch/x86/kernel/vsyscall_64.c
29111 +++ b/arch/x86/kernel/vsyscall_64.c
29112 @@ -54,15 +54,13 @@
29113
29114 DEFINE_VVAR(int, vgetcpu_mode);
29115
29116 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
29117 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
29118
29119 static int __init vsyscall_setup(char *str)
29120 {
29121 if (str) {
29122 if (!strcmp("emulate", str))
29123 vsyscall_mode = EMULATE;
29124 - else if (!strcmp("native", str))
29125 - vsyscall_mode = NATIVE;
29126 else if (!strcmp("none", str))
29127 vsyscall_mode = NONE;
29128 else
29129 @@ -279,8 +277,7 @@ do_ret:
29130 return true;
29131
29132 sigsegv:
29133 - force_sig(SIGSEGV, current);
29134 - return true;
29135 + do_group_exit(SIGKILL);
29136 }
29137
29138 /*
29139 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
29140 extern char __vsyscall_page;
29141 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
29142
29143 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
29144 - vsyscall_mode == NATIVE
29145 - ? PAGE_KERNEL_VSYSCALL
29146 - : PAGE_KERNEL_VVAR);
29147 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
29148 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
29149 (unsigned long)VSYSCALL_ADDR);
29150 }
29151 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
29152 index 04068192..4d75aa6 100644
29153 --- a/arch/x86/kernel/x8664_ksyms_64.c
29154 +++ b/arch/x86/kernel/x8664_ksyms_64.c
29155 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
29156 EXPORT_SYMBOL(copy_user_generic_unrolled);
29157 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
29158 EXPORT_SYMBOL(__copy_user_nocache);
29159 -EXPORT_SYMBOL(_copy_from_user);
29160 -EXPORT_SYMBOL(_copy_to_user);
29161
29162 EXPORT_SYMBOL(copy_page);
29163 EXPORT_SYMBOL(clear_page);
29164 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
29165 EXPORT_SYMBOL(___preempt_schedule_context);
29166 #endif
29167 #endif
29168 +
29169 +#ifdef CONFIG_PAX_PER_CPU_PGD
29170 +EXPORT_SYMBOL(cpu_pgd);
29171 +#endif
29172 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
29173 index e48b674..a451dd9 100644
29174 --- a/arch/x86/kernel/x86_init.c
29175 +++ b/arch/x86/kernel/x86_init.c
29176 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
29177 static void default_nmi_init(void) { };
29178 static int default_i8042_detect(void) { return 1; };
29179
29180 -struct x86_platform_ops x86_platform = {
29181 +struct x86_platform_ops x86_platform __read_only = {
29182 .calibrate_tsc = native_calibrate_tsc,
29183 .get_wallclock = mach_get_cmos_time,
29184 .set_wallclock = mach_set_rtc_mmss,
29185 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
29186 EXPORT_SYMBOL_GPL(x86_platform);
29187
29188 #if defined(CONFIG_PCI_MSI)
29189 -struct x86_msi_ops x86_msi = {
29190 +struct x86_msi_ops x86_msi __read_only = {
29191 .setup_msi_irqs = native_setup_msi_irqs,
29192 .compose_msi_msg = native_compose_msi_msg,
29193 .teardown_msi_irq = native_teardown_msi_irq,
29194 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
29195 }
29196 #endif
29197
29198 -struct x86_io_apic_ops x86_io_apic_ops = {
29199 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
29200 .init = native_io_apic_init_mappings,
29201 .read = native_io_apic_read,
29202 .write = native_io_apic_write,
29203 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
29204 index 4c540c4..0b985b0 100644
29205 --- a/arch/x86/kernel/xsave.c
29206 +++ b/arch/x86/kernel/xsave.c
29207 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29208
29209 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
29210 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
29211 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29212 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29213
29214 if (!use_xsave())
29215 return err;
29216
29217 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
29218 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
29219
29220 /*
29221 * Read the xstate_bv which we copied (directly from the cpu or
29222 * from the state in task struct) to the user buffers.
29223 */
29224 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29225 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29226
29227 /*
29228 * For legacy compatible, we always set FP/SSE bits in the bit
29229 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29230 */
29231 xstate_bv |= XSTATE_FPSSE;
29232
29233 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29234 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29235
29236 return err;
29237 }
29238 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
29239 {
29240 int err;
29241
29242 + buf = (struct xsave_struct __user *)____m(buf);
29243 if (use_xsave())
29244 err = xsave_user(buf);
29245 else if (use_fxsr())
29246 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
29247 */
29248 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
29249 {
29250 + buf = (void __user *)____m(buf);
29251 if (use_xsave()) {
29252 if ((unsigned long)buf % 64 || fx_only) {
29253 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
29254 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
29255 index 38a0afe..94421a9 100644
29256 --- a/arch/x86/kvm/cpuid.c
29257 +++ b/arch/x86/kvm/cpuid.c
29258 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
29259 struct kvm_cpuid2 *cpuid,
29260 struct kvm_cpuid_entry2 __user *entries)
29261 {
29262 - int r;
29263 + int r, i;
29264
29265 r = -E2BIG;
29266 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
29267 goto out;
29268 r = -EFAULT;
29269 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
29270 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29271 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29272 goto out;
29273 + for (i = 0; i < cpuid->nent; ++i) {
29274 + struct kvm_cpuid_entry2 cpuid_entry;
29275 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
29276 + goto out;
29277 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
29278 + }
29279 vcpu->arch.cpuid_nent = cpuid->nent;
29280 kvm_apic_set_version(vcpu);
29281 kvm_x86_ops->cpuid_update(vcpu);
29282 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
29283 struct kvm_cpuid2 *cpuid,
29284 struct kvm_cpuid_entry2 __user *entries)
29285 {
29286 - int r;
29287 + int r, i;
29288
29289 r = -E2BIG;
29290 if (cpuid->nent < vcpu->arch.cpuid_nent)
29291 goto out;
29292 r = -EFAULT;
29293 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
29294 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29295 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29296 goto out;
29297 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
29298 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
29299 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
29300 + goto out;
29301 + }
29302 return 0;
29303
29304 out:
29305 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29306 index 08e8a89..0e9183e 100644
29307 --- a/arch/x86/kvm/lapic.c
29308 +++ b/arch/x86/kvm/lapic.c
29309 @@ -55,7 +55,7 @@
29310 #define APIC_BUS_CYCLE_NS 1
29311
29312 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29313 -#define apic_debug(fmt, arg...)
29314 +#define apic_debug(fmt, arg...) do {} while (0)
29315
29316 #define APIC_LVT_NUM 6
29317 /* 14 is the version for Xeon and Pentium 8.4.8*/
29318 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29319 index 4107765..d9eb358 100644
29320 --- a/arch/x86/kvm/paging_tmpl.h
29321 +++ b/arch/x86/kvm/paging_tmpl.h
29322 @@ -331,7 +331,7 @@ retry_walk:
29323 if (unlikely(kvm_is_error_hva(host_addr)))
29324 goto error;
29325
29326 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29327 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29328 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29329 goto error;
29330 walker->ptep_user[walker->level - 1] = ptep_user;
29331 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29332 index 78dadc3..fd84599 100644
29333 --- a/arch/x86/kvm/svm.c
29334 +++ b/arch/x86/kvm/svm.c
29335 @@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29336 int cpu = raw_smp_processor_id();
29337
29338 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29339 +
29340 + pax_open_kernel();
29341 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29342 + pax_close_kernel();
29343 +
29344 load_TR_desc();
29345 }
29346
29347 @@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29348 #endif
29349 #endif
29350
29351 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29352 + __set_fs(current_thread_info()->addr_limit);
29353 +#endif
29354 +
29355 reload_tss(vcpu);
29356
29357 local_irq_disable();
29358 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29359 index 41a5426..c0b3c00 100644
29360 --- a/arch/x86/kvm/vmx.c
29361 +++ b/arch/x86/kvm/vmx.c
29362 @@ -1341,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29363 #endif
29364 }
29365
29366 -static void vmcs_clear_bits(unsigned long field, u32 mask)
29367 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29368 {
29369 vmcs_writel(field, vmcs_readl(field) & ~mask);
29370 }
29371
29372 -static void vmcs_set_bits(unsigned long field, u32 mask)
29373 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
29374 {
29375 vmcs_writel(field, vmcs_readl(field) | mask);
29376 }
29377 @@ -1606,7 +1606,11 @@ static void reload_tss(void)
29378 struct desc_struct *descs;
29379
29380 descs = (void *)gdt->address;
29381 +
29382 + pax_open_kernel();
29383 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29384 + pax_close_kernel();
29385 +
29386 load_TR_desc();
29387 }
29388
29389 @@ -1834,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29390 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29391 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29392
29393 +#ifdef CONFIG_PAX_PER_CPU_PGD
29394 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29395 +#endif
29396 +
29397 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29398 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29399 vmx->loaded_vmcs->cpu = cpu;
29400 @@ -2123,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29401 * reads and returns guest's timestamp counter "register"
29402 * guest_tsc = host_tsc + tsc_offset -- 21.3
29403 */
29404 -static u64 guest_read_tsc(void)
29405 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
29406 {
29407 u64 host_tsc, tsc_offset;
29408
29409 @@ -3114,8 +3122,11 @@ static __init int hardware_setup(void)
29410 if (!cpu_has_vmx_flexpriority())
29411 flexpriority_enabled = 0;
29412
29413 - if (!cpu_has_vmx_tpr_shadow())
29414 - kvm_x86_ops->update_cr8_intercept = NULL;
29415 + if (!cpu_has_vmx_tpr_shadow()) {
29416 + pax_open_kernel();
29417 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29418 + pax_close_kernel();
29419 + }
29420
29421 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29422 kvm_disable_largepages();
29423 @@ -3126,13 +3137,15 @@ static __init int hardware_setup(void)
29424 if (!cpu_has_vmx_apicv())
29425 enable_apicv = 0;
29426
29427 + pax_open_kernel();
29428 if (enable_apicv)
29429 - kvm_x86_ops->update_cr8_intercept = NULL;
29430 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29431 else {
29432 - kvm_x86_ops->hwapic_irr_update = NULL;
29433 - kvm_x86_ops->deliver_posted_interrupt = NULL;
29434 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29435 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29436 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29437 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29438 }
29439 + pax_close_kernel();
29440
29441 if (nested)
29442 nested_vmx_setup_ctls_msrs();
29443 @@ -4242,7 +4255,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29444 unsigned long cr4;
29445
29446 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29447 +
29448 +#ifndef CONFIG_PAX_PER_CPU_PGD
29449 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29450 +#endif
29451
29452 /* Save the most likely value for this task's CR4 in the VMCS. */
29453 cr4 = read_cr4();
29454 @@ -4269,7 +4285,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29455 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29456 vmx->host_idt_base = dt.address;
29457
29458 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29459 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29460
29461 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29462 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29463 @@ -7475,6 +7491,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29464 "jmp 2f \n\t"
29465 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29466 "2: "
29467 +
29468 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29469 + "ljmp %[cs],$3f\n\t"
29470 + "3: "
29471 +#endif
29472 +
29473 /* Save guest registers, load host registers, keep flags */
29474 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29475 "pop %0 \n\t"
29476 @@ -7527,6 +7549,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29477 #endif
29478 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29479 [wordsize]"i"(sizeof(ulong))
29480 +
29481 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29482 + ,[cs]"i"(__KERNEL_CS)
29483 +#endif
29484 +
29485 : "cc", "memory"
29486 #ifdef CONFIG_X86_64
29487 , "rax", "rbx", "rdi", "rsi"
29488 @@ -7540,7 +7567,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29489 if (debugctlmsr)
29490 update_debugctlmsr(debugctlmsr);
29491
29492 -#ifndef CONFIG_X86_64
29493 +#ifdef CONFIG_X86_32
29494 /*
29495 * The sysexit path does not restore ds/es, so we must set them to
29496 * a reasonable value ourselves.
29497 @@ -7549,8 +7576,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29498 * may be executed in interrupt context, which saves and restore segments
29499 * around it, nullifying its effect.
29500 */
29501 - loadsegment(ds, __USER_DS);
29502 - loadsegment(es, __USER_DS);
29503 + loadsegment(ds, __KERNEL_DS);
29504 + loadsegment(es, __KERNEL_DS);
29505 + loadsegment(ss, __KERNEL_DS);
29506 +
29507 +#ifdef CONFIG_PAX_KERNEXEC
29508 + loadsegment(fs, __KERNEL_PERCPU);
29509 +#endif
29510 +
29511 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29512 + __set_fs(current_thread_info()->addr_limit);
29513 +#endif
29514 +
29515 #endif
29516
29517 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29518 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29519 index d6aeccf..cea125a 100644
29520 --- a/arch/x86/kvm/x86.c
29521 +++ b/arch/x86/kvm/x86.c
29522 @@ -1857,8 +1857,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29523 {
29524 struct kvm *kvm = vcpu->kvm;
29525 int lm = is_long_mode(vcpu);
29526 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29527 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29528 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29529 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29530 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29531 : kvm->arch.xen_hvm_config.blob_size_32;
29532 u32 page_num = data & ~PAGE_MASK;
29533 @@ -2779,6 +2779,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29534 if (n < msr_list.nmsrs)
29535 goto out;
29536 r = -EFAULT;
29537 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29538 + goto out;
29539 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29540 num_msrs_to_save * sizeof(u32)))
29541 goto out;
29542 @@ -5639,7 +5641,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29543 };
29544 #endif
29545
29546 -int kvm_arch_init(void *opaque)
29547 +int kvm_arch_init(const void *opaque)
29548 {
29549 int r;
29550 struct kvm_x86_ops *ops = opaque;
29551 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29552 index aae9413..d11e829 100644
29553 --- a/arch/x86/lguest/boot.c
29554 +++ b/arch/x86/lguest/boot.c
29555 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29556 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29557 * Launcher to reboot us.
29558 */
29559 -static void lguest_restart(char *reason)
29560 +static __noreturn void lguest_restart(char *reason)
29561 {
29562 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29563 + BUG();
29564 }
29565
29566 /*G:050
29567 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29568 index 00933d5..3a64af9 100644
29569 --- a/arch/x86/lib/atomic64_386_32.S
29570 +++ b/arch/x86/lib/atomic64_386_32.S
29571 @@ -48,6 +48,10 @@ BEGIN(read)
29572 movl (v), %eax
29573 movl 4(v), %edx
29574 RET_ENDP
29575 +BEGIN(read_unchecked)
29576 + movl (v), %eax
29577 + movl 4(v), %edx
29578 +RET_ENDP
29579 #undef v
29580
29581 #define v %esi
29582 @@ -55,6 +59,10 @@ BEGIN(set)
29583 movl %ebx, (v)
29584 movl %ecx, 4(v)
29585 RET_ENDP
29586 +BEGIN(set_unchecked)
29587 + movl %ebx, (v)
29588 + movl %ecx, 4(v)
29589 +RET_ENDP
29590 #undef v
29591
29592 #define v %esi
29593 @@ -70,6 +78,20 @@ RET_ENDP
29594 BEGIN(add)
29595 addl %eax, (v)
29596 adcl %edx, 4(v)
29597 +
29598 +#ifdef CONFIG_PAX_REFCOUNT
29599 + jno 0f
29600 + subl %eax, (v)
29601 + sbbl %edx, 4(v)
29602 + int $4
29603 +0:
29604 + _ASM_EXTABLE(0b, 0b)
29605 +#endif
29606 +
29607 +RET_ENDP
29608 +BEGIN(add_unchecked)
29609 + addl %eax, (v)
29610 + adcl %edx, 4(v)
29611 RET_ENDP
29612 #undef v
29613
29614 @@ -77,6 +99,24 @@ RET_ENDP
29615 BEGIN(add_return)
29616 addl (v), %eax
29617 adcl 4(v), %edx
29618 +
29619 +#ifdef CONFIG_PAX_REFCOUNT
29620 + into
29621 +1234:
29622 + _ASM_EXTABLE(1234b, 2f)
29623 +#endif
29624 +
29625 + movl %eax, (v)
29626 + movl %edx, 4(v)
29627 +
29628 +#ifdef CONFIG_PAX_REFCOUNT
29629 +2:
29630 +#endif
29631 +
29632 +RET_ENDP
29633 +BEGIN(add_return_unchecked)
29634 + addl (v), %eax
29635 + adcl 4(v), %edx
29636 movl %eax, (v)
29637 movl %edx, 4(v)
29638 RET_ENDP
29639 @@ -86,6 +126,20 @@ RET_ENDP
29640 BEGIN(sub)
29641 subl %eax, (v)
29642 sbbl %edx, 4(v)
29643 +
29644 +#ifdef CONFIG_PAX_REFCOUNT
29645 + jno 0f
29646 + addl %eax, (v)
29647 + adcl %edx, 4(v)
29648 + int $4
29649 +0:
29650 + _ASM_EXTABLE(0b, 0b)
29651 +#endif
29652 +
29653 +RET_ENDP
29654 +BEGIN(sub_unchecked)
29655 + subl %eax, (v)
29656 + sbbl %edx, 4(v)
29657 RET_ENDP
29658 #undef v
29659
29660 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29661 sbbl $0, %edx
29662 addl (v), %eax
29663 adcl 4(v), %edx
29664 +
29665 +#ifdef CONFIG_PAX_REFCOUNT
29666 + into
29667 +1234:
29668 + _ASM_EXTABLE(1234b, 2f)
29669 +#endif
29670 +
29671 + movl %eax, (v)
29672 + movl %edx, 4(v)
29673 +
29674 +#ifdef CONFIG_PAX_REFCOUNT
29675 +2:
29676 +#endif
29677 +
29678 +RET_ENDP
29679 +BEGIN(sub_return_unchecked)
29680 + negl %edx
29681 + negl %eax
29682 + sbbl $0, %edx
29683 + addl (v), %eax
29684 + adcl 4(v), %edx
29685 movl %eax, (v)
29686 movl %edx, 4(v)
29687 RET_ENDP
29688 @@ -105,6 +180,20 @@ RET_ENDP
29689 BEGIN(inc)
29690 addl $1, (v)
29691 adcl $0, 4(v)
29692 +
29693 +#ifdef CONFIG_PAX_REFCOUNT
29694 + jno 0f
29695 + subl $1, (v)
29696 + sbbl $0, 4(v)
29697 + int $4
29698 +0:
29699 + _ASM_EXTABLE(0b, 0b)
29700 +#endif
29701 +
29702 +RET_ENDP
29703 +BEGIN(inc_unchecked)
29704 + addl $1, (v)
29705 + adcl $0, 4(v)
29706 RET_ENDP
29707 #undef v
29708
29709 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29710 movl 4(v), %edx
29711 addl $1, %eax
29712 adcl $0, %edx
29713 +
29714 +#ifdef CONFIG_PAX_REFCOUNT
29715 + into
29716 +1234:
29717 + _ASM_EXTABLE(1234b, 2f)
29718 +#endif
29719 +
29720 + movl %eax, (v)
29721 + movl %edx, 4(v)
29722 +
29723 +#ifdef CONFIG_PAX_REFCOUNT
29724 +2:
29725 +#endif
29726 +
29727 +RET_ENDP
29728 +BEGIN(inc_return_unchecked)
29729 + movl (v), %eax
29730 + movl 4(v), %edx
29731 + addl $1, %eax
29732 + adcl $0, %edx
29733 movl %eax, (v)
29734 movl %edx, 4(v)
29735 RET_ENDP
29736 @@ -123,6 +232,20 @@ RET_ENDP
29737 BEGIN(dec)
29738 subl $1, (v)
29739 sbbl $0, 4(v)
29740 +
29741 +#ifdef CONFIG_PAX_REFCOUNT
29742 + jno 0f
29743 + addl $1, (v)
29744 + adcl $0, 4(v)
29745 + int $4
29746 +0:
29747 + _ASM_EXTABLE(0b, 0b)
29748 +#endif
29749 +
29750 +RET_ENDP
29751 +BEGIN(dec_unchecked)
29752 + subl $1, (v)
29753 + sbbl $0, 4(v)
29754 RET_ENDP
29755 #undef v
29756
29757 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29758 movl 4(v), %edx
29759 subl $1, %eax
29760 sbbl $0, %edx
29761 +
29762 +#ifdef CONFIG_PAX_REFCOUNT
29763 + into
29764 +1234:
29765 + _ASM_EXTABLE(1234b, 2f)
29766 +#endif
29767 +
29768 + movl %eax, (v)
29769 + movl %edx, 4(v)
29770 +
29771 +#ifdef CONFIG_PAX_REFCOUNT
29772 +2:
29773 +#endif
29774 +
29775 +RET_ENDP
29776 +BEGIN(dec_return_unchecked)
29777 + movl (v), %eax
29778 + movl 4(v), %edx
29779 + subl $1, %eax
29780 + sbbl $0, %edx
29781 movl %eax, (v)
29782 movl %edx, 4(v)
29783 RET_ENDP
29784 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29785 adcl %edx, %edi
29786 addl (v), %eax
29787 adcl 4(v), %edx
29788 +
29789 +#ifdef CONFIG_PAX_REFCOUNT
29790 + into
29791 +1234:
29792 + _ASM_EXTABLE(1234b, 2f)
29793 +#endif
29794 +
29795 cmpl %eax, %ecx
29796 je 3f
29797 1:
29798 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29799 1:
29800 addl $1, %eax
29801 adcl $0, %edx
29802 +
29803 +#ifdef CONFIG_PAX_REFCOUNT
29804 + into
29805 +1234:
29806 + _ASM_EXTABLE(1234b, 2f)
29807 +#endif
29808 +
29809 movl %eax, (v)
29810 movl %edx, 4(v)
29811 movl $1, %eax
29812 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29813 movl 4(v), %edx
29814 subl $1, %eax
29815 sbbl $0, %edx
29816 +
29817 +#ifdef CONFIG_PAX_REFCOUNT
29818 + into
29819 +1234:
29820 + _ASM_EXTABLE(1234b, 1f)
29821 +#endif
29822 +
29823 js 1f
29824 movl %eax, (v)
29825 movl %edx, 4(v)
29826 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29827 index f5cc9eb..51fa319 100644
29828 --- a/arch/x86/lib/atomic64_cx8_32.S
29829 +++ b/arch/x86/lib/atomic64_cx8_32.S
29830 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29831 CFI_STARTPROC
29832
29833 read64 %ecx
29834 + pax_force_retaddr
29835 ret
29836 CFI_ENDPROC
29837 ENDPROC(atomic64_read_cx8)
29838
29839 +ENTRY(atomic64_read_unchecked_cx8)
29840 + CFI_STARTPROC
29841 +
29842 + read64 %ecx
29843 + pax_force_retaddr
29844 + ret
29845 + CFI_ENDPROC
29846 +ENDPROC(atomic64_read_unchecked_cx8)
29847 +
29848 ENTRY(atomic64_set_cx8)
29849 CFI_STARTPROC
29850
29851 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29852 cmpxchg8b (%esi)
29853 jne 1b
29854
29855 + pax_force_retaddr
29856 ret
29857 CFI_ENDPROC
29858 ENDPROC(atomic64_set_cx8)
29859
29860 +ENTRY(atomic64_set_unchecked_cx8)
29861 + CFI_STARTPROC
29862 +
29863 +1:
29864 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29865 + * are atomic on 586 and newer */
29866 + cmpxchg8b (%esi)
29867 + jne 1b
29868 +
29869 + pax_force_retaddr
29870 + ret
29871 + CFI_ENDPROC
29872 +ENDPROC(atomic64_set_unchecked_cx8)
29873 +
29874 ENTRY(atomic64_xchg_cx8)
29875 CFI_STARTPROC
29876
29877 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29878 cmpxchg8b (%esi)
29879 jne 1b
29880
29881 + pax_force_retaddr
29882 ret
29883 CFI_ENDPROC
29884 ENDPROC(atomic64_xchg_cx8)
29885
29886 -.macro addsub_return func ins insc
29887 -ENTRY(atomic64_\func\()_return_cx8)
29888 +.macro addsub_return func ins insc unchecked=""
29889 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29890 CFI_STARTPROC
29891 SAVE ebp
29892 SAVE ebx
29893 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29894 movl %edx, %ecx
29895 \ins\()l %esi, %ebx
29896 \insc\()l %edi, %ecx
29897 +
29898 +.ifb \unchecked
29899 +#ifdef CONFIG_PAX_REFCOUNT
29900 + into
29901 +2:
29902 + _ASM_EXTABLE(2b, 3f)
29903 +#endif
29904 +.endif
29905 +
29906 LOCK_PREFIX
29907 cmpxchg8b (%ebp)
29908 jne 1b
29909 -
29910 -10:
29911 movl %ebx, %eax
29912 movl %ecx, %edx
29913 +
29914 +.ifb \unchecked
29915 +#ifdef CONFIG_PAX_REFCOUNT
29916 +3:
29917 +#endif
29918 +.endif
29919 +
29920 RESTORE edi
29921 RESTORE esi
29922 RESTORE ebx
29923 RESTORE ebp
29924 + pax_force_retaddr
29925 ret
29926 CFI_ENDPROC
29927 -ENDPROC(atomic64_\func\()_return_cx8)
29928 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29929 .endm
29930
29931 addsub_return add add adc
29932 addsub_return sub sub sbb
29933 +addsub_return add add adc _unchecked
29934 +addsub_return sub sub sbb _unchecked
29935
29936 -.macro incdec_return func ins insc
29937 -ENTRY(atomic64_\func\()_return_cx8)
29938 +.macro incdec_return func ins insc unchecked=""
29939 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29940 CFI_STARTPROC
29941 SAVE ebx
29942
29943 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29944 movl %edx, %ecx
29945 \ins\()l $1, %ebx
29946 \insc\()l $0, %ecx
29947 +
29948 +.ifb \unchecked
29949 +#ifdef CONFIG_PAX_REFCOUNT
29950 + into
29951 +2:
29952 + _ASM_EXTABLE(2b, 3f)
29953 +#endif
29954 +.endif
29955 +
29956 LOCK_PREFIX
29957 cmpxchg8b (%esi)
29958 jne 1b
29959
29960 -10:
29961 movl %ebx, %eax
29962 movl %ecx, %edx
29963 +
29964 +.ifb \unchecked
29965 +#ifdef CONFIG_PAX_REFCOUNT
29966 +3:
29967 +#endif
29968 +.endif
29969 +
29970 RESTORE ebx
29971 + pax_force_retaddr
29972 ret
29973 CFI_ENDPROC
29974 -ENDPROC(atomic64_\func\()_return_cx8)
29975 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29976 .endm
29977
29978 incdec_return inc add adc
29979 incdec_return dec sub sbb
29980 +incdec_return inc add adc _unchecked
29981 +incdec_return dec sub sbb _unchecked
29982
29983 ENTRY(atomic64_dec_if_positive_cx8)
29984 CFI_STARTPROC
29985 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29986 movl %edx, %ecx
29987 subl $1, %ebx
29988 sbb $0, %ecx
29989 +
29990 +#ifdef CONFIG_PAX_REFCOUNT
29991 + into
29992 +1234:
29993 + _ASM_EXTABLE(1234b, 2f)
29994 +#endif
29995 +
29996 js 2f
29997 LOCK_PREFIX
29998 cmpxchg8b (%esi)
29999 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
30000 movl %ebx, %eax
30001 movl %ecx, %edx
30002 RESTORE ebx
30003 + pax_force_retaddr
30004 ret
30005 CFI_ENDPROC
30006 ENDPROC(atomic64_dec_if_positive_cx8)
30007 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30008 movl %edx, %ecx
30009 addl %ebp, %ebx
30010 adcl %edi, %ecx
30011 +
30012 +#ifdef CONFIG_PAX_REFCOUNT
30013 + into
30014 +1234:
30015 + _ASM_EXTABLE(1234b, 3f)
30016 +#endif
30017 +
30018 LOCK_PREFIX
30019 cmpxchg8b (%esi)
30020 jne 1b
30021 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30022 CFI_ADJUST_CFA_OFFSET -8
30023 RESTORE ebx
30024 RESTORE ebp
30025 + pax_force_retaddr
30026 ret
30027 4:
30028 cmpl %edx, 4(%esp)
30029 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30030 xorl %ecx, %ecx
30031 addl $1, %ebx
30032 adcl %edx, %ecx
30033 +
30034 +#ifdef CONFIG_PAX_REFCOUNT
30035 + into
30036 +1234:
30037 + _ASM_EXTABLE(1234b, 3f)
30038 +#endif
30039 +
30040 LOCK_PREFIX
30041 cmpxchg8b (%esi)
30042 jne 1b
30043 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30044 movl $1, %eax
30045 3:
30046 RESTORE ebx
30047 + pax_force_retaddr
30048 ret
30049 CFI_ENDPROC
30050 ENDPROC(atomic64_inc_not_zero_cx8)
30051 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30052 index e78b8eee..7e173a8 100644
30053 --- a/arch/x86/lib/checksum_32.S
30054 +++ b/arch/x86/lib/checksum_32.S
30055 @@ -29,7 +29,8 @@
30056 #include <asm/dwarf2.h>
30057 #include <asm/errno.h>
30058 #include <asm/asm.h>
30059 -
30060 +#include <asm/segment.h>
30061 +
30062 /*
30063 * computes a partial checksum, e.g. for TCP/UDP fragments
30064 */
30065 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30066
30067 #define ARGBASE 16
30068 #define FP 12
30069 -
30070 -ENTRY(csum_partial_copy_generic)
30071 +
30072 +ENTRY(csum_partial_copy_generic_to_user)
30073 CFI_STARTPROC
30074 +
30075 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30076 + pushl_cfi %gs
30077 + popl_cfi %es
30078 + jmp csum_partial_copy_generic
30079 +#endif
30080 +
30081 +ENTRY(csum_partial_copy_generic_from_user)
30082 +
30083 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30084 + pushl_cfi %gs
30085 + popl_cfi %ds
30086 +#endif
30087 +
30088 +ENTRY(csum_partial_copy_generic)
30089 subl $4,%esp
30090 CFI_ADJUST_CFA_OFFSET 4
30091 pushl_cfi %edi
30092 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30093 jmp 4f
30094 SRC(1: movw (%esi), %bx )
30095 addl $2, %esi
30096 -DST( movw %bx, (%edi) )
30097 +DST( movw %bx, %es:(%edi) )
30098 addl $2, %edi
30099 addw %bx, %ax
30100 adcl $0, %eax
30101 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30102 SRC(1: movl (%esi), %ebx )
30103 SRC( movl 4(%esi), %edx )
30104 adcl %ebx, %eax
30105 -DST( movl %ebx, (%edi) )
30106 +DST( movl %ebx, %es:(%edi) )
30107 adcl %edx, %eax
30108 -DST( movl %edx, 4(%edi) )
30109 +DST( movl %edx, %es:4(%edi) )
30110
30111 SRC( movl 8(%esi), %ebx )
30112 SRC( movl 12(%esi), %edx )
30113 adcl %ebx, %eax
30114 -DST( movl %ebx, 8(%edi) )
30115 +DST( movl %ebx, %es:8(%edi) )
30116 adcl %edx, %eax
30117 -DST( movl %edx, 12(%edi) )
30118 +DST( movl %edx, %es:12(%edi) )
30119
30120 SRC( movl 16(%esi), %ebx )
30121 SRC( movl 20(%esi), %edx )
30122 adcl %ebx, %eax
30123 -DST( movl %ebx, 16(%edi) )
30124 +DST( movl %ebx, %es:16(%edi) )
30125 adcl %edx, %eax
30126 -DST( movl %edx, 20(%edi) )
30127 +DST( movl %edx, %es:20(%edi) )
30128
30129 SRC( movl 24(%esi), %ebx )
30130 SRC( movl 28(%esi), %edx )
30131 adcl %ebx, %eax
30132 -DST( movl %ebx, 24(%edi) )
30133 +DST( movl %ebx, %es:24(%edi) )
30134 adcl %edx, %eax
30135 -DST( movl %edx, 28(%edi) )
30136 +DST( movl %edx, %es:28(%edi) )
30137
30138 lea 32(%esi), %esi
30139 lea 32(%edi), %edi
30140 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30141 shrl $2, %edx # This clears CF
30142 SRC(3: movl (%esi), %ebx )
30143 adcl %ebx, %eax
30144 -DST( movl %ebx, (%edi) )
30145 +DST( movl %ebx, %es:(%edi) )
30146 lea 4(%esi), %esi
30147 lea 4(%edi), %edi
30148 dec %edx
30149 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30150 jb 5f
30151 SRC( movw (%esi), %cx )
30152 leal 2(%esi), %esi
30153 -DST( movw %cx, (%edi) )
30154 +DST( movw %cx, %es:(%edi) )
30155 leal 2(%edi), %edi
30156 je 6f
30157 shll $16,%ecx
30158 SRC(5: movb (%esi), %cl )
30159 -DST( movb %cl, (%edi) )
30160 +DST( movb %cl, %es:(%edi) )
30161 6: addl %ecx, %eax
30162 adcl $0, %eax
30163 7:
30164 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30165
30166 6001:
30167 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30168 - movl $-EFAULT, (%ebx)
30169 + movl $-EFAULT, %ss:(%ebx)
30170
30171 # zero the complete destination - computing the rest
30172 # is too much work
30173 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30174
30175 6002:
30176 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30177 - movl $-EFAULT,(%ebx)
30178 + movl $-EFAULT,%ss:(%ebx)
30179 jmp 5000b
30180
30181 .previous
30182
30183 + pushl_cfi %ss
30184 + popl_cfi %ds
30185 + pushl_cfi %ss
30186 + popl_cfi %es
30187 popl_cfi %ebx
30188 CFI_RESTORE ebx
30189 popl_cfi %esi
30190 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30191 popl_cfi %ecx # equivalent to addl $4,%esp
30192 ret
30193 CFI_ENDPROC
30194 -ENDPROC(csum_partial_copy_generic)
30195 +ENDPROC(csum_partial_copy_generic_to_user)
30196
30197 #else
30198
30199 /* Version for PentiumII/PPro */
30200
30201 #define ROUND1(x) \
30202 + nop; nop; nop; \
30203 SRC(movl x(%esi), %ebx ) ; \
30204 addl %ebx, %eax ; \
30205 - DST(movl %ebx, x(%edi) ) ;
30206 + DST(movl %ebx, %es:x(%edi)) ;
30207
30208 #define ROUND(x) \
30209 + nop; nop; nop; \
30210 SRC(movl x(%esi), %ebx ) ; \
30211 adcl %ebx, %eax ; \
30212 - DST(movl %ebx, x(%edi) ) ;
30213 + DST(movl %ebx, %es:x(%edi)) ;
30214
30215 #define ARGBASE 12
30216 -
30217 -ENTRY(csum_partial_copy_generic)
30218 +
30219 +ENTRY(csum_partial_copy_generic_to_user)
30220 CFI_STARTPROC
30221 +
30222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30223 + pushl_cfi %gs
30224 + popl_cfi %es
30225 + jmp csum_partial_copy_generic
30226 +#endif
30227 +
30228 +ENTRY(csum_partial_copy_generic_from_user)
30229 +
30230 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30231 + pushl_cfi %gs
30232 + popl_cfi %ds
30233 +#endif
30234 +
30235 +ENTRY(csum_partial_copy_generic)
30236 pushl_cfi %ebx
30237 CFI_REL_OFFSET ebx, 0
30238 pushl_cfi %edi
30239 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30240 subl %ebx, %edi
30241 lea -1(%esi),%edx
30242 andl $-32,%edx
30243 - lea 3f(%ebx,%ebx), %ebx
30244 + lea 3f(%ebx,%ebx,2), %ebx
30245 testl %esi, %esi
30246 jmp *%ebx
30247 1: addl $64,%esi
30248 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30249 jb 5f
30250 SRC( movw (%esi), %dx )
30251 leal 2(%esi), %esi
30252 -DST( movw %dx, (%edi) )
30253 +DST( movw %dx, %es:(%edi) )
30254 leal 2(%edi), %edi
30255 je 6f
30256 shll $16,%edx
30257 5:
30258 SRC( movb (%esi), %dl )
30259 -DST( movb %dl, (%edi) )
30260 +DST( movb %dl, %es:(%edi) )
30261 6: addl %edx, %eax
30262 adcl $0, %eax
30263 7:
30264 .section .fixup, "ax"
30265 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30266 - movl $-EFAULT, (%ebx)
30267 + movl $-EFAULT, %ss:(%ebx)
30268 # zero the complete destination (computing the rest is too much work)
30269 movl ARGBASE+8(%esp),%edi # dst
30270 movl ARGBASE+12(%esp),%ecx # len
30271 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30272 rep; stosb
30273 jmp 7b
30274 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30275 - movl $-EFAULT, (%ebx)
30276 + movl $-EFAULT, %ss:(%ebx)
30277 jmp 7b
30278 .previous
30279
30280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30281 + pushl_cfi %ss
30282 + popl_cfi %ds
30283 + pushl_cfi %ss
30284 + popl_cfi %es
30285 +#endif
30286 +
30287 popl_cfi %esi
30288 CFI_RESTORE esi
30289 popl_cfi %edi
30290 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30291 CFI_RESTORE ebx
30292 ret
30293 CFI_ENDPROC
30294 -ENDPROC(csum_partial_copy_generic)
30295 +ENDPROC(csum_partial_copy_generic_to_user)
30296
30297 #undef ROUND
30298 #undef ROUND1
30299 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30300 index f2145cf..cea889d 100644
30301 --- a/arch/x86/lib/clear_page_64.S
30302 +++ b/arch/x86/lib/clear_page_64.S
30303 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30304 movl $4096/8,%ecx
30305 xorl %eax,%eax
30306 rep stosq
30307 + pax_force_retaddr
30308 ret
30309 CFI_ENDPROC
30310 ENDPROC(clear_page_c)
30311 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30312 movl $4096,%ecx
30313 xorl %eax,%eax
30314 rep stosb
30315 + pax_force_retaddr
30316 ret
30317 CFI_ENDPROC
30318 ENDPROC(clear_page_c_e)
30319 @@ -43,6 +45,7 @@ ENTRY(clear_page)
30320 leaq 64(%rdi),%rdi
30321 jnz .Lloop
30322 nop
30323 + pax_force_retaddr
30324 ret
30325 CFI_ENDPROC
30326 .Lclear_page_end:
30327 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
30328
30329 #include <asm/cpufeature.h>
30330
30331 - .section .altinstr_replacement,"ax"
30332 + .section .altinstr_replacement,"a"
30333 1: .byte 0xeb /* jmp <disp8> */
30334 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30335 2: .byte 0xeb /* jmp <disp8> */
30336 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30337 index 1e572c5..2a162cd 100644
30338 --- a/arch/x86/lib/cmpxchg16b_emu.S
30339 +++ b/arch/x86/lib/cmpxchg16b_emu.S
30340 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30341
30342 popf
30343 mov $1, %al
30344 + pax_force_retaddr
30345 ret
30346
30347 not_same:
30348 popf
30349 xor %al,%al
30350 + pax_force_retaddr
30351 ret
30352
30353 CFI_ENDPROC
30354 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30355 index 176cca6..e0d658e 100644
30356 --- a/arch/x86/lib/copy_page_64.S
30357 +++ b/arch/x86/lib/copy_page_64.S
30358 @@ -9,6 +9,7 @@ copy_page_rep:
30359 CFI_STARTPROC
30360 movl $4096/8, %ecx
30361 rep movsq
30362 + pax_force_retaddr
30363 ret
30364 CFI_ENDPROC
30365 ENDPROC(copy_page_rep)
30366 @@ -24,8 +25,8 @@ ENTRY(copy_page)
30367 CFI_ADJUST_CFA_OFFSET 2*8
30368 movq %rbx, (%rsp)
30369 CFI_REL_OFFSET rbx, 0
30370 - movq %r12, 1*8(%rsp)
30371 - CFI_REL_OFFSET r12, 1*8
30372 + movq %r13, 1*8(%rsp)
30373 + CFI_REL_OFFSET r13, 1*8
30374
30375 movl $(4096/64)-5, %ecx
30376 .p2align 4
30377 @@ -38,7 +39,7 @@ ENTRY(copy_page)
30378 movq 0x8*4(%rsi), %r9
30379 movq 0x8*5(%rsi), %r10
30380 movq 0x8*6(%rsi), %r11
30381 - movq 0x8*7(%rsi), %r12
30382 + movq 0x8*7(%rsi), %r13
30383
30384 prefetcht0 5*64(%rsi)
30385
30386 @@ -49,7 +50,7 @@ ENTRY(copy_page)
30387 movq %r9, 0x8*4(%rdi)
30388 movq %r10, 0x8*5(%rdi)
30389 movq %r11, 0x8*6(%rdi)
30390 - movq %r12, 0x8*7(%rdi)
30391 + movq %r13, 0x8*7(%rdi)
30392
30393 leaq 64 (%rsi), %rsi
30394 leaq 64 (%rdi), %rdi
30395 @@ -68,7 +69,7 @@ ENTRY(copy_page)
30396 movq 0x8*4(%rsi), %r9
30397 movq 0x8*5(%rsi), %r10
30398 movq 0x8*6(%rsi), %r11
30399 - movq 0x8*7(%rsi), %r12
30400 + movq 0x8*7(%rsi), %r13
30401
30402 movq %rax, 0x8*0(%rdi)
30403 movq %rbx, 0x8*1(%rdi)
30404 @@ -77,7 +78,7 @@ ENTRY(copy_page)
30405 movq %r9, 0x8*4(%rdi)
30406 movq %r10, 0x8*5(%rdi)
30407 movq %r11, 0x8*6(%rdi)
30408 - movq %r12, 0x8*7(%rdi)
30409 + movq %r13, 0x8*7(%rdi)
30410
30411 leaq 64(%rdi), %rdi
30412 leaq 64(%rsi), %rsi
30413 @@ -85,10 +86,11 @@ ENTRY(copy_page)
30414
30415 movq (%rsp), %rbx
30416 CFI_RESTORE rbx
30417 - movq 1*8(%rsp), %r12
30418 - CFI_RESTORE r12
30419 + movq 1*8(%rsp), %r13
30420 + CFI_RESTORE r13
30421 addq $2*8, %rsp
30422 CFI_ADJUST_CFA_OFFSET -2*8
30423 + pax_force_retaddr
30424 ret
30425 .Lcopy_page_end:
30426 CFI_ENDPROC
30427 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
30428
30429 #include <asm/cpufeature.h>
30430
30431 - .section .altinstr_replacement,"ax"
30432 + .section .altinstr_replacement,"a"
30433 1: .byte 0xeb /* jmp <disp8> */
30434 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30435 2:
30436 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30437 index dee945d..a84067b 100644
30438 --- a/arch/x86/lib/copy_user_64.S
30439 +++ b/arch/x86/lib/copy_user_64.S
30440 @@ -18,31 +18,7 @@
30441 #include <asm/alternative-asm.h>
30442 #include <asm/asm.h>
30443 #include <asm/smap.h>
30444 -
30445 -/*
30446 - * By placing feature2 after feature1 in altinstructions section, we logically
30447 - * implement:
30448 - * If CPU has feature2, jmp to alt2 is used
30449 - * else if CPU has feature1, jmp to alt1 is used
30450 - * else jmp to orig is used.
30451 - */
30452 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30453 -0:
30454 - .byte 0xe9 /* 32bit jump */
30455 - .long \orig-1f /* by default jump to orig */
30456 -1:
30457 - .section .altinstr_replacement,"ax"
30458 -2: .byte 0xe9 /* near jump with 32bit immediate */
30459 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30460 -3: .byte 0xe9 /* near jump with 32bit immediate */
30461 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30462 - .previous
30463 -
30464 - .section .altinstructions,"a"
30465 - altinstruction_entry 0b,2b,\feature1,5,5
30466 - altinstruction_entry 0b,3b,\feature2,5,5
30467 - .previous
30468 - .endm
30469 +#include <asm/pgtable.h>
30470
30471 .macro ALIGN_DESTINATION
30472 #ifdef FIX_ALIGNMENT
30473 @@ -70,52 +46,6 @@
30474 #endif
30475 .endm
30476
30477 -/* Standard copy_to_user with segment limit checking */
30478 -ENTRY(_copy_to_user)
30479 - CFI_STARTPROC
30480 - GET_THREAD_INFO(%rax)
30481 - movq %rdi,%rcx
30482 - addq %rdx,%rcx
30483 - jc bad_to_user
30484 - cmpq TI_addr_limit(%rax),%rcx
30485 - ja bad_to_user
30486 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30487 - copy_user_generic_unrolled,copy_user_generic_string, \
30488 - copy_user_enhanced_fast_string
30489 - CFI_ENDPROC
30490 -ENDPROC(_copy_to_user)
30491 -
30492 -/* Standard copy_from_user with segment limit checking */
30493 -ENTRY(_copy_from_user)
30494 - CFI_STARTPROC
30495 - GET_THREAD_INFO(%rax)
30496 - movq %rsi,%rcx
30497 - addq %rdx,%rcx
30498 - jc bad_from_user
30499 - cmpq TI_addr_limit(%rax),%rcx
30500 - ja bad_from_user
30501 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30502 - copy_user_generic_unrolled,copy_user_generic_string, \
30503 - copy_user_enhanced_fast_string
30504 - CFI_ENDPROC
30505 -ENDPROC(_copy_from_user)
30506 -
30507 - .section .fixup,"ax"
30508 - /* must zero dest */
30509 -ENTRY(bad_from_user)
30510 -bad_from_user:
30511 - CFI_STARTPROC
30512 - movl %edx,%ecx
30513 - xorl %eax,%eax
30514 - rep
30515 - stosb
30516 -bad_to_user:
30517 - movl %edx,%eax
30518 - ret
30519 - CFI_ENDPROC
30520 -ENDPROC(bad_from_user)
30521 - .previous
30522 -
30523 /*
30524 * copy_user_generic_unrolled - memory copy with exception handling.
30525 * This version is for CPUs like P4 that don't have efficient micro
30526 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30527 */
30528 ENTRY(copy_user_generic_unrolled)
30529 CFI_STARTPROC
30530 + ASM_PAX_OPEN_USERLAND
30531 ASM_STAC
30532 cmpl $8,%edx
30533 jb 20f /* less then 8 bytes, go to byte copy loop */
30534 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30535 jnz 21b
30536 23: xor %eax,%eax
30537 ASM_CLAC
30538 + ASM_PAX_CLOSE_USERLAND
30539 + pax_force_retaddr
30540 ret
30541
30542 .section .fixup,"ax"
30543 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30544 */
30545 ENTRY(copy_user_generic_string)
30546 CFI_STARTPROC
30547 + ASM_PAX_OPEN_USERLAND
30548 ASM_STAC
30549 cmpl $8,%edx
30550 jb 2f /* less than 8 bytes, go to byte copy loop */
30551 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30552 movsb
30553 xorl %eax,%eax
30554 ASM_CLAC
30555 + ASM_PAX_CLOSE_USERLAND
30556 + pax_force_retaddr
30557 ret
30558
30559 .section .fixup,"ax"
30560 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30561 */
30562 ENTRY(copy_user_enhanced_fast_string)
30563 CFI_STARTPROC
30564 + ASM_PAX_OPEN_USERLAND
30565 ASM_STAC
30566 movl %edx,%ecx
30567 1: rep
30568 movsb
30569 xorl %eax,%eax
30570 ASM_CLAC
30571 + ASM_PAX_CLOSE_USERLAND
30572 + pax_force_retaddr
30573 ret
30574
30575 .section .fixup,"ax"
30576 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30577 index 6a4f43c..c70fb52 100644
30578 --- a/arch/x86/lib/copy_user_nocache_64.S
30579 +++ b/arch/x86/lib/copy_user_nocache_64.S
30580 @@ -8,6 +8,7 @@
30581
30582 #include <linux/linkage.h>
30583 #include <asm/dwarf2.h>
30584 +#include <asm/alternative-asm.h>
30585
30586 #define FIX_ALIGNMENT 1
30587
30588 @@ -16,6 +17,7 @@
30589 #include <asm/thread_info.h>
30590 #include <asm/asm.h>
30591 #include <asm/smap.h>
30592 +#include <asm/pgtable.h>
30593
30594 .macro ALIGN_DESTINATION
30595 #ifdef FIX_ALIGNMENT
30596 @@ -49,6 +51,16 @@
30597 */
30598 ENTRY(__copy_user_nocache)
30599 CFI_STARTPROC
30600 +
30601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30602 + mov pax_user_shadow_base,%rcx
30603 + cmp %rcx,%rsi
30604 + jae 1f
30605 + add %rcx,%rsi
30606 +1:
30607 +#endif
30608 +
30609 + ASM_PAX_OPEN_USERLAND
30610 ASM_STAC
30611 cmpl $8,%edx
30612 jb 20f /* less then 8 bytes, go to byte copy loop */
30613 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30614 jnz 21b
30615 23: xorl %eax,%eax
30616 ASM_CLAC
30617 + ASM_PAX_CLOSE_USERLAND
30618 sfence
30619 + pax_force_retaddr
30620 ret
30621
30622 .section .fixup,"ax"
30623 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30624 index 2419d5f..fe52d0e 100644
30625 --- a/arch/x86/lib/csum-copy_64.S
30626 +++ b/arch/x86/lib/csum-copy_64.S
30627 @@ -9,6 +9,7 @@
30628 #include <asm/dwarf2.h>
30629 #include <asm/errno.h>
30630 #include <asm/asm.h>
30631 +#include <asm/alternative-asm.h>
30632
30633 /*
30634 * Checksum copy with exception handling.
30635 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30636 CFI_ADJUST_CFA_OFFSET 7*8
30637 movq %rbx, 2*8(%rsp)
30638 CFI_REL_OFFSET rbx, 2*8
30639 - movq %r12, 3*8(%rsp)
30640 - CFI_REL_OFFSET r12, 3*8
30641 + movq %r15, 3*8(%rsp)
30642 + CFI_REL_OFFSET r15, 3*8
30643 movq %r14, 4*8(%rsp)
30644 CFI_REL_OFFSET r14, 4*8
30645 movq %r13, 5*8(%rsp)
30646 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30647 movl %edx, %ecx
30648
30649 xorl %r9d, %r9d
30650 - movq %rcx, %r12
30651 + movq %rcx, %r15
30652
30653 - shrq $6, %r12
30654 + shrq $6, %r15
30655 jz .Lhandle_tail /* < 64 */
30656
30657 clc
30658
30659 /* main loop. clear in 64 byte blocks */
30660 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30661 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30662 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30663 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30664 .p2align 4
30665 .Lloop:
30666 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30667 adcq %r14, %rax
30668 adcq %r13, %rax
30669
30670 - decl %r12d
30671 + decl %r15d
30672
30673 dest
30674 movq %rbx, (%rsi)
30675 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30676 .Lende:
30677 movq 2*8(%rsp), %rbx
30678 CFI_RESTORE rbx
30679 - movq 3*8(%rsp), %r12
30680 - CFI_RESTORE r12
30681 + movq 3*8(%rsp), %r15
30682 + CFI_RESTORE r15
30683 movq 4*8(%rsp), %r14
30684 CFI_RESTORE r14
30685 movq 5*8(%rsp), %r13
30686 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30687 CFI_RESTORE rbp
30688 addq $7*8, %rsp
30689 CFI_ADJUST_CFA_OFFSET -7*8
30690 + pax_force_retaddr
30691 ret
30692 CFI_RESTORE_STATE
30693
30694 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30695 index 7609e0e..b449b98 100644
30696 --- a/arch/x86/lib/csum-wrappers_64.c
30697 +++ b/arch/x86/lib/csum-wrappers_64.c
30698 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30699 len -= 2;
30700 }
30701 }
30702 + pax_open_userland();
30703 stac();
30704 - isum = csum_partial_copy_generic((__force const void *)src,
30705 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30706 dst, len, isum, errp, NULL);
30707 clac();
30708 + pax_close_userland();
30709 if (unlikely(*errp))
30710 goto out_err;
30711
30712 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30713 }
30714
30715 *errp = 0;
30716 + pax_open_userland();
30717 stac();
30718 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30719 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30720 len, isum, NULL, errp);
30721 clac();
30722 + pax_close_userland();
30723 return ret;
30724 }
30725 EXPORT_SYMBOL(csum_partial_copy_to_user);
30726 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30727 index a451235..1daa956 100644
30728 --- a/arch/x86/lib/getuser.S
30729 +++ b/arch/x86/lib/getuser.S
30730 @@ -33,17 +33,40 @@
30731 #include <asm/thread_info.h>
30732 #include <asm/asm.h>
30733 #include <asm/smap.h>
30734 +#include <asm/segment.h>
30735 +#include <asm/pgtable.h>
30736 +#include <asm/alternative-asm.h>
30737 +
30738 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30739 +#define __copyuser_seg gs;
30740 +#else
30741 +#define __copyuser_seg
30742 +#endif
30743
30744 .text
30745 ENTRY(__get_user_1)
30746 CFI_STARTPROC
30747 +
30748 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30749 GET_THREAD_INFO(%_ASM_DX)
30750 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30751 jae bad_get_user
30752 ASM_STAC
30753 -1: movzbl (%_ASM_AX),%edx
30754 +
30755 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30756 + mov pax_user_shadow_base,%_ASM_DX
30757 + cmp %_ASM_DX,%_ASM_AX
30758 + jae 1234f
30759 + add %_ASM_DX,%_ASM_AX
30760 +1234:
30761 +#endif
30762 +
30763 +#endif
30764 +
30765 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30766 xor %eax,%eax
30767 ASM_CLAC
30768 + pax_force_retaddr
30769 ret
30770 CFI_ENDPROC
30771 ENDPROC(__get_user_1)
30772 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30773 ENTRY(__get_user_2)
30774 CFI_STARTPROC
30775 add $1,%_ASM_AX
30776 +
30777 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30778 jc bad_get_user
30779 GET_THREAD_INFO(%_ASM_DX)
30780 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30781 jae bad_get_user
30782 ASM_STAC
30783 -2: movzwl -1(%_ASM_AX),%edx
30784 +
30785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30786 + mov pax_user_shadow_base,%_ASM_DX
30787 + cmp %_ASM_DX,%_ASM_AX
30788 + jae 1234f
30789 + add %_ASM_DX,%_ASM_AX
30790 +1234:
30791 +#endif
30792 +
30793 +#endif
30794 +
30795 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30796 xor %eax,%eax
30797 ASM_CLAC
30798 + pax_force_retaddr
30799 ret
30800 CFI_ENDPROC
30801 ENDPROC(__get_user_2)
30802 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30803 ENTRY(__get_user_4)
30804 CFI_STARTPROC
30805 add $3,%_ASM_AX
30806 +
30807 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30808 jc bad_get_user
30809 GET_THREAD_INFO(%_ASM_DX)
30810 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30811 jae bad_get_user
30812 ASM_STAC
30813 -3: movl -3(%_ASM_AX),%edx
30814 +
30815 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30816 + mov pax_user_shadow_base,%_ASM_DX
30817 + cmp %_ASM_DX,%_ASM_AX
30818 + jae 1234f
30819 + add %_ASM_DX,%_ASM_AX
30820 +1234:
30821 +#endif
30822 +
30823 +#endif
30824 +
30825 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30826 xor %eax,%eax
30827 ASM_CLAC
30828 + pax_force_retaddr
30829 ret
30830 CFI_ENDPROC
30831 ENDPROC(__get_user_4)
30832 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30833 GET_THREAD_INFO(%_ASM_DX)
30834 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30835 jae bad_get_user
30836 +
30837 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30838 + mov pax_user_shadow_base,%_ASM_DX
30839 + cmp %_ASM_DX,%_ASM_AX
30840 + jae 1234f
30841 + add %_ASM_DX,%_ASM_AX
30842 +1234:
30843 +#endif
30844 +
30845 ASM_STAC
30846 4: movq -7(%_ASM_AX),%rdx
30847 xor %eax,%eax
30848 ASM_CLAC
30849 + pax_force_retaddr
30850 ret
30851 #else
30852 add $7,%_ASM_AX
30853 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30854 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30855 jae bad_get_user_8
30856 ASM_STAC
30857 -4: movl -7(%_ASM_AX),%edx
30858 -5: movl -3(%_ASM_AX),%ecx
30859 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30860 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30861 xor %eax,%eax
30862 ASM_CLAC
30863 + pax_force_retaddr
30864 ret
30865 #endif
30866 CFI_ENDPROC
30867 @@ -113,6 +175,7 @@ bad_get_user:
30868 xor %edx,%edx
30869 mov $(-EFAULT),%_ASM_AX
30870 ASM_CLAC
30871 + pax_force_retaddr
30872 ret
30873 CFI_ENDPROC
30874 END(bad_get_user)
30875 @@ -124,6 +187,7 @@ bad_get_user_8:
30876 xor %ecx,%ecx
30877 mov $(-EFAULT),%_ASM_AX
30878 ASM_CLAC
30879 + pax_force_retaddr
30880 ret
30881 CFI_ENDPROC
30882 END(bad_get_user_8)
30883 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30884 index 54fcffe..7be149e 100644
30885 --- a/arch/x86/lib/insn.c
30886 +++ b/arch/x86/lib/insn.c
30887 @@ -20,8 +20,10 @@
30888
30889 #ifdef __KERNEL__
30890 #include <linux/string.h>
30891 +#include <asm/pgtable_types.h>
30892 #else
30893 #include <string.h>
30894 +#define ktla_ktva(addr) addr
30895 #endif
30896 #include <asm/inat.h>
30897 #include <asm/insn.h>
30898 @@ -53,8 +55,8 @@
30899 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30900 {
30901 memset(insn, 0, sizeof(*insn));
30902 - insn->kaddr = kaddr;
30903 - insn->next_byte = kaddr;
30904 + insn->kaddr = ktla_ktva(kaddr);
30905 + insn->next_byte = ktla_ktva(kaddr);
30906 insn->x86_64 = x86_64 ? 1 : 0;
30907 insn->opnd_bytes = 4;
30908 if (x86_64)
30909 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30910 index 05a95e7..326f2fa 100644
30911 --- a/arch/x86/lib/iomap_copy_64.S
30912 +++ b/arch/x86/lib/iomap_copy_64.S
30913 @@ -17,6 +17,7 @@
30914
30915 #include <linux/linkage.h>
30916 #include <asm/dwarf2.h>
30917 +#include <asm/alternative-asm.h>
30918
30919 /*
30920 * override generic version in lib/iomap_copy.c
30921 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30922 CFI_STARTPROC
30923 movl %edx,%ecx
30924 rep movsd
30925 + pax_force_retaddr
30926 ret
30927 CFI_ENDPROC
30928 ENDPROC(__iowrite32_copy)
30929 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30930 index 56313a3..0db417e 100644
30931 --- a/arch/x86/lib/memcpy_64.S
30932 +++ b/arch/x86/lib/memcpy_64.S
30933 @@ -24,7 +24,7 @@
30934 * This gets patched over the unrolled variant (below) via the
30935 * alternative instructions framework:
30936 */
30937 - .section .altinstr_replacement, "ax", @progbits
30938 + .section .altinstr_replacement, "a", @progbits
30939 .Lmemcpy_c:
30940 movq %rdi, %rax
30941 movq %rdx, %rcx
30942 @@ -33,6 +33,7 @@
30943 rep movsq
30944 movl %edx, %ecx
30945 rep movsb
30946 + pax_force_retaddr
30947 ret
30948 .Lmemcpy_e:
30949 .previous
30950 @@ -44,11 +45,12 @@
30951 * This gets patched over the unrolled variant (below) via the
30952 * alternative instructions framework:
30953 */
30954 - .section .altinstr_replacement, "ax", @progbits
30955 + .section .altinstr_replacement, "a", @progbits
30956 .Lmemcpy_c_e:
30957 movq %rdi, %rax
30958 movq %rdx, %rcx
30959 rep movsb
30960 + pax_force_retaddr
30961 ret
30962 .Lmemcpy_e_e:
30963 .previous
30964 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30965 movq %r9, 1*8(%rdi)
30966 movq %r10, -2*8(%rdi, %rdx)
30967 movq %r11, -1*8(%rdi, %rdx)
30968 + pax_force_retaddr
30969 retq
30970 .p2align 4
30971 .Lless_16bytes:
30972 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30973 movq -1*8(%rsi, %rdx), %r9
30974 movq %r8, 0*8(%rdi)
30975 movq %r9, -1*8(%rdi, %rdx)
30976 + pax_force_retaddr
30977 retq
30978 .p2align 4
30979 .Lless_8bytes:
30980 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30981 movl -4(%rsi, %rdx), %r8d
30982 movl %ecx, (%rdi)
30983 movl %r8d, -4(%rdi, %rdx)
30984 + pax_force_retaddr
30985 retq
30986 .p2align 4
30987 .Lless_3bytes:
30988 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30989 movb %cl, (%rdi)
30990
30991 .Lend:
30992 + pax_force_retaddr
30993 retq
30994 CFI_ENDPROC
30995 ENDPROC(memcpy)
30996 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30997 index 65268a6..dd1de11 100644
30998 --- a/arch/x86/lib/memmove_64.S
30999 +++ b/arch/x86/lib/memmove_64.S
31000 @@ -202,14 +202,16 @@ ENTRY(memmove)
31001 movb (%rsi), %r11b
31002 movb %r11b, (%rdi)
31003 13:
31004 + pax_force_retaddr
31005 retq
31006 CFI_ENDPROC
31007
31008 - .section .altinstr_replacement,"ax"
31009 + .section .altinstr_replacement,"a"
31010 .Lmemmove_begin_forward_efs:
31011 /* Forward moving data. */
31012 movq %rdx, %rcx
31013 rep movsb
31014 + pax_force_retaddr
31015 retq
31016 .Lmemmove_end_forward_efs:
31017 .previous
31018 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31019 index 2dcb380..2eb79fe 100644
31020 --- a/arch/x86/lib/memset_64.S
31021 +++ b/arch/x86/lib/memset_64.S
31022 @@ -16,7 +16,7 @@
31023 *
31024 * rax original destination
31025 */
31026 - .section .altinstr_replacement, "ax", @progbits
31027 + .section .altinstr_replacement, "a", @progbits
31028 .Lmemset_c:
31029 movq %rdi,%r9
31030 movq %rdx,%rcx
31031 @@ -30,6 +30,7 @@
31032 movl %edx,%ecx
31033 rep stosb
31034 movq %r9,%rax
31035 + pax_force_retaddr
31036 ret
31037 .Lmemset_e:
31038 .previous
31039 @@ -45,13 +46,14 @@
31040 *
31041 * rax original destination
31042 */
31043 - .section .altinstr_replacement, "ax", @progbits
31044 + .section .altinstr_replacement, "a", @progbits
31045 .Lmemset_c_e:
31046 movq %rdi,%r9
31047 movb %sil,%al
31048 movq %rdx,%rcx
31049 rep stosb
31050 movq %r9,%rax
31051 + pax_force_retaddr
31052 ret
31053 .Lmemset_e_e:
31054 .previous
31055 @@ -118,6 +120,7 @@ ENTRY(__memset)
31056
31057 .Lende:
31058 movq %r10,%rax
31059 + pax_force_retaddr
31060 ret
31061
31062 CFI_RESTORE_STATE
31063 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31064 index c9f2d9b..e7fd2c0 100644
31065 --- a/arch/x86/lib/mmx_32.c
31066 +++ b/arch/x86/lib/mmx_32.c
31067 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31068 {
31069 void *p;
31070 int i;
31071 + unsigned long cr0;
31072
31073 if (unlikely(in_interrupt()))
31074 return __memcpy(to, from, len);
31075 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31076 kernel_fpu_begin();
31077
31078 __asm__ __volatile__ (
31079 - "1: prefetch (%0)\n" /* This set is 28 bytes */
31080 - " prefetch 64(%0)\n"
31081 - " prefetch 128(%0)\n"
31082 - " prefetch 192(%0)\n"
31083 - " prefetch 256(%0)\n"
31084 + "1: prefetch (%1)\n" /* This set is 28 bytes */
31085 + " prefetch 64(%1)\n"
31086 + " prefetch 128(%1)\n"
31087 + " prefetch 192(%1)\n"
31088 + " prefetch 256(%1)\n"
31089 "2: \n"
31090 ".section .fixup, \"ax\"\n"
31091 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31092 + "3: \n"
31093 +
31094 +#ifdef CONFIG_PAX_KERNEXEC
31095 + " movl %%cr0, %0\n"
31096 + " movl %0, %%eax\n"
31097 + " andl $0xFFFEFFFF, %%eax\n"
31098 + " movl %%eax, %%cr0\n"
31099 +#endif
31100 +
31101 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31102 +
31103 +#ifdef CONFIG_PAX_KERNEXEC
31104 + " movl %0, %%cr0\n"
31105 +#endif
31106 +
31107 " jmp 2b\n"
31108 ".previous\n"
31109 _ASM_EXTABLE(1b, 3b)
31110 - : : "r" (from));
31111 + : "=&r" (cr0) : "r" (from) : "ax");
31112
31113 for ( ; i > 5; i--) {
31114 __asm__ __volatile__ (
31115 - "1: prefetch 320(%0)\n"
31116 - "2: movq (%0), %%mm0\n"
31117 - " movq 8(%0), %%mm1\n"
31118 - " movq 16(%0), %%mm2\n"
31119 - " movq 24(%0), %%mm3\n"
31120 - " movq %%mm0, (%1)\n"
31121 - " movq %%mm1, 8(%1)\n"
31122 - " movq %%mm2, 16(%1)\n"
31123 - " movq %%mm3, 24(%1)\n"
31124 - " movq 32(%0), %%mm0\n"
31125 - " movq 40(%0), %%mm1\n"
31126 - " movq 48(%0), %%mm2\n"
31127 - " movq 56(%0), %%mm3\n"
31128 - " movq %%mm0, 32(%1)\n"
31129 - " movq %%mm1, 40(%1)\n"
31130 - " movq %%mm2, 48(%1)\n"
31131 - " movq %%mm3, 56(%1)\n"
31132 + "1: prefetch 320(%1)\n"
31133 + "2: movq (%1), %%mm0\n"
31134 + " movq 8(%1), %%mm1\n"
31135 + " movq 16(%1), %%mm2\n"
31136 + " movq 24(%1), %%mm3\n"
31137 + " movq %%mm0, (%2)\n"
31138 + " movq %%mm1, 8(%2)\n"
31139 + " movq %%mm2, 16(%2)\n"
31140 + " movq %%mm3, 24(%2)\n"
31141 + " movq 32(%1), %%mm0\n"
31142 + " movq 40(%1), %%mm1\n"
31143 + " movq 48(%1), %%mm2\n"
31144 + " movq 56(%1), %%mm3\n"
31145 + " movq %%mm0, 32(%2)\n"
31146 + " movq %%mm1, 40(%2)\n"
31147 + " movq %%mm2, 48(%2)\n"
31148 + " movq %%mm3, 56(%2)\n"
31149 ".section .fixup, \"ax\"\n"
31150 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31151 + "3:\n"
31152 +
31153 +#ifdef CONFIG_PAX_KERNEXEC
31154 + " movl %%cr0, %0\n"
31155 + " movl %0, %%eax\n"
31156 + " andl $0xFFFEFFFF, %%eax\n"
31157 + " movl %%eax, %%cr0\n"
31158 +#endif
31159 +
31160 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31161 +
31162 +#ifdef CONFIG_PAX_KERNEXEC
31163 + " movl %0, %%cr0\n"
31164 +#endif
31165 +
31166 " jmp 2b\n"
31167 ".previous\n"
31168 _ASM_EXTABLE(1b, 3b)
31169 - : : "r" (from), "r" (to) : "memory");
31170 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31171
31172 from += 64;
31173 to += 64;
31174 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31175 static void fast_copy_page(void *to, void *from)
31176 {
31177 int i;
31178 + unsigned long cr0;
31179
31180 kernel_fpu_begin();
31181
31182 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31183 * but that is for later. -AV
31184 */
31185 __asm__ __volatile__(
31186 - "1: prefetch (%0)\n"
31187 - " prefetch 64(%0)\n"
31188 - " prefetch 128(%0)\n"
31189 - " prefetch 192(%0)\n"
31190 - " prefetch 256(%0)\n"
31191 + "1: prefetch (%1)\n"
31192 + " prefetch 64(%1)\n"
31193 + " prefetch 128(%1)\n"
31194 + " prefetch 192(%1)\n"
31195 + " prefetch 256(%1)\n"
31196 "2: \n"
31197 ".section .fixup, \"ax\"\n"
31198 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31199 + "3: \n"
31200 +
31201 +#ifdef CONFIG_PAX_KERNEXEC
31202 + " movl %%cr0, %0\n"
31203 + " movl %0, %%eax\n"
31204 + " andl $0xFFFEFFFF, %%eax\n"
31205 + " movl %%eax, %%cr0\n"
31206 +#endif
31207 +
31208 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31209 +
31210 +#ifdef CONFIG_PAX_KERNEXEC
31211 + " movl %0, %%cr0\n"
31212 +#endif
31213 +
31214 " jmp 2b\n"
31215 ".previous\n"
31216 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31217 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31218
31219 for (i = 0; i < (4096-320)/64; i++) {
31220 __asm__ __volatile__ (
31221 - "1: prefetch 320(%0)\n"
31222 - "2: movq (%0), %%mm0\n"
31223 - " movntq %%mm0, (%1)\n"
31224 - " movq 8(%0), %%mm1\n"
31225 - " movntq %%mm1, 8(%1)\n"
31226 - " movq 16(%0), %%mm2\n"
31227 - " movntq %%mm2, 16(%1)\n"
31228 - " movq 24(%0), %%mm3\n"
31229 - " movntq %%mm3, 24(%1)\n"
31230 - " movq 32(%0), %%mm4\n"
31231 - " movntq %%mm4, 32(%1)\n"
31232 - " movq 40(%0), %%mm5\n"
31233 - " movntq %%mm5, 40(%1)\n"
31234 - " movq 48(%0), %%mm6\n"
31235 - " movntq %%mm6, 48(%1)\n"
31236 - " movq 56(%0), %%mm7\n"
31237 - " movntq %%mm7, 56(%1)\n"
31238 + "1: prefetch 320(%1)\n"
31239 + "2: movq (%1), %%mm0\n"
31240 + " movntq %%mm0, (%2)\n"
31241 + " movq 8(%1), %%mm1\n"
31242 + " movntq %%mm1, 8(%2)\n"
31243 + " movq 16(%1), %%mm2\n"
31244 + " movntq %%mm2, 16(%2)\n"
31245 + " movq 24(%1), %%mm3\n"
31246 + " movntq %%mm3, 24(%2)\n"
31247 + " movq 32(%1), %%mm4\n"
31248 + " movntq %%mm4, 32(%2)\n"
31249 + " movq 40(%1), %%mm5\n"
31250 + " movntq %%mm5, 40(%2)\n"
31251 + " movq 48(%1), %%mm6\n"
31252 + " movntq %%mm6, 48(%2)\n"
31253 + " movq 56(%1), %%mm7\n"
31254 + " movntq %%mm7, 56(%2)\n"
31255 ".section .fixup, \"ax\"\n"
31256 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31257 + "3:\n"
31258 +
31259 +#ifdef CONFIG_PAX_KERNEXEC
31260 + " movl %%cr0, %0\n"
31261 + " movl %0, %%eax\n"
31262 + " andl $0xFFFEFFFF, %%eax\n"
31263 + " movl %%eax, %%cr0\n"
31264 +#endif
31265 +
31266 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31267 +
31268 +#ifdef CONFIG_PAX_KERNEXEC
31269 + " movl %0, %%cr0\n"
31270 +#endif
31271 +
31272 " jmp 2b\n"
31273 ".previous\n"
31274 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31275 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31276
31277 from += 64;
31278 to += 64;
31279 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31280 static void fast_copy_page(void *to, void *from)
31281 {
31282 int i;
31283 + unsigned long cr0;
31284
31285 kernel_fpu_begin();
31286
31287 __asm__ __volatile__ (
31288 - "1: prefetch (%0)\n"
31289 - " prefetch 64(%0)\n"
31290 - " prefetch 128(%0)\n"
31291 - " prefetch 192(%0)\n"
31292 - " prefetch 256(%0)\n"
31293 + "1: prefetch (%1)\n"
31294 + " prefetch 64(%1)\n"
31295 + " prefetch 128(%1)\n"
31296 + " prefetch 192(%1)\n"
31297 + " prefetch 256(%1)\n"
31298 "2: \n"
31299 ".section .fixup, \"ax\"\n"
31300 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31301 + "3: \n"
31302 +
31303 +#ifdef CONFIG_PAX_KERNEXEC
31304 + " movl %%cr0, %0\n"
31305 + " movl %0, %%eax\n"
31306 + " andl $0xFFFEFFFF, %%eax\n"
31307 + " movl %%eax, %%cr0\n"
31308 +#endif
31309 +
31310 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31311 +
31312 +#ifdef CONFIG_PAX_KERNEXEC
31313 + " movl %0, %%cr0\n"
31314 +#endif
31315 +
31316 " jmp 2b\n"
31317 ".previous\n"
31318 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31319 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31320
31321 for (i = 0; i < 4096/64; i++) {
31322 __asm__ __volatile__ (
31323 - "1: prefetch 320(%0)\n"
31324 - "2: movq (%0), %%mm0\n"
31325 - " movq 8(%0), %%mm1\n"
31326 - " movq 16(%0), %%mm2\n"
31327 - " movq 24(%0), %%mm3\n"
31328 - " movq %%mm0, (%1)\n"
31329 - " movq %%mm1, 8(%1)\n"
31330 - " movq %%mm2, 16(%1)\n"
31331 - " movq %%mm3, 24(%1)\n"
31332 - " movq 32(%0), %%mm0\n"
31333 - " movq 40(%0), %%mm1\n"
31334 - " movq 48(%0), %%mm2\n"
31335 - " movq 56(%0), %%mm3\n"
31336 - " movq %%mm0, 32(%1)\n"
31337 - " movq %%mm1, 40(%1)\n"
31338 - " movq %%mm2, 48(%1)\n"
31339 - " movq %%mm3, 56(%1)\n"
31340 + "1: prefetch 320(%1)\n"
31341 + "2: movq (%1), %%mm0\n"
31342 + " movq 8(%1), %%mm1\n"
31343 + " movq 16(%1), %%mm2\n"
31344 + " movq 24(%1), %%mm3\n"
31345 + " movq %%mm0, (%2)\n"
31346 + " movq %%mm1, 8(%2)\n"
31347 + " movq %%mm2, 16(%2)\n"
31348 + " movq %%mm3, 24(%2)\n"
31349 + " movq 32(%1), %%mm0\n"
31350 + " movq 40(%1), %%mm1\n"
31351 + " movq 48(%1), %%mm2\n"
31352 + " movq 56(%1), %%mm3\n"
31353 + " movq %%mm0, 32(%2)\n"
31354 + " movq %%mm1, 40(%2)\n"
31355 + " movq %%mm2, 48(%2)\n"
31356 + " movq %%mm3, 56(%2)\n"
31357 ".section .fixup, \"ax\"\n"
31358 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31359 + "3:\n"
31360 +
31361 +#ifdef CONFIG_PAX_KERNEXEC
31362 + " movl %%cr0, %0\n"
31363 + " movl %0, %%eax\n"
31364 + " andl $0xFFFEFFFF, %%eax\n"
31365 + " movl %%eax, %%cr0\n"
31366 +#endif
31367 +
31368 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31369 +
31370 +#ifdef CONFIG_PAX_KERNEXEC
31371 + " movl %0, %%cr0\n"
31372 +#endif
31373 +
31374 " jmp 2b\n"
31375 ".previous\n"
31376 _ASM_EXTABLE(1b, 3b)
31377 - : : "r" (from), "r" (to) : "memory");
31378 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31379
31380 from += 64;
31381 to += 64;
31382 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31383 index f6d13ee..d789440 100644
31384 --- a/arch/x86/lib/msr-reg.S
31385 +++ b/arch/x86/lib/msr-reg.S
31386 @@ -3,6 +3,7 @@
31387 #include <asm/dwarf2.h>
31388 #include <asm/asm.h>
31389 #include <asm/msr.h>
31390 +#include <asm/alternative-asm.h>
31391
31392 #ifdef CONFIG_X86_64
31393 /*
31394 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31395 movl %edi, 28(%r10)
31396 popq_cfi %rbp
31397 popq_cfi %rbx
31398 + pax_force_retaddr
31399 ret
31400 3:
31401 CFI_RESTORE_STATE
31402 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31403 index fc6ba17..d4d989d 100644
31404 --- a/arch/x86/lib/putuser.S
31405 +++ b/arch/x86/lib/putuser.S
31406 @@ -16,7 +16,9 @@
31407 #include <asm/errno.h>
31408 #include <asm/asm.h>
31409 #include <asm/smap.h>
31410 -
31411 +#include <asm/segment.h>
31412 +#include <asm/pgtable.h>
31413 +#include <asm/alternative-asm.h>
31414
31415 /*
31416 * __put_user_X
31417 @@ -30,57 +32,125 @@
31418 * as they get called from within inline assembly.
31419 */
31420
31421 -#define ENTER CFI_STARTPROC ; \
31422 - GET_THREAD_INFO(%_ASM_BX)
31423 -#define EXIT ASM_CLAC ; \
31424 - ret ; \
31425 +#define ENTER CFI_STARTPROC
31426 +#define EXIT ASM_CLAC ; \
31427 + pax_force_retaddr ; \
31428 + ret ; \
31429 CFI_ENDPROC
31430
31431 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31432 +#define _DEST %_ASM_CX,%_ASM_BX
31433 +#else
31434 +#define _DEST %_ASM_CX
31435 +#endif
31436 +
31437 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31438 +#define __copyuser_seg gs;
31439 +#else
31440 +#define __copyuser_seg
31441 +#endif
31442 +
31443 .text
31444 ENTRY(__put_user_1)
31445 ENTER
31446 +
31447 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31448 + GET_THREAD_INFO(%_ASM_BX)
31449 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31450 jae bad_put_user
31451 ASM_STAC
31452 -1: movb %al,(%_ASM_CX)
31453 +
31454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31455 + mov pax_user_shadow_base,%_ASM_BX
31456 + cmp %_ASM_BX,%_ASM_CX
31457 + jb 1234f
31458 + xor %ebx,%ebx
31459 +1234:
31460 +#endif
31461 +
31462 +#endif
31463 +
31464 +1: __copyuser_seg movb %al,(_DEST)
31465 xor %eax,%eax
31466 EXIT
31467 ENDPROC(__put_user_1)
31468
31469 ENTRY(__put_user_2)
31470 ENTER
31471 +
31472 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31473 + GET_THREAD_INFO(%_ASM_BX)
31474 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31475 sub $1,%_ASM_BX
31476 cmp %_ASM_BX,%_ASM_CX
31477 jae bad_put_user
31478 ASM_STAC
31479 -2: movw %ax,(%_ASM_CX)
31480 +
31481 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31482 + mov pax_user_shadow_base,%_ASM_BX
31483 + cmp %_ASM_BX,%_ASM_CX
31484 + jb 1234f
31485 + xor %ebx,%ebx
31486 +1234:
31487 +#endif
31488 +
31489 +#endif
31490 +
31491 +2: __copyuser_seg movw %ax,(_DEST)
31492 xor %eax,%eax
31493 EXIT
31494 ENDPROC(__put_user_2)
31495
31496 ENTRY(__put_user_4)
31497 ENTER
31498 +
31499 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31500 + GET_THREAD_INFO(%_ASM_BX)
31501 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31502 sub $3,%_ASM_BX
31503 cmp %_ASM_BX,%_ASM_CX
31504 jae bad_put_user
31505 ASM_STAC
31506 -3: movl %eax,(%_ASM_CX)
31507 +
31508 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31509 + mov pax_user_shadow_base,%_ASM_BX
31510 + cmp %_ASM_BX,%_ASM_CX
31511 + jb 1234f
31512 + xor %ebx,%ebx
31513 +1234:
31514 +#endif
31515 +
31516 +#endif
31517 +
31518 +3: __copyuser_seg movl %eax,(_DEST)
31519 xor %eax,%eax
31520 EXIT
31521 ENDPROC(__put_user_4)
31522
31523 ENTRY(__put_user_8)
31524 ENTER
31525 +
31526 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31527 + GET_THREAD_INFO(%_ASM_BX)
31528 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31529 sub $7,%_ASM_BX
31530 cmp %_ASM_BX,%_ASM_CX
31531 jae bad_put_user
31532 ASM_STAC
31533 -4: mov %_ASM_AX,(%_ASM_CX)
31534 +
31535 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31536 + mov pax_user_shadow_base,%_ASM_BX
31537 + cmp %_ASM_BX,%_ASM_CX
31538 + jb 1234f
31539 + xor %ebx,%ebx
31540 +1234:
31541 +#endif
31542 +
31543 +#endif
31544 +
31545 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31546 #ifdef CONFIG_X86_32
31547 -5: movl %edx,4(%_ASM_CX)
31548 +5: __copyuser_seg movl %edx,4(_DEST)
31549 #endif
31550 xor %eax,%eax
31551 EXIT
31552 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31553 index 1cad221..de671ee 100644
31554 --- a/arch/x86/lib/rwlock.S
31555 +++ b/arch/x86/lib/rwlock.S
31556 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31557 FRAME
31558 0: LOCK_PREFIX
31559 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31560 +
31561 +#ifdef CONFIG_PAX_REFCOUNT
31562 + jno 1234f
31563 + LOCK_PREFIX
31564 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31565 + int $4
31566 +1234:
31567 + _ASM_EXTABLE(1234b, 1234b)
31568 +#endif
31569 +
31570 1: rep; nop
31571 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31572 jne 1b
31573 LOCK_PREFIX
31574 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31575 +
31576 +#ifdef CONFIG_PAX_REFCOUNT
31577 + jno 1234f
31578 + LOCK_PREFIX
31579 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31580 + int $4
31581 +1234:
31582 + _ASM_EXTABLE(1234b, 1234b)
31583 +#endif
31584 +
31585 jnz 0b
31586 ENDFRAME
31587 + pax_force_retaddr
31588 ret
31589 CFI_ENDPROC
31590 END(__write_lock_failed)
31591 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31592 FRAME
31593 0: LOCK_PREFIX
31594 READ_LOCK_SIZE(inc) (%__lock_ptr)
31595 +
31596 +#ifdef CONFIG_PAX_REFCOUNT
31597 + jno 1234f
31598 + LOCK_PREFIX
31599 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31600 + int $4
31601 +1234:
31602 + _ASM_EXTABLE(1234b, 1234b)
31603 +#endif
31604 +
31605 1: rep; nop
31606 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31607 js 1b
31608 LOCK_PREFIX
31609 READ_LOCK_SIZE(dec) (%__lock_ptr)
31610 +
31611 +#ifdef CONFIG_PAX_REFCOUNT
31612 + jno 1234f
31613 + LOCK_PREFIX
31614 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31615 + int $4
31616 +1234:
31617 + _ASM_EXTABLE(1234b, 1234b)
31618 +#endif
31619 +
31620 js 0b
31621 ENDFRAME
31622 + pax_force_retaddr
31623 ret
31624 CFI_ENDPROC
31625 END(__read_lock_failed)
31626 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31627 index 5dff5f0..cadebf4 100644
31628 --- a/arch/x86/lib/rwsem.S
31629 +++ b/arch/x86/lib/rwsem.S
31630 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31631 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31632 CFI_RESTORE __ASM_REG(dx)
31633 restore_common_regs
31634 + pax_force_retaddr
31635 ret
31636 CFI_ENDPROC
31637 ENDPROC(call_rwsem_down_read_failed)
31638 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31639 movq %rax,%rdi
31640 call rwsem_down_write_failed
31641 restore_common_regs
31642 + pax_force_retaddr
31643 ret
31644 CFI_ENDPROC
31645 ENDPROC(call_rwsem_down_write_failed)
31646 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31647 movq %rax,%rdi
31648 call rwsem_wake
31649 restore_common_regs
31650 -1: ret
31651 +1: pax_force_retaddr
31652 + ret
31653 CFI_ENDPROC
31654 ENDPROC(call_rwsem_wake)
31655
31656 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31657 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31658 CFI_RESTORE __ASM_REG(dx)
31659 restore_common_regs
31660 + pax_force_retaddr
31661 ret
31662 CFI_ENDPROC
31663 ENDPROC(call_rwsem_downgrade_wake)
31664 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31665 index 92d9fea..b2762c8 100644
31666 --- a/arch/x86/lib/thunk_64.S
31667 +++ b/arch/x86/lib/thunk_64.S
31668 @@ -9,6 +9,7 @@
31669 #include <asm/dwarf2.h>
31670 #include <asm/calling.h>
31671 #include <asm/asm.h>
31672 +#include <asm/alternative-asm.h>
31673
31674 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31675 .macro THUNK name, func, put_ret_addr_in_rdi=0
31676 @@ -16,11 +17,11 @@
31677 \name:
31678 CFI_STARTPROC
31679
31680 - /* this one pushes 9 elems, the next one would be %rIP */
31681 - SAVE_ARGS
31682 + /* this one pushes 15+1 elems, the next one would be %rIP */
31683 + SAVE_ARGS 8
31684
31685 .if \put_ret_addr_in_rdi
31686 - movq_cfi_restore 9*8, rdi
31687 + movq_cfi_restore RIP, rdi
31688 .endif
31689
31690 call \func
31691 @@ -40,9 +41,10 @@
31692
31693 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31694 CFI_STARTPROC
31695 - SAVE_ARGS
31696 + SAVE_ARGS 8
31697 restore:
31698 - RESTORE_ARGS
31699 + RESTORE_ARGS 1,8
31700 + pax_force_retaddr
31701 ret
31702 CFI_ENDPROC
31703 _ASM_NOKPROBE(restore)
31704 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31705 index e2f5e21..4b22130 100644
31706 --- a/arch/x86/lib/usercopy_32.c
31707 +++ b/arch/x86/lib/usercopy_32.c
31708 @@ -42,11 +42,13 @@ do { \
31709 int __d0; \
31710 might_fault(); \
31711 __asm__ __volatile__( \
31712 + __COPYUSER_SET_ES \
31713 ASM_STAC "\n" \
31714 "0: rep; stosl\n" \
31715 " movl %2,%0\n" \
31716 "1: rep; stosb\n" \
31717 "2: " ASM_CLAC "\n" \
31718 + __COPYUSER_RESTORE_ES \
31719 ".section .fixup,\"ax\"\n" \
31720 "3: lea 0(%2,%0,4),%0\n" \
31721 " jmp 2b\n" \
31722 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31723
31724 #ifdef CONFIG_X86_INTEL_USERCOPY
31725 static unsigned long
31726 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31727 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31728 {
31729 int d0, d1;
31730 __asm__ __volatile__(
31731 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31732 " .align 2,0x90\n"
31733 "3: movl 0(%4), %%eax\n"
31734 "4: movl 4(%4), %%edx\n"
31735 - "5: movl %%eax, 0(%3)\n"
31736 - "6: movl %%edx, 4(%3)\n"
31737 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31738 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31739 "7: movl 8(%4), %%eax\n"
31740 "8: movl 12(%4),%%edx\n"
31741 - "9: movl %%eax, 8(%3)\n"
31742 - "10: movl %%edx, 12(%3)\n"
31743 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31744 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31745 "11: movl 16(%4), %%eax\n"
31746 "12: movl 20(%4), %%edx\n"
31747 - "13: movl %%eax, 16(%3)\n"
31748 - "14: movl %%edx, 20(%3)\n"
31749 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31750 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31751 "15: movl 24(%4), %%eax\n"
31752 "16: movl 28(%4), %%edx\n"
31753 - "17: movl %%eax, 24(%3)\n"
31754 - "18: movl %%edx, 28(%3)\n"
31755 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31756 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31757 "19: movl 32(%4), %%eax\n"
31758 "20: movl 36(%4), %%edx\n"
31759 - "21: movl %%eax, 32(%3)\n"
31760 - "22: movl %%edx, 36(%3)\n"
31761 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31762 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31763 "23: movl 40(%4), %%eax\n"
31764 "24: movl 44(%4), %%edx\n"
31765 - "25: movl %%eax, 40(%3)\n"
31766 - "26: movl %%edx, 44(%3)\n"
31767 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31768 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31769 "27: movl 48(%4), %%eax\n"
31770 "28: movl 52(%4), %%edx\n"
31771 - "29: movl %%eax, 48(%3)\n"
31772 - "30: movl %%edx, 52(%3)\n"
31773 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31774 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31775 "31: movl 56(%4), %%eax\n"
31776 "32: movl 60(%4), %%edx\n"
31777 - "33: movl %%eax, 56(%3)\n"
31778 - "34: movl %%edx, 60(%3)\n"
31779 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31780 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31781 " addl $-64, %0\n"
31782 " addl $64, %4\n"
31783 " addl $64, %3\n"
31784 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31785 " shrl $2, %0\n"
31786 " andl $3, %%eax\n"
31787 " cld\n"
31788 + __COPYUSER_SET_ES
31789 "99: rep; movsl\n"
31790 "36: movl %%eax, %0\n"
31791 "37: rep; movsb\n"
31792 "100:\n"
31793 + __COPYUSER_RESTORE_ES
31794 + ".section .fixup,\"ax\"\n"
31795 + "101: lea 0(%%eax,%0,4),%0\n"
31796 + " jmp 100b\n"
31797 + ".previous\n"
31798 + _ASM_EXTABLE(1b,100b)
31799 + _ASM_EXTABLE(2b,100b)
31800 + _ASM_EXTABLE(3b,100b)
31801 + _ASM_EXTABLE(4b,100b)
31802 + _ASM_EXTABLE(5b,100b)
31803 + _ASM_EXTABLE(6b,100b)
31804 + _ASM_EXTABLE(7b,100b)
31805 + _ASM_EXTABLE(8b,100b)
31806 + _ASM_EXTABLE(9b,100b)
31807 + _ASM_EXTABLE(10b,100b)
31808 + _ASM_EXTABLE(11b,100b)
31809 + _ASM_EXTABLE(12b,100b)
31810 + _ASM_EXTABLE(13b,100b)
31811 + _ASM_EXTABLE(14b,100b)
31812 + _ASM_EXTABLE(15b,100b)
31813 + _ASM_EXTABLE(16b,100b)
31814 + _ASM_EXTABLE(17b,100b)
31815 + _ASM_EXTABLE(18b,100b)
31816 + _ASM_EXTABLE(19b,100b)
31817 + _ASM_EXTABLE(20b,100b)
31818 + _ASM_EXTABLE(21b,100b)
31819 + _ASM_EXTABLE(22b,100b)
31820 + _ASM_EXTABLE(23b,100b)
31821 + _ASM_EXTABLE(24b,100b)
31822 + _ASM_EXTABLE(25b,100b)
31823 + _ASM_EXTABLE(26b,100b)
31824 + _ASM_EXTABLE(27b,100b)
31825 + _ASM_EXTABLE(28b,100b)
31826 + _ASM_EXTABLE(29b,100b)
31827 + _ASM_EXTABLE(30b,100b)
31828 + _ASM_EXTABLE(31b,100b)
31829 + _ASM_EXTABLE(32b,100b)
31830 + _ASM_EXTABLE(33b,100b)
31831 + _ASM_EXTABLE(34b,100b)
31832 + _ASM_EXTABLE(35b,100b)
31833 + _ASM_EXTABLE(36b,100b)
31834 + _ASM_EXTABLE(37b,100b)
31835 + _ASM_EXTABLE(99b,101b)
31836 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31837 + : "1"(to), "2"(from), "0"(size)
31838 + : "eax", "edx", "memory");
31839 + return size;
31840 +}
31841 +
31842 +static unsigned long
31843 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31844 +{
31845 + int d0, d1;
31846 + __asm__ __volatile__(
31847 + " .align 2,0x90\n"
31848 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31849 + " cmpl $67, %0\n"
31850 + " jbe 3f\n"
31851 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31852 + " .align 2,0x90\n"
31853 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31854 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31855 + "5: movl %%eax, 0(%3)\n"
31856 + "6: movl %%edx, 4(%3)\n"
31857 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31858 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31859 + "9: movl %%eax, 8(%3)\n"
31860 + "10: movl %%edx, 12(%3)\n"
31861 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31862 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31863 + "13: movl %%eax, 16(%3)\n"
31864 + "14: movl %%edx, 20(%3)\n"
31865 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31866 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31867 + "17: movl %%eax, 24(%3)\n"
31868 + "18: movl %%edx, 28(%3)\n"
31869 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31870 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31871 + "21: movl %%eax, 32(%3)\n"
31872 + "22: movl %%edx, 36(%3)\n"
31873 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31874 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31875 + "25: movl %%eax, 40(%3)\n"
31876 + "26: movl %%edx, 44(%3)\n"
31877 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31878 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31879 + "29: movl %%eax, 48(%3)\n"
31880 + "30: movl %%edx, 52(%3)\n"
31881 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31882 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31883 + "33: movl %%eax, 56(%3)\n"
31884 + "34: movl %%edx, 60(%3)\n"
31885 + " addl $-64, %0\n"
31886 + " addl $64, %4\n"
31887 + " addl $64, %3\n"
31888 + " cmpl $63, %0\n"
31889 + " ja 1b\n"
31890 + "35: movl %0, %%eax\n"
31891 + " shrl $2, %0\n"
31892 + " andl $3, %%eax\n"
31893 + " cld\n"
31894 + "99: rep; "__copyuser_seg" movsl\n"
31895 + "36: movl %%eax, %0\n"
31896 + "37: rep; "__copyuser_seg" movsb\n"
31897 + "100:\n"
31898 ".section .fixup,\"ax\"\n"
31899 "101: lea 0(%%eax,%0,4),%0\n"
31900 " jmp 100b\n"
31901 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31902 int d0, d1;
31903 __asm__ __volatile__(
31904 " .align 2,0x90\n"
31905 - "0: movl 32(%4), %%eax\n"
31906 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31907 " cmpl $67, %0\n"
31908 " jbe 2f\n"
31909 - "1: movl 64(%4), %%eax\n"
31910 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31911 " .align 2,0x90\n"
31912 - "2: movl 0(%4), %%eax\n"
31913 - "21: movl 4(%4), %%edx\n"
31914 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31915 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31916 " movl %%eax, 0(%3)\n"
31917 " movl %%edx, 4(%3)\n"
31918 - "3: movl 8(%4), %%eax\n"
31919 - "31: movl 12(%4),%%edx\n"
31920 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31921 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31922 " movl %%eax, 8(%3)\n"
31923 " movl %%edx, 12(%3)\n"
31924 - "4: movl 16(%4), %%eax\n"
31925 - "41: movl 20(%4), %%edx\n"
31926 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31927 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31928 " movl %%eax, 16(%3)\n"
31929 " movl %%edx, 20(%3)\n"
31930 - "10: movl 24(%4), %%eax\n"
31931 - "51: movl 28(%4), %%edx\n"
31932 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31933 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31934 " movl %%eax, 24(%3)\n"
31935 " movl %%edx, 28(%3)\n"
31936 - "11: movl 32(%4), %%eax\n"
31937 - "61: movl 36(%4), %%edx\n"
31938 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31939 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31940 " movl %%eax, 32(%3)\n"
31941 " movl %%edx, 36(%3)\n"
31942 - "12: movl 40(%4), %%eax\n"
31943 - "71: movl 44(%4), %%edx\n"
31944 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31945 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31946 " movl %%eax, 40(%3)\n"
31947 " movl %%edx, 44(%3)\n"
31948 - "13: movl 48(%4), %%eax\n"
31949 - "81: movl 52(%4), %%edx\n"
31950 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31951 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31952 " movl %%eax, 48(%3)\n"
31953 " movl %%edx, 52(%3)\n"
31954 - "14: movl 56(%4), %%eax\n"
31955 - "91: movl 60(%4), %%edx\n"
31956 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31957 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31958 " movl %%eax, 56(%3)\n"
31959 " movl %%edx, 60(%3)\n"
31960 " addl $-64, %0\n"
31961 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31962 " shrl $2, %0\n"
31963 " andl $3, %%eax\n"
31964 " cld\n"
31965 - "6: rep; movsl\n"
31966 + "6: rep; "__copyuser_seg" movsl\n"
31967 " movl %%eax,%0\n"
31968 - "7: rep; movsb\n"
31969 + "7: rep; "__copyuser_seg" movsb\n"
31970 "8:\n"
31971 ".section .fixup,\"ax\"\n"
31972 "9: lea 0(%%eax,%0,4),%0\n"
31973 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31974
31975 __asm__ __volatile__(
31976 " .align 2,0x90\n"
31977 - "0: movl 32(%4), %%eax\n"
31978 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31979 " cmpl $67, %0\n"
31980 " jbe 2f\n"
31981 - "1: movl 64(%4), %%eax\n"
31982 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31983 " .align 2,0x90\n"
31984 - "2: movl 0(%4), %%eax\n"
31985 - "21: movl 4(%4), %%edx\n"
31986 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31987 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31988 " movnti %%eax, 0(%3)\n"
31989 " movnti %%edx, 4(%3)\n"
31990 - "3: movl 8(%4), %%eax\n"
31991 - "31: movl 12(%4),%%edx\n"
31992 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31993 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31994 " movnti %%eax, 8(%3)\n"
31995 " movnti %%edx, 12(%3)\n"
31996 - "4: movl 16(%4), %%eax\n"
31997 - "41: movl 20(%4), %%edx\n"
31998 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31999 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32000 " movnti %%eax, 16(%3)\n"
32001 " movnti %%edx, 20(%3)\n"
32002 - "10: movl 24(%4), %%eax\n"
32003 - "51: movl 28(%4), %%edx\n"
32004 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32005 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32006 " movnti %%eax, 24(%3)\n"
32007 " movnti %%edx, 28(%3)\n"
32008 - "11: movl 32(%4), %%eax\n"
32009 - "61: movl 36(%4), %%edx\n"
32010 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32011 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32012 " movnti %%eax, 32(%3)\n"
32013 " movnti %%edx, 36(%3)\n"
32014 - "12: movl 40(%4), %%eax\n"
32015 - "71: movl 44(%4), %%edx\n"
32016 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32017 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32018 " movnti %%eax, 40(%3)\n"
32019 " movnti %%edx, 44(%3)\n"
32020 - "13: movl 48(%4), %%eax\n"
32021 - "81: movl 52(%4), %%edx\n"
32022 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32023 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32024 " movnti %%eax, 48(%3)\n"
32025 " movnti %%edx, 52(%3)\n"
32026 - "14: movl 56(%4), %%eax\n"
32027 - "91: movl 60(%4), %%edx\n"
32028 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32029 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32030 " movnti %%eax, 56(%3)\n"
32031 " movnti %%edx, 60(%3)\n"
32032 " addl $-64, %0\n"
32033 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32034 " shrl $2, %0\n"
32035 " andl $3, %%eax\n"
32036 " cld\n"
32037 - "6: rep; movsl\n"
32038 + "6: rep; "__copyuser_seg" movsl\n"
32039 " movl %%eax,%0\n"
32040 - "7: rep; movsb\n"
32041 + "7: rep; "__copyuser_seg" movsb\n"
32042 "8:\n"
32043 ".section .fixup,\"ax\"\n"
32044 "9: lea 0(%%eax,%0,4),%0\n"
32045 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32046
32047 __asm__ __volatile__(
32048 " .align 2,0x90\n"
32049 - "0: movl 32(%4), %%eax\n"
32050 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32051 " cmpl $67, %0\n"
32052 " jbe 2f\n"
32053 - "1: movl 64(%4), %%eax\n"
32054 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32055 " .align 2,0x90\n"
32056 - "2: movl 0(%4), %%eax\n"
32057 - "21: movl 4(%4), %%edx\n"
32058 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32059 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32060 " movnti %%eax, 0(%3)\n"
32061 " movnti %%edx, 4(%3)\n"
32062 - "3: movl 8(%4), %%eax\n"
32063 - "31: movl 12(%4),%%edx\n"
32064 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32065 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32066 " movnti %%eax, 8(%3)\n"
32067 " movnti %%edx, 12(%3)\n"
32068 - "4: movl 16(%4), %%eax\n"
32069 - "41: movl 20(%4), %%edx\n"
32070 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32071 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32072 " movnti %%eax, 16(%3)\n"
32073 " movnti %%edx, 20(%3)\n"
32074 - "10: movl 24(%4), %%eax\n"
32075 - "51: movl 28(%4), %%edx\n"
32076 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32077 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32078 " movnti %%eax, 24(%3)\n"
32079 " movnti %%edx, 28(%3)\n"
32080 - "11: movl 32(%4), %%eax\n"
32081 - "61: movl 36(%4), %%edx\n"
32082 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32083 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32084 " movnti %%eax, 32(%3)\n"
32085 " movnti %%edx, 36(%3)\n"
32086 - "12: movl 40(%4), %%eax\n"
32087 - "71: movl 44(%4), %%edx\n"
32088 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32089 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32090 " movnti %%eax, 40(%3)\n"
32091 " movnti %%edx, 44(%3)\n"
32092 - "13: movl 48(%4), %%eax\n"
32093 - "81: movl 52(%4), %%edx\n"
32094 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32095 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32096 " movnti %%eax, 48(%3)\n"
32097 " movnti %%edx, 52(%3)\n"
32098 - "14: movl 56(%4), %%eax\n"
32099 - "91: movl 60(%4), %%edx\n"
32100 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32101 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32102 " movnti %%eax, 56(%3)\n"
32103 " movnti %%edx, 60(%3)\n"
32104 " addl $-64, %0\n"
32105 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32106 " shrl $2, %0\n"
32107 " andl $3, %%eax\n"
32108 " cld\n"
32109 - "6: rep; movsl\n"
32110 + "6: rep; "__copyuser_seg" movsl\n"
32111 " movl %%eax,%0\n"
32112 - "7: rep; movsb\n"
32113 + "7: rep; "__copyuser_seg" movsb\n"
32114 "8:\n"
32115 ".section .fixup,\"ax\"\n"
32116 "9: lea 0(%%eax,%0,4),%0\n"
32117 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32118 */
32119 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32120 unsigned long size);
32121 -unsigned long __copy_user_intel(void __user *to, const void *from,
32122 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32123 + unsigned long size);
32124 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32125 unsigned long size);
32126 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32127 const void __user *from, unsigned long size);
32128 #endif /* CONFIG_X86_INTEL_USERCOPY */
32129
32130 /* Generic arbitrary sized copy. */
32131 -#define __copy_user(to, from, size) \
32132 +#define __copy_user(to, from, size, prefix, set, restore) \
32133 do { \
32134 int __d0, __d1, __d2; \
32135 __asm__ __volatile__( \
32136 + set \
32137 " cmp $7,%0\n" \
32138 " jbe 1f\n" \
32139 " movl %1,%0\n" \
32140 " negl %0\n" \
32141 " andl $7,%0\n" \
32142 " subl %0,%3\n" \
32143 - "4: rep; movsb\n" \
32144 + "4: rep; "prefix"movsb\n" \
32145 " movl %3,%0\n" \
32146 " shrl $2,%0\n" \
32147 " andl $3,%3\n" \
32148 " .align 2,0x90\n" \
32149 - "0: rep; movsl\n" \
32150 + "0: rep; "prefix"movsl\n" \
32151 " movl %3,%0\n" \
32152 - "1: rep; movsb\n" \
32153 + "1: rep; "prefix"movsb\n" \
32154 "2:\n" \
32155 + restore \
32156 ".section .fixup,\"ax\"\n" \
32157 "5: addl %3,%0\n" \
32158 " jmp 2b\n" \
32159 @@ -538,14 +650,14 @@ do { \
32160 " negl %0\n" \
32161 " andl $7,%0\n" \
32162 " subl %0,%3\n" \
32163 - "4: rep; movsb\n" \
32164 + "4: rep; "__copyuser_seg"movsb\n" \
32165 " movl %3,%0\n" \
32166 " shrl $2,%0\n" \
32167 " andl $3,%3\n" \
32168 " .align 2,0x90\n" \
32169 - "0: rep; movsl\n" \
32170 + "0: rep; "__copyuser_seg"movsl\n" \
32171 " movl %3,%0\n" \
32172 - "1: rep; movsb\n" \
32173 + "1: rep; "__copyuser_seg"movsb\n" \
32174 "2:\n" \
32175 ".section .fixup,\"ax\"\n" \
32176 "5: addl %3,%0\n" \
32177 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32178 {
32179 stac();
32180 if (movsl_is_ok(to, from, n))
32181 - __copy_user(to, from, n);
32182 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32183 else
32184 - n = __copy_user_intel(to, from, n);
32185 + n = __generic_copy_to_user_intel(to, from, n);
32186 clac();
32187 return n;
32188 }
32189 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32190 {
32191 stac();
32192 if (movsl_is_ok(to, from, n))
32193 - __copy_user(to, from, n);
32194 + __copy_user(to, from, n, __copyuser_seg, "", "");
32195 else
32196 - n = __copy_user_intel((void __user *)to,
32197 - (const void *)from, n);
32198 + n = __generic_copy_from_user_intel(to, from, n);
32199 clac();
32200 return n;
32201 }
32202 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32203 if (n > 64 && cpu_has_xmm2)
32204 n = __copy_user_intel_nocache(to, from, n);
32205 else
32206 - __copy_user(to, from, n);
32207 + __copy_user(to, from, n, __copyuser_seg, "", "");
32208 #else
32209 - __copy_user(to, from, n);
32210 + __copy_user(to, from, n, __copyuser_seg, "", "");
32211 #endif
32212 clac();
32213 return n;
32214 }
32215 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32216
32217 -/**
32218 - * copy_to_user: - Copy a block of data into user space.
32219 - * @to: Destination address, in user space.
32220 - * @from: Source address, in kernel space.
32221 - * @n: Number of bytes to copy.
32222 - *
32223 - * Context: User context only. This function may sleep.
32224 - *
32225 - * Copy data from kernel space to user space.
32226 - *
32227 - * Returns number of bytes that could not be copied.
32228 - * On success, this will be zero.
32229 - */
32230 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32231 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32232 +void __set_fs(mm_segment_t x)
32233 {
32234 - if (access_ok(VERIFY_WRITE, to, n))
32235 - n = __copy_to_user(to, from, n);
32236 - return n;
32237 + switch (x.seg) {
32238 + case 0:
32239 + loadsegment(gs, 0);
32240 + break;
32241 + case TASK_SIZE_MAX:
32242 + loadsegment(gs, __USER_DS);
32243 + break;
32244 + case -1UL:
32245 + loadsegment(gs, __KERNEL_DS);
32246 + break;
32247 + default:
32248 + BUG();
32249 + }
32250 }
32251 -EXPORT_SYMBOL(_copy_to_user);
32252 +EXPORT_SYMBOL(__set_fs);
32253
32254 -/**
32255 - * copy_from_user: - Copy a block of data from user space.
32256 - * @to: Destination address, in kernel space.
32257 - * @from: Source address, in user space.
32258 - * @n: Number of bytes to copy.
32259 - *
32260 - * Context: User context only. This function may sleep.
32261 - *
32262 - * Copy data from user space to kernel space.
32263 - *
32264 - * Returns number of bytes that could not be copied.
32265 - * On success, this will be zero.
32266 - *
32267 - * If some data could not be copied, this function will pad the copied
32268 - * data to the requested size using zero bytes.
32269 - */
32270 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32271 +void set_fs(mm_segment_t x)
32272 {
32273 - if (access_ok(VERIFY_READ, from, n))
32274 - n = __copy_from_user(to, from, n);
32275 - else
32276 - memset(to, 0, n);
32277 - return n;
32278 + current_thread_info()->addr_limit = x;
32279 + __set_fs(x);
32280 }
32281 -EXPORT_SYMBOL(_copy_from_user);
32282 +EXPORT_SYMBOL(set_fs);
32283 +#endif
32284 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32285 index c905e89..01ab928 100644
32286 --- a/arch/x86/lib/usercopy_64.c
32287 +++ b/arch/x86/lib/usercopy_64.c
32288 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32289 might_fault();
32290 /* no memory constraint because it doesn't change any memory gcc knows
32291 about */
32292 + pax_open_userland();
32293 stac();
32294 asm volatile(
32295 " testq %[size8],%[size8]\n"
32296 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32297 _ASM_EXTABLE(0b,3b)
32298 _ASM_EXTABLE(1b,2b)
32299 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32300 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32301 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32302 [zero] "r" (0UL), [eight] "r" (8UL));
32303 clac();
32304 + pax_close_userland();
32305 return size;
32306 }
32307 EXPORT_SYMBOL(__clear_user);
32308 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32309 }
32310 EXPORT_SYMBOL(clear_user);
32311
32312 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32313 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32314 {
32315 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32316 - return copy_user_generic((__force void *)to, (__force void *)from, len);
32317 - }
32318 - return len;
32319 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32320 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32321 + return len;
32322 }
32323 EXPORT_SYMBOL(copy_in_user);
32324
32325 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32326 * it is not necessary to optimize tail handling.
32327 */
32328 __visible unsigned long
32329 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32330 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32331 {
32332 char c;
32333 unsigned zero_len;
32334
32335 + clac();
32336 + pax_close_userland();
32337 for (; len; --len, to++) {
32338 if (__get_user_nocheck(c, from++, sizeof(char)))
32339 break;
32340 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32341 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32342 if (__put_user_nocheck(c, to++, sizeof(char)))
32343 break;
32344 - clac();
32345 return len;
32346 }
32347 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32348 index 6a19ad9..1c48f9a 100644
32349 --- a/arch/x86/mm/Makefile
32350 +++ b/arch/x86/mm/Makefile
32351 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32352 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32353
32354 obj-$(CONFIG_MEMTEST) += memtest.o
32355 +
32356 +quote:="
32357 +obj-$(CONFIG_X86_64) += uderef_64.o
32358 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32359 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32360 index 903ec1e..c4166b2 100644
32361 --- a/arch/x86/mm/extable.c
32362 +++ b/arch/x86/mm/extable.c
32363 @@ -6,12 +6,24 @@
32364 static inline unsigned long
32365 ex_insn_addr(const struct exception_table_entry *x)
32366 {
32367 - return (unsigned long)&x->insn + x->insn;
32368 + unsigned long reloc = 0;
32369 +
32370 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32371 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32372 +#endif
32373 +
32374 + return (unsigned long)&x->insn + x->insn + reloc;
32375 }
32376 static inline unsigned long
32377 ex_fixup_addr(const struct exception_table_entry *x)
32378 {
32379 - return (unsigned long)&x->fixup + x->fixup;
32380 + unsigned long reloc = 0;
32381 +
32382 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32383 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32384 +#endif
32385 +
32386 + return (unsigned long)&x->fixup + x->fixup + reloc;
32387 }
32388
32389 int fixup_exception(struct pt_regs *regs)
32390 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32391 unsigned long new_ip;
32392
32393 #ifdef CONFIG_PNPBIOS
32394 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32395 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32396 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32397 extern u32 pnp_bios_is_utter_crap;
32398 pnp_bios_is_utter_crap = 1;
32399 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32400 i += 4;
32401 p->fixup -= i;
32402 i += 4;
32403 +
32404 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32405 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32406 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32407 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32408 +#endif
32409 +
32410 }
32411 }
32412
32413 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32414 index a241946..d7a04cf 100644
32415 --- a/arch/x86/mm/fault.c
32416 +++ b/arch/x86/mm/fault.c
32417 @@ -14,12 +14,19 @@
32418 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32419 #include <linux/prefetch.h> /* prefetchw */
32420 #include <linux/context_tracking.h> /* exception_enter(), ... */
32421 +#include <linux/unistd.h>
32422 +#include <linux/compiler.h>
32423
32424 #include <asm/traps.h> /* dotraplinkage, ... */
32425 #include <asm/pgalloc.h> /* pgd_*(), ... */
32426 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32427 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32428 #include <asm/vsyscall.h> /* emulate_vsyscall */
32429 +#include <asm/tlbflush.h>
32430 +
32431 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32432 +#include <asm/stacktrace.h>
32433 +#endif
32434
32435 #define CREATE_TRACE_POINTS
32436 #include <asm/trace/exceptions.h>
32437 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32438 int ret = 0;
32439
32440 /* kprobe_running() needs smp_processor_id() */
32441 - if (kprobes_built_in() && !user_mode_vm(regs)) {
32442 + if (kprobes_built_in() && !user_mode(regs)) {
32443 preempt_disable();
32444 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32445 ret = 1;
32446 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32447 return !instr_lo || (instr_lo>>1) == 1;
32448 case 0x00:
32449 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32450 - if (probe_kernel_address(instr, opcode))
32451 + if (user_mode(regs)) {
32452 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32453 + return 0;
32454 + } else if (probe_kernel_address(instr, opcode))
32455 return 0;
32456
32457 *prefetch = (instr_lo == 0xF) &&
32458 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32459 while (instr < max_instr) {
32460 unsigned char opcode;
32461
32462 - if (probe_kernel_address(instr, opcode))
32463 + if (user_mode(regs)) {
32464 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32465 + break;
32466 + } else if (probe_kernel_address(instr, opcode))
32467 break;
32468
32469 instr++;
32470 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32471 force_sig_info(si_signo, &info, tsk);
32472 }
32473
32474 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32475 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32476 +#endif
32477 +
32478 +#ifdef CONFIG_PAX_EMUTRAMP
32479 +static int pax_handle_fetch_fault(struct pt_regs *regs);
32480 +#endif
32481 +
32482 +#ifdef CONFIG_PAX_PAGEEXEC
32483 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32484 +{
32485 + pgd_t *pgd;
32486 + pud_t *pud;
32487 + pmd_t *pmd;
32488 +
32489 + pgd = pgd_offset(mm, address);
32490 + if (!pgd_present(*pgd))
32491 + return NULL;
32492 + pud = pud_offset(pgd, address);
32493 + if (!pud_present(*pud))
32494 + return NULL;
32495 + pmd = pmd_offset(pud, address);
32496 + if (!pmd_present(*pmd))
32497 + return NULL;
32498 + return pmd;
32499 +}
32500 +#endif
32501 +
32502 DEFINE_SPINLOCK(pgd_lock);
32503 LIST_HEAD(pgd_list);
32504
32505 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32506 for (address = VMALLOC_START & PMD_MASK;
32507 address >= TASK_SIZE && address < FIXADDR_TOP;
32508 address += PMD_SIZE) {
32509 +
32510 +#ifdef CONFIG_PAX_PER_CPU_PGD
32511 + unsigned long cpu;
32512 +#else
32513 struct page *page;
32514 +#endif
32515
32516 spin_lock(&pgd_lock);
32517 +
32518 +#ifdef CONFIG_PAX_PER_CPU_PGD
32519 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32520 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32521 + pmd_t *ret;
32522 +
32523 + ret = vmalloc_sync_one(pgd, address);
32524 + if (!ret)
32525 + break;
32526 + pgd = get_cpu_pgd(cpu, kernel);
32527 +#else
32528 list_for_each_entry(page, &pgd_list, lru) {
32529 + pgd_t *pgd;
32530 spinlock_t *pgt_lock;
32531 pmd_t *ret;
32532
32533 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32534 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32535
32536 spin_lock(pgt_lock);
32537 - ret = vmalloc_sync_one(page_address(page), address);
32538 + pgd = page_address(page);
32539 +#endif
32540 +
32541 + ret = vmalloc_sync_one(pgd, address);
32542 +
32543 +#ifndef CONFIG_PAX_PER_CPU_PGD
32544 spin_unlock(pgt_lock);
32545 +#endif
32546
32547 if (!ret)
32548 break;
32549 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32550 * an interrupt in the middle of a task switch..
32551 */
32552 pgd_paddr = read_cr3();
32553 +
32554 +#ifdef CONFIG_PAX_PER_CPU_PGD
32555 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32556 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32557 +#endif
32558 +
32559 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32560 if (!pmd_k)
32561 return -1;
32562 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32563 * happen within a race in page table update. In the later
32564 * case just flush:
32565 */
32566 - pgd = pgd_offset(current->active_mm, address);
32567 +
32568 pgd_ref = pgd_offset_k(address);
32569 if (pgd_none(*pgd_ref))
32570 return -1;
32571
32572 +#ifdef CONFIG_PAX_PER_CPU_PGD
32573 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32574 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32575 + if (pgd_none(*pgd)) {
32576 + set_pgd(pgd, *pgd_ref);
32577 + arch_flush_lazy_mmu_mode();
32578 + } else {
32579 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32580 + }
32581 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32582 +#else
32583 + pgd = pgd_offset(current->active_mm, address);
32584 +#endif
32585 +
32586 if (pgd_none(*pgd)) {
32587 set_pgd(pgd, *pgd_ref);
32588 arch_flush_lazy_mmu_mode();
32589 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32590 static int is_errata100(struct pt_regs *regs, unsigned long address)
32591 {
32592 #ifdef CONFIG_X86_64
32593 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32594 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32595 return 1;
32596 #endif
32597 return 0;
32598 @@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32599 }
32600
32601 static const char nx_warning[] = KERN_CRIT
32602 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32603 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32604 static const char smep_warning[] = KERN_CRIT
32605 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
32606 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32607
32608 static void
32609 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32610 @@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32611 if (!oops_may_print())
32612 return;
32613
32614 - if (error_code & PF_INSTR) {
32615 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32616 unsigned int level;
32617 pgd_t *pgd;
32618 pte_t *pte;
32619 @@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32620 pte = lookup_address_in_pgd(pgd, address, &level);
32621
32622 if (pte && pte_present(*pte) && !pte_exec(*pte))
32623 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32624 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32625 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32626 (pgd_flags(*pgd) & _PAGE_USER) &&
32627 (read_cr4() & X86_CR4_SMEP))
32628 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32629 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32630 }
32631
32632 +#ifdef CONFIG_PAX_KERNEXEC
32633 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32634 + if (current->signal->curr_ip)
32635 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32636 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32637 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32638 + else
32639 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32640 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32641 + }
32642 +#endif
32643 +
32644 printk(KERN_ALERT "BUG: unable to handle kernel ");
32645 if (address < PAGE_SIZE)
32646 printk(KERN_CONT "NULL pointer dereference");
32647 @@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32648 return;
32649 }
32650 #endif
32651 +
32652 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32653 + if (pax_is_fetch_fault(regs, error_code, address)) {
32654 +
32655 +#ifdef CONFIG_PAX_EMUTRAMP
32656 + switch (pax_handle_fetch_fault(regs)) {
32657 + case 2:
32658 + return;
32659 + }
32660 +#endif
32661 +
32662 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32663 + do_group_exit(SIGKILL);
32664 + }
32665 +#endif
32666 +
32667 /* Kernel addresses are always protection faults: */
32668 if (address >= TASK_SIZE)
32669 error_code |= PF_PROT;
32670 @@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32671 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32672 printk(KERN_ERR
32673 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32674 - tsk->comm, tsk->pid, address);
32675 + tsk->comm, task_pid_nr(tsk), address);
32676 code = BUS_MCEERR_AR;
32677 }
32678 #endif
32679 @@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32680 return 1;
32681 }
32682
32683 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32684 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32685 +{
32686 + pte_t *pte;
32687 + pmd_t *pmd;
32688 + spinlock_t *ptl;
32689 + unsigned char pte_mask;
32690 +
32691 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32692 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32693 + return 0;
32694 +
32695 + /* PaX: it's our fault, let's handle it if we can */
32696 +
32697 + /* PaX: take a look at read faults before acquiring any locks */
32698 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32699 + /* instruction fetch attempt from a protected page in user mode */
32700 + up_read(&mm->mmap_sem);
32701 +
32702 +#ifdef CONFIG_PAX_EMUTRAMP
32703 + switch (pax_handle_fetch_fault(regs)) {
32704 + case 2:
32705 + return 1;
32706 + }
32707 +#endif
32708 +
32709 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32710 + do_group_exit(SIGKILL);
32711 + }
32712 +
32713 + pmd = pax_get_pmd(mm, address);
32714 + if (unlikely(!pmd))
32715 + return 0;
32716 +
32717 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32718 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32719 + pte_unmap_unlock(pte, ptl);
32720 + return 0;
32721 + }
32722 +
32723 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32724 + /* write attempt to a protected page in user mode */
32725 + pte_unmap_unlock(pte, ptl);
32726 + return 0;
32727 + }
32728 +
32729 +#ifdef CONFIG_SMP
32730 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32731 +#else
32732 + if (likely(address > get_limit(regs->cs)))
32733 +#endif
32734 + {
32735 + set_pte(pte, pte_mkread(*pte));
32736 + __flush_tlb_one(address);
32737 + pte_unmap_unlock(pte, ptl);
32738 + up_read(&mm->mmap_sem);
32739 + return 1;
32740 + }
32741 +
32742 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32743 +
32744 + /*
32745 + * PaX: fill DTLB with user rights and retry
32746 + */
32747 + __asm__ __volatile__ (
32748 + "orb %2,(%1)\n"
32749 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32750 +/*
32751 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32752 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32753 + * page fault when examined during a TLB load attempt. this is true not only
32754 + * for PTEs holding a non-present entry but also present entries that will
32755 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32756 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32757 + * for our target pages since their PTEs are simply not in the TLBs at all.
32758 +
32759 + * the best thing in omitting it is that we gain around 15-20% speed in the
32760 + * fast path of the page fault handler and can get rid of tracing since we
32761 + * can no longer flush unintended entries.
32762 + */
32763 + "invlpg (%0)\n"
32764 +#endif
32765 + __copyuser_seg"testb $0,(%0)\n"
32766 + "xorb %3,(%1)\n"
32767 + :
32768 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32769 + : "memory", "cc");
32770 + pte_unmap_unlock(pte, ptl);
32771 + up_read(&mm->mmap_sem);
32772 + return 1;
32773 +}
32774 +#endif
32775 +
32776 /*
32777 * Handle a spurious fault caused by a stale TLB entry.
32778 *
32779 @@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
32780 static inline int
32781 access_error(unsigned long error_code, struct vm_area_struct *vma)
32782 {
32783 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32784 + return 1;
32785 +
32786 if (error_code & PF_WRITE) {
32787 /* write, present and write, not present: */
32788 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32789 @@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32790 if (error_code & PF_USER)
32791 return false;
32792
32793 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32794 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32795 return false;
32796
32797 return true;
32798 @@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32799 tsk = current;
32800 mm = tsk->mm;
32801
32802 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32803 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32804 + if (!search_exception_tables(regs->ip)) {
32805 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32806 + bad_area_nosemaphore(regs, error_code, address);
32807 + return;
32808 + }
32809 + if (address < pax_user_shadow_base) {
32810 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32811 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32812 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32813 + } else
32814 + address -= pax_user_shadow_base;
32815 + }
32816 +#endif
32817 +
32818 /*
32819 * Detect and handle instructions that would cause a page fault for
32820 * both a tracked kernel page and a userspace page.
32821 @@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32822 * User-mode registers count as a user access even for any
32823 * potential system fault or CPU buglet:
32824 */
32825 - if (user_mode_vm(regs)) {
32826 + if (user_mode(regs)) {
32827 local_irq_enable();
32828 error_code |= PF_USER;
32829 flags |= FAULT_FLAG_USER;
32830 @@ -1177,6 +1401,11 @@ retry:
32831 might_sleep();
32832 }
32833
32834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32835 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32836 + return;
32837 +#endif
32838 +
32839 vma = find_vma(mm, address);
32840 if (unlikely(!vma)) {
32841 bad_area(regs, error_code, address);
32842 @@ -1188,18 +1417,24 @@ retry:
32843 bad_area(regs, error_code, address);
32844 return;
32845 }
32846 - if (error_code & PF_USER) {
32847 - /*
32848 - * Accessing the stack below %sp is always a bug.
32849 - * The large cushion allows instructions like enter
32850 - * and pusha to work. ("enter $65535, $31" pushes
32851 - * 32 pointers and then decrements %sp by 65535.)
32852 - */
32853 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32854 - bad_area(regs, error_code, address);
32855 - return;
32856 - }
32857 + /*
32858 + * Accessing the stack below %sp is always a bug.
32859 + * The large cushion allows instructions like enter
32860 + * and pusha to work. ("enter $65535, $31" pushes
32861 + * 32 pointers and then decrements %sp by 65535.)
32862 + */
32863 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32864 + bad_area(regs, error_code, address);
32865 + return;
32866 }
32867 +
32868 +#ifdef CONFIG_PAX_SEGMEXEC
32869 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32870 + bad_area(regs, error_code, address);
32871 + return;
32872 + }
32873 +#endif
32874 +
32875 if (unlikely(expand_stack(vma, address))) {
32876 bad_area(regs, error_code, address);
32877 return;
32878 @@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32879 }
32880 NOKPROBE_SYMBOL(trace_do_page_fault);
32881 #endif /* CONFIG_TRACING */
32882 +
32883 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32884 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32885 +{
32886 + struct mm_struct *mm = current->mm;
32887 + unsigned long ip = regs->ip;
32888 +
32889 + if (v8086_mode(regs))
32890 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32891 +
32892 +#ifdef CONFIG_PAX_PAGEEXEC
32893 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32894 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32895 + return true;
32896 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32897 + return true;
32898 + return false;
32899 + }
32900 +#endif
32901 +
32902 +#ifdef CONFIG_PAX_SEGMEXEC
32903 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32904 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32905 + return true;
32906 + return false;
32907 + }
32908 +#endif
32909 +
32910 + return false;
32911 +}
32912 +#endif
32913 +
32914 +#ifdef CONFIG_PAX_EMUTRAMP
32915 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32916 +{
32917 + int err;
32918 +
32919 + do { /* PaX: libffi trampoline emulation */
32920 + unsigned char mov, jmp;
32921 + unsigned int addr1, addr2;
32922 +
32923 +#ifdef CONFIG_X86_64
32924 + if ((regs->ip + 9) >> 32)
32925 + break;
32926 +#endif
32927 +
32928 + err = get_user(mov, (unsigned char __user *)regs->ip);
32929 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32930 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32931 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32932 +
32933 + if (err)
32934 + break;
32935 +
32936 + if (mov == 0xB8 && jmp == 0xE9) {
32937 + regs->ax = addr1;
32938 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32939 + return 2;
32940 + }
32941 + } while (0);
32942 +
32943 + do { /* PaX: gcc trampoline emulation #1 */
32944 + unsigned char mov1, mov2;
32945 + unsigned short jmp;
32946 + unsigned int addr1, addr2;
32947 +
32948 +#ifdef CONFIG_X86_64
32949 + if ((regs->ip + 11) >> 32)
32950 + break;
32951 +#endif
32952 +
32953 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32954 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32955 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32956 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32957 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32958 +
32959 + if (err)
32960 + break;
32961 +
32962 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32963 + regs->cx = addr1;
32964 + regs->ax = addr2;
32965 + regs->ip = addr2;
32966 + return 2;
32967 + }
32968 + } while (0);
32969 +
32970 + do { /* PaX: gcc trampoline emulation #2 */
32971 + unsigned char mov, jmp;
32972 + unsigned int addr1, addr2;
32973 +
32974 +#ifdef CONFIG_X86_64
32975 + if ((regs->ip + 9) >> 32)
32976 + break;
32977 +#endif
32978 +
32979 + err = get_user(mov, (unsigned char __user *)regs->ip);
32980 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32981 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32982 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32983 +
32984 + if (err)
32985 + break;
32986 +
32987 + if (mov == 0xB9 && jmp == 0xE9) {
32988 + regs->cx = addr1;
32989 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32990 + return 2;
32991 + }
32992 + } while (0);
32993 +
32994 + return 1; /* PaX in action */
32995 +}
32996 +
32997 +#ifdef CONFIG_X86_64
32998 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32999 +{
33000 + int err;
33001 +
33002 + do { /* PaX: libffi trampoline emulation */
33003 + unsigned short mov1, mov2, jmp1;
33004 + unsigned char stcclc, jmp2;
33005 + unsigned long addr1, addr2;
33006 +
33007 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33008 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33009 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33010 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33011 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33012 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33013 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33014 +
33015 + if (err)
33016 + break;
33017 +
33018 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33019 + regs->r11 = addr1;
33020 + regs->r10 = addr2;
33021 + if (stcclc == 0xF8)
33022 + regs->flags &= ~X86_EFLAGS_CF;
33023 + else
33024 + regs->flags |= X86_EFLAGS_CF;
33025 + regs->ip = addr1;
33026 + return 2;
33027 + }
33028 + } while (0);
33029 +
33030 + do { /* PaX: gcc trampoline emulation #1 */
33031 + unsigned short mov1, mov2, jmp1;
33032 + unsigned char jmp2;
33033 + unsigned int addr1;
33034 + unsigned long addr2;
33035 +
33036 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33037 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33038 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33039 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33040 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33041 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33042 +
33043 + if (err)
33044 + break;
33045 +
33046 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33047 + regs->r11 = addr1;
33048 + regs->r10 = addr2;
33049 + regs->ip = addr1;
33050 + return 2;
33051 + }
33052 + } while (0);
33053 +
33054 + do { /* PaX: gcc trampoline emulation #2 */
33055 + unsigned short mov1, mov2, jmp1;
33056 + unsigned char jmp2;
33057 + unsigned long addr1, addr2;
33058 +
33059 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33060 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33061 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33062 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33063 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33064 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33065 +
33066 + if (err)
33067 + break;
33068 +
33069 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33070 + regs->r11 = addr1;
33071 + regs->r10 = addr2;
33072 + regs->ip = addr1;
33073 + return 2;
33074 + }
33075 + } while (0);
33076 +
33077 + return 1; /* PaX in action */
33078 +}
33079 +#endif
33080 +
33081 +/*
33082 + * PaX: decide what to do with offenders (regs->ip = fault address)
33083 + *
33084 + * returns 1 when task should be killed
33085 + * 2 when gcc trampoline was detected
33086 + */
33087 +static int pax_handle_fetch_fault(struct pt_regs *regs)
33088 +{
33089 + if (v8086_mode(regs))
33090 + return 1;
33091 +
33092 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33093 + return 1;
33094 +
33095 +#ifdef CONFIG_X86_32
33096 + return pax_handle_fetch_fault_32(regs);
33097 +#else
33098 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33099 + return pax_handle_fetch_fault_32(regs);
33100 + else
33101 + return pax_handle_fetch_fault_64(regs);
33102 +#endif
33103 +}
33104 +#endif
33105 +
33106 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33107 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33108 +{
33109 + long i;
33110 +
33111 + printk(KERN_ERR "PAX: bytes at PC: ");
33112 + for (i = 0; i < 20; i++) {
33113 + unsigned char c;
33114 + if (get_user(c, (unsigned char __force_user *)pc+i))
33115 + printk(KERN_CONT "?? ");
33116 + else
33117 + printk(KERN_CONT "%02x ", c);
33118 + }
33119 + printk("\n");
33120 +
33121 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33122 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
33123 + unsigned long c;
33124 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
33125 +#ifdef CONFIG_X86_32
33126 + printk(KERN_CONT "???????? ");
33127 +#else
33128 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33129 + printk(KERN_CONT "???????? ???????? ");
33130 + else
33131 + printk(KERN_CONT "???????????????? ");
33132 +#endif
33133 + } else {
33134 +#ifdef CONFIG_X86_64
33135 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33136 + printk(KERN_CONT "%08x ", (unsigned int)c);
33137 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33138 + } else
33139 +#endif
33140 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33141 + }
33142 + }
33143 + printk("\n");
33144 +}
33145 +#endif
33146 +
33147 +/**
33148 + * probe_kernel_write(): safely attempt to write to a location
33149 + * @dst: address to write to
33150 + * @src: pointer to the data that shall be written
33151 + * @size: size of the data chunk
33152 + *
33153 + * Safely write to address @dst from the buffer at @src. If a kernel fault
33154 + * happens, handle that and return -EFAULT.
33155 + */
33156 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33157 +{
33158 + long ret;
33159 + mm_segment_t old_fs = get_fs();
33160 +
33161 + set_fs(KERNEL_DS);
33162 + pagefault_disable();
33163 + pax_open_kernel();
33164 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33165 + pax_close_kernel();
33166 + pagefault_enable();
33167 + set_fs(old_fs);
33168 +
33169 + return ret ? -EFAULT : 0;
33170 +}
33171 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33172 index 207d9aef..69030980 100644
33173 --- a/arch/x86/mm/gup.c
33174 +++ b/arch/x86/mm/gup.c
33175 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33176 addr = start;
33177 len = (unsigned long) nr_pages << PAGE_SHIFT;
33178 end = start + len;
33179 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33180 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33181 (void __user *)start, len)))
33182 return 0;
33183
33184 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33185 goto slow_irqon;
33186 #endif
33187
33188 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33189 + (void __user *)start, len)))
33190 + return 0;
33191 +
33192 /*
33193 * XXX: batch / limit 'nr', to avoid large irq off latency
33194 * needs some instrumenting to determine the common sizes used by
33195 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33196 index 4500142..53a363c 100644
33197 --- a/arch/x86/mm/highmem_32.c
33198 +++ b/arch/x86/mm/highmem_32.c
33199 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33200 idx = type + KM_TYPE_NR*smp_processor_id();
33201 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33202 BUG_ON(!pte_none(*(kmap_pte-idx)));
33203 +
33204 + pax_open_kernel();
33205 set_pte(kmap_pte-idx, mk_pte(page, prot));
33206 + pax_close_kernel();
33207 +
33208 arch_flush_lazy_mmu_mode();
33209
33210 return (void *)vaddr;
33211 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33212 index 8b977eb..4732c33 100644
33213 --- a/arch/x86/mm/hugetlbpage.c
33214 +++ b/arch/x86/mm/hugetlbpage.c
33215 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33216 #ifdef CONFIG_HUGETLB_PAGE
33217 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33218 unsigned long addr, unsigned long len,
33219 - unsigned long pgoff, unsigned long flags)
33220 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33221 {
33222 struct hstate *h = hstate_file(file);
33223 struct vm_unmapped_area_info info;
33224 -
33225 +
33226 info.flags = 0;
33227 info.length = len;
33228 info.low_limit = current->mm->mmap_legacy_base;
33229 info.high_limit = TASK_SIZE;
33230 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33231 info.align_offset = 0;
33232 + info.threadstack_offset = offset;
33233 return vm_unmapped_area(&info);
33234 }
33235
33236 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33237 unsigned long addr0, unsigned long len,
33238 - unsigned long pgoff, unsigned long flags)
33239 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33240 {
33241 struct hstate *h = hstate_file(file);
33242 struct vm_unmapped_area_info info;
33243 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33244 info.high_limit = current->mm->mmap_base;
33245 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33246 info.align_offset = 0;
33247 + info.threadstack_offset = offset;
33248 addr = vm_unmapped_area(&info);
33249
33250 /*
33251 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33252 VM_BUG_ON(addr != -ENOMEM);
33253 info.flags = 0;
33254 info.low_limit = TASK_UNMAPPED_BASE;
33255 +
33256 +#ifdef CONFIG_PAX_RANDMMAP
33257 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33258 + info.low_limit += current->mm->delta_mmap;
33259 +#endif
33260 +
33261 info.high_limit = TASK_SIZE;
33262 addr = vm_unmapped_area(&info);
33263 }
33264 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33265 struct hstate *h = hstate_file(file);
33266 struct mm_struct *mm = current->mm;
33267 struct vm_area_struct *vma;
33268 + unsigned long pax_task_size = TASK_SIZE;
33269 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33270
33271 if (len & ~huge_page_mask(h))
33272 return -EINVAL;
33273 - if (len > TASK_SIZE)
33274 +
33275 +#ifdef CONFIG_PAX_SEGMEXEC
33276 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33277 + pax_task_size = SEGMEXEC_TASK_SIZE;
33278 +#endif
33279 +
33280 + pax_task_size -= PAGE_SIZE;
33281 +
33282 + if (len > pax_task_size)
33283 return -ENOMEM;
33284
33285 if (flags & MAP_FIXED) {
33286 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33287 return addr;
33288 }
33289
33290 +#ifdef CONFIG_PAX_RANDMMAP
33291 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33292 +#endif
33293 +
33294 if (addr) {
33295 addr = ALIGN(addr, huge_page_size(h));
33296 vma = find_vma(mm, addr);
33297 - if (TASK_SIZE - len >= addr &&
33298 - (!vma || addr + len <= vma->vm_start))
33299 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33300 return addr;
33301 }
33302 if (mm->get_unmapped_area == arch_get_unmapped_area)
33303 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33304 - pgoff, flags);
33305 + pgoff, flags, offset);
33306 else
33307 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33308 - pgoff, flags);
33309 + pgoff, flags, offset);
33310 }
33311 #endif /* CONFIG_HUGETLB_PAGE */
33312
33313 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33314 index 66dba36..f8082ec 100644
33315 --- a/arch/x86/mm/init.c
33316 +++ b/arch/x86/mm/init.c
33317 @@ -4,6 +4,7 @@
33318 #include <linux/swap.h>
33319 #include <linux/memblock.h>
33320 #include <linux/bootmem.h> /* for max_low_pfn */
33321 +#include <linux/tboot.h>
33322
33323 #include <asm/cacheflush.h>
33324 #include <asm/e820.h>
33325 @@ -17,6 +18,8 @@
33326 #include <asm/proto.h>
33327 #include <asm/dma.h> /* for MAX_DMA_PFN */
33328 #include <asm/microcode.h>
33329 +#include <asm/desc.h>
33330 +#include <asm/bios_ebda.h>
33331
33332 /*
33333 * We need to define the tracepoints somewhere, and tlb.c
33334 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33335 early_ioremap_page_table_range_init();
33336 #endif
33337
33338 +#ifdef CONFIG_PAX_PER_CPU_PGD
33339 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33340 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33341 + KERNEL_PGD_PTRS);
33342 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33343 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33344 + KERNEL_PGD_PTRS);
33345 + load_cr3(get_cpu_pgd(0, kernel));
33346 +#else
33347 load_cr3(swapper_pg_dir);
33348 +#endif
33349 +
33350 __flush_tlb_all();
33351
33352 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33353 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33354 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33355 * mmio resources as well as potential bios/acpi data regions.
33356 */
33357 +
33358 +#ifdef CONFIG_GRKERNSEC_KMEM
33359 +static unsigned int ebda_start __read_only;
33360 +static unsigned int ebda_end __read_only;
33361 +#endif
33362 +
33363 int devmem_is_allowed(unsigned long pagenr)
33364 {
33365 - if (pagenr < 256)
33366 +#ifdef CONFIG_GRKERNSEC_KMEM
33367 + /* allow BDA */
33368 + if (!pagenr)
33369 return 1;
33370 + /* allow EBDA */
33371 + if (pagenr >= ebda_start && pagenr < ebda_end)
33372 + return 1;
33373 + /* if tboot is in use, allow access to its hardcoded serial log range */
33374 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33375 + return 1;
33376 +#else
33377 + if (!pagenr)
33378 + return 1;
33379 +#ifdef CONFIG_VM86
33380 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33381 + return 1;
33382 +#endif
33383 +#endif
33384 +
33385 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33386 + return 1;
33387 +#ifdef CONFIG_GRKERNSEC_KMEM
33388 + /* throw out everything else below 1MB */
33389 + if (pagenr <= 256)
33390 + return 0;
33391 +#endif
33392 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33393 return 0;
33394 if (!page_is_ram(pagenr))
33395 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33396 #endif
33397 }
33398
33399 +#ifdef CONFIG_GRKERNSEC_KMEM
33400 +static inline void gr_init_ebda(void)
33401 +{
33402 + unsigned int ebda_addr;
33403 + unsigned int ebda_size = 0;
33404 +
33405 + ebda_addr = get_bios_ebda();
33406 + if (ebda_addr) {
33407 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33408 + ebda_size <<= 10;
33409 + }
33410 + if (ebda_addr && ebda_size) {
33411 + ebda_start = ebda_addr >> PAGE_SHIFT;
33412 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33413 + } else {
33414 + ebda_start = 0x9f000 >> PAGE_SHIFT;
33415 + ebda_end = 0xa0000 >> PAGE_SHIFT;
33416 + }
33417 +}
33418 +#else
33419 +static inline void gr_init_ebda(void) { }
33420 +#endif
33421 +
33422 void free_initmem(void)
33423 {
33424 +#ifdef CONFIG_PAX_KERNEXEC
33425 +#ifdef CONFIG_X86_32
33426 + /* PaX: limit KERNEL_CS to actual size */
33427 + unsigned long addr, limit;
33428 + struct desc_struct d;
33429 + int cpu;
33430 +#else
33431 + pgd_t *pgd;
33432 + pud_t *pud;
33433 + pmd_t *pmd;
33434 + unsigned long addr, end;
33435 +#endif
33436 +#endif
33437 +
33438 + gr_init_ebda();
33439 +
33440 +#ifdef CONFIG_PAX_KERNEXEC
33441 +#ifdef CONFIG_X86_32
33442 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33443 + limit = (limit - 1UL) >> PAGE_SHIFT;
33444 +
33445 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33446 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33447 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33448 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33449 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33450 + }
33451 +
33452 + /* PaX: make KERNEL_CS read-only */
33453 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33454 + if (!paravirt_enabled())
33455 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33456 +/*
33457 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33458 + pgd = pgd_offset_k(addr);
33459 + pud = pud_offset(pgd, addr);
33460 + pmd = pmd_offset(pud, addr);
33461 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33462 + }
33463 +*/
33464 +#ifdef CONFIG_X86_PAE
33465 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33466 +/*
33467 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33468 + pgd = pgd_offset_k(addr);
33469 + pud = pud_offset(pgd, addr);
33470 + pmd = pmd_offset(pud, addr);
33471 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33472 + }
33473 +*/
33474 +#endif
33475 +
33476 +#ifdef CONFIG_MODULES
33477 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33478 +#endif
33479 +
33480 +#else
33481 + /* PaX: make kernel code/rodata read-only, rest non-executable */
33482 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33483 + pgd = pgd_offset_k(addr);
33484 + pud = pud_offset(pgd, addr);
33485 + pmd = pmd_offset(pud, addr);
33486 + if (!pmd_present(*pmd))
33487 + continue;
33488 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33489 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33490 + else
33491 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33492 + }
33493 +
33494 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33495 + end = addr + KERNEL_IMAGE_SIZE;
33496 + for (; addr < end; addr += PMD_SIZE) {
33497 + pgd = pgd_offset_k(addr);
33498 + pud = pud_offset(pgd, addr);
33499 + pmd = pmd_offset(pud, addr);
33500 + if (!pmd_present(*pmd))
33501 + continue;
33502 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33503 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33504 + }
33505 +#endif
33506 +
33507 + flush_tlb_all();
33508 +#endif
33509 +
33510 free_init_pages("unused kernel",
33511 (unsigned long)(&__init_begin),
33512 (unsigned long)(&__init_end));
33513 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33514 index 7d05565..bfc5338 100644
33515 --- a/arch/x86/mm/init_32.c
33516 +++ b/arch/x86/mm/init_32.c
33517 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33518 bool __read_mostly __vmalloc_start_set = false;
33519
33520 /*
33521 - * Creates a middle page table and puts a pointer to it in the
33522 - * given global directory entry. This only returns the gd entry
33523 - * in non-PAE compilation mode, since the middle layer is folded.
33524 - */
33525 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33526 -{
33527 - pud_t *pud;
33528 - pmd_t *pmd_table;
33529 -
33530 -#ifdef CONFIG_X86_PAE
33531 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33532 - pmd_table = (pmd_t *)alloc_low_page();
33533 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33534 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33535 - pud = pud_offset(pgd, 0);
33536 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33537 -
33538 - return pmd_table;
33539 - }
33540 -#endif
33541 - pud = pud_offset(pgd, 0);
33542 - pmd_table = pmd_offset(pud, 0);
33543 -
33544 - return pmd_table;
33545 -}
33546 -
33547 -/*
33548 * Create a page table and place a pointer to it in a middle page
33549 * directory entry:
33550 */
33551 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33552 pte_t *page_table = (pte_t *)alloc_low_page();
33553
33554 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33555 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33556 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33557 +#else
33558 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33559 +#endif
33560 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33561 }
33562
33563 return pte_offset_kernel(pmd, 0);
33564 }
33565
33566 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33567 +{
33568 + pud_t *pud;
33569 + pmd_t *pmd_table;
33570 +
33571 + pud = pud_offset(pgd, 0);
33572 + pmd_table = pmd_offset(pud, 0);
33573 +
33574 + return pmd_table;
33575 +}
33576 +
33577 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33578 {
33579 int pgd_idx = pgd_index(vaddr);
33580 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33581 int pgd_idx, pmd_idx;
33582 unsigned long vaddr;
33583 pgd_t *pgd;
33584 + pud_t *pud;
33585 pmd_t *pmd;
33586 pte_t *pte = NULL;
33587 unsigned long count = page_table_range_init_count(start, end);
33588 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33589 pgd = pgd_base + pgd_idx;
33590
33591 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33592 - pmd = one_md_table_init(pgd);
33593 - pmd = pmd + pmd_index(vaddr);
33594 + pud = pud_offset(pgd, vaddr);
33595 + pmd = pmd_offset(pud, vaddr);
33596 +
33597 +#ifdef CONFIG_X86_PAE
33598 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33599 +#endif
33600 +
33601 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33602 pmd++, pmd_idx++) {
33603 pte = page_table_kmap_check(one_page_table_init(pmd),
33604 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33605 }
33606 }
33607
33608 -static inline int is_kernel_text(unsigned long addr)
33609 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33610 {
33611 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33612 - return 1;
33613 - return 0;
33614 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33615 + end <= ktla_ktva((unsigned long)_stext)) &&
33616 + (start >= ktla_ktva((unsigned long)_einittext) ||
33617 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33618 +
33619 +#ifdef CONFIG_ACPI_SLEEP
33620 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33621 +#endif
33622 +
33623 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33624 + return 0;
33625 + return 1;
33626 }
33627
33628 /*
33629 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33630 unsigned long last_map_addr = end;
33631 unsigned long start_pfn, end_pfn;
33632 pgd_t *pgd_base = swapper_pg_dir;
33633 - int pgd_idx, pmd_idx, pte_ofs;
33634 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33635 unsigned long pfn;
33636 pgd_t *pgd;
33637 + pud_t *pud;
33638 pmd_t *pmd;
33639 pte_t *pte;
33640 unsigned pages_2m, pages_4k;
33641 @@ -291,8 +295,13 @@ repeat:
33642 pfn = start_pfn;
33643 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33644 pgd = pgd_base + pgd_idx;
33645 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33646 - pmd = one_md_table_init(pgd);
33647 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33648 + pud = pud_offset(pgd, 0);
33649 + pmd = pmd_offset(pud, 0);
33650 +
33651 +#ifdef CONFIG_X86_PAE
33652 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33653 +#endif
33654
33655 if (pfn >= end_pfn)
33656 continue;
33657 @@ -304,14 +313,13 @@ repeat:
33658 #endif
33659 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33660 pmd++, pmd_idx++) {
33661 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33662 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33663
33664 /*
33665 * Map with big pages if possible, otherwise
33666 * create normal page tables:
33667 */
33668 if (use_pse) {
33669 - unsigned int addr2;
33670 pgprot_t prot = PAGE_KERNEL_LARGE;
33671 /*
33672 * first pass will use the same initial
33673 @@ -322,11 +330,7 @@ repeat:
33674 _PAGE_PSE);
33675
33676 pfn &= PMD_MASK >> PAGE_SHIFT;
33677 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33678 - PAGE_OFFSET + PAGE_SIZE-1;
33679 -
33680 - if (is_kernel_text(addr) ||
33681 - is_kernel_text(addr2))
33682 + if (is_kernel_text(address, address + PMD_SIZE))
33683 prot = PAGE_KERNEL_LARGE_EXEC;
33684
33685 pages_2m++;
33686 @@ -343,7 +347,7 @@ repeat:
33687 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33688 pte += pte_ofs;
33689 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33690 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33691 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33692 pgprot_t prot = PAGE_KERNEL;
33693 /*
33694 * first pass will use the same initial
33695 @@ -351,7 +355,7 @@ repeat:
33696 */
33697 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33698
33699 - if (is_kernel_text(addr))
33700 + if (is_kernel_text(address, address + PAGE_SIZE))
33701 prot = PAGE_KERNEL_EXEC;
33702
33703 pages_4k++;
33704 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33705
33706 pud = pud_offset(pgd, va);
33707 pmd = pmd_offset(pud, va);
33708 - if (!pmd_present(*pmd))
33709 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33710 break;
33711
33712 /* should not be large page here */
33713 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33714
33715 static void __init pagetable_init(void)
33716 {
33717 - pgd_t *pgd_base = swapper_pg_dir;
33718 -
33719 - permanent_kmaps_init(pgd_base);
33720 + permanent_kmaps_init(swapper_pg_dir);
33721 }
33722
33723 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33724 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33725 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33726
33727 /* user-defined highmem size */
33728 @@ -787,10 +789,10 @@ void __init mem_init(void)
33729 ((unsigned long)&__init_end -
33730 (unsigned long)&__init_begin) >> 10,
33731
33732 - (unsigned long)&_etext, (unsigned long)&_edata,
33733 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33734 + (unsigned long)&_sdata, (unsigned long)&_edata,
33735 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33736
33737 - (unsigned long)&_text, (unsigned long)&_etext,
33738 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33739 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33740
33741 /*
33742 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33743 if (!kernel_set_to_readonly)
33744 return;
33745
33746 + start = ktla_ktva(start);
33747 pr_debug("Set kernel text: %lx - %lx for read write\n",
33748 start, start+size);
33749
33750 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33751 if (!kernel_set_to_readonly)
33752 return;
33753
33754 + start = ktla_ktva(start);
33755 pr_debug("Set kernel text: %lx - %lx for read only\n",
33756 start, start+size);
33757
33758 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33759 unsigned long start = PFN_ALIGN(_text);
33760 unsigned long size = PFN_ALIGN(_etext) - start;
33761
33762 + start = ktla_ktva(start);
33763 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33764 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33765 size >> 10);
33766 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33767 index 5621c47..5e17b7390 100644
33768 --- a/arch/x86/mm/init_64.c
33769 +++ b/arch/x86/mm/init_64.c
33770 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33771 * around without checking the pgd every time.
33772 */
33773
33774 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33775 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33776 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33777
33778 int force_personality32;
33779 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33780
33781 for (address = start; address <= end; address += PGDIR_SIZE) {
33782 const pgd_t *pgd_ref = pgd_offset_k(address);
33783 +
33784 +#ifdef CONFIG_PAX_PER_CPU_PGD
33785 + unsigned long cpu;
33786 +#else
33787 struct page *page;
33788 +#endif
33789
33790 if (pgd_none(*pgd_ref))
33791 continue;
33792
33793 spin_lock(&pgd_lock);
33794 +
33795 +#ifdef CONFIG_PAX_PER_CPU_PGD
33796 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33797 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33798 +
33799 + if (pgd_none(*pgd))
33800 + set_pgd(pgd, *pgd_ref);
33801 + else
33802 + BUG_ON(pgd_page_vaddr(*pgd)
33803 + != pgd_page_vaddr(*pgd_ref));
33804 + pgd = pgd_offset_cpu(cpu, kernel, address);
33805 +#else
33806 list_for_each_entry(page, &pgd_list, lru) {
33807 pgd_t *pgd;
33808 spinlock_t *pgt_lock;
33809 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33810 /* the pgt_lock only for Xen */
33811 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33812 spin_lock(pgt_lock);
33813 +#endif
33814
33815 if (pgd_none(*pgd))
33816 set_pgd(pgd, *pgd_ref);
33817 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33818 BUG_ON(pgd_page_vaddr(*pgd)
33819 != pgd_page_vaddr(*pgd_ref));
33820
33821 +#ifndef CONFIG_PAX_PER_CPU_PGD
33822 spin_unlock(pgt_lock);
33823 +#endif
33824 +
33825 }
33826 spin_unlock(&pgd_lock);
33827 }
33828 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33829 {
33830 if (pgd_none(*pgd)) {
33831 pud_t *pud = (pud_t *)spp_getpage();
33832 - pgd_populate(&init_mm, pgd, pud);
33833 + pgd_populate_kernel(&init_mm, pgd, pud);
33834 if (pud != pud_offset(pgd, 0))
33835 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33836 pud, pud_offset(pgd, 0));
33837 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33838 {
33839 if (pud_none(*pud)) {
33840 pmd_t *pmd = (pmd_t *) spp_getpage();
33841 - pud_populate(&init_mm, pud, pmd);
33842 + pud_populate_kernel(&init_mm, pud, pmd);
33843 if (pmd != pmd_offset(pud, 0))
33844 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33845 pmd, pmd_offset(pud, 0));
33846 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33847 pmd = fill_pmd(pud, vaddr);
33848 pte = fill_pte(pmd, vaddr);
33849
33850 + pax_open_kernel();
33851 set_pte(pte, new_pte);
33852 + pax_close_kernel();
33853
33854 /*
33855 * It's enough to flush this one mapping.
33856 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33857 pgd = pgd_offset_k((unsigned long)__va(phys));
33858 if (pgd_none(*pgd)) {
33859 pud = (pud_t *) spp_getpage();
33860 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33861 - _PAGE_USER));
33862 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33863 }
33864 pud = pud_offset(pgd, (unsigned long)__va(phys));
33865 if (pud_none(*pud)) {
33866 pmd = (pmd_t *) spp_getpage();
33867 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33868 - _PAGE_USER));
33869 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33870 }
33871 pmd = pmd_offset(pud, phys);
33872 BUG_ON(!pmd_none(*pmd));
33873 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33874 prot);
33875
33876 spin_lock(&init_mm.page_table_lock);
33877 - pud_populate(&init_mm, pud, pmd);
33878 + pud_populate_kernel(&init_mm, pud, pmd);
33879 spin_unlock(&init_mm.page_table_lock);
33880 }
33881 __flush_tlb_all();
33882 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33883 page_size_mask);
33884
33885 spin_lock(&init_mm.page_table_lock);
33886 - pgd_populate(&init_mm, pgd, pud);
33887 + pgd_populate_kernel(&init_mm, pgd, pud);
33888 spin_unlock(&init_mm.page_table_lock);
33889 pgd_changed = true;
33890 }
33891 @@ -1196,8 +1217,8 @@ static struct vm_operations_struct gate_vma_ops = {
33892 static struct vm_area_struct gate_vma = {
33893 .vm_start = VSYSCALL_ADDR,
33894 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33895 - .vm_page_prot = PAGE_READONLY_EXEC,
33896 - .vm_flags = VM_READ | VM_EXEC,
33897 + .vm_page_prot = PAGE_READONLY,
33898 + .vm_flags = VM_READ,
33899 .vm_ops = &gate_vma_ops,
33900 };
33901
33902 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33903 index 7b179b49..6bd17777 100644
33904 --- a/arch/x86/mm/iomap_32.c
33905 +++ b/arch/x86/mm/iomap_32.c
33906 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33907 type = kmap_atomic_idx_push();
33908 idx = type + KM_TYPE_NR * smp_processor_id();
33909 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33910 +
33911 + pax_open_kernel();
33912 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33913 + pax_close_kernel();
33914 +
33915 arch_flush_lazy_mmu_mode();
33916
33917 return (void *)vaddr;
33918 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33919 index baff1da..2816ef4 100644
33920 --- a/arch/x86/mm/ioremap.c
33921 +++ b/arch/x86/mm/ioremap.c
33922 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33923 unsigned long i;
33924
33925 for (i = 0; i < nr_pages; ++i)
33926 - if (pfn_valid(start_pfn + i) &&
33927 - !PageReserved(pfn_to_page(start_pfn + i)))
33928 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33929 + !PageReserved(pfn_to_page(start_pfn + i))))
33930 return 1;
33931
33932 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33933 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33934 *
33935 * Caller must ensure there is only one unmapping for the same pointer.
33936 */
33937 -void iounmap(volatile void __iomem *addr)
33938 +void iounmap(const volatile void __iomem *addr)
33939 {
33940 struct vm_struct *p, *o;
33941
33942 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33943
33944 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33945 if (page_is_ram(start >> PAGE_SHIFT))
33946 +#ifdef CONFIG_HIGHMEM
33947 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33948 +#endif
33949 return __va(phys);
33950
33951 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33952 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33953 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33954 {
33955 if (page_is_ram(phys >> PAGE_SHIFT))
33956 +#ifdef CONFIG_HIGHMEM
33957 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33958 +#endif
33959 return;
33960
33961 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33962 return;
33963 }
33964
33965 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33966 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33967
33968 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33969 {
33970 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33971 early_ioremap_setup();
33972
33973 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33974 - memset(bm_pte, 0, sizeof(bm_pte));
33975 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33976 + pmd_populate_user(&init_mm, pmd, bm_pte);
33977
33978 /*
33979 * The boot-ioremap range spans multiple pmds, for which
33980 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33981 index dd89a13..d77bdcc 100644
33982 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33983 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33984 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33985 * memory (e.g. tracked pages)? For now, we need this to avoid
33986 * invoking kmemcheck for PnP BIOS calls.
33987 */
33988 - if (regs->flags & X86_VM_MASK)
33989 + if (v8086_mode(regs))
33990 return false;
33991 - if (regs->cs != __KERNEL_CS)
33992 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33993 return false;
33994
33995 pte = kmemcheck_pte_lookup(address);
33996 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33997 index 919b912..9267313 100644
33998 --- a/arch/x86/mm/mmap.c
33999 +++ b/arch/x86/mm/mmap.c
34000 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
34001 * Leave an at least ~128 MB hole with possible stack randomization.
34002 */
34003 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
34004 -#define MAX_GAP (TASK_SIZE/6*5)
34005 +#define MAX_GAP (pax_task_size/6*5)
34006
34007 static int mmap_is_legacy(void)
34008 {
34009 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34010 return rnd << PAGE_SHIFT;
34011 }
34012
34013 -static unsigned long mmap_base(void)
34014 +static unsigned long mmap_base(struct mm_struct *mm)
34015 {
34016 unsigned long gap = rlimit(RLIMIT_STACK);
34017 + unsigned long pax_task_size = TASK_SIZE;
34018 +
34019 +#ifdef CONFIG_PAX_SEGMEXEC
34020 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34021 + pax_task_size = SEGMEXEC_TASK_SIZE;
34022 +#endif
34023
34024 if (gap < MIN_GAP)
34025 gap = MIN_GAP;
34026 else if (gap > MAX_GAP)
34027 gap = MAX_GAP;
34028
34029 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34030 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34031 }
34032
34033 /*
34034 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34035 * does, but not when emulating X86_32
34036 */
34037 -static unsigned long mmap_legacy_base(void)
34038 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
34039 {
34040 - if (mmap_is_ia32())
34041 + if (mmap_is_ia32()) {
34042 +
34043 +#ifdef CONFIG_PAX_SEGMEXEC
34044 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34045 + return SEGMEXEC_TASK_UNMAPPED_BASE;
34046 + else
34047 +#endif
34048 +
34049 return TASK_UNMAPPED_BASE;
34050 - else
34051 + } else
34052 return TASK_UNMAPPED_BASE + mmap_rnd();
34053 }
34054
34055 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34056 */
34057 void arch_pick_mmap_layout(struct mm_struct *mm)
34058 {
34059 - mm->mmap_legacy_base = mmap_legacy_base();
34060 - mm->mmap_base = mmap_base();
34061 + mm->mmap_legacy_base = mmap_legacy_base(mm);
34062 + mm->mmap_base = mmap_base(mm);
34063 +
34064 +#ifdef CONFIG_PAX_RANDMMAP
34065 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
34066 + mm->mmap_legacy_base += mm->delta_mmap;
34067 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34068 + }
34069 +#endif
34070
34071 if (mmap_is_legacy()) {
34072 mm->mmap_base = mm->mmap_legacy_base;
34073 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34074 index 0057a7a..95c7edd 100644
34075 --- a/arch/x86/mm/mmio-mod.c
34076 +++ b/arch/x86/mm/mmio-mod.c
34077 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34078 break;
34079 default:
34080 {
34081 - unsigned char *ip = (unsigned char *)instptr;
34082 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34083 my_trace->opcode = MMIO_UNKNOWN_OP;
34084 my_trace->width = 0;
34085 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34086 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34087 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34088 void __iomem *addr)
34089 {
34090 - static atomic_t next_id;
34091 + static atomic_unchecked_t next_id;
34092 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34093 /* These are page-unaligned. */
34094 struct mmiotrace_map map = {
34095 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34096 .private = trace
34097 },
34098 .phys = offset,
34099 - .id = atomic_inc_return(&next_id)
34100 + .id = atomic_inc_return_unchecked(&next_id)
34101 };
34102 map.map_id = trace->id;
34103
34104 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34105 ioremap_trace_core(offset, size, addr);
34106 }
34107
34108 -static void iounmap_trace_core(volatile void __iomem *addr)
34109 +static void iounmap_trace_core(const volatile void __iomem *addr)
34110 {
34111 struct mmiotrace_map map = {
34112 .phys = 0,
34113 @@ -328,7 +328,7 @@ not_enabled:
34114 }
34115 }
34116
34117 -void mmiotrace_iounmap(volatile void __iomem *addr)
34118 +void mmiotrace_iounmap(const volatile void __iomem *addr)
34119 {
34120 might_sleep();
34121 if (is_enabled()) /* recheck and proper locking in *_core() */
34122 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34123 index a32b706..efb308b 100644
34124 --- a/arch/x86/mm/numa.c
34125 +++ b/arch/x86/mm/numa.c
34126 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34127 return true;
34128 }
34129
34130 -static int __init numa_register_memblks(struct numa_meminfo *mi)
34131 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34132 {
34133 unsigned long uninitialized_var(pfn_align);
34134 int i, nid;
34135 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34136 index 36de293..b820ddc 100644
34137 --- a/arch/x86/mm/pageattr.c
34138 +++ b/arch/x86/mm/pageattr.c
34139 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34140 */
34141 #ifdef CONFIG_PCI_BIOS
34142 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34143 - pgprot_val(forbidden) |= _PAGE_NX;
34144 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34145 #endif
34146
34147 /*
34148 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34149 * Does not cover __inittext since that is gone later on. On
34150 * 64bit we do not enforce !NX on the low mapping
34151 */
34152 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
34153 - pgprot_val(forbidden) |= _PAGE_NX;
34154 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34155 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34156
34157 +#ifdef CONFIG_DEBUG_RODATA
34158 /*
34159 * The .rodata section needs to be read-only. Using the pfn
34160 * catches all aliases.
34161 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34162 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34163 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34164 pgprot_val(forbidden) |= _PAGE_RW;
34165 +#endif
34166
34167 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34168 /*
34169 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34170 }
34171 #endif
34172
34173 +#ifdef CONFIG_PAX_KERNEXEC
34174 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34175 + pgprot_val(forbidden) |= _PAGE_RW;
34176 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34177 + }
34178 +#endif
34179 +
34180 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34181
34182 return prot;
34183 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34184 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34185 {
34186 /* change init_mm */
34187 + pax_open_kernel();
34188 set_pte_atomic(kpte, pte);
34189 +
34190 #ifdef CONFIG_X86_32
34191 if (!SHARED_KERNEL_PMD) {
34192 +
34193 +#ifdef CONFIG_PAX_PER_CPU_PGD
34194 + unsigned long cpu;
34195 +#else
34196 struct page *page;
34197 +#endif
34198
34199 +#ifdef CONFIG_PAX_PER_CPU_PGD
34200 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34201 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34202 +#else
34203 list_for_each_entry(page, &pgd_list, lru) {
34204 - pgd_t *pgd;
34205 + pgd_t *pgd = (pgd_t *)page_address(page);
34206 +#endif
34207 +
34208 pud_t *pud;
34209 pmd_t *pmd;
34210
34211 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
34212 + pgd += pgd_index(address);
34213 pud = pud_offset(pgd, address);
34214 pmd = pmd_offset(pud, address);
34215 set_pte_atomic((pte_t *)pmd, pte);
34216 }
34217 }
34218 #endif
34219 + pax_close_kernel();
34220 }
34221
34222 static int
34223 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34224 index 6574388..87e9bef 100644
34225 --- a/arch/x86/mm/pat.c
34226 +++ b/arch/x86/mm/pat.c
34227 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34228
34229 if (!entry) {
34230 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34231 - current->comm, current->pid, start, end - 1);
34232 + current->comm, task_pid_nr(current), start, end - 1);
34233 return -EINVAL;
34234 }
34235
34236 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34237
34238 while (cursor < to) {
34239 if (!devmem_is_allowed(pfn)) {
34240 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34241 - current->comm, from, to - 1);
34242 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34243 + current->comm, from, to - 1, cursor);
34244 return 0;
34245 }
34246 cursor += PAGE_SIZE;
34247 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34248 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34249 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34250 "for [mem %#010Lx-%#010Lx]\n",
34251 - current->comm, current->pid,
34252 + current->comm, task_pid_nr(current),
34253 cattr_name(flags),
34254 base, (unsigned long long)(base + size-1));
34255 return -EINVAL;
34256 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34257 flags = lookup_memtype(paddr);
34258 if (want_flags != flags) {
34259 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34260 - current->comm, current->pid,
34261 + current->comm, task_pid_nr(current),
34262 cattr_name(want_flags),
34263 (unsigned long long)paddr,
34264 (unsigned long long)(paddr + size - 1),
34265 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34266 free_memtype(paddr, paddr + size);
34267 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34268 " for [mem %#010Lx-%#010Lx], got %s\n",
34269 - current->comm, current->pid,
34270 + current->comm, task_pid_nr(current),
34271 cattr_name(want_flags),
34272 (unsigned long long)paddr,
34273 (unsigned long long)(paddr + size - 1),
34274 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34275 index 415f6c4..d319983 100644
34276 --- a/arch/x86/mm/pat_rbtree.c
34277 +++ b/arch/x86/mm/pat_rbtree.c
34278 @@ -160,7 +160,7 @@ success:
34279
34280 failure:
34281 printk(KERN_INFO "%s:%d conflicting memory types "
34282 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34283 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34284 end, cattr_name(found_type), cattr_name(match->type));
34285 return -EBUSY;
34286 }
34287 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34288 index 9f0614d..92ae64a 100644
34289 --- a/arch/x86/mm/pf_in.c
34290 +++ b/arch/x86/mm/pf_in.c
34291 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34292 int i;
34293 enum reason_type rv = OTHERS;
34294
34295 - p = (unsigned char *)ins_addr;
34296 + p = (unsigned char *)ktla_ktva(ins_addr);
34297 p += skip_prefix(p, &prf);
34298 p += get_opcode(p, &opcode);
34299
34300 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34301 struct prefix_bits prf;
34302 int i;
34303
34304 - p = (unsigned char *)ins_addr;
34305 + p = (unsigned char *)ktla_ktva(ins_addr);
34306 p += skip_prefix(p, &prf);
34307 p += get_opcode(p, &opcode);
34308
34309 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34310 struct prefix_bits prf;
34311 int i;
34312
34313 - p = (unsigned char *)ins_addr;
34314 + p = (unsigned char *)ktla_ktva(ins_addr);
34315 p += skip_prefix(p, &prf);
34316 p += get_opcode(p, &opcode);
34317
34318 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34319 struct prefix_bits prf;
34320 int i;
34321
34322 - p = (unsigned char *)ins_addr;
34323 + p = (unsigned char *)ktla_ktva(ins_addr);
34324 p += skip_prefix(p, &prf);
34325 p += get_opcode(p, &opcode);
34326 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34327 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34328 struct prefix_bits prf;
34329 int i;
34330
34331 - p = (unsigned char *)ins_addr;
34332 + p = (unsigned char *)ktla_ktva(ins_addr);
34333 p += skip_prefix(p, &prf);
34334 p += get_opcode(p, &opcode);
34335 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34336 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34337 index 6fb6927..4fc13c0 100644
34338 --- a/arch/x86/mm/pgtable.c
34339 +++ b/arch/x86/mm/pgtable.c
34340 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34341 list_del(&page->lru);
34342 }
34343
34344 -#define UNSHARED_PTRS_PER_PGD \
34345 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34346 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34347 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34348
34349 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34350 +{
34351 + unsigned int count = USER_PGD_PTRS;
34352
34353 + if (!pax_user_shadow_base)
34354 + return;
34355 +
34356 + while (count--)
34357 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34358 +}
34359 +#endif
34360 +
34361 +#ifdef CONFIG_PAX_PER_CPU_PGD
34362 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34363 +{
34364 + unsigned int count = USER_PGD_PTRS;
34365 +
34366 + while (count--) {
34367 + pgd_t pgd;
34368 +
34369 +#ifdef CONFIG_X86_64
34370 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34371 +#else
34372 + pgd = *src++;
34373 +#endif
34374 +
34375 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34376 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34377 +#endif
34378 +
34379 + *dst++ = pgd;
34380 + }
34381 +
34382 +}
34383 +#endif
34384 +
34385 +#ifdef CONFIG_X86_64
34386 +#define pxd_t pud_t
34387 +#define pyd_t pgd_t
34388 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34389 +#define pgtable_pxd_page_ctor(page) true
34390 +#define pgtable_pxd_page_dtor(page)
34391 +#define pxd_free(mm, pud) pud_free((mm), (pud))
34392 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34393 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
34394 +#define PYD_SIZE PGDIR_SIZE
34395 +#else
34396 +#define pxd_t pmd_t
34397 +#define pyd_t pud_t
34398 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34399 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34400 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34401 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
34402 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34403 +#define pyd_offset(mm, address) pud_offset((mm), (address))
34404 +#define PYD_SIZE PUD_SIZE
34405 +#endif
34406 +
34407 +#ifdef CONFIG_PAX_PER_CPU_PGD
34408 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34409 +static inline void pgd_dtor(pgd_t *pgd) {}
34410 +#else
34411 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34412 {
34413 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34414 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34415 pgd_list_del(pgd);
34416 spin_unlock(&pgd_lock);
34417 }
34418 +#endif
34419
34420 /*
34421 * List of all pgd's needed for non-PAE so it can invalidate entries
34422 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34423 * -- nyc
34424 */
34425
34426 -#ifdef CONFIG_X86_PAE
34427 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34428 /*
34429 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34430 * updating the top-level pagetable entries to guarantee the
34431 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34432 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34433 * and initialize the kernel pmds here.
34434 */
34435 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34436 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34437
34438 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34439 {
34440 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34441 */
34442 flush_tlb_mm(mm);
34443 }
34444 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34445 +#define PREALLOCATED_PXDS USER_PGD_PTRS
34446 #else /* !CONFIG_X86_PAE */
34447
34448 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34449 -#define PREALLOCATED_PMDS 0
34450 +#define PREALLOCATED_PXDS 0
34451
34452 #endif /* CONFIG_X86_PAE */
34453
34454 -static void free_pmds(pmd_t *pmds[])
34455 +static void free_pxds(pxd_t *pxds[])
34456 {
34457 int i;
34458
34459 - for(i = 0; i < PREALLOCATED_PMDS; i++)
34460 - if (pmds[i]) {
34461 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34462 - free_page((unsigned long)pmds[i]);
34463 + for(i = 0; i < PREALLOCATED_PXDS; i++)
34464 + if (pxds[i]) {
34465 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34466 + free_page((unsigned long)pxds[i]);
34467 }
34468 }
34469
34470 -static int preallocate_pmds(pmd_t *pmds[])
34471 +static int preallocate_pxds(pxd_t *pxds[])
34472 {
34473 int i;
34474 bool failed = false;
34475
34476 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34477 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34478 - if (!pmd)
34479 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34480 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34481 + if (!pxd)
34482 failed = true;
34483 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34484 - free_page((unsigned long)pmd);
34485 - pmd = NULL;
34486 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34487 + free_page((unsigned long)pxd);
34488 + pxd = NULL;
34489 failed = true;
34490 }
34491 - pmds[i] = pmd;
34492 + pxds[i] = pxd;
34493 }
34494
34495 if (failed) {
34496 - free_pmds(pmds);
34497 + free_pxds(pxds);
34498 return -ENOMEM;
34499 }
34500
34501 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34502 * preallocate which never got a corresponding vma will need to be
34503 * freed manually.
34504 */
34505 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34506 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34507 {
34508 int i;
34509
34510 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34511 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34512 pgd_t pgd = pgdp[i];
34513
34514 if (pgd_val(pgd) != 0) {
34515 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34516 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34517
34518 - pgdp[i] = native_make_pgd(0);
34519 + set_pgd(pgdp + i, native_make_pgd(0));
34520
34521 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34522 - pmd_free(mm, pmd);
34523 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34524 + pxd_free(mm, pxd);
34525 }
34526 }
34527 }
34528
34529 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34530 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34531 {
34532 - pud_t *pud;
34533 + pyd_t *pyd;
34534 int i;
34535
34536 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34537 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34538 return;
34539
34540 - pud = pud_offset(pgd, 0);
34541 -
34542 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34543 - pmd_t *pmd = pmds[i];
34544 +#ifdef CONFIG_X86_64
34545 + pyd = pyd_offset(mm, 0L);
34546 +#else
34547 + pyd = pyd_offset(pgd, 0L);
34548 +#endif
34549
34550 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34551 + pxd_t *pxd = pxds[i];
34552 if (i >= KERNEL_PGD_BOUNDARY)
34553 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34554 - sizeof(pmd_t) * PTRS_PER_PMD);
34555 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34556 + sizeof(pxd_t) * PTRS_PER_PMD);
34557
34558 - pud_populate(mm, pud, pmd);
34559 + pyd_populate(mm, pyd, pxd);
34560 }
34561 }
34562
34563 pgd_t *pgd_alloc(struct mm_struct *mm)
34564 {
34565 pgd_t *pgd;
34566 - pmd_t *pmds[PREALLOCATED_PMDS];
34567 + pxd_t *pxds[PREALLOCATED_PXDS];
34568
34569 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34570
34571 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34572
34573 mm->pgd = pgd;
34574
34575 - if (preallocate_pmds(pmds) != 0)
34576 + if (preallocate_pxds(pxds) != 0)
34577 goto out_free_pgd;
34578
34579 if (paravirt_pgd_alloc(mm) != 0)
34580 - goto out_free_pmds;
34581 + goto out_free_pxds;
34582
34583 /*
34584 * Make sure that pre-populating the pmds is atomic with
34585 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34586 spin_lock(&pgd_lock);
34587
34588 pgd_ctor(mm, pgd);
34589 - pgd_prepopulate_pmd(mm, pgd, pmds);
34590 + pgd_prepopulate_pxd(mm, pgd, pxds);
34591
34592 spin_unlock(&pgd_lock);
34593
34594 return pgd;
34595
34596 -out_free_pmds:
34597 - free_pmds(pmds);
34598 +out_free_pxds:
34599 + free_pxds(pxds);
34600 out_free_pgd:
34601 free_page((unsigned long)pgd);
34602 out:
34603 @@ -313,7 +380,7 @@ out:
34604
34605 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34606 {
34607 - pgd_mop_up_pmds(mm, pgd);
34608 + pgd_mop_up_pxds(mm, pgd);
34609 pgd_dtor(pgd);
34610 paravirt_pgd_free(mm, pgd);
34611 free_page((unsigned long)pgd);
34612 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34613 index 4dd8cf6..f9d143e 100644
34614 --- a/arch/x86/mm/pgtable_32.c
34615 +++ b/arch/x86/mm/pgtable_32.c
34616 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34617 return;
34618 }
34619 pte = pte_offset_kernel(pmd, vaddr);
34620 +
34621 + pax_open_kernel();
34622 if (pte_val(pteval))
34623 set_pte_at(&init_mm, vaddr, pte, pteval);
34624 else
34625 pte_clear(&init_mm, vaddr, pte);
34626 + pax_close_kernel();
34627
34628 /*
34629 * It's enough to flush this one mapping.
34630 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34631 index e666cbb..61788c45 100644
34632 --- a/arch/x86/mm/physaddr.c
34633 +++ b/arch/x86/mm/physaddr.c
34634 @@ -10,7 +10,7 @@
34635 #ifdef CONFIG_X86_64
34636
34637 #ifdef CONFIG_DEBUG_VIRTUAL
34638 -unsigned long __phys_addr(unsigned long x)
34639 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34640 {
34641 unsigned long y = x - __START_KERNEL_map;
34642
34643 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34644 #else
34645
34646 #ifdef CONFIG_DEBUG_VIRTUAL
34647 -unsigned long __phys_addr(unsigned long x)
34648 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34649 {
34650 unsigned long phys_addr = x - PAGE_OFFSET;
34651 /* VMALLOC_* aren't constants */
34652 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34653 index 90555bf..f5f1828 100644
34654 --- a/arch/x86/mm/setup_nx.c
34655 +++ b/arch/x86/mm/setup_nx.c
34656 @@ -5,8 +5,10 @@
34657 #include <asm/pgtable.h>
34658 #include <asm/proto.h>
34659
34660 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34661 static int disable_nx;
34662
34663 +#ifndef CONFIG_PAX_PAGEEXEC
34664 /*
34665 * noexec = on|off
34666 *
34667 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34668 return 0;
34669 }
34670 early_param("noexec", noexec_setup);
34671 +#endif
34672 +
34673 +#endif
34674
34675 void x86_configure_nx(void)
34676 {
34677 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34678 if (cpu_has_nx && !disable_nx)
34679 __supported_pte_mask |= _PAGE_NX;
34680 else
34681 +#endif
34682 __supported_pte_mask &= ~_PAGE_NX;
34683 }
34684
34685 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34686 index ee61c36..e6fedeb 100644
34687 --- a/arch/x86/mm/tlb.c
34688 +++ b/arch/x86/mm/tlb.c
34689 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34690 BUG();
34691 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34692 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34693 +
34694 +#ifndef CONFIG_PAX_PER_CPU_PGD
34695 load_cr3(swapper_pg_dir);
34696 +#endif
34697 +
34698 /*
34699 * This gets called in the idle path where RCU
34700 * functions differently. Tracing normally
34701 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34702 new file mode 100644
34703 index 0000000..dace51c
34704 --- /dev/null
34705 +++ b/arch/x86/mm/uderef_64.c
34706 @@ -0,0 +1,37 @@
34707 +#include <linux/mm.h>
34708 +#include <asm/pgtable.h>
34709 +#include <asm/uaccess.h>
34710 +
34711 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34712 +/* PaX: due to the special call convention these functions must
34713 + * - remain leaf functions under all configurations,
34714 + * - never be called directly, only dereferenced from the wrappers.
34715 + */
34716 +void __pax_open_userland(void)
34717 +{
34718 + unsigned int cpu;
34719 +
34720 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34721 + return;
34722 +
34723 + cpu = raw_get_cpu();
34724 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34725 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34726 + raw_put_cpu_no_resched();
34727 +}
34728 +EXPORT_SYMBOL(__pax_open_userland);
34729 +
34730 +void __pax_close_userland(void)
34731 +{
34732 + unsigned int cpu;
34733 +
34734 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34735 + return;
34736 +
34737 + cpu = raw_get_cpu();
34738 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34739 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34740 + raw_put_cpu_no_resched();
34741 +}
34742 +EXPORT_SYMBOL(__pax_close_userland);
34743 +#endif
34744 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34745 index 6440221..f84b5c7 100644
34746 --- a/arch/x86/net/bpf_jit.S
34747 +++ b/arch/x86/net/bpf_jit.S
34748 @@ -9,6 +9,7 @@
34749 */
34750 #include <linux/linkage.h>
34751 #include <asm/dwarf2.h>
34752 +#include <asm/alternative-asm.h>
34753
34754 /*
34755 * Calling convention :
34756 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34757 jle bpf_slow_path_word
34758 mov (SKBDATA,%rsi),%eax
34759 bswap %eax /* ntohl() */
34760 + pax_force_retaddr
34761 ret
34762
34763 sk_load_half:
34764 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34765 jle bpf_slow_path_half
34766 movzwl (SKBDATA,%rsi),%eax
34767 rol $8,%ax # ntohs()
34768 + pax_force_retaddr
34769 ret
34770
34771 sk_load_byte:
34772 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34773 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34774 jle bpf_slow_path_byte
34775 movzbl (SKBDATA,%rsi),%eax
34776 + pax_force_retaddr
34777 ret
34778
34779 /* rsi contains offset and can be scratched */
34780 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34781 js bpf_error
34782 mov - MAX_BPF_STACK + 32(%rbp),%eax
34783 bswap %eax
34784 + pax_force_retaddr
34785 ret
34786
34787 bpf_slow_path_half:
34788 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34789 mov - MAX_BPF_STACK + 32(%rbp),%ax
34790 rol $8,%ax
34791 movzwl %ax,%eax
34792 + pax_force_retaddr
34793 ret
34794
34795 bpf_slow_path_byte:
34796 bpf_slow_path_common(1)
34797 js bpf_error
34798 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34799 + pax_force_retaddr
34800 ret
34801
34802 #define sk_negative_common(SIZE) \
34803 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34804 sk_negative_common(4)
34805 mov (%rax), %eax
34806 bswap %eax
34807 + pax_force_retaddr
34808 ret
34809
34810 bpf_slow_path_half_neg:
34811 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34812 mov (%rax),%ax
34813 rol $8,%ax
34814 movzwl %ax,%eax
34815 + pax_force_retaddr
34816 ret
34817
34818 bpf_slow_path_byte_neg:
34819 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34820 .globl sk_load_byte_negative_offset
34821 sk_negative_common(1)
34822 movzbl (%rax), %eax
34823 + pax_force_retaddr
34824 ret
34825
34826 bpf_error:
34827 @@ -156,4 +166,5 @@ bpf_error:
34828 mov - MAX_BPF_STACK + 16(%rbp),%r14
34829 mov - MAX_BPF_STACK + 24(%rbp),%r15
34830 leaveq
34831 + pax_force_retaddr
34832 ret
34833 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34834 index c881ba8..71aca2e 100644
34835 --- a/arch/x86/net/bpf_jit_comp.c
34836 +++ b/arch/x86/net/bpf_jit_comp.c
34837 @@ -15,7 +15,11 @@
34838 #include <linux/if_vlan.h>
34839 #include <linux/random.h>
34840
34841 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34842 +int bpf_jit_enable __read_only;
34843 +#else
34844 int bpf_jit_enable __read_mostly;
34845 +#endif
34846
34847 /*
34848 * assembly code in arch/x86/net/bpf_jit.S
34849 @@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
34850 #define CHOOSE_LOAD_FUNC(K, func) \
34851 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34852
34853 -struct bpf_binary_header {
34854 - unsigned int pages;
34855 - /* Note : for security reasons, bpf code will follow a randomly
34856 - * sized amount of int3 instructions
34857 - */
34858 - u8 image[];
34859 -};
34860 -
34861 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34862 +/* Note : for security reasons, bpf code will follow a randomly
34863 + * sized amount of int3 instructions
34864 + */
34865 +static u8 *bpf_alloc_binary(unsigned int proglen,
34866 u8 **image_ptr)
34867 {
34868 unsigned int sz, hole;
34869 - struct bpf_binary_header *header;
34870 + u8 *header;
34871
34872 /* Most of BPF filters are really small,
34873 * but if some of them fill a page, allow at least
34874 * 128 extra bytes to insert a random section of int3
34875 */
34876 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34877 - header = module_alloc(sz);
34878 + sz = round_up(proglen + 128, PAGE_SIZE);
34879 + header = module_alloc_exec(sz);
34880 if (!header)
34881 return NULL;
34882
34883 + pax_open_kernel();
34884 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34885 + pax_close_kernel();
34886
34887 - header->pages = sz / PAGE_SIZE;
34888 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34889 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34890
34891 /* insert a random number of int3 instructions before BPF code */
34892 - *image_ptr = &header->image[prandom_u32() % hole];
34893 + *image_ptr = &header[prandom_u32() % hole];
34894 return header;
34895 }
34896
34897 @@ -864,7 +864,9 @@ common_load:
34898 pr_err("bpf_jit_compile fatal error\n");
34899 return -EFAULT;
34900 }
34901 + pax_open_kernel();
34902 memcpy(image + proglen, temp, ilen);
34903 + pax_close_kernel();
34904 }
34905 proglen += ilen;
34906 addrs[i] = proglen;
34907 @@ -879,7 +881,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
34908
34909 void bpf_int_jit_compile(struct bpf_prog *prog)
34910 {
34911 - struct bpf_binary_header *header = NULL;
34912 + u8 *header = NULL;
34913 int proglen, oldproglen = 0;
34914 struct jit_context ctx = {};
34915 u8 *image = NULL;
34916 @@ -911,7 +913,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34917 if (proglen <= 0) {
34918 image = NULL;
34919 if (header)
34920 - module_free(NULL, header);
34921 + module_free_exec(NULL, image);
34922 goto out;
34923 }
34924 if (image) {
34925 @@ -935,7 +937,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34926
34927 if (image) {
34928 bpf_flush_icache(header, image + proglen);
34929 - set_memory_ro((unsigned long)header, header->pages);
34930 prog->bpf_func = (void *)image;
34931 prog->jited = 1;
34932 }
34933 @@ -943,23 +944,15 @@ out:
34934 kfree(addrs);
34935 }
34936
34937 -static void bpf_jit_free_deferred(struct work_struct *work)
34938 -{
34939 - struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
34940 - unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34941 - struct bpf_binary_header *header = (void *)addr;
34942 -
34943 - set_memory_rw(addr, header->pages);
34944 - module_free(NULL, header);
34945 - kfree(fp);
34946 -}
34947 -
34948 void bpf_jit_free(struct bpf_prog *fp)
34949 {
34950 - if (fp->jited) {
34951 - INIT_WORK(&fp->work, bpf_jit_free_deferred);
34952 - schedule_work(&fp->work);
34953 - } else {
34954 - kfree(fp);
34955 - }
34956 + unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34957 +
34958 + if (!fp->jited)
34959 + goto free_filter;
34960 +
34961 + module_free_exec(NULL, (void *)addr);
34962 +
34963 +free_filter:
34964 + bpf_prog_unlock_free(fp);
34965 }
34966 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34967 index 5d04be5..2beeaa2 100644
34968 --- a/arch/x86/oprofile/backtrace.c
34969 +++ b/arch/x86/oprofile/backtrace.c
34970 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34971 struct stack_frame_ia32 *fp;
34972 unsigned long bytes;
34973
34974 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34975 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34976 if (bytes != 0)
34977 return NULL;
34978
34979 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34980 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34981
34982 oprofile_add_trace(bufhead[0].return_address);
34983
34984 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34985 struct stack_frame bufhead[2];
34986 unsigned long bytes;
34987
34988 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34989 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34990 if (bytes != 0)
34991 return NULL;
34992
34993 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34994 {
34995 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34996
34997 - if (!user_mode_vm(regs)) {
34998 + if (!user_mode(regs)) {
34999 unsigned long stack = kernel_stack_pointer(regs);
35000 if (depth)
35001 dump_trace(NULL, regs, (unsigned long *)stack, 0,
35002 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
35003 index 379e8bd..6386e09 100644
35004 --- a/arch/x86/oprofile/nmi_int.c
35005 +++ b/arch/x86/oprofile/nmi_int.c
35006 @@ -23,6 +23,7 @@
35007 #include <asm/nmi.h>
35008 #include <asm/msr.h>
35009 #include <asm/apic.h>
35010 +#include <asm/pgtable.h>
35011
35012 #include "op_counter.h"
35013 #include "op_x86_model.h"
35014 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35015 if (ret)
35016 return ret;
35017
35018 - if (!model->num_virt_counters)
35019 - model->num_virt_counters = model->num_counters;
35020 + if (!model->num_virt_counters) {
35021 + pax_open_kernel();
35022 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
35023 + pax_close_kernel();
35024 + }
35025
35026 mux_init(ops);
35027
35028 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35029 index 50d86c0..7985318 100644
35030 --- a/arch/x86/oprofile/op_model_amd.c
35031 +++ b/arch/x86/oprofile/op_model_amd.c
35032 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35033 num_counters = AMD64_NUM_COUNTERS;
35034 }
35035
35036 - op_amd_spec.num_counters = num_counters;
35037 - op_amd_spec.num_controls = num_counters;
35038 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35039 + pax_open_kernel();
35040 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35041 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35042 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35043 + pax_close_kernel();
35044
35045 return 0;
35046 }
35047 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35048 index d90528e..0127e2b 100644
35049 --- a/arch/x86/oprofile/op_model_ppro.c
35050 +++ b/arch/x86/oprofile/op_model_ppro.c
35051 @@ -19,6 +19,7 @@
35052 #include <asm/msr.h>
35053 #include <asm/apic.h>
35054 #include <asm/nmi.h>
35055 +#include <asm/pgtable.h>
35056
35057 #include "op_x86_model.h"
35058 #include "op_counter.h"
35059 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35060
35061 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35062
35063 - op_arch_perfmon_spec.num_counters = num_counters;
35064 - op_arch_perfmon_spec.num_controls = num_counters;
35065 + pax_open_kernel();
35066 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35067 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35068 + pax_close_kernel();
35069 }
35070
35071 static int arch_perfmon_init(struct oprofile_operations *ignore)
35072 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35073 index 71e8a67..6a313bb 100644
35074 --- a/arch/x86/oprofile/op_x86_model.h
35075 +++ b/arch/x86/oprofile/op_x86_model.h
35076 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
35077 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35078 struct op_msrs const * const msrs);
35079 #endif
35080 -};
35081 +} __do_const;
35082
35083 struct op_counter_config;
35084
35085 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35086 index b9958c3..24229ab 100644
35087 --- a/arch/x86/pci/intel_mid_pci.c
35088 +++ b/arch/x86/pci/intel_mid_pci.c
35089 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35090 pci_mmcfg_late_init();
35091 pcibios_enable_irq = intel_mid_pci_irq_enable;
35092 pcibios_disable_irq = intel_mid_pci_irq_disable;
35093 - pci_root_ops = intel_mid_pci_ops;
35094 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35095 pci_soc_mode = 1;
35096 /* Continue with standard init */
35097 return 1;
35098 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35099 index eb500c2..eab9e70 100644
35100 --- a/arch/x86/pci/irq.c
35101 +++ b/arch/x86/pci/irq.c
35102 @@ -51,7 +51,7 @@ struct irq_router {
35103 struct irq_router_handler {
35104 u16 vendor;
35105 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35106 -};
35107 +} __do_const;
35108
35109 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35110 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35111 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35112 return 0;
35113 }
35114
35115 -static __initdata struct irq_router_handler pirq_routers[] = {
35116 +static __initconst const struct irq_router_handler pirq_routers[] = {
35117 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35118 { PCI_VENDOR_ID_AL, ali_router_probe },
35119 { PCI_VENDOR_ID_ITE, ite_router_probe },
35120 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35121 static void __init pirq_find_router(struct irq_router *r)
35122 {
35123 struct irq_routing_table *rt = pirq_table;
35124 - struct irq_router_handler *h;
35125 + const struct irq_router_handler *h;
35126
35127 #ifdef CONFIG_PCI_BIOS
35128 if (!rt->signature) {
35129 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35130 return 0;
35131 }
35132
35133 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35134 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35135 {
35136 .callback = fix_broken_hp_bios_irq9,
35137 .ident = "HP Pavilion N5400 Series Laptop",
35138 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35139 index c77b24a..c979855 100644
35140 --- a/arch/x86/pci/pcbios.c
35141 +++ b/arch/x86/pci/pcbios.c
35142 @@ -79,7 +79,7 @@ union bios32 {
35143 static struct {
35144 unsigned long address;
35145 unsigned short segment;
35146 -} bios32_indirect = { 0, __KERNEL_CS };
35147 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35148
35149 /*
35150 * Returns the entry point for the given service, NULL on error
35151 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35152 unsigned long length; /* %ecx */
35153 unsigned long entry; /* %edx */
35154 unsigned long flags;
35155 + struct desc_struct d, *gdt;
35156
35157 local_irq_save(flags);
35158 - __asm__("lcall *(%%edi); cld"
35159 +
35160 + gdt = get_cpu_gdt_table(smp_processor_id());
35161 +
35162 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35163 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35164 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35165 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35166 +
35167 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35168 : "=a" (return_code),
35169 "=b" (address),
35170 "=c" (length),
35171 "=d" (entry)
35172 : "0" (service),
35173 "1" (0),
35174 - "D" (&bios32_indirect));
35175 + "D" (&bios32_indirect),
35176 + "r"(__PCIBIOS_DS)
35177 + : "memory");
35178 +
35179 + pax_open_kernel();
35180 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35181 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35182 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35183 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35184 + pax_close_kernel();
35185 +
35186 local_irq_restore(flags);
35187
35188 switch (return_code) {
35189 - case 0:
35190 - return address + entry;
35191 - case 0x80: /* Not present */
35192 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35193 - return 0;
35194 - default: /* Shouldn't happen */
35195 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35196 - service, return_code);
35197 + case 0: {
35198 + int cpu;
35199 + unsigned char flags;
35200 +
35201 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35202 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35203 + printk(KERN_WARNING "bios32_service: not valid\n");
35204 return 0;
35205 + }
35206 + address = address + PAGE_OFFSET;
35207 + length += 16UL; /* some BIOSs underreport this... */
35208 + flags = 4;
35209 + if (length >= 64*1024*1024) {
35210 + length >>= PAGE_SHIFT;
35211 + flags |= 8;
35212 + }
35213 +
35214 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35215 + gdt = get_cpu_gdt_table(cpu);
35216 + pack_descriptor(&d, address, length, 0x9b, flags);
35217 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35218 + pack_descriptor(&d, address, length, 0x93, flags);
35219 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35220 + }
35221 + return entry;
35222 + }
35223 + case 0x80: /* Not present */
35224 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35225 + return 0;
35226 + default: /* Shouldn't happen */
35227 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35228 + service, return_code);
35229 + return 0;
35230 }
35231 }
35232
35233 static struct {
35234 unsigned long address;
35235 unsigned short segment;
35236 -} pci_indirect = { 0, __KERNEL_CS };
35237 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35238
35239 -static int pci_bios_present;
35240 +static int pci_bios_present __read_only;
35241
35242 static int check_pcibios(void)
35243 {
35244 @@ -131,11 +174,13 @@ static int check_pcibios(void)
35245 unsigned long flags, pcibios_entry;
35246
35247 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35248 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35249 + pci_indirect.address = pcibios_entry;
35250
35251 local_irq_save(flags);
35252 - __asm__(
35253 - "lcall *(%%edi); cld\n\t"
35254 + __asm__("movw %w6, %%ds\n\t"
35255 + "lcall *%%ss:(%%edi); cld\n\t"
35256 + "push %%ss\n\t"
35257 + "pop %%ds\n\t"
35258 "jc 1f\n\t"
35259 "xor %%ah, %%ah\n"
35260 "1:"
35261 @@ -144,7 +189,8 @@ static int check_pcibios(void)
35262 "=b" (ebx),
35263 "=c" (ecx)
35264 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35265 - "D" (&pci_indirect)
35266 + "D" (&pci_indirect),
35267 + "r" (__PCIBIOS_DS)
35268 : "memory");
35269 local_irq_restore(flags);
35270
35271 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35272
35273 switch (len) {
35274 case 1:
35275 - __asm__("lcall *(%%esi); cld\n\t"
35276 + __asm__("movw %w6, %%ds\n\t"
35277 + "lcall *%%ss:(%%esi); cld\n\t"
35278 + "push %%ss\n\t"
35279 + "pop %%ds\n\t"
35280 "jc 1f\n\t"
35281 "xor %%ah, %%ah\n"
35282 "1:"
35283 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35284 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35285 "b" (bx),
35286 "D" ((long)reg),
35287 - "S" (&pci_indirect));
35288 + "S" (&pci_indirect),
35289 + "r" (__PCIBIOS_DS));
35290 /*
35291 * Zero-extend the result beyond 8 bits, do not trust the
35292 * BIOS having done it:
35293 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35294 *value &= 0xff;
35295 break;
35296 case 2:
35297 - __asm__("lcall *(%%esi); cld\n\t"
35298 + __asm__("movw %w6, %%ds\n\t"
35299 + "lcall *%%ss:(%%esi); cld\n\t"
35300 + "push %%ss\n\t"
35301 + "pop %%ds\n\t"
35302 "jc 1f\n\t"
35303 "xor %%ah, %%ah\n"
35304 "1:"
35305 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35306 : "1" (PCIBIOS_READ_CONFIG_WORD),
35307 "b" (bx),
35308 "D" ((long)reg),
35309 - "S" (&pci_indirect));
35310 + "S" (&pci_indirect),
35311 + "r" (__PCIBIOS_DS));
35312 /*
35313 * Zero-extend the result beyond 16 bits, do not trust the
35314 * BIOS having done it:
35315 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35316 *value &= 0xffff;
35317 break;
35318 case 4:
35319 - __asm__("lcall *(%%esi); cld\n\t"
35320 + __asm__("movw %w6, %%ds\n\t"
35321 + "lcall *%%ss:(%%esi); cld\n\t"
35322 + "push %%ss\n\t"
35323 + "pop %%ds\n\t"
35324 "jc 1f\n\t"
35325 "xor %%ah, %%ah\n"
35326 "1:"
35327 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35328 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35329 "b" (bx),
35330 "D" ((long)reg),
35331 - "S" (&pci_indirect));
35332 + "S" (&pci_indirect),
35333 + "r" (__PCIBIOS_DS));
35334 break;
35335 }
35336
35337 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35338
35339 switch (len) {
35340 case 1:
35341 - __asm__("lcall *(%%esi); cld\n\t"
35342 + __asm__("movw %w6, %%ds\n\t"
35343 + "lcall *%%ss:(%%esi); cld\n\t"
35344 + "push %%ss\n\t"
35345 + "pop %%ds\n\t"
35346 "jc 1f\n\t"
35347 "xor %%ah, %%ah\n"
35348 "1:"
35349 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35350 "c" (value),
35351 "b" (bx),
35352 "D" ((long)reg),
35353 - "S" (&pci_indirect));
35354 + "S" (&pci_indirect),
35355 + "r" (__PCIBIOS_DS));
35356 break;
35357 case 2:
35358 - __asm__("lcall *(%%esi); cld\n\t"
35359 + __asm__("movw %w6, %%ds\n\t"
35360 + "lcall *%%ss:(%%esi); cld\n\t"
35361 + "push %%ss\n\t"
35362 + "pop %%ds\n\t"
35363 "jc 1f\n\t"
35364 "xor %%ah, %%ah\n"
35365 "1:"
35366 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35367 "c" (value),
35368 "b" (bx),
35369 "D" ((long)reg),
35370 - "S" (&pci_indirect));
35371 + "S" (&pci_indirect),
35372 + "r" (__PCIBIOS_DS));
35373 break;
35374 case 4:
35375 - __asm__("lcall *(%%esi); cld\n\t"
35376 + __asm__("movw %w6, %%ds\n\t"
35377 + "lcall *%%ss:(%%esi); cld\n\t"
35378 + "push %%ss\n\t"
35379 + "pop %%ds\n\t"
35380 "jc 1f\n\t"
35381 "xor %%ah, %%ah\n"
35382 "1:"
35383 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35384 "c" (value),
35385 "b" (bx),
35386 "D" ((long)reg),
35387 - "S" (&pci_indirect));
35388 + "S" (&pci_indirect),
35389 + "r" (__PCIBIOS_DS));
35390 break;
35391 }
35392
35393 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35394
35395 DBG("PCI: Fetching IRQ routing table... ");
35396 __asm__("push %%es\n\t"
35397 + "movw %w8, %%ds\n\t"
35398 "push %%ds\n\t"
35399 "pop %%es\n\t"
35400 - "lcall *(%%esi); cld\n\t"
35401 + "lcall *%%ss:(%%esi); cld\n\t"
35402 "pop %%es\n\t"
35403 + "push %%ss\n\t"
35404 + "pop %%ds\n"
35405 "jc 1f\n\t"
35406 "xor %%ah, %%ah\n"
35407 "1:"
35408 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35409 "1" (0),
35410 "D" ((long) &opt),
35411 "S" (&pci_indirect),
35412 - "m" (opt)
35413 + "m" (opt),
35414 + "r" (__PCIBIOS_DS)
35415 : "memory");
35416 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35417 if (ret & 0xff00)
35418 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35419 {
35420 int ret;
35421
35422 - __asm__("lcall *(%%esi); cld\n\t"
35423 + __asm__("movw %w5, %%ds\n\t"
35424 + "lcall *%%ss:(%%esi); cld\n\t"
35425 + "push %%ss\n\t"
35426 + "pop %%ds\n"
35427 "jc 1f\n\t"
35428 "xor %%ah, %%ah\n"
35429 "1:"
35430 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35431 : "0" (PCIBIOS_SET_PCI_HW_INT),
35432 "b" ((dev->bus->number << 8) | dev->devfn),
35433 "c" ((irq << 8) | (pin + 10)),
35434 - "S" (&pci_indirect));
35435 + "S" (&pci_indirect),
35436 + "r" (__PCIBIOS_DS));
35437 return !(ret & 0xff00);
35438 }
35439 EXPORT_SYMBOL(pcibios_set_irq_routing);
35440 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35441 index 9ee3491..872192f 100644
35442 --- a/arch/x86/platform/efi/efi_32.c
35443 +++ b/arch/x86/platform/efi/efi_32.c
35444 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35445 {
35446 struct desc_ptr gdt_descr;
35447
35448 +#ifdef CONFIG_PAX_KERNEXEC
35449 + struct desc_struct d;
35450 +#endif
35451 +
35452 local_irq_save(efi_rt_eflags);
35453
35454 load_cr3(initial_page_table);
35455 __flush_tlb_all();
35456
35457 +#ifdef CONFIG_PAX_KERNEXEC
35458 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35459 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35460 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35461 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35462 +#endif
35463 +
35464 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35465 gdt_descr.size = GDT_SIZE - 1;
35466 load_gdt(&gdt_descr);
35467 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35468 {
35469 struct desc_ptr gdt_descr;
35470
35471 +#ifdef CONFIG_PAX_KERNEXEC
35472 + struct desc_struct d;
35473 +
35474 + memset(&d, 0, sizeof d);
35475 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35476 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35477 +#endif
35478 +
35479 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35480 gdt_descr.size = GDT_SIZE - 1;
35481 load_gdt(&gdt_descr);
35482
35483 +#ifdef CONFIG_PAX_PER_CPU_PGD
35484 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35485 +#else
35486 load_cr3(swapper_pg_dir);
35487 +#endif
35488 +
35489 __flush_tlb_all();
35490
35491 local_irq_restore(efi_rt_eflags);
35492 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35493 index 290d397..e09d270 100644
35494 --- a/arch/x86/platform/efi/efi_64.c
35495 +++ b/arch/x86/platform/efi/efi_64.c
35496 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35497 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35498 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35499 }
35500 +
35501 +#ifdef CONFIG_PAX_PER_CPU_PGD
35502 + load_cr3(swapper_pg_dir);
35503 +#endif
35504 +
35505 __flush_tlb_all();
35506 }
35507
35508 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35509 for (pgd = 0; pgd < n_pgds; pgd++)
35510 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35511 kfree(save_pgd);
35512 +
35513 +#ifdef CONFIG_PAX_PER_CPU_PGD
35514 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35515 +#endif
35516 +
35517 __flush_tlb_all();
35518 local_irq_restore(efi_flags);
35519 early_code_mapping_set_exec(0);
35520 @@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35521 unsigned npages;
35522 pgd_t *pgd;
35523
35524 - if (efi_enabled(EFI_OLD_MEMMAP))
35525 + if (efi_enabled(EFI_OLD_MEMMAP)) {
35526 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35527 + * able to execute the EFI services.
35528 + */
35529 + if (__supported_pte_mask & _PAGE_NX) {
35530 + unsigned long addr = (unsigned long) __va(0);
35531 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35532 +
35533 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35534 +#ifdef CONFIG_PAX_PER_CPU_PGD
35535 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35536 +#endif
35537 + set_pgd(pgd_offset_k(addr), pe);
35538 + }
35539 +
35540 return 0;
35541 + }
35542
35543 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35544 pgd = __va(efi_scratch.efi_pgt);
35545 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35546 index fbe66e6..eae5e38 100644
35547 --- a/arch/x86/platform/efi/efi_stub_32.S
35548 +++ b/arch/x86/platform/efi/efi_stub_32.S
35549 @@ -6,7 +6,9 @@
35550 */
35551
35552 #include <linux/linkage.h>
35553 +#include <linux/init.h>
35554 #include <asm/page_types.h>
35555 +#include <asm/segment.h>
35556
35557 /*
35558 * efi_call_phys(void *, ...) is a function with variable parameters.
35559 @@ -20,7 +22,7 @@
35560 * service functions will comply with gcc calling convention, too.
35561 */
35562
35563 -.text
35564 +__INIT
35565 ENTRY(efi_call_phys)
35566 /*
35567 * 0. The function can only be called in Linux kernel. So CS has been
35568 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35569 * The mapping of lower virtual memory has been created in prelog and
35570 * epilog.
35571 */
35572 - movl $1f, %edx
35573 - subl $__PAGE_OFFSET, %edx
35574 - jmp *%edx
35575 +#ifdef CONFIG_PAX_KERNEXEC
35576 + movl $(__KERNEXEC_EFI_DS), %edx
35577 + mov %edx, %ds
35578 + mov %edx, %es
35579 + mov %edx, %ss
35580 + addl $2f,(1f)
35581 + ljmp *(1f)
35582 +
35583 +__INITDATA
35584 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35585 +.previous
35586 +
35587 +2:
35588 + subl $2b,(1b)
35589 +#else
35590 + jmp 1f-__PAGE_OFFSET
35591 1:
35592 +#endif
35593
35594 /*
35595 * 2. Now on the top of stack is the return
35596 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35597 * parameter 2, ..., param n. To make things easy, we save the return
35598 * address of efi_call_phys in a global variable.
35599 */
35600 - popl %edx
35601 - movl %edx, saved_return_addr
35602 - /* get the function pointer into ECX*/
35603 - popl %ecx
35604 - movl %ecx, efi_rt_function_ptr
35605 - movl $2f, %edx
35606 - subl $__PAGE_OFFSET, %edx
35607 - pushl %edx
35608 + popl (saved_return_addr)
35609 + popl (efi_rt_function_ptr)
35610
35611 /*
35612 * 3. Clear PG bit in %CR0.
35613 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35614 /*
35615 * 5. Call the physical function.
35616 */
35617 - jmp *%ecx
35618 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
35619
35620 -2:
35621 /*
35622 * 6. After EFI runtime service returns, control will return to
35623 * following instruction. We'd better readjust stack pointer first.
35624 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35625 movl %cr0, %edx
35626 orl $0x80000000, %edx
35627 movl %edx, %cr0
35628 - jmp 1f
35629 -1:
35630 +
35631 /*
35632 * 8. Now restore the virtual mode from flat mode by
35633 * adding EIP with PAGE_OFFSET.
35634 */
35635 - movl $1f, %edx
35636 - jmp *%edx
35637 +#ifdef CONFIG_PAX_KERNEXEC
35638 + movl $(__KERNEL_DS), %edx
35639 + mov %edx, %ds
35640 + mov %edx, %es
35641 + mov %edx, %ss
35642 + ljmp $(__KERNEL_CS),$1f
35643 +#else
35644 + jmp 1f+__PAGE_OFFSET
35645 +#endif
35646 1:
35647
35648 /*
35649 * 9. Balance the stack. And because EAX contain the return value,
35650 * we'd better not clobber it.
35651 */
35652 - leal efi_rt_function_ptr, %edx
35653 - movl (%edx), %ecx
35654 - pushl %ecx
35655 + pushl (efi_rt_function_ptr)
35656
35657 /*
35658 - * 10. Push the saved return address onto the stack and return.
35659 + * 10. Return to the saved return address.
35660 */
35661 - leal saved_return_addr, %edx
35662 - movl (%edx), %ecx
35663 - pushl %ecx
35664 - ret
35665 + jmpl *(saved_return_addr)
35666 ENDPROC(efi_call_phys)
35667 .previous
35668
35669 -.data
35670 +__INITDATA
35671 saved_return_addr:
35672 .long 0
35673 efi_rt_function_ptr:
35674 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35675 index 5fcda72..cd4dc41 100644
35676 --- a/arch/x86/platform/efi/efi_stub_64.S
35677 +++ b/arch/x86/platform/efi/efi_stub_64.S
35678 @@ -11,6 +11,7 @@
35679 #include <asm/msr.h>
35680 #include <asm/processor-flags.h>
35681 #include <asm/page_types.h>
35682 +#include <asm/alternative-asm.h>
35683
35684 #define SAVE_XMM \
35685 mov %rsp, %rax; \
35686 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35687 RESTORE_PGT
35688 addq $48, %rsp
35689 RESTORE_XMM
35690 + pax_force_retaddr 0, 1
35691 ret
35692 ENDPROC(efi_call)
35693
35694 @@ -245,8 +247,8 @@ efi_gdt64:
35695 .long 0 /* Filled out by user */
35696 .word 0
35697 .quad 0x0000000000000000 /* NULL descriptor */
35698 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
35699 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
35700 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
35701 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
35702 .quad 0x0080890000000000 /* TS descriptor */
35703 .quad 0x0000000000000000 /* TS continued */
35704 efi_gdt64_end:
35705 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35706 index 1bbedc4..eb795b5 100644
35707 --- a/arch/x86/platform/intel-mid/intel-mid.c
35708 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35709 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35710 {
35711 };
35712
35713 -static void intel_mid_reboot(void)
35714 +static void __noreturn intel_mid_reboot(void)
35715 {
35716 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35717 + BUG();
35718 }
35719
35720 static unsigned long __init intel_mid_calibrate_tsc(void)
35721 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35722 index 46aa25c..59a68ed 100644
35723 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35724 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35725 @@ -10,10 +10,9 @@
35726 */
35727
35728
35729 -/* __attribute__((weak)) makes these declarations overridable */
35730 /* For every CPU addition a new get_<cpuname>_ops interface needs
35731 * to be added.
35732 */
35733 -extern void *get_penwell_ops(void) __attribute__((weak));
35734 -extern void *get_cloverview_ops(void) __attribute__((weak));
35735 -extern void *get_tangier_ops(void) __attribute__((weak));
35736 +extern const void *get_penwell_ops(void);
35737 +extern const void *get_cloverview_ops(void);
35738 +extern const void *get_tangier_ops(void);
35739 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35740 index 23381d2..8ddc10e 100644
35741 --- a/arch/x86/platform/intel-mid/mfld.c
35742 +++ b/arch/x86/platform/intel-mid/mfld.c
35743 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35744 pm_power_off = mfld_power_off;
35745 }
35746
35747 -void *get_penwell_ops(void)
35748 +const void *get_penwell_ops(void)
35749 {
35750 return &penwell_ops;
35751 }
35752
35753 -void *get_cloverview_ops(void)
35754 +const void *get_cloverview_ops(void)
35755 {
35756 return &penwell_ops;
35757 }
35758 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35759 index aaca917..66eadbc 100644
35760 --- a/arch/x86/platform/intel-mid/mrfl.c
35761 +++ b/arch/x86/platform/intel-mid/mrfl.c
35762 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35763 .arch_setup = tangier_arch_setup,
35764 };
35765
35766 -void *get_tangier_ops(void)
35767 +const void *get_tangier_ops(void)
35768 {
35769 return &tangier_ops;
35770 }
35771 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35772 index d6ee929..3637cb5 100644
35773 --- a/arch/x86/platform/olpc/olpc_dt.c
35774 +++ b/arch/x86/platform/olpc/olpc_dt.c
35775 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35776 return res;
35777 }
35778
35779 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35780 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35781 .nextprop = olpc_dt_nextprop,
35782 .getproplen = olpc_dt_getproplen,
35783 .getproperty = olpc_dt_getproperty,
35784 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35785 index 6ec7910..ecdbb11 100644
35786 --- a/arch/x86/power/cpu.c
35787 +++ b/arch/x86/power/cpu.c
35788 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35789 static void fix_processor_context(void)
35790 {
35791 int cpu = smp_processor_id();
35792 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35793 -#ifdef CONFIG_X86_64
35794 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35795 - tss_desc tss;
35796 -#endif
35797 + struct tss_struct *t = init_tss + cpu;
35798 +
35799 set_tss_desc(cpu, t); /*
35800 * This just modifies memory; should not be
35801 * necessary. But... This is necessary, because
35802 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35803 */
35804
35805 #ifdef CONFIG_X86_64
35806 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35807 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35808 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35809 -
35810 syscall_init(); /* This sets MSR_*STAR and related */
35811 #endif
35812 load_TR_desc(); /* This does ltr */
35813 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35814 index bad628a..a102610 100644
35815 --- a/arch/x86/realmode/init.c
35816 +++ b/arch/x86/realmode/init.c
35817 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35818 __va(real_mode_header->trampoline_header);
35819
35820 #ifdef CONFIG_X86_32
35821 - trampoline_header->start = __pa_symbol(startup_32_smp);
35822 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35823 +
35824 +#ifdef CONFIG_PAX_KERNEXEC
35825 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35826 +#endif
35827 +
35828 + trampoline_header->boot_cs = __BOOT_CS;
35829 trampoline_header->gdt_limit = __BOOT_DS + 7;
35830 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35831 #else
35832 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35833 *trampoline_cr4_features = read_cr4();
35834
35835 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35836 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35837 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35838 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35839 #endif
35840 }
35841 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35842 index 7c0d7be..d24dc88 100644
35843 --- a/arch/x86/realmode/rm/Makefile
35844 +++ b/arch/x86/realmode/rm/Makefile
35845 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35846
35847 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35848 -I$(srctree)/arch/x86/boot
35849 +ifdef CONSTIFY_PLUGIN
35850 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35851 +endif
35852 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35853 GCOV_PROFILE := n
35854 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35855 index a28221d..93c40f1 100644
35856 --- a/arch/x86/realmode/rm/header.S
35857 +++ b/arch/x86/realmode/rm/header.S
35858 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35859 #endif
35860 /* APM/BIOS reboot */
35861 .long pa_machine_real_restart_asm
35862 -#ifdef CONFIG_X86_64
35863 +#ifdef CONFIG_X86_32
35864 + .long __KERNEL_CS
35865 +#else
35866 .long __KERNEL32_CS
35867 #endif
35868 END(real_mode_header)
35869 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35870 index 48ddd76..c26749f 100644
35871 --- a/arch/x86/realmode/rm/trampoline_32.S
35872 +++ b/arch/x86/realmode/rm/trampoline_32.S
35873 @@ -24,6 +24,12 @@
35874 #include <asm/page_types.h>
35875 #include "realmode.h"
35876
35877 +#ifdef CONFIG_PAX_KERNEXEC
35878 +#define ta(X) (X)
35879 +#else
35880 +#define ta(X) (pa_ ## X)
35881 +#endif
35882 +
35883 .text
35884 .code16
35885
35886 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35887
35888 cli # We should be safe anyway
35889
35890 - movl tr_start, %eax # where we need to go
35891 -
35892 movl $0xA5A5A5A5, trampoline_status
35893 # write marker for master knows we're running
35894
35895 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35896 movw $1, %dx # protected mode (PE) bit
35897 lmsw %dx # into protected mode
35898
35899 - ljmpl $__BOOT_CS, $pa_startup_32
35900 + ljmpl *(trampoline_header)
35901
35902 .section ".text32","ax"
35903 .code32
35904 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35905 .balign 8
35906 GLOBAL(trampoline_header)
35907 tr_start: .space 4
35908 - tr_gdt_pad: .space 2
35909 + tr_boot_cs: .space 2
35910 tr_gdt: .space 6
35911 END(trampoline_header)
35912
35913 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35914 index dac7b20..72dbaca 100644
35915 --- a/arch/x86/realmode/rm/trampoline_64.S
35916 +++ b/arch/x86/realmode/rm/trampoline_64.S
35917 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35918 movl %edx, %gs
35919
35920 movl pa_tr_cr4, %eax
35921 + andl $~X86_CR4_PCIDE, %eax
35922 movl %eax, %cr4 # Enable PAE mode
35923
35924 # Setup trampoline 4 level pagetables
35925 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35926 wrmsr
35927
35928 # Enable paging and in turn activate Long Mode
35929 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35930 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35931 movl %eax, %cr0
35932
35933 /*
35934 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35935 index 9e7e147..25a4158 100644
35936 --- a/arch/x86/realmode/rm/wakeup_asm.S
35937 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35938 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35939 lgdtl pmode_gdt
35940
35941 /* This really couldn't... */
35942 - movl pmode_entry, %eax
35943 movl pmode_cr0, %ecx
35944 movl %ecx, %cr0
35945 - ljmpl $__KERNEL_CS, $pa_startup_32
35946 - /* -> jmp *%eax in trampoline_32.S */
35947 +
35948 + ljmpl *pmode_entry
35949 #else
35950 jmp trampoline_start
35951 #endif
35952 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35953 index 604a37e..e49702a 100644
35954 --- a/arch/x86/tools/Makefile
35955 +++ b/arch/x86/tools/Makefile
35956 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35957
35958 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
35959
35960 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35961 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35962 hostprogs-y += relocs
35963 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35964 PHONY += relocs
35965 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35966 index bbb1d22..e505211 100644
35967 --- a/arch/x86/tools/relocs.c
35968 +++ b/arch/x86/tools/relocs.c
35969 @@ -1,5 +1,7 @@
35970 /* This is included from relocs_32/64.c */
35971
35972 +#include "../../../include/generated/autoconf.h"
35973 +
35974 #define ElfW(type) _ElfW(ELF_BITS, type)
35975 #define _ElfW(bits, type) __ElfW(bits, type)
35976 #define __ElfW(bits, type) Elf##bits##_##type
35977 @@ -11,6 +13,7 @@
35978 #define Elf_Sym ElfW(Sym)
35979
35980 static Elf_Ehdr ehdr;
35981 +static Elf_Phdr *phdr;
35982
35983 struct relocs {
35984 uint32_t *offset;
35985 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35986 }
35987 }
35988
35989 +static void read_phdrs(FILE *fp)
35990 +{
35991 + unsigned int i;
35992 +
35993 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35994 + if (!phdr) {
35995 + die("Unable to allocate %d program headers\n",
35996 + ehdr.e_phnum);
35997 + }
35998 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35999 + die("Seek to %d failed: %s\n",
36000 + ehdr.e_phoff, strerror(errno));
36001 + }
36002 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
36003 + die("Cannot read ELF program headers: %s\n",
36004 + strerror(errno));
36005 + }
36006 + for(i = 0; i < ehdr.e_phnum; i++) {
36007 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36008 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36009 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36010 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36011 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36012 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36013 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36014 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36015 + }
36016 +
36017 +}
36018 +
36019 static void read_shdrs(FILE *fp)
36020 {
36021 - int i;
36022 + unsigned int i;
36023 Elf_Shdr shdr;
36024
36025 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36026 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36027
36028 static void read_strtabs(FILE *fp)
36029 {
36030 - int i;
36031 + unsigned int i;
36032 for (i = 0; i < ehdr.e_shnum; i++) {
36033 struct section *sec = &secs[i];
36034 if (sec->shdr.sh_type != SHT_STRTAB) {
36035 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36036
36037 static void read_symtabs(FILE *fp)
36038 {
36039 - int i,j;
36040 + unsigned int i,j;
36041 for (i = 0; i < ehdr.e_shnum; i++) {
36042 struct section *sec = &secs[i];
36043 if (sec->shdr.sh_type != SHT_SYMTAB) {
36044 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36045 }
36046
36047
36048 -static void read_relocs(FILE *fp)
36049 +static void read_relocs(FILE *fp, int use_real_mode)
36050 {
36051 - int i,j;
36052 + unsigned int i,j;
36053 + uint32_t base;
36054 +
36055 for (i = 0; i < ehdr.e_shnum; i++) {
36056 struct section *sec = &secs[i];
36057 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36058 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36059 die("Cannot read symbol table: %s\n",
36060 strerror(errno));
36061 }
36062 + base = 0;
36063 +
36064 +#ifdef CONFIG_X86_32
36065 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36066 + if (phdr[j].p_type != PT_LOAD )
36067 + continue;
36068 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
36069 + continue;
36070 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36071 + break;
36072 + }
36073 +#endif
36074 +
36075 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36076 Elf_Rel *rel = &sec->reltab[j];
36077 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36078 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36079 rel->r_info = elf_xword_to_cpu(rel->r_info);
36080 #if (SHT_REL_TYPE == SHT_RELA)
36081 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36082 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36083
36084 static void print_absolute_symbols(void)
36085 {
36086 - int i;
36087 + unsigned int i;
36088 const char *format;
36089
36090 if (ELF_BITS == 64)
36091 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36092 for (i = 0; i < ehdr.e_shnum; i++) {
36093 struct section *sec = &secs[i];
36094 char *sym_strtab;
36095 - int j;
36096 + unsigned int j;
36097
36098 if (sec->shdr.sh_type != SHT_SYMTAB) {
36099 continue;
36100 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36101
36102 static void print_absolute_relocs(void)
36103 {
36104 - int i, printed = 0;
36105 + unsigned int i, printed = 0;
36106 const char *format;
36107
36108 if (ELF_BITS == 64)
36109 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36110 struct section *sec_applies, *sec_symtab;
36111 char *sym_strtab;
36112 Elf_Sym *sh_symtab;
36113 - int j;
36114 + unsigned int j;
36115 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36116 continue;
36117 }
36118 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36119 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36120 Elf_Sym *sym, const char *symname))
36121 {
36122 - int i;
36123 + unsigned int i;
36124 /* Walk through the relocations */
36125 for (i = 0; i < ehdr.e_shnum; i++) {
36126 char *sym_strtab;
36127 Elf_Sym *sh_symtab;
36128 struct section *sec_applies, *sec_symtab;
36129 - int j;
36130 + unsigned int j;
36131 struct section *sec = &secs[i];
36132
36133 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36134 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36135 {
36136 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36137 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36138 + char *sym_strtab = sec->link->link->strtab;
36139 +
36140 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36141 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36142 + return 0;
36143 +
36144 +#ifdef CONFIG_PAX_KERNEXEC
36145 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36146 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36147 + return 0;
36148 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36149 + return 0;
36150 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36151 + return 0;
36152 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36153 + return 0;
36154 +#endif
36155
36156 switch (r_type) {
36157 case R_386_NONE:
36158 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36159
36160 static void emit_relocs(int as_text, int use_real_mode)
36161 {
36162 - int i;
36163 + unsigned int i;
36164 int (*write_reloc)(uint32_t, FILE *) = write32;
36165 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36166 const char *symname);
36167 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36168 {
36169 regex_init(use_real_mode);
36170 read_ehdr(fp);
36171 + read_phdrs(fp);
36172 read_shdrs(fp);
36173 read_strtabs(fp);
36174 read_symtabs(fp);
36175 - read_relocs(fp);
36176 + read_relocs(fp, use_real_mode);
36177 if (ELF_BITS == 64)
36178 percpu_init();
36179 if (show_absolute_syms) {
36180 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36181 index f40281e..92728c9 100644
36182 --- a/arch/x86/um/mem_32.c
36183 +++ b/arch/x86/um/mem_32.c
36184 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36185 gate_vma.vm_start = FIXADDR_USER_START;
36186 gate_vma.vm_end = FIXADDR_USER_END;
36187 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36188 - gate_vma.vm_page_prot = __P101;
36189 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36190
36191 return 0;
36192 }
36193 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36194 index 80ffa5b..a33bd15 100644
36195 --- a/arch/x86/um/tls_32.c
36196 +++ b/arch/x86/um/tls_32.c
36197 @@ -260,7 +260,7 @@ out:
36198 if (unlikely(task == current &&
36199 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36200 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36201 - "without flushed TLS.", current->pid);
36202 + "without flushed TLS.", task_pid_nr(current));
36203 }
36204
36205 return 0;
36206 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36207 index 5a4affe..9e2d522 100644
36208 --- a/arch/x86/vdso/Makefile
36209 +++ b/arch/x86/vdso/Makefile
36210 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36211 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36212 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36213
36214 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36215 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36216 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36217 GCOV_PROFILE := n
36218
36219 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36220 index e904c27..b9eaa03 100644
36221 --- a/arch/x86/vdso/vdso32-setup.c
36222 +++ b/arch/x86/vdso/vdso32-setup.c
36223 @@ -14,6 +14,7 @@
36224 #include <asm/cpufeature.h>
36225 #include <asm/processor.h>
36226 #include <asm/vdso.h>
36227 +#include <asm/mman.h>
36228
36229 #ifdef CONFIG_COMPAT_VDSO
36230 #define VDSO_DEFAULT 0
36231 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36232 index 970463b..da82d3e 100644
36233 --- a/arch/x86/vdso/vma.c
36234 +++ b/arch/x86/vdso/vma.c
36235 @@ -16,10 +16,9 @@
36236 #include <asm/vdso.h>
36237 #include <asm/page.h>
36238 #include <asm/hpet.h>
36239 +#include <asm/mman.h>
36240
36241 #if defined(CONFIG_X86_64)
36242 -unsigned int __read_mostly vdso64_enabled = 1;
36243 -
36244 extern unsigned short vdso_sync_cpuid;
36245 #endif
36246
36247 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36248 .pages = no_pages,
36249 };
36250
36251 +#ifdef CONFIG_PAX_RANDMMAP
36252 + if (mm->pax_flags & MF_PAX_RANDMMAP)
36253 + calculate_addr = false;
36254 +#endif
36255 +
36256 if (calculate_addr) {
36257 addr = vdso_addr(current->mm->start_stack,
36258 image->size - image->sym_vvar_start);
36259 @@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36260 down_write(&mm->mmap_sem);
36261
36262 addr = get_unmapped_area(NULL, addr,
36263 - image->size - image->sym_vvar_start, 0, 0);
36264 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36265 if (IS_ERR_VALUE(addr)) {
36266 ret = addr;
36267 goto up_fail;
36268 }
36269
36270 text_start = addr - image->sym_vvar_start;
36271 - current->mm->context.vdso = (void __user *)text_start;
36272 + mm->context.vdso = text_start;
36273
36274 /*
36275 * MAYWRITE to allow gdb to COW and set breakpoints
36276 @@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36277 hpet_address >> PAGE_SHIFT,
36278 PAGE_SIZE,
36279 pgprot_noncached(PAGE_READONLY));
36280 -
36281 - if (ret)
36282 - goto up_fail;
36283 }
36284 #endif
36285
36286 up_fail:
36287 if (ret)
36288 - current->mm->context.vdso = NULL;
36289 + current->mm->context.vdso = 0;
36290
36291 up_write(&mm->mmap_sem);
36292 return ret;
36293 @@ -191,8 +192,8 @@ static int load_vdso32(void)
36294
36295 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36296 current_thread_info()->sysenter_return =
36297 - current->mm->context.vdso +
36298 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36299 + (void __force_user *)(current->mm->context.vdso +
36300 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36301
36302 return 0;
36303 }
36304 @@ -201,9 +202,6 @@ static int load_vdso32(void)
36305 #ifdef CONFIG_X86_64
36306 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36307 {
36308 - if (!vdso64_enabled)
36309 - return 0;
36310 -
36311 return map_vdso(&vdso_image_64, true);
36312 }
36313
36314 @@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36315 int uses_interp)
36316 {
36317 #ifdef CONFIG_X86_X32_ABI
36318 - if (test_thread_flag(TIF_X32)) {
36319 - if (!vdso64_enabled)
36320 - return 0;
36321 -
36322 + if (test_thread_flag(TIF_X32))
36323 return map_vdso(&vdso_image_x32, true);
36324 - }
36325 #endif
36326
36327 return load_vdso32();
36328 @@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36329 return load_vdso32();
36330 }
36331 #endif
36332 -
36333 -#ifdef CONFIG_X86_64
36334 -static __init int vdso_setup(char *s)
36335 -{
36336 - vdso64_enabled = simple_strtoul(s, NULL, 0);
36337 - return 0;
36338 -}
36339 -__setup("vdso=", vdso_setup);
36340 -#endif
36341 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36342 index e88fda8..76ce7ce 100644
36343 --- a/arch/x86/xen/Kconfig
36344 +++ b/arch/x86/xen/Kconfig
36345 @@ -9,6 +9,7 @@ config XEN
36346 select XEN_HAVE_PVMMU
36347 depends on X86_64 || (X86_32 && X86_PAE)
36348 depends on X86_TSC
36349 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36350 help
36351 This is the Linux Xen port. Enabling this will allow the
36352 kernel to boot in a paravirtualized environment under the
36353 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36354 index c0cb11f..bed56ff 100644
36355 --- a/arch/x86/xen/enlighten.c
36356 +++ b/arch/x86/xen/enlighten.c
36357 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36358
36359 struct shared_info xen_dummy_shared_info;
36360
36361 -void *xen_initial_gdt;
36362 -
36363 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36364 __read_mostly int xen_have_vector_callback;
36365 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36366 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36367 {
36368 unsigned long va = dtr->address;
36369 unsigned int size = dtr->size + 1;
36370 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36371 - unsigned long frames[pages];
36372 + unsigned long frames[65536 / PAGE_SIZE];
36373 int f;
36374
36375 /*
36376 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36377 {
36378 unsigned long va = dtr->address;
36379 unsigned int size = dtr->size + 1;
36380 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36381 - unsigned long frames[pages];
36382 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36383 int f;
36384
36385 /*
36386 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36387 * 8-byte entries, or 16 4k pages..
36388 */
36389
36390 - BUG_ON(size > 65536);
36391 + BUG_ON(size > GDT_SIZE);
36392 BUG_ON(va & ~PAGE_MASK);
36393
36394 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36395 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36396 return 0;
36397 }
36398
36399 -static void set_xen_basic_apic_ops(void)
36400 +static void __init set_xen_basic_apic_ops(void)
36401 {
36402 apic->read = xen_apic_read;
36403 apic->write = xen_apic_write;
36404 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36405 #endif
36406 };
36407
36408 -static void xen_reboot(int reason)
36409 +static __noreturn void xen_reboot(int reason)
36410 {
36411 struct sched_shutdown r = { .reason = reason };
36412
36413 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36414 - BUG();
36415 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36416 + BUG();
36417 }
36418
36419 -static void xen_restart(char *msg)
36420 +static __noreturn void xen_restart(char *msg)
36421 {
36422 xen_reboot(SHUTDOWN_reboot);
36423 }
36424
36425 -static void xen_emergency_restart(void)
36426 +static __noreturn void xen_emergency_restart(void)
36427 {
36428 xen_reboot(SHUTDOWN_reboot);
36429 }
36430
36431 -static void xen_machine_halt(void)
36432 +static __noreturn void xen_machine_halt(void)
36433 {
36434 xen_reboot(SHUTDOWN_poweroff);
36435 }
36436
36437 -static void xen_machine_power_off(void)
36438 +static __noreturn void xen_machine_power_off(void)
36439 {
36440 if (pm_power_off)
36441 pm_power_off();
36442 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36443 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36444
36445 /* Work out if we support NX */
36446 - x86_configure_nx();
36447 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36448 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36449 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36450 + unsigned l, h;
36451 +
36452 + __supported_pte_mask |= _PAGE_NX;
36453 + rdmsr(MSR_EFER, l, h);
36454 + l |= EFER_NX;
36455 + wrmsr(MSR_EFER, l, h);
36456 + }
36457 +#endif
36458
36459 /* Get mfn list */
36460 xen_build_dynamic_phys_to_machine();
36461 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36462
36463 machine_ops = xen_machine_ops;
36464
36465 - /*
36466 - * The only reliable way to retain the initial address of the
36467 - * percpu gdt_page is to remember it here, so we can go and
36468 - * mark it RW later, when the initial percpu area is freed.
36469 - */
36470 - xen_initial_gdt = &per_cpu(gdt_page, 0);
36471 -
36472 xen_smp_init();
36473
36474 #ifdef CONFIG_ACPI_NUMA
36475 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36476 index 16fb009..02b7801 100644
36477 --- a/arch/x86/xen/mmu.c
36478 +++ b/arch/x86/xen/mmu.c
36479 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36480 return val;
36481 }
36482
36483 -static pteval_t pte_pfn_to_mfn(pteval_t val)
36484 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36485 {
36486 if (val & _PAGE_PRESENT) {
36487 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36488 @@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36489 * L3_k[511] -> level2_fixmap_pgt */
36490 convert_pfn_mfn(level3_kernel_pgt);
36491
36492 + convert_pfn_mfn(level3_vmalloc_start_pgt);
36493 + convert_pfn_mfn(level3_vmalloc_end_pgt);
36494 + convert_pfn_mfn(level3_vmemmap_pgt);
36495 /* L3_k[511][506] -> level1_fixmap_pgt */
36496 + /* L3_k[511][507] -> level1_vsyscall_pgt */
36497 convert_pfn_mfn(level2_fixmap_pgt);
36498 }
36499 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36500 @@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36501 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36502 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36503 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36504 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36505 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36506 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36507 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36508 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36509 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36510 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36511 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36512 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36513 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36514
36515 /* Pin down new L4 */
36516 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36517 @@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36518 pv_mmu_ops.set_pud = xen_set_pud;
36519 #if PAGETABLE_LEVELS == 4
36520 pv_mmu_ops.set_pgd = xen_set_pgd;
36521 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36522 #endif
36523
36524 /* This will work as long as patching hasn't happened yet
36525 @@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36526 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36527 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36528 .set_pgd = xen_set_pgd_hyper,
36529 + .set_pgd_batched = xen_set_pgd_hyper,
36530
36531 .alloc_pud = xen_alloc_pmd_init,
36532 .release_pud = xen_release_pmd_init,
36533 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36534 index 7005974..54fb05f 100644
36535 --- a/arch/x86/xen/smp.c
36536 +++ b/arch/x86/xen/smp.c
36537 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36538
36539 if (xen_pv_domain()) {
36540 if (!xen_feature(XENFEAT_writable_page_tables))
36541 - /* We've switched to the "real" per-cpu gdt, so make
36542 - * sure the old memory can be recycled. */
36543 - make_lowmem_page_readwrite(xen_initial_gdt);
36544 -
36545 #ifdef CONFIG_X86_32
36546 /*
36547 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36548 * expects __USER_DS
36549 */
36550 - loadsegment(ds, __USER_DS);
36551 - loadsegment(es, __USER_DS);
36552 + loadsegment(ds, __KERNEL_DS);
36553 + loadsegment(es, __KERNEL_DS);
36554 #endif
36555
36556 xen_filter_cpu_maps();
36557 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36558 #ifdef CONFIG_X86_32
36559 /* Note: PVH is not yet supported on x86_32. */
36560 ctxt->user_regs.fs = __KERNEL_PERCPU;
36561 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36562 + savesegment(gs, ctxt->user_regs.gs);
36563 #endif
36564 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36565
36566 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36567 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36568 ctxt->flags = VGCF_IN_KERNEL;
36569 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36570 - ctxt->user_regs.ds = __USER_DS;
36571 - ctxt->user_regs.es = __USER_DS;
36572 + ctxt->user_regs.ds = __KERNEL_DS;
36573 + ctxt->user_regs.es = __KERNEL_DS;
36574 ctxt->user_regs.ss = __KERNEL_DS;
36575
36576 xen_copy_trap_info(ctxt->trap_ctxt);
36577 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36578 int rc;
36579
36580 per_cpu(current_task, cpu) = idle;
36581 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
36582 #ifdef CONFIG_X86_32
36583 irq_ctx_init(cpu);
36584 #else
36585 clear_tsk_thread_flag(idle, TIF_FORK);
36586 #endif
36587 - per_cpu(kernel_stack, cpu) =
36588 - (unsigned long)task_stack_page(idle) -
36589 - KERNEL_STACK_OFFSET + THREAD_SIZE;
36590 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36591
36592 xen_setup_runstate_info(cpu);
36593 xen_setup_timer(cpu);
36594 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36595
36596 void __init xen_smp_init(void)
36597 {
36598 - smp_ops = xen_smp_ops;
36599 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36600 xen_fill_possible_map();
36601 }
36602
36603 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36604 index fd92a64..1f72641 100644
36605 --- a/arch/x86/xen/xen-asm_32.S
36606 +++ b/arch/x86/xen/xen-asm_32.S
36607 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
36608 pushw %fs
36609 movl $(__KERNEL_PERCPU), %eax
36610 movl %eax, %fs
36611 - movl %fs:xen_vcpu, %eax
36612 + mov PER_CPU_VAR(xen_vcpu), %eax
36613 POP_FS
36614 #else
36615 movl %ss:xen_vcpu, %eax
36616 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36617 index 485b695..fda3e7c 100644
36618 --- a/arch/x86/xen/xen-head.S
36619 +++ b/arch/x86/xen/xen-head.S
36620 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36621 #ifdef CONFIG_X86_32
36622 mov %esi,xen_start_info
36623 mov $init_thread_union+THREAD_SIZE,%esp
36624 +#ifdef CONFIG_SMP
36625 + movl $cpu_gdt_table,%edi
36626 + movl $__per_cpu_load,%eax
36627 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36628 + rorl $16,%eax
36629 + movb %al,__KERNEL_PERCPU + 4(%edi)
36630 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36631 + movl $__per_cpu_end - 1,%eax
36632 + subl $__per_cpu_start,%eax
36633 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36634 +#endif
36635 #else
36636 mov %rsi,xen_start_info
36637 mov $init_thread_union+THREAD_SIZE,%rsp
36638 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36639 index 28c7e0b..2acfec7 100644
36640 --- a/arch/x86/xen/xen-ops.h
36641 +++ b/arch/x86/xen/xen-ops.h
36642 @@ -10,8 +10,6 @@
36643 extern const char xen_hypervisor_callback[];
36644 extern const char xen_failsafe_callback[];
36645
36646 -extern void *xen_initial_gdt;
36647 -
36648 struct trap_info;
36649 void xen_copy_trap_info(struct trap_info *traps);
36650
36651 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36652 index 525bd3d..ef888b1 100644
36653 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36654 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36655 @@ -119,9 +119,9 @@
36656 ----------------------------------------------------------------------*/
36657
36658 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36659 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36660 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36661 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36662 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36663
36664 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36665 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36666 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36667 index 2f33760..835e50a 100644
36668 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36669 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36670 @@ -11,6 +11,7 @@
36671 #ifndef _XTENSA_CORE_H
36672 #define _XTENSA_CORE_H
36673
36674 +#include <linux/const.h>
36675
36676 /****************************************************************************
36677 Parameters Useful for Any Code, USER or PRIVILEGED
36678 @@ -112,9 +113,9 @@
36679 ----------------------------------------------------------------------*/
36680
36681 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36682 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36683 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36684 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36685 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36686
36687 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36688 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36689 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36690 index af00795..2bb8105 100644
36691 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36692 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36693 @@ -11,6 +11,7 @@
36694 #ifndef _XTENSA_CORE_CONFIGURATION_H
36695 #define _XTENSA_CORE_CONFIGURATION_H
36696
36697 +#include <linux/const.h>
36698
36699 /****************************************************************************
36700 Parameters Useful for Any Code, USER or PRIVILEGED
36701 @@ -118,9 +119,9 @@
36702 ----------------------------------------------------------------------*/
36703
36704 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36705 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36706 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36707 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36708 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36709
36710 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36711 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36712 diff --git a/block/bio.c b/block/bio.c
36713 index 3e6331d..f970433 100644
36714 --- a/block/bio.c
36715 +++ b/block/bio.c
36716 @@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36717 /*
36718 * Overflow, abort
36719 */
36720 - if (end < start)
36721 + if (end < start || end - start > INT_MAX - nr_pages)
36722 return ERR_PTR(-EINVAL);
36723
36724 nr_pages += end - start;
36725 @@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36726 /*
36727 * Overflow, abort
36728 */
36729 - if (end < start)
36730 + if (end < start || end - start > INT_MAX - nr_pages)
36731 return ERR_PTR(-EINVAL);
36732
36733 nr_pages += end - start;
36734 @@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36735 const int read = bio_data_dir(bio) == READ;
36736 struct bio_map_data *bmd = bio->bi_private;
36737 int i;
36738 - char *p = bmd->sgvecs[0].iov_base;
36739 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36740
36741 bio_for_each_segment_all(bvec, bio, i) {
36742 char *addr = page_address(bvec->bv_page);
36743 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36744 index e17da94..e01cce1 100644
36745 --- a/block/blk-cgroup.c
36746 +++ b/block/blk-cgroup.c
36747 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36748 static struct cgroup_subsys_state *
36749 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36750 {
36751 - static atomic64_t id_seq = ATOMIC64_INIT(0);
36752 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36753 struct blkcg *blkcg;
36754
36755 if (!parent_css) {
36756 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36757
36758 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36759 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36760 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36761 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36762 done:
36763 spin_lock_init(&blkcg->lock);
36764 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36765 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36766 index 0736729..2ec3b48 100644
36767 --- a/block/blk-iopoll.c
36768 +++ b/block/blk-iopoll.c
36769 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36770 }
36771 EXPORT_SYMBOL(blk_iopoll_complete);
36772
36773 -static void blk_iopoll_softirq(struct softirq_action *h)
36774 +static __latent_entropy void blk_iopoll_softirq(void)
36775 {
36776 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36777 int rearm = 0, budget = blk_iopoll_budget;
36778 diff --git a/block/blk-map.c b/block/blk-map.c
36779 index f890d43..97b0482 100644
36780 --- a/block/blk-map.c
36781 +++ b/block/blk-map.c
36782 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36783 if (!len || !kbuf)
36784 return -EINVAL;
36785
36786 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36787 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36788 if (do_copy)
36789 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36790 else
36791 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36792 index 53b1737..08177d2e 100644
36793 --- a/block/blk-softirq.c
36794 +++ b/block/blk-softirq.c
36795 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36796 * Softirq action handler - move entries to local list and loop over them
36797 * while passing them to the queue registered handler.
36798 */
36799 -static void blk_done_softirq(struct softirq_action *h)
36800 +static __latent_entropy void blk_done_softirq(void)
36801 {
36802 struct list_head *cpu_list, local_list;
36803
36804 diff --git a/block/bsg.c b/block/bsg.c
36805 index ff46add..c4ba8ee 100644
36806 --- a/block/bsg.c
36807 +++ b/block/bsg.c
36808 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36809 struct sg_io_v4 *hdr, struct bsg_device *bd,
36810 fmode_t has_write_perm)
36811 {
36812 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36813 + unsigned char *cmdptr;
36814 +
36815 if (hdr->request_len > BLK_MAX_CDB) {
36816 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36817 if (!rq->cmd)
36818 return -ENOMEM;
36819 - }
36820 + cmdptr = rq->cmd;
36821 + } else
36822 + cmdptr = tmpcmd;
36823
36824 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36825 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36826 hdr->request_len))
36827 return -EFAULT;
36828
36829 + if (cmdptr != rq->cmd)
36830 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36831 +
36832 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36833 if (blk_verify_command(rq->cmd, has_write_perm))
36834 return -EPERM;
36835 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36836 index 18b282c..050dbe5 100644
36837 --- a/block/compat_ioctl.c
36838 +++ b/block/compat_ioctl.c
36839 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36840 cgc = compat_alloc_user_space(sizeof(*cgc));
36841 cgc32 = compat_ptr(arg);
36842
36843 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36844 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36845 get_user(data, &cgc32->buffer) ||
36846 put_user(compat_ptr(data), &cgc->buffer) ||
36847 copy_in_user(&cgc->buflen, &cgc32->buflen,
36848 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36849 err |= __get_user(f->spec1, &uf->spec1);
36850 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36851 err |= __get_user(name, &uf->name);
36852 - f->name = compat_ptr(name);
36853 + f->name = (void __force_kernel *)compat_ptr(name);
36854 if (err) {
36855 err = -EFAULT;
36856 goto out;
36857 diff --git a/block/genhd.c b/block/genhd.c
36858 index e6723bd..703e4ac 100644
36859 --- a/block/genhd.c
36860 +++ b/block/genhd.c
36861 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36862
36863 /*
36864 * Register device numbers dev..(dev+range-1)
36865 - * range must be nonzero
36866 + * Noop if @range is zero.
36867 * The hash chain is sorted on range, so that subranges can override.
36868 */
36869 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36870 struct kobject *(*probe)(dev_t, int *, void *),
36871 int (*lock)(dev_t, void *), void *data)
36872 {
36873 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36874 + if (range)
36875 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36876 }
36877
36878 EXPORT_SYMBOL(blk_register_region);
36879
36880 +/* undo blk_register_region(), noop if @range is zero */
36881 void blk_unregister_region(dev_t devt, unsigned long range)
36882 {
36883 - kobj_unmap(bdev_map, devt, range);
36884 + if (range)
36885 + kobj_unmap(bdev_map, devt, range);
36886 }
36887
36888 EXPORT_SYMBOL(blk_unregister_region);
36889 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36890 index 56d08fd..2e07090 100644
36891 --- a/block/partitions/efi.c
36892 +++ b/block/partitions/efi.c
36893 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36894 if (!gpt)
36895 return NULL;
36896
36897 + if (!le32_to_cpu(gpt->num_partition_entries))
36898 + return NULL;
36899 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36900 + if (!pte)
36901 + return NULL;
36902 +
36903 count = le32_to_cpu(gpt->num_partition_entries) *
36904 le32_to_cpu(gpt->sizeof_partition_entry);
36905 - if (!count)
36906 - return NULL;
36907 - pte = kmalloc(count, GFP_KERNEL);
36908 - if (!pte)
36909 - return NULL;
36910 -
36911 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36912 (u8 *) pte, count) < count) {
36913 kfree(pte);
36914 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36915 index a6d6270..c4bb72f 100644
36916 --- a/block/scsi_ioctl.c
36917 +++ b/block/scsi_ioctl.c
36918 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36919 return put_user(0, p);
36920 }
36921
36922 -static int sg_get_timeout(struct request_queue *q)
36923 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36924 {
36925 return jiffies_to_clock_t(q->sg_timeout);
36926 }
36927 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36928 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36929 struct sg_io_hdr *hdr, fmode_t mode)
36930 {
36931 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36932 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36933 + unsigned char *cmdptr;
36934 +
36935 + if (rq->cmd != rq->__cmd)
36936 + cmdptr = rq->cmd;
36937 + else
36938 + cmdptr = tmpcmd;
36939 +
36940 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36941 return -EFAULT;
36942 +
36943 + if (cmdptr != rq->cmd)
36944 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36945 +
36946 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36947 return -EPERM;
36948
36949 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36950 int err;
36951 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36952 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36953 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36954 + unsigned char *cmdptr;
36955
36956 if (!sic)
36957 return -EINVAL;
36958 @@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36959 */
36960 err = -EFAULT;
36961 rq->cmd_len = cmdlen;
36962 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36963 +
36964 + if (rq->cmd != rq->__cmd)
36965 + cmdptr = rq->cmd;
36966 + else
36967 + cmdptr = tmpcmd;
36968 +
36969 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36970 goto error;
36971
36972 + if (rq->cmd != cmdptr)
36973 + memcpy(rq->cmd, cmdptr, cmdlen);
36974 +
36975 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36976 goto error;
36977
36978 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36979 index e592c90..c566114 100644
36980 --- a/crypto/cryptd.c
36981 +++ b/crypto/cryptd.c
36982 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36983
36984 struct cryptd_blkcipher_request_ctx {
36985 crypto_completion_t complete;
36986 -};
36987 +} __no_const;
36988
36989 struct cryptd_hash_ctx {
36990 struct crypto_shash *child;
36991 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36992
36993 struct cryptd_aead_request_ctx {
36994 crypto_completion_t complete;
36995 -};
36996 +} __no_const;
36997
36998 static void cryptd_queue_worker(struct work_struct *work);
36999
37000 diff --git a/crypto/cts.c b/crypto/cts.c
37001 index 042223f..133f087 100644
37002 --- a/crypto/cts.c
37003 +++ b/crypto/cts.c
37004 @@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37005 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37006 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37007 /* 6. Decrypt En to create Pn-1 */
37008 - memset(iv, 0, sizeof(iv));
37009 + memzero_explicit(iv, sizeof(iv));
37010 +
37011 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37012 sg_set_buf(&sgdst[0], d, bsize);
37013 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37014 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37015 index 309d345..1632720 100644
37016 --- a/crypto/pcrypt.c
37017 +++ b/crypto/pcrypt.c
37018 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37019 int ret;
37020
37021 pinst->kobj.kset = pcrypt_kset;
37022 - ret = kobject_add(&pinst->kobj, NULL, name);
37023 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37024 if (!ret)
37025 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37026
37027 diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37028 index 4279480..7bb0474 100644
37029 --- a/crypto/sha1_generic.c
37030 +++ b/crypto/sha1_generic.c
37031 @@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37032 src = data + done;
37033 } while (done + SHA1_BLOCK_SIZE <= len);
37034
37035 - memset(temp, 0, sizeof(temp));
37036 + memzero_explicit(temp, sizeof(temp));
37037 partial = 0;
37038 }
37039 memcpy(sctx->buffer + partial, src, len - done);
37040 diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37041 index 5433667..32c5e5e 100644
37042 --- a/crypto/sha256_generic.c
37043 +++ b/crypto/sha256_generic.c
37044 @@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37045
37046 /* clear any sensitive info... */
37047 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37048 - memset(W, 0, 64 * sizeof(u32));
37049 + memzero_explicit(W, 64 * sizeof(u32));
37050 }
37051
37052 -
37053 static int sha224_init(struct shash_desc *desc)
37054 {
37055 struct sha256_state *sctx = shash_desc_ctx(desc);
37056 @@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37057 sha256_final(desc, D);
37058
37059 memcpy(hash, D, SHA224_DIGEST_SIZE);
37060 - memset(D, 0, SHA256_DIGEST_SIZE);
37061 + memzero_explicit(D, SHA256_DIGEST_SIZE);
37062
37063 return 0;
37064 }
37065 diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37066 index 6ed124f..04d295a 100644
37067 --- a/crypto/sha512_generic.c
37068 +++ b/crypto/sha512_generic.c
37069 @@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37070 sha512_final(desc, D);
37071
37072 memcpy(hash, D, 48);
37073 - memset(D, 0, 64);
37074 + memzero_explicit(D, 64);
37075
37076 return 0;
37077 }
37078 diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37079 index 8740355..3c7af0d 100644
37080 --- a/crypto/tgr192.c
37081 +++ b/crypto/tgr192.c
37082 @@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37083
37084 tgr192_final(desc, D);
37085 memcpy(out, D, TGR160_DIGEST_SIZE);
37086 - memset(D, 0, TGR192_DIGEST_SIZE);
37087 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37088
37089 return 0;
37090 }
37091 @@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37092
37093 tgr192_final(desc, D);
37094 memcpy(out, D, TGR128_DIGEST_SIZE);
37095 - memset(D, 0, TGR192_DIGEST_SIZE);
37096 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37097
37098 return 0;
37099 }
37100 diff --git a/crypto/vmac.c b/crypto/vmac.c
37101 index 2eb11a3..d84c24b 100644
37102 --- a/crypto/vmac.c
37103 +++ b/crypto/vmac.c
37104 @@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37105 }
37106 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37107 memcpy(out, &mac, sizeof(vmac_t));
37108 - memset(&mac, 0, sizeof(vmac_t));
37109 + memzero_explicit(&mac, sizeof(vmac_t));
37110 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37111 ctx->partial_size = 0;
37112 return 0;
37113 diff --git a/crypto/wp512.c b/crypto/wp512.c
37114 index 180f1d6..ec64e77 100644
37115 --- a/crypto/wp512.c
37116 +++ b/crypto/wp512.c
37117 @@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37118 u8 D[64];
37119
37120 wp512_final(desc, D);
37121 - memcpy (out, D, WP384_DIGEST_SIZE);
37122 - memset (D, 0, WP512_DIGEST_SIZE);
37123 + memcpy(out, D, WP384_DIGEST_SIZE);
37124 + memzero_explicit(D, WP512_DIGEST_SIZE);
37125
37126 return 0;
37127 }
37128 @@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37129 u8 D[64];
37130
37131 wp512_final(desc, D);
37132 - memcpy (out, D, WP256_DIGEST_SIZE);
37133 - memset (D, 0, WP512_DIGEST_SIZE);
37134 + memcpy(out, D, WP256_DIGEST_SIZE);
37135 + memzero_explicit(D, WP512_DIGEST_SIZE);
37136
37137 return 0;
37138 }
37139 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37140 index 6921c7f..78e1af7 100644
37141 --- a/drivers/acpi/acpica/hwxfsleep.c
37142 +++ b/drivers/acpi/acpica/hwxfsleep.c
37143 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37144 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37145
37146 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37147 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37148 - acpi_hw_extended_sleep},
37149 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37150 - acpi_hw_extended_wake_prep},
37151 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37152 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37153 + .extended_function = acpi_hw_extended_sleep},
37154 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37155 + .extended_function = acpi_hw_extended_wake_prep},
37156 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37157 + .extended_function = acpi_hw_extended_wake}
37158 };
37159
37160 /*
37161 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37162 index 16129c7..8b675cd 100644
37163 --- a/drivers/acpi/apei/apei-internal.h
37164 +++ b/drivers/acpi/apei/apei-internal.h
37165 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37166 struct apei_exec_ins_type {
37167 u32 flags;
37168 apei_exec_ins_func_t run;
37169 -};
37170 +} __do_const;
37171
37172 struct apei_exec_context {
37173 u32 ip;
37174 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37175 index fc5f780..e5ac91a 100644
37176 --- a/drivers/acpi/apei/ghes.c
37177 +++ b/drivers/acpi/apei/ghes.c
37178 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37179 const struct acpi_hest_generic *generic,
37180 const struct acpi_hest_generic_status *estatus)
37181 {
37182 - static atomic_t seqno;
37183 + static atomic_unchecked_t seqno;
37184 unsigned int curr_seqno;
37185 char pfx_seq[64];
37186
37187 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37188 else
37189 pfx = KERN_ERR;
37190 }
37191 - curr_seqno = atomic_inc_return(&seqno);
37192 + curr_seqno = atomic_inc_return_unchecked(&seqno);
37193 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37194 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37195 pfx_seq, generic->header.source_id);
37196 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37197 index a83e3c6..c3d617f 100644
37198 --- a/drivers/acpi/bgrt.c
37199 +++ b/drivers/acpi/bgrt.c
37200 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37201 if (!bgrt_image)
37202 return -ENODEV;
37203
37204 - bin_attr_image.private = bgrt_image;
37205 - bin_attr_image.size = bgrt_image_size;
37206 + pax_open_kernel();
37207 + *(void **)&bin_attr_image.private = bgrt_image;
37208 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
37209 + pax_close_kernel();
37210
37211 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37212 if (!bgrt_kobj)
37213 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37214 index 36eb42e..3b2f47e 100644
37215 --- a/drivers/acpi/blacklist.c
37216 +++ b/drivers/acpi/blacklist.c
37217 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37218 u32 is_critical_error;
37219 };
37220
37221 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37222 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37223
37224 /*
37225 * POLICY: If *anything* doesn't work, put it on the blacklist.
37226 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37227 return 0;
37228 }
37229
37230 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37231 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37232 {
37233 .callback = dmi_disable_osi_vista,
37234 .ident = "Fujitsu Siemens",
37235 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37236 index c68e724..e863008 100644
37237 --- a/drivers/acpi/custom_method.c
37238 +++ b/drivers/acpi/custom_method.c
37239 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37240 struct acpi_table_header table;
37241 acpi_status status;
37242
37243 +#ifdef CONFIG_GRKERNSEC_KMEM
37244 + return -EPERM;
37245 +#endif
37246 +
37247 if (!(*ppos)) {
37248 /* parse the table header to get the table length */
37249 if (count <= sizeof(struct acpi_table_header))
37250 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37251 index 17f9ec5..d9a455e 100644
37252 --- a/drivers/acpi/processor_idle.c
37253 +++ b/drivers/acpi/processor_idle.c
37254 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37255 {
37256 int i, count = CPUIDLE_DRIVER_STATE_START;
37257 struct acpi_processor_cx *cx;
37258 - struct cpuidle_state *state;
37259 + cpuidle_state_no_const *state;
37260 struct cpuidle_driver *drv = &acpi_idle_driver;
37261
37262 if (!pr->flags.power_setup_done)
37263 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37264 index 38cb978..352c761 100644
37265 --- a/drivers/acpi/sysfs.c
37266 +++ b/drivers/acpi/sysfs.c
37267 @@ -423,11 +423,11 @@ static u32 num_counters;
37268 static struct attribute **all_attrs;
37269 static u32 acpi_gpe_count;
37270
37271 -static struct attribute_group interrupt_stats_attr_group = {
37272 +static attribute_group_no_const interrupt_stats_attr_group = {
37273 .name = "interrupts",
37274 };
37275
37276 -static struct kobj_attribute *counter_attrs;
37277 +static kobj_attribute_no_const *counter_attrs;
37278
37279 static void delete_gpe_attr_array(void)
37280 {
37281 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37282 index b784e9d..a69a049 100644
37283 --- a/drivers/ata/libahci.c
37284 +++ b/drivers/ata/libahci.c
37285 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37286 }
37287 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37288
37289 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37290 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37291 struct ata_taskfile *tf, int is_cmd, u16 flags,
37292 unsigned long timeout_msec)
37293 {
37294 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37295 index 6f67490..f951ead 100644
37296 --- a/drivers/ata/libata-core.c
37297 +++ b/drivers/ata/libata-core.c
37298 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37299 static void ata_dev_xfermask(struct ata_device *dev);
37300 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37301
37302 -atomic_t ata_print_id = ATOMIC_INIT(0);
37303 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37304
37305 struct ata_force_param {
37306 const char *name;
37307 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37308 struct ata_port *ap;
37309 unsigned int tag;
37310
37311 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37312 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37313 ap = qc->ap;
37314
37315 qc->flags = 0;
37316 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37317 struct ata_port *ap;
37318 struct ata_link *link;
37319
37320 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37321 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37322 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37323 ap = qc->ap;
37324 link = qc->dev->link;
37325 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37326 return;
37327
37328 spin_lock(&lock);
37329 + pax_open_kernel();
37330
37331 for (cur = ops->inherits; cur; cur = cur->inherits) {
37332 void **inherit = (void **)cur;
37333 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37334 if (IS_ERR(*pp))
37335 *pp = NULL;
37336
37337 - ops->inherits = NULL;
37338 + *(struct ata_port_operations **)&ops->inherits = NULL;
37339
37340 + pax_close_kernel();
37341 spin_unlock(&lock);
37342 }
37343
37344 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37345
37346 /* give ports names and add SCSI hosts */
37347 for (i = 0; i < host->n_ports; i++) {
37348 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37349 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37350 host->ports[i]->local_port_no = i + 1;
37351 }
37352
37353 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37354 index 0586f66..1a8f74a 100644
37355 --- a/drivers/ata/libata-scsi.c
37356 +++ b/drivers/ata/libata-scsi.c
37357 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37358
37359 if (rc)
37360 return rc;
37361 - ap->print_id = atomic_inc_return(&ata_print_id);
37362 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37363 return 0;
37364 }
37365 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37366 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37367 index 5f4e0cc..ff2c347 100644
37368 --- a/drivers/ata/libata.h
37369 +++ b/drivers/ata/libata.h
37370 @@ -53,7 +53,7 @@ enum {
37371 ATA_DNXFER_QUIET = (1 << 31),
37372 };
37373
37374 -extern atomic_t ata_print_id;
37375 +extern atomic_unchecked_t ata_print_id;
37376 extern int atapi_passthru16;
37377 extern int libata_fua;
37378 extern int libata_noacpi;
37379 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37380 index 4edb1a8..84e1658 100644
37381 --- a/drivers/ata/pata_arasan_cf.c
37382 +++ b/drivers/ata/pata_arasan_cf.c
37383 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37384 /* Handle platform specific quirks */
37385 if (quirk) {
37386 if (quirk & CF_BROKEN_PIO) {
37387 - ap->ops->set_piomode = NULL;
37388 + pax_open_kernel();
37389 + *(void **)&ap->ops->set_piomode = NULL;
37390 + pax_close_kernel();
37391 ap->pio_mask = 0;
37392 }
37393 if (quirk & CF_BROKEN_MWDMA)
37394 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37395 index f9b983a..887b9d8 100644
37396 --- a/drivers/atm/adummy.c
37397 +++ b/drivers/atm/adummy.c
37398 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37399 vcc->pop(vcc, skb);
37400 else
37401 dev_kfree_skb_any(skb);
37402 - atomic_inc(&vcc->stats->tx);
37403 + atomic_inc_unchecked(&vcc->stats->tx);
37404
37405 return 0;
37406 }
37407 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37408 index f1a9198..f466a4a 100644
37409 --- a/drivers/atm/ambassador.c
37410 +++ b/drivers/atm/ambassador.c
37411 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37412 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37413
37414 // VC layer stats
37415 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37416 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37417
37418 // free the descriptor
37419 kfree (tx_descr);
37420 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37421 dump_skb ("<<<", vc, skb);
37422
37423 // VC layer stats
37424 - atomic_inc(&atm_vcc->stats->rx);
37425 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37426 __net_timestamp(skb);
37427 // end of our responsibility
37428 atm_vcc->push (atm_vcc, skb);
37429 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37430 } else {
37431 PRINTK (KERN_INFO, "dropped over-size frame");
37432 // should we count this?
37433 - atomic_inc(&atm_vcc->stats->rx_drop);
37434 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37435 }
37436
37437 } else {
37438 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37439 }
37440
37441 if (check_area (skb->data, skb->len)) {
37442 - atomic_inc(&atm_vcc->stats->tx_err);
37443 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37444 return -ENOMEM; // ?
37445 }
37446
37447 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37448 index 480fa6f..947067c 100644
37449 --- a/drivers/atm/atmtcp.c
37450 +++ b/drivers/atm/atmtcp.c
37451 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37452 if (vcc->pop) vcc->pop(vcc,skb);
37453 else dev_kfree_skb(skb);
37454 if (dev_data) return 0;
37455 - atomic_inc(&vcc->stats->tx_err);
37456 + atomic_inc_unchecked(&vcc->stats->tx_err);
37457 return -ENOLINK;
37458 }
37459 size = skb->len+sizeof(struct atmtcp_hdr);
37460 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37461 if (!new_skb) {
37462 if (vcc->pop) vcc->pop(vcc,skb);
37463 else dev_kfree_skb(skb);
37464 - atomic_inc(&vcc->stats->tx_err);
37465 + atomic_inc_unchecked(&vcc->stats->tx_err);
37466 return -ENOBUFS;
37467 }
37468 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37469 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37470 if (vcc->pop) vcc->pop(vcc,skb);
37471 else dev_kfree_skb(skb);
37472 out_vcc->push(out_vcc,new_skb);
37473 - atomic_inc(&vcc->stats->tx);
37474 - atomic_inc(&out_vcc->stats->rx);
37475 + atomic_inc_unchecked(&vcc->stats->tx);
37476 + atomic_inc_unchecked(&out_vcc->stats->rx);
37477 return 0;
37478 }
37479
37480 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37481 read_unlock(&vcc_sklist_lock);
37482 if (!out_vcc) {
37483 result = -EUNATCH;
37484 - atomic_inc(&vcc->stats->tx_err);
37485 + atomic_inc_unchecked(&vcc->stats->tx_err);
37486 goto done;
37487 }
37488 skb_pull(skb,sizeof(struct atmtcp_hdr));
37489 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37490 __net_timestamp(new_skb);
37491 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37492 out_vcc->push(out_vcc,new_skb);
37493 - atomic_inc(&vcc->stats->tx);
37494 - atomic_inc(&out_vcc->stats->rx);
37495 + atomic_inc_unchecked(&vcc->stats->tx);
37496 + atomic_inc_unchecked(&out_vcc->stats->rx);
37497 done:
37498 if (vcc->pop) vcc->pop(vcc,skb);
37499 else dev_kfree_skb(skb);
37500 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37501 index d65975a..0b87e20 100644
37502 --- a/drivers/atm/eni.c
37503 +++ b/drivers/atm/eni.c
37504 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37505 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37506 vcc->dev->number);
37507 length = 0;
37508 - atomic_inc(&vcc->stats->rx_err);
37509 + atomic_inc_unchecked(&vcc->stats->rx_err);
37510 }
37511 else {
37512 length = ATM_CELL_SIZE-1; /* no HEC */
37513 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37514 size);
37515 }
37516 eff = length = 0;
37517 - atomic_inc(&vcc->stats->rx_err);
37518 + atomic_inc_unchecked(&vcc->stats->rx_err);
37519 }
37520 else {
37521 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37522 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37523 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37524 vcc->dev->number,vcc->vci,length,size << 2,descr);
37525 length = eff = 0;
37526 - atomic_inc(&vcc->stats->rx_err);
37527 + atomic_inc_unchecked(&vcc->stats->rx_err);
37528 }
37529 }
37530 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37531 @@ -767,7 +767,7 @@ rx_dequeued++;
37532 vcc->push(vcc,skb);
37533 pushed++;
37534 }
37535 - atomic_inc(&vcc->stats->rx);
37536 + atomic_inc_unchecked(&vcc->stats->rx);
37537 }
37538 wake_up(&eni_dev->rx_wait);
37539 }
37540 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37541 PCI_DMA_TODEVICE);
37542 if (vcc->pop) vcc->pop(vcc,skb);
37543 else dev_kfree_skb_irq(skb);
37544 - atomic_inc(&vcc->stats->tx);
37545 + atomic_inc_unchecked(&vcc->stats->tx);
37546 wake_up(&eni_dev->tx_wait);
37547 dma_complete++;
37548 }
37549 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37550 index 82f2ae0..f205c02 100644
37551 --- a/drivers/atm/firestream.c
37552 +++ b/drivers/atm/firestream.c
37553 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37554 }
37555 }
37556
37557 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37558 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37559
37560 fs_dprintk (FS_DEBUG_TXMEM, "i");
37561 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37562 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37563 #endif
37564 skb_put (skb, qe->p1 & 0xffff);
37565 ATM_SKB(skb)->vcc = atm_vcc;
37566 - atomic_inc(&atm_vcc->stats->rx);
37567 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37568 __net_timestamp(skb);
37569 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37570 atm_vcc->push (atm_vcc, skb);
37571 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37572 kfree (pe);
37573 }
37574 if (atm_vcc)
37575 - atomic_inc(&atm_vcc->stats->rx_drop);
37576 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37577 break;
37578 case 0x1f: /* Reassembly abort: no buffers. */
37579 /* Silently increment error counter. */
37580 if (atm_vcc)
37581 - atomic_inc(&atm_vcc->stats->rx_drop);
37582 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37583 break;
37584 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37585 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37586 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37587 index d4725fc..2d4ea65 100644
37588 --- a/drivers/atm/fore200e.c
37589 +++ b/drivers/atm/fore200e.c
37590 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37591 #endif
37592 /* check error condition */
37593 if (*entry->status & STATUS_ERROR)
37594 - atomic_inc(&vcc->stats->tx_err);
37595 + atomic_inc_unchecked(&vcc->stats->tx_err);
37596 else
37597 - atomic_inc(&vcc->stats->tx);
37598 + atomic_inc_unchecked(&vcc->stats->tx);
37599 }
37600 }
37601
37602 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37603 if (skb == NULL) {
37604 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37605
37606 - atomic_inc(&vcc->stats->rx_drop);
37607 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37608 return -ENOMEM;
37609 }
37610
37611 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37612
37613 dev_kfree_skb_any(skb);
37614
37615 - atomic_inc(&vcc->stats->rx_drop);
37616 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37617 return -ENOMEM;
37618 }
37619
37620 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37621
37622 vcc->push(vcc, skb);
37623 - atomic_inc(&vcc->stats->rx);
37624 + atomic_inc_unchecked(&vcc->stats->rx);
37625
37626 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37627
37628 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37629 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37630 fore200e->atm_dev->number,
37631 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37632 - atomic_inc(&vcc->stats->rx_err);
37633 + atomic_inc_unchecked(&vcc->stats->rx_err);
37634 }
37635 }
37636
37637 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37638 goto retry_here;
37639 }
37640
37641 - atomic_inc(&vcc->stats->tx_err);
37642 + atomic_inc_unchecked(&vcc->stats->tx_err);
37643
37644 fore200e->tx_sat++;
37645 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37646 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37647 index c39702b..785b73b 100644
37648 --- a/drivers/atm/he.c
37649 +++ b/drivers/atm/he.c
37650 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37651
37652 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37653 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37654 - atomic_inc(&vcc->stats->rx_drop);
37655 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37656 goto return_host_buffers;
37657 }
37658
37659 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37660 RBRQ_LEN_ERR(he_dev->rbrq_head)
37661 ? "LEN_ERR" : "",
37662 vcc->vpi, vcc->vci);
37663 - atomic_inc(&vcc->stats->rx_err);
37664 + atomic_inc_unchecked(&vcc->stats->rx_err);
37665 goto return_host_buffers;
37666 }
37667
37668 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37669 vcc->push(vcc, skb);
37670 spin_lock(&he_dev->global_lock);
37671
37672 - atomic_inc(&vcc->stats->rx);
37673 + atomic_inc_unchecked(&vcc->stats->rx);
37674
37675 return_host_buffers:
37676 ++pdus_assembled;
37677 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37678 tpd->vcc->pop(tpd->vcc, tpd->skb);
37679 else
37680 dev_kfree_skb_any(tpd->skb);
37681 - atomic_inc(&tpd->vcc->stats->tx_err);
37682 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37683 }
37684 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37685 return;
37686 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37687 vcc->pop(vcc, skb);
37688 else
37689 dev_kfree_skb_any(skb);
37690 - atomic_inc(&vcc->stats->tx_err);
37691 + atomic_inc_unchecked(&vcc->stats->tx_err);
37692 return -EINVAL;
37693 }
37694
37695 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37696 vcc->pop(vcc, skb);
37697 else
37698 dev_kfree_skb_any(skb);
37699 - atomic_inc(&vcc->stats->tx_err);
37700 + atomic_inc_unchecked(&vcc->stats->tx_err);
37701 return -EINVAL;
37702 }
37703 #endif
37704 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37705 vcc->pop(vcc, skb);
37706 else
37707 dev_kfree_skb_any(skb);
37708 - atomic_inc(&vcc->stats->tx_err);
37709 + atomic_inc_unchecked(&vcc->stats->tx_err);
37710 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37711 return -ENOMEM;
37712 }
37713 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37714 vcc->pop(vcc, skb);
37715 else
37716 dev_kfree_skb_any(skb);
37717 - atomic_inc(&vcc->stats->tx_err);
37718 + atomic_inc_unchecked(&vcc->stats->tx_err);
37719 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37720 return -ENOMEM;
37721 }
37722 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37723 __enqueue_tpd(he_dev, tpd, cid);
37724 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37725
37726 - atomic_inc(&vcc->stats->tx);
37727 + atomic_inc_unchecked(&vcc->stats->tx);
37728
37729 return 0;
37730 }
37731 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37732 index 1dc0519..1aadaf7 100644
37733 --- a/drivers/atm/horizon.c
37734 +++ b/drivers/atm/horizon.c
37735 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37736 {
37737 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37738 // VC layer stats
37739 - atomic_inc(&vcc->stats->rx);
37740 + atomic_inc_unchecked(&vcc->stats->rx);
37741 __net_timestamp(skb);
37742 // end of our responsibility
37743 vcc->push (vcc, skb);
37744 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37745 dev->tx_iovec = NULL;
37746
37747 // VC layer stats
37748 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37749 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37750
37751 // free the skb
37752 hrz_kfree_skb (skb);
37753 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37754 index 2b24ed0..b3d6acc 100644
37755 --- a/drivers/atm/idt77252.c
37756 +++ b/drivers/atm/idt77252.c
37757 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37758 else
37759 dev_kfree_skb(skb);
37760
37761 - atomic_inc(&vcc->stats->tx);
37762 + atomic_inc_unchecked(&vcc->stats->tx);
37763 }
37764
37765 atomic_dec(&scq->used);
37766 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37767 if ((sb = dev_alloc_skb(64)) == NULL) {
37768 printk("%s: Can't allocate buffers for aal0.\n",
37769 card->name);
37770 - atomic_add(i, &vcc->stats->rx_drop);
37771 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37772 break;
37773 }
37774 if (!atm_charge(vcc, sb->truesize)) {
37775 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37776 card->name);
37777 - atomic_add(i - 1, &vcc->stats->rx_drop);
37778 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37779 dev_kfree_skb(sb);
37780 break;
37781 }
37782 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37783 ATM_SKB(sb)->vcc = vcc;
37784 __net_timestamp(sb);
37785 vcc->push(vcc, sb);
37786 - atomic_inc(&vcc->stats->rx);
37787 + atomic_inc_unchecked(&vcc->stats->rx);
37788
37789 cell += ATM_CELL_PAYLOAD;
37790 }
37791 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37792 "(CDC: %08x)\n",
37793 card->name, len, rpp->len, readl(SAR_REG_CDC));
37794 recycle_rx_pool_skb(card, rpp);
37795 - atomic_inc(&vcc->stats->rx_err);
37796 + atomic_inc_unchecked(&vcc->stats->rx_err);
37797 return;
37798 }
37799 if (stat & SAR_RSQE_CRC) {
37800 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37801 recycle_rx_pool_skb(card, rpp);
37802 - atomic_inc(&vcc->stats->rx_err);
37803 + atomic_inc_unchecked(&vcc->stats->rx_err);
37804 return;
37805 }
37806 if (skb_queue_len(&rpp->queue) > 1) {
37807 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37808 RXPRINTK("%s: Can't alloc RX skb.\n",
37809 card->name);
37810 recycle_rx_pool_skb(card, rpp);
37811 - atomic_inc(&vcc->stats->rx_err);
37812 + atomic_inc_unchecked(&vcc->stats->rx_err);
37813 return;
37814 }
37815 if (!atm_charge(vcc, skb->truesize)) {
37816 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37817 __net_timestamp(skb);
37818
37819 vcc->push(vcc, skb);
37820 - atomic_inc(&vcc->stats->rx);
37821 + atomic_inc_unchecked(&vcc->stats->rx);
37822
37823 return;
37824 }
37825 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37826 __net_timestamp(skb);
37827
37828 vcc->push(vcc, skb);
37829 - atomic_inc(&vcc->stats->rx);
37830 + atomic_inc_unchecked(&vcc->stats->rx);
37831
37832 if (skb->truesize > SAR_FB_SIZE_3)
37833 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37834 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37835 if (vcc->qos.aal != ATM_AAL0) {
37836 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37837 card->name, vpi, vci);
37838 - atomic_inc(&vcc->stats->rx_drop);
37839 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37840 goto drop;
37841 }
37842
37843 if ((sb = dev_alloc_skb(64)) == NULL) {
37844 printk("%s: Can't allocate buffers for AAL0.\n",
37845 card->name);
37846 - atomic_inc(&vcc->stats->rx_err);
37847 + atomic_inc_unchecked(&vcc->stats->rx_err);
37848 goto drop;
37849 }
37850
37851 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37852 ATM_SKB(sb)->vcc = vcc;
37853 __net_timestamp(sb);
37854 vcc->push(vcc, sb);
37855 - atomic_inc(&vcc->stats->rx);
37856 + atomic_inc_unchecked(&vcc->stats->rx);
37857
37858 drop:
37859 skb_pull(queue, 64);
37860 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37861
37862 if (vc == NULL) {
37863 printk("%s: NULL connection in send().\n", card->name);
37864 - atomic_inc(&vcc->stats->tx_err);
37865 + atomic_inc_unchecked(&vcc->stats->tx_err);
37866 dev_kfree_skb(skb);
37867 return -EINVAL;
37868 }
37869 if (!test_bit(VCF_TX, &vc->flags)) {
37870 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37871 - atomic_inc(&vcc->stats->tx_err);
37872 + atomic_inc_unchecked(&vcc->stats->tx_err);
37873 dev_kfree_skb(skb);
37874 return -EINVAL;
37875 }
37876 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37877 break;
37878 default:
37879 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37880 - atomic_inc(&vcc->stats->tx_err);
37881 + atomic_inc_unchecked(&vcc->stats->tx_err);
37882 dev_kfree_skb(skb);
37883 return -EINVAL;
37884 }
37885
37886 if (skb_shinfo(skb)->nr_frags != 0) {
37887 printk("%s: No scatter-gather yet.\n", card->name);
37888 - atomic_inc(&vcc->stats->tx_err);
37889 + atomic_inc_unchecked(&vcc->stats->tx_err);
37890 dev_kfree_skb(skb);
37891 return -EINVAL;
37892 }
37893 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37894
37895 err = queue_skb(card, vc, skb, oam);
37896 if (err) {
37897 - atomic_inc(&vcc->stats->tx_err);
37898 + atomic_inc_unchecked(&vcc->stats->tx_err);
37899 dev_kfree_skb(skb);
37900 return err;
37901 }
37902 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37903 skb = dev_alloc_skb(64);
37904 if (!skb) {
37905 printk("%s: Out of memory in send_oam().\n", card->name);
37906 - atomic_inc(&vcc->stats->tx_err);
37907 + atomic_inc_unchecked(&vcc->stats->tx_err);
37908 return -ENOMEM;
37909 }
37910 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37911 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37912 index 4217f29..88f547a 100644
37913 --- a/drivers/atm/iphase.c
37914 +++ b/drivers/atm/iphase.c
37915 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37916 status = (u_short) (buf_desc_ptr->desc_mode);
37917 if (status & (RX_CER | RX_PTE | RX_OFL))
37918 {
37919 - atomic_inc(&vcc->stats->rx_err);
37920 + atomic_inc_unchecked(&vcc->stats->rx_err);
37921 IF_ERR(printk("IA: bad packet, dropping it");)
37922 if (status & RX_CER) {
37923 IF_ERR(printk(" cause: packet CRC error\n");)
37924 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37925 len = dma_addr - buf_addr;
37926 if (len > iadev->rx_buf_sz) {
37927 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37928 - atomic_inc(&vcc->stats->rx_err);
37929 + atomic_inc_unchecked(&vcc->stats->rx_err);
37930 goto out_free_desc;
37931 }
37932
37933 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37934 ia_vcc = INPH_IA_VCC(vcc);
37935 if (ia_vcc == NULL)
37936 {
37937 - atomic_inc(&vcc->stats->rx_err);
37938 + atomic_inc_unchecked(&vcc->stats->rx_err);
37939 atm_return(vcc, skb->truesize);
37940 dev_kfree_skb_any(skb);
37941 goto INCR_DLE;
37942 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37943 if ((length > iadev->rx_buf_sz) || (length >
37944 (skb->len - sizeof(struct cpcs_trailer))))
37945 {
37946 - atomic_inc(&vcc->stats->rx_err);
37947 + atomic_inc_unchecked(&vcc->stats->rx_err);
37948 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37949 length, skb->len);)
37950 atm_return(vcc, skb->truesize);
37951 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37952
37953 IF_RX(printk("rx_dle_intr: skb push");)
37954 vcc->push(vcc,skb);
37955 - atomic_inc(&vcc->stats->rx);
37956 + atomic_inc_unchecked(&vcc->stats->rx);
37957 iadev->rx_pkt_cnt++;
37958 }
37959 INCR_DLE:
37960 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37961 {
37962 struct k_sonet_stats *stats;
37963 stats = &PRIV(_ia_dev[board])->sonet_stats;
37964 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37965 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37966 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37967 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37968 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37969 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37970 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37971 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37972 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37973 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37974 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37975 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37976 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37977 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37978 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37979 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37980 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37981 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37982 }
37983 ia_cmds.status = 0;
37984 break;
37985 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37986 if ((desc == 0) || (desc > iadev->num_tx_desc))
37987 {
37988 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37989 - atomic_inc(&vcc->stats->tx);
37990 + atomic_inc_unchecked(&vcc->stats->tx);
37991 if (vcc->pop)
37992 vcc->pop(vcc, skb);
37993 else
37994 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37995 ATM_DESC(skb) = vcc->vci;
37996 skb_queue_tail(&iadev->tx_dma_q, skb);
37997
37998 - atomic_inc(&vcc->stats->tx);
37999 + atomic_inc_unchecked(&vcc->stats->tx);
38000 iadev->tx_pkt_cnt++;
38001 /* Increment transaction counter */
38002 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38003
38004 #if 0
38005 /* add flow control logic */
38006 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38007 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38008 if (iavcc->vc_desc_cnt > 10) {
38009 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38010 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38011 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38012 index fa7d7019..1e404c7 100644
38013 --- a/drivers/atm/lanai.c
38014 +++ b/drivers/atm/lanai.c
38015 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38016 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38017 lanai_endtx(lanai, lvcc);
38018 lanai_free_skb(lvcc->tx.atmvcc, skb);
38019 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38020 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38021 }
38022
38023 /* Try to fill the buffer - don't call unless there is backlog */
38024 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38025 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38026 __net_timestamp(skb);
38027 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38028 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38029 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38030 out:
38031 lvcc->rx.buf.ptr = end;
38032 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38033 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38034 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38035 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38036 lanai->stats.service_rxnotaal5++;
38037 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38038 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38039 return 0;
38040 }
38041 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38042 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38043 int bytes;
38044 read_unlock(&vcc_sklist_lock);
38045 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38046 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38047 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38048 lvcc->stats.x.aal5.service_trash++;
38049 bytes = (SERVICE_GET_END(s) * 16) -
38050 (((unsigned long) lvcc->rx.buf.ptr) -
38051 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38052 }
38053 if (s & SERVICE_STREAM) {
38054 read_unlock(&vcc_sklist_lock);
38055 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38056 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38057 lvcc->stats.x.aal5.service_stream++;
38058 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38059 "PDU on VCI %d!\n", lanai->number, vci);
38060 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38061 return 0;
38062 }
38063 DPRINTK("got rx crc error on vci %d\n", vci);
38064 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38065 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38066 lvcc->stats.x.aal5.service_rxcrc++;
38067 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38068 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38069 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38070 index 9988ac9..7c52585 100644
38071 --- a/drivers/atm/nicstar.c
38072 +++ b/drivers/atm/nicstar.c
38073 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38074 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38075 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38076 card->index);
38077 - atomic_inc(&vcc->stats->tx_err);
38078 + atomic_inc_unchecked(&vcc->stats->tx_err);
38079 dev_kfree_skb_any(skb);
38080 return -EINVAL;
38081 }
38082 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38083 if (!vc->tx) {
38084 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38085 card->index);
38086 - atomic_inc(&vcc->stats->tx_err);
38087 + atomic_inc_unchecked(&vcc->stats->tx_err);
38088 dev_kfree_skb_any(skb);
38089 return -EINVAL;
38090 }
38091 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38092 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38093 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38094 card->index);
38095 - atomic_inc(&vcc->stats->tx_err);
38096 + atomic_inc_unchecked(&vcc->stats->tx_err);
38097 dev_kfree_skb_any(skb);
38098 return -EINVAL;
38099 }
38100
38101 if (skb_shinfo(skb)->nr_frags != 0) {
38102 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38103 - atomic_inc(&vcc->stats->tx_err);
38104 + atomic_inc_unchecked(&vcc->stats->tx_err);
38105 dev_kfree_skb_any(skb);
38106 return -EINVAL;
38107 }
38108 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38109 }
38110
38111 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38112 - atomic_inc(&vcc->stats->tx_err);
38113 + atomic_inc_unchecked(&vcc->stats->tx_err);
38114 dev_kfree_skb_any(skb);
38115 return -EIO;
38116 }
38117 - atomic_inc(&vcc->stats->tx);
38118 + atomic_inc_unchecked(&vcc->stats->tx);
38119
38120 return 0;
38121 }
38122 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38123 printk
38124 ("nicstar%d: Can't allocate buffers for aal0.\n",
38125 card->index);
38126 - atomic_add(i, &vcc->stats->rx_drop);
38127 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38128 break;
38129 }
38130 if (!atm_charge(vcc, sb->truesize)) {
38131 RXPRINTK
38132 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38133 card->index);
38134 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38135 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38136 dev_kfree_skb_any(sb);
38137 break;
38138 }
38139 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38140 ATM_SKB(sb)->vcc = vcc;
38141 __net_timestamp(sb);
38142 vcc->push(vcc, sb);
38143 - atomic_inc(&vcc->stats->rx);
38144 + atomic_inc_unchecked(&vcc->stats->rx);
38145 cell += ATM_CELL_PAYLOAD;
38146 }
38147
38148 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38149 if (iovb == NULL) {
38150 printk("nicstar%d: Out of iovec buffers.\n",
38151 card->index);
38152 - atomic_inc(&vcc->stats->rx_drop);
38153 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38154 recycle_rx_buf(card, skb);
38155 return;
38156 }
38157 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38158 small or large buffer itself. */
38159 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38160 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38161 - atomic_inc(&vcc->stats->rx_err);
38162 + atomic_inc_unchecked(&vcc->stats->rx_err);
38163 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38164 NS_MAX_IOVECS);
38165 NS_PRV_IOVCNT(iovb) = 0;
38166 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38167 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38168 card->index);
38169 which_list(card, skb);
38170 - atomic_inc(&vcc->stats->rx_err);
38171 + atomic_inc_unchecked(&vcc->stats->rx_err);
38172 recycle_rx_buf(card, skb);
38173 vc->rx_iov = NULL;
38174 recycle_iov_buf(card, iovb);
38175 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38176 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38177 card->index);
38178 which_list(card, skb);
38179 - atomic_inc(&vcc->stats->rx_err);
38180 + atomic_inc_unchecked(&vcc->stats->rx_err);
38181 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38182 NS_PRV_IOVCNT(iovb));
38183 vc->rx_iov = NULL;
38184 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38185 printk(" - PDU size mismatch.\n");
38186 else
38187 printk(".\n");
38188 - atomic_inc(&vcc->stats->rx_err);
38189 + atomic_inc_unchecked(&vcc->stats->rx_err);
38190 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38191 NS_PRV_IOVCNT(iovb));
38192 vc->rx_iov = NULL;
38193 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38194 /* skb points to a small buffer */
38195 if (!atm_charge(vcc, skb->truesize)) {
38196 push_rxbufs(card, skb);
38197 - atomic_inc(&vcc->stats->rx_drop);
38198 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38199 } else {
38200 skb_put(skb, len);
38201 dequeue_sm_buf(card, skb);
38202 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38203 ATM_SKB(skb)->vcc = vcc;
38204 __net_timestamp(skb);
38205 vcc->push(vcc, skb);
38206 - atomic_inc(&vcc->stats->rx);
38207 + atomic_inc_unchecked(&vcc->stats->rx);
38208 }
38209 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38210 struct sk_buff *sb;
38211 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38212 if (len <= NS_SMBUFSIZE) {
38213 if (!atm_charge(vcc, sb->truesize)) {
38214 push_rxbufs(card, sb);
38215 - atomic_inc(&vcc->stats->rx_drop);
38216 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38217 } else {
38218 skb_put(sb, len);
38219 dequeue_sm_buf(card, sb);
38220 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38221 ATM_SKB(sb)->vcc = vcc;
38222 __net_timestamp(sb);
38223 vcc->push(vcc, sb);
38224 - atomic_inc(&vcc->stats->rx);
38225 + atomic_inc_unchecked(&vcc->stats->rx);
38226 }
38227
38228 push_rxbufs(card, skb);
38229 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38230
38231 if (!atm_charge(vcc, skb->truesize)) {
38232 push_rxbufs(card, skb);
38233 - atomic_inc(&vcc->stats->rx_drop);
38234 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38235 } else {
38236 dequeue_lg_buf(card, skb);
38237 #ifdef NS_USE_DESTRUCTORS
38238 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38239 ATM_SKB(skb)->vcc = vcc;
38240 __net_timestamp(skb);
38241 vcc->push(vcc, skb);
38242 - atomic_inc(&vcc->stats->rx);
38243 + atomic_inc_unchecked(&vcc->stats->rx);
38244 }
38245
38246 push_rxbufs(card, sb);
38247 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38248 printk
38249 ("nicstar%d: Out of huge buffers.\n",
38250 card->index);
38251 - atomic_inc(&vcc->stats->rx_drop);
38252 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38253 recycle_iovec_rx_bufs(card,
38254 (struct iovec *)
38255 iovb->data,
38256 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38257 card->hbpool.count++;
38258 } else
38259 dev_kfree_skb_any(hb);
38260 - atomic_inc(&vcc->stats->rx_drop);
38261 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38262 } else {
38263 /* Copy the small buffer to the huge buffer */
38264 sb = (struct sk_buff *)iov->iov_base;
38265 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38266 #endif /* NS_USE_DESTRUCTORS */
38267 __net_timestamp(hb);
38268 vcc->push(vcc, hb);
38269 - atomic_inc(&vcc->stats->rx);
38270 + atomic_inc_unchecked(&vcc->stats->rx);
38271 }
38272 }
38273
38274 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38275 index 7652e8d..db45069 100644
38276 --- a/drivers/atm/solos-pci.c
38277 +++ b/drivers/atm/solos-pci.c
38278 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38279 }
38280 atm_charge(vcc, skb->truesize);
38281 vcc->push(vcc, skb);
38282 - atomic_inc(&vcc->stats->rx);
38283 + atomic_inc_unchecked(&vcc->stats->rx);
38284 break;
38285
38286 case PKT_STATUS:
38287 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38288 vcc = SKB_CB(oldskb)->vcc;
38289
38290 if (vcc) {
38291 - atomic_inc(&vcc->stats->tx);
38292 + atomic_inc_unchecked(&vcc->stats->tx);
38293 solos_pop(vcc, oldskb);
38294 } else {
38295 dev_kfree_skb_irq(oldskb);
38296 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38297 index 0215934..ce9f5b1 100644
38298 --- a/drivers/atm/suni.c
38299 +++ b/drivers/atm/suni.c
38300 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38301
38302
38303 #define ADD_LIMITED(s,v) \
38304 - atomic_add((v),&stats->s); \
38305 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38306 + atomic_add_unchecked((v),&stats->s); \
38307 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38308
38309
38310 static void suni_hz(unsigned long from_timer)
38311 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38312 index 5120a96..e2572bd 100644
38313 --- a/drivers/atm/uPD98402.c
38314 +++ b/drivers/atm/uPD98402.c
38315 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38316 struct sonet_stats tmp;
38317 int error = 0;
38318
38319 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38320 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38321 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38322 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38323 if (zero && !error) {
38324 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38325
38326
38327 #define ADD_LIMITED(s,v) \
38328 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38329 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38330 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38331 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38332 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38333 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38334
38335
38336 static void stat_event(struct atm_dev *dev)
38337 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38338 if (reason & uPD98402_INT_PFM) stat_event(dev);
38339 if (reason & uPD98402_INT_PCO) {
38340 (void) GET(PCOCR); /* clear interrupt cause */
38341 - atomic_add(GET(HECCT),
38342 + atomic_add_unchecked(GET(HECCT),
38343 &PRIV(dev)->sonet_stats.uncorr_hcs);
38344 }
38345 if ((reason & uPD98402_INT_RFO) &&
38346 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38347 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38348 uPD98402_INT_LOS),PIMR); /* enable them */
38349 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38350 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38351 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38352 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38353 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38354 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38355 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38356 return 0;
38357 }
38358
38359 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38360 index 969c3c2..9b72956 100644
38361 --- a/drivers/atm/zatm.c
38362 +++ b/drivers/atm/zatm.c
38363 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38364 }
38365 if (!size) {
38366 dev_kfree_skb_irq(skb);
38367 - if (vcc) atomic_inc(&vcc->stats->rx_err);
38368 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38369 continue;
38370 }
38371 if (!atm_charge(vcc,skb->truesize)) {
38372 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38373 skb->len = size;
38374 ATM_SKB(skb)->vcc = vcc;
38375 vcc->push(vcc,skb);
38376 - atomic_inc(&vcc->stats->rx);
38377 + atomic_inc_unchecked(&vcc->stats->rx);
38378 }
38379 zout(pos & 0xffff,MTA(mbx));
38380 #if 0 /* probably a stupid idea */
38381 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38382 skb_queue_head(&zatm_vcc->backlog,skb);
38383 break;
38384 }
38385 - atomic_inc(&vcc->stats->tx);
38386 + atomic_inc_unchecked(&vcc->stats->tx);
38387 wake_up(&zatm_vcc->tx_wait);
38388 }
38389
38390 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38391 index 83e910a..b224a73 100644
38392 --- a/drivers/base/bus.c
38393 +++ b/drivers/base/bus.c
38394 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38395 return -EINVAL;
38396
38397 mutex_lock(&subsys->p->mutex);
38398 - list_add_tail(&sif->node, &subsys->p->interfaces);
38399 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38400 if (sif->add_dev) {
38401 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38402 while ((dev = subsys_dev_iter_next(&iter)))
38403 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38404 subsys = sif->subsys;
38405
38406 mutex_lock(&subsys->p->mutex);
38407 - list_del_init(&sif->node);
38408 + pax_list_del_init((struct list_head *)&sif->node);
38409 if (sif->remove_dev) {
38410 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38411 while ((dev = subsys_dev_iter_next(&iter)))
38412 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38413 index 25798db..15f130e 100644
38414 --- a/drivers/base/devtmpfs.c
38415 +++ b/drivers/base/devtmpfs.c
38416 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38417 if (!thread)
38418 return 0;
38419
38420 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38421 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38422 if (err)
38423 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38424 else
38425 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38426 *err = sys_unshare(CLONE_NEWNS);
38427 if (*err)
38428 goto out;
38429 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38430 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38431 if (*err)
38432 goto out;
38433 - sys_chdir("/.."); /* will traverse into overmounted root */
38434 - sys_chroot(".");
38435 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38436 + sys_chroot((char __force_user *)".");
38437 complete(&setup_done);
38438 while (1) {
38439 spin_lock(&req_lock);
38440 diff --git a/drivers/base/node.c b/drivers/base/node.c
38441 index d51c49c..28908df 100644
38442 --- a/drivers/base/node.c
38443 +++ b/drivers/base/node.c
38444 @@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38445 struct node_attr {
38446 struct device_attribute attr;
38447 enum node_states state;
38448 -};
38449 +} __do_const;
38450
38451 static ssize_t show_node_state(struct device *dev,
38452 struct device_attribute *attr, char *buf)
38453 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38454 index eee55c1..b8c9393 100644
38455 --- a/drivers/base/power/domain.c
38456 +++ b/drivers/base/power/domain.c
38457 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38458
38459 if (dev->power.subsys_data->domain_data) {
38460 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38461 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
38462 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38463 if (clear_td)
38464 - gpd_data->td = (struct gpd_timing_data){ 0 };
38465 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38466
38467 if (--gpd_data->refcount == 0) {
38468 dev->power.subsys_data->domain_data = NULL;
38469 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38470 {
38471 struct cpuidle_driver *cpuidle_drv;
38472 struct gpd_cpu_data *cpu_data;
38473 - struct cpuidle_state *idle_state;
38474 + cpuidle_state_no_const *idle_state;
38475 int ret = 0;
38476
38477 if (IS_ERR_OR_NULL(genpd) || state < 0)
38478 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38479 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38480 {
38481 struct gpd_cpu_data *cpu_data;
38482 - struct cpuidle_state *idle_state;
38483 + cpuidle_state_no_const *idle_state;
38484 int ret = 0;
38485
38486 if (IS_ERR_OR_NULL(genpd))
38487 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38488 index 95b181d1..c4f0e19 100644
38489 --- a/drivers/base/power/sysfs.c
38490 +++ b/drivers/base/power/sysfs.c
38491 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38492 return -EIO;
38493 }
38494 }
38495 - return sprintf(buf, p);
38496 + return sprintf(buf, "%s", p);
38497 }
38498
38499 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38500 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38501 index eb1bd2e..2667d3a 100644
38502 --- a/drivers/base/power/wakeup.c
38503 +++ b/drivers/base/power/wakeup.c
38504 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38505 * They need to be modified together atomically, so it's better to use one
38506 * atomic variable to hold them both.
38507 */
38508 -static atomic_t combined_event_count = ATOMIC_INIT(0);
38509 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38510
38511 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38512 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38513
38514 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38515 {
38516 - unsigned int comb = atomic_read(&combined_event_count);
38517 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
38518
38519 *cnt = (comb >> IN_PROGRESS_BITS);
38520 *inpr = comb & MAX_IN_PROGRESS;
38521 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38522 ws->start_prevent_time = ws->last_time;
38523
38524 /* Increment the counter of events in progress. */
38525 - cec = atomic_inc_return(&combined_event_count);
38526 + cec = atomic_inc_return_unchecked(&combined_event_count);
38527
38528 trace_wakeup_source_activate(ws->name, cec);
38529 }
38530 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38531 * Increment the counter of registered wakeup events and decrement the
38532 * couter of wakeup events in progress simultaneously.
38533 */
38534 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38535 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38536 trace_wakeup_source_deactivate(ws->name, cec);
38537
38538 split_counters(&cnt, &inpr);
38539 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38540 index dbb8350..4762f4c 100644
38541 --- a/drivers/base/syscore.c
38542 +++ b/drivers/base/syscore.c
38543 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38544 void register_syscore_ops(struct syscore_ops *ops)
38545 {
38546 mutex_lock(&syscore_ops_lock);
38547 - list_add_tail(&ops->node, &syscore_ops_list);
38548 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38549 mutex_unlock(&syscore_ops_lock);
38550 }
38551 EXPORT_SYMBOL_GPL(register_syscore_ops);
38552 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38553 void unregister_syscore_ops(struct syscore_ops *ops)
38554 {
38555 mutex_lock(&syscore_ops_lock);
38556 - list_del(&ops->node);
38557 + pax_list_del((struct list_head *)&ops->node);
38558 mutex_unlock(&syscore_ops_lock);
38559 }
38560 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38561 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38562 index ff20f19..018f1da 100644
38563 --- a/drivers/block/cciss.c
38564 +++ b/drivers/block/cciss.c
38565 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38566 while (!list_empty(&h->reqQ)) {
38567 c = list_entry(h->reqQ.next, CommandList_struct, list);
38568 /* can't do anything if fifo is full */
38569 - if ((h->access.fifo_full(h))) {
38570 + if ((h->access->fifo_full(h))) {
38571 dev_warn(&h->pdev->dev, "fifo full\n");
38572 break;
38573 }
38574 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38575 h->Qdepth--;
38576
38577 /* Tell the controller execute command */
38578 - h->access.submit_command(h, c);
38579 + h->access->submit_command(h, c);
38580
38581 /* Put job onto the completed Q */
38582 addQ(&h->cmpQ, c);
38583 @@ -3444,17 +3444,17 @@ startio:
38584
38585 static inline unsigned long get_next_completion(ctlr_info_t *h)
38586 {
38587 - return h->access.command_completed(h);
38588 + return h->access->command_completed(h);
38589 }
38590
38591 static inline int interrupt_pending(ctlr_info_t *h)
38592 {
38593 - return h->access.intr_pending(h);
38594 + return h->access->intr_pending(h);
38595 }
38596
38597 static inline long interrupt_not_for_us(ctlr_info_t *h)
38598 {
38599 - return ((h->access.intr_pending(h) == 0) ||
38600 + return ((h->access->intr_pending(h) == 0) ||
38601 (h->interrupts_enabled == 0));
38602 }
38603
38604 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38605 u32 a;
38606
38607 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38608 - return h->access.command_completed(h);
38609 + return h->access->command_completed(h);
38610
38611 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38612 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38613 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38614 trans_support & CFGTBL_Trans_use_short_tags);
38615
38616 /* Change the access methods to the performant access methods */
38617 - h->access = SA5_performant_access;
38618 + h->access = &SA5_performant_access;
38619 h->transMethod = CFGTBL_Trans_Performant;
38620
38621 return;
38622 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38623 if (prod_index < 0)
38624 return -ENODEV;
38625 h->product_name = products[prod_index].product_name;
38626 - h->access = *(products[prod_index].access);
38627 + h->access = products[prod_index].access;
38628
38629 if (cciss_board_disabled(h)) {
38630 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38631 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38632 }
38633
38634 /* make sure the board interrupts are off */
38635 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38636 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38637 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38638 if (rc)
38639 goto clean2;
38640 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38641 * fake ones to scoop up any residual completions.
38642 */
38643 spin_lock_irqsave(&h->lock, flags);
38644 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38645 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38646 spin_unlock_irqrestore(&h->lock, flags);
38647 free_irq(h->intr[h->intr_mode], h);
38648 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38649 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38650 dev_info(&h->pdev->dev, "Board READY.\n");
38651 dev_info(&h->pdev->dev,
38652 "Waiting for stale completions to drain.\n");
38653 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38654 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38655 msleep(10000);
38656 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38657 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38658
38659 rc = controller_reset_failed(h->cfgtable);
38660 if (rc)
38661 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38662 cciss_scsi_setup(h);
38663
38664 /* Turn the interrupts on so we can service requests */
38665 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38666 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38667
38668 /* Get the firmware version */
38669 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38670 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38671 kfree(flush_buf);
38672 if (return_code != IO_OK)
38673 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38674 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38675 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38676 free_irq(h->intr[h->intr_mode], h);
38677 }
38678
38679 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38680 index 7fda30e..2f27946 100644
38681 --- a/drivers/block/cciss.h
38682 +++ b/drivers/block/cciss.h
38683 @@ -101,7 +101,7 @@ struct ctlr_info
38684 /* information about each logical volume */
38685 drive_info_struct *drv[CISS_MAX_LUN];
38686
38687 - struct access_method access;
38688 + struct access_method *access;
38689
38690 /* queue and queue Info */
38691 struct list_head reqQ;
38692 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38693 }
38694
38695 static struct access_method SA5_access = {
38696 - SA5_submit_command,
38697 - SA5_intr_mask,
38698 - SA5_fifo_full,
38699 - SA5_intr_pending,
38700 - SA5_completed,
38701 + .submit_command = SA5_submit_command,
38702 + .set_intr_mask = SA5_intr_mask,
38703 + .fifo_full = SA5_fifo_full,
38704 + .intr_pending = SA5_intr_pending,
38705 + .command_completed = SA5_completed,
38706 };
38707
38708 static struct access_method SA5B_access = {
38709 - SA5_submit_command,
38710 - SA5B_intr_mask,
38711 - SA5_fifo_full,
38712 - SA5B_intr_pending,
38713 - SA5_completed,
38714 + .submit_command = SA5_submit_command,
38715 + .set_intr_mask = SA5B_intr_mask,
38716 + .fifo_full = SA5_fifo_full,
38717 + .intr_pending = SA5B_intr_pending,
38718 + .command_completed = SA5_completed,
38719 };
38720
38721 static struct access_method SA5_performant_access = {
38722 - SA5_submit_command,
38723 - SA5_performant_intr_mask,
38724 - SA5_fifo_full,
38725 - SA5_performant_intr_pending,
38726 - SA5_performant_completed,
38727 + .submit_command = SA5_submit_command,
38728 + .set_intr_mask = SA5_performant_intr_mask,
38729 + .fifo_full = SA5_fifo_full,
38730 + .intr_pending = SA5_performant_intr_pending,
38731 + .command_completed = SA5_performant_completed,
38732 };
38733
38734 struct board_type {
38735 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38736 index 2b94403..fd6ad1f 100644
38737 --- a/drivers/block/cpqarray.c
38738 +++ b/drivers/block/cpqarray.c
38739 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38740 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38741 goto Enomem4;
38742 }
38743 - hba[i]->access.set_intr_mask(hba[i], 0);
38744 + hba[i]->access->set_intr_mask(hba[i], 0);
38745 if (request_irq(hba[i]->intr, do_ida_intr,
38746 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38747 {
38748 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38749 add_timer(&hba[i]->timer);
38750
38751 /* Enable IRQ now that spinlock and rate limit timer are set up */
38752 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38753 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38754
38755 for(j=0; j<NWD; j++) {
38756 struct gendisk *disk = ida_gendisk[i][j];
38757 @@ -694,7 +694,7 @@ DBGINFO(
38758 for(i=0; i<NR_PRODUCTS; i++) {
38759 if (board_id == products[i].board_id) {
38760 c->product_name = products[i].product_name;
38761 - c->access = *(products[i].access);
38762 + c->access = products[i].access;
38763 break;
38764 }
38765 }
38766 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38767 hba[ctlr]->intr = intr;
38768 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38769 hba[ctlr]->product_name = products[j].product_name;
38770 - hba[ctlr]->access = *(products[j].access);
38771 + hba[ctlr]->access = products[j].access;
38772 hba[ctlr]->ctlr = ctlr;
38773 hba[ctlr]->board_id = board_id;
38774 hba[ctlr]->pci_dev = NULL; /* not PCI */
38775 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38776
38777 while((c = h->reqQ) != NULL) {
38778 /* Can't do anything if we're busy */
38779 - if (h->access.fifo_full(h) == 0)
38780 + if (h->access->fifo_full(h) == 0)
38781 return;
38782
38783 /* Get the first entry from the request Q */
38784 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38785 h->Qdepth--;
38786
38787 /* Tell the controller to do our bidding */
38788 - h->access.submit_command(h, c);
38789 + h->access->submit_command(h, c);
38790
38791 /* Get onto the completion Q */
38792 addQ(&h->cmpQ, c);
38793 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38794 unsigned long flags;
38795 __u32 a,a1;
38796
38797 - istat = h->access.intr_pending(h);
38798 + istat = h->access->intr_pending(h);
38799 /* Is this interrupt for us? */
38800 if (istat == 0)
38801 return IRQ_NONE;
38802 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38803 */
38804 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38805 if (istat & FIFO_NOT_EMPTY) {
38806 - while((a = h->access.command_completed(h))) {
38807 + while((a = h->access->command_completed(h))) {
38808 a1 = a; a &= ~3;
38809 if ((c = h->cmpQ) == NULL)
38810 {
38811 @@ -1448,11 +1448,11 @@ static int sendcmd(
38812 /*
38813 * Disable interrupt
38814 */
38815 - info_p->access.set_intr_mask(info_p, 0);
38816 + info_p->access->set_intr_mask(info_p, 0);
38817 /* Make sure there is room in the command FIFO */
38818 /* Actually it should be completely empty at this time. */
38819 for (i = 200000; i > 0; i--) {
38820 - temp = info_p->access.fifo_full(info_p);
38821 + temp = info_p->access->fifo_full(info_p);
38822 if (temp != 0) {
38823 break;
38824 }
38825 @@ -1465,7 +1465,7 @@ DBG(
38826 /*
38827 * Send the cmd
38828 */
38829 - info_p->access.submit_command(info_p, c);
38830 + info_p->access->submit_command(info_p, c);
38831 complete = pollcomplete(ctlr);
38832
38833 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38834 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38835 * we check the new geometry. Then turn interrupts back on when
38836 * we're done.
38837 */
38838 - host->access.set_intr_mask(host, 0);
38839 + host->access->set_intr_mask(host, 0);
38840 getgeometry(ctlr);
38841 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38842 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38843
38844 for(i=0; i<NWD; i++) {
38845 struct gendisk *disk = ida_gendisk[ctlr][i];
38846 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38847 /* Wait (up to 2 seconds) for a command to complete */
38848
38849 for (i = 200000; i > 0; i--) {
38850 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38851 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38852 if (done == 0) {
38853 udelay(10); /* a short fixed delay */
38854 } else
38855 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38856 index be73e9d..7fbf140 100644
38857 --- a/drivers/block/cpqarray.h
38858 +++ b/drivers/block/cpqarray.h
38859 @@ -99,7 +99,7 @@ struct ctlr_info {
38860 drv_info_t drv[NWD];
38861 struct proc_dir_entry *proc;
38862
38863 - struct access_method access;
38864 + struct access_method *access;
38865
38866 cmdlist_t *reqQ;
38867 cmdlist_t *cmpQ;
38868 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38869 index 426c97a..8c58607 100644
38870 --- a/drivers/block/drbd/drbd_bitmap.c
38871 +++ b/drivers/block/drbd/drbd_bitmap.c
38872 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38873 submit_bio(rw, bio);
38874 /* this should not count as user activity and cause the
38875 * resync to throttle -- see drbd_rs_should_slow_down(). */
38876 - atomic_add(len >> 9, &device->rs_sect_ev);
38877 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38878 }
38879 }
38880
38881 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38882 index 1a00001..c0d4253 100644
38883 --- a/drivers/block/drbd/drbd_int.h
38884 +++ b/drivers/block/drbd/drbd_int.h
38885 @@ -387,7 +387,7 @@ struct drbd_epoch {
38886 struct drbd_connection *connection;
38887 struct list_head list;
38888 unsigned int barrier_nr;
38889 - atomic_t epoch_size; /* increased on every request added. */
38890 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38891 atomic_t active; /* increased on every req. added, and dec on every finished. */
38892 unsigned long flags;
38893 };
38894 @@ -948,7 +948,7 @@ struct drbd_device {
38895 unsigned int al_tr_number;
38896 int al_tr_cycle;
38897 wait_queue_head_t seq_wait;
38898 - atomic_t packet_seq;
38899 + atomic_unchecked_t packet_seq;
38900 unsigned int peer_seq;
38901 spinlock_t peer_seq_lock;
38902 unsigned long comm_bm_set; /* communicated number of set bits. */
38903 @@ -957,8 +957,8 @@ struct drbd_device {
38904 struct mutex own_state_mutex;
38905 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38906 char congestion_reason; /* Why we where congested... */
38907 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38908 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38909 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38910 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38911 int rs_last_sect_ev; /* counter to compare with */
38912 int rs_last_events; /* counter of read or write "events" (unit sectors)
38913 * on the lower level device when we last looked. */
38914 @@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38915 char __user *uoptval;
38916 int err;
38917
38918 - uoptval = (char __user __force *)optval;
38919 + uoptval = (char __force_user *)optval;
38920
38921 set_fs(KERNEL_DS);
38922 if (level == SOL_SOCKET)
38923 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38924 index 04a14e0..5b8f0aa 100644
38925 --- a/drivers/block/drbd/drbd_interval.c
38926 +++ b/drivers/block/drbd/drbd_interval.c
38927 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38928 }
38929
38930 static const struct rb_augment_callbacks augment_callbacks = {
38931 - augment_propagate,
38932 - augment_copy,
38933 - augment_rotate,
38934 + .propagate = augment_propagate,
38935 + .copy = augment_copy,
38936 + .rotate = augment_rotate,
38937 };
38938
38939 /**
38940 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38941 index 9b465bb..00034ecf 100644
38942 --- a/drivers/block/drbd/drbd_main.c
38943 +++ b/drivers/block/drbd/drbd_main.c
38944 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38945 p->sector = sector;
38946 p->block_id = block_id;
38947 p->blksize = blksize;
38948 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38949 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38950 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38951 }
38952
38953 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38954 return -EIO;
38955 p->sector = cpu_to_be64(req->i.sector);
38956 p->block_id = (unsigned long)req;
38957 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38958 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38959 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38960 if (device->state.conn >= C_SYNC_SOURCE &&
38961 device->state.conn <= C_PAUSED_SYNC_T)
38962 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38963 atomic_set(&device->unacked_cnt, 0);
38964 atomic_set(&device->local_cnt, 0);
38965 atomic_set(&device->pp_in_use_by_net, 0);
38966 - atomic_set(&device->rs_sect_in, 0);
38967 - atomic_set(&device->rs_sect_ev, 0);
38968 + atomic_set_unchecked(&device->rs_sect_in, 0);
38969 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38970 atomic_set(&device->ap_in_flight, 0);
38971 atomic_set(&device->md_io.in_use, 0);
38972
38973 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38974 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38975 struct drbd_resource *resource = connection->resource;
38976
38977 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38978 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38979 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38980 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38981 kfree(connection->current_epoch);
38982
38983 idr_destroy(&connection->peer_devices);
38984 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38985 index 1cd47df..57c53c0 100644
38986 --- a/drivers/block/drbd/drbd_nl.c
38987 +++ b/drivers/block/drbd/drbd_nl.c
38988 @@ -3645,13 +3645,13 @@ finish:
38989
38990 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38991 {
38992 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38993 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38994 struct sk_buff *msg;
38995 struct drbd_genlmsghdr *d_out;
38996 unsigned seq;
38997 int err = -ENOMEM;
38998
38999 - seq = atomic_inc_return(&drbd_genl_seq);
39000 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39001 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39002 if (!msg)
39003 goto failed;
39004 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39005 index 9342b8d..b6a6825 100644
39006 --- a/drivers/block/drbd/drbd_receiver.c
39007 +++ b/drivers/block/drbd/drbd_receiver.c
39008 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39009 struct drbd_device *device = peer_device->device;
39010 int err;
39011
39012 - atomic_set(&device->packet_seq, 0);
39013 + atomic_set_unchecked(&device->packet_seq, 0);
39014 device->peer_seq = 0;
39015
39016 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39017 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39018 do {
39019 next_epoch = NULL;
39020
39021 - epoch_size = atomic_read(&epoch->epoch_size);
39022 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39023
39024 switch (ev & ~EV_CLEANUP) {
39025 case EV_PUT:
39026 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39027 rv = FE_DESTROYED;
39028 } else {
39029 epoch->flags = 0;
39030 - atomic_set(&epoch->epoch_size, 0);
39031 + atomic_set_unchecked(&epoch->epoch_size, 0);
39032 /* atomic_set(&epoch->active, 0); is already zero */
39033 if (rv == FE_STILL_LIVE)
39034 rv = FE_RECYCLED;
39035 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39036 conn_wait_active_ee_empty(connection);
39037 drbd_flush(connection);
39038
39039 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39040 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39041 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39042 if (epoch)
39043 break;
39044 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39045 }
39046
39047 epoch->flags = 0;
39048 - atomic_set(&epoch->epoch_size, 0);
39049 + atomic_set_unchecked(&epoch->epoch_size, 0);
39050 atomic_set(&epoch->active, 0);
39051
39052 spin_lock(&connection->epoch_lock);
39053 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39054 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39055 list_add(&epoch->list, &connection->current_epoch->list);
39056 connection->current_epoch = epoch;
39057 connection->epochs++;
39058 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39059 list_add_tail(&peer_req->w.list, &device->sync_ee);
39060 spin_unlock_irq(&device->resource->req_lock);
39061
39062 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
39063 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39064 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39065 return 0;
39066
39067 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39068 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39069 }
39070
39071 - atomic_add(pi->size >> 9, &device->rs_sect_in);
39072 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39073
39074 return err;
39075 }
39076 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39077
39078 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39079 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39080 - atomic_inc(&connection->current_epoch->epoch_size);
39081 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39082 err2 = drbd_drain_block(peer_device, pi->size);
39083 if (!err)
39084 err = err2;
39085 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39086
39087 spin_lock(&connection->epoch_lock);
39088 peer_req->epoch = connection->current_epoch;
39089 - atomic_inc(&peer_req->epoch->epoch_size);
39090 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39091 atomic_inc(&peer_req->epoch->active);
39092 spin_unlock(&connection->epoch_lock);
39093
39094 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39095
39096 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39097 (int)part_stat_read(&disk->part0, sectors[1]) -
39098 - atomic_read(&device->rs_sect_ev);
39099 + atomic_read_unchecked(&device->rs_sect_ev);
39100
39101 if (atomic_read(&device->ap_actlog_cnt)
39102 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39103 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39104 device->use_csums = true;
39105 } else if (pi->cmd == P_OV_REPLY) {
39106 /* track progress, we may need to throttle */
39107 - atomic_add(size >> 9, &device->rs_sect_in);
39108 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39109 peer_req->w.cb = w_e_end_ov_reply;
39110 dec_rs_pending(device);
39111 /* drbd_rs_begin_io done when we sent this request,
39112 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39113 goto out_free_e;
39114
39115 submit_for_resync:
39116 - atomic_add(size >> 9, &device->rs_sect_ev);
39117 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39118
39119 submit:
39120 update_receiver_timing_details(connection, drbd_submit_peer_request);
39121 @@ -4564,7 +4564,7 @@ struct data_cmd {
39122 int expect_payload;
39123 size_t pkt_size;
39124 int (*fn)(struct drbd_connection *, struct packet_info *);
39125 -};
39126 +} __do_const;
39127
39128 static struct data_cmd drbd_cmd_handler[] = {
39129 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39130 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39131 if (!list_empty(&connection->current_epoch->list))
39132 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39133 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39134 - atomic_set(&connection->current_epoch->epoch_size, 0);
39135 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39136 connection->send.seen_any_write_yet = false;
39137
39138 drbd_info(connection, "Connection closed\n");
39139 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39140 put_ldev(device);
39141 }
39142 dec_rs_pending(device);
39143 - atomic_add(blksize >> 9, &device->rs_sect_in);
39144 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39145
39146 return 0;
39147 }
39148 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39149 struct asender_cmd {
39150 size_t pkt_size;
39151 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39152 -};
39153 +} __do_const;
39154
39155 static struct asender_cmd asender_tbl[] = {
39156 [P_PING] = { 0, got_Ping },
39157 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39158 index 50776b3..1477c3f 100644
39159 --- a/drivers/block/drbd/drbd_worker.c
39160 +++ b/drivers/block/drbd/drbd_worker.c
39161 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39162 list_add_tail(&peer_req->w.list, &device->read_ee);
39163 spin_unlock_irq(&device->resource->req_lock);
39164
39165 - atomic_add(size >> 9, &device->rs_sect_ev);
39166 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39167 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39168 return 0;
39169
39170 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39171 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39172 int number, mxb;
39173
39174 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
39175 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39176 device->rs_in_flight -= sect_in;
39177
39178 rcu_read_lock();
39179 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39180 {
39181 struct fifo_buffer *plan;
39182
39183 - atomic_set(&device->rs_sect_in, 0);
39184 - atomic_set(&device->rs_sect_ev, 0);
39185 + atomic_set_unchecked(&device->rs_sect_in, 0);
39186 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39187 device->rs_in_flight = 0;
39188
39189 /* Updating the RCU protected object in place is necessary since
39190 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39191 index 6cb1beb..bf490f7 100644
39192 --- a/drivers/block/loop.c
39193 +++ b/drivers/block/loop.c
39194 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39195
39196 file_start_write(file);
39197 set_fs(get_ds());
39198 - bw = file->f_op->write(file, buf, len, &pos);
39199 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39200 set_fs(old_fs);
39201 file_end_write(file);
39202 if (likely(bw == len))
39203 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39204 index 02351e2..a9ea617 100644
39205 --- a/drivers/block/nvme-core.c
39206 +++ b/drivers/block/nvme-core.c
39207 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39208 static struct task_struct *nvme_thread;
39209 static struct workqueue_struct *nvme_workq;
39210 static wait_queue_head_t nvme_kthread_wait;
39211 -static struct notifier_block nvme_nb;
39212
39213 static void nvme_reset_failed_dev(struct work_struct *ws);
39214
39215 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39216 .err_handler = &nvme_err_handler,
39217 };
39218
39219 +static struct notifier_block nvme_nb = {
39220 + .notifier_call = &nvme_cpu_notify,
39221 +};
39222 +
39223 static int __init nvme_init(void)
39224 {
39225 int result;
39226 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39227 else if (result > 0)
39228 nvme_major = result;
39229
39230 - nvme_nb.notifier_call = &nvme_cpu_notify;
39231 result = register_hotcpu_notifier(&nvme_nb);
39232 if (result)
39233 goto unregister_blkdev;
39234 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39235 index 758ac44..58087fd 100644
39236 --- a/drivers/block/pktcdvd.c
39237 +++ b/drivers/block/pktcdvd.c
39238 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39239
39240 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39241 {
39242 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39243 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39244 }
39245
39246 /*
39247 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39248 return -EROFS;
39249 }
39250 pd->settings.fp = ti.fp;
39251 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39252 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39253
39254 if (ti.nwa_v) {
39255 pd->nwa = be32_to_cpu(ti.next_writable);
39256 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39257 index e5565fb..71be10b4 100644
39258 --- a/drivers/block/smart1,2.h
39259 +++ b/drivers/block/smart1,2.h
39260 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39261 }
39262
39263 static struct access_method smart4_access = {
39264 - smart4_submit_command,
39265 - smart4_intr_mask,
39266 - smart4_fifo_full,
39267 - smart4_intr_pending,
39268 - smart4_completed,
39269 + .submit_command = smart4_submit_command,
39270 + .set_intr_mask = smart4_intr_mask,
39271 + .fifo_full = smart4_fifo_full,
39272 + .intr_pending = smart4_intr_pending,
39273 + .command_completed = smart4_completed,
39274 };
39275
39276 /*
39277 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39278 }
39279
39280 static struct access_method smart2_access = {
39281 - smart2_submit_command,
39282 - smart2_intr_mask,
39283 - smart2_fifo_full,
39284 - smart2_intr_pending,
39285 - smart2_completed,
39286 + .submit_command = smart2_submit_command,
39287 + .set_intr_mask = smart2_intr_mask,
39288 + .fifo_full = smart2_fifo_full,
39289 + .intr_pending = smart2_intr_pending,
39290 + .command_completed = smart2_completed,
39291 };
39292
39293 /*
39294 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39295 }
39296
39297 static struct access_method smart2e_access = {
39298 - smart2e_submit_command,
39299 - smart2e_intr_mask,
39300 - smart2e_fifo_full,
39301 - smart2e_intr_pending,
39302 - smart2e_completed,
39303 + .submit_command = smart2e_submit_command,
39304 + .set_intr_mask = smart2e_intr_mask,
39305 + .fifo_full = smart2e_fifo_full,
39306 + .intr_pending = smart2e_intr_pending,
39307 + .command_completed = smart2e_completed,
39308 };
39309
39310 /*
39311 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39312 }
39313
39314 static struct access_method smart1_access = {
39315 - smart1_submit_command,
39316 - smart1_intr_mask,
39317 - smart1_fifo_full,
39318 - smart1_intr_pending,
39319 - smart1_completed,
39320 + .submit_command = smart1_submit_command,
39321 + .set_intr_mask = smart1_intr_mask,
39322 + .fifo_full = smart1_fifo_full,
39323 + .intr_pending = smart1_intr_pending,
39324 + .command_completed = smart1_completed,
39325 };
39326 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39327 index f038dba..bb74c08 100644
39328 --- a/drivers/bluetooth/btwilink.c
39329 +++ b/drivers/bluetooth/btwilink.c
39330 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39331
39332 static int bt_ti_probe(struct platform_device *pdev)
39333 {
39334 - static struct ti_st *hst;
39335 + struct ti_st *hst;
39336 struct hci_dev *hdev;
39337 int err;
39338
39339 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39340 index 898b84b..86f74b9 100644
39341 --- a/drivers/cdrom/cdrom.c
39342 +++ b/drivers/cdrom/cdrom.c
39343 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39344 ENSURE(reset, CDC_RESET);
39345 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39346 cdi->mc_flags = 0;
39347 - cdo->n_minors = 0;
39348 cdi->options = CDO_USE_FFLAGS;
39349
39350 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39351 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39352 else
39353 cdi->cdda_method = CDDA_OLD;
39354
39355 - if (!cdo->generic_packet)
39356 - cdo->generic_packet = cdrom_dummy_generic_packet;
39357 + if (!cdo->generic_packet) {
39358 + pax_open_kernel();
39359 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39360 + pax_close_kernel();
39361 + }
39362
39363 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39364 mutex_lock(&cdrom_mutex);
39365 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39366 if (cdi->exit)
39367 cdi->exit(cdi);
39368
39369 - cdi->ops->n_minors--;
39370 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39371 }
39372
39373 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39374 */
39375 nr = nframes;
39376 do {
39377 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39378 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39379 if (cgc.buffer)
39380 break;
39381
39382 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39383 struct cdrom_device_info *cdi;
39384 int ret;
39385
39386 - ret = scnprintf(info + *pos, max_size - *pos, header);
39387 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39388 if (!ret)
39389 return 1;
39390
39391 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39392 index 584bc31..e64a12c 100644
39393 --- a/drivers/cdrom/gdrom.c
39394 +++ b/drivers/cdrom/gdrom.c
39395 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39396 .audio_ioctl = gdrom_audio_ioctl,
39397 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39398 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39399 - .n_minors = 1,
39400 };
39401
39402 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39403 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39404 index 6e9f74a..50c7cea 100644
39405 --- a/drivers/char/Kconfig
39406 +++ b/drivers/char/Kconfig
39407 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39408
39409 config DEVKMEM
39410 bool "/dev/kmem virtual device support"
39411 - default y
39412 + default n
39413 + depends on !GRKERNSEC_KMEM
39414 help
39415 Say Y here if you want to support the /dev/kmem device. The
39416 /dev/kmem device is rarely used, but can be used for certain
39417 @@ -577,6 +578,7 @@ config DEVPORT
39418 bool
39419 depends on !M68K
39420 depends on ISA || PCI
39421 + depends on !GRKERNSEC_KMEM
39422 default y
39423
39424 source "drivers/s390/char/Kconfig"
39425 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39426 index a48e05b..6bac831 100644
39427 --- a/drivers/char/agp/compat_ioctl.c
39428 +++ b/drivers/char/agp/compat_ioctl.c
39429 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39430 return -ENOMEM;
39431 }
39432
39433 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39434 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39435 sizeof(*usegment) * ureserve.seg_count)) {
39436 kfree(usegment);
39437 kfree(ksegment);
39438 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39439 index 09f17eb..8531d2f 100644
39440 --- a/drivers/char/agp/frontend.c
39441 +++ b/drivers/char/agp/frontend.c
39442 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39443 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39444 return -EFAULT;
39445
39446 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39447 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39448 return -EFAULT;
39449
39450 client = agp_find_client_by_pid(reserve.pid);
39451 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39452 if (segment == NULL)
39453 return -ENOMEM;
39454
39455 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
39456 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39457 sizeof(struct agp_segment) * reserve.seg_count)) {
39458 kfree(segment);
39459 return -EFAULT;
39460 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39461 index 4f94375..413694e 100644
39462 --- a/drivers/char/genrtc.c
39463 +++ b/drivers/char/genrtc.c
39464 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39465 switch (cmd) {
39466
39467 case RTC_PLL_GET:
39468 + memset(&pll, 0, sizeof(pll));
39469 if (get_rtc_pll(&pll))
39470 return -EINVAL;
39471 else
39472 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39473 index d5d4cd8..22d561d 100644
39474 --- a/drivers/char/hpet.c
39475 +++ b/drivers/char/hpet.c
39476 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39477 }
39478
39479 static int
39480 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39481 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39482 struct hpet_info *info)
39483 {
39484 struct hpet_timer __iomem *timer;
39485 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39486 index 86fe45c..c0ea948 100644
39487 --- a/drivers/char/hw_random/intel-rng.c
39488 +++ b/drivers/char/hw_random/intel-rng.c
39489 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39490
39491 if (no_fwh_detect)
39492 return -ENODEV;
39493 - printk(warning);
39494 + printk("%s", warning);
39495 return -EBUSY;
39496 }
39497
39498 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39499 index e6db938..835e3a2 100644
39500 --- a/drivers/char/ipmi/ipmi_msghandler.c
39501 +++ b/drivers/char/ipmi/ipmi_msghandler.c
39502 @@ -438,7 +438,7 @@ struct ipmi_smi {
39503 struct proc_dir_entry *proc_dir;
39504 char proc_dir_name[10];
39505
39506 - atomic_t stats[IPMI_NUM_STATS];
39507 + atomic_unchecked_t stats[IPMI_NUM_STATS];
39508
39509 /*
39510 * run_to_completion duplicate of smb_info, smi_info
39511 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39512 static DEFINE_MUTEX(smi_watchers_mutex);
39513
39514 #define ipmi_inc_stat(intf, stat) \
39515 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39516 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39517 #define ipmi_get_stat(intf, stat) \
39518 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39519 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39520
39521 static int is_lan_addr(struct ipmi_addr *addr)
39522 {
39523 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39524 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39525 init_waitqueue_head(&intf->waitq);
39526 for (i = 0; i < IPMI_NUM_STATS; i++)
39527 - atomic_set(&intf->stats[i], 0);
39528 + atomic_set_unchecked(&intf->stats[i], 0);
39529
39530 intf->proc_dir = NULL;
39531
39532 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39533 index 5d66568..c9d93c3 100644
39534 --- a/drivers/char/ipmi/ipmi_si_intf.c
39535 +++ b/drivers/char/ipmi/ipmi_si_intf.c
39536 @@ -285,7 +285,7 @@ struct smi_info {
39537 unsigned char slave_addr;
39538
39539 /* Counters and things for the proc filesystem. */
39540 - atomic_t stats[SI_NUM_STATS];
39541 + atomic_unchecked_t stats[SI_NUM_STATS];
39542
39543 struct task_struct *thread;
39544
39545 @@ -294,9 +294,9 @@ struct smi_info {
39546 };
39547
39548 #define smi_inc_stat(smi, stat) \
39549 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39550 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39551 #define smi_get_stat(smi, stat) \
39552 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39553 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39554
39555 #define SI_MAX_PARMS 4
39556
39557 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39558 atomic_set(&new_smi->req_events, 0);
39559 new_smi->run_to_completion = false;
39560 for (i = 0; i < SI_NUM_STATS; i++)
39561 - atomic_set(&new_smi->stats[i], 0);
39562 + atomic_set_unchecked(&new_smi->stats[i], 0);
39563
39564 new_smi->interrupt_disabled = true;
39565 atomic_set(&new_smi->stop_operation, 0);
39566 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39567 index 917403f..dddd899 100644
39568 --- a/drivers/char/mem.c
39569 +++ b/drivers/char/mem.c
39570 @@ -18,6 +18,7 @@
39571 #include <linux/raw.h>
39572 #include <linux/tty.h>
39573 #include <linux/capability.h>
39574 +#include <linux/security.h>
39575 #include <linux/ptrace.h>
39576 #include <linux/device.h>
39577 #include <linux/highmem.h>
39578 @@ -36,6 +37,10 @@
39579
39580 #define DEVPORT_MINOR 4
39581
39582 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39583 +extern const struct file_operations grsec_fops;
39584 +#endif
39585 +
39586 static inline unsigned long size_inside_page(unsigned long start,
39587 unsigned long size)
39588 {
39589 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39590
39591 while (cursor < to) {
39592 if (!devmem_is_allowed(pfn)) {
39593 +#ifdef CONFIG_GRKERNSEC_KMEM
39594 + gr_handle_mem_readwrite(from, to);
39595 +#else
39596 printk(KERN_INFO
39597 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39598 current->comm, from, to);
39599 +#endif
39600 return 0;
39601 }
39602 cursor += PAGE_SIZE;
39603 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39604 }
39605 return 1;
39606 }
39607 +#elif defined(CONFIG_GRKERNSEC_KMEM)
39608 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39609 +{
39610 + return 0;
39611 +}
39612 #else
39613 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39614 {
39615 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39616
39617 while (count > 0) {
39618 unsigned long remaining;
39619 + char *temp;
39620
39621 sz = size_inside_page(p, count);
39622
39623 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39624 if (!ptr)
39625 return -EFAULT;
39626
39627 - remaining = copy_to_user(buf, ptr, sz);
39628 +#ifdef CONFIG_PAX_USERCOPY
39629 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39630 + if (!temp) {
39631 + unxlate_dev_mem_ptr(p, ptr);
39632 + return -ENOMEM;
39633 + }
39634 + memcpy(temp, ptr, sz);
39635 +#else
39636 + temp = ptr;
39637 +#endif
39638 +
39639 + remaining = copy_to_user(buf, temp, sz);
39640 +
39641 +#ifdef CONFIG_PAX_USERCOPY
39642 + kfree(temp);
39643 +#endif
39644 +
39645 unxlate_dev_mem_ptr(p, ptr);
39646 if (remaining)
39647 return -EFAULT;
39648 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39649 size_t count, loff_t *ppos)
39650 {
39651 unsigned long p = *ppos;
39652 - ssize_t low_count, read, sz;
39653 + ssize_t low_count, read, sz, err = 0;
39654 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39655 - int err = 0;
39656
39657 read = 0;
39658 if (p < (unsigned long) high_memory) {
39659 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39660 }
39661 #endif
39662 while (low_count > 0) {
39663 + char *temp;
39664 +
39665 sz = size_inside_page(p, low_count);
39666
39667 /*
39668 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39669 */
39670 kbuf = xlate_dev_kmem_ptr((char *)p);
39671
39672 - if (copy_to_user(buf, kbuf, sz))
39673 +#ifdef CONFIG_PAX_USERCOPY
39674 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39675 + if (!temp)
39676 + return -ENOMEM;
39677 + memcpy(temp, kbuf, sz);
39678 +#else
39679 + temp = kbuf;
39680 +#endif
39681 +
39682 + err = copy_to_user(buf, temp, sz);
39683 +
39684 +#ifdef CONFIG_PAX_USERCOPY
39685 + kfree(temp);
39686 +#endif
39687 +
39688 + if (err)
39689 return -EFAULT;
39690 buf += sz;
39691 p += sz;
39692 @@ -827,6 +874,9 @@ static const struct memdev {
39693 #ifdef CONFIG_PRINTK
39694 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39695 #endif
39696 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39697 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39698 +#endif
39699 };
39700
39701 static int memory_open(struct inode *inode, struct file *filp)
39702 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
39703 continue;
39704
39705 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39706 - NULL, devlist[minor].name);
39707 + NULL, "%s", devlist[minor].name);
39708 }
39709
39710 return tty_init();
39711 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39712 index 9df78e2..01ba9ae 100644
39713 --- a/drivers/char/nvram.c
39714 +++ b/drivers/char/nvram.c
39715 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
39716
39717 spin_unlock_irq(&rtc_lock);
39718
39719 - if (copy_to_user(buf, contents, tmp - contents))
39720 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
39721 return -EFAULT;
39722
39723 *ppos = i;
39724 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
39725 index 0ea9986..e7b07e4 100644
39726 --- a/drivers/char/pcmcia/synclink_cs.c
39727 +++ b/drivers/char/pcmcia/synclink_cs.c
39728 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39729
39730 if (debug_level >= DEBUG_LEVEL_INFO)
39731 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
39732 - __FILE__, __LINE__, info->device_name, port->count);
39733 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
39734
39735 if (tty_port_close_start(port, tty, filp) == 0)
39736 goto cleanup;
39737 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39738 cleanup:
39739 if (debug_level >= DEBUG_LEVEL_INFO)
39740 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
39741 - tty->driver->name, port->count);
39742 + tty->driver->name, atomic_read(&port->count));
39743 }
39744
39745 /* Wait until the transmitter is empty.
39746 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39747
39748 if (debug_level >= DEBUG_LEVEL_INFO)
39749 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
39750 - __FILE__, __LINE__, tty->driver->name, port->count);
39751 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
39752
39753 /* If port is closing, signal caller to try again */
39754 if (port->flags & ASYNC_CLOSING){
39755 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39756 goto cleanup;
39757 }
39758 spin_lock(&port->lock);
39759 - port->count++;
39760 + atomic_inc(&port->count);
39761 spin_unlock(&port->lock);
39762 spin_unlock_irqrestore(&info->netlock, flags);
39763
39764 - if (port->count == 1) {
39765 + if (atomic_read(&port->count) == 1) {
39766 /* 1st open on this device, init hardware */
39767 retval = startup(info, tty);
39768 if (retval < 0)
39769 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39770 unsigned short new_crctype;
39771
39772 /* return error if TTY interface open */
39773 - if (info->port.count)
39774 + if (atomic_read(&info->port.count))
39775 return -EBUSY;
39776
39777 switch (encoding)
39778 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
39779
39780 /* arbitrate between network and tty opens */
39781 spin_lock_irqsave(&info->netlock, flags);
39782 - if (info->port.count != 0 || info->netcount != 0) {
39783 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39784 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39785 spin_unlock_irqrestore(&info->netlock, flags);
39786 return -EBUSY;
39787 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39788 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39789
39790 /* return error if TTY interface open */
39791 - if (info->port.count)
39792 + if (atomic_read(&info->port.count))
39793 return -EBUSY;
39794
39795 if (cmd != SIOCWANDEV)
39796 diff --git a/drivers/char/random.c b/drivers/char/random.c
39797 index 8c86a95..7c499f3 100644
39798 --- a/drivers/char/random.c
39799 +++ b/drivers/char/random.c
39800 @@ -289,9 +289,6 @@
39801 /*
39802 * To allow fractional bits to be tracked, the entropy_count field is
39803 * denominated in units of 1/8th bits.
39804 - *
39805 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39806 - * credit_entropy_bits() needs to be 64 bits wide.
39807 */
39808 #define ENTROPY_SHIFT 3
39809 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39810 @@ -439,9 +436,9 @@ struct entropy_store {
39811 };
39812
39813 static void push_to_pool(struct work_struct *work);
39814 -static __u32 input_pool_data[INPUT_POOL_WORDS];
39815 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39816 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39817 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39818 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39819 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39820
39821 static struct entropy_store input_pool = {
39822 .poolinfo = &poolinfo_table[0],
39823 @@ -635,7 +632,7 @@ retry:
39824 /* The +2 corresponds to the /4 in the denominator */
39825
39826 do {
39827 - unsigned int anfrac = min(pnfrac, pool_size/2);
39828 + u64 anfrac = min(pnfrac, pool_size/2);
39829 unsigned int add =
39830 ((pool_size - entropy_count)*anfrac*3) >> s;
39831
39832 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39833
39834 extract_buf(r, tmp);
39835 i = min_t(int, nbytes, EXTRACT_SIZE);
39836 - if (copy_to_user(buf, tmp, i)) {
39837 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39838 ret = -EFAULT;
39839 break;
39840 }
39841 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39842 static int proc_do_uuid(struct ctl_table *table, int write,
39843 void __user *buffer, size_t *lenp, loff_t *ppos)
39844 {
39845 - struct ctl_table fake_table;
39846 + ctl_table_no_const fake_table;
39847 unsigned char buf[64], tmp_uuid[16], *uuid;
39848
39849 uuid = table->data;
39850 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39851 static int proc_do_entropy(struct ctl_table *table, int write,
39852 void __user *buffer, size_t *lenp, loff_t *ppos)
39853 {
39854 - struct ctl_table fake_table;
39855 + ctl_table_no_const fake_table;
39856 int entropy_count;
39857
39858 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39859 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39860 index 7cc1fe22..b602d6b 100644
39861 --- a/drivers/char/sonypi.c
39862 +++ b/drivers/char/sonypi.c
39863 @@ -54,6 +54,7 @@
39864
39865 #include <asm/uaccess.h>
39866 #include <asm/io.h>
39867 +#include <asm/local.h>
39868
39869 #include <linux/sonypi.h>
39870
39871 @@ -490,7 +491,7 @@ static struct sonypi_device {
39872 spinlock_t fifo_lock;
39873 wait_queue_head_t fifo_proc_list;
39874 struct fasync_struct *fifo_async;
39875 - int open_count;
39876 + local_t open_count;
39877 int model;
39878 struct input_dev *input_jog_dev;
39879 struct input_dev *input_key_dev;
39880 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39881 static int sonypi_misc_release(struct inode *inode, struct file *file)
39882 {
39883 mutex_lock(&sonypi_device.lock);
39884 - sonypi_device.open_count--;
39885 + local_dec(&sonypi_device.open_count);
39886 mutex_unlock(&sonypi_device.lock);
39887 return 0;
39888 }
39889 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39890 {
39891 mutex_lock(&sonypi_device.lock);
39892 /* Flush input queue on first open */
39893 - if (!sonypi_device.open_count)
39894 + if (!local_read(&sonypi_device.open_count))
39895 kfifo_reset(&sonypi_device.fifo);
39896 - sonypi_device.open_count++;
39897 + local_inc(&sonypi_device.open_count);
39898 mutex_unlock(&sonypi_device.lock);
39899
39900 return 0;
39901 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39902 index 565a947..dcdc06e 100644
39903 --- a/drivers/char/tpm/tpm_acpi.c
39904 +++ b/drivers/char/tpm/tpm_acpi.c
39905 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39906 virt = acpi_os_map_iomem(start, len);
39907 if (!virt) {
39908 kfree(log->bios_event_log);
39909 + log->bios_event_log = NULL;
39910 printk("%s: ERROR - Unable to map memory\n", __func__);
39911 return -EIO;
39912 }
39913
39914 - memcpy_fromio(log->bios_event_log, virt, len);
39915 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39916
39917 acpi_os_unmap_iomem(virt, len);
39918 return 0;
39919 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39920 index 3a56a13..f8cbd25 100644
39921 --- a/drivers/char/tpm/tpm_eventlog.c
39922 +++ b/drivers/char/tpm/tpm_eventlog.c
39923 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39924 event = addr;
39925
39926 if ((event->event_type == 0 && event->event_size == 0) ||
39927 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39928 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39929 return NULL;
39930
39931 return addr;
39932 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39933 return NULL;
39934
39935 if ((event->event_type == 0 && event->event_size == 0) ||
39936 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39937 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39938 return NULL;
39939
39940 (*pos)++;
39941 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39942 int i;
39943
39944 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39945 - seq_putc(m, data[i]);
39946 + if (!seq_putc(m, data[i]))
39947 + return -EFAULT;
39948
39949 return 0;
39950 }
39951 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39952 index b585b47..488f43e 100644
39953 --- a/drivers/char/virtio_console.c
39954 +++ b/drivers/char/virtio_console.c
39955 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39956 if (to_user) {
39957 ssize_t ret;
39958
39959 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39960 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39961 if (ret)
39962 return -EFAULT;
39963 } else {
39964 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39965 if (!port_has_data(port) && !port->host_connected)
39966 return 0;
39967
39968 - return fill_readbuf(port, ubuf, count, true);
39969 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39970 }
39971
39972 static int wait_port_writable(struct port *port, bool nonblock)
39973 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39974 index b9355da..9611f4e 100644
39975 --- a/drivers/clk/clk-composite.c
39976 +++ b/drivers/clk/clk-composite.c
39977 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39978 struct clk *clk;
39979 struct clk_init_data init;
39980 struct clk_composite *composite;
39981 - struct clk_ops *clk_composite_ops;
39982 + clk_ops_no_const *clk_composite_ops;
39983
39984 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39985 if (!composite) {
39986 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39987 index dd3a78c..386d49c 100644
39988 --- a/drivers/clk/socfpga/clk-gate.c
39989 +++ b/drivers/clk/socfpga/clk-gate.c
39990 @@ -22,6 +22,7 @@
39991 #include <linux/mfd/syscon.h>
39992 #include <linux/of.h>
39993 #include <linux/regmap.h>
39994 +#include <asm/pgtable.h>
39995
39996 #include "clk.h"
39997
39998 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39999 return 0;
40000 }
40001
40002 -static struct clk_ops gateclk_ops = {
40003 +static clk_ops_no_const gateclk_ops __read_only = {
40004 .prepare = socfpga_clk_prepare,
40005 .recalc_rate = socfpga_clk_recalc_rate,
40006 .get_parent = socfpga_clk_get_parent,
40007 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40008 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40009 socfpga_clk->hw.bit_idx = clk_gate[1];
40010
40011 - gateclk_ops.enable = clk_gate_ops.enable;
40012 - gateclk_ops.disable = clk_gate_ops.disable;
40013 + pax_open_kernel();
40014 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40015 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40016 + pax_close_kernel();
40017 }
40018
40019 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40020 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40021 index de6da95..c98278b 100644
40022 --- a/drivers/clk/socfpga/clk-pll.c
40023 +++ b/drivers/clk/socfpga/clk-pll.c
40024 @@ -21,6 +21,7 @@
40025 #include <linux/io.h>
40026 #include <linux/of.h>
40027 #include <linux/of_address.h>
40028 +#include <asm/pgtable.h>
40029
40030 #include "clk.h"
40031
40032 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40033 CLK_MGR_PLL_CLK_SRC_MASK;
40034 }
40035
40036 -static struct clk_ops clk_pll_ops = {
40037 +static clk_ops_no_const clk_pll_ops __read_only = {
40038 .recalc_rate = clk_pll_recalc_rate,
40039 .get_parent = clk_pll_get_parent,
40040 };
40041 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40042 pll_clk->hw.hw.init = &init;
40043
40044 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40045 - clk_pll_ops.enable = clk_gate_ops.enable;
40046 - clk_pll_ops.disable = clk_gate_ops.disable;
40047 + pax_open_kernel();
40048 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40049 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40050 + pax_close_kernel();
40051
40052 clk = clk_register(NULL, &pll_clk->hw.hw);
40053 if (WARN_ON(IS_ERR(clk))) {
40054 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40055 index b0c18ed..1713a80 100644
40056 --- a/drivers/cpufreq/acpi-cpufreq.c
40057 +++ b/drivers/cpufreq/acpi-cpufreq.c
40058 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40059 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40060 per_cpu(acfreq_data, cpu) = data;
40061
40062 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40063 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40064 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40065 + pax_open_kernel();
40066 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40067 + pax_close_kernel();
40068 + }
40069
40070 result = acpi_processor_register_performance(data->acpi_data, cpu);
40071 if (result)
40072 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40073 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40074 break;
40075 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40076 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40077 + pax_open_kernel();
40078 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40079 + pax_close_kernel();
40080 break;
40081 default:
40082 break;
40083 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40084 if (!msrs)
40085 return;
40086
40087 - acpi_cpufreq_driver.boost_supported = true;
40088 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40089 + pax_open_kernel();
40090 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40091 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40092 + pax_close_kernel();
40093
40094 cpu_notifier_register_begin();
40095
40096 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40097 index 07c8276..38bd07c 100644
40098 --- a/drivers/cpufreq/cpufreq.c
40099 +++ b/drivers/cpufreq/cpufreq.c
40100 @@ -2107,7 +2107,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40101 }
40102
40103 mutex_lock(&cpufreq_governor_mutex);
40104 - list_del(&governor->governor_list);
40105 + pax_list_del(&governor->governor_list);
40106 mutex_unlock(&cpufreq_governor_mutex);
40107 return;
40108 }
40109 @@ -2323,7 +2323,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40110 return NOTIFY_OK;
40111 }
40112
40113 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40114 +static struct notifier_block cpufreq_cpu_notifier = {
40115 .notifier_call = cpufreq_cpu_callback,
40116 };
40117
40118 @@ -2363,13 +2363,17 @@ int cpufreq_boost_trigger_state(int state)
40119 return 0;
40120
40121 write_lock_irqsave(&cpufreq_driver_lock, flags);
40122 - cpufreq_driver->boost_enabled = state;
40123 + pax_open_kernel();
40124 + *(bool *)&cpufreq_driver->boost_enabled = state;
40125 + pax_close_kernel();
40126 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40127
40128 ret = cpufreq_driver->set_boost(state);
40129 if (ret) {
40130 write_lock_irqsave(&cpufreq_driver_lock, flags);
40131 - cpufreq_driver->boost_enabled = !state;
40132 + pax_open_kernel();
40133 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40134 + pax_close_kernel();
40135 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40136
40137 pr_err("%s: Cannot %s BOOST\n",
40138 @@ -2426,8 +2430,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40139
40140 pr_debug("trying to register driver %s\n", driver_data->name);
40141
40142 - if (driver_data->setpolicy)
40143 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40144 + if (driver_data->setpolicy) {
40145 + pax_open_kernel();
40146 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40147 + pax_close_kernel();
40148 + }
40149
40150 write_lock_irqsave(&cpufreq_driver_lock, flags);
40151 if (cpufreq_driver) {
40152 @@ -2442,8 +2449,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40153 * Check if driver provides function to enable boost -
40154 * if not, use cpufreq_boost_set_sw as default
40155 */
40156 - if (!cpufreq_driver->set_boost)
40157 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40158 + if (!cpufreq_driver->set_boost) {
40159 + pax_open_kernel();
40160 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40161 + pax_close_kernel();
40162 + }
40163
40164 ret = cpufreq_sysfs_create_file(&boost.attr);
40165 if (ret) {
40166 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40167 index 1b44496..b80ff5e 100644
40168 --- a/drivers/cpufreq/cpufreq_governor.c
40169 +++ b/drivers/cpufreq/cpufreq_governor.c
40170 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40171 struct dbs_data *dbs_data;
40172 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40173 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40174 - struct od_ops *od_ops = NULL;
40175 + const struct od_ops *od_ops = NULL;
40176 struct od_dbs_tuners *od_tuners = NULL;
40177 struct cs_dbs_tuners *cs_tuners = NULL;
40178 struct cpu_dbs_common_info *cpu_cdbs;
40179 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40180
40181 if ((cdata->governor == GOV_CONSERVATIVE) &&
40182 (!policy->governor->initialized)) {
40183 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40184 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40185
40186 cpufreq_register_notifier(cs_ops->notifier_block,
40187 CPUFREQ_TRANSITION_NOTIFIER);
40188 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40189
40190 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40191 (policy->governor->initialized == 1)) {
40192 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40193 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40194
40195 cpufreq_unregister_notifier(cs_ops->notifier_block,
40196 CPUFREQ_TRANSITION_NOTIFIER);
40197 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40198 index cc401d1..8197340 100644
40199 --- a/drivers/cpufreq/cpufreq_governor.h
40200 +++ b/drivers/cpufreq/cpufreq_governor.h
40201 @@ -212,7 +212,7 @@ struct common_dbs_data {
40202 void (*exit)(struct dbs_data *dbs_data);
40203
40204 /* Governor specific ops, see below */
40205 - void *gov_ops;
40206 + const void *gov_ops;
40207 };
40208
40209 /* Governor Per policy data */
40210 @@ -232,7 +232,7 @@ struct od_ops {
40211 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40212 unsigned int freq_next, unsigned int relation);
40213 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40214 -};
40215 +} __no_const;
40216
40217 struct cs_ops {
40218 struct notifier_block *notifier_block;
40219 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40220 index ad3f38f..8f086cd 100644
40221 --- a/drivers/cpufreq/cpufreq_ondemand.c
40222 +++ b/drivers/cpufreq/cpufreq_ondemand.c
40223 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40224
40225 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40226
40227 -static struct od_ops od_ops = {
40228 +static struct od_ops od_ops __read_only = {
40229 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40230 .powersave_bias_target = generic_powersave_bias_target,
40231 .freq_increase = dbs_freq_increase,
40232 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40233 (struct cpufreq_policy *, unsigned int, unsigned int),
40234 unsigned int powersave_bias)
40235 {
40236 - od_ops.powersave_bias_target = f;
40237 + pax_open_kernel();
40238 + *(void **)&od_ops.powersave_bias_target = f;
40239 + pax_close_kernel();
40240 od_set_powersave_bias(powersave_bias);
40241 }
40242 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40243
40244 void od_unregister_powersave_bias_handler(void)
40245 {
40246 - od_ops.powersave_bias_target = generic_powersave_bias_target;
40247 + pax_open_kernel();
40248 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40249 + pax_close_kernel();
40250 od_set_powersave_bias(0);
40251 }
40252 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40253 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40254 index 27bb6d3..4cf595c 100644
40255 --- a/drivers/cpufreq/intel_pstate.c
40256 +++ b/drivers/cpufreq/intel_pstate.c
40257 @@ -133,10 +133,10 @@ struct pstate_funcs {
40258 struct cpu_defaults {
40259 struct pstate_adjust_policy pid_policy;
40260 struct pstate_funcs funcs;
40261 -};
40262 +} __do_const;
40263
40264 static struct pstate_adjust_policy pid_params;
40265 -static struct pstate_funcs pstate_funcs;
40266 +static struct pstate_funcs *pstate_funcs;
40267
40268 struct perf_limits {
40269 int no_turbo;
40270 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40271
40272 cpu->pstate.current_pstate = pstate;
40273
40274 - pstate_funcs.set(cpu, pstate);
40275 + pstate_funcs->set(cpu, pstate);
40276 }
40277
40278 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40279 {
40280 - cpu->pstate.min_pstate = pstate_funcs.get_min();
40281 - cpu->pstate.max_pstate = pstate_funcs.get_max();
40282 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40283 - cpu->pstate.scaling = pstate_funcs.get_scaling();
40284 + cpu->pstate.min_pstate = pstate_funcs->get_min();
40285 + cpu->pstate.max_pstate = pstate_funcs->get_max();
40286 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40287 + cpu->pstate.scaling = pstate_funcs->get_scaling();
40288
40289 - if (pstate_funcs.get_vid)
40290 - pstate_funcs.get_vid(cpu);
40291 + if (pstate_funcs->get_vid)
40292 + pstate_funcs->get_vid(cpu);
40293 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40294 }
40295
40296 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
40297 rdmsrl(MSR_IA32_APERF, aperf);
40298 rdmsrl(MSR_IA32_MPERF, mperf);
40299
40300 - if (!pstate_funcs.get_max() ||
40301 - !pstate_funcs.get_min() ||
40302 - !pstate_funcs.get_turbo())
40303 + if (!pstate_funcs->get_max() ||
40304 + !pstate_funcs->get_min() ||
40305 + !pstate_funcs->get_turbo())
40306 return -ENODEV;
40307
40308 rdmsrl(MSR_IA32_APERF, tmp);
40309 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
40310 return 0;
40311 }
40312
40313 -static void copy_pid_params(struct pstate_adjust_policy *policy)
40314 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
40315 {
40316 pid_params.sample_rate_ms = policy->sample_rate_ms;
40317 pid_params.p_gain_pct = policy->p_gain_pct;
40318 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40319
40320 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40321 {
40322 - pstate_funcs.get_max = funcs->get_max;
40323 - pstate_funcs.get_min = funcs->get_min;
40324 - pstate_funcs.get_turbo = funcs->get_turbo;
40325 - pstate_funcs.get_scaling = funcs->get_scaling;
40326 - pstate_funcs.set = funcs->set;
40327 - pstate_funcs.get_vid = funcs->get_vid;
40328 + pstate_funcs = funcs;
40329 }
40330
40331 #if IS_ENABLED(CONFIG_ACPI)
40332 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40333 index 529cfd9..0e28fff 100644
40334 --- a/drivers/cpufreq/p4-clockmod.c
40335 +++ b/drivers/cpufreq/p4-clockmod.c
40336 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40337 case 0x0F: /* Core Duo */
40338 case 0x16: /* Celeron Core */
40339 case 0x1C: /* Atom */
40340 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40341 + pax_open_kernel();
40342 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40343 + pax_close_kernel();
40344 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40345 case 0x0D: /* Pentium M (Dothan) */
40346 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40347 + pax_open_kernel();
40348 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40349 + pax_close_kernel();
40350 /* fall through */
40351 case 0x09: /* Pentium M (Banias) */
40352 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40353 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40354
40355 /* on P-4s, the TSC runs with constant frequency independent whether
40356 * throttling is active or not. */
40357 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40358 + pax_open_kernel();
40359 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40360 + pax_close_kernel();
40361
40362 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40363 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40364 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40365 index 9bb42ba..b01b4a2 100644
40366 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
40367 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40368 @@ -18,14 +18,12 @@
40369 #include <asm/head.h>
40370 #include <asm/timer.h>
40371
40372 -static struct cpufreq_driver *cpufreq_us3_driver;
40373 -
40374 struct us3_freq_percpu_info {
40375 struct cpufreq_frequency_table table[4];
40376 };
40377
40378 /* Indexed by cpu number. */
40379 -static struct us3_freq_percpu_info *us3_freq_table;
40380 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40381
40382 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40383 * in the Safari config register.
40384 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40385
40386 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40387 {
40388 - if (cpufreq_us3_driver)
40389 - us3_freq_target(policy, 0);
40390 + us3_freq_target(policy, 0);
40391
40392 return 0;
40393 }
40394
40395 +static int __init us3_freq_init(void);
40396 +static void __exit us3_freq_exit(void);
40397 +
40398 +static struct cpufreq_driver cpufreq_us3_driver = {
40399 + .init = us3_freq_cpu_init,
40400 + .verify = cpufreq_generic_frequency_table_verify,
40401 + .target_index = us3_freq_target,
40402 + .get = us3_freq_get,
40403 + .exit = us3_freq_cpu_exit,
40404 + .name = "UltraSPARC-III",
40405 +
40406 +};
40407 +
40408 static int __init us3_freq_init(void)
40409 {
40410 unsigned long manuf, impl, ver;
40411 - int ret;
40412
40413 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40414 return -ENODEV;
40415 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40416 (impl == CHEETAH_IMPL ||
40417 impl == CHEETAH_PLUS_IMPL ||
40418 impl == JAGUAR_IMPL ||
40419 - impl == PANTHER_IMPL)) {
40420 - struct cpufreq_driver *driver;
40421 -
40422 - ret = -ENOMEM;
40423 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40424 - if (!driver)
40425 - goto err_out;
40426 -
40427 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40428 - GFP_KERNEL);
40429 - if (!us3_freq_table)
40430 - goto err_out;
40431 -
40432 - driver->init = us3_freq_cpu_init;
40433 - driver->verify = cpufreq_generic_frequency_table_verify;
40434 - driver->target_index = us3_freq_target;
40435 - driver->get = us3_freq_get;
40436 - driver->exit = us3_freq_cpu_exit;
40437 - strcpy(driver->name, "UltraSPARC-III");
40438 -
40439 - cpufreq_us3_driver = driver;
40440 - ret = cpufreq_register_driver(driver);
40441 - if (ret)
40442 - goto err_out;
40443 -
40444 - return 0;
40445 -
40446 -err_out:
40447 - if (driver) {
40448 - kfree(driver);
40449 - cpufreq_us3_driver = NULL;
40450 - }
40451 - kfree(us3_freq_table);
40452 - us3_freq_table = NULL;
40453 - return ret;
40454 - }
40455 + impl == PANTHER_IMPL))
40456 + return cpufreq_register_driver(&cpufreq_us3_driver);
40457
40458 return -ENODEV;
40459 }
40460
40461 static void __exit us3_freq_exit(void)
40462 {
40463 - if (cpufreq_us3_driver) {
40464 - cpufreq_unregister_driver(cpufreq_us3_driver);
40465 - kfree(cpufreq_us3_driver);
40466 - cpufreq_us3_driver = NULL;
40467 - kfree(us3_freq_table);
40468 - us3_freq_table = NULL;
40469 - }
40470 + cpufreq_unregister_driver(&cpufreq_us3_driver);
40471 }
40472
40473 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40474 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40475 index 7d4a315..21bb886 100644
40476 --- a/drivers/cpufreq/speedstep-centrino.c
40477 +++ b/drivers/cpufreq/speedstep-centrino.c
40478 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40479 !cpu_has(cpu, X86_FEATURE_EST))
40480 return -ENODEV;
40481
40482 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40483 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40484 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40485 + pax_open_kernel();
40486 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40487 + pax_close_kernel();
40488 + }
40489
40490 if (policy->cpu != 0)
40491 return -ENODEV;
40492 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40493 index e431d11..d0b997e 100644
40494 --- a/drivers/cpuidle/driver.c
40495 +++ b/drivers/cpuidle/driver.c
40496 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40497
40498 static void poll_idle_init(struct cpuidle_driver *drv)
40499 {
40500 - struct cpuidle_state *state = &drv->states[0];
40501 + cpuidle_state_no_const *state = &drv->states[0];
40502
40503 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40504 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40505 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40506 index ca89412..a7b9c49 100644
40507 --- a/drivers/cpuidle/governor.c
40508 +++ b/drivers/cpuidle/governor.c
40509 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40510 mutex_lock(&cpuidle_lock);
40511 if (__cpuidle_find_governor(gov->name) == NULL) {
40512 ret = 0;
40513 - list_add_tail(&gov->governor_list, &cpuidle_governors);
40514 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40515 if (!cpuidle_curr_governor ||
40516 cpuidle_curr_governor->rating < gov->rating)
40517 cpuidle_switch_governor(gov);
40518 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40519 index 97c5903..023ad23 100644
40520 --- a/drivers/cpuidle/sysfs.c
40521 +++ b/drivers/cpuidle/sysfs.c
40522 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40523 NULL
40524 };
40525
40526 -static struct attribute_group cpuidle_attr_group = {
40527 +static attribute_group_no_const cpuidle_attr_group = {
40528 .attrs = cpuidle_default_attrs,
40529 .name = "cpuidle",
40530 };
40531 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40532 index 8d2a772..33826c9 100644
40533 --- a/drivers/crypto/hifn_795x.c
40534 +++ b/drivers/crypto/hifn_795x.c
40535 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40536 MODULE_PARM_DESC(hifn_pll_ref,
40537 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40538
40539 -static atomic_t hifn_dev_number;
40540 +static atomic_unchecked_t hifn_dev_number;
40541
40542 #define ACRYPTO_OP_DECRYPT 0
40543 #define ACRYPTO_OP_ENCRYPT 1
40544 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40545 goto err_out_disable_pci_device;
40546
40547 snprintf(name, sizeof(name), "hifn%d",
40548 - atomic_inc_return(&hifn_dev_number)-1);
40549 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
40550
40551 err = pci_request_regions(pdev, name);
40552 if (err)
40553 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40554 index 9f90369..bfcacdb 100644
40555 --- a/drivers/devfreq/devfreq.c
40556 +++ b/drivers/devfreq/devfreq.c
40557 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40558 goto err_out;
40559 }
40560
40561 - list_add(&governor->node, &devfreq_governor_list);
40562 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40563
40564 list_for_each_entry(devfreq, &devfreq_list, node) {
40565 int ret = 0;
40566 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40567 }
40568 }
40569
40570 - list_del(&governor->node);
40571 + pax_list_del((struct list_head *)&governor->node);
40572 err_out:
40573 mutex_unlock(&devfreq_list_lock);
40574
40575 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40576 index 42d4974..2714f36 100644
40577 --- a/drivers/dma/sh/shdma-base.c
40578 +++ b/drivers/dma/sh/shdma-base.c
40579 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40580 schan->slave_id = -EINVAL;
40581 }
40582
40583 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40584 - sdev->desc_size, GFP_KERNEL);
40585 + schan->desc = kcalloc(sdev->desc_size,
40586 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40587 if (!schan->desc) {
40588 ret = -ENOMEM;
40589 goto edescalloc;
40590 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40591 index 58eb857..d7e42c8 100644
40592 --- a/drivers/dma/sh/shdmac.c
40593 +++ b/drivers/dma/sh/shdmac.c
40594 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40595 return ret;
40596 }
40597
40598 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40599 +static struct notifier_block sh_dmae_nmi_notifier = {
40600 .notifier_call = sh_dmae_nmi_handler,
40601
40602 /* Run before NMI debug handler and KGDB */
40603 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40604 index 592af5f..bb1d583 100644
40605 --- a/drivers/edac/edac_device.c
40606 +++ b/drivers/edac/edac_device.c
40607 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40608 */
40609 int edac_device_alloc_index(void)
40610 {
40611 - static atomic_t device_indexes = ATOMIC_INIT(0);
40612 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40613
40614 - return atomic_inc_return(&device_indexes) - 1;
40615 + return atomic_inc_return_unchecked(&device_indexes) - 1;
40616 }
40617 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40618
40619 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40620 index a6cd361..7bdbf53 100644
40621 --- a/drivers/edac/edac_mc_sysfs.c
40622 +++ b/drivers/edac/edac_mc_sysfs.c
40623 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40624 struct dev_ch_attribute {
40625 struct device_attribute attr;
40626 int channel;
40627 -};
40628 +} __do_const;
40629
40630 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40631 struct dev_ch_attribute dev_attr_legacy_##_name = \
40632 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40633 }
40634
40635 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40636 + pax_open_kernel();
40637 if (mci->get_sdram_scrub_rate) {
40638 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40639 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40640 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40641 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40642 }
40643 if (mci->set_sdram_scrub_rate) {
40644 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40645 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40646 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40647 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40648 }
40649 + pax_close_kernel();
40650 err = device_create_file(&mci->dev,
40651 &dev_attr_sdram_scrub_rate);
40652 if (err) {
40653 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40654 index 2cf44b4d..6dd2dc7 100644
40655 --- a/drivers/edac/edac_pci.c
40656 +++ b/drivers/edac/edac_pci.c
40657 @@ -29,7 +29,7 @@
40658
40659 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40660 static LIST_HEAD(edac_pci_list);
40661 -static atomic_t pci_indexes = ATOMIC_INIT(0);
40662 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40663
40664 /*
40665 * edac_pci_alloc_ctl_info
40666 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40667 */
40668 int edac_pci_alloc_index(void)
40669 {
40670 - return atomic_inc_return(&pci_indexes) - 1;
40671 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
40672 }
40673 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40674
40675 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40676 index e8658e4..22746d6 100644
40677 --- a/drivers/edac/edac_pci_sysfs.c
40678 +++ b/drivers/edac/edac_pci_sysfs.c
40679 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40680 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40681 static int edac_pci_poll_msec = 1000; /* one second workq period */
40682
40683 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
40684 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40685 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40686 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40687
40688 static struct kobject *edac_pci_top_main_kobj;
40689 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40690 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40691 void *value;
40692 ssize_t(*show) (void *, char *);
40693 ssize_t(*store) (void *, const char *, size_t);
40694 -};
40695 +} __do_const;
40696
40697 /* Set of show/store abstract level functions for PCI Parity object */
40698 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40699 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40700 edac_printk(KERN_CRIT, EDAC_PCI,
40701 "Signaled System Error on %s\n",
40702 pci_name(dev));
40703 - atomic_inc(&pci_nonparity_count);
40704 + atomic_inc_unchecked(&pci_nonparity_count);
40705 }
40706
40707 if (status & (PCI_STATUS_PARITY)) {
40708 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40709 "Master Data Parity Error on %s\n",
40710 pci_name(dev));
40711
40712 - atomic_inc(&pci_parity_count);
40713 + atomic_inc_unchecked(&pci_parity_count);
40714 }
40715
40716 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40717 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40718 "Detected Parity Error on %s\n",
40719 pci_name(dev));
40720
40721 - atomic_inc(&pci_parity_count);
40722 + atomic_inc_unchecked(&pci_parity_count);
40723 }
40724 }
40725
40726 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40727 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
40728 "Signaled System Error on %s\n",
40729 pci_name(dev));
40730 - atomic_inc(&pci_nonparity_count);
40731 + atomic_inc_unchecked(&pci_nonparity_count);
40732 }
40733
40734 if (status & (PCI_STATUS_PARITY)) {
40735 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40736 "Master Data Parity Error on "
40737 "%s\n", pci_name(dev));
40738
40739 - atomic_inc(&pci_parity_count);
40740 + atomic_inc_unchecked(&pci_parity_count);
40741 }
40742
40743 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40744 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40745 "Detected Parity Error on %s\n",
40746 pci_name(dev));
40747
40748 - atomic_inc(&pci_parity_count);
40749 + atomic_inc_unchecked(&pci_parity_count);
40750 }
40751 }
40752 }
40753 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40754 if (!check_pci_errors)
40755 return;
40756
40757 - before_count = atomic_read(&pci_parity_count);
40758 + before_count = atomic_read_unchecked(&pci_parity_count);
40759
40760 /* scan all PCI devices looking for a Parity Error on devices and
40761 * bridges.
40762 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40763 /* Only if operator has selected panic on PCI Error */
40764 if (edac_pci_get_panic_on_pe()) {
40765 /* If the count is different 'after' from 'before' */
40766 - if (before_count != atomic_read(&pci_parity_count))
40767 + if (before_count != atomic_read_unchecked(&pci_parity_count))
40768 panic("EDAC: PCI Parity Error");
40769 }
40770 }
40771 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40772 index 51b7e3a..aa8a3e8 100644
40773 --- a/drivers/edac/mce_amd.h
40774 +++ b/drivers/edac/mce_amd.h
40775 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
40776 bool (*mc0_mce)(u16, u8);
40777 bool (*mc1_mce)(u16, u8);
40778 bool (*mc2_mce)(u16, u8);
40779 -};
40780 +} __no_const;
40781
40782 void amd_report_gart_errors(bool);
40783 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40784 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40785 index 57ea7f4..af06b76 100644
40786 --- a/drivers/firewire/core-card.c
40787 +++ b/drivers/firewire/core-card.c
40788 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40789 const struct fw_card_driver *driver,
40790 struct device *device)
40791 {
40792 - static atomic_t index = ATOMIC_INIT(-1);
40793 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
40794
40795 - card->index = atomic_inc_return(&index);
40796 + card->index = atomic_inc_return_unchecked(&index);
40797 card->driver = driver;
40798 card->device = device;
40799 card->current_tlabel = 0;
40800 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40801
40802 void fw_core_remove_card(struct fw_card *card)
40803 {
40804 - struct fw_card_driver dummy_driver = dummy_driver_template;
40805 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
40806
40807 card->driver->update_phy_reg(card, 4,
40808 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40809 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40810 index 2c6d5e1..a2cca6b 100644
40811 --- a/drivers/firewire/core-device.c
40812 +++ b/drivers/firewire/core-device.c
40813 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40814 struct config_rom_attribute {
40815 struct device_attribute attr;
40816 u32 key;
40817 -};
40818 +} __do_const;
40819
40820 static ssize_t show_immediate(struct device *dev,
40821 struct device_attribute *dattr, char *buf)
40822 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40823 index eb6935c..3cc2bfa 100644
40824 --- a/drivers/firewire/core-transaction.c
40825 +++ b/drivers/firewire/core-transaction.c
40826 @@ -38,6 +38,7 @@
40827 #include <linux/timer.h>
40828 #include <linux/types.h>
40829 #include <linux/workqueue.h>
40830 +#include <linux/sched.h>
40831
40832 #include <asm/byteorder.h>
40833
40834 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40835 index e1480ff6..1a429bd 100644
40836 --- a/drivers/firewire/core.h
40837 +++ b/drivers/firewire/core.h
40838 @@ -111,6 +111,7 @@ struct fw_card_driver {
40839
40840 int (*stop_iso)(struct fw_iso_context *ctx);
40841 };
40842 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40843
40844 void fw_card_initialize(struct fw_card *card,
40845 const struct fw_card_driver *driver, struct device *device);
40846 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40847 index a66a321..f6caf20 100644
40848 --- a/drivers/firewire/ohci.c
40849 +++ b/drivers/firewire/ohci.c
40850 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40851 be32_to_cpu(ohci->next_header));
40852 }
40853
40854 +#ifndef CONFIG_GRKERNSEC
40855 if (param_remote_dma) {
40856 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40857 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40858 }
40859 +#endif
40860
40861 spin_unlock_irq(&ohci->lock);
40862
40863 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40864 unsigned long flags;
40865 int n, ret = 0;
40866
40867 +#ifndef CONFIG_GRKERNSEC
40868 if (param_remote_dma)
40869 return 0;
40870 +#endif
40871
40872 /*
40873 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40874 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40875 index 94a58a0..f5eba42 100644
40876 --- a/drivers/firmware/dmi-id.c
40877 +++ b/drivers/firmware/dmi-id.c
40878 @@ -16,7 +16,7 @@
40879 struct dmi_device_attribute{
40880 struct device_attribute dev_attr;
40881 int field;
40882 -};
40883 +} __do_const;
40884 #define to_dmi_dev_attr(_dev_attr) \
40885 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40886
40887 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40888 index 17afc51..0ef90cd 100644
40889 --- a/drivers/firmware/dmi_scan.c
40890 +++ b/drivers/firmware/dmi_scan.c
40891 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40892 if (buf == NULL)
40893 return -1;
40894
40895 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40896 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40897
40898 dmi_unmap(buf);
40899 return 0;
40900 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40901 index 5b53d61..72cee96 100644
40902 --- a/drivers/firmware/efi/cper.c
40903 +++ b/drivers/firmware/efi/cper.c
40904 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40905 */
40906 u64 cper_next_record_id(void)
40907 {
40908 - static atomic64_t seq;
40909 + static atomic64_unchecked_t seq;
40910
40911 - if (!atomic64_read(&seq))
40912 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40913 + if (!atomic64_read_unchecked(&seq))
40914 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40915
40916 - return atomic64_inc_return(&seq);
40917 + return atomic64_inc_return_unchecked(&seq);
40918 }
40919 EXPORT_SYMBOL_GPL(cper_next_record_id);
40920
40921 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40922 index 64ecbb5..d921eb3 100644
40923 --- a/drivers/firmware/efi/efi.c
40924 +++ b/drivers/firmware/efi/efi.c
40925 @@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
40926 };
40927
40928 static struct efivars generic_efivars;
40929 -static struct efivar_operations generic_ops;
40930 +static efivar_operations_no_const generic_ops __read_only;
40931
40932 static int generic_ops_register(void)
40933 {
40934 - generic_ops.get_variable = efi.get_variable;
40935 - generic_ops.set_variable = efi.set_variable;
40936 - generic_ops.get_next_variable = efi.get_next_variable;
40937 - generic_ops.query_variable_store = efi_query_variable_store;
40938 + pax_open_kernel();
40939 + *(void **)&generic_ops.get_variable = efi.get_variable;
40940 + *(void **)&generic_ops.set_variable = efi.set_variable;
40941 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40942 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40943 + pax_close_kernel();
40944
40945 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40946 }
40947 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40948 index f256ecd..387dcb1 100644
40949 --- a/drivers/firmware/efi/efivars.c
40950 +++ b/drivers/firmware/efi/efivars.c
40951 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40952 static int
40953 create_efivars_bin_attributes(void)
40954 {
40955 - struct bin_attribute *attr;
40956 + bin_attribute_no_const *attr;
40957 int error;
40958
40959 /* new_var */
40960 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40961 index 2f569aa..c95f4fb 100644
40962 --- a/drivers/firmware/google/memconsole.c
40963 +++ b/drivers/firmware/google/memconsole.c
40964 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40965 if (!found_memconsole())
40966 return -ENODEV;
40967
40968 - memconsole_bin_attr.size = memconsole_length;
40969 + pax_open_kernel();
40970 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40971 + pax_close_kernel();
40972 +
40973 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40974 }
40975
40976 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40977 index fe49ec3..1ade794 100644
40978 --- a/drivers/gpio/gpio-em.c
40979 +++ b/drivers/gpio/gpio-em.c
40980 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40981 struct em_gio_priv *p;
40982 struct resource *io[2], *irq[2];
40983 struct gpio_chip *gpio_chip;
40984 - struct irq_chip *irq_chip;
40985 + irq_chip_no_const *irq_chip;
40986 const char *name = dev_name(&pdev->dev);
40987 int ret;
40988
40989 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40990 index 3784e81..73637b5 100644
40991 --- a/drivers/gpio/gpio-ich.c
40992 +++ b/drivers/gpio/gpio-ich.c
40993 @@ -94,7 +94,7 @@ struct ichx_desc {
40994 * this option allows driver caching written output values
40995 */
40996 bool use_outlvl_cache;
40997 -};
40998 +} __do_const;
40999
41000 static struct {
41001 spinlock_t lock;
41002 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41003 index bf6c094..6573caf 100644
41004 --- a/drivers/gpio/gpio-rcar.c
41005 +++ b/drivers/gpio/gpio-rcar.c
41006 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41007 struct gpio_rcar_priv *p;
41008 struct resource *io, *irq;
41009 struct gpio_chip *gpio_chip;
41010 - struct irq_chip *irq_chip;
41011 + irq_chip_no_const *irq_chip;
41012 struct device *dev = &pdev->dev;
41013 const char *name = dev_name(dev);
41014 int ret;
41015 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41016 index dbf28fa..04dad4e 100644
41017 --- a/drivers/gpio/gpio-vr41xx.c
41018 +++ b/drivers/gpio/gpio-vr41xx.c
41019 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41020 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41021 maskl, pendl, maskh, pendh);
41022
41023 - atomic_inc(&irq_err_count);
41024 + atomic_inc_unchecked(&irq_err_count);
41025
41026 return -EINVAL;
41027 }
41028 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41029 index c68d037..2f4f9a9 100644
41030 --- a/drivers/gpio/gpiolib.c
41031 +++ b/drivers/gpio/gpiolib.c
41032 @@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41033 }
41034
41035 if (gpiochip->irqchip) {
41036 - gpiochip->irqchip->irq_request_resources = NULL;
41037 - gpiochip->irqchip->irq_release_resources = NULL;
41038 + pax_open_kernel();
41039 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41040 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41041 + pax_close_kernel();
41042 gpiochip->irqchip = NULL;
41043 }
41044 }
41045 @@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41046 gpiochip->irqchip = NULL;
41047 return -EINVAL;
41048 }
41049 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41050 - irqchip->irq_release_resources = gpiochip_irq_relres;
41051 +
41052 + pax_open_kernel();
41053 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41054 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41055 + pax_close_kernel();
41056
41057 /*
41058 * Prepare the mapping since the irqchip shall be orthogonal to
41059 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41060 index 90e7730..3b41807 100644
41061 --- a/drivers/gpu/drm/drm_crtc.c
41062 +++ b/drivers/gpu/drm/drm_crtc.c
41063 @@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41064 goto done;
41065 }
41066
41067 - if (copy_to_user(&enum_ptr[copied].name,
41068 + if (copy_to_user(enum_ptr[copied].name,
41069 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41070 ret = -EFAULT;
41071 goto done;
41072 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41073 index 3242e20..7e4f621 100644
41074 --- a/drivers/gpu/drm/drm_drv.c
41075 +++ b/drivers/gpu/drm/drm_drv.c
41076 @@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41077
41078 drm_device_set_unplugged(dev);
41079
41080 - if (dev->open_count == 0) {
41081 + if (local_read(&dev->open_count) == 0) {
41082 drm_put_dev(dev);
41083 }
41084 mutex_unlock(&drm_global_mutex);
41085 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41086 index 79d5221..7ff73496 100644
41087 --- a/drivers/gpu/drm/drm_fops.c
41088 +++ b/drivers/gpu/drm/drm_fops.c
41089 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41090 return PTR_ERR(minor);
41091
41092 dev = minor->dev;
41093 - if (!dev->open_count++)
41094 + if (local_inc_return(&dev->open_count) == 1)
41095 need_setup = 1;
41096
41097 /* share address_space across all char-devs of a single device */
41098 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41099 return 0;
41100
41101 err_undo:
41102 - dev->open_count--;
41103 + local_dec(&dev->open_count);
41104 drm_minor_release(minor);
41105 return retcode;
41106 }
41107 @@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41108
41109 mutex_lock(&drm_global_mutex);
41110
41111 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41112 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41113
41114 mutex_lock(&dev->struct_mutex);
41115 list_del(&file_priv->lhead);
41116 @@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41117 * Begin inline drm_release
41118 */
41119
41120 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41121 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41122 task_pid_nr(current),
41123 (long)old_encode_dev(file_priv->minor->kdev->devt),
41124 - dev->open_count);
41125 + local_read(&dev->open_count));
41126
41127 /* Release any auth tokens that might point to this file_priv,
41128 (do that under the drm_global_mutex) */
41129 @@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41130 * End inline drm_release
41131 */
41132
41133 - if (!--dev->open_count) {
41134 + if (local_dec_and_test(&dev->open_count)) {
41135 retcode = drm_lastclose(dev);
41136 if (drm_device_is_unplugged(dev))
41137 drm_put_dev(dev);
41138 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41139 index 3d2e91c..d31c4c9 100644
41140 --- a/drivers/gpu/drm/drm_global.c
41141 +++ b/drivers/gpu/drm/drm_global.c
41142 @@ -36,7 +36,7 @@
41143 struct drm_global_item {
41144 struct mutex mutex;
41145 void *object;
41146 - int refcount;
41147 + atomic_t refcount;
41148 };
41149
41150 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41151 @@ -49,7 +49,7 @@ void drm_global_init(void)
41152 struct drm_global_item *item = &glob[i];
41153 mutex_init(&item->mutex);
41154 item->object = NULL;
41155 - item->refcount = 0;
41156 + atomic_set(&item->refcount, 0);
41157 }
41158 }
41159
41160 @@ -59,7 +59,7 @@ void drm_global_release(void)
41161 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41162 struct drm_global_item *item = &glob[i];
41163 BUG_ON(item->object != NULL);
41164 - BUG_ON(item->refcount != 0);
41165 + BUG_ON(atomic_read(&item->refcount) != 0);
41166 }
41167 }
41168
41169 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41170 struct drm_global_item *item = &glob[ref->global_type];
41171
41172 mutex_lock(&item->mutex);
41173 - if (item->refcount == 0) {
41174 + if (atomic_read(&item->refcount) == 0) {
41175 item->object = kzalloc(ref->size, GFP_KERNEL);
41176 if (unlikely(item->object == NULL)) {
41177 ret = -ENOMEM;
41178 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41179 goto out_err;
41180
41181 }
41182 - ++item->refcount;
41183 + atomic_inc(&item->refcount);
41184 ref->object = item->object;
41185 mutex_unlock(&item->mutex);
41186 return 0;
41187 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41188 struct drm_global_item *item = &glob[ref->global_type];
41189
41190 mutex_lock(&item->mutex);
41191 - BUG_ON(item->refcount == 0);
41192 + BUG_ON(atomic_read(&item->refcount) == 0);
41193 BUG_ON(ref->object != item->object);
41194 - if (--item->refcount == 0) {
41195 + if (atomic_dec_and_test(&item->refcount)) {
41196 ref->release(ref);
41197 item->object = NULL;
41198 }
41199 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41200 index ecaf0fa..a49cee9 100644
41201 --- a/drivers/gpu/drm/drm_info.c
41202 +++ b/drivers/gpu/drm/drm_info.c
41203 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41204 struct drm_local_map *map;
41205 struct drm_map_list *r_list;
41206
41207 - /* Hardcoded from _DRM_FRAME_BUFFER,
41208 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41209 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41210 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41211 + static const char * const types[] = {
41212 + [_DRM_FRAME_BUFFER] = "FB",
41213 + [_DRM_REGISTERS] = "REG",
41214 + [_DRM_SHM] = "SHM",
41215 + [_DRM_AGP] = "AGP",
41216 + [_DRM_SCATTER_GATHER] = "SG",
41217 + [_DRM_CONSISTENT] = "PCI"};
41218 const char *type;
41219 int i;
41220
41221 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41222 map = r_list->map;
41223 if (!map)
41224 continue;
41225 - if (map->type < 0 || map->type > 5)
41226 + if (map->type >= ARRAY_SIZE(types))
41227 type = "??";
41228 else
41229 type = types[map->type];
41230 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41231 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41232 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41233 vma->vm_flags & VM_IO ? 'i' : '-',
41234 +#ifdef CONFIG_GRKERNSEC_HIDESYM
41235 + 0);
41236 +#else
41237 vma->vm_pgoff);
41238 +#endif
41239
41240 #if defined(__i386__)
41241 pgprot = pgprot_val(vma->vm_page_prot);
41242 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41243 index 2f4c4343..dd12cd2 100644
41244 --- a/drivers/gpu/drm/drm_ioc32.c
41245 +++ b/drivers/gpu/drm/drm_ioc32.c
41246 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41247 request = compat_alloc_user_space(nbytes);
41248 if (!access_ok(VERIFY_WRITE, request, nbytes))
41249 return -EFAULT;
41250 - list = (struct drm_buf_desc *) (request + 1);
41251 + list = (struct drm_buf_desc __user *) (request + 1);
41252
41253 if (__put_user(count, &request->count)
41254 || __put_user(list, &request->list))
41255 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41256 request = compat_alloc_user_space(nbytes);
41257 if (!access_ok(VERIFY_WRITE, request, nbytes))
41258 return -EFAULT;
41259 - list = (struct drm_buf_pub *) (request + 1);
41260 + list = (struct drm_buf_pub __user *) (request + 1);
41261
41262 if (__put_user(count, &request->count)
41263 || __put_user(list, &request->list))
41264 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41265 return 0;
41266 }
41267
41268 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
41269 +drm_ioctl_compat_t drm_compat_ioctls[] = {
41270 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41271 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41272 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41273 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41274 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41275 {
41276 unsigned int nr = DRM_IOCTL_NR(cmd);
41277 - drm_ioctl_compat_t *fn;
41278 int ret;
41279
41280 /* Assume that ioctls without an explicit compat routine will just
41281 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41282 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41283 return drm_ioctl(filp, cmd, arg);
41284
41285 - fn = drm_compat_ioctls[nr];
41286 -
41287 - if (fn != NULL)
41288 - ret = (*fn) (filp, cmd, arg);
41289 + if (drm_compat_ioctls[nr] != NULL)
41290 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41291 else
41292 ret = drm_ioctl(filp, cmd, arg);
41293
41294 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41295 index 40be746..fd78faf 100644
41296 --- a/drivers/gpu/drm/drm_ioctl.c
41297 +++ b/drivers/gpu/drm/drm_ioctl.c
41298 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41299 struct drm_file *file_priv = filp->private_data;
41300 struct drm_device *dev;
41301 const struct drm_ioctl_desc *ioctl = NULL;
41302 - drm_ioctl_t *func;
41303 + drm_ioctl_no_const_t func;
41304 unsigned int nr = DRM_IOCTL_NR(cmd);
41305 int retcode = -EINVAL;
41306 char stack_kdata[128];
41307 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41308 index d4d16ed..8fb0b51 100644
41309 --- a/drivers/gpu/drm/i810/i810_drv.h
41310 +++ b/drivers/gpu/drm/i810/i810_drv.h
41311 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41312 int page_flipping;
41313
41314 wait_queue_head_t irq_queue;
41315 - atomic_t irq_received;
41316 - atomic_t irq_emitted;
41317 + atomic_unchecked_t irq_received;
41318 + atomic_unchecked_t irq_emitted;
41319
41320 int front_offset;
41321 } drm_i810_private_t;
41322 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41323 index 9933c26..32cc097 100644
41324 --- a/drivers/gpu/drm/i915/i915_dma.c
41325 +++ b/drivers/gpu/drm/i915/i915_dma.c
41326 @@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41327 * locking inversion with the driver load path. And the access here is
41328 * completely racy anyway. So don't bother with locking for now.
41329 */
41330 - return dev->open_count == 0;
41331 + return local_read(&dev->open_count) == 0;
41332 }
41333
41334 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41335 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41336 index 60998fc..3b244bc 100644
41337 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41338 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41339 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41340
41341 static int
41342 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41343 - int count)
41344 + unsigned int count)
41345 {
41346 - int i;
41347 + unsigned int i;
41348 unsigned relocs_total = 0;
41349 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41350
41351 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41352 index 2e0613e..a8b94d9 100644
41353 --- a/drivers/gpu/drm/i915/i915_ioc32.c
41354 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
41355 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41356 (unsigned long)request);
41357 }
41358
41359 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41360 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
41361 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41362 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41363 [DRM_I915_GETPARAM] = compat_i915_getparam,
41364 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41365 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41366 {
41367 unsigned int nr = DRM_IOCTL_NR(cmd);
41368 - drm_ioctl_compat_t *fn = NULL;
41369 int ret;
41370
41371 if (nr < DRM_COMMAND_BASE)
41372 return drm_compat_ioctl(filp, cmd, arg);
41373
41374 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41375 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41376 -
41377 - if (fn != NULL)
41378 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41379 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41380 ret = (*fn) (filp, cmd, arg);
41381 - else
41382 + } else
41383 ret = drm_ioctl(filp, cmd, arg);
41384
41385 return ret;
41386 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41387 index b71a026..8b6cc10 100644
41388 --- a/drivers/gpu/drm/i915/intel_display.c
41389 +++ b/drivers/gpu/drm/i915/intel_display.c
41390 @@ -12437,13 +12437,13 @@ struct intel_quirk {
41391 int subsystem_vendor;
41392 int subsystem_device;
41393 void (*hook)(struct drm_device *dev);
41394 -};
41395 +} __do_const;
41396
41397 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41398 struct intel_dmi_quirk {
41399 void (*hook)(struct drm_device *dev);
41400 const struct dmi_system_id (*dmi_id_list)[];
41401 -};
41402 +} __do_const;
41403
41404 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41405 {
41406 @@ -12451,18 +12451,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41407 return 1;
41408 }
41409
41410 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41411 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
41412 {
41413 - .dmi_id_list = &(const struct dmi_system_id[]) {
41414 - {
41415 - .callback = intel_dmi_reverse_brightness,
41416 - .ident = "NCR Corporation",
41417 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41418 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
41419 - },
41420 - },
41421 - { } /* terminating entry */
41422 + .callback = intel_dmi_reverse_brightness,
41423 + .ident = "NCR Corporation",
41424 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41425 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
41426 },
41427 + },
41428 + { } /* terminating entry */
41429 +};
41430 +
41431 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41432 + {
41433 + .dmi_id_list = &intel_dmi_quirks_table,
41434 .hook = quirk_invert_brightness,
41435 },
41436 };
41437 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41438 index fe45321..836fdca 100644
41439 --- a/drivers/gpu/drm/mga/mga_drv.h
41440 +++ b/drivers/gpu/drm/mga/mga_drv.h
41441 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41442 u32 clear_cmd;
41443 u32 maccess;
41444
41445 - atomic_t vbl_received; /**< Number of vblanks received. */
41446 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41447 wait_queue_head_t fence_queue;
41448 - atomic_t last_fence_retired;
41449 + atomic_unchecked_t last_fence_retired;
41450 u32 next_fence_to_post;
41451
41452 unsigned int fb_cpp;
41453 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41454 index 729bfd5..ead8823 100644
41455 --- a/drivers/gpu/drm/mga/mga_ioc32.c
41456 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
41457 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41458 return 0;
41459 }
41460
41461 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
41462 +drm_ioctl_compat_t mga_compat_ioctls[] = {
41463 [DRM_MGA_INIT] = compat_mga_init,
41464 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41465 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41466 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41467 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41468 {
41469 unsigned int nr = DRM_IOCTL_NR(cmd);
41470 - drm_ioctl_compat_t *fn = NULL;
41471 int ret;
41472
41473 if (nr < DRM_COMMAND_BASE)
41474 return drm_compat_ioctl(filp, cmd, arg);
41475
41476 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41477 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41478 -
41479 - if (fn != NULL)
41480 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41481 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41482 ret = (*fn) (filp, cmd, arg);
41483 - else
41484 + } else
41485 ret = drm_ioctl(filp, cmd, arg);
41486
41487 return ret;
41488 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41489 index 1b071b8..de8601a 100644
41490 --- a/drivers/gpu/drm/mga/mga_irq.c
41491 +++ b/drivers/gpu/drm/mga/mga_irq.c
41492 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41493 if (crtc != 0)
41494 return 0;
41495
41496 - return atomic_read(&dev_priv->vbl_received);
41497 + return atomic_read_unchecked(&dev_priv->vbl_received);
41498 }
41499
41500
41501 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41502 /* VBLANK interrupt */
41503 if (status & MGA_VLINEPEN) {
41504 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41505 - atomic_inc(&dev_priv->vbl_received);
41506 + atomic_inc_unchecked(&dev_priv->vbl_received);
41507 drm_handle_vblank(dev, 0);
41508 handled = 1;
41509 }
41510 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41511 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41512 MGA_WRITE(MGA_PRIMEND, prim_end);
41513
41514 - atomic_inc(&dev_priv->last_fence_retired);
41515 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
41516 wake_up(&dev_priv->fence_queue);
41517 handled = 1;
41518 }
41519 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41520 * using fences.
41521 */
41522 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41523 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41524 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41525 - *sequence) <= (1 << 23)));
41526
41527 *sequence = cur_fence;
41528 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41529 index dae2c96..324dbe4 100644
41530 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41531 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41532 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41533 struct bit_table {
41534 const char id;
41535 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41536 -};
41537 +} __no_const;
41538
41539 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41540
41541 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41542 index b02b024..aed7bad 100644
41543 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41544 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41545 @@ -119,7 +119,6 @@ struct nouveau_drm {
41546 struct drm_global_reference mem_global_ref;
41547 struct ttm_bo_global_ref bo_global_ref;
41548 struct ttm_bo_device bdev;
41549 - atomic_t validate_sequence;
41550 int (*move)(struct nouveau_channel *,
41551 struct ttm_buffer_object *,
41552 struct ttm_mem_reg *, struct ttm_mem_reg *);
41553 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41554 index 462679a..88e32a7 100644
41555 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41556 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41557 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41558 unsigned long arg)
41559 {
41560 unsigned int nr = DRM_IOCTL_NR(cmd);
41561 - drm_ioctl_compat_t *fn = NULL;
41562 + drm_ioctl_compat_t fn = NULL;
41563 int ret;
41564
41565 if (nr < DRM_COMMAND_BASE)
41566 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41567 index 53874b7..1db0a68 100644
41568 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41569 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41570 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41571 }
41572
41573 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41574 - nouveau_vram_manager_init,
41575 - nouveau_vram_manager_fini,
41576 - nouveau_vram_manager_new,
41577 - nouveau_vram_manager_del,
41578 - nouveau_vram_manager_debug
41579 + .init = nouveau_vram_manager_init,
41580 + .takedown = nouveau_vram_manager_fini,
41581 + .get_node = nouveau_vram_manager_new,
41582 + .put_node = nouveau_vram_manager_del,
41583 + .debug = nouveau_vram_manager_debug
41584 };
41585
41586 static int
41587 @@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41588 }
41589
41590 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41591 - nouveau_gart_manager_init,
41592 - nouveau_gart_manager_fini,
41593 - nouveau_gart_manager_new,
41594 - nouveau_gart_manager_del,
41595 - nouveau_gart_manager_debug
41596 + .init = nouveau_gart_manager_init,
41597 + .takedown = nouveau_gart_manager_fini,
41598 + .get_node = nouveau_gart_manager_new,
41599 + .put_node = nouveau_gart_manager_del,
41600 + .debug = nouveau_gart_manager_debug
41601 };
41602
41603 /*XXX*/
41604 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41605 }
41606
41607 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41608 - nv04_gart_manager_init,
41609 - nv04_gart_manager_fini,
41610 - nv04_gart_manager_new,
41611 - nv04_gart_manager_del,
41612 - nv04_gart_manager_debug
41613 + .init = nv04_gart_manager_init,
41614 + .takedown = nv04_gart_manager_fini,
41615 + .get_node = nv04_gart_manager_new,
41616 + .put_node = nv04_gart_manager_del,
41617 + .debug = nv04_gart_manager_debug
41618 };
41619
41620 int
41621 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41622 index c7592ec..dd45ebc 100644
41623 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41624 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41625 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41626 * locking inversion with the driver load path. And the access here is
41627 * completely racy anyway. So don't bother with locking for now.
41628 */
41629 - return dev->open_count == 0;
41630 + return local_read(&dev->open_count) == 0;
41631 }
41632
41633 static const struct vga_switcheroo_client_ops
41634 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41635 index eb89653..613cf71 100644
41636 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
41637 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41638 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41639 int ret;
41640
41641 mutex_lock(&qdev->async_io_mutex);
41642 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41643 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41644 if (qdev->last_sent_io_cmd > irq_num) {
41645 if (intr)
41646 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41647 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41648 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41649 else
41650 ret = wait_event_timeout(qdev->io_cmd_event,
41651 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41652 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41653 /* 0 is timeout, just bail the "hw" has gone away */
41654 if (ret <= 0)
41655 goto out;
41656 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41657 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41658 }
41659 outb(val, addr);
41660 qdev->last_sent_io_cmd = irq_num + 1;
41661 if (intr)
41662 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41663 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41664 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41665 else
41666 ret = wait_event_timeout(qdev->io_cmd_event,
41667 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41668 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41669 out:
41670 if (ret > 0)
41671 ret = 0;
41672 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41673 index c3c2bbd..bc3c0fb 100644
41674 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41675 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41676 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41677 struct drm_info_node *node = (struct drm_info_node *) m->private;
41678 struct qxl_device *qdev = node->minor->dev->dev_private;
41679
41680 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41681 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41682 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41683 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41684 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41685 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41686 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41687 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41688 seq_printf(m, "%d\n", qdev->irq_received_error);
41689 return 0;
41690 }
41691 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41692 index 36ed40b..0397633 100644
41693 --- a/drivers/gpu/drm/qxl/qxl_drv.h
41694 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
41695 @@ -290,10 +290,10 @@ struct qxl_device {
41696 unsigned int last_sent_io_cmd;
41697
41698 /* interrupt handling */
41699 - atomic_t irq_received;
41700 - atomic_t irq_received_display;
41701 - atomic_t irq_received_cursor;
41702 - atomic_t irq_received_io_cmd;
41703 + atomic_unchecked_t irq_received;
41704 + atomic_unchecked_t irq_received_display;
41705 + atomic_unchecked_t irq_received_cursor;
41706 + atomic_unchecked_t irq_received_io_cmd;
41707 unsigned irq_received_error;
41708 wait_queue_head_t display_event;
41709 wait_queue_head_t cursor_event;
41710 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41711 index b110883..dd06418 100644
41712 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41713 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41714 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41715
41716 /* TODO copy slow path code from i915 */
41717 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41718 - unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
41719 + unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
41720
41721 {
41722 struct qxl_drawable *draw = fb_cmd;
41723 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41724 struct drm_qxl_reloc reloc;
41725
41726 if (copy_from_user(&reloc,
41727 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41728 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41729 sizeof(reloc))) {
41730 ret = -EFAULT;
41731 goto out_free_bos;
41732 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41733
41734 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41735
41736 - struct drm_qxl_command *commands =
41737 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41738 + struct drm_qxl_command __user *commands =
41739 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41740
41741 - if (copy_from_user(&user_cmd, &commands[cmd_num],
41742 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41743 sizeof(user_cmd)))
41744 return -EFAULT;
41745
41746 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41747 index 0bf1e20..42a7310 100644
41748 --- a/drivers/gpu/drm/qxl/qxl_irq.c
41749 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
41750 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41751 if (!pending)
41752 return IRQ_NONE;
41753
41754 - atomic_inc(&qdev->irq_received);
41755 + atomic_inc_unchecked(&qdev->irq_received);
41756
41757 if (pending & QXL_INTERRUPT_DISPLAY) {
41758 - atomic_inc(&qdev->irq_received_display);
41759 + atomic_inc_unchecked(&qdev->irq_received_display);
41760 wake_up_all(&qdev->display_event);
41761 qxl_queue_garbage_collect(qdev, false);
41762 }
41763 if (pending & QXL_INTERRUPT_CURSOR) {
41764 - atomic_inc(&qdev->irq_received_cursor);
41765 + atomic_inc_unchecked(&qdev->irq_received_cursor);
41766 wake_up_all(&qdev->cursor_event);
41767 }
41768 if (pending & QXL_INTERRUPT_IO_CMD) {
41769 - atomic_inc(&qdev->irq_received_io_cmd);
41770 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41771 wake_up_all(&qdev->io_cmd_event);
41772 }
41773 if (pending & QXL_INTERRUPT_ERROR) {
41774 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41775 init_waitqueue_head(&qdev->io_cmd_event);
41776 INIT_WORK(&qdev->client_monitors_config_work,
41777 qxl_client_monitors_config_work_func);
41778 - atomic_set(&qdev->irq_received, 0);
41779 - atomic_set(&qdev->irq_received_display, 0);
41780 - atomic_set(&qdev->irq_received_cursor, 0);
41781 - atomic_set(&qdev->irq_received_io_cmd, 0);
41782 + atomic_set_unchecked(&qdev->irq_received, 0);
41783 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41784 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41785 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41786 qdev->irq_received_error = 0;
41787 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41788 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41789 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41790 index 71a1bae..cb1f103 100644
41791 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41792 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41793 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41794 }
41795 }
41796
41797 -static struct vm_operations_struct qxl_ttm_vm_ops;
41798 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41799 static const struct vm_operations_struct *ttm_vm_ops;
41800
41801 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41802 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41803 return r;
41804 if (unlikely(ttm_vm_ops == NULL)) {
41805 ttm_vm_ops = vma->vm_ops;
41806 + pax_open_kernel();
41807 qxl_ttm_vm_ops = *ttm_vm_ops;
41808 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41809 + pax_close_kernel();
41810 }
41811 vma->vm_ops = &qxl_ttm_vm_ops;
41812 return 0;
41813 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41814 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41815 {
41816 #if defined(CONFIG_DEBUG_FS)
41817 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41818 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41819 - unsigned i;
41820 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41821 + {
41822 + .name = "qxl_mem_mm",
41823 + .show = &qxl_mm_dump_table,
41824 + },
41825 + {
41826 + .name = "qxl_surf_mm",
41827 + .show = &qxl_mm_dump_table,
41828 + }
41829 + };
41830
41831 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41832 - if (i == 0)
41833 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41834 - else
41835 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41836 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41837 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41838 - qxl_mem_types_list[i].driver_features = 0;
41839 - if (i == 0)
41840 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41841 - else
41842 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41843 + pax_open_kernel();
41844 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41845 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41846 + pax_close_kernel();
41847
41848 - }
41849 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41850 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41851 #else
41852 return 0;
41853 #endif
41854 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41855 index 59459fe..be26b31 100644
41856 --- a/drivers/gpu/drm/r128/r128_cce.c
41857 +++ b/drivers/gpu/drm/r128/r128_cce.c
41858 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41859
41860 /* GH: Simple idle check.
41861 */
41862 - atomic_set(&dev_priv->idle_count, 0);
41863 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41864
41865 /* We don't support anything other than bus-mastering ring mode,
41866 * but the ring can be in either AGP or PCI space for the ring
41867 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41868 index 5bf3f5f..7000661 100644
41869 --- a/drivers/gpu/drm/r128/r128_drv.h
41870 +++ b/drivers/gpu/drm/r128/r128_drv.h
41871 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41872 int is_pci;
41873 unsigned long cce_buffers_offset;
41874
41875 - atomic_t idle_count;
41876 + atomic_unchecked_t idle_count;
41877
41878 int page_flipping;
41879 int current_page;
41880 u32 crtc_offset;
41881 u32 crtc_offset_cntl;
41882
41883 - atomic_t vbl_received;
41884 + atomic_unchecked_t vbl_received;
41885
41886 u32 color_fmt;
41887 unsigned int front_offset;
41888 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41889 index 663f38c..c689495 100644
41890 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41891 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41892 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41893 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41894 }
41895
41896 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41897 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41898 [DRM_R128_INIT] = compat_r128_init,
41899 [DRM_R128_DEPTH] = compat_r128_depth,
41900 [DRM_R128_STIPPLE] = compat_r128_stipple,
41901 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41902 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41903 {
41904 unsigned int nr = DRM_IOCTL_NR(cmd);
41905 - drm_ioctl_compat_t *fn = NULL;
41906 int ret;
41907
41908 if (nr < DRM_COMMAND_BASE)
41909 return drm_compat_ioctl(filp, cmd, arg);
41910
41911 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41912 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41913 -
41914 - if (fn != NULL)
41915 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41916 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41917 ret = (*fn) (filp, cmd, arg);
41918 - else
41919 + } else
41920 ret = drm_ioctl(filp, cmd, arg);
41921
41922 return ret;
41923 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41924 index c2ae496..30b5993 100644
41925 --- a/drivers/gpu/drm/r128/r128_irq.c
41926 +++ b/drivers/gpu/drm/r128/r128_irq.c
41927 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41928 if (crtc != 0)
41929 return 0;
41930
41931 - return atomic_read(&dev_priv->vbl_received);
41932 + return atomic_read_unchecked(&dev_priv->vbl_received);
41933 }
41934
41935 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41936 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41937 /* VBLANK interrupt */
41938 if (status & R128_CRTC_VBLANK_INT) {
41939 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41940 - atomic_inc(&dev_priv->vbl_received);
41941 + atomic_inc_unchecked(&dev_priv->vbl_received);
41942 drm_handle_vblank(dev, 0);
41943 return IRQ_HANDLED;
41944 }
41945 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41946 index 575e986..66e62ca 100644
41947 --- a/drivers/gpu/drm/r128/r128_state.c
41948 +++ b/drivers/gpu/drm/r128/r128_state.c
41949 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41950
41951 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41952 {
41953 - if (atomic_read(&dev_priv->idle_count) == 0)
41954 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41955 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41956 else
41957 - atomic_set(&dev_priv->idle_count, 0);
41958 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41959 }
41960
41961 #endif
41962 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41963 index 4a85bb6..aaea819 100644
41964 --- a/drivers/gpu/drm/radeon/mkregtable.c
41965 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41966 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41967 regex_t mask_rex;
41968 regmatch_t match[4];
41969 char buf[1024];
41970 - size_t end;
41971 + long end;
41972 int len;
41973 int done = 0;
41974 int r;
41975 unsigned o;
41976 struct offset *offset;
41977 char last_reg_s[10];
41978 - int last_reg;
41979 + unsigned long last_reg;
41980
41981 if (regcomp
41982 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41983 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41984 index 5d4416f..80b7fc4 100644
41985 --- a/drivers/gpu/drm/radeon/radeon_device.c
41986 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41987 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41988 * locking inversion with the driver load path. And the access here is
41989 * completely racy anyway. So don't bother with locking for now.
41990 */
41991 - return dev->open_count == 0;
41992 + return local_read(&dev->open_count) == 0;
41993 }
41994
41995 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41996 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41997 index dafd812..1bf20c7 100644
41998 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41999 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42000 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42001
42002 /* SW interrupt */
42003 wait_queue_head_t swi_queue;
42004 - atomic_t swi_emitted;
42005 + atomic_unchecked_t swi_emitted;
42006 int vblank_crtc;
42007 uint32_t irq_enable_reg;
42008 uint32_t r500_disp_irq_reg;
42009 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42010 index 0b98ea1..0881827 100644
42011 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42012 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42013 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42014 request = compat_alloc_user_space(sizeof(*request));
42015 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42016 || __put_user(req32.param, &request->param)
42017 - || __put_user((void __user *)(unsigned long)req32.value,
42018 + || __put_user((unsigned long)req32.value,
42019 &request->value))
42020 return -EFAULT;
42021
42022 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42023 #define compat_radeon_cp_setparam NULL
42024 #endif /* X86_64 || IA64 */
42025
42026 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42027 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42028 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42029 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42030 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42031 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42032 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42033 {
42034 unsigned int nr = DRM_IOCTL_NR(cmd);
42035 - drm_ioctl_compat_t *fn = NULL;
42036 int ret;
42037
42038 if (nr < DRM_COMMAND_BASE)
42039 return drm_compat_ioctl(filp, cmd, arg);
42040
42041 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42042 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42043 -
42044 - if (fn != NULL)
42045 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42046 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42047 ret = (*fn) (filp, cmd, arg);
42048 - else
42049 + } else
42050 ret = drm_ioctl(filp, cmd, arg);
42051
42052 return ret;
42053 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42054 index 244b19b..c19226d 100644
42055 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42056 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42057 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42058 unsigned int ret;
42059 RING_LOCALS;
42060
42061 - atomic_inc(&dev_priv->swi_emitted);
42062 - ret = atomic_read(&dev_priv->swi_emitted);
42063 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42064 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42065
42066 BEGIN_RING(4);
42067 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42068 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42069 drm_radeon_private_t *dev_priv =
42070 (drm_radeon_private_t *) dev->dev_private;
42071
42072 - atomic_set(&dev_priv->swi_emitted, 0);
42073 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42074 init_waitqueue_head(&dev_priv->swi_queue);
42075
42076 dev->max_vblank_count = 0x001fffff;
42077 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42078 index 23bb64f..69d7234 100644
42079 --- a/drivers/gpu/drm/radeon/radeon_state.c
42080 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42081 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42082 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42083 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42084
42085 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42086 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42087 sarea_priv->nbox * sizeof(depth_boxes[0])))
42088 return -EFAULT;
42089
42090 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42091 {
42092 drm_radeon_private_t *dev_priv = dev->dev_private;
42093 drm_radeon_getparam_t *param = data;
42094 - int value;
42095 + int value = 0;
42096
42097 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42098
42099 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42100 index 72afe82..056a57a 100644
42101 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42102 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42103 @@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42104 man->size = size >> PAGE_SHIFT;
42105 }
42106
42107 -static struct vm_operations_struct radeon_ttm_vm_ops;
42108 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42109 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42110
42111 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42112 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42113 }
42114 if (unlikely(ttm_vm_ops == NULL)) {
42115 ttm_vm_ops = vma->vm_ops;
42116 + pax_open_kernel();
42117 radeon_ttm_vm_ops = *ttm_vm_ops;
42118 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42119 + pax_close_kernel();
42120 }
42121 vma->vm_ops = &radeon_ttm_vm_ops;
42122 return 0;
42123 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42124 index 6553fd2..aecd29c 100644
42125 --- a/drivers/gpu/drm/tegra/dc.c
42126 +++ b/drivers/gpu/drm/tegra/dc.c
42127 @@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42128 }
42129
42130 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42131 - dc->debugfs_files[i].data = dc;
42132 + *(void **)&dc->debugfs_files[i].data = dc;
42133
42134 err = drm_debugfs_create_files(dc->debugfs_files,
42135 ARRAY_SIZE(debugfs_files),
42136 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42137 index f787445..2df2c65 100644
42138 --- a/drivers/gpu/drm/tegra/dsi.c
42139 +++ b/drivers/gpu/drm/tegra/dsi.c
42140 @@ -41,7 +41,7 @@ struct tegra_dsi {
42141 struct clk *clk_lp;
42142 struct clk *clk;
42143
42144 - struct drm_info_list *debugfs_files;
42145 + drm_info_list_no_const *debugfs_files;
42146 struct drm_minor *minor;
42147 struct dentry *debugfs;
42148
42149 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42150 index ffe2654..03c7b1c 100644
42151 --- a/drivers/gpu/drm/tegra/hdmi.c
42152 +++ b/drivers/gpu/drm/tegra/hdmi.c
42153 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42154 bool stereo;
42155 bool dvi;
42156
42157 - struct drm_info_list *debugfs_files;
42158 + drm_info_list_no_const *debugfs_files;
42159 struct drm_minor *minor;
42160 struct dentry *debugfs;
42161 };
42162 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42163 index 9e103a48..0e117f3 100644
42164 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42165 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42166 @@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42167 }
42168
42169 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42170 - ttm_bo_man_init,
42171 - ttm_bo_man_takedown,
42172 - ttm_bo_man_get_node,
42173 - ttm_bo_man_put_node,
42174 - ttm_bo_man_debug
42175 + .init = ttm_bo_man_init,
42176 + .takedown = ttm_bo_man_takedown,
42177 + .get_node = ttm_bo_man_get_node,
42178 + .put_node = ttm_bo_man_put_node,
42179 + .debug = ttm_bo_man_debug
42180 };
42181 EXPORT_SYMBOL(ttm_bo_manager_func);
42182 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42183 index dbc2def..0a9f710 100644
42184 --- a/drivers/gpu/drm/ttm/ttm_memory.c
42185 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
42186 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42187 zone->glob = glob;
42188 glob->zone_kernel = zone;
42189 ret = kobject_init_and_add(
42190 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42191 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42192 if (unlikely(ret != 0)) {
42193 kobject_put(&zone->kobj);
42194 return ret;
42195 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42196 zone->glob = glob;
42197 glob->zone_dma32 = zone;
42198 ret = kobject_init_and_add(
42199 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42200 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42201 if (unlikely(ret != 0)) {
42202 kobject_put(&zone->kobj);
42203 return ret;
42204 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42205 index d1da339..829235e 100644
42206 --- a/drivers/gpu/drm/udl/udl_fb.c
42207 +++ b/drivers/gpu/drm/udl/udl_fb.c
42208 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42209 fb_deferred_io_cleanup(info);
42210 kfree(info->fbdefio);
42211 info->fbdefio = NULL;
42212 - info->fbops->fb_mmap = udl_fb_mmap;
42213 }
42214
42215 pr_warn("released /dev/fb%d user=%d count=%d\n",
42216 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42217 index ad02732..144f5ed 100644
42218 --- a/drivers/gpu/drm/via/via_drv.h
42219 +++ b/drivers/gpu/drm/via/via_drv.h
42220 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42221 typedef uint32_t maskarray_t[5];
42222
42223 typedef struct drm_via_irq {
42224 - atomic_t irq_received;
42225 + atomic_unchecked_t irq_received;
42226 uint32_t pending_mask;
42227 uint32_t enable_mask;
42228 wait_queue_head_t irq_queue;
42229 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
42230 struct timeval last_vblank;
42231 int last_vblank_valid;
42232 unsigned usec_per_vblank;
42233 - atomic_t vbl_received;
42234 + atomic_unchecked_t vbl_received;
42235 drm_via_state_t hc_state;
42236 char pci_buf[VIA_PCI_BUF_SIZE];
42237 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42238 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42239 index 1319433..a993b0c 100644
42240 --- a/drivers/gpu/drm/via/via_irq.c
42241 +++ b/drivers/gpu/drm/via/via_irq.c
42242 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42243 if (crtc != 0)
42244 return 0;
42245
42246 - return atomic_read(&dev_priv->vbl_received);
42247 + return atomic_read_unchecked(&dev_priv->vbl_received);
42248 }
42249
42250 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42251 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42252
42253 status = VIA_READ(VIA_REG_INTERRUPT);
42254 if (status & VIA_IRQ_VBLANK_PENDING) {
42255 - atomic_inc(&dev_priv->vbl_received);
42256 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42257 + atomic_inc_unchecked(&dev_priv->vbl_received);
42258 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42259 do_gettimeofday(&cur_vblank);
42260 if (dev_priv->last_vblank_valid) {
42261 dev_priv->usec_per_vblank =
42262 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42263 dev_priv->last_vblank = cur_vblank;
42264 dev_priv->last_vblank_valid = 1;
42265 }
42266 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42267 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42268 DRM_DEBUG("US per vblank is: %u\n",
42269 dev_priv->usec_per_vblank);
42270 }
42271 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42272
42273 for (i = 0; i < dev_priv->num_irqs; ++i) {
42274 if (status & cur_irq->pending_mask) {
42275 - atomic_inc(&cur_irq->irq_received);
42276 + atomic_inc_unchecked(&cur_irq->irq_received);
42277 wake_up(&cur_irq->irq_queue);
42278 handled = 1;
42279 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42280 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42281 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42282 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42283 masks[irq][4]));
42284 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42285 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42286 } else {
42287 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42288 (((cur_irq_sequence =
42289 - atomic_read(&cur_irq->irq_received)) -
42290 + atomic_read_unchecked(&cur_irq->irq_received)) -
42291 *sequence) <= (1 << 23)));
42292 }
42293 *sequence = cur_irq_sequence;
42294 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42295 }
42296
42297 for (i = 0; i < dev_priv->num_irqs; ++i) {
42298 - atomic_set(&cur_irq->irq_received, 0);
42299 + atomic_set_unchecked(&cur_irq->irq_received, 0);
42300 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42301 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42302 init_waitqueue_head(&cur_irq->irq_queue);
42303 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42304 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42305 case VIA_IRQ_RELATIVE:
42306 irqwait->request.sequence +=
42307 - atomic_read(&cur_irq->irq_received);
42308 + atomic_read_unchecked(&cur_irq->irq_received);
42309 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42310 case VIA_IRQ_ABSOLUTE:
42311 break;
42312 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42313 index 99f7317..33a835b 100644
42314 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42315 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42316 @@ -447,7 +447,7 @@ struct vmw_private {
42317 * Fencing and IRQs.
42318 */
42319
42320 - atomic_t marker_seq;
42321 + atomic_unchecked_t marker_seq;
42322 wait_queue_head_t fence_queue;
42323 wait_queue_head_t fifo_queue;
42324 int fence_queue_waiters; /* Protected by hw_mutex */
42325 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42326 index 6eae14d..aa311b3 100644
42327 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42328 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42329 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42330 (unsigned int) min,
42331 (unsigned int) fifo->capabilities);
42332
42333 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42334 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42335 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42336 vmw_marker_queue_init(&fifo->marker_queue);
42337 return vmw_fifo_send_fence(dev_priv, &dummy);
42338 @@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42339 if (reserveable)
42340 iowrite32(bytes, fifo_mem +
42341 SVGA_FIFO_RESERVED);
42342 - return fifo_mem + (next_cmd >> 2);
42343 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42344 } else {
42345 need_bounce = true;
42346 }
42347 @@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42348
42349 fm = vmw_fifo_reserve(dev_priv, bytes);
42350 if (unlikely(fm == NULL)) {
42351 - *seqno = atomic_read(&dev_priv->marker_seq);
42352 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42353 ret = -ENOMEM;
42354 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42355 false, 3*HZ);
42356 @@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42357 }
42358
42359 do {
42360 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42361 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42362 } while (*seqno == 0);
42363
42364 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42365 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42366 index 26f8bdd..90a0008 100644
42367 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42368 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42369 @@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42370 }
42371
42372 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42373 - vmw_gmrid_man_init,
42374 - vmw_gmrid_man_takedown,
42375 - vmw_gmrid_man_get_node,
42376 - vmw_gmrid_man_put_node,
42377 - vmw_gmrid_man_debug
42378 + .init = vmw_gmrid_man_init,
42379 + .takedown = vmw_gmrid_man_takedown,
42380 + .get_node = vmw_gmrid_man_get_node,
42381 + .put_node = vmw_gmrid_man_put_node,
42382 + .debug = vmw_gmrid_man_debug
42383 };
42384 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42385 index 37881ec..319065d 100644
42386 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42387 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42388 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42389 int ret;
42390
42391 num_clips = arg->num_clips;
42392 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42393 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42394
42395 if (unlikely(num_clips == 0))
42396 return 0;
42397 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42398 int ret;
42399
42400 num_clips = arg->num_clips;
42401 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42402 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42403
42404 if (unlikely(num_clips == 0))
42405 return 0;
42406 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42407 index 0c42376..6febe77 100644
42408 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42409 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42410 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42411 * emitted. Then the fence is stale and signaled.
42412 */
42413
42414 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42415 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42416 > VMW_FENCE_WRAP);
42417
42418 return ret;
42419 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42420
42421 if (fifo_idle)
42422 down_read(&fifo_state->rwsem);
42423 - signal_seq = atomic_read(&dev_priv->marker_seq);
42424 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42425 ret = 0;
42426
42427 for (;;) {
42428 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42429 index efd1ffd..0ae13ca 100644
42430 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42431 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42432 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42433 while (!vmw_lag_lt(queue, us)) {
42434 spin_lock(&queue->lock);
42435 if (list_empty(&queue->head))
42436 - seqno = atomic_read(&dev_priv->marker_seq);
42437 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42438 else {
42439 marker = list_first_entry(&queue->head,
42440 struct vmw_marker, head);
42441 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42442 index 37ac7b5..d52a5c9 100644
42443 --- a/drivers/gpu/vga/vga_switcheroo.c
42444 +++ b/drivers/gpu/vga/vga_switcheroo.c
42445 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42446
42447 /* this version is for the case where the power switch is separate
42448 to the device being powered down. */
42449 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42450 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42451 {
42452 /* copy over all the bus versions */
42453 if (dev->bus && dev->bus->pm) {
42454 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42455 return ret;
42456 }
42457
42458 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42459 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42460 {
42461 /* copy over all the bus versions */
42462 if (dev->bus && dev->bus->pm) {
42463 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42464 index 12b6e67..ddd983c 100644
42465 --- a/drivers/hid/hid-core.c
42466 +++ b/drivers/hid/hid-core.c
42467 @@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42468
42469 int hid_add_device(struct hid_device *hdev)
42470 {
42471 - static atomic_t id = ATOMIC_INIT(0);
42472 + static atomic_unchecked_t id = ATOMIC_INIT(0);
42473 int ret;
42474
42475 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42476 @@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42477 /* XXX hack, any other cleaner solution after the driver core
42478 * is converted to allow more than 20 bytes as the device name? */
42479 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42480 - hdev->vendor, hdev->product, atomic_inc_return(&id));
42481 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42482
42483 hid_debug_register(hdev, dev_name(&hdev->dev));
42484 ret = device_add(&hdev->dev);
42485 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42486 index 9bf8637..f462416 100644
42487 --- a/drivers/hid/hid-logitech-dj.c
42488 +++ b/drivers/hid/hid-logitech-dj.c
42489 @@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42490 * device (via hid_input_report() ) and return 1 so hid-core does not do
42491 * anything else with it.
42492 */
42493 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42494 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42495 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42496 + __func__, dj_report->device_index);
42497 + return false;
42498 + }
42499
42500 /* case 1) */
42501 if (data[0] != REPORT_ID_DJ_SHORT)
42502 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42503 index c13fb5b..55a3802 100644
42504 --- a/drivers/hid/hid-wiimote-debug.c
42505 +++ b/drivers/hid/hid-wiimote-debug.c
42506 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42507 else if (size == 0)
42508 return -EIO;
42509
42510 - if (copy_to_user(u, buf, size))
42511 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42512 return -EFAULT;
42513
42514 *off += size;
42515 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
42516 index 0cb92e3..c7d453d 100644
42517 --- a/drivers/hid/uhid.c
42518 +++ b/drivers/hid/uhid.c
42519 @@ -47,7 +47,7 @@ struct uhid_device {
42520 struct mutex report_lock;
42521 wait_queue_head_t report_wait;
42522 atomic_t report_done;
42523 - atomic_t report_id;
42524 + atomic_unchecked_t report_id;
42525 struct uhid_event report_buf;
42526 };
42527
42528 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42529
42530 spin_lock_irqsave(&uhid->qlock, flags);
42531 ev->type = UHID_FEATURE;
42532 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42533 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42534 ev->u.feature.rnum = rnum;
42535 ev->u.feature.rtype = report_type;
42536
42537 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42538 spin_lock_irqsave(&uhid->qlock, flags);
42539
42540 /* id for old report; drop it silently */
42541 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42542 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42543 goto unlock;
42544 if (atomic_read(&uhid->report_done))
42545 goto unlock;
42546 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42547 index 19bad59..ca24eaf 100644
42548 --- a/drivers/hv/channel.c
42549 +++ b/drivers/hv/channel.c
42550 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42551 unsigned long flags;
42552 int ret = 0;
42553
42554 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42555 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42556 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42557 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42558
42559 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42560 if (ret)
42561 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42562 index 3e4235c..877d0e5 100644
42563 --- a/drivers/hv/hv.c
42564 +++ b/drivers/hv/hv.c
42565 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42566 u64 output_address = (output) ? virt_to_phys(output) : 0;
42567 u32 output_address_hi = output_address >> 32;
42568 u32 output_address_lo = output_address & 0xFFFFFFFF;
42569 - void *hypercall_page = hv_context.hypercall_page;
42570 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42571
42572 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42573 "=a"(hv_status_lo) : "d" (control_hi),
42574 @@ -156,7 +156,7 @@ int hv_init(void)
42575 /* See if the hypercall page is already set */
42576 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42577
42578 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42579 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42580
42581 if (!virtaddr)
42582 goto cleanup;
42583 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42584 index 5e90c5d..d8fcefb 100644
42585 --- a/drivers/hv/hv_balloon.c
42586 +++ b/drivers/hv/hv_balloon.c
42587 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42588
42589 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42590 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42591 -static atomic_t trans_id = ATOMIC_INIT(0);
42592 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42593
42594 static int dm_ring_size = (5 * PAGE_SIZE);
42595
42596 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42597 pr_info("Memory hot add failed\n");
42598
42599 dm->state = DM_INITIALIZED;
42600 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42601 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42602 vmbus_sendpacket(dm->dev->channel, &resp,
42603 sizeof(struct dm_hot_add_response),
42604 (unsigned long)NULL,
42605 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42606 memset(&status, 0, sizeof(struct dm_status));
42607 status.hdr.type = DM_STATUS_REPORT;
42608 status.hdr.size = sizeof(struct dm_status);
42609 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42610 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42611
42612 /*
42613 * The host expects the guest to report free memory.
42614 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42615 * send the status. This can happen if we were interrupted
42616 * after we picked our transaction ID.
42617 */
42618 - if (status.hdr.trans_id != atomic_read(&trans_id))
42619 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42620 return;
42621
42622 /*
42623 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42624 */
42625
42626 do {
42627 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42628 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42629 ret = vmbus_sendpacket(dm_device.dev->channel,
42630 bl_resp,
42631 bl_resp->hdr.size,
42632 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42633
42634 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42635 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42636 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42637 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42638 resp.hdr.size = sizeof(struct dm_unballoon_response);
42639
42640 vmbus_sendpacket(dm_device.dev->channel, &resp,
42641 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42642 memset(&version_req, 0, sizeof(struct dm_version_request));
42643 version_req.hdr.type = DM_VERSION_REQUEST;
42644 version_req.hdr.size = sizeof(struct dm_version_request);
42645 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42646 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42647 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42648 version_req.is_last_attempt = 1;
42649
42650 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42651 memset(&version_req, 0, sizeof(struct dm_version_request));
42652 version_req.hdr.type = DM_VERSION_REQUEST;
42653 version_req.hdr.size = sizeof(struct dm_version_request);
42654 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42655 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42656 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42657 version_req.is_last_attempt = 0;
42658
42659 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42660 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42661 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42662 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42663 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42664 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42665
42666 cap_msg.caps.cap_bits.balloon = 1;
42667 cap_msg.caps.cap_bits.hot_add = 1;
42668 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42669 index c386d8d..d6004c4 100644
42670 --- a/drivers/hv/hyperv_vmbus.h
42671 +++ b/drivers/hv/hyperv_vmbus.h
42672 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42673 struct vmbus_connection {
42674 enum vmbus_connect_state conn_state;
42675
42676 - atomic_t next_gpadl_handle;
42677 + atomic_unchecked_t next_gpadl_handle;
42678
42679 /*
42680 * Represents channel interrupts. Each bit position represents a
42681 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42682 index 4d6b269..2e23b86 100644
42683 --- a/drivers/hv/vmbus_drv.c
42684 +++ b/drivers/hv/vmbus_drv.c
42685 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42686 {
42687 int ret = 0;
42688
42689 - static atomic_t device_num = ATOMIC_INIT(0);
42690 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42691
42692 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42693 - atomic_inc_return(&device_num));
42694 + atomic_inc_return_unchecked(&device_num));
42695
42696 child_device_obj->device.bus = &hv_bus;
42697 child_device_obj->device.parent = &hv_acpi_dev->dev;
42698 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42699 index 579bdf9..75118b5 100644
42700 --- a/drivers/hwmon/acpi_power_meter.c
42701 +++ b/drivers/hwmon/acpi_power_meter.c
42702 @@ -116,7 +116,7 @@ struct sensor_template {
42703 struct device_attribute *devattr,
42704 const char *buf, size_t count);
42705 int index;
42706 -};
42707 +} __do_const;
42708
42709 /* Averaging interval */
42710 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42711 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42712 struct sensor_template *attrs)
42713 {
42714 struct device *dev = &resource->acpi_dev->dev;
42715 - struct sensor_device_attribute *sensors =
42716 + sensor_device_attribute_no_const *sensors =
42717 &resource->sensors[resource->num_sensors];
42718 int res = 0;
42719
42720 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42721 index 3288f13..71cfb4e 100644
42722 --- a/drivers/hwmon/applesmc.c
42723 +++ b/drivers/hwmon/applesmc.c
42724 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42725 {
42726 struct applesmc_node_group *grp;
42727 struct applesmc_dev_attr *node;
42728 - struct attribute *attr;
42729 + attribute_no_const *attr;
42730 int ret, i;
42731
42732 for (grp = groups; grp->format; grp++) {
42733 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42734 index cccef87..06ce8ec 100644
42735 --- a/drivers/hwmon/asus_atk0110.c
42736 +++ b/drivers/hwmon/asus_atk0110.c
42737 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42738 struct atk_sensor_data {
42739 struct list_head list;
42740 struct atk_data *data;
42741 - struct device_attribute label_attr;
42742 - struct device_attribute input_attr;
42743 - struct device_attribute limit1_attr;
42744 - struct device_attribute limit2_attr;
42745 + device_attribute_no_const label_attr;
42746 + device_attribute_no_const input_attr;
42747 + device_attribute_no_const limit1_attr;
42748 + device_attribute_no_const limit2_attr;
42749 char label_attr_name[ATTR_NAME_SIZE];
42750 char input_attr_name[ATTR_NAME_SIZE];
42751 char limit1_attr_name[ATTR_NAME_SIZE];
42752 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42753 static struct device_attribute atk_name_attr =
42754 __ATTR(name, 0444, atk_name_show, NULL);
42755
42756 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42757 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42758 sysfs_show_func show)
42759 {
42760 sysfs_attr_init(&attr->attr);
42761 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42762 index d76f0b7..55ae976 100644
42763 --- a/drivers/hwmon/coretemp.c
42764 +++ b/drivers/hwmon/coretemp.c
42765 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42766 return NOTIFY_OK;
42767 }
42768
42769 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42770 +static struct notifier_block coretemp_cpu_notifier = {
42771 .notifier_call = coretemp_cpu_callback,
42772 };
42773
42774 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42775 index 7a8a6fb..015c1fd 100644
42776 --- a/drivers/hwmon/ibmaem.c
42777 +++ b/drivers/hwmon/ibmaem.c
42778 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42779 struct aem_rw_sensor_template *rw)
42780 {
42781 struct device *dev = &data->pdev->dev;
42782 - struct sensor_device_attribute *sensors = data->sensors;
42783 + sensor_device_attribute_no_const *sensors = data->sensors;
42784 int err;
42785
42786 /* Set up read-only sensors */
42787 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42788 index 14c82da..09b25d7 100644
42789 --- a/drivers/hwmon/iio_hwmon.c
42790 +++ b/drivers/hwmon/iio_hwmon.c
42791 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42792 {
42793 struct device *dev = &pdev->dev;
42794 struct iio_hwmon_state *st;
42795 - struct sensor_device_attribute *a;
42796 + sensor_device_attribute_no_const *a;
42797 int ret, i;
42798 int in_i = 1, temp_i = 1, curr_i = 1;
42799 enum iio_chan_type type;
42800 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42801 index 7710f46..427a28d 100644
42802 --- a/drivers/hwmon/nct6683.c
42803 +++ b/drivers/hwmon/nct6683.c
42804 @@ -397,11 +397,11 @@ static struct attribute_group *
42805 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42806 int repeat)
42807 {
42808 - struct sensor_device_attribute_2 *a2;
42809 - struct sensor_device_attribute *a;
42810 + sensor_device_attribute_2_no_const *a2;
42811 + sensor_device_attribute_no_const *a;
42812 struct sensor_device_template **t;
42813 struct sensor_device_attr_u *su;
42814 - struct attribute_group *group;
42815 + attribute_group_no_const *group;
42816 struct attribute **attrs;
42817 int i, j, count;
42818
42819 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42820 index 504cbdd..35d6f25 100644
42821 --- a/drivers/hwmon/nct6775.c
42822 +++ b/drivers/hwmon/nct6775.c
42823 @@ -943,10 +943,10 @@ static struct attribute_group *
42824 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42825 int repeat)
42826 {
42827 - struct attribute_group *group;
42828 + attribute_group_no_const *group;
42829 struct sensor_device_attr_u *su;
42830 - struct sensor_device_attribute *a;
42831 - struct sensor_device_attribute_2 *a2;
42832 + sensor_device_attribute_no_const *a;
42833 + sensor_device_attribute_2_no_const *a2;
42834 struct attribute **attrs;
42835 struct sensor_device_template **t;
42836 int i, count;
42837 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42838 index 291d11f..3f0dbbd 100644
42839 --- a/drivers/hwmon/pmbus/pmbus_core.c
42840 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42841 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42842 return 0;
42843 }
42844
42845 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42846 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42847 const char *name,
42848 umode_t mode,
42849 ssize_t (*show)(struct device *dev,
42850 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42851 dev_attr->store = store;
42852 }
42853
42854 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42855 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42856 const char *name,
42857 umode_t mode,
42858 ssize_t (*show)(struct device *dev,
42859 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42860 u16 reg, u8 mask)
42861 {
42862 struct pmbus_boolean *boolean;
42863 - struct sensor_device_attribute *a;
42864 + sensor_device_attribute_no_const *a;
42865
42866 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42867 if (!boolean)
42868 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42869 bool update, bool readonly)
42870 {
42871 struct pmbus_sensor *sensor;
42872 - struct device_attribute *a;
42873 + device_attribute_no_const *a;
42874
42875 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42876 if (!sensor)
42877 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42878 const char *lstring, int index)
42879 {
42880 struct pmbus_label *label;
42881 - struct device_attribute *a;
42882 + device_attribute_no_const *a;
42883
42884 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42885 if (!label)
42886 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42887 index 97cd45a..ac54d8b 100644
42888 --- a/drivers/hwmon/sht15.c
42889 +++ b/drivers/hwmon/sht15.c
42890 @@ -169,7 +169,7 @@ struct sht15_data {
42891 int supply_uv;
42892 bool supply_uv_valid;
42893 struct work_struct update_supply_work;
42894 - atomic_t interrupt_handled;
42895 + atomic_unchecked_t interrupt_handled;
42896 };
42897
42898 /**
42899 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42900 ret = gpio_direction_input(data->pdata->gpio_data);
42901 if (ret)
42902 return ret;
42903 - atomic_set(&data->interrupt_handled, 0);
42904 + atomic_set_unchecked(&data->interrupt_handled, 0);
42905
42906 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42907 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42908 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42909 /* Only relevant if the interrupt hasn't occurred. */
42910 - if (!atomic_read(&data->interrupt_handled))
42911 + if (!atomic_read_unchecked(&data->interrupt_handled))
42912 schedule_work(&data->read_work);
42913 }
42914 ret = wait_event_timeout(data->wait_queue,
42915 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42916
42917 /* First disable the interrupt */
42918 disable_irq_nosync(irq);
42919 - atomic_inc(&data->interrupt_handled);
42920 + atomic_inc_unchecked(&data->interrupt_handled);
42921 /* Then schedule a reading work struct */
42922 if (data->state != SHT15_READING_NOTHING)
42923 schedule_work(&data->read_work);
42924 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42925 * If not, then start the interrupt again - care here as could
42926 * have gone low in meantime so verify it hasn't!
42927 */
42928 - atomic_set(&data->interrupt_handled, 0);
42929 + atomic_set_unchecked(&data->interrupt_handled, 0);
42930 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42931 /* If still not occurred or another handler was scheduled */
42932 if (gpio_get_value(data->pdata->gpio_data)
42933 - || atomic_read(&data->interrupt_handled))
42934 + || atomic_read_unchecked(&data->interrupt_handled))
42935 return;
42936 }
42937
42938 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42939 index 8df43c5..b07b91d 100644
42940 --- a/drivers/hwmon/via-cputemp.c
42941 +++ b/drivers/hwmon/via-cputemp.c
42942 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42943 return NOTIFY_OK;
42944 }
42945
42946 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42947 +static struct notifier_block via_cputemp_cpu_notifier = {
42948 .notifier_call = via_cputemp_cpu_callback,
42949 };
42950
42951 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42952 index 41fc683..a39cfea 100644
42953 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42954 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42955 @@ -43,7 +43,7 @@
42956 extern struct i2c_adapter amd756_smbus;
42957
42958 static struct i2c_adapter *s4882_adapter;
42959 -static struct i2c_algorithm *s4882_algo;
42960 +static i2c_algorithm_no_const *s4882_algo;
42961
42962 /* Wrapper access functions for multiplexed SMBus */
42963 static DEFINE_MUTEX(amd756_lock);
42964 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42965 index b19a310..d6eece0 100644
42966 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42967 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42968 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42969 /* usb layer */
42970
42971 /* Send command to device, and get response. */
42972 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42973 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42974 {
42975 int ret = 0;
42976 int actual;
42977 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42978 index b170bdf..3c76427 100644
42979 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42980 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42981 @@ -41,7 +41,7 @@
42982 extern struct i2c_adapter *nforce2_smbus;
42983
42984 static struct i2c_adapter *s4985_adapter;
42985 -static struct i2c_algorithm *s4985_algo;
42986 +static i2c_algorithm_no_const *s4985_algo;
42987
42988 /* Wrapper access functions for multiplexed SMBus */
42989 static DEFINE_MUTEX(nforce2_lock);
42990 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42991 index 80b47e8..1a6040d9 100644
42992 --- a/drivers/i2c/i2c-dev.c
42993 +++ b/drivers/i2c/i2c-dev.c
42994 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42995 break;
42996 }
42997
42998 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42999 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43000 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43001 if (IS_ERR(rdwr_pa[i].buf)) {
43002 res = PTR_ERR(rdwr_pa[i].buf);
43003 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43004 index 0b510ba..4fbb5085 100644
43005 --- a/drivers/ide/ide-cd.c
43006 +++ b/drivers/ide/ide-cd.c
43007 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43008 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43009 if ((unsigned long)buf & alignment
43010 || blk_rq_bytes(rq) & q->dma_pad_mask
43011 - || object_is_on_stack(buf))
43012 + || object_starts_on_stack(buf))
43013 drive->dma = 0;
43014 }
43015 }
43016 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43017 index af3e76d..96dfe5e 100644
43018 --- a/drivers/iio/industrialio-core.c
43019 +++ b/drivers/iio/industrialio-core.c
43020 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43021 }
43022
43023 static
43024 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43025 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43026 const char *postfix,
43027 struct iio_chan_spec const *chan,
43028 ssize_t (*readfunc)(struct device *dev,
43029 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43030 index e28a494..f7c2671 100644
43031 --- a/drivers/infiniband/core/cm.c
43032 +++ b/drivers/infiniband/core/cm.c
43033 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43034
43035 struct cm_counter_group {
43036 struct kobject obj;
43037 - atomic_long_t counter[CM_ATTR_COUNT];
43038 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43039 };
43040
43041 struct cm_counter_attribute {
43042 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43043 struct ib_mad_send_buf *msg = NULL;
43044 int ret;
43045
43046 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43047 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43048 counter[CM_REQ_COUNTER]);
43049
43050 /* Quick state check to discard duplicate REQs. */
43051 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43052 if (!cm_id_priv)
43053 return;
43054
43055 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43056 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43057 counter[CM_REP_COUNTER]);
43058 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43059 if (ret)
43060 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43061 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43062 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43063 spin_unlock_irq(&cm_id_priv->lock);
43064 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43065 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43066 counter[CM_RTU_COUNTER]);
43067 goto out;
43068 }
43069 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43070 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43071 dreq_msg->local_comm_id);
43072 if (!cm_id_priv) {
43073 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43074 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43075 counter[CM_DREQ_COUNTER]);
43076 cm_issue_drep(work->port, work->mad_recv_wc);
43077 return -EINVAL;
43078 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43079 case IB_CM_MRA_REP_RCVD:
43080 break;
43081 case IB_CM_TIMEWAIT:
43082 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43083 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43084 counter[CM_DREQ_COUNTER]);
43085 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43086 goto unlock;
43087 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43088 cm_free_msg(msg);
43089 goto deref;
43090 case IB_CM_DREQ_RCVD:
43091 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43092 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43093 counter[CM_DREQ_COUNTER]);
43094 goto unlock;
43095 default:
43096 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43097 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43098 cm_id_priv->msg, timeout)) {
43099 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43100 - atomic_long_inc(&work->port->
43101 + atomic_long_inc_unchecked(&work->port->
43102 counter_group[CM_RECV_DUPLICATES].
43103 counter[CM_MRA_COUNTER]);
43104 goto out;
43105 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43106 break;
43107 case IB_CM_MRA_REQ_RCVD:
43108 case IB_CM_MRA_REP_RCVD:
43109 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43110 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43111 counter[CM_MRA_COUNTER]);
43112 /* fall through */
43113 default:
43114 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43115 case IB_CM_LAP_IDLE:
43116 break;
43117 case IB_CM_MRA_LAP_SENT:
43118 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43119 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43120 counter[CM_LAP_COUNTER]);
43121 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43122 goto unlock;
43123 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43124 cm_free_msg(msg);
43125 goto deref;
43126 case IB_CM_LAP_RCVD:
43127 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43128 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43129 counter[CM_LAP_COUNTER]);
43130 goto unlock;
43131 default:
43132 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43133 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43134 if (cur_cm_id_priv) {
43135 spin_unlock_irq(&cm.lock);
43136 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43137 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43138 counter[CM_SIDR_REQ_COUNTER]);
43139 goto out; /* Duplicate message. */
43140 }
43141 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43142 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43143 msg->retries = 1;
43144
43145 - atomic_long_add(1 + msg->retries,
43146 + atomic_long_add_unchecked(1 + msg->retries,
43147 &port->counter_group[CM_XMIT].counter[attr_index]);
43148 if (msg->retries)
43149 - atomic_long_add(msg->retries,
43150 + atomic_long_add_unchecked(msg->retries,
43151 &port->counter_group[CM_XMIT_RETRIES].
43152 counter[attr_index]);
43153
43154 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43155 }
43156
43157 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43158 - atomic_long_inc(&port->counter_group[CM_RECV].
43159 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43160 counter[attr_id - CM_ATTR_ID_OFFSET]);
43161
43162 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43163 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43164 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43165
43166 return sprintf(buf, "%ld\n",
43167 - atomic_long_read(&group->counter[cm_attr->index]));
43168 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43169 }
43170
43171 static const struct sysfs_ops cm_counter_ops = {
43172 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43173 index 9f5ad7c..588cd84 100644
43174 --- a/drivers/infiniband/core/fmr_pool.c
43175 +++ b/drivers/infiniband/core/fmr_pool.c
43176 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
43177
43178 struct task_struct *thread;
43179
43180 - atomic_t req_ser;
43181 - atomic_t flush_ser;
43182 + atomic_unchecked_t req_ser;
43183 + atomic_unchecked_t flush_ser;
43184
43185 wait_queue_head_t force_wait;
43186 };
43187 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43188 struct ib_fmr_pool *pool = pool_ptr;
43189
43190 do {
43191 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43192 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43193 ib_fmr_batch_release(pool);
43194
43195 - atomic_inc(&pool->flush_ser);
43196 + atomic_inc_unchecked(&pool->flush_ser);
43197 wake_up_interruptible(&pool->force_wait);
43198
43199 if (pool->flush_function)
43200 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43201 }
43202
43203 set_current_state(TASK_INTERRUPTIBLE);
43204 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43205 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43206 !kthread_should_stop())
43207 schedule();
43208 __set_current_state(TASK_RUNNING);
43209 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43210 pool->dirty_watermark = params->dirty_watermark;
43211 pool->dirty_len = 0;
43212 spin_lock_init(&pool->pool_lock);
43213 - atomic_set(&pool->req_ser, 0);
43214 - atomic_set(&pool->flush_ser, 0);
43215 + atomic_set_unchecked(&pool->req_ser, 0);
43216 + atomic_set_unchecked(&pool->flush_ser, 0);
43217 init_waitqueue_head(&pool->force_wait);
43218
43219 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43220 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43221 }
43222 spin_unlock_irq(&pool->pool_lock);
43223
43224 - serial = atomic_inc_return(&pool->req_ser);
43225 + serial = atomic_inc_return_unchecked(&pool->req_ser);
43226 wake_up_process(pool->thread);
43227
43228 if (wait_event_interruptible(pool->force_wait,
43229 - atomic_read(&pool->flush_ser) - serial >= 0))
43230 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43231 return -EINTR;
43232
43233 return 0;
43234 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43235 } else {
43236 list_add_tail(&fmr->list, &pool->dirty_list);
43237 if (++pool->dirty_len >= pool->dirty_watermark) {
43238 - atomic_inc(&pool->req_ser);
43239 + atomic_inc_unchecked(&pool->req_ser);
43240 wake_up_process(pool->thread);
43241 }
43242 }
43243 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43244 index ec7a298..8742e59 100644
43245 --- a/drivers/infiniband/hw/cxgb4/mem.c
43246 +++ b/drivers/infiniband/hw/cxgb4/mem.c
43247 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43248 int err;
43249 struct fw_ri_tpte tpt;
43250 u32 stag_idx;
43251 - static atomic_t key;
43252 + static atomic_unchecked_t key;
43253
43254 if (c4iw_fatal_error(rdev))
43255 return -EIO;
43256 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43257 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43258 rdev->stats.stag.max = rdev->stats.stag.cur;
43259 mutex_unlock(&rdev->stats.lock);
43260 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43261 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
43262 }
43263 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
43264 __func__, stag_state, type, pdid, stag_idx);
43265 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
43266 index 79b3dbc..96e5fcc 100644
43267 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
43268 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
43269 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43270 struct ib_atomic_eth *ateth;
43271 struct ipath_ack_entry *e;
43272 u64 vaddr;
43273 - atomic64_t *maddr;
43274 + atomic64_unchecked_t *maddr;
43275 u64 sdata;
43276 u32 rkey;
43277 u8 next;
43278 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43279 IB_ACCESS_REMOTE_ATOMIC)))
43280 goto nack_acc_unlck;
43281 /* Perform atomic OP and save result. */
43282 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43283 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43284 sdata = be64_to_cpu(ateth->swap_data);
43285 e = &qp->s_ack_queue[qp->r_head_ack_queue];
43286 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
43287 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43288 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43289 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43290 be64_to_cpu(ateth->compare_data),
43291 sdata);
43292 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
43293 index 1f95bba..9530f87 100644
43294 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
43295 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
43296 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
43297 unsigned long flags;
43298 struct ib_wc wc;
43299 u64 sdata;
43300 - atomic64_t *maddr;
43301 + atomic64_unchecked_t *maddr;
43302 enum ib_wc_status send_status;
43303
43304 /*
43305 @@ -382,11 +382,11 @@ again:
43306 IB_ACCESS_REMOTE_ATOMIC)))
43307 goto acc_err;
43308 /* Perform atomic OP and save result. */
43309 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43310 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43311 sdata = wqe->wr.wr.atomic.compare_add;
43312 *(u64 *) sqp->s_sge.sge.vaddr =
43313 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43314 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43315 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43316 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43317 sdata, wqe->wr.wr.atomic.swap);
43318 goto send_comp;
43319 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43320 index 82a7dd8..8fb6ba6 100644
43321 --- a/drivers/infiniband/hw/mlx4/mad.c
43322 +++ b/drivers/infiniband/hw/mlx4/mad.c
43323 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43324
43325 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43326 {
43327 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43328 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43329 cpu_to_be64(0xff00000000000000LL);
43330 }
43331
43332 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43333 index ed327e6..ca1739e0 100644
43334 --- a/drivers/infiniband/hw/mlx4/mcg.c
43335 +++ b/drivers/infiniband/hw/mlx4/mcg.c
43336 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43337 {
43338 char name[20];
43339
43340 - atomic_set(&ctx->tid, 0);
43341 + atomic_set_unchecked(&ctx->tid, 0);
43342 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43343 ctx->mcg_wq = create_singlethread_workqueue(name);
43344 if (!ctx->mcg_wq)
43345 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43346 index 6eb743f..a7b0f6d 100644
43347 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43348 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43349 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43350 struct list_head mcg_mgid0_list;
43351 struct workqueue_struct *mcg_wq;
43352 struct mlx4_ib_demux_pv_ctx **tun;
43353 - atomic_t tid;
43354 + atomic_unchecked_t tid;
43355 int flushing; /* flushing the work queue */
43356 };
43357
43358 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43359 index 9d3e5c1..6f166df 100644
43360 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43361 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43362 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43363 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43364 }
43365
43366 -int mthca_QUERY_FW(struct mthca_dev *dev)
43367 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43368 {
43369 struct mthca_mailbox *mailbox;
43370 u32 *outbox;
43371 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43372 CMD_TIME_CLASS_B);
43373 }
43374
43375 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43376 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43377 int num_mtt)
43378 {
43379 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43380 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43381 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43382 }
43383
43384 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43385 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43386 int eq_num)
43387 {
43388 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43389 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43390 CMD_TIME_CLASS_B);
43391 }
43392
43393 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43394 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43395 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43396 void *in_mad, void *response_mad)
43397 {
43398 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43399 index ded76c1..0cf0a08 100644
43400 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43401 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43402 @@ -692,7 +692,7 @@ err_close:
43403 return err;
43404 }
43405
43406 -static int mthca_setup_hca(struct mthca_dev *dev)
43407 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43408 {
43409 int err;
43410
43411 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43412 index ed9a989..6aa5dc2 100644
43413 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43414 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43415 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43416 * through the bitmaps)
43417 */
43418
43419 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43420 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43421 {
43422 int o;
43423 int m;
43424 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43425 return key;
43426 }
43427
43428 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43429 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43430 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43431 {
43432 struct mthca_mailbox *mailbox;
43433 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43434 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43435 }
43436
43437 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43438 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43439 u64 *buffer_list, int buffer_size_shift,
43440 int list_len, u64 iova, u64 total_size,
43441 u32 access, struct mthca_mr *mr)
43442 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43443 index 415f8e1..e34214e 100644
43444 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43445 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43446 @@ -764,7 +764,7 @@ unlock:
43447 return 0;
43448 }
43449
43450 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43451 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43452 {
43453 struct mthca_dev *dev = to_mdev(ibcq->device);
43454 struct mthca_cq *cq = to_mcq(ibcq);
43455 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43456 index 3b2a6dc..bce26ff 100644
43457 --- a/drivers/infiniband/hw/nes/nes.c
43458 +++ b/drivers/infiniband/hw/nes/nes.c
43459 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43460 LIST_HEAD(nes_adapter_list);
43461 static LIST_HEAD(nes_dev_list);
43462
43463 -atomic_t qps_destroyed;
43464 +atomic_unchecked_t qps_destroyed;
43465
43466 static unsigned int ee_flsh_adapter;
43467 static unsigned int sysfs_nonidx_addr;
43468 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43469 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43470 struct nes_adapter *nesadapter = nesdev->nesadapter;
43471
43472 - atomic_inc(&qps_destroyed);
43473 + atomic_inc_unchecked(&qps_destroyed);
43474
43475 /* Free the control structures */
43476
43477 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43478 index bd9d132..70d84f4 100644
43479 --- a/drivers/infiniband/hw/nes/nes.h
43480 +++ b/drivers/infiniband/hw/nes/nes.h
43481 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43482 extern unsigned int wqm_quanta;
43483 extern struct list_head nes_adapter_list;
43484
43485 -extern atomic_t cm_connects;
43486 -extern atomic_t cm_accepts;
43487 -extern atomic_t cm_disconnects;
43488 -extern atomic_t cm_closes;
43489 -extern atomic_t cm_connecteds;
43490 -extern atomic_t cm_connect_reqs;
43491 -extern atomic_t cm_rejects;
43492 -extern atomic_t mod_qp_timouts;
43493 -extern atomic_t qps_created;
43494 -extern atomic_t qps_destroyed;
43495 -extern atomic_t sw_qps_destroyed;
43496 +extern atomic_unchecked_t cm_connects;
43497 +extern atomic_unchecked_t cm_accepts;
43498 +extern atomic_unchecked_t cm_disconnects;
43499 +extern atomic_unchecked_t cm_closes;
43500 +extern atomic_unchecked_t cm_connecteds;
43501 +extern atomic_unchecked_t cm_connect_reqs;
43502 +extern atomic_unchecked_t cm_rejects;
43503 +extern atomic_unchecked_t mod_qp_timouts;
43504 +extern atomic_unchecked_t qps_created;
43505 +extern atomic_unchecked_t qps_destroyed;
43506 +extern atomic_unchecked_t sw_qps_destroyed;
43507 extern u32 mh_detected;
43508 extern u32 mh_pauses_sent;
43509 extern u32 cm_packets_sent;
43510 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43511 extern u32 cm_packets_received;
43512 extern u32 cm_packets_dropped;
43513 extern u32 cm_packets_retrans;
43514 -extern atomic_t cm_listens_created;
43515 -extern atomic_t cm_listens_destroyed;
43516 +extern atomic_unchecked_t cm_listens_created;
43517 +extern atomic_unchecked_t cm_listens_destroyed;
43518 extern u32 cm_backlog_drops;
43519 -extern atomic_t cm_loopbacks;
43520 -extern atomic_t cm_nodes_created;
43521 -extern atomic_t cm_nodes_destroyed;
43522 -extern atomic_t cm_accel_dropped_pkts;
43523 -extern atomic_t cm_resets_recvd;
43524 -extern atomic_t pau_qps_created;
43525 -extern atomic_t pau_qps_destroyed;
43526 +extern atomic_unchecked_t cm_loopbacks;
43527 +extern atomic_unchecked_t cm_nodes_created;
43528 +extern atomic_unchecked_t cm_nodes_destroyed;
43529 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43530 +extern atomic_unchecked_t cm_resets_recvd;
43531 +extern atomic_unchecked_t pau_qps_created;
43532 +extern atomic_unchecked_t pau_qps_destroyed;
43533
43534 extern u32 int_mod_timer_init;
43535 extern u32 int_mod_cq_depth_256;
43536 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43537 index 6f09a72..cf4399d 100644
43538 --- a/drivers/infiniband/hw/nes/nes_cm.c
43539 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43540 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43541 u32 cm_packets_retrans;
43542 u32 cm_packets_created;
43543 u32 cm_packets_received;
43544 -atomic_t cm_listens_created;
43545 -atomic_t cm_listens_destroyed;
43546 +atomic_unchecked_t cm_listens_created;
43547 +atomic_unchecked_t cm_listens_destroyed;
43548 u32 cm_backlog_drops;
43549 -atomic_t cm_loopbacks;
43550 -atomic_t cm_nodes_created;
43551 -atomic_t cm_nodes_destroyed;
43552 -atomic_t cm_accel_dropped_pkts;
43553 -atomic_t cm_resets_recvd;
43554 +atomic_unchecked_t cm_loopbacks;
43555 +atomic_unchecked_t cm_nodes_created;
43556 +atomic_unchecked_t cm_nodes_destroyed;
43557 +atomic_unchecked_t cm_accel_dropped_pkts;
43558 +atomic_unchecked_t cm_resets_recvd;
43559
43560 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43561 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43562 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43563 /* instance of function pointers for client API */
43564 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43565 static struct nes_cm_ops nes_cm_api = {
43566 - mini_cm_accelerated,
43567 - mini_cm_listen,
43568 - mini_cm_del_listen,
43569 - mini_cm_connect,
43570 - mini_cm_close,
43571 - mini_cm_accept,
43572 - mini_cm_reject,
43573 - mini_cm_recv_pkt,
43574 - mini_cm_dealloc_core,
43575 - mini_cm_get,
43576 - mini_cm_set
43577 + .accelerated = mini_cm_accelerated,
43578 + .listen = mini_cm_listen,
43579 + .stop_listener = mini_cm_del_listen,
43580 + .connect = mini_cm_connect,
43581 + .close = mini_cm_close,
43582 + .accept = mini_cm_accept,
43583 + .reject = mini_cm_reject,
43584 + .recv_pkt = mini_cm_recv_pkt,
43585 + .destroy_cm_core = mini_cm_dealloc_core,
43586 + .get = mini_cm_get,
43587 + .set = mini_cm_set
43588 };
43589
43590 static struct nes_cm_core *g_cm_core;
43591
43592 -atomic_t cm_connects;
43593 -atomic_t cm_accepts;
43594 -atomic_t cm_disconnects;
43595 -atomic_t cm_closes;
43596 -atomic_t cm_connecteds;
43597 -atomic_t cm_connect_reqs;
43598 -atomic_t cm_rejects;
43599 +atomic_unchecked_t cm_connects;
43600 +atomic_unchecked_t cm_accepts;
43601 +atomic_unchecked_t cm_disconnects;
43602 +atomic_unchecked_t cm_closes;
43603 +atomic_unchecked_t cm_connecteds;
43604 +atomic_unchecked_t cm_connect_reqs;
43605 +atomic_unchecked_t cm_rejects;
43606
43607 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43608 {
43609 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43610 kfree(listener);
43611 listener = NULL;
43612 ret = 0;
43613 - atomic_inc(&cm_listens_destroyed);
43614 + atomic_inc_unchecked(&cm_listens_destroyed);
43615 } else {
43616 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43617 }
43618 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43619 cm_node->rem_mac);
43620
43621 add_hte_node(cm_core, cm_node);
43622 - atomic_inc(&cm_nodes_created);
43623 + atomic_inc_unchecked(&cm_nodes_created);
43624
43625 return cm_node;
43626 }
43627 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43628 }
43629
43630 atomic_dec(&cm_core->node_cnt);
43631 - atomic_inc(&cm_nodes_destroyed);
43632 + atomic_inc_unchecked(&cm_nodes_destroyed);
43633 nesqp = cm_node->nesqp;
43634 if (nesqp) {
43635 nesqp->cm_node = NULL;
43636 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43637
43638 static void drop_packet(struct sk_buff *skb)
43639 {
43640 - atomic_inc(&cm_accel_dropped_pkts);
43641 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43642 dev_kfree_skb_any(skb);
43643 }
43644
43645 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43646 {
43647
43648 int reset = 0; /* whether to send reset in case of err.. */
43649 - atomic_inc(&cm_resets_recvd);
43650 + atomic_inc_unchecked(&cm_resets_recvd);
43651 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43652 " refcnt=%d\n", cm_node, cm_node->state,
43653 atomic_read(&cm_node->ref_count));
43654 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43655 rem_ref_cm_node(cm_node->cm_core, cm_node);
43656 return NULL;
43657 }
43658 - atomic_inc(&cm_loopbacks);
43659 + atomic_inc_unchecked(&cm_loopbacks);
43660 loopbackremotenode->loopbackpartner = cm_node;
43661 loopbackremotenode->tcp_cntxt.rcv_wscale =
43662 NES_CM_DEFAULT_RCV_WND_SCALE;
43663 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43664 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43665 else {
43666 rem_ref_cm_node(cm_core, cm_node);
43667 - atomic_inc(&cm_accel_dropped_pkts);
43668 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43669 dev_kfree_skb_any(skb);
43670 }
43671 break;
43672 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43673
43674 if ((cm_id) && (cm_id->event_handler)) {
43675 if (issue_disconn) {
43676 - atomic_inc(&cm_disconnects);
43677 + atomic_inc_unchecked(&cm_disconnects);
43678 cm_event.event = IW_CM_EVENT_DISCONNECT;
43679 cm_event.status = disconn_status;
43680 cm_event.local_addr = cm_id->local_addr;
43681 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43682 }
43683
43684 if (issue_close) {
43685 - atomic_inc(&cm_closes);
43686 + atomic_inc_unchecked(&cm_closes);
43687 nes_disconnect(nesqp, 1);
43688
43689 cm_id->provider_data = nesqp;
43690 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43691
43692 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43693 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43694 - atomic_inc(&cm_accepts);
43695 + atomic_inc_unchecked(&cm_accepts);
43696
43697 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43698 netdev_refcnt_read(nesvnic->netdev));
43699 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43700 struct nes_cm_core *cm_core;
43701 u8 *start_buff;
43702
43703 - atomic_inc(&cm_rejects);
43704 + atomic_inc_unchecked(&cm_rejects);
43705 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43706 loopback = cm_node->loopbackpartner;
43707 cm_core = cm_node->cm_core;
43708 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43709 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43710 ntohs(laddr->sin_port));
43711
43712 - atomic_inc(&cm_connects);
43713 + atomic_inc_unchecked(&cm_connects);
43714 nesqp->active_conn = 1;
43715
43716 /* cache the cm_id in the qp */
43717 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43718 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43719 return err;
43720 }
43721 - atomic_inc(&cm_listens_created);
43722 + atomic_inc_unchecked(&cm_listens_created);
43723 }
43724
43725 cm_id->add_ref(cm_id);
43726 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43727
43728 if (nesqp->destroyed)
43729 return;
43730 - atomic_inc(&cm_connecteds);
43731 + atomic_inc_unchecked(&cm_connecteds);
43732 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43733 " local port 0x%04X. jiffies = %lu.\n",
43734 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43735 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43736
43737 cm_id->add_ref(cm_id);
43738 ret = cm_id->event_handler(cm_id, &cm_event);
43739 - atomic_inc(&cm_closes);
43740 + atomic_inc_unchecked(&cm_closes);
43741 cm_event.event = IW_CM_EVENT_CLOSE;
43742 cm_event.status = 0;
43743 cm_event.provider_data = cm_id->provider_data;
43744 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43745 return;
43746 cm_id = cm_node->cm_id;
43747
43748 - atomic_inc(&cm_connect_reqs);
43749 + atomic_inc_unchecked(&cm_connect_reqs);
43750 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43751 cm_node, cm_id, jiffies);
43752
43753 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43754 return;
43755 cm_id = cm_node->cm_id;
43756
43757 - atomic_inc(&cm_connect_reqs);
43758 + atomic_inc_unchecked(&cm_connect_reqs);
43759 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43760 cm_node, cm_id, jiffies);
43761
43762 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43763 index 4166452..fc952c3 100644
43764 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43765 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43766 @@ -40,8 +40,8 @@
43767 #include "nes.h"
43768 #include "nes_mgt.h"
43769
43770 -atomic_t pau_qps_created;
43771 -atomic_t pau_qps_destroyed;
43772 +atomic_unchecked_t pau_qps_created;
43773 +atomic_unchecked_t pau_qps_destroyed;
43774
43775 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43776 {
43777 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43778 {
43779 struct sk_buff *skb;
43780 unsigned long flags;
43781 - atomic_inc(&pau_qps_destroyed);
43782 + atomic_inc_unchecked(&pau_qps_destroyed);
43783
43784 /* Free packets that have not yet been forwarded */
43785 /* Lock is acquired by skb_dequeue when removing the skb */
43786 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43787 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43788 skb_queue_head_init(&nesqp->pau_list);
43789 spin_lock_init(&nesqp->pau_lock);
43790 - atomic_inc(&pau_qps_created);
43791 + atomic_inc_unchecked(&pau_qps_created);
43792 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43793 }
43794
43795 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43796 index 49eb511..a774366 100644
43797 --- a/drivers/infiniband/hw/nes/nes_nic.c
43798 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43799 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43800 target_stat_values[++index] = mh_detected;
43801 target_stat_values[++index] = mh_pauses_sent;
43802 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43803 - target_stat_values[++index] = atomic_read(&cm_connects);
43804 - target_stat_values[++index] = atomic_read(&cm_accepts);
43805 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43806 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43807 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43808 - target_stat_values[++index] = atomic_read(&cm_rejects);
43809 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43810 - target_stat_values[++index] = atomic_read(&qps_created);
43811 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43812 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43813 - target_stat_values[++index] = atomic_read(&cm_closes);
43814 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43815 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43816 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43817 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43818 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43819 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43820 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43821 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43822 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43823 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43824 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43825 target_stat_values[++index] = cm_packets_sent;
43826 target_stat_values[++index] = cm_packets_bounced;
43827 target_stat_values[++index] = cm_packets_created;
43828 target_stat_values[++index] = cm_packets_received;
43829 target_stat_values[++index] = cm_packets_dropped;
43830 target_stat_values[++index] = cm_packets_retrans;
43831 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43832 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43833 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43834 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43835 target_stat_values[++index] = cm_backlog_drops;
43836 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43837 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43838 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43839 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43840 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43841 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43842 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43843 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43844 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43845 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43846 target_stat_values[++index] = nesadapter->free_4kpbl;
43847 target_stat_values[++index] = nesadapter->free_256pbl;
43848 target_stat_values[++index] = int_mod_timer_init;
43849 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43850 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43851 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43852 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43853 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43854 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43855 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43856 }
43857
43858 /**
43859 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43860 index fef067c..6a25ccd 100644
43861 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43862 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43863 @@ -46,9 +46,9 @@
43864
43865 #include <rdma/ib_umem.h>
43866
43867 -atomic_t mod_qp_timouts;
43868 -atomic_t qps_created;
43869 -atomic_t sw_qps_destroyed;
43870 +atomic_unchecked_t mod_qp_timouts;
43871 +atomic_unchecked_t qps_created;
43872 +atomic_unchecked_t sw_qps_destroyed;
43873
43874 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43875
43876 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43877 if (init_attr->create_flags)
43878 return ERR_PTR(-EINVAL);
43879
43880 - atomic_inc(&qps_created);
43881 + atomic_inc_unchecked(&qps_created);
43882 switch (init_attr->qp_type) {
43883 case IB_QPT_RC:
43884 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43885 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43886 struct iw_cm_event cm_event;
43887 int ret = 0;
43888
43889 - atomic_inc(&sw_qps_destroyed);
43890 + atomic_inc_unchecked(&sw_qps_destroyed);
43891 nesqp->destroyed = 1;
43892
43893 /* Blow away the connection if it exists. */
43894 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43895 index c00ae09..04e91be 100644
43896 --- a/drivers/infiniband/hw/qib/qib.h
43897 +++ b/drivers/infiniband/hw/qib/qib.h
43898 @@ -52,6 +52,7 @@
43899 #include <linux/kref.h>
43900 #include <linux/sched.h>
43901 #include <linux/kthread.h>
43902 +#include <linux/slab.h>
43903
43904 #include "qib_common.h"
43905 #include "qib_verbs.h"
43906 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43907 index 24c41ba..102d71f 100644
43908 --- a/drivers/input/gameport/gameport.c
43909 +++ b/drivers/input/gameport/gameport.c
43910 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43911 */
43912 static void gameport_init_port(struct gameport *gameport)
43913 {
43914 - static atomic_t gameport_no = ATOMIC_INIT(0);
43915 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43916
43917 __module_get(THIS_MODULE);
43918
43919 mutex_init(&gameport->drv_mutex);
43920 device_initialize(&gameport->dev);
43921 dev_set_name(&gameport->dev, "gameport%lu",
43922 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43923 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43924 gameport->dev.bus = &gameport_bus;
43925 gameport->dev.release = gameport_release_port;
43926 if (gameport->parent)
43927 diff --git a/drivers/input/input.c b/drivers/input/input.c
43928 index 29ca0bb..f4bc2e3 100644
43929 --- a/drivers/input/input.c
43930 +++ b/drivers/input/input.c
43931 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
43932 */
43933 struct input_dev *input_allocate_device(void)
43934 {
43935 - static atomic_t input_no = ATOMIC_INIT(0);
43936 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43937 struct input_dev *dev;
43938
43939 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43940 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
43941 INIT_LIST_HEAD(&dev->node);
43942
43943 dev_set_name(&dev->dev, "input%ld",
43944 - (unsigned long) atomic_inc_return(&input_no) - 1);
43945 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43946
43947 __module_get(THIS_MODULE);
43948 }
43949 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43950 index 4a95b22..874c182 100644
43951 --- a/drivers/input/joystick/sidewinder.c
43952 +++ b/drivers/input/joystick/sidewinder.c
43953 @@ -30,6 +30,7 @@
43954 #include <linux/kernel.h>
43955 #include <linux/module.h>
43956 #include <linux/slab.h>
43957 +#include <linux/sched.h>
43958 #include <linux/input.h>
43959 #include <linux/gameport.h>
43960 #include <linux/jiffies.h>
43961 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43962 index 177602c..ec78499 100644
43963 --- a/drivers/input/joystick/xpad.c
43964 +++ b/drivers/input/joystick/xpad.c
43965 @@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43966
43967 static int xpad_led_probe(struct usb_xpad *xpad)
43968 {
43969 - static atomic_t led_seq = ATOMIC_INIT(0);
43970 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43971 long led_no;
43972 struct xpad_led *led;
43973 struct led_classdev *led_cdev;
43974 @@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43975 if (!led)
43976 return -ENOMEM;
43977
43978 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43979 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43980
43981 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43982 led->xpad = xpad;
43983 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43984 index 719410f..1896169 100644
43985 --- a/drivers/input/misc/ims-pcu.c
43986 +++ b/drivers/input/misc/ims-pcu.c
43987 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43988
43989 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43990 {
43991 - static atomic_t device_no = ATOMIC_INIT(0);
43992 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43993
43994 const struct ims_pcu_device_info *info;
43995 int error;
43996 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43997 }
43998
43999 /* Device appears to be operable, complete initialization */
44000 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44001 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44002
44003 /*
44004 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44005 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44006 index 2f0b39d..7370f13 100644
44007 --- a/drivers/input/mouse/psmouse.h
44008 +++ b/drivers/input/mouse/psmouse.h
44009 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44010 ssize_t (*set)(struct psmouse *psmouse, void *data,
44011 const char *buf, size_t count);
44012 bool protect;
44013 -};
44014 +} __do_const;
44015 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44016
44017 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44018 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44019 index b604564..3f14ae4 100644
44020 --- a/drivers/input/mousedev.c
44021 +++ b/drivers/input/mousedev.c
44022 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44023
44024 spin_unlock_irq(&client->packet_lock);
44025
44026 - if (copy_to_user(buffer, data, count))
44027 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44028 return -EFAULT;
44029
44030 return count;
44031 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44032 index b29134d..394deb0 100644
44033 --- a/drivers/input/serio/serio.c
44034 +++ b/drivers/input/serio/serio.c
44035 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44036 */
44037 static void serio_init_port(struct serio *serio)
44038 {
44039 - static atomic_t serio_no = ATOMIC_INIT(0);
44040 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44041
44042 __module_get(THIS_MODULE);
44043
44044 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44045 mutex_init(&serio->drv_mutex);
44046 device_initialize(&serio->dev);
44047 dev_set_name(&serio->dev, "serio%ld",
44048 - (long)atomic_inc_return(&serio_no) - 1);
44049 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44050 serio->dev.bus = &serio_bus;
44051 serio->dev.release = serio_release_port;
44052 serio->dev.groups = serio_device_attr_groups;
44053 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44054 index c9a02fe..0debc75 100644
44055 --- a/drivers/input/serio/serio_raw.c
44056 +++ b/drivers/input/serio/serio_raw.c
44057 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44058
44059 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44060 {
44061 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44062 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44063 struct serio_raw *serio_raw;
44064 int err;
44065
44066 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44067 }
44068
44069 snprintf(serio_raw->name, sizeof(serio_raw->name),
44070 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44071 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44072 kref_init(&serio_raw->kref);
44073 INIT_LIST_HEAD(&serio_raw->client_list);
44074 init_waitqueue_head(&serio_raw->wait);
44075 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44076 index a83cc2a..64462e6 100644
44077 --- a/drivers/iommu/arm-smmu.c
44078 +++ b/drivers/iommu/arm-smmu.c
44079 @@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44080 cfg->irptndx = cfg->cbndx;
44081 }
44082
44083 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
44084 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44085 arm_smmu_init_context_bank(smmu_domain);
44086 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44087
44088 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44089 index 33c4395..e06447e 100644
44090 --- a/drivers/iommu/irq_remapping.c
44091 +++ b/drivers/iommu/irq_remapping.c
44092 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44093 void panic_if_irq_remap(const char *msg)
44094 {
44095 if (irq_remapping_enabled)
44096 - panic(msg);
44097 + panic("%s", msg);
44098 }
44099
44100 static void ir_ack_apic_edge(struct irq_data *data)
44101 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44102
44103 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44104 {
44105 - chip->irq_print_chip = ir_print_prefix;
44106 - chip->irq_ack = ir_ack_apic_edge;
44107 - chip->irq_eoi = ir_ack_apic_level;
44108 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44109 + pax_open_kernel();
44110 + *(void **)&chip->irq_print_chip = ir_print_prefix;
44111 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
44112 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
44113 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44114 + pax_close_kernel();
44115 }
44116
44117 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44118 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44119 index dda6dbc..f9adebb 100644
44120 --- a/drivers/irqchip/irq-gic.c
44121 +++ b/drivers/irqchip/irq-gic.c
44122 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44123 * Supported arch specific GIC irq extension.
44124 * Default make them NULL.
44125 */
44126 -struct irq_chip gic_arch_extn = {
44127 +irq_chip_no_const gic_arch_extn = {
44128 .irq_eoi = NULL,
44129 .irq_mask = NULL,
44130 .irq_unmask = NULL,
44131 @@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44132 chained_irq_exit(chip, desc);
44133 }
44134
44135 -static struct irq_chip gic_chip = {
44136 +static irq_chip_no_const gic_chip __read_only = {
44137 .name = "GIC",
44138 .irq_mask = gic_mask_irq,
44139 .irq_unmask = gic_unmask_irq,
44140 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44141 index 8777065..a4a9967 100644
44142 --- a/drivers/irqchip/irq-renesas-irqc.c
44143 +++ b/drivers/irqchip/irq-renesas-irqc.c
44144 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44145 struct irqc_priv *p;
44146 struct resource *io;
44147 struct resource *irq;
44148 - struct irq_chip *irq_chip;
44149 + irq_chip_no_const *irq_chip;
44150 const char *name = dev_name(&pdev->dev);
44151 int ret;
44152 int k;
44153 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44154 index 6a2df32..dc962f1 100644
44155 --- a/drivers/isdn/capi/capi.c
44156 +++ b/drivers/isdn/capi/capi.c
44157 @@ -81,8 +81,8 @@ struct capiminor {
44158
44159 struct capi20_appl *ap;
44160 u32 ncci;
44161 - atomic_t datahandle;
44162 - atomic_t msgid;
44163 + atomic_unchecked_t datahandle;
44164 + atomic_unchecked_t msgid;
44165
44166 struct tty_port port;
44167 int ttyinstop;
44168 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44169 capimsg_setu16(s, 2, mp->ap->applid);
44170 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44171 capimsg_setu8 (s, 5, CAPI_RESP);
44172 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44173 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44174 capimsg_setu32(s, 8, mp->ncci);
44175 capimsg_setu16(s, 12, datahandle);
44176 }
44177 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44178 mp->outbytes -= len;
44179 spin_unlock_bh(&mp->outlock);
44180
44181 - datahandle = atomic_inc_return(&mp->datahandle);
44182 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44183 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44184 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44185 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44186 capimsg_setu16(skb->data, 2, mp->ap->applid);
44187 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44188 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44189 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44190 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44191 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44192 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44193 capimsg_setu16(skb->data, 16, len); /* Data length */
44194 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44195 index b7ae0a0..04590fa 100644
44196 --- a/drivers/isdn/gigaset/bas-gigaset.c
44197 +++ b/drivers/isdn/gigaset/bas-gigaset.c
44198 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44199
44200
44201 static const struct gigaset_ops gigops = {
44202 - gigaset_write_cmd,
44203 - gigaset_write_room,
44204 - gigaset_chars_in_buffer,
44205 - gigaset_brkchars,
44206 - gigaset_init_bchannel,
44207 - gigaset_close_bchannel,
44208 - gigaset_initbcshw,
44209 - gigaset_freebcshw,
44210 - gigaset_reinitbcshw,
44211 - gigaset_initcshw,
44212 - gigaset_freecshw,
44213 - gigaset_set_modem_ctrl,
44214 - gigaset_baud_rate,
44215 - gigaset_set_line_ctrl,
44216 - gigaset_isoc_send_skb,
44217 - gigaset_isoc_input,
44218 + .write_cmd = gigaset_write_cmd,
44219 + .write_room = gigaset_write_room,
44220 + .chars_in_buffer = gigaset_chars_in_buffer,
44221 + .brkchars = gigaset_brkchars,
44222 + .init_bchannel = gigaset_init_bchannel,
44223 + .close_bchannel = gigaset_close_bchannel,
44224 + .initbcshw = gigaset_initbcshw,
44225 + .freebcshw = gigaset_freebcshw,
44226 + .reinitbcshw = gigaset_reinitbcshw,
44227 + .initcshw = gigaset_initcshw,
44228 + .freecshw = gigaset_freecshw,
44229 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44230 + .baud_rate = gigaset_baud_rate,
44231 + .set_line_ctrl = gigaset_set_line_ctrl,
44232 + .send_skb = gigaset_isoc_send_skb,
44233 + .handle_input = gigaset_isoc_input,
44234 };
44235
44236 /* bas_gigaset_init
44237 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44238 index 600c79b..3752bab 100644
44239 --- a/drivers/isdn/gigaset/interface.c
44240 +++ b/drivers/isdn/gigaset/interface.c
44241 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44242 }
44243 tty->driver_data = cs;
44244
44245 - ++cs->port.count;
44246 + atomic_inc(&cs->port.count);
44247
44248 - if (cs->port.count == 1) {
44249 + if (atomic_read(&cs->port.count) == 1) {
44250 tty_port_tty_set(&cs->port, tty);
44251 cs->port.low_latency = 1;
44252 }
44253 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44254
44255 if (!cs->connected)
44256 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44257 - else if (!cs->port.count)
44258 + else if (!atomic_read(&cs->port.count))
44259 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44260 - else if (!--cs->port.count)
44261 + else if (!atomic_dec_return(&cs->port.count))
44262 tty_port_tty_set(&cs->port, NULL);
44263
44264 mutex_unlock(&cs->mutex);
44265 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44266 index 8c91fd5..14f13ce 100644
44267 --- a/drivers/isdn/gigaset/ser-gigaset.c
44268 +++ b/drivers/isdn/gigaset/ser-gigaset.c
44269 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44270 }
44271
44272 static const struct gigaset_ops ops = {
44273 - gigaset_write_cmd,
44274 - gigaset_write_room,
44275 - gigaset_chars_in_buffer,
44276 - gigaset_brkchars,
44277 - gigaset_init_bchannel,
44278 - gigaset_close_bchannel,
44279 - gigaset_initbcshw,
44280 - gigaset_freebcshw,
44281 - gigaset_reinitbcshw,
44282 - gigaset_initcshw,
44283 - gigaset_freecshw,
44284 - gigaset_set_modem_ctrl,
44285 - gigaset_baud_rate,
44286 - gigaset_set_line_ctrl,
44287 - gigaset_m10x_send_skb, /* asyncdata.c */
44288 - gigaset_m10x_input, /* asyncdata.c */
44289 + .write_cmd = gigaset_write_cmd,
44290 + .write_room = gigaset_write_room,
44291 + .chars_in_buffer = gigaset_chars_in_buffer,
44292 + .brkchars = gigaset_brkchars,
44293 + .init_bchannel = gigaset_init_bchannel,
44294 + .close_bchannel = gigaset_close_bchannel,
44295 + .initbcshw = gigaset_initbcshw,
44296 + .freebcshw = gigaset_freebcshw,
44297 + .reinitbcshw = gigaset_reinitbcshw,
44298 + .initcshw = gigaset_initcshw,
44299 + .freecshw = gigaset_freecshw,
44300 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44301 + .baud_rate = gigaset_baud_rate,
44302 + .set_line_ctrl = gigaset_set_line_ctrl,
44303 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44304 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44305 };
44306
44307
44308 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44309 index d0a41cb..b953e50 100644
44310 --- a/drivers/isdn/gigaset/usb-gigaset.c
44311 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44312 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44313 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44314 memcpy(cs->hw.usb->bchars, buf, 6);
44315 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44316 - 0, 0, &buf, 6, 2000);
44317 + 0, 0, buf, 6, 2000);
44318 }
44319
44320 static void gigaset_freebcshw(struct bc_state *bcs)
44321 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44322 }
44323
44324 static const struct gigaset_ops ops = {
44325 - gigaset_write_cmd,
44326 - gigaset_write_room,
44327 - gigaset_chars_in_buffer,
44328 - gigaset_brkchars,
44329 - gigaset_init_bchannel,
44330 - gigaset_close_bchannel,
44331 - gigaset_initbcshw,
44332 - gigaset_freebcshw,
44333 - gigaset_reinitbcshw,
44334 - gigaset_initcshw,
44335 - gigaset_freecshw,
44336 - gigaset_set_modem_ctrl,
44337 - gigaset_baud_rate,
44338 - gigaset_set_line_ctrl,
44339 - gigaset_m10x_send_skb,
44340 - gigaset_m10x_input,
44341 + .write_cmd = gigaset_write_cmd,
44342 + .write_room = gigaset_write_room,
44343 + .chars_in_buffer = gigaset_chars_in_buffer,
44344 + .brkchars = gigaset_brkchars,
44345 + .init_bchannel = gigaset_init_bchannel,
44346 + .close_bchannel = gigaset_close_bchannel,
44347 + .initbcshw = gigaset_initbcshw,
44348 + .freebcshw = gigaset_freebcshw,
44349 + .reinitbcshw = gigaset_reinitbcshw,
44350 + .initcshw = gigaset_initcshw,
44351 + .freecshw = gigaset_freecshw,
44352 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44353 + .baud_rate = gigaset_baud_rate,
44354 + .set_line_ctrl = gigaset_set_line_ctrl,
44355 + .send_skb = gigaset_m10x_send_skb,
44356 + .handle_input = gigaset_m10x_input,
44357 };
44358
44359 /*
44360 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44361 index 4d9b195..455075c 100644
44362 --- a/drivers/isdn/hardware/avm/b1.c
44363 +++ b/drivers/isdn/hardware/avm/b1.c
44364 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44365 }
44366 if (left) {
44367 if (t4file->user) {
44368 - if (copy_from_user(buf, dp, left))
44369 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44370 return -EFAULT;
44371 } else {
44372 memcpy(buf, dp, left);
44373 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44374 }
44375 if (left) {
44376 if (config->user) {
44377 - if (copy_from_user(buf, dp, left))
44378 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44379 return -EFAULT;
44380 } else {
44381 memcpy(buf, dp, left);
44382 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44383 index 9b856e1..fa03c92 100644
44384 --- a/drivers/isdn/i4l/isdn_common.c
44385 +++ b/drivers/isdn/i4l/isdn_common.c
44386 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44387 } else
44388 return -EINVAL;
44389 case IIOCDBGVAR:
44390 + if (!capable(CAP_SYS_RAWIO))
44391 + return -EPERM;
44392 if (arg) {
44393 if (copy_to_user(argp, &dev, sizeof(ulong)))
44394 return -EFAULT;
44395 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44396 index 91d5730..336523e 100644
44397 --- a/drivers/isdn/i4l/isdn_concap.c
44398 +++ b/drivers/isdn/i4l/isdn_concap.c
44399 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44400 }
44401
44402 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44403 - &isdn_concap_dl_data_req,
44404 - &isdn_concap_dl_connect_req,
44405 - &isdn_concap_dl_disconn_req
44406 + .data_req = &isdn_concap_dl_data_req,
44407 + .connect_req = &isdn_concap_dl_connect_req,
44408 + .disconn_req = &isdn_concap_dl_disconn_req
44409 };
44410
44411 /* The following should better go into a dedicated source file such that
44412 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44413 index 3c5f249..5fac4d0 100644
44414 --- a/drivers/isdn/i4l/isdn_tty.c
44415 +++ b/drivers/isdn/i4l/isdn_tty.c
44416 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44417
44418 #ifdef ISDN_DEBUG_MODEM_OPEN
44419 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44420 - port->count);
44421 + atomic_read(&port->count));
44422 #endif
44423 - port->count++;
44424 + atomic_inc(&port->count);
44425 port->tty = tty;
44426 /*
44427 * Start up serial port
44428 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44429 #endif
44430 return;
44431 }
44432 - if ((tty->count == 1) && (port->count != 1)) {
44433 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44434 /*
44435 * Uh, oh. tty->count is 1, which means that the tty
44436 * structure will be freed. Info->count should always
44437 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44438 * serial port won't be shutdown.
44439 */
44440 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44441 - "info->count is %d\n", port->count);
44442 - port->count = 1;
44443 + "info->count is %d\n", atomic_read(&port->count));
44444 + atomic_set(&port->count, 1);
44445 }
44446 - if (--port->count < 0) {
44447 + if (atomic_dec_return(&port->count) < 0) {
44448 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44449 - info->line, port->count);
44450 - port->count = 0;
44451 + info->line, atomic_read(&port->count));
44452 + atomic_set(&port->count, 0);
44453 }
44454 - if (port->count) {
44455 + if (atomic_read(&port->count)) {
44456 #ifdef ISDN_DEBUG_MODEM_OPEN
44457 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44458 #endif
44459 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44460 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44461 return;
44462 isdn_tty_shutdown(info);
44463 - port->count = 0;
44464 + atomic_set(&port->count, 0);
44465 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44466 port->tty = NULL;
44467 wake_up_interruptible(&port->open_wait);
44468 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44469 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44470 modem_info *info = &dev->mdm.info[i];
44471
44472 - if (info->port.count == 0)
44473 + if (atomic_read(&info->port.count) == 0)
44474 continue;
44475 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44476 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44477 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44478 index e2d4e58..40cd045 100644
44479 --- a/drivers/isdn/i4l/isdn_x25iface.c
44480 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44481 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44482
44483
44484 static struct concap_proto_ops ix25_pops = {
44485 - &isdn_x25iface_proto_new,
44486 - &isdn_x25iface_proto_del,
44487 - &isdn_x25iface_proto_restart,
44488 - &isdn_x25iface_proto_close,
44489 - &isdn_x25iface_xmit,
44490 - &isdn_x25iface_receive,
44491 - &isdn_x25iface_connect_ind,
44492 - &isdn_x25iface_disconn_ind
44493 + .proto_new = &isdn_x25iface_proto_new,
44494 + .proto_del = &isdn_x25iface_proto_del,
44495 + .restart = &isdn_x25iface_proto_restart,
44496 + .close = &isdn_x25iface_proto_close,
44497 + .encap_and_xmit = &isdn_x25iface_xmit,
44498 + .data_ind = &isdn_x25iface_receive,
44499 + .connect_ind = &isdn_x25iface_connect_ind,
44500 + .disconn_ind = &isdn_x25iface_disconn_ind
44501 };
44502
44503 /* error message helper function */
44504 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44505 index 6a7447c..cae33fe 100644
44506 --- a/drivers/isdn/icn/icn.c
44507 +++ b/drivers/isdn/icn/icn.c
44508 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44509 if (count > len)
44510 count = len;
44511 if (user) {
44512 - if (copy_from_user(msg, buf, count))
44513 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44514 return -EFAULT;
44515 } else
44516 memcpy(msg, buf, count);
44517 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44518 index a4f05c5..1433bc5 100644
44519 --- a/drivers/isdn/mISDN/dsp_cmx.c
44520 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44521 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44522 static u16 dsp_count; /* last sample count */
44523 static int dsp_count_valid; /* if we have last sample count */
44524
44525 -void
44526 +void __intentional_overflow(-1)
44527 dsp_cmx_send(void *arg)
44528 {
44529 struct dsp_conf *conf;
44530 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44531 index f58a354..fbae176 100644
44532 --- a/drivers/leds/leds-clevo-mail.c
44533 +++ b/drivers/leds/leds-clevo-mail.c
44534 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44535 * detected as working, but in reality it is not) as low as
44536 * possible.
44537 */
44538 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44539 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44540 {
44541 .callback = clevo_mail_led_dmi_callback,
44542 .ident = "Clevo D410J",
44543 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44544 index 046cb70..6b20d39 100644
44545 --- a/drivers/leds/leds-ss4200.c
44546 +++ b/drivers/leds/leds-ss4200.c
44547 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44548 * detected as working, but in reality it is not) as low as
44549 * possible.
44550 */
44551 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44552 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44553 {
44554 .callback = ss4200_led_dmi_callback,
44555 .ident = "Intel SS4200-E",
44556 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44557 index 6590558..a74c5dd 100644
44558 --- a/drivers/lguest/core.c
44559 +++ b/drivers/lguest/core.c
44560 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44561 * The end address needs +1 because __get_vm_area allocates an
44562 * extra guard page, so we need space for that.
44563 */
44564 +
44565 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44566 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44567 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44568 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44569 +#else
44570 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44571 VM_ALLOC, switcher_addr, switcher_addr
44572 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44573 +#endif
44574 +
44575 if (!switcher_vma) {
44576 err = -ENOMEM;
44577 printk("lguest: could not map switcher pages high\n");
44578 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44579 * Now the Switcher is mapped at the right address, we can't fail!
44580 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44581 */
44582 - memcpy(switcher_vma->addr, start_switcher_text,
44583 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44584 end_switcher_text - start_switcher_text);
44585
44586 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44587 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44588 index e8b55c3..3514c37 100644
44589 --- a/drivers/lguest/page_tables.c
44590 +++ b/drivers/lguest/page_tables.c
44591 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44592 /*:*/
44593
44594 #ifdef CONFIG_X86_PAE
44595 -static void release_pmd(pmd_t *spmd)
44596 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44597 {
44598 /* If the entry's not present, there's nothing to release. */
44599 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44600 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44601 index 922a1ac..9dd0c2a 100644
44602 --- a/drivers/lguest/x86/core.c
44603 +++ b/drivers/lguest/x86/core.c
44604 @@ -59,7 +59,7 @@ static struct {
44605 /* Offset from where switcher.S was compiled to where we've copied it */
44606 static unsigned long switcher_offset(void)
44607 {
44608 - return switcher_addr - (unsigned long)start_switcher_text;
44609 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44610 }
44611
44612 /* This cpu's struct lguest_pages (after the Switcher text page) */
44613 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44614 * These copies are pretty cheap, so we do them unconditionally: */
44615 /* Save the current Host top-level page directory.
44616 */
44617 +
44618 +#ifdef CONFIG_PAX_PER_CPU_PGD
44619 + pages->state.host_cr3 = read_cr3();
44620 +#else
44621 pages->state.host_cr3 = __pa(current->mm->pgd);
44622 +#endif
44623 +
44624 /*
44625 * Set up the Guest's page tables to see this CPU's pages (and no
44626 * other CPU's pages).
44627 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44628 * compiled-in switcher code and the high-mapped copy we just made.
44629 */
44630 for (i = 0; i < IDT_ENTRIES; i++)
44631 - default_idt_entries[i] += switcher_offset();
44632 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44633
44634 /*
44635 * Set up the Switcher's per-cpu areas.
44636 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44637 * it will be undisturbed when we switch. To change %cs and jump we
44638 * need this structure to feed to Intel's "lcall" instruction.
44639 */
44640 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44641 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44642 lguest_entry.segment = LGUEST_CS;
44643
44644 /*
44645 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44646 index 40634b0..4f5855e 100644
44647 --- a/drivers/lguest/x86/switcher_32.S
44648 +++ b/drivers/lguest/x86/switcher_32.S
44649 @@ -87,6 +87,7 @@
44650 #include <asm/page.h>
44651 #include <asm/segment.h>
44652 #include <asm/lguest.h>
44653 +#include <asm/processor-flags.h>
44654
44655 // We mark the start of the code to copy
44656 // It's placed in .text tho it's never run here
44657 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44658 // Changes type when we load it: damn Intel!
44659 // For after we switch over our page tables
44660 // That entry will be read-only: we'd crash.
44661 +
44662 +#ifdef CONFIG_PAX_KERNEXEC
44663 + mov %cr0, %edx
44664 + xor $X86_CR0_WP, %edx
44665 + mov %edx, %cr0
44666 +#endif
44667 +
44668 movl $(GDT_ENTRY_TSS*8), %edx
44669 ltr %dx
44670
44671 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44672 // Let's clear it again for our return.
44673 // The GDT descriptor of the Host
44674 // Points to the table after two "size" bytes
44675 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44676 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44677 // Clear "used" from type field (byte 5, bit 2)
44678 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44679 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44680 +
44681 +#ifdef CONFIG_PAX_KERNEXEC
44682 + mov %cr0, %eax
44683 + xor $X86_CR0_WP, %eax
44684 + mov %eax, %cr0
44685 +#endif
44686
44687 // Once our page table's switched, the Guest is live!
44688 // The Host fades as we run this final step.
44689 @@ -295,13 +309,12 @@ deliver_to_host:
44690 // I consulted gcc, and it gave
44691 // These instructions, which I gladly credit:
44692 leal (%edx,%ebx,8), %eax
44693 - movzwl (%eax),%edx
44694 - movl 4(%eax), %eax
44695 - xorw %ax, %ax
44696 - orl %eax, %edx
44697 + movl 4(%eax), %edx
44698 + movw (%eax), %dx
44699 // Now the address of the handler's in %edx
44700 // We call it now: its "iret" drops us home.
44701 - jmp *%edx
44702 + ljmp $__KERNEL_CS, $1f
44703 +1: jmp *%edx
44704
44705 // Every interrupt can come to us here
44706 // But we must truly tell each apart.
44707 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44708 index a08e3ee..df8ade2 100644
44709 --- a/drivers/md/bcache/closure.h
44710 +++ b/drivers/md/bcache/closure.h
44711 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44712 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44713 struct workqueue_struct *wq)
44714 {
44715 - BUG_ON(object_is_on_stack(cl));
44716 + BUG_ON(object_starts_on_stack(cl));
44717 closure_set_ip(cl);
44718 cl->fn = fn;
44719 cl->wq = wq;
44720 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44721 index 67f8b31..9418f2b 100644
44722 --- a/drivers/md/bitmap.c
44723 +++ b/drivers/md/bitmap.c
44724 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44725 chunk_kb ? "KB" : "B");
44726 if (bitmap->storage.file) {
44727 seq_printf(seq, ", file: ");
44728 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44729 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44730 }
44731
44732 seq_printf(seq, "\n");
44733 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44734 index 5152142..623d141 100644
44735 --- a/drivers/md/dm-ioctl.c
44736 +++ b/drivers/md/dm-ioctl.c
44737 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44738 cmd == DM_LIST_VERSIONS_CMD)
44739 return 0;
44740
44741 - if ((cmd == DM_DEV_CREATE_CMD)) {
44742 + if (cmd == DM_DEV_CREATE_CMD) {
44743 if (!*param->name) {
44744 DMWARN("name not supplied when creating device");
44745 return -EINVAL;
44746 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44747 index 7dfdb5c..4caada6 100644
44748 --- a/drivers/md/dm-raid1.c
44749 +++ b/drivers/md/dm-raid1.c
44750 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44751
44752 struct mirror {
44753 struct mirror_set *ms;
44754 - atomic_t error_count;
44755 + atomic_unchecked_t error_count;
44756 unsigned long error_type;
44757 struct dm_dev *dev;
44758 sector_t offset;
44759 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44760 struct mirror *m;
44761
44762 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44763 - if (!atomic_read(&m->error_count))
44764 + if (!atomic_read_unchecked(&m->error_count))
44765 return m;
44766
44767 return NULL;
44768 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44769 * simple way to tell if a device has encountered
44770 * errors.
44771 */
44772 - atomic_inc(&m->error_count);
44773 + atomic_inc_unchecked(&m->error_count);
44774
44775 if (test_and_set_bit(error_type, &m->error_type))
44776 return;
44777 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44778 struct mirror *m = get_default_mirror(ms);
44779
44780 do {
44781 - if (likely(!atomic_read(&m->error_count)))
44782 + if (likely(!atomic_read_unchecked(&m->error_count)))
44783 return m;
44784
44785 if (m-- == ms->mirror)
44786 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44787 {
44788 struct mirror *default_mirror = get_default_mirror(m->ms);
44789
44790 - return !atomic_read(&default_mirror->error_count);
44791 + return !atomic_read_unchecked(&default_mirror->error_count);
44792 }
44793
44794 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44795 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44796 */
44797 if (likely(region_in_sync(ms, region, 1)))
44798 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44799 - else if (m && atomic_read(&m->error_count))
44800 + else if (m && atomic_read_unchecked(&m->error_count))
44801 m = NULL;
44802
44803 if (likely(m))
44804 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44805 }
44806
44807 ms->mirror[mirror].ms = ms;
44808 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44809 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44810 ms->mirror[mirror].error_type = 0;
44811 ms->mirror[mirror].offset = offset;
44812
44813 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44814 */
44815 static char device_status_char(struct mirror *m)
44816 {
44817 - if (!atomic_read(&(m->error_count)))
44818 + if (!atomic_read_unchecked(&(m->error_count)))
44819 return 'A';
44820
44821 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44822 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44823 index 28a9012..9c0f6a5 100644
44824 --- a/drivers/md/dm-stats.c
44825 +++ b/drivers/md/dm-stats.c
44826 @@ -382,7 +382,7 @@ do_sync_free:
44827 synchronize_rcu_expedited();
44828 dm_stat_free(&s->rcu_head);
44829 } else {
44830 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44831 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44832 call_rcu(&s->rcu_head, dm_stat_free);
44833 }
44834 return 0;
44835 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44836 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44837 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44838 ));
44839 - ACCESS_ONCE(last->last_sector) = end_sector;
44840 - ACCESS_ONCE(last->last_rw) = bi_rw;
44841 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44842 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44843 }
44844
44845 rcu_read_lock();
44846 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44847 index d1600d2..4c3af3a 100644
44848 --- a/drivers/md/dm-stripe.c
44849 +++ b/drivers/md/dm-stripe.c
44850 @@ -21,7 +21,7 @@ struct stripe {
44851 struct dm_dev *dev;
44852 sector_t physical_start;
44853
44854 - atomic_t error_count;
44855 + atomic_unchecked_t error_count;
44856 };
44857
44858 struct stripe_c {
44859 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44860 kfree(sc);
44861 return r;
44862 }
44863 - atomic_set(&(sc->stripe[i].error_count), 0);
44864 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44865 }
44866
44867 ti->private = sc;
44868 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44869 DMEMIT("%d ", sc->stripes);
44870 for (i = 0; i < sc->stripes; i++) {
44871 DMEMIT("%s ", sc->stripe[i].dev->name);
44872 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44873 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44874 'D' : 'A';
44875 }
44876 buffer[i] = '\0';
44877 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44878 */
44879 for (i = 0; i < sc->stripes; i++)
44880 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44881 - atomic_inc(&(sc->stripe[i].error_count));
44882 - if (atomic_read(&(sc->stripe[i].error_count)) <
44883 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44884 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44885 DM_IO_ERROR_THRESHOLD)
44886 schedule_work(&sc->trigger_event);
44887 }
44888 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44889 index f9c6cb8..e272df6 100644
44890 --- a/drivers/md/dm-table.c
44891 +++ b/drivers/md/dm-table.c
44892 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44893 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44894 struct mapped_device *md)
44895 {
44896 - static char *_claim_ptr = "I belong to device-mapper";
44897 + static char _claim_ptr[] = "I belong to device-mapper";
44898 struct block_device *bdev;
44899
44900 int r;
44901 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44902 if (!dev_size)
44903 return 0;
44904
44905 - if ((start >= dev_size) || (start + len > dev_size)) {
44906 + if ((start >= dev_size) || (len > dev_size - start)) {
44907 DMWARN("%s: %s too small for target: "
44908 "start=%llu, len=%llu, dev_size=%llu",
44909 dm_device_name(ti->table->md), bdevname(bdev, b),
44910 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44911 index e9d33ad..dae9880d 100644
44912 --- a/drivers/md/dm-thin-metadata.c
44913 +++ b/drivers/md/dm-thin-metadata.c
44914 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44915 {
44916 pmd->info.tm = pmd->tm;
44917 pmd->info.levels = 2;
44918 - pmd->info.value_type.context = pmd->data_sm;
44919 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44920 pmd->info.value_type.size = sizeof(__le64);
44921 pmd->info.value_type.inc = data_block_inc;
44922 pmd->info.value_type.dec = data_block_dec;
44923 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44924
44925 pmd->bl_info.tm = pmd->tm;
44926 pmd->bl_info.levels = 1;
44927 - pmd->bl_info.value_type.context = pmd->data_sm;
44928 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44929 pmd->bl_info.value_type.size = sizeof(__le64);
44930 pmd->bl_info.value_type.inc = data_block_inc;
44931 pmd->bl_info.value_type.dec = data_block_dec;
44932 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44933 index 32b958d..34011e8 100644
44934 --- a/drivers/md/dm.c
44935 +++ b/drivers/md/dm.c
44936 @@ -180,9 +180,9 @@ struct mapped_device {
44937 /*
44938 * Event handling.
44939 */
44940 - atomic_t event_nr;
44941 + atomic_unchecked_t event_nr;
44942 wait_queue_head_t eventq;
44943 - atomic_t uevent_seq;
44944 + atomic_unchecked_t uevent_seq;
44945 struct list_head uevent_list;
44946 spinlock_t uevent_lock; /* Protect access to uevent_list */
44947
44948 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
44949 spin_lock_init(&md->deferred_lock);
44950 atomic_set(&md->holders, 1);
44951 atomic_set(&md->open_count, 0);
44952 - atomic_set(&md->event_nr, 0);
44953 - atomic_set(&md->uevent_seq, 0);
44954 + atomic_set_unchecked(&md->event_nr, 0);
44955 + atomic_set_unchecked(&md->uevent_seq, 0);
44956 INIT_LIST_HEAD(&md->uevent_list);
44957 spin_lock_init(&md->uevent_lock);
44958
44959 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
44960
44961 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44962
44963 - atomic_inc(&md->event_nr);
44964 + atomic_inc_unchecked(&md->event_nr);
44965 wake_up(&md->eventq);
44966 }
44967
44968 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44969
44970 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44971 {
44972 - return atomic_add_return(1, &md->uevent_seq);
44973 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44974 }
44975
44976 uint32_t dm_get_event_nr(struct mapped_device *md)
44977 {
44978 - return atomic_read(&md->event_nr);
44979 + return atomic_read_unchecked(&md->event_nr);
44980 }
44981
44982 int dm_wait_event(struct mapped_device *md, int event_nr)
44983 {
44984 return wait_event_interruptible(md->eventq,
44985 - (event_nr != atomic_read(&md->event_nr)));
44986 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44987 }
44988
44989 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44990 diff --git a/drivers/md/md.c b/drivers/md/md.c
44991 index b7f603c..723d2bd 100644
44992 --- a/drivers/md/md.c
44993 +++ b/drivers/md/md.c
44994 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44995 * start build, activate spare
44996 */
44997 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44998 -static atomic_t md_event_count;
44999 +static atomic_unchecked_t md_event_count;
45000 void md_new_event(struct mddev *mddev)
45001 {
45002 - atomic_inc(&md_event_count);
45003 + atomic_inc_unchecked(&md_event_count);
45004 wake_up(&md_event_waiters);
45005 }
45006 EXPORT_SYMBOL_GPL(md_new_event);
45007 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45008 */
45009 static void md_new_event_inintr(struct mddev *mddev)
45010 {
45011 - atomic_inc(&md_event_count);
45012 + atomic_inc_unchecked(&md_event_count);
45013 wake_up(&md_event_waiters);
45014 }
45015
45016 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45017 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45018 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45019 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45020 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45021 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45022
45023 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45024 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45025 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45026 else
45027 sb->resync_offset = cpu_to_le64(0);
45028
45029 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45030 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45031
45032 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45033 sb->size = cpu_to_le64(mddev->dev_sectors);
45034 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45035 static ssize_t
45036 errors_show(struct md_rdev *rdev, char *page)
45037 {
45038 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45039 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45040 }
45041
45042 static ssize_t
45043 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45044 char *e;
45045 unsigned long n = simple_strtoul(buf, &e, 10);
45046 if (*buf && (*e == 0 || *e == '\n')) {
45047 - atomic_set(&rdev->corrected_errors, n);
45048 + atomic_set_unchecked(&rdev->corrected_errors, n);
45049 return len;
45050 }
45051 return -EINVAL;
45052 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45053 rdev->sb_loaded = 0;
45054 rdev->bb_page = NULL;
45055 atomic_set(&rdev->nr_pending, 0);
45056 - atomic_set(&rdev->read_errors, 0);
45057 - atomic_set(&rdev->corrected_errors, 0);
45058 + atomic_set_unchecked(&rdev->read_errors, 0);
45059 + atomic_set_unchecked(&rdev->corrected_errors, 0);
45060
45061 INIT_LIST_HEAD(&rdev->same_set);
45062 init_waitqueue_head(&rdev->blocked_wait);
45063 @@ -7072,7 +7072,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45064
45065 spin_unlock(&pers_lock);
45066 seq_printf(seq, "\n");
45067 - seq->poll_event = atomic_read(&md_event_count);
45068 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45069 return 0;
45070 }
45071 if (v == (void*)2) {
45072 @@ -7175,7 +7175,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45073 return error;
45074
45075 seq = file->private_data;
45076 - seq->poll_event = atomic_read(&md_event_count);
45077 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45078 return error;
45079 }
45080
45081 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45082 /* always allow read */
45083 mask = POLLIN | POLLRDNORM;
45084
45085 - if (seq->poll_event != atomic_read(&md_event_count))
45086 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45087 mask |= POLLERR | POLLPRI;
45088 return mask;
45089 }
45090 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45091 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45092 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45093 (int)part_stat_read(&disk->part0, sectors[1]) -
45094 - atomic_read(&disk->sync_io);
45095 + atomic_read_unchecked(&disk->sync_io);
45096 /* sync IO will cause sync_io to increase before the disk_stats
45097 * as sync_io is counted when a request starts, and
45098 * disk_stats is counted when it completes.
45099 diff --git a/drivers/md/md.h b/drivers/md/md.h
45100 index a49d991..3582bb7 100644
45101 --- a/drivers/md/md.h
45102 +++ b/drivers/md/md.h
45103 @@ -94,13 +94,13 @@ struct md_rdev {
45104 * only maintained for arrays that
45105 * support hot removal
45106 */
45107 - atomic_t read_errors; /* number of consecutive read errors that
45108 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
45109 * we have tried to ignore.
45110 */
45111 struct timespec last_read_error; /* monotonic time since our
45112 * last read error
45113 */
45114 - atomic_t corrected_errors; /* number of corrected read errors,
45115 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45116 * for reporting to userspace and storing
45117 * in superblock.
45118 */
45119 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45120
45121 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45122 {
45123 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45124 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45125 }
45126
45127 struct md_personality
45128 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45129 index 786b689..ea8c956 100644
45130 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
45131 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45132 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45133 * Flick into a mode where all blocks get allocated in the new area.
45134 */
45135 smm->begin = old_len;
45136 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
45137 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45138
45139 /*
45140 * Extend.
45141 @@ -710,7 +710,7 @@ out:
45142 /*
45143 * Switch back to normal behaviour.
45144 */
45145 - memcpy(sm, &ops, sizeof(*sm));
45146 + memcpy((void *)sm, &ops, sizeof(*sm));
45147 return r;
45148 }
45149
45150 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45151 index 3e6d115..ffecdeb 100644
45152 --- a/drivers/md/persistent-data/dm-space-map.h
45153 +++ b/drivers/md/persistent-data/dm-space-map.h
45154 @@ -71,6 +71,7 @@ struct dm_space_map {
45155 dm_sm_threshold_fn fn,
45156 void *context);
45157 };
45158 +typedef struct dm_space_map __no_const dm_space_map_no_const;
45159
45160 /*----------------------------------------------------------------*/
45161
45162 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45163 index 55de4f6..b1c57fe 100644
45164 --- a/drivers/md/raid1.c
45165 +++ b/drivers/md/raid1.c
45166 @@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45167 if (r1_sync_page_io(rdev, sect, s,
45168 bio->bi_io_vec[idx].bv_page,
45169 READ) != 0)
45170 - atomic_add(s, &rdev->corrected_errors);
45171 + atomic_add_unchecked(s, &rdev->corrected_errors);
45172 }
45173 sectors -= s;
45174 sect += s;
45175 @@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45176 !test_bit(Faulty, &rdev->flags)) {
45177 if (r1_sync_page_io(rdev, sect, s,
45178 conf->tmppage, READ)) {
45179 - atomic_add(s, &rdev->corrected_errors);
45180 + atomic_add_unchecked(s, &rdev->corrected_errors);
45181 printk(KERN_INFO
45182 "md/raid1:%s: read error corrected "
45183 "(%d sectors at %llu on %s)\n",
45184 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45185 index 6703751..187af1e 100644
45186 --- a/drivers/md/raid10.c
45187 +++ b/drivers/md/raid10.c
45188 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45189 /* The write handler will notice the lack of
45190 * R10BIO_Uptodate and record any errors etc
45191 */
45192 - atomic_add(r10_bio->sectors,
45193 + atomic_add_unchecked(r10_bio->sectors,
45194 &conf->mirrors[d].rdev->corrected_errors);
45195
45196 /* for reconstruct, we always reschedule after a read.
45197 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45198 {
45199 struct timespec cur_time_mon;
45200 unsigned long hours_since_last;
45201 - unsigned int read_errors = atomic_read(&rdev->read_errors);
45202 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45203
45204 ktime_get_ts(&cur_time_mon);
45205
45206 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45207 * overflowing the shift of read_errors by hours_since_last.
45208 */
45209 if (hours_since_last >= 8 * sizeof(read_errors))
45210 - atomic_set(&rdev->read_errors, 0);
45211 + atomic_set_unchecked(&rdev->read_errors, 0);
45212 else
45213 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45214 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45215 }
45216
45217 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45218 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45219 return;
45220
45221 check_decay_read_errors(mddev, rdev);
45222 - atomic_inc(&rdev->read_errors);
45223 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
45224 + atomic_inc_unchecked(&rdev->read_errors);
45225 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
45226 char b[BDEVNAME_SIZE];
45227 bdevname(rdev->bdev, b);
45228
45229 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45230 "md/raid10:%s: %s: Raid device exceeded "
45231 "read_error threshold [cur %d:max %d]\n",
45232 mdname(mddev), b,
45233 - atomic_read(&rdev->read_errors), max_read_errors);
45234 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
45235 printk(KERN_NOTICE
45236 "md/raid10:%s: %s: Failing raid device\n",
45237 mdname(mddev), b);
45238 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45239 sect +
45240 choose_data_offset(r10_bio, rdev)),
45241 bdevname(rdev->bdev, b));
45242 - atomic_add(s, &rdev->corrected_errors);
45243 + atomic_add_unchecked(s, &rdev->corrected_errors);
45244 }
45245
45246 rdev_dec_pending(rdev, mddev);
45247 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45248 index 9f0fbec..991e7a1 100644
45249 --- a/drivers/md/raid5.c
45250 +++ b/drivers/md/raid5.c
45251 @@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45252 return 1;
45253 }
45254
45255 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45256 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45257 +#endif
45258 +
45259 static int grow_stripes(struct r5conf *conf, int num)
45260 {
45261 struct kmem_cache *sc;
45262 @@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45263 "raid%d-%s", conf->level, mdname(conf->mddev));
45264 else
45265 sprintf(conf->cache_name[0],
45266 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45267 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45268 +#else
45269 "raid%d-%p", conf->level, conf->mddev);
45270 +#endif
45271 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45272
45273 conf->active_name = 0;
45274 @@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45275 mdname(conf->mddev), STRIPE_SECTORS,
45276 (unsigned long long)s,
45277 bdevname(rdev->bdev, b));
45278 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45279 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45280 clear_bit(R5_ReadError, &sh->dev[i].flags);
45281 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45282 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45283 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45284
45285 - if (atomic_read(&rdev->read_errors))
45286 - atomic_set(&rdev->read_errors, 0);
45287 + if (atomic_read_unchecked(&rdev->read_errors))
45288 + atomic_set_unchecked(&rdev->read_errors, 0);
45289 } else {
45290 const char *bdn = bdevname(rdev->bdev, b);
45291 int retry = 0;
45292 int set_bad = 0;
45293
45294 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45295 - atomic_inc(&rdev->read_errors);
45296 + atomic_inc_unchecked(&rdev->read_errors);
45297 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45298 printk_ratelimited(
45299 KERN_WARNING
45300 @@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45301 mdname(conf->mddev),
45302 (unsigned long long)s,
45303 bdn);
45304 - } else if (atomic_read(&rdev->read_errors)
45305 + } else if (atomic_read_unchecked(&rdev->read_errors)
45306 > conf->max_nr_stripes)
45307 printk(KERN_WARNING
45308 "md/raid:%s: Too many read errors, failing device %s.\n",
45309 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45310 index 983db75..ef9248c 100644
45311 --- a/drivers/media/dvb-core/dvbdev.c
45312 +++ b/drivers/media/dvb-core/dvbdev.c
45313 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45314 const struct dvb_device *template, void *priv, int type)
45315 {
45316 struct dvb_device *dvbdev;
45317 - struct file_operations *dvbdevfops;
45318 + file_operations_no_const *dvbdevfops;
45319 struct device *clsdev;
45320 int minor;
45321 int id;
45322 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45323 index 539f4db..cdd403b 100644
45324 --- a/drivers/media/dvb-frontends/af9033.h
45325 +++ b/drivers/media/dvb-frontends/af9033.h
45326 @@ -82,7 +82,7 @@ struct af9033_ops {
45327 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45328 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45329 int onoff);
45330 -};
45331 +} __no_const;
45332
45333
45334 #if IS_ENABLED(CONFIG_DVB_AF9033)
45335 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45336 index 9b6c3bb..baeb5c7 100644
45337 --- a/drivers/media/dvb-frontends/dib3000.h
45338 +++ b/drivers/media/dvb-frontends/dib3000.h
45339 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45340 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45341 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45342 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45343 -};
45344 +} __no_const;
45345
45346 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45347 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45348 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45349 index 1fea0e9..321ce8f 100644
45350 --- a/drivers/media/dvb-frontends/dib7000p.h
45351 +++ b/drivers/media/dvb-frontends/dib7000p.h
45352 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45353 int (*get_adc_power)(struct dvb_frontend *fe);
45354 int (*slave_reset)(struct dvb_frontend *fe);
45355 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45356 -};
45357 +} __no_const;
45358
45359 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45360 void *dib7000p_attach(struct dib7000p_ops *ops);
45361 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45362 index 84cc103..5780c54 100644
45363 --- a/drivers/media/dvb-frontends/dib8000.h
45364 +++ b/drivers/media/dvb-frontends/dib8000.h
45365 @@ -61,7 +61,7 @@ struct dib8000_ops {
45366 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45367 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45368 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45369 -};
45370 +} __no_const;
45371
45372 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45373 void *dib8000_attach(struct dib8000_ops *ops);
45374 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45375 index ed8cb90..5ef7f79 100644
45376 --- a/drivers/media/pci/cx88/cx88-video.c
45377 +++ b/drivers/media/pci/cx88/cx88-video.c
45378 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45379
45380 /* ------------------------------------------------------------------ */
45381
45382 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45383 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45384 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45385 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45386 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45387 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45388
45389 module_param_array(video_nr, int, NULL, 0444);
45390 module_param_array(vbi_nr, int, NULL, 0444);
45391 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45392 index 802642d..5534900 100644
45393 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45394 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45395 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45396 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45397
45398 /* ivtv instance counter */
45399 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45400 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45401
45402 /* Parameter declarations */
45403 static int cardtype[IVTV_MAX_CARDS];
45404 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45405 index 172583d..0f806f4 100644
45406 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45407 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45408 @@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
45409
45410 static int solo_sysfs_init(struct solo_dev *solo_dev)
45411 {
45412 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45413 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45414 struct device *dev = &solo_dev->dev;
45415 const char *driver;
45416 int i;
45417 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45418 index c7141f2..5301fec 100644
45419 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45420 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45421 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45422
45423 int solo_g723_init(struct solo_dev *solo_dev)
45424 {
45425 - static struct snd_device_ops ops = { NULL };
45426 + static struct snd_device_ops ops = { };
45427 struct snd_card *card;
45428 struct snd_kcontrol_new kctl;
45429 char name[32];
45430 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45431 index 8c84846..27b4f83 100644
45432 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45433 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45434 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45435
45436 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45437 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45438 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45439 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45440 if (p2m_id < 0)
45441 p2m_id = -p2m_id;
45442 }
45443 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45444 index c6154b0..73e4ae9 100644
45445 --- a/drivers/media/pci/solo6x10/solo6x10.h
45446 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45447 @@ -219,7 +219,7 @@ struct solo_dev {
45448
45449 /* P2M DMA Engine */
45450 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45451 - atomic_t p2m_count;
45452 + atomic_unchecked_t p2m_count;
45453 int p2m_jiffies;
45454 unsigned int p2m_timeouts;
45455
45456 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45457 index 2d177fa..5b925a1 100644
45458 --- a/drivers/media/platform/omap/omap_vout.c
45459 +++ b/drivers/media/platform/omap/omap_vout.c
45460 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45461 OMAP_VIDEO2,
45462 };
45463
45464 -static struct videobuf_queue_ops video_vbq_ops;
45465 /* Variables configurable through module params*/
45466 static u32 video1_numbuffers = 3;
45467 static u32 video2_numbuffers = 3;
45468 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
45469 {
45470 struct videobuf_queue *q;
45471 struct omap_vout_device *vout = NULL;
45472 + static struct videobuf_queue_ops video_vbq_ops = {
45473 + .buf_setup = omap_vout_buffer_setup,
45474 + .buf_prepare = omap_vout_buffer_prepare,
45475 + .buf_release = omap_vout_buffer_release,
45476 + .buf_queue = omap_vout_buffer_queue,
45477 + };
45478
45479 vout = video_drvdata(file);
45480 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45481 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
45482 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45483
45484 q = &vout->vbq;
45485 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45486 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45487 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45488 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45489 spin_lock_init(&vout->vbq_lock);
45490
45491 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45492 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45493 index fb2acc5..a2fcbdc4 100644
45494 --- a/drivers/media/platform/s5p-tv/mixer.h
45495 +++ b/drivers/media/platform/s5p-tv/mixer.h
45496 @@ -156,7 +156,7 @@ struct mxr_layer {
45497 /** layer index (unique identifier) */
45498 int idx;
45499 /** callbacks for layer methods */
45500 - struct mxr_layer_ops ops;
45501 + struct mxr_layer_ops *ops;
45502 /** format array */
45503 const struct mxr_format **fmt_array;
45504 /** size of format array */
45505 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45506 index 74344c7..a39e70e 100644
45507 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45508 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45509 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45510 {
45511 struct mxr_layer *layer;
45512 int ret;
45513 - struct mxr_layer_ops ops = {
45514 + static struct mxr_layer_ops ops = {
45515 .release = mxr_graph_layer_release,
45516 .buffer_set = mxr_graph_buffer_set,
45517 .stream_set = mxr_graph_stream_set,
45518 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45519 index b713403..53cb5ad 100644
45520 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45521 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45522 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45523 layer->update_buf = next;
45524 }
45525
45526 - layer->ops.buffer_set(layer, layer->update_buf);
45527 + layer->ops->buffer_set(layer, layer->update_buf);
45528
45529 if (done && done != layer->shadow_buf)
45530 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45531 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45532 index b4d2696..91df48e 100644
45533 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45534 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45535 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45536 layer->geo.src.height = layer->geo.src.full_height;
45537
45538 mxr_geometry_dump(mdev, &layer->geo);
45539 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45540 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45541 mxr_geometry_dump(mdev, &layer->geo);
45542 }
45543
45544 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45545 layer->geo.dst.full_width = mbus_fmt.width;
45546 layer->geo.dst.full_height = mbus_fmt.height;
45547 layer->geo.dst.field = mbus_fmt.field;
45548 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45549 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45550
45551 mxr_geometry_dump(mdev, &layer->geo);
45552 }
45553 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45554 /* set source size to highest accepted value */
45555 geo->src.full_width = max(geo->dst.full_width, pix->width);
45556 geo->src.full_height = max(geo->dst.full_height, pix->height);
45557 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45558 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45559 mxr_geometry_dump(mdev, &layer->geo);
45560 /* set cropping to total visible screen */
45561 geo->src.width = pix->width;
45562 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45563 geo->src.x_offset = 0;
45564 geo->src.y_offset = 0;
45565 /* assure consistency of geometry */
45566 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45567 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45568 mxr_geometry_dump(mdev, &layer->geo);
45569 /* set full size to lowest possible value */
45570 geo->src.full_width = 0;
45571 geo->src.full_height = 0;
45572 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45573 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45574 mxr_geometry_dump(mdev, &layer->geo);
45575
45576 /* returning results */
45577 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45578 target->width = s->r.width;
45579 target->height = s->r.height;
45580
45581 - layer->ops.fix_geometry(layer, stage, s->flags);
45582 + layer->ops->fix_geometry(layer, stage, s->flags);
45583
45584 /* retrieve update selection rectangle */
45585 res.left = target->x_offset;
45586 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45587 mxr_output_get(mdev);
45588
45589 mxr_layer_update_output(layer);
45590 - layer->ops.format_set(layer);
45591 + layer->ops->format_set(layer);
45592 /* enabling layer in hardware */
45593 spin_lock_irqsave(&layer->enq_slock, flags);
45594 layer->state = MXR_LAYER_STREAMING;
45595 spin_unlock_irqrestore(&layer->enq_slock, flags);
45596
45597 - layer->ops.stream_set(layer, MXR_ENABLE);
45598 + layer->ops->stream_set(layer, MXR_ENABLE);
45599 mxr_streamer_get(mdev);
45600
45601 return 0;
45602 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45603 spin_unlock_irqrestore(&layer->enq_slock, flags);
45604
45605 /* disabling layer in hardware */
45606 - layer->ops.stream_set(layer, MXR_DISABLE);
45607 + layer->ops->stream_set(layer, MXR_DISABLE);
45608 /* remove one streamer */
45609 mxr_streamer_put(mdev);
45610 /* allow changes in output configuration */
45611 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45612
45613 void mxr_layer_release(struct mxr_layer *layer)
45614 {
45615 - if (layer->ops.release)
45616 - layer->ops.release(layer);
45617 + if (layer->ops->release)
45618 + layer->ops->release(layer);
45619 }
45620
45621 void mxr_base_layer_release(struct mxr_layer *layer)
45622 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45623
45624 layer->mdev = mdev;
45625 layer->idx = idx;
45626 - layer->ops = *ops;
45627 + layer->ops = ops;
45628
45629 spin_lock_init(&layer->enq_slock);
45630 INIT_LIST_HEAD(&layer->enq_list);
45631 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45632 index c9388c4..ce71ece 100644
45633 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45634 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45635 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45636 {
45637 struct mxr_layer *layer;
45638 int ret;
45639 - struct mxr_layer_ops ops = {
45640 + static struct mxr_layer_ops ops = {
45641 .release = mxr_vp_layer_release,
45642 .buffer_set = mxr_vp_buffer_set,
45643 .stream_set = mxr_vp_stream_set,
45644 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45645 index 8033371..de5bca0 100644
45646 --- a/drivers/media/platform/vivi.c
45647 +++ b/drivers/media/platform/vivi.c
45648 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45649 MODULE_LICENSE("Dual BSD/GPL");
45650 MODULE_VERSION(VIVI_VERSION);
45651
45652 -static unsigned video_nr = -1;
45653 -module_param(video_nr, uint, 0644);
45654 +static int video_nr = -1;
45655 +module_param(video_nr, int, 0644);
45656 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45657
45658 static unsigned n_devs = 1;
45659 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45660 index 82affae..42833ec 100644
45661 --- a/drivers/media/radio/radio-cadet.c
45662 +++ b/drivers/media/radio/radio-cadet.c
45663 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45664 unsigned char readbuf[RDS_BUFFER];
45665 int i = 0;
45666
45667 + if (count > RDS_BUFFER)
45668 + return -EFAULT;
45669 mutex_lock(&dev->lock);
45670 if (dev->rdsstat == 0)
45671 cadet_start_rds(dev);
45672 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45673 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45674 mutex_unlock(&dev->lock);
45675
45676 - if (i && copy_to_user(data, readbuf, i))
45677 - return -EFAULT;
45678 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45679 + i = -EFAULT;
45680 +
45681 return i;
45682 }
45683
45684 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45685 index 5236035..c622c74 100644
45686 --- a/drivers/media/radio/radio-maxiradio.c
45687 +++ b/drivers/media/radio/radio-maxiradio.c
45688 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45689 /* TEA5757 pin mappings */
45690 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45691
45692 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45693 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45694
45695 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45696 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45697 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45698 index 050b3bb..79f62b9 100644
45699 --- a/drivers/media/radio/radio-shark.c
45700 +++ b/drivers/media/radio/radio-shark.c
45701 @@ -79,7 +79,7 @@ struct shark_device {
45702 u32 last_val;
45703 };
45704
45705 -static atomic_t shark_instance = ATOMIC_INIT(0);
45706 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45707
45708 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45709 {
45710 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45711 index 8654e0d..0608a64 100644
45712 --- a/drivers/media/radio/radio-shark2.c
45713 +++ b/drivers/media/radio/radio-shark2.c
45714 @@ -74,7 +74,7 @@ struct shark_device {
45715 u8 *transfer_buffer;
45716 };
45717
45718 -static atomic_t shark_instance = ATOMIC_INIT(0);
45719 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45720
45721 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45722 {
45723 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45724 index 633022b..7f10754 100644
45725 --- a/drivers/media/radio/radio-si476x.c
45726 +++ b/drivers/media/radio/radio-si476x.c
45727 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45728 struct si476x_radio *radio;
45729 struct v4l2_ctrl *ctrl;
45730
45731 - static atomic_t instance = ATOMIC_INIT(0);
45732 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45733
45734 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45735 if (!radio)
45736 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45737 index 9fd1527..8927230 100644
45738 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45739 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45740 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45741
45742 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45743 {
45744 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45745 - char result[64];
45746 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45747 - sizeof(result), 0);
45748 + char *buf;
45749 + char *result;
45750 + int retval;
45751 +
45752 + buf = kmalloc(2, GFP_KERNEL);
45753 + if (buf == NULL)
45754 + return -ENOMEM;
45755 + result = kmalloc(64, GFP_KERNEL);
45756 + if (result == NULL) {
45757 + kfree(buf);
45758 + return -ENOMEM;
45759 + }
45760 +
45761 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45762 + buf[1] = enable ? 1 : 0;
45763 +
45764 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45765 +
45766 + kfree(buf);
45767 + kfree(result);
45768 + return retval;
45769 }
45770
45771 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45772 {
45773 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45774 - char state[3];
45775 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45776 + char *buf;
45777 + char *state;
45778 + int retval;
45779 +
45780 + buf = kmalloc(2, GFP_KERNEL);
45781 + if (buf == NULL)
45782 + return -ENOMEM;
45783 + state = kmalloc(3, GFP_KERNEL);
45784 + if (state == NULL) {
45785 + kfree(buf);
45786 + return -ENOMEM;
45787 + }
45788 +
45789 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45790 + buf[1] = enable ? 1 : 0;
45791 +
45792 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45793 +
45794 + kfree(buf);
45795 + kfree(state);
45796 + return retval;
45797 }
45798
45799 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45800 {
45801 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45802 - char state[3];
45803 + char *query;
45804 + char *state;
45805 int ret;
45806 + query = kmalloc(1, GFP_KERNEL);
45807 + if (query == NULL)
45808 + return -ENOMEM;
45809 + state = kmalloc(3, GFP_KERNEL);
45810 + if (state == NULL) {
45811 + kfree(query);
45812 + return -ENOMEM;
45813 + }
45814 +
45815 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45816
45817 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45818
45819 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45820 - sizeof(state), 0);
45821 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45822 if (ret < 0) {
45823 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45824 "state info\n");
45825 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45826
45827 /* Copy this pointer as we are gonna need it in the release phase */
45828 cinergyt2_usb_device = adap->dev;
45829 -
45830 + kfree(query);
45831 + kfree(state);
45832 return 0;
45833 }
45834
45835 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45836 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45837 {
45838 struct cinergyt2_state *st = d->priv;
45839 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45840 + u8 *key, *cmd;
45841 int i;
45842
45843 + cmd = kmalloc(1, GFP_KERNEL);
45844 + if (cmd == NULL)
45845 + return -EINVAL;
45846 + key = kzalloc(5, GFP_KERNEL);
45847 + if (key == NULL) {
45848 + kfree(cmd);
45849 + return -EINVAL;
45850 + }
45851 +
45852 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45853 +
45854 *state = REMOTE_NO_KEY_PRESSED;
45855
45856 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45857 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45858 if (key[4] == 0xff) {
45859 /* key repeat */
45860 st->rc_counter++;
45861 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45862 *event = d->last_event;
45863 deb_rc("repeat key, event %x\n",
45864 *event);
45865 - return 0;
45866 + goto out;
45867 }
45868 }
45869 deb_rc("repeated key (non repeatable)\n");
45870 }
45871 - return 0;
45872 + goto out;
45873 }
45874
45875 /* hack to pass checksum on the custom field */
45876 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45877
45878 deb_rc("key: %*ph\n", 5, key);
45879 }
45880 +out:
45881 + kfree(cmd);
45882 + kfree(key);
45883 return 0;
45884 }
45885
45886 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45887 index c890fe4..f9b2ae6 100644
45888 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45889 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45890 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45891 fe_status_t *status)
45892 {
45893 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45894 - struct dvbt_get_status_msg result;
45895 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45896 + struct dvbt_get_status_msg *result;
45897 + u8 *cmd;
45898 int ret;
45899
45900 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45901 - sizeof(result), 0);
45902 + cmd = kmalloc(1, GFP_KERNEL);
45903 + if (cmd == NULL)
45904 + return -ENOMEM;
45905 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45906 + if (result == NULL) {
45907 + kfree(cmd);
45908 + return -ENOMEM;
45909 + }
45910 +
45911 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45912 +
45913 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45914 + sizeof(*result), 0);
45915 if (ret < 0)
45916 - return ret;
45917 + goto out;
45918
45919 *status = 0;
45920
45921 - if (0xffff - le16_to_cpu(result.gain) > 30)
45922 + if (0xffff - le16_to_cpu(result->gain) > 30)
45923 *status |= FE_HAS_SIGNAL;
45924 - if (result.lock_bits & (1 << 6))
45925 + if (result->lock_bits & (1 << 6))
45926 *status |= FE_HAS_LOCK;
45927 - if (result.lock_bits & (1 << 5))
45928 + if (result->lock_bits & (1 << 5))
45929 *status |= FE_HAS_SYNC;
45930 - if (result.lock_bits & (1 << 4))
45931 + if (result->lock_bits & (1 << 4))
45932 *status |= FE_HAS_CARRIER;
45933 - if (result.lock_bits & (1 << 1))
45934 + if (result->lock_bits & (1 << 1))
45935 *status |= FE_HAS_VITERBI;
45936
45937 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45938 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45939 *status &= ~FE_HAS_LOCK;
45940
45941 - return 0;
45942 +out:
45943 + kfree(cmd);
45944 + kfree(result);
45945 + return ret;
45946 }
45947
45948 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45949 {
45950 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45951 - struct dvbt_get_status_msg status;
45952 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45953 + struct dvbt_get_status_msg *status;
45954 + char *cmd;
45955 int ret;
45956
45957 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45958 - sizeof(status), 0);
45959 + cmd = kmalloc(1, GFP_KERNEL);
45960 + if (cmd == NULL)
45961 + return -ENOMEM;
45962 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45963 + if (status == NULL) {
45964 + kfree(cmd);
45965 + return -ENOMEM;
45966 + }
45967 +
45968 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45969 +
45970 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45971 + sizeof(*status), 0);
45972 if (ret < 0)
45973 - return ret;
45974 + goto out;
45975
45976 - *ber = le32_to_cpu(status.viterbi_error_rate);
45977 + *ber = le32_to_cpu(status->viterbi_error_rate);
45978 +out:
45979 + kfree(cmd);
45980 + kfree(status);
45981 return 0;
45982 }
45983
45984 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45985 {
45986 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45987 - struct dvbt_get_status_msg status;
45988 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45989 + struct dvbt_get_status_msg *status;
45990 + u8 *cmd;
45991 int ret;
45992
45993 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45994 - sizeof(status), 0);
45995 + cmd = kmalloc(1, GFP_KERNEL);
45996 + if (cmd == NULL)
45997 + return -ENOMEM;
45998 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45999 + if (status == NULL) {
46000 + kfree(cmd);
46001 + return -ENOMEM;
46002 + }
46003 +
46004 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46005 +
46006 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46007 + sizeof(*status), 0);
46008 if (ret < 0) {
46009 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46010 ret);
46011 - return ret;
46012 + goto out;
46013 }
46014 - *unc = le32_to_cpu(status.uncorrected_block_count);
46015 - return 0;
46016 + *unc = le32_to_cpu(status->uncorrected_block_count);
46017 +
46018 +out:
46019 + kfree(cmd);
46020 + kfree(status);
46021 + return ret;
46022 }
46023
46024 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46025 u16 *strength)
46026 {
46027 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46028 - struct dvbt_get_status_msg status;
46029 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46030 + struct dvbt_get_status_msg *status;
46031 + char *cmd;
46032 int ret;
46033
46034 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46035 - sizeof(status), 0);
46036 + cmd = kmalloc(1, GFP_KERNEL);
46037 + if (cmd == NULL)
46038 + return -ENOMEM;
46039 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46040 + if (status == NULL) {
46041 + kfree(cmd);
46042 + return -ENOMEM;
46043 + }
46044 +
46045 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46046 +
46047 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46048 + sizeof(*status), 0);
46049 if (ret < 0) {
46050 err("cinergyt2_fe_read_signal_strength() Failed!"
46051 " (Error=%d)\n", ret);
46052 - return ret;
46053 + goto out;
46054 }
46055 - *strength = (0xffff - le16_to_cpu(status.gain));
46056 + *strength = (0xffff - le16_to_cpu(status->gain));
46057 +
46058 +out:
46059 + kfree(cmd);
46060 + kfree(status);
46061 return 0;
46062 }
46063
46064 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46065 {
46066 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46067 - struct dvbt_get_status_msg status;
46068 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46069 + struct dvbt_get_status_msg *status;
46070 + char *cmd;
46071 int ret;
46072
46073 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46074 - sizeof(status), 0);
46075 + cmd = kmalloc(1, GFP_KERNEL);
46076 + if (cmd == NULL)
46077 + return -ENOMEM;
46078 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46079 + if (status == NULL) {
46080 + kfree(cmd);
46081 + return -ENOMEM;
46082 + }
46083 +
46084 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46085 +
46086 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46087 + sizeof(*status), 0);
46088 if (ret < 0) {
46089 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46090 - return ret;
46091 + goto out;
46092 }
46093 - *snr = (status.snr << 8) | status.snr;
46094 - return 0;
46095 + *snr = (status->snr << 8) | status->snr;
46096 +
46097 +out:
46098 + kfree(cmd);
46099 + kfree(status);
46100 + return ret;
46101 }
46102
46103 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46104 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46105 {
46106 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46107 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46108 - struct dvbt_set_parameters_msg param;
46109 - char result[2];
46110 + struct dvbt_set_parameters_msg *param;
46111 + char *result;
46112 int err;
46113
46114 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46115 - param.tps = cpu_to_le16(compute_tps(fep));
46116 - param.freq = cpu_to_le32(fep->frequency / 1000);
46117 - param.flags = 0;
46118 + result = kmalloc(2, GFP_KERNEL);
46119 + if (result == NULL)
46120 + return -ENOMEM;
46121 + param = kmalloc(sizeof(*param), GFP_KERNEL);
46122 + if (param == NULL) {
46123 + kfree(result);
46124 + return -ENOMEM;
46125 + }
46126 +
46127 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46128 + param->tps = cpu_to_le16(compute_tps(fep));
46129 + param->freq = cpu_to_le32(fep->frequency / 1000);
46130 + param->flags = 0;
46131
46132 switch (fep->bandwidth_hz) {
46133 default:
46134 case 8000000:
46135 - param.bandwidth = 8;
46136 + param->bandwidth = 8;
46137 break;
46138 case 7000000:
46139 - param.bandwidth = 7;
46140 + param->bandwidth = 7;
46141 break;
46142 case 6000000:
46143 - param.bandwidth = 6;
46144 + param->bandwidth = 6;
46145 break;
46146 }
46147
46148 err = dvb_usb_generic_rw(state->d,
46149 - (char *)&param, sizeof(param),
46150 - result, sizeof(result), 0);
46151 + (char *)param, sizeof(*param),
46152 + result, 2, 0);
46153 if (err < 0)
46154 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46155
46156 - return (err < 0) ? err : 0;
46157 + kfree(result);
46158 + kfree(param);
46159 + return err;
46160 }
46161
46162 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46163 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46164 index 733a7ff..f8b52e3 100644
46165 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46166 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46167 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46168
46169 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46170 {
46171 - struct hexline hx;
46172 - u8 reset;
46173 + struct hexline *hx;
46174 + u8 *reset;
46175 int ret,pos=0;
46176
46177 + reset = kmalloc(1, GFP_KERNEL);
46178 + if (reset == NULL)
46179 + return -ENOMEM;
46180 +
46181 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46182 + if (hx == NULL) {
46183 + kfree(reset);
46184 + return -ENOMEM;
46185 + }
46186 +
46187 /* stop the CPU */
46188 - reset = 1;
46189 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46190 + reset[0] = 1;
46191 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46192 err("could not stop the USB controller CPU.");
46193
46194 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46195 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46196 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46197 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46198 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46199 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46200
46201 - if (ret != hx.len) {
46202 + if (ret != hx->len) {
46203 err("error while transferring firmware "
46204 "(transferred size: %d, block size: %d)",
46205 - ret,hx.len);
46206 + ret,hx->len);
46207 ret = -EINVAL;
46208 break;
46209 }
46210 }
46211 if (ret < 0) {
46212 err("firmware download failed at %d with %d",pos,ret);
46213 + kfree(reset);
46214 + kfree(hx);
46215 return ret;
46216 }
46217
46218 if (ret == 0) {
46219 /* restart the CPU */
46220 - reset = 0;
46221 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46222 + reset[0] = 0;
46223 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46224 err("could not restart the USB controller CPU.");
46225 ret = -EINVAL;
46226 }
46227 } else
46228 ret = -EIO;
46229
46230 + kfree(reset);
46231 + kfree(hx);
46232 +
46233 return ret;
46234 }
46235 EXPORT_SYMBOL(usb_cypress_load_firmware);
46236 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46237 index 2add8c5..c33b854 100644
46238 --- a/drivers/media/usb/dvb-usb/dw2102.c
46239 +++ b/drivers/media/usb/dvb-usb/dw2102.c
46240 @@ -118,7 +118,7 @@ struct su3000_state {
46241
46242 struct s6x0_state {
46243 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46244 -};
46245 +} __no_const;
46246
46247 /* debug */
46248 static int dvb_usb_dw2102_debug;
46249 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46250 index 6b0b8b6b..4038398 100644
46251 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46252 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46253 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46254 static int technisat_usb2_i2c_access(struct usb_device *udev,
46255 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46256 {
46257 - u8 b[64];
46258 - int ret, actual_length;
46259 + u8 *b = kmalloc(64, GFP_KERNEL);
46260 + int ret, actual_length, error = 0;
46261 +
46262 + if (b == NULL)
46263 + return -ENOMEM;
46264
46265 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46266 debug_dump(tx, txlen, deb_i2c);
46267 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46268
46269 if (ret < 0) {
46270 err("i2c-error: out failed %02x = %d", device_addr, ret);
46271 - return -ENODEV;
46272 + error = -ENODEV;
46273 + goto out;
46274 }
46275
46276 ret = usb_bulk_msg(udev,
46277 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46278 b, 64, &actual_length, 1000);
46279 if (ret < 0) {
46280 err("i2c-error: in failed %02x = %d", device_addr, ret);
46281 - return -ENODEV;
46282 + error = -ENODEV;
46283 + goto out;
46284 }
46285
46286 if (b[0] != I2C_STATUS_OK) {
46287 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46288 /* handle tuner-i2c-nak */
46289 if (!(b[0] == I2C_STATUS_NAK &&
46290 device_addr == 0x60
46291 - /* && device_is_technisat_usb2 */))
46292 - return -ENODEV;
46293 + /* && device_is_technisat_usb2 */)) {
46294 + error = -ENODEV;
46295 + goto out;
46296 + }
46297 }
46298
46299 deb_i2c("status: %d, ", b[0]);
46300 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46301
46302 deb_i2c("\n");
46303
46304 - return 0;
46305 +out:
46306 + kfree(b);
46307 + return error;
46308 }
46309
46310 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46311 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46312 {
46313 int ret;
46314
46315 - u8 led[8] = {
46316 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46317 - 0
46318 - };
46319 + u8 *led = kzalloc(8, GFP_KERNEL);
46320 +
46321 + if (led == NULL)
46322 + return -ENOMEM;
46323
46324 if (disable_led_control && state != TECH_LED_OFF)
46325 return 0;
46326
46327 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46328 +
46329 switch (state) {
46330 case TECH_LED_ON:
46331 led[1] = 0x82;
46332 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46333 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46334 USB_TYPE_VENDOR | USB_DIR_OUT,
46335 0, 0,
46336 - led, sizeof(led), 500);
46337 + led, 8, 500);
46338
46339 mutex_unlock(&d->i2c_mutex);
46340 +
46341 + kfree(led);
46342 +
46343 return ret;
46344 }
46345
46346 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46347 {
46348 int ret;
46349 - u8 b = 0;
46350 + u8 *b = kzalloc(1, GFP_KERNEL);
46351 +
46352 + if (b == NULL)
46353 + return -ENOMEM;
46354
46355 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46356 return -EAGAIN;
46357 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46358 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46359 USB_TYPE_VENDOR | USB_DIR_OUT,
46360 (red << 8) | green, 0,
46361 - &b, 1, 500);
46362 + b, 1, 500);
46363
46364 mutex_unlock(&d->i2c_mutex);
46365
46366 + kfree(b);
46367 +
46368 return ret;
46369 }
46370
46371 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46372 struct dvb_usb_device_description **desc, int *cold)
46373 {
46374 int ret;
46375 - u8 version[3];
46376 + u8 *version = kmalloc(3, GFP_KERNEL);
46377
46378 /* first select the interface */
46379 if (usb_set_interface(udev, 0, 1) != 0)
46380 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46381
46382 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46383
46384 + if (version == NULL)
46385 + return 0;
46386 +
46387 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46388 GET_VERSION_INFO_VENDOR_REQUEST,
46389 USB_TYPE_VENDOR | USB_DIR_IN,
46390 0, 0,
46391 - version, sizeof(version), 500);
46392 + version, 3, 500);
46393
46394 if (ret < 0)
46395 *cold = 1;
46396 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46397 *cold = 0;
46398 }
46399
46400 + kfree(version);
46401 +
46402 return 0;
46403 }
46404
46405 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46406
46407 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46408 {
46409 - u8 buf[62], *b;
46410 + u8 *buf, *b;
46411 int ret;
46412 struct ir_raw_event ev;
46413
46414 + buf = kmalloc(62, GFP_KERNEL);
46415 +
46416 + if (buf == NULL)
46417 + return -ENOMEM;
46418 +
46419 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46420 buf[1] = 0x08;
46421 buf[2] = 0x8f;
46422 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46423 GET_IR_DATA_VENDOR_REQUEST,
46424 USB_TYPE_VENDOR | USB_DIR_IN,
46425 0x8080, 0,
46426 - buf, sizeof(buf), 500);
46427 + buf, 62, 500);
46428
46429 unlock:
46430 mutex_unlock(&d->i2c_mutex);
46431
46432 - if (ret < 0)
46433 + if (ret < 0) {
46434 + kfree(buf);
46435 return ret;
46436 + }
46437
46438 - if (ret == 1)
46439 + if (ret == 1) {
46440 + kfree(buf);
46441 return 0; /* no key pressed */
46442 + }
46443
46444 /* decoding */
46445 b = buf+1;
46446 @@ -653,6 +686,8 @@ unlock:
46447
46448 ir_raw_event_handle(d->rc_dev);
46449
46450 + kfree(buf);
46451 +
46452 return 1;
46453 }
46454
46455 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46456 index cca6c2f..77b9a18 100644
46457 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46458 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46459 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
46460 __u32 reserved;
46461 };
46462
46463 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46464 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46465 enum v4l2_memory memory)
46466 {
46467 void __user *up_pln;
46468 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46469 return 0;
46470 }
46471
46472 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46473 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46474 enum v4l2_memory memory)
46475 {
46476 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
46477 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46478 * by passing a very big num_planes value */
46479 uplane = compat_alloc_user_space(num_planes *
46480 sizeof(struct v4l2_plane));
46481 - kp->m.planes = uplane;
46482 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
46483
46484 while (--num_planes >= 0) {
46485 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46486 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46487 if (num_planes == 0)
46488 return 0;
46489
46490 - uplane = kp->m.planes;
46491 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46492 if (get_user(p, &up->m.planes))
46493 return -EFAULT;
46494 uplane32 = compat_ptr(p);
46495 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46496 get_user(kp->flags, &up->flags) ||
46497 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46498 return -EFAULT;
46499 - kp->base = compat_ptr(tmp);
46500 + kp->base = (void __force_kernel *)compat_ptr(tmp);
46501 return 0;
46502 }
46503
46504 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46505 n * sizeof(struct v4l2_ext_control32)))
46506 return -EFAULT;
46507 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46508 - kp->controls = kcontrols;
46509 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
46510 while (--n >= 0) {
46511 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
46512 return -EFAULT;
46513 @@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46514 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
46515 {
46516 struct v4l2_ext_control32 __user *ucontrols;
46517 - struct v4l2_ext_control __user *kcontrols = kp->controls;
46518 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
46519 int n = kp->count;
46520 compat_caddr_t p;
46521
46522 @@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46523 put_user(kp->start_block, &up->start_block) ||
46524 put_user(kp->blocks, &up->blocks) ||
46525 put_user(tmp, &up->edid) ||
46526 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46527 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
46528 return -EFAULT;
46529 return 0;
46530 }
46531 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46532 index 015f92a..59e311e 100644
46533 --- a/drivers/media/v4l2-core/v4l2-device.c
46534 +++ b/drivers/media/v4l2-core/v4l2-device.c
46535 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46536 EXPORT_SYMBOL_GPL(v4l2_device_put);
46537
46538 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46539 - atomic_t *instance)
46540 + atomic_unchecked_t *instance)
46541 {
46542 - int num = atomic_inc_return(instance) - 1;
46543 + int num = atomic_inc_return_unchecked(instance) - 1;
46544 int len = strlen(basename);
46545
46546 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46547 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46548 index d15e167..337f374 100644
46549 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46550 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46551 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46552 struct file *file, void *fh, void *p);
46553 } u;
46554 void (*debug)(const void *arg, bool write_only);
46555 -};
46556 +} __do_const;
46557 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46558
46559 /* This control needs a priority check */
46560 #define INFO_FL_PRIO (1 << 0)
46561 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46562 struct video_device *vfd = video_devdata(file);
46563 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46564 bool write_only = false;
46565 - struct v4l2_ioctl_info default_info;
46566 + v4l2_ioctl_info_no_const default_info;
46567 const struct v4l2_ioctl_info *info;
46568 void *fh = file->private_data;
46569 struct v4l2_fh *vfh = NULL;
46570 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46571 ret = -EINVAL;
46572 break;
46573 }
46574 - *user_ptr = (void __user *)buf->m.planes;
46575 + *user_ptr = (void __force_user *)buf->m.planes;
46576 *kernel_ptr = (void **)&buf->m.planes;
46577 *array_size = sizeof(struct v4l2_plane) * buf->length;
46578 ret = 1;
46579 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46580 ret = -EINVAL;
46581 break;
46582 }
46583 - *user_ptr = (void __user *)edid->edid;
46584 + *user_ptr = (void __force_user *)edid->edid;
46585 *kernel_ptr = (void **)&edid->edid;
46586 *array_size = edid->blocks * 128;
46587 ret = 1;
46588 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46589 ret = -EINVAL;
46590 break;
46591 }
46592 - *user_ptr = (void __user *)ctrls->controls;
46593 + *user_ptr = (void __force_user *)ctrls->controls;
46594 *kernel_ptr = (void **)&ctrls->controls;
46595 *array_size = sizeof(struct v4l2_ext_control)
46596 * ctrls->count;
46597 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46598 }
46599
46600 if (has_array_args) {
46601 - *kernel_ptr = (void __force *)user_ptr;
46602 + *kernel_ptr = (void __force_kernel *)user_ptr;
46603 if (copy_to_user(user_ptr, mbuf, array_size))
46604 err = -EFAULT;
46605 goto out_array_args;
46606 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46607 index a896d94..a5d56b1 100644
46608 --- a/drivers/message/fusion/mptbase.c
46609 +++ b/drivers/message/fusion/mptbase.c
46610 @@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46611 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46612 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46613
46614 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46615 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46616 +#else
46617 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46618 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46619 +#endif
46620 +
46621 /*
46622 * Rounding UP to nearest 4-kB boundary here...
46623 */
46624 @@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46625 ioc->facts.GlobalCredits);
46626
46627 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46628 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46629 + NULL, NULL);
46630 +#else
46631 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46632 +#endif
46633 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46634 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46635 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46636 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46637 index 0707fa2..70ca794 100644
46638 --- a/drivers/message/fusion/mptsas.c
46639 +++ b/drivers/message/fusion/mptsas.c
46640 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46641 return 0;
46642 }
46643
46644 +static inline void
46645 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46646 +{
46647 + if (phy_info->port_details) {
46648 + phy_info->port_details->rphy = rphy;
46649 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46650 + ioc->name, rphy));
46651 + }
46652 +
46653 + if (rphy) {
46654 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46655 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46656 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46657 + ioc->name, rphy, rphy->dev.release));
46658 + }
46659 +}
46660 +
46661 /* no mutex */
46662 static void
46663 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46664 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46665 return NULL;
46666 }
46667
46668 -static inline void
46669 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46670 -{
46671 - if (phy_info->port_details) {
46672 - phy_info->port_details->rphy = rphy;
46673 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46674 - ioc->name, rphy));
46675 - }
46676 -
46677 - if (rphy) {
46678 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46679 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46680 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46681 - ioc->name, rphy, rphy->dev.release));
46682 - }
46683 -}
46684 -
46685 static inline struct sas_port *
46686 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46687 {
46688 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46689 index b7d87cd..3fb36da 100644
46690 --- a/drivers/message/i2o/i2o_proc.c
46691 +++ b/drivers/message/i2o/i2o_proc.c
46692 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46693 "Array Controller Device"
46694 };
46695
46696 -static char *chtostr(char *tmp, u8 *chars, int n)
46697 -{
46698 - tmp[0] = 0;
46699 - return strncat(tmp, (char *)chars, n);
46700 -}
46701 -
46702 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46703 char *group)
46704 {
46705 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46706 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46707 {
46708 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46709 - static u32 work32[5];
46710 - static u8 *work8 = (u8 *) work32;
46711 - static u16 *work16 = (u16 *) work32;
46712 + u32 work32[5];
46713 + u8 *work8 = (u8 *) work32;
46714 + u16 *work16 = (u16 *) work32;
46715 int token;
46716 u32 hwcap;
46717
46718 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46719 } *result;
46720
46721 i2o_exec_execute_ddm_table ddm_table;
46722 - char tmp[28 + 1];
46723
46724 result = kmalloc(sizeof(*result), GFP_KERNEL);
46725 if (!result)
46726 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46727
46728 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46729 seq_printf(seq, "%-#8x", ddm_table.module_id);
46730 - seq_printf(seq, "%-29s",
46731 - chtostr(tmp, ddm_table.module_name_version, 28));
46732 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46733 seq_printf(seq, "%9d ", ddm_table.data_size);
46734 seq_printf(seq, "%8d", ddm_table.code_size);
46735
46736 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46737
46738 i2o_driver_result_table *result;
46739 i2o_driver_store_table *dst;
46740 - char tmp[28 + 1];
46741
46742 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46743 if (result == NULL)
46744 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46745
46746 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46747 seq_printf(seq, "%-#8x", dst->module_id);
46748 - seq_printf(seq, "%-29s",
46749 - chtostr(tmp, dst->module_name_version, 28));
46750 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46751 + seq_printf(seq, "%-.28s", dst->module_name_version);
46752 + seq_printf(seq, "%-.8s", dst->date);
46753 seq_printf(seq, "%8d ", dst->module_size);
46754 seq_printf(seq, "%8d ", dst->mpb_size);
46755 seq_printf(seq, "0x%04x", dst->module_flags);
46756 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46757 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46758 {
46759 struct i2o_device *d = (struct i2o_device *)seq->private;
46760 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46761 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46762 // == (allow) 512d bytes (max)
46763 - static u16 *work16 = (u16 *) work32;
46764 + u16 *work16 = (u16 *) work32;
46765 int token;
46766 - char tmp[16 + 1];
46767
46768 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46769
46770 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46771 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46772 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46773 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46774 - seq_printf(seq, "Vendor info : %s\n",
46775 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46776 - seq_printf(seq, "Product info : %s\n",
46777 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46778 - seq_printf(seq, "Description : %s\n",
46779 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46780 - seq_printf(seq, "Product rev. : %s\n",
46781 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46782 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46783 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46784 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46785 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46786
46787 seq_printf(seq, "Serial number : ");
46788 print_serial_number(seq, (u8 *) (work32 + 16),
46789 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46790 u8 pad[256]; // allow up to 256 byte (max) serial number
46791 } result;
46792
46793 - char tmp[24 + 1];
46794 -
46795 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46796
46797 if (token < 0) {
46798 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46799 }
46800
46801 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46802 - seq_printf(seq, "Module name : %s\n",
46803 - chtostr(tmp, result.module_name, 24));
46804 - seq_printf(seq, "Module revision : %s\n",
46805 - chtostr(tmp, result.module_rev, 8));
46806 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46807 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46808
46809 seq_printf(seq, "Serial number : ");
46810 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46811 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46812 u8 instance_number[4];
46813 } result;
46814
46815 - char tmp[64 + 1];
46816 -
46817 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46818
46819 if (token < 0) {
46820 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46821 return 0;
46822 }
46823
46824 - seq_printf(seq, "Device name : %s\n",
46825 - chtostr(tmp, result.device_name, 64));
46826 - seq_printf(seq, "Service name : %s\n",
46827 - chtostr(tmp, result.service_name, 64));
46828 - seq_printf(seq, "Physical name : %s\n",
46829 - chtostr(tmp, result.physical_location, 64));
46830 - seq_printf(seq, "Instance number : %s\n",
46831 - chtostr(tmp, result.instance_number, 4));
46832 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46833 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46834 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46835 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46836
46837 return 0;
46838 }
46839 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46840 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46841 {
46842 struct i2o_device *d = (struct i2o_device *)seq->private;
46843 - static u32 work32[12];
46844 - static u16 *work16 = (u16 *) work32;
46845 - static u8 *work8 = (u8 *) work32;
46846 + u32 work32[12];
46847 + u16 *work16 = (u16 *) work32;
46848 + u8 *work8 = (u8 *) work32;
46849 int token;
46850
46851 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46852 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46853 index 92752fb..a7494f6 100644
46854 --- a/drivers/message/i2o/iop.c
46855 +++ b/drivers/message/i2o/iop.c
46856 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46857
46858 spin_lock_irqsave(&c->context_list_lock, flags);
46859
46860 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46861 - atomic_inc(&c->context_list_counter);
46862 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46863 + atomic_inc_unchecked(&c->context_list_counter);
46864
46865 - entry->context = atomic_read(&c->context_list_counter);
46866 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46867
46868 list_add(&entry->list, &c->context_list);
46869
46870 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46871
46872 #if BITS_PER_LONG == 64
46873 spin_lock_init(&c->context_list_lock);
46874 - atomic_set(&c->context_list_counter, 0);
46875 + atomic_set_unchecked(&c->context_list_counter, 0);
46876 INIT_LIST_HEAD(&c->context_list);
46877 #endif
46878
46879 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46880 index b2c7e3b..85aa4764 100644
46881 --- a/drivers/mfd/ab8500-debugfs.c
46882 +++ b/drivers/mfd/ab8500-debugfs.c
46883 @@ -100,7 +100,7 @@ static int irq_last;
46884 static u32 *irq_count;
46885 static int num_irqs;
46886
46887 -static struct device_attribute **dev_attr;
46888 +static device_attribute_no_const **dev_attr;
46889 static char **event_name;
46890
46891 static u8 avg_sample = SAMPLE_16;
46892 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46893 index ecbe78e..b2ca870 100644
46894 --- a/drivers/mfd/max8925-i2c.c
46895 +++ b/drivers/mfd/max8925-i2c.c
46896 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46897 const struct i2c_device_id *id)
46898 {
46899 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46900 - static struct max8925_chip *chip;
46901 + struct max8925_chip *chip;
46902 struct device_node *node = client->dev.of_node;
46903
46904 if (node && !pdata) {
46905 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46906 index f243e75..322176c 100644
46907 --- a/drivers/mfd/tps65910.c
46908 +++ b/drivers/mfd/tps65910.c
46909 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46910 struct tps65910_platform_data *pdata)
46911 {
46912 int ret = 0;
46913 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46914 + struct regmap_irq_chip *tps6591x_irqs_chip;
46915
46916 if (!irq) {
46917 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46918 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46919 index b1dabba..24a88f2 100644
46920 --- a/drivers/mfd/twl4030-irq.c
46921 +++ b/drivers/mfd/twl4030-irq.c
46922 @@ -34,6 +34,7 @@
46923 #include <linux/of.h>
46924 #include <linux/irqdomain.h>
46925 #include <linux/i2c/twl.h>
46926 +#include <asm/pgtable.h>
46927
46928 #include "twl-core.h"
46929
46930 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46931 * Install an irq handler for each of the SIH modules;
46932 * clone dummy irq_chip since PIH can't *do* anything
46933 */
46934 - twl4030_irq_chip = dummy_irq_chip;
46935 - twl4030_irq_chip.name = "twl4030";
46936 + pax_open_kernel();
46937 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46938 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46939
46940 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46941 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46942 + pax_close_kernel();
46943
46944 for (i = irq_base; i < irq_end; i++) {
46945 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46946 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46947 index 464419b..64bae8d 100644
46948 --- a/drivers/misc/c2port/core.c
46949 +++ b/drivers/misc/c2port/core.c
46950 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46951 goto error_idr_alloc;
46952 c2dev->id = ret;
46953
46954 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46955 + pax_open_kernel();
46956 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46957 + pax_close_kernel();
46958
46959 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46960 "c2port%d", c2dev->id);
46961 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46962 index 3f2b625..945e179 100644
46963 --- a/drivers/misc/eeprom/sunxi_sid.c
46964 +++ b/drivers/misc/eeprom/sunxi_sid.c
46965 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46966
46967 platform_set_drvdata(pdev, sid_data);
46968
46969 - sid_bin_attr.size = sid_data->keysize;
46970 + pax_open_kernel();
46971 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46972 + pax_close_kernel();
46973 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46974 return -ENODEV;
46975
46976 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46977 index 36f5d52..32311c3 100644
46978 --- a/drivers/misc/kgdbts.c
46979 +++ b/drivers/misc/kgdbts.c
46980 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46981 char before[BREAK_INSTR_SIZE];
46982 char after[BREAK_INSTR_SIZE];
46983
46984 - probe_kernel_read(before, (char *)kgdbts_break_test,
46985 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46986 BREAK_INSTR_SIZE);
46987 init_simple_test();
46988 ts.tst = plant_and_detach_test;
46989 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46990 /* Activate test with initial breakpoint */
46991 if (!is_early)
46992 kgdb_breakpoint();
46993 - probe_kernel_read(after, (char *)kgdbts_break_test,
46994 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46995 BREAK_INSTR_SIZE);
46996 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46997 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46998 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46999 index 3ef4627..8d00486 100644
47000 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47001 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47002 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47003 * the lid is closed. This leads to interrupts as soon as a little move
47004 * is done.
47005 */
47006 - atomic_inc(&lis3->count);
47007 + atomic_inc_unchecked(&lis3->count);
47008
47009 wake_up_interruptible(&lis3->misc_wait);
47010 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47011 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47012 if (lis3->pm_dev)
47013 pm_runtime_get_sync(lis3->pm_dev);
47014
47015 - atomic_set(&lis3->count, 0);
47016 + atomic_set_unchecked(&lis3->count, 0);
47017 return 0;
47018 }
47019
47020 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47021 add_wait_queue(&lis3->misc_wait, &wait);
47022 while (true) {
47023 set_current_state(TASK_INTERRUPTIBLE);
47024 - data = atomic_xchg(&lis3->count, 0);
47025 + data = atomic_xchg_unchecked(&lis3->count, 0);
47026 if (data)
47027 break;
47028
47029 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47030 struct lis3lv02d, miscdev);
47031
47032 poll_wait(file, &lis3->misc_wait, wait);
47033 - if (atomic_read(&lis3->count))
47034 + if (atomic_read_unchecked(&lis3->count))
47035 return POLLIN | POLLRDNORM;
47036 return 0;
47037 }
47038 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47039 index c439c82..1f20f57 100644
47040 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47041 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47042 @@ -297,7 +297,7 @@ struct lis3lv02d {
47043 struct input_polled_dev *idev; /* input device */
47044 struct platform_device *pdev; /* platform device */
47045 struct regulator_bulk_data regulators[2];
47046 - atomic_t count; /* interrupt count after last read */
47047 + atomic_unchecked_t count; /* interrupt count after last read */
47048 union axis_conversion ac; /* hw -> logical axis */
47049 int mapped_btns[3];
47050
47051 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47052 index 2f30bad..c4c13d0 100644
47053 --- a/drivers/misc/sgi-gru/gruhandles.c
47054 +++ b/drivers/misc/sgi-gru/gruhandles.c
47055 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47056 unsigned long nsec;
47057
47058 nsec = CLKS2NSEC(clks);
47059 - atomic_long_inc(&mcs_op_statistics[op].count);
47060 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47061 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47062 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47063 if (mcs_op_statistics[op].max < nsec)
47064 mcs_op_statistics[op].max = nsec;
47065 }
47066 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47067 index 4f76359..cdfcb2e 100644
47068 --- a/drivers/misc/sgi-gru/gruprocfs.c
47069 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47070 @@ -32,9 +32,9 @@
47071
47072 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47073
47074 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47075 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47076 {
47077 - unsigned long val = atomic_long_read(v);
47078 + unsigned long val = atomic_long_read_unchecked(v);
47079
47080 seq_printf(s, "%16lu %s\n", val, id);
47081 }
47082 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47083
47084 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47085 for (op = 0; op < mcsop_last; op++) {
47086 - count = atomic_long_read(&mcs_op_statistics[op].count);
47087 - total = atomic_long_read(&mcs_op_statistics[op].total);
47088 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47089 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47090 max = mcs_op_statistics[op].max;
47091 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47092 count ? total / count : 0, max);
47093 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47094 index 5c3ce24..4915ccb 100644
47095 --- a/drivers/misc/sgi-gru/grutables.h
47096 +++ b/drivers/misc/sgi-gru/grutables.h
47097 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47098 * GRU statistics.
47099 */
47100 struct gru_stats_s {
47101 - atomic_long_t vdata_alloc;
47102 - atomic_long_t vdata_free;
47103 - atomic_long_t gts_alloc;
47104 - atomic_long_t gts_free;
47105 - atomic_long_t gms_alloc;
47106 - atomic_long_t gms_free;
47107 - atomic_long_t gts_double_allocate;
47108 - atomic_long_t assign_context;
47109 - atomic_long_t assign_context_failed;
47110 - atomic_long_t free_context;
47111 - atomic_long_t load_user_context;
47112 - atomic_long_t load_kernel_context;
47113 - atomic_long_t lock_kernel_context;
47114 - atomic_long_t unlock_kernel_context;
47115 - atomic_long_t steal_user_context;
47116 - atomic_long_t steal_kernel_context;
47117 - atomic_long_t steal_context_failed;
47118 - atomic_long_t nopfn;
47119 - atomic_long_t asid_new;
47120 - atomic_long_t asid_next;
47121 - atomic_long_t asid_wrap;
47122 - atomic_long_t asid_reuse;
47123 - atomic_long_t intr;
47124 - atomic_long_t intr_cbr;
47125 - atomic_long_t intr_tfh;
47126 - atomic_long_t intr_spurious;
47127 - atomic_long_t intr_mm_lock_failed;
47128 - atomic_long_t call_os;
47129 - atomic_long_t call_os_wait_queue;
47130 - atomic_long_t user_flush_tlb;
47131 - atomic_long_t user_unload_context;
47132 - atomic_long_t user_exception;
47133 - atomic_long_t set_context_option;
47134 - atomic_long_t check_context_retarget_intr;
47135 - atomic_long_t check_context_unload;
47136 - atomic_long_t tlb_dropin;
47137 - atomic_long_t tlb_preload_page;
47138 - atomic_long_t tlb_dropin_fail_no_asid;
47139 - atomic_long_t tlb_dropin_fail_upm;
47140 - atomic_long_t tlb_dropin_fail_invalid;
47141 - atomic_long_t tlb_dropin_fail_range_active;
47142 - atomic_long_t tlb_dropin_fail_idle;
47143 - atomic_long_t tlb_dropin_fail_fmm;
47144 - atomic_long_t tlb_dropin_fail_no_exception;
47145 - atomic_long_t tfh_stale_on_fault;
47146 - atomic_long_t mmu_invalidate_range;
47147 - atomic_long_t mmu_invalidate_page;
47148 - atomic_long_t flush_tlb;
47149 - atomic_long_t flush_tlb_gru;
47150 - atomic_long_t flush_tlb_gru_tgh;
47151 - atomic_long_t flush_tlb_gru_zero_asid;
47152 + atomic_long_unchecked_t vdata_alloc;
47153 + atomic_long_unchecked_t vdata_free;
47154 + atomic_long_unchecked_t gts_alloc;
47155 + atomic_long_unchecked_t gts_free;
47156 + atomic_long_unchecked_t gms_alloc;
47157 + atomic_long_unchecked_t gms_free;
47158 + atomic_long_unchecked_t gts_double_allocate;
47159 + atomic_long_unchecked_t assign_context;
47160 + atomic_long_unchecked_t assign_context_failed;
47161 + atomic_long_unchecked_t free_context;
47162 + atomic_long_unchecked_t load_user_context;
47163 + atomic_long_unchecked_t load_kernel_context;
47164 + atomic_long_unchecked_t lock_kernel_context;
47165 + atomic_long_unchecked_t unlock_kernel_context;
47166 + atomic_long_unchecked_t steal_user_context;
47167 + atomic_long_unchecked_t steal_kernel_context;
47168 + atomic_long_unchecked_t steal_context_failed;
47169 + atomic_long_unchecked_t nopfn;
47170 + atomic_long_unchecked_t asid_new;
47171 + atomic_long_unchecked_t asid_next;
47172 + atomic_long_unchecked_t asid_wrap;
47173 + atomic_long_unchecked_t asid_reuse;
47174 + atomic_long_unchecked_t intr;
47175 + atomic_long_unchecked_t intr_cbr;
47176 + atomic_long_unchecked_t intr_tfh;
47177 + atomic_long_unchecked_t intr_spurious;
47178 + atomic_long_unchecked_t intr_mm_lock_failed;
47179 + atomic_long_unchecked_t call_os;
47180 + atomic_long_unchecked_t call_os_wait_queue;
47181 + atomic_long_unchecked_t user_flush_tlb;
47182 + atomic_long_unchecked_t user_unload_context;
47183 + atomic_long_unchecked_t user_exception;
47184 + atomic_long_unchecked_t set_context_option;
47185 + atomic_long_unchecked_t check_context_retarget_intr;
47186 + atomic_long_unchecked_t check_context_unload;
47187 + atomic_long_unchecked_t tlb_dropin;
47188 + atomic_long_unchecked_t tlb_preload_page;
47189 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47190 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47191 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47192 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47193 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47194 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47195 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47196 + atomic_long_unchecked_t tfh_stale_on_fault;
47197 + atomic_long_unchecked_t mmu_invalidate_range;
47198 + atomic_long_unchecked_t mmu_invalidate_page;
47199 + atomic_long_unchecked_t flush_tlb;
47200 + atomic_long_unchecked_t flush_tlb_gru;
47201 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47202 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47203
47204 - atomic_long_t copy_gpa;
47205 - atomic_long_t read_gpa;
47206 + atomic_long_unchecked_t copy_gpa;
47207 + atomic_long_unchecked_t read_gpa;
47208
47209 - atomic_long_t mesq_receive;
47210 - atomic_long_t mesq_receive_none;
47211 - atomic_long_t mesq_send;
47212 - atomic_long_t mesq_send_failed;
47213 - atomic_long_t mesq_noop;
47214 - atomic_long_t mesq_send_unexpected_error;
47215 - atomic_long_t mesq_send_lb_overflow;
47216 - atomic_long_t mesq_send_qlimit_reached;
47217 - atomic_long_t mesq_send_amo_nacked;
47218 - atomic_long_t mesq_send_put_nacked;
47219 - atomic_long_t mesq_page_overflow;
47220 - atomic_long_t mesq_qf_locked;
47221 - atomic_long_t mesq_qf_noop_not_full;
47222 - atomic_long_t mesq_qf_switch_head_failed;
47223 - atomic_long_t mesq_qf_unexpected_error;
47224 - atomic_long_t mesq_noop_unexpected_error;
47225 - atomic_long_t mesq_noop_lb_overflow;
47226 - atomic_long_t mesq_noop_qlimit_reached;
47227 - atomic_long_t mesq_noop_amo_nacked;
47228 - atomic_long_t mesq_noop_put_nacked;
47229 - atomic_long_t mesq_noop_page_overflow;
47230 + atomic_long_unchecked_t mesq_receive;
47231 + atomic_long_unchecked_t mesq_receive_none;
47232 + atomic_long_unchecked_t mesq_send;
47233 + atomic_long_unchecked_t mesq_send_failed;
47234 + atomic_long_unchecked_t mesq_noop;
47235 + atomic_long_unchecked_t mesq_send_unexpected_error;
47236 + atomic_long_unchecked_t mesq_send_lb_overflow;
47237 + atomic_long_unchecked_t mesq_send_qlimit_reached;
47238 + atomic_long_unchecked_t mesq_send_amo_nacked;
47239 + atomic_long_unchecked_t mesq_send_put_nacked;
47240 + atomic_long_unchecked_t mesq_page_overflow;
47241 + atomic_long_unchecked_t mesq_qf_locked;
47242 + atomic_long_unchecked_t mesq_qf_noop_not_full;
47243 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
47244 + atomic_long_unchecked_t mesq_qf_unexpected_error;
47245 + atomic_long_unchecked_t mesq_noop_unexpected_error;
47246 + atomic_long_unchecked_t mesq_noop_lb_overflow;
47247 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
47248 + atomic_long_unchecked_t mesq_noop_amo_nacked;
47249 + atomic_long_unchecked_t mesq_noop_put_nacked;
47250 + atomic_long_unchecked_t mesq_noop_page_overflow;
47251
47252 };
47253
47254 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47255 tghop_invalidate, mcsop_last};
47256
47257 struct mcs_op_statistic {
47258 - atomic_long_t count;
47259 - atomic_long_t total;
47260 + atomic_long_unchecked_t count;
47261 + atomic_long_unchecked_t total;
47262 unsigned long max;
47263 };
47264
47265 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47266
47267 #define STAT(id) do { \
47268 if (gru_options & OPT_STATS) \
47269 - atomic_long_inc(&gru_stats.id); \
47270 + atomic_long_inc_unchecked(&gru_stats.id); \
47271 } while (0)
47272
47273 #ifdef CONFIG_SGI_GRU_DEBUG
47274 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47275 index c862cd4..0d176fe 100644
47276 --- a/drivers/misc/sgi-xp/xp.h
47277 +++ b/drivers/misc/sgi-xp/xp.h
47278 @@ -288,7 +288,7 @@ struct xpc_interface {
47279 xpc_notify_func, void *);
47280 void (*received) (short, int, void *);
47281 enum xp_retval (*partid_to_nasids) (short, void *);
47282 -};
47283 +} __no_const;
47284
47285 extern struct xpc_interface xpc_interface;
47286
47287 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47288 index 01be66d..e3a0c7e 100644
47289 --- a/drivers/misc/sgi-xp/xp_main.c
47290 +++ b/drivers/misc/sgi-xp/xp_main.c
47291 @@ -78,13 +78,13 @@ xpc_notloaded(void)
47292 }
47293
47294 struct xpc_interface xpc_interface = {
47295 - (void (*)(int))xpc_notloaded,
47296 - (void (*)(int))xpc_notloaded,
47297 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47298 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47299 + .connect = (void (*)(int))xpc_notloaded,
47300 + .disconnect = (void (*)(int))xpc_notloaded,
47301 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47302 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47303 void *))xpc_notloaded,
47304 - (void (*)(short, int, void *))xpc_notloaded,
47305 - (enum xp_retval(*)(short, void *))xpc_notloaded
47306 + .received = (void (*)(short, int, void *))xpc_notloaded,
47307 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47308 };
47309 EXPORT_SYMBOL_GPL(xpc_interface);
47310
47311 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47312 index b94d5f7..7f494c5 100644
47313 --- a/drivers/misc/sgi-xp/xpc.h
47314 +++ b/drivers/misc/sgi-xp/xpc.h
47315 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47316 void (*received_payload) (struct xpc_channel *, void *);
47317 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47318 };
47319 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47320
47321 /* struct xpc_partition act_state values (for XPC HB) */
47322
47323 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47324 /* found in xpc_main.c */
47325 extern struct device *xpc_part;
47326 extern struct device *xpc_chan;
47327 -extern struct xpc_arch_operations xpc_arch_ops;
47328 +extern xpc_arch_operations_no_const xpc_arch_ops;
47329 extern int xpc_disengage_timelimit;
47330 extern int xpc_disengage_timedout;
47331 extern int xpc_activate_IRQ_rcvd;
47332 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47333 index 82dc574..8539ab2 100644
47334 --- a/drivers/misc/sgi-xp/xpc_main.c
47335 +++ b/drivers/misc/sgi-xp/xpc_main.c
47336 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47337 .notifier_call = xpc_system_die,
47338 };
47339
47340 -struct xpc_arch_operations xpc_arch_ops;
47341 +xpc_arch_operations_no_const xpc_arch_ops;
47342
47343 /*
47344 * Timer function to enforce the timelimit on the partition disengage.
47345 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47346
47347 if (((die_args->trapnr == X86_TRAP_MF) ||
47348 (die_args->trapnr == X86_TRAP_XF)) &&
47349 - !user_mode_vm(die_args->regs))
47350 + !user_mode(die_args->regs))
47351 xpc_die_deactivate();
47352
47353 break;
47354 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47355 index ede41f0..744fbd9 100644
47356 --- a/drivers/mmc/card/block.c
47357 +++ b/drivers/mmc/card/block.c
47358 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47359 if (idata->ic.postsleep_min_us)
47360 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47361
47362 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47363 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47364 err = -EFAULT;
47365 goto cmd_rel_host;
47366 }
47367 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47368 index f51b5ba..86614a7 100644
47369 --- a/drivers/mmc/core/mmc_ops.c
47370 +++ b/drivers/mmc/core/mmc_ops.c
47371 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47372 void *data_buf;
47373 int is_on_stack;
47374
47375 - is_on_stack = object_is_on_stack(buf);
47376 + is_on_stack = object_starts_on_stack(buf);
47377 if (is_on_stack) {
47378 /*
47379 * dma onto stack is unsafe/nonportable, but callers to this
47380 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47381 index 08fd956..370487a 100644
47382 --- a/drivers/mmc/host/dw_mmc.h
47383 +++ b/drivers/mmc/host/dw_mmc.h
47384 @@ -262,5 +262,5 @@ struct dw_mci_drv_data {
47385 int (*parse_dt)(struct dw_mci *host);
47386 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47387 struct dw_mci_tuning_data *tuning_data);
47388 -};
47389 +} __do_const;
47390 #endif /* _DW_MMC_H_ */
47391 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47392 index e4d4707..28262a3 100644
47393 --- a/drivers/mmc/host/mmci.c
47394 +++ b/drivers/mmc/host/mmci.c
47395 @@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
47396 mmc->caps |= MMC_CAP_CMD23;
47397
47398 if (variant->busy_detect) {
47399 - mmci_ops.card_busy = mmci_card_busy;
47400 + pax_open_kernel();
47401 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47402 + pax_close_kernel();
47403 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47404 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47405 mmc->max_busy_timeout = 0;
47406 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47407 index ccec0e3..199f9ce 100644
47408 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47409 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47410 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47411 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47412 }
47413
47414 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47415 - sdhci_esdhc_ops.platform_execute_tuning =
47416 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47417 + pax_open_kernel();
47418 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47419 esdhc_executing_tuning;
47420 + pax_close_kernel();
47421 + }
47422
47423 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47424 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47425 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47426 index 1e47903..7683916 100644
47427 --- a/drivers/mmc/host/sdhci-s3c.c
47428 +++ b/drivers/mmc/host/sdhci-s3c.c
47429 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47430 * we can use overriding functions instead of default.
47431 */
47432 if (sc->no_divider) {
47433 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47434 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47435 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47436 + pax_open_kernel();
47437 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47438 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47439 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47440 + pax_close_kernel();
47441 }
47442
47443 /* It supports additional host capabilities if needed */
47444 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47445 index 423666b..81ff5eb 100644
47446 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47447 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47448 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47449 size_t totlen = 0, thislen;
47450 int ret = 0;
47451 size_t buflen = 0;
47452 - static char *buffer;
47453 + char *buffer;
47454
47455 if (!ECCBUF_SIZE) {
47456 /* We should fall back to a general writev implementation.
47457 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47458 index 0b071a3..8ec3d5b 100644
47459 --- a/drivers/mtd/nand/denali.c
47460 +++ b/drivers/mtd/nand/denali.c
47461 @@ -24,6 +24,7 @@
47462 #include <linux/slab.h>
47463 #include <linux/mtd/mtd.h>
47464 #include <linux/module.h>
47465 +#include <linux/slab.h>
47466
47467 #include "denali.h"
47468
47469 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47470 index 959cb9b..8520fe5 100644
47471 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47472 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47473 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47474
47475 /* first try to map the upper buffer directly */
47476 if (virt_addr_valid(this->upper_buf) &&
47477 - !object_is_on_stack(this->upper_buf)) {
47478 + !object_starts_on_stack(this->upper_buf)) {
47479 sg_init_one(sgl, this->upper_buf, this->upper_len);
47480 ret = dma_map_sg(this->dev, sgl, 1, dr);
47481 if (ret == 0)
47482 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47483 index 51b9d6a..52af9a7 100644
47484 --- a/drivers/mtd/nftlmount.c
47485 +++ b/drivers/mtd/nftlmount.c
47486 @@ -24,6 +24,7 @@
47487 #include <asm/errno.h>
47488 #include <linux/delay.h>
47489 #include <linux/slab.h>
47490 +#include <linux/sched.h>
47491 #include <linux/mtd/mtd.h>
47492 #include <linux/mtd/nand.h>
47493 #include <linux/mtd/nftl.h>
47494 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47495 index cf49c22..971b133 100644
47496 --- a/drivers/mtd/sm_ftl.c
47497 +++ b/drivers/mtd/sm_ftl.c
47498 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47499 #define SM_CIS_VENDOR_OFFSET 0x59
47500 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47501 {
47502 - struct attribute_group *attr_group;
47503 + attribute_group_no_const *attr_group;
47504 struct attribute **attributes;
47505 struct sm_sysfs_attribute *vendor_attribute;
47506 char *vendor;
47507 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47508 index d163e11..f517018 100644
47509 --- a/drivers/net/bonding/bond_netlink.c
47510 +++ b/drivers/net/bonding/bond_netlink.c
47511 @@ -548,7 +548,7 @@ nla_put_failure:
47512 return -EMSGSIZE;
47513 }
47514
47515 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47516 +struct rtnl_link_ops bond_link_ops = {
47517 .kind = "bond",
47518 .priv_size = sizeof(struct bonding),
47519 .setup = bond_setup,
47520 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47521 index 4168822..f38eeddf 100644
47522 --- a/drivers/net/can/Kconfig
47523 +++ b/drivers/net/can/Kconfig
47524 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47525
47526 config CAN_FLEXCAN
47527 tristate "Support for Freescale FLEXCAN based chips"
47528 - depends on ARM || PPC
47529 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47530 ---help---
47531 Say Y here if you want to support for Freescale FlexCAN.
47532
47533 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47534 index 1d162cc..b546a75 100644
47535 --- a/drivers/net/ethernet/8390/ax88796.c
47536 +++ b/drivers/net/ethernet/8390/ax88796.c
47537 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47538 if (ax->plat->reg_offsets)
47539 ei_local->reg_offset = ax->plat->reg_offsets;
47540 else {
47541 + resource_size_t _mem_size = mem_size;
47542 + do_div(_mem_size, 0x18);
47543 ei_local->reg_offset = ax->reg_offsets;
47544 for (ret = 0; ret < 0x18; ret++)
47545 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47546 + ax->reg_offsets[ret] = _mem_size * ret;
47547 }
47548
47549 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47550 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47551 index 7330681..7e9e463 100644
47552 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47553 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47554 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
47555 return 0;
47556 }
47557
47558 -static struct net_device_ops altera_tse_netdev_ops = {
47559 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47560 .ndo_open = tse_open,
47561 .ndo_stop = tse_shutdown,
47562 .ndo_start_xmit = tse_start_xmit,
47563 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47564 ndev->netdev_ops = &altera_tse_netdev_ops;
47565 altera_tse_set_ethtool_ops(ndev);
47566
47567 + pax_open_kernel();
47568 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47569
47570 if (priv->hash_filter)
47571 altera_tse_netdev_ops.ndo_set_rx_mode =
47572 tse_set_rx_mode_hashfilter;
47573 + pax_close_kernel();
47574
47575 /* Scatter/gather IO is not supported,
47576 * so it is turned off
47577 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47578 index cc25a3a..c8d72d3 100644
47579 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47580 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47581 @@ -1083,14 +1083,14 @@ do { \
47582 * operations, everything works on mask values.
47583 */
47584 #define XMDIO_READ(_pdata, _mmd, _reg) \
47585 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47586 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47587 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47588
47589 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47590 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47591
47592 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47593 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47594 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47595 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47596
47597 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47598 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47599 index 7d6a49b..e6d403b 100644
47600 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47601 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47602 @@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47603
47604 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47605
47606 - pdata->hw_if.config_dcb_tc(pdata);
47607 + pdata->hw_if->config_dcb_tc(pdata);
47608
47609 return 0;
47610 }
47611 @@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47612
47613 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47614
47615 - pdata->hw_if.config_dcb_pfc(pdata);
47616 + pdata->hw_if->config_dcb_pfc(pdata);
47617
47618 return 0;
47619 }
47620 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47621 index 1c5d62e..8e14d54 100644
47622 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47623 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47624 @@ -236,7 +236,7 @@ err_ring:
47625
47626 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47627 {
47628 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47629 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47630 struct xgbe_channel *channel;
47631 struct xgbe_ring *ring;
47632 struct xgbe_ring_data *rdata;
47633 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47634
47635 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47636 {
47637 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47638 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47639 struct xgbe_channel *channel;
47640 struct xgbe_ring *ring;
47641 struct xgbe_ring_desc *rdesc;
47642 @@ -506,7 +506,7 @@ err_out:
47643 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47644 {
47645 struct xgbe_prv_data *pdata = channel->pdata;
47646 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47647 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47648 struct xgbe_ring *ring = channel->rx_ring;
47649 struct xgbe_ring_data *rdata;
47650 struct sk_buff *skb = NULL;
47651 @@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47652 DBGPR("<--xgbe_realloc_skb\n");
47653 }
47654
47655 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47656 -{
47657 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47658 -
47659 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47660 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47661 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47662 - desc_if->realloc_skb = xgbe_realloc_skb;
47663 - desc_if->unmap_skb = xgbe_unmap_skb;
47664 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47665 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47666 -
47667 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47668 -}
47669 +const struct xgbe_desc_if default_xgbe_desc_if = {
47670 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47671 + .free_ring_resources = xgbe_free_ring_resources,
47672 + .map_tx_skb = xgbe_map_tx_skb,
47673 + .realloc_skb = xgbe_realloc_skb,
47674 + .unmap_skb = xgbe_unmap_skb,
47675 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47676 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47677 +};
47678 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47679 index ea27383..faa8936 100644
47680 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47681 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47682 @@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47683
47684 static int xgbe_init(struct xgbe_prv_data *pdata)
47685 {
47686 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47687 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47688 int ret;
47689
47690 DBGPR("-->xgbe_init\n");
47691 @@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47692 return 0;
47693 }
47694
47695 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47696 -{
47697 - DBGPR("-->xgbe_init_function_ptrs\n");
47698 -
47699 - hw_if->tx_complete = xgbe_tx_complete;
47700 -
47701 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47702 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47703 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47704 - hw_if->set_mac_address = xgbe_set_mac_address;
47705 -
47706 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47707 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47708 -
47709 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47710 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47711 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47712 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47713 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47714 -
47715 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47716 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47717 -
47718 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47719 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47720 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47721 -
47722 - hw_if->enable_tx = xgbe_enable_tx;
47723 - hw_if->disable_tx = xgbe_disable_tx;
47724 - hw_if->enable_rx = xgbe_enable_rx;
47725 - hw_if->disable_rx = xgbe_disable_rx;
47726 -
47727 - hw_if->powerup_tx = xgbe_powerup_tx;
47728 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47729 - hw_if->powerup_rx = xgbe_powerup_rx;
47730 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47731 -
47732 - hw_if->pre_xmit = xgbe_pre_xmit;
47733 - hw_if->dev_read = xgbe_dev_read;
47734 - hw_if->enable_int = xgbe_enable_int;
47735 - hw_if->disable_int = xgbe_disable_int;
47736 - hw_if->init = xgbe_init;
47737 - hw_if->exit = xgbe_exit;
47738 +const struct xgbe_hw_if default_xgbe_hw_if = {
47739 + .tx_complete = xgbe_tx_complete,
47740 +
47741 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47742 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47743 + .add_mac_addresses = xgbe_add_mac_addresses,
47744 + .set_mac_address = xgbe_set_mac_address,
47745 +
47746 + .enable_rx_csum = xgbe_enable_rx_csum,
47747 + .disable_rx_csum = xgbe_disable_rx_csum,
47748 +
47749 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47750 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47751 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47752 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47753 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47754 +
47755 + .read_mmd_regs = xgbe_read_mmd_regs,
47756 + .write_mmd_regs = xgbe_write_mmd_regs,
47757 +
47758 + .set_gmii_speed = xgbe_set_gmii_speed,
47759 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47760 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47761 +
47762 + .enable_tx = xgbe_enable_tx,
47763 + .disable_tx = xgbe_disable_tx,
47764 + .enable_rx = xgbe_enable_rx,
47765 + .disable_rx = xgbe_disable_rx,
47766 +
47767 + .powerup_tx = xgbe_powerup_tx,
47768 + .powerdown_tx = xgbe_powerdown_tx,
47769 + .powerup_rx = xgbe_powerup_rx,
47770 + .powerdown_rx = xgbe_powerdown_rx,
47771 +
47772 + .pre_xmit = xgbe_pre_xmit,
47773 + .dev_read = xgbe_dev_read,
47774 + .enable_int = xgbe_enable_int,
47775 + .disable_int = xgbe_disable_int,
47776 + .init = xgbe_init,
47777 + .exit = xgbe_exit,
47778
47779 /* Descriptor related Sequences have to be initialized here */
47780 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47781 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47782 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47783 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47784 - hw_if->is_last_desc = xgbe_is_last_desc;
47785 - hw_if->is_context_desc = xgbe_is_context_desc;
47786 + .tx_desc_init = xgbe_tx_desc_init,
47787 + .rx_desc_init = xgbe_rx_desc_init,
47788 + .tx_desc_reset = xgbe_tx_desc_reset,
47789 + .rx_desc_reset = xgbe_rx_desc_reset,
47790 + .is_last_desc = xgbe_is_last_desc,
47791 + .is_context_desc = xgbe_is_context_desc,
47792
47793 /* For FLOW ctrl */
47794 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47795 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47796 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47797 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47798
47799 /* For RX coalescing */
47800 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47801 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47802 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47803 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47804 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47805 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47806 + .usec_to_riwt = xgbe_usec_to_riwt,
47807 + .riwt_to_usec = xgbe_riwt_to_usec,
47808
47809 /* For RX and TX threshold config */
47810 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47811 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47812 + .config_rx_threshold = xgbe_config_rx_threshold,
47813 + .config_tx_threshold = xgbe_config_tx_threshold,
47814
47815 /* For RX and TX Store and Forward Mode config */
47816 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47817 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47818 + .config_rsf_mode = xgbe_config_rsf_mode,
47819 + .config_tsf_mode = xgbe_config_tsf_mode,
47820
47821 /* For TX DMA Operating on Second Frame config */
47822 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47823 + .config_osp_mode = xgbe_config_osp_mode,
47824
47825 /* For RX and TX PBL config */
47826 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47827 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47828 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47829 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47830 - hw_if->config_pblx8 = xgbe_config_pblx8;
47831 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47832 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47833 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47834 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47835 + .config_pblx8 = xgbe_config_pblx8,
47836
47837 /* For MMC statistics support */
47838 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47839 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47840 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47841 + .tx_mmc_int = xgbe_tx_mmc_int,
47842 + .rx_mmc_int = xgbe_rx_mmc_int,
47843 + .read_mmc_stats = xgbe_read_mmc_stats,
47844
47845 /* For PTP config */
47846 - hw_if->config_tstamp = xgbe_config_tstamp;
47847 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47848 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47849 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47850 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47851 + .config_tstamp = xgbe_config_tstamp,
47852 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47853 + .set_tstamp_time = xgbe_set_tstamp_time,
47854 + .get_tstamp_time = xgbe_get_tstamp_time,
47855 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47856
47857 /* For Data Center Bridging config */
47858 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47859 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47860 -
47861 - DBGPR("<--xgbe_init_function_ptrs\n");
47862 -}
47863 + .config_dcb_tc = xgbe_config_dcb_tc,
47864 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47865 +};
47866 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47867 index b26d758..b0d1c3b 100644
47868 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47869 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47870 @@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47871
47872 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47873 {
47874 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47875 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47876 struct xgbe_channel *channel;
47877 enum xgbe_int int_id;
47878 unsigned int i;
47879 @@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47880
47881 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47882 {
47883 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47884 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47885 struct xgbe_channel *channel;
47886 enum xgbe_int int_id;
47887 unsigned int i;
47888 @@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47889 static irqreturn_t xgbe_isr(int irq, void *data)
47890 {
47891 struct xgbe_prv_data *pdata = data;
47892 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47893 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47894 struct xgbe_channel *channel;
47895 unsigned int dma_isr, dma_ch_isr;
47896 unsigned int mac_isr, mac_tssr;
47897 @@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47898
47899 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47900 {
47901 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47902 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47903
47904 DBGPR("-->xgbe_init_tx_coalesce\n");
47905
47906 @@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47907
47908 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47909 {
47910 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47911 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47912
47913 DBGPR("-->xgbe_init_rx_coalesce\n");
47914
47915 @@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47916
47917 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47918 {
47919 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47920 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47921 struct xgbe_channel *channel;
47922 struct xgbe_ring *ring;
47923 struct xgbe_ring_data *rdata;
47924 @@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47925
47926 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47927 {
47928 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47929 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47930 struct xgbe_channel *channel;
47931 struct xgbe_ring *ring;
47932 struct xgbe_ring_data *rdata;
47933 @@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47934 static void xgbe_adjust_link(struct net_device *netdev)
47935 {
47936 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47937 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47938 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47939 struct phy_device *phydev = pdata->phydev;
47940 int new_state = 0;
47941
47942 @@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47943 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47944 {
47945 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47946 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47947 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47948 unsigned long flags;
47949
47950 DBGPR("-->xgbe_powerdown\n");
47951 @@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47952 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47953 {
47954 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47955 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47956 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47957 unsigned long flags;
47958
47959 DBGPR("-->xgbe_powerup\n");
47960 @@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47961
47962 static int xgbe_start(struct xgbe_prv_data *pdata)
47963 {
47964 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47965 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47966 struct net_device *netdev = pdata->netdev;
47967
47968 DBGPR("-->xgbe_start\n");
47969 @@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47970
47971 static void xgbe_stop(struct xgbe_prv_data *pdata)
47972 {
47973 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47974 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47975 struct net_device *netdev = pdata->netdev;
47976
47977 DBGPR("-->xgbe_stop\n");
47978 @@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47979
47980 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47981 {
47982 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47983 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47984
47985 DBGPR("-->xgbe_restart_dev\n");
47986
47987 @@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47988 return -ERANGE;
47989 }
47990
47991 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47992 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47993
47994 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47995
47996 @@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47997 static int xgbe_open(struct net_device *netdev)
47998 {
47999 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48000 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48001 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48002 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48003 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48004 int ret;
48005
48006 DBGPR("-->xgbe_open\n");
48007 @@ -1171,8 +1171,8 @@ err_phy_init:
48008 static int xgbe_close(struct net_device *netdev)
48009 {
48010 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48011 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48012 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48013 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48014 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48015
48016 DBGPR("-->xgbe_close\n");
48017
48018 @@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48019 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48020 {
48021 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48022 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48023 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48024 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48025 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48026 struct xgbe_channel *channel;
48027 struct xgbe_ring *ring;
48028 struct xgbe_packet_data *packet;
48029 @@ -1276,7 +1276,7 @@ tx_netdev_return:
48030 static void xgbe_set_rx_mode(struct net_device *netdev)
48031 {
48032 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48033 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48034 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48035 unsigned int pr_mode, am_mode;
48036
48037 DBGPR("-->xgbe_set_rx_mode\n");
48038 @@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48039 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48040 {
48041 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48042 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48043 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48044 struct sockaddr *saddr = addr;
48045
48046 DBGPR("-->xgbe_set_mac_address\n");
48047 @@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48048
48049 DBGPR("-->%s\n", __func__);
48050
48051 - pdata->hw_if.read_mmc_stats(pdata);
48052 + pdata->hw_if->read_mmc_stats(pdata);
48053
48054 s->rx_packets = pstats->rxframecount_gb;
48055 s->rx_bytes = pstats->rxoctetcount_gb;
48056 @@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48057 u16 vid)
48058 {
48059 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48060 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48061 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48062
48063 DBGPR("-->%s\n", __func__);
48064
48065 @@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48066 u16 vid)
48067 {
48068 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48069 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48070 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48071
48072 DBGPR("-->%s\n", __func__);
48073
48074 @@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48075 netdev_features_t features)
48076 {
48077 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48078 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48079 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48080 unsigned int rxcsum, rxvlan, rxvlan_filter;
48081
48082 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48083 @@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48084 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48085 {
48086 struct xgbe_prv_data *pdata = channel->pdata;
48087 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48088 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48089 struct xgbe_ring *ring = channel->rx_ring;
48090 struct xgbe_ring_data *rdata;
48091
48092 @@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48093 static int xgbe_tx_poll(struct xgbe_channel *channel)
48094 {
48095 struct xgbe_prv_data *pdata = channel->pdata;
48096 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48097 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48098 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48099 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48100 struct xgbe_ring *ring = channel->tx_ring;
48101 struct xgbe_ring_data *rdata;
48102 struct xgbe_ring_desc *rdesc;
48103 @@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48104 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48105 {
48106 struct xgbe_prv_data *pdata = channel->pdata;
48107 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48108 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48109 struct xgbe_ring *ring = channel->rx_ring;
48110 struct xgbe_ring_data *rdata;
48111 struct xgbe_packet_data *packet;
48112 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48113 index 46f6130..f37dde3 100644
48114 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48115 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48116 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48117
48118 DBGPR("-->%s\n", __func__);
48119
48120 - pdata->hw_if.read_mmc_stats(pdata);
48121 + pdata->hw_if->read_mmc_stats(pdata);
48122 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48123 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48124 *data++ = *(u64 *)stat;
48125 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48126 struct ethtool_coalesce *ec)
48127 {
48128 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48129 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48130 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48131 unsigned int riwt;
48132
48133 DBGPR("-->xgbe_get_coalesce\n");
48134 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48135 struct ethtool_coalesce *ec)
48136 {
48137 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48138 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48139 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48140 unsigned int rx_frames, rx_riwt, rx_usecs;
48141 unsigned int tx_frames, tx_usecs;
48142
48143 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48144 index bdf9cfa..340aea1 100644
48145 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48146 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48147 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48148 DBGPR("<--xgbe_default_config\n");
48149 }
48150
48151 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48152 -{
48153 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48154 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48155 -}
48156 -
48157 static int xgbe_probe(struct platform_device *pdev)
48158 {
48159 struct xgbe_prv_data *pdata;
48160 @@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48161 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48162
48163 /* Set all the function pointers */
48164 - xgbe_init_all_fptrs(pdata);
48165 - hw_if = &pdata->hw_if;
48166 - desc_if = &pdata->desc_if;
48167 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48168 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
48169
48170 /* Issue software reset to device */
48171 hw_if->exit(pdata);
48172 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48173 index 6d2221e..47d1325 100644
48174 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48175 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48176 @@ -127,7 +127,7 @@
48177 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48178 {
48179 struct xgbe_prv_data *pdata = mii->priv;
48180 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48181 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48182 int mmd_data;
48183
48184 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48185 @@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48186 u16 mmd_val)
48187 {
48188 struct xgbe_prv_data *pdata = mii->priv;
48189 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48190 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48191 int mmd_data = mmd_val;
48192
48193 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48194 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48195 index 37e64cf..c3b61cf 100644
48196 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48197 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48198 @@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48199 tstamp_cc);
48200 u64 nsec;
48201
48202 - nsec = pdata->hw_if.get_tstamp_time(pdata);
48203 + nsec = pdata->hw_if->get_tstamp_time(pdata);
48204
48205 return nsec;
48206 }
48207 @@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48208
48209 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48210
48211 - pdata->hw_if.update_tstamp_addend(pdata, addend);
48212 + pdata->hw_if->update_tstamp_addend(pdata, addend);
48213
48214 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48215
48216 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48217 index e9fe6e6..875fbaf 100644
48218 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48219 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48220 @@ -585,8 +585,8 @@ struct xgbe_prv_data {
48221
48222 int irq_number;
48223
48224 - struct xgbe_hw_if hw_if;
48225 - struct xgbe_desc_if desc_if;
48226 + const struct xgbe_hw_if *hw_if;
48227 + const struct xgbe_desc_if *desc_if;
48228
48229 /* AXI DMA settings */
48230 unsigned int axdomain;
48231 @@ -699,6 +699,9 @@ struct xgbe_prv_data {
48232 #endif
48233 };
48234
48235 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48236 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48237 +
48238 /* Function prototypes*/
48239
48240 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48241 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48242 index 571427c..e9fe9e7 100644
48243 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48244 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48245 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48246 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48247 {
48248 /* RX_MODE controlling object */
48249 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48250 + bnx2x_init_rx_mode_obj(bp);
48251
48252 /* multicast configuration controlling object */
48253 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48254 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48255 index b193604..8873bfd 100644
48256 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48257 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48258 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48259 return rc;
48260 }
48261
48262 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48263 - struct bnx2x_rx_mode_obj *o)
48264 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48265 {
48266 if (CHIP_IS_E1x(bp)) {
48267 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48268 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48269 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48270 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48271 } else {
48272 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48273 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48274 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48275 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48276 }
48277 }
48278
48279 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48280 index 718ecd2..2183b2f 100644
48281 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48282 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48283 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48284
48285 /********************* RX MODE ****************/
48286
48287 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48288 - struct bnx2x_rx_mode_obj *o);
48289 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48290
48291 /**
48292 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48293 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48294 index 31c9f82..e65e986 100644
48295 --- a/drivers/net/ethernet/broadcom/tg3.h
48296 +++ b/drivers/net/ethernet/broadcom/tg3.h
48297 @@ -150,6 +150,7 @@
48298 #define CHIPREV_ID_5750_A0 0x4000
48299 #define CHIPREV_ID_5750_A1 0x4001
48300 #define CHIPREV_ID_5750_A3 0x4003
48301 +#define CHIPREV_ID_5750_C1 0x4201
48302 #define CHIPREV_ID_5750_C2 0x4202
48303 #define CHIPREV_ID_5752_A0_HW 0x5000
48304 #define CHIPREV_ID_5752_A0 0x6000
48305 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48306 index 13f9636..228040f 100644
48307 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48308 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48309 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48310 }
48311
48312 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48313 - bna_cb_ioceth_enable,
48314 - bna_cb_ioceth_disable,
48315 - bna_cb_ioceth_hbfail,
48316 - bna_cb_ioceth_reset
48317 + .enable_cbfn = bna_cb_ioceth_enable,
48318 + .disable_cbfn = bna_cb_ioceth_disable,
48319 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48320 + .reset_cbfn = bna_cb_ioceth_reset
48321 };
48322
48323 static void bna_attr_init(struct bna_ioceth *ioceth)
48324 diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
48325 index ffc92a4..40edc77 100644
48326 --- a/drivers/net/ethernet/brocade/bna/bnad.c
48327 +++ b/drivers/net/ethernet/brocade/bna/bnad.c
48328 @@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48329
48330 len = (vec == nvecs) ?
48331 last_fraglen : unmap->vector.len;
48332 + skb->truesize += unmap->vector.len;
48333 totlen += len;
48334
48335 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
48336 @@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48337
48338 skb->len += totlen;
48339 skb->data_len += totlen;
48340 - skb->truesize += totlen;
48341 }
48342
48343 static inline void
48344 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48345 index 8cffcdf..aadf043 100644
48346 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48347 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48348 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48349 */
48350 struct l2t_skb_cb {
48351 arp_failure_handler_func arp_failure_handler;
48352 -};
48353 +} __no_const;
48354
48355 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48356
48357 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48358 index 9f5f3c3..86d21a6 100644
48359 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48360 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48361 @@ -2359,7 +2359,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48362
48363 int i;
48364 struct adapter *ap = netdev2adap(dev);
48365 - static const unsigned int *reg_ranges;
48366 + const unsigned int *reg_ranges;
48367 int arr_size = 0, buf_size = 0;
48368
48369 if (is_t4(ap->params.chip)) {
48370 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48371 index cf8b6ff..274271e 100644
48372 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48373 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48374 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48375 for (i=0; i<ETH_ALEN; i++) {
48376 tmp.addr[i] = dev->dev_addr[i];
48377 }
48378 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48379 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48380 break;
48381
48382 case DE4X5_SET_HWADDR: /* Set the hardware address */
48383 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48384 spin_lock_irqsave(&lp->lock, flags);
48385 memcpy(&statbuf, &lp->pktStats, ioc->len);
48386 spin_unlock_irqrestore(&lp->lock, flags);
48387 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48388 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48389 return -EFAULT;
48390 break;
48391 }
48392 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48393 index 93ff8ef..01e0537 100644
48394 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48395 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48396 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48397
48398 if (wrapped)
48399 newacc += 65536;
48400 - ACCESS_ONCE(*acc) = newacc;
48401 + ACCESS_ONCE_RW(*acc) = newacc;
48402 }
48403
48404 static void populate_erx_stats(struct be_adapter *adapter,
48405 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48406 index c77fa4a..7fd42fc 100644
48407 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48408 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48409 @@ -30,6 +30,8 @@
48410 #include <linux/netdevice.h>
48411 #include <linux/phy.h>
48412 #include <linux/platform_device.h>
48413 +#include <linux/interrupt.h>
48414 +#include <linux/irqreturn.h>
48415 #include <net/ip.h>
48416
48417 #include "ftgmac100.h"
48418 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48419 index 4ff1adc..0ea6bf4 100644
48420 --- a/drivers/net/ethernet/faraday/ftmac100.c
48421 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48422 @@ -31,6 +31,8 @@
48423 #include <linux/module.h>
48424 #include <linux/netdevice.h>
48425 #include <linux/platform_device.h>
48426 +#include <linux/interrupt.h>
48427 +#include <linux/irqreturn.h>
48428
48429 #include "ftmac100.h"
48430
48431 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48432 index 537b621..07f87ce 100644
48433 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48434 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48435 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48436 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48437
48438 /* Update the base adjustement value. */
48439 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48440 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48441 smp_mb(); /* Force the above update. */
48442 }
48443
48444 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48445 index 5fd4b52..87aa34b 100644
48446 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48447 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48448 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48449 }
48450
48451 /* update the base incval used to calculate frequency adjustment */
48452 - ACCESS_ONCE(adapter->base_incval) = incval;
48453 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48454 smp_mb();
48455
48456 /* need lock to prevent incorrect read while modifying cyclecounter */
48457 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48458 index c14d4d8..66da603 100644
48459 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48460 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48461 @@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
48462 struct ixgbe_hw *hw = &adapter->hw;
48463 u32 regval;
48464
48465 + if (vf >= adapter->num_vfs)
48466 + return -EINVAL;
48467 +
48468 adapter->vfinfo[vf].spoofchk_enabled = setting;
48469
48470 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
48471 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48472 index 2bbd01f..e8baa64 100644
48473 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48474 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48475 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48476 struct __vxge_hw_fifo *fifo;
48477 struct vxge_hw_fifo_config *config;
48478 u32 txdl_size, txdl_per_memblock;
48479 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48480 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48481 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48482 + };
48483 +
48484 struct __vxge_hw_virtualpath *vpath;
48485
48486 if ((vp == NULL) || (attr == NULL)) {
48487 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48488 goto exit;
48489 }
48490
48491 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48492 -
48493 fifo->mempool =
48494 __vxge_hw_mempool_create(vpath->hldev,
48495 fifo->config->memblock_size,
48496 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48497 index 3172cdf..d01ab34 100644
48498 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48499 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48500 @@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48501 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48502 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48503 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48504 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48505 + pax_open_kernel();
48506 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48507 + pax_close_kernel();
48508 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48509 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48510 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48511 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48512 index be7d7a6..a8983f8 100644
48513 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48514 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48515 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48516 case QLCNIC_NON_PRIV_FUNC:
48517 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48518 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48519 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48520 + pax_open_kernel();
48521 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48522 + pax_close_kernel();
48523 break;
48524 case QLCNIC_PRIV_FUNC:
48525 ahw->op_mode = QLCNIC_PRIV_FUNC;
48526 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48527 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48528 + pax_open_kernel();
48529 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48530 + pax_close_kernel();
48531 break;
48532 case QLCNIC_MGMT_FUNC:
48533 ahw->op_mode = QLCNIC_MGMT_FUNC;
48534 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48535 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48536 + pax_open_kernel();
48537 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48538 + pax_close_kernel();
48539 break;
48540 default:
48541 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48542 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48543 index c9f57fb..208bdc1 100644
48544 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48545 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48546 @@ -1285,7 +1285,7 @@ flash_temp:
48547 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48548 {
48549 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48550 - static const struct qlcnic_dump_operations *fw_dump_ops;
48551 + const struct qlcnic_dump_operations *fw_dump_ops;
48552 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48553 u32 entry_offset, dump, no_entries, buf_offset = 0;
48554 int i, k, ops_cnt, ops_index, dump_size = 0;
48555 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48556 index 0921302..927f761 100644
48557 --- a/drivers/net/ethernet/realtek/r8169.c
48558 +++ b/drivers/net/ethernet/realtek/r8169.c
48559 @@ -744,22 +744,22 @@ struct rtl8169_private {
48560 struct mdio_ops {
48561 void (*write)(struct rtl8169_private *, int, int);
48562 int (*read)(struct rtl8169_private *, int);
48563 - } mdio_ops;
48564 + } __no_const mdio_ops;
48565
48566 struct pll_power_ops {
48567 void (*down)(struct rtl8169_private *);
48568 void (*up)(struct rtl8169_private *);
48569 - } pll_power_ops;
48570 + } __no_const pll_power_ops;
48571
48572 struct jumbo_ops {
48573 void (*enable)(struct rtl8169_private *);
48574 void (*disable)(struct rtl8169_private *);
48575 - } jumbo_ops;
48576 + } __no_const jumbo_ops;
48577
48578 struct csi_ops {
48579 void (*write)(struct rtl8169_private *, int, int);
48580 u32 (*read)(struct rtl8169_private *, int);
48581 - } csi_ops;
48582 + } __no_const csi_ops;
48583
48584 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48585 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48586 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48587 index 6b861e3..204ac86 100644
48588 --- a/drivers/net/ethernet/sfc/ptp.c
48589 +++ b/drivers/net/ethernet/sfc/ptp.c
48590 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48591 ptp->start.dma_addr);
48592
48593 /* Clear flag that signals MC ready */
48594 - ACCESS_ONCE(*start) = 0;
48595 + ACCESS_ONCE_RW(*start) = 0;
48596 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48597 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48598 EFX_BUG_ON_PARANOID(rc);
48599 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48600 index 08c483b..2c4a553 100644
48601 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48602 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48603 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48604
48605 writel(value, ioaddr + MMC_CNTRL);
48606
48607 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48608 - MMC_CNTRL, value);
48609 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48610 +// MMC_CNTRL, value);
48611 }
48612
48613 /* To mask all all interrupts.*/
48614 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48615 index d5e07de..e3bf20a 100644
48616 --- a/drivers/net/hyperv/hyperv_net.h
48617 +++ b/drivers/net/hyperv/hyperv_net.h
48618 @@ -171,7 +171,7 @@ struct rndis_device {
48619 enum rndis_device_state state;
48620 bool link_state;
48621 bool link_change;
48622 - atomic_t new_req_id;
48623 + atomic_unchecked_t new_req_id;
48624
48625 spinlock_t request_lock;
48626 struct list_head req_list;
48627 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48628 index 2b86f0b..ecc996f 100644
48629 --- a/drivers/net/hyperv/rndis_filter.c
48630 +++ b/drivers/net/hyperv/rndis_filter.c
48631 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48632 * template
48633 */
48634 set = &rndis_msg->msg.set_req;
48635 - set->req_id = atomic_inc_return(&dev->new_req_id);
48636 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48637
48638 /* Add to the request list */
48639 spin_lock_irqsave(&dev->request_lock, flags);
48640 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48641
48642 /* Setup the rndis set */
48643 halt = &request->request_msg.msg.halt_req;
48644 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48645 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48646
48647 /* Ignore return since this msg is optional. */
48648 rndis_filter_send_request(dev, request);
48649 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48650 index 9ce854f..e43fa17 100644
48651 --- a/drivers/net/ieee802154/fakehard.c
48652 +++ b/drivers/net/ieee802154/fakehard.c
48653 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48654 phy->transmit_power = 0xbf;
48655
48656 dev->netdev_ops = &fake_ops;
48657 - dev->ml_priv = &fake_mlme;
48658 + dev->ml_priv = (void *)&fake_mlme;
48659
48660 priv = netdev_priv(dev);
48661 priv->phy = phy;
48662 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48663 index 5f17ad0..e0463c8 100644
48664 --- a/drivers/net/macvlan.c
48665 +++ b/drivers/net/macvlan.c
48666 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48667 free_nskb:
48668 kfree_skb(nskb);
48669 err:
48670 - atomic_long_inc(&skb->dev->rx_dropped);
48671 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48672 }
48673
48674 /* called under rcu_read_lock() from netif_receive_skb */
48675 @@ -1150,13 +1150,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48676 int macvlan_link_register(struct rtnl_link_ops *ops)
48677 {
48678 /* common fields */
48679 - ops->priv_size = sizeof(struct macvlan_dev);
48680 - ops->validate = macvlan_validate;
48681 - ops->maxtype = IFLA_MACVLAN_MAX;
48682 - ops->policy = macvlan_policy;
48683 - ops->changelink = macvlan_changelink;
48684 - ops->get_size = macvlan_get_size;
48685 - ops->fill_info = macvlan_fill_info;
48686 + pax_open_kernel();
48687 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48688 + *(void **)&ops->validate = macvlan_validate;
48689 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48690 + *(const void **)&ops->policy = macvlan_policy;
48691 + *(void **)&ops->changelink = macvlan_changelink;
48692 + *(void **)&ops->get_size = macvlan_get_size;
48693 + *(void **)&ops->fill_info = macvlan_fill_info;
48694 + pax_close_kernel();
48695
48696 return rtnl_link_register(ops);
48697 };
48698 @@ -1236,7 +1238,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48699 return NOTIFY_DONE;
48700 }
48701
48702 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48703 +static struct notifier_block macvlan_notifier_block = {
48704 .notifier_call = macvlan_device_event,
48705 };
48706
48707 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48708 index 07c942b..2d8b073 100644
48709 --- a/drivers/net/macvtap.c
48710 +++ b/drivers/net/macvtap.c
48711 @@ -1023,7 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48712 }
48713
48714 ret = 0;
48715 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48716 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48717 put_user(q->flags, &ifr->ifr_flags))
48718 ret = -EFAULT;
48719 macvtap_put_vlan(vlan);
48720 @@ -1193,7 +1193,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48721 return NOTIFY_DONE;
48722 }
48723
48724 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48725 +static struct notifier_block macvtap_notifier_block = {
48726 .notifier_call = macvtap_device_event,
48727 };
48728
48729 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48730 index 17ecdd6..79ad848 100644
48731 --- a/drivers/net/ppp/ppp_generic.c
48732 +++ b/drivers/net/ppp/ppp_generic.c
48733 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48734 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48735 struct ppp_stats stats;
48736 struct ppp_comp_stats cstats;
48737 - char *vers;
48738
48739 switch (cmd) {
48740 case SIOCGPPPSTATS:
48741 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48742 break;
48743
48744 case SIOCGPPPVER:
48745 - vers = PPP_VERSION;
48746 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48747 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48748 break;
48749 err = 0;
48750 break;
48751 diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
48752 index 1aff970..cc2ee29 100644
48753 --- a/drivers/net/ppp/pptp.c
48754 +++ b/drivers/net/ppp/pptp.c
48755 @@ -506,7 +506,9 @@ static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
48756 int len = sizeof(struct sockaddr_pppox);
48757 struct sockaddr_pppox sp;
48758
48759 - sp.sa_family = AF_PPPOX;
48760 + memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
48761 +
48762 + sp.sa_family = AF_PPPOX;
48763 sp.sa_protocol = PX_PROTO_PPTP;
48764 sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
48765
48766 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48767 index 079f7ad..b2a2bfa7 100644
48768 --- a/drivers/net/slip/slhc.c
48769 +++ b/drivers/net/slip/slhc.c
48770 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48771 register struct tcphdr *thp;
48772 register struct iphdr *ip;
48773 register struct cstate *cs;
48774 - int len, hdrlen;
48775 + long len, hdrlen;
48776 unsigned char *cp = icp;
48777
48778 /* We've got a compressed packet; read the change byte */
48779 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48780 index 1f76c2ea..9681171 100644
48781 --- a/drivers/net/team/team.c
48782 +++ b/drivers/net/team/team.c
48783 @@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
48784 return NOTIFY_DONE;
48785 }
48786
48787 -static struct notifier_block team_notifier_block __read_mostly = {
48788 +static struct notifier_block team_notifier_block = {
48789 .notifier_call = team_device_event,
48790 };
48791
48792 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48793 index d965e8a..f119e64 100644
48794 --- a/drivers/net/tun.c
48795 +++ b/drivers/net/tun.c
48796 @@ -1861,7 +1861,7 @@ unlock:
48797 }
48798
48799 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48800 - unsigned long arg, int ifreq_len)
48801 + unsigned long arg, size_t ifreq_len)
48802 {
48803 struct tun_file *tfile = file->private_data;
48804 struct tun_struct *tun;
48805 @@ -1874,6 +1874,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48806 unsigned int ifindex;
48807 int ret;
48808
48809 + if (ifreq_len > sizeof ifr)
48810 + return -EFAULT;
48811 +
48812 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48813 if (copy_from_user(&ifr, argp, ifreq_len))
48814 return -EFAULT;
48815 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48816 index babda7d..e40c90a 100644
48817 --- a/drivers/net/usb/hso.c
48818 +++ b/drivers/net/usb/hso.c
48819 @@ -71,7 +71,7 @@
48820 #include <asm/byteorder.h>
48821 #include <linux/serial_core.h>
48822 #include <linux/serial.h>
48823 -
48824 +#include <asm/local.h>
48825
48826 #define MOD_AUTHOR "Option Wireless"
48827 #define MOD_DESCRIPTION "USB High Speed Option driver"
48828 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48829 struct urb *urb;
48830
48831 urb = serial->rx_urb[0];
48832 - if (serial->port.count > 0) {
48833 + if (atomic_read(&serial->port.count) > 0) {
48834 count = put_rxbuf_data(urb, serial);
48835 if (count == -1)
48836 return;
48837 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48838 DUMP1(urb->transfer_buffer, urb->actual_length);
48839
48840 /* Anyone listening? */
48841 - if (serial->port.count == 0)
48842 + if (atomic_read(&serial->port.count) == 0)
48843 return;
48844
48845 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48846 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48847 tty_port_tty_set(&serial->port, tty);
48848
48849 /* check for port already opened, if not set the termios */
48850 - serial->port.count++;
48851 - if (serial->port.count == 1) {
48852 + if (atomic_inc_return(&serial->port.count) == 1) {
48853 serial->rx_state = RX_IDLE;
48854 /* Force default termio settings */
48855 _hso_serial_set_termios(tty, NULL);
48856 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48857 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48858 if (result) {
48859 hso_stop_serial_device(serial->parent);
48860 - serial->port.count--;
48861 + atomic_dec(&serial->port.count);
48862 kref_put(&serial->parent->ref, hso_serial_ref_free);
48863 }
48864 } else {
48865 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48866
48867 /* reset the rts and dtr */
48868 /* do the actual close */
48869 - serial->port.count--;
48870 + atomic_dec(&serial->port.count);
48871
48872 - if (serial->port.count <= 0) {
48873 - serial->port.count = 0;
48874 + if (atomic_read(&serial->port.count) <= 0) {
48875 + atomic_set(&serial->port.count, 0);
48876 tty_port_tty_set(&serial->port, NULL);
48877 if (!usb_gone)
48878 hso_stop_serial_device(serial->parent);
48879 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48880
48881 /* the actual setup */
48882 spin_lock_irqsave(&serial->serial_lock, flags);
48883 - if (serial->port.count)
48884 + if (atomic_read(&serial->port.count))
48885 _hso_serial_set_termios(tty, old);
48886 else
48887 tty->termios = *old;
48888 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48889 D1("Pending read interrupt on port %d\n", i);
48890 spin_lock(&serial->serial_lock);
48891 if (serial->rx_state == RX_IDLE &&
48892 - serial->port.count > 0) {
48893 + atomic_read(&serial->port.count) > 0) {
48894 /* Setup and send a ctrl req read on
48895 * port i */
48896 if (!serial->rx_urb_filled[0]) {
48897 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48898 /* Start all serial ports */
48899 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48900 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48901 - if (dev2ser(serial_table[i])->port.count) {
48902 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48903 result =
48904 hso_start_serial_device(serial_table[i], GFP_NOIO);
48905 hso_kick_transmit(dev2ser(serial_table[i]));
48906 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48907 index 604ef21..d1f49a1 100644
48908 --- a/drivers/net/usb/r8152.c
48909 +++ b/drivers/net/usb/r8152.c
48910 @@ -575,7 +575,7 @@ struct r8152 {
48911 void (*up)(struct r8152 *);
48912 void (*down)(struct r8152 *);
48913 void (*unload)(struct r8152 *);
48914 - } rtl_ops;
48915 + } __no_const rtl_ops;
48916
48917 int intr_interval;
48918 u32 saved_wolopts;
48919 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48920 index a2515887..6d13233 100644
48921 --- a/drivers/net/usb/sierra_net.c
48922 +++ b/drivers/net/usb/sierra_net.c
48923 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48924 /* atomic counter partially included in MAC address to make sure 2 devices
48925 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48926 */
48927 -static atomic_t iface_counter = ATOMIC_INIT(0);
48928 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48929
48930 /*
48931 * SYNC Timer Delay definition used to set the expiry time
48932 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48933 dev->net->netdev_ops = &sierra_net_device_ops;
48934
48935 /* change MAC addr to include, ifacenum, and to be unique */
48936 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48937 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48938 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48939
48940 /* we will have to manufacture ethernet headers, prepare template */
48941 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48942 index 59caa06..de191b3 100644
48943 --- a/drivers/net/virtio_net.c
48944 +++ b/drivers/net/virtio_net.c
48945 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48946 #define RECEIVE_AVG_WEIGHT 64
48947
48948 /* Minimum alignment for mergeable packet buffers. */
48949 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48950 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48951
48952 #define VIRTNET_DRIVER_VERSION "1.0.0"
48953
48954 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48955 index 81a8a29..ae60a58 100644
48956 --- a/drivers/net/vxlan.c
48957 +++ b/drivers/net/vxlan.c
48958 @@ -2762,7 +2762,7 @@ nla_put_failure:
48959 return -EMSGSIZE;
48960 }
48961
48962 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48963 +static struct rtnl_link_ops vxlan_link_ops = {
48964 .kind = "vxlan",
48965 .maxtype = IFLA_VXLAN_MAX,
48966 .policy = vxlan_policy,
48967 @@ -2809,7 +2809,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48968 return NOTIFY_DONE;
48969 }
48970
48971 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48972 +static struct notifier_block vxlan_notifier_block = {
48973 .notifier_call = vxlan_lowerdev_event,
48974 };
48975
48976 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48977 index 5920c99..ff2e4a5 100644
48978 --- a/drivers/net/wan/lmc/lmc_media.c
48979 +++ b/drivers/net/wan/lmc/lmc_media.c
48980 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48981 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48982
48983 lmc_media_t lmc_ds3_media = {
48984 - lmc_ds3_init, /* special media init stuff */
48985 - lmc_ds3_default, /* reset to default state */
48986 - lmc_ds3_set_status, /* reset status to state provided */
48987 - lmc_dummy_set_1, /* set clock source */
48988 - lmc_dummy_set2_1, /* set line speed */
48989 - lmc_ds3_set_100ft, /* set cable length */
48990 - lmc_ds3_set_scram, /* set scrambler */
48991 - lmc_ds3_get_link_status, /* get link status */
48992 - lmc_dummy_set_1, /* set link status */
48993 - lmc_ds3_set_crc_length, /* set CRC length */
48994 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48995 - lmc_ds3_watchdog
48996 + .init = lmc_ds3_init, /* special media init stuff */
48997 + .defaults = lmc_ds3_default, /* reset to default state */
48998 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48999 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49000 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49001 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49002 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49003 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49004 + .set_link_status = lmc_dummy_set_1, /* set link status */
49005 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49006 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49007 + .watchdog = lmc_ds3_watchdog
49008 };
49009
49010 lmc_media_t lmc_hssi_media = {
49011 - lmc_hssi_init, /* special media init stuff */
49012 - lmc_hssi_default, /* reset to default state */
49013 - lmc_hssi_set_status, /* reset status to state provided */
49014 - lmc_hssi_set_clock, /* set clock source */
49015 - lmc_dummy_set2_1, /* set line speed */
49016 - lmc_dummy_set_1, /* set cable length */
49017 - lmc_dummy_set_1, /* set scrambler */
49018 - lmc_hssi_get_link_status, /* get link status */
49019 - lmc_hssi_set_link_status, /* set link status */
49020 - lmc_hssi_set_crc_length, /* set CRC length */
49021 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49022 - lmc_hssi_watchdog
49023 + .init = lmc_hssi_init, /* special media init stuff */
49024 + .defaults = lmc_hssi_default, /* reset to default state */
49025 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49026 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49027 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49028 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49029 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49030 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49031 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49032 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49033 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49034 + .watchdog = lmc_hssi_watchdog
49035 };
49036
49037 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49038 - lmc_ssi_default, /* reset to default state */
49039 - lmc_ssi_set_status, /* reset status to state provided */
49040 - lmc_ssi_set_clock, /* set clock source */
49041 - lmc_ssi_set_speed, /* set line speed */
49042 - lmc_dummy_set_1, /* set cable length */
49043 - lmc_dummy_set_1, /* set scrambler */
49044 - lmc_ssi_get_link_status, /* get link status */
49045 - lmc_ssi_set_link_status, /* set link status */
49046 - lmc_ssi_set_crc_length, /* set CRC length */
49047 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49048 - lmc_ssi_watchdog
49049 +lmc_media_t lmc_ssi_media = {
49050 + .init = lmc_ssi_init, /* special media init stuff */
49051 + .defaults = lmc_ssi_default, /* reset to default state */
49052 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49053 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49054 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49055 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49056 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49057 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49058 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49059 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49060 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49061 + .watchdog = lmc_ssi_watchdog
49062 };
49063
49064 lmc_media_t lmc_t1_media = {
49065 - lmc_t1_init, /* special media init stuff */
49066 - lmc_t1_default, /* reset to default state */
49067 - lmc_t1_set_status, /* reset status to state provided */
49068 - lmc_t1_set_clock, /* set clock source */
49069 - lmc_dummy_set2_1, /* set line speed */
49070 - lmc_dummy_set_1, /* set cable length */
49071 - lmc_dummy_set_1, /* set scrambler */
49072 - lmc_t1_get_link_status, /* get link status */
49073 - lmc_dummy_set_1, /* set link status */
49074 - lmc_t1_set_crc_length, /* set CRC length */
49075 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49076 - lmc_t1_watchdog
49077 + .init = lmc_t1_init, /* special media init stuff */
49078 + .defaults = lmc_t1_default, /* reset to default state */
49079 + .set_status = lmc_t1_set_status, /* reset status to state provided */
49080 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
49081 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49082 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49083 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49084 + .get_link_status = lmc_t1_get_link_status, /* get link status */
49085 + .set_link_status = lmc_dummy_set_1, /* set link status */
49086 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49087 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49088 + .watchdog = lmc_t1_watchdog
49089 };
49090
49091 static void
49092 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49093 index feacc3b..5bac0de 100644
49094 --- a/drivers/net/wan/z85230.c
49095 +++ b/drivers/net/wan/z85230.c
49096 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49097
49098 struct z8530_irqhandler z8530_sync =
49099 {
49100 - z8530_rx,
49101 - z8530_tx,
49102 - z8530_status
49103 + .rx = z8530_rx,
49104 + .tx = z8530_tx,
49105 + .status = z8530_status
49106 };
49107
49108 EXPORT_SYMBOL(z8530_sync);
49109 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49110 }
49111
49112 static struct z8530_irqhandler z8530_dma_sync = {
49113 - z8530_dma_rx,
49114 - z8530_dma_tx,
49115 - z8530_dma_status
49116 + .rx = z8530_dma_rx,
49117 + .tx = z8530_dma_tx,
49118 + .status = z8530_dma_status
49119 };
49120
49121 static struct z8530_irqhandler z8530_txdma_sync = {
49122 - z8530_rx,
49123 - z8530_dma_tx,
49124 - z8530_dma_status
49125 + .rx = z8530_rx,
49126 + .tx = z8530_dma_tx,
49127 + .status = z8530_dma_status
49128 };
49129
49130 /**
49131 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49132
49133 struct z8530_irqhandler z8530_nop=
49134 {
49135 - z8530_rx_clear,
49136 - z8530_tx_clear,
49137 - z8530_status_clear
49138 + .rx = z8530_rx_clear,
49139 + .tx = z8530_tx_clear,
49140 + .status = z8530_status_clear
49141 };
49142
49143
49144 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49145 index 0b60295..b8bfa5b 100644
49146 --- a/drivers/net/wimax/i2400m/rx.c
49147 +++ b/drivers/net/wimax/i2400m/rx.c
49148 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49149 if (i2400m->rx_roq == NULL)
49150 goto error_roq_alloc;
49151
49152 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49153 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49154 GFP_KERNEL);
49155 if (rd == NULL) {
49156 result = -ENOMEM;
49157 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49158 index e71a2ce..2268d61 100644
49159 --- a/drivers/net/wireless/airo.c
49160 +++ b/drivers/net/wireless/airo.c
49161 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49162 struct airo_info *ai = dev->ml_priv;
49163 int ridcode;
49164 int enabled;
49165 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49166 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49167 unsigned char *iobuf;
49168
49169 /* Only super-user can write RIDs */
49170 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49171 index da92bfa..5a9001a 100644
49172 --- a/drivers/net/wireless/at76c50x-usb.c
49173 +++ b/drivers/net/wireless/at76c50x-usb.c
49174 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49175 }
49176
49177 /* Convert timeout from the DFU status to jiffies */
49178 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49179 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49180 {
49181 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49182 | (s->poll_timeout[1] << 8)
49183 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49184 index 5fdc40d..3975205 100644
49185 --- a/drivers/net/wireless/ath/ath10k/htc.c
49186 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49187 @@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49188 /* registered target arrival callback from the HIF layer */
49189 int ath10k_htc_init(struct ath10k *ar)
49190 {
49191 - struct ath10k_hif_cb htc_callbacks;
49192 + static struct ath10k_hif_cb htc_callbacks = {
49193 + .rx_completion = ath10k_htc_rx_completion_handler,
49194 + .tx_completion = ath10k_htc_tx_completion_handler,
49195 + };
49196 struct ath10k_htc_ep *ep = NULL;
49197 struct ath10k_htc *htc = &ar->htc;
49198
49199 @@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
49200 ath10k_htc_reset_endpoint_states(htc);
49201
49202 /* setup HIF layer callbacks */
49203 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49204 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49205 htc->ar = ar;
49206
49207 /* Get HIF default pipe for HTC message exchange */
49208 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49209 index 4716d33..a688310 100644
49210 --- a/drivers/net/wireless/ath/ath10k/htc.h
49211 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49212 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
49213
49214 struct ath10k_htc_ops {
49215 void (*target_send_suspend_complete)(struct ath10k *ar);
49216 -};
49217 +} __no_const;
49218
49219 struct ath10k_htc_ep_ops {
49220 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49221 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49222 void (*ep_tx_credits)(struct ath10k *);
49223 -};
49224 +} __no_const;
49225
49226 /* service connection information */
49227 struct ath10k_htc_svc_conn_req {
49228 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49229 index 59af9f9..5f3564f 100644
49230 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49231 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49232 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49233 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49234 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49235
49236 - ACCESS_ONCE(ads->ds_link) = i->link;
49237 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49238 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49239 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49240
49241 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49242 ctl6 = SM(i->keytype, AR_EncrType);
49243 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49244
49245 if ((i->is_first || i->is_last) &&
49246 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49247 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49248 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49249 | set11nTries(i->rates, 1)
49250 | set11nTries(i->rates, 2)
49251 | set11nTries(i->rates, 3)
49252 | (i->dur_update ? AR_DurUpdateEna : 0)
49253 | SM(0, AR_BurstDur);
49254
49255 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49256 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49257 | set11nRate(i->rates, 1)
49258 | set11nRate(i->rates, 2)
49259 | set11nRate(i->rates, 3);
49260 } else {
49261 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49262 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49263 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49264 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49265 }
49266
49267 if (!i->is_first) {
49268 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49269 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49270 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49271 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49272 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49273 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49274 return;
49275 }
49276
49277 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49278 break;
49279 }
49280
49281 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49282 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49283 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49284 | SM(i->txpower, AR_XmitPower0)
49285 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49286 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49287 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49288 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49289
49290 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49291 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49292 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49293 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49294
49295 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49296 return;
49297
49298 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49299 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49300 | set11nPktDurRTSCTS(i->rates, 1);
49301
49302 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49303 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49304 | set11nPktDurRTSCTS(i->rates, 3);
49305
49306 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49307 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49308 | set11nRateFlags(i->rates, 1)
49309 | set11nRateFlags(i->rates, 2)
49310 | set11nRateFlags(i->rates, 3)
49311 | SM(i->rtscts_rate, AR_RTSCTSRate);
49312
49313 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49314 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49315 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49316 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49317 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49318 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49319 }
49320
49321 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49322 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49323 index 71e38e8..5ac96ca 100644
49324 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49325 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49326 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49327 (i->qcu << AR_TxQcuNum_S) | desc_len;
49328
49329 checksum += val;
49330 - ACCESS_ONCE(ads->info) = val;
49331 + ACCESS_ONCE_RW(ads->info) = val;
49332
49333 checksum += i->link;
49334 - ACCESS_ONCE(ads->link) = i->link;
49335 + ACCESS_ONCE_RW(ads->link) = i->link;
49336
49337 checksum += i->buf_addr[0];
49338 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49339 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49340 checksum += i->buf_addr[1];
49341 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49342 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49343 checksum += i->buf_addr[2];
49344 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49345 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49346 checksum += i->buf_addr[3];
49347 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49348 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49349
49350 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49351 - ACCESS_ONCE(ads->ctl3) = val;
49352 + ACCESS_ONCE_RW(ads->ctl3) = val;
49353 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49354 - ACCESS_ONCE(ads->ctl5) = val;
49355 + ACCESS_ONCE_RW(ads->ctl5) = val;
49356 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49357 - ACCESS_ONCE(ads->ctl7) = val;
49358 + ACCESS_ONCE_RW(ads->ctl7) = val;
49359 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49360 - ACCESS_ONCE(ads->ctl9) = val;
49361 + ACCESS_ONCE_RW(ads->ctl9) = val;
49362
49363 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49364 - ACCESS_ONCE(ads->ctl10) = checksum;
49365 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49366
49367 if (i->is_first || i->is_last) {
49368 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49369 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49370 | set11nTries(i->rates, 1)
49371 | set11nTries(i->rates, 2)
49372 | set11nTries(i->rates, 3)
49373 | (i->dur_update ? AR_DurUpdateEna : 0)
49374 | SM(0, AR_BurstDur);
49375
49376 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49377 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49378 | set11nRate(i->rates, 1)
49379 | set11nRate(i->rates, 2)
49380 | set11nRate(i->rates, 3);
49381 } else {
49382 - ACCESS_ONCE(ads->ctl13) = 0;
49383 - ACCESS_ONCE(ads->ctl14) = 0;
49384 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49385 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49386 }
49387
49388 ads->ctl20 = 0;
49389 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49390
49391 ctl17 = SM(i->keytype, AR_EncrType);
49392 if (!i->is_first) {
49393 - ACCESS_ONCE(ads->ctl11) = 0;
49394 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49395 - ACCESS_ONCE(ads->ctl15) = 0;
49396 - ACCESS_ONCE(ads->ctl16) = 0;
49397 - ACCESS_ONCE(ads->ctl17) = ctl17;
49398 - ACCESS_ONCE(ads->ctl18) = 0;
49399 - ACCESS_ONCE(ads->ctl19) = 0;
49400 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49401 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49402 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49403 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49404 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49405 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49406 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49407 return;
49408 }
49409
49410 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49411 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49412 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49413 | SM(i->txpower, AR_XmitPower0)
49414 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49415 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49416 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49417 ctl12 |= SM(val, AR_PAPRDChainMask);
49418
49419 - ACCESS_ONCE(ads->ctl12) = ctl12;
49420 - ACCESS_ONCE(ads->ctl17) = ctl17;
49421 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49422 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49423
49424 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49425 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49426 | set11nPktDurRTSCTS(i->rates, 1);
49427
49428 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49429 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49430 | set11nPktDurRTSCTS(i->rates, 3);
49431
49432 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49433 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49434 | set11nRateFlags(i->rates, 1)
49435 | set11nRateFlags(i->rates, 2)
49436 | set11nRateFlags(i->rates, 3)
49437 | SM(i->rtscts_rate, AR_RTSCTSRate);
49438
49439 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49440 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49441
49442 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49443 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49444 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49445 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49446 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49447 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49448 }
49449
49450 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49451 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49452 index 51b4ebe..d1929dd 100644
49453 --- a/drivers/net/wireless/ath/ath9k/hw.h
49454 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49455 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
49456
49457 /* ANI */
49458 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49459 -};
49460 +} __no_const;
49461
49462 /**
49463 * struct ath_spec_scan - parameters for Atheros spectral scan
49464 @@ -706,7 +706,7 @@ struct ath_hw_ops {
49465 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49466 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49467 #endif
49468 -};
49469 +} __no_const;
49470
49471 struct ath_nf_limits {
49472 s16 max;
49473 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49474 index 4b148bb..ac738fa 100644
49475 --- a/drivers/net/wireless/ath/ath9k/main.c
49476 +++ b/drivers/net/wireless/ath/ath9k/main.c
49477 @@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
49478 if (!ath9k_use_chanctx)
49479 return;
49480
49481 - ath9k_ops.hw_scan = ath9k_hw_scan;
49482 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49483 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49484 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49485 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49486 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49487 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49488 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49489 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49490 - ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49491 + pax_open_kernel();
49492 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49493 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49494 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49495 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49496 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49497 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49498 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49499 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49500 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49501 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49502 + pax_close_kernel();
49503 }
49504
49505 struct ieee80211_ops ath9k_ops = {
49506 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49507 index 92190da..f3a4c4c 100644
49508 --- a/drivers/net/wireless/b43/phy_lp.c
49509 +++ b/drivers/net/wireless/b43/phy_lp.c
49510 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49511 {
49512 struct ssb_bus *bus = dev->dev->sdev->bus;
49513
49514 - static const struct b206x_channel *chandata = NULL;
49515 + const struct b206x_channel *chandata = NULL;
49516 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49517 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49518 u16 old_comm15, scale;
49519 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49520 index dc1d20c..f7a4f06 100644
49521 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49522 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49523 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49524 */
49525 if (il3945_mod_params.disable_hw_scan) {
49526 D_INFO("Disabling hw_scan\n");
49527 - il3945_mac_ops.hw_scan = NULL;
49528 + pax_open_kernel();
49529 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49530 + pax_close_kernel();
49531 }
49532
49533 D_INFO("*** LOAD DRIVER ***\n");
49534 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49535 index 0ffb6ff..c0b7f0e 100644
49536 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49537 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49538 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49539 {
49540 struct iwl_priv *priv = file->private_data;
49541 char buf[64];
49542 - int buf_size;
49543 + size_t buf_size;
49544 u32 offset, len;
49545
49546 memset(buf, 0, sizeof(buf));
49547 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49548 struct iwl_priv *priv = file->private_data;
49549
49550 char buf[8];
49551 - int buf_size;
49552 + size_t buf_size;
49553 u32 reset_flag;
49554
49555 memset(buf, 0, sizeof(buf));
49556 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49557 {
49558 struct iwl_priv *priv = file->private_data;
49559 char buf[8];
49560 - int buf_size;
49561 + size_t buf_size;
49562 int ht40;
49563
49564 memset(buf, 0, sizeof(buf));
49565 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49566 {
49567 struct iwl_priv *priv = file->private_data;
49568 char buf[8];
49569 - int buf_size;
49570 + size_t buf_size;
49571 int value;
49572
49573 memset(buf, 0, sizeof(buf));
49574 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49575 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49576 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49577
49578 -static const char *fmt_value = " %-30s %10u\n";
49579 -static const char *fmt_hex = " %-30s 0x%02X\n";
49580 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49581 -static const char *fmt_header =
49582 +static const char fmt_value[] = " %-30s %10u\n";
49583 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49584 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49585 +static const char fmt_header[] =
49586 "%-32s current cumulative delta max\n";
49587
49588 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49589 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49590 {
49591 struct iwl_priv *priv = file->private_data;
49592 char buf[8];
49593 - int buf_size;
49594 + size_t buf_size;
49595 int clear;
49596
49597 memset(buf, 0, sizeof(buf));
49598 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49599 {
49600 struct iwl_priv *priv = file->private_data;
49601 char buf[8];
49602 - int buf_size;
49603 + size_t buf_size;
49604 int trace;
49605
49606 memset(buf, 0, sizeof(buf));
49607 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49608 {
49609 struct iwl_priv *priv = file->private_data;
49610 char buf[8];
49611 - int buf_size;
49612 + size_t buf_size;
49613 int missed;
49614
49615 memset(buf, 0, sizeof(buf));
49616 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49617
49618 struct iwl_priv *priv = file->private_data;
49619 char buf[8];
49620 - int buf_size;
49621 + size_t buf_size;
49622 int plcp;
49623
49624 memset(buf, 0, sizeof(buf));
49625 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49626
49627 struct iwl_priv *priv = file->private_data;
49628 char buf[8];
49629 - int buf_size;
49630 + size_t buf_size;
49631 int flush;
49632
49633 memset(buf, 0, sizeof(buf));
49634 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49635
49636 struct iwl_priv *priv = file->private_data;
49637 char buf[8];
49638 - int buf_size;
49639 + size_t buf_size;
49640 int rts;
49641
49642 if (!priv->cfg->ht_params)
49643 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49644 {
49645 struct iwl_priv *priv = file->private_data;
49646 char buf[8];
49647 - int buf_size;
49648 + size_t buf_size;
49649
49650 memset(buf, 0, sizeof(buf));
49651 buf_size = min(count, sizeof(buf) - 1);
49652 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49653 struct iwl_priv *priv = file->private_data;
49654 u32 event_log_flag;
49655 char buf[8];
49656 - int buf_size;
49657 + size_t buf_size;
49658
49659 /* check that the interface is up */
49660 if (!iwl_is_ready(priv))
49661 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49662 struct iwl_priv *priv = file->private_data;
49663 char buf[8];
49664 u32 calib_disabled;
49665 - int buf_size;
49666 + size_t buf_size;
49667
49668 memset(buf, 0, sizeof(buf));
49669 buf_size = min(count, sizeof(buf) - 1);
49670 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49671 index 6c02467..771bb8a 100644
49672 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49673 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49674 @@ -1686,7 +1686,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49675 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49676
49677 char buf[8];
49678 - int buf_size;
49679 + size_t buf_size;
49680 u32 reset_flag;
49681
49682 memset(buf, 0, sizeof(buf));
49683 @@ -1707,7 +1707,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49684 {
49685 struct iwl_trans *trans = file->private_data;
49686 char buf[8];
49687 - int buf_size;
49688 + size_t buf_size;
49689 int csr;
49690
49691 memset(buf, 0, sizeof(buf));
49692 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49693 index 6b48c865..19646a7 100644
49694 --- a/drivers/net/wireless/mac80211_hwsim.c
49695 +++ b/drivers/net/wireless/mac80211_hwsim.c
49696 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49697 if (channels < 1)
49698 return -EINVAL;
49699
49700 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49701 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49702 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49703 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49704 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49705 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49706 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49707 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49708 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49709 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49710 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49711 - mac80211_hwsim_assign_vif_chanctx;
49712 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49713 - mac80211_hwsim_unassign_vif_chanctx;
49714 + pax_open_kernel();
49715 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49716 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49717 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49718 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49719 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49720 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49721 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49722 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49723 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49724 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49725 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49726 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49727 + pax_close_kernel();
49728
49729 spin_lock_init(&hwsim_radio_lock);
49730 INIT_LIST_HEAD(&hwsim_radios);
49731 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49732 index d2a9a08..0cb175d 100644
49733 --- a/drivers/net/wireless/rndis_wlan.c
49734 +++ b/drivers/net/wireless/rndis_wlan.c
49735 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49736
49737 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49738
49739 - if (rts_threshold < 0 || rts_threshold > 2347)
49740 + if (rts_threshold > 2347)
49741 rts_threshold = 2347;
49742
49743 tmp = cpu_to_le32(rts_threshold);
49744 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49745 index d13f25c..2573994 100644
49746 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49747 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49748 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49749 * for hardware which doesn't support hardware
49750 * sequence counting.
49751 */
49752 - atomic_t seqno;
49753 + atomic_unchecked_t seqno;
49754 };
49755
49756 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49757 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49758 index 8e68f87..c35ba29 100644
49759 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49760 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49761 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49762 * sequence counter given by mac80211.
49763 */
49764 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49765 - seqno = atomic_add_return(0x10, &intf->seqno);
49766 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49767 else
49768 - seqno = atomic_read(&intf->seqno);
49769 + seqno = atomic_read_unchecked(&intf->seqno);
49770
49771 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49772 hdr->seq_ctrl |= cpu_to_le16(seqno);
49773 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49774 index b661f896..ddf7d2b 100644
49775 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49776 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49777 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49778
49779 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49780
49781 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49782 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49783 + pax_open_kernel();
49784 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49785 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49786 + pax_close_kernel();
49787
49788 wl1251_info("using dedicated interrupt line");
49789 } else {
49790 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49791 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49792 + pax_open_kernel();
49793 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49794 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49795 + pax_close_kernel();
49796
49797 wl1251_info("using SDIO interrupt");
49798 }
49799 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49800 index 0bccf12..3d95068 100644
49801 --- a/drivers/net/wireless/ti/wl12xx/main.c
49802 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49803 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49804 sizeof(wl->conf.mem));
49805
49806 /* read data preparation is only needed by wl127x */
49807 - wl->ops->prepare_read = wl127x_prepare_read;
49808 + pax_open_kernel();
49809 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49810 + pax_close_kernel();
49811
49812 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49813 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49814 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49815 sizeof(wl->conf.mem));
49816
49817 /* read data preparation is only needed by wl127x */
49818 - wl->ops->prepare_read = wl127x_prepare_read;
49819 + pax_open_kernel();
49820 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49821 + pax_close_kernel();
49822
49823 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49824 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49825 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49826 index 7af1936..128bb35 100644
49827 --- a/drivers/net/wireless/ti/wl18xx/main.c
49828 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49829 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49830 }
49831
49832 if (!checksum_param) {
49833 - wl18xx_ops.set_rx_csum = NULL;
49834 - wl18xx_ops.init_vif = NULL;
49835 + pax_open_kernel();
49836 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49837 + *(void **)&wl18xx_ops.init_vif = NULL;
49838 + pax_close_kernel();
49839 }
49840
49841 /* Enable 11a Band only if we have 5G antennas */
49842 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49843 index a912dc0..a8225ba 100644
49844 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49845 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49846 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49847 {
49848 struct zd_usb *usb = urb->context;
49849 struct zd_usb_interrupt *intr = &usb->intr;
49850 - int len;
49851 + unsigned int len;
49852 u16 int_num;
49853
49854 ZD_ASSERT(in_interrupt());
49855 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49856 index 683671a..4519fc2 100644
49857 --- a/drivers/nfc/nfcwilink.c
49858 +++ b/drivers/nfc/nfcwilink.c
49859 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49860
49861 static int nfcwilink_probe(struct platform_device *pdev)
49862 {
49863 - static struct nfcwilink *drv;
49864 + struct nfcwilink *drv;
49865 int rc;
49866 __u32 protocols;
49867
49868 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49869 index d93b2b6..ae50401 100644
49870 --- a/drivers/oprofile/buffer_sync.c
49871 +++ b/drivers/oprofile/buffer_sync.c
49872 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49873 if (cookie == NO_COOKIE)
49874 offset = pc;
49875 if (cookie == INVALID_COOKIE) {
49876 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49877 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49878 offset = pc;
49879 }
49880 if (cookie != last_cookie) {
49881 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49882 /* add userspace sample */
49883
49884 if (!mm) {
49885 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49886 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49887 return 0;
49888 }
49889
49890 cookie = lookup_dcookie(mm, s->eip, &offset);
49891
49892 if (cookie == INVALID_COOKIE) {
49893 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49894 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49895 return 0;
49896 }
49897
49898 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49899 /* ignore backtraces if failed to add a sample */
49900 if (state == sb_bt_start) {
49901 state = sb_bt_ignore;
49902 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49903 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49904 }
49905 }
49906 release_mm(mm);
49907 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49908 index c0cc4e7..44d4e54 100644
49909 --- a/drivers/oprofile/event_buffer.c
49910 +++ b/drivers/oprofile/event_buffer.c
49911 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49912 }
49913
49914 if (buffer_pos == buffer_size) {
49915 - atomic_inc(&oprofile_stats.event_lost_overflow);
49916 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49917 return;
49918 }
49919
49920 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49921 index ed2c3ec..deda85a 100644
49922 --- a/drivers/oprofile/oprof.c
49923 +++ b/drivers/oprofile/oprof.c
49924 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49925 if (oprofile_ops.switch_events())
49926 return;
49927
49928 - atomic_inc(&oprofile_stats.multiplex_counter);
49929 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49930 start_switch_worker();
49931 }
49932
49933 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49934 index ee2cfce..7f8f699 100644
49935 --- a/drivers/oprofile/oprofile_files.c
49936 +++ b/drivers/oprofile/oprofile_files.c
49937 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49938
49939 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49940
49941 -static ssize_t timeout_read(struct file *file, char __user *buf,
49942 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49943 size_t count, loff_t *offset)
49944 {
49945 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49946 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49947 index 59659ce..6c860a0 100644
49948 --- a/drivers/oprofile/oprofile_stats.c
49949 +++ b/drivers/oprofile/oprofile_stats.c
49950 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49951 cpu_buf->sample_invalid_eip = 0;
49952 }
49953
49954 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49955 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49956 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49957 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49958 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49959 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49960 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49961 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49962 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49963 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49964 }
49965
49966
49967 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49968 index 1fc622b..8c48fc3 100644
49969 --- a/drivers/oprofile/oprofile_stats.h
49970 +++ b/drivers/oprofile/oprofile_stats.h
49971 @@ -13,11 +13,11 @@
49972 #include <linux/atomic.h>
49973
49974 struct oprofile_stat_struct {
49975 - atomic_t sample_lost_no_mm;
49976 - atomic_t sample_lost_no_mapping;
49977 - atomic_t bt_lost_no_mapping;
49978 - atomic_t event_lost_overflow;
49979 - atomic_t multiplex_counter;
49980 + atomic_unchecked_t sample_lost_no_mm;
49981 + atomic_unchecked_t sample_lost_no_mapping;
49982 + atomic_unchecked_t bt_lost_no_mapping;
49983 + atomic_unchecked_t event_lost_overflow;
49984 + atomic_unchecked_t multiplex_counter;
49985 };
49986
49987 extern struct oprofile_stat_struct oprofile_stats;
49988 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49989 index 3f49345..c750d0b 100644
49990 --- a/drivers/oprofile/oprofilefs.c
49991 +++ b/drivers/oprofile/oprofilefs.c
49992 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49993
49994 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49995 {
49996 - atomic_t *val = file->private_data;
49997 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49998 + atomic_unchecked_t *val = file->private_data;
49999 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50000 }
50001
50002
50003 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50004
50005
50006 int oprofilefs_create_ro_atomic(struct dentry *root,
50007 - char const *name, atomic_t *val)
50008 + char const *name, atomic_unchecked_t *val)
50009 {
50010 return __oprofilefs_create_file(root, name,
50011 &atomic_ro_fops, 0444, val);
50012 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50013 index 61be1d9..dec05d7 100644
50014 --- a/drivers/oprofile/timer_int.c
50015 +++ b/drivers/oprofile/timer_int.c
50016 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50017 return NOTIFY_OK;
50018 }
50019
50020 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50021 +static struct notifier_block oprofile_cpu_notifier = {
50022 .notifier_call = oprofile_cpu_notify,
50023 };
50024
50025 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50026 index 3b47080..6cd05dd 100644
50027 --- a/drivers/parport/procfs.c
50028 +++ b/drivers/parport/procfs.c
50029 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50030
50031 *ppos += len;
50032
50033 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50034 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50035 }
50036
50037 #ifdef CONFIG_PARPORT_1284
50038 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50039
50040 *ppos += len;
50041
50042 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50043 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50044 }
50045 #endif /* IEEE1284.3 support. */
50046
50047 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50048 index 8dcccff..35d701d 100644
50049 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50050 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50051 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50052 goto init_cleanup;
50053 }
50054
50055 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50056 + pax_open_kernel();
50057 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50058 + pax_close_kernel();
50059 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50060
50061 return retval;
50062 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50063 index 04fcd78..39e83f1 100644
50064 --- a/drivers/pci/hotplug/cpcihp_generic.c
50065 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50066 @@ -73,7 +73,6 @@ static u16 port;
50067 static unsigned int enum_bit;
50068 static u8 enum_mask;
50069
50070 -static struct cpci_hp_controller_ops generic_hpc_ops;
50071 static struct cpci_hp_controller generic_hpc;
50072
50073 static int __init validate_parameters(void)
50074 @@ -139,6 +138,10 @@ static int query_enum(void)
50075 return ((value & enum_mask) == enum_mask);
50076 }
50077
50078 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50079 + .query_enum = query_enum,
50080 +};
50081 +
50082 static int __init cpcihp_generic_init(void)
50083 {
50084 int status;
50085 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50086 pci_dev_put(dev);
50087
50088 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50089 - generic_hpc_ops.query_enum = query_enum;
50090 generic_hpc.ops = &generic_hpc_ops;
50091
50092 status = cpci_hp_register_controller(&generic_hpc);
50093 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50094 index 6757b3e..d3bad62 100644
50095 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50096 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50097 @@ -59,7 +59,6 @@
50098 /* local variables */
50099 static bool debug;
50100 static bool poll;
50101 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50102 static struct cpci_hp_controller zt5550_hpc;
50103
50104 /* Primary cPCI bus bridge device */
50105 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50106 return 0;
50107 }
50108
50109 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50110 + .query_enum = zt5550_hc_query_enum,
50111 +};
50112 +
50113 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50114 {
50115 int status;
50116 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50117 dbg("returned from zt5550_hc_config");
50118
50119 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50120 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50121 zt5550_hpc.ops = &zt5550_hpc_ops;
50122 if(!poll) {
50123 zt5550_hpc.irq = hc_dev->irq;
50124 zt5550_hpc.irq_flags = IRQF_SHARED;
50125 zt5550_hpc.dev_id = hc_dev;
50126
50127 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50128 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50129 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50130 + pax_open_kernel();
50131 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50132 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50133 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50134 + pax_open_kernel();
50135 } else {
50136 info("using ENUM# polling mode");
50137 }
50138 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50139 index 0968a9b..5a00edf 100644
50140 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50141 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50142 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50143
50144 void compaq_nvram_init (void __iomem *rom_start)
50145 {
50146 +
50147 +#ifndef CONFIG_PAX_KERNEXEC
50148 if (rom_start) {
50149 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50150 }
50151 +#endif
50152 +
50153 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50154
50155 /* initialize our int15 lock */
50156 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50157 index 56d8486..f26113f 100644
50158 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50159 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50160 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50161 return -EINVAL;
50162 }
50163
50164 - slot->ops->owner = owner;
50165 - slot->ops->mod_name = mod_name;
50166 + pax_open_kernel();
50167 + *(struct module **)&slot->ops->owner = owner;
50168 + *(const char **)&slot->ops->mod_name = mod_name;
50169 + pax_close_kernel();
50170
50171 mutex_lock(&pci_hp_mutex);
50172 /*
50173 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50174 index 07aa722..84514b4 100644
50175 --- a/drivers/pci/hotplug/pciehp_core.c
50176 +++ b/drivers/pci/hotplug/pciehp_core.c
50177 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50178 struct slot *slot = ctrl->slot;
50179 struct hotplug_slot *hotplug = NULL;
50180 struct hotplug_slot_info *info = NULL;
50181 - struct hotplug_slot_ops *ops = NULL;
50182 + hotplug_slot_ops_no_const *ops = NULL;
50183 char name[SLOT_NAME_SIZE];
50184 int retval = -ENOMEM;
50185
50186 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50187 index 5a40516..136d5a7 100644
50188 --- a/drivers/pci/msi.c
50189 +++ b/drivers/pci/msi.c
50190 @@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50191 {
50192 struct attribute **msi_attrs;
50193 struct attribute *msi_attr;
50194 - struct device_attribute *msi_dev_attr;
50195 - struct attribute_group *msi_irq_group;
50196 + device_attribute_no_const *msi_dev_attr;
50197 + attribute_group_no_const *msi_irq_group;
50198 const struct attribute_group **msi_irq_groups;
50199 struct msi_desc *entry;
50200 int ret = -ENOMEM;
50201 @@ -568,7 +568,7 @@ error_attrs:
50202 count = 0;
50203 msi_attr = msi_attrs[count];
50204 while (msi_attr) {
50205 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50206 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50207 kfree(msi_attr->name);
50208 kfree(msi_dev_attr);
50209 ++count;
50210 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50211 index 6d04771..4126004 100644
50212 --- a/drivers/pci/pci-sysfs.c
50213 +++ b/drivers/pci/pci-sysfs.c
50214 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50215 {
50216 /* allocate attribute structure, piggyback attribute name */
50217 int name_len = write_combine ? 13 : 10;
50218 - struct bin_attribute *res_attr;
50219 + bin_attribute_no_const *res_attr;
50220 int retval;
50221
50222 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50223 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50224 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50225 {
50226 int retval;
50227 - struct bin_attribute *attr;
50228 + bin_attribute_no_const *attr;
50229
50230 /* If the device has VPD, try to expose it in sysfs. */
50231 if (dev->vpd) {
50232 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50233 {
50234 int retval;
50235 int rom_size = 0;
50236 - struct bin_attribute *attr;
50237 + bin_attribute_no_const *attr;
50238
50239 if (!sysfs_initialized)
50240 return -EACCES;
50241 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50242 index 0601890..dc15007 100644
50243 --- a/drivers/pci/pci.h
50244 +++ b/drivers/pci/pci.h
50245 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
50246 struct pci_vpd {
50247 unsigned int len;
50248 const struct pci_vpd_ops *ops;
50249 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50250 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50251 };
50252
50253 int pci_vpd_pci22_init(struct pci_dev *dev);
50254 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50255 index e1e7026..d28dd33 100644
50256 --- a/drivers/pci/pcie/aspm.c
50257 +++ b/drivers/pci/pcie/aspm.c
50258 @@ -27,9 +27,9 @@
50259 #define MODULE_PARAM_PREFIX "pcie_aspm."
50260
50261 /* Note: those are not register definitions */
50262 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50263 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50264 -#define ASPM_STATE_L1 (4) /* L1 state */
50265 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50266 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50267 +#define ASPM_STATE_L1 (4U) /* L1 state */
50268 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50269 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50270
50271 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50272 index 4170113..7cc5339 100644
50273 --- a/drivers/pci/probe.c
50274 +++ b/drivers/pci/probe.c
50275 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50276 struct pci_bus_region region, inverted_region;
50277 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50278
50279 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50280 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50281
50282 /* No printks while decoding is disabled! */
50283 if (!dev->mmio_always_on) {
50284 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50285 index 3f155e7..0f4b1f0 100644
50286 --- a/drivers/pci/proc.c
50287 +++ b/drivers/pci/proc.c
50288 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50289 static int __init pci_proc_init(void)
50290 {
50291 struct pci_dev *dev = NULL;
50292 +
50293 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50294 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50295 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50296 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50297 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50298 +#endif
50299 +#else
50300 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50301 +#endif
50302 proc_create("devices", 0, proc_bus_pci_dir,
50303 &proc_bus_pci_dev_operations);
50304 proc_initialized = 1;
50305 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50306 index d866db8..c827d1f 100644
50307 --- a/drivers/platform/chrome/chromeos_laptop.c
50308 +++ b/drivers/platform/chrome/chromeos_laptop.c
50309 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50310 .callback = chromeos_laptop_dmi_matched, \
50311 .driver_data = (void *)&board_
50312
50313 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50314 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50315 {
50316 .ident = "Samsung Series 5 550",
50317 .matches = {
50318 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50319 index c5af23b..3d62d5e 100644
50320 --- a/drivers/platform/x86/alienware-wmi.c
50321 +++ b/drivers/platform/x86/alienware-wmi.c
50322 @@ -150,7 +150,7 @@ struct wmax_led_args {
50323 } __packed;
50324
50325 static struct platform_device *platform_device;
50326 -static struct device_attribute *zone_dev_attrs;
50327 +static device_attribute_no_const *zone_dev_attrs;
50328 static struct attribute **zone_attrs;
50329 static struct platform_zone *zone_data;
50330
50331 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50332 }
50333 };
50334
50335 -static struct attribute_group zone_attribute_group = {
50336 +static attribute_group_no_const zone_attribute_group = {
50337 .name = "rgb_zones",
50338 };
50339
50340 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50341 index 21fc932..ee9394a 100644
50342 --- a/drivers/platform/x86/asus-wmi.c
50343 +++ b/drivers/platform/x86/asus-wmi.c
50344 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50345 int err;
50346 u32 retval = -1;
50347
50348 +#ifdef CONFIG_GRKERNSEC_KMEM
50349 + return -EPERM;
50350 +#endif
50351 +
50352 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50353
50354 if (err < 0)
50355 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50356 int err;
50357 u32 retval = -1;
50358
50359 +#ifdef CONFIG_GRKERNSEC_KMEM
50360 + return -EPERM;
50361 +#endif
50362 +
50363 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50364 &retval);
50365
50366 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50367 union acpi_object *obj;
50368 acpi_status status;
50369
50370 +#ifdef CONFIG_GRKERNSEC_KMEM
50371 + return -EPERM;
50372 +#endif
50373 +
50374 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50375 1, asus->debug.method_id,
50376 &input, &output);
50377 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50378 index 62f8030..c7f2a45 100644
50379 --- a/drivers/platform/x86/msi-laptop.c
50380 +++ b/drivers/platform/x86/msi-laptop.c
50381 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50382
50383 if (!quirks->ec_read_only) {
50384 /* allow userland write sysfs file */
50385 - dev_attr_bluetooth.store = store_bluetooth;
50386 - dev_attr_wlan.store = store_wlan;
50387 - dev_attr_threeg.store = store_threeg;
50388 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50389 - dev_attr_wlan.attr.mode |= S_IWUSR;
50390 - dev_attr_threeg.attr.mode |= S_IWUSR;
50391 + pax_open_kernel();
50392 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50393 + *(void **)&dev_attr_wlan.store = store_wlan;
50394 + *(void **)&dev_attr_threeg.store = store_threeg;
50395 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50396 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50397 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50398 + pax_close_kernel();
50399 }
50400
50401 /* disable hardware control by fn key */
50402 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50403 index 70222f2..8c8ce66 100644
50404 --- a/drivers/platform/x86/msi-wmi.c
50405 +++ b/drivers/platform/x86/msi-wmi.c
50406 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50407 static void msi_wmi_notify(u32 value, void *context)
50408 {
50409 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50410 - static struct key_entry *key;
50411 + struct key_entry *key;
50412 union acpi_object *obj;
50413 acpi_status status;
50414
50415 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50416 index 26ad9ff..7c52909 100644
50417 --- a/drivers/platform/x86/sony-laptop.c
50418 +++ b/drivers/platform/x86/sony-laptop.c
50419 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50420 }
50421
50422 /* High speed charging function */
50423 -static struct device_attribute *hsc_handle;
50424 +static device_attribute_no_const *hsc_handle;
50425
50426 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50427 struct device_attribute *attr,
50428 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50429 }
50430
50431 /* low battery function */
50432 -static struct device_attribute *lowbatt_handle;
50433 +static device_attribute_no_const *lowbatt_handle;
50434
50435 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50436 struct device_attribute *attr,
50437 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50438 }
50439
50440 /* fan speed function */
50441 -static struct device_attribute *fan_handle, *hsf_handle;
50442 +static device_attribute_no_const *fan_handle, *hsf_handle;
50443
50444 static ssize_t sony_nc_hsfan_store(struct device *dev,
50445 struct device_attribute *attr,
50446 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50447 }
50448
50449 /* USB charge function */
50450 -static struct device_attribute *uc_handle;
50451 +static device_attribute_no_const *uc_handle;
50452
50453 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50454 struct device_attribute *attr,
50455 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50456 }
50457
50458 /* Panel ID function */
50459 -static struct device_attribute *panel_handle;
50460 +static device_attribute_no_const *panel_handle;
50461
50462 static ssize_t sony_nc_panelid_show(struct device *dev,
50463 struct device_attribute *attr, char *buffer)
50464 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50465 }
50466
50467 /* smart connect function */
50468 -static struct device_attribute *sc_handle;
50469 +static device_attribute_no_const *sc_handle;
50470
50471 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50472 struct device_attribute *attr,
50473 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50474 index 3bbc6eb..7760460 100644
50475 --- a/drivers/platform/x86/thinkpad_acpi.c
50476 +++ b/drivers/platform/x86/thinkpad_acpi.c
50477 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50478 return 0;
50479 }
50480
50481 -void static hotkey_mask_warn_incomplete_mask(void)
50482 +static void hotkey_mask_warn_incomplete_mask(void)
50483 {
50484 /* log only what the user can fix... */
50485 const u32 wantedmask = hotkey_driver_mask &
50486 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50487 && !tp_features.bright_unkfw)
50488 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50489 }
50490 +}
50491
50492 #undef TPACPI_COMPARE_KEY
50493 #undef TPACPI_MAY_SEND_KEY
50494 -}
50495
50496 /*
50497 * Polling driver
50498 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50499 index 438d4c7..ca8a2fb 100644
50500 --- a/drivers/pnp/pnpbios/bioscalls.c
50501 +++ b/drivers/pnp/pnpbios/bioscalls.c
50502 @@ -59,7 +59,7 @@ do { \
50503 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50504 } while(0)
50505
50506 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50507 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50508 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50509
50510 /*
50511 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50512
50513 cpu = get_cpu();
50514 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50515 +
50516 + pax_open_kernel();
50517 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50518 + pax_close_kernel();
50519
50520 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50521 spin_lock_irqsave(&pnp_bios_lock, flags);
50522 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50523 :"memory");
50524 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50525
50526 + pax_open_kernel();
50527 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50528 + pax_close_kernel();
50529 +
50530 put_cpu();
50531
50532 /* If we get here and this is set then the PnP BIOS faulted on us. */
50533 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50534 return status;
50535 }
50536
50537 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50538 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50539 {
50540 int i;
50541
50542 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50543 pnp_bios_callpoint.offset = header->fields.pm16offset;
50544 pnp_bios_callpoint.segment = PNP_CS16;
50545
50546 + pax_open_kernel();
50547 +
50548 for_each_possible_cpu(i) {
50549 struct desc_struct *gdt = get_cpu_gdt_table(i);
50550 if (!gdt)
50551 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50552 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50553 (unsigned long)__va(header->fields.pm16dseg));
50554 }
50555 +
50556 + pax_close_kernel();
50557 }
50558 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50559 index 0c52e2a..3421ab7 100644
50560 --- a/drivers/power/pda_power.c
50561 +++ b/drivers/power/pda_power.c
50562 @@ -37,7 +37,11 @@ static int polling;
50563
50564 #if IS_ENABLED(CONFIG_USB_PHY)
50565 static struct usb_phy *transceiver;
50566 -static struct notifier_block otg_nb;
50567 +static int otg_handle_notification(struct notifier_block *nb,
50568 + unsigned long event, void *unused);
50569 +static struct notifier_block otg_nb = {
50570 + .notifier_call = otg_handle_notification
50571 +};
50572 #endif
50573
50574 static struct regulator *ac_draw;
50575 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50576
50577 #if IS_ENABLED(CONFIG_USB_PHY)
50578 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50579 - otg_nb.notifier_call = otg_handle_notification;
50580 ret = usb_register_notifier(transceiver, &otg_nb);
50581 if (ret) {
50582 dev_err(dev, "failure to register otg notifier\n");
50583 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50584 index cc439fd..8fa30df 100644
50585 --- a/drivers/power/power_supply.h
50586 +++ b/drivers/power/power_supply.h
50587 @@ -16,12 +16,12 @@ struct power_supply;
50588
50589 #ifdef CONFIG_SYSFS
50590
50591 -extern void power_supply_init_attrs(struct device_type *dev_type);
50592 +extern void power_supply_init_attrs(void);
50593 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50594
50595 #else
50596
50597 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50598 +static inline void power_supply_init_attrs(void) {}
50599 #define power_supply_uevent NULL
50600
50601 #endif /* CONFIG_SYSFS */
50602 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50603 index 078afd6..fbac9da 100644
50604 --- a/drivers/power/power_supply_core.c
50605 +++ b/drivers/power/power_supply_core.c
50606 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50607 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50608 EXPORT_SYMBOL_GPL(power_supply_notifier);
50609
50610 -static struct device_type power_supply_dev_type;
50611 +extern const struct attribute_group *power_supply_attr_groups[];
50612 +static struct device_type power_supply_dev_type = {
50613 + .groups = power_supply_attr_groups,
50614 +};
50615
50616 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50617 struct power_supply *supply)
50618 @@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
50619 return PTR_ERR(power_supply_class);
50620
50621 power_supply_class->dev_uevent = power_supply_uevent;
50622 - power_supply_init_attrs(&power_supply_dev_type);
50623 + power_supply_init_attrs();
50624
50625 return 0;
50626 }
50627 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50628 index 750a202..99c8f4b 100644
50629 --- a/drivers/power/power_supply_sysfs.c
50630 +++ b/drivers/power/power_supply_sysfs.c
50631 @@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
50632 .is_visible = power_supply_attr_is_visible,
50633 };
50634
50635 -static const struct attribute_group *power_supply_attr_groups[] = {
50636 +const struct attribute_group *power_supply_attr_groups[] = {
50637 &power_supply_attr_group,
50638 NULL,
50639 };
50640
50641 -void power_supply_init_attrs(struct device_type *dev_type)
50642 +void power_supply_init_attrs(void)
50643 {
50644 int i;
50645
50646 - dev_type->groups = power_supply_attr_groups;
50647 -
50648 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50649 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50650 }
50651 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50652 index 84419af..268ede8 100644
50653 --- a/drivers/powercap/powercap_sys.c
50654 +++ b/drivers/powercap/powercap_sys.c
50655 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50656 struct device_attribute name_attr;
50657 };
50658
50659 +static ssize_t show_constraint_name(struct device *dev,
50660 + struct device_attribute *dev_attr,
50661 + char *buf);
50662 +
50663 static struct powercap_constraint_attr
50664 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50665 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50666 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50667 + .power_limit_attr = {
50668 + .attr = {
50669 + .name = NULL,
50670 + .mode = S_IWUSR | S_IRUGO
50671 + },
50672 + .show = show_constraint_power_limit_uw,
50673 + .store = store_constraint_power_limit_uw
50674 + },
50675 +
50676 + .time_window_attr = {
50677 + .attr = {
50678 + .name = NULL,
50679 + .mode = S_IWUSR | S_IRUGO
50680 + },
50681 + .show = show_constraint_time_window_us,
50682 + .store = store_constraint_time_window_us
50683 + },
50684 +
50685 + .max_power_attr = {
50686 + .attr = {
50687 + .name = NULL,
50688 + .mode = S_IRUGO
50689 + },
50690 + .show = show_constraint_max_power_uw,
50691 + .store = NULL
50692 + },
50693 +
50694 + .min_power_attr = {
50695 + .attr = {
50696 + .name = NULL,
50697 + .mode = S_IRUGO
50698 + },
50699 + .show = show_constraint_min_power_uw,
50700 + .store = NULL
50701 + },
50702 +
50703 + .max_time_window_attr = {
50704 + .attr = {
50705 + .name = NULL,
50706 + .mode = S_IRUGO
50707 + },
50708 + .show = show_constraint_max_time_window_us,
50709 + .store = NULL
50710 + },
50711 +
50712 + .min_time_window_attr = {
50713 + .attr = {
50714 + .name = NULL,
50715 + .mode = S_IRUGO
50716 + },
50717 + .show = show_constraint_min_time_window_us,
50718 + .store = NULL
50719 + },
50720 +
50721 + .name_attr = {
50722 + .attr = {
50723 + .name = NULL,
50724 + .mode = S_IRUGO
50725 + },
50726 + .show = show_constraint_name,
50727 + .store = NULL
50728 + }
50729 + }
50730 +};
50731
50732 /* A list of powercap control_types */
50733 static LIST_HEAD(powercap_cntrl_list);
50734 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50735 }
50736
50737 static int create_constraint_attribute(int id, const char *name,
50738 - int mode,
50739 - struct device_attribute *dev_attr,
50740 - ssize_t (*show)(struct device *,
50741 - struct device_attribute *, char *),
50742 - ssize_t (*store)(struct device *,
50743 - struct device_attribute *,
50744 - const char *, size_t)
50745 - )
50746 + struct device_attribute *dev_attr)
50747 {
50748 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50749
50750 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50751 - id, name);
50752 - if (!dev_attr->attr.name)
50753 + if (!name)
50754 return -ENOMEM;
50755 - dev_attr->attr.mode = mode;
50756 - dev_attr->show = show;
50757 - dev_attr->store = store;
50758 +
50759 + pax_open_kernel();
50760 + *(const char **)&dev_attr->attr.name = name;
50761 + pax_close_kernel();
50762
50763 return 0;
50764 }
50765 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50766
50767 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50768 ret = create_constraint_attribute(i, "power_limit_uw",
50769 - S_IWUSR | S_IRUGO,
50770 - &constraint_attrs[i].power_limit_attr,
50771 - show_constraint_power_limit_uw,
50772 - store_constraint_power_limit_uw);
50773 + &constraint_attrs[i].power_limit_attr);
50774 if (ret)
50775 goto err_alloc;
50776 ret = create_constraint_attribute(i, "time_window_us",
50777 - S_IWUSR | S_IRUGO,
50778 - &constraint_attrs[i].time_window_attr,
50779 - show_constraint_time_window_us,
50780 - store_constraint_time_window_us);
50781 + &constraint_attrs[i].time_window_attr);
50782 if (ret)
50783 goto err_alloc;
50784 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50785 - &constraint_attrs[i].name_attr,
50786 - show_constraint_name,
50787 - NULL);
50788 + ret = create_constraint_attribute(i, "name",
50789 + &constraint_attrs[i].name_attr);
50790 if (ret)
50791 goto err_alloc;
50792 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50793 - &constraint_attrs[i].max_power_attr,
50794 - show_constraint_max_power_uw,
50795 - NULL);
50796 + ret = create_constraint_attribute(i, "max_power_uw",
50797 + &constraint_attrs[i].max_power_attr);
50798 if (ret)
50799 goto err_alloc;
50800 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50801 - &constraint_attrs[i].min_power_attr,
50802 - show_constraint_min_power_uw,
50803 - NULL);
50804 + ret = create_constraint_attribute(i, "min_power_uw",
50805 + &constraint_attrs[i].min_power_attr);
50806 if (ret)
50807 goto err_alloc;
50808 ret = create_constraint_attribute(i, "max_time_window_us",
50809 - S_IRUGO,
50810 - &constraint_attrs[i].max_time_window_attr,
50811 - show_constraint_max_time_window_us,
50812 - NULL);
50813 + &constraint_attrs[i].max_time_window_attr);
50814 if (ret)
50815 goto err_alloc;
50816 ret = create_constraint_attribute(i, "min_time_window_us",
50817 - S_IRUGO,
50818 - &constraint_attrs[i].min_time_window_attr,
50819 - show_constraint_min_time_window_us,
50820 - NULL);
50821 + &constraint_attrs[i].min_time_window_attr);
50822 if (ret)
50823 goto err_alloc;
50824
50825 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50826 power_zone->zone_dev_attrs[count++] =
50827 &dev_attr_max_energy_range_uj.attr;
50828 if (power_zone->ops->get_energy_uj) {
50829 + pax_open_kernel();
50830 if (power_zone->ops->reset_energy_uj)
50831 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50832 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50833 else
50834 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50835 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50836 + pax_close_kernel();
50837 power_zone->zone_dev_attrs[count++] =
50838 &dev_attr_energy_uj.attr;
50839 }
50840 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50841 index 9c5d414..c7900ce 100644
50842 --- a/drivers/ptp/ptp_private.h
50843 +++ b/drivers/ptp/ptp_private.h
50844 @@ -51,7 +51,7 @@ struct ptp_clock {
50845 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50846 wait_queue_head_t tsev_wq;
50847 int defunct; /* tells readers to go away when clock is being removed */
50848 - struct device_attribute *pin_dev_attr;
50849 + device_attribute_no_const *pin_dev_attr;
50850 struct attribute **pin_attr;
50851 struct attribute_group pin_attr_group;
50852 };
50853 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50854 index 302e626..12579af 100644
50855 --- a/drivers/ptp/ptp_sysfs.c
50856 +++ b/drivers/ptp/ptp_sysfs.c
50857 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50858 goto no_pin_attr;
50859
50860 for (i = 0; i < n_pins; i++) {
50861 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50862 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50863 sysfs_attr_init(&da->attr);
50864 da->attr.name = info->pin_config[i].name;
50865 da->attr.mode = 0644;
50866 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50867 index a3c3785..c901e3a 100644
50868 --- a/drivers/regulator/core.c
50869 +++ b/drivers/regulator/core.c
50870 @@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50871 {
50872 const struct regulation_constraints *constraints = NULL;
50873 const struct regulator_init_data *init_data;
50874 - static atomic_t regulator_no = ATOMIC_INIT(0);
50875 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50876 struct regulator_dev *rdev;
50877 struct device *dev;
50878 int ret, i;
50879 @@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50880 rdev->dev.of_node = of_node_get(config->of_node);
50881 rdev->dev.parent = dev;
50882 dev_set_name(&rdev->dev, "regulator.%d",
50883 - atomic_inc_return(&regulator_no) - 1);
50884 + atomic_inc_return_unchecked(&regulator_no) - 1);
50885 ret = device_register(&rdev->dev);
50886 if (ret != 0) {
50887 put_device(&rdev->dev);
50888 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50889 index 2fc4111..6aa88ca 100644
50890 --- a/drivers/regulator/max8660.c
50891 +++ b/drivers/regulator/max8660.c
50892 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50893 max8660->shadow_regs[MAX8660_OVER1] = 5;
50894 } else {
50895 /* Otherwise devices can be toggled via software */
50896 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50897 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50898 + pax_open_kernel();
50899 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50900 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50901 + pax_close_kernel();
50902 }
50903
50904 /*
50905 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50906 index dbedf17..18ff6b7 100644
50907 --- a/drivers/regulator/max8973-regulator.c
50908 +++ b/drivers/regulator/max8973-regulator.c
50909 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50910 if (!pdata || !pdata->enable_ext_control) {
50911 max->desc.enable_reg = MAX8973_VOUT;
50912 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50913 - max->ops.enable = regulator_enable_regmap;
50914 - max->ops.disable = regulator_disable_regmap;
50915 - max->ops.is_enabled = regulator_is_enabled_regmap;
50916 + pax_open_kernel();
50917 + *(void **)&max->ops.enable = regulator_enable_regmap;
50918 + *(void **)&max->ops.disable = regulator_disable_regmap;
50919 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50920 + pax_close_kernel();
50921 }
50922
50923 if (pdata) {
50924 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50925 index f374fa5..26f0683 100644
50926 --- a/drivers/regulator/mc13892-regulator.c
50927 +++ b/drivers/regulator/mc13892-regulator.c
50928 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50929 }
50930 mc13xxx_unlock(mc13892);
50931
50932 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
50933 + pax_open_kernel();
50934 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
50935 = mc13892_vcam_set_mode;
50936 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
50937 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
50938 = mc13892_vcam_get_mode;
50939 + pax_close_kernel();
50940
50941 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50942 ARRAY_SIZE(mc13892_regulators));
50943 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50944 index 5b2e761..c8c8a4a 100644
50945 --- a/drivers/rtc/rtc-cmos.c
50946 +++ b/drivers/rtc/rtc-cmos.c
50947 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50948 hpet_rtc_timer_init();
50949
50950 /* export at least the first block of NVRAM */
50951 - nvram.size = address_space - NVRAM_OFFSET;
50952 + pax_open_kernel();
50953 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50954 + pax_close_kernel();
50955 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50956 if (retval < 0) {
50957 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50958 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50959 index d049393..bb20be0 100644
50960 --- a/drivers/rtc/rtc-dev.c
50961 +++ b/drivers/rtc/rtc-dev.c
50962 @@ -16,6 +16,7 @@
50963 #include <linux/module.h>
50964 #include <linux/rtc.h>
50965 #include <linux/sched.h>
50966 +#include <linux/grsecurity.h>
50967 #include "rtc-core.h"
50968
50969 static dev_t rtc_devt;
50970 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50971 if (copy_from_user(&tm, uarg, sizeof(tm)))
50972 return -EFAULT;
50973
50974 + gr_log_timechange();
50975 +
50976 return rtc_set_time(rtc, &tm);
50977
50978 case RTC_PIE_ON:
50979 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50980 index f03d5ba..8325bf6 100644
50981 --- a/drivers/rtc/rtc-ds1307.c
50982 +++ b/drivers/rtc/rtc-ds1307.c
50983 @@ -107,7 +107,7 @@ struct ds1307 {
50984 u8 offset; /* register's offset */
50985 u8 regs[11];
50986 u16 nvram_offset;
50987 - struct bin_attribute *nvram;
50988 + bin_attribute_no_const *nvram;
50989 enum ds_type type;
50990 unsigned long flags;
50991 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50992 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50993 index 11880c1..b823aa4 100644
50994 --- a/drivers/rtc/rtc-m48t59.c
50995 +++ b/drivers/rtc/rtc-m48t59.c
50996 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50997 if (IS_ERR(m48t59->rtc))
50998 return PTR_ERR(m48t59->rtc);
50999
51000 - m48t59_nvram_attr.size = pdata->offset;
51001 + pax_open_kernel();
51002 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51003 + pax_close_kernel();
51004
51005 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51006 if (ret)
51007 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51008 index e693af6..2e525b6 100644
51009 --- a/drivers/scsi/bfa/bfa_fcpim.h
51010 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51011 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51012
51013 struct bfa_itn_s {
51014 bfa_isr_func_t isr;
51015 -};
51016 +} __no_const;
51017
51018 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51019 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51020 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51021 index 0f19455..ef7adb5 100644
51022 --- a/drivers/scsi/bfa/bfa_fcs.c
51023 +++ b/drivers/scsi/bfa/bfa_fcs.c
51024 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51025 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51026
51027 static struct bfa_fcs_mod_s fcs_modules[] = {
51028 - { bfa_fcs_port_attach, NULL, NULL },
51029 - { bfa_fcs_uf_attach, NULL, NULL },
51030 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51031 - bfa_fcs_fabric_modexit },
51032 + {
51033 + .attach = bfa_fcs_port_attach,
51034 + .modinit = NULL,
51035 + .modexit = NULL
51036 + },
51037 + {
51038 + .attach = bfa_fcs_uf_attach,
51039 + .modinit = NULL,
51040 + .modexit = NULL
51041 + },
51042 + {
51043 + .attach = bfa_fcs_fabric_attach,
51044 + .modinit = bfa_fcs_fabric_modinit,
51045 + .modexit = bfa_fcs_fabric_modexit
51046 + },
51047 };
51048
51049 /*
51050 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51051 index ff75ef8..2dfe00a 100644
51052 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51053 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51054 @@ -89,15 +89,26 @@ static struct {
51055 void (*offline) (struct bfa_fcs_lport_s *port);
51056 } __port_action[] = {
51057 {
51058 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51059 - bfa_fcs_lport_unknown_offline}, {
51060 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51061 - bfa_fcs_lport_fab_offline}, {
51062 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51063 - bfa_fcs_lport_n2n_offline}, {
51064 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51065 - bfa_fcs_lport_loop_offline},
51066 - };
51067 + .init = bfa_fcs_lport_unknown_init,
51068 + .online = bfa_fcs_lport_unknown_online,
51069 + .offline = bfa_fcs_lport_unknown_offline
51070 + },
51071 + {
51072 + .init = bfa_fcs_lport_fab_init,
51073 + .online = bfa_fcs_lport_fab_online,
51074 + .offline = bfa_fcs_lport_fab_offline
51075 + },
51076 + {
51077 + .init = bfa_fcs_lport_n2n_init,
51078 + .online = bfa_fcs_lport_n2n_online,
51079 + .offline = bfa_fcs_lport_n2n_offline
51080 + },
51081 + {
51082 + .init = bfa_fcs_lport_loop_init,
51083 + .online = bfa_fcs_lport_loop_online,
51084 + .offline = bfa_fcs_lport_loop_offline
51085 + },
51086 +};
51087
51088 /*
51089 * fcs_port_sm FCS logical port state machine
51090 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51091 index a38aafa0..fe8f03b 100644
51092 --- a/drivers/scsi/bfa/bfa_ioc.h
51093 +++ b/drivers/scsi/bfa/bfa_ioc.h
51094 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51095 bfa_ioc_disable_cbfn_t disable_cbfn;
51096 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51097 bfa_ioc_reset_cbfn_t reset_cbfn;
51098 -};
51099 +} __no_const;
51100
51101 /*
51102 * IOC event notification mechanism.
51103 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51104 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51105 enum bfi_ioc_state fwstate);
51106 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51107 -};
51108 +} __no_const;
51109
51110 /*
51111 * Queue element to wait for room in request queue. FIFO order is
51112 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51113 index a14c784..6de6790 100644
51114 --- a/drivers/scsi/bfa/bfa_modules.h
51115 +++ b/drivers/scsi/bfa/bfa_modules.h
51116 @@ -78,12 +78,12 @@ enum {
51117 \
51118 extern struct bfa_module_s hal_mod_ ## __mod; \
51119 struct bfa_module_s hal_mod_ ## __mod = { \
51120 - bfa_ ## __mod ## _meminfo, \
51121 - bfa_ ## __mod ## _attach, \
51122 - bfa_ ## __mod ## _detach, \
51123 - bfa_ ## __mod ## _start, \
51124 - bfa_ ## __mod ## _stop, \
51125 - bfa_ ## __mod ## _iocdisable, \
51126 + .meminfo = bfa_ ## __mod ## _meminfo, \
51127 + .attach = bfa_ ## __mod ## _attach, \
51128 + .detach = bfa_ ## __mod ## _detach, \
51129 + .start = bfa_ ## __mod ## _start, \
51130 + .stop = bfa_ ## __mod ## _stop, \
51131 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51132 }
51133
51134 #define BFA_CACHELINE_SZ (256)
51135 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51136 index 045c4e1..13de803 100644
51137 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51138 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51139 @@ -33,8 +33,8 @@
51140 */
51141 #include "libfcoe.h"
51142
51143 -static atomic_t ctlr_num;
51144 -static atomic_t fcf_num;
51145 +static atomic_unchecked_t ctlr_num;
51146 +static atomic_unchecked_t fcf_num;
51147
51148 /*
51149 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51150 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51151 if (!ctlr)
51152 goto out;
51153
51154 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51155 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51156 ctlr->f = f;
51157 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51158 INIT_LIST_HEAD(&ctlr->fcfs);
51159 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51160 fcf->dev.parent = &ctlr->dev;
51161 fcf->dev.bus = &fcoe_bus_type;
51162 fcf->dev.type = &fcoe_fcf_device_type;
51163 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51164 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51165 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51166
51167 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51168 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51169 {
51170 int error;
51171
51172 - atomic_set(&ctlr_num, 0);
51173 - atomic_set(&fcf_num, 0);
51174 + atomic_set_unchecked(&ctlr_num, 0);
51175 + atomic_set_unchecked(&fcf_num, 0);
51176
51177 error = bus_register(&fcoe_bus_type);
51178 if (error)
51179 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51180 index 6de80e3..a11e0ac 100644
51181 --- a/drivers/scsi/hosts.c
51182 +++ b/drivers/scsi/hosts.c
51183 @@ -42,7 +42,7 @@
51184 #include "scsi_logging.h"
51185
51186
51187 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51188 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51189
51190
51191 static void scsi_host_cls_release(struct device *dev)
51192 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51193 * subtract one because we increment first then return, but we need to
51194 * know what the next host number was before increment
51195 */
51196 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51197 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51198 shost->dma_channel = 0xff;
51199
51200 /* These three are default values which can be overridden */
51201 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51202 index 6b35d0d..2880305 100644
51203 --- a/drivers/scsi/hpsa.c
51204 +++ b/drivers/scsi/hpsa.c
51205 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51206 unsigned long flags;
51207
51208 if (h->transMethod & CFGTBL_Trans_io_accel1)
51209 - return h->access.command_completed(h, q);
51210 + return h->access->command_completed(h, q);
51211
51212 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51213 - return h->access.command_completed(h, q);
51214 + return h->access->command_completed(h, q);
51215
51216 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51217 a = rq->head[rq->current_entry];
51218 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51219 while (!list_empty(&h->reqQ)) {
51220 c = list_entry(h->reqQ.next, struct CommandList, list);
51221 /* can't do anything if fifo is full */
51222 - if ((h->access.fifo_full(h))) {
51223 + if ((h->access->fifo_full(h))) {
51224 h->fifo_recently_full = 1;
51225 dev_warn(&h->pdev->dev, "fifo full\n");
51226 break;
51227 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51228
51229 /* Tell the controller execute command */
51230 spin_unlock_irqrestore(&h->lock, *flags);
51231 - h->access.submit_command(h, c);
51232 + h->access->submit_command(h, c);
51233 spin_lock_irqsave(&h->lock, *flags);
51234 }
51235 }
51236 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51237
51238 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51239 {
51240 - return h->access.command_completed(h, q);
51241 + return h->access->command_completed(h, q);
51242 }
51243
51244 static inline bool interrupt_pending(struct ctlr_info *h)
51245 {
51246 - return h->access.intr_pending(h);
51247 + return h->access->intr_pending(h);
51248 }
51249
51250 static inline long interrupt_not_for_us(struct ctlr_info *h)
51251 {
51252 - return (h->access.intr_pending(h) == 0) ||
51253 + return (h->access->intr_pending(h) == 0) ||
51254 (h->interrupts_enabled == 0);
51255 }
51256
51257 @@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51258 if (prod_index < 0)
51259 return -ENODEV;
51260 h->product_name = products[prod_index].product_name;
51261 - h->access = *(products[prod_index].access);
51262 + h->access = products[prod_index].access;
51263
51264 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51265 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51266 @@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51267 unsigned long flags;
51268 u32 lockup_detected;
51269
51270 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51271 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51272 spin_lock_irqsave(&h->lock, flags);
51273 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51274 if (!lockup_detected) {
51275 @@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
51276 }
51277
51278 /* make sure the board interrupts are off */
51279 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51280 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51281
51282 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51283 goto clean2;
51284 @@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
51285 * fake ones to scoop up any residual completions.
51286 */
51287 spin_lock_irqsave(&h->lock, flags);
51288 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51289 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51290 spin_unlock_irqrestore(&h->lock, flags);
51291 free_irqs(h);
51292 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51293 @@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
51294 dev_info(&h->pdev->dev, "Board READY.\n");
51295 dev_info(&h->pdev->dev,
51296 "Waiting for stale completions to drain.\n");
51297 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51298 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51299 msleep(10000);
51300 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51301 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51302
51303 rc = controller_reset_failed(h->cfgtable);
51304 if (rc)
51305 @@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
51306 h->drv_req_rescan = 0;
51307
51308 /* Turn the interrupts on so we can service requests */
51309 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51310 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51311
51312 hpsa_hba_inquiry(h);
51313 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51314 @@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51315 * To write all data in the battery backed cache to disks
51316 */
51317 hpsa_flush_cache(h);
51318 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51319 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51320 hpsa_free_irqs_and_disable_msix(h);
51321 }
51322
51323 @@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51324 CFGTBL_Trans_enable_directed_msix |
51325 (trans_support & (CFGTBL_Trans_io_accel1 |
51326 CFGTBL_Trans_io_accel2));
51327 - struct access_method access = SA5_performant_access;
51328 + struct access_method *access = &SA5_performant_access;
51329
51330 /* This is a bit complicated. There are 8 registers on
51331 * the controller which we write to to tell it 8 different
51332 @@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51333 * perform the superfluous readl() after each command submission.
51334 */
51335 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51336 - access = SA5_performant_access_no_read;
51337 + access = &SA5_performant_access_no_read;
51338
51339 /* Controller spec: zero out this buffer. */
51340 for (i = 0; i < h->nreply_queues; i++)
51341 @@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51342 * enable outbound interrupt coalescing in accelerator mode;
51343 */
51344 if (trans_support & CFGTBL_Trans_io_accel1) {
51345 - access = SA5_ioaccel_mode1_access;
51346 + access = &SA5_ioaccel_mode1_access;
51347 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51348 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51349 } else {
51350 if (trans_support & CFGTBL_Trans_io_accel2) {
51351 - access = SA5_ioaccel_mode2_access;
51352 + access = &SA5_ioaccel_mode2_access;
51353 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51354 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51355 }
51356 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51357 index 24472ce..8782caf 100644
51358 --- a/drivers/scsi/hpsa.h
51359 +++ b/drivers/scsi/hpsa.h
51360 @@ -127,7 +127,7 @@ struct ctlr_info {
51361 unsigned int msix_vector;
51362 unsigned int msi_vector;
51363 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51364 - struct access_method access;
51365 + struct access_method *access;
51366 char hba_mode_enabled;
51367
51368 /* queue and queue Info */
51369 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51370 }
51371
51372 static struct access_method SA5_access = {
51373 - SA5_submit_command,
51374 - SA5_intr_mask,
51375 - SA5_fifo_full,
51376 - SA5_intr_pending,
51377 - SA5_completed,
51378 + .submit_command = SA5_submit_command,
51379 + .set_intr_mask = SA5_intr_mask,
51380 + .fifo_full = SA5_fifo_full,
51381 + .intr_pending = SA5_intr_pending,
51382 + .command_completed = SA5_completed,
51383 };
51384
51385 static struct access_method SA5_ioaccel_mode1_access = {
51386 - SA5_submit_command,
51387 - SA5_performant_intr_mask,
51388 - SA5_fifo_full,
51389 - SA5_ioaccel_mode1_intr_pending,
51390 - SA5_ioaccel_mode1_completed,
51391 + .submit_command = SA5_submit_command,
51392 + .set_intr_mask = SA5_performant_intr_mask,
51393 + .fifo_full = SA5_fifo_full,
51394 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51395 + .command_completed = SA5_ioaccel_mode1_completed,
51396 };
51397
51398 static struct access_method SA5_ioaccel_mode2_access = {
51399 - SA5_submit_command_ioaccel2,
51400 - SA5_performant_intr_mask,
51401 - SA5_fifo_full,
51402 - SA5_performant_intr_pending,
51403 - SA5_performant_completed,
51404 + .submit_command = SA5_submit_command_ioaccel2,
51405 + .set_intr_mask = SA5_performant_intr_mask,
51406 + .fifo_full = SA5_fifo_full,
51407 + .intr_pending = SA5_performant_intr_pending,
51408 + .command_completed = SA5_performant_completed,
51409 };
51410
51411 static struct access_method SA5_performant_access = {
51412 - SA5_submit_command,
51413 - SA5_performant_intr_mask,
51414 - SA5_fifo_full,
51415 - SA5_performant_intr_pending,
51416 - SA5_performant_completed,
51417 + .submit_command = SA5_submit_command,
51418 + .set_intr_mask = SA5_performant_intr_mask,
51419 + .fifo_full = SA5_fifo_full,
51420 + .intr_pending = SA5_performant_intr_pending,
51421 + .command_completed = SA5_performant_completed,
51422 };
51423
51424 static struct access_method SA5_performant_access_no_read = {
51425 - SA5_submit_command_no_read,
51426 - SA5_performant_intr_mask,
51427 - SA5_fifo_full,
51428 - SA5_performant_intr_pending,
51429 - SA5_performant_completed,
51430 + .submit_command = SA5_submit_command_no_read,
51431 + .set_intr_mask = SA5_performant_intr_mask,
51432 + .fifo_full = SA5_fifo_full,
51433 + .intr_pending = SA5_performant_intr_pending,
51434 + .command_completed = SA5_performant_completed,
51435 };
51436
51437 struct board_type {
51438 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51439 index 1b3a094..068e683 100644
51440 --- a/drivers/scsi/libfc/fc_exch.c
51441 +++ b/drivers/scsi/libfc/fc_exch.c
51442 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51443 u16 pool_max_index;
51444
51445 struct {
51446 - atomic_t no_free_exch;
51447 - atomic_t no_free_exch_xid;
51448 - atomic_t xid_not_found;
51449 - atomic_t xid_busy;
51450 - atomic_t seq_not_found;
51451 - atomic_t non_bls_resp;
51452 + atomic_unchecked_t no_free_exch;
51453 + atomic_unchecked_t no_free_exch_xid;
51454 + atomic_unchecked_t xid_not_found;
51455 + atomic_unchecked_t xid_busy;
51456 + atomic_unchecked_t seq_not_found;
51457 + atomic_unchecked_t non_bls_resp;
51458 } stats;
51459 };
51460
51461 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51462 /* allocate memory for exchange */
51463 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51464 if (!ep) {
51465 - atomic_inc(&mp->stats.no_free_exch);
51466 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51467 goto out;
51468 }
51469 memset(ep, 0, sizeof(*ep));
51470 @@ -874,7 +874,7 @@ out:
51471 return ep;
51472 err:
51473 spin_unlock_bh(&pool->lock);
51474 - atomic_inc(&mp->stats.no_free_exch_xid);
51475 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51476 mempool_free(ep, mp->ep_pool);
51477 return NULL;
51478 }
51479 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51480 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51481 ep = fc_exch_find(mp, xid);
51482 if (!ep) {
51483 - atomic_inc(&mp->stats.xid_not_found);
51484 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51485 reject = FC_RJT_OX_ID;
51486 goto out;
51487 }
51488 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51489 ep = fc_exch_find(mp, xid);
51490 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51491 if (ep) {
51492 - atomic_inc(&mp->stats.xid_busy);
51493 + atomic_inc_unchecked(&mp->stats.xid_busy);
51494 reject = FC_RJT_RX_ID;
51495 goto rel;
51496 }
51497 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51498 }
51499 xid = ep->xid; /* get our XID */
51500 } else if (!ep) {
51501 - atomic_inc(&mp->stats.xid_not_found);
51502 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51503 reject = FC_RJT_RX_ID; /* XID not found */
51504 goto out;
51505 }
51506 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51507 } else {
51508 sp = &ep->seq;
51509 if (sp->id != fh->fh_seq_id) {
51510 - atomic_inc(&mp->stats.seq_not_found);
51511 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51512 if (f_ctl & FC_FC_END_SEQ) {
51513 /*
51514 * Update sequence_id based on incoming last
51515 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51516
51517 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51518 if (!ep) {
51519 - atomic_inc(&mp->stats.xid_not_found);
51520 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51521 goto out;
51522 }
51523 if (ep->esb_stat & ESB_ST_COMPLETE) {
51524 - atomic_inc(&mp->stats.xid_not_found);
51525 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51526 goto rel;
51527 }
51528 if (ep->rxid == FC_XID_UNKNOWN)
51529 ep->rxid = ntohs(fh->fh_rx_id);
51530 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51531 - atomic_inc(&mp->stats.xid_not_found);
51532 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51533 goto rel;
51534 }
51535 if (ep->did != ntoh24(fh->fh_s_id) &&
51536 ep->did != FC_FID_FLOGI) {
51537 - atomic_inc(&mp->stats.xid_not_found);
51538 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51539 goto rel;
51540 }
51541 sof = fr_sof(fp);
51542 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51543 sp->ssb_stat |= SSB_ST_RESP;
51544 sp->id = fh->fh_seq_id;
51545 } else if (sp->id != fh->fh_seq_id) {
51546 - atomic_inc(&mp->stats.seq_not_found);
51547 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51548 goto rel;
51549 }
51550
51551 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51552 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51553
51554 if (!sp)
51555 - atomic_inc(&mp->stats.xid_not_found);
51556 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51557 else
51558 - atomic_inc(&mp->stats.non_bls_resp);
51559 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51560
51561 fc_frame_free(fp);
51562 }
51563 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51564
51565 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51566 mp = ema->mp;
51567 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51568 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51569 st->fc_no_free_exch_xid +=
51570 - atomic_read(&mp->stats.no_free_exch_xid);
51571 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51572 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51573 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51574 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51575 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51576 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51577 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51578 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51579 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51580 }
51581 }
51582 EXPORT_SYMBOL(fc_exch_update_stats);
51583 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51584 index 766098a..1c6c971 100644
51585 --- a/drivers/scsi/libsas/sas_ata.c
51586 +++ b/drivers/scsi/libsas/sas_ata.c
51587 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51588 .postreset = ata_std_postreset,
51589 .error_handler = ata_std_error_handler,
51590 .post_internal_cmd = sas_ata_post_internal,
51591 - .qc_defer = ata_std_qc_defer,
51592 + .qc_defer = ata_std_qc_defer,
51593 .qc_prep = ata_noop_qc_prep,
51594 .qc_issue = sas_ata_qc_issue,
51595 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51596 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51597 index 434e903..5a4a79b 100644
51598 --- a/drivers/scsi/lpfc/lpfc.h
51599 +++ b/drivers/scsi/lpfc/lpfc.h
51600 @@ -430,7 +430,7 @@ struct lpfc_vport {
51601 struct dentry *debug_nodelist;
51602 struct dentry *vport_debugfs_root;
51603 struct lpfc_debugfs_trc *disc_trc;
51604 - atomic_t disc_trc_cnt;
51605 + atomic_unchecked_t disc_trc_cnt;
51606 #endif
51607 uint8_t stat_data_enabled;
51608 uint8_t stat_data_blocked;
51609 @@ -880,8 +880,8 @@ struct lpfc_hba {
51610 struct timer_list fabric_block_timer;
51611 unsigned long bit_flags;
51612 #define FABRIC_COMANDS_BLOCKED 0
51613 - atomic_t num_rsrc_err;
51614 - atomic_t num_cmd_success;
51615 + atomic_unchecked_t num_rsrc_err;
51616 + atomic_unchecked_t num_cmd_success;
51617 unsigned long last_rsrc_error_time;
51618 unsigned long last_ramp_down_time;
51619 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51620 @@ -916,7 +916,7 @@ struct lpfc_hba {
51621
51622 struct dentry *debug_slow_ring_trc;
51623 struct lpfc_debugfs_trc *slow_ring_trc;
51624 - atomic_t slow_ring_trc_cnt;
51625 + atomic_unchecked_t slow_ring_trc_cnt;
51626 /* iDiag debugfs sub-directory */
51627 struct dentry *idiag_root;
51628 struct dentry *idiag_pci_cfg;
51629 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51630 index b0aedce..89c6ca6 100644
51631 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51632 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51633 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51634
51635 #include <linux/debugfs.h>
51636
51637 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51638 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51639 static unsigned long lpfc_debugfs_start_time = 0L;
51640
51641 /* iDiag */
51642 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51643 lpfc_debugfs_enable = 0;
51644
51645 len = 0;
51646 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51647 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51648 (lpfc_debugfs_max_disc_trc - 1);
51649 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51650 dtp = vport->disc_trc + i;
51651 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51652 lpfc_debugfs_enable = 0;
51653
51654 len = 0;
51655 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51656 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51657 (lpfc_debugfs_max_slow_ring_trc - 1);
51658 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51659 dtp = phba->slow_ring_trc + i;
51660 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51661 !vport || !vport->disc_trc)
51662 return;
51663
51664 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51665 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51666 (lpfc_debugfs_max_disc_trc - 1);
51667 dtp = vport->disc_trc + index;
51668 dtp->fmt = fmt;
51669 dtp->data1 = data1;
51670 dtp->data2 = data2;
51671 dtp->data3 = data3;
51672 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51673 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51674 dtp->jif = jiffies;
51675 #endif
51676 return;
51677 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51678 !phba || !phba->slow_ring_trc)
51679 return;
51680
51681 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51682 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51683 (lpfc_debugfs_max_slow_ring_trc - 1);
51684 dtp = phba->slow_ring_trc + index;
51685 dtp->fmt = fmt;
51686 dtp->data1 = data1;
51687 dtp->data2 = data2;
51688 dtp->data3 = data3;
51689 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51690 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51691 dtp->jif = jiffies;
51692 #endif
51693 return;
51694 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51695 "slow_ring buffer\n");
51696 goto debug_failed;
51697 }
51698 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51699 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51700 memset(phba->slow_ring_trc, 0,
51701 (sizeof(struct lpfc_debugfs_trc) *
51702 lpfc_debugfs_max_slow_ring_trc));
51703 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51704 "buffer\n");
51705 goto debug_failed;
51706 }
51707 - atomic_set(&vport->disc_trc_cnt, 0);
51708 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51709
51710 snprintf(name, sizeof(name), "discovery_trace");
51711 vport->debug_disc_trc =
51712 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51713 index a5769a9..718ecc7 100644
51714 --- a/drivers/scsi/lpfc/lpfc_init.c
51715 +++ b/drivers/scsi/lpfc/lpfc_init.c
51716 @@ -11299,8 +11299,10 @@ lpfc_init(void)
51717 "misc_register returned with status %d", error);
51718
51719 if (lpfc_enable_npiv) {
51720 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51721 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51722 + pax_open_kernel();
51723 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51724 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51725 + pax_close_kernel();
51726 }
51727 lpfc_transport_template =
51728 fc_attach_transport(&lpfc_transport_functions);
51729 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51730 index 7862c55..5aa65df 100644
51731 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51732 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51733 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51734 uint32_t evt_posted;
51735
51736 spin_lock_irqsave(&phba->hbalock, flags);
51737 - atomic_inc(&phba->num_rsrc_err);
51738 + atomic_inc_unchecked(&phba->num_rsrc_err);
51739 phba->last_rsrc_error_time = jiffies;
51740
51741 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
51742 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51743 unsigned long num_rsrc_err, num_cmd_success;
51744 int i;
51745
51746 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51747 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51748 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51749 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51750
51751 /*
51752 * The error and success command counters are global per
51753 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51754 }
51755 }
51756 lpfc_destroy_vport_work_array(phba, vports);
51757 - atomic_set(&phba->num_rsrc_err, 0);
51758 - atomic_set(&phba->num_cmd_success, 0);
51759 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51760 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51761 }
51762
51763 /**
51764 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51765 index dd46101..ca80eb9 100644
51766 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51767 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51768 @@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
51769 {
51770 struct scsi_device *sdev = to_scsi_device(dev);
51771 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51772 - static struct _raid_device *raid_device;
51773 + struct _raid_device *raid_device;
51774 unsigned long flags;
51775 Mpi2RaidVolPage0_t vol_pg0;
51776 Mpi2ConfigReply_t mpi_reply;
51777 @@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
51778 {
51779 struct scsi_device *sdev = to_scsi_device(dev);
51780 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51781 - static struct _raid_device *raid_device;
51782 + struct _raid_device *raid_device;
51783 unsigned long flags;
51784 Mpi2RaidVolPage0_t vol_pg0;
51785 Mpi2ConfigReply_t mpi_reply;
51786 @@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51787 Mpi2EventDataIrOperationStatus_t *event_data =
51788 (Mpi2EventDataIrOperationStatus_t *)
51789 fw_event->event_data;
51790 - static struct _raid_device *raid_device;
51791 + struct _raid_device *raid_device;
51792 unsigned long flags;
51793 u16 handle;
51794
51795 @@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51796 u64 sas_address;
51797 struct _sas_device *sas_device;
51798 struct _sas_node *expander_device;
51799 - static struct _raid_device *raid_device;
51800 + struct _raid_device *raid_device;
51801 u8 retry_count;
51802 unsigned long flags;
51803
51804 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51805 index 6f3275d..fa5e6b6 100644
51806 --- a/drivers/scsi/pmcraid.c
51807 +++ b/drivers/scsi/pmcraid.c
51808 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51809 res->scsi_dev = scsi_dev;
51810 scsi_dev->hostdata = res;
51811 res->change_detected = 0;
51812 - atomic_set(&res->read_failures, 0);
51813 - atomic_set(&res->write_failures, 0);
51814 + atomic_set_unchecked(&res->read_failures, 0);
51815 + atomic_set_unchecked(&res->write_failures, 0);
51816 rc = 0;
51817 }
51818 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51819 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51820
51821 /* If this was a SCSI read/write command keep count of errors */
51822 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51823 - atomic_inc(&res->read_failures);
51824 + atomic_inc_unchecked(&res->read_failures);
51825 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51826 - atomic_inc(&res->write_failures);
51827 + atomic_inc_unchecked(&res->write_failures);
51828
51829 if (!RES_IS_GSCSI(res->cfg_entry) &&
51830 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51831 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51832 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51833 * hrrq_id assigned here in queuecommand
51834 */
51835 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51836 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51837 pinstance->num_hrrq;
51838 cmd->cmd_done = pmcraid_io_done;
51839
51840 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51841 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51842 * hrrq_id assigned here in queuecommand
51843 */
51844 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51845 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51846 pinstance->num_hrrq;
51847
51848 if (request_size) {
51849 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51850
51851 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51852 /* add resources only after host is added into system */
51853 - if (!atomic_read(&pinstance->expose_resources))
51854 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51855 return;
51856
51857 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51858 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51859 init_waitqueue_head(&pinstance->reset_wait_q);
51860
51861 atomic_set(&pinstance->outstanding_cmds, 0);
51862 - atomic_set(&pinstance->last_message_id, 0);
51863 - atomic_set(&pinstance->expose_resources, 0);
51864 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51865 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51866
51867 INIT_LIST_HEAD(&pinstance->free_res_q);
51868 INIT_LIST_HEAD(&pinstance->used_res_q);
51869 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51870 /* Schedule worker thread to handle CCN and take care of adding and
51871 * removing devices to OS
51872 */
51873 - atomic_set(&pinstance->expose_resources, 1);
51874 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51875 schedule_work(&pinstance->worker_q);
51876 return rc;
51877
51878 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51879 index e1d150f..6c6df44 100644
51880 --- a/drivers/scsi/pmcraid.h
51881 +++ b/drivers/scsi/pmcraid.h
51882 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51883 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51884
51885 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51886 - atomic_t last_message_id;
51887 + atomic_unchecked_t last_message_id;
51888
51889 /* configuration table */
51890 struct pmcraid_config_table *cfg_table;
51891 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51892 atomic_t outstanding_cmds;
51893
51894 /* should add/delete resources to mid-layer now ?*/
51895 - atomic_t expose_resources;
51896 + atomic_unchecked_t expose_resources;
51897
51898
51899
51900 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51901 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51902 };
51903 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51904 - atomic_t read_failures; /* count of failed READ commands */
51905 - atomic_t write_failures; /* count of failed WRITE commands */
51906 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51907 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51908
51909 /* To indicate add/delete/modify during CCN */
51910 u8 change_detected;
51911 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51912 index 16fe519..3b1ec82 100644
51913 --- a/drivers/scsi/qla2xxx/qla_attr.c
51914 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51915 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51916 return 0;
51917 }
51918
51919 -struct fc_function_template qla2xxx_transport_functions = {
51920 +fc_function_template_no_const qla2xxx_transport_functions = {
51921
51922 .show_host_node_name = 1,
51923 .show_host_port_name = 1,
51924 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51925 .bsg_timeout = qla24xx_bsg_timeout,
51926 };
51927
51928 -struct fc_function_template qla2xxx_transport_vport_functions = {
51929 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51930
51931 .show_host_node_name = 1,
51932 .show_host_port_name = 1,
51933 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51934 index d646540..5b13554 100644
51935 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51936 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51937 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
51938 struct device_attribute;
51939 extern struct device_attribute *qla2x00_host_attrs[];
51940 struct fc_function_template;
51941 -extern struct fc_function_template qla2xxx_transport_functions;
51942 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51943 +extern fc_function_template_no_const qla2xxx_transport_functions;
51944 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51945 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51946 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51947 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51948 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51949 index 8252c0e..613adad 100644
51950 --- a/drivers/scsi/qla2xxx/qla_os.c
51951 +++ b/drivers/scsi/qla2xxx/qla_os.c
51952 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51953 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51954 /* Ok, a 64bit DMA mask is applicable. */
51955 ha->flags.enable_64bit_addressing = 1;
51956 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51957 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51958 + pax_open_kernel();
51959 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51960 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51961 + pax_close_kernel();
51962 return;
51963 }
51964 }
51965 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51966 index 8f6d0fb..1b21097 100644
51967 --- a/drivers/scsi/qla4xxx/ql4_def.h
51968 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51969 @@ -305,7 +305,7 @@ struct ddb_entry {
51970 * (4000 only) */
51971 atomic_t relogin_timer; /* Max Time to wait for
51972 * relogin to complete */
51973 - atomic_t relogin_retry_count; /* Num of times relogin has been
51974 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51975 * retried */
51976 uint32_t default_time2wait; /* Default Min time between
51977 * relogins (+aens) */
51978 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51979 index 199fcf7..3c3a918 100644
51980 --- a/drivers/scsi/qla4xxx/ql4_os.c
51981 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51982 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51983 */
51984 if (!iscsi_is_session_online(cls_sess)) {
51985 /* Reset retry relogin timer */
51986 - atomic_inc(&ddb_entry->relogin_retry_count);
51987 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51988 DEBUG2(ql4_printk(KERN_INFO, ha,
51989 "%s: index[%d] relogin timed out-retrying"
51990 " relogin (%d), retry (%d)\n", __func__,
51991 ddb_entry->fw_ddb_index,
51992 - atomic_read(&ddb_entry->relogin_retry_count),
51993 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51994 ddb_entry->default_time2wait + 4));
51995 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51996 atomic_set(&ddb_entry->retry_relogin_timer,
51997 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51998
51999 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52000 atomic_set(&ddb_entry->relogin_timer, 0);
52001 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52002 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52003 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52004 ddb_entry->default_relogin_timeout =
52005 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52006 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52007 index d81f3cc..0093e5b 100644
52008 --- a/drivers/scsi/scsi.c
52009 +++ b/drivers/scsi/scsi.c
52010 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52011 struct Scsi_Host *host = cmd->device->host;
52012 int rtn = 0;
52013
52014 - atomic_inc(&cmd->device->iorequest_cnt);
52015 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52016
52017 /* check if the device is still usable */
52018 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52019 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52020 index 7cb8c73..14561b5 100644
52021 --- a/drivers/scsi/scsi_lib.c
52022 +++ b/drivers/scsi/scsi_lib.c
52023 @@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52024 shost = sdev->host;
52025 scsi_init_cmd_errh(cmd);
52026 cmd->result = DID_NO_CONNECT << 16;
52027 - atomic_inc(&cmd->device->iorequest_cnt);
52028 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52029
52030 /*
52031 * SCSI request completion path will do scsi_device_unbusy(),
52032 @@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52033
52034 INIT_LIST_HEAD(&cmd->eh_entry);
52035
52036 - atomic_inc(&cmd->device->iodone_cnt);
52037 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52038 if (cmd->result)
52039 - atomic_inc(&cmd->device->ioerr_cnt);
52040 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52041
52042 disposition = scsi_decide_disposition(cmd);
52043 if (disposition != SUCCESS &&
52044 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52045 index 8b4105a..1f58363 100644
52046 --- a/drivers/scsi/scsi_sysfs.c
52047 +++ b/drivers/scsi/scsi_sysfs.c
52048 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52049 char *buf) \
52050 { \
52051 struct scsi_device *sdev = to_scsi_device(dev); \
52052 - unsigned long long count = atomic_read(&sdev->field); \
52053 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52054 return snprintf(buf, 20, "0x%llx\n", count); \
52055 } \
52056 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52057 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52058 index 5d6f348..18778a6b 100644
52059 --- a/drivers/scsi/scsi_transport_fc.c
52060 +++ b/drivers/scsi/scsi_transport_fc.c
52061 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52062 * Netlink Infrastructure
52063 */
52064
52065 -static atomic_t fc_event_seq;
52066 +static atomic_unchecked_t fc_event_seq;
52067
52068 /**
52069 * fc_get_event_number - Obtain the next sequential FC event number
52070 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52071 u32
52072 fc_get_event_number(void)
52073 {
52074 - return atomic_add_return(1, &fc_event_seq);
52075 + return atomic_add_return_unchecked(1, &fc_event_seq);
52076 }
52077 EXPORT_SYMBOL(fc_get_event_number);
52078
52079 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52080 {
52081 int error;
52082
52083 - atomic_set(&fc_event_seq, 0);
52084 + atomic_set_unchecked(&fc_event_seq, 0);
52085
52086 error = transport_class_register(&fc_host_class);
52087 if (error)
52088 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52089 char *cp;
52090
52091 *val = simple_strtoul(buf, &cp, 0);
52092 - if ((*cp && (*cp != '\n')) || (*val < 0))
52093 + if (*cp && (*cp != '\n'))
52094 return -EINVAL;
52095 /*
52096 * Check for overflow; dev_loss_tmo is u32
52097 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52098 index 67d43e3..8cee73c 100644
52099 --- a/drivers/scsi/scsi_transport_iscsi.c
52100 +++ b/drivers/scsi/scsi_transport_iscsi.c
52101 @@ -79,7 +79,7 @@ struct iscsi_internal {
52102 struct transport_container session_cont;
52103 };
52104
52105 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52106 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52107 static struct workqueue_struct *iscsi_eh_timer_workq;
52108
52109 static DEFINE_IDA(iscsi_sess_ida);
52110 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52111 int err;
52112
52113 ihost = shost->shost_data;
52114 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52115 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52116
52117 if (target_id == ISCSI_MAX_TARGET) {
52118 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52119 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52120 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52121 ISCSI_TRANSPORT_VERSION);
52122
52123 - atomic_set(&iscsi_session_nr, 0);
52124 + atomic_set_unchecked(&iscsi_session_nr, 0);
52125
52126 err = class_register(&iscsi_transport_class);
52127 if (err)
52128 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52129 index ae45bd9..c32a586 100644
52130 --- a/drivers/scsi/scsi_transport_srp.c
52131 +++ b/drivers/scsi/scsi_transport_srp.c
52132 @@ -35,7 +35,7 @@
52133 #include "scsi_priv.h"
52134
52135 struct srp_host_attrs {
52136 - atomic_t next_port_id;
52137 + atomic_unchecked_t next_port_id;
52138 };
52139 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52140
52141 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52142 struct Scsi_Host *shost = dev_to_shost(dev);
52143 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52144
52145 - atomic_set(&srp_host->next_port_id, 0);
52146 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52147 return 0;
52148 }
52149
52150 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52151 rport_fast_io_fail_timedout);
52152 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52153
52154 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52155 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52156 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52157
52158 transport_setup_device(&rport->dev);
52159 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52160 index 2c2041c..9d94085 100644
52161 --- a/drivers/scsi/sd.c
52162 +++ b/drivers/scsi/sd.c
52163 @@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
52164 sdkp->disk = gd;
52165 sdkp->index = index;
52166 atomic_set(&sdkp->openers, 0);
52167 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52168 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52169
52170 if (!sdp->request_queue->rq_timeout) {
52171 if (sdp->type != TYPE_MOD)
52172 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52173 index 01cf888..59e0475 100644
52174 --- a/drivers/scsi/sg.c
52175 +++ b/drivers/scsi/sg.c
52176 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52177 sdp->disk->disk_name,
52178 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52179 NULL,
52180 - (char *)arg);
52181 + (char __user *)arg);
52182 case BLKTRACESTART:
52183 return blk_trace_startstop(sdp->device->request_queue, 1);
52184 case BLKTRACESTOP:
52185 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52186 index 11a5043..e36f04c 100644
52187 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52188 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52189 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52190 return i;
52191 }
52192
52193 -static struct bin_attribute fuse_bin_attr = {
52194 +static bin_attribute_no_const fuse_bin_attr = {
52195 .attr = { .name = "fuse", .mode = S_IRUGO, },
52196 .read = fuse_read,
52197 };
52198 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52199 index ca935df..ae8a3dc 100644
52200 --- a/drivers/spi/spi.c
52201 +++ b/drivers/spi/spi.c
52202 @@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
52203 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52204
52205 /* portable code must never pass more than 32 bytes */
52206 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52207 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52208
52209 static u8 *buf;
52210
52211 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52212 index b41429f..2de5373 100644
52213 --- a/drivers/staging/android/timed_output.c
52214 +++ b/drivers/staging/android/timed_output.c
52215 @@ -25,7 +25,7 @@
52216 #include "timed_output.h"
52217
52218 static struct class *timed_output_class;
52219 -static atomic_t device_count;
52220 +static atomic_unchecked_t device_count;
52221
52222 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52223 char *buf)
52224 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52225 timed_output_class = class_create(THIS_MODULE, "timed_output");
52226 if (IS_ERR(timed_output_class))
52227 return PTR_ERR(timed_output_class);
52228 - atomic_set(&device_count, 0);
52229 + atomic_set_unchecked(&device_count, 0);
52230 timed_output_class->dev_groups = timed_output_groups;
52231 }
52232
52233 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52234 if (ret < 0)
52235 return ret;
52236
52237 - tdev->index = atomic_inc_return(&device_count);
52238 + tdev->index = atomic_inc_return_unchecked(&device_count);
52239 tdev->dev = device_create(timed_output_class, NULL,
52240 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52241 if (IS_ERR(tdev->dev))
52242 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52243 index 001348c..cfaac8a 100644
52244 --- a/drivers/staging/gdm724x/gdm_tty.c
52245 +++ b/drivers/staging/gdm724x/gdm_tty.c
52246 @@ -44,7 +44,7 @@
52247 #define gdm_tty_send_control(n, r, v, d, l) (\
52248 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52249
52250 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52251 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52252
52253 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52254 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52255 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52256 index 6b22106..6c6e641 100644
52257 --- a/drivers/staging/imx-drm/imx-drm-core.c
52258 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52259 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52260 if (imxdrm->pipes >= MAX_CRTC)
52261 return -EINVAL;
52262
52263 - if (imxdrm->drm->open_count)
52264 + if (local_read(&imxdrm->drm->open_count))
52265 return -EBUSY;
52266
52267 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52268 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52269 index 503b2d7..c918745 100644
52270 --- a/drivers/staging/line6/driver.c
52271 +++ b/drivers/staging/line6/driver.c
52272 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52273 {
52274 struct usb_device *usbdev = line6->usbdev;
52275 int ret;
52276 - unsigned char len;
52277 + unsigned char *plen;
52278
52279 /* query the serial number: */
52280 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52281 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52282 return ret;
52283 }
52284
52285 + plen = kmalloc(1, GFP_KERNEL);
52286 + if (plen == NULL)
52287 + return -ENOMEM;
52288 +
52289 /* Wait for data length. We'll get 0xff until length arrives. */
52290 do {
52291 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52292 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52293 USB_DIR_IN,
52294 - 0x0012, 0x0000, &len, 1,
52295 + 0x0012, 0x0000, plen, 1,
52296 LINE6_TIMEOUT * HZ);
52297 if (ret < 0) {
52298 dev_err(line6->ifcdev,
52299 "receive length failed (error %d)\n", ret);
52300 + kfree(plen);
52301 return ret;
52302 }
52303 - } while (len == 0xff);
52304 + } while (*plen == 0xff);
52305
52306 - if (len != datalen) {
52307 + if (*plen != datalen) {
52308 /* should be equal or something went wrong */
52309 dev_err(line6->ifcdev,
52310 "length mismatch (expected %d, got %d)\n",
52311 - (int)datalen, (int)len);
52312 + (int)datalen, (int)*plen);
52313 + kfree(plen);
52314 return -EINVAL;
52315 }
52316 + kfree(plen);
52317
52318 /* receive the result: */
52319 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52320 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52321 index bcce919..f30fcf9 100644
52322 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52323 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52324 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52325 return 0;
52326 }
52327
52328 -sfw_test_client_ops_t brw_test_client;
52329 -void brw_init_test_client(void)
52330 -{
52331 - brw_test_client.tso_init = brw_client_init;
52332 - brw_test_client.tso_fini = brw_client_fini;
52333 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52334 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52335 +sfw_test_client_ops_t brw_test_client = {
52336 + .tso_init = brw_client_init,
52337 + .tso_fini = brw_client_fini,
52338 + .tso_prep_rpc = brw_client_prep_rpc,
52339 + .tso_done_rpc = brw_client_done_rpc,
52340 };
52341
52342 srpc_service_t brw_test_service;
52343 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52344 index 7e83dff..1f9a545 100644
52345 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52346 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52347 @@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
52348
52349 extern sfw_test_client_ops_t ping_test_client;
52350 extern srpc_service_t ping_test_service;
52351 -extern void ping_init_test_client(void);
52352 extern void ping_init_test_service(void);
52353
52354 extern sfw_test_client_ops_t brw_test_client;
52355 extern srpc_service_t brw_test_service;
52356 -extern void brw_init_test_client(void);
52357 extern void brw_init_test_service(void);
52358
52359
52360 @@ -1682,12 +1680,10 @@ sfw_startup (void)
52361 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52362 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52363
52364 - brw_init_test_client();
52365 brw_init_test_service();
52366 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52367 LASSERT (rc == 0);
52368
52369 - ping_init_test_client();
52370 ping_init_test_service();
52371 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52372 LASSERT (rc == 0);
52373 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52374 index 750cac4..e4d751f 100644
52375 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52376 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52377 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52378 return 0;
52379 }
52380
52381 -sfw_test_client_ops_t ping_test_client;
52382 -void ping_init_test_client(void)
52383 -{
52384 - ping_test_client.tso_init = ping_client_init;
52385 - ping_test_client.tso_fini = ping_client_fini;
52386 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52387 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52388 -}
52389 +sfw_test_client_ops_t ping_test_client = {
52390 + .tso_init = ping_client_init,
52391 + .tso_fini = ping_client_fini,
52392 + .tso_prep_rpc = ping_client_prep_rpc,
52393 + .tso_done_rpc = ping_client_done_rpc,
52394 +};
52395
52396 srpc_service_t ping_test_service;
52397 void ping_init_test_service(void)
52398 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52399 index 30b1812f..9e5bd0b 100644
52400 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52401 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52402 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
52403 ldlm_completion_callback lcs_completion;
52404 ldlm_blocking_callback lcs_blocking;
52405 ldlm_glimpse_callback lcs_glimpse;
52406 -};
52407 +} __no_const;
52408
52409 /* ldlm_lockd.c */
52410 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52411 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52412 index 489bdd3..65058081 100644
52413 --- a/drivers/staging/lustre/lustre/include/obd.h
52414 +++ b/drivers/staging/lustre/lustre/include/obd.h
52415 @@ -1438,7 +1438,7 @@ struct md_ops {
52416 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52417 * wrapper function in include/linux/obd_class.h.
52418 */
52419 -};
52420 +} __no_const;
52421
52422 struct lsm_operations {
52423 void (*lsm_free)(struct lov_stripe_md *);
52424 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52425 index b798daa..b28ca8f 100644
52426 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52427 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52428 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52429 int added = (mode == LCK_NL);
52430 int overlaps = 0;
52431 int splitted = 0;
52432 - const struct ldlm_callback_suite null_cbs = { NULL };
52433 + const struct ldlm_callback_suite null_cbs = { };
52434
52435 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52436 *flags, new->l_policy_data.l_flock.owner,
52437 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52438 index 13a9266..3439390 100644
52439 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52440 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52441 @@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52442 void __user *buffer, size_t *lenp, loff_t *ppos)
52443 {
52444 int rc, max_delay_cs;
52445 - struct ctl_table dummy = *table;
52446 + ctl_table_no_const dummy = *table;
52447 long d;
52448
52449 dummy.data = &max_delay_cs;
52450 @@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52451 void __user *buffer, size_t *lenp, loff_t *ppos)
52452 {
52453 int rc, min_delay_cs;
52454 - struct ctl_table dummy = *table;
52455 + ctl_table_no_const dummy = *table;
52456 long d;
52457
52458 dummy.data = &min_delay_cs;
52459 @@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52460 void __user *buffer, size_t *lenp, loff_t *ppos)
52461 {
52462 int rc, backoff;
52463 - struct ctl_table dummy = *table;
52464 + ctl_table_no_const dummy = *table;
52465
52466 dummy.data = &backoff;
52467 dummy.proc_handler = &proc_dointvec;
52468 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52469 index 3396858..c0bd996 100644
52470 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52471 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52472 @@ -314,11 +314,11 @@ out:
52473
52474
52475 struct cfs_psdev_ops libcfs_psdev_ops = {
52476 - libcfs_psdev_open,
52477 - libcfs_psdev_release,
52478 - NULL,
52479 - NULL,
52480 - libcfs_ioctl
52481 + .p_open = libcfs_psdev_open,
52482 + .p_close = libcfs_psdev_release,
52483 + .p_read = NULL,
52484 + .p_write = NULL,
52485 + .p_ioctl = libcfs_ioctl
52486 };
52487
52488 extern int insert_proc(void);
52489 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52490 index efa2faf..03a9836 100644
52491 --- a/drivers/staging/lustre/lustre/llite/dir.c
52492 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52493 @@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52494 int mode;
52495 int err;
52496
52497 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52498 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52499 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52500 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52501 lump);
52502 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52503 index a0f4868..139f1fb 100644
52504 --- a/drivers/staging/octeon/ethernet-rx.c
52505 +++ b/drivers/staging/octeon/ethernet-rx.c
52506 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52507 /* Increment RX stats for virtual ports */
52508 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52509 #ifdef CONFIG_64BIT
52510 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52511 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52512 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52513 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52514 #else
52515 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52516 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52517 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52518 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52519 #endif
52520 }
52521 netif_receive_skb(skb);
52522 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52523 dev->name);
52524 */
52525 #ifdef CONFIG_64BIT
52526 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52527 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52528 #else
52529 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52530 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52531 #endif
52532 dev_kfree_skb_irq(skb);
52533 }
52534 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52535 index 2aa7235..ba3c205 100644
52536 --- a/drivers/staging/octeon/ethernet.c
52537 +++ b/drivers/staging/octeon/ethernet.c
52538 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52539 * since the RX tasklet also increments it.
52540 */
52541 #ifdef CONFIG_64BIT
52542 - atomic64_add(rx_status.dropped_packets,
52543 - (atomic64_t *)&priv->stats.rx_dropped);
52544 + atomic64_add_unchecked(rx_status.dropped_packets,
52545 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52546 #else
52547 - atomic_add(rx_status.dropped_packets,
52548 - (atomic_t *)&priv->stats.rx_dropped);
52549 + atomic_add_unchecked(rx_status.dropped_packets,
52550 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52551 #endif
52552 }
52553
52554 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52555 index 56d5c50..a14f4db 100644
52556 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52557 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52558 @@ -234,7 +234,7 @@ struct hal_ops {
52559
52560 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52561 void (*hal_reset_security_engine)(struct adapter *adapter);
52562 -};
52563 +} __no_const;
52564
52565 enum rt_eeprom_type {
52566 EEPROM_93C46,
52567 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52568 index dc23395..cf7e9b1 100644
52569 --- a/drivers/staging/rtl8712/rtl871x_io.h
52570 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52571 @@ -108,7 +108,7 @@ struct _io_ops {
52572 u8 *pmem);
52573 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52574 u8 *pmem);
52575 -};
52576 +} __no_const;
52577
52578 struct io_req {
52579 struct list_head list;
52580 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52581 index 2bf2e2f..84421c9 100644
52582 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52583 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52584 @@ -228,7 +228,7 @@ typedef struct {
52585 void (*device_resume)(ulong busNo, ulong devNo);
52586 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52587 ulong *maxSize);
52588 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52589 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52590
52591 /* These functions live inside visorchipset, and will be called to indicate
52592 * responses to specific events (by code outside of visorchipset).
52593 @@ -243,7 +243,7 @@ typedef struct {
52594 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52595 void (*device_pause)(ulong busNo, ulong devNo, int response);
52596 void (*device_resume)(ulong busNo, ulong devNo, int response);
52597 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52598 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52599
52600 /** Register functions (in the bus driver) to get called by visorchipset
52601 * whenever a bus or device appears for which this service partition is
52602 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52603 index 164136b..7244df5 100644
52604 --- a/drivers/staging/vt6655/hostap.c
52605 +++ b/drivers/staging/vt6655/hostap.c
52606 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
52607 *
52608 */
52609
52610 +static net_device_ops_no_const apdev_netdev_ops;
52611 +
52612 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52613 {
52614 PSDevice apdev_priv;
52615 struct net_device *dev = pDevice->dev;
52616 int ret;
52617 - const struct net_device_ops apdev_netdev_ops = {
52618 - .ndo_start_xmit = pDevice->tx_80211,
52619 - };
52620
52621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
52622
52623 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52624 *apdev_priv = *pDevice;
52625 eth_hw_addr_inherit(pDevice->apdev, dev);
52626
52627 + /* only half broken now */
52628 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52629 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52630
52631 pDevice->apdev->type = ARPHRD_IEEE80211;
52632 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52633 index e7e9372..161f530 100644
52634 --- a/drivers/target/sbp/sbp_target.c
52635 +++ b/drivers/target/sbp/sbp_target.c
52636 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52637
52638 #define SESSION_MAINTENANCE_INTERVAL HZ
52639
52640 -static atomic_t login_id = ATOMIC_INIT(0);
52641 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52642
52643 static void session_maintenance_work(struct work_struct *);
52644 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52645 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52646 login->lun = se_lun;
52647 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52648 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52649 - login->login_id = atomic_inc_return(&login_id);
52650 + login->login_id = atomic_inc_return_unchecked(&login_id);
52651
52652 login->tgt_agt = sbp_target_agent_register(login);
52653 if (IS_ERR(login->tgt_agt)) {
52654 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52655 index 15a1c13..6c9b96b 100644
52656 --- a/drivers/target/target_core_device.c
52657 +++ b/drivers/target/target_core_device.c
52658 @@ -1526,7 +1526,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52659 spin_lock_init(&dev->se_tmr_lock);
52660 spin_lock_init(&dev->qf_cmd_lock);
52661 sema_init(&dev->caw_sem, 1);
52662 - atomic_set(&dev->dev_ordered_id, 0);
52663 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52664 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52665 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52666 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52667 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52668 index ab61014..8f1116e 100644
52669 --- a/drivers/target/target_core_transport.c
52670 +++ b/drivers/target/target_core_transport.c
52671 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52672 * Used to determine when ORDERED commands should go from
52673 * Dormant to Active status.
52674 */
52675 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52676 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52677 smp_mb__after_atomic();
52678 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52679 cmd->se_ordered_id, cmd->sam_task_attr,
52680 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52681 index 4b2b999..cad9fa5 100644
52682 --- a/drivers/thermal/of-thermal.c
52683 +++ b/drivers/thermal/of-thermal.c
52684 @@ -30,6 +30,7 @@
52685 #include <linux/err.h>
52686 #include <linux/export.h>
52687 #include <linux/string.h>
52688 +#include <linux/mm.h>
52689
52690 #include "thermal_core.h"
52691
52692 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52693 tz->get_trend = get_trend;
52694 tz->sensor_data = data;
52695
52696 - tzd->ops->get_temp = of_thermal_get_temp;
52697 - tzd->ops->get_trend = of_thermal_get_trend;
52698 + pax_open_kernel();
52699 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52700 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52701 + pax_close_kernel();
52702 mutex_unlock(&tzd->lock);
52703
52704 return tzd;
52705 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52706 return;
52707
52708 mutex_lock(&tzd->lock);
52709 - tzd->ops->get_temp = NULL;
52710 - tzd->ops->get_trend = NULL;
52711 + pax_open_kernel();
52712 + *(void **)&tzd->ops->get_temp = NULL;
52713 + *(void **)&tzd->ops->get_trend = NULL;
52714 + pax_close_kernel();
52715
52716 tz->get_temp = NULL;
52717 tz->get_trend = NULL;
52718 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52719 index fd66f57..48e6376 100644
52720 --- a/drivers/tty/cyclades.c
52721 +++ b/drivers/tty/cyclades.c
52722 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52723 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52724 info->port.count);
52725 #endif
52726 - info->port.count++;
52727 + atomic_inc(&info->port.count);
52728 #ifdef CY_DEBUG_COUNT
52729 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52730 - current->pid, info->port.count);
52731 + current->pid, atomic_read(&info->port.count));
52732 #endif
52733
52734 /*
52735 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52736 for (j = 0; j < cy_card[i].nports; j++) {
52737 info = &cy_card[i].ports[j];
52738
52739 - if (info->port.count) {
52740 + if (atomic_read(&info->port.count)) {
52741 /* XXX is the ldisc num worth this? */
52742 struct tty_struct *tty;
52743 struct tty_ldisc *ld;
52744 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52745 index 4fcec1d..5a036f7 100644
52746 --- a/drivers/tty/hvc/hvc_console.c
52747 +++ b/drivers/tty/hvc/hvc_console.c
52748 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52749
52750 spin_lock_irqsave(&hp->port.lock, flags);
52751 /* Check and then increment for fast path open. */
52752 - if (hp->port.count++ > 0) {
52753 + if (atomic_inc_return(&hp->port.count) > 1) {
52754 spin_unlock_irqrestore(&hp->port.lock, flags);
52755 hvc_kick();
52756 return 0;
52757 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52758
52759 spin_lock_irqsave(&hp->port.lock, flags);
52760
52761 - if (--hp->port.count == 0) {
52762 + if (atomic_dec_return(&hp->port.count) == 0) {
52763 spin_unlock_irqrestore(&hp->port.lock, flags);
52764 /* We are done with the tty pointer now. */
52765 tty_port_tty_set(&hp->port, NULL);
52766 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52767 */
52768 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52769 } else {
52770 - if (hp->port.count < 0)
52771 + if (atomic_read(&hp->port.count) < 0)
52772 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52773 - hp->vtermno, hp->port.count);
52774 + hp->vtermno, atomic_read(&hp->port.count));
52775 spin_unlock_irqrestore(&hp->port.lock, flags);
52776 }
52777 }
52778 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52779 * open->hangup case this can be called after the final close so prevent
52780 * that from happening for now.
52781 */
52782 - if (hp->port.count <= 0) {
52783 + if (atomic_read(&hp->port.count) <= 0) {
52784 spin_unlock_irqrestore(&hp->port.lock, flags);
52785 return;
52786 }
52787
52788 - hp->port.count = 0;
52789 + atomic_set(&hp->port.count, 0);
52790 spin_unlock_irqrestore(&hp->port.lock, flags);
52791 tty_port_tty_set(&hp->port, NULL);
52792
52793 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52794 return -EPIPE;
52795
52796 /* FIXME what's this (unprotected) check for? */
52797 - if (hp->port.count <= 0)
52798 + if (atomic_read(&hp->port.count) <= 0)
52799 return -EIO;
52800
52801 spin_lock_irqsave(&hp->lock, flags);
52802 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52803 index 81e939e..95ead10 100644
52804 --- a/drivers/tty/hvc/hvcs.c
52805 +++ b/drivers/tty/hvc/hvcs.c
52806 @@ -83,6 +83,7 @@
52807 #include <asm/hvcserver.h>
52808 #include <asm/uaccess.h>
52809 #include <asm/vio.h>
52810 +#include <asm/local.h>
52811
52812 /*
52813 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52814 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52815
52816 spin_lock_irqsave(&hvcsd->lock, flags);
52817
52818 - if (hvcsd->port.count > 0) {
52819 + if (atomic_read(&hvcsd->port.count) > 0) {
52820 spin_unlock_irqrestore(&hvcsd->lock, flags);
52821 printk(KERN_INFO "HVCS: vterm state unchanged. "
52822 "The hvcs device node is still in use.\n");
52823 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52824 }
52825 }
52826
52827 - hvcsd->port.count = 0;
52828 + atomic_set(&hvcsd->port.count, 0);
52829 hvcsd->port.tty = tty;
52830 tty->driver_data = hvcsd;
52831
52832 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52833 unsigned long flags;
52834
52835 spin_lock_irqsave(&hvcsd->lock, flags);
52836 - hvcsd->port.count++;
52837 + atomic_inc(&hvcsd->port.count);
52838 hvcsd->todo_mask |= HVCS_SCHED_READ;
52839 spin_unlock_irqrestore(&hvcsd->lock, flags);
52840
52841 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52842 hvcsd = tty->driver_data;
52843
52844 spin_lock_irqsave(&hvcsd->lock, flags);
52845 - if (--hvcsd->port.count == 0) {
52846 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52847
52848 vio_disable_interrupts(hvcsd->vdev);
52849
52850 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52851
52852 free_irq(irq, hvcsd);
52853 return;
52854 - } else if (hvcsd->port.count < 0) {
52855 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52856 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52857 " is missmanaged.\n",
52858 - hvcsd->vdev->unit_address, hvcsd->port.count);
52859 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52860 }
52861
52862 spin_unlock_irqrestore(&hvcsd->lock, flags);
52863 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52864
52865 spin_lock_irqsave(&hvcsd->lock, flags);
52866 /* Preserve this so that we know how many kref refs to put */
52867 - temp_open_count = hvcsd->port.count;
52868 + temp_open_count = atomic_read(&hvcsd->port.count);
52869
52870 /*
52871 * Don't kref put inside the spinlock because the destruction
52872 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52873 tty->driver_data = NULL;
52874 hvcsd->port.tty = NULL;
52875
52876 - hvcsd->port.count = 0;
52877 + atomic_set(&hvcsd->port.count, 0);
52878
52879 /* This will drop any buffered data on the floor which is OK in a hangup
52880 * scenario. */
52881 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52882 * the middle of a write operation? This is a crummy place to do this
52883 * but we want to keep it all in the spinlock.
52884 */
52885 - if (hvcsd->port.count <= 0) {
52886 + if (atomic_read(&hvcsd->port.count) <= 0) {
52887 spin_unlock_irqrestore(&hvcsd->lock, flags);
52888 return -ENODEV;
52889 }
52890 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52891 {
52892 struct hvcs_struct *hvcsd = tty->driver_data;
52893
52894 - if (!hvcsd || hvcsd->port.count <= 0)
52895 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52896 return 0;
52897
52898 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52899 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52900 index 4190199..06d5bfa 100644
52901 --- a/drivers/tty/hvc/hvsi.c
52902 +++ b/drivers/tty/hvc/hvsi.c
52903 @@ -85,7 +85,7 @@ struct hvsi_struct {
52904 int n_outbuf;
52905 uint32_t vtermno;
52906 uint32_t virq;
52907 - atomic_t seqno; /* HVSI packet sequence number */
52908 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52909 uint16_t mctrl;
52910 uint8_t state; /* HVSI protocol state */
52911 uint8_t flags;
52912 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52913
52914 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52915 packet.hdr.len = sizeof(struct hvsi_query_response);
52916 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52917 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52918 packet.verb = VSV_SEND_VERSION_NUMBER;
52919 packet.u.version = HVSI_VERSION;
52920 packet.query_seqno = query_seqno+1;
52921 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52922
52923 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52924 packet.hdr.len = sizeof(struct hvsi_query);
52925 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52926 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52927 packet.verb = verb;
52928
52929 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52930 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52931 int wrote;
52932
52933 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52934 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52935 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52936 packet.hdr.len = sizeof(struct hvsi_control);
52937 packet.verb = VSV_SET_MODEM_CTL;
52938 packet.mask = HVSI_TSDTR;
52939 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52940 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52941
52942 packet.hdr.type = VS_DATA_PACKET_HEADER;
52943 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52944 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52945 packet.hdr.len = count + sizeof(struct hvsi_header);
52946 memcpy(&packet.data, buf, count);
52947
52948 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52949 struct hvsi_control packet __ALIGNED__;
52950
52951 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52952 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52953 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52954 packet.hdr.len = 6;
52955 packet.verb = VSV_CLOSE_PROTOCOL;
52956
52957 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52958
52959 tty_port_tty_set(&hp->port, tty);
52960 spin_lock_irqsave(&hp->lock, flags);
52961 - hp->port.count++;
52962 + atomic_inc(&hp->port.count);
52963 atomic_set(&hp->seqno, 0);
52964 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52965 spin_unlock_irqrestore(&hp->lock, flags);
52966 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52967
52968 spin_lock_irqsave(&hp->lock, flags);
52969
52970 - if (--hp->port.count == 0) {
52971 + if (atomic_dec_return(&hp->port.count) == 0) {
52972 tty_port_tty_set(&hp->port, NULL);
52973 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52974
52975 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52976
52977 spin_lock_irqsave(&hp->lock, flags);
52978 }
52979 - } else if (hp->port.count < 0)
52980 + } else if (atomic_read(&hp->port.count) < 0)
52981 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52982 - hp - hvsi_ports, hp->port.count);
52983 + hp - hvsi_ports, atomic_read(&hp->port.count));
52984
52985 spin_unlock_irqrestore(&hp->lock, flags);
52986 }
52987 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52988 tty_port_tty_set(&hp->port, NULL);
52989
52990 spin_lock_irqsave(&hp->lock, flags);
52991 - hp->port.count = 0;
52992 + atomic_set(&hp->port.count, 0);
52993 hp->n_outbuf = 0;
52994 spin_unlock_irqrestore(&hp->lock, flags);
52995 }
52996 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52997 index 7ae6c29..05c6dba 100644
52998 --- a/drivers/tty/hvc/hvsi_lib.c
52999 +++ b/drivers/tty/hvc/hvsi_lib.c
53000 @@ -8,7 +8,7 @@
53001
53002 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53003 {
53004 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53005 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53006
53007 /* Assumes that always succeeds, works in practice */
53008 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53009 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53010
53011 /* Reset state */
53012 pv->established = 0;
53013 - atomic_set(&pv->seqno, 0);
53014 + atomic_set_unchecked(&pv->seqno, 0);
53015
53016 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53017
53018 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53019 index 345cebb..d5a1e9e 100644
53020 --- a/drivers/tty/ipwireless/tty.c
53021 +++ b/drivers/tty/ipwireless/tty.c
53022 @@ -28,6 +28,7 @@
53023 #include <linux/tty_driver.h>
53024 #include <linux/tty_flip.h>
53025 #include <linux/uaccess.h>
53026 +#include <asm/local.h>
53027
53028 #include "tty.h"
53029 #include "network.h"
53030 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53031 return -ENODEV;
53032
53033 mutex_lock(&tty->ipw_tty_mutex);
53034 - if (tty->port.count == 0)
53035 + if (atomic_read(&tty->port.count) == 0)
53036 tty->tx_bytes_queued = 0;
53037
53038 - tty->port.count++;
53039 + atomic_inc(&tty->port.count);
53040
53041 tty->port.tty = linux_tty;
53042 linux_tty->driver_data = tty;
53043 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53044
53045 static void do_ipw_close(struct ipw_tty *tty)
53046 {
53047 - tty->port.count--;
53048 -
53049 - if (tty->port.count == 0) {
53050 + if (atomic_dec_return(&tty->port.count) == 0) {
53051 struct tty_struct *linux_tty = tty->port.tty;
53052
53053 if (linux_tty != NULL) {
53054 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53055 return;
53056
53057 mutex_lock(&tty->ipw_tty_mutex);
53058 - if (tty->port.count == 0) {
53059 + if (atomic_read(&tty->port.count) == 0) {
53060 mutex_unlock(&tty->ipw_tty_mutex);
53061 return;
53062 }
53063 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53064
53065 mutex_lock(&tty->ipw_tty_mutex);
53066
53067 - if (!tty->port.count) {
53068 + if (!atomic_read(&tty->port.count)) {
53069 mutex_unlock(&tty->ipw_tty_mutex);
53070 return;
53071 }
53072 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53073 return -ENODEV;
53074
53075 mutex_lock(&tty->ipw_tty_mutex);
53076 - if (!tty->port.count) {
53077 + if (!atomic_read(&tty->port.count)) {
53078 mutex_unlock(&tty->ipw_tty_mutex);
53079 return -EINVAL;
53080 }
53081 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53082 if (!tty)
53083 return -ENODEV;
53084
53085 - if (!tty->port.count)
53086 + if (!atomic_read(&tty->port.count))
53087 return -EINVAL;
53088
53089 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53090 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53091 if (!tty)
53092 return 0;
53093
53094 - if (!tty->port.count)
53095 + if (!atomic_read(&tty->port.count))
53096 return 0;
53097
53098 return tty->tx_bytes_queued;
53099 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53100 if (!tty)
53101 return -ENODEV;
53102
53103 - if (!tty->port.count)
53104 + if (!atomic_read(&tty->port.count))
53105 return -EINVAL;
53106
53107 return get_control_lines(tty);
53108 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53109 if (!tty)
53110 return -ENODEV;
53111
53112 - if (!tty->port.count)
53113 + if (!atomic_read(&tty->port.count))
53114 return -EINVAL;
53115
53116 return set_control_lines(tty, set, clear);
53117 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53118 if (!tty)
53119 return -ENODEV;
53120
53121 - if (!tty->port.count)
53122 + if (!atomic_read(&tty->port.count))
53123 return -EINVAL;
53124
53125 /* FIXME: Exactly how is the tty object locked here .. */
53126 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53127 * are gone */
53128 mutex_lock(&ttyj->ipw_tty_mutex);
53129 }
53130 - while (ttyj->port.count)
53131 + while (atomic_read(&ttyj->port.count))
53132 do_ipw_close(ttyj);
53133 ipwireless_disassociate_network_ttys(network,
53134 ttyj->channel_idx);
53135 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53136 index 1deaca4..c8582d4 100644
53137 --- a/drivers/tty/moxa.c
53138 +++ b/drivers/tty/moxa.c
53139 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53140 }
53141
53142 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53143 - ch->port.count++;
53144 + atomic_inc(&ch->port.count);
53145 tty->driver_data = ch;
53146 tty_port_tty_set(&ch->port, tty);
53147 mutex_lock(&ch->port.mutex);
53148 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53149 index c434376..114ce13 100644
53150 --- a/drivers/tty/n_gsm.c
53151 +++ b/drivers/tty/n_gsm.c
53152 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53153 spin_lock_init(&dlci->lock);
53154 mutex_init(&dlci->mutex);
53155 dlci->fifo = &dlci->_fifo;
53156 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53157 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53158 kfree(dlci);
53159 return NULL;
53160 }
53161 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53162 struct gsm_dlci *dlci = tty->driver_data;
53163 struct tty_port *port = &dlci->port;
53164
53165 - port->count++;
53166 + atomic_inc(&port->count);
53167 tty_port_tty_set(port, tty);
53168
53169 dlci->modem_rx = 0;
53170 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53171 index f44f1ba..a8d5915 100644
53172 --- a/drivers/tty/n_tty.c
53173 +++ b/drivers/tty/n_tty.c
53174 @@ -115,7 +115,7 @@ struct n_tty_data {
53175 int minimum_to_wake;
53176
53177 /* consumer-published */
53178 - size_t read_tail;
53179 + size_t read_tail __intentional_overflow(-1);
53180 size_t line_start;
53181
53182 /* protected by output lock */
53183 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53184 {
53185 *ops = tty_ldisc_N_TTY;
53186 ops->owner = NULL;
53187 - ops->refcount = ops->flags = 0;
53188 + atomic_set(&ops->refcount, 0);
53189 + ops->flags = 0;
53190 }
53191 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53192 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53193 index 9bbdb1d..dc514ee 100644
53194 --- a/drivers/tty/pty.c
53195 +++ b/drivers/tty/pty.c
53196 @@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
53197 panic("Couldn't register Unix98 pts driver");
53198
53199 /* Now create the /dev/ptmx special device */
53200 + pax_open_kernel();
53201 tty_default_fops(&ptmx_fops);
53202 - ptmx_fops.open = ptmx_open;
53203 + *(void **)&ptmx_fops.open = ptmx_open;
53204 + pax_close_kernel();
53205
53206 cdev_init(&ptmx_cdev, &ptmx_fops);
53207 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53208 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53209 index 383c4c7..d408e21 100644
53210 --- a/drivers/tty/rocket.c
53211 +++ b/drivers/tty/rocket.c
53212 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53213 tty->driver_data = info;
53214 tty_port_tty_set(port, tty);
53215
53216 - if (port->count++ == 0) {
53217 + if (atomic_inc_return(&port->count) == 1) {
53218 atomic_inc(&rp_num_ports_open);
53219
53220 #ifdef ROCKET_DEBUG_OPEN
53221 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53222 #endif
53223 }
53224 #ifdef ROCKET_DEBUG_OPEN
53225 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53226 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53227 #endif
53228
53229 /*
53230 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53231 spin_unlock_irqrestore(&info->port.lock, flags);
53232 return;
53233 }
53234 - if (info->port.count)
53235 + if (atomic_read(&info->port.count))
53236 atomic_dec(&rp_num_ports_open);
53237 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53238 spin_unlock_irqrestore(&info->port.lock, flags);
53239 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53240 index aa28209..e08fb85 100644
53241 --- a/drivers/tty/serial/ioc4_serial.c
53242 +++ b/drivers/tty/serial/ioc4_serial.c
53243 @@ -437,7 +437,7 @@ struct ioc4_soft {
53244 } is_intr_info[MAX_IOC4_INTR_ENTS];
53245
53246 /* Number of entries active in the above array */
53247 - atomic_t is_num_intrs;
53248 + atomic_unchecked_t is_num_intrs;
53249 } is_intr_type[IOC4_NUM_INTR_TYPES];
53250
53251 /* is_ir_lock must be held while
53252 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53253 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53254 || (type == IOC4_OTHER_INTR_TYPE)));
53255
53256 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53257 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53258 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53259
53260 /* Save off the lower level interrupt handler */
53261 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53262
53263 soft = arg;
53264 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53265 - num_intrs = (int)atomic_read(
53266 + num_intrs = (int)atomic_read_unchecked(
53267 &soft->is_intr_type[intr_type].is_num_intrs);
53268
53269 this_mir = this_ir = pending_intrs(soft, intr_type);
53270 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53271 index 6ec7501..265bcbf 100644
53272 --- a/drivers/tty/serial/kgdb_nmi.c
53273 +++ b/drivers/tty/serial/kgdb_nmi.c
53274 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53275 * I/O utilities that messages sent to the console will automatically
53276 * be displayed on the dbg_io.
53277 */
53278 - dbg_io_ops->is_console = true;
53279 + pax_open_kernel();
53280 + *(int *)&dbg_io_ops->is_console = true;
53281 + pax_close_kernel();
53282
53283 return 0;
53284 }
53285 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53286 index a260cde..6b2b5ce 100644
53287 --- a/drivers/tty/serial/kgdboc.c
53288 +++ b/drivers/tty/serial/kgdboc.c
53289 @@ -24,8 +24,9 @@
53290 #define MAX_CONFIG_LEN 40
53291
53292 static struct kgdb_io kgdboc_io_ops;
53293 +static struct kgdb_io kgdboc_io_ops_console;
53294
53295 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53296 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53297 static int configured = -1;
53298
53299 static char config[MAX_CONFIG_LEN];
53300 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53301 kgdboc_unregister_kbd();
53302 if (configured == 1)
53303 kgdb_unregister_io_module(&kgdboc_io_ops);
53304 + else if (configured == 2)
53305 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53306 }
53307
53308 static int configure_kgdboc(void)
53309 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53310 int err;
53311 char *cptr = config;
53312 struct console *cons;
53313 + int is_console = 0;
53314
53315 err = kgdboc_option_setup(config);
53316 if (err || !strlen(config) || isspace(config[0]))
53317 goto noconfig;
53318
53319 err = -ENODEV;
53320 - kgdboc_io_ops.is_console = 0;
53321 kgdb_tty_driver = NULL;
53322
53323 kgdboc_use_kms = 0;
53324 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53325 int idx;
53326 if (cons->device && cons->device(cons, &idx) == p &&
53327 idx == tty_line) {
53328 - kgdboc_io_ops.is_console = 1;
53329 + is_console = 1;
53330 break;
53331 }
53332 cons = cons->next;
53333 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53334 kgdb_tty_line = tty_line;
53335
53336 do_register:
53337 - err = kgdb_register_io_module(&kgdboc_io_ops);
53338 + if (is_console) {
53339 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53340 + configured = 2;
53341 + } else {
53342 + err = kgdb_register_io_module(&kgdboc_io_ops);
53343 + configured = 1;
53344 + }
53345 if (err)
53346 goto noconfig;
53347
53348 @@ -205,8 +214,6 @@ do_register:
53349 if (err)
53350 goto nmi_con_failed;
53351
53352 - configured = 1;
53353 -
53354 return 0;
53355
53356 nmi_con_failed:
53357 @@ -223,7 +230,7 @@ noconfig:
53358 static int __init init_kgdboc(void)
53359 {
53360 /* Already configured? */
53361 - if (configured == 1)
53362 + if (configured >= 1)
53363 return 0;
53364
53365 return configure_kgdboc();
53366 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53367 if (config[len - 1] == '\n')
53368 config[len - 1] = '\0';
53369
53370 - if (configured == 1)
53371 + if (configured >= 1)
53372 cleanup_kgdboc();
53373
53374 /* Go and configure with the new params. */
53375 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53376 .post_exception = kgdboc_post_exp_handler,
53377 };
53378
53379 +static struct kgdb_io kgdboc_io_ops_console = {
53380 + .name = "kgdboc",
53381 + .read_char = kgdboc_get_char,
53382 + .write_char = kgdboc_put_char,
53383 + .pre_exception = kgdboc_pre_exp_handler,
53384 + .post_exception = kgdboc_post_exp_handler,
53385 + .is_console = 1
53386 +};
53387 +
53388 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53389 /* This is only available if kgdboc is a built in for early debugging */
53390 static int __init kgdboc_early_init(char *opt)
53391 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53392 index 077570a..12550a9 100644
53393 --- a/drivers/tty/serial/msm_serial.c
53394 +++ b/drivers/tty/serial/msm_serial.c
53395 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
53396 .cons = MSM_CONSOLE,
53397 };
53398
53399 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53400 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53401
53402 static const struct of_device_id msm_uartdm_table[] = {
53403 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53404 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53405 int irq;
53406
53407 if (pdev->id == -1)
53408 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53409 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53410
53411 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53412 return -ENXIO;
53413 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53414 index c78f43a..22b1dab 100644
53415 --- a/drivers/tty/serial/samsung.c
53416 +++ b/drivers/tty/serial/samsung.c
53417 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53418 }
53419 }
53420
53421 +static int s3c64xx_serial_startup(struct uart_port *port);
53422 static int s3c24xx_serial_startup(struct uart_port *port)
53423 {
53424 struct s3c24xx_uart_port *ourport = to_ourport(port);
53425 int ret;
53426
53427 + /* Startup sequence is different for s3c64xx and higher SoC's */
53428 + if (s3c24xx_serial_has_interrupt_mask(port))
53429 + return s3c64xx_serial_startup(port);
53430 +
53431 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53432 port, (unsigned long long)port->mapbase, port->membase);
53433
53434 @@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53435 /* setup info for port */
53436 port->dev = &platdev->dev;
53437
53438 - /* Startup sequence is different for s3c64xx and higher SoC's */
53439 - if (s3c24xx_serial_has_interrupt_mask(port))
53440 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53441 -
53442 port->uartclk = 1;
53443
53444 if (cfg->uart_flags & UPF_CONS_FLOW) {
53445 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53446 index 0f03988..8a8038d 100644
53447 --- a/drivers/tty/serial/serial_core.c
53448 +++ b/drivers/tty/serial/serial_core.c
53449 @@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53450
53451 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53452
53453 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53454 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53455 return;
53456
53457 /*
53458 @@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
53459 uart_flush_buffer(tty);
53460 uart_shutdown(tty, state);
53461 spin_lock_irqsave(&port->lock, flags);
53462 - port->count = 0;
53463 + atomic_set(&port->count, 0);
53464 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53465 spin_unlock_irqrestore(&port->lock, flags);
53466 tty_port_tty_set(port, NULL);
53467 @@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53468 goto end;
53469 }
53470
53471 - port->count++;
53472 + atomic_inc(&port->count);
53473 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53474 retval = -ENXIO;
53475 goto err_dec_count;
53476 @@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53477 end:
53478 return retval;
53479 err_dec_count:
53480 - port->count--;
53481 + atomic_inc(&port->count);
53482 mutex_unlock(&port->mutex);
53483 goto end;
53484 }
53485 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53486 index b799170..87dafd5 100644
53487 --- a/drivers/tty/synclink.c
53488 +++ b/drivers/tty/synclink.c
53489 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53490
53491 if (debug_level >= DEBUG_LEVEL_INFO)
53492 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53493 - __FILE__,__LINE__, info->device_name, info->port.count);
53494 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53495
53496 if (tty_port_close_start(&info->port, tty, filp) == 0)
53497 goto cleanup;
53498 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53499 cleanup:
53500 if (debug_level >= DEBUG_LEVEL_INFO)
53501 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53502 - tty->driver->name, info->port.count);
53503 + tty->driver->name, atomic_read(&info->port.count));
53504
53505 } /* end of mgsl_close() */
53506
53507 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53508
53509 mgsl_flush_buffer(tty);
53510 shutdown(info);
53511 -
53512 - info->port.count = 0;
53513 +
53514 + atomic_set(&info->port.count, 0);
53515 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53516 info->port.tty = NULL;
53517
53518 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53519
53520 if (debug_level >= DEBUG_LEVEL_INFO)
53521 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53522 - __FILE__,__LINE__, tty->driver->name, port->count );
53523 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53524
53525 spin_lock_irqsave(&info->irq_spinlock, flags);
53526 - port->count--;
53527 + atomic_dec(&port->count);
53528 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53529 port->blocked_open++;
53530
53531 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53532
53533 if (debug_level >= DEBUG_LEVEL_INFO)
53534 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53535 - __FILE__,__LINE__, tty->driver->name, port->count );
53536 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53537
53538 tty_unlock(tty);
53539 schedule();
53540 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53541
53542 /* FIXME: Racy on hangup during close wait */
53543 if (!tty_hung_up_p(filp))
53544 - port->count++;
53545 + atomic_inc(&port->count);
53546 port->blocked_open--;
53547
53548 if (debug_level >= DEBUG_LEVEL_INFO)
53549 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53550 - __FILE__,__LINE__, tty->driver->name, port->count );
53551 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53552
53553 if (!retval)
53554 port->flags |= ASYNC_NORMAL_ACTIVE;
53555 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53556
53557 if (debug_level >= DEBUG_LEVEL_INFO)
53558 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53559 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53560 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53561
53562 /* If port is closing, signal caller to try again */
53563 if (info->port.flags & ASYNC_CLOSING){
53564 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53565 spin_unlock_irqrestore(&info->netlock, flags);
53566 goto cleanup;
53567 }
53568 - info->port.count++;
53569 + atomic_inc(&info->port.count);
53570 spin_unlock_irqrestore(&info->netlock, flags);
53571
53572 - if (info->port.count == 1) {
53573 + if (atomic_read(&info->port.count) == 1) {
53574 /* 1st open on this device, init hardware */
53575 retval = startup(info);
53576 if (retval < 0)
53577 @@ -3442,8 +3442,8 @@ cleanup:
53578 if (retval) {
53579 if (tty->count == 1)
53580 info->port.tty = NULL; /* tty layer will release tty struct */
53581 - if(info->port.count)
53582 - info->port.count--;
53583 + if (atomic_read(&info->port.count))
53584 + atomic_dec(&info->port.count);
53585 }
53586
53587 return retval;
53588 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53589 unsigned short new_crctype;
53590
53591 /* return error if TTY interface open */
53592 - if (info->port.count)
53593 + if (atomic_read(&info->port.count))
53594 return -EBUSY;
53595
53596 switch (encoding)
53597 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53598
53599 /* arbitrate between network and tty opens */
53600 spin_lock_irqsave(&info->netlock, flags);
53601 - if (info->port.count != 0 || info->netcount != 0) {
53602 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53603 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53604 spin_unlock_irqrestore(&info->netlock, flags);
53605 return -EBUSY;
53606 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53607 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53608
53609 /* return error if TTY interface open */
53610 - if (info->port.count)
53611 + if (atomic_read(&info->port.count))
53612 return -EBUSY;
53613
53614 if (cmd != SIOCWANDEV)
53615 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53616 index 0e8c39b..e0cb171 100644
53617 --- a/drivers/tty/synclink_gt.c
53618 +++ b/drivers/tty/synclink_gt.c
53619 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53620 tty->driver_data = info;
53621 info->port.tty = tty;
53622
53623 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53624 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53625
53626 /* If port is closing, signal caller to try again */
53627 if (info->port.flags & ASYNC_CLOSING){
53628 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53629 mutex_unlock(&info->port.mutex);
53630 goto cleanup;
53631 }
53632 - info->port.count++;
53633 + atomic_inc(&info->port.count);
53634 spin_unlock_irqrestore(&info->netlock, flags);
53635
53636 - if (info->port.count == 1) {
53637 + if (atomic_read(&info->port.count) == 1) {
53638 /* 1st open on this device, init hardware */
53639 retval = startup(info);
53640 if (retval < 0) {
53641 @@ -715,8 +715,8 @@ cleanup:
53642 if (retval) {
53643 if (tty->count == 1)
53644 info->port.tty = NULL; /* tty layer will release tty struct */
53645 - if(info->port.count)
53646 - info->port.count--;
53647 + if(atomic_read(&info->port.count))
53648 + atomic_dec(&info->port.count);
53649 }
53650
53651 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53652 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53653
53654 if (sanity_check(info, tty->name, "close"))
53655 return;
53656 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53657 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53658
53659 if (tty_port_close_start(&info->port, tty, filp) == 0)
53660 goto cleanup;
53661 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53662 tty_port_close_end(&info->port, tty);
53663 info->port.tty = NULL;
53664 cleanup:
53665 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53666 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53667 }
53668
53669 static void hangup(struct tty_struct *tty)
53670 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53671 shutdown(info);
53672
53673 spin_lock_irqsave(&info->port.lock, flags);
53674 - info->port.count = 0;
53675 + atomic_set(&info->port.count, 0);
53676 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53677 info->port.tty = NULL;
53678 spin_unlock_irqrestore(&info->port.lock, flags);
53679 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53680 unsigned short new_crctype;
53681
53682 /* return error if TTY interface open */
53683 - if (info->port.count)
53684 + if (atomic_read(&info->port.count))
53685 return -EBUSY;
53686
53687 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53688 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53689
53690 /* arbitrate between network and tty opens */
53691 spin_lock_irqsave(&info->netlock, flags);
53692 - if (info->port.count != 0 || info->netcount != 0) {
53693 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53694 DBGINFO(("%s hdlc_open busy\n", dev->name));
53695 spin_unlock_irqrestore(&info->netlock, flags);
53696 return -EBUSY;
53697 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53698 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53699
53700 /* return error if TTY interface open */
53701 - if (info->port.count)
53702 + if (atomic_read(&info->port.count))
53703 return -EBUSY;
53704
53705 if (cmd != SIOCWANDEV)
53706 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53707 if (port == NULL)
53708 continue;
53709 spin_lock(&port->lock);
53710 - if ((port->port.count || port->netcount) &&
53711 + if ((atomic_read(&port->port.count) || port->netcount) &&
53712 port->pending_bh && !port->bh_running &&
53713 !port->bh_requested) {
53714 DBGISR(("%s bh queued\n", port->device_name));
53715 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53716 add_wait_queue(&port->open_wait, &wait);
53717
53718 spin_lock_irqsave(&info->lock, flags);
53719 - port->count--;
53720 + atomic_dec(&port->count);
53721 spin_unlock_irqrestore(&info->lock, flags);
53722 port->blocked_open++;
53723
53724 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53725 remove_wait_queue(&port->open_wait, &wait);
53726
53727 if (!tty_hung_up_p(filp))
53728 - port->count++;
53729 + atomic_inc(&port->count);
53730 port->blocked_open--;
53731
53732 if (!retval)
53733 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53734 index c3f9091..abe4601 100644
53735 --- a/drivers/tty/synclinkmp.c
53736 +++ b/drivers/tty/synclinkmp.c
53737 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53738
53739 if (debug_level >= DEBUG_LEVEL_INFO)
53740 printk("%s(%d):%s open(), old ref count = %d\n",
53741 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53742 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53743
53744 /* If port is closing, signal caller to try again */
53745 if (info->port.flags & ASYNC_CLOSING){
53746 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53747 spin_unlock_irqrestore(&info->netlock, flags);
53748 goto cleanup;
53749 }
53750 - info->port.count++;
53751 + atomic_inc(&info->port.count);
53752 spin_unlock_irqrestore(&info->netlock, flags);
53753
53754 - if (info->port.count == 1) {
53755 + if (atomic_read(&info->port.count) == 1) {
53756 /* 1st open on this device, init hardware */
53757 retval = startup(info);
53758 if (retval < 0)
53759 @@ -796,8 +796,8 @@ cleanup:
53760 if (retval) {
53761 if (tty->count == 1)
53762 info->port.tty = NULL; /* tty layer will release tty struct */
53763 - if(info->port.count)
53764 - info->port.count--;
53765 + if(atomic_read(&info->port.count))
53766 + atomic_dec(&info->port.count);
53767 }
53768
53769 return retval;
53770 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53771
53772 if (debug_level >= DEBUG_LEVEL_INFO)
53773 printk("%s(%d):%s close() entry, count=%d\n",
53774 - __FILE__,__LINE__, info->device_name, info->port.count);
53775 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53776
53777 if (tty_port_close_start(&info->port, tty, filp) == 0)
53778 goto cleanup;
53779 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53780 cleanup:
53781 if (debug_level >= DEBUG_LEVEL_INFO)
53782 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53783 - tty->driver->name, info->port.count);
53784 + tty->driver->name, atomic_read(&info->port.count));
53785 }
53786
53787 /* Called by tty_hangup() when a hangup is signaled.
53788 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53789 shutdown(info);
53790
53791 spin_lock_irqsave(&info->port.lock, flags);
53792 - info->port.count = 0;
53793 + atomic_set(&info->port.count, 0);
53794 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53795 info->port.tty = NULL;
53796 spin_unlock_irqrestore(&info->port.lock, flags);
53797 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53798 unsigned short new_crctype;
53799
53800 /* return error if TTY interface open */
53801 - if (info->port.count)
53802 + if (atomic_read(&info->port.count))
53803 return -EBUSY;
53804
53805 switch (encoding)
53806 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53807
53808 /* arbitrate between network and tty opens */
53809 spin_lock_irqsave(&info->netlock, flags);
53810 - if (info->port.count != 0 || info->netcount != 0) {
53811 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53812 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53813 spin_unlock_irqrestore(&info->netlock, flags);
53814 return -EBUSY;
53815 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53816 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53817
53818 /* return error if TTY interface open */
53819 - if (info->port.count)
53820 + if (atomic_read(&info->port.count))
53821 return -EBUSY;
53822
53823 if (cmd != SIOCWANDEV)
53824 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53825 * do not request bottom half processing if the
53826 * device is not open in a normal mode.
53827 */
53828 - if ( port && (port->port.count || port->netcount) &&
53829 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53830 port->pending_bh && !port->bh_running &&
53831 !port->bh_requested ) {
53832 if ( debug_level >= DEBUG_LEVEL_ISR )
53833 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53834
53835 if (debug_level >= DEBUG_LEVEL_INFO)
53836 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53837 - __FILE__,__LINE__, tty->driver->name, port->count );
53838 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53839
53840 spin_lock_irqsave(&info->lock, flags);
53841 - port->count--;
53842 + atomic_dec(&port->count);
53843 spin_unlock_irqrestore(&info->lock, flags);
53844 port->blocked_open++;
53845
53846 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53847
53848 if (debug_level >= DEBUG_LEVEL_INFO)
53849 printk("%s(%d):%s block_til_ready() count=%d\n",
53850 - __FILE__,__LINE__, tty->driver->name, port->count );
53851 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53852
53853 tty_unlock(tty);
53854 schedule();
53855 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53856 set_current_state(TASK_RUNNING);
53857 remove_wait_queue(&port->open_wait, &wait);
53858 if (!tty_hung_up_p(filp))
53859 - port->count++;
53860 + atomic_inc(&port->count);
53861 port->blocked_open--;
53862
53863 if (debug_level >= DEBUG_LEVEL_INFO)
53864 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53865 - __FILE__,__LINE__, tty->driver->name, port->count );
53866 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53867
53868 if (!retval)
53869 port->flags |= ASYNC_NORMAL_ACTIVE;
53870 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53871 index 42bad18..447d7a2 100644
53872 --- a/drivers/tty/sysrq.c
53873 +++ b/drivers/tty/sysrq.c
53874 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53875 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53876 size_t count, loff_t *ppos)
53877 {
53878 - if (count) {
53879 + if (count && capable(CAP_SYS_ADMIN)) {
53880 char c;
53881
53882 if (get_user(c, buf))
53883 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53884 index 848c17a..e930437 100644
53885 --- a/drivers/tty/tty_io.c
53886 +++ b/drivers/tty/tty_io.c
53887 @@ -3469,7 +3469,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53888
53889 void tty_default_fops(struct file_operations *fops)
53890 {
53891 - *fops = tty_fops;
53892 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53893 }
53894
53895 /*
53896 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53897 index 2d822aa..a566234 100644
53898 --- a/drivers/tty/tty_ldisc.c
53899 +++ b/drivers/tty/tty_ldisc.c
53900 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53901 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53902 tty_ldiscs[disc] = new_ldisc;
53903 new_ldisc->num = disc;
53904 - new_ldisc->refcount = 0;
53905 + atomic_set(&new_ldisc->refcount, 0);
53906 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53907
53908 return ret;
53909 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53910 return -EINVAL;
53911
53912 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53913 - if (tty_ldiscs[disc]->refcount)
53914 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53915 ret = -EBUSY;
53916 else
53917 tty_ldiscs[disc] = NULL;
53918 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53919 if (ldops) {
53920 ret = ERR_PTR(-EAGAIN);
53921 if (try_module_get(ldops->owner)) {
53922 - ldops->refcount++;
53923 + atomic_inc(&ldops->refcount);
53924 ret = ldops;
53925 }
53926 }
53927 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53928 unsigned long flags;
53929
53930 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53931 - ldops->refcount--;
53932 + atomic_dec(&ldops->refcount);
53933 module_put(ldops->owner);
53934 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53935 }
53936 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53937 index 1b93357..ea9f82c 100644
53938 --- a/drivers/tty/tty_port.c
53939 +++ b/drivers/tty/tty_port.c
53940 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53941 unsigned long flags;
53942
53943 spin_lock_irqsave(&port->lock, flags);
53944 - port->count = 0;
53945 + atomic_set(&port->count, 0);
53946 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53947 tty = port->tty;
53948 if (tty)
53949 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53950
53951 /* The port lock protects the port counts */
53952 spin_lock_irqsave(&port->lock, flags);
53953 - port->count--;
53954 + atomic_dec(&port->count);
53955 port->blocked_open++;
53956 spin_unlock_irqrestore(&port->lock, flags);
53957
53958 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53959 we must not mess that up further */
53960 spin_lock_irqsave(&port->lock, flags);
53961 if (!tty_hung_up_p(filp))
53962 - port->count++;
53963 + atomic_inc(&port->count);
53964 port->blocked_open--;
53965 if (retval == 0)
53966 port->flags |= ASYNC_NORMAL_ACTIVE;
53967 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53968 return 0;
53969 }
53970
53971 - if (tty->count == 1 && port->count != 1) {
53972 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53973 printk(KERN_WARNING
53974 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53975 - port->count);
53976 - port->count = 1;
53977 + atomic_read(&port->count));
53978 + atomic_set(&port->count, 1);
53979 }
53980 - if (--port->count < 0) {
53981 + if (atomic_dec_return(&port->count) < 0) {
53982 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53983 - port->count);
53984 - port->count = 0;
53985 + atomic_read(&port->count));
53986 + atomic_set(&port->count, 0);
53987 }
53988
53989 - if (port->count) {
53990 + if (atomic_read(&port->count)) {
53991 spin_unlock_irqrestore(&port->lock, flags);
53992 return 0;
53993 }
53994 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53995 struct file *filp)
53996 {
53997 spin_lock_irq(&port->lock);
53998 - ++port->count;
53999 + atomic_inc(&port->count);
54000 spin_unlock_irq(&port->lock);
54001 tty_port_tty_set(port, tty);
54002
54003 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54004 index d0e3a44..5f8b754 100644
54005 --- a/drivers/tty/vt/keyboard.c
54006 +++ b/drivers/tty/vt/keyboard.c
54007 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54008 kbd->kbdmode == VC_OFF) &&
54009 value != KVAL(K_SAK))
54010 return; /* SAK is allowed even in raw mode */
54011 +
54012 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54013 + {
54014 + void *func = fn_handler[value];
54015 + if (func == fn_show_state || func == fn_show_ptregs ||
54016 + func == fn_show_mem)
54017 + return;
54018 + }
54019 +#endif
54020 +
54021 fn_handler[value](vc);
54022 }
54023
54024 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54025 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54026 return -EFAULT;
54027
54028 - if (!capable(CAP_SYS_TTY_CONFIG))
54029 - perm = 0;
54030 -
54031 switch (cmd) {
54032 case KDGKBENT:
54033 /* Ensure another thread doesn't free it under us */
54034 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54035 spin_unlock_irqrestore(&kbd_event_lock, flags);
54036 return put_user(val, &user_kbe->kb_value);
54037 case KDSKBENT:
54038 + if (!capable(CAP_SYS_TTY_CONFIG))
54039 + perm = 0;
54040 +
54041 if (!perm)
54042 return -EPERM;
54043 if (!i && v == K_NOSUCHMAP) {
54044 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54045 int i, j, k;
54046 int ret;
54047
54048 - if (!capable(CAP_SYS_TTY_CONFIG))
54049 - perm = 0;
54050 -
54051 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54052 if (!kbs) {
54053 ret = -ENOMEM;
54054 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54055 kfree(kbs);
54056 return ((p && *p) ? -EOVERFLOW : 0);
54057 case KDSKBSENT:
54058 + if (!capable(CAP_SYS_TTY_CONFIG))
54059 + perm = 0;
54060 +
54061 if (!perm) {
54062 ret = -EPERM;
54063 goto reterr;
54064 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54065 index a673e5b..36e5d32 100644
54066 --- a/drivers/uio/uio.c
54067 +++ b/drivers/uio/uio.c
54068 @@ -25,6 +25,7 @@
54069 #include <linux/kobject.h>
54070 #include <linux/cdev.h>
54071 #include <linux/uio_driver.h>
54072 +#include <asm/local.h>
54073
54074 #define UIO_MAX_DEVICES (1U << MINORBITS)
54075
54076 @@ -32,7 +33,7 @@ struct uio_device {
54077 struct module *owner;
54078 struct device *dev;
54079 int minor;
54080 - atomic_t event;
54081 + atomic_unchecked_t event;
54082 struct fasync_struct *async_queue;
54083 wait_queue_head_t wait;
54084 struct uio_info *info;
54085 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54086 struct device_attribute *attr, char *buf)
54087 {
54088 struct uio_device *idev = dev_get_drvdata(dev);
54089 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54090 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54091 }
54092 static DEVICE_ATTR_RO(event);
54093
54094 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54095 {
54096 struct uio_device *idev = info->uio_dev;
54097
54098 - atomic_inc(&idev->event);
54099 + atomic_inc_unchecked(&idev->event);
54100 wake_up_interruptible(&idev->wait);
54101 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54102 }
54103 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54104 }
54105
54106 listener->dev = idev;
54107 - listener->event_count = atomic_read(&idev->event);
54108 + listener->event_count = atomic_read_unchecked(&idev->event);
54109 filep->private_data = listener;
54110
54111 if (idev->info->open) {
54112 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54113 return -EIO;
54114
54115 poll_wait(filep, &idev->wait, wait);
54116 - if (listener->event_count != atomic_read(&idev->event))
54117 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54118 return POLLIN | POLLRDNORM;
54119 return 0;
54120 }
54121 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54122 do {
54123 set_current_state(TASK_INTERRUPTIBLE);
54124
54125 - event_count = atomic_read(&idev->event);
54126 + event_count = atomic_read_unchecked(&idev->event);
54127 if (event_count != listener->event_count) {
54128 if (copy_to_user(buf, &event_count, count))
54129 retval = -EFAULT;
54130 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54131 static int uio_find_mem_index(struct vm_area_struct *vma)
54132 {
54133 struct uio_device *idev = vma->vm_private_data;
54134 + unsigned long size;
54135
54136 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54137 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54138 + size = idev->info->mem[vma->vm_pgoff].size;
54139 + if (size == 0)
54140 + return -1;
54141 + if (vma->vm_end - vma->vm_start > size)
54142 return -1;
54143 return (int)vma->vm_pgoff;
54144 }
54145 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54146 idev->owner = owner;
54147 idev->info = info;
54148 init_waitqueue_head(&idev->wait);
54149 - atomic_set(&idev->event, 0);
54150 + atomic_set_unchecked(&idev->event, 0);
54151
54152 ret = uio_get_minor(idev);
54153 if (ret)
54154 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54155 index 813d4d3..a71934f 100644
54156 --- a/drivers/usb/atm/cxacru.c
54157 +++ b/drivers/usb/atm/cxacru.c
54158 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54159 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54160 if (ret < 2)
54161 return -EINVAL;
54162 - if (index < 0 || index > 0x7f)
54163 + if (index > 0x7f)
54164 return -EINVAL;
54165 pos += tmp;
54166
54167 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54168 index dada014..1d0d517 100644
54169 --- a/drivers/usb/atm/usbatm.c
54170 +++ b/drivers/usb/atm/usbatm.c
54171 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54172 if (printk_ratelimit())
54173 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54174 __func__, vpi, vci);
54175 - atomic_inc(&vcc->stats->rx_err);
54176 + atomic_inc_unchecked(&vcc->stats->rx_err);
54177 return;
54178 }
54179
54180 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54181 if (length > ATM_MAX_AAL5_PDU) {
54182 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54183 __func__, length, vcc);
54184 - atomic_inc(&vcc->stats->rx_err);
54185 + atomic_inc_unchecked(&vcc->stats->rx_err);
54186 goto out;
54187 }
54188
54189 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54190 if (sarb->len < pdu_length) {
54191 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54192 __func__, pdu_length, sarb->len, vcc);
54193 - atomic_inc(&vcc->stats->rx_err);
54194 + atomic_inc_unchecked(&vcc->stats->rx_err);
54195 goto out;
54196 }
54197
54198 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54199 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54200 __func__, vcc);
54201 - atomic_inc(&vcc->stats->rx_err);
54202 + atomic_inc_unchecked(&vcc->stats->rx_err);
54203 goto out;
54204 }
54205
54206 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54207 if (printk_ratelimit())
54208 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54209 __func__, length);
54210 - atomic_inc(&vcc->stats->rx_drop);
54211 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54212 goto out;
54213 }
54214
54215 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54216
54217 vcc->push(vcc, skb);
54218
54219 - atomic_inc(&vcc->stats->rx);
54220 + atomic_inc_unchecked(&vcc->stats->rx);
54221 out:
54222 skb_trim(sarb, 0);
54223 }
54224 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54225 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54226
54227 usbatm_pop(vcc, skb);
54228 - atomic_inc(&vcc->stats->tx);
54229 + atomic_inc_unchecked(&vcc->stats->tx);
54230
54231 skb = skb_dequeue(&instance->sndqueue);
54232 }
54233 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54234 if (!left--)
54235 return sprintf(page,
54236 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54237 - atomic_read(&atm_dev->stats.aal5.tx),
54238 - atomic_read(&atm_dev->stats.aal5.tx_err),
54239 - atomic_read(&atm_dev->stats.aal5.rx),
54240 - atomic_read(&atm_dev->stats.aal5.rx_err),
54241 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54242 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54243 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54244 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54245 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54246 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54247
54248 if (!left--) {
54249 if (instance->disconnected)
54250 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54251 index 2a3bbdf..91d72cf 100644
54252 --- a/drivers/usb/core/devices.c
54253 +++ b/drivers/usb/core/devices.c
54254 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54255 * time it gets called.
54256 */
54257 static struct device_connect_event {
54258 - atomic_t count;
54259 + atomic_unchecked_t count;
54260 wait_queue_head_t wait;
54261 } device_event = {
54262 .count = ATOMIC_INIT(1),
54263 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54264
54265 void usbfs_conn_disc_event(void)
54266 {
54267 - atomic_add(2, &device_event.count);
54268 + atomic_add_unchecked(2, &device_event.count);
54269 wake_up(&device_event.wait);
54270 }
54271
54272 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54273
54274 poll_wait(file, &device_event.wait, wait);
54275
54276 - event_count = atomic_read(&device_event.count);
54277 + event_count = atomic_read_unchecked(&device_event.count);
54278 if (file->f_version != event_count) {
54279 file->f_version = event_count;
54280 return POLLIN | POLLRDNORM;
54281 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54282 index 0b59731..46ee7d1 100644
54283 --- a/drivers/usb/core/devio.c
54284 +++ b/drivers/usb/core/devio.c
54285 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54286 struct usb_dev_state *ps = file->private_data;
54287 struct usb_device *dev = ps->dev;
54288 ssize_t ret = 0;
54289 - unsigned len;
54290 + size_t len;
54291 loff_t pos;
54292 int i;
54293
54294 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54295 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54296 struct usb_config_descriptor *config =
54297 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54298 - unsigned int length = le16_to_cpu(config->wTotalLength);
54299 + size_t length = le16_to_cpu(config->wTotalLength);
54300
54301 if (*ppos < pos + length) {
54302
54303 /* The descriptor may claim to be longer than it
54304 * really is. Here is the actual allocated length. */
54305 - unsigned alloclen =
54306 + size_t alloclen =
54307 le16_to_cpu(dev->config[i].desc.wTotalLength);
54308
54309 - len = length - (*ppos - pos);
54310 + len = length + pos - *ppos;
54311 if (len > nbytes)
54312 len = nbytes;
54313
54314 /* Simply don't write (skip over) unallocated parts */
54315 if (alloclen > (*ppos - pos)) {
54316 - alloclen -= (*ppos - pos);
54317 + alloclen = alloclen + pos - *ppos;
54318 if (copy_to_user(buf,
54319 dev->rawdescriptors[i] + (*ppos - pos),
54320 min(len, alloclen))) {
54321 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54322 index 258e6fe..9ea48d7 100644
54323 --- a/drivers/usb/core/hcd.c
54324 +++ b/drivers/usb/core/hcd.c
54325 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54326 */
54327 usb_get_urb(urb);
54328 atomic_inc(&urb->use_count);
54329 - atomic_inc(&urb->dev->urbnum);
54330 + atomic_inc_unchecked(&urb->dev->urbnum);
54331 usbmon_urb_submit(&hcd->self, urb);
54332
54333 /* NOTE requirements on root-hub callers (usbfs and the hub
54334 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54335 urb->hcpriv = NULL;
54336 INIT_LIST_HEAD(&urb->urb_list);
54337 atomic_dec(&urb->use_count);
54338 - atomic_dec(&urb->dev->urbnum);
54339 + atomic_dec_unchecked(&urb->dev->urbnum);
54340 if (atomic_read(&urb->reject))
54341 wake_up(&usb_kill_urb_queue);
54342 usb_put_urb(urb);
54343 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54344 index 674c262..71fdd90 100644
54345 --- a/drivers/usb/core/hub.c
54346 +++ b/drivers/usb/core/hub.c
54347 @@ -27,6 +27,7 @@
54348 #include <linux/freezer.h>
54349 #include <linux/random.h>
54350 #include <linux/pm_qos.h>
54351 +#include <linux/grsecurity.h>
54352
54353 #include <asm/uaccess.h>
54354 #include <asm/byteorder.h>
54355 @@ -4665,6 +4666,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54356 goto done;
54357 return;
54358 }
54359 +
54360 + if (gr_handle_new_usb())
54361 + goto done;
54362 +
54363 if (hub_is_superspeed(hub->hdev))
54364 unit_load = 150;
54365 else
54366 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54367 index 0c8a7fc..c45b40a 100644
54368 --- a/drivers/usb/core/message.c
54369 +++ b/drivers/usb/core/message.c
54370 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54371 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54372 * error number.
54373 */
54374 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54375 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54376 __u8 requesttype, __u16 value, __u16 index, void *data,
54377 __u16 size, int timeout)
54378 {
54379 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54380 * If successful, 0. Otherwise a negative error number. The number of actual
54381 * bytes transferred will be stored in the @actual_length parameter.
54382 */
54383 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54384 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54385 void *data, int len, int *actual_length, int timeout)
54386 {
54387 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54388 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54389 * bytes transferred will be stored in the @actual_length parameter.
54390 *
54391 */
54392 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54393 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54394 void *data, int len, int *actual_length, int timeout)
54395 {
54396 struct urb *urb;
54397 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54398 index 1236c60..d47a51c 100644
54399 --- a/drivers/usb/core/sysfs.c
54400 +++ b/drivers/usb/core/sysfs.c
54401 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54402 struct usb_device *udev;
54403
54404 udev = to_usb_device(dev);
54405 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54406 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54407 }
54408 static DEVICE_ATTR_RO(urbnum);
54409
54410 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54411 index 2dd2362..1135437 100644
54412 --- a/drivers/usb/core/usb.c
54413 +++ b/drivers/usb/core/usb.c
54414 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54415 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54416 dev->state = USB_STATE_ATTACHED;
54417 dev->lpm_disable_count = 1;
54418 - atomic_set(&dev->urbnum, 0);
54419 + atomic_set_unchecked(&dev->urbnum, 0);
54420
54421 INIT_LIST_HEAD(&dev->ep0.urb_list);
54422 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54423 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54424 index 8cfc319..4868255 100644
54425 --- a/drivers/usb/early/ehci-dbgp.c
54426 +++ b/drivers/usb/early/ehci-dbgp.c
54427 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54428
54429 #ifdef CONFIG_KGDB
54430 static struct kgdb_io kgdbdbgp_io_ops;
54431 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54432 +static struct kgdb_io kgdbdbgp_io_ops_console;
54433 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54434 #else
54435 #define dbgp_kgdb_mode (0)
54436 #endif
54437 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54438 .write_char = kgdbdbgp_write_char,
54439 };
54440
54441 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54442 + .name = "kgdbdbgp",
54443 + .read_char = kgdbdbgp_read_char,
54444 + .write_char = kgdbdbgp_write_char,
54445 + .is_console = 1
54446 +};
54447 +
54448 static int kgdbdbgp_wait_time;
54449
54450 static int __init kgdbdbgp_parse_config(char *str)
54451 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54452 ptr++;
54453 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54454 }
54455 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54456 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54457 + if (early_dbgp_console.index != -1)
54458 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54459 + else
54460 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54461
54462 return 0;
54463 }
54464 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54465 index 2b4c82d..06a8ee6 100644
54466 --- a/drivers/usb/gadget/function/f_uac1.c
54467 +++ b/drivers/usb/gadget/function/f_uac1.c
54468 @@ -13,6 +13,7 @@
54469 #include <linux/kernel.h>
54470 #include <linux/device.h>
54471 #include <linux/atomic.h>
54472 +#include <linux/module.h>
54473
54474 #include "u_uac1.h"
54475
54476 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54477 index ad0aca8..8ff84865 100644
54478 --- a/drivers/usb/gadget/function/u_serial.c
54479 +++ b/drivers/usb/gadget/function/u_serial.c
54480 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54481 spin_lock_irq(&port->port_lock);
54482
54483 /* already open? Great. */
54484 - if (port->port.count) {
54485 + if (atomic_read(&port->port.count)) {
54486 status = 0;
54487 - port->port.count++;
54488 + atomic_inc(&port->port.count);
54489
54490 /* currently opening/closing? wait ... */
54491 } else if (port->openclose) {
54492 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54493 tty->driver_data = port;
54494 port->port.tty = tty;
54495
54496 - port->port.count = 1;
54497 + atomic_set(&port->port.count, 1);
54498 port->openclose = false;
54499
54500 /* if connected, start the I/O stream */
54501 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54502
54503 spin_lock_irq(&port->port_lock);
54504
54505 - if (port->port.count != 1) {
54506 - if (port->port.count == 0)
54507 + if (atomic_read(&port->port.count) != 1) {
54508 + if (atomic_read(&port->port.count) == 0)
54509 WARN_ON(1);
54510 else
54511 - --port->port.count;
54512 + atomic_dec(&port->port.count);
54513 goto exit;
54514 }
54515
54516 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54517 * and sleep if necessary
54518 */
54519 port->openclose = true;
54520 - port->port.count = 0;
54521 + atomic_set(&port->port.count, 0);
54522
54523 gser = port->port_usb;
54524 if (gser && gser->disconnect)
54525 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
54526 int cond;
54527
54528 spin_lock_irq(&port->port_lock);
54529 - cond = (port->port.count == 0) && !port->openclose;
54530 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54531 spin_unlock_irq(&port->port_lock);
54532 return cond;
54533 }
54534 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54535 /* if it's already open, start I/O ... and notify the serial
54536 * protocol about open/close status (connect/disconnect).
54537 */
54538 - if (port->port.count) {
54539 + if (atomic_read(&port->port.count)) {
54540 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54541 gs_start_io(port);
54542 if (gser->connect)
54543 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
54544
54545 port->port_usb = NULL;
54546 gser->ioport = NULL;
54547 - if (port->port.count > 0 || port->openclose) {
54548 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54549 wake_up_interruptible(&port->drain_wait);
54550 if (port->port.tty)
54551 tty_hangup(port->port.tty);
54552 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
54553
54554 /* finally, free any unused/unusable I/O buffers */
54555 spin_lock_irqsave(&port->port_lock, flags);
54556 - if (port->port.count == 0 && !port->openclose)
54557 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54558 gs_buf_free(&port->port_write_buf);
54559 gs_free_requests(gser->out, &port->read_pool, NULL);
54560 gs_free_requests(gser->out, &port->read_queue, NULL);
54561 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54562 index 7a55fea..cc0ed4f 100644
54563 --- a/drivers/usb/gadget/function/u_uac1.c
54564 +++ b/drivers/usb/gadget/function/u_uac1.c
54565 @@ -16,6 +16,7 @@
54566 #include <linux/ctype.h>
54567 #include <linux/random.h>
54568 #include <linux/syscalls.h>
54569 +#include <linux/module.h>
54570
54571 #include "u_uac1.h"
54572
54573 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54574 index 6130b75..3b60008 100644
54575 --- a/drivers/usb/host/ehci-hub.c
54576 +++ b/drivers/usb/host/ehci-hub.c
54577 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54578 urb->transfer_flags = URB_DIR_IN;
54579 usb_get_urb(urb);
54580 atomic_inc(&urb->use_count);
54581 - atomic_inc(&urb->dev->urbnum);
54582 + atomic_inc_unchecked(&urb->dev->urbnum);
54583 urb->setup_dma = dma_map_single(
54584 hcd->self.controller,
54585 urb->setup_packet,
54586 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54587 urb->status = -EINPROGRESS;
54588 usb_get_urb(urb);
54589 atomic_inc(&urb->use_count);
54590 - atomic_inc(&urb->dev->urbnum);
54591 + atomic_inc_unchecked(&urb->dev->urbnum);
54592 retval = submit_single_step_set_feature(hcd, urb, 0);
54593 if (!retval && !wait_for_completion_timeout(&done,
54594 msecs_to_jiffies(2000))) {
54595 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54596 index d0d8fad..668ef7b 100644
54597 --- a/drivers/usb/host/hwa-hc.c
54598 +++ b/drivers/usb/host/hwa-hc.c
54599 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54600 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54601 struct wahc *wa = &hwahc->wa;
54602 struct device *dev = &wa->usb_iface->dev;
54603 - u8 mas_le[UWB_NUM_MAS/8];
54604 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54605 +
54606 + if (mas_le == NULL)
54607 + return -ENOMEM;
54608
54609 /* Set the stream index */
54610 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54611 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54612 WUSB_REQ_SET_WUSB_MAS,
54613 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54614 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54615 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54616 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54617 if (result < 0)
54618 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54619 out:
54620 + kfree(mas_le);
54621 +
54622 return result;
54623 }
54624
54625 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54626 index b3d245e..99549ed 100644
54627 --- a/drivers/usb/misc/appledisplay.c
54628 +++ b/drivers/usb/misc/appledisplay.c
54629 @@ -84,7 +84,7 @@ struct appledisplay {
54630 struct mutex sysfslock; /* concurrent read and write */
54631 };
54632
54633 -static atomic_t count_displays = ATOMIC_INIT(0);
54634 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54635 static struct workqueue_struct *wq;
54636
54637 static void appledisplay_complete(struct urb *urb)
54638 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54639
54640 /* Register backlight device */
54641 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54642 - atomic_inc_return(&count_displays) - 1);
54643 + atomic_inc_return_unchecked(&count_displays) - 1);
54644 memset(&props, 0, sizeof(struct backlight_properties));
54645 props.type = BACKLIGHT_RAW;
54646 props.max_brightness = 0xff;
54647 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54648 index 8d7fc48..01c4986 100644
54649 --- a/drivers/usb/serial/console.c
54650 +++ b/drivers/usb/serial/console.c
54651 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54652
54653 info->port = port;
54654
54655 - ++port->port.count;
54656 + atomic_inc(&port->port.count);
54657 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54658 if (serial->type->set_termios) {
54659 /*
54660 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54661 }
54662 /* Now that any required fake tty operations are completed restore
54663 * the tty port count */
54664 - --port->port.count;
54665 + atomic_dec(&port->port.count);
54666 /* The console is special in terms of closing the device so
54667 * indicate this port is now acting as a system console. */
54668 port->port.console = 1;
54669 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54670 free_tty:
54671 kfree(tty);
54672 reset_open_count:
54673 - port->port.count = 0;
54674 + atomic_set(&port->port.count, 0);
54675 usb_autopm_put_interface(serial->interface);
54676 error_get_interface:
54677 usb_serial_put(serial);
54678 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54679 static void usb_console_write(struct console *co,
54680 const char *buf, unsigned count)
54681 {
54682 - static struct usbcons_info *info = &usbcons_info;
54683 + struct usbcons_info *info = &usbcons_info;
54684 struct usb_serial_port *port = info->port;
54685 struct usb_serial *serial;
54686 int retval = -ENODEV;
54687 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54688 index 307e339..6aa97cb 100644
54689 --- a/drivers/usb/storage/usb.h
54690 +++ b/drivers/usb/storage/usb.h
54691 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54692 __u8 useProtocol;
54693 __u8 useTransport;
54694 int (*initFunction)(struct us_data *);
54695 -};
54696 +} __do_const;
54697
54698
54699 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54700 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54701 index a863a98..d272795 100644
54702 --- a/drivers/usb/usbip/vhci.h
54703 +++ b/drivers/usb/usbip/vhci.h
54704 @@ -83,7 +83,7 @@ struct vhci_hcd {
54705 unsigned resuming:1;
54706 unsigned long re_timeout;
54707
54708 - atomic_t seqnum;
54709 + atomic_unchecked_t seqnum;
54710
54711 /*
54712 * NOTE:
54713 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54714 index c02374b..32d47a9 100644
54715 --- a/drivers/usb/usbip/vhci_hcd.c
54716 +++ b/drivers/usb/usbip/vhci_hcd.c
54717 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54718
54719 spin_lock(&vdev->priv_lock);
54720
54721 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54722 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54723 if (priv->seqnum == 0xffff)
54724 dev_info(&urb->dev->dev, "seqnum max\n");
54725
54726 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54727 return -ENOMEM;
54728 }
54729
54730 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54731 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54732 if (unlink->seqnum == 0xffff)
54733 pr_info("seqnum max\n");
54734
54735 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54736 vdev->rhport = rhport;
54737 }
54738
54739 - atomic_set(&vhci->seqnum, 0);
54740 + atomic_set_unchecked(&vhci->seqnum, 0);
54741 spin_lock_init(&vhci->lock);
54742
54743 hcd->power_budget = 0; /* no limit */
54744 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54745 index 00e4a54..d676f85 100644
54746 --- a/drivers/usb/usbip/vhci_rx.c
54747 +++ b/drivers/usb/usbip/vhci_rx.c
54748 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54749 if (!urb) {
54750 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54751 pr_info("max seqnum %d\n",
54752 - atomic_read(&the_controller->seqnum));
54753 + atomic_read_unchecked(&the_controller->seqnum));
54754 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54755 return;
54756 }
54757 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54758 index f2a8d29..7bc3fe7 100644
54759 --- a/drivers/usb/wusbcore/wa-hc.h
54760 +++ b/drivers/usb/wusbcore/wa-hc.h
54761 @@ -240,7 +240,7 @@ struct wahc {
54762 spinlock_t xfer_list_lock;
54763 struct work_struct xfer_enqueue_work;
54764 struct work_struct xfer_error_work;
54765 - atomic_t xfer_id_count;
54766 + atomic_unchecked_t xfer_id_count;
54767
54768 kernel_ulong_t quirks;
54769 };
54770 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54771 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54772 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54773 wa->dto_in_use = 0;
54774 - atomic_set(&wa->xfer_id_count, 1);
54775 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54776 /* init the buf in URBs */
54777 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54778 usb_init_urb(&(wa->buf_in_urbs[index]));
54779 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54780 index e279015..c2d0dae 100644
54781 --- a/drivers/usb/wusbcore/wa-xfer.c
54782 +++ b/drivers/usb/wusbcore/wa-xfer.c
54783 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54784 */
54785 static void wa_xfer_id_init(struct wa_xfer *xfer)
54786 {
54787 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54788 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54789 }
54790
54791 /* Return the xfer's ID. */
54792 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54793 index f018d8d..ccab63f 100644
54794 --- a/drivers/vfio/vfio.c
54795 +++ b/drivers/vfio/vfio.c
54796 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54797 return 0;
54798
54799 /* TODO Prevent device auto probing */
54800 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54801 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54802 iommu_group_id(group->iommu_group));
54803
54804 return 0;
54805 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54806 index 5174eba..451e6bc 100644
54807 --- a/drivers/vhost/vringh.c
54808 +++ b/drivers/vhost/vringh.c
54809 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54810 /* Userspace access helpers: in this case, addresses are really userspace. */
54811 static inline int getu16_user(u16 *val, const u16 *p)
54812 {
54813 - return get_user(*val, (__force u16 __user *)p);
54814 + return get_user(*val, (u16 __force_user *)p);
54815 }
54816
54817 static inline int putu16_user(u16 *p, u16 val)
54818 {
54819 - return put_user(val, (__force u16 __user *)p);
54820 + return put_user(val, (u16 __force_user *)p);
54821 }
54822
54823 static inline int copydesc_user(void *dst, const void *src, size_t len)
54824 {
54825 - return copy_from_user(dst, (__force void __user *)src, len) ?
54826 + return copy_from_user(dst, (void __force_user *)src, len) ?
54827 -EFAULT : 0;
54828 }
54829
54830 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54831 const struct vring_used_elem *src,
54832 unsigned int num)
54833 {
54834 - return copy_to_user((__force void __user *)dst, src,
54835 + return copy_to_user((void __force_user *)dst, src,
54836 sizeof(*dst) * num) ? -EFAULT : 0;
54837 }
54838
54839 static inline int xfer_from_user(void *src, void *dst, size_t len)
54840 {
54841 - return copy_from_user(dst, (__force void __user *)src, len) ?
54842 + return copy_from_user(dst, (void __force_user *)src, len) ?
54843 -EFAULT : 0;
54844 }
54845
54846 static inline int xfer_to_user(void *dst, void *src, size_t len)
54847 {
54848 - return copy_to_user((__force void __user *)dst, src, len) ?
54849 + return copy_to_user((void __force_user *)dst, src, len) ?
54850 -EFAULT : 0;
54851 }
54852
54853 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54854 vrh->last_used_idx = 0;
54855 vrh->vring.num = num;
54856 /* vring expects kernel addresses, but only used via accessors. */
54857 - vrh->vring.desc = (__force struct vring_desc *)desc;
54858 - vrh->vring.avail = (__force struct vring_avail *)avail;
54859 - vrh->vring.used = (__force struct vring_used *)used;
54860 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54861 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54862 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54863 return 0;
54864 }
54865 EXPORT_SYMBOL(vringh_init_user);
54866 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54867
54868 static inline int putu16_kern(u16 *p, u16 val)
54869 {
54870 - ACCESS_ONCE(*p) = val;
54871 + ACCESS_ONCE_RW(*p) = val;
54872 return 0;
54873 }
54874
54875 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54876 index 84a110a..96312c3 100644
54877 --- a/drivers/video/backlight/kb3886_bl.c
54878 +++ b/drivers/video/backlight/kb3886_bl.c
54879 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54880 static unsigned long kb3886bl_flags;
54881 #define KB3886BL_SUSPENDED 0x01
54882
54883 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54884 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54885 {
54886 .ident = "Sahara Touch-iT",
54887 .matches = {
54888 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54889 index 1b0b233..6f34c2c 100644
54890 --- a/drivers/video/fbdev/arcfb.c
54891 +++ b/drivers/video/fbdev/arcfb.c
54892 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54893 return -ENOSPC;
54894
54895 err = 0;
54896 - if ((count + p) > fbmemlength) {
54897 + if (count > (fbmemlength - p)) {
54898 count = fbmemlength - p;
54899 err = -ENOSPC;
54900 }
54901 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54902 index ff60701..814b973 100644
54903 --- a/drivers/video/fbdev/aty/aty128fb.c
54904 +++ b/drivers/video/fbdev/aty/aty128fb.c
54905 @@ -149,7 +149,7 @@ enum {
54906 };
54907
54908 /* Must match above enum */
54909 -static char * const r128_family[] = {
54910 +static const char * const r128_family[] = {
54911 "AGP",
54912 "PCI",
54913 "PRO AGP",
54914 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54915 index 37ec09b..98f8862 100644
54916 --- a/drivers/video/fbdev/aty/atyfb_base.c
54917 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54918 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54919 par->accel_flags = var->accel_flags; /* hack */
54920
54921 if (var->accel_flags) {
54922 - info->fbops->fb_sync = atyfb_sync;
54923 + pax_open_kernel();
54924 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54925 + pax_close_kernel();
54926 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54927 } else {
54928 - info->fbops->fb_sync = NULL;
54929 + pax_open_kernel();
54930 + *(void **)&info->fbops->fb_sync = NULL;
54931 + pax_close_kernel();
54932 info->flags |= FBINFO_HWACCEL_DISABLED;
54933 }
54934
54935 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54936 index 2fa0317..4983f2a 100644
54937 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54938 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54939 @@ -8,6 +8,7 @@
54940 #include "../core/fb_draw.h"
54941
54942 #include <asm/io.h>
54943 +#include <asm/pgtable.h>
54944
54945 #ifdef __sparc__
54946 #include <asm/fbio.h>
54947 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54948 info->sprite.buf_align = 16; /* and 64 lines tall. */
54949 info->sprite.flags = FB_PIXMAP_IO;
54950
54951 - info->fbops->fb_cursor = atyfb_cursor;
54952 + pax_open_kernel();
54953 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54954 + pax_close_kernel();
54955
54956 return 0;
54957 }
54958 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54959 index 900aa4e..6d49418 100644
54960 --- a/drivers/video/fbdev/core/fb_defio.c
54961 +++ b/drivers/video/fbdev/core/fb_defio.c
54962 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
54963
54964 BUG_ON(!fbdefio);
54965 mutex_init(&fbdefio->lock);
54966 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54967 + pax_open_kernel();
54968 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54969 + pax_close_kernel();
54970 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54971 INIT_LIST_HEAD(&fbdefio->pagelist);
54972 if (fbdefio->delay == 0) /* set a default of 1 s */
54973 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54974 page->mapping = NULL;
54975 }
54976
54977 - info->fbops->fb_mmap = NULL;
54978 + *(void **)&info->fbops->fb_mmap = NULL;
54979 mutex_destroy(&fbdefio->lock);
54980 }
54981 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54982 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54983 index b5e85f6..290f8c7 100644
54984 --- a/drivers/video/fbdev/core/fbmem.c
54985 +++ b/drivers/video/fbdev/core/fbmem.c
54986 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54987 __u32 data;
54988 int err;
54989
54990 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54991 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54992
54993 data = (__u32) (unsigned long) fix->smem_start;
54994 err |= put_user(data, &fix32->smem_start);
54995 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54996 index 4254336..282567e 100644
54997 --- a/drivers/video/fbdev/hyperv_fb.c
54998 +++ b/drivers/video/fbdev/hyperv_fb.c
54999 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55000 static inline int synthvid_send(struct hv_device *hdev,
55001 struct synthvid_msg *msg)
55002 {
55003 - static atomic64_t request_id = ATOMIC64_INIT(0);
55004 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55005 int ret;
55006
55007 msg->pipe_hdr.type = PIPE_MSG_DATA;
55008 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55009
55010 ret = vmbus_sendpacket(hdev->channel, msg,
55011 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55012 - atomic64_inc_return(&request_id),
55013 + atomic64_inc_return_unchecked(&request_id),
55014 VM_PKT_DATA_INBAND, 0);
55015
55016 if (ret)
55017 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55018 index 7672d2e..b56437f 100644
55019 --- a/drivers/video/fbdev/i810/i810_accel.c
55020 +++ b/drivers/video/fbdev/i810/i810_accel.c
55021 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55022 }
55023 }
55024 printk("ringbuffer lockup!!!\n");
55025 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55026 i810_report_error(mmio);
55027 par->dev_flags |= LOCKUP;
55028 info->pixmap.scan_align = 1;
55029 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55030 index a01147f..5d896f8 100644
55031 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55032 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55033 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55034
55035 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55036 struct matrox_switch matrox_mystique = {
55037 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55038 + .preinit = MGA1064_preinit,
55039 + .reset = MGA1064_reset,
55040 + .init = MGA1064_init,
55041 + .restore = MGA1064_restore,
55042 };
55043 EXPORT_SYMBOL(matrox_mystique);
55044 #endif
55045
55046 #ifdef CONFIG_FB_MATROX_G
55047 struct matrox_switch matrox_G100 = {
55048 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55049 + .preinit = MGAG100_preinit,
55050 + .reset = MGAG100_reset,
55051 + .init = MGAG100_init,
55052 + .restore = MGAG100_restore,
55053 };
55054 EXPORT_SYMBOL(matrox_G100);
55055 #endif
55056 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55057 index 195ad7c..09743fc 100644
55058 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55059 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55060 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55061 }
55062
55063 struct matrox_switch matrox_millennium = {
55064 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55065 + .preinit = Ti3026_preinit,
55066 + .reset = Ti3026_reset,
55067 + .init = Ti3026_init,
55068 + .restore = Ti3026_restore
55069 };
55070 EXPORT_SYMBOL(matrox_millennium);
55071 #endif
55072 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55073 index fe92eed..106e085 100644
55074 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55075 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55076 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55077 struct mb862xxfb_par *par = info->par;
55078
55079 if (info->var.bits_per_pixel == 32) {
55080 - info->fbops->fb_fillrect = cfb_fillrect;
55081 - info->fbops->fb_copyarea = cfb_copyarea;
55082 - info->fbops->fb_imageblit = cfb_imageblit;
55083 + pax_open_kernel();
55084 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55085 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55086 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55087 + pax_close_kernel();
55088 } else {
55089 outreg(disp, GC_L0EM, 3);
55090 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55091 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55092 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55093 + pax_open_kernel();
55094 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55095 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55096 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55097 + pax_close_kernel();
55098 }
55099 outreg(draw, GDC_REG_DRAW_BASE, 0);
55100 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55101 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55102 index def0412..fed6529 100644
55103 --- a/drivers/video/fbdev/nvidia/nvidia.c
55104 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55105 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55106 info->fix.line_length = (info->var.xres_virtual *
55107 info->var.bits_per_pixel) >> 3;
55108 if (info->var.accel_flags) {
55109 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55110 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55111 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55112 - info->fbops->fb_sync = nvidiafb_sync;
55113 + pax_open_kernel();
55114 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55115 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55116 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55117 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55118 + pax_close_kernel();
55119 info->pixmap.scan_align = 4;
55120 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55121 info->flags |= FBINFO_READS_FAST;
55122 NVResetGraphics(info);
55123 } else {
55124 - info->fbops->fb_imageblit = cfb_imageblit;
55125 - info->fbops->fb_fillrect = cfb_fillrect;
55126 - info->fbops->fb_copyarea = cfb_copyarea;
55127 - info->fbops->fb_sync = NULL;
55128 + pax_open_kernel();
55129 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55130 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55131 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55132 + *(void **)&info->fbops->fb_sync = NULL;
55133 + pax_close_kernel();
55134 info->pixmap.scan_align = 1;
55135 info->flags |= FBINFO_HWACCEL_DISABLED;
55136 info->flags &= ~FBINFO_READS_FAST;
55137 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55138 info->pixmap.size = 8 * 1024;
55139 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55140
55141 - if (!hwcur)
55142 - info->fbops->fb_cursor = NULL;
55143 + if (!hwcur) {
55144 + pax_open_kernel();
55145 + *(void **)&info->fbops->fb_cursor = NULL;
55146 + pax_close_kernel();
55147 + }
55148
55149 info->var.accel_flags = (!noaccel);
55150
55151 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55152 index 2412a0d..294215b 100644
55153 --- a/drivers/video/fbdev/omap2/dss/display.c
55154 +++ b/drivers/video/fbdev/omap2/dss/display.c
55155 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55156 if (dssdev->name == NULL)
55157 dssdev->name = dssdev->alias;
55158
55159 + pax_open_kernel();
55160 if (drv && drv->get_resolution == NULL)
55161 - drv->get_resolution = omapdss_default_get_resolution;
55162 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55163 if (drv && drv->get_recommended_bpp == NULL)
55164 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55165 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55166 if (drv && drv->get_timings == NULL)
55167 - drv->get_timings = omapdss_default_get_timings;
55168 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55169 + pax_close_kernel();
55170
55171 mutex_lock(&panel_list_mutex);
55172 list_add_tail(&dssdev->panel_list, &panel_list);
55173 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55174 index 83433cb..71e9b98 100644
55175 --- a/drivers/video/fbdev/s1d13xxxfb.c
55176 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55177 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55178
55179 switch(prod_id) {
55180 case S1D13506_PROD_ID: /* activate acceleration */
55181 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55182 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55183 + pax_open_kernel();
55184 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55185 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55186 + pax_close_kernel();
55187 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55188 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55189 break;
55190 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55191 index 2bcc84a..29dd1ea 100644
55192 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55193 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55194 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55195 }
55196
55197 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55198 - lcdc_sys_write_index,
55199 - lcdc_sys_write_data,
55200 - lcdc_sys_read_data,
55201 + .write_index = lcdc_sys_write_index,
55202 + .write_data = lcdc_sys_write_data,
55203 + .read_data = lcdc_sys_read_data,
55204 };
55205
55206 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55207 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55208 index d513ed6..90b0de9 100644
55209 --- a/drivers/video/fbdev/smscufx.c
55210 +++ b/drivers/video/fbdev/smscufx.c
55211 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55212 fb_deferred_io_cleanup(info);
55213 kfree(info->fbdefio);
55214 info->fbdefio = NULL;
55215 - info->fbops->fb_mmap = ufx_ops_mmap;
55216 + pax_open_kernel();
55217 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55218 + pax_close_kernel();
55219 }
55220
55221 pr_debug("released /dev/fb%d user=%d count=%d",
55222 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55223 index 77b890e..458e666 100644
55224 --- a/drivers/video/fbdev/udlfb.c
55225 +++ b/drivers/video/fbdev/udlfb.c
55226 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55227 dlfb_urb_completion(urb);
55228
55229 error:
55230 - atomic_add(bytes_sent, &dev->bytes_sent);
55231 - atomic_add(bytes_identical, &dev->bytes_identical);
55232 - atomic_add(width*height*2, &dev->bytes_rendered);
55233 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55234 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55235 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55236 end_cycles = get_cycles();
55237 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55238 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55239 >> 10)), /* Kcycles */
55240 &dev->cpu_kcycles_used);
55241
55242 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55243 dlfb_urb_completion(urb);
55244
55245 error:
55246 - atomic_add(bytes_sent, &dev->bytes_sent);
55247 - atomic_add(bytes_identical, &dev->bytes_identical);
55248 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55249 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55250 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55251 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55252 end_cycles = get_cycles();
55253 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55254 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55255 >> 10)), /* Kcycles */
55256 &dev->cpu_kcycles_used);
55257 }
55258 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55259 fb_deferred_io_cleanup(info);
55260 kfree(info->fbdefio);
55261 info->fbdefio = NULL;
55262 - info->fbops->fb_mmap = dlfb_ops_mmap;
55263 + pax_open_kernel();
55264 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55265 + pax_close_kernel();
55266 }
55267
55268 pr_warn("released /dev/fb%d user=%d count=%d\n",
55269 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55270 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55271 struct dlfb_data *dev = fb_info->par;
55272 return snprintf(buf, PAGE_SIZE, "%u\n",
55273 - atomic_read(&dev->bytes_rendered));
55274 + atomic_read_unchecked(&dev->bytes_rendered));
55275 }
55276
55277 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55278 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55279 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55280 struct dlfb_data *dev = fb_info->par;
55281 return snprintf(buf, PAGE_SIZE, "%u\n",
55282 - atomic_read(&dev->bytes_identical));
55283 + atomic_read_unchecked(&dev->bytes_identical));
55284 }
55285
55286 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55287 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55288 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55289 struct dlfb_data *dev = fb_info->par;
55290 return snprintf(buf, PAGE_SIZE, "%u\n",
55291 - atomic_read(&dev->bytes_sent));
55292 + atomic_read_unchecked(&dev->bytes_sent));
55293 }
55294
55295 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55296 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55297 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55298 struct dlfb_data *dev = fb_info->par;
55299 return snprintf(buf, PAGE_SIZE, "%u\n",
55300 - atomic_read(&dev->cpu_kcycles_used));
55301 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55302 }
55303
55304 static ssize_t edid_show(
55305 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55306 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55307 struct dlfb_data *dev = fb_info->par;
55308
55309 - atomic_set(&dev->bytes_rendered, 0);
55310 - atomic_set(&dev->bytes_identical, 0);
55311 - atomic_set(&dev->bytes_sent, 0);
55312 - atomic_set(&dev->cpu_kcycles_used, 0);
55313 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55314 + atomic_set_unchecked(&dev->bytes_identical, 0);
55315 + atomic_set_unchecked(&dev->bytes_sent, 0);
55316 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55317
55318 return count;
55319 }
55320 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55321 index 509d452..7c9d2de 100644
55322 --- a/drivers/video/fbdev/uvesafb.c
55323 +++ b/drivers/video/fbdev/uvesafb.c
55324 @@ -19,6 +19,7 @@
55325 #include <linux/io.h>
55326 #include <linux/mutex.h>
55327 #include <linux/slab.h>
55328 +#include <linux/moduleloader.h>
55329 #include <video/edid.h>
55330 #include <video/uvesafb.h>
55331 #ifdef CONFIG_X86
55332 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55333 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55334 par->pmi_setpal = par->ypan = 0;
55335 } else {
55336 +
55337 +#ifdef CONFIG_PAX_KERNEXEC
55338 +#ifdef CONFIG_MODULES
55339 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55340 +#endif
55341 + if (!par->pmi_code) {
55342 + par->pmi_setpal = par->ypan = 0;
55343 + return 0;
55344 + }
55345 +#endif
55346 +
55347 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55348 + task->t.regs.edi);
55349 +
55350 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55351 + pax_open_kernel();
55352 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55353 + pax_close_kernel();
55354 +
55355 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55356 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55357 +#else
55358 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55359 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55360 +#endif
55361 +
55362 printk(KERN_INFO "uvesafb: protected mode interface info at "
55363 "%04x:%04x\n",
55364 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55365 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55366 par->ypan = ypan;
55367
55368 if (par->pmi_setpal || par->ypan) {
55369 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55370 if (__supported_pte_mask & _PAGE_NX) {
55371 par->pmi_setpal = par->ypan = 0;
55372 printk(KERN_WARNING "uvesafb: NX protection is active, "
55373 "better not use the PMI.\n");
55374 - } else {
55375 + } else
55376 +#endif
55377 uvesafb_vbe_getpmi(task, par);
55378 - }
55379 }
55380 #else
55381 /* The protected mode interface is not available on non-x86. */
55382 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55383 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55384
55385 /* Disable blanking if the user requested so. */
55386 - if (!blank)
55387 - info->fbops->fb_blank = NULL;
55388 + if (!blank) {
55389 + pax_open_kernel();
55390 + *(void **)&info->fbops->fb_blank = NULL;
55391 + pax_close_kernel();
55392 + }
55393
55394 /*
55395 * Find out how much IO memory is required for the mode with
55396 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55397 info->flags = FBINFO_FLAG_DEFAULT |
55398 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55399
55400 - if (!par->ypan)
55401 - info->fbops->fb_pan_display = NULL;
55402 + if (!par->ypan) {
55403 + pax_open_kernel();
55404 + *(void **)&info->fbops->fb_pan_display = NULL;
55405 + pax_close_kernel();
55406 + }
55407 }
55408
55409 static void uvesafb_init_mtrr(struct fb_info *info)
55410 @@ -1787,6 +1817,11 @@ out_mode:
55411 out:
55412 kfree(par->vbe_modes);
55413
55414 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55415 + if (par->pmi_code)
55416 + module_free_exec(NULL, par->pmi_code);
55417 +#endif
55418 +
55419 framebuffer_release(info);
55420 return err;
55421 }
55422 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55423 kfree(par->vbe_state_orig);
55424 kfree(par->vbe_state_saved);
55425
55426 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55427 + if (par->pmi_code)
55428 + module_free_exec(NULL, par->pmi_code);
55429 +#endif
55430 +
55431 framebuffer_release(info);
55432 }
55433 return 0;
55434 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55435 index 6170e7f..dd63031 100644
55436 --- a/drivers/video/fbdev/vesafb.c
55437 +++ b/drivers/video/fbdev/vesafb.c
55438 @@ -9,6 +9,7 @@
55439 */
55440
55441 #include <linux/module.h>
55442 +#include <linux/moduleloader.h>
55443 #include <linux/kernel.h>
55444 #include <linux/errno.h>
55445 #include <linux/string.h>
55446 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55447 static int vram_total; /* Set total amount of memory */
55448 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55449 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55450 -static void (*pmi_start)(void) __read_mostly;
55451 -static void (*pmi_pal) (void) __read_mostly;
55452 +static void (*pmi_start)(void) __read_only;
55453 +static void (*pmi_pal) (void) __read_only;
55454 static int depth __read_mostly;
55455 static int vga_compat __read_mostly;
55456 /* --------------------------------------------------------------------- */
55457 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55458 unsigned int size_remap;
55459 unsigned int size_total;
55460 char *option = NULL;
55461 + void *pmi_code = NULL;
55462
55463 /* ignore error return of fb_get_options */
55464 fb_get_options("vesafb", &option);
55465 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55466 size_remap = size_total;
55467 vesafb_fix.smem_len = size_remap;
55468
55469 -#ifndef __i386__
55470 - screen_info.vesapm_seg = 0;
55471 -#endif
55472 -
55473 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55474 printk(KERN_WARNING
55475 "vesafb: cannot reserve video memory at 0x%lx\n",
55476 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55477 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55478 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55479
55480 +#ifdef __i386__
55481 +
55482 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55483 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55484 + if (!pmi_code)
55485 +#elif !defined(CONFIG_PAX_KERNEXEC)
55486 + if (0)
55487 +#endif
55488 +
55489 +#endif
55490 + screen_info.vesapm_seg = 0;
55491 +
55492 if (screen_info.vesapm_seg) {
55493 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55494 - screen_info.vesapm_seg,screen_info.vesapm_off);
55495 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55496 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55497 }
55498
55499 if (screen_info.vesapm_seg < 0xc000)
55500 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55501
55502 if (ypan || pmi_setpal) {
55503 unsigned short *pmi_base;
55504 +
55505 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55506 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55507 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55508 +
55509 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55510 + pax_open_kernel();
55511 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55512 +#else
55513 + pmi_code = pmi_base;
55514 +#endif
55515 +
55516 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55517 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55518 +
55519 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55520 + pmi_start = ktva_ktla(pmi_start);
55521 + pmi_pal = ktva_ktla(pmi_pal);
55522 + pax_close_kernel();
55523 +#endif
55524 +
55525 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55526 if (pmi_base[3]) {
55527 printk(KERN_INFO "vesafb: pmi: ports = ");
55528 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55529 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55530 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55531
55532 - if (!ypan)
55533 - info->fbops->fb_pan_display = NULL;
55534 + if (!ypan) {
55535 + pax_open_kernel();
55536 + *(void **)&info->fbops->fb_pan_display = NULL;
55537 + pax_close_kernel();
55538 + }
55539
55540 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55541 err = -ENOMEM;
55542 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55543 fb_info(info, "%s frame buffer device\n", info->fix.id);
55544 return 0;
55545 err:
55546 +
55547 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55548 + module_free_exec(NULL, pmi_code);
55549 +#endif
55550 +
55551 if (info->screen_base)
55552 iounmap(info->screen_base);
55553 framebuffer_release(info);
55554 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55555 index 88714ae..16c2e11 100644
55556 --- a/drivers/video/fbdev/via/via_clock.h
55557 +++ b/drivers/video/fbdev/via/via_clock.h
55558 @@ -56,7 +56,7 @@ struct via_clock {
55559
55560 void (*set_engine_pll_state)(u8 state);
55561 void (*set_engine_pll)(struct via_pll_config config);
55562 -};
55563 +} __no_const;
55564
55565
55566 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55567 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55568 index 3c14e43..2630570 100644
55569 --- a/drivers/video/logo/logo_linux_clut224.ppm
55570 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55571 @@ -2,1603 +2,1123 @@ P3
55572 # Standard 224-color Linux logo
55573 80 80
55574 255
55575 - 0 0 0 0 0 0 0 0 0 0 0 0
55576 - 0 0 0 0 0 0 0 0 0 0 0 0
55577 - 0 0 0 0 0 0 0 0 0 0 0 0
55578 - 0 0 0 0 0 0 0 0 0 0 0 0
55579 - 0 0 0 0 0 0 0 0 0 0 0 0
55580 - 0 0 0 0 0 0 0 0 0 0 0 0
55581 - 0 0 0 0 0 0 0 0 0 0 0 0
55582 - 0 0 0 0 0 0 0 0 0 0 0 0
55583 - 0 0 0 0 0 0 0 0 0 0 0 0
55584 - 6 6 6 6 6 6 10 10 10 10 10 10
55585 - 10 10 10 6 6 6 6 6 6 6 6 6
55586 - 0 0 0 0 0 0 0 0 0 0 0 0
55587 - 0 0 0 0 0 0 0 0 0 0 0 0
55588 - 0 0 0 0 0 0 0 0 0 0 0 0
55589 - 0 0 0 0 0 0 0 0 0 0 0 0
55590 - 0 0 0 0 0 0 0 0 0 0 0 0
55591 - 0 0 0 0 0 0 0 0 0 0 0 0
55592 - 0 0 0 0 0 0 0 0 0 0 0 0
55593 - 0 0 0 0 0 0 0 0 0 0 0 0
55594 - 0 0 0 0 0 0 0 0 0 0 0 0
55595 - 0 0 0 0 0 0 0 0 0 0 0 0
55596 - 0 0 0 0 0 0 0 0 0 0 0 0
55597 - 0 0 0 0 0 0 0 0 0 0 0 0
55598 - 0 0 0 0 0 0 0 0 0 0 0 0
55599 - 0 0 0 0 0 0 0 0 0 0 0 0
55600 - 0 0 0 0 0 0 0 0 0 0 0 0
55601 - 0 0 0 0 0 0 0 0 0 0 0 0
55602 - 0 0 0 0 0 0 0 0 0 0 0 0
55603 - 0 0 0 6 6 6 10 10 10 14 14 14
55604 - 22 22 22 26 26 26 30 30 30 34 34 34
55605 - 30 30 30 30 30 30 26 26 26 18 18 18
55606 - 14 14 14 10 10 10 6 6 6 0 0 0
55607 - 0 0 0 0 0 0 0 0 0 0 0 0
55608 - 0 0 0 0 0 0 0 0 0 0 0 0
55609 - 0 0 0 0 0 0 0 0 0 0 0 0
55610 - 0 0 0 0 0 0 0 0 0 0 0 0
55611 - 0 0 0 0 0 0 0 0 0 0 0 0
55612 - 0 0 0 0 0 0 0 0 0 0 0 0
55613 - 0 0 0 0 0 0 0 0 0 0 0 0
55614 - 0 0 0 0 0 0 0 0 0 0 0 0
55615 - 0 0 0 0 0 0 0 0 0 0 0 0
55616 - 0 0 0 0 0 1 0 0 1 0 0 0
55617 - 0 0 0 0 0 0 0 0 0 0 0 0
55618 - 0 0 0 0 0 0 0 0 0 0 0 0
55619 - 0 0 0 0 0 0 0 0 0 0 0 0
55620 - 0 0 0 0 0 0 0 0 0 0 0 0
55621 - 0 0 0 0 0 0 0 0 0 0 0 0
55622 - 0 0 0 0 0 0 0 0 0 0 0 0
55623 - 6 6 6 14 14 14 26 26 26 42 42 42
55624 - 54 54 54 66 66 66 78 78 78 78 78 78
55625 - 78 78 78 74 74 74 66 66 66 54 54 54
55626 - 42 42 42 26 26 26 18 18 18 10 10 10
55627 - 6 6 6 0 0 0 0 0 0 0 0 0
55628 - 0 0 0 0 0 0 0 0 0 0 0 0
55629 - 0 0 0 0 0 0 0 0 0 0 0 0
55630 - 0 0 0 0 0 0 0 0 0 0 0 0
55631 - 0 0 0 0 0 0 0 0 0 0 0 0
55632 - 0 0 0 0 0 0 0 0 0 0 0 0
55633 - 0 0 0 0 0 0 0 0 0 0 0 0
55634 - 0 0 0 0 0 0 0 0 0 0 0 0
55635 - 0 0 0 0 0 0 0 0 0 0 0 0
55636 - 0 0 1 0 0 0 0 0 0 0 0 0
55637 - 0 0 0 0 0 0 0 0 0 0 0 0
55638 - 0 0 0 0 0 0 0 0 0 0 0 0
55639 - 0 0 0 0 0 0 0 0 0 0 0 0
55640 - 0 0 0 0 0 0 0 0 0 0 0 0
55641 - 0 0 0 0 0 0 0 0 0 0 0 0
55642 - 0 0 0 0 0 0 0 0 0 10 10 10
55643 - 22 22 22 42 42 42 66 66 66 86 86 86
55644 - 66 66 66 38 38 38 38 38 38 22 22 22
55645 - 26 26 26 34 34 34 54 54 54 66 66 66
55646 - 86 86 86 70 70 70 46 46 46 26 26 26
55647 - 14 14 14 6 6 6 0 0 0 0 0 0
55648 - 0 0 0 0 0 0 0 0 0 0 0 0
55649 - 0 0 0 0 0 0 0 0 0 0 0 0
55650 - 0 0 0 0 0 0 0 0 0 0 0 0
55651 - 0 0 0 0 0 0 0 0 0 0 0 0
55652 - 0 0 0 0 0 0 0 0 0 0 0 0
55653 - 0 0 0 0 0 0 0 0 0 0 0 0
55654 - 0 0 0 0 0 0 0 0 0 0 0 0
55655 - 0 0 0 0 0 0 0 0 0 0 0 0
55656 - 0 0 1 0 0 1 0 0 1 0 0 0
55657 - 0 0 0 0 0 0 0 0 0 0 0 0
55658 - 0 0 0 0 0 0 0 0 0 0 0 0
55659 - 0 0 0 0 0 0 0 0 0 0 0 0
55660 - 0 0 0 0 0 0 0 0 0 0 0 0
55661 - 0 0 0 0 0 0 0 0 0 0 0 0
55662 - 0 0 0 0 0 0 10 10 10 26 26 26
55663 - 50 50 50 82 82 82 58 58 58 6 6 6
55664 - 2 2 6 2 2 6 2 2 6 2 2 6
55665 - 2 2 6 2 2 6 2 2 6 2 2 6
55666 - 6 6 6 54 54 54 86 86 86 66 66 66
55667 - 38 38 38 18 18 18 6 6 6 0 0 0
55668 - 0 0 0 0 0 0 0 0 0 0 0 0
55669 - 0 0 0 0 0 0 0 0 0 0 0 0
55670 - 0 0 0 0 0 0 0 0 0 0 0 0
55671 - 0 0 0 0 0 0 0 0 0 0 0 0
55672 - 0 0 0 0 0 0 0 0 0 0 0 0
55673 - 0 0 0 0 0 0 0 0 0 0 0 0
55674 - 0 0 0 0 0 0 0 0 0 0 0 0
55675 - 0 0 0 0 0 0 0 0 0 0 0 0
55676 - 0 0 0 0 0 0 0 0 0 0 0 0
55677 - 0 0 0 0 0 0 0 0 0 0 0 0
55678 - 0 0 0 0 0 0 0 0 0 0 0 0
55679 - 0 0 0 0 0 0 0 0 0 0 0 0
55680 - 0 0 0 0 0 0 0 0 0 0 0 0
55681 - 0 0 0 0 0 0 0 0 0 0 0 0
55682 - 0 0 0 6 6 6 22 22 22 50 50 50
55683 - 78 78 78 34 34 34 2 2 6 2 2 6
55684 - 2 2 6 2 2 6 2 2 6 2 2 6
55685 - 2 2 6 2 2 6 2 2 6 2 2 6
55686 - 2 2 6 2 2 6 6 6 6 70 70 70
55687 - 78 78 78 46 46 46 22 22 22 6 6 6
55688 - 0 0 0 0 0 0 0 0 0 0 0 0
55689 - 0 0 0 0 0 0 0 0 0 0 0 0
55690 - 0 0 0 0 0 0 0 0 0 0 0 0
55691 - 0 0 0 0 0 0 0 0 0 0 0 0
55692 - 0 0 0 0 0 0 0 0 0 0 0 0
55693 - 0 0 0 0 0 0 0 0 0 0 0 0
55694 - 0 0 0 0 0 0 0 0 0 0 0 0
55695 - 0 0 0 0 0 0 0 0 0 0 0 0
55696 - 0 0 1 0 0 1 0 0 1 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 6 6 6 18 18 18 42 42 42 82 82 82
55703 - 26 26 26 2 2 6 2 2 6 2 2 6
55704 - 2 2 6 2 2 6 2 2 6 2 2 6
55705 - 2 2 6 2 2 6 2 2 6 14 14 14
55706 - 46 46 46 34 34 34 6 6 6 2 2 6
55707 - 42 42 42 78 78 78 42 42 42 18 18 18
55708 - 6 6 6 0 0 0 0 0 0 0 0 0
55709 - 0 0 0 0 0 0 0 0 0 0 0 0
55710 - 0 0 0 0 0 0 0 0 0 0 0 0
55711 - 0 0 0 0 0 0 0 0 0 0 0 0
55712 - 0 0 0 0 0 0 0 0 0 0 0 0
55713 - 0 0 0 0 0 0 0 0 0 0 0 0
55714 - 0 0 0 0 0 0 0 0 0 0 0 0
55715 - 0 0 0 0 0 0 0 0 0 0 0 0
55716 - 0 0 1 0 0 0 0 0 1 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 0 0 0
55722 - 10 10 10 30 30 30 66 66 66 58 58 58
55723 - 2 2 6 2 2 6 2 2 6 2 2 6
55724 - 2 2 6 2 2 6 2 2 6 2 2 6
55725 - 2 2 6 2 2 6 2 2 6 26 26 26
55726 - 86 86 86 101 101 101 46 46 46 10 10 10
55727 - 2 2 6 58 58 58 70 70 70 34 34 34
55728 - 10 10 10 0 0 0 0 0 0 0 0 0
55729 - 0 0 0 0 0 0 0 0 0 0 0 0
55730 - 0 0 0 0 0 0 0 0 0 0 0 0
55731 - 0 0 0 0 0 0 0 0 0 0 0 0
55732 - 0 0 0 0 0 0 0 0 0 0 0 0
55733 - 0 0 0 0 0 0 0 0 0 0 0 0
55734 - 0 0 0 0 0 0 0 0 0 0 0 0
55735 - 0 0 0 0 0 0 0 0 0 0 0 0
55736 - 0 0 1 0 0 1 0 0 1 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 0 0 0
55742 - 14 14 14 42 42 42 86 86 86 10 10 10
55743 - 2 2 6 2 2 6 2 2 6 2 2 6
55744 - 2 2 6 2 2 6 2 2 6 2 2 6
55745 - 2 2 6 2 2 6 2 2 6 30 30 30
55746 - 94 94 94 94 94 94 58 58 58 26 26 26
55747 - 2 2 6 6 6 6 78 78 78 54 54 54
55748 - 22 22 22 6 6 6 0 0 0 0 0 0
55749 - 0 0 0 0 0 0 0 0 0 0 0 0
55750 - 0 0 0 0 0 0 0 0 0 0 0 0
55751 - 0 0 0 0 0 0 0 0 0 0 0 0
55752 - 0 0 0 0 0 0 0 0 0 0 0 0
55753 - 0 0 0 0 0 0 0 0 0 0 0 0
55754 - 0 0 0 0 0 0 0 0 0 0 0 0
55755 - 0 0 0 0 0 0 0 0 0 0 0 0
55756 - 0 0 0 0 0 0 0 0 0 0 0 0
55757 - 0 0 0 0 0 0 0 0 0 0 0 0
55758 - 0 0 0 0 0 0 0 0 0 0 0 0
55759 - 0 0 0 0 0 0 0 0 0 0 0 0
55760 - 0 0 0 0 0 0 0 0 0 0 0 0
55761 - 0 0 0 0 0 0 0 0 0 6 6 6
55762 - 22 22 22 62 62 62 62 62 62 2 2 6
55763 - 2 2 6 2 2 6 2 2 6 2 2 6
55764 - 2 2 6 2 2 6 2 2 6 2 2 6
55765 - 2 2 6 2 2 6 2 2 6 26 26 26
55766 - 54 54 54 38 38 38 18 18 18 10 10 10
55767 - 2 2 6 2 2 6 34 34 34 82 82 82
55768 - 38 38 38 14 14 14 0 0 0 0 0 0
55769 - 0 0 0 0 0 0 0 0 0 0 0 0
55770 - 0 0 0 0 0 0 0 0 0 0 0 0
55771 - 0 0 0 0 0 0 0 0 0 0 0 0
55772 - 0 0 0 0 0 0 0 0 0 0 0 0
55773 - 0 0 0 0 0 0 0 0 0 0 0 0
55774 - 0 0 0 0 0 0 0 0 0 0 0 0
55775 - 0 0 0 0 0 0 0 0 0 0 0 0
55776 - 0 0 0 0 0 1 0 0 1 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 6 6 6
55782 - 30 30 30 78 78 78 30 30 30 2 2 6
55783 - 2 2 6 2 2 6 2 2 6 2 2 6
55784 - 2 2 6 2 2 6 2 2 6 2 2 6
55785 - 2 2 6 2 2 6 2 2 6 10 10 10
55786 - 10 10 10 2 2 6 2 2 6 2 2 6
55787 - 2 2 6 2 2 6 2 2 6 78 78 78
55788 - 50 50 50 18 18 18 6 6 6 0 0 0
55789 - 0 0 0 0 0 0 0 0 0 0 0 0
55790 - 0 0 0 0 0 0 0 0 0 0 0 0
55791 - 0 0 0 0 0 0 0 0 0 0 0 0
55792 - 0 0 0 0 0 0 0 0 0 0 0 0
55793 - 0 0 0 0 0 0 0 0 0 0 0 0
55794 - 0 0 0 0 0 0 0 0 0 0 0 0
55795 - 0 0 0 0 0 0 0 0 0 0 0 0
55796 - 0 0 1 0 0 0 0 0 0 0 0 0
55797 - 0 0 0 0 0 0 0 0 0 0 0 0
55798 - 0 0 0 0 0 0 0 0 0 0 0 0
55799 - 0 0 0 0 0 0 0 0 0 0 0 0
55800 - 0 0 0 0 0 0 0 0 0 0 0 0
55801 - 0 0 0 0 0 0 0 0 0 10 10 10
55802 - 38 38 38 86 86 86 14 14 14 2 2 6
55803 - 2 2 6 2 2 6 2 2 6 2 2 6
55804 - 2 2 6 2 2 6 2 2 6 2 2 6
55805 - 2 2 6 2 2 6 2 2 6 2 2 6
55806 - 2 2 6 2 2 6 2 2 6 2 2 6
55807 - 2 2 6 2 2 6 2 2 6 54 54 54
55808 - 66 66 66 26 26 26 6 6 6 0 0 0
55809 - 0 0 0 0 0 0 0 0 0 0 0 0
55810 - 0 0 0 0 0 0 0 0 0 0 0 0
55811 - 0 0 0 0 0 0 0 0 0 0 0 0
55812 - 0 0 0 0 0 0 0 0 0 0 0 0
55813 - 0 0 0 0 0 0 0 0 0 0 0 0
55814 - 0 0 0 0 0 0 0 0 0 0 0 0
55815 - 0 0 0 0 0 0 0 0 0 0 0 0
55816 - 0 0 0 0 0 1 0 0 1 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 14 14 14
55822 - 42 42 42 82 82 82 2 2 6 2 2 6
55823 - 2 2 6 6 6 6 10 10 10 2 2 6
55824 - 2 2 6 2 2 6 2 2 6 2 2 6
55825 - 2 2 6 2 2 6 2 2 6 6 6 6
55826 - 14 14 14 10 10 10 2 2 6 2 2 6
55827 - 2 2 6 2 2 6 2 2 6 18 18 18
55828 - 82 82 82 34 34 34 10 10 10 0 0 0
55829 - 0 0 0 0 0 0 0 0 0 0 0 0
55830 - 0 0 0 0 0 0 0 0 0 0 0 0
55831 - 0 0 0 0 0 0 0 0 0 0 0 0
55832 - 0 0 0 0 0 0 0 0 0 0 0 0
55833 - 0 0 0 0 0 0 0 0 0 0 0 0
55834 - 0 0 0 0 0 0 0 0 0 0 0 0
55835 - 0 0 0 0 0 0 0 0 0 0 0 0
55836 - 0 0 1 0 0 0 0 0 0 0 0 0
55837 - 0 0 0 0 0 0 0 0 0 0 0 0
55838 - 0 0 0 0 0 0 0 0 0 0 0 0
55839 - 0 0 0 0 0 0 0 0 0 0 0 0
55840 - 0 0 0 0 0 0 0 0 0 0 0 0
55841 - 0 0 0 0 0 0 0 0 0 14 14 14
55842 - 46 46 46 86 86 86 2 2 6 2 2 6
55843 - 6 6 6 6 6 6 22 22 22 34 34 34
55844 - 6 6 6 2 2 6 2 2 6 2 2 6
55845 - 2 2 6 2 2 6 18 18 18 34 34 34
55846 - 10 10 10 50 50 50 22 22 22 2 2 6
55847 - 2 2 6 2 2 6 2 2 6 10 10 10
55848 - 86 86 86 42 42 42 14 14 14 0 0 0
55849 - 0 0 0 0 0 0 0 0 0 0 0 0
55850 - 0 0 0 0 0 0 0 0 0 0 0 0
55851 - 0 0 0 0 0 0 0 0 0 0 0 0
55852 - 0 0 0 0 0 0 0 0 0 0 0 0
55853 - 0 0 0 0 0 0 0 0 0 0 0 0
55854 - 0 0 0 0 0 0 0 0 0 0 0 0
55855 - 0 0 0 0 0 0 0 0 0 0 0 0
55856 - 0 0 1 0 0 1 0 0 1 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 14 14 14
55862 - 46 46 46 86 86 86 2 2 6 2 2 6
55863 - 38 38 38 116 116 116 94 94 94 22 22 22
55864 - 22 22 22 2 2 6 2 2 6 2 2 6
55865 - 14 14 14 86 86 86 138 138 138 162 162 162
55866 -154 154 154 38 38 38 26 26 26 6 6 6
55867 - 2 2 6 2 2 6 2 2 6 2 2 6
55868 - 86 86 86 46 46 46 14 14 14 0 0 0
55869 - 0 0 0 0 0 0 0 0 0 0 0 0
55870 - 0 0 0 0 0 0 0 0 0 0 0 0
55871 - 0 0 0 0 0 0 0 0 0 0 0 0
55872 - 0 0 0 0 0 0 0 0 0 0 0 0
55873 - 0 0 0 0 0 0 0 0 0 0 0 0
55874 - 0 0 0 0 0 0 0 0 0 0 0 0
55875 - 0 0 0 0 0 0 0 0 0 0 0 0
55876 - 0 0 0 0 0 0 0 0 0 0 0 0
55877 - 0 0 0 0 0 0 0 0 0 0 0 0
55878 - 0 0 0 0 0 0 0 0 0 0 0 0
55879 - 0 0 0 0 0 0 0 0 0 0 0 0
55880 - 0 0 0 0 0 0 0 0 0 0 0 0
55881 - 0 0 0 0 0 0 0 0 0 14 14 14
55882 - 46 46 46 86 86 86 2 2 6 14 14 14
55883 -134 134 134 198 198 198 195 195 195 116 116 116
55884 - 10 10 10 2 2 6 2 2 6 6 6 6
55885 -101 98 89 187 187 187 210 210 210 218 218 218
55886 -214 214 214 134 134 134 14 14 14 6 6 6
55887 - 2 2 6 2 2 6 2 2 6 2 2 6
55888 - 86 86 86 50 50 50 18 18 18 6 6 6
55889 - 0 0 0 0 0 0 0 0 0 0 0 0
55890 - 0 0 0 0 0 0 0 0 0 0 0 0
55891 - 0 0 0 0 0 0 0 0 0 0 0 0
55892 - 0 0 0 0 0 0 0 0 0 0 0 0
55893 - 0 0 0 0 0 0 0 0 0 0 0 0
55894 - 0 0 0 0 0 0 0 0 0 0 0 0
55895 - 0 0 0 0 0 0 0 0 1 0 0 0
55896 - 0 0 1 0 0 1 0 0 1 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 0 0 0 0 0 0 0 0 0 14 14 14
55902 - 46 46 46 86 86 86 2 2 6 54 54 54
55903 -218 218 218 195 195 195 226 226 226 246 246 246
55904 - 58 58 58 2 2 6 2 2 6 30 30 30
55905 -210 210 210 253 253 253 174 174 174 123 123 123
55906 -221 221 221 234 234 234 74 74 74 2 2 6
55907 - 2 2 6 2 2 6 2 2 6 2 2 6
55908 - 70 70 70 58 58 58 22 22 22 6 6 6
55909 - 0 0 0 0 0 0 0 0 0 0 0 0
55910 - 0 0 0 0 0 0 0 0 0 0 0 0
55911 - 0 0 0 0 0 0 0 0 0 0 0 0
55912 - 0 0 0 0 0 0 0 0 0 0 0 0
55913 - 0 0 0 0 0 0 0 0 0 0 0 0
55914 - 0 0 0 0 0 0 0 0 0 0 0 0
55915 - 0 0 0 0 0 0 0 0 0 0 0 0
55916 - 0 0 0 0 0 0 0 0 0 0 0 0
55917 - 0 0 0 0 0 0 0 0 0 0 0 0
55918 - 0 0 0 0 0 0 0 0 0 0 0 0
55919 - 0 0 0 0 0 0 0 0 0 0 0 0
55920 - 0 0 0 0 0 0 0 0 0 0 0 0
55921 - 0 0 0 0 0 0 0 0 0 14 14 14
55922 - 46 46 46 82 82 82 2 2 6 106 106 106
55923 -170 170 170 26 26 26 86 86 86 226 226 226
55924 -123 123 123 10 10 10 14 14 14 46 46 46
55925 -231 231 231 190 190 190 6 6 6 70 70 70
55926 - 90 90 90 238 238 238 158 158 158 2 2 6
55927 - 2 2 6 2 2 6 2 2 6 2 2 6
55928 - 70 70 70 58 58 58 22 22 22 6 6 6
55929 - 0 0 0 0 0 0 0 0 0 0 0 0
55930 - 0 0 0 0 0 0 0 0 0 0 0 0
55931 - 0 0 0 0 0 0 0 0 0 0 0 0
55932 - 0 0 0 0 0 0 0 0 0 0 0 0
55933 - 0 0 0 0 0 0 0 0 0 0 0 0
55934 - 0 0 0 0 0 0 0 0 0 0 0 0
55935 - 0 0 0 0 0 0 0 0 1 0 0 0
55936 - 0 0 1 0 0 1 0 0 1 0 0 0
55937 - 0 0 0 0 0 0 0 0 0 0 0 0
55938 - 0 0 0 0 0 0 0 0 0 0 0 0
55939 - 0 0 0 0 0 0 0 0 0 0 0 0
55940 - 0 0 0 0 0 0 0 0 0 0 0 0
55941 - 0 0 0 0 0 0 0 0 0 14 14 14
55942 - 42 42 42 86 86 86 6 6 6 116 116 116
55943 -106 106 106 6 6 6 70 70 70 149 149 149
55944 -128 128 128 18 18 18 38 38 38 54 54 54
55945 -221 221 221 106 106 106 2 2 6 14 14 14
55946 - 46 46 46 190 190 190 198 198 198 2 2 6
55947 - 2 2 6 2 2 6 2 2 6 2 2 6
55948 - 74 74 74 62 62 62 22 22 22 6 6 6
55949 - 0 0 0 0 0 0 0 0 0 0 0 0
55950 - 0 0 0 0 0 0 0 0 0 0 0 0
55951 - 0 0 0 0 0 0 0 0 0 0 0 0
55952 - 0 0 0 0 0 0 0 0 0 0 0 0
55953 - 0 0 0 0 0 0 0 0 0 0 0 0
55954 - 0 0 0 0 0 0 0 0 0 0 0 0
55955 - 0 0 0 0 0 0 0 0 1 0 0 0
55956 - 0 0 1 0 0 0 0 0 1 0 0 0
55957 - 0 0 0 0 0 0 0 0 0 0 0 0
55958 - 0 0 0 0 0 0 0 0 0 0 0 0
55959 - 0 0 0 0 0 0 0 0 0 0 0 0
55960 - 0 0 0 0 0 0 0 0 0 0 0 0
55961 - 0 0 0 0 0 0 0 0 0 14 14 14
55962 - 42 42 42 94 94 94 14 14 14 101 101 101
55963 -128 128 128 2 2 6 18 18 18 116 116 116
55964 -118 98 46 121 92 8 121 92 8 98 78 10
55965 -162 162 162 106 106 106 2 2 6 2 2 6
55966 - 2 2 6 195 195 195 195 195 195 6 6 6
55967 - 2 2 6 2 2 6 2 2 6 2 2 6
55968 - 74 74 74 62 62 62 22 22 22 6 6 6
55969 - 0 0 0 0 0 0 0 0 0 0 0 0
55970 - 0 0 0 0 0 0 0 0 0 0 0 0
55971 - 0 0 0 0 0 0 0 0 0 0 0 0
55972 - 0 0 0 0 0 0 0 0 0 0 0 0
55973 - 0 0 0 0 0 0 0 0 0 0 0 0
55974 - 0 0 0 0 0 0 0 0 0 0 0 0
55975 - 0 0 0 0 0 0 0 0 1 0 0 1
55976 - 0 0 1 0 0 0 0 0 1 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 10 10 10
55982 - 38 38 38 90 90 90 14 14 14 58 58 58
55983 -210 210 210 26 26 26 54 38 6 154 114 10
55984 -226 170 11 236 186 11 225 175 15 184 144 12
55985 -215 174 15 175 146 61 37 26 9 2 2 6
55986 - 70 70 70 246 246 246 138 138 138 2 2 6
55987 - 2 2 6 2 2 6 2 2 6 2 2 6
55988 - 70 70 70 66 66 66 26 26 26 6 6 6
55989 - 0 0 0 0 0 0 0 0 0 0 0 0
55990 - 0 0 0 0 0 0 0 0 0 0 0 0
55991 - 0 0 0 0 0 0 0 0 0 0 0 0
55992 - 0 0 0 0 0 0 0 0 0 0 0 0
55993 - 0 0 0 0 0 0 0 0 0 0 0 0
55994 - 0 0 0 0 0 0 0 0 0 0 0 0
55995 - 0 0 0 0 0 0 0 0 0 0 0 0
55996 - 0 0 0 0 0 0 0 0 0 0 0 0
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 0 0 0 0 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 10 10 10
56002 - 38 38 38 86 86 86 14 14 14 10 10 10
56003 -195 195 195 188 164 115 192 133 9 225 175 15
56004 -239 182 13 234 190 10 232 195 16 232 200 30
56005 -245 207 45 241 208 19 232 195 16 184 144 12
56006 -218 194 134 211 206 186 42 42 42 2 2 6
56007 - 2 2 6 2 2 6 2 2 6 2 2 6
56008 - 50 50 50 74 74 74 30 30 30 6 6 6
56009 - 0 0 0 0 0 0 0 0 0 0 0 0
56010 - 0 0 0 0 0 0 0 0 0 0 0 0
56011 - 0 0 0 0 0 0 0 0 0 0 0 0
56012 - 0 0 0 0 0 0 0 0 0 0 0 0
56013 - 0 0 0 0 0 0 0 0 0 0 0 0
56014 - 0 0 0 0 0 0 0 0 0 0 0 0
56015 - 0 0 0 0 0 0 0 0 0 0 0 0
56016 - 0 0 0 0 0 0 0 0 0 0 0 0
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 0 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 10 10 10
56022 - 34 34 34 86 86 86 14 14 14 2 2 6
56023 -121 87 25 192 133 9 219 162 10 239 182 13
56024 -236 186 11 232 195 16 241 208 19 244 214 54
56025 -246 218 60 246 218 38 246 215 20 241 208 19
56026 -241 208 19 226 184 13 121 87 25 2 2 6
56027 - 2 2 6 2 2 6 2 2 6 2 2 6
56028 - 50 50 50 82 82 82 34 34 34 10 10 10
56029 - 0 0 0 0 0 0 0 0 0 0 0 0
56030 - 0 0 0 0 0 0 0 0 0 0 0 0
56031 - 0 0 0 0 0 0 0 0 0 0 0 0
56032 - 0 0 0 0 0 0 0 0 0 0 0 0
56033 - 0 0 0 0 0 0 0 0 0 0 0 0
56034 - 0 0 0 0 0 0 0 0 0 0 0 0
56035 - 0 0 0 0 0 0 0 0 0 0 0 0
56036 - 0 0 0 0 0 0 0 0 0 0 0 0
56037 - 0 0 0 0 0 0 0 0 0 0 0 0
56038 - 0 0 0 0 0 0 0 0 0 0 0 0
56039 - 0 0 0 0 0 0 0 0 0 0 0 0
56040 - 0 0 0 0 0 0 0 0 0 0 0 0
56041 - 0 0 0 0 0 0 0 0 0 10 10 10
56042 - 34 34 34 82 82 82 30 30 30 61 42 6
56043 -180 123 7 206 145 10 230 174 11 239 182 13
56044 -234 190 10 238 202 15 241 208 19 246 218 74
56045 -246 218 38 246 215 20 246 215 20 246 215 20
56046 -226 184 13 215 174 15 184 144 12 6 6 6
56047 - 2 2 6 2 2 6 2 2 6 2 2 6
56048 - 26 26 26 94 94 94 42 42 42 14 14 14
56049 - 0 0 0 0 0 0 0 0 0 0 0 0
56050 - 0 0 0 0 0 0 0 0 0 0 0 0
56051 - 0 0 0 0 0 0 0 0 0 0 0 0
56052 - 0 0 0 0 0 0 0 0 0 0 0 0
56053 - 0 0 0 0 0 0 0 0 0 0 0 0
56054 - 0 0 0 0 0 0 0 0 0 0 0 0
56055 - 0 0 0 0 0 0 0 0 0 0 0 0
56056 - 0 0 0 0 0 0 0 0 0 0 0 0
56057 - 0 0 0 0 0 0 0 0 0 0 0 0
56058 - 0 0 0 0 0 0 0 0 0 0 0 0
56059 - 0 0 0 0 0 0 0 0 0 0 0 0
56060 - 0 0 0 0 0 0 0 0 0 0 0 0
56061 - 0 0 0 0 0 0 0 0 0 10 10 10
56062 - 30 30 30 78 78 78 50 50 50 104 69 6
56063 -192 133 9 216 158 10 236 178 12 236 186 11
56064 -232 195 16 241 208 19 244 214 54 245 215 43
56065 -246 215 20 246 215 20 241 208 19 198 155 10
56066 -200 144 11 216 158 10 156 118 10 2 2 6
56067 - 2 2 6 2 2 6 2 2 6 2 2 6
56068 - 6 6 6 90 90 90 54 54 54 18 18 18
56069 - 6 6 6 0 0 0 0 0 0 0 0 0
56070 - 0 0 0 0 0 0 0 0 0 0 0 0
56071 - 0 0 0 0 0 0 0 0 0 0 0 0
56072 - 0 0 0 0 0 0 0 0 0 0 0 0
56073 - 0 0 0 0 0 0 0 0 0 0 0 0
56074 - 0 0 0 0 0 0 0 0 0 0 0 0
56075 - 0 0 0 0 0 0 0 0 0 0 0 0
56076 - 0 0 0 0 0 0 0 0 0 0 0 0
56077 - 0 0 0 0 0 0 0 0 0 0 0 0
56078 - 0 0 0 0 0 0 0 0 0 0 0 0
56079 - 0 0 0 0 0 0 0 0 0 0 0 0
56080 - 0 0 0 0 0 0 0 0 0 0 0 0
56081 - 0 0 0 0 0 0 0 0 0 10 10 10
56082 - 30 30 30 78 78 78 46 46 46 22 22 22
56083 -137 92 6 210 162 10 239 182 13 238 190 10
56084 -238 202 15 241 208 19 246 215 20 246 215 20
56085 -241 208 19 203 166 17 185 133 11 210 150 10
56086 -216 158 10 210 150 10 102 78 10 2 2 6
56087 - 6 6 6 54 54 54 14 14 14 2 2 6
56088 - 2 2 6 62 62 62 74 74 74 30 30 30
56089 - 10 10 10 0 0 0 0 0 0 0 0 0
56090 - 0 0 0 0 0 0 0 0 0 0 0 0
56091 - 0 0 0 0 0 0 0 0 0 0 0 0
56092 - 0 0 0 0 0 0 0 0 0 0 0 0
56093 - 0 0 0 0 0 0 0 0 0 0 0 0
56094 - 0 0 0 0 0 0 0 0 0 0 0 0
56095 - 0 0 0 0 0 0 0 0 0 0 0 0
56096 - 0 0 0 0 0 0 0 0 0 0 0 0
56097 - 0 0 0 0 0 0 0 0 0 0 0 0
56098 - 0 0 0 0 0 0 0 0 0 0 0 0
56099 - 0 0 0 0 0 0 0 0 0 0 0 0
56100 - 0 0 0 0 0 0 0 0 0 0 0 0
56101 - 0 0 0 0 0 0 0 0 0 10 10 10
56102 - 34 34 34 78 78 78 50 50 50 6 6 6
56103 - 94 70 30 139 102 15 190 146 13 226 184 13
56104 -232 200 30 232 195 16 215 174 15 190 146 13
56105 -168 122 10 192 133 9 210 150 10 213 154 11
56106 -202 150 34 182 157 106 101 98 89 2 2 6
56107 - 2 2 6 78 78 78 116 116 116 58 58 58
56108 - 2 2 6 22 22 22 90 90 90 46 46 46
56109 - 18 18 18 6 6 6 0 0 0 0 0 0
56110 - 0 0 0 0 0 0 0 0 0 0 0 0
56111 - 0 0 0 0 0 0 0 0 0 0 0 0
56112 - 0 0 0 0 0 0 0 0 0 0 0 0
56113 - 0 0 0 0 0 0 0 0 0 0 0 0
56114 - 0 0 0 0 0 0 0 0 0 0 0 0
56115 - 0 0 0 0 0 0 0 0 0 0 0 0
56116 - 0 0 0 0 0 0 0 0 0 0 0 0
56117 - 0 0 0 0 0 0 0 0 0 0 0 0
56118 - 0 0 0 0 0 0 0 0 0 0 0 0
56119 - 0 0 0 0 0 0 0 0 0 0 0 0
56120 - 0 0 0 0 0 0 0 0 0 0 0 0
56121 - 0 0 0 0 0 0 0 0 0 10 10 10
56122 - 38 38 38 86 86 86 50 50 50 6 6 6
56123 -128 128 128 174 154 114 156 107 11 168 122 10
56124 -198 155 10 184 144 12 197 138 11 200 144 11
56125 -206 145 10 206 145 10 197 138 11 188 164 115
56126 -195 195 195 198 198 198 174 174 174 14 14 14
56127 - 2 2 6 22 22 22 116 116 116 116 116 116
56128 - 22 22 22 2 2 6 74 74 74 70 70 70
56129 - 30 30 30 10 10 10 0 0 0 0 0 0
56130 - 0 0 0 0 0 0 0 0 0 0 0 0
56131 - 0 0 0 0 0 0 0 0 0 0 0 0
56132 - 0 0 0 0 0 0 0 0 0 0 0 0
56133 - 0 0 0 0 0 0 0 0 0 0 0 0
56134 - 0 0 0 0 0 0 0 0 0 0 0 0
56135 - 0 0 0 0 0 0 0 0 0 0 0 0
56136 - 0 0 0 0 0 0 0 0 0 0 0 0
56137 - 0 0 0 0 0 0 0 0 0 0 0 0
56138 - 0 0 0 0 0 0 0 0 0 0 0 0
56139 - 0 0 0 0 0 0 0 0 0 0 0 0
56140 - 0 0 0 0 0 0 0 0 0 0 0 0
56141 - 0 0 0 0 0 0 6 6 6 18 18 18
56142 - 50 50 50 101 101 101 26 26 26 10 10 10
56143 -138 138 138 190 190 190 174 154 114 156 107 11
56144 -197 138 11 200 144 11 197 138 11 192 133 9
56145 -180 123 7 190 142 34 190 178 144 187 187 187
56146 -202 202 202 221 221 221 214 214 214 66 66 66
56147 - 2 2 6 2 2 6 50 50 50 62 62 62
56148 - 6 6 6 2 2 6 10 10 10 90 90 90
56149 - 50 50 50 18 18 18 6 6 6 0 0 0
56150 - 0 0 0 0 0 0 0 0 0 0 0 0
56151 - 0 0 0 0 0 0 0 0 0 0 0 0
56152 - 0 0 0 0 0 0 0 0 0 0 0 0
56153 - 0 0 0 0 0 0 0 0 0 0 0 0
56154 - 0 0 0 0 0 0 0 0 0 0 0 0
56155 - 0 0 0 0 0 0 0 0 0 0 0 0
56156 - 0 0 0 0 0 0 0 0 0 0 0 0
56157 - 0 0 0 0 0 0 0 0 0 0 0 0
56158 - 0 0 0 0 0 0 0 0 0 0 0 0
56159 - 0 0 0 0 0 0 0 0 0 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 0 0 0 10 10 10 34 34 34
56162 - 74 74 74 74 74 74 2 2 6 6 6 6
56163 -144 144 144 198 198 198 190 190 190 178 166 146
56164 -154 121 60 156 107 11 156 107 11 168 124 44
56165 -174 154 114 187 187 187 190 190 190 210 210 210
56166 -246 246 246 253 253 253 253 253 253 182 182 182
56167 - 6 6 6 2 2 6 2 2 6 2 2 6
56168 - 2 2 6 2 2 6 2 2 6 62 62 62
56169 - 74 74 74 34 34 34 14 14 14 0 0 0
56170 - 0 0 0 0 0 0 0 0 0 0 0 0
56171 - 0 0 0 0 0 0 0 0 0 0 0 0
56172 - 0 0 0 0 0 0 0 0 0 0 0 0
56173 - 0 0 0 0 0 0 0 0 0 0 0 0
56174 - 0 0 0 0 0 0 0 0 0 0 0 0
56175 - 0 0 0 0 0 0 0 0 0 0 0 0
56176 - 0 0 0 0 0 0 0 0 0 0 0 0
56177 - 0 0 0 0 0 0 0 0 0 0 0 0
56178 - 0 0 0 0 0 0 0 0 0 0 0 0
56179 - 0 0 0 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 0 0 0 10 10 10 22 22 22 54 54 54
56182 - 94 94 94 18 18 18 2 2 6 46 46 46
56183 -234 234 234 221 221 221 190 190 190 190 190 190
56184 -190 190 190 187 187 187 187 187 187 190 190 190
56185 -190 190 190 195 195 195 214 214 214 242 242 242
56186 -253 253 253 253 253 253 253 253 253 253 253 253
56187 - 82 82 82 2 2 6 2 2 6 2 2 6
56188 - 2 2 6 2 2 6 2 2 6 14 14 14
56189 - 86 86 86 54 54 54 22 22 22 6 6 6
56190 - 0 0 0 0 0 0 0 0 0 0 0 0
56191 - 0 0 0 0 0 0 0 0 0 0 0 0
56192 - 0 0 0 0 0 0 0 0 0 0 0 0
56193 - 0 0 0 0 0 0 0 0 0 0 0 0
56194 - 0 0 0 0 0 0 0 0 0 0 0 0
56195 - 0 0 0 0 0 0 0 0 0 0 0 0
56196 - 0 0 0 0 0 0 0 0 0 0 0 0
56197 - 0 0 0 0 0 0 0 0 0 0 0 0
56198 - 0 0 0 0 0 0 0 0 0 0 0 0
56199 - 0 0 0 0 0 0 0 0 0 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 0 0 0
56201 - 6 6 6 18 18 18 46 46 46 90 90 90
56202 - 46 46 46 18 18 18 6 6 6 182 182 182
56203 -253 253 253 246 246 246 206 206 206 190 190 190
56204 -190 190 190 190 190 190 190 190 190 190 190 190
56205 -206 206 206 231 231 231 250 250 250 253 253 253
56206 -253 253 253 253 253 253 253 253 253 253 253 253
56207 -202 202 202 14 14 14 2 2 6 2 2 6
56208 - 2 2 6 2 2 6 2 2 6 2 2 6
56209 - 42 42 42 86 86 86 42 42 42 18 18 18
56210 - 6 6 6 0 0 0 0 0 0 0 0 0
56211 - 0 0 0 0 0 0 0 0 0 0 0 0
56212 - 0 0 0 0 0 0 0 0 0 0 0 0
56213 - 0 0 0 0 0 0 0 0 0 0 0 0
56214 - 0 0 0 0 0 0 0 0 0 0 0 0
56215 - 0 0 0 0 0 0 0 0 0 0 0 0
56216 - 0 0 0 0 0 0 0 0 0 0 0 0
56217 - 0 0 0 0 0 0 0 0 0 0 0 0
56218 - 0 0 0 0 0 0 0 0 0 0 0 0
56219 - 0 0 0 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 6 6 6
56221 - 14 14 14 38 38 38 74 74 74 66 66 66
56222 - 2 2 6 6 6 6 90 90 90 250 250 250
56223 -253 253 253 253 253 253 238 238 238 198 198 198
56224 -190 190 190 190 190 190 195 195 195 221 221 221
56225 -246 246 246 253 253 253 253 253 253 253 253 253
56226 -253 253 253 253 253 253 253 253 253 253 253 253
56227 -253 253 253 82 82 82 2 2 6 2 2 6
56228 - 2 2 6 2 2 6 2 2 6 2 2 6
56229 - 2 2 6 78 78 78 70 70 70 34 34 34
56230 - 14 14 14 6 6 6 0 0 0 0 0 0
56231 - 0 0 0 0 0 0 0 0 0 0 0 0
56232 - 0 0 0 0 0 0 0 0 0 0 0 0
56233 - 0 0 0 0 0 0 0 0 0 0 0 0
56234 - 0 0 0 0 0 0 0 0 0 0 0 0
56235 - 0 0 0 0 0 0 0 0 0 0 0 0
56236 - 0 0 0 0 0 0 0 0 0 0 0 0
56237 - 0 0 0 0 0 0 0 0 0 0 0 0
56238 - 0 0 0 0 0 0 0 0 0 0 0 0
56239 - 0 0 0 0 0 0 0 0 0 0 0 0
56240 - 0 0 0 0 0 0 0 0 0 14 14 14
56241 - 34 34 34 66 66 66 78 78 78 6 6 6
56242 - 2 2 6 18 18 18 218 218 218 253 253 253
56243 -253 253 253 253 253 253 253 253 253 246 246 246
56244 -226 226 226 231 231 231 246 246 246 253 253 253
56245 -253 253 253 253 253 253 253 253 253 253 253 253
56246 -253 253 253 253 253 253 253 253 253 253 253 253
56247 -253 253 253 178 178 178 2 2 6 2 2 6
56248 - 2 2 6 2 2 6 2 2 6 2 2 6
56249 - 2 2 6 18 18 18 90 90 90 62 62 62
56250 - 30 30 30 10 10 10 0 0 0 0 0 0
56251 - 0 0 0 0 0 0 0 0 0 0 0 0
56252 - 0 0 0 0 0 0 0 0 0 0 0 0
56253 - 0 0 0 0 0 0 0 0 0 0 0 0
56254 - 0 0 0 0 0 0 0 0 0 0 0 0
56255 - 0 0 0 0 0 0 0 0 0 0 0 0
56256 - 0 0 0 0 0 0 0 0 0 0 0 0
56257 - 0 0 0 0 0 0 0 0 0 0 0 0
56258 - 0 0 0 0 0 0 0 0 0 0 0 0
56259 - 0 0 0 0 0 0 0 0 0 0 0 0
56260 - 0 0 0 0 0 0 10 10 10 26 26 26
56261 - 58 58 58 90 90 90 18 18 18 2 2 6
56262 - 2 2 6 110 110 110 253 253 253 253 253 253
56263 -253 253 253 253 253 253 253 253 253 253 253 253
56264 -250 250 250 253 253 253 253 253 253 253 253 253
56265 -253 253 253 253 253 253 253 253 253 253 253 253
56266 -253 253 253 253 253 253 253 253 253 253 253 253
56267 -253 253 253 231 231 231 18 18 18 2 2 6
56268 - 2 2 6 2 2 6 2 2 6 2 2 6
56269 - 2 2 6 2 2 6 18 18 18 94 94 94
56270 - 54 54 54 26 26 26 10 10 10 0 0 0
56271 - 0 0 0 0 0 0 0 0 0 0 0 0
56272 - 0 0 0 0 0 0 0 0 0 0 0 0
56273 - 0 0 0 0 0 0 0 0 0 0 0 0
56274 - 0 0 0 0 0 0 0 0 0 0 0 0
56275 - 0 0 0 0 0 0 0 0 0 0 0 0
56276 - 0 0 0 0 0 0 0 0 0 0 0 0
56277 - 0 0 0 0 0 0 0 0 0 0 0 0
56278 - 0 0 0 0 0 0 0 0 0 0 0 0
56279 - 0 0 0 0 0 0 0 0 0 0 0 0
56280 - 0 0 0 6 6 6 22 22 22 50 50 50
56281 - 90 90 90 26 26 26 2 2 6 2 2 6
56282 - 14 14 14 195 195 195 250 250 250 253 253 253
56283 -253 253 253 253 253 253 253 253 253 253 253 253
56284 -253 253 253 253 253 253 253 253 253 253 253 253
56285 -253 253 253 253 253 253 253 253 253 253 253 253
56286 -253 253 253 253 253 253 253 253 253 253 253 253
56287 -250 250 250 242 242 242 54 54 54 2 2 6
56288 - 2 2 6 2 2 6 2 2 6 2 2 6
56289 - 2 2 6 2 2 6 2 2 6 38 38 38
56290 - 86 86 86 50 50 50 22 22 22 6 6 6
56291 - 0 0 0 0 0 0 0 0 0 0 0 0
56292 - 0 0 0 0 0 0 0 0 0 0 0 0
56293 - 0 0 0 0 0 0 0 0 0 0 0 0
56294 - 0 0 0 0 0 0 0 0 0 0 0 0
56295 - 0 0 0 0 0 0 0 0 0 0 0 0
56296 - 0 0 0 0 0 0 0 0 0 0 0 0
56297 - 0 0 0 0 0 0 0 0 0 0 0 0
56298 - 0 0 0 0 0 0 0 0 0 0 0 0
56299 - 0 0 0 0 0 0 0 0 0 0 0 0
56300 - 6 6 6 14 14 14 38 38 38 82 82 82
56301 - 34 34 34 2 2 6 2 2 6 2 2 6
56302 - 42 42 42 195 195 195 246 246 246 253 253 253
56303 -253 253 253 253 253 253 253 253 253 250 250 250
56304 -242 242 242 242 242 242 250 250 250 253 253 253
56305 -253 253 253 253 253 253 253 253 253 253 253 253
56306 -253 253 253 250 250 250 246 246 246 238 238 238
56307 -226 226 226 231 231 231 101 101 101 6 6 6
56308 - 2 2 6 2 2 6 2 2 6 2 2 6
56309 - 2 2 6 2 2 6 2 2 6 2 2 6
56310 - 38 38 38 82 82 82 42 42 42 14 14 14
56311 - 6 6 6 0 0 0 0 0 0 0 0 0
56312 - 0 0 0 0 0 0 0 0 0 0 0 0
56313 - 0 0 0 0 0 0 0 0 0 0 0 0
56314 - 0 0 0 0 0 0 0 0 0 0 0 0
56315 - 0 0 0 0 0 0 0 0 0 0 0 0
56316 - 0 0 0 0 0 0 0 0 0 0 0 0
56317 - 0 0 0 0 0 0 0 0 0 0 0 0
56318 - 0 0 0 0 0 0 0 0 0 0 0 0
56319 - 0 0 0 0 0 0 0 0 0 0 0 0
56320 - 10 10 10 26 26 26 62 62 62 66 66 66
56321 - 2 2 6 2 2 6 2 2 6 6 6 6
56322 - 70 70 70 170 170 170 206 206 206 234 234 234
56323 -246 246 246 250 250 250 250 250 250 238 238 238
56324 -226 226 226 231 231 231 238 238 238 250 250 250
56325 -250 250 250 250 250 250 246 246 246 231 231 231
56326 -214 214 214 206 206 206 202 202 202 202 202 202
56327 -198 198 198 202 202 202 182 182 182 18 18 18
56328 - 2 2 6 2 2 6 2 2 6 2 2 6
56329 - 2 2 6 2 2 6 2 2 6 2 2 6
56330 - 2 2 6 62 62 62 66 66 66 30 30 30
56331 - 10 10 10 0 0 0 0 0 0 0 0 0
56332 - 0 0 0 0 0 0 0 0 0 0 0 0
56333 - 0 0 0 0 0 0 0 0 0 0 0 0
56334 - 0 0 0 0 0 0 0 0 0 0 0 0
56335 - 0 0 0 0 0 0 0 0 0 0 0 0
56336 - 0 0 0 0 0 0 0 0 0 0 0 0
56337 - 0 0 0 0 0 0 0 0 0 0 0 0
56338 - 0 0 0 0 0 0 0 0 0 0 0 0
56339 - 0 0 0 0 0 0 0 0 0 0 0 0
56340 - 14 14 14 42 42 42 82 82 82 18 18 18
56341 - 2 2 6 2 2 6 2 2 6 10 10 10
56342 - 94 94 94 182 182 182 218 218 218 242 242 242
56343 -250 250 250 253 253 253 253 253 253 250 250 250
56344 -234 234 234 253 253 253 253 253 253 253 253 253
56345 -253 253 253 253 253 253 253 253 253 246 246 246
56346 -238 238 238 226 226 226 210 210 210 202 202 202
56347 -195 195 195 195 195 195 210 210 210 158 158 158
56348 - 6 6 6 14 14 14 50 50 50 14 14 14
56349 - 2 2 6 2 2 6 2 2 6 2 2 6
56350 - 2 2 6 6 6 6 86 86 86 46 46 46
56351 - 18 18 18 6 6 6 0 0 0 0 0 0
56352 - 0 0 0 0 0 0 0 0 0 0 0 0
56353 - 0 0 0 0 0 0 0 0 0 0 0 0
56354 - 0 0 0 0 0 0 0 0 0 0 0 0
56355 - 0 0 0 0 0 0 0 0 0 0 0 0
56356 - 0 0 0 0 0 0 0 0 0 0 0 0
56357 - 0 0 0 0 0 0 0 0 0 0 0 0
56358 - 0 0 0 0 0 0 0 0 0 0 0 0
56359 - 0 0 0 0 0 0 0 0 0 6 6 6
56360 - 22 22 22 54 54 54 70 70 70 2 2 6
56361 - 2 2 6 10 10 10 2 2 6 22 22 22
56362 -166 166 166 231 231 231 250 250 250 253 253 253
56363 -253 253 253 253 253 253 253 253 253 250 250 250
56364 -242 242 242 253 253 253 253 253 253 253 253 253
56365 -253 253 253 253 253 253 253 253 253 253 253 253
56366 -253 253 253 253 253 253 253 253 253 246 246 246
56367 -231 231 231 206 206 206 198 198 198 226 226 226
56368 - 94 94 94 2 2 6 6 6 6 38 38 38
56369 - 30 30 30 2 2 6 2 2 6 2 2 6
56370 - 2 2 6 2 2 6 62 62 62 66 66 66
56371 - 26 26 26 10 10 10 0 0 0 0 0 0
56372 - 0 0 0 0 0 0 0 0 0 0 0 0
56373 - 0 0 0 0 0 0 0 0 0 0 0 0
56374 - 0 0 0 0 0 0 0 0 0 0 0 0
56375 - 0 0 0 0 0 0 0 0 0 0 0 0
56376 - 0 0 0 0 0 0 0 0 0 0 0 0
56377 - 0 0 0 0 0 0 0 0 0 0 0 0
56378 - 0 0 0 0 0 0 0 0 0 0 0 0
56379 - 0 0 0 0 0 0 0 0 0 10 10 10
56380 - 30 30 30 74 74 74 50 50 50 2 2 6
56381 - 26 26 26 26 26 26 2 2 6 106 106 106
56382 -238 238 238 253 253 253 253 253 253 253 253 253
56383 -253 253 253 253 253 253 253 253 253 253 253 253
56384 -253 253 253 253 253 253 253 253 253 253 253 253
56385 -253 253 253 253 253 253 253 253 253 253 253 253
56386 -253 253 253 253 253 253 253 253 253 253 253 253
56387 -253 253 253 246 246 246 218 218 218 202 202 202
56388 -210 210 210 14 14 14 2 2 6 2 2 6
56389 - 30 30 30 22 22 22 2 2 6 2 2 6
56390 - 2 2 6 2 2 6 18 18 18 86 86 86
56391 - 42 42 42 14 14 14 0 0 0 0 0 0
56392 - 0 0 0 0 0 0 0 0 0 0 0 0
56393 - 0 0 0 0 0 0 0 0 0 0 0 0
56394 - 0 0 0 0 0 0 0 0 0 0 0 0
56395 - 0 0 0 0 0 0 0 0 0 0 0 0
56396 - 0 0 0 0 0 0 0 0 0 0 0 0
56397 - 0 0 0 0 0 0 0 0 0 0 0 0
56398 - 0 0 0 0 0 0 0 0 0 0 0 0
56399 - 0 0 0 0 0 0 0 0 0 14 14 14
56400 - 42 42 42 90 90 90 22 22 22 2 2 6
56401 - 42 42 42 2 2 6 18 18 18 218 218 218
56402 -253 253 253 253 253 253 253 253 253 253 253 253
56403 -253 253 253 253 253 253 253 253 253 253 253 253
56404 -253 253 253 253 253 253 253 253 253 253 253 253
56405 -253 253 253 253 253 253 253 253 253 253 253 253
56406 -253 253 253 253 253 253 253 253 253 253 253 253
56407 -253 253 253 253 253 253 250 250 250 221 221 221
56408 -218 218 218 101 101 101 2 2 6 14 14 14
56409 - 18 18 18 38 38 38 10 10 10 2 2 6
56410 - 2 2 6 2 2 6 2 2 6 78 78 78
56411 - 58 58 58 22 22 22 6 6 6 0 0 0
56412 - 0 0 0 0 0 0 0 0 0 0 0 0
56413 - 0 0 0 0 0 0 0 0 0 0 0 0
56414 - 0 0 0 0 0 0 0 0 0 0 0 0
56415 - 0 0 0 0 0 0 0 0 0 0 0 0
56416 - 0 0 0 0 0 0 0 0 0 0 0 0
56417 - 0 0 0 0 0 0 0 0 0 0 0 0
56418 - 0 0 0 0 0 0 0 0 0 0 0 0
56419 - 0 0 0 0 0 0 6 6 6 18 18 18
56420 - 54 54 54 82 82 82 2 2 6 26 26 26
56421 - 22 22 22 2 2 6 123 123 123 253 253 253
56422 -253 253 253 253 253 253 253 253 253 253 253 253
56423 -253 253 253 253 253 253 253 253 253 253 253 253
56424 -253 253 253 253 253 253 253 253 253 253 253 253
56425 -253 253 253 253 253 253 253 253 253 253 253 253
56426 -253 253 253 253 253 253 253 253 253 253 253 253
56427 -253 253 253 253 253 253 253 253 253 250 250 250
56428 -238 238 238 198 198 198 6 6 6 38 38 38
56429 - 58 58 58 26 26 26 38 38 38 2 2 6
56430 - 2 2 6 2 2 6 2 2 6 46 46 46
56431 - 78 78 78 30 30 30 10 10 10 0 0 0
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 0 0 0 0 0 0
56435 - 0 0 0 0 0 0 0 0 0 0 0 0
56436 - 0 0 0 0 0 0 0 0 0 0 0 0
56437 - 0 0 0 0 0 0 0 0 0 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 0 0 0
56439 - 0 0 0 0 0 0 10 10 10 30 30 30
56440 - 74 74 74 58 58 58 2 2 6 42 42 42
56441 - 2 2 6 22 22 22 231 231 231 253 253 253
56442 -253 253 253 253 253 253 253 253 253 253 253 253
56443 -253 253 253 253 253 253 253 253 253 250 250 250
56444 -253 253 253 253 253 253 253 253 253 253 253 253
56445 -253 253 253 253 253 253 253 253 253 253 253 253
56446 -253 253 253 253 253 253 253 253 253 253 253 253
56447 -253 253 253 253 253 253 253 253 253 253 253 253
56448 -253 253 253 246 246 246 46 46 46 38 38 38
56449 - 42 42 42 14 14 14 38 38 38 14 14 14
56450 - 2 2 6 2 2 6 2 2 6 6 6 6
56451 - 86 86 86 46 46 46 14 14 14 0 0 0
56452 - 0 0 0 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 0 0 0 0 0 0 0 0 0
56455 - 0 0 0 0 0 0 0 0 0 0 0 0
56456 - 0 0 0 0 0 0 0 0 0 0 0 0
56457 - 0 0 0 0 0 0 0 0 0 0 0 0
56458 - 0 0 0 0 0 0 0 0 0 0 0 0
56459 - 0 0 0 6 6 6 14 14 14 42 42 42
56460 - 90 90 90 18 18 18 18 18 18 26 26 26
56461 - 2 2 6 116 116 116 253 253 253 253 253 253
56462 -253 253 253 253 253 253 253 253 253 253 253 253
56463 -253 253 253 253 253 253 250 250 250 238 238 238
56464 -253 253 253 253 253 253 253 253 253 253 253 253
56465 -253 253 253 253 253 253 253 253 253 253 253 253
56466 -253 253 253 253 253 253 253 253 253 253 253 253
56467 -253 253 253 253 253 253 253 253 253 253 253 253
56468 -253 253 253 253 253 253 94 94 94 6 6 6
56469 - 2 2 6 2 2 6 10 10 10 34 34 34
56470 - 2 2 6 2 2 6 2 2 6 2 2 6
56471 - 74 74 74 58 58 58 22 22 22 6 6 6
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 0 0 0 0 0 0 0 0 0 0 0 0
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 0 0 0 10 10 10 26 26 26 66 66 66
56480 - 82 82 82 2 2 6 38 38 38 6 6 6
56481 - 14 14 14 210 210 210 253 253 253 253 253 253
56482 -253 253 253 253 253 253 253 253 253 253 253 253
56483 -253 253 253 253 253 253 246 246 246 242 242 242
56484 -253 253 253 253 253 253 253 253 253 253 253 253
56485 -253 253 253 253 253 253 253 253 253 253 253 253
56486 -253 253 253 253 253 253 253 253 253 253 253 253
56487 -253 253 253 253 253 253 253 253 253 253 253 253
56488 -253 253 253 253 253 253 144 144 144 2 2 6
56489 - 2 2 6 2 2 6 2 2 6 46 46 46
56490 - 2 2 6 2 2 6 2 2 6 2 2 6
56491 - 42 42 42 74 74 74 30 30 30 10 10 10
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 0 0 0 0 0 0 0 0 0
56497 - 0 0 0 0 0 0 0 0 0 0 0 0
56498 - 0 0 0 0 0 0 0 0 0 0 0 0
56499 - 6 6 6 14 14 14 42 42 42 90 90 90
56500 - 26 26 26 6 6 6 42 42 42 2 2 6
56501 - 74 74 74 250 250 250 253 253 253 253 253 253
56502 -253 253 253 253 253 253 253 253 253 253 253 253
56503 -253 253 253 253 253 253 242 242 242 242 242 242
56504 -253 253 253 253 253 253 253 253 253 253 253 253
56505 -253 253 253 253 253 253 253 253 253 253 253 253
56506 -253 253 253 253 253 253 253 253 253 253 253 253
56507 -253 253 253 253 253 253 253 253 253 253 253 253
56508 -253 253 253 253 253 253 182 182 182 2 2 6
56509 - 2 2 6 2 2 6 2 2 6 46 46 46
56510 - 2 2 6 2 2 6 2 2 6 2 2 6
56511 - 10 10 10 86 86 86 38 38 38 10 10 10
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 0 0 0 0 0 0 0 0 0 0 0 0
56517 - 0 0 0 0 0 0 0 0 0 0 0 0
56518 - 0 0 0 0 0 0 0 0 0 0 0 0
56519 - 10 10 10 26 26 26 66 66 66 82 82 82
56520 - 2 2 6 22 22 22 18 18 18 2 2 6
56521 -149 149 149 253 253 253 253 253 253 253 253 253
56522 -253 253 253 253 253 253 253 253 253 253 253 253
56523 -253 253 253 253 253 253 234 234 234 242 242 242
56524 -253 253 253 253 253 253 253 253 253 253 253 253
56525 -253 253 253 253 253 253 253 253 253 253 253 253
56526 -253 253 253 253 253 253 253 253 253 253 253 253
56527 -253 253 253 253 253 253 253 253 253 253 253 253
56528 -253 253 253 253 253 253 206 206 206 2 2 6
56529 - 2 2 6 2 2 6 2 2 6 38 38 38
56530 - 2 2 6 2 2 6 2 2 6 2 2 6
56531 - 6 6 6 86 86 86 46 46 46 14 14 14
56532 - 0 0 0 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 0 0 0
56536 - 0 0 0 0 0 0 0 0 0 0 0 0
56537 - 0 0 0 0 0 0 0 0 0 0 0 0
56538 - 0 0 0 0 0 0 0 0 0 6 6 6
56539 - 18 18 18 46 46 46 86 86 86 18 18 18
56540 - 2 2 6 34 34 34 10 10 10 6 6 6
56541 -210 210 210 253 253 253 253 253 253 253 253 253
56542 -253 253 253 253 253 253 253 253 253 253 253 253
56543 -253 253 253 253 253 253 234 234 234 242 242 242
56544 -253 253 253 253 253 253 253 253 253 253 253 253
56545 -253 253 253 253 253 253 253 253 253 253 253 253
56546 -253 253 253 253 253 253 253 253 253 253 253 253
56547 -253 253 253 253 253 253 253 253 253 253 253 253
56548 -253 253 253 253 253 253 221 221 221 6 6 6
56549 - 2 2 6 2 2 6 6 6 6 30 30 30
56550 - 2 2 6 2 2 6 2 2 6 2 2 6
56551 - 2 2 6 82 82 82 54 54 54 18 18 18
56552 - 6 6 6 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 0 0 0 0 0 0
56556 - 0 0 0 0 0 0 0 0 0 0 0 0
56557 - 0 0 0 0 0 0 0 0 0 0 0 0
56558 - 0 0 0 0 0 0 0 0 0 10 10 10
56559 - 26 26 26 66 66 66 62 62 62 2 2 6
56560 - 2 2 6 38 38 38 10 10 10 26 26 26
56561 -238 238 238 253 253 253 253 253 253 253 253 253
56562 -253 253 253 253 253 253 253 253 253 253 253 253
56563 -253 253 253 253 253 253 231 231 231 238 238 238
56564 -253 253 253 253 253 253 253 253 253 253 253 253
56565 -253 253 253 253 253 253 253 253 253 253 253 253
56566 -253 253 253 253 253 253 253 253 253 253 253 253
56567 -253 253 253 253 253 253 253 253 253 253 253 253
56568 -253 253 253 253 253 253 231 231 231 6 6 6
56569 - 2 2 6 2 2 6 10 10 10 30 30 30
56570 - 2 2 6 2 2 6 2 2 6 2 2 6
56571 - 2 2 6 66 66 66 58 58 58 22 22 22
56572 - 6 6 6 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 0 0 0 0 0 0 0 0 0
56576 - 0 0 0 0 0 0 0 0 0 0 0 0
56577 - 0 0 0 0 0 0 0 0 0 0 0 0
56578 - 0 0 0 0 0 0 0 0 0 10 10 10
56579 - 38 38 38 78 78 78 6 6 6 2 2 6
56580 - 2 2 6 46 46 46 14 14 14 42 42 42
56581 -246 246 246 253 253 253 253 253 253 253 253 253
56582 -253 253 253 253 253 253 253 253 253 253 253 253
56583 -253 253 253 253 253 253 231 231 231 242 242 242
56584 -253 253 253 253 253 253 253 253 253 253 253 253
56585 -253 253 253 253 253 253 253 253 253 253 253 253
56586 -253 253 253 253 253 253 253 253 253 253 253 253
56587 -253 253 253 253 253 253 253 253 253 253 253 253
56588 -253 253 253 253 253 253 234 234 234 10 10 10
56589 - 2 2 6 2 2 6 22 22 22 14 14 14
56590 - 2 2 6 2 2 6 2 2 6 2 2 6
56591 - 2 2 6 66 66 66 62 62 62 22 22 22
56592 - 6 6 6 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 0 0 0 0 0 0 0 0 0 0 0 0
56596 - 0 0 0 0 0 0 0 0 0 0 0 0
56597 - 0 0 0 0 0 0 0 0 0 0 0 0
56598 - 0 0 0 0 0 0 6 6 6 18 18 18
56599 - 50 50 50 74 74 74 2 2 6 2 2 6
56600 - 14 14 14 70 70 70 34 34 34 62 62 62
56601 -250 250 250 253 253 253 253 253 253 253 253 253
56602 -253 253 253 253 253 253 253 253 253 253 253 253
56603 -253 253 253 253 253 253 231 231 231 246 246 246
56604 -253 253 253 253 253 253 253 253 253 253 253 253
56605 -253 253 253 253 253 253 253 253 253 253 253 253
56606 -253 253 253 253 253 253 253 253 253 253 253 253
56607 -253 253 253 253 253 253 253 253 253 253 253 253
56608 -253 253 253 253 253 253 234 234 234 14 14 14
56609 - 2 2 6 2 2 6 30 30 30 2 2 6
56610 - 2 2 6 2 2 6 2 2 6 2 2 6
56611 - 2 2 6 66 66 66 62 62 62 22 22 22
56612 - 6 6 6 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 0 0 0 0 0 0 0 0 0 0 0 0
56616 - 0 0 0 0 0 0 0 0 0 0 0 0
56617 - 0 0 0 0 0 0 0 0 0 0 0 0
56618 - 0 0 0 0 0 0 6 6 6 18 18 18
56619 - 54 54 54 62 62 62 2 2 6 2 2 6
56620 - 2 2 6 30 30 30 46 46 46 70 70 70
56621 -250 250 250 253 253 253 253 253 253 253 253 253
56622 -253 253 253 253 253 253 253 253 253 253 253 253
56623 -253 253 253 253 253 253 231 231 231 246 246 246
56624 -253 253 253 253 253 253 253 253 253 253 253 253
56625 -253 253 253 253 253 253 253 253 253 253 253 253
56626 -253 253 253 253 253 253 253 253 253 253 253 253
56627 -253 253 253 253 253 253 253 253 253 253 253 253
56628 -253 253 253 253 253 253 226 226 226 10 10 10
56629 - 2 2 6 6 6 6 30 30 30 2 2 6
56630 - 2 2 6 2 2 6 2 2 6 2 2 6
56631 - 2 2 6 66 66 66 58 58 58 22 22 22
56632 - 6 6 6 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 0 0 0 0 0 0 0 0 0 0 0 0
56636 - 0 0 0 0 0 0 0 0 0 0 0 0
56637 - 0 0 0 0 0 0 0 0 0 0 0 0
56638 - 0 0 0 0 0 0 6 6 6 22 22 22
56639 - 58 58 58 62 62 62 2 2 6 2 2 6
56640 - 2 2 6 2 2 6 30 30 30 78 78 78
56641 -250 250 250 253 253 253 253 253 253 253 253 253
56642 -253 253 253 253 253 253 253 253 253 253 253 253
56643 -253 253 253 253 253 253 231 231 231 246 246 246
56644 -253 253 253 253 253 253 253 253 253 253 253 253
56645 -253 253 253 253 253 253 253 253 253 253 253 253
56646 -253 253 253 253 253 253 253 253 253 253 253 253
56647 -253 253 253 253 253 253 253 253 253 253 253 253
56648 -253 253 253 253 253 253 206 206 206 2 2 6
56649 - 22 22 22 34 34 34 18 14 6 22 22 22
56650 - 26 26 26 18 18 18 6 6 6 2 2 6
56651 - 2 2 6 82 82 82 54 54 54 18 18 18
56652 - 6 6 6 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 0 0 0
56655 - 0 0 0 0 0 0 0 0 0 0 0 0
56656 - 0 0 0 0 0 0 0 0 0 0 0 0
56657 - 0 0 0 0 0 0 0 0 0 0 0 0
56658 - 0 0 0 0 0 0 6 6 6 26 26 26
56659 - 62 62 62 106 106 106 74 54 14 185 133 11
56660 -210 162 10 121 92 8 6 6 6 62 62 62
56661 -238 238 238 253 253 253 253 253 253 253 253 253
56662 -253 253 253 253 253 253 253 253 253 253 253 253
56663 -253 253 253 253 253 253 231 231 231 246 246 246
56664 -253 253 253 253 253 253 253 253 253 253 253 253
56665 -253 253 253 253 253 253 253 253 253 253 253 253
56666 -253 253 253 253 253 253 253 253 253 253 253 253
56667 -253 253 253 253 253 253 253 253 253 253 253 253
56668 -253 253 253 253 253 253 158 158 158 18 18 18
56669 - 14 14 14 2 2 6 2 2 6 2 2 6
56670 - 6 6 6 18 18 18 66 66 66 38 38 38
56671 - 6 6 6 94 94 94 50 50 50 18 18 18
56672 - 6 6 6 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 0 0 0
56674 - 0 0 0 0 0 0 0 0 0 0 0 0
56675 - 0 0 0 0 0 0 0 0 0 0 0 0
56676 - 0 0 0 0 0 0 0 0 0 0 0 0
56677 - 0 0 0 0 0 0 0 0 0 6 6 6
56678 - 10 10 10 10 10 10 18 18 18 38 38 38
56679 - 78 78 78 142 134 106 216 158 10 242 186 14
56680 -246 190 14 246 190 14 156 118 10 10 10 10
56681 - 90 90 90 238 238 238 253 253 253 253 253 253
56682 -253 253 253 253 253 253 253 253 253 253 253 253
56683 -253 253 253 253 253 253 231 231 231 250 250 250
56684 -253 253 253 253 253 253 253 253 253 253 253 253
56685 -253 253 253 253 253 253 253 253 253 253 253 253
56686 -253 253 253 253 253 253 253 253 253 253 253 253
56687 -253 253 253 253 253 253 253 253 253 246 230 190
56688 -238 204 91 238 204 91 181 142 44 37 26 9
56689 - 2 2 6 2 2 6 2 2 6 2 2 6
56690 - 2 2 6 2 2 6 38 38 38 46 46 46
56691 - 26 26 26 106 106 106 54 54 54 18 18 18
56692 - 6 6 6 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 0 0 0
56694 - 0 0 0 0 0 0 0 0 0 0 0 0
56695 - 0 0 0 0 0 0 0 0 0 0 0 0
56696 - 0 0 0 0 0 0 0 0 0 0 0 0
56697 - 0 0 0 6 6 6 14 14 14 22 22 22
56698 - 30 30 30 38 38 38 50 50 50 70 70 70
56699 -106 106 106 190 142 34 226 170 11 242 186 14
56700 -246 190 14 246 190 14 246 190 14 154 114 10
56701 - 6 6 6 74 74 74 226 226 226 253 253 253
56702 -253 253 253 253 253 253 253 253 253 253 253 253
56703 -253 253 253 253 253 253 231 231 231 250 250 250
56704 -253 253 253 253 253 253 253 253 253 253 253 253
56705 -253 253 253 253 253 253 253 253 253 253 253 253
56706 -253 253 253 253 253 253 253 253 253 253 253 253
56707 -253 253 253 253 253 253 253 253 253 228 184 62
56708 -241 196 14 241 208 19 232 195 16 38 30 10
56709 - 2 2 6 2 2 6 2 2 6 2 2 6
56710 - 2 2 6 6 6 6 30 30 30 26 26 26
56711 -203 166 17 154 142 90 66 66 66 26 26 26
56712 - 6 6 6 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 0 0 0
56714 - 0 0 0 0 0 0 0 0 0 0 0 0
56715 - 0 0 0 0 0 0 0 0 0 0 0 0
56716 - 0 0 0 0 0 0 0 0 0 0 0 0
56717 - 6 6 6 18 18 18 38 38 38 58 58 58
56718 - 78 78 78 86 86 86 101 101 101 123 123 123
56719 -175 146 61 210 150 10 234 174 13 246 186 14
56720 -246 190 14 246 190 14 246 190 14 238 190 10
56721 -102 78 10 2 2 6 46 46 46 198 198 198
56722 -253 253 253 253 253 253 253 253 253 253 253 253
56723 -253 253 253 253 253 253 234 234 234 242 242 242
56724 -253 253 253 253 253 253 253 253 253 253 253 253
56725 -253 253 253 253 253 253 253 253 253 253 253 253
56726 -253 253 253 253 253 253 253 253 253 253 253 253
56727 -253 253 253 253 253 253 253 253 253 224 178 62
56728 -242 186 14 241 196 14 210 166 10 22 18 6
56729 - 2 2 6 2 2 6 2 2 6 2 2 6
56730 - 2 2 6 2 2 6 6 6 6 121 92 8
56731 -238 202 15 232 195 16 82 82 82 34 34 34
56732 - 10 10 10 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 0 0 0
56734 - 0 0 0 0 0 0 0 0 0 0 0 0
56735 - 0 0 0 0 0 0 0 0 0 0 0 0
56736 - 0 0 0 0 0 0 0 0 0 0 0 0
56737 - 14 14 14 38 38 38 70 70 70 154 122 46
56738 -190 142 34 200 144 11 197 138 11 197 138 11
56739 -213 154 11 226 170 11 242 186 14 246 190 14
56740 -246 190 14 246 190 14 246 190 14 246 190 14
56741 -225 175 15 46 32 6 2 2 6 22 22 22
56742 -158 158 158 250 250 250 253 253 253 253 253 253
56743 -253 253 253 253 253 253 253 253 253 253 253 253
56744 -253 253 253 253 253 253 253 253 253 253 253 253
56745 -253 253 253 253 253 253 253 253 253 253 253 253
56746 -253 253 253 253 253 253 253 253 253 253 253 253
56747 -253 253 253 250 250 250 242 242 242 224 178 62
56748 -239 182 13 236 186 11 213 154 11 46 32 6
56749 - 2 2 6 2 2 6 2 2 6 2 2 6
56750 - 2 2 6 2 2 6 61 42 6 225 175 15
56751 -238 190 10 236 186 11 112 100 78 42 42 42
56752 - 14 14 14 0 0 0 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 0 0 0 6 6 6
56757 - 22 22 22 54 54 54 154 122 46 213 154 11
56758 -226 170 11 230 174 11 226 170 11 226 170 11
56759 -236 178 12 242 186 14 246 190 14 246 190 14
56760 -246 190 14 246 190 14 246 190 14 246 190 14
56761 -241 196 14 184 144 12 10 10 10 2 2 6
56762 - 6 6 6 116 116 116 242 242 242 253 253 253
56763 -253 253 253 253 253 253 253 253 253 253 253 253
56764 -253 253 253 253 253 253 253 253 253 253 253 253
56765 -253 253 253 253 253 253 253 253 253 253 253 253
56766 -253 253 253 253 253 253 253 253 253 253 253 253
56767 -253 253 253 231 231 231 198 198 198 214 170 54
56768 -236 178 12 236 178 12 210 150 10 137 92 6
56769 - 18 14 6 2 2 6 2 2 6 2 2 6
56770 - 6 6 6 70 47 6 200 144 11 236 178 12
56771 -239 182 13 239 182 13 124 112 88 58 58 58
56772 - 22 22 22 6 6 6 0 0 0 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 0 0 0 0 0 0 10 10 10
56777 - 30 30 30 70 70 70 180 133 36 226 170 11
56778 -239 182 13 242 186 14 242 186 14 246 186 14
56779 -246 190 14 246 190 14 246 190 14 246 190 14
56780 -246 190 14 246 190 14 246 190 14 246 190 14
56781 -246 190 14 232 195 16 98 70 6 2 2 6
56782 - 2 2 6 2 2 6 66 66 66 221 221 221
56783 -253 253 253 253 253 253 253 253 253 253 253 253
56784 -253 253 253 253 253 253 253 253 253 253 253 253
56785 -253 253 253 253 253 253 253 253 253 253 253 253
56786 -253 253 253 253 253 253 253 253 253 253 253 253
56787 -253 253 253 206 206 206 198 198 198 214 166 58
56788 -230 174 11 230 174 11 216 158 10 192 133 9
56789 -163 110 8 116 81 8 102 78 10 116 81 8
56790 -167 114 7 197 138 11 226 170 11 239 182 13
56791 -242 186 14 242 186 14 162 146 94 78 78 78
56792 - 34 34 34 14 14 14 6 6 6 0 0 0
56793 - 0 0 0 0 0 0 0 0 0 0 0 0
56794 - 0 0 0 0 0 0 0 0 0 0 0 0
56795 - 0 0 0 0 0 0 0 0 0 0 0 0
56796 - 0 0 0 0 0 0 0 0 0 6 6 6
56797 - 30 30 30 78 78 78 190 142 34 226 170 11
56798 -239 182 13 246 190 14 246 190 14 246 190 14
56799 -246 190 14 246 190 14 246 190 14 246 190 14
56800 -246 190 14 246 190 14 246 190 14 246 190 14
56801 -246 190 14 241 196 14 203 166 17 22 18 6
56802 - 2 2 6 2 2 6 2 2 6 38 38 38
56803 -218 218 218 253 253 253 253 253 253 253 253 253
56804 -253 253 253 253 253 253 253 253 253 253 253 253
56805 -253 253 253 253 253 253 253 253 253 253 253 253
56806 -253 253 253 253 253 253 253 253 253 253 253 253
56807 -250 250 250 206 206 206 198 198 198 202 162 69
56808 -226 170 11 236 178 12 224 166 10 210 150 10
56809 -200 144 11 197 138 11 192 133 9 197 138 11
56810 -210 150 10 226 170 11 242 186 14 246 190 14
56811 -246 190 14 246 186 14 225 175 15 124 112 88
56812 - 62 62 62 30 30 30 14 14 14 6 6 6
56813 - 0 0 0 0 0 0 0 0 0 0 0 0
56814 - 0 0 0 0 0 0 0 0 0 0 0 0
56815 - 0 0 0 0 0 0 0 0 0 0 0 0
56816 - 0 0 0 0 0 0 0 0 0 10 10 10
56817 - 30 30 30 78 78 78 174 135 50 224 166 10
56818 -239 182 13 246 190 14 246 190 14 246 190 14
56819 -246 190 14 246 190 14 246 190 14 246 190 14
56820 -246 190 14 246 190 14 246 190 14 246 190 14
56821 -246 190 14 246 190 14 241 196 14 139 102 15
56822 - 2 2 6 2 2 6 2 2 6 2 2 6
56823 - 78 78 78 250 250 250 253 253 253 253 253 253
56824 -253 253 253 253 253 253 253 253 253 253 253 253
56825 -253 253 253 253 253 253 253 253 253 253 253 253
56826 -253 253 253 253 253 253 253 253 253 253 253 253
56827 -250 250 250 214 214 214 198 198 198 190 150 46
56828 -219 162 10 236 178 12 234 174 13 224 166 10
56829 -216 158 10 213 154 11 213 154 11 216 158 10
56830 -226 170 11 239 182 13 246 190 14 246 190 14
56831 -246 190 14 246 190 14 242 186 14 206 162 42
56832 -101 101 101 58 58 58 30 30 30 14 14 14
56833 - 6 6 6 0 0 0 0 0 0 0 0 0
56834 - 0 0 0 0 0 0 0 0 0 0 0 0
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 0 0 0 0 0 0 0 0 0 10 10 10
56837 - 30 30 30 74 74 74 174 135 50 216 158 10
56838 -236 178 12 246 190 14 246 190 14 246 190 14
56839 -246 190 14 246 190 14 246 190 14 246 190 14
56840 -246 190 14 246 190 14 246 190 14 246 190 14
56841 -246 190 14 246 190 14 241 196 14 226 184 13
56842 - 61 42 6 2 2 6 2 2 6 2 2 6
56843 - 22 22 22 238 238 238 253 253 253 253 253 253
56844 -253 253 253 253 253 253 253 253 253 253 253 253
56845 -253 253 253 253 253 253 253 253 253 253 253 253
56846 -253 253 253 253 253 253 253 253 253 253 253 253
56847 -253 253 253 226 226 226 187 187 187 180 133 36
56848 -216 158 10 236 178 12 239 182 13 236 178 12
56849 -230 174 11 226 170 11 226 170 11 230 174 11
56850 -236 178 12 242 186 14 246 190 14 246 190 14
56851 -246 190 14 246 190 14 246 186 14 239 182 13
56852 -206 162 42 106 106 106 66 66 66 34 34 34
56853 - 14 14 14 6 6 6 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 0 0 0
56855 - 0 0 0 0 0 0 0 0 0 0 0 0
56856 - 0 0 0 0 0 0 0 0 0 6 6 6
56857 - 26 26 26 70 70 70 163 133 67 213 154 11
56858 -236 178 12 246 190 14 246 190 14 246 190 14
56859 -246 190 14 246 190 14 246 190 14 246 190 14
56860 -246 190 14 246 190 14 246 190 14 246 190 14
56861 -246 190 14 246 190 14 246 190 14 241 196 14
56862 -190 146 13 18 14 6 2 2 6 2 2 6
56863 - 46 46 46 246 246 246 253 253 253 253 253 253
56864 -253 253 253 253 253 253 253 253 253 253 253 253
56865 -253 253 253 253 253 253 253 253 253 253 253 253
56866 -253 253 253 253 253 253 253 253 253 253 253 253
56867 -253 253 253 221 221 221 86 86 86 156 107 11
56868 -216 158 10 236 178 12 242 186 14 246 186 14
56869 -242 186 14 239 182 13 239 182 13 242 186 14
56870 -242 186 14 246 186 14 246 190 14 246 190 14
56871 -246 190 14 246 190 14 246 190 14 246 190 14
56872 -242 186 14 225 175 15 142 122 72 66 66 66
56873 - 30 30 30 10 10 10 0 0 0 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 0 0 0
56875 - 0 0 0 0 0 0 0 0 0 0 0 0
56876 - 0 0 0 0 0 0 0 0 0 6 6 6
56877 - 26 26 26 70 70 70 163 133 67 210 150 10
56878 -236 178 12 246 190 14 246 190 14 246 190 14
56879 -246 190 14 246 190 14 246 190 14 246 190 14
56880 -246 190 14 246 190 14 246 190 14 246 190 14
56881 -246 190 14 246 190 14 246 190 14 246 190 14
56882 -232 195 16 121 92 8 34 34 34 106 106 106
56883 -221 221 221 253 253 253 253 253 253 253 253 253
56884 -253 253 253 253 253 253 253 253 253 253 253 253
56885 -253 253 253 253 253 253 253 253 253 253 253 253
56886 -253 253 253 253 253 253 253 253 253 253 253 253
56887 -242 242 242 82 82 82 18 14 6 163 110 8
56888 -216 158 10 236 178 12 242 186 14 246 190 14
56889 -246 190 14 246 190 14 246 190 14 246 190 14
56890 -246 190 14 246 190 14 246 190 14 246 190 14
56891 -246 190 14 246 190 14 246 190 14 246 190 14
56892 -246 190 14 246 190 14 242 186 14 163 133 67
56893 - 46 46 46 18 18 18 6 6 6 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 0 0 0 0 0 0 0 10 10 10
56897 - 30 30 30 78 78 78 163 133 67 210 150 10
56898 -236 178 12 246 186 14 246 190 14 246 190 14
56899 -246 190 14 246 190 14 246 190 14 246 190 14
56900 -246 190 14 246 190 14 246 190 14 246 190 14
56901 -246 190 14 246 190 14 246 190 14 246 190 14
56902 -241 196 14 215 174 15 190 178 144 253 253 253
56903 -253 253 253 253 253 253 253 253 253 253 253 253
56904 -253 253 253 253 253 253 253 253 253 253 253 253
56905 -253 253 253 253 253 253 253 253 253 253 253 253
56906 -253 253 253 253 253 253 253 253 253 218 218 218
56907 - 58 58 58 2 2 6 22 18 6 167 114 7
56908 -216 158 10 236 178 12 246 186 14 246 190 14
56909 -246 190 14 246 190 14 246 190 14 246 190 14
56910 -246 190 14 246 190 14 246 190 14 246 190 14
56911 -246 190 14 246 190 14 246 190 14 246 190 14
56912 -246 190 14 246 186 14 242 186 14 190 150 46
56913 - 54 54 54 22 22 22 6 6 6 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 0 0 0
56915 - 0 0 0 0 0 0 0 0 0 0 0 0
56916 - 0 0 0 0 0 0 0 0 0 14 14 14
56917 - 38 38 38 86 86 86 180 133 36 213 154 11
56918 -236 178 12 246 186 14 246 190 14 246 190 14
56919 -246 190 14 246 190 14 246 190 14 246 190 14
56920 -246 190 14 246 190 14 246 190 14 246 190 14
56921 -246 190 14 246 190 14 246 190 14 246 190 14
56922 -246 190 14 232 195 16 190 146 13 214 214 214
56923 -253 253 253 253 253 253 253 253 253 253 253 253
56924 -253 253 253 253 253 253 253 253 253 253 253 253
56925 -253 253 253 253 253 253 253 253 253 253 253 253
56926 -253 253 253 250 250 250 170 170 170 26 26 26
56927 - 2 2 6 2 2 6 37 26 9 163 110 8
56928 -219 162 10 239 182 13 246 186 14 246 190 14
56929 -246 190 14 246 190 14 246 190 14 246 190 14
56930 -246 190 14 246 190 14 246 190 14 246 190 14
56931 -246 190 14 246 190 14 246 190 14 246 190 14
56932 -246 186 14 236 178 12 224 166 10 142 122 72
56933 - 46 46 46 18 18 18 6 6 6 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 0 0 0
56935 - 0 0 0 0 0 0 0 0 0 0 0 0
56936 - 0 0 0 0 0 0 6 6 6 18 18 18
56937 - 50 50 50 109 106 95 192 133 9 224 166 10
56938 -242 186 14 246 190 14 246 190 14 246 190 14
56939 -246 190 14 246 190 14 246 190 14 246 190 14
56940 -246 190 14 246 190 14 246 190 14 246 190 14
56941 -246 190 14 246 190 14 246 190 14 246 190 14
56942 -242 186 14 226 184 13 210 162 10 142 110 46
56943 -226 226 226 253 253 253 253 253 253 253 253 253
56944 -253 253 253 253 253 253 253 253 253 253 253 253
56945 -253 253 253 253 253 253 253 253 253 253 253 253
56946 -198 198 198 66 66 66 2 2 6 2 2 6
56947 - 2 2 6 2 2 6 50 34 6 156 107 11
56948 -219 162 10 239 182 13 246 186 14 246 190 14
56949 -246 190 14 246 190 14 246 190 14 246 190 14
56950 -246 190 14 246 190 14 246 190 14 246 190 14
56951 -246 190 14 246 190 14 246 190 14 242 186 14
56952 -234 174 13 213 154 11 154 122 46 66 66 66
56953 - 30 30 30 10 10 10 0 0 0 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 0 0 0
56955 - 0 0 0 0 0 0 0 0 0 0 0 0
56956 - 0 0 0 0 0 0 6 6 6 22 22 22
56957 - 58 58 58 154 121 60 206 145 10 234 174 13
56958 -242 186 14 246 186 14 246 190 14 246 190 14
56959 -246 190 14 246 190 14 246 190 14 246 190 14
56960 -246 190 14 246 190 14 246 190 14 246 190 14
56961 -246 190 14 246 190 14 246 190 14 246 190 14
56962 -246 186 14 236 178 12 210 162 10 163 110 8
56963 - 61 42 6 138 138 138 218 218 218 250 250 250
56964 -253 253 253 253 253 253 253 253 253 250 250 250
56965 -242 242 242 210 210 210 144 144 144 66 66 66
56966 - 6 6 6 2 2 6 2 2 6 2 2 6
56967 - 2 2 6 2 2 6 61 42 6 163 110 8
56968 -216 158 10 236 178 12 246 190 14 246 190 14
56969 -246 190 14 246 190 14 246 190 14 246 190 14
56970 -246 190 14 246 190 14 246 190 14 246 190 14
56971 -246 190 14 239 182 13 230 174 11 216 158 10
56972 -190 142 34 124 112 88 70 70 70 38 38 38
56973 - 18 18 18 6 6 6 0 0 0 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 0 0 0
56975 - 0 0 0 0 0 0 0 0 0 0 0 0
56976 - 0 0 0 0 0 0 6 6 6 22 22 22
56977 - 62 62 62 168 124 44 206 145 10 224 166 10
56978 -236 178 12 239 182 13 242 186 14 242 186 14
56979 -246 186 14 246 190 14 246 190 14 246 190 14
56980 -246 190 14 246 190 14 246 190 14 246 190 14
56981 -246 190 14 246 190 14 246 190 14 246 190 14
56982 -246 190 14 236 178 12 216 158 10 175 118 6
56983 - 80 54 7 2 2 6 6 6 6 30 30 30
56984 - 54 54 54 62 62 62 50 50 50 38 38 38
56985 - 14 14 14 2 2 6 2 2 6 2 2 6
56986 - 2 2 6 2 2 6 2 2 6 2 2 6
56987 - 2 2 6 6 6 6 80 54 7 167 114 7
56988 -213 154 11 236 178 12 246 190 14 246 190 14
56989 -246 190 14 246 190 14 246 190 14 246 190 14
56990 -246 190 14 242 186 14 239 182 13 239 182 13
56991 -230 174 11 210 150 10 174 135 50 124 112 88
56992 - 82 82 82 54 54 54 34 34 34 18 18 18
56993 - 6 6 6 0 0 0 0 0 0 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 0 0 0
56995 - 0 0 0 0 0 0 0 0 0 0 0 0
56996 - 0 0 0 0 0 0 6 6 6 18 18 18
56997 - 50 50 50 158 118 36 192 133 9 200 144 11
56998 -216 158 10 219 162 10 224 166 10 226 170 11
56999 -230 174 11 236 178 12 239 182 13 239 182 13
57000 -242 186 14 246 186 14 246 190 14 246 190 14
57001 -246 190 14 246 190 14 246 190 14 246 190 14
57002 -246 186 14 230 174 11 210 150 10 163 110 8
57003 -104 69 6 10 10 10 2 2 6 2 2 6
57004 - 2 2 6 2 2 6 2 2 6 2 2 6
57005 - 2 2 6 2 2 6 2 2 6 2 2 6
57006 - 2 2 6 2 2 6 2 2 6 2 2 6
57007 - 2 2 6 6 6 6 91 60 6 167 114 7
57008 -206 145 10 230 174 11 242 186 14 246 190 14
57009 -246 190 14 246 190 14 246 186 14 242 186 14
57010 -239 182 13 230 174 11 224 166 10 213 154 11
57011 -180 133 36 124 112 88 86 86 86 58 58 58
57012 - 38 38 38 22 22 22 10 10 10 6 6 6
57013 - 0 0 0 0 0 0 0 0 0 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 0 0 0
57015 - 0 0 0 0 0 0 0 0 0 0 0 0
57016 - 0 0 0 0 0 0 0 0 0 14 14 14
57017 - 34 34 34 70 70 70 138 110 50 158 118 36
57018 -167 114 7 180 123 7 192 133 9 197 138 11
57019 -200 144 11 206 145 10 213 154 11 219 162 10
57020 -224 166 10 230 174 11 239 182 13 242 186 14
57021 -246 186 14 246 186 14 246 186 14 246 186 14
57022 -239 182 13 216 158 10 185 133 11 152 99 6
57023 -104 69 6 18 14 6 2 2 6 2 2 6
57024 - 2 2 6 2 2 6 2 2 6 2 2 6
57025 - 2 2 6 2 2 6 2 2 6 2 2 6
57026 - 2 2 6 2 2 6 2 2 6 2 2 6
57027 - 2 2 6 6 6 6 80 54 7 152 99 6
57028 -192 133 9 219 162 10 236 178 12 239 182 13
57029 -246 186 14 242 186 14 239 182 13 236 178 12
57030 -224 166 10 206 145 10 192 133 9 154 121 60
57031 - 94 94 94 62 62 62 42 42 42 22 22 22
57032 - 14 14 14 6 6 6 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 0 0 0 0 0 0
57035 - 0 0 0 0 0 0 0 0 0 0 0 0
57036 - 0 0 0 0 0 0 0 0 0 6 6 6
57037 - 18 18 18 34 34 34 58 58 58 78 78 78
57038 -101 98 89 124 112 88 142 110 46 156 107 11
57039 -163 110 8 167 114 7 175 118 6 180 123 7
57040 -185 133 11 197 138 11 210 150 10 219 162 10
57041 -226 170 11 236 178 12 236 178 12 234 174 13
57042 -219 162 10 197 138 11 163 110 8 130 83 6
57043 - 91 60 6 10 10 10 2 2 6 2 2 6
57044 - 18 18 18 38 38 38 38 38 38 38 38 38
57045 - 38 38 38 38 38 38 38 38 38 38 38 38
57046 - 38 38 38 38 38 38 26 26 26 2 2 6
57047 - 2 2 6 6 6 6 70 47 6 137 92 6
57048 -175 118 6 200 144 11 219 162 10 230 174 11
57049 -234 174 13 230 174 11 219 162 10 210 150 10
57050 -192 133 9 163 110 8 124 112 88 82 82 82
57051 - 50 50 50 30 30 30 14 14 14 6 6 6
57052 - 0 0 0 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 0 0 0 0 0 0
57055 - 0 0 0 0 0 0 0 0 0 0 0 0
57056 - 0 0 0 0 0 0 0 0 0 0 0 0
57057 - 6 6 6 14 14 14 22 22 22 34 34 34
57058 - 42 42 42 58 58 58 74 74 74 86 86 86
57059 -101 98 89 122 102 70 130 98 46 121 87 25
57060 -137 92 6 152 99 6 163 110 8 180 123 7
57061 -185 133 11 197 138 11 206 145 10 200 144 11
57062 -180 123 7 156 107 11 130 83 6 104 69 6
57063 - 50 34 6 54 54 54 110 110 110 101 98 89
57064 - 86 86 86 82 82 82 78 78 78 78 78 78
57065 - 78 78 78 78 78 78 78 78 78 78 78 78
57066 - 78 78 78 82 82 82 86 86 86 94 94 94
57067 -106 106 106 101 101 101 86 66 34 124 80 6
57068 -156 107 11 180 123 7 192 133 9 200 144 11
57069 -206 145 10 200 144 11 192 133 9 175 118 6
57070 -139 102 15 109 106 95 70 70 70 42 42 42
57071 - 22 22 22 10 10 10 0 0 0 0 0 0
57072 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 0 0 0 0 0 0 0 0 0
57075 - 0 0 0 0 0 0 0 0 0 0 0 0
57076 - 0 0 0 0 0 0 0 0 0 0 0 0
57077 - 0 0 0 0 0 0 6 6 6 10 10 10
57078 - 14 14 14 22 22 22 30 30 30 38 38 38
57079 - 50 50 50 62 62 62 74 74 74 90 90 90
57080 -101 98 89 112 100 78 121 87 25 124 80 6
57081 -137 92 6 152 99 6 152 99 6 152 99 6
57082 -138 86 6 124 80 6 98 70 6 86 66 30
57083 -101 98 89 82 82 82 58 58 58 46 46 46
57084 - 38 38 38 34 34 34 34 34 34 34 34 34
57085 - 34 34 34 34 34 34 34 34 34 34 34 34
57086 - 34 34 34 34 34 34 38 38 38 42 42 42
57087 - 54 54 54 82 82 82 94 86 76 91 60 6
57088 -134 86 6 156 107 11 167 114 7 175 118 6
57089 -175 118 6 167 114 7 152 99 6 121 87 25
57090 -101 98 89 62 62 62 34 34 34 18 18 18
57091 - 6 6 6 0 0 0 0 0 0 0 0 0
57092 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 0 0 0 0 0 0 0 0 0 0 0 0
57095 - 0 0 0 0 0 0 0 0 0 0 0 0
57096 - 0 0 0 0 0 0 0 0 0 0 0 0
57097 - 0 0 0 0 0 0 0 0 0 0 0 0
57098 - 0 0 0 6 6 6 6 6 6 10 10 10
57099 - 18 18 18 22 22 22 30 30 30 42 42 42
57100 - 50 50 50 66 66 66 86 86 86 101 98 89
57101 -106 86 58 98 70 6 104 69 6 104 69 6
57102 -104 69 6 91 60 6 82 62 34 90 90 90
57103 - 62 62 62 38 38 38 22 22 22 14 14 14
57104 - 10 10 10 10 10 10 10 10 10 10 10 10
57105 - 10 10 10 10 10 10 6 6 6 10 10 10
57106 - 10 10 10 10 10 10 10 10 10 14 14 14
57107 - 22 22 22 42 42 42 70 70 70 89 81 66
57108 - 80 54 7 104 69 6 124 80 6 137 92 6
57109 -134 86 6 116 81 8 100 82 52 86 86 86
57110 - 58 58 58 30 30 30 14 14 14 6 6 6
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 0 0 0
57114 - 0 0 0 0 0 0 0 0 0 0 0 0
57115 - 0 0 0 0 0 0 0 0 0 0 0 0
57116 - 0 0 0 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 6 6 6 10 10 10 14 14 14
57120 - 18 18 18 26 26 26 38 38 38 54 54 54
57121 - 70 70 70 86 86 86 94 86 76 89 81 66
57122 - 89 81 66 86 86 86 74 74 74 50 50 50
57123 - 30 30 30 14 14 14 6 6 6 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 0 0 0 0 0 0 0 0 0
57126 - 0 0 0 0 0 0 0 0 0 0 0 0
57127 - 6 6 6 18 18 18 34 34 34 58 58 58
57128 - 82 82 82 89 81 66 89 81 66 89 81 66
57129 - 94 86 66 94 86 76 74 74 74 50 50 50
57130 - 26 26 26 14 14 14 6 6 6 0 0 0
57131 - 0 0 0 0 0 0 0 0 0 0 0 0
57132 - 0 0 0 0 0 0 0 0 0 0 0 0
57133 - 0 0 0 0 0 0 0 0 0 0 0 0
57134 - 0 0 0 0 0 0 0 0 0 0 0 0
57135 - 0 0 0 0 0 0 0 0 0 0 0 0
57136 - 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 0 0 0
57140 - 6 6 6 6 6 6 14 14 14 18 18 18
57141 - 30 30 30 38 38 38 46 46 46 54 54 54
57142 - 50 50 50 42 42 42 30 30 30 18 18 18
57143 - 10 10 10 0 0 0 0 0 0 0 0 0
57144 - 0 0 0 0 0 0 0 0 0 0 0 0
57145 - 0 0 0 0 0 0 0 0 0 0 0 0
57146 - 0 0 0 0 0 0 0 0 0 0 0 0
57147 - 0 0 0 6 6 6 14 14 14 26 26 26
57148 - 38 38 38 50 50 50 58 58 58 58 58 58
57149 - 54 54 54 42 42 42 30 30 30 18 18 18
57150 - 10 10 10 0 0 0 0 0 0 0 0 0
57151 - 0 0 0 0 0 0 0 0 0 0 0 0
57152 - 0 0 0 0 0 0 0 0 0 0 0 0
57153 - 0 0 0 0 0 0 0 0 0 0 0 0
57154 - 0 0 0 0 0 0 0 0 0 0 0 0
57155 - 0 0 0 0 0 0 0 0 0 0 0 0
57156 - 0 0 0 0 0 0 0 0 0 0 0 0
57157 - 0 0 0 0 0 0 0 0 0 0 0 0
57158 - 0 0 0 0 0 0 0 0 0 0 0 0
57159 - 0 0 0 0 0 0 0 0 0 0 0 0
57160 - 0 0 0 0 0 0 0 0 0 6 6 6
57161 - 6 6 6 10 10 10 14 14 14 18 18 18
57162 - 18 18 18 14 14 14 10 10 10 6 6 6
57163 - 0 0 0 0 0 0 0 0 0 0 0 0
57164 - 0 0 0 0 0 0 0 0 0 0 0 0
57165 - 0 0 0 0 0 0 0 0 0 0 0 0
57166 - 0 0 0 0 0 0 0 0 0 0 0 0
57167 - 0 0 0 0 0 0 0 0 0 6 6 6
57168 - 14 14 14 18 18 18 22 22 22 22 22 22
57169 - 18 18 18 14 14 14 10 10 10 6 6 6
57170 - 0 0 0 0 0 0 0 0 0 0 0 0
57171 - 0 0 0 0 0 0 0 0 0 0 0 0
57172 - 0 0 0 0 0 0 0 0 0 0 0 0
57173 - 0 0 0 0 0 0 0 0 0 0 0 0
57174 - 0 0 0 0 0 0 0 0 0 0 0 0
57175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57188 +4 4 4 4 4 4
57189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57202 +4 4 4 4 4 4
57203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57216 +4 4 4 4 4 4
57217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57230 +4 4 4 4 4 4
57231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57244 +4 4 4 4 4 4
57245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57258 +4 4 4 4 4 4
57259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57263 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57264 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57268 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57269 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57270 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57272 +4 4 4 4 4 4
57273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57277 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57278 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57279 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57282 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57283 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57284 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57285 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57286 +4 4 4 4 4 4
57287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57291 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57292 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57293 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57296 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57297 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57298 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57299 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57300 +4 4 4 4 4 4
57301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57304 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57305 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57306 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57307 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57309 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57310 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57311 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57312 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57313 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57314 +4 4 4 4 4 4
57315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57318 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57319 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57320 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57321 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57322 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57323 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57324 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57325 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57326 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57327 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57328 +4 4 4 4 4 4
57329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57332 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57333 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57334 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57335 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57336 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57337 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57338 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57339 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57340 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57341 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57342 +4 4 4 4 4 4
57343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57345 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57346 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57347 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57348 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57349 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57350 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57351 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57352 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57353 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57354 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57355 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57356 +4 4 4 4 4 4
57357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57359 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57360 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57361 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57362 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57363 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57364 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57365 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57366 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57367 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57368 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57369 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57370 +4 4 4 4 4 4
57371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57373 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57374 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57375 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57376 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57377 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57378 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57379 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57380 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57381 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57382 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57383 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57384 +4 4 4 4 4 4
57385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57387 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57388 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57389 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57390 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57391 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57392 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57393 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57394 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57395 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57396 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57397 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57398 +4 4 4 4 4 4
57399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57400 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57401 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57402 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57403 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57404 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57405 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57406 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57407 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57408 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57409 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57410 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57411 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57412 +4 4 4 4 4 4
57413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57414 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57415 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57416 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57417 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57418 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57419 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57420 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57421 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57422 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57423 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57424 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57425 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57426 +0 0 0 4 4 4
57427 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57428 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57429 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57430 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57431 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57432 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57433 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57434 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57435 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57436 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57437 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57438 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57439 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57440 +2 0 0 0 0 0
57441 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57442 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57443 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57444 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57445 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57446 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57447 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57448 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57449 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57450 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57451 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57452 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57453 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57454 +37 38 37 0 0 0
57455 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57456 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57457 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57458 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57459 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57460 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57461 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57462 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57463 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57464 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57465 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57466 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57467 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57468 +85 115 134 4 0 0
57469 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57470 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57471 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57472 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57473 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57474 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57475 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57476 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57477 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57478 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57479 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57480 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57481 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57482 +60 73 81 4 0 0
57483 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57484 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57485 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57486 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57487 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57488 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57489 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57490 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57491 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57492 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57493 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57494 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57495 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57496 +16 19 21 4 0 0
57497 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57498 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57499 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57500 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57501 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57502 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57503 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57504 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57505 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57506 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57507 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57508 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57509 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57510 +4 0 0 4 3 3
57511 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57512 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57513 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57515 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57516 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57517 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57518 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57519 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57520 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57521 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57522 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57523 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57524 +3 2 2 4 4 4
57525 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57526 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57527 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57528 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57529 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57530 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57531 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57532 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57533 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57534 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57535 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57536 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57537 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57538 +4 4 4 4 4 4
57539 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57540 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57541 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57542 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57543 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57544 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57545 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57546 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57547 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57548 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57549 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57550 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57551 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57552 +4 4 4 4 4 4
57553 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57554 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57555 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57556 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57557 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57558 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57559 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57560 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57561 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57562 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57563 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57564 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57565 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57566 +5 5 5 5 5 5
57567 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57568 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57569 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57570 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57571 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57572 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57573 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57574 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57575 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57576 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57577 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57578 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57579 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57580 +5 5 5 4 4 4
57581 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57582 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57583 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57584 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57585 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57586 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57587 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57588 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57589 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57590 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57591 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57592 +4 0 0 4 0 0 5 5 5 5 5 5 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
57595 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57596 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57597 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57598 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57599 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57600 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57601 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57602 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57603 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57604 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57605 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57606 +3 3 3 5 5 5 6 6 6 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
57609 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57610 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57611 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57612 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57613 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57614 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57615 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57616 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57617 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57618 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57619 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
57623 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57624 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57625 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57626 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57627 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57628 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57629 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57630 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57631 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57632 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57633 +6 6 6 4 0 0 4 0 0 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
57637 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57638 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57639 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57640 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57641 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57642 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57643 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57644 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57645 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57646 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57647 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57650 +4 4 4 4 4 4
57651 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57652 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57653 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57654 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57655 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57656 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57657 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57658 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57659 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57660 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57661 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57664 +4 4 4 4 4 4
57665 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57666 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57667 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57668 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57669 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57670 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57671 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57672 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57673 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57674 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57675 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57678 +4 4 4 4 4 4
57679 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57680 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57681 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57682 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57683 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57684 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57685 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57686 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57687 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57688 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57689 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57692 +4 4 4 4 4 4
57693 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57694 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57695 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57696 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57697 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57698 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57699 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57700 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57701 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57702 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57703 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57706 +4 4 4 4 4 4
57707 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57708 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57709 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57710 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57711 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57712 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57713 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57714 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57715 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57716 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57717 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57720 +4 4 4 4 4 4
57721 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57722 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57723 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57724 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57725 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57726 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57727 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57728 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57729 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57730 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57731 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57734 +4 4 4 4 4 4
57735 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57736 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57737 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57738 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57739 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57740 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57741 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57742 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57743 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57744 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57745 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57748 +4 4 4 4 4 4
57749 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57750 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57751 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57752 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57753 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57754 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57755 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57756 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57757 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57758 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57759 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57762 +4 4 4 4 4 4
57763 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57764 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57765 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57766 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57767 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57768 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57769 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57770 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57771 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57772 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57773 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57776 +4 4 4 4 4 4
57777 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57778 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57779 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57780 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57781 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57782 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57783 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57784 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57785 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57786 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57787 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57790 +4 4 4 4 4 4
57791 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57792 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57793 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57794 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57795 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57796 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57797 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57798 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57799 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57800 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57801 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57804 +4 4 4 4 4 4
57805 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57806 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57807 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57808 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57809 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57810 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57811 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57812 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57813 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57814 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57815 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57818 +4 4 4 4 4 4
57819 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57820 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57821 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57822 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57823 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57824 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57825 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57826 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57827 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57828 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57829 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57832 +4 4 4 4 4 4
57833 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57834 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57835 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57836 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57837 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57838 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57839 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57840 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57841 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57842 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57843 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57846 +4 4 4 4 4 4
57847 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57848 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57849 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57850 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57851 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57852 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57853 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57854 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57855 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57856 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57857 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57860 +4 4 4 4 4 4
57861 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57862 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57863 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57864 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57865 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57866 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57867 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57868 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57869 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57870 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57871 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57874 +4 4 4 4 4 4
57875 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57876 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57877 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57878 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57879 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57880 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57881 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57882 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57883 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57884 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57885 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57888 +4 4 4 4 4 4
57889 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57890 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57891 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57892 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57893 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57894 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57895 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57896 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57897 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57898 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57899 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57902 +4 4 4 4 4 4
57903 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57904 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57905 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57906 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57907 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57908 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57909 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57910 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57911 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57912 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57913 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57916 +4 4 4 4 4 4
57917 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57918 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57919 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57920 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57921 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57922 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57923 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57924 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57925 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57926 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57927 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57930 +4 4 4 4 4 4
57931 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57932 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57933 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57934 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57935 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57936 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57937 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57938 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57939 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57940 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57941 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57944 +4 4 4 4 4 4
57945 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57946 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57947 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57948 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57949 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57950 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57951 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57952 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57953 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57954 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57955 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57958 +4 4 4 4 4 4
57959 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57960 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57961 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57962 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57963 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57964 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57965 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57967 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57968 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57969 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57972 +4 4 4 4 4 4
57973 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57974 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57975 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57976 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57977 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57978 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57979 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57980 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57981 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57982 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57983 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57986 +4 4 4 4 4 4
57987 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57988 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57989 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57990 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57991 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57992 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57993 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57994 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57995 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57996 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
57997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58000 +4 4 4 4 4 4
58001 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58002 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58003 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58004 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58005 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58006 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58007 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58008 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58009 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58010 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58014 +4 4 4 4 4 4
58015 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58016 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58017 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58018 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58019 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58020 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58021 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58022 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58023 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58024 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58028 +4 4 4 4 4 4
58029 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58030 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58031 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58032 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58033 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58034 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58035 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58036 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58037 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58038 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58042 +4 4 4 4 4 4
58043 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58044 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58045 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58046 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58047 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58048 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58049 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58050 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58051 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58056 +4 4 4 4 4 4
58057 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58058 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58059 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58060 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58061 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58062 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58063 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58064 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58065 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58070 +4 4 4 4 4 4
58071 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58072 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58073 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58074 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58075 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58076 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58077 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58078 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58079 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58084 +4 4 4 4 4 4
58085 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58086 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58087 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58088 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58089 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58090 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58091 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58092 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58098 +4 4 4 4 4 4
58099 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58100 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58101 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58102 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58103 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58104 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58105 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58106 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58112 +4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58114 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58115 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58116 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58117 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58118 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58119 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58120 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58126 +4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58129 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58130 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58131 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58132 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58133 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58134 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140 +4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58143 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58144 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58145 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58146 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58147 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58148 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154 +4 4 4 4 4 4
58155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58157 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58158 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58159 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58160 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58161 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58162 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168 +4 4 4 4 4 4
58169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58172 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58173 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58174 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58175 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182 +4 4 4 4 4 4
58183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58187 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58188 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58189 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196 +4 4 4 4 4 4
58197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58201 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58202 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58203 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210 +4 4 4 4 4 4
58211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58215 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58216 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58217 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58224 +4 4 4 4 4 4
58225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58229 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58230 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58231 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58238 +4 4 4 4 4 4
58239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58243 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58244 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58245 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58252 +4 4 4 4 4 4
58253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58258 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58259 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58266 +4 4 4 4 4 4
58267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58272 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58280 +4 4 4 4 4 4
58281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58285 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58286 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58294 +4 4 4 4 4 4
58295 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58296 index fef20db..d28b1ab 100644
58297 --- a/drivers/xen/xenfs/xenstored.c
58298 +++ b/drivers/xen/xenfs/xenstored.c
58299 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58300 static int xsd_kva_open(struct inode *inode, struct file *file)
58301 {
58302 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58303 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58304 + NULL);
58305 +#else
58306 xen_store_interface);
58307 +#endif
58308 +
58309 if (!file->private_data)
58310 return -ENOMEM;
58311 return 0;
58312 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58313 index cc1cfae..41158ad 100644
58314 --- a/fs/9p/vfs_addr.c
58315 +++ b/fs/9p/vfs_addr.c
58316 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58317
58318 retval = v9fs_file_write_internal(inode,
58319 v9inode->writeback_fid,
58320 - (__force const char __user *)buffer,
58321 + (const char __force_user *)buffer,
58322 len, &offset, 0);
58323 if (retval > 0)
58324 retval = 0;
58325 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58326 index 7fa4f7a..a7ebf8c 100644
58327 --- a/fs/9p/vfs_inode.c
58328 +++ b/fs/9p/vfs_inode.c
58329 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58330 void
58331 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58332 {
58333 - char *s = nd_get_link(nd);
58334 + const char *s = nd_get_link(nd);
58335
58336 p9_debug(P9_DEBUG_VFS, " %s %s\n",
58337 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
58338 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58339 index 370b24c..ff0be7b 100644
58340 --- a/fs/Kconfig.binfmt
58341 +++ b/fs/Kconfig.binfmt
58342 @@ -103,7 +103,7 @@ config HAVE_AOUT
58343
58344 config BINFMT_AOUT
58345 tristate "Kernel support for a.out and ECOFF binaries"
58346 - depends on HAVE_AOUT
58347 + depends on HAVE_AOUT && BROKEN
58348 ---help---
58349 A.out (Assembler.OUTput) is a set of formats for libraries and
58350 executables used in the earliest versions of UNIX. Linux used
58351 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58352 index 2946712..f737435 100644
58353 --- a/fs/afs/inode.c
58354 +++ b/fs/afs/inode.c
58355 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58356 struct afs_vnode *vnode;
58357 struct super_block *sb;
58358 struct inode *inode;
58359 - static atomic_t afs_autocell_ino;
58360 + static atomic_unchecked_t afs_autocell_ino;
58361
58362 _enter("{%x:%u},%*.*s,",
58363 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58364 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58365 data.fid.unique = 0;
58366 data.fid.vnode = 0;
58367
58368 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58369 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58370 afs_iget5_autocell_test, afs_iget5_set,
58371 &data);
58372 if (!inode) {
58373 diff --git a/fs/aio.c b/fs/aio.c
58374 index 7337500..2058af6 100644
58375 --- a/fs/aio.c
58376 +++ b/fs/aio.c
58377 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58378 size += sizeof(struct io_event) * nr_events;
58379
58380 nr_pages = PFN_UP(size);
58381 - if (nr_pages < 0)
58382 + if (nr_pages <= 0)
58383 return -EINVAL;
58384
58385 file = aio_private_file(ctx, nr_pages);
58386 diff --git a/fs/attr.c b/fs/attr.c
58387 index 6530ced..4a827e2 100644
58388 --- a/fs/attr.c
58389 +++ b/fs/attr.c
58390 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58391 unsigned long limit;
58392
58393 limit = rlimit(RLIMIT_FSIZE);
58394 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58395 if (limit != RLIM_INFINITY && offset > limit)
58396 goto out_sig;
58397 if (offset > inode->i_sb->s_maxbytes)
58398 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58399 index 116fd38..c04182da 100644
58400 --- a/fs/autofs4/waitq.c
58401 +++ b/fs/autofs4/waitq.c
58402 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58403 {
58404 unsigned long sigpipe, flags;
58405 mm_segment_t fs;
58406 - const char *data = (const char *)addr;
58407 + const char __user *data = (const char __force_user *)addr;
58408 ssize_t wr = 0;
58409
58410 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58411 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58412 return 1;
58413 }
58414
58415 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58416 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58417 +#endif
58418 +
58419 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58420 enum autofs_notify notify)
58421 {
58422 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58423
58424 /* If this is a direct mount request create a dummy name */
58425 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58426 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58427 + /* this name does get written to userland via autofs4_write() */
58428 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58429 +#else
58430 qstr.len = sprintf(name, "%p", dentry);
58431 +#endif
58432 else {
58433 qstr.len = autofs4_getpath(sbi, dentry, &name);
58434 if (!qstr.len) {
58435 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58436 index 2722387..56059b5 100644
58437 --- a/fs/befs/endian.h
58438 +++ b/fs/befs/endian.h
58439 @@ -11,7 +11,7 @@
58440
58441 #include <asm/byteorder.h>
58442
58443 -static inline u64
58444 +static inline u64 __intentional_overflow(-1)
58445 fs64_to_cpu(const struct super_block *sb, fs64 n)
58446 {
58447 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58448 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58449 return (__force fs64)cpu_to_be64(n);
58450 }
58451
58452 -static inline u32
58453 +static inline u32 __intentional_overflow(-1)
58454 fs32_to_cpu(const struct super_block *sb, fs32 n)
58455 {
58456 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58457 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58458 return (__force fs32)cpu_to_be32(n);
58459 }
58460
58461 -static inline u16
58462 +static inline u16 __intentional_overflow(-1)
58463 fs16_to_cpu(const struct super_block *sb, fs16 n)
58464 {
58465 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58466 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58467 index ca0ba15..0fa3257 100644
58468 --- a/fs/binfmt_aout.c
58469 +++ b/fs/binfmt_aout.c
58470 @@ -16,6 +16,7 @@
58471 #include <linux/string.h>
58472 #include <linux/fs.h>
58473 #include <linux/file.h>
58474 +#include <linux/security.h>
58475 #include <linux/stat.h>
58476 #include <linux/fcntl.h>
58477 #include <linux/ptrace.h>
58478 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58479 #endif
58480 # define START_STACK(u) ((void __user *)u.start_stack)
58481
58482 + memset(&dump, 0, sizeof(dump));
58483 +
58484 fs = get_fs();
58485 set_fs(KERNEL_DS);
58486 has_dumped = 1;
58487 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58488
58489 /* If the size of the dump file exceeds the rlimit, then see what would happen
58490 if we wrote the stack, but not the data area. */
58491 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58492 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58493 dump.u_dsize = 0;
58494
58495 /* Make sure we have enough room to write the stack and data areas. */
58496 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58497 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58498 dump.u_ssize = 0;
58499
58500 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58501 rlim = rlimit(RLIMIT_DATA);
58502 if (rlim >= RLIM_INFINITY)
58503 rlim = ~0;
58504 +
58505 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58506 if (ex.a_data + ex.a_bss > rlim)
58507 return -ENOMEM;
58508
58509 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58510
58511 install_exec_creds(bprm);
58512
58513 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58514 + current->mm->pax_flags = 0UL;
58515 +#endif
58516 +
58517 +#ifdef CONFIG_PAX_PAGEEXEC
58518 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58519 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58520 +
58521 +#ifdef CONFIG_PAX_EMUTRAMP
58522 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58523 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58524 +#endif
58525 +
58526 +#ifdef CONFIG_PAX_MPROTECT
58527 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58528 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58529 +#endif
58530 +
58531 + }
58532 +#endif
58533 +
58534 if (N_MAGIC(ex) == OMAGIC) {
58535 unsigned long text_addr, map_size;
58536 loff_t pos;
58537 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58538 }
58539
58540 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58541 - PROT_READ | PROT_WRITE | PROT_EXEC,
58542 + PROT_READ | PROT_WRITE,
58543 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58544 fd_offset + ex.a_text);
58545 if (error != N_DATADDR(ex)) {
58546 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58547 index 3892c1a..4e27c04 100644
58548 --- a/fs/binfmt_elf.c
58549 +++ b/fs/binfmt_elf.c
58550 @@ -34,6 +34,7 @@
58551 #include <linux/utsname.h>
58552 #include <linux/coredump.h>
58553 #include <linux/sched.h>
58554 +#include <linux/xattr.h>
58555 #include <asm/uaccess.h>
58556 #include <asm/param.h>
58557 #include <asm/page.h>
58558 @@ -47,7 +48,7 @@
58559
58560 static int load_elf_binary(struct linux_binprm *bprm);
58561 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58562 - int, int, unsigned long);
58563 + int, int, unsigned long) __intentional_overflow(-1);
58564
58565 #ifdef CONFIG_USELIB
58566 static int load_elf_library(struct file *);
58567 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58568 #define elf_core_dump NULL
58569 #endif
58570
58571 +#ifdef CONFIG_PAX_MPROTECT
58572 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58573 +#endif
58574 +
58575 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58576 +static void elf_handle_mmap(struct file *file);
58577 +#endif
58578 +
58579 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58580 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58581 #else
58582 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58583 .load_binary = load_elf_binary,
58584 .load_shlib = load_elf_library,
58585 .core_dump = elf_core_dump,
58586 +
58587 +#ifdef CONFIG_PAX_MPROTECT
58588 + .handle_mprotect= elf_handle_mprotect,
58589 +#endif
58590 +
58591 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58592 + .handle_mmap = elf_handle_mmap,
58593 +#endif
58594 +
58595 .min_coredump = ELF_EXEC_PAGESIZE,
58596 };
58597
58598 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58599
58600 static int set_brk(unsigned long start, unsigned long end)
58601 {
58602 + unsigned long e = end;
58603 +
58604 start = ELF_PAGEALIGN(start);
58605 end = ELF_PAGEALIGN(end);
58606 if (end > start) {
58607 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58608 if (BAD_ADDR(addr))
58609 return addr;
58610 }
58611 - current->mm->start_brk = current->mm->brk = end;
58612 + current->mm->start_brk = current->mm->brk = e;
58613 return 0;
58614 }
58615
58616 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58617 elf_addr_t __user *u_rand_bytes;
58618 const char *k_platform = ELF_PLATFORM;
58619 const char *k_base_platform = ELF_BASE_PLATFORM;
58620 - unsigned char k_rand_bytes[16];
58621 + u32 k_rand_bytes[4];
58622 int items;
58623 elf_addr_t *elf_info;
58624 int ei_index = 0;
58625 const struct cred *cred = current_cred();
58626 struct vm_area_struct *vma;
58627 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58628
58629 /*
58630 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58631 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58632 * Generate 16 random bytes for userspace PRNG seeding.
58633 */
58634 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58635 - u_rand_bytes = (elf_addr_t __user *)
58636 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58637 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58638 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58639 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58640 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58641 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58642 + u_rand_bytes = (elf_addr_t __user *) p;
58643 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58644 return -EFAULT;
58645
58646 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58647 return -EFAULT;
58648 current->mm->env_end = p;
58649
58650 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58651 +
58652 /* Put the elf_info on the stack in the right place. */
58653 sp = (elf_addr_t __user *)envp + 1;
58654 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58655 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58656 return -EFAULT;
58657 return 0;
58658 }
58659 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58660 an ELF header */
58661
58662 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58663 - struct file *interpreter, unsigned long *interp_map_addr,
58664 - unsigned long no_base)
58665 + struct file *interpreter, unsigned long no_base)
58666 {
58667 struct elf_phdr *elf_phdata;
58668 struct elf_phdr *eppnt;
58669 - unsigned long load_addr = 0;
58670 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58671 int load_addr_set = 0;
58672 unsigned long last_bss = 0, elf_bss = 0;
58673 - unsigned long error = ~0UL;
58674 + unsigned long error = -EINVAL;
58675 unsigned long total_size;
58676 int retval, i, size;
58677
58678 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58679 goto out_close;
58680 }
58681
58682 +#ifdef CONFIG_PAX_SEGMEXEC
58683 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58684 + pax_task_size = SEGMEXEC_TASK_SIZE;
58685 +#endif
58686 +
58687 eppnt = elf_phdata;
58688 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58689 if (eppnt->p_type == PT_LOAD) {
58690 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58691 map_addr = elf_map(interpreter, load_addr + vaddr,
58692 eppnt, elf_prot, elf_type, total_size);
58693 total_size = 0;
58694 - if (!*interp_map_addr)
58695 - *interp_map_addr = map_addr;
58696 error = map_addr;
58697 if (BAD_ADDR(map_addr))
58698 goto out_close;
58699 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58700 k = load_addr + eppnt->p_vaddr;
58701 if (BAD_ADDR(k) ||
58702 eppnt->p_filesz > eppnt->p_memsz ||
58703 - eppnt->p_memsz > TASK_SIZE ||
58704 - TASK_SIZE - eppnt->p_memsz < k) {
58705 + eppnt->p_memsz > pax_task_size ||
58706 + pax_task_size - eppnt->p_memsz < k) {
58707 error = -ENOMEM;
58708 goto out_close;
58709 }
58710 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58711 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58712
58713 /* Map the last of the bss segment */
58714 - error = vm_brk(elf_bss, last_bss - elf_bss);
58715 - if (BAD_ADDR(error))
58716 - goto out_close;
58717 + if (last_bss > elf_bss) {
58718 + error = vm_brk(elf_bss, last_bss - elf_bss);
58719 + if (BAD_ADDR(error))
58720 + goto out_close;
58721 + }
58722 }
58723
58724 error = load_addr;
58725 @@ -543,6 +574,336 @@ out:
58726 return error;
58727 }
58728
58729 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58730 +#ifdef CONFIG_PAX_SOFTMODE
58731 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58732 +{
58733 + unsigned long pax_flags = 0UL;
58734 +
58735 +#ifdef CONFIG_PAX_PAGEEXEC
58736 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58737 + pax_flags |= MF_PAX_PAGEEXEC;
58738 +#endif
58739 +
58740 +#ifdef CONFIG_PAX_SEGMEXEC
58741 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58742 + pax_flags |= MF_PAX_SEGMEXEC;
58743 +#endif
58744 +
58745 +#ifdef CONFIG_PAX_EMUTRAMP
58746 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58747 + pax_flags |= MF_PAX_EMUTRAMP;
58748 +#endif
58749 +
58750 +#ifdef CONFIG_PAX_MPROTECT
58751 + if (elf_phdata->p_flags & PF_MPROTECT)
58752 + pax_flags |= MF_PAX_MPROTECT;
58753 +#endif
58754 +
58755 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58756 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58757 + pax_flags |= MF_PAX_RANDMMAP;
58758 +#endif
58759 +
58760 + return pax_flags;
58761 +}
58762 +#endif
58763 +
58764 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58765 +{
58766 + unsigned long pax_flags = 0UL;
58767 +
58768 +#ifdef CONFIG_PAX_PAGEEXEC
58769 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58770 + pax_flags |= MF_PAX_PAGEEXEC;
58771 +#endif
58772 +
58773 +#ifdef CONFIG_PAX_SEGMEXEC
58774 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58775 + pax_flags |= MF_PAX_SEGMEXEC;
58776 +#endif
58777 +
58778 +#ifdef CONFIG_PAX_EMUTRAMP
58779 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58780 + pax_flags |= MF_PAX_EMUTRAMP;
58781 +#endif
58782 +
58783 +#ifdef CONFIG_PAX_MPROTECT
58784 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58785 + pax_flags |= MF_PAX_MPROTECT;
58786 +#endif
58787 +
58788 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58789 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58790 + pax_flags |= MF_PAX_RANDMMAP;
58791 +#endif
58792 +
58793 + return pax_flags;
58794 +}
58795 +#endif
58796 +
58797 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58798 +#ifdef CONFIG_PAX_SOFTMODE
58799 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58800 +{
58801 + unsigned long pax_flags = 0UL;
58802 +
58803 +#ifdef CONFIG_PAX_PAGEEXEC
58804 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58805 + pax_flags |= MF_PAX_PAGEEXEC;
58806 +#endif
58807 +
58808 +#ifdef CONFIG_PAX_SEGMEXEC
58809 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58810 + pax_flags |= MF_PAX_SEGMEXEC;
58811 +#endif
58812 +
58813 +#ifdef CONFIG_PAX_EMUTRAMP
58814 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58815 + pax_flags |= MF_PAX_EMUTRAMP;
58816 +#endif
58817 +
58818 +#ifdef CONFIG_PAX_MPROTECT
58819 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58820 + pax_flags |= MF_PAX_MPROTECT;
58821 +#endif
58822 +
58823 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58824 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58825 + pax_flags |= MF_PAX_RANDMMAP;
58826 +#endif
58827 +
58828 + return pax_flags;
58829 +}
58830 +#endif
58831 +
58832 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58833 +{
58834 + unsigned long pax_flags = 0UL;
58835 +
58836 +#ifdef CONFIG_PAX_PAGEEXEC
58837 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58838 + pax_flags |= MF_PAX_PAGEEXEC;
58839 +#endif
58840 +
58841 +#ifdef CONFIG_PAX_SEGMEXEC
58842 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58843 + pax_flags |= MF_PAX_SEGMEXEC;
58844 +#endif
58845 +
58846 +#ifdef CONFIG_PAX_EMUTRAMP
58847 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58848 + pax_flags |= MF_PAX_EMUTRAMP;
58849 +#endif
58850 +
58851 +#ifdef CONFIG_PAX_MPROTECT
58852 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58853 + pax_flags |= MF_PAX_MPROTECT;
58854 +#endif
58855 +
58856 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58857 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58858 + pax_flags |= MF_PAX_RANDMMAP;
58859 +#endif
58860 +
58861 + return pax_flags;
58862 +}
58863 +#endif
58864 +
58865 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58866 +static unsigned long pax_parse_defaults(void)
58867 +{
58868 + unsigned long pax_flags = 0UL;
58869 +
58870 +#ifdef CONFIG_PAX_SOFTMODE
58871 + if (pax_softmode)
58872 + return pax_flags;
58873 +#endif
58874 +
58875 +#ifdef CONFIG_PAX_PAGEEXEC
58876 + pax_flags |= MF_PAX_PAGEEXEC;
58877 +#endif
58878 +
58879 +#ifdef CONFIG_PAX_SEGMEXEC
58880 + pax_flags |= MF_PAX_SEGMEXEC;
58881 +#endif
58882 +
58883 +#ifdef CONFIG_PAX_MPROTECT
58884 + pax_flags |= MF_PAX_MPROTECT;
58885 +#endif
58886 +
58887 +#ifdef CONFIG_PAX_RANDMMAP
58888 + if (randomize_va_space)
58889 + pax_flags |= MF_PAX_RANDMMAP;
58890 +#endif
58891 +
58892 + return pax_flags;
58893 +}
58894 +
58895 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58896 +{
58897 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58898 +
58899 +#ifdef CONFIG_PAX_EI_PAX
58900 +
58901 +#ifdef CONFIG_PAX_SOFTMODE
58902 + if (pax_softmode)
58903 + return pax_flags;
58904 +#endif
58905 +
58906 + pax_flags = 0UL;
58907 +
58908 +#ifdef CONFIG_PAX_PAGEEXEC
58909 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58910 + pax_flags |= MF_PAX_PAGEEXEC;
58911 +#endif
58912 +
58913 +#ifdef CONFIG_PAX_SEGMEXEC
58914 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58915 + pax_flags |= MF_PAX_SEGMEXEC;
58916 +#endif
58917 +
58918 +#ifdef CONFIG_PAX_EMUTRAMP
58919 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58920 + pax_flags |= MF_PAX_EMUTRAMP;
58921 +#endif
58922 +
58923 +#ifdef CONFIG_PAX_MPROTECT
58924 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58925 + pax_flags |= MF_PAX_MPROTECT;
58926 +#endif
58927 +
58928 +#ifdef CONFIG_PAX_ASLR
58929 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58930 + pax_flags |= MF_PAX_RANDMMAP;
58931 +#endif
58932 +
58933 +#endif
58934 +
58935 + return pax_flags;
58936 +
58937 +}
58938 +
58939 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58940 +{
58941 +
58942 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58943 + unsigned long i;
58944 +
58945 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58946 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58947 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58948 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58949 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58950 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58951 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58952 + return PAX_PARSE_FLAGS_FALLBACK;
58953 +
58954 +#ifdef CONFIG_PAX_SOFTMODE
58955 + if (pax_softmode)
58956 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58957 + else
58958 +#endif
58959 +
58960 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58961 + break;
58962 + }
58963 +#endif
58964 +
58965 + return PAX_PARSE_FLAGS_FALLBACK;
58966 +}
58967 +
58968 +static unsigned long pax_parse_xattr_pax(struct file * const file)
58969 +{
58970 +
58971 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58972 + ssize_t xattr_size, i;
58973 + unsigned char xattr_value[sizeof("pemrs") - 1];
58974 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58975 +
58976 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58977 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58978 + return PAX_PARSE_FLAGS_FALLBACK;
58979 +
58980 + for (i = 0; i < xattr_size; i++)
58981 + switch (xattr_value[i]) {
58982 + default:
58983 + return PAX_PARSE_FLAGS_FALLBACK;
58984 +
58985 +#define parse_flag(option1, option2, flag) \
58986 + case option1: \
58987 + if (pax_flags_hardmode & MF_PAX_##flag) \
58988 + return PAX_PARSE_FLAGS_FALLBACK;\
58989 + pax_flags_hardmode |= MF_PAX_##flag; \
58990 + break; \
58991 + case option2: \
58992 + if (pax_flags_softmode & MF_PAX_##flag) \
58993 + return PAX_PARSE_FLAGS_FALLBACK;\
58994 + pax_flags_softmode |= MF_PAX_##flag; \
58995 + break;
58996 +
58997 + parse_flag('p', 'P', PAGEEXEC);
58998 + parse_flag('e', 'E', EMUTRAMP);
58999 + parse_flag('m', 'M', MPROTECT);
59000 + parse_flag('r', 'R', RANDMMAP);
59001 + parse_flag('s', 'S', SEGMEXEC);
59002 +
59003 +#undef parse_flag
59004 + }
59005 +
59006 + if (pax_flags_hardmode & pax_flags_softmode)
59007 + return PAX_PARSE_FLAGS_FALLBACK;
59008 +
59009 +#ifdef CONFIG_PAX_SOFTMODE
59010 + if (pax_softmode)
59011 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59012 + else
59013 +#endif
59014 +
59015 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59016 +#else
59017 + return PAX_PARSE_FLAGS_FALLBACK;
59018 +#endif
59019 +
59020 +}
59021 +
59022 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59023 +{
59024 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59025 +
59026 + pax_flags = pax_parse_defaults();
59027 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59028 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59029 + xattr_pax_flags = pax_parse_xattr_pax(file);
59030 +
59031 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59032 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59033 + pt_pax_flags != xattr_pax_flags)
59034 + return -EINVAL;
59035 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59036 + pax_flags = xattr_pax_flags;
59037 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59038 + pax_flags = pt_pax_flags;
59039 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59040 + pax_flags = ei_pax_flags;
59041 +
59042 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59043 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59044 + if ((__supported_pte_mask & _PAGE_NX))
59045 + pax_flags &= ~MF_PAX_SEGMEXEC;
59046 + else
59047 + pax_flags &= ~MF_PAX_PAGEEXEC;
59048 + }
59049 +#endif
59050 +
59051 + if (0 > pax_check_flags(&pax_flags))
59052 + return -EINVAL;
59053 +
59054 + current->mm->pax_flags = pax_flags;
59055 + return 0;
59056 +}
59057 +#endif
59058 +
59059 /*
59060 * These are the functions used to load ELF style executables and shared
59061 * libraries. There is no binary dependent code anywhere else.
59062 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59063 {
59064 unsigned int random_variable = 0;
59065
59066 +#ifdef CONFIG_PAX_RANDUSTACK
59067 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59068 + return stack_top - current->mm->delta_stack;
59069 +#endif
59070 +
59071 if ((current->flags & PF_RANDOMIZE) &&
59072 !(current->personality & ADDR_NO_RANDOMIZE)) {
59073 random_variable = get_random_int() & STACK_RND_MASK;
59074 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59075 unsigned long load_addr = 0, load_bias = 0;
59076 int load_addr_set = 0;
59077 char * elf_interpreter = NULL;
59078 - unsigned long error;
59079 + unsigned long error = 0;
59080 struct elf_phdr *elf_ppnt, *elf_phdata;
59081 unsigned long elf_bss, elf_brk;
59082 int retval, i;
59083 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59084 struct elfhdr elf_ex;
59085 struct elfhdr interp_elf_ex;
59086 } *loc;
59087 + unsigned long pax_task_size;
59088
59089 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59090 if (!loc) {
59091 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59092 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59093 may depend on the personality. */
59094 SET_PERSONALITY(loc->elf_ex);
59095 +
59096 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59097 + current->mm->pax_flags = 0UL;
59098 +#endif
59099 +
59100 +#ifdef CONFIG_PAX_DLRESOLVE
59101 + current->mm->call_dl_resolve = 0UL;
59102 +#endif
59103 +
59104 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59105 + current->mm->call_syscall = 0UL;
59106 +#endif
59107 +
59108 +#ifdef CONFIG_PAX_ASLR
59109 + current->mm->delta_mmap = 0UL;
59110 + current->mm->delta_stack = 0UL;
59111 +#endif
59112 +
59113 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59114 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59115 + send_sig(SIGKILL, current, 0);
59116 + goto out_free_dentry;
59117 + }
59118 +#endif
59119 +
59120 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59121 + pax_set_initial_flags(bprm);
59122 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59123 + if (pax_set_initial_flags_func)
59124 + (pax_set_initial_flags_func)(bprm);
59125 +#endif
59126 +
59127 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59128 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59129 + current->mm->context.user_cs_limit = PAGE_SIZE;
59130 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59131 + }
59132 +#endif
59133 +
59134 +#ifdef CONFIG_PAX_SEGMEXEC
59135 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59136 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59137 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59138 + pax_task_size = SEGMEXEC_TASK_SIZE;
59139 + current->mm->def_flags |= VM_NOHUGEPAGE;
59140 + } else
59141 +#endif
59142 +
59143 + pax_task_size = TASK_SIZE;
59144 +
59145 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59146 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59147 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59148 + put_cpu();
59149 + }
59150 +#endif
59151 +
59152 +#ifdef CONFIG_PAX_ASLR
59153 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59154 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59155 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59156 + }
59157 +#endif
59158 +
59159 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59160 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59161 + executable_stack = EXSTACK_DISABLE_X;
59162 + current->personality &= ~READ_IMPLIES_EXEC;
59163 + } else
59164 +#endif
59165 +
59166 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59167 current->personality |= READ_IMPLIES_EXEC;
59168
59169 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59170 #else
59171 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59172 #endif
59173 +
59174 +#ifdef CONFIG_PAX_RANDMMAP
59175 + /* PaX: randomize base address at the default exe base if requested */
59176 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59177 +#ifdef CONFIG_SPARC64
59178 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59179 +#else
59180 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59181 +#endif
59182 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59183 + elf_flags |= MAP_FIXED;
59184 + }
59185 +#endif
59186 +
59187 }
59188
59189 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59190 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59191 * allowed task size. Note that p_filesz must always be
59192 * <= p_memsz so it is only necessary to check p_memsz.
59193 */
59194 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59195 - elf_ppnt->p_memsz > TASK_SIZE ||
59196 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59197 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59198 + elf_ppnt->p_memsz > pax_task_size ||
59199 + pax_task_size - elf_ppnt->p_memsz < k) {
59200 /* set_brk can never work. Avoid overflows. */
59201 send_sig(SIGKILL, current, 0);
59202 retval = -EINVAL;
59203 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
59204 goto out_free_dentry;
59205 }
59206 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59207 - send_sig(SIGSEGV, current, 0);
59208 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59209 - goto out_free_dentry;
59210 + /*
59211 + * This bss-zeroing can fail if the ELF
59212 + * file specifies odd protections. So
59213 + * we don't check the return value
59214 + */
59215 }
59216
59217 +#ifdef CONFIG_PAX_RANDMMAP
59218 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59219 + unsigned long start, size, flags;
59220 + vm_flags_t vm_flags;
59221 +
59222 + start = ELF_PAGEALIGN(elf_brk);
59223 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59224 + flags = MAP_FIXED | MAP_PRIVATE;
59225 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59226 +
59227 + down_write(&current->mm->mmap_sem);
59228 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59229 + retval = -ENOMEM;
59230 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59231 +// if (current->personality & ADDR_NO_RANDOMIZE)
59232 +// vm_flags |= VM_READ | VM_MAYREAD;
59233 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59234 + retval = IS_ERR_VALUE(start) ? start : 0;
59235 + }
59236 + up_write(&current->mm->mmap_sem);
59237 + if (retval == 0)
59238 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59239 + if (retval < 0) {
59240 + send_sig(SIGKILL, current, 0);
59241 + goto out_free_dentry;
59242 + }
59243 + }
59244 +#endif
59245 +
59246 if (elf_interpreter) {
59247 - unsigned long interp_map_addr = 0;
59248 -
59249 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59250 interpreter,
59251 - &interp_map_addr,
59252 load_bias);
59253 if (!IS_ERR((void *)elf_entry)) {
59254 /*
59255 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59256 * Decide what to dump of a segment, part, all or none.
59257 */
59258 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59259 - unsigned long mm_flags)
59260 + unsigned long mm_flags, long signr)
59261 {
59262 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59263
59264 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59265 if (vma->vm_file == NULL)
59266 return 0;
59267
59268 - if (FILTER(MAPPED_PRIVATE))
59269 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59270 goto whole;
59271
59272 /*
59273 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59274 {
59275 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59276 int i = 0;
59277 - do
59278 + do {
59279 i += 2;
59280 - while (auxv[i - 2] != AT_NULL);
59281 + } while (auxv[i - 2] != AT_NULL);
59282 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59283 }
59284
59285 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59286 {
59287 mm_segment_t old_fs = get_fs();
59288 set_fs(KERNEL_DS);
59289 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59290 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59291 set_fs(old_fs);
59292 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59293 }
59294 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59295 }
59296
59297 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59298 - unsigned long mm_flags)
59299 + struct coredump_params *cprm)
59300 {
59301 struct vm_area_struct *vma;
59302 size_t size = 0;
59303
59304 for (vma = first_vma(current, gate_vma); vma != NULL;
59305 vma = next_vma(vma, gate_vma))
59306 - size += vma_dump_size(vma, mm_flags);
59307 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59308 return size;
59309 }
59310
59311 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59312
59313 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59314
59315 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59316 + offset += elf_core_vma_data_size(gate_vma, cprm);
59317 offset += elf_core_extra_data_size();
59318 e_shoff = offset;
59319
59320 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59321 phdr.p_offset = offset;
59322 phdr.p_vaddr = vma->vm_start;
59323 phdr.p_paddr = 0;
59324 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59325 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59326 phdr.p_memsz = vma->vm_end - vma->vm_start;
59327 offset += phdr.p_filesz;
59328 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59329 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59330 unsigned long addr;
59331 unsigned long end;
59332
59333 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59334 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59335
59336 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59337 struct page *page;
59338 @@ -2210,6 +2690,167 @@ out:
59339
59340 #endif /* CONFIG_ELF_CORE */
59341
59342 +#ifdef CONFIG_PAX_MPROTECT
59343 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59344 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59345 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59346 + *
59347 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59348 + * basis because we want to allow the common case and not the special ones.
59349 + */
59350 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59351 +{
59352 + struct elfhdr elf_h;
59353 + struct elf_phdr elf_p;
59354 + unsigned long i;
59355 + unsigned long oldflags;
59356 + bool is_textrel_rw, is_textrel_rx, is_relro;
59357 +
59358 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59359 + return;
59360 +
59361 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59362 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59363 +
59364 +#ifdef CONFIG_PAX_ELFRELOCS
59365 + /* possible TEXTREL */
59366 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59367 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59368 +#else
59369 + is_textrel_rw = false;
59370 + is_textrel_rx = false;
59371 +#endif
59372 +
59373 + /* possible RELRO */
59374 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59375 +
59376 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59377 + return;
59378 +
59379 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59380 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59381 +
59382 +#ifdef CONFIG_PAX_ETEXECRELOCS
59383 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59384 +#else
59385 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59386 +#endif
59387 +
59388 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59389 + !elf_check_arch(&elf_h) ||
59390 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59391 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59392 + return;
59393 +
59394 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59395 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59396 + return;
59397 + switch (elf_p.p_type) {
59398 + case PT_DYNAMIC:
59399 + if (!is_textrel_rw && !is_textrel_rx)
59400 + continue;
59401 + i = 0UL;
59402 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59403 + elf_dyn dyn;
59404 +
59405 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59406 + break;
59407 + if (dyn.d_tag == DT_NULL)
59408 + break;
59409 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59410 + gr_log_textrel(vma);
59411 + if (is_textrel_rw)
59412 + vma->vm_flags |= VM_MAYWRITE;
59413 + else
59414 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59415 + vma->vm_flags &= ~VM_MAYWRITE;
59416 + break;
59417 + }
59418 + i++;
59419 + }
59420 + is_textrel_rw = false;
59421 + is_textrel_rx = false;
59422 + continue;
59423 +
59424 + case PT_GNU_RELRO:
59425 + if (!is_relro)
59426 + continue;
59427 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59428 + vma->vm_flags &= ~VM_MAYWRITE;
59429 + is_relro = false;
59430 + continue;
59431 +
59432 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59433 + case PT_PAX_FLAGS: {
59434 + const char *msg_mprotect = "", *msg_emutramp = "";
59435 + char *buffer_lib, *buffer_exe;
59436 +
59437 + if (elf_p.p_flags & PF_NOMPROTECT)
59438 + msg_mprotect = "MPROTECT disabled";
59439 +
59440 +#ifdef CONFIG_PAX_EMUTRAMP
59441 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59442 + msg_emutramp = "EMUTRAMP enabled";
59443 +#endif
59444 +
59445 + if (!msg_mprotect[0] && !msg_emutramp[0])
59446 + continue;
59447 +
59448 + if (!printk_ratelimit())
59449 + continue;
59450 +
59451 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59452 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59453 + if (buffer_lib && buffer_exe) {
59454 + char *path_lib, *path_exe;
59455 +
59456 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59457 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59458 +
59459 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59460 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59461 +
59462 + }
59463 + free_page((unsigned long)buffer_exe);
59464 + free_page((unsigned long)buffer_lib);
59465 + continue;
59466 + }
59467 +#endif
59468 +
59469 + }
59470 + }
59471 +}
59472 +#endif
59473 +
59474 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59475 +
59476 +extern int grsec_enable_log_rwxmaps;
59477 +
59478 +static void elf_handle_mmap(struct file *file)
59479 +{
59480 + struct elfhdr elf_h;
59481 + struct elf_phdr elf_p;
59482 + unsigned long i;
59483 +
59484 + if (!grsec_enable_log_rwxmaps)
59485 + return;
59486 +
59487 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59488 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59489 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59490 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59491 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59492 + return;
59493 +
59494 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59495 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59496 + return;
59497 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59498 + gr_log_ptgnustack(file);
59499 + }
59500 +}
59501 +#endif
59502 +
59503 static int __init init_elf_binfmt(void)
59504 {
59505 register_binfmt(&elf_format);
59506 diff --git a/fs/block_dev.c b/fs/block_dev.c
59507 index 6d72746..536d1db 100644
59508 --- a/fs/block_dev.c
59509 +++ b/fs/block_dev.c
59510 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59511 else if (bdev->bd_contains == bdev)
59512 return true; /* is a whole device which isn't held */
59513
59514 - else if (whole->bd_holder == bd_may_claim)
59515 + else if (whole->bd_holder == (void *)bd_may_claim)
59516 return true; /* is a partition of a device that is being partitioned */
59517 else if (whole->bd_holder != NULL)
59518 return false; /* is a partition of a held device */
59519 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59520 index 44ee5d2..8b23e53 100644
59521 --- a/fs/btrfs/ctree.c
59522 +++ b/fs/btrfs/ctree.c
59523 @@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59524 free_extent_buffer(buf);
59525 add_root_to_dirty_list(root);
59526 } else {
59527 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59528 - parent_start = parent->start;
59529 - else
59530 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59531 + if (parent)
59532 + parent_start = parent->start;
59533 + else
59534 + parent_start = 0;
59535 + } else
59536 parent_start = 0;
59537
59538 WARN_ON(trans->transid != btrfs_header_generation(parent));
59539 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59540 index a2e90f8..5135e5f 100644
59541 --- a/fs/btrfs/delayed-inode.c
59542 +++ b/fs/btrfs/delayed-inode.c
59543 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59544
59545 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59546 {
59547 - int seq = atomic_inc_return(&delayed_root->items_seq);
59548 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59549 if ((atomic_dec_return(&delayed_root->items) <
59550 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59551 waitqueue_active(&delayed_root->wait))
59552 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59553
59554 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59555 {
59556 - int val = atomic_read(&delayed_root->items_seq);
59557 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59558
59559 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59560 return 1;
59561 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59562 int seq;
59563 int ret;
59564
59565 - seq = atomic_read(&delayed_root->items_seq);
59566 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59567
59568 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59569 if (ret)
59570 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59571 index f70119f..ab5894d 100644
59572 --- a/fs/btrfs/delayed-inode.h
59573 +++ b/fs/btrfs/delayed-inode.h
59574 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59575 */
59576 struct list_head prepare_list;
59577 atomic_t items; /* for delayed items */
59578 - atomic_t items_seq; /* for delayed items */
59579 + atomic_unchecked_t items_seq; /* for delayed items */
59580 int nodes; /* for delayed nodes */
59581 wait_queue_head_t wait;
59582 };
59583 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59584 struct btrfs_delayed_root *delayed_root)
59585 {
59586 atomic_set(&delayed_root->items, 0);
59587 - atomic_set(&delayed_root->items_seq, 0);
59588 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59589 delayed_root->nodes = 0;
59590 spin_lock_init(&delayed_root->lock);
59591 init_waitqueue_head(&delayed_root->wait);
59592 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59593 index b765d41..5a8b0c3 100644
59594 --- a/fs/btrfs/ioctl.c
59595 +++ b/fs/btrfs/ioctl.c
59596 @@ -3975,9 +3975,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59597 for (i = 0; i < num_types; i++) {
59598 struct btrfs_space_info *tmp;
59599
59600 + /* Don't copy in more than we allocated */
59601 if (!slot_count)
59602 break;
59603
59604 + slot_count--;
59605 +
59606 info = NULL;
59607 rcu_read_lock();
59608 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59609 @@ -3999,10 +4002,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59610 memcpy(dest, &space, sizeof(space));
59611 dest++;
59612 space_args.total_spaces++;
59613 - slot_count--;
59614 }
59615 - if (!slot_count)
59616 - break;
59617 }
59618 up_read(&info->groups_sem);
59619 }
59620 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59621 index c4124de..d7613eb6 100644
59622 --- a/fs/btrfs/super.c
59623 +++ b/fs/btrfs/super.c
59624 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59625 function, line, errstr);
59626 return;
59627 }
59628 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59629 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59630 /* Wake up anybody who may be waiting on this transaction */
59631 wake_up(&root->fs_info->transaction_wait);
59632 wake_up(&root->fs_info->transaction_blocked_wait);
59633 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59634 index 12e5355..cdf30c6 100644
59635 --- a/fs/btrfs/sysfs.c
59636 +++ b/fs/btrfs/sysfs.c
59637 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59638 for (set = 0; set < FEAT_MAX; set++) {
59639 int i;
59640 struct attribute *attrs[2];
59641 - struct attribute_group agroup = {
59642 + attribute_group_no_const agroup = {
59643 .name = "features",
59644 .attrs = attrs,
59645 };
59646 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59647 index e2e798a..f454c18 100644
59648 --- a/fs/btrfs/tree-log.h
59649 +++ b/fs/btrfs/tree-log.h
59650 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59651 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59652 struct btrfs_trans_handle *trans)
59653 {
59654 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59655 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59656 }
59657
59658 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59659 diff --git a/fs/buffer.c b/fs/buffer.c
59660 index 72daaa5..60ffeb9 100644
59661 --- a/fs/buffer.c
59662 +++ b/fs/buffer.c
59663 @@ -3432,7 +3432,7 @@ void __init buffer_init(void)
59664 bh_cachep = kmem_cache_create("buffer_head",
59665 sizeof(struct buffer_head), 0,
59666 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59667 - SLAB_MEM_SPREAD),
59668 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59669 NULL);
59670
59671 /*
59672 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59673 index fbb08e9..0fda764 100644
59674 --- a/fs/cachefiles/bind.c
59675 +++ b/fs/cachefiles/bind.c
59676 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59677 args);
59678
59679 /* start by checking things over */
59680 - ASSERT(cache->fstop_percent >= 0 &&
59681 - cache->fstop_percent < cache->fcull_percent &&
59682 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59683 cache->fcull_percent < cache->frun_percent &&
59684 cache->frun_percent < 100);
59685
59686 - ASSERT(cache->bstop_percent >= 0 &&
59687 - cache->bstop_percent < cache->bcull_percent &&
59688 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59689 cache->bcull_percent < cache->brun_percent &&
59690 cache->brun_percent < 100);
59691
59692 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59693 index ce1b115..4a6852c 100644
59694 --- a/fs/cachefiles/daemon.c
59695 +++ b/fs/cachefiles/daemon.c
59696 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59697 if (n > buflen)
59698 return -EMSGSIZE;
59699
59700 - if (copy_to_user(_buffer, buffer, n) != 0)
59701 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59702 return -EFAULT;
59703
59704 return n;
59705 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59706 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59707 return -EIO;
59708
59709 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59710 + if (datalen > PAGE_SIZE - 1)
59711 return -EOPNOTSUPP;
59712
59713 /* drag the command string into the kernel so we can parse it */
59714 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59715 if (args[0] != '%' || args[1] != '\0')
59716 return -EINVAL;
59717
59718 - if (fstop < 0 || fstop >= cache->fcull_percent)
59719 + if (fstop >= cache->fcull_percent)
59720 return cachefiles_daemon_range_error(cache, args);
59721
59722 cache->fstop_percent = fstop;
59723 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59724 if (args[0] != '%' || args[1] != '\0')
59725 return -EINVAL;
59726
59727 - if (bstop < 0 || bstop >= cache->bcull_percent)
59728 + if (bstop >= cache->bcull_percent)
59729 return cachefiles_daemon_range_error(cache, args);
59730
59731 cache->bstop_percent = bstop;
59732 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59733 index 8c52472..c4e3a69 100644
59734 --- a/fs/cachefiles/internal.h
59735 +++ b/fs/cachefiles/internal.h
59736 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59737 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59738 struct rb_root active_nodes; /* active nodes (can't be culled) */
59739 rwlock_t active_lock; /* lock for active_nodes */
59740 - atomic_t gravecounter; /* graveyard uniquifier */
59741 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59742 unsigned frun_percent; /* when to stop culling (% files) */
59743 unsigned fcull_percent; /* when to start culling (% files) */
59744 unsigned fstop_percent; /* when to stop allocating (% files) */
59745 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59746 * proc.c
59747 */
59748 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59749 -extern atomic_t cachefiles_lookup_histogram[HZ];
59750 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59751 -extern atomic_t cachefiles_create_histogram[HZ];
59752 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59753 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59754 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59755
59756 extern int __init cachefiles_proc_init(void);
59757 extern void cachefiles_proc_cleanup(void);
59758 static inline
59759 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59760 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59761 {
59762 unsigned long jif = jiffies - start_jif;
59763 if (jif >= HZ)
59764 jif = HZ - 1;
59765 - atomic_inc(&histogram[jif]);
59766 + atomic_inc_unchecked(&histogram[jif]);
59767 }
59768
59769 #else
59770 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59771 index dad7d95..07475af 100644
59772 --- a/fs/cachefiles/namei.c
59773 +++ b/fs/cachefiles/namei.c
59774 @@ -312,7 +312,7 @@ try_again:
59775 /* first step is to make up a grave dentry in the graveyard */
59776 sprintf(nbuffer, "%08x%08x",
59777 (uint32_t) get_seconds(),
59778 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59779 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59780
59781 /* do the multiway lock magic */
59782 trap = lock_rename(cache->graveyard, dir);
59783 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59784 index eccd339..4c1d995 100644
59785 --- a/fs/cachefiles/proc.c
59786 +++ b/fs/cachefiles/proc.c
59787 @@ -14,9 +14,9 @@
59788 #include <linux/seq_file.h>
59789 #include "internal.h"
59790
59791 -atomic_t cachefiles_lookup_histogram[HZ];
59792 -atomic_t cachefiles_mkdir_histogram[HZ];
59793 -atomic_t cachefiles_create_histogram[HZ];
59794 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59795 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59796 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59797
59798 /*
59799 * display the latency histogram
59800 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59801 return 0;
59802 default:
59803 index = (unsigned long) v - 3;
59804 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59805 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59806 - z = atomic_read(&cachefiles_create_histogram[index]);
59807 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59808 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59809 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59810 if (x == 0 && y == 0 && z == 0)
59811 return 0;
59812
59813 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
59814 index 25e745b..220e604 100644
59815 --- a/fs/cachefiles/rdwr.c
59816 +++ b/fs/cachefiles/rdwr.c
59817 @@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
59818 old_fs = get_fs();
59819 set_fs(KERNEL_DS);
59820 ret = file->f_op->write(
59821 - file, (const void __user *) data, len, &pos);
59822 + file, (const void __force_user *) data, len, &pos);
59823 set_fs(old_fs);
59824 kunmap(page);
59825 file_end_write(file);
59826 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59827 index c29d6ae..719b9bb 100644
59828 --- a/fs/ceph/dir.c
59829 +++ b/fs/ceph/dir.c
59830 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59831 struct dentry *dentry, *last;
59832 struct ceph_dentry_info *di;
59833 int err = 0;
59834 + char d_name[DNAME_INLINE_LEN];
59835 + const unsigned char *name;
59836
59837 /* claim ref on last dentry we returned */
59838 last = fi->dentry;
59839 @@ -192,7 +194,12 @@ more:
59840
59841 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59842 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59843 - if (!dir_emit(ctx, dentry->d_name.name,
59844 + name = dentry->d_name.name;
59845 + if (name == dentry->d_iname) {
59846 + memcpy(d_name, name, dentry->d_name.len);
59847 + name = d_name;
59848 + }
59849 + if (!dir_emit(ctx, name,
59850 dentry->d_name.len,
59851 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59852 dentry->d_inode->i_mode >> 12)) {
59853 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59854 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59855 struct ceph_mds_client *mdsc = fsc->mdsc;
59856 unsigned frag = fpos_frag(ctx->pos);
59857 - int off = fpos_off(ctx->pos);
59858 + unsigned int off = fpos_off(ctx->pos);
59859 int err;
59860 u32 ftype;
59861 struct ceph_mds_reply_info_parsed *rinfo;
59862 diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
59863 index a822a6e..4644256 100644
59864 --- a/fs/ceph/ioctl.c
59865 +++ b/fs/ceph/ioctl.c
59866 @@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
59867 /* validate striping parameters */
59868 if ((l->object_size & ~PAGE_MASK) ||
59869 (l->stripe_unit & ~PAGE_MASK) ||
59870 - (l->stripe_unit != 0 &&
59871 + ((unsigned)l->stripe_unit != 0 &&
59872 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
59873 return -EINVAL;
59874
59875 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59876 index f6e1237..796ffd1 100644
59877 --- a/fs/ceph/super.c
59878 +++ b/fs/ceph/super.c
59879 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59880 /*
59881 * construct our own bdi so we can control readahead, etc.
59882 */
59883 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59884 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59885
59886 static int ceph_register_bdi(struct super_block *sb,
59887 struct ceph_fs_client *fsc)
59888 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59889 default_backing_dev_info.ra_pages;
59890
59891 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59892 - atomic_long_inc_return(&bdi_seq));
59893 + atomic_long_inc_return_unchecked(&bdi_seq));
59894 if (!err)
59895 sb->s_bdi = &fsc->backing_dev_info;
59896 return err;
59897 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59898 index 44ec726..bcb06a3 100644
59899 --- a/fs/cifs/cifs_debug.c
59900 +++ b/fs/cifs/cifs_debug.c
59901 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59902
59903 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59904 #ifdef CONFIG_CIFS_STATS2
59905 - atomic_set(&totBufAllocCount, 0);
59906 - atomic_set(&totSmBufAllocCount, 0);
59907 + atomic_set_unchecked(&totBufAllocCount, 0);
59908 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59909 #endif /* CONFIG_CIFS_STATS2 */
59910 spin_lock(&cifs_tcp_ses_lock);
59911 list_for_each(tmp1, &cifs_tcp_ses_list) {
59912 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59913 tcon = list_entry(tmp3,
59914 struct cifs_tcon,
59915 tcon_list);
59916 - atomic_set(&tcon->num_smbs_sent, 0);
59917 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59918 if (server->ops->clear_stats)
59919 server->ops->clear_stats(tcon);
59920 }
59921 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59922 smBufAllocCount.counter, cifs_min_small);
59923 #ifdef CONFIG_CIFS_STATS2
59924 seq_printf(m, "Total Large %d Small %d Allocations\n",
59925 - atomic_read(&totBufAllocCount),
59926 - atomic_read(&totSmBufAllocCount));
59927 + atomic_read_unchecked(&totBufAllocCount),
59928 + atomic_read_unchecked(&totSmBufAllocCount));
59929 #endif /* CONFIG_CIFS_STATS2 */
59930
59931 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59932 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59933 if (tcon->need_reconnect)
59934 seq_puts(m, "\tDISCONNECTED ");
59935 seq_printf(m, "\nSMBs: %d",
59936 - atomic_read(&tcon->num_smbs_sent));
59937 + atomic_read_unchecked(&tcon->num_smbs_sent));
59938 if (server->ops->print_stats)
59939 server->ops->print_stats(m, tcon);
59940 }
59941 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59942 index 889b984..fcb8431 100644
59943 --- a/fs/cifs/cifsfs.c
59944 +++ b/fs/cifs/cifsfs.c
59945 @@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
59946 */
59947 cifs_req_cachep = kmem_cache_create("cifs_request",
59948 CIFSMaxBufSize + max_hdr_size, 0,
59949 - SLAB_HWCACHE_ALIGN, NULL);
59950 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59951 if (cifs_req_cachep == NULL)
59952 return -ENOMEM;
59953
59954 @@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
59955 efficient to alloc 1 per page off the slab compared to 17K (5page)
59956 alloc of large cifs buffers even when page debugging is on */
59957 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59958 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59959 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59960 NULL);
59961 if (cifs_sm_req_cachep == NULL) {
59962 mempool_destroy(cifs_req_poolp);
59963 @@ -1204,8 +1204,8 @@ init_cifs(void)
59964 atomic_set(&bufAllocCount, 0);
59965 atomic_set(&smBufAllocCount, 0);
59966 #ifdef CONFIG_CIFS_STATS2
59967 - atomic_set(&totBufAllocCount, 0);
59968 - atomic_set(&totSmBufAllocCount, 0);
59969 + atomic_set_unchecked(&totBufAllocCount, 0);
59970 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59971 #endif /* CONFIG_CIFS_STATS2 */
59972
59973 atomic_set(&midCount, 0);
59974 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59975 index 25b8392..01e46dc 100644
59976 --- a/fs/cifs/cifsglob.h
59977 +++ b/fs/cifs/cifsglob.h
59978 @@ -821,35 +821,35 @@ struct cifs_tcon {
59979 __u16 Flags; /* optional support bits */
59980 enum statusEnum tidStatus;
59981 #ifdef CONFIG_CIFS_STATS
59982 - atomic_t num_smbs_sent;
59983 + atomic_unchecked_t num_smbs_sent;
59984 union {
59985 struct {
59986 - atomic_t num_writes;
59987 - atomic_t num_reads;
59988 - atomic_t num_flushes;
59989 - atomic_t num_oplock_brks;
59990 - atomic_t num_opens;
59991 - atomic_t num_closes;
59992 - atomic_t num_deletes;
59993 - atomic_t num_mkdirs;
59994 - atomic_t num_posixopens;
59995 - atomic_t num_posixmkdirs;
59996 - atomic_t num_rmdirs;
59997 - atomic_t num_renames;
59998 - atomic_t num_t2renames;
59999 - atomic_t num_ffirst;
60000 - atomic_t num_fnext;
60001 - atomic_t num_fclose;
60002 - atomic_t num_hardlinks;
60003 - atomic_t num_symlinks;
60004 - atomic_t num_locks;
60005 - atomic_t num_acl_get;
60006 - atomic_t num_acl_set;
60007 + atomic_unchecked_t num_writes;
60008 + atomic_unchecked_t num_reads;
60009 + atomic_unchecked_t num_flushes;
60010 + atomic_unchecked_t num_oplock_brks;
60011 + atomic_unchecked_t num_opens;
60012 + atomic_unchecked_t num_closes;
60013 + atomic_unchecked_t num_deletes;
60014 + atomic_unchecked_t num_mkdirs;
60015 + atomic_unchecked_t num_posixopens;
60016 + atomic_unchecked_t num_posixmkdirs;
60017 + atomic_unchecked_t num_rmdirs;
60018 + atomic_unchecked_t num_renames;
60019 + atomic_unchecked_t num_t2renames;
60020 + atomic_unchecked_t num_ffirst;
60021 + atomic_unchecked_t num_fnext;
60022 + atomic_unchecked_t num_fclose;
60023 + atomic_unchecked_t num_hardlinks;
60024 + atomic_unchecked_t num_symlinks;
60025 + atomic_unchecked_t num_locks;
60026 + atomic_unchecked_t num_acl_get;
60027 + atomic_unchecked_t num_acl_set;
60028 } cifs_stats;
60029 #ifdef CONFIG_CIFS_SMB2
60030 struct {
60031 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60032 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60033 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60034 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60035 } smb2_stats;
60036 #endif /* CONFIG_CIFS_SMB2 */
60037 } stats;
60038 @@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60039 }
60040
60041 #ifdef CONFIG_CIFS_STATS
60042 -#define cifs_stats_inc atomic_inc
60043 +#define cifs_stats_inc atomic_inc_unchecked
60044
60045 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60046 unsigned int bytes)
60047 @@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60048 /* Various Debug counters */
60049 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60050 #ifdef CONFIG_CIFS_STATS2
60051 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60052 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60053 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60054 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60055 #endif
60056 GLOBAL_EXTERN atomic_t smBufAllocCount;
60057 GLOBAL_EXTERN atomic_t midCount;
60058 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60059 index 5f29354..359bc0d 100644
60060 --- a/fs/cifs/file.c
60061 +++ b/fs/cifs/file.c
60062 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60063 index = mapping->writeback_index; /* Start from prev offset */
60064 end = -1;
60065 } else {
60066 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60067 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60068 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60069 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60070 range_whole = true;
60071 + index = 0;
60072 + end = ULONG_MAX;
60073 + } else {
60074 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60075 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60076 + }
60077 scanned = true;
60078 }
60079 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60080 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60081 index b7415d5..3984ec0 100644
60082 --- a/fs/cifs/misc.c
60083 +++ b/fs/cifs/misc.c
60084 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60085 memset(ret_buf, 0, buf_size + 3);
60086 atomic_inc(&bufAllocCount);
60087 #ifdef CONFIG_CIFS_STATS2
60088 - atomic_inc(&totBufAllocCount);
60089 + atomic_inc_unchecked(&totBufAllocCount);
60090 #endif /* CONFIG_CIFS_STATS2 */
60091 }
60092
60093 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60094 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60095 atomic_inc(&smBufAllocCount);
60096 #ifdef CONFIG_CIFS_STATS2
60097 - atomic_inc(&totSmBufAllocCount);
60098 + atomic_inc_unchecked(&totSmBufAllocCount);
60099 #endif /* CONFIG_CIFS_STATS2 */
60100
60101 }
60102 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60103 index 52131d8..fd79e97 100644
60104 --- a/fs/cifs/smb1ops.c
60105 +++ b/fs/cifs/smb1ops.c
60106 @@ -626,27 +626,27 @@ static void
60107 cifs_clear_stats(struct cifs_tcon *tcon)
60108 {
60109 #ifdef CONFIG_CIFS_STATS
60110 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60111 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60112 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60113 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60114 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60115 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60116 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60117 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60118 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60119 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60120 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60121 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60122 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60123 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60124 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60125 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60126 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60127 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60128 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60129 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60130 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60131 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60132 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60133 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60134 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60135 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60136 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60137 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60138 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60139 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60140 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60141 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60142 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60143 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60144 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60145 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60146 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60147 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60148 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60149 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60150 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60151 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60152 #endif
60153 }
60154
60155 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60156 {
60157 #ifdef CONFIG_CIFS_STATS
60158 seq_printf(m, " Oplocks breaks: %d",
60159 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60160 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60161 seq_printf(m, "\nReads: %d Bytes: %llu",
60162 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60163 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60164 (long long)(tcon->bytes_read));
60165 seq_printf(m, "\nWrites: %d Bytes: %llu",
60166 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60167 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60168 (long long)(tcon->bytes_written));
60169 seq_printf(m, "\nFlushes: %d",
60170 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60171 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60172 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60173 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60174 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60175 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60176 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60177 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60178 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60179 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60180 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60181 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60182 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60183 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60184 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60185 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60186 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60187 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60188 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60189 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60190 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60191 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60192 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60193 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60194 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60195 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60196 seq_printf(m, "\nRenames: %d T2 Renames %d",
60197 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60198 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60199 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60200 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60201 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60202 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60203 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60204 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60205 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60206 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60207 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60208 #endif
60209 }
60210
60211 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60212 index f522193..586121b 100644
60213 --- a/fs/cifs/smb2ops.c
60214 +++ b/fs/cifs/smb2ops.c
60215 @@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60216 #ifdef CONFIG_CIFS_STATS
60217 int i;
60218 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60219 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60220 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60221 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60222 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60223 }
60224 #endif
60225 }
60226 @@ -455,65 +455,65 @@ static void
60227 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60228 {
60229 #ifdef CONFIG_CIFS_STATS
60230 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60231 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60232 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60233 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60234 seq_printf(m, "\nNegotiates: %d sent %d failed",
60235 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60236 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60237 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60238 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60239 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60240 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60241 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60242 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60243 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60244 seq_printf(m, "\nLogoffs: %d sent %d failed",
60245 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60246 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60247 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60248 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60249 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60250 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60251 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60252 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60253 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60254 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60255 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60256 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60257 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60258 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60259 seq_printf(m, "\nCreates: %d sent %d failed",
60260 - atomic_read(&sent[SMB2_CREATE_HE]),
60261 - atomic_read(&failed[SMB2_CREATE_HE]));
60262 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60263 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60264 seq_printf(m, "\nCloses: %d sent %d failed",
60265 - atomic_read(&sent[SMB2_CLOSE_HE]),
60266 - atomic_read(&failed[SMB2_CLOSE_HE]));
60267 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60268 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60269 seq_printf(m, "\nFlushes: %d sent %d failed",
60270 - atomic_read(&sent[SMB2_FLUSH_HE]),
60271 - atomic_read(&failed[SMB2_FLUSH_HE]));
60272 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60273 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60274 seq_printf(m, "\nReads: %d sent %d failed",
60275 - atomic_read(&sent[SMB2_READ_HE]),
60276 - atomic_read(&failed[SMB2_READ_HE]));
60277 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60278 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60279 seq_printf(m, "\nWrites: %d sent %d failed",
60280 - atomic_read(&sent[SMB2_WRITE_HE]),
60281 - atomic_read(&failed[SMB2_WRITE_HE]));
60282 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60283 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60284 seq_printf(m, "\nLocks: %d sent %d failed",
60285 - atomic_read(&sent[SMB2_LOCK_HE]),
60286 - atomic_read(&failed[SMB2_LOCK_HE]));
60287 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60288 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60289 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60290 - atomic_read(&sent[SMB2_IOCTL_HE]),
60291 - atomic_read(&failed[SMB2_IOCTL_HE]));
60292 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60293 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60294 seq_printf(m, "\nCancels: %d sent %d failed",
60295 - atomic_read(&sent[SMB2_CANCEL_HE]),
60296 - atomic_read(&failed[SMB2_CANCEL_HE]));
60297 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60298 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60299 seq_printf(m, "\nEchos: %d sent %d failed",
60300 - atomic_read(&sent[SMB2_ECHO_HE]),
60301 - atomic_read(&failed[SMB2_ECHO_HE]));
60302 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60303 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60304 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60305 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60306 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60307 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60308 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60309 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60310 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60311 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60312 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60313 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60314 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60315 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60316 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60317 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60318 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60319 seq_printf(m, "\nSetInfos: %d sent %d failed",
60320 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60321 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60322 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60323 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60324 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60325 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60326 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60327 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60328 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60329 #endif
60330 }
60331
60332 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60333 index 74b3a66..0c709f3 100644
60334 --- a/fs/cifs/smb2pdu.c
60335 +++ b/fs/cifs/smb2pdu.c
60336 @@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60337 default:
60338 cifs_dbg(VFS, "info level %u isn't supported\n",
60339 srch_inf->info_level);
60340 - rc = -EINVAL;
60341 - goto qdir_exit;
60342 + return -EINVAL;
60343 }
60344
60345 req->FileIndex = cpu_to_le32(index);
60346 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60347 index 278f8fd..e69c52d 100644
60348 --- a/fs/coda/cache.c
60349 +++ b/fs/coda/cache.c
60350 @@ -24,7 +24,7 @@
60351 #include "coda_linux.h"
60352 #include "coda_cache.h"
60353
60354 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60355 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60356
60357 /* replace or extend an acl cache hit */
60358 void coda_cache_enter(struct inode *inode, int mask)
60359 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60360 struct coda_inode_info *cii = ITOC(inode);
60361
60362 spin_lock(&cii->c_lock);
60363 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60364 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60365 if (!uid_eq(cii->c_uid, current_fsuid())) {
60366 cii->c_uid = current_fsuid();
60367 cii->c_cached_perm = mask;
60368 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60369 {
60370 struct coda_inode_info *cii = ITOC(inode);
60371 spin_lock(&cii->c_lock);
60372 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60373 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60374 spin_unlock(&cii->c_lock);
60375 }
60376
60377 /* remove all acl caches */
60378 void coda_cache_clear_all(struct super_block *sb)
60379 {
60380 - atomic_inc(&permission_epoch);
60381 + atomic_inc_unchecked(&permission_epoch);
60382 }
60383
60384
60385 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60386 spin_lock(&cii->c_lock);
60387 hit = (mask & cii->c_cached_perm) == mask &&
60388 uid_eq(cii->c_uid, current_fsuid()) &&
60389 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60390 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60391 spin_unlock(&cii->c_lock);
60392
60393 return hit;
60394 diff --git a/fs/compat.c b/fs/compat.c
60395 index 66d3d3c..9c10175 100644
60396 --- a/fs/compat.c
60397 +++ b/fs/compat.c
60398 @@ -54,7 +54,7 @@
60399 #include <asm/ioctls.h>
60400 #include "internal.h"
60401
60402 -int compat_log = 1;
60403 +int compat_log = 0;
60404
60405 int compat_printk(const char *fmt, ...)
60406 {
60407 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60408
60409 set_fs(KERNEL_DS);
60410 /* The __user pointer cast is valid because of the set_fs() */
60411 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60412 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60413 set_fs(oldfs);
60414 /* truncating is ok because it's a user address */
60415 if (!ret)
60416 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60417 goto out;
60418
60419 ret = -EINVAL;
60420 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60421 + if (nr_segs > UIO_MAXIOV)
60422 goto out;
60423 if (nr_segs > fast_segs) {
60424 ret = -ENOMEM;
60425 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
60426 struct compat_readdir_callback {
60427 struct dir_context ctx;
60428 struct compat_old_linux_dirent __user *dirent;
60429 + struct file * file;
60430 int result;
60431 };
60432
60433 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60434 buf->result = -EOVERFLOW;
60435 return -EOVERFLOW;
60436 }
60437 +
60438 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60439 + return 0;
60440 +
60441 buf->result++;
60442 dirent = buf->dirent;
60443 if (!access_ok(VERIFY_WRITE, dirent,
60444 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60445 if (!f.file)
60446 return -EBADF;
60447
60448 + buf.file = f.file;
60449 error = iterate_dir(f.file, &buf.ctx);
60450 if (buf.result)
60451 error = buf.result;
60452 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
60453 struct dir_context ctx;
60454 struct compat_linux_dirent __user *current_dir;
60455 struct compat_linux_dirent __user *previous;
60456 + struct file * file;
60457 int count;
60458 int error;
60459 };
60460 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60461 buf->error = -EOVERFLOW;
60462 return -EOVERFLOW;
60463 }
60464 +
60465 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60466 + return 0;
60467 +
60468 dirent = buf->previous;
60469 if (dirent) {
60470 if (__put_user(offset, &dirent->d_off))
60471 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60472 if (!f.file)
60473 return -EBADF;
60474
60475 + buf.file = f.file;
60476 error = iterate_dir(f.file, &buf.ctx);
60477 if (error >= 0)
60478 error = buf.error;
60479 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
60480 struct dir_context ctx;
60481 struct linux_dirent64 __user *current_dir;
60482 struct linux_dirent64 __user *previous;
60483 + struct file * file;
60484 int count;
60485 int error;
60486 };
60487 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60488 buf->error = -EINVAL; /* only used if we fail.. */
60489 if (reclen > buf->count)
60490 return -EINVAL;
60491 +
60492 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60493 + return 0;
60494 +
60495 dirent = buf->previous;
60496
60497 if (dirent) {
60498 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60499 if (!f.file)
60500 return -EBADF;
60501
60502 + buf.file = f.file;
60503 error = iterate_dir(f.file, &buf.ctx);
60504 if (error >= 0)
60505 error = buf.error;
60506 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60507 index 4d24d17..4f8c09e 100644
60508 --- a/fs/compat_binfmt_elf.c
60509 +++ b/fs/compat_binfmt_elf.c
60510 @@ -30,11 +30,13 @@
60511 #undef elf_phdr
60512 #undef elf_shdr
60513 #undef elf_note
60514 +#undef elf_dyn
60515 #undef elf_addr_t
60516 #define elfhdr elf32_hdr
60517 #define elf_phdr elf32_phdr
60518 #define elf_shdr elf32_shdr
60519 #define elf_note elf32_note
60520 +#define elf_dyn Elf32_Dyn
60521 #define elf_addr_t Elf32_Addr
60522
60523 /*
60524 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60525 index afec645..9c65620 100644
60526 --- a/fs/compat_ioctl.c
60527 +++ b/fs/compat_ioctl.c
60528 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60529 return -EFAULT;
60530 if (__get_user(udata, &ss32->iomem_base))
60531 return -EFAULT;
60532 - ss.iomem_base = compat_ptr(udata);
60533 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60534 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60535 __get_user(ss.port_high, &ss32->port_high))
60536 return -EFAULT;
60537 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60538 for (i = 0; i < nmsgs; i++) {
60539 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60540 return -EFAULT;
60541 - if (get_user(datap, &umsgs[i].buf) ||
60542 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60543 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60544 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60545 return -EFAULT;
60546 }
60547 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60548 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60549 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60550 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60551 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60552 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60553 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60554 return -EFAULT;
60555
60556 return ioctl_preallocate(file, p);
60557 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60558 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60559 {
60560 unsigned int a, b;
60561 - a = *(unsigned int *)p;
60562 - b = *(unsigned int *)q;
60563 + a = *(const unsigned int *)p;
60564 + b = *(const unsigned int *)q;
60565 if (a > b)
60566 return 1;
60567 if (a < b)
60568 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60569 index 668dcab..daebcd6 100644
60570 --- a/fs/configfs/dir.c
60571 +++ b/fs/configfs/dir.c
60572 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60573 }
60574 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60575 struct configfs_dirent *next;
60576 - const char *name;
60577 + const unsigned char * name;
60578 + char d_name[sizeof(next->s_dentry->d_iname)];
60579 int len;
60580 struct inode *inode = NULL;
60581
60582 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60583 continue;
60584
60585 name = configfs_get_name(next);
60586 - len = strlen(name);
60587 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60588 + len = next->s_dentry->d_name.len;
60589 + memcpy(d_name, name, len);
60590 + name = d_name;
60591 + } else
60592 + len = strlen(name);
60593
60594 /*
60595 * We'll have a dentry and an inode for
60596 diff --git a/fs/coredump.c b/fs/coredump.c
60597 index a93f7e6..d58bcbe 100644
60598 --- a/fs/coredump.c
60599 +++ b/fs/coredump.c
60600 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
60601 struct pipe_inode_info *pipe = file->private_data;
60602
60603 pipe_lock(pipe);
60604 - pipe->readers++;
60605 - pipe->writers--;
60606 + atomic_inc(&pipe->readers);
60607 + atomic_dec(&pipe->writers);
60608 wake_up_interruptible_sync(&pipe->wait);
60609 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60610 pipe_unlock(pipe);
60611 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
60612 * We actually want wait_event_freezable() but then we need
60613 * to clear TIF_SIGPENDING and improve dump_interrupted().
60614 */
60615 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60616 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60617
60618 pipe_lock(pipe);
60619 - pipe->readers--;
60620 - pipe->writers++;
60621 + atomic_dec(&pipe->readers);
60622 + atomic_inc(&pipe->writers);
60623 pipe_unlock(pipe);
60624 }
60625
60626 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
60627 struct files_struct *displaced;
60628 bool need_nonrelative = false;
60629 bool core_dumped = false;
60630 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60631 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60632 + long signr = siginfo->si_signo;
60633 + int dumpable;
60634 struct coredump_params cprm = {
60635 .siginfo = siginfo,
60636 .regs = signal_pt_regs(),
60637 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
60638 .mm_flags = mm->flags,
60639 };
60640
60641 - audit_core_dumps(siginfo->si_signo);
60642 + audit_core_dumps(signr);
60643 +
60644 + dumpable = __get_dumpable(cprm.mm_flags);
60645 +
60646 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60647 + gr_handle_brute_attach(dumpable);
60648
60649 binfmt = mm->binfmt;
60650 if (!binfmt || !binfmt->core_dump)
60651 goto fail;
60652 - if (!__get_dumpable(cprm.mm_flags))
60653 + if (!dumpable)
60654 goto fail;
60655
60656 cred = prepare_creds();
60657 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
60658 need_nonrelative = true;
60659 }
60660
60661 - retval = coredump_wait(siginfo->si_signo, &core_state);
60662 + retval = coredump_wait(signr, &core_state);
60663 if (retval < 0)
60664 goto fail_creds;
60665
60666 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
60667 }
60668 cprm.limit = RLIM_INFINITY;
60669
60670 - dump_count = atomic_inc_return(&core_dump_count);
60671 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60672 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60673 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60674 task_tgid_vnr(current), current->comm);
60675 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
60676 } else {
60677 struct inode *inode;
60678
60679 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60680 +
60681 if (cprm.limit < binfmt->min_coredump)
60682 goto fail_unlock;
60683
60684 @@ -673,7 +682,7 @@ close_fail:
60685 filp_close(cprm.file, NULL);
60686 fail_dropcount:
60687 if (ispipe)
60688 - atomic_dec(&core_dump_count);
60689 + atomic_dec_unchecked(&core_dump_count);
60690 fail_unlock:
60691 kfree(cn.corename);
60692 coredump_finish(mm, core_dumped);
60693 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60694 struct file *file = cprm->file;
60695 loff_t pos = file->f_pos;
60696 ssize_t n;
60697 +
60698 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60699 if (cprm->written + nr > cprm->limit)
60700 return 0;
60701 while (nr) {
60702 diff --git a/fs/dcache.c b/fs/dcache.c
60703 index 34b40be8..2003532 100644
60704 --- a/fs/dcache.c
60705 +++ b/fs/dcache.c
60706 @@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
60707 * dentry_iput drops the locks, at which point nobody (except
60708 * transient RCU lookups) can reach this dentry.
60709 */
60710 - BUG_ON((int)dentry->d_lockref.count > 0);
60711 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60712 this_cpu_dec(nr_dentry);
60713 if (dentry->d_op && dentry->d_op->d_release)
60714 dentry->d_op->d_release(dentry);
60715 @@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60716 struct dentry *parent = dentry->d_parent;
60717 if (IS_ROOT(dentry))
60718 return NULL;
60719 - if (unlikely((int)dentry->d_lockref.count < 0))
60720 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60721 return NULL;
60722 if (likely(spin_trylock(&parent->d_lock)))
60723 return parent;
60724 @@ -608,7 +608,7 @@ repeat:
60725 dentry->d_flags |= DCACHE_REFERENCED;
60726 dentry_lru_add(dentry);
60727
60728 - dentry->d_lockref.count--;
60729 + __lockref_dec(&dentry->d_lockref);
60730 spin_unlock(&dentry->d_lock);
60731 return;
60732
60733 @@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
60734 * We also need to leave mountpoints alone,
60735 * directory or not.
60736 */
60737 - if (dentry->d_lockref.count > 1 && dentry->d_inode) {
60738 + if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
60739 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
60740 spin_unlock(&dentry->d_lock);
60741 return -EBUSY;
60742 @@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
60743 /* This must be called with d_lock held */
60744 static inline void __dget_dlock(struct dentry *dentry)
60745 {
60746 - dentry->d_lockref.count++;
60747 + __lockref_inc(&dentry->d_lockref);
60748 }
60749
60750 static inline void __dget(struct dentry *dentry)
60751 @@ -720,8 +720,8 @@ repeat:
60752 goto repeat;
60753 }
60754 rcu_read_unlock();
60755 - BUG_ON(!ret->d_lockref.count);
60756 - ret->d_lockref.count++;
60757 + BUG_ON(!__lockref_read(&ret->d_lockref));
60758 + __lockref_inc(&ret->d_lockref);
60759 spin_unlock(&ret->d_lock);
60760 return ret;
60761 }
60762 @@ -798,7 +798,7 @@ restart:
60763 spin_lock(&inode->i_lock);
60764 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
60765 spin_lock(&dentry->d_lock);
60766 - if (!dentry->d_lockref.count) {
60767 + if (!__lockref_read(&dentry->d_lockref)) {
60768 /*
60769 * inform the fs via d_prune that this dentry
60770 * is about to be unhashed and destroyed.
60771 @@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
60772 * We found an inuse dentry which was not removed from
60773 * the LRU because of laziness during lookup. Do not free it.
60774 */
60775 - if ((int)dentry->d_lockref.count > 0) {
60776 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60777 spin_unlock(&dentry->d_lock);
60778 if (parent)
60779 spin_unlock(&parent->d_lock);
60780 @@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
60781 dentry = parent;
60782 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60783 parent = lock_parent(dentry);
60784 - if (dentry->d_lockref.count != 1) {
60785 - dentry->d_lockref.count--;
60786 + if (__lockref_read(&dentry->d_lockref) != 1) {
60787 + __lockref_inc(&dentry->d_lockref);
60788 spin_unlock(&dentry->d_lock);
60789 if (parent)
60790 spin_unlock(&parent->d_lock);
60791 @@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60792 * counts, just remove them from the LRU. Otherwise give them
60793 * another pass through the LRU.
60794 */
60795 - if (dentry->d_lockref.count) {
60796 + if (__lockref_read(&dentry->d_lockref) > 0) {
60797 d_lru_isolate(dentry);
60798 spin_unlock(&dentry->d_lock);
60799 return LRU_REMOVED;
60800 @@ -1149,6 +1149,7 @@ out_unlock:
60801 return;
60802
60803 rename_retry:
60804 + done_seqretry(&rename_lock, seq);
60805 if (!retry)
60806 return;
60807 seq = 1;
60808 @@ -1255,7 +1256,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60809 } else {
60810 if (dentry->d_flags & DCACHE_LRU_LIST)
60811 d_lru_del(dentry);
60812 - if (!dentry->d_lockref.count) {
60813 + if (!__lockref_read(&dentry->d_lockref)) {
60814 d_shrink_add(dentry, &data->dispose);
60815 data->found++;
60816 }
60817 @@ -1303,7 +1304,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60818 return D_WALK_CONTINUE;
60819
60820 /* root with refcount 1 is fine */
60821 - if (dentry == _data && dentry->d_lockref.count == 1)
60822 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60823 return D_WALK_CONTINUE;
60824
60825 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60826 @@ -1312,7 +1313,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60827 dentry->d_inode ?
60828 dentry->d_inode->i_ino : 0UL,
60829 dentry,
60830 - dentry->d_lockref.count,
60831 + __lockref_read(&dentry->d_lockref),
60832 dentry->d_sb->s_type->name,
60833 dentry->d_sb->s_id);
60834 WARN_ON(1);
60835 @@ -1438,7 +1439,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60836 */
60837 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60838 if (name->len > DNAME_INLINE_LEN-1) {
60839 - dname = kmalloc(name->len + 1, GFP_KERNEL);
60840 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
60841 if (!dname) {
60842 kmem_cache_free(dentry_cache, dentry);
60843 return NULL;
60844 @@ -1456,7 +1457,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60845 smp_wmb();
60846 dentry->d_name.name = dname;
60847
60848 - dentry->d_lockref.count = 1;
60849 + __lockref_set(&dentry->d_lockref, 1);
60850 dentry->d_flags = 0;
60851 spin_lock_init(&dentry->d_lock);
60852 seqcount_init(&dentry->d_seq);
60853 @@ -2196,7 +2197,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60854 goto next;
60855 }
60856
60857 - dentry->d_lockref.count++;
60858 + __lockref_inc(&dentry->d_lockref);
60859 found = dentry;
60860 spin_unlock(&dentry->d_lock);
60861 break;
60862 @@ -2295,7 +2296,7 @@ again:
60863 spin_lock(&dentry->d_lock);
60864 inode = dentry->d_inode;
60865 isdir = S_ISDIR(inode->i_mode);
60866 - if (dentry->d_lockref.count == 1) {
60867 + if (__lockref_read(&dentry->d_lockref) == 1) {
60868 if (!spin_trylock(&inode->i_lock)) {
60869 spin_unlock(&dentry->d_lock);
60870 cpu_relax();
60871 @@ -3307,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60872
60873 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60874 dentry->d_flags |= DCACHE_GENOCIDE;
60875 - dentry->d_lockref.count--;
60876 + __lockref_dec(&dentry->d_lockref);
60877 }
60878 }
60879 return D_WALK_CONTINUE;
60880 @@ -3423,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
60881 mempages -= reserve;
60882
60883 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60884 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60885 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60886 + SLAB_NO_SANITIZE, NULL);
60887
60888 dcache_init();
60889 inode_init();
60890 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60891 index 1e3b99d..6512101 100644
60892 --- a/fs/debugfs/inode.c
60893 +++ b/fs/debugfs/inode.c
60894 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60895 */
60896 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60897 {
60898 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60899 + return __create_file(name, S_IFDIR | S_IRWXU,
60900 +#else
60901 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60902 +#endif
60903 parent, NULL, NULL);
60904 }
60905 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60906 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60907 index 57ee4c5..ecb13b0 100644
60908 --- a/fs/ecryptfs/inode.c
60909 +++ b/fs/ecryptfs/inode.c
60910 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60911 old_fs = get_fs();
60912 set_fs(get_ds());
60913 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60914 - (char __user *)lower_buf,
60915 + (char __force_user *)lower_buf,
60916 PATH_MAX);
60917 set_fs(old_fs);
60918 if (rc < 0)
60919 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60920 index e4141f2..d8263e8 100644
60921 --- a/fs/ecryptfs/miscdev.c
60922 +++ b/fs/ecryptfs/miscdev.c
60923 @@ -304,7 +304,7 @@ check_list:
60924 goto out_unlock_msg_ctx;
60925 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60926 if (msg_ctx->msg) {
60927 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
60928 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60929 goto out_unlock_msg_ctx;
60930 i += packet_length_size;
60931 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60932 diff --git a/fs/exec.c b/fs/exec.c
60933 index a2b42a9..1e924b3 100644
60934 --- a/fs/exec.c
60935 +++ b/fs/exec.c
60936 @@ -56,8 +56,20 @@
60937 #include <linux/pipe_fs_i.h>
60938 #include <linux/oom.h>
60939 #include <linux/compat.h>
60940 +#include <linux/random.h>
60941 +#include <linux/seq_file.h>
60942 +#include <linux/coredump.h>
60943 +#include <linux/mman.h>
60944 +
60945 +#ifdef CONFIG_PAX_REFCOUNT
60946 +#include <linux/kallsyms.h>
60947 +#include <linux/kdebug.h>
60948 +#endif
60949 +
60950 +#include <trace/events/fs.h>
60951
60952 #include <asm/uaccess.h>
60953 +#include <asm/sections.h>
60954 #include <asm/mmu_context.h>
60955 #include <asm/tlb.h>
60956
60957 @@ -66,19 +78,34 @@
60958
60959 #include <trace/events/sched.h>
60960
60961 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60962 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60963 +{
60964 + 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");
60965 +}
60966 +#endif
60967 +
60968 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60969 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60970 +EXPORT_SYMBOL(pax_set_initial_flags_func);
60971 +#endif
60972 +
60973 int suid_dumpable = 0;
60974
60975 static LIST_HEAD(formats);
60976 static DEFINE_RWLOCK(binfmt_lock);
60977
60978 +extern int gr_process_kernel_exec_ban(void);
60979 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
60980 +
60981 void __register_binfmt(struct linux_binfmt * fmt, int insert)
60982 {
60983 BUG_ON(!fmt);
60984 if (WARN_ON(!fmt->load_binary))
60985 return;
60986 write_lock(&binfmt_lock);
60987 - insert ? list_add(&fmt->lh, &formats) :
60988 - list_add_tail(&fmt->lh, &formats);
60989 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
60990 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
60991 write_unlock(&binfmt_lock);
60992 }
60993
60994 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
60995 void unregister_binfmt(struct linux_binfmt * fmt)
60996 {
60997 write_lock(&binfmt_lock);
60998 - list_del(&fmt->lh);
60999 + pax_list_del((struct list_head *)&fmt->lh);
61000 write_unlock(&binfmt_lock);
61001 }
61002
61003 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61004 int write)
61005 {
61006 struct page *page;
61007 - int ret;
61008
61009 -#ifdef CONFIG_STACK_GROWSUP
61010 - if (write) {
61011 - ret = expand_downwards(bprm->vma, pos);
61012 - if (ret < 0)
61013 - return NULL;
61014 - }
61015 -#endif
61016 - ret = get_user_pages(current, bprm->mm, pos,
61017 - 1, write, 1, &page, NULL);
61018 - if (ret <= 0)
61019 + if (0 > expand_downwards(bprm->vma, pos))
61020 + return NULL;
61021 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61022 return NULL;
61023
61024 if (write) {
61025 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61026 if (size <= ARG_MAX)
61027 return page;
61028
61029 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61030 + // only allow 512KB for argv+env on suid/sgid binaries
61031 + // to prevent easy ASLR exhaustion
61032 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61033 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61034 + (size > (512 * 1024))) {
61035 + put_page(page);
61036 + return NULL;
61037 + }
61038 +#endif
61039 +
61040 /*
61041 * Limit to 1/4-th the stack size for the argv+env strings.
61042 * This ensures that:
61043 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61044 vma->vm_end = STACK_TOP_MAX;
61045 vma->vm_start = vma->vm_end - PAGE_SIZE;
61046 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61047 +
61048 +#ifdef CONFIG_PAX_SEGMEXEC
61049 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61050 +#endif
61051 +
61052 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61053 INIT_LIST_HEAD(&vma->anon_vma_chain);
61054
61055 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61056 mm->stack_vm = mm->total_vm = 1;
61057 up_write(&mm->mmap_sem);
61058 bprm->p = vma->vm_end - sizeof(void *);
61059 +
61060 +#ifdef CONFIG_PAX_RANDUSTACK
61061 + if (randomize_va_space)
61062 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61063 +#endif
61064 +
61065 return 0;
61066 err:
61067 up_write(&mm->mmap_sem);
61068 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61069 } ptr;
61070 };
61071
61072 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61073 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61074 {
61075 const char __user *native;
61076
61077 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61078 compat_uptr_t compat;
61079
61080 if (get_user(compat, argv.ptr.compat + nr))
61081 - return ERR_PTR(-EFAULT);
61082 + return (const char __force_user *)ERR_PTR(-EFAULT);
61083
61084 return compat_ptr(compat);
61085 }
61086 #endif
61087
61088 if (get_user(native, argv.ptr.native + nr))
61089 - return ERR_PTR(-EFAULT);
61090 + return (const char __force_user *)ERR_PTR(-EFAULT);
61091
61092 return native;
61093 }
61094 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61095 if (!p)
61096 break;
61097
61098 - if (IS_ERR(p))
61099 + if (IS_ERR((const char __force_kernel *)p))
61100 return -EFAULT;
61101
61102 if (i >= max)
61103 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61104
61105 ret = -EFAULT;
61106 str = get_user_arg_ptr(argv, argc);
61107 - if (IS_ERR(str))
61108 + if (IS_ERR((const char __force_kernel *)str))
61109 goto out;
61110
61111 len = strnlen_user(str, MAX_ARG_STRLEN);
61112 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61113 int r;
61114 mm_segment_t oldfs = get_fs();
61115 struct user_arg_ptr argv = {
61116 - .ptr.native = (const char __user *const __user *)__argv,
61117 + .ptr.native = (const char __user * const __force_user *)__argv,
61118 };
61119
61120 set_fs(KERNEL_DS);
61121 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61122 unsigned long new_end = old_end - shift;
61123 struct mmu_gather tlb;
61124
61125 - BUG_ON(new_start > new_end);
61126 + if (new_start >= new_end || new_start < mmap_min_addr)
61127 + return -ENOMEM;
61128
61129 /*
61130 * ensure there are no vmas between where we want to go
61131 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61132 if (vma != find_vma(mm, new_start))
61133 return -EFAULT;
61134
61135 +#ifdef CONFIG_PAX_SEGMEXEC
61136 + BUG_ON(pax_find_mirror_vma(vma));
61137 +#endif
61138 +
61139 /*
61140 * cover the whole range: [new_start, old_end)
61141 */
61142 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61143 stack_top = arch_align_stack(stack_top);
61144 stack_top = PAGE_ALIGN(stack_top);
61145
61146 - if (unlikely(stack_top < mmap_min_addr) ||
61147 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61148 - return -ENOMEM;
61149 -
61150 stack_shift = vma->vm_end - stack_top;
61151
61152 bprm->p -= stack_shift;
61153 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61154 bprm->exec -= stack_shift;
61155
61156 down_write(&mm->mmap_sem);
61157 +
61158 + /* Move stack pages down in memory. */
61159 + if (stack_shift) {
61160 + ret = shift_arg_pages(vma, stack_shift);
61161 + if (ret)
61162 + goto out_unlock;
61163 + }
61164 +
61165 vm_flags = VM_STACK_FLAGS;
61166
61167 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61168 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61169 + vm_flags &= ~VM_EXEC;
61170 +
61171 +#ifdef CONFIG_PAX_MPROTECT
61172 + if (mm->pax_flags & MF_PAX_MPROTECT)
61173 + vm_flags &= ~VM_MAYEXEC;
61174 +#endif
61175 +
61176 + }
61177 +#endif
61178 +
61179 /*
61180 * Adjust stack execute permissions; explicitly enable for
61181 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61182 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61183 goto out_unlock;
61184 BUG_ON(prev != vma);
61185
61186 - /* Move stack pages down in memory. */
61187 - if (stack_shift) {
61188 - ret = shift_arg_pages(vma, stack_shift);
61189 - if (ret)
61190 - goto out_unlock;
61191 - }
61192 -
61193 /* mprotect_fixup is overkill to remove the temporary stack flags */
61194 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61195
61196 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61197 #endif
61198 current->mm->start_stack = bprm->p;
61199 ret = expand_stack(vma, stack_base);
61200 +
61201 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61202 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61203 + unsigned long size;
61204 + vm_flags_t vm_flags;
61205 +
61206 + size = STACK_TOP - vma->vm_end;
61207 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61208 +
61209 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61210 +
61211 +#ifdef CONFIG_X86
61212 + if (!ret) {
61213 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61214 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61215 + }
61216 +#endif
61217 +
61218 + }
61219 +#endif
61220 +
61221 if (ret)
61222 ret = -EFAULT;
61223
61224 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61225
61226 fsnotify_open(file);
61227
61228 + trace_open_exec(name->name);
61229 +
61230 err = deny_write_access(file);
61231 if (err)
61232 goto exit;
61233 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61234 old_fs = get_fs();
61235 set_fs(get_ds());
61236 /* The cast to a user pointer is valid due to the set_fs() */
61237 - result = vfs_read(file, (void __user *)addr, count, &pos);
61238 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61239 set_fs(old_fs);
61240 return result;
61241 }
61242 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61243 tsk->mm = mm;
61244 tsk->active_mm = mm;
61245 activate_mm(active_mm, mm);
61246 + populate_stack();
61247 tsk->mm->vmacache_seqnum = 0;
61248 vmacache_flush(tsk);
61249 task_unlock(tsk);
61250 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61251 }
61252 rcu_read_unlock();
61253
61254 - if (p->fs->users > n_fs)
61255 + if (atomic_read(&p->fs->users) > n_fs)
61256 bprm->unsafe |= LSM_UNSAFE_SHARE;
61257 else
61258 p->fs->in_exec = 1;
61259 @@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61260 return ret;
61261 }
61262
61263 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61264 +static DEFINE_PER_CPU(u64, exec_counter);
61265 +static int __init init_exec_counters(void)
61266 +{
61267 + unsigned int cpu;
61268 +
61269 + for_each_possible_cpu(cpu) {
61270 + per_cpu(exec_counter, cpu) = (u64)cpu;
61271 + }
61272 +
61273 + return 0;
61274 +}
61275 +early_initcall(init_exec_counters);
61276 +static inline void increment_exec_counter(void)
61277 +{
61278 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61279 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61280 +}
61281 +#else
61282 +static inline void increment_exec_counter(void) {}
61283 +#endif
61284 +
61285 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61286 + struct user_arg_ptr argv);
61287 +
61288 /*
61289 * sys_execve() executes a new program.
61290 */
61291 @@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
61292 struct user_arg_ptr argv,
61293 struct user_arg_ptr envp)
61294 {
61295 +#ifdef CONFIG_GRKERNSEC
61296 + struct file *old_exec_file;
61297 + struct acl_subject_label *old_acl;
61298 + struct rlimit old_rlim[RLIM_NLIMITS];
61299 +#endif
61300 struct linux_binprm *bprm;
61301 struct file *file;
61302 struct files_struct *displaced;
61303 @@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
61304 if (IS_ERR(filename))
61305 return PTR_ERR(filename);
61306
61307 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61308 +
61309 /*
61310 * We move the actual failure in case of RLIMIT_NPROC excess from
61311 * set*uid() to execve() because too many poorly written programs
61312 @@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
61313 if (IS_ERR(file))
61314 goto out_unmark;
61315
61316 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61317 + retval = -EPERM;
61318 + goto out_unmark;
61319 + }
61320 +
61321 sched_exec();
61322
61323 bprm->file = file;
61324 bprm->filename = bprm->interp = filename->name;
61325
61326 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61327 + retval = -EACCES;
61328 + goto out_unmark;
61329 + }
61330 +
61331 retval = bprm_mm_init(bprm);
61332 if (retval)
61333 goto out_unmark;
61334 @@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
61335 if (retval < 0)
61336 goto out;
61337
61338 +#ifdef CONFIG_GRKERNSEC
61339 + old_acl = current->acl;
61340 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61341 + old_exec_file = current->exec_file;
61342 + get_file(file);
61343 + current->exec_file = file;
61344 +#endif
61345 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61346 + /* limit suid stack to 8MB
61347 + * we saved the old limits above and will restore them if this exec fails
61348 + */
61349 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61350 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61351 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61352 +#endif
61353 +
61354 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61355 + retval = -EPERM;
61356 + goto out_fail;
61357 + }
61358 +
61359 + if (!gr_tpe_allow(file)) {
61360 + retval = -EACCES;
61361 + goto out_fail;
61362 + }
61363 +
61364 + if (gr_check_crash_exec(file)) {
61365 + retval = -EACCES;
61366 + goto out_fail;
61367 + }
61368 +
61369 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61370 + bprm->unsafe);
61371 + if (retval < 0)
61372 + goto out_fail;
61373 +
61374 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61375 if (retval < 0)
61376 - goto out;
61377 + goto out_fail;
61378
61379 bprm->exec = bprm->p;
61380 retval = copy_strings(bprm->envc, envp, bprm);
61381 if (retval < 0)
61382 - goto out;
61383 + goto out_fail;
61384
61385 retval = copy_strings(bprm->argc, argv, bprm);
61386 if (retval < 0)
61387 - goto out;
61388 + goto out_fail;
61389 +
61390 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61391 +
61392 + gr_handle_exec_args(bprm, argv);
61393
61394 retval = exec_binprm(bprm);
61395 if (retval < 0)
61396 - goto out;
61397 + goto out_fail;
61398 +#ifdef CONFIG_GRKERNSEC
61399 + if (old_exec_file)
61400 + fput(old_exec_file);
61401 +#endif
61402
61403 /* execve succeeded */
61404 +
61405 + increment_exec_counter();
61406 current->fs->in_exec = 0;
61407 current->in_execve = 0;
61408 acct_update_integrals(current);
61409 @@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
61410 put_files_struct(displaced);
61411 return retval;
61412
61413 +out_fail:
61414 +#ifdef CONFIG_GRKERNSEC
61415 + current->acl = old_acl;
61416 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61417 + fput(current->exec_file);
61418 + current->exec_file = old_exec_file;
61419 +#endif
61420 +
61421 out:
61422 if (bprm->mm) {
61423 acct_arg_size(bprm, 0);
61424 @@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61425 return compat_do_execve(getname(filename), argv, envp);
61426 }
61427 #endif
61428 +
61429 +int pax_check_flags(unsigned long *flags)
61430 +{
61431 + int retval = 0;
61432 +
61433 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61434 + if (*flags & MF_PAX_SEGMEXEC)
61435 + {
61436 + *flags &= ~MF_PAX_SEGMEXEC;
61437 + retval = -EINVAL;
61438 + }
61439 +#endif
61440 +
61441 + if ((*flags & MF_PAX_PAGEEXEC)
61442 +
61443 +#ifdef CONFIG_PAX_PAGEEXEC
61444 + && (*flags & MF_PAX_SEGMEXEC)
61445 +#endif
61446 +
61447 + )
61448 + {
61449 + *flags &= ~MF_PAX_PAGEEXEC;
61450 + retval = -EINVAL;
61451 + }
61452 +
61453 + if ((*flags & MF_PAX_MPROTECT)
61454 +
61455 +#ifdef CONFIG_PAX_MPROTECT
61456 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61457 +#endif
61458 +
61459 + )
61460 + {
61461 + *flags &= ~MF_PAX_MPROTECT;
61462 + retval = -EINVAL;
61463 + }
61464 +
61465 + if ((*flags & MF_PAX_EMUTRAMP)
61466 +
61467 +#ifdef CONFIG_PAX_EMUTRAMP
61468 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61469 +#endif
61470 +
61471 + )
61472 + {
61473 + *flags &= ~MF_PAX_EMUTRAMP;
61474 + retval = -EINVAL;
61475 + }
61476 +
61477 + return retval;
61478 +}
61479 +
61480 +EXPORT_SYMBOL(pax_check_flags);
61481 +
61482 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61483 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61484 +{
61485 + char *pathname = d_path(path, buf, buflen);
61486 +
61487 + if (IS_ERR(pathname))
61488 + goto toolong;
61489 +
61490 + pathname = mangle_path(buf, pathname, "\t\n\\");
61491 + if (!pathname)
61492 + goto toolong;
61493 +
61494 + *pathname = 0;
61495 + return buf;
61496 +
61497 +toolong:
61498 + return "<path too long>";
61499 +}
61500 +EXPORT_SYMBOL(pax_get_path);
61501 +
61502 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61503 +{
61504 + struct task_struct *tsk = current;
61505 + struct mm_struct *mm = current->mm;
61506 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61507 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61508 + char *path_exec = NULL;
61509 + char *path_fault = NULL;
61510 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61511 + siginfo_t info = { };
61512 +
61513 + if (buffer_exec && buffer_fault) {
61514 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61515 +
61516 + down_read(&mm->mmap_sem);
61517 + vma = mm->mmap;
61518 + while (vma && (!vma_exec || !vma_fault)) {
61519 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61520 + vma_exec = vma;
61521 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61522 + vma_fault = vma;
61523 + vma = vma->vm_next;
61524 + }
61525 + if (vma_exec)
61526 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61527 + if (vma_fault) {
61528 + start = vma_fault->vm_start;
61529 + end = vma_fault->vm_end;
61530 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61531 + if (vma_fault->vm_file)
61532 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61533 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61534 + path_fault = "<heap>";
61535 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61536 + path_fault = "<stack>";
61537 + else
61538 + path_fault = "<anonymous mapping>";
61539 + }
61540 + up_read(&mm->mmap_sem);
61541 + }
61542 + if (tsk->signal->curr_ip)
61543 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61544 + else
61545 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61546 + 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),
61547 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61548 + free_page((unsigned long)buffer_exec);
61549 + free_page((unsigned long)buffer_fault);
61550 + pax_report_insns(regs, pc, sp);
61551 + info.si_signo = SIGKILL;
61552 + info.si_errno = 0;
61553 + info.si_code = SI_KERNEL;
61554 + info.si_pid = 0;
61555 + info.si_uid = 0;
61556 + do_coredump(&info);
61557 +}
61558 +#endif
61559 +
61560 +#ifdef CONFIG_PAX_REFCOUNT
61561 +void pax_report_refcount_overflow(struct pt_regs *regs)
61562 +{
61563 + if (current->signal->curr_ip)
61564 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61565 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61566 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61567 + else
61568 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61569 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61570 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61571 + preempt_disable();
61572 + show_regs(regs);
61573 + preempt_enable();
61574 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61575 +}
61576 +#endif
61577 +
61578 +#ifdef CONFIG_PAX_USERCOPY
61579 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61580 +static noinline int check_stack_object(const void *obj, unsigned long len)
61581 +{
61582 + const void * const stack = task_stack_page(current);
61583 + const void * const stackend = stack + THREAD_SIZE;
61584 +
61585 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61586 + const void *frame = NULL;
61587 + const void *oldframe;
61588 +#endif
61589 +
61590 + if (obj + len < obj)
61591 + return -1;
61592 +
61593 + if (obj + len <= stack || stackend <= obj)
61594 + return 0;
61595 +
61596 + if (obj < stack || stackend < obj + len)
61597 + return -1;
61598 +
61599 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61600 + oldframe = __builtin_frame_address(1);
61601 + if (oldframe)
61602 + frame = __builtin_frame_address(2);
61603 + /*
61604 + low ----------------------------------------------> high
61605 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61606 + ^----------------^
61607 + allow copies only within here
61608 + */
61609 + while (stack <= frame && frame < stackend) {
61610 + /* if obj + len extends past the last frame, this
61611 + check won't pass and the next frame will be 0,
61612 + causing us to bail out and correctly report
61613 + the copy as invalid
61614 + */
61615 + if (obj + len <= frame)
61616 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61617 + oldframe = frame;
61618 + frame = *(const void * const *)frame;
61619 + }
61620 + return -1;
61621 +#else
61622 + return 1;
61623 +#endif
61624 +}
61625 +
61626 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61627 +{
61628 + if (current->signal->curr_ip)
61629 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61630 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61631 + else
61632 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61633 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61634 + dump_stack();
61635 + gr_handle_kernel_exploit();
61636 + do_group_exit(SIGKILL);
61637 +}
61638 +#endif
61639 +
61640 +#ifdef CONFIG_PAX_USERCOPY
61641 +
61642 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61643 +{
61644 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61645 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61646 +#ifdef CONFIG_MODULES
61647 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61648 +#else
61649 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61650 +#endif
61651 +
61652 +#else
61653 + unsigned long textlow = (unsigned long)_stext;
61654 + unsigned long texthigh = (unsigned long)_etext;
61655 +
61656 +#ifdef CONFIG_X86_64
61657 + /* check against linear mapping as well */
61658 + if (high > (unsigned long)__va(__pa(textlow)) &&
61659 + low < (unsigned long)__va(__pa(texthigh)))
61660 + return true;
61661 +#endif
61662 +
61663 +#endif
61664 +
61665 + if (high <= textlow || low >= texthigh)
61666 + return false;
61667 + else
61668 + return true;
61669 +}
61670 +#endif
61671 +
61672 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61673 +{
61674 +#ifdef CONFIG_PAX_USERCOPY
61675 + const char *type;
61676 +#endif
61677 +
61678 +#ifndef CONFIG_STACK_GROWSUP
61679 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61680 + unsigned long currentsp = (unsigned long)&stackstart;
61681 + if (unlikely((currentsp < stackstart + 512 ||
61682 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61683 + BUG();
61684 +#endif
61685 +
61686 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61687 + if (const_size)
61688 + return;
61689 +#endif
61690 +
61691 +#ifdef CONFIG_PAX_USERCOPY
61692 + if (!n)
61693 + return;
61694 +
61695 + type = check_heap_object(ptr, n);
61696 + if (!type) {
61697 + int ret = check_stack_object(ptr, n);
61698 + if (ret == 1 || ret == 2)
61699 + return;
61700 + if (ret == 0) {
61701 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61702 + type = "<kernel text>";
61703 + else
61704 + return;
61705 + } else
61706 + type = "<process stack>";
61707 + }
61708 +
61709 + pax_report_usercopy(ptr, n, to_user, type);
61710 +#endif
61711 +
61712 +}
61713 +EXPORT_SYMBOL(__check_object_size);
61714 +
61715 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61716 +void pax_track_stack(void)
61717 +{
61718 + unsigned long sp = (unsigned long)&sp;
61719 + if (sp < current_thread_info()->lowest_stack &&
61720 + sp > (unsigned long)task_stack_page(current))
61721 + current_thread_info()->lowest_stack = sp;
61722 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61723 + BUG();
61724 +}
61725 +EXPORT_SYMBOL(pax_track_stack);
61726 +#endif
61727 +
61728 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61729 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61730 +{
61731 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61732 + dump_stack();
61733 + do_group_exit(SIGKILL);
61734 +}
61735 +EXPORT_SYMBOL(report_size_overflow);
61736 +#endif
61737 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61738 index 9f9992b..8b59411 100644
61739 --- a/fs/ext2/balloc.c
61740 +++ b/fs/ext2/balloc.c
61741 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61742
61743 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61744 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61745 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61746 + if (free_blocks < root_blocks + 1 &&
61747 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61748 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61749 - !in_group_p (sbi->s_resgid))) {
61750 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61751 return 0;
61752 }
61753 return 1;
61754 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61755 index 9142614..97484fa 100644
61756 --- a/fs/ext2/xattr.c
61757 +++ b/fs/ext2/xattr.c
61758 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61759 struct buffer_head *bh = NULL;
61760 struct ext2_xattr_entry *entry;
61761 char *end;
61762 - size_t rest = buffer_size;
61763 + size_t rest = buffer_size, total_size = 0;
61764 int error;
61765
61766 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61767 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61768 buffer += size;
61769 }
61770 rest -= size;
61771 + total_size += size;
61772 }
61773 }
61774 - error = buffer_size - rest; /* total size */
61775 + error = total_size;
61776
61777 cleanup:
61778 brelse(bh);
61779 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61780 index 158b5d4..2432610 100644
61781 --- a/fs/ext3/balloc.c
61782 +++ b/fs/ext3/balloc.c
61783 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61784
61785 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61786 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61787 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61788 + if (free_blocks < root_blocks + 1 &&
61789 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61790 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61791 - !in_group_p (sbi->s_resgid))) {
61792 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61793 return 0;
61794 }
61795 return 1;
61796 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61797 index c6874be..f8a6ae8 100644
61798 --- a/fs/ext3/xattr.c
61799 +++ b/fs/ext3/xattr.c
61800 @@ -330,7 +330,7 @@ static int
61801 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61802 char *buffer, size_t buffer_size)
61803 {
61804 - size_t rest = buffer_size;
61805 + size_t rest = buffer_size, total_size = 0;
61806
61807 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61808 const struct xattr_handler *handler =
61809 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61810 buffer += size;
61811 }
61812 rest -= size;
61813 + total_size += size;
61814 }
61815 }
61816 - return buffer_size - rest;
61817 + return total_size;
61818 }
61819
61820 static int
61821 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61822 index e069155..b825b08 100644
61823 --- a/fs/ext4/balloc.c
61824 +++ b/fs/ext4/balloc.c
61825 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61826 /* Hm, nope. Are (enough) root reserved clusters available? */
61827 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61828 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61829 - capable(CAP_SYS_RESOURCE) ||
61830 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61831 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61832 + capable_nolog(CAP_SYS_RESOURCE)) {
61833
61834 if (free_clusters >= (nclusters + dirty_clusters +
61835 resv_clusters))
61836 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61837 index 96ac9d3..1c30e7e6 100644
61838 --- a/fs/ext4/ext4.h
61839 +++ b/fs/ext4/ext4.h
61840 @@ -1275,19 +1275,19 @@ struct ext4_sb_info {
61841 unsigned long s_mb_last_start;
61842
61843 /* stats for buddy allocator */
61844 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61845 - atomic_t s_bal_success; /* we found long enough chunks */
61846 - atomic_t s_bal_allocated; /* in blocks */
61847 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61848 - atomic_t s_bal_goals; /* goal hits */
61849 - atomic_t s_bal_breaks; /* too long searches */
61850 - atomic_t s_bal_2orders; /* 2^order hits */
61851 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61852 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61853 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61854 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61855 + atomic_unchecked_t s_bal_goals; /* goal hits */
61856 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61857 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61858 spinlock_t s_bal_lock;
61859 unsigned long s_mb_buddies_generated;
61860 unsigned long long s_mb_generation_time;
61861 - atomic_t s_mb_lost_chunks;
61862 - atomic_t s_mb_preallocated;
61863 - atomic_t s_mb_discarded;
61864 + atomic_unchecked_t s_mb_lost_chunks;
61865 + atomic_unchecked_t s_mb_preallocated;
61866 + atomic_unchecked_t s_mb_discarded;
61867 atomic_t s_lock_busy;
61868
61869 /* locality groups */
61870 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61871 index 8b0f9ef..cb9f620 100644
61872 --- a/fs/ext4/mballoc.c
61873 +++ b/fs/ext4/mballoc.c
61874 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61875 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61876
61877 if (EXT4_SB(sb)->s_mb_stats)
61878 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61879 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61880
61881 break;
61882 }
61883 @@ -2211,7 +2211,7 @@ repeat:
61884 ac->ac_status = AC_STATUS_CONTINUE;
61885 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61886 cr = 3;
61887 - atomic_inc(&sbi->s_mb_lost_chunks);
61888 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61889 goto repeat;
61890 }
61891 }
61892 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61893 if (sbi->s_mb_stats) {
61894 ext4_msg(sb, KERN_INFO,
61895 "mballoc: %u blocks %u reqs (%u success)",
61896 - atomic_read(&sbi->s_bal_allocated),
61897 - atomic_read(&sbi->s_bal_reqs),
61898 - atomic_read(&sbi->s_bal_success));
61899 + atomic_read_unchecked(&sbi->s_bal_allocated),
61900 + atomic_read_unchecked(&sbi->s_bal_reqs),
61901 + atomic_read_unchecked(&sbi->s_bal_success));
61902 ext4_msg(sb, KERN_INFO,
61903 "mballoc: %u extents scanned, %u goal hits, "
61904 "%u 2^N hits, %u breaks, %u lost",
61905 - atomic_read(&sbi->s_bal_ex_scanned),
61906 - atomic_read(&sbi->s_bal_goals),
61907 - atomic_read(&sbi->s_bal_2orders),
61908 - atomic_read(&sbi->s_bal_breaks),
61909 - atomic_read(&sbi->s_mb_lost_chunks));
61910 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61911 + atomic_read_unchecked(&sbi->s_bal_goals),
61912 + atomic_read_unchecked(&sbi->s_bal_2orders),
61913 + atomic_read_unchecked(&sbi->s_bal_breaks),
61914 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61915 ext4_msg(sb, KERN_INFO,
61916 "mballoc: %lu generated and it took %Lu",
61917 sbi->s_mb_buddies_generated,
61918 sbi->s_mb_generation_time);
61919 ext4_msg(sb, KERN_INFO,
61920 "mballoc: %u preallocated, %u discarded",
61921 - atomic_read(&sbi->s_mb_preallocated),
61922 - atomic_read(&sbi->s_mb_discarded));
61923 + atomic_read_unchecked(&sbi->s_mb_preallocated),
61924 + atomic_read_unchecked(&sbi->s_mb_discarded));
61925 }
61926
61927 free_percpu(sbi->s_locality_groups);
61928 @@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61929 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61930
61931 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61932 - atomic_inc(&sbi->s_bal_reqs);
61933 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61934 + atomic_inc_unchecked(&sbi->s_bal_reqs);
61935 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61936 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61937 - atomic_inc(&sbi->s_bal_success);
61938 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61939 + atomic_inc_unchecked(&sbi->s_bal_success);
61940 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
61941 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
61942 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
61943 - atomic_inc(&sbi->s_bal_goals);
61944 + atomic_inc_unchecked(&sbi->s_bal_goals);
61945 if (ac->ac_found > sbi->s_mb_max_to_scan)
61946 - atomic_inc(&sbi->s_bal_breaks);
61947 + atomic_inc_unchecked(&sbi->s_bal_breaks);
61948 }
61949
61950 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
61951 @@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
61952 trace_ext4_mb_new_inode_pa(ac, pa);
61953
61954 ext4_mb_use_inode_pa(ac, pa);
61955 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
61956 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
61957
61958 ei = EXT4_I(ac->ac_inode);
61959 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61960 @@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
61961 trace_ext4_mb_new_group_pa(ac, pa);
61962
61963 ext4_mb_use_group_pa(ac, pa);
61964 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61965 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61966
61967 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61968 lg = ac->ac_lg;
61969 @@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
61970 * from the bitmap and continue.
61971 */
61972 }
61973 - atomic_add(free, &sbi->s_mb_discarded);
61974 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
61975
61976 return err;
61977 }
61978 @@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
61979 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
61980 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
61981 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
61982 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61983 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61984 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
61985
61986 return 0;
61987 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
61988 index 8313ca3..8a37d08 100644
61989 --- a/fs/ext4/mmp.c
61990 +++ b/fs/ext4/mmp.c
61991 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
61992 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
61993 const char *function, unsigned int line, const char *msg)
61994 {
61995 - __ext4_warning(sb, function, line, msg);
61996 + __ext4_warning(sb, function, line, "%s", msg);
61997 __ext4_warning(sb, function, line,
61998 "MMP failure info: last update time: %llu, last update "
61999 "node: %s, last update device: %s\n",
62000 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62001 index b1f0ac7..77e9a05 100644
62002 --- a/fs/ext4/super.c
62003 +++ b/fs/ext4/super.c
62004 @@ -1274,7 +1274,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62005 }
62006
62007 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62008 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62009 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62010 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62011
62012 #ifdef CONFIG_QUOTA
62013 @@ -2454,7 +2454,7 @@ struct ext4_attr {
62014 int offset;
62015 int deprecated_val;
62016 } u;
62017 -};
62018 +} __do_const;
62019
62020 static int parse_strtoull(const char *buf,
62021 unsigned long long max, unsigned long long *value)
62022 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62023 index 2d1e5803..1b082d415 100644
62024 --- a/fs/ext4/xattr.c
62025 +++ b/fs/ext4/xattr.c
62026 @@ -399,7 +399,7 @@ static int
62027 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62028 char *buffer, size_t buffer_size)
62029 {
62030 - size_t rest = buffer_size;
62031 + size_t rest = buffer_size, total_size = 0;
62032
62033 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62034 const struct xattr_handler *handler =
62035 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62036 buffer += size;
62037 }
62038 rest -= size;
62039 + total_size += size;
62040 }
62041 }
62042 - return buffer_size - rest;
62043 + return total_size;
62044 }
62045
62046 static int
62047 diff --git a/fs/fcntl.c b/fs/fcntl.c
62048 index 22d1c3d..600cf7e 100644
62049 --- a/fs/fcntl.c
62050 +++ b/fs/fcntl.c
62051 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62052 if (err)
62053 return err;
62054
62055 + if (gr_handle_chroot_fowner(pid, type))
62056 + return -ENOENT;
62057 + if (gr_check_protected_task_fowner(pid, type))
62058 + return -EACCES;
62059 +
62060 f_modown(filp, pid, type, force);
62061 return 0;
62062 }
62063 diff --git a/fs/fhandle.c b/fs/fhandle.c
62064 index 999ff5c..ac037c9 100644
62065 --- a/fs/fhandle.c
62066 +++ b/fs/fhandle.c
62067 @@ -8,6 +8,7 @@
62068 #include <linux/fs_struct.h>
62069 #include <linux/fsnotify.h>
62070 #include <linux/personality.h>
62071 +#include <linux/grsecurity.h>
62072 #include <asm/uaccess.h>
62073 #include "internal.h"
62074 #include "mount.h"
62075 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62076 } else
62077 retval = 0;
62078 /* copy the mount id */
62079 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62080 - sizeof(*mnt_id)) ||
62081 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62082 copy_to_user(ufh, handle,
62083 sizeof(struct file_handle) + handle_bytes))
62084 retval = -EFAULT;
62085 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62086 * the directory. Ideally we would like CAP_DAC_SEARCH.
62087 * But we don't have that
62088 */
62089 - if (!capable(CAP_DAC_READ_SEARCH)) {
62090 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62091 retval = -EPERM;
62092 goto out_err;
62093 }
62094 diff --git a/fs/file.c b/fs/file.c
62095 index 66923fe..2849783 100644
62096 --- a/fs/file.c
62097 +++ b/fs/file.c
62098 @@ -16,6 +16,7 @@
62099 #include <linux/slab.h>
62100 #include <linux/vmalloc.h>
62101 #include <linux/file.h>
62102 +#include <linux/security.h>
62103 #include <linux/fdtable.h>
62104 #include <linux/bitops.h>
62105 #include <linux/interrupt.h>
62106 @@ -139,7 +140,7 @@ out:
62107 * Return <0 error code on error; 1 on successful completion.
62108 * The files->file_lock should be held on entry, and will be held on exit.
62109 */
62110 -static int expand_fdtable(struct files_struct *files, int nr)
62111 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62112 __releases(files->file_lock)
62113 __acquires(files->file_lock)
62114 {
62115 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62116 * expanded and execution may have blocked.
62117 * The files->file_lock should be held on entry, and will be held on exit.
62118 */
62119 -static int expand_files(struct files_struct *files, int nr)
62120 +static int expand_files(struct files_struct *files, unsigned int nr)
62121 {
62122 struct fdtable *fdt;
62123
62124 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62125 if (!file)
62126 return __close_fd(files, fd);
62127
62128 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62129 if (fd >= rlimit(RLIMIT_NOFILE))
62130 return -EBADF;
62131
62132 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62133 if (unlikely(oldfd == newfd))
62134 return -EINVAL;
62135
62136 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62137 if (newfd >= rlimit(RLIMIT_NOFILE))
62138 return -EBADF;
62139
62140 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62141 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62142 {
62143 int err;
62144 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62145 if (from >= rlimit(RLIMIT_NOFILE))
62146 return -EINVAL;
62147 err = alloc_fd(from, flags);
62148 diff --git a/fs/filesystems.c b/fs/filesystems.c
62149 index 5797d45..7d7d79a 100644
62150 --- a/fs/filesystems.c
62151 +++ b/fs/filesystems.c
62152 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62153 int len = dot ? dot - name : strlen(name);
62154
62155 fs = __get_fs_type(name, len);
62156 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62157 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62158 +#else
62159 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62160 +#endif
62161 fs = __get_fs_type(name, len);
62162
62163 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62164 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62165 index 7dca743..543d620 100644
62166 --- a/fs/fs_struct.c
62167 +++ b/fs/fs_struct.c
62168 @@ -4,6 +4,7 @@
62169 #include <linux/path.h>
62170 #include <linux/slab.h>
62171 #include <linux/fs_struct.h>
62172 +#include <linux/grsecurity.h>
62173 #include "internal.h"
62174
62175 /*
62176 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62177 write_seqcount_begin(&fs->seq);
62178 old_root = fs->root;
62179 fs->root = *path;
62180 + gr_set_chroot_entries(current, path);
62181 write_seqcount_end(&fs->seq);
62182 spin_unlock(&fs->lock);
62183 if (old_root.dentry)
62184 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62185 int hits = 0;
62186 spin_lock(&fs->lock);
62187 write_seqcount_begin(&fs->seq);
62188 + /* this root replacement is only done by pivot_root,
62189 + leave grsec's chroot tagging alone for this task
62190 + so that a pivoted root isn't treated as a chroot
62191 + */
62192 hits += replace_path(&fs->root, old_root, new_root);
62193 hits += replace_path(&fs->pwd, old_root, new_root);
62194 write_seqcount_end(&fs->seq);
62195 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62196 task_lock(tsk);
62197 spin_lock(&fs->lock);
62198 tsk->fs = NULL;
62199 - kill = !--fs->users;
62200 + gr_clear_chroot_entries(tsk);
62201 + kill = !atomic_dec_return(&fs->users);
62202 spin_unlock(&fs->lock);
62203 task_unlock(tsk);
62204 if (kill)
62205 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62206 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62207 /* We don't need to lock fs - think why ;-) */
62208 if (fs) {
62209 - fs->users = 1;
62210 + atomic_set(&fs->users, 1);
62211 fs->in_exec = 0;
62212 spin_lock_init(&fs->lock);
62213 seqcount_init(&fs->seq);
62214 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62215 spin_lock(&old->lock);
62216 fs->root = old->root;
62217 path_get(&fs->root);
62218 + /* instead of calling gr_set_chroot_entries here,
62219 + we call it from every caller of this function
62220 + */
62221 fs->pwd = old->pwd;
62222 path_get(&fs->pwd);
62223 spin_unlock(&old->lock);
62224 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62225
62226 task_lock(current);
62227 spin_lock(&fs->lock);
62228 - kill = !--fs->users;
62229 + kill = !atomic_dec_return(&fs->users);
62230 current->fs = new_fs;
62231 + gr_set_chroot_entries(current, &new_fs->root);
62232 spin_unlock(&fs->lock);
62233 task_unlock(current);
62234
62235 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62236
62237 int current_umask(void)
62238 {
62239 - return current->fs->umask;
62240 + return current->fs->umask | gr_acl_umask();
62241 }
62242 EXPORT_SYMBOL(current_umask);
62243
62244 /* to be mentioned only in INIT_TASK */
62245 struct fs_struct init_fs = {
62246 - .users = 1,
62247 + .users = ATOMIC_INIT(1),
62248 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62249 .seq = SEQCNT_ZERO(init_fs.seq),
62250 .umask = 0022,
62251 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62252 index 89acec7..a575262 100644
62253 --- a/fs/fscache/cookie.c
62254 +++ b/fs/fscache/cookie.c
62255 @@ -19,7 +19,7 @@
62256
62257 struct kmem_cache *fscache_cookie_jar;
62258
62259 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62260 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62261
62262 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62263 static int fscache_alloc_object(struct fscache_cache *cache,
62264 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62265 parent ? (char *) parent->def->name : "<no-parent>",
62266 def->name, netfs_data, enable);
62267
62268 - fscache_stat(&fscache_n_acquires);
62269 + fscache_stat_unchecked(&fscache_n_acquires);
62270
62271 /* if there's no parent cookie, then we don't create one here either */
62272 if (!parent) {
62273 - fscache_stat(&fscache_n_acquires_null);
62274 + fscache_stat_unchecked(&fscache_n_acquires_null);
62275 _leave(" [no parent]");
62276 return NULL;
62277 }
62278 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62279 /* allocate and initialise a cookie */
62280 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62281 if (!cookie) {
62282 - fscache_stat(&fscache_n_acquires_oom);
62283 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62284 _leave(" [ENOMEM]");
62285 return NULL;
62286 }
62287 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62288
62289 switch (cookie->def->type) {
62290 case FSCACHE_COOKIE_TYPE_INDEX:
62291 - fscache_stat(&fscache_n_cookie_index);
62292 + fscache_stat_unchecked(&fscache_n_cookie_index);
62293 break;
62294 case FSCACHE_COOKIE_TYPE_DATAFILE:
62295 - fscache_stat(&fscache_n_cookie_data);
62296 + fscache_stat_unchecked(&fscache_n_cookie_data);
62297 break;
62298 default:
62299 - fscache_stat(&fscache_n_cookie_special);
62300 + fscache_stat_unchecked(&fscache_n_cookie_special);
62301 break;
62302 }
62303
62304 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62305 } else {
62306 atomic_dec(&parent->n_children);
62307 __fscache_cookie_put(cookie);
62308 - fscache_stat(&fscache_n_acquires_nobufs);
62309 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62310 _leave(" = NULL");
62311 return NULL;
62312 }
62313 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62314 }
62315 }
62316
62317 - fscache_stat(&fscache_n_acquires_ok);
62318 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62319 _leave(" = %p", cookie);
62320 return cookie;
62321 }
62322 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62323 cache = fscache_select_cache_for_object(cookie->parent);
62324 if (!cache) {
62325 up_read(&fscache_addremove_sem);
62326 - fscache_stat(&fscache_n_acquires_no_cache);
62327 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62328 _leave(" = -ENOMEDIUM [no cache]");
62329 return -ENOMEDIUM;
62330 }
62331 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62332 object = cache->ops->alloc_object(cache, cookie);
62333 fscache_stat_d(&fscache_n_cop_alloc_object);
62334 if (IS_ERR(object)) {
62335 - fscache_stat(&fscache_n_object_no_alloc);
62336 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62337 ret = PTR_ERR(object);
62338 goto error;
62339 }
62340
62341 - fscache_stat(&fscache_n_object_alloc);
62342 + fscache_stat_unchecked(&fscache_n_object_alloc);
62343
62344 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62345 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62346
62347 _debug("ALLOC OBJ%x: %s {%lx}",
62348 object->debug_id, cookie->def->name, object->events);
62349 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62350
62351 _enter("{%s}", cookie->def->name);
62352
62353 - fscache_stat(&fscache_n_invalidates);
62354 + fscache_stat_unchecked(&fscache_n_invalidates);
62355
62356 /* Only permit invalidation of data files. Invalidating an index will
62357 * require the caller to release all its attachments to the tree rooted
62358 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62359 {
62360 struct fscache_object *object;
62361
62362 - fscache_stat(&fscache_n_updates);
62363 + fscache_stat_unchecked(&fscache_n_updates);
62364
62365 if (!cookie) {
62366 - fscache_stat(&fscache_n_updates_null);
62367 + fscache_stat_unchecked(&fscache_n_updates_null);
62368 _leave(" [no cookie]");
62369 return;
62370 }
62371 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62372 */
62373 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62374 {
62375 - fscache_stat(&fscache_n_relinquishes);
62376 + fscache_stat_unchecked(&fscache_n_relinquishes);
62377 if (retire)
62378 - fscache_stat(&fscache_n_relinquishes_retire);
62379 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62380
62381 if (!cookie) {
62382 - fscache_stat(&fscache_n_relinquishes_null);
62383 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62384 _leave(" [no cookie]");
62385 return;
62386 }
62387 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62388 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62389 goto inconsistent;
62390
62391 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62392 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62393
62394 __fscache_use_cookie(cookie);
62395 if (fscache_submit_op(object, op) < 0)
62396 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62397 index 7872a62..d91b19f 100644
62398 --- a/fs/fscache/internal.h
62399 +++ b/fs/fscache/internal.h
62400 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62401 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62402 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62403 struct fscache_operation *,
62404 - atomic_t *,
62405 - atomic_t *,
62406 + atomic_unchecked_t *,
62407 + atomic_unchecked_t *,
62408 void (*)(struct fscache_operation *));
62409 extern void fscache_invalidate_writes(struct fscache_cookie *);
62410
62411 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62412 * stats.c
62413 */
62414 #ifdef CONFIG_FSCACHE_STATS
62415 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62416 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62417 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62418 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62419
62420 -extern atomic_t fscache_n_op_pend;
62421 -extern atomic_t fscache_n_op_run;
62422 -extern atomic_t fscache_n_op_enqueue;
62423 -extern atomic_t fscache_n_op_deferred_release;
62424 -extern atomic_t fscache_n_op_release;
62425 -extern atomic_t fscache_n_op_gc;
62426 -extern atomic_t fscache_n_op_cancelled;
62427 -extern atomic_t fscache_n_op_rejected;
62428 +extern atomic_unchecked_t fscache_n_op_pend;
62429 +extern atomic_unchecked_t fscache_n_op_run;
62430 +extern atomic_unchecked_t fscache_n_op_enqueue;
62431 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62432 +extern atomic_unchecked_t fscache_n_op_release;
62433 +extern atomic_unchecked_t fscache_n_op_gc;
62434 +extern atomic_unchecked_t fscache_n_op_cancelled;
62435 +extern atomic_unchecked_t fscache_n_op_rejected;
62436
62437 -extern atomic_t fscache_n_attr_changed;
62438 -extern atomic_t fscache_n_attr_changed_ok;
62439 -extern atomic_t fscache_n_attr_changed_nobufs;
62440 -extern atomic_t fscache_n_attr_changed_nomem;
62441 -extern atomic_t fscache_n_attr_changed_calls;
62442 +extern atomic_unchecked_t fscache_n_attr_changed;
62443 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62444 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62445 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62446 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62447
62448 -extern atomic_t fscache_n_allocs;
62449 -extern atomic_t fscache_n_allocs_ok;
62450 -extern atomic_t fscache_n_allocs_wait;
62451 -extern atomic_t fscache_n_allocs_nobufs;
62452 -extern atomic_t fscache_n_allocs_intr;
62453 -extern atomic_t fscache_n_allocs_object_dead;
62454 -extern atomic_t fscache_n_alloc_ops;
62455 -extern atomic_t fscache_n_alloc_op_waits;
62456 +extern atomic_unchecked_t fscache_n_allocs;
62457 +extern atomic_unchecked_t fscache_n_allocs_ok;
62458 +extern atomic_unchecked_t fscache_n_allocs_wait;
62459 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62460 +extern atomic_unchecked_t fscache_n_allocs_intr;
62461 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62462 +extern atomic_unchecked_t fscache_n_alloc_ops;
62463 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62464
62465 -extern atomic_t fscache_n_retrievals;
62466 -extern atomic_t fscache_n_retrievals_ok;
62467 -extern atomic_t fscache_n_retrievals_wait;
62468 -extern atomic_t fscache_n_retrievals_nodata;
62469 -extern atomic_t fscache_n_retrievals_nobufs;
62470 -extern atomic_t fscache_n_retrievals_intr;
62471 -extern atomic_t fscache_n_retrievals_nomem;
62472 -extern atomic_t fscache_n_retrievals_object_dead;
62473 -extern atomic_t fscache_n_retrieval_ops;
62474 -extern atomic_t fscache_n_retrieval_op_waits;
62475 +extern atomic_unchecked_t fscache_n_retrievals;
62476 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62477 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62478 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62479 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62480 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62481 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62482 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62483 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62484 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62485
62486 -extern atomic_t fscache_n_stores;
62487 -extern atomic_t fscache_n_stores_ok;
62488 -extern atomic_t fscache_n_stores_again;
62489 -extern atomic_t fscache_n_stores_nobufs;
62490 -extern atomic_t fscache_n_stores_oom;
62491 -extern atomic_t fscache_n_store_ops;
62492 -extern atomic_t fscache_n_store_calls;
62493 -extern atomic_t fscache_n_store_pages;
62494 -extern atomic_t fscache_n_store_radix_deletes;
62495 -extern atomic_t fscache_n_store_pages_over_limit;
62496 +extern atomic_unchecked_t fscache_n_stores;
62497 +extern atomic_unchecked_t fscache_n_stores_ok;
62498 +extern atomic_unchecked_t fscache_n_stores_again;
62499 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62500 +extern atomic_unchecked_t fscache_n_stores_oom;
62501 +extern atomic_unchecked_t fscache_n_store_ops;
62502 +extern atomic_unchecked_t fscache_n_store_calls;
62503 +extern atomic_unchecked_t fscache_n_store_pages;
62504 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62505 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62506
62507 -extern atomic_t fscache_n_store_vmscan_not_storing;
62508 -extern atomic_t fscache_n_store_vmscan_gone;
62509 -extern atomic_t fscache_n_store_vmscan_busy;
62510 -extern atomic_t fscache_n_store_vmscan_cancelled;
62511 -extern atomic_t fscache_n_store_vmscan_wait;
62512 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62513 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62514 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62515 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62516 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62517
62518 -extern atomic_t fscache_n_marks;
62519 -extern atomic_t fscache_n_uncaches;
62520 +extern atomic_unchecked_t fscache_n_marks;
62521 +extern atomic_unchecked_t fscache_n_uncaches;
62522
62523 -extern atomic_t fscache_n_acquires;
62524 -extern atomic_t fscache_n_acquires_null;
62525 -extern atomic_t fscache_n_acquires_no_cache;
62526 -extern atomic_t fscache_n_acquires_ok;
62527 -extern atomic_t fscache_n_acquires_nobufs;
62528 -extern atomic_t fscache_n_acquires_oom;
62529 +extern atomic_unchecked_t fscache_n_acquires;
62530 +extern atomic_unchecked_t fscache_n_acquires_null;
62531 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62532 +extern atomic_unchecked_t fscache_n_acquires_ok;
62533 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62534 +extern atomic_unchecked_t fscache_n_acquires_oom;
62535
62536 -extern atomic_t fscache_n_invalidates;
62537 -extern atomic_t fscache_n_invalidates_run;
62538 +extern atomic_unchecked_t fscache_n_invalidates;
62539 +extern atomic_unchecked_t fscache_n_invalidates_run;
62540
62541 -extern atomic_t fscache_n_updates;
62542 -extern atomic_t fscache_n_updates_null;
62543 -extern atomic_t fscache_n_updates_run;
62544 +extern atomic_unchecked_t fscache_n_updates;
62545 +extern atomic_unchecked_t fscache_n_updates_null;
62546 +extern atomic_unchecked_t fscache_n_updates_run;
62547
62548 -extern atomic_t fscache_n_relinquishes;
62549 -extern atomic_t fscache_n_relinquishes_null;
62550 -extern atomic_t fscache_n_relinquishes_waitcrt;
62551 -extern atomic_t fscache_n_relinquishes_retire;
62552 +extern atomic_unchecked_t fscache_n_relinquishes;
62553 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62554 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62555 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62556
62557 -extern atomic_t fscache_n_cookie_index;
62558 -extern atomic_t fscache_n_cookie_data;
62559 -extern atomic_t fscache_n_cookie_special;
62560 +extern atomic_unchecked_t fscache_n_cookie_index;
62561 +extern atomic_unchecked_t fscache_n_cookie_data;
62562 +extern atomic_unchecked_t fscache_n_cookie_special;
62563
62564 -extern atomic_t fscache_n_object_alloc;
62565 -extern atomic_t fscache_n_object_no_alloc;
62566 -extern atomic_t fscache_n_object_lookups;
62567 -extern atomic_t fscache_n_object_lookups_negative;
62568 -extern atomic_t fscache_n_object_lookups_positive;
62569 -extern atomic_t fscache_n_object_lookups_timed_out;
62570 -extern atomic_t fscache_n_object_created;
62571 -extern atomic_t fscache_n_object_avail;
62572 -extern atomic_t fscache_n_object_dead;
62573 +extern atomic_unchecked_t fscache_n_object_alloc;
62574 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62575 +extern atomic_unchecked_t fscache_n_object_lookups;
62576 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62577 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62578 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62579 +extern atomic_unchecked_t fscache_n_object_created;
62580 +extern atomic_unchecked_t fscache_n_object_avail;
62581 +extern atomic_unchecked_t fscache_n_object_dead;
62582
62583 -extern atomic_t fscache_n_checkaux_none;
62584 -extern atomic_t fscache_n_checkaux_okay;
62585 -extern atomic_t fscache_n_checkaux_update;
62586 -extern atomic_t fscache_n_checkaux_obsolete;
62587 +extern atomic_unchecked_t fscache_n_checkaux_none;
62588 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62589 +extern atomic_unchecked_t fscache_n_checkaux_update;
62590 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62591
62592 extern atomic_t fscache_n_cop_alloc_object;
62593 extern atomic_t fscache_n_cop_lookup_object;
62594 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62595 atomic_inc(stat);
62596 }
62597
62598 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62599 +{
62600 + atomic_inc_unchecked(stat);
62601 +}
62602 +
62603 static inline void fscache_stat_d(atomic_t *stat)
62604 {
62605 atomic_dec(stat);
62606 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62607
62608 #define __fscache_stat(stat) (NULL)
62609 #define fscache_stat(stat) do {} while (0)
62610 +#define fscache_stat_unchecked(stat) do {} while (0)
62611 #define fscache_stat_d(stat) do {} while (0)
62612 #endif
62613
62614 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62615 index da032da..0076ce7 100644
62616 --- a/fs/fscache/object.c
62617 +++ b/fs/fscache/object.c
62618 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62619 _debug("LOOKUP \"%s\" in \"%s\"",
62620 cookie->def->name, object->cache->tag->name);
62621
62622 - fscache_stat(&fscache_n_object_lookups);
62623 + fscache_stat_unchecked(&fscache_n_object_lookups);
62624 fscache_stat(&fscache_n_cop_lookup_object);
62625 ret = object->cache->ops->lookup_object(object);
62626 fscache_stat_d(&fscache_n_cop_lookup_object);
62627 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62628 if (ret == -ETIMEDOUT) {
62629 /* probably stuck behind another object, so move this one to
62630 * the back of the queue */
62631 - fscache_stat(&fscache_n_object_lookups_timed_out);
62632 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62633 _leave(" [timeout]");
62634 return NO_TRANSIT;
62635 }
62636 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62637 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62638
62639 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62640 - fscache_stat(&fscache_n_object_lookups_negative);
62641 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62642
62643 /* Allow write requests to begin stacking up and read requests to begin
62644 * returning ENODATA.
62645 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62646 /* if we were still looking up, then we must have a positive lookup
62647 * result, in which case there may be data available */
62648 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62649 - fscache_stat(&fscache_n_object_lookups_positive);
62650 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62651
62652 /* We do (presumably) have data */
62653 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62654 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62655 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62656 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62657 } else {
62658 - fscache_stat(&fscache_n_object_created);
62659 + fscache_stat_unchecked(&fscache_n_object_created);
62660 }
62661
62662 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62663 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62664 fscache_stat_d(&fscache_n_cop_lookup_complete);
62665
62666 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62667 - fscache_stat(&fscache_n_object_avail);
62668 + fscache_stat_unchecked(&fscache_n_object_avail);
62669
62670 _leave("");
62671 return transit_to(JUMPSTART_DEPS);
62672 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62673
62674 /* this just shifts the object release to the work processor */
62675 fscache_put_object(object);
62676 - fscache_stat(&fscache_n_object_dead);
62677 + fscache_stat_unchecked(&fscache_n_object_dead);
62678
62679 _leave("");
62680 return transit_to(OBJECT_DEAD);
62681 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62682 enum fscache_checkaux result;
62683
62684 if (!object->cookie->def->check_aux) {
62685 - fscache_stat(&fscache_n_checkaux_none);
62686 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62687 return FSCACHE_CHECKAUX_OKAY;
62688 }
62689
62690 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62691 switch (result) {
62692 /* entry okay as is */
62693 case FSCACHE_CHECKAUX_OKAY:
62694 - fscache_stat(&fscache_n_checkaux_okay);
62695 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62696 break;
62697
62698 /* entry requires update */
62699 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62700 - fscache_stat(&fscache_n_checkaux_update);
62701 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62702 break;
62703
62704 /* entry requires deletion */
62705 case FSCACHE_CHECKAUX_OBSOLETE:
62706 - fscache_stat(&fscache_n_checkaux_obsolete);
62707 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62708 break;
62709
62710 default:
62711 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62712 {
62713 const struct fscache_state *s;
62714
62715 - fscache_stat(&fscache_n_invalidates_run);
62716 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62717 fscache_stat(&fscache_n_cop_invalidate_object);
62718 s = _fscache_invalidate_object(object, event);
62719 fscache_stat_d(&fscache_n_cop_invalidate_object);
62720 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62721 {
62722 _enter("{OBJ%x},%d", object->debug_id, event);
62723
62724 - fscache_stat(&fscache_n_updates_run);
62725 + fscache_stat_unchecked(&fscache_n_updates_run);
62726 fscache_stat(&fscache_n_cop_update_object);
62727 object->cache->ops->update_object(object);
62728 fscache_stat_d(&fscache_n_cop_update_object);
62729 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62730 index e7b87a0..a85d47a 100644
62731 --- a/fs/fscache/operation.c
62732 +++ b/fs/fscache/operation.c
62733 @@ -17,7 +17,7 @@
62734 #include <linux/slab.h>
62735 #include "internal.h"
62736
62737 -atomic_t fscache_op_debug_id;
62738 +atomic_unchecked_t fscache_op_debug_id;
62739 EXPORT_SYMBOL(fscache_op_debug_id);
62740
62741 /**
62742 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62743 ASSERTCMP(atomic_read(&op->usage), >, 0);
62744 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62745
62746 - fscache_stat(&fscache_n_op_enqueue);
62747 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62748 switch (op->flags & FSCACHE_OP_TYPE) {
62749 case FSCACHE_OP_ASYNC:
62750 _debug("queue async");
62751 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62752 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62753 if (op->processor)
62754 fscache_enqueue_operation(op);
62755 - fscache_stat(&fscache_n_op_run);
62756 + fscache_stat_unchecked(&fscache_n_op_run);
62757 }
62758
62759 /*
62760 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62761 if (object->n_in_progress > 0) {
62762 atomic_inc(&op->usage);
62763 list_add_tail(&op->pend_link, &object->pending_ops);
62764 - fscache_stat(&fscache_n_op_pend);
62765 + fscache_stat_unchecked(&fscache_n_op_pend);
62766 } else if (!list_empty(&object->pending_ops)) {
62767 atomic_inc(&op->usage);
62768 list_add_tail(&op->pend_link, &object->pending_ops);
62769 - fscache_stat(&fscache_n_op_pend);
62770 + fscache_stat_unchecked(&fscache_n_op_pend);
62771 fscache_start_operations(object);
62772 } else {
62773 ASSERTCMP(object->n_in_progress, ==, 0);
62774 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62775 object->n_exclusive++; /* reads and writes must wait */
62776 atomic_inc(&op->usage);
62777 list_add_tail(&op->pend_link, &object->pending_ops);
62778 - fscache_stat(&fscache_n_op_pend);
62779 + fscache_stat_unchecked(&fscache_n_op_pend);
62780 ret = 0;
62781 } else {
62782 /* If we're in any other state, there must have been an I/O
62783 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62784 if (object->n_exclusive > 0) {
62785 atomic_inc(&op->usage);
62786 list_add_tail(&op->pend_link, &object->pending_ops);
62787 - fscache_stat(&fscache_n_op_pend);
62788 + fscache_stat_unchecked(&fscache_n_op_pend);
62789 } else if (!list_empty(&object->pending_ops)) {
62790 atomic_inc(&op->usage);
62791 list_add_tail(&op->pend_link, &object->pending_ops);
62792 - fscache_stat(&fscache_n_op_pend);
62793 + fscache_stat_unchecked(&fscache_n_op_pend);
62794 fscache_start_operations(object);
62795 } else {
62796 ASSERTCMP(object->n_exclusive, ==, 0);
62797 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62798 object->n_ops++;
62799 atomic_inc(&op->usage);
62800 list_add_tail(&op->pend_link, &object->pending_ops);
62801 - fscache_stat(&fscache_n_op_pend);
62802 + fscache_stat_unchecked(&fscache_n_op_pend);
62803 ret = 0;
62804 } else if (fscache_object_is_dying(object)) {
62805 - fscache_stat(&fscache_n_op_rejected);
62806 + fscache_stat_unchecked(&fscache_n_op_rejected);
62807 op->state = FSCACHE_OP_ST_CANCELLED;
62808 ret = -ENOBUFS;
62809 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62810 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62811 ret = -EBUSY;
62812 if (op->state == FSCACHE_OP_ST_PENDING) {
62813 ASSERT(!list_empty(&op->pend_link));
62814 - fscache_stat(&fscache_n_op_cancelled);
62815 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62816 list_del_init(&op->pend_link);
62817 if (do_cancel)
62818 do_cancel(op);
62819 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62820 while (!list_empty(&object->pending_ops)) {
62821 op = list_entry(object->pending_ops.next,
62822 struct fscache_operation, pend_link);
62823 - fscache_stat(&fscache_n_op_cancelled);
62824 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62825 list_del_init(&op->pend_link);
62826
62827 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62828 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62829 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62830 op->state = FSCACHE_OP_ST_DEAD;
62831
62832 - fscache_stat(&fscache_n_op_release);
62833 + fscache_stat_unchecked(&fscache_n_op_release);
62834
62835 if (op->release) {
62836 op->release(op);
62837 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62838 * lock, and defer it otherwise */
62839 if (!spin_trylock(&object->lock)) {
62840 _debug("defer put");
62841 - fscache_stat(&fscache_n_op_deferred_release);
62842 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
62843
62844 cache = object->cache;
62845 spin_lock(&cache->op_gc_list_lock);
62846 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62847
62848 _debug("GC DEFERRED REL OBJ%x OP%x",
62849 object->debug_id, op->debug_id);
62850 - fscache_stat(&fscache_n_op_gc);
62851 + fscache_stat_unchecked(&fscache_n_op_gc);
62852
62853 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62854 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62855 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62856 index de33b3f..8be4d29 100644
62857 --- a/fs/fscache/page.c
62858 +++ b/fs/fscache/page.c
62859 @@ -74,7 +74,7 @@ try_again:
62860 val = radix_tree_lookup(&cookie->stores, page->index);
62861 if (!val) {
62862 rcu_read_unlock();
62863 - fscache_stat(&fscache_n_store_vmscan_not_storing);
62864 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62865 __fscache_uncache_page(cookie, page);
62866 return true;
62867 }
62868 @@ -104,11 +104,11 @@ try_again:
62869 spin_unlock(&cookie->stores_lock);
62870
62871 if (xpage) {
62872 - fscache_stat(&fscache_n_store_vmscan_cancelled);
62873 - fscache_stat(&fscache_n_store_radix_deletes);
62874 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62875 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62876 ASSERTCMP(xpage, ==, page);
62877 } else {
62878 - fscache_stat(&fscache_n_store_vmscan_gone);
62879 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62880 }
62881
62882 wake_up_bit(&cookie->flags, 0);
62883 @@ -123,11 +123,11 @@ page_busy:
62884 * sleeping on memory allocation, so we may need to impose a timeout
62885 * too. */
62886 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62887 - fscache_stat(&fscache_n_store_vmscan_busy);
62888 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62889 return false;
62890 }
62891
62892 - fscache_stat(&fscache_n_store_vmscan_wait);
62893 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62894 if (!release_page_wait_timeout(cookie, page))
62895 _debug("fscache writeout timeout page: %p{%lx}",
62896 page, page->index);
62897 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
62898 FSCACHE_COOKIE_STORING_TAG);
62899 if (!radix_tree_tag_get(&cookie->stores, page->index,
62900 FSCACHE_COOKIE_PENDING_TAG)) {
62901 - fscache_stat(&fscache_n_store_radix_deletes);
62902 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62903 xpage = radix_tree_delete(&cookie->stores, page->index);
62904 }
62905 spin_unlock(&cookie->stores_lock);
62906 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
62907
62908 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
62909
62910 - fscache_stat(&fscache_n_attr_changed_calls);
62911 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
62912
62913 if (fscache_object_is_active(object)) {
62914 fscache_stat(&fscache_n_cop_attr_changed);
62915 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62916
62917 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62918
62919 - fscache_stat(&fscache_n_attr_changed);
62920 + fscache_stat_unchecked(&fscache_n_attr_changed);
62921
62922 op = kzalloc(sizeof(*op), GFP_KERNEL);
62923 if (!op) {
62924 - fscache_stat(&fscache_n_attr_changed_nomem);
62925 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
62926 _leave(" = -ENOMEM");
62927 return -ENOMEM;
62928 }
62929 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62930 if (fscache_submit_exclusive_op(object, op) < 0)
62931 goto nobufs_dec;
62932 spin_unlock(&cookie->lock);
62933 - fscache_stat(&fscache_n_attr_changed_ok);
62934 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
62935 fscache_put_operation(op);
62936 _leave(" = 0");
62937 return 0;
62938 @@ -242,7 +242,7 @@ nobufs:
62939 kfree(op);
62940 if (wake_cookie)
62941 __fscache_wake_unused_cookie(cookie);
62942 - fscache_stat(&fscache_n_attr_changed_nobufs);
62943 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
62944 _leave(" = %d", -ENOBUFS);
62945 return -ENOBUFS;
62946 }
62947 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
62948 /* allocate a retrieval operation and attempt to submit it */
62949 op = kzalloc(sizeof(*op), GFP_NOIO);
62950 if (!op) {
62951 - fscache_stat(&fscache_n_retrievals_nomem);
62952 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62953 return NULL;
62954 }
62955
62956 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
62957 return 0;
62958 }
62959
62960 - fscache_stat(&fscache_n_retrievals_wait);
62961 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
62962
62963 jif = jiffies;
62964 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
62965 TASK_INTERRUPTIBLE) != 0) {
62966 - fscache_stat(&fscache_n_retrievals_intr);
62967 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
62968 _leave(" = -ERESTARTSYS");
62969 return -ERESTARTSYS;
62970 }
62971 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
62972 */
62973 int fscache_wait_for_operation_activation(struct fscache_object *object,
62974 struct fscache_operation *op,
62975 - atomic_t *stat_op_waits,
62976 - atomic_t *stat_object_dead,
62977 + atomic_unchecked_t *stat_op_waits,
62978 + atomic_unchecked_t *stat_object_dead,
62979 void (*do_cancel)(struct fscache_operation *))
62980 {
62981 int ret;
62982 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62983
62984 _debug(">>> WT");
62985 if (stat_op_waits)
62986 - fscache_stat(stat_op_waits);
62987 + fscache_stat_unchecked(stat_op_waits);
62988 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
62989 TASK_INTERRUPTIBLE) != 0) {
62990 ret = fscache_cancel_op(op, do_cancel);
62991 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62992 check_if_dead:
62993 if (op->state == FSCACHE_OP_ST_CANCELLED) {
62994 if (stat_object_dead)
62995 - fscache_stat(stat_object_dead);
62996 + fscache_stat_unchecked(stat_object_dead);
62997 _leave(" = -ENOBUFS [cancelled]");
62998 return -ENOBUFS;
62999 }
63000 @@ -381,7 +381,7 @@ check_if_dead:
63001 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63002 fscache_cancel_op(op, do_cancel);
63003 if (stat_object_dead)
63004 - fscache_stat(stat_object_dead);
63005 + fscache_stat_unchecked(stat_object_dead);
63006 return -ENOBUFS;
63007 }
63008 return 0;
63009 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63010
63011 _enter("%p,%p,,,", cookie, page);
63012
63013 - fscache_stat(&fscache_n_retrievals);
63014 + fscache_stat_unchecked(&fscache_n_retrievals);
63015
63016 if (hlist_empty(&cookie->backing_objects))
63017 goto nobufs;
63018 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63019 goto nobufs_unlock_dec;
63020 spin_unlock(&cookie->lock);
63021
63022 - fscache_stat(&fscache_n_retrieval_ops);
63023 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63024
63025 /* pin the netfs read context in case we need to do the actual netfs
63026 * read because we've encountered a cache read failure */
63027 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63028
63029 error:
63030 if (ret == -ENOMEM)
63031 - fscache_stat(&fscache_n_retrievals_nomem);
63032 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63033 else if (ret == -ERESTARTSYS)
63034 - fscache_stat(&fscache_n_retrievals_intr);
63035 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63036 else if (ret == -ENODATA)
63037 - fscache_stat(&fscache_n_retrievals_nodata);
63038 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63039 else if (ret < 0)
63040 - fscache_stat(&fscache_n_retrievals_nobufs);
63041 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63042 else
63043 - fscache_stat(&fscache_n_retrievals_ok);
63044 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63045
63046 fscache_put_retrieval(op);
63047 _leave(" = %d", ret);
63048 @@ -505,7 +505,7 @@ nobufs_unlock:
63049 __fscache_wake_unused_cookie(cookie);
63050 kfree(op);
63051 nobufs:
63052 - fscache_stat(&fscache_n_retrievals_nobufs);
63053 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63054 _leave(" = -ENOBUFS");
63055 return -ENOBUFS;
63056 }
63057 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63058
63059 _enter("%p,,%d,,,", cookie, *nr_pages);
63060
63061 - fscache_stat(&fscache_n_retrievals);
63062 + fscache_stat_unchecked(&fscache_n_retrievals);
63063
63064 if (hlist_empty(&cookie->backing_objects))
63065 goto nobufs;
63066 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63067 goto nobufs_unlock_dec;
63068 spin_unlock(&cookie->lock);
63069
63070 - fscache_stat(&fscache_n_retrieval_ops);
63071 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63072
63073 /* pin the netfs read context in case we need to do the actual netfs
63074 * read because we've encountered a cache read failure */
63075 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63076
63077 error:
63078 if (ret == -ENOMEM)
63079 - fscache_stat(&fscache_n_retrievals_nomem);
63080 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63081 else if (ret == -ERESTARTSYS)
63082 - fscache_stat(&fscache_n_retrievals_intr);
63083 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63084 else if (ret == -ENODATA)
63085 - fscache_stat(&fscache_n_retrievals_nodata);
63086 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63087 else if (ret < 0)
63088 - fscache_stat(&fscache_n_retrievals_nobufs);
63089 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63090 else
63091 - fscache_stat(&fscache_n_retrievals_ok);
63092 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63093
63094 fscache_put_retrieval(op);
63095 _leave(" = %d", ret);
63096 @@ -636,7 +636,7 @@ nobufs_unlock:
63097 if (wake_cookie)
63098 __fscache_wake_unused_cookie(cookie);
63099 nobufs:
63100 - fscache_stat(&fscache_n_retrievals_nobufs);
63101 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63102 _leave(" = -ENOBUFS");
63103 return -ENOBUFS;
63104 }
63105 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63106
63107 _enter("%p,%p,,,", cookie, page);
63108
63109 - fscache_stat(&fscache_n_allocs);
63110 + fscache_stat_unchecked(&fscache_n_allocs);
63111
63112 if (hlist_empty(&cookie->backing_objects))
63113 goto nobufs;
63114 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63115 goto nobufs_unlock_dec;
63116 spin_unlock(&cookie->lock);
63117
63118 - fscache_stat(&fscache_n_alloc_ops);
63119 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63120
63121 ret = fscache_wait_for_operation_activation(
63122 object, &op->op,
63123 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63124
63125 error:
63126 if (ret == -ERESTARTSYS)
63127 - fscache_stat(&fscache_n_allocs_intr);
63128 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63129 else if (ret < 0)
63130 - fscache_stat(&fscache_n_allocs_nobufs);
63131 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63132 else
63133 - fscache_stat(&fscache_n_allocs_ok);
63134 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63135
63136 fscache_put_retrieval(op);
63137 _leave(" = %d", ret);
63138 @@ -730,7 +730,7 @@ nobufs_unlock:
63139 if (wake_cookie)
63140 __fscache_wake_unused_cookie(cookie);
63141 nobufs:
63142 - fscache_stat(&fscache_n_allocs_nobufs);
63143 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63144 _leave(" = -ENOBUFS");
63145 return -ENOBUFS;
63146 }
63147 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63148
63149 spin_lock(&cookie->stores_lock);
63150
63151 - fscache_stat(&fscache_n_store_calls);
63152 + fscache_stat_unchecked(&fscache_n_store_calls);
63153
63154 /* find a page to store */
63155 page = NULL;
63156 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63157 page = results[0];
63158 _debug("gang %d [%lx]", n, page->index);
63159 if (page->index > op->store_limit) {
63160 - fscache_stat(&fscache_n_store_pages_over_limit);
63161 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63162 goto superseded;
63163 }
63164
63165 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63166 spin_unlock(&cookie->stores_lock);
63167 spin_unlock(&object->lock);
63168
63169 - fscache_stat(&fscache_n_store_pages);
63170 + fscache_stat_unchecked(&fscache_n_store_pages);
63171 fscache_stat(&fscache_n_cop_write_page);
63172 ret = object->cache->ops->write_page(op, page);
63173 fscache_stat_d(&fscache_n_cop_write_page);
63174 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63175 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63176 ASSERT(PageFsCache(page));
63177
63178 - fscache_stat(&fscache_n_stores);
63179 + fscache_stat_unchecked(&fscache_n_stores);
63180
63181 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63182 _leave(" = -ENOBUFS [invalidating]");
63183 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63184 spin_unlock(&cookie->stores_lock);
63185 spin_unlock(&object->lock);
63186
63187 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63188 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63189 op->store_limit = object->store_limit;
63190
63191 __fscache_use_cookie(cookie);
63192 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63193
63194 spin_unlock(&cookie->lock);
63195 radix_tree_preload_end();
63196 - fscache_stat(&fscache_n_store_ops);
63197 - fscache_stat(&fscache_n_stores_ok);
63198 + fscache_stat_unchecked(&fscache_n_store_ops);
63199 + fscache_stat_unchecked(&fscache_n_stores_ok);
63200
63201 /* the work queue now carries its own ref on the object */
63202 fscache_put_operation(&op->op);
63203 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63204 return 0;
63205
63206 already_queued:
63207 - fscache_stat(&fscache_n_stores_again);
63208 + fscache_stat_unchecked(&fscache_n_stores_again);
63209 already_pending:
63210 spin_unlock(&cookie->stores_lock);
63211 spin_unlock(&object->lock);
63212 spin_unlock(&cookie->lock);
63213 radix_tree_preload_end();
63214 kfree(op);
63215 - fscache_stat(&fscache_n_stores_ok);
63216 + fscache_stat_unchecked(&fscache_n_stores_ok);
63217 _leave(" = 0");
63218 return 0;
63219
63220 @@ -1039,14 +1039,14 @@ nobufs:
63221 kfree(op);
63222 if (wake_cookie)
63223 __fscache_wake_unused_cookie(cookie);
63224 - fscache_stat(&fscache_n_stores_nobufs);
63225 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63226 _leave(" = -ENOBUFS");
63227 return -ENOBUFS;
63228
63229 nomem_free:
63230 kfree(op);
63231 nomem:
63232 - fscache_stat(&fscache_n_stores_oom);
63233 + fscache_stat_unchecked(&fscache_n_stores_oom);
63234 _leave(" = -ENOMEM");
63235 return -ENOMEM;
63236 }
63237 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63238 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63239 ASSERTCMP(page, !=, NULL);
63240
63241 - fscache_stat(&fscache_n_uncaches);
63242 + fscache_stat_unchecked(&fscache_n_uncaches);
63243
63244 /* cache withdrawal may beat us to it */
63245 if (!PageFsCache(page))
63246 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63247 struct fscache_cookie *cookie = op->op.object->cookie;
63248
63249 #ifdef CONFIG_FSCACHE_STATS
63250 - atomic_inc(&fscache_n_marks);
63251 + atomic_inc_unchecked(&fscache_n_marks);
63252 #endif
63253
63254 _debug("- mark %p{%lx}", page, page->index);
63255 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63256 index 40d13c7..ddf52b9 100644
63257 --- a/fs/fscache/stats.c
63258 +++ b/fs/fscache/stats.c
63259 @@ -18,99 +18,99 @@
63260 /*
63261 * operation counters
63262 */
63263 -atomic_t fscache_n_op_pend;
63264 -atomic_t fscache_n_op_run;
63265 -atomic_t fscache_n_op_enqueue;
63266 -atomic_t fscache_n_op_requeue;
63267 -atomic_t fscache_n_op_deferred_release;
63268 -atomic_t fscache_n_op_release;
63269 -atomic_t fscache_n_op_gc;
63270 -atomic_t fscache_n_op_cancelled;
63271 -atomic_t fscache_n_op_rejected;
63272 +atomic_unchecked_t fscache_n_op_pend;
63273 +atomic_unchecked_t fscache_n_op_run;
63274 +atomic_unchecked_t fscache_n_op_enqueue;
63275 +atomic_unchecked_t fscache_n_op_requeue;
63276 +atomic_unchecked_t fscache_n_op_deferred_release;
63277 +atomic_unchecked_t fscache_n_op_release;
63278 +atomic_unchecked_t fscache_n_op_gc;
63279 +atomic_unchecked_t fscache_n_op_cancelled;
63280 +atomic_unchecked_t fscache_n_op_rejected;
63281
63282 -atomic_t fscache_n_attr_changed;
63283 -atomic_t fscache_n_attr_changed_ok;
63284 -atomic_t fscache_n_attr_changed_nobufs;
63285 -atomic_t fscache_n_attr_changed_nomem;
63286 -atomic_t fscache_n_attr_changed_calls;
63287 +atomic_unchecked_t fscache_n_attr_changed;
63288 +atomic_unchecked_t fscache_n_attr_changed_ok;
63289 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63290 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63291 +atomic_unchecked_t fscache_n_attr_changed_calls;
63292
63293 -atomic_t fscache_n_allocs;
63294 -atomic_t fscache_n_allocs_ok;
63295 -atomic_t fscache_n_allocs_wait;
63296 -atomic_t fscache_n_allocs_nobufs;
63297 -atomic_t fscache_n_allocs_intr;
63298 -atomic_t fscache_n_allocs_object_dead;
63299 -atomic_t fscache_n_alloc_ops;
63300 -atomic_t fscache_n_alloc_op_waits;
63301 +atomic_unchecked_t fscache_n_allocs;
63302 +atomic_unchecked_t fscache_n_allocs_ok;
63303 +atomic_unchecked_t fscache_n_allocs_wait;
63304 +atomic_unchecked_t fscache_n_allocs_nobufs;
63305 +atomic_unchecked_t fscache_n_allocs_intr;
63306 +atomic_unchecked_t fscache_n_allocs_object_dead;
63307 +atomic_unchecked_t fscache_n_alloc_ops;
63308 +atomic_unchecked_t fscache_n_alloc_op_waits;
63309
63310 -atomic_t fscache_n_retrievals;
63311 -atomic_t fscache_n_retrievals_ok;
63312 -atomic_t fscache_n_retrievals_wait;
63313 -atomic_t fscache_n_retrievals_nodata;
63314 -atomic_t fscache_n_retrievals_nobufs;
63315 -atomic_t fscache_n_retrievals_intr;
63316 -atomic_t fscache_n_retrievals_nomem;
63317 -atomic_t fscache_n_retrievals_object_dead;
63318 -atomic_t fscache_n_retrieval_ops;
63319 -atomic_t fscache_n_retrieval_op_waits;
63320 +atomic_unchecked_t fscache_n_retrievals;
63321 +atomic_unchecked_t fscache_n_retrievals_ok;
63322 +atomic_unchecked_t fscache_n_retrievals_wait;
63323 +atomic_unchecked_t fscache_n_retrievals_nodata;
63324 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63325 +atomic_unchecked_t fscache_n_retrievals_intr;
63326 +atomic_unchecked_t fscache_n_retrievals_nomem;
63327 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63328 +atomic_unchecked_t fscache_n_retrieval_ops;
63329 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63330
63331 -atomic_t fscache_n_stores;
63332 -atomic_t fscache_n_stores_ok;
63333 -atomic_t fscache_n_stores_again;
63334 -atomic_t fscache_n_stores_nobufs;
63335 -atomic_t fscache_n_stores_oom;
63336 -atomic_t fscache_n_store_ops;
63337 -atomic_t fscache_n_store_calls;
63338 -atomic_t fscache_n_store_pages;
63339 -atomic_t fscache_n_store_radix_deletes;
63340 -atomic_t fscache_n_store_pages_over_limit;
63341 +atomic_unchecked_t fscache_n_stores;
63342 +atomic_unchecked_t fscache_n_stores_ok;
63343 +atomic_unchecked_t fscache_n_stores_again;
63344 +atomic_unchecked_t fscache_n_stores_nobufs;
63345 +atomic_unchecked_t fscache_n_stores_oom;
63346 +atomic_unchecked_t fscache_n_store_ops;
63347 +atomic_unchecked_t fscache_n_store_calls;
63348 +atomic_unchecked_t fscache_n_store_pages;
63349 +atomic_unchecked_t fscache_n_store_radix_deletes;
63350 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63351
63352 -atomic_t fscache_n_store_vmscan_not_storing;
63353 -atomic_t fscache_n_store_vmscan_gone;
63354 -atomic_t fscache_n_store_vmscan_busy;
63355 -atomic_t fscache_n_store_vmscan_cancelled;
63356 -atomic_t fscache_n_store_vmscan_wait;
63357 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63358 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63359 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63360 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63361 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63362
63363 -atomic_t fscache_n_marks;
63364 -atomic_t fscache_n_uncaches;
63365 +atomic_unchecked_t fscache_n_marks;
63366 +atomic_unchecked_t fscache_n_uncaches;
63367
63368 -atomic_t fscache_n_acquires;
63369 -atomic_t fscache_n_acquires_null;
63370 -atomic_t fscache_n_acquires_no_cache;
63371 -atomic_t fscache_n_acquires_ok;
63372 -atomic_t fscache_n_acquires_nobufs;
63373 -atomic_t fscache_n_acquires_oom;
63374 +atomic_unchecked_t fscache_n_acquires;
63375 +atomic_unchecked_t fscache_n_acquires_null;
63376 +atomic_unchecked_t fscache_n_acquires_no_cache;
63377 +atomic_unchecked_t fscache_n_acquires_ok;
63378 +atomic_unchecked_t fscache_n_acquires_nobufs;
63379 +atomic_unchecked_t fscache_n_acquires_oom;
63380
63381 -atomic_t fscache_n_invalidates;
63382 -atomic_t fscache_n_invalidates_run;
63383 +atomic_unchecked_t fscache_n_invalidates;
63384 +atomic_unchecked_t fscache_n_invalidates_run;
63385
63386 -atomic_t fscache_n_updates;
63387 -atomic_t fscache_n_updates_null;
63388 -atomic_t fscache_n_updates_run;
63389 +atomic_unchecked_t fscache_n_updates;
63390 +atomic_unchecked_t fscache_n_updates_null;
63391 +atomic_unchecked_t fscache_n_updates_run;
63392
63393 -atomic_t fscache_n_relinquishes;
63394 -atomic_t fscache_n_relinquishes_null;
63395 -atomic_t fscache_n_relinquishes_waitcrt;
63396 -atomic_t fscache_n_relinquishes_retire;
63397 +atomic_unchecked_t fscache_n_relinquishes;
63398 +atomic_unchecked_t fscache_n_relinquishes_null;
63399 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63400 +atomic_unchecked_t fscache_n_relinquishes_retire;
63401
63402 -atomic_t fscache_n_cookie_index;
63403 -atomic_t fscache_n_cookie_data;
63404 -atomic_t fscache_n_cookie_special;
63405 +atomic_unchecked_t fscache_n_cookie_index;
63406 +atomic_unchecked_t fscache_n_cookie_data;
63407 +atomic_unchecked_t fscache_n_cookie_special;
63408
63409 -atomic_t fscache_n_object_alloc;
63410 -atomic_t fscache_n_object_no_alloc;
63411 -atomic_t fscache_n_object_lookups;
63412 -atomic_t fscache_n_object_lookups_negative;
63413 -atomic_t fscache_n_object_lookups_positive;
63414 -atomic_t fscache_n_object_lookups_timed_out;
63415 -atomic_t fscache_n_object_created;
63416 -atomic_t fscache_n_object_avail;
63417 -atomic_t fscache_n_object_dead;
63418 +atomic_unchecked_t fscache_n_object_alloc;
63419 +atomic_unchecked_t fscache_n_object_no_alloc;
63420 +atomic_unchecked_t fscache_n_object_lookups;
63421 +atomic_unchecked_t fscache_n_object_lookups_negative;
63422 +atomic_unchecked_t fscache_n_object_lookups_positive;
63423 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63424 +atomic_unchecked_t fscache_n_object_created;
63425 +atomic_unchecked_t fscache_n_object_avail;
63426 +atomic_unchecked_t fscache_n_object_dead;
63427
63428 -atomic_t fscache_n_checkaux_none;
63429 -atomic_t fscache_n_checkaux_okay;
63430 -atomic_t fscache_n_checkaux_update;
63431 -atomic_t fscache_n_checkaux_obsolete;
63432 +atomic_unchecked_t fscache_n_checkaux_none;
63433 +atomic_unchecked_t fscache_n_checkaux_okay;
63434 +atomic_unchecked_t fscache_n_checkaux_update;
63435 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63436
63437 atomic_t fscache_n_cop_alloc_object;
63438 atomic_t fscache_n_cop_lookup_object;
63439 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63440 seq_puts(m, "FS-Cache statistics\n");
63441
63442 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63443 - atomic_read(&fscache_n_cookie_index),
63444 - atomic_read(&fscache_n_cookie_data),
63445 - atomic_read(&fscache_n_cookie_special));
63446 + atomic_read_unchecked(&fscache_n_cookie_index),
63447 + atomic_read_unchecked(&fscache_n_cookie_data),
63448 + atomic_read_unchecked(&fscache_n_cookie_special));
63449
63450 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63451 - atomic_read(&fscache_n_object_alloc),
63452 - atomic_read(&fscache_n_object_no_alloc),
63453 - atomic_read(&fscache_n_object_avail),
63454 - atomic_read(&fscache_n_object_dead));
63455 + atomic_read_unchecked(&fscache_n_object_alloc),
63456 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63457 + atomic_read_unchecked(&fscache_n_object_avail),
63458 + atomic_read_unchecked(&fscache_n_object_dead));
63459 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63460 - atomic_read(&fscache_n_checkaux_none),
63461 - atomic_read(&fscache_n_checkaux_okay),
63462 - atomic_read(&fscache_n_checkaux_update),
63463 - atomic_read(&fscache_n_checkaux_obsolete));
63464 + atomic_read_unchecked(&fscache_n_checkaux_none),
63465 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63466 + atomic_read_unchecked(&fscache_n_checkaux_update),
63467 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63468
63469 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63470 - atomic_read(&fscache_n_marks),
63471 - atomic_read(&fscache_n_uncaches));
63472 + atomic_read_unchecked(&fscache_n_marks),
63473 + atomic_read_unchecked(&fscache_n_uncaches));
63474
63475 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63476 " oom=%u\n",
63477 - atomic_read(&fscache_n_acquires),
63478 - atomic_read(&fscache_n_acquires_null),
63479 - atomic_read(&fscache_n_acquires_no_cache),
63480 - atomic_read(&fscache_n_acquires_ok),
63481 - atomic_read(&fscache_n_acquires_nobufs),
63482 - atomic_read(&fscache_n_acquires_oom));
63483 + atomic_read_unchecked(&fscache_n_acquires),
63484 + atomic_read_unchecked(&fscache_n_acquires_null),
63485 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63486 + atomic_read_unchecked(&fscache_n_acquires_ok),
63487 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63488 + atomic_read_unchecked(&fscache_n_acquires_oom));
63489
63490 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63491 - atomic_read(&fscache_n_object_lookups),
63492 - atomic_read(&fscache_n_object_lookups_negative),
63493 - atomic_read(&fscache_n_object_lookups_positive),
63494 - atomic_read(&fscache_n_object_created),
63495 - atomic_read(&fscache_n_object_lookups_timed_out));
63496 + atomic_read_unchecked(&fscache_n_object_lookups),
63497 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63498 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63499 + atomic_read_unchecked(&fscache_n_object_created),
63500 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63501
63502 seq_printf(m, "Invals : n=%u run=%u\n",
63503 - atomic_read(&fscache_n_invalidates),
63504 - atomic_read(&fscache_n_invalidates_run));
63505 + atomic_read_unchecked(&fscache_n_invalidates),
63506 + atomic_read_unchecked(&fscache_n_invalidates_run));
63507
63508 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63509 - atomic_read(&fscache_n_updates),
63510 - atomic_read(&fscache_n_updates_null),
63511 - atomic_read(&fscache_n_updates_run));
63512 + atomic_read_unchecked(&fscache_n_updates),
63513 + atomic_read_unchecked(&fscache_n_updates_null),
63514 + atomic_read_unchecked(&fscache_n_updates_run));
63515
63516 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63517 - atomic_read(&fscache_n_relinquishes),
63518 - atomic_read(&fscache_n_relinquishes_null),
63519 - atomic_read(&fscache_n_relinquishes_waitcrt),
63520 - atomic_read(&fscache_n_relinquishes_retire));
63521 + atomic_read_unchecked(&fscache_n_relinquishes),
63522 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63523 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63524 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63525
63526 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63527 - atomic_read(&fscache_n_attr_changed),
63528 - atomic_read(&fscache_n_attr_changed_ok),
63529 - atomic_read(&fscache_n_attr_changed_nobufs),
63530 - atomic_read(&fscache_n_attr_changed_nomem),
63531 - atomic_read(&fscache_n_attr_changed_calls));
63532 + atomic_read_unchecked(&fscache_n_attr_changed),
63533 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63534 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63535 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63536 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63537
63538 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63539 - atomic_read(&fscache_n_allocs),
63540 - atomic_read(&fscache_n_allocs_ok),
63541 - atomic_read(&fscache_n_allocs_wait),
63542 - atomic_read(&fscache_n_allocs_nobufs),
63543 - atomic_read(&fscache_n_allocs_intr));
63544 + atomic_read_unchecked(&fscache_n_allocs),
63545 + atomic_read_unchecked(&fscache_n_allocs_ok),
63546 + atomic_read_unchecked(&fscache_n_allocs_wait),
63547 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63548 + atomic_read_unchecked(&fscache_n_allocs_intr));
63549 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63550 - atomic_read(&fscache_n_alloc_ops),
63551 - atomic_read(&fscache_n_alloc_op_waits),
63552 - atomic_read(&fscache_n_allocs_object_dead));
63553 + atomic_read_unchecked(&fscache_n_alloc_ops),
63554 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63555 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63556
63557 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63558 " int=%u oom=%u\n",
63559 - atomic_read(&fscache_n_retrievals),
63560 - atomic_read(&fscache_n_retrievals_ok),
63561 - atomic_read(&fscache_n_retrievals_wait),
63562 - atomic_read(&fscache_n_retrievals_nodata),
63563 - atomic_read(&fscache_n_retrievals_nobufs),
63564 - atomic_read(&fscache_n_retrievals_intr),
63565 - atomic_read(&fscache_n_retrievals_nomem));
63566 + atomic_read_unchecked(&fscache_n_retrievals),
63567 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63568 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63569 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63570 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63571 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63572 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63573 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63574 - atomic_read(&fscache_n_retrieval_ops),
63575 - atomic_read(&fscache_n_retrieval_op_waits),
63576 - atomic_read(&fscache_n_retrievals_object_dead));
63577 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63578 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63579 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63580
63581 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63582 - atomic_read(&fscache_n_stores),
63583 - atomic_read(&fscache_n_stores_ok),
63584 - atomic_read(&fscache_n_stores_again),
63585 - atomic_read(&fscache_n_stores_nobufs),
63586 - atomic_read(&fscache_n_stores_oom));
63587 + atomic_read_unchecked(&fscache_n_stores),
63588 + atomic_read_unchecked(&fscache_n_stores_ok),
63589 + atomic_read_unchecked(&fscache_n_stores_again),
63590 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63591 + atomic_read_unchecked(&fscache_n_stores_oom));
63592 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63593 - atomic_read(&fscache_n_store_ops),
63594 - atomic_read(&fscache_n_store_calls),
63595 - atomic_read(&fscache_n_store_pages),
63596 - atomic_read(&fscache_n_store_radix_deletes),
63597 - atomic_read(&fscache_n_store_pages_over_limit));
63598 + atomic_read_unchecked(&fscache_n_store_ops),
63599 + atomic_read_unchecked(&fscache_n_store_calls),
63600 + atomic_read_unchecked(&fscache_n_store_pages),
63601 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63602 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63603
63604 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63605 - atomic_read(&fscache_n_store_vmscan_not_storing),
63606 - atomic_read(&fscache_n_store_vmscan_gone),
63607 - atomic_read(&fscache_n_store_vmscan_busy),
63608 - atomic_read(&fscache_n_store_vmscan_cancelled),
63609 - atomic_read(&fscache_n_store_vmscan_wait));
63610 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63611 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63612 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63613 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63614 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63615
63616 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63617 - atomic_read(&fscache_n_op_pend),
63618 - atomic_read(&fscache_n_op_run),
63619 - atomic_read(&fscache_n_op_enqueue),
63620 - atomic_read(&fscache_n_op_cancelled),
63621 - atomic_read(&fscache_n_op_rejected));
63622 + atomic_read_unchecked(&fscache_n_op_pend),
63623 + atomic_read_unchecked(&fscache_n_op_run),
63624 + atomic_read_unchecked(&fscache_n_op_enqueue),
63625 + atomic_read_unchecked(&fscache_n_op_cancelled),
63626 + atomic_read_unchecked(&fscache_n_op_rejected));
63627 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63628 - atomic_read(&fscache_n_op_deferred_release),
63629 - atomic_read(&fscache_n_op_release),
63630 - atomic_read(&fscache_n_op_gc));
63631 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63632 + atomic_read_unchecked(&fscache_n_op_release),
63633 + atomic_read_unchecked(&fscache_n_op_gc));
63634
63635 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63636 atomic_read(&fscache_n_cop_alloc_object),
63637 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63638 index 966ace8..030a03a 100644
63639 --- a/fs/fuse/cuse.c
63640 +++ b/fs/fuse/cuse.c
63641 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63642 INIT_LIST_HEAD(&cuse_conntbl[i]);
63643
63644 /* inherit and extend fuse_dev_operations */
63645 - cuse_channel_fops = fuse_dev_operations;
63646 - cuse_channel_fops.owner = THIS_MODULE;
63647 - cuse_channel_fops.open = cuse_channel_open;
63648 - cuse_channel_fops.release = cuse_channel_release;
63649 + pax_open_kernel();
63650 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63651 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63652 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63653 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63654 + pax_close_kernel();
63655
63656 cuse_class = class_create(THIS_MODULE, "cuse");
63657 if (IS_ERR(cuse_class))
63658 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63659 index ca88731..8e9c55d 100644
63660 --- a/fs/fuse/dev.c
63661 +++ b/fs/fuse/dev.c
63662 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63663 ret = 0;
63664 pipe_lock(pipe);
63665
63666 - if (!pipe->readers) {
63667 + if (!atomic_read(&pipe->readers)) {
63668 send_sig(SIGPIPE, current, 0);
63669 if (!ret)
63670 ret = -EPIPE;
63671 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63672 page_nr++;
63673 ret += buf->len;
63674
63675 - if (pipe->files)
63676 + if (atomic_read(&pipe->files))
63677 do_wakeup = 1;
63678 }
63679
63680 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63681 index de1d84a..fd69c0c 100644
63682 --- a/fs/fuse/dir.c
63683 +++ b/fs/fuse/dir.c
63684 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
63685 return link;
63686 }
63687
63688 -static void free_link(char *link)
63689 +static void free_link(const char *link)
63690 {
63691 if (!IS_ERR(link))
63692 free_page((unsigned long) link);
63693 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63694 index fd62cae..3494dfa 100644
63695 --- a/fs/hostfs/hostfs_kern.c
63696 +++ b/fs/hostfs/hostfs_kern.c
63697 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63698
63699 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63700 {
63701 - char *s = nd_get_link(nd);
63702 + const char *s = nd_get_link(nd);
63703 if (!IS_ERR(s))
63704 __putname(s);
63705 }
63706 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63707 index 1e2872b..7aea000 100644
63708 --- a/fs/hugetlbfs/inode.c
63709 +++ b/fs/hugetlbfs/inode.c
63710 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63711 struct mm_struct *mm = current->mm;
63712 struct vm_area_struct *vma;
63713 struct hstate *h = hstate_file(file);
63714 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63715 struct vm_unmapped_area_info info;
63716
63717 if (len & ~huge_page_mask(h))
63718 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63719 return addr;
63720 }
63721
63722 +#ifdef CONFIG_PAX_RANDMMAP
63723 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63724 +#endif
63725 +
63726 if (addr) {
63727 addr = ALIGN(addr, huge_page_size(h));
63728 vma = find_vma(mm, addr);
63729 - if (TASK_SIZE - len >= addr &&
63730 - (!vma || addr + len <= vma->vm_start))
63731 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63732 return addr;
63733 }
63734
63735 info.flags = 0;
63736 info.length = len;
63737 info.low_limit = TASK_UNMAPPED_BASE;
63738 +
63739 +#ifdef CONFIG_PAX_RANDMMAP
63740 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63741 + info.low_limit += mm->delta_mmap;
63742 +#endif
63743 +
63744 info.high_limit = TASK_SIZE;
63745 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63746 info.align_offset = 0;
63747 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63748 };
63749 MODULE_ALIAS_FS("hugetlbfs");
63750
63751 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63752 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63753
63754 static int can_do_hugetlb_shm(void)
63755 {
63756 diff --git a/fs/inode.c b/fs/inode.c
63757 index 26753ba..d19eb34 100644
63758 --- a/fs/inode.c
63759 +++ b/fs/inode.c
63760 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63761 unsigned int *p = &get_cpu_var(last_ino);
63762 unsigned int res = *p;
63763
63764 +start:
63765 +
63766 #ifdef CONFIG_SMP
63767 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63768 - static atomic_t shared_last_ino;
63769 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63770 + static atomic_unchecked_t shared_last_ino;
63771 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63772
63773 res = next - LAST_INO_BATCH;
63774 }
63775 #endif
63776
63777 - *p = ++res;
63778 + if (unlikely(!++res))
63779 + goto start; /* never zero */
63780 + *p = res;
63781 put_cpu_var(last_ino);
63782 return res;
63783 }
63784 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63785 index 4a6cf28..d3a29d3 100644
63786 --- a/fs/jffs2/erase.c
63787 +++ b/fs/jffs2/erase.c
63788 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63789 struct jffs2_unknown_node marker = {
63790 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63791 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63792 - .totlen = cpu_to_je32(c->cleanmarker_size)
63793 + .totlen = cpu_to_je32(c->cleanmarker_size),
63794 + .hdr_crc = cpu_to_je32(0)
63795 };
63796
63797 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63798 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63799 index 09ed551..45684f8 100644
63800 --- a/fs/jffs2/wbuf.c
63801 +++ b/fs/jffs2/wbuf.c
63802 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63803 {
63804 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63805 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63806 - .totlen = constant_cpu_to_je32(8)
63807 + .totlen = constant_cpu_to_je32(8),
63808 + .hdr_crc = constant_cpu_to_je32(0)
63809 };
63810
63811 /*
63812 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63813 index adf8cb0..bb935fa 100644
63814 --- a/fs/jfs/super.c
63815 +++ b/fs/jfs/super.c
63816 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63817
63818 jfs_inode_cachep =
63819 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63820 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63821 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63822 init_once);
63823 if (jfs_inode_cachep == NULL)
63824 return -ENOMEM;
63825 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63826 index a693f5b..82276a1 100644
63827 --- a/fs/kernfs/dir.c
63828 +++ b/fs/kernfs/dir.c
63829 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63830 *
63831 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63832 */
63833 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63834 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63835 {
63836 unsigned long hash = init_name_hash();
63837 unsigned int len = strlen(name);
63838 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63839 index 4429d6d..9831f52 100644
63840 --- a/fs/kernfs/file.c
63841 +++ b/fs/kernfs/file.c
63842 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63843
63844 struct kernfs_open_node {
63845 atomic_t refcnt;
63846 - atomic_t event;
63847 + atomic_unchecked_t event;
63848 wait_queue_head_t poll;
63849 struct list_head files; /* goes through kernfs_open_file.list */
63850 };
63851 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63852 {
63853 struct kernfs_open_file *of = sf->private;
63854
63855 - of->event = atomic_read(&of->kn->attr.open->event);
63856 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63857
63858 return of->kn->attr.ops->seq_show(sf, v);
63859 }
63860 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63861 return ret;
63862 }
63863
63864 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63865 - void *buf, int len, int write)
63866 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63867 + void *buf, size_t len, int write)
63868 {
63869 struct file *file = vma->vm_file;
63870 struct kernfs_open_file *of = kernfs_of(file);
63871 - int ret;
63872 + ssize_t ret;
63873
63874 if (!of->vm_ops)
63875 return -EINVAL;
63876 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63877 return -ENOMEM;
63878
63879 atomic_set(&new_on->refcnt, 0);
63880 - atomic_set(&new_on->event, 1);
63881 + atomic_set_unchecked(&new_on->event, 1);
63882 init_waitqueue_head(&new_on->poll);
63883 INIT_LIST_HEAD(&new_on->files);
63884 goto retry;
63885 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63886
63887 kernfs_put_active(kn);
63888
63889 - if (of->event != atomic_read(&on->event))
63890 + if (of->event != atomic_read_unchecked(&on->event))
63891 goto trigger;
63892
63893 return DEFAULT_POLLMASK;
63894 @@ -818,7 +818,7 @@ repeat:
63895
63896 on = kn->attr.open;
63897 if (on) {
63898 - atomic_inc(&on->event);
63899 + atomic_inc_unchecked(&on->event);
63900 wake_up_interruptible(&on->poll);
63901 }
63902
63903 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
63904 index 8a19889..4c3069a 100644
63905 --- a/fs/kernfs/symlink.c
63906 +++ b/fs/kernfs/symlink.c
63907 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
63908 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
63909 void *cookie)
63910 {
63911 - char *page = nd_get_link(nd);
63912 + const char *page = nd_get_link(nd);
63913 if (!IS_ERR(page))
63914 free_page((unsigned long)page);
63915 }
63916 diff --git a/fs/libfs.c b/fs/libfs.c
63917 index 88e3e00..979c262 100644
63918 --- a/fs/libfs.c
63919 +++ b/fs/libfs.c
63920 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63921
63922 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
63923 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
63924 + char d_name[sizeof(next->d_iname)];
63925 + const unsigned char *name;
63926 +
63927 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
63928 if (!simple_positive(next)) {
63929 spin_unlock(&next->d_lock);
63930 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63931
63932 spin_unlock(&next->d_lock);
63933 spin_unlock(&dentry->d_lock);
63934 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
63935 + name = next->d_name.name;
63936 + if (name == next->d_iname) {
63937 + memcpy(d_name, name, next->d_name.len);
63938 + name = d_name;
63939 + }
63940 + if (!dir_emit(ctx, name, next->d_name.len,
63941 next->d_inode->i_ino, dt_type(next->d_inode)))
63942 return 0;
63943 spin_lock(&dentry->d_lock);
63944 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
63945 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
63946 void *cookie)
63947 {
63948 - char *s = nd_get_link(nd);
63949 + const char *s = nd_get_link(nd);
63950 if (!IS_ERR(s))
63951 kfree(s);
63952 }
63953 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
63954 index acd3947..1f896e2 100644
63955 --- a/fs/lockd/clntproc.c
63956 +++ b/fs/lockd/clntproc.c
63957 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
63958 /*
63959 * Cookie counter for NLM requests
63960 */
63961 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
63962 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
63963
63964 void nlmclnt_next_cookie(struct nlm_cookie *c)
63965 {
63966 - u32 cookie = atomic_inc_return(&nlm_cookie);
63967 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
63968
63969 memcpy(c->data, &cookie, 4);
63970 c->len=4;
63971 diff --git a/fs/locks.c b/fs/locks.c
63972 index bb08857..f65e8bf 100644
63973 --- a/fs/locks.c
63974 +++ b/fs/locks.c
63975 @@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
63976 locks_remove_posix(filp, filp);
63977
63978 if (filp->f_op->flock) {
63979 - struct file_lock fl = {
63980 + struct file_lock flock = {
63981 .fl_owner = filp,
63982 .fl_pid = current->tgid,
63983 .fl_file = filp,
63984 @@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
63985 .fl_type = F_UNLCK,
63986 .fl_end = OFFSET_MAX,
63987 };
63988 - filp->f_op->flock(filp, F_SETLKW, &fl);
63989 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
63990 - fl.fl_ops->fl_release_private(&fl);
63991 + filp->f_op->flock(filp, F_SETLKW, &flock);
63992 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
63993 + flock.fl_ops->fl_release_private(&flock);
63994 }
63995
63996 spin_lock(&inode->i_lock);
63997 diff --git a/fs/mount.h b/fs/mount.h
63998 index 6740a62..ccb472f 100644
63999 --- a/fs/mount.h
64000 +++ b/fs/mount.h
64001 @@ -11,7 +11,7 @@ struct mnt_namespace {
64002 u64 seq; /* Sequence number to prevent loops */
64003 wait_queue_head_t poll;
64004 u64 event;
64005 -};
64006 +} __randomize_layout;
64007
64008 struct mnt_pcp {
64009 int mnt_count;
64010 @@ -57,7 +57,7 @@ struct mount {
64011 int mnt_expiry_mark; /* true if marked for expiry */
64012 struct hlist_head mnt_pins;
64013 struct path mnt_ex_mountpoint;
64014 -};
64015 +} __randomize_layout;
64016
64017 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64018
64019 diff --git a/fs/namei.c b/fs/namei.c
64020 index bb02687..79cba2c 100644
64021 --- a/fs/namei.c
64022 +++ b/fs/namei.c
64023 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64024 if (ret != -EACCES)
64025 return ret;
64026
64027 +#ifdef CONFIG_GRKERNSEC
64028 + /* we'll block if we have to log due to a denied capability use */
64029 + if (mask & MAY_NOT_BLOCK)
64030 + return -ECHILD;
64031 +#endif
64032 +
64033 if (S_ISDIR(inode->i_mode)) {
64034 /* DACs are overridable for directories */
64035 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64036 - return 0;
64037 if (!(mask & MAY_WRITE))
64038 - if (capable_wrt_inode_uidgid(inode,
64039 - CAP_DAC_READ_SEARCH))
64040 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64041 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64042 return 0;
64043 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64044 + return 0;
64045 return -EACCES;
64046 }
64047 /*
64048 + * Searching includes executable on directories, else just read.
64049 + */
64050 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64051 + if (mask == MAY_READ)
64052 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64053 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64054 + return 0;
64055 +
64056 + /*
64057 * Read/write DACs are always overridable.
64058 * Executable DACs are overridable when there is
64059 * at least one exec bit set.
64060 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64061 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64062 return 0;
64063
64064 - /*
64065 - * Searching includes executable on directories, else just read.
64066 - */
64067 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64068 - if (mask == MAY_READ)
64069 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64070 - return 0;
64071 -
64072 return -EACCES;
64073 }
64074 EXPORT_SYMBOL(generic_permission);
64075 @@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64076 {
64077 struct dentry *dentry = link->dentry;
64078 int error;
64079 - char *s;
64080 + const char *s;
64081
64082 BUG_ON(nd->flags & LOOKUP_RCU);
64083
64084 @@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64085 if (error)
64086 goto out_put_nd_path;
64087
64088 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64089 + dentry->d_inode, dentry, nd->path.mnt)) {
64090 + error = -EACCES;
64091 + goto out_put_nd_path;
64092 + }
64093 +
64094 nd->last_type = LAST_BIND;
64095 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64096 error = PTR_ERR(*p);
64097 @@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64098 if (res)
64099 break;
64100 res = walk_component(nd, path, LOOKUP_FOLLOW);
64101 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64102 + res = -EACCES;
64103 put_link(nd, &link, cookie);
64104 } while (res > 0);
64105
64106 @@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
64107 static inline u64 hash_name(const char *name)
64108 {
64109 unsigned long a, b, adata, bdata, mask, hash, len;
64110 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64111 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64112
64113 hash = a = 0;
64114 len = -sizeof(unsigned long);
64115 @@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
64116 if (err)
64117 break;
64118 err = lookup_last(nd, &path);
64119 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64120 + err = -EACCES;
64121 put_link(nd, &link, cookie);
64122 }
64123 }
64124 @@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
64125 if (!err)
64126 err = complete_walk(nd);
64127
64128 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64129 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64130 + path_put(&nd->path);
64131 + err = -ENOENT;
64132 + }
64133 + }
64134 +
64135 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64136 if (!d_can_lookup(nd->path.dentry)) {
64137 path_put(&nd->path);
64138 @@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
64139 retval = path_lookupat(dfd, name->name,
64140 flags | LOOKUP_REVAL, nd);
64141
64142 - if (likely(!retval))
64143 + if (likely(!retval)) {
64144 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64145 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64146 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64147 + path_put(&nd->path);
64148 + return -ENOENT;
64149 + }
64150 + }
64151 + }
64152 return retval;
64153 }
64154
64155 @@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64156 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64157 return -EPERM;
64158
64159 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64160 + return -EPERM;
64161 + if (gr_handle_rawio(inode))
64162 + return -EPERM;
64163 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64164 + return -EACCES;
64165 +
64166 return 0;
64167 }
64168
64169 @@ -2816,7 +2854,7 @@ looked_up:
64170 * cleared otherwise prior to returning.
64171 */
64172 static int lookup_open(struct nameidata *nd, struct path *path,
64173 - struct file *file,
64174 + struct path *link, struct file *file,
64175 const struct open_flags *op,
64176 bool got_write, int *opened)
64177 {
64178 @@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64179 /* Negative dentry, just create the file */
64180 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64181 umode_t mode = op->mode;
64182 +
64183 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64184 + error = -EACCES;
64185 + goto out_dput;
64186 + }
64187 +
64188 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64189 + error = -EACCES;
64190 + goto out_dput;
64191 + }
64192 +
64193 if (!IS_POSIXACL(dir->d_inode))
64194 mode &= ~current_umask();
64195 /*
64196 @@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64197 nd->flags & LOOKUP_EXCL);
64198 if (error)
64199 goto out_dput;
64200 + else
64201 + gr_handle_create(dentry, nd->path.mnt);
64202 }
64203 out_no_open:
64204 path->dentry = dentry;
64205 @@ -2886,7 +2937,7 @@ out_dput:
64206 /*
64207 * Handle the last step of open()
64208 */
64209 -static int do_last(struct nameidata *nd, struct path *path,
64210 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64211 struct file *file, const struct open_flags *op,
64212 int *opened, struct filename *name)
64213 {
64214 @@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64215 if (error)
64216 return error;
64217
64218 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64219 + error = -ENOENT;
64220 + goto out;
64221 + }
64222 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64223 + error = -EACCES;
64224 + goto out;
64225 + }
64226 +
64227 audit_inode(name, dir, LOOKUP_PARENT);
64228 error = -EISDIR;
64229 /* trailing slashes? */
64230 @@ -2955,7 +3015,7 @@ retry_lookup:
64231 */
64232 }
64233 mutex_lock(&dir->d_inode->i_mutex);
64234 - error = lookup_open(nd, path, file, op, got_write, opened);
64235 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64236 mutex_unlock(&dir->d_inode->i_mutex);
64237
64238 if (error <= 0) {
64239 @@ -2979,11 +3039,28 @@ retry_lookup:
64240 goto finish_open_created;
64241 }
64242
64243 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64244 + error = -ENOENT;
64245 + goto exit_dput;
64246 + }
64247 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64248 + error = -EACCES;
64249 + goto exit_dput;
64250 + }
64251 +
64252 /*
64253 * create/update audit record if it already exists.
64254 */
64255 - if (d_is_positive(path->dentry))
64256 + if (d_is_positive(path->dentry)) {
64257 + /* only check if O_CREAT is specified, all other checks need to go
64258 + into may_open */
64259 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64260 + error = -EACCES;
64261 + goto exit_dput;
64262 + }
64263 +
64264 audit_inode(name, path->dentry, 0);
64265 + }
64266
64267 /*
64268 * If atomic_open() acquired write access it is dropped now due to
64269 @@ -3024,6 +3101,11 @@ finish_lookup:
64270 }
64271 }
64272 BUG_ON(inode != path->dentry->d_inode);
64273 + /* if we're resolving a symlink to another symlink */
64274 + if (link && gr_handle_symlink_owner(link, inode)) {
64275 + error = -EACCES;
64276 + goto out;
64277 + }
64278 return 1;
64279 }
64280
64281 @@ -3033,7 +3115,6 @@ finish_lookup:
64282 save_parent.dentry = nd->path.dentry;
64283 save_parent.mnt = mntget(path->mnt);
64284 nd->path.dentry = path->dentry;
64285 -
64286 }
64287 nd->inode = inode;
64288 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
64289 @@ -3043,7 +3124,18 @@ finish_open:
64290 path_put(&save_parent);
64291 return error;
64292 }
64293 +
64294 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64295 + error = -ENOENT;
64296 + goto out;
64297 + }
64298 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64299 + error = -EACCES;
64300 + goto out;
64301 + }
64302 +
64303 audit_inode(name, nd->path.dentry, 0);
64304 +
64305 error = -EISDIR;
64306 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64307 goto out;
64308 @@ -3207,7 +3299,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64309 if (unlikely(error))
64310 goto out;
64311
64312 - error = do_last(nd, &path, file, op, &opened, pathname);
64313 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64314 while (unlikely(error > 0)) { /* trailing symlink */
64315 struct path link = path;
64316 void *cookie;
64317 @@ -3225,7 +3317,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64318 error = follow_link(&link, nd, &cookie);
64319 if (unlikely(error))
64320 break;
64321 - error = do_last(nd, &path, file, op, &opened, pathname);
64322 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64323 put_link(nd, &link, cookie);
64324 }
64325 out:
64326 @@ -3325,9 +3417,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64327 goto unlock;
64328
64329 error = -EEXIST;
64330 - if (d_is_positive(dentry))
64331 + if (d_is_positive(dentry)) {
64332 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64333 + error = -ENOENT;
64334 goto fail;
64335 -
64336 + }
64337 /*
64338 * Special case - lookup gave negative, but... we had foo/bar/
64339 * From the vfs_mknod() POV we just have a negative dentry -
64340 @@ -3379,6 +3473,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64341 }
64342 EXPORT_SYMBOL(user_path_create);
64343
64344 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64345 +{
64346 + struct filename *tmp = getname(pathname);
64347 + struct dentry *res;
64348 + if (IS_ERR(tmp))
64349 + return ERR_CAST(tmp);
64350 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64351 + if (IS_ERR(res))
64352 + putname(tmp);
64353 + else
64354 + *to = tmp;
64355 + return res;
64356 +}
64357 +
64358 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64359 {
64360 int error = may_create(dir, dentry);
64361 @@ -3442,6 +3550,17 @@ retry:
64362
64363 if (!IS_POSIXACL(path.dentry->d_inode))
64364 mode &= ~current_umask();
64365 +
64366 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64367 + error = -EPERM;
64368 + goto out;
64369 + }
64370 +
64371 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64372 + error = -EACCES;
64373 + goto out;
64374 + }
64375 +
64376 error = security_path_mknod(&path, dentry, mode, dev);
64377 if (error)
64378 goto out;
64379 @@ -3457,6 +3576,8 @@ retry:
64380 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64381 break;
64382 }
64383 + if (!error)
64384 + gr_handle_create(dentry, path.mnt);
64385 out:
64386 done_path_create(&path, dentry);
64387 if (retry_estale(error, lookup_flags)) {
64388 @@ -3511,9 +3632,16 @@ retry:
64389
64390 if (!IS_POSIXACL(path.dentry->d_inode))
64391 mode &= ~current_umask();
64392 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64393 + error = -EACCES;
64394 + goto out;
64395 + }
64396 error = security_path_mkdir(&path, dentry, mode);
64397 if (!error)
64398 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64399 + if (!error)
64400 + gr_handle_create(dentry, path.mnt);
64401 +out:
64402 done_path_create(&path, dentry);
64403 if (retry_estale(error, lookup_flags)) {
64404 lookup_flags |= LOOKUP_REVAL;
64405 @@ -3596,6 +3724,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64406 struct filename *name;
64407 struct dentry *dentry;
64408 struct nameidata nd;
64409 + ino_t saved_ino = 0;
64410 + dev_t saved_dev = 0;
64411 unsigned int lookup_flags = 0;
64412 retry:
64413 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64414 @@ -3628,10 +3758,21 @@ retry:
64415 error = -ENOENT;
64416 goto exit3;
64417 }
64418 +
64419 + saved_ino = dentry->d_inode->i_ino;
64420 + saved_dev = gr_get_dev_from_dentry(dentry);
64421 +
64422 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64423 + error = -EACCES;
64424 + goto exit3;
64425 + }
64426 +
64427 error = security_path_rmdir(&nd.path, dentry);
64428 if (error)
64429 goto exit3;
64430 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64431 + if (!error && (saved_dev || saved_ino))
64432 + gr_handle_delete(saved_ino, saved_dev);
64433 exit3:
64434 dput(dentry);
64435 exit2:
64436 @@ -3722,6 +3863,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64437 struct nameidata nd;
64438 struct inode *inode = NULL;
64439 struct inode *delegated_inode = NULL;
64440 + ino_t saved_ino = 0;
64441 + dev_t saved_dev = 0;
64442 unsigned int lookup_flags = 0;
64443 retry:
64444 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64445 @@ -3748,10 +3891,22 @@ retry_deleg:
64446 if (d_is_negative(dentry))
64447 goto slashes;
64448 ihold(inode);
64449 +
64450 + if (inode->i_nlink <= 1) {
64451 + saved_ino = inode->i_ino;
64452 + saved_dev = gr_get_dev_from_dentry(dentry);
64453 + }
64454 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64455 + error = -EACCES;
64456 + goto exit2;
64457 + }
64458 +
64459 error = security_path_unlink(&nd.path, dentry);
64460 if (error)
64461 goto exit2;
64462 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64463 + if (!error && (saved_ino || saved_dev))
64464 + gr_handle_delete(saved_ino, saved_dev);
64465 exit2:
64466 dput(dentry);
64467 }
64468 @@ -3840,9 +3995,17 @@ retry:
64469 if (IS_ERR(dentry))
64470 goto out_putname;
64471
64472 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64473 + error = -EACCES;
64474 + goto out;
64475 + }
64476 +
64477 error = security_path_symlink(&path, dentry, from->name);
64478 if (!error)
64479 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64480 + if (!error)
64481 + gr_handle_create(dentry, path.mnt);
64482 +out:
64483 done_path_create(&path, dentry);
64484 if (retry_estale(error, lookup_flags)) {
64485 lookup_flags |= LOOKUP_REVAL;
64486 @@ -3946,6 +4109,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64487 struct dentry *new_dentry;
64488 struct path old_path, new_path;
64489 struct inode *delegated_inode = NULL;
64490 + struct filename *to = NULL;
64491 int how = 0;
64492 int error;
64493
64494 @@ -3969,7 +4133,7 @@ retry:
64495 if (error)
64496 return error;
64497
64498 - new_dentry = user_path_create(newdfd, newname, &new_path,
64499 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64500 (how & LOOKUP_REVAL));
64501 error = PTR_ERR(new_dentry);
64502 if (IS_ERR(new_dentry))
64503 @@ -3981,11 +4145,28 @@ retry:
64504 error = may_linkat(&old_path);
64505 if (unlikely(error))
64506 goto out_dput;
64507 +
64508 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64509 + old_path.dentry->d_inode,
64510 + old_path.dentry->d_inode->i_mode, to)) {
64511 + error = -EACCES;
64512 + goto out_dput;
64513 + }
64514 +
64515 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64516 + old_path.dentry, old_path.mnt, to)) {
64517 + error = -EACCES;
64518 + goto out_dput;
64519 + }
64520 +
64521 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64522 if (error)
64523 goto out_dput;
64524 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64525 + if (!error)
64526 + gr_handle_create(new_dentry, new_path.mnt);
64527 out_dput:
64528 + putname(to);
64529 done_path_create(&new_path, new_dentry);
64530 if (delegated_inode) {
64531 error = break_deleg_wait(&delegated_inode);
64532 @@ -4296,6 +4477,12 @@ retry_deleg:
64533 if (new_dentry == trap)
64534 goto exit5;
64535
64536 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64537 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64538 + to, flags);
64539 + if (error)
64540 + goto exit5;
64541 +
64542 error = security_path_rename(&oldnd.path, old_dentry,
64543 &newnd.path, new_dentry, flags);
64544 if (error)
64545 @@ -4303,6 +4490,9 @@ retry_deleg:
64546 error = vfs_rename(old_dir->d_inode, old_dentry,
64547 new_dir->d_inode, new_dentry,
64548 &delegated_inode, flags);
64549 + if (!error)
64550 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64551 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64552 exit5:
64553 dput(new_dentry);
64554 exit4:
64555 @@ -4345,14 +4535,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
64556
64557 int readlink_copy(char __user *buffer, int buflen, const char *link)
64558 {
64559 + char tmpbuf[64];
64560 + const char *newlink;
64561 int len = PTR_ERR(link);
64562 +
64563 if (IS_ERR(link))
64564 goto out;
64565
64566 len = strlen(link);
64567 if (len > (unsigned) buflen)
64568 len = buflen;
64569 - if (copy_to_user(buffer, link, len))
64570 +
64571 + if (len < sizeof(tmpbuf)) {
64572 + memcpy(tmpbuf, link, len);
64573 + newlink = tmpbuf;
64574 + } else
64575 + newlink = link;
64576 +
64577 + if (copy_to_user(buffer, newlink, len))
64578 len = -EFAULT;
64579 out:
64580 return len;
64581 diff --git a/fs/namespace.c b/fs/namespace.c
64582 index 550dbff..c4ad324 100644
64583 --- a/fs/namespace.c
64584 +++ b/fs/namespace.c
64585 @@ -1362,6 +1362,9 @@ static int do_umount(struct mount *mnt, int flags)
64586 if (!(sb->s_flags & MS_RDONLY))
64587 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64588 up_write(&sb->s_umount);
64589 +
64590 + gr_log_remount(mnt->mnt_devname, retval);
64591 +
64592 return retval;
64593 }
64594
64595 @@ -1384,6 +1387,9 @@ static int do_umount(struct mount *mnt, int flags)
64596 }
64597 unlock_mount_hash();
64598 namespace_unlock();
64599 +
64600 + gr_log_unmount(mnt->mnt_devname, retval);
64601 +
64602 return retval;
64603 }
64604
64605 @@ -1403,7 +1409,7 @@ static inline bool may_mount(void)
64606 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64607 */
64608
64609 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64610 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64611 {
64612 struct path path;
64613 struct mount *mnt;
64614 @@ -1445,7 +1451,7 @@ out:
64615 /*
64616 * The 2.0 compatible umount. No flags.
64617 */
64618 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64619 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64620 {
64621 return sys_umount(name, 0);
64622 }
64623 @@ -2494,6 +2500,16 @@ long do_mount(const char *dev_name, const char *dir_name,
64624 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64625 MS_STRICTATIME);
64626
64627 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64628 + retval = -EPERM;
64629 + goto dput_out;
64630 + }
64631 +
64632 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64633 + retval = -EPERM;
64634 + goto dput_out;
64635 + }
64636 +
64637 if (flags & MS_REMOUNT)
64638 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64639 data_page);
64640 @@ -2508,6 +2524,9 @@ long do_mount(const char *dev_name, const char *dir_name,
64641 dev_name, data_page);
64642 dput_out:
64643 path_put(&path);
64644 +
64645 + gr_log_mount(dev_name, dir_name, retval);
64646 +
64647 return retval;
64648 }
64649
64650 @@ -2525,7 +2544,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64651 * number incrementing at 10Ghz will take 12,427 years to wrap which
64652 * is effectively never, so we can ignore the possibility.
64653 */
64654 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64655 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64656
64657 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64658 {
64659 @@ -2540,7 +2559,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64660 kfree(new_ns);
64661 return ERR_PTR(ret);
64662 }
64663 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64664 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64665 atomic_set(&new_ns->count, 1);
64666 new_ns->root = NULL;
64667 INIT_LIST_HEAD(&new_ns->list);
64668 @@ -2550,7 +2569,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64669 return new_ns;
64670 }
64671
64672 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64673 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64674 struct user_namespace *user_ns, struct fs_struct *new_fs)
64675 {
64676 struct mnt_namespace *new_ns;
64677 @@ -2671,8 +2690,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64678 }
64679 EXPORT_SYMBOL(mount_subtree);
64680
64681 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64682 - char __user *, type, unsigned long, flags, void __user *, data)
64683 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64684 + const char __user *, type, unsigned long, flags, void __user *, data)
64685 {
64686 int ret;
64687 char *kernel_type;
64688 @@ -2785,6 +2804,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64689 if (error)
64690 goto out2;
64691
64692 + if (gr_handle_chroot_pivot()) {
64693 + error = -EPERM;
64694 + goto out2;
64695 + }
64696 +
64697 get_fs_root(current->fs, &root);
64698 old_mp = lock_mount(&old);
64699 error = PTR_ERR(old_mp);
64700 @@ -3056,7 +3080,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64701 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64702 return -EPERM;
64703
64704 - if (fs->users != 1)
64705 + if (atomic_read(&fs->users) != 1)
64706 return -EINVAL;
64707
64708 get_mnt_ns(mnt_ns);
64709 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64710 index f4ccfe6..a5cf064 100644
64711 --- a/fs/nfs/callback_xdr.c
64712 +++ b/fs/nfs/callback_xdr.c
64713 @@ -51,7 +51,7 @@ struct callback_op {
64714 callback_decode_arg_t decode_args;
64715 callback_encode_res_t encode_res;
64716 long res_maxsize;
64717 -};
64718 +} __do_const;
64719
64720 static struct callback_op callback_ops[];
64721
64722 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64723 index 0689aa5..299386e 100644
64724 --- a/fs/nfs/inode.c
64725 +++ b/fs/nfs/inode.c
64726 @@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64727 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64728 }
64729
64730 -static atomic_long_t nfs_attr_generation_counter;
64731 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64732
64733 static unsigned long nfs_read_attr_generation_counter(void)
64734 {
64735 - return atomic_long_read(&nfs_attr_generation_counter);
64736 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64737 }
64738
64739 unsigned long nfs_inc_attr_generation_counter(void)
64740 {
64741 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64742 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64743 }
64744
64745 void nfs_fattr_init(struct nfs_fattr *fattr)
64746 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64747 index 1d3cb47..2b8ed89 100644
64748 --- a/fs/nfsd/nfs4proc.c
64749 +++ b/fs/nfsd/nfs4proc.c
64750 @@ -1155,7 +1155,7 @@ struct nfsd4_operation {
64751 nfsd4op_rsize op_rsize_bop;
64752 stateid_getter op_get_currentstateid;
64753 stateid_setter op_set_currentstateid;
64754 -};
64755 +} __do_const;
64756
64757 static struct nfsd4_operation nfsd4_ops[];
64758
64759 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64760 index 353aac8..32035ee 100644
64761 --- a/fs/nfsd/nfs4xdr.c
64762 +++ b/fs/nfsd/nfs4xdr.c
64763 @@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64764
64765 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64766
64767 -static nfsd4_dec nfsd4_dec_ops[] = {
64768 +static const nfsd4_dec nfsd4_dec_ops[] = {
64769 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64770 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64771 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64772 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64773 index ff95676..96cf3f62 100644
64774 --- a/fs/nfsd/nfscache.c
64775 +++ b/fs/nfsd/nfscache.c
64776 @@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64777 {
64778 struct svc_cacherep *rp = rqstp->rq_cacherep;
64779 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64780 - int len;
64781 + long len;
64782 size_t bufsize = 0;
64783
64784 if (!rp)
64785 return;
64786
64787 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64788 - len >>= 2;
64789 + if (statp) {
64790 + len = (char*)statp - (char*)resv->iov_base;
64791 + len = resv->iov_len - len;
64792 + len >>= 2;
64793 + }
64794
64795 /* Don't cache excessive amounts of data and XDR failures */
64796 - if (!statp || len > (256 >> 2)) {
64797 + if (!statp || len > (256 >> 2) || len < 0) {
64798 nfsd_reply_cache_free(rp);
64799 return;
64800 }
64801 @@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64802 switch (cachetype) {
64803 case RC_REPLSTAT:
64804 if (len != 1)
64805 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64806 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64807 rp->c_replstat = *statp;
64808 break;
64809 case RC_REPLBUFF:
64810 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64811 index 6ab077b..5ac7f0b 100644
64812 --- a/fs/nfsd/vfs.c
64813 +++ b/fs/nfsd/vfs.c
64814 @@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64815
64816 oldfs = get_fs();
64817 set_fs(KERNEL_DS);
64818 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64819 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64820 set_fs(oldfs);
64821 return nfsd_finish_read(file, count, host_err);
64822 }
64823 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64824
64825 /* Write the data. */
64826 oldfs = get_fs(); set_fs(KERNEL_DS);
64827 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64828 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64829 set_fs(oldfs);
64830 if (host_err < 0)
64831 goto out_nfserr;
64832 @@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64833 */
64834
64835 oldfs = get_fs(); set_fs(KERNEL_DS);
64836 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64837 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64838 set_fs(oldfs);
64839
64840 if (host_err < 0)
64841 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64842 index 52ccd34..7a6b202 100644
64843 --- a/fs/nls/nls_base.c
64844 +++ b/fs/nls/nls_base.c
64845 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64846
64847 int __register_nls(struct nls_table *nls, struct module *owner)
64848 {
64849 - struct nls_table ** tmp = &tables;
64850 + struct nls_table *tmp = tables;
64851
64852 if (nls->next)
64853 return -EBUSY;
64854
64855 - nls->owner = owner;
64856 + pax_open_kernel();
64857 + *(void **)&nls->owner = owner;
64858 + pax_close_kernel();
64859 spin_lock(&nls_lock);
64860 - while (*tmp) {
64861 - if (nls == *tmp) {
64862 + while (tmp) {
64863 + if (nls == tmp) {
64864 spin_unlock(&nls_lock);
64865 return -EBUSY;
64866 }
64867 - tmp = &(*tmp)->next;
64868 + tmp = tmp->next;
64869 }
64870 - nls->next = tables;
64871 + pax_open_kernel();
64872 + *(struct nls_table **)&nls->next = tables;
64873 + pax_close_kernel();
64874 tables = nls;
64875 spin_unlock(&nls_lock);
64876 return 0;
64877 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64878
64879 int unregister_nls(struct nls_table * nls)
64880 {
64881 - struct nls_table ** tmp = &tables;
64882 + struct nls_table * const * tmp = &tables;
64883
64884 spin_lock(&nls_lock);
64885 while (*tmp) {
64886 if (nls == *tmp) {
64887 - *tmp = nls->next;
64888 + pax_open_kernel();
64889 + *(struct nls_table **)tmp = nls->next;
64890 + pax_close_kernel();
64891 spin_unlock(&nls_lock);
64892 return 0;
64893 }
64894 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
64895 return -EINVAL;
64896 }
64897
64898 -static struct nls_table *find_nls(char *charset)
64899 +static struct nls_table *find_nls(const char *charset)
64900 {
64901 struct nls_table *nls;
64902 spin_lock(&nls_lock);
64903 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
64904 return nls;
64905 }
64906
64907 -struct nls_table *load_nls(char *charset)
64908 +struct nls_table *load_nls(const char *charset)
64909 {
64910 return try_then_request_module(find_nls(charset), "nls_%s", charset);
64911 }
64912 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
64913 index 162b3f1..6076a7c 100644
64914 --- a/fs/nls/nls_euc-jp.c
64915 +++ b/fs/nls/nls_euc-jp.c
64916 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
64917 p_nls = load_nls("cp932");
64918
64919 if (p_nls) {
64920 - table.charset2upper = p_nls->charset2upper;
64921 - table.charset2lower = p_nls->charset2lower;
64922 + pax_open_kernel();
64923 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64924 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64925 + pax_close_kernel();
64926 return register_nls(&table);
64927 }
64928
64929 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
64930 index a80a741..7b96e1b 100644
64931 --- a/fs/nls/nls_koi8-ru.c
64932 +++ b/fs/nls/nls_koi8-ru.c
64933 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
64934 p_nls = load_nls("koi8-u");
64935
64936 if (p_nls) {
64937 - table.charset2upper = p_nls->charset2upper;
64938 - table.charset2lower = p_nls->charset2lower;
64939 + pax_open_kernel();
64940 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64941 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64942 + pax_close_kernel();
64943 return register_nls(&table);
64944 }
64945
64946 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
64947 index c991616..5ae51af 100644
64948 --- a/fs/notify/fanotify/fanotify_user.c
64949 +++ b/fs/notify/fanotify/fanotify_user.c
64950 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
64951
64952 fd = fanotify_event_metadata.fd;
64953 ret = -EFAULT;
64954 - if (copy_to_user(buf, &fanotify_event_metadata,
64955 - fanotify_event_metadata.event_len))
64956 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
64957 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
64958 goto out_close_fd;
64959
64960 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
64961 diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
64962 index 0f88bc0..7d888d7 100644
64963 --- a/fs/notify/inotify/inotify_fsnotify.c
64964 +++ b/fs/notify/inotify/inotify_fsnotify.c
64965 @@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
64966 /* ideally the idr is empty and we won't hit the BUG in the callback */
64967 idr_for_each(&group->inotify_data.idr, idr_callback, group);
64968 idr_destroy(&group->inotify_data.idr);
64969 - atomic_dec(&group->inotify_data.user->inotify_devs);
64970 - free_uid(group->inotify_data.user);
64971 + if (group->inotify_data.user) {
64972 + atomic_dec(&group->inotify_data.user->inotify_devs);
64973 + free_uid(group->inotify_data.user);
64974 + }
64975 }
64976
64977 static void inotify_free_event(struct fsnotify_event *fsn_event)
64978 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
64979 index a95d8e0..a91a5fd 100644
64980 --- a/fs/notify/notification.c
64981 +++ b/fs/notify/notification.c
64982 @@ -48,7 +48,7 @@
64983 #include <linux/fsnotify_backend.h>
64984 #include "fsnotify.h"
64985
64986 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64987 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64988
64989 /**
64990 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
64991 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64992 */
64993 u32 fsnotify_get_cookie(void)
64994 {
64995 - return atomic_inc_return(&fsnotify_sync_cookie);
64996 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
64997 }
64998 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
64999
65000 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65001 index 9e38daf..5727cae 100644
65002 --- a/fs/ntfs/dir.c
65003 +++ b/fs/ntfs/dir.c
65004 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65005 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65006 ~(s64)(ndir->itype.index.block_size - 1)));
65007 /* Bounds checks. */
65008 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65009 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65010 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65011 "inode 0x%lx or driver bug.", vdir->i_ino);
65012 goto err_out;
65013 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65014 index f5ec1ce..807fd78 100644
65015 --- a/fs/ntfs/file.c
65016 +++ b/fs/ntfs/file.c
65017 @@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65018 char *addr;
65019 size_t total = 0;
65020 unsigned len;
65021 - int left;
65022 + unsigned left;
65023
65024 do {
65025 len = PAGE_CACHE_SIZE - ofs;
65026 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65027 index 6c3296e..c0b99f0 100644
65028 --- a/fs/ntfs/super.c
65029 +++ b/fs/ntfs/super.c
65030 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65031 if (!silent)
65032 ntfs_error(sb, "Primary boot sector is invalid.");
65033 } else if (!silent)
65034 - ntfs_error(sb, read_err_str, "primary");
65035 + ntfs_error(sb, read_err_str, "%s", "primary");
65036 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65037 if (bh_primary)
65038 brelse(bh_primary);
65039 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65040 goto hotfix_primary_boot_sector;
65041 brelse(bh_backup);
65042 } else if (!silent)
65043 - ntfs_error(sb, read_err_str, "backup");
65044 + ntfs_error(sb, read_err_str, "%s", "backup");
65045 /* Try to read NT3.51- backup boot sector. */
65046 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65047 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65048 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65049 "sector.");
65050 brelse(bh_backup);
65051 } else if (!silent)
65052 - ntfs_error(sb, read_err_str, "backup");
65053 + ntfs_error(sb, read_err_str, "%s", "backup");
65054 /* We failed. Cleanup and return. */
65055 if (bh_primary)
65056 brelse(bh_primary);
65057 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65058 index 0440134..d52c93a 100644
65059 --- a/fs/ocfs2/localalloc.c
65060 +++ b/fs/ocfs2/localalloc.c
65061 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65062 goto bail;
65063 }
65064
65065 - atomic_inc(&osb->alloc_stats.moves);
65066 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65067
65068 bail:
65069 if (handle)
65070 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
65071 index 8add6f1..b931e04 100644
65072 --- a/fs/ocfs2/namei.c
65073 +++ b/fs/ocfs2/namei.c
65074 @@ -158,7 +158,7 @@ bail_add:
65075 * NOTE: This dentry already has ->d_op set from
65076 * ocfs2_get_parent() and ocfs2_get_dentry()
65077 */
65078 - if (ret)
65079 + if (!IS_ERR_OR_NULL(ret))
65080 dentry = ret;
65081
65082 status = ocfs2_dentry_attach_lock(dentry, inode,
65083 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65084 index bbec539..7b266d5 100644
65085 --- a/fs/ocfs2/ocfs2.h
65086 +++ b/fs/ocfs2/ocfs2.h
65087 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65088
65089 struct ocfs2_alloc_stats
65090 {
65091 - atomic_t moves;
65092 - atomic_t local_data;
65093 - atomic_t bitmap_data;
65094 - atomic_t bg_allocs;
65095 - atomic_t bg_extends;
65096 + atomic_unchecked_t moves;
65097 + atomic_unchecked_t local_data;
65098 + atomic_unchecked_t bitmap_data;
65099 + atomic_unchecked_t bg_allocs;
65100 + atomic_unchecked_t bg_extends;
65101 };
65102
65103 enum ocfs2_local_alloc_state
65104 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65105 index 0cb889a..6a26b24 100644
65106 --- a/fs/ocfs2/suballoc.c
65107 +++ b/fs/ocfs2/suballoc.c
65108 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65109 mlog_errno(status);
65110 goto bail;
65111 }
65112 - atomic_inc(&osb->alloc_stats.bg_extends);
65113 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65114
65115 /* You should never ask for this much metadata */
65116 BUG_ON(bits_wanted >
65117 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65118 mlog_errno(status);
65119 goto bail;
65120 }
65121 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65122 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65123
65124 *suballoc_loc = res.sr_bg_blkno;
65125 *suballoc_bit_start = res.sr_bit_offset;
65126 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65127 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65128 res->sr_bits);
65129
65130 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65131 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65132
65133 BUG_ON(res->sr_bits != 1);
65134
65135 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65136 mlog_errno(status);
65137 goto bail;
65138 }
65139 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65140 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65141
65142 BUG_ON(res.sr_bits != 1);
65143
65144 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65145 cluster_start,
65146 num_clusters);
65147 if (!status)
65148 - atomic_inc(&osb->alloc_stats.local_data);
65149 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65150 } else {
65151 if (min_clusters > (osb->bitmap_cpg - 1)) {
65152 /* The only paths asking for contiguousness
65153 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65154 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65155 res.sr_bg_blkno,
65156 res.sr_bit_offset);
65157 - atomic_inc(&osb->alloc_stats.bitmap_data);
65158 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65159 *num_clusters = res.sr_bits;
65160 }
65161 }
65162 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65163 index 4142546..69375a9 100644
65164 --- a/fs/ocfs2/super.c
65165 +++ b/fs/ocfs2/super.c
65166 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65167 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65168 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65169 "Stats",
65170 - atomic_read(&osb->alloc_stats.bitmap_data),
65171 - atomic_read(&osb->alloc_stats.local_data),
65172 - atomic_read(&osb->alloc_stats.bg_allocs),
65173 - atomic_read(&osb->alloc_stats.moves),
65174 - atomic_read(&osb->alloc_stats.bg_extends));
65175 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65176 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65177 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65178 + atomic_read_unchecked(&osb->alloc_stats.moves),
65179 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65180
65181 out += snprintf(buf + out, len - out,
65182 "%10s => State: %u Descriptor: %llu Size: %u bits "
65183 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65184
65185 mutex_init(&osb->system_file_mutex);
65186
65187 - atomic_set(&osb->alloc_stats.moves, 0);
65188 - atomic_set(&osb->alloc_stats.local_data, 0);
65189 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65190 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65191 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65192 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65193 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65194 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65195 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65196 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65197
65198 /* Copy the blockcheck stats from the superblock probe */
65199 osb->osb_ecc_stats = *stats;
65200 diff --git a/fs/open.c b/fs/open.c
65201 index d6fd3ac..6ccf474 100644
65202 --- a/fs/open.c
65203 +++ b/fs/open.c
65204 @@ -32,6 +32,8 @@
65205 #include <linux/dnotify.h>
65206 #include <linux/compat.h>
65207
65208 +#define CREATE_TRACE_POINTS
65209 +#include <trace/events/fs.h>
65210 #include "internal.h"
65211
65212 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65213 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65214 error = locks_verify_truncate(inode, NULL, length);
65215 if (!error)
65216 error = security_path_truncate(path);
65217 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65218 + error = -EACCES;
65219 if (!error)
65220 error = do_truncate(path->dentry, length, 0, NULL);
65221
65222 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65223 error = locks_verify_truncate(inode, f.file, length);
65224 if (!error)
65225 error = security_path_truncate(&f.file->f_path);
65226 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65227 + error = -EACCES;
65228 if (!error)
65229 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65230 sb_end_write(inode->i_sb);
65231 @@ -380,6 +386,9 @@ retry:
65232 if (__mnt_is_readonly(path.mnt))
65233 res = -EROFS;
65234
65235 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65236 + res = -EACCES;
65237 +
65238 out_path_release:
65239 path_put(&path);
65240 if (retry_estale(res, lookup_flags)) {
65241 @@ -411,6 +420,8 @@ retry:
65242 if (error)
65243 goto dput_and_out;
65244
65245 + gr_log_chdir(path.dentry, path.mnt);
65246 +
65247 set_fs_pwd(current->fs, &path);
65248
65249 dput_and_out:
65250 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65251 goto out_putf;
65252
65253 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65254 +
65255 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65256 + error = -EPERM;
65257 +
65258 + if (!error)
65259 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65260 +
65261 if (!error)
65262 set_fs_pwd(current->fs, &f.file->f_path);
65263 out_putf:
65264 @@ -469,7 +487,13 @@ retry:
65265 if (error)
65266 goto dput_and_out;
65267
65268 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65269 + goto dput_and_out;
65270 +
65271 set_fs_root(current->fs, &path);
65272 +
65273 + gr_handle_chroot_chdir(&path);
65274 +
65275 error = 0;
65276 dput_and_out:
65277 path_put(&path);
65278 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65279 return error;
65280 retry_deleg:
65281 mutex_lock(&inode->i_mutex);
65282 +
65283 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65284 + error = -EACCES;
65285 + goto out_unlock;
65286 + }
65287 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65288 + error = -EACCES;
65289 + goto out_unlock;
65290 + }
65291 +
65292 error = security_path_chmod(path, mode);
65293 if (error)
65294 goto out_unlock;
65295 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65296 uid = make_kuid(current_user_ns(), user);
65297 gid = make_kgid(current_user_ns(), group);
65298
65299 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65300 + return -EACCES;
65301 +
65302 newattrs.ia_valid = ATTR_CTIME;
65303 if (user != (uid_t) -1) {
65304 if (!uid_valid(uid))
65305 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65306 } else {
65307 fsnotify_open(f);
65308 fd_install(fd, f);
65309 + trace_do_sys_open(tmp->name, flags, mode);
65310 }
65311 }
65312 putname(tmp);
65313 diff --git a/fs/pipe.c b/fs/pipe.c
65314 index 21981e5..3d5f55c 100644
65315 --- a/fs/pipe.c
65316 +++ b/fs/pipe.c
65317 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65318
65319 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65320 {
65321 - if (pipe->files)
65322 + if (atomic_read(&pipe->files))
65323 mutex_lock_nested(&pipe->mutex, subclass);
65324 }
65325
65326 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65327
65328 void pipe_unlock(struct pipe_inode_info *pipe)
65329 {
65330 - if (pipe->files)
65331 + if (atomic_read(&pipe->files))
65332 mutex_unlock(&pipe->mutex);
65333 }
65334 EXPORT_SYMBOL(pipe_unlock);
65335 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65336 }
65337 if (bufs) /* More to do? */
65338 continue;
65339 - if (!pipe->writers)
65340 + if (!atomic_read(&pipe->writers))
65341 break;
65342 - if (!pipe->waiting_writers) {
65343 + if (!atomic_read(&pipe->waiting_writers)) {
65344 /* syscall merging: Usually we must not sleep
65345 * if O_NONBLOCK is set, or if we got some data.
65346 * But if a writer sleeps in kernel space, then
65347 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65348
65349 __pipe_lock(pipe);
65350
65351 - if (!pipe->readers) {
65352 + if (!atomic_read(&pipe->readers)) {
65353 send_sig(SIGPIPE, current, 0);
65354 ret = -EPIPE;
65355 goto out;
65356 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65357 for (;;) {
65358 int bufs;
65359
65360 - if (!pipe->readers) {
65361 + if (!atomic_read(&pipe->readers)) {
65362 send_sig(SIGPIPE, current, 0);
65363 if (!ret)
65364 ret = -EPIPE;
65365 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65366 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65367 do_wakeup = 0;
65368 }
65369 - pipe->waiting_writers++;
65370 + atomic_inc(&pipe->waiting_writers);
65371 pipe_wait(pipe);
65372 - pipe->waiting_writers--;
65373 + atomic_dec(&pipe->waiting_writers);
65374 }
65375 out:
65376 __pipe_unlock(pipe);
65377 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65378 mask = 0;
65379 if (filp->f_mode & FMODE_READ) {
65380 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65381 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65382 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65383 mask |= POLLHUP;
65384 }
65385
65386 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65387 * Most Unices do not set POLLERR for FIFOs but on Linux they
65388 * behave exactly like pipes for poll().
65389 */
65390 - if (!pipe->readers)
65391 + if (!atomic_read(&pipe->readers))
65392 mask |= POLLERR;
65393 }
65394
65395 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65396 int kill = 0;
65397
65398 spin_lock(&inode->i_lock);
65399 - if (!--pipe->files) {
65400 + if (atomic_dec_and_test(&pipe->files)) {
65401 inode->i_pipe = NULL;
65402 kill = 1;
65403 }
65404 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65405
65406 __pipe_lock(pipe);
65407 if (file->f_mode & FMODE_READ)
65408 - pipe->readers--;
65409 + atomic_dec(&pipe->readers);
65410 if (file->f_mode & FMODE_WRITE)
65411 - pipe->writers--;
65412 + atomic_dec(&pipe->writers);
65413
65414 - if (pipe->readers || pipe->writers) {
65415 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65416 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65417 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65418 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65419 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65420 kfree(pipe);
65421 }
65422
65423 -static struct vfsmount *pipe_mnt __read_mostly;
65424 +struct vfsmount *pipe_mnt __read_mostly;
65425
65426 /*
65427 * pipefs_dname() is called from d_path().
65428 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65429 goto fail_iput;
65430
65431 inode->i_pipe = pipe;
65432 - pipe->files = 2;
65433 - pipe->readers = pipe->writers = 1;
65434 + atomic_set(&pipe->files, 2);
65435 + atomic_set(&pipe->readers, 1);
65436 + atomic_set(&pipe->writers, 1);
65437 inode->i_fop = &pipefifo_fops;
65438
65439 /*
65440 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65441 spin_lock(&inode->i_lock);
65442 if (inode->i_pipe) {
65443 pipe = inode->i_pipe;
65444 - pipe->files++;
65445 + atomic_inc(&pipe->files);
65446 spin_unlock(&inode->i_lock);
65447 } else {
65448 spin_unlock(&inode->i_lock);
65449 pipe = alloc_pipe_info();
65450 if (!pipe)
65451 return -ENOMEM;
65452 - pipe->files = 1;
65453 + atomic_set(&pipe->files, 1);
65454 spin_lock(&inode->i_lock);
65455 if (unlikely(inode->i_pipe)) {
65456 - inode->i_pipe->files++;
65457 + atomic_inc(&inode->i_pipe->files);
65458 spin_unlock(&inode->i_lock);
65459 free_pipe_info(pipe);
65460 pipe = inode->i_pipe;
65461 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65462 * opened, even when there is no process writing the FIFO.
65463 */
65464 pipe->r_counter++;
65465 - if (pipe->readers++ == 0)
65466 + if (atomic_inc_return(&pipe->readers) == 1)
65467 wake_up_partner(pipe);
65468
65469 - if (!is_pipe && !pipe->writers) {
65470 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65471 if ((filp->f_flags & O_NONBLOCK)) {
65472 /* suppress POLLHUP until we have
65473 * seen a writer */
65474 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65475 * errno=ENXIO when there is no process reading the FIFO.
65476 */
65477 ret = -ENXIO;
65478 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65479 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65480 goto err;
65481
65482 pipe->w_counter++;
65483 - if (!pipe->writers++)
65484 + if (atomic_inc_return(&pipe->writers) == 1)
65485 wake_up_partner(pipe);
65486
65487 - if (!is_pipe && !pipe->readers) {
65488 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65489 if (wait_for_partner(pipe, &pipe->r_counter))
65490 goto err_wr;
65491 }
65492 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65493 * the process can at least talk to itself.
65494 */
65495
65496 - pipe->readers++;
65497 - pipe->writers++;
65498 + atomic_inc(&pipe->readers);
65499 + atomic_inc(&pipe->writers);
65500 pipe->r_counter++;
65501 pipe->w_counter++;
65502 - if (pipe->readers == 1 || pipe->writers == 1)
65503 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65504 wake_up_partner(pipe);
65505 break;
65506
65507 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65508 return 0;
65509
65510 err_rd:
65511 - if (!--pipe->readers)
65512 + if (atomic_dec_and_test(&pipe->readers))
65513 wake_up_interruptible(&pipe->wait);
65514 ret = -ERESTARTSYS;
65515 goto err;
65516
65517 err_wr:
65518 - if (!--pipe->writers)
65519 + if (atomic_dec_and_test(&pipe->writers))
65520 wake_up_interruptible(&pipe->wait);
65521 ret = -ERESTARTSYS;
65522 goto err;
65523 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65524 index 0855f77..6787d50 100644
65525 --- a/fs/posix_acl.c
65526 +++ b/fs/posix_acl.c
65527 @@ -20,6 +20,7 @@
65528 #include <linux/xattr.h>
65529 #include <linux/export.h>
65530 #include <linux/user_namespace.h>
65531 +#include <linux/grsecurity.h>
65532
65533 struct posix_acl **acl_by_type(struct inode *inode, int type)
65534 {
65535 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65536 }
65537 }
65538 if (mode_p)
65539 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65540 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65541 return not_equiv;
65542 }
65543 EXPORT_SYMBOL(posix_acl_equiv_mode);
65544 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65545 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65546 }
65547
65548 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65549 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65550 return not_equiv;
65551 }
65552
65553 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65554 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65555 int err = -ENOMEM;
65556 if (clone) {
65557 + *mode_p &= ~gr_acl_umask();
65558 +
65559 err = posix_acl_create_masq(clone, mode_p);
65560 if (err < 0) {
65561 posix_acl_release(clone);
65562 @@ -659,11 +662,12 @@ struct posix_acl *
65563 posix_acl_from_xattr(struct user_namespace *user_ns,
65564 const void *value, size_t size)
65565 {
65566 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65567 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65568 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65569 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65570 int count;
65571 struct posix_acl *acl;
65572 struct posix_acl_entry *acl_e;
65573 + umode_t umask = gr_acl_umask();
65574
65575 if (!value)
65576 return NULL;
65577 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65578
65579 switch(acl_e->e_tag) {
65580 case ACL_USER_OBJ:
65581 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65582 + break;
65583 case ACL_GROUP_OBJ:
65584 case ACL_MASK:
65585 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65586 + break;
65587 case ACL_OTHER:
65588 + acl_e->e_perm &= ~(umask & S_IRWXO);
65589 break;
65590
65591 case ACL_USER:
65592 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65593 acl_e->e_uid =
65594 make_kuid(user_ns,
65595 le32_to_cpu(entry->e_id));
65596 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65597 goto fail;
65598 break;
65599 case ACL_GROUP:
65600 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65601 acl_e->e_gid =
65602 make_kgid(user_ns,
65603 le32_to_cpu(entry->e_id));
65604 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65605 index 2183fcf..3c32a98 100644
65606 --- a/fs/proc/Kconfig
65607 +++ b/fs/proc/Kconfig
65608 @@ -30,7 +30,7 @@ config PROC_FS
65609
65610 config PROC_KCORE
65611 bool "/proc/kcore support" if !ARM
65612 - depends on PROC_FS && MMU
65613 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65614 help
65615 Provides a virtual ELF core file of the live kernel. This can
65616 be read with gdb and other ELF tools. No modifications can be
65617 @@ -38,8 +38,8 @@ config PROC_KCORE
65618
65619 config PROC_VMCORE
65620 bool "/proc/vmcore support"
65621 - depends on PROC_FS && CRASH_DUMP
65622 - default y
65623 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65624 + default n
65625 help
65626 Exports the dump image of crashed kernel in ELF format.
65627
65628 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65629 limited in memory.
65630
65631 config PROC_PAGE_MONITOR
65632 - default y
65633 - depends on PROC_FS && MMU
65634 + default n
65635 + depends on PROC_FS && MMU && !GRKERNSEC
65636 bool "Enable /proc page monitoring" if EXPERT
65637 help
65638 Various /proc files exist to monitor process memory utilization:
65639 diff --git a/fs/proc/array.c b/fs/proc/array.c
65640 index cd3653e..9b9b79a 100644
65641 --- a/fs/proc/array.c
65642 +++ b/fs/proc/array.c
65643 @@ -60,6 +60,7 @@
65644 #include <linux/tty.h>
65645 #include <linux/string.h>
65646 #include <linux/mman.h>
65647 +#include <linux/grsecurity.h>
65648 #include <linux/proc_fs.h>
65649 #include <linux/ioport.h>
65650 #include <linux/uaccess.h>
65651 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65652 seq_putc(m, '\n');
65653 }
65654
65655 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65656 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65657 +{
65658 + if (p->mm)
65659 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65660 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65661 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65662 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65663 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65664 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65665 + else
65666 + seq_printf(m, "PaX:\t-----\n");
65667 +}
65668 +#endif
65669 +
65670 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65671 struct pid *pid, struct task_struct *task)
65672 {
65673 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65674 task_cpus_allowed(m, task);
65675 cpuset_task_status_allowed(m, task);
65676 task_context_switch_counts(m, task);
65677 +
65678 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65679 + task_pax(m, task);
65680 +#endif
65681 +
65682 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65683 + task_grsec_rbac(m, task);
65684 +#endif
65685 +
65686 return 0;
65687 }
65688
65689 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65690 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65691 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65692 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65693 +#endif
65694 +
65695 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65696 struct pid *pid, struct task_struct *task, int whole)
65697 {
65698 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65699 char tcomm[sizeof(task->comm)];
65700 unsigned long flags;
65701
65702 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65703 + if (current->exec_id != m->exec_id) {
65704 + gr_log_badprocpid("stat");
65705 + return 0;
65706 + }
65707 +#endif
65708 +
65709 state = *get_task_state(task);
65710 vsize = eip = esp = 0;
65711 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65712 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65713 gtime = task_gtime(task);
65714 }
65715
65716 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65717 + if (PAX_RAND_FLAGS(mm)) {
65718 + eip = 0;
65719 + esp = 0;
65720 + wchan = 0;
65721 + }
65722 +#endif
65723 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65724 + wchan = 0;
65725 + eip =0;
65726 + esp =0;
65727 +#endif
65728 +
65729 /* scale priority and nice values from timeslices to -20..20 */
65730 /* to make it look like a "normal" Unix priority/nice value */
65731 priority = task_prio(task);
65732 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65733 seq_put_decimal_ull(m, ' ', vsize);
65734 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65735 seq_put_decimal_ull(m, ' ', rsslim);
65736 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65737 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65738 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65739 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65740 +#else
65741 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65742 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65743 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65744 +#endif
65745 seq_put_decimal_ull(m, ' ', esp);
65746 seq_put_decimal_ull(m, ' ', eip);
65747 /* The signal information here is obsolete.
65748 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65749 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65750 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65751
65752 - if (mm && permitted) {
65753 + if (mm && permitted
65754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65755 + && !PAX_RAND_FLAGS(mm)
65756 +#endif
65757 + ) {
65758 seq_put_decimal_ull(m, ' ', mm->start_data);
65759 seq_put_decimal_ull(m, ' ', mm->end_data);
65760 seq_put_decimal_ull(m, ' ', mm->start_brk);
65761 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65762 struct pid *pid, struct task_struct *task)
65763 {
65764 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65765 - struct mm_struct *mm = get_task_mm(task);
65766 + struct mm_struct *mm;
65767
65768 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65769 + if (current->exec_id != m->exec_id) {
65770 + gr_log_badprocpid("statm");
65771 + return 0;
65772 + }
65773 +#endif
65774 + mm = get_task_mm(task);
65775 if (mm) {
65776 size = task_statm(mm, &shared, &text, &data, &resident);
65777 mmput(mm);
65778 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65779 return 0;
65780 }
65781
65782 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65783 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65784 +{
65785 + unsigned long flags;
65786 + u32 curr_ip = 0;
65787 +
65788 + if (lock_task_sighand(task, &flags)) {
65789 + curr_ip = task->signal->curr_ip;
65790 + unlock_task_sighand(task, &flags);
65791 + }
65792 + return seq_printf(m, "%pI4\n", &curr_ip);
65793 +}
65794 +#endif
65795 +
65796 #ifdef CONFIG_CHECKPOINT_RESTORE
65797 static struct pid *
65798 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65799 diff --git a/fs/proc/base.c b/fs/proc/base.c
65800 index baf852b..03fe930 100644
65801 --- a/fs/proc/base.c
65802 +++ b/fs/proc/base.c
65803 @@ -113,6 +113,14 @@ struct pid_entry {
65804 union proc_op op;
65805 };
65806
65807 +struct getdents_callback {
65808 + struct linux_dirent __user * current_dir;
65809 + struct linux_dirent __user * previous;
65810 + struct file * file;
65811 + int count;
65812 + int error;
65813 +};
65814 +
65815 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65816 .name = (NAME), \
65817 .len = sizeof(NAME) - 1, \
65818 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65819 return 0;
65820 }
65821
65822 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65823 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65824 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65825 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65826 +#endif
65827 +
65828 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65829 struct pid *pid, struct task_struct *task)
65830 {
65831 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65832 if (mm && !IS_ERR(mm)) {
65833 unsigned int nwords = 0;
65834 +
65835 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65836 + /* allow if we're currently ptracing this task */
65837 + if (PAX_RAND_FLAGS(mm) &&
65838 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65839 + mmput(mm);
65840 + return 0;
65841 + }
65842 +#endif
65843 +
65844 do {
65845 nwords += 2;
65846 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65847 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65848 }
65849
65850
65851 -#ifdef CONFIG_KALLSYMS
65852 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65853 /*
65854 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65855 * Returns the resolved symbol. If that fails, simply return the address.
65856 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65857 mutex_unlock(&task->signal->cred_guard_mutex);
65858 }
65859
65860 -#ifdef CONFIG_STACKTRACE
65861 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65862
65863 #define MAX_STACK_TRACE_DEPTH 64
65864
65865 @@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65866 return 0;
65867 }
65868
65869 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65870 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65871 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65872 struct pid *pid, struct task_struct *task)
65873 {
65874 @@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65875 /************************************************************************/
65876
65877 /* permission checks */
65878 -static int proc_fd_access_allowed(struct inode *inode)
65879 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65880 {
65881 struct task_struct *task;
65882 int allowed = 0;
65883 @@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65884 */
65885 task = get_proc_task(inode);
65886 if (task) {
65887 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65888 + if (log)
65889 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65890 + else
65891 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65892 put_task_struct(task);
65893 }
65894 return allowed;
65895 @@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65896 struct task_struct *task,
65897 int hide_pid_min)
65898 {
65899 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65900 + return false;
65901 +
65902 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65903 + rcu_read_lock();
65904 + {
65905 + const struct cred *tmpcred = current_cred();
65906 + const struct cred *cred = __task_cred(task);
65907 +
65908 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
65909 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65910 + || in_group_p(grsec_proc_gid)
65911 +#endif
65912 + ) {
65913 + rcu_read_unlock();
65914 + return true;
65915 + }
65916 + }
65917 + rcu_read_unlock();
65918 +
65919 + if (!pid->hide_pid)
65920 + return false;
65921 +#endif
65922 +
65923 if (pid->hide_pid < hide_pid_min)
65924 return true;
65925 if (in_group_p(pid->pid_gid))
65926 return true;
65927 +
65928 return ptrace_may_access(task, PTRACE_MODE_READ);
65929 }
65930
65931 @@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
65932 put_task_struct(task);
65933
65934 if (!has_perms) {
65935 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65936 + {
65937 +#else
65938 if (pid->hide_pid == 2) {
65939 +#endif
65940 /*
65941 * Let's make getdents(), stat(), and open()
65942 * consistent with each other. If a process
65943 @@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65944 if (!task)
65945 return -ESRCH;
65946
65947 + if (gr_acl_handle_procpidmem(task)) {
65948 + put_task_struct(task);
65949 + return -EPERM;
65950 + }
65951 +
65952 mm = mm_access(task, mode);
65953 put_task_struct(task);
65954
65955 @@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65956
65957 file->private_data = mm;
65958
65959 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65960 + file->f_version = current->exec_id;
65961 +#endif
65962 +
65963 return 0;
65964 }
65965
65966 @@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65967 ssize_t copied;
65968 char *page;
65969
65970 +#ifdef CONFIG_GRKERNSEC
65971 + if (write)
65972 + return -EPERM;
65973 +#endif
65974 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65975 + if (file->f_version != current->exec_id) {
65976 + gr_log_badprocpid("mem");
65977 + return 0;
65978 + }
65979 +#endif
65980 +
65981 if (!mm)
65982 return 0;
65983
65984 @@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65985 goto free;
65986
65987 while (count > 0) {
65988 - int this_len = min_t(int, count, PAGE_SIZE);
65989 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
65990
65991 if (write && copy_from_user(page, buf, this_len)) {
65992 copied = -EFAULT;
65993 @@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65994 if (!mm)
65995 return 0;
65996
65997 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65998 + if (file->f_version != current->exec_id) {
65999 + gr_log_badprocpid("environ");
66000 + return 0;
66001 + }
66002 +#endif
66003 +
66004 page = (char *)__get_free_page(GFP_TEMPORARY);
66005 if (!page)
66006 return -ENOMEM;
66007 @@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66008 goto free;
66009 while (count > 0) {
66010 size_t this_len, max_len;
66011 - int retval;
66012 + ssize_t retval;
66013
66014 if (src >= (mm->env_end - mm->env_start))
66015 break;
66016 @@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66017 int error = -EACCES;
66018
66019 /* Are we allowed to snoop on the tasks file descriptors? */
66020 - if (!proc_fd_access_allowed(inode))
66021 + if (!proc_fd_access_allowed(inode, 0))
66022 goto out;
66023
66024 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66025 @@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66026 struct path path;
66027
66028 /* Are we allowed to snoop on the tasks file descriptors? */
66029 - if (!proc_fd_access_allowed(inode))
66030 - goto out;
66031 + /* logging this is needed for learning on chromium to work properly,
66032 + but we don't want to flood the logs from 'ps' which does a readlink
66033 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66034 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66035 + */
66036 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66037 + if (!proc_fd_access_allowed(inode,0))
66038 + goto out;
66039 + } else {
66040 + if (!proc_fd_access_allowed(inode,1))
66041 + goto out;
66042 + }
66043
66044 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66045 if (error)
66046 @@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66047 rcu_read_lock();
66048 cred = __task_cred(task);
66049 inode->i_uid = cred->euid;
66050 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66051 + inode->i_gid = grsec_proc_gid;
66052 +#else
66053 inode->i_gid = cred->egid;
66054 +#endif
66055 rcu_read_unlock();
66056 }
66057 security_task_to_inode(task, inode);
66058 @@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66059 return -ENOENT;
66060 }
66061 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66062 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66063 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66064 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66065 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66066 +#endif
66067 task_dumpable(task)) {
66068 cred = __task_cred(task);
66069 stat->uid = cred->euid;
66070 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66071 + stat->gid = grsec_proc_gid;
66072 +#else
66073 stat->gid = cred->egid;
66074 +#endif
66075 }
66076 }
66077 rcu_read_unlock();
66078 @@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66079
66080 if (task) {
66081 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66082 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66083 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66084 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66085 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66086 +#endif
66087 task_dumpable(task)) {
66088 rcu_read_lock();
66089 cred = __task_cred(task);
66090 inode->i_uid = cred->euid;
66091 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66092 + inode->i_gid = grsec_proc_gid;
66093 +#else
66094 inode->i_gid = cred->egid;
66095 +#endif
66096 rcu_read_unlock();
66097 } else {
66098 inode->i_uid = GLOBAL_ROOT_UID;
66099 @@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66100 if (!task)
66101 goto out_no_task;
66102
66103 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66104 + goto out;
66105 +
66106 /*
66107 * Yes, it does not scale. And it should not. Don't add
66108 * new entries into /proc/<tgid>/ without very good reasons.
66109 @@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66110 if (!task)
66111 return -ENOENT;
66112
66113 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66114 + goto out;
66115 +
66116 if (!dir_emit_dots(file, ctx))
66117 goto out;
66118
66119 @@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66120 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66121 #endif
66122 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66123 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66124 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66125 ONE("syscall", S_IRUSR, proc_pid_syscall),
66126 #endif
66127 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66128 @@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66129 #ifdef CONFIG_SECURITY
66130 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66131 #endif
66132 -#ifdef CONFIG_KALLSYMS
66133 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66134 ONE("wchan", S_IRUGO, proc_pid_wchan),
66135 #endif
66136 -#ifdef CONFIG_STACKTRACE
66137 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66138 ONE("stack", S_IRUSR, proc_pid_stack),
66139 #endif
66140 #ifdef CONFIG_SCHEDSTATS
66141 @@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66142 #ifdef CONFIG_HARDWALL
66143 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66144 #endif
66145 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66146 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66147 +#endif
66148 #ifdef CONFIG_USER_NS
66149 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66150 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66151 @@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
66152 if (!inode)
66153 goto out;
66154
66155 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66156 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66157 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66158 + inode->i_gid = grsec_proc_gid;
66159 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66160 +#else
66161 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66162 +#endif
66163 inode->i_op = &proc_tgid_base_inode_operations;
66164 inode->i_fop = &proc_tgid_base_operations;
66165 inode->i_flags|=S_IMMUTABLE;
66166 @@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66167 if (!task)
66168 goto out;
66169
66170 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66171 + goto out_put_task;
66172 +
66173 result = proc_pid_instantiate(dir, dentry, task, NULL);
66174 +out_put_task:
66175 put_task_struct(task);
66176 out:
66177 return ERR_PTR(result);
66178 @@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
66179 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66180 #endif
66181 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66182 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66183 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66184 ONE("syscall", S_IRUSR, proc_pid_syscall),
66185 #endif
66186 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66187 @@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
66188 #ifdef CONFIG_SECURITY
66189 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66190 #endif
66191 -#ifdef CONFIG_KALLSYMS
66192 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66193 ONE("wchan", S_IRUGO, proc_pid_wchan),
66194 #endif
66195 -#ifdef CONFIG_STACKTRACE
66196 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66197 ONE("stack", S_IRUSR, proc_pid_stack),
66198 #endif
66199 #ifdef CONFIG_SCHEDSTATS
66200 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66201 index cbd82df..c0407d2 100644
66202 --- a/fs/proc/cmdline.c
66203 +++ b/fs/proc/cmdline.c
66204 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66205
66206 static int __init proc_cmdline_init(void)
66207 {
66208 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66209 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66210 +#else
66211 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66212 +#endif
66213 return 0;
66214 }
66215 fs_initcall(proc_cmdline_init);
66216 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66217 index 50493ed..248166b 100644
66218 --- a/fs/proc/devices.c
66219 +++ b/fs/proc/devices.c
66220 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66221
66222 static int __init proc_devices_init(void)
66223 {
66224 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66225 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66226 +#else
66227 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66228 +#endif
66229 return 0;
66230 }
66231 fs_initcall(proc_devices_init);
66232 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66233 index 955bb55..71948bd 100644
66234 --- a/fs/proc/fd.c
66235 +++ b/fs/proc/fd.c
66236 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66237 if (!task)
66238 return -ENOENT;
66239
66240 - files = get_files_struct(task);
66241 + if (!gr_acl_handle_procpidmem(task))
66242 + files = get_files_struct(task);
66243 put_task_struct(task);
66244
66245 if (files) {
66246 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66247 */
66248 int proc_fd_permission(struct inode *inode, int mask)
66249 {
66250 + struct task_struct *task;
66251 int rv = generic_permission(inode, mask);
66252 - if (rv == 0)
66253 - return 0;
66254 +
66255 if (task_tgid(current) == proc_pid(inode))
66256 rv = 0;
66257 +
66258 + task = get_proc_task(inode);
66259 + if (task == NULL)
66260 + return rv;
66261 +
66262 + if (gr_acl_handle_procpidmem(task))
66263 + rv = -EACCES;
66264 +
66265 + put_task_struct(task);
66266 +
66267 return rv;
66268 }
66269
66270 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66271 index 317b726..e329aed 100644
66272 --- a/fs/proc/generic.c
66273 +++ b/fs/proc/generic.c
66274 @@ -23,6 +23,7 @@
66275 #include <linux/bitops.h>
66276 #include <linux/spinlock.h>
66277 #include <linux/completion.h>
66278 +#include <linux/grsecurity.h>
66279 #include <asm/uaccess.h>
66280
66281 #include "internal.h"
66282 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66283 return proc_lookup_de(PDE(dir), dir, dentry);
66284 }
66285
66286 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66287 + unsigned int flags)
66288 +{
66289 + if (gr_proc_is_restricted())
66290 + return ERR_PTR(-EACCES);
66291 +
66292 + return proc_lookup_de(PDE(dir), dir, dentry);
66293 +}
66294 +
66295 /*
66296 * This returns non-zero if at EOF, so that the /proc
66297 * root directory can use this and check if it should
66298 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66299 return proc_readdir_de(PDE(inode), file, ctx);
66300 }
66301
66302 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66303 +{
66304 + struct inode *inode = file_inode(file);
66305 +
66306 + if (gr_proc_is_restricted())
66307 + return -EACCES;
66308 +
66309 + return proc_readdir_de(PDE(inode), file, ctx);
66310 +}
66311 +
66312 /*
66313 * These are the generic /proc directory operations. They
66314 * use the in-memory "struct proc_dir_entry" tree to parse
66315 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66316 .iterate = proc_readdir,
66317 };
66318
66319 +static const struct file_operations proc_dir_restricted_operations = {
66320 + .llseek = generic_file_llseek,
66321 + .read = generic_read_dir,
66322 + .iterate = proc_readdir_restrict,
66323 +};
66324 +
66325 /*
66326 * proc directories can do almost nothing..
66327 */
66328 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66329 .setattr = proc_notify_change,
66330 };
66331
66332 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66333 + .lookup = proc_lookup_restrict,
66334 + .getattr = proc_getattr,
66335 + .setattr = proc_notify_change,
66336 +};
66337 +
66338 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66339 {
66340 struct proc_dir_entry *tmp;
66341 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66342 return ret;
66343
66344 if (S_ISDIR(dp->mode)) {
66345 - dp->proc_fops = &proc_dir_operations;
66346 - dp->proc_iops = &proc_dir_inode_operations;
66347 + if (dp->restricted) {
66348 + dp->proc_fops = &proc_dir_restricted_operations;
66349 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66350 + } else {
66351 + dp->proc_fops = &proc_dir_operations;
66352 + dp->proc_iops = &proc_dir_inode_operations;
66353 + }
66354 dir->nlink++;
66355 } else if (S_ISLNK(dp->mode)) {
66356 dp->proc_iops = &proc_link_inode_operations;
66357 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66358 }
66359 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66360
66361 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66362 + struct proc_dir_entry *parent, void *data)
66363 +{
66364 + struct proc_dir_entry *ent;
66365 +
66366 + if (mode == 0)
66367 + mode = S_IRUGO | S_IXUGO;
66368 +
66369 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66370 + if (ent) {
66371 + ent->data = data;
66372 + ent->restricted = 1;
66373 + if (proc_register(parent, ent) < 0) {
66374 + kfree(ent);
66375 + ent = NULL;
66376 + }
66377 + }
66378 + return ent;
66379 +}
66380 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66381 +
66382 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66383 struct proc_dir_entry *parent)
66384 {
66385 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66386 }
66387 EXPORT_SYMBOL(proc_mkdir);
66388
66389 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66390 + struct proc_dir_entry *parent)
66391 +{
66392 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66393 +}
66394 +EXPORT_SYMBOL(proc_mkdir_restrict);
66395 +
66396 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66397 struct proc_dir_entry *parent,
66398 const struct file_operations *proc_fops,
66399 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66400 index 333080d..0a35ec4 100644
66401 --- a/fs/proc/inode.c
66402 +++ b/fs/proc/inode.c
66403 @@ -23,11 +23,17 @@
66404 #include <linux/slab.h>
66405 #include <linux/mount.h>
66406 #include <linux/magic.h>
66407 +#include <linux/grsecurity.h>
66408
66409 #include <asm/uaccess.h>
66410
66411 #include "internal.h"
66412
66413 +#ifdef CONFIG_PROC_SYSCTL
66414 +extern const struct inode_operations proc_sys_inode_operations;
66415 +extern const struct inode_operations proc_sys_dir_operations;
66416 +#endif
66417 +
66418 static void proc_evict_inode(struct inode *inode)
66419 {
66420 struct proc_dir_entry *de;
66421 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66422 ns = PROC_I(inode)->ns.ns;
66423 if (ns_ops && ns)
66424 ns_ops->put(ns);
66425 +
66426 +#ifdef CONFIG_PROC_SYSCTL
66427 + if (inode->i_op == &proc_sys_inode_operations ||
66428 + inode->i_op == &proc_sys_dir_operations)
66429 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66430 +#endif
66431 +
66432 }
66433
66434 static struct kmem_cache * proc_inode_cachep;
66435 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66436 if (de->mode) {
66437 inode->i_mode = de->mode;
66438 inode->i_uid = de->uid;
66439 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66440 + inode->i_gid = grsec_proc_gid;
66441 +#else
66442 inode->i_gid = de->gid;
66443 +#endif
66444 }
66445 if (de->size)
66446 inode->i_size = de->size;
66447 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66448 index 7da13e4..68d0981 100644
66449 --- a/fs/proc/internal.h
66450 +++ b/fs/proc/internal.h
66451 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66452 struct completion *pde_unload_completion;
66453 struct list_head pde_openers; /* who did ->open, but not ->release */
66454 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66455 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66456 u8 namelen;
66457 char name[];
66458 -};
66459 +} __randomize_layout;
66460
66461 union proc_op {
66462 int (*proc_get_link)(struct dentry *, struct path *);
66463 @@ -66,7 +67,7 @@ struct proc_inode {
66464 struct ctl_table *sysctl_entry;
66465 struct proc_ns ns;
66466 struct inode vfs_inode;
66467 -};
66468 +} __randomize_layout;
66469
66470 /*
66471 * General functions
66472 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66473 struct pid *, struct task_struct *);
66474 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66475 struct pid *, struct task_struct *);
66476 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66477 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66478 + struct pid *, struct task_struct *);
66479 +#endif
66480
66481 /*
66482 * base.c
66483 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66484 * generic.c
66485 */
66486 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66487 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66488 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66489 struct dentry *);
66490 extern int proc_readdir(struct file *, struct dir_context *);
66491 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66492 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66493
66494 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66495 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66496 index a352d57..cb94a5c 100644
66497 --- a/fs/proc/interrupts.c
66498 +++ b/fs/proc/interrupts.c
66499 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66500
66501 static int __init proc_interrupts_init(void)
66502 {
66503 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66504 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66505 +#else
66506 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66507 +#endif
66508 return 0;
66509 }
66510 fs_initcall(proc_interrupts_init);
66511 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66512 index 6df8d07..3321060 100644
66513 --- a/fs/proc/kcore.c
66514 +++ b/fs/proc/kcore.c
66515 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66516 * the addresses in the elf_phdr on our list.
66517 */
66518 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66519 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66520 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66521 + if (tsz > buflen)
66522 tsz = buflen;
66523 -
66524 +
66525 while (buflen) {
66526 struct kcore_list *m;
66527
66528 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66529 kfree(elf_buf);
66530 } else {
66531 if (kern_addr_valid(start)) {
66532 - unsigned long n;
66533 + char *elf_buf;
66534 + mm_segment_t oldfs;
66535
66536 - n = copy_to_user(buffer, (char *)start, tsz);
66537 - /*
66538 - * We cannot distinguish between fault on source
66539 - * and fault on destination. When this happens
66540 - * we clear too and hope it will trigger the
66541 - * EFAULT again.
66542 - */
66543 - if (n) {
66544 - if (clear_user(buffer + tsz - n,
66545 - n))
66546 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66547 + if (!elf_buf)
66548 + return -ENOMEM;
66549 + oldfs = get_fs();
66550 + set_fs(KERNEL_DS);
66551 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66552 + set_fs(oldfs);
66553 + if (copy_to_user(buffer, elf_buf, tsz)) {
66554 + kfree(elf_buf);
66555 return -EFAULT;
66556 + }
66557 }
66558 + set_fs(oldfs);
66559 + kfree(elf_buf);
66560 } else {
66561 if (clear_user(buffer, tsz))
66562 return -EFAULT;
66563 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66564
66565 static int open_kcore(struct inode *inode, struct file *filp)
66566 {
66567 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66568 + return -EPERM;
66569 +#endif
66570 if (!capable(CAP_SYS_RAWIO))
66571 return -EPERM;
66572 if (kcore_need_update)
66573 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66574 index aa1eee0..03dda72 100644
66575 --- a/fs/proc/meminfo.c
66576 +++ b/fs/proc/meminfo.c
66577 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66578 vmi.used >> 10,
66579 vmi.largest_chunk >> 10
66580 #ifdef CONFIG_MEMORY_FAILURE
66581 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66582 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66583 #endif
66584 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66585 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66586 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66587 index d4a3574..b421ce9 100644
66588 --- a/fs/proc/nommu.c
66589 +++ b/fs/proc/nommu.c
66590 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66591
66592 if (file) {
66593 seq_pad(m, ' ');
66594 - seq_path(m, &file->f_path, "");
66595 + seq_path(m, &file->f_path, "\n\\");
66596 }
66597
66598 seq_putc(m, '\n');
66599 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66600 index a63af3e..b4f262a 100644
66601 --- a/fs/proc/proc_net.c
66602 +++ b/fs/proc/proc_net.c
66603 @@ -23,9 +23,27 @@
66604 #include <linux/nsproxy.h>
66605 #include <net/net_namespace.h>
66606 #include <linux/seq_file.h>
66607 +#include <linux/grsecurity.h>
66608
66609 #include "internal.h"
66610
66611 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66612 +static struct seq_operations *ipv6_seq_ops_addr;
66613 +
66614 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66615 +{
66616 + ipv6_seq_ops_addr = addr;
66617 +}
66618 +
66619 +void unregister_ipv6_seq_ops_addr(void)
66620 +{
66621 + ipv6_seq_ops_addr = NULL;
66622 +}
66623 +
66624 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66625 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66626 +#endif
66627 +
66628 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66629 {
66630 return pde->parent->data;
66631 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66632 return maybe_get_net(PDE_NET(PDE(inode)));
66633 }
66634
66635 +extern const struct seq_operations dev_seq_ops;
66636 +
66637 int seq_open_net(struct inode *ino, struct file *f,
66638 const struct seq_operations *ops, int size)
66639 {
66640 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66641
66642 BUG_ON(size < sizeof(*p));
66643
66644 + /* only permit access to /proc/net/dev */
66645 + if (
66646 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66647 + ops != ipv6_seq_ops_addr &&
66648 +#endif
66649 + ops != &dev_seq_ops && gr_proc_is_restricted())
66650 + return -EACCES;
66651 +
66652 net = get_proc_net(ino);
66653 if (net == NULL)
66654 return -ENXIO;
66655 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66656 int err;
66657 struct net *net;
66658
66659 + if (gr_proc_is_restricted())
66660 + return -EACCES;
66661 +
66662 err = -ENXIO;
66663 net = get_proc_net(inode);
66664 if (net == NULL)
66665 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66666 index f92d5dd..26398ac 100644
66667 --- a/fs/proc/proc_sysctl.c
66668 +++ b/fs/proc/proc_sysctl.c
66669 @@ -11,13 +11,21 @@
66670 #include <linux/namei.h>
66671 #include <linux/mm.h>
66672 #include <linux/module.h>
66673 +#include <linux/nsproxy.h>
66674 +#ifdef CONFIG_GRKERNSEC
66675 +#include <net/net_namespace.h>
66676 +#endif
66677 #include "internal.h"
66678
66679 +extern int gr_handle_chroot_sysctl(const int op);
66680 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66681 + const int op);
66682 +
66683 static const struct dentry_operations proc_sys_dentry_operations;
66684 static const struct file_operations proc_sys_file_operations;
66685 -static const struct inode_operations proc_sys_inode_operations;
66686 +const struct inode_operations proc_sys_inode_operations;
66687 static const struct file_operations proc_sys_dir_file_operations;
66688 -static const struct inode_operations proc_sys_dir_operations;
66689 +const struct inode_operations proc_sys_dir_operations;
66690
66691 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66692 {
66693 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66694
66695 err = NULL;
66696 d_set_d_op(dentry, &proc_sys_dentry_operations);
66697 +
66698 + gr_handle_proc_create(dentry, inode);
66699 +
66700 d_add(dentry, inode);
66701
66702 out:
66703 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66704 struct inode *inode = file_inode(filp);
66705 struct ctl_table_header *head = grab_header(inode);
66706 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66707 + int op = write ? MAY_WRITE : MAY_READ;
66708 ssize_t error;
66709 size_t res;
66710
66711 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66712 * and won't be until we finish.
66713 */
66714 error = -EPERM;
66715 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66716 + if (sysctl_perm(head, table, op))
66717 goto out;
66718
66719 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66720 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66721 if (!table->proc_handler)
66722 goto out;
66723
66724 +#ifdef CONFIG_GRKERNSEC
66725 + error = -EPERM;
66726 + if (gr_handle_chroot_sysctl(op))
66727 + goto out;
66728 + dget(filp->f_path.dentry);
66729 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66730 + dput(filp->f_path.dentry);
66731 + goto out;
66732 + }
66733 + dput(filp->f_path.dentry);
66734 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66735 + goto out;
66736 + if (write) {
66737 + if (current->nsproxy->net_ns != table->extra2) {
66738 + if (!capable(CAP_SYS_ADMIN))
66739 + goto out;
66740 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66741 + goto out;
66742 + }
66743 +#endif
66744 +
66745 /* careful: calling conventions are nasty here */
66746 res = count;
66747 error = table->proc_handler(table, write, buf, &res, ppos);
66748 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66749 return false;
66750 } else {
66751 d_set_d_op(child, &proc_sys_dentry_operations);
66752 +
66753 + gr_handle_proc_create(child, inode);
66754 +
66755 d_add(child, inode);
66756 }
66757 } else {
66758 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66759 if ((*pos)++ < ctx->pos)
66760 return true;
66761
66762 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66763 + return 0;
66764 +
66765 if (unlikely(S_ISLNK(table->mode)))
66766 res = proc_sys_link_fill_cache(file, ctx, head, table);
66767 else
66768 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66769 if (IS_ERR(head))
66770 return PTR_ERR(head);
66771
66772 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66773 + return -ENOENT;
66774 +
66775 generic_fillattr(inode, stat);
66776 if (table)
66777 stat->mode = (stat->mode & S_IFMT) | table->mode;
66778 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66779 .llseek = generic_file_llseek,
66780 };
66781
66782 -static const struct inode_operations proc_sys_inode_operations = {
66783 +const struct inode_operations proc_sys_inode_operations = {
66784 .permission = proc_sys_permission,
66785 .setattr = proc_sys_setattr,
66786 .getattr = proc_sys_getattr,
66787 };
66788
66789 -static const struct inode_operations proc_sys_dir_operations = {
66790 +const struct inode_operations proc_sys_dir_operations = {
66791 .lookup = proc_sys_lookup,
66792 .permission = proc_sys_permission,
66793 .setattr = proc_sys_setattr,
66794 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66795 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66796 const char *name, int namelen)
66797 {
66798 - struct ctl_table *table;
66799 + ctl_table_no_const *table;
66800 struct ctl_dir *new;
66801 struct ctl_node *node;
66802 char *new_name;
66803 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66804 return NULL;
66805
66806 node = (struct ctl_node *)(new + 1);
66807 - table = (struct ctl_table *)(node + 1);
66808 + table = (ctl_table_no_const *)(node + 1);
66809 new_name = (char *)(table + 2);
66810 memcpy(new_name, name, namelen);
66811 new_name[namelen] = '\0';
66812 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66813 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66814 struct ctl_table_root *link_root)
66815 {
66816 - struct ctl_table *link_table, *entry, *link;
66817 + ctl_table_no_const *link_table, *link;
66818 + struct ctl_table *entry;
66819 struct ctl_table_header *links;
66820 struct ctl_node *node;
66821 char *link_name;
66822 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66823 return NULL;
66824
66825 node = (struct ctl_node *)(links + 1);
66826 - link_table = (struct ctl_table *)(node + nr_entries);
66827 + link_table = (ctl_table_no_const *)(node + nr_entries);
66828 link_name = (char *)&link_table[nr_entries + 1];
66829
66830 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66831 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66832 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66833 struct ctl_table *table)
66834 {
66835 - struct ctl_table *ctl_table_arg = NULL;
66836 - struct ctl_table *entry, *files;
66837 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66838 + struct ctl_table *entry;
66839 int nr_files = 0;
66840 int nr_dirs = 0;
66841 int err = -ENOMEM;
66842 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66843 nr_files++;
66844 }
66845
66846 - files = table;
66847 /* If there are mixed files and directories we need a new table */
66848 if (nr_dirs && nr_files) {
66849 - struct ctl_table *new;
66850 + ctl_table_no_const *new;
66851 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66852 GFP_KERNEL);
66853 if (!files)
66854 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66855 /* Register everything except a directory full of subdirectories */
66856 if (nr_files || !nr_dirs) {
66857 struct ctl_table_header *header;
66858 - header = __register_sysctl_table(set, path, files);
66859 + header = __register_sysctl_table(set, path, files ? files : table);
66860 if (!header) {
66861 kfree(ctl_table_arg);
66862 goto out;
66863 diff --git a/fs/proc/root.c b/fs/proc/root.c
66864 index 094e44d..085a877 100644
66865 --- a/fs/proc/root.c
66866 +++ b/fs/proc/root.c
66867 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
66868 proc_mkdir("openprom", NULL);
66869 #endif
66870 proc_tty_init();
66871 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66872 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66873 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66874 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66875 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66876 +#endif
66877 +#else
66878 proc_mkdir("bus", NULL);
66879 +#endif
66880 proc_sys_init();
66881 }
66882
66883 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66884 index bf2d03f..f058f9c 100644
66885 --- a/fs/proc/stat.c
66886 +++ b/fs/proc/stat.c
66887 @@ -11,6 +11,7 @@
66888 #include <linux/irqnr.h>
66889 #include <linux/cputime.h>
66890 #include <linux/tick.h>
66891 +#include <linux/grsecurity.h>
66892
66893 #ifndef arch_irq_stat_cpu
66894 #define arch_irq_stat_cpu(cpu) 0
66895 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66896 u64 sum_softirq = 0;
66897 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66898 struct timespec boottime;
66899 + int unrestricted = 1;
66900 +
66901 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66902 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66903 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66904 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66905 + && !in_group_p(grsec_proc_gid)
66906 +#endif
66907 + )
66908 + unrestricted = 0;
66909 +#endif
66910 +#endif
66911
66912 user = nice = system = idle = iowait =
66913 irq = softirq = steal = 0;
66914 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
66915 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66916 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66917 idle += get_idle_time(i);
66918 - iowait += get_iowait_time(i);
66919 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66920 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66921 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66922 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66923 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66924 - sum += kstat_cpu_irqs_sum(i);
66925 - sum += arch_irq_stat_cpu(i);
66926 + if (unrestricted) {
66927 + iowait += get_iowait_time(i);
66928 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66929 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66930 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66931 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66932 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66933 + sum += kstat_cpu_irqs_sum(i);
66934 + sum += arch_irq_stat_cpu(i);
66935 + for (j = 0; j < NR_SOFTIRQS; j++) {
66936 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66937
66938 - for (j = 0; j < NR_SOFTIRQS; j++) {
66939 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66940 -
66941 - per_softirq_sums[j] += softirq_stat;
66942 - sum_softirq += softirq_stat;
66943 + per_softirq_sums[j] += softirq_stat;
66944 + sum_softirq += softirq_stat;
66945 + }
66946 }
66947 }
66948 - sum += arch_irq_stat();
66949 + if (unrestricted)
66950 + sum += arch_irq_stat();
66951
66952 seq_puts(p, "cpu ");
66953 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66954 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
66955 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66956 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66957 idle = get_idle_time(i);
66958 - iowait = get_iowait_time(i);
66959 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66960 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66961 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66962 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66963 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66964 + if (unrestricted) {
66965 + iowait = get_iowait_time(i);
66966 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66967 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66968 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66969 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66970 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66971 + }
66972 seq_printf(p, "cpu%d", i);
66973 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66974 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
66975 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
66976
66977 /* sum again ? it could be updated? */
66978 for_each_irq_nr(j)
66979 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
66980 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
66981
66982 seq_printf(p,
66983 "\nctxt %llu\n"
66984 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
66985 "processes %lu\n"
66986 "procs_running %lu\n"
66987 "procs_blocked %lu\n",
66988 - nr_context_switches(),
66989 + unrestricted ? nr_context_switches() : 0ULL,
66990 (unsigned long)jif,
66991 - total_forks,
66992 - nr_running(),
66993 - nr_iowait());
66994 + unrestricted ? total_forks : 0UL,
66995 + unrestricted ? nr_running() : 0UL,
66996 + unrestricted ? nr_iowait() : 0UL);
66997
66998 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
66999
67000 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67001 index c341568..75852a2 100644
67002 --- a/fs/proc/task_mmu.c
67003 +++ b/fs/proc/task_mmu.c
67004 @@ -13,12 +13,19 @@
67005 #include <linux/swap.h>
67006 #include <linux/swapops.h>
67007 #include <linux/mmu_notifier.h>
67008 +#include <linux/grsecurity.h>
67009
67010 #include <asm/elf.h>
67011 #include <asm/uaccess.h>
67012 #include <asm/tlbflush.h>
67013 #include "internal.h"
67014
67015 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67016 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67017 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67018 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67019 +#endif
67020 +
67021 void task_mem(struct seq_file *m, struct mm_struct *mm)
67022 {
67023 unsigned long data, text, lib, swap;
67024 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67025 "VmExe:\t%8lu kB\n"
67026 "VmLib:\t%8lu kB\n"
67027 "VmPTE:\t%8lu kB\n"
67028 - "VmSwap:\t%8lu kB\n",
67029 - hiwater_vm << (PAGE_SHIFT-10),
67030 + "VmSwap:\t%8lu kB\n"
67031 +
67032 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67033 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67034 +#endif
67035 +
67036 + ,hiwater_vm << (PAGE_SHIFT-10),
67037 total_vm << (PAGE_SHIFT-10),
67038 mm->locked_vm << (PAGE_SHIFT-10),
67039 mm->pinned_vm << (PAGE_SHIFT-10),
67040 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67041 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67042 (PTRS_PER_PTE * sizeof(pte_t) *
67043 atomic_long_read(&mm->nr_ptes)) >> 10,
67044 - swap << (PAGE_SHIFT-10));
67045 + swap << (PAGE_SHIFT-10)
67046 +
67047 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67048 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67049 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67050 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67051 +#else
67052 + , mm->context.user_cs_base
67053 + , mm->context.user_cs_limit
67054 +#endif
67055 +#endif
67056 +
67057 + );
67058 }
67059
67060 unsigned long task_vsize(struct mm_struct *mm)
67061 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67062 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67063 }
67064
67065 - /* We don't show the stack guard page in /proc/maps */
67066 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67067 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67068 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67069 +#else
67070 start = vma->vm_start;
67071 - if (stack_guard_page_start(vma, start))
67072 - start += PAGE_SIZE;
67073 end = vma->vm_end;
67074 - if (stack_guard_page_end(vma, end))
67075 - end -= PAGE_SIZE;
67076 +#endif
67077
67078 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67079 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67080 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67081 flags & VM_WRITE ? 'w' : '-',
67082 flags & VM_EXEC ? 'x' : '-',
67083 flags & VM_MAYSHARE ? 's' : 'p',
67084 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67085 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67086 +#else
67087 pgoff,
67088 +#endif
67089 MAJOR(dev), MINOR(dev), ino);
67090
67091 /*
67092 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67093 */
67094 if (file) {
67095 seq_pad(m, ' ');
67096 - seq_path(m, &file->f_path, "\n");
67097 + seq_path(m, &file->f_path, "\n\\");
67098 goto done;
67099 }
67100
67101 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67102 * Thread stack in /proc/PID/task/TID/maps or
67103 * the main process stack.
67104 */
67105 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67106 - vma->vm_end >= mm->start_stack)) {
67107 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67108 + (vma->vm_start <= mm->start_stack &&
67109 + vma->vm_end >= mm->start_stack)) {
67110 name = "[stack]";
67111 } else {
67112 /* Thread stack in /proc/PID/maps */
67113 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67114 struct proc_maps_private *priv = m->private;
67115 struct task_struct *task = priv->task;
67116
67117 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67118 + if (current->exec_id != m->exec_id) {
67119 + gr_log_badprocpid("maps");
67120 + return 0;
67121 + }
67122 +#endif
67123 +
67124 show_map_vma(m, vma, is_pid);
67125
67126 if (m->count < m->size) /* vma is copied successfully */
67127 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67128 .private = &mss,
67129 };
67130
67131 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67132 + if (current->exec_id != m->exec_id) {
67133 + gr_log_badprocpid("smaps");
67134 + return 0;
67135 + }
67136 +#endif
67137 memset(&mss, 0, sizeof mss);
67138 - mss.vma = vma;
67139 - /* mmap_sem is held in m_start */
67140 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67141 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67142 -
67143 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67144 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67145 +#endif
67146 + mss.vma = vma;
67147 + /* mmap_sem is held in m_start */
67148 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67149 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67150 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67151 + }
67152 +#endif
67153 show_map_vma(m, vma, is_pid);
67154
67155 seq_printf(m,
67156 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67157 "KernelPageSize: %8lu kB\n"
67158 "MMUPageSize: %8lu kB\n"
67159 "Locked: %8lu kB\n",
67160 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67161 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67162 +#else
67163 (vma->vm_end - vma->vm_start) >> 10,
67164 +#endif
67165 mss.resident >> 10,
67166 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67167 mss.shared_clean >> 10,
67168 @@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67169 char buffer[64];
67170 int nid;
67171
67172 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67173 + if (current->exec_id != m->exec_id) {
67174 + gr_log_badprocpid("numa_maps");
67175 + return 0;
67176 + }
67177 +#endif
67178 +
67179 if (!mm)
67180 return 0;
67181
67182 @@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67183 mpol_to_str(buffer, sizeof(buffer), pol);
67184 mpol_cond_put(pol);
67185
67186 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67187 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67188 +#else
67189 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67190 +#endif
67191
67192 if (file) {
67193 seq_puts(m, " file=");
67194 - seq_path(m, &file->f_path, "\n\t= ");
67195 + seq_path(m, &file->f_path, "\n\t\\= ");
67196 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67197 seq_puts(m, " heap");
67198 } else {
67199 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67200 index 678455d..ebd3245 100644
67201 --- a/fs/proc/task_nommu.c
67202 +++ b/fs/proc/task_nommu.c
67203 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67204 else
67205 bytes += kobjsize(mm);
67206
67207 - if (current->fs && current->fs->users > 1)
67208 + if (current->fs && atomic_read(&current->fs->users) > 1)
67209 sbytes += kobjsize(current->fs);
67210 else
67211 bytes += kobjsize(current->fs);
67212 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67213
67214 if (file) {
67215 seq_pad(m, ' ');
67216 - seq_path(m, &file->f_path, "");
67217 + seq_path(m, &file->f_path, "\n\\");
67218 } else if (mm) {
67219 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67220
67221 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67222 index a90d6d35..d08047c 100644
67223 --- a/fs/proc/vmcore.c
67224 +++ b/fs/proc/vmcore.c
67225 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67226 nr_bytes = count;
67227
67228 /* If pfn is not ram, return zeros for sparse dump files */
67229 - if (pfn_is_ram(pfn) == 0)
67230 - memset(buf, 0, nr_bytes);
67231 - else {
67232 + if (pfn_is_ram(pfn) == 0) {
67233 + if (userbuf) {
67234 + if (clear_user((char __force_user *)buf, nr_bytes))
67235 + return -EFAULT;
67236 + } else
67237 + memset(buf, 0, nr_bytes);
67238 + } else {
67239 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67240 offset, userbuf);
67241 if (tmp < 0)
67242 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67243 static int copy_to(void *target, void *src, size_t size, int userbuf)
67244 {
67245 if (userbuf) {
67246 - if (copy_to_user((char __user *) target, src, size))
67247 + if (copy_to_user((char __force_user *) target, src, size))
67248 return -EFAULT;
67249 } else {
67250 memcpy(target, src, size);
67251 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67252 if (*fpos < m->offset + m->size) {
67253 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67254 start = m->paddr + *fpos - m->offset;
67255 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67256 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67257 if (tmp < 0)
67258 return tmp;
67259 buflen -= tsz;
67260 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67261 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67262 size_t buflen, loff_t *fpos)
67263 {
67264 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67265 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67266 }
67267
67268 /*
67269 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67270 index d3fb2b6..43a8140 100644
67271 --- a/fs/qnx6/qnx6.h
67272 +++ b/fs/qnx6/qnx6.h
67273 @@ -74,7 +74,7 @@ enum {
67274 BYTESEX_BE,
67275 };
67276
67277 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67278 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67279 {
67280 if (sbi->s_bytesex == BYTESEX_LE)
67281 return le64_to_cpu((__force __le64)n);
67282 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67283 return (__force __fs64)cpu_to_be64(n);
67284 }
67285
67286 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67287 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67288 {
67289 if (sbi->s_bytesex == BYTESEX_LE)
67290 return le32_to_cpu((__force __le32)n);
67291 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67292 index bb2869f..d34ada8 100644
67293 --- a/fs/quota/netlink.c
67294 +++ b/fs/quota/netlink.c
67295 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67296 void quota_send_warning(struct kqid qid, dev_t dev,
67297 const char warntype)
67298 {
67299 - static atomic_t seq;
67300 + static atomic_unchecked_t seq;
67301 struct sk_buff *skb;
67302 void *msg_head;
67303 int ret;
67304 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67305 "VFS: Not enough memory to send quota warning.\n");
67306 return;
67307 }
67308 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67309 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67310 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67311 if (!msg_head) {
67312 printk(KERN_ERR
67313 diff --git a/fs/read_write.c b/fs/read_write.c
67314 index 009d854..16ce214 100644
67315 --- a/fs/read_write.c
67316 +++ b/fs/read_write.c
67317 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67318
67319 old_fs = get_fs();
67320 set_fs(get_ds());
67321 - p = (__force const char __user *)buf;
67322 + p = (const char __force_user *)buf;
67323 if (count > MAX_RW_COUNT)
67324 count = MAX_RW_COUNT;
67325 if (file->f_op->write)
67326 diff --git a/fs/readdir.c b/fs/readdir.c
67327 index 33fd922..e0d6094 100644
67328 --- a/fs/readdir.c
67329 +++ b/fs/readdir.c
67330 @@ -18,6 +18,7 @@
67331 #include <linux/security.h>
67332 #include <linux/syscalls.h>
67333 #include <linux/unistd.h>
67334 +#include <linux/namei.h>
67335
67336 #include <asm/uaccess.h>
67337
67338 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67339 struct readdir_callback {
67340 struct dir_context ctx;
67341 struct old_linux_dirent __user * dirent;
67342 + struct file * file;
67343 int result;
67344 };
67345
67346 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67347 buf->result = -EOVERFLOW;
67348 return -EOVERFLOW;
67349 }
67350 +
67351 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67352 + return 0;
67353 +
67354 buf->result++;
67355 dirent = buf->dirent;
67356 if (!access_ok(VERIFY_WRITE, dirent,
67357 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67358 if (!f.file)
67359 return -EBADF;
67360
67361 + buf.file = f.file;
67362 error = iterate_dir(f.file, &buf.ctx);
67363 if (buf.result)
67364 error = buf.result;
67365 @@ -144,6 +151,7 @@ struct getdents_callback {
67366 struct dir_context ctx;
67367 struct linux_dirent __user * current_dir;
67368 struct linux_dirent __user * previous;
67369 + struct file * file;
67370 int count;
67371 int error;
67372 };
67373 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67374 buf->error = -EOVERFLOW;
67375 return -EOVERFLOW;
67376 }
67377 +
67378 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67379 + return 0;
67380 +
67381 dirent = buf->previous;
67382 if (dirent) {
67383 if (__put_user(offset, &dirent->d_off))
67384 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67385 if (!f.file)
67386 return -EBADF;
67387
67388 + buf.file = f.file;
67389 error = iterate_dir(f.file, &buf.ctx);
67390 if (error >= 0)
67391 error = buf.error;
67392 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67393 struct dir_context ctx;
67394 struct linux_dirent64 __user * current_dir;
67395 struct linux_dirent64 __user * previous;
67396 + struct file *file;
67397 int count;
67398 int error;
67399 };
67400 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67401 buf->error = -EINVAL; /* only used if we fail.. */
67402 if (reclen > buf->count)
67403 return -EINVAL;
67404 +
67405 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67406 + return 0;
67407 +
67408 dirent = buf->previous;
67409 if (dirent) {
67410 if (__put_user(offset, &dirent->d_off))
67411 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67412 if (!f.file)
67413 return -EBADF;
67414
67415 + buf.file = f.file;
67416 error = iterate_dir(f.file, &buf.ctx);
67417 if (error >= 0)
67418 error = buf.error;
67419 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67420 index 9c02d96..6562c10 100644
67421 --- a/fs/reiserfs/do_balan.c
67422 +++ b/fs/reiserfs/do_balan.c
67423 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67424 return;
67425 }
67426
67427 - atomic_inc(&fs_generation(tb->tb_sb));
67428 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67429 do_balance_starts(tb);
67430
67431 /*
67432 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67433 index aca73dd..e3c558d 100644
67434 --- a/fs/reiserfs/item_ops.c
67435 +++ b/fs/reiserfs/item_ops.c
67436 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67437 }
67438
67439 static struct item_operations errcatch_ops = {
67440 - errcatch_bytes_number,
67441 - errcatch_decrement_key,
67442 - errcatch_is_left_mergeable,
67443 - errcatch_print_item,
67444 - errcatch_check_item,
67445 + .bytes_number = errcatch_bytes_number,
67446 + .decrement_key = errcatch_decrement_key,
67447 + .is_left_mergeable = errcatch_is_left_mergeable,
67448 + .print_item = errcatch_print_item,
67449 + .check_item = errcatch_check_item,
67450
67451 - errcatch_create_vi,
67452 - errcatch_check_left,
67453 - errcatch_check_right,
67454 - errcatch_part_size,
67455 - errcatch_unit_num,
67456 - errcatch_print_vi
67457 + .create_vi = errcatch_create_vi,
67458 + .check_left = errcatch_check_left,
67459 + .check_right = errcatch_check_right,
67460 + .part_size = errcatch_part_size,
67461 + .unit_num = errcatch_unit_num,
67462 + .print_vi = errcatch_print_vi
67463 };
67464
67465 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67466 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67467 index 621b9f3..af527fd 100644
67468 --- a/fs/reiserfs/procfs.c
67469 +++ b/fs/reiserfs/procfs.c
67470 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67471 "SMALL_TAILS " : "NO_TAILS ",
67472 replay_only(sb) ? "REPLAY_ONLY " : "",
67473 convert_reiserfs(sb) ? "CONV " : "",
67474 - atomic_read(&r->s_generation_counter),
67475 + atomic_read_unchecked(&r->s_generation_counter),
67476 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67477 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67478 SF(s_good_search_by_key_reada), SF(s_bmaps),
67479 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67480 index 735c2c2..81b91af 100644
67481 --- a/fs/reiserfs/reiserfs.h
67482 +++ b/fs/reiserfs/reiserfs.h
67483 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
67484 /* Comment? -Hans */
67485 wait_queue_head_t s_wait;
67486 /* increased by one every time the tree gets re-balanced */
67487 - atomic_t s_generation_counter;
67488 + atomic_unchecked_t s_generation_counter;
67489
67490 /* File system properties. Currently holds on-disk FS format */
67491 unsigned long s_properties;
67492 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67493 #define REISERFS_USER_MEM 1 /* user memory mode */
67494
67495 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67496 -#define get_generation(s) atomic_read (&fs_generation(s))
67497 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67498 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67499 #define __fs_changed(gen,s) (gen != get_generation (s))
67500 #define fs_changed(gen,s) \
67501 diff --git a/fs/select.c b/fs/select.c
67502 index 467bb1c..cf9d65a 100644
67503 --- a/fs/select.c
67504 +++ b/fs/select.c
67505 @@ -20,6 +20,7 @@
67506 #include <linux/export.h>
67507 #include <linux/slab.h>
67508 #include <linux/poll.h>
67509 +#include <linux/security.h>
67510 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67511 #include <linux/file.h>
67512 #include <linux/fdtable.h>
67513 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67514 struct poll_list *walk = head;
67515 unsigned long todo = nfds;
67516
67517 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67518 if (nfds > rlimit(RLIMIT_NOFILE))
67519 return -EINVAL;
67520
67521 diff --git a/fs/seq_file.c b/fs/seq_file.c
67522 index 3857b72..0b7281e 100644
67523 --- a/fs/seq_file.c
67524 +++ b/fs/seq_file.c
67525 @@ -12,6 +12,8 @@
67526 #include <linux/slab.h>
67527 #include <linux/cred.h>
67528 #include <linux/mm.h>
67529 +#include <linux/sched.h>
67530 +#include <linux/grsecurity.h>
67531
67532 #include <asm/uaccess.h>
67533 #include <asm/page.h>
67534 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67535
67536 static void *seq_buf_alloc(unsigned long size)
67537 {
67538 - void *buf;
67539 -
67540 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67541 - if (!buf && size > PAGE_SIZE)
67542 - buf = vmalloc(size);
67543 - return buf;
67544 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67545 }
67546
67547 /**
67548 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67549 #ifdef CONFIG_USER_NS
67550 p->user_ns = file->f_cred->user_ns;
67551 #endif
67552 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67553 + p->exec_id = current->exec_id;
67554 +#endif
67555
67556 /*
67557 * Wrappers around seq_open(e.g. swaps_open) need to be
67558 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67559 }
67560 EXPORT_SYMBOL(seq_open);
67561
67562 +
67563 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67564 +{
67565 + if (gr_proc_is_restricted())
67566 + return -EACCES;
67567 +
67568 + return seq_open(file, op);
67569 +}
67570 +EXPORT_SYMBOL(seq_open_restrict);
67571 +
67572 static int traverse(struct seq_file *m, loff_t offset)
67573 {
67574 loff_t pos = 0, index;
67575 @@ -165,7 +175,7 @@ Eoverflow:
67576 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67577 {
67578 struct seq_file *m = file->private_data;
67579 - size_t copied = 0;
67580 + ssize_t copied = 0;
67581 loff_t pos;
67582 size_t n;
67583 void *p;
67584 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67585 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67586 void *data)
67587 {
67588 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67589 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67590 int res = -ENOMEM;
67591
67592 if (op) {
67593 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67594 }
67595 EXPORT_SYMBOL(single_open_size);
67596
67597 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67598 + void *data)
67599 +{
67600 + if (gr_proc_is_restricted())
67601 + return -EACCES;
67602 +
67603 + return single_open(file, show, data);
67604 +}
67605 +EXPORT_SYMBOL(single_open_restrict);
67606 +
67607 +
67608 int single_release(struct inode *inode, struct file *file)
67609 {
67610 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67611 diff --git a/fs/splice.c b/fs/splice.c
67612 index f5cb9ba..8ddb1e9 100644
67613 --- a/fs/splice.c
67614 +++ b/fs/splice.c
67615 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67616 pipe_lock(pipe);
67617
67618 for (;;) {
67619 - if (!pipe->readers) {
67620 + if (!atomic_read(&pipe->readers)) {
67621 send_sig(SIGPIPE, current, 0);
67622 if (!ret)
67623 ret = -EPIPE;
67624 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67625 page_nr++;
67626 ret += buf->len;
67627
67628 - if (pipe->files)
67629 + if (atomic_read(&pipe->files))
67630 do_wakeup = 1;
67631
67632 if (!--spd->nr_pages)
67633 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67634 do_wakeup = 0;
67635 }
67636
67637 - pipe->waiting_writers++;
67638 + atomic_inc(&pipe->waiting_writers);
67639 pipe_wait(pipe);
67640 - pipe->waiting_writers--;
67641 + atomic_dec(&pipe->waiting_writers);
67642 }
67643
67644 pipe_unlock(pipe);
67645 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67646 old_fs = get_fs();
67647 set_fs(get_ds());
67648 /* The cast to a user pointer is valid due to the set_fs() */
67649 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67650 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67651 set_fs(old_fs);
67652
67653 return res;
67654 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67655 old_fs = get_fs();
67656 set_fs(get_ds());
67657 /* The cast to a user pointer is valid due to the set_fs() */
67658 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67659 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67660 set_fs(old_fs);
67661
67662 return res;
67663 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67664 goto err;
67665
67666 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67667 - vec[i].iov_base = (void __user *) page_address(page);
67668 + vec[i].iov_base = (void __force_user *) page_address(page);
67669 vec[i].iov_len = this_len;
67670 spd.pages[i] = page;
67671 spd.nr_pages++;
67672 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67673 ops->release(pipe, buf);
67674 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67675 pipe->nrbufs--;
67676 - if (pipe->files)
67677 + if (atomic_read(&pipe->files))
67678 sd->need_wakeup = true;
67679 }
67680
67681 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67682 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67683 {
67684 while (!pipe->nrbufs) {
67685 - if (!pipe->writers)
67686 + if (!atomic_read(&pipe->writers))
67687 return 0;
67688
67689 - if (!pipe->waiting_writers && sd->num_spliced)
67690 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67691 return 0;
67692
67693 if (sd->flags & SPLICE_F_NONBLOCK)
67694 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67695 ops->release(pipe, buf);
67696 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67697 pipe->nrbufs--;
67698 - if (pipe->files)
67699 + if (atomic_read(&pipe->files))
67700 sd.need_wakeup = true;
67701 } else {
67702 buf->offset += ret;
67703 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67704 * out of the pipe right after the splice_to_pipe(). So set
67705 * PIPE_READERS appropriately.
67706 */
67707 - pipe->readers = 1;
67708 + atomic_set(&pipe->readers, 1);
67709
67710 current->splice_pipe = pipe;
67711 }
67712 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67713
67714 partial[buffers].offset = off;
67715 partial[buffers].len = plen;
67716 + partial[buffers].private = 0;
67717
67718 off = 0;
67719 len -= plen;
67720 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67721 ret = -ERESTARTSYS;
67722 break;
67723 }
67724 - if (!pipe->writers)
67725 + if (!atomic_read(&pipe->writers))
67726 break;
67727 - if (!pipe->waiting_writers) {
67728 + if (!atomic_read(&pipe->waiting_writers)) {
67729 if (flags & SPLICE_F_NONBLOCK) {
67730 ret = -EAGAIN;
67731 break;
67732 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67733 pipe_lock(pipe);
67734
67735 while (pipe->nrbufs >= pipe->buffers) {
67736 - if (!pipe->readers) {
67737 + if (!atomic_read(&pipe->readers)) {
67738 send_sig(SIGPIPE, current, 0);
67739 ret = -EPIPE;
67740 break;
67741 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67742 ret = -ERESTARTSYS;
67743 break;
67744 }
67745 - pipe->waiting_writers++;
67746 + atomic_inc(&pipe->waiting_writers);
67747 pipe_wait(pipe);
67748 - pipe->waiting_writers--;
67749 + atomic_dec(&pipe->waiting_writers);
67750 }
67751
67752 pipe_unlock(pipe);
67753 @@ -1817,14 +1818,14 @@ retry:
67754 pipe_double_lock(ipipe, opipe);
67755
67756 do {
67757 - if (!opipe->readers) {
67758 + if (!atomic_read(&opipe->readers)) {
67759 send_sig(SIGPIPE, current, 0);
67760 if (!ret)
67761 ret = -EPIPE;
67762 break;
67763 }
67764
67765 - if (!ipipe->nrbufs && !ipipe->writers)
67766 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67767 break;
67768
67769 /*
67770 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67771 pipe_double_lock(ipipe, opipe);
67772
67773 do {
67774 - if (!opipe->readers) {
67775 + if (!atomic_read(&opipe->readers)) {
67776 send_sig(SIGPIPE, current, 0);
67777 if (!ret)
67778 ret = -EPIPE;
67779 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67780 * return EAGAIN if we have the potential of some data in the
67781 * future, otherwise just return 0
67782 */
67783 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67784 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67785 ret = -EAGAIN;
67786
67787 pipe_unlock(ipipe);
67788 diff --git a/fs/stat.c b/fs/stat.c
67789 index ae0c3ce..9ee641c 100644
67790 --- a/fs/stat.c
67791 +++ b/fs/stat.c
67792 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67793 stat->gid = inode->i_gid;
67794 stat->rdev = inode->i_rdev;
67795 stat->size = i_size_read(inode);
67796 - stat->atime = inode->i_atime;
67797 - stat->mtime = inode->i_mtime;
67798 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67799 + stat->atime = inode->i_ctime;
67800 + stat->mtime = inode->i_ctime;
67801 + } else {
67802 + stat->atime = inode->i_atime;
67803 + stat->mtime = inode->i_mtime;
67804 + }
67805 stat->ctime = inode->i_ctime;
67806 stat->blksize = (1 << inode->i_blkbits);
67807 stat->blocks = inode->i_blocks;
67808 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67809 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67810 {
67811 struct inode *inode = path->dentry->d_inode;
67812 + int retval;
67813
67814 - if (inode->i_op->getattr)
67815 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67816 + if (inode->i_op->getattr) {
67817 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67818 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67819 + stat->atime = stat->ctime;
67820 + stat->mtime = stat->ctime;
67821 + }
67822 + return retval;
67823 + }
67824
67825 generic_fillattr(inode, stat);
67826 return 0;
67827 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67828 index 0b45ff4..847de5b 100644
67829 --- a/fs/sysfs/dir.c
67830 +++ b/fs/sysfs/dir.c
67831 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67832 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67833 {
67834 struct kernfs_node *parent, *kn;
67835 + const char *name;
67836 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67837 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67838 + const char *parent_name;
67839 +#endif
67840
67841 BUG_ON(!kobj);
67842
67843 + name = kobject_name(kobj);
67844 +
67845 if (kobj->parent)
67846 parent = kobj->parent->sd;
67847 else
67848 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67849 if (!parent)
67850 return -ENOENT;
67851
67852 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67853 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67854 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67855 + parent_name = parent->name;
67856 + mode = S_IRWXU;
67857 +
67858 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67859 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67860 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67861 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67862 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
67863 +#endif
67864 +
67865 + kn = kernfs_create_dir_ns(parent, name,
67866 + mode, kobj, ns);
67867 if (IS_ERR(kn)) {
67868 if (PTR_ERR(kn) == -EEXIST)
67869 - sysfs_warn_dup(parent, kobject_name(kobj));
67870 + sysfs_warn_dup(parent, name);
67871 return PTR_ERR(kn);
67872 }
67873
67874 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67875 index 69d4889..a810bd4 100644
67876 --- a/fs/sysv/sysv.h
67877 +++ b/fs/sysv/sysv.h
67878 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67879 #endif
67880 }
67881
67882 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67883 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67884 {
67885 if (sbi->s_bytesex == BYTESEX_PDP)
67886 return PDP_swab((__force __u32)n);
67887 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67888 index fb08b0c..65fcc7e 100644
67889 --- a/fs/ubifs/io.c
67890 +++ b/fs/ubifs/io.c
67891 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67892 return err;
67893 }
67894
67895 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67896 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67897 {
67898 int err;
67899
67900 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
67901 index c175b4d..8f36a16 100644
67902 --- a/fs/udf/misc.c
67903 +++ b/fs/udf/misc.c
67904 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
67905
67906 u8 udf_tag_checksum(const struct tag *t)
67907 {
67908 - u8 *data = (u8 *)t;
67909 + const u8 *data = (const u8 *)t;
67910 u8 checksum = 0;
67911 int i;
67912 for (i = 0; i < sizeof(struct tag); ++i)
67913 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
67914 index 8d974c4..b82f6ec 100644
67915 --- a/fs/ufs/swab.h
67916 +++ b/fs/ufs/swab.h
67917 @@ -22,7 +22,7 @@ enum {
67918 BYTESEX_BE
67919 };
67920
67921 -static inline u64
67922 +static inline u64 __intentional_overflow(-1)
67923 fs64_to_cpu(struct super_block *sbp, __fs64 n)
67924 {
67925 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67926 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
67927 return (__force __fs64)cpu_to_be64(n);
67928 }
67929
67930 -static inline u32
67931 +static inline u32 __intentional_overflow(-1)
67932 fs32_to_cpu(struct super_block *sbp, __fs32 n)
67933 {
67934 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67935 diff --git a/fs/utimes.c b/fs/utimes.c
67936 index aa138d6..5f3a811 100644
67937 --- a/fs/utimes.c
67938 +++ b/fs/utimes.c
67939 @@ -1,6 +1,7 @@
67940 #include <linux/compiler.h>
67941 #include <linux/file.h>
67942 #include <linux/fs.h>
67943 +#include <linux/security.h>
67944 #include <linux/linkage.h>
67945 #include <linux/mount.h>
67946 #include <linux/namei.h>
67947 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
67948 }
67949 }
67950 retry_deleg:
67951 +
67952 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
67953 + error = -EACCES;
67954 + goto mnt_drop_write_and_out;
67955 + }
67956 +
67957 mutex_lock(&inode->i_mutex);
67958 error = notify_change(path->dentry, &newattrs, &delegated_inode);
67959 mutex_unlock(&inode->i_mutex);
67960 diff --git a/fs/xattr.c b/fs/xattr.c
67961 index c69e6d4..cc56af5 100644
67962 --- a/fs/xattr.c
67963 +++ b/fs/xattr.c
67964 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
67965 return rc;
67966 }
67967
67968 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
67969 +ssize_t
67970 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
67971 +{
67972 + struct inode *inode = dentry->d_inode;
67973 + ssize_t error;
67974 +
67975 + error = inode_permission(inode, MAY_EXEC);
67976 + if (error)
67977 + return error;
67978 +
67979 + if (inode->i_op->getxattr)
67980 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
67981 + else
67982 + error = -EOPNOTSUPP;
67983 +
67984 + return error;
67985 +}
67986 +EXPORT_SYMBOL(pax_getxattr);
67987 +#endif
67988 +
67989 ssize_t
67990 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
67991 {
67992 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
67993 * Extended attribute SET operations
67994 */
67995 static long
67996 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
67997 +setxattr(struct path *path, const char __user *name, const void __user *value,
67998 size_t size, int flags)
67999 {
68000 int error;
68001 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68002 posix_acl_fix_xattr_from_user(kvalue, size);
68003 }
68004
68005 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68006 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68007 + error = -EACCES;
68008 + goto out;
68009 + }
68010 +
68011 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68012 out:
68013 if (vvalue)
68014 vfree(vvalue);
68015 @@ -377,7 +403,7 @@ retry:
68016 return error;
68017 error = mnt_want_write(path.mnt);
68018 if (!error) {
68019 - error = setxattr(path.dentry, name, value, size, flags);
68020 + error = setxattr(&path, name, value, size, flags);
68021 mnt_drop_write(path.mnt);
68022 }
68023 path_put(&path);
68024 @@ -401,7 +427,7 @@ retry:
68025 return error;
68026 error = mnt_want_write(path.mnt);
68027 if (!error) {
68028 - error = setxattr(path.dentry, name, value, size, flags);
68029 + error = setxattr(&path, name, value, size, flags);
68030 mnt_drop_write(path.mnt);
68031 }
68032 path_put(&path);
68033 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68034 const void __user *,value, size_t, size, int, flags)
68035 {
68036 struct fd f = fdget(fd);
68037 - struct dentry *dentry;
68038 int error = -EBADF;
68039
68040 if (!f.file)
68041 return error;
68042 - dentry = f.file->f_path.dentry;
68043 - audit_inode(NULL, dentry, 0);
68044 + audit_inode(NULL, f.file->f_path.dentry, 0);
68045 error = mnt_want_write_file(f.file);
68046 if (!error) {
68047 - error = setxattr(dentry, name, value, size, flags);
68048 + error = setxattr(&f.file->f_path, name, value, size, flags);
68049 mnt_drop_write_file(f.file);
68050 }
68051 fdput(f);
68052 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68053 * Extended attribute REMOVE operations
68054 */
68055 static long
68056 -removexattr(struct dentry *d, const char __user *name)
68057 +removexattr(struct path *path, const char __user *name)
68058 {
68059 int error;
68060 char kname[XATTR_NAME_MAX + 1];
68061 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68062 if (error < 0)
68063 return error;
68064
68065 - return vfs_removexattr(d, kname);
68066 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68067 + return -EACCES;
68068 +
68069 + return vfs_removexattr(path->dentry, kname);
68070 }
68071
68072 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68073 @@ -652,7 +679,7 @@ retry:
68074 return error;
68075 error = mnt_want_write(path.mnt);
68076 if (!error) {
68077 - error = removexattr(path.dentry, name);
68078 + error = removexattr(&path, name);
68079 mnt_drop_write(path.mnt);
68080 }
68081 path_put(&path);
68082 @@ -675,7 +702,7 @@ retry:
68083 return error;
68084 error = mnt_want_write(path.mnt);
68085 if (!error) {
68086 - error = removexattr(path.dentry, name);
68087 + error = removexattr(&path, name);
68088 mnt_drop_write(path.mnt);
68089 }
68090 path_put(&path);
68091 @@ -689,16 +716,16 @@ retry:
68092 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68093 {
68094 struct fd f = fdget(fd);
68095 - struct dentry *dentry;
68096 + struct path *path;
68097 int error = -EBADF;
68098
68099 if (!f.file)
68100 return error;
68101 - dentry = f.file->f_path.dentry;
68102 - audit_inode(NULL, dentry, 0);
68103 + path = &f.file->f_path;
68104 + audit_inode(NULL, path->dentry, 0);
68105 error = mnt_want_write_file(f.file);
68106 if (!error) {
68107 - error = removexattr(dentry, name);
68108 + error = removexattr(path, name);
68109 mnt_drop_write_file(f.file);
68110 }
68111 fdput(f);
68112 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68113 index 86df952..ac430d6 100644
68114 --- a/fs/xfs/libxfs/xfs_bmap.c
68115 +++ b/fs/xfs/libxfs/xfs_bmap.c
68116 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68117
68118 #else
68119 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68120 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68121 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68122 #endif /* DEBUG */
68123
68124 /*
68125 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68126 index f1b69ed..3d0222f 100644
68127 --- a/fs/xfs/xfs_dir2_readdir.c
68128 +++ b/fs/xfs/xfs_dir2_readdir.c
68129 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68130 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68131 filetype = dp->d_ops->sf_get_ftype(sfep);
68132 ctx->pos = off & 0x7fffffff;
68133 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68134 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68135 + char name[sfep->namelen];
68136 + memcpy(name, sfep->name, sfep->namelen);
68137 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68138 + return 0;
68139 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68140 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68141 return 0;
68142 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68143 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68144 index 3799695..0ddc953 100644
68145 --- a/fs/xfs/xfs_ioctl.c
68146 +++ b/fs/xfs/xfs_ioctl.c
68147 @@ -122,7 +122,7 @@ xfs_find_handle(
68148 }
68149
68150 error = -EFAULT;
68151 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68152 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68153 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68154 goto out_put;
68155
68156 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68157 index d10dc8f..56b3430 100644
68158 --- a/fs/xfs/xfs_linux.h
68159 +++ b/fs/xfs/xfs_linux.h
68160 @@ -230,7 +230,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68161 * of the compiler which do not like us using do_div in the middle
68162 * of large functions.
68163 */
68164 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68165 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68166 {
68167 __u32 mod;
68168
68169 @@ -286,7 +286,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68170 return 0;
68171 }
68172 #else
68173 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68174 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68175 {
68176 __u32 mod;
68177
68178 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68179 new file mode 100644
68180 index 0000000..f27264e
68181 --- /dev/null
68182 +++ b/grsecurity/Kconfig
68183 @@ -0,0 +1,1166 @@
68184 +#
68185 +# grecurity configuration
68186 +#
68187 +menu "Memory Protections"
68188 +depends on GRKERNSEC
68189 +
68190 +config GRKERNSEC_KMEM
68191 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68192 + default y if GRKERNSEC_CONFIG_AUTO
68193 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68194 + help
68195 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68196 + be written to or read from to modify or leak the contents of the running
68197 + kernel. /dev/port will also not be allowed to be opened, writing to
68198 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68199 + If you have module support disabled, enabling this will close up several
68200 + ways that are currently used to insert malicious code into the running
68201 + kernel.
68202 +
68203 + Even with this feature enabled, we still highly recommend that
68204 + you use the RBAC system, as it is still possible for an attacker to
68205 + modify the running kernel through other more obscure methods.
68206 +
68207 + It is highly recommended that you say Y here if you meet all the
68208 + conditions above.
68209 +
68210 +config GRKERNSEC_VM86
68211 + bool "Restrict VM86 mode"
68212 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68213 + depends on X86_32
68214 +
68215 + help
68216 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68217 + make use of a special execution mode on 32bit x86 processors called
68218 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68219 + video cards and will still work with this option enabled. The purpose
68220 + of the option is to prevent exploitation of emulation errors in
68221 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68222 + Nearly all users should be able to enable this option.
68223 +
68224 +config GRKERNSEC_IO
68225 + bool "Disable privileged I/O"
68226 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68227 + depends on X86
68228 + select RTC_CLASS
68229 + select RTC_INTF_DEV
68230 + select RTC_DRV_CMOS
68231 +
68232 + help
68233 + If you say Y here, all ioperm and iopl calls will return an error.
68234 + Ioperm and iopl can be used to modify the running kernel.
68235 + Unfortunately, some programs need this access to operate properly,
68236 + the most notable of which are XFree86 and hwclock. hwclock can be
68237 + remedied by having RTC support in the kernel, so real-time
68238 + clock support is enabled if this option is enabled, to ensure
68239 + that hwclock operates correctly. If hwclock still does not work,
68240 + either update udev or symlink /dev/rtc to /dev/rtc0.
68241 +
68242 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68243 + you may not be able to boot into a graphical environment with this
68244 + option enabled. In this case, you should use the RBAC system instead.
68245 +
68246 +config GRKERNSEC_BPF_HARDEN
68247 + bool "Harden BPF interpreter"
68248 + default y if GRKERNSEC_CONFIG_AUTO
68249 + help
68250 + Unlike previous versions of grsecurity that hardened both the BPF
68251 + interpreted code against corruption at rest as well as the JIT code
68252 + against JIT-spray attacks and attacker-controlled immediate values
68253 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68254 + and will ensure the interpreted code is read-only at rest. This feature
68255 + may be removed at a later time when eBPF stabilizes to entirely revert
68256 + back to the more secure pre-3.16 BPF interpreter/JIT.
68257 +
68258 + If you're using KERNEXEC, it's recommended that you enable this option
68259 + to supplement the hardening of the kernel.
68260 +
68261 +config GRKERNSEC_PERF_HARDEN
68262 + bool "Disable unprivileged PERF_EVENTS usage by default"
68263 + default y if GRKERNSEC_CONFIG_AUTO
68264 + depends on PERF_EVENTS
68265 + help
68266 + If you say Y here, the range of acceptable values for the
68267 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68268 + default to a new value: 3. When the sysctl is set to this value, no
68269 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68270 +
68271 + Though PERF_EVENTS can be used legitimately for performance monitoring
68272 + and low-level application profiling, it is forced on regardless of
68273 + configuration, has been at fault for several vulnerabilities, and
68274 + creates new opportunities for side channels and other information leaks.
68275 +
68276 + This feature puts PERF_EVENTS into a secure default state and permits
68277 + the administrator to change out of it temporarily if unprivileged
68278 + application profiling is needed.
68279 +
68280 +config GRKERNSEC_RAND_THREADSTACK
68281 + bool "Insert random gaps between thread stacks"
68282 + default y if GRKERNSEC_CONFIG_AUTO
68283 + depends on PAX_RANDMMAP && !PPC
68284 + help
68285 + If you say Y here, a random-sized gap will be enforced between allocated
68286 + thread stacks. Glibc's NPTL and other threading libraries that
68287 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68288 + The implementation currently provides 8 bits of entropy for the gap.
68289 +
68290 + Many distributions do not compile threaded remote services with the
68291 + -fstack-check argument to GCC, causing the variable-sized stack-based
68292 + allocator, alloca(), to not probe the stack on allocation. This
68293 + permits an unbounded alloca() to skip over any guard page and potentially
68294 + modify another thread's stack reliably. An enforced random gap
68295 + reduces the reliability of such an attack and increases the chance
68296 + that such a read/write to another thread's stack instead lands in
68297 + an unmapped area, causing a crash and triggering grsecurity's
68298 + anti-bruteforcing logic.
68299 +
68300 +config GRKERNSEC_PROC_MEMMAP
68301 + bool "Harden ASLR against information leaks and entropy reduction"
68302 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68303 + depends on PAX_NOEXEC || PAX_ASLR
68304 + help
68305 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68306 + give no information about the addresses of its mappings if
68307 + PaX features that rely on random addresses are enabled on the task.
68308 + In addition to sanitizing this information and disabling other
68309 + dangerous sources of information, this option causes reads of sensitive
68310 + /proc/<pid> entries where the file descriptor was opened in a different
68311 + task than the one performing the read. Such attempts are logged.
68312 + This option also limits argv/env strings for suid/sgid binaries
68313 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68314 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68315 + binaries to prevent alternative mmap layouts from being abused.
68316 +
68317 + If you use PaX it is essential that you say Y here as it closes up
68318 + several holes that make full ASLR useless locally.
68319 +
68320 +
68321 +config GRKERNSEC_KSTACKOVERFLOW
68322 + bool "Prevent kernel stack overflows"
68323 + default y if GRKERNSEC_CONFIG_AUTO
68324 + depends on !IA64 && 64BIT
68325 + help
68326 + If you say Y here, the kernel's process stacks will be allocated
68327 + with vmalloc instead of the kernel's default allocator. This
68328 + introduces guard pages that in combination with the alloca checking
68329 + of the STACKLEAK feature prevents all forms of kernel process stack
68330 + overflow abuse. Note that this is different from kernel stack
68331 + buffer overflows.
68332 +
68333 +config GRKERNSEC_BRUTE
68334 + bool "Deter exploit bruteforcing"
68335 + default y if GRKERNSEC_CONFIG_AUTO
68336 + help
68337 + If you say Y here, attempts to bruteforce exploits against forking
68338 + daemons such as apache or sshd, as well as against suid/sgid binaries
68339 + will be deterred. When a child of a forking daemon is killed by PaX
68340 + or crashes due to an illegal instruction or other suspicious signal,
68341 + the parent process will be delayed 30 seconds upon every subsequent
68342 + fork until the administrator is able to assess the situation and
68343 + restart the daemon.
68344 + In the suid/sgid case, the attempt is logged, the user has all their
68345 + existing instances of the suid/sgid binary terminated and will
68346 + be unable to execute any suid/sgid binaries for 15 minutes.
68347 +
68348 + It is recommended that you also enable signal logging in the auditing
68349 + section so that logs are generated when a process triggers a suspicious
68350 + signal.
68351 + If the sysctl option is enabled, a sysctl option with name
68352 + "deter_bruteforce" is created.
68353 +
68354 +config GRKERNSEC_MODHARDEN
68355 + bool "Harden module auto-loading"
68356 + default y if GRKERNSEC_CONFIG_AUTO
68357 + depends on MODULES
68358 + help
68359 + If you say Y here, module auto-loading in response to use of some
68360 + feature implemented by an unloaded module will be restricted to
68361 + root users. Enabling this option helps defend against attacks
68362 + by unprivileged users who abuse the auto-loading behavior to
68363 + cause a vulnerable module to load that is then exploited.
68364 +
68365 + If this option prevents a legitimate use of auto-loading for a
68366 + non-root user, the administrator can execute modprobe manually
68367 + with the exact name of the module mentioned in the alert log.
68368 + Alternatively, the administrator can add the module to the list
68369 + of modules loaded at boot by modifying init scripts.
68370 +
68371 + Modification of init scripts will most likely be needed on
68372 + Ubuntu servers with encrypted home directory support enabled,
68373 + as the first non-root user logging in will cause the ecb(aes),
68374 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68375 +
68376 +config GRKERNSEC_HIDESYM
68377 + bool "Hide kernel symbols"
68378 + default y if GRKERNSEC_CONFIG_AUTO
68379 + select PAX_USERCOPY_SLABS
68380 + help
68381 + If you say Y here, getting information on loaded modules, and
68382 + displaying all kernel symbols through a syscall will be restricted
68383 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68384 + /proc/kallsyms will be restricted to the root user. The RBAC
68385 + system can hide that entry even from root.
68386 +
68387 + This option also prevents leaking of kernel addresses through
68388 + several /proc entries.
68389 +
68390 + Note that this option is only effective provided the following
68391 + conditions are met:
68392 + 1) The kernel using grsecurity is not precompiled by some distribution
68393 + 2) You have also enabled GRKERNSEC_DMESG
68394 + 3) You are using the RBAC system and hiding other files such as your
68395 + kernel image and System.map. Alternatively, enabling this option
68396 + causes the permissions on /boot, /lib/modules, and the kernel
68397 + source directory to change at compile time to prevent
68398 + reading by non-root users.
68399 + If the above conditions are met, this option will aid in providing a
68400 + useful protection against local kernel exploitation of overflows
68401 + and arbitrary read/write vulnerabilities.
68402 +
68403 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68404 + in addition to this feature.
68405 +
68406 +config GRKERNSEC_RANDSTRUCT
68407 + bool "Randomize layout of sensitive kernel structures"
68408 + default y if GRKERNSEC_CONFIG_AUTO
68409 + select GRKERNSEC_HIDESYM
68410 + select MODVERSIONS if MODULES
68411 + help
68412 + If you say Y here, the layouts of a number of sensitive kernel
68413 + structures (task, fs, cred, etc) and all structures composed entirely
68414 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68415 + This can introduce the requirement of an additional infoleak
68416 + vulnerability for exploits targeting these structure types.
68417 +
68418 + Enabling this feature will introduce some performance impact, slightly
68419 + increase memory usage, and prevent the use of forensic tools like
68420 + Volatility against the system (unless the kernel source tree isn't
68421 + cleaned after kernel installation).
68422 +
68423 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68424 + It remains after a make clean to allow for external modules to be compiled
68425 + with the existing seed and will be removed by a make mrproper or
68426 + make distclean.
68427 +
68428 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68429 + to install the supporting headers explicitly in addition to the normal
68430 + gcc package.
68431 +
68432 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68433 + bool "Use cacheline-aware structure randomization"
68434 + depends on GRKERNSEC_RANDSTRUCT
68435 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68436 + help
68437 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68438 + at restricting randomization to cacheline-sized groups of elements. It
68439 + will further not randomize bitfields in structures. This reduces the
68440 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68441 +
68442 +config GRKERNSEC_KERN_LOCKOUT
68443 + bool "Active kernel exploit response"
68444 + default y if GRKERNSEC_CONFIG_AUTO
68445 + depends on X86 || ARM || PPC || SPARC
68446 + help
68447 + If you say Y here, when a PaX alert is triggered due to suspicious
68448 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68449 + or an OOPS occurs due to bad memory accesses, instead of just
68450 + terminating the offending process (and potentially allowing
68451 + a subsequent exploit from the same user), we will take one of two
68452 + actions:
68453 + If the user was root, we will panic the system
68454 + If the user was non-root, we will log the attempt, terminate
68455 + all processes owned by the user, then prevent them from creating
68456 + any new processes until the system is restarted
68457 + This deters repeated kernel exploitation/bruteforcing attempts
68458 + and is useful for later forensics.
68459 +
68460 +config GRKERNSEC_OLD_ARM_USERLAND
68461 + bool "Old ARM userland compatibility"
68462 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68463 + help
68464 + If you say Y here, stubs of executable code to perform such operations
68465 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68466 + table. This is unfortunately needed for old ARM userland meant to run
68467 + across a wide range of processors. Without this option enabled,
68468 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68469 + which is enough for Linaro userlands or other userlands designed for v6
68470 + and newer ARM CPUs. It's recommended that you try without this option enabled
68471 + first, and only enable it if your userland does not boot (it will likely fail
68472 + at init time).
68473 +
68474 +endmenu
68475 +menu "Role Based Access Control Options"
68476 +depends on GRKERNSEC
68477 +
68478 +config GRKERNSEC_RBAC_DEBUG
68479 + bool
68480 +
68481 +config GRKERNSEC_NO_RBAC
68482 + bool "Disable RBAC system"
68483 + help
68484 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68485 + preventing the RBAC system from being enabled. You should only say Y
68486 + here if you have no intention of using the RBAC system, so as to prevent
68487 + an attacker with root access from misusing the RBAC system to hide files
68488 + and processes when loadable module support and /dev/[k]mem have been
68489 + locked down.
68490 +
68491 +config GRKERNSEC_ACL_HIDEKERN
68492 + bool "Hide kernel processes"
68493 + help
68494 + If you say Y here, all kernel threads will be hidden to all
68495 + processes but those whose subject has the "view hidden processes"
68496 + flag.
68497 +
68498 +config GRKERNSEC_ACL_MAXTRIES
68499 + int "Maximum tries before password lockout"
68500 + default 3
68501 + help
68502 + This option enforces the maximum number of times a user can attempt
68503 + to authorize themselves with the grsecurity RBAC system before being
68504 + denied the ability to attempt authorization again for a specified time.
68505 + The lower the number, the harder it will be to brute-force a password.
68506 +
68507 +config GRKERNSEC_ACL_TIMEOUT
68508 + int "Time to wait after max password tries, in seconds"
68509 + default 30
68510 + help
68511 + This option specifies the time the user must wait after attempting to
68512 + authorize to the RBAC system with the maximum number of invalid
68513 + passwords. The higher the number, the harder it will be to brute-force
68514 + a password.
68515 +
68516 +endmenu
68517 +menu "Filesystem Protections"
68518 +depends on GRKERNSEC
68519 +
68520 +config GRKERNSEC_PROC
68521 + bool "Proc restrictions"
68522 + default y if GRKERNSEC_CONFIG_AUTO
68523 + help
68524 + If you say Y here, the permissions of the /proc filesystem
68525 + will be altered to enhance system security and privacy. You MUST
68526 + choose either a user only restriction or a user and group restriction.
68527 + Depending upon the option you choose, you can either restrict users to
68528 + see only the processes they themselves run, or choose a group that can
68529 + view all processes and files normally restricted to root if you choose
68530 + the "restrict to user only" option. NOTE: If you're running identd or
68531 + ntpd as a non-root user, you will have to run it as the group you
68532 + specify here.
68533 +
68534 +config GRKERNSEC_PROC_USER
68535 + bool "Restrict /proc to user only"
68536 + depends on GRKERNSEC_PROC
68537 + help
68538 + If you say Y here, non-root users will only be able to view their own
68539 + processes, and restricts them from viewing network-related information,
68540 + and viewing kernel symbol and module information.
68541 +
68542 +config GRKERNSEC_PROC_USERGROUP
68543 + bool "Allow special group"
68544 + default y if GRKERNSEC_CONFIG_AUTO
68545 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68546 + help
68547 + If you say Y here, you will be able to select a group that will be
68548 + able to view all processes and network-related information. If you've
68549 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68550 + remain hidden. This option is useful if you want to run identd as
68551 + a non-root user. The group you select may also be chosen at boot time
68552 + via "grsec_proc_gid=" on the kernel commandline.
68553 +
68554 +config GRKERNSEC_PROC_GID
68555 + int "GID for special group"
68556 + depends on GRKERNSEC_PROC_USERGROUP
68557 + default 1001
68558 +
68559 +config GRKERNSEC_PROC_ADD
68560 + bool "Additional restrictions"
68561 + default y if GRKERNSEC_CONFIG_AUTO
68562 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68563 + help
68564 + If you say Y here, additional restrictions will be placed on
68565 + /proc that keep normal users from viewing device information and
68566 + slabinfo information that could be useful for exploits.
68567 +
68568 +config GRKERNSEC_LINK
68569 + bool "Linking restrictions"
68570 + default y if GRKERNSEC_CONFIG_AUTO
68571 + help
68572 + If you say Y here, /tmp race exploits will be prevented, since users
68573 + will no longer be able to follow symlinks owned by other users in
68574 + world-writable +t directories (e.g. /tmp), unless the owner of the
68575 + symlink is the owner of the directory. users will also not be
68576 + able to hardlink to files they do not own. If the sysctl option is
68577 + enabled, a sysctl option with name "linking_restrictions" is created.
68578 +
68579 +config GRKERNSEC_SYMLINKOWN
68580 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68581 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68582 + help
68583 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68584 + that prevents it from being used as a security feature. As Apache
68585 + verifies the symlink by performing a stat() against the target of
68586 + the symlink before it is followed, an attacker can setup a symlink
68587 + to point to a same-owned file, then replace the symlink with one
68588 + that targets another user's file just after Apache "validates" the
68589 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68590 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68591 + will be in place for the group you specify. If the sysctl option
68592 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68593 + created.
68594 +
68595 +config GRKERNSEC_SYMLINKOWN_GID
68596 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68597 + depends on GRKERNSEC_SYMLINKOWN
68598 + default 1006
68599 + help
68600 + Setting this GID determines what group kernel-enforced
68601 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68602 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68603 +
68604 +config GRKERNSEC_FIFO
68605 + bool "FIFO restrictions"
68606 + default y if GRKERNSEC_CONFIG_AUTO
68607 + help
68608 + If you say Y here, users will not be able to write to FIFOs they don't
68609 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68610 + the FIFO is the same owner of the directory it's held in. If the sysctl
68611 + option is enabled, a sysctl option with name "fifo_restrictions" is
68612 + created.
68613 +
68614 +config GRKERNSEC_SYSFS_RESTRICT
68615 + bool "Sysfs/debugfs restriction"
68616 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68617 + depends on SYSFS
68618 + help
68619 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68620 + any filesystem normally mounted under it (e.g. debugfs) will be
68621 + mostly accessible only by root. These filesystems generally provide access
68622 + to hardware and debug information that isn't appropriate for unprivileged
68623 + users of the system. Sysfs and debugfs have also become a large source
68624 + of new vulnerabilities, ranging from infoleaks to local compromise.
68625 + There has been very little oversight with an eye toward security involved
68626 + in adding new exporters of information to these filesystems, so their
68627 + use is discouraged.
68628 + For reasons of compatibility, a few directories have been whitelisted
68629 + for access by non-root users:
68630 + /sys/fs/selinux
68631 + /sys/fs/fuse
68632 + /sys/devices/system/cpu
68633 +
68634 +config GRKERNSEC_ROFS
68635 + bool "Runtime read-only mount protection"
68636 + depends on SYSCTL
68637 + help
68638 + If you say Y here, a sysctl option with name "romount_protect" will
68639 + be created. By setting this option to 1 at runtime, filesystems
68640 + will be protected in the following ways:
68641 + * No new writable mounts will be allowed
68642 + * Existing read-only mounts won't be able to be remounted read/write
68643 + * Write operations will be denied on all block devices
68644 + This option acts independently of grsec_lock: once it is set to 1,
68645 + it cannot be turned off. Therefore, please be mindful of the resulting
68646 + behavior if this option is enabled in an init script on a read-only
68647 + filesystem.
68648 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68649 + and GRKERNSEC_IO should be enabled and module loading disabled via
68650 + config or at runtime.
68651 + This feature is mainly intended for secure embedded systems.
68652 +
68653 +
68654 +config GRKERNSEC_DEVICE_SIDECHANNEL
68655 + bool "Eliminate stat/notify-based device sidechannels"
68656 + default y if GRKERNSEC_CONFIG_AUTO
68657 + help
68658 + If you say Y here, timing analyses on block or character
68659 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68660 + will be thwarted for unprivileged users. If a process without
68661 + CAP_MKNOD stats such a device, the last access and last modify times
68662 + will match the device's create time. No access or modify events
68663 + will be triggered through inotify/dnotify/fanotify for such devices.
68664 + This feature will prevent attacks that may at a minimum
68665 + allow an attacker to determine the administrator's password length.
68666 +
68667 +config GRKERNSEC_CHROOT
68668 + bool "Chroot jail restrictions"
68669 + default y if GRKERNSEC_CONFIG_AUTO
68670 + help
68671 + If you say Y here, you will be able to choose several options that will
68672 + make breaking out of a chrooted jail much more difficult. If you
68673 + encounter no software incompatibilities with the following options, it
68674 + is recommended that you enable each one.
68675 +
68676 + Note that the chroot restrictions are not intended to apply to "chroots"
68677 + to directories that are simple bind mounts of the global root filesystem.
68678 + For several other reasons, a user shouldn't expect any significant
68679 + security by performing such a chroot.
68680 +
68681 +config GRKERNSEC_CHROOT_MOUNT
68682 + bool "Deny mounts"
68683 + default y if GRKERNSEC_CONFIG_AUTO
68684 + depends on GRKERNSEC_CHROOT
68685 + help
68686 + If you say Y here, processes inside a chroot will not be able to
68687 + mount or remount filesystems. If the sysctl option is enabled, a
68688 + sysctl option with name "chroot_deny_mount" is created.
68689 +
68690 +config GRKERNSEC_CHROOT_DOUBLE
68691 + bool "Deny double-chroots"
68692 + default y if GRKERNSEC_CONFIG_AUTO
68693 + depends on GRKERNSEC_CHROOT
68694 + help
68695 + If you say Y here, processes inside a chroot will not be able to chroot
68696 + again outside the chroot. This is a widely used method of breaking
68697 + out of a chroot jail and should not be allowed. If the sysctl
68698 + option is enabled, a sysctl option with name
68699 + "chroot_deny_chroot" is created.
68700 +
68701 +config GRKERNSEC_CHROOT_PIVOT
68702 + bool "Deny pivot_root in chroot"
68703 + default y if GRKERNSEC_CONFIG_AUTO
68704 + depends on GRKERNSEC_CHROOT
68705 + help
68706 + If you say Y here, processes inside a chroot will not be able to use
68707 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68708 + works similar to chroot in that it changes the root filesystem. This
68709 + function could be misused in a chrooted process to attempt to break out
68710 + of the chroot, and therefore should not be allowed. If the sysctl
68711 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68712 + created.
68713 +
68714 +config GRKERNSEC_CHROOT_CHDIR
68715 + bool "Enforce chdir(\"/\") on all chroots"
68716 + default y if GRKERNSEC_CONFIG_AUTO
68717 + depends on GRKERNSEC_CHROOT
68718 + help
68719 + If you say Y here, the current working directory of all newly-chrooted
68720 + applications will be set to the the root directory of the chroot.
68721 + The man page on chroot(2) states:
68722 + Note that this call does not change the current working
68723 + directory, so that `.' can be outside the tree rooted at
68724 + `/'. In particular, the super-user can escape from a
68725 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68726 +
68727 + It is recommended that you say Y here, since it's not known to break
68728 + any software. If the sysctl option is enabled, a sysctl option with
68729 + name "chroot_enforce_chdir" is created.
68730 +
68731 +config GRKERNSEC_CHROOT_CHMOD
68732 + bool "Deny (f)chmod +s"
68733 + default y if GRKERNSEC_CONFIG_AUTO
68734 + depends on GRKERNSEC_CHROOT
68735 + help
68736 + If you say Y here, processes inside a chroot will not be able to chmod
68737 + or fchmod files to make them have suid or sgid bits. This protects
68738 + against another published method of breaking a chroot. If the sysctl
68739 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68740 + created.
68741 +
68742 +config GRKERNSEC_CHROOT_FCHDIR
68743 + bool "Deny fchdir and fhandle out of chroot"
68744 + default y if GRKERNSEC_CONFIG_AUTO
68745 + depends on GRKERNSEC_CHROOT
68746 + help
68747 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68748 + to a file descriptor of the chrooting process that points to a directory
68749 + outside the filesystem will be stopped. Additionally, this option prevents
68750 + use of the recently-created syscall for opening files by a guessable "file
68751 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68752 + with name "chroot_deny_fchdir" is created.
68753 +
68754 +config GRKERNSEC_CHROOT_MKNOD
68755 + bool "Deny mknod"
68756 + default y if GRKERNSEC_CONFIG_AUTO
68757 + depends on GRKERNSEC_CHROOT
68758 + help
68759 + If you say Y here, processes inside a chroot will not be allowed to
68760 + mknod. The problem with using mknod inside a chroot is that it
68761 + would allow an attacker to create a device entry that is the same
68762 + as one on the physical root of your system, which could range from
68763 + anything from the console device to a device for your harddrive (which
68764 + they could then use to wipe the drive or steal data). It is recommended
68765 + that you say Y here, unless you run into software incompatibilities.
68766 + If the sysctl option is enabled, a sysctl option with name
68767 + "chroot_deny_mknod" is created.
68768 +
68769 +config GRKERNSEC_CHROOT_SHMAT
68770 + bool "Deny shmat() out of chroot"
68771 + default y if GRKERNSEC_CONFIG_AUTO
68772 + depends on GRKERNSEC_CHROOT
68773 + help
68774 + If you say Y here, processes inside a chroot will not be able to attach
68775 + to shared memory segments that were created outside of the chroot jail.
68776 + It is recommended that you say Y here. If the sysctl option is enabled,
68777 + a sysctl option with name "chroot_deny_shmat" is created.
68778 +
68779 +config GRKERNSEC_CHROOT_UNIX
68780 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68781 + default y if GRKERNSEC_CONFIG_AUTO
68782 + depends on GRKERNSEC_CHROOT
68783 + help
68784 + If you say Y here, processes inside a chroot will not be able to
68785 + connect to abstract (meaning not belonging to a filesystem) Unix
68786 + domain sockets that were bound outside of a chroot. It is recommended
68787 + that you say Y here. If the sysctl option is enabled, a sysctl option
68788 + with name "chroot_deny_unix" is created.
68789 +
68790 +config GRKERNSEC_CHROOT_FINDTASK
68791 + bool "Protect outside processes"
68792 + default y if GRKERNSEC_CONFIG_AUTO
68793 + depends on GRKERNSEC_CHROOT
68794 + help
68795 + If you say Y here, processes inside a chroot will not be able to
68796 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68797 + getsid, or view any process outside of the chroot. If the sysctl
68798 + option is enabled, a sysctl option with name "chroot_findtask" is
68799 + created.
68800 +
68801 +config GRKERNSEC_CHROOT_NICE
68802 + bool "Restrict priority changes"
68803 + default y if GRKERNSEC_CONFIG_AUTO
68804 + depends on GRKERNSEC_CHROOT
68805 + help
68806 + If you say Y here, processes inside a chroot will not be able to raise
68807 + the priority of processes in the chroot, or alter the priority of
68808 + processes outside the chroot. This provides more security than simply
68809 + removing CAP_SYS_NICE from the process' capability set. If the
68810 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68811 + is created.
68812 +
68813 +config GRKERNSEC_CHROOT_SYSCTL
68814 + bool "Deny sysctl writes"
68815 + default y if GRKERNSEC_CONFIG_AUTO
68816 + depends on GRKERNSEC_CHROOT
68817 + help
68818 + If you say Y here, an attacker in a chroot will not be able to
68819 + write to sysctl entries, either by sysctl(2) or through a /proc
68820 + interface. It is strongly recommended that you say Y here. If the
68821 + sysctl option is enabled, a sysctl option with name
68822 + "chroot_deny_sysctl" is created.
68823 +
68824 +config GRKERNSEC_CHROOT_CAPS
68825 + bool "Capability restrictions"
68826 + default y if GRKERNSEC_CONFIG_AUTO
68827 + depends on GRKERNSEC_CHROOT
68828 + help
68829 + If you say Y here, the capabilities on all processes within a
68830 + chroot jail will be lowered to stop module insertion, raw i/o,
68831 + system and net admin tasks, rebooting the system, modifying immutable
68832 + files, modifying IPC owned by another, and changing the system time.
68833 + This is left an option because it can break some apps. Disable this
68834 + if your chrooted apps are having problems performing those kinds of
68835 + tasks. If the sysctl option is enabled, a sysctl option with
68836 + name "chroot_caps" is created.
68837 +
68838 +config GRKERNSEC_CHROOT_INITRD
68839 + bool "Exempt initrd tasks from restrictions"
68840 + default y if GRKERNSEC_CONFIG_AUTO
68841 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68842 + help
68843 + If you say Y here, tasks started prior to init will be exempted from
68844 + grsecurity's chroot restrictions. This option is mainly meant to
68845 + resolve Plymouth's performing privileged operations unnecessarily
68846 + in a chroot.
68847 +
68848 +endmenu
68849 +menu "Kernel Auditing"
68850 +depends on GRKERNSEC
68851 +
68852 +config GRKERNSEC_AUDIT_GROUP
68853 + bool "Single group for auditing"
68854 + help
68855 + If you say Y here, the exec and chdir logging features will only operate
68856 + on a group you specify. This option is recommended if you only want to
68857 + watch certain users instead of having a large amount of logs from the
68858 + entire system. If the sysctl option is enabled, a sysctl option with
68859 + name "audit_group" is created.
68860 +
68861 +config GRKERNSEC_AUDIT_GID
68862 + int "GID for auditing"
68863 + depends on GRKERNSEC_AUDIT_GROUP
68864 + default 1007
68865 +
68866 +config GRKERNSEC_EXECLOG
68867 + bool "Exec logging"
68868 + help
68869 + If you say Y here, all execve() calls will be logged (since the
68870 + other exec*() calls are frontends to execve(), all execution
68871 + will be logged). Useful for shell-servers that like to keep track
68872 + of their users. If the sysctl option is enabled, a sysctl option with
68873 + name "exec_logging" is created.
68874 + WARNING: This option when enabled will produce a LOT of logs, especially
68875 + on an active system.
68876 +
68877 +config GRKERNSEC_RESLOG
68878 + bool "Resource logging"
68879 + default y if GRKERNSEC_CONFIG_AUTO
68880 + help
68881 + If you say Y here, all attempts to overstep resource limits will
68882 + be logged with the resource name, the requested size, and the current
68883 + limit. It is highly recommended that you say Y here. If the sysctl
68884 + option is enabled, a sysctl option with name "resource_logging" is
68885 + created. If the RBAC system is enabled, the sysctl value is ignored.
68886 +
68887 +config GRKERNSEC_CHROOT_EXECLOG
68888 + bool "Log execs within chroot"
68889 + help
68890 + If you say Y here, all executions inside a chroot jail will be logged
68891 + to syslog. This can cause a large amount of logs if certain
68892 + applications (eg. djb's daemontools) are installed on the system, and
68893 + is therefore left as an option. If the sysctl option is enabled, a
68894 + sysctl option with name "chroot_execlog" is created.
68895 +
68896 +config GRKERNSEC_AUDIT_PTRACE
68897 + bool "Ptrace logging"
68898 + help
68899 + If you say Y here, all attempts to attach to a process via ptrace
68900 + will be logged. If the sysctl option is enabled, a sysctl option
68901 + with name "audit_ptrace" is created.
68902 +
68903 +config GRKERNSEC_AUDIT_CHDIR
68904 + bool "Chdir logging"
68905 + help
68906 + If you say Y here, all chdir() calls will be logged. If the sysctl
68907 + option is enabled, a sysctl option with name "audit_chdir" is created.
68908 +
68909 +config GRKERNSEC_AUDIT_MOUNT
68910 + bool "(Un)Mount logging"
68911 + help
68912 + If you say Y here, all mounts and unmounts will be logged. If the
68913 + sysctl option is enabled, a sysctl option with name "audit_mount" is
68914 + created.
68915 +
68916 +config GRKERNSEC_SIGNAL
68917 + bool "Signal logging"
68918 + default y if GRKERNSEC_CONFIG_AUTO
68919 + help
68920 + If you say Y here, certain important signals will be logged, such as
68921 + SIGSEGV, which will as a result inform you of when a error in a program
68922 + occurred, which in some cases could mean a possible exploit attempt.
68923 + If the sysctl option is enabled, a sysctl option with name
68924 + "signal_logging" is created.
68925 +
68926 +config GRKERNSEC_FORKFAIL
68927 + bool "Fork failure logging"
68928 + help
68929 + If you say Y here, all failed fork() attempts will be logged.
68930 + This could suggest a fork bomb, or someone attempting to overstep
68931 + their process limit. If the sysctl option is enabled, a sysctl option
68932 + with name "forkfail_logging" is created.
68933 +
68934 +config GRKERNSEC_TIME
68935 + bool "Time change logging"
68936 + default y if GRKERNSEC_CONFIG_AUTO
68937 + help
68938 + If you say Y here, any changes of the system clock will be logged.
68939 + If the sysctl option is enabled, a sysctl option with name
68940 + "timechange_logging" is created.
68941 +
68942 +config GRKERNSEC_PROC_IPADDR
68943 + bool "/proc/<pid>/ipaddr support"
68944 + default y if GRKERNSEC_CONFIG_AUTO
68945 + help
68946 + If you say Y here, a new entry will be added to each /proc/<pid>
68947 + directory that contains the IP address of the person using the task.
68948 + The IP is carried across local TCP and AF_UNIX stream sockets.
68949 + This information can be useful for IDS/IPSes to perform remote response
68950 + to a local attack. The entry is readable by only the owner of the
68951 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
68952 + the RBAC system), and thus does not create privacy concerns.
68953 +
68954 +config GRKERNSEC_RWXMAP_LOG
68955 + bool 'Denied RWX mmap/mprotect logging'
68956 + default y if GRKERNSEC_CONFIG_AUTO
68957 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
68958 + help
68959 + If you say Y here, calls to mmap() and mprotect() with explicit
68960 + usage of PROT_WRITE and PROT_EXEC together will be logged when
68961 + denied by the PAX_MPROTECT feature. This feature will also
68962 + log other problematic scenarios that can occur when PAX_MPROTECT
68963 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
68964 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
68965 + is created.
68966 +
68967 +endmenu
68968 +
68969 +menu "Executable Protections"
68970 +depends on GRKERNSEC
68971 +
68972 +config GRKERNSEC_DMESG
68973 + bool "Dmesg(8) restriction"
68974 + default y if GRKERNSEC_CONFIG_AUTO
68975 + help
68976 + If you say Y here, non-root users will not be able to use dmesg(8)
68977 + to view the contents of the kernel's circular log buffer.
68978 + The kernel's log buffer often contains kernel addresses and other
68979 + identifying information useful to an attacker in fingerprinting a
68980 + system for a targeted exploit.
68981 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
68982 + created.
68983 +
68984 +config GRKERNSEC_HARDEN_PTRACE
68985 + bool "Deter ptrace-based process snooping"
68986 + default y if GRKERNSEC_CONFIG_AUTO
68987 + help
68988 + If you say Y here, TTY sniffers and other malicious monitoring
68989 + programs implemented through ptrace will be defeated. If you
68990 + have been using the RBAC system, this option has already been
68991 + enabled for several years for all users, with the ability to make
68992 + fine-grained exceptions.
68993 +
68994 + This option only affects the ability of non-root users to ptrace
68995 + processes that are not a descendent of the ptracing process.
68996 + This means that strace ./binary and gdb ./binary will still work,
68997 + but attaching to arbitrary processes will not. If the sysctl
68998 + option is enabled, a sysctl option with name "harden_ptrace" is
68999 + created.
69000 +
69001 +config GRKERNSEC_PTRACE_READEXEC
69002 + bool "Require read access to ptrace sensitive binaries"
69003 + default y if GRKERNSEC_CONFIG_AUTO
69004 + help
69005 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69006 + binaries. This option is useful in environments that
69007 + remove the read bits (e.g. file mode 4711) from suid binaries to
69008 + prevent infoleaking of their contents. This option adds
69009 + consistency to the use of that file mode, as the binary could normally
69010 + be read out when run without privileges while ptracing.
69011 +
69012 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69013 + is created.
69014 +
69015 +config GRKERNSEC_SETXID
69016 + bool "Enforce consistent multithreaded privileges"
69017 + default y if GRKERNSEC_CONFIG_AUTO
69018 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69019 + help
69020 + If you say Y here, a change from a root uid to a non-root uid
69021 + in a multithreaded application will cause the resulting uids,
69022 + gids, supplementary groups, and capabilities in that thread
69023 + to be propagated to the other threads of the process. In most
69024 + cases this is unnecessary, as glibc will emulate this behavior
69025 + on behalf of the application. Other libcs do not act in the
69026 + same way, allowing the other threads of the process to continue
69027 + running with root privileges. If the sysctl option is enabled,
69028 + a sysctl option with name "consistent_setxid" is created.
69029 +
69030 +config GRKERNSEC_HARDEN_IPC
69031 + bool "Disallow access to overly-permissive IPC objects"
69032 + default y if GRKERNSEC_CONFIG_AUTO
69033 + depends on SYSVIPC
69034 + help
69035 + If you say Y here, access to overly-permissive IPC objects (shared
69036 + memory, message queues, and semaphores) will be denied for processes
69037 + given the following criteria beyond normal permission checks:
69038 + 1) If the IPC object is world-accessible and the euid doesn't match
69039 + that of the creator or current uid for the IPC object
69040 + 2) If the IPC object is group-accessible and the egid doesn't
69041 + match that of the creator or current gid for the IPC object
69042 + It's a common error to grant too much permission to these objects,
69043 + with impact ranging from denial of service and information leaking to
69044 + privilege escalation. This feature was developed in response to
69045 + research by Tim Brown:
69046 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69047 + who found hundreds of such insecure usages. Processes with
69048 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69049 + If the sysctl option is enabled, a sysctl option with name
69050 + "harden_ipc" is created.
69051 +
69052 +config GRKERNSEC_TPE
69053 + bool "Trusted Path Execution (TPE)"
69054 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69055 + help
69056 + If you say Y here, you will be able to choose a gid to add to the
69057 + supplementary groups of users you want to mark as "untrusted."
69058 + These users will not be able to execute any files that are not in
69059 + root-owned directories writable only by root. If the sysctl option
69060 + is enabled, a sysctl option with name "tpe" is created.
69061 +
69062 +config GRKERNSEC_TPE_ALL
69063 + bool "Partially restrict all non-root users"
69064 + depends on GRKERNSEC_TPE
69065 + help
69066 + If you say Y here, all non-root users will be covered under
69067 + a weaker TPE restriction. This is separate from, and in addition to,
69068 + the main TPE options that you have selected elsewhere. Thus, if a
69069 + "trusted" GID is chosen, this restriction applies to even that GID.
69070 + Under this restriction, all non-root users will only be allowed to
69071 + execute files in directories they own that are not group or
69072 + world-writable, or in directories owned by root and writable only by
69073 + root. If the sysctl option is enabled, a sysctl option with name
69074 + "tpe_restrict_all" is created.
69075 +
69076 +config GRKERNSEC_TPE_INVERT
69077 + bool "Invert GID option"
69078 + depends on GRKERNSEC_TPE
69079 + help
69080 + If you say Y here, the group you specify in the TPE configuration will
69081 + decide what group TPE restrictions will be *disabled* for. This
69082 + option is useful if you want TPE restrictions to be applied to most
69083 + users on the system. If the sysctl option is enabled, a sysctl option
69084 + with name "tpe_invert" is created. Unlike other sysctl options, this
69085 + entry will default to on for backward-compatibility.
69086 +
69087 +config GRKERNSEC_TPE_GID
69088 + int
69089 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69090 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69091 +
69092 +config GRKERNSEC_TPE_UNTRUSTED_GID
69093 + int "GID for TPE-untrusted users"
69094 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69095 + default 1005
69096 + help
69097 + Setting this GID determines what group TPE restrictions will be
69098 + *enabled* for. If the sysctl option is enabled, a sysctl option
69099 + with name "tpe_gid" is created.
69100 +
69101 +config GRKERNSEC_TPE_TRUSTED_GID
69102 + int "GID for TPE-trusted users"
69103 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69104 + default 1005
69105 + help
69106 + Setting this GID determines what group TPE restrictions will be
69107 + *disabled* for. If the sysctl option is enabled, a sysctl option
69108 + with name "tpe_gid" is created.
69109 +
69110 +endmenu
69111 +menu "Network Protections"
69112 +depends on GRKERNSEC
69113 +
69114 +config GRKERNSEC_BLACKHOLE
69115 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69116 + default y if GRKERNSEC_CONFIG_AUTO
69117 + depends on NET
69118 + help
69119 + If you say Y here, neither TCP resets nor ICMP
69120 + destination-unreachable packets will be sent in response to packets
69121 + sent to ports for which no associated listening process exists.
69122 + It will also prevent the sending of ICMP protocol unreachable packets
69123 + in response to packets with unknown protocols.
69124 + This feature supports both IPV4 and IPV6 and exempts the
69125 + loopback interface from blackholing. Enabling this feature
69126 + makes a host more resilient to DoS attacks and reduces network
69127 + visibility against scanners.
69128 +
69129 + The blackhole feature as-implemented is equivalent to the FreeBSD
69130 + blackhole feature, as it prevents RST responses to all packets, not
69131 + just SYNs. Under most application behavior this causes no
69132 + problems, but applications (like haproxy) may not close certain
69133 + connections in a way that cleanly terminates them on the remote
69134 + end, leaving the remote host in LAST_ACK state. Because of this
69135 + side-effect and to prevent intentional LAST_ACK DoSes, this
69136 + feature also adds automatic mitigation against such attacks.
69137 + The mitigation drastically reduces the amount of time a socket
69138 + can spend in LAST_ACK state. If you're using haproxy and not
69139 + all servers it connects to have this option enabled, consider
69140 + disabling this feature on the haproxy host.
69141 +
69142 + If the sysctl option is enabled, two sysctl options with names
69143 + "ip_blackhole" and "lastack_retries" will be created.
69144 + While "ip_blackhole" takes the standard zero/non-zero on/off
69145 + toggle, "lastack_retries" uses the same kinds of values as
69146 + "tcp_retries1" and "tcp_retries2". The default value of 4
69147 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69148 + state.
69149 +
69150 +config GRKERNSEC_NO_SIMULT_CONNECT
69151 + bool "Disable TCP Simultaneous Connect"
69152 + default y if GRKERNSEC_CONFIG_AUTO
69153 + depends on NET
69154 + help
69155 + If you say Y here, a feature by Willy Tarreau will be enabled that
69156 + removes a weakness in Linux's strict implementation of TCP that
69157 + allows two clients to connect to each other without either entering
69158 + a listening state. The weakness allows an attacker to easily prevent
69159 + a client from connecting to a known server provided the source port
69160 + for the connection is guessed correctly.
69161 +
69162 + As the weakness could be used to prevent an antivirus or IPS from
69163 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69164 + it should be eliminated by enabling this option. Though Linux is
69165 + one of few operating systems supporting simultaneous connect, it
69166 + has no legitimate use in practice and is rarely supported by firewalls.
69167 +
69168 +config GRKERNSEC_SOCKET
69169 + bool "Socket restrictions"
69170 + depends on NET
69171 + help
69172 + If you say Y here, you will be able to choose from several options.
69173 + If you assign a GID on your system and add it to the supplementary
69174 + groups of users you want to restrict socket access to, this patch
69175 + will perform up to three things, based on the option(s) you choose.
69176 +
69177 +config GRKERNSEC_SOCKET_ALL
69178 + bool "Deny any sockets to group"
69179 + depends on GRKERNSEC_SOCKET
69180 + help
69181 + If you say Y here, you will be able to choose a GID of whose users will
69182 + be unable to connect to other hosts from your machine or run server
69183 + applications from your machine. If the sysctl option is enabled, a
69184 + sysctl option with name "socket_all" is created.
69185 +
69186 +config GRKERNSEC_SOCKET_ALL_GID
69187 + int "GID to deny all sockets for"
69188 + depends on GRKERNSEC_SOCKET_ALL
69189 + default 1004
69190 + help
69191 + Here you can choose the GID to disable socket access for. Remember to
69192 + add the users you want socket access disabled for to the GID
69193 + specified here. If the sysctl option is enabled, a sysctl option
69194 + with name "socket_all_gid" is created.
69195 +
69196 +config GRKERNSEC_SOCKET_CLIENT
69197 + bool "Deny client sockets to group"
69198 + depends on GRKERNSEC_SOCKET
69199 + help
69200 + If you say Y here, you will be able to choose a GID of whose users will
69201 + be unable to connect to other hosts from your machine, but will be
69202 + able to run servers. If this option is enabled, all users in the group
69203 + you specify will have to use passive mode when initiating ftp transfers
69204 + from the shell on your machine. If the sysctl option is enabled, a
69205 + sysctl option with name "socket_client" is created.
69206 +
69207 +config GRKERNSEC_SOCKET_CLIENT_GID
69208 + int "GID to deny client sockets for"
69209 + depends on GRKERNSEC_SOCKET_CLIENT
69210 + default 1003
69211 + help
69212 + Here you can choose the GID to disable client socket access for.
69213 + Remember to add the users you want client socket access disabled for to
69214 + the GID specified here. If the sysctl option is enabled, a sysctl
69215 + option with name "socket_client_gid" is created.
69216 +
69217 +config GRKERNSEC_SOCKET_SERVER
69218 + bool "Deny server sockets to group"
69219 + depends on GRKERNSEC_SOCKET
69220 + help
69221 + If you say Y here, you will be able to choose a GID of whose users will
69222 + be unable to run server applications from your machine. If the sysctl
69223 + option is enabled, a sysctl option with name "socket_server" is created.
69224 +
69225 +config GRKERNSEC_SOCKET_SERVER_GID
69226 + int "GID to deny server sockets for"
69227 + depends on GRKERNSEC_SOCKET_SERVER
69228 + default 1002
69229 + help
69230 + Here you can choose the GID to disable server socket access for.
69231 + Remember to add the users you want server socket access disabled for to
69232 + the GID specified here. If the sysctl option is enabled, a sysctl
69233 + option with name "socket_server_gid" is created.
69234 +
69235 +endmenu
69236 +
69237 +menu "Physical Protections"
69238 +depends on GRKERNSEC
69239 +
69240 +config GRKERNSEC_DENYUSB
69241 + bool "Deny new USB connections after toggle"
69242 + default y if GRKERNSEC_CONFIG_AUTO
69243 + depends on SYSCTL && USB_SUPPORT
69244 + help
69245 + If you say Y here, a new sysctl option with name "deny_new_usb"
69246 + will be created. Setting its value to 1 will prevent any new
69247 + USB devices from being recognized by the OS. Any attempted USB
69248 + device insertion will be logged. This option is intended to be
69249 + used against custom USB devices designed to exploit vulnerabilities
69250 + in various USB device drivers.
69251 +
69252 + For greatest effectiveness, this sysctl should be set after any
69253 + relevant init scripts. This option is safe to enable in distros
69254 + as each user can choose whether or not to toggle the sysctl.
69255 +
69256 +config GRKERNSEC_DENYUSB_FORCE
69257 + bool "Reject all USB devices not connected at boot"
69258 + select USB
69259 + depends on GRKERNSEC_DENYUSB
69260 + help
69261 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69262 + that doesn't involve a sysctl entry. This option should only be
69263 + enabled if you're sure you want to deny all new USB connections
69264 + at runtime and don't want to modify init scripts. This should not
69265 + be enabled by distros. It forces the core USB code to be built
69266 + into the kernel image so that all devices connected at boot time
69267 + can be recognized and new USB device connections can be prevented
69268 + prior to init running.
69269 +
69270 +endmenu
69271 +
69272 +menu "Sysctl Support"
69273 +depends on GRKERNSEC && SYSCTL
69274 +
69275 +config GRKERNSEC_SYSCTL
69276 + bool "Sysctl support"
69277 + default y if GRKERNSEC_CONFIG_AUTO
69278 + help
69279 + If you say Y here, you will be able to change the options that
69280 + grsecurity runs with at bootup, without having to recompile your
69281 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69282 + to enable (1) or disable (0) various features. All the sysctl entries
69283 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69284 + All features enabled in the kernel configuration are disabled at boot
69285 + if you do not say Y to the "Turn on features by default" option.
69286 + All options should be set at startup, and the grsec_lock entry should
69287 + be set to a non-zero value after all the options are set.
69288 + *THIS IS EXTREMELY IMPORTANT*
69289 +
69290 +config GRKERNSEC_SYSCTL_DISTRO
69291 + bool "Extra sysctl support for distro makers (READ HELP)"
69292 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69293 + help
69294 + If you say Y here, additional sysctl options will be created
69295 + for features that affect processes running as root. Therefore,
69296 + it is critical when using this option that the grsec_lock entry be
69297 + enabled after boot. Only distros with prebuilt kernel packages
69298 + with this option enabled that can ensure grsec_lock is enabled
69299 + after boot should use this option.
69300 + *Failure to set grsec_lock after boot makes all grsec features
69301 + this option covers useless*
69302 +
69303 + Currently this option creates the following sysctl entries:
69304 + "Disable Privileged I/O": "disable_priv_io"
69305 +
69306 +config GRKERNSEC_SYSCTL_ON
69307 + bool "Turn on features by default"
69308 + default y if GRKERNSEC_CONFIG_AUTO
69309 + depends on GRKERNSEC_SYSCTL
69310 + help
69311 + If you say Y here, instead of having all features enabled in the
69312 + kernel configuration disabled at boot time, the features will be
69313 + enabled at boot time. It is recommended you say Y here unless
69314 + there is some reason you would want all sysctl-tunable features to
69315 + be disabled by default. As mentioned elsewhere, it is important
69316 + to enable the grsec_lock entry once you have finished modifying
69317 + the sysctl entries.
69318 +
69319 +endmenu
69320 +menu "Logging Options"
69321 +depends on GRKERNSEC
69322 +
69323 +config GRKERNSEC_FLOODTIME
69324 + int "Seconds in between log messages (minimum)"
69325 + default 10
69326 + help
69327 + This option allows you to enforce the number of seconds between
69328 + grsecurity log messages. The default should be suitable for most
69329 + people, however, if you choose to change it, choose a value small enough
69330 + to allow informative logs to be produced, but large enough to
69331 + prevent flooding.
69332 +
69333 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69334 + any rate limiting on grsecurity log messages.
69335 +
69336 +config GRKERNSEC_FLOODBURST
69337 + int "Number of messages in a burst (maximum)"
69338 + default 6
69339 + help
69340 + This option allows you to choose the maximum number of messages allowed
69341 + within the flood time interval you chose in a separate option. The
69342 + default should be suitable for most people, however if you find that
69343 + many of your logs are being interpreted as flooding, you may want to
69344 + raise this value.
69345 +
69346 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69347 + any rate limiting on grsecurity log messages.
69348 +
69349 +endmenu
69350 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69351 new file mode 100644
69352 index 0000000..30ababb
69353 --- /dev/null
69354 +++ b/grsecurity/Makefile
69355 @@ -0,0 +1,54 @@
69356 +# grsecurity – access control and security hardening for Linux
69357 +# All code in this directory and various hooks located throughout the Linux kernel are
69358 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69359 +# http://www.grsecurity.net spender@grsecurity.net
69360 +#
69361 +# This program is free software; you can redistribute it and/or
69362 +# modify it under the terms of the GNU General Public License version 2
69363 +# as published by the Free Software Foundation.
69364 +#
69365 +# This program is distributed in the hope that it will be useful,
69366 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69367 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69368 +# GNU General Public License for more details.
69369 +#
69370 +# You should have received a copy of the GNU General Public License
69371 +# along with this program; if not, write to the Free Software
69372 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69373 +
69374 +KBUILD_CFLAGS += -Werror
69375 +
69376 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69377 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69378 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69379 + grsec_usb.o grsec_ipc.o grsec_proc.o
69380 +
69381 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69382 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69383 + gracl_learn.o grsec_log.o gracl_policy.o
69384 +ifdef CONFIG_COMPAT
69385 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69386 +endif
69387 +
69388 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69389 +
69390 +ifdef CONFIG_NET
69391 +obj-y += grsec_sock.o
69392 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69393 +endif
69394 +
69395 +ifndef CONFIG_GRKERNSEC
69396 +obj-y += grsec_disabled.o
69397 +endif
69398 +
69399 +ifdef CONFIG_GRKERNSEC_HIDESYM
69400 +extra-y := grsec_hidesym.o
69401 +$(obj)/grsec_hidesym.o:
69402 + @-chmod -f 500 /boot
69403 + @-chmod -f 500 /lib/modules
69404 + @-chmod -f 500 /lib64/modules
69405 + @-chmod -f 500 /lib32/modules
69406 + @-chmod -f 700 .
69407 + @-chmod -f 700 $(objtree)
69408 + @echo ' grsec: protected kernel image paths'
69409 +endif
69410 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69411 new file mode 100644
69412 index 0000000..6ae3aa0
69413 --- /dev/null
69414 +++ b/grsecurity/gracl.c
69415 @@ -0,0 +1,2703 @@
69416 +#include <linux/kernel.h>
69417 +#include <linux/module.h>
69418 +#include <linux/sched.h>
69419 +#include <linux/mm.h>
69420 +#include <linux/file.h>
69421 +#include <linux/fs.h>
69422 +#include <linux/namei.h>
69423 +#include <linux/mount.h>
69424 +#include <linux/tty.h>
69425 +#include <linux/proc_fs.h>
69426 +#include <linux/lglock.h>
69427 +#include <linux/slab.h>
69428 +#include <linux/vmalloc.h>
69429 +#include <linux/types.h>
69430 +#include <linux/sysctl.h>
69431 +#include <linux/netdevice.h>
69432 +#include <linux/ptrace.h>
69433 +#include <linux/gracl.h>
69434 +#include <linux/gralloc.h>
69435 +#include <linux/security.h>
69436 +#include <linux/grinternal.h>
69437 +#include <linux/pid_namespace.h>
69438 +#include <linux/stop_machine.h>
69439 +#include <linux/fdtable.h>
69440 +#include <linux/percpu.h>
69441 +#include <linux/lglock.h>
69442 +#include <linux/hugetlb.h>
69443 +#include <linux/posix-timers.h>
69444 +#include <linux/prefetch.h>
69445 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69446 +#include <linux/magic.h>
69447 +#include <linux/pagemap.h>
69448 +#include "../fs/btrfs/async-thread.h"
69449 +#include "../fs/btrfs/ctree.h"
69450 +#include "../fs/btrfs/btrfs_inode.h"
69451 +#endif
69452 +#include "../fs/mount.h"
69453 +
69454 +#include <asm/uaccess.h>
69455 +#include <asm/errno.h>
69456 +#include <asm/mman.h>
69457 +
69458 +#define FOR_EACH_ROLE_START(role) \
69459 + role = running_polstate.role_list; \
69460 + while (role) {
69461 +
69462 +#define FOR_EACH_ROLE_END(role) \
69463 + role = role->prev; \
69464 + }
69465 +
69466 +extern struct path gr_real_root;
69467 +
69468 +static struct gr_policy_state running_polstate;
69469 +struct gr_policy_state *polstate = &running_polstate;
69470 +extern struct gr_alloc_state *current_alloc_state;
69471 +
69472 +extern char *gr_shared_page[4];
69473 +DEFINE_RWLOCK(gr_inode_lock);
69474 +
69475 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69476 +
69477 +#ifdef CONFIG_NET
69478 +extern struct vfsmount *sock_mnt;
69479 +#endif
69480 +
69481 +extern struct vfsmount *pipe_mnt;
69482 +extern struct vfsmount *shm_mnt;
69483 +
69484 +#ifdef CONFIG_HUGETLBFS
69485 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69486 +#endif
69487 +
69488 +extern u16 acl_sp_role_value;
69489 +extern struct acl_object_label *fakefs_obj_rw;
69490 +extern struct acl_object_label *fakefs_obj_rwx;
69491 +
69492 +int gr_acl_is_enabled(void)
69493 +{
69494 + return (gr_status & GR_READY);
69495 +}
69496 +
69497 +void gr_enable_rbac_system(void)
69498 +{
69499 + pax_open_kernel();
69500 + gr_status |= GR_READY;
69501 + pax_close_kernel();
69502 +}
69503 +
69504 +int gr_rbac_disable(void *unused)
69505 +{
69506 + pax_open_kernel();
69507 + gr_status &= ~GR_READY;
69508 + pax_close_kernel();
69509 +
69510 + return 0;
69511 +}
69512 +
69513 +static inline dev_t __get_dev(const struct dentry *dentry)
69514 +{
69515 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69516 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69517 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69518 + else
69519 +#endif
69520 + return dentry->d_sb->s_dev;
69521 +}
69522 +
69523 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69524 +{
69525 + return __get_dev(dentry);
69526 +}
69527 +
69528 +static char gr_task_roletype_to_char(struct task_struct *task)
69529 +{
69530 + switch (task->role->roletype &
69531 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69532 + GR_ROLE_SPECIAL)) {
69533 + case GR_ROLE_DEFAULT:
69534 + return 'D';
69535 + case GR_ROLE_USER:
69536 + return 'U';
69537 + case GR_ROLE_GROUP:
69538 + return 'G';
69539 + case GR_ROLE_SPECIAL:
69540 + return 'S';
69541 + }
69542 +
69543 + return 'X';
69544 +}
69545 +
69546 +char gr_roletype_to_char(void)
69547 +{
69548 + return gr_task_roletype_to_char(current);
69549 +}
69550 +
69551 +__inline__ int
69552 +gr_acl_tpe_check(void)
69553 +{
69554 + if (unlikely(!(gr_status & GR_READY)))
69555 + return 0;
69556 + if (current->role->roletype & GR_ROLE_TPE)
69557 + return 1;
69558 + else
69559 + return 0;
69560 +}
69561 +
69562 +int
69563 +gr_handle_rawio(const struct inode *inode)
69564 +{
69565 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69566 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69567 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69568 + !capable(CAP_SYS_RAWIO))
69569 + return 1;
69570 +#endif
69571 + return 0;
69572 +}
69573 +
69574 +int
69575 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69576 +{
69577 + if (likely(lena != lenb))
69578 + return 0;
69579 +
69580 + return !memcmp(a, b, lena);
69581 +}
69582 +
69583 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69584 +{
69585 + *buflen -= namelen;
69586 + if (*buflen < 0)
69587 + return -ENAMETOOLONG;
69588 + *buffer -= namelen;
69589 + memcpy(*buffer, str, namelen);
69590 + return 0;
69591 +}
69592 +
69593 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69594 +{
69595 + return prepend(buffer, buflen, name->name, name->len);
69596 +}
69597 +
69598 +static int prepend_path(const struct path *path, struct path *root,
69599 + char **buffer, int *buflen)
69600 +{
69601 + struct dentry *dentry = path->dentry;
69602 + struct vfsmount *vfsmnt = path->mnt;
69603 + struct mount *mnt = real_mount(vfsmnt);
69604 + bool slash = false;
69605 + int error = 0;
69606 +
69607 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69608 + struct dentry * parent;
69609 +
69610 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69611 + /* Global root? */
69612 + if (!mnt_has_parent(mnt)) {
69613 + goto out;
69614 + }
69615 + dentry = mnt->mnt_mountpoint;
69616 + mnt = mnt->mnt_parent;
69617 + vfsmnt = &mnt->mnt;
69618 + continue;
69619 + }
69620 + parent = dentry->d_parent;
69621 + prefetch(parent);
69622 + spin_lock(&dentry->d_lock);
69623 + error = prepend_name(buffer, buflen, &dentry->d_name);
69624 + spin_unlock(&dentry->d_lock);
69625 + if (!error)
69626 + error = prepend(buffer, buflen, "/", 1);
69627 + if (error)
69628 + break;
69629 +
69630 + slash = true;
69631 + dentry = parent;
69632 + }
69633 +
69634 +out:
69635 + if (!error && !slash)
69636 + error = prepend(buffer, buflen, "/", 1);
69637 +
69638 + return error;
69639 +}
69640 +
69641 +/* this must be called with mount_lock and rename_lock held */
69642 +
69643 +static char *__our_d_path(const struct path *path, struct path *root,
69644 + char *buf, int buflen)
69645 +{
69646 + char *res = buf + buflen;
69647 + int error;
69648 +
69649 + prepend(&res, &buflen, "\0", 1);
69650 + error = prepend_path(path, root, &res, &buflen);
69651 + if (error)
69652 + return ERR_PTR(error);
69653 +
69654 + return res;
69655 +}
69656 +
69657 +static char *
69658 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69659 +{
69660 + char *retval;
69661 +
69662 + retval = __our_d_path(path, root, buf, buflen);
69663 + if (unlikely(IS_ERR(retval)))
69664 + retval = strcpy(buf, "<path too long>");
69665 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69666 + retval[1] = '\0';
69667 +
69668 + return retval;
69669 +}
69670 +
69671 +static char *
69672 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69673 + char *buf, int buflen)
69674 +{
69675 + struct path path;
69676 + char *res;
69677 +
69678 + path.dentry = (struct dentry *)dentry;
69679 + path.mnt = (struct vfsmount *)vfsmnt;
69680 +
69681 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69682 + by the RBAC system */
69683 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69684 +
69685 + return res;
69686 +}
69687 +
69688 +static char *
69689 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69690 + char *buf, int buflen)
69691 +{
69692 + char *res;
69693 + struct path path;
69694 + struct path root;
69695 + struct task_struct *reaper = init_pid_ns.child_reaper;
69696 +
69697 + path.dentry = (struct dentry *)dentry;
69698 + path.mnt = (struct vfsmount *)vfsmnt;
69699 +
69700 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69701 + get_fs_root(reaper->fs, &root);
69702 +
69703 + read_seqlock_excl(&mount_lock);
69704 + write_seqlock(&rename_lock);
69705 + res = gen_full_path(&path, &root, buf, buflen);
69706 + write_sequnlock(&rename_lock);
69707 + read_sequnlock_excl(&mount_lock);
69708 +
69709 + path_put(&root);
69710 + return res;
69711 +}
69712 +
69713 +char *
69714 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69715 +{
69716 + char *ret;
69717 + read_seqlock_excl(&mount_lock);
69718 + write_seqlock(&rename_lock);
69719 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69720 + PAGE_SIZE);
69721 + write_sequnlock(&rename_lock);
69722 + read_sequnlock_excl(&mount_lock);
69723 + return ret;
69724 +}
69725 +
69726 +static char *
69727 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69728 +{
69729 + char *ret;
69730 + char *buf;
69731 + int buflen;
69732 +
69733 + read_seqlock_excl(&mount_lock);
69734 + write_seqlock(&rename_lock);
69735 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69736 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69737 + buflen = (int)(ret - buf);
69738 + if (buflen >= 5)
69739 + prepend(&ret, &buflen, "/proc", 5);
69740 + else
69741 + ret = strcpy(buf, "<path too long>");
69742 + write_sequnlock(&rename_lock);
69743 + read_sequnlock_excl(&mount_lock);
69744 + return ret;
69745 +}
69746 +
69747 +char *
69748 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69749 +{
69750 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69751 + PAGE_SIZE);
69752 +}
69753 +
69754 +char *
69755 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69756 +{
69757 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69758 + PAGE_SIZE);
69759 +}
69760 +
69761 +char *
69762 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69763 +{
69764 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69765 + PAGE_SIZE);
69766 +}
69767 +
69768 +char *
69769 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69770 +{
69771 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69772 + PAGE_SIZE);
69773 +}
69774 +
69775 +char *
69776 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69777 +{
69778 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69779 + PAGE_SIZE);
69780 +}
69781 +
69782 +__inline__ __u32
69783 +to_gr_audit(const __u32 reqmode)
69784 +{
69785 + /* masks off auditable permission flags, then shifts them to create
69786 + auditing flags, and adds the special case of append auditing if
69787 + we're requesting write */
69788 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69789 +}
69790 +
69791 +struct acl_role_label *
69792 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69793 + const gid_t gid)
69794 +{
69795 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69796 + struct acl_role_label *match;
69797 + struct role_allowed_ip *ipp;
69798 + unsigned int x;
69799 + u32 curr_ip = task->signal->saved_ip;
69800 +
69801 + match = state->acl_role_set.r_hash[index];
69802 +
69803 + while (match) {
69804 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69805 + for (x = 0; x < match->domain_child_num; x++) {
69806 + if (match->domain_children[x] == uid)
69807 + goto found;
69808 + }
69809 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69810 + break;
69811 + match = match->next;
69812 + }
69813 +found:
69814 + if (match == NULL) {
69815 + try_group:
69816 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69817 + match = state->acl_role_set.r_hash[index];
69818 +
69819 + while (match) {
69820 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69821 + for (x = 0; x < match->domain_child_num; x++) {
69822 + if (match->domain_children[x] == gid)
69823 + goto found2;
69824 + }
69825 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69826 + break;
69827 + match = match->next;
69828 + }
69829 +found2:
69830 + if (match == NULL)
69831 + match = state->default_role;
69832 + if (match->allowed_ips == NULL)
69833 + return match;
69834 + else {
69835 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69836 + if (likely
69837 + ((ntohl(curr_ip) & ipp->netmask) ==
69838 + (ntohl(ipp->addr) & ipp->netmask)))
69839 + return match;
69840 + }
69841 + match = state->default_role;
69842 + }
69843 + } else if (match->allowed_ips == NULL) {
69844 + return match;
69845 + } else {
69846 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69847 + if (likely
69848 + ((ntohl(curr_ip) & ipp->netmask) ==
69849 + (ntohl(ipp->addr) & ipp->netmask)))
69850 + return match;
69851 + }
69852 + goto try_group;
69853 + }
69854 +
69855 + return match;
69856 +}
69857 +
69858 +static struct acl_role_label *
69859 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69860 + const gid_t gid)
69861 +{
69862 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69863 +}
69864 +
69865 +struct acl_subject_label *
69866 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69867 + const struct acl_role_label *role)
69868 +{
69869 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69870 + struct acl_subject_label *match;
69871 +
69872 + match = role->subj_hash[index];
69873 +
69874 + while (match && (match->inode != ino || match->device != dev ||
69875 + (match->mode & GR_DELETED))) {
69876 + match = match->next;
69877 + }
69878 +
69879 + if (match && !(match->mode & GR_DELETED))
69880 + return match;
69881 + else
69882 + return NULL;
69883 +}
69884 +
69885 +struct acl_subject_label *
69886 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69887 + const struct acl_role_label *role)
69888 +{
69889 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69890 + struct acl_subject_label *match;
69891 +
69892 + match = role->subj_hash[index];
69893 +
69894 + while (match && (match->inode != ino || match->device != dev ||
69895 + !(match->mode & GR_DELETED))) {
69896 + match = match->next;
69897 + }
69898 +
69899 + if (match && (match->mode & GR_DELETED))
69900 + return match;
69901 + else
69902 + return NULL;
69903 +}
69904 +
69905 +static struct acl_object_label *
69906 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
69907 + const struct acl_subject_label *subj)
69908 +{
69909 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69910 + struct acl_object_label *match;
69911 +
69912 + match = subj->obj_hash[index];
69913 +
69914 + while (match && (match->inode != ino || match->device != dev ||
69915 + (match->mode & GR_DELETED))) {
69916 + match = match->next;
69917 + }
69918 +
69919 + if (match && !(match->mode & GR_DELETED))
69920 + return match;
69921 + else
69922 + return NULL;
69923 +}
69924 +
69925 +static struct acl_object_label *
69926 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
69927 + const struct acl_subject_label *subj)
69928 +{
69929 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69930 + struct acl_object_label *match;
69931 +
69932 + match = subj->obj_hash[index];
69933 +
69934 + while (match && (match->inode != ino || match->device != dev ||
69935 + !(match->mode & GR_DELETED))) {
69936 + match = match->next;
69937 + }
69938 +
69939 + if (match && (match->mode & GR_DELETED))
69940 + return match;
69941 +
69942 + match = subj->obj_hash[index];
69943 +
69944 + while (match && (match->inode != ino || match->device != dev ||
69945 + (match->mode & GR_DELETED))) {
69946 + match = match->next;
69947 + }
69948 +
69949 + if (match && !(match->mode & GR_DELETED))
69950 + return match;
69951 + else
69952 + return NULL;
69953 +}
69954 +
69955 +struct name_entry *
69956 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
69957 +{
69958 + unsigned int len = strlen(name);
69959 + unsigned int key = full_name_hash(name, len);
69960 + unsigned int index = key % state->name_set.n_size;
69961 + struct name_entry *match;
69962 +
69963 + match = state->name_set.n_hash[index];
69964 +
69965 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
69966 + match = match->next;
69967 +
69968 + return match;
69969 +}
69970 +
69971 +static struct name_entry *
69972 +lookup_name_entry(const char *name)
69973 +{
69974 + return __lookup_name_entry(&running_polstate, name);
69975 +}
69976 +
69977 +static struct name_entry *
69978 +lookup_name_entry_create(const char *name)
69979 +{
69980 + unsigned int len = strlen(name);
69981 + unsigned int key = full_name_hash(name, len);
69982 + unsigned int index = key % running_polstate.name_set.n_size;
69983 + struct name_entry *match;
69984 +
69985 + match = running_polstate.name_set.n_hash[index];
69986 +
69987 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
69988 + !match->deleted))
69989 + match = match->next;
69990 +
69991 + if (match && match->deleted)
69992 + return match;
69993 +
69994 + match = running_polstate.name_set.n_hash[index];
69995 +
69996 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
69997 + match->deleted))
69998 + match = match->next;
69999 +
70000 + if (match && !match->deleted)
70001 + return match;
70002 + else
70003 + return NULL;
70004 +}
70005 +
70006 +static struct inodev_entry *
70007 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70008 +{
70009 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70010 + struct inodev_entry *match;
70011 +
70012 + match = running_polstate.inodev_set.i_hash[index];
70013 +
70014 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70015 + match = match->next;
70016 +
70017 + return match;
70018 +}
70019 +
70020 +void
70021 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70022 +{
70023 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70024 + state->inodev_set.i_size);
70025 + struct inodev_entry **curr;
70026 +
70027 + entry->prev = NULL;
70028 +
70029 + curr = &state->inodev_set.i_hash[index];
70030 + if (*curr != NULL)
70031 + (*curr)->prev = entry;
70032 +
70033 + entry->next = *curr;
70034 + *curr = entry;
70035 +
70036 + return;
70037 +}
70038 +
70039 +static void
70040 +insert_inodev_entry(struct inodev_entry *entry)
70041 +{
70042 + __insert_inodev_entry(&running_polstate, entry);
70043 +}
70044 +
70045 +void
70046 +insert_acl_obj_label(struct acl_object_label *obj,
70047 + struct acl_subject_label *subj)
70048 +{
70049 + unsigned int index =
70050 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70051 + struct acl_object_label **curr;
70052 +
70053 + obj->prev = NULL;
70054 +
70055 + curr = &subj->obj_hash[index];
70056 + if (*curr != NULL)
70057 + (*curr)->prev = obj;
70058 +
70059 + obj->next = *curr;
70060 + *curr = obj;
70061 +
70062 + return;
70063 +}
70064 +
70065 +void
70066 +insert_acl_subj_label(struct acl_subject_label *obj,
70067 + struct acl_role_label *role)
70068 +{
70069 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70070 + struct acl_subject_label **curr;
70071 +
70072 + obj->prev = NULL;
70073 +
70074 + curr = &role->subj_hash[index];
70075 + if (*curr != NULL)
70076 + (*curr)->prev = obj;
70077 +
70078 + obj->next = *curr;
70079 + *curr = obj;
70080 +
70081 + return;
70082 +}
70083 +
70084 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70085 +
70086 +static int
70087 +glob_match(const char *p, const char *n)
70088 +{
70089 + char c;
70090 +
70091 + while ((c = *p++) != '\0') {
70092 + switch (c) {
70093 + case '?':
70094 + if (*n == '\0')
70095 + return 1;
70096 + else if (*n == '/')
70097 + return 1;
70098 + break;
70099 + case '\\':
70100 + if (*n != c)
70101 + return 1;
70102 + break;
70103 + case '*':
70104 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70105 + if (*n == '/')
70106 + return 1;
70107 + else if (c == '?') {
70108 + if (*n == '\0')
70109 + return 1;
70110 + else
70111 + ++n;
70112 + }
70113 + }
70114 + if (c == '\0') {
70115 + return 0;
70116 + } else {
70117 + const char *endp;
70118 +
70119 + if ((endp = strchr(n, '/')) == NULL)
70120 + endp = n + strlen(n);
70121 +
70122 + if (c == '[') {
70123 + for (--p; n < endp; ++n)
70124 + if (!glob_match(p, n))
70125 + return 0;
70126 + } else if (c == '/') {
70127 + while (*n != '\0' && *n != '/')
70128 + ++n;
70129 + if (*n == '/' && !glob_match(p, n + 1))
70130 + return 0;
70131 + } else {
70132 + for (--p; n < endp; ++n)
70133 + if (*n == c && !glob_match(p, n))
70134 + return 0;
70135 + }
70136 +
70137 + return 1;
70138 + }
70139 + case '[':
70140 + {
70141 + int not;
70142 + char cold;
70143 +
70144 + if (*n == '\0' || *n == '/')
70145 + return 1;
70146 +
70147 + not = (*p == '!' || *p == '^');
70148 + if (not)
70149 + ++p;
70150 +
70151 + c = *p++;
70152 + for (;;) {
70153 + unsigned char fn = (unsigned char)*n;
70154 +
70155 + if (c == '\0')
70156 + return 1;
70157 + else {
70158 + if (c == fn)
70159 + goto matched;
70160 + cold = c;
70161 + c = *p++;
70162 +
70163 + if (c == '-' && *p != ']') {
70164 + unsigned char cend = *p++;
70165 +
70166 + if (cend == '\0')
70167 + return 1;
70168 +
70169 + if (cold <= fn && fn <= cend)
70170 + goto matched;
70171 +
70172 + c = *p++;
70173 + }
70174 + }
70175 +
70176 + if (c == ']')
70177 + break;
70178 + }
70179 + if (!not)
70180 + return 1;
70181 + break;
70182 + matched:
70183 + while (c != ']') {
70184 + if (c == '\0')
70185 + return 1;
70186 +
70187 + c = *p++;
70188 + }
70189 + if (not)
70190 + return 1;
70191 + }
70192 + break;
70193 + default:
70194 + if (c != *n)
70195 + return 1;
70196 + }
70197 +
70198 + ++n;
70199 + }
70200 +
70201 + if (*n == '\0')
70202 + return 0;
70203 +
70204 + if (*n == '/')
70205 + return 0;
70206 +
70207 + return 1;
70208 +}
70209 +
70210 +static struct acl_object_label *
70211 +chk_glob_label(struct acl_object_label *globbed,
70212 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70213 +{
70214 + struct acl_object_label *tmp;
70215 +
70216 + if (*path == NULL)
70217 + *path = gr_to_filename_nolock(dentry, mnt);
70218 +
70219 + tmp = globbed;
70220 +
70221 + while (tmp) {
70222 + if (!glob_match(tmp->filename, *path))
70223 + return tmp;
70224 + tmp = tmp->next;
70225 + }
70226 +
70227 + return NULL;
70228 +}
70229 +
70230 +static struct acl_object_label *
70231 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70232 + const ino_t curr_ino, const dev_t curr_dev,
70233 + const struct acl_subject_label *subj, char **path, const int checkglob)
70234 +{
70235 + struct acl_subject_label *tmpsubj;
70236 + struct acl_object_label *retval;
70237 + struct acl_object_label *retval2;
70238 +
70239 + tmpsubj = (struct acl_subject_label *) subj;
70240 + read_lock(&gr_inode_lock);
70241 + do {
70242 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70243 + if (retval) {
70244 + if (checkglob && retval->globbed) {
70245 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70246 + if (retval2)
70247 + retval = retval2;
70248 + }
70249 + break;
70250 + }
70251 + } while ((tmpsubj = tmpsubj->parent_subject));
70252 + read_unlock(&gr_inode_lock);
70253 +
70254 + return retval;
70255 +}
70256 +
70257 +static __inline__ struct acl_object_label *
70258 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70259 + struct dentry *curr_dentry,
70260 + const struct acl_subject_label *subj, char **path, const int checkglob)
70261 +{
70262 + int newglob = checkglob;
70263 + ino_t inode;
70264 + dev_t device;
70265 +
70266 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70267 + as we don't want a / * rule to match instead of the / object
70268 + don't do this for create lookups that call this function though, since they're looking up
70269 + on the parent and thus need globbing checks on all paths
70270 + */
70271 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70272 + newglob = GR_NO_GLOB;
70273 +
70274 + spin_lock(&curr_dentry->d_lock);
70275 + inode = curr_dentry->d_inode->i_ino;
70276 + device = __get_dev(curr_dentry);
70277 + spin_unlock(&curr_dentry->d_lock);
70278 +
70279 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70280 +}
70281 +
70282 +#ifdef CONFIG_HUGETLBFS
70283 +static inline bool
70284 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70285 +{
70286 + int i;
70287 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70288 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70289 + return true;
70290 + }
70291 +
70292 + return false;
70293 +}
70294 +#endif
70295 +
70296 +static struct acl_object_label *
70297 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70298 + const struct acl_subject_label *subj, char *path, const int checkglob)
70299 +{
70300 + struct dentry *dentry = (struct dentry *) l_dentry;
70301 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70302 + struct mount *real_mnt = real_mount(mnt);
70303 + struct acl_object_label *retval;
70304 + struct dentry *parent;
70305 +
70306 + read_seqlock_excl(&mount_lock);
70307 + write_seqlock(&rename_lock);
70308 +
70309 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70310 +#ifdef CONFIG_NET
70311 + mnt == sock_mnt ||
70312 +#endif
70313 +#ifdef CONFIG_HUGETLBFS
70314 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70315 +#endif
70316 + /* ignore Eric Biederman */
70317 + IS_PRIVATE(l_dentry->d_inode))) {
70318 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70319 + goto out;
70320 + }
70321 +
70322 + for (;;) {
70323 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70324 + break;
70325 +
70326 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70327 + if (!mnt_has_parent(real_mnt))
70328 + break;
70329 +
70330 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70331 + if (retval != NULL)
70332 + goto out;
70333 +
70334 + dentry = real_mnt->mnt_mountpoint;
70335 + real_mnt = real_mnt->mnt_parent;
70336 + mnt = &real_mnt->mnt;
70337 + continue;
70338 + }
70339 +
70340 + parent = dentry->d_parent;
70341 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70342 + if (retval != NULL)
70343 + goto out;
70344 +
70345 + dentry = parent;
70346 + }
70347 +
70348 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70349 +
70350 + /* gr_real_root is pinned so we don't have to hold a reference */
70351 + if (retval == NULL)
70352 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70353 +out:
70354 + write_sequnlock(&rename_lock);
70355 + read_sequnlock_excl(&mount_lock);
70356 +
70357 + BUG_ON(retval == NULL);
70358 +
70359 + return retval;
70360 +}
70361 +
70362 +static __inline__ struct acl_object_label *
70363 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70364 + const struct acl_subject_label *subj)
70365 +{
70366 + char *path = NULL;
70367 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70368 +}
70369 +
70370 +static __inline__ struct acl_object_label *
70371 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70372 + const struct acl_subject_label *subj)
70373 +{
70374 + char *path = NULL;
70375 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70376 +}
70377 +
70378 +static __inline__ struct acl_object_label *
70379 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70380 + const struct acl_subject_label *subj, char *path)
70381 +{
70382 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70383 +}
70384 +
70385 +struct acl_subject_label *
70386 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70387 + const struct acl_role_label *role)
70388 +{
70389 + struct dentry *dentry = (struct dentry *) l_dentry;
70390 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70391 + struct mount *real_mnt = real_mount(mnt);
70392 + struct acl_subject_label *retval;
70393 + struct dentry *parent;
70394 +
70395 + read_seqlock_excl(&mount_lock);
70396 + write_seqlock(&rename_lock);
70397 +
70398 + for (;;) {
70399 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70400 + break;
70401 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70402 + if (!mnt_has_parent(real_mnt))
70403 + break;
70404 +
70405 + spin_lock(&dentry->d_lock);
70406 + read_lock(&gr_inode_lock);
70407 + retval =
70408 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70409 + __get_dev(dentry), role);
70410 + read_unlock(&gr_inode_lock);
70411 + spin_unlock(&dentry->d_lock);
70412 + if (retval != NULL)
70413 + goto out;
70414 +
70415 + dentry = real_mnt->mnt_mountpoint;
70416 + real_mnt = real_mnt->mnt_parent;
70417 + mnt = &real_mnt->mnt;
70418 + continue;
70419 + }
70420 +
70421 + spin_lock(&dentry->d_lock);
70422 + read_lock(&gr_inode_lock);
70423 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70424 + __get_dev(dentry), role);
70425 + read_unlock(&gr_inode_lock);
70426 + parent = dentry->d_parent;
70427 + spin_unlock(&dentry->d_lock);
70428 +
70429 + if (retval != NULL)
70430 + goto out;
70431 +
70432 + dentry = parent;
70433 + }
70434 +
70435 + spin_lock(&dentry->d_lock);
70436 + read_lock(&gr_inode_lock);
70437 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70438 + __get_dev(dentry), role);
70439 + read_unlock(&gr_inode_lock);
70440 + spin_unlock(&dentry->d_lock);
70441 +
70442 + if (unlikely(retval == NULL)) {
70443 + /* gr_real_root is pinned, we don't need to hold a reference */
70444 + read_lock(&gr_inode_lock);
70445 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70446 + __get_dev(gr_real_root.dentry), role);
70447 + read_unlock(&gr_inode_lock);
70448 + }
70449 +out:
70450 + write_sequnlock(&rename_lock);
70451 + read_sequnlock_excl(&mount_lock);
70452 +
70453 + BUG_ON(retval == NULL);
70454 +
70455 + return retval;
70456 +}
70457 +
70458 +void
70459 +assign_special_role(const char *rolename)
70460 +{
70461 + struct acl_object_label *obj;
70462 + struct acl_role_label *r;
70463 + struct acl_role_label *assigned = NULL;
70464 + struct task_struct *tsk;
70465 + struct file *filp;
70466 +
70467 + FOR_EACH_ROLE_START(r)
70468 + if (!strcmp(rolename, r->rolename) &&
70469 + (r->roletype & GR_ROLE_SPECIAL)) {
70470 + assigned = r;
70471 + break;
70472 + }
70473 + FOR_EACH_ROLE_END(r)
70474 +
70475 + if (!assigned)
70476 + return;
70477 +
70478 + read_lock(&tasklist_lock);
70479 + read_lock(&grsec_exec_file_lock);
70480 +
70481 + tsk = current->real_parent;
70482 + if (tsk == NULL)
70483 + goto out_unlock;
70484 +
70485 + filp = tsk->exec_file;
70486 + if (filp == NULL)
70487 + goto out_unlock;
70488 +
70489 + tsk->is_writable = 0;
70490 + tsk->inherited = 0;
70491 +
70492 + tsk->acl_sp_role = 1;
70493 + tsk->acl_role_id = ++acl_sp_role_value;
70494 + tsk->role = assigned;
70495 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70496 +
70497 + /* ignore additional mmap checks for processes that are writable
70498 + by the default ACL */
70499 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70500 + if (unlikely(obj->mode & GR_WRITE))
70501 + tsk->is_writable = 1;
70502 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70503 + if (unlikely(obj->mode & GR_WRITE))
70504 + tsk->is_writable = 1;
70505 +
70506 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70507 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70508 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70509 +#endif
70510 +
70511 +out_unlock:
70512 + read_unlock(&grsec_exec_file_lock);
70513 + read_unlock(&tasklist_lock);
70514 + return;
70515 +}
70516 +
70517 +
70518 +static void
70519 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70520 +{
70521 + struct task_struct *task = current;
70522 + const struct cred *cred = current_cred();
70523 +
70524 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70525 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70526 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70527 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70528 +
70529 + return;
70530 +}
70531 +
70532 +static void
70533 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70534 +{
70535 + struct task_struct *task = current;
70536 + const struct cred *cred = current_cred();
70537 +
70538 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70539 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70540 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70541 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70542 +
70543 + return;
70544 +}
70545 +
70546 +static void
70547 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70548 +{
70549 + struct task_struct *task = current;
70550 + const struct cred *cred = current_cred();
70551 +
70552 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70553 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70554 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70555 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70556 +
70557 + return;
70558 +}
70559 +
70560 +static void
70561 +gr_set_proc_res(struct task_struct *task)
70562 +{
70563 + struct acl_subject_label *proc;
70564 + unsigned short i;
70565 +
70566 + proc = task->acl;
70567 +
70568 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70569 + return;
70570 +
70571 + for (i = 0; i < RLIM_NLIMITS; i++) {
70572 + if (!(proc->resmask & (1U << i)))
70573 + continue;
70574 +
70575 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70576 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70577 +
70578 + if (i == RLIMIT_CPU)
70579 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70580 + }
70581 +
70582 + return;
70583 +}
70584 +
70585 +/* both of the below must be called with
70586 + rcu_read_lock();
70587 + read_lock(&tasklist_lock);
70588 + read_lock(&grsec_exec_file_lock);
70589 +*/
70590 +
70591 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70592 +{
70593 + char *tmpname;
70594 + struct acl_subject_label *tmpsubj;
70595 + struct file *filp;
70596 + struct name_entry *nmatch;
70597 +
70598 + filp = task->exec_file;
70599 + if (filp == NULL)
70600 + return NULL;
70601 +
70602 + /* the following is to apply the correct subject
70603 + on binaries running when the RBAC system
70604 + is enabled, when the binaries have been
70605 + replaced or deleted since their execution
70606 + -----
70607 + when the RBAC system starts, the inode/dev
70608 + from exec_file will be one the RBAC system
70609 + is unaware of. It only knows the inode/dev
70610 + of the present file on disk, or the absence
70611 + of it.
70612 + */
70613 +
70614 + if (filename)
70615 + nmatch = __lookup_name_entry(state, filename);
70616 + else {
70617 + preempt_disable();
70618 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70619 +
70620 + nmatch = __lookup_name_entry(state, tmpname);
70621 + preempt_enable();
70622 + }
70623 + tmpsubj = NULL;
70624 + if (nmatch) {
70625 + if (nmatch->deleted)
70626 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70627 + else
70628 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70629 + }
70630 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70631 + then we fall back to a normal lookup based on the binary's ino/dev
70632 + */
70633 + if (tmpsubj == NULL)
70634 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70635 +
70636 + return tmpsubj;
70637 +}
70638 +
70639 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70640 +{
70641 + return __gr_get_subject_for_task(&running_polstate, task, filename);
70642 +}
70643 +
70644 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70645 +{
70646 + struct acl_object_label *obj;
70647 + struct file *filp;
70648 +
70649 + filp = task->exec_file;
70650 +
70651 + task->acl = subj;
70652 + task->is_writable = 0;
70653 + /* ignore additional mmap checks for processes that are writable
70654 + by the default ACL */
70655 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70656 + if (unlikely(obj->mode & GR_WRITE))
70657 + task->is_writable = 1;
70658 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70659 + if (unlikely(obj->mode & GR_WRITE))
70660 + task->is_writable = 1;
70661 +
70662 + gr_set_proc_res(task);
70663 +
70664 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70665 + 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);
70666 +#endif
70667 +}
70668 +
70669 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70670 +{
70671 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70672 +}
70673 +
70674 +__u32
70675 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70676 + const struct vfsmount * mnt)
70677 +{
70678 + __u32 retval = mode;
70679 + struct acl_subject_label *curracl;
70680 + struct acl_object_label *currobj;
70681 +
70682 + if (unlikely(!(gr_status & GR_READY)))
70683 + return (mode & ~GR_AUDITS);
70684 +
70685 + curracl = current->acl;
70686 +
70687 + currobj = chk_obj_label(dentry, mnt, curracl);
70688 + retval = currobj->mode & mode;
70689 +
70690 + /* if we're opening a specified transfer file for writing
70691 + (e.g. /dev/initctl), then transfer our role to init
70692 + */
70693 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70694 + current->role->roletype & GR_ROLE_PERSIST)) {
70695 + struct task_struct *task = init_pid_ns.child_reaper;
70696 +
70697 + if (task->role != current->role) {
70698 + struct acl_subject_label *subj;
70699 +
70700 + task->acl_sp_role = 0;
70701 + task->acl_role_id = current->acl_role_id;
70702 + task->role = current->role;
70703 + rcu_read_lock();
70704 + read_lock(&grsec_exec_file_lock);
70705 + subj = gr_get_subject_for_task(task, NULL);
70706 + gr_apply_subject_to_task(task, subj);
70707 + read_unlock(&grsec_exec_file_lock);
70708 + rcu_read_unlock();
70709 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70710 + }
70711 + }
70712 +
70713 + if (unlikely
70714 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70715 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70716 + __u32 new_mode = mode;
70717 +
70718 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70719 +
70720 + retval = new_mode;
70721 +
70722 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70723 + new_mode |= GR_INHERIT;
70724 +
70725 + if (!(mode & GR_NOLEARN))
70726 + gr_log_learn(dentry, mnt, new_mode);
70727 + }
70728 +
70729 + return retval;
70730 +}
70731 +
70732 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70733 + const struct dentry *parent,
70734 + const struct vfsmount *mnt)
70735 +{
70736 + struct name_entry *match;
70737 + struct acl_object_label *matchpo;
70738 + struct acl_subject_label *curracl;
70739 + char *path;
70740 +
70741 + if (unlikely(!(gr_status & GR_READY)))
70742 + return NULL;
70743 +
70744 + preempt_disable();
70745 + path = gr_to_filename_rbac(new_dentry, mnt);
70746 + match = lookup_name_entry_create(path);
70747 +
70748 + curracl = current->acl;
70749 +
70750 + if (match) {
70751 + read_lock(&gr_inode_lock);
70752 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70753 + read_unlock(&gr_inode_lock);
70754 +
70755 + if (matchpo) {
70756 + preempt_enable();
70757 + return matchpo;
70758 + }
70759 + }
70760 +
70761 + // lookup parent
70762 +
70763 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70764 +
70765 + preempt_enable();
70766 + return matchpo;
70767 +}
70768 +
70769 +__u32
70770 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70771 + const struct vfsmount * mnt, const __u32 mode)
70772 +{
70773 + struct acl_object_label *matchpo;
70774 + __u32 retval;
70775 +
70776 + if (unlikely(!(gr_status & GR_READY)))
70777 + return (mode & ~GR_AUDITS);
70778 +
70779 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70780 +
70781 + retval = matchpo->mode & mode;
70782 +
70783 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70784 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70785 + __u32 new_mode = mode;
70786 +
70787 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70788 +
70789 + gr_log_learn(new_dentry, mnt, new_mode);
70790 + return new_mode;
70791 + }
70792 +
70793 + return retval;
70794 +}
70795 +
70796 +__u32
70797 +gr_check_link(const struct dentry * new_dentry,
70798 + const struct dentry * parent_dentry,
70799 + const struct vfsmount * parent_mnt,
70800 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70801 +{
70802 + struct acl_object_label *obj;
70803 + __u32 oldmode, newmode;
70804 + __u32 needmode;
70805 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70806 + GR_DELETE | GR_INHERIT;
70807 +
70808 + if (unlikely(!(gr_status & GR_READY)))
70809 + return (GR_CREATE | GR_LINK);
70810 +
70811 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70812 + oldmode = obj->mode;
70813 +
70814 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70815 + newmode = obj->mode;
70816 +
70817 + needmode = newmode & checkmodes;
70818 +
70819 + // old name for hardlink must have at least the permissions of the new name
70820 + if ((oldmode & needmode) != needmode)
70821 + goto bad;
70822 +
70823 + // if old name had restrictions/auditing, make sure the new name does as well
70824 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70825 +
70826 + // don't allow hardlinking of suid/sgid/fcapped files without permission
70827 + if (is_privileged_binary(old_dentry))
70828 + needmode |= GR_SETID;
70829 +
70830 + if ((newmode & needmode) != needmode)
70831 + goto bad;
70832 +
70833 + // enforce minimum permissions
70834 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70835 + return newmode;
70836 +bad:
70837 + needmode = oldmode;
70838 + if (is_privileged_binary(old_dentry))
70839 + needmode |= GR_SETID;
70840 +
70841 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70842 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70843 + return (GR_CREATE | GR_LINK);
70844 + } else if (newmode & GR_SUPPRESS)
70845 + return GR_SUPPRESS;
70846 + else
70847 + return 0;
70848 +}
70849 +
70850 +int
70851 +gr_check_hidden_task(const struct task_struct *task)
70852 +{
70853 + if (unlikely(!(gr_status & GR_READY)))
70854 + return 0;
70855 +
70856 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70857 + return 1;
70858 +
70859 + return 0;
70860 +}
70861 +
70862 +int
70863 +gr_check_protected_task(const struct task_struct *task)
70864 +{
70865 + if (unlikely(!(gr_status & GR_READY) || !task))
70866 + return 0;
70867 +
70868 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70869 + task->acl != current->acl)
70870 + return 1;
70871 +
70872 + return 0;
70873 +}
70874 +
70875 +int
70876 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70877 +{
70878 + struct task_struct *p;
70879 + int ret = 0;
70880 +
70881 + if (unlikely(!(gr_status & GR_READY) || !pid))
70882 + return ret;
70883 +
70884 + read_lock(&tasklist_lock);
70885 + do_each_pid_task(pid, type, p) {
70886 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70887 + p->acl != current->acl) {
70888 + ret = 1;
70889 + goto out;
70890 + }
70891 + } while_each_pid_task(pid, type, p);
70892 +out:
70893 + read_unlock(&tasklist_lock);
70894 +
70895 + return ret;
70896 +}
70897 +
70898 +void
70899 +gr_copy_label(struct task_struct *tsk)
70900 +{
70901 + struct task_struct *p = current;
70902 +
70903 + tsk->inherited = p->inherited;
70904 + tsk->acl_sp_role = 0;
70905 + tsk->acl_role_id = p->acl_role_id;
70906 + tsk->acl = p->acl;
70907 + tsk->role = p->role;
70908 + tsk->signal->used_accept = 0;
70909 + tsk->signal->curr_ip = p->signal->curr_ip;
70910 + tsk->signal->saved_ip = p->signal->saved_ip;
70911 + if (p->exec_file)
70912 + get_file(p->exec_file);
70913 + tsk->exec_file = p->exec_file;
70914 + tsk->is_writable = p->is_writable;
70915 + if (unlikely(p->signal->used_accept)) {
70916 + p->signal->curr_ip = 0;
70917 + p->signal->saved_ip = 0;
70918 + }
70919 +
70920 + return;
70921 +}
70922 +
70923 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
70924 +
70925 +int
70926 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70927 +{
70928 + unsigned int i;
70929 + __u16 num;
70930 + uid_t *uidlist;
70931 + uid_t curuid;
70932 + int realok = 0;
70933 + int effectiveok = 0;
70934 + int fsok = 0;
70935 + uid_t globalreal, globaleffective, globalfs;
70936 +
70937 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
70938 + struct user_struct *user;
70939 +
70940 + if (!uid_valid(real))
70941 + goto skipit;
70942 +
70943 + /* find user based on global namespace */
70944 +
70945 + globalreal = GR_GLOBAL_UID(real);
70946 +
70947 + user = find_user(make_kuid(&init_user_ns, globalreal));
70948 + if (user == NULL)
70949 + goto skipit;
70950 +
70951 + if (gr_process_kernel_setuid_ban(user)) {
70952 + /* for find_user */
70953 + free_uid(user);
70954 + return 1;
70955 + }
70956 +
70957 + /* for find_user */
70958 + free_uid(user);
70959 +
70960 +skipit:
70961 +#endif
70962 +
70963 + if (unlikely(!(gr_status & GR_READY)))
70964 + return 0;
70965 +
70966 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70967 + gr_log_learn_uid_change(real, effective, fs);
70968 +
70969 + num = current->acl->user_trans_num;
70970 + uidlist = current->acl->user_transitions;
70971 +
70972 + if (uidlist == NULL)
70973 + return 0;
70974 +
70975 + if (!uid_valid(real)) {
70976 + realok = 1;
70977 + globalreal = (uid_t)-1;
70978 + } else {
70979 + globalreal = GR_GLOBAL_UID(real);
70980 + }
70981 + if (!uid_valid(effective)) {
70982 + effectiveok = 1;
70983 + globaleffective = (uid_t)-1;
70984 + } else {
70985 + globaleffective = GR_GLOBAL_UID(effective);
70986 + }
70987 + if (!uid_valid(fs)) {
70988 + fsok = 1;
70989 + globalfs = (uid_t)-1;
70990 + } else {
70991 + globalfs = GR_GLOBAL_UID(fs);
70992 + }
70993 +
70994 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
70995 + for (i = 0; i < num; i++) {
70996 + curuid = uidlist[i];
70997 + if (globalreal == curuid)
70998 + realok = 1;
70999 + if (globaleffective == curuid)
71000 + effectiveok = 1;
71001 + if (globalfs == curuid)
71002 + fsok = 1;
71003 + }
71004 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71005 + for (i = 0; i < num; i++) {
71006 + curuid = uidlist[i];
71007 + if (globalreal == curuid)
71008 + break;
71009 + if (globaleffective == curuid)
71010 + break;
71011 + if (globalfs == curuid)
71012 + break;
71013 + }
71014 + /* not in deny list */
71015 + if (i == num) {
71016 + realok = 1;
71017 + effectiveok = 1;
71018 + fsok = 1;
71019 + }
71020 + }
71021 +
71022 + if (realok && effectiveok && fsok)
71023 + return 0;
71024 + else {
71025 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71026 + return 1;
71027 + }
71028 +}
71029 +
71030 +int
71031 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71032 +{
71033 + unsigned int i;
71034 + __u16 num;
71035 + gid_t *gidlist;
71036 + gid_t curgid;
71037 + int realok = 0;
71038 + int effectiveok = 0;
71039 + int fsok = 0;
71040 + gid_t globalreal, globaleffective, globalfs;
71041 +
71042 + if (unlikely(!(gr_status & GR_READY)))
71043 + return 0;
71044 +
71045 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71046 + gr_log_learn_gid_change(real, effective, fs);
71047 +
71048 + num = current->acl->group_trans_num;
71049 + gidlist = current->acl->group_transitions;
71050 +
71051 + if (gidlist == NULL)
71052 + return 0;
71053 +
71054 + if (!gid_valid(real)) {
71055 + realok = 1;
71056 + globalreal = (gid_t)-1;
71057 + } else {
71058 + globalreal = GR_GLOBAL_GID(real);
71059 + }
71060 + if (!gid_valid(effective)) {
71061 + effectiveok = 1;
71062 + globaleffective = (gid_t)-1;
71063 + } else {
71064 + globaleffective = GR_GLOBAL_GID(effective);
71065 + }
71066 + if (!gid_valid(fs)) {
71067 + fsok = 1;
71068 + globalfs = (gid_t)-1;
71069 + } else {
71070 + globalfs = GR_GLOBAL_GID(fs);
71071 + }
71072 +
71073 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71074 + for (i = 0; i < num; i++) {
71075 + curgid = gidlist[i];
71076 + if (globalreal == curgid)
71077 + realok = 1;
71078 + if (globaleffective == curgid)
71079 + effectiveok = 1;
71080 + if (globalfs == curgid)
71081 + fsok = 1;
71082 + }
71083 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71084 + for (i = 0; i < num; i++) {
71085 + curgid = gidlist[i];
71086 + if (globalreal == curgid)
71087 + break;
71088 + if (globaleffective == curgid)
71089 + break;
71090 + if (globalfs == curgid)
71091 + break;
71092 + }
71093 + /* not in deny list */
71094 + if (i == num) {
71095 + realok = 1;
71096 + effectiveok = 1;
71097 + fsok = 1;
71098 + }
71099 + }
71100 +
71101 + if (realok && effectiveok && fsok)
71102 + return 0;
71103 + else {
71104 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71105 + return 1;
71106 + }
71107 +}
71108 +
71109 +extern int gr_acl_is_capable(const int cap);
71110 +
71111 +void
71112 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71113 +{
71114 + struct acl_role_label *role = task->role;
71115 + struct acl_subject_label *subj = NULL;
71116 + struct acl_object_label *obj;
71117 + struct file *filp;
71118 + uid_t uid;
71119 + gid_t gid;
71120 +
71121 + if (unlikely(!(gr_status & GR_READY)))
71122 + return;
71123 +
71124 + uid = GR_GLOBAL_UID(kuid);
71125 + gid = GR_GLOBAL_GID(kgid);
71126 +
71127 + filp = task->exec_file;
71128 +
71129 + /* kernel process, we'll give them the kernel role */
71130 + if (unlikely(!filp)) {
71131 + task->role = running_polstate.kernel_role;
71132 + task->acl = running_polstate.kernel_role->root_label;
71133 + return;
71134 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71135 + /* save the current ip at time of role lookup so that the proper
71136 + IP will be learned for role_allowed_ip */
71137 + task->signal->saved_ip = task->signal->curr_ip;
71138 + role = lookup_acl_role_label(task, uid, gid);
71139 + }
71140 +
71141 + /* don't change the role if we're not a privileged process */
71142 + if (role && task->role != role &&
71143 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71144 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71145 + return;
71146 +
71147 + /* perform subject lookup in possibly new role
71148 + we can use this result below in the case where role == task->role
71149 + */
71150 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71151 +
71152 + /* if we changed uid/gid, but result in the same role
71153 + and are using inheritance, don't lose the inherited subject
71154 + if current subject is other than what normal lookup
71155 + would result in, we arrived via inheritance, don't
71156 + lose subject
71157 + */
71158 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71159 + (subj == task->acl)))
71160 + task->acl = subj;
71161 +
71162 + /* leave task->inherited unaffected */
71163 +
71164 + task->role = role;
71165 +
71166 + task->is_writable = 0;
71167 +
71168 + /* ignore additional mmap checks for processes that are writable
71169 + by the default ACL */
71170 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71171 + if (unlikely(obj->mode & GR_WRITE))
71172 + task->is_writable = 1;
71173 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71174 + if (unlikely(obj->mode & GR_WRITE))
71175 + task->is_writable = 1;
71176 +
71177 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71178 + 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);
71179 +#endif
71180 +
71181 + gr_set_proc_res(task);
71182 +
71183 + return;
71184 +}
71185 +
71186 +int
71187 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71188 + const int unsafe_flags)
71189 +{
71190 + struct task_struct *task = current;
71191 + struct acl_subject_label *newacl;
71192 + struct acl_object_label *obj;
71193 + __u32 retmode;
71194 +
71195 + if (unlikely(!(gr_status & GR_READY)))
71196 + return 0;
71197 +
71198 + newacl = chk_subj_label(dentry, mnt, task->role);
71199 +
71200 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71201 + did an exec
71202 + */
71203 + rcu_read_lock();
71204 + read_lock(&tasklist_lock);
71205 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71206 + (task->parent->acl->mode & GR_POVERRIDE))) {
71207 + read_unlock(&tasklist_lock);
71208 + rcu_read_unlock();
71209 + goto skip_check;
71210 + }
71211 + read_unlock(&tasklist_lock);
71212 + rcu_read_unlock();
71213 +
71214 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71215 + !(task->role->roletype & GR_ROLE_GOD) &&
71216 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71217 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71218 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71219 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71220 + else
71221 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71222 + return -EACCES;
71223 + }
71224 +
71225 +skip_check:
71226 +
71227 + obj = chk_obj_label(dentry, mnt, task->acl);
71228 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71229 +
71230 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71231 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71232 + if (obj->nested)
71233 + task->acl = obj->nested;
71234 + else
71235 + task->acl = newacl;
71236 + task->inherited = 0;
71237 + } else {
71238 + task->inherited = 1;
71239 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71240 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71241 + }
71242 +
71243 + task->is_writable = 0;
71244 +
71245 + /* ignore additional mmap checks for processes that are writable
71246 + by the default ACL */
71247 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71248 + if (unlikely(obj->mode & GR_WRITE))
71249 + task->is_writable = 1;
71250 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71251 + if (unlikely(obj->mode & GR_WRITE))
71252 + task->is_writable = 1;
71253 +
71254 + gr_set_proc_res(task);
71255 +
71256 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71257 + 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);
71258 +#endif
71259 + return 0;
71260 +}
71261 +
71262 +/* always called with valid inodev ptr */
71263 +static void
71264 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71265 +{
71266 + struct acl_object_label *matchpo;
71267 + struct acl_subject_label *matchps;
71268 + struct acl_subject_label *subj;
71269 + struct acl_role_label *role;
71270 + unsigned int x;
71271 +
71272 + FOR_EACH_ROLE_START(role)
71273 + FOR_EACH_SUBJECT_START(role, subj, x)
71274 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71275 + matchpo->mode |= GR_DELETED;
71276 + FOR_EACH_SUBJECT_END(subj,x)
71277 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71278 + /* nested subjects aren't in the role's subj_hash table */
71279 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71280 + matchpo->mode |= GR_DELETED;
71281 + FOR_EACH_NESTED_SUBJECT_END(subj)
71282 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71283 + matchps->mode |= GR_DELETED;
71284 + FOR_EACH_ROLE_END(role)
71285 +
71286 + inodev->nentry->deleted = 1;
71287 +
71288 + return;
71289 +}
71290 +
71291 +void
71292 +gr_handle_delete(const ino_t ino, const dev_t dev)
71293 +{
71294 + struct inodev_entry *inodev;
71295 +
71296 + if (unlikely(!(gr_status & GR_READY)))
71297 + return;
71298 +
71299 + write_lock(&gr_inode_lock);
71300 + inodev = lookup_inodev_entry(ino, dev);
71301 + if (inodev != NULL)
71302 + do_handle_delete(inodev, ino, dev);
71303 + write_unlock(&gr_inode_lock);
71304 +
71305 + return;
71306 +}
71307 +
71308 +static void
71309 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71310 + const ino_t newinode, const dev_t newdevice,
71311 + struct acl_subject_label *subj)
71312 +{
71313 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71314 + struct acl_object_label *match;
71315 +
71316 + match = subj->obj_hash[index];
71317 +
71318 + while (match && (match->inode != oldinode ||
71319 + match->device != olddevice ||
71320 + !(match->mode & GR_DELETED)))
71321 + match = match->next;
71322 +
71323 + if (match && (match->inode == oldinode)
71324 + && (match->device == olddevice)
71325 + && (match->mode & GR_DELETED)) {
71326 + if (match->prev == NULL) {
71327 + subj->obj_hash[index] = match->next;
71328 + if (match->next != NULL)
71329 + match->next->prev = NULL;
71330 + } else {
71331 + match->prev->next = match->next;
71332 + if (match->next != NULL)
71333 + match->next->prev = match->prev;
71334 + }
71335 + match->prev = NULL;
71336 + match->next = NULL;
71337 + match->inode = newinode;
71338 + match->device = newdevice;
71339 + match->mode &= ~GR_DELETED;
71340 +
71341 + insert_acl_obj_label(match, subj);
71342 + }
71343 +
71344 + return;
71345 +}
71346 +
71347 +static void
71348 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71349 + const ino_t newinode, const dev_t newdevice,
71350 + struct acl_role_label *role)
71351 +{
71352 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71353 + struct acl_subject_label *match;
71354 +
71355 + match = role->subj_hash[index];
71356 +
71357 + while (match && (match->inode != oldinode ||
71358 + match->device != olddevice ||
71359 + !(match->mode & GR_DELETED)))
71360 + match = match->next;
71361 +
71362 + if (match && (match->inode == oldinode)
71363 + && (match->device == olddevice)
71364 + && (match->mode & GR_DELETED)) {
71365 + if (match->prev == NULL) {
71366 + role->subj_hash[index] = match->next;
71367 + if (match->next != NULL)
71368 + match->next->prev = NULL;
71369 + } else {
71370 + match->prev->next = match->next;
71371 + if (match->next != NULL)
71372 + match->next->prev = match->prev;
71373 + }
71374 + match->prev = NULL;
71375 + match->next = NULL;
71376 + match->inode = newinode;
71377 + match->device = newdevice;
71378 + match->mode &= ~GR_DELETED;
71379 +
71380 + insert_acl_subj_label(match, role);
71381 + }
71382 +
71383 + return;
71384 +}
71385 +
71386 +static void
71387 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71388 + const ino_t newinode, const dev_t newdevice)
71389 +{
71390 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71391 + struct inodev_entry *match;
71392 +
71393 + match = running_polstate.inodev_set.i_hash[index];
71394 +
71395 + while (match && (match->nentry->inode != oldinode ||
71396 + match->nentry->device != olddevice || !match->nentry->deleted))
71397 + match = match->next;
71398 +
71399 + if (match && (match->nentry->inode == oldinode)
71400 + && (match->nentry->device == olddevice) &&
71401 + match->nentry->deleted) {
71402 + if (match->prev == NULL) {
71403 + running_polstate.inodev_set.i_hash[index] = match->next;
71404 + if (match->next != NULL)
71405 + match->next->prev = NULL;
71406 + } else {
71407 + match->prev->next = match->next;
71408 + if (match->next != NULL)
71409 + match->next->prev = match->prev;
71410 + }
71411 + match->prev = NULL;
71412 + match->next = NULL;
71413 + match->nentry->inode = newinode;
71414 + match->nentry->device = newdevice;
71415 + match->nentry->deleted = 0;
71416 +
71417 + insert_inodev_entry(match);
71418 + }
71419 +
71420 + return;
71421 +}
71422 +
71423 +static void
71424 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71425 +{
71426 + struct acl_subject_label *subj;
71427 + struct acl_role_label *role;
71428 + unsigned int x;
71429 +
71430 + FOR_EACH_ROLE_START(role)
71431 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71432 +
71433 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71434 + if ((subj->inode == ino) && (subj->device == dev)) {
71435 + subj->inode = ino;
71436 + subj->device = dev;
71437 + }
71438 + /* nested subjects aren't in the role's subj_hash table */
71439 + update_acl_obj_label(matchn->inode, matchn->device,
71440 + ino, dev, subj);
71441 + FOR_EACH_NESTED_SUBJECT_END(subj)
71442 + FOR_EACH_SUBJECT_START(role, subj, x)
71443 + update_acl_obj_label(matchn->inode, matchn->device,
71444 + ino, dev, subj);
71445 + FOR_EACH_SUBJECT_END(subj,x)
71446 + FOR_EACH_ROLE_END(role)
71447 +
71448 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71449 +
71450 + return;
71451 +}
71452 +
71453 +static void
71454 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71455 + const struct vfsmount *mnt)
71456 +{
71457 + ino_t ino = dentry->d_inode->i_ino;
71458 + dev_t dev = __get_dev(dentry);
71459 +
71460 + __do_handle_create(matchn, ino, dev);
71461 +
71462 + return;
71463 +}
71464 +
71465 +void
71466 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71467 +{
71468 + struct name_entry *matchn;
71469 +
71470 + if (unlikely(!(gr_status & GR_READY)))
71471 + return;
71472 +
71473 + preempt_disable();
71474 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71475 +
71476 + if (unlikely((unsigned long)matchn)) {
71477 + write_lock(&gr_inode_lock);
71478 + do_handle_create(matchn, dentry, mnt);
71479 + write_unlock(&gr_inode_lock);
71480 + }
71481 + preempt_enable();
71482 +
71483 + return;
71484 +}
71485 +
71486 +void
71487 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71488 +{
71489 + struct name_entry *matchn;
71490 +
71491 + if (unlikely(!(gr_status & GR_READY)))
71492 + return;
71493 +
71494 + preempt_disable();
71495 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71496 +
71497 + if (unlikely((unsigned long)matchn)) {
71498 + write_lock(&gr_inode_lock);
71499 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71500 + write_unlock(&gr_inode_lock);
71501 + }
71502 + preempt_enable();
71503 +
71504 + return;
71505 +}
71506 +
71507 +void
71508 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71509 + struct dentry *old_dentry,
71510 + struct dentry *new_dentry,
71511 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71512 +{
71513 + struct name_entry *matchn;
71514 + struct name_entry *matchn2 = NULL;
71515 + struct inodev_entry *inodev;
71516 + struct inode *inode = new_dentry->d_inode;
71517 + ino_t old_ino = old_dentry->d_inode->i_ino;
71518 + dev_t old_dev = __get_dev(old_dentry);
71519 + unsigned int exchange = flags & RENAME_EXCHANGE;
71520 +
71521 + /* vfs_rename swaps the name and parent link for old_dentry and
71522 + new_dentry
71523 + at this point, old_dentry has the new name, parent link, and inode
71524 + for the renamed file
71525 + if a file is being replaced by a rename, new_dentry has the inode
71526 + and name for the replaced file
71527 + */
71528 +
71529 + if (unlikely(!(gr_status & GR_READY)))
71530 + return;
71531 +
71532 + preempt_disable();
71533 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71534 +
71535 + /* exchange cases:
71536 + a filename exists for the source, but not dest
71537 + do a recreate on source
71538 + a filename exists for the dest, but not source
71539 + do a recreate on dest
71540 + a filename exists for both source and dest
71541 + delete source and dest, then create source and dest
71542 + a filename exists for neither source nor dest
71543 + no updates needed
71544 +
71545 + the name entry lookups get us the old inode/dev associated with
71546 + each name, so do the deletes first (if possible) so that when
71547 + we do the create, we pick up on the right entries
71548 + */
71549 +
71550 + if (exchange)
71551 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71552 +
71553 + /* we wouldn't have to check d_inode if it weren't for
71554 + NFS silly-renaming
71555 + */
71556 +
71557 + write_lock(&gr_inode_lock);
71558 + if (unlikely((replace || exchange) && inode)) {
71559 + ino_t new_ino = inode->i_ino;
71560 + dev_t new_dev = __get_dev(new_dentry);
71561 +
71562 + inodev = lookup_inodev_entry(new_ino, new_dev);
71563 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71564 + do_handle_delete(inodev, new_ino, new_dev);
71565 + }
71566 +
71567 + inodev = lookup_inodev_entry(old_ino, old_dev);
71568 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71569 + do_handle_delete(inodev, old_ino, old_dev);
71570 +
71571 + if (unlikely(matchn != NULL))
71572 + do_handle_create(matchn, old_dentry, mnt);
71573 +
71574 + if (unlikely(matchn2 != NULL))
71575 + do_handle_create(matchn2, new_dentry, mnt);
71576 +
71577 + write_unlock(&gr_inode_lock);
71578 + preempt_enable();
71579 +
71580 + return;
71581 +}
71582 +
71583 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71584 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71585 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71586 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71587 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71588 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71589 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71590 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71591 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71592 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71593 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71594 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71595 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71596 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71597 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71598 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71599 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71600 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71601 +};
71602 +
71603 +void
71604 +gr_learn_resource(const struct task_struct *task,
71605 + const int res, const unsigned long wanted, const int gt)
71606 +{
71607 + struct acl_subject_label *acl;
71608 + const struct cred *cred;
71609 +
71610 + if (unlikely((gr_status & GR_READY) &&
71611 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71612 + goto skip_reslog;
71613 +
71614 + gr_log_resource(task, res, wanted, gt);
71615 +skip_reslog:
71616 +
71617 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71618 + return;
71619 +
71620 + acl = task->acl;
71621 +
71622 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71623 + !(acl->resmask & (1U << (unsigned short) res))))
71624 + return;
71625 +
71626 + if (wanted >= acl->res[res].rlim_cur) {
71627 + unsigned long res_add;
71628 +
71629 + res_add = wanted + res_learn_bumps[res];
71630 +
71631 + acl->res[res].rlim_cur = res_add;
71632 +
71633 + if (wanted > acl->res[res].rlim_max)
71634 + acl->res[res].rlim_max = res_add;
71635 +
71636 + /* only log the subject filename, since resource logging is supported for
71637 + single-subject learning only */
71638 + rcu_read_lock();
71639 + cred = __task_cred(task);
71640 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71641 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71642 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71643 + "", (unsigned long) res, &task->signal->saved_ip);
71644 + rcu_read_unlock();
71645 + }
71646 +
71647 + return;
71648 +}
71649 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71650 +#endif
71651 +
71652 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71653 +void
71654 +pax_set_initial_flags(struct linux_binprm *bprm)
71655 +{
71656 + struct task_struct *task = current;
71657 + struct acl_subject_label *proc;
71658 + unsigned long flags;
71659 +
71660 + if (unlikely(!(gr_status & GR_READY)))
71661 + return;
71662 +
71663 + flags = pax_get_flags(task);
71664 +
71665 + proc = task->acl;
71666 +
71667 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71668 + flags &= ~MF_PAX_PAGEEXEC;
71669 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71670 + flags &= ~MF_PAX_SEGMEXEC;
71671 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71672 + flags &= ~MF_PAX_RANDMMAP;
71673 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71674 + flags &= ~MF_PAX_EMUTRAMP;
71675 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71676 + flags &= ~MF_PAX_MPROTECT;
71677 +
71678 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71679 + flags |= MF_PAX_PAGEEXEC;
71680 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71681 + flags |= MF_PAX_SEGMEXEC;
71682 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71683 + flags |= MF_PAX_RANDMMAP;
71684 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71685 + flags |= MF_PAX_EMUTRAMP;
71686 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71687 + flags |= MF_PAX_MPROTECT;
71688 +
71689 + pax_set_flags(task, flags);
71690 +
71691 + return;
71692 +}
71693 +#endif
71694 +
71695 +int
71696 +gr_handle_proc_ptrace(struct task_struct *task)
71697 +{
71698 + struct file *filp;
71699 + struct task_struct *tmp = task;
71700 + struct task_struct *curtemp = current;
71701 + __u32 retmode;
71702 +
71703 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71704 + if (unlikely(!(gr_status & GR_READY)))
71705 + return 0;
71706 +#endif
71707 +
71708 + read_lock(&tasklist_lock);
71709 + read_lock(&grsec_exec_file_lock);
71710 + filp = task->exec_file;
71711 +
71712 + while (task_pid_nr(tmp) > 0) {
71713 + if (tmp == curtemp)
71714 + break;
71715 + tmp = tmp->real_parent;
71716 + }
71717 +
71718 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71719 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71720 + read_unlock(&grsec_exec_file_lock);
71721 + read_unlock(&tasklist_lock);
71722 + return 1;
71723 + }
71724 +
71725 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71726 + if (!(gr_status & GR_READY)) {
71727 + read_unlock(&grsec_exec_file_lock);
71728 + read_unlock(&tasklist_lock);
71729 + return 0;
71730 + }
71731 +#endif
71732 +
71733 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71734 + read_unlock(&grsec_exec_file_lock);
71735 + read_unlock(&tasklist_lock);
71736 +
71737 + if (retmode & GR_NOPTRACE)
71738 + return 1;
71739 +
71740 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71741 + && (current->acl != task->acl || (current->acl != current->role->root_label
71742 + && task_pid_nr(current) != task_pid_nr(task))))
71743 + return 1;
71744 +
71745 + return 0;
71746 +}
71747 +
71748 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71749 +{
71750 + if (unlikely(!(gr_status & GR_READY)))
71751 + return;
71752 +
71753 + if (!(current->role->roletype & GR_ROLE_GOD))
71754 + return;
71755 +
71756 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71757 + p->role->rolename, gr_task_roletype_to_char(p),
71758 + p->acl->filename);
71759 +}
71760 +
71761 +int
71762 +gr_handle_ptrace(struct task_struct *task, const long request)
71763 +{
71764 + struct task_struct *tmp = task;
71765 + struct task_struct *curtemp = current;
71766 + __u32 retmode;
71767 +
71768 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71769 + if (unlikely(!(gr_status & GR_READY)))
71770 + return 0;
71771 +#endif
71772 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71773 + read_lock(&tasklist_lock);
71774 + while (task_pid_nr(tmp) > 0) {
71775 + if (tmp == curtemp)
71776 + break;
71777 + tmp = tmp->real_parent;
71778 + }
71779 +
71780 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71781 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71782 + read_unlock(&tasklist_lock);
71783 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71784 + return 1;
71785 + }
71786 + read_unlock(&tasklist_lock);
71787 + }
71788 +
71789 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71790 + if (!(gr_status & GR_READY))
71791 + return 0;
71792 +#endif
71793 +
71794 + read_lock(&grsec_exec_file_lock);
71795 + if (unlikely(!task->exec_file)) {
71796 + read_unlock(&grsec_exec_file_lock);
71797 + return 0;
71798 + }
71799 +
71800 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71801 + read_unlock(&grsec_exec_file_lock);
71802 +
71803 + if (retmode & GR_NOPTRACE) {
71804 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71805 + return 1;
71806 + }
71807 +
71808 + if (retmode & GR_PTRACERD) {
71809 + switch (request) {
71810 + case PTRACE_SEIZE:
71811 + case PTRACE_POKETEXT:
71812 + case PTRACE_POKEDATA:
71813 + case PTRACE_POKEUSR:
71814 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71815 + case PTRACE_SETREGS:
71816 + case PTRACE_SETFPREGS:
71817 +#endif
71818 +#ifdef CONFIG_X86
71819 + case PTRACE_SETFPXREGS:
71820 +#endif
71821 +#ifdef CONFIG_ALTIVEC
71822 + case PTRACE_SETVRREGS:
71823 +#endif
71824 + return 1;
71825 + default:
71826 + return 0;
71827 + }
71828 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
71829 + !(current->role->roletype & GR_ROLE_GOD) &&
71830 + (current->acl != task->acl)) {
71831 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71832 + return 1;
71833 + }
71834 +
71835 + return 0;
71836 +}
71837 +
71838 +static int is_writable_mmap(const struct file *filp)
71839 +{
71840 + struct task_struct *task = current;
71841 + struct acl_object_label *obj, *obj2;
71842 +
71843 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71844 + !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))) {
71845 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71846 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71847 + task->role->root_label);
71848 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71849 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71850 + return 1;
71851 + }
71852 + }
71853 + return 0;
71854 +}
71855 +
71856 +int
71857 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71858 +{
71859 + __u32 mode;
71860 +
71861 + if (unlikely(!file || !(prot & PROT_EXEC)))
71862 + return 1;
71863 +
71864 + if (is_writable_mmap(file))
71865 + return 0;
71866 +
71867 + mode =
71868 + gr_search_file(file->f_path.dentry,
71869 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71870 + file->f_path.mnt);
71871 +
71872 + if (!gr_tpe_allow(file))
71873 + return 0;
71874 +
71875 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71876 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71877 + return 0;
71878 + } else if (unlikely(!(mode & GR_EXEC))) {
71879 + return 0;
71880 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71881 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71882 + return 1;
71883 + }
71884 +
71885 + return 1;
71886 +}
71887 +
71888 +int
71889 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71890 +{
71891 + __u32 mode;
71892 +
71893 + if (unlikely(!file || !(prot & PROT_EXEC)))
71894 + return 1;
71895 +
71896 + if (is_writable_mmap(file))
71897 + return 0;
71898 +
71899 + mode =
71900 + gr_search_file(file->f_path.dentry,
71901 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71902 + file->f_path.mnt);
71903 +
71904 + if (!gr_tpe_allow(file))
71905 + return 0;
71906 +
71907 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71908 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71909 + return 0;
71910 + } else if (unlikely(!(mode & GR_EXEC))) {
71911 + return 0;
71912 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71913 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71914 + return 1;
71915 + }
71916 +
71917 + return 1;
71918 +}
71919 +
71920 +void
71921 +gr_acl_handle_psacct(struct task_struct *task, const long code)
71922 +{
71923 + unsigned long runtime, cputime;
71924 + cputime_t utime, stime;
71925 + unsigned int wday, cday;
71926 + __u8 whr, chr;
71927 + __u8 wmin, cmin;
71928 + __u8 wsec, csec;
71929 + struct timespec curtime, starttime;
71930 +
71931 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
71932 + !(task->acl->mode & GR_PROCACCT)))
71933 + return;
71934 +
71935 + curtime = ns_to_timespec(ktime_get_ns());
71936 + starttime = ns_to_timespec(task->start_time);
71937 + runtime = curtime.tv_sec - starttime.tv_sec;
71938 + wday = runtime / (60 * 60 * 24);
71939 + runtime -= wday * (60 * 60 * 24);
71940 + whr = runtime / (60 * 60);
71941 + runtime -= whr * (60 * 60);
71942 + wmin = runtime / 60;
71943 + runtime -= wmin * 60;
71944 + wsec = runtime;
71945 +
71946 + task_cputime(task, &utime, &stime);
71947 + cputime = cputime_to_secs(utime + stime);
71948 + cday = cputime / (60 * 60 * 24);
71949 + cputime -= cday * (60 * 60 * 24);
71950 + chr = cputime / (60 * 60);
71951 + cputime -= chr * (60 * 60);
71952 + cmin = cputime / 60;
71953 + cputime -= cmin * 60;
71954 + csec = cputime;
71955 +
71956 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
71957 +
71958 + return;
71959 +}
71960 +
71961 +#ifdef CONFIG_TASKSTATS
71962 +int gr_is_taskstats_denied(int pid)
71963 +{
71964 + struct task_struct *task;
71965 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71966 + const struct cred *cred;
71967 +#endif
71968 + int ret = 0;
71969 +
71970 + /* restrict taskstats viewing to un-chrooted root users
71971 + who have the 'view' subject flag if the RBAC system is enabled
71972 + */
71973 +
71974 + rcu_read_lock();
71975 + read_lock(&tasklist_lock);
71976 + task = find_task_by_vpid(pid);
71977 + if (task) {
71978 +#ifdef CONFIG_GRKERNSEC_CHROOT
71979 + if (proc_is_chrooted(task))
71980 + ret = -EACCES;
71981 +#endif
71982 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71983 + cred = __task_cred(task);
71984 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71985 + if (gr_is_global_nonroot(cred->uid))
71986 + ret = -EACCES;
71987 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71988 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
71989 + ret = -EACCES;
71990 +#endif
71991 +#endif
71992 + if (gr_status & GR_READY) {
71993 + if (!(task->acl->mode & GR_VIEW))
71994 + ret = -EACCES;
71995 + }
71996 + } else
71997 + ret = -ENOENT;
71998 +
71999 + read_unlock(&tasklist_lock);
72000 + rcu_read_unlock();
72001 +
72002 + return ret;
72003 +}
72004 +#endif
72005 +
72006 +/* AUXV entries are filled via a descendant of search_binary_handler
72007 + after we've already applied the subject for the target
72008 +*/
72009 +int gr_acl_enable_at_secure(void)
72010 +{
72011 + if (unlikely(!(gr_status & GR_READY)))
72012 + return 0;
72013 +
72014 + if (current->acl->mode & GR_ATSECURE)
72015 + return 1;
72016 +
72017 + return 0;
72018 +}
72019 +
72020 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72021 +{
72022 + struct task_struct *task = current;
72023 + struct dentry *dentry = file->f_path.dentry;
72024 + struct vfsmount *mnt = file->f_path.mnt;
72025 + struct acl_object_label *obj, *tmp;
72026 + struct acl_subject_label *subj;
72027 + unsigned int bufsize;
72028 + int is_not_root;
72029 + char *path;
72030 + dev_t dev = __get_dev(dentry);
72031 +
72032 + if (unlikely(!(gr_status & GR_READY)))
72033 + return 1;
72034 +
72035 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72036 + return 1;
72037 +
72038 + /* ignore Eric Biederman */
72039 + if (IS_PRIVATE(dentry->d_inode))
72040 + return 1;
72041 +
72042 + subj = task->acl;
72043 + read_lock(&gr_inode_lock);
72044 + do {
72045 + obj = lookup_acl_obj_label(ino, dev, subj);
72046 + if (obj != NULL) {
72047 + read_unlock(&gr_inode_lock);
72048 + return (obj->mode & GR_FIND) ? 1 : 0;
72049 + }
72050 + } while ((subj = subj->parent_subject));
72051 + read_unlock(&gr_inode_lock);
72052 +
72053 + /* this is purely an optimization since we're looking for an object
72054 + for the directory we're doing a readdir on
72055 + if it's possible for any globbed object to match the entry we're
72056 + filling into the directory, then the object we find here will be
72057 + an anchor point with attached globbed objects
72058 + */
72059 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72060 + if (obj->globbed == NULL)
72061 + return (obj->mode & GR_FIND) ? 1 : 0;
72062 +
72063 + is_not_root = ((obj->filename[0] == '/') &&
72064 + (obj->filename[1] == '\0')) ? 0 : 1;
72065 + bufsize = PAGE_SIZE - namelen - is_not_root;
72066 +
72067 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72068 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72069 + return 1;
72070 +
72071 + preempt_disable();
72072 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72073 + bufsize);
72074 +
72075 + bufsize = strlen(path);
72076 +
72077 + /* if base is "/", don't append an additional slash */
72078 + if (is_not_root)
72079 + *(path + bufsize) = '/';
72080 + memcpy(path + bufsize + is_not_root, name, namelen);
72081 + *(path + bufsize + namelen + is_not_root) = '\0';
72082 +
72083 + tmp = obj->globbed;
72084 + while (tmp) {
72085 + if (!glob_match(tmp->filename, path)) {
72086 + preempt_enable();
72087 + return (tmp->mode & GR_FIND) ? 1 : 0;
72088 + }
72089 + tmp = tmp->next;
72090 + }
72091 + preempt_enable();
72092 + return (obj->mode & GR_FIND) ? 1 : 0;
72093 +}
72094 +
72095 +void gr_put_exec_file(struct task_struct *task)
72096 +{
72097 + struct file *filp;
72098 +
72099 + write_lock(&grsec_exec_file_lock);
72100 + filp = task->exec_file;
72101 + task->exec_file = NULL;
72102 + write_unlock(&grsec_exec_file_lock);
72103 +
72104 + if (filp)
72105 + fput(filp);
72106 +
72107 + return;
72108 +}
72109 +
72110 +
72111 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72112 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72113 +#endif
72114 +#ifdef CONFIG_SECURITY
72115 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72116 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72117 +#endif
72118 +
72119 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72120 new file mode 100644
72121 index 0000000..18ffbbd
72122 --- /dev/null
72123 +++ b/grsecurity/gracl_alloc.c
72124 @@ -0,0 +1,105 @@
72125 +#include <linux/kernel.h>
72126 +#include <linux/mm.h>
72127 +#include <linux/slab.h>
72128 +#include <linux/vmalloc.h>
72129 +#include <linux/gracl.h>
72130 +#include <linux/grsecurity.h>
72131 +
72132 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72133 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72134 +
72135 +static __inline__ int
72136 +alloc_pop(void)
72137 +{
72138 + if (current_alloc_state->alloc_stack_next == 1)
72139 + return 0;
72140 +
72141 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72142 +
72143 + current_alloc_state->alloc_stack_next--;
72144 +
72145 + return 1;
72146 +}
72147 +
72148 +static __inline__ int
72149 +alloc_push(void *buf)
72150 +{
72151 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72152 + return 1;
72153 +
72154 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72155 +
72156 + current_alloc_state->alloc_stack_next++;
72157 +
72158 + return 0;
72159 +}
72160 +
72161 +void *
72162 +acl_alloc(unsigned long len)
72163 +{
72164 + void *ret = NULL;
72165 +
72166 + if (!len || len > PAGE_SIZE)
72167 + goto out;
72168 +
72169 + ret = kmalloc(len, GFP_KERNEL);
72170 +
72171 + if (ret) {
72172 + if (alloc_push(ret)) {
72173 + kfree(ret);
72174 + ret = NULL;
72175 + }
72176 + }
72177 +
72178 +out:
72179 + return ret;
72180 +}
72181 +
72182 +void *
72183 +acl_alloc_num(unsigned long num, unsigned long len)
72184 +{
72185 + if (!len || (num > (PAGE_SIZE / len)))
72186 + return NULL;
72187 +
72188 + return acl_alloc(num * len);
72189 +}
72190 +
72191 +void
72192 +acl_free_all(void)
72193 +{
72194 + if (!current_alloc_state->alloc_stack)
72195 + return;
72196 +
72197 + while (alloc_pop()) ;
72198 +
72199 + if (current_alloc_state->alloc_stack) {
72200 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72201 + kfree(current_alloc_state->alloc_stack);
72202 + else
72203 + vfree(current_alloc_state->alloc_stack);
72204 + }
72205 +
72206 + current_alloc_state->alloc_stack = NULL;
72207 + current_alloc_state->alloc_stack_size = 1;
72208 + current_alloc_state->alloc_stack_next = 1;
72209 +
72210 + return;
72211 +}
72212 +
72213 +int
72214 +acl_alloc_stack_init(unsigned long size)
72215 +{
72216 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72217 + current_alloc_state->alloc_stack =
72218 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72219 + else
72220 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72221 +
72222 + current_alloc_state->alloc_stack_size = size;
72223 + current_alloc_state->alloc_stack_next = 1;
72224 +
72225 + if (!current_alloc_state->alloc_stack)
72226 + return 0;
72227 + else
72228 + return 1;
72229 +}
72230 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72231 new file mode 100644
72232 index 0000000..1a94c11
72233 --- /dev/null
72234 +++ b/grsecurity/gracl_cap.c
72235 @@ -0,0 +1,127 @@
72236 +#include <linux/kernel.h>
72237 +#include <linux/module.h>
72238 +#include <linux/sched.h>
72239 +#include <linux/gracl.h>
72240 +#include <linux/grsecurity.h>
72241 +#include <linux/grinternal.h>
72242 +
72243 +extern const char *captab_log[];
72244 +extern int captab_log_entries;
72245 +
72246 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72247 +{
72248 + struct acl_subject_label *curracl;
72249 +
72250 + if (!gr_acl_is_enabled())
72251 + return 1;
72252 +
72253 + curracl = task->acl;
72254 +
72255 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72256 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72257 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72258 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72259 + gr_to_filename(task->exec_file->f_path.dentry,
72260 + task->exec_file->f_path.mnt) : curracl->filename,
72261 + curracl->filename, 0UL,
72262 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72263 + return 1;
72264 + }
72265 +
72266 + return 0;
72267 +}
72268 +
72269 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72270 +{
72271 + struct acl_subject_label *curracl;
72272 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72273 + kernel_cap_t cap_audit = __cap_empty_set;
72274 +
72275 + if (!gr_acl_is_enabled())
72276 + return 1;
72277 +
72278 + curracl = task->acl;
72279 +
72280 + cap_drop = curracl->cap_lower;
72281 + cap_mask = curracl->cap_mask;
72282 + cap_audit = curracl->cap_invert_audit;
72283 +
72284 + while ((curracl = curracl->parent_subject)) {
72285 + /* if the cap isn't specified in the current computed mask but is specified in the
72286 + current level subject, and is lowered in the current level subject, then add
72287 + it to the set of dropped capabilities
72288 + otherwise, add the current level subject's mask to the current computed mask
72289 + */
72290 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72291 + cap_raise(cap_mask, cap);
72292 + if (cap_raised(curracl->cap_lower, cap))
72293 + cap_raise(cap_drop, cap);
72294 + if (cap_raised(curracl->cap_invert_audit, cap))
72295 + cap_raise(cap_audit, cap);
72296 + }
72297 + }
72298 +
72299 + if (!cap_raised(cap_drop, cap)) {
72300 + if (cap_raised(cap_audit, cap))
72301 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72302 + return 1;
72303 + }
72304 +
72305 + /* only learn the capability use if the process has the capability in the
72306 + general case, the two uses in sys.c of gr_learn_cap are an exception
72307 + to this rule to ensure any role transition involves what the full-learned
72308 + policy believes in a privileged process
72309 + */
72310 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72311 + return 1;
72312 +
72313 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72314 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72315 +
72316 + return 0;
72317 +}
72318 +
72319 +int
72320 +gr_acl_is_capable(const int cap)
72321 +{
72322 + return gr_task_acl_is_capable(current, current_cred(), cap);
72323 +}
72324 +
72325 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72326 +{
72327 + struct acl_subject_label *curracl;
72328 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72329 +
72330 + if (!gr_acl_is_enabled())
72331 + return 1;
72332 +
72333 + curracl = task->acl;
72334 +
72335 + cap_drop = curracl->cap_lower;
72336 + cap_mask = curracl->cap_mask;
72337 +
72338 + while ((curracl = curracl->parent_subject)) {
72339 + /* if the cap isn't specified in the current computed mask but is specified in the
72340 + current level subject, and is lowered in the current level subject, then add
72341 + it to the set of dropped capabilities
72342 + otherwise, add the current level subject's mask to the current computed mask
72343 + */
72344 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72345 + cap_raise(cap_mask, cap);
72346 + if (cap_raised(curracl->cap_lower, cap))
72347 + cap_raise(cap_drop, cap);
72348 + }
72349 + }
72350 +
72351 + if (!cap_raised(cap_drop, cap))
72352 + return 1;
72353 +
72354 + return 0;
72355 +}
72356 +
72357 +int
72358 +gr_acl_is_capable_nolog(const int cap)
72359 +{
72360 + return gr_task_acl_is_capable_nolog(current, cap);
72361 +}
72362 +
72363 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72364 new file mode 100644
72365 index 0000000..ca25605
72366 --- /dev/null
72367 +++ b/grsecurity/gracl_compat.c
72368 @@ -0,0 +1,270 @@
72369 +#include <linux/kernel.h>
72370 +#include <linux/gracl.h>
72371 +#include <linux/compat.h>
72372 +#include <linux/gracl_compat.h>
72373 +
72374 +#include <asm/uaccess.h>
72375 +
72376 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72377 +{
72378 + struct gr_arg_wrapper_compat uwrapcompat;
72379 +
72380 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72381 + return -EFAULT;
72382 +
72383 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72384 + (uwrapcompat.version != 0x2901)) ||
72385 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72386 + return -EINVAL;
72387 +
72388 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72389 + uwrap->version = uwrapcompat.version;
72390 + uwrap->size = sizeof(struct gr_arg);
72391 +
72392 + return 0;
72393 +}
72394 +
72395 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72396 +{
72397 + struct gr_arg_compat argcompat;
72398 +
72399 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72400 + return -EFAULT;
72401 +
72402 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72403 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72404 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72405 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72406 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72407 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72408 +
72409 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72410 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72411 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72412 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72413 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72414 + arg->segv_device = argcompat.segv_device;
72415 + arg->segv_inode = argcompat.segv_inode;
72416 + arg->segv_uid = argcompat.segv_uid;
72417 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72418 + arg->mode = argcompat.mode;
72419 +
72420 + return 0;
72421 +}
72422 +
72423 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72424 +{
72425 + struct acl_object_label_compat objcompat;
72426 +
72427 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72428 + return -EFAULT;
72429 +
72430 + obj->filename = compat_ptr(objcompat.filename);
72431 + obj->inode = objcompat.inode;
72432 + obj->device = objcompat.device;
72433 + obj->mode = objcompat.mode;
72434 +
72435 + obj->nested = compat_ptr(objcompat.nested);
72436 + obj->globbed = compat_ptr(objcompat.globbed);
72437 +
72438 + obj->prev = compat_ptr(objcompat.prev);
72439 + obj->next = compat_ptr(objcompat.next);
72440 +
72441 + return 0;
72442 +}
72443 +
72444 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72445 +{
72446 + unsigned int i;
72447 + struct acl_subject_label_compat subjcompat;
72448 +
72449 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72450 + return -EFAULT;
72451 +
72452 + subj->filename = compat_ptr(subjcompat.filename);
72453 + subj->inode = subjcompat.inode;
72454 + subj->device = subjcompat.device;
72455 + subj->mode = subjcompat.mode;
72456 + subj->cap_mask = subjcompat.cap_mask;
72457 + subj->cap_lower = subjcompat.cap_lower;
72458 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72459 +
72460 + for (i = 0; i < GR_NLIMITS; i++) {
72461 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72462 + subj->res[i].rlim_cur = RLIM_INFINITY;
72463 + else
72464 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72465 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72466 + subj->res[i].rlim_max = RLIM_INFINITY;
72467 + else
72468 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72469 + }
72470 + subj->resmask = subjcompat.resmask;
72471 +
72472 + subj->user_trans_type = subjcompat.user_trans_type;
72473 + subj->group_trans_type = subjcompat.group_trans_type;
72474 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72475 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72476 + subj->user_trans_num = subjcompat.user_trans_num;
72477 + subj->group_trans_num = subjcompat.group_trans_num;
72478 +
72479 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72480 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72481 + subj->ip_type = subjcompat.ip_type;
72482 + subj->ips = compat_ptr(subjcompat.ips);
72483 + subj->ip_num = subjcompat.ip_num;
72484 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72485 +
72486 + subj->crashes = subjcompat.crashes;
72487 + subj->expires = subjcompat.expires;
72488 +
72489 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72490 + subj->hash = compat_ptr(subjcompat.hash);
72491 + subj->prev = compat_ptr(subjcompat.prev);
72492 + subj->next = compat_ptr(subjcompat.next);
72493 +
72494 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72495 + subj->obj_hash_size = subjcompat.obj_hash_size;
72496 + subj->pax_flags = subjcompat.pax_flags;
72497 +
72498 + return 0;
72499 +}
72500 +
72501 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72502 +{
72503 + struct acl_role_label_compat rolecompat;
72504 +
72505 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72506 + return -EFAULT;
72507 +
72508 + role->rolename = compat_ptr(rolecompat.rolename);
72509 + role->uidgid = rolecompat.uidgid;
72510 + role->roletype = rolecompat.roletype;
72511 +
72512 + role->auth_attempts = rolecompat.auth_attempts;
72513 + role->expires = rolecompat.expires;
72514 +
72515 + role->root_label = compat_ptr(rolecompat.root_label);
72516 + role->hash = compat_ptr(rolecompat.hash);
72517 +
72518 + role->prev = compat_ptr(rolecompat.prev);
72519 + role->next = compat_ptr(rolecompat.next);
72520 +
72521 + role->transitions = compat_ptr(rolecompat.transitions);
72522 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72523 + role->domain_children = compat_ptr(rolecompat.domain_children);
72524 + role->domain_child_num = rolecompat.domain_child_num;
72525 +
72526 + role->umask = rolecompat.umask;
72527 +
72528 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72529 + role->subj_hash_size = rolecompat.subj_hash_size;
72530 +
72531 + return 0;
72532 +}
72533 +
72534 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72535 +{
72536 + struct role_allowed_ip_compat roleip_compat;
72537 +
72538 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72539 + return -EFAULT;
72540 +
72541 + roleip->addr = roleip_compat.addr;
72542 + roleip->netmask = roleip_compat.netmask;
72543 +
72544 + roleip->prev = compat_ptr(roleip_compat.prev);
72545 + roleip->next = compat_ptr(roleip_compat.next);
72546 +
72547 + return 0;
72548 +}
72549 +
72550 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72551 +{
72552 + struct role_transition_compat trans_compat;
72553 +
72554 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72555 + return -EFAULT;
72556 +
72557 + trans->rolename = compat_ptr(trans_compat.rolename);
72558 +
72559 + trans->prev = compat_ptr(trans_compat.prev);
72560 + trans->next = compat_ptr(trans_compat.next);
72561 +
72562 + return 0;
72563 +
72564 +}
72565 +
72566 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72567 +{
72568 + struct gr_hash_struct_compat hash_compat;
72569 +
72570 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72571 + return -EFAULT;
72572 +
72573 + hash->table = compat_ptr(hash_compat.table);
72574 + hash->nametable = compat_ptr(hash_compat.nametable);
72575 + hash->first = compat_ptr(hash_compat.first);
72576 +
72577 + hash->table_size = hash_compat.table_size;
72578 + hash->used_size = hash_compat.used_size;
72579 +
72580 + hash->type = hash_compat.type;
72581 +
72582 + return 0;
72583 +}
72584 +
72585 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72586 +{
72587 + compat_uptr_t ptrcompat;
72588 +
72589 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72590 + return -EFAULT;
72591 +
72592 + *(void **)ptr = compat_ptr(ptrcompat);
72593 +
72594 + return 0;
72595 +}
72596 +
72597 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72598 +{
72599 + struct acl_ip_label_compat ip_compat;
72600 +
72601 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72602 + return -EFAULT;
72603 +
72604 + ip->iface = compat_ptr(ip_compat.iface);
72605 + ip->addr = ip_compat.addr;
72606 + ip->netmask = ip_compat.netmask;
72607 + ip->low = ip_compat.low;
72608 + ip->high = ip_compat.high;
72609 + ip->mode = ip_compat.mode;
72610 + ip->type = ip_compat.type;
72611 +
72612 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72613 +
72614 + ip->prev = compat_ptr(ip_compat.prev);
72615 + ip->next = compat_ptr(ip_compat.next);
72616 +
72617 + return 0;
72618 +}
72619 +
72620 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72621 +{
72622 + struct sprole_pw_compat pw_compat;
72623 +
72624 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72625 + return -EFAULT;
72626 +
72627 + pw->rolename = compat_ptr(pw_compat.rolename);
72628 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72629 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72630 +
72631 + return 0;
72632 +}
72633 +
72634 +size_t get_gr_arg_wrapper_size_compat(void)
72635 +{
72636 + return sizeof(struct gr_arg_wrapper_compat);
72637 +}
72638 +
72639 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72640 new file mode 100644
72641 index 0000000..4008fdc
72642 --- /dev/null
72643 +++ b/grsecurity/gracl_fs.c
72644 @@ -0,0 +1,445 @@
72645 +#include <linux/kernel.h>
72646 +#include <linux/sched.h>
72647 +#include <linux/types.h>
72648 +#include <linux/fs.h>
72649 +#include <linux/file.h>
72650 +#include <linux/stat.h>
72651 +#include <linux/grsecurity.h>
72652 +#include <linux/grinternal.h>
72653 +#include <linux/gracl.h>
72654 +
72655 +umode_t
72656 +gr_acl_umask(void)
72657 +{
72658 + if (unlikely(!gr_acl_is_enabled()))
72659 + return 0;
72660 +
72661 + return current->role->umask;
72662 +}
72663 +
72664 +__u32
72665 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72666 + const struct vfsmount * mnt)
72667 +{
72668 + __u32 mode;
72669 +
72670 + if (unlikely(d_is_negative(dentry)))
72671 + return GR_FIND;
72672 +
72673 + mode =
72674 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72675 +
72676 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72677 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72678 + return mode;
72679 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72680 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72681 + return 0;
72682 + } else if (unlikely(!(mode & GR_FIND)))
72683 + return 0;
72684 +
72685 + return GR_FIND;
72686 +}
72687 +
72688 +__u32
72689 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72690 + int acc_mode)
72691 +{
72692 + __u32 reqmode = GR_FIND;
72693 + __u32 mode;
72694 +
72695 + if (unlikely(d_is_negative(dentry)))
72696 + return reqmode;
72697 +
72698 + if (acc_mode & MAY_APPEND)
72699 + reqmode |= GR_APPEND;
72700 + else if (acc_mode & MAY_WRITE)
72701 + reqmode |= GR_WRITE;
72702 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72703 + reqmode |= GR_READ;
72704 +
72705 + mode =
72706 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72707 + mnt);
72708 +
72709 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72710 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72711 + reqmode & GR_READ ? " reading" : "",
72712 + reqmode & GR_WRITE ? " writing" : reqmode &
72713 + GR_APPEND ? " appending" : "");
72714 + return reqmode;
72715 + } else
72716 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72717 + {
72718 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72719 + reqmode & GR_READ ? " reading" : "",
72720 + reqmode & GR_WRITE ? " writing" : reqmode &
72721 + GR_APPEND ? " appending" : "");
72722 + return 0;
72723 + } else if (unlikely((mode & reqmode) != reqmode))
72724 + return 0;
72725 +
72726 + return reqmode;
72727 +}
72728 +
72729 +__u32
72730 +gr_acl_handle_creat(const struct dentry * dentry,
72731 + const struct dentry * p_dentry,
72732 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72733 + const int imode)
72734 +{
72735 + __u32 reqmode = GR_WRITE | GR_CREATE;
72736 + __u32 mode;
72737 +
72738 + if (acc_mode & MAY_APPEND)
72739 + reqmode |= GR_APPEND;
72740 + // if a directory was required or the directory already exists, then
72741 + // don't count this open as a read
72742 + if ((acc_mode & MAY_READ) &&
72743 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72744 + reqmode |= GR_READ;
72745 + if ((open_flags & O_CREAT) &&
72746 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72747 + reqmode |= GR_SETID;
72748 +
72749 + mode =
72750 + gr_check_create(dentry, p_dentry, p_mnt,
72751 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72752 +
72753 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72754 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72755 + reqmode & GR_READ ? " reading" : "",
72756 + reqmode & GR_WRITE ? " writing" : reqmode &
72757 + GR_APPEND ? " appending" : "");
72758 + return reqmode;
72759 + } else
72760 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72761 + {
72762 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72763 + reqmode & GR_READ ? " reading" : "",
72764 + reqmode & GR_WRITE ? " writing" : reqmode &
72765 + GR_APPEND ? " appending" : "");
72766 + return 0;
72767 + } else if (unlikely((mode & reqmode) != reqmode))
72768 + return 0;
72769 +
72770 + return reqmode;
72771 +}
72772 +
72773 +__u32
72774 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72775 + const int fmode)
72776 +{
72777 + __u32 mode, reqmode = GR_FIND;
72778 +
72779 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72780 + reqmode |= GR_EXEC;
72781 + if (fmode & S_IWOTH)
72782 + reqmode |= GR_WRITE;
72783 + if (fmode & S_IROTH)
72784 + reqmode |= GR_READ;
72785 +
72786 + mode =
72787 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72788 + mnt);
72789 +
72790 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72791 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72792 + reqmode & GR_READ ? " reading" : "",
72793 + reqmode & GR_WRITE ? " writing" : "",
72794 + reqmode & GR_EXEC ? " executing" : "");
72795 + return reqmode;
72796 + } else
72797 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72798 + {
72799 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72800 + reqmode & GR_READ ? " reading" : "",
72801 + reqmode & GR_WRITE ? " writing" : "",
72802 + reqmode & GR_EXEC ? " executing" : "");
72803 + return 0;
72804 + } else if (unlikely((mode & reqmode) != reqmode))
72805 + return 0;
72806 +
72807 + return reqmode;
72808 +}
72809 +
72810 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72811 +{
72812 + __u32 mode;
72813 +
72814 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72815 +
72816 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72817 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72818 + return mode;
72819 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72820 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72821 + return 0;
72822 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72823 + return 0;
72824 +
72825 + return (reqmode);
72826 +}
72827 +
72828 +__u32
72829 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72830 +{
72831 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72832 +}
72833 +
72834 +__u32
72835 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72836 +{
72837 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72838 +}
72839 +
72840 +__u32
72841 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72842 +{
72843 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72844 +}
72845 +
72846 +__u32
72847 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72848 +{
72849 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72850 +}
72851 +
72852 +__u32
72853 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72854 + umode_t *modeptr)
72855 +{
72856 + umode_t mode;
72857 +
72858 + *modeptr &= ~gr_acl_umask();
72859 + mode = *modeptr;
72860 +
72861 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72862 + return 1;
72863 +
72864 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72865 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72866 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72867 + GR_CHMOD_ACL_MSG);
72868 + } else {
72869 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72870 + }
72871 +}
72872 +
72873 +__u32
72874 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72875 +{
72876 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72877 +}
72878 +
72879 +__u32
72880 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72881 +{
72882 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72883 +}
72884 +
72885 +__u32
72886 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72887 +{
72888 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72889 +}
72890 +
72891 +__u32
72892 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72893 +{
72894 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
72895 +}
72896 +
72897 +__u32
72898 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
72899 +{
72900 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
72901 + GR_UNIXCONNECT_ACL_MSG);
72902 +}
72903 +
72904 +/* hardlinks require at minimum create and link permission,
72905 + any additional privilege required is based on the
72906 + privilege of the file being linked to
72907 +*/
72908 +__u32
72909 +gr_acl_handle_link(const struct dentry * new_dentry,
72910 + const struct dentry * parent_dentry,
72911 + const struct vfsmount * parent_mnt,
72912 + const struct dentry * old_dentry,
72913 + const struct vfsmount * old_mnt, const struct filename *to)
72914 +{
72915 + __u32 mode;
72916 + __u32 needmode = GR_CREATE | GR_LINK;
72917 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
72918 +
72919 + mode =
72920 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
72921 + old_mnt);
72922 +
72923 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
72924 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72925 + return mode;
72926 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72927 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72928 + return 0;
72929 + } else if (unlikely((mode & needmode) != needmode))
72930 + return 0;
72931 +
72932 + return 1;
72933 +}
72934 +
72935 +__u32
72936 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72937 + const struct dentry * parent_dentry,
72938 + const struct vfsmount * parent_mnt, const struct filename *from)
72939 +{
72940 + __u32 needmode = GR_WRITE | GR_CREATE;
72941 + __u32 mode;
72942 +
72943 + mode =
72944 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
72945 + GR_CREATE | GR_AUDIT_CREATE |
72946 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
72947 +
72948 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
72949 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72950 + return mode;
72951 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72952 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72953 + return 0;
72954 + } else if (unlikely((mode & needmode) != needmode))
72955 + return 0;
72956 +
72957 + return (GR_WRITE | GR_CREATE);
72958 +}
72959 +
72960 +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)
72961 +{
72962 + __u32 mode;
72963 +
72964 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72965 +
72966 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72967 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
72968 + return mode;
72969 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72970 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
72971 + return 0;
72972 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72973 + return 0;
72974 +
72975 + return (reqmode);
72976 +}
72977 +
72978 +__u32
72979 +gr_acl_handle_mknod(const struct dentry * new_dentry,
72980 + const struct dentry * parent_dentry,
72981 + const struct vfsmount * parent_mnt,
72982 + const int mode)
72983 +{
72984 + __u32 reqmode = GR_WRITE | GR_CREATE;
72985 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72986 + reqmode |= GR_SETID;
72987 +
72988 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
72989 + reqmode, GR_MKNOD_ACL_MSG);
72990 +}
72991 +
72992 +__u32
72993 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
72994 + const struct dentry *parent_dentry,
72995 + const struct vfsmount *parent_mnt)
72996 +{
72997 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
72998 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
72999 +}
73000 +
73001 +#define RENAME_CHECK_SUCCESS(old, new) \
73002 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73003 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73004 +
73005 +int
73006 +gr_acl_handle_rename(struct dentry *new_dentry,
73007 + struct dentry *parent_dentry,
73008 + const struct vfsmount *parent_mnt,
73009 + struct dentry *old_dentry,
73010 + struct inode *old_parent_inode,
73011 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73012 +{
73013 + __u32 comp1, comp2;
73014 + int error = 0;
73015 +
73016 + if (unlikely(!gr_acl_is_enabled()))
73017 + return 0;
73018 +
73019 + if (flags & RENAME_EXCHANGE) {
73020 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73021 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73022 + GR_SUPPRESS, parent_mnt);
73023 + comp2 =
73024 + gr_search_file(old_dentry,
73025 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73026 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73027 + } else if (d_is_negative(new_dentry)) {
73028 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73029 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73030 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73031 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73032 + GR_DELETE | GR_AUDIT_DELETE |
73033 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73034 + GR_SUPPRESS, old_mnt);
73035 + } else {
73036 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73037 + GR_CREATE | GR_DELETE |
73038 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73039 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73040 + GR_SUPPRESS, parent_mnt);
73041 + comp2 =
73042 + gr_search_file(old_dentry,
73043 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73044 + GR_DELETE | GR_AUDIT_DELETE |
73045 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73046 + }
73047 +
73048 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73049 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73050 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73051 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73052 + && !(comp2 & GR_SUPPRESS)) {
73053 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73054 + error = -EACCES;
73055 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73056 + error = -EACCES;
73057 +
73058 + return error;
73059 +}
73060 +
73061 +void
73062 +gr_acl_handle_exit(void)
73063 +{
73064 + u16 id;
73065 + char *rolename;
73066 +
73067 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73068 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73069 + id = current->acl_role_id;
73070 + rolename = current->role->rolename;
73071 + gr_set_acls(1);
73072 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73073 + }
73074 +
73075 + gr_put_exec_file(current);
73076 + return;
73077 +}
73078 +
73079 +int
73080 +gr_acl_handle_procpidmem(const struct task_struct *task)
73081 +{
73082 + if (unlikely(!gr_acl_is_enabled()))
73083 + return 0;
73084 +
73085 + if (task != current && task->acl->mode & GR_PROTPROCFD)
73086 + return -EACCES;
73087 +
73088 + return 0;
73089 +}
73090 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73091 new file mode 100644
73092 index 0000000..f056b81
73093 --- /dev/null
73094 +++ b/grsecurity/gracl_ip.c
73095 @@ -0,0 +1,386 @@
73096 +#include <linux/kernel.h>
73097 +#include <asm/uaccess.h>
73098 +#include <asm/errno.h>
73099 +#include <net/sock.h>
73100 +#include <linux/file.h>
73101 +#include <linux/fs.h>
73102 +#include <linux/net.h>
73103 +#include <linux/in.h>
73104 +#include <linux/skbuff.h>
73105 +#include <linux/ip.h>
73106 +#include <linux/udp.h>
73107 +#include <linux/types.h>
73108 +#include <linux/sched.h>
73109 +#include <linux/netdevice.h>
73110 +#include <linux/inetdevice.h>
73111 +#include <linux/gracl.h>
73112 +#include <linux/grsecurity.h>
73113 +#include <linux/grinternal.h>
73114 +
73115 +#define GR_BIND 0x01
73116 +#define GR_CONNECT 0x02
73117 +#define GR_INVERT 0x04
73118 +#define GR_BINDOVERRIDE 0x08
73119 +#define GR_CONNECTOVERRIDE 0x10
73120 +#define GR_SOCK_FAMILY 0x20
73121 +
73122 +static const char * gr_protocols[IPPROTO_MAX] = {
73123 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73124 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73125 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73126 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73127 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73128 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73129 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73130 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73131 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73132 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73133 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73134 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73135 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73136 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73137 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73138 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73139 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73140 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73141 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73142 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73143 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73144 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73145 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73146 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73147 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73148 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73149 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73150 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73151 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73152 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73153 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73154 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73155 + };
73156 +
73157 +static const char * gr_socktypes[SOCK_MAX] = {
73158 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73159 + "unknown:7", "unknown:8", "unknown:9", "packet"
73160 + };
73161 +
73162 +static const char * gr_sockfamilies[AF_MAX+1] = {
73163 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73164 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73165 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73166 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73167 + };
73168 +
73169 +const char *
73170 +gr_proto_to_name(unsigned char proto)
73171 +{
73172 + return gr_protocols[proto];
73173 +}
73174 +
73175 +const char *
73176 +gr_socktype_to_name(unsigned char type)
73177 +{
73178 + return gr_socktypes[type];
73179 +}
73180 +
73181 +const char *
73182 +gr_sockfamily_to_name(unsigned char family)
73183 +{
73184 + return gr_sockfamilies[family];
73185 +}
73186 +
73187 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73188 +
73189 +int
73190 +gr_search_socket(const int domain, const int type, const int protocol)
73191 +{
73192 + struct acl_subject_label *curr;
73193 + const struct cred *cred = current_cred();
73194 +
73195 + if (unlikely(!gr_acl_is_enabled()))
73196 + goto exit;
73197 +
73198 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73199 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73200 + goto exit; // let the kernel handle it
73201 +
73202 + curr = current->acl;
73203 +
73204 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73205 + /* the family is allowed, if this is PF_INET allow it only if
73206 + the extra sock type/protocol checks pass */
73207 + if (domain == PF_INET)
73208 + goto inet_check;
73209 + goto exit;
73210 + } else {
73211 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73212 + __u32 fakeip = 0;
73213 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73214 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73215 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73216 + gr_to_filename(current->exec_file->f_path.dentry,
73217 + current->exec_file->f_path.mnt) :
73218 + curr->filename, curr->filename,
73219 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73220 + &current->signal->saved_ip);
73221 + goto exit;
73222 + }
73223 + goto exit_fail;
73224 + }
73225 +
73226 +inet_check:
73227 + /* the rest of this checking is for IPv4 only */
73228 + if (!curr->ips)
73229 + goto exit;
73230 +
73231 + if ((curr->ip_type & (1U << type)) &&
73232 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73233 + goto exit;
73234 +
73235 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73236 + /* we don't place acls on raw sockets , and sometimes
73237 + dgram/ip sockets are opened for ioctl and not
73238 + bind/connect, so we'll fake a bind learn log */
73239 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73240 + __u32 fakeip = 0;
73241 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73242 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73243 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73244 + gr_to_filename(current->exec_file->f_path.dentry,
73245 + current->exec_file->f_path.mnt) :
73246 + curr->filename, curr->filename,
73247 + &fakeip, 0, type,
73248 + protocol, GR_CONNECT, &current->signal->saved_ip);
73249 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73250 + __u32 fakeip = 0;
73251 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73252 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73253 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73254 + gr_to_filename(current->exec_file->f_path.dentry,
73255 + current->exec_file->f_path.mnt) :
73256 + curr->filename, curr->filename,
73257 + &fakeip, 0, type,
73258 + protocol, GR_BIND, &current->signal->saved_ip);
73259 + }
73260 + /* we'll log when they use connect or bind */
73261 + goto exit;
73262 + }
73263 +
73264 +exit_fail:
73265 + if (domain == PF_INET)
73266 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73267 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73268 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73269 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73270 + gr_socktype_to_name(type), protocol);
73271 +
73272 + return 0;
73273 +exit:
73274 + return 1;
73275 +}
73276 +
73277 +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)
73278 +{
73279 + if ((ip->mode & mode) &&
73280 + (ip_port >= ip->low) &&
73281 + (ip_port <= ip->high) &&
73282 + ((ntohl(ip_addr) & our_netmask) ==
73283 + (ntohl(our_addr) & our_netmask))
73284 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73285 + && (ip->type & (1U << type))) {
73286 + if (ip->mode & GR_INVERT)
73287 + return 2; // specifically denied
73288 + else
73289 + return 1; // allowed
73290 + }
73291 +
73292 + return 0; // not specifically allowed, may continue parsing
73293 +}
73294 +
73295 +static int
73296 +gr_search_connectbind(const int full_mode, struct sock *sk,
73297 + struct sockaddr_in *addr, const int type)
73298 +{
73299 + char iface[IFNAMSIZ] = {0};
73300 + struct acl_subject_label *curr;
73301 + struct acl_ip_label *ip;
73302 + struct inet_sock *isk;
73303 + struct net_device *dev;
73304 + struct in_device *idev;
73305 + unsigned long i;
73306 + int ret;
73307 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73308 + __u32 ip_addr = 0;
73309 + __u32 our_addr;
73310 + __u32 our_netmask;
73311 + char *p;
73312 + __u16 ip_port = 0;
73313 + const struct cred *cred = current_cred();
73314 +
73315 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73316 + return 0;
73317 +
73318 + curr = current->acl;
73319 + isk = inet_sk(sk);
73320 +
73321 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73322 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73323 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73324 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73325 + struct sockaddr_in saddr;
73326 + int err;
73327 +
73328 + saddr.sin_family = AF_INET;
73329 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73330 + saddr.sin_port = isk->inet_sport;
73331 +
73332 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73333 + if (err)
73334 + return err;
73335 +
73336 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73337 + if (err)
73338 + return err;
73339 + }
73340 +
73341 + if (!curr->ips)
73342 + return 0;
73343 +
73344 + ip_addr = addr->sin_addr.s_addr;
73345 + ip_port = ntohs(addr->sin_port);
73346 +
73347 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73348 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73349 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73350 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73351 + gr_to_filename(current->exec_file->f_path.dentry,
73352 + current->exec_file->f_path.mnt) :
73353 + curr->filename, curr->filename,
73354 + &ip_addr, ip_port, type,
73355 + sk->sk_protocol, mode, &current->signal->saved_ip);
73356 + return 0;
73357 + }
73358 +
73359 + for (i = 0; i < curr->ip_num; i++) {
73360 + ip = *(curr->ips + i);
73361 + if (ip->iface != NULL) {
73362 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73363 + p = strchr(iface, ':');
73364 + if (p != NULL)
73365 + *p = '\0';
73366 + dev = dev_get_by_name(sock_net(sk), iface);
73367 + if (dev == NULL)
73368 + continue;
73369 + idev = in_dev_get(dev);
73370 + if (idev == NULL) {
73371 + dev_put(dev);
73372 + continue;
73373 + }
73374 + rcu_read_lock();
73375 + for_ifa(idev) {
73376 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73377 + our_addr = ifa->ifa_address;
73378 + our_netmask = 0xffffffff;
73379 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73380 + if (ret == 1) {
73381 + rcu_read_unlock();
73382 + in_dev_put(idev);
73383 + dev_put(dev);
73384 + return 0;
73385 + } else if (ret == 2) {
73386 + rcu_read_unlock();
73387 + in_dev_put(idev);
73388 + dev_put(dev);
73389 + goto denied;
73390 + }
73391 + }
73392 + } endfor_ifa(idev);
73393 + rcu_read_unlock();
73394 + in_dev_put(idev);
73395 + dev_put(dev);
73396 + } else {
73397 + our_addr = ip->addr;
73398 + our_netmask = ip->netmask;
73399 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73400 + if (ret == 1)
73401 + return 0;
73402 + else if (ret == 2)
73403 + goto denied;
73404 + }
73405 + }
73406 +
73407 +denied:
73408 + if (mode == GR_BIND)
73409 + 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));
73410 + else if (mode == GR_CONNECT)
73411 + 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));
73412 +
73413 + return -EACCES;
73414 +}
73415 +
73416 +int
73417 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73418 +{
73419 + /* always allow disconnection of dgram sockets with connect */
73420 + if (addr->sin_family == AF_UNSPEC)
73421 + return 0;
73422 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73423 +}
73424 +
73425 +int
73426 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73427 +{
73428 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73429 +}
73430 +
73431 +int gr_search_listen(struct socket *sock)
73432 +{
73433 + struct sock *sk = sock->sk;
73434 + struct sockaddr_in addr;
73435 +
73436 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73437 + addr.sin_port = inet_sk(sk)->inet_sport;
73438 +
73439 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73440 +}
73441 +
73442 +int gr_search_accept(struct socket *sock)
73443 +{
73444 + struct sock *sk = sock->sk;
73445 + struct sockaddr_in addr;
73446 +
73447 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73448 + addr.sin_port = inet_sk(sk)->inet_sport;
73449 +
73450 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73451 +}
73452 +
73453 +int
73454 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73455 +{
73456 + if (addr)
73457 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73458 + else {
73459 + struct sockaddr_in sin;
73460 + const struct inet_sock *inet = inet_sk(sk);
73461 +
73462 + sin.sin_addr.s_addr = inet->inet_daddr;
73463 + sin.sin_port = inet->inet_dport;
73464 +
73465 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73466 + }
73467 +}
73468 +
73469 +int
73470 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73471 +{
73472 + struct sockaddr_in sin;
73473 +
73474 + if (unlikely(skb->len < sizeof (struct udphdr)))
73475 + return 0; // skip this packet
73476 +
73477 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73478 + sin.sin_port = udp_hdr(skb)->source;
73479 +
73480 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73481 +}
73482 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73483 new file mode 100644
73484 index 0000000..25f54ef
73485 --- /dev/null
73486 +++ b/grsecurity/gracl_learn.c
73487 @@ -0,0 +1,207 @@
73488 +#include <linux/kernel.h>
73489 +#include <linux/mm.h>
73490 +#include <linux/sched.h>
73491 +#include <linux/poll.h>
73492 +#include <linux/string.h>
73493 +#include <linux/file.h>
73494 +#include <linux/types.h>
73495 +#include <linux/vmalloc.h>
73496 +#include <linux/grinternal.h>
73497 +
73498 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73499 + size_t count, loff_t *ppos);
73500 +extern int gr_acl_is_enabled(void);
73501 +
73502 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73503 +static int gr_learn_attached;
73504 +
73505 +/* use a 512k buffer */
73506 +#define LEARN_BUFFER_SIZE (512 * 1024)
73507 +
73508 +static DEFINE_SPINLOCK(gr_learn_lock);
73509 +static DEFINE_MUTEX(gr_learn_user_mutex);
73510 +
73511 +/* we need to maintain two buffers, so that the kernel context of grlearn
73512 + uses a semaphore around the userspace copying, and the other kernel contexts
73513 + use a spinlock when copying into the buffer, since they cannot sleep
73514 +*/
73515 +static char *learn_buffer;
73516 +static char *learn_buffer_user;
73517 +static int learn_buffer_len;
73518 +static int learn_buffer_user_len;
73519 +
73520 +static ssize_t
73521 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73522 +{
73523 + DECLARE_WAITQUEUE(wait, current);
73524 + ssize_t retval = 0;
73525 +
73526 + add_wait_queue(&learn_wait, &wait);
73527 + set_current_state(TASK_INTERRUPTIBLE);
73528 + do {
73529 + mutex_lock(&gr_learn_user_mutex);
73530 + spin_lock(&gr_learn_lock);
73531 + if (learn_buffer_len)
73532 + break;
73533 + spin_unlock(&gr_learn_lock);
73534 + mutex_unlock(&gr_learn_user_mutex);
73535 + if (file->f_flags & O_NONBLOCK) {
73536 + retval = -EAGAIN;
73537 + goto out;
73538 + }
73539 + if (signal_pending(current)) {
73540 + retval = -ERESTARTSYS;
73541 + goto out;
73542 + }
73543 +
73544 + schedule();
73545 + } while (1);
73546 +
73547 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73548 + learn_buffer_user_len = learn_buffer_len;
73549 + retval = learn_buffer_len;
73550 + learn_buffer_len = 0;
73551 +
73552 + spin_unlock(&gr_learn_lock);
73553 +
73554 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73555 + retval = -EFAULT;
73556 +
73557 + mutex_unlock(&gr_learn_user_mutex);
73558 +out:
73559 + set_current_state(TASK_RUNNING);
73560 + remove_wait_queue(&learn_wait, &wait);
73561 + return retval;
73562 +}
73563 +
73564 +static unsigned int
73565 +poll_learn(struct file * file, poll_table * wait)
73566 +{
73567 + poll_wait(file, &learn_wait, wait);
73568 +
73569 + if (learn_buffer_len)
73570 + return (POLLIN | POLLRDNORM);
73571 +
73572 + return 0;
73573 +}
73574 +
73575 +void
73576 +gr_clear_learn_entries(void)
73577 +{
73578 + char *tmp;
73579 +
73580 + mutex_lock(&gr_learn_user_mutex);
73581 + spin_lock(&gr_learn_lock);
73582 + tmp = learn_buffer;
73583 + learn_buffer = NULL;
73584 + spin_unlock(&gr_learn_lock);
73585 + if (tmp)
73586 + vfree(tmp);
73587 + if (learn_buffer_user != NULL) {
73588 + vfree(learn_buffer_user);
73589 + learn_buffer_user = NULL;
73590 + }
73591 + learn_buffer_len = 0;
73592 + mutex_unlock(&gr_learn_user_mutex);
73593 +
73594 + return;
73595 +}
73596 +
73597 +void
73598 +gr_add_learn_entry(const char *fmt, ...)
73599 +{
73600 + va_list args;
73601 + unsigned int len;
73602 +
73603 + if (!gr_learn_attached)
73604 + return;
73605 +
73606 + spin_lock(&gr_learn_lock);
73607 +
73608 + /* leave a gap at the end so we know when it's "full" but don't have to
73609 + compute the exact length of the string we're trying to append
73610 + */
73611 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73612 + spin_unlock(&gr_learn_lock);
73613 + wake_up_interruptible(&learn_wait);
73614 + return;
73615 + }
73616 + if (learn_buffer == NULL) {
73617 + spin_unlock(&gr_learn_lock);
73618 + return;
73619 + }
73620 +
73621 + va_start(args, fmt);
73622 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73623 + va_end(args);
73624 +
73625 + learn_buffer_len += len + 1;
73626 +
73627 + spin_unlock(&gr_learn_lock);
73628 + wake_up_interruptible(&learn_wait);
73629 +
73630 + return;
73631 +}
73632 +
73633 +static int
73634 +open_learn(struct inode *inode, struct file *file)
73635 +{
73636 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73637 + return -EBUSY;
73638 + if (file->f_mode & FMODE_READ) {
73639 + int retval = 0;
73640 + mutex_lock(&gr_learn_user_mutex);
73641 + if (learn_buffer == NULL)
73642 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73643 + if (learn_buffer_user == NULL)
73644 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73645 + if (learn_buffer == NULL) {
73646 + retval = -ENOMEM;
73647 + goto out_error;
73648 + }
73649 + if (learn_buffer_user == NULL) {
73650 + retval = -ENOMEM;
73651 + goto out_error;
73652 + }
73653 + learn_buffer_len = 0;
73654 + learn_buffer_user_len = 0;
73655 + gr_learn_attached = 1;
73656 +out_error:
73657 + mutex_unlock(&gr_learn_user_mutex);
73658 + return retval;
73659 + }
73660 + return 0;
73661 +}
73662 +
73663 +static int
73664 +close_learn(struct inode *inode, struct file *file)
73665 +{
73666 + if (file->f_mode & FMODE_READ) {
73667 + char *tmp = NULL;
73668 + mutex_lock(&gr_learn_user_mutex);
73669 + spin_lock(&gr_learn_lock);
73670 + tmp = learn_buffer;
73671 + learn_buffer = NULL;
73672 + spin_unlock(&gr_learn_lock);
73673 + if (tmp)
73674 + vfree(tmp);
73675 + if (learn_buffer_user != NULL) {
73676 + vfree(learn_buffer_user);
73677 + learn_buffer_user = NULL;
73678 + }
73679 + learn_buffer_len = 0;
73680 + learn_buffer_user_len = 0;
73681 + gr_learn_attached = 0;
73682 + mutex_unlock(&gr_learn_user_mutex);
73683 + }
73684 +
73685 + return 0;
73686 +}
73687 +
73688 +const struct file_operations grsec_fops = {
73689 + .read = read_learn,
73690 + .write = write_grsec_handler,
73691 + .open = open_learn,
73692 + .release = close_learn,
73693 + .poll = poll_learn,
73694 +};
73695 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73696 new file mode 100644
73697 index 0000000..3f8ade0
73698 --- /dev/null
73699 +++ b/grsecurity/gracl_policy.c
73700 @@ -0,0 +1,1782 @@
73701 +#include <linux/kernel.h>
73702 +#include <linux/module.h>
73703 +#include <linux/sched.h>
73704 +#include <linux/mm.h>
73705 +#include <linux/file.h>
73706 +#include <linux/fs.h>
73707 +#include <linux/namei.h>
73708 +#include <linux/mount.h>
73709 +#include <linux/tty.h>
73710 +#include <linux/proc_fs.h>
73711 +#include <linux/lglock.h>
73712 +#include <linux/slab.h>
73713 +#include <linux/vmalloc.h>
73714 +#include <linux/types.h>
73715 +#include <linux/sysctl.h>
73716 +#include <linux/netdevice.h>
73717 +#include <linux/ptrace.h>
73718 +#include <linux/gracl.h>
73719 +#include <linux/gralloc.h>
73720 +#include <linux/security.h>
73721 +#include <linux/grinternal.h>
73722 +#include <linux/pid_namespace.h>
73723 +#include <linux/stop_machine.h>
73724 +#include <linux/fdtable.h>
73725 +#include <linux/percpu.h>
73726 +#include <linux/lglock.h>
73727 +#include <linux/hugetlb.h>
73728 +#include <linux/posix-timers.h>
73729 +#include "../fs/mount.h"
73730 +
73731 +#include <asm/uaccess.h>
73732 +#include <asm/errno.h>
73733 +#include <asm/mman.h>
73734 +
73735 +extern struct gr_policy_state *polstate;
73736 +
73737 +#define FOR_EACH_ROLE_START(role) \
73738 + role = polstate->role_list; \
73739 + while (role) {
73740 +
73741 +#define FOR_EACH_ROLE_END(role) \
73742 + role = role->prev; \
73743 + }
73744 +
73745 +struct path gr_real_root;
73746 +
73747 +extern struct gr_alloc_state *current_alloc_state;
73748 +
73749 +u16 acl_sp_role_value;
73750 +
73751 +static DEFINE_MUTEX(gr_dev_mutex);
73752 +
73753 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73754 +extern void gr_clear_learn_entries(void);
73755 +
73756 +struct gr_arg *gr_usermode __read_only;
73757 +unsigned char *gr_system_salt __read_only;
73758 +unsigned char *gr_system_sum __read_only;
73759 +
73760 +static unsigned int gr_auth_attempts = 0;
73761 +static unsigned long gr_auth_expires = 0UL;
73762 +
73763 +struct acl_object_label *fakefs_obj_rw;
73764 +struct acl_object_label *fakefs_obj_rwx;
73765 +
73766 +extern int gr_init_uidset(void);
73767 +extern void gr_free_uidset(void);
73768 +extern void gr_remove_uid(uid_t uid);
73769 +extern int gr_find_uid(uid_t uid);
73770 +
73771 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73772 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73773 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73774 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73775 +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);
73776 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73777 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73778 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73779 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73780 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73781 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73782 +extern void assign_special_role(const char *rolename);
73783 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73784 +extern int gr_rbac_disable(void *unused);
73785 +extern void gr_enable_rbac_system(void);
73786 +
73787 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73788 +{
73789 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73790 + return -EFAULT;
73791 +
73792 + return 0;
73793 +}
73794 +
73795 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73796 +{
73797 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73798 + return -EFAULT;
73799 +
73800 + return 0;
73801 +}
73802 +
73803 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73804 +{
73805 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73806 + return -EFAULT;
73807 +
73808 + return 0;
73809 +}
73810 +
73811 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73812 +{
73813 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73814 + return -EFAULT;
73815 +
73816 + return 0;
73817 +}
73818 +
73819 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73820 +{
73821 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73822 + return -EFAULT;
73823 +
73824 + return 0;
73825 +}
73826 +
73827 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73828 +{
73829 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73830 + return -EFAULT;
73831 +
73832 + return 0;
73833 +}
73834 +
73835 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73836 +{
73837 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73838 + return -EFAULT;
73839 +
73840 + return 0;
73841 +}
73842 +
73843 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73844 +{
73845 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73846 + return -EFAULT;
73847 +
73848 + return 0;
73849 +}
73850 +
73851 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73852 +{
73853 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73854 + return -EFAULT;
73855 +
73856 + return 0;
73857 +}
73858 +
73859 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73860 +{
73861 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73862 + return -EFAULT;
73863 +
73864 + if (((uwrap->version != GRSECURITY_VERSION) &&
73865 + (uwrap->version != 0x2901)) ||
73866 + (uwrap->size != sizeof(struct gr_arg)))
73867 + return -EINVAL;
73868 +
73869 + return 0;
73870 +}
73871 +
73872 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73873 +{
73874 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73875 + return -EFAULT;
73876 +
73877 + return 0;
73878 +}
73879 +
73880 +static size_t get_gr_arg_wrapper_size_normal(void)
73881 +{
73882 + return sizeof(struct gr_arg_wrapper);
73883 +}
73884 +
73885 +#ifdef CONFIG_COMPAT
73886 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73887 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73888 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73889 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73890 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73891 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73892 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73893 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
73894 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
73895 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
73896 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
73897 +extern size_t get_gr_arg_wrapper_size_compat(void);
73898 +
73899 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
73900 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
73901 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
73902 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
73903 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
73904 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
73905 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
73906 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
73907 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
73908 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
73909 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
73910 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
73911 +
73912 +#else
73913 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
73914 +#define copy_gr_arg copy_gr_arg_normal
73915 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
73916 +#define copy_acl_object_label copy_acl_object_label_normal
73917 +#define copy_acl_subject_label copy_acl_subject_label_normal
73918 +#define copy_acl_role_label copy_acl_role_label_normal
73919 +#define copy_acl_ip_label copy_acl_ip_label_normal
73920 +#define copy_pointer_from_array copy_pointer_from_array_normal
73921 +#define copy_sprole_pw copy_sprole_pw_normal
73922 +#define copy_role_transition copy_role_transition_normal
73923 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
73924 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
73925 +#endif
73926 +
73927 +static struct acl_subject_label *
73928 +lookup_subject_map(const struct acl_subject_label *userp)
73929 +{
73930 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
73931 + struct subject_map *match;
73932 +
73933 + match = polstate->subj_map_set.s_hash[index];
73934 +
73935 + while (match && match->user != userp)
73936 + match = match->next;
73937 +
73938 + if (match != NULL)
73939 + return match->kernel;
73940 + else
73941 + return NULL;
73942 +}
73943 +
73944 +static void
73945 +insert_subj_map_entry(struct subject_map *subjmap)
73946 +{
73947 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
73948 + struct subject_map **curr;
73949 +
73950 + subjmap->prev = NULL;
73951 +
73952 + curr = &polstate->subj_map_set.s_hash[index];
73953 + if (*curr != NULL)
73954 + (*curr)->prev = subjmap;
73955 +
73956 + subjmap->next = *curr;
73957 + *curr = subjmap;
73958 +
73959 + return;
73960 +}
73961 +
73962 +static void
73963 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
73964 +{
73965 + unsigned int index =
73966 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
73967 + struct acl_role_label **curr;
73968 + struct acl_role_label *tmp, *tmp2;
73969 +
73970 + curr = &polstate->acl_role_set.r_hash[index];
73971 +
73972 + /* simple case, slot is empty, just set it to our role */
73973 + if (*curr == NULL) {
73974 + *curr = role;
73975 + } else {
73976 + /* example:
73977 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
73978 + 2 -> 3
73979 + */
73980 + /* first check to see if we can already be reached via this slot */
73981 + tmp = *curr;
73982 + while (tmp && tmp != role)
73983 + tmp = tmp->next;
73984 + if (tmp == role) {
73985 + /* we don't need to add ourselves to this slot's chain */
73986 + return;
73987 + }
73988 + /* we need to add ourselves to this chain, two cases */
73989 + if (role->next == NULL) {
73990 + /* simple case, append the current chain to our role */
73991 + role->next = *curr;
73992 + *curr = role;
73993 + } else {
73994 + /* 1 -> 2 -> 3 -> 4
73995 + 2 -> 3 -> 4
73996 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
73997 + */
73998 + /* trickier case: walk our role's chain until we find
73999 + the role for the start of the current slot's chain */
74000 + tmp = role;
74001 + tmp2 = *curr;
74002 + while (tmp->next && tmp->next != tmp2)
74003 + tmp = tmp->next;
74004 + if (tmp->next == tmp2) {
74005 + /* from example above, we found 3, so just
74006 + replace this slot's chain with ours */
74007 + *curr = role;
74008 + } else {
74009 + /* we didn't find a subset of our role's chain
74010 + in the current slot's chain, so append their
74011 + chain to ours, and set us as the first role in
74012 + the slot's chain
74013 +
74014 + we could fold this case with the case above,
74015 + but making it explicit for clarity
74016 + */
74017 + tmp->next = tmp2;
74018 + *curr = role;
74019 + }
74020 + }
74021 + }
74022 +
74023 + return;
74024 +}
74025 +
74026 +static void
74027 +insert_acl_role_label(struct acl_role_label *role)
74028 +{
74029 + int i;
74030 +
74031 + if (polstate->role_list == NULL) {
74032 + polstate->role_list = role;
74033 + role->prev = NULL;
74034 + } else {
74035 + role->prev = polstate->role_list;
74036 + polstate->role_list = role;
74037 + }
74038 +
74039 + /* used for hash chains */
74040 + role->next = NULL;
74041 +
74042 + if (role->roletype & GR_ROLE_DOMAIN) {
74043 + for (i = 0; i < role->domain_child_num; i++)
74044 + __insert_acl_role_label(role, role->domain_children[i]);
74045 + } else
74046 + __insert_acl_role_label(role, role->uidgid);
74047 +}
74048 +
74049 +static int
74050 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74051 +{
74052 + struct name_entry **curr, *nentry;
74053 + struct inodev_entry *ientry;
74054 + unsigned int len = strlen(name);
74055 + unsigned int key = full_name_hash(name, len);
74056 + unsigned int index = key % polstate->name_set.n_size;
74057 +
74058 + curr = &polstate->name_set.n_hash[index];
74059 +
74060 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74061 + curr = &((*curr)->next);
74062 +
74063 + if (*curr != NULL)
74064 + return 1;
74065 +
74066 + nentry = acl_alloc(sizeof (struct name_entry));
74067 + if (nentry == NULL)
74068 + return 0;
74069 + ientry = acl_alloc(sizeof (struct inodev_entry));
74070 + if (ientry == NULL)
74071 + return 0;
74072 + ientry->nentry = nentry;
74073 +
74074 + nentry->key = key;
74075 + nentry->name = name;
74076 + nentry->inode = inode;
74077 + nentry->device = device;
74078 + nentry->len = len;
74079 + nentry->deleted = deleted;
74080 +
74081 + nentry->prev = NULL;
74082 + curr = &polstate->name_set.n_hash[index];
74083 + if (*curr != NULL)
74084 + (*curr)->prev = nentry;
74085 + nentry->next = *curr;
74086 + *curr = nentry;
74087 +
74088 + /* insert us into the table searchable by inode/dev */
74089 + __insert_inodev_entry(polstate, ientry);
74090 +
74091 + return 1;
74092 +}
74093 +
74094 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74095 +
74096 +static void *
74097 +create_table(__u32 * len, int elementsize)
74098 +{
74099 + unsigned int table_sizes[] = {
74100 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74101 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74102 + 4194301, 8388593, 16777213, 33554393, 67108859
74103 + };
74104 + void *newtable = NULL;
74105 + unsigned int pwr = 0;
74106 +
74107 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74108 + table_sizes[pwr] <= *len)
74109 + pwr++;
74110 +
74111 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74112 + return newtable;
74113 +
74114 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74115 + newtable =
74116 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74117 + else
74118 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74119 +
74120 + *len = table_sizes[pwr];
74121 +
74122 + return newtable;
74123 +}
74124 +
74125 +static int
74126 +init_variables(const struct gr_arg *arg, bool reload)
74127 +{
74128 + struct task_struct *reaper = init_pid_ns.child_reaper;
74129 + unsigned int stacksize;
74130 +
74131 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74132 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74133 + polstate->name_set.n_size = arg->role_db.num_objects;
74134 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74135 +
74136 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74137 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74138 + return 1;
74139 +
74140 + if (!reload) {
74141 + if (!gr_init_uidset())
74142 + return 1;
74143 + }
74144 +
74145 + /* set up the stack that holds allocation info */
74146 +
74147 + stacksize = arg->role_db.num_pointers + 5;
74148 +
74149 + if (!acl_alloc_stack_init(stacksize))
74150 + return 1;
74151 +
74152 + if (!reload) {
74153 + /* grab reference for the real root dentry and vfsmount */
74154 + get_fs_root(reaper->fs, &gr_real_root);
74155 +
74156 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74157 + 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);
74158 +#endif
74159 +
74160 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74161 + if (fakefs_obj_rw == NULL)
74162 + return 1;
74163 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74164 +
74165 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74166 + if (fakefs_obj_rwx == NULL)
74167 + return 1;
74168 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74169 + }
74170 +
74171 + polstate->subj_map_set.s_hash =
74172 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74173 + polstate->acl_role_set.r_hash =
74174 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74175 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74176 + polstate->inodev_set.i_hash =
74177 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74178 +
74179 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74180 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74181 + return 1;
74182 +
74183 + memset(polstate->subj_map_set.s_hash, 0,
74184 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74185 + memset(polstate->acl_role_set.r_hash, 0,
74186 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74187 + memset(polstate->name_set.n_hash, 0,
74188 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74189 + memset(polstate->inodev_set.i_hash, 0,
74190 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74191 +
74192 + return 0;
74193 +}
74194 +
74195 +/* free information not needed after startup
74196 + currently contains user->kernel pointer mappings for subjects
74197 +*/
74198 +
74199 +static void
74200 +free_init_variables(void)
74201 +{
74202 + __u32 i;
74203 +
74204 + if (polstate->subj_map_set.s_hash) {
74205 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74206 + if (polstate->subj_map_set.s_hash[i]) {
74207 + kfree(polstate->subj_map_set.s_hash[i]);
74208 + polstate->subj_map_set.s_hash[i] = NULL;
74209 + }
74210 + }
74211 +
74212 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74213 + PAGE_SIZE)
74214 + kfree(polstate->subj_map_set.s_hash);
74215 + else
74216 + vfree(polstate->subj_map_set.s_hash);
74217 + }
74218 +
74219 + return;
74220 +}
74221 +
74222 +static void
74223 +free_variables(bool reload)
74224 +{
74225 + struct acl_subject_label *s;
74226 + struct acl_role_label *r;
74227 + struct task_struct *task, *task2;
74228 + unsigned int x;
74229 +
74230 + if (!reload) {
74231 + gr_clear_learn_entries();
74232 +
74233 + read_lock(&tasklist_lock);
74234 + do_each_thread(task2, task) {
74235 + task->acl_sp_role = 0;
74236 + task->acl_role_id = 0;
74237 + task->inherited = 0;
74238 + task->acl = NULL;
74239 + task->role = NULL;
74240 + } while_each_thread(task2, task);
74241 + read_unlock(&tasklist_lock);
74242 +
74243 + kfree(fakefs_obj_rw);
74244 + fakefs_obj_rw = NULL;
74245 + kfree(fakefs_obj_rwx);
74246 + fakefs_obj_rwx = NULL;
74247 +
74248 + /* release the reference to the real root dentry and vfsmount */
74249 + path_put(&gr_real_root);
74250 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74251 + }
74252 +
74253 + /* free all object hash tables */
74254 +
74255 + FOR_EACH_ROLE_START(r)
74256 + if (r->subj_hash == NULL)
74257 + goto next_role;
74258 + FOR_EACH_SUBJECT_START(r, s, x)
74259 + if (s->obj_hash == NULL)
74260 + break;
74261 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74262 + kfree(s->obj_hash);
74263 + else
74264 + vfree(s->obj_hash);
74265 + FOR_EACH_SUBJECT_END(s, x)
74266 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74267 + if (s->obj_hash == NULL)
74268 + break;
74269 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74270 + kfree(s->obj_hash);
74271 + else
74272 + vfree(s->obj_hash);
74273 + FOR_EACH_NESTED_SUBJECT_END(s)
74274 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74275 + kfree(r->subj_hash);
74276 + else
74277 + vfree(r->subj_hash);
74278 + r->subj_hash = NULL;
74279 +next_role:
74280 + FOR_EACH_ROLE_END(r)
74281 +
74282 + acl_free_all();
74283 +
74284 + if (polstate->acl_role_set.r_hash) {
74285 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74286 + PAGE_SIZE)
74287 + kfree(polstate->acl_role_set.r_hash);
74288 + else
74289 + vfree(polstate->acl_role_set.r_hash);
74290 + }
74291 + if (polstate->name_set.n_hash) {
74292 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74293 + PAGE_SIZE)
74294 + kfree(polstate->name_set.n_hash);
74295 + else
74296 + vfree(polstate->name_set.n_hash);
74297 + }
74298 +
74299 + if (polstate->inodev_set.i_hash) {
74300 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74301 + PAGE_SIZE)
74302 + kfree(polstate->inodev_set.i_hash);
74303 + else
74304 + vfree(polstate->inodev_set.i_hash);
74305 + }
74306 +
74307 + if (!reload)
74308 + gr_free_uidset();
74309 +
74310 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74311 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74312 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74313 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74314 +
74315 + polstate->default_role = NULL;
74316 + polstate->kernel_role = NULL;
74317 + polstate->role_list = NULL;
74318 +
74319 + return;
74320 +}
74321 +
74322 +static struct acl_subject_label *
74323 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74324 +
74325 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74326 +{
74327 + unsigned int len = strnlen_user(*name, maxlen);
74328 + char *tmp;
74329 +
74330 + if (!len || len >= maxlen)
74331 + return -EINVAL;
74332 +
74333 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74334 + return -ENOMEM;
74335 +
74336 + if (copy_from_user(tmp, *name, len))
74337 + return -EFAULT;
74338 +
74339 + tmp[len-1] = '\0';
74340 + *name = tmp;
74341 +
74342 + return 0;
74343 +}
74344 +
74345 +static int
74346 +copy_user_glob(struct acl_object_label *obj)
74347 +{
74348 + struct acl_object_label *g_tmp, **guser;
74349 + int error;
74350 +
74351 + if (obj->globbed == NULL)
74352 + return 0;
74353 +
74354 + guser = &obj->globbed;
74355 + while (*guser) {
74356 + g_tmp = (struct acl_object_label *)
74357 + acl_alloc(sizeof (struct acl_object_label));
74358 + if (g_tmp == NULL)
74359 + return -ENOMEM;
74360 +
74361 + if (copy_acl_object_label(g_tmp, *guser))
74362 + return -EFAULT;
74363 +
74364 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74365 + if (error)
74366 + return error;
74367 +
74368 + *guser = g_tmp;
74369 + guser = &(g_tmp->next);
74370 + }
74371 +
74372 + return 0;
74373 +}
74374 +
74375 +static int
74376 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74377 + struct acl_role_label *role)
74378 +{
74379 + struct acl_object_label *o_tmp;
74380 + int ret;
74381 +
74382 + while (userp) {
74383 + if ((o_tmp = (struct acl_object_label *)
74384 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74385 + return -ENOMEM;
74386 +
74387 + if (copy_acl_object_label(o_tmp, userp))
74388 + return -EFAULT;
74389 +
74390 + userp = o_tmp->prev;
74391 +
74392 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74393 + if (ret)
74394 + return ret;
74395 +
74396 + insert_acl_obj_label(o_tmp, subj);
74397 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74398 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74399 + return -ENOMEM;
74400 +
74401 + ret = copy_user_glob(o_tmp);
74402 + if (ret)
74403 + return ret;
74404 +
74405 + if (o_tmp->nested) {
74406 + int already_copied;
74407 +
74408 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74409 + if (IS_ERR(o_tmp->nested))
74410 + return PTR_ERR(o_tmp->nested);
74411 +
74412 + /* insert into nested subject list if we haven't copied this one yet
74413 + to prevent duplicate entries */
74414 + if (!already_copied) {
74415 + o_tmp->nested->next = role->hash->first;
74416 + role->hash->first = o_tmp->nested;
74417 + }
74418 + }
74419 + }
74420 +
74421 + return 0;
74422 +}
74423 +
74424 +static __u32
74425 +count_user_subjs(struct acl_subject_label *userp)
74426 +{
74427 + struct acl_subject_label s_tmp;
74428 + __u32 num = 0;
74429 +
74430 + while (userp) {
74431 + if (copy_acl_subject_label(&s_tmp, userp))
74432 + break;
74433 +
74434 + userp = s_tmp.prev;
74435 + }
74436 +
74437 + return num;
74438 +}
74439 +
74440 +static int
74441 +copy_user_allowedips(struct acl_role_label *rolep)
74442 +{
74443 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74444 +
74445 + ruserip = rolep->allowed_ips;
74446 +
74447 + while (ruserip) {
74448 + rlast = rtmp;
74449 +
74450 + if ((rtmp = (struct role_allowed_ip *)
74451 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74452 + return -ENOMEM;
74453 +
74454 + if (copy_role_allowed_ip(rtmp, ruserip))
74455 + return -EFAULT;
74456 +
74457 + ruserip = rtmp->prev;
74458 +
74459 + if (!rlast) {
74460 + rtmp->prev = NULL;
74461 + rolep->allowed_ips = rtmp;
74462 + } else {
74463 + rlast->next = rtmp;
74464 + rtmp->prev = rlast;
74465 + }
74466 +
74467 + if (!ruserip)
74468 + rtmp->next = NULL;
74469 + }
74470 +
74471 + return 0;
74472 +}
74473 +
74474 +static int
74475 +copy_user_transitions(struct acl_role_label *rolep)
74476 +{
74477 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74478 + int error;
74479 +
74480 + rusertp = rolep->transitions;
74481 +
74482 + while (rusertp) {
74483 + rlast = rtmp;
74484 +
74485 + if ((rtmp = (struct role_transition *)
74486 + acl_alloc(sizeof (struct role_transition))) == NULL)
74487 + return -ENOMEM;
74488 +
74489 + if (copy_role_transition(rtmp, rusertp))
74490 + return -EFAULT;
74491 +
74492 + rusertp = rtmp->prev;
74493 +
74494 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74495 + if (error)
74496 + return error;
74497 +
74498 + if (!rlast) {
74499 + rtmp->prev = NULL;
74500 + rolep->transitions = rtmp;
74501 + } else {
74502 + rlast->next = rtmp;
74503 + rtmp->prev = rlast;
74504 + }
74505 +
74506 + if (!rusertp)
74507 + rtmp->next = NULL;
74508 + }
74509 +
74510 + return 0;
74511 +}
74512 +
74513 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74514 +{
74515 + struct acl_object_label o_tmp;
74516 + __u32 num = 0;
74517 +
74518 + while (userp) {
74519 + if (copy_acl_object_label(&o_tmp, userp))
74520 + break;
74521 +
74522 + userp = o_tmp.prev;
74523 + num++;
74524 + }
74525 +
74526 + return num;
74527 +}
74528 +
74529 +static struct acl_subject_label *
74530 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74531 +{
74532 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74533 + __u32 num_objs;
74534 + struct acl_ip_label **i_tmp, *i_utmp2;
74535 + struct gr_hash_struct ghash;
74536 + struct subject_map *subjmap;
74537 + unsigned int i_num;
74538 + int err;
74539 +
74540 + if (already_copied != NULL)
74541 + *already_copied = 0;
74542 +
74543 + s_tmp = lookup_subject_map(userp);
74544 +
74545 + /* we've already copied this subject into the kernel, just return
74546 + the reference to it, and don't copy it over again
74547 + */
74548 + if (s_tmp) {
74549 + if (already_copied != NULL)
74550 + *already_copied = 1;
74551 + return(s_tmp);
74552 + }
74553 +
74554 + if ((s_tmp = (struct acl_subject_label *)
74555 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74556 + return ERR_PTR(-ENOMEM);
74557 +
74558 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74559 + if (subjmap == NULL)
74560 + return ERR_PTR(-ENOMEM);
74561 +
74562 + subjmap->user = userp;
74563 + subjmap->kernel = s_tmp;
74564 + insert_subj_map_entry(subjmap);
74565 +
74566 + if (copy_acl_subject_label(s_tmp, userp))
74567 + return ERR_PTR(-EFAULT);
74568 +
74569 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74570 + if (err)
74571 + return ERR_PTR(err);
74572 +
74573 + if (!strcmp(s_tmp->filename, "/"))
74574 + role->root_label = s_tmp;
74575 +
74576 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74577 + return ERR_PTR(-EFAULT);
74578 +
74579 + /* copy user and group transition tables */
74580 +
74581 + if (s_tmp->user_trans_num) {
74582 + uid_t *uidlist;
74583 +
74584 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74585 + if (uidlist == NULL)
74586 + return ERR_PTR(-ENOMEM);
74587 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74588 + return ERR_PTR(-EFAULT);
74589 +
74590 + s_tmp->user_transitions = uidlist;
74591 + }
74592 +
74593 + if (s_tmp->group_trans_num) {
74594 + gid_t *gidlist;
74595 +
74596 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74597 + if (gidlist == NULL)
74598 + return ERR_PTR(-ENOMEM);
74599 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74600 + return ERR_PTR(-EFAULT);
74601 +
74602 + s_tmp->group_transitions = gidlist;
74603 + }
74604 +
74605 + /* set up object hash table */
74606 + num_objs = count_user_objs(ghash.first);
74607 +
74608 + s_tmp->obj_hash_size = num_objs;
74609 + s_tmp->obj_hash =
74610 + (struct acl_object_label **)
74611 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74612 +
74613 + if (!s_tmp->obj_hash)
74614 + return ERR_PTR(-ENOMEM);
74615 +
74616 + memset(s_tmp->obj_hash, 0,
74617 + s_tmp->obj_hash_size *
74618 + sizeof (struct acl_object_label *));
74619 +
74620 + /* add in objects */
74621 + err = copy_user_objs(ghash.first, s_tmp, role);
74622 +
74623 + if (err)
74624 + return ERR_PTR(err);
74625 +
74626 + /* set pointer for parent subject */
74627 + if (s_tmp->parent_subject) {
74628 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74629 +
74630 + if (IS_ERR(s_tmp2))
74631 + return s_tmp2;
74632 +
74633 + s_tmp->parent_subject = s_tmp2;
74634 + }
74635 +
74636 + /* add in ip acls */
74637 +
74638 + if (!s_tmp->ip_num) {
74639 + s_tmp->ips = NULL;
74640 + goto insert;
74641 + }
74642 +
74643 + i_tmp =
74644 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74645 + sizeof (struct acl_ip_label *));
74646 +
74647 + if (!i_tmp)
74648 + return ERR_PTR(-ENOMEM);
74649 +
74650 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74651 + *(i_tmp + i_num) =
74652 + (struct acl_ip_label *)
74653 + acl_alloc(sizeof (struct acl_ip_label));
74654 + if (!*(i_tmp + i_num))
74655 + return ERR_PTR(-ENOMEM);
74656 +
74657 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74658 + return ERR_PTR(-EFAULT);
74659 +
74660 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74661 + return ERR_PTR(-EFAULT);
74662 +
74663 + if ((*(i_tmp + i_num))->iface == NULL)
74664 + continue;
74665 +
74666 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74667 + if (err)
74668 + return ERR_PTR(err);
74669 + }
74670 +
74671 + s_tmp->ips = i_tmp;
74672 +
74673 +insert:
74674 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74675 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74676 + return ERR_PTR(-ENOMEM);
74677 +
74678 + return s_tmp;
74679 +}
74680 +
74681 +static int
74682 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74683 +{
74684 + struct acl_subject_label s_pre;
74685 + struct acl_subject_label * ret;
74686 + int err;
74687 +
74688 + while (userp) {
74689 + if (copy_acl_subject_label(&s_pre, userp))
74690 + return -EFAULT;
74691 +
74692 + ret = do_copy_user_subj(userp, role, NULL);
74693 +
74694 + err = PTR_ERR(ret);
74695 + if (IS_ERR(ret))
74696 + return err;
74697 +
74698 + insert_acl_subj_label(ret, role);
74699 +
74700 + userp = s_pre.prev;
74701 + }
74702 +
74703 + return 0;
74704 +}
74705 +
74706 +static int
74707 +copy_user_acl(struct gr_arg *arg)
74708 +{
74709 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74710 + struct acl_subject_label *subj_list;
74711 + struct sprole_pw *sptmp;
74712 + struct gr_hash_struct *ghash;
74713 + uid_t *domainlist;
74714 + unsigned int r_num;
74715 + int err = 0;
74716 + __u16 i;
74717 + __u32 num_subjs;
74718 +
74719 + /* we need a default and kernel role */
74720 + if (arg->role_db.num_roles < 2)
74721 + return -EINVAL;
74722 +
74723 + /* copy special role authentication info from userspace */
74724 +
74725 + polstate->num_sprole_pws = arg->num_sprole_pws;
74726 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74727 +
74728 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74729 + return -ENOMEM;
74730 +
74731 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74732 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74733 + if (!sptmp)
74734 + return -ENOMEM;
74735 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74736 + return -EFAULT;
74737 +
74738 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74739 + if (err)
74740 + return err;
74741 +
74742 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74743 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74744 +#endif
74745 +
74746 + polstate->acl_special_roles[i] = sptmp;
74747 + }
74748 +
74749 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74750 +
74751 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74752 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74753 +
74754 + if (!r_tmp)
74755 + return -ENOMEM;
74756 +
74757 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74758 + return -EFAULT;
74759 +
74760 + if (copy_acl_role_label(r_tmp, r_utmp2))
74761 + return -EFAULT;
74762 +
74763 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74764 + if (err)
74765 + return err;
74766 +
74767 + if (!strcmp(r_tmp->rolename, "default")
74768 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74769 + polstate->default_role = r_tmp;
74770 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74771 + polstate->kernel_role = r_tmp;
74772 + }
74773 +
74774 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74775 + return -ENOMEM;
74776 +
74777 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74778 + return -EFAULT;
74779 +
74780 + r_tmp->hash = ghash;
74781 +
74782 + num_subjs = count_user_subjs(r_tmp->hash->first);
74783 +
74784 + r_tmp->subj_hash_size = num_subjs;
74785 + r_tmp->subj_hash =
74786 + (struct acl_subject_label **)
74787 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74788 +
74789 + if (!r_tmp->subj_hash)
74790 + return -ENOMEM;
74791 +
74792 + err = copy_user_allowedips(r_tmp);
74793 + if (err)
74794 + return err;
74795 +
74796 + /* copy domain info */
74797 + if (r_tmp->domain_children != NULL) {
74798 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74799 + if (domainlist == NULL)
74800 + return -ENOMEM;
74801 +
74802 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74803 + return -EFAULT;
74804 +
74805 + r_tmp->domain_children = domainlist;
74806 + }
74807 +
74808 + err = copy_user_transitions(r_tmp);
74809 + if (err)
74810 + return err;
74811 +
74812 + memset(r_tmp->subj_hash, 0,
74813 + r_tmp->subj_hash_size *
74814 + sizeof (struct acl_subject_label *));
74815 +
74816 + /* acquire the list of subjects, then NULL out
74817 + the list prior to parsing the subjects for this role,
74818 + as during this parsing the list is replaced with a list
74819 + of *nested* subjects for the role
74820 + */
74821 + subj_list = r_tmp->hash->first;
74822 +
74823 + /* set nested subject list to null */
74824 + r_tmp->hash->first = NULL;
74825 +
74826 + err = copy_user_subjs(subj_list, r_tmp);
74827 +
74828 + if (err)
74829 + return err;
74830 +
74831 + insert_acl_role_label(r_tmp);
74832 + }
74833 +
74834 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74835 + return -EINVAL;
74836 +
74837 + return err;
74838 +}
74839 +
74840 +static int gracl_reload_apply_policies(void *reload)
74841 +{
74842 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74843 + struct task_struct *task, *task2;
74844 + struct acl_role_label *role, *rtmp;
74845 + struct acl_subject_label *subj;
74846 + const struct cred *cred;
74847 + int role_applied;
74848 + int ret = 0;
74849 +
74850 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74851 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74852 +
74853 + /* first make sure we'll be able to apply the new policy cleanly */
74854 + do_each_thread(task2, task) {
74855 + if (task->exec_file == NULL)
74856 + continue;
74857 + role_applied = 0;
74858 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74859 + /* preserve special roles */
74860 + FOR_EACH_ROLE_START(role)
74861 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74862 + rtmp = task->role;
74863 + task->role = role;
74864 + role_applied = 1;
74865 + break;
74866 + }
74867 + FOR_EACH_ROLE_END(role)
74868 + }
74869 + if (!role_applied) {
74870 + cred = __task_cred(task);
74871 + rtmp = task->role;
74872 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74873 + }
74874 + /* this handles non-nested inherited subjects, nested subjects will still
74875 + be dropped currently */
74876 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74877 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
74878 + /* change the role back so that we've made no modifications to the policy */
74879 + task->role = rtmp;
74880 +
74881 + if (subj == NULL || task->tmpacl == NULL) {
74882 + ret = -EINVAL;
74883 + goto out;
74884 + }
74885 + } while_each_thread(task2, task);
74886 +
74887 + /* now actually apply the policy */
74888 +
74889 + do_each_thread(task2, task) {
74890 + if (task->exec_file) {
74891 + role_applied = 0;
74892 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74893 + /* preserve special roles */
74894 + FOR_EACH_ROLE_START(role)
74895 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74896 + task->role = role;
74897 + role_applied = 1;
74898 + break;
74899 + }
74900 + FOR_EACH_ROLE_END(role)
74901 + }
74902 + if (!role_applied) {
74903 + cred = __task_cred(task);
74904 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74905 + }
74906 + /* this handles non-nested inherited subjects, nested subjects will still
74907 + be dropped currently */
74908 + if (!reload_state->oldmode && task->inherited)
74909 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74910 + else {
74911 + /* looked up and tagged to the task previously */
74912 + subj = task->tmpacl;
74913 + }
74914 + /* subj will be non-null */
74915 + __gr_apply_subject_to_task(polstate, task, subj);
74916 + if (reload_state->oldmode) {
74917 + task->acl_role_id = 0;
74918 + task->acl_sp_role = 0;
74919 + task->inherited = 0;
74920 + }
74921 + } else {
74922 + // it's a kernel process
74923 + task->role = polstate->kernel_role;
74924 + task->acl = polstate->kernel_role->root_label;
74925 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
74926 + task->acl->mode &= ~GR_PROCFIND;
74927 +#endif
74928 + }
74929 + } while_each_thread(task2, task);
74930 +
74931 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
74932 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
74933 +
74934 +out:
74935 +
74936 + return ret;
74937 +}
74938 +
74939 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
74940 +{
74941 + struct gr_reload_state new_reload_state = { };
74942 + int err;
74943 +
74944 + new_reload_state.oldpolicy_ptr = polstate;
74945 + new_reload_state.oldalloc_ptr = current_alloc_state;
74946 + new_reload_state.oldmode = oldmode;
74947 +
74948 + current_alloc_state = &new_reload_state.newalloc;
74949 + polstate = &new_reload_state.newpolicy;
74950 +
74951 + /* everything relevant is now saved off, copy in the new policy */
74952 + if (init_variables(args, true)) {
74953 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
74954 + err = -ENOMEM;
74955 + goto error;
74956 + }
74957 +
74958 + err = copy_user_acl(args);
74959 + free_init_variables();
74960 + if (err)
74961 + goto error;
74962 + /* the new policy is copied in, with the old policy available via saved_state
74963 + first go through applying roles, making sure to preserve special roles
74964 + then apply new subjects, making sure to preserve inherited and nested subjects,
74965 + though currently only inherited subjects will be preserved
74966 + */
74967 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
74968 + if (err)
74969 + goto error;
74970 +
74971 + /* we've now applied the new policy, so restore the old policy state to free it */
74972 + polstate = &new_reload_state.oldpolicy;
74973 + current_alloc_state = &new_reload_state.oldalloc;
74974 + free_variables(true);
74975 +
74976 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
74977 + to running_polstate/current_alloc_state inside stop_machine
74978 + */
74979 + err = 0;
74980 + goto out;
74981 +error:
74982 + /* on error of loading the new policy, we'll just keep the previous
74983 + policy set around
74984 + */
74985 + free_variables(true);
74986 +
74987 + /* doesn't affect runtime, but maintains consistent state */
74988 +out:
74989 + polstate = new_reload_state.oldpolicy_ptr;
74990 + current_alloc_state = new_reload_state.oldalloc_ptr;
74991 +
74992 + return err;
74993 +}
74994 +
74995 +static int
74996 +gracl_init(struct gr_arg *args)
74997 +{
74998 + int error = 0;
74999 +
75000 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75001 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75002 +
75003 + if (init_variables(args, false)) {
75004 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75005 + error = -ENOMEM;
75006 + goto out;
75007 + }
75008 +
75009 + error = copy_user_acl(args);
75010 + free_init_variables();
75011 + if (error)
75012 + goto out;
75013 +
75014 + error = gr_set_acls(0);
75015 + if (error)
75016 + goto out;
75017 +
75018 + gr_enable_rbac_system();
75019 +
75020 + return 0;
75021 +
75022 +out:
75023 + free_variables(false);
75024 + return error;
75025 +}
75026 +
75027 +static int
75028 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75029 + unsigned char **sum)
75030 +{
75031 + struct acl_role_label *r;
75032 + struct role_allowed_ip *ipp;
75033 + struct role_transition *trans;
75034 + unsigned int i;
75035 + int found = 0;
75036 + u32 curr_ip = current->signal->curr_ip;
75037 +
75038 + current->signal->saved_ip = curr_ip;
75039 +
75040 + /* check transition table */
75041 +
75042 + for (trans = current->role->transitions; trans; trans = trans->next) {
75043 + if (!strcmp(rolename, trans->rolename)) {
75044 + found = 1;
75045 + break;
75046 + }
75047 + }
75048 +
75049 + if (!found)
75050 + return 0;
75051 +
75052 + /* handle special roles that do not require authentication
75053 + and check ip */
75054 +
75055 + FOR_EACH_ROLE_START(r)
75056 + if (!strcmp(rolename, r->rolename) &&
75057 + (r->roletype & GR_ROLE_SPECIAL)) {
75058 + found = 0;
75059 + if (r->allowed_ips != NULL) {
75060 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75061 + if ((ntohl(curr_ip) & ipp->netmask) ==
75062 + (ntohl(ipp->addr) & ipp->netmask))
75063 + found = 1;
75064 + }
75065 + } else
75066 + found = 2;
75067 + if (!found)
75068 + return 0;
75069 +
75070 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75071 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75072 + *salt = NULL;
75073 + *sum = NULL;
75074 + return 1;
75075 + }
75076 + }
75077 + FOR_EACH_ROLE_END(r)
75078 +
75079 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75080 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75081 + *salt = polstate->acl_special_roles[i]->salt;
75082 + *sum = polstate->acl_special_roles[i]->sum;
75083 + return 1;
75084 + }
75085 + }
75086 +
75087 + return 0;
75088 +}
75089 +
75090 +int gr_check_secure_terminal(struct task_struct *task)
75091 +{
75092 + struct task_struct *p, *p2, *p3;
75093 + struct files_struct *files;
75094 + struct fdtable *fdt;
75095 + struct file *our_file = NULL, *file;
75096 + int i;
75097 +
75098 + if (task->signal->tty == NULL)
75099 + return 1;
75100 +
75101 + files = get_files_struct(task);
75102 + if (files != NULL) {
75103 + rcu_read_lock();
75104 + fdt = files_fdtable(files);
75105 + for (i=0; i < fdt->max_fds; i++) {
75106 + file = fcheck_files(files, i);
75107 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75108 + get_file(file);
75109 + our_file = file;
75110 + }
75111 + }
75112 + rcu_read_unlock();
75113 + put_files_struct(files);
75114 + }
75115 +
75116 + if (our_file == NULL)
75117 + return 1;
75118 +
75119 + read_lock(&tasklist_lock);
75120 + do_each_thread(p2, p) {
75121 + files = get_files_struct(p);
75122 + if (files == NULL ||
75123 + (p->signal && p->signal->tty == task->signal->tty)) {
75124 + if (files != NULL)
75125 + put_files_struct(files);
75126 + continue;
75127 + }
75128 + rcu_read_lock();
75129 + fdt = files_fdtable(files);
75130 + for (i=0; i < fdt->max_fds; i++) {
75131 + file = fcheck_files(files, i);
75132 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75133 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75134 + p3 = task;
75135 + while (task_pid_nr(p3) > 0) {
75136 + if (p3 == p)
75137 + break;
75138 + p3 = p3->real_parent;
75139 + }
75140 + if (p3 == p)
75141 + break;
75142 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75143 + gr_handle_alertkill(p);
75144 + rcu_read_unlock();
75145 + put_files_struct(files);
75146 + read_unlock(&tasklist_lock);
75147 + fput(our_file);
75148 + return 0;
75149 + }
75150 + }
75151 + rcu_read_unlock();
75152 + put_files_struct(files);
75153 + } while_each_thread(p2, p);
75154 + read_unlock(&tasklist_lock);
75155 +
75156 + fput(our_file);
75157 + return 1;
75158 +}
75159 +
75160 +ssize_t
75161 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75162 +{
75163 + struct gr_arg_wrapper uwrap;
75164 + unsigned char *sprole_salt = NULL;
75165 + unsigned char *sprole_sum = NULL;
75166 + int error = 0;
75167 + int error2 = 0;
75168 + size_t req_count = 0;
75169 + unsigned char oldmode = 0;
75170 +
75171 + mutex_lock(&gr_dev_mutex);
75172 +
75173 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75174 + error = -EPERM;
75175 + goto out;
75176 + }
75177 +
75178 +#ifdef CONFIG_COMPAT
75179 + pax_open_kernel();
75180 + if (is_compat_task()) {
75181 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75182 + copy_gr_arg = &copy_gr_arg_compat;
75183 + copy_acl_object_label = &copy_acl_object_label_compat;
75184 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75185 + copy_acl_role_label = &copy_acl_role_label_compat;
75186 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75187 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75188 + copy_role_transition = &copy_role_transition_compat;
75189 + copy_sprole_pw = &copy_sprole_pw_compat;
75190 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75191 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75192 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75193 + } else {
75194 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75195 + copy_gr_arg = &copy_gr_arg_normal;
75196 + copy_acl_object_label = &copy_acl_object_label_normal;
75197 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75198 + copy_acl_role_label = &copy_acl_role_label_normal;
75199 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75200 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75201 + copy_role_transition = &copy_role_transition_normal;
75202 + copy_sprole_pw = &copy_sprole_pw_normal;
75203 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75204 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75205 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75206 + }
75207 + pax_close_kernel();
75208 +#endif
75209 +
75210 + req_count = get_gr_arg_wrapper_size();
75211 +
75212 + if (count != req_count) {
75213 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75214 + error = -EINVAL;
75215 + goto out;
75216 + }
75217 +
75218 +
75219 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75220 + gr_auth_expires = 0;
75221 + gr_auth_attempts = 0;
75222 + }
75223 +
75224 + error = copy_gr_arg_wrapper(buf, &uwrap);
75225 + if (error)
75226 + goto out;
75227 +
75228 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75229 + if (error)
75230 + goto out;
75231 +
75232 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75233 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75234 + time_after(gr_auth_expires, get_seconds())) {
75235 + error = -EBUSY;
75236 + goto out;
75237 + }
75238 +
75239 + /* if non-root trying to do anything other than use a special role,
75240 + do not attempt authentication, do not count towards authentication
75241 + locking
75242 + */
75243 +
75244 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75245 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75246 + gr_is_global_nonroot(current_uid())) {
75247 + error = -EPERM;
75248 + goto out;
75249 + }
75250 +
75251 + /* ensure pw and special role name are null terminated */
75252 +
75253 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75254 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75255 +
75256 + /* Okay.
75257 + * We have our enough of the argument structure..(we have yet
75258 + * to copy_from_user the tables themselves) . Copy the tables
75259 + * only if we need them, i.e. for loading operations. */
75260 +
75261 + switch (gr_usermode->mode) {
75262 + case GR_STATUS:
75263 + if (gr_acl_is_enabled()) {
75264 + error = 1;
75265 + if (!gr_check_secure_terminal(current))
75266 + error = 3;
75267 + } else
75268 + error = 2;
75269 + goto out;
75270 + case GR_SHUTDOWN:
75271 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75272 + stop_machine(gr_rbac_disable, NULL, NULL);
75273 + free_variables(false);
75274 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75275 + memset(gr_system_salt, 0, GR_SALT_LEN);
75276 + memset(gr_system_sum, 0, GR_SHA_LEN);
75277 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75278 + } else if (gr_acl_is_enabled()) {
75279 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75280 + error = -EPERM;
75281 + } else {
75282 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75283 + error = -EAGAIN;
75284 + }
75285 + break;
75286 + case GR_ENABLE:
75287 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75288 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75289 + else {
75290 + if (gr_acl_is_enabled())
75291 + error = -EAGAIN;
75292 + else
75293 + error = error2;
75294 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75295 + }
75296 + break;
75297 + case GR_OLDRELOAD:
75298 + oldmode = 1;
75299 + case GR_RELOAD:
75300 + if (!gr_acl_is_enabled()) {
75301 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75302 + error = -EAGAIN;
75303 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75304 + error2 = gracl_reload(gr_usermode, oldmode);
75305 + if (!error2)
75306 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75307 + else {
75308 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75309 + error = error2;
75310 + }
75311 + } else {
75312 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75313 + error = -EPERM;
75314 + }
75315 + break;
75316 + case GR_SEGVMOD:
75317 + if (unlikely(!gr_acl_is_enabled())) {
75318 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75319 + error = -EAGAIN;
75320 + break;
75321 + }
75322 +
75323 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75324 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75325 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75326 + struct acl_subject_label *segvacl;
75327 + segvacl =
75328 + lookup_acl_subj_label(gr_usermode->segv_inode,
75329 + gr_usermode->segv_device,
75330 + current->role);
75331 + if (segvacl) {
75332 + segvacl->crashes = 0;
75333 + segvacl->expires = 0;
75334 + }
75335 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75336 + gr_remove_uid(gr_usermode->segv_uid);
75337 + }
75338 + } else {
75339 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75340 + error = -EPERM;
75341 + }
75342 + break;
75343 + case GR_SPROLE:
75344 + case GR_SPROLEPAM:
75345 + if (unlikely(!gr_acl_is_enabled())) {
75346 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75347 + error = -EAGAIN;
75348 + break;
75349 + }
75350 +
75351 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75352 + current->role->expires = 0;
75353 + current->role->auth_attempts = 0;
75354 + }
75355 +
75356 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75357 + time_after(current->role->expires, get_seconds())) {
75358 + error = -EBUSY;
75359 + goto out;
75360 + }
75361 +
75362 + if (lookup_special_role_auth
75363 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75364 + && ((!sprole_salt && !sprole_sum)
75365 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75366 + char *p = "";
75367 + assign_special_role(gr_usermode->sp_role);
75368 + read_lock(&tasklist_lock);
75369 + if (current->real_parent)
75370 + p = current->real_parent->role->rolename;
75371 + read_unlock(&tasklist_lock);
75372 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75373 + p, acl_sp_role_value);
75374 + } else {
75375 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75376 + error = -EPERM;
75377 + if(!(current->role->auth_attempts++))
75378 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75379 +
75380 + goto out;
75381 + }
75382 + break;
75383 + case GR_UNSPROLE:
75384 + if (unlikely(!gr_acl_is_enabled())) {
75385 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75386 + error = -EAGAIN;
75387 + break;
75388 + }
75389 +
75390 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75391 + char *p = "";
75392 + int i = 0;
75393 +
75394 + read_lock(&tasklist_lock);
75395 + if (current->real_parent) {
75396 + p = current->real_parent->role->rolename;
75397 + i = current->real_parent->acl_role_id;
75398 + }
75399 + read_unlock(&tasklist_lock);
75400 +
75401 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75402 + gr_set_acls(1);
75403 + } else {
75404 + error = -EPERM;
75405 + goto out;
75406 + }
75407 + break;
75408 + default:
75409 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75410 + error = -EINVAL;
75411 + break;
75412 + }
75413 +
75414 + if (error != -EPERM)
75415 + goto out;
75416 +
75417 + if(!(gr_auth_attempts++))
75418 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75419 +
75420 + out:
75421 + mutex_unlock(&gr_dev_mutex);
75422 +
75423 + if (!error)
75424 + error = req_count;
75425 +
75426 + return error;
75427 +}
75428 +
75429 +int
75430 +gr_set_acls(const int type)
75431 +{
75432 + struct task_struct *task, *task2;
75433 + struct acl_role_label *role = current->role;
75434 + struct acl_subject_label *subj;
75435 + __u16 acl_role_id = current->acl_role_id;
75436 + const struct cred *cred;
75437 + int ret;
75438 +
75439 + rcu_read_lock();
75440 + read_lock(&tasklist_lock);
75441 + read_lock(&grsec_exec_file_lock);
75442 + do_each_thread(task2, task) {
75443 + /* check to see if we're called from the exit handler,
75444 + if so, only replace ACLs that have inherited the admin
75445 + ACL */
75446 +
75447 + if (type && (task->role != role ||
75448 + task->acl_role_id != acl_role_id))
75449 + continue;
75450 +
75451 + task->acl_role_id = 0;
75452 + task->acl_sp_role = 0;
75453 + task->inherited = 0;
75454 +
75455 + if (task->exec_file) {
75456 + cred = __task_cred(task);
75457 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75458 + subj = __gr_get_subject_for_task(polstate, task, NULL);
75459 + if (subj == NULL) {
75460 + ret = -EINVAL;
75461 + read_unlock(&grsec_exec_file_lock);
75462 + read_unlock(&tasklist_lock);
75463 + rcu_read_unlock();
75464 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75465 + return ret;
75466 + }
75467 + __gr_apply_subject_to_task(polstate, task, subj);
75468 + } else {
75469 + // it's a kernel process
75470 + task->role = polstate->kernel_role;
75471 + task->acl = polstate->kernel_role->root_label;
75472 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75473 + task->acl->mode &= ~GR_PROCFIND;
75474 +#endif
75475 + }
75476 + } while_each_thread(task2, task);
75477 + read_unlock(&grsec_exec_file_lock);
75478 + read_unlock(&tasklist_lock);
75479 + rcu_read_unlock();
75480 +
75481 + return 0;
75482 +}
75483 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75484 new file mode 100644
75485 index 0000000..39645c9
75486 --- /dev/null
75487 +++ b/grsecurity/gracl_res.c
75488 @@ -0,0 +1,68 @@
75489 +#include <linux/kernel.h>
75490 +#include <linux/sched.h>
75491 +#include <linux/gracl.h>
75492 +#include <linux/grinternal.h>
75493 +
75494 +static const char *restab_log[] = {
75495 + [RLIMIT_CPU] = "RLIMIT_CPU",
75496 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75497 + [RLIMIT_DATA] = "RLIMIT_DATA",
75498 + [RLIMIT_STACK] = "RLIMIT_STACK",
75499 + [RLIMIT_CORE] = "RLIMIT_CORE",
75500 + [RLIMIT_RSS] = "RLIMIT_RSS",
75501 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75502 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75503 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75504 + [RLIMIT_AS] = "RLIMIT_AS",
75505 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75506 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75507 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75508 + [RLIMIT_NICE] = "RLIMIT_NICE",
75509 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75510 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75511 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75512 +};
75513 +
75514 +void
75515 +gr_log_resource(const struct task_struct *task,
75516 + const int res, const unsigned long wanted, const int gt)
75517 +{
75518 + const struct cred *cred;
75519 + unsigned long rlim;
75520 +
75521 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75522 + return;
75523 +
75524 + // not yet supported resource
75525 + if (unlikely(!restab_log[res]))
75526 + return;
75527 +
75528 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75529 + rlim = task_rlimit_max(task, res);
75530 + else
75531 + rlim = task_rlimit(task, res);
75532 +
75533 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75534 + return;
75535 +
75536 + rcu_read_lock();
75537 + cred = __task_cred(task);
75538 +
75539 + if (res == RLIMIT_NPROC &&
75540 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75541 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75542 + goto out_rcu_unlock;
75543 + else if (res == RLIMIT_MEMLOCK &&
75544 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75545 + goto out_rcu_unlock;
75546 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75547 + goto out_rcu_unlock;
75548 + rcu_read_unlock();
75549 +
75550 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75551 +
75552 + return;
75553 +out_rcu_unlock:
75554 + rcu_read_unlock();
75555 + return;
75556 +}
75557 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75558 new file mode 100644
75559 index 0000000..2040e61
75560 --- /dev/null
75561 +++ b/grsecurity/gracl_segv.c
75562 @@ -0,0 +1,313 @@
75563 +#include <linux/kernel.h>
75564 +#include <linux/mm.h>
75565 +#include <asm/uaccess.h>
75566 +#include <asm/errno.h>
75567 +#include <asm/mman.h>
75568 +#include <net/sock.h>
75569 +#include <linux/file.h>
75570 +#include <linux/fs.h>
75571 +#include <linux/net.h>
75572 +#include <linux/in.h>
75573 +#include <linux/slab.h>
75574 +#include <linux/types.h>
75575 +#include <linux/sched.h>
75576 +#include <linux/timer.h>
75577 +#include <linux/gracl.h>
75578 +#include <linux/grsecurity.h>
75579 +#include <linux/grinternal.h>
75580 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75581 +#include <linux/magic.h>
75582 +#include <linux/pagemap.h>
75583 +#include "../fs/btrfs/async-thread.h"
75584 +#include "../fs/btrfs/ctree.h"
75585 +#include "../fs/btrfs/btrfs_inode.h"
75586 +#endif
75587 +
75588 +static struct crash_uid *uid_set;
75589 +static unsigned short uid_used;
75590 +static DEFINE_SPINLOCK(gr_uid_lock);
75591 +extern rwlock_t gr_inode_lock;
75592 +extern struct acl_subject_label *
75593 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75594 + struct acl_role_label *role);
75595 +
75596 +static inline dev_t __get_dev(const struct dentry *dentry)
75597 +{
75598 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75599 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75600 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75601 + else
75602 +#endif
75603 + return dentry->d_sb->s_dev;
75604 +}
75605 +
75606 +int
75607 +gr_init_uidset(void)
75608 +{
75609 + uid_set =
75610 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75611 + uid_used = 0;
75612 +
75613 + return uid_set ? 1 : 0;
75614 +}
75615 +
75616 +void
75617 +gr_free_uidset(void)
75618 +{
75619 + if (uid_set) {
75620 + struct crash_uid *tmpset;
75621 + spin_lock(&gr_uid_lock);
75622 + tmpset = uid_set;
75623 + uid_set = NULL;
75624 + uid_used = 0;
75625 + spin_unlock(&gr_uid_lock);
75626 + if (tmpset)
75627 + kfree(tmpset);
75628 + }
75629 +
75630 + return;
75631 +}
75632 +
75633 +int
75634 +gr_find_uid(const uid_t uid)
75635 +{
75636 + struct crash_uid *tmp = uid_set;
75637 + uid_t buid;
75638 + int low = 0, high = uid_used - 1, mid;
75639 +
75640 + while (high >= low) {
75641 + mid = (low + high) >> 1;
75642 + buid = tmp[mid].uid;
75643 + if (buid == uid)
75644 + return mid;
75645 + if (buid > uid)
75646 + high = mid - 1;
75647 + if (buid < uid)
75648 + low = mid + 1;
75649 + }
75650 +
75651 + return -1;
75652 +}
75653 +
75654 +static __inline__ void
75655 +gr_insertsort(void)
75656 +{
75657 + unsigned short i, j;
75658 + struct crash_uid index;
75659 +
75660 + for (i = 1; i < uid_used; i++) {
75661 + index = uid_set[i];
75662 + j = i;
75663 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75664 + uid_set[j] = uid_set[j - 1];
75665 + j--;
75666 + }
75667 + uid_set[j] = index;
75668 + }
75669 +
75670 + return;
75671 +}
75672 +
75673 +static __inline__ void
75674 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75675 +{
75676 + int loc;
75677 + uid_t uid = GR_GLOBAL_UID(kuid);
75678 +
75679 + if (uid_used == GR_UIDTABLE_MAX)
75680 + return;
75681 +
75682 + loc = gr_find_uid(uid);
75683 +
75684 + if (loc >= 0) {
75685 + uid_set[loc].expires = expires;
75686 + return;
75687 + }
75688 +
75689 + uid_set[uid_used].uid = uid;
75690 + uid_set[uid_used].expires = expires;
75691 + uid_used++;
75692 +
75693 + gr_insertsort();
75694 +
75695 + return;
75696 +}
75697 +
75698 +void
75699 +gr_remove_uid(const unsigned short loc)
75700 +{
75701 + unsigned short i;
75702 +
75703 + for (i = loc + 1; i < uid_used; i++)
75704 + uid_set[i - 1] = uid_set[i];
75705 +
75706 + uid_used--;
75707 +
75708 + return;
75709 +}
75710 +
75711 +int
75712 +gr_check_crash_uid(const kuid_t kuid)
75713 +{
75714 + int loc;
75715 + int ret = 0;
75716 + uid_t uid;
75717 +
75718 + if (unlikely(!gr_acl_is_enabled()))
75719 + return 0;
75720 +
75721 + uid = GR_GLOBAL_UID(kuid);
75722 +
75723 + spin_lock(&gr_uid_lock);
75724 + loc = gr_find_uid(uid);
75725 +
75726 + if (loc < 0)
75727 + goto out_unlock;
75728 +
75729 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75730 + gr_remove_uid(loc);
75731 + else
75732 + ret = 1;
75733 +
75734 +out_unlock:
75735 + spin_unlock(&gr_uid_lock);
75736 + return ret;
75737 +}
75738 +
75739 +static __inline__ int
75740 +proc_is_setxid(const struct cred *cred)
75741 +{
75742 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75743 + !uid_eq(cred->uid, cred->fsuid))
75744 + return 1;
75745 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75746 + !gid_eq(cred->gid, cred->fsgid))
75747 + return 1;
75748 +
75749 + return 0;
75750 +}
75751 +
75752 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75753 +
75754 +void
75755 +gr_handle_crash(struct task_struct *task, const int sig)
75756 +{
75757 + struct acl_subject_label *curr;
75758 + struct task_struct *tsk, *tsk2;
75759 + const struct cred *cred;
75760 + const struct cred *cred2;
75761 +
75762 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75763 + return;
75764 +
75765 + if (unlikely(!gr_acl_is_enabled()))
75766 + return;
75767 +
75768 + curr = task->acl;
75769 +
75770 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75771 + return;
75772 +
75773 + if (time_before_eq(curr->expires, get_seconds())) {
75774 + curr->expires = 0;
75775 + curr->crashes = 0;
75776 + }
75777 +
75778 + curr->crashes++;
75779 +
75780 + if (!curr->expires)
75781 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75782 +
75783 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75784 + time_after(curr->expires, get_seconds())) {
75785 + rcu_read_lock();
75786 + cred = __task_cred(task);
75787 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75788 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75789 + spin_lock(&gr_uid_lock);
75790 + gr_insert_uid(cred->uid, curr->expires);
75791 + spin_unlock(&gr_uid_lock);
75792 + curr->expires = 0;
75793 + curr->crashes = 0;
75794 + read_lock(&tasklist_lock);
75795 + do_each_thread(tsk2, tsk) {
75796 + cred2 = __task_cred(tsk);
75797 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
75798 + gr_fake_force_sig(SIGKILL, tsk);
75799 + } while_each_thread(tsk2, tsk);
75800 + read_unlock(&tasklist_lock);
75801 + } else {
75802 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75803 + read_lock(&tasklist_lock);
75804 + read_lock(&grsec_exec_file_lock);
75805 + do_each_thread(tsk2, tsk) {
75806 + if (likely(tsk != task)) {
75807 + // if this thread has the same subject as the one that triggered
75808 + // RES_CRASH and it's the same binary, kill it
75809 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75810 + gr_fake_force_sig(SIGKILL, tsk);
75811 + }
75812 + } while_each_thread(tsk2, tsk);
75813 + read_unlock(&grsec_exec_file_lock);
75814 + read_unlock(&tasklist_lock);
75815 + }
75816 + rcu_read_unlock();
75817 + }
75818 +
75819 + return;
75820 +}
75821 +
75822 +int
75823 +gr_check_crash_exec(const struct file *filp)
75824 +{
75825 + struct acl_subject_label *curr;
75826 +
75827 + if (unlikely(!gr_acl_is_enabled()))
75828 + return 0;
75829 +
75830 + read_lock(&gr_inode_lock);
75831 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75832 + __get_dev(filp->f_path.dentry),
75833 + current->role);
75834 + read_unlock(&gr_inode_lock);
75835 +
75836 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75837 + (!curr->crashes && !curr->expires))
75838 + return 0;
75839 +
75840 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75841 + time_after(curr->expires, get_seconds()))
75842 + return 1;
75843 + else if (time_before_eq(curr->expires, get_seconds())) {
75844 + curr->crashes = 0;
75845 + curr->expires = 0;
75846 + }
75847 +
75848 + return 0;
75849 +}
75850 +
75851 +void
75852 +gr_handle_alertkill(struct task_struct *task)
75853 +{
75854 + struct acl_subject_label *curracl;
75855 + __u32 curr_ip;
75856 + struct task_struct *p, *p2;
75857 +
75858 + if (unlikely(!gr_acl_is_enabled()))
75859 + return;
75860 +
75861 + curracl = task->acl;
75862 + curr_ip = task->signal->curr_ip;
75863 +
75864 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75865 + read_lock(&tasklist_lock);
75866 + do_each_thread(p2, p) {
75867 + if (p->signal->curr_ip == curr_ip)
75868 + gr_fake_force_sig(SIGKILL, p);
75869 + } while_each_thread(p2, p);
75870 + read_unlock(&tasklist_lock);
75871 + } else if (curracl->mode & GR_KILLPROC)
75872 + gr_fake_force_sig(SIGKILL, task);
75873 +
75874 + return;
75875 +}
75876 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75877 new file mode 100644
75878 index 0000000..6b0c9cc
75879 --- /dev/null
75880 +++ b/grsecurity/gracl_shm.c
75881 @@ -0,0 +1,40 @@
75882 +#include <linux/kernel.h>
75883 +#include <linux/mm.h>
75884 +#include <linux/sched.h>
75885 +#include <linux/file.h>
75886 +#include <linux/ipc.h>
75887 +#include <linux/gracl.h>
75888 +#include <linux/grsecurity.h>
75889 +#include <linux/grinternal.h>
75890 +
75891 +int
75892 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75893 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
75894 +{
75895 + struct task_struct *task;
75896 +
75897 + if (!gr_acl_is_enabled())
75898 + return 1;
75899 +
75900 + rcu_read_lock();
75901 + read_lock(&tasklist_lock);
75902 +
75903 + task = find_task_by_vpid(shm_cprid);
75904 +
75905 + if (unlikely(!task))
75906 + task = find_task_by_vpid(shm_lapid);
75907 +
75908 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
75909 + (task_pid_nr(task) == shm_lapid)) &&
75910 + (task->acl->mode & GR_PROTSHM) &&
75911 + (task->acl != current->acl))) {
75912 + read_unlock(&tasklist_lock);
75913 + rcu_read_unlock();
75914 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
75915 + return 0;
75916 + }
75917 + read_unlock(&tasklist_lock);
75918 + rcu_read_unlock();
75919 +
75920 + return 1;
75921 +}
75922 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
75923 new file mode 100644
75924 index 0000000..bc0be01
75925 --- /dev/null
75926 +++ b/grsecurity/grsec_chdir.c
75927 @@ -0,0 +1,19 @@
75928 +#include <linux/kernel.h>
75929 +#include <linux/sched.h>
75930 +#include <linux/fs.h>
75931 +#include <linux/file.h>
75932 +#include <linux/grsecurity.h>
75933 +#include <linux/grinternal.h>
75934 +
75935 +void
75936 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
75937 +{
75938 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75939 + if ((grsec_enable_chdir && grsec_enable_group &&
75940 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
75941 + !grsec_enable_group)) {
75942 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
75943 + }
75944 +#endif
75945 + return;
75946 +}
75947 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
75948 new file mode 100644
75949 index 0000000..6d99cec
75950 --- /dev/null
75951 +++ b/grsecurity/grsec_chroot.c
75952 @@ -0,0 +1,385 @@
75953 +#include <linux/kernel.h>
75954 +#include <linux/module.h>
75955 +#include <linux/sched.h>
75956 +#include <linux/file.h>
75957 +#include <linux/fs.h>
75958 +#include <linux/mount.h>
75959 +#include <linux/types.h>
75960 +#include "../fs/mount.h"
75961 +#include <linux/grsecurity.h>
75962 +#include <linux/grinternal.h>
75963 +
75964 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75965 +int gr_init_ran;
75966 +#endif
75967 +
75968 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
75969 +{
75970 +#ifdef CONFIG_GRKERNSEC
75971 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
75972 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
75973 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75974 + && gr_init_ran
75975 +#endif
75976 + )
75977 + task->gr_is_chrooted = 1;
75978 + else {
75979 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75980 + if (task_pid_nr(task) == 1 && !gr_init_ran)
75981 + gr_init_ran = 1;
75982 +#endif
75983 + task->gr_is_chrooted = 0;
75984 + }
75985 +
75986 + task->gr_chroot_dentry = path->dentry;
75987 +#endif
75988 + return;
75989 +}
75990 +
75991 +void gr_clear_chroot_entries(struct task_struct *task)
75992 +{
75993 +#ifdef CONFIG_GRKERNSEC
75994 + task->gr_is_chrooted = 0;
75995 + task->gr_chroot_dentry = NULL;
75996 +#endif
75997 + return;
75998 +}
75999 +
76000 +int
76001 +gr_handle_chroot_unix(const pid_t pid)
76002 +{
76003 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76004 + struct task_struct *p;
76005 +
76006 + if (unlikely(!grsec_enable_chroot_unix))
76007 + return 1;
76008 +
76009 + if (likely(!proc_is_chrooted(current)))
76010 + return 1;
76011 +
76012 + rcu_read_lock();
76013 + read_lock(&tasklist_lock);
76014 + p = find_task_by_vpid_unrestricted(pid);
76015 + if (unlikely(p && !have_same_root(current, p))) {
76016 + read_unlock(&tasklist_lock);
76017 + rcu_read_unlock();
76018 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76019 + return 0;
76020 + }
76021 + read_unlock(&tasklist_lock);
76022 + rcu_read_unlock();
76023 +#endif
76024 + return 1;
76025 +}
76026 +
76027 +int
76028 +gr_handle_chroot_nice(void)
76029 +{
76030 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76031 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76032 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76033 + return -EPERM;
76034 + }
76035 +#endif
76036 + return 0;
76037 +}
76038 +
76039 +int
76040 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76041 +{
76042 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76043 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76044 + && proc_is_chrooted(current)) {
76045 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76046 + return -EACCES;
76047 + }
76048 +#endif
76049 + return 0;
76050 +}
76051 +
76052 +int
76053 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76054 +{
76055 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76056 + struct task_struct *p;
76057 + int ret = 0;
76058 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76059 + return ret;
76060 +
76061 + read_lock(&tasklist_lock);
76062 + do_each_pid_task(pid, type, p) {
76063 + if (!have_same_root(current, p)) {
76064 + ret = 1;
76065 + goto out;
76066 + }
76067 + } while_each_pid_task(pid, type, p);
76068 +out:
76069 + read_unlock(&tasklist_lock);
76070 + return ret;
76071 +#endif
76072 + return 0;
76073 +}
76074 +
76075 +int
76076 +gr_pid_is_chrooted(struct task_struct *p)
76077 +{
76078 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76079 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76080 + return 0;
76081 +
76082 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76083 + !have_same_root(current, p)) {
76084 + return 1;
76085 + }
76086 +#endif
76087 + return 0;
76088 +}
76089 +
76090 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76091 +
76092 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76093 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76094 +{
76095 + struct path path, currentroot;
76096 + int ret = 0;
76097 +
76098 + path.dentry = (struct dentry *)u_dentry;
76099 + path.mnt = (struct vfsmount *)u_mnt;
76100 + get_fs_root(current->fs, &currentroot);
76101 + if (path_is_under(&path, &currentroot))
76102 + ret = 1;
76103 + path_put(&currentroot);
76104 +
76105 + return ret;
76106 +}
76107 +#endif
76108 +
76109 +int
76110 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76111 +{
76112 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76113 + if (!grsec_enable_chroot_fchdir)
76114 + return 1;
76115 +
76116 + if (!proc_is_chrooted(current))
76117 + return 1;
76118 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76119 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76120 + return 0;
76121 + }
76122 +#endif
76123 + return 1;
76124 +}
76125 +
76126 +int
76127 +gr_chroot_fhandle(void)
76128 +{
76129 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76130 + if (!grsec_enable_chroot_fchdir)
76131 + return 1;
76132 +
76133 + if (!proc_is_chrooted(current))
76134 + return 1;
76135 + else {
76136 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76137 + return 0;
76138 + }
76139 +#endif
76140 + return 1;
76141 +}
76142 +
76143 +int
76144 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76145 + const u64 shm_createtime)
76146 +{
76147 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76148 + struct task_struct *p;
76149 +
76150 + if (unlikely(!grsec_enable_chroot_shmat))
76151 + return 1;
76152 +
76153 + if (likely(!proc_is_chrooted(current)))
76154 + return 1;
76155 +
76156 + rcu_read_lock();
76157 + read_lock(&tasklist_lock);
76158 +
76159 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76160 + if (time_before_eq64(p->start_time, shm_createtime)) {
76161 + if (have_same_root(current, p)) {
76162 + goto allow;
76163 + } else {
76164 + read_unlock(&tasklist_lock);
76165 + rcu_read_unlock();
76166 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76167 + return 0;
76168 + }
76169 + }
76170 + /* creator exited, pid reuse, fall through to next check */
76171 + }
76172 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76173 + if (unlikely(!have_same_root(current, p))) {
76174 + read_unlock(&tasklist_lock);
76175 + rcu_read_unlock();
76176 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76177 + return 0;
76178 + }
76179 + }
76180 +
76181 +allow:
76182 + read_unlock(&tasklist_lock);
76183 + rcu_read_unlock();
76184 +#endif
76185 + return 1;
76186 +}
76187 +
76188 +void
76189 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76190 +{
76191 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76192 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76193 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76194 +#endif
76195 + return;
76196 +}
76197 +
76198 +int
76199 +gr_handle_chroot_mknod(const struct dentry *dentry,
76200 + const struct vfsmount *mnt, const int mode)
76201 +{
76202 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76203 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76204 + proc_is_chrooted(current)) {
76205 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76206 + return -EPERM;
76207 + }
76208 +#endif
76209 + return 0;
76210 +}
76211 +
76212 +int
76213 +gr_handle_chroot_mount(const struct dentry *dentry,
76214 + const struct vfsmount *mnt, const char *dev_name)
76215 +{
76216 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76217 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76218 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76219 + return -EPERM;
76220 + }
76221 +#endif
76222 + return 0;
76223 +}
76224 +
76225 +int
76226 +gr_handle_chroot_pivot(void)
76227 +{
76228 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76229 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76230 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76231 + return -EPERM;
76232 + }
76233 +#endif
76234 + return 0;
76235 +}
76236 +
76237 +int
76238 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76239 +{
76240 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76241 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76242 + !gr_is_outside_chroot(dentry, mnt)) {
76243 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76244 + return -EPERM;
76245 + }
76246 +#endif
76247 + return 0;
76248 +}
76249 +
76250 +extern const char *captab_log[];
76251 +extern int captab_log_entries;
76252 +
76253 +int
76254 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76255 +{
76256 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76257 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76258 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76259 + if (cap_raised(chroot_caps, cap)) {
76260 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76261 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76262 + }
76263 + return 0;
76264 + }
76265 + }
76266 +#endif
76267 + return 1;
76268 +}
76269 +
76270 +int
76271 +gr_chroot_is_capable(const int cap)
76272 +{
76273 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76274 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76275 +#endif
76276 + return 1;
76277 +}
76278 +
76279 +int
76280 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76281 +{
76282 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76283 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76284 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76285 + if (cap_raised(chroot_caps, cap)) {
76286 + return 0;
76287 + }
76288 + }
76289 +#endif
76290 + return 1;
76291 +}
76292 +
76293 +int
76294 +gr_chroot_is_capable_nolog(const int cap)
76295 +{
76296 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76297 + return gr_task_chroot_is_capable_nolog(current, cap);
76298 +#endif
76299 + return 1;
76300 +}
76301 +
76302 +int
76303 +gr_handle_chroot_sysctl(const int op)
76304 +{
76305 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76306 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76307 + proc_is_chrooted(current))
76308 + return -EACCES;
76309 +#endif
76310 + return 0;
76311 +}
76312 +
76313 +void
76314 +gr_handle_chroot_chdir(const struct path *path)
76315 +{
76316 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76317 + if (grsec_enable_chroot_chdir)
76318 + set_fs_pwd(current->fs, path);
76319 +#endif
76320 + return;
76321 +}
76322 +
76323 +int
76324 +gr_handle_chroot_chmod(const struct dentry *dentry,
76325 + const struct vfsmount *mnt, const int mode)
76326 +{
76327 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76328 + /* allow chmod +s on directories, but not files */
76329 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76330 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76331 + proc_is_chrooted(current)) {
76332 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76333 + return -EPERM;
76334 + }
76335 +#endif
76336 + return 0;
76337 +}
76338 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76339 new file mode 100644
76340 index 0000000..0f9ac91
76341 --- /dev/null
76342 +++ b/grsecurity/grsec_disabled.c
76343 @@ -0,0 +1,440 @@
76344 +#include <linux/kernel.h>
76345 +#include <linux/module.h>
76346 +#include <linux/sched.h>
76347 +#include <linux/file.h>
76348 +#include <linux/fs.h>
76349 +#include <linux/kdev_t.h>
76350 +#include <linux/net.h>
76351 +#include <linux/in.h>
76352 +#include <linux/ip.h>
76353 +#include <linux/skbuff.h>
76354 +#include <linux/sysctl.h>
76355 +
76356 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76357 +void
76358 +pax_set_initial_flags(struct linux_binprm *bprm)
76359 +{
76360 + return;
76361 +}
76362 +#endif
76363 +
76364 +#ifdef CONFIG_SYSCTL
76365 +__u32
76366 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76367 +{
76368 + return 0;
76369 +}
76370 +#endif
76371 +
76372 +#ifdef CONFIG_TASKSTATS
76373 +int gr_is_taskstats_denied(int pid)
76374 +{
76375 + return 0;
76376 +}
76377 +#endif
76378 +
76379 +int
76380 +gr_acl_is_enabled(void)
76381 +{
76382 + return 0;
76383 +}
76384 +
76385 +int
76386 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76387 +{
76388 + return 0;
76389 +}
76390 +
76391 +void
76392 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76393 +{
76394 + return;
76395 +}
76396 +
76397 +int
76398 +gr_handle_rawio(const struct inode *inode)
76399 +{
76400 + return 0;
76401 +}
76402 +
76403 +void
76404 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76405 +{
76406 + return;
76407 +}
76408 +
76409 +int
76410 +gr_handle_ptrace(struct task_struct *task, const long request)
76411 +{
76412 + return 0;
76413 +}
76414 +
76415 +int
76416 +gr_handle_proc_ptrace(struct task_struct *task)
76417 +{
76418 + return 0;
76419 +}
76420 +
76421 +int
76422 +gr_set_acls(const int type)
76423 +{
76424 + return 0;
76425 +}
76426 +
76427 +int
76428 +gr_check_hidden_task(const struct task_struct *tsk)
76429 +{
76430 + return 0;
76431 +}
76432 +
76433 +int
76434 +gr_check_protected_task(const struct task_struct *task)
76435 +{
76436 + return 0;
76437 +}
76438 +
76439 +int
76440 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76441 +{
76442 + return 0;
76443 +}
76444 +
76445 +void
76446 +gr_copy_label(struct task_struct *tsk)
76447 +{
76448 + return;
76449 +}
76450 +
76451 +void
76452 +gr_set_pax_flags(struct task_struct *task)
76453 +{
76454 + return;
76455 +}
76456 +
76457 +int
76458 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76459 + const int unsafe_share)
76460 +{
76461 + return 0;
76462 +}
76463 +
76464 +void
76465 +gr_handle_delete(const ino_t ino, const dev_t dev)
76466 +{
76467 + return;
76468 +}
76469 +
76470 +void
76471 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76472 +{
76473 + return;
76474 +}
76475 +
76476 +void
76477 +gr_handle_crash(struct task_struct *task, const int sig)
76478 +{
76479 + return;
76480 +}
76481 +
76482 +int
76483 +gr_check_crash_exec(const struct file *filp)
76484 +{
76485 + return 0;
76486 +}
76487 +
76488 +int
76489 +gr_check_crash_uid(const kuid_t uid)
76490 +{
76491 + return 0;
76492 +}
76493 +
76494 +void
76495 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76496 + struct dentry *old_dentry,
76497 + struct dentry *new_dentry,
76498 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76499 +{
76500 + return;
76501 +}
76502 +
76503 +int
76504 +gr_search_socket(const int family, const int type, const int protocol)
76505 +{
76506 + return 1;
76507 +}
76508 +
76509 +int
76510 +gr_search_connectbind(const int mode, const struct socket *sock,
76511 + const struct sockaddr_in *addr)
76512 +{
76513 + return 0;
76514 +}
76515 +
76516 +void
76517 +gr_handle_alertkill(struct task_struct *task)
76518 +{
76519 + return;
76520 +}
76521 +
76522 +__u32
76523 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76524 +{
76525 + return 1;
76526 +}
76527 +
76528 +__u32
76529 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76530 + const struct vfsmount * mnt)
76531 +{
76532 + return 1;
76533 +}
76534 +
76535 +__u32
76536 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76537 + int acc_mode)
76538 +{
76539 + return 1;
76540 +}
76541 +
76542 +__u32
76543 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76544 +{
76545 + return 1;
76546 +}
76547 +
76548 +__u32
76549 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76550 +{
76551 + return 1;
76552 +}
76553 +
76554 +int
76555 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76556 + unsigned int *vm_flags)
76557 +{
76558 + return 1;
76559 +}
76560 +
76561 +__u32
76562 +gr_acl_handle_truncate(const struct dentry * dentry,
76563 + const struct vfsmount * mnt)
76564 +{
76565 + return 1;
76566 +}
76567 +
76568 +__u32
76569 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76570 +{
76571 + return 1;
76572 +}
76573 +
76574 +__u32
76575 +gr_acl_handle_access(const struct dentry * dentry,
76576 + const struct vfsmount * mnt, const int fmode)
76577 +{
76578 + return 1;
76579 +}
76580 +
76581 +__u32
76582 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76583 + umode_t *mode)
76584 +{
76585 + return 1;
76586 +}
76587 +
76588 +__u32
76589 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76590 +{
76591 + return 1;
76592 +}
76593 +
76594 +__u32
76595 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76596 +{
76597 + return 1;
76598 +}
76599 +
76600 +__u32
76601 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76602 +{
76603 + return 1;
76604 +}
76605 +
76606 +void
76607 +grsecurity_init(void)
76608 +{
76609 + return;
76610 +}
76611 +
76612 +umode_t gr_acl_umask(void)
76613 +{
76614 + return 0;
76615 +}
76616 +
76617 +__u32
76618 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76619 + const struct dentry * parent_dentry,
76620 + const struct vfsmount * parent_mnt,
76621 + const int mode)
76622 +{
76623 + return 1;
76624 +}
76625 +
76626 +__u32
76627 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76628 + const struct dentry * parent_dentry,
76629 + const struct vfsmount * parent_mnt)
76630 +{
76631 + return 1;
76632 +}
76633 +
76634 +__u32
76635 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76636 + const struct dentry * parent_dentry,
76637 + const struct vfsmount * parent_mnt, const struct filename *from)
76638 +{
76639 + return 1;
76640 +}
76641 +
76642 +__u32
76643 +gr_acl_handle_link(const struct dentry * new_dentry,
76644 + const struct dentry * parent_dentry,
76645 + const struct vfsmount * parent_mnt,
76646 + const struct dentry * old_dentry,
76647 + const struct vfsmount * old_mnt, const struct filename *to)
76648 +{
76649 + return 1;
76650 +}
76651 +
76652 +int
76653 +gr_acl_handle_rename(const struct dentry *new_dentry,
76654 + const struct dentry *parent_dentry,
76655 + const struct vfsmount *parent_mnt,
76656 + const struct dentry *old_dentry,
76657 + const struct inode *old_parent_inode,
76658 + const struct vfsmount *old_mnt, const struct filename *newname,
76659 + unsigned int flags)
76660 +{
76661 + return 0;
76662 +}
76663 +
76664 +int
76665 +gr_acl_handle_filldir(const struct file *file, const char *name,
76666 + const int namelen, const ino_t ino)
76667 +{
76668 + return 1;
76669 +}
76670 +
76671 +int
76672 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76673 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76674 +{
76675 + return 1;
76676 +}
76677 +
76678 +int
76679 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76680 +{
76681 + return 0;
76682 +}
76683 +
76684 +int
76685 +gr_search_accept(const struct socket *sock)
76686 +{
76687 + return 0;
76688 +}
76689 +
76690 +int
76691 +gr_search_listen(const struct socket *sock)
76692 +{
76693 + return 0;
76694 +}
76695 +
76696 +int
76697 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76698 +{
76699 + return 0;
76700 +}
76701 +
76702 +__u32
76703 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76704 +{
76705 + return 1;
76706 +}
76707 +
76708 +__u32
76709 +gr_acl_handle_creat(const struct dentry * dentry,
76710 + const struct dentry * p_dentry,
76711 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76712 + const int imode)
76713 +{
76714 + return 1;
76715 +}
76716 +
76717 +void
76718 +gr_acl_handle_exit(void)
76719 +{
76720 + return;
76721 +}
76722 +
76723 +int
76724 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76725 +{
76726 + return 1;
76727 +}
76728 +
76729 +void
76730 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
76731 +{
76732 + return;
76733 +}
76734 +
76735 +int
76736 +gr_acl_handle_procpidmem(const struct task_struct *task)
76737 +{
76738 + return 0;
76739 +}
76740 +
76741 +int
76742 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76743 +{
76744 + return 0;
76745 +}
76746 +
76747 +int
76748 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76749 +{
76750 + return 0;
76751 +}
76752 +
76753 +int
76754 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76755 +{
76756 + return 0;
76757 +}
76758 +
76759 +int
76760 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76761 +{
76762 + return 0;
76763 +}
76764 +
76765 +int gr_acl_enable_at_secure(void)
76766 +{
76767 + return 0;
76768 +}
76769 +
76770 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76771 +{
76772 + return dentry->d_sb->s_dev;
76773 +}
76774 +
76775 +void gr_put_exec_file(struct task_struct *task)
76776 +{
76777 + return;
76778 +}
76779 +
76780 +#ifdef CONFIG_SECURITY
76781 +EXPORT_SYMBOL_GPL(gr_check_user_change);
76782 +EXPORT_SYMBOL_GPL(gr_check_group_change);
76783 +#endif
76784 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76785 new file mode 100644
76786 index 0000000..14638ff
76787 --- /dev/null
76788 +++ b/grsecurity/grsec_exec.c
76789 @@ -0,0 +1,188 @@
76790 +#include <linux/kernel.h>
76791 +#include <linux/sched.h>
76792 +#include <linux/file.h>
76793 +#include <linux/binfmts.h>
76794 +#include <linux/fs.h>
76795 +#include <linux/types.h>
76796 +#include <linux/grdefs.h>
76797 +#include <linux/grsecurity.h>
76798 +#include <linux/grinternal.h>
76799 +#include <linux/capability.h>
76800 +#include <linux/module.h>
76801 +#include <linux/compat.h>
76802 +
76803 +#include <asm/uaccess.h>
76804 +
76805 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76806 +static char gr_exec_arg_buf[132];
76807 +static DEFINE_MUTEX(gr_exec_arg_mutex);
76808 +#endif
76809 +
76810 +struct user_arg_ptr {
76811 +#ifdef CONFIG_COMPAT
76812 + bool is_compat;
76813 +#endif
76814 + union {
76815 + const char __user *const __user *native;
76816 +#ifdef CONFIG_COMPAT
76817 + const compat_uptr_t __user *compat;
76818 +#endif
76819 + } ptr;
76820 +};
76821 +
76822 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76823 +
76824 +void
76825 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76826 +{
76827 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76828 + char *grarg = gr_exec_arg_buf;
76829 + unsigned int i, x, execlen = 0;
76830 + char c;
76831 +
76832 + if (!((grsec_enable_execlog && grsec_enable_group &&
76833 + in_group_p(grsec_audit_gid))
76834 + || (grsec_enable_execlog && !grsec_enable_group)))
76835 + return;
76836 +
76837 + mutex_lock(&gr_exec_arg_mutex);
76838 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
76839 +
76840 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
76841 + const char __user *p;
76842 + unsigned int len;
76843 +
76844 + p = get_user_arg_ptr(argv, i);
76845 + if (IS_ERR(p))
76846 + goto log;
76847 +
76848 + len = strnlen_user(p, 128 - execlen);
76849 + if (len > 128 - execlen)
76850 + len = 128 - execlen;
76851 + else if (len > 0)
76852 + len--;
76853 + if (copy_from_user(grarg + execlen, p, len))
76854 + goto log;
76855 +
76856 + /* rewrite unprintable characters */
76857 + for (x = 0; x < len; x++) {
76858 + c = *(grarg + execlen + x);
76859 + if (c < 32 || c > 126)
76860 + *(grarg + execlen + x) = ' ';
76861 + }
76862 +
76863 + execlen += len;
76864 + *(grarg + execlen) = ' ';
76865 + *(grarg + execlen + 1) = '\0';
76866 + execlen++;
76867 + }
76868 +
76869 + log:
76870 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76871 + bprm->file->f_path.mnt, grarg);
76872 + mutex_unlock(&gr_exec_arg_mutex);
76873 +#endif
76874 + return;
76875 +}
76876 +
76877 +#ifdef CONFIG_GRKERNSEC
76878 +extern int gr_acl_is_capable(const int cap);
76879 +extern int gr_acl_is_capable_nolog(const int cap);
76880 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76881 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
76882 +extern int gr_chroot_is_capable(const int cap);
76883 +extern int gr_chroot_is_capable_nolog(const int cap);
76884 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76885 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
76886 +#endif
76887 +
76888 +const char *captab_log[] = {
76889 + "CAP_CHOWN",
76890 + "CAP_DAC_OVERRIDE",
76891 + "CAP_DAC_READ_SEARCH",
76892 + "CAP_FOWNER",
76893 + "CAP_FSETID",
76894 + "CAP_KILL",
76895 + "CAP_SETGID",
76896 + "CAP_SETUID",
76897 + "CAP_SETPCAP",
76898 + "CAP_LINUX_IMMUTABLE",
76899 + "CAP_NET_BIND_SERVICE",
76900 + "CAP_NET_BROADCAST",
76901 + "CAP_NET_ADMIN",
76902 + "CAP_NET_RAW",
76903 + "CAP_IPC_LOCK",
76904 + "CAP_IPC_OWNER",
76905 + "CAP_SYS_MODULE",
76906 + "CAP_SYS_RAWIO",
76907 + "CAP_SYS_CHROOT",
76908 + "CAP_SYS_PTRACE",
76909 + "CAP_SYS_PACCT",
76910 + "CAP_SYS_ADMIN",
76911 + "CAP_SYS_BOOT",
76912 + "CAP_SYS_NICE",
76913 + "CAP_SYS_RESOURCE",
76914 + "CAP_SYS_TIME",
76915 + "CAP_SYS_TTY_CONFIG",
76916 + "CAP_MKNOD",
76917 + "CAP_LEASE",
76918 + "CAP_AUDIT_WRITE",
76919 + "CAP_AUDIT_CONTROL",
76920 + "CAP_SETFCAP",
76921 + "CAP_MAC_OVERRIDE",
76922 + "CAP_MAC_ADMIN",
76923 + "CAP_SYSLOG",
76924 + "CAP_WAKE_ALARM",
76925 + "CAP_BLOCK_SUSPEND"
76926 +};
76927 +
76928 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
76929 +
76930 +int gr_is_capable(const int cap)
76931 +{
76932 +#ifdef CONFIG_GRKERNSEC
76933 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
76934 + return 1;
76935 + return 0;
76936 +#else
76937 + return 1;
76938 +#endif
76939 +}
76940 +
76941 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76942 +{
76943 +#ifdef CONFIG_GRKERNSEC
76944 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
76945 + return 1;
76946 + return 0;
76947 +#else
76948 + return 1;
76949 +#endif
76950 +}
76951 +
76952 +int gr_is_capable_nolog(const int cap)
76953 +{
76954 +#ifdef CONFIG_GRKERNSEC
76955 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
76956 + return 1;
76957 + return 0;
76958 +#else
76959 + return 1;
76960 +#endif
76961 +}
76962 +
76963 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
76964 +{
76965 +#ifdef CONFIG_GRKERNSEC
76966 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
76967 + return 1;
76968 + return 0;
76969 +#else
76970 + return 1;
76971 +#endif
76972 +}
76973 +
76974 +EXPORT_SYMBOL_GPL(gr_is_capable);
76975 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
76976 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
76977 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
76978 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
76979 new file mode 100644
76980 index 0000000..06cc6ea
76981 --- /dev/null
76982 +++ b/grsecurity/grsec_fifo.c
76983 @@ -0,0 +1,24 @@
76984 +#include <linux/kernel.h>
76985 +#include <linux/sched.h>
76986 +#include <linux/fs.h>
76987 +#include <linux/file.h>
76988 +#include <linux/grinternal.h>
76989 +
76990 +int
76991 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
76992 + const struct dentry *dir, const int flag, const int acc_mode)
76993 +{
76994 +#ifdef CONFIG_GRKERNSEC_FIFO
76995 + const struct cred *cred = current_cred();
76996 +
76997 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
76998 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
76999 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77000 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77001 + if (!inode_permission(dentry->d_inode, acc_mode))
77002 + 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));
77003 + return -EACCES;
77004 + }
77005 +#endif
77006 + return 0;
77007 +}
77008 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77009 new file mode 100644
77010 index 0000000..8ca18bf
77011 --- /dev/null
77012 +++ b/grsecurity/grsec_fork.c
77013 @@ -0,0 +1,23 @@
77014 +#include <linux/kernel.h>
77015 +#include <linux/sched.h>
77016 +#include <linux/grsecurity.h>
77017 +#include <linux/grinternal.h>
77018 +#include <linux/errno.h>
77019 +
77020 +void
77021 +gr_log_forkfail(const int retval)
77022 +{
77023 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77024 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77025 + switch (retval) {
77026 + case -EAGAIN:
77027 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77028 + break;
77029 + case -ENOMEM:
77030 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77031 + break;
77032 + }
77033 + }
77034 +#endif
77035 + return;
77036 +}
77037 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77038 new file mode 100644
77039 index 0000000..b7cb191
77040 --- /dev/null
77041 +++ b/grsecurity/grsec_init.c
77042 @@ -0,0 +1,286 @@
77043 +#include <linux/kernel.h>
77044 +#include <linux/sched.h>
77045 +#include <linux/mm.h>
77046 +#include <linux/gracl.h>
77047 +#include <linux/slab.h>
77048 +#include <linux/vmalloc.h>
77049 +#include <linux/percpu.h>
77050 +#include <linux/module.h>
77051 +
77052 +int grsec_enable_ptrace_readexec;
77053 +int grsec_enable_setxid;
77054 +int grsec_enable_symlinkown;
77055 +kgid_t grsec_symlinkown_gid;
77056 +int grsec_enable_brute;
77057 +int grsec_enable_link;
77058 +int grsec_enable_dmesg;
77059 +int grsec_enable_harden_ptrace;
77060 +int grsec_enable_harden_ipc;
77061 +int grsec_enable_fifo;
77062 +int grsec_enable_execlog;
77063 +int grsec_enable_signal;
77064 +int grsec_enable_forkfail;
77065 +int grsec_enable_audit_ptrace;
77066 +int grsec_enable_time;
77067 +int grsec_enable_group;
77068 +kgid_t grsec_audit_gid;
77069 +int grsec_enable_chdir;
77070 +int grsec_enable_mount;
77071 +int grsec_enable_rofs;
77072 +int grsec_deny_new_usb;
77073 +int grsec_enable_chroot_findtask;
77074 +int grsec_enable_chroot_mount;
77075 +int grsec_enable_chroot_shmat;
77076 +int grsec_enable_chroot_fchdir;
77077 +int grsec_enable_chroot_double;
77078 +int grsec_enable_chroot_pivot;
77079 +int grsec_enable_chroot_chdir;
77080 +int grsec_enable_chroot_chmod;
77081 +int grsec_enable_chroot_mknod;
77082 +int grsec_enable_chroot_nice;
77083 +int grsec_enable_chroot_execlog;
77084 +int grsec_enable_chroot_caps;
77085 +int grsec_enable_chroot_sysctl;
77086 +int grsec_enable_chroot_unix;
77087 +int grsec_enable_tpe;
77088 +kgid_t grsec_tpe_gid;
77089 +int grsec_enable_blackhole;
77090 +#ifdef CONFIG_IPV6_MODULE
77091 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77092 +#endif
77093 +int grsec_lastack_retries;
77094 +int grsec_enable_tpe_all;
77095 +int grsec_enable_tpe_invert;
77096 +int grsec_enable_socket_all;
77097 +kgid_t grsec_socket_all_gid;
77098 +int grsec_enable_socket_client;
77099 +kgid_t grsec_socket_client_gid;
77100 +int grsec_enable_socket_server;
77101 +kgid_t grsec_socket_server_gid;
77102 +int grsec_resource_logging;
77103 +int grsec_disable_privio;
77104 +int grsec_enable_log_rwxmaps;
77105 +int grsec_lock;
77106 +
77107 +DEFINE_SPINLOCK(grsec_alert_lock);
77108 +unsigned long grsec_alert_wtime = 0;
77109 +unsigned long grsec_alert_fyet = 0;
77110 +
77111 +DEFINE_SPINLOCK(grsec_audit_lock);
77112 +
77113 +DEFINE_RWLOCK(grsec_exec_file_lock);
77114 +
77115 +char *gr_shared_page[4];
77116 +
77117 +char *gr_alert_log_fmt;
77118 +char *gr_audit_log_fmt;
77119 +char *gr_alert_log_buf;
77120 +char *gr_audit_log_buf;
77121 +
77122 +extern struct gr_arg *gr_usermode;
77123 +extern unsigned char *gr_system_salt;
77124 +extern unsigned char *gr_system_sum;
77125 +
77126 +void __init
77127 +grsecurity_init(void)
77128 +{
77129 + int j;
77130 + /* create the per-cpu shared pages */
77131 +
77132 +#ifdef CONFIG_X86
77133 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77134 +#endif
77135 +
77136 + for (j = 0; j < 4; j++) {
77137 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77138 + if (gr_shared_page[j] == NULL) {
77139 + panic("Unable to allocate grsecurity shared page");
77140 + return;
77141 + }
77142 + }
77143 +
77144 + /* allocate log buffers */
77145 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77146 + if (!gr_alert_log_fmt) {
77147 + panic("Unable to allocate grsecurity alert log format buffer");
77148 + return;
77149 + }
77150 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77151 + if (!gr_audit_log_fmt) {
77152 + panic("Unable to allocate grsecurity audit log format buffer");
77153 + return;
77154 + }
77155 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77156 + if (!gr_alert_log_buf) {
77157 + panic("Unable to allocate grsecurity alert log buffer");
77158 + return;
77159 + }
77160 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77161 + if (!gr_audit_log_buf) {
77162 + panic("Unable to allocate grsecurity audit log buffer");
77163 + return;
77164 + }
77165 +
77166 + /* allocate memory for authentication structure */
77167 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77168 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77169 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77170 +
77171 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77172 + panic("Unable to allocate grsecurity authentication structure");
77173 + return;
77174 + }
77175 +
77176 +#ifdef CONFIG_GRKERNSEC_IO
77177 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77178 + grsec_disable_privio = 1;
77179 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77180 + grsec_disable_privio = 1;
77181 +#else
77182 + grsec_disable_privio = 0;
77183 +#endif
77184 +#endif
77185 +
77186 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77187 + /* for backward compatibility, tpe_invert always defaults to on if
77188 + enabled in the kernel
77189 + */
77190 + grsec_enable_tpe_invert = 1;
77191 +#endif
77192 +
77193 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77194 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77195 + grsec_lock = 1;
77196 +#endif
77197 +
77198 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77199 + grsec_enable_log_rwxmaps = 1;
77200 +#endif
77201 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77202 + grsec_enable_group = 1;
77203 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77204 +#endif
77205 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77206 + grsec_enable_ptrace_readexec = 1;
77207 +#endif
77208 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77209 + grsec_enable_chdir = 1;
77210 +#endif
77211 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77212 + grsec_enable_harden_ptrace = 1;
77213 +#endif
77214 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77215 + grsec_enable_harden_ipc = 1;
77216 +#endif
77217 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77218 + grsec_enable_mount = 1;
77219 +#endif
77220 +#ifdef CONFIG_GRKERNSEC_LINK
77221 + grsec_enable_link = 1;
77222 +#endif
77223 +#ifdef CONFIG_GRKERNSEC_BRUTE
77224 + grsec_enable_brute = 1;
77225 +#endif
77226 +#ifdef CONFIG_GRKERNSEC_DMESG
77227 + grsec_enable_dmesg = 1;
77228 +#endif
77229 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77230 + grsec_enable_blackhole = 1;
77231 + grsec_lastack_retries = 4;
77232 +#endif
77233 +#ifdef CONFIG_GRKERNSEC_FIFO
77234 + grsec_enable_fifo = 1;
77235 +#endif
77236 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77237 + grsec_enable_execlog = 1;
77238 +#endif
77239 +#ifdef CONFIG_GRKERNSEC_SETXID
77240 + grsec_enable_setxid = 1;
77241 +#endif
77242 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77243 + grsec_enable_signal = 1;
77244 +#endif
77245 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77246 + grsec_enable_forkfail = 1;
77247 +#endif
77248 +#ifdef CONFIG_GRKERNSEC_TIME
77249 + grsec_enable_time = 1;
77250 +#endif
77251 +#ifdef CONFIG_GRKERNSEC_RESLOG
77252 + grsec_resource_logging = 1;
77253 +#endif
77254 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77255 + grsec_enable_chroot_findtask = 1;
77256 +#endif
77257 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77258 + grsec_enable_chroot_unix = 1;
77259 +#endif
77260 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77261 + grsec_enable_chroot_mount = 1;
77262 +#endif
77263 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77264 + grsec_enable_chroot_fchdir = 1;
77265 +#endif
77266 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77267 + grsec_enable_chroot_shmat = 1;
77268 +#endif
77269 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77270 + grsec_enable_audit_ptrace = 1;
77271 +#endif
77272 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77273 + grsec_enable_chroot_double = 1;
77274 +#endif
77275 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77276 + grsec_enable_chroot_pivot = 1;
77277 +#endif
77278 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77279 + grsec_enable_chroot_chdir = 1;
77280 +#endif
77281 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77282 + grsec_enable_chroot_chmod = 1;
77283 +#endif
77284 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77285 + grsec_enable_chroot_mknod = 1;
77286 +#endif
77287 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77288 + grsec_enable_chroot_nice = 1;
77289 +#endif
77290 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77291 + grsec_enable_chroot_execlog = 1;
77292 +#endif
77293 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77294 + grsec_enable_chroot_caps = 1;
77295 +#endif
77296 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77297 + grsec_enable_chroot_sysctl = 1;
77298 +#endif
77299 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77300 + grsec_enable_symlinkown = 1;
77301 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77302 +#endif
77303 +#ifdef CONFIG_GRKERNSEC_TPE
77304 + grsec_enable_tpe = 1;
77305 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77306 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77307 + grsec_enable_tpe_all = 1;
77308 +#endif
77309 +#endif
77310 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77311 + grsec_enable_socket_all = 1;
77312 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77313 +#endif
77314 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77315 + grsec_enable_socket_client = 1;
77316 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77317 +#endif
77318 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77319 + grsec_enable_socket_server = 1;
77320 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77321 +#endif
77322 +#endif
77323 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77324 + grsec_deny_new_usb = 1;
77325 +#endif
77326 +
77327 + return;
77328 +}
77329 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77330 new file mode 100644
77331 index 0000000..1773300
77332 --- /dev/null
77333 +++ b/grsecurity/grsec_ipc.c
77334 @@ -0,0 +1,48 @@
77335 +#include <linux/kernel.h>
77336 +#include <linux/mm.h>
77337 +#include <linux/sched.h>
77338 +#include <linux/file.h>
77339 +#include <linux/ipc.h>
77340 +#include <linux/ipc_namespace.h>
77341 +#include <linux/grsecurity.h>
77342 +#include <linux/grinternal.h>
77343 +
77344 +int
77345 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77346 +{
77347 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77348 + int write;
77349 + int orig_granted_mode;
77350 + kuid_t euid;
77351 + kgid_t egid;
77352 +
77353 + if (!grsec_enable_harden_ipc)
77354 + return 1;
77355 +
77356 + euid = current_euid();
77357 + egid = current_egid();
77358 +
77359 + write = requested_mode & 00002;
77360 + orig_granted_mode = ipcp->mode;
77361 +
77362 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77363 + orig_granted_mode >>= 6;
77364 + else {
77365 + /* if likely wrong permissions, lock to user */
77366 + if (orig_granted_mode & 0007)
77367 + orig_granted_mode = 0;
77368 + /* otherwise do a egid-only check */
77369 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77370 + orig_granted_mode >>= 3;
77371 + /* otherwise, no access */
77372 + else
77373 + orig_granted_mode = 0;
77374 + }
77375 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77376 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77377 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77378 + return 0;
77379 + }
77380 +#endif
77381 + return 1;
77382 +}
77383 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77384 new file mode 100644
77385 index 0000000..5e05e20
77386 --- /dev/null
77387 +++ b/grsecurity/grsec_link.c
77388 @@ -0,0 +1,58 @@
77389 +#include <linux/kernel.h>
77390 +#include <linux/sched.h>
77391 +#include <linux/fs.h>
77392 +#include <linux/file.h>
77393 +#include <linux/grinternal.h>
77394 +
77395 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77396 +{
77397 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77398 + const struct inode *link_inode = link->dentry->d_inode;
77399 +
77400 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77401 + /* ignore root-owned links, e.g. /proc/self */
77402 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77403 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77404 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77405 + return 1;
77406 + }
77407 +#endif
77408 + return 0;
77409 +}
77410 +
77411 +int
77412 +gr_handle_follow_link(const struct inode *parent,
77413 + const struct inode *inode,
77414 + const struct dentry *dentry, const struct vfsmount *mnt)
77415 +{
77416 +#ifdef CONFIG_GRKERNSEC_LINK
77417 + const struct cred *cred = current_cred();
77418 +
77419 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77420 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77421 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77422 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77423 + return -EACCES;
77424 + }
77425 +#endif
77426 + return 0;
77427 +}
77428 +
77429 +int
77430 +gr_handle_hardlink(const struct dentry *dentry,
77431 + const struct vfsmount *mnt,
77432 + struct inode *inode, const int mode, const struct filename *to)
77433 +{
77434 +#ifdef CONFIG_GRKERNSEC_LINK
77435 + const struct cred *cred = current_cred();
77436 +
77437 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77438 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77439 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77440 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77441 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77442 + return -EPERM;
77443 + }
77444 +#endif
77445 + return 0;
77446 +}
77447 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77448 new file mode 100644
77449 index 0000000..dbe0a6b
77450 --- /dev/null
77451 +++ b/grsecurity/grsec_log.c
77452 @@ -0,0 +1,341 @@
77453 +#include <linux/kernel.h>
77454 +#include <linux/sched.h>
77455 +#include <linux/file.h>
77456 +#include <linux/tty.h>
77457 +#include <linux/fs.h>
77458 +#include <linux/mm.h>
77459 +#include <linux/grinternal.h>
77460 +
77461 +#ifdef CONFIG_TREE_PREEMPT_RCU
77462 +#define DISABLE_PREEMPT() preempt_disable()
77463 +#define ENABLE_PREEMPT() preempt_enable()
77464 +#else
77465 +#define DISABLE_PREEMPT()
77466 +#define ENABLE_PREEMPT()
77467 +#endif
77468 +
77469 +#define BEGIN_LOCKS(x) \
77470 + DISABLE_PREEMPT(); \
77471 + rcu_read_lock(); \
77472 + read_lock(&tasklist_lock); \
77473 + read_lock(&grsec_exec_file_lock); \
77474 + if (x != GR_DO_AUDIT) \
77475 + spin_lock(&grsec_alert_lock); \
77476 + else \
77477 + spin_lock(&grsec_audit_lock)
77478 +
77479 +#define END_LOCKS(x) \
77480 + if (x != GR_DO_AUDIT) \
77481 + spin_unlock(&grsec_alert_lock); \
77482 + else \
77483 + spin_unlock(&grsec_audit_lock); \
77484 + read_unlock(&grsec_exec_file_lock); \
77485 + read_unlock(&tasklist_lock); \
77486 + rcu_read_unlock(); \
77487 + ENABLE_PREEMPT(); \
77488 + if (x == GR_DONT_AUDIT) \
77489 + gr_handle_alertkill(current)
77490 +
77491 +enum {
77492 + FLOODING,
77493 + NO_FLOODING
77494 +};
77495 +
77496 +extern char *gr_alert_log_fmt;
77497 +extern char *gr_audit_log_fmt;
77498 +extern char *gr_alert_log_buf;
77499 +extern char *gr_audit_log_buf;
77500 +
77501 +static int gr_log_start(int audit)
77502 +{
77503 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77504 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77505 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77506 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77507 + unsigned long curr_secs = get_seconds();
77508 +
77509 + if (audit == GR_DO_AUDIT)
77510 + goto set_fmt;
77511 +
77512 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77513 + grsec_alert_wtime = curr_secs;
77514 + grsec_alert_fyet = 0;
77515 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77516 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77517 + grsec_alert_fyet++;
77518 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77519 + grsec_alert_wtime = curr_secs;
77520 + grsec_alert_fyet++;
77521 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77522 + return FLOODING;
77523 + }
77524 + else return FLOODING;
77525 +
77526 +set_fmt:
77527 +#endif
77528 + memset(buf, 0, PAGE_SIZE);
77529 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77530 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77531 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77532 + } else if (current->signal->curr_ip) {
77533 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77534 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77535 + } else if (gr_acl_is_enabled()) {
77536 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77537 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77538 + } else {
77539 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77540 + strcpy(buf, fmt);
77541 + }
77542 +
77543 + return NO_FLOODING;
77544 +}
77545 +
77546 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77547 + __attribute__ ((format (printf, 2, 0)));
77548 +
77549 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77550 +{
77551 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77552 + unsigned int len = strlen(buf);
77553 +
77554 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77555 +
77556 + return;
77557 +}
77558 +
77559 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77560 + __attribute__ ((format (printf, 2, 3)));
77561 +
77562 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77563 +{
77564 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77565 + unsigned int len = strlen(buf);
77566 + va_list ap;
77567 +
77568 + va_start(ap, msg);
77569 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77570 + va_end(ap);
77571 +
77572 + return;
77573 +}
77574 +
77575 +static void gr_log_end(int audit, int append_default)
77576 +{
77577 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77578 + if (append_default) {
77579 + struct task_struct *task = current;
77580 + struct task_struct *parent = task->real_parent;
77581 + const struct cred *cred = __task_cred(task);
77582 + const struct cred *pcred = __task_cred(parent);
77583 + unsigned int len = strlen(buf);
77584 +
77585 + 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));
77586 + }
77587 +
77588 + printk("%s\n", buf);
77589 +
77590 + return;
77591 +}
77592 +
77593 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77594 +{
77595 + int logtype;
77596 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77597 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77598 + void *voidptr = NULL;
77599 + int num1 = 0, num2 = 0;
77600 + unsigned long ulong1 = 0, ulong2 = 0;
77601 + struct dentry *dentry = NULL;
77602 + struct vfsmount *mnt = NULL;
77603 + struct file *file = NULL;
77604 + struct task_struct *task = NULL;
77605 + struct vm_area_struct *vma = NULL;
77606 + const struct cred *cred, *pcred;
77607 + va_list ap;
77608 +
77609 + BEGIN_LOCKS(audit);
77610 + logtype = gr_log_start(audit);
77611 + if (logtype == FLOODING) {
77612 + END_LOCKS(audit);
77613 + return;
77614 + }
77615 + va_start(ap, argtypes);
77616 + switch (argtypes) {
77617 + case GR_TTYSNIFF:
77618 + task = va_arg(ap, struct task_struct *);
77619 + 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));
77620 + break;
77621 + case GR_SYSCTL_HIDDEN:
77622 + str1 = va_arg(ap, char *);
77623 + gr_log_middle_varargs(audit, msg, result, str1);
77624 + break;
77625 + case GR_RBAC:
77626 + dentry = va_arg(ap, struct dentry *);
77627 + mnt = va_arg(ap, struct vfsmount *);
77628 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77629 + break;
77630 + case GR_RBAC_STR:
77631 + dentry = va_arg(ap, struct dentry *);
77632 + mnt = va_arg(ap, struct vfsmount *);
77633 + str1 = va_arg(ap, char *);
77634 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77635 + break;
77636 + case GR_STR_RBAC:
77637 + str1 = va_arg(ap, char *);
77638 + dentry = va_arg(ap, struct dentry *);
77639 + mnt = va_arg(ap, struct vfsmount *);
77640 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77641 + break;
77642 + case GR_RBAC_MODE2:
77643 + dentry = va_arg(ap, struct dentry *);
77644 + mnt = va_arg(ap, struct vfsmount *);
77645 + str1 = va_arg(ap, char *);
77646 + str2 = va_arg(ap, char *);
77647 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77648 + break;
77649 + case GR_RBAC_MODE3:
77650 + dentry = va_arg(ap, struct dentry *);
77651 + mnt = va_arg(ap, struct vfsmount *);
77652 + str1 = va_arg(ap, char *);
77653 + str2 = va_arg(ap, char *);
77654 + str3 = va_arg(ap, char *);
77655 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77656 + break;
77657 + case GR_FILENAME:
77658 + dentry = va_arg(ap, struct dentry *);
77659 + mnt = va_arg(ap, struct vfsmount *);
77660 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77661 + break;
77662 + case GR_STR_FILENAME:
77663 + str1 = va_arg(ap, char *);
77664 + dentry = va_arg(ap, struct dentry *);
77665 + mnt = va_arg(ap, struct vfsmount *);
77666 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77667 + break;
77668 + case GR_FILENAME_STR:
77669 + dentry = va_arg(ap, struct dentry *);
77670 + mnt = va_arg(ap, struct vfsmount *);
77671 + str1 = va_arg(ap, char *);
77672 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77673 + break;
77674 + case GR_FILENAME_TWO_INT:
77675 + dentry = va_arg(ap, struct dentry *);
77676 + mnt = va_arg(ap, struct vfsmount *);
77677 + num1 = va_arg(ap, int);
77678 + num2 = va_arg(ap, int);
77679 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77680 + break;
77681 + case GR_FILENAME_TWO_INT_STR:
77682 + dentry = va_arg(ap, struct dentry *);
77683 + mnt = va_arg(ap, struct vfsmount *);
77684 + num1 = va_arg(ap, int);
77685 + num2 = va_arg(ap, int);
77686 + str1 = va_arg(ap, char *);
77687 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77688 + break;
77689 + case GR_TEXTREL:
77690 + file = va_arg(ap, struct file *);
77691 + ulong1 = va_arg(ap, unsigned long);
77692 + ulong2 = va_arg(ap, unsigned long);
77693 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77694 + break;
77695 + case GR_PTRACE:
77696 + task = va_arg(ap, struct task_struct *);
77697 + 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));
77698 + break;
77699 + case GR_RESOURCE:
77700 + task = va_arg(ap, struct task_struct *);
77701 + cred = __task_cred(task);
77702 + pcred = __task_cred(task->real_parent);
77703 + ulong1 = va_arg(ap, unsigned long);
77704 + str1 = va_arg(ap, char *);
77705 + ulong2 = va_arg(ap, unsigned long);
77706 + 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));
77707 + break;
77708 + case GR_CAP:
77709 + task = va_arg(ap, struct task_struct *);
77710 + cred = __task_cred(task);
77711 + pcred = __task_cred(task->real_parent);
77712 + str1 = va_arg(ap, char *);
77713 + 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));
77714 + break;
77715 + case GR_SIG:
77716 + str1 = va_arg(ap, char *);
77717 + voidptr = va_arg(ap, void *);
77718 + gr_log_middle_varargs(audit, msg, str1, voidptr);
77719 + break;
77720 + case GR_SIG2:
77721 + task = va_arg(ap, struct task_struct *);
77722 + cred = __task_cred(task);
77723 + pcred = __task_cred(task->real_parent);
77724 + num1 = va_arg(ap, int);
77725 + 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));
77726 + break;
77727 + case GR_CRASH1:
77728 + task = va_arg(ap, struct task_struct *);
77729 + cred = __task_cred(task);
77730 + pcred = __task_cred(task->real_parent);
77731 + ulong1 = va_arg(ap, unsigned long);
77732 + 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);
77733 + break;
77734 + case GR_CRASH2:
77735 + task = va_arg(ap, struct task_struct *);
77736 + cred = __task_cred(task);
77737 + pcred = __task_cred(task->real_parent);
77738 + ulong1 = va_arg(ap, unsigned long);
77739 + 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);
77740 + break;
77741 + case GR_RWXMAP:
77742 + file = va_arg(ap, struct file *);
77743 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77744 + break;
77745 + case GR_RWXMAPVMA:
77746 + vma = va_arg(ap, struct vm_area_struct *);
77747 + if (vma->vm_file)
77748 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77749 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77750 + str1 = "<stack>";
77751 + else if (vma->vm_start <= current->mm->brk &&
77752 + vma->vm_end >= current->mm->start_brk)
77753 + str1 = "<heap>";
77754 + else
77755 + str1 = "<anonymous mapping>";
77756 + gr_log_middle_varargs(audit, msg, str1);
77757 + break;
77758 + case GR_PSACCT:
77759 + {
77760 + unsigned int wday, cday;
77761 + __u8 whr, chr;
77762 + __u8 wmin, cmin;
77763 + __u8 wsec, csec;
77764 + char cur_tty[64] = { 0 };
77765 + char parent_tty[64] = { 0 };
77766 +
77767 + task = va_arg(ap, struct task_struct *);
77768 + wday = va_arg(ap, unsigned int);
77769 + cday = va_arg(ap, unsigned int);
77770 + whr = va_arg(ap, int);
77771 + chr = va_arg(ap, int);
77772 + wmin = va_arg(ap, int);
77773 + cmin = va_arg(ap, int);
77774 + wsec = va_arg(ap, int);
77775 + csec = va_arg(ap, int);
77776 + ulong1 = va_arg(ap, unsigned long);
77777 + cred = __task_cred(task);
77778 + pcred = __task_cred(task->real_parent);
77779 +
77780 + 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));
77781 + }
77782 + break;
77783 + default:
77784 + gr_log_middle(audit, msg, ap);
77785 + }
77786 + va_end(ap);
77787 + // these don't need DEFAULTSECARGS printed on the end
77788 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77789 + gr_log_end(audit, 0);
77790 + else
77791 + gr_log_end(audit, 1);
77792 + END_LOCKS(audit);
77793 +}
77794 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77795 new file mode 100644
77796 index 0000000..0e39d8c
77797 --- /dev/null
77798 +++ b/grsecurity/grsec_mem.c
77799 @@ -0,0 +1,48 @@
77800 +#include <linux/kernel.h>
77801 +#include <linux/sched.h>
77802 +#include <linux/mm.h>
77803 +#include <linux/mman.h>
77804 +#include <linux/module.h>
77805 +#include <linux/grinternal.h>
77806 +
77807 +void gr_handle_msr_write(void)
77808 +{
77809 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77810 + return;
77811 +}
77812 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77813 +
77814 +void
77815 +gr_handle_ioperm(void)
77816 +{
77817 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77818 + return;
77819 +}
77820 +
77821 +void
77822 +gr_handle_iopl(void)
77823 +{
77824 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77825 + return;
77826 +}
77827 +
77828 +void
77829 +gr_handle_mem_readwrite(u64 from, u64 to)
77830 +{
77831 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77832 + return;
77833 +}
77834 +
77835 +void
77836 +gr_handle_vm86(void)
77837 +{
77838 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77839 + return;
77840 +}
77841 +
77842 +void
77843 +gr_log_badprocpid(const char *entry)
77844 +{
77845 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77846 + return;
77847 +}
77848 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77849 new file mode 100644
77850 index 0000000..cd9e124
77851 --- /dev/null
77852 +++ b/grsecurity/grsec_mount.c
77853 @@ -0,0 +1,65 @@
77854 +#include <linux/kernel.h>
77855 +#include <linux/sched.h>
77856 +#include <linux/mount.h>
77857 +#include <linux/major.h>
77858 +#include <linux/grsecurity.h>
77859 +#include <linux/grinternal.h>
77860 +
77861 +void
77862 +gr_log_remount(const char *devname, const int retval)
77863 +{
77864 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77865 + if (grsec_enable_mount && (retval >= 0))
77866 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77867 +#endif
77868 + return;
77869 +}
77870 +
77871 +void
77872 +gr_log_unmount(const char *devname, const int retval)
77873 +{
77874 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77875 + if (grsec_enable_mount && (retval >= 0))
77876 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
77877 +#endif
77878 + return;
77879 +}
77880 +
77881 +void
77882 +gr_log_mount(const char *from, const char *to, const int retval)
77883 +{
77884 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77885 + if (grsec_enable_mount && (retval >= 0))
77886 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
77887 +#endif
77888 + return;
77889 +}
77890 +
77891 +int
77892 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
77893 +{
77894 +#ifdef CONFIG_GRKERNSEC_ROFS
77895 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
77896 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
77897 + return -EPERM;
77898 + } else
77899 + return 0;
77900 +#endif
77901 + return 0;
77902 +}
77903 +
77904 +int
77905 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
77906 +{
77907 +#ifdef CONFIG_GRKERNSEC_ROFS
77908 + struct inode *inode = dentry->d_inode;
77909 +
77910 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
77911 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
77912 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
77913 + return -EPERM;
77914 + } else
77915 + return 0;
77916 +#endif
77917 + return 0;
77918 +}
77919 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
77920 new file mode 100644
77921 index 0000000..6ee9d50
77922 --- /dev/null
77923 +++ b/grsecurity/grsec_pax.c
77924 @@ -0,0 +1,45 @@
77925 +#include <linux/kernel.h>
77926 +#include <linux/sched.h>
77927 +#include <linux/mm.h>
77928 +#include <linux/file.h>
77929 +#include <linux/grinternal.h>
77930 +#include <linux/grsecurity.h>
77931 +
77932 +void
77933 +gr_log_textrel(struct vm_area_struct * vma)
77934 +{
77935 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77936 + if (grsec_enable_log_rwxmaps)
77937 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
77938 +#endif
77939 + return;
77940 +}
77941 +
77942 +void gr_log_ptgnustack(struct file *file)
77943 +{
77944 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77945 + if (grsec_enable_log_rwxmaps)
77946 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
77947 +#endif
77948 + return;
77949 +}
77950 +
77951 +void
77952 +gr_log_rwxmmap(struct file *file)
77953 +{
77954 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77955 + if (grsec_enable_log_rwxmaps)
77956 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
77957 +#endif
77958 + return;
77959 +}
77960 +
77961 +void
77962 +gr_log_rwxmprotect(struct vm_area_struct *vma)
77963 +{
77964 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77965 + if (grsec_enable_log_rwxmaps)
77966 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
77967 +#endif
77968 + return;
77969 +}
77970 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
77971 new file mode 100644
77972 index 0000000..2005a3a
77973 --- /dev/null
77974 +++ b/grsecurity/grsec_proc.c
77975 @@ -0,0 +1,20 @@
77976 +#include <linux/kernel.h>
77977 +#include <linux/sched.h>
77978 +#include <linux/grsecurity.h>
77979 +#include <linux/grinternal.h>
77980 +
77981 +int gr_proc_is_restricted(void)
77982 +{
77983 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77984 + const struct cred *cred = current_cred();
77985 +#endif
77986 +
77987 +#ifdef CONFIG_GRKERNSEC_PROC_USER
77988 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
77989 + return -EACCES;
77990 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77991 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
77992 + return -EACCES;
77993 +#endif
77994 + return 0;
77995 +}
77996 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
77997 new file mode 100644
77998 index 0000000..f7f29aa
77999 --- /dev/null
78000 +++ b/grsecurity/grsec_ptrace.c
78001 @@ -0,0 +1,30 @@
78002 +#include <linux/kernel.h>
78003 +#include <linux/sched.h>
78004 +#include <linux/grinternal.h>
78005 +#include <linux/security.h>
78006 +
78007 +void
78008 +gr_audit_ptrace(struct task_struct *task)
78009 +{
78010 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78011 + if (grsec_enable_audit_ptrace)
78012 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78013 +#endif
78014 + return;
78015 +}
78016 +
78017 +int
78018 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78019 +{
78020 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78021 + const struct dentry *dentry = file->f_path.dentry;
78022 + const struct vfsmount *mnt = file->f_path.mnt;
78023 +
78024 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78025 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78026 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78027 + return -EACCES;
78028 + }
78029 +#endif
78030 + return 0;
78031 +}
78032 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78033 new file mode 100644
78034 index 0000000..3860c7e
78035 --- /dev/null
78036 +++ b/grsecurity/grsec_sig.c
78037 @@ -0,0 +1,236 @@
78038 +#include <linux/kernel.h>
78039 +#include <linux/sched.h>
78040 +#include <linux/fs.h>
78041 +#include <linux/delay.h>
78042 +#include <linux/grsecurity.h>
78043 +#include <linux/grinternal.h>
78044 +#include <linux/hardirq.h>
78045 +
78046 +char *signames[] = {
78047 + [SIGSEGV] = "Segmentation fault",
78048 + [SIGILL] = "Illegal instruction",
78049 + [SIGABRT] = "Abort",
78050 + [SIGBUS] = "Invalid alignment/Bus error"
78051 +};
78052 +
78053 +void
78054 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78055 +{
78056 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78057 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78058 + (sig == SIGABRT) || (sig == SIGBUS))) {
78059 + if (task_pid_nr(t) == task_pid_nr(current)) {
78060 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78061 + } else {
78062 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78063 + }
78064 + }
78065 +#endif
78066 + return;
78067 +}
78068 +
78069 +int
78070 +gr_handle_signal(const struct task_struct *p, const int sig)
78071 +{
78072 +#ifdef CONFIG_GRKERNSEC
78073 + /* ignore the 0 signal for protected task checks */
78074 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78075 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78076 + return -EPERM;
78077 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78078 + return -EPERM;
78079 + }
78080 +#endif
78081 + return 0;
78082 +}
78083 +
78084 +#ifdef CONFIG_GRKERNSEC
78085 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78086 +
78087 +int gr_fake_force_sig(int sig, struct task_struct *t)
78088 +{
78089 + unsigned long int flags;
78090 + int ret, blocked, ignored;
78091 + struct k_sigaction *action;
78092 +
78093 + spin_lock_irqsave(&t->sighand->siglock, flags);
78094 + action = &t->sighand->action[sig-1];
78095 + ignored = action->sa.sa_handler == SIG_IGN;
78096 + blocked = sigismember(&t->blocked, sig);
78097 + if (blocked || ignored) {
78098 + action->sa.sa_handler = SIG_DFL;
78099 + if (blocked) {
78100 + sigdelset(&t->blocked, sig);
78101 + recalc_sigpending_and_wake(t);
78102 + }
78103 + }
78104 + if (action->sa.sa_handler == SIG_DFL)
78105 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78106 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78107 +
78108 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78109 +
78110 + return ret;
78111 +}
78112 +#endif
78113 +
78114 +#define GR_USER_BAN_TIME (15 * 60)
78115 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78116 +
78117 +void gr_handle_brute_attach(int dumpable)
78118 +{
78119 +#ifdef CONFIG_GRKERNSEC_BRUTE
78120 + struct task_struct *p = current;
78121 + kuid_t uid = GLOBAL_ROOT_UID;
78122 + int daemon = 0;
78123 +
78124 + if (!grsec_enable_brute)
78125 + return;
78126 +
78127 + rcu_read_lock();
78128 + read_lock(&tasklist_lock);
78129 + read_lock(&grsec_exec_file_lock);
78130 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78131 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78132 + p->real_parent->brute = 1;
78133 + daemon = 1;
78134 + } else {
78135 + const struct cred *cred = __task_cred(p), *cred2;
78136 + struct task_struct *tsk, *tsk2;
78137 +
78138 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78139 + struct user_struct *user;
78140 +
78141 + uid = cred->uid;
78142 +
78143 + /* this is put upon execution past expiration */
78144 + user = find_user(uid);
78145 + if (user == NULL)
78146 + goto unlock;
78147 + user->suid_banned = 1;
78148 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78149 + if (user->suid_ban_expires == ~0UL)
78150 + user->suid_ban_expires--;
78151 +
78152 + /* only kill other threads of the same binary, from the same user */
78153 + do_each_thread(tsk2, tsk) {
78154 + cred2 = __task_cred(tsk);
78155 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78156 + gr_fake_force_sig(SIGKILL, tsk);
78157 + } while_each_thread(tsk2, tsk);
78158 + }
78159 + }
78160 +unlock:
78161 + read_unlock(&grsec_exec_file_lock);
78162 + read_unlock(&tasklist_lock);
78163 + rcu_read_unlock();
78164 +
78165 + if (gr_is_global_nonroot(uid))
78166 + 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);
78167 + else if (daemon)
78168 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78169 +
78170 +#endif
78171 + return;
78172 +}
78173 +
78174 +void gr_handle_brute_check(void)
78175 +{
78176 +#ifdef CONFIG_GRKERNSEC_BRUTE
78177 + struct task_struct *p = current;
78178 +
78179 + if (unlikely(p->brute)) {
78180 + if (!grsec_enable_brute)
78181 + p->brute = 0;
78182 + else if (time_before(get_seconds(), p->brute_expires))
78183 + msleep(30 * 1000);
78184 + }
78185 +#endif
78186 + return;
78187 +}
78188 +
78189 +void gr_handle_kernel_exploit(void)
78190 +{
78191 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78192 + const struct cred *cred;
78193 + struct task_struct *tsk, *tsk2;
78194 + struct user_struct *user;
78195 + kuid_t uid;
78196 +
78197 + if (in_irq() || in_serving_softirq() || in_nmi())
78198 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78199 +
78200 + uid = current_uid();
78201 +
78202 + if (gr_is_global_root(uid))
78203 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78204 + else {
78205 + /* kill all the processes of this user, hold a reference
78206 + to their creds struct, and prevent them from creating
78207 + another process until system reset
78208 + */
78209 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78210 + GR_GLOBAL_UID(uid));
78211 + /* we intentionally leak this ref */
78212 + user = get_uid(current->cred->user);
78213 + if (user)
78214 + user->kernel_banned = 1;
78215 +
78216 + /* kill all processes of this user */
78217 + read_lock(&tasklist_lock);
78218 + do_each_thread(tsk2, tsk) {
78219 + cred = __task_cred(tsk);
78220 + if (uid_eq(cred->uid, uid))
78221 + gr_fake_force_sig(SIGKILL, tsk);
78222 + } while_each_thread(tsk2, tsk);
78223 + read_unlock(&tasklist_lock);
78224 + }
78225 +#endif
78226 +}
78227 +
78228 +#ifdef CONFIG_GRKERNSEC_BRUTE
78229 +static bool suid_ban_expired(struct user_struct *user)
78230 +{
78231 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78232 + user->suid_banned = 0;
78233 + user->suid_ban_expires = 0;
78234 + free_uid(user);
78235 + return true;
78236 + }
78237 +
78238 + return false;
78239 +}
78240 +#endif
78241 +
78242 +int gr_process_kernel_exec_ban(void)
78243 +{
78244 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78245 + if (unlikely(current->cred->user->kernel_banned))
78246 + return -EPERM;
78247 +#endif
78248 + return 0;
78249 +}
78250 +
78251 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78252 +{
78253 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78254 + if (unlikely(user->kernel_banned))
78255 + gr_fake_force_sig(SIGKILL, current);
78256 +#endif
78257 + return 0;
78258 +}
78259 +
78260 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78261 +{
78262 +#ifdef CONFIG_GRKERNSEC_BRUTE
78263 + struct user_struct *user = current->cred->user;
78264 + if (unlikely(user->suid_banned)) {
78265 + if (suid_ban_expired(user))
78266 + return 0;
78267 + /* disallow execution of suid binaries only */
78268 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78269 + return -EPERM;
78270 + }
78271 +#endif
78272 + return 0;
78273 +}
78274 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78275 new file mode 100644
78276 index 0000000..e3650b6
78277 --- /dev/null
78278 +++ b/grsecurity/grsec_sock.c
78279 @@ -0,0 +1,244 @@
78280 +#include <linux/kernel.h>
78281 +#include <linux/module.h>
78282 +#include <linux/sched.h>
78283 +#include <linux/file.h>
78284 +#include <linux/net.h>
78285 +#include <linux/in.h>
78286 +#include <linux/ip.h>
78287 +#include <net/sock.h>
78288 +#include <net/inet_sock.h>
78289 +#include <linux/grsecurity.h>
78290 +#include <linux/grinternal.h>
78291 +#include <linux/gracl.h>
78292 +
78293 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78294 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78295 +
78296 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78297 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78298 +
78299 +#ifdef CONFIG_UNIX_MODULE
78300 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78301 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78302 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78303 +EXPORT_SYMBOL_GPL(gr_handle_create);
78304 +#endif
78305 +
78306 +#ifdef CONFIG_GRKERNSEC
78307 +#define gr_conn_table_size 32749
78308 +struct conn_table_entry {
78309 + struct conn_table_entry *next;
78310 + struct signal_struct *sig;
78311 +};
78312 +
78313 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78314 +DEFINE_SPINLOCK(gr_conn_table_lock);
78315 +
78316 +extern const char * gr_socktype_to_name(unsigned char type);
78317 +extern const char * gr_proto_to_name(unsigned char proto);
78318 +extern const char * gr_sockfamily_to_name(unsigned char family);
78319 +
78320 +static __inline__ int
78321 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78322 +{
78323 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78324 +}
78325 +
78326 +static __inline__ int
78327 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78328 + __u16 sport, __u16 dport)
78329 +{
78330 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78331 + sig->gr_sport == sport && sig->gr_dport == dport))
78332 + return 1;
78333 + else
78334 + return 0;
78335 +}
78336 +
78337 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78338 +{
78339 + struct conn_table_entry **match;
78340 + unsigned int index;
78341 +
78342 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78343 + sig->gr_sport, sig->gr_dport,
78344 + gr_conn_table_size);
78345 +
78346 + newent->sig = sig;
78347 +
78348 + match = &gr_conn_table[index];
78349 + newent->next = *match;
78350 + *match = newent;
78351 +
78352 + return;
78353 +}
78354 +
78355 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78356 +{
78357 + struct conn_table_entry *match, *last = NULL;
78358 + unsigned int index;
78359 +
78360 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78361 + sig->gr_sport, sig->gr_dport,
78362 + gr_conn_table_size);
78363 +
78364 + match = gr_conn_table[index];
78365 + while (match && !conn_match(match->sig,
78366 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78367 + sig->gr_dport)) {
78368 + last = match;
78369 + match = match->next;
78370 + }
78371 +
78372 + if (match) {
78373 + if (last)
78374 + last->next = match->next;
78375 + else
78376 + gr_conn_table[index] = NULL;
78377 + kfree(match);
78378 + }
78379 +
78380 + return;
78381 +}
78382 +
78383 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78384 + __u16 sport, __u16 dport)
78385 +{
78386 + struct conn_table_entry *match;
78387 + unsigned int index;
78388 +
78389 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78390 +
78391 + match = gr_conn_table[index];
78392 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78393 + match = match->next;
78394 +
78395 + if (match)
78396 + return match->sig;
78397 + else
78398 + return NULL;
78399 +}
78400 +
78401 +#endif
78402 +
78403 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78404 +{
78405 +#ifdef CONFIG_GRKERNSEC
78406 + struct signal_struct *sig = current->signal;
78407 + struct conn_table_entry *newent;
78408 +
78409 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78410 + if (newent == NULL)
78411 + return;
78412 + /* no bh lock needed since we are called with bh disabled */
78413 + spin_lock(&gr_conn_table_lock);
78414 + gr_del_task_from_ip_table_nolock(sig);
78415 + sig->gr_saddr = inet->inet_rcv_saddr;
78416 + sig->gr_daddr = inet->inet_daddr;
78417 + sig->gr_sport = inet->inet_sport;
78418 + sig->gr_dport = inet->inet_dport;
78419 + gr_add_to_task_ip_table_nolock(sig, newent);
78420 + spin_unlock(&gr_conn_table_lock);
78421 +#endif
78422 + return;
78423 +}
78424 +
78425 +void gr_del_task_from_ip_table(struct task_struct *task)
78426 +{
78427 +#ifdef CONFIG_GRKERNSEC
78428 + spin_lock_bh(&gr_conn_table_lock);
78429 + gr_del_task_from_ip_table_nolock(task->signal);
78430 + spin_unlock_bh(&gr_conn_table_lock);
78431 +#endif
78432 + return;
78433 +}
78434 +
78435 +void
78436 +gr_attach_curr_ip(const struct sock *sk)
78437 +{
78438 +#ifdef CONFIG_GRKERNSEC
78439 + struct signal_struct *p, *set;
78440 + const struct inet_sock *inet = inet_sk(sk);
78441 +
78442 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78443 + return;
78444 +
78445 + set = current->signal;
78446 +
78447 + spin_lock_bh(&gr_conn_table_lock);
78448 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78449 + inet->inet_dport, inet->inet_sport);
78450 + if (unlikely(p != NULL)) {
78451 + set->curr_ip = p->curr_ip;
78452 + set->used_accept = 1;
78453 + gr_del_task_from_ip_table_nolock(p);
78454 + spin_unlock_bh(&gr_conn_table_lock);
78455 + return;
78456 + }
78457 + spin_unlock_bh(&gr_conn_table_lock);
78458 +
78459 + set->curr_ip = inet->inet_daddr;
78460 + set->used_accept = 1;
78461 +#endif
78462 + return;
78463 +}
78464 +
78465 +int
78466 +gr_handle_sock_all(const int family, const int type, const int protocol)
78467 +{
78468 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78469 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78470 + (family != AF_UNIX)) {
78471 + if (family == AF_INET)
78472 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78473 + else
78474 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78475 + return -EACCES;
78476 + }
78477 +#endif
78478 + return 0;
78479 +}
78480 +
78481 +int
78482 +gr_handle_sock_server(const struct sockaddr *sck)
78483 +{
78484 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78485 + if (grsec_enable_socket_server &&
78486 + in_group_p(grsec_socket_server_gid) &&
78487 + sck && (sck->sa_family != AF_UNIX) &&
78488 + (sck->sa_family != AF_LOCAL)) {
78489 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78490 + return -EACCES;
78491 + }
78492 +#endif
78493 + return 0;
78494 +}
78495 +
78496 +int
78497 +gr_handle_sock_server_other(const struct sock *sck)
78498 +{
78499 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78500 + if (grsec_enable_socket_server &&
78501 + in_group_p(grsec_socket_server_gid) &&
78502 + sck && (sck->sk_family != AF_UNIX) &&
78503 + (sck->sk_family != AF_LOCAL)) {
78504 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78505 + return -EACCES;
78506 + }
78507 +#endif
78508 + return 0;
78509 +}
78510 +
78511 +int
78512 +gr_handle_sock_client(const struct sockaddr *sck)
78513 +{
78514 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78515 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78516 + sck && (sck->sa_family != AF_UNIX) &&
78517 + (sck->sa_family != AF_LOCAL)) {
78518 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78519 + return -EACCES;
78520 + }
78521 +#endif
78522 + return 0;
78523 +}
78524 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78525 new file mode 100644
78526 index 0000000..8159888
78527 --- /dev/null
78528 +++ b/grsecurity/grsec_sysctl.c
78529 @@ -0,0 +1,479 @@
78530 +#include <linux/kernel.h>
78531 +#include <linux/sched.h>
78532 +#include <linux/sysctl.h>
78533 +#include <linux/grsecurity.h>
78534 +#include <linux/grinternal.h>
78535 +
78536 +int
78537 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78538 +{
78539 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78540 + if (dirname == NULL || name == NULL)
78541 + return 0;
78542 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78543 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78544 + return -EACCES;
78545 + }
78546 +#endif
78547 + return 0;
78548 +}
78549 +
78550 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78551 +static int __maybe_unused __read_only one = 1;
78552 +#endif
78553 +
78554 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78555 + defined(CONFIG_GRKERNSEC_DENYUSB)
78556 +struct ctl_table grsecurity_table[] = {
78557 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78558 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78559 +#ifdef CONFIG_GRKERNSEC_IO
78560 + {
78561 + .procname = "disable_priv_io",
78562 + .data = &grsec_disable_privio,
78563 + .maxlen = sizeof(int),
78564 + .mode = 0600,
78565 + .proc_handler = &proc_dointvec,
78566 + },
78567 +#endif
78568 +#endif
78569 +#ifdef CONFIG_GRKERNSEC_LINK
78570 + {
78571 + .procname = "linking_restrictions",
78572 + .data = &grsec_enable_link,
78573 + .maxlen = sizeof(int),
78574 + .mode = 0600,
78575 + .proc_handler = &proc_dointvec,
78576 + },
78577 +#endif
78578 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78579 + {
78580 + .procname = "enforce_symlinksifowner",
78581 + .data = &grsec_enable_symlinkown,
78582 + .maxlen = sizeof(int),
78583 + .mode = 0600,
78584 + .proc_handler = &proc_dointvec,
78585 + },
78586 + {
78587 + .procname = "symlinkown_gid",
78588 + .data = &grsec_symlinkown_gid,
78589 + .maxlen = sizeof(int),
78590 + .mode = 0600,
78591 + .proc_handler = &proc_dointvec,
78592 + },
78593 +#endif
78594 +#ifdef CONFIG_GRKERNSEC_BRUTE
78595 + {
78596 + .procname = "deter_bruteforce",
78597 + .data = &grsec_enable_brute,
78598 + .maxlen = sizeof(int),
78599 + .mode = 0600,
78600 + .proc_handler = &proc_dointvec,
78601 + },
78602 +#endif
78603 +#ifdef CONFIG_GRKERNSEC_FIFO
78604 + {
78605 + .procname = "fifo_restrictions",
78606 + .data = &grsec_enable_fifo,
78607 + .maxlen = sizeof(int),
78608 + .mode = 0600,
78609 + .proc_handler = &proc_dointvec,
78610 + },
78611 +#endif
78612 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78613 + {
78614 + .procname = "ptrace_readexec",
78615 + .data = &grsec_enable_ptrace_readexec,
78616 + .maxlen = sizeof(int),
78617 + .mode = 0600,
78618 + .proc_handler = &proc_dointvec,
78619 + },
78620 +#endif
78621 +#ifdef CONFIG_GRKERNSEC_SETXID
78622 + {
78623 + .procname = "consistent_setxid",
78624 + .data = &grsec_enable_setxid,
78625 + .maxlen = sizeof(int),
78626 + .mode = 0600,
78627 + .proc_handler = &proc_dointvec,
78628 + },
78629 +#endif
78630 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78631 + {
78632 + .procname = "ip_blackhole",
78633 + .data = &grsec_enable_blackhole,
78634 + .maxlen = sizeof(int),
78635 + .mode = 0600,
78636 + .proc_handler = &proc_dointvec,
78637 + },
78638 + {
78639 + .procname = "lastack_retries",
78640 + .data = &grsec_lastack_retries,
78641 + .maxlen = sizeof(int),
78642 + .mode = 0600,
78643 + .proc_handler = &proc_dointvec,
78644 + },
78645 +#endif
78646 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78647 + {
78648 + .procname = "exec_logging",
78649 + .data = &grsec_enable_execlog,
78650 + .maxlen = sizeof(int),
78651 + .mode = 0600,
78652 + .proc_handler = &proc_dointvec,
78653 + },
78654 +#endif
78655 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78656 + {
78657 + .procname = "rwxmap_logging",
78658 + .data = &grsec_enable_log_rwxmaps,
78659 + .maxlen = sizeof(int),
78660 + .mode = 0600,
78661 + .proc_handler = &proc_dointvec,
78662 + },
78663 +#endif
78664 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78665 + {
78666 + .procname = "signal_logging",
78667 + .data = &grsec_enable_signal,
78668 + .maxlen = sizeof(int),
78669 + .mode = 0600,
78670 + .proc_handler = &proc_dointvec,
78671 + },
78672 +#endif
78673 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78674 + {
78675 + .procname = "forkfail_logging",
78676 + .data = &grsec_enable_forkfail,
78677 + .maxlen = sizeof(int),
78678 + .mode = 0600,
78679 + .proc_handler = &proc_dointvec,
78680 + },
78681 +#endif
78682 +#ifdef CONFIG_GRKERNSEC_TIME
78683 + {
78684 + .procname = "timechange_logging",
78685 + .data = &grsec_enable_time,
78686 + .maxlen = sizeof(int),
78687 + .mode = 0600,
78688 + .proc_handler = &proc_dointvec,
78689 + },
78690 +#endif
78691 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78692 + {
78693 + .procname = "chroot_deny_shmat",
78694 + .data = &grsec_enable_chroot_shmat,
78695 + .maxlen = sizeof(int),
78696 + .mode = 0600,
78697 + .proc_handler = &proc_dointvec,
78698 + },
78699 +#endif
78700 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78701 + {
78702 + .procname = "chroot_deny_unix",
78703 + .data = &grsec_enable_chroot_unix,
78704 + .maxlen = sizeof(int),
78705 + .mode = 0600,
78706 + .proc_handler = &proc_dointvec,
78707 + },
78708 +#endif
78709 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78710 + {
78711 + .procname = "chroot_deny_mount",
78712 + .data = &grsec_enable_chroot_mount,
78713 + .maxlen = sizeof(int),
78714 + .mode = 0600,
78715 + .proc_handler = &proc_dointvec,
78716 + },
78717 +#endif
78718 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78719 + {
78720 + .procname = "chroot_deny_fchdir",
78721 + .data = &grsec_enable_chroot_fchdir,
78722 + .maxlen = sizeof(int),
78723 + .mode = 0600,
78724 + .proc_handler = &proc_dointvec,
78725 + },
78726 +#endif
78727 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78728 + {
78729 + .procname = "chroot_deny_chroot",
78730 + .data = &grsec_enable_chroot_double,
78731 + .maxlen = sizeof(int),
78732 + .mode = 0600,
78733 + .proc_handler = &proc_dointvec,
78734 + },
78735 +#endif
78736 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78737 + {
78738 + .procname = "chroot_deny_pivot",
78739 + .data = &grsec_enable_chroot_pivot,
78740 + .maxlen = sizeof(int),
78741 + .mode = 0600,
78742 + .proc_handler = &proc_dointvec,
78743 + },
78744 +#endif
78745 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78746 + {
78747 + .procname = "chroot_enforce_chdir",
78748 + .data = &grsec_enable_chroot_chdir,
78749 + .maxlen = sizeof(int),
78750 + .mode = 0600,
78751 + .proc_handler = &proc_dointvec,
78752 + },
78753 +#endif
78754 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78755 + {
78756 + .procname = "chroot_deny_chmod",
78757 + .data = &grsec_enable_chroot_chmod,
78758 + .maxlen = sizeof(int),
78759 + .mode = 0600,
78760 + .proc_handler = &proc_dointvec,
78761 + },
78762 +#endif
78763 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78764 + {
78765 + .procname = "chroot_deny_mknod",
78766 + .data = &grsec_enable_chroot_mknod,
78767 + .maxlen = sizeof(int),
78768 + .mode = 0600,
78769 + .proc_handler = &proc_dointvec,
78770 + },
78771 +#endif
78772 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78773 + {
78774 + .procname = "chroot_restrict_nice",
78775 + .data = &grsec_enable_chroot_nice,
78776 + .maxlen = sizeof(int),
78777 + .mode = 0600,
78778 + .proc_handler = &proc_dointvec,
78779 + },
78780 +#endif
78781 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78782 + {
78783 + .procname = "chroot_execlog",
78784 + .data = &grsec_enable_chroot_execlog,
78785 + .maxlen = sizeof(int),
78786 + .mode = 0600,
78787 + .proc_handler = &proc_dointvec,
78788 + },
78789 +#endif
78790 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78791 + {
78792 + .procname = "chroot_caps",
78793 + .data = &grsec_enable_chroot_caps,
78794 + .maxlen = sizeof(int),
78795 + .mode = 0600,
78796 + .proc_handler = &proc_dointvec,
78797 + },
78798 +#endif
78799 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78800 + {
78801 + .procname = "chroot_deny_sysctl",
78802 + .data = &grsec_enable_chroot_sysctl,
78803 + .maxlen = sizeof(int),
78804 + .mode = 0600,
78805 + .proc_handler = &proc_dointvec,
78806 + },
78807 +#endif
78808 +#ifdef CONFIG_GRKERNSEC_TPE
78809 + {
78810 + .procname = "tpe",
78811 + .data = &grsec_enable_tpe,
78812 + .maxlen = sizeof(int),
78813 + .mode = 0600,
78814 + .proc_handler = &proc_dointvec,
78815 + },
78816 + {
78817 + .procname = "tpe_gid",
78818 + .data = &grsec_tpe_gid,
78819 + .maxlen = sizeof(int),
78820 + .mode = 0600,
78821 + .proc_handler = &proc_dointvec,
78822 + },
78823 +#endif
78824 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78825 + {
78826 + .procname = "tpe_invert",
78827 + .data = &grsec_enable_tpe_invert,
78828 + .maxlen = sizeof(int),
78829 + .mode = 0600,
78830 + .proc_handler = &proc_dointvec,
78831 + },
78832 +#endif
78833 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78834 + {
78835 + .procname = "tpe_restrict_all",
78836 + .data = &grsec_enable_tpe_all,
78837 + .maxlen = sizeof(int),
78838 + .mode = 0600,
78839 + .proc_handler = &proc_dointvec,
78840 + },
78841 +#endif
78842 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78843 + {
78844 + .procname = "socket_all",
78845 + .data = &grsec_enable_socket_all,
78846 + .maxlen = sizeof(int),
78847 + .mode = 0600,
78848 + .proc_handler = &proc_dointvec,
78849 + },
78850 + {
78851 + .procname = "socket_all_gid",
78852 + .data = &grsec_socket_all_gid,
78853 + .maxlen = sizeof(int),
78854 + .mode = 0600,
78855 + .proc_handler = &proc_dointvec,
78856 + },
78857 +#endif
78858 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78859 + {
78860 + .procname = "socket_client",
78861 + .data = &grsec_enable_socket_client,
78862 + .maxlen = sizeof(int),
78863 + .mode = 0600,
78864 + .proc_handler = &proc_dointvec,
78865 + },
78866 + {
78867 + .procname = "socket_client_gid",
78868 + .data = &grsec_socket_client_gid,
78869 + .maxlen = sizeof(int),
78870 + .mode = 0600,
78871 + .proc_handler = &proc_dointvec,
78872 + },
78873 +#endif
78874 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78875 + {
78876 + .procname = "socket_server",
78877 + .data = &grsec_enable_socket_server,
78878 + .maxlen = sizeof(int),
78879 + .mode = 0600,
78880 + .proc_handler = &proc_dointvec,
78881 + },
78882 + {
78883 + .procname = "socket_server_gid",
78884 + .data = &grsec_socket_server_gid,
78885 + .maxlen = sizeof(int),
78886 + .mode = 0600,
78887 + .proc_handler = &proc_dointvec,
78888 + },
78889 +#endif
78890 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78891 + {
78892 + .procname = "audit_group",
78893 + .data = &grsec_enable_group,
78894 + .maxlen = sizeof(int),
78895 + .mode = 0600,
78896 + .proc_handler = &proc_dointvec,
78897 + },
78898 + {
78899 + .procname = "audit_gid",
78900 + .data = &grsec_audit_gid,
78901 + .maxlen = sizeof(int),
78902 + .mode = 0600,
78903 + .proc_handler = &proc_dointvec,
78904 + },
78905 +#endif
78906 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78907 + {
78908 + .procname = "audit_chdir",
78909 + .data = &grsec_enable_chdir,
78910 + .maxlen = sizeof(int),
78911 + .mode = 0600,
78912 + .proc_handler = &proc_dointvec,
78913 + },
78914 +#endif
78915 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78916 + {
78917 + .procname = "audit_mount",
78918 + .data = &grsec_enable_mount,
78919 + .maxlen = sizeof(int),
78920 + .mode = 0600,
78921 + .proc_handler = &proc_dointvec,
78922 + },
78923 +#endif
78924 +#ifdef CONFIG_GRKERNSEC_DMESG
78925 + {
78926 + .procname = "dmesg",
78927 + .data = &grsec_enable_dmesg,
78928 + .maxlen = sizeof(int),
78929 + .mode = 0600,
78930 + .proc_handler = &proc_dointvec,
78931 + },
78932 +#endif
78933 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78934 + {
78935 + .procname = "chroot_findtask",
78936 + .data = &grsec_enable_chroot_findtask,
78937 + .maxlen = sizeof(int),
78938 + .mode = 0600,
78939 + .proc_handler = &proc_dointvec,
78940 + },
78941 +#endif
78942 +#ifdef CONFIG_GRKERNSEC_RESLOG
78943 + {
78944 + .procname = "resource_logging",
78945 + .data = &grsec_resource_logging,
78946 + .maxlen = sizeof(int),
78947 + .mode = 0600,
78948 + .proc_handler = &proc_dointvec,
78949 + },
78950 +#endif
78951 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78952 + {
78953 + .procname = "audit_ptrace",
78954 + .data = &grsec_enable_audit_ptrace,
78955 + .maxlen = sizeof(int),
78956 + .mode = 0600,
78957 + .proc_handler = &proc_dointvec,
78958 + },
78959 +#endif
78960 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78961 + {
78962 + .procname = "harden_ptrace",
78963 + .data = &grsec_enable_harden_ptrace,
78964 + .maxlen = sizeof(int),
78965 + .mode = 0600,
78966 + .proc_handler = &proc_dointvec,
78967 + },
78968 +#endif
78969 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78970 + {
78971 + .procname = "harden_ipc",
78972 + .data = &grsec_enable_harden_ipc,
78973 + .maxlen = sizeof(int),
78974 + .mode = 0600,
78975 + .proc_handler = &proc_dointvec,
78976 + },
78977 +#endif
78978 + {
78979 + .procname = "grsec_lock",
78980 + .data = &grsec_lock,
78981 + .maxlen = sizeof(int),
78982 + .mode = 0600,
78983 + .proc_handler = &proc_dointvec,
78984 + },
78985 +#endif
78986 +#ifdef CONFIG_GRKERNSEC_ROFS
78987 + {
78988 + .procname = "romount_protect",
78989 + .data = &grsec_enable_rofs,
78990 + .maxlen = sizeof(int),
78991 + .mode = 0600,
78992 + .proc_handler = &proc_dointvec_minmax,
78993 + .extra1 = &one,
78994 + .extra2 = &one,
78995 + },
78996 +#endif
78997 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
78998 + {
78999 + .procname = "deny_new_usb",
79000 + .data = &grsec_deny_new_usb,
79001 + .maxlen = sizeof(int),
79002 + .mode = 0600,
79003 + .proc_handler = &proc_dointvec,
79004 + },
79005 +#endif
79006 + { }
79007 +};
79008 +#endif
79009 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79010 new file mode 100644
79011 index 0000000..61b514e
79012 --- /dev/null
79013 +++ b/grsecurity/grsec_time.c
79014 @@ -0,0 +1,16 @@
79015 +#include <linux/kernel.h>
79016 +#include <linux/sched.h>
79017 +#include <linux/grinternal.h>
79018 +#include <linux/module.h>
79019 +
79020 +void
79021 +gr_log_timechange(void)
79022 +{
79023 +#ifdef CONFIG_GRKERNSEC_TIME
79024 + if (grsec_enable_time)
79025 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79026 +#endif
79027 + return;
79028 +}
79029 +
79030 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79031 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79032 new file mode 100644
79033 index 0000000..d1953de
79034 --- /dev/null
79035 +++ b/grsecurity/grsec_tpe.c
79036 @@ -0,0 +1,78 @@
79037 +#include <linux/kernel.h>
79038 +#include <linux/sched.h>
79039 +#include <linux/file.h>
79040 +#include <linux/fs.h>
79041 +#include <linux/grinternal.h>
79042 +
79043 +extern int gr_acl_tpe_check(void);
79044 +
79045 +int
79046 +gr_tpe_allow(const struct file *file)
79047 +{
79048 +#ifdef CONFIG_GRKERNSEC
79049 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79050 + struct inode *file_inode = file->f_path.dentry->d_inode;
79051 + const struct cred *cred = current_cred();
79052 + char *msg = NULL;
79053 + char *msg2 = NULL;
79054 +
79055 + // never restrict root
79056 + if (gr_is_global_root(cred->uid))
79057 + return 1;
79058 +
79059 + if (grsec_enable_tpe) {
79060 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79061 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79062 + msg = "not being in trusted group";
79063 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79064 + msg = "being in untrusted group";
79065 +#else
79066 + if (in_group_p(grsec_tpe_gid))
79067 + msg = "being in untrusted group";
79068 +#endif
79069 + }
79070 + if (!msg && gr_acl_tpe_check())
79071 + msg = "being in untrusted role";
79072 +
79073 + // not in any affected group/role
79074 + if (!msg)
79075 + goto next_check;
79076 +
79077 + if (gr_is_global_nonroot(inode->i_uid))
79078 + msg2 = "file in non-root-owned directory";
79079 + else if (inode->i_mode & S_IWOTH)
79080 + msg2 = "file in world-writable directory";
79081 + else if (inode->i_mode & S_IWGRP)
79082 + msg2 = "file in group-writable directory";
79083 + else if (file_inode->i_mode & S_IWOTH)
79084 + msg2 = "file is world-writable";
79085 +
79086 + if (msg && msg2) {
79087 + char fullmsg[70] = {0};
79088 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79089 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79090 + return 0;
79091 + }
79092 + msg = NULL;
79093 +next_check:
79094 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79095 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79096 + return 1;
79097 +
79098 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79099 + msg = "directory not owned by user";
79100 + else if (inode->i_mode & S_IWOTH)
79101 + msg = "file in world-writable directory";
79102 + else if (inode->i_mode & S_IWGRP)
79103 + msg = "file in group-writable directory";
79104 + else if (file_inode->i_mode & S_IWOTH)
79105 + msg = "file is world-writable";
79106 +
79107 + if (msg) {
79108 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79109 + return 0;
79110 + }
79111 +#endif
79112 +#endif
79113 + return 1;
79114 +}
79115 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79116 new file mode 100644
79117 index 0000000..ae02d8e
79118 --- /dev/null
79119 +++ b/grsecurity/grsec_usb.c
79120 @@ -0,0 +1,15 @@
79121 +#include <linux/kernel.h>
79122 +#include <linux/grinternal.h>
79123 +#include <linux/module.h>
79124 +
79125 +int gr_handle_new_usb(void)
79126 +{
79127 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79128 + if (grsec_deny_new_usb) {
79129 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79130 + return 1;
79131 + }
79132 +#endif
79133 + return 0;
79134 +}
79135 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79136 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79137 new file mode 100644
79138 index 0000000..158b330
79139 --- /dev/null
79140 +++ b/grsecurity/grsum.c
79141 @@ -0,0 +1,64 @@
79142 +#include <linux/err.h>
79143 +#include <linux/kernel.h>
79144 +#include <linux/sched.h>
79145 +#include <linux/mm.h>
79146 +#include <linux/scatterlist.h>
79147 +#include <linux/crypto.h>
79148 +#include <linux/gracl.h>
79149 +
79150 +
79151 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79152 +#error "crypto and sha256 must be built into the kernel"
79153 +#endif
79154 +
79155 +int
79156 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79157 +{
79158 + struct crypto_hash *tfm;
79159 + struct hash_desc desc;
79160 + struct scatterlist sg[2];
79161 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79162 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79163 + unsigned long *sumptr = (unsigned long *)sum;
79164 + int cryptres;
79165 + int retval = 1;
79166 + volatile int mismatched = 0;
79167 + volatile int dummy = 0;
79168 + unsigned int i;
79169 +
79170 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79171 + if (IS_ERR(tfm)) {
79172 + /* should never happen, since sha256 should be built in */
79173 + memset(entry->pw, 0, GR_PW_LEN);
79174 + return 1;
79175 + }
79176 +
79177 + sg_init_table(sg, 2);
79178 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79179 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79180 +
79181 + desc.tfm = tfm;
79182 + desc.flags = 0;
79183 +
79184 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79185 + temp_sum);
79186 +
79187 + memset(entry->pw, 0, GR_PW_LEN);
79188 +
79189 + if (cryptres)
79190 + goto out;
79191 +
79192 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79193 + if (sumptr[i] != tmpsumptr[i])
79194 + mismatched = 1;
79195 + else
79196 + dummy = 1; // waste a cycle
79197 +
79198 + if (!mismatched)
79199 + retval = dummy - 1;
79200 +
79201 +out:
79202 + crypto_free_hash(tfm);
79203 +
79204 + return retval;
79205 +}
79206 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79207 index 77ff547..181834f 100644
79208 --- a/include/asm-generic/4level-fixup.h
79209 +++ b/include/asm-generic/4level-fixup.h
79210 @@ -13,8 +13,10 @@
79211 #define pmd_alloc(mm, pud, address) \
79212 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79213 NULL: pmd_offset(pud, address))
79214 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79215
79216 #define pud_alloc(mm, pgd, address) (pgd)
79217 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79218 #define pud_offset(pgd, start) (pgd)
79219 #define pud_none(pud) 0
79220 #define pud_bad(pud) 0
79221 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79222 index b7babf0..97f4c4f 100644
79223 --- a/include/asm-generic/atomic-long.h
79224 +++ b/include/asm-generic/atomic-long.h
79225 @@ -22,6 +22,12 @@
79226
79227 typedef atomic64_t atomic_long_t;
79228
79229 +#ifdef CONFIG_PAX_REFCOUNT
79230 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79231 +#else
79232 +typedef atomic64_t atomic_long_unchecked_t;
79233 +#endif
79234 +
79235 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79236
79237 static inline long atomic_long_read(atomic_long_t *l)
79238 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79239 return (long)atomic64_read(v);
79240 }
79241
79242 +#ifdef CONFIG_PAX_REFCOUNT
79243 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79244 +{
79245 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79246 +
79247 + return (long)atomic64_read_unchecked(v);
79248 +}
79249 +#endif
79250 +
79251 static inline void atomic_long_set(atomic_long_t *l, long i)
79252 {
79253 atomic64_t *v = (atomic64_t *)l;
79254 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79255 atomic64_set(v, i);
79256 }
79257
79258 +#ifdef CONFIG_PAX_REFCOUNT
79259 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79260 +{
79261 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79262 +
79263 + atomic64_set_unchecked(v, i);
79264 +}
79265 +#endif
79266 +
79267 static inline void atomic_long_inc(atomic_long_t *l)
79268 {
79269 atomic64_t *v = (atomic64_t *)l;
79270 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79271 atomic64_inc(v);
79272 }
79273
79274 +#ifdef CONFIG_PAX_REFCOUNT
79275 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79276 +{
79277 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79278 +
79279 + atomic64_inc_unchecked(v);
79280 +}
79281 +#endif
79282 +
79283 static inline void atomic_long_dec(atomic_long_t *l)
79284 {
79285 atomic64_t *v = (atomic64_t *)l;
79286 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79287 atomic64_dec(v);
79288 }
79289
79290 +#ifdef CONFIG_PAX_REFCOUNT
79291 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79292 +{
79293 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79294 +
79295 + atomic64_dec_unchecked(v);
79296 +}
79297 +#endif
79298 +
79299 static inline void atomic_long_add(long i, atomic_long_t *l)
79300 {
79301 atomic64_t *v = (atomic64_t *)l;
79302 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79303 atomic64_add(i, v);
79304 }
79305
79306 +#ifdef CONFIG_PAX_REFCOUNT
79307 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79308 +{
79309 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79310 +
79311 + atomic64_add_unchecked(i, v);
79312 +}
79313 +#endif
79314 +
79315 static inline void atomic_long_sub(long i, atomic_long_t *l)
79316 {
79317 atomic64_t *v = (atomic64_t *)l;
79318 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79319 atomic64_sub(i, v);
79320 }
79321
79322 +#ifdef CONFIG_PAX_REFCOUNT
79323 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79324 +{
79325 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79326 +
79327 + atomic64_sub_unchecked(i, v);
79328 +}
79329 +#endif
79330 +
79331 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79332 {
79333 atomic64_t *v = (atomic64_t *)l;
79334 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79335 return atomic64_add_negative(i, v);
79336 }
79337
79338 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79339 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79340 {
79341 atomic64_t *v = (atomic64_t *)l;
79342
79343 return (long)atomic64_add_return(i, v);
79344 }
79345
79346 +#ifdef CONFIG_PAX_REFCOUNT
79347 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79348 +{
79349 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79350 +
79351 + return (long)atomic64_add_return_unchecked(i, v);
79352 +}
79353 +#endif
79354 +
79355 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79356 {
79357 atomic64_t *v = (atomic64_t *)l;
79358 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79359 return (long)atomic64_inc_return(v);
79360 }
79361
79362 +#ifdef CONFIG_PAX_REFCOUNT
79363 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79364 +{
79365 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79366 +
79367 + return (long)atomic64_inc_return_unchecked(v);
79368 +}
79369 +#endif
79370 +
79371 static inline long atomic_long_dec_return(atomic_long_t *l)
79372 {
79373 atomic64_t *v = (atomic64_t *)l;
79374 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79375
79376 typedef atomic_t atomic_long_t;
79377
79378 +#ifdef CONFIG_PAX_REFCOUNT
79379 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79380 +#else
79381 +typedef atomic_t atomic_long_unchecked_t;
79382 +#endif
79383 +
79384 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79385 static inline long atomic_long_read(atomic_long_t *l)
79386 {
79387 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79388 return (long)atomic_read(v);
79389 }
79390
79391 +#ifdef CONFIG_PAX_REFCOUNT
79392 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79393 +{
79394 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79395 +
79396 + return (long)atomic_read_unchecked(v);
79397 +}
79398 +#endif
79399 +
79400 static inline void atomic_long_set(atomic_long_t *l, long i)
79401 {
79402 atomic_t *v = (atomic_t *)l;
79403 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79404 atomic_set(v, i);
79405 }
79406
79407 +#ifdef CONFIG_PAX_REFCOUNT
79408 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79409 +{
79410 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79411 +
79412 + atomic_set_unchecked(v, i);
79413 +}
79414 +#endif
79415 +
79416 static inline void atomic_long_inc(atomic_long_t *l)
79417 {
79418 atomic_t *v = (atomic_t *)l;
79419 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79420 atomic_inc(v);
79421 }
79422
79423 +#ifdef CONFIG_PAX_REFCOUNT
79424 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79425 +{
79426 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79427 +
79428 + atomic_inc_unchecked(v);
79429 +}
79430 +#endif
79431 +
79432 static inline void atomic_long_dec(atomic_long_t *l)
79433 {
79434 atomic_t *v = (atomic_t *)l;
79435 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79436 atomic_dec(v);
79437 }
79438
79439 +#ifdef CONFIG_PAX_REFCOUNT
79440 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79441 +{
79442 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79443 +
79444 + atomic_dec_unchecked(v);
79445 +}
79446 +#endif
79447 +
79448 static inline void atomic_long_add(long i, atomic_long_t *l)
79449 {
79450 atomic_t *v = (atomic_t *)l;
79451 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79452 atomic_add(i, v);
79453 }
79454
79455 +#ifdef CONFIG_PAX_REFCOUNT
79456 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79457 +{
79458 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79459 +
79460 + atomic_add_unchecked(i, v);
79461 +}
79462 +#endif
79463 +
79464 static inline void atomic_long_sub(long i, atomic_long_t *l)
79465 {
79466 atomic_t *v = (atomic_t *)l;
79467 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79468 atomic_sub(i, v);
79469 }
79470
79471 +#ifdef CONFIG_PAX_REFCOUNT
79472 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79473 +{
79474 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79475 +
79476 + atomic_sub_unchecked(i, v);
79477 +}
79478 +#endif
79479 +
79480 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79481 {
79482 atomic_t *v = (atomic_t *)l;
79483 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
79484 return (long)atomic_add_return(i, v);
79485 }
79486
79487 +#ifdef CONFIG_PAX_REFCOUNT
79488 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79489 +{
79490 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79491 +
79492 + return (long)atomic_add_return_unchecked(i, v);
79493 +}
79494 +
79495 +#endif
79496 +
79497 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79498 {
79499 atomic_t *v = (atomic_t *)l;
79500 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79501 return (long)atomic_inc_return(v);
79502 }
79503
79504 +#ifdef CONFIG_PAX_REFCOUNT
79505 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79506 +{
79507 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79508 +
79509 + return (long)atomic_inc_return_unchecked(v);
79510 +}
79511 +#endif
79512 +
79513 static inline long atomic_long_dec_return(atomic_long_t *l)
79514 {
79515 atomic_t *v = (atomic_t *)l;
79516 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79517
79518 #endif /* BITS_PER_LONG == 64 */
79519
79520 +#ifdef CONFIG_PAX_REFCOUNT
79521 +static inline void pax_refcount_needs_these_functions(void)
79522 +{
79523 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79524 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79525 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79526 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79527 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79528 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79529 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79530 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79531 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79532 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79533 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79534 +#ifdef CONFIG_X86
79535 + atomic_clear_mask_unchecked(0, NULL);
79536 + atomic_set_mask_unchecked(0, NULL);
79537 +#endif
79538 +
79539 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79540 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79541 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79542 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79543 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79544 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79545 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79546 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79547 +}
79548 +#else
79549 +#define atomic_read_unchecked(v) atomic_read(v)
79550 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79551 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79552 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79553 +#define atomic_inc_unchecked(v) atomic_inc(v)
79554 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79555 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79556 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79557 +#define atomic_dec_unchecked(v) atomic_dec(v)
79558 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79559 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79560 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79561 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79562 +
79563 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79564 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79565 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79566 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79567 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79568 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79569 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79570 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79571 +#endif
79572 +
79573 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79574 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
79575 index 9c79e76..9f7827d 100644
79576 --- a/include/asm-generic/atomic.h
79577 +++ b/include/asm-generic/atomic.h
79578 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
79579 * Atomically clears the bits set in @mask from @v
79580 */
79581 #ifndef atomic_clear_mask
79582 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
79583 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
79584 {
79585 unsigned long flags;
79586
79587 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79588 index b18ce4f..2ee2843 100644
79589 --- a/include/asm-generic/atomic64.h
79590 +++ b/include/asm-generic/atomic64.h
79591 @@ -16,6 +16,8 @@ typedef struct {
79592 long long counter;
79593 } atomic64_t;
79594
79595 +typedef atomic64_t atomic64_unchecked_t;
79596 +
79597 #define ATOMIC64_INIT(i) { (i) }
79598
79599 extern long long atomic64_read(const atomic64_t *v);
79600 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79601 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79602 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79603
79604 +#define atomic64_read_unchecked(v) atomic64_read(v)
79605 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79606 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79607 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79608 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79609 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79610 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79611 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79612 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79613 +
79614 #endif /* _ASM_GENERIC_ATOMIC64_H */
79615 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79616 index 1402fa8..025a736 100644
79617 --- a/include/asm-generic/barrier.h
79618 +++ b/include/asm-generic/barrier.h
79619 @@ -74,7 +74,7 @@
79620 do { \
79621 compiletime_assert_atomic_type(*p); \
79622 smp_mb(); \
79623 - ACCESS_ONCE(*p) = (v); \
79624 + ACCESS_ONCE_RW(*p) = (v); \
79625 } while (0)
79626
79627 #define smp_load_acquire(p) \
79628 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79629 index a60a7cc..0fe12f2 100644
79630 --- a/include/asm-generic/bitops/__fls.h
79631 +++ b/include/asm-generic/bitops/__fls.h
79632 @@ -9,7 +9,7 @@
79633 *
79634 * Undefined if no set bit exists, so code should check against 0 first.
79635 */
79636 -static __always_inline unsigned long __fls(unsigned long word)
79637 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79638 {
79639 int num = BITS_PER_LONG - 1;
79640
79641 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79642 index 0576d1f..dad6c71 100644
79643 --- a/include/asm-generic/bitops/fls.h
79644 +++ b/include/asm-generic/bitops/fls.h
79645 @@ -9,7 +9,7 @@
79646 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79647 */
79648
79649 -static __always_inline int fls(int x)
79650 +static __always_inline int __intentional_overflow(-1) fls(int x)
79651 {
79652 int r = 32;
79653
79654 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79655 index b097cf8..3d40e14 100644
79656 --- a/include/asm-generic/bitops/fls64.h
79657 +++ b/include/asm-generic/bitops/fls64.h
79658 @@ -15,7 +15,7 @@
79659 * at position 64.
79660 */
79661 #if BITS_PER_LONG == 32
79662 -static __always_inline int fls64(__u64 x)
79663 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79664 {
79665 __u32 h = x >> 32;
79666 if (h)
79667 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79668 return fls(x);
79669 }
79670 #elif BITS_PER_LONG == 64
79671 -static __always_inline int fls64(__u64 x)
79672 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79673 {
79674 if (x == 0)
79675 return 0;
79676 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79677 index 1bfcfe5..e04c5c9 100644
79678 --- a/include/asm-generic/cache.h
79679 +++ b/include/asm-generic/cache.h
79680 @@ -6,7 +6,7 @@
79681 * cache lines need to provide their own cache.h.
79682 */
79683
79684 -#define L1_CACHE_SHIFT 5
79685 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79686 +#define L1_CACHE_SHIFT 5UL
79687 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79688
79689 #endif /* __ASM_GENERIC_CACHE_H */
79690 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79691 index 0d68a1e..b74a761 100644
79692 --- a/include/asm-generic/emergency-restart.h
79693 +++ b/include/asm-generic/emergency-restart.h
79694 @@ -1,7 +1,7 @@
79695 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79696 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79697
79698 -static inline void machine_emergency_restart(void)
79699 +static inline __noreturn void machine_emergency_restart(void)
79700 {
79701 machine_restart(NULL);
79702 }
79703 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79704 index 975e1cc..0b8a083 100644
79705 --- a/include/asm-generic/io.h
79706 +++ b/include/asm-generic/io.h
79707 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79708 * These are pretty trivial
79709 */
79710 #ifndef virt_to_phys
79711 -static inline unsigned long virt_to_phys(volatile void *address)
79712 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79713 {
79714 return __pa((unsigned long)address);
79715 }
79716 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79717 index 90f99c7..00ce236 100644
79718 --- a/include/asm-generic/kmap_types.h
79719 +++ b/include/asm-generic/kmap_types.h
79720 @@ -2,9 +2,9 @@
79721 #define _ASM_GENERIC_KMAP_TYPES_H
79722
79723 #ifdef __WITH_KM_FENCE
79724 -# define KM_TYPE_NR 41
79725 +# define KM_TYPE_NR 42
79726 #else
79727 -# define KM_TYPE_NR 20
79728 +# define KM_TYPE_NR 21
79729 #endif
79730
79731 #endif
79732 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79733 index 9ceb03b..62b0b8f 100644
79734 --- a/include/asm-generic/local.h
79735 +++ b/include/asm-generic/local.h
79736 @@ -23,24 +23,37 @@ typedef struct
79737 atomic_long_t a;
79738 } local_t;
79739
79740 +typedef struct {
79741 + atomic_long_unchecked_t a;
79742 +} local_unchecked_t;
79743 +
79744 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79745
79746 #define local_read(l) atomic_long_read(&(l)->a)
79747 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79748 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79749 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79750 #define local_inc(l) atomic_long_inc(&(l)->a)
79751 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79752 #define local_dec(l) atomic_long_dec(&(l)->a)
79753 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79754 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79755 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79756 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79757 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79758
79759 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79760 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79761 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79762 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79763 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79764 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79765 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79766 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79767 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79768
79769 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79770 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79771 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79772 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79773 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79774 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79775 index 725612b..9cc513a 100644
79776 --- a/include/asm-generic/pgtable-nopmd.h
79777 +++ b/include/asm-generic/pgtable-nopmd.h
79778 @@ -1,14 +1,19 @@
79779 #ifndef _PGTABLE_NOPMD_H
79780 #define _PGTABLE_NOPMD_H
79781
79782 -#ifndef __ASSEMBLY__
79783 -
79784 #include <asm-generic/pgtable-nopud.h>
79785
79786 -struct mm_struct;
79787 -
79788 #define __PAGETABLE_PMD_FOLDED
79789
79790 +#define PMD_SHIFT PUD_SHIFT
79791 +#define PTRS_PER_PMD 1
79792 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79793 +#define PMD_MASK (~(PMD_SIZE-1))
79794 +
79795 +#ifndef __ASSEMBLY__
79796 +
79797 +struct mm_struct;
79798 +
79799 /*
79800 * Having the pmd type consist of a pud gets the size right, and allows
79801 * us to conceptually access the pud entry that this pmd is folded into
79802 @@ -16,11 +21,6 @@ struct mm_struct;
79803 */
79804 typedef struct { pud_t pud; } pmd_t;
79805
79806 -#define PMD_SHIFT PUD_SHIFT
79807 -#define PTRS_PER_PMD 1
79808 -#define PMD_SIZE (1UL << PMD_SHIFT)
79809 -#define PMD_MASK (~(PMD_SIZE-1))
79810 -
79811 /*
79812 * The "pud_xxx()" functions here are trivial for a folded two-level
79813 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79814 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79815 index 810431d..0ec4804f 100644
79816 --- a/include/asm-generic/pgtable-nopud.h
79817 +++ b/include/asm-generic/pgtable-nopud.h
79818 @@ -1,10 +1,15 @@
79819 #ifndef _PGTABLE_NOPUD_H
79820 #define _PGTABLE_NOPUD_H
79821
79822 -#ifndef __ASSEMBLY__
79823 -
79824 #define __PAGETABLE_PUD_FOLDED
79825
79826 +#define PUD_SHIFT PGDIR_SHIFT
79827 +#define PTRS_PER_PUD 1
79828 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79829 +#define PUD_MASK (~(PUD_SIZE-1))
79830 +
79831 +#ifndef __ASSEMBLY__
79832 +
79833 /*
79834 * Having the pud type consist of a pgd gets the size right, and allows
79835 * us to conceptually access the pgd entry that this pud is folded into
79836 @@ -12,11 +17,6 @@
79837 */
79838 typedef struct { pgd_t pgd; } pud_t;
79839
79840 -#define PUD_SHIFT PGDIR_SHIFT
79841 -#define PTRS_PER_PUD 1
79842 -#define PUD_SIZE (1UL << PUD_SHIFT)
79843 -#define PUD_MASK (~(PUD_SIZE-1))
79844 -
79845 /*
79846 * The "pgd_xxx()" functions here are trivial for a folded two-level
79847 * setup: the pud is never bad, and a pud always exists (as it's folded
79848 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79849 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79850
79851 #define pgd_populate(mm, pgd, pud) do { } while (0)
79852 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79853 /*
79854 * (puds are folded into pgds so this doesn't get actually called,
79855 * but the define is needed for a generic inline function.)
79856 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79857 index 53b2acc..f4568e7 100644
79858 --- a/include/asm-generic/pgtable.h
79859 +++ b/include/asm-generic/pgtable.h
79860 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79861 }
79862 #endif /* CONFIG_NUMA_BALANCING */
79863
79864 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79865 +#ifdef CONFIG_PAX_KERNEXEC
79866 +#error KERNEXEC requires pax_open_kernel
79867 +#else
79868 +static inline unsigned long pax_open_kernel(void) { return 0; }
79869 +#endif
79870 +#endif
79871 +
79872 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79873 +#ifdef CONFIG_PAX_KERNEXEC
79874 +#error KERNEXEC requires pax_close_kernel
79875 +#else
79876 +static inline unsigned long pax_close_kernel(void) { return 0; }
79877 +#endif
79878 +#endif
79879 +
79880 #endif /* CONFIG_MMU */
79881
79882 #endif /* !__ASSEMBLY__ */
79883 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
79884 index 72d8803..cb9749c 100644
79885 --- a/include/asm-generic/uaccess.h
79886 +++ b/include/asm-generic/uaccess.h
79887 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
79888 return __clear_user(to, n);
79889 }
79890
79891 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
79892 +#ifdef CONFIG_PAX_MEMORY_UDEREF
79893 +#error UDEREF requires pax_open_userland
79894 +#else
79895 +static inline unsigned long pax_open_userland(void) { return 0; }
79896 +#endif
79897 +#endif
79898 +
79899 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
79900 +#ifdef CONFIG_PAX_MEMORY_UDEREF
79901 +#error UDEREF requires pax_close_userland
79902 +#else
79903 +static inline unsigned long pax_close_userland(void) { return 0; }
79904 +#endif
79905 +#endif
79906 +
79907 #endif /* __ASM_GENERIC_UACCESS_H */
79908 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
79909 index 5ba0360..e85c934 100644
79910 --- a/include/asm-generic/vmlinux.lds.h
79911 +++ b/include/asm-generic/vmlinux.lds.h
79912 @@ -231,6 +231,7 @@
79913 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
79914 VMLINUX_SYMBOL(__start_rodata) = .; \
79915 *(.rodata) *(.rodata.*) \
79916 + *(.data..read_only) \
79917 *(__vermagic) /* Kernel version magic */ \
79918 . = ALIGN(8); \
79919 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
79920 @@ -722,17 +723,18 @@
79921 * section in the linker script will go there too. @phdr should have
79922 * a leading colon.
79923 *
79924 - * Note that this macros defines __per_cpu_load as an absolute symbol.
79925 + * Note that this macros defines per_cpu_load as an absolute symbol.
79926 * If there is no need to put the percpu section at a predetermined
79927 * address, use PERCPU_SECTION.
79928 */
79929 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
79930 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
79931 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
79932 + per_cpu_load = .; \
79933 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
79934 - LOAD_OFFSET) { \
79935 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
79936 PERCPU_INPUT(cacheline) \
79937 } phdr \
79938 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
79939 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
79940
79941 /**
79942 * PERCPU_SECTION - define output section for percpu area, simple version
79943 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
79944 index 623a59c..1e79ab9 100644
79945 --- a/include/crypto/algapi.h
79946 +++ b/include/crypto/algapi.h
79947 @@ -34,7 +34,7 @@ struct crypto_type {
79948 unsigned int maskclear;
79949 unsigned int maskset;
79950 unsigned int tfmsize;
79951 -};
79952 +} __do_const;
79953
79954 struct crypto_instance {
79955 struct crypto_alg alg;
79956 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
79957 index 1968907..7d9ed9f 100644
79958 --- a/include/drm/drmP.h
79959 +++ b/include/drm/drmP.h
79960 @@ -68,6 +68,7 @@
79961 #include <linux/workqueue.h>
79962 #include <linux/poll.h>
79963 #include <asm/pgalloc.h>
79964 +#include <asm/local.h>
79965 #include <drm/drm.h>
79966 #include <drm/drm_sarea.h>
79967 #include <drm/drm_vma_manager.h>
79968 @@ -260,10 +261,12 @@ do { \
79969 * \param cmd command.
79970 * \param arg argument.
79971 */
79972 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
79973 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
79974 + struct drm_file *file_priv);
79975 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
79976 struct drm_file *file_priv);
79977
79978 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
79979 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
79980 unsigned long arg);
79981
79982 #define DRM_IOCTL_NR(n) _IOC_NR(n)
79983 @@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
79984 struct drm_ioctl_desc {
79985 unsigned int cmd;
79986 int flags;
79987 - drm_ioctl_t *func;
79988 + drm_ioctl_t func;
79989 unsigned int cmd_drv;
79990 const char *name;
79991 -};
79992 +} __do_const;
79993
79994 /**
79995 * Creates a driver or general drm_ioctl_desc array entry for the given
79996 @@ -946,7 +949,8 @@ struct drm_info_list {
79997 int (*show)(struct seq_file*, void*); /** show callback */
79998 u32 driver_features; /**< Required driver features for this entry */
79999 void *data;
80000 -};
80001 +} __do_const;
80002 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80003
80004 /**
80005 * debugfs node structure. This structure represents a debugfs file.
80006 @@ -1030,7 +1034,7 @@ struct drm_device {
80007
80008 /** \name Usage Counters */
80009 /*@{ */
80010 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80011 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80012 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80013 int buf_use; /**< Buffers in use -- cannot alloc */
80014 atomic_t buf_alloc; /**< Buffer allocation in progress */
80015 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80016 index a3d75fe..6802f9c 100644
80017 --- a/include/drm/drm_crtc_helper.h
80018 +++ b/include/drm/drm_crtc_helper.h
80019 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80020 struct drm_connector *connector);
80021 /* disable encoder when not in use - more explicit than dpms off */
80022 void (*disable)(struct drm_encoder *encoder);
80023 -};
80024 +} __no_const;
80025
80026 /**
80027 * drm_connector_helper_funcs - helper operations for connectors
80028 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80029 index a70d456..6ea07cd 100644
80030 --- a/include/drm/i915_pciids.h
80031 +++ b/include/drm/i915_pciids.h
80032 @@ -37,7 +37,7 @@
80033 */
80034 #define INTEL_VGA_DEVICE(id, info) { \
80035 0x8086, id, \
80036 - ~0, ~0, \
80037 + PCI_ANY_ID, PCI_ANY_ID, \
80038 0x030000, 0xff0000, \
80039 (unsigned long) info }
80040
80041 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80042 index 72dcbe8..8db58d7 100644
80043 --- a/include/drm/ttm/ttm_memory.h
80044 +++ b/include/drm/ttm/ttm_memory.h
80045 @@ -48,7 +48,7 @@
80046
80047 struct ttm_mem_shrink {
80048 int (*do_shrink) (struct ttm_mem_shrink *);
80049 -};
80050 +} __no_const;
80051
80052 /**
80053 * struct ttm_mem_global - Global memory accounting structure.
80054 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80055 index 49a8284..9643967 100644
80056 --- a/include/drm/ttm/ttm_page_alloc.h
80057 +++ b/include/drm/ttm/ttm_page_alloc.h
80058 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80059 */
80060 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80061
80062 +struct device;
80063 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80064 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80065
80066 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80067 index 4b840e8..155d235 100644
80068 --- a/include/keys/asymmetric-subtype.h
80069 +++ b/include/keys/asymmetric-subtype.h
80070 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80071 /* Verify the signature on a key of this subtype (optional) */
80072 int (*verify_signature)(const struct key *key,
80073 const struct public_key_signature *sig);
80074 -};
80075 +} __do_const;
80076
80077 /**
80078 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80079 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80080 index c1da539..1dcec55 100644
80081 --- a/include/linux/atmdev.h
80082 +++ b/include/linux/atmdev.h
80083 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80084 #endif
80085
80086 struct k_atm_aal_stats {
80087 -#define __HANDLE_ITEM(i) atomic_t i
80088 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80089 __AAL_STAT_ITEMS
80090 #undef __HANDLE_ITEM
80091 };
80092 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80093 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80094 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80095 struct module *owner;
80096 -};
80097 +} __do_const ;
80098
80099 struct atmphy_ops {
80100 int (*start)(struct atm_dev *dev);
80101 diff --git a/include/linux/audit.h b/include/linux/audit.h
80102 index 22cfddb..1514eef 100644
80103 --- a/include/linux/audit.h
80104 +++ b/include/linux/audit.h
80105 @@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
80106 extern unsigned compat_chattr_class[];
80107 extern unsigned compat_signal_class[];
80108
80109 -extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
80110 +extern int audit_classify_compat_syscall(int abi, unsigned syscall);
80111
80112 /* audit_names->type values */
80113 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
80114 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80115 extern unsigned int audit_serial(void);
80116 extern int auditsc_get_stamp(struct audit_context *ctx,
80117 struct timespec *t, unsigned int *serial);
80118 -extern int audit_set_loginuid(kuid_t loginuid);
80119 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80120
80121 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80122 {
80123 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80124 index 61f29e5..e67c658 100644
80125 --- a/include/linux/binfmts.h
80126 +++ b/include/linux/binfmts.h
80127 @@ -44,7 +44,7 @@ struct linux_binprm {
80128 unsigned interp_flags;
80129 unsigned interp_data;
80130 unsigned long loader, exec;
80131 -};
80132 +} __randomize_layout;
80133
80134 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80135 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80136 @@ -73,8 +73,10 @@ struct linux_binfmt {
80137 int (*load_binary)(struct linux_binprm *);
80138 int (*load_shlib)(struct file *);
80139 int (*core_dump)(struct coredump_params *cprm);
80140 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80141 + void (*handle_mmap)(struct file *);
80142 unsigned long min_coredump; /* minimal dump size */
80143 -};
80144 +} __do_const __randomize_layout;
80145
80146 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80147
80148 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80149 index cbc5833..8123ebc 100644
80150 --- a/include/linux/bitops.h
80151 +++ b/include/linux/bitops.h
80152 @@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80153 * @word: value to rotate
80154 * @shift: bits to roll
80155 */
80156 -static inline __u32 rol32(__u32 word, unsigned int shift)
80157 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80158 {
80159 return (word << shift) | (word >> (32 - shift));
80160 }
80161 @@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80162 * @word: value to rotate
80163 * @shift: bits to roll
80164 */
80165 -static inline __u32 ror32(__u32 word, unsigned int shift)
80166 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80167 {
80168 return (word >> shift) | (word << (32 - shift));
80169 }
80170 @@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80171 return (__s32)(value << shift) >> shift;
80172 }
80173
80174 -static inline unsigned fls_long(unsigned long l)
80175 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80176 {
80177 if (sizeof(l) == 4)
80178 return fls(l);
80179 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80180 index f2057ff8..59dfa2d 100644
80181 --- a/include/linux/blkdev.h
80182 +++ b/include/linux/blkdev.h
80183 @@ -1625,7 +1625,7 @@ struct block_device_operations {
80184 /* this callback is with swap_lock and sometimes page table lock held */
80185 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80186 struct module *owner;
80187 -};
80188 +} __do_const;
80189
80190 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80191 unsigned long);
80192 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80193 index afc1343..9735539 100644
80194 --- a/include/linux/blktrace_api.h
80195 +++ b/include/linux/blktrace_api.h
80196 @@ -25,7 +25,7 @@ struct blk_trace {
80197 struct dentry *dropped_file;
80198 struct dentry *msg_file;
80199 struct list_head running_list;
80200 - atomic_t dropped;
80201 + atomic_unchecked_t dropped;
80202 };
80203
80204 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80205 diff --git a/include/linux/cache.h b/include/linux/cache.h
80206 index 17e7e82..1d7da26 100644
80207 --- a/include/linux/cache.h
80208 +++ b/include/linux/cache.h
80209 @@ -16,6 +16,14 @@
80210 #define __read_mostly
80211 #endif
80212
80213 +#ifndef __read_only
80214 +#ifdef CONFIG_PAX_KERNEXEC
80215 +#error KERNEXEC requires __read_only
80216 +#else
80217 +#define __read_only __read_mostly
80218 +#endif
80219 +#endif
80220 +
80221 #ifndef ____cacheline_aligned
80222 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80223 #endif
80224 diff --git a/include/linux/capability.h b/include/linux/capability.h
80225 index aa93e5e..985a1b0 100644
80226 --- a/include/linux/capability.h
80227 +++ b/include/linux/capability.h
80228 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80229 extern bool capable(int cap);
80230 extern bool ns_capable(struct user_namespace *ns, int cap);
80231 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80232 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80233 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80234 +extern bool capable_nolog(int cap);
80235 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80236
80237 /* audit system wants to get cap info from files as well */
80238 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80239
80240 +extern int is_privileged_binary(const struct dentry *dentry);
80241 +
80242 #endif /* !_LINUX_CAPABILITY_H */
80243 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80244 index 8609d57..86e4d79 100644
80245 --- a/include/linux/cdrom.h
80246 +++ b/include/linux/cdrom.h
80247 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80248
80249 /* driver specifications */
80250 const int capability; /* capability flags */
80251 - int n_minors; /* number of active minor devices */
80252 /* handle uniform packets for scsi type devices (scsi,atapi) */
80253 int (*generic_packet) (struct cdrom_device_info *,
80254 struct packet_command *);
80255 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80256 index 4ce9056..86caac6 100644
80257 --- a/include/linux/cleancache.h
80258 +++ b/include/linux/cleancache.h
80259 @@ -31,7 +31,7 @@ struct cleancache_ops {
80260 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80261 void (*invalidate_inode)(int, struct cleancache_filekey);
80262 void (*invalidate_fs)(int);
80263 -};
80264 +} __no_const;
80265
80266 extern struct cleancache_ops *
80267 cleancache_register_ops(struct cleancache_ops *ops);
80268 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80269 index 411dd7e..ee38878 100644
80270 --- a/include/linux/clk-provider.h
80271 +++ b/include/linux/clk-provider.h
80272 @@ -180,6 +180,7 @@ struct clk_ops {
80273 void (*init)(struct clk_hw *hw);
80274 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80275 };
80276 +typedef struct clk_ops __no_const clk_ops_no_const;
80277
80278 /**
80279 * struct clk_init_data - holds init data that's common to all clocks and is
80280 diff --git a/include/linux/compat.h b/include/linux/compat.h
80281 index e649426..a74047b 100644
80282 --- a/include/linux/compat.h
80283 +++ b/include/linux/compat.h
80284 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80285 compat_size_t __user *len_ptr);
80286
80287 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80288 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80289 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80290 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80291 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80292 compat_ssize_t msgsz, int msgflg);
80293 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80294 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80295 compat_ulong_t addr, compat_ulong_t data);
80296 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80297 - compat_long_t addr, compat_long_t data);
80298 + compat_ulong_t addr, compat_ulong_t data);
80299
80300 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80301 /*
80302 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80303 index 2507fd2..55203f8 100644
80304 --- a/include/linux/compiler-gcc4.h
80305 +++ b/include/linux/compiler-gcc4.h
80306 @@ -39,9 +39,34 @@
80307 # define __compiletime_warning(message) __attribute__((warning(message)))
80308 # define __compiletime_error(message) __attribute__((error(message)))
80309 #endif /* __CHECKER__ */
80310 +
80311 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80312 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80313 +#define __bos0(ptr) __bos((ptr), 0)
80314 +#define __bos1(ptr) __bos((ptr), 1)
80315 #endif /* GCC_VERSION >= 40300 */
80316
80317 #if GCC_VERSION >= 40500
80318 +
80319 +#ifdef RANDSTRUCT_PLUGIN
80320 +#define __randomize_layout __attribute__((randomize_layout))
80321 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80322 +#endif
80323 +
80324 +#ifdef CONSTIFY_PLUGIN
80325 +#define __no_const __attribute__((no_const))
80326 +#define __do_const __attribute__((do_const))
80327 +#endif
80328 +
80329 +#ifdef SIZE_OVERFLOW_PLUGIN
80330 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80331 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80332 +#endif
80333 +
80334 +#ifdef LATENT_ENTROPY_PLUGIN
80335 +#define __latent_entropy __attribute__((latent_entropy))
80336 +#endif
80337 +
80338 /*
80339 * Mark a position in code as unreachable. This can be used to
80340 * suppress control flow warnings after asm blocks that transfer
80341 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80342 index d5ad7b1..3b74638 100644
80343 --- a/include/linux/compiler.h
80344 +++ b/include/linux/compiler.h
80345 @@ -5,11 +5,14 @@
80346
80347 #ifdef __CHECKER__
80348 # define __user __attribute__((noderef, address_space(1)))
80349 +# define __force_user __force __user
80350 # define __kernel __attribute__((address_space(0)))
80351 +# define __force_kernel __force __kernel
80352 # define __safe __attribute__((safe))
80353 # define __force __attribute__((force))
80354 # define __nocast __attribute__((nocast))
80355 # define __iomem __attribute__((noderef, address_space(2)))
80356 +# define __force_iomem __force __iomem
80357 # define __must_hold(x) __attribute__((context(x,1,1)))
80358 # define __acquires(x) __attribute__((context(x,0,1)))
80359 # define __releases(x) __attribute__((context(x,1,0)))
80360 @@ -17,20 +20,37 @@
80361 # define __release(x) __context__(x,-1)
80362 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80363 # define __percpu __attribute__((noderef, address_space(3)))
80364 +# define __force_percpu __force __percpu
80365 #ifdef CONFIG_SPARSE_RCU_POINTER
80366 # define __rcu __attribute__((noderef, address_space(4)))
80367 +# define __force_rcu __force __rcu
80368 #else
80369 # define __rcu
80370 +# define __force_rcu
80371 #endif
80372 extern void __chk_user_ptr(const volatile void __user *);
80373 extern void __chk_io_ptr(const volatile void __iomem *);
80374 #else
80375 -# define __user
80376 -# define __kernel
80377 +# ifdef CHECKER_PLUGIN
80378 +//# define __user
80379 +//# define __force_user
80380 +//# define __kernel
80381 +//# define __force_kernel
80382 +# else
80383 +# ifdef STRUCTLEAK_PLUGIN
80384 +# define __user __attribute__((user))
80385 +# else
80386 +# define __user
80387 +# endif
80388 +# define __force_user
80389 +# define __kernel
80390 +# define __force_kernel
80391 +# endif
80392 # define __safe
80393 # define __force
80394 # define __nocast
80395 # define __iomem
80396 +# define __force_iomem
80397 # define __chk_user_ptr(x) (void)0
80398 # define __chk_io_ptr(x) (void)0
80399 # define __builtin_warning(x, y...) (1)
80400 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80401 # define __release(x) (void)0
80402 # define __cond_lock(x,c) (c)
80403 # define __percpu
80404 +# define __force_percpu
80405 # define __rcu
80406 +# define __force_rcu
80407 #endif
80408
80409 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80410 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80411 # define __attribute_const__ /* unimplemented */
80412 #endif
80413
80414 +#ifndef __randomize_layout
80415 +# define __randomize_layout
80416 +#endif
80417 +
80418 +#ifndef __no_randomize_layout
80419 +# define __no_randomize_layout
80420 +#endif
80421 +
80422 +#ifndef __no_const
80423 +# define __no_const
80424 +#endif
80425 +
80426 +#ifndef __do_const
80427 +# define __do_const
80428 +#endif
80429 +
80430 +#ifndef __size_overflow
80431 +# define __size_overflow(...)
80432 +#endif
80433 +
80434 +#ifndef __intentional_overflow
80435 +# define __intentional_overflow(...)
80436 +#endif
80437 +
80438 +#ifndef __latent_entropy
80439 +# define __latent_entropy
80440 +#endif
80441 +
80442 /*
80443 * Tell gcc if a function is cold. The compiler will assume any path
80444 * directly leading to the call is unlikely.
80445 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80446 #define __cold
80447 #endif
80448
80449 +#ifndef __alloc_size
80450 +#define __alloc_size(...)
80451 +#endif
80452 +
80453 +#ifndef __bos
80454 +#define __bos(ptr, arg)
80455 +#endif
80456 +
80457 +#ifndef __bos0
80458 +#define __bos0(ptr)
80459 +#endif
80460 +
80461 +#ifndef __bos1
80462 +#define __bos1(ptr)
80463 +#endif
80464 +
80465 /* Simple shorthand for a section definition */
80466 #ifndef __section
80467 # define __section(S) __attribute__ ((__section__(#S)))
80468 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80469 * use is to mediate communication between process-level code and irq/NMI
80470 * handlers, all running on the same CPU.
80471 */
80472 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80473 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80474 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80475
80476 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80477 #ifdef CONFIG_KPROBES
80478 diff --git a/include/linux/completion.h b/include/linux/completion.h
80479 index 5d5aaae..0ea9b84 100644
80480 --- a/include/linux/completion.h
80481 +++ b/include/linux/completion.h
80482 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80483
80484 extern void wait_for_completion(struct completion *);
80485 extern void wait_for_completion_io(struct completion *);
80486 -extern int wait_for_completion_interruptible(struct completion *x);
80487 -extern int wait_for_completion_killable(struct completion *x);
80488 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80489 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80490 extern unsigned long wait_for_completion_timeout(struct completion *x,
80491 - unsigned long timeout);
80492 + unsigned long timeout) __intentional_overflow(-1);
80493 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80494 - unsigned long timeout);
80495 + unsigned long timeout) __intentional_overflow(-1);
80496 extern long wait_for_completion_interruptible_timeout(
80497 - struct completion *x, unsigned long timeout);
80498 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80499 extern long wait_for_completion_killable_timeout(
80500 - struct completion *x, unsigned long timeout);
80501 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80502 extern bool try_wait_for_completion(struct completion *x);
80503 extern bool completion_done(struct completion *x);
80504
80505 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80506 index 34025df..d94bbbc 100644
80507 --- a/include/linux/configfs.h
80508 +++ b/include/linux/configfs.h
80509 @@ -125,7 +125,7 @@ struct configfs_attribute {
80510 const char *ca_name;
80511 struct module *ca_owner;
80512 umode_t ca_mode;
80513 -};
80514 +} __do_const;
80515
80516 /*
80517 * Users often need to create attribute structures for their configurable
80518 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80519 index 7d1955a..d86a3ca 100644
80520 --- a/include/linux/cpufreq.h
80521 +++ b/include/linux/cpufreq.h
80522 @@ -203,6 +203,7 @@ struct global_attr {
80523 ssize_t (*store)(struct kobject *a, struct attribute *b,
80524 const char *c, size_t count);
80525 };
80526 +typedef struct global_attr __no_const global_attr_no_const;
80527
80528 #define define_one_global_ro(_name) \
80529 static struct global_attr _name = \
80530 @@ -269,7 +270,7 @@ struct cpufreq_driver {
80531 bool boost_supported;
80532 bool boost_enabled;
80533 int (*set_boost) (int state);
80534 -};
80535 +} __do_const;
80536
80537 /* flags */
80538 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80539 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80540 index 25e0df6..952dffd 100644
80541 --- a/include/linux/cpuidle.h
80542 +++ b/include/linux/cpuidle.h
80543 @@ -50,7 +50,8 @@ struct cpuidle_state {
80544 int index);
80545
80546 int (*enter_dead) (struct cpuidle_device *dev, int index);
80547 -};
80548 +} __do_const;
80549 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80550
80551 /* Idle State Flags */
80552 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80553 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80554 void (*reflect) (struct cpuidle_device *dev, int index);
80555
80556 struct module *owner;
80557 -};
80558 +} __do_const;
80559
80560 #ifdef CONFIG_CPU_IDLE
80561 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80562 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80563 index 2997af6..424ddc1 100644
80564 --- a/include/linux/cpumask.h
80565 +++ b/include/linux/cpumask.h
80566 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80567 }
80568
80569 /* Valid inputs for n are -1 and 0. */
80570 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80571 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80572 {
80573 return n+1;
80574 }
80575
80576 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80577 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80578 {
80579 return n+1;
80580 }
80581
80582 -static inline unsigned int cpumask_next_and(int n,
80583 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80584 const struct cpumask *srcp,
80585 const struct cpumask *andp)
80586 {
80587 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80588 *
80589 * Returns >= nr_cpu_ids if no further cpus set.
80590 */
80591 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80592 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80593 {
80594 /* -1 is a legal arg here. */
80595 if (n != -1)
80596 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80597 *
80598 * Returns >= nr_cpu_ids if no further cpus unset.
80599 */
80600 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80601 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80602 {
80603 /* -1 is a legal arg here. */
80604 if (n != -1)
80605 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80606 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80607 }
80608
80609 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80610 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80611 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80612 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80613
80614 diff --git a/include/linux/cred.h b/include/linux/cred.h
80615 index b2d0820..2ecafd3 100644
80616 --- a/include/linux/cred.h
80617 +++ b/include/linux/cred.h
80618 @@ -35,7 +35,7 @@ struct group_info {
80619 int nblocks;
80620 kgid_t small_block[NGROUPS_SMALL];
80621 kgid_t *blocks[0];
80622 -};
80623 +} __randomize_layout;
80624
80625 /**
80626 * get_group_info - Get a reference to a group info structure
80627 @@ -136,7 +136,7 @@ struct cred {
80628 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80629 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80630 struct rcu_head rcu; /* RCU deletion hook */
80631 -};
80632 +} __randomize_layout;
80633
80634 extern void __put_cred(struct cred *);
80635 extern void exit_creds(struct task_struct *);
80636 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80637 static inline void validate_process_creds(void)
80638 {
80639 }
80640 +static inline void validate_task_creds(struct task_struct *task)
80641 +{
80642 +}
80643 #endif
80644
80645 /**
80646 @@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
80647
80648 #define task_uid(task) (task_cred_xxx((task), uid))
80649 #define task_euid(task) (task_cred_xxx((task), euid))
80650 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80651
80652 #define current_cred_xxx(xxx) \
80653 ({ \
80654 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80655 index d45e949..51cf5ea 100644
80656 --- a/include/linux/crypto.h
80657 +++ b/include/linux/crypto.h
80658 @@ -373,7 +373,7 @@ struct cipher_tfm {
80659 const u8 *key, unsigned int keylen);
80660 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80661 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80662 -};
80663 +} __no_const;
80664
80665 struct hash_tfm {
80666 int (*init)(struct hash_desc *desc);
80667 @@ -394,13 +394,13 @@ struct compress_tfm {
80668 int (*cot_decompress)(struct crypto_tfm *tfm,
80669 const u8 *src, unsigned int slen,
80670 u8 *dst, unsigned int *dlen);
80671 -};
80672 +} __no_const;
80673
80674 struct rng_tfm {
80675 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80676 unsigned int dlen);
80677 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80678 -};
80679 +} __no_const;
80680
80681 #define crt_ablkcipher crt_u.ablkcipher
80682 #define crt_aead crt_u.aead
80683 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80684 index 653589e..4ef254a 100644
80685 --- a/include/linux/ctype.h
80686 +++ b/include/linux/ctype.h
80687 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80688 * Fast implementation of tolower() for internal usage. Do not use in your
80689 * code.
80690 */
80691 -static inline char _tolower(const char c)
80692 +static inline unsigned char _tolower(const unsigned char c)
80693 {
80694 return c | 0x20;
80695 }
80696 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80697 index 75a227c..1456987 100644
80698 --- a/include/linux/dcache.h
80699 +++ b/include/linux/dcache.h
80700 @@ -134,7 +134,7 @@ struct dentry {
80701 } d_u;
80702 struct list_head d_subdirs; /* our children */
80703 struct hlist_node d_alias; /* inode alias list */
80704 -};
80705 +} __randomize_layout;
80706
80707 /*
80708 * dentry->d_lock spinlock nesting subclasses:
80709 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80710 index 7925bf0..d5143d2 100644
80711 --- a/include/linux/decompress/mm.h
80712 +++ b/include/linux/decompress/mm.h
80713 @@ -77,7 +77,7 @@ static void free(void *where)
80714 * warnings when not needed (indeed large_malloc / large_free are not
80715 * needed by inflate */
80716
80717 -#define malloc(a) kmalloc(a, GFP_KERNEL)
80718 +#define malloc(a) kmalloc((a), GFP_KERNEL)
80719 #define free(a) kfree(a)
80720
80721 #define large_malloc(a) vmalloc(a)
80722 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80723 index f1863dc..5c26074 100644
80724 --- a/include/linux/devfreq.h
80725 +++ b/include/linux/devfreq.h
80726 @@ -114,7 +114,7 @@ struct devfreq_governor {
80727 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80728 int (*event_handler)(struct devfreq *devfreq,
80729 unsigned int event, void *data);
80730 -};
80731 +} __do_const;
80732
80733 /**
80734 * struct devfreq - Device devfreq structure
80735 diff --git a/include/linux/device.h b/include/linux/device.h
80736 index 43d183a..03b6ba2 100644
80737 --- a/include/linux/device.h
80738 +++ b/include/linux/device.h
80739 @@ -310,7 +310,7 @@ struct subsys_interface {
80740 struct list_head node;
80741 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80742 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80743 -};
80744 +} __do_const;
80745
80746 int subsys_interface_register(struct subsys_interface *sif);
80747 void subsys_interface_unregister(struct subsys_interface *sif);
80748 @@ -506,7 +506,7 @@ struct device_type {
80749 void (*release)(struct device *dev);
80750
80751 const struct dev_pm_ops *pm;
80752 -};
80753 +} __do_const;
80754
80755 /* interface for exporting device attributes */
80756 struct device_attribute {
80757 @@ -516,11 +516,12 @@ struct device_attribute {
80758 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80759 const char *buf, size_t count);
80760 };
80761 +typedef struct device_attribute __no_const device_attribute_no_const;
80762
80763 struct dev_ext_attribute {
80764 struct device_attribute attr;
80765 void *var;
80766 -};
80767 +} __do_const;
80768
80769 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80770 char *buf);
80771 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80772 index 931b709..89b2d89 100644
80773 --- a/include/linux/dma-mapping.h
80774 +++ b/include/linux/dma-mapping.h
80775 @@ -60,7 +60,7 @@ struct dma_map_ops {
80776 u64 (*get_required_mask)(struct device *dev);
80777 #endif
80778 int is_phys;
80779 -};
80780 +} __do_const;
80781
80782 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80783
80784 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80785 index 1f9e642..39e4263 100644
80786 --- a/include/linux/dmaengine.h
80787 +++ b/include/linux/dmaengine.h
80788 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
80789 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80790 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80791
80792 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80793 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80794 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80795 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80796 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80797 struct dma_pinned_list *pinned_list, struct page *page,
80798 unsigned int offset, size_t len);
80799
80800 diff --git a/include/linux/efi.h b/include/linux/efi.h
80801 index 45cb4ff..c9b4912 100644
80802 --- a/include/linux/efi.h
80803 +++ b/include/linux/efi.h
80804 @@ -1036,6 +1036,7 @@ struct efivar_operations {
80805 efi_set_variable_t *set_variable;
80806 efi_query_variable_store_t *query_variable_store;
80807 };
80808 +typedef struct efivar_operations __no_const efivar_operations_no_const;
80809
80810 struct efivars {
80811 /*
80812 diff --git a/include/linux/elf.h b/include/linux/elf.h
80813 index 67a5fa7..b817372 100644
80814 --- a/include/linux/elf.h
80815 +++ b/include/linux/elf.h
80816 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80817 #define elf_note elf32_note
80818 #define elf_addr_t Elf32_Off
80819 #define Elf_Half Elf32_Half
80820 +#define elf_dyn Elf32_Dyn
80821
80822 #else
80823
80824 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80825 #define elf_note elf64_note
80826 #define elf_addr_t Elf64_Off
80827 #define Elf_Half Elf64_Half
80828 +#define elf_dyn Elf64_Dyn
80829
80830 #endif
80831
80832 diff --git a/include/linux/err.h b/include/linux/err.h
80833 index a729120..6ede2c9 100644
80834 --- a/include/linux/err.h
80835 +++ b/include/linux/err.h
80836 @@ -20,12 +20,12 @@
80837
80838 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80839
80840 -static inline void * __must_check ERR_PTR(long error)
80841 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80842 {
80843 return (void *) error;
80844 }
80845
80846 -static inline long __must_check PTR_ERR(__force const void *ptr)
80847 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80848 {
80849 return (long) ptr;
80850 }
80851 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80852 index 36f49c4..a2a1f4c 100644
80853 --- a/include/linux/extcon.h
80854 +++ b/include/linux/extcon.h
80855 @@ -135,7 +135,7 @@ struct extcon_dev {
80856 /* /sys/class/extcon/.../mutually_exclusive/... */
80857 struct attribute_group attr_g_muex;
80858 struct attribute **attrs_muex;
80859 - struct device_attribute *d_attrs_muex;
80860 + device_attribute_no_const *d_attrs_muex;
80861 };
80862
80863 /**
80864 diff --git a/include/linux/fb.h b/include/linux/fb.h
80865 index 09bb7a1..d98870a 100644
80866 --- a/include/linux/fb.h
80867 +++ b/include/linux/fb.h
80868 @@ -305,7 +305,7 @@ struct fb_ops {
80869 /* called at KDB enter and leave time to prepare the console */
80870 int (*fb_debug_enter)(struct fb_info *info);
80871 int (*fb_debug_leave)(struct fb_info *info);
80872 -};
80873 +} __do_const;
80874
80875 #ifdef CONFIG_FB_TILEBLITTING
80876 #define FB_TILE_CURSOR_NONE 0
80877 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
80878 index 230f87b..1fd0485 100644
80879 --- a/include/linux/fdtable.h
80880 +++ b/include/linux/fdtable.h
80881 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
80882 void put_files_struct(struct files_struct *fs);
80883 void reset_files_struct(struct files_struct *);
80884 int unshare_files(struct files_struct **);
80885 -struct files_struct *dup_fd(struct files_struct *, int *);
80886 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
80887 void do_close_on_exec(struct files_struct *);
80888 int iterate_fd(struct files_struct *, unsigned,
80889 int (*)(const void *, struct file *, unsigned),
80890 diff --git a/include/linux/filter.h b/include/linux/filter.h
80891 index a5227ab..c789945 100644
80892 --- a/include/linux/filter.h
80893 +++ b/include/linux/filter.h
80894 @@ -9,6 +9,11 @@
80895 #include <linux/skbuff.h>
80896 #include <linux/workqueue.h>
80897 #include <uapi/linux/filter.h>
80898 +#include <asm/cacheflush.h>
80899 +
80900 +struct sk_buff;
80901 +struct sock;
80902 +struct seccomp_data;
80903
80904 /* Internally used and optimized filter representation with extended
80905 * instruction set based on top of classic BPF.
80906 @@ -320,20 +325,23 @@ struct sock_fprog_kern {
80907 struct sock_filter *filter;
80908 };
80909
80910 -struct sk_buff;
80911 -struct sock;
80912 -struct seccomp_data;
80913 +struct bpf_work_struct {
80914 + struct bpf_prog *prog;
80915 + struct work_struct work;
80916 +};
80917
80918 struct bpf_prog {
80919 + u32 pages; /* Number of allocated pages */
80920 u32 jited:1, /* Is our filter JIT'ed? */
80921 len:31; /* Number of filter blocks */
80922 struct sock_fprog_kern *orig_prog; /* Original BPF program */
80923 + struct bpf_work_struct *work; /* Deferred free work struct */
80924 unsigned int (*bpf_func)(const struct sk_buff *skb,
80925 const struct bpf_insn *filter);
80926 + /* Instructions for interpreter */
80927 union {
80928 struct sock_filter insns[0];
80929 struct bpf_insn insnsi[0];
80930 - struct work_struct work;
80931 };
80932 };
80933
80934 @@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
80935
80936 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
80937
80938 +#ifdef CONFIG_DEBUG_SET_MODULE_RONX
80939 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
80940 +{
80941 + set_memory_ro((unsigned long)fp, fp->pages);
80942 +}
80943 +
80944 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
80945 +{
80946 + set_memory_rw((unsigned long)fp, fp->pages);
80947 +}
80948 +#else
80949 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
80950 +{
80951 +}
80952 +
80953 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
80954 +{
80955 +}
80956 +#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
80957 +
80958 int sk_filter(struct sock *sk, struct sk_buff *skb);
80959
80960 void bpf_prog_select_runtime(struct bpf_prog *fp);
80961 @@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
80962 int bpf_convert_filter(struct sock_filter *prog, int len,
80963 struct bpf_insn *new_prog, int *new_len);
80964
80965 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
80966 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
80967 + gfp_t gfp_extra_flags);
80968 +void __bpf_prog_free(struct bpf_prog *fp);
80969 +
80970 +static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
80971 +{
80972 + bpf_prog_unlock_ro(fp);
80973 + __bpf_prog_free(fp);
80974 +}
80975 +
80976 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
80977 void bpf_prog_destroy(struct bpf_prog *fp);
80978
80979 @@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
80980
80981 static inline void bpf_jit_free(struct bpf_prog *fp)
80982 {
80983 - kfree(fp);
80984 + bpf_prog_unlock_free(fp);
80985 }
80986 #endif /* CONFIG_BPF_JIT */
80987
80988 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
80989 index 8293262..2b3b8bd 100644
80990 --- a/include/linux/frontswap.h
80991 +++ b/include/linux/frontswap.h
80992 @@ -11,7 +11,7 @@ struct frontswap_ops {
80993 int (*load)(unsigned, pgoff_t, struct page *);
80994 void (*invalidate_page)(unsigned, pgoff_t);
80995 void (*invalidate_area)(unsigned);
80996 -};
80997 +} __no_const;
80998
80999 extern bool frontswap_enabled;
81000 extern struct frontswap_ops *
81001 diff --git a/include/linux/fs.h b/include/linux/fs.h
81002 index 9418772..0155807 100644
81003 --- a/include/linux/fs.h
81004 +++ b/include/linux/fs.h
81005 @@ -401,7 +401,7 @@ struct address_space {
81006 spinlock_t private_lock; /* for use by the address_space */
81007 struct list_head private_list; /* ditto */
81008 void *private_data; /* ditto */
81009 -} __attribute__((aligned(sizeof(long))));
81010 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81011 /*
81012 * On most architectures that alignment is already the case; but
81013 * must be enforced here for CRIS, to let the least significant bit
81014 @@ -444,7 +444,7 @@ struct block_device {
81015 int bd_fsfreeze_count;
81016 /* Mutex for freeze */
81017 struct mutex bd_fsfreeze_mutex;
81018 -};
81019 +} __randomize_layout;
81020
81021 /*
81022 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81023 @@ -613,7 +613,7 @@ struct inode {
81024 #endif
81025
81026 void *i_private; /* fs or device private pointer */
81027 -};
81028 +} __randomize_layout;
81029
81030 static inline int inode_unhashed(struct inode *inode)
81031 {
81032 @@ -806,7 +806,7 @@ struct file {
81033 struct list_head f_tfile_llink;
81034 #endif /* #ifdef CONFIG_EPOLL */
81035 struct address_space *f_mapping;
81036 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81037 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81038
81039 struct file_handle {
81040 __u32 handle_bytes;
81041 @@ -934,7 +934,7 @@ struct file_lock {
81042 int state; /* state of grant or error if -ve */
81043 } afs;
81044 } fl_u;
81045 -};
81046 +} __randomize_layout;
81047
81048 /* The following constant reflects the upper bound of the file/locking space */
81049 #ifndef OFFSET_MAX
81050 @@ -1284,7 +1284,7 @@ struct super_block {
81051 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
81052 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
81053 struct rcu_head rcu;
81054 -};
81055 +} __randomize_layout;
81056
81057 extern struct timespec current_fs_time(struct super_block *sb);
81058
81059 @@ -1510,7 +1510,8 @@ struct file_operations {
81060 long (*fallocate)(struct file *file, int mode, loff_t offset,
81061 loff_t len);
81062 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81063 -};
81064 +} __do_const __randomize_layout;
81065 +typedef struct file_operations __no_const file_operations_no_const;
81066
81067 struct inode_operations {
81068 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81069 @@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
81070 return !IS_DEADDIR(inode);
81071 }
81072
81073 +static inline bool is_sidechannel_device(const struct inode *inode)
81074 +{
81075 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81076 + umode_t mode = inode->i_mode;
81077 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81078 +#else
81079 + return false;
81080 +#endif
81081 +}
81082 +
81083 #endif /* _LINUX_FS_H */
81084 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81085 index 0efc3e6..fd23610 100644
81086 --- a/include/linux/fs_struct.h
81087 +++ b/include/linux/fs_struct.h
81088 @@ -6,13 +6,13 @@
81089 #include <linux/seqlock.h>
81090
81091 struct fs_struct {
81092 - int users;
81093 + atomic_t users;
81094 spinlock_t lock;
81095 seqcount_t seq;
81096 int umask;
81097 int in_exec;
81098 struct path root, pwd;
81099 -};
81100 +} __randomize_layout;
81101
81102 extern struct kmem_cache *fs_cachep;
81103
81104 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81105 index 7714849..a4a5c7a 100644
81106 --- a/include/linux/fscache-cache.h
81107 +++ b/include/linux/fscache-cache.h
81108 @@ -113,7 +113,7 @@ struct fscache_operation {
81109 fscache_operation_release_t release;
81110 };
81111
81112 -extern atomic_t fscache_op_debug_id;
81113 +extern atomic_unchecked_t fscache_op_debug_id;
81114 extern void fscache_op_work_func(struct work_struct *work);
81115
81116 extern void fscache_enqueue_operation(struct fscache_operation *);
81117 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81118 INIT_WORK(&op->work, fscache_op_work_func);
81119 atomic_set(&op->usage, 1);
81120 op->state = FSCACHE_OP_ST_INITIALISED;
81121 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81122 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81123 op->processor = processor;
81124 op->release = release;
81125 INIT_LIST_HEAD(&op->pend_link);
81126 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81127 index 115bb81..e7b812b 100644
81128 --- a/include/linux/fscache.h
81129 +++ b/include/linux/fscache.h
81130 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81131 * - this is mandatory for any object that may have data
81132 */
81133 void (*now_uncached)(void *cookie_netfs_data);
81134 -};
81135 +} __do_const;
81136
81137 /*
81138 * fscache cached network filesystem type
81139 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81140 index 1c804b0..1432c2b 100644
81141 --- a/include/linux/fsnotify.h
81142 +++ b/include/linux/fsnotify.h
81143 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81144 struct inode *inode = file_inode(file);
81145 __u32 mask = FS_ACCESS;
81146
81147 + if (is_sidechannel_device(inode))
81148 + return;
81149 +
81150 if (S_ISDIR(inode->i_mode))
81151 mask |= FS_ISDIR;
81152
81153 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81154 struct inode *inode = file_inode(file);
81155 __u32 mask = FS_MODIFY;
81156
81157 + if (is_sidechannel_device(inode))
81158 + return;
81159 +
81160 if (S_ISDIR(inode->i_mode))
81161 mask |= FS_ISDIR;
81162
81163 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81164 */
81165 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81166 {
81167 - return kstrdup(name, GFP_KERNEL);
81168 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81169 }
81170
81171 /*
81172 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81173 index ec274e0..e678159 100644
81174 --- a/include/linux/genhd.h
81175 +++ b/include/linux/genhd.h
81176 @@ -194,7 +194,7 @@ struct gendisk {
81177 struct kobject *slave_dir;
81178
81179 struct timer_rand_state *random;
81180 - atomic_t sync_io; /* RAID */
81181 + atomic_unchecked_t sync_io; /* RAID */
81182 struct disk_events *ev;
81183 #ifdef CONFIG_BLK_DEV_INTEGRITY
81184 struct blk_integrity *integrity;
81185 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81186 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81187
81188 /* drivers/char/random.c */
81189 -extern void add_disk_randomness(struct gendisk *disk);
81190 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81191 extern void rand_initialize_disk(struct gendisk *disk);
81192
81193 static inline sector_t get_start_sect(struct block_device *bdev)
81194 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81195 index c0894dd..2fbf10c 100644
81196 --- a/include/linux/genl_magic_func.h
81197 +++ b/include/linux/genl_magic_func.h
81198 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81199 },
81200
81201 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81202 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81203 +static struct genl_ops ZZZ_genl_ops[] = {
81204 #include GENL_MAGIC_INCLUDE_FILE
81205 };
81206
81207 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81208 index 5e7219d..b1ed627 100644
81209 --- a/include/linux/gfp.h
81210 +++ b/include/linux/gfp.h
81211 @@ -34,6 +34,13 @@ struct vm_area_struct;
81212 #define ___GFP_NO_KSWAPD 0x400000u
81213 #define ___GFP_OTHER_NODE 0x800000u
81214 #define ___GFP_WRITE 0x1000000u
81215 +
81216 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81217 +#define ___GFP_USERCOPY 0x2000000u
81218 +#else
81219 +#define ___GFP_USERCOPY 0
81220 +#endif
81221 +
81222 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81223
81224 /*
81225 @@ -90,6 +97,7 @@ struct vm_area_struct;
81226 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81227 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81228 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81229 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81230
81231 /*
81232 * This may seem redundant, but it's a way of annotating false positives vs.
81233 @@ -97,7 +105,7 @@ struct vm_area_struct;
81234 */
81235 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81236
81237 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81238 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81239 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81240
81241 /* This equals 0, but use constants in case they ever change */
81242 @@ -155,6 +163,8 @@ struct vm_area_struct;
81243 /* 4GB DMA on some platforms */
81244 #define GFP_DMA32 __GFP_DMA32
81245
81246 +#define GFP_USERCOPY __GFP_USERCOPY
81247 +
81248 /* Convert GFP flags to their corresponding migrate type */
81249 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
81250 {
81251 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81252 new file mode 100644
81253 index 0000000..edb2cb6
81254 --- /dev/null
81255 +++ b/include/linux/gracl.h
81256 @@ -0,0 +1,340 @@
81257 +#ifndef GR_ACL_H
81258 +#define GR_ACL_H
81259 +
81260 +#include <linux/grdefs.h>
81261 +#include <linux/resource.h>
81262 +#include <linux/capability.h>
81263 +#include <linux/dcache.h>
81264 +#include <asm/resource.h>
81265 +
81266 +/* Major status information */
81267 +
81268 +#define GR_VERSION "grsecurity 3.0"
81269 +#define GRSECURITY_VERSION 0x3000
81270 +
81271 +enum {
81272 + GR_SHUTDOWN = 0,
81273 + GR_ENABLE = 1,
81274 + GR_SPROLE = 2,
81275 + GR_OLDRELOAD = 3,
81276 + GR_SEGVMOD = 4,
81277 + GR_STATUS = 5,
81278 + GR_UNSPROLE = 6,
81279 + GR_PASSSET = 7,
81280 + GR_SPROLEPAM = 8,
81281 + GR_RELOAD = 9,
81282 +};
81283 +
81284 +/* Password setup definitions
81285 + * kernel/grhash.c */
81286 +enum {
81287 + GR_PW_LEN = 128,
81288 + GR_SALT_LEN = 16,
81289 + GR_SHA_LEN = 32,
81290 +};
81291 +
81292 +enum {
81293 + GR_SPROLE_LEN = 64,
81294 +};
81295 +
81296 +enum {
81297 + GR_NO_GLOB = 0,
81298 + GR_REG_GLOB,
81299 + GR_CREATE_GLOB
81300 +};
81301 +
81302 +#define GR_NLIMITS 32
81303 +
81304 +/* Begin Data Structures */
81305 +
81306 +struct sprole_pw {
81307 + unsigned char *rolename;
81308 + unsigned char salt[GR_SALT_LEN];
81309 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81310 +};
81311 +
81312 +struct name_entry {
81313 + __u32 key;
81314 + ino_t inode;
81315 + dev_t device;
81316 + char *name;
81317 + __u16 len;
81318 + __u8 deleted;
81319 + struct name_entry *prev;
81320 + struct name_entry *next;
81321 +};
81322 +
81323 +struct inodev_entry {
81324 + struct name_entry *nentry;
81325 + struct inodev_entry *prev;
81326 + struct inodev_entry *next;
81327 +};
81328 +
81329 +struct acl_role_db {
81330 + struct acl_role_label **r_hash;
81331 + __u32 r_size;
81332 +};
81333 +
81334 +struct inodev_db {
81335 + struct inodev_entry **i_hash;
81336 + __u32 i_size;
81337 +};
81338 +
81339 +struct name_db {
81340 + struct name_entry **n_hash;
81341 + __u32 n_size;
81342 +};
81343 +
81344 +struct crash_uid {
81345 + uid_t uid;
81346 + unsigned long expires;
81347 +};
81348 +
81349 +struct gr_hash_struct {
81350 + void **table;
81351 + void **nametable;
81352 + void *first;
81353 + __u32 table_size;
81354 + __u32 used_size;
81355 + int type;
81356 +};
81357 +
81358 +/* Userspace Grsecurity ACL data structures */
81359 +
81360 +struct acl_subject_label {
81361 + char *filename;
81362 + ino_t inode;
81363 + dev_t device;
81364 + __u32 mode;
81365 + kernel_cap_t cap_mask;
81366 + kernel_cap_t cap_lower;
81367 + kernel_cap_t cap_invert_audit;
81368 +
81369 + struct rlimit res[GR_NLIMITS];
81370 + __u32 resmask;
81371 +
81372 + __u8 user_trans_type;
81373 + __u8 group_trans_type;
81374 + uid_t *user_transitions;
81375 + gid_t *group_transitions;
81376 + __u16 user_trans_num;
81377 + __u16 group_trans_num;
81378 +
81379 + __u32 sock_families[2];
81380 + __u32 ip_proto[8];
81381 + __u32 ip_type;
81382 + struct acl_ip_label **ips;
81383 + __u32 ip_num;
81384 + __u32 inaddr_any_override;
81385 +
81386 + __u32 crashes;
81387 + unsigned long expires;
81388 +
81389 + struct acl_subject_label *parent_subject;
81390 + struct gr_hash_struct *hash;
81391 + struct acl_subject_label *prev;
81392 + struct acl_subject_label *next;
81393 +
81394 + struct acl_object_label **obj_hash;
81395 + __u32 obj_hash_size;
81396 + __u16 pax_flags;
81397 +};
81398 +
81399 +struct role_allowed_ip {
81400 + __u32 addr;
81401 + __u32 netmask;
81402 +
81403 + struct role_allowed_ip *prev;
81404 + struct role_allowed_ip *next;
81405 +};
81406 +
81407 +struct role_transition {
81408 + char *rolename;
81409 +
81410 + struct role_transition *prev;
81411 + struct role_transition *next;
81412 +};
81413 +
81414 +struct acl_role_label {
81415 + char *rolename;
81416 + uid_t uidgid;
81417 + __u16 roletype;
81418 +
81419 + __u16 auth_attempts;
81420 + unsigned long expires;
81421 +
81422 + struct acl_subject_label *root_label;
81423 + struct gr_hash_struct *hash;
81424 +
81425 + struct acl_role_label *prev;
81426 + struct acl_role_label *next;
81427 +
81428 + struct role_transition *transitions;
81429 + struct role_allowed_ip *allowed_ips;
81430 + uid_t *domain_children;
81431 + __u16 domain_child_num;
81432 +
81433 + umode_t umask;
81434 +
81435 + struct acl_subject_label **subj_hash;
81436 + __u32 subj_hash_size;
81437 +};
81438 +
81439 +struct user_acl_role_db {
81440 + struct acl_role_label **r_table;
81441 + __u32 num_pointers; /* Number of allocations to track */
81442 + __u32 num_roles; /* Number of roles */
81443 + __u32 num_domain_children; /* Number of domain children */
81444 + __u32 num_subjects; /* Number of subjects */
81445 + __u32 num_objects; /* Number of objects */
81446 +};
81447 +
81448 +struct acl_object_label {
81449 + char *filename;
81450 + ino_t inode;
81451 + dev_t device;
81452 + __u32 mode;
81453 +
81454 + struct acl_subject_label *nested;
81455 + struct acl_object_label *globbed;
81456 +
81457 + /* next two structures not used */
81458 +
81459 + struct acl_object_label *prev;
81460 + struct acl_object_label *next;
81461 +};
81462 +
81463 +struct acl_ip_label {
81464 + char *iface;
81465 + __u32 addr;
81466 + __u32 netmask;
81467 + __u16 low, high;
81468 + __u8 mode;
81469 + __u32 type;
81470 + __u32 proto[8];
81471 +
81472 + /* next two structures not used */
81473 +
81474 + struct acl_ip_label *prev;
81475 + struct acl_ip_label *next;
81476 +};
81477 +
81478 +struct gr_arg {
81479 + struct user_acl_role_db role_db;
81480 + unsigned char pw[GR_PW_LEN];
81481 + unsigned char salt[GR_SALT_LEN];
81482 + unsigned char sum[GR_SHA_LEN];
81483 + unsigned char sp_role[GR_SPROLE_LEN];
81484 + struct sprole_pw *sprole_pws;
81485 + dev_t segv_device;
81486 + ino_t segv_inode;
81487 + uid_t segv_uid;
81488 + __u16 num_sprole_pws;
81489 + __u16 mode;
81490 +};
81491 +
81492 +struct gr_arg_wrapper {
81493 + struct gr_arg *arg;
81494 + __u32 version;
81495 + __u32 size;
81496 +};
81497 +
81498 +struct subject_map {
81499 + struct acl_subject_label *user;
81500 + struct acl_subject_label *kernel;
81501 + struct subject_map *prev;
81502 + struct subject_map *next;
81503 +};
81504 +
81505 +struct acl_subj_map_db {
81506 + struct subject_map **s_hash;
81507 + __u32 s_size;
81508 +};
81509 +
81510 +struct gr_policy_state {
81511 + struct sprole_pw **acl_special_roles;
81512 + __u16 num_sprole_pws;
81513 + struct acl_role_label *kernel_role;
81514 + struct acl_role_label *role_list;
81515 + struct acl_role_label *default_role;
81516 + struct acl_role_db acl_role_set;
81517 + struct acl_subj_map_db subj_map_set;
81518 + struct name_db name_set;
81519 + struct inodev_db inodev_set;
81520 +};
81521 +
81522 +struct gr_alloc_state {
81523 + unsigned long alloc_stack_next;
81524 + unsigned long alloc_stack_size;
81525 + void **alloc_stack;
81526 +};
81527 +
81528 +struct gr_reload_state {
81529 + struct gr_policy_state oldpolicy;
81530 + struct gr_alloc_state oldalloc;
81531 + struct gr_policy_state newpolicy;
81532 + struct gr_alloc_state newalloc;
81533 + struct gr_policy_state *oldpolicy_ptr;
81534 + struct gr_alloc_state *oldalloc_ptr;
81535 + unsigned char oldmode;
81536 +};
81537 +
81538 +/* End Data Structures Section */
81539 +
81540 +/* Hash functions generated by empirical testing by Brad Spengler
81541 + Makes good use of the low bits of the inode. Generally 0-1 times
81542 + in loop for successful match. 0-3 for unsuccessful match.
81543 + Shift/add algorithm with modulus of table size and an XOR*/
81544 +
81545 +static __inline__ unsigned int
81546 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81547 +{
81548 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81549 +}
81550 +
81551 + static __inline__ unsigned int
81552 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81553 +{
81554 + return ((const unsigned long)userp % sz);
81555 +}
81556 +
81557 +static __inline__ unsigned int
81558 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81559 +{
81560 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81561 +}
81562 +
81563 +static __inline__ unsigned int
81564 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81565 +{
81566 + return full_name_hash((const unsigned char *)name, len) % sz;
81567 +}
81568 +
81569 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81570 + subj = NULL; \
81571 + iter = 0; \
81572 + while (iter < role->subj_hash_size) { \
81573 + if (subj == NULL) \
81574 + subj = role->subj_hash[iter]; \
81575 + if (subj == NULL) { \
81576 + iter++; \
81577 + continue; \
81578 + }
81579 +
81580 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81581 + subj = subj->next; \
81582 + if (subj == NULL) \
81583 + iter++; \
81584 + }
81585 +
81586 +
81587 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81588 + subj = role->hash->first; \
81589 + while (subj != NULL) {
81590 +
81591 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81592 + subj = subj->next; \
81593 + }
81594 +
81595 +#endif
81596 +
81597 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81598 new file mode 100644
81599 index 0000000..33ebd1f
81600 --- /dev/null
81601 +++ b/include/linux/gracl_compat.h
81602 @@ -0,0 +1,156 @@
81603 +#ifndef GR_ACL_COMPAT_H
81604 +#define GR_ACL_COMPAT_H
81605 +
81606 +#include <linux/resource.h>
81607 +#include <asm/resource.h>
81608 +
81609 +struct sprole_pw_compat {
81610 + compat_uptr_t rolename;
81611 + unsigned char salt[GR_SALT_LEN];
81612 + unsigned char sum[GR_SHA_LEN];
81613 +};
81614 +
81615 +struct gr_hash_struct_compat {
81616 + compat_uptr_t table;
81617 + compat_uptr_t nametable;
81618 + compat_uptr_t first;
81619 + __u32 table_size;
81620 + __u32 used_size;
81621 + int type;
81622 +};
81623 +
81624 +struct acl_subject_label_compat {
81625 + compat_uptr_t filename;
81626 + compat_ino_t inode;
81627 + __u32 device;
81628 + __u32 mode;
81629 + kernel_cap_t cap_mask;
81630 + kernel_cap_t cap_lower;
81631 + kernel_cap_t cap_invert_audit;
81632 +
81633 + struct compat_rlimit res[GR_NLIMITS];
81634 + __u32 resmask;
81635 +
81636 + __u8 user_trans_type;
81637 + __u8 group_trans_type;
81638 + compat_uptr_t user_transitions;
81639 + compat_uptr_t group_transitions;
81640 + __u16 user_trans_num;
81641 + __u16 group_trans_num;
81642 +
81643 + __u32 sock_families[2];
81644 + __u32 ip_proto[8];
81645 + __u32 ip_type;
81646 + compat_uptr_t ips;
81647 + __u32 ip_num;
81648 + __u32 inaddr_any_override;
81649 +
81650 + __u32 crashes;
81651 + compat_ulong_t expires;
81652 +
81653 + compat_uptr_t parent_subject;
81654 + compat_uptr_t hash;
81655 + compat_uptr_t prev;
81656 + compat_uptr_t next;
81657 +
81658 + compat_uptr_t obj_hash;
81659 + __u32 obj_hash_size;
81660 + __u16 pax_flags;
81661 +};
81662 +
81663 +struct role_allowed_ip_compat {
81664 + __u32 addr;
81665 + __u32 netmask;
81666 +
81667 + compat_uptr_t prev;
81668 + compat_uptr_t next;
81669 +};
81670 +
81671 +struct role_transition_compat {
81672 + compat_uptr_t rolename;
81673 +
81674 + compat_uptr_t prev;
81675 + compat_uptr_t next;
81676 +};
81677 +
81678 +struct acl_role_label_compat {
81679 + compat_uptr_t rolename;
81680 + uid_t uidgid;
81681 + __u16 roletype;
81682 +
81683 + __u16 auth_attempts;
81684 + compat_ulong_t expires;
81685 +
81686 + compat_uptr_t root_label;
81687 + compat_uptr_t hash;
81688 +
81689 + compat_uptr_t prev;
81690 + compat_uptr_t next;
81691 +
81692 + compat_uptr_t transitions;
81693 + compat_uptr_t allowed_ips;
81694 + compat_uptr_t domain_children;
81695 + __u16 domain_child_num;
81696 +
81697 + umode_t umask;
81698 +
81699 + compat_uptr_t subj_hash;
81700 + __u32 subj_hash_size;
81701 +};
81702 +
81703 +struct user_acl_role_db_compat {
81704 + compat_uptr_t r_table;
81705 + __u32 num_pointers;
81706 + __u32 num_roles;
81707 + __u32 num_domain_children;
81708 + __u32 num_subjects;
81709 + __u32 num_objects;
81710 +};
81711 +
81712 +struct acl_object_label_compat {
81713 + compat_uptr_t filename;
81714 + compat_ino_t inode;
81715 + __u32 device;
81716 + __u32 mode;
81717 +
81718 + compat_uptr_t nested;
81719 + compat_uptr_t globbed;
81720 +
81721 + compat_uptr_t prev;
81722 + compat_uptr_t next;
81723 +};
81724 +
81725 +struct acl_ip_label_compat {
81726 + compat_uptr_t iface;
81727 + __u32 addr;
81728 + __u32 netmask;
81729 + __u16 low, high;
81730 + __u8 mode;
81731 + __u32 type;
81732 + __u32 proto[8];
81733 +
81734 + compat_uptr_t prev;
81735 + compat_uptr_t next;
81736 +};
81737 +
81738 +struct gr_arg_compat {
81739 + struct user_acl_role_db_compat role_db;
81740 + unsigned char pw[GR_PW_LEN];
81741 + unsigned char salt[GR_SALT_LEN];
81742 + unsigned char sum[GR_SHA_LEN];
81743 + unsigned char sp_role[GR_SPROLE_LEN];
81744 + compat_uptr_t sprole_pws;
81745 + __u32 segv_device;
81746 + compat_ino_t segv_inode;
81747 + uid_t segv_uid;
81748 + __u16 num_sprole_pws;
81749 + __u16 mode;
81750 +};
81751 +
81752 +struct gr_arg_wrapper_compat {
81753 + compat_uptr_t arg;
81754 + __u32 version;
81755 + __u32 size;
81756 +};
81757 +
81758 +#endif
81759 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81760 new file mode 100644
81761 index 0000000..323ecf2
81762 --- /dev/null
81763 +++ b/include/linux/gralloc.h
81764 @@ -0,0 +1,9 @@
81765 +#ifndef __GRALLOC_H
81766 +#define __GRALLOC_H
81767 +
81768 +void acl_free_all(void);
81769 +int acl_alloc_stack_init(unsigned long size);
81770 +void *acl_alloc(unsigned long len);
81771 +void *acl_alloc_num(unsigned long num, unsigned long len);
81772 +
81773 +#endif
81774 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81775 new file mode 100644
81776 index 0000000..be66033
81777 --- /dev/null
81778 +++ b/include/linux/grdefs.h
81779 @@ -0,0 +1,140 @@
81780 +#ifndef GRDEFS_H
81781 +#define GRDEFS_H
81782 +
81783 +/* Begin grsecurity status declarations */
81784 +
81785 +enum {
81786 + GR_READY = 0x01,
81787 + GR_STATUS_INIT = 0x00 // disabled state
81788 +};
81789 +
81790 +/* Begin ACL declarations */
81791 +
81792 +/* Role flags */
81793 +
81794 +enum {
81795 + GR_ROLE_USER = 0x0001,
81796 + GR_ROLE_GROUP = 0x0002,
81797 + GR_ROLE_DEFAULT = 0x0004,
81798 + GR_ROLE_SPECIAL = 0x0008,
81799 + GR_ROLE_AUTH = 0x0010,
81800 + GR_ROLE_NOPW = 0x0020,
81801 + GR_ROLE_GOD = 0x0040,
81802 + GR_ROLE_LEARN = 0x0080,
81803 + GR_ROLE_TPE = 0x0100,
81804 + GR_ROLE_DOMAIN = 0x0200,
81805 + GR_ROLE_PAM = 0x0400,
81806 + GR_ROLE_PERSIST = 0x0800
81807 +};
81808 +
81809 +/* ACL Subject and Object mode flags */
81810 +enum {
81811 + GR_DELETED = 0x80000000
81812 +};
81813 +
81814 +/* ACL Object-only mode flags */
81815 +enum {
81816 + GR_READ = 0x00000001,
81817 + GR_APPEND = 0x00000002,
81818 + GR_WRITE = 0x00000004,
81819 + GR_EXEC = 0x00000008,
81820 + GR_FIND = 0x00000010,
81821 + GR_INHERIT = 0x00000020,
81822 + GR_SETID = 0x00000040,
81823 + GR_CREATE = 0x00000080,
81824 + GR_DELETE = 0x00000100,
81825 + GR_LINK = 0x00000200,
81826 + GR_AUDIT_READ = 0x00000400,
81827 + GR_AUDIT_APPEND = 0x00000800,
81828 + GR_AUDIT_WRITE = 0x00001000,
81829 + GR_AUDIT_EXEC = 0x00002000,
81830 + GR_AUDIT_FIND = 0x00004000,
81831 + GR_AUDIT_INHERIT= 0x00008000,
81832 + GR_AUDIT_SETID = 0x00010000,
81833 + GR_AUDIT_CREATE = 0x00020000,
81834 + GR_AUDIT_DELETE = 0x00040000,
81835 + GR_AUDIT_LINK = 0x00080000,
81836 + GR_PTRACERD = 0x00100000,
81837 + GR_NOPTRACE = 0x00200000,
81838 + GR_SUPPRESS = 0x00400000,
81839 + GR_NOLEARN = 0x00800000,
81840 + GR_INIT_TRANSFER= 0x01000000
81841 +};
81842 +
81843 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81844 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81845 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81846 +
81847 +/* ACL subject-only mode flags */
81848 +enum {
81849 + GR_KILL = 0x00000001,
81850 + GR_VIEW = 0x00000002,
81851 + GR_PROTECTED = 0x00000004,
81852 + GR_LEARN = 0x00000008,
81853 + GR_OVERRIDE = 0x00000010,
81854 + /* just a placeholder, this mode is only used in userspace */
81855 + GR_DUMMY = 0x00000020,
81856 + GR_PROTSHM = 0x00000040,
81857 + GR_KILLPROC = 0x00000080,
81858 + GR_KILLIPPROC = 0x00000100,
81859 + /* just a placeholder, this mode is only used in userspace */
81860 + GR_NOTROJAN = 0x00000200,
81861 + GR_PROTPROCFD = 0x00000400,
81862 + GR_PROCACCT = 0x00000800,
81863 + GR_RELAXPTRACE = 0x00001000,
81864 + //GR_NESTED = 0x00002000,
81865 + GR_INHERITLEARN = 0x00004000,
81866 + GR_PROCFIND = 0x00008000,
81867 + GR_POVERRIDE = 0x00010000,
81868 + GR_KERNELAUTH = 0x00020000,
81869 + GR_ATSECURE = 0x00040000,
81870 + GR_SHMEXEC = 0x00080000
81871 +};
81872 +
81873 +enum {
81874 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
81875 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
81876 + GR_PAX_ENABLE_MPROTECT = 0x0004,
81877 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
81878 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
81879 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
81880 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
81881 + GR_PAX_DISABLE_MPROTECT = 0x0400,
81882 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
81883 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
81884 +};
81885 +
81886 +enum {
81887 + GR_ID_USER = 0x01,
81888 + GR_ID_GROUP = 0x02,
81889 +};
81890 +
81891 +enum {
81892 + GR_ID_ALLOW = 0x01,
81893 + GR_ID_DENY = 0x02,
81894 +};
81895 +
81896 +#define GR_CRASH_RES 31
81897 +#define GR_UIDTABLE_MAX 500
81898 +
81899 +/* begin resource learning section */
81900 +enum {
81901 + GR_RLIM_CPU_BUMP = 60,
81902 + GR_RLIM_FSIZE_BUMP = 50000,
81903 + GR_RLIM_DATA_BUMP = 10000,
81904 + GR_RLIM_STACK_BUMP = 1000,
81905 + GR_RLIM_CORE_BUMP = 10000,
81906 + GR_RLIM_RSS_BUMP = 500000,
81907 + GR_RLIM_NPROC_BUMP = 1,
81908 + GR_RLIM_NOFILE_BUMP = 5,
81909 + GR_RLIM_MEMLOCK_BUMP = 50000,
81910 + GR_RLIM_AS_BUMP = 500000,
81911 + GR_RLIM_LOCKS_BUMP = 2,
81912 + GR_RLIM_SIGPENDING_BUMP = 5,
81913 + GR_RLIM_MSGQUEUE_BUMP = 10000,
81914 + GR_RLIM_NICE_BUMP = 1,
81915 + GR_RLIM_RTPRIO_BUMP = 1,
81916 + GR_RLIM_RTTIME_BUMP = 1000000
81917 +};
81918 +
81919 +#endif
81920 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
81921 new file mode 100644
81922 index 0000000..d25522e
81923 --- /dev/null
81924 +++ b/include/linux/grinternal.h
81925 @@ -0,0 +1,229 @@
81926 +#ifndef __GRINTERNAL_H
81927 +#define __GRINTERNAL_H
81928 +
81929 +#ifdef CONFIG_GRKERNSEC
81930 +
81931 +#include <linux/fs.h>
81932 +#include <linux/mnt_namespace.h>
81933 +#include <linux/nsproxy.h>
81934 +#include <linux/gracl.h>
81935 +#include <linux/grdefs.h>
81936 +#include <linux/grmsg.h>
81937 +
81938 +void gr_add_learn_entry(const char *fmt, ...)
81939 + __attribute__ ((format (printf, 1, 2)));
81940 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
81941 + const struct vfsmount *mnt);
81942 +__u32 gr_check_create(const struct dentry *new_dentry,
81943 + const struct dentry *parent,
81944 + const struct vfsmount *mnt, const __u32 mode);
81945 +int gr_check_protected_task(const struct task_struct *task);
81946 +__u32 to_gr_audit(const __u32 reqmode);
81947 +int gr_set_acls(const int type);
81948 +int gr_acl_is_enabled(void);
81949 +char gr_roletype_to_char(void);
81950 +
81951 +void gr_handle_alertkill(struct task_struct *task);
81952 +char *gr_to_filename(const struct dentry *dentry,
81953 + const struct vfsmount *mnt);
81954 +char *gr_to_filename1(const struct dentry *dentry,
81955 + const struct vfsmount *mnt);
81956 +char *gr_to_filename2(const struct dentry *dentry,
81957 + const struct vfsmount *mnt);
81958 +char *gr_to_filename3(const struct dentry *dentry,
81959 + const struct vfsmount *mnt);
81960 +
81961 +extern int grsec_enable_ptrace_readexec;
81962 +extern int grsec_enable_harden_ptrace;
81963 +extern int grsec_enable_link;
81964 +extern int grsec_enable_fifo;
81965 +extern int grsec_enable_execve;
81966 +extern int grsec_enable_shm;
81967 +extern int grsec_enable_execlog;
81968 +extern int grsec_enable_signal;
81969 +extern int grsec_enable_audit_ptrace;
81970 +extern int grsec_enable_forkfail;
81971 +extern int grsec_enable_time;
81972 +extern int grsec_enable_rofs;
81973 +extern int grsec_deny_new_usb;
81974 +extern int grsec_enable_chroot_shmat;
81975 +extern int grsec_enable_chroot_mount;
81976 +extern int grsec_enable_chroot_double;
81977 +extern int grsec_enable_chroot_pivot;
81978 +extern int grsec_enable_chroot_chdir;
81979 +extern int grsec_enable_chroot_chmod;
81980 +extern int grsec_enable_chroot_mknod;
81981 +extern int grsec_enable_chroot_fchdir;
81982 +extern int grsec_enable_chroot_nice;
81983 +extern int grsec_enable_chroot_execlog;
81984 +extern int grsec_enable_chroot_caps;
81985 +extern int grsec_enable_chroot_sysctl;
81986 +extern int grsec_enable_chroot_unix;
81987 +extern int grsec_enable_symlinkown;
81988 +extern kgid_t grsec_symlinkown_gid;
81989 +extern int grsec_enable_tpe;
81990 +extern kgid_t grsec_tpe_gid;
81991 +extern int grsec_enable_tpe_all;
81992 +extern int grsec_enable_tpe_invert;
81993 +extern int grsec_enable_socket_all;
81994 +extern kgid_t grsec_socket_all_gid;
81995 +extern int grsec_enable_socket_client;
81996 +extern kgid_t grsec_socket_client_gid;
81997 +extern int grsec_enable_socket_server;
81998 +extern kgid_t grsec_socket_server_gid;
81999 +extern kgid_t grsec_audit_gid;
82000 +extern int grsec_enable_group;
82001 +extern int grsec_enable_log_rwxmaps;
82002 +extern int grsec_enable_mount;
82003 +extern int grsec_enable_chdir;
82004 +extern int grsec_resource_logging;
82005 +extern int grsec_enable_blackhole;
82006 +extern int grsec_lastack_retries;
82007 +extern int grsec_enable_brute;
82008 +extern int grsec_enable_harden_ipc;
82009 +extern int grsec_lock;
82010 +
82011 +extern spinlock_t grsec_alert_lock;
82012 +extern unsigned long grsec_alert_wtime;
82013 +extern unsigned long grsec_alert_fyet;
82014 +
82015 +extern spinlock_t grsec_audit_lock;
82016 +
82017 +extern rwlock_t grsec_exec_file_lock;
82018 +
82019 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82020 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82021 + (tsk)->exec_file->f_path.mnt) : "/")
82022 +
82023 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82024 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82025 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82026 +
82027 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82028 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82029 + (tsk)->exec_file->f_path.mnt) : "/")
82030 +
82031 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82032 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82033 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82034 +
82035 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82036 +
82037 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82038 +
82039 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82040 +{
82041 + if (file1 && file2) {
82042 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82043 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82044 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82045 + return true;
82046 + }
82047 +
82048 + return false;
82049 +}
82050 +
82051 +#define GR_CHROOT_CAPS {{ \
82052 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82053 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82054 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82055 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82056 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82057 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82058 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82059 +
82060 +#define security_learn(normal_msg,args...) \
82061 +({ \
82062 + read_lock(&grsec_exec_file_lock); \
82063 + gr_add_learn_entry(normal_msg "\n", ## args); \
82064 + read_unlock(&grsec_exec_file_lock); \
82065 +})
82066 +
82067 +enum {
82068 + GR_DO_AUDIT,
82069 + GR_DONT_AUDIT,
82070 + /* used for non-audit messages that we shouldn't kill the task on */
82071 + GR_DONT_AUDIT_GOOD
82072 +};
82073 +
82074 +enum {
82075 + GR_TTYSNIFF,
82076 + GR_RBAC,
82077 + GR_RBAC_STR,
82078 + GR_STR_RBAC,
82079 + GR_RBAC_MODE2,
82080 + GR_RBAC_MODE3,
82081 + GR_FILENAME,
82082 + GR_SYSCTL_HIDDEN,
82083 + GR_NOARGS,
82084 + GR_ONE_INT,
82085 + GR_ONE_INT_TWO_STR,
82086 + GR_ONE_STR,
82087 + GR_STR_INT,
82088 + GR_TWO_STR_INT,
82089 + GR_TWO_INT,
82090 + GR_TWO_U64,
82091 + GR_THREE_INT,
82092 + GR_FIVE_INT_TWO_STR,
82093 + GR_TWO_STR,
82094 + GR_THREE_STR,
82095 + GR_FOUR_STR,
82096 + GR_STR_FILENAME,
82097 + GR_FILENAME_STR,
82098 + GR_FILENAME_TWO_INT,
82099 + GR_FILENAME_TWO_INT_STR,
82100 + GR_TEXTREL,
82101 + GR_PTRACE,
82102 + GR_RESOURCE,
82103 + GR_CAP,
82104 + GR_SIG,
82105 + GR_SIG2,
82106 + GR_CRASH1,
82107 + GR_CRASH2,
82108 + GR_PSACCT,
82109 + GR_RWXMAP,
82110 + GR_RWXMAPVMA
82111 +};
82112 +
82113 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82114 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82115 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82116 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82117 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82118 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82119 +#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)
82120 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82121 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82122 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82123 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82124 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82125 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82126 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82127 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82128 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82129 +#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)
82130 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82131 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82132 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82133 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82134 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82135 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82136 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82137 +#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)
82138 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82139 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82140 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82141 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82142 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82143 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82144 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82145 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82146 +#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)
82147 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82148 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82149 +
82150 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82151 +
82152 +#endif
82153 +
82154 +#endif
82155 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82156 new file mode 100644
82157 index 0000000..b02ba9d
82158 --- /dev/null
82159 +++ b/include/linux/grmsg.h
82160 @@ -0,0 +1,117 @@
82161 +#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"
82162 +#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"
82163 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82164 +#define GR_STOPMOD_MSG "denied modification of module state by "
82165 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82166 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82167 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82168 +#define GR_IOPL_MSG "denied use of iopl() by "
82169 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82170 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82171 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82172 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82173 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82174 +#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"
82175 +#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"
82176 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82177 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82178 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82179 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82180 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82181 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82182 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82183 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82184 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82185 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82186 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82187 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82188 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82189 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82190 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82191 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82192 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82193 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82194 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82195 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82196 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82197 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82198 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82199 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82200 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82201 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82202 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82203 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82204 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82205 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82206 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82207 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82208 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82209 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82210 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82211 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82212 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82213 +#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"
82214 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82215 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82216 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82217 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82218 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82219 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82220 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82221 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82222 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82223 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82224 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82225 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82226 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82227 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82228 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82229 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82230 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82231 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82232 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82233 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82234 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82235 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82236 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82237 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82238 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82239 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82240 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82241 +#define GR_TIME_MSG "time set by "
82242 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82243 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82244 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82245 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82246 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82247 +#define GR_BIND_MSG "denied bind() by "
82248 +#define GR_CONNECT_MSG "denied connect() by "
82249 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82250 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82251 +#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"
82252 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82253 +#define GR_CAP_ACL_MSG "use of %s denied for "
82254 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82255 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82256 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82257 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82258 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82259 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82260 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82261 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82262 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82263 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82264 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82265 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82266 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82267 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82268 +#define GR_VM86_MSG "denied use of vm86 by "
82269 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82270 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82271 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82272 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82273 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82274 +#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 "
82275 +#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 "
82276 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82277 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82278 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82279 new file mode 100644
82280 index 0000000..10b9635
82281 --- /dev/null
82282 +++ b/include/linux/grsecurity.h
82283 @@ -0,0 +1,254 @@
82284 +#ifndef GR_SECURITY_H
82285 +#define GR_SECURITY_H
82286 +#include <linux/fs.h>
82287 +#include <linux/fs_struct.h>
82288 +#include <linux/binfmts.h>
82289 +#include <linux/gracl.h>
82290 +
82291 +/* notify of brain-dead configs */
82292 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82293 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82294 +#endif
82295 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82296 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82297 +#endif
82298 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82299 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82300 +#endif
82301 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82302 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82303 +#endif
82304 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82305 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82306 +#endif
82307 +
82308 +int gr_handle_new_usb(void);
82309 +
82310 +void gr_handle_brute_attach(int dumpable);
82311 +void gr_handle_brute_check(void);
82312 +void gr_handle_kernel_exploit(void);
82313 +
82314 +char gr_roletype_to_char(void);
82315 +
82316 +int gr_proc_is_restricted(void);
82317 +
82318 +int gr_acl_enable_at_secure(void);
82319 +
82320 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82321 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82322 +
82323 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82324 +
82325 +void gr_del_task_from_ip_table(struct task_struct *p);
82326 +
82327 +int gr_pid_is_chrooted(struct task_struct *p);
82328 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82329 +int gr_handle_chroot_nice(void);
82330 +int gr_handle_chroot_sysctl(const int op);
82331 +int gr_handle_chroot_setpriority(struct task_struct *p,
82332 + const int niceval);
82333 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82334 +int gr_chroot_fhandle(void);
82335 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82336 + const struct vfsmount *mnt);
82337 +void gr_handle_chroot_chdir(const struct path *path);
82338 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82339 + const struct vfsmount *mnt, const int mode);
82340 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82341 + const struct vfsmount *mnt, const int mode);
82342 +int gr_handle_chroot_mount(const struct dentry *dentry,
82343 + const struct vfsmount *mnt,
82344 + const char *dev_name);
82345 +int gr_handle_chroot_pivot(void);
82346 +int gr_handle_chroot_unix(const pid_t pid);
82347 +
82348 +int gr_handle_rawio(const struct inode *inode);
82349 +
82350 +void gr_handle_ioperm(void);
82351 +void gr_handle_iopl(void);
82352 +void gr_handle_msr_write(void);
82353 +
82354 +umode_t gr_acl_umask(void);
82355 +
82356 +int gr_tpe_allow(const struct file *file);
82357 +
82358 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82359 +void gr_clear_chroot_entries(struct task_struct *task);
82360 +
82361 +void gr_log_forkfail(const int retval);
82362 +void gr_log_timechange(void);
82363 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82364 +void gr_log_chdir(const struct dentry *dentry,
82365 + const struct vfsmount *mnt);
82366 +void gr_log_chroot_exec(const struct dentry *dentry,
82367 + const struct vfsmount *mnt);
82368 +void gr_log_remount(const char *devname, const int retval);
82369 +void gr_log_unmount(const char *devname, const int retval);
82370 +void gr_log_mount(const char *from, const char *to, const int retval);
82371 +void gr_log_textrel(struct vm_area_struct *vma);
82372 +void gr_log_ptgnustack(struct file *file);
82373 +void gr_log_rwxmmap(struct file *file);
82374 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82375 +
82376 +int gr_handle_follow_link(const struct inode *parent,
82377 + const struct inode *inode,
82378 + const struct dentry *dentry,
82379 + const struct vfsmount *mnt);
82380 +int gr_handle_fifo(const struct dentry *dentry,
82381 + const struct vfsmount *mnt,
82382 + const struct dentry *dir, const int flag,
82383 + const int acc_mode);
82384 +int gr_handle_hardlink(const struct dentry *dentry,
82385 + const struct vfsmount *mnt,
82386 + struct inode *inode,
82387 + const int mode, const struct filename *to);
82388 +
82389 +int gr_is_capable(const int cap);
82390 +int gr_is_capable_nolog(const int cap);
82391 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82392 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82393 +
82394 +void gr_copy_label(struct task_struct *tsk);
82395 +void gr_handle_crash(struct task_struct *task, const int sig);
82396 +int gr_handle_signal(const struct task_struct *p, const int sig);
82397 +int gr_check_crash_uid(const kuid_t uid);
82398 +int gr_check_protected_task(const struct task_struct *task);
82399 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82400 +int gr_acl_handle_mmap(const struct file *file,
82401 + const unsigned long prot);
82402 +int gr_acl_handle_mprotect(const struct file *file,
82403 + const unsigned long prot);
82404 +int gr_check_hidden_task(const struct task_struct *tsk);
82405 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82406 + const struct vfsmount *mnt);
82407 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82408 + const struct vfsmount *mnt);
82409 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82410 + const struct vfsmount *mnt, const int fmode);
82411 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82412 + const struct vfsmount *mnt, umode_t *mode);
82413 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82414 + const struct vfsmount *mnt);
82415 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82416 + const struct vfsmount *mnt);
82417 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82418 + const struct vfsmount *mnt);
82419 +int gr_handle_ptrace(struct task_struct *task, const long request);
82420 +int gr_handle_proc_ptrace(struct task_struct *task);
82421 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82422 + const struct vfsmount *mnt);
82423 +int gr_check_crash_exec(const struct file *filp);
82424 +int gr_acl_is_enabled(void);
82425 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82426 + const kgid_t gid);
82427 +int gr_set_proc_label(const struct dentry *dentry,
82428 + const struct vfsmount *mnt,
82429 + const int unsafe_flags);
82430 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82431 + const struct vfsmount *mnt);
82432 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82433 + const struct vfsmount *mnt, int acc_mode);
82434 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82435 + const struct dentry *p_dentry,
82436 + const struct vfsmount *p_mnt,
82437 + int open_flags, int acc_mode, const int imode);
82438 +void gr_handle_create(const struct dentry *dentry,
82439 + const struct vfsmount *mnt);
82440 +void gr_handle_proc_create(const struct dentry *dentry,
82441 + const struct inode *inode);
82442 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82443 + const struct dentry *parent_dentry,
82444 + const struct vfsmount *parent_mnt,
82445 + const int mode);
82446 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82447 + const struct dentry *parent_dentry,
82448 + const struct vfsmount *parent_mnt);
82449 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82450 + const struct vfsmount *mnt);
82451 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82452 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82453 + const struct vfsmount *mnt);
82454 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82455 + const struct dentry *parent_dentry,
82456 + const struct vfsmount *parent_mnt,
82457 + const struct filename *from);
82458 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82459 + const struct dentry *parent_dentry,
82460 + const struct vfsmount *parent_mnt,
82461 + const struct dentry *old_dentry,
82462 + const struct vfsmount *old_mnt, const struct filename *to);
82463 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82464 +int gr_acl_handle_rename(struct dentry *new_dentry,
82465 + struct dentry *parent_dentry,
82466 + const struct vfsmount *parent_mnt,
82467 + struct dentry *old_dentry,
82468 + struct inode *old_parent_inode,
82469 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82470 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82471 + struct dentry *old_dentry,
82472 + struct dentry *new_dentry,
82473 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82474 +__u32 gr_check_link(const struct dentry *new_dentry,
82475 + const struct dentry *parent_dentry,
82476 + const struct vfsmount *parent_mnt,
82477 + const struct dentry *old_dentry,
82478 + const struct vfsmount *old_mnt);
82479 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82480 + const unsigned int namelen, const ino_t ino);
82481 +
82482 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82483 + const struct vfsmount *mnt);
82484 +void gr_acl_handle_exit(void);
82485 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82486 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82487 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82488 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82489 +void gr_audit_ptrace(struct task_struct *task);
82490 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82491 +void gr_put_exec_file(struct task_struct *task);
82492 +
82493 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82494 +
82495 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82496 +extern void gr_learn_resource(const struct task_struct *task, const int res,
82497 + const unsigned long wanted, const int gt);
82498 +#else
82499 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
82500 + const unsigned long wanted, const int gt)
82501 +{
82502 +}
82503 +#endif
82504 +
82505 +#ifdef CONFIG_GRKERNSEC_RESLOG
82506 +extern void gr_log_resource(const struct task_struct *task, const int res,
82507 + const unsigned long wanted, const int gt);
82508 +#else
82509 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82510 + const unsigned long wanted, const int gt)
82511 +{
82512 +}
82513 +#endif
82514 +
82515 +#ifdef CONFIG_GRKERNSEC
82516 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82517 +void gr_handle_vm86(void);
82518 +void gr_handle_mem_readwrite(u64 from, u64 to);
82519 +
82520 +void gr_log_badprocpid(const char *entry);
82521 +
82522 +extern int grsec_enable_dmesg;
82523 +extern int grsec_disable_privio;
82524 +
82525 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82526 +extern kgid_t grsec_proc_gid;
82527 +#endif
82528 +
82529 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82530 +extern int grsec_enable_chroot_findtask;
82531 +#endif
82532 +#ifdef CONFIG_GRKERNSEC_SETXID
82533 +extern int grsec_enable_setxid;
82534 +#endif
82535 +#endif
82536 +
82537 +#endif
82538 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82539 new file mode 100644
82540 index 0000000..e7ffaaf
82541 --- /dev/null
82542 +++ b/include/linux/grsock.h
82543 @@ -0,0 +1,19 @@
82544 +#ifndef __GRSOCK_H
82545 +#define __GRSOCK_H
82546 +
82547 +extern void gr_attach_curr_ip(const struct sock *sk);
82548 +extern int gr_handle_sock_all(const int family, const int type,
82549 + const int protocol);
82550 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82551 +extern int gr_handle_sock_server_other(const struct sock *sck);
82552 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82553 +extern int gr_search_connect(struct socket * sock,
82554 + struct sockaddr_in * addr);
82555 +extern int gr_search_bind(struct socket * sock,
82556 + struct sockaddr_in * addr);
82557 +extern int gr_search_listen(struct socket * sock);
82558 +extern int gr_search_accept(struct socket * sock);
82559 +extern int gr_search_socket(const int domain, const int type,
82560 + const int protocol);
82561 +
82562 +#endif
82563 diff --git a/include/linux/hash.h b/include/linux/hash.h
82564 index d0494c3..69b7715 100644
82565 --- a/include/linux/hash.h
82566 +++ b/include/linux/hash.h
82567 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82568 struct fast_hash_ops {
82569 u32 (*hash)(const void *data, u32 len, u32 seed);
82570 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82571 -};
82572 +} __no_const;
82573
82574 /**
82575 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82576 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82577 index 9286a46..373f27f 100644
82578 --- a/include/linux/highmem.h
82579 +++ b/include/linux/highmem.h
82580 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82581 kunmap_atomic(kaddr);
82582 }
82583
82584 +static inline void sanitize_highpage(struct page *page)
82585 +{
82586 + void *kaddr;
82587 + unsigned long flags;
82588 +
82589 + local_irq_save(flags);
82590 + kaddr = kmap_atomic(page);
82591 + clear_page(kaddr);
82592 + kunmap_atomic(kaddr);
82593 + local_irq_restore(flags);
82594 +}
82595 +
82596 static inline void zero_user_segments(struct page *page,
82597 unsigned start1, unsigned end1,
82598 unsigned start2, unsigned end2)
82599 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82600 index 1c7b89a..7dda400 100644
82601 --- a/include/linux/hwmon-sysfs.h
82602 +++ b/include/linux/hwmon-sysfs.h
82603 @@ -25,7 +25,8 @@
82604 struct sensor_device_attribute{
82605 struct device_attribute dev_attr;
82606 int index;
82607 -};
82608 +} __do_const;
82609 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82610 #define to_sensor_dev_attr(_dev_attr) \
82611 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82612
82613 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82614 struct device_attribute dev_attr;
82615 u8 index;
82616 u8 nr;
82617 -};
82618 +} __do_const;
82619 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82620 #define to_sensor_dev_attr_2(_dev_attr) \
82621 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82622
82623 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82624 index b556e0a..c10a515 100644
82625 --- a/include/linux/i2c.h
82626 +++ b/include/linux/i2c.h
82627 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82628 /* To determine what the adapter supports */
82629 u32 (*functionality) (struct i2c_adapter *);
82630 };
82631 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82632
82633 /**
82634 * struct i2c_bus_recovery_info - I2C bus recovery information
82635 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82636 index d23c3c2..eb63c81 100644
82637 --- a/include/linux/i2o.h
82638 +++ b/include/linux/i2o.h
82639 @@ -565,7 +565,7 @@ struct i2o_controller {
82640 struct i2o_device *exec; /* Executive */
82641 #if BITS_PER_LONG == 64
82642 spinlock_t context_list_lock; /* lock for context_list */
82643 - atomic_t context_list_counter; /* needed for unique contexts */
82644 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82645 struct list_head context_list; /* list of context id's
82646 and pointers */
82647 #endif
82648 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82649 index aff7ad8..3942bbd 100644
82650 --- a/include/linux/if_pppox.h
82651 +++ b/include/linux/if_pppox.h
82652 @@ -76,7 +76,7 @@ struct pppox_proto {
82653 int (*ioctl)(struct socket *sock, unsigned int cmd,
82654 unsigned long arg);
82655 struct module *owner;
82656 -};
82657 +} __do_const;
82658
82659 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82660 extern void unregister_pppox_proto(int proto_num);
82661 diff --git a/include/linux/init.h b/include/linux/init.h
82662 index 2df8e8d..3e1280d 100644
82663 --- a/include/linux/init.h
82664 +++ b/include/linux/init.h
82665 @@ -37,9 +37,17 @@
82666 * section.
82667 */
82668
82669 +#define add_init_latent_entropy __latent_entropy
82670 +
82671 +#ifdef CONFIG_MEMORY_HOTPLUG
82672 +#define add_meminit_latent_entropy
82673 +#else
82674 +#define add_meminit_latent_entropy __latent_entropy
82675 +#endif
82676 +
82677 /* These are for everybody (although not all archs will actually
82678 discard it in modules) */
82679 -#define __init __section(.init.text) __cold notrace
82680 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82681 #define __initdata __section(.init.data)
82682 #define __initconst __constsection(.init.rodata)
82683 #define __exitdata __section(.exit.data)
82684 @@ -100,7 +108,7 @@
82685 #define __cpuexitconst
82686
82687 /* Used for MEMORY_HOTPLUG */
82688 -#define __meminit __section(.meminit.text) __cold notrace
82689 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82690 #define __meminitdata __section(.meminit.data)
82691 #define __meminitconst __constsection(.meminit.rodata)
82692 #define __memexit __section(.memexit.text) __exitused __cold notrace
82693 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82694 index 2bb4c4f3..e0fac69 100644
82695 --- a/include/linux/init_task.h
82696 +++ b/include/linux/init_task.h
82697 @@ -149,6 +149,12 @@ extern struct task_group root_task_group;
82698
82699 #define INIT_TASK_COMM "swapper"
82700
82701 +#ifdef CONFIG_X86
82702 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82703 +#else
82704 +#define INIT_TASK_THREAD_INFO
82705 +#endif
82706 +
82707 #ifdef CONFIG_RT_MUTEXES
82708 # define INIT_RT_MUTEXES(tsk) \
82709 .pi_waiters = RB_ROOT, \
82710 @@ -196,6 +202,7 @@ extern struct task_group root_task_group;
82711 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82712 .comm = INIT_TASK_COMM, \
82713 .thread = INIT_THREAD, \
82714 + INIT_TASK_THREAD_INFO \
82715 .fs = &init_fs, \
82716 .files = &init_files, \
82717 .signal = &init_signals, \
82718 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82719 index 698ad05..8601bb7 100644
82720 --- a/include/linux/interrupt.h
82721 +++ b/include/linux/interrupt.h
82722 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82723
82724 struct softirq_action
82725 {
82726 - void (*action)(struct softirq_action *);
82727 -};
82728 + void (*action)(void);
82729 +} __no_const;
82730
82731 asmlinkage void do_softirq(void);
82732 asmlinkage void __do_softirq(void);
82733 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
82734 }
82735 #endif
82736
82737 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82738 +extern void open_softirq(int nr, void (*action)(void));
82739 extern void softirq_init(void);
82740 extern void __raise_softirq_irqoff(unsigned int nr);
82741
82742 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82743 index 20f9a52..63ee2e3 100644
82744 --- a/include/linux/iommu.h
82745 +++ b/include/linux/iommu.h
82746 @@ -131,7 +131,7 @@ struct iommu_ops {
82747 u32 (*domain_get_windows)(struct iommu_domain *domain);
82748
82749 unsigned long pgsize_bitmap;
82750 -};
82751 +} __do_const;
82752
82753 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82754 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82755 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82756 index 142ec54..873e033 100644
82757 --- a/include/linux/ioport.h
82758 +++ b/include/linux/ioport.h
82759 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82760 int adjust_resource(struct resource *res, resource_size_t start,
82761 resource_size_t size);
82762 resource_size_t resource_alignment(struct resource *res);
82763 -static inline resource_size_t resource_size(const struct resource *res)
82764 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82765 {
82766 return res->end - res->start + 1;
82767 }
82768 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82769 index 35e7eca..6afb7ad 100644
82770 --- a/include/linux/ipc_namespace.h
82771 +++ b/include/linux/ipc_namespace.h
82772 @@ -69,7 +69,7 @@ struct ipc_namespace {
82773 struct user_namespace *user_ns;
82774
82775 unsigned int proc_inum;
82776 -};
82777 +} __randomize_layout;
82778
82779 extern struct ipc_namespace init_ipc_ns;
82780 extern atomic_t nr_ipc_ns;
82781 diff --git a/include/linux/irq.h b/include/linux/irq.h
82782 index 62af592..cc3b0d0 100644
82783 --- a/include/linux/irq.h
82784 +++ b/include/linux/irq.h
82785 @@ -344,7 +344,8 @@ struct irq_chip {
82786 void (*irq_release_resources)(struct irq_data *data);
82787
82788 unsigned long flags;
82789 -};
82790 +} __do_const;
82791 +typedef struct irq_chip __no_const irq_chip_no_const;
82792
82793 /*
82794 * irq_chip specific flags
82795 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82796 index 45e2d8c..26d85da 100644
82797 --- a/include/linux/irqchip/arm-gic.h
82798 +++ b/include/linux/irqchip/arm-gic.h
82799 @@ -75,9 +75,11 @@
82800
82801 #ifndef __ASSEMBLY__
82802
82803 +#include <linux/irq.h>
82804 +
82805 struct device_node;
82806
82807 -extern struct irq_chip gic_arch_extn;
82808 +extern irq_chip_no_const gic_arch_extn;
82809
82810 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82811 u32 offset, struct device_node *);
82812 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82813 index c367cbd..c9b79e6 100644
82814 --- a/include/linux/jiffies.h
82815 +++ b/include/linux/jiffies.h
82816 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82817 /*
82818 * Convert various time units to each other:
82819 */
82820 -extern unsigned int jiffies_to_msecs(const unsigned long j);
82821 -extern unsigned int jiffies_to_usecs(const unsigned long j);
82822 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82823 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82824
82825 -static inline u64 jiffies_to_nsecs(const unsigned long j)
82826 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82827 {
82828 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82829 }
82830
82831 -extern unsigned long msecs_to_jiffies(const unsigned int m);
82832 -extern unsigned long usecs_to_jiffies(const unsigned int u);
82833 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82834 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82835 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82836 extern void jiffies_to_timespec(const unsigned long jiffies,
82837 - struct timespec *value);
82838 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
82839 + struct timespec *value) __intentional_overflow(-1);
82840 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82841 extern void jiffies_to_timeval(const unsigned long jiffies,
82842 struct timeval *value);
82843
82844 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82845 index 6883e19..e854fcb 100644
82846 --- a/include/linux/kallsyms.h
82847 +++ b/include/linux/kallsyms.h
82848 @@ -15,7 +15,8 @@
82849
82850 struct module;
82851
82852 -#ifdef CONFIG_KALLSYMS
82853 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82854 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82855 /* Lookup the address for a symbol. Returns 0 if not found. */
82856 unsigned long kallsyms_lookup_name(const char *name);
82857
82858 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82859 /* Stupid that this does nothing, but I didn't create this mess. */
82860 #define __print_symbol(fmt, addr)
82861 #endif /*CONFIG_KALLSYMS*/
82862 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82863 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82864 +extern unsigned long kallsyms_lookup_name(const char *name);
82865 +extern void __print_symbol(const char *fmt, unsigned long address);
82866 +extern int sprint_backtrace(char *buffer, unsigned long address);
82867 +extern int sprint_symbol(char *buffer, unsigned long address);
82868 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82869 +const char *kallsyms_lookup(unsigned long addr,
82870 + unsigned long *symbolsize,
82871 + unsigned long *offset,
82872 + char **modname, char *namebuf);
82873 +extern int kallsyms_lookup_size_offset(unsigned long addr,
82874 + unsigned long *symbolsize,
82875 + unsigned long *offset);
82876 +#endif
82877
82878 /* This macro allows us to keep printk typechecking */
82879 static __printf(1, 2)
82880 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
82881 index 44792ee..6172f2a 100644
82882 --- a/include/linux/key-type.h
82883 +++ b/include/linux/key-type.h
82884 @@ -132,7 +132,7 @@ struct key_type {
82885 /* internal fields */
82886 struct list_head link; /* link in types list */
82887 struct lock_class_key lock_class; /* key->sem lock class */
82888 -};
82889 +} __do_const;
82890
82891 extern struct key_type key_type_keyring;
82892
82893 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
82894 index e465bb1..19f605f 100644
82895 --- a/include/linux/kgdb.h
82896 +++ b/include/linux/kgdb.h
82897 @@ -52,7 +52,7 @@ extern int kgdb_connected;
82898 extern int kgdb_io_module_registered;
82899
82900 extern atomic_t kgdb_setting_breakpoint;
82901 -extern atomic_t kgdb_cpu_doing_single_step;
82902 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
82903
82904 extern struct task_struct *kgdb_usethread;
82905 extern struct task_struct *kgdb_contthread;
82906 @@ -254,7 +254,7 @@ struct kgdb_arch {
82907 void (*correct_hw_break)(void);
82908
82909 void (*enable_nmi)(bool on);
82910 -};
82911 +} __do_const;
82912
82913 /**
82914 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
82915 @@ -279,7 +279,7 @@ struct kgdb_io {
82916 void (*pre_exception) (void);
82917 void (*post_exception) (void);
82918 int is_console;
82919 -};
82920 +} __do_const;
82921
82922 extern struct kgdb_arch arch_kgdb_ops;
82923
82924 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
82925 index 0555cc6..40116ce 100644
82926 --- a/include/linux/kmod.h
82927 +++ b/include/linux/kmod.h
82928 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
82929 * usually useless though. */
82930 extern __printf(2, 3)
82931 int __request_module(bool wait, const char *name, ...);
82932 +extern __printf(3, 4)
82933 +int ___request_module(bool wait, char *param_name, const char *name, ...);
82934 #define request_module(mod...) __request_module(true, mod)
82935 #define request_module_nowait(mod...) __request_module(false, mod)
82936 #define try_then_request_module(x, mod...) \
82937 @@ -57,6 +59,9 @@ struct subprocess_info {
82938 struct work_struct work;
82939 struct completion *complete;
82940 char *path;
82941 +#ifdef CONFIG_GRKERNSEC
82942 + char *origpath;
82943 +#endif
82944 char **argv;
82945 char **envp;
82946 int wait;
82947 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
82948 index 2d61b90..a1d0a13 100644
82949 --- a/include/linux/kobject.h
82950 +++ b/include/linux/kobject.h
82951 @@ -118,7 +118,7 @@ struct kobj_type {
82952 struct attribute **default_attrs;
82953 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
82954 const void *(*namespace)(struct kobject *kobj);
82955 -};
82956 +} __do_const;
82957
82958 struct kobj_uevent_env {
82959 char *argv[3];
82960 @@ -142,6 +142,7 @@ struct kobj_attribute {
82961 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
82962 const char *buf, size_t count);
82963 };
82964 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
82965
82966 extern const struct sysfs_ops kobj_sysfs_ops;
82967
82968 @@ -169,7 +170,7 @@ struct kset {
82969 spinlock_t list_lock;
82970 struct kobject kobj;
82971 const struct kset_uevent_ops *uevent_ops;
82972 -};
82973 +} __randomize_layout;
82974
82975 extern void kset_init(struct kset *kset);
82976 extern int __must_check kset_register(struct kset *kset);
82977 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
82978 index df32d25..fb52e27 100644
82979 --- a/include/linux/kobject_ns.h
82980 +++ b/include/linux/kobject_ns.h
82981 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
82982 const void *(*netlink_ns)(struct sock *sk);
82983 const void *(*initial_ns)(void);
82984 void (*drop_ns)(void *);
82985 -};
82986 +} __do_const;
82987
82988 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
82989 int kobj_ns_type_registered(enum kobj_ns_type type);
82990 diff --git a/include/linux/kref.h b/include/linux/kref.h
82991 index 484604d..0f6c5b6 100644
82992 --- a/include/linux/kref.h
82993 +++ b/include/linux/kref.h
82994 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
82995 static inline int kref_sub(struct kref *kref, unsigned int count,
82996 void (*release)(struct kref *kref))
82997 {
82998 - WARN_ON(release == NULL);
82999 + BUG_ON(release == NULL);
83000
83001 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83002 release(kref);
83003 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83004 index a4c33b3..e854710 100644
83005 --- a/include/linux/kvm_host.h
83006 +++ b/include/linux/kvm_host.h
83007 @@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
83008 {
83009 }
83010 #endif
83011 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83012 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83013 struct module *module);
83014 void kvm_exit(void);
83015
83016 @@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83017 struct kvm_guest_debug *dbg);
83018 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83019
83020 -int kvm_arch_init(void *opaque);
83021 +int kvm_arch_init(const void *opaque);
83022 void kvm_arch_exit(void);
83023
83024 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83025 diff --git a/include/linux/libata.h b/include/linux/libata.h
83026 index 92abb49..e7fff2a 100644
83027 --- a/include/linux/libata.h
83028 +++ b/include/linux/libata.h
83029 @@ -976,7 +976,7 @@ struct ata_port_operations {
83030 * fields must be pointers.
83031 */
83032 const struct ata_port_operations *inherits;
83033 -};
83034 +} __do_const;
83035
83036 struct ata_port_info {
83037 unsigned long flags;
83038 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83039 index a6a42dd..6c5ebce 100644
83040 --- a/include/linux/linkage.h
83041 +++ b/include/linux/linkage.h
83042 @@ -36,6 +36,7 @@
83043 #endif
83044
83045 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83046 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83047 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83048
83049 /*
83050 diff --git a/include/linux/list.h b/include/linux/list.h
83051 index cbbb96f..602d023 100644
83052 --- a/include/linux/list.h
83053 +++ b/include/linux/list.h
83054 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
83055 extern void list_del(struct list_head *entry);
83056 #endif
83057
83058 +extern void __pax_list_add(struct list_head *new,
83059 + struct list_head *prev,
83060 + struct list_head *next);
83061 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83062 +{
83063 + __pax_list_add(new, head, head->next);
83064 +}
83065 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83066 +{
83067 + __pax_list_add(new, head->prev, head);
83068 +}
83069 +extern void pax_list_del(struct list_head *entry);
83070 +
83071 /**
83072 * list_replace - replace old entry by new one
83073 * @old : the element to be replaced
83074 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
83075 INIT_LIST_HEAD(entry);
83076 }
83077
83078 +extern void pax_list_del_init(struct list_head *entry);
83079 +
83080 /**
83081 * list_move - delete from one list and add as another's head
83082 * @list: the entry to move
83083 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83084 index 4bfde0e..d6e2e09 100644
83085 --- a/include/linux/lockref.h
83086 +++ b/include/linux/lockref.h
83087 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83088 return ((int)l->count < 0);
83089 }
83090
83091 +static inline unsigned int __lockref_read(struct lockref *lockref)
83092 +{
83093 + return lockref->count;
83094 +}
83095 +
83096 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83097 +{
83098 + lockref->count = count;
83099 +}
83100 +
83101 +static inline void __lockref_inc(struct lockref *lockref)
83102 +{
83103 +
83104 +#ifdef CONFIG_PAX_REFCOUNT
83105 + atomic_inc((atomic_t *)&lockref->count);
83106 +#else
83107 + lockref->count++;
83108 +#endif
83109 +
83110 +}
83111 +
83112 +static inline void __lockref_dec(struct lockref *lockref)
83113 +{
83114 +
83115 +#ifdef CONFIG_PAX_REFCOUNT
83116 + atomic_dec((atomic_t *)&lockref->count);
83117 +#else
83118 + lockref->count--;
83119 +#endif
83120 +
83121 +}
83122 +
83123 #endif /* __LINUX_LOCKREF_H */
83124 diff --git a/include/linux/math64.h b/include/linux/math64.h
83125 index c45c089..298841c 100644
83126 --- a/include/linux/math64.h
83127 +++ b/include/linux/math64.h
83128 @@ -15,7 +15,7 @@
83129 * This is commonly provided by 32bit archs to provide an optimized 64bit
83130 * divide.
83131 */
83132 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83133 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83134 {
83135 *remainder = dividend % divisor;
83136 return dividend / divisor;
83137 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83138 /**
83139 * div64_u64 - unsigned 64bit divide with 64bit divisor
83140 */
83141 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83142 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83143 {
83144 return dividend / divisor;
83145 }
83146 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83147 #define div64_ul(x, y) div_u64((x), (y))
83148
83149 #ifndef div_u64_rem
83150 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83151 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83152 {
83153 *remainder = do_div(dividend, divisor);
83154 return dividend;
83155 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83156 #endif
83157
83158 #ifndef div64_u64
83159 -extern u64 div64_u64(u64 dividend, u64 divisor);
83160 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83161 #endif
83162
83163 #ifndef div64_s64
83164 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83165 * divide.
83166 */
83167 #ifndef div_u64
83168 -static inline u64 div_u64(u64 dividend, u32 divisor)
83169 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83170 {
83171 u32 remainder;
83172 return div_u64_rem(dividend, divisor, &remainder);
83173 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83174 index f230a97..714c006 100644
83175 --- a/include/linux/mempolicy.h
83176 +++ b/include/linux/mempolicy.h
83177 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83178 }
83179
83180 #define vma_policy(vma) ((vma)->vm_policy)
83181 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83182 +{
83183 + vma->vm_policy = pol;
83184 +}
83185
83186 static inline void mpol_get(struct mempolicy *pol)
83187 {
83188 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83189 }
83190
83191 #define vma_policy(vma) NULL
83192 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83193 +{
83194 +}
83195
83196 static inline int
83197 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83198 diff --git a/include/linux/mm.h b/include/linux/mm.h
83199 index f952cc8..b9f6135 100644
83200 --- a/include/linux/mm.h
83201 +++ b/include/linux/mm.h
83202 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
83203 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83204 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83205 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83206 +
83207 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83208 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83209 +#endif
83210 +
83211 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83212
83213 #ifdef CONFIG_MEM_SOFT_DIRTY
83214 @@ -237,8 +242,8 @@ struct vm_operations_struct {
83215 /* called by access_process_vm when get_user_pages() fails, typically
83216 * for use by special VMAs that can switch between memory and hardware
83217 */
83218 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83219 - void *buf, int len, int write);
83220 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83221 + void *buf, size_t len, int write);
83222
83223 /* Called by the /proc/PID/maps code to ask the vma whether it
83224 * has a special name. Returning non-NULL will also cause this
83225 @@ -274,6 +279,7 @@ struct vm_operations_struct {
83226 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83227 unsigned long size, pgoff_t pgoff);
83228 };
83229 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83230
83231 struct mmu_gather;
83232 struct inode;
83233 @@ -1163,8 +1169,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83234 unsigned long *pfn);
83235 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83236 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83237 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83238 - void *buf, int len, int write);
83239 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83240 + void *buf, size_t len, int write);
83241
83242 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83243 loff_t const holebegin, loff_t const holelen)
83244 @@ -1204,9 +1210,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83245 }
83246 #endif
83247
83248 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83249 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83250 - void *buf, int len, int write);
83251 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83252 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83253 + void *buf, size_t len, int write);
83254
83255 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83256 unsigned long start, unsigned long nr_pages,
83257 @@ -1238,34 +1244,6 @@ int set_page_dirty_lock(struct page *page);
83258 int clear_page_dirty_for_io(struct page *page);
83259 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83260
83261 -/* Is the vma a continuation of the stack vma above it? */
83262 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83263 -{
83264 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83265 -}
83266 -
83267 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83268 - unsigned long addr)
83269 -{
83270 - return (vma->vm_flags & VM_GROWSDOWN) &&
83271 - (vma->vm_start == addr) &&
83272 - !vma_growsdown(vma->vm_prev, addr);
83273 -}
83274 -
83275 -/* Is the vma a continuation of the stack vma below it? */
83276 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83277 -{
83278 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83279 -}
83280 -
83281 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83282 - unsigned long addr)
83283 -{
83284 - return (vma->vm_flags & VM_GROWSUP) &&
83285 - (vma->vm_end == addr) &&
83286 - !vma_growsup(vma->vm_next, addr);
83287 -}
83288 -
83289 extern pid_t
83290 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
83291
83292 @@ -1365,6 +1343,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
83293 }
83294 #endif
83295
83296 +#ifdef CONFIG_MMU
83297 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83298 +#else
83299 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83300 +{
83301 + return __pgprot(0);
83302 +}
83303 +#endif
83304 +
83305 int vma_wants_writenotify(struct vm_area_struct *vma);
83306
83307 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
83308 @@ -1383,8 +1370,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83309 {
83310 return 0;
83311 }
83312 +
83313 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83314 + unsigned long address)
83315 +{
83316 + return 0;
83317 +}
83318 #else
83319 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83320 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83321 #endif
83322
83323 #ifdef __PAGETABLE_PMD_FOLDED
83324 @@ -1393,8 +1387,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83325 {
83326 return 0;
83327 }
83328 +
83329 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83330 + unsigned long address)
83331 +{
83332 + return 0;
83333 +}
83334 #else
83335 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83336 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83337 #endif
83338
83339 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83340 @@ -1412,11 +1413,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83341 NULL: pud_offset(pgd, address);
83342 }
83343
83344 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83345 +{
83346 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83347 + NULL: pud_offset(pgd, address);
83348 +}
83349 +
83350 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83351 {
83352 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83353 NULL: pmd_offset(pud, address);
83354 }
83355 +
83356 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83357 +{
83358 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83359 + NULL: pmd_offset(pud, address);
83360 +}
83361 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83362
83363 #if USE_SPLIT_PTE_PTLOCKS
83364 @@ -1815,7 +1828,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83365 unsigned long addr, unsigned long len,
83366 unsigned long flags, struct page **pages);
83367
83368 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83369 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83370
83371 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83372 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83373 @@ -1823,6 +1836,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83374 unsigned long len, unsigned long prot, unsigned long flags,
83375 unsigned long pgoff, unsigned long *populate);
83376 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83377 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83378
83379 #ifdef CONFIG_MMU
83380 extern int __mm_populate(unsigned long addr, unsigned long len,
83381 @@ -1851,10 +1865,11 @@ struct vm_unmapped_area_info {
83382 unsigned long high_limit;
83383 unsigned long align_mask;
83384 unsigned long align_offset;
83385 + unsigned long threadstack_offset;
83386 };
83387
83388 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83389 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83390 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83391 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83392
83393 /*
83394 * Search for an unmapped address range.
83395 @@ -1866,7 +1881,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83396 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83397 */
83398 static inline unsigned long
83399 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83400 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83401 {
83402 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83403 return unmapped_area(info);
83404 @@ -1928,6 +1943,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83405 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83406 struct vm_area_struct **pprev);
83407
83408 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83409 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83410 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83411 +
83412 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83413 NULL if none. Assume start_addr < end_addr. */
83414 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83415 @@ -1956,15 +1975,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83416 return vma;
83417 }
83418
83419 -#ifdef CONFIG_MMU
83420 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83421 -#else
83422 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83423 -{
83424 - return __pgprot(0);
83425 -}
83426 -#endif
83427 -
83428 #ifdef CONFIG_NUMA_BALANCING
83429 unsigned long change_prot_numa(struct vm_area_struct *vma,
83430 unsigned long start, unsigned long end);
83431 @@ -2016,6 +2026,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83432 static inline void vm_stat_account(struct mm_struct *mm,
83433 unsigned long flags, struct file *file, long pages)
83434 {
83435 +
83436 +#ifdef CONFIG_PAX_RANDMMAP
83437 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83438 +#endif
83439 +
83440 mm->total_vm += pages;
83441 }
83442 #endif /* CONFIG_PROC_FS */
83443 @@ -2104,7 +2119,7 @@ extern int unpoison_memory(unsigned long pfn);
83444 extern int sysctl_memory_failure_early_kill;
83445 extern int sysctl_memory_failure_recovery;
83446 extern void shake_page(struct page *p, int access);
83447 -extern atomic_long_t num_poisoned_pages;
83448 +extern atomic_long_unchecked_t num_poisoned_pages;
83449 extern int soft_offline_page(struct page *page, int flags);
83450
83451 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83452 @@ -2139,5 +2154,11 @@ void __init setup_nr_node_ids(void);
83453 static inline void setup_nr_node_ids(void) {}
83454 #endif
83455
83456 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83457 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83458 +#else
83459 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83460 +#endif
83461 +
83462 #endif /* __KERNEL__ */
83463 #endif /* _LINUX_MM_H */
83464 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83465 index 6e0b286..90d9c0d 100644
83466 --- a/include/linux/mm_types.h
83467 +++ b/include/linux/mm_types.h
83468 @@ -308,7 +308,9 @@ struct vm_area_struct {
83469 #ifdef CONFIG_NUMA
83470 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83471 #endif
83472 -};
83473 +
83474 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83475 +} __randomize_layout;
83476
83477 struct core_thread {
83478 struct task_struct *task;
83479 @@ -454,7 +456,25 @@ struct mm_struct {
83480 bool tlb_flush_pending;
83481 #endif
83482 struct uprobes_state uprobes_state;
83483 -};
83484 +
83485 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83486 + unsigned long pax_flags;
83487 +#endif
83488 +
83489 +#ifdef CONFIG_PAX_DLRESOLVE
83490 + unsigned long call_dl_resolve;
83491 +#endif
83492 +
83493 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83494 + unsigned long call_syscall;
83495 +#endif
83496 +
83497 +#ifdef CONFIG_PAX_ASLR
83498 + unsigned long delta_mmap; /* randomized offset */
83499 + unsigned long delta_stack; /* randomized offset */
83500 +#endif
83501 +
83502 +} __randomize_layout;
83503
83504 static inline void mm_init_cpumask(struct mm_struct *mm)
83505 {
83506 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83507 index c5d5278..f0b68c8 100644
83508 --- a/include/linux/mmiotrace.h
83509 +++ b/include/linux/mmiotrace.h
83510 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83511 /* Called from ioremap.c */
83512 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83513 void __iomem *addr);
83514 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83515 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83516
83517 /* For anyone to insert markers. Remember trailing newline. */
83518 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83519 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83520 {
83521 }
83522
83523 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83524 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83525 {
83526 }
83527
83528 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83529 index b21bac4..94142ca 100644
83530 --- a/include/linux/mmzone.h
83531 +++ b/include/linux/mmzone.h
83532 @@ -527,7 +527,7 @@ struct zone {
83533
83534 ZONE_PADDING(_pad3_)
83535 /* Zone statistics */
83536 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83537 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83538 } ____cacheline_internodealigned_in_smp;
83539
83540 typedef enum {
83541 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83542 index 44eeef0..a92d3f9 100644
83543 --- a/include/linux/mod_devicetable.h
83544 +++ b/include/linux/mod_devicetable.h
83545 @@ -139,7 +139,7 @@ struct usb_device_id {
83546 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83547 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83548
83549 -#define HID_ANY_ID (~0)
83550 +#define HID_ANY_ID (~0U)
83551 #define HID_BUS_ANY 0xffff
83552 #define HID_GROUP_ANY 0x0000
83553
83554 @@ -475,7 +475,7 @@ struct dmi_system_id {
83555 const char *ident;
83556 struct dmi_strmatch matches[4];
83557 void *driver_data;
83558 -};
83559 +} __do_const;
83560 /*
83561 * struct dmi_device_id appears during expansion of
83562 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83563 diff --git a/include/linux/module.h b/include/linux/module.h
83564 index 71f282a..b2387e2 100644
83565 --- a/include/linux/module.h
83566 +++ b/include/linux/module.h
83567 @@ -17,9 +17,11 @@
83568 #include <linux/moduleparam.h>
83569 #include <linux/jump_label.h>
83570 #include <linux/export.h>
83571 +#include <linux/fs.h>
83572
83573 #include <linux/percpu.h>
83574 #include <asm/module.h>
83575 +#include <asm/pgtable.h>
83576
83577 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83578 #define MODULE_SIG_STRING "~Module signature appended~\n"
83579 @@ -42,7 +44,7 @@ struct module_kobject {
83580 struct kobject *drivers_dir;
83581 struct module_param_attrs *mp;
83582 struct completion *kobj_completion;
83583 -};
83584 +} __randomize_layout;
83585
83586 struct module_attribute {
83587 struct attribute attr;
83588 @@ -54,12 +56,13 @@ struct module_attribute {
83589 int (*test)(struct module *);
83590 void (*free)(struct module *);
83591 };
83592 +typedef struct module_attribute __no_const module_attribute_no_const;
83593
83594 struct module_version_attribute {
83595 struct module_attribute mattr;
83596 const char *module_name;
83597 const char *version;
83598 -} __attribute__ ((__aligned__(sizeof(void *))));
83599 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83600
83601 extern ssize_t __modver_version_show(struct module_attribute *,
83602 struct module_kobject *, char *);
83603 @@ -235,7 +238,7 @@ struct module {
83604
83605 /* Sysfs stuff. */
83606 struct module_kobject mkobj;
83607 - struct module_attribute *modinfo_attrs;
83608 + module_attribute_no_const *modinfo_attrs;
83609 const char *version;
83610 const char *srcversion;
83611 struct kobject *holders_dir;
83612 @@ -284,19 +287,16 @@ struct module {
83613 int (*init)(void);
83614
83615 /* If this is non-NULL, vfree after init() returns */
83616 - void *module_init;
83617 + void *module_init_rx, *module_init_rw;
83618
83619 /* Here is the actual code + data, vfree'd on unload. */
83620 - void *module_core;
83621 + void *module_core_rx, *module_core_rw;
83622
83623 /* Here are the sizes of the init and core sections */
83624 - unsigned int init_size, core_size;
83625 + unsigned int init_size_rw, core_size_rw;
83626
83627 /* The size of the executable code in each section. */
83628 - unsigned int init_text_size, core_text_size;
83629 -
83630 - /* Size of RO sections of the module (text+rodata) */
83631 - unsigned int init_ro_size, core_ro_size;
83632 + unsigned int init_size_rx, core_size_rx;
83633
83634 /* Arch-specific module values */
83635 struct mod_arch_specific arch;
83636 @@ -352,6 +352,10 @@ struct module {
83637 #ifdef CONFIG_EVENT_TRACING
83638 struct ftrace_event_call **trace_events;
83639 unsigned int num_trace_events;
83640 + struct file_operations trace_id;
83641 + struct file_operations trace_enable;
83642 + struct file_operations trace_format;
83643 + struct file_operations trace_filter;
83644 #endif
83645 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83646 unsigned int num_ftrace_callsites;
83647 @@ -375,7 +379,7 @@ struct module {
83648 ctor_fn_t *ctors;
83649 unsigned int num_ctors;
83650 #endif
83651 -};
83652 +} __randomize_layout;
83653 #ifndef MODULE_ARCH_INIT
83654 #define MODULE_ARCH_INIT {}
83655 #endif
83656 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83657 bool is_module_percpu_address(unsigned long addr);
83658 bool is_module_text_address(unsigned long addr);
83659
83660 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83661 +{
83662 +
83663 +#ifdef CONFIG_PAX_KERNEXEC
83664 + if (ktla_ktva(addr) >= (unsigned long)start &&
83665 + ktla_ktva(addr) < (unsigned long)start + size)
83666 + return 1;
83667 +#endif
83668 +
83669 + return ((void *)addr >= start && (void *)addr < start + size);
83670 +}
83671 +
83672 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83673 +{
83674 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83675 +}
83676 +
83677 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83678 +{
83679 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83680 +}
83681 +
83682 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83683 +{
83684 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83685 +}
83686 +
83687 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83688 +{
83689 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83690 +}
83691 +
83692 static inline bool within_module_core(unsigned long addr,
83693 const struct module *mod)
83694 {
83695 - return (unsigned long)mod->module_core <= addr &&
83696 - addr < (unsigned long)mod->module_core + mod->core_size;
83697 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83698 }
83699
83700 static inline bool within_module_init(unsigned long addr,
83701 const struct module *mod)
83702 {
83703 - return (unsigned long)mod->module_init <= addr &&
83704 - addr < (unsigned long)mod->module_init + mod->init_size;
83705 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83706 }
83707
83708 static inline bool within_module(unsigned long addr, const struct module *mod)
83709 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83710 index 7eeb9bb..68f37e0 100644
83711 --- a/include/linux/moduleloader.h
83712 +++ b/include/linux/moduleloader.h
83713 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83714 sections. Returns NULL on failure. */
83715 void *module_alloc(unsigned long size);
83716
83717 +#ifdef CONFIG_PAX_KERNEXEC
83718 +void *module_alloc_exec(unsigned long size);
83719 +#else
83720 +#define module_alloc_exec(x) module_alloc(x)
83721 +#endif
83722 +
83723 /* Free memory returned from module_alloc. */
83724 void module_free(struct module *mod, void *module_region);
83725
83726 +#ifdef CONFIG_PAX_KERNEXEC
83727 +void module_free_exec(struct module *mod, void *module_region);
83728 +#else
83729 +#define module_free_exec(x, y) module_free((x), (y))
83730 +#endif
83731 +
83732 /*
83733 * Apply the given relocation to the (simplified) ELF. Return -error
83734 * or 0.
83735 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83736 unsigned int relsec,
83737 struct module *me)
83738 {
83739 +#ifdef CONFIG_MODULES
83740 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83741 module_name(me));
83742 +#endif
83743 return -ENOEXEC;
83744 }
83745 #endif
83746 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83747 unsigned int relsec,
83748 struct module *me)
83749 {
83750 +#ifdef CONFIG_MODULES
83751 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83752 module_name(me));
83753 +#endif
83754 return -ENOEXEC;
83755 }
83756 #endif
83757 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83758 index 494f99e..5059f63 100644
83759 --- a/include/linux/moduleparam.h
83760 +++ b/include/linux/moduleparam.h
83761 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
83762 * @len is usually just sizeof(string).
83763 */
83764 #define module_param_string(name, string, len, perm) \
83765 - static const struct kparam_string __param_string_##name \
83766 + static const struct kparam_string __param_string_##name __used \
83767 = { len, string }; \
83768 __module_param_call(MODULE_PARAM_PREFIX, name, \
83769 &param_ops_string, \
83770 @@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83771 */
83772 #define module_param_array_named(name, array, type, nump, perm) \
83773 param_check_##type(name, &(array)[0]); \
83774 - static const struct kparam_array __param_arr_##name \
83775 + static const struct kparam_array __param_arr_##name __used \
83776 = { .max = ARRAY_SIZE(array), .num = nump, \
83777 .ops = &param_ops_##type, \
83778 .elemsize = sizeof(array[0]), .elem = array }; \
83779 diff --git a/include/linux/mount.h b/include/linux/mount.h
83780 index 9262e4b..0a45f98 100644
83781 --- a/include/linux/mount.h
83782 +++ b/include/linux/mount.h
83783 @@ -66,7 +66,7 @@ struct vfsmount {
83784 struct dentry *mnt_root; /* root of the mounted tree */
83785 struct super_block *mnt_sb; /* pointer to superblock */
83786 int mnt_flags;
83787 -};
83788 +} __randomize_layout;
83789
83790 struct file; /* forward dec */
83791 struct path;
83792 diff --git a/include/linux/namei.h b/include/linux/namei.h
83793 index 492de72..1bddcd4 100644
83794 --- a/include/linux/namei.h
83795 +++ b/include/linux/namei.h
83796 @@ -19,7 +19,7 @@ struct nameidata {
83797 unsigned seq, m_seq;
83798 int last_type;
83799 unsigned depth;
83800 - char *saved_names[MAX_NESTED_LINKS + 1];
83801 + const char *saved_names[MAX_NESTED_LINKS + 1];
83802 };
83803
83804 /*
83805 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83806
83807 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83808
83809 -static inline void nd_set_link(struct nameidata *nd, char *path)
83810 +static inline void nd_set_link(struct nameidata *nd, const char *path)
83811 {
83812 nd->saved_names[nd->depth] = path;
83813 }
83814
83815 -static inline char *nd_get_link(struct nameidata *nd)
83816 +static inline const char *nd_get_link(const struct nameidata *nd)
83817 {
83818 return nd->saved_names[nd->depth];
83819 }
83820 diff --git a/include/linux/net.h b/include/linux/net.h
83821 index 17d8339..81656c0 100644
83822 --- a/include/linux/net.h
83823 +++ b/include/linux/net.h
83824 @@ -192,7 +192,7 @@ struct net_proto_family {
83825 int (*create)(struct net *net, struct socket *sock,
83826 int protocol, int kern);
83827 struct module *owner;
83828 -};
83829 +} __do_const;
83830
83831 struct iovec;
83832 struct kvec;
83833 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83834 index c8e388e..5d8cd9b 100644
83835 --- a/include/linux/netdevice.h
83836 +++ b/include/linux/netdevice.h
83837 @@ -1147,6 +1147,7 @@ struct net_device_ops {
83838 void *priv);
83839 int (*ndo_get_lock_subclass)(struct net_device *dev);
83840 };
83841 +typedef struct net_device_ops __no_const net_device_ops_no_const;
83842
83843 /**
83844 * enum net_device_priv_flags - &struct net_device priv_flags
83845 @@ -1485,10 +1486,10 @@ struct net_device {
83846
83847 struct net_device_stats stats;
83848
83849 - atomic_long_t rx_dropped;
83850 - atomic_long_t tx_dropped;
83851 + atomic_long_unchecked_t rx_dropped;
83852 + atomic_long_unchecked_t tx_dropped;
83853
83854 - atomic_t carrier_changes;
83855 + atomic_unchecked_t carrier_changes;
83856
83857 #ifdef CONFIG_WIRELESS_EXT
83858 const struct iw_handler_def * wireless_handlers;
83859 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83860 index 2517ece..0bbfcfb 100644
83861 --- a/include/linux/netfilter.h
83862 +++ b/include/linux/netfilter.h
83863 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83864 #endif
83865 /* Use the module struct to lock set/get code in place */
83866 struct module *owner;
83867 -};
83868 +} __do_const;
83869
83870 /* Function to register/unregister hook points. */
83871 int nf_register_hook(struct nf_hook_ops *reg);
83872 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83873 index e955d47..04a5338 100644
83874 --- a/include/linux/netfilter/nfnetlink.h
83875 +++ b/include/linux/netfilter/nfnetlink.h
83876 @@ -19,7 +19,7 @@ struct nfnl_callback {
83877 const struct nlattr * const cda[]);
83878 const struct nla_policy *policy; /* netlink attribute policy */
83879 const u_int16_t attr_count; /* number of nlattr's */
83880 -};
83881 +} __do_const;
83882
83883 struct nfnetlink_subsystem {
83884 const char *name;
83885 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
83886 new file mode 100644
83887 index 0000000..33f4af8
83888 --- /dev/null
83889 +++ b/include/linux/netfilter/xt_gradm.h
83890 @@ -0,0 +1,9 @@
83891 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
83892 +#define _LINUX_NETFILTER_XT_GRADM_H 1
83893 +
83894 +struct xt_gradm_mtinfo {
83895 + __u16 flags;
83896 + __u16 invflags;
83897 +};
83898 +
83899 +#endif
83900 diff --git a/include/linux/nls.h b/include/linux/nls.h
83901 index 520681b..2b7fabb 100644
83902 --- a/include/linux/nls.h
83903 +++ b/include/linux/nls.h
83904 @@ -31,7 +31,7 @@ struct nls_table {
83905 const unsigned char *charset2upper;
83906 struct module *owner;
83907 struct nls_table *next;
83908 -};
83909 +} __do_const;
83910
83911 /* this value hold the maximum octet of charset */
83912 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
83913 @@ -46,7 +46,7 @@ enum utf16_endian {
83914 /* nls_base.c */
83915 extern int __register_nls(struct nls_table *, struct module *);
83916 extern int unregister_nls(struct nls_table *);
83917 -extern struct nls_table *load_nls(char *);
83918 +extern struct nls_table *load_nls(const char *);
83919 extern void unload_nls(struct nls_table *);
83920 extern struct nls_table *load_nls_default(void);
83921 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
83922 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
83923 index d14a4c3..a078786 100644
83924 --- a/include/linux/notifier.h
83925 +++ b/include/linux/notifier.h
83926 @@ -54,7 +54,8 @@ struct notifier_block {
83927 notifier_fn_t notifier_call;
83928 struct notifier_block __rcu *next;
83929 int priority;
83930 -};
83931 +} __do_const;
83932 +typedef struct notifier_block __no_const notifier_block_no_const;
83933
83934 struct atomic_notifier_head {
83935 spinlock_t lock;
83936 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
83937 index b2a0f15..4d7da32 100644
83938 --- a/include/linux/oprofile.h
83939 +++ b/include/linux/oprofile.h
83940 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
83941 int oprofilefs_create_ro_ulong(struct dentry * root,
83942 char const * name, ulong * val);
83943
83944 -/** Create a file for read-only access to an atomic_t. */
83945 +/** Create a file for read-only access to an atomic_unchecked_t. */
83946 int oprofilefs_create_ro_atomic(struct dentry * root,
83947 - char const * name, atomic_t * val);
83948 + char const * name, atomic_unchecked_t * val);
83949
83950 /** create a directory */
83951 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
83952 diff --git a/include/linux/padata.h b/include/linux/padata.h
83953 index 4386946..f50c615 100644
83954 --- a/include/linux/padata.h
83955 +++ b/include/linux/padata.h
83956 @@ -129,7 +129,7 @@ struct parallel_data {
83957 struct padata_serial_queue __percpu *squeue;
83958 atomic_t reorder_objects;
83959 atomic_t refcnt;
83960 - atomic_t seq_nr;
83961 + atomic_unchecked_t seq_nr;
83962 struct padata_cpumask cpumask;
83963 spinlock_t lock ____cacheline_aligned;
83964 unsigned int processed;
83965 diff --git a/include/linux/path.h b/include/linux/path.h
83966 index d137218..be0c176 100644
83967 --- a/include/linux/path.h
83968 +++ b/include/linux/path.h
83969 @@ -1,13 +1,15 @@
83970 #ifndef _LINUX_PATH_H
83971 #define _LINUX_PATH_H
83972
83973 +#include <linux/compiler.h>
83974 +
83975 struct dentry;
83976 struct vfsmount;
83977
83978 struct path {
83979 struct vfsmount *mnt;
83980 struct dentry *dentry;
83981 -};
83982 +} __randomize_layout;
83983
83984 extern void path_get(const struct path *);
83985 extern void path_put(const struct path *);
83986 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
83987 index 5f2e559..7d59314 100644
83988 --- a/include/linux/pci_hotplug.h
83989 +++ b/include/linux/pci_hotplug.h
83990 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
83991 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
83992 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
83993 int (*reset_slot) (struct hotplug_slot *slot, int probe);
83994 -};
83995 +} __do_const;
83996 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
83997
83998 /**
83999 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84000 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84001 index 707617a..28a2e7e 100644
84002 --- a/include/linux/perf_event.h
84003 +++ b/include/linux/perf_event.h
84004 @@ -339,8 +339,8 @@ struct perf_event {
84005
84006 enum perf_event_active_state state;
84007 unsigned int attach_state;
84008 - local64_t count;
84009 - atomic64_t child_count;
84010 + local64_t count; /* PaX: fix it one day */
84011 + atomic64_unchecked_t child_count;
84012
84013 /*
84014 * These are the total time in nanoseconds that the event
84015 @@ -391,8 +391,8 @@ struct perf_event {
84016 * These accumulate total time (in nanoseconds) that children
84017 * events have been enabled and running, respectively.
84018 */
84019 - atomic64_t child_total_time_enabled;
84020 - atomic64_t child_total_time_running;
84021 + atomic64_unchecked_t child_total_time_enabled;
84022 + atomic64_unchecked_t child_total_time_running;
84023
84024 /*
84025 * Protect attach/detach and child_list:
84026 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84027 entry->ip[entry->nr++] = ip;
84028 }
84029
84030 -extern int sysctl_perf_event_paranoid;
84031 +extern int sysctl_perf_event_legitimately_concerned;
84032 extern int sysctl_perf_event_mlock;
84033 extern int sysctl_perf_event_sample_rate;
84034 extern int sysctl_perf_cpu_time_max_percent;
84035 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84036 loff_t *ppos);
84037
84038
84039 +static inline bool perf_paranoid_any(void)
84040 +{
84041 + return sysctl_perf_event_legitimately_concerned > 2;
84042 +}
84043 +
84044 static inline bool perf_paranoid_tracepoint_raw(void)
84045 {
84046 - return sysctl_perf_event_paranoid > -1;
84047 + return sysctl_perf_event_legitimately_concerned > -1;
84048 }
84049
84050 static inline bool perf_paranoid_cpu(void)
84051 {
84052 - return sysctl_perf_event_paranoid > 0;
84053 + return sysctl_perf_event_legitimately_concerned > 0;
84054 }
84055
84056 static inline bool perf_paranoid_kernel(void)
84057 {
84058 - return sysctl_perf_event_paranoid > 1;
84059 + return sysctl_perf_event_legitimately_concerned > 1;
84060 }
84061
84062 extern void perf_event_init(void);
84063 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
84064 struct device_attribute attr;
84065 u64 id;
84066 const char *event_str;
84067 -};
84068 +} __do_const;
84069
84070 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84071 static struct perf_pmu_events_attr _var = { \
84072 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84073 index 1997ffc..4f1f44d 100644
84074 --- a/include/linux/pid_namespace.h
84075 +++ b/include/linux/pid_namespace.h
84076 @@ -44,7 +44,7 @@ struct pid_namespace {
84077 int hide_pid;
84078 int reboot; /* group exit code if this pidns was rebooted */
84079 unsigned int proc_inum;
84080 -};
84081 +} __randomize_layout;
84082
84083 extern struct pid_namespace init_pid_ns;
84084
84085 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84086 index eb8b8ac..62649e1 100644
84087 --- a/include/linux/pipe_fs_i.h
84088 +++ b/include/linux/pipe_fs_i.h
84089 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84090 struct mutex mutex;
84091 wait_queue_head_t wait;
84092 unsigned int nrbufs, curbuf, buffers;
84093 - unsigned int readers;
84094 - unsigned int writers;
84095 - unsigned int files;
84096 - unsigned int waiting_writers;
84097 + atomic_t readers;
84098 + atomic_t writers;
84099 + atomic_t files;
84100 + atomic_t waiting_writers;
84101 unsigned int r_counter;
84102 unsigned int w_counter;
84103 struct page *tmp_page;
84104 diff --git a/include/linux/pm.h b/include/linux/pm.h
84105 index 72c0fe0..26918ed 100644
84106 --- a/include/linux/pm.h
84107 +++ b/include/linux/pm.h
84108 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
84109 struct dev_pm_domain {
84110 struct dev_pm_ops ops;
84111 };
84112 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84113
84114 /*
84115 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84116 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84117 index ebc4c76..7fab7b0 100644
84118 --- a/include/linux/pm_domain.h
84119 +++ b/include/linux/pm_domain.h
84120 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
84121 int (*thaw_early)(struct device *dev);
84122 int (*thaw)(struct device *dev);
84123 bool (*active_wakeup)(struct device *dev);
84124 -};
84125 +} __no_const;
84126
84127 struct gpd_cpu_data {
84128 unsigned int saved_exit_latency;
84129 - struct cpuidle_state *idle_state;
84130 + cpuidle_state_no_const *idle_state;
84131 };
84132
84133 struct generic_pm_domain {
84134 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84135 index 367f49b..d2f5a14 100644
84136 --- a/include/linux/pm_runtime.h
84137 +++ b/include/linux/pm_runtime.h
84138 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84139
84140 static inline void pm_runtime_mark_last_busy(struct device *dev)
84141 {
84142 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84143 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84144 }
84145
84146 #else /* !CONFIG_PM_RUNTIME */
84147 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84148 index 195aafc..49a7bc2 100644
84149 --- a/include/linux/pnp.h
84150 +++ b/include/linux/pnp.h
84151 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84152 struct pnp_fixup {
84153 char id[7];
84154 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84155 -};
84156 +} __do_const;
84157
84158 /* config parameters */
84159 #define PNP_CONFIG_NORMAL 0x0001
84160 diff --git a/include/linux/poison.h b/include/linux/poison.h
84161 index 2110a81..13a11bb 100644
84162 --- a/include/linux/poison.h
84163 +++ b/include/linux/poison.h
84164 @@ -19,8 +19,8 @@
84165 * under normal circumstances, used to verify that nobody uses
84166 * non-initialized list entries.
84167 */
84168 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84169 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84170 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84171 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84172
84173 /********** include/linux/timer.h **********/
84174 /*
84175 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84176 index d8b187c3..9a9257a 100644
84177 --- a/include/linux/power/smartreflex.h
84178 +++ b/include/linux/power/smartreflex.h
84179 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84180 int (*notify)(struct omap_sr *sr, u32 status);
84181 u8 notify_flags;
84182 u8 class_type;
84183 -};
84184 +} __do_const;
84185
84186 /**
84187 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84188 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84189 index 4ea1d37..80f4b33 100644
84190 --- a/include/linux/ppp-comp.h
84191 +++ b/include/linux/ppp-comp.h
84192 @@ -84,7 +84,7 @@ struct compressor {
84193 struct module *owner;
84194 /* Extra skb space needed by the compressor algorithm */
84195 unsigned int comp_extra;
84196 -};
84197 +} __do_const;
84198
84199 /*
84200 * The return value from decompress routine is the length of the
84201 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84202 index de83b4e..c4b997d 100644
84203 --- a/include/linux/preempt.h
84204 +++ b/include/linux/preempt.h
84205 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84206 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84207 #endif
84208
84209 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84210 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84211 +
84212 #define __preempt_count_inc() __preempt_count_add(1)
84213 #define __preempt_count_dec() __preempt_count_sub(1)
84214
84215 #define preempt_count_inc() preempt_count_add(1)
84216 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84217 #define preempt_count_dec() preempt_count_sub(1)
84218 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84219
84220 #ifdef CONFIG_PREEMPT_COUNT
84221
84222 @@ -41,6 +46,12 @@ do { \
84223 barrier(); \
84224 } while (0)
84225
84226 +#define raw_preempt_disable() \
84227 +do { \
84228 + raw_preempt_count_inc(); \
84229 + barrier(); \
84230 +} while (0)
84231 +
84232 #define sched_preempt_enable_no_resched() \
84233 do { \
84234 barrier(); \
84235 @@ -49,6 +60,12 @@ do { \
84236
84237 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84238
84239 +#define raw_preempt_enable_no_resched() \
84240 +do { \
84241 + barrier(); \
84242 + raw_preempt_count_dec(); \
84243 +} while (0)
84244 +
84245 #ifdef CONFIG_PREEMPT
84246 #define preempt_enable() \
84247 do { \
84248 @@ -113,8 +130,10 @@ do { \
84249 * region.
84250 */
84251 #define preempt_disable() barrier()
84252 +#define raw_preempt_disable() barrier()
84253 #define sched_preempt_enable_no_resched() barrier()
84254 #define preempt_enable_no_resched() barrier()
84255 +#define raw_preempt_enable_no_resched() barrier()
84256 #define preempt_enable() barrier()
84257 #define preempt_check_resched() do { } while (0)
84258
84259 @@ -128,11 +147,13 @@ do { \
84260 /*
84261 * Modules have no business playing preemption tricks.
84262 */
84263 +#ifndef CONFIG_PAX_KERNEXEC
84264 #undef sched_preempt_enable_no_resched
84265 #undef preempt_enable_no_resched
84266 #undef preempt_enable_no_resched_notrace
84267 #undef preempt_check_resched
84268 #endif
84269 +#endif
84270
84271 #define preempt_set_need_resched() \
84272 do { \
84273 diff --git a/include/linux/printk.h b/include/linux/printk.h
84274 index d78125f..7f36596 100644
84275 --- a/include/linux/printk.h
84276 +++ b/include/linux/printk.h
84277 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84278 void early_printk(const char *s, ...) { }
84279 #endif
84280
84281 +extern int kptr_restrict;
84282 +
84283 #ifdef CONFIG_PRINTK
84284 asmlinkage __printf(5, 0)
84285 int vprintk_emit(int facility, int level,
84286 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84287
84288 extern int printk_delay_msec;
84289 extern int dmesg_restrict;
84290 -extern int kptr_restrict;
84291
84292 extern void wake_up_klogd(void);
84293
84294 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84295 index 9d117f6..d832b31 100644
84296 --- a/include/linux/proc_fs.h
84297 +++ b/include/linux/proc_fs.h
84298 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84299 extern struct proc_dir_entry *proc_symlink(const char *,
84300 struct proc_dir_entry *, const char *);
84301 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84302 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84303 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84304 struct proc_dir_entry *, void *);
84305 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84306 + struct proc_dir_entry *, void *);
84307 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84308 struct proc_dir_entry *);
84309
84310 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84311 return proc_create_data(name, mode, parent, proc_fops, NULL);
84312 }
84313
84314 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84315 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84316 +{
84317 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84318 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84319 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84320 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84321 +#else
84322 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84323 +#endif
84324 +}
84325 +
84326 +
84327 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84328 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84329 extern void *PDE_DATA(const struct inode *);
84330 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84331 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84332 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84333 struct proc_dir_entry *parent) {return NULL;}
84334 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84335 + struct proc_dir_entry *parent) { return NULL; }
84336 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84337 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84338 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84339 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84340 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84341 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84342 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84343 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
84344 static inline struct proc_dir_entry *proc_net_mkdir(
84345 struct net *net, const char *name, struct proc_dir_entry *parent)
84346 {
84347 - return proc_mkdir_data(name, 0, parent, net);
84348 + return proc_mkdir_data_restrict(name, 0, parent, net);
84349 }
84350
84351 #endif /* _LINUX_PROC_FS_H */
84352 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84353 index 34a1e10..70f6bde 100644
84354 --- a/include/linux/proc_ns.h
84355 +++ b/include/linux/proc_ns.h
84356 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84357 void (*put)(void *ns);
84358 int (*install)(struct nsproxy *nsproxy, void *ns);
84359 unsigned int (*inum)(void *ns);
84360 -};
84361 +} __do_const __randomize_layout;
84362
84363 struct proc_ns {
84364 void *ns;
84365 diff --git a/include/linux/quota.h b/include/linux/quota.h
84366 index 80d345a..9e89a9a 100644
84367 --- a/include/linux/quota.h
84368 +++ b/include/linux/quota.h
84369 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84370
84371 extern bool qid_eq(struct kqid left, struct kqid right);
84372 extern bool qid_lt(struct kqid left, struct kqid right);
84373 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84374 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84375 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84376 extern bool qid_valid(struct kqid qid);
84377
84378 diff --git a/include/linux/random.h b/include/linux/random.h
84379 index 57fbbff..2170304 100644
84380 --- a/include/linux/random.h
84381 +++ b/include/linux/random.h
84382 @@ -9,9 +9,19 @@
84383 #include <uapi/linux/random.h>
84384
84385 extern void add_device_randomness(const void *, unsigned int);
84386 +
84387 +static inline void add_latent_entropy(void)
84388 +{
84389 +
84390 +#ifdef LATENT_ENTROPY_PLUGIN
84391 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84392 +#endif
84393 +
84394 +}
84395 +
84396 extern void add_input_randomness(unsigned int type, unsigned int code,
84397 - unsigned int value);
84398 -extern void add_interrupt_randomness(int irq, int irq_flags);
84399 + unsigned int value) __latent_entropy;
84400 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84401
84402 extern void get_random_bytes(void *buf, int nbytes);
84403 extern void get_random_bytes_arch(void *buf, int nbytes);
84404 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84405 extern const struct file_operations random_fops, urandom_fops;
84406 #endif
84407
84408 -unsigned int get_random_int(void);
84409 +unsigned int __intentional_overflow(-1) get_random_int(void);
84410 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84411
84412 -u32 prandom_u32(void);
84413 +u32 prandom_u32(void) __intentional_overflow(-1);
84414 void prandom_bytes(void *buf, int nbytes);
84415 void prandom_seed(u32 seed);
84416 void prandom_reseed_late(void);
84417 @@ -37,6 +47,11 @@ struct rnd_state {
84418 u32 prandom_u32_state(struct rnd_state *state);
84419 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84420
84421 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84422 +{
84423 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84424 +}
84425 +
84426 /**
84427 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84428 * @ep_ro: right open interval endpoint
84429 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84430 *
84431 * Returns: pseudo-random number in interval [0, ep_ro)
84432 */
84433 -static inline u32 prandom_u32_max(u32 ep_ro)
84434 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84435 {
84436 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84437 }
84438 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84439 index fea49b5..2ac22bb 100644
84440 --- a/include/linux/rbtree_augmented.h
84441 +++ b/include/linux/rbtree_augmented.h
84442 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84443 old->rbaugmented = rbcompute(old); \
84444 } \
84445 rbstatic const struct rb_augment_callbacks rbname = { \
84446 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84447 + .propagate = rbname ## _propagate, \
84448 + .copy = rbname ## _copy, \
84449 + .rotate = rbname ## _rotate \
84450 };
84451
84452
84453 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84454 index 372ad5e..d4373f8 100644
84455 --- a/include/linux/rculist.h
84456 +++ b/include/linux/rculist.h
84457 @@ -29,8 +29,8 @@
84458 */
84459 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84460 {
84461 - ACCESS_ONCE(list->next) = list;
84462 - ACCESS_ONCE(list->prev) = list;
84463 + ACCESS_ONCE_RW(list->next) = list;
84464 + ACCESS_ONCE_RW(list->prev) = list;
84465 }
84466
84467 /*
84468 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84469 struct list_head *prev, struct list_head *next);
84470 #endif
84471
84472 +void __pax_list_add_rcu(struct list_head *new,
84473 + struct list_head *prev, struct list_head *next);
84474 +
84475 /**
84476 * list_add_rcu - add a new entry to rcu-protected list
84477 * @new: new entry to be added
84478 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84479 __list_add_rcu(new, head, head->next);
84480 }
84481
84482 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84483 +{
84484 + __pax_list_add_rcu(new, head, head->next);
84485 +}
84486 +
84487 /**
84488 * list_add_tail_rcu - add a new entry to rcu-protected list
84489 * @new: new entry to be added
84490 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84491 __list_add_rcu(new, head->prev, head);
84492 }
84493
84494 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84495 + struct list_head *head)
84496 +{
84497 + __pax_list_add_rcu(new, head->prev, head);
84498 +}
84499 +
84500 /**
84501 * list_del_rcu - deletes entry from list without re-initialization
84502 * @entry: the element to delete from the list.
84503 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84504 entry->prev = LIST_POISON2;
84505 }
84506
84507 +extern void pax_list_del_rcu(struct list_head *entry);
84508 +
84509 /**
84510 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84511 * @n: the element to delete from the hash list.
84512 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84513 index 48bf152..d38b785 100644
84514 --- a/include/linux/reboot.h
84515 +++ b/include/linux/reboot.h
84516 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
84517 */
84518
84519 extern void migrate_to_reboot_cpu(void);
84520 -extern void machine_restart(char *cmd);
84521 -extern void machine_halt(void);
84522 -extern void machine_power_off(void);
84523 +extern void machine_restart(char *cmd) __noreturn;
84524 +extern void machine_halt(void) __noreturn;
84525 +extern void machine_power_off(void) __noreturn;
84526
84527 extern void machine_shutdown(void);
84528 struct pt_regs;
84529 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84530 */
84531
84532 extern void kernel_restart_prepare(char *cmd);
84533 -extern void kernel_restart(char *cmd);
84534 -extern void kernel_halt(void);
84535 -extern void kernel_power_off(void);
84536 +extern void kernel_restart(char *cmd) __noreturn;
84537 +extern void kernel_halt(void) __noreturn;
84538 +extern void kernel_power_off(void) __noreturn;
84539
84540 extern int C_A_D; /* for sysctl */
84541 void ctrl_alt_del(void);
84542 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
84543 * Emergency restart, callable from an interrupt handler.
84544 */
84545
84546 -extern void emergency_restart(void);
84547 +extern void emergency_restart(void) __noreturn;
84548 #include <asm/emergency-restart.h>
84549
84550 #endif /* _LINUX_REBOOT_H */
84551 diff --git a/include/linux/regset.h b/include/linux/regset.h
84552 index 8e0c9fe..ac4d221 100644
84553 --- a/include/linux/regset.h
84554 +++ b/include/linux/regset.h
84555 @@ -161,7 +161,8 @@ struct user_regset {
84556 unsigned int align;
84557 unsigned int bias;
84558 unsigned int core_note_type;
84559 -};
84560 +} __do_const;
84561 +typedef struct user_regset __no_const user_regset_no_const;
84562
84563 /**
84564 * struct user_regset_view - available regsets
84565 diff --git a/include/linux/relay.h b/include/linux/relay.h
84566 index d7c8359..818daf5 100644
84567 --- a/include/linux/relay.h
84568 +++ b/include/linux/relay.h
84569 @@ -157,7 +157,7 @@ struct rchan_callbacks
84570 * The callback should return 0 if successful, negative if not.
84571 */
84572 int (*remove_buf_file)(struct dentry *dentry);
84573 -};
84574 +} __no_const;
84575
84576 /*
84577 * CONFIG_RELAY kernel API, kernel/relay.c
84578 diff --git a/include/linux/rio.h b/include/linux/rio.h
84579 index 6bda06f..bf39a9b 100644
84580 --- a/include/linux/rio.h
84581 +++ b/include/linux/rio.h
84582 @@ -358,7 +358,7 @@ struct rio_ops {
84583 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84584 u64 rstart, u32 size, u32 flags);
84585 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84586 -};
84587 +} __no_const;
84588
84589 #define RIO_RESOURCE_MEM 0x00000100
84590 #define RIO_RESOURCE_DOORBELL 0x00000200
84591 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84592 index be57450..31cf65e 100644
84593 --- a/include/linux/rmap.h
84594 +++ b/include/linux/rmap.h
84595 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84596 void anon_vma_init(void); /* create anon_vma_cachep */
84597 int anon_vma_prepare(struct vm_area_struct *);
84598 void unlink_anon_vmas(struct vm_area_struct *);
84599 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84600 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84601 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84602 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84603
84604 static inline void anon_vma_merge(struct vm_area_struct *vma,
84605 struct vm_area_struct *next)
84606 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84607 index ed8f9e7..999bc96 100644
84608 --- a/include/linux/scatterlist.h
84609 +++ b/include/linux/scatterlist.h
84610 @@ -1,6 +1,7 @@
84611 #ifndef _LINUX_SCATTERLIST_H
84612 #define _LINUX_SCATTERLIST_H
84613
84614 +#include <linux/sched.h>
84615 #include <linux/string.h>
84616 #include <linux/bug.h>
84617 #include <linux/mm.h>
84618 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84619 #ifdef CONFIG_DEBUG_SG
84620 BUG_ON(!virt_addr_valid(buf));
84621 #endif
84622 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84623 + if (object_starts_on_stack(buf)) {
84624 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84625 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84626 + } else
84627 +#endif
84628 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84629 }
84630
84631 diff --git a/include/linux/sched.h b/include/linux/sched.h
84632 index 2b1d9e9..10ba706 100644
84633 --- a/include/linux/sched.h
84634 +++ b/include/linux/sched.h
84635 @@ -132,6 +132,7 @@ struct fs_struct;
84636 struct perf_event_context;
84637 struct blk_plug;
84638 struct filename;
84639 +struct linux_binprm;
84640
84641 #define VMACACHE_BITS 2
84642 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84643 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
84644 extern int in_sched_functions(unsigned long addr);
84645
84646 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84647 -extern signed long schedule_timeout(signed long timeout);
84648 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84649 extern signed long schedule_timeout_interruptible(signed long timeout);
84650 extern signed long schedule_timeout_killable(signed long timeout);
84651 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84652 @@ -385,6 +386,19 @@ struct nsproxy;
84653 struct user_namespace;
84654
84655 #ifdef CONFIG_MMU
84656 +
84657 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84658 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84659 +#else
84660 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84661 +{
84662 + return 0;
84663 +}
84664 +#endif
84665 +
84666 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84667 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84668 +
84669 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84670 extern unsigned long
84671 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84672 @@ -682,6 +696,17 @@ struct signal_struct {
84673 #ifdef CONFIG_TASKSTATS
84674 struct taskstats *stats;
84675 #endif
84676 +
84677 +#ifdef CONFIG_GRKERNSEC
84678 + u32 curr_ip;
84679 + u32 saved_ip;
84680 + u32 gr_saddr;
84681 + u32 gr_daddr;
84682 + u16 gr_sport;
84683 + u16 gr_dport;
84684 + u8 used_accept:1;
84685 +#endif
84686 +
84687 #ifdef CONFIG_AUDIT
84688 unsigned audit_tty;
84689 unsigned audit_tty_log_passwd;
84690 @@ -708,7 +733,7 @@ struct signal_struct {
84691 struct mutex cred_guard_mutex; /* guard against foreign influences on
84692 * credential calculations
84693 * (notably. ptrace) */
84694 -};
84695 +} __randomize_layout;
84696
84697 /*
84698 * Bits in flags field of signal_struct.
84699 @@ -761,6 +786,14 @@ struct user_struct {
84700 struct key *session_keyring; /* UID's default session keyring */
84701 #endif
84702
84703 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84704 + unsigned char kernel_banned;
84705 +#endif
84706 +#ifdef CONFIG_GRKERNSEC_BRUTE
84707 + unsigned char suid_banned;
84708 + unsigned long suid_ban_expires;
84709 +#endif
84710 +
84711 /* Hash table maintenance information */
84712 struct hlist_node uidhash_node;
84713 kuid_t uid;
84714 @@ -768,7 +801,7 @@ struct user_struct {
84715 #ifdef CONFIG_PERF_EVENTS
84716 atomic_long_t locked_vm;
84717 #endif
84718 -};
84719 +} __randomize_layout;
84720
84721 extern int uids_sysfs_init(void);
84722
84723 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
84724 struct task_struct {
84725 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84726 void *stack;
84727 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84728 + void *lowmem_stack;
84729 +#endif
84730 atomic_t usage;
84731 unsigned int flags; /* per process flags, defined below */
84732 unsigned int ptrace;
84733 @@ -1345,8 +1381,8 @@ struct task_struct {
84734 struct list_head thread_node;
84735
84736 struct completion *vfork_done; /* for vfork() */
84737 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84738 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84739 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84740 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84741
84742 cputime_t utime, stime, utimescaled, stimescaled;
84743 cputime_t gtime;
84744 @@ -1371,11 +1407,6 @@ struct task_struct {
84745 struct task_cputime cputime_expires;
84746 struct list_head cpu_timers[3];
84747
84748 -/* process credentials */
84749 - const struct cred __rcu *real_cred; /* objective and real subjective task
84750 - * credentials (COW) */
84751 - const struct cred __rcu *cred; /* effective (overridable) subjective task
84752 - * credentials (COW) */
84753 char comm[TASK_COMM_LEN]; /* executable name excluding path
84754 - access with [gs]et_task_comm (which lock
84755 it with task_lock())
84756 @@ -1393,6 +1424,10 @@ struct task_struct {
84757 #endif
84758 /* CPU-specific state of this task */
84759 struct thread_struct thread;
84760 +/* thread_info moved to task_struct */
84761 +#ifdef CONFIG_X86
84762 + struct thread_info tinfo;
84763 +#endif
84764 /* filesystem information */
84765 struct fs_struct *fs;
84766 /* open file information */
84767 @@ -1467,6 +1502,10 @@ struct task_struct {
84768 gfp_t lockdep_reclaim_gfp;
84769 #endif
84770
84771 +/* process credentials */
84772 + const struct cred __rcu *real_cred; /* objective and real subjective task
84773 + * credentials (COW) */
84774 +
84775 /* journalling filesystem info */
84776 void *journal_info;
84777
84778 @@ -1505,6 +1544,10 @@ struct task_struct {
84779 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84780 struct list_head cg_list;
84781 #endif
84782 +
84783 + const struct cred __rcu *cred; /* effective (overridable) subjective task
84784 + * credentials (COW) */
84785 +
84786 #ifdef CONFIG_FUTEX
84787 struct robust_list_head __user *robust_list;
84788 #ifdef CONFIG_COMPAT
84789 @@ -1644,7 +1687,78 @@ struct task_struct {
84790 unsigned int sequential_io;
84791 unsigned int sequential_io_avg;
84792 #endif
84793 -};
84794 +
84795 +#ifdef CONFIG_GRKERNSEC
84796 + /* grsecurity */
84797 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84798 + u64 exec_id;
84799 +#endif
84800 +#ifdef CONFIG_GRKERNSEC_SETXID
84801 + const struct cred *delayed_cred;
84802 +#endif
84803 + struct dentry *gr_chroot_dentry;
84804 + struct acl_subject_label *acl;
84805 + struct acl_subject_label *tmpacl;
84806 + struct acl_role_label *role;
84807 + struct file *exec_file;
84808 + unsigned long brute_expires;
84809 + u16 acl_role_id;
84810 + u8 inherited;
84811 + /* is this the task that authenticated to the special role */
84812 + u8 acl_sp_role;
84813 + u8 is_writable;
84814 + u8 brute;
84815 + u8 gr_is_chrooted;
84816 +#endif
84817 +
84818 +} __randomize_layout;
84819 +
84820 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84821 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84822 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84823 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84824 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84825 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84826 +
84827 +#ifdef CONFIG_PAX_SOFTMODE
84828 +extern int pax_softmode;
84829 +#endif
84830 +
84831 +extern int pax_check_flags(unsigned long *);
84832 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84833 +
84834 +/* if tsk != current then task_lock must be held on it */
84835 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84836 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
84837 +{
84838 + if (likely(tsk->mm))
84839 + return tsk->mm->pax_flags;
84840 + else
84841 + return 0UL;
84842 +}
84843 +
84844 +/* if tsk != current then task_lock must be held on it */
84845 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84846 +{
84847 + if (likely(tsk->mm)) {
84848 + tsk->mm->pax_flags = flags;
84849 + return 0;
84850 + }
84851 + return -EINVAL;
84852 +}
84853 +#endif
84854 +
84855 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84856 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
84857 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84858 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84859 +#endif
84860 +
84861 +struct path;
84862 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84863 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84864 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84865 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
84866
84867 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84868 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84869 @@ -1726,7 +1840,7 @@ struct pid_namespace;
84870 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84871 struct pid_namespace *ns);
84872
84873 -static inline pid_t task_pid_nr(struct task_struct *tsk)
84874 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
84875 {
84876 return tsk->pid;
84877 }
84878 @@ -2097,6 +2211,25 @@ extern u64 sched_clock_cpu(int cpu);
84879
84880 extern void sched_clock_init(void);
84881
84882 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84883 +static inline void populate_stack(void)
84884 +{
84885 + struct task_struct *curtask = current;
84886 + int c;
84887 + int *ptr = curtask->stack;
84888 + int *end = curtask->stack + THREAD_SIZE;
84889 +
84890 + while (ptr < end) {
84891 + c = *(volatile int *)ptr;
84892 + ptr += PAGE_SIZE/sizeof(int);
84893 + }
84894 +}
84895 +#else
84896 +static inline void populate_stack(void)
84897 +{
84898 +}
84899 +#endif
84900 +
84901 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
84902 static inline void sched_clock_tick(void)
84903 {
84904 @@ -2230,7 +2363,9 @@ void yield(void);
84905 extern struct exec_domain default_exec_domain;
84906
84907 union thread_union {
84908 +#ifndef CONFIG_X86
84909 struct thread_info thread_info;
84910 +#endif
84911 unsigned long stack[THREAD_SIZE/sizeof(long)];
84912 };
84913
84914 @@ -2263,6 +2398,7 @@ extern struct pid_namespace init_pid_ns;
84915 */
84916
84917 extern struct task_struct *find_task_by_vpid(pid_t nr);
84918 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
84919 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
84920 struct pid_namespace *ns);
84921
84922 @@ -2427,7 +2563,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
84923 extern void exit_itimers(struct signal_struct *);
84924 extern void flush_itimer_signals(void);
84925
84926 -extern void do_group_exit(int);
84927 +extern __noreturn void do_group_exit(int);
84928
84929 extern int do_execve(struct filename *,
84930 const char __user * const __user *,
84931 @@ -2642,9 +2778,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
84932
84933 #endif
84934
84935 -static inline int object_is_on_stack(void *obj)
84936 +static inline int object_starts_on_stack(const void *obj)
84937 {
84938 - void *stack = task_stack_page(current);
84939 + const void *stack = task_stack_page(current);
84940
84941 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
84942 }
84943 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
84944 index 596a0e0..bea77ec 100644
84945 --- a/include/linux/sched/sysctl.h
84946 +++ b/include/linux/sched/sysctl.h
84947 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
84948 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
84949
84950 extern int sysctl_max_map_count;
84951 +extern unsigned long sysctl_heap_stack_gap;
84952
84953 extern unsigned int sysctl_sched_latency;
84954 extern unsigned int sysctl_sched_min_granularity;
84955 diff --git a/include/linux/security.h b/include/linux/security.h
84956 index 623f90e..90b39da 100644
84957 --- a/include/linux/security.h
84958 +++ b/include/linux/security.h
84959 @@ -27,6 +27,7 @@
84960 #include <linux/slab.h>
84961 #include <linux/err.h>
84962 #include <linux/string.h>
84963 +#include <linux/grsecurity.h>
84964
84965 struct linux_binprm;
84966 struct cred;
84967 @@ -116,8 +117,6 @@ struct seq_file;
84968
84969 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
84970
84971 -void reset_security_ops(void);
84972 -
84973 #ifdef CONFIG_MMU
84974 extern unsigned long mmap_min_addr;
84975 extern unsigned long dac_mmap_min_addr;
84976 @@ -1729,7 +1728,7 @@ struct security_operations {
84977 struct audit_context *actx);
84978 void (*audit_rule_free) (void *lsmrule);
84979 #endif /* CONFIG_AUDIT */
84980 -};
84981 +} __randomize_layout;
84982
84983 /* prototypes */
84984 extern int security_init(void);
84985 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
84986 index dc368b8..e895209 100644
84987 --- a/include/linux/semaphore.h
84988 +++ b/include/linux/semaphore.h
84989 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
84990 }
84991
84992 extern void down(struct semaphore *sem);
84993 -extern int __must_check down_interruptible(struct semaphore *sem);
84994 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
84995 extern int __must_check down_killable(struct semaphore *sem);
84996 extern int __must_check down_trylock(struct semaphore *sem);
84997 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
84998 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
84999 index 52e0097..383f21d 100644
85000 --- a/include/linux/seq_file.h
85001 +++ b/include/linux/seq_file.h
85002 @@ -27,6 +27,9 @@ struct seq_file {
85003 struct mutex lock;
85004 const struct seq_operations *op;
85005 int poll_event;
85006 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85007 + u64 exec_id;
85008 +#endif
85009 #ifdef CONFIG_USER_NS
85010 struct user_namespace *user_ns;
85011 #endif
85012 @@ -39,6 +42,7 @@ struct seq_operations {
85013 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85014 int (*show) (struct seq_file *m, void *v);
85015 };
85016 +typedef struct seq_operations __no_const seq_operations_no_const;
85017
85018 #define SEQ_SKIP 1
85019
85020 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85021
85022 char *mangle_path(char *s, const char *p, const char *esc);
85023 int seq_open(struct file *, const struct seq_operations *);
85024 +int seq_open_restrict(struct file *, const struct seq_operations *);
85025 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85026 loff_t seq_lseek(struct file *, loff_t, int);
85027 int seq_release(struct inode *, struct file *);
85028 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85029 }
85030
85031 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85032 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85033 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85034 int single_release(struct inode *, struct file *);
85035 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85036 diff --git a/include/linux/shm.h b/include/linux/shm.h
85037 index 6fb8016..ab4465e 100644
85038 --- a/include/linux/shm.h
85039 +++ b/include/linux/shm.h
85040 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85041 /* The task created the shm object. NULL if the task is dead. */
85042 struct task_struct *shm_creator;
85043 struct list_head shm_clist; /* list by creator */
85044 +#ifdef CONFIG_GRKERNSEC
85045 + u64 shm_createtime;
85046 + pid_t shm_lapid;
85047 +#endif
85048 };
85049
85050 /* shm_mode upper byte flags */
85051 diff --git a/include/linux/signal.h b/include/linux/signal.h
85052 index 750196f..ae7a3a4 100644
85053 --- a/include/linux/signal.h
85054 +++ b/include/linux/signal.h
85055 @@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
85056 * know it'll be handled, so that they don't get converted to
85057 * SIGKILL or just silently dropped.
85058 */
85059 - kernel_sigaction(sig, (__force __sighandler_t)2);
85060 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85061 }
85062
85063 static inline void disallow_signal(int sig)
85064 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85065 index abde271..bc9ece1 100644
85066 --- a/include/linux/skbuff.h
85067 +++ b/include/linux/skbuff.h
85068 @@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85069 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85070 int node);
85071 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85072 -static inline struct sk_buff *alloc_skb(unsigned int size,
85073 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85074 gfp_t priority)
85075 {
85076 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85077 @@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85078 return skb->inner_transport_header - skb->inner_network_header;
85079 }
85080
85081 -static inline int skb_network_offset(const struct sk_buff *skb)
85082 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85083 {
85084 return skb_network_header(skb) - skb->data;
85085 }
85086 @@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
85087 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85088 */
85089 #ifndef NET_SKB_PAD
85090 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85091 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85092 #endif
85093
85094 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85095 @@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85096 int *err);
85097 unsigned int datagram_poll(struct file *file, struct socket *sock,
85098 struct poll_table_struct *wait);
85099 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85100 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85101 struct iovec *to, int size);
85102 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85103 struct iovec *iov);
85104 @@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
85105 nf_bridge_put(skb->nf_bridge);
85106 skb->nf_bridge = NULL;
85107 #endif
85108 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85109 + skb->nf_trace = 0;
85110 +#endif
85111 }
85112
85113 static inline void nf_reset_trace(struct sk_buff *skb)
85114 diff --git a/include/linux/slab.h b/include/linux/slab.h
85115 index 1d9abb7..b1e8b10 100644
85116 --- a/include/linux/slab.h
85117 +++ b/include/linux/slab.h
85118 @@ -14,15 +14,29 @@
85119 #include <linux/gfp.h>
85120 #include <linux/types.h>
85121 #include <linux/workqueue.h>
85122 -
85123 +#include <linux/err.h>
85124
85125 /*
85126 * Flags to pass to kmem_cache_create().
85127 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85128 */
85129 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85130 +
85131 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85132 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85133 +#else
85134 +#define SLAB_USERCOPY 0x00000000UL
85135 +#endif
85136 +
85137 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85138 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85139 +
85140 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85141 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85142 +#else
85143 +#define SLAB_NO_SANITIZE 0x00000000UL
85144 +#endif
85145 +
85146 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85147 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85148 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85149 @@ -98,10 +112,13 @@
85150 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85151 * Both make kfree a no-op.
85152 */
85153 -#define ZERO_SIZE_PTR ((void *)16)
85154 +#define ZERO_SIZE_PTR \
85155 +({ \
85156 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85157 + (void *)(-MAX_ERRNO-1L); \
85158 +})
85159
85160 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85161 - (unsigned long)ZERO_SIZE_PTR)
85162 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85163
85164 #include <linux/kmemleak.h>
85165
85166 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85167 void kfree(const void *);
85168 void kzfree(const void *);
85169 size_t ksize(const void *);
85170 +const char *check_heap_object(const void *ptr, unsigned long n);
85171 +bool is_usercopy_object(const void *ptr);
85172
85173 /*
85174 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85175 @@ -176,7 +195,7 @@ struct kmem_cache {
85176 unsigned int align; /* Alignment as calculated */
85177 unsigned long flags; /* Active flags on the slab */
85178 const char *name; /* Slab name for sysfs */
85179 - int refcount; /* Use counter */
85180 + atomic_t refcount; /* Use counter */
85181 void (*ctor)(void *); /* Called on object slot creation */
85182 struct list_head list; /* List of all slab caches on the system */
85183 };
85184 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85185 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85186 #endif
85187
85188 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85189 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85190 +#endif
85191 +
85192 /*
85193 * Figure out which kmalloc slab an allocation of a certain size
85194 * belongs to.
85195 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85196 * 2 = 120 .. 192 bytes
85197 * n = 2^(n-1) .. 2^n -1
85198 */
85199 -static __always_inline int kmalloc_index(size_t size)
85200 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85201 {
85202 if (!size)
85203 return 0;
85204 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
85205 }
85206 #endif /* !CONFIG_SLOB */
85207
85208 -void *__kmalloc(size_t size, gfp_t flags);
85209 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85210 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85211
85212 #ifdef CONFIG_NUMA
85213 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85214 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85215 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85216 #else
85217 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85218 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85219 index 8235dfb..47ce586 100644
85220 --- a/include/linux/slab_def.h
85221 +++ b/include/linux/slab_def.h
85222 @@ -38,7 +38,7 @@ struct kmem_cache {
85223 /* 4) cache creation/removal */
85224 const char *name;
85225 struct list_head list;
85226 - int refcount;
85227 + atomic_t refcount;
85228 int object_size;
85229 int align;
85230
85231 @@ -54,10 +54,14 @@ struct kmem_cache {
85232 unsigned long node_allocs;
85233 unsigned long node_frees;
85234 unsigned long node_overflow;
85235 - atomic_t allochit;
85236 - atomic_t allocmiss;
85237 - atomic_t freehit;
85238 - atomic_t freemiss;
85239 + atomic_unchecked_t allochit;
85240 + atomic_unchecked_t allocmiss;
85241 + atomic_unchecked_t freehit;
85242 + atomic_unchecked_t freemiss;
85243 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85244 + atomic_unchecked_t sanitized;
85245 + atomic_unchecked_t not_sanitized;
85246 +#endif
85247
85248 /*
85249 * If debugging is enabled, then the allocator can add additional
85250 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85251 index d82abd4..408c3a0 100644
85252 --- a/include/linux/slub_def.h
85253 +++ b/include/linux/slub_def.h
85254 @@ -74,7 +74,7 @@ struct kmem_cache {
85255 struct kmem_cache_order_objects max;
85256 struct kmem_cache_order_objects min;
85257 gfp_t allocflags; /* gfp flags to use on each alloc */
85258 - int refcount; /* Refcount for slab cache destroy */
85259 + atomic_t refcount; /* Refcount for slab cache destroy */
85260 void (*ctor)(void *);
85261 int inuse; /* Offset to metadata */
85262 int align; /* Alignment */
85263 diff --git a/include/linux/smp.h b/include/linux/smp.h
85264 index 34347f2..8739978 100644
85265 --- a/include/linux/smp.h
85266 +++ b/include/linux/smp.h
85267 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
85268 #endif
85269
85270 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85271 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85272 #define put_cpu() preempt_enable()
85273 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85274
85275 /*
85276 * Callback to arch code if there's nosmp or maxcpus=0 on the
85277 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85278 index 46cca4c..3323536 100644
85279 --- a/include/linux/sock_diag.h
85280 +++ b/include/linux/sock_diag.h
85281 @@ -11,7 +11,7 @@ struct sock;
85282 struct sock_diag_handler {
85283 __u8 family;
85284 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85285 -};
85286 +} __do_const;
85287
85288 int sock_diag_register(const struct sock_diag_handler *h);
85289 void sock_diag_unregister(const struct sock_diag_handler *h);
85290 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85291 index 680f9a3..f13aeb0 100644
85292 --- a/include/linux/sonet.h
85293 +++ b/include/linux/sonet.h
85294 @@ -7,7 +7,7 @@
85295 #include <uapi/linux/sonet.h>
85296
85297 struct k_sonet_stats {
85298 -#define __HANDLE_ITEM(i) atomic_t i
85299 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85300 __SONET_ITEMS
85301 #undef __HANDLE_ITEM
85302 };
85303 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85304 index 07d8e53..dc934c9 100644
85305 --- a/include/linux/sunrpc/addr.h
85306 +++ b/include/linux/sunrpc/addr.h
85307 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85308 {
85309 switch (sap->sa_family) {
85310 case AF_INET:
85311 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85312 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85313 case AF_INET6:
85314 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85315 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85316 }
85317 return 0;
85318 }
85319 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85320 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85321 const struct sockaddr *src)
85322 {
85323 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85324 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85325 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85326
85327 dsin->sin_family = ssin->sin_family;
85328 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85329 if (sa->sa_family != AF_INET6)
85330 return 0;
85331
85332 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85333 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85334 }
85335
85336 #endif /* _LINUX_SUNRPC_ADDR_H */
85337 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85338 index 70736b9..37f33db 100644
85339 --- a/include/linux/sunrpc/clnt.h
85340 +++ b/include/linux/sunrpc/clnt.h
85341 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85342 unsigned int p_timer; /* Which RTT timer to use */
85343 u32 p_statidx; /* Which procedure to account */
85344 const char * p_name; /* name of procedure */
85345 -};
85346 +} __do_const;
85347
85348 #ifdef __KERNEL__
85349
85350 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85351 index cf61ecd..a4a9bc0 100644
85352 --- a/include/linux/sunrpc/svc.h
85353 +++ b/include/linux/sunrpc/svc.h
85354 @@ -417,7 +417,7 @@ struct svc_procedure {
85355 unsigned int pc_count; /* call count */
85356 unsigned int pc_cachetype; /* cache info (NFS) */
85357 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85358 -};
85359 +} __do_const;
85360
85361 /*
85362 * Function prototypes.
85363 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85364 index 975da75..318c083 100644
85365 --- a/include/linux/sunrpc/svc_rdma.h
85366 +++ b/include/linux/sunrpc/svc_rdma.h
85367 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85368 extern unsigned int svcrdma_max_requests;
85369 extern unsigned int svcrdma_max_req_size;
85370
85371 -extern atomic_t rdma_stat_recv;
85372 -extern atomic_t rdma_stat_read;
85373 -extern atomic_t rdma_stat_write;
85374 -extern atomic_t rdma_stat_sq_starve;
85375 -extern atomic_t rdma_stat_rq_starve;
85376 -extern atomic_t rdma_stat_rq_poll;
85377 -extern atomic_t rdma_stat_rq_prod;
85378 -extern atomic_t rdma_stat_sq_poll;
85379 -extern atomic_t rdma_stat_sq_prod;
85380 +extern atomic_unchecked_t rdma_stat_recv;
85381 +extern atomic_unchecked_t rdma_stat_read;
85382 +extern atomic_unchecked_t rdma_stat_write;
85383 +extern atomic_unchecked_t rdma_stat_sq_starve;
85384 +extern atomic_unchecked_t rdma_stat_rq_starve;
85385 +extern atomic_unchecked_t rdma_stat_rq_poll;
85386 +extern atomic_unchecked_t rdma_stat_rq_prod;
85387 +extern atomic_unchecked_t rdma_stat_sq_poll;
85388 +extern atomic_unchecked_t rdma_stat_sq_prod;
85389
85390 #define RPCRDMA_VERSION 1
85391
85392 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85393 index 8d71d65..f79586e 100644
85394 --- a/include/linux/sunrpc/svcauth.h
85395 +++ b/include/linux/sunrpc/svcauth.h
85396 @@ -120,7 +120,7 @@ struct auth_ops {
85397 int (*release)(struct svc_rqst *rq);
85398 void (*domain_release)(struct auth_domain *);
85399 int (*set_client)(struct svc_rqst *rq);
85400 -};
85401 +} __do_const;
85402
85403 #define SVC_GARBAGE 1
85404 #define SVC_SYSERR 2
85405 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85406 index e7a018e..49f8b17 100644
85407 --- a/include/linux/swiotlb.h
85408 +++ b/include/linux/swiotlb.h
85409 @@ -60,7 +60,8 @@ extern void
85410
85411 extern void
85412 swiotlb_free_coherent(struct device *hwdev, size_t size,
85413 - void *vaddr, dma_addr_t dma_handle);
85414 + void *vaddr, dma_addr_t dma_handle,
85415 + struct dma_attrs *attrs);
85416
85417 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85418 unsigned long offset, size_t size,
85419 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85420 index 0f86d85..dff3419 100644
85421 --- a/include/linux/syscalls.h
85422 +++ b/include/linux/syscalls.h
85423 @@ -98,10 +98,16 @@ struct sigaltstack;
85424 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85425
85426 #define __SC_DECL(t, a) t a
85427 +#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))
85428 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85429 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85430 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85431 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85432 +#define __SC_LONG(t, a) __typeof( \
85433 + __builtin_choose_expr( \
85434 + sizeof(t) > sizeof(int), \
85435 + (t) 0, \
85436 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85437 + )) a
85438 #define __SC_CAST(t, a) (t) a
85439 #define __SC_ARGS(t, a) a
85440 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85441 @@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
85442 asmlinkage long sys_fsync(unsigned int fd);
85443 asmlinkage long sys_fdatasync(unsigned int fd);
85444 asmlinkage long sys_bdflush(int func, long data);
85445 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85446 - char __user *type, unsigned long flags,
85447 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85448 + const char __user *type, unsigned long flags,
85449 void __user *data);
85450 -asmlinkage long sys_umount(char __user *name, int flags);
85451 -asmlinkage long sys_oldumount(char __user *name);
85452 +asmlinkage long sys_umount(const char __user *name, int flags);
85453 +asmlinkage long sys_oldumount(const char __user *name);
85454 asmlinkage long sys_truncate(const char __user *path, long length);
85455 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85456 asmlinkage long sys_stat(const char __user *filename,
85457 @@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85458 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85459 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85460 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85461 - struct sockaddr __user *, int);
85462 + struct sockaddr __user *, int) __intentional_overflow(0);
85463 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85464 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85465 unsigned int vlen, unsigned flags);
85466 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85467 index 27b3b0b..e093dd9 100644
85468 --- a/include/linux/syscore_ops.h
85469 +++ b/include/linux/syscore_ops.h
85470 @@ -16,7 +16,7 @@ struct syscore_ops {
85471 int (*suspend)(void);
85472 void (*resume)(void);
85473 void (*shutdown)(void);
85474 -};
85475 +} __do_const;
85476
85477 extern void register_syscore_ops(struct syscore_ops *ops);
85478 extern void unregister_syscore_ops(struct syscore_ops *ops);
85479 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85480 index b7361f8..341a15a 100644
85481 --- a/include/linux/sysctl.h
85482 +++ b/include/linux/sysctl.h
85483 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85484
85485 extern int proc_dostring(struct ctl_table *, int,
85486 void __user *, size_t *, loff_t *);
85487 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85488 + void __user *, size_t *, loff_t *);
85489 extern int proc_dointvec(struct ctl_table *, int,
85490 void __user *, size_t *, loff_t *);
85491 extern int proc_dointvec_minmax(struct ctl_table *, int,
85492 @@ -113,7 +115,8 @@ struct ctl_table
85493 struct ctl_table_poll *poll;
85494 void *extra1;
85495 void *extra2;
85496 -};
85497 +} __do_const __randomize_layout;
85498 +typedef struct ctl_table __no_const ctl_table_no_const;
85499
85500 struct ctl_node {
85501 struct rb_node node;
85502 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85503 index f97d0db..c1187dc 100644
85504 --- a/include/linux/sysfs.h
85505 +++ b/include/linux/sysfs.h
85506 @@ -34,7 +34,8 @@ struct attribute {
85507 struct lock_class_key *key;
85508 struct lock_class_key skey;
85509 #endif
85510 -};
85511 +} __do_const;
85512 +typedef struct attribute __no_const attribute_no_const;
85513
85514 /**
85515 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85516 @@ -63,7 +64,8 @@ struct attribute_group {
85517 struct attribute *, int);
85518 struct attribute **attrs;
85519 struct bin_attribute **bin_attrs;
85520 -};
85521 +} __do_const;
85522 +typedef struct attribute_group __no_const attribute_group_no_const;
85523
85524 /**
85525 * Use these macros to make defining attributes easier. See include/linux/device.h
85526 @@ -128,7 +130,8 @@ struct bin_attribute {
85527 char *, loff_t, size_t);
85528 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85529 struct vm_area_struct *vma);
85530 -};
85531 +} __do_const;
85532 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85533
85534 /**
85535 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85536 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85537 index 387fa7d..3fcde6b 100644
85538 --- a/include/linux/sysrq.h
85539 +++ b/include/linux/sysrq.h
85540 @@ -16,6 +16,7 @@
85541
85542 #include <linux/errno.h>
85543 #include <linux/types.h>
85544 +#include <linux/compiler.h>
85545
85546 /* Possible values of bitmask for enabling sysrq functions */
85547 /* 0x0001 is reserved for enable everything */
85548 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85549 char *help_msg;
85550 char *action_msg;
85551 int enable_mask;
85552 -};
85553 +} __do_const;
85554
85555 #ifdef CONFIG_MAGIC_SYSRQ
85556
85557 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85558 index ff307b5..f1a4468 100644
85559 --- a/include/linux/thread_info.h
85560 +++ b/include/linux/thread_info.h
85561 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85562 #error "no set_restore_sigmask() provided and default one won't work"
85563 #endif
85564
85565 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85566 +
85567 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85568 +{
85569 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85570 +}
85571 +
85572 #endif /* __KERNEL__ */
85573
85574 #endif /* _LINUX_THREAD_INFO_H */
85575 diff --git a/include/linux/tty.h b/include/linux/tty.h
85576 index 8413294..44391c7 100644
85577 --- a/include/linux/tty.h
85578 +++ b/include/linux/tty.h
85579 @@ -202,7 +202,7 @@ struct tty_port {
85580 const struct tty_port_operations *ops; /* Port operations */
85581 spinlock_t lock; /* Lock protecting tty field */
85582 int blocked_open; /* Waiting to open */
85583 - int count; /* Usage count */
85584 + atomic_t count; /* Usage count */
85585 wait_queue_head_t open_wait; /* Open waiters */
85586 wait_queue_head_t close_wait; /* Close waiters */
85587 wait_queue_head_t delta_msr_wait; /* Modem status change */
85588 @@ -284,7 +284,7 @@ struct tty_struct {
85589 /* If the tty has a pending do_SAK, queue it here - akpm */
85590 struct work_struct SAK_work;
85591 struct tty_port *port;
85592 -};
85593 +} __randomize_layout;
85594
85595 /* Each of a tty's open files has private_data pointing to tty_file_private */
85596 struct tty_file_private {
85597 @@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
85598 struct tty_struct *tty, struct file *filp);
85599 static inline int tty_port_users(struct tty_port *port)
85600 {
85601 - return port->count + port->blocked_open;
85602 + return atomic_read(&port->count) + port->blocked_open;
85603 }
85604
85605 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85606 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85607 index e48c608..6a19af2 100644
85608 --- a/include/linux/tty_driver.h
85609 +++ b/include/linux/tty_driver.h
85610 @@ -287,7 +287,7 @@ struct tty_operations {
85611 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85612 #endif
85613 const struct file_operations *proc_fops;
85614 -};
85615 +} __do_const __randomize_layout;
85616
85617 struct tty_driver {
85618 int magic; /* magic number for this structure */
85619 @@ -321,7 +321,7 @@ struct tty_driver {
85620
85621 const struct tty_operations *ops;
85622 struct list_head tty_drivers;
85623 -};
85624 +} __randomize_layout;
85625
85626 extern struct list_head tty_drivers;
85627
85628 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85629 index 00c9d68..bc0188b 100644
85630 --- a/include/linux/tty_ldisc.h
85631 +++ b/include/linux/tty_ldisc.h
85632 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85633
85634 struct module *owner;
85635
85636 - int refcount;
85637 + atomic_t refcount;
85638 };
85639
85640 struct tty_ldisc {
85641 diff --git a/include/linux/types.h b/include/linux/types.h
85642 index a0bb704..f511c77 100644
85643 --- a/include/linux/types.h
85644 +++ b/include/linux/types.h
85645 @@ -177,10 +177,26 @@ typedef struct {
85646 int counter;
85647 } atomic_t;
85648
85649 +#ifdef CONFIG_PAX_REFCOUNT
85650 +typedef struct {
85651 + int counter;
85652 +} atomic_unchecked_t;
85653 +#else
85654 +typedef atomic_t atomic_unchecked_t;
85655 +#endif
85656 +
85657 #ifdef CONFIG_64BIT
85658 typedef struct {
85659 long counter;
85660 } atomic64_t;
85661 +
85662 +#ifdef CONFIG_PAX_REFCOUNT
85663 +typedef struct {
85664 + long counter;
85665 +} atomic64_unchecked_t;
85666 +#else
85667 +typedef atomic64_t atomic64_unchecked_t;
85668 +#endif
85669 #endif
85670
85671 struct list_head {
85672 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85673 index ecd3319..8a36ded 100644
85674 --- a/include/linux/uaccess.h
85675 +++ b/include/linux/uaccess.h
85676 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85677 long ret; \
85678 mm_segment_t old_fs = get_fs(); \
85679 \
85680 - set_fs(KERNEL_DS); \
85681 pagefault_disable(); \
85682 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85683 - pagefault_enable(); \
85684 + set_fs(KERNEL_DS); \
85685 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85686 set_fs(old_fs); \
85687 + pagefault_enable(); \
85688 ret; \
85689 })
85690
85691 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85692 index 2d1f9b6..d7a9fce 100644
85693 --- a/include/linux/uidgid.h
85694 +++ b/include/linux/uidgid.h
85695 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85696
85697 #endif /* CONFIG_USER_NS */
85698
85699 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85700 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85701 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85702 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85703 +
85704 #endif /* _LINUX_UIDGID_H */
85705 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85706 index 99c1b4d..562e6f3 100644
85707 --- a/include/linux/unaligned/access_ok.h
85708 +++ b/include/linux/unaligned/access_ok.h
85709 @@ -4,34 +4,34 @@
85710 #include <linux/kernel.h>
85711 #include <asm/byteorder.h>
85712
85713 -static inline u16 get_unaligned_le16(const void *p)
85714 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85715 {
85716 - return le16_to_cpup((__le16 *)p);
85717 + return le16_to_cpup((const __le16 *)p);
85718 }
85719
85720 -static inline u32 get_unaligned_le32(const void *p)
85721 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85722 {
85723 - return le32_to_cpup((__le32 *)p);
85724 + return le32_to_cpup((const __le32 *)p);
85725 }
85726
85727 -static inline u64 get_unaligned_le64(const void *p)
85728 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85729 {
85730 - return le64_to_cpup((__le64 *)p);
85731 + return le64_to_cpup((const __le64 *)p);
85732 }
85733
85734 -static inline u16 get_unaligned_be16(const void *p)
85735 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85736 {
85737 - return be16_to_cpup((__be16 *)p);
85738 + return be16_to_cpup((const __be16 *)p);
85739 }
85740
85741 -static inline u32 get_unaligned_be32(const void *p)
85742 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85743 {
85744 - return be32_to_cpup((__be32 *)p);
85745 + return be32_to_cpup((const __be32 *)p);
85746 }
85747
85748 -static inline u64 get_unaligned_be64(const void *p)
85749 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85750 {
85751 - return be64_to_cpup((__be64 *)p);
85752 + return be64_to_cpup((const __be64 *)p);
85753 }
85754
85755 static inline void put_unaligned_le16(u16 val, void *p)
85756 diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
85757 index 4f844c6..60beb5d 100644
85758 --- a/include/linux/uprobes.h
85759 +++ b/include/linux/uprobes.h
85760 @@ -98,11 +98,11 @@ struct uprobes_state {
85761 struct xol_area *xol_area;
85762 };
85763
85764 -extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85765 -extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85766 -extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
85767 -extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
85768 -extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
85769 +extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85770 +extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85771 +extern bool is_swbp_insn(uprobe_opcode_t *insn);
85772 +extern bool is_trap_insn(uprobe_opcode_t *insn);
85773 +extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
85774 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
85775 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
85776 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
85777 @@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
85778 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
85779 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
85780 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
85781 -extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
85782 -extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
85783 +extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
85784 +extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
85785 void *src, unsigned long len);
85786 #else /* !CONFIG_UPROBES */
85787 struct uprobes_state {
85788 diff --git a/include/linux/usb.h b/include/linux/usb.h
85789 index d2465bc..5256de4 100644
85790 --- a/include/linux/usb.h
85791 +++ b/include/linux/usb.h
85792 @@ -571,7 +571,7 @@ struct usb_device {
85793 int maxchild;
85794
85795 u32 quirks;
85796 - atomic_t urbnum;
85797 + atomic_unchecked_t urbnum;
85798
85799 unsigned long active_duration;
85800
85801 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85802
85803 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85804 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85805 - void *data, __u16 size, int timeout);
85806 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
85807 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85808 void *data, int len, int *actual_length, int timeout);
85809 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85810 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85811 index d5952bb..9a626d4 100644
85812 --- a/include/linux/usb/renesas_usbhs.h
85813 +++ b/include/linux/usb/renesas_usbhs.h
85814 @@ -39,7 +39,7 @@ enum {
85815 */
85816 struct renesas_usbhs_driver_callback {
85817 int (*notify_hotplug)(struct platform_device *pdev);
85818 -};
85819 +} __no_const;
85820
85821 /*
85822 * callback functions for platform
85823 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85824 index e953726..8edb26a 100644
85825 --- a/include/linux/user_namespace.h
85826 +++ b/include/linux/user_namespace.h
85827 @@ -33,7 +33,7 @@ struct user_namespace {
85828 struct key *persistent_keyring_register;
85829 struct rw_semaphore persistent_keyring_register_sem;
85830 #endif
85831 -};
85832 +} __randomize_layout;
85833
85834 extern struct user_namespace init_user_ns;
85835
85836 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85837 index 239e277..22a5cf5 100644
85838 --- a/include/linux/utsname.h
85839 +++ b/include/linux/utsname.h
85840 @@ -24,7 +24,7 @@ struct uts_namespace {
85841 struct new_utsname name;
85842 struct user_namespace *user_ns;
85843 unsigned int proc_inum;
85844 -};
85845 +} __randomize_layout;
85846 extern struct uts_namespace init_uts_ns;
85847
85848 #ifdef CONFIG_UTS_NS
85849 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85850 index 6f8fbcf..4efc177 100644
85851 --- a/include/linux/vermagic.h
85852 +++ b/include/linux/vermagic.h
85853 @@ -25,9 +25,42 @@
85854 #define MODULE_ARCH_VERMAGIC ""
85855 #endif
85856
85857 +#ifdef CONFIG_PAX_REFCOUNT
85858 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
85859 +#else
85860 +#define MODULE_PAX_REFCOUNT ""
85861 +#endif
85862 +
85863 +#ifdef CONSTIFY_PLUGIN
85864 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85865 +#else
85866 +#define MODULE_CONSTIFY_PLUGIN ""
85867 +#endif
85868 +
85869 +#ifdef STACKLEAK_PLUGIN
85870 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85871 +#else
85872 +#define MODULE_STACKLEAK_PLUGIN ""
85873 +#endif
85874 +
85875 +#ifdef RANDSTRUCT_PLUGIN
85876 +#include <generated/randomize_layout_hash.h>
85877 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
85878 +#else
85879 +#define MODULE_RANDSTRUCT_PLUGIN
85880 +#endif
85881 +
85882 +#ifdef CONFIG_GRKERNSEC
85883 +#define MODULE_GRSEC "GRSEC "
85884 +#else
85885 +#define MODULE_GRSEC ""
85886 +#endif
85887 +
85888 #define VERMAGIC_STRING \
85889 UTS_RELEASE " " \
85890 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
85891 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
85892 - MODULE_ARCH_VERMAGIC
85893 + MODULE_ARCH_VERMAGIC \
85894 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
85895 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
85896
85897 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
85898 index b483abd..af305ad 100644
85899 --- a/include/linux/vga_switcheroo.h
85900 +++ b/include/linux/vga_switcheroo.h
85901 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
85902
85903 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
85904
85905 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
85906 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
85907 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
85908 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
85909 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
85910 #else
85911
85912 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
85913 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
85914
85915 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
85916
85917 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85918 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85919 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
85920 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85921 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85922
85923 #endif
85924 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
85925 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
85926 index b87696f..1d11de7 100644
85927 --- a/include/linux/vmalloc.h
85928 +++ b/include/linux/vmalloc.h
85929 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
85930 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
85931 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
85932 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
85933 +
85934 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85935 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
85936 +#endif
85937 +
85938 /* bits [20..32] reserved for arch specific ioremap internals */
85939
85940 /*
85941 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
85942 unsigned long flags, pgprot_t prot);
85943 extern void vunmap(const void *addr);
85944
85945 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85946 +extern void unmap_process_stacks(struct task_struct *task);
85947 +#endif
85948 +
85949 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
85950 unsigned long uaddr, void *kaddr,
85951 unsigned long size);
85952 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
85953
85954 /* for /dev/kmem */
85955 extern long vread(char *buf, char *addr, unsigned long count);
85956 -extern long vwrite(char *buf, char *addr, unsigned long count);
85957 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
85958
85959 /*
85960 * Internals. Dont't use..
85961 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
85962 index 82e7db7..f8ce3d0 100644
85963 --- a/include/linux/vmstat.h
85964 +++ b/include/linux/vmstat.h
85965 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
85966 /*
85967 * Zone based page accounting with per cpu differentials.
85968 */
85969 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85970 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85971
85972 static inline void zone_page_state_add(long x, struct zone *zone,
85973 enum zone_stat_item item)
85974 {
85975 - atomic_long_add(x, &zone->vm_stat[item]);
85976 - atomic_long_add(x, &vm_stat[item]);
85977 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
85978 + atomic_long_add_unchecked(x, &vm_stat[item]);
85979 }
85980
85981 -static inline unsigned long global_page_state(enum zone_stat_item item)
85982 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
85983 {
85984 - long x = atomic_long_read(&vm_stat[item]);
85985 + long x = atomic_long_read_unchecked(&vm_stat[item]);
85986 #ifdef CONFIG_SMP
85987 if (x < 0)
85988 x = 0;
85989 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
85990 return x;
85991 }
85992
85993 -static inline unsigned long zone_page_state(struct zone *zone,
85994 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
85995 enum zone_stat_item item)
85996 {
85997 - long x = atomic_long_read(&zone->vm_stat[item]);
85998 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85999 #ifdef CONFIG_SMP
86000 if (x < 0)
86001 x = 0;
86002 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86003 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86004 enum zone_stat_item item)
86005 {
86006 - long x = atomic_long_read(&zone->vm_stat[item]);
86007 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86008
86009 #ifdef CONFIG_SMP
86010 int cpu;
86011 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86012
86013 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86014 {
86015 - atomic_long_inc(&zone->vm_stat[item]);
86016 - atomic_long_inc(&vm_stat[item]);
86017 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86018 + atomic_long_inc_unchecked(&vm_stat[item]);
86019 }
86020
86021 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86022 {
86023 - atomic_long_dec(&zone->vm_stat[item]);
86024 - atomic_long_dec(&vm_stat[item]);
86025 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86026 + atomic_long_dec_unchecked(&vm_stat[item]);
86027 }
86028
86029 static inline void __inc_zone_page_state(struct page *page,
86030 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86031 index 91b0a68..0e9adf6 100644
86032 --- a/include/linux/xattr.h
86033 +++ b/include/linux/xattr.h
86034 @@ -28,7 +28,7 @@ struct xattr_handler {
86035 size_t size, int handler_flags);
86036 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86037 size_t size, int flags, int handler_flags);
86038 -};
86039 +} __do_const;
86040
86041 struct xattr {
86042 const char *name;
86043 @@ -37,6 +37,9 @@ struct xattr {
86044 };
86045
86046 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86047 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86048 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86049 +#endif
86050 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86051 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86052 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86053 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86054 index 92dbbd3..13ab0b3 100644
86055 --- a/include/linux/zlib.h
86056 +++ b/include/linux/zlib.h
86057 @@ -31,6 +31,7 @@
86058 #define _ZLIB_H
86059
86060 #include <linux/zconf.h>
86061 +#include <linux/compiler.h>
86062
86063 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86064 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86065 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86066
86067 /* basic functions */
86068
86069 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86070 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86071 /*
86072 Returns the number of bytes that needs to be allocated for a per-
86073 stream workspace with the specified parameters. A pointer to this
86074 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86075 index eb76cfd..9fd0e7c 100644
86076 --- a/include/media/v4l2-dev.h
86077 +++ b/include/media/v4l2-dev.h
86078 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86079 int (*mmap) (struct file *, struct vm_area_struct *);
86080 int (*open) (struct file *);
86081 int (*release) (struct file *);
86082 -};
86083 +} __do_const;
86084
86085 /*
86086 * Newer version of video_device, handled by videodev2.c
86087 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86088 index ffb69da..040393e 100644
86089 --- a/include/media/v4l2-device.h
86090 +++ b/include/media/v4l2-device.h
86091 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86092 this function returns 0. If the name ends with a digit (e.g. cx18),
86093 then the name will be set to cx18-0 since cx180 looks really odd. */
86094 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86095 - atomic_t *instance);
86096 + atomic_unchecked_t *instance);
86097
86098 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86099 Since the parent disappears this ensures that v4l2_dev doesn't have an
86100 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86101 index d9fa68f..45c88d1 100644
86102 --- a/include/net/9p/transport.h
86103 +++ b/include/net/9p/transport.h
86104 @@ -63,7 +63,7 @@ struct p9_trans_module {
86105 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86106 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86107 char *, char *, int , int, int, int);
86108 -};
86109 +} __do_const;
86110
86111 void v9fs_register_trans(struct p9_trans_module *m);
86112 void v9fs_unregister_trans(struct p9_trans_module *m);
86113 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86114 index a175ba4..196eb82 100644
86115 --- a/include/net/af_unix.h
86116 +++ b/include/net/af_unix.h
86117 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86118 u32 secid; /* Security ID */
86119 #endif
86120 u32 consumed;
86121 -};
86122 +} __randomize_layout;
86123
86124 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86125 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86126 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86127 index 8df15ad..837fbedd 100644
86128 --- a/include/net/bluetooth/l2cap.h
86129 +++ b/include/net/bluetooth/l2cap.h
86130 @@ -608,7 +608,7 @@ struct l2cap_ops {
86131 unsigned char *kdata,
86132 struct iovec *iov,
86133 int len);
86134 -};
86135 +} __do_const;
86136
86137 struct l2cap_conn {
86138 struct hci_conn *hcon;
86139 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86140 index f2ae33d..c457cf0 100644
86141 --- a/include/net/caif/cfctrl.h
86142 +++ b/include/net/caif/cfctrl.h
86143 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86144 void (*radioset_rsp)(void);
86145 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86146 struct cflayer *client_layer);
86147 -};
86148 +} __no_const;
86149
86150 /* Link Setup Parameters for CAIF-Links. */
86151 struct cfctrl_link_param {
86152 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86153 struct cfctrl {
86154 struct cfsrvl serv;
86155 struct cfctrl_rsp res;
86156 - atomic_t req_seq_no;
86157 - atomic_t rsp_seq_no;
86158 + atomic_unchecked_t req_seq_no;
86159 + atomic_unchecked_t rsp_seq_no;
86160 struct list_head list;
86161 /* Protects from simultaneous access to first_req list */
86162 spinlock_t info_list_lock;
86163 diff --git a/include/net/flow.h b/include/net/flow.h
86164 index 8109a15..504466d 100644
86165 --- a/include/net/flow.h
86166 +++ b/include/net/flow.h
86167 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86168
86169 void flow_cache_flush(struct net *net);
86170 void flow_cache_flush_deferred(struct net *net);
86171 -extern atomic_t flow_cache_genid;
86172 +extern atomic_unchecked_t flow_cache_genid;
86173
86174 #endif
86175 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86176 index af10c2c..a431cc5 100644
86177 --- a/include/net/genetlink.h
86178 +++ b/include/net/genetlink.h
86179 @@ -120,7 +120,7 @@ struct genl_ops {
86180 u8 cmd;
86181 u8 internal_flags;
86182 u8 flags;
86183 -};
86184 +} __do_const;
86185
86186 int __genl_register_family(struct genl_family *family);
86187
86188 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86189 index 734d9b5..48a9a4b 100644
86190 --- a/include/net/gro_cells.h
86191 +++ b/include/net/gro_cells.h
86192 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86193 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86194
86195 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86196 - atomic_long_inc(&dev->rx_dropped);
86197 + atomic_long_inc_unchecked(&dev->rx_dropped);
86198 kfree_skb(skb);
86199 return;
86200 }
86201 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86202 index 5fbe656..9ed3d8b 100644
86203 --- a/include/net/inet_connection_sock.h
86204 +++ b/include/net/inet_connection_sock.h
86205 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86206 int (*bind_conflict)(const struct sock *sk,
86207 const struct inet_bind_bucket *tb, bool relax);
86208 void (*mtu_reduced)(struct sock *sk);
86209 -};
86210 +} __do_const;
86211
86212 /** inet_connection_sock - INET connection oriented sock
86213 *
86214 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86215 index 01d590e..f69c61d 100644
86216 --- a/include/net/inetpeer.h
86217 +++ b/include/net/inetpeer.h
86218 @@ -47,7 +47,7 @@ struct inet_peer {
86219 */
86220 union {
86221 struct {
86222 - atomic_t rid; /* Frag reception counter */
86223 + atomic_unchecked_t rid; /* Frag reception counter */
86224 };
86225 struct rcu_head rcu;
86226 struct inet_peer *gc_next;
86227 diff --git a/include/net/ip.h b/include/net/ip.h
86228 index db4a771..965a42a 100644
86229 --- a/include/net/ip.h
86230 +++ b/include/net/ip.h
86231 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86232 }
86233 }
86234
86235 -u32 ip_idents_reserve(u32 hash, int segs);
86236 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86237 void __ip_select_ident(struct iphdr *iph, int segs);
86238
86239 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86240 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86241 index 9922093..a1755d6 100644
86242 --- a/include/net/ip_fib.h
86243 +++ b/include/net/ip_fib.h
86244 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86245
86246 #define FIB_RES_SADDR(net, res) \
86247 ((FIB_RES_NH(res).nh_saddr_genid == \
86248 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86249 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86250 FIB_RES_NH(res).nh_saddr : \
86251 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86252 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86253 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86254 index 624a8a5..b1e2a24 100644
86255 --- a/include/net/ip_vs.h
86256 +++ b/include/net/ip_vs.h
86257 @@ -558,7 +558,7 @@ struct ip_vs_conn {
86258 struct ip_vs_conn *control; /* Master control connection */
86259 atomic_t n_control; /* Number of controlled ones */
86260 struct ip_vs_dest *dest; /* real server */
86261 - atomic_t in_pkts; /* incoming packet counter */
86262 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86263
86264 /* packet transmitter for different forwarding methods. If it
86265 mangles the packet, it must return NF_DROP or better NF_STOLEN,
86266 @@ -705,7 +705,7 @@ struct ip_vs_dest {
86267 __be16 port; /* port number of the server */
86268 union nf_inet_addr addr; /* IP address of the server */
86269 volatile unsigned int flags; /* dest status flags */
86270 - atomic_t conn_flags; /* flags to copy to conn */
86271 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86272 atomic_t weight; /* server weight */
86273
86274 atomic_t refcnt; /* reference counter */
86275 @@ -960,11 +960,11 @@ struct netns_ipvs {
86276 /* ip_vs_lblc */
86277 int sysctl_lblc_expiration;
86278 struct ctl_table_header *lblc_ctl_header;
86279 - struct ctl_table *lblc_ctl_table;
86280 + ctl_table_no_const *lblc_ctl_table;
86281 /* ip_vs_lblcr */
86282 int sysctl_lblcr_expiration;
86283 struct ctl_table_header *lblcr_ctl_header;
86284 - struct ctl_table *lblcr_ctl_table;
86285 + ctl_table_no_const *lblcr_ctl_table;
86286 /* ip_vs_est */
86287 struct list_head est_list; /* estimator list */
86288 spinlock_t est_lock;
86289 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86290 index 8d4f588..2e37ad2 100644
86291 --- a/include/net/irda/ircomm_tty.h
86292 +++ b/include/net/irda/ircomm_tty.h
86293 @@ -33,6 +33,7 @@
86294 #include <linux/termios.h>
86295 #include <linux/timer.h>
86296 #include <linux/tty.h> /* struct tty_struct */
86297 +#include <asm/local.h>
86298
86299 #include <net/irda/irias_object.h>
86300 #include <net/irda/ircomm_core.h>
86301 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86302 index 714cc9a..ea05f3e 100644
86303 --- a/include/net/iucv/af_iucv.h
86304 +++ b/include/net/iucv/af_iucv.h
86305 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86306 struct iucv_sock_list {
86307 struct hlist_head head;
86308 rwlock_t lock;
86309 - atomic_t autobind_name;
86310 + atomic_unchecked_t autobind_name;
86311 };
86312
86313 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86314 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86315 index f3be818..bf46196 100644
86316 --- a/include/net/llc_c_ac.h
86317 +++ b/include/net/llc_c_ac.h
86318 @@ -87,7 +87,7 @@
86319 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86320 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86321
86322 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86323 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86324
86325 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86326 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86327 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86328 index 3948cf1..83b28c4 100644
86329 --- a/include/net/llc_c_ev.h
86330 +++ b/include/net/llc_c_ev.h
86331 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86332 return (struct llc_conn_state_ev *)skb->cb;
86333 }
86334
86335 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86336 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86337 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86338 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86339
86340 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86341 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86342 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86343 index 0e79cfb..f46db31 100644
86344 --- a/include/net/llc_c_st.h
86345 +++ b/include/net/llc_c_st.h
86346 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86347 u8 next_state;
86348 llc_conn_ev_qfyr_t *ev_qualifiers;
86349 llc_conn_action_t *ev_actions;
86350 -};
86351 +} __do_const;
86352
86353 struct llc_conn_state {
86354 u8 current_state;
86355 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86356 index a61b98c..aade1eb 100644
86357 --- a/include/net/llc_s_ac.h
86358 +++ b/include/net/llc_s_ac.h
86359 @@ -23,7 +23,7 @@
86360 #define SAP_ACT_TEST_IND 9
86361
86362 /* All action functions must look like this */
86363 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86364 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86365
86366 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86367 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86368 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86369 index 567c681..cd73ac02 100644
86370 --- a/include/net/llc_s_st.h
86371 +++ b/include/net/llc_s_st.h
86372 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86373 llc_sap_ev_t ev;
86374 u8 next_state;
86375 llc_sap_action_t *ev_actions;
86376 -};
86377 +} __do_const;
86378
86379 struct llc_sap_state {
86380 u8 curr_state;
86381 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86382 index dae2e24..89336e6 100644
86383 --- a/include/net/mac80211.h
86384 +++ b/include/net/mac80211.h
86385 @@ -4650,7 +4650,7 @@ struct rate_control_ops {
86386 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86387
86388 u32 (*get_expected_throughput)(void *priv_sta);
86389 -};
86390 +} __do_const;
86391
86392 static inline int rate_supported(struct ieee80211_sta *sta,
86393 enum ieee80211_band band,
86394 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86395 index 47f4254..fd095bc 100644
86396 --- a/include/net/neighbour.h
86397 +++ b/include/net/neighbour.h
86398 @@ -163,7 +163,7 @@ struct neigh_ops {
86399 void (*error_report)(struct neighbour *, struct sk_buff *);
86400 int (*output)(struct neighbour *, struct sk_buff *);
86401 int (*connected_output)(struct neighbour *, struct sk_buff *);
86402 -};
86403 +} __do_const;
86404
86405 struct pneigh_entry {
86406 struct pneigh_entry *next;
86407 @@ -217,7 +217,7 @@ struct neigh_table {
86408 struct neigh_statistics __percpu *stats;
86409 struct neigh_hash_table __rcu *nht;
86410 struct pneigh_entry **phash_buckets;
86411 -};
86412 +} __randomize_layout;
86413
86414 static inline int neigh_parms_family(struct neigh_parms *p)
86415 {
86416 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86417 index e0d6466..e2f3003 100644
86418 --- a/include/net/net_namespace.h
86419 +++ b/include/net/net_namespace.h
86420 @@ -129,8 +129,8 @@ struct net {
86421 struct netns_ipvs *ipvs;
86422 #endif
86423 struct sock *diag_nlsk;
86424 - atomic_t fnhe_genid;
86425 -};
86426 + atomic_unchecked_t fnhe_genid;
86427 +} __randomize_layout;
86428
86429 #include <linux/seq_file_net.h>
86430
86431 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86432 #define __net_init __init
86433 #define __net_exit __exit_refok
86434 #define __net_initdata __initdata
86435 +#ifdef CONSTIFY_PLUGIN
86436 #define __net_initconst __initconst
86437 +#else
86438 +#define __net_initconst __initdata
86439 +#endif
86440 #endif
86441
86442 struct pernet_operations {
86443 @@ -296,7 +300,7 @@ struct pernet_operations {
86444 void (*exit_batch)(struct list_head *net_exit_list);
86445 int *id;
86446 size_t size;
86447 -};
86448 +} __do_const;
86449
86450 /*
86451 * Use these carefully. If you implement a network device and it
86452 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86453
86454 static inline int rt_genid_ipv4(struct net *net)
86455 {
86456 - return atomic_read(&net->ipv4.rt_genid);
86457 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86458 }
86459
86460 static inline void rt_genid_bump_ipv4(struct net *net)
86461 {
86462 - atomic_inc(&net->ipv4.rt_genid);
86463 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86464 }
86465
86466 extern void (*__fib6_flush_trees)(struct net *net);
86467 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86468
86469 static inline int fnhe_genid(struct net *net)
86470 {
86471 - return atomic_read(&net->fnhe_genid);
86472 + return atomic_read_unchecked(&net->fnhe_genid);
86473 }
86474
86475 static inline void fnhe_genid_bump(struct net *net)
86476 {
86477 - atomic_inc(&net->fnhe_genid);
86478 + atomic_inc_unchecked(&net->fnhe_genid);
86479 }
86480
86481 #endif /* __NET_NET_NAMESPACE_H */
86482 diff --git a/include/net/netdma.h b/include/net/netdma.h
86483 index 8ba8ce2..99b7fff 100644
86484 --- a/include/net/netdma.h
86485 +++ b/include/net/netdma.h
86486 @@ -24,7 +24,7 @@
86487 #include <linux/dmaengine.h>
86488 #include <linux/skbuff.h>
86489
86490 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86491 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86492 struct sk_buff *skb, int offset, struct iovec *to,
86493 size_t len, struct dma_pinned_list *pinned_list);
86494
86495 diff --git a/include/net/netlink.h b/include/net/netlink.h
86496 index 6c10762..3e5de0c 100644
86497 --- a/include/net/netlink.h
86498 +++ b/include/net/netlink.h
86499 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86500 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86501 {
86502 if (mark)
86503 - skb_trim(skb, (unsigned char *) mark - skb->data);
86504 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86505 }
86506
86507 /**
86508 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86509 index 29d6a94..235d3d8 100644
86510 --- a/include/net/netns/conntrack.h
86511 +++ b/include/net/netns/conntrack.h
86512 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86513 struct nf_proto_net {
86514 #ifdef CONFIG_SYSCTL
86515 struct ctl_table_header *ctl_table_header;
86516 - struct ctl_table *ctl_table;
86517 + ctl_table_no_const *ctl_table;
86518 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86519 struct ctl_table_header *ctl_compat_header;
86520 - struct ctl_table *ctl_compat_table;
86521 + ctl_table_no_const *ctl_compat_table;
86522 #endif
86523 #endif
86524 unsigned int users;
86525 @@ -60,7 +60,7 @@ struct nf_ip_net {
86526 struct nf_icmp_net icmpv6;
86527 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86528 struct ctl_table_header *ctl_table_header;
86529 - struct ctl_table *ctl_table;
86530 + ctl_table_no_const *ctl_table;
86531 #endif
86532 };
86533
86534 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86535 index aec5e12..807233f 100644
86536 --- a/include/net/netns/ipv4.h
86537 +++ b/include/net/netns/ipv4.h
86538 @@ -82,7 +82,7 @@ struct netns_ipv4 {
86539
86540 struct ping_group_range ping_group_range;
86541
86542 - atomic_t dev_addr_genid;
86543 + atomic_unchecked_t dev_addr_genid;
86544
86545 #ifdef CONFIG_SYSCTL
86546 unsigned long *sysctl_local_reserved_ports;
86547 @@ -96,6 +96,6 @@ struct netns_ipv4 {
86548 struct fib_rules_ops *mr_rules_ops;
86549 #endif
86550 #endif
86551 - atomic_t rt_genid;
86552 + atomic_unchecked_t rt_genid;
86553 };
86554 #endif
86555 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86556 index eade27a..42894dd 100644
86557 --- a/include/net/netns/ipv6.h
86558 +++ b/include/net/netns/ipv6.h
86559 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86560 struct fib_rules_ops *mr6_rules_ops;
86561 #endif
86562 #endif
86563 - atomic_t dev_addr_genid;
86564 - atomic_t rt_genid;
86565 + atomic_unchecked_t dev_addr_genid;
86566 + atomic_unchecked_t rt_genid;
86567 };
86568
86569 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86570 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86571 index 3492434..209f58c 100644
86572 --- a/include/net/netns/xfrm.h
86573 +++ b/include/net/netns/xfrm.h
86574 @@ -64,7 +64,7 @@ struct netns_xfrm {
86575
86576 /* flow cache part */
86577 struct flow_cache flow_cache_global;
86578 - atomic_t flow_cache_genid;
86579 + atomic_unchecked_t flow_cache_genid;
86580 struct list_head flow_cache_gc_list;
86581 spinlock_t flow_cache_gc_lock;
86582 struct work_struct flow_cache_gc_work;
86583 diff --git a/include/net/ping.h b/include/net/ping.h
86584 index 026479b..d9b2829 100644
86585 --- a/include/net/ping.h
86586 +++ b/include/net/ping.h
86587 @@ -54,7 +54,7 @@ struct ping_iter_state {
86588
86589 extern struct proto ping_prot;
86590 #if IS_ENABLED(CONFIG_IPV6)
86591 -extern struct pingv6_ops pingv6_ops;
86592 +extern struct pingv6_ops *pingv6_ops;
86593 #endif
86594
86595 struct pingfakehdr {
86596 diff --git a/include/net/protocol.h b/include/net/protocol.h
86597 index d6fcc1f..ca277058 100644
86598 --- a/include/net/protocol.h
86599 +++ b/include/net/protocol.h
86600 @@ -49,7 +49,7 @@ struct net_protocol {
86601 * socket lookup?
86602 */
86603 icmp_strict_tag_validation:1;
86604 -};
86605 +} __do_const;
86606
86607 #if IS_ENABLED(CONFIG_IPV6)
86608 struct inet6_protocol {
86609 @@ -62,7 +62,7 @@ struct inet6_protocol {
86610 u8 type, u8 code, int offset,
86611 __be32 info);
86612 unsigned int flags; /* INET6_PROTO_xxx */
86613 -};
86614 +} __do_const;
86615
86616 #define INET6_PROTO_NOPOLICY 0x1
86617 #define INET6_PROTO_FINAL 0x2
86618 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86619 index e21b9f9..0191ef0 100644
86620 --- a/include/net/rtnetlink.h
86621 +++ b/include/net/rtnetlink.h
86622 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86623 int (*fill_slave_info)(struct sk_buff *skb,
86624 const struct net_device *dev,
86625 const struct net_device *slave_dev);
86626 -};
86627 +} __do_const;
86628
86629 int __rtnl_link_register(struct rtnl_link_ops *ops);
86630 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86631 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86632 index 4a5b9a3..ca27d73 100644
86633 --- a/include/net/sctp/checksum.h
86634 +++ b/include/net/sctp/checksum.h
86635 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86636 unsigned int offset)
86637 {
86638 struct sctphdr *sh = sctp_hdr(skb);
86639 - __le32 ret, old = sh->checksum;
86640 - const struct skb_checksum_ops ops = {
86641 + __le32 ret, old = sh->checksum;
86642 + static const struct skb_checksum_ops ops = {
86643 .update = sctp_csum_update,
86644 .combine = sctp_csum_combine,
86645 };
86646 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86647 index 72a31db..aaa63d9 100644
86648 --- a/include/net/sctp/sm.h
86649 +++ b/include/net/sctp/sm.h
86650 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86651 typedef struct {
86652 sctp_state_fn_t *fn;
86653 const char *name;
86654 -} sctp_sm_table_entry_t;
86655 +} __do_const sctp_sm_table_entry_t;
86656
86657 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86658 * currently in use.
86659 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86660 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86661
86662 /* Extern declarations for major data structures. */
86663 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86664 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86665
86666
86667 /* Get the size of a DATA chunk payload. */
86668 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86669 index 4ff3f67..89ae38e 100644
86670 --- a/include/net/sctp/structs.h
86671 +++ b/include/net/sctp/structs.h
86672 @@ -509,7 +509,7 @@ struct sctp_pf {
86673 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86674 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86675 struct sctp_af *af;
86676 -};
86677 +} __do_const;
86678
86679
86680 /* Structure to track chunk fragments that have been acked, but peer
86681 diff --git a/include/net/sock.h b/include/net/sock.h
86682 index b9a5bd0..dcd5f3c 100644
86683 --- a/include/net/sock.h
86684 +++ b/include/net/sock.h
86685 @@ -356,7 +356,7 @@ struct sock {
86686 unsigned int sk_napi_id;
86687 unsigned int sk_ll_usec;
86688 #endif
86689 - atomic_t sk_drops;
86690 + atomic_unchecked_t sk_drops;
86691 int sk_rcvbuf;
86692
86693 struct sk_filter __rcu *sk_filter;
86694 @@ -1053,7 +1053,7 @@ struct proto {
86695 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86696 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86697 #endif
86698 -};
86699 +} __randomize_layout;
86700
86701 /*
86702 * Bits in struct cg_proto.flags
86703 @@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86704 return ret >> PAGE_SHIFT;
86705 }
86706
86707 -static inline long
86708 +static inline long __intentional_overflow(-1)
86709 sk_memory_allocated(const struct sock *sk)
86710 {
86711 struct proto *prot = sk->sk_prot;
86712 @@ -1385,7 +1385,7 @@ struct sock_iocb {
86713 struct scm_cookie *scm;
86714 struct msghdr *msg, async_msg;
86715 struct kiocb *kiocb;
86716 -};
86717 +} __randomize_layout;
86718
86719 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86720 {
86721 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86722 }
86723
86724 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86725 - char __user *from, char *to,
86726 + char __user *from, unsigned char *to,
86727 int copy, int offset)
86728 {
86729 if (skb->ip_summed == CHECKSUM_NONE) {
86730 @@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86731 }
86732 }
86733
86734 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86735 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86736
86737 /**
86738 * sk_page_frag - return an appropriate page_frag
86739 diff --git a/include/net/tcp.h b/include/net/tcp.h
86740 index 590e01a..76498f3 100644
86741 --- a/include/net/tcp.h
86742 +++ b/include/net/tcp.h
86743 @@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
86744 void tcp_xmit_retransmit_queue(struct sock *);
86745 void tcp_simple_retransmit(struct sock *);
86746 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86747 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86748 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86749
86750 void tcp_send_probe0(struct sock *);
86751 void tcp_send_partial(struct sock *);
86752 @@ -696,8 +696,8 @@ struct tcp_skb_cb {
86753 struct inet6_skb_parm h6;
86754 #endif
86755 } header; /* For incoming frames */
86756 - __u32 seq; /* Starting sequence number */
86757 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86758 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
86759 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86760 __u32 when; /* used to compute rtt's */
86761 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
86762
86763 @@ -713,7 +713,7 @@ struct tcp_skb_cb {
86764
86765 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86766 /* 1 byte hole */
86767 - __u32 ack_seq; /* Sequence number ACK'd */
86768 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86769 };
86770
86771 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
86772 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86773 index 721e9c3b..3c81bbf 100644
86774 --- a/include/net/xfrm.h
86775 +++ b/include/net/xfrm.h
86776 @@ -285,7 +285,6 @@ struct xfrm_dst;
86777 struct xfrm_policy_afinfo {
86778 unsigned short family;
86779 struct dst_ops *dst_ops;
86780 - void (*garbage_collect)(struct net *net);
86781 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86782 const xfrm_address_t *saddr,
86783 const xfrm_address_t *daddr);
86784 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86785 struct net_device *dev,
86786 const struct flowi *fl);
86787 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86788 -};
86789 +} __do_const;
86790
86791 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86792 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86793 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86794 int (*transport_finish)(struct sk_buff *skb,
86795 int async);
86796 void (*local_error)(struct sk_buff *skb, u32 mtu);
86797 -};
86798 +} __do_const;
86799
86800 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86801 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86802 @@ -437,7 +436,7 @@ struct xfrm_mode {
86803 struct module *owner;
86804 unsigned int encap;
86805 int flags;
86806 -};
86807 +} __do_const;
86808
86809 /* Flags for xfrm_mode. */
86810 enum {
86811 @@ -534,7 +533,7 @@ struct xfrm_policy {
86812 struct timer_list timer;
86813
86814 struct flow_cache_object flo;
86815 - atomic_t genid;
86816 + atomic_unchecked_t genid;
86817 u32 priority;
86818 u32 index;
86819 struct xfrm_mark mark;
86820 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86821 }
86822
86823 void xfrm_garbage_collect(struct net *net);
86824 +void xfrm_garbage_collect_deferred(struct net *net);
86825
86826 #else
86827
86828 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86829 static inline void xfrm_garbage_collect(struct net *net)
86830 {
86831 }
86832 +static inline void xfrm_garbage_collect_deferred(struct net *net)
86833 +{
86834 +}
86835 #endif
86836
86837 static __inline__
86838 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86839 index 1017e0b..227aa4d 100644
86840 --- a/include/rdma/iw_cm.h
86841 +++ b/include/rdma/iw_cm.h
86842 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
86843 int backlog);
86844
86845 int (*destroy_listen)(struct iw_cm_id *cm_id);
86846 -};
86847 +} __no_const;
86848
86849 /**
86850 * iw_create_cm_id - Create an IW CM identifier.
86851 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86852 index 52beadf..598734c 100644
86853 --- a/include/scsi/libfc.h
86854 +++ b/include/scsi/libfc.h
86855 @@ -771,6 +771,7 @@ struct libfc_function_template {
86856 */
86857 void (*disc_stop_final) (struct fc_lport *);
86858 };
86859 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86860
86861 /**
86862 * struct fc_disc - Discovery context
86863 @@ -875,7 +876,7 @@ struct fc_lport {
86864 struct fc_vport *vport;
86865
86866 /* Operational Information */
86867 - struct libfc_function_template tt;
86868 + libfc_function_template_no_const tt;
86869 u8 link_up;
86870 u8 qfull;
86871 enum fc_lport_state state;
86872 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86873 index 1a0d184..4fb841f 100644
86874 --- a/include/scsi/scsi_device.h
86875 +++ b/include/scsi/scsi_device.h
86876 @@ -185,9 +185,9 @@ struct scsi_device {
86877 unsigned int max_device_blocked; /* what device_blocked counts down from */
86878 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
86879
86880 - atomic_t iorequest_cnt;
86881 - atomic_t iodone_cnt;
86882 - atomic_t ioerr_cnt;
86883 + atomic_unchecked_t iorequest_cnt;
86884 + atomic_unchecked_t iodone_cnt;
86885 + atomic_unchecked_t ioerr_cnt;
86886
86887 struct device sdev_gendev,
86888 sdev_dev;
86889 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
86890 index 007a0bc..7188db8 100644
86891 --- a/include/scsi/scsi_transport_fc.h
86892 +++ b/include/scsi/scsi_transport_fc.h
86893 @@ -756,7 +756,8 @@ struct fc_function_template {
86894 unsigned long show_host_system_hostname:1;
86895
86896 unsigned long disable_target_scan:1;
86897 -};
86898 +} __do_const;
86899 +typedef struct fc_function_template __no_const fc_function_template_no_const;
86900
86901
86902 /**
86903 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
86904 index ae6c3b8..fd748ac 100644
86905 --- a/include/sound/compress_driver.h
86906 +++ b/include/sound/compress_driver.h
86907 @@ -128,7 +128,7 @@ struct snd_compr_ops {
86908 struct snd_compr_caps *caps);
86909 int (*get_codec_caps) (struct snd_compr_stream *stream,
86910 struct snd_compr_codec_caps *codec);
86911 -};
86912 +} __no_const;
86913
86914 /**
86915 * struct snd_compr: Compressed device
86916 diff --git a/include/sound/soc.h b/include/sound/soc.h
86917 index c83a334..27c8038 100644
86918 --- a/include/sound/soc.h
86919 +++ b/include/sound/soc.h
86920 @@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
86921 /* probe ordering - for components with runtime dependencies */
86922 int probe_order;
86923 int remove_order;
86924 -};
86925 +} __do_const;
86926
86927 /* SoC platform interface */
86928 struct snd_soc_platform_driver {
86929 @@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
86930 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
86931 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
86932 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
86933 -};
86934 +} __do_const;
86935
86936 struct snd_soc_dai_link_component {
86937 const char *name;
86938 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
86939 index 9ec9864..e2ee1ee 100644
86940 --- a/include/target/target_core_base.h
86941 +++ b/include/target/target_core_base.h
86942 @@ -761,7 +761,7 @@ struct se_device {
86943 atomic_long_t write_bytes;
86944 /* Active commands on this virtual SE device */
86945 atomic_t simple_cmds;
86946 - atomic_t dev_ordered_id;
86947 + atomic_unchecked_t dev_ordered_id;
86948 atomic_t dev_ordered_sync;
86949 atomic_t dev_qf_count;
86950 int export_count;
86951 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
86952 new file mode 100644
86953 index 0000000..fb634b7
86954 --- /dev/null
86955 +++ b/include/trace/events/fs.h
86956 @@ -0,0 +1,53 @@
86957 +#undef TRACE_SYSTEM
86958 +#define TRACE_SYSTEM fs
86959 +
86960 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
86961 +#define _TRACE_FS_H
86962 +
86963 +#include <linux/fs.h>
86964 +#include <linux/tracepoint.h>
86965 +
86966 +TRACE_EVENT(do_sys_open,
86967 +
86968 + TP_PROTO(const char *filename, int flags, int mode),
86969 +
86970 + TP_ARGS(filename, flags, mode),
86971 +
86972 + TP_STRUCT__entry(
86973 + __string( filename, filename )
86974 + __field( int, flags )
86975 + __field( int, mode )
86976 + ),
86977 +
86978 + TP_fast_assign(
86979 + __assign_str(filename, filename);
86980 + __entry->flags = flags;
86981 + __entry->mode = mode;
86982 + ),
86983 +
86984 + TP_printk("\"%s\" %x %o",
86985 + __get_str(filename), __entry->flags, __entry->mode)
86986 +);
86987 +
86988 +TRACE_EVENT(open_exec,
86989 +
86990 + TP_PROTO(const char *filename),
86991 +
86992 + TP_ARGS(filename),
86993 +
86994 + TP_STRUCT__entry(
86995 + __string( filename, filename )
86996 + ),
86997 +
86998 + TP_fast_assign(
86999 + __assign_str(filename, filename);
87000 + ),
87001 +
87002 + TP_printk("\"%s\"",
87003 + __get_str(filename))
87004 +);
87005 +
87006 +#endif /* _TRACE_FS_H */
87007 +
87008 +/* This part must be outside protection */
87009 +#include <trace/define_trace.h>
87010 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87011 index 3608beb..df39d8a 100644
87012 --- a/include/trace/events/irq.h
87013 +++ b/include/trace/events/irq.h
87014 @@ -36,7 +36,7 @@ struct softirq_action;
87015 */
87016 TRACE_EVENT(irq_handler_entry,
87017
87018 - TP_PROTO(int irq, struct irqaction *action),
87019 + TP_PROTO(int irq, const struct irqaction *action),
87020
87021 TP_ARGS(irq, action),
87022
87023 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87024 */
87025 TRACE_EVENT(irq_handler_exit,
87026
87027 - TP_PROTO(int irq, struct irqaction *action, int ret),
87028 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87029
87030 TP_ARGS(irq, action, ret),
87031
87032 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87033 index 7caf44c..23c6f27 100644
87034 --- a/include/uapi/linux/a.out.h
87035 +++ b/include/uapi/linux/a.out.h
87036 @@ -39,6 +39,14 @@ enum machine_type {
87037 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87038 };
87039
87040 +/* Constants for the N_FLAGS field */
87041 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87042 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87043 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87044 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87045 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87046 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87047 +
87048 #if !defined (N_MAGIC)
87049 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87050 #endif
87051 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87052 index 22b6ad3..aeba37e 100644
87053 --- a/include/uapi/linux/bcache.h
87054 +++ b/include/uapi/linux/bcache.h
87055 @@ -5,6 +5,7 @@
87056 * Bcache on disk data structures
87057 */
87058
87059 +#include <linux/compiler.h>
87060 #include <asm/types.h>
87061
87062 #define BITMASK(name, type, field, offset, size) \
87063 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87064 /* Btree keys - all units are in sectors */
87065
87066 struct bkey {
87067 - __u64 high;
87068 - __u64 low;
87069 + __u64 high __intentional_overflow(-1);
87070 + __u64 low __intentional_overflow(-1);
87071 __u64 ptr[];
87072 };
87073
87074 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87075 index d876736..ccce5c0 100644
87076 --- a/include/uapi/linux/byteorder/little_endian.h
87077 +++ b/include/uapi/linux/byteorder/little_endian.h
87078 @@ -42,51 +42,51 @@
87079
87080 static inline __le64 __cpu_to_le64p(const __u64 *p)
87081 {
87082 - return (__force __le64)*p;
87083 + return (__force const __le64)*p;
87084 }
87085 -static inline __u64 __le64_to_cpup(const __le64 *p)
87086 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87087 {
87088 - return (__force __u64)*p;
87089 + return (__force const __u64)*p;
87090 }
87091 static inline __le32 __cpu_to_le32p(const __u32 *p)
87092 {
87093 - return (__force __le32)*p;
87094 + return (__force const __le32)*p;
87095 }
87096 static inline __u32 __le32_to_cpup(const __le32 *p)
87097 {
87098 - return (__force __u32)*p;
87099 + return (__force const __u32)*p;
87100 }
87101 static inline __le16 __cpu_to_le16p(const __u16 *p)
87102 {
87103 - return (__force __le16)*p;
87104 + return (__force const __le16)*p;
87105 }
87106 static inline __u16 __le16_to_cpup(const __le16 *p)
87107 {
87108 - return (__force __u16)*p;
87109 + return (__force const __u16)*p;
87110 }
87111 static inline __be64 __cpu_to_be64p(const __u64 *p)
87112 {
87113 - return (__force __be64)__swab64p(p);
87114 + return (__force const __be64)__swab64p(p);
87115 }
87116 static inline __u64 __be64_to_cpup(const __be64 *p)
87117 {
87118 - return __swab64p((__u64 *)p);
87119 + return __swab64p((const __u64 *)p);
87120 }
87121 static inline __be32 __cpu_to_be32p(const __u32 *p)
87122 {
87123 - return (__force __be32)__swab32p(p);
87124 + return (__force const __be32)__swab32p(p);
87125 }
87126 -static inline __u32 __be32_to_cpup(const __be32 *p)
87127 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87128 {
87129 - return __swab32p((__u32 *)p);
87130 + return __swab32p((const __u32 *)p);
87131 }
87132 static inline __be16 __cpu_to_be16p(const __u16 *p)
87133 {
87134 - return (__force __be16)__swab16p(p);
87135 + return (__force const __be16)__swab16p(p);
87136 }
87137 static inline __u16 __be16_to_cpup(const __be16 *p)
87138 {
87139 - return __swab16p((__u16 *)p);
87140 + return __swab16p((const __u16 *)p);
87141 }
87142 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87143 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87144 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87145 index ef6103b..d4e65dd 100644
87146 --- a/include/uapi/linux/elf.h
87147 +++ b/include/uapi/linux/elf.h
87148 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87149 #define PT_GNU_EH_FRAME 0x6474e550
87150
87151 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87152 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87153 +
87154 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87155 +
87156 +/* Constants for the e_flags field */
87157 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87158 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87159 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87160 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87161 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87162 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87163
87164 /*
87165 * Extended Numbering
87166 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87167 #define DT_DEBUG 21
87168 #define DT_TEXTREL 22
87169 #define DT_JMPREL 23
87170 +#define DT_FLAGS 30
87171 + #define DF_TEXTREL 0x00000004
87172 #define DT_ENCODING 32
87173 #define OLD_DT_LOOS 0x60000000
87174 #define DT_LOOS 0x6000000d
87175 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87176 #define PF_W 0x2
87177 #define PF_X 0x1
87178
87179 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87180 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87181 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87182 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87183 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87184 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87185 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87186 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87187 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87188 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87189 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87190 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87191 +
87192 typedef struct elf32_phdr{
87193 Elf32_Word p_type;
87194 Elf32_Off p_offset;
87195 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87196 #define EI_OSABI 7
87197 #define EI_PAD 8
87198
87199 +#define EI_PAX 14
87200 +
87201 #define ELFMAG0 0x7f /* EI_MAG */
87202 #define ELFMAG1 'E'
87203 #define ELFMAG2 'L'
87204 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87205 index aa169c4..6a2771d 100644
87206 --- a/include/uapi/linux/personality.h
87207 +++ b/include/uapi/linux/personality.h
87208 @@ -30,6 +30,7 @@ enum {
87209 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87210 ADDR_NO_RANDOMIZE | \
87211 ADDR_COMPAT_LAYOUT | \
87212 + ADDR_LIMIT_3GB | \
87213 MMAP_PAGE_ZERO)
87214
87215 /*
87216 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87217 index 7530e74..e714828 100644
87218 --- a/include/uapi/linux/screen_info.h
87219 +++ b/include/uapi/linux/screen_info.h
87220 @@ -43,7 +43,8 @@ struct screen_info {
87221 __u16 pages; /* 0x32 */
87222 __u16 vesa_attributes; /* 0x34 */
87223 __u32 capabilities; /* 0x36 */
87224 - __u8 _reserved[6]; /* 0x3a */
87225 + __u16 vesapm_size; /* 0x3a */
87226 + __u8 _reserved[4]; /* 0x3c */
87227 } __attribute__((packed));
87228
87229 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87230 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87231 index 0e011eb..82681b1 100644
87232 --- a/include/uapi/linux/swab.h
87233 +++ b/include/uapi/linux/swab.h
87234 @@ -43,7 +43,7 @@
87235 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87236 */
87237
87238 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87239 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87240 {
87241 #ifdef __HAVE_BUILTIN_BSWAP16__
87242 return __builtin_bswap16(val);
87243 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87244 #endif
87245 }
87246
87247 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87248 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87249 {
87250 #ifdef __HAVE_BUILTIN_BSWAP32__
87251 return __builtin_bswap32(val);
87252 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87253 #endif
87254 }
87255
87256 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87257 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87258 {
87259 #ifdef __HAVE_BUILTIN_BSWAP64__
87260 return __builtin_bswap64(val);
87261 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87262 index 43aaba1..1c30b48 100644
87263 --- a/include/uapi/linux/sysctl.h
87264 +++ b/include/uapi/linux/sysctl.h
87265 @@ -155,8 +155,6 @@ enum
87266 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87267 };
87268
87269 -
87270 -
87271 /* CTL_VM names: */
87272 enum
87273 {
87274 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
87275 index 778a329..1416ffb 100644
87276 --- a/include/uapi/linux/videodev2.h
87277 +++ b/include/uapi/linux/videodev2.h
87278 @@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
87279 union {
87280 __s32 value;
87281 __s64 value64;
87282 - char *string;
87283 + char __user *string;
87284 __u8 *p_u8;
87285 __u16 *p_u16;
87286 __u32 *p_u32;
87287 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87288 index 1590c49..5eab462 100644
87289 --- a/include/uapi/linux/xattr.h
87290 +++ b/include/uapi/linux/xattr.h
87291 @@ -73,5 +73,9 @@
87292 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87293 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87294
87295 +/* User namespace */
87296 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87297 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87298 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87299
87300 #endif /* _UAPI_LINUX_XATTR_H */
87301 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87302 index f9466fa..f4e2b81 100644
87303 --- a/include/video/udlfb.h
87304 +++ b/include/video/udlfb.h
87305 @@ -53,10 +53,10 @@ struct dlfb_data {
87306 u32 pseudo_palette[256];
87307 int blank_mode; /*one of FB_BLANK_ */
87308 /* blit-only rendering path metrics, exposed through sysfs */
87309 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87310 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87311 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87312 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87313 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87314 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87315 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87316 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87317 };
87318
87319 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87320 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87321 index 30f5362..8ed8ac9 100644
87322 --- a/include/video/uvesafb.h
87323 +++ b/include/video/uvesafb.h
87324 @@ -122,6 +122,7 @@ struct uvesafb_par {
87325 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87326 u8 pmi_setpal; /* PMI for palette changes */
87327 u16 *pmi_base; /* protected mode interface location */
87328 + u8 *pmi_code; /* protected mode code location */
87329 void *pmi_start;
87330 void *pmi_pal;
87331 u8 *vbe_state_orig; /*
87332 diff --git a/init/Kconfig b/init/Kconfig
87333 index 80a6907..baf7d53 100644
87334 --- a/init/Kconfig
87335 +++ b/init/Kconfig
87336 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87337
87338 config CHECKPOINT_RESTORE
87339 bool "Checkpoint/restore support" if EXPERT
87340 + depends on !GRKERNSEC
87341 default n
87342 help
87343 Enables additional kernel features in a sake of checkpoint/restore.
87344 @@ -1635,7 +1636,7 @@ config SLUB_DEBUG
87345
87346 config COMPAT_BRK
87347 bool "Disable heap randomization"
87348 - default y
87349 + default n
87350 help
87351 Randomizing heap placement makes heap exploits harder, but it
87352 also breaks ancient binaries (including anything libc5 based).
87353 @@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
87354 config STOP_MACHINE
87355 bool
87356 default y
87357 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87358 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87359 help
87360 Need stop_machine() primitive.
87361
87362 diff --git a/init/Makefile b/init/Makefile
87363 index 7bc47ee..6da2dc7 100644
87364 --- a/init/Makefile
87365 +++ b/init/Makefile
87366 @@ -2,6 +2,9 @@
87367 # Makefile for the linux kernel.
87368 #
87369
87370 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87371 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87372 +
87373 obj-y := main.o version.o mounts.o
87374 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87375 obj-y += noinitramfs.o
87376 diff --git a/init/do_mounts.c b/init/do_mounts.c
87377 index 82f2288..ea1430a 100644
87378 --- a/init/do_mounts.c
87379 +++ b/init/do_mounts.c
87380 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
87381 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87382 {
87383 struct super_block *s;
87384 - int err = sys_mount(name, "/root", fs, flags, data);
87385 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87386 if (err)
87387 return err;
87388
87389 - sys_chdir("/root");
87390 + sys_chdir((const char __force_user *)"/root");
87391 s = current->fs->pwd.dentry->d_sb;
87392 ROOT_DEV = s->s_dev;
87393 printk(KERN_INFO
87394 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
87395 va_start(args, fmt);
87396 vsprintf(buf, fmt, args);
87397 va_end(args);
87398 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87399 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87400 if (fd >= 0) {
87401 sys_ioctl(fd, FDEJECT, 0);
87402 sys_close(fd);
87403 }
87404 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87405 - fd = sys_open("/dev/console", O_RDWR, 0);
87406 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87407 if (fd >= 0) {
87408 sys_ioctl(fd, TCGETS, (long)&termios);
87409 termios.c_lflag &= ~ICANON;
87410 sys_ioctl(fd, TCSETSF, (long)&termios);
87411 - sys_read(fd, &c, 1);
87412 + sys_read(fd, (char __user *)&c, 1);
87413 termios.c_lflag |= ICANON;
87414 sys_ioctl(fd, TCSETSF, (long)&termios);
87415 sys_close(fd);
87416 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
87417 mount_root();
87418 out:
87419 devtmpfs_mount("dev");
87420 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87421 - sys_chroot(".");
87422 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87423 + sys_chroot((const char __force_user *)".");
87424 }
87425
87426 static bool is_tmpfs;
87427 diff --git a/init/do_mounts.h b/init/do_mounts.h
87428 index f5b978a..69dbfe8 100644
87429 --- a/init/do_mounts.h
87430 +++ b/init/do_mounts.h
87431 @@ -15,15 +15,15 @@ extern int root_mountflags;
87432
87433 static inline int create_dev(char *name, dev_t dev)
87434 {
87435 - sys_unlink(name);
87436 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87437 + sys_unlink((char __force_user *)name);
87438 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87439 }
87440
87441 #if BITS_PER_LONG == 32
87442 static inline u32 bstat(char *name)
87443 {
87444 struct stat64 stat;
87445 - if (sys_stat64(name, &stat) != 0)
87446 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87447 return 0;
87448 if (!S_ISBLK(stat.st_mode))
87449 return 0;
87450 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87451 static inline u32 bstat(char *name)
87452 {
87453 struct stat stat;
87454 - if (sys_newstat(name, &stat) != 0)
87455 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87456 return 0;
87457 if (!S_ISBLK(stat.st_mode))
87458 return 0;
87459 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87460 index 3e0878e..8a9d7a0 100644
87461 --- a/init/do_mounts_initrd.c
87462 +++ b/init/do_mounts_initrd.c
87463 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87464 {
87465 sys_unshare(CLONE_FS | CLONE_FILES);
87466 /* stdin/stdout/stderr for /linuxrc */
87467 - sys_open("/dev/console", O_RDWR, 0);
87468 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87469 sys_dup(0);
87470 sys_dup(0);
87471 /* move initrd over / and chdir/chroot in initrd root */
87472 - sys_chdir("/root");
87473 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87474 - sys_chroot(".");
87475 + sys_chdir((const char __force_user *)"/root");
87476 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87477 + sys_chroot((const char __force_user *)".");
87478 sys_setsid();
87479 return 0;
87480 }
87481 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87482 create_dev("/dev/root.old", Root_RAM0);
87483 /* mount initrd on rootfs' /root */
87484 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87485 - sys_mkdir("/old", 0700);
87486 - sys_chdir("/old");
87487 + sys_mkdir((const char __force_user *)"/old", 0700);
87488 + sys_chdir((const char __force_user *)"/old");
87489
87490 /* try loading default modules from initrd */
87491 load_default_modules();
87492 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87493 current->flags &= ~PF_FREEZER_SKIP;
87494
87495 /* move initrd to rootfs' /old */
87496 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87497 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87498 /* switch root and cwd back to / of rootfs */
87499 - sys_chroot("..");
87500 + sys_chroot((const char __force_user *)"..");
87501
87502 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87503 - sys_chdir("/old");
87504 + sys_chdir((const char __force_user *)"/old");
87505 return;
87506 }
87507
87508 - sys_chdir("/");
87509 + sys_chdir((const char __force_user *)"/");
87510 ROOT_DEV = new_decode_dev(real_root_dev);
87511 mount_root();
87512
87513 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87514 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87515 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87516 if (!error)
87517 printk("okay\n");
87518 else {
87519 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87520 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87521 if (error == -ENOENT)
87522 printk("/initrd does not exist. Ignored.\n");
87523 else
87524 printk("failed\n");
87525 printk(KERN_NOTICE "Unmounting old root\n");
87526 - sys_umount("/old", MNT_DETACH);
87527 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87528 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87529 if (fd < 0) {
87530 error = fd;
87531 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87532 * mounted in the normal path.
87533 */
87534 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87535 - sys_unlink("/initrd.image");
87536 + sys_unlink((const char __force_user *)"/initrd.image");
87537 handle_initrd();
87538 return 1;
87539 }
87540 }
87541 - sys_unlink("/initrd.image");
87542 + sys_unlink((const char __force_user *)"/initrd.image");
87543 return 0;
87544 }
87545 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87546 index 8cb6db5..d729f50 100644
87547 --- a/init/do_mounts_md.c
87548 +++ b/init/do_mounts_md.c
87549 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87550 partitioned ? "_d" : "", minor,
87551 md_setup_args[ent].device_names);
87552
87553 - fd = sys_open(name, 0, 0);
87554 + fd = sys_open((char __force_user *)name, 0, 0);
87555 if (fd < 0) {
87556 printk(KERN_ERR "md: open failed - cannot start "
87557 "array %s\n", name);
87558 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87559 * array without it
87560 */
87561 sys_close(fd);
87562 - fd = sys_open(name, 0, 0);
87563 + fd = sys_open((char __force_user *)name, 0, 0);
87564 sys_ioctl(fd, BLKRRPART, 0);
87565 }
87566 sys_close(fd);
87567 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87568
87569 wait_for_device_probe();
87570
87571 - fd = sys_open("/dev/md0", 0, 0);
87572 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87573 if (fd >= 0) {
87574 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87575 sys_close(fd);
87576 diff --git a/init/init_task.c b/init/init_task.c
87577 index ba0a7f36..2bcf1d5 100644
87578 --- a/init/init_task.c
87579 +++ b/init/init_task.c
87580 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87581 * Initial thread structure. Alignment of this is handled by a special
87582 * linker map entry.
87583 */
87584 +#ifdef CONFIG_X86
87585 +union thread_union init_thread_union __init_task_data;
87586 +#else
87587 union thread_union init_thread_union __init_task_data =
87588 { INIT_THREAD_INFO(init_task) };
87589 +#endif
87590 diff --git a/init/initramfs.c b/init/initramfs.c
87591 index bece48c..e911bd8 100644
87592 --- a/init/initramfs.c
87593 +++ b/init/initramfs.c
87594 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87595
87596 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87597 while (count) {
87598 - ssize_t rv = sys_write(fd, p, count);
87599 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87600
87601 if (rv < 0) {
87602 if (rv == -EINTR || rv == -EAGAIN)
87603 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87604 }
87605 }
87606
87607 -static long __init do_utime(char *filename, time_t mtime)
87608 +static long __init do_utime(char __force_user *filename, time_t mtime)
87609 {
87610 struct timespec t[2];
87611
87612 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87613 struct dir_entry *de, *tmp;
87614 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87615 list_del(&de->list);
87616 - do_utime(de->name, de->mtime);
87617 + do_utime((char __force_user *)de->name, de->mtime);
87618 kfree(de->name);
87619 kfree(de);
87620 }
87621 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87622 if (nlink >= 2) {
87623 char *old = find_link(major, minor, ino, mode, collected);
87624 if (old)
87625 - return (sys_link(old, collected) < 0) ? -1 : 1;
87626 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87627 }
87628 return 0;
87629 }
87630 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
87631 {
87632 struct stat st;
87633
87634 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
87635 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
87636 if (S_ISDIR(st.st_mode))
87637 - sys_rmdir(path);
87638 + sys_rmdir((char __force_user *)path);
87639 else
87640 - sys_unlink(path);
87641 + sys_unlink((char __force_user *)path);
87642 }
87643 }
87644
87645 @@ -338,7 +338,7 @@ static int __init do_name(void)
87646 int openflags = O_WRONLY|O_CREAT;
87647 if (ml != 1)
87648 openflags |= O_TRUNC;
87649 - wfd = sys_open(collected, openflags, mode);
87650 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87651
87652 if (wfd >= 0) {
87653 sys_fchown(wfd, uid, gid);
87654 @@ -350,17 +350,17 @@ static int __init do_name(void)
87655 }
87656 }
87657 } else if (S_ISDIR(mode)) {
87658 - sys_mkdir(collected, mode);
87659 - sys_chown(collected, uid, gid);
87660 - sys_chmod(collected, mode);
87661 + sys_mkdir((char __force_user *)collected, mode);
87662 + sys_chown((char __force_user *)collected, uid, gid);
87663 + sys_chmod((char __force_user *)collected, mode);
87664 dir_add(collected, mtime);
87665 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87666 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87667 if (maybe_link() == 0) {
87668 - sys_mknod(collected, mode, rdev);
87669 - sys_chown(collected, uid, gid);
87670 - sys_chmod(collected, mode);
87671 - do_utime(collected, mtime);
87672 + sys_mknod((char __force_user *)collected, mode, rdev);
87673 + sys_chown((char __force_user *)collected, uid, gid);
87674 + sys_chmod((char __force_user *)collected, mode);
87675 + do_utime((char __force_user *)collected, mtime);
87676 }
87677 }
87678 return 0;
87679 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87680 if (xwrite(wfd, victim, body_len) != body_len)
87681 error("write error");
87682 sys_close(wfd);
87683 - do_utime(vcollected, mtime);
87684 + do_utime((char __force_user *)vcollected, mtime);
87685 kfree(vcollected);
87686 eat(body_len);
87687 state = SkipIt;
87688 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87689 {
87690 collected[N_ALIGN(name_len) + body_len] = '\0';
87691 clean_path(collected, 0);
87692 - sys_symlink(collected + N_ALIGN(name_len), collected);
87693 - sys_lchown(collected, uid, gid);
87694 - do_utime(collected, mtime);
87695 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87696 + sys_lchown((char __force_user *)collected, uid, gid);
87697 + do_utime((char __force_user *)collected, mtime);
87698 state = SkipIt;
87699 next_state = Reset;
87700 return 0;
87701 diff --git a/init/main.c b/init/main.c
87702 index d0f4b59..0c4b184 100644
87703 --- a/init/main.c
87704 +++ b/init/main.c
87705 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87706 static inline void mark_rodata_ro(void) { }
87707 #endif
87708
87709 +extern void grsecurity_init(void);
87710 +
87711 /*
87712 * Debug helper: via this flag we know that we are in 'early bootup code'
87713 * where only the boot processor is running with IRQ disabled. This means
87714 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87715
87716 __setup("reset_devices", set_reset_devices);
87717
87718 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87719 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87720 +static int __init setup_grsec_proc_gid(char *str)
87721 +{
87722 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87723 + return 1;
87724 +}
87725 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87726 +#endif
87727 +
87728 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87729 +unsigned long pax_user_shadow_base __read_only;
87730 +EXPORT_SYMBOL(pax_user_shadow_base);
87731 +extern char pax_enter_kernel_user[];
87732 +extern char pax_exit_kernel_user[];
87733 +#endif
87734 +
87735 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87736 +static int __init setup_pax_nouderef(char *str)
87737 +{
87738 +#ifdef CONFIG_X86_32
87739 + unsigned int cpu;
87740 + struct desc_struct *gdt;
87741 +
87742 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87743 + gdt = get_cpu_gdt_table(cpu);
87744 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87745 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87746 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87747 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87748 + }
87749 + loadsegment(ds, __KERNEL_DS);
87750 + loadsegment(es, __KERNEL_DS);
87751 + loadsegment(ss, __KERNEL_DS);
87752 +#else
87753 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87754 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87755 + clone_pgd_mask = ~(pgdval_t)0UL;
87756 + pax_user_shadow_base = 0UL;
87757 + setup_clear_cpu_cap(X86_FEATURE_PCID);
87758 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87759 +#endif
87760 +
87761 + return 0;
87762 +}
87763 +early_param("pax_nouderef", setup_pax_nouderef);
87764 +
87765 +#ifdef CONFIG_X86_64
87766 +static int __init setup_pax_weakuderef(char *str)
87767 +{
87768 + if (clone_pgd_mask != ~(pgdval_t)0UL)
87769 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87770 + return 1;
87771 +}
87772 +__setup("pax_weakuderef", setup_pax_weakuderef);
87773 +#endif
87774 +#endif
87775 +
87776 +#ifdef CONFIG_PAX_SOFTMODE
87777 +int pax_softmode;
87778 +
87779 +static int __init setup_pax_softmode(char *str)
87780 +{
87781 + get_option(&str, &pax_softmode);
87782 + return 1;
87783 +}
87784 +__setup("pax_softmode=", setup_pax_softmode);
87785 +#endif
87786 +
87787 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87788 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87789 static const char *panic_later, *panic_param;
87790 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87791 struct blacklist_entry *entry;
87792 char *fn_name;
87793
87794 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87795 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87796 if (!fn_name)
87797 return false;
87798
87799 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87800 {
87801 int count = preempt_count();
87802 int ret;
87803 - char msgbuf[64];
87804 + const char *msg1 = "", *msg2 = "";
87805
87806 if (initcall_blacklisted(fn))
87807 return -EPERM;
87808 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87809 else
87810 ret = fn();
87811
87812 - msgbuf[0] = 0;
87813 -
87814 if (preempt_count() != count) {
87815 - sprintf(msgbuf, "preemption imbalance ");
87816 + msg1 = " preemption imbalance";
87817 preempt_count_set(count);
87818 }
87819 if (irqs_disabled()) {
87820 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87821 + msg2 = " disabled interrupts";
87822 local_irq_enable();
87823 }
87824 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87825 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87826
87827 + add_latent_entropy();
87828 return ret;
87829 }
87830
87831 @@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
87832 {
87833 argv_init[0] = init_filename;
87834 return do_execve(getname_kernel(init_filename),
87835 - (const char __user *const __user *)argv_init,
87836 - (const char __user *const __user *)envp_init);
87837 + (const char __user *const __force_user *)argv_init,
87838 + (const char __user *const __force_user *)envp_init);
87839 }
87840
87841 static int try_to_run_init_process(const char *init_filename)
87842 @@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
87843 return ret;
87844 }
87845
87846 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87847 +extern int gr_init_ran;
87848 +#endif
87849 +
87850 static noinline void __init kernel_init_freeable(void);
87851
87852 static int __ref kernel_init(void *unused)
87853 @@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
87854 ramdisk_execute_command, ret);
87855 }
87856
87857 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87858 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
87859 + gr_init_ran = 1;
87860 +#endif
87861 +
87862 /*
87863 * We try each of these until one succeeds.
87864 *
87865 @@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
87866 do_basic_setup();
87867
87868 /* Open the /dev/console on the rootfs, this should never fail */
87869 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87870 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87871 pr_err("Warning: unable to open an initial console.\n");
87872
87873 (void) sys_dup(0);
87874 @@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
87875 if (!ramdisk_execute_command)
87876 ramdisk_execute_command = "/init";
87877
87878 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
87879 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
87880 ramdisk_execute_command = NULL;
87881 prepare_namespace();
87882 }
87883
87884 + grsecurity_init();
87885 +
87886 /*
87887 * Ok, we have completed the initial bootup, and
87888 * we're essentially up and running. Get rid of the
87889 diff --git a/ipc/compat.c b/ipc/compat.c
87890 index b5ef4f7..ff31d87 100644
87891 --- a/ipc/compat.c
87892 +++ b/ipc/compat.c
87893 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
87894 COMPAT_SHMLBA);
87895 if (err < 0)
87896 return err;
87897 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
87898 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
87899 }
87900 case SHMDT:
87901 return sys_shmdt(compat_ptr(ptr));
87902 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
87903 index e8075b2..76f2c6a 100644
87904 --- a/ipc/ipc_sysctl.c
87905 +++ b/ipc/ipc_sysctl.c
87906 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
87907 static int proc_ipc_dointvec(struct ctl_table *table, int write,
87908 void __user *buffer, size_t *lenp, loff_t *ppos)
87909 {
87910 - struct ctl_table ipc_table;
87911 + ctl_table_no_const ipc_table;
87912
87913 memcpy(&ipc_table, table, sizeof(ipc_table));
87914 ipc_table.data = get_ipc(table);
87915 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
87916 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
87917 void __user *buffer, size_t *lenp, loff_t *ppos)
87918 {
87919 - struct ctl_table ipc_table;
87920 + ctl_table_no_const ipc_table;
87921
87922 memcpy(&ipc_table, table, sizeof(ipc_table));
87923 ipc_table.data = get_ipc(table);
87924 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
87925 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87926 void __user *buffer, size_t *lenp, loff_t *ppos)
87927 {
87928 - struct ctl_table ipc_table;
87929 + ctl_table_no_const ipc_table;
87930 size_t lenp_bef = *lenp;
87931 int rc;
87932
87933 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87934 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
87935 void __user *buffer, size_t *lenp, loff_t *ppos)
87936 {
87937 - struct ctl_table ipc_table;
87938 + ctl_table_no_const ipc_table;
87939 memcpy(&ipc_table, table, sizeof(ipc_table));
87940 ipc_table.data = get_ipc(table);
87941
87942 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
87943 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
87944 void __user *buffer, size_t *lenp, loff_t *ppos)
87945 {
87946 - struct ctl_table ipc_table;
87947 + ctl_table_no_const ipc_table;
87948 int oldval;
87949 int rc;
87950
87951 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
87952 index 68d4e95..1477ded 100644
87953 --- a/ipc/mq_sysctl.c
87954 +++ b/ipc/mq_sysctl.c
87955 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
87956 static int proc_mq_dointvec(struct ctl_table *table, int write,
87957 void __user *buffer, size_t *lenp, loff_t *ppos)
87958 {
87959 - struct ctl_table mq_table;
87960 + ctl_table_no_const mq_table;
87961 memcpy(&mq_table, table, sizeof(mq_table));
87962 mq_table.data = get_mq(table);
87963
87964 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
87965 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
87966 void __user *buffer, size_t *lenp, loff_t *ppos)
87967 {
87968 - struct ctl_table mq_table;
87969 + ctl_table_no_const mq_table;
87970 memcpy(&mq_table, table, sizeof(mq_table));
87971 mq_table.data = get_mq(table);
87972
87973 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
87974 index 4fcf39a..d3cc2ec 100644
87975 --- a/ipc/mqueue.c
87976 +++ b/ipc/mqueue.c
87977 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
87978 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
87979 info->attr.mq_msgsize);
87980
87981 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
87982 spin_lock(&mq_lock);
87983 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
87984 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
87985 diff --git a/ipc/shm.c b/ipc/shm.c
87986 index 7fc9f9f..95e201f 100644
87987 --- a/ipc/shm.c
87988 +++ b/ipc/shm.c
87989 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
87990 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
87991 #endif
87992
87993 +#ifdef CONFIG_GRKERNSEC
87994 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87995 + const u64 shm_createtime, const kuid_t cuid,
87996 + const int shmid);
87997 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87998 + const u64 shm_createtime);
87999 +#endif
88000 +
88001 void shm_init_ns(struct ipc_namespace *ns)
88002 {
88003 ns->shm_ctlmax = SHMMAX;
88004 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88005 shp->shm_lprid = 0;
88006 shp->shm_atim = shp->shm_dtim = 0;
88007 shp->shm_ctim = get_seconds();
88008 +#ifdef CONFIG_GRKERNSEC
88009 + shp->shm_createtime = ktime_get_ns();
88010 +#endif
88011 shp->shm_segsz = size;
88012 shp->shm_nattch = 0;
88013 shp->shm_file = file;
88014 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88015 f_mode = FMODE_READ | FMODE_WRITE;
88016 }
88017 if (shmflg & SHM_EXEC) {
88018 +
88019 +#ifdef CONFIG_PAX_MPROTECT
88020 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88021 + goto out;
88022 +#endif
88023 +
88024 prot |= PROT_EXEC;
88025 acc_mode |= S_IXUGO;
88026 }
88027 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88028 if (err)
88029 goto out_unlock;
88030
88031 +#ifdef CONFIG_GRKERNSEC
88032 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88033 + shp->shm_perm.cuid, shmid) ||
88034 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88035 + err = -EACCES;
88036 + goto out_unlock;
88037 + }
88038 +#endif
88039 +
88040 ipc_lock_object(&shp->shm_perm);
88041
88042 /* check if shm_destroy() is tearing down shp */
88043 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88044 path = shp->shm_file->f_path;
88045 path_get(&path);
88046 shp->shm_nattch++;
88047 +#ifdef CONFIG_GRKERNSEC
88048 + shp->shm_lapid = current->pid;
88049 +#endif
88050 size = i_size_read(path.dentry->d_inode);
88051 ipc_unlock_object(&shp->shm_perm);
88052 rcu_read_unlock();
88053 diff --git a/ipc/util.c b/ipc/util.c
88054 index 27d74e6..8be0be2 100644
88055 --- a/ipc/util.c
88056 +++ b/ipc/util.c
88057 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88058 int (*show)(struct seq_file *, void *);
88059 };
88060
88061 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88062 +
88063 static void ipc_memory_notifier(struct work_struct *work)
88064 {
88065 ipcns_notify(IPCNS_MEMCHANGED);
88066 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88067 granted_mode >>= 6;
88068 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88069 granted_mode >>= 3;
88070 +
88071 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88072 + return -1;
88073 +
88074 /* is there some bit set in requested_mode but not in granted_mode? */
88075 if ((requested_mode & ~granted_mode & 0007) &&
88076 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88077 diff --git a/kernel/audit.c b/kernel/audit.c
88078 index 6726aa6..bb864a9 100644
88079 --- a/kernel/audit.c
88080 +++ b/kernel/audit.c
88081 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88082 3) suppressed due to audit_rate_limit
88083 4) suppressed due to audit_backlog_limit
88084 */
88085 -static atomic_t audit_lost = ATOMIC_INIT(0);
88086 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88087
88088 /* The netlink socket. */
88089 static struct sock *audit_sock;
88090 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88091 unsigned long now;
88092 int print;
88093
88094 - atomic_inc(&audit_lost);
88095 + atomic_inc_unchecked(&audit_lost);
88096
88097 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88098
88099 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88100 if (print) {
88101 if (printk_ratelimit())
88102 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88103 - atomic_read(&audit_lost),
88104 + atomic_read_unchecked(&audit_lost),
88105 audit_rate_limit,
88106 audit_backlog_limit);
88107 audit_panic(message);
88108 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88109 s.pid = audit_pid;
88110 s.rate_limit = audit_rate_limit;
88111 s.backlog_limit = audit_backlog_limit;
88112 - s.lost = atomic_read(&audit_lost);
88113 + s.lost = atomic_read_unchecked(&audit_lost);
88114 s.backlog = skb_queue_len(&audit_skb_queue);
88115 s.version = AUDIT_VERSION_LATEST;
88116 s.backlog_wait_time = audit_backlog_wait_time;
88117 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88118 index 21eae3c..66db239 100644
88119 --- a/kernel/auditsc.c
88120 +++ b/kernel/auditsc.c
88121 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88122 }
88123
88124 /* global counter which is incremented every time something logs in */
88125 -static atomic_t session_id = ATOMIC_INIT(0);
88126 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88127
88128 static int audit_set_loginuid_perm(kuid_t loginuid)
88129 {
88130 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
88131
88132 /* are we setting or clearing? */
88133 if (uid_valid(loginuid))
88134 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88135 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88136
88137 task->sessionid = sessionid;
88138 task->loginuid = loginuid;
88139 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88140 index 7f0dbcb..b54bb2c 100644
88141 --- a/kernel/bpf/core.c
88142 +++ b/kernel/bpf/core.c
88143 @@ -22,6 +22,7 @@
88144 */
88145 #include <linux/filter.h>
88146 #include <linux/skbuff.h>
88147 +#include <linux/vmalloc.h>
88148 #include <asm/unaligned.h>
88149
88150 /* Registers */
88151 @@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
88152 return NULL;
88153 }
88154
88155 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
88156 +{
88157 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88158 + gfp_extra_flags;
88159 + struct bpf_work_struct *ws;
88160 + struct bpf_prog *fp;
88161 +
88162 + size = round_up(size, PAGE_SIZE);
88163 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88164 + if (fp == NULL)
88165 + return NULL;
88166 +
88167 + ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
88168 + if (ws == NULL) {
88169 + vfree(fp);
88170 + return NULL;
88171 + }
88172 +
88173 + fp->pages = size / PAGE_SIZE;
88174 + fp->work = ws;
88175 +
88176 + return fp;
88177 +}
88178 +EXPORT_SYMBOL_GPL(bpf_prog_alloc);
88179 +
88180 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
88181 + gfp_t gfp_extra_flags)
88182 +{
88183 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88184 + gfp_extra_flags;
88185 + struct bpf_prog *fp;
88186 +
88187 + BUG_ON(fp_old == NULL);
88188 +
88189 + size = round_up(size, PAGE_SIZE);
88190 + if (size <= fp_old->pages * PAGE_SIZE)
88191 + return fp_old;
88192 +
88193 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88194 + if (fp != NULL) {
88195 + memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
88196 + fp->pages = size / PAGE_SIZE;
88197 +
88198 + /* We keep fp->work from fp_old around in the new
88199 + * reallocated structure.
88200 + */
88201 + fp_old->work = NULL;
88202 + __bpf_prog_free(fp_old);
88203 + }
88204 +
88205 + return fp;
88206 +}
88207 +EXPORT_SYMBOL_GPL(bpf_prog_realloc);
88208 +
88209 +void __bpf_prog_free(struct bpf_prog *fp)
88210 +{
88211 + kfree(fp->work);
88212 + vfree(fp);
88213 +}
88214 +EXPORT_SYMBOL_GPL(__bpf_prog_free);
88215 +
88216 /* Base function for offset calculation. Needs to go into .text section,
88217 * therefore keeping it non-static as well; will also be used by JITs
88218 * anyway later on, so do not let the compiler omit it.
88219 @@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
88220
88221 /* Probe if internal BPF can be JITed */
88222 bpf_int_jit_compile(fp);
88223 + /* Lock whole bpf_prog as read-only */
88224 + bpf_prog_lock_ro(fp);
88225 }
88226 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
88227
88228 -/* free internal BPF program */
88229 +static void bpf_prog_free_deferred(struct work_struct *work)
88230 +{
88231 + struct bpf_work_struct *ws;
88232 +
88233 + ws = container_of(work, struct bpf_work_struct, work);
88234 + bpf_jit_free(ws->prog);
88235 +}
88236 +
88237 +/* Free internal BPF program */
88238 void bpf_prog_free(struct bpf_prog *fp)
88239 {
88240 - bpf_jit_free(fp);
88241 + struct bpf_work_struct *ws = fp->work;
88242 +
88243 + INIT_WORK(&ws->work, bpf_prog_free_deferred);
88244 + ws->prog = fp;
88245 + schedule_work(&ws->work);
88246 }
88247 EXPORT_SYMBOL_GPL(bpf_prog_free);
88248 diff --git a/kernel/capability.c b/kernel/capability.c
88249 index 989f5bf..d317ca0 100644
88250 --- a/kernel/capability.c
88251 +++ b/kernel/capability.c
88252 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88253 * before modification is attempted and the application
88254 * fails.
88255 */
88256 + if (tocopy > ARRAY_SIZE(kdata))
88257 + return -EFAULT;
88258 +
88259 if (copy_to_user(dataptr, kdata, tocopy
88260 * sizeof(struct __user_cap_data_struct))) {
88261 return -EFAULT;
88262 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88263 int ret;
88264
88265 rcu_read_lock();
88266 - ret = security_capable(__task_cred(t), ns, cap);
88267 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88268 + gr_task_is_capable(t, __task_cred(t), cap);
88269 rcu_read_unlock();
88270
88271 - return (ret == 0);
88272 + return ret;
88273 }
88274
88275 /**
88276 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88277 int ret;
88278
88279 rcu_read_lock();
88280 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88281 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88282 rcu_read_unlock();
88283
88284 - return (ret == 0);
88285 + return ret;
88286 }
88287
88288 /**
88289 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88290 BUG();
88291 }
88292
88293 - if (security_capable(current_cred(), ns, cap) == 0) {
88294 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88295 current->flags |= PF_SUPERPRIV;
88296 return true;
88297 }
88298 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88299 }
88300 EXPORT_SYMBOL(ns_capable);
88301
88302 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88303 +{
88304 + if (unlikely(!cap_valid(cap))) {
88305 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88306 + BUG();
88307 + }
88308 +
88309 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88310 + current->flags |= PF_SUPERPRIV;
88311 + return true;
88312 + }
88313 + return false;
88314 +}
88315 +EXPORT_SYMBOL(ns_capable_nolog);
88316 +
88317 /**
88318 * file_ns_capable - Determine if the file's opener had a capability in effect
88319 * @file: The file we want to check
88320 @@ -427,6 +446,12 @@ bool capable(int cap)
88321 }
88322 EXPORT_SYMBOL(capable);
88323
88324 +bool capable_nolog(int cap)
88325 +{
88326 + return ns_capable_nolog(&init_user_ns, cap);
88327 +}
88328 +EXPORT_SYMBOL(capable_nolog);
88329 +
88330 /**
88331 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88332 * @inode: The inode in question
88333 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88334 kgid_has_mapping(ns, inode->i_gid);
88335 }
88336 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88337 +
88338 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88339 +{
88340 + struct user_namespace *ns = current_user_ns();
88341 +
88342 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88343 + kgid_has_mapping(ns, inode->i_gid);
88344 +}
88345 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88346 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88347 index 3a73f99..4f29fea 100644
88348 --- a/kernel/cgroup.c
88349 +++ b/kernel/cgroup.c
88350 @@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
88351 release_list);
88352 list_del_init(&cgrp->release_list);
88353 raw_spin_unlock(&release_list_lock);
88354 +
88355 + /*
88356 + * don't bother calling call_usermodehelper if we haven't
88357 + * configured a binary to execute
88358 + */
88359 + if (cgrp->root->release_agent_path[0] == '\0')
88360 + goto continue_free;
88361 +
88362 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
88363 if (!pathbuf)
88364 goto continue_free;
88365 @@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88366 struct task_struct *task;
88367 int count = 0;
88368
88369 - seq_printf(seq, "css_set %p\n", cset);
88370 + seq_printf(seq, "css_set %pK\n", cset);
88371
88372 list_for_each_entry(task, &cset->tasks, cg_list) {
88373 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88374 diff --git a/kernel/compat.c b/kernel/compat.c
88375 index ebb3c36..1df606e 100644
88376 --- a/kernel/compat.c
88377 +++ b/kernel/compat.c
88378 @@ -13,6 +13,7 @@
88379
88380 #include <linux/linkage.h>
88381 #include <linux/compat.h>
88382 +#include <linux/module.h>
88383 #include <linux/errno.h>
88384 #include <linux/time.h>
88385 #include <linux/signal.h>
88386 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88387 mm_segment_t oldfs;
88388 long ret;
88389
88390 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88391 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88392 oldfs = get_fs();
88393 set_fs(KERNEL_DS);
88394 ret = hrtimer_nanosleep_restart(restart);
88395 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88396 oldfs = get_fs();
88397 set_fs(KERNEL_DS);
88398 ret = hrtimer_nanosleep(&tu,
88399 - rmtp ? (struct timespec __user *)&rmt : NULL,
88400 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88401 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88402 set_fs(oldfs);
88403
88404 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88405 mm_segment_t old_fs = get_fs();
88406
88407 set_fs(KERNEL_DS);
88408 - ret = sys_sigpending((old_sigset_t __user *) &s);
88409 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88410 set_fs(old_fs);
88411 if (ret == 0)
88412 ret = put_user(s, set);
88413 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88414 mm_segment_t old_fs = get_fs();
88415
88416 set_fs(KERNEL_DS);
88417 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88418 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88419 set_fs(old_fs);
88420
88421 if (!ret) {
88422 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88423 set_fs (KERNEL_DS);
88424 ret = sys_wait4(pid,
88425 (stat_addr ?
88426 - (unsigned int __user *) &status : NULL),
88427 - options, (struct rusage __user *) &r);
88428 + (unsigned int __force_user *) &status : NULL),
88429 + options, (struct rusage __force_user *) &r);
88430 set_fs (old_fs);
88431
88432 if (ret > 0) {
88433 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88434 memset(&info, 0, sizeof(info));
88435
88436 set_fs(KERNEL_DS);
88437 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88438 - uru ? (struct rusage __user *)&ru : NULL);
88439 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88440 + uru ? (struct rusage __force_user *)&ru : NULL);
88441 set_fs(old_fs);
88442
88443 if ((ret < 0) || (info.si_signo == 0))
88444 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88445 oldfs = get_fs();
88446 set_fs(KERNEL_DS);
88447 err = sys_timer_settime(timer_id, flags,
88448 - (struct itimerspec __user *) &newts,
88449 - (struct itimerspec __user *) &oldts);
88450 + (struct itimerspec __force_user *) &newts,
88451 + (struct itimerspec __force_user *) &oldts);
88452 set_fs(oldfs);
88453 if (!err && old && put_compat_itimerspec(old, &oldts))
88454 return -EFAULT;
88455 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88456 oldfs = get_fs();
88457 set_fs(KERNEL_DS);
88458 err = sys_timer_gettime(timer_id,
88459 - (struct itimerspec __user *) &ts);
88460 + (struct itimerspec __force_user *) &ts);
88461 set_fs(oldfs);
88462 if (!err && put_compat_itimerspec(setting, &ts))
88463 return -EFAULT;
88464 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88465 oldfs = get_fs();
88466 set_fs(KERNEL_DS);
88467 err = sys_clock_settime(which_clock,
88468 - (struct timespec __user *) &ts);
88469 + (struct timespec __force_user *) &ts);
88470 set_fs(oldfs);
88471 return err;
88472 }
88473 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88474 oldfs = get_fs();
88475 set_fs(KERNEL_DS);
88476 err = sys_clock_gettime(which_clock,
88477 - (struct timespec __user *) &ts);
88478 + (struct timespec __force_user *) &ts);
88479 set_fs(oldfs);
88480 if (!err && compat_put_timespec(&ts, tp))
88481 return -EFAULT;
88482 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88483
88484 oldfs = get_fs();
88485 set_fs(KERNEL_DS);
88486 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88487 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88488 set_fs(oldfs);
88489
88490 err = compat_put_timex(utp, &txc);
88491 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88492 oldfs = get_fs();
88493 set_fs(KERNEL_DS);
88494 err = sys_clock_getres(which_clock,
88495 - (struct timespec __user *) &ts);
88496 + (struct timespec __force_user *) &ts);
88497 set_fs(oldfs);
88498 if (!err && tp && compat_put_timespec(&ts, tp))
88499 return -EFAULT;
88500 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88501 struct timespec tu;
88502 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88503
88504 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88505 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88506 oldfs = get_fs();
88507 set_fs(KERNEL_DS);
88508 err = clock_nanosleep_restart(restart);
88509 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88510 oldfs = get_fs();
88511 set_fs(KERNEL_DS);
88512 err = sys_clock_nanosleep(which_clock, flags,
88513 - (struct timespec __user *) &in,
88514 - (struct timespec __user *) &out);
88515 + (struct timespec __force_user *) &in,
88516 + (struct timespec __force_user *) &out);
88517 set_fs(oldfs);
88518
88519 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88520 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88521 mm_segment_t old_fs = get_fs();
88522
88523 set_fs(KERNEL_DS);
88524 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88525 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88526 set_fs(old_fs);
88527 if (compat_put_timespec(&t, interval))
88528 return -EFAULT;
88529 diff --git a/kernel/configs.c b/kernel/configs.c
88530 index c18b1f1..b9a0132 100644
88531 --- a/kernel/configs.c
88532 +++ b/kernel/configs.c
88533 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88534 struct proc_dir_entry *entry;
88535
88536 /* create the current config file */
88537 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88538 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88539 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88540 + &ikconfig_file_ops);
88541 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88542 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88543 + &ikconfig_file_ops);
88544 +#endif
88545 +#else
88546 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88547 &ikconfig_file_ops);
88548 +#endif
88549 +
88550 if (!entry)
88551 return -ENOMEM;
88552
88553 diff --git a/kernel/cred.c b/kernel/cred.c
88554 index e0573a4..26c0fd3 100644
88555 --- a/kernel/cred.c
88556 +++ b/kernel/cred.c
88557 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88558 validate_creds(cred);
88559 alter_cred_subscribers(cred, -1);
88560 put_cred(cred);
88561 +
88562 +#ifdef CONFIG_GRKERNSEC_SETXID
88563 + cred = (struct cred *) tsk->delayed_cred;
88564 + if (cred != NULL) {
88565 + tsk->delayed_cred = NULL;
88566 + validate_creds(cred);
88567 + alter_cred_subscribers(cred, -1);
88568 + put_cred(cred);
88569 + }
88570 +#endif
88571 }
88572
88573 /**
88574 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88575 * Always returns 0 thus allowing this function to be tail-called at the end
88576 * of, say, sys_setgid().
88577 */
88578 -int commit_creds(struct cred *new)
88579 +static int __commit_creds(struct cred *new)
88580 {
88581 struct task_struct *task = current;
88582 const struct cred *old = task->real_cred;
88583 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88584
88585 get_cred(new); /* we will require a ref for the subj creds too */
88586
88587 + gr_set_role_label(task, new->uid, new->gid);
88588 +
88589 /* dumpability changes */
88590 if (!uid_eq(old->euid, new->euid) ||
88591 !gid_eq(old->egid, new->egid) ||
88592 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88593 put_cred(old);
88594 return 0;
88595 }
88596 +#ifdef CONFIG_GRKERNSEC_SETXID
88597 +extern int set_user(struct cred *new);
88598 +
88599 +void gr_delayed_cred_worker(void)
88600 +{
88601 + const struct cred *new = current->delayed_cred;
88602 + struct cred *ncred;
88603 +
88604 + current->delayed_cred = NULL;
88605 +
88606 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88607 + // from doing get_cred on it when queueing this
88608 + put_cred(new);
88609 + return;
88610 + } else if (new == NULL)
88611 + return;
88612 +
88613 + ncred = prepare_creds();
88614 + if (!ncred)
88615 + goto die;
88616 + // uids
88617 + ncred->uid = new->uid;
88618 + ncred->euid = new->euid;
88619 + ncred->suid = new->suid;
88620 + ncred->fsuid = new->fsuid;
88621 + // gids
88622 + ncred->gid = new->gid;
88623 + ncred->egid = new->egid;
88624 + ncred->sgid = new->sgid;
88625 + ncred->fsgid = new->fsgid;
88626 + // groups
88627 + set_groups(ncred, new->group_info);
88628 + // caps
88629 + ncred->securebits = new->securebits;
88630 + ncred->cap_inheritable = new->cap_inheritable;
88631 + ncred->cap_permitted = new->cap_permitted;
88632 + ncred->cap_effective = new->cap_effective;
88633 + ncred->cap_bset = new->cap_bset;
88634 +
88635 + if (set_user(ncred)) {
88636 + abort_creds(ncred);
88637 + goto die;
88638 + }
88639 +
88640 + // from doing get_cred on it when queueing this
88641 + put_cred(new);
88642 +
88643 + __commit_creds(ncred);
88644 + return;
88645 +die:
88646 + // from doing get_cred on it when queueing this
88647 + put_cred(new);
88648 + do_group_exit(SIGKILL);
88649 +}
88650 +#endif
88651 +
88652 +int commit_creds(struct cred *new)
88653 +{
88654 +#ifdef CONFIG_GRKERNSEC_SETXID
88655 + int ret;
88656 + int schedule_it = 0;
88657 + struct task_struct *t;
88658 + unsigned oldsecurebits = current_cred()->securebits;
88659 +
88660 + /* we won't get called with tasklist_lock held for writing
88661 + and interrupts disabled as the cred struct in that case is
88662 + init_cred
88663 + */
88664 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88665 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88666 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88667 + schedule_it = 1;
88668 + }
88669 + ret = __commit_creds(new);
88670 + if (schedule_it) {
88671 + rcu_read_lock();
88672 + read_lock(&tasklist_lock);
88673 + for (t = next_thread(current); t != current;
88674 + t = next_thread(t)) {
88675 + /* we'll check if the thread has uid 0 in
88676 + * the delayed worker routine
88677 + */
88678 + if (task_securebits(t) == oldsecurebits &&
88679 + t->delayed_cred == NULL) {
88680 + t->delayed_cred = get_cred(new);
88681 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88682 + set_tsk_need_resched(t);
88683 + }
88684 + }
88685 + read_unlock(&tasklist_lock);
88686 + rcu_read_unlock();
88687 + }
88688 +
88689 + return ret;
88690 +#else
88691 + return __commit_creds(new);
88692 +#endif
88693 +}
88694 +
88695 EXPORT_SYMBOL(commit_creds);
88696
88697 /**
88698 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88699 index 1adf62b..7736e06 100644
88700 --- a/kernel/debug/debug_core.c
88701 +++ b/kernel/debug/debug_core.c
88702 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88703 */
88704 static atomic_t masters_in_kgdb;
88705 static atomic_t slaves_in_kgdb;
88706 -static atomic_t kgdb_break_tasklet_var;
88707 +static atomic_unchecked_t kgdb_break_tasklet_var;
88708 atomic_t kgdb_setting_breakpoint;
88709
88710 struct task_struct *kgdb_usethread;
88711 @@ -134,7 +134,7 @@ int kgdb_single_step;
88712 static pid_t kgdb_sstep_pid;
88713
88714 /* to keep track of the CPU which is doing the single stepping*/
88715 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88716 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88717
88718 /*
88719 * If you are debugging a problem where roundup (the collection of
88720 @@ -549,7 +549,7 @@ return_normal:
88721 * kernel will only try for the value of sstep_tries before
88722 * giving up and continuing on.
88723 */
88724 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88725 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88726 (kgdb_info[cpu].task &&
88727 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88728 atomic_set(&kgdb_active, -1);
88729 @@ -647,8 +647,8 @@ cpu_master_loop:
88730 }
88731
88732 kgdb_restore:
88733 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88734 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88735 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88736 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88737 if (kgdb_info[sstep_cpu].task)
88738 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88739 else
88740 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88741 static void kgdb_tasklet_bpt(unsigned long ing)
88742 {
88743 kgdb_breakpoint();
88744 - atomic_set(&kgdb_break_tasklet_var, 0);
88745 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88746 }
88747
88748 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88749
88750 void kgdb_schedule_breakpoint(void)
88751 {
88752 - if (atomic_read(&kgdb_break_tasklet_var) ||
88753 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88754 atomic_read(&kgdb_active) != -1 ||
88755 atomic_read(&kgdb_setting_breakpoint))
88756 return;
88757 - atomic_inc(&kgdb_break_tasklet_var);
88758 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88759 tasklet_schedule(&kgdb_tasklet_breakpoint);
88760 }
88761 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88762 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88763 index 379650b..30c5180 100644
88764 --- a/kernel/debug/kdb/kdb_main.c
88765 +++ b/kernel/debug/kdb/kdb_main.c
88766 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88767 continue;
88768
88769 kdb_printf("%-20s%8u 0x%p ", mod->name,
88770 - mod->core_size, (void *)mod);
88771 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88772 #ifdef CONFIG_MODULE_UNLOAD
88773 kdb_printf("%4ld ", module_refcount(mod));
88774 #endif
88775 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88776 kdb_printf(" (Loading)");
88777 else
88778 kdb_printf(" (Live)");
88779 - kdb_printf(" 0x%p", mod->module_core);
88780 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88781
88782 #ifdef CONFIG_MODULE_UNLOAD
88783 {
88784 diff --git a/kernel/events/core.c b/kernel/events/core.c
88785 index 658f232..32e9595 100644
88786 --- a/kernel/events/core.c
88787 +++ b/kernel/events/core.c
88788 @@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
88789 * 0 - disallow raw tracepoint access for unpriv
88790 * 1 - disallow cpu events for unpriv
88791 * 2 - disallow kernel profiling for unpriv
88792 + * 3 - disallow all unpriv perf event use
88793 */
88794 -int sysctl_perf_event_paranoid __read_mostly = 1;
88795 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88796 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88797 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88798 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88799 +#else
88800 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88801 +#endif
88802
88803 /* Minimum for 512 kiB + 1 user control page */
88804 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88805 @@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
88806
88807 tmp *= sysctl_perf_cpu_time_max_percent;
88808 do_div(tmp, 100);
88809 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88810 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88811 }
88812
88813 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88814 @@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88815 }
88816 }
88817
88818 -static atomic64_t perf_event_id;
88819 +static atomic64_unchecked_t perf_event_id;
88820
88821 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88822 enum event_type_t event_type);
88823 @@ -3051,7 +3058,7 @@ static void __perf_event_read(void *info)
88824
88825 static inline u64 perf_event_count(struct perf_event *event)
88826 {
88827 - return local64_read(&event->count) + atomic64_read(&event->child_count);
88828 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88829 }
88830
88831 static u64 perf_event_read(struct perf_event *event)
88832 @@ -3430,9 +3437,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88833 mutex_lock(&event->child_mutex);
88834 total += perf_event_read(event);
88835 *enabled += event->total_time_enabled +
88836 - atomic64_read(&event->child_total_time_enabled);
88837 + atomic64_read_unchecked(&event->child_total_time_enabled);
88838 *running += event->total_time_running +
88839 - atomic64_read(&event->child_total_time_running);
88840 + atomic64_read_unchecked(&event->child_total_time_running);
88841
88842 list_for_each_entry(child, &event->child_list, child_list) {
88843 total += perf_event_read(child);
88844 @@ -3881,10 +3888,10 @@ void perf_event_update_userpage(struct perf_event *event)
88845 userpg->offset -= local64_read(&event->hw.prev_count);
88846
88847 userpg->time_enabled = enabled +
88848 - atomic64_read(&event->child_total_time_enabled);
88849 + atomic64_read_unchecked(&event->child_total_time_enabled);
88850
88851 userpg->time_running = running +
88852 - atomic64_read(&event->child_total_time_running);
88853 + atomic64_read_unchecked(&event->child_total_time_running);
88854
88855 arch_perf_update_userpage(userpg, now);
88856
88857 @@ -4448,7 +4455,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88858
88859 /* Data. */
88860 sp = perf_user_stack_pointer(regs);
88861 - rem = __output_copy_user(handle, (void *) sp, dump_size);
88862 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88863 dyn_size = dump_size - rem;
88864
88865 perf_output_skip(handle, rem);
88866 @@ -4539,11 +4546,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88867 values[n++] = perf_event_count(event);
88868 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88869 values[n++] = enabled +
88870 - atomic64_read(&event->child_total_time_enabled);
88871 + atomic64_read_unchecked(&event->child_total_time_enabled);
88872 }
88873 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
88874 values[n++] = running +
88875 - atomic64_read(&event->child_total_time_running);
88876 + atomic64_read_unchecked(&event->child_total_time_running);
88877 }
88878 if (read_format & PERF_FORMAT_ID)
88879 values[n++] = primary_event_id(event);
88880 @@ -6858,7 +6865,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
88881 event->parent = parent_event;
88882
88883 event->ns = get_pid_ns(task_active_pid_ns(current));
88884 - event->id = atomic64_inc_return(&perf_event_id);
88885 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
88886
88887 event->state = PERF_EVENT_STATE_INACTIVE;
88888
88889 @@ -7137,6 +7144,11 @@ SYSCALL_DEFINE5(perf_event_open,
88890 if (flags & ~PERF_FLAG_ALL)
88891 return -EINVAL;
88892
88893 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88894 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
88895 + return -EACCES;
88896 +#endif
88897 +
88898 err = perf_copy_attr(attr_uptr, &attr);
88899 if (err)
88900 return err;
88901 @@ -7489,10 +7501,10 @@ static void sync_child_event(struct perf_event *child_event,
88902 /*
88903 * Add back the child's count to the parent's count:
88904 */
88905 - atomic64_add(child_val, &parent_event->child_count);
88906 - atomic64_add(child_event->total_time_enabled,
88907 + atomic64_add_unchecked(child_val, &parent_event->child_count);
88908 + atomic64_add_unchecked(child_event->total_time_enabled,
88909 &parent_event->child_total_time_enabled);
88910 - atomic64_add(child_event->total_time_running,
88911 + atomic64_add_unchecked(child_event->total_time_running,
88912 &parent_event->child_total_time_running);
88913
88914 /*
88915 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
88916 index 569b2187..19940d9 100644
88917 --- a/kernel/events/internal.h
88918 +++ b/kernel/events/internal.h
88919 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
88920 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
88921 }
88922
88923 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
88924 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
88925 static inline unsigned long \
88926 func_name(struct perf_output_handle *handle, \
88927 - const void *buf, unsigned long len) \
88928 + const void user *buf, unsigned long len) \
88929 { \
88930 unsigned long size, written; \
88931 \
88932 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
88933 return 0;
88934 }
88935
88936 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
88937 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
88938
88939 static inline unsigned long
88940 memcpy_skip(void *dst, const void *src, unsigned long n)
88941 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
88942 return 0;
88943 }
88944
88945 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
88946 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
88947
88948 #ifndef arch_perf_out_copy_user
88949 #define arch_perf_out_copy_user arch_perf_out_copy_user
88950 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
88951 }
88952 #endif
88953
88954 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
88955 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
88956
88957 /* Callchain handling */
88958 extern struct perf_callchain_entry *
88959 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
88960 index 1d0af8a..9913530 100644
88961 --- a/kernel/events/uprobes.c
88962 +++ b/kernel/events/uprobes.c
88963 @@ -1671,7 +1671,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
88964 {
88965 struct page *page;
88966 uprobe_opcode_t opcode;
88967 - int result;
88968 + long result;
88969
88970 pagefault_disable();
88971 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
88972 diff --git a/kernel/exit.c b/kernel/exit.c
88973 index 32c58f7..9eb6907 100644
88974 --- a/kernel/exit.c
88975 +++ b/kernel/exit.c
88976 @@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
88977 struct task_struct *leader;
88978 int zap_leader;
88979 repeat:
88980 +#ifdef CONFIG_NET
88981 + gr_del_task_from_ip_table(p);
88982 +#endif
88983 +
88984 /* don't need to get the RCU readlock here - the process is dead and
88985 * can't be modifying its own credentials. But shut RCU-lockdep up */
88986 rcu_read_lock();
88987 @@ -668,6 +672,8 @@ void do_exit(long code)
88988 struct task_struct *tsk = current;
88989 int group_dead;
88990
88991 + set_fs(USER_DS);
88992 +
88993 profile_task_exit(tsk);
88994
88995 WARN_ON(blk_needs_flush_plug(tsk));
88996 @@ -684,7 +690,6 @@ void do_exit(long code)
88997 * mm_release()->clear_child_tid() from writing to a user-controlled
88998 * kernel address.
88999 */
89000 - set_fs(USER_DS);
89001
89002 ptrace_event(PTRACE_EVENT_EXIT, code);
89003
89004 @@ -742,6 +747,9 @@ void do_exit(long code)
89005 tsk->exit_code = code;
89006 taskstats_exit(tsk, group_dead);
89007
89008 + gr_acl_handle_psacct(tsk, code);
89009 + gr_acl_handle_exit();
89010 +
89011 exit_mm(tsk);
89012
89013 if (group_dead)
89014 @@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89015 * Take down every thread in the group. This is called by fatal signals
89016 * as well as by sys_exit_group (below).
89017 */
89018 -void
89019 +__noreturn void
89020 do_group_exit(int exit_code)
89021 {
89022 struct signal_struct *sig = current->signal;
89023 diff --git a/kernel/fork.c b/kernel/fork.c
89024 index a91e47d..71c9064 100644
89025 --- a/kernel/fork.c
89026 +++ b/kernel/fork.c
89027 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89028 # endif
89029 #endif
89030
89031 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89032 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89033 + int node, void **lowmem_stack)
89034 +{
89035 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89036 + void *ret = NULL;
89037 + unsigned int i;
89038 +
89039 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89040 + if (*lowmem_stack == NULL)
89041 + goto out;
89042 +
89043 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89044 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89045 +
89046 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89047 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89048 + if (ret == NULL) {
89049 + free_thread_info(*lowmem_stack);
89050 + *lowmem_stack = NULL;
89051 + }
89052 +
89053 +out:
89054 + return ret;
89055 +}
89056 +
89057 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89058 +{
89059 + unmap_process_stacks(tsk);
89060 +}
89061 +#else
89062 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89063 + int node, void **lowmem_stack)
89064 +{
89065 + return alloc_thread_info_node(tsk, node);
89066 +}
89067 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89068 +{
89069 + free_thread_info(ti);
89070 +}
89071 +#endif
89072 +
89073 /* SLAB cache for signal_struct structures (tsk->signal) */
89074 static struct kmem_cache *signal_cachep;
89075
89076 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89077 /* SLAB cache for mm_struct structures (tsk->mm) */
89078 static struct kmem_cache *mm_cachep;
89079
89080 -static void account_kernel_stack(struct thread_info *ti, int account)
89081 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89082 {
89083 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89084 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89085 +#else
89086 struct zone *zone = page_zone(virt_to_page(ti));
89087 +#endif
89088
89089 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89090 }
89091
89092 void free_task(struct task_struct *tsk)
89093 {
89094 - account_kernel_stack(tsk->stack, -1);
89095 + account_kernel_stack(tsk, tsk->stack, -1);
89096 arch_release_thread_info(tsk->stack);
89097 - free_thread_info(tsk->stack);
89098 + gr_free_thread_info(tsk, tsk->stack);
89099 rt_mutex_debug_task_free(tsk);
89100 ftrace_graph_exit_task(tsk);
89101 put_seccomp_filter(tsk);
89102 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89103 struct task_struct *tsk;
89104 struct thread_info *ti;
89105 unsigned long *stackend;
89106 + void *lowmem_stack;
89107 int node = tsk_fork_get_node(orig);
89108 int err;
89109
89110 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89111 if (!tsk)
89112 return NULL;
89113
89114 - ti = alloc_thread_info_node(tsk, node);
89115 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89116 if (!ti)
89117 goto free_tsk;
89118
89119 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89120 goto free_ti;
89121
89122 tsk->stack = ti;
89123 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89124 + tsk->lowmem_stack = lowmem_stack;
89125 +#endif
89126 #ifdef CONFIG_SECCOMP
89127 /*
89128 * We must handle setting up seccomp filters once we're under
89129 @@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89130 *stackend = STACK_END_MAGIC; /* for overflow detection */
89131
89132 #ifdef CONFIG_CC_STACKPROTECTOR
89133 - tsk->stack_canary = get_random_int();
89134 + tsk->stack_canary = pax_get_random_long();
89135 #endif
89136
89137 /*
89138 @@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89139 tsk->splice_pipe = NULL;
89140 tsk->task_frag.page = NULL;
89141
89142 - account_kernel_stack(ti, 1);
89143 + account_kernel_stack(tsk, ti, 1);
89144
89145 return tsk;
89146
89147 free_ti:
89148 - free_thread_info(ti);
89149 + gr_free_thread_info(tsk, ti);
89150 free_tsk:
89151 free_task_struct(tsk);
89152 return NULL;
89153 }
89154
89155 #ifdef CONFIG_MMU
89156 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89157 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89158 +{
89159 + struct vm_area_struct *tmp;
89160 + unsigned long charge;
89161 + struct file *file;
89162 + int retval;
89163 +
89164 + charge = 0;
89165 + if (mpnt->vm_flags & VM_ACCOUNT) {
89166 + unsigned long len = vma_pages(mpnt);
89167 +
89168 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89169 + goto fail_nomem;
89170 + charge = len;
89171 + }
89172 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89173 + if (!tmp)
89174 + goto fail_nomem;
89175 + *tmp = *mpnt;
89176 + tmp->vm_mm = mm;
89177 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89178 + retval = vma_dup_policy(mpnt, tmp);
89179 + if (retval)
89180 + goto fail_nomem_policy;
89181 + if (anon_vma_fork(tmp, mpnt))
89182 + goto fail_nomem_anon_vma_fork;
89183 + tmp->vm_flags &= ~VM_LOCKED;
89184 + tmp->vm_next = tmp->vm_prev = NULL;
89185 + tmp->vm_mirror = NULL;
89186 + file = tmp->vm_file;
89187 + if (file) {
89188 + struct inode *inode = file_inode(file);
89189 + struct address_space *mapping = file->f_mapping;
89190 +
89191 + get_file(file);
89192 + if (tmp->vm_flags & VM_DENYWRITE)
89193 + atomic_dec(&inode->i_writecount);
89194 + mutex_lock(&mapping->i_mmap_mutex);
89195 + if (tmp->vm_flags & VM_SHARED)
89196 + atomic_inc(&mapping->i_mmap_writable);
89197 + flush_dcache_mmap_lock(mapping);
89198 + /* insert tmp into the share list, just after mpnt */
89199 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89200 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89201 + else
89202 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89203 + flush_dcache_mmap_unlock(mapping);
89204 + mutex_unlock(&mapping->i_mmap_mutex);
89205 + }
89206 +
89207 + /*
89208 + * Clear hugetlb-related page reserves for children. This only
89209 + * affects MAP_PRIVATE mappings. Faults generated by the child
89210 + * are not guaranteed to succeed, even if read-only
89211 + */
89212 + if (is_vm_hugetlb_page(tmp))
89213 + reset_vma_resv_huge_pages(tmp);
89214 +
89215 + return tmp;
89216 +
89217 +fail_nomem_anon_vma_fork:
89218 + mpol_put(vma_policy(tmp));
89219 +fail_nomem_policy:
89220 + kmem_cache_free(vm_area_cachep, tmp);
89221 +fail_nomem:
89222 + vm_unacct_memory(charge);
89223 + return NULL;
89224 +}
89225 +
89226 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89227 {
89228 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89229 struct rb_node **rb_link, *rb_parent;
89230 int retval;
89231 - unsigned long charge;
89232
89233 uprobe_start_dup_mmap();
89234 down_write(&oldmm->mmap_sem);
89235 @@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89236
89237 prev = NULL;
89238 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89239 - struct file *file;
89240 -
89241 if (mpnt->vm_flags & VM_DONTCOPY) {
89242 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89243 -vma_pages(mpnt));
89244 continue;
89245 }
89246 - charge = 0;
89247 - if (mpnt->vm_flags & VM_ACCOUNT) {
89248 - unsigned long len = vma_pages(mpnt);
89249 -
89250 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89251 - goto fail_nomem;
89252 - charge = len;
89253 - }
89254 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89255 - if (!tmp)
89256 - goto fail_nomem;
89257 - *tmp = *mpnt;
89258 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89259 - retval = vma_dup_policy(mpnt, tmp);
89260 - if (retval)
89261 - goto fail_nomem_policy;
89262 - tmp->vm_mm = mm;
89263 - if (anon_vma_fork(tmp, mpnt))
89264 - goto fail_nomem_anon_vma_fork;
89265 - tmp->vm_flags &= ~VM_LOCKED;
89266 - tmp->vm_next = tmp->vm_prev = NULL;
89267 - file = tmp->vm_file;
89268 - if (file) {
89269 - struct inode *inode = file_inode(file);
89270 - struct address_space *mapping = file->f_mapping;
89271 -
89272 - get_file(file);
89273 - if (tmp->vm_flags & VM_DENYWRITE)
89274 - atomic_dec(&inode->i_writecount);
89275 - mutex_lock(&mapping->i_mmap_mutex);
89276 - if (tmp->vm_flags & VM_SHARED)
89277 - atomic_inc(&mapping->i_mmap_writable);
89278 - flush_dcache_mmap_lock(mapping);
89279 - /* insert tmp into the share list, just after mpnt */
89280 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89281 - vma_nonlinear_insert(tmp,
89282 - &mapping->i_mmap_nonlinear);
89283 - else
89284 - vma_interval_tree_insert_after(tmp, mpnt,
89285 - &mapping->i_mmap);
89286 - flush_dcache_mmap_unlock(mapping);
89287 - mutex_unlock(&mapping->i_mmap_mutex);
89288 + tmp = dup_vma(mm, oldmm, mpnt);
89289 + if (!tmp) {
89290 + retval = -ENOMEM;
89291 + goto out;
89292 }
89293
89294 /*
89295 @@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89296 if (retval)
89297 goto out;
89298 }
89299 +
89300 +#ifdef CONFIG_PAX_SEGMEXEC
89301 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89302 + struct vm_area_struct *mpnt_m;
89303 +
89304 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89305 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89306 +
89307 + if (!mpnt->vm_mirror)
89308 + continue;
89309 +
89310 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89311 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89312 + mpnt->vm_mirror = mpnt_m;
89313 + } else {
89314 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89315 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89316 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89317 + mpnt->vm_mirror->vm_mirror = mpnt;
89318 + }
89319 + }
89320 + BUG_ON(mpnt_m);
89321 + }
89322 +#endif
89323 +
89324 /* a new mm has just been created */
89325 arch_dup_mmap(oldmm, mm);
89326 retval = 0;
89327 @@ -480,14 +583,6 @@ out:
89328 up_write(&oldmm->mmap_sem);
89329 uprobe_end_dup_mmap();
89330 return retval;
89331 -fail_nomem_anon_vma_fork:
89332 - mpol_put(vma_policy(tmp));
89333 -fail_nomem_policy:
89334 - kmem_cache_free(vm_area_cachep, tmp);
89335 -fail_nomem:
89336 - retval = -ENOMEM;
89337 - vm_unacct_memory(charge);
89338 - goto out;
89339 }
89340
89341 static inline int mm_alloc_pgd(struct mm_struct *mm)
89342 @@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89343 return ERR_PTR(err);
89344
89345 mm = get_task_mm(task);
89346 - if (mm && mm != current->mm &&
89347 - !ptrace_may_access(task, mode)) {
89348 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89349 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89350 mmput(mm);
89351 mm = ERR_PTR(-EACCES);
89352 }
89353 @@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89354 spin_unlock(&fs->lock);
89355 return -EAGAIN;
89356 }
89357 - fs->users++;
89358 + atomic_inc(&fs->users);
89359 spin_unlock(&fs->lock);
89360 return 0;
89361 }
89362 tsk->fs = copy_fs_struct(fs);
89363 if (!tsk->fs)
89364 return -ENOMEM;
89365 + /* Carry through gr_chroot_dentry and is_chrooted instead
89366 + of recomputing it here. Already copied when the task struct
89367 + is duplicated. This allows pivot_root to not be treated as
89368 + a chroot
89369 + */
89370 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89371 +
89372 return 0;
89373 }
89374
89375 @@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89376 * parts of the process environment (as per the clone
89377 * flags). The actual kick-off is left to the caller.
89378 */
89379 -static struct task_struct *copy_process(unsigned long clone_flags,
89380 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89381 unsigned long stack_start,
89382 unsigned long stack_size,
89383 int __user *child_tidptr,
89384 @@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89385 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89386 #endif
89387 retval = -EAGAIN;
89388 +
89389 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89390 +
89391 if (atomic_read(&p->real_cred->user->processes) >=
89392 task_rlimit(p, RLIMIT_NPROC)) {
89393 if (p->real_cred->user != INIT_USER &&
89394 @@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89395 goto bad_fork_free_pid;
89396 }
89397
89398 + /* synchronizes with gr_set_acls()
89399 + we need to call this past the point of no return for fork()
89400 + */
89401 + gr_copy_label(p);
89402 +
89403 if (likely(p->pid)) {
89404 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89405
89406 @@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
89407 bad_fork_free:
89408 free_task(p);
89409 fork_out:
89410 + gr_log_forkfail(retval);
89411 +
89412 return ERR_PTR(retval);
89413 }
89414
89415 @@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
89416
89417 p = copy_process(clone_flags, stack_start, stack_size,
89418 child_tidptr, NULL, trace);
89419 + add_latent_entropy();
89420 /*
89421 * Do this prior waking up the new thread - the thread pointer
89422 * might get invalid after that point, if the thread exits quickly.
89423 @@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
89424 if (clone_flags & CLONE_PARENT_SETTID)
89425 put_user(nr, parent_tidptr);
89426
89427 + gr_handle_brute_check();
89428 +
89429 if (clone_flags & CLONE_VFORK) {
89430 p->vfork_done = &vfork;
89431 init_completion(&vfork);
89432 @@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
89433 mm_cachep = kmem_cache_create("mm_struct",
89434 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89435 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89436 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89437 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89438 mmap_init();
89439 nsproxy_cache_init();
89440 }
89441 @@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89442 return 0;
89443
89444 /* don't need lock here; in the worst case we'll do useless copy */
89445 - if (fs->users == 1)
89446 + if (atomic_read(&fs->users) == 1)
89447 return 0;
89448
89449 *new_fsp = copy_fs_struct(fs);
89450 @@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89451 fs = current->fs;
89452 spin_lock(&fs->lock);
89453 current->fs = new_fs;
89454 - if (--fs->users)
89455 + gr_set_chroot_entries(current, &current->fs->root);
89456 + if (atomic_dec_return(&fs->users))
89457 new_fs = NULL;
89458 else
89459 new_fs = fs;
89460 diff --git a/kernel/futex.c b/kernel/futex.c
89461 index 22b3f1b..6820bc0 100644
89462 --- a/kernel/futex.c
89463 +++ b/kernel/futex.c
89464 @@ -202,7 +202,7 @@ struct futex_pi_state {
89465 atomic_t refcount;
89466
89467 union futex_key key;
89468 -};
89469 +} __randomize_layout;
89470
89471 /**
89472 * struct futex_q - The hashed futex queue entry, one per waiting task
89473 @@ -236,7 +236,7 @@ struct futex_q {
89474 struct rt_mutex_waiter *rt_waiter;
89475 union futex_key *requeue_pi_key;
89476 u32 bitset;
89477 -};
89478 +} __randomize_layout;
89479
89480 static const struct futex_q futex_q_init = {
89481 /* list gets initialized in queue_me()*/
89482 @@ -396,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89483 struct page *page, *page_head;
89484 int err, ro = 0;
89485
89486 +#ifdef CONFIG_PAX_SEGMEXEC
89487 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89488 + return -EFAULT;
89489 +#endif
89490 +
89491 /*
89492 * The futex address must be "naturally" aligned.
89493 */
89494 @@ -595,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89495
89496 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89497 {
89498 - int ret;
89499 + unsigned long ret;
89500
89501 pagefault_disable();
89502 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89503 @@ -3000,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
89504 {
89505 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89506 u32 curval;
89507 + mm_segment_t oldfs;
89508
89509 /*
89510 * This will fail and we want it. Some arch implementations do
89511 @@ -3011,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
89512 * implementation, the non-functional ones will return
89513 * -ENOSYS.
89514 */
89515 + oldfs = get_fs();
89516 + set_fs(USER_DS);
89517 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89518 futex_cmpxchg_enabled = 1;
89519 + set_fs(oldfs);
89520 #endif
89521 }
89522
89523 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89524 index 55c8c93..9ba7ad6 100644
89525 --- a/kernel/futex_compat.c
89526 +++ b/kernel/futex_compat.c
89527 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89528 return 0;
89529 }
89530
89531 -static void __user *futex_uaddr(struct robust_list __user *entry,
89532 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89533 compat_long_t futex_offset)
89534 {
89535 compat_uptr_t base = ptr_to_compat(entry);
89536 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89537 index b358a80..fc25240 100644
89538 --- a/kernel/gcov/base.c
89539 +++ b/kernel/gcov/base.c
89540 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89541 }
89542
89543 #ifdef CONFIG_MODULES
89544 -static inline int within(void *addr, void *start, unsigned long size)
89545 -{
89546 - return ((addr >= start) && (addr < start + size));
89547 -}
89548 -
89549 /* Update list and generate events when modules are unloaded. */
89550 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89551 void *data)
89552 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89553
89554 /* Remove entries located in module from linked list. */
89555 while ((info = gcov_info_next(info))) {
89556 - if (within(info, mod->module_core, mod->core_size)) {
89557 + if (within_module_core_rw((unsigned long)info, mod)) {
89558 gcov_info_unlink(prev, info);
89559 if (gcov_events_enabled)
89560 gcov_event(GCOV_REMOVE, info);
89561 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89562 index 9019f15..9a3c42e 100644
89563 --- a/kernel/jump_label.c
89564 +++ b/kernel/jump_label.c
89565 @@ -14,6 +14,7 @@
89566 #include <linux/err.h>
89567 #include <linux/static_key.h>
89568 #include <linux/jump_label_ratelimit.h>
89569 +#include <linux/mm.h>
89570
89571 #ifdef HAVE_JUMP_LABEL
89572
89573 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89574
89575 size = (((unsigned long)stop - (unsigned long)start)
89576 / sizeof(struct jump_entry));
89577 + pax_open_kernel();
89578 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89579 + pax_close_kernel();
89580 }
89581
89582 static void jump_label_update(struct static_key *key, int enable);
89583 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89584 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89585 struct jump_entry *iter;
89586
89587 + pax_open_kernel();
89588 for (iter = iter_start; iter < iter_stop; iter++) {
89589 if (within_module_init(iter->code, mod))
89590 iter->code = 0;
89591 }
89592 + pax_close_kernel();
89593 }
89594
89595 static int
89596 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89597 index ae51670..c1a9796 100644
89598 --- a/kernel/kallsyms.c
89599 +++ b/kernel/kallsyms.c
89600 @@ -11,6 +11,9 @@
89601 * Changed the compression method from stem compression to "table lookup"
89602 * compression (see scripts/kallsyms.c for a more complete description)
89603 */
89604 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89605 +#define __INCLUDED_BY_HIDESYM 1
89606 +#endif
89607 #include <linux/kallsyms.h>
89608 #include <linux/module.h>
89609 #include <linux/init.h>
89610 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89611
89612 static inline int is_kernel_inittext(unsigned long addr)
89613 {
89614 + if (system_state != SYSTEM_BOOTING)
89615 + return 0;
89616 +
89617 if (addr >= (unsigned long)_sinittext
89618 && addr <= (unsigned long)_einittext)
89619 return 1;
89620 return 0;
89621 }
89622
89623 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89624 +#ifdef CONFIG_MODULES
89625 +static inline int is_module_text(unsigned long addr)
89626 +{
89627 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89628 + return 1;
89629 +
89630 + addr = ktla_ktva(addr);
89631 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89632 +}
89633 +#else
89634 +static inline int is_module_text(unsigned long addr)
89635 +{
89636 + return 0;
89637 +}
89638 +#endif
89639 +#endif
89640 +
89641 static inline int is_kernel_text(unsigned long addr)
89642 {
89643 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89644 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89645
89646 static inline int is_kernel(unsigned long addr)
89647 {
89648 +
89649 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89650 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89651 + return 1;
89652 +
89653 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89654 +#else
89655 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89656 +#endif
89657 +
89658 return 1;
89659 return in_gate_area_no_mm(addr);
89660 }
89661
89662 static int is_ksym_addr(unsigned long addr)
89663 {
89664 +
89665 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89666 + if (is_module_text(addr))
89667 + return 0;
89668 +#endif
89669 +
89670 if (all_var)
89671 return is_kernel(addr);
89672
89673 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89674
89675 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89676 {
89677 - iter->name[0] = '\0';
89678 iter->nameoff = get_symbol_offset(new_pos);
89679 iter->pos = new_pos;
89680 }
89681 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89682 {
89683 struct kallsym_iter *iter = m->private;
89684
89685 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89686 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89687 + return 0;
89688 +#endif
89689 +
89690 /* Some debugging symbols have no name. Ignore them. */
89691 if (!iter->name[0])
89692 return 0;
89693 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89694 */
89695 type = iter->exported ? toupper(iter->type) :
89696 tolower(iter->type);
89697 +
89698 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89699 type, iter->name, iter->module_name);
89700 } else
89701 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
89702 struct kallsym_iter *iter;
89703 int ret;
89704
89705 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
89706 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
89707 if (!iter)
89708 return -ENOMEM;
89709 reset_iter(iter, 0);
89710 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89711 index 0aa69ea..a7fcafb 100644
89712 --- a/kernel/kcmp.c
89713 +++ b/kernel/kcmp.c
89714 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89715 struct task_struct *task1, *task2;
89716 int ret;
89717
89718 +#ifdef CONFIG_GRKERNSEC
89719 + return -ENOSYS;
89720 +#endif
89721 +
89722 rcu_read_lock();
89723
89724 /*
89725 diff --git a/kernel/kexec.c b/kernel/kexec.c
89726 index 2bee072..8979af8 100644
89727 --- a/kernel/kexec.c
89728 +++ b/kernel/kexec.c
89729 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89730 compat_ulong_t, flags)
89731 {
89732 struct compat_kexec_segment in;
89733 - struct kexec_segment out, __user *ksegments;
89734 + struct kexec_segment out;
89735 + struct kexec_segment __user *ksegments;
89736 unsigned long i, result;
89737
89738 /* Don't allow clients that don't understand the native
89739 diff --git a/kernel/kmod.c b/kernel/kmod.c
89740 index 8637e04..8b1d0d8 100644
89741 --- a/kernel/kmod.c
89742 +++ b/kernel/kmod.c
89743 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89744 kfree(info->argv);
89745 }
89746
89747 -static int call_modprobe(char *module_name, int wait)
89748 +static int call_modprobe(char *module_name, char *module_param, int wait)
89749 {
89750 struct subprocess_info *info;
89751 static char *envp[] = {
89752 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89753 NULL
89754 };
89755
89756 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89757 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89758 if (!argv)
89759 goto out;
89760
89761 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89762 argv[1] = "-q";
89763 argv[2] = "--";
89764 argv[3] = module_name; /* check free_modprobe_argv() */
89765 - argv[4] = NULL;
89766 + argv[4] = module_param;
89767 + argv[5] = NULL;
89768
89769 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89770 NULL, free_modprobe_argv, NULL);
89771 @@ -129,9 +130,8 @@ out:
89772 * If module auto-loading support is disabled then this function
89773 * becomes a no-operation.
89774 */
89775 -int __request_module(bool wait, const char *fmt, ...)
89776 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89777 {
89778 - va_list args;
89779 char module_name[MODULE_NAME_LEN];
89780 unsigned int max_modprobes;
89781 int ret;
89782 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89783 if (!modprobe_path[0])
89784 return 0;
89785
89786 - va_start(args, fmt);
89787 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89788 - va_end(args);
89789 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89790 if (ret >= MODULE_NAME_LEN)
89791 return -ENAMETOOLONG;
89792
89793 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89794 if (ret)
89795 return ret;
89796
89797 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89798 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89799 + /* hack to workaround consolekit/udisks stupidity */
89800 + read_lock(&tasklist_lock);
89801 + if (!strcmp(current->comm, "mount") &&
89802 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89803 + read_unlock(&tasklist_lock);
89804 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89805 + return -EPERM;
89806 + }
89807 + read_unlock(&tasklist_lock);
89808 + }
89809 +#endif
89810 +
89811 /* If modprobe needs a service that is in a module, we get a recursive
89812 * loop. Limit the number of running kmod threads to max_threads/2 or
89813 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89814 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
89815
89816 trace_module_request(module_name, wait, _RET_IP_);
89817
89818 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89819 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89820
89821 atomic_dec(&kmod_concurrent);
89822 return ret;
89823 }
89824 +
89825 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89826 +{
89827 + va_list args;
89828 + int ret;
89829 +
89830 + va_start(args, fmt);
89831 + ret = ____request_module(wait, module_param, fmt, args);
89832 + va_end(args);
89833 +
89834 + return ret;
89835 +}
89836 +
89837 +int __request_module(bool wait, const char *fmt, ...)
89838 +{
89839 + va_list args;
89840 + int ret;
89841 +
89842 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89843 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89844 + char module_param[MODULE_NAME_LEN];
89845 +
89846 + memset(module_param, 0, sizeof(module_param));
89847 +
89848 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89849 +
89850 + va_start(args, fmt);
89851 + ret = ____request_module(wait, module_param, fmt, args);
89852 + va_end(args);
89853 +
89854 + return ret;
89855 + }
89856 +#endif
89857 +
89858 + va_start(args, fmt);
89859 + ret = ____request_module(wait, NULL, fmt, args);
89860 + va_end(args);
89861 +
89862 + return ret;
89863 +}
89864 +
89865 EXPORT_SYMBOL(__request_module);
89866 #endif /* CONFIG_MODULES */
89867
89868 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
89869 */
89870 set_user_nice(current, 0);
89871
89872 +#ifdef CONFIG_GRKERNSEC
89873 + /* this is race-free as far as userland is concerned as we copied
89874 + out the path to be used prior to this point and are now operating
89875 + on that copy
89876 + */
89877 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
89878 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
89879 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
89880 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
89881 + retval = -EPERM;
89882 + goto fail;
89883 + }
89884 +#endif
89885 +
89886 retval = -ENOMEM;
89887 new = prepare_kernel_cred(current);
89888 if (!new)
89889 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
89890 commit_creds(new);
89891
89892 retval = do_execve(getname_kernel(sub_info->path),
89893 - (const char __user *const __user *)sub_info->argv,
89894 - (const char __user *const __user *)sub_info->envp);
89895 + (const char __user *const __force_user *)sub_info->argv,
89896 + (const char __user *const __force_user *)sub_info->envp);
89897 if (!retval)
89898 return 0;
89899
89900 @@ -260,6 +327,10 @@ static int call_helper(void *data)
89901
89902 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89903 {
89904 +#ifdef CONFIG_GRKERNSEC
89905 + kfree(info->path);
89906 + info->path = info->origpath;
89907 +#endif
89908 if (info->cleanup)
89909 (*info->cleanup)(info);
89910 kfree(info);
89911 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
89912 *
89913 * Thus the __user pointer cast is valid here.
89914 */
89915 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
89916 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
89917
89918 /*
89919 * If ret is 0, either ____call_usermodehelper failed and the
89920 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
89921 goto out;
89922
89923 INIT_WORK(&sub_info->work, __call_usermodehelper);
89924 +#ifdef CONFIG_GRKERNSEC
89925 + sub_info->origpath = path;
89926 + sub_info->path = kstrdup(path, gfp_mask);
89927 +#else
89928 sub_info->path = path;
89929 +#endif
89930 sub_info->argv = argv;
89931 sub_info->envp = envp;
89932
89933 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
89934 static int proc_cap_handler(struct ctl_table *table, int write,
89935 void __user *buffer, size_t *lenp, loff_t *ppos)
89936 {
89937 - struct ctl_table t;
89938 + ctl_table_no_const t;
89939 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
89940 kernel_cap_t new_cap;
89941 int err, i;
89942 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
89943 index 3995f54..e247879 100644
89944 --- a/kernel/kprobes.c
89945 +++ b/kernel/kprobes.c
89946 @@ -31,6 +31,9 @@
89947 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
89948 * <prasanna@in.ibm.com> added function-return probes.
89949 */
89950 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89951 +#define __INCLUDED_BY_HIDESYM 1
89952 +#endif
89953 #include <linux/kprobes.h>
89954 #include <linux/hash.h>
89955 #include <linux/init.h>
89956 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
89957
89958 static void *alloc_insn_page(void)
89959 {
89960 - return module_alloc(PAGE_SIZE);
89961 + return module_alloc_exec(PAGE_SIZE);
89962 }
89963
89964 static void free_insn_page(void *page)
89965 {
89966 - module_free(NULL, page);
89967 + module_free_exec(NULL, page);
89968 }
89969
89970 struct kprobe_insn_cache kprobe_insn_slots = {
89971 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
89972 kprobe_type = "k";
89973
89974 if (sym)
89975 - seq_printf(pi, "%p %s %s+0x%x %s ",
89976 + seq_printf(pi, "%pK %s %s+0x%x %s ",
89977 p->addr, kprobe_type, sym, offset,
89978 (modname ? modname : " "));
89979 else
89980 - seq_printf(pi, "%p %s %p ",
89981 + seq_printf(pi, "%pK %s %pK ",
89982 p->addr, kprobe_type, p->addr);
89983
89984 if (!pp)
89985 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
89986 index 6683cce..daf8999 100644
89987 --- a/kernel/ksysfs.c
89988 +++ b/kernel/ksysfs.c
89989 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
89990 {
89991 if (count+1 > UEVENT_HELPER_PATH_LEN)
89992 return -ENOENT;
89993 + if (!capable(CAP_SYS_ADMIN))
89994 + return -EPERM;
89995 memcpy(uevent_helper, buf, count);
89996 uevent_helper[count] = '\0';
89997 if (count && uevent_helper[count-1] == '\n')
89998 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
89999 return count;
90000 }
90001
90002 -static struct bin_attribute notes_attr = {
90003 +static bin_attribute_no_const notes_attr __read_only = {
90004 .attr = {
90005 .name = "notes",
90006 .mode = S_IRUGO,
90007 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90008 index 88d0d44..e9ce0ee 100644
90009 --- a/kernel/locking/lockdep.c
90010 +++ b/kernel/locking/lockdep.c
90011 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90012 end = (unsigned long) &_end,
90013 addr = (unsigned long) obj;
90014
90015 +#ifdef CONFIG_PAX_KERNEXEC
90016 + start = ktla_ktva(start);
90017 +#endif
90018 +
90019 /*
90020 * static variable?
90021 */
90022 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90023 if (!static_obj(lock->key)) {
90024 debug_locks_off();
90025 printk("INFO: trying to register non-static key.\n");
90026 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90027 printk("the code is fine but needs lockdep annotation.\n");
90028 printk("turning off the locking correctness validator.\n");
90029 dump_stack();
90030 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90031 if (!class)
90032 return 0;
90033 }
90034 - atomic_inc((atomic_t *)&class->ops);
90035 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90036 if (very_verbose(class)) {
90037 printk("\nacquire class [%p] %s", class->key, class->name);
90038 if (class->name_version > 1)
90039 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90040 index ef43ac4..2720dfa 100644
90041 --- a/kernel/locking/lockdep_proc.c
90042 +++ b/kernel/locking/lockdep_proc.c
90043 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90044 return 0;
90045 }
90046
90047 - seq_printf(m, "%p", class->key);
90048 + seq_printf(m, "%pK", class->key);
90049 #ifdef CONFIG_DEBUG_LOCKDEP
90050 seq_printf(m, " OPS:%8ld", class->ops);
90051 #endif
90052 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90053
90054 list_for_each_entry(entry, &class->locks_after, entry) {
90055 if (entry->distance == 1) {
90056 - seq_printf(m, " -> [%p] ", entry->class->key);
90057 + seq_printf(m, " -> [%pK] ", entry->class->key);
90058 print_name(m, entry->class);
90059 seq_puts(m, "\n");
90060 }
90061 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90062 if (!class->key)
90063 continue;
90064
90065 - seq_printf(m, "[%p] ", class->key);
90066 + seq_printf(m, "[%pK] ", class->key);
90067 print_name(m, class);
90068 seq_puts(m, "\n");
90069 }
90070 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90071 if (!i)
90072 seq_line(m, '-', 40-namelen, namelen);
90073
90074 - snprintf(ip, sizeof(ip), "[<%p>]",
90075 + snprintf(ip, sizeof(ip), "[<%pK>]",
90076 (void *)class->contention_point[i]);
90077 seq_printf(m, "%40s %14lu %29s %pS\n",
90078 name, stats->contention_point[i],
90079 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90080 if (!i)
90081 seq_line(m, '-', 40-namelen, namelen);
90082
90083 - snprintf(ip, sizeof(ip), "[<%p>]",
90084 + snprintf(ip, sizeof(ip), "[<%pK>]",
90085 (void *)class->contending_point[i]);
90086 seq_printf(m, "%40s %14lu %29s %pS\n",
90087 name, stats->contending_point[i],
90088 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90089 index 9887a90..0cd2b1d 100644
90090 --- a/kernel/locking/mcs_spinlock.c
90091 +++ b/kernel/locking/mcs_spinlock.c
90092 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90093
90094 prev = decode_cpu(old);
90095 node->prev = prev;
90096 - ACCESS_ONCE(prev->next) = node;
90097 + ACCESS_ONCE_RW(prev->next) = node;
90098
90099 /*
90100 * Normally @prev is untouchable after the above store; because at that
90101 @@ -172,8 +172,8 @@ unqueue:
90102 * it will wait in Step-A.
90103 */
90104
90105 - ACCESS_ONCE(next->prev) = prev;
90106 - ACCESS_ONCE(prev->next) = next;
90107 + ACCESS_ONCE_RW(next->prev) = prev;
90108 + ACCESS_ONCE_RW(prev->next) = next;
90109
90110 return false;
90111 }
90112 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90113 node = this_cpu_ptr(&osq_node);
90114 next = xchg(&node->next, NULL);
90115 if (next) {
90116 - ACCESS_ONCE(next->locked) = 1;
90117 + ACCESS_ONCE_RW(next->locked) = 1;
90118 return;
90119 }
90120
90121 next = osq_wait_next(lock, node, NULL);
90122 if (next)
90123 - ACCESS_ONCE(next->locked) = 1;
90124 + ACCESS_ONCE_RW(next->locked) = 1;
90125 }
90126
90127 #endif
90128 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90129 index 23e89c5..8558eac 100644
90130 --- a/kernel/locking/mcs_spinlock.h
90131 +++ b/kernel/locking/mcs_spinlock.h
90132 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90133 */
90134 return;
90135 }
90136 - ACCESS_ONCE(prev->next) = node;
90137 + ACCESS_ONCE_RW(prev->next) = node;
90138
90139 /* Wait until the lock holder passes the lock down. */
90140 arch_mcs_spin_lock_contended(&node->locked);
90141 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90142 index 5cf6731..ce3bc5a 100644
90143 --- a/kernel/locking/mutex-debug.c
90144 +++ b/kernel/locking/mutex-debug.c
90145 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90146 }
90147
90148 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90149 - struct thread_info *ti)
90150 + struct task_struct *task)
90151 {
90152 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90153
90154 /* Mark the current thread as blocked on the lock: */
90155 - ti->task->blocked_on = waiter;
90156 + task->blocked_on = waiter;
90157 }
90158
90159 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90160 - struct thread_info *ti)
90161 + struct task_struct *task)
90162 {
90163 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90164 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90165 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90166 - ti->task->blocked_on = NULL;
90167 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90168 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90169 + task->blocked_on = NULL;
90170
90171 list_del_init(&waiter->list);
90172 waiter->task = NULL;
90173 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90174 index 0799fd3..d06ae3b 100644
90175 --- a/kernel/locking/mutex-debug.h
90176 +++ b/kernel/locking/mutex-debug.h
90177 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90178 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90179 extern void debug_mutex_add_waiter(struct mutex *lock,
90180 struct mutex_waiter *waiter,
90181 - struct thread_info *ti);
90182 + struct task_struct *task);
90183 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90184 - struct thread_info *ti);
90185 + struct task_struct *task);
90186 extern void debug_mutex_unlock(struct mutex *lock);
90187 extern void debug_mutex_init(struct mutex *lock, const char *name,
90188 struct lock_class_key *key);
90189 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90190 index ae712b2..d0d4a41 100644
90191 --- a/kernel/locking/mutex.c
90192 +++ b/kernel/locking/mutex.c
90193 @@ -486,7 +486,7 @@ slowpath:
90194 goto skip_wait;
90195
90196 debug_mutex_lock_common(lock, &waiter);
90197 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90198 + debug_mutex_add_waiter(lock, &waiter, task);
90199
90200 /* add waiting tasks to the end of the waitqueue (FIFO): */
90201 list_add_tail(&waiter.list, &lock->wait_list);
90202 @@ -531,7 +531,7 @@ slowpath:
90203 schedule_preempt_disabled();
90204 spin_lock_mutex(&lock->wait_lock, flags);
90205 }
90206 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90207 + mutex_remove_waiter(lock, &waiter, task);
90208 /* set it to 0 if there are no waiters left: */
90209 if (likely(list_empty(&lock->wait_list)))
90210 atomic_set(&lock->count, 0);
90211 @@ -568,7 +568,7 @@ skip_wait:
90212 return 0;
90213
90214 err:
90215 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90216 + mutex_remove_waiter(lock, &waiter, task);
90217 spin_unlock_mutex(&lock->wait_lock, flags);
90218 debug_mutex_free_waiter(&waiter);
90219 mutex_release(&lock->dep_map, 1, ip);
90220 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90221 index 1d96dd0..994ff19 100644
90222 --- a/kernel/locking/rtmutex-tester.c
90223 +++ b/kernel/locking/rtmutex-tester.c
90224 @@ -22,7 +22,7 @@
90225 #define MAX_RT_TEST_MUTEXES 8
90226
90227 static spinlock_t rttest_lock;
90228 -static atomic_t rttest_event;
90229 +static atomic_unchecked_t rttest_event;
90230
90231 struct test_thread_data {
90232 int opcode;
90233 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90234
90235 case RTTEST_LOCKCONT:
90236 td->mutexes[td->opdata] = 1;
90237 - td->event = atomic_add_return(1, &rttest_event);
90238 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90239 return 0;
90240
90241 case RTTEST_RESET:
90242 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90243 return 0;
90244
90245 case RTTEST_RESETEVENT:
90246 - atomic_set(&rttest_event, 0);
90247 + atomic_set_unchecked(&rttest_event, 0);
90248 return 0;
90249
90250 default:
90251 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90252 return ret;
90253
90254 td->mutexes[id] = 1;
90255 - td->event = atomic_add_return(1, &rttest_event);
90256 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90257 rt_mutex_lock(&mutexes[id]);
90258 - td->event = atomic_add_return(1, &rttest_event);
90259 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90260 td->mutexes[id] = 4;
90261 return 0;
90262
90263 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90264 return ret;
90265
90266 td->mutexes[id] = 1;
90267 - td->event = atomic_add_return(1, &rttest_event);
90268 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90269 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90270 - td->event = atomic_add_return(1, &rttest_event);
90271 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90272 td->mutexes[id] = ret ? 0 : 4;
90273 return ret ? -EINTR : 0;
90274
90275 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90276 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90277 return ret;
90278
90279 - td->event = atomic_add_return(1, &rttest_event);
90280 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90281 rt_mutex_unlock(&mutexes[id]);
90282 - td->event = atomic_add_return(1, &rttest_event);
90283 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90284 td->mutexes[id] = 0;
90285 return 0;
90286
90287 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90288 break;
90289
90290 td->mutexes[dat] = 2;
90291 - td->event = atomic_add_return(1, &rttest_event);
90292 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90293 break;
90294
90295 default:
90296 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90297 return;
90298
90299 td->mutexes[dat] = 3;
90300 - td->event = atomic_add_return(1, &rttest_event);
90301 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90302 break;
90303
90304 case RTTEST_LOCKNOWAIT:
90305 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90306 return;
90307
90308 td->mutexes[dat] = 1;
90309 - td->event = atomic_add_return(1, &rttest_event);
90310 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90311 return;
90312
90313 default:
90314 diff --git a/kernel/module.c b/kernel/module.c
90315 index 1c47139..6242887 100644
90316 --- a/kernel/module.c
90317 +++ b/kernel/module.c
90318 @@ -60,6 +60,7 @@
90319 #include <linux/jump_label.h>
90320 #include <linux/pfn.h>
90321 #include <linux/bsearch.h>
90322 +#include <linux/grsecurity.h>
90323 #include <uapi/linux/module.h>
90324 #include "module-internal.h"
90325
90326 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90327
90328 /* Bounds of module allocation, for speeding __module_address.
90329 * Protected by module_mutex. */
90330 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90331 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90332 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90333
90334 int register_module_notifier(struct notifier_block * nb)
90335 {
90336 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90337 return true;
90338
90339 list_for_each_entry_rcu(mod, &modules, list) {
90340 - struct symsearch arr[] = {
90341 + struct symsearch modarr[] = {
90342 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90343 NOT_GPL_ONLY, false },
90344 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90345 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90346 if (mod->state == MODULE_STATE_UNFORMED)
90347 continue;
90348
90349 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90350 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90351 return true;
90352 }
90353 return false;
90354 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90355 if (!pcpusec->sh_size)
90356 return 0;
90357
90358 - if (align > PAGE_SIZE) {
90359 + if (align-1 >= PAGE_SIZE) {
90360 pr_warn("%s: per-cpu alignment %li > %li\n",
90361 mod->name, align, PAGE_SIZE);
90362 align = PAGE_SIZE;
90363 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90364 static ssize_t show_coresize(struct module_attribute *mattr,
90365 struct module_kobject *mk, char *buffer)
90366 {
90367 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90368 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90369 }
90370
90371 static struct module_attribute modinfo_coresize =
90372 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90373 static ssize_t show_initsize(struct module_attribute *mattr,
90374 struct module_kobject *mk, char *buffer)
90375 {
90376 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90377 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90378 }
90379
90380 static struct module_attribute modinfo_initsize =
90381 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90382 goto bad_version;
90383 }
90384
90385 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90386 + /*
90387 + * avoid potentially printing jibberish on attempted load
90388 + * of a module randomized with a different seed
90389 + */
90390 + pr_warn("no symbol version for %s\n", symname);
90391 +#else
90392 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90393 +#endif
90394 return 0;
90395
90396 bad_version:
90397 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90398 + /*
90399 + * avoid potentially printing jibberish on attempted load
90400 + * of a module randomized with a different seed
90401 + */
90402 + printk("attempted module disagrees about version of symbol %s\n",
90403 + symname);
90404 +#else
90405 printk("%s: disagrees about version of symbol %s\n",
90406 mod->name, symname);
90407 +#endif
90408 return 0;
90409 }
90410
90411 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90412 */
90413 #ifdef CONFIG_SYSFS
90414
90415 -#ifdef CONFIG_KALLSYMS
90416 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90417 static inline bool sect_empty(const Elf_Shdr *sect)
90418 {
90419 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90420 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90421 {
90422 unsigned int notes, loaded, i;
90423 struct module_notes_attrs *notes_attrs;
90424 - struct bin_attribute *nattr;
90425 + bin_attribute_no_const *nattr;
90426
90427 /* failed to create section attributes, so can't create notes */
90428 if (!mod->sect_attrs)
90429 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90430 static int module_add_modinfo_attrs(struct module *mod)
90431 {
90432 struct module_attribute *attr;
90433 - struct module_attribute *temp_attr;
90434 + module_attribute_no_const *temp_attr;
90435 int error = 0;
90436 int i;
90437
90438 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90439
90440 static void unset_module_core_ro_nx(struct module *mod)
90441 {
90442 - set_page_attributes(mod->module_core + mod->core_text_size,
90443 - mod->module_core + mod->core_size,
90444 + set_page_attributes(mod->module_core_rw,
90445 + mod->module_core_rw + mod->core_size_rw,
90446 set_memory_x);
90447 - set_page_attributes(mod->module_core,
90448 - mod->module_core + mod->core_ro_size,
90449 + set_page_attributes(mod->module_core_rx,
90450 + mod->module_core_rx + mod->core_size_rx,
90451 set_memory_rw);
90452 }
90453
90454 static void unset_module_init_ro_nx(struct module *mod)
90455 {
90456 - set_page_attributes(mod->module_init + mod->init_text_size,
90457 - mod->module_init + mod->init_size,
90458 + set_page_attributes(mod->module_init_rw,
90459 + mod->module_init_rw + mod->init_size_rw,
90460 set_memory_x);
90461 - set_page_attributes(mod->module_init,
90462 - mod->module_init + mod->init_ro_size,
90463 + set_page_attributes(mod->module_init_rx,
90464 + mod->module_init_rx + mod->init_size_rx,
90465 set_memory_rw);
90466 }
90467
90468 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90469 list_for_each_entry_rcu(mod, &modules, list) {
90470 if (mod->state == MODULE_STATE_UNFORMED)
90471 continue;
90472 - if ((mod->module_core) && (mod->core_text_size)) {
90473 - set_page_attributes(mod->module_core,
90474 - mod->module_core + mod->core_text_size,
90475 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90476 + set_page_attributes(mod->module_core_rx,
90477 + mod->module_core_rx + mod->core_size_rx,
90478 set_memory_rw);
90479 }
90480 - if ((mod->module_init) && (mod->init_text_size)) {
90481 - set_page_attributes(mod->module_init,
90482 - mod->module_init + mod->init_text_size,
90483 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90484 + set_page_attributes(mod->module_init_rx,
90485 + mod->module_init_rx + mod->init_size_rx,
90486 set_memory_rw);
90487 }
90488 }
90489 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90490 list_for_each_entry_rcu(mod, &modules, list) {
90491 if (mod->state == MODULE_STATE_UNFORMED)
90492 continue;
90493 - if ((mod->module_core) && (mod->core_text_size)) {
90494 - set_page_attributes(mod->module_core,
90495 - mod->module_core + mod->core_text_size,
90496 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90497 + set_page_attributes(mod->module_core_rx,
90498 + mod->module_core_rx + mod->core_size_rx,
90499 set_memory_ro);
90500 }
90501 - if ((mod->module_init) && (mod->init_text_size)) {
90502 - set_page_attributes(mod->module_init,
90503 - mod->module_init + mod->init_text_size,
90504 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90505 + set_page_attributes(mod->module_init_rx,
90506 + mod->module_init_rx + mod->init_size_rx,
90507 set_memory_ro);
90508 }
90509 }
90510 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90511
90512 /* This may be NULL, but that's OK */
90513 unset_module_init_ro_nx(mod);
90514 - module_free(mod, mod->module_init);
90515 + module_free(mod, mod->module_init_rw);
90516 + module_free_exec(mod, mod->module_init_rx);
90517 kfree(mod->args);
90518 percpu_modfree(mod);
90519
90520 /* Free lock-classes: */
90521 - lockdep_free_key_range(mod->module_core, mod->core_size);
90522 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90523 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90524
90525 /* Finally, free the core (containing the module structure) */
90526 unset_module_core_ro_nx(mod);
90527 - module_free(mod, mod->module_core);
90528 + module_free_exec(mod, mod->module_core_rx);
90529 + module_free(mod, mod->module_core_rw);
90530
90531 #ifdef CONFIG_MPU
90532 update_protections(current->mm);
90533 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90534 int ret = 0;
90535 const struct kernel_symbol *ksym;
90536
90537 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90538 + int is_fs_load = 0;
90539 + int register_filesystem_found = 0;
90540 + char *p;
90541 +
90542 + p = strstr(mod->args, "grsec_modharden_fs");
90543 + if (p) {
90544 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90545 + /* copy \0 as well */
90546 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90547 + is_fs_load = 1;
90548 + }
90549 +#endif
90550 +
90551 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90552 const char *name = info->strtab + sym[i].st_name;
90553
90554 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90555 + /* it's a real shame this will never get ripped and copied
90556 + upstream! ;(
90557 + */
90558 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90559 + register_filesystem_found = 1;
90560 +#endif
90561 +
90562 switch (sym[i].st_shndx) {
90563 case SHN_COMMON:
90564 /* Ignore common symbols */
90565 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90566 ksym = resolve_symbol_wait(mod, info, name);
90567 /* Ok if resolved. */
90568 if (ksym && !IS_ERR(ksym)) {
90569 + pax_open_kernel();
90570 sym[i].st_value = ksym->value;
90571 + pax_close_kernel();
90572 break;
90573 }
90574
90575 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90576 secbase = (unsigned long)mod_percpu(mod);
90577 else
90578 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90579 + pax_open_kernel();
90580 sym[i].st_value += secbase;
90581 + pax_close_kernel();
90582 break;
90583 }
90584 }
90585
90586 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90587 + if (is_fs_load && !register_filesystem_found) {
90588 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90589 + ret = -EPERM;
90590 + }
90591 +#endif
90592 +
90593 return ret;
90594 }
90595
90596 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90597 || s->sh_entsize != ~0UL
90598 || strstarts(sname, ".init"))
90599 continue;
90600 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90601 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90602 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90603 + else
90604 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90605 pr_debug("\t%s\n", sname);
90606 }
90607 - switch (m) {
90608 - case 0: /* executable */
90609 - mod->core_size = debug_align(mod->core_size);
90610 - mod->core_text_size = mod->core_size;
90611 - break;
90612 - case 1: /* RO: text and ro-data */
90613 - mod->core_size = debug_align(mod->core_size);
90614 - mod->core_ro_size = mod->core_size;
90615 - break;
90616 - case 3: /* whole core */
90617 - mod->core_size = debug_align(mod->core_size);
90618 - break;
90619 - }
90620 }
90621
90622 pr_debug("Init section allocation order:\n");
90623 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90624 || s->sh_entsize != ~0UL
90625 || !strstarts(sname, ".init"))
90626 continue;
90627 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90628 - | INIT_OFFSET_MASK);
90629 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90630 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90631 + else
90632 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90633 + s->sh_entsize |= INIT_OFFSET_MASK;
90634 pr_debug("\t%s\n", sname);
90635 }
90636 - switch (m) {
90637 - case 0: /* executable */
90638 - mod->init_size = debug_align(mod->init_size);
90639 - mod->init_text_size = mod->init_size;
90640 - break;
90641 - case 1: /* RO: text and ro-data */
90642 - mod->init_size = debug_align(mod->init_size);
90643 - mod->init_ro_size = mod->init_size;
90644 - break;
90645 - case 3: /* whole init */
90646 - mod->init_size = debug_align(mod->init_size);
90647 - break;
90648 - }
90649 }
90650 }
90651
90652 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90653
90654 /* Put symbol section at end of init part of module. */
90655 symsect->sh_flags |= SHF_ALLOC;
90656 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90657 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90658 info->index.sym) | INIT_OFFSET_MASK;
90659 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90660
90661 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90662 }
90663
90664 /* Append room for core symbols at end of core part. */
90665 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90666 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90667 - mod->core_size += strtab_size;
90668 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90669 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90670 + mod->core_size_rx += strtab_size;
90671
90672 /* Put string table section at end of init part of module. */
90673 strsect->sh_flags |= SHF_ALLOC;
90674 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90675 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90676 info->index.str) | INIT_OFFSET_MASK;
90677 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90678 }
90679 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90680 /* Make sure we get permanent strtab: don't use info->strtab. */
90681 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90682
90683 + pax_open_kernel();
90684 +
90685 /* Set types up while we still have access to sections. */
90686 for (i = 0; i < mod->num_symtab; i++)
90687 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90688
90689 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90690 - mod->core_strtab = s = mod->module_core + info->stroffs;
90691 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90692 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90693 src = mod->symtab;
90694 for (ndst = i = 0; i < mod->num_symtab; i++) {
90695 if (i == 0 ||
90696 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90697 }
90698 }
90699 mod->core_num_syms = ndst;
90700 +
90701 + pax_close_kernel();
90702 }
90703 #else
90704 static inline void layout_symtab(struct module *mod, struct load_info *info)
90705 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90706 return vmalloc_exec(size);
90707 }
90708
90709 -static void *module_alloc_update_bounds(unsigned long size)
90710 +static void *module_alloc_update_bounds_rw(unsigned long size)
90711 {
90712 void *ret = module_alloc(size);
90713
90714 if (ret) {
90715 mutex_lock(&module_mutex);
90716 /* Update module bounds. */
90717 - if ((unsigned long)ret < module_addr_min)
90718 - module_addr_min = (unsigned long)ret;
90719 - if ((unsigned long)ret + size > module_addr_max)
90720 - module_addr_max = (unsigned long)ret + size;
90721 + if ((unsigned long)ret < module_addr_min_rw)
90722 + module_addr_min_rw = (unsigned long)ret;
90723 + if ((unsigned long)ret + size > module_addr_max_rw)
90724 + module_addr_max_rw = (unsigned long)ret + size;
90725 + mutex_unlock(&module_mutex);
90726 + }
90727 + return ret;
90728 +}
90729 +
90730 +static void *module_alloc_update_bounds_rx(unsigned long size)
90731 +{
90732 + void *ret = module_alloc_exec(size);
90733 +
90734 + if (ret) {
90735 + mutex_lock(&module_mutex);
90736 + /* Update module bounds. */
90737 + if ((unsigned long)ret < module_addr_min_rx)
90738 + module_addr_min_rx = (unsigned long)ret;
90739 + if ((unsigned long)ret + size > module_addr_max_rx)
90740 + module_addr_max_rx = (unsigned long)ret + size;
90741 mutex_unlock(&module_mutex);
90742 }
90743 return ret;
90744 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90745 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90746
90747 if (info->index.sym == 0) {
90748 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90749 + /*
90750 + * avoid potentially printing jibberish on attempted load
90751 + * of a module randomized with a different seed
90752 + */
90753 + pr_warn("module has no symbols (stripped?)\n");
90754 +#else
90755 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90756 +#endif
90757 return ERR_PTR(-ENOEXEC);
90758 }
90759
90760 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90761 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90762 {
90763 const char *modmagic = get_modinfo(info, "vermagic");
90764 + const char *license = get_modinfo(info, "license");
90765 int err;
90766
90767 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90768 + if (!license || !license_is_gpl_compatible(license))
90769 + return -ENOEXEC;
90770 +#endif
90771 +
90772 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90773 modmagic = NULL;
90774
90775 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90776 }
90777
90778 /* Set up license info based on the info section */
90779 - set_license(mod, get_modinfo(info, "license"));
90780 + set_license(mod, license);
90781
90782 return 0;
90783 }
90784 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90785 void *ptr;
90786
90787 /* Do the allocs. */
90788 - ptr = module_alloc_update_bounds(mod->core_size);
90789 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90790 /*
90791 * The pointer to this block is stored in the module structure
90792 * which is inside the block. Just mark it as not being a
90793 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90794 if (!ptr)
90795 return -ENOMEM;
90796
90797 - memset(ptr, 0, mod->core_size);
90798 - mod->module_core = ptr;
90799 + memset(ptr, 0, mod->core_size_rw);
90800 + mod->module_core_rw = ptr;
90801
90802 - if (mod->init_size) {
90803 - ptr = module_alloc_update_bounds(mod->init_size);
90804 + if (mod->init_size_rw) {
90805 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90806 /*
90807 * The pointer to this block is stored in the module structure
90808 * which is inside the block. This block doesn't need to be
90809 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90810 */
90811 kmemleak_ignore(ptr);
90812 if (!ptr) {
90813 - module_free(mod, mod->module_core);
90814 + module_free(mod, mod->module_core_rw);
90815 return -ENOMEM;
90816 }
90817 - memset(ptr, 0, mod->init_size);
90818 - mod->module_init = ptr;
90819 + memset(ptr, 0, mod->init_size_rw);
90820 + mod->module_init_rw = ptr;
90821 } else
90822 - mod->module_init = NULL;
90823 + mod->module_init_rw = NULL;
90824 +
90825 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90826 + kmemleak_not_leak(ptr);
90827 + if (!ptr) {
90828 + if (mod->module_init_rw)
90829 + module_free(mod, mod->module_init_rw);
90830 + module_free(mod, mod->module_core_rw);
90831 + return -ENOMEM;
90832 + }
90833 +
90834 + pax_open_kernel();
90835 + memset(ptr, 0, mod->core_size_rx);
90836 + pax_close_kernel();
90837 + mod->module_core_rx = ptr;
90838 +
90839 + if (mod->init_size_rx) {
90840 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90841 + kmemleak_ignore(ptr);
90842 + if (!ptr && mod->init_size_rx) {
90843 + module_free_exec(mod, mod->module_core_rx);
90844 + if (mod->module_init_rw)
90845 + module_free(mod, mod->module_init_rw);
90846 + module_free(mod, mod->module_core_rw);
90847 + return -ENOMEM;
90848 + }
90849 +
90850 + pax_open_kernel();
90851 + memset(ptr, 0, mod->init_size_rx);
90852 + pax_close_kernel();
90853 + mod->module_init_rx = ptr;
90854 + } else
90855 + mod->module_init_rx = NULL;
90856
90857 /* Transfer each section which specifies SHF_ALLOC */
90858 pr_debug("final section addresses:\n");
90859 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90860 if (!(shdr->sh_flags & SHF_ALLOC))
90861 continue;
90862
90863 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
90864 - dest = mod->module_init
90865 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90866 - else
90867 - dest = mod->module_core + shdr->sh_entsize;
90868 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90869 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90870 + dest = mod->module_init_rw
90871 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90872 + else
90873 + dest = mod->module_init_rx
90874 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90875 + } else {
90876 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90877 + dest = mod->module_core_rw + shdr->sh_entsize;
90878 + else
90879 + dest = mod->module_core_rx + shdr->sh_entsize;
90880 + }
90881 +
90882 + if (shdr->sh_type != SHT_NOBITS) {
90883 +
90884 +#ifdef CONFIG_PAX_KERNEXEC
90885 +#ifdef CONFIG_X86_64
90886 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
90887 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
90888 +#endif
90889 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
90890 + pax_open_kernel();
90891 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90892 + pax_close_kernel();
90893 + } else
90894 +#endif
90895
90896 - if (shdr->sh_type != SHT_NOBITS)
90897 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90898 + }
90899 /* Update sh_addr to point to copy in image. */
90900 - shdr->sh_addr = (unsigned long)dest;
90901 +
90902 +#ifdef CONFIG_PAX_KERNEXEC
90903 + if (shdr->sh_flags & SHF_EXECINSTR)
90904 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
90905 + else
90906 +#endif
90907 +
90908 + shdr->sh_addr = (unsigned long)dest;
90909 pr_debug("\t0x%lx %s\n",
90910 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
90911 }
90912 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
90913 * Do it before processing of module parameters, so the module
90914 * can provide parameter accessor functions of its own.
90915 */
90916 - if (mod->module_init)
90917 - flush_icache_range((unsigned long)mod->module_init,
90918 - (unsigned long)mod->module_init
90919 - + mod->init_size);
90920 - flush_icache_range((unsigned long)mod->module_core,
90921 - (unsigned long)mod->module_core + mod->core_size);
90922 + if (mod->module_init_rx)
90923 + flush_icache_range((unsigned long)mod->module_init_rx,
90924 + (unsigned long)mod->module_init_rx
90925 + + mod->init_size_rx);
90926 + flush_icache_range((unsigned long)mod->module_core_rx,
90927 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
90928
90929 set_fs(old_fs);
90930 }
90931 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
90932 static void module_deallocate(struct module *mod, struct load_info *info)
90933 {
90934 percpu_modfree(mod);
90935 - module_free(mod, mod->module_init);
90936 - module_free(mod, mod->module_core);
90937 + module_free_exec(mod, mod->module_init_rx);
90938 + module_free_exec(mod, mod->module_core_rx);
90939 + module_free(mod, mod->module_init_rw);
90940 + module_free(mod, mod->module_core_rw);
90941 }
90942
90943 int __weak module_finalize(const Elf_Ehdr *hdr,
90944 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
90945 static int post_relocation(struct module *mod, const struct load_info *info)
90946 {
90947 /* Sort exception table now relocations are done. */
90948 + pax_open_kernel();
90949 sort_extable(mod->extable, mod->extable + mod->num_exentries);
90950 + pax_close_kernel();
90951
90952 /* Copy relocated percpu area over. */
90953 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
90954 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
90955 mod->strtab = mod->core_strtab;
90956 #endif
90957 unset_module_init_ro_nx(mod);
90958 - module_free(mod, mod->module_init);
90959 - mod->module_init = NULL;
90960 - mod->init_size = 0;
90961 - mod->init_ro_size = 0;
90962 - mod->init_text_size = 0;
90963 + module_free(mod, mod->module_init_rw);
90964 + module_free_exec(mod, mod->module_init_rx);
90965 + mod->module_init_rw = NULL;
90966 + mod->module_init_rx = NULL;
90967 + mod->init_size_rw = 0;
90968 + mod->init_size_rx = 0;
90969 mutex_unlock(&module_mutex);
90970 wake_up_all(&module_wq);
90971
90972 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
90973 module_bug_finalize(info->hdr, info->sechdrs, mod);
90974
90975 /* Set RO and NX regions for core */
90976 - set_section_ro_nx(mod->module_core,
90977 - mod->core_text_size,
90978 - mod->core_ro_size,
90979 - mod->core_size);
90980 + set_section_ro_nx(mod->module_core_rx,
90981 + mod->core_size_rx,
90982 + mod->core_size_rx,
90983 + mod->core_size_rx);
90984
90985 /* Set RO and NX regions for init */
90986 - set_section_ro_nx(mod->module_init,
90987 - mod->init_text_size,
90988 - mod->init_ro_size,
90989 - mod->init_size);
90990 + set_section_ro_nx(mod->module_init_rx,
90991 + mod->init_size_rx,
90992 + mod->init_size_rx,
90993 + mod->init_size_rx);
90994
90995 /* Mark state as coming so strong_try_module_get() ignores us,
90996 * but kallsyms etc. can see us. */
90997 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
90998 if (err)
90999 goto free_unload;
91000
91001 + /* Now copy in args */
91002 + mod->args = strndup_user(uargs, ~0UL >> 1);
91003 + if (IS_ERR(mod->args)) {
91004 + err = PTR_ERR(mod->args);
91005 + goto free_unload;
91006 + }
91007 +
91008 /* Set up MODINFO_ATTR fields */
91009 setup_modinfo(mod, info);
91010
91011 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91012 + {
91013 + char *p, *p2;
91014 +
91015 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91016 + 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);
91017 + err = -EPERM;
91018 + goto free_modinfo;
91019 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91020 + p += sizeof("grsec_modharden_normal") - 1;
91021 + p2 = strstr(p, "_");
91022 + if (p2) {
91023 + *p2 = '\0';
91024 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91025 + *p2 = '_';
91026 + }
91027 + err = -EPERM;
91028 + goto free_modinfo;
91029 + }
91030 + }
91031 +#endif
91032 +
91033 /* Fix up syms, so that st_value is a pointer to location. */
91034 err = simplify_symbols(mod, info);
91035 if (err < 0)
91036 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91037
91038 flush_module_icache(mod);
91039
91040 - /* Now copy in args */
91041 - mod->args = strndup_user(uargs, ~0UL >> 1);
91042 - if (IS_ERR(mod->args)) {
91043 - err = PTR_ERR(mod->args);
91044 - goto free_arch_cleanup;
91045 - }
91046 -
91047 dynamic_debug_setup(info->debug, info->num_debug);
91048
91049 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91050 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91051 ddebug_cleanup:
91052 dynamic_debug_remove(info->debug);
91053 synchronize_sched();
91054 - kfree(mod->args);
91055 - free_arch_cleanup:
91056 module_arch_cleanup(mod);
91057 free_modinfo:
91058 free_modinfo(mod);
91059 + kfree(mod->args);
91060 free_unload:
91061 module_unload_free(mod);
91062 unlink_mod:
91063 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91064 unsigned long nextval;
91065
91066 /* At worse, next value is at end of module */
91067 - if (within_module_init(addr, mod))
91068 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91069 + if (within_module_init_rx(addr, mod))
91070 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91071 + else if (within_module_init_rw(addr, mod))
91072 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91073 + else if (within_module_core_rx(addr, mod))
91074 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91075 + else if (within_module_core_rw(addr, mod))
91076 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91077 else
91078 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91079 + return NULL;
91080
91081 /* Scan for closest preceding symbol, and next symbol. (ELF
91082 starts real symbols at 1). */
91083 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91084 return 0;
91085
91086 seq_printf(m, "%s %u",
91087 - mod->name, mod->init_size + mod->core_size);
91088 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91089 print_unload_info(m, mod);
91090
91091 /* Informative for users. */
91092 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91093 mod->state == MODULE_STATE_COMING ? "Loading":
91094 "Live");
91095 /* Used by oprofile and other similar tools. */
91096 - seq_printf(m, " 0x%pK", mod->module_core);
91097 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91098
91099 /* Taints info */
91100 if (mod->taints)
91101 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91102
91103 static int __init proc_modules_init(void)
91104 {
91105 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91106 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91107 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91108 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91109 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91110 +#else
91111 proc_create("modules", 0, NULL, &proc_modules_operations);
91112 +#endif
91113 +#else
91114 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91115 +#endif
91116 return 0;
91117 }
91118 module_init(proc_modules_init);
91119 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91120 {
91121 struct module *mod;
91122
91123 - if (addr < module_addr_min || addr > module_addr_max)
91124 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91125 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91126 return NULL;
91127
91128 list_for_each_entry_rcu(mod, &modules, list) {
91129 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91130 */
91131 struct module *__module_text_address(unsigned long addr)
91132 {
91133 - struct module *mod = __module_address(addr);
91134 + struct module *mod;
91135 +
91136 +#ifdef CONFIG_X86_32
91137 + addr = ktla_ktva(addr);
91138 +#endif
91139 +
91140 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91141 + return NULL;
91142 +
91143 + mod = __module_address(addr);
91144 +
91145 if (mod) {
91146 /* Make sure it's within the text section. */
91147 - if (!within(addr, mod->module_init, mod->init_text_size)
91148 - && !within(addr, mod->module_core, mod->core_text_size))
91149 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91150 mod = NULL;
91151 }
91152 return mod;
91153 diff --git a/kernel/notifier.c b/kernel/notifier.c
91154 index 4803da6..1c5eea6 100644
91155 --- a/kernel/notifier.c
91156 +++ b/kernel/notifier.c
91157 @@ -5,6 +5,7 @@
91158 #include <linux/rcupdate.h>
91159 #include <linux/vmalloc.h>
91160 #include <linux/reboot.h>
91161 +#include <linux/mm.h>
91162
91163 /*
91164 * Notifier list for kernel code which wants to be called
91165 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91166 while ((*nl) != NULL) {
91167 if (n->priority > (*nl)->priority)
91168 break;
91169 - nl = &((*nl)->next);
91170 + nl = (struct notifier_block **)&((*nl)->next);
91171 }
91172 - n->next = *nl;
91173 + pax_open_kernel();
91174 + *(const void **)&n->next = *nl;
91175 rcu_assign_pointer(*nl, n);
91176 + pax_close_kernel();
91177 return 0;
91178 }
91179
91180 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91181 return 0;
91182 if (n->priority > (*nl)->priority)
91183 break;
91184 - nl = &((*nl)->next);
91185 + nl = (struct notifier_block **)&((*nl)->next);
91186 }
91187 - n->next = *nl;
91188 + pax_open_kernel();
91189 + *(const void **)&n->next = *nl;
91190 rcu_assign_pointer(*nl, n);
91191 + pax_close_kernel();
91192 return 0;
91193 }
91194
91195 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91196 {
91197 while ((*nl) != NULL) {
91198 if ((*nl) == n) {
91199 + pax_open_kernel();
91200 rcu_assign_pointer(*nl, n->next);
91201 + pax_close_kernel();
91202 return 0;
91203 }
91204 - nl = &((*nl)->next);
91205 + nl = (struct notifier_block **)&((*nl)->next);
91206 }
91207 return -ENOENT;
91208 }
91209 diff --git a/kernel/padata.c b/kernel/padata.c
91210 index 161402f..598814c 100644
91211 --- a/kernel/padata.c
91212 +++ b/kernel/padata.c
91213 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91214 * seq_nr mod. number of cpus in use.
91215 */
91216
91217 - seq_nr = atomic_inc_return(&pd->seq_nr);
91218 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91219 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91220
91221 return padata_index_to_cpu(pd, cpu_index);
91222 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91223 padata_init_pqueues(pd);
91224 padata_init_squeues(pd);
91225 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91226 - atomic_set(&pd->seq_nr, -1);
91227 + atomic_set_unchecked(&pd->seq_nr, -1);
91228 atomic_set(&pd->reorder_objects, 0);
91229 atomic_set(&pd->refcnt, 0);
91230 pd->pinst = pinst;
91231 diff --git a/kernel/panic.c b/kernel/panic.c
91232 index d09dc5c..9abbdff 100644
91233 --- a/kernel/panic.c
91234 +++ b/kernel/panic.c
91235 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91236 /*
91237 * Stop ourself in panic -- architecture code may override this
91238 */
91239 -void __weak panic_smp_self_stop(void)
91240 +void __weak __noreturn panic_smp_self_stop(void)
91241 {
91242 while (1)
91243 cpu_relax();
91244 @@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91245 disable_trace_on_warning();
91246
91247 pr_warn("------------[ cut here ]------------\n");
91248 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91249 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91250 raw_smp_processor_id(), current->pid, file, line, caller);
91251
91252 if (args)
91253 @@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91254 */
91255 __visible void __stack_chk_fail(void)
91256 {
91257 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91258 + dump_stack();
91259 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91260 __builtin_return_address(0));
91261 }
91262 EXPORT_SYMBOL(__stack_chk_fail);
91263 diff --git a/kernel/pid.c b/kernel/pid.c
91264 index 9b9a266..c20ef80 100644
91265 --- a/kernel/pid.c
91266 +++ b/kernel/pid.c
91267 @@ -33,6 +33,7 @@
91268 #include <linux/rculist.h>
91269 #include <linux/bootmem.h>
91270 #include <linux/hash.h>
91271 +#include <linux/security.h>
91272 #include <linux/pid_namespace.h>
91273 #include <linux/init_task.h>
91274 #include <linux/syscalls.h>
91275 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91276
91277 int pid_max = PID_MAX_DEFAULT;
91278
91279 -#define RESERVED_PIDS 300
91280 +#define RESERVED_PIDS 500
91281
91282 int pid_max_min = RESERVED_PIDS + 1;
91283 int pid_max_max = PID_MAX_LIMIT;
91284 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91285 */
91286 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91287 {
91288 + struct task_struct *task;
91289 +
91290 rcu_lockdep_assert(rcu_read_lock_held(),
91291 "find_task_by_pid_ns() needs rcu_read_lock()"
91292 " protection");
91293 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91294 +
91295 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91296 +
91297 + if (gr_pid_is_chrooted(task))
91298 + return NULL;
91299 +
91300 + return task;
91301 }
91302
91303 struct task_struct *find_task_by_vpid(pid_t vnr)
91304 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91305 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91306 }
91307
91308 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91309 +{
91310 + rcu_lockdep_assert(rcu_read_lock_held(),
91311 + "find_task_by_pid_ns() needs rcu_read_lock()"
91312 + " protection");
91313 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91314 +}
91315 +
91316 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91317 {
91318 struct pid *pid;
91319 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91320 index db95d8e..a0ca23f 100644
91321 --- a/kernel/pid_namespace.c
91322 +++ b/kernel/pid_namespace.c
91323 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91324 void __user *buffer, size_t *lenp, loff_t *ppos)
91325 {
91326 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91327 - struct ctl_table tmp = *table;
91328 + ctl_table_no_const tmp = *table;
91329
91330 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91331 return -EPERM;
91332 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91333 index e4e4121..71faf14 100644
91334 --- a/kernel/power/Kconfig
91335 +++ b/kernel/power/Kconfig
91336 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91337 config HIBERNATION
91338 bool "Hibernation (aka 'suspend to disk')"
91339 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91340 + depends on !GRKERNSEC_KMEM
91341 + depends on !PAX_MEMORY_SANITIZE
91342 select HIBERNATE_CALLBACKS
91343 select LZO_COMPRESS
91344 select LZO_DECOMPRESS
91345 diff --git a/kernel/power/process.c b/kernel/power/process.c
91346 index 7a37cf3..3e4c1c8 100644
91347 --- a/kernel/power/process.c
91348 +++ b/kernel/power/process.c
91349 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91350 unsigned int elapsed_msecs;
91351 bool wakeup = false;
91352 int sleep_usecs = USEC_PER_MSEC;
91353 + bool timedout = false;
91354
91355 do_gettimeofday(&start);
91356
91357 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91358
91359 while (true) {
91360 todo = 0;
91361 + if (time_after(jiffies, end_time))
91362 + timedout = true;
91363 read_lock(&tasklist_lock);
91364 do_each_thread(g, p) {
91365 if (p == current || !freeze_task(p))
91366 continue;
91367
91368 - if (!freezer_should_skip(p))
91369 + if (!freezer_should_skip(p)) {
91370 todo++;
91371 + if (timedout) {
91372 + printk(KERN_ERR "Task refusing to freeze:\n");
91373 + sched_show_task(p);
91374 + }
91375 + }
91376 } while_each_thread(g, p);
91377 read_unlock(&tasklist_lock);
91378
91379 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91380 todo += wq_busy;
91381 }
91382
91383 - if (!todo || time_after(jiffies, end_time))
91384 + if (!todo || timedout)
91385 break;
91386
91387 if (pm_wakeup_pending()) {
91388 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91389 index 1ce7706..3b07c49 100644
91390 --- a/kernel/printk/printk.c
91391 +++ b/kernel/printk/printk.c
91392 @@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
91393 if (from_file && type != SYSLOG_ACTION_OPEN)
91394 return 0;
91395
91396 +#ifdef CONFIG_GRKERNSEC_DMESG
91397 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91398 + return -EPERM;
91399 +#endif
91400 +
91401 if (syslog_action_restricted(type)) {
91402 if (capable(CAP_SYSLOG))
91403 return 0;
91404 diff --git a/kernel/profile.c b/kernel/profile.c
91405 index 54bf5ba..df6e0a2 100644
91406 --- a/kernel/profile.c
91407 +++ b/kernel/profile.c
91408 @@ -37,7 +37,7 @@ struct profile_hit {
91409 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91410 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91411
91412 -static atomic_t *prof_buffer;
91413 +static atomic_unchecked_t *prof_buffer;
91414 static unsigned long prof_len, prof_shift;
91415
91416 int prof_on __read_mostly;
91417 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91418 hits[i].pc = 0;
91419 continue;
91420 }
91421 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91422 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91423 hits[i].hits = hits[i].pc = 0;
91424 }
91425 }
91426 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91427 * Add the current hit(s) and flush the write-queue out
91428 * to the global buffer:
91429 */
91430 - atomic_add(nr_hits, &prof_buffer[pc]);
91431 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91432 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91433 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91434 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91435 hits[i].pc = hits[i].hits = 0;
91436 }
91437 out:
91438 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91439 {
91440 unsigned long pc;
91441 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91442 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91443 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91444 }
91445 #endif /* !CONFIG_SMP */
91446
91447 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91448 return -EFAULT;
91449 buf++; p++; count--; read++;
91450 }
91451 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91452 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91453 if (copy_to_user(buf, (void *)pnt, count))
91454 return -EFAULT;
91455 read += count;
91456 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91457 }
91458 #endif
91459 profile_discard_flip_buffers();
91460 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91461 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91462 return count;
91463 }
91464
91465 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91466 index 54e7522..5b82dd6 100644
91467 --- a/kernel/ptrace.c
91468 +++ b/kernel/ptrace.c
91469 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91470 if (seize)
91471 flags |= PT_SEIZED;
91472 rcu_read_lock();
91473 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91474 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91475 flags |= PT_PTRACE_CAP;
91476 rcu_read_unlock();
91477 task->ptrace = flags;
91478 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91479 break;
91480 return -EIO;
91481 }
91482 - if (copy_to_user(dst, buf, retval))
91483 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91484 return -EFAULT;
91485 copied += retval;
91486 src += retval;
91487 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91488 bool seized = child->ptrace & PT_SEIZED;
91489 int ret = -EIO;
91490 siginfo_t siginfo, *si;
91491 - void __user *datavp = (void __user *) data;
91492 + void __user *datavp = (__force void __user *) data;
91493 unsigned long __user *datalp = datavp;
91494 unsigned long flags;
91495
91496 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91497 goto out;
91498 }
91499
91500 + if (gr_handle_ptrace(child, request)) {
91501 + ret = -EPERM;
91502 + goto out_put_task_struct;
91503 + }
91504 +
91505 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91506 ret = ptrace_attach(child, request, addr, data);
91507 /*
91508 * Some architectures need to do book-keeping after
91509 * a ptrace attach.
91510 */
91511 - if (!ret)
91512 + if (!ret) {
91513 arch_ptrace_attach(child);
91514 + gr_audit_ptrace(child);
91515 + }
91516 goto out_put_task_struct;
91517 }
91518
91519 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91520 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91521 if (copied != sizeof(tmp))
91522 return -EIO;
91523 - return put_user(tmp, (unsigned long __user *)data);
91524 + return put_user(tmp, (__force unsigned long __user *)data);
91525 }
91526
91527 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91528 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91529 }
91530
91531 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91532 - compat_long_t, addr, compat_long_t, data)
91533 + compat_ulong_t, addr, compat_ulong_t, data)
91534 {
91535 struct task_struct *child;
91536 long ret;
91537 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91538 goto out;
91539 }
91540
91541 + if (gr_handle_ptrace(child, request)) {
91542 + ret = -EPERM;
91543 + goto out_put_task_struct;
91544 + }
91545 +
91546 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91547 ret = ptrace_attach(child, request, addr, data);
91548 /*
91549 * Some architectures need to do book-keeping after
91550 * a ptrace attach.
91551 */
91552 - if (!ret)
91553 + if (!ret) {
91554 arch_ptrace_attach(child);
91555 + gr_audit_ptrace(child);
91556 + }
91557 goto out_put_task_struct;
91558 }
91559
91560 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91561 index 948a769..5ca842b 100644
91562 --- a/kernel/rcu/rcutorture.c
91563 +++ b/kernel/rcu/rcutorture.c
91564 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91565 rcu_torture_count) = { 0 };
91566 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91567 rcu_torture_batch) = { 0 };
91568 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91569 -static atomic_t n_rcu_torture_alloc;
91570 -static atomic_t n_rcu_torture_alloc_fail;
91571 -static atomic_t n_rcu_torture_free;
91572 -static atomic_t n_rcu_torture_mberror;
91573 -static atomic_t n_rcu_torture_error;
91574 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91575 +static atomic_unchecked_t n_rcu_torture_alloc;
91576 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91577 +static atomic_unchecked_t n_rcu_torture_free;
91578 +static atomic_unchecked_t n_rcu_torture_mberror;
91579 +static atomic_unchecked_t n_rcu_torture_error;
91580 static long n_rcu_torture_barrier_error;
91581 static long n_rcu_torture_boost_ktrerror;
91582 static long n_rcu_torture_boost_rterror;
91583 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
91584
91585 spin_lock_bh(&rcu_torture_lock);
91586 if (list_empty(&rcu_torture_freelist)) {
91587 - atomic_inc(&n_rcu_torture_alloc_fail);
91588 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91589 spin_unlock_bh(&rcu_torture_lock);
91590 return NULL;
91591 }
91592 - atomic_inc(&n_rcu_torture_alloc);
91593 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91594 p = rcu_torture_freelist.next;
91595 list_del_init(p);
91596 spin_unlock_bh(&rcu_torture_lock);
91597 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
91598 static void
91599 rcu_torture_free(struct rcu_torture *p)
91600 {
91601 - atomic_inc(&n_rcu_torture_free);
91602 + atomic_inc_unchecked(&n_rcu_torture_free);
91603 spin_lock_bh(&rcu_torture_lock);
91604 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91605 spin_unlock_bh(&rcu_torture_lock);
91606 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91607 i = rp->rtort_pipe_count;
91608 if (i > RCU_TORTURE_PIPE_LEN)
91609 i = RCU_TORTURE_PIPE_LEN;
91610 - atomic_inc(&rcu_torture_wcount[i]);
91611 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91612 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91613 rp->rtort_mbtest = 0;
91614 return true;
91615 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
91616 i = old_rp->rtort_pipe_count;
91617 if (i > RCU_TORTURE_PIPE_LEN)
91618 i = RCU_TORTURE_PIPE_LEN;
91619 - atomic_inc(&rcu_torture_wcount[i]);
91620 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91621 old_rp->rtort_pipe_count++;
91622 switch (synctype[torture_random(&rand) % nsynctypes]) {
91623 case RTWS_DEF_FREE:
91624 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
91625 return;
91626 }
91627 if (p->rtort_mbtest == 0)
91628 - atomic_inc(&n_rcu_torture_mberror);
91629 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91630 spin_lock(&rand_lock);
91631 cur_ops->read_delay(&rand);
91632 n_rcu_torture_timers++;
91633 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
91634 continue;
91635 }
91636 if (p->rtort_mbtest == 0)
91637 - atomic_inc(&n_rcu_torture_mberror);
91638 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91639 cur_ops->read_delay(&rand);
91640 preempt_disable();
91641 pipe_count = p->rtort_pipe_count;
91642 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
91643 }
91644 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
91645 page += sprintf(page,
91646 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
91647 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
91648 rcu_torture_current,
91649 rcu_torture_current_version,
91650 list_empty(&rcu_torture_freelist),
91651 - atomic_read(&n_rcu_torture_alloc),
91652 - atomic_read(&n_rcu_torture_alloc_fail),
91653 - atomic_read(&n_rcu_torture_free));
91654 + atomic_read_unchecked(&n_rcu_torture_alloc),
91655 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91656 + atomic_read_unchecked(&n_rcu_torture_free));
91657 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
91658 - atomic_read(&n_rcu_torture_mberror),
91659 + atomic_read_unchecked(&n_rcu_torture_mberror),
91660 n_rcu_torture_boost_ktrerror,
91661 n_rcu_torture_boost_rterror);
91662 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
91663 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
91664 n_barrier_attempts,
91665 n_rcu_torture_barrier_error);
91666 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
91667 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91668 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91669 n_rcu_torture_barrier_error != 0 ||
91670 n_rcu_torture_boost_ktrerror != 0 ||
91671 n_rcu_torture_boost_rterror != 0 ||
91672 n_rcu_torture_boost_failure != 0 ||
91673 i > 1) {
91674 page += sprintf(page, "!!! ");
91675 - atomic_inc(&n_rcu_torture_error);
91676 + atomic_inc_unchecked(&n_rcu_torture_error);
91677 WARN_ON_ONCE(1);
91678 }
91679 page += sprintf(page, "Reader Pipe: ");
91680 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
91681 page += sprintf(page, "Free-Block Circulation: ");
91682 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91683 page += sprintf(page, " %d",
91684 - atomic_read(&rcu_torture_wcount[i]));
91685 + atomic_read_unchecked(&rcu_torture_wcount[i]));
91686 }
91687 page += sprintf(page, "\n");
91688 if (cur_ops->stats)
91689 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
91690
91691 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91692
91693 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91694 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91695 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91696 else if (torture_onoff_failures())
91697 rcu_torture_print_module_parms(cur_ops,
91698 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
91699
91700 rcu_torture_current = NULL;
91701 rcu_torture_current_version = 0;
91702 - atomic_set(&n_rcu_torture_alloc, 0);
91703 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91704 - atomic_set(&n_rcu_torture_free, 0);
91705 - atomic_set(&n_rcu_torture_mberror, 0);
91706 - atomic_set(&n_rcu_torture_error, 0);
91707 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91708 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91709 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91710 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91711 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91712 n_rcu_torture_barrier_error = 0;
91713 n_rcu_torture_boost_ktrerror = 0;
91714 n_rcu_torture_boost_rterror = 0;
91715 n_rcu_torture_boost_failure = 0;
91716 n_rcu_torture_boosts = 0;
91717 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91718 - atomic_set(&rcu_torture_wcount[i], 0);
91719 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91720 for_each_possible_cpu(cpu) {
91721 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91722 per_cpu(rcu_torture_count, cpu)[i] = 0;
91723 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91724 index d9efcc1..ea543e9 100644
91725 --- a/kernel/rcu/tiny.c
91726 +++ b/kernel/rcu/tiny.c
91727 @@ -42,7 +42,7 @@
91728 /* Forward declarations for tiny_plugin.h. */
91729 struct rcu_ctrlblk;
91730 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91731 -static void rcu_process_callbacks(struct softirq_action *unused);
91732 +static void rcu_process_callbacks(void);
91733 static void __call_rcu(struct rcu_head *head,
91734 void (*func)(struct rcu_head *rcu),
91735 struct rcu_ctrlblk *rcp);
91736 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91737 false));
91738 }
91739
91740 -static void rcu_process_callbacks(struct softirq_action *unused)
91741 +static __latent_entropy void rcu_process_callbacks(void)
91742 {
91743 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91744 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91745 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91746 index 858c565..7efd915 100644
91747 --- a/kernel/rcu/tiny_plugin.h
91748 +++ b/kernel/rcu/tiny_plugin.h
91749 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91750 dump_stack();
91751 }
91752 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91753 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91754 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91755 3 * rcu_jiffies_till_stall_check() + 3;
91756 else if (ULONG_CMP_GE(j, js))
91757 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91758 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91759 }
91760
91761 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91762 {
91763 rcp->ticks_this_gp = 0;
91764 rcp->gp_start = jiffies;
91765 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91766 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91767 }
91768
91769 static void check_cpu_stalls(void)
91770 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91771 index 89a404a..f42a019 100644
91772 --- a/kernel/rcu/tree.c
91773 +++ b/kernel/rcu/tree.c
91774 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
91775 */
91776 rdtp = this_cpu_ptr(&rcu_dynticks);
91777 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91778 - atomic_add(2, &rdtp->dynticks); /* QS. */
91779 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91780 smp_mb__after_atomic(); /* Later stuff after QS. */
91781 break;
91782 }
91783 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91784 rcu_prepare_for_idle(smp_processor_id());
91785 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91786 smp_mb__before_atomic(); /* See above. */
91787 - atomic_inc(&rdtp->dynticks);
91788 + atomic_inc_unchecked(&rdtp->dynticks);
91789 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91790 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91791 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91792
91793 /*
91794 * It is illegal to enter an extended quiescent state while
91795 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91796 int user)
91797 {
91798 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91799 - atomic_inc(&rdtp->dynticks);
91800 + atomic_inc_unchecked(&rdtp->dynticks);
91801 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91802 smp_mb__after_atomic(); /* See above. */
91803 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91804 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91805 rcu_cleanup_after_idle(smp_processor_id());
91806 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91807 if (!user && !is_idle_task(current)) {
91808 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
91809 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91810
91811 if (rdtp->dynticks_nmi_nesting == 0 &&
91812 - (atomic_read(&rdtp->dynticks) & 0x1))
91813 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91814 return;
91815 rdtp->dynticks_nmi_nesting++;
91816 smp_mb__before_atomic(); /* Force delay from prior write. */
91817 - atomic_inc(&rdtp->dynticks);
91818 + atomic_inc_unchecked(&rdtp->dynticks);
91819 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91820 smp_mb__after_atomic(); /* See above. */
91821 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91822 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91823 }
91824
91825 /**
91826 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
91827 return;
91828 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91829 smp_mb__before_atomic(); /* See above. */
91830 - atomic_inc(&rdtp->dynticks);
91831 + atomic_inc_unchecked(&rdtp->dynticks);
91832 smp_mb__after_atomic(); /* Force delay to next write. */
91833 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91834 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91835 }
91836
91837 /**
91838 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
91839 */
91840 bool notrace __rcu_is_watching(void)
91841 {
91842 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91843 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91844 }
91845
91846 /**
91847 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91848 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91849 bool *isidle, unsigned long *maxj)
91850 {
91851 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91852 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91853 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91854 if ((rdp->dynticks_snap & 0x1) == 0) {
91855 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91856 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91857 int *rcrmp;
91858 unsigned int snap;
91859
91860 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91861 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91862 snap = (unsigned int)rdp->dynticks_snap;
91863
91864 /*
91865 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91866 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91867 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91868 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91869 - ACCESS_ONCE(rdp->cond_resched_completed) =
91870 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91871 ACCESS_ONCE(rdp->mynode->completed);
91872 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91873 - ACCESS_ONCE(*rcrmp) =
91874 + ACCESS_ONCE_RW(*rcrmp) =
91875 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
91876 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
91877 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
91878 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
91879 rsp->gp_start = j;
91880 smp_wmb(); /* Record start time before stall time. */
91881 j1 = rcu_jiffies_till_stall_check();
91882 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
91883 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
91884 rsp->jiffies_resched = j + j1 / 2;
91885 }
91886
91887 @@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
91888 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91889 return;
91890 }
91891 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91892 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91893 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91894
91895 /*
91896 @@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
91897
91898 raw_spin_lock_irqsave(&rnp->lock, flags);
91899 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
91900 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
91901 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
91902 3 * rcu_jiffies_till_stall_check() + 3;
91903 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91904
91905 @@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
91906 struct rcu_state *rsp;
91907
91908 for_each_rcu_flavor(rsp)
91909 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91910 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91911 }
91912
91913 /*
91914 @@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
91915 raw_spin_unlock_irq(&rnp->lock);
91916 return 0;
91917 }
91918 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91919 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91920
91921 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
91922 /*
91923 @@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
91924 rdp = this_cpu_ptr(rsp->rda);
91925 rcu_preempt_check_blocked_tasks(rnp);
91926 rnp->qsmask = rnp->qsmaskinit;
91927 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
91928 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
91929 WARN_ON_ONCE(rnp->completed != rsp->completed);
91930 - ACCESS_ONCE(rnp->completed) = rsp->completed;
91931 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
91932 if (rnp == rdp->mynode)
91933 (void)__note_gp_changes(rsp, rnp, rdp);
91934 rcu_preempt_boost_start_gp(rnp);
91935 @@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
91936 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
91937 raw_spin_lock_irq(&rnp->lock);
91938 smp_mb__after_unlock_lock();
91939 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
91940 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
91941 raw_spin_unlock_irq(&rnp->lock);
91942 }
91943 return fqs_state;
91944 @@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91945 rcu_for_each_node_breadth_first(rsp, rnp) {
91946 raw_spin_lock_irq(&rnp->lock);
91947 smp_mb__after_unlock_lock();
91948 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
91949 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
91950 rdp = this_cpu_ptr(rsp->rda);
91951 if (rnp == rdp->mynode)
91952 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
91953 @@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91954 rcu_nocb_gp_set(rnp, nocb);
91955
91956 /* Declare grace period done. */
91957 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
91958 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
91959 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
91960 rsp->fqs_state = RCU_GP_IDLE;
91961 rdp = this_cpu_ptr(rsp->rda);
91962 /* Advance CBs to reduce false positives below. */
91963 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
91964 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91965 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91966 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91967 trace_rcu_grace_period(rsp->name,
91968 ACCESS_ONCE(rsp->gpnum),
91969 TPS("newreq"));
91970 @@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
91971 */
91972 return false;
91973 }
91974 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91975 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91976 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
91977 TPS("newreq"));
91978
91979 @@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
91980 rsp->qlen += rdp->qlen;
91981 rdp->n_cbs_orphaned += rdp->qlen;
91982 rdp->qlen_lazy = 0;
91983 - ACCESS_ONCE(rdp->qlen) = 0;
91984 + ACCESS_ONCE_RW(rdp->qlen) = 0;
91985 }
91986
91987 /*
91988 @@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
91989 }
91990 smp_mb(); /* List handling before counting for rcu_barrier(). */
91991 rdp->qlen_lazy -= count_lazy;
91992 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
91993 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
91994 rdp->n_cbs_invoked += count;
91995
91996 /* Reinstate batch limit if we have worked down the excess. */
91997 @@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
91998 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91999 return; /* Someone beat us to it. */
92000 }
92001 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92002 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92003 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92004 rcu_gp_kthread_wake(rsp);
92005 }
92006 @@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92007 /*
92008 * Do RCU core processing for the current CPU.
92009 */
92010 -static void rcu_process_callbacks(struct softirq_action *unused)
92011 +static void rcu_process_callbacks(void)
92012 {
92013 struct rcu_state *rsp;
92014
92015 @@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92016 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92017 if (debug_rcu_head_queue(head)) {
92018 /* Probable double call_rcu(), so leak the callback. */
92019 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92020 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92021 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92022 return;
92023 }
92024 @@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92025 local_irq_restore(flags);
92026 return;
92027 }
92028 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92029 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92030 if (lazy)
92031 rdp->qlen_lazy++;
92032 else
92033 @@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
92034 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92035 * course be required on a 64-bit system.
92036 */
92037 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92038 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92039 (ulong)atomic_long_read(&rsp->expedited_done) +
92040 ULONG_MAX / 8)) {
92041 synchronize_sched();
92042 - atomic_long_inc(&rsp->expedited_wrap);
92043 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92044 return;
92045 }
92046
92047 @@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
92048 * Take a ticket. Note that atomic_inc_return() implies a
92049 * full memory barrier.
92050 */
92051 - snap = atomic_long_inc_return(&rsp->expedited_start);
92052 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92053 firstsnap = snap;
92054 get_online_cpus();
92055 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92056 @@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
92057 synchronize_sched_expedited_cpu_stop,
92058 NULL) == -EAGAIN) {
92059 put_online_cpus();
92060 - atomic_long_inc(&rsp->expedited_tryfail);
92061 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92062
92063 /* Check to see if someone else did our work for us. */
92064 s = atomic_long_read(&rsp->expedited_done);
92065 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92066 /* ensure test happens before caller kfree */
92067 smp_mb__before_atomic(); /* ^^^ */
92068 - atomic_long_inc(&rsp->expedited_workdone1);
92069 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92070 return;
92071 }
92072
92073 @@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
92074 udelay(trycount * num_online_cpus());
92075 } else {
92076 wait_rcu_gp(call_rcu_sched);
92077 - atomic_long_inc(&rsp->expedited_normal);
92078 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92079 return;
92080 }
92081
92082 @@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
92083 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92084 /* ensure test happens before caller kfree */
92085 smp_mb__before_atomic(); /* ^^^ */
92086 - atomic_long_inc(&rsp->expedited_workdone2);
92087 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92088 return;
92089 }
92090
92091 @@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
92092 * period works for us.
92093 */
92094 get_online_cpus();
92095 - snap = atomic_long_read(&rsp->expedited_start);
92096 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92097 smp_mb(); /* ensure read is before try_stop_cpus(). */
92098 }
92099 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92100 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92101
92102 /*
92103 * Everyone up to our most recent fetch is covered by our grace
92104 @@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
92105 * than we did already did their update.
92106 */
92107 do {
92108 - atomic_long_inc(&rsp->expedited_done_tries);
92109 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92110 s = atomic_long_read(&rsp->expedited_done);
92111 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92112 /* ensure test happens before caller kfree */
92113 smp_mb__before_atomic(); /* ^^^ */
92114 - atomic_long_inc(&rsp->expedited_done_lost);
92115 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92116 break;
92117 }
92118 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92119 - atomic_long_inc(&rsp->expedited_done_exit);
92120 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92121
92122 put_online_cpus();
92123 }
92124 @@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92125 * ACCESS_ONCE() to prevent the compiler from speculating
92126 * the increment to precede the early-exit check.
92127 */
92128 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92129 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92130 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92131 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92132 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92133 @@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92134
92135 /* Increment ->n_barrier_done to prevent duplicate work. */
92136 smp_mb(); /* Keep increment after above mechanism. */
92137 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92138 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92139 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92140 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92141 smp_mb(); /* Keep increment before caller's subsequent code. */
92142 @@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92143 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92144 init_callback_list(rdp);
92145 rdp->qlen_lazy = 0;
92146 - ACCESS_ONCE(rdp->qlen) = 0;
92147 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92148 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92149 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92150 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92151 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92152 rdp->cpu = cpu;
92153 rdp->rsp = rsp;
92154 rcu_boot_init_nocb_percpu_data(rdp);
92155 @@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92156 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92157 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92158 rcu_sysidle_init_percpu_data(rdp->dynticks);
92159 - atomic_set(&rdp->dynticks->dynticks,
92160 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92161 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92162 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92163 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92164
92165 /* Add CPU to rcu_node bitmasks. */
92166 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92167 index 6a86eb7..022b506 100644
92168 --- a/kernel/rcu/tree.h
92169 +++ b/kernel/rcu/tree.h
92170 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92171 long long dynticks_nesting; /* Track irq/process nesting level. */
92172 /* Process level is worth LLONG_MAX/2. */
92173 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92174 - atomic_t dynticks; /* Even value for idle, else odd. */
92175 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92176 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92177 long long dynticks_idle_nesting;
92178 /* irq/process nesting level from idle. */
92179 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92180 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92181 /* "Idle" excludes userspace execution. */
92182 unsigned long dynticks_idle_jiffies;
92183 /* End of last non-NMI non-idle period. */
92184 @@ -461,17 +461,17 @@ struct rcu_state {
92185 /* _rcu_barrier(). */
92186 /* End of fields guarded by barrier_mutex. */
92187
92188 - atomic_long_t expedited_start; /* Starting ticket. */
92189 - atomic_long_t expedited_done; /* Done ticket. */
92190 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92191 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92192 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92193 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92194 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92195 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92196 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92197 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92198 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92199 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92200 + atomic_long_t expedited_done; /* Done ticket. */
92201 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92202 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92203 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92204 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92205 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92206 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92207 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92208 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92209 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92210
92211 unsigned long jiffies_force_qs; /* Time at which to invoke */
92212 /* force_quiescent_state(). */
92213 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92214 index a7997e2..9787c9e 100644
92215 --- a/kernel/rcu/tree_plugin.h
92216 +++ b/kernel/rcu/tree_plugin.h
92217 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92218 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92219 {
92220 return !rcu_preempted_readers_exp(rnp) &&
92221 - ACCESS_ONCE(rnp->expmask) == 0;
92222 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92223 }
92224
92225 /*
92226 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
92227
92228 /* Clean up and exit. */
92229 smp_mb(); /* ensure expedited GP seen before counter increment. */
92230 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
92231 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
92232 unlock_mb_ret:
92233 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92234 mb_ret:
92235 @@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92236 free_cpumask_var(cm);
92237 }
92238
92239 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92240 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92241 .store = &rcu_cpu_kthread_task,
92242 .thread_should_run = rcu_cpu_kthread_should_run,
92243 .thread_fn = rcu_cpu_kthread,
92244 @@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92245 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92246 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92247 cpu, ticks_value, ticks_title,
92248 - atomic_read(&rdtp->dynticks) & 0xfff,
92249 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92250 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92251 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92252 fast_no_hz);
92253 @@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92254 return;
92255 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92256 /* Prior xchg orders against prior callback enqueue. */
92257 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92258 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92259 wake_up(&rdp_leader->nocb_wq);
92260 }
92261 }
92262 @@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92263
92264 /* Enqueue the callback on the nocb list and update counts. */
92265 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92266 - ACCESS_ONCE(*old_rhpp) = rhp;
92267 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92268 atomic_long_add(rhcount, &rdp->nocb_q_count);
92269 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92270
92271 @@ -2272,7 +2272,7 @@ wait_again:
92272 continue; /* No CBs here, try next follower. */
92273
92274 /* Move callbacks to wait-for-GP list, which is empty. */
92275 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92276 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92277 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92278 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92279 rdp->nocb_gp_count_lazy =
92280 @@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
92281 list = ACCESS_ONCE(rdp->nocb_follower_head);
92282 BUG_ON(!list);
92283 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92284 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92285 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92286 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92287 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92288 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92289 @@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
92290 list = next;
92291 }
92292 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92293 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
92294 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
92295 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
92296 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
92297 rdp->n_nocbs_invoked += c;
92298 }
92299 return 0;
92300 @@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92301 {
92302 if (!rcu_nocb_need_deferred_wakeup(rdp))
92303 return;
92304 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
92305 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
92306 wake_nocb_leader(rdp, false);
92307 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
92308 }
92309 @@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
92310 t = kthread_run(rcu_nocb_kthread, rdp,
92311 "rcuo%c/%d", rsp->abbr, cpu);
92312 BUG_ON(IS_ERR(t));
92313 - ACCESS_ONCE(rdp->nocb_kthread) = t;
92314 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
92315 }
92316 }
92317
92318 @@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92319
92320 /* Record start of fully idle period. */
92321 j = jiffies;
92322 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92323 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92324 smp_mb__before_atomic();
92325 - atomic_inc(&rdtp->dynticks_idle);
92326 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92327 smp_mb__after_atomic();
92328 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92329 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92330 }
92331
92332 /*
92333 @@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92334
92335 /* Record end of idle period. */
92336 smp_mb__before_atomic();
92337 - atomic_inc(&rdtp->dynticks_idle);
92338 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92339 smp_mb__after_atomic();
92340 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92341 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92342
92343 /*
92344 * If we are the timekeeping CPU, we are permitted to be non-idle
92345 @@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92346 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92347
92348 /* Pick up current idle and NMI-nesting counter and check. */
92349 - cur = atomic_read(&rdtp->dynticks_idle);
92350 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92351 if (cur & 0x1) {
92352 *isidle = false; /* We are not idle! */
92353 return;
92354 @@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
92355 case RCU_SYSIDLE_NOT:
92356
92357 /* First time all are idle, so note a short idle period. */
92358 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92359 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92360 break;
92361
92362 case RCU_SYSIDLE_SHORT:
92363 @@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
92364 {
92365 smp_mb();
92366 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92367 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92368 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92369 }
92370
92371 /*
92372 @@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92373 smp_mb(); /* grace period precedes setting inuse. */
92374
92375 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92376 - ACCESS_ONCE(rshp->inuse) = 0;
92377 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92378 }
92379
92380 /*
92381 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92382 index 5cdc62e..cc52e88 100644
92383 --- a/kernel/rcu/tree_trace.c
92384 +++ b/kernel/rcu/tree_trace.c
92385 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92386 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92387 rdp->passed_quiesce, rdp->qs_pending);
92388 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92389 - atomic_read(&rdp->dynticks->dynticks),
92390 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92391 rdp->dynticks->dynticks_nesting,
92392 rdp->dynticks->dynticks_nmi_nesting,
92393 rdp->dynticks_fqs);
92394 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92395 struct rcu_state *rsp = (struct rcu_state *)m->private;
92396
92397 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",
92398 - atomic_long_read(&rsp->expedited_start),
92399 + atomic_long_read_unchecked(&rsp->expedited_start),
92400 atomic_long_read(&rsp->expedited_done),
92401 - atomic_long_read(&rsp->expedited_wrap),
92402 - atomic_long_read(&rsp->expedited_tryfail),
92403 - atomic_long_read(&rsp->expedited_workdone1),
92404 - atomic_long_read(&rsp->expedited_workdone2),
92405 - atomic_long_read(&rsp->expedited_normal),
92406 - atomic_long_read(&rsp->expedited_stoppedcpus),
92407 - atomic_long_read(&rsp->expedited_done_tries),
92408 - atomic_long_read(&rsp->expedited_done_lost),
92409 - atomic_long_read(&rsp->expedited_done_exit));
92410 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92411 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92412 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92413 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92414 + atomic_long_read_unchecked(&rsp->expedited_normal),
92415 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92416 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92417 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92418 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92419 return 0;
92420 }
92421
92422 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92423 index 4056d79..c11741a 100644
92424 --- a/kernel/rcu/update.c
92425 +++ b/kernel/rcu/update.c
92426 @@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
92427 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92428 */
92429 if (till_stall_check < 3) {
92430 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92431 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92432 till_stall_check = 3;
92433 } else if (till_stall_check > 300) {
92434 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92435 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92436 till_stall_check = 300;
92437 }
92438 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92439 diff --git a/kernel/resource.c b/kernel/resource.c
92440 index 60c5a38..ed77193 100644
92441 --- a/kernel/resource.c
92442 +++ b/kernel/resource.c
92443 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92444
92445 static int __init ioresources_init(void)
92446 {
92447 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92448 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92449 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92450 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92451 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92452 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92453 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92454 +#endif
92455 +#else
92456 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92457 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92458 +#endif
92459 return 0;
92460 }
92461 __initcall(ioresources_init);
92462 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92463 index e73efba..c9bfbd4 100644
92464 --- a/kernel/sched/auto_group.c
92465 +++ b/kernel/sched/auto_group.c
92466 @@ -11,7 +11,7 @@
92467
92468 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92469 static struct autogroup autogroup_default;
92470 -static atomic_t autogroup_seq_nr;
92471 +static atomic_unchecked_t autogroup_seq_nr;
92472
92473 void __init autogroup_init(struct task_struct *init_task)
92474 {
92475 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92476
92477 kref_init(&ag->kref);
92478 init_rwsem(&ag->lock);
92479 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92480 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92481 ag->tg = tg;
92482 #ifdef CONFIG_RT_GROUP_SCHED
92483 /*
92484 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92485 index a63f4dc..349bbb0 100644
92486 --- a/kernel/sched/completion.c
92487 +++ b/kernel/sched/completion.c
92488 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92489 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92490 * or number of jiffies left till timeout) if completed.
92491 */
92492 -long __sched
92493 +long __sched __intentional_overflow(-1)
92494 wait_for_completion_interruptible_timeout(struct completion *x,
92495 unsigned long timeout)
92496 {
92497 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92498 *
92499 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92500 */
92501 -int __sched wait_for_completion_killable(struct completion *x)
92502 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92503 {
92504 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92505 if (t == -ERESTARTSYS)
92506 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92507 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92508 * or number of jiffies left till timeout) if completed.
92509 */
92510 -long __sched
92511 +long __sched __intentional_overflow(-1)
92512 wait_for_completion_killable_timeout(struct completion *x,
92513 unsigned long timeout)
92514 {
92515 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92516 index 6d7cb91..420f2d2 100644
92517 --- a/kernel/sched/core.c
92518 +++ b/kernel/sched/core.c
92519 @@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
92520 int sysctl_numa_balancing(struct ctl_table *table, int write,
92521 void __user *buffer, size_t *lenp, loff_t *ppos)
92522 {
92523 - struct ctl_table t;
92524 + ctl_table_no_const t;
92525 int err;
92526 int state = numabalancing_enabled;
92527
92528 @@ -2324,8 +2324,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92529 next->active_mm = oldmm;
92530 atomic_inc(&oldmm->mm_count);
92531 enter_lazy_tlb(oldmm, next);
92532 - } else
92533 + } else {
92534 switch_mm(oldmm, mm, next);
92535 + populate_stack();
92536 + }
92537
92538 if (!prev->mm) {
92539 prev->active_mm = NULL;
92540 @@ -3107,6 +3109,8 @@ int can_nice(const struct task_struct *p, const int nice)
92541 /* convert nice value [19,-20] to rlimit style value [1,40] */
92542 int nice_rlim = nice_to_rlimit(nice);
92543
92544 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92545 +
92546 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92547 capable(CAP_SYS_NICE));
92548 }
92549 @@ -3133,7 +3137,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92550 nice = task_nice(current) + increment;
92551
92552 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92553 - if (increment < 0 && !can_nice(current, nice))
92554 + if (increment < 0 && (!can_nice(current, nice) ||
92555 + gr_handle_chroot_nice()))
92556 return -EPERM;
92557
92558 retval = security_task_setnice(current, nice);
92559 @@ -3412,6 +3417,7 @@ recheck:
92560 if (policy != p->policy && !rlim_rtprio)
92561 return -EPERM;
92562
92563 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92564 /* can't increase priority */
92565 if (attr->sched_priority > p->rt_priority &&
92566 attr->sched_priority > rlim_rtprio)
92567 @@ -4802,6 +4808,7 @@ void idle_task_exit(void)
92568
92569 if (mm != &init_mm) {
92570 switch_mm(mm, &init_mm, current);
92571 + populate_stack();
92572 finish_arch_post_lock_switch();
92573 }
92574 mmdrop(mm);
92575 @@ -4897,7 +4904,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92576
92577 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92578
92579 -static struct ctl_table sd_ctl_dir[] = {
92580 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92581 {
92582 .procname = "sched_domain",
92583 .mode = 0555,
92584 @@ -4914,17 +4921,17 @@ static struct ctl_table sd_ctl_root[] = {
92585 {}
92586 };
92587
92588 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92589 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92590 {
92591 - struct ctl_table *entry =
92592 + ctl_table_no_const *entry =
92593 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92594
92595 return entry;
92596 }
92597
92598 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92599 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92600 {
92601 - struct ctl_table *entry;
92602 + ctl_table_no_const *entry;
92603
92604 /*
92605 * In the intermediate directories, both the child directory and
92606 @@ -4932,22 +4939,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92607 * will always be set. In the lowest directory the names are
92608 * static strings and all have proc handlers.
92609 */
92610 - for (entry = *tablep; entry->mode; entry++) {
92611 - if (entry->child)
92612 - sd_free_ctl_entry(&entry->child);
92613 + for (entry = tablep; entry->mode; entry++) {
92614 + if (entry->child) {
92615 + sd_free_ctl_entry(entry->child);
92616 + pax_open_kernel();
92617 + entry->child = NULL;
92618 + pax_close_kernel();
92619 + }
92620 if (entry->proc_handler == NULL)
92621 kfree(entry->procname);
92622 }
92623
92624 - kfree(*tablep);
92625 - *tablep = NULL;
92626 + kfree(tablep);
92627 }
92628
92629 static int min_load_idx = 0;
92630 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92631
92632 static void
92633 -set_table_entry(struct ctl_table *entry,
92634 +set_table_entry(ctl_table_no_const *entry,
92635 const char *procname, void *data, int maxlen,
92636 umode_t mode, proc_handler *proc_handler,
92637 bool load_idx)
92638 @@ -4967,7 +4977,7 @@ set_table_entry(struct ctl_table *entry,
92639 static struct ctl_table *
92640 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92641 {
92642 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92643 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92644
92645 if (table == NULL)
92646 return NULL;
92647 @@ -5005,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92648 return table;
92649 }
92650
92651 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92652 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92653 {
92654 - struct ctl_table *entry, *table;
92655 + ctl_table_no_const *entry, *table;
92656 struct sched_domain *sd;
92657 int domain_num = 0, i;
92658 char buf[32];
92659 @@ -5034,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
92660 static void register_sched_domain_sysctl(void)
92661 {
92662 int i, cpu_num = num_possible_cpus();
92663 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92664 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92665 char buf[32];
92666
92667 WARN_ON(sd_ctl_dir[0].child);
92668 + pax_open_kernel();
92669 sd_ctl_dir[0].child = entry;
92670 + pax_close_kernel();
92671
92672 if (entry == NULL)
92673 return;
92674 @@ -5061,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
92675 if (sd_sysctl_header)
92676 unregister_sysctl_table(sd_sysctl_header);
92677 sd_sysctl_header = NULL;
92678 - if (sd_ctl_dir[0].child)
92679 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
92680 + if (sd_ctl_dir[0].child) {
92681 + sd_free_ctl_entry(sd_ctl_dir[0].child);
92682 + pax_open_kernel();
92683 + sd_ctl_dir[0].child = NULL;
92684 + pax_close_kernel();
92685 + }
92686 }
92687 #else
92688 static void register_sched_domain_sysctl(void)
92689 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92690 index bfa3c86..e58767c 100644
92691 --- a/kernel/sched/fair.c
92692 +++ b/kernel/sched/fair.c
92693 @@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92694
92695 static void reset_ptenuma_scan(struct task_struct *p)
92696 {
92697 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
92698 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92699 p->mm->numa_scan_offset = 0;
92700 }
92701
92702 @@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92703 * run_rebalance_domains is triggered when needed from the scheduler tick.
92704 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92705 */
92706 -static void run_rebalance_domains(struct softirq_action *h)
92707 +static __latent_entropy void run_rebalance_domains(void)
92708 {
92709 struct rq *this_rq = this_rq();
92710 enum cpu_idle_type idle = this_rq->idle_balance ?
92711 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92712 index 579712f..a338a9d 100644
92713 --- a/kernel/sched/sched.h
92714 +++ b/kernel/sched/sched.h
92715 @@ -1146,7 +1146,7 @@ struct sched_class {
92716 #ifdef CONFIG_FAIR_GROUP_SCHED
92717 void (*task_move_group) (struct task_struct *p, int on_rq);
92718 #endif
92719 -};
92720 +} __do_const;
92721
92722 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92723 {
92724 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
92725 index 44eb005..84922be 100644
92726 --- a/kernel/seccomp.c
92727 +++ b/kernel/seccomp.c
92728 @@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
92729 if (!filter)
92730 goto free_prog;
92731
92732 - filter->prog = kzalloc(bpf_prog_size(new_len),
92733 - GFP_KERNEL|__GFP_NOWARN);
92734 + filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
92735 if (!filter->prog)
92736 goto free_filter;
92737
92738 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
92739 if (ret)
92740 goto free_filter_prog;
92741 - kfree(fp);
92742
92743 + kfree(fp);
92744 atomic_set(&filter->usage, 1);
92745 filter->prog->len = new_len;
92746
92747 @@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
92748 return filter;
92749
92750 free_filter_prog:
92751 - kfree(filter->prog);
92752 + __bpf_prog_free(filter->prog);
92753 free_filter:
92754 kfree(filter);
92755 free_prog:
92756 diff --git a/kernel/signal.c b/kernel/signal.c
92757 index 8f0876f..1153a5a 100644
92758 --- a/kernel/signal.c
92759 +++ b/kernel/signal.c
92760 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92761
92762 int print_fatal_signals __read_mostly;
92763
92764 -static void __user *sig_handler(struct task_struct *t, int sig)
92765 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
92766 {
92767 return t->sighand->action[sig - 1].sa.sa_handler;
92768 }
92769
92770 -static int sig_handler_ignored(void __user *handler, int sig)
92771 +static int sig_handler_ignored(__sighandler_t handler, int sig)
92772 {
92773 /* Is it explicitly or implicitly ignored? */
92774 return handler == SIG_IGN ||
92775 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92776
92777 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92778 {
92779 - void __user *handler;
92780 + __sighandler_t handler;
92781
92782 handler = sig_handler(t, sig);
92783
92784 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92785 atomic_inc(&user->sigpending);
92786 rcu_read_unlock();
92787
92788 + if (!override_rlimit)
92789 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92790 +
92791 if (override_rlimit ||
92792 atomic_read(&user->sigpending) <=
92793 task_rlimit(t, RLIMIT_SIGPENDING)) {
92794 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92795
92796 int unhandled_signal(struct task_struct *tsk, int sig)
92797 {
92798 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92799 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92800 if (is_global_init(tsk))
92801 return 1;
92802 if (handler != SIG_IGN && handler != SIG_DFL)
92803 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92804 }
92805 }
92806
92807 + /* allow glibc communication via tgkill to other threads in our
92808 + thread group */
92809 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92810 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92811 + && gr_handle_signal(t, sig))
92812 + return -EPERM;
92813 +
92814 return security_task_kill(t, info, sig, 0);
92815 }
92816
92817 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92818 return send_signal(sig, info, p, 1);
92819 }
92820
92821 -static int
92822 +int
92823 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92824 {
92825 return send_signal(sig, info, t, 0);
92826 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92827 unsigned long int flags;
92828 int ret, blocked, ignored;
92829 struct k_sigaction *action;
92830 + int is_unhandled = 0;
92831
92832 spin_lock_irqsave(&t->sighand->siglock, flags);
92833 action = &t->sighand->action[sig-1];
92834 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92835 }
92836 if (action->sa.sa_handler == SIG_DFL)
92837 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92838 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92839 + is_unhandled = 1;
92840 ret = specific_send_sig_info(sig, info, t);
92841 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92842
92843 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
92844 + normal operation */
92845 + if (is_unhandled) {
92846 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92847 + gr_handle_crash(t, sig);
92848 + }
92849 +
92850 return ret;
92851 }
92852
92853 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92854 ret = check_kill_permission(sig, info, p);
92855 rcu_read_unlock();
92856
92857 - if (!ret && sig)
92858 + if (!ret && sig) {
92859 ret = do_send_sig_info(sig, info, p, true);
92860 + if (!ret)
92861 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92862 + }
92863
92864 return ret;
92865 }
92866 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92867 int error = -ESRCH;
92868
92869 rcu_read_lock();
92870 - p = find_task_by_vpid(pid);
92871 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92872 + /* allow glibc communication via tgkill to other threads in our
92873 + thread group */
92874 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
92875 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
92876 + p = find_task_by_vpid_unrestricted(pid);
92877 + else
92878 +#endif
92879 + p = find_task_by_vpid(pid);
92880 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
92881 error = check_kill_permission(sig, info, p);
92882 /*
92883 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
92884 }
92885 seg = get_fs();
92886 set_fs(KERNEL_DS);
92887 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
92888 - (stack_t __force __user *) &uoss,
92889 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
92890 + (stack_t __force_user *) &uoss,
92891 compat_user_stack_pointer());
92892 set_fs(seg);
92893 if (ret >= 0 && uoss_ptr) {
92894 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
92895 index eb89e18..a4e6792 100644
92896 --- a/kernel/smpboot.c
92897 +++ b/kernel/smpboot.c
92898 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
92899 }
92900 smpboot_unpark_thread(plug_thread, cpu);
92901 }
92902 - list_add(&plug_thread->list, &hotplug_threads);
92903 + pax_list_add(&plug_thread->list, &hotplug_threads);
92904 out:
92905 mutex_unlock(&smpboot_threads_lock);
92906 return ret;
92907 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
92908 {
92909 get_online_cpus();
92910 mutex_lock(&smpboot_threads_lock);
92911 - list_del(&plug_thread->list);
92912 + pax_list_del(&plug_thread->list);
92913 smpboot_destroy_threads(plug_thread);
92914 mutex_unlock(&smpboot_threads_lock);
92915 put_online_cpus();
92916 diff --git a/kernel/softirq.c b/kernel/softirq.c
92917 index 5918d22..e95d1926 100644
92918 --- a/kernel/softirq.c
92919 +++ b/kernel/softirq.c
92920 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
92921 EXPORT_SYMBOL(irq_stat);
92922 #endif
92923
92924 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
92925 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
92926
92927 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
92928
92929 @@ -266,7 +266,7 @@ restart:
92930 kstat_incr_softirqs_this_cpu(vec_nr);
92931
92932 trace_softirq_entry(vec_nr);
92933 - h->action(h);
92934 + h->action();
92935 trace_softirq_exit(vec_nr);
92936 if (unlikely(prev_count != preempt_count())) {
92937 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
92938 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
92939 or_softirq_pending(1UL << nr);
92940 }
92941
92942 -void open_softirq(int nr, void (*action)(struct softirq_action *))
92943 +void __init open_softirq(int nr, void (*action)(void))
92944 {
92945 softirq_vec[nr].action = action;
92946 }
92947 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
92948 }
92949 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
92950
92951 -static void tasklet_action(struct softirq_action *a)
92952 +static void tasklet_action(void)
92953 {
92954 struct tasklet_struct *list;
92955
92956 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
92957 }
92958 }
92959
92960 -static void tasklet_hi_action(struct softirq_action *a)
92961 +static __latent_entropy void tasklet_hi_action(void)
92962 {
92963 struct tasklet_struct *list;
92964
92965 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
92966 .notifier_call = cpu_callback
92967 };
92968
92969 -static struct smp_hotplug_thread softirq_threads = {
92970 +static struct smp_hotplug_thread softirq_threads __read_only = {
92971 .store = &ksoftirqd,
92972 .thread_should_run = ksoftirqd_should_run,
92973 .thread_fn = run_ksoftirqd,
92974 diff --git a/kernel/sys.c b/kernel/sys.c
92975 index ce81291..df2ca85 100644
92976 --- a/kernel/sys.c
92977 +++ b/kernel/sys.c
92978 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
92979 error = -EACCES;
92980 goto out;
92981 }
92982 +
92983 + if (gr_handle_chroot_setpriority(p, niceval)) {
92984 + error = -EACCES;
92985 + goto out;
92986 + }
92987 +
92988 no_nice = security_task_setnice(p, niceval);
92989 if (no_nice) {
92990 error = no_nice;
92991 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
92992 goto error;
92993 }
92994
92995 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
92996 + goto error;
92997 +
92998 + if (!gid_eq(new->gid, old->gid)) {
92999 + /* make sure we generate a learn log for what will
93000 + end up being a role transition after a full-learning
93001 + policy is generated
93002 + CAP_SETGID is required to perform a transition
93003 + we may not log a CAP_SETGID check above, e.g.
93004 + in the case where new rgid = old egid
93005 + */
93006 + gr_learn_cap(current, new, CAP_SETGID);
93007 + }
93008 +
93009 if (rgid != (gid_t) -1 ||
93010 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93011 new->sgid = new->egid;
93012 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93013 old = current_cred();
93014
93015 retval = -EPERM;
93016 +
93017 + if (gr_check_group_change(kgid, kgid, kgid))
93018 + goto error;
93019 +
93020 if (ns_capable(old->user_ns, CAP_SETGID))
93021 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93022 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93023 @@ -403,7 +427,7 @@ error:
93024 /*
93025 * change the user struct in a credentials set to match the new UID
93026 */
93027 -static int set_user(struct cred *new)
93028 +int set_user(struct cred *new)
93029 {
93030 struct user_struct *new_user;
93031
93032 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93033 goto error;
93034 }
93035
93036 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93037 + goto error;
93038 +
93039 if (!uid_eq(new->uid, old->uid)) {
93040 + /* make sure we generate a learn log for what will
93041 + end up being a role transition after a full-learning
93042 + policy is generated
93043 + CAP_SETUID is required to perform a transition
93044 + we may not log a CAP_SETUID check above, e.g.
93045 + in the case where new ruid = old euid
93046 + */
93047 + gr_learn_cap(current, new, CAP_SETUID);
93048 retval = set_user(new);
93049 if (retval < 0)
93050 goto error;
93051 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93052 old = current_cred();
93053
93054 retval = -EPERM;
93055 +
93056 + if (gr_check_crash_uid(kuid))
93057 + goto error;
93058 + if (gr_check_user_change(kuid, kuid, kuid))
93059 + goto error;
93060 +
93061 if (ns_capable(old->user_ns, CAP_SETUID)) {
93062 new->suid = new->uid = kuid;
93063 if (!uid_eq(kuid, old->uid)) {
93064 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93065 goto error;
93066 }
93067
93068 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93069 + goto error;
93070 +
93071 if (ruid != (uid_t) -1) {
93072 new->uid = kruid;
93073 if (!uid_eq(kruid, old->uid)) {
93074 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93075 goto error;
93076 }
93077
93078 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93079 + goto error;
93080 +
93081 if (rgid != (gid_t) -1)
93082 new->gid = krgid;
93083 if (egid != (gid_t) -1)
93084 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93085 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93086 ns_capable(old->user_ns, CAP_SETUID)) {
93087 if (!uid_eq(kuid, old->fsuid)) {
93088 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93089 + goto error;
93090 +
93091 new->fsuid = kuid;
93092 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93093 goto change_okay;
93094 }
93095 }
93096
93097 +error:
93098 abort_creds(new);
93099 return old_fsuid;
93100
93101 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93102 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93103 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93104 ns_capable(old->user_ns, CAP_SETGID)) {
93105 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93106 + goto error;
93107 +
93108 if (!gid_eq(kgid, old->fsgid)) {
93109 new->fsgid = kgid;
93110 goto change_okay;
93111 }
93112 }
93113
93114 +error:
93115 abort_creds(new);
93116 return old_fsgid;
93117
93118 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93119 return -EFAULT;
93120
93121 down_read(&uts_sem);
93122 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93123 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93124 __OLD_UTS_LEN);
93125 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93126 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93127 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93128 __OLD_UTS_LEN);
93129 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93130 - error |= __copy_to_user(&name->release, &utsname()->release,
93131 + error |= __copy_to_user(name->release, &utsname()->release,
93132 __OLD_UTS_LEN);
93133 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93134 - error |= __copy_to_user(&name->version, &utsname()->version,
93135 + error |= __copy_to_user(name->version, &utsname()->version,
93136 __OLD_UTS_LEN);
93137 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93138 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93139 + error |= __copy_to_user(name->machine, &utsname()->machine,
93140 __OLD_UTS_LEN);
93141 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93142 up_read(&uts_sem);
93143 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93144 */
93145 new_rlim->rlim_cur = 1;
93146 }
93147 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93148 + is changed to a lower value. Since tasks can be created by the same
93149 + user in between this limit change and an execve by this task, force
93150 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93151 + */
93152 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93153 + tsk->flags |= PF_NPROC_EXCEEDED;
93154 }
93155 if (!retval) {
93156 if (old_rlim)
93157 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93158 index 75875a7..cd8e838 100644
93159 --- a/kernel/sysctl.c
93160 +++ b/kernel/sysctl.c
93161 @@ -94,7 +94,6 @@
93162
93163
93164 #if defined(CONFIG_SYSCTL)
93165 -
93166 /* External variables not in a header file. */
93167 extern int max_threads;
93168 extern int suid_dumpable;
93169 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93170
93171 /* Constants used for minimum and maximum */
93172 #ifdef CONFIG_LOCKUP_DETECTOR
93173 -static int sixty = 60;
93174 +static int sixty __read_only = 60;
93175 #endif
93176
93177 -static int __maybe_unused neg_one = -1;
93178 +static int __maybe_unused neg_one __read_only = -1;
93179
93180 -static int zero;
93181 -static int __maybe_unused one = 1;
93182 -static int __maybe_unused two = 2;
93183 -static int __maybe_unused four = 4;
93184 -static unsigned long one_ul = 1;
93185 -static int one_hundred = 100;
93186 +static int zero __read_only = 0;
93187 +static int __maybe_unused one __read_only = 1;
93188 +static int __maybe_unused two __read_only = 2;
93189 +static int __maybe_unused three __read_only = 3;
93190 +static int __maybe_unused four __read_only = 4;
93191 +static unsigned long one_ul __read_only = 1;
93192 +static int one_hundred __read_only = 100;
93193 #ifdef CONFIG_PRINTK
93194 -static int ten_thousand = 10000;
93195 +static int ten_thousand __read_only = 10000;
93196 #endif
93197
93198 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93199 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93200 void __user *buffer, size_t *lenp, loff_t *ppos);
93201 #endif
93202
93203 -#ifdef CONFIG_PRINTK
93204 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93205 void __user *buffer, size_t *lenp, loff_t *ppos);
93206 -#endif
93207
93208 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93209 void __user *buffer, size_t *lenp, loff_t *ppos);
93210 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93211
93212 #endif
93213
93214 +extern struct ctl_table grsecurity_table[];
93215 +
93216 static struct ctl_table kern_table[];
93217 static struct ctl_table vm_table[];
93218 static struct ctl_table fs_table[];
93219 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93220 int sysctl_legacy_va_layout;
93221 #endif
93222
93223 +#ifdef CONFIG_PAX_SOFTMODE
93224 +static struct ctl_table pax_table[] = {
93225 + {
93226 + .procname = "softmode",
93227 + .data = &pax_softmode,
93228 + .maxlen = sizeof(unsigned int),
93229 + .mode = 0600,
93230 + .proc_handler = &proc_dointvec,
93231 + },
93232 +
93233 + { }
93234 +};
93235 +#endif
93236 +
93237 /* The default sysctl tables: */
93238
93239 static struct ctl_table sysctl_base_table[] = {
93240 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93241 #endif
93242
93243 static struct ctl_table kern_table[] = {
93244 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93245 + {
93246 + .procname = "grsecurity",
93247 + .mode = 0500,
93248 + .child = grsecurity_table,
93249 + },
93250 +#endif
93251 +
93252 +#ifdef CONFIG_PAX_SOFTMODE
93253 + {
93254 + .procname = "pax",
93255 + .mode = 0500,
93256 + .child = pax_table,
93257 + },
93258 +#endif
93259 +
93260 {
93261 .procname = "sched_child_runs_first",
93262 .data = &sysctl_sched_child_runs_first,
93263 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
93264 .data = &modprobe_path,
93265 .maxlen = KMOD_PATH_LEN,
93266 .mode = 0644,
93267 - .proc_handler = proc_dostring,
93268 + .proc_handler = proc_dostring_modpriv,
93269 },
93270 {
93271 .procname = "modules_disabled",
93272 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
93273 .extra1 = &zero,
93274 .extra2 = &one,
93275 },
93276 +#endif
93277 {
93278 .procname = "kptr_restrict",
93279 .data = &kptr_restrict,
93280 .maxlen = sizeof(int),
93281 .mode = 0644,
93282 .proc_handler = proc_dointvec_minmax_sysadmin,
93283 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93284 + .extra1 = &two,
93285 +#else
93286 .extra1 = &zero,
93287 +#endif
93288 .extra2 = &two,
93289 },
93290 -#endif
93291 {
93292 .procname = "ngroups_max",
93293 .data = &ngroups_max,
93294 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
93295 */
93296 {
93297 .procname = "perf_event_paranoid",
93298 - .data = &sysctl_perf_event_paranoid,
93299 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93300 + .data = &sysctl_perf_event_legitimately_concerned,
93301 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93302 .mode = 0644,
93303 - .proc_handler = proc_dointvec,
93304 + /* go ahead, be a hero */
93305 + .proc_handler = proc_dointvec_minmax_sysadmin,
93306 + .extra1 = &neg_one,
93307 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93308 + .extra2 = &three,
93309 +#else
93310 + .extra2 = &two,
93311 +#endif
93312 },
93313 {
93314 .procname = "perf_event_mlock_kb",
93315 @@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
93316 .proc_handler = proc_dointvec_minmax,
93317 .extra1 = &zero,
93318 },
93319 + {
93320 + .procname = "heap_stack_gap",
93321 + .data = &sysctl_heap_stack_gap,
93322 + .maxlen = sizeof(sysctl_heap_stack_gap),
93323 + .mode = 0644,
93324 + .proc_handler = proc_doulongvec_minmax,
93325 + },
93326 #else
93327 {
93328 .procname = "nr_trim_pages",
93329 @@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
93330 (char __user *)buffer, lenp, ppos);
93331 }
93332
93333 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93334 + void __user *buffer, size_t *lenp, loff_t *ppos)
93335 +{
93336 + if (write && !capable(CAP_SYS_MODULE))
93337 + return -EPERM;
93338 +
93339 + return _proc_do_string(table->data, table->maxlen, write,
93340 + buffer, lenp, ppos);
93341 +}
93342 +
93343 static size_t proc_skip_spaces(char **buf)
93344 {
93345 size_t ret;
93346 @@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93347 len = strlen(tmp);
93348 if (len > *size)
93349 len = *size;
93350 + if (len > sizeof(tmp))
93351 + len = sizeof(tmp);
93352 if (copy_to_user(*buf, tmp, len))
93353 return -EFAULT;
93354 *size -= len;
93355 @@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93356 static int proc_taint(struct ctl_table *table, int write,
93357 void __user *buffer, size_t *lenp, loff_t *ppos)
93358 {
93359 - struct ctl_table t;
93360 + ctl_table_no_const t;
93361 unsigned long tmptaint = get_taint();
93362 int err;
93363
93364 @@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
93365 return err;
93366 }
93367
93368 -#ifdef CONFIG_PRINTK
93369 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93370 void __user *buffer, size_t *lenp, loff_t *ppos)
93371 {
93372 @@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93373
93374 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93375 }
93376 -#endif
93377
93378 struct do_proc_dointvec_minmax_conv_param {
93379 int *min;
93380 @@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
93381 return -ENOSYS;
93382 }
93383
93384 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93385 + void __user *buffer, size_t *lenp, loff_t *ppos)
93386 +{
93387 + return -ENOSYS;
93388 +}
93389 +
93390 int proc_dointvec(struct ctl_table *table, int write,
93391 void __user *buffer, size_t *lenp, loff_t *ppos)
93392 {
93393 @@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93394 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93395 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93396 EXPORT_SYMBOL(proc_dostring);
93397 +EXPORT_SYMBOL(proc_dostring_modpriv);
93398 EXPORT_SYMBOL(proc_doulongvec_minmax);
93399 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93400 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93401 index 13d2f7c..c93d0b0 100644
93402 --- a/kernel/taskstats.c
93403 +++ b/kernel/taskstats.c
93404 @@ -28,9 +28,12 @@
93405 #include <linux/fs.h>
93406 #include <linux/file.h>
93407 #include <linux/pid_namespace.h>
93408 +#include <linux/grsecurity.h>
93409 #include <net/genetlink.h>
93410 #include <linux/atomic.h>
93411
93412 +extern int gr_is_taskstats_denied(int pid);
93413 +
93414 /*
93415 * Maximum length of a cpumask that can be specified in
93416 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93417 @@ -576,6 +579,9 @@ err:
93418
93419 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93420 {
93421 + if (gr_is_taskstats_denied(current->pid))
93422 + return -EACCES;
93423 +
93424 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93425 return cmd_attr_register_cpumask(info);
93426 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93427 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93428 index a7077d3..dd48a49 100644
93429 --- a/kernel/time/alarmtimer.c
93430 +++ b/kernel/time/alarmtimer.c
93431 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93432 struct platform_device *pdev;
93433 int error = 0;
93434 int i;
93435 - struct k_clock alarm_clock = {
93436 + static struct k_clock alarm_clock = {
93437 .clock_getres = alarm_clock_getres,
93438 .clock_get = alarm_clock_get,
93439 .timer_create = alarm_timer_create,
93440 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93441 index 1c2fe7d..ce7483d 100644
93442 --- a/kernel/time/hrtimer.c
93443 +++ b/kernel/time/hrtimer.c
93444 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93445 local_irq_restore(flags);
93446 }
93447
93448 -static void run_hrtimer_softirq(struct softirq_action *h)
93449 +static __latent_entropy void run_hrtimer_softirq(void)
93450 {
93451 hrtimer_peek_ahead_timers();
93452 }
93453 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93454 index 3b89464..5e38379 100644
93455 --- a/kernel/time/posix-cpu-timers.c
93456 +++ b/kernel/time/posix-cpu-timers.c
93457 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93458
93459 static __init int init_posix_cpu_timers(void)
93460 {
93461 - struct k_clock process = {
93462 + static struct k_clock process = {
93463 .clock_getres = process_cpu_clock_getres,
93464 .clock_get = process_cpu_clock_get,
93465 .timer_create = process_cpu_timer_create,
93466 .nsleep = process_cpu_nsleep,
93467 .nsleep_restart = process_cpu_nsleep_restart,
93468 };
93469 - struct k_clock thread = {
93470 + static struct k_clock thread = {
93471 .clock_getres = thread_cpu_clock_getres,
93472 .clock_get = thread_cpu_clock_get,
93473 .timer_create = thread_cpu_timer_create,
93474 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93475 index 31ea01f..7fc61ef 100644
93476 --- a/kernel/time/posix-timers.c
93477 +++ b/kernel/time/posix-timers.c
93478 @@ -43,6 +43,7 @@
93479 #include <linux/hash.h>
93480 #include <linux/posix-clock.h>
93481 #include <linux/posix-timers.h>
93482 +#include <linux/grsecurity.h>
93483 #include <linux/syscalls.h>
93484 #include <linux/wait.h>
93485 #include <linux/workqueue.h>
93486 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93487 * which we beg off on and pass to do_sys_settimeofday().
93488 */
93489
93490 -static struct k_clock posix_clocks[MAX_CLOCKS];
93491 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93492
93493 /*
93494 * These ones are defined below.
93495 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93496 */
93497 static __init int init_posix_timers(void)
93498 {
93499 - struct k_clock clock_realtime = {
93500 + static struct k_clock clock_realtime = {
93501 .clock_getres = hrtimer_get_res,
93502 .clock_get = posix_clock_realtime_get,
93503 .clock_set = posix_clock_realtime_set,
93504 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93505 .timer_get = common_timer_get,
93506 .timer_del = common_timer_del,
93507 };
93508 - struct k_clock clock_monotonic = {
93509 + static struct k_clock clock_monotonic = {
93510 .clock_getres = hrtimer_get_res,
93511 .clock_get = posix_ktime_get_ts,
93512 .nsleep = common_nsleep,
93513 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93514 .timer_get = common_timer_get,
93515 .timer_del = common_timer_del,
93516 };
93517 - struct k_clock clock_monotonic_raw = {
93518 + static struct k_clock clock_monotonic_raw = {
93519 .clock_getres = hrtimer_get_res,
93520 .clock_get = posix_get_monotonic_raw,
93521 };
93522 - struct k_clock clock_realtime_coarse = {
93523 + static struct k_clock clock_realtime_coarse = {
93524 .clock_getres = posix_get_coarse_res,
93525 .clock_get = posix_get_realtime_coarse,
93526 };
93527 - struct k_clock clock_monotonic_coarse = {
93528 + static struct k_clock clock_monotonic_coarse = {
93529 .clock_getres = posix_get_coarse_res,
93530 .clock_get = posix_get_monotonic_coarse,
93531 };
93532 - struct k_clock clock_tai = {
93533 + static struct k_clock clock_tai = {
93534 .clock_getres = hrtimer_get_res,
93535 .clock_get = posix_get_tai,
93536 .nsleep = common_nsleep,
93537 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93538 .timer_get = common_timer_get,
93539 .timer_del = common_timer_del,
93540 };
93541 - struct k_clock clock_boottime = {
93542 + static struct k_clock clock_boottime = {
93543 .clock_getres = hrtimer_get_res,
93544 .clock_get = posix_get_boottime,
93545 .nsleep = common_nsleep,
93546 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93547 return;
93548 }
93549
93550 - posix_clocks[clock_id] = *new_clock;
93551 + posix_clocks[clock_id] = new_clock;
93552 }
93553 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93554
93555 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93556 return (id & CLOCKFD_MASK) == CLOCKFD ?
93557 &clock_posix_dynamic : &clock_posix_cpu;
93558
93559 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93560 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93561 return NULL;
93562 - return &posix_clocks[id];
93563 + return posix_clocks[id];
93564 }
93565
93566 static int common_timer_create(struct k_itimer *new_timer)
93567 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93568 struct k_clock *kc = clockid_to_kclock(which_clock);
93569 struct k_itimer *new_timer;
93570 int error, new_timer_id;
93571 - sigevent_t event;
93572 + sigevent_t event = { };
93573 int it_id_set = IT_ID_NOT_SET;
93574
93575 if (!kc)
93576 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93577 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93578 return -EFAULT;
93579
93580 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93581 + have their clock_set fptr set to a nosettime dummy function
93582 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93583 + call common_clock_set, which calls do_sys_settimeofday, which
93584 + we hook
93585 + */
93586 +
93587 return kc->clock_set(which_clock, &new_tp);
93588 }
93589
93590 diff --git a/kernel/time/time.c b/kernel/time/time.c
93591 index a9ae20f..d3fbde7 100644
93592 --- a/kernel/time/time.c
93593 +++ b/kernel/time/time.c
93594 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93595 return error;
93596
93597 if (tz) {
93598 + /* we log in do_settimeofday called below, so don't log twice
93599 + */
93600 + if (!tv)
93601 + gr_log_timechange();
93602 +
93603 sys_tz = *tz;
93604 update_vsyscall_tz();
93605 if (firsttime) {
93606 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93607 index ec1791f..6a086cd 100644
93608 --- a/kernel/time/timekeeping.c
93609 +++ b/kernel/time/timekeeping.c
93610 @@ -15,6 +15,7 @@
93611 #include <linux/init.h>
93612 #include <linux/mm.h>
93613 #include <linux/sched.h>
93614 +#include <linux/grsecurity.h>
93615 #include <linux/syscore_ops.h>
93616 #include <linux/clocksource.h>
93617 #include <linux/jiffies.h>
93618 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93619 if (!timespec_valid_strict(tv))
93620 return -EINVAL;
93621
93622 + gr_log_timechange();
93623 +
93624 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93625 write_seqcount_begin(&tk_core.seq);
93626
93627 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93628 index 9bbb834..3caa8ed 100644
93629 --- a/kernel/time/timer.c
93630 +++ b/kernel/time/timer.c
93631 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93632 /*
93633 * This function runs timers and the timer-tq in bottom half context.
93634 */
93635 -static void run_timer_softirq(struct softirq_action *h)
93636 +static __latent_entropy void run_timer_softirq(void)
93637 {
93638 struct tvec_base *base = __this_cpu_read(tvec_bases);
93639
93640 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93641 *
93642 * In all cases the return value is guaranteed to be non-negative.
93643 */
93644 -signed long __sched schedule_timeout(signed long timeout)
93645 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93646 {
93647 struct timer_list timer;
93648 unsigned long expire;
93649 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93650 index 61ed862..3b52c65 100644
93651 --- a/kernel/time/timer_list.c
93652 +++ b/kernel/time/timer_list.c
93653 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93654
93655 static void print_name_offset(struct seq_file *m, void *sym)
93656 {
93657 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93658 + SEQ_printf(m, "<%p>", NULL);
93659 +#else
93660 char symname[KSYM_NAME_LEN];
93661
93662 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93663 SEQ_printf(m, "<%pK>", sym);
93664 else
93665 SEQ_printf(m, "%s", symname);
93666 +#endif
93667 }
93668
93669 static void
93670 @@ -119,7 +123,11 @@ next_one:
93671 static void
93672 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93673 {
93674 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93675 + SEQ_printf(m, " .base: %p\n", NULL);
93676 +#else
93677 SEQ_printf(m, " .base: %pK\n", base);
93678 +#endif
93679 SEQ_printf(m, " .index: %d\n",
93680 base->index);
93681 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93682 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93683 {
93684 struct proc_dir_entry *pe;
93685
93686 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93687 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93688 +#else
93689 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93690 +#endif
93691 if (!pe)
93692 return -ENOMEM;
93693 return 0;
93694 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93695 index 1fb08f2..ca4bb1e 100644
93696 --- a/kernel/time/timer_stats.c
93697 +++ b/kernel/time/timer_stats.c
93698 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93699 static unsigned long nr_entries;
93700 static struct entry entries[MAX_ENTRIES];
93701
93702 -static atomic_t overflow_count;
93703 +static atomic_unchecked_t overflow_count;
93704
93705 /*
93706 * The entries are in a hash-table, for fast lookup:
93707 @@ -140,7 +140,7 @@ static void reset_entries(void)
93708 nr_entries = 0;
93709 memset(entries, 0, sizeof(entries));
93710 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93711 - atomic_set(&overflow_count, 0);
93712 + atomic_set_unchecked(&overflow_count, 0);
93713 }
93714
93715 static struct entry *alloc_entry(void)
93716 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93717 if (likely(entry))
93718 entry->count++;
93719 else
93720 - atomic_inc(&overflow_count);
93721 + atomic_inc_unchecked(&overflow_count);
93722
93723 out_unlock:
93724 raw_spin_unlock_irqrestore(lock, flags);
93725 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93726
93727 static void print_name_offset(struct seq_file *m, unsigned long addr)
93728 {
93729 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93730 + seq_printf(m, "<%p>", NULL);
93731 +#else
93732 char symname[KSYM_NAME_LEN];
93733
93734 if (lookup_symbol_name(addr, symname) < 0)
93735 - seq_printf(m, "<%p>", (void *)addr);
93736 + seq_printf(m, "<%pK>", (void *)addr);
93737 else
93738 seq_printf(m, "%s", symname);
93739 +#endif
93740 }
93741
93742 static int tstats_show(struct seq_file *m, void *v)
93743 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93744
93745 seq_puts(m, "Timer Stats Version: v0.3\n");
93746 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93747 - if (atomic_read(&overflow_count))
93748 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93749 + if (atomic_read_unchecked(&overflow_count))
93750 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93751 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93752
93753 for (i = 0; i < nr_entries; i++) {
93754 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93755 {
93756 struct proc_dir_entry *pe;
93757
93758 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93759 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93760 +#else
93761 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93762 +#endif
93763 if (!pe)
93764 return -ENOMEM;
93765 return 0;
93766 diff --git a/kernel/torture.c b/kernel/torture.c
93767 index d600af2..27a4e9d 100644
93768 --- a/kernel/torture.c
93769 +++ b/kernel/torture.c
93770 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93771 mutex_lock(&fullstop_mutex);
93772 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93773 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93774 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93775 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93776 } else {
93777 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93778 }
93779 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
93780 if (!torture_must_stop()) {
93781 if (stutter > 1) {
93782 schedule_timeout_interruptible(stutter - 1);
93783 - ACCESS_ONCE(stutter_pause_test) = 2;
93784 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
93785 }
93786 schedule_timeout_interruptible(1);
93787 - ACCESS_ONCE(stutter_pause_test) = 1;
93788 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
93789 }
93790 if (!torture_must_stop())
93791 schedule_timeout_interruptible(stutter);
93792 - ACCESS_ONCE(stutter_pause_test) = 0;
93793 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
93794 torture_shutdown_absorb("torture_stutter");
93795 } while (!torture_must_stop());
93796 torture_kthread_stopping("torture_stutter");
93797 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
93798 schedule_timeout_uninterruptible(10);
93799 return true;
93800 }
93801 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93802 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93803 mutex_unlock(&fullstop_mutex);
93804 torture_shutdown_cleanup();
93805 torture_shuffle_cleanup();
93806 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93807 index c1bd4ad..4b861dc 100644
93808 --- a/kernel/trace/blktrace.c
93809 +++ b/kernel/trace/blktrace.c
93810 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93811 struct blk_trace *bt = filp->private_data;
93812 char buf[16];
93813
93814 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93815 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93816
93817 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93818 }
93819 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93820 return 1;
93821
93822 bt = buf->chan->private_data;
93823 - atomic_inc(&bt->dropped);
93824 + atomic_inc_unchecked(&bt->dropped);
93825 return 0;
93826 }
93827
93828 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93829
93830 bt->dir = dir;
93831 bt->dev = dev;
93832 - atomic_set(&bt->dropped, 0);
93833 + atomic_set_unchecked(&bt->dropped, 0);
93834 INIT_LIST_HEAD(&bt->running_list);
93835
93836 ret = -EIO;
93837 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93838 index 5916a8e..5cd3b1f 100644
93839 --- a/kernel/trace/ftrace.c
93840 +++ b/kernel/trace/ftrace.c
93841 @@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93842 if (unlikely(ftrace_disabled))
93843 return 0;
93844
93845 + ret = ftrace_arch_code_modify_prepare();
93846 + FTRACE_WARN_ON(ret);
93847 + if (ret)
93848 + return 0;
93849 +
93850 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93851 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93852 if (ret) {
93853 ftrace_bug(ret, ip);
93854 - return 0;
93855 }
93856 - return 1;
93857 + return ret ? 0 : 1;
93858 }
93859
93860 /*
93861 @@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
93862 if (!count)
93863 return 0;
93864
93865 + pax_open_kernel();
93866 sort(start, count, sizeof(*start),
93867 ftrace_cmp_ips, ftrace_swap_ips);
93868 + pax_close_kernel();
93869
93870 start_pg = ftrace_allocate_pages(count);
93871 if (!start_pg)
93872 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93873 index a56e07c..d46f0ba 100644
93874 --- a/kernel/trace/ring_buffer.c
93875 +++ b/kernel/trace/ring_buffer.c
93876 @@ -352,9 +352,9 @@ struct buffer_data_page {
93877 */
93878 struct buffer_page {
93879 struct list_head list; /* list of buffer pages */
93880 - local_t write; /* index for next write */
93881 + local_unchecked_t write; /* index for next write */
93882 unsigned read; /* index for next read */
93883 - local_t entries; /* entries on this page */
93884 + local_unchecked_t entries; /* entries on this page */
93885 unsigned long real_end; /* real end of data */
93886 struct buffer_data_page *page; /* Actual data page */
93887 };
93888 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
93889 unsigned long last_overrun;
93890 local_t entries_bytes;
93891 local_t entries;
93892 - local_t overrun;
93893 - local_t commit_overrun;
93894 + local_unchecked_t overrun;
93895 + local_unchecked_t commit_overrun;
93896 local_t dropped_events;
93897 local_t committing;
93898 local_t commits;
93899 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93900 *
93901 * We add a counter to the write field to denote this.
93902 */
93903 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
93904 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
93905 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
93906 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
93907
93908 /*
93909 * Just make sure we have seen our old_write and synchronize
93910 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93911 * cmpxchg to only update if an interrupt did not already
93912 * do it for us. If the cmpxchg fails, we don't care.
93913 */
93914 - (void)local_cmpxchg(&next_page->write, old_write, val);
93915 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
93916 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
93917 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
93918
93919 /*
93920 * No need to worry about races with clearing out the commit.
93921 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
93922
93923 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
93924 {
93925 - return local_read(&bpage->entries) & RB_WRITE_MASK;
93926 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
93927 }
93928
93929 static inline unsigned long rb_page_write(struct buffer_page *bpage)
93930 {
93931 - return local_read(&bpage->write) & RB_WRITE_MASK;
93932 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
93933 }
93934
93935 static int
93936 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
93937 * bytes consumed in ring buffer from here.
93938 * Increment overrun to account for the lost events.
93939 */
93940 - local_add(page_entries, &cpu_buffer->overrun);
93941 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
93942 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93943 }
93944
93945 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
93946 * it is our responsibility to update
93947 * the counters.
93948 */
93949 - local_add(entries, &cpu_buffer->overrun);
93950 + local_add_unchecked(entries, &cpu_buffer->overrun);
93951 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93952
93953 /*
93954 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93955 if (tail == BUF_PAGE_SIZE)
93956 tail_page->real_end = 0;
93957
93958 - local_sub(length, &tail_page->write);
93959 + local_sub_unchecked(length, &tail_page->write);
93960 return;
93961 }
93962
93963 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93964 rb_event_set_padding(event);
93965
93966 /* Set the write back to the previous setting */
93967 - local_sub(length, &tail_page->write);
93968 + local_sub_unchecked(length, &tail_page->write);
93969 return;
93970 }
93971
93972 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93973
93974 /* Set write to end of buffer */
93975 length = (tail + length) - BUF_PAGE_SIZE;
93976 - local_sub(length, &tail_page->write);
93977 + local_sub_unchecked(length, &tail_page->write);
93978 }
93979
93980 /*
93981 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93982 * about it.
93983 */
93984 if (unlikely(next_page == commit_page)) {
93985 - local_inc(&cpu_buffer->commit_overrun);
93986 + local_inc_unchecked(&cpu_buffer->commit_overrun);
93987 goto out_reset;
93988 }
93989
93990 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93991 cpu_buffer->tail_page) &&
93992 (cpu_buffer->commit_page ==
93993 cpu_buffer->reader_page))) {
93994 - local_inc(&cpu_buffer->commit_overrun);
93995 + local_inc_unchecked(&cpu_buffer->commit_overrun);
93996 goto out_reset;
93997 }
93998 }
93999 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94000 length += RB_LEN_TIME_EXTEND;
94001
94002 tail_page = cpu_buffer->tail_page;
94003 - write = local_add_return(length, &tail_page->write);
94004 + write = local_add_return_unchecked(length, &tail_page->write);
94005
94006 /* set write to only the index of the write */
94007 write &= RB_WRITE_MASK;
94008 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94009 kmemcheck_annotate_bitfield(event, bitfield);
94010 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94011
94012 - local_inc(&tail_page->entries);
94013 + local_inc_unchecked(&tail_page->entries);
94014
94015 /*
94016 * If this is the first commit on the page, then update
94017 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94018
94019 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94020 unsigned long write_mask =
94021 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94022 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94023 unsigned long event_length = rb_event_length(event);
94024 /*
94025 * This is on the tail page. It is possible that
94026 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94027 */
94028 old_index += write_mask;
94029 new_index += write_mask;
94030 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94031 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94032 if (index == old_index) {
94033 /* update counters */
94034 local_sub(event_length, &cpu_buffer->entries_bytes);
94035 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94036
94037 /* Do the likely case first */
94038 if (likely(bpage->page == (void *)addr)) {
94039 - local_dec(&bpage->entries);
94040 + local_dec_unchecked(&bpage->entries);
94041 return;
94042 }
94043
94044 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94045 start = bpage;
94046 do {
94047 if (bpage->page == (void *)addr) {
94048 - local_dec(&bpage->entries);
94049 + local_dec_unchecked(&bpage->entries);
94050 return;
94051 }
94052 rb_inc_page(cpu_buffer, &bpage);
94053 @@ -3173,7 +3173,7 @@ static inline unsigned long
94054 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94055 {
94056 return local_read(&cpu_buffer->entries) -
94057 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94058 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94059 }
94060
94061 /**
94062 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94063 return 0;
94064
94065 cpu_buffer = buffer->buffers[cpu];
94066 - ret = local_read(&cpu_buffer->overrun);
94067 + ret = local_read_unchecked(&cpu_buffer->overrun);
94068
94069 return ret;
94070 }
94071 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94072 return 0;
94073
94074 cpu_buffer = buffer->buffers[cpu];
94075 - ret = local_read(&cpu_buffer->commit_overrun);
94076 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94077
94078 return ret;
94079 }
94080 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94081 /* if you care about this being correct, lock the buffer */
94082 for_each_buffer_cpu(buffer, cpu) {
94083 cpu_buffer = buffer->buffers[cpu];
94084 - overruns += local_read(&cpu_buffer->overrun);
94085 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94086 }
94087
94088 return overruns;
94089 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94090 /*
94091 * Reset the reader page to size zero.
94092 */
94093 - local_set(&cpu_buffer->reader_page->write, 0);
94094 - local_set(&cpu_buffer->reader_page->entries, 0);
94095 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94096 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94097 local_set(&cpu_buffer->reader_page->page->commit, 0);
94098 cpu_buffer->reader_page->real_end = 0;
94099
94100 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94101 * want to compare with the last_overrun.
94102 */
94103 smp_mb();
94104 - overwrite = local_read(&(cpu_buffer->overrun));
94105 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94106
94107 /*
94108 * Here's the tricky part.
94109 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94110
94111 cpu_buffer->head_page
94112 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94113 - local_set(&cpu_buffer->head_page->write, 0);
94114 - local_set(&cpu_buffer->head_page->entries, 0);
94115 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94116 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94117 local_set(&cpu_buffer->head_page->page->commit, 0);
94118
94119 cpu_buffer->head_page->read = 0;
94120 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94121
94122 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94123 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94124 - local_set(&cpu_buffer->reader_page->write, 0);
94125 - local_set(&cpu_buffer->reader_page->entries, 0);
94126 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94127 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94128 local_set(&cpu_buffer->reader_page->page->commit, 0);
94129 cpu_buffer->reader_page->read = 0;
94130
94131 local_set(&cpu_buffer->entries_bytes, 0);
94132 - local_set(&cpu_buffer->overrun, 0);
94133 - local_set(&cpu_buffer->commit_overrun, 0);
94134 + local_set_unchecked(&cpu_buffer->overrun, 0);
94135 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94136 local_set(&cpu_buffer->dropped_events, 0);
94137 local_set(&cpu_buffer->entries, 0);
94138 local_set(&cpu_buffer->committing, 0);
94139 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94140 rb_init_page(bpage);
94141 bpage = reader->page;
94142 reader->page = *data_page;
94143 - local_set(&reader->write, 0);
94144 - local_set(&reader->entries, 0);
94145 + local_set_unchecked(&reader->write, 0);
94146 + local_set_unchecked(&reader->entries, 0);
94147 reader->read = 0;
94148 *data_page = bpage;
94149
94150 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94151 index 1520933..c651ebc 100644
94152 --- a/kernel/trace/trace.c
94153 +++ b/kernel/trace/trace.c
94154 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94155 return 0;
94156 }
94157
94158 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94159 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94160 {
94161 /* do nothing if flag is already set */
94162 if (!!(trace_flags & mask) == !!enabled)
94163 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94164 index 385391f..8d2250f 100644
94165 --- a/kernel/trace/trace.h
94166 +++ b/kernel/trace/trace.h
94167 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94168 void trace_printk_init_buffers(void);
94169 void trace_printk_start_comm(void);
94170 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94171 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94172 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94173
94174 /*
94175 * Normal trace_printk() and friends allocates special buffers
94176 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94177 index 57b67b1..66082a9 100644
94178 --- a/kernel/trace/trace_clock.c
94179 +++ b/kernel/trace/trace_clock.c
94180 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94181 return now;
94182 }
94183
94184 -static atomic64_t trace_counter;
94185 +static atomic64_unchecked_t trace_counter;
94186
94187 /*
94188 * trace_clock_counter(): simply an atomic counter.
94189 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94190 */
94191 u64 notrace trace_clock_counter(void)
94192 {
94193 - return atomic64_add_return(1, &trace_counter);
94194 + return atomic64_inc_return_unchecked(&trace_counter);
94195 }
94196 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94197 index ef06ce7..3ea161d 100644
94198 --- a/kernel/trace/trace_events.c
94199 +++ b/kernel/trace/trace_events.c
94200 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94201 return 0;
94202 }
94203
94204 -struct ftrace_module_file_ops;
94205 static void __add_event_to_tracers(struct ftrace_event_call *call);
94206
94207 /* Add an additional event_call dynamically */
94208 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94209 index 0abd9b8..6a663a2 100644
94210 --- a/kernel/trace/trace_mmiotrace.c
94211 +++ b/kernel/trace/trace_mmiotrace.c
94212 @@ -24,7 +24,7 @@ struct header_iter {
94213 static struct trace_array *mmio_trace_array;
94214 static bool overrun_detected;
94215 static unsigned long prev_overruns;
94216 -static atomic_t dropped_count;
94217 +static atomic_unchecked_t dropped_count;
94218
94219 static void mmio_reset_data(struct trace_array *tr)
94220 {
94221 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94222
94223 static unsigned long count_overruns(struct trace_iterator *iter)
94224 {
94225 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94226 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94227 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94228
94229 if (over > prev_overruns)
94230 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94231 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94232 sizeof(*entry), 0, pc);
94233 if (!event) {
94234 - atomic_inc(&dropped_count);
94235 + atomic_inc_unchecked(&dropped_count);
94236 return;
94237 }
94238 entry = ring_buffer_event_data(event);
94239 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94240 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94241 sizeof(*entry), 0, pc);
94242 if (!event) {
94243 - atomic_inc(&dropped_count);
94244 + atomic_inc_unchecked(&dropped_count);
94245 return;
94246 }
94247 entry = ring_buffer_event_data(event);
94248 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94249 index c6977d5..d243785 100644
94250 --- a/kernel/trace/trace_output.c
94251 +++ b/kernel/trace/trace_output.c
94252 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94253 goto out;
94254 }
94255
94256 + pax_open_kernel();
94257 if (event->funcs->trace == NULL)
94258 - event->funcs->trace = trace_nop_print;
94259 + *(void **)&event->funcs->trace = trace_nop_print;
94260 if (event->funcs->raw == NULL)
94261 - event->funcs->raw = trace_nop_print;
94262 + *(void **)&event->funcs->raw = trace_nop_print;
94263 if (event->funcs->hex == NULL)
94264 - event->funcs->hex = trace_nop_print;
94265 + *(void **)&event->funcs->hex = trace_nop_print;
94266 if (event->funcs->binary == NULL)
94267 - event->funcs->binary = trace_nop_print;
94268 + *(void **)&event->funcs->binary = trace_nop_print;
94269 + pax_close_kernel();
94270
94271 key = event->type & (EVENT_HASHSIZE - 1);
94272
94273 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94274 index 1f24ed9..10407ec 100644
94275 --- a/kernel/trace/trace_seq.c
94276 +++ b/kernel/trace/trace_seq.c
94277 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94278
94279 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94280 if (!IS_ERR(p)) {
94281 - p = mangle_path(s->buffer + s->len, p, "\n");
94282 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94283 if (p) {
94284 s->len = p - s->buffer;
94285 return 1;
94286 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94287 index 8a4e5cb..64f270d 100644
94288 --- a/kernel/trace/trace_stack.c
94289 +++ b/kernel/trace/trace_stack.c
94290 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94291 return;
94292
94293 /* we do not handle interrupt stacks yet */
94294 - if (!object_is_on_stack(stack))
94295 + if (!object_starts_on_stack(stack))
94296 return;
94297
94298 local_irq_save(flags);
94299 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94300 index 7e3cd7a..5156a5fe 100644
94301 --- a/kernel/trace/trace_syscalls.c
94302 +++ b/kernel/trace/trace_syscalls.c
94303 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94304 int num;
94305
94306 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94307 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94308 + return -EINVAL;
94309
94310 mutex_lock(&syscall_trace_lock);
94311 if (!sys_perf_refcount_enter)
94312 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94313 int num;
94314
94315 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94316 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94317 + return;
94318
94319 mutex_lock(&syscall_trace_lock);
94320 sys_perf_refcount_enter--;
94321 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94322 int num;
94323
94324 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94325 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94326 + return -EINVAL;
94327
94328 mutex_lock(&syscall_trace_lock);
94329 if (!sys_perf_refcount_exit)
94330 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94331 int num;
94332
94333 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94334 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94335 + return;
94336
94337 mutex_lock(&syscall_trace_lock);
94338 sys_perf_refcount_exit--;
94339 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94340 index aa312b0..395f343 100644
94341 --- a/kernel/user_namespace.c
94342 +++ b/kernel/user_namespace.c
94343 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94344 !kgid_has_mapping(parent_ns, group))
94345 return -EPERM;
94346
94347 +#ifdef CONFIG_GRKERNSEC
94348 + /*
94349 + * This doesn't really inspire confidence:
94350 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94351 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94352 + * Increases kernel attack surface in areas developers
94353 + * previously cared little about ("low importance due
94354 + * to requiring "root" capability")
94355 + * To be removed when this code receives *proper* review
94356 + */
94357 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94358 + !capable(CAP_SETGID))
94359 + return -EPERM;
94360 +#endif
94361 +
94362 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94363 if (!ns)
94364 return -ENOMEM;
94365 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94366 if (atomic_read(&current->mm->mm_users) > 1)
94367 return -EINVAL;
94368
94369 - if (current->fs->users != 1)
94370 + if (atomic_read(&current->fs->users) != 1)
94371 return -EINVAL;
94372
94373 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94374 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94375 index c8eac43..4b5f08f 100644
94376 --- a/kernel/utsname_sysctl.c
94377 +++ b/kernel/utsname_sysctl.c
94378 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94379 static int proc_do_uts_string(struct ctl_table *table, int write,
94380 void __user *buffer, size_t *lenp, loff_t *ppos)
94381 {
94382 - struct ctl_table uts_table;
94383 + ctl_table_no_const uts_table;
94384 int r;
94385 memcpy(&uts_table, table, sizeof(uts_table));
94386 uts_table.data = get_uts(table, write);
94387 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94388 index a8d6914..8fbdb13 100644
94389 --- a/kernel/watchdog.c
94390 +++ b/kernel/watchdog.c
94391 @@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94392 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94393 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94394
94395 -static struct smp_hotplug_thread watchdog_threads = {
94396 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94397 .store = &softlockup_watchdog,
94398 .thread_should_run = watchdog_should_run,
94399 .thread_fn = watchdog,
94400 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94401 index 5dbe22a..872413c 100644
94402 --- a/kernel/workqueue.c
94403 +++ b/kernel/workqueue.c
94404 @@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
94405 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94406 worker_flags |= WORKER_REBOUND;
94407 worker_flags &= ~WORKER_UNBOUND;
94408 - ACCESS_ONCE(worker->flags) = worker_flags;
94409 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94410 }
94411
94412 spin_unlock_irq(&pool->lock);
94413 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94414 index a285900..5e3b26b 100644
94415 --- a/lib/Kconfig.debug
94416 +++ b/lib/Kconfig.debug
94417 @@ -882,7 +882,7 @@ config DEBUG_MUTEXES
94418
94419 config DEBUG_WW_MUTEX_SLOWPATH
94420 bool "Wait/wound mutex debugging: Slowpath testing"
94421 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94422 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94423 select DEBUG_LOCK_ALLOC
94424 select DEBUG_SPINLOCK
94425 select DEBUG_MUTEXES
94426 @@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94427
94428 config DEBUG_LOCK_ALLOC
94429 bool "Lock debugging: detect incorrect freeing of live locks"
94430 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94431 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94432 select DEBUG_SPINLOCK
94433 select DEBUG_MUTEXES
94434 select LOCKDEP
94435 @@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
94436
94437 config PROVE_LOCKING
94438 bool "Lock debugging: prove locking correctness"
94439 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94440 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94441 select LOCKDEP
94442 select DEBUG_SPINLOCK
94443 select DEBUG_MUTEXES
94444 @@ -964,7 +964,7 @@ config LOCKDEP
94445
94446 config LOCK_STAT
94447 bool "Lock usage statistics"
94448 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94449 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94450 select LOCKDEP
94451 select DEBUG_SPINLOCK
94452 select DEBUG_MUTEXES
94453 @@ -1437,6 +1437,7 @@ config LATENCYTOP
94454 depends on DEBUG_KERNEL
94455 depends on STACKTRACE_SUPPORT
94456 depends on PROC_FS
94457 + depends on !GRKERNSEC_HIDESYM
94458 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94459 select KALLSYMS
94460 select KALLSYMS_ALL
94461 @@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94462 config DEBUG_STRICT_USER_COPY_CHECKS
94463 bool "Strict user copy size checks"
94464 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94465 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94466 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94467 help
94468 Enabling this option turns a certain set of sanity checks for user
94469 copy operations into compile time failures.
94470 @@ -1581,7 +1582,7 @@ endmenu # runtime tests
94471
94472 config PROVIDE_OHCI1394_DMA_INIT
94473 bool "Remote debugging over FireWire early on boot"
94474 - depends on PCI && X86
94475 + depends on PCI && X86 && !GRKERNSEC
94476 help
94477 If you want to debug problems which hang or crash the kernel early
94478 on boot and the crashing machine has a FireWire port, you can use
94479 diff --git a/lib/Makefile b/lib/Makefile
94480 index d6b4bc4..a3724eb 100644
94481 --- a/lib/Makefile
94482 +++ b/lib/Makefile
94483 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94484 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94485 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94486 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94487 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94488 +obj-y += list_debug.o
94489 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94490
94491 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94492 diff --git a/lib/average.c b/lib/average.c
94493 index 114d1be..ab0350c 100644
94494 --- a/lib/average.c
94495 +++ b/lib/average.c
94496 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94497 {
94498 unsigned long internal = ACCESS_ONCE(avg->internal);
94499
94500 - ACCESS_ONCE(avg->internal) = internal ?
94501 + ACCESS_ONCE_RW(avg->internal) = internal ?
94502 (((internal << avg->weight) - internal) +
94503 (val << avg->factor)) >> avg->weight :
94504 (val << avg->factor);
94505 diff --git a/lib/bitmap.c b/lib/bitmap.c
94506 index 33ce011..89e3d6f 100644
94507 --- a/lib/bitmap.c
94508 +++ b/lib/bitmap.c
94509 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94510 {
94511 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94512 u32 chunk;
94513 - const char __user __force *ubuf = (const char __user __force *)buf;
94514 + const char __user *ubuf = (const char __force_user *)buf;
94515
94516 bitmap_zero(maskp, nmaskbits);
94517
94518 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94519 {
94520 if (!access_ok(VERIFY_READ, ubuf, ulen))
94521 return -EFAULT;
94522 - return __bitmap_parse((const char __force *)ubuf,
94523 + return __bitmap_parse((const char __force_kernel *)ubuf,
94524 ulen, 1, maskp, nmaskbits);
94525
94526 }
94527 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94528 {
94529 unsigned a, b;
94530 int c, old_c, totaldigits;
94531 - const char __user __force *ubuf = (const char __user __force *)buf;
94532 + const char __user *ubuf = (const char __force_user *)buf;
94533 int exp_digit, in_range;
94534
94535 totaldigits = c = 0;
94536 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94537 {
94538 if (!access_ok(VERIFY_READ, ubuf, ulen))
94539 return -EFAULT;
94540 - return __bitmap_parselist((const char __force *)ubuf,
94541 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94542 ulen, 1, maskp, nmaskbits);
94543 }
94544 EXPORT_SYMBOL(bitmap_parselist_user);
94545 diff --git a/lib/bug.c b/lib/bug.c
94546 index d1d7c78..b354235 100644
94547 --- a/lib/bug.c
94548 +++ b/lib/bug.c
94549 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94550 return BUG_TRAP_TYPE_NONE;
94551
94552 bug = find_bug(bugaddr);
94553 + if (!bug)
94554 + return BUG_TRAP_TYPE_NONE;
94555
94556 file = NULL;
94557 line = 0;
94558 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94559 index 547f7f9..a6d4ba0 100644
94560 --- a/lib/debugobjects.c
94561 +++ b/lib/debugobjects.c
94562 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94563 if (limit > 4)
94564 return;
94565
94566 - is_on_stack = object_is_on_stack(addr);
94567 + is_on_stack = object_starts_on_stack(addr);
94568 if (is_on_stack == onstack)
94569 return;
94570
94571 diff --git a/lib/div64.c b/lib/div64.c
94572 index 4382ad7..08aa558 100644
94573 --- a/lib/div64.c
94574 +++ b/lib/div64.c
94575 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94576 EXPORT_SYMBOL(__div64_32);
94577
94578 #ifndef div_s64_rem
94579 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94580 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94581 {
94582 u64 quotient;
94583
94584 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94585 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94586 */
94587 #ifndef div64_u64
94588 -u64 div64_u64(u64 dividend, u64 divisor)
94589 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94590 {
94591 u32 high = divisor >> 32;
94592 u64 quot;
94593 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94594 index 98f2d7e..899da5c 100644
94595 --- a/lib/dma-debug.c
94596 +++ b/lib/dma-debug.c
94597 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94598
94599 void dma_debug_add_bus(struct bus_type *bus)
94600 {
94601 - struct notifier_block *nb;
94602 + notifier_block_no_const *nb;
94603
94604 if (global_disable)
94605 return;
94606 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94607
94608 static void check_for_stack(struct device *dev, void *addr)
94609 {
94610 - if (object_is_on_stack(addr))
94611 + if (object_starts_on_stack(addr))
94612 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
94613 "stack [addr=%p]\n", addr);
94614 }
94615 diff --git a/lib/hash.c b/lib/hash.c
94616 index fea973f..386626f 100644
94617 --- a/lib/hash.c
94618 +++ b/lib/hash.c
94619 @@ -14,7 +14,7 @@
94620 #include <linux/hash.h>
94621 #include <linux/cache.h>
94622
94623 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94624 +static struct fast_hash_ops arch_hash_ops __read_only = {
94625 .hash = jhash,
94626 .hash2 = jhash2,
94627 };
94628 diff --git a/lib/inflate.c b/lib/inflate.c
94629 index 013a761..c28f3fc 100644
94630 --- a/lib/inflate.c
94631 +++ b/lib/inflate.c
94632 @@ -269,7 +269,7 @@ static void free(void *where)
94633 malloc_ptr = free_mem_ptr;
94634 }
94635 #else
94636 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94637 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94638 #define free(a) kfree(a)
94639 #endif
94640
94641 diff --git a/lib/ioremap.c b/lib/ioremap.c
94642 index 0c9216c..863bd89 100644
94643 --- a/lib/ioremap.c
94644 +++ b/lib/ioremap.c
94645 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94646 unsigned long next;
94647
94648 phys_addr -= addr;
94649 - pmd = pmd_alloc(&init_mm, pud, addr);
94650 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94651 if (!pmd)
94652 return -ENOMEM;
94653 do {
94654 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94655 unsigned long next;
94656
94657 phys_addr -= addr;
94658 - pud = pud_alloc(&init_mm, pgd, addr);
94659 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94660 if (!pud)
94661 return -ENOMEM;
94662 do {
94663 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94664 index bd2bea9..6b3c95e 100644
94665 --- a/lib/is_single_threaded.c
94666 +++ b/lib/is_single_threaded.c
94667 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94668 struct task_struct *p, *t;
94669 bool ret;
94670
94671 + if (!mm)
94672 + return true;
94673 +
94674 if (atomic_read(&task->signal->live) != 1)
94675 return false;
94676
94677 diff --git a/lib/kobject.c b/lib/kobject.c
94678 index 58751bb..93a1853 100644
94679 --- a/lib/kobject.c
94680 +++ b/lib/kobject.c
94681 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94682
94683
94684 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94685 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94686 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94687
94688 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94689 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94690 {
94691 enum kobj_ns_type type = ops->type;
94692 int error;
94693 diff --git a/lib/list_debug.c b/lib/list_debug.c
94694 index c24c2f7..f0296f4 100644
94695 --- a/lib/list_debug.c
94696 +++ b/lib/list_debug.c
94697 @@ -11,7 +11,9 @@
94698 #include <linux/bug.h>
94699 #include <linux/kernel.h>
94700 #include <linux/rculist.h>
94701 +#include <linux/mm.h>
94702
94703 +#ifdef CONFIG_DEBUG_LIST
94704 /*
94705 * Insert a new entry between two known consecutive entries.
94706 *
94707 @@ -19,21 +21,40 @@
94708 * the prev/next entries already!
94709 */
94710
94711 +static bool __list_add_debug(struct list_head *new,
94712 + struct list_head *prev,
94713 + struct list_head *next)
94714 +{
94715 + if (unlikely(next->prev != prev)) {
94716 + printk(KERN_ERR "list_add corruption. next->prev should be "
94717 + "prev (%p), but was %p. (next=%p).\n",
94718 + prev, next->prev, next);
94719 + BUG();
94720 + return false;
94721 + }
94722 + if (unlikely(prev->next != next)) {
94723 + printk(KERN_ERR "list_add corruption. prev->next should be "
94724 + "next (%p), but was %p. (prev=%p).\n",
94725 + next, prev->next, prev);
94726 + BUG();
94727 + return false;
94728 + }
94729 + if (unlikely(new == prev || new == next)) {
94730 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94731 + new, prev, next);
94732 + BUG();
94733 + return false;
94734 + }
94735 + return true;
94736 +}
94737 +
94738 void __list_add(struct list_head *new,
94739 - struct list_head *prev,
94740 - struct list_head *next)
94741 + struct list_head *prev,
94742 + struct list_head *next)
94743 {
94744 - WARN(next->prev != prev,
94745 - "list_add corruption. next->prev should be "
94746 - "prev (%p), but was %p. (next=%p).\n",
94747 - prev, next->prev, next);
94748 - WARN(prev->next != next,
94749 - "list_add corruption. prev->next should be "
94750 - "next (%p), but was %p. (prev=%p).\n",
94751 - next, prev->next, prev);
94752 - WARN(new == prev || new == next,
94753 - "list_add double add: new=%p, prev=%p, next=%p.\n",
94754 - new, prev, next);
94755 + if (!__list_add_debug(new, prev, next))
94756 + return;
94757 +
94758 next->prev = new;
94759 new->next = next;
94760 new->prev = prev;
94761 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94762 }
94763 EXPORT_SYMBOL(__list_add);
94764
94765 -void __list_del_entry(struct list_head *entry)
94766 +static bool __list_del_entry_debug(struct list_head *entry)
94767 {
94768 struct list_head *prev, *next;
94769
94770 prev = entry->prev;
94771 next = entry->next;
94772
94773 - if (WARN(next == LIST_POISON1,
94774 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94775 - entry, LIST_POISON1) ||
94776 - WARN(prev == LIST_POISON2,
94777 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94778 - entry, LIST_POISON2) ||
94779 - WARN(prev->next != entry,
94780 - "list_del corruption. prev->next should be %p, "
94781 - "but was %p\n", entry, prev->next) ||
94782 - WARN(next->prev != entry,
94783 - "list_del corruption. next->prev should be %p, "
94784 - "but was %p\n", entry, next->prev))
94785 + if (unlikely(next == LIST_POISON1)) {
94786 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94787 + entry, LIST_POISON1);
94788 + BUG();
94789 + return false;
94790 + }
94791 + if (unlikely(prev == LIST_POISON2)) {
94792 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94793 + entry, LIST_POISON2);
94794 + BUG();
94795 + return false;
94796 + }
94797 + if (unlikely(entry->prev->next != entry)) {
94798 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94799 + "but was %p\n", entry, prev->next);
94800 + BUG();
94801 + return false;
94802 + }
94803 + if (unlikely(entry->next->prev != entry)) {
94804 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94805 + "but was %p\n", entry, next->prev);
94806 + BUG();
94807 + return false;
94808 + }
94809 + return true;
94810 +}
94811 +
94812 +void __list_del_entry(struct list_head *entry)
94813 +{
94814 + if (!__list_del_entry_debug(entry))
94815 return;
94816
94817 - __list_del(prev, next);
94818 + __list_del(entry->prev, entry->next);
94819 }
94820 EXPORT_SYMBOL(__list_del_entry);
94821
94822 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94823 void __list_add_rcu(struct list_head *new,
94824 struct list_head *prev, struct list_head *next)
94825 {
94826 - WARN(next->prev != prev,
94827 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94828 - prev, next->prev, next);
94829 - WARN(prev->next != next,
94830 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94831 - next, prev->next, prev);
94832 + if (!__list_add_debug(new, prev, next))
94833 + return;
94834 +
94835 new->next = next;
94836 new->prev = prev;
94837 rcu_assign_pointer(list_next_rcu(prev), new);
94838 next->prev = new;
94839 }
94840 EXPORT_SYMBOL(__list_add_rcu);
94841 +#endif
94842 +
94843 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94844 +{
94845 +#ifdef CONFIG_DEBUG_LIST
94846 + if (!__list_add_debug(new, prev, next))
94847 + return;
94848 +#endif
94849 +
94850 + pax_open_kernel();
94851 + next->prev = new;
94852 + new->next = next;
94853 + new->prev = prev;
94854 + prev->next = new;
94855 + pax_close_kernel();
94856 +}
94857 +EXPORT_SYMBOL(__pax_list_add);
94858 +
94859 +void pax_list_del(struct list_head *entry)
94860 +{
94861 +#ifdef CONFIG_DEBUG_LIST
94862 + if (!__list_del_entry_debug(entry))
94863 + return;
94864 +#endif
94865 +
94866 + pax_open_kernel();
94867 + __list_del(entry->prev, entry->next);
94868 + entry->next = LIST_POISON1;
94869 + entry->prev = LIST_POISON2;
94870 + pax_close_kernel();
94871 +}
94872 +EXPORT_SYMBOL(pax_list_del);
94873 +
94874 +void pax_list_del_init(struct list_head *entry)
94875 +{
94876 + pax_open_kernel();
94877 + __list_del(entry->prev, entry->next);
94878 + INIT_LIST_HEAD(entry);
94879 + pax_close_kernel();
94880 +}
94881 +EXPORT_SYMBOL(pax_list_del_init);
94882 +
94883 +void __pax_list_add_rcu(struct list_head *new,
94884 + struct list_head *prev, struct list_head *next)
94885 +{
94886 +#ifdef CONFIG_DEBUG_LIST
94887 + if (!__list_add_debug(new, prev, next))
94888 + return;
94889 +#endif
94890 +
94891 + pax_open_kernel();
94892 + new->next = next;
94893 + new->prev = prev;
94894 + rcu_assign_pointer(list_next_rcu(prev), new);
94895 + next->prev = new;
94896 + pax_close_kernel();
94897 +}
94898 +EXPORT_SYMBOL(__pax_list_add_rcu);
94899 +
94900 +void pax_list_del_rcu(struct list_head *entry)
94901 +{
94902 +#ifdef CONFIG_DEBUG_LIST
94903 + if (!__list_del_entry_debug(entry))
94904 + return;
94905 +#endif
94906 +
94907 + pax_open_kernel();
94908 + __list_del(entry->prev, entry->next);
94909 + entry->next = LIST_POISON1;
94910 + entry->prev = LIST_POISON2;
94911 + pax_close_kernel();
94912 +}
94913 +EXPORT_SYMBOL(pax_list_del_rcu);
94914 diff --git a/lib/lockref.c b/lib/lockref.c
94915 index d2233de..fa1a2f6 100644
94916 --- a/lib/lockref.c
94917 +++ b/lib/lockref.c
94918 @@ -48,13 +48,13 @@
94919 void lockref_get(struct lockref *lockref)
94920 {
94921 CMPXCHG_LOOP(
94922 - new.count++;
94923 + __lockref_inc(&new);
94924 ,
94925 return;
94926 );
94927
94928 spin_lock(&lockref->lock);
94929 - lockref->count++;
94930 + __lockref_inc(lockref);
94931 spin_unlock(&lockref->lock);
94932 }
94933 EXPORT_SYMBOL(lockref_get);
94934 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94935 int retval;
94936
94937 CMPXCHG_LOOP(
94938 - new.count++;
94939 + __lockref_inc(&new);
94940 if (!old.count)
94941 return 0;
94942 ,
94943 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94944 spin_lock(&lockref->lock);
94945 retval = 0;
94946 if (lockref->count) {
94947 - lockref->count++;
94948 + __lockref_inc(lockref);
94949 retval = 1;
94950 }
94951 spin_unlock(&lockref->lock);
94952 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
94953 int lockref_get_or_lock(struct lockref *lockref)
94954 {
94955 CMPXCHG_LOOP(
94956 - new.count++;
94957 + __lockref_inc(&new);
94958 if (!old.count)
94959 break;
94960 ,
94961 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
94962 spin_lock(&lockref->lock);
94963 if (!lockref->count)
94964 return 0;
94965 - lockref->count++;
94966 + __lockref_inc(lockref);
94967 spin_unlock(&lockref->lock);
94968 return 1;
94969 }
94970 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
94971 int lockref_put_or_lock(struct lockref *lockref)
94972 {
94973 CMPXCHG_LOOP(
94974 - new.count--;
94975 + __lockref_dec(&new);
94976 if (old.count <= 1)
94977 break;
94978 ,
94979 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
94980 spin_lock(&lockref->lock);
94981 if (lockref->count <= 1)
94982 return 0;
94983 - lockref->count--;
94984 + __lockref_dec(lockref);
94985 spin_unlock(&lockref->lock);
94986 return 1;
94987 }
94988 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94989 int retval;
94990
94991 CMPXCHG_LOOP(
94992 - new.count++;
94993 + __lockref_inc(&new);
94994 if ((int)old.count < 0)
94995 return 0;
94996 ,
94997 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94998 spin_lock(&lockref->lock);
94999 retval = 0;
95000 if ((int) lockref->count >= 0) {
95001 - lockref->count++;
95002 + __lockref_inc(lockref);
95003 retval = 1;
95004 }
95005 spin_unlock(&lockref->lock);
95006 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95007 index a89cf09..1a42c2d 100644
95008 --- a/lib/percpu-refcount.c
95009 +++ b/lib/percpu-refcount.c
95010 @@ -29,7 +29,7 @@
95011 * can't hit 0 before we've added up all the percpu refs.
95012 */
95013
95014 -#define PCPU_COUNT_BIAS (1U << 31)
95015 +#define PCPU_COUNT_BIAS (1U << 30)
95016
95017 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
95018 {
95019 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95020 index 3291a8e..346a91e 100644
95021 --- a/lib/radix-tree.c
95022 +++ b/lib/radix-tree.c
95023 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95024 int nr;
95025 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95026 };
95027 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95028 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95029
95030 static inline void *ptr_to_indirect(void *ptr)
95031 {
95032 diff --git a/lib/random32.c b/lib/random32.c
95033 index c9b6bf3..4752c6d4 100644
95034 --- a/lib/random32.c
95035 +++ b/lib/random32.c
95036 @@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
95037 }
95038 #endif
95039
95040 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95041 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95042
95043 /**
95044 * prandom_u32_state - seeded pseudo-random number generator.
95045 diff --git a/lib/rbtree.c b/lib/rbtree.c
95046 index c16c81a..4dcbda1 100644
95047 --- a/lib/rbtree.c
95048 +++ b/lib/rbtree.c
95049 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95050 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95051
95052 static const struct rb_augment_callbacks dummy_callbacks = {
95053 - dummy_propagate, dummy_copy, dummy_rotate
95054 + .propagate = dummy_propagate,
95055 + .copy = dummy_copy,
95056 + .rotate = dummy_rotate
95057 };
95058
95059 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95060 diff --git a/lib/show_mem.c b/lib/show_mem.c
95061 index 0922579..9d7adb9 100644
95062 --- a/lib/show_mem.c
95063 +++ b/lib/show_mem.c
95064 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95065 quicklist_total_size());
95066 #endif
95067 #ifdef CONFIG_MEMORY_FAILURE
95068 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95069 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95070 #endif
95071 }
95072 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95073 index bb2b201..46abaf9 100644
95074 --- a/lib/strncpy_from_user.c
95075 +++ b/lib/strncpy_from_user.c
95076 @@ -21,7 +21,7 @@
95077 */
95078 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95079 {
95080 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95081 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95082 long res = 0;
95083
95084 /*
95085 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95086 index a28df52..3d55877 100644
95087 --- a/lib/strnlen_user.c
95088 +++ b/lib/strnlen_user.c
95089 @@ -26,7 +26,7 @@
95090 */
95091 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95092 {
95093 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95094 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95095 long align, res = 0;
95096 unsigned long c;
95097
95098 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95099 index 4abda07..b9d3765 100644
95100 --- a/lib/swiotlb.c
95101 +++ b/lib/swiotlb.c
95102 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95103
95104 void
95105 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95106 - dma_addr_t dev_addr)
95107 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95108 {
95109 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95110
95111 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
95112 index 89e0345..3347efe 100644
95113 --- a/lib/test_bpf.c
95114 +++ b/lib/test_bpf.c
95115 @@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
95116 break;
95117
95118 case INTERNAL:
95119 - fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
95120 + fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
95121 if (fp == NULL) {
95122 pr_cont("UNEXPECTED_FAIL no memory left\n");
95123 *err = -ENOMEM;
95124 diff --git a/lib/usercopy.c b/lib/usercopy.c
95125 index 4f5b1dd..7cab418 100644
95126 --- a/lib/usercopy.c
95127 +++ b/lib/usercopy.c
95128 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95129 WARN(1, "Buffer overflow detected!\n");
95130 }
95131 EXPORT_SYMBOL(copy_from_user_overflow);
95132 +
95133 +void copy_to_user_overflow(void)
95134 +{
95135 + WARN(1, "Buffer overflow detected!\n");
95136 +}
95137 +EXPORT_SYMBOL(copy_to_user_overflow);
95138 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95139 index 6fe2c84..2fe5ec6 100644
95140 --- a/lib/vsprintf.c
95141 +++ b/lib/vsprintf.c
95142 @@ -16,6 +16,9 @@
95143 * - scnprintf and vscnprintf
95144 */
95145
95146 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95147 +#define __INCLUDED_BY_HIDESYM 1
95148 +#endif
95149 #include <stdarg.h>
95150 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95151 #include <linux/types.h>
95152 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95153 #ifdef CONFIG_KALLSYMS
95154 if (*fmt == 'B')
95155 sprint_backtrace(sym, value);
95156 - else if (*fmt != 'f' && *fmt != 's')
95157 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95158 sprint_symbol(sym, value);
95159 else
95160 sprint_symbol_no_offset(sym, value);
95161 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
95162 return number(buf, end, num, spec);
95163 }
95164
95165 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95166 +int kptr_restrict __read_mostly = 2;
95167 +#else
95168 int kptr_restrict __read_mostly;
95169 +#endif
95170
95171 /*
95172 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95173 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
95174 *
95175 * - 'F' For symbolic function descriptor pointers with offset
95176 * - 'f' For simple symbolic function names without offset
95177 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95178 * - 'S' For symbolic direct pointers with offset
95179 * - 's' For symbolic direct pointers without offset
95180 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95181 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95182 * - 'B' For backtraced symbolic direct pointers with offset
95183 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95184 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95185
95186 if (!ptr && *fmt != 'K') {
95187 /*
95188 - * Print (null) with the same width as a pointer so it makes
95189 + * Print (nil) with the same width as a pointer so it makes
95190 * tabular output look nice.
95191 */
95192 if (spec.field_width == -1)
95193 spec.field_width = default_width;
95194 - return string(buf, end, "(null)", spec);
95195 + return string(buf, end, "(nil)", spec);
95196 }
95197
95198 switch (*fmt) {
95199 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95200 /* Fallthrough */
95201 case 'S':
95202 case 's':
95203 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95204 + break;
95205 +#else
95206 + return symbol_string(buf, end, ptr, spec, fmt);
95207 +#endif
95208 + case 'X':
95209 + ptr = dereference_function_descriptor(ptr);
95210 + case 'A':
95211 case 'B':
95212 return symbol_string(buf, end, ptr, spec, fmt);
95213 case 'R':
95214 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95215 va_end(va);
95216 return buf;
95217 }
95218 + case 'P':
95219 + break;
95220 case 'K':
95221 /*
95222 * %pK cannot be used in IRQ context because its test
95223 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95224 ((const struct file *)ptr)->f_path.dentry,
95225 spec, fmt);
95226 }
95227 +
95228 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95229 + /* 'P' = approved pointers to copy to userland,
95230 + as in the /proc/kallsyms case, as we make it display nothing
95231 + for non-root users, and the real contents for root users
95232 + 'X' = approved simple symbols
95233 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95234 + above
95235 + */
95236 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95237 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95238 + dump_stack();
95239 + ptr = NULL;
95240 + }
95241 +#endif
95242 +
95243 spec.flags |= SMALL;
95244 if (spec.field_width == -1) {
95245 spec.field_width = default_width;
95246 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95247 typeof(type) value; \
95248 if (sizeof(type) == 8) { \
95249 args = PTR_ALIGN(args, sizeof(u32)); \
95250 - *(u32 *)&value = *(u32 *)args; \
95251 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95252 + *(u32 *)&value = *(const u32 *)args; \
95253 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95254 } else { \
95255 args = PTR_ALIGN(args, sizeof(type)); \
95256 - value = *(typeof(type) *)args; \
95257 + value = *(const typeof(type) *)args; \
95258 } \
95259 args += sizeof(type); \
95260 value; \
95261 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95262 case FORMAT_TYPE_STR: {
95263 const char *str_arg = args;
95264 args += strlen(str_arg) + 1;
95265 - str = string(str, end, (char *)str_arg, spec);
95266 + str = string(str, end, str_arg, spec);
95267 break;
95268 }
95269
95270 diff --git a/localversion-grsec b/localversion-grsec
95271 new file mode 100644
95272 index 0000000..7cd6065
95273 --- /dev/null
95274 +++ b/localversion-grsec
95275 @@ -0,0 +1 @@
95276 +-grsec
95277 diff --git a/mm/Kconfig b/mm/Kconfig
95278 index 886db21..f514de2 100644
95279 --- a/mm/Kconfig
95280 +++ b/mm/Kconfig
95281 @@ -333,10 +333,11 @@ config KSM
95282 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95283
95284 config DEFAULT_MMAP_MIN_ADDR
95285 - int "Low address space to protect from user allocation"
95286 + int "Low address space to protect from user allocation"
95287 depends on MMU
95288 - default 4096
95289 - help
95290 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95291 + default 65536
95292 + help
95293 This is the portion of low virtual memory which should be protected
95294 from userspace allocation. Keeping a user from writing to low pages
95295 can help reduce the impact of kernel NULL pointer bugs.
95296 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
95297
95298 config HWPOISON_INJECT
95299 tristate "HWPoison pages injector"
95300 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95301 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95302 select PROC_PAGE_MONITOR
95303
95304 config NOMMU_INITIAL_TRIM_EXCESS
95305 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95306 index 1706cbb..f89dbca 100644
95307 --- a/mm/backing-dev.c
95308 +++ b/mm/backing-dev.c
95309 @@ -12,7 +12,7 @@
95310 #include <linux/device.h>
95311 #include <trace/events/writeback.h>
95312
95313 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95314 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95315
95316 struct backing_dev_info default_backing_dev_info = {
95317 .name = "default",
95318 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95319 return err;
95320
95321 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95322 - atomic_long_inc_return(&bdi_seq));
95323 + atomic_long_inc_return_unchecked(&bdi_seq));
95324 if (err) {
95325 bdi_destroy(bdi);
95326 return err;
95327 diff --git a/mm/filemap.c b/mm/filemap.c
95328 index 90effcd..539aa64 100644
95329 --- a/mm/filemap.c
95330 +++ b/mm/filemap.c
95331 @@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95332 struct address_space *mapping = file->f_mapping;
95333
95334 if (!mapping->a_ops->readpage)
95335 - return -ENOEXEC;
95336 + return -ENODEV;
95337 file_accessed(file);
95338 vma->vm_ops = &generic_file_vm_ops;
95339 return 0;
95340 @@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95341 *pos = i_size_read(inode);
95342
95343 if (limit != RLIM_INFINITY) {
95344 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95345 if (*pos >= limit) {
95346 send_sig(SIGXFSZ, current, 0);
95347 return -EFBIG;
95348 diff --git a/mm/fremap.c b/mm/fremap.c
95349 index 72b8fa3..c5b39f1 100644
95350 --- a/mm/fremap.c
95351 +++ b/mm/fremap.c
95352 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95353 retry:
95354 vma = find_vma(mm, start);
95355
95356 +#ifdef CONFIG_PAX_SEGMEXEC
95357 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95358 + goto out;
95359 +#endif
95360 +
95361 /*
95362 * Make sure the vma is shared, that it supports prefaulting,
95363 * and that the remapped range is valid and fully within
95364 diff --git a/mm/gup.c b/mm/gup.c
95365 index 91d044b..a58ecf6 100644
95366 --- a/mm/gup.c
95367 +++ b/mm/gup.c
95368 @@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95369 unsigned int fault_flags = 0;
95370 int ret;
95371
95372 - /* For mlock, just skip the stack guard page. */
95373 - if ((*flags & FOLL_MLOCK) &&
95374 - (stack_guard_page_start(vma, address) ||
95375 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95376 - return -ENOENT;
95377 if (*flags & FOLL_WRITE)
95378 fault_flags |= FAULT_FLAG_WRITE;
95379 if (nonblocking)
95380 @@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95381 if (!(gup_flags & FOLL_FORCE))
95382 gup_flags |= FOLL_NUMA;
95383
95384 - do {
95385 + while (nr_pages) {
95386 struct page *page;
95387 unsigned int foll_flags = gup_flags;
95388 unsigned int page_increm;
95389
95390 /* first iteration or cross vma bound */
95391 if (!vma || start >= vma->vm_end) {
95392 - vma = find_extend_vma(mm, start);
95393 + vma = find_vma(mm, start);
95394 if (!vma && in_gate_area(mm, start)) {
95395 int ret;
95396 ret = get_gate_page(mm, start & PAGE_MASK,
95397 @@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95398 goto next_page;
95399 }
95400
95401 - if (!vma || check_vma_flags(vma, gup_flags))
95402 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95403 return i ? : -EFAULT;
95404 if (is_vm_hugetlb_page(vma)) {
95405 i = follow_hugetlb_page(mm, vma, pages, vmas,
95406 @@ -510,7 +505,7 @@ next_page:
95407 i += page_increm;
95408 start += page_increm * PAGE_SIZE;
95409 nr_pages -= page_increm;
95410 - } while (nr_pages);
95411 + }
95412 return i;
95413 }
95414 EXPORT_SYMBOL(__get_user_pages);
95415 diff --git a/mm/highmem.c b/mm/highmem.c
95416 index 123bcd3..0de52ba 100644
95417 --- a/mm/highmem.c
95418 +++ b/mm/highmem.c
95419 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95420 * So no dangers, even with speculative execution.
95421 */
95422 page = pte_page(pkmap_page_table[i]);
95423 + pax_open_kernel();
95424 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95425 -
95426 + pax_close_kernel();
95427 set_page_address(page, NULL);
95428 need_flush = 1;
95429 }
95430 @@ -259,9 +260,11 @@ start:
95431 }
95432 }
95433 vaddr = PKMAP_ADDR(last_pkmap_nr);
95434 +
95435 + pax_open_kernel();
95436 set_pte_at(&init_mm, vaddr,
95437 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95438 -
95439 + pax_close_kernel();
95440 pkmap_count[last_pkmap_nr] = 1;
95441 set_page_address(page, (void *)vaddr);
95442
95443 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95444 index eeceeeb..a209d58 100644
95445 --- a/mm/hugetlb.c
95446 +++ b/mm/hugetlb.c
95447 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95448 struct ctl_table *table, int write,
95449 void __user *buffer, size_t *length, loff_t *ppos)
95450 {
95451 + ctl_table_no_const t;
95452 struct hstate *h = &default_hstate;
95453 unsigned long tmp = h->max_huge_pages;
95454 int ret;
95455 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95456 if (!hugepages_supported())
95457 return -ENOTSUPP;
95458
95459 - table->data = &tmp;
95460 - table->maxlen = sizeof(unsigned long);
95461 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95462 + t = *table;
95463 + t.data = &tmp;
95464 + t.maxlen = sizeof(unsigned long);
95465 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95466 if (ret)
95467 goto out;
95468
95469 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95470 struct hstate *h = &default_hstate;
95471 unsigned long tmp;
95472 int ret;
95473 + ctl_table_no_const hugetlb_table;
95474
95475 if (!hugepages_supported())
95476 return -ENOTSUPP;
95477 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95478 if (write && hstate_is_gigantic(h))
95479 return -EINVAL;
95480
95481 - table->data = &tmp;
95482 - table->maxlen = sizeof(unsigned long);
95483 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95484 + hugetlb_table = *table;
95485 + hugetlb_table.data = &tmp;
95486 + hugetlb_table.maxlen = sizeof(unsigned long);
95487 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95488 if (ret)
95489 goto out;
95490
95491 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95492 mutex_unlock(&mapping->i_mmap_mutex);
95493 }
95494
95495 +#ifdef CONFIG_PAX_SEGMEXEC
95496 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95497 +{
95498 + struct mm_struct *mm = vma->vm_mm;
95499 + struct vm_area_struct *vma_m;
95500 + unsigned long address_m;
95501 + pte_t *ptep_m;
95502 +
95503 + vma_m = pax_find_mirror_vma(vma);
95504 + if (!vma_m)
95505 + return;
95506 +
95507 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95508 + address_m = address + SEGMEXEC_TASK_SIZE;
95509 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95510 + get_page(page_m);
95511 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95512 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95513 +}
95514 +#endif
95515 +
95516 /*
95517 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95518 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95519 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95520 make_huge_pte(vma, new_page, 1));
95521 page_remove_rmap(old_page);
95522 hugepage_add_new_anon_rmap(new_page, vma, address);
95523 +
95524 +#ifdef CONFIG_PAX_SEGMEXEC
95525 + pax_mirror_huge_pte(vma, address, new_page);
95526 +#endif
95527 +
95528 /* Make the old page be freed below */
95529 new_page = old_page;
95530 }
95531 @@ -3063,6 +3093,10 @@ retry:
95532 && (vma->vm_flags & VM_SHARED)));
95533 set_huge_pte_at(mm, address, ptep, new_pte);
95534
95535 +#ifdef CONFIG_PAX_SEGMEXEC
95536 + pax_mirror_huge_pte(vma, address, page);
95537 +#endif
95538 +
95539 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95540 /* Optimization, do the COW without a second fault */
95541 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95542 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95543 struct hstate *h = hstate_vma(vma);
95544 struct address_space *mapping;
95545
95546 +#ifdef CONFIG_PAX_SEGMEXEC
95547 + struct vm_area_struct *vma_m;
95548 +#endif
95549 +
95550 address &= huge_page_mask(h);
95551
95552 ptep = huge_pte_offset(mm, address);
95553 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95554 VM_FAULT_SET_HINDEX(hstate_index(h));
95555 }
95556
95557 +#ifdef CONFIG_PAX_SEGMEXEC
95558 + vma_m = pax_find_mirror_vma(vma);
95559 + if (vma_m) {
95560 + unsigned long address_m;
95561 +
95562 + if (vma->vm_start > vma_m->vm_start) {
95563 + address_m = address;
95564 + address -= SEGMEXEC_TASK_SIZE;
95565 + vma = vma_m;
95566 + h = hstate_vma(vma);
95567 + } else
95568 + address_m = address + SEGMEXEC_TASK_SIZE;
95569 +
95570 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95571 + return VM_FAULT_OOM;
95572 + address_m &= HPAGE_MASK;
95573 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95574 + }
95575 +#endif
95576 +
95577 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95578 if (!ptep)
95579 return VM_FAULT_OOM;
95580 diff --git a/mm/internal.h b/mm/internal.h
95581 index 5f2772f..4c3882c 100644
95582 --- a/mm/internal.h
95583 +++ b/mm/internal.h
95584 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95585
95586 extern int __isolate_free_page(struct page *page, unsigned int order);
95587 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95588 +extern void free_compound_page(struct page *page);
95589 extern void prep_compound_page(struct page *page, unsigned long order);
95590 #ifdef CONFIG_MEMORY_FAILURE
95591 extern bool is_free_buddy_page(struct page *page);
95592 @@ -376,7 +377,7 @@ extern u32 hwpoison_filter_enable;
95593
95594 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95595 unsigned long, unsigned long,
95596 - unsigned long, unsigned long);
95597 + unsigned long, unsigned long) __intentional_overflow(-1);
95598
95599 extern void set_pageblock_order(void);
95600 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95601 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95602 index 141dcf7..7327fd3 100644
95603 --- a/mm/iov_iter.c
95604 +++ b/mm/iov_iter.c
95605 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95606
95607 while (bytes) {
95608 char __user *buf = iov->iov_base + base;
95609 - int copy = min(bytes, iov->iov_len - base);
95610 + size_t copy = min(bytes, iov->iov_len - base);
95611
95612 base = 0;
95613 left = __copy_from_user_inatomic(vaddr, buf, copy);
95614 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95615
95616 kaddr = kmap_atomic(page);
95617 if (likely(i->nr_segs == 1)) {
95618 - int left;
95619 + size_t left;
95620 char __user *buf = i->iov->iov_base + i->iov_offset;
95621 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95622 copied = bytes - left;
95623 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95624 * zero-length segments (without overruning the iovec).
95625 */
95626 while (bytes || unlikely(i->count && !iov->iov_len)) {
95627 - int copy;
95628 + size_t copy;
95629
95630 copy = min(bytes, iov->iov_len - base);
95631 BUG_ON(!i->count || i->count < copy);
95632 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95633 index 3cda50c..032ba634 100644
95634 --- a/mm/kmemleak.c
95635 +++ b/mm/kmemleak.c
95636 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95637
95638 for (i = 0; i < object->trace_len; i++) {
95639 void *ptr = (void *)object->trace[i];
95640 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95641 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95642 }
95643 }
95644
95645 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95646 return -ENOMEM;
95647 }
95648
95649 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95650 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95651 &kmemleak_fops);
95652 if (!dentry)
95653 pr_warning("Failed to create the debugfs kmemleak file\n");
95654 diff --git a/mm/maccess.c b/mm/maccess.c
95655 index d53adf9..03a24bf 100644
95656 --- a/mm/maccess.c
95657 +++ b/mm/maccess.c
95658 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95659 set_fs(KERNEL_DS);
95660 pagefault_disable();
95661 ret = __copy_from_user_inatomic(dst,
95662 - (__force const void __user *)src, size);
95663 + (const void __force_user *)src, size);
95664 pagefault_enable();
95665 set_fs(old_fs);
95666
95667 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95668
95669 set_fs(KERNEL_DS);
95670 pagefault_disable();
95671 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95672 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95673 pagefault_enable();
95674 set_fs(old_fs);
95675
95676 diff --git a/mm/madvise.c b/mm/madvise.c
95677 index 0938b30..199abe8 100644
95678 --- a/mm/madvise.c
95679 +++ b/mm/madvise.c
95680 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95681 pgoff_t pgoff;
95682 unsigned long new_flags = vma->vm_flags;
95683
95684 +#ifdef CONFIG_PAX_SEGMEXEC
95685 + struct vm_area_struct *vma_m;
95686 +#endif
95687 +
95688 switch (behavior) {
95689 case MADV_NORMAL:
95690 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95691 @@ -126,6 +130,13 @@ success:
95692 /*
95693 * vm_flags is protected by the mmap_sem held in write mode.
95694 */
95695 +
95696 +#ifdef CONFIG_PAX_SEGMEXEC
95697 + vma_m = pax_find_mirror_vma(vma);
95698 + if (vma_m)
95699 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95700 +#endif
95701 +
95702 vma->vm_flags = new_flags;
95703
95704 out:
95705 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95706 struct vm_area_struct **prev,
95707 unsigned long start, unsigned long end)
95708 {
95709 +
95710 +#ifdef CONFIG_PAX_SEGMEXEC
95711 + struct vm_area_struct *vma_m;
95712 +#endif
95713 +
95714 *prev = vma;
95715 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95716 return -EINVAL;
95717 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95718 zap_page_range(vma, start, end - start, &details);
95719 } else
95720 zap_page_range(vma, start, end - start, NULL);
95721 +
95722 +#ifdef CONFIG_PAX_SEGMEXEC
95723 + vma_m = pax_find_mirror_vma(vma);
95724 + if (vma_m) {
95725 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95726 + struct zap_details details = {
95727 + .nonlinear_vma = vma_m,
95728 + .last_index = ULONG_MAX,
95729 + };
95730 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95731 + } else
95732 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95733 + }
95734 +#endif
95735 +
95736 return 0;
95737 }
95738
95739 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95740 if (end < start)
95741 return error;
95742
95743 +#ifdef CONFIG_PAX_SEGMEXEC
95744 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95745 + if (end > SEGMEXEC_TASK_SIZE)
95746 + return error;
95747 + } else
95748 +#endif
95749 +
95750 + if (end > TASK_SIZE)
95751 + return error;
95752 +
95753 error = 0;
95754 if (end == start)
95755 return error;
95756 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95757 index 44c6bd2..60369dc3 100644
95758 --- a/mm/memory-failure.c
95759 +++ b/mm/memory-failure.c
95760 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95761
95762 int sysctl_memory_failure_recovery __read_mostly = 1;
95763
95764 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95765 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95766
95767 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95768
95769 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95770 pfn, t->comm, t->pid);
95771 si.si_signo = SIGBUS;
95772 si.si_errno = 0;
95773 - si.si_addr = (void *)addr;
95774 + si.si_addr = (void __user *)addr;
95775 #ifdef __ARCH_SI_TRAPNO
95776 si.si_trapno = trapno;
95777 #endif
95778 @@ -791,7 +791,7 @@ static struct page_state {
95779 unsigned long res;
95780 char *msg;
95781 int (*action)(struct page *p, unsigned long pfn);
95782 -} error_states[] = {
95783 +} __do_const error_states[] = {
95784 { reserved, reserved, "reserved kernel", me_kernel },
95785 /*
95786 * free pages are specially detected outside this table:
95787 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95788 nr_pages = 1 << compound_order(hpage);
95789 else /* normal page or thp */
95790 nr_pages = 1;
95791 - atomic_long_add(nr_pages, &num_poisoned_pages);
95792 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95793
95794 /*
95795 * We need/can do nothing about count=0 pages.
95796 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95797 if (PageHWPoison(hpage)) {
95798 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95799 || (p != hpage && TestSetPageHWPoison(hpage))) {
95800 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95801 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95802 unlock_page(hpage);
95803 return 0;
95804 }
95805 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95806 */
95807 if (!PageHWPoison(p)) {
95808 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95809 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95810 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95811 put_page(hpage);
95812 res = 0;
95813 goto out;
95814 }
95815 if (hwpoison_filter(p)) {
95816 if (TestClearPageHWPoison(p))
95817 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95818 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95819 unlock_page(hpage);
95820 put_page(hpage);
95821 return 0;
95822 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95823 return 0;
95824 }
95825 if (TestClearPageHWPoison(p))
95826 - atomic_long_dec(&num_poisoned_pages);
95827 + atomic_long_dec_unchecked(&num_poisoned_pages);
95828 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95829 return 0;
95830 }
95831 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95832 */
95833 if (TestClearPageHWPoison(page)) {
95834 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95835 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95836 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95837 freeit = 1;
95838 if (PageHuge(page))
95839 clear_page_hwpoison_huge_page(page);
95840 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95841 if (PageHuge(page)) {
95842 set_page_hwpoison_huge_page(hpage);
95843 dequeue_hwpoisoned_huge_page(hpage);
95844 - atomic_long_add(1 << compound_order(hpage),
95845 + atomic_long_add_unchecked(1 << compound_order(hpage),
95846 &num_poisoned_pages);
95847 } else {
95848 SetPageHWPoison(page);
95849 - atomic_long_inc(&num_poisoned_pages);
95850 + atomic_long_inc_unchecked(&num_poisoned_pages);
95851 }
95852 }
95853 return ret;
95854 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95855 put_page(page);
95856 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95857 SetPageHWPoison(page);
95858 - atomic_long_inc(&num_poisoned_pages);
95859 + atomic_long_inc_unchecked(&num_poisoned_pages);
95860 return 0;
95861 }
95862
95863 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95864 if (!is_free_buddy_page(page))
95865 pr_info("soft offline: %#lx: page leaked\n",
95866 pfn);
95867 - atomic_long_inc(&num_poisoned_pages);
95868 + atomic_long_inc_unchecked(&num_poisoned_pages);
95869 }
95870 } else {
95871 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95872 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95873 if (PageHuge(page)) {
95874 set_page_hwpoison_huge_page(hpage);
95875 dequeue_hwpoisoned_huge_page(hpage);
95876 - atomic_long_add(1 << compound_order(hpage),
95877 + atomic_long_add_unchecked(1 << compound_order(hpage),
95878 &num_poisoned_pages);
95879 } else {
95880 SetPageHWPoison(page);
95881 - atomic_long_inc(&num_poisoned_pages);
95882 + atomic_long_inc_unchecked(&num_poisoned_pages);
95883 }
95884 }
95885 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
95886 diff --git a/mm/memory.c b/mm/memory.c
95887 index 37b80fc..68218aa 100644
95888 --- a/mm/memory.c
95889 +++ b/mm/memory.c
95890 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95891 free_pte_range(tlb, pmd, addr);
95892 } while (pmd++, addr = next, addr != end);
95893
95894 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
95895 start &= PUD_MASK;
95896 if (start < floor)
95897 return;
95898 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95899 pmd = pmd_offset(pud, start);
95900 pud_clear(pud);
95901 pmd_free_tlb(tlb, pmd, start);
95902 +#endif
95903 +
95904 }
95905
95906 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95907 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95908 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
95909 } while (pud++, addr = next, addr != end);
95910
95911 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
95912 start &= PGDIR_MASK;
95913 if (start < floor)
95914 return;
95915 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95916 pud = pud_offset(pgd, start);
95917 pgd_clear(pgd);
95918 pud_free_tlb(tlb, pud, start);
95919 +#endif
95920 +
95921 }
95922
95923 /*
95924 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
95925 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
95926 */
95927 if (vma->vm_ops)
95928 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
95929 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
95930 vma->vm_ops->fault);
95931 if (vma->vm_file)
95932 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
95933 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
95934 vma->vm_file->f_op->mmap);
95935 dump_stack();
95936 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
95937 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
95938 page_add_file_rmap(page);
95939 set_pte_at(mm, addr, pte, mk_pte(page, prot));
95940
95941 +#ifdef CONFIG_PAX_SEGMEXEC
95942 + pax_mirror_file_pte(vma, addr, page, ptl);
95943 +#endif
95944 +
95945 retval = 0;
95946 pte_unmap_unlock(pte, ptl);
95947 return retval;
95948 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
95949 if (!page_count(page))
95950 return -EINVAL;
95951 if (!(vma->vm_flags & VM_MIXEDMAP)) {
95952 +
95953 +#ifdef CONFIG_PAX_SEGMEXEC
95954 + struct vm_area_struct *vma_m;
95955 +#endif
95956 +
95957 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
95958 BUG_ON(vma->vm_flags & VM_PFNMAP);
95959 vma->vm_flags |= VM_MIXEDMAP;
95960 +
95961 +#ifdef CONFIG_PAX_SEGMEXEC
95962 + vma_m = pax_find_mirror_vma(vma);
95963 + if (vma_m)
95964 + vma_m->vm_flags |= VM_MIXEDMAP;
95965 +#endif
95966 +
95967 }
95968 return insert_page(vma, addr, page, vma->vm_page_prot);
95969 }
95970 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
95971 unsigned long pfn)
95972 {
95973 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
95974 + BUG_ON(vma->vm_mirror);
95975
95976 if (addr < vma->vm_start || addr >= vma->vm_end)
95977 return -EFAULT;
95978 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
95979
95980 BUG_ON(pud_huge(*pud));
95981
95982 - pmd = pmd_alloc(mm, pud, addr);
95983 + pmd = (mm == &init_mm) ?
95984 + pmd_alloc_kernel(mm, pud, addr) :
95985 + pmd_alloc(mm, pud, addr);
95986 if (!pmd)
95987 return -ENOMEM;
95988 do {
95989 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
95990 unsigned long next;
95991 int err;
95992
95993 - pud = pud_alloc(mm, pgd, addr);
95994 + pud = (mm == &init_mm) ?
95995 + pud_alloc_kernel(mm, pgd, addr) :
95996 + pud_alloc(mm, pgd, addr);
95997 if (!pud)
95998 return -ENOMEM;
95999 do {
96000 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96001 return ret;
96002 }
96003
96004 +#ifdef CONFIG_PAX_SEGMEXEC
96005 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96006 +{
96007 + struct mm_struct *mm = vma->vm_mm;
96008 + spinlock_t *ptl;
96009 + pte_t *pte, entry;
96010 +
96011 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96012 + entry = *pte;
96013 + if (!pte_present(entry)) {
96014 + if (!pte_none(entry)) {
96015 + BUG_ON(pte_file(entry));
96016 + free_swap_and_cache(pte_to_swp_entry(entry));
96017 + pte_clear_not_present_full(mm, address, pte, 0);
96018 + }
96019 + } else {
96020 + struct page *page;
96021 +
96022 + flush_cache_page(vma, address, pte_pfn(entry));
96023 + entry = ptep_clear_flush(vma, address, pte);
96024 + BUG_ON(pte_dirty(entry));
96025 + page = vm_normal_page(vma, address, entry);
96026 + if (page) {
96027 + update_hiwater_rss(mm);
96028 + if (PageAnon(page))
96029 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96030 + else
96031 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96032 + page_remove_rmap(page);
96033 + page_cache_release(page);
96034 + }
96035 + }
96036 + pte_unmap_unlock(pte, ptl);
96037 +}
96038 +
96039 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96040 + *
96041 + * the ptl of the lower mapped page is held on entry and is not released on exit
96042 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96043 + */
96044 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96045 +{
96046 + struct mm_struct *mm = vma->vm_mm;
96047 + unsigned long address_m;
96048 + spinlock_t *ptl_m;
96049 + struct vm_area_struct *vma_m;
96050 + pmd_t *pmd_m;
96051 + pte_t *pte_m, entry_m;
96052 +
96053 + BUG_ON(!page_m || !PageAnon(page_m));
96054 +
96055 + vma_m = pax_find_mirror_vma(vma);
96056 + if (!vma_m)
96057 + return;
96058 +
96059 + BUG_ON(!PageLocked(page_m));
96060 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96061 + address_m = address + SEGMEXEC_TASK_SIZE;
96062 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96063 + pte_m = pte_offset_map(pmd_m, address_m);
96064 + ptl_m = pte_lockptr(mm, pmd_m);
96065 + if (ptl != ptl_m) {
96066 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96067 + if (!pte_none(*pte_m))
96068 + goto out;
96069 + }
96070 +
96071 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96072 + page_cache_get(page_m);
96073 + page_add_anon_rmap(page_m, vma_m, address_m);
96074 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96075 + set_pte_at(mm, address_m, pte_m, entry_m);
96076 + update_mmu_cache(vma_m, address_m, pte_m);
96077 +out:
96078 + if (ptl != ptl_m)
96079 + spin_unlock(ptl_m);
96080 + pte_unmap(pte_m);
96081 + unlock_page(page_m);
96082 +}
96083 +
96084 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96085 +{
96086 + struct mm_struct *mm = vma->vm_mm;
96087 + unsigned long address_m;
96088 + spinlock_t *ptl_m;
96089 + struct vm_area_struct *vma_m;
96090 + pmd_t *pmd_m;
96091 + pte_t *pte_m, entry_m;
96092 +
96093 + BUG_ON(!page_m || PageAnon(page_m));
96094 +
96095 + vma_m = pax_find_mirror_vma(vma);
96096 + if (!vma_m)
96097 + return;
96098 +
96099 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96100 + address_m = address + SEGMEXEC_TASK_SIZE;
96101 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96102 + pte_m = pte_offset_map(pmd_m, address_m);
96103 + ptl_m = pte_lockptr(mm, pmd_m);
96104 + if (ptl != ptl_m) {
96105 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96106 + if (!pte_none(*pte_m))
96107 + goto out;
96108 + }
96109 +
96110 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96111 + page_cache_get(page_m);
96112 + page_add_file_rmap(page_m);
96113 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96114 + set_pte_at(mm, address_m, pte_m, entry_m);
96115 + update_mmu_cache(vma_m, address_m, pte_m);
96116 +out:
96117 + if (ptl != ptl_m)
96118 + spin_unlock(ptl_m);
96119 + pte_unmap(pte_m);
96120 +}
96121 +
96122 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96123 +{
96124 + struct mm_struct *mm = vma->vm_mm;
96125 + unsigned long address_m;
96126 + spinlock_t *ptl_m;
96127 + struct vm_area_struct *vma_m;
96128 + pmd_t *pmd_m;
96129 + pte_t *pte_m, entry_m;
96130 +
96131 + vma_m = pax_find_mirror_vma(vma);
96132 + if (!vma_m)
96133 + return;
96134 +
96135 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96136 + address_m = address + SEGMEXEC_TASK_SIZE;
96137 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96138 + pte_m = pte_offset_map(pmd_m, address_m);
96139 + ptl_m = pte_lockptr(mm, pmd_m);
96140 + if (ptl != ptl_m) {
96141 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96142 + if (!pte_none(*pte_m))
96143 + goto out;
96144 + }
96145 +
96146 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96147 + set_pte_at(mm, address_m, pte_m, entry_m);
96148 +out:
96149 + if (ptl != ptl_m)
96150 + spin_unlock(ptl_m);
96151 + pte_unmap(pte_m);
96152 +}
96153 +
96154 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96155 +{
96156 + struct page *page_m;
96157 + pte_t entry;
96158 +
96159 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96160 + goto out;
96161 +
96162 + entry = *pte;
96163 + page_m = vm_normal_page(vma, address, entry);
96164 + if (!page_m)
96165 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96166 + else if (PageAnon(page_m)) {
96167 + if (pax_find_mirror_vma(vma)) {
96168 + pte_unmap_unlock(pte, ptl);
96169 + lock_page(page_m);
96170 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96171 + if (pte_same(entry, *pte))
96172 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96173 + else
96174 + unlock_page(page_m);
96175 + }
96176 + } else
96177 + pax_mirror_file_pte(vma, address, page_m, ptl);
96178 +
96179 +out:
96180 + pte_unmap_unlock(pte, ptl);
96181 +}
96182 +#endif
96183 +
96184 /*
96185 * This routine handles present pages, when users try to write
96186 * to a shared page. It is done by copying the page to a new address
96187 @@ -2217,6 +2424,12 @@ gotten:
96188 */
96189 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96190 if (likely(pte_same(*page_table, orig_pte))) {
96191 +
96192 +#ifdef CONFIG_PAX_SEGMEXEC
96193 + if (pax_find_mirror_vma(vma))
96194 + BUG_ON(!trylock_page(new_page));
96195 +#endif
96196 +
96197 if (old_page) {
96198 if (!PageAnon(old_page)) {
96199 dec_mm_counter_fast(mm, MM_FILEPAGES);
96200 @@ -2270,6 +2483,10 @@ gotten:
96201 page_remove_rmap(old_page);
96202 }
96203
96204 +#ifdef CONFIG_PAX_SEGMEXEC
96205 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96206 +#endif
96207 +
96208 /* Free the old page.. */
96209 new_page = old_page;
96210 ret |= VM_FAULT_WRITE;
96211 @@ -2544,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96212 swap_free(entry);
96213 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96214 try_to_free_swap(page);
96215 +
96216 +#ifdef CONFIG_PAX_SEGMEXEC
96217 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96218 +#endif
96219 +
96220 unlock_page(page);
96221 if (page != swapcache) {
96222 /*
96223 @@ -2567,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96224
96225 /* No need to invalidate - it was non-present before */
96226 update_mmu_cache(vma, address, page_table);
96227 +
96228 +#ifdef CONFIG_PAX_SEGMEXEC
96229 + pax_mirror_anon_pte(vma, address, page, ptl);
96230 +#endif
96231 +
96232 unlock:
96233 pte_unmap_unlock(page_table, ptl);
96234 out:
96235 @@ -2586,40 +2813,6 @@ out_release:
96236 }
96237
96238 /*
96239 - * This is like a special single-page "expand_{down|up}wards()",
96240 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96241 - * doesn't hit another vma.
96242 - */
96243 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96244 -{
96245 - address &= PAGE_MASK;
96246 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96247 - struct vm_area_struct *prev = vma->vm_prev;
96248 -
96249 - /*
96250 - * Is there a mapping abutting this one below?
96251 - *
96252 - * That's only ok if it's the same stack mapping
96253 - * that has gotten split..
96254 - */
96255 - if (prev && prev->vm_end == address)
96256 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96257 -
96258 - expand_downwards(vma, address - PAGE_SIZE);
96259 - }
96260 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96261 - struct vm_area_struct *next = vma->vm_next;
96262 -
96263 - /* As VM_GROWSDOWN but s/below/above/ */
96264 - if (next && next->vm_start == address + PAGE_SIZE)
96265 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96266 -
96267 - expand_upwards(vma, address + PAGE_SIZE);
96268 - }
96269 - return 0;
96270 -}
96271 -
96272 -/*
96273 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96274 * but allow concurrent faults), and pte mapped but not yet locked.
96275 * We return with mmap_sem still held, but pte unmapped and unlocked.
96276 @@ -2629,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96277 unsigned int flags)
96278 {
96279 struct mem_cgroup *memcg;
96280 - struct page *page;
96281 + struct page *page = NULL;
96282 spinlock_t *ptl;
96283 pte_t entry;
96284
96285 - pte_unmap(page_table);
96286 -
96287 - /* Check if we need to add a guard page to the stack */
96288 - if (check_stack_guard_page(vma, address) < 0)
96289 - return VM_FAULT_SIGBUS;
96290 -
96291 - /* Use the zero-page for reads */
96292 if (!(flags & FAULT_FLAG_WRITE)) {
96293 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96294 vma->vm_page_prot));
96295 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96296 + ptl = pte_lockptr(mm, pmd);
96297 + spin_lock(ptl);
96298 if (!pte_none(*page_table))
96299 goto unlock;
96300 goto setpte;
96301 }
96302
96303 /* Allocate our own private page. */
96304 + pte_unmap(page_table);
96305 +
96306 if (unlikely(anon_vma_prepare(vma)))
96307 goto oom;
96308 page = alloc_zeroed_user_highpage_movable(vma, address);
96309 @@ -2673,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96310 if (!pte_none(*page_table))
96311 goto release;
96312
96313 +#ifdef CONFIG_PAX_SEGMEXEC
96314 + if (pax_find_mirror_vma(vma))
96315 + BUG_ON(!trylock_page(page));
96316 +#endif
96317 +
96318 inc_mm_counter_fast(mm, MM_ANONPAGES);
96319 page_add_new_anon_rmap(page, vma, address);
96320 mem_cgroup_commit_charge(page, memcg, false);
96321 @@ -2682,6 +2876,12 @@ setpte:
96322
96323 /* No need to invalidate - it was non-present before */
96324 update_mmu_cache(vma, address, page_table);
96325 +
96326 +#ifdef CONFIG_PAX_SEGMEXEC
96327 + if (page)
96328 + pax_mirror_anon_pte(vma, address, page, ptl);
96329 +#endif
96330 +
96331 unlock:
96332 pte_unmap_unlock(page_table, ptl);
96333 return 0;
96334 @@ -2912,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96335 return ret;
96336 }
96337 do_set_pte(vma, address, fault_page, pte, false, false);
96338 +
96339 +#ifdef CONFIG_PAX_SEGMEXEC
96340 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96341 +#endif
96342 +
96343 unlock_page(fault_page);
96344 unlock_out:
96345 pte_unmap_unlock(pte, ptl);
96346 @@ -2954,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96347 page_cache_release(fault_page);
96348 goto uncharge_out;
96349 }
96350 +
96351 +#ifdef CONFIG_PAX_SEGMEXEC
96352 + if (pax_find_mirror_vma(vma))
96353 + BUG_ON(!trylock_page(new_page));
96354 +#endif
96355 +
96356 do_set_pte(vma, address, new_page, pte, true, true);
96357 +
96358 +#ifdef CONFIG_PAX_SEGMEXEC
96359 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96360 +#endif
96361 +
96362 mem_cgroup_commit_charge(new_page, memcg, false);
96363 lru_cache_add_active_or_unevictable(new_page, vma);
96364 pte_unmap_unlock(pte, ptl);
96365 @@ -3004,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96366 return ret;
96367 }
96368 do_set_pte(vma, address, fault_page, pte, true, false);
96369 +
96370 +#ifdef CONFIG_PAX_SEGMEXEC
96371 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96372 +#endif
96373 +
96374 pte_unmap_unlock(pte, ptl);
96375
96376 if (set_page_dirty(fault_page))
96377 @@ -3245,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96378 if (flags & FAULT_FLAG_WRITE)
96379 flush_tlb_fix_spurious_fault(vma, address);
96380 }
96381 +
96382 +#ifdef CONFIG_PAX_SEGMEXEC
96383 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96384 + return 0;
96385 +#endif
96386 +
96387 unlock:
96388 pte_unmap_unlock(pte, ptl);
96389 return 0;
96390 @@ -3264,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96391 pmd_t *pmd;
96392 pte_t *pte;
96393
96394 +#ifdef CONFIG_PAX_SEGMEXEC
96395 + struct vm_area_struct *vma_m;
96396 +#endif
96397 +
96398 if (unlikely(is_vm_hugetlb_page(vma)))
96399 return hugetlb_fault(mm, vma, address, flags);
96400
96401 +#ifdef CONFIG_PAX_SEGMEXEC
96402 + vma_m = pax_find_mirror_vma(vma);
96403 + if (vma_m) {
96404 + unsigned long address_m;
96405 + pgd_t *pgd_m;
96406 + pud_t *pud_m;
96407 + pmd_t *pmd_m;
96408 +
96409 + if (vma->vm_start > vma_m->vm_start) {
96410 + address_m = address;
96411 + address -= SEGMEXEC_TASK_SIZE;
96412 + vma = vma_m;
96413 + } else
96414 + address_m = address + SEGMEXEC_TASK_SIZE;
96415 +
96416 + pgd_m = pgd_offset(mm, address_m);
96417 + pud_m = pud_alloc(mm, pgd_m, address_m);
96418 + if (!pud_m)
96419 + return VM_FAULT_OOM;
96420 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96421 + if (!pmd_m)
96422 + return VM_FAULT_OOM;
96423 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96424 + return VM_FAULT_OOM;
96425 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96426 + }
96427 +#endif
96428 +
96429 pgd = pgd_offset(mm, address);
96430 pud = pud_alloc(mm, pgd, address);
96431 if (!pud)
96432 @@ -3400,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96433 spin_unlock(&mm->page_table_lock);
96434 return 0;
96435 }
96436 +
96437 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96438 +{
96439 + pud_t *new = pud_alloc_one(mm, address);
96440 + if (!new)
96441 + return -ENOMEM;
96442 +
96443 + smp_wmb(); /* See comment in __pte_alloc */
96444 +
96445 + spin_lock(&mm->page_table_lock);
96446 + if (pgd_present(*pgd)) /* Another has populated it */
96447 + pud_free(mm, new);
96448 + else
96449 + pgd_populate_kernel(mm, pgd, new);
96450 + spin_unlock(&mm->page_table_lock);
96451 + return 0;
96452 +}
96453 #endif /* __PAGETABLE_PUD_FOLDED */
96454
96455 #ifndef __PAGETABLE_PMD_FOLDED
96456 @@ -3430,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96457 spin_unlock(&mm->page_table_lock);
96458 return 0;
96459 }
96460 +
96461 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96462 +{
96463 + pmd_t *new = pmd_alloc_one(mm, address);
96464 + if (!new)
96465 + return -ENOMEM;
96466 +
96467 + smp_wmb(); /* See comment in __pte_alloc */
96468 +
96469 + spin_lock(&mm->page_table_lock);
96470 +#ifndef __ARCH_HAS_4LEVEL_HACK
96471 + if (pud_present(*pud)) /* Another has populated it */
96472 + pmd_free(mm, new);
96473 + else
96474 + pud_populate_kernel(mm, pud, new);
96475 +#else
96476 + if (pgd_present(*pud)) /* Another has populated it */
96477 + pmd_free(mm, new);
96478 + else
96479 + pgd_populate_kernel(mm, pud, new);
96480 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96481 + spin_unlock(&mm->page_table_lock);
96482 + return 0;
96483 +}
96484 #endif /* __PAGETABLE_PMD_FOLDED */
96485
96486 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96487 @@ -3539,8 +3839,8 @@ out:
96488 return ret;
96489 }
96490
96491 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96492 - void *buf, int len, int write)
96493 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96494 + void *buf, size_t len, int write)
96495 {
96496 resource_size_t phys_addr;
96497 unsigned long prot = 0;
96498 @@ -3566,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96499 * Access another process' address space as given in mm. If non-NULL, use the
96500 * given task for page fault accounting.
96501 */
96502 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96503 - unsigned long addr, void *buf, int len, int write)
96504 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96505 + unsigned long addr, void *buf, size_t len, int write)
96506 {
96507 struct vm_area_struct *vma;
96508 void *old_buf = buf;
96509 @@ -3575,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96510 down_read(&mm->mmap_sem);
96511 /* ignore errors, just check how much was successfully transferred */
96512 while (len) {
96513 - int bytes, ret, offset;
96514 + ssize_t bytes, ret, offset;
96515 void *maddr;
96516 struct page *page = NULL;
96517
96518 @@ -3636,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96519 *
96520 * The caller must hold a reference on @mm.
96521 */
96522 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96523 - void *buf, int len, int write)
96524 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96525 + void *buf, size_t len, int write)
96526 {
96527 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96528 }
96529 @@ -3647,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96530 * Source/target buffer must be kernel space,
96531 * Do not walk the page table directly, use get_user_pages
96532 */
96533 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96534 - void *buf, int len, int write)
96535 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96536 + void *buf, size_t len, int write)
96537 {
96538 struct mm_struct *mm;
96539 - int ret;
96540 + ssize_t ret;
96541
96542 mm = get_task_mm(tsk);
96543 if (!mm)
96544 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96545 index 8f5330d..b41914b 100644
96546 --- a/mm/mempolicy.c
96547 +++ b/mm/mempolicy.c
96548 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96549 unsigned long vmstart;
96550 unsigned long vmend;
96551
96552 +#ifdef CONFIG_PAX_SEGMEXEC
96553 + struct vm_area_struct *vma_m;
96554 +#endif
96555 +
96556 vma = find_vma(mm, start);
96557 if (!vma || vma->vm_start > start)
96558 return -EFAULT;
96559 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96560 err = vma_replace_policy(vma, new_pol);
96561 if (err)
96562 goto out;
96563 +
96564 +#ifdef CONFIG_PAX_SEGMEXEC
96565 + vma_m = pax_find_mirror_vma(vma);
96566 + if (vma_m) {
96567 + err = vma_replace_policy(vma_m, new_pol);
96568 + if (err)
96569 + goto out;
96570 + }
96571 +#endif
96572 +
96573 }
96574
96575 out:
96576 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96577
96578 if (end < start)
96579 return -EINVAL;
96580 +
96581 +#ifdef CONFIG_PAX_SEGMEXEC
96582 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96583 + if (end > SEGMEXEC_TASK_SIZE)
96584 + return -EINVAL;
96585 + } else
96586 +#endif
96587 +
96588 + if (end > TASK_SIZE)
96589 + return -EINVAL;
96590 +
96591 if (end == start)
96592 return 0;
96593
96594 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96595 */
96596 tcred = __task_cred(task);
96597 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96598 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96599 - !capable(CAP_SYS_NICE)) {
96600 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96601 rcu_read_unlock();
96602 err = -EPERM;
96603 goto out_put;
96604 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96605 goto out;
96606 }
96607
96608 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96609 + if (mm != current->mm &&
96610 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96611 + mmput(mm);
96612 + err = -EPERM;
96613 + goto out;
96614 + }
96615 +#endif
96616 +
96617 err = do_migrate_pages(mm, old, new,
96618 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96619
96620 diff --git a/mm/migrate.c b/mm/migrate.c
96621 index 0143995..b294728 100644
96622 --- a/mm/migrate.c
96623 +++ b/mm/migrate.c
96624 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96625 */
96626 tcred = __task_cred(task);
96627 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96628 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96629 - !capable(CAP_SYS_NICE)) {
96630 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96631 rcu_read_unlock();
96632 err = -EPERM;
96633 goto out;
96634 diff --git a/mm/mlock.c b/mm/mlock.c
96635 index ce84cb0..6d5a9aa 100644
96636 --- a/mm/mlock.c
96637 +++ b/mm/mlock.c
96638 @@ -14,6 +14,7 @@
96639 #include <linux/pagevec.h>
96640 #include <linux/mempolicy.h>
96641 #include <linux/syscalls.h>
96642 +#include <linux/security.h>
96643 #include <linux/sched.h>
96644 #include <linux/export.h>
96645 #include <linux/rmap.h>
96646 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96647 {
96648 unsigned long nstart, end, tmp;
96649 struct vm_area_struct * vma, * prev;
96650 - int error;
96651 + int error = 0;
96652
96653 VM_BUG_ON(start & ~PAGE_MASK);
96654 VM_BUG_ON(len != PAGE_ALIGN(len));
96655 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96656 return -EINVAL;
96657 if (end == start)
96658 return 0;
96659 + if (end > TASK_SIZE)
96660 + return -EINVAL;
96661 +
96662 vma = find_vma(current->mm, start);
96663 if (!vma || vma->vm_start > start)
96664 return -ENOMEM;
96665 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96666 for (nstart = start ; ; ) {
96667 vm_flags_t newflags;
96668
96669 +#ifdef CONFIG_PAX_SEGMEXEC
96670 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96671 + break;
96672 +#endif
96673 +
96674 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96675
96676 newflags = vma->vm_flags & ~VM_LOCKED;
96677 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96678 locked += current->mm->locked_vm;
96679
96680 /* check against resource limits */
96681 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96682 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96683 error = do_mlock(start, len, 1);
96684
96685 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96686 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96687 vm_flags_t newflags;
96688
96689 +#ifdef CONFIG_PAX_SEGMEXEC
96690 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96691 + break;
96692 +#endif
96693 +
96694 newflags = vma->vm_flags & ~VM_LOCKED;
96695 if (flags & MCL_CURRENT)
96696 newflags |= VM_LOCKED;
96697 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96698 lock_limit >>= PAGE_SHIFT;
96699
96700 ret = -ENOMEM;
96701 +
96702 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96703 +
96704 down_write(&current->mm->mmap_sem);
96705 -
96706 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96707 capable(CAP_IPC_LOCK))
96708 ret = do_mlockall(flags);
96709 diff --git a/mm/mmap.c b/mm/mmap.c
96710 index ebc25fa..0ef0db0 100644
96711 --- a/mm/mmap.c
96712 +++ b/mm/mmap.c
96713 @@ -41,6 +41,7 @@
96714 #include <linux/notifier.h>
96715 #include <linux/memory.h>
96716 #include <linux/printk.h>
96717 +#include <linux/random.h>
96718
96719 #include <asm/uaccess.h>
96720 #include <asm/cacheflush.h>
96721 @@ -57,6 +58,16 @@
96722 #define arch_rebalance_pgtables(addr, len) (addr)
96723 #endif
96724
96725 +static inline void verify_mm_writelocked(struct mm_struct *mm)
96726 +{
96727 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96728 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96729 + up_read(&mm->mmap_sem);
96730 + BUG();
96731 + }
96732 +#endif
96733 +}
96734 +
96735 static void unmap_region(struct mm_struct *mm,
96736 struct vm_area_struct *vma, struct vm_area_struct *prev,
96737 unsigned long start, unsigned long end);
96738 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96739 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96740 *
96741 */
96742 -pgprot_t protection_map[16] = {
96743 +pgprot_t protection_map[16] __read_only = {
96744 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96745 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96746 };
96747
96748 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
96749 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96750 {
96751 - return __pgprot(pgprot_val(protection_map[vm_flags &
96752 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96753 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96754 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96755 +
96756 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96757 + if (!(__supported_pte_mask & _PAGE_NX) &&
96758 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96759 + (vm_flags & (VM_READ | VM_WRITE)))
96760 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96761 +#endif
96762 +
96763 + return prot;
96764 }
96765 EXPORT_SYMBOL(vm_get_page_prot);
96766
96767 @@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96768 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96769 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96770 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96771 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96772 /*
96773 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96774 * other variables. It can be updated by several CPUs frequently.
96775 @@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96776 struct vm_area_struct *next = vma->vm_next;
96777
96778 might_sleep();
96779 + BUG_ON(vma->vm_mirror);
96780 if (vma->vm_ops && vma->vm_ops->close)
96781 vma->vm_ops->close(vma);
96782 if (vma->vm_file)
96783 @@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96784 * not page aligned -Ram Gupta
96785 */
96786 rlim = rlimit(RLIMIT_DATA);
96787 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96788 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
96789 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96790 + rlim = 4096 * PAGE_SIZE;
96791 +#endif
96792 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
96793 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
96794 (mm->end_data - mm->start_data) > rlim)
96795 goto out;
96796 @@ -949,6 +977,12 @@ static int
96797 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96798 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96799 {
96800 +
96801 +#ifdef CONFIG_PAX_SEGMEXEC
96802 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96803 + return 0;
96804 +#endif
96805 +
96806 if (is_mergeable_vma(vma, file, vm_flags) &&
96807 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96808 if (vma->vm_pgoff == vm_pgoff)
96809 @@ -968,6 +1002,12 @@ static int
96810 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96811 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96812 {
96813 +
96814 +#ifdef CONFIG_PAX_SEGMEXEC
96815 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96816 + return 0;
96817 +#endif
96818 +
96819 if (is_mergeable_vma(vma, file, vm_flags) &&
96820 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96821 pgoff_t vm_pglen;
96822 @@ -1010,13 +1050,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96823 struct vm_area_struct *vma_merge(struct mm_struct *mm,
96824 struct vm_area_struct *prev, unsigned long addr,
96825 unsigned long end, unsigned long vm_flags,
96826 - struct anon_vma *anon_vma, struct file *file,
96827 + struct anon_vma *anon_vma, struct file *file,
96828 pgoff_t pgoff, struct mempolicy *policy)
96829 {
96830 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
96831 struct vm_area_struct *area, *next;
96832 int err;
96833
96834 +#ifdef CONFIG_PAX_SEGMEXEC
96835 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
96836 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
96837 +
96838 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
96839 +#endif
96840 +
96841 /*
96842 * We later require that vma->vm_flags == vm_flags,
96843 * so this tests vma->vm_flags & VM_SPECIAL, too.
96844 @@ -1032,6 +1079,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96845 if (next && next->vm_end == end) /* cases 6, 7, 8 */
96846 next = next->vm_next;
96847
96848 +#ifdef CONFIG_PAX_SEGMEXEC
96849 + if (prev)
96850 + prev_m = pax_find_mirror_vma(prev);
96851 + if (area)
96852 + area_m = pax_find_mirror_vma(area);
96853 + if (next)
96854 + next_m = pax_find_mirror_vma(next);
96855 +#endif
96856 +
96857 /*
96858 * Can it merge with the predecessor?
96859 */
96860 @@ -1051,9 +1107,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96861 /* cases 1, 6 */
96862 err = vma_adjust(prev, prev->vm_start,
96863 next->vm_end, prev->vm_pgoff, NULL);
96864 - } else /* cases 2, 5, 7 */
96865 +
96866 +#ifdef CONFIG_PAX_SEGMEXEC
96867 + if (!err && prev_m)
96868 + err = vma_adjust(prev_m, prev_m->vm_start,
96869 + next_m->vm_end, prev_m->vm_pgoff, NULL);
96870 +#endif
96871 +
96872 + } else { /* cases 2, 5, 7 */
96873 err = vma_adjust(prev, prev->vm_start,
96874 end, prev->vm_pgoff, NULL);
96875 +
96876 +#ifdef CONFIG_PAX_SEGMEXEC
96877 + if (!err && prev_m)
96878 + err = vma_adjust(prev_m, prev_m->vm_start,
96879 + end_m, prev_m->vm_pgoff, NULL);
96880 +#endif
96881 +
96882 + }
96883 if (err)
96884 return NULL;
96885 khugepaged_enter_vma_merge(prev, vm_flags);
96886 @@ -1067,12 +1138,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96887 mpol_equal(policy, vma_policy(next)) &&
96888 can_vma_merge_before(next, vm_flags,
96889 anon_vma, file, pgoff+pglen)) {
96890 - if (prev && addr < prev->vm_end) /* case 4 */
96891 + if (prev && addr < prev->vm_end) { /* case 4 */
96892 err = vma_adjust(prev, prev->vm_start,
96893 addr, prev->vm_pgoff, NULL);
96894 - else /* cases 3, 8 */
96895 +
96896 +#ifdef CONFIG_PAX_SEGMEXEC
96897 + if (!err && prev_m)
96898 + err = vma_adjust(prev_m, prev_m->vm_start,
96899 + addr_m, prev_m->vm_pgoff, NULL);
96900 +#endif
96901 +
96902 + } else { /* cases 3, 8 */
96903 err = vma_adjust(area, addr, next->vm_end,
96904 next->vm_pgoff - pglen, NULL);
96905 +
96906 +#ifdef CONFIG_PAX_SEGMEXEC
96907 + if (!err && area_m)
96908 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
96909 + next_m->vm_pgoff - pglen, NULL);
96910 +#endif
96911 +
96912 + }
96913 if (err)
96914 return NULL;
96915 khugepaged_enter_vma_merge(area, vm_flags);
96916 @@ -1181,8 +1267,10 @@ none:
96917 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96918 struct file *file, long pages)
96919 {
96920 - const unsigned long stack_flags
96921 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
96922 +
96923 +#ifdef CONFIG_PAX_RANDMMAP
96924 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96925 +#endif
96926
96927 mm->total_vm += pages;
96928
96929 @@ -1190,7 +1278,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96930 mm->shared_vm += pages;
96931 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
96932 mm->exec_vm += pages;
96933 - } else if (flags & stack_flags)
96934 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
96935 mm->stack_vm += pages;
96936 }
96937 #endif /* CONFIG_PROC_FS */
96938 @@ -1220,6 +1308,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
96939 locked += mm->locked_vm;
96940 lock_limit = rlimit(RLIMIT_MEMLOCK);
96941 lock_limit >>= PAGE_SHIFT;
96942 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96943 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
96944 return -EAGAIN;
96945 }
96946 @@ -1246,7 +1335,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96947 * (the exception is when the underlying filesystem is noexec
96948 * mounted, in which case we dont add PROT_EXEC.)
96949 */
96950 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
96951 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
96952 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
96953 prot |= PROT_EXEC;
96954
96955 @@ -1272,7 +1361,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96956 /* Obtain the address to map to. we verify (or select) it and ensure
96957 * that it represents a valid section of the address space.
96958 */
96959 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
96960 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
96961 if (addr & ~PAGE_MASK)
96962 return addr;
96963
96964 @@ -1283,6 +1372,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96965 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
96966 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
96967
96968 +#ifdef CONFIG_PAX_MPROTECT
96969 + if (mm->pax_flags & MF_PAX_MPROTECT) {
96970 +
96971 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
96972 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
96973 + mm->binfmt->handle_mmap)
96974 + mm->binfmt->handle_mmap(file);
96975 +#endif
96976 +
96977 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
96978 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
96979 + gr_log_rwxmmap(file);
96980 +
96981 +#ifdef CONFIG_PAX_EMUPLT
96982 + vm_flags &= ~VM_EXEC;
96983 +#else
96984 + return -EPERM;
96985 +#endif
96986 +
96987 + }
96988 +
96989 + if (!(vm_flags & VM_EXEC))
96990 + vm_flags &= ~VM_MAYEXEC;
96991 +#else
96992 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
96993 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
96994 +#endif
96995 + else
96996 + vm_flags &= ~VM_MAYWRITE;
96997 + }
96998 +#endif
96999 +
97000 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97001 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97002 + vm_flags &= ~VM_PAGEEXEC;
97003 +#endif
97004 +
97005 if (flags & MAP_LOCKED)
97006 if (!can_do_mlock())
97007 return -EPERM;
97008 @@ -1370,6 +1496,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97009 vm_flags |= VM_NORESERVE;
97010 }
97011
97012 + if (!gr_acl_handle_mmap(file, prot))
97013 + return -EACCES;
97014 +
97015 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97016 if (!IS_ERR_VALUE(addr) &&
97017 ((vm_flags & VM_LOCKED) ||
97018 @@ -1463,7 +1592,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97019 vm_flags_t vm_flags = vma->vm_flags;
97020
97021 /* If it was private or non-writable, the write bit is already clear */
97022 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97023 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97024 return 0;
97025
97026 /* The backer wishes to know when pages are first written to? */
97027 @@ -1509,7 +1638,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97028 struct rb_node **rb_link, *rb_parent;
97029 unsigned long charged = 0;
97030
97031 +#ifdef CONFIG_PAX_SEGMEXEC
97032 + struct vm_area_struct *vma_m = NULL;
97033 +#endif
97034 +
97035 + /*
97036 + * mm->mmap_sem is required to protect against another thread
97037 + * changing the mappings in case we sleep.
97038 + */
97039 + verify_mm_writelocked(mm);
97040 +
97041 /* Check against address space limit. */
97042 +
97043 +#ifdef CONFIG_PAX_RANDMMAP
97044 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97045 +#endif
97046 +
97047 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97048 unsigned long nr_pages;
97049
97050 @@ -1528,11 +1672,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97051
97052 /* Clear old maps */
97053 error = -ENOMEM;
97054 -munmap_back:
97055 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97056 if (do_munmap(mm, addr, len))
97057 return -ENOMEM;
97058 - goto munmap_back;
97059 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97060 }
97061
97062 /*
97063 @@ -1563,6 +1706,16 @@ munmap_back:
97064 goto unacct_error;
97065 }
97066
97067 +#ifdef CONFIG_PAX_SEGMEXEC
97068 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97069 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97070 + if (!vma_m) {
97071 + error = -ENOMEM;
97072 + goto free_vma;
97073 + }
97074 + }
97075 +#endif
97076 +
97077 vma->vm_mm = mm;
97078 vma->vm_start = addr;
97079 vma->vm_end = addr + len;
97080 @@ -1593,6 +1746,13 @@ munmap_back:
97081 if (error)
97082 goto unmap_and_free_vma;
97083
97084 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97085 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97086 + vma->vm_flags |= VM_PAGEEXEC;
97087 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97088 + }
97089 +#endif
97090 +
97091 /* Can addr have changed??
97092 *
97093 * Answer: Yes, several device drivers can do it in their
97094 @@ -1626,6 +1786,12 @@ munmap_back:
97095 }
97096
97097 vma_link(mm, vma, prev, rb_link, rb_parent);
97098 +
97099 +#ifdef CONFIG_PAX_SEGMEXEC
97100 + if (vma_m)
97101 + BUG_ON(pax_mirror_vma(vma_m, vma));
97102 +#endif
97103 +
97104 /* Once vma denies write, undo our temporary denial count */
97105 if (file) {
97106 if (vm_flags & VM_SHARED)
97107 @@ -1638,6 +1804,7 @@ out:
97108 perf_event_mmap(vma);
97109
97110 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97111 + track_exec_limit(mm, addr, addr + len, vm_flags);
97112 if (vm_flags & VM_LOCKED) {
97113 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97114 vma == get_gate_vma(current->mm)))
97115 @@ -1673,6 +1840,12 @@ allow_write_and_free_vma:
97116 if (vm_flags & VM_DENYWRITE)
97117 allow_write_access(file);
97118 free_vma:
97119 +
97120 +#ifdef CONFIG_PAX_SEGMEXEC
97121 + if (vma_m)
97122 + kmem_cache_free(vm_area_cachep, vma_m);
97123 +#endif
97124 +
97125 kmem_cache_free(vm_area_cachep, vma);
97126 unacct_error:
97127 if (charged)
97128 @@ -1680,7 +1853,63 @@ unacct_error:
97129 return error;
97130 }
97131
97132 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97133 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97134 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97135 +{
97136 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97137 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97138 +
97139 + return 0;
97140 +}
97141 +#endif
97142 +
97143 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97144 +{
97145 + if (!vma) {
97146 +#ifdef CONFIG_STACK_GROWSUP
97147 + if (addr > sysctl_heap_stack_gap)
97148 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97149 + else
97150 + vma = find_vma(current->mm, 0);
97151 + if (vma && (vma->vm_flags & VM_GROWSUP))
97152 + return false;
97153 +#endif
97154 + return true;
97155 + }
97156 +
97157 + if (addr + len > vma->vm_start)
97158 + return false;
97159 +
97160 + if (vma->vm_flags & VM_GROWSDOWN)
97161 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97162 +#ifdef CONFIG_STACK_GROWSUP
97163 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97164 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97165 +#endif
97166 + else if (offset)
97167 + return offset <= vma->vm_start - addr - len;
97168 +
97169 + return true;
97170 +}
97171 +
97172 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97173 +{
97174 + if (vma->vm_start < len)
97175 + return -ENOMEM;
97176 +
97177 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97178 + if (offset <= vma->vm_start - len)
97179 + return vma->vm_start - len - offset;
97180 + else
97181 + return -ENOMEM;
97182 + }
97183 +
97184 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97185 + return vma->vm_start - len - sysctl_heap_stack_gap;
97186 + return -ENOMEM;
97187 +}
97188 +
97189 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97190 {
97191 /*
97192 * We implement the search by looking for an rbtree node that
97193 @@ -1728,11 +1957,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97194 }
97195 }
97196
97197 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97198 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97199 check_current:
97200 /* Check if current node has a suitable gap */
97201 if (gap_start > high_limit)
97202 return -ENOMEM;
97203 +
97204 + if (gap_end - gap_start > info->threadstack_offset)
97205 + gap_start += info->threadstack_offset;
97206 + else
97207 + gap_start = gap_end;
97208 +
97209 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97210 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97211 + gap_start += sysctl_heap_stack_gap;
97212 + else
97213 + gap_start = gap_end;
97214 + }
97215 + if (vma->vm_flags & VM_GROWSDOWN) {
97216 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97217 + gap_end -= sysctl_heap_stack_gap;
97218 + else
97219 + gap_end = gap_start;
97220 + }
97221 if (gap_end >= low_limit && gap_end - gap_start >= length)
97222 goto found;
97223
97224 @@ -1782,7 +2029,7 @@ found:
97225 return gap_start;
97226 }
97227
97228 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97229 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97230 {
97231 struct mm_struct *mm = current->mm;
97232 struct vm_area_struct *vma;
97233 @@ -1836,6 +2083,24 @@ check_current:
97234 gap_end = vma->vm_start;
97235 if (gap_end < low_limit)
97236 return -ENOMEM;
97237 +
97238 + if (gap_end - gap_start > info->threadstack_offset)
97239 + gap_end -= info->threadstack_offset;
97240 + else
97241 + gap_end = gap_start;
97242 +
97243 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97244 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97245 + gap_start += sysctl_heap_stack_gap;
97246 + else
97247 + gap_start = gap_end;
97248 + }
97249 + if (vma->vm_flags & VM_GROWSDOWN) {
97250 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97251 + gap_end -= sysctl_heap_stack_gap;
97252 + else
97253 + gap_end = gap_start;
97254 + }
97255 if (gap_start <= high_limit && gap_end - gap_start >= length)
97256 goto found;
97257
97258 @@ -1899,6 +2164,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97259 struct mm_struct *mm = current->mm;
97260 struct vm_area_struct *vma;
97261 struct vm_unmapped_area_info info;
97262 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97263
97264 if (len > TASK_SIZE - mmap_min_addr)
97265 return -ENOMEM;
97266 @@ -1906,11 +2172,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97267 if (flags & MAP_FIXED)
97268 return addr;
97269
97270 +#ifdef CONFIG_PAX_RANDMMAP
97271 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97272 +#endif
97273 +
97274 if (addr) {
97275 addr = PAGE_ALIGN(addr);
97276 vma = find_vma(mm, addr);
97277 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97278 - (!vma || addr + len <= vma->vm_start))
97279 + check_heap_stack_gap(vma, addr, len, offset))
97280 return addr;
97281 }
97282
97283 @@ -1919,6 +2189,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97284 info.low_limit = mm->mmap_base;
97285 info.high_limit = TASK_SIZE;
97286 info.align_mask = 0;
97287 + info.threadstack_offset = offset;
97288 return vm_unmapped_area(&info);
97289 }
97290 #endif
97291 @@ -1937,6 +2208,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97292 struct mm_struct *mm = current->mm;
97293 unsigned long addr = addr0;
97294 struct vm_unmapped_area_info info;
97295 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97296
97297 /* requested length too big for entire address space */
97298 if (len > TASK_SIZE - mmap_min_addr)
97299 @@ -1945,12 +2217,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97300 if (flags & MAP_FIXED)
97301 return addr;
97302
97303 +#ifdef CONFIG_PAX_RANDMMAP
97304 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97305 +#endif
97306 +
97307 /* requesting a specific address */
97308 if (addr) {
97309 addr = PAGE_ALIGN(addr);
97310 vma = find_vma(mm, addr);
97311 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97312 - (!vma || addr + len <= vma->vm_start))
97313 + check_heap_stack_gap(vma, addr, len, offset))
97314 return addr;
97315 }
97316
97317 @@ -1959,6 +2235,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97318 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97319 info.high_limit = mm->mmap_base;
97320 info.align_mask = 0;
97321 + info.threadstack_offset = offset;
97322 addr = vm_unmapped_area(&info);
97323
97324 /*
97325 @@ -1971,6 +2248,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97326 VM_BUG_ON(addr != -ENOMEM);
97327 info.flags = 0;
97328 info.low_limit = TASK_UNMAPPED_BASE;
97329 +
97330 +#ifdef CONFIG_PAX_RANDMMAP
97331 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97332 + info.low_limit += mm->delta_mmap;
97333 +#endif
97334 +
97335 info.high_limit = TASK_SIZE;
97336 addr = vm_unmapped_area(&info);
97337 }
97338 @@ -2071,6 +2354,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97339 return vma;
97340 }
97341
97342 +#ifdef CONFIG_PAX_SEGMEXEC
97343 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97344 +{
97345 + struct vm_area_struct *vma_m;
97346 +
97347 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97348 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97349 + BUG_ON(vma->vm_mirror);
97350 + return NULL;
97351 + }
97352 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97353 + vma_m = vma->vm_mirror;
97354 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97355 + BUG_ON(vma->vm_file != vma_m->vm_file);
97356 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97357 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97358 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97359 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97360 + return vma_m;
97361 +}
97362 +#endif
97363 +
97364 /*
97365 * Verify that the stack growth is acceptable and
97366 * update accounting. This is shared with both the
97367 @@ -2087,6 +2392,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97368 return -ENOMEM;
97369
97370 /* Stack limit test */
97371 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
97372 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97373 return -ENOMEM;
97374
97375 @@ -2097,6 +2403,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97376 locked = mm->locked_vm + grow;
97377 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97378 limit >>= PAGE_SHIFT;
97379 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97380 if (locked > limit && !capable(CAP_IPC_LOCK))
97381 return -ENOMEM;
97382 }
97383 @@ -2126,37 +2433,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97384 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97385 * vma is the last one with address > vma->vm_end. Have to extend vma.
97386 */
97387 +#ifndef CONFIG_IA64
97388 +static
97389 +#endif
97390 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97391 {
97392 int error;
97393 + bool locknext;
97394
97395 if (!(vma->vm_flags & VM_GROWSUP))
97396 return -EFAULT;
97397
97398 + /* Also guard against wrapping around to address 0. */
97399 + if (address < PAGE_ALIGN(address+1))
97400 + address = PAGE_ALIGN(address+1);
97401 + else
97402 + return -ENOMEM;
97403 +
97404 /*
97405 * We must make sure the anon_vma is allocated
97406 * so that the anon_vma locking is not a noop.
97407 */
97408 if (unlikely(anon_vma_prepare(vma)))
97409 return -ENOMEM;
97410 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97411 + if (locknext && anon_vma_prepare(vma->vm_next))
97412 + return -ENOMEM;
97413 vma_lock_anon_vma(vma);
97414 + if (locknext)
97415 + vma_lock_anon_vma(vma->vm_next);
97416
97417 /*
97418 * vma->vm_start/vm_end cannot change under us because the caller
97419 * is required to hold the mmap_sem in read mode. We need the
97420 - * anon_vma lock to serialize against concurrent expand_stacks.
97421 - * Also guard against wrapping around to address 0.
97422 + * anon_vma locks to serialize against concurrent expand_stacks
97423 + * and expand_upwards.
97424 */
97425 - if (address < PAGE_ALIGN(address+4))
97426 - address = PAGE_ALIGN(address+4);
97427 - else {
97428 - vma_unlock_anon_vma(vma);
97429 - return -ENOMEM;
97430 - }
97431 error = 0;
97432
97433 /* Somebody else might have raced and expanded it already */
97434 - if (address > vma->vm_end) {
97435 + 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)
97436 + error = -ENOMEM;
97437 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97438 unsigned long size, grow;
97439
97440 size = address - vma->vm_start;
97441 @@ -2191,6 +2509,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97442 }
97443 }
97444 }
97445 + if (locknext)
97446 + vma_unlock_anon_vma(vma->vm_next);
97447 vma_unlock_anon_vma(vma);
97448 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97449 validate_mm(vma->vm_mm);
97450 @@ -2205,6 +2525,8 @@ int expand_downwards(struct vm_area_struct *vma,
97451 unsigned long address)
97452 {
97453 int error;
97454 + bool lockprev = false;
97455 + struct vm_area_struct *prev;
97456
97457 /*
97458 * We must make sure the anon_vma is allocated
97459 @@ -2218,6 +2540,15 @@ int expand_downwards(struct vm_area_struct *vma,
97460 if (error)
97461 return error;
97462
97463 + prev = vma->vm_prev;
97464 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97465 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97466 +#endif
97467 + if (lockprev && anon_vma_prepare(prev))
97468 + return -ENOMEM;
97469 + if (lockprev)
97470 + vma_lock_anon_vma(prev);
97471 +
97472 vma_lock_anon_vma(vma);
97473
97474 /*
97475 @@ -2227,9 +2558,17 @@ int expand_downwards(struct vm_area_struct *vma,
97476 */
97477
97478 /* Somebody else might have raced and expanded it already */
97479 - if (address < vma->vm_start) {
97480 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97481 + error = -ENOMEM;
97482 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97483 unsigned long size, grow;
97484
97485 +#ifdef CONFIG_PAX_SEGMEXEC
97486 + struct vm_area_struct *vma_m;
97487 +
97488 + vma_m = pax_find_mirror_vma(vma);
97489 +#endif
97490 +
97491 size = vma->vm_end - address;
97492 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97493
97494 @@ -2254,13 +2593,27 @@ int expand_downwards(struct vm_area_struct *vma,
97495 vma->vm_pgoff -= grow;
97496 anon_vma_interval_tree_post_update_vma(vma);
97497 vma_gap_update(vma);
97498 +
97499 +#ifdef CONFIG_PAX_SEGMEXEC
97500 + if (vma_m) {
97501 + anon_vma_interval_tree_pre_update_vma(vma_m);
97502 + vma_m->vm_start -= grow << PAGE_SHIFT;
97503 + vma_m->vm_pgoff -= grow;
97504 + anon_vma_interval_tree_post_update_vma(vma_m);
97505 + vma_gap_update(vma_m);
97506 + }
97507 +#endif
97508 +
97509 spin_unlock(&vma->vm_mm->page_table_lock);
97510
97511 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97512 perf_event_mmap(vma);
97513 }
97514 }
97515 }
97516 vma_unlock_anon_vma(vma);
97517 + if (lockprev)
97518 + vma_unlock_anon_vma(prev);
97519 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97520 validate_mm(vma->vm_mm);
97521 return error;
97522 @@ -2358,6 +2711,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97523 do {
97524 long nrpages = vma_pages(vma);
97525
97526 +#ifdef CONFIG_PAX_SEGMEXEC
97527 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97528 + vma = remove_vma(vma);
97529 + continue;
97530 + }
97531 +#endif
97532 +
97533 if (vma->vm_flags & VM_ACCOUNT)
97534 nr_accounted += nrpages;
97535 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97536 @@ -2402,6 +2762,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97537 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97538 vma->vm_prev = NULL;
97539 do {
97540 +
97541 +#ifdef CONFIG_PAX_SEGMEXEC
97542 + if (vma->vm_mirror) {
97543 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97544 + vma->vm_mirror->vm_mirror = NULL;
97545 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97546 + vma->vm_mirror = NULL;
97547 + }
97548 +#endif
97549 +
97550 vma_rb_erase(vma, &mm->mm_rb);
97551 mm->map_count--;
97552 tail_vma = vma;
97553 @@ -2429,14 +2799,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97554 struct vm_area_struct *new;
97555 int err = -ENOMEM;
97556
97557 +#ifdef CONFIG_PAX_SEGMEXEC
97558 + struct vm_area_struct *vma_m, *new_m = NULL;
97559 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97560 +#endif
97561 +
97562 if (is_vm_hugetlb_page(vma) && (addr &
97563 ~(huge_page_mask(hstate_vma(vma)))))
97564 return -EINVAL;
97565
97566 +#ifdef CONFIG_PAX_SEGMEXEC
97567 + vma_m = pax_find_mirror_vma(vma);
97568 +#endif
97569 +
97570 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97571 if (!new)
97572 goto out_err;
97573
97574 +#ifdef CONFIG_PAX_SEGMEXEC
97575 + if (vma_m) {
97576 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97577 + if (!new_m) {
97578 + kmem_cache_free(vm_area_cachep, new);
97579 + goto out_err;
97580 + }
97581 + }
97582 +#endif
97583 +
97584 /* most fields are the same, copy all, and then fixup */
97585 *new = *vma;
97586
97587 @@ -2449,6 +2838,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97588 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97589 }
97590
97591 +#ifdef CONFIG_PAX_SEGMEXEC
97592 + if (vma_m) {
97593 + *new_m = *vma_m;
97594 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97595 + new_m->vm_mirror = new;
97596 + new->vm_mirror = new_m;
97597 +
97598 + if (new_below)
97599 + new_m->vm_end = addr_m;
97600 + else {
97601 + new_m->vm_start = addr_m;
97602 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97603 + }
97604 + }
97605 +#endif
97606 +
97607 err = vma_dup_policy(vma, new);
97608 if (err)
97609 goto out_free_vma;
97610 @@ -2468,6 +2873,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97611 else
97612 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97613
97614 +#ifdef CONFIG_PAX_SEGMEXEC
97615 + if (!err && vma_m) {
97616 + struct mempolicy *pol = vma_policy(new);
97617 +
97618 + if (anon_vma_clone(new_m, vma_m))
97619 + goto out_free_mpol;
97620 +
97621 + mpol_get(pol);
97622 + set_vma_policy(new_m, pol);
97623 +
97624 + if (new_m->vm_file)
97625 + get_file(new_m->vm_file);
97626 +
97627 + if (new_m->vm_ops && new_m->vm_ops->open)
97628 + new_m->vm_ops->open(new_m);
97629 +
97630 + if (new_below)
97631 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97632 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97633 + else
97634 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97635 +
97636 + if (err) {
97637 + if (new_m->vm_ops && new_m->vm_ops->close)
97638 + new_m->vm_ops->close(new_m);
97639 + if (new_m->vm_file)
97640 + fput(new_m->vm_file);
97641 + mpol_put(pol);
97642 + }
97643 + }
97644 +#endif
97645 +
97646 /* Success. */
97647 if (!err)
97648 return 0;
97649 @@ -2477,10 +2914,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97650 new->vm_ops->close(new);
97651 if (new->vm_file)
97652 fput(new->vm_file);
97653 - unlink_anon_vmas(new);
97654 out_free_mpol:
97655 mpol_put(vma_policy(new));
97656 out_free_vma:
97657 +
97658 +#ifdef CONFIG_PAX_SEGMEXEC
97659 + if (new_m) {
97660 + unlink_anon_vmas(new_m);
97661 + kmem_cache_free(vm_area_cachep, new_m);
97662 + }
97663 +#endif
97664 +
97665 + unlink_anon_vmas(new);
97666 kmem_cache_free(vm_area_cachep, new);
97667 out_err:
97668 return err;
97669 @@ -2493,6 +2938,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97670 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97671 unsigned long addr, int new_below)
97672 {
97673 +
97674 +#ifdef CONFIG_PAX_SEGMEXEC
97675 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97676 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97677 + if (mm->map_count >= sysctl_max_map_count-1)
97678 + return -ENOMEM;
97679 + } else
97680 +#endif
97681 +
97682 if (mm->map_count >= sysctl_max_map_count)
97683 return -ENOMEM;
97684
97685 @@ -2504,11 +2958,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97686 * work. This now handles partial unmappings.
97687 * Jeremy Fitzhardinge <jeremy@goop.org>
97688 */
97689 +#ifdef CONFIG_PAX_SEGMEXEC
97690 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97691 {
97692 + int ret = __do_munmap(mm, start, len);
97693 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97694 + return ret;
97695 +
97696 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97697 +}
97698 +
97699 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97700 +#else
97701 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97702 +#endif
97703 +{
97704 unsigned long end;
97705 struct vm_area_struct *vma, *prev, *last;
97706
97707 + /*
97708 + * mm->mmap_sem is required to protect against another thread
97709 + * changing the mappings in case we sleep.
97710 + */
97711 + verify_mm_writelocked(mm);
97712 +
97713 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97714 return -EINVAL;
97715
97716 @@ -2583,6 +3056,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97717 /* Fix up all other VM information */
97718 remove_vma_list(mm, vma);
97719
97720 + track_exec_limit(mm, start, end, 0UL);
97721 +
97722 return 0;
97723 }
97724
97725 @@ -2591,6 +3066,13 @@ int vm_munmap(unsigned long start, size_t len)
97726 int ret;
97727 struct mm_struct *mm = current->mm;
97728
97729 +
97730 +#ifdef CONFIG_PAX_SEGMEXEC
97731 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97732 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97733 + return -EINVAL;
97734 +#endif
97735 +
97736 down_write(&mm->mmap_sem);
97737 ret = do_munmap(mm, start, len);
97738 up_write(&mm->mmap_sem);
97739 @@ -2604,16 +3086,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97740 return vm_munmap(addr, len);
97741 }
97742
97743 -static inline void verify_mm_writelocked(struct mm_struct *mm)
97744 -{
97745 -#ifdef CONFIG_DEBUG_VM
97746 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97747 - WARN_ON(1);
97748 - up_read(&mm->mmap_sem);
97749 - }
97750 -#endif
97751 -}
97752 -
97753 /*
97754 * this is really a simplified "do_mmap". it only handles
97755 * anonymous maps. eventually we may be able to do some
97756 @@ -2627,6 +3099,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97757 struct rb_node ** rb_link, * rb_parent;
97758 pgoff_t pgoff = addr >> PAGE_SHIFT;
97759 int error;
97760 + unsigned long charged;
97761
97762 len = PAGE_ALIGN(len);
97763 if (!len)
97764 @@ -2634,10 +3107,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97765
97766 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97767
97768 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97769 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97770 + flags &= ~VM_EXEC;
97771 +
97772 +#ifdef CONFIG_PAX_MPROTECT
97773 + if (mm->pax_flags & MF_PAX_MPROTECT)
97774 + flags &= ~VM_MAYEXEC;
97775 +#endif
97776 +
97777 + }
97778 +#endif
97779 +
97780 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97781 if (error & ~PAGE_MASK)
97782 return error;
97783
97784 + charged = len >> PAGE_SHIFT;
97785 +
97786 error = mlock_future_check(mm, mm->def_flags, len);
97787 if (error)
97788 return error;
97789 @@ -2651,21 +3138,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97790 /*
97791 * Clear old maps. this also does some error checking for us
97792 */
97793 - munmap_back:
97794 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97795 if (do_munmap(mm, addr, len))
97796 return -ENOMEM;
97797 - goto munmap_back;
97798 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97799 }
97800
97801 /* Check against address space limits *after* clearing old maps... */
97802 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97803 + if (!may_expand_vm(mm, charged))
97804 return -ENOMEM;
97805
97806 if (mm->map_count > sysctl_max_map_count)
97807 return -ENOMEM;
97808
97809 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97810 + if (security_vm_enough_memory_mm(mm, charged))
97811 return -ENOMEM;
97812
97813 /* Can we just expand an old private anonymous mapping? */
97814 @@ -2679,7 +3165,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97815 */
97816 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97817 if (!vma) {
97818 - vm_unacct_memory(len >> PAGE_SHIFT);
97819 + vm_unacct_memory(charged);
97820 return -ENOMEM;
97821 }
97822
97823 @@ -2693,10 +3179,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97824 vma_link(mm, vma, prev, rb_link, rb_parent);
97825 out:
97826 perf_event_mmap(vma);
97827 - mm->total_vm += len >> PAGE_SHIFT;
97828 + mm->total_vm += charged;
97829 if (flags & VM_LOCKED)
97830 - mm->locked_vm += (len >> PAGE_SHIFT);
97831 + mm->locked_vm += charged;
97832 vma->vm_flags |= VM_SOFTDIRTY;
97833 + track_exec_limit(mm, addr, addr + len, flags);
97834 return addr;
97835 }
97836
97837 @@ -2758,6 +3245,7 @@ void exit_mmap(struct mm_struct *mm)
97838 while (vma) {
97839 if (vma->vm_flags & VM_ACCOUNT)
97840 nr_accounted += vma_pages(vma);
97841 + vma->vm_mirror = NULL;
97842 vma = remove_vma(vma);
97843 }
97844 vm_unacct_memory(nr_accounted);
97845 @@ -2775,6 +3263,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97846 struct vm_area_struct *prev;
97847 struct rb_node **rb_link, *rb_parent;
97848
97849 +#ifdef CONFIG_PAX_SEGMEXEC
97850 + struct vm_area_struct *vma_m = NULL;
97851 +#endif
97852 +
97853 + if (security_mmap_addr(vma->vm_start))
97854 + return -EPERM;
97855 +
97856 /*
97857 * The vm_pgoff of a purely anonymous vma should be irrelevant
97858 * until its first write fault, when page's anon_vma and index
97859 @@ -2798,7 +3293,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97860 security_vm_enough_memory_mm(mm, vma_pages(vma)))
97861 return -ENOMEM;
97862
97863 +#ifdef CONFIG_PAX_SEGMEXEC
97864 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
97865 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97866 + if (!vma_m)
97867 + return -ENOMEM;
97868 + }
97869 +#endif
97870 +
97871 vma_link(mm, vma, prev, rb_link, rb_parent);
97872 +
97873 +#ifdef CONFIG_PAX_SEGMEXEC
97874 + if (vma_m)
97875 + BUG_ON(pax_mirror_vma(vma_m, vma));
97876 +#endif
97877 +
97878 return 0;
97879 }
97880
97881 @@ -2817,6 +3326,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97882 struct rb_node **rb_link, *rb_parent;
97883 bool faulted_in_anon_vma = true;
97884
97885 + BUG_ON(vma->vm_mirror);
97886 +
97887 /*
97888 * If anonymous vma has not yet been faulted, update new pgoff
97889 * to match new location, to increase its chance of merging.
97890 @@ -2881,6 +3392,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97891 return NULL;
97892 }
97893
97894 +#ifdef CONFIG_PAX_SEGMEXEC
97895 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
97896 +{
97897 + struct vm_area_struct *prev_m;
97898 + struct rb_node **rb_link_m, *rb_parent_m;
97899 + struct mempolicy *pol_m;
97900 +
97901 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
97902 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
97903 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
97904 + *vma_m = *vma;
97905 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
97906 + if (anon_vma_clone(vma_m, vma))
97907 + return -ENOMEM;
97908 + pol_m = vma_policy(vma_m);
97909 + mpol_get(pol_m);
97910 + set_vma_policy(vma_m, pol_m);
97911 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
97912 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
97913 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
97914 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
97915 + if (vma_m->vm_file)
97916 + get_file(vma_m->vm_file);
97917 + if (vma_m->vm_ops && vma_m->vm_ops->open)
97918 + vma_m->vm_ops->open(vma_m);
97919 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
97920 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
97921 + vma_m->vm_mirror = vma;
97922 + vma->vm_mirror = vma_m;
97923 + return 0;
97924 +}
97925 +#endif
97926 +
97927 /*
97928 * Return true if the calling process may expand its vm space by the passed
97929 * number of pages
97930 @@ -2892,6 +3436,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
97931
97932 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
97933
97934 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
97935 if (cur + npages > lim)
97936 return 0;
97937 return 1;
97938 @@ -2974,6 +3519,22 @@ static struct vm_area_struct *__install_special_mapping(
97939 vma->vm_start = addr;
97940 vma->vm_end = addr + len;
97941
97942 +#ifdef CONFIG_PAX_MPROTECT
97943 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97944 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97945 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
97946 + return ERR_PTR(-EPERM);
97947 + if (!(vm_flags & VM_EXEC))
97948 + vm_flags &= ~VM_MAYEXEC;
97949 +#else
97950 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97951 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97952 +#endif
97953 + else
97954 + vm_flags &= ~VM_MAYWRITE;
97955 + }
97956 +#endif
97957 +
97958 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
97959 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97960
97961 diff --git a/mm/mprotect.c b/mm/mprotect.c
97962 index c43d557..0b7ccd2 100644
97963 --- a/mm/mprotect.c
97964 +++ b/mm/mprotect.c
97965 @@ -24,10 +24,18 @@
97966 #include <linux/migrate.h>
97967 #include <linux/perf_event.h>
97968 #include <linux/ksm.h>
97969 +#include <linux/sched/sysctl.h>
97970 +
97971 +#ifdef CONFIG_PAX_MPROTECT
97972 +#include <linux/elf.h>
97973 +#include <linux/binfmts.h>
97974 +#endif
97975 +
97976 #include <asm/uaccess.h>
97977 #include <asm/pgtable.h>
97978 #include <asm/cacheflush.h>
97979 #include <asm/tlbflush.h>
97980 +#include <asm/mmu_context.h>
97981
97982 #ifndef pgprot_modify
97983 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
97984 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
97985 return pages;
97986 }
97987
97988 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97989 +/* called while holding the mmap semaphor for writing except stack expansion */
97990 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
97991 +{
97992 + unsigned long oldlimit, newlimit = 0UL;
97993 +
97994 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
97995 + return;
97996 +
97997 + spin_lock(&mm->page_table_lock);
97998 + oldlimit = mm->context.user_cs_limit;
97999 + if ((prot & VM_EXEC) && oldlimit < end)
98000 + /* USER_CS limit moved up */
98001 + newlimit = end;
98002 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98003 + /* USER_CS limit moved down */
98004 + newlimit = start;
98005 +
98006 + if (newlimit) {
98007 + mm->context.user_cs_limit = newlimit;
98008 +
98009 +#ifdef CONFIG_SMP
98010 + wmb();
98011 + cpus_clear(mm->context.cpu_user_cs_mask);
98012 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98013 +#endif
98014 +
98015 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98016 + }
98017 + spin_unlock(&mm->page_table_lock);
98018 + if (newlimit == end) {
98019 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98020 +
98021 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98022 + if (is_vm_hugetlb_page(vma))
98023 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98024 + else
98025 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98026 + }
98027 +}
98028 +#endif
98029 +
98030 int
98031 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98032 unsigned long start, unsigned long end, unsigned long newflags)
98033 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98034 int error;
98035 int dirty_accountable = 0;
98036
98037 +#ifdef CONFIG_PAX_SEGMEXEC
98038 + struct vm_area_struct *vma_m = NULL;
98039 + unsigned long start_m, end_m;
98040 +
98041 + start_m = start + SEGMEXEC_TASK_SIZE;
98042 + end_m = end + SEGMEXEC_TASK_SIZE;
98043 +#endif
98044 +
98045 if (newflags == oldflags) {
98046 *pprev = vma;
98047 return 0;
98048 }
98049
98050 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98051 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98052 +
98053 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98054 + return -ENOMEM;
98055 +
98056 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98057 + return -ENOMEM;
98058 + }
98059 +
98060 /*
98061 * If we make a private mapping writable we increase our commit;
98062 * but (without finer accounting) cannot reduce our commit if we
98063 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98064 }
98065 }
98066
98067 +#ifdef CONFIG_PAX_SEGMEXEC
98068 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98069 + if (start != vma->vm_start) {
98070 + error = split_vma(mm, vma, start, 1);
98071 + if (error)
98072 + goto fail;
98073 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98074 + *pprev = (*pprev)->vm_next;
98075 + }
98076 +
98077 + if (end != vma->vm_end) {
98078 + error = split_vma(mm, vma, end, 0);
98079 + if (error)
98080 + goto fail;
98081 + }
98082 +
98083 + if (pax_find_mirror_vma(vma)) {
98084 + error = __do_munmap(mm, start_m, end_m - start_m);
98085 + if (error)
98086 + goto fail;
98087 + } else {
98088 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98089 + if (!vma_m) {
98090 + error = -ENOMEM;
98091 + goto fail;
98092 + }
98093 + vma->vm_flags = newflags;
98094 + error = pax_mirror_vma(vma_m, vma);
98095 + if (error) {
98096 + vma->vm_flags = oldflags;
98097 + goto fail;
98098 + }
98099 + }
98100 + }
98101 +#endif
98102 +
98103 /*
98104 * First try to merge with previous and/or next vma.
98105 */
98106 @@ -319,9 +423,21 @@ success:
98107 * vm_flags and vm_page_prot are protected by the mmap_sem
98108 * held in write mode.
98109 */
98110 +
98111 +#ifdef CONFIG_PAX_SEGMEXEC
98112 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98113 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98114 +#endif
98115 +
98116 vma->vm_flags = newflags;
98117 +
98118 +#ifdef CONFIG_PAX_MPROTECT
98119 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98120 + mm->binfmt->handle_mprotect(vma, newflags);
98121 +#endif
98122 +
98123 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
98124 - vm_get_page_prot(newflags));
98125 + vm_get_page_prot(vma->vm_flags));
98126
98127 if (vma_wants_writenotify(vma)) {
98128 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
98129 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98130 end = start + len;
98131 if (end <= start)
98132 return -ENOMEM;
98133 +
98134 +#ifdef CONFIG_PAX_SEGMEXEC
98135 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98136 + if (end > SEGMEXEC_TASK_SIZE)
98137 + return -EINVAL;
98138 + } else
98139 +#endif
98140 +
98141 + if (end > TASK_SIZE)
98142 + return -EINVAL;
98143 +
98144 if (!arch_validate_prot(prot))
98145 return -EINVAL;
98146
98147 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98148 /*
98149 * Does the application expect PROT_READ to imply PROT_EXEC:
98150 */
98151 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98152 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98153 prot |= PROT_EXEC;
98154
98155 vm_flags = calc_vm_prot_bits(prot);
98156 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98157 if (start > vma->vm_start)
98158 prev = vma;
98159
98160 +#ifdef CONFIG_PAX_MPROTECT
98161 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98162 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98163 +#endif
98164 +
98165 for (nstart = start ; ; ) {
98166 unsigned long newflags;
98167
98168 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98169
98170 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98171 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98172 + if (prot & (PROT_WRITE | PROT_EXEC))
98173 + gr_log_rwxmprotect(vma);
98174 +
98175 + error = -EACCES;
98176 + goto out;
98177 + }
98178 +
98179 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98180 error = -EACCES;
98181 goto out;
98182 }
98183 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98184 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98185 if (error)
98186 goto out;
98187 +
98188 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98189 +
98190 nstart = tmp;
98191
98192 if (nstart < prev->vm_end)
98193 diff --git a/mm/mremap.c b/mm/mremap.c
98194 index 05f1180..c3cde48 100644
98195 --- a/mm/mremap.c
98196 +++ b/mm/mremap.c
98197 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98198 continue;
98199 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98200 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98201 +
98202 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98203 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98204 + pte = pte_exprotect(pte);
98205 +#endif
98206 +
98207 pte = move_soft_dirty_pte(pte);
98208 set_pte_at(mm, new_addr, new_pte, pte);
98209 }
98210 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98211 if (is_vm_hugetlb_page(vma))
98212 goto Einval;
98213
98214 +#ifdef CONFIG_PAX_SEGMEXEC
98215 + if (pax_find_mirror_vma(vma))
98216 + goto Einval;
98217 +#endif
98218 +
98219 /* We can't remap across vm area boundaries */
98220 if (old_len > vma->vm_end - addr)
98221 goto Efault;
98222 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98223 unsigned long ret = -EINVAL;
98224 unsigned long charged = 0;
98225 unsigned long map_flags;
98226 + unsigned long pax_task_size = TASK_SIZE;
98227
98228 if (new_addr & ~PAGE_MASK)
98229 goto out;
98230
98231 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98232 +#ifdef CONFIG_PAX_SEGMEXEC
98233 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98234 + pax_task_size = SEGMEXEC_TASK_SIZE;
98235 +#endif
98236 +
98237 + pax_task_size -= PAGE_SIZE;
98238 +
98239 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98240 goto out;
98241
98242 /* Check if the location we're moving into overlaps the
98243 * old location at all, and fail if it does.
98244 */
98245 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98246 - goto out;
98247 -
98248 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98249 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98250 goto out;
98251
98252 ret = do_munmap(mm, new_addr, new_len);
98253 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98254 unsigned long ret = -EINVAL;
98255 unsigned long charged = 0;
98256 bool locked = false;
98257 + unsigned long pax_task_size = TASK_SIZE;
98258
98259 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98260 return ret;
98261 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98262 if (!new_len)
98263 return ret;
98264
98265 +#ifdef CONFIG_PAX_SEGMEXEC
98266 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98267 + pax_task_size = SEGMEXEC_TASK_SIZE;
98268 +#endif
98269 +
98270 + pax_task_size -= PAGE_SIZE;
98271 +
98272 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98273 + old_len > pax_task_size || addr > pax_task_size-old_len)
98274 + return ret;
98275 +
98276 down_write(&current->mm->mmap_sem);
98277
98278 if (flags & MREMAP_FIXED) {
98279 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98280 new_addr = addr;
98281 }
98282 ret = addr;
98283 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98284 goto out;
98285 }
98286 }
98287 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98288 goto out;
98289 }
98290
98291 + map_flags = vma->vm_flags;
98292 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98293 + if (!(ret & ~PAGE_MASK)) {
98294 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98295 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98296 + }
98297 }
98298 out:
98299 if (ret & ~PAGE_MASK)
98300 diff --git a/mm/nommu.c b/mm/nommu.c
98301 index a881d96..e5932cd 100644
98302 --- a/mm/nommu.c
98303 +++ b/mm/nommu.c
98304 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98305 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98306 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98307 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98308 -int heap_stack_gap = 0;
98309
98310 atomic_long_t mmap_pages_allocated;
98311
98312 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98313 EXPORT_SYMBOL(find_vma);
98314
98315 /*
98316 - * find a VMA
98317 - * - we don't extend stack VMAs under NOMMU conditions
98318 - */
98319 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98320 -{
98321 - return find_vma(mm, addr);
98322 -}
98323 -
98324 -/*
98325 * expand a stack to a given address
98326 * - not supported under NOMMU conditions
98327 */
98328 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98329
98330 /* most fields are the same, copy all, and then fixup */
98331 *new = *vma;
98332 + INIT_LIST_HEAD(&new->anon_vma_chain);
98333 *region = *vma->vm_region;
98334 new->vm_region = region;
98335
98336 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98337 }
98338 EXPORT_SYMBOL(generic_file_remap_pages);
98339
98340 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98341 - unsigned long addr, void *buf, int len, int write)
98342 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98343 + unsigned long addr, void *buf, size_t len, int write)
98344 {
98345 struct vm_area_struct *vma;
98346
98347 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98348 *
98349 * The caller must hold a reference on @mm.
98350 */
98351 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98352 - void *buf, int len, int write)
98353 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98354 + void *buf, size_t len, int write)
98355 {
98356 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98357 }
98358 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98359 * Access another process' address space.
98360 * - source/target buffer must be kernel space
98361 */
98362 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98363 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98364 {
98365 struct mm_struct *mm;
98366
98367 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98368 index ba5fd97..5a95869 100644
98369 --- a/mm/page-writeback.c
98370 +++ b/mm/page-writeback.c
98371 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98372 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98373 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98374 */
98375 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98376 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98377 unsigned long thresh,
98378 unsigned long bg_thresh,
98379 unsigned long dirty,
98380 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98381 index c5fe124..2cf7f17 100644
98382 --- a/mm/page_alloc.c
98383 +++ b/mm/page_alloc.c
98384 @@ -61,6 +61,7 @@
98385 #include <linux/page-debug-flags.h>
98386 #include <linux/hugetlb.h>
98387 #include <linux/sched/rt.h>
98388 +#include <linux/random.h>
98389
98390 #include <asm/sections.h>
98391 #include <asm/tlbflush.h>
98392 @@ -357,7 +358,7 @@ out:
98393 * This usage means that zero-order pages may not be compound.
98394 */
98395
98396 -static void free_compound_page(struct page *page)
98397 +void free_compound_page(struct page *page)
98398 {
98399 __free_pages_ok(page, compound_order(page));
98400 }
98401 @@ -740,6 +741,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98402 int i;
98403 int bad = 0;
98404
98405 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98406 + unsigned long index = 1UL << order;
98407 +#endif
98408 +
98409 trace_mm_page_free(page, order);
98410 kmemcheck_free_shadow(page, order);
98411
98412 @@ -756,6 +761,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98413 debug_check_no_obj_freed(page_address(page),
98414 PAGE_SIZE << order);
98415 }
98416 +
98417 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98418 + for (; index; --index)
98419 + sanitize_highpage(page + index - 1);
98420 +#endif
98421 +
98422 arch_free_page(page, order);
98423 kernel_map_pages(page, 1 << order, 0);
98424
98425 @@ -779,6 +790,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98426 local_irq_restore(flags);
98427 }
98428
98429 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98430 +bool __meminitdata extra_latent_entropy;
98431 +
98432 +static int __init setup_pax_extra_latent_entropy(char *str)
98433 +{
98434 + extra_latent_entropy = true;
98435 + return 0;
98436 +}
98437 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98438 +
98439 +volatile u64 latent_entropy __latent_entropy;
98440 +EXPORT_SYMBOL(latent_entropy);
98441 +#endif
98442 +
98443 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98444 {
98445 unsigned int nr_pages = 1 << order;
98446 @@ -794,6 +819,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98447 __ClearPageReserved(p);
98448 set_page_count(p, 0);
98449
98450 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98451 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98452 + u64 hash = 0;
98453 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98454 + const u64 *data = lowmem_page_address(page);
98455 +
98456 + for (index = 0; index < end; index++)
98457 + hash ^= hash + data[index];
98458 + latent_entropy ^= hash;
98459 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98460 + }
98461 +#endif
98462 +
98463 page_zone(page)->managed_pages += nr_pages;
98464 set_page_refcounted(page);
98465 __free_pages(page, order);
98466 @@ -922,8 +960,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98467 arch_alloc_page(page, order);
98468 kernel_map_pages(page, 1 << order, 1);
98469
98470 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98471 if (gfp_flags & __GFP_ZERO)
98472 prep_zero_page(page, order, gfp_flags);
98473 +#endif
98474
98475 if (order && (gfp_flags & __GFP_COMP))
98476 prep_compound_page(page, order);
98477 @@ -1601,7 +1641,7 @@ again:
98478 }
98479
98480 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98481 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98482 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98483 !zone_is_fair_depleted(zone))
98484 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
98485
98486 @@ -1922,7 +1962,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98487 do {
98488 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98489 high_wmark_pages(zone) - low_wmark_pages(zone) -
98490 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98491 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98492 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
98493 } while (zone++ != preferred_zone);
98494 }
98495 @@ -5699,7 +5739,7 @@ static void __setup_per_zone_wmarks(void)
98496
98497 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98498 high_wmark_pages(zone) - low_wmark_pages(zone) -
98499 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98500 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98501
98502 setup_zone_migrate_reserve(zone);
98503 spin_unlock_irqrestore(&zone->lock, flags);
98504 diff --git a/mm/percpu.c b/mm/percpu.c
98505 index 2139e30..1d45bce 100644
98506 --- a/mm/percpu.c
98507 +++ b/mm/percpu.c
98508 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98509 static unsigned int pcpu_high_unit_cpu __read_mostly;
98510
98511 /* the address of the first chunk which starts with the kernel static area */
98512 -void *pcpu_base_addr __read_mostly;
98513 +void *pcpu_base_addr __read_only;
98514 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98515
98516 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98517 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98518 index 5077afc..846c9ef 100644
98519 --- a/mm/process_vm_access.c
98520 +++ b/mm/process_vm_access.c
98521 @@ -13,6 +13,7 @@
98522 #include <linux/uio.h>
98523 #include <linux/sched.h>
98524 #include <linux/highmem.h>
98525 +#include <linux/security.h>
98526 #include <linux/ptrace.h>
98527 #include <linux/slab.h>
98528 #include <linux/syscalls.h>
98529 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98530 ssize_t iov_len;
98531 size_t total_len = iov_iter_count(iter);
98532
98533 + return -ENOSYS; // PaX: until properly audited
98534 +
98535 /*
98536 * Work out how many pages of struct pages we're going to need
98537 * when eventually calling get_user_pages
98538 */
98539 for (i = 0; i < riovcnt; i++) {
98540 iov_len = rvec[i].iov_len;
98541 - if (iov_len > 0) {
98542 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98543 - + iov_len)
98544 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98545 - / PAGE_SIZE + 1;
98546 - nr_pages = max(nr_pages, nr_pages_iov);
98547 - }
98548 + if (iov_len <= 0)
98549 + continue;
98550 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98551 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98552 + nr_pages = max(nr_pages, nr_pages_iov);
98553 }
98554
98555 if (nr_pages == 0)
98556 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98557 goto free_proc_pages;
98558 }
98559
98560 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98561 + rc = -EPERM;
98562 + goto put_task_struct;
98563 + }
98564 +
98565 mm = mm_access(task, PTRACE_MODE_ATTACH);
98566 if (!mm || IS_ERR(mm)) {
98567 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98568 diff --git a/mm/rmap.c b/mm/rmap.c
98569 index e01318d..25117ca 100644
98570 --- a/mm/rmap.c
98571 +++ b/mm/rmap.c
98572 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98573 struct anon_vma *anon_vma = vma->anon_vma;
98574 struct anon_vma_chain *avc;
98575
98576 +#ifdef CONFIG_PAX_SEGMEXEC
98577 + struct anon_vma_chain *avc_m = NULL;
98578 +#endif
98579 +
98580 might_sleep();
98581 if (unlikely(!anon_vma)) {
98582 struct mm_struct *mm = vma->vm_mm;
98583 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98584 if (!avc)
98585 goto out_enomem;
98586
98587 +#ifdef CONFIG_PAX_SEGMEXEC
98588 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98589 + if (!avc_m)
98590 + goto out_enomem_free_avc;
98591 +#endif
98592 +
98593 anon_vma = find_mergeable_anon_vma(vma);
98594 allocated = NULL;
98595 if (!anon_vma) {
98596 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98597 /* page_table_lock to protect against threads */
98598 spin_lock(&mm->page_table_lock);
98599 if (likely(!vma->anon_vma)) {
98600 +
98601 +#ifdef CONFIG_PAX_SEGMEXEC
98602 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98603 +
98604 + if (vma_m) {
98605 + BUG_ON(vma_m->anon_vma);
98606 + vma_m->anon_vma = anon_vma;
98607 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98608 + avc_m = NULL;
98609 + }
98610 +#endif
98611 +
98612 vma->anon_vma = anon_vma;
98613 anon_vma_chain_link(vma, avc, anon_vma);
98614 allocated = NULL;
98615 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98616
98617 if (unlikely(allocated))
98618 put_anon_vma(allocated);
98619 +
98620 +#ifdef CONFIG_PAX_SEGMEXEC
98621 + if (unlikely(avc_m))
98622 + anon_vma_chain_free(avc_m);
98623 +#endif
98624 +
98625 if (unlikely(avc))
98626 anon_vma_chain_free(avc);
98627 }
98628 return 0;
98629
98630 out_enomem_free_avc:
98631 +
98632 +#ifdef CONFIG_PAX_SEGMEXEC
98633 + if (avc_m)
98634 + anon_vma_chain_free(avc_m);
98635 +#endif
98636 +
98637 anon_vma_chain_free(avc);
98638 out_enomem:
98639 return -ENOMEM;
98640 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98641 * Attach the anon_vmas from src to dst.
98642 * Returns 0 on success, -ENOMEM on failure.
98643 */
98644 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98645 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98646 {
98647 struct anon_vma_chain *avc, *pavc;
98648 struct anon_vma *root = NULL;
98649 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98650 * the corresponding VMA in the parent process is attached to.
98651 * Returns 0 on success, non-zero on failure.
98652 */
98653 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98654 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98655 {
98656 struct anon_vma_chain *avc;
98657 struct anon_vma *anon_vma;
98658 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
98659 void __init anon_vma_init(void)
98660 {
98661 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98662 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98663 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98664 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98665 + anon_vma_ctor);
98666 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98667 + SLAB_PANIC|SLAB_NO_SANITIZE);
98668 }
98669
98670 /*
98671 diff --git a/mm/shmem.c b/mm/shmem.c
98672 index 469f90d..34a09ee 100644
98673 --- a/mm/shmem.c
98674 +++ b/mm/shmem.c
98675 @@ -33,7 +33,7 @@
98676 #include <linux/swap.h>
98677 #include <linux/aio.h>
98678
98679 -static struct vfsmount *shm_mnt;
98680 +struct vfsmount *shm_mnt;
98681
98682 #ifdef CONFIG_SHMEM
98683 /*
98684 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98685 #define BOGO_DIRENT_SIZE 20
98686
98687 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98688 -#define SHORT_SYMLINK_LEN 128
98689 +#define SHORT_SYMLINK_LEN 64
98690
98691 /*
98692 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98693 @@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98694 static int shmem_xattr_validate(const char *name)
98695 {
98696 struct { const char *prefix; size_t len; } arr[] = {
98697 +
98698 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98699 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98700 +#endif
98701 +
98702 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98703 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98704 };
98705 @@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98706 if (err)
98707 return err;
98708
98709 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98710 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98711 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98712 + return -EOPNOTSUPP;
98713 + if (size > 8)
98714 + return -EINVAL;
98715 + }
98716 +#endif
98717 +
98718 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98719 }
98720
98721 @@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98722 int err = -ENOMEM;
98723
98724 /* Round up to L1_CACHE_BYTES to resist false sharing */
98725 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98726 - L1_CACHE_BYTES), GFP_KERNEL);
98727 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98728 if (!sbinfo)
98729 return -ENOMEM;
98730
98731 diff --git a/mm/slab.c b/mm/slab.c
98732 index 7c52b38..3ccc17e 100644
98733 --- a/mm/slab.c
98734 +++ b/mm/slab.c
98735 @@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98736 if ((x)->max_freeable < i) \
98737 (x)->max_freeable = i; \
98738 } while (0)
98739 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98740 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98741 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98742 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98743 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98744 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98745 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98746 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98747 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98748 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98749 #else
98750 #define STATS_INC_ACTIVE(x) do { } while (0)
98751 #define STATS_DEC_ACTIVE(x) do { } while (0)
98752 @@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98753 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98754 #define STATS_INC_FREEHIT(x) do { } while (0)
98755 #define STATS_INC_FREEMISS(x) do { } while (0)
98756 +#define STATS_INC_SANITIZED(x) do { } while (0)
98757 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98758 #endif
98759
98760 #if DEBUG
98761 @@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98762 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98763 */
98764 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98765 - const struct page *page, void *obj)
98766 + const struct page *page, const void *obj)
98767 {
98768 u32 offset = (obj - page->s_mem);
98769 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98770 @@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
98771 */
98772
98773 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
98774 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
98775 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98776
98777 if (INDEX_AC != INDEX_NODE)
98778 kmalloc_caches[INDEX_NODE] =
98779 create_kmalloc_cache("kmalloc-node",
98780 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98781 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98782
98783 slab_early_init = 0;
98784
98785 @@ -3384,6 +3388,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98786 struct array_cache *ac = cpu_cache_get(cachep);
98787
98788 check_irq_off();
98789 +
98790 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98791 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98792 + STATS_INC_NOT_SANITIZED(cachep);
98793 + else {
98794 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98795 +
98796 + if (cachep->ctor)
98797 + cachep->ctor(objp);
98798 +
98799 + STATS_INC_SANITIZED(cachep);
98800 + }
98801 +#endif
98802 +
98803 kmemleak_free_recursive(objp, cachep->flags);
98804 objp = cache_free_debugcheck(cachep, objp, caller);
98805
98806 @@ -3607,6 +3625,7 @@ void kfree(const void *objp)
98807
98808 if (unlikely(ZERO_OR_NULL_PTR(objp)))
98809 return;
98810 + VM_BUG_ON(!virt_addr_valid(objp));
98811 local_irq_save(flags);
98812 kfree_debugcheck(objp);
98813 c = virt_to_cache(objp);
98814 @@ -4056,14 +4075,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
98815 }
98816 /* cpu stats */
98817 {
98818 - unsigned long allochit = atomic_read(&cachep->allochit);
98819 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
98820 - unsigned long freehit = atomic_read(&cachep->freehit);
98821 - unsigned long freemiss = atomic_read(&cachep->freemiss);
98822 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
98823 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
98824 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
98825 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
98826
98827 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
98828 allochit, allocmiss, freehit, freemiss);
98829 }
98830 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98831 + {
98832 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
98833 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
98834 +
98835 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
98836 + }
98837 +#endif
98838 #endif
98839 }
98840
98841 @@ -4281,13 +4308,69 @@ static const struct file_operations proc_slabstats_operations = {
98842 static int __init slab_proc_init(void)
98843 {
98844 #ifdef CONFIG_DEBUG_SLAB_LEAK
98845 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
98846 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
98847 #endif
98848 return 0;
98849 }
98850 module_init(slab_proc_init);
98851 #endif
98852
98853 +bool is_usercopy_object(const void *ptr)
98854 +{
98855 + struct page *page;
98856 + struct kmem_cache *cachep;
98857 +
98858 + if (ZERO_OR_NULL_PTR(ptr))
98859 + return false;
98860 +
98861 + if (!slab_is_available())
98862 + return false;
98863 +
98864 + if (!virt_addr_valid(ptr))
98865 + return false;
98866 +
98867 + page = virt_to_head_page(ptr);
98868 +
98869 + if (!PageSlab(page))
98870 + return false;
98871 +
98872 + cachep = page->slab_cache;
98873 + return cachep->flags & SLAB_USERCOPY;
98874 +}
98875 +
98876 +#ifdef CONFIG_PAX_USERCOPY
98877 +const char *check_heap_object(const void *ptr, unsigned long n)
98878 +{
98879 + struct page *page;
98880 + struct kmem_cache *cachep;
98881 + unsigned int objnr;
98882 + unsigned long offset;
98883 +
98884 + if (ZERO_OR_NULL_PTR(ptr))
98885 + return "<null>";
98886 +
98887 + if (!virt_addr_valid(ptr))
98888 + return NULL;
98889 +
98890 + page = virt_to_head_page(ptr);
98891 +
98892 + if (!PageSlab(page))
98893 + return NULL;
98894 +
98895 + cachep = page->slab_cache;
98896 + if (!(cachep->flags & SLAB_USERCOPY))
98897 + return cachep->name;
98898 +
98899 + objnr = obj_to_index(cachep, page, ptr);
98900 + BUG_ON(objnr >= cachep->num);
98901 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
98902 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
98903 + return NULL;
98904 +
98905 + return cachep->name;
98906 +}
98907 +#endif
98908 +
98909 /**
98910 * ksize - get the actual amount of memory allocated for a given object
98911 * @objp: Pointer to the object
98912 diff --git a/mm/slab.h b/mm/slab.h
98913 index 0e0fdd3..d0fd761 100644
98914 --- a/mm/slab.h
98915 +++ b/mm/slab.h
98916 @@ -32,6 +32,20 @@ extern struct list_head slab_caches;
98917 /* The slab cache that manages slab cache information */
98918 extern struct kmem_cache *kmem_cache;
98919
98920 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98921 +#ifdef CONFIG_X86_64
98922 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
98923 +#else
98924 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
98925 +#endif
98926 +enum pax_sanitize_mode {
98927 + PAX_SANITIZE_SLAB_OFF = 0,
98928 + PAX_SANITIZE_SLAB_FAST,
98929 + PAX_SANITIZE_SLAB_FULL,
98930 +};
98931 +extern enum pax_sanitize_mode pax_sanitize_slab;
98932 +#endif
98933 +
98934 unsigned long calculate_alignment(unsigned long flags,
98935 unsigned long align, unsigned long size);
98936
98937 @@ -67,7 +81,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98938
98939 /* Legal flag mask for kmem_cache_create(), for various configurations */
98940 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
98941 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
98942 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
98943 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
98944
98945 #if defined(CONFIG_DEBUG_SLAB)
98946 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
98947 @@ -251,6 +266,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
98948 return s;
98949
98950 page = virt_to_head_page(x);
98951 +
98952 + BUG_ON(!PageSlab(page));
98953 +
98954 cachep = page->slab_cache;
98955 if (slab_equal_or_root(cachep, s))
98956 return cachep;
98957 diff --git a/mm/slab_common.c b/mm/slab_common.c
98958 index d319502..da7714e 100644
98959 --- a/mm/slab_common.c
98960 +++ b/mm/slab_common.c
98961 @@ -25,11 +25,35 @@
98962
98963 #include "slab.h"
98964
98965 -enum slab_state slab_state;
98966 +enum slab_state slab_state __read_only;
98967 LIST_HEAD(slab_caches);
98968 DEFINE_MUTEX(slab_mutex);
98969 struct kmem_cache *kmem_cache;
98970
98971 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98972 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
98973 +static int __init pax_sanitize_slab_setup(char *str)
98974 +{
98975 + if (!str)
98976 + return 0;
98977 +
98978 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
98979 + pr_info("PaX slab sanitization: %s\n", "disabled");
98980 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
98981 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
98982 + pr_info("PaX slab sanitization: %s\n", "fast");
98983 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
98984 + } else if (!strcmp(str, "full")) {
98985 + pr_info("PaX slab sanitization: %s\n", "full");
98986 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
98987 + } else
98988 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
98989 +
98990 + return 0;
98991 +}
98992 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
98993 +#endif
98994 +
98995 #ifdef CONFIG_DEBUG_VM
98996 static int kmem_cache_sanity_check(const char *name, size_t size)
98997 {
98998 @@ -160,7 +184,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
98999 if (err)
99000 goto out_free_cache;
99001
99002 - s->refcount = 1;
99003 + atomic_set(&s->refcount, 1);
99004 list_add(&s->list, &slab_caches);
99005 out:
99006 if (err)
99007 @@ -222,6 +246,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99008 */
99009 flags &= CACHE_CREATE_MASK;
99010
99011 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99012 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99013 + flags |= SLAB_NO_SANITIZE;
99014 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99015 + flags &= ~SLAB_NO_SANITIZE;
99016 +#endif
99017 +
99018 s = __kmem_cache_alias(name, size, align, flags, ctor);
99019 if (s)
99020 goto out_unlock;
99021 @@ -341,8 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99022
99023 mutex_lock(&slab_mutex);
99024
99025 - s->refcount--;
99026 - if (s->refcount)
99027 + if (!atomic_dec_and_test(&s->refcount))
99028 goto out_unlock;
99029
99030 if (memcg_cleanup_cache_params(s) != 0)
99031 @@ -362,7 +392,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99032 rcu_barrier();
99033
99034 memcg_free_cache_params(s);
99035 -#ifdef SLAB_SUPPORTS_SYSFS
99036 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99037 sysfs_slab_remove(s);
99038 #else
99039 slab_kmem_cache_release(s);
99040 @@ -418,7 +448,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99041 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99042 name, size, err);
99043
99044 - s->refcount = -1; /* Exempt from merging for now */
99045 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99046 }
99047
99048 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99049 @@ -431,7 +461,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99050
99051 create_boot_cache(s, name, size, flags);
99052 list_add(&s->list, &slab_caches);
99053 - s->refcount = 1;
99054 + atomic_set(&s->refcount, 1);
99055 return s;
99056 }
99057
99058 @@ -443,6 +473,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99059 EXPORT_SYMBOL(kmalloc_dma_caches);
99060 #endif
99061
99062 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99063 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99064 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99065 +#endif
99066 +
99067 /*
99068 * Conversion table for small slabs sizes / 8 to the index in the
99069 * kmalloc array. This is necessary for slabs < 192 since we have non power
99070 @@ -507,6 +542,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99071 return kmalloc_dma_caches[index];
99072
99073 #endif
99074 +
99075 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99076 + if (unlikely((flags & GFP_USERCOPY)))
99077 + return kmalloc_usercopy_caches[index];
99078 +
99079 +#endif
99080 +
99081 return kmalloc_caches[index];
99082 }
99083
99084 @@ -563,7 +605,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99085 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99086 if (!kmalloc_caches[i]) {
99087 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99088 - 1 << i, flags);
99089 + 1 << i, SLAB_USERCOPY | flags);
99090 }
99091
99092 /*
99093 @@ -572,10 +614,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99094 * earlier power of two caches
99095 */
99096 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99097 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99098 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99099
99100 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99101 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99102 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99103 }
99104
99105 /* Kmalloc array is now usable */
99106 @@ -608,6 +650,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99107 }
99108 }
99109 #endif
99110 +
99111 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99112 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99113 + struct kmem_cache *s = kmalloc_caches[i];
99114 +
99115 + if (s) {
99116 + int size = kmalloc_size(i);
99117 + char *n = kasprintf(GFP_NOWAIT,
99118 + "usercopy-kmalloc-%d", size);
99119 +
99120 + BUG_ON(!n);
99121 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99122 + size, SLAB_USERCOPY | flags);
99123 + }
99124 + }
99125 +#endif
99126 +
99127 }
99128 #endif /* !CONFIG_SLOB */
99129
99130 @@ -666,6 +725,9 @@ void print_slabinfo_header(struct seq_file *m)
99131 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99132 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99133 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99134 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99135 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99136 +#endif
99137 #endif
99138 seq_putc(m, '\n');
99139 }
99140 diff --git a/mm/slob.c b/mm/slob.c
99141 index 21980e0..975f1bf 100644
99142 --- a/mm/slob.c
99143 +++ b/mm/slob.c
99144 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99145 /*
99146 * Return the size of a slob block.
99147 */
99148 -static slobidx_t slob_units(slob_t *s)
99149 +static slobidx_t slob_units(const slob_t *s)
99150 {
99151 if (s->units > 0)
99152 return s->units;
99153 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99154 /*
99155 * Return the next free slob block pointer after this one.
99156 */
99157 -static slob_t *slob_next(slob_t *s)
99158 +static slob_t *slob_next(const slob_t *s)
99159 {
99160 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99161 slobidx_t next;
99162 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99163 /*
99164 * Returns true if s is the last free block in its page.
99165 */
99166 -static int slob_last(slob_t *s)
99167 +static int slob_last(const slob_t *s)
99168 {
99169 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99170 }
99171
99172 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99173 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99174 {
99175 - void *page;
99176 + struct page *page;
99177
99178 #ifdef CONFIG_NUMA
99179 if (node != NUMA_NO_NODE)
99180 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99181 if (!page)
99182 return NULL;
99183
99184 - return page_address(page);
99185 + __SetPageSlab(page);
99186 + return page;
99187 }
99188
99189 -static void slob_free_pages(void *b, int order)
99190 +static void slob_free_pages(struct page *sp, int order)
99191 {
99192 if (current->reclaim_state)
99193 current->reclaim_state->reclaimed_slab += 1 << order;
99194 - free_pages((unsigned long)b, order);
99195 + __ClearPageSlab(sp);
99196 + page_mapcount_reset(sp);
99197 + sp->private = 0;
99198 + __free_pages(sp, order);
99199 }
99200
99201 /*
99202 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99203
99204 /* Not enough space: must allocate a new page */
99205 if (!b) {
99206 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99207 - if (!b)
99208 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99209 + if (!sp)
99210 return NULL;
99211 - sp = virt_to_page(b);
99212 - __SetPageSlab(sp);
99213 + b = page_address(sp);
99214
99215 spin_lock_irqsave(&slob_lock, flags);
99216 sp->units = SLOB_UNITS(PAGE_SIZE);
99217 sp->freelist = b;
99218 + sp->private = 0;
99219 INIT_LIST_HEAD(&sp->lru);
99220 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99221 set_slob_page_free(sp, slob_list);
99222 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99223 /*
99224 * slob_free: entry point into the slob allocator.
99225 */
99226 -static void slob_free(void *block, int size)
99227 +static void slob_free(struct kmem_cache *c, void *block, int size)
99228 {
99229 struct page *sp;
99230 slob_t *prev, *next, *b = (slob_t *)block;
99231 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99232 if (slob_page_free(sp))
99233 clear_slob_page_free(sp);
99234 spin_unlock_irqrestore(&slob_lock, flags);
99235 - __ClearPageSlab(sp);
99236 - page_mapcount_reset(sp);
99237 - slob_free_pages(b, 0);
99238 + slob_free_pages(sp, 0);
99239 return;
99240 }
99241
99242 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99243 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99244 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99245 +#endif
99246 +
99247 if (!slob_page_free(sp)) {
99248 /* This slob page is about to become partially free. Easy! */
99249 sp->units = units;
99250 @@ -424,11 +431,10 @@ out:
99251 */
99252
99253 static __always_inline void *
99254 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99255 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99256 {
99257 - unsigned int *m;
99258 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99259 - void *ret;
99260 + slob_t *m;
99261 + void *ret = NULL;
99262
99263 gfp &= gfp_allowed_mask;
99264
99265 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99266
99267 if (!m)
99268 return NULL;
99269 - *m = size;
99270 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99271 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99272 + m[0].units = size;
99273 + m[1].units = align;
99274 ret = (void *)m + align;
99275
99276 trace_kmalloc_node(caller, ret,
99277 size, size + align, gfp, node);
99278 } else {
99279 unsigned int order = get_order(size);
99280 + struct page *page;
99281
99282 if (likely(order))
99283 gfp |= __GFP_COMP;
99284 - ret = slob_new_pages(gfp, order, node);
99285 + page = slob_new_pages(gfp, order, node);
99286 + if (page) {
99287 + ret = page_address(page);
99288 + page->private = size;
99289 + }
99290
99291 trace_kmalloc_node(caller, ret,
99292 size, PAGE_SIZE << order, gfp, node);
99293 }
99294
99295 - kmemleak_alloc(ret, size, 1, gfp);
99296 + return ret;
99297 +}
99298 +
99299 +static __always_inline void *
99300 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99301 +{
99302 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99303 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99304 +
99305 + if (!ZERO_OR_NULL_PTR(ret))
99306 + kmemleak_alloc(ret, size, 1, gfp);
99307 return ret;
99308 }
99309
99310 @@ -493,34 +517,112 @@ void kfree(const void *block)
99311 return;
99312 kmemleak_free(block);
99313
99314 + VM_BUG_ON(!virt_addr_valid(block));
99315 sp = virt_to_page(block);
99316 - if (PageSlab(sp)) {
99317 + VM_BUG_ON(!PageSlab(sp));
99318 + if (!sp->private) {
99319 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99320 - unsigned int *m = (unsigned int *)(block - align);
99321 - slob_free(m, *m + align);
99322 - } else
99323 + slob_t *m = (slob_t *)(block - align);
99324 + slob_free(NULL, m, m[0].units + align);
99325 + } else {
99326 + __ClearPageSlab(sp);
99327 + page_mapcount_reset(sp);
99328 + sp->private = 0;
99329 __free_pages(sp, compound_order(sp));
99330 + }
99331 }
99332 EXPORT_SYMBOL(kfree);
99333
99334 +bool is_usercopy_object(const void *ptr)
99335 +{
99336 + if (!slab_is_available())
99337 + return false;
99338 +
99339 + // PAX: TODO
99340 +
99341 + return false;
99342 +}
99343 +
99344 +#ifdef CONFIG_PAX_USERCOPY
99345 +const char *check_heap_object(const void *ptr, unsigned long n)
99346 +{
99347 + struct page *page;
99348 + const slob_t *free;
99349 + const void *base;
99350 + unsigned long flags;
99351 +
99352 + if (ZERO_OR_NULL_PTR(ptr))
99353 + return "<null>";
99354 +
99355 + if (!virt_addr_valid(ptr))
99356 + return NULL;
99357 +
99358 + page = virt_to_head_page(ptr);
99359 + if (!PageSlab(page))
99360 + return NULL;
99361 +
99362 + if (page->private) {
99363 + base = page;
99364 + if (base <= ptr && n <= page->private - (ptr - base))
99365 + return NULL;
99366 + return "<slob>";
99367 + }
99368 +
99369 + /* some tricky double walking to find the chunk */
99370 + spin_lock_irqsave(&slob_lock, flags);
99371 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99372 + free = page->freelist;
99373 +
99374 + while (!slob_last(free) && (void *)free <= ptr) {
99375 + base = free + slob_units(free);
99376 + free = slob_next(free);
99377 + }
99378 +
99379 + while (base < (void *)free) {
99380 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99381 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99382 + int offset;
99383 +
99384 + if (ptr < base + align)
99385 + break;
99386 +
99387 + offset = ptr - base - align;
99388 + if (offset >= m) {
99389 + base += size;
99390 + continue;
99391 + }
99392 +
99393 + if (n > m - offset)
99394 + break;
99395 +
99396 + spin_unlock_irqrestore(&slob_lock, flags);
99397 + return NULL;
99398 + }
99399 +
99400 + spin_unlock_irqrestore(&slob_lock, flags);
99401 + return "<slob>";
99402 +}
99403 +#endif
99404 +
99405 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99406 size_t ksize(const void *block)
99407 {
99408 struct page *sp;
99409 int align;
99410 - unsigned int *m;
99411 + slob_t *m;
99412
99413 BUG_ON(!block);
99414 if (unlikely(block == ZERO_SIZE_PTR))
99415 return 0;
99416
99417 sp = virt_to_page(block);
99418 - if (unlikely(!PageSlab(sp)))
99419 - return PAGE_SIZE << compound_order(sp);
99420 + VM_BUG_ON(!PageSlab(sp));
99421 + if (sp->private)
99422 + return sp->private;
99423
99424 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99425 - m = (unsigned int *)(block - align);
99426 - return SLOB_UNITS(*m) * SLOB_UNIT;
99427 + m = (slob_t *)(block - align);
99428 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99429 }
99430 EXPORT_SYMBOL(ksize);
99431
99432 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99433
99434 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99435 {
99436 - void *b;
99437 + void *b = NULL;
99438
99439 flags &= gfp_allowed_mask;
99440
99441 lockdep_trace_alloc(flags);
99442
99443 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99444 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99445 +#else
99446 if (c->size < PAGE_SIZE) {
99447 b = slob_alloc(c->size, flags, c->align, node);
99448 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99449 SLOB_UNITS(c->size) * SLOB_UNIT,
99450 flags, node);
99451 } else {
99452 - b = slob_new_pages(flags, get_order(c->size), node);
99453 + struct page *sp;
99454 +
99455 + sp = slob_new_pages(flags, get_order(c->size), node);
99456 + if (sp) {
99457 + b = page_address(sp);
99458 + sp->private = c->size;
99459 + }
99460 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99461 PAGE_SIZE << get_order(c->size),
99462 flags, node);
99463 }
99464 +#endif
99465
99466 if (b && c->ctor)
99467 c->ctor(b);
99468 @@ -582,12 +694,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99469 EXPORT_SYMBOL(kmem_cache_alloc_node);
99470 #endif
99471
99472 -static void __kmem_cache_free(void *b, int size)
99473 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99474 {
99475 - if (size < PAGE_SIZE)
99476 - slob_free(b, size);
99477 + struct page *sp;
99478 +
99479 + sp = virt_to_page(b);
99480 + BUG_ON(!PageSlab(sp));
99481 + if (!sp->private)
99482 + slob_free(c, b, size);
99483 else
99484 - slob_free_pages(b, get_order(size));
99485 + slob_free_pages(sp, get_order(size));
99486 }
99487
99488 static void kmem_rcu_free(struct rcu_head *head)
99489 @@ -595,22 +711,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99490 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99491 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99492
99493 - __kmem_cache_free(b, slob_rcu->size);
99494 + __kmem_cache_free(NULL, b, slob_rcu->size);
99495 }
99496
99497 void kmem_cache_free(struct kmem_cache *c, void *b)
99498 {
99499 + int size = c->size;
99500 +
99501 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99502 + if (size + c->align < PAGE_SIZE) {
99503 + size += c->align;
99504 + b -= c->align;
99505 + }
99506 +#endif
99507 +
99508 kmemleak_free_recursive(b, c->flags);
99509 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99510 struct slob_rcu *slob_rcu;
99511 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99512 - slob_rcu->size = c->size;
99513 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99514 + slob_rcu->size = size;
99515 call_rcu(&slob_rcu->head, kmem_rcu_free);
99516 } else {
99517 - __kmem_cache_free(b, c->size);
99518 + __kmem_cache_free(c, b, size);
99519 }
99520
99521 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99522 + trace_kfree(_RET_IP_, b);
99523 +#else
99524 trace_kmem_cache_free(_RET_IP_, b);
99525 +#endif
99526 +
99527 }
99528 EXPORT_SYMBOL(kmem_cache_free);
99529
99530 diff --git a/mm/slub.c b/mm/slub.c
99531 index 3e8afcc..d6e2c89 100644
99532 --- a/mm/slub.c
99533 +++ b/mm/slub.c
99534 @@ -207,7 +207,7 @@ struct track {
99535
99536 enum track_item { TRACK_ALLOC, TRACK_FREE };
99537
99538 -#ifdef CONFIG_SYSFS
99539 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99540 static int sysfs_slab_add(struct kmem_cache *);
99541 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99542 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99543 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
99544 if (!t->addr)
99545 return;
99546
99547 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99548 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99549 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99550 #ifdef CONFIG_STACKTRACE
99551 {
99552 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99553
99554 slab_free_hook(s, x);
99555
99556 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99557 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99558 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99559 + if (s->ctor)
99560 + s->ctor(x);
99561 + }
99562 +#endif
99563 +
99564 redo:
99565 /*
99566 * Determine the currently cpus per cpu slab.
99567 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
99568 * Merge control. If this is set then no merging of slab caches will occur.
99569 * (Could be removed. This was introduced to pacify the merge skeptics.)
99570 */
99571 -static int slub_nomerge;
99572 +static int slub_nomerge = 1;
99573
99574 /*
99575 * Calculate the order of allocation given an slab object size.
99576 @@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99577 s->inuse = size;
99578
99579 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99580 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99581 + (!(flags & SLAB_NO_SANITIZE)) ||
99582 +#endif
99583 s->ctor)) {
99584 /*
99585 * Relocate free pointer after the object if it is not
99586 @@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99587 EXPORT_SYMBOL(__kmalloc_node);
99588 #endif
99589
99590 +bool is_usercopy_object(const void *ptr)
99591 +{
99592 + struct page *page;
99593 + struct kmem_cache *s;
99594 +
99595 + if (ZERO_OR_NULL_PTR(ptr))
99596 + return false;
99597 +
99598 + if (!slab_is_available())
99599 + return false;
99600 +
99601 + if (!virt_addr_valid(ptr))
99602 + return false;
99603 +
99604 + page = virt_to_head_page(ptr);
99605 +
99606 + if (!PageSlab(page))
99607 + return false;
99608 +
99609 + s = page->slab_cache;
99610 + return s->flags & SLAB_USERCOPY;
99611 +}
99612 +
99613 +#ifdef CONFIG_PAX_USERCOPY
99614 +const char *check_heap_object(const void *ptr, unsigned long n)
99615 +{
99616 + struct page *page;
99617 + struct kmem_cache *s;
99618 + unsigned long offset;
99619 +
99620 + if (ZERO_OR_NULL_PTR(ptr))
99621 + return "<null>";
99622 +
99623 + if (!virt_addr_valid(ptr))
99624 + return NULL;
99625 +
99626 + page = virt_to_head_page(ptr);
99627 +
99628 + if (!PageSlab(page))
99629 + return NULL;
99630 +
99631 + s = page->slab_cache;
99632 + if (!(s->flags & SLAB_USERCOPY))
99633 + return s->name;
99634 +
99635 + offset = (ptr - page_address(page)) % s->size;
99636 + if (offset <= s->object_size && n <= s->object_size - offset)
99637 + return NULL;
99638 +
99639 + return s->name;
99640 +}
99641 +#endif
99642 +
99643 size_t ksize(const void *object)
99644 {
99645 struct page *page;
99646 @@ -3341,6 +3405,7 @@ void kfree(const void *x)
99647 if (unlikely(ZERO_OR_NULL_PTR(x)))
99648 return;
99649
99650 + VM_BUG_ON(!virt_addr_valid(x));
99651 page = virt_to_head_page(x);
99652 if (unlikely(!PageSlab(page))) {
99653 BUG_ON(!PageCompound(page));
99654 @@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
99655 /*
99656 * We may have set a slab to be unmergeable during bootstrap.
99657 */
99658 - if (s->refcount < 0)
99659 + if (atomic_read(&s->refcount) < 0)
99660 return 1;
99661
99662 return 0;
99663 @@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99664 int i;
99665 struct kmem_cache *c;
99666
99667 - s->refcount++;
99668 + atomic_inc(&s->refcount);
99669
99670 /*
99671 * Adjust the object sizes so that we clear
99672 @@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99673 }
99674
99675 if (sysfs_slab_alias(s, name)) {
99676 - s->refcount--;
99677 + atomic_dec(&s->refcount);
99678 s = NULL;
99679 }
99680 }
99681 @@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99682 }
99683 #endif
99684
99685 -#ifdef CONFIG_SYSFS
99686 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99687 static int count_inuse(struct page *page)
99688 {
99689 return page->inuse;
99690 @@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99691 len += sprintf(buf + len, "%7ld ", l->count);
99692
99693 if (l->addr)
99694 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99695 + len += sprintf(buf + len, "%pS", NULL);
99696 +#else
99697 len += sprintf(buf + len, "%pS", (void *)l->addr);
99698 +#endif
99699 else
99700 len += sprintf(buf + len, "<not-available>");
99701
99702 @@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
99703 validate_slab_cache(kmalloc_caches[9]);
99704 }
99705 #else
99706 -#ifdef CONFIG_SYSFS
99707 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99708 static void resiliency_test(void) {};
99709 #endif
99710 #endif
99711
99712 -#ifdef CONFIG_SYSFS
99713 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99714 enum slab_stat_type {
99715 SL_ALL, /* All slabs */
99716 SL_PARTIAL, /* Only partially allocated slabs */
99717 @@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99718 {
99719 if (!s->ctor)
99720 return 0;
99721 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99722 + return sprintf(buf, "%pS\n", NULL);
99723 +#else
99724 return sprintf(buf, "%pS\n", s->ctor);
99725 +#endif
99726 }
99727 SLAB_ATTR_RO(ctor);
99728
99729 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99730 {
99731 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99732 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99733 }
99734 SLAB_ATTR_RO(aliases);
99735
99736 @@ -4554,6 +4627,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99737 SLAB_ATTR_RO(cache_dma);
99738 #endif
99739
99740 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99741 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99742 +{
99743 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99744 +}
99745 +SLAB_ATTR_RO(usercopy);
99746 +#endif
99747 +
99748 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99749 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99750 +{
99751 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99752 +}
99753 +SLAB_ATTR_RO(sanitize);
99754 +#endif
99755 +
99756 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99757 {
99758 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99759 @@ -4888,6 +4977,12 @@ static struct attribute *slab_attrs[] = {
99760 #ifdef CONFIG_ZONE_DMA
99761 &cache_dma_attr.attr,
99762 #endif
99763 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99764 + &usercopy_attr.attr,
99765 +#endif
99766 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99767 + &sanitize_attr.attr,
99768 +#endif
99769 #ifdef CONFIG_NUMA
99770 &remote_node_defrag_ratio_attr.attr,
99771 #endif
99772 @@ -5132,6 +5227,7 @@ static char *create_unique_id(struct kmem_cache *s)
99773 return name;
99774 }
99775
99776 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99777 static int sysfs_slab_add(struct kmem_cache *s)
99778 {
99779 int err;
99780 @@ -5205,6 +5301,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99781 kobject_del(&s->kobj);
99782 kobject_put(&s->kobj);
99783 }
99784 +#endif
99785
99786 /*
99787 * Need to buffer aliases during bootup until sysfs becomes
99788 @@ -5218,6 +5315,7 @@ struct saved_alias {
99789
99790 static struct saved_alias *alias_list;
99791
99792 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99793 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99794 {
99795 struct saved_alias *al;
99796 @@ -5240,6 +5338,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99797 alias_list = al;
99798 return 0;
99799 }
99800 +#endif
99801
99802 static int __init slab_sysfs_init(void)
99803 {
99804 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99805 index 4cba9c2..b4f9fcc 100644
99806 --- a/mm/sparse-vmemmap.c
99807 +++ b/mm/sparse-vmemmap.c
99808 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
99809 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99810 if (!p)
99811 return NULL;
99812 - pud_populate(&init_mm, pud, p);
99813 + pud_populate_kernel(&init_mm, pud, p);
99814 }
99815 return pud;
99816 }
99817 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
99818 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99819 if (!p)
99820 return NULL;
99821 - pgd_populate(&init_mm, pgd, p);
99822 + pgd_populate_kernel(&init_mm, pgd, p);
99823 }
99824 return pgd;
99825 }
99826 diff --git a/mm/sparse.c b/mm/sparse.c
99827 index d1b48b6..6e8590e 100644
99828 --- a/mm/sparse.c
99829 +++ b/mm/sparse.c
99830 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
99831
99832 for (i = 0; i < PAGES_PER_SECTION; i++) {
99833 if (PageHWPoison(&memmap[i])) {
99834 - atomic_long_sub(1, &num_poisoned_pages);
99835 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
99836 ClearPageHWPoison(&memmap[i]);
99837 }
99838 }
99839 diff --git a/mm/swap.c b/mm/swap.c
99840 index 6b2dc38..46b79ba 100644
99841 --- a/mm/swap.c
99842 +++ b/mm/swap.c
99843 @@ -31,6 +31,7 @@
99844 #include <linux/memcontrol.h>
99845 #include <linux/gfp.h>
99846 #include <linux/uio.h>
99847 +#include <linux/hugetlb.h>
99848
99849 #include "internal.h"
99850
99851 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
99852
99853 __page_cache_release(page);
99854 dtor = get_compound_page_dtor(page);
99855 + if (!PageHuge(page))
99856 + BUG_ON(dtor != free_compound_page);
99857 (*dtor)(page);
99858 }
99859
99860 diff --git a/mm/swapfile.c b/mm/swapfile.c
99861 index 8798b2e..348f9dd 100644
99862 --- a/mm/swapfile.c
99863 +++ b/mm/swapfile.c
99864 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
99865
99866 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
99867 /* Activity counter to indicate that a swapon or swapoff has occurred */
99868 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
99869 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
99870
99871 static inline unsigned char swap_count(unsigned char ent)
99872 {
99873 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
99874 spin_unlock(&swap_lock);
99875
99876 err = 0;
99877 - atomic_inc(&proc_poll_event);
99878 + atomic_inc_unchecked(&proc_poll_event);
99879 wake_up_interruptible(&proc_poll_wait);
99880
99881 out_dput:
99882 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
99883
99884 poll_wait(file, &proc_poll_wait, wait);
99885
99886 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
99887 - seq->poll_event = atomic_read(&proc_poll_event);
99888 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
99889 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99890 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
99891 }
99892
99893 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
99894 return ret;
99895
99896 seq = file->private_data;
99897 - seq->poll_event = atomic_read(&proc_poll_event);
99898 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99899 return 0;
99900 }
99901
99902 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
99903 (frontswap_map) ? "FS" : "");
99904
99905 mutex_unlock(&swapon_mutex);
99906 - atomic_inc(&proc_poll_event);
99907 + atomic_inc_unchecked(&proc_poll_event);
99908 wake_up_interruptible(&proc_poll_wait);
99909
99910 if (S_ISREG(inode->i_mode))
99911 diff --git a/mm/util.c b/mm/util.c
99912 index 093c973..b70a268 100644
99913 --- a/mm/util.c
99914 +++ b/mm/util.c
99915 @@ -202,6 +202,12 @@ done:
99916 void arch_pick_mmap_layout(struct mm_struct *mm)
99917 {
99918 mm->mmap_base = TASK_UNMAPPED_BASE;
99919 +
99920 +#ifdef CONFIG_PAX_RANDMMAP
99921 + if (mm->pax_flags & MF_PAX_RANDMMAP)
99922 + mm->mmap_base += mm->delta_mmap;
99923 +#endif
99924 +
99925 mm->get_unmapped_area = arch_get_unmapped_area;
99926 }
99927 #endif
99928 @@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
99929 if (!mm->arg_end)
99930 goto out_mm; /* Shh! No looking before we're done */
99931
99932 + if (gr_acl_handle_procpidmem(task))
99933 + goto out_mm;
99934 +
99935 len = mm->arg_end - mm->arg_start;
99936
99937 if (len > buflen)
99938 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
99939 index 2b0aa54..b451f74 100644
99940 --- a/mm/vmalloc.c
99941 +++ b/mm/vmalloc.c
99942 @@ -40,6 +40,21 @@ struct vfree_deferred {
99943 };
99944 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
99945
99946 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99947 +struct stack_deferred_llist {
99948 + struct llist_head list;
99949 + void *stack;
99950 + void *lowmem_stack;
99951 +};
99952 +
99953 +struct stack_deferred {
99954 + struct stack_deferred_llist list;
99955 + struct work_struct wq;
99956 +};
99957 +
99958 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
99959 +#endif
99960 +
99961 static void __vunmap(const void *, int);
99962
99963 static void free_work(struct work_struct *w)
99964 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
99965 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
99966 struct llist_node *llnode = llist_del_all(&p->list);
99967 while (llnode) {
99968 - void *p = llnode;
99969 + void *x = llnode;
99970 llnode = llist_next(llnode);
99971 - __vunmap(p, 1);
99972 + __vunmap(x, 1);
99973 }
99974 }
99975
99976 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99977 +static void unmap_work(struct work_struct *w)
99978 +{
99979 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
99980 + struct llist_node *llnode = llist_del_all(&p->list.list);
99981 + while (llnode) {
99982 + struct stack_deferred_llist *x =
99983 + llist_entry((struct llist_head *)llnode,
99984 + struct stack_deferred_llist, list);
99985 + void *stack = ACCESS_ONCE(x->stack);
99986 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
99987 + llnode = llist_next(llnode);
99988 + __vunmap(stack, 0);
99989 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
99990 + }
99991 +}
99992 +#endif
99993 +
99994 /*** Page table manipulation functions ***/
99995
99996 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99997 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99998
99999 pte = pte_offset_kernel(pmd, addr);
100000 do {
100001 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100002 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100003 +
100004 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100005 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100006 + BUG_ON(!pte_exec(*pte));
100007 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100008 + continue;
100009 + }
100010 +#endif
100011 +
100012 + {
100013 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100014 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100015 + }
100016 } while (pte++, addr += PAGE_SIZE, addr != end);
100017 }
100018
100019 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100020 pte = pte_alloc_kernel(pmd, addr);
100021 if (!pte)
100022 return -ENOMEM;
100023 +
100024 + pax_open_kernel();
100025 do {
100026 struct page *page = pages[*nr];
100027
100028 - if (WARN_ON(!pte_none(*pte)))
100029 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100030 + if (pgprot_val(prot) & _PAGE_NX)
100031 +#endif
100032 +
100033 + if (!pte_none(*pte)) {
100034 + pax_close_kernel();
100035 + WARN_ON(1);
100036 return -EBUSY;
100037 - if (WARN_ON(!page))
100038 + }
100039 + if (!page) {
100040 + pax_close_kernel();
100041 + WARN_ON(1);
100042 return -ENOMEM;
100043 + }
100044 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100045 (*nr)++;
100046 } while (pte++, addr += PAGE_SIZE, addr != end);
100047 + pax_close_kernel();
100048 return 0;
100049 }
100050
100051 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100052 pmd_t *pmd;
100053 unsigned long next;
100054
100055 - pmd = pmd_alloc(&init_mm, pud, addr);
100056 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100057 if (!pmd)
100058 return -ENOMEM;
100059 do {
100060 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100061 pud_t *pud;
100062 unsigned long next;
100063
100064 - pud = pud_alloc(&init_mm, pgd, addr);
100065 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100066 if (!pud)
100067 return -ENOMEM;
100068 do {
100069 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100070 if (addr >= MODULES_VADDR && addr < MODULES_END)
100071 return 1;
100072 #endif
100073 +
100074 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100075 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100076 + return 1;
100077 +#endif
100078 +
100079 return is_vmalloc_addr(x);
100080 }
100081
100082 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100083
100084 if (!pgd_none(*pgd)) {
100085 pud_t *pud = pud_offset(pgd, addr);
100086 +#ifdef CONFIG_X86
100087 + if (!pud_large(*pud))
100088 +#endif
100089 if (!pud_none(*pud)) {
100090 pmd_t *pmd = pmd_offset(pud, addr);
100091 +#ifdef CONFIG_X86
100092 + if (!pmd_large(*pmd))
100093 +#endif
100094 if (!pmd_none(*pmd)) {
100095 pte_t *ptep, pte;
100096
100097 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100098 for_each_possible_cpu(i) {
100099 struct vmap_block_queue *vbq;
100100 struct vfree_deferred *p;
100101 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100102 + struct stack_deferred *p2;
100103 +#endif
100104
100105 vbq = &per_cpu(vmap_block_queue, i);
100106 spin_lock_init(&vbq->lock);
100107 INIT_LIST_HEAD(&vbq->free);
100108 +
100109 p = &per_cpu(vfree_deferred, i);
100110 init_llist_head(&p->list);
100111 INIT_WORK(&p->wq, free_work);
100112 +
100113 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100114 + p2 = &per_cpu(stack_deferred, i);
100115 + init_llist_head(&p2->list.list);
100116 + INIT_WORK(&p2->wq, unmap_work);
100117 +#endif
100118 }
100119
100120 /* Import existing vmlist entries. */
100121 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100122 struct vm_struct *area;
100123
100124 BUG_ON(in_interrupt());
100125 +
100126 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100127 + if (flags & VM_KERNEXEC) {
100128 + if (start != VMALLOC_START || end != VMALLOC_END)
100129 + return NULL;
100130 + start = (unsigned long)MODULES_EXEC_VADDR;
100131 + end = (unsigned long)MODULES_EXEC_END;
100132 + }
100133 +#endif
100134 +
100135 if (flags & VM_IOREMAP)
100136 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100137
100138 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100139 }
100140 EXPORT_SYMBOL(vunmap);
100141
100142 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100143 +void unmap_process_stacks(struct task_struct *task)
100144 +{
100145 + if (unlikely(in_interrupt())) {
100146 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100147 + struct stack_deferred_llist *list = task->stack;
100148 + list->stack = task->stack;
100149 + list->lowmem_stack = task->lowmem_stack;
100150 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100151 + schedule_work(&p->wq);
100152 + } else {
100153 + __vunmap(task->stack, 0);
100154 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100155 + }
100156 +}
100157 +#endif
100158 +
100159 /**
100160 * vmap - map an array of pages into virtually contiguous space
100161 * @pages: array of page pointers
100162 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100163 if (count > totalram_pages)
100164 return NULL;
100165
100166 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100167 + if (!(pgprot_val(prot) & _PAGE_NX))
100168 + flags |= VM_KERNEXEC;
100169 +#endif
100170 +
100171 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100172 __builtin_return_address(0));
100173 if (!area)
100174 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100175 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100176 goto fail;
100177
100178 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100179 + if (!(pgprot_val(prot) & _PAGE_NX))
100180 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100181 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100182 + else
100183 +#endif
100184 +
100185 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100186 start, end, node, gfp_mask, caller);
100187 if (!area)
100188 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100189 * For tight control over page level allocator and protection flags
100190 * use __vmalloc() instead.
100191 */
100192 -
100193 void *vmalloc_exec(unsigned long size)
100194 {
100195 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100196 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100197 NUMA_NO_NODE, __builtin_return_address(0));
100198 }
100199
100200 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100201 {
100202 struct vm_struct *area;
100203
100204 + BUG_ON(vma->vm_mirror);
100205 +
100206 size = PAGE_ALIGN(size);
100207
100208 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100209 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100210 v->addr, v->addr + v->size, v->size);
100211
100212 if (v->caller)
100213 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100214 + seq_printf(m, " %pK", v->caller);
100215 +#else
100216 seq_printf(m, " %pS", v->caller);
100217 +#endif
100218
100219 if (v->nr_pages)
100220 seq_printf(m, " pages=%d", v->nr_pages);
100221 diff --git a/mm/vmstat.c b/mm/vmstat.c
100222 index e9ab104..de275bd 100644
100223 --- a/mm/vmstat.c
100224 +++ b/mm/vmstat.c
100225 @@ -20,6 +20,7 @@
100226 #include <linux/writeback.h>
100227 #include <linux/compaction.h>
100228 #include <linux/mm_inline.h>
100229 +#include <linux/grsecurity.h>
100230
100231 #include "internal.h"
100232
100233 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
100234 *
100235 * vm_stat contains the global counters
100236 */
100237 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100238 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100239 EXPORT_SYMBOL(vm_stat);
100240
100241 #ifdef CONFIG_SMP
100242 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
100243
100244 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100245 if (diff[i])
100246 - atomic_long_add(diff[i], &vm_stat[i]);
100247 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100248 }
100249
100250 /*
100251 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
100252 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100253 if (v) {
100254
100255 - atomic_long_add(v, &zone->vm_stat[i]);
100256 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100257 global_diff[i] += v;
100258 #ifdef CONFIG_NUMA
100259 /* 3 seconds idle till flush */
100260 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
100261
100262 v = p->vm_stat_diff[i];
100263 p->vm_stat_diff[i] = 0;
100264 - atomic_long_add(v, &zone->vm_stat[i]);
100265 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100266 global_diff[i] += v;
100267 }
100268 }
100269 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100270 if (pset->vm_stat_diff[i]) {
100271 int v = pset->vm_stat_diff[i];
100272 pset->vm_stat_diff[i] = 0;
100273 - atomic_long_add(v, &zone->vm_stat[i]);
100274 - atomic_long_add(v, &vm_stat[i]);
100275 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100276 + atomic_long_add_unchecked(v, &vm_stat[i]);
100277 }
100278 }
100279 #endif
100280 @@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100281 stat_items_size += sizeof(struct vm_event_state);
100282 #endif
100283
100284 - v = kmalloc(stat_items_size, GFP_KERNEL);
100285 + v = kzalloc(stat_items_size, GFP_KERNEL);
100286 m->private = v;
100287 if (!v)
100288 return ERR_PTR(-ENOMEM);
100289 +
100290 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100291 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100292 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100293 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100294 + && !in_group_p(grsec_proc_gid)
100295 +#endif
100296 + )
100297 + return (unsigned long *)m->private + *pos;
100298 +#endif
100299 +#endif
100300 +
100301 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100302 v[i] = global_page_state(i);
100303 v += NR_VM_ZONE_STAT_ITEMS;
100304 @@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
100305 cpu_notifier_register_done();
100306 #endif
100307 #ifdef CONFIG_PROC_FS
100308 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100309 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100310 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100311 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100312 + {
100313 + mode_t gr_mode = S_IRUGO;
100314 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100315 + gr_mode = S_IRUSR;
100316 +#endif
100317 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100318 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100319 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100320 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100321 + }
100322 #endif
100323 return 0;
100324 }
100325 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100326 index 64c6bed..b79a5de 100644
100327 --- a/net/8021q/vlan.c
100328 +++ b/net/8021q/vlan.c
100329 @@ -481,7 +481,7 @@ out:
100330 return NOTIFY_DONE;
100331 }
100332
100333 -static struct notifier_block vlan_notifier_block __read_mostly = {
100334 +static struct notifier_block vlan_notifier_block = {
100335 .notifier_call = vlan_device_event,
100336 };
100337
100338 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100339 err = -EPERM;
100340 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100341 break;
100342 - if ((args.u.name_type >= 0) &&
100343 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100344 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100345 struct vlan_net *vn;
100346
100347 vn = net_generic(net, vlan_net_id);
100348 diff --git a/net/9p/client.c b/net/9p/client.c
100349 index e86a9bea..e91f70e 100644
100350 --- a/net/9p/client.c
100351 +++ b/net/9p/client.c
100352 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100353 len - inline_len);
100354 } else {
100355 err = copy_from_user(ename + inline_len,
100356 - uidata, len - inline_len);
100357 + (char __force_user *)uidata, len - inline_len);
100358 if (err) {
100359 err = -EFAULT;
100360 goto out_err;
100361 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100362 kernel_buf = 1;
100363 indata = data;
100364 } else
100365 - indata = (__force char *)udata;
100366 + indata = (__force_kernel char *)udata;
100367 /*
100368 * response header len is 11
100369 * PDU Header(7) + IO Size (4)
100370 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100371 kernel_buf = 1;
100372 odata = data;
100373 } else
100374 - odata = (char *)udata;
100375 + odata = (char __force_kernel *)udata;
100376 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100377 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100378 fid->fid, offset, rsize);
100379 diff --git a/net/9p/mod.c b/net/9p/mod.c
100380 index 6ab36ae..6f1841b 100644
100381 --- a/net/9p/mod.c
100382 +++ b/net/9p/mod.c
100383 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100384 void v9fs_register_trans(struct p9_trans_module *m)
100385 {
100386 spin_lock(&v9fs_trans_lock);
100387 - list_add_tail(&m->list, &v9fs_trans_list);
100388 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100389 spin_unlock(&v9fs_trans_lock);
100390 }
100391 EXPORT_SYMBOL(v9fs_register_trans);
100392 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100393 void v9fs_unregister_trans(struct p9_trans_module *m)
100394 {
100395 spin_lock(&v9fs_trans_lock);
100396 - list_del_init(&m->list);
100397 + pax_list_del_init((struct list_head *)&m->list);
100398 spin_unlock(&v9fs_trans_lock);
100399 }
100400 EXPORT_SYMBOL(v9fs_unregister_trans);
100401 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100402 index 80d08f6..de63fd1 100644
100403 --- a/net/9p/trans_fd.c
100404 +++ b/net/9p/trans_fd.c
100405 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100406 oldfs = get_fs();
100407 set_fs(get_ds());
100408 /* The cast to a user pointer is valid due to the set_fs() */
100409 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100410 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100411 set_fs(oldfs);
100412
100413 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100414 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100415 index af46bc4..f9adfcd 100644
100416 --- a/net/appletalk/atalk_proc.c
100417 +++ b/net/appletalk/atalk_proc.c
100418 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100419 struct proc_dir_entry *p;
100420 int rc = -ENOMEM;
100421
100422 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100423 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100424 if (!atalk_proc_dir)
100425 goto out;
100426
100427 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100428 index 876fbe8..8bbea9f 100644
100429 --- a/net/atm/atm_misc.c
100430 +++ b/net/atm/atm_misc.c
100431 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100432 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100433 return 1;
100434 atm_return(vcc, truesize);
100435 - atomic_inc(&vcc->stats->rx_drop);
100436 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100437 return 0;
100438 }
100439 EXPORT_SYMBOL(atm_charge);
100440 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100441 }
100442 }
100443 atm_return(vcc, guess);
100444 - atomic_inc(&vcc->stats->rx_drop);
100445 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100446 return NULL;
100447 }
100448 EXPORT_SYMBOL(atm_alloc_charge);
100449 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100450
100451 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100452 {
100453 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100454 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100455 __SONET_ITEMS
100456 #undef __HANDLE_ITEM
100457 }
100458 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100459
100460 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100461 {
100462 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100463 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100464 __SONET_ITEMS
100465 #undef __HANDLE_ITEM
100466 }
100467 diff --git a/net/atm/lec.c b/net/atm/lec.c
100468 index 4b98f89..5a2f6cb 100644
100469 --- a/net/atm/lec.c
100470 +++ b/net/atm/lec.c
100471 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100472 }
100473
100474 static struct lane2_ops lane2_ops = {
100475 - lane2_resolve, /* resolve, spec 3.1.3 */
100476 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100477 - NULL /* associate indicator, spec 3.1.5 */
100478 + .resolve = lane2_resolve,
100479 + .associate_req = lane2_associate_req,
100480 + .associate_indicator = NULL
100481 };
100482
100483 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100484 diff --git a/net/atm/lec.h b/net/atm/lec.h
100485 index 4149db1..f2ab682 100644
100486 --- a/net/atm/lec.h
100487 +++ b/net/atm/lec.h
100488 @@ -48,7 +48,7 @@ struct lane2_ops {
100489 const u8 *tlvs, u32 sizeoftlvs);
100490 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100491 const u8 *tlvs, u32 sizeoftlvs);
100492 -};
100493 +} __no_const;
100494
100495 /*
100496 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100497 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100498 index d1b2d9a..d549f7f 100644
100499 --- a/net/atm/mpoa_caches.c
100500 +++ b/net/atm/mpoa_caches.c
100501 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100502
100503
100504 static struct in_cache_ops ingress_ops = {
100505 - in_cache_add_entry, /* add_entry */
100506 - in_cache_get, /* get */
100507 - in_cache_get_with_mask, /* get_with_mask */
100508 - in_cache_get_by_vcc, /* get_by_vcc */
100509 - in_cache_put, /* put */
100510 - in_cache_remove_entry, /* remove_entry */
100511 - cache_hit, /* cache_hit */
100512 - clear_count_and_expired, /* clear_count */
100513 - check_resolving_entries, /* check_resolving */
100514 - refresh_entries, /* refresh */
100515 - in_destroy_cache /* destroy_cache */
100516 + .add_entry = in_cache_add_entry,
100517 + .get = in_cache_get,
100518 + .get_with_mask = in_cache_get_with_mask,
100519 + .get_by_vcc = in_cache_get_by_vcc,
100520 + .put = in_cache_put,
100521 + .remove_entry = in_cache_remove_entry,
100522 + .cache_hit = cache_hit,
100523 + .clear_count = clear_count_and_expired,
100524 + .check_resolving = check_resolving_entries,
100525 + .refresh = refresh_entries,
100526 + .destroy_cache = in_destroy_cache
100527 };
100528
100529 static struct eg_cache_ops egress_ops = {
100530 - eg_cache_add_entry, /* add_entry */
100531 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100532 - eg_cache_get_by_tag, /* get_by_tag */
100533 - eg_cache_get_by_vcc, /* get_by_vcc */
100534 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100535 - eg_cache_put, /* put */
100536 - eg_cache_remove_entry, /* remove_entry */
100537 - update_eg_cache_entry, /* update */
100538 - clear_expired, /* clear_expired */
100539 - eg_destroy_cache /* destroy_cache */
100540 + .add_entry = eg_cache_add_entry,
100541 + .get_by_cache_id = eg_cache_get_by_cache_id,
100542 + .get_by_tag = eg_cache_get_by_tag,
100543 + .get_by_vcc = eg_cache_get_by_vcc,
100544 + .get_by_src_ip = eg_cache_get_by_src_ip,
100545 + .put = eg_cache_put,
100546 + .remove_entry = eg_cache_remove_entry,
100547 + .update = update_eg_cache_entry,
100548 + .clear_expired = clear_expired,
100549 + .destroy_cache = eg_destroy_cache
100550 };
100551
100552
100553 diff --git a/net/atm/proc.c b/net/atm/proc.c
100554 index bbb6461..cf04016 100644
100555 --- a/net/atm/proc.c
100556 +++ b/net/atm/proc.c
100557 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100558 const struct k_atm_aal_stats *stats)
100559 {
100560 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100561 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100562 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100563 - atomic_read(&stats->rx_drop));
100564 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100565 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100566 + atomic_read_unchecked(&stats->rx_drop));
100567 }
100568
100569 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100570 diff --git a/net/atm/resources.c b/net/atm/resources.c
100571 index 0447d5d..3cf4728 100644
100572 --- a/net/atm/resources.c
100573 +++ b/net/atm/resources.c
100574 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100575 static void copy_aal_stats(struct k_atm_aal_stats *from,
100576 struct atm_aal_stats *to)
100577 {
100578 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100579 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100580 __AAL_STAT_ITEMS
100581 #undef __HANDLE_ITEM
100582 }
100583 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100584 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100585 struct atm_aal_stats *to)
100586 {
100587 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100588 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100589 __AAL_STAT_ITEMS
100590 #undef __HANDLE_ITEM
100591 }
100592 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100593 index 919a5ce..cc6b444 100644
100594 --- a/net/ax25/sysctl_net_ax25.c
100595 +++ b/net/ax25/sysctl_net_ax25.c
100596 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100597 {
100598 char path[sizeof("net/ax25/") + IFNAMSIZ];
100599 int k;
100600 - struct ctl_table *table;
100601 + ctl_table_no_const *table;
100602
100603 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100604 if (!table)
100605 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100606 index 1e80539..676c37a 100644
100607 --- a/net/batman-adv/bat_iv_ogm.c
100608 +++ b/net/batman-adv/bat_iv_ogm.c
100609 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100610
100611 /* randomize initial seqno to avoid collision */
100612 get_random_bytes(&random_seqno, sizeof(random_seqno));
100613 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100614 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100615
100616 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100617 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100618 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100619 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100620
100621 /* change sequence number to network order */
100622 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100623 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100624 batadv_ogm_packet->seqno = htonl(seqno);
100625 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100626 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100627
100628 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100629
100630 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100631 return;
100632
100633 /* could be changed by schedule_own_packet() */
100634 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100635 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100636
100637 if (ogm_packet->flags & BATADV_DIRECTLINK)
100638 has_directlink_flag = true;
100639 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100640 index fc1835c..eead856 100644
100641 --- a/net/batman-adv/fragmentation.c
100642 +++ b/net/batman-adv/fragmentation.c
100643 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100644 frag_header.packet_type = BATADV_UNICAST_FRAG;
100645 frag_header.version = BATADV_COMPAT_VERSION;
100646 frag_header.ttl = BATADV_TTL;
100647 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100648 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100649 frag_header.reserved = 0;
100650 frag_header.no = 0;
100651 frag_header.total_size = htons(skb->len);
100652 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100653 index 5467955..30cc771 100644
100654 --- a/net/batman-adv/soft-interface.c
100655 +++ b/net/batman-adv/soft-interface.c
100656 @@ -296,7 +296,7 @@ send:
100657 primary_if->net_dev->dev_addr);
100658
100659 /* set broadcast sequence number */
100660 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100661 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100662 bcast_packet->seqno = htonl(seqno);
100663
100664 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100665 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100666 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100667
100668 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100669 - atomic_set(&bat_priv->bcast_seqno, 1);
100670 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100671 atomic_set(&bat_priv->tt.vn, 0);
100672 atomic_set(&bat_priv->tt.local_changes, 0);
100673 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100674 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100675
100676 /* randomize initial seqno to avoid collision */
100677 get_random_bytes(&random_seqno, sizeof(random_seqno));
100678 - atomic_set(&bat_priv->frag_seqno, random_seqno);
100679 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100680
100681 bat_priv->primary_if = NULL;
100682 bat_priv->num_ifaces = 0;
100683 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100684 index 8854c05..ee5d5497 100644
100685 --- a/net/batman-adv/types.h
100686 +++ b/net/batman-adv/types.h
100687 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100688 struct batadv_hard_iface_bat_iv {
100689 unsigned char *ogm_buff;
100690 int ogm_buff_len;
100691 - atomic_t ogm_seqno;
100692 + atomic_unchecked_t ogm_seqno;
100693 };
100694
100695 /**
100696 @@ -768,7 +768,7 @@ struct batadv_priv {
100697 atomic_t bonding;
100698 atomic_t fragmentation;
100699 atomic_t packet_size_max;
100700 - atomic_t frag_seqno;
100701 + atomic_unchecked_t frag_seqno;
100702 #ifdef CONFIG_BATMAN_ADV_BLA
100703 atomic_t bridge_loop_avoidance;
100704 #endif
100705 @@ -787,7 +787,7 @@ struct batadv_priv {
100706 #endif
100707 uint32_t isolation_mark;
100708 uint32_t isolation_mark_mask;
100709 - atomic_t bcast_seqno;
100710 + atomic_unchecked_t bcast_seqno;
100711 atomic_t bcast_queue_left;
100712 atomic_t batman_queue_left;
100713 char num_ifaces;
100714 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100715 index 115f149..f0ba286 100644
100716 --- a/net/bluetooth/hci_sock.c
100717 +++ b/net/bluetooth/hci_sock.c
100718 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100719 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100720 }
100721
100722 - len = min_t(unsigned int, len, sizeof(uf));
100723 + len = min((size_t)len, sizeof(uf));
100724 if (copy_from_user(&uf, optval, len)) {
100725 err = -EFAULT;
100726 break;
100727 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100728 index 14ca8ae..262d49a 100644
100729 --- a/net/bluetooth/l2cap_core.c
100730 +++ b/net/bluetooth/l2cap_core.c
100731 @@ -3565,8 +3565,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100732 break;
100733
100734 case L2CAP_CONF_RFC:
100735 - if (olen == sizeof(rfc))
100736 - memcpy(&rfc, (void *)val, olen);
100737 + if (olen != sizeof(rfc))
100738 + break;
100739 +
100740 + memcpy(&rfc, (void *)val, olen);
100741
100742 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100743 rfc.mode != chan->mode)
100744 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100745 index 1884f72..b3b71f9 100644
100746 --- a/net/bluetooth/l2cap_sock.c
100747 +++ b/net/bluetooth/l2cap_sock.c
100748 @@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100749 struct sock *sk = sock->sk;
100750 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100751 struct l2cap_options opts;
100752 - int len, err = 0;
100753 + int err = 0;
100754 + size_t len = optlen;
100755 u32 opt;
100756
100757 BT_DBG("sk %p", sk);
100758 @@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100759 opts.max_tx = chan->max_tx;
100760 opts.txwin_size = chan->tx_win;
100761
100762 - len = min_t(unsigned int, sizeof(opts), optlen);
100763 + len = min(sizeof(opts), len);
100764 if (copy_from_user((char *) &opts, optval, len)) {
100765 err = -EFAULT;
100766 break;
100767 @@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100768 struct bt_security sec;
100769 struct bt_power pwr;
100770 struct l2cap_conn *conn;
100771 - int len, err = 0;
100772 + int err = 0;
100773 + size_t len = optlen;
100774 u32 opt;
100775
100776 BT_DBG("sk %p", sk);
100777 @@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100778
100779 sec.level = BT_SECURITY_LOW;
100780
100781 - len = min_t(unsigned int, sizeof(sec), optlen);
100782 + len = min(sizeof(sec), len);
100783 if (copy_from_user((char *) &sec, optval, len)) {
100784 err = -EFAULT;
100785 break;
100786 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100787
100788 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100789
100790 - len = min_t(unsigned int, sizeof(pwr), optlen);
100791 + len = min(sizeof(pwr), len);
100792 if (copy_from_user((char *) &pwr, optval, len)) {
100793 err = -EFAULT;
100794 break;
100795 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100796 index 8bbbb5e..6fc0950 100644
100797 --- a/net/bluetooth/rfcomm/sock.c
100798 +++ b/net/bluetooth/rfcomm/sock.c
100799 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100800 struct sock *sk = sock->sk;
100801 struct bt_security sec;
100802 int err = 0;
100803 - size_t len;
100804 + size_t len = optlen;
100805 u32 opt;
100806
100807 BT_DBG("sk %p", sk);
100808 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100809
100810 sec.level = BT_SECURITY_LOW;
100811
100812 - len = min_t(unsigned int, sizeof(sec), optlen);
100813 + len = min(sizeof(sec), len);
100814 if (copy_from_user((char *) &sec, optval, len)) {
100815 err = -EFAULT;
100816 break;
100817 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
100818 index 8e385a0..a5bdd8e 100644
100819 --- a/net/bluetooth/rfcomm/tty.c
100820 +++ b/net/bluetooth/rfcomm/tty.c
100821 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
100822 BT_DBG("tty %p id %d", tty, tty->index);
100823
100824 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
100825 - dev->channel, dev->port.count);
100826 + dev->channel, atomic_read(&dev->port.count));
100827
100828 err = tty_port_open(&dev->port, tty, filp);
100829 if (err)
100830 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
100831 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
100832
100833 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
100834 - dev->port.count);
100835 + atomic_read(&dev->port.count));
100836
100837 tty_port_close(&dev->port, tty, filp);
100838 }
100839 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
100840 index 6d69631..b8fdc85 100644
100841 --- a/net/bridge/netfilter/ebtables.c
100842 +++ b/net/bridge/netfilter/ebtables.c
100843 @@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100844 tmp.valid_hooks = t->table->valid_hooks;
100845 }
100846 mutex_unlock(&ebt_mutex);
100847 - if (copy_to_user(user, &tmp, *len) != 0) {
100848 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100849 BUGPRINT("c2u Didn't work\n");
100850 ret = -EFAULT;
100851 break;
100852 @@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100853 goto out;
100854 tmp.valid_hooks = t->valid_hooks;
100855
100856 - if (copy_to_user(user, &tmp, *len) != 0) {
100857 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100858 ret = -EFAULT;
100859 break;
100860 }
100861 @@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100862 tmp.entries_size = t->table->entries_size;
100863 tmp.valid_hooks = t->table->valid_hooks;
100864
100865 - if (copy_to_user(user, &tmp, *len) != 0) {
100866 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100867 ret = -EFAULT;
100868 break;
100869 }
100870 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
100871 index f5afda1..dcf770a 100644
100872 --- a/net/caif/cfctrl.c
100873 +++ b/net/caif/cfctrl.c
100874 @@ -10,6 +10,7 @@
100875 #include <linux/spinlock.h>
100876 #include <linux/slab.h>
100877 #include <linux/pkt_sched.h>
100878 +#include <linux/sched.h>
100879 #include <net/caif/caif_layer.h>
100880 #include <net/caif/cfpkt.h>
100881 #include <net/caif/cfctrl.h>
100882 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
100883 memset(&dev_info, 0, sizeof(dev_info));
100884 dev_info.id = 0xff;
100885 cfsrvl_init(&this->serv, 0, &dev_info, false);
100886 - atomic_set(&this->req_seq_no, 1);
100887 - atomic_set(&this->rsp_seq_no, 1);
100888 + atomic_set_unchecked(&this->req_seq_no, 1);
100889 + atomic_set_unchecked(&this->rsp_seq_no, 1);
100890 this->serv.layer.receive = cfctrl_recv;
100891 sprintf(this->serv.layer.name, "ctrl");
100892 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
100893 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
100894 struct cfctrl_request_info *req)
100895 {
100896 spin_lock_bh(&ctrl->info_list_lock);
100897 - atomic_inc(&ctrl->req_seq_no);
100898 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
100899 + atomic_inc_unchecked(&ctrl->req_seq_no);
100900 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
100901 list_add_tail(&req->list, &ctrl->list);
100902 spin_unlock_bh(&ctrl->info_list_lock);
100903 }
100904 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
100905 if (p != first)
100906 pr_warn("Requests are not received in order\n");
100907
100908 - atomic_set(&ctrl->rsp_seq_no,
100909 + atomic_set_unchecked(&ctrl->rsp_seq_no,
100910 p->sequence_no);
100911 list_del(&p->list);
100912 goto out;
100913 diff --git a/net/can/af_can.c b/net/can/af_can.c
100914 index ce82337..5d17b4d 100644
100915 --- a/net/can/af_can.c
100916 +++ b/net/can/af_can.c
100917 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
100918 };
100919
100920 /* notifier block for netdevice event */
100921 -static struct notifier_block can_netdev_notifier __read_mostly = {
100922 +static struct notifier_block can_netdev_notifier = {
100923 .notifier_call = can_notifier,
100924 };
100925
100926 diff --git a/net/can/bcm.c b/net/can/bcm.c
100927 index dcb75c0..24b1b43 100644
100928 --- a/net/can/bcm.c
100929 +++ b/net/can/bcm.c
100930 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
100931 }
100932
100933 /* create /proc/net/can-bcm directory */
100934 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
100935 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
100936 return 0;
100937 }
100938
100939 diff --git a/net/can/gw.c b/net/can/gw.c
100940 index 050a211..bb9fe33 100644
100941 --- a/net/can/gw.c
100942 +++ b/net/can/gw.c
100943 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
100944 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
100945
100946 static HLIST_HEAD(cgw_list);
100947 -static struct notifier_block notifier;
100948
100949 static struct kmem_cache *cgw_cache __read_mostly;
100950
100951 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
100952 return err;
100953 }
100954
100955 +static struct notifier_block notifier = {
100956 + .notifier_call = cgw_notifier
100957 +};
100958 +
100959 static __init int cgw_module_init(void)
100960 {
100961 /* sanitize given module parameter */
100962 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
100963 return -ENOMEM;
100964
100965 /* set notifier */
100966 - notifier.notifier_call = cgw_notifier;
100967 register_netdevice_notifier(&notifier);
100968
100969 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
100970 diff --git a/net/can/proc.c b/net/can/proc.c
100971 index 1a19b98..df2b4ec 100644
100972 --- a/net/can/proc.c
100973 +++ b/net/can/proc.c
100974 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
100975 void can_init_proc(void)
100976 {
100977 /* create /proc/net/can directory */
100978 - can_dir = proc_mkdir("can", init_net.proc_net);
100979 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
100980
100981 if (!can_dir) {
100982 printk(KERN_INFO "can: failed to create /proc/net/can . "
100983 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
100984 index 9f02369..e6160e9 100644
100985 --- a/net/ceph/messenger.c
100986 +++ b/net/ceph/messenger.c
100987 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
100988 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
100989
100990 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
100991 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
100992 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
100993
100994 static struct page *zero_page; /* used in certain error cases */
100995
100996 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
100997 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
100998 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
100999
101000 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101001 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101002 s = addr_str[i];
101003
101004 switch (ss->ss_family) {
101005 diff --git a/net/compat.c b/net/compat.c
101006 index bc8aeef..f9c070c 100644
101007 --- a/net/compat.c
101008 +++ b/net/compat.c
101009 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101010 return -EFAULT;
101011 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101012 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101013 - kmsg->msg_name = compat_ptr(tmp1);
101014 - kmsg->msg_iov = compat_ptr(tmp2);
101015 - kmsg->msg_control = compat_ptr(tmp3);
101016 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101017 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101018 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101019 return 0;
101020 }
101021
101022 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101023
101024 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101025 if (mode == VERIFY_READ) {
101026 - int err = move_addr_to_kernel(kern_msg->msg_name,
101027 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101028 kern_msg->msg_namelen,
101029 kern_address);
101030 if (err < 0)
101031 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101032 }
101033
101034 tot_len = iov_from_user_compat_to_kern(kern_iov,
101035 - (struct compat_iovec __user *)kern_msg->msg_iov,
101036 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101037 kern_msg->msg_iovlen);
101038 if (tot_len >= 0)
101039 kern_msg->msg_iov = kern_iov;
101040 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101041
101042 #define CMSG_COMPAT_FIRSTHDR(msg) \
101043 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101044 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101045 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101046 (struct compat_cmsghdr __user *)NULL)
101047
101048 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101049 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101050 (ucmlen) <= (unsigned long) \
101051 ((mhdr)->msg_controllen - \
101052 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101053 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101054
101055 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101056 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101057 {
101058 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101059 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101060 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101061 msg->msg_controllen)
101062 return NULL;
101063 return (struct compat_cmsghdr __user *)ptr;
101064 @@ -223,7 +223,7 @@ Efault:
101065
101066 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101067 {
101068 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101069 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101070 struct compat_cmsghdr cmhdr;
101071 struct compat_timeval ctv;
101072 struct compat_timespec cts[3];
101073 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101074
101075 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101076 {
101077 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101078 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101079 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101080 int fdnum = scm->fp->count;
101081 struct file **fp = scm->fp->fp;
101082 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101083 return -EFAULT;
101084 old_fs = get_fs();
101085 set_fs(KERNEL_DS);
101086 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101087 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101088 set_fs(old_fs);
101089
101090 return err;
101091 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101092 len = sizeof(ktime);
101093 old_fs = get_fs();
101094 set_fs(KERNEL_DS);
101095 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101096 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101097 set_fs(old_fs);
101098
101099 if (!err) {
101100 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101101 case MCAST_JOIN_GROUP:
101102 case MCAST_LEAVE_GROUP:
101103 {
101104 - struct compat_group_req __user *gr32 = (void *)optval;
101105 + struct compat_group_req __user *gr32 = (void __user *)optval;
101106 struct group_req __user *kgr =
101107 compat_alloc_user_space(sizeof(struct group_req));
101108 u32 interface;
101109 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101110 case MCAST_BLOCK_SOURCE:
101111 case MCAST_UNBLOCK_SOURCE:
101112 {
101113 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101114 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101115 struct group_source_req __user *kgsr = compat_alloc_user_space(
101116 sizeof(struct group_source_req));
101117 u32 interface;
101118 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101119 }
101120 case MCAST_MSFILTER:
101121 {
101122 - struct compat_group_filter __user *gf32 = (void *)optval;
101123 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101124 struct group_filter __user *kgf;
101125 u32 interface, fmode, numsrc;
101126
101127 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101128 char __user *optval, int __user *optlen,
101129 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101130 {
101131 - struct compat_group_filter __user *gf32 = (void *)optval;
101132 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101133 struct group_filter __user *kgf;
101134 int __user *koptlen;
101135 u32 interface, fmode, numsrc;
101136 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101137
101138 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101139 return -EINVAL;
101140 - if (copy_from_user(a, args, nas[call]))
101141 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101142 return -EFAULT;
101143 a0 = a[0];
101144 a1 = a[1];
101145 diff --git a/net/core/datagram.c b/net/core/datagram.c
101146 index fdbc9a8..cd6972c 100644
101147 --- a/net/core/datagram.c
101148 +++ b/net/core/datagram.c
101149 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101150 }
101151
101152 kfree_skb(skb);
101153 - atomic_inc(&sk->sk_drops);
101154 + atomic_inc_unchecked(&sk->sk_drops);
101155 sk_mem_reclaim_partial(sk);
101156
101157 return err;
101158 diff --git a/net/core/dev.c b/net/core/dev.c
101159 index cf8a95f..2837211 100644
101160 --- a/net/core/dev.c
101161 +++ b/net/core/dev.c
101162 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101163 {
101164 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101165 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101166 - atomic_long_inc(&dev->rx_dropped);
101167 + atomic_long_inc_unchecked(&dev->rx_dropped);
101168 kfree_skb(skb);
101169 return NET_RX_DROP;
101170 }
101171 }
101172
101173 if (unlikely(!is_skb_forwardable(dev, skb))) {
101174 - atomic_long_inc(&dev->rx_dropped);
101175 + atomic_long_inc_unchecked(&dev->rx_dropped);
101176 kfree_skb(skb);
101177 return NET_RX_DROP;
101178 }
101179 @@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
101180
101181 struct dev_gso_cb {
101182 void (*destructor)(struct sk_buff *skb);
101183 -};
101184 +} __no_const;
101185
101186 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
101187
101188 @@ -2952,7 +2952,7 @@ recursion_alert:
101189 rc = -ENETDOWN;
101190 rcu_read_unlock_bh();
101191
101192 - atomic_long_inc(&dev->tx_dropped);
101193 + atomic_long_inc_unchecked(&dev->tx_dropped);
101194 kfree_skb(skb);
101195 return rc;
101196 out:
101197 @@ -3296,7 +3296,7 @@ enqueue:
101198
101199 local_irq_restore(flags);
101200
101201 - atomic_long_inc(&skb->dev->rx_dropped);
101202 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101203 kfree_skb(skb);
101204 return NET_RX_DROP;
101205 }
101206 @@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
101207 }
101208 EXPORT_SYMBOL(netif_rx_ni);
101209
101210 -static void net_tx_action(struct softirq_action *h)
101211 +static __latent_entropy void net_tx_action(void)
101212 {
101213 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101214
101215 @@ -3706,7 +3706,7 @@ ncls:
101216 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101217 } else {
101218 drop:
101219 - atomic_long_inc(&skb->dev->rx_dropped);
101220 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101221 kfree_skb(skb);
101222 /* Jamal, now you will not able to escape explaining
101223 * me how you were going to use this. :-)
101224 @@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
101225 }
101226 EXPORT_SYMBOL(netif_napi_del);
101227
101228 -static void net_rx_action(struct softirq_action *h)
101229 +static __latent_entropy void net_rx_action(void)
101230 {
101231 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101232 unsigned long time_limit = jiffies + 2;
101233 @@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101234 } else {
101235 netdev_stats_to_stats64(storage, &dev->stats);
101236 }
101237 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101238 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101239 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101240 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101241 return storage;
101242 }
101243 EXPORT_SYMBOL(dev_get_stats);
101244 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101245 index cf999e0..c59a9754 100644
101246 --- a/net/core/dev_ioctl.c
101247 +++ b/net/core/dev_ioctl.c
101248 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
101249 if (no_module && capable(CAP_NET_ADMIN))
101250 no_module = request_module("netdev-%s", name);
101251 if (no_module && capable(CAP_SYS_MODULE)) {
101252 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101253 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101254 +#else
101255 if (!request_module("%s", name))
101256 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
101257 name);
101258 +#endif
101259 }
101260 }
101261 EXPORT_SYMBOL(dev_load);
101262 diff --git a/net/core/filter.c b/net/core/filter.c
101263 index d814b8a..b5ab778 100644
101264 --- a/net/core/filter.c
101265 +++ b/net/core/filter.c
101266 @@ -559,7 +559,11 @@ do_pass:
101267
101268 /* Unkown instruction. */
101269 default:
101270 - goto err;
101271 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101272 + fp->code, fp->jt, fp->jf, fp->k);
101273 + kfree(addrs);
101274 + BUG();
101275 + return -EINVAL;
101276 }
101277
101278 insn++;
101279 @@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101280 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101281 int pc, ret = 0;
101282
101283 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101284 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101285
101286 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101287 if (!masks)
101288 @@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
101289
101290 /* Expand fp for appending the new filter representation. */
101291 old_fp = fp;
101292 - fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
101293 + fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
101294 if (!fp) {
101295 /* The old_fp is still around in case we couldn't
101296 * allocate new memory, so uncharge on that one.
101297 @@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101298 if (fprog->filter == NULL)
101299 return -EINVAL;
101300
101301 - fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
101302 + fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
101303 if (!fp)
101304 return -ENOMEM;
101305
101306 - memcpy(fp->insns, fprog->filter, fsize);
101307 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101308
101309 fp->len = fprog->len;
101310 /* Since unattached filters are not copied back to user
101311 @@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101312 if (fprog->filter == NULL)
101313 return -EINVAL;
101314
101315 - prog = kmalloc(bpf_fsize, GFP_KERNEL);
101316 + prog = bpf_prog_alloc(bpf_fsize, 0);
101317 if (!prog)
101318 return -ENOMEM;
101319
101320 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
101321 - kfree(prog);
101322 + __bpf_prog_free(prog);
101323 return -EFAULT;
101324 }
101325
101326 @@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101327
101328 err = bpf_prog_store_orig_filter(prog, fprog);
101329 if (err) {
101330 - kfree(prog);
101331 + __bpf_prog_free(prog);
101332 return -ENOMEM;
101333 }
101334
101335 diff --git a/net/core/flow.c b/net/core/flow.c
101336 index a0348fd..6951c76 100644
101337 --- a/net/core/flow.c
101338 +++ b/net/core/flow.c
101339 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101340 static int flow_entry_valid(struct flow_cache_entry *fle,
101341 struct netns_xfrm *xfrm)
101342 {
101343 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101344 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101345 return 0;
101346 if (fle->object && !fle->object->ops->check(fle->object))
101347 return 0;
101348 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101349 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101350 fcp->hash_count++;
101351 }
101352 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101353 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101354 flo = fle->object;
101355 if (!flo)
101356 goto ret_object;
101357 @@ -263,7 +263,7 @@ nocache:
101358 }
101359 flo = resolver(net, key, family, dir, flo, ctx);
101360 if (fle) {
101361 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101362 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101363 if (!IS_ERR(flo))
101364 fle->object = flo;
101365 else
101366 diff --git a/net/core/iovec.c b/net/core/iovec.c
101367 index e1ec45a..e5c6f16 100644
101368 --- a/net/core/iovec.c
101369 +++ b/net/core/iovec.c
101370 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101371 if (m->msg_name && m->msg_namelen) {
101372 if (mode == VERIFY_READ) {
101373 void __user *namep;
101374 - namep = (void __user __force *) m->msg_name;
101375 + namep = (void __force_user *) m->msg_name;
101376 err = move_addr_to_kernel(namep, m->msg_namelen,
101377 address);
101378 if (err < 0)
101379 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101380 }
101381
101382 size = m->msg_iovlen * sizeof(struct iovec);
101383 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101384 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101385 return -EFAULT;
101386
101387 m->msg_iov = iov;
101388 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101389 index ef31fef..8be66d9 100644
101390 --- a/net/core/neighbour.c
101391 +++ b/net/core/neighbour.c
101392 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101393 void __user *buffer, size_t *lenp, loff_t *ppos)
101394 {
101395 int size, ret;
101396 - struct ctl_table tmp = *ctl;
101397 + ctl_table_no_const tmp = *ctl;
101398
101399 tmp.extra1 = &zero;
101400 tmp.extra2 = &unres_qlen_max;
101401 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101402 void __user *buffer,
101403 size_t *lenp, loff_t *ppos)
101404 {
101405 - struct ctl_table tmp = *ctl;
101406 + ctl_table_no_const tmp = *ctl;
101407 int ret;
101408
101409 tmp.extra1 = &zero;
101410 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101411 index 2bf8329..2eb1423 100644
101412 --- a/net/core/net-procfs.c
101413 +++ b/net/core/net-procfs.c
101414 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101415 struct rtnl_link_stats64 temp;
101416 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101417
101418 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101419 + if (gr_proc_is_restricted())
101420 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101421 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101422 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101423 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101424 + else
101425 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101426 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101427 dev->name, stats->rx_bytes, stats->rx_packets,
101428 stats->rx_errors,
101429 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101430 return 0;
101431 }
101432
101433 -static const struct seq_operations dev_seq_ops = {
101434 +const struct seq_operations dev_seq_ops = {
101435 .start = dev_seq_start,
101436 .next = dev_seq_next,
101437 .stop = dev_seq_stop,
101438 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101439
101440 static int softnet_seq_open(struct inode *inode, struct file *file)
101441 {
101442 - return seq_open(file, &softnet_seq_ops);
101443 + return seq_open_restrict(file, &softnet_seq_ops);
101444 }
101445
101446 static const struct file_operations softnet_seq_fops = {
101447 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101448 else
101449 seq_printf(seq, "%04x", ntohs(pt->type));
101450
101451 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101452 + seq_printf(seq, " %-8s %pf\n",
101453 + pt->dev ? pt->dev->name : "", NULL);
101454 +#else
101455 seq_printf(seq, " %-8s %pf\n",
101456 pt->dev ? pt->dev->name : "", pt->func);
101457 +#endif
101458 }
101459
101460 return 0;
101461 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101462 index 9dd0669..c52fb1b 100644
101463 --- a/net/core/net-sysfs.c
101464 +++ b/net/core/net-sysfs.c
101465 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101466 {
101467 struct net_device *netdev = to_net_dev(dev);
101468 return sprintf(buf, fmt_dec,
101469 - atomic_read(&netdev->carrier_changes));
101470 + atomic_read_unchecked(&netdev->carrier_changes));
101471 }
101472 static DEVICE_ATTR_RO(carrier_changes);
101473
101474 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101475 index 7c6b51a..e9dd57f 100644
101476 --- a/net/core/net_namespace.c
101477 +++ b/net/core/net_namespace.c
101478 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101479 int error;
101480 LIST_HEAD(net_exit_list);
101481
101482 - list_add_tail(&ops->list, list);
101483 + pax_list_add_tail((struct list_head *)&ops->list, list);
101484 if (ops->init || (ops->id && ops->size)) {
101485 for_each_net(net) {
101486 error = ops_init(ops, net);
101487 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101488
101489 out_undo:
101490 /* If I have an error cleanup all namespaces I initialized */
101491 - list_del(&ops->list);
101492 + pax_list_del((struct list_head *)&ops->list);
101493 ops_exit_list(ops, &net_exit_list);
101494 ops_free_list(ops, &net_exit_list);
101495 return error;
101496 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101497 struct net *net;
101498 LIST_HEAD(net_exit_list);
101499
101500 - list_del(&ops->list);
101501 + pax_list_del((struct list_head *)&ops->list);
101502 for_each_net(net)
101503 list_add_tail(&net->exit_list, &net_exit_list);
101504 ops_exit_list(ops, &net_exit_list);
101505 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101506 mutex_lock(&net_mutex);
101507 error = register_pernet_operations(&pernet_list, ops);
101508 if (!error && (first_device == &pernet_list))
101509 - first_device = &ops->list;
101510 + first_device = (struct list_head *)&ops->list;
101511 mutex_unlock(&net_mutex);
101512 return error;
101513 }
101514 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101515 index 907fb5e..8260f040b 100644
101516 --- a/net/core/netpoll.c
101517 +++ b/net/core/netpoll.c
101518 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101519 struct udphdr *udph;
101520 struct iphdr *iph;
101521 struct ethhdr *eth;
101522 - static atomic_t ip_ident;
101523 + static atomic_unchecked_t ip_ident;
101524 struct ipv6hdr *ip6h;
101525
101526 udp_len = len + sizeof(*udph);
101527 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101528 put_unaligned(0x45, (unsigned char *)iph);
101529 iph->tos = 0;
101530 put_unaligned(htons(ip_len), &(iph->tot_len));
101531 - iph->id = htons(atomic_inc_return(&ip_ident));
101532 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101533 iph->frag_off = 0;
101534 iph->ttl = 64;
101535 iph->protocol = IPPROTO_UDP;
101536 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101537 index 8b849dd..cd88bfc 100644
101538 --- a/net/core/pktgen.c
101539 +++ b/net/core/pktgen.c
101540 @@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
101541 pn->net = net;
101542 INIT_LIST_HEAD(&pn->pktgen_threads);
101543 pn->pktgen_exiting = false;
101544 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101545 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101546 if (!pn->proc_dir) {
101547 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101548 return -ENODEV;
101549 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101550 index f0493e3..0f43f7a 100644
101551 --- a/net/core/rtnetlink.c
101552 +++ b/net/core/rtnetlink.c
101553 @@ -58,7 +58,7 @@ struct rtnl_link {
101554 rtnl_doit_func doit;
101555 rtnl_dumpit_func dumpit;
101556 rtnl_calcit_func calcit;
101557 -};
101558 +} __no_const;
101559
101560 static DEFINE_MUTEX(rtnl_mutex);
101561
101562 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101563 * to use the ops for creating device. So do not
101564 * fill up dellink as well. That disables rtnl_dellink.
101565 */
101566 - if (ops->setup && !ops->dellink)
101567 - ops->dellink = unregister_netdevice_queue;
101568 + if (ops->setup && !ops->dellink) {
101569 + pax_open_kernel();
101570 + *(void **)&ops->dellink = unregister_netdevice_queue;
101571 + pax_close_kernel();
101572 + }
101573
101574 - list_add_tail(&ops->list, &link_ops);
101575 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101576 return 0;
101577 }
101578 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101579 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101580 for_each_net(net) {
101581 __rtnl_kill_links(net, ops);
101582 }
101583 - list_del(&ops->list);
101584 + pax_list_del((struct list_head *)&ops->list);
101585 }
101586 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101587
101588 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101589 (dev->ifalias &&
101590 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101591 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101592 - atomic_read(&dev->carrier_changes)))
101593 + atomic_read_unchecked(&dev->carrier_changes)))
101594 goto nla_put_failure;
101595
101596 if (1) {
101597 diff --git a/net/core/scm.c b/net/core/scm.c
101598 index b442e7e..6f5b5a2 100644
101599 --- a/net/core/scm.c
101600 +++ b/net/core/scm.c
101601 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101602 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101603 {
101604 struct cmsghdr __user *cm
101605 - = (__force struct cmsghdr __user *)msg->msg_control;
101606 + = (struct cmsghdr __force_user *)msg->msg_control;
101607 struct cmsghdr cmhdr;
101608 int cmlen = CMSG_LEN(len);
101609 int err;
101610 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101611 err = -EFAULT;
101612 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101613 goto out;
101614 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101615 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101616 goto out;
101617 cmlen = CMSG_SPACE(len);
101618 if (msg->msg_controllen < cmlen)
101619 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101620 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101621 {
101622 struct cmsghdr __user *cm
101623 - = (__force struct cmsghdr __user*)msg->msg_control;
101624 + = (struct cmsghdr __force_user *)msg->msg_control;
101625
101626 int fdmax = 0;
101627 int fdnum = scm->fp->count;
101628 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101629 if (fdnum < fdmax)
101630 fdmax = fdnum;
101631
101632 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101633 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101634 i++, cmfptr++)
101635 {
101636 struct socket *sock;
101637 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101638 index 8d28969..4d36260 100644
101639 --- a/net/core/skbuff.c
101640 +++ b/net/core/skbuff.c
101641 @@ -360,18 +360,29 @@ refill:
101642 goto end;
101643 }
101644 nc->frag.size = PAGE_SIZE << order;
101645 -recycle:
101646 - atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
101647 + /* Even if we own the page, we do not use atomic_set().
101648 + * This would break get_page_unless_zero() users.
101649 + */
101650 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
101651 + &nc->frag.page->_count);
101652 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
101653 nc->frag.offset = 0;
101654 }
101655
101656 if (nc->frag.offset + fragsz > nc->frag.size) {
101657 - /* avoid unnecessary locked operations if possible */
101658 - if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
101659 - atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
101660 - goto recycle;
101661 - goto refill;
101662 + if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
101663 + if (!atomic_sub_and_test(nc->pagecnt_bias,
101664 + &nc->frag.page->_count))
101665 + goto refill;
101666 + /* OK, page count is 0, we can safely set it */
101667 + atomic_set(&nc->frag.page->_count,
101668 + NETDEV_PAGECNT_MAX_BIAS);
101669 + } else {
101670 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
101671 + &nc->frag.page->_count);
101672 + }
101673 + nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
101674 + nc->frag.offset = 0;
101675 }
101676
101677 data = page_address(nc->frag.page) + nc->frag.offset;
101678 @@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
101679 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101680 int len, __wsum csum)
101681 {
101682 - const struct skb_checksum_ops ops = {
101683 + static const struct skb_checksum_ops ops = {
101684 .update = csum_partial_ext,
101685 .combine = csum_block_add_ext,
101686 };
101687 @@ -3237,13 +3248,15 @@ void __init skb_init(void)
101688 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101689 sizeof(struct sk_buff),
101690 0,
101691 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101692 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101693 + SLAB_NO_SANITIZE,
101694 NULL);
101695 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101696 (2*sizeof(struct sk_buff)) +
101697 sizeof(atomic_t),
101698 0,
101699 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101700 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101701 + SLAB_NO_SANITIZE,
101702 NULL);
101703 }
101704
101705 diff --git a/net/core/sock.c b/net/core/sock.c
101706 index 9c3f823..bd8c884 100644
101707 --- a/net/core/sock.c
101708 +++ b/net/core/sock.c
101709 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101710 struct sk_buff_head *list = &sk->sk_receive_queue;
101711
101712 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101713 - atomic_inc(&sk->sk_drops);
101714 + atomic_inc_unchecked(&sk->sk_drops);
101715 trace_sock_rcvqueue_full(sk, skb);
101716 return -ENOMEM;
101717 }
101718 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101719 return err;
101720
101721 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101722 - atomic_inc(&sk->sk_drops);
101723 + atomic_inc_unchecked(&sk->sk_drops);
101724 return -ENOBUFS;
101725 }
101726
101727 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101728 skb_dst_force(skb);
101729
101730 spin_lock_irqsave(&list->lock, flags);
101731 - skb->dropcount = atomic_read(&sk->sk_drops);
101732 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101733 __skb_queue_tail(list, skb);
101734 spin_unlock_irqrestore(&list->lock, flags);
101735
101736 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101737 skb->dev = NULL;
101738
101739 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101740 - atomic_inc(&sk->sk_drops);
101741 + atomic_inc_unchecked(&sk->sk_drops);
101742 goto discard_and_relse;
101743 }
101744 if (nested)
101745 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101746 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101747 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101748 bh_unlock_sock(sk);
101749 - atomic_inc(&sk->sk_drops);
101750 + atomic_inc_unchecked(&sk->sk_drops);
101751 goto discard_and_relse;
101752 }
101753
101754 @@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101755 struct timeval tm;
101756 } v;
101757
101758 - int lv = sizeof(int);
101759 - int len;
101760 + unsigned int lv = sizeof(int);
101761 + unsigned int len;
101762
101763 if (get_user(len, optlen))
101764 return -EFAULT;
101765 - if (len < 0)
101766 + if (len > INT_MAX)
101767 return -EINVAL;
101768
101769 memset(&v, 0, sizeof(v));
101770 @@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101771
101772 case SO_PEERNAME:
101773 {
101774 - char address[128];
101775 + char address[_K_SS_MAXSIZE];
101776
101777 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
101778 return -ENOTCONN;
101779 - if (lv < len)
101780 + if (lv < len || sizeof address < len)
101781 return -EINVAL;
101782 if (copy_to_user(optval, address, len))
101783 return -EFAULT;
101784 @@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101785
101786 if (len > lv)
101787 len = lv;
101788 - if (copy_to_user(optval, &v, len))
101789 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
101790 return -EFAULT;
101791 lenout:
101792 if (put_user(len, optlen))
101793 @@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
101794 */
101795 void sock_kfree_s(struct sock *sk, void *mem, int size)
101796 {
101797 + if (WARN_ON_ONCE(!mem))
101798 + return;
101799 kfree(mem);
101800 atomic_sub(size, &sk->sk_omem_alloc);
101801 }
101802 @@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
101803 */
101804 smp_wmb();
101805 atomic_set(&sk->sk_refcnt, 1);
101806 - atomic_set(&sk->sk_drops, 0);
101807 + atomic_set_unchecked(&sk->sk_drops, 0);
101808 }
101809 EXPORT_SYMBOL(sock_init_data);
101810
101811 @@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
101812 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101813 int level, int type)
101814 {
101815 + struct sock_extended_err ee;
101816 struct sock_exterr_skb *serr;
101817 struct sk_buff *skb, *skb2;
101818 int copied, err;
101819 @@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101820 sock_recv_timestamp(msg, sk, skb);
101821
101822 serr = SKB_EXT_ERR(skb);
101823 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
101824 + ee = serr->ee;
101825 + put_cmsg(msg, level, type, sizeof ee, &ee);
101826
101827 msg->msg_flags |= MSG_ERRQUEUE;
101828 err = copied;
101829 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
101830 index ad704c7..ca48aff 100644
101831 --- a/net/core/sock_diag.c
101832 +++ b/net/core/sock_diag.c
101833 @@ -9,26 +9,33 @@
101834 #include <linux/inet_diag.h>
101835 #include <linux/sock_diag.h>
101836
101837 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
101838 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
101839 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
101840 static DEFINE_MUTEX(sock_diag_table_mutex);
101841
101842 int sock_diag_check_cookie(void *sk, __u32 *cookie)
101843 {
101844 +#ifndef CONFIG_GRKERNSEC_HIDESYM
101845 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
101846 cookie[1] != INET_DIAG_NOCOOKIE) &&
101847 ((u32)(unsigned long)sk != cookie[0] ||
101848 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
101849 return -ESTALE;
101850 else
101851 +#endif
101852 return 0;
101853 }
101854 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
101855
101856 void sock_diag_save_cookie(void *sk, __u32 *cookie)
101857 {
101858 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101859 + cookie[0] = 0;
101860 + cookie[1] = 0;
101861 +#else
101862 cookie[0] = (u32)(unsigned long)sk;
101863 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
101864 +#endif
101865 }
101866 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
101867
101868 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
101869 mutex_lock(&sock_diag_table_mutex);
101870 if (sock_diag_handlers[hndl->family])
101871 err = -EBUSY;
101872 - else
101873 + else {
101874 + pax_open_kernel();
101875 sock_diag_handlers[hndl->family] = hndl;
101876 + pax_close_kernel();
101877 + }
101878 mutex_unlock(&sock_diag_table_mutex);
101879
101880 return err;
101881 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
101882
101883 mutex_lock(&sock_diag_table_mutex);
101884 BUG_ON(sock_diag_handlers[family] != hnld);
101885 + pax_open_kernel();
101886 sock_diag_handlers[family] = NULL;
101887 + pax_close_kernel();
101888 mutex_unlock(&sock_diag_table_mutex);
101889 }
101890 EXPORT_SYMBOL_GPL(sock_diag_unregister);
101891 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
101892 index cf9cd13..50683950 100644
101893 --- a/net/core/sysctl_net_core.c
101894 +++ b/net/core/sysctl_net_core.c
101895 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
101896 {
101897 unsigned int orig_size, size;
101898 int ret, i;
101899 - struct ctl_table tmp = {
101900 + ctl_table_no_const tmp = {
101901 .data = &size,
101902 .maxlen = sizeof(size),
101903 .mode = table->mode
101904 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
101905 void __user *buffer, size_t *lenp, loff_t *ppos)
101906 {
101907 char id[IFNAMSIZ];
101908 - struct ctl_table tbl = {
101909 + ctl_table_no_const tbl = {
101910 .data = id,
101911 .maxlen = IFNAMSIZ,
101912 };
101913 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
101914 .mode = 0644,
101915 .proc_handler = proc_dointvec
101916 },
101917 -#ifdef CONFIG_BPF_JIT
101918 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
101919 {
101920 .procname = "bpf_jit_enable",
101921 .data = &bpf_jit_enable,
101922 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
101923
101924 static __net_init int sysctl_core_net_init(struct net *net)
101925 {
101926 - struct ctl_table *tbl;
101927 + ctl_table_no_const *tbl = NULL;
101928
101929 net->core.sysctl_somaxconn = SOMAXCONN;
101930
101931 - tbl = netns_core_table;
101932 if (!net_eq(net, &init_net)) {
101933 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
101934 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
101935 if (tbl == NULL)
101936 goto err_dup;
101937
101938 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
101939 if (net->user_ns != &init_user_ns) {
101940 tbl[0].procname = NULL;
101941 }
101942 - }
101943 -
101944 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101945 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101946 + } else
101947 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
101948 if (net->core.sysctl_hdr == NULL)
101949 goto err_reg;
101950
101951 return 0;
101952
101953 err_reg:
101954 - if (tbl != netns_core_table)
101955 - kfree(tbl);
101956 + kfree(tbl);
101957 err_dup:
101958 return -ENOMEM;
101959 }
101960 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
101961 kfree(tbl);
101962 }
101963
101964 -static __net_initdata struct pernet_operations sysctl_core_ops = {
101965 +static __net_initconst struct pernet_operations sysctl_core_ops = {
101966 .init = sysctl_core_net_init,
101967 .exit = sysctl_core_net_exit,
101968 };
101969 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
101970 index ae011b4..d2d18bf 100644
101971 --- a/net/decnet/af_decnet.c
101972 +++ b/net/decnet/af_decnet.c
101973 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
101974 .sysctl_rmem = sysctl_decnet_rmem,
101975 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
101976 .obj_size = sizeof(struct dn_sock),
101977 + .slab_flags = SLAB_USERCOPY,
101978 };
101979
101980 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
101981 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
101982 index 3b726f3..1af6368 100644
101983 --- a/net/decnet/dn_dev.c
101984 +++ b/net/decnet/dn_dev.c
101985 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
101986 .extra1 = &min_t3,
101987 .extra2 = &max_t3
101988 },
101989 - {0}
101990 + { }
101991 },
101992 };
101993
101994 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
101995 index 5325b54..a0d4d69 100644
101996 --- a/net/decnet/sysctl_net_decnet.c
101997 +++ b/net/decnet/sysctl_net_decnet.c
101998 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
101999
102000 if (len > *lenp) len = *lenp;
102001
102002 - if (copy_to_user(buffer, addr, len))
102003 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102004 return -EFAULT;
102005
102006 *lenp = len;
102007 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102008
102009 if (len > *lenp) len = *lenp;
102010
102011 - if (copy_to_user(buffer, devname, len))
102012 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102013 return -EFAULT;
102014
102015 *lenp = len;
102016 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102017 index 32755cb..236d827 100644
102018 --- a/net/ieee802154/reassembly.c
102019 +++ b/net/ieee802154/reassembly.c
102020 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102021
102022 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102023 {
102024 - struct ctl_table *table;
102025 + ctl_table_no_const *table = NULL;
102026 struct ctl_table_header *hdr;
102027 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102028 net_ieee802154_lowpan(net);
102029
102030 - table = lowpan_frags_ns_ctl_table;
102031 if (!net_eq(net, &init_net)) {
102032 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102033 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102034 GFP_KERNEL);
102035 if (table == NULL)
102036 goto err_alloc;
102037 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102038 /* Don't export sysctls to unprivileged users */
102039 if (net->user_ns != &init_user_ns)
102040 table[0].procname = NULL;
102041 - }
102042 -
102043 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102044 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102045 + } else
102046 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102047 if (hdr == NULL)
102048 goto err_reg;
102049
102050 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102051 return 0;
102052
102053 err_reg:
102054 - if (!net_eq(net, &init_net))
102055 - kfree(table);
102056 + kfree(table);
102057 err_alloc:
102058 return -ENOMEM;
102059 }
102060 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102061 index 214882e..f958b50 100644
102062 --- a/net/ipv4/devinet.c
102063 +++ b/net/ipv4/devinet.c
102064 @@ -1548,7 +1548,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102065 idx = 0;
102066 head = &net->dev_index_head[h];
102067 rcu_read_lock();
102068 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102069 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102070 net->dev_base_seq;
102071 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102072 if (idx < s_idx)
102073 @@ -1866,7 +1866,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102074 idx = 0;
102075 head = &net->dev_index_head[h];
102076 rcu_read_lock();
102077 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102078 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102079 net->dev_base_seq;
102080 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102081 if (idx < s_idx)
102082 @@ -2101,7 +2101,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102083 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102084 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102085
102086 -static struct devinet_sysctl_table {
102087 +static const struct devinet_sysctl_table {
102088 struct ctl_table_header *sysctl_header;
102089 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102090 } devinet_sysctl = {
102091 @@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
102092 int err;
102093 struct ipv4_devconf *all, *dflt;
102094 #ifdef CONFIG_SYSCTL
102095 - struct ctl_table *tbl = ctl_forward_entry;
102096 + ctl_table_no_const *tbl = NULL;
102097 struct ctl_table_header *forw_hdr;
102098 #endif
102099
102100 @@ -2251,7 +2251,7 @@ static __net_init int devinet_init_net(struct net *net)
102101 goto err_alloc_dflt;
102102
102103 #ifdef CONFIG_SYSCTL
102104 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102105 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102106 if (tbl == NULL)
102107 goto err_alloc_ctl;
102108
102109 @@ -2271,7 +2271,10 @@ static __net_init int devinet_init_net(struct net *net)
102110 goto err_reg_dflt;
102111
102112 err = -ENOMEM;
102113 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102114 + if (!net_eq(net, &init_net))
102115 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102116 + else
102117 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102118 if (forw_hdr == NULL)
102119 goto err_reg_ctl;
102120 net->ipv4.forw_hdr = forw_hdr;
102121 @@ -2287,8 +2290,7 @@ err_reg_ctl:
102122 err_reg_dflt:
102123 __devinet_sysctl_unregister(all);
102124 err_reg_all:
102125 - if (tbl != ctl_forward_entry)
102126 - kfree(tbl);
102127 + kfree(tbl);
102128 err_alloc_ctl:
102129 #endif
102130 if (dflt != &ipv4_devconf_dflt)
102131 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102132 index 255aa99..45c78f8 100644
102133 --- a/net/ipv4/fib_frontend.c
102134 +++ b/net/ipv4/fib_frontend.c
102135 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102136 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102137 fib_sync_up(dev);
102138 #endif
102139 - atomic_inc(&net->ipv4.dev_addr_genid);
102140 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102141 rt_cache_flush(dev_net(dev));
102142 break;
102143 case NETDEV_DOWN:
102144 fib_del_ifaddr(ifa, NULL);
102145 - atomic_inc(&net->ipv4.dev_addr_genid);
102146 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102147 if (ifa->ifa_dev->ifa_list == NULL) {
102148 /* Last address was deleted from this interface.
102149 * Disable IP.
102150 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102151 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102152 fib_sync_up(dev);
102153 #endif
102154 - atomic_inc(&net->ipv4.dev_addr_genid);
102155 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102156 rt_cache_flush(net);
102157 break;
102158 case NETDEV_DOWN:
102159 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102160 index 4a74ea8..32335a7 100644
102161 --- a/net/ipv4/fib_semantics.c
102162 +++ b/net/ipv4/fib_semantics.c
102163 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102164 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102165 nh->nh_gw,
102166 nh->nh_parent->fib_scope);
102167 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102168 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102169
102170 return nh->nh_saddr;
102171 }
102172 diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
102173 index dd73bea..a2eec02 100644
102174 --- a/net/ipv4/gre_offload.c
102175 +++ b/net/ipv4/gre_offload.c
102176 @@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
102177 if (csum)
102178 skb->encap_hdr_csum = 1;
102179
102180 - if (unlikely(!pskb_may_pull(skb, ghl)))
102181 - goto out;
102182 -
102183 /* setup inner skb. */
102184 skb->protocol = greh->protocol;
102185 skb->encapsulation = 0;
102186
102187 + if (unlikely(!pskb_may_pull(skb, ghl)))
102188 + goto out;
102189 +
102190 __skb_pull(skb, ghl);
102191 skb_reset_mac_header(skb);
102192 skb_set_network_header(skb, skb_inner_network_offset(skb));
102193 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102194 index 43116e8..ba0916a8 100644
102195 --- a/net/ipv4/inet_hashtables.c
102196 +++ b/net/ipv4/inet_hashtables.c
102197 @@ -18,6 +18,7 @@
102198 #include <linux/sched.h>
102199 #include <linux/slab.h>
102200 #include <linux/wait.h>
102201 +#include <linux/security.h>
102202
102203 #include <net/inet_connection_sock.h>
102204 #include <net/inet_hashtables.h>
102205 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102206 return inet_ehashfn(net, laddr, lport, faddr, fport);
102207 }
102208
102209 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102210 +
102211 /*
102212 * Allocate and initialize a new local port bind bucket.
102213 * The bindhash mutex for snum's hash chain must be held here.
102214 @@ -554,6 +557,8 @@ ok:
102215 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102216 spin_unlock(&head->lock);
102217
102218 + gr_update_task_in_ip_table(inet_sk(sk));
102219 +
102220 if (tw) {
102221 inet_twsk_deschedule(tw, death_row);
102222 while (twrefcnt) {
102223 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102224 index bd5f592..e80e605 100644
102225 --- a/net/ipv4/inetpeer.c
102226 +++ b/net/ipv4/inetpeer.c
102227 @@ -482,7 +482,7 @@ relookup:
102228 if (p) {
102229 p->daddr = *daddr;
102230 atomic_set(&p->refcnt, 1);
102231 - atomic_set(&p->rid, 0);
102232 + atomic_set_unchecked(&p->rid, 0);
102233 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102234 p->rate_tokens = 0;
102235 /* 60*HZ is arbitrary, but chosen enough high so that the first
102236 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102237 index 15f0e2b..8cf8177 100644
102238 --- a/net/ipv4/ip_fragment.c
102239 +++ b/net/ipv4/ip_fragment.c
102240 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102241 return 0;
102242
102243 start = qp->rid;
102244 - end = atomic_inc_return(&peer->rid);
102245 + end = atomic_inc_return_unchecked(&peer->rid);
102246 qp->rid = end;
102247
102248 rc = qp->q.fragments && (end - start) > max;
102249 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102250
102251 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102252 {
102253 - struct ctl_table *table;
102254 + ctl_table_no_const *table = NULL;
102255 struct ctl_table_header *hdr;
102256
102257 - table = ip4_frags_ns_ctl_table;
102258 if (!net_eq(net, &init_net)) {
102259 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102260 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102261 if (table == NULL)
102262 goto err_alloc;
102263
102264 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102265 /* Don't export sysctls to unprivileged users */
102266 if (net->user_ns != &init_user_ns)
102267 table[0].procname = NULL;
102268 - }
102269 + hdr = register_net_sysctl(net, "net/ipv4", table);
102270 + } else
102271 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102272
102273 - hdr = register_net_sysctl(net, "net/ipv4", table);
102274 if (hdr == NULL)
102275 goto err_reg;
102276
102277 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102278 return 0;
102279
102280 err_reg:
102281 - if (!net_eq(net, &init_net))
102282 - kfree(table);
102283 + kfree(table);
102284 err_alloc:
102285 return -ENOMEM;
102286 }
102287 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102288 index 9b84254..c776611 100644
102289 --- a/net/ipv4/ip_gre.c
102290 +++ b/net/ipv4/ip_gre.c
102291 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102292 module_param(log_ecn_error, bool, 0644);
102293 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102294
102295 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102296 +static struct rtnl_link_ops ipgre_link_ops;
102297 static int ipgre_tunnel_init(struct net_device *dev);
102298
102299 static int ipgre_net_id __read_mostly;
102300 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102301 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
102302 };
102303
102304 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102305 +static struct rtnl_link_ops ipgre_link_ops = {
102306 .kind = "gre",
102307 .maxtype = IFLA_GRE_MAX,
102308 .policy = ipgre_policy,
102309 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102310 .fill_info = ipgre_fill_info,
102311 };
102312
102313 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102314 +static struct rtnl_link_ops ipgre_tap_ops = {
102315 .kind = "gretap",
102316 .maxtype = IFLA_GRE_MAX,
102317 .policy = ipgre_policy,
102318 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102319 index 3d4da2c..40f9c29 100644
102320 --- a/net/ipv4/ip_input.c
102321 +++ b/net/ipv4/ip_input.c
102322 @@ -147,6 +147,10 @@
102323 #include <linux/mroute.h>
102324 #include <linux/netlink.h>
102325
102326 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102327 +extern int grsec_enable_blackhole;
102328 +#endif
102329 +
102330 /*
102331 * Process Router Attention IP option (RFC 2113)
102332 */
102333 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102334 if (!raw) {
102335 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102336 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102337 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102338 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102339 +#endif
102340 icmp_send(skb, ICMP_DEST_UNREACH,
102341 ICMP_PROT_UNREACH, 0);
102342 }
102343 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102344 index c43a1e2..73cbbe1 100644
102345 --- a/net/ipv4/ip_output.c
102346 +++ b/net/ipv4/ip_output.c
102347 @@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
102348 */
102349 features = netif_skb_features(skb);
102350 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
102351 - if (IS_ERR(segs)) {
102352 + if (IS_ERR_OR_NULL(segs)) {
102353 kfree_skb(skb);
102354 return -ENOMEM;
102355 }
102356 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102357 index 2407e5d..edc2f1a 100644
102358 --- a/net/ipv4/ip_sockglue.c
102359 +++ b/net/ipv4/ip_sockglue.c
102360 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102361 len = min_t(unsigned int, len, opt->optlen);
102362 if (put_user(len, optlen))
102363 return -EFAULT;
102364 - if (copy_to_user(optval, opt->__data, len))
102365 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102366 + copy_to_user(optval, opt->__data, len))
102367 return -EFAULT;
102368 return 0;
102369 }
102370 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102371 if (sk->sk_type != SOCK_STREAM)
102372 return -ENOPROTOOPT;
102373
102374 - msg.msg_control = (__force void *) optval;
102375 + msg.msg_control = (__force_kernel void *) optval;
102376 msg.msg_controllen = len;
102377 msg.msg_flags = flags;
102378
102379 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102380 index e453cb7..3c8d952 100644
102381 --- a/net/ipv4/ip_vti.c
102382 +++ b/net/ipv4/ip_vti.c
102383 @@ -45,7 +45,7 @@
102384 #include <net/net_namespace.h>
102385 #include <net/netns/generic.h>
102386
102387 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102388 +static struct rtnl_link_ops vti_link_ops;
102389
102390 static int vti_net_id __read_mostly;
102391 static int vti_tunnel_init(struct net_device *dev);
102392 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102393 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102394 };
102395
102396 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102397 +static struct rtnl_link_ops vti_link_ops = {
102398 .kind = "vti",
102399 .maxtype = IFLA_VTI_MAX,
102400 .policy = vti_policy,
102401 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102402 index 5bbef4f..5bc4fb6 100644
102403 --- a/net/ipv4/ipconfig.c
102404 +++ b/net/ipv4/ipconfig.c
102405 @@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102406
102407 mm_segment_t oldfs = get_fs();
102408 set_fs(get_ds());
102409 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102410 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102411 set_fs(oldfs);
102412 return res;
102413 }
102414 @@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102415
102416 mm_segment_t oldfs = get_fs();
102417 set_fs(get_ds());
102418 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102419 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102420 set_fs(oldfs);
102421 return res;
102422 }
102423 @@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102424
102425 mm_segment_t oldfs = get_fs();
102426 set_fs(get_ds());
102427 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102428 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102429 set_fs(oldfs);
102430 return res;
102431 }
102432 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102433 index 62eaa00..29b2dc2 100644
102434 --- a/net/ipv4/ipip.c
102435 +++ b/net/ipv4/ipip.c
102436 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102437 static int ipip_net_id __read_mostly;
102438
102439 static int ipip_tunnel_init(struct net_device *dev);
102440 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102441 +static struct rtnl_link_ops ipip_link_ops;
102442
102443 static int ipip_err(struct sk_buff *skb, u32 info)
102444 {
102445 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102446 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
102447 };
102448
102449 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102450 +static struct rtnl_link_ops ipip_link_ops = {
102451 .kind = "ipip",
102452 .maxtype = IFLA_IPTUN_MAX,
102453 .policy = ipip_policy,
102454 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102455 index f95b6f9..2ee2097 100644
102456 --- a/net/ipv4/netfilter/arp_tables.c
102457 +++ b/net/ipv4/netfilter/arp_tables.c
102458 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102459 #endif
102460
102461 static int get_info(struct net *net, void __user *user,
102462 - const int *len, int compat)
102463 + int len, int compat)
102464 {
102465 char name[XT_TABLE_MAXNAMELEN];
102466 struct xt_table *t;
102467 int ret;
102468
102469 - if (*len != sizeof(struct arpt_getinfo)) {
102470 - duprintf("length %u != %Zu\n", *len,
102471 + if (len != sizeof(struct arpt_getinfo)) {
102472 + duprintf("length %u != %Zu\n", len,
102473 sizeof(struct arpt_getinfo));
102474 return -EINVAL;
102475 }
102476 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102477 info.size = private->size;
102478 strcpy(info.name, name);
102479
102480 - if (copy_to_user(user, &info, *len) != 0)
102481 + if (copy_to_user(user, &info, len) != 0)
102482 ret = -EFAULT;
102483 else
102484 ret = 0;
102485 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102486
102487 switch (cmd) {
102488 case ARPT_SO_GET_INFO:
102489 - ret = get_info(sock_net(sk), user, len, 1);
102490 + ret = get_info(sock_net(sk), user, *len, 1);
102491 break;
102492 case ARPT_SO_GET_ENTRIES:
102493 ret = compat_get_entries(sock_net(sk), user, len);
102494 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102495
102496 switch (cmd) {
102497 case ARPT_SO_GET_INFO:
102498 - ret = get_info(sock_net(sk), user, len, 0);
102499 + ret = get_info(sock_net(sk), user, *len, 0);
102500 break;
102501
102502 case ARPT_SO_GET_ENTRIES:
102503 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102504 index 99e810f..3711b81 100644
102505 --- a/net/ipv4/netfilter/ip_tables.c
102506 +++ b/net/ipv4/netfilter/ip_tables.c
102507 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102508 #endif
102509
102510 static int get_info(struct net *net, void __user *user,
102511 - const int *len, int compat)
102512 + int len, int compat)
102513 {
102514 char name[XT_TABLE_MAXNAMELEN];
102515 struct xt_table *t;
102516 int ret;
102517
102518 - if (*len != sizeof(struct ipt_getinfo)) {
102519 - duprintf("length %u != %zu\n", *len,
102520 + if (len != sizeof(struct ipt_getinfo)) {
102521 + duprintf("length %u != %zu\n", len,
102522 sizeof(struct ipt_getinfo));
102523 return -EINVAL;
102524 }
102525 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102526 info.size = private->size;
102527 strcpy(info.name, name);
102528
102529 - if (copy_to_user(user, &info, *len) != 0)
102530 + if (copy_to_user(user, &info, len) != 0)
102531 ret = -EFAULT;
102532 else
102533 ret = 0;
102534 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102535
102536 switch (cmd) {
102537 case IPT_SO_GET_INFO:
102538 - ret = get_info(sock_net(sk), user, len, 1);
102539 + ret = get_info(sock_net(sk), user, *len, 1);
102540 break;
102541 case IPT_SO_GET_ENTRIES:
102542 ret = compat_get_entries(sock_net(sk), user, len);
102543 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102544
102545 switch (cmd) {
102546 case IPT_SO_GET_INFO:
102547 - ret = get_info(sock_net(sk), user, len, 0);
102548 + ret = get_info(sock_net(sk), user, *len, 0);
102549 break;
102550
102551 case IPT_SO_GET_ENTRIES:
102552 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102553 index 2510c02..cfb34fa 100644
102554 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102555 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102556 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102557 spin_lock_init(&cn->lock);
102558
102559 #ifdef CONFIG_PROC_FS
102560 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102561 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102562 if (!cn->procdir) {
102563 pr_err("Unable to proc dir entry\n");
102564 return -ENOMEM;
102565 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102566 index a3c59a0..ec620a50 100644
102567 --- a/net/ipv4/ping.c
102568 +++ b/net/ipv4/ping.c
102569 @@ -59,7 +59,7 @@ struct ping_table {
102570 };
102571
102572 static struct ping_table ping_table;
102573 -struct pingv6_ops pingv6_ops;
102574 +struct pingv6_ops *pingv6_ops;
102575 EXPORT_SYMBOL_GPL(pingv6_ops);
102576
102577 static u16 ping_port_rover;
102578 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102579 return -ENODEV;
102580 }
102581 }
102582 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102583 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102584 scoped);
102585 rcu_read_unlock();
102586
102587 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102588 }
102589 #if IS_ENABLED(CONFIG_IPV6)
102590 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102591 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102592 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102593 #endif
102594 }
102595
102596 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102597 info, (u8 *)icmph);
102598 #if IS_ENABLED(CONFIG_IPV6)
102599 } else if (family == AF_INET6) {
102600 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102601 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102602 info, (u8 *)icmph);
102603 #endif
102604 }
102605 @@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102606 return ip_recv_error(sk, msg, len, addr_len);
102607 #if IS_ENABLED(CONFIG_IPV6)
102608 } else if (family == AF_INET6) {
102609 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
102610 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
102611 addr_len);
102612 #endif
102613 }
102614 @@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102615 }
102616
102617 if (inet6_sk(sk)->rxopt.all)
102618 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102619 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102620 if (skb->protocol == htons(ETH_P_IPV6) &&
102621 inet6_sk(sk)->rxopt.all)
102622 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102623 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102624 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102625 ip_cmsg_recv(msg, skb);
102626 #endif
102627 @@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102628 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102629 0, sock_i_ino(sp),
102630 atomic_read(&sp->sk_refcnt), sp,
102631 - atomic_read(&sp->sk_drops));
102632 + atomic_read_unchecked(&sp->sk_drops));
102633 }
102634
102635 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102636 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102637 index 739db31..74f0210 100644
102638 --- a/net/ipv4/raw.c
102639 +++ b/net/ipv4/raw.c
102640 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102641 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102642 {
102643 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102644 - atomic_inc(&sk->sk_drops);
102645 + atomic_inc_unchecked(&sk->sk_drops);
102646 kfree_skb(skb);
102647 return NET_RX_DROP;
102648 }
102649 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102650
102651 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102652 {
102653 + struct icmp_filter filter;
102654 +
102655 if (optlen > sizeof(struct icmp_filter))
102656 optlen = sizeof(struct icmp_filter);
102657 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102658 + if (copy_from_user(&filter, optval, optlen))
102659 return -EFAULT;
102660 + raw_sk(sk)->filter = filter;
102661 return 0;
102662 }
102663
102664 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102665 {
102666 int len, ret = -EFAULT;
102667 + struct icmp_filter filter;
102668
102669 if (get_user(len, optlen))
102670 goto out;
102671 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102672 if (len > sizeof(struct icmp_filter))
102673 len = sizeof(struct icmp_filter);
102674 ret = -EFAULT;
102675 - if (put_user(len, optlen) ||
102676 - copy_to_user(optval, &raw_sk(sk)->filter, len))
102677 + filter = raw_sk(sk)->filter;
102678 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102679 goto out;
102680 ret = 0;
102681 out: return ret;
102682 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102683 0, 0L, 0,
102684 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102685 0, sock_i_ino(sp),
102686 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102687 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102688 }
102689
102690 static int raw_seq_show(struct seq_file *seq, void *v)
102691 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102692 index 29836f8..bd1e2ba 100644
102693 --- a/net/ipv4/route.c
102694 +++ b/net/ipv4/route.c
102695 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102696
102697 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102698 {
102699 - return seq_open(file, &rt_cache_seq_ops);
102700 + return seq_open_restrict(file, &rt_cache_seq_ops);
102701 }
102702
102703 static const struct file_operations rt_cache_seq_fops = {
102704 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102705
102706 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102707 {
102708 - return seq_open(file, &rt_cpu_seq_ops);
102709 + return seq_open_restrict(file, &rt_cpu_seq_ops);
102710 }
102711
102712 static const struct file_operations rt_cpu_seq_fops = {
102713 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102714
102715 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102716 {
102717 - return single_open(file, rt_acct_proc_show, NULL);
102718 + return single_open_restrict(file, rt_acct_proc_show, NULL);
102719 }
102720
102721 static const struct file_operations rt_acct_proc_fops = {
102722 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102723
102724 #define IP_IDENTS_SZ 2048u
102725 struct ip_ident_bucket {
102726 - atomic_t id;
102727 + atomic_unchecked_t id;
102728 u32 stamp32;
102729 };
102730
102731 -static struct ip_ident_bucket *ip_idents __read_mostly;
102732 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
102733
102734 /* In order to protect privacy, we add a perturbation to identifiers
102735 * if one generator is seldom used. This makes hard for an attacker
102736 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
102737 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
102738 delta = prandom_u32_max(now - old);
102739
102740 - return atomic_add_return(segs + delta, &bucket->id) - segs;
102741 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
102742 }
102743 EXPORT_SYMBOL(ip_idents_reserve);
102744
102745 @@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
102746 .maxlen = sizeof(int),
102747 .mode = 0200,
102748 .proc_handler = ipv4_sysctl_rtcache_flush,
102749 + .extra1 = &init_net,
102750 },
102751 { },
102752 };
102753
102754 static __net_init int sysctl_route_net_init(struct net *net)
102755 {
102756 - struct ctl_table *tbl;
102757 + ctl_table_no_const *tbl = NULL;
102758
102759 - tbl = ipv4_route_flush_table;
102760 if (!net_eq(net, &init_net)) {
102761 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102762 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102763 if (tbl == NULL)
102764 goto err_dup;
102765
102766 /* Don't export sysctls to unprivileged users */
102767 if (net->user_ns != &init_user_ns)
102768 tbl[0].procname = NULL;
102769 - }
102770 - tbl[0].extra1 = net;
102771 + tbl[0].extra1 = net;
102772 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102773 + } else
102774 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
102775
102776 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102777 if (net->ipv4.route_hdr == NULL)
102778 goto err_reg;
102779 return 0;
102780
102781 err_reg:
102782 - if (tbl != ipv4_route_flush_table)
102783 - kfree(tbl);
102784 + kfree(tbl);
102785 err_dup:
102786 return -ENOMEM;
102787 }
102788 @@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
102789
102790 static __net_init int rt_genid_init(struct net *net)
102791 {
102792 - atomic_set(&net->ipv4.rt_genid, 0);
102793 - atomic_set(&net->fnhe_genid, 0);
102794 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
102795 + atomic_set_unchecked(&net->fnhe_genid, 0);
102796 get_random_bytes(&net->ipv4.dev_addr_genid,
102797 sizeof(net->ipv4.dev_addr_genid));
102798 return 0;
102799 @@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
102800 {
102801 int rc = 0;
102802
102803 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
102804 - if (!ip_idents)
102805 - panic("IP: failed to allocate ip_idents\n");
102806 -
102807 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
102808 + prandom_bytes(ip_idents, sizeof(ip_idents));
102809
102810 #ifdef CONFIG_IP_ROUTE_CLASSID
102811 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
102812 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
102813 index 79a007c..5023029 100644
102814 --- a/net/ipv4/sysctl_net_ipv4.c
102815 +++ b/net/ipv4/sysctl_net_ipv4.c
102816 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
102817 container_of(table->data, struct net, ipv4.ip_local_ports.range);
102818 int ret;
102819 int range[2];
102820 - struct ctl_table tmp = {
102821 + ctl_table_no_const tmp = {
102822 .data = &range,
102823 .maxlen = sizeof(range),
102824 .mode = table->mode,
102825 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
102826 int ret;
102827 gid_t urange[2];
102828 kgid_t low, high;
102829 - struct ctl_table tmp = {
102830 + ctl_table_no_const tmp = {
102831 .data = &urange,
102832 .maxlen = sizeof(urange),
102833 .mode = table->mode,
102834 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
102835 void __user *buffer, size_t *lenp, loff_t *ppos)
102836 {
102837 char val[TCP_CA_NAME_MAX];
102838 - struct ctl_table tbl = {
102839 + ctl_table_no_const tbl = {
102840 .data = val,
102841 .maxlen = TCP_CA_NAME_MAX,
102842 };
102843 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
102844 void __user *buffer, size_t *lenp,
102845 loff_t *ppos)
102846 {
102847 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
102848 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
102849 int ret;
102850
102851 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102852 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
102853 void __user *buffer, size_t *lenp,
102854 loff_t *ppos)
102855 {
102856 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
102857 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
102858 int ret;
102859
102860 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102861 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
102862 void __user *buffer, size_t *lenp,
102863 loff_t *ppos)
102864 {
102865 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102866 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102867 struct tcp_fastopen_context *ctxt;
102868 int ret;
102869 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
102870 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
102871
102872 static __net_init int ipv4_sysctl_init_net(struct net *net)
102873 {
102874 - struct ctl_table *table;
102875 + ctl_table_no_const *table = NULL;
102876
102877 - table = ipv4_net_table;
102878 if (!net_eq(net, &init_net)) {
102879 int i;
102880
102881 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
102882 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
102883 if (table == NULL)
102884 goto err_alloc;
102885
102886 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
102887 table[i].data += (void *)net - (void *)&init_net;
102888 }
102889
102890 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102891 + if (!net_eq(net, &init_net))
102892 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102893 + else
102894 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
102895 if (net->ipv4.ipv4_hdr == NULL)
102896 goto err_reg;
102897
102898 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
102899 index a906e02..f3b6a0f 100644
102900 --- a/net/ipv4/tcp_input.c
102901 +++ b/net/ipv4/tcp_input.c
102902 @@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
102903 * without any lock. We want to make sure compiler wont store
102904 * intermediate values in this location.
102905 */
102906 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
102907 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
102908 sk->sk_max_pacing_rate);
102909 }
102910
102911 @@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
102912 * simplifies code)
102913 */
102914 static void
102915 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102916 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102917 struct sk_buff *head, struct sk_buff *tail,
102918 u32 start, u32 end)
102919 {
102920 @@ -5546,6 +5546,7 @@ discard:
102921 tcp_paws_reject(&tp->rx_opt, 0))
102922 goto discard_and_undo;
102923
102924 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
102925 if (th->syn) {
102926 /* We see SYN without ACK. It is attempt of
102927 * simultaneous connect with crossed SYNs.
102928 @@ -5596,6 +5597,7 @@ discard:
102929 goto discard;
102930 #endif
102931 }
102932 +#endif
102933 /* "fifth, if neither of the SYN or RST bits is set then
102934 * drop the segment and return."
102935 */
102936 @@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
102937 goto discard;
102938
102939 if (th->syn) {
102940 - if (th->fin)
102941 + if (th->fin || th->urg || th->psh)
102942 goto discard;
102943 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
102944 return 1;
102945 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
102946 index 3f49eae..bde687a 100644
102947 --- a/net/ipv4/tcp_ipv4.c
102948 +++ b/net/ipv4/tcp_ipv4.c
102949 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
102950 EXPORT_SYMBOL(sysctl_tcp_low_latency);
102951
102952
102953 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102954 +extern int grsec_enable_blackhole;
102955 +#endif
102956 +
102957 #ifdef CONFIG_TCP_MD5SIG
102958 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
102959 __be32 daddr, __be32 saddr, const struct tcphdr *th);
102960 @@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
102961 return 0;
102962
102963 reset:
102964 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102965 + if (!grsec_enable_blackhole)
102966 +#endif
102967 tcp_v4_send_reset(rsk, skb);
102968 discard:
102969 kfree_skb(skb);
102970 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
102971 TCP_SKB_CB(skb)->sacked = 0;
102972
102973 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
102974 - if (!sk)
102975 + if (!sk) {
102976 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102977 + ret = 1;
102978 +#endif
102979 goto no_tcp_socket;
102980 -
102981 + }
102982 process:
102983 - if (sk->sk_state == TCP_TIME_WAIT)
102984 + if (sk->sk_state == TCP_TIME_WAIT) {
102985 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102986 + ret = 2;
102987 +#endif
102988 goto do_time_wait;
102989 + }
102990
102991 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
102992 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
102993 @@ -1704,6 +1718,10 @@ csum_error:
102994 bad_packet:
102995 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
102996 } else {
102997 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102998 + if (!grsec_enable_blackhole || (ret == 1 &&
102999 + (skb->dev->flags & IFF_LOOPBACK)))
103000 +#endif
103001 tcp_v4_send_reset(NULL, skb);
103002 }
103003
103004 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103005 index 1649988..6251843 100644
103006 --- a/net/ipv4/tcp_minisocks.c
103007 +++ b/net/ipv4/tcp_minisocks.c
103008 @@ -27,6 +27,10 @@
103009 #include <net/inet_common.h>
103010 #include <net/xfrm.h>
103011
103012 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103013 +extern int grsec_enable_blackhole;
103014 +#endif
103015 +
103016 int sysctl_tcp_syncookies __read_mostly = 1;
103017 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103018
103019 @@ -740,7 +744,10 @@ embryonic_reset:
103020 * avoid becoming vulnerable to outside attack aiming at
103021 * resetting legit local connections.
103022 */
103023 - req->rsk_ops->send_reset(sk, skb);
103024 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103025 + if (!grsec_enable_blackhole)
103026 +#endif
103027 + req->rsk_ops->send_reset(sk, skb);
103028 } else if (fastopen) { /* received a valid RST pkt */
103029 reqsk_fastopen_remove(sk, req, true);
103030 tcp_reset(sk);
103031 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103032 index 3b66610..bfbe23a 100644
103033 --- a/net/ipv4/tcp_probe.c
103034 +++ b/net/ipv4/tcp_probe.c
103035 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103036 if (cnt + width >= len)
103037 break;
103038
103039 - if (copy_to_user(buf + cnt, tbuf, width))
103040 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103041 return -EFAULT;
103042 cnt += width;
103043 }
103044 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103045 index df90cd1..9ab2c9b 100644
103046 --- a/net/ipv4/tcp_timer.c
103047 +++ b/net/ipv4/tcp_timer.c
103048 @@ -22,6 +22,10 @@
103049 #include <linux/gfp.h>
103050 #include <net/tcp.h>
103051
103052 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103053 +extern int grsec_lastack_retries;
103054 +#endif
103055 +
103056 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103057 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103058 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103059 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
103060 }
103061 }
103062
103063 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103064 + if ((sk->sk_state == TCP_LAST_ACK) &&
103065 + (grsec_lastack_retries > 0) &&
103066 + (grsec_lastack_retries < retry_until))
103067 + retry_until = grsec_lastack_retries;
103068 +#endif
103069 +
103070 if (retransmits_timed_out(sk, retry_until,
103071 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103072 /* Has it gone just too far? */
103073 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103074 index f57c0e4..cf24bd0 100644
103075 --- a/net/ipv4/udp.c
103076 +++ b/net/ipv4/udp.c
103077 @@ -87,6 +87,7 @@
103078 #include <linux/types.h>
103079 #include <linux/fcntl.h>
103080 #include <linux/module.h>
103081 +#include <linux/security.h>
103082 #include <linux/socket.h>
103083 #include <linux/sockios.h>
103084 #include <linux/igmp.h>
103085 @@ -113,6 +114,10 @@
103086 #include <net/busy_poll.h>
103087 #include "udp_impl.h"
103088
103089 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103090 +extern int grsec_enable_blackhole;
103091 +#endif
103092 +
103093 struct udp_table udp_table __read_mostly;
103094 EXPORT_SYMBOL(udp_table);
103095
103096 @@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103097 return true;
103098 }
103099
103100 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103101 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103102 +
103103 /*
103104 * This routine is called by the ICMP module when it gets some
103105 * sort of error condition. If err < 0 then the socket should
103106 @@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103107 dport = usin->sin_port;
103108 if (dport == 0)
103109 return -EINVAL;
103110 +
103111 + err = gr_search_udp_sendmsg(sk, usin);
103112 + if (err)
103113 + return err;
103114 } else {
103115 if (sk->sk_state != TCP_ESTABLISHED)
103116 return -EDESTADDRREQ;
103117 +
103118 + err = gr_search_udp_sendmsg(sk, NULL);
103119 + if (err)
103120 + return err;
103121 +
103122 daddr = inet->inet_daddr;
103123 dport = inet->inet_dport;
103124 /* Open fast path for connected socket.
103125 @@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
103126 IS_UDPLITE(sk));
103127 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103128 IS_UDPLITE(sk));
103129 - atomic_inc(&sk->sk_drops);
103130 + atomic_inc_unchecked(&sk->sk_drops);
103131 __skb_unlink(skb, rcvq);
103132 __skb_queue_tail(&list_kill, skb);
103133 }
103134 @@ -1261,6 +1278,10 @@ try_again:
103135 if (!skb)
103136 goto out;
103137
103138 + err = gr_search_udp_recvmsg(sk, skb);
103139 + if (err)
103140 + goto out_free;
103141 +
103142 ulen = skb->len - sizeof(struct udphdr);
103143 copied = len;
103144 if (copied > ulen)
103145 @@ -1294,7 +1315,7 @@ try_again:
103146 if (unlikely(err)) {
103147 trace_kfree_skb(skb, udp_recvmsg);
103148 if (!peeked) {
103149 - atomic_inc(&sk->sk_drops);
103150 + atomic_inc_unchecked(&sk->sk_drops);
103151 UDP_INC_STATS_USER(sock_net(sk),
103152 UDP_MIB_INERRORS, is_udplite);
103153 }
103154 @@ -1591,7 +1612,7 @@ csum_error:
103155 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103156 drop:
103157 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103158 - atomic_inc(&sk->sk_drops);
103159 + atomic_inc_unchecked(&sk->sk_drops);
103160 kfree_skb(skb);
103161 return -1;
103162 }
103163 @@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103164 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103165
103166 if (!skb1) {
103167 - atomic_inc(&sk->sk_drops);
103168 + atomic_inc_unchecked(&sk->sk_drops);
103169 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103170 IS_UDPLITE(sk));
103171 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103172 @@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103173 goto csum_error;
103174
103175 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103176 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103177 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103178 +#endif
103179 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103180
103181 /*
103182 @@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103183 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103184 0, sock_i_ino(sp),
103185 atomic_read(&sp->sk_refcnt), sp,
103186 - atomic_read(&sp->sk_drops));
103187 + atomic_read_unchecked(&sp->sk_drops));
103188 }
103189
103190 int udp4_seq_show(struct seq_file *seq, void *v)
103191 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103192 index 6156f68..d6ab46d 100644
103193 --- a/net/ipv4/xfrm4_policy.c
103194 +++ b/net/ipv4/xfrm4_policy.c
103195 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103196 fl4->flowi4_tos = iph->tos;
103197 }
103198
103199 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103200 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103201 {
103202 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103203
103204 - xfrm4_policy_afinfo.garbage_collect(net);
103205 + xfrm_garbage_collect_deferred(net);
103206 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103207 }
103208
103209 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103210
103211 static int __net_init xfrm4_net_init(struct net *net)
103212 {
103213 - struct ctl_table *table;
103214 + ctl_table_no_const *table = NULL;
103215 struct ctl_table_header *hdr;
103216
103217 - table = xfrm4_policy_table;
103218 if (!net_eq(net, &init_net)) {
103219 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103220 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103221 if (!table)
103222 goto err_alloc;
103223
103224 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103225 - }
103226 -
103227 - hdr = register_net_sysctl(net, "net/ipv4", table);
103228 + hdr = register_net_sysctl(net, "net/ipv4", table);
103229 + } else
103230 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103231 if (!hdr)
103232 goto err_reg;
103233
103234 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103235 return 0;
103236
103237 err_reg:
103238 - if (!net_eq(net, &init_net))
103239 - kfree(table);
103240 + kfree(table);
103241 err_alloc:
103242 return -ENOMEM;
103243 }
103244 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103245 index 3e118df..27b16cf 100644
103246 --- a/net/ipv6/addrconf.c
103247 +++ b/net/ipv6/addrconf.c
103248 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103249 idx = 0;
103250 head = &net->dev_index_head[h];
103251 rcu_read_lock();
103252 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103253 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103254 net->dev_base_seq;
103255 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103256 if (idx < s_idx)
103257 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103258 p.iph.ihl = 5;
103259 p.iph.protocol = IPPROTO_IPV6;
103260 p.iph.ttl = 64;
103261 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103262 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103263
103264 if (ops->ndo_do_ioctl) {
103265 mm_segment_t oldfs = get_fs();
103266 @@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
103267 .release = seq_release_net,
103268 };
103269
103270 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103271 +extern void unregister_ipv6_seq_ops_addr(void);
103272 +
103273 static int __net_init if6_proc_net_init(struct net *net)
103274 {
103275 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103276 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103277 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103278 + unregister_ipv6_seq_ops_addr();
103279 return -ENOMEM;
103280 + }
103281 return 0;
103282 }
103283
103284 static void __net_exit if6_proc_net_exit(struct net *net)
103285 {
103286 remove_proc_entry("if_inet6", net->proc_net);
103287 + unregister_ipv6_seq_ops_addr();
103288 }
103289
103290 static struct pernet_operations if6_proc_net_ops = {
103291 @@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103292 s_ip_idx = ip_idx = cb->args[2];
103293
103294 rcu_read_lock();
103295 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103296 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103297 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103298 idx = 0;
103299 head = &net->dev_index_head[h];
103300 @@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103301 rt_genid_bump_ipv6(net);
103302 break;
103303 }
103304 - atomic_inc(&net->ipv6.dev_addr_genid);
103305 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103306 }
103307
103308 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103309 @@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103310 int *valp = ctl->data;
103311 int val = *valp;
103312 loff_t pos = *ppos;
103313 - struct ctl_table lctl;
103314 + ctl_table_no_const lctl;
103315 int ret;
103316
103317 /*
103318 @@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103319 int *valp = ctl->data;
103320 int val = *valp;
103321 loff_t pos = *ppos;
103322 - struct ctl_table lctl;
103323 + ctl_table_no_const lctl;
103324 int ret;
103325
103326 /*
103327 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103328 index 2daa3a1..341066c 100644
103329 --- a/net/ipv6/af_inet6.c
103330 +++ b/net/ipv6/af_inet6.c
103331 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103332 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103333 net->ipv6.sysctl.flowlabel_consistency = 1;
103334 net->ipv6.sysctl.auto_flowlabels = 0;
103335 - atomic_set(&net->ipv6.rt_genid, 0);
103336 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
103337
103338 err = ipv6_init_mibs(net);
103339 if (err)
103340 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103341 index 2753319..b7e625c 100644
103342 --- a/net/ipv6/datagram.c
103343 +++ b/net/ipv6/datagram.c
103344 @@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103345 0,
103346 sock_i_ino(sp),
103347 atomic_read(&sp->sk_refcnt), sp,
103348 - atomic_read(&sp->sk_drops));
103349 + atomic_read_unchecked(&sp->sk_drops));
103350 }
103351 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103352 index 06ba3e5..5c08d38 100644
103353 --- a/net/ipv6/icmp.c
103354 +++ b/net/ipv6/icmp.c
103355 @@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103356
103357 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103358 {
103359 - struct ctl_table *table;
103360 + ctl_table_no_const *table;
103361
103362 table = kmemdup(ipv6_icmp_table_template,
103363 sizeof(ipv6_icmp_table_template),
103364 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103365 index cacb493..3cae894 100644
103366 --- a/net/ipv6/ip6_gre.c
103367 +++ b/net/ipv6/ip6_gre.c
103368 @@ -71,8 +71,8 @@ struct ip6gre_net {
103369 struct net_device *fb_tunnel_dev;
103370 };
103371
103372 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103373 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103374 +static struct rtnl_link_ops ip6gre_link_ops;
103375 +static struct rtnl_link_ops ip6gre_tap_ops;
103376 static int ip6gre_tunnel_init(struct net_device *dev);
103377 static void ip6gre_tunnel_setup(struct net_device *dev);
103378 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103379 @@ -1285,7 +1285,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103380 }
103381
103382
103383 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103384 +static struct inet6_protocol ip6gre_protocol = {
103385 .handler = ip6gre_rcv,
103386 .err_handler = ip6gre_err,
103387 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103388 @@ -1646,7 +1646,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103389 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103390 };
103391
103392 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103393 +static struct rtnl_link_ops ip6gre_link_ops = {
103394 .kind = "ip6gre",
103395 .maxtype = IFLA_GRE_MAX,
103396 .policy = ip6gre_policy,
103397 @@ -1660,7 +1660,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103398 .fill_info = ip6gre_fill_info,
103399 };
103400
103401 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103402 +static struct rtnl_link_ops ip6gre_tap_ops = {
103403 .kind = "ip6gretap",
103404 .maxtype = IFLA_GRE_MAX,
103405 .policy = ip6gre_policy,
103406 diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
103407 index 65eda2a..620a102 100644
103408 --- a/net/ipv6/ip6_offload.c
103409 +++ b/net/ipv6/ip6_offload.c
103410 @@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
103411 if (unlikely(!pskb_may_pull(skb, len)))
103412 break;
103413
103414 + opth = (void *)skb->data;
103415 proto = opth->nexthdr;
103416 __skb_pull(skb, len);
103417 }
103418 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103419 index d2eeb3b..c186e9a 100644
103420 --- a/net/ipv6/ip6_tunnel.c
103421 +++ b/net/ipv6/ip6_tunnel.c
103422 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103423
103424 static int ip6_tnl_dev_init(struct net_device *dev);
103425 static void ip6_tnl_dev_setup(struct net_device *dev);
103426 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103427 +static struct rtnl_link_ops ip6_link_ops;
103428
103429 static int ip6_tnl_net_id __read_mostly;
103430 struct ip6_tnl_net {
103431 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103432 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103433 };
103434
103435 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103436 +static struct rtnl_link_ops ip6_link_ops = {
103437 .kind = "ip6tnl",
103438 .maxtype = IFLA_IPTUN_MAX,
103439 .policy = ip6_tnl_policy,
103440 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103441 index 99c9487..63f4d92 100644
103442 --- a/net/ipv6/ip6_vti.c
103443 +++ b/net/ipv6/ip6_vti.c
103444 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103445
103446 static int vti6_dev_init(struct net_device *dev);
103447 static void vti6_dev_setup(struct net_device *dev);
103448 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103449 +static struct rtnl_link_ops vti6_link_ops;
103450
103451 static int vti6_net_id __read_mostly;
103452 struct vti6_net {
103453 @@ -972,7 +972,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103454 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103455 };
103456
103457 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103458 +static struct rtnl_link_ops vti6_link_ops = {
103459 .kind = "vti6",
103460 .maxtype = IFLA_VTI_MAX,
103461 .policy = vti6_policy,
103462 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103463 index 0c28998..d0a2ecd 100644
103464 --- a/net/ipv6/ipv6_sockglue.c
103465 +++ b/net/ipv6/ipv6_sockglue.c
103466 @@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103467 if (sk->sk_type != SOCK_STREAM)
103468 return -ENOPROTOOPT;
103469
103470 - msg.msg_control = optval;
103471 + msg.msg_control = (void __force_kernel *)optval;
103472 msg.msg_controllen = len;
103473 msg.msg_flags = flags;
103474
103475 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103476 index e080fbb..412b3cf 100644
103477 --- a/net/ipv6/netfilter/ip6_tables.c
103478 +++ b/net/ipv6/netfilter/ip6_tables.c
103479 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103480 #endif
103481
103482 static int get_info(struct net *net, void __user *user,
103483 - const int *len, int compat)
103484 + int len, int compat)
103485 {
103486 char name[XT_TABLE_MAXNAMELEN];
103487 struct xt_table *t;
103488 int ret;
103489
103490 - if (*len != sizeof(struct ip6t_getinfo)) {
103491 - duprintf("length %u != %zu\n", *len,
103492 + if (len != sizeof(struct ip6t_getinfo)) {
103493 + duprintf("length %u != %zu\n", len,
103494 sizeof(struct ip6t_getinfo));
103495 return -EINVAL;
103496 }
103497 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103498 info.size = private->size;
103499 strcpy(info.name, name);
103500
103501 - if (copy_to_user(user, &info, *len) != 0)
103502 + if (copy_to_user(user, &info, len) != 0)
103503 ret = -EFAULT;
103504 else
103505 ret = 0;
103506 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103507
103508 switch (cmd) {
103509 case IP6T_SO_GET_INFO:
103510 - ret = get_info(sock_net(sk), user, len, 1);
103511 + ret = get_info(sock_net(sk), user, *len, 1);
103512 break;
103513 case IP6T_SO_GET_ENTRIES:
103514 ret = compat_get_entries(sock_net(sk), user, len);
103515 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103516
103517 switch (cmd) {
103518 case IP6T_SO_GET_INFO:
103519 - ret = get_info(sock_net(sk), user, len, 0);
103520 + ret = get_info(sock_net(sk), user, *len, 0);
103521 break;
103522
103523 case IP6T_SO_GET_ENTRIES:
103524 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103525 index 6f187c8..34b367f 100644
103526 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103527 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103528 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103529
103530 static int nf_ct_frag6_sysctl_register(struct net *net)
103531 {
103532 - struct ctl_table *table;
103533 + ctl_table_no_const *table = NULL;
103534 struct ctl_table_header *hdr;
103535
103536 - table = nf_ct_frag6_sysctl_table;
103537 if (!net_eq(net, &init_net)) {
103538 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103539 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103540 GFP_KERNEL);
103541 if (table == NULL)
103542 goto err_alloc;
103543 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103544 table[2].data = &net->nf_frag.frags.high_thresh;
103545 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103546 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103547 - }
103548 -
103549 - hdr = register_net_sysctl(net, "net/netfilter", table);
103550 + hdr = register_net_sysctl(net, "net/netfilter", table);
103551 + } else
103552 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103553 if (hdr == NULL)
103554 goto err_reg;
103555
103556 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103557 return 0;
103558
103559 err_reg:
103560 - if (!net_eq(net, &init_net))
103561 - kfree(table);
103562 + kfree(table);
103563 err_alloc:
103564 return -ENOMEM;
103565 }
103566 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103567 index 5b7a1ed..d9da205 100644
103568 --- a/net/ipv6/ping.c
103569 +++ b/net/ipv6/ping.c
103570 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103571 };
103572 #endif
103573
103574 +static struct pingv6_ops real_pingv6_ops = {
103575 + .ipv6_recv_error = ipv6_recv_error,
103576 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103577 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103578 + .icmpv6_err_convert = icmpv6_err_convert,
103579 + .ipv6_icmp_error = ipv6_icmp_error,
103580 + .ipv6_chk_addr = ipv6_chk_addr,
103581 +};
103582 +
103583 +static struct pingv6_ops dummy_pingv6_ops = {
103584 + .ipv6_recv_error = dummy_ipv6_recv_error,
103585 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103586 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103587 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
103588 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
103589 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
103590 +};
103591 +
103592 int __init pingv6_init(void)
103593 {
103594 #ifdef CONFIG_PROC_FS
103595 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
103596 if (ret)
103597 return ret;
103598 #endif
103599 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103600 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103601 - pingv6_ops.ip6_datagram_recv_specific_ctl =
103602 - ip6_datagram_recv_specific_ctl;
103603 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103604 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103605 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103606 + pingv6_ops = &real_pingv6_ops;
103607 return inet6_register_protosw(&pingv6_protosw);
103608 }
103609
103610 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
103611 */
103612 void pingv6_exit(void)
103613 {
103614 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103615 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103616 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103617 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103618 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103619 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103620 #ifdef CONFIG_PROC_FS
103621 unregister_pernet_subsys(&ping_v6_net_ops);
103622 #endif
103623 + pingv6_ops = &dummy_pingv6_ops;
103624 inet6_unregister_protosw(&pingv6_protosw);
103625 }
103626 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103627 index 2d6f860..b0165f5 100644
103628 --- a/net/ipv6/proc.c
103629 +++ b/net/ipv6/proc.c
103630 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103631 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103632 goto proc_snmp6_fail;
103633
103634 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103635 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103636 if (!net->mib.proc_net_devsnmp6)
103637 goto proc_dev_snmp6_fail;
103638 return 0;
103639 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103640 index 39d4422..b0979547 100644
103641 --- a/net/ipv6/raw.c
103642 +++ b/net/ipv6/raw.c
103643 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103644 {
103645 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103646 skb_checksum_complete(skb)) {
103647 - atomic_inc(&sk->sk_drops);
103648 + atomic_inc_unchecked(&sk->sk_drops);
103649 kfree_skb(skb);
103650 return NET_RX_DROP;
103651 }
103652 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103653 struct raw6_sock *rp = raw6_sk(sk);
103654
103655 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103656 - atomic_inc(&sk->sk_drops);
103657 + atomic_inc_unchecked(&sk->sk_drops);
103658 kfree_skb(skb);
103659 return NET_RX_DROP;
103660 }
103661 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103662
103663 if (inet->hdrincl) {
103664 if (skb_checksum_complete(skb)) {
103665 - atomic_inc(&sk->sk_drops);
103666 + atomic_inc_unchecked(&sk->sk_drops);
103667 kfree_skb(skb);
103668 return NET_RX_DROP;
103669 }
103670 @@ -608,7 +608,7 @@ out:
103671 return err;
103672 }
103673
103674 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103675 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103676 struct flowi6 *fl6, struct dst_entry **dstp,
103677 unsigned int flags)
103678 {
103679 @@ -914,12 +914,15 @@ do_confirm:
103680 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103681 char __user *optval, int optlen)
103682 {
103683 + struct icmp6_filter filter;
103684 +
103685 switch (optname) {
103686 case ICMPV6_FILTER:
103687 if (optlen > sizeof(struct icmp6_filter))
103688 optlen = sizeof(struct icmp6_filter);
103689 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103690 + if (copy_from_user(&filter, optval, optlen))
103691 return -EFAULT;
103692 + raw6_sk(sk)->filter = filter;
103693 return 0;
103694 default:
103695 return -ENOPROTOOPT;
103696 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103697 char __user *optval, int __user *optlen)
103698 {
103699 int len;
103700 + struct icmp6_filter filter;
103701
103702 switch (optname) {
103703 case ICMPV6_FILTER:
103704 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103705 len = sizeof(struct icmp6_filter);
103706 if (put_user(len, optlen))
103707 return -EFAULT;
103708 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
103709 + filter = raw6_sk(sk)->filter;
103710 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
103711 return -EFAULT;
103712 return 0;
103713 default:
103714 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
103715 index c6557d9..173e728 100644
103716 --- a/net/ipv6/reassembly.c
103717 +++ b/net/ipv6/reassembly.c
103718 @@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
103719
103720 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103721 {
103722 - struct ctl_table *table;
103723 + ctl_table_no_const *table = NULL;
103724 struct ctl_table_header *hdr;
103725
103726 - table = ip6_frags_ns_ctl_table;
103727 if (!net_eq(net, &init_net)) {
103728 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103729 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103730 if (table == NULL)
103731 goto err_alloc;
103732
103733 @@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103734 /* Don't export sysctls to unprivileged users */
103735 if (net->user_ns != &init_user_ns)
103736 table[0].procname = NULL;
103737 - }
103738 + hdr = register_net_sysctl(net, "net/ipv6", table);
103739 + } else
103740 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
103741
103742 - hdr = register_net_sysctl(net, "net/ipv6", table);
103743 if (hdr == NULL)
103744 goto err_reg;
103745
103746 @@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103747 return 0;
103748
103749 err_reg:
103750 - if (!net_eq(net, &init_net))
103751 - kfree(table);
103752 + kfree(table);
103753 err_alloc:
103754 return -ENOMEM;
103755 }
103756 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
103757 index bafde82..af2c91f 100644
103758 --- a/net/ipv6/route.c
103759 +++ b/net/ipv6/route.c
103760 @@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
103761
103762 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
103763 {
103764 - struct ctl_table *table;
103765 + ctl_table_no_const *table;
103766
103767 table = kmemdup(ipv6_route_table_template,
103768 sizeof(ipv6_route_table_template),
103769 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
103770 index ca1c7c4..37fba59 100644
103771 --- a/net/ipv6/sit.c
103772 +++ b/net/ipv6/sit.c
103773 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
103774 static void ipip6_dev_free(struct net_device *dev);
103775 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
103776 __be32 *v4dst);
103777 -static struct rtnl_link_ops sit_link_ops __read_mostly;
103778 +static struct rtnl_link_ops sit_link_ops;
103779
103780 static int sit_net_id __read_mostly;
103781 struct sit_net {
103782 @@ -484,11 +484,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
103783 */
103784 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
103785 {
103786 - const struct iphdr *iph = (const struct iphdr *) skb->data;
103787 + int ihl = ((const struct iphdr *)skb->data)->ihl*4;
103788 struct rt6_info *rt;
103789 struct sk_buff *skb2;
103790
103791 - if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
103792 + if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
103793 return 1;
103794
103795 skb2 = skb_clone(skb, GFP_ATOMIC);
103796 @@ -497,7 +497,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
103797 return 1;
103798
103799 skb_dst_drop(skb2);
103800 - skb_pull(skb2, iph->ihl * 4);
103801 + skb_pull(skb2, ihl);
103802 skb_reset_network_header(skb2);
103803
103804 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
103805 @@ -1659,7 +1659,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
103806 unregister_netdevice_queue(dev, head);
103807 }
103808
103809 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
103810 +static struct rtnl_link_ops sit_link_ops = {
103811 .kind = "sit",
103812 .maxtype = IFLA_IPTUN_MAX,
103813 .policy = ipip6_policy,
103814 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
103815 index 0c56c93..ece50df 100644
103816 --- a/net/ipv6/sysctl_net_ipv6.c
103817 +++ b/net/ipv6/sysctl_net_ipv6.c
103818 @@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
103819
103820 static int __net_init ipv6_sysctl_net_init(struct net *net)
103821 {
103822 - struct ctl_table *ipv6_table;
103823 + ctl_table_no_const *ipv6_table;
103824 struct ctl_table *ipv6_route_table;
103825 struct ctl_table *ipv6_icmp_table;
103826 int err;
103827 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
103828 index 264c0f2..b6512c6 100644
103829 --- a/net/ipv6/tcp_ipv6.c
103830 +++ b/net/ipv6/tcp_ipv6.c
103831 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
103832 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
103833 }
103834
103835 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103836 +extern int grsec_enable_blackhole;
103837 +#endif
103838 +
103839 static void tcp_v6_hash(struct sock *sk)
103840 {
103841 if (sk->sk_state != TCP_CLOSE) {
103842 @@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
103843 return 0;
103844
103845 reset:
103846 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103847 + if (!grsec_enable_blackhole)
103848 +#endif
103849 tcp_v6_send_reset(sk, skb);
103850 discard:
103851 if (opt_skb)
103852 @@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
103853 TCP_SKB_CB(skb)->sacked = 0;
103854
103855 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103856 - if (!sk)
103857 + if (!sk) {
103858 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103859 + ret = 1;
103860 +#endif
103861 goto no_tcp_socket;
103862 + }
103863
103864 process:
103865 - if (sk->sk_state == TCP_TIME_WAIT)
103866 + if (sk->sk_state == TCP_TIME_WAIT) {
103867 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103868 + ret = 2;
103869 +#endif
103870 goto do_time_wait;
103871 + }
103872
103873 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
103874 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103875 @@ -1479,6 +1494,10 @@ csum_error:
103876 bad_packet:
103877 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103878 } else {
103879 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103880 + if (!grsec_enable_blackhole || (ret == 1 &&
103881 + (skb->dev->flags & IFF_LOOPBACK)))
103882 +#endif
103883 tcp_v6_send_reset(NULL, skb);
103884 }
103885
103886 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
103887 index 4836af8..0e52bbd 100644
103888 --- a/net/ipv6/udp.c
103889 +++ b/net/ipv6/udp.c
103890 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
103891 udp_ipv6_hash_secret + net_hash_mix(net));
103892 }
103893
103894 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103895 +extern int grsec_enable_blackhole;
103896 +#endif
103897 +
103898 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
103899 {
103900 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
103901 @@ -434,7 +438,7 @@ try_again:
103902 if (unlikely(err)) {
103903 trace_kfree_skb(skb, udpv6_recvmsg);
103904 if (!peeked) {
103905 - atomic_inc(&sk->sk_drops);
103906 + atomic_inc_unchecked(&sk->sk_drops);
103907 if (is_udp4)
103908 UDP_INC_STATS_USER(sock_net(sk),
103909 UDP_MIB_INERRORS,
103910 @@ -701,7 +705,7 @@ csum_error:
103911 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103912 drop:
103913 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103914 - atomic_inc(&sk->sk_drops);
103915 + atomic_inc_unchecked(&sk->sk_drops);
103916 kfree_skb(skb);
103917 return -1;
103918 }
103919 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103920 if (likely(skb1 == NULL))
103921 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103922 if (!skb1) {
103923 - atomic_inc(&sk->sk_drops);
103924 + atomic_inc_unchecked(&sk->sk_drops);
103925 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103926 IS_UDPLITE(sk));
103927 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103928 @@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103929 goto csum_error;
103930
103931 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103932 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103933 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103934 +#endif
103935 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
103936
103937 kfree_skb(skb);
103938 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
103939 index 2a0bbda..442240d 100644
103940 --- a/net/ipv6/xfrm6_policy.c
103941 +++ b/net/ipv6/xfrm6_policy.c
103942 @@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103943 case IPPROTO_DCCP:
103944 if (!onlyproto && (nh + offset + 4 < skb->data ||
103945 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
103946 - __be16 *ports = (__be16 *)exthdr;
103947 + __be16 *ports;
103948
103949 + nh = skb_network_header(skb);
103950 + ports = (__be16 *)(nh + offset);
103951 fl6->fl6_sport = ports[!!reverse];
103952 fl6->fl6_dport = ports[!reverse];
103953 }
103954 @@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103955
103956 case IPPROTO_ICMPV6:
103957 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
103958 - u8 *icmp = (u8 *)exthdr;
103959 + u8 *icmp;
103960
103961 + nh = skb_network_header(skb);
103962 + icmp = (u8 *)(nh + offset);
103963 fl6->fl6_icmp_type = icmp[0];
103964 fl6->fl6_icmp_code = icmp[1];
103965 }
103966 @@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103967 case IPPROTO_MH:
103968 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
103969 struct ip6_mh *mh;
103970 - mh = (struct ip6_mh *)exthdr;
103971
103972 + nh = skb_network_header(skb);
103973 + mh = (struct ip6_mh *)(nh + offset);
103974 fl6->fl6_mh_type = mh->ip6mh_type;
103975 }
103976 fl6->flowi6_proto = nexthdr;
103977 @@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103978 }
103979 }
103980
103981 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
103982 +static int xfrm6_garbage_collect(struct dst_ops *ops)
103983 {
103984 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
103985
103986 - xfrm6_policy_afinfo.garbage_collect(net);
103987 + xfrm_garbage_collect_deferred(net);
103988 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
103989 }
103990
103991 @@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
103992
103993 static int __net_init xfrm6_net_init(struct net *net)
103994 {
103995 - struct ctl_table *table;
103996 + ctl_table_no_const *table = NULL;
103997 struct ctl_table_header *hdr;
103998
103999 - table = xfrm6_policy_table;
104000 if (!net_eq(net, &init_net)) {
104001 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104002 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104003 if (!table)
104004 goto err_alloc;
104005
104006 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104007 - }
104008 + hdr = register_net_sysctl(net, "net/ipv6", table);
104009 + } else
104010 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104011
104012 - hdr = register_net_sysctl(net, "net/ipv6", table);
104013 if (!hdr)
104014 goto err_reg;
104015
104016 @@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104017 return 0;
104018
104019 err_reg:
104020 - if (!net_eq(net, &init_net))
104021 - kfree(table);
104022 + kfree(table);
104023 err_alloc:
104024 return -ENOMEM;
104025 }
104026 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104027 index e15c16a..7cf07aa 100644
104028 --- a/net/ipx/ipx_proc.c
104029 +++ b/net/ipx/ipx_proc.c
104030 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104031 struct proc_dir_entry *p;
104032 int rc = -ENOMEM;
104033
104034 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104035 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104036
104037 if (!ipx_proc_dir)
104038 goto out;
104039 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104040 index 61ceb4c..e788eb8 100644
104041 --- a/net/irda/ircomm/ircomm_tty.c
104042 +++ b/net/irda/ircomm/ircomm_tty.c
104043 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104044 add_wait_queue(&port->open_wait, &wait);
104045
104046 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104047 - __FILE__, __LINE__, tty->driver->name, port->count);
104048 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104049
104050 spin_lock_irqsave(&port->lock, flags);
104051 - port->count--;
104052 + atomic_dec(&port->count);
104053 port->blocked_open++;
104054 spin_unlock_irqrestore(&port->lock, flags);
104055
104056 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104057 }
104058
104059 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104060 - __FILE__, __LINE__, tty->driver->name, port->count);
104061 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104062
104063 schedule();
104064 }
104065 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104066
104067 spin_lock_irqsave(&port->lock, flags);
104068 if (!tty_hung_up_p(filp))
104069 - port->count++;
104070 + atomic_inc(&port->count);
104071 port->blocked_open--;
104072 spin_unlock_irqrestore(&port->lock, flags);
104073
104074 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104075 - __FILE__, __LINE__, tty->driver->name, port->count);
104076 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104077
104078 if (!retval)
104079 port->flags |= ASYNC_NORMAL_ACTIVE;
104080 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104081
104082 /* ++ is not atomic, so this should be protected - Jean II */
104083 spin_lock_irqsave(&self->port.lock, flags);
104084 - self->port.count++;
104085 + atomic_inc(&self->port.count);
104086 spin_unlock_irqrestore(&self->port.lock, flags);
104087 tty_port_tty_set(&self->port, tty);
104088
104089 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104090 - self->line, self->port.count);
104091 + self->line, atomic_read(&self->port.count));
104092
104093 /* Not really used by us, but lets do it anyway */
104094 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104095 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104096 tty_kref_put(port->tty);
104097 }
104098 port->tty = NULL;
104099 - port->count = 0;
104100 + atomic_set(&port->count, 0);
104101 spin_unlock_irqrestore(&port->lock, flags);
104102
104103 wake_up_interruptible(&port->open_wait);
104104 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104105 seq_putc(m, '\n');
104106
104107 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104108 - seq_printf(m, "Open count: %d\n", self->port.count);
104109 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104110 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104111 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104112
104113 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104114 index b9ac598..f88cc56 100644
104115 --- a/net/irda/irproc.c
104116 +++ b/net/irda/irproc.c
104117 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104118 {
104119 int i;
104120
104121 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104122 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104123 if (proc_irda == NULL)
104124 return;
104125
104126 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104127 index a089b6b..3ca3b60 100644
104128 --- a/net/iucv/af_iucv.c
104129 +++ b/net/iucv/af_iucv.c
104130 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104131 {
104132 char name[12];
104133
104134 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104135 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104136 while (__iucv_get_sock_by_name(name)) {
104137 sprintf(name, "%08x",
104138 - atomic_inc_return(&iucv_sk_list.autobind_name));
104139 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104140 }
104141 memcpy(iucv->src_name, name, 8);
104142 }
104143 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104144 index da78793..bdd78cf 100644
104145 --- a/net/iucv/iucv.c
104146 +++ b/net/iucv/iucv.c
104147 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104148 return NOTIFY_OK;
104149 }
104150
104151 -static struct notifier_block __refdata iucv_cpu_notifier = {
104152 +static struct notifier_block iucv_cpu_notifier = {
104153 .notifier_call = iucv_cpu_notify,
104154 };
104155
104156 diff --git a/net/key/af_key.c b/net/key/af_key.c
104157 index 1847ec4..26ef732 100644
104158 --- a/net/key/af_key.c
104159 +++ b/net/key/af_key.c
104160 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104161 static u32 get_acqseq(void)
104162 {
104163 u32 res;
104164 - static atomic_t acqseq;
104165 + static atomic_unchecked_t acqseq;
104166
104167 do {
104168 - res = atomic_inc_return(&acqseq);
104169 + res = atomic_inc_return_unchecked(&acqseq);
104170 } while (!res);
104171 return res;
104172 }
104173 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104174 index edb78e6..8dc654a 100644
104175 --- a/net/l2tp/l2tp_eth.c
104176 +++ b/net/l2tp/l2tp_eth.c
104177 @@ -42,12 +42,12 @@ struct l2tp_eth {
104178 struct sock *tunnel_sock;
104179 struct l2tp_session *session;
104180 struct list_head list;
104181 - atomic_long_t tx_bytes;
104182 - atomic_long_t tx_packets;
104183 - atomic_long_t tx_dropped;
104184 - atomic_long_t rx_bytes;
104185 - atomic_long_t rx_packets;
104186 - atomic_long_t rx_errors;
104187 + atomic_long_unchecked_t tx_bytes;
104188 + atomic_long_unchecked_t tx_packets;
104189 + atomic_long_unchecked_t tx_dropped;
104190 + atomic_long_unchecked_t rx_bytes;
104191 + atomic_long_unchecked_t rx_packets;
104192 + atomic_long_unchecked_t rx_errors;
104193 };
104194
104195 /* via l2tp_session_priv() */
104196 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104197 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104198
104199 if (likely(ret == NET_XMIT_SUCCESS)) {
104200 - atomic_long_add(len, &priv->tx_bytes);
104201 - atomic_long_inc(&priv->tx_packets);
104202 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104203 + atomic_long_inc_unchecked(&priv->tx_packets);
104204 } else {
104205 - atomic_long_inc(&priv->tx_dropped);
104206 + atomic_long_inc_unchecked(&priv->tx_dropped);
104207 }
104208 return NETDEV_TX_OK;
104209 }
104210 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104211 {
104212 struct l2tp_eth *priv = netdev_priv(dev);
104213
104214 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104215 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104216 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104217 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104218 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104219 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104220 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104221 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104222 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104223 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104224 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104225 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104226 return stats;
104227 }
104228
104229 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104230 nf_reset(skb);
104231
104232 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104233 - atomic_long_inc(&priv->rx_packets);
104234 - atomic_long_add(data_len, &priv->rx_bytes);
104235 + atomic_long_inc_unchecked(&priv->rx_packets);
104236 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104237 } else {
104238 - atomic_long_inc(&priv->rx_errors);
104239 + atomic_long_inc_unchecked(&priv->rx_errors);
104240 }
104241 return;
104242
104243 error:
104244 - atomic_long_inc(&priv->rx_errors);
104245 + atomic_long_inc_unchecked(&priv->rx_errors);
104246 kfree_skb(skb);
104247 }
104248
104249 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104250 index 1a3c7e0..80f8b0c 100644
104251 --- a/net/llc/llc_proc.c
104252 +++ b/net/llc/llc_proc.c
104253 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104254 int rc = -ENOMEM;
104255 struct proc_dir_entry *p;
104256
104257 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104258 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104259 if (!llc_proc_dir)
104260 goto out;
104261
104262 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104263 index 927b4ea..88a30e2 100644
104264 --- a/net/mac80211/cfg.c
104265 +++ b/net/mac80211/cfg.c
104266 @@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104267 ret = ieee80211_vif_use_channel(sdata, chandef,
104268 IEEE80211_CHANCTX_EXCLUSIVE);
104269 }
104270 - } else if (local->open_count == local->monitors) {
104271 + } else if (local_read(&local->open_count) == local->monitors) {
104272 local->_oper_chandef = *chandef;
104273 ieee80211_hw_config(local, 0);
104274 }
104275 @@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104276 else
104277 local->probe_req_reg--;
104278
104279 - if (!local->open_count)
104280 + if (!local_read(&local->open_count))
104281 break;
104282
104283 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104284 @@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104285 if (chanctx_conf) {
104286 *chandef = chanctx_conf->def;
104287 ret = 0;
104288 - } else if (local->open_count > 0 &&
104289 - local->open_count == local->monitors &&
104290 + } else if (local_read(&local->open_count) > 0 &&
104291 + local_read(&local->open_count) == local->monitors &&
104292 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104293 if (local->use_chanctx)
104294 *chandef = local->monitor_chandef;
104295 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104296 index 5d102b5..6199fca 100644
104297 --- a/net/mac80211/ieee80211_i.h
104298 +++ b/net/mac80211/ieee80211_i.h
104299 @@ -28,6 +28,7 @@
104300 #include <net/ieee80211_radiotap.h>
104301 #include <net/cfg80211.h>
104302 #include <net/mac80211.h>
104303 +#include <asm/local.h>
104304 #include "key.h"
104305 #include "sta_info.h"
104306 #include "debug.h"
104307 @@ -1055,7 +1056,7 @@ struct ieee80211_local {
104308 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104309 spinlock_t queue_stop_reason_lock;
104310
104311 - int open_count;
104312 + local_t open_count;
104313 int monitors, cooked_mntrs;
104314 /* number of interfaces with corresponding FIF_ flags */
104315 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104316 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104317 index 3538e5e..0aa7879 100644
104318 --- a/net/mac80211/iface.c
104319 +++ b/net/mac80211/iface.c
104320 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104321 break;
104322 }
104323
104324 - if (local->open_count == 0) {
104325 + if (local_read(&local->open_count) == 0) {
104326 res = drv_start(local);
104327 if (res)
104328 goto err_del_bss;
104329 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104330 res = drv_add_interface(local, sdata);
104331 if (res)
104332 goto err_stop;
104333 - } else if (local->monitors == 0 && local->open_count == 0) {
104334 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104335 res = ieee80211_add_virtual_monitor(local);
104336 if (res)
104337 goto err_stop;
104338 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104339 atomic_inc(&local->iff_promiscs);
104340
104341 if (coming_up)
104342 - local->open_count++;
104343 + local_inc(&local->open_count);
104344
104345 if (hw_reconf_flags)
104346 ieee80211_hw_config(local, hw_reconf_flags);
104347 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104348 err_del_interface:
104349 drv_remove_interface(local, sdata);
104350 err_stop:
104351 - if (!local->open_count)
104352 + if (!local_read(&local->open_count))
104353 drv_stop(local);
104354 err_del_bss:
104355 sdata->bss = NULL;
104356 @@ -891,7 +891,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104357 }
104358
104359 if (going_down)
104360 - local->open_count--;
104361 + local_dec(&local->open_count);
104362
104363 switch (sdata->vif.type) {
104364 case NL80211_IFTYPE_AP_VLAN:
104365 @@ -952,7 +952,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104366 }
104367 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104368
104369 - if (local->open_count == 0)
104370 + if (local_read(&local->open_count) == 0)
104371 ieee80211_clear_tx_pending(local);
104372
104373 /*
104374 @@ -995,7 +995,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104375 if (cancel_scan)
104376 flush_delayed_work(&local->scan_work);
104377
104378 - if (local->open_count == 0) {
104379 + if (local_read(&local->open_count) == 0) {
104380 ieee80211_stop_device(local);
104381
104382 /* no reconfiguring after stop! */
104383 @@ -1006,7 +1006,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104384 ieee80211_configure_filter(local);
104385 ieee80211_hw_config(local, hw_reconf_flags);
104386
104387 - if (local->monitors == local->open_count)
104388 + if (local->monitors == local_read(&local->open_count))
104389 ieee80211_add_virtual_monitor(local);
104390 }
104391
104392 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104393 index e0ab432..36b7b94 100644
104394 --- a/net/mac80211/main.c
104395 +++ b/net/mac80211/main.c
104396 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104397 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104398 IEEE80211_CONF_CHANGE_POWER);
104399
104400 - if (changed && local->open_count) {
104401 + if (changed && local_read(&local->open_count)) {
104402 ret = drv_config(local, changed);
104403 /*
104404 * Goal:
104405 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104406 index 4c5192e..04cc0d8 100644
104407 --- a/net/mac80211/pm.c
104408 +++ b/net/mac80211/pm.c
104409 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104410 struct ieee80211_sub_if_data *sdata;
104411 struct sta_info *sta;
104412
104413 - if (!local->open_count)
104414 + if (!local_read(&local->open_count))
104415 goto suspend;
104416
104417 ieee80211_scan_cancel(local);
104418 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104419 cancel_work_sync(&local->dynamic_ps_enable_work);
104420 del_timer_sync(&local->dynamic_ps_timer);
104421
104422 - local->wowlan = wowlan && local->open_count;
104423 + local->wowlan = wowlan && local_read(&local->open_count);
104424 if (local->wowlan) {
104425 int err = drv_suspend(local, wowlan);
104426 if (err < 0) {
104427 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104428 WARN_ON(!list_empty(&local->chanctx_list));
104429
104430 /* stop hardware - this must stop RX */
104431 - if (local->open_count)
104432 + if (local_read(&local->open_count))
104433 ieee80211_stop_device(local);
104434
104435 suspend:
104436 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104437 index 6081329..ab23834 100644
104438 --- a/net/mac80211/rate.c
104439 +++ b/net/mac80211/rate.c
104440 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104441
104442 ASSERT_RTNL();
104443
104444 - if (local->open_count)
104445 + if (local_read(&local->open_count))
104446 return -EBUSY;
104447
104448 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104449 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104450 index 725af7a..a21a20a 100644
104451 --- a/net/mac80211/util.c
104452 +++ b/net/mac80211/util.c
104453 @@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104454 }
104455 #endif
104456 /* everything else happens only if HW was up & running */
104457 - if (!local->open_count)
104458 + if (!local_read(&local->open_count))
104459 goto wake_up;
104460
104461 /*
104462 @@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104463 local->in_reconfig = false;
104464 barrier();
104465
104466 - if (local->monitors == local->open_count && local->monitors > 0)
104467 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104468 ieee80211_add_virtual_monitor(local);
104469
104470 /*
104471 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104472 index 6d77cce..36e2fc3 100644
104473 --- a/net/netfilter/Kconfig
104474 +++ b/net/netfilter/Kconfig
104475 @@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
104476
104477 To compile it as a module, choose M here. If unsure, say N.
104478
104479 +config NETFILTER_XT_MATCH_GRADM
104480 + tristate '"gradm" match support'
104481 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104482 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104483 + ---help---
104484 + The gradm match allows to match on grsecurity RBAC being enabled.
104485 + It is useful when iptables rules are applied early on bootup to
104486 + prevent connections to the machine (except from a trusted host)
104487 + while the RBAC system is disabled.
104488 +
104489 config NETFILTER_XT_MATCH_HASHLIMIT
104490 tristate '"hashlimit" match support'
104491 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104492 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104493 index fad5fdb..ba3672a 100644
104494 --- a/net/netfilter/Makefile
104495 +++ b/net/netfilter/Makefile
104496 @@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104497 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104498 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104499 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104500 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104501 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104502 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104503 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104504 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104505 index 6582dce..a911da7 100644
104506 --- a/net/netfilter/ipset/ip_set_core.c
104507 +++ b/net/netfilter/ipset/ip_set_core.c
104508 @@ -1921,7 +1921,7 @@ done:
104509 return ret;
104510 }
104511
104512 -static struct nf_sockopt_ops so_set __read_mostly = {
104513 +static struct nf_sockopt_ops so_set = {
104514 .pf = PF_INET,
104515 .get_optmin = SO_IP_SET,
104516 .get_optmax = SO_IP_SET + 1,
104517 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104518 index 610e19c..08d0c3f 100644
104519 --- a/net/netfilter/ipvs/ip_vs_conn.c
104520 +++ b/net/netfilter/ipvs/ip_vs_conn.c
104521 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104522 /* Increase the refcnt counter of the dest */
104523 ip_vs_dest_hold(dest);
104524
104525 - conn_flags = atomic_read(&dest->conn_flags);
104526 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
104527 if (cp->protocol != IPPROTO_UDP)
104528 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104529 flags = cp->flags;
104530 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
104531
104532 cp->control = NULL;
104533 atomic_set(&cp->n_control, 0);
104534 - atomic_set(&cp->in_pkts, 0);
104535 + atomic_set_unchecked(&cp->in_pkts, 0);
104536
104537 cp->packet_xmit = NULL;
104538 cp->app = NULL;
104539 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104540
104541 /* Don't drop the entry if its number of incoming packets is not
104542 located in [0, 8] */
104543 - i = atomic_read(&cp->in_pkts);
104544 + i = atomic_read_unchecked(&cp->in_pkts);
104545 if (i > 8 || i < 0) return 0;
104546
104547 if (!todrop_rate[i]) return 0;
104548 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104549 index 5c34e8d..0d8eb7f 100644
104550 --- a/net/netfilter/ipvs/ip_vs_core.c
104551 +++ b/net/netfilter/ipvs/ip_vs_core.c
104552 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104553 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104554 /* do not touch skb anymore */
104555
104556 - atomic_inc(&cp->in_pkts);
104557 + atomic_inc_unchecked(&cp->in_pkts);
104558 ip_vs_conn_put(cp);
104559 return ret;
104560 }
104561 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104562 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104563 pkts = sysctl_sync_threshold(ipvs);
104564 else
104565 - pkts = atomic_add_return(1, &cp->in_pkts);
104566 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104567
104568 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104569 ip_vs_sync_conn(net, cp, pkts);
104570 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104571 index fd3f444..ab28fa24 100644
104572 --- a/net/netfilter/ipvs/ip_vs_ctl.c
104573 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
104574 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104575 */
104576 ip_vs_rs_hash(ipvs, dest);
104577 }
104578 - atomic_set(&dest->conn_flags, conn_flags);
104579 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
104580
104581 /* bind the service */
104582 old_svc = rcu_dereference_protected(dest->svc, 1);
104583 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104584 * align with netns init in ip_vs_control_net_init()
104585 */
104586
104587 -static struct ctl_table vs_vars[] = {
104588 +static ctl_table_no_const vs_vars[] __read_only = {
104589 {
104590 .procname = "amemthresh",
104591 .maxlen = sizeof(int),
104592 @@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104593 " %-7s %-6d %-10d %-10d\n",
104594 &dest->addr.in6,
104595 ntohs(dest->port),
104596 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104597 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104598 atomic_read(&dest->weight),
104599 atomic_read(&dest->activeconns),
104600 atomic_read(&dest->inactconns));
104601 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104602 "%-7s %-6d %-10d %-10d\n",
104603 ntohl(dest->addr.ip),
104604 ntohs(dest->port),
104605 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104606 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104607 atomic_read(&dest->weight),
104608 atomic_read(&dest->activeconns),
104609 atomic_read(&dest->inactconns));
104610 @@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104611
104612 entry.addr = dest->addr.ip;
104613 entry.port = dest->port;
104614 - entry.conn_flags = atomic_read(&dest->conn_flags);
104615 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104616 entry.weight = atomic_read(&dest->weight);
104617 entry.u_threshold = dest->u_threshold;
104618 entry.l_threshold = dest->l_threshold;
104619 @@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104620 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104621 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104622 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104623 - (atomic_read(&dest->conn_flags) &
104624 + (atomic_read_unchecked(&dest->conn_flags) &
104625 IP_VS_CONN_F_FWD_MASK)) ||
104626 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104627 atomic_read(&dest->weight)) ||
104628 @@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104629 {
104630 int idx;
104631 struct netns_ipvs *ipvs = net_ipvs(net);
104632 - struct ctl_table *tbl;
104633 + ctl_table_no_const *tbl;
104634
104635 atomic_set(&ipvs->dropentry, 0);
104636 spin_lock_init(&ipvs->dropentry_lock);
104637 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104638 index 547ff33..c8c8117 100644
104639 --- a/net/netfilter/ipvs/ip_vs_lblc.c
104640 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
104641 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104642 * IPVS LBLC sysctl table
104643 */
104644 #ifdef CONFIG_SYSCTL
104645 -static struct ctl_table vs_vars_table[] = {
104646 +static ctl_table_no_const vs_vars_table[] __read_only = {
104647 {
104648 .procname = "lblc_expiration",
104649 .data = NULL,
104650 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104651 index 3f21a2f..a112e85 100644
104652 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
104653 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104654 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104655 * IPVS LBLCR sysctl table
104656 */
104657
104658 -static struct ctl_table vs_vars_table[] = {
104659 +static ctl_table_no_const vs_vars_table[] __read_only = {
104660 {
104661 .procname = "lblcr_expiration",
104662 .data = NULL,
104663 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104664 index eadffb2..c2feeae 100644
104665 --- a/net/netfilter/ipvs/ip_vs_sync.c
104666 +++ b/net/netfilter/ipvs/ip_vs_sync.c
104667 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104668 cp = cp->control;
104669 if (cp) {
104670 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104671 - pkts = atomic_add_return(1, &cp->in_pkts);
104672 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104673 else
104674 pkts = sysctl_sync_threshold(ipvs);
104675 ip_vs_sync_conn(net, cp->control, pkts);
104676 @@ -771,7 +771,7 @@ control:
104677 if (!cp)
104678 return;
104679 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104680 - pkts = atomic_add_return(1, &cp->in_pkts);
104681 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104682 else
104683 pkts = sysctl_sync_threshold(ipvs);
104684 goto sloop;
104685 @@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104686
104687 if (opt)
104688 memcpy(&cp->in_seq, opt, sizeof(*opt));
104689 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104690 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104691 cp->state = state;
104692 cp->old_state = cp->state;
104693 /*
104694 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104695 index 56896a4..dfe3806 100644
104696 --- a/net/netfilter/ipvs/ip_vs_xmit.c
104697 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
104698 @@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104699 else
104700 rc = NF_ACCEPT;
104701 /* do not touch skb anymore */
104702 - atomic_inc(&cp->in_pkts);
104703 + atomic_inc_unchecked(&cp->in_pkts);
104704 goto out;
104705 }
104706
104707 @@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104708 else
104709 rc = NF_ACCEPT;
104710 /* do not touch skb anymore */
104711 - atomic_inc(&cp->in_pkts);
104712 + atomic_inc_unchecked(&cp->in_pkts);
104713 goto out;
104714 }
104715
104716 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
104717 index a4b5e2a..13b1de3 100644
104718 --- a/net/netfilter/nf_conntrack_acct.c
104719 +++ b/net/netfilter/nf_conntrack_acct.c
104720 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
104721 #ifdef CONFIG_SYSCTL
104722 static int nf_conntrack_acct_init_sysctl(struct net *net)
104723 {
104724 - struct ctl_table *table;
104725 + ctl_table_no_const *table;
104726
104727 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
104728 GFP_KERNEL);
104729 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
104730 index de88c4a..ec84234 100644
104731 --- a/net/netfilter/nf_conntrack_core.c
104732 +++ b/net/netfilter/nf_conntrack_core.c
104733 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
104734 #define DYING_NULLS_VAL ((1<<30)+1)
104735 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
104736
104737 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104738 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
104739 +#endif
104740 +
104741 int nf_conntrack_init_net(struct net *net)
104742 {
104743 int ret = -ENOMEM;
104744 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
104745 if (!net->ct.stat)
104746 goto err_pcpu_lists;
104747
104748 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104749 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
104750 +#else
104751 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
104752 +#endif
104753 if (!net->ct.slabname)
104754 goto err_slabname;
104755
104756 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
104757 index 4e78c57..ec8fb74 100644
104758 --- a/net/netfilter/nf_conntrack_ecache.c
104759 +++ b/net/netfilter/nf_conntrack_ecache.c
104760 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
104761 #ifdef CONFIG_SYSCTL
104762 static int nf_conntrack_event_init_sysctl(struct net *net)
104763 {
104764 - struct ctl_table *table;
104765 + ctl_table_no_const *table;
104766
104767 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
104768 GFP_KERNEL);
104769 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
104770 index 5b3eae7..dd4b8fe 100644
104771 --- a/net/netfilter/nf_conntrack_helper.c
104772 +++ b/net/netfilter/nf_conntrack_helper.c
104773 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
104774
104775 static int nf_conntrack_helper_init_sysctl(struct net *net)
104776 {
104777 - struct ctl_table *table;
104778 + ctl_table_no_const *table;
104779
104780 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
104781 GFP_KERNEL);
104782 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
104783 index b65d586..beec902 100644
104784 --- a/net/netfilter/nf_conntrack_proto.c
104785 +++ b/net/netfilter/nf_conntrack_proto.c
104786 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
104787
104788 static void
104789 nf_ct_unregister_sysctl(struct ctl_table_header **header,
104790 - struct ctl_table **table,
104791 + ctl_table_no_const **table,
104792 unsigned int users)
104793 {
104794 if (users > 0)
104795 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
104796 index f641751..d3c5b51 100644
104797 --- a/net/netfilter/nf_conntrack_standalone.c
104798 +++ b/net/netfilter/nf_conntrack_standalone.c
104799 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
104800
104801 static int nf_conntrack_standalone_init_sysctl(struct net *net)
104802 {
104803 - struct ctl_table *table;
104804 + ctl_table_no_const *table;
104805
104806 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
104807 GFP_KERNEL);
104808 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
104809 index 7a394df..bd91a8a 100644
104810 --- a/net/netfilter/nf_conntrack_timestamp.c
104811 +++ b/net/netfilter/nf_conntrack_timestamp.c
104812 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
104813 #ifdef CONFIG_SYSCTL
104814 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
104815 {
104816 - struct ctl_table *table;
104817 + ctl_table_no_const *table;
104818
104819 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
104820 GFP_KERNEL);
104821 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
104822 index daad602..384be13 100644
104823 --- a/net/netfilter/nf_log.c
104824 +++ b/net/netfilter/nf_log.c
104825 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
104826
104827 #ifdef CONFIG_SYSCTL
104828 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
104829 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
104830 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
104831
104832 static int nf_log_proc_dostring(struct ctl_table *table, int write,
104833 void __user *buffer, size_t *lenp, loff_t *ppos)
104834 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
104835 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
104836 mutex_unlock(&nf_log_mutex);
104837 } else {
104838 + ctl_table_no_const nf_log_table = *table;
104839 +
104840 mutex_lock(&nf_log_mutex);
104841 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
104842 lockdep_is_held(&nf_log_mutex));
104843 if (!logger)
104844 - table->data = "NONE";
104845 + nf_log_table.data = "NONE";
104846 else
104847 - table->data = logger->name;
104848 - r = proc_dostring(table, write, buffer, lenp, ppos);
104849 + nf_log_table.data = logger->name;
104850 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
104851 mutex_unlock(&nf_log_mutex);
104852 }
104853
104854 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
104855 index c68c1e5..8b5d670 100644
104856 --- a/net/netfilter/nf_sockopt.c
104857 +++ b/net/netfilter/nf_sockopt.c
104858 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
104859 }
104860 }
104861
104862 - list_add(&reg->list, &nf_sockopts);
104863 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
104864 out:
104865 mutex_unlock(&nf_sockopt_mutex);
104866 return ret;
104867 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
104868 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
104869 {
104870 mutex_lock(&nf_sockopt_mutex);
104871 - list_del(&reg->list);
104872 + pax_list_del((struct list_head *)&reg->list);
104873 mutex_unlock(&nf_sockopt_mutex);
104874 }
104875 EXPORT_SYMBOL(nf_unregister_sockopt);
104876 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
104877 index 3250735..1fac969 100644
104878 --- a/net/netfilter/nfnetlink_log.c
104879 +++ b/net/netfilter/nfnetlink_log.c
104880 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
104881 struct nfnl_log_net {
104882 spinlock_t instances_lock;
104883 struct hlist_head instance_table[INSTANCE_BUCKETS];
104884 - atomic_t global_seq;
104885 + atomic_unchecked_t global_seq;
104886 };
104887
104888 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
104889 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
104890 /* global sequence number */
104891 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
104892 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
104893 - htonl(atomic_inc_return(&log->global_seq))))
104894 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
104895 goto nla_put_failure;
104896
104897 if (data_len) {
104898 diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
104899 index 108120f..5b169db 100644
104900 --- a/net/netfilter/nfnetlink_queue_core.c
104901 +++ b/net/netfilter/nfnetlink_queue_core.c
104902 @@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
104903 * returned by nf_queue. For instance, callers rely on -ECANCELED to
104904 * mean 'ignore this hook'.
104905 */
104906 - if (IS_ERR(segs))
104907 + if (IS_ERR_OR_NULL(segs))
104908 goto out_err;
104909 queued = 0;
104910 err = 0;
104911 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
104912 index 5b5ab9e..fc1015c 100644
104913 --- a/net/netfilter/nft_compat.c
104914 +++ b/net/netfilter/nft_compat.c
104915 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
104916 /* We want to reuse existing compat_to_user */
104917 old_fs = get_fs();
104918 set_fs(KERNEL_DS);
104919 - t->compat_to_user(out, in);
104920 + t->compat_to_user((void __force_user *)out, in);
104921 set_fs(old_fs);
104922 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
104923 kfree(out);
104924 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
104925 /* We want to reuse existing compat_to_user */
104926 old_fs = get_fs();
104927 set_fs(KERNEL_DS);
104928 - m->compat_to_user(out, in);
104929 + m->compat_to_user((void __force_user *)out, in);
104930 set_fs(old_fs);
104931 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
104932 kfree(out);
104933 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
104934 new file mode 100644
104935 index 0000000..c566332
104936 --- /dev/null
104937 +++ b/net/netfilter/xt_gradm.c
104938 @@ -0,0 +1,51 @@
104939 +/*
104940 + * gradm match for netfilter
104941 + * Copyright © Zbigniew Krzystolik, 2010
104942 + *
104943 + * This program is free software; you can redistribute it and/or modify
104944 + * it under the terms of the GNU General Public License; either version
104945 + * 2 or 3 as published by the Free Software Foundation.
104946 + */
104947 +#include <linux/module.h>
104948 +#include <linux/moduleparam.h>
104949 +#include <linux/skbuff.h>
104950 +#include <linux/netfilter/x_tables.h>
104951 +#include <linux/grsecurity.h>
104952 +#include <linux/netfilter/xt_gradm.h>
104953 +
104954 +static bool
104955 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
104956 +{
104957 + const struct xt_gradm_mtinfo *info = par->matchinfo;
104958 + bool retval = false;
104959 + if (gr_acl_is_enabled())
104960 + retval = true;
104961 + return retval ^ info->invflags;
104962 +}
104963 +
104964 +static struct xt_match gradm_mt_reg __read_mostly = {
104965 + .name = "gradm",
104966 + .revision = 0,
104967 + .family = NFPROTO_UNSPEC,
104968 + .match = gradm_mt,
104969 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
104970 + .me = THIS_MODULE,
104971 +};
104972 +
104973 +static int __init gradm_mt_init(void)
104974 +{
104975 + return xt_register_match(&gradm_mt_reg);
104976 +}
104977 +
104978 +static void __exit gradm_mt_exit(void)
104979 +{
104980 + xt_unregister_match(&gradm_mt_reg);
104981 +}
104982 +
104983 +module_init(gradm_mt_init);
104984 +module_exit(gradm_mt_exit);
104985 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
104986 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
104987 +MODULE_LICENSE("GPL");
104988 +MODULE_ALIAS("ipt_gradm");
104989 +MODULE_ALIAS("ip6t_gradm");
104990 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
104991 index 47dc683..2e0d52c 100644
104992 --- a/net/netfilter/xt_hashlimit.c
104993 +++ b/net/netfilter/xt_hashlimit.c
104994 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
104995 {
104996 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
104997
104998 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
104999 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105000 if (!hashlimit_net->ipt_hashlimit)
105001 return -ENOMEM;
105002 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105003 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105004 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105005 if (!hashlimit_net->ip6t_hashlimit) {
105006 remove_proc_entry("ipt_hashlimit", net->proc_net);
105007 return -ENOMEM;
105008 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105009 index a9faae8..1ea30e0 100644
105010 --- a/net/netfilter/xt_recent.c
105011 +++ b/net/netfilter/xt_recent.c
105012 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105013 {
105014 struct recent_net *recent_net = recent_pernet(net);
105015
105016 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105017 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105018 if (!recent_net->xt_recent)
105019 return -ENOMEM;
105020 return 0;
105021 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105022 index 11de55e..f25e448 100644
105023 --- a/net/netfilter/xt_statistic.c
105024 +++ b/net/netfilter/xt_statistic.c
105025 @@ -19,7 +19,7 @@
105026 #include <linux/module.h>
105027
105028 struct xt_statistic_priv {
105029 - atomic_t count;
105030 + atomic_unchecked_t count;
105031 } ____cacheline_aligned_in_smp;
105032
105033 MODULE_LICENSE("GPL");
105034 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105035 break;
105036 case XT_STATISTIC_MODE_NTH:
105037 do {
105038 - oval = atomic_read(&info->master->count);
105039 + oval = atomic_read_unchecked(&info->master->count);
105040 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105041 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105042 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105043 if (nval == 0)
105044 ret = !ret;
105045 break;
105046 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105047 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105048 if (info->master == NULL)
105049 return -ENOMEM;
105050 - atomic_set(&info->master->count, info->u.nth.count);
105051 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105052
105053 return 0;
105054 }
105055 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105056 index 0007b81..cb08369 100644
105057 --- a/net/netlink/af_netlink.c
105058 +++ b/net/netlink/af_netlink.c
105059 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105060 sk->sk_error_report(sk);
105061 }
105062 }
105063 - atomic_inc(&sk->sk_drops);
105064 + atomic_inc_unchecked(&sk->sk_drops);
105065 }
105066
105067 static void netlink_rcv_wake(struct sock *sk)
105068 @@ -3010,7 +3010,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105069 sk_wmem_alloc_get(s),
105070 nlk->cb_running,
105071 atomic_read(&s->sk_refcnt),
105072 - atomic_read(&s->sk_drops),
105073 + atomic_read_unchecked(&s->sk_drops),
105074 sock_i_ino(s)
105075 );
105076
105077 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
105078 index 64dc864..7a9e2a4 100644
105079 --- a/net/openvswitch/datapath.c
105080 +++ b/net/openvswitch/datapath.c
105081 @@ -332,6 +332,8 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
105082 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
105083 if (IS_ERR(segs))
105084 return PTR_ERR(segs);
105085 + if (segs == NULL)
105086 + return -EINVAL;
105087
105088 /* Queue all of the segments. */
105089 skb = segs;
105090 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105091 index 93896d2..b701c88 100644
105092 --- a/net/packet/af_packet.c
105093 +++ b/net/packet/af_packet.c
105094 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105095
105096 return ret;
105097 drop:
105098 - atomic_long_inc(&dev->tx_dropped);
105099 + atomic_long_inc_unchecked(&dev->tx_dropped);
105100 kfree_skb(skb);
105101 return NET_XMIT_DROP;
105102 }
105103 @@ -1842,7 +1842,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105104
105105 spin_lock(&sk->sk_receive_queue.lock);
105106 po->stats.stats1.tp_packets++;
105107 - skb->dropcount = atomic_read(&sk->sk_drops);
105108 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105109 __skb_queue_tail(&sk->sk_receive_queue, skb);
105110 spin_unlock(&sk->sk_receive_queue.lock);
105111 sk->sk_data_ready(sk);
105112 @@ -1851,7 +1851,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105113 drop_n_acct:
105114 spin_lock(&sk->sk_receive_queue.lock);
105115 po->stats.stats1.tp_drops++;
105116 - atomic_inc(&sk->sk_drops);
105117 + atomic_inc_unchecked(&sk->sk_drops);
105118 spin_unlock(&sk->sk_receive_queue.lock);
105119
105120 drop_n_restore:
105121 @@ -3466,7 +3466,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105122 case PACKET_HDRLEN:
105123 if (len > sizeof(int))
105124 len = sizeof(int);
105125 - if (copy_from_user(&val, optval, len))
105126 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105127 return -EFAULT;
105128 switch (val) {
105129 case TPACKET_V1:
105130 @@ -3512,7 +3512,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105131 len = lv;
105132 if (put_user(len, optlen))
105133 return -EFAULT;
105134 - if (copy_to_user(optval, data, len))
105135 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105136 return -EFAULT;
105137 return 0;
105138 }
105139 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105140 index 70a547e..23477fe 100644
105141 --- a/net/phonet/pep.c
105142 +++ b/net/phonet/pep.c
105143 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105144
105145 case PNS_PEP_CTRL_REQ:
105146 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105147 - atomic_inc(&sk->sk_drops);
105148 + atomic_inc_unchecked(&sk->sk_drops);
105149 break;
105150 }
105151 __skb_pull(skb, 4);
105152 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105153 }
105154
105155 if (pn->rx_credits == 0) {
105156 - atomic_inc(&sk->sk_drops);
105157 + atomic_inc_unchecked(&sk->sk_drops);
105158 err = -ENOBUFS;
105159 break;
105160 }
105161 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105162 }
105163
105164 if (pn->rx_credits == 0) {
105165 - atomic_inc(&sk->sk_drops);
105166 + atomic_inc_unchecked(&sk->sk_drops);
105167 err = NET_RX_DROP;
105168 break;
105169 }
105170 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105171 index 008214a..bb68240 100644
105172 --- a/net/phonet/socket.c
105173 +++ b/net/phonet/socket.c
105174 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105175 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105176 sock_i_ino(sk),
105177 atomic_read(&sk->sk_refcnt), sk,
105178 - atomic_read(&sk->sk_drops));
105179 + atomic_read_unchecked(&sk->sk_drops));
105180 }
105181 seq_pad(seq, '\n');
105182 return 0;
105183 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105184 index c02a8c4..3c5b600 100644
105185 --- a/net/phonet/sysctl.c
105186 +++ b/net/phonet/sysctl.c
105187 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105188 {
105189 int ret;
105190 int range[2] = {local_port_range[0], local_port_range[1]};
105191 - struct ctl_table tmp = {
105192 + ctl_table_no_const tmp = {
105193 .data = &range,
105194 .maxlen = sizeof(range),
105195 .mode = table->mode,
105196 diff --git a/net/rds/cong.c b/net/rds/cong.c
105197 index e5b65ac..f3b6fb7 100644
105198 --- a/net/rds/cong.c
105199 +++ b/net/rds/cong.c
105200 @@ -78,7 +78,7 @@
105201 * finds that the saved generation number is smaller than the global generation
105202 * number, it wakes up the process.
105203 */
105204 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105205 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105206
105207 /*
105208 * Congestion monitoring
105209 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105210 rdsdebug("waking map %p for %pI4\n",
105211 map, &map->m_addr);
105212 rds_stats_inc(s_cong_update_received);
105213 - atomic_inc(&rds_cong_generation);
105214 + atomic_inc_unchecked(&rds_cong_generation);
105215 if (waitqueue_active(&map->m_waitq))
105216 wake_up(&map->m_waitq);
105217 if (waitqueue_active(&rds_poll_waitq))
105218 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105219
105220 int rds_cong_updated_since(unsigned long *recent)
105221 {
105222 - unsigned long gen = atomic_read(&rds_cong_generation);
105223 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105224
105225 if (likely(*recent == gen))
105226 return 0;
105227 diff --git a/net/rds/ib.h b/net/rds/ib.h
105228 index 7280ab8..e04f4ea 100644
105229 --- a/net/rds/ib.h
105230 +++ b/net/rds/ib.h
105231 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105232 /* sending acks */
105233 unsigned long i_ack_flags;
105234 #ifdef KERNEL_HAS_ATOMIC64
105235 - atomic64_t i_ack_next; /* next ACK to send */
105236 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105237 #else
105238 spinlock_t i_ack_lock; /* protect i_ack_next */
105239 u64 i_ack_next; /* next ACK to send */
105240 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105241 index 31b74f5..dc1fbfa 100644
105242 --- a/net/rds/ib_cm.c
105243 +++ b/net/rds/ib_cm.c
105244 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105245 /* Clear the ACK state */
105246 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105247 #ifdef KERNEL_HAS_ATOMIC64
105248 - atomic64_set(&ic->i_ack_next, 0);
105249 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105250 #else
105251 ic->i_ack_next = 0;
105252 #endif
105253 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105254 index d67de45..73dbf51 100644
105255 --- a/net/rds/ib_recv.c
105256 +++ b/net/rds/ib_recv.c
105257 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105258 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105259 int ack_required)
105260 {
105261 - atomic64_set(&ic->i_ack_next, seq);
105262 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105263 if (ack_required) {
105264 smp_mb__before_atomic();
105265 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105266 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105267 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105268 smp_mb__after_atomic();
105269
105270 - return atomic64_read(&ic->i_ack_next);
105271 + return atomic64_read_unchecked(&ic->i_ack_next);
105272 }
105273 #endif
105274
105275 diff --git a/net/rds/iw.h b/net/rds/iw.h
105276 index 04ce3b1..48119a6 100644
105277 --- a/net/rds/iw.h
105278 +++ b/net/rds/iw.h
105279 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105280 /* sending acks */
105281 unsigned long i_ack_flags;
105282 #ifdef KERNEL_HAS_ATOMIC64
105283 - atomic64_t i_ack_next; /* next ACK to send */
105284 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105285 #else
105286 spinlock_t i_ack_lock; /* protect i_ack_next */
105287 u64 i_ack_next; /* next ACK to send */
105288 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105289 index a91e1db..cf3053f 100644
105290 --- a/net/rds/iw_cm.c
105291 +++ b/net/rds/iw_cm.c
105292 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105293 /* Clear the ACK state */
105294 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105295 #ifdef KERNEL_HAS_ATOMIC64
105296 - atomic64_set(&ic->i_ack_next, 0);
105297 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105298 #else
105299 ic->i_ack_next = 0;
105300 #endif
105301 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105302 index aa8bf67..b70133c 100644
105303 --- a/net/rds/iw_recv.c
105304 +++ b/net/rds/iw_recv.c
105305 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105306 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105307 int ack_required)
105308 {
105309 - atomic64_set(&ic->i_ack_next, seq);
105310 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105311 if (ack_required) {
105312 smp_mb__before_atomic();
105313 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105314 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105315 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105316 smp_mb__after_atomic();
105317
105318 - return atomic64_read(&ic->i_ack_next);
105319 + return atomic64_read_unchecked(&ic->i_ack_next);
105320 }
105321 #endif
105322
105323 diff --git a/net/rds/rdma.c b/net/rds/rdma.c
105324 index 4e37c1c..40084d8 100644
105325 --- a/net/rds/rdma.c
105326 +++ b/net/rds/rdma.c
105327 @@ -564,12 +564,12 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105328
105329 if (rs->rs_bound_addr == 0) {
105330 ret = -ENOTCONN; /* XXX not a great errno */
105331 - goto out;
105332 + goto out_ret;
105333 }
105334
105335 if (args->nr_local > UIO_MAXIOV) {
105336 ret = -EMSGSIZE;
105337 - goto out;
105338 + goto out_ret;
105339 }
105340
105341 /* Check whether to allocate the iovec area */
105342 @@ -578,7 +578,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105343 iovs = sock_kmalloc(rds_rs_to_sk(rs), iov_size, GFP_KERNEL);
105344 if (!iovs) {
105345 ret = -ENOMEM;
105346 - goto out;
105347 + goto out_ret;
105348 }
105349 }
105350
105351 @@ -696,6 +696,7 @@ out:
105352 if (iovs != iovstack)
105353 sock_kfree_s(rds_rs_to_sk(rs), iovs, iov_size);
105354 kfree(pages);
105355 +out_ret:
105356 if (ret)
105357 rds_rdma_free_op(op);
105358 else
105359 diff --git a/net/rds/rds.h b/net/rds/rds.h
105360 index 48f8ffc..0ef3eec 100644
105361 --- a/net/rds/rds.h
105362 +++ b/net/rds/rds.h
105363 @@ -449,7 +449,7 @@ struct rds_transport {
105364 void (*sync_mr)(void *trans_private, int direction);
105365 void (*free_mr)(void *trans_private, int invalidate);
105366 void (*flush_mrs)(void);
105367 -};
105368 +} __do_const;
105369
105370 struct rds_sock {
105371 struct sock rs_sk;
105372 diff --git a/net/rds/send.c b/net/rds/send.c
105373 index 2371816..0a64541 100644
105374 --- a/net/rds/send.c
105375 +++ b/net/rds/send.c
105376 @@ -593,8 +593,11 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
105377 sock_put(rds_rs_to_sk(rs));
105378 }
105379 rs = rm->m_rs;
105380 - sock_hold(rds_rs_to_sk(rs));
105381 + if (rs)
105382 + sock_hold(rds_rs_to_sk(rs));
105383 }
105384 + if (!rs)
105385 + goto unlock_and_drop;
105386 spin_lock(&rs->rs_lock);
105387
105388 if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) {
105389 @@ -638,9 +641,6 @@ unlock_and_drop:
105390 * queue. This means that in the TCP case, the message may not have been
105391 * assigned the m_ack_seq yet - but that's fine as long as tcp_is_acked
105392 * checks the RDS_MSG_HAS_ACK_SEQ bit.
105393 - *
105394 - * XXX It's not clear to me how this is safely serialized with socket
105395 - * destruction. Maybe it should bail if it sees SOCK_DEAD.
105396 */
105397 void rds_send_drop_acked(struct rds_connection *conn, u64 ack,
105398 is_acked_func is_acked)
105399 @@ -711,6 +711,9 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
105400 */
105401 if (!test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) {
105402 spin_unlock_irqrestore(&conn->c_lock, flags);
105403 + spin_lock_irqsave(&rm->m_rs_lock, flags);
105404 + rm->m_rs = NULL;
105405 + spin_unlock_irqrestore(&rm->m_rs_lock, flags);
105406 continue;
105407 }
105408 list_del_init(&rm->m_conn_item);
105409 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105410 index edac9ef..16bcb98 100644
105411 --- a/net/rds/tcp.c
105412 +++ b/net/rds/tcp.c
105413 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105414 int val = 1;
105415
105416 set_fs(KERNEL_DS);
105417 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105418 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105419 sizeof(val));
105420 set_fs(oldfs);
105421 }
105422 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105423 index 53b17ca..45463e7 100644
105424 --- a/net/rds/tcp_send.c
105425 +++ b/net/rds/tcp_send.c
105426 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105427
105428 oldfs = get_fs();
105429 set_fs(KERNEL_DS);
105430 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105431 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
105432 sizeof(val));
105433 set_fs(oldfs);
105434 }
105435 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
105436 index 7b16704..9628ec6 100644
105437 --- a/net/rxrpc/af_rxrpc.c
105438 +++ b/net/rxrpc/af_rxrpc.c
105439 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
105440 __be32 rxrpc_epoch;
105441
105442 /* current debugging ID */
105443 -atomic_t rxrpc_debug_id;
105444 +atomic_unchecked_t rxrpc_debug_id;
105445
105446 /* count of skbs currently in use */
105447 atomic_t rxrpc_n_skbs;
105448 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
105449 index c6be17a..2a6200a 100644
105450 --- a/net/rxrpc/ar-ack.c
105451 +++ b/net/rxrpc/ar-ack.c
105452 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105453
105454 _enter("{%d,%d,%d,%d},",
105455 call->acks_hard, call->acks_unacked,
105456 - atomic_read(&call->sequence),
105457 + atomic_read_unchecked(&call->sequence),
105458 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
105459
105460 stop = 0;
105461 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105462
105463 /* each Tx packet has a new serial number */
105464 sp->hdr.serial =
105465 - htonl(atomic_inc_return(&call->conn->serial));
105466 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
105467
105468 hdr = (struct rxrpc_header *) txb->head;
105469 hdr->serial = sp->hdr.serial;
105470 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
105471 */
105472 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
105473 {
105474 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
105475 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
105476 }
105477
105478 /*
105479 @@ -677,7 +677,7 @@ process_further:
105480
105481 latest = ntohl(sp->hdr.serial);
105482 hard = ntohl(ack.firstPacket);
105483 - tx = atomic_read(&call->sequence);
105484 + tx = atomic_read_unchecked(&call->sequence);
105485
105486 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105487 latest,
105488 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
105489 goto maybe_reschedule;
105490
105491 send_ACK_with_skew:
105492 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
105493 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
105494 ntohl(ack.serial));
105495 send_ACK:
105496 mtu = call->conn->trans->peer->if_mtu;
105497 @@ -1221,7 +1221,7 @@ send_ACK:
105498 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
105499 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
105500
105501 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105502 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105503 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105504 ntohl(hdr.serial),
105505 ntohs(ack.maxSkew),
105506 @@ -1239,7 +1239,7 @@ send_ACK:
105507 send_message:
105508 _debug("send message");
105509
105510 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105511 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105512 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
105513 send_message_2:
105514
105515 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
105516 index a9e05db..194e793 100644
105517 --- a/net/rxrpc/ar-call.c
105518 +++ b/net/rxrpc/ar-call.c
105519 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
105520 spin_lock_init(&call->lock);
105521 rwlock_init(&call->state_lock);
105522 atomic_set(&call->usage, 1);
105523 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
105524 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105525 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
105526
105527 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
105528 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
105529 index 6631f4f..bfdf056 100644
105530 --- a/net/rxrpc/ar-connection.c
105531 +++ b/net/rxrpc/ar-connection.c
105532 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
105533 rwlock_init(&conn->lock);
105534 spin_lock_init(&conn->state_lock);
105535 atomic_set(&conn->usage, 1);
105536 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
105537 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105538 conn->avail_calls = RXRPC_MAXCALLS;
105539 conn->size_align = 4;
105540 conn->header_size = sizeof(struct rxrpc_header);
105541 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
105542 index e7ed43a..6afa140 100644
105543 --- a/net/rxrpc/ar-connevent.c
105544 +++ b/net/rxrpc/ar-connevent.c
105545 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
105546
105547 len = iov[0].iov_len + iov[1].iov_len;
105548
105549 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105550 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105551 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
105552
105553 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105554 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
105555 index 63b21e5..330232e 100644
105556 --- a/net/rxrpc/ar-input.c
105557 +++ b/net/rxrpc/ar-input.c
105558 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
105559 /* track the latest serial number on this connection for ACK packet
105560 * information */
105561 serial = ntohl(sp->hdr.serial);
105562 - hi_serial = atomic_read(&call->conn->hi_serial);
105563 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
105564 while (serial > hi_serial)
105565 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
105566 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
105567 serial);
105568
105569 /* request ACK generation for any ACK or DATA packet that requests
105570 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
105571 index ba9fd36..9bbfe01 100644
105572 --- a/net/rxrpc/ar-internal.h
105573 +++ b/net/rxrpc/ar-internal.h
105574 @@ -272,8 +272,8 @@ struct rxrpc_connection {
105575 int error; /* error code for local abort */
105576 int debug_id; /* debug ID for printks */
105577 unsigned int call_counter; /* call ID counter */
105578 - atomic_t serial; /* packet serial number counter */
105579 - atomic_t hi_serial; /* highest serial number received */
105580 + atomic_unchecked_t serial; /* packet serial number counter */
105581 + atomic_unchecked_t hi_serial; /* highest serial number received */
105582 u8 avail_calls; /* number of calls available */
105583 u8 size_align; /* data size alignment (for security) */
105584 u8 header_size; /* rxrpc + security header size */
105585 @@ -346,7 +346,7 @@ struct rxrpc_call {
105586 spinlock_t lock;
105587 rwlock_t state_lock; /* lock for state transition */
105588 atomic_t usage;
105589 - atomic_t sequence; /* Tx data packet sequence counter */
105590 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
105591 u32 abort_code; /* local/remote abort code */
105592 enum { /* current state of call */
105593 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
105594 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
105595 */
105596 extern atomic_t rxrpc_n_skbs;
105597 extern __be32 rxrpc_epoch;
105598 -extern atomic_t rxrpc_debug_id;
105599 +extern atomic_unchecked_t rxrpc_debug_id;
105600 extern struct workqueue_struct *rxrpc_workqueue;
105601
105602 /*
105603 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
105604 index 87f7135..74d3703 100644
105605 --- a/net/rxrpc/ar-local.c
105606 +++ b/net/rxrpc/ar-local.c
105607 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
105608 spin_lock_init(&local->lock);
105609 rwlock_init(&local->services_lock);
105610 atomic_set(&local->usage, 1);
105611 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
105612 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105613 memcpy(&local->srx, srx, sizeof(*srx));
105614 }
105615
105616 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
105617 index 0b4b9a7..966ffbb 100644
105618 --- a/net/rxrpc/ar-output.c
105619 +++ b/net/rxrpc/ar-output.c
105620 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
105621 memset(skb_put(skb, pad), 0, pad);
105622 }
105623
105624 - seq = atomic_inc_return(&call->sequence);
105625 + seq = atomic_inc_return_unchecked(&call->sequence);
105626
105627 sp->hdr.epoch = conn->epoch;
105628 sp->hdr.cid = call->cid;
105629 sp->hdr.callNumber = call->call_id;
105630 sp->hdr.seq = htonl(seq);
105631 sp->hdr.serial =
105632 - htonl(atomic_inc_return(&conn->serial));
105633 + htonl(atomic_inc_return_unchecked(&conn->serial));
105634 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
105635 sp->hdr.userStatus = 0;
105636 sp->hdr.securityIndex = conn->security_ix;
105637 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
105638 index bebaa43..2644591 100644
105639 --- a/net/rxrpc/ar-peer.c
105640 +++ b/net/rxrpc/ar-peer.c
105641 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
105642 INIT_LIST_HEAD(&peer->error_targets);
105643 spin_lock_init(&peer->lock);
105644 atomic_set(&peer->usage, 1);
105645 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
105646 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105647 memcpy(&peer->srx, srx, sizeof(*srx));
105648
105649 rxrpc_assess_MTU_size(peer);
105650 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
105651 index 38047f7..9f48511 100644
105652 --- a/net/rxrpc/ar-proc.c
105653 +++ b/net/rxrpc/ar-proc.c
105654 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
105655 atomic_read(&conn->usage),
105656 rxrpc_conn_states[conn->state],
105657 key_serial(conn->key),
105658 - atomic_read(&conn->serial),
105659 - atomic_read(&conn->hi_serial));
105660 + atomic_read_unchecked(&conn->serial),
105661 + atomic_read_unchecked(&conn->hi_serial));
105662
105663 return 0;
105664 }
105665 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
105666 index 1976dec..aa70be5 100644
105667 --- a/net/rxrpc/ar-transport.c
105668 +++ b/net/rxrpc/ar-transport.c
105669 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
105670 spin_lock_init(&trans->client_lock);
105671 rwlock_init(&trans->conn_lock);
105672 atomic_set(&trans->usage, 1);
105673 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
105674 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105675
105676 if (peer->srx.transport.family == AF_INET) {
105677 switch (peer->srx.transport_type) {
105678 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
105679 index f226709..0e735a8 100644
105680 --- a/net/rxrpc/rxkad.c
105681 +++ b/net/rxrpc/rxkad.c
105682 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
105683
105684 len = iov[0].iov_len + iov[1].iov_len;
105685
105686 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105687 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105688 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
105689
105690 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105691 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
105692
105693 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
105694
105695 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
105696 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105697 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
105698
105699 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
105700 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
105701 index fc04fe9..8167357 100644
105702 --- a/net/sched/sch_generic.c
105703 +++ b/net/sched/sch_generic.c
105704 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
105705 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105706 if (dev->reg_state == NETREG_UNINITIALIZED)
105707 return;
105708 - atomic_inc(&dev->carrier_changes);
105709 + atomic_inc_unchecked(&dev->carrier_changes);
105710 linkwatch_fire_event(dev);
105711 if (netif_running(dev))
105712 __netdev_watchdog_up(dev);
105713 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
105714 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105715 if (dev->reg_state == NETREG_UNINITIALIZED)
105716 return;
105717 - atomic_inc(&dev->carrier_changes);
105718 + atomic_inc_unchecked(&dev->carrier_changes);
105719 linkwatch_fire_event(dev);
105720 }
105721 }
105722 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
105723 index 0e4198e..f94193e 100644
105724 --- a/net/sctp/ipv6.c
105725 +++ b/net/sctp/ipv6.c
105726 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
105727 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
105728 };
105729
105730 -static struct sctp_af sctp_af_inet6 = {
105731 +static struct sctp_af sctp_af_inet6 __read_only = {
105732 .sa_family = AF_INET6,
105733 .sctp_xmit = sctp_v6_xmit,
105734 .setsockopt = ipv6_setsockopt,
105735 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
105736 #endif
105737 };
105738
105739 -static struct sctp_pf sctp_pf_inet6 = {
105740 +static struct sctp_pf sctp_pf_inet6 __read_only = {
105741 .event_msgname = sctp_inet6_event_msgname,
105742 .skb_msgname = sctp_inet6_skb_msgname,
105743 .af_supported = sctp_inet6_af_supported,
105744 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
105745
105746 void sctp_v6_pf_exit(void)
105747 {
105748 - list_del(&sctp_af_inet6.list);
105749 + pax_list_del(&sctp_af_inet6.list);
105750 }
105751
105752 /* Initialize IPv6 support and register with socket layer. */
105753 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
105754 index 6240834..cac4b52 100644
105755 --- a/net/sctp/protocol.c
105756 +++ b/net/sctp/protocol.c
105757 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
105758 return 0;
105759 }
105760
105761 + pax_open_kernel();
105762 INIT_LIST_HEAD(&af->list);
105763 - list_add_tail(&af->list, &sctp_address_families);
105764 + pax_close_kernel();
105765 + pax_list_add_tail(&af->list, &sctp_address_families);
105766 return 1;
105767 }
105768
105769 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
105770
105771 static struct sctp_af sctp_af_inet;
105772
105773 -static struct sctp_pf sctp_pf_inet = {
105774 +static struct sctp_pf sctp_pf_inet __read_only = {
105775 .event_msgname = sctp_inet_event_msgname,
105776 .skb_msgname = sctp_inet_skb_msgname,
105777 .af_supported = sctp_inet_af_supported,
105778 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
105779 };
105780
105781 /* IPv4 address related functions. */
105782 -static struct sctp_af sctp_af_inet = {
105783 +static struct sctp_af sctp_af_inet __read_only = {
105784 .sa_family = AF_INET,
105785 .sctp_xmit = sctp_v4_xmit,
105786 .setsockopt = ip_setsockopt,
105787 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
105788
105789 static void sctp_v4_pf_exit(void)
105790 {
105791 - list_del(&sctp_af_inet.list);
105792 + pax_list_del(&sctp_af_inet.list);
105793 }
105794
105795 static int sctp_v4_protosw_init(void)
105796 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
105797 index fef2acd..c705c4f 100644
105798 --- a/net/sctp/sm_sideeffect.c
105799 +++ b/net/sctp/sm_sideeffect.c
105800 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
105801 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
105802 }
105803
105804 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
105805 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
105806 NULL,
105807 sctp_generate_t1_cookie_event,
105808 sctp_generate_t1_init_event,
105809 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
105810 index 634a2ab..8e93929 100644
105811 --- a/net/sctp/socket.c
105812 +++ b/net/sctp/socket.c
105813 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
105814 {
105815 struct sctp_association *asoc;
105816 struct sctp_ulpevent *event;
105817 + struct sctp_event_subscribe subscribe;
105818
105819 if (optlen > sizeof(struct sctp_event_subscribe))
105820 return -EINVAL;
105821 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
105822 + if (copy_from_user(&subscribe, optval, optlen))
105823 return -EFAULT;
105824 + sctp_sk(sk)->subscribe = subscribe;
105825
105826 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
105827 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
105828 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
105829 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
105830 int __user *optlen)
105831 {
105832 + struct sctp_event_subscribe subscribe;
105833 +
105834 if (len <= 0)
105835 return -EINVAL;
105836 if (len > sizeof(struct sctp_event_subscribe))
105837 len = sizeof(struct sctp_event_subscribe);
105838 if (put_user(len, optlen))
105839 return -EFAULT;
105840 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
105841 + subscribe = sctp_sk(sk)->subscribe;
105842 + if (copy_to_user(optval, &subscribe, len))
105843 return -EFAULT;
105844 return 0;
105845 }
105846 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
105847 */
105848 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
105849 {
105850 + __u32 autoclose;
105851 +
105852 /* Applicable to UDP-style socket only */
105853 if (sctp_style(sk, TCP))
105854 return -EOPNOTSUPP;
105855 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
105856 len = sizeof(int);
105857 if (put_user(len, optlen))
105858 return -EFAULT;
105859 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
105860 + autoclose = sctp_sk(sk)->autoclose;
105861 + if (copy_to_user(optval, &autoclose, sizeof(int)))
105862 return -EFAULT;
105863 return 0;
105864 }
105865 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
105866 */
105867 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
105868 {
105869 + struct sctp_initmsg initmsg;
105870 +
105871 if (len < sizeof(struct sctp_initmsg))
105872 return -EINVAL;
105873 len = sizeof(struct sctp_initmsg);
105874 if (put_user(len, optlen))
105875 return -EFAULT;
105876 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
105877 + initmsg = sctp_sk(sk)->initmsg;
105878 + if (copy_to_user(optval, &initmsg, len))
105879 return -EFAULT;
105880 return 0;
105881 }
105882 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
105883 ->addr_to_user(sp, &temp);
105884 if (space_left < addrlen)
105885 return -ENOMEM;
105886 + if (addrlen > sizeof(temp) || addrlen < 0)
105887 + return -EFAULT;
105888 if (copy_to_user(to, &temp, addrlen))
105889 return -EFAULT;
105890 to += addrlen;
105891 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
105892 index 2e9ada1..40f425d 100644
105893 --- a/net/sctp/sysctl.c
105894 +++ b/net/sctp/sysctl.c
105895 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
105896 loff_t *ppos)
105897 {
105898 struct net *net = current->nsproxy->net_ns;
105899 - struct ctl_table tbl;
105900 + ctl_table_no_const tbl;
105901 bool changed = false;
105902 char *none = "none";
105903 char tmp[8];
105904 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
105905 struct net *net = current->nsproxy->net_ns;
105906 unsigned int min = *(unsigned int *) ctl->extra1;
105907 unsigned int max = *(unsigned int *) ctl->extra2;
105908 - struct ctl_table tbl;
105909 + ctl_table_no_const tbl;
105910 int ret, new_value;
105911
105912 memset(&tbl, 0, sizeof(struct ctl_table));
105913 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
105914 struct net *net = current->nsproxy->net_ns;
105915 unsigned int min = *(unsigned int *) ctl->extra1;
105916 unsigned int max = *(unsigned int *) ctl->extra2;
105917 - struct ctl_table tbl;
105918 + ctl_table_no_const tbl;
105919 int ret, new_value;
105920
105921 memset(&tbl, 0, sizeof(struct ctl_table));
105922 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
105923 loff_t *ppos)
105924 {
105925 struct net *net = current->nsproxy->net_ns;
105926 - struct ctl_table tbl;
105927 + ctl_table_no_const tbl;
105928 int new_value, ret;
105929
105930 memset(&tbl, 0, sizeof(struct ctl_table));
105931 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
105932
105933 int sctp_sysctl_net_register(struct net *net)
105934 {
105935 - struct ctl_table *table;
105936 + ctl_table_no_const *table;
105937 int i;
105938
105939 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
105940 diff --git a/net/socket.c b/net/socket.c
105941 index 4cdbc10..f075204 100644
105942 --- a/net/socket.c
105943 +++ b/net/socket.c
105944 @@ -89,6 +89,7 @@
105945 #include <linux/magic.h>
105946 #include <linux/slab.h>
105947 #include <linux/xattr.h>
105948 +#include <linux/in.h>
105949
105950 #include <asm/uaccess.h>
105951 #include <asm/unistd.h>
105952 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
105953 unsigned int sysctl_net_busy_poll __read_mostly;
105954 #endif
105955
105956 +#include <linux/grsock.h>
105957 +
105958 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
105959 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
105960 unsigned long nr_segs, loff_t pos);
105961 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
105962 */
105963
105964 static DEFINE_SPINLOCK(net_family_lock);
105965 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
105966 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
105967
105968 /*
105969 * Statistics counters of the socket lists
105970 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
105971 &sockfs_dentry_operations, SOCKFS_MAGIC);
105972 }
105973
105974 -static struct vfsmount *sock_mnt __read_mostly;
105975 +struct vfsmount *sock_mnt __read_mostly;
105976
105977 static struct file_system_type sock_fs_type = {
105978 .name = "sockfs",
105979 @@ -1265,6 +1268,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
105980 return -EAFNOSUPPORT;
105981 if (type < 0 || type >= SOCK_MAX)
105982 return -EINVAL;
105983 + if (protocol < 0)
105984 + return -EINVAL;
105985
105986 /* Compatibility.
105987
105988 @@ -1285,6 +1290,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
105989 if (err)
105990 return err;
105991
105992 + if(!kern && !gr_search_socket(family, type, protocol)) {
105993 + if (rcu_access_pointer(net_families[family]) == NULL)
105994 + return -EAFNOSUPPORT;
105995 + else
105996 + return -EACCES;
105997 + }
105998 +
105999 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106000 + if (rcu_access_pointer(net_families[family]) == NULL)
106001 + return -EAFNOSUPPORT;
106002 + else
106003 + return -EACCES;
106004 + }
106005 +
106006 /*
106007 * Allocate the socket and allow the family to set things up. if
106008 * the protocol is 0, the family is instructed to select an appropriate
106009 @@ -1536,6 +1555,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106010 if (sock) {
106011 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106012 if (err >= 0) {
106013 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106014 + err = -EACCES;
106015 + goto error;
106016 + }
106017 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106018 + if (err)
106019 + goto error;
106020 +
106021 err = security_socket_bind(sock,
106022 (struct sockaddr *)&address,
106023 addrlen);
106024 @@ -1544,6 +1571,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106025 (struct sockaddr *)
106026 &address, addrlen);
106027 }
106028 +error:
106029 fput_light(sock->file, fput_needed);
106030 }
106031 return err;
106032 @@ -1567,10 +1595,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106033 if ((unsigned int)backlog > somaxconn)
106034 backlog = somaxconn;
106035
106036 + if (gr_handle_sock_server_other(sock->sk)) {
106037 + err = -EPERM;
106038 + goto error;
106039 + }
106040 +
106041 + err = gr_search_listen(sock);
106042 + if (err)
106043 + goto error;
106044 +
106045 err = security_socket_listen(sock, backlog);
106046 if (!err)
106047 err = sock->ops->listen(sock, backlog);
106048
106049 +error:
106050 fput_light(sock->file, fput_needed);
106051 }
106052 return err;
106053 @@ -1614,6 +1652,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106054 newsock->type = sock->type;
106055 newsock->ops = sock->ops;
106056
106057 + if (gr_handle_sock_server_other(sock->sk)) {
106058 + err = -EPERM;
106059 + sock_release(newsock);
106060 + goto out_put;
106061 + }
106062 +
106063 + err = gr_search_accept(sock);
106064 + if (err) {
106065 + sock_release(newsock);
106066 + goto out_put;
106067 + }
106068 +
106069 /*
106070 * We don't need try_module_get here, as the listening socket (sock)
106071 * has the protocol module (sock->ops->owner) held.
106072 @@ -1659,6 +1709,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106073 fd_install(newfd, newfile);
106074 err = newfd;
106075
106076 + gr_attach_curr_ip(newsock->sk);
106077 +
106078 out_put:
106079 fput_light(sock->file, fput_needed);
106080 out:
106081 @@ -1691,6 +1743,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106082 int, addrlen)
106083 {
106084 struct socket *sock;
106085 + struct sockaddr *sck;
106086 struct sockaddr_storage address;
106087 int err, fput_needed;
106088
106089 @@ -1701,6 +1754,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106090 if (err < 0)
106091 goto out_put;
106092
106093 + sck = (struct sockaddr *)&address;
106094 +
106095 + if (gr_handle_sock_client(sck)) {
106096 + err = -EACCES;
106097 + goto out_put;
106098 + }
106099 +
106100 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106101 + if (err)
106102 + goto out_put;
106103 +
106104 err =
106105 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106106 if (err)
106107 @@ -1782,6 +1846,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106108 * the protocol.
106109 */
106110
106111 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106112 +
106113 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106114 unsigned int, flags, struct sockaddr __user *, addr,
106115 int, addr_len)
106116 @@ -1848,7 +1914,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106117 struct socket *sock;
106118 struct iovec iov;
106119 struct msghdr msg;
106120 - struct sockaddr_storage address;
106121 + struct sockaddr_storage address = { };
106122 int err, err2;
106123 int fput_needed;
106124
106125 @@ -2077,7 +2143,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106126 * checking falls down on this.
106127 */
106128 if (copy_from_user(ctl_buf,
106129 - (void __user __force *)msg_sys->msg_control,
106130 + (void __force_user *)msg_sys->msg_control,
106131 ctl_len))
106132 goto out_freectl;
106133 msg_sys->msg_control = ctl_buf;
106134 @@ -2228,7 +2294,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106135 int err, total_len, len;
106136
106137 /* kernel mode address */
106138 - struct sockaddr_storage addr;
106139 + struct sockaddr_storage addr = { };
106140
106141 /* user mode address pointers */
106142 struct sockaddr __user *uaddr;
106143 @@ -2257,7 +2323,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106144 /* Save the user-mode address (verify_iovec will change the
106145 * kernel msghdr to use the kernel address space)
106146 */
106147 - uaddr = (__force void __user *)msg_sys->msg_name;
106148 + uaddr = (void __force_user *)msg_sys->msg_name;
106149 uaddr_len = COMPAT_NAMELEN(msg);
106150 if (MSG_CMSG_COMPAT & flags)
106151 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106152 @@ -2898,7 +2964,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106153 ifr = compat_alloc_user_space(buf_size);
106154 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106155
106156 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106157 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106158 return -EFAULT;
106159
106160 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106161 @@ -3009,7 +3075,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106162 old_fs = get_fs();
106163 set_fs(KERNEL_DS);
106164 err = dev_ioctl(net, cmd,
106165 - (struct ifreq __user __force *) &kifr);
106166 + (struct ifreq __force_user *) &kifr);
106167 set_fs(old_fs);
106168
106169 return err;
106170 @@ -3102,7 +3168,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106171
106172 old_fs = get_fs();
106173 set_fs(KERNEL_DS);
106174 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106175 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106176 set_fs(old_fs);
106177
106178 if (cmd == SIOCGIFMAP && !err) {
106179 @@ -3186,7 +3252,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106180 ret |= get_user(rtdev, &(ur4->rt_dev));
106181 if (rtdev) {
106182 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106183 - r4.rt_dev = (char __user __force *)devname;
106184 + r4.rt_dev = (char __force_user *)devname;
106185 devname[15] = 0;
106186 } else
106187 r4.rt_dev = NULL;
106188 @@ -3413,8 +3479,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106189 int __user *uoptlen;
106190 int err;
106191
106192 - uoptval = (char __user __force *) optval;
106193 - uoptlen = (int __user __force *) optlen;
106194 + uoptval = (char __force_user *) optval;
106195 + uoptlen = (int __force_user *) optlen;
106196
106197 set_fs(KERNEL_DS);
106198 if (level == SOL_SOCKET)
106199 @@ -3434,7 +3500,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106200 char __user *uoptval;
106201 int err;
106202
106203 - uoptval = (char __user __force *) optval;
106204 + uoptval = (char __force_user *) optval;
106205
106206 set_fs(KERNEL_DS);
106207 if (level == SOL_SOCKET)
106208 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106209 index c548ab2..4e1b68b 100644
106210 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106211 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106212 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106213 uint64_t *handle)
106214 {
106215 struct rsc rsci, *rscp = NULL;
106216 - static atomic64_t ctxhctr;
106217 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106218 long long ctxh;
106219 struct gss_api_mech *gm = NULL;
106220 time_t expiry;
106221 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106222 status = -ENOMEM;
106223 /* the handle needs to be just a unique id,
106224 * use a static counter */
106225 - ctxh = atomic64_inc_return(&ctxhctr);
106226 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106227
106228 /* make a copy for the caller */
106229 *handle = ctxh;
106230 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106231 index 0663621..c4928d4 100644
106232 --- a/net/sunrpc/cache.c
106233 +++ b/net/sunrpc/cache.c
106234 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106235 struct sunrpc_net *sn;
106236
106237 sn = net_generic(net, sunrpc_net_id);
106238 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106239 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106240 if (cd->u.procfs.proc_ent == NULL)
106241 goto out_nomem;
106242 cd->u.procfs.channel_ent = NULL;
106243 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106244 index e0b94ce..6135813 100644
106245 --- a/net/sunrpc/clnt.c
106246 +++ b/net/sunrpc/clnt.c
106247 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106248 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106249
106250 /* Increment call count */
106251 - task->tk_msg.rpc_proc->p_count++;
106252 + pax_open_kernel();
106253 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106254 + pax_close_kernel();
106255 clnt->cl_stats->rpccnt++;
106256 task->tk_action = call_reserve;
106257 }
106258 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106259 index 9358c79..22d0a5b 100644
106260 --- a/net/sunrpc/sched.c
106261 +++ b/net/sunrpc/sched.c
106262 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106263 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106264 static void rpc_task_set_debuginfo(struct rpc_task *task)
106265 {
106266 - static atomic_t rpc_pid;
106267 + static atomic_unchecked_t rpc_pid;
106268
106269 - task->tk_pid = atomic_inc_return(&rpc_pid);
106270 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106271 }
106272 #else
106273 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106274 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106275 index 5453049..465669a 100644
106276 --- a/net/sunrpc/stats.c
106277 +++ b/net/sunrpc/stats.c
106278 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106279
106280 dprintk("RPC: registering /proc/net/rpc\n");
106281 sn = net_generic(net, sunrpc_net_id);
106282 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106283 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106284 if (sn->proc_net_rpc == NULL)
106285 return -ENOMEM;
106286
106287 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106288 index 1db5007..6e66296 100644
106289 --- a/net/sunrpc/svc.c
106290 +++ b/net/sunrpc/svc.c
106291 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106292 svc_putnl(resv, RPC_SUCCESS);
106293
106294 /* Bump per-procedure stats counter */
106295 - procp->pc_count++;
106296 + pax_open_kernel();
106297 + (*(unsigned int *)&procp->pc_count)++;
106298 + pax_close_kernel();
106299
106300 /* Initialize storage for argp and resp */
106301 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106302 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106303 index 621ca7b..59421dd 100644
106304 --- a/net/sunrpc/svcauth_unix.c
106305 +++ b/net/sunrpc/svcauth_unix.c
106306 @@ -414,7 +414,7 @@ struct unix_gid {
106307 struct group_info *gi;
106308 };
106309
106310 -static int unix_gid_hash(kuid_t uid)
106311 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106312 {
106313 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106314 }
106315 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106316 (*bpp)[-1] = '\n';
106317 }
106318
106319 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106320 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106321
106322 static int unix_gid_parse(struct cache_detail *cd,
106323 char *mesg, int mlen)
106324 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106325 index c1b6270..05089c1 100644
106326 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106327 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106328 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106329 static unsigned int min_max_inline = 4096;
106330 static unsigned int max_max_inline = 65536;
106331
106332 -atomic_t rdma_stat_recv;
106333 -atomic_t rdma_stat_read;
106334 -atomic_t rdma_stat_write;
106335 -atomic_t rdma_stat_sq_starve;
106336 -atomic_t rdma_stat_rq_starve;
106337 -atomic_t rdma_stat_rq_poll;
106338 -atomic_t rdma_stat_rq_prod;
106339 -atomic_t rdma_stat_sq_poll;
106340 -atomic_t rdma_stat_sq_prod;
106341 +atomic_unchecked_t rdma_stat_recv;
106342 +atomic_unchecked_t rdma_stat_read;
106343 +atomic_unchecked_t rdma_stat_write;
106344 +atomic_unchecked_t rdma_stat_sq_starve;
106345 +atomic_unchecked_t rdma_stat_rq_starve;
106346 +atomic_unchecked_t rdma_stat_rq_poll;
106347 +atomic_unchecked_t rdma_stat_rq_prod;
106348 +atomic_unchecked_t rdma_stat_sq_poll;
106349 +atomic_unchecked_t rdma_stat_sq_prod;
106350
106351 /* Temporary NFS request map and context caches */
106352 struct kmem_cache *svc_rdma_map_cachep;
106353 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
106354 len -= *ppos;
106355 if (len > *lenp)
106356 len = *lenp;
106357 - if (len && copy_to_user(buffer, str_buf, len))
106358 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
106359 return -EFAULT;
106360 *lenp = len;
106361 *ppos += len;
106362 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
106363 {
106364 .procname = "rdma_stat_read",
106365 .data = &rdma_stat_read,
106366 - .maxlen = sizeof(atomic_t),
106367 + .maxlen = sizeof(atomic_unchecked_t),
106368 .mode = 0644,
106369 .proc_handler = read_reset_stat,
106370 },
106371 {
106372 .procname = "rdma_stat_recv",
106373 .data = &rdma_stat_recv,
106374 - .maxlen = sizeof(atomic_t),
106375 + .maxlen = sizeof(atomic_unchecked_t),
106376 .mode = 0644,
106377 .proc_handler = read_reset_stat,
106378 },
106379 {
106380 .procname = "rdma_stat_write",
106381 .data = &rdma_stat_write,
106382 - .maxlen = sizeof(atomic_t),
106383 + .maxlen = sizeof(atomic_unchecked_t),
106384 .mode = 0644,
106385 .proc_handler = read_reset_stat,
106386 },
106387 {
106388 .procname = "rdma_stat_sq_starve",
106389 .data = &rdma_stat_sq_starve,
106390 - .maxlen = sizeof(atomic_t),
106391 + .maxlen = sizeof(atomic_unchecked_t),
106392 .mode = 0644,
106393 .proc_handler = read_reset_stat,
106394 },
106395 {
106396 .procname = "rdma_stat_rq_starve",
106397 .data = &rdma_stat_rq_starve,
106398 - .maxlen = sizeof(atomic_t),
106399 + .maxlen = sizeof(atomic_unchecked_t),
106400 .mode = 0644,
106401 .proc_handler = read_reset_stat,
106402 },
106403 {
106404 .procname = "rdma_stat_rq_poll",
106405 .data = &rdma_stat_rq_poll,
106406 - .maxlen = sizeof(atomic_t),
106407 + .maxlen = sizeof(atomic_unchecked_t),
106408 .mode = 0644,
106409 .proc_handler = read_reset_stat,
106410 },
106411 {
106412 .procname = "rdma_stat_rq_prod",
106413 .data = &rdma_stat_rq_prod,
106414 - .maxlen = sizeof(atomic_t),
106415 + .maxlen = sizeof(atomic_unchecked_t),
106416 .mode = 0644,
106417 .proc_handler = read_reset_stat,
106418 },
106419 {
106420 .procname = "rdma_stat_sq_poll",
106421 .data = &rdma_stat_sq_poll,
106422 - .maxlen = sizeof(atomic_t),
106423 + .maxlen = sizeof(atomic_unchecked_t),
106424 .mode = 0644,
106425 .proc_handler = read_reset_stat,
106426 },
106427 {
106428 .procname = "rdma_stat_sq_prod",
106429 .data = &rdma_stat_sq_prod,
106430 - .maxlen = sizeof(atomic_t),
106431 + .maxlen = sizeof(atomic_unchecked_t),
106432 .mode = 0644,
106433 .proc_handler = read_reset_stat,
106434 },
106435 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106436 index e011027..9d3c4e1 100644
106437 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106438 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106439 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
106440 *page_no = pg_no;
106441 *page_offset = pg_off;
106442 ret = read;
106443 - atomic_inc(&rdma_stat_read);
106444 + atomic_inc_unchecked(&rdma_stat_read);
106445 return ret;
106446 err:
106447 svc_rdma_unmap_dma(ctxt);
106448 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
106449 *page_no = pg_no;
106450 *page_offset = pg_off;
106451 ret = read;
106452 - atomic_inc(&rdma_stat_read);
106453 + atomic_inc_unchecked(&rdma_stat_read);
106454 return ret;
106455 err:
106456 svc_rdma_unmap_dma(ctxt);
106457 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106458 dto_q);
106459 list_del_init(&ctxt->dto_q);
106460 } else {
106461 - atomic_inc(&rdma_stat_rq_starve);
106462 + atomic_inc_unchecked(&rdma_stat_rq_starve);
106463 clear_bit(XPT_DATA, &xprt->xpt_flags);
106464 ctxt = NULL;
106465 }
106466 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106467 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
106468 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
106469 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
106470 - atomic_inc(&rdma_stat_recv);
106471 + atomic_inc_unchecked(&rdma_stat_recv);
106472
106473 /* Build up the XDR from the receive buffers. */
106474 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
106475 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106476 index 9f1b506..2e0b321 100644
106477 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106478 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106479 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
106480 write_wr.wr.rdma.remote_addr = to;
106481
106482 /* Post It */
106483 - atomic_inc(&rdma_stat_write);
106484 + atomic_inc_unchecked(&rdma_stat_write);
106485 if (svc_rdma_send(xprt, &write_wr))
106486 goto err;
106487 return write_len - bc;
106488 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106489 index 374feb4..46487d5 100644
106490 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
106491 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106492 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106493 return;
106494
106495 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
106496 - atomic_inc(&rdma_stat_rq_poll);
106497 + atomic_inc_unchecked(&rdma_stat_rq_poll);
106498
106499 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
106500 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
106501 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106502 }
106503
106504 if (ctxt)
106505 - atomic_inc(&rdma_stat_rq_prod);
106506 + atomic_inc_unchecked(&rdma_stat_rq_prod);
106507
106508 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
106509 /*
106510 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106511 return;
106512
106513 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
106514 - atomic_inc(&rdma_stat_sq_poll);
106515 + atomic_inc_unchecked(&rdma_stat_sq_poll);
106516 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
106517 int i;
106518
106519 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106520 }
106521
106522 if (ctxt)
106523 - atomic_inc(&rdma_stat_sq_prod);
106524 + atomic_inc_unchecked(&rdma_stat_sq_prod);
106525 }
106526
106527 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
106528 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
106529 spin_lock_bh(&xprt->sc_lock);
106530 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
106531 spin_unlock_bh(&xprt->sc_lock);
106532 - atomic_inc(&rdma_stat_sq_starve);
106533 + atomic_inc_unchecked(&rdma_stat_sq_starve);
106534
106535 /* See if we can opportunistically reap SQ WR to make room */
106536 sq_cq_reap(xprt);
106537 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
106538 index e7000be..e3b0ba7 100644
106539 --- a/net/sysctl_net.c
106540 +++ b/net/sysctl_net.c
106541 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
106542 kgid_t root_gid = make_kgid(net->user_ns, 0);
106543
106544 /* Allow network administrator to have same access as root. */
106545 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
106546 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
106547 uid_eq(root_uid, current_euid())) {
106548 int mode = (table->mode >> 6) & 7;
106549 return (mode << 6) | (mode << 3) | mode;
106550 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
106551 index 6424372..afd36e9 100644
106552 --- a/net/tipc/subscr.c
106553 +++ b/net/tipc/subscr.c
106554 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
106555 struct tipc_subscriber *subscriber = sub->subscriber;
106556 struct kvec msg_sect;
106557
106558 - msg_sect.iov_base = (void *)&sub->evt;
106559 + msg_sect.iov_base = &sub->evt;
106560 msg_sect.iov_len = sizeof(struct tipc_event);
106561 sub->evt.event = htohl(event, sub->swap);
106562 sub->evt.found_lower = htohl(found_lower, sub->swap);
106563 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
106564 index e968843..bc95776 100644
106565 --- a/net/unix/af_unix.c
106566 +++ b/net/unix/af_unix.c
106567 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
106568 err = -ECONNREFUSED;
106569 if (!S_ISSOCK(inode->i_mode))
106570 goto put_fail;
106571 +
106572 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
106573 + err = -EACCES;
106574 + goto put_fail;
106575 + }
106576 +
106577 u = unix_find_socket_byinode(inode);
106578 if (!u)
106579 goto put_fail;
106580 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
106581 if (u) {
106582 struct dentry *dentry;
106583 dentry = unix_sk(u)->path.dentry;
106584 +
106585 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
106586 + err = -EPERM;
106587 + sock_put(u);
106588 + goto fail;
106589 + }
106590 +
106591 if (dentry)
106592 touch_atime(&unix_sk(u)->path);
106593 } else
106594 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
106595 */
106596 err = security_path_mknod(&path, dentry, mode, 0);
106597 if (!err) {
106598 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
106599 + err = -EACCES;
106600 + goto out;
106601 + }
106602 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
106603 if (!err) {
106604 res->mnt = mntget(path.mnt);
106605 res->dentry = dget(dentry);
106606 + gr_handle_create(dentry, path.mnt);
106607 }
106608 }
106609 +out:
106610 done_path_create(&path, dentry);
106611 return err;
106612 }
106613 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106614 seq_puts(seq, "Num RefCount Protocol Flags Type St "
106615 "Inode Path\n");
106616 else {
106617 - struct sock *s = v;
106618 + struct sock *s = v, *peer;
106619 struct unix_sock *u = unix_sk(s);
106620 unix_state_lock(s);
106621 + peer = unix_peer(s);
106622 + unix_state_unlock(s);
106623 +
106624 + unix_state_double_lock(s, peer);
106625
106626 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
106627 s,
106628 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106629 }
106630 for ( ; i < len; i++)
106631 seq_putc(seq, u->addr->name->sun_path[i]);
106632 - }
106633 - unix_state_unlock(s);
106634 + } else if (peer)
106635 + seq_printf(seq, " P%lu", sock_i_ino(peer));
106636 +
106637 + unix_state_double_unlock(s, peer);
106638 seq_putc(seq, '\n');
106639 }
106640
106641 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
106642 index b3d5150..ff3a837 100644
106643 --- a/net/unix/sysctl_net_unix.c
106644 +++ b/net/unix/sysctl_net_unix.c
106645 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
106646
106647 int __net_init unix_sysctl_register(struct net *net)
106648 {
106649 - struct ctl_table *table;
106650 + ctl_table_no_const *table;
106651
106652 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
106653 if (table == NULL)
106654 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
106655 index 9b7f207..2596621 100644
106656 --- a/net/vmw_vsock/vmci_transport_notify.c
106657 +++ b/net/vmw_vsock/vmci_transport_notify.c
106658 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
106659
106660 /* Socket control packet based operations. */
106661 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
106662 - vmci_transport_notify_pkt_socket_init,
106663 - vmci_transport_notify_pkt_socket_destruct,
106664 - vmci_transport_notify_pkt_poll_in,
106665 - vmci_transport_notify_pkt_poll_out,
106666 - vmci_transport_notify_pkt_handle_pkt,
106667 - vmci_transport_notify_pkt_recv_init,
106668 - vmci_transport_notify_pkt_recv_pre_block,
106669 - vmci_transport_notify_pkt_recv_pre_dequeue,
106670 - vmci_transport_notify_pkt_recv_post_dequeue,
106671 - vmci_transport_notify_pkt_send_init,
106672 - vmci_transport_notify_pkt_send_pre_block,
106673 - vmci_transport_notify_pkt_send_pre_enqueue,
106674 - vmci_transport_notify_pkt_send_post_enqueue,
106675 - vmci_transport_notify_pkt_process_request,
106676 - vmci_transport_notify_pkt_process_negotiate,
106677 + .socket_init = vmci_transport_notify_pkt_socket_init,
106678 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106679 + .poll_in = vmci_transport_notify_pkt_poll_in,
106680 + .poll_out = vmci_transport_notify_pkt_poll_out,
106681 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106682 + .recv_init = vmci_transport_notify_pkt_recv_init,
106683 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106684 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106685 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106686 + .send_init = vmci_transport_notify_pkt_send_init,
106687 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106688 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106689 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106690 + .process_request = vmci_transport_notify_pkt_process_request,
106691 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106692 };
106693 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
106694 index dc9c792..3089de0 100644
106695 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
106696 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
106697 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
106698
106699 /* Socket always on control packet based operations. */
106700 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
106701 - vmci_transport_notify_pkt_socket_init,
106702 - vmci_transport_notify_pkt_socket_destruct,
106703 - vmci_transport_notify_pkt_poll_in,
106704 - vmci_transport_notify_pkt_poll_out,
106705 - vmci_transport_notify_pkt_handle_pkt,
106706 - vmci_transport_notify_pkt_recv_init,
106707 - vmci_transport_notify_pkt_recv_pre_block,
106708 - vmci_transport_notify_pkt_recv_pre_dequeue,
106709 - vmci_transport_notify_pkt_recv_post_dequeue,
106710 - vmci_transport_notify_pkt_send_init,
106711 - vmci_transport_notify_pkt_send_pre_block,
106712 - vmci_transport_notify_pkt_send_pre_enqueue,
106713 - vmci_transport_notify_pkt_send_post_enqueue,
106714 - vmci_transport_notify_pkt_process_request,
106715 - vmci_transport_notify_pkt_process_negotiate,
106716 + .socket_init = vmci_transport_notify_pkt_socket_init,
106717 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106718 + .poll_in = vmci_transport_notify_pkt_poll_in,
106719 + .poll_out = vmci_transport_notify_pkt_poll_out,
106720 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106721 + .recv_init = vmci_transport_notify_pkt_recv_init,
106722 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106723 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106724 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106725 + .send_init = vmci_transport_notify_pkt_send_init,
106726 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106727 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106728 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106729 + .process_request = vmci_transport_notify_pkt_process_request,
106730 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106731 };
106732 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
106733 index c8717c1..08539f5 100644
106734 --- a/net/wireless/wext-core.c
106735 +++ b/net/wireless/wext-core.c
106736 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
106737 */
106738
106739 /* Support for very large requests */
106740 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
106741 - (user_length > descr->max_tokens)) {
106742 + if (user_length > descr->max_tokens) {
106743 /* Allow userspace to GET more than max so
106744 * we can support any size GET requests.
106745 * There is still a limit : -ENOMEM.
106746 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
106747 }
106748 }
106749
106750 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
106751 - /*
106752 - * If this is a GET, but not NOMAX, it means that the extra
106753 - * data is not bounded by userspace, but by max_tokens. Thus
106754 - * set the length to max_tokens. This matches the extra data
106755 - * allocation.
106756 - * The driver should fill it with the number of tokens it
106757 - * provided, and it may check iwp->length rather than having
106758 - * knowledge of max_tokens. If the driver doesn't change the
106759 - * iwp->length, this ioctl just copies back max_token tokens
106760 - * filled with zeroes. Hopefully the driver isn't claiming
106761 - * them to be valid data.
106762 - */
106763 - iwp->length = descr->max_tokens;
106764 - }
106765 -
106766 err = handler(dev, info, (union iwreq_data *) iwp, extra);
106767
106768 iwp->length += essid_compat;
106769 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
106770 index 4323952..a06dfe1 100644
106771 --- a/net/x25/sysctl_net_x25.c
106772 +++ b/net/x25/sysctl_net_x25.c
106773 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
106774 .mode = 0644,
106775 .proc_handler = proc_dointvec,
106776 },
106777 - { 0, },
106778 + { },
106779 };
106780
106781 void __init x25_register_sysctl(void)
106782 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
106783 index 0917f04..f4e3d8c 100644
106784 --- a/net/x25/x25_proc.c
106785 +++ b/net/x25/x25_proc.c
106786 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
106787
106788 int __init x25_proc_init(void)
106789 {
106790 - if (!proc_mkdir("x25", init_net.proc_net))
106791 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
106792 return -ENOMEM;
106793
106794 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
106795 diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
106796 index c51e8f7b..e44f360 100644
106797 --- a/net/xfrm/xfrm_output.c
106798 +++ b/net/xfrm/xfrm_output.c
106799 @@ -157,6 +157,8 @@ static int xfrm_output_gso(struct sk_buff *skb)
106800 kfree_skb(skb);
106801 if (IS_ERR(segs))
106802 return PTR_ERR(segs);
106803 + if (segs == NULL)
106804 + return -EINVAL;
106805
106806 do {
106807 struct sk_buff *nskb = segs->next;
106808 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
106809 index fdde51f..4839450 100644
106810 --- a/net/xfrm/xfrm_policy.c
106811 +++ b/net/xfrm/xfrm_policy.c
106812 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
106813 {
106814 policy->walk.dead = 1;
106815
106816 - atomic_inc(&policy->genid);
106817 + atomic_inc_unchecked(&policy->genid);
106818
106819 if (del_timer(&policy->polq.hold_timer))
106820 xfrm_pol_put(policy);
106821 @@ -664,7 +664,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
106822 hlist_add_head(&policy->bydst, chain);
106823 xfrm_pol_hold(policy);
106824 net->xfrm.policy_count[dir]++;
106825 - atomic_inc(&net->xfrm.flow_cache_genid);
106826 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
106827
106828 /* After previous checking, family can either be AF_INET or AF_INET6 */
106829 if (policy->family == AF_INET)
106830 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
106831
106832 xdst->num_pols = num_pols;
106833 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
106834 - xdst->policy_genid = atomic_read(&pols[0]->genid);
106835 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
106836
106837 return xdst;
106838 }
106839 @@ -2570,10 +2570,11 @@ void xfrm_garbage_collect(struct net *net)
106840 }
106841 EXPORT_SYMBOL(xfrm_garbage_collect);
106842
106843 -static void xfrm_garbage_collect_deferred(struct net *net)
106844 +void xfrm_garbage_collect_deferred(struct net *net)
106845 {
106846 flow_cache_flush_deferred(net);
106847 }
106848 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
106849
106850 static void xfrm_init_pmtu(struct dst_entry *dst)
106851 {
106852 @@ -2623,7 +2624,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
106853 if (xdst->xfrm_genid != dst->xfrm->genid)
106854 return 0;
106855 if (xdst->num_pols > 0 &&
106856 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
106857 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
106858 return 0;
106859
106860 mtu = dst_mtu(dst->child);
106861 @@ -2711,8 +2712,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
106862 dst_ops->link_failure = xfrm_link_failure;
106863 if (likely(dst_ops->neigh_lookup == NULL))
106864 dst_ops->neigh_lookup = xfrm_neigh_lookup;
106865 - if (likely(afinfo->garbage_collect == NULL))
106866 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
106867 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
106868 }
106869 spin_unlock(&xfrm_policy_afinfo_lock);
106870 @@ -2766,7 +2765,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
106871 dst_ops->check = NULL;
106872 dst_ops->negative_advice = NULL;
106873 dst_ops->link_failure = NULL;
106874 - afinfo->garbage_collect = NULL;
106875 }
106876 return err;
106877 }
106878 @@ -3151,7 +3149,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
106879 sizeof(pol->xfrm_vec[i].saddr));
106880 pol->xfrm_vec[i].encap_family = mp->new_family;
106881 /* flush bundles */
106882 - atomic_inc(&pol->genid);
106883 + atomic_inc_unchecked(&pol->genid);
106884 }
106885 }
106886
106887 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
106888 index 0ab5413..73dd2cf 100644
106889 --- a/net/xfrm/xfrm_state.c
106890 +++ b/net/xfrm/xfrm_state.c
106891 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
106892
106893 if (unlikely(afinfo == NULL))
106894 return -EAFNOSUPPORT;
106895 - typemap = afinfo->type_map;
106896 + typemap = (const struct xfrm_type **)afinfo->type_map;
106897 spin_lock_bh(&xfrm_type_lock);
106898
106899 - if (likely(typemap[type->proto] == NULL))
106900 + if (likely(typemap[type->proto] == NULL)) {
106901 + pax_open_kernel();
106902 typemap[type->proto] = type;
106903 - else
106904 + pax_close_kernel();
106905 + } else
106906 err = -EEXIST;
106907 spin_unlock_bh(&xfrm_type_lock);
106908 xfrm_state_put_afinfo(afinfo);
106909 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
106910
106911 if (unlikely(afinfo == NULL))
106912 return -EAFNOSUPPORT;
106913 - typemap = afinfo->type_map;
106914 + typemap = (const struct xfrm_type **)afinfo->type_map;
106915 spin_lock_bh(&xfrm_type_lock);
106916
106917 if (unlikely(typemap[type->proto] != type))
106918 err = -ENOENT;
106919 - else
106920 + else {
106921 + pax_open_kernel();
106922 typemap[type->proto] = NULL;
106923 + pax_close_kernel();
106924 + }
106925 spin_unlock_bh(&xfrm_type_lock);
106926 xfrm_state_put_afinfo(afinfo);
106927 return err;
106928 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
106929 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
106930 {
106931 struct xfrm_state_afinfo *afinfo;
106932 - const struct xfrm_type **typemap;
106933 const struct xfrm_type *type;
106934 int modload_attempted = 0;
106935
106936 @@ -218,9 +222,8 @@ retry:
106937 afinfo = xfrm_state_get_afinfo(family);
106938 if (unlikely(afinfo == NULL))
106939 return NULL;
106940 - typemap = afinfo->type_map;
106941
106942 - type = typemap[proto];
106943 + type = afinfo->type_map[proto];
106944 if (unlikely(type && !try_module_get(type->owner)))
106945 type = NULL;
106946 if (!type && !modload_attempted) {
106947 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
106948 return -EAFNOSUPPORT;
106949
106950 err = -EEXIST;
106951 - modemap = afinfo->mode_map;
106952 + modemap = (struct xfrm_mode **)afinfo->mode_map;
106953 spin_lock_bh(&xfrm_mode_lock);
106954 if (modemap[mode->encap])
106955 goto out;
106956 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
106957 if (!try_module_get(afinfo->owner))
106958 goto out;
106959
106960 - mode->afinfo = afinfo;
106961 + pax_open_kernel();
106962 + *(const void **)&mode->afinfo = afinfo;
106963 modemap[mode->encap] = mode;
106964 + pax_close_kernel();
106965 err = 0;
106966
106967 out:
106968 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
106969 return -EAFNOSUPPORT;
106970
106971 err = -ENOENT;
106972 - modemap = afinfo->mode_map;
106973 + modemap = (struct xfrm_mode **)afinfo->mode_map;
106974 spin_lock_bh(&xfrm_mode_lock);
106975 if (likely(modemap[mode->encap] == mode)) {
106976 + pax_open_kernel();
106977 modemap[mode->encap] = NULL;
106978 + pax_close_kernel();
106979 module_put(mode->afinfo->owner);
106980 err = 0;
106981 }
106982 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
106983 u32 xfrm_get_acqseq(void)
106984 {
106985 u32 res;
106986 - static atomic_t acqseq;
106987 + static atomic_unchecked_t acqseq;
106988
106989 do {
106990 - res = atomic_inc_return(&acqseq);
106991 + res = atomic_inc_return_unchecked(&acqseq);
106992 } while (!res);
106993
106994 return res;
106995 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
106996 index 05a6e3d..6716ec9 100644
106997 --- a/net/xfrm/xfrm_sysctl.c
106998 +++ b/net/xfrm/xfrm_sysctl.c
106999 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107000
107001 int __net_init xfrm_sysctl_init(struct net *net)
107002 {
107003 - struct ctl_table *table;
107004 + ctl_table_no_const *table;
107005
107006 __xfrm_sysctl_init(net);
107007
107008 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107009 index bf3e677..c7d426e 100644
107010 --- a/scripts/Makefile.build
107011 +++ b/scripts/Makefile.build
107012 @@ -60,7 +60,7 @@ endif
107013 endif
107014
107015 # Do not include host rules unless needed
107016 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107017 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107018 include scripts/Makefile.host
107019 endif
107020
107021 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107022 index a651cee..6b3b9a3 100644
107023 --- a/scripts/Makefile.clean
107024 +++ b/scripts/Makefile.clean
107025 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107026 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107027 $(always) $(targets) $(clean-files) \
107028 $(host-progs) \
107029 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107030 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107031 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107032
107033 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107034
107035 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107036 index ab5980f..85fd3e1 100644
107037 --- a/scripts/Makefile.host
107038 +++ b/scripts/Makefile.host
107039 @@ -20,7 +20,19 @@
107040 # Will compile qconf as a C++ program, and menu as a C program.
107041 # They are linked as C++ code to the executable qconf
107042
107043 +# hostprogs-y := conf
107044 +# conf-objs := conf.o libkconfig.so
107045 +# libkconfig-objs := expr.o type.o
107046 +# Will create a shared library named libkconfig.so that consists of
107047 +# expr.o and type.o (they are both compiled as C code and the object files
107048 +# are made as position independent code).
107049 +# conf.c is compiled as a C program, and conf.o is linked together with
107050 +# libkconfig.so as the executable conf.
107051 +# Note: Shared libraries consisting of C++ files are not supported
107052 +
107053 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107054 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107055 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107056
107057 # C code
107058 # Executables compiled from a single .c file
107059 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107060 # C++ Object (.o) files compiled from .cc files
107061 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107062
107063 +# Shared libaries (only .c supported)
107064 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107065 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107066 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107067 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107068 +# Remove .so files from "xxx-objs"
107069 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107070 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107071 +
107072 +# Object (.o) files used by the shared libaries
107073 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107074 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107075 +
107076 # output directory for programs/.o files
107077 # hostprogs-y := tools/build may have been specified.
107078 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107079 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107080 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107081 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107082 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107083 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107084 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107085 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107086 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107087 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107088
107089 obj-dirs += $(host-objdirs)
107090 @@ -96,7 +125,7 @@ quiet_cmd_host-cmulti = HOSTLD $@
107091 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
107092 $(addprefix $(obj)/,$($(@F)-objs)) \
107093 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107094 -$(host-cmulti): $(obj)/%: $(host-cobjs) FORCE
107095 +$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE
107096 $(call if_changed,host-cmulti)
107097
107098 # Create .o file from a single .c file
107099 @@ -113,7 +142,7 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
107100 $(foreach o,objs cxxobjs,\
107101 $(addprefix $(obj)/,$($(@F)-$(o)))) \
107102 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107103 -$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) FORCE
107104 +$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
107105 $(call if_changed,host-cxxmulti)
107106
107107 # Create .o file from a single .cc (C++) file
107108 @@ -122,5 +151,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107109 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107110 $(call if_changed_dep,host-cxxobjs)
107111
107112 +# Compile .c file, create position independent .o file
107113 +# host-cshobjs -> .o
107114 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107115 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107116 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107117 + $(call if_changed_dep,host-cshobjs)
107118 +
107119 +# Compile .c file, create position independent .o file
107120 +# host-cxxshobjs -> .o
107121 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107122 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107123 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107124 + $(call if_changed_dep,host-cxxshobjs)
107125 +
107126 +# Link a shared library, based on position independent .o files
107127 +# *.o -> .so shared library (host-cshlib)
107128 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107129 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107130 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107131 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107132 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107133 + $(call if_changed,host-cshlib)
107134 +
107135 +# Link a shared library, based on position independent .o files
107136 +# *.o -> .so shared library (host-cxxshlib)
107137 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107138 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107139 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107140 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107141 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107142 + $(call if_changed,host-cxxshlib)
107143 +
107144 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107145 - $(host-cxxmulti) $(host-cxxobjs)
107146 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107147 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107148 index b304068..462d24e 100644
107149 --- a/scripts/basic/fixdep.c
107150 +++ b/scripts/basic/fixdep.c
107151 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107152 /*
107153 * Lookup a value in the configuration string.
107154 */
107155 -static int is_defined_config(const char *name, int len, unsigned int hash)
107156 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107157 {
107158 struct item *aux;
107159
107160 @@ -211,10 +211,10 @@ static void clear_config(void)
107161 /*
107162 * Record the use of a CONFIG_* word.
107163 */
107164 -static void use_config(const char *m, int slen)
107165 +static void use_config(const char *m, unsigned int slen)
107166 {
107167 unsigned int hash = strhash(m, slen);
107168 - int c, i;
107169 + unsigned int c, i;
107170
107171 if (is_defined_config(m, slen, hash))
107172 return;
107173 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107174
107175 static void parse_config_file(const char *map, size_t len)
107176 {
107177 - const int *end = (const int *) (map + len);
107178 + const unsigned int *end = (const unsigned int *) (map + len);
107179 /* start at +1, so that p can never be < map */
107180 - const int *m = (const int *) map + 1;
107181 + const unsigned int *m = (const unsigned int *) map + 1;
107182 const char *p, *q;
107183
107184 for (; m < end; m++) {
107185 @@ -435,7 +435,7 @@ static void print_deps(void)
107186 static void traps(void)
107187 {
107188 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107189 - int *p = (int *)test;
107190 + unsigned int *p = (unsigned int *)test;
107191
107192 if (*p != INT_CONF) {
107193 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107194 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107195 new file mode 100644
107196 index 0000000..42018ed
107197 --- /dev/null
107198 +++ b/scripts/gcc-plugin.sh
107199 @@ -0,0 +1,51 @@
107200 +#!/bin/sh
107201 +srctree=$(dirname "$0")
107202 +gccplugins_dir=$($3 -print-file-name=plugin)
107203 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107204 +#include "gcc-common.h"
107205 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107206 +#warning $2 CXX
107207 +#else
107208 +#warning $1 CC
107209 +#endif
107210 +EOF
107211 +)
107212 +
107213 +if [ $? -ne 0 ]
107214 +then
107215 + exit 1
107216 +fi
107217 +
107218 +case "$plugincc" in
107219 + *"$1 CC"*)
107220 + echo "$1"
107221 + exit 0
107222 + ;;
107223 +
107224 + *"$2 CXX"*)
107225 + # the c++ compiler needs another test, see below
107226 + ;;
107227 +
107228 + *)
107229 + exit 1
107230 + ;;
107231 +esac
107232 +
107233 +# we need a c++ compiler that supports the designated initializer GNU extension
107234 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107235 +#include "gcc-common.h"
107236 +class test {
107237 +public:
107238 + int test;
107239 +} test = {
107240 + .test = 1
107241 +};
107242 +EOF
107243 +)
107244 +
107245 +if [ $? -eq 0 ]
107246 +then
107247 + echo "$2"
107248 + exit 0
107249 +fi
107250 +exit 1
107251 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107252 index 5de5660..d3deb89 100644
107253 --- a/scripts/headers_install.sh
107254 +++ b/scripts/headers_install.sh
107255 @@ -32,6 +32,7 @@ do
107256 FILE="$(basename "$i")"
107257 sed -r \
107258 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107259 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107260 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107261 -e 's@^#include <linux/compiler.h>@@' \
107262 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107263 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107264 index 86a4fe7..99e91f9 100644
107265 --- a/scripts/link-vmlinux.sh
107266 +++ b/scripts/link-vmlinux.sh
107267 @@ -166,7 +166,7 @@ else
107268 fi;
107269
107270 # final build of init/
107271 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107272 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107273
107274 kallsymso=""
107275 kallsyms_vmlinux=""
107276 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107277 index e614ef6..d9d2b01 100644
107278 --- a/scripts/mod/file2alias.c
107279 +++ b/scripts/mod/file2alias.c
107280 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107281 unsigned long size, unsigned long id_size,
107282 void *symval)
107283 {
107284 - int i;
107285 + unsigned int i;
107286
107287 if (size % id_size || size < id_size) {
107288 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107289 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107290 /* USB is special because the bcdDevice can be matched against a numeric range */
107291 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107292 static void do_usb_entry(void *symval,
107293 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107294 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107295 unsigned char range_lo, unsigned char range_hi,
107296 unsigned char max, struct module *mod)
107297 {
107298 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107299 {
107300 unsigned int devlo, devhi;
107301 unsigned char chi, clo, max;
107302 - int ndigits;
107303 + unsigned int ndigits;
107304
107305 DEF_FIELD(symval, usb_device_id, match_flags);
107306 DEF_FIELD(symval, usb_device_id, idVendor);
107307 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107308 for (i = 0; i < count; i++) {
107309 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107310 char acpi_id[sizeof(*id)];
107311 - int j;
107312 + unsigned int j;
107313
107314 buf_printf(&mod->dev_table_buf,
107315 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107316 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107317
107318 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107319 const char *id = (char *)(*devs)[j].id;
107320 - int i2, j2;
107321 + unsigned int i2, j2;
107322 int dup = 0;
107323
107324 if (!id[0])
107325 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107326 /* add an individual alias for every device entry */
107327 if (!dup) {
107328 char acpi_id[PNP_ID_LEN];
107329 - int k;
107330 + unsigned int k;
107331
107332 buf_printf(&mod->dev_table_buf,
107333 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107334 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107335 static int do_dmi_entry(const char *filename, void *symval,
107336 char *alias)
107337 {
107338 - int i, j;
107339 + unsigned int i, j;
107340 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107341 sprintf(alias, "dmi*");
107342
107343 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107344 index 091d905..77b88c7 100644
107345 --- a/scripts/mod/modpost.c
107346 +++ b/scripts/mod/modpost.c
107347 @@ -920,6 +920,7 @@ enum mismatch {
107348 ANY_INIT_TO_ANY_EXIT,
107349 ANY_EXIT_TO_ANY_INIT,
107350 EXPORT_TO_INIT_EXIT,
107351 + DATA_TO_TEXT
107352 };
107353
107354 struct sectioncheck {
107355 @@ -1006,6 +1007,12 @@ const struct sectioncheck sectioncheck[] = {
107356 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
107357 .mismatch = EXPORT_TO_INIT_EXIT,
107358 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
107359 +},
107360 +/* Do not reference code from writable data */
107361 +{
107362 + .fromsec = { DATA_SECTIONS, NULL },
107363 + .tosec = { TEXT_SECTIONS, NULL },
107364 + .mismatch = DATA_TO_TEXT
107365 }
107366 };
107367
107368 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
107369 continue;
107370 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
107371 continue;
107372 - if (sym->st_value == addr)
107373 - return sym;
107374 /* Find a symbol nearby - addr are maybe negative */
107375 d = sym->st_value - addr;
107376 + if (d == 0)
107377 + return sym;
107378 if (d < 0)
107379 d = addr - sym->st_value;
107380 if (d < distance) {
107381 @@ -1407,6 +1414,14 @@ static void report_sec_mismatch(const char *modname,
107382 tosym, prl_to, prl_to, tosym);
107383 free(prl_to);
107384 break;
107385 + case DATA_TO_TEXT:
107386 +#if 0
107387 + fprintf(stderr,
107388 + "The %s %s:%s references\n"
107389 + "the %s %s:%s%s\n",
107390 + from, fromsec, fromsym, to, tosec, tosym, to_p);
107391 +#endif
107392 + break;
107393 }
107394 fprintf(stderr, "\n");
107395 }
107396 @@ -1658,7 +1673,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
107397 static void check_sec_ref(struct module *mod, const char *modname,
107398 struct elf_info *elf)
107399 {
107400 - int i;
107401 + unsigned int i;
107402 Elf_Shdr *sechdrs = elf->sechdrs;
107403
107404 /* Walk through all sections */
107405 @@ -1789,7 +1804,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
107406 va_end(ap);
107407 }
107408
107409 -void buf_write(struct buffer *buf, const char *s, int len)
107410 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
107411 {
107412 if (buf->size - buf->pos < len) {
107413 buf->size += len + SZ;
107414 @@ -2008,7 +2023,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
107415 if (fstat(fileno(file), &st) < 0)
107416 goto close_write;
107417
107418 - if (st.st_size != b->pos)
107419 + if (st.st_size != (off_t)b->pos)
107420 goto close_write;
107421
107422 tmp = NOFAIL(malloc(b->pos));
107423 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
107424 index 168b43d..77914bf 100644
107425 --- a/scripts/mod/modpost.h
107426 +++ b/scripts/mod/modpost.h
107427 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
107428
107429 struct buffer {
107430 char *p;
107431 - int pos;
107432 - int size;
107433 + unsigned int pos;
107434 + unsigned int size;
107435 };
107436
107437 void __attribute__((format(printf, 2, 3)))
107438 buf_printf(struct buffer *buf, const char *fmt, ...);
107439
107440 void
107441 -buf_write(struct buffer *buf, const char *s, int len);
107442 +buf_write(struct buffer *buf, const char *s, unsigned int len);
107443
107444 struct module {
107445 struct module *next;
107446 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
107447 index 944418d..15291e4 100644
107448 --- a/scripts/mod/sumversion.c
107449 +++ b/scripts/mod/sumversion.c
107450 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
107451 goto out;
107452 }
107453
107454 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
107455 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
107456 warn("writing sum in %s failed: %s\n",
107457 filename, strerror(errno));
107458 goto out;
107459 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
107460 index 0865b3e..7235dd4 100644
107461 --- a/scripts/module-common.lds
107462 +++ b/scripts/module-common.lds
107463 @@ -6,6 +6,10 @@
107464 SECTIONS {
107465 /DISCARD/ : { *(.discard) }
107466
107467 + .rodata : {
107468 + *(.rodata) *(.rodata.*)
107469 + *(.data..read_only)
107470 + }
107471 __ksymtab : { *(SORT(___ksymtab+*)) }
107472 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
107473 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
107474 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
107475 index 7c0e6e4..bf2c90e 100644
107476 --- a/scripts/package/builddeb
107477 +++ b/scripts/package/builddeb
107478 @@ -293,6 +293,7 @@ fi
107479 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
107480 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
107481 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
107482 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
107483 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
107484 mkdir -p "$destdir"
107485 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
107486 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
107487 index 1395760..e4f4ac4 100755
107488 --- a/scripts/package/mkspec
107489 +++ b/scripts/package/mkspec
107490 @@ -82,6 +82,16 @@ echo ""
107491 fi
107492
107493 echo "%install"
107494 +echo 'chmod -f 0500 /boot'
107495 +echo 'if [ -d /lib/modules ]; then'
107496 +echo 'chmod -f 0500 /lib/modules'
107497 +echo 'fi'
107498 +echo 'if [ -d /lib32/modules ]; then'
107499 +echo 'chmod -f 0500 /lib32/modules'
107500 +echo 'fi'
107501 +echo 'if [ -d /lib64/modules ]; then'
107502 +echo 'chmod -f 0500 /lib64/modules'
107503 +echo 'fi'
107504 echo 'KBUILD_IMAGE=$(make image_name)'
107505 echo "%ifarch ia64"
107506 echo 'mkdir -p $RPM_BUILD_ROOT/boot/efi $RPM_BUILD_ROOT/lib/modules'
107507 @@ -139,7 +149,7 @@ echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm
107508 echo "fi"
107509 echo ""
107510 echo "%files"
107511 -echo '%defattr (-, root, root)'
107512 +echo '%defattr (400, root, root, 500)'
107513 echo "%dir /lib/modules"
107514 echo "/lib/modules/$KERNELRELEASE"
107515 echo "%exclude /lib/modules/$KERNELRELEASE/build"
107516 @@ -152,7 +162,7 @@ echo '%defattr (-, root, root)'
107517 echo "/usr/include"
107518 echo ""
107519 echo "%files devel"
107520 -echo '%defattr (-, root, root)'
107521 +echo '%defattr (400, root, root, 500)'
107522 echo "/usr/src/kernels/$KERNELRELEASE"
107523 echo "/lib/modules/$KERNELRELEASE/build"
107524 echo "/lib/modules/$KERNELRELEASE/source"
107525 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
107526 index 4718d78..9220d58 100644
107527 --- a/scripts/pnmtologo.c
107528 +++ b/scripts/pnmtologo.c
107529 @@ -244,14 +244,14 @@ static void write_header(void)
107530 fprintf(out, " * Linux logo %s\n", logoname);
107531 fputs(" */\n\n", out);
107532 fputs("#include <linux/linux_logo.h>\n\n", out);
107533 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
107534 + fprintf(out, "static unsigned char %s_data[] = {\n",
107535 logoname);
107536 }
107537
107538 static void write_footer(void)
107539 {
107540 fputs("\n};\n\n", out);
107541 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
107542 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
107543 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
107544 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
107545 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
107546 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
107547 fputs("\n};\n\n", out);
107548
107549 /* write logo clut */
107550 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
107551 + fprintf(out, "static unsigned char %s_clut[] = {\n",
107552 logoname);
107553 write_hex_cnt = 0;
107554 for (i = 0; i < logo_clutsize; i++) {
107555 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
107556 index 8fac3fd..32ff38d 100644
107557 --- a/scripts/sortextable.h
107558 +++ b/scripts/sortextable.h
107559 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
107560 const char *secstrtab;
107561 const char *strtab;
107562 char *extab_image;
107563 - int extab_index = 0;
107564 - int i;
107565 - int idx;
107566 + unsigned int extab_index = 0;
107567 + unsigned int i;
107568 + unsigned int idx;
107569 unsigned int num_sections;
107570 unsigned int secindex_strings;
107571
107572 diff --git a/scripts/tags.sh b/scripts/tags.sh
107573 index 293828b..9fbe696 100755
107574 --- a/scripts/tags.sh
107575 +++ b/scripts/tags.sh
107576 @@ -26,7 +26,7 @@ else
107577 fi
107578
107579 # ignore userspace tools
107580 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
107581 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
107582
107583 # Find all available archs
107584 find_all_archs()
107585 diff --git a/security/Kconfig b/security/Kconfig
107586 index beb86b5..00daaca 100644
107587 --- a/security/Kconfig
107588 +++ b/security/Kconfig
107589 @@ -4,6 +4,969 @@
107590
107591 menu "Security options"
107592
107593 +menu "Grsecurity"
107594 +
107595 + config ARCH_TRACK_EXEC_LIMIT
107596 + bool
107597 +
107598 + config PAX_KERNEXEC_PLUGIN
107599 + bool
107600 +
107601 + config PAX_PER_CPU_PGD
107602 + bool
107603 +
107604 + config TASK_SIZE_MAX_SHIFT
107605 + int
107606 + depends on X86_64
107607 + default 47 if !PAX_PER_CPU_PGD
107608 + default 42 if PAX_PER_CPU_PGD
107609 +
107610 + config PAX_ENABLE_PAE
107611 + bool
107612 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
107613 +
107614 + config PAX_USERCOPY_SLABS
107615 + bool
107616 +
107617 +config GRKERNSEC
107618 + bool "Grsecurity"
107619 + select CRYPTO
107620 + select CRYPTO_SHA256
107621 + select PROC_FS
107622 + select STOP_MACHINE
107623 + select TTY
107624 + select DEBUG_KERNEL
107625 + select DEBUG_LIST
107626 + help
107627 + If you say Y here, you will be able to configure many features
107628 + that will enhance the security of your system. It is highly
107629 + recommended that you say Y here and read through the help
107630 + for each option so that you fully understand the features and
107631 + can evaluate their usefulness for your machine.
107632 +
107633 +choice
107634 + prompt "Configuration Method"
107635 + depends on GRKERNSEC
107636 + default GRKERNSEC_CONFIG_CUSTOM
107637 + help
107638 +
107639 +config GRKERNSEC_CONFIG_AUTO
107640 + bool "Automatic"
107641 + help
107642 + If you choose this configuration method, you'll be able to answer a small
107643 + number of simple questions about how you plan to use this kernel.
107644 + The settings of grsecurity and PaX will be automatically configured for
107645 + the highest commonly-used settings within the provided constraints.
107646 +
107647 + If you require additional configuration, custom changes can still be made
107648 + from the "custom configuration" menu.
107649 +
107650 +config GRKERNSEC_CONFIG_CUSTOM
107651 + bool "Custom"
107652 + help
107653 + If you choose this configuration method, you'll be able to configure all
107654 + grsecurity and PaX settings manually. Via this method, no options are
107655 + automatically enabled.
107656 +
107657 +endchoice
107658 +
107659 +choice
107660 + prompt "Usage Type"
107661 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107662 + default GRKERNSEC_CONFIG_SERVER
107663 + help
107664 +
107665 +config GRKERNSEC_CONFIG_SERVER
107666 + bool "Server"
107667 + help
107668 + Choose this option if you plan to use this kernel on a server.
107669 +
107670 +config GRKERNSEC_CONFIG_DESKTOP
107671 + bool "Desktop"
107672 + help
107673 + Choose this option if you plan to use this kernel on a desktop.
107674 +
107675 +endchoice
107676 +
107677 +choice
107678 + prompt "Virtualization Type"
107679 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
107680 + default GRKERNSEC_CONFIG_VIRT_NONE
107681 + help
107682 +
107683 +config GRKERNSEC_CONFIG_VIRT_NONE
107684 + bool "None"
107685 + help
107686 + Choose this option if this kernel will be run on bare metal.
107687 +
107688 +config GRKERNSEC_CONFIG_VIRT_GUEST
107689 + bool "Guest"
107690 + help
107691 + Choose this option if this kernel will be run as a VM guest.
107692 +
107693 +config GRKERNSEC_CONFIG_VIRT_HOST
107694 + bool "Host"
107695 + help
107696 + Choose this option if this kernel will be run as a VM host.
107697 +
107698 +endchoice
107699 +
107700 +choice
107701 + prompt "Virtualization Hardware"
107702 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
107703 + help
107704 +
107705 +config GRKERNSEC_CONFIG_VIRT_EPT
107706 + bool "EPT/RVI Processor Support"
107707 + depends on X86
107708 + help
107709 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
107710 + hardware virtualization. This allows for additional kernel hardening protections
107711 + to operate without additional performance impact.
107712 +
107713 + To see if your Intel processor supports EPT, see:
107714 + http://ark.intel.com/Products/VirtualizationTechnology
107715 + (Most Core i3/5/7 support EPT)
107716 +
107717 + To see if your AMD processor supports RVI, see:
107718 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
107719 +
107720 +config GRKERNSEC_CONFIG_VIRT_SOFT
107721 + bool "First-gen/No Hardware Virtualization"
107722 + help
107723 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
107724 + support hardware virtualization or doesn't support the EPT/RVI extensions.
107725 +
107726 +endchoice
107727 +
107728 +choice
107729 + prompt "Virtualization Software"
107730 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
107731 + help
107732 +
107733 +config GRKERNSEC_CONFIG_VIRT_XEN
107734 + bool "Xen"
107735 + help
107736 + Choose this option if this kernel is running as a Xen guest or host.
107737 +
107738 +config GRKERNSEC_CONFIG_VIRT_VMWARE
107739 + bool "VMWare"
107740 + help
107741 + Choose this option if this kernel is running as a VMWare guest or host.
107742 +
107743 +config GRKERNSEC_CONFIG_VIRT_KVM
107744 + bool "KVM"
107745 + help
107746 + Choose this option if this kernel is running as a KVM guest or host.
107747 +
107748 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
107749 + bool "VirtualBox"
107750 + help
107751 + Choose this option if this kernel is running as a VirtualBox guest or host.
107752 +
107753 +endchoice
107754 +
107755 +choice
107756 + prompt "Required Priorities"
107757 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107758 + default GRKERNSEC_CONFIG_PRIORITY_PERF
107759 + help
107760 +
107761 +config GRKERNSEC_CONFIG_PRIORITY_PERF
107762 + bool "Performance"
107763 + help
107764 + Choose this option if performance is of highest priority for this deployment
107765 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
107766 + clearing of structures intended for userland, and freed memory sanitizing will
107767 + be disabled.
107768 +
107769 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
107770 + bool "Security"
107771 + help
107772 + Choose this option if security is of highest priority for this deployment of
107773 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
107774 + for userland, and freed memory sanitizing will be enabled for this kernel.
107775 + In a worst-case scenario, these features can introduce a 20% performance hit
107776 + (UDEREF on x64 contributing half of this hit).
107777 +
107778 +endchoice
107779 +
107780 +menu "Default Special Groups"
107781 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107782 +
107783 +config GRKERNSEC_PROC_GID
107784 + int "GID exempted from /proc restrictions"
107785 + default 1001
107786 + help
107787 + Setting this GID determines which group will be exempted from
107788 + grsecurity's /proc restrictions, allowing users of the specified
107789 + group to view network statistics and the existence of other users'
107790 + processes on the system. This GID may also be chosen at boot time
107791 + via "grsec_proc_gid=" on the kernel commandline.
107792 +
107793 +config GRKERNSEC_TPE_UNTRUSTED_GID
107794 + int "GID for TPE-untrusted users"
107795 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
107796 + default 1005
107797 + help
107798 + Setting this GID determines which group untrusted users should
107799 + be added to. These users will be placed under grsecurity's Trusted Path
107800 + Execution mechanism, preventing them from executing their own binaries.
107801 + The users will only be able to execute binaries in directories owned and
107802 + writable only by the root user. If the sysctl option is enabled, a sysctl
107803 + option with name "tpe_gid" is created.
107804 +
107805 +config GRKERNSEC_TPE_TRUSTED_GID
107806 + int "GID for TPE-trusted users"
107807 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
107808 + default 1005
107809 + help
107810 + Setting this GID determines what group TPE restrictions will be
107811 + *disabled* for. If the sysctl option is enabled, a sysctl option
107812 + with name "tpe_gid" is created.
107813 +
107814 +config GRKERNSEC_SYMLINKOWN_GID
107815 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
107816 + depends on GRKERNSEC_CONFIG_SERVER
107817 + default 1006
107818 + help
107819 + Setting this GID determines what group kernel-enforced
107820 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
107821 + is enabled, a sysctl option with name "symlinkown_gid" is created.
107822 +
107823 +
107824 +endmenu
107825 +
107826 +menu "Customize Configuration"
107827 +depends on GRKERNSEC
107828 +
107829 +menu "PaX"
107830 +
107831 +config PAX
107832 + bool "Enable various PaX features"
107833 + default y if GRKERNSEC_CONFIG_AUTO
107834 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
107835 + help
107836 + This allows you to enable various PaX features. PaX adds
107837 + intrusion prevention mechanisms to the kernel that reduce
107838 + the risks posed by exploitable memory corruption bugs.
107839 +
107840 +menu "PaX Control"
107841 + depends on PAX
107842 +
107843 +config PAX_SOFTMODE
107844 + bool 'Support soft mode'
107845 + help
107846 + Enabling this option will allow you to run PaX in soft mode, that
107847 + is, PaX features will not be enforced by default, only on executables
107848 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
107849 + support as they are the only way to mark executables for soft mode use.
107850 +
107851 + Soft mode can be activated by using the "pax_softmode=1" kernel command
107852 + line option on boot. Furthermore you can control various PaX features
107853 + at runtime via the entries in /proc/sys/kernel/pax.
107854 +
107855 +config PAX_EI_PAX
107856 + bool 'Use legacy ELF header marking'
107857 + default y if GRKERNSEC_CONFIG_AUTO
107858 + help
107859 + Enabling this option will allow you to control PaX features on
107860 + a per executable basis via the 'chpax' utility available at
107861 + http://pax.grsecurity.net/. The control flags will be read from
107862 + an otherwise reserved part of the ELF header. This marking has
107863 + numerous drawbacks (no support for soft-mode, toolchain does not
107864 + know about the non-standard use of the ELF header) therefore it
107865 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
107866 + support.
107867 +
107868 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
107869 + support as well, they will override the legacy EI_PAX marks.
107870 +
107871 + If you enable none of the marking options then all applications
107872 + will run with PaX enabled on them by default.
107873 +
107874 +config PAX_PT_PAX_FLAGS
107875 + bool 'Use ELF program header marking'
107876 + default y if GRKERNSEC_CONFIG_AUTO
107877 + help
107878 + Enabling this option will allow you to control PaX features on
107879 + a per executable basis via the 'paxctl' utility available at
107880 + http://pax.grsecurity.net/. The control flags will be read from
107881 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
107882 + has the benefits of supporting both soft mode and being fully
107883 + integrated into the toolchain (the binutils patch is available
107884 + from http://pax.grsecurity.net).
107885 +
107886 + Note that if you enable the legacy EI_PAX marking support as well,
107887 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
107888 +
107889 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
107890 + must make sure that the marks are the same if a binary has both marks.
107891 +
107892 + If you enable none of the marking options then all applications
107893 + will run with PaX enabled on them by default.
107894 +
107895 +config PAX_XATTR_PAX_FLAGS
107896 + bool 'Use filesystem extended attributes marking'
107897 + default y if GRKERNSEC_CONFIG_AUTO
107898 + select CIFS_XATTR if CIFS
107899 + select F2FS_FS_XATTR if F2FS_FS
107900 + select EXT2_FS_XATTR if EXT2_FS
107901 + select EXT3_FS_XATTR if EXT3_FS
107902 + select JFFS2_FS_XATTR if JFFS2_FS
107903 + select REISERFS_FS_XATTR if REISERFS_FS
107904 + select SQUASHFS_XATTR if SQUASHFS
107905 + select TMPFS_XATTR if TMPFS
107906 + help
107907 + Enabling this option will allow you to control PaX features on
107908 + a per executable basis via the 'setfattr' utility. The control
107909 + flags will be read from the user.pax.flags extended attribute of
107910 + the file. This marking has the benefit of supporting binary-only
107911 + applications that self-check themselves (e.g., skype) and would
107912 + not tolerate chpax/paxctl changes. The main drawback is that
107913 + extended attributes are not supported by some filesystems (e.g.,
107914 + isofs, udf, vfat) so copying files through such filesystems will
107915 + lose the extended attributes and these PaX markings.
107916 +
107917 + Note that if you enable the legacy EI_PAX marking support as well,
107918 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
107919 +
107920 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
107921 + must make sure that the marks are the same if a binary has both marks.
107922 +
107923 + If you enable none of the marking options then all applications
107924 + will run with PaX enabled on them by default.
107925 +
107926 +choice
107927 + prompt 'MAC system integration'
107928 + default PAX_HAVE_ACL_FLAGS
107929 + help
107930 + Mandatory Access Control systems have the option of controlling
107931 + PaX flags on a per executable basis, choose the method supported
107932 + by your particular system.
107933 +
107934 + - "none": if your MAC system does not interact with PaX,
107935 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
107936 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
107937 +
107938 + NOTE: this option is for developers/integrators only.
107939 +
107940 + config PAX_NO_ACL_FLAGS
107941 + bool 'none'
107942 +
107943 + config PAX_HAVE_ACL_FLAGS
107944 + bool 'direct'
107945 +
107946 + config PAX_HOOK_ACL_FLAGS
107947 + bool 'hook'
107948 +endchoice
107949 +
107950 +endmenu
107951 +
107952 +menu "Non-executable pages"
107953 + depends on PAX
107954 +
107955 +config PAX_NOEXEC
107956 + bool "Enforce non-executable pages"
107957 + default y if GRKERNSEC_CONFIG_AUTO
107958 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
107959 + help
107960 + By design some architectures do not allow for protecting memory
107961 + pages against execution or even if they do, Linux does not make
107962 + use of this feature. In practice this means that if a page is
107963 + readable (such as the stack or heap) it is also executable.
107964 +
107965 + There is a well known exploit technique that makes use of this
107966 + fact and a common programming mistake where an attacker can
107967 + introduce code of his choice somewhere in the attacked program's
107968 + memory (typically the stack or the heap) and then execute it.
107969 +
107970 + If the attacked program was running with different (typically
107971 + higher) privileges than that of the attacker, then he can elevate
107972 + his own privilege level (e.g. get a root shell, write to files for
107973 + which he does not have write access to, etc).
107974 +
107975 + Enabling this option will let you choose from various features
107976 + that prevent the injection and execution of 'foreign' code in
107977 + a program.
107978 +
107979 + This will also break programs that rely on the old behaviour and
107980 + expect that dynamically allocated memory via the malloc() family
107981 + of functions is executable (which it is not). Notable examples
107982 + are the XFree86 4.x server, the java runtime and wine.
107983 +
107984 +config PAX_PAGEEXEC
107985 + bool "Paging based non-executable pages"
107986 + default y if GRKERNSEC_CONFIG_AUTO
107987 + 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)
107988 + select ARCH_TRACK_EXEC_LIMIT if X86_32
107989 + help
107990 + This implementation is based on the paging feature of the CPU.
107991 + On i386 without hardware non-executable bit support there is a
107992 + variable but usually low performance impact, however on Intel's
107993 + P4 core based CPUs it is very high so you should not enable this
107994 + for kernels meant to be used on such CPUs.
107995 +
107996 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
107997 + with hardware non-executable bit support there is no performance
107998 + impact, on ppc the impact is negligible.
107999 +
108000 + Note that several architectures require various emulations due to
108001 + badly designed userland ABIs, this will cause a performance impact
108002 + but will disappear as soon as userland is fixed. For example, ppc
108003 + userland MUST have been built with secure-plt by a recent toolchain.
108004 +
108005 +config PAX_SEGMEXEC
108006 + bool "Segmentation based non-executable pages"
108007 + default y if GRKERNSEC_CONFIG_AUTO
108008 + depends on PAX_NOEXEC && X86_32
108009 + help
108010 + This implementation is based on the segmentation feature of the
108011 + CPU and has a very small performance impact, however applications
108012 + will be limited to a 1.5 GB address space instead of the normal
108013 + 3 GB.
108014 +
108015 +config PAX_EMUTRAMP
108016 + bool "Emulate trampolines"
108017 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108018 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108019 + help
108020 + There are some programs and libraries that for one reason or
108021 + another attempt to execute special small code snippets from
108022 + non-executable memory pages. Most notable examples are the
108023 + signal handler return code generated by the kernel itself and
108024 + the GCC trampolines.
108025 +
108026 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108027 + such programs will no longer work under your kernel.
108028 +
108029 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108030 + utilities to enable trampoline emulation for the affected programs
108031 + yet still have the protection provided by the non-executable pages.
108032 +
108033 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108034 + your system will not even boot.
108035 +
108036 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108037 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108038 + for the affected files.
108039 +
108040 + NOTE: enabling this feature *may* open up a loophole in the
108041 + protection provided by non-executable pages that an attacker
108042 + could abuse. Therefore the best solution is to not have any
108043 + files on your system that would require this option. This can
108044 + be achieved by not using libc5 (which relies on the kernel
108045 + signal handler return code) and not using or rewriting programs
108046 + that make use of the nested function implementation of GCC.
108047 + Skilled users can just fix GCC itself so that it implements
108048 + nested function calls in a way that does not interfere with PaX.
108049 +
108050 +config PAX_EMUSIGRT
108051 + bool "Automatically emulate sigreturn trampolines"
108052 + depends on PAX_EMUTRAMP && PARISC
108053 + default y
108054 + help
108055 + Enabling this option will have the kernel automatically detect
108056 + and emulate signal return trampolines executing on the stack
108057 + that would otherwise lead to task termination.
108058 +
108059 + This solution is intended as a temporary one for users with
108060 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108061 + Modula-3 runtime, etc) or executables linked to such, basically
108062 + everything that does not specify its own SA_RESTORER function in
108063 + normal executable memory like glibc 2.1+ does.
108064 +
108065 + On parisc you MUST enable this option, otherwise your system will
108066 + not even boot.
108067 +
108068 + NOTE: this feature cannot be disabled on a per executable basis
108069 + and since it *does* open up a loophole in the protection provided
108070 + by non-executable pages, the best solution is to not have any
108071 + files on your system that would require this option.
108072 +
108073 +config PAX_MPROTECT
108074 + bool "Restrict mprotect()"
108075 + default y if GRKERNSEC_CONFIG_AUTO
108076 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108077 + help
108078 + Enabling this option will prevent programs from
108079 + - changing the executable status of memory pages that were
108080 + not originally created as executable,
108081 + - making read-only executable pages writable again,
108082 + - creating executable pages from anonymous memory,
108083 + - making read-only-after-relocations (RELRO) data pages writable again.
108084 +
108085 + You should say Y here to complete the protection provided by
108086 + the enforcement of non-executable pages.
108087 +
108088 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108089 + this feature on a per file basis.
108090 +
108091 +config PAX_MPROTECT_COMPAT
108092 + bool "Use legacy/compat protection demoting (read help)"
108093 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108094 + depends on PAX_MPROTECT
108095 + help
108096 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108097 + by sending the proper error code to the application. For some broken
108098 + userland, this can cause problems with Python or other applications. The
108099 + current implementation however allows for applications like clamav to
108100 + detect if JIT compilation/execution is allowed and to fall back gracefully
108101 + to an interpreter-based mode if it does not. While we encourage everyone
108102 + to use the current implementation as-is and push upstream to fix broken
108103 + userland (note that the RWX logging option can assist with this), in some
108104 + environments this may not be possible. Having to disable MPROTECT
108105 + completely on certain binaries reduces the security benefit of PaX,
108106 + so this option is provided for those environments to revert to the old
108107 + behavior.
108108 +
108109 +config PAX_ELFRELOCS
108110 + bool "Allow ELF text relocations (read help)"
108111 + depends on PAX_MPROTECT
108112 + default n
108113 + help
108114 + Non-executable pages and mprotect() restrictions are effective
108115 + in preventing the introduction of new executable code into an
108116 + attacked task's address space. There remain only two venues
108117 + for this kind of attack: if the attacker can execute already
108118 + existing code in the attacked task then he can either have it
108119 + create and mmap() a file containing his code or have it mmap()
108120 + an already existing ELF library that does not have position
108121 + independent code in it and use mprotect() on it to make it
108122 + writable and copy his code there. While protecting against
108123 + the former approach is beyond PaX, the latter can be prevented
108124 + by having only PIC ELF libraries on one's system (which do not
108125 + need to relocate their code). If you are sure this is your case,
108126 + as is the case with all modern Linux distributions, then leave
108127 + this option disabled. You should say 'n' here.
108128 +
108129 +config PAX_ETEXECRELOCS
108130 + bool "Allow ELF ET_EXEC text relocations"
108131 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108132 + select PAX_ELFRELOCS
108133 + default y
108134 + help
108135 + On some architectures there are incorrectly created applications
108136 + that require text relocations and would not work without enabling
108137 + this option. If you are an alpha, ia64 or parisc user, you should
108138 + enable this option and disable it once you have made sure that
108139 + none of your applications need it.
108140 +
108141 +config PAX_EMUPLT
108142 + bool "Automatically emulate ELF PLT"
108143 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108144 + default y
108145 + help
108146 + Enabling this option will have the kernel automatically detect
108147 + and emulate the Procedure Linkage Table entries in ELF files.
108148 + On some architectures such entries are in writable memory, and
108149 + become non-executable leading to task termination. Therefore
108150 + it is mandatory that you enable this option on alpha, parisc,
108151 + sparc and sparc64, otherwise your system would not even boot.
108152 +
108153 + NOTE: this feature *does* open up a loophole in the protection
108154 + provided by the non-executable pages, therefore the proper
108155 + solution is to modify the toolchain to produce a PLT that does
108156 + not need to be writable.
108157 +
108158 +config PAX_DLRESOLVE
108159 + bool 'Emulate old glibc resolver stub'
108160 + depends on PAX_EMUPLT && SPARC
108161 + default n
108162 + help
108163 + This option is needed if userland has an old glibc (before 2.4)
108164 + that puts a 'save' instruction into the runtime generated resolver
108165 + stub that needs special emulation.
108166 +
108167 +config PAX_KERNEXEC
108168 + bool "Enforce non-executable kernel pages"
108169 + 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))
108170 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108171 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108172 + select PAX_KERNEXEC_PLUGIN if X86_64
108173 + help
108174 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108175 + that is, enabling this option will make it harder to inject
108176 + and execute 'foreign' code in kernel memory itself.
108177 +
108178 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108179 + the kernel command-line will result in an RWX physical map.
108180 +
108181 + Likewise, the EFI runtime services are necessarily mapped as
108182 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108183 + is recommended that you boot with "noefi" on the kernel
108184 + command-line if possible to eliminate the mapping.
108185 +
108186 +choice
108187 + prompt "Return Address Instrumentation Method"
108188 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108189 + depends on PAX_KERNEXEC_PLUGIN
108190 + help
108191 + Select the method used to instrument function pointer dereferences.
108192 + Note that binary modules cannot be instrumented by this approach.
108193 +
108194 + Note that the implementation requires a gcc with plugin support,
108195 + i.e., gcc 4.5 or newer. You may need to install the supporting
108196 + headers explicitly in addition to the normal gcc package.
108197 +
108198 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108199 + bool "bts"
108200 + help
108201 + This method is compatible with binary only modules but has
108202 + a higher runtime overhead.
108203 +
108204 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108205 + bool "or"
108206 + depends on !PARAVIRT
108207 + help
108208 + This method is incompatible with binary only modules but has
108209 + a lower runtime overhead.
108210 +endchoice
108211 +
108212 +config PAX_KERNEXEC_PLUGIN_METHOD
108213 + string
108214 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108215 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108216 + default ""
108217 +
108218 +config PAX_KERNEXEC_MODULE_TEXT
108219 + int "Minimum amount of memory reserved for module code"
108220 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108221 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108222 + depends on PAX_KERNEXEC && X86_32
108223 + help
108224 + Due to implementation details the kernel must reserve a fixed
108225 + amount of memory for runtime allocated code (such as modules)
108226 + at compile time that cannot be changed at runtime. Here you
108227 + can specify the minimum amount in MB that will be reserved.
108228 + Due to the same implementation details this size will always
108229 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108230 + the actually available memory for runtime allocated code will
108231 + usually be more than this minimum.
108232 +
108233 + The default 4 MB should be enough for most users but if you have
108234 + an excessive number of modules (e.g., most distribution configs
108235 + compile many drivers as modules) or use huge modules such as
108236 + nvidia's kernel driver, you will need to adjust this amount.
108237 + A good rule of thumb is to look at your currently loaded kernel
108238 + modules and add up their sizes.
108239 +
108240 +endmenu
108241 +
108242 +menu "Address Space Layout Randomization"
108243 + depends on PAX
108244 +
108245 +config PAX_ASLR
108246 + bool "Address Space Layout Randomization"
108247 + default y if GRKERNSEC_CONFIG_AUTO
108248 + help
108249 + Many if not most exploit techniques rely on the knowledge of
108250 + certain addresses in the attacked program. The following options
108251 + will allow the kernel to apply a certain amount of randomization
108252 + to specific parts of the program thereby forcing an attacker to
108253 + guess them in most cases. Any failed guess will most likely crash
108254 + the attacked program which allows the kernel to detect such attempts
108255 + and react on them. PaX itself provides no reaction mechanisms,
108256 + instead it is strongly encouraged that you make use of grsecurity's
108257 + (http://www.grsecurity.net/) built-in crash detection features or
108258 + develop one yourself.
108259 +
108260 + By saying Y here you can choose to randomize the following areas:
108261 + - top of the task's kernel stack
108262 + - top of the task's userland stack
108263 + - base address for mmap() requests that do not specify one
108264 + (this includes all libraries)
108265 + - base address of the main executable
108266 +
108267 + It is strongly recommended to say Y here as address space layout
108268 + randomization has negligible impact on performance yet it provides
108269 + a very effective protection.
108270 +
108271 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108272 + this feature on a per file basis.
108273 +
108274 +config PAX_RANDKSTACK
108275 + bool "Randomize kernel stack base"
108276 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108277 + depends on X86_TSC && X86
108278 + help
108279 + By saying Y here the kernel will randomize every task's kernel
108280 + stack on every system call. This will not only force an attacker
108281 + to guess it but also prevent him from making use of possible
108282 + leaked information about it.
108283 +
108284 + Since the kernel stack is a rather scarce resource, randomization
108285 + may cause unexpected stack overflows, therefore you should very
108286 + carefully test your system. Note that once enabled in the kernel
108287 + configuration, this feature cannot be disabled on a per file basis.
108288 +
108289 +config PAX_RANDUSTACK
108290 + bool
108291 +
108292 +config PAX_RANDMMAP
108293 + bool "Randomize user stack and mmap() bases"
108294 + default y if GRKERNSEC_CONFIG_AUTO
108295 + depends on PAX_ASLR
108296 + select PAX_RANDUSTACK
108297 + help
108298 + By saying Y here the kernel will randomize every task's userland
108299 + stack and use a randomized base address for mmap() requests that
108300 + do not specify one themselves.
108301 +
108302 + The stack randomization is done in two steps where the second
108303 + one may apply a big amount of shift to the top of the stack and
108304 + cause problems for programs that want to use lots of memory (more
108305 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108306 +
108307 + As a result of mmap randomization all dynamically loaded libraries
108308 + will appear at random addresses and therefore be harder to exploit
108309 + by a technique where an attacker attempts to execute library code
108310 + for his purposes (e.g. spawn a shell from an exploited program that
108311 + is running at an elevated privilege level).
108312 +
108313 + Furthermore, if a program is relinked as a dynamic ELF file, its
108314 + base address will be randomized as well, completing the full
108315 + randomization of the address space layout. Attacking such programs
108316 + becomes a guess game. You can find an example of doing this at
108317 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
108318 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
108319 +
108320 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
108321 + feature on a per file basis.
108322 +
108323 +endmenu
108324 +
108325 +menu "Miscellaneous hardening features"
108326 +
108327 +config PAX_MEMORY_SANITIZE
108328 + bool "Sanitize all freed memory"
108329 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108330 + help
108331 + By saying Y here the kernel will erase memory pages and slab objects
108332 + as soon as they are freed. This in turn reduces the lifetime of data
108333 + stored in them, making it less likely that sensitive information such
108334 + as passwords, cryptographic secrets, etc stay in memory for too long.
108335 +
108336 + This is especially useful for programs whose runtime is short, long
108337 + lived processes and the kernel itself benefit from this as long as
108338 + they ensure timely freeing of memory that may hold sensitive
108339 + information.
108340 +
108341 + A nice side effect of the sanitization of slab objects is the
108342 + reduction of possible info leaks caused by padding bytes within the
108343 + leaky structures. Use-after-free bugs for structures containing
108344 + pointers can also be detected as dereferencing the sanitized pointer
108345 + will generate an access violation.
108346 +
108347 + The tradeoff is performance impact, on a single CPU system kernel
108348 + compilation sees a 3% slowdown, other systems and workloads may vary
108349 + and you are advised to test this feature on your expected workload
108350 + before deploying it.
108351 +
108352 + The slab sanitization feature excludes a few slab caches per default
108353 + for performance reasons. To extend the feature to cover those as
108354 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
108355 +
108356 + To reduce the performance penalty by sanitizing pages only, albeit
108357 + limiting the effectiveness of this feature at the same time, slab
108358 + sanitization can be disabled with the kernel command line parameter
108359 + "pax_sanitize_slab=off".
108360 +
108361 + Note that this feature does not protect data stored in live pages,
108362 + e.g., process memory swapped to disk may stay there for a long time.
108363 +
108364 +config PAX_MEMORY_STACKLEAK
108365 + bool "Sanitize kernel stack"
108366 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108367 + depends on X86
108368 + help
108369 + By saying Y here the kernel will erase the kernel stack before it
108370 + returns from a system call. This in turn reduces the information
108371 + that a kernel stack leak bug can reveal.
108372 +
108373 + Note that such a bug can still leak information that was put on
108374 + the stack by the current system call (the one eventually triggering
108375 + the bug) but traces of earlier system calls on the kernel stack
108376 + cannot leak anymore.
108377 +
108378 + The tradeoff is performance impact: on a single CPU system kernel
108379 + compilation sees a 1% slowdown, other systems and workloads may vary
108380 + and you are advised to test this feature on your expected workload
108381 + before deploying it.
108382 +
108383 + Note that the full feature requires a gcc with plugin support,
108384 + i.e., gcc 4.5 or newer. You may need to install the supporting
108385 + headers explicitly in addition to the normal gcc package. Using
108386 + older gcc versions means that functions with large enough stack
108387 + frames may leave uninitialized memory behind that may be exposed
108388 + to a later syscall leaking the stack.
108389 +
108390 +config PAX_MEMORY_STRUCTLEAK
108391 + bool "Forcibly initialize local variables copied to userland"
108392 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108393 + help
108394 + By saying Y here the kernel will zero initialize some local
108395 + variables that are going to be copied to userland. This in
108396 + turn prevents unintended information leakage from the kernel
108397 + stack should later code forget to explicitly set all parts of
108398 + the copied variable.
108399 +
108400 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
108401 + at a much smaller coverage.
108402 +
108403 + Note that the implementation requires a gcc with plugin support,
108404 + i.e., gcc 4.5 or newer. You may need to install the supporting
108405 + headers explicitly in addition to the normal gcc package.
108406 +
108407 +config PAX_MEMORY_UDEREF
108408 + bool "Prevent invalid userland pointer dereference"
108409 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
108410 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
108411 + select PAX_PER_CPU_PGD if X86_64
108412 + help
108413 + By saying Y here the kernel will be prevented from dereferencing
108414 + userland pointers in contexts where the kernel expects only kernel
108415 + pointers. This is both a useful runtime debugging feature and a
108416 + security measure that prevents exploiting a class of kernel bugs.
108417 +
108418 + The tradeoff is that some virtualization solutions may experience
108419 + a huge slowdown and therefore you should not enable this feature
108420 + for kernels meant to run in such environments. Whether a given VM
108421 + solution is affected or not is best determined by simply trying it
108422 + out, the performance impact will be obvious right on boot as this
108423 + mechanism engages from very early on. A good rule of thumb is that
108424 + VMs running on CPUs without hardware virtualization support (i.e.,
108425 + the majority of IA-32 CPUs) will likely experience the slowdown.
108426 +
108427 + On X86_64 the kernel will make use of PCID support when available
108428 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
108429 + or performance impact. Pass pax_weakuderef on the kernel command
108430 + line to choose the latter.
108431 +
108432 +config PAX_REFCOUNT
108433 + bool "Prevent various kernel object reference counter overflows"
108434 + default y if GRKERNSEC_CONFIG_AUTO
108435 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
108436 + help
108437 + By saying Y here the kernel will detect and prevent overflowing
108438 + various (but not all) kinds of object reference counters. Such
108439 + overflows can normally occur due to bugs only and are often, if
108440 + not always, exploitable.
108441 +
108442 + The tradeoff is that data structures protected by an overflowed
108443 + refcount will never be freed and therefore will leak memory. Note
108444 + that this leak also happens even without this protection but in
108445 + that case the overflow can eventually trigger the freeing of the
108446 + data structure while it is still being used elsewhere, resulting
108447 + in the exploitable situation that this feature prevents.
108448 +
108449 + Since this has a negligible performance impact, you should enable
108450 + this feature.
108451 +
108452 +config PAX_CONSTIFY_PLUGIN
108453 + bool "Automatically constify eligible structures"
108454 + default y
108455 + depends on !UML && PAX_KERNEXEC
108456 + help
108457 + By saying Y here the compiler will automatically constify a class
108458 + of types that contain only function pointers. This reduces the
108459 + kernel's attack surface and also produces a better memory layout.
108460 +
108461 + Note that the implementation requires a gcc with plugin support,
108462 + i.e., gcc 4.5 or newer. You may need to install the supporting
108463 + headers explicitly in addition to the normal gcc package.
108464 +
108465 + Note that if some code really has to modify constified variables
108466 + then the source code will have to be patched to allow it. Examples
108467 + can be found in PaX itself (the no_const attribute) and for some
108468 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
108469 +
108470 +config PAX_USERCOPY
108471 + bool "Harden heap object copies between kernel and userland"
108472 + default y if GRKERNSEC_CONFIG_AUTO
108473 + depends on ARM || IA64 || PPC || SPARC || X86
108474 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
108475 + select PAX_USERCOPY_SLABS
108476 + help
108477 + By saying Y here the kernel will enforce the size of heap objects
108478 + when they are copied in either direction between the kernel and
108479 + userland, even if only a part of the heap object is copied.
108480 +
108481 + Specifically, this checking prevents information leaking from the
108482 + kernel heap during kernel to userland copies (if the kernel heap
108483 + object is otherwise fully initialized) and prevents kernel heap
108484 + overflows during userland to kernel copies.
108485 +
108486 + Note that the current implementation provides the strictest bounds
108487 + checks for the SLUB allocator.
108488 +
108489 + Enabling this option also enables per-slab cache protection against
108490 + data in a given cache being copied into/out of via userland
108491 + accessors. Though the whitelist of regions will be reduced over
108492 + time, it notably protects important data structures like task structs.
108493 +
108494 + If frame pointers are enabled on x86, this option will also restrict
108495 + copies into and out of the kernel stack to local variables within a
108496 + single frame.
108497 +
108498 + Since this has a negligible performance impact, you should enable
108499 + this feature.
108500 +
108501 +config PAX_USERCOPY_DEBUG
108502 + bool
108503 + depends on X86 && PAX_USERCOPY
108504 + default n
108505 +
108506 +config PAX_SIZE_OVERFLOW
108507 + bool "Prevent various integer overflows in function size parameters"
108508 + default y if GRKERNSEC_CONFIG_AUTO
108509 + depends on X86
108510 + help
108511 + By saying Y here the kernel recomputes expressions of function
108512 + arguments marked by a size_overflow attribute with double integer
108513 + precision (DImode/TImode for 32/64 bit integer types).
108514 +
108515 + The recomputed argument is checked against TYPE_MAX and an event
108516 + is logged on overflow and the triggering process is killed.
108517 +
108518 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
108519 +
108520 + Note that the implementation requires a gcc with plugin support,
108521 + i.e., gcc 4.5 or newer. You may need to install the supporting
108522 + headers explicitly in addition to the normal gcc package.
108523 +
108524 +config PAX_LATENT_ENTROPY
108525 + bool "Generate some entropy during boot and runtime"
108526 + default y if GRKERNSEC_CONFIG_AUTO
108527 + help
108528 + By saying Y here the kernel will instrument some kernel code to
108529 + extract some entropy from both original and artificially created
108530 + program state. This will help especially embedded systems where
108531 + there is little 'natural' source of entropy normally. The cost
108532 + is some slowdown of the boot process and fork and irq processing.
108533 +
108534 + When pax_extra_latent_entropy is passed on the kernel command line,
108535 + entropy will be extracted from up to the first 4GB of RAM while the
108536 + runtime memory allocator is being initialized. This costs even more
108537 + slowdown of the boot process.
108538 +
108539 + Note that the implementation requires a gcc with plugin support,
108540 + i.e., gcc 4.5 or newer. You may need to install the supporting
108541 + headers explicitly in addition to the normal gcc package.
108542 +
108543 + Note that entropy extracted this way is not cryptographically
108544 + secure!
108545 +
108546 +endmenu
108547 +
108548 +endmenu
108549 +
108550 +source grsecurity/Kconfig
108551 +
108552 +endmenu
108553 +
108554 +endmenu
108555 +
108556 source security/keys/Kconfig
108557
108558 config SECURITY_DMESG_RESTRICT
108559 @@ -103,7 +1066,7 @@ config INTEL_TXT
108560 config LSM_MMAP_MIN_ADDR
108561 int "Low address space for LSM to protect from user allocation"
108562 depends on SECURITY && SECURITY_SELINUX
108563 - default 32768 if ARM || (ARM64 && COMPAT)
108564 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
108565 default 65536
108566 help
108567 This is the portion of low virtual memory which should be protected
108568 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
108569 index fdaa50c..2761dcb 100644
108570 --- a/security/apparmor/file.c
108571 +++ b/security/apparmor/file.c
108572 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
108573 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
108574 struct path *new_dir, struct dentry *new_dentry)
108575 {
108576 - struct path link = { new_dir->mnt, new_dentry };
108577 - struct path target = { new_dir->mnt, old_dentry };
108578 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
108579 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
108580 struct path_cond cond = {
108581 old_dentry->d_inode->i_uid,
108582 old_dentry->d_inode->i_mode
108583 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
108584 index 9981000..eb21356 100644
108585 --- a/security/apparmor/lsm.c
108586 +++ b/security/apparmor/lsm.c
108587 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108588 struct dentry *dentry, u32 mask,
108589 struct path_cond *cond)
108590 {
108591 - struct path path = { dir->mnt, dentry };
108592 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
108593
108594 return common_perm(op, &path, mask, cond);
108595 }
108596 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108597 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
108598 struct dentry *dentry, u32 mask)
108599 {
108600 - struct path path = { mnt, dentry };
108601 + struct path path = { .mnt = mnt, .dentry = dentry };
108602 struct path_cond cond = { dentry->d_inode->i_uid,
108603 dentry->d_inode->i_mode
108604 };
108605 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
108606
108607 profile = aa_current_profile();
108608 if (!unconfined(profile)) {
108609 - struct path old_path = { old_dir->mnt, old_dentry };
108610 - struct path new_path = { new_dir->mnt, new_dentry };
108611 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
108612 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
108613 struct path_cond cond = { old_dentry->d_inode->i_uid,
108614 old_dentry->d_inode->i_mode
108615 };
108616 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
108617 return error;
108618 }
108619
108620 -static struct security_operations apparmor_ops = {
108621 +static struct security_operations apparmor_ops __read_only = {
108622 .name = "apparmor",
108623
108624 .ptrace_access_check = apparmor_ptrace_access_check,
108625 diff --git a/security/commoncap.c b/security/commoncap.c
108626 index bab0611..f9a0ff5 100644
108627 --- a/security/commoncap.c
108628 +++ b/security/commoncap.c
108629 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
108630 return 0;
108631 }
108632
108633 +/* returns:
108634 + 1 for suid privilege
108635 + 2 for sgid privilege
108636 + 3 for fscap privilege
108637 +*/
108638 +int is_privileged_binary(const struct dentry *dentry)
108639 +{
108640 + struct cpu_vfs_cap_data capdata;
108641 + struct inode *inode = dentry->d_inode;
108642 +
108643 + if (!inode || S_ISDIR(inode->i_mode))
108644 + return 0;
108645 +
108646 + if (inode->i_mode & S_ISUID)
108647 + return 1;
108648 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
108649 + return 2;
108650 +
108651 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
108652 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
108653 + return 3;
108654 + }
108655 +
108656 + return 0;
108657 +}
108658 +
108659 /*
108660 * Attempt to get the on-exec apply capability sets for an executable file from
108661 * its xattrs and, if present, apply them to the proposed credentials being
108662 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
108663 const struct cred *cred = current_cred();
108664 kuid_t root_uid = make_kuid(cred->user_ns, 0);
108665
108666 + if (gr_acl_enable_at_secure())
108667 + return 1;
108668 +
108669 if (!uid_eq(cred->uid, root_uid)) {
108670 if (bprm->cap_effective)
108671 return 1;
108672 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
108673 index 0fb456c..83711f9 100644
108674 --- a/security/integrity/ima/ima.h
108675 +++ b/security/integrity/ima/ima.h
108676 @@ -118,8 +118,8 @@ int ima_init_template(void);
108677 extern spinlock_t ima_queue_lock;
108678
108679 struct ima_h_table {
108680 - atomic_long_t len; /* number of stored measurements in the list */
108681 - atomic_long_t violations;
108682 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
108683 + atomic_long_unchecked_t violations;
108684 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
108685 };
108686 extern struct ima_h_table ima_htable;
108687 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
108688 index d9cd5ce..c5c29ac 100644
108689 --- a/security/integrity/ima/ima_api.c
108690 +++ b/security/integrity/ima/ima_api.c
108691 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
108692 int result;
108693
108694 /* can overflow, only indicator */
108695 - atomic_long_inc(&ima_htable.violations);
108696 + atomic_long_inc_unchecked(&ima_htable.violations);
108697
108698 result = ima_alloc_init_template(NULL, file, filename,
108699 NULL, 0, &entry);
108700 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
108701 index da92fcc..8a5d390 100644
108702 --- a/security/integrity/ima/ima_fs.c
108703 +++ b/security/integrity/ima/ima_fs.c
108704 @@ -28,12 +28,12 @@
108705 static int valid_policy = 1;
108706 #define TMPBUFLEN 12
108707 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
108708 - loff_t *ppos, atomic_long_t *val)
108709 + loff_t *ppos, atomic_long_unchecked_t *val)
108710 {
108711 char tmpbuf[TMPBUFLEN];
108712 ssize_t len;
108713
108714 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
108715 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
108716 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
108717 }
108718
108719 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
108720 index 552705d..9920f4fb 100644
108721 --- a/security/integrity/ima/ima_queue.c
108722 +++ b/security/integrity/ima/ima_queue.c
108723 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
108724 INIT_LIST_HEAD(&qe->later);
108725 list_add_tail_rcu(&qe->later, &ima_measurements);
108726
108727 - atomic_long_inc(&ima_htable.len);
108728 + atomic_long_inc_unchecked(&ima_htable.len);
108729 key = ima_hash_key(entry->digest);
108730 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
108731 return 0;
108732 diff --git a/security/keys/compat.c b/security/keys/compat.c
108733 index 3478965..ec7bb9e 100644
108734 --- a/security/keys/compat.c
108735 +++ b/security/keys/compat.c
108736 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
108737 if (ret == 0)
108738 goto no_payload_free;
108739
108740 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
108741 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
108742 err:
108743 if (iov != iovstack)
108744 kfree(iov);
108745 diff --git a/security/keys/internal.h b/security/keys/internal.h
108746 index 5f20da0..444ccf1 100644
108747 --- a/security/keys/internal.h
108748 +++ b/security/keys/internal.h
108749 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
108750 extern long keyctl_invalidate_key(key_serial_t);
108751
108752 extern long keyctl_instantiate_key_common(key_serial_t,
108753 - const struct iovec *,
108754 + const struct iovec __user *,
108755 unsigned, size_t, key_serial_t);
108756 #ifdef CONFIG_PERSISTENT_KEYRINGS
108757 extern long keyctl_get_persistent(uid_t, key_serial_t);
108758 diff --git a/security/keys/key.c b/security/keys/key.c
108759 index 6d0cad1..8f957df 100644
108760 --- a/security/keys/key.c
108761 +++ b/security/keys/key.c
108762 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
108763
108764 atomic_set(&key->usage, 1);
108765 init_rwsem(&key->sem);
108766 - lockdep_set_class(&key->sem, &type->lock_class);
108767 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
108768 key->index_key.type = type;
108769 key->user = user;
108770 key->quotalen = quotalen;
108771 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
108772 struct key_type *p;
108773 int ret;
108774
108775 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
108776 + pax_open_kernel();
108777 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
108778 + pax_close_kernel();
108779
108780 ret = -EEXIST;
108781 down_write(&key_types_sem);
108782 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
108783 }
108784
108785 /* store the type */
108786 - list_add(&ktype->link, &key_types_list);
108787 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
108788
108789 pr_notice("Key type %s registered\n", ktype->name);
108790 ret = 0;
108791 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
108792 void unregister_key_type(struct key_type *ktype)
108793 {
108794 down_write(&key_types_sem);
108795 - list_del_init(&ktype->link);
108796 + pax_list_del_init((struct list_head *)&ktype->link);
108797 downgrade_write(&key_types_sem);
108798 key_gc_keytype(ktype);
108799 pr_notice("Key type %s unregistered\n", ktype->name);
108800 @@ -1127,10 +1129,10 @@ void __init key_init(void)
108801 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
108802
108803 /* add the special key types */
108804 - list_add_tail(&key_type_keyring.link, &key_types_list);
108805 - list_add_tail(&key_type_dead.link, &key_types_list);
108806 - list_add_tail(&key_type_user.link, &key_types_list);
108807 - list_add_tail(&key_type_logon.link, &key_types_list);
108808 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
108809 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
108810 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
108811 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
108812
108813 /* record the root user tracking */
108814 rb_link_node(&root_key_user.node,
108815 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
108816 index eff88a5..51d35ef 100644
108817 --- a/security/keys/keyctl.c
108818 +++ b/security/keys/keyctl.c
108819 @@ -1004,7 +1004,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
108820 /*
108821 * Copy the iovec data from userspace
108822 */
108823 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
108824 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
108825 unsigned ioc)
108826 {
108827 for (; ioc > 0; ioc--) {
108828 @@ -1026,7 +1026,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
108829 * If successful, 0 will be returned.
108830 */
108831 long keyctl_instantiate_key_common(key_serial_t id,
108832 - const struct iovec *payload_iov,
108833 + const struct iovec __user *payload_iov,
108834 unsigned ioc,
108835 size_t plen,
108836 key_serial_t ringid)
108837 @@ -1121,7 +1121,7 @@ long keyctl_instantiate_key(key_serial_t id,
108838 [0].iov_len = plen
108839 };
108840
108841 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
108842 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
108843 }
108844
108845 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
108846 @@ -1154,7 +1154,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
108847 if (ret == 0)
108848 goto no_payload_free;
108849
108850 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
108851 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
108852 err:
108853 if (iov != iovstack)
108854 kfree(iov);
108855 diff --git a/security/min_addr.c b/security/min_addr.c
108856 index f728728..6457a0c 100644
108857 --- a/security/min_addr.c
108858 +++ b/security/min_addr.c
108859 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
108860 */
108861 static void update_mmap_min_addr(void)
108862 {
108863 +#ifndef SPARC
108864 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
108865 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
108866 mmap_min_addr = dac_mmap_min_addr;
108867 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
108868 #else
108869 mmap_min_addr = dac_mmap_min_addr;
108870 #endif
108871 +#endif
108872 }
108873
108874 /*
108875 diff --git a/security/security.c b/security/security.c
108876 index e41b1a8..b66a558 100644
108877 --- a/security/security.c
108878 +++ b/security/security.c
108879 @@ -33,8 +33,8 @@
108880 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
108881 CONFIG_DEFAULT_SECURITY;
108882
108883 -static struct security_operations *security_ops;
108884 -static struct security_operations default_security_ops = {
108885 +struct security_operations *security_ops __read_only;
108886 +struct security_operations default_security_ops __read_only = {
108887 .name = "default",
108888 };
108889
108890 @@ -73,11 +73,6 @@ int __init security_init(void)
108891 return 0;
108892 }
108893
108894 -void reset_security_ops(void)
108895 -{
108896 - security_ops = &default_security_ops;
108897 -}
108898 -
108899 /* Save user chosen LSM */
108900 static int __init choose_lsm(char *str)
108901 {
108902 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
108903 index a18f1fa..c9b9fc4 100644
108904 --- a/security/selinux/avc.c
108905 +++ b/security/selinux/avc.c
108906 @@ -59,7 +59,7 @@ struct avc_node {
108907 struct avc_cache {
108908 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
108909 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
108910 - atomic_t lru_hint; /* LRU hint for reclaim scan */
108911 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
108912 atomic_t active_nodes;
108913 u32 latest_notif; /* latest revocation notification */
108914 };
108915 @@ -167,7 +167,7 @@ void __init avc_init(void)
108916 spin_lock_init(&avc_cache.slots_lock[i]);
108917 }
108918 atomic_set(&avc_cache.active_nodes, 0);
108919 - atomic_set(&avc_cache.lru_hint, 0);
108920 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
108921
108922 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
108923 0, SLAB_PANIC, NULL);
108924 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
108925 spinlock_t *lock;
108926
108927 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
108928 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
108929 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
108930 head = &avc_cache.slots[hvalue];
108931 lock = &avc_cache.slots_lock[hvalue];
108932
108933 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
108934 index e03bad5..b15da09 100644
108935 --- a/security/selinux/hooks.c
108936 +++ b/security/selinux/hooks.c
108937 @@ -95,8 +95,6 @@
108938 #include "audit.h"
108939 #include "avc_ss.h"
108940
108941 -extern struct security_operations *security_ops;
108942 -
108943 /* SECMARK reference count */
108944 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
108945
108946 @@ -5772,7 +5770,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
108947
108948 #endif
108949
108950 -static struct security_operations selinux_ops = {
108951 +static struct security_operations selinux_ops __read_only = {
108952 .name = "selinux",
108953
108954 .ptrace_access_check = selinux_ptrace_access_check,
108955 @@ -6128,6 +6126,9 @@ static void selinux_nf_ip_exit(void)
108956 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
108957 static int selinux_disabled;
108958
108959 +extern struct security_operations *security_ops;
108960 +extern struct security_operations default_security_ops;
108961 +
108962 int selinux_disable(void)
108963 {
108964 if (ss_initialized) {
108965 @@ -6145,7 +6146,9 @@ int selinux_disable(void)
108966 selinux_disabled = 1;
108967 selinux_enabled = 0;
108968
108969 - reset_security_ops();
108970 + pax_open_kernel();
108971 + security_ops = &default_security_ops;
108972 + pax_close_kernel();
108973
108974 /* Try to destroy the avc node cache */
108975 avc_disable();
108976 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
108977 index 1450f85..a91e0bc 100644
108978 --- a/security/selinux/include/xfrm.h
108979 +++ b/security/selinux/include/xfrm.h
108980 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
108981
108982 rtnl_lock();
108983 for_each_net(net) {
108984 - atomic_inc(&net->xfrm.flow_cache_genid);
108985 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
108986 rt_genid_bump_all(net);
108987 }
108988 rtnl_unlock();
108989 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
108990 index e6ab307..2008c98 100644
108991 --- a/security/smack/smack_lsm.c
108992 +++ b/security/smack/smack_lsm.c
108993 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
108994 return 0;
108995 }
108996
108997 -struct security_operations smack_ops = {
108998 +struct security_operations smack_ops __read_only = {
108999 .name = "smack",
109000
109001 .ptrace_access_check = smack_ptrace_access_check,
109002 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109003 index 4003907..13a2b55 100644
109004 --- a/security/tomoyo/file.c
109005 +++ b/security/tomoyo/file.c
109006 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109007 {
109008 struct tomoyo_request_info r;
109009 struct tomoyo_obj_info obj = {
109010 - .path1 = *path,
109011 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109012 };
109013 int error = -ENOMEM;
109014 struct tomoyo_path_info buf;
109015 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109016 struct tomoyo_path_info buf;
109017 struct tomoyo_request_info r;
109018 struct tomoyo_obj_info obj = {
109019 - .path1 = *path,
109020 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109021 };
109022 int idx;
109023
109024 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109025 {
109026 struct tomoyo_request_info r;
109027 struct tomoyo_obj_info obj = {
109028 - .path1 = *path,
109029 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109030 };
109031 int error;
109032 struct tomoyo_path_info buf;
109033 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109034 {
109035 struct tomoyo_request_info r;
109036 struct tomoyo_obj_info obj = {
109037 - .path1 = *path,
109038 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109039 };
109040 int error = -ENOMEM;
109041 struct tomoyo_path_info buf;
109042 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109043 struct tomoyo_path_info buf2;
109044 struct tomoyo_request_info r;
109045 struct tomoyo_obj_info obj = {
109046 - .path1 = *path1,
109047 - .path2 = *path2,
109048 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109049 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109050 };
109051 int idx;
109052
109053 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109054 index 390c646..f2f8db3 100644
109055 --- a/security/tomoyo/mount.c
109056 +++ b/security/tomoyo/mount.c
109057 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109058 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109059 need_dev = -1; /* dev_name is a directory */
109060 } else {
109061 + if (!capable(CAP_SYS_ADMIN)) {
109062 + error = -EPERM;
109063 + goto out;
109064 + }
109065 fstype = get_fs_type(type);
109066 if (!fstype) {
109067 error = -ENODEV;
109068 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109069 index f0b756e..8aa497b 100644
109070 --- a/security/tomoyo/tomoyo.c
109071 +++ b/security/tomoyo/tomoyo.c
109072 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109073 */
109074 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109075 {
109076 - struct path path = { mnt, dentry };
109077 + struct path path = { .mnt = mnt, .dentry = dentry };
109078 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109079 }
109080
109081 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109082 */
109083 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109084 {
109085 - struct path path = { parent->mnt, dentry };
109086 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109087 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109088 }
109089
109090 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109091 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109092 umode_t mode)
109093 {
109094 - struct path path = { parent->mnt, dentry };
109095 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109096 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109097 mode & S_IALLUGO);
109098 }
109099 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109100 */
109101 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109102 {
109103 - struct path path = { parent->mnt, dentry };
109104 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109105 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109106 }
109107
109108 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109109 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109110 const char *old_name)
109111 {
109112 - struct path path = { parent->mnt, dentry };
109113 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109114 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109115 }
109116
109117 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109118 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109119 umode_t mode, unsigned int dev)
109120 {
109121 - struct path path = { parent->mnt, dentry };
109122 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109123 int type = TOMOYO_TYPE_CREATE;
109124 const unsigned int perm = mode & S_IALLUGO;
109125
109126 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109127 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109128 struct dentry *new_dentry)
109129 {
109130 - struct path path1 = { new_dir->mnt, old_dentry };
109131 - struct path path2 = { new_dir->mnt, new_dentry };
109132 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109133 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109134 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109135 }
109136
109137 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109138 struct path *new_parent,
109139 struct dentry *new_dentry)
109140 {
109141 - struct path path1 = { old_parent->mnt, old_dentry };
109142 - struct path path2 = { new_parent->mnt, new_dentry };
109143 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109144 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109145 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109146 }
109147
109148 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109149 */
109150 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109151 {
109152 - struct path path = { mnt, mnt->mnt_root };
109153 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109154 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109155 }
109156
109157 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109158 * tomoyo_security_ops is a "struct security_operations" which is used for
109159 * registering TOMOYO.
109160 */
109161 -static struct security_operations tomoyo_security_ops = {
109162 +static struct security_operations tomoyo_security_ops __read_only = {
109163 .name = "tomoyo",
109164 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109165 .cred_prepare = tomoyo_cred_prepare,
109166 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109167 index 20ef514..4182bed 100644
109168 --- a/security/yama/Kconfig
109169 +++ b/security/yama/Kconfig
109170 @@ -1,6 +1,6 @@
109171 config SECURITY_YAMA
109172 bool "Yama support"
109173 - depends on SECURITY
109174 + depends on SECURITY && !GRKERNSEC
109175 select SECURITYFS
109176 select SECURITY_PATH
109177 default n
109178 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109179 index 13c88fbc..f8c115e 100644
109180 --- a/security/yama/yama_lsm.c
109181 +++ b/security/yama/yama_lsm.c
109182 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109183 }
109184
109185 #ifndef CONFIG_SECURITY_YAMA_STACKED
109186 -static struct security_operations yama_ops = {
109187 +static struct security_operations yama_ops __read_only = {
109188 .name = "yama",
109189
109190 .ptrace_access_check = yama_ptrace_access_check,
109191 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109192 #endif
109193
109194 #ifdef CONFIG_SYSCTL
109195 +static int zero __read_only;
109196 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109197 +
109198 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109199 void __user *buffer, size_t *lenp, loff_t *ppos)
109200 {
109201 - int rc;
109202 + ctl_table_no_const yama_table;
109203
109204 if (write && !capable(CAP_SYS_PTRACE))
109205 return -EPERM;
109206
109207 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109208 - if (rc)
109209 - return rc;
109210 -
109211 + yama_table = *table;
109212 /* Lock the max value if it ever gets set. */
109213 - if (write && *(int *)table->data == *(int *)table->extra2)
109214 - table->extra1 = table->extra2;
109215 -
109216 - return rc;
109217 + if (ptrace_scope == max_scope)
109218 + yama_table.extra1 = &max_scope;
109219 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109220 }
109221
109222 -static int zero;
109223 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109224 -
109225 struct ctl_path yama_sysctl_path[] = {
109226 { .procname = "kernel", },
109227 { .procname = "yama", },
109228 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109229 index 401107b..b9c47c6 100644
109230 --- a/sound/aoa/codecs/onyx.c
109231 +++ b/sound/aoa/codecs/onyx.c
109232 @@ -54,7 +54,7 @@ struct onyx {
109233 spdif_locked:1,
109234 analog_locked:1,
109235 original_mute:2;
109236 - int open_count;
109237 + local_t open_count;
109238 struct codec_info *codec_info;
109239
109240 /* mutex serializes concurrent access to the device
109241 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109242 struct onyx *onyx = cii->codec_data;
109243
109244 mutex_lock(&onyx->mutex);
109245 - onyx->open_count++;
109246 + local_inc(&onyx->open_count);
109247 mutex_unlock(&onyx->mutex);
109248
109249 return 0;
109250 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109251 struct onyx *onyx = cii->codec_data;
109252
109253 mutex_lock(&onyx->mutex);
109254 - onyx->open_count--;
109255 - if (!onyx->open_count)
109256 + if (local_dec_and_test(&onyx->open_count))
109257 onyx->spdif_locked = onyx->analog_locked = 0;
109258 mutex_unlock(&onyx->mutex);
109259
109260 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109261 index ffd2025..df062c9 100644
109262 --- a/sound/aoa/codecs/onyx.h
109263 +++ b/sound/aoa/codecs/onyx.h
109264 @@ -11,6 +11,7 @@
109265 #include <linux/i2c.h>
109266 #include <asm/pmac_low_i2c.h>
109267 #include <asm/prom.h>
109268 +#include <asm/local.h>
109269
109270 /* PCM3052 register definitions */
109271
109272 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109273 index ada69d7..5f65386 100644
109274 --- a/sound/core/oss/pcm_oss.c
109275 +++ b/sound/core/oss/pcm_oss.c
109276 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109277 if (in_kernel) {
109278 mm_segment_t fs;
109279 fs = snd_enter_user();
109280 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109281 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109282 snd_leave_user(fs);
109283 } else {
109284 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109285 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109286 }
109287 if (ret != -EPIPE && ret != -ESTRPIPE)
109288 break;
109289 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109290 if (in_kernel) {
109291 mm_segment_t fs;
109292 fs = snd_enter_user();
109293 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109294 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109295 snd_leave_user(fs);
109296 } else {
109297 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109298 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109299 }
109300 if (ret == -EPIPE) {
109301 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
109302 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
109303 struct snd_pcm_plugin_channel *channels;
109304 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
109305 if (!in_kernel) {
109306 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
109307 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
109308 return -EFAULT;
109309 buf = runtime->oss.buffer;
109310 }
109311 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
109312 }
109313 } else {
109314 tmp = snd_pcm_oss_write2(substream,
109315 - (const char __force *)buf,
109316 + (const char __force_kernel *)buf,
109317 runtime->oss.period_bytes, 0);
109318 if (tmp <= 0)
109319 goto err;
109320 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
109321 struct snd_pcm_runtime *runtime = substream->runtime;
109322 snd_pcm_sframes_t frames, frames1;
109323 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
109324 - char __user *final_dst = (char __force __user *)buf;
109325 + char __user *final_dst = (char __force_user *)buf;
109326 if (runtime->oss.plugin_first) {
109327 struct snd_pcm_plugin_channel *channels;
109328 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
109329 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
109330 xfer += tmp;
109331 runtime->oss.buffer_used -= tmp;
109332 } else {
109333 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
109334 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
109335 runtime->oss.period_bytes, 0);
109336 if (tmp <= 0)
109337 goto err;
109338 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
109339 size1);
109340 size1 /= runtime->channels; /* frames */
109341 fs = snd_enter_user();
109342 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
109343 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
109344 snd_leave_user(fs);
109345 }
109346 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
109347 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
109348 index 2d957ba..fda022c 100644
109349 --- a/sound/core/pcm_compat.c
109350 +++ b/sound/core/pcm_compat.c
109351 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
109352 int err;
109353
109354 fs = snd_enter_user();
109355 - err = snd_pcm_delay(substream, &delay);
109356 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
109357 snd_leave_user(fs);
109358 if (err < 0)
109359 return err;
109360 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
109361 index a95356f..0f5eabf 100644
109362 --- a/sound/core/pcm_native.c
109363 +++ b/sound/core/pcm_native.c
109364 @@ -2815,11 +2815,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
109365 switch (substream->stream) {
109366 case SNDRV_PCM_STREAM_PLAYBACK:
109367 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
109368 - (void __user *)arg);
109369 + (void __force_user *)arg);
109370 break;
109371 case SNDRV_PCM_STREAM_CAPTURE:
109372 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
109373 - (void __user *)arg);
109374 + (void __force_user *)arg);
109375 break;
109376 default:
109377 result = -EINVAL;
109378 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
109379 index 16d4267..fe8b49b 100644
109380 --- a/sound/core/seq/oss/seq_oss.c
109381 +++ b/sound/core/seq/oss/seq_oss.c
109382 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
109383 {
109384 int rc;
109385 static struct snd_seq_dev_ops ops = {
109386 - snd_seq_oss_synth_register,
109387 - snd_seq_oss_synth_unregister,
109388 + .init_device = snd_seq_oss_synth_register,
109389 + .free_device = snd_seq_oss_synth_unregister,
109390 };
109391
109392 snd_seq_autoload_lock();
109393 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
109394 index 91a786a..4c07ed4 100644
109395 --- a/sound/core/seq/seq_device.c
109396 +++ b/sound/core/seq/seq_device.c
109397 @@ -64,7 +64,7 @@ struct ops_list {
109398 int argsize; /* argument size */
109399
109400 /* operators */
109401 - struct snd_seq_dev_ops ops;
109402 + struct snd_seq_dev_ops *ops;
109403
109404 /* registered devices */
109405 struct list_head dev_list; /* list of devices */
109406 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
109407
109408 mutex_lock(&ops->reg_mutex);
109409 /* copy driver operators */
109410 - ops->ops = *entry;
109411 + ops->ops = entry;
109412 ops->driver |= DRIVER_LOADED;
109413 ops->argsize = argsize;
109414
109415 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
109416 dev->name, ops->id, ops->argsize, dev->argsize);
109417 return -EINVAL;
109418 }
109419 - if (ops->ops.init_device(dev) >= 0) {
109420 + if (ops->ops->init_device(dev) >= 0) {
109421 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
109422 ops->num_init_devices++;
109423 } else {
109424 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
109425 dev->name, ops->id, ops->argsize, dev->argsize);
109426 return -EINVAL;
109427 }
109428 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
109429 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
109430 dev->status = SNDRV_SEQ_DEVICE_FREE;
109431 dev->driver_data = NULL;
109432 ops->num_init_devices--;
109433 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
109434 index a1fd77a..69cd659 100644
109435 --- a/sound/core/seq/seq_midi.c
109436 +++ b/sound/core/seq/seq_midi.c
109437 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
109438 static int __init alsa_seq_midi_init(void)
109439 {
109440 static struct snd_seq_dev_ops ops = {
109441 - snd_seq_midisynth_register_port,
109442 - snd_seq_midisynth_unregister_port,
109443 + .init_device = snd_seq_midisynth_register_port,
109444 + .free_device = snd_seq_midisynth_unregister_port,
109445 };
109446 memset(&synths, 0, sizeof(synths));
109447 snd_seq_autoload_lock();
109448 diff --git a/sound/core/sound.c b/sound/core/sound.c
109449 index 38ad1a0..5010a40 100644
109450 --- a/sound/core/sound.c
109451 +++ b/sound/core/sound.c
109452 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
109453 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
109454 default: return;
109455 }
109456 - request_module(str);
109457 + request_module("%s", str);
109458 }
109459
109460 #endif /* modular kernel */
109461 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
109462 index f5fd448..6ae276da 100644
109463 --- a/sound/drivers/mts64.c
109464 +++ b/sound/drivers/mts64.c
109465 @@ -29,6 +29,7 @@
109466 #include <sound/initval.h>
109467 #include <sound/rawmidi.h>
109468 #include <sound/control.h>
109469 +#include <asm/local.h>
109470
109471 #define CARD_NAME "Miditerminal 4140"
109472 #define DRIVER_NAME "MTS64"
109473 @@ -67,7 +68,7 @@ struct mts64 {
109474 struct pardevice *pardev;
109475 int pardev_claimed;
109476
109477 - int open_count;
109478 + local_t open_count;
109479 int current_midi_output_port;
109480 int current_midi_input_port;
109481 u8 mode[MTS64_NUM_INPUT_PORTS];
109482 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109483 {
109484 struct mts64 *mts = substream->rmidi->private_data;
109485
109486 - if (mts->open_count == 0) {
109487 + if (local_read(&mts->open_count) == 0) {
109488 /* We don't need a spinlock here, because this is just called
109489 if the device has not been opened before.
109490 So there aren't any IRQs from the device */
109491 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109492
109493 msleep(50);
109494 }
109495 - ++(mts->open_count);
109496 + local_inc(&mts->open_count);
109497
109498 return 0;
109499 }
109500 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109501 struct mts64 *mts = substream->rmidi->private_data;
109502 unsigned long flags;
109503
109504 - --(mts->open_count);
109505 - if (mts->open_count == 0) {
109506 + if (local_dec_return(&mts->open_count) == 0) {
109507 /* We need the spinlock_irqsave here because we can still
109508 have IRQs at this point */
109509 spin_lock_irqsave(&mts->lock, flags);
109510 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109511
109512 msleep(500);
109513
109514 - } else if (mts->open_count < 0)
109515 - mts->open_count = 0;
109516 + } else if (local_read(&mts->open_count) < 0)
109517 + local_set(&mts->open_count, 0);
109518
109519 return 0;
109520 }
109521 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
109522 index 6839953..7a0f4b9 100644
109523 --- a/sound/drivers/opl3/opl3_seq.c
109524 +++ b/sound/drivers/opl3/opl3_seq.c
109525 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
109526 {
109527 static struct snd_seq_dev_ops ops =
109528 {
109529 - snd_opl3_seq_new_device,
109530 - snd_opl3_seq_delete_device
109531 + .init_device = snd_opl3_seq_new_device,
109532 + .free_device = snd_opl3_seq_delete_device
109533 };
109534
109535 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
109536 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
109537 index b953fb4..1999c01 100644
109538 --- a/sound/drivers/opl4/opl4_lib.c
109539 +++ b/sound/drivers/opl4/opl4_lib.c
109540 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
109541 MODULE_DESCRIPTION("OPL4 driver");
109542 MODULE_LICENSE("GPL");
109543
109544 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
109545 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
109546 {
109547 int timeout = 10;
109548 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
109549 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
109550 index 9919769..d7de36c 100644
109551 --- a/sound/drivers/opl4/opl4_seq.c
109552 +++ b/sound/drivers/opl4/opl4_seq.c
109553 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
109554 static int __init alsa_opl4_synth_init(void)
109555 {
109556 static struct snd_seq_dev_ops ops = {
109557 - snd_opl4_seq_new_device,
109558 - snd_opl4_seq_delete_device
109559 + .init_device = snd_opl4_seq_new_device,
109560 + .free_device = snd_opl4_seq_delete_device
109561 };
109562
109563 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
109564 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
109565 index 78ccfa4..7a0857b 100644
109566 --- a/sound/drivers/portman2x4.c
109567 +++ b/sound/drivers/portman2x4.c
109568 @@ -48,6 +48,7 @@
109569 #include <sound/initval.h>
109570 #include <sound/rawmidi.h>
109571 #include <sound/control.h>
109572 +#include <asm/local.h>
109573
109574 #define CARD_NAME "Portman 2x4"
109575 #define DRIVER_NAME "portman"
109576 @@ -85,7 +86,7 @@ struct portman {
109577 struct pardevice *pardev;
109578 int pardev_claimed;
109579
109580 - int open_count;
109581 + local_t open_count;
109582 int mode[PORTMAN_NUM_INPUT_PORTS];
109583 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
109584 };
109585 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
109586 index 95fc2eaf..ea5d6a7 100644
109587 --- a/sound/firewire/amdtp.c
109588 +++ b/sound/firewire/amdtp.c
109589 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
109590 ptr = s->pcm_buffer_pointer + frames;
109591 if (ptr >= pcm->runtime->buffer_size)
109592 ptr -= pcm->runtime->buffer_size;
109593 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
109594 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
109595
109596 s->pcm_period_pointer += frames;
109597 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
109598 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
109599 */
109600 void amdtp_stream_update(struct amdtp_stream *s)
109601 {
109602 - ACCESS_ONCE(s->source_node_id_field) =
109603 + ACCESS_ONCE_RW(s->source_node_id_field) =
109604 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
109605 }
109606 EXPORT_SYMBOL(amdtp_stream_update);
109607 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
109608 index 4823c08..47a5f7c 100644
109609 --- a/sound/firewire/amdtp.h
109610 +++ b/sound/firewire/amdtp.h
109611 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
109612 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
109613 struct snd_pcm_substream *pcm)
109614 {
109615 - ACCESS_ONCE(s->pcm) = pcm;
109616 + ACCESS_ONCE_RW(s->pcm) = pcm;
109617 }
109618
109619 /**
109620 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
109621 struct snd_rawmidi_substream *midi)
109622 {
109623 if (port < s->midi_ports)
109624 - ACCESS_ONCE(s->midi[port]) = midi;
109625 + ACCESS_ONCE_RW(s->midi[port]) = midi;
109626 }
109627
109628 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
109629 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
109630 index 7ac9443..0ec6274 100644
109631 --- a/sound/firewire/isight.c
109632 +++ b/sound/firewire/isight.c
109633 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
109634 ptr += count;
109635 if (ptr >= runtime->buffer_size)
109636 ptr -= runtime->buffer_size;
109637 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
109638 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
109639
109640 isight->period_counter += count;
109641 if (isight->period_counter >= runtime->period_size) {
109642 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
109643 if (err < 0)
109644 return err;
109645
109646 - ACCESS_ONCE(isight->pcm_active) = true;
109647 + ACCESS_ONCE_RW(isight->pcm_active) = true;
109648
109649 return 0;
109650 }
109651 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
109652 {
109653 struct isight *isight = substream->private_data;
109654
109655 - ACCESS_ONCE(isight->pcm_active) = false;
109656 + ACCESS_ONCE_RW(isight->pcm_active) = false;
109657
109658 mutex_lock(&isight->mutex);
109659 isight_stop_streaming(isight);
109660 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
109661
109662 switch (cmd) {
109663 case SNDRV_PCM_TRIGGER_START:
109664 - ACCESS_ONCE(isight->pcm_running) = true;
109665 + ACCESS_ONCE_RW(isight->pcm_running) = true;
109666 break;
109667 case SNDRV_PCM_TRIGGER_STOP:
109668 - ACCESS_ONCE(isight->pcm_running) = false;
109669 + ACCESS_ONCE_RW(isight->pcm_running) = false;
109670 break;
109671 default:
109672 return -EINVAL;
109673 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
109674 index 2dba848..c682aef 100644
109675 --- a/sound/firewire/scs1x.c
109676 +++ b/sound/firewire/scs1x.c
109677 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
109678 {
109679 struct scs *scs = stream->rmidi->private_data;
109680
109681 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
109682 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
109683 if (up) {
109684 scs->output_idle = false;
109685 tasklet_schedule(&scs->tasklet);
109686 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
109687 {
109688 struct scs *scs = stream->rmidi->private_data;
109689
109690 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
109691 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
109692 }
109693
109694 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
109695 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
109696
109697 snd_card_disconnect(scs->card);
109698
109699 - ACCESS_ONCE(scs->output) = NULL;
109700 - ACCESS_ONCE(scs->input) = NULL;
109701 + ACCESS_ONCE_RW(scs->output) = NULL;
109702 + ACCESS_ONCE_RW(scs->input) = NULL;
109703
109704 wait_event(scs->idle_wait, scs->output_idle);
109705
109706 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
109707 index 4e3fcfb..ab45a9d 100644
109708 --- a/sound/isa/sb/emu8000_synth.c
109709 +++ b/sound/isa/sb/emu8000_synth.c
109710 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
109711 {
109712
109713 static struct snd_seq_dev_ops ops = {
109714 - snd_emu8000_new_device,
109715 - snd_emu8000_delete_device,
109716 + .init_device = snd_emu8000_new_device,
109717 + .free_device = snd_emu8000_delete_device,
109718 };
109719 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
109720 sizeof(struct snd_emu8000*));
109721 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
109722 index 048439a..3be9f6f 100644
109723 --- a/sound/oss/sb_audio.c
109724 +++ b/sound/oss/sb_audio.c
109725 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
109726 buf16 = (signed short *)(localbuf + localoffs);
109727 while (c)
109728 {
109729 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
109730 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
109731 if (copy_from_user(lbuf8,
109732 userbuf+useroffs + p,
109733 locallen))
109734 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
109735 index a33e8ce..2262303 100644
109736 --- a/sound/oss/swarm_cs4297a.c
109737 +++ b/sound/oss/swarm_cs4297a.c
109738 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
109739 {
109740 struct cs4297a_state *s;
109741 u32 pwr, id;
109742 - mm_segment_t fs;
109743 int rval;
109744 u64 cfg;
109745 int mdio_val;
109746 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
109747 if (!rval) {
109748 char *sb1250_duart_present;
109749
109750 +#if 0
109751 + mm_segment_t fs;
109752 fs = get_fs();
109753 set_fs(KERNEL_DS);
109754 -#if 0
109755 val = SOUND_MASK_LINE;
109756 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
109757 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
109758 val = initvol[i].vol;
109759 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
109760 }
109761 + set_fs(fs);
109762 // cs4297a_write_ac97(s, 0x18, 0x0808);
109763 #else
109764 // cs4297a_write_ac97(s, 0x5e, 0x180);
109765 cs4297a_write_ac97(s, 0x02, 0x0808);
109766 cs4297a_write_ac97(s, 0x18, 0x0808);
109767 #endif
109768 - set_fs(fs);
109769
109770 list_add(&s->list, &cs4297a_devs);
109771
109772 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
109773 index 4c41c90..37f3631 100644
109774 --- a/sound/pci/emu10k1/emu10k1_synth.c
109775 +++ b/sound/pci/emu10k1/emu10k1_synth.c
109776 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
109777 {
109778
109779 static struct snd_seq_dev_ops ops = {
109780 - snd_emu10k1_synth_new_device,
109781 - snd_emu10k1_synth_delete_device,
109782 + .init_device = snd_emu10k1_synth_new_device,
109783 + .free_device = snd_emu10k1_synth_delete_device,
109784 };
109785 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
109786 sizeof(struct snd_emu10k1_synth_arg));
109787 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
109788 index ec6a7d0..4e578f7 100644
109789 --- a/sound/pci/hda/hda_codec.c
109790 +++ b/sound/pci/hda/hda_codec.c
109791 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
109792 mutex_unlock(&preset_mutex);
109793
109794 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
109795 - char name[32];
109796 if (!mod_requested)
109797 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
109798 - codec->vendor_id);
109799 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
109800 else
109801 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
109802 - (codec->vendor_id >> 16) & 0xffff);
109803 - request_module(name);
109804 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
109805 mod_requested++;
109806 goto again;
109807 }
109808 @@ -2780,7 +2776,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
109809 /* FIXME: set_fs() hack for obtaining user-space TLV data */
109810 mm_segment_t fs = get_fs();
109811 set_fs(get_ds());
109812 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
109813 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
109814 tlv = _tlv;
109815 set_fs(fs);
109816 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
109817 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
109818 index 4631a23..001ae57 100644
109819 --- a/sound/pci/ymfpci/ymfpci.h
109820 +++ b/sound/pci/ymfpci/ymfpci.h
109821 @@ -358,7 +358,7 @@ struct snd_ymfpci {
109822 spinlock_t reg_lock;
109823 spinlock_t voice_lock;
109824 wait_queue_head_t interrupt_sleep;
109825 - atomic_t interrupt_sleep_count;
109826 + atomic_unchecked_t interrupt_sleep_count;
109827 struct snd_info_entry *proc_entry;
109828 const struct firmware *dsp_microcode;
109829 const struct firmware *controller_microcode;
109830 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
109831 index 81c916a..516f0bf 100644
109832 --- a/sound/pci/ymfpci/ymfpci_main.c
109833 +++ b/sound/pci/ymfpci/ymfpci_main.c
109834 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
109835 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
109836 break;
109837 }
109838 - if (atomic_read(&chip->interrupt_sleep_count)) {
109839 - atomic_set(&chip->interrupt_sleep_count, 0);
109840 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
109841 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
109842 wake_up(&chip->interrupt_sleep);
109843 }
109844 __end:
109845 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
109846 continue;
109847 init_waitqueue_entry(&wait, current);
109848 add_wait_queue(&chip->interrupt_sleep, &wait);
109849 - atomic_inc(&chip->interrupt_sleep_count);
109850 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
109851 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
109852 remove_wait_queue(&chip->interrupt_sleep, &wait);
109853 }
109854 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
109855 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
109856 spin_unlock(&chip->reg_lock);
109857
109858 - if (atomic_read(&chip->interrupt_sleep_count)) {
109859 - atomic_set(&chip->interrupt_sleep_count, 0);
109860 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
109861 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
109862 wake_up(&chip->interrupt_sleep);
109863 }
109864 }
109865 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
109866 spin_lock_init(&chip->reg_lock);
109867 spin_lock_init(&chip->voice_lock);
109868 init_waitqueue_head(&chip->interrupt_sleep);
109869 - atomic_set(&chip->interrupt_sleep_count, 0);
109870 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
109871 chip->card = card;
109872 chip->pci = pci;
109873 chip->irq = -1;
109874 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
109875 index a3e0a0d..ab98399 100644
109876 --- a/sound/soc/soc-core.c
109877 +++ b/sound/soc/soc-core.c
109878 @@ -2286,8 +2286,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
109879 if (ret)
109880 return ret;
109881
109882 - ops->warm_reset = snd_soc_ac97_warm_reset;
109883 - ops->reset = snd_soc_ac97_reset;
109884 + pax_open_kernel();
109885 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
109886 + *(void **)&ops->reset = snd_soc_ac97_reset;
109887 + pax_close_kernel();
109888
109889 snd_ac97_rst_cfg = cfg;
109890 return 0;
109891 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
109892 index 7778b8e..3d619fc 100644
109893 --- a/sound/synth/emux/emux_seq.c
109894 +++ b/sound/synth/emux/emux_seq.c
109895 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
109896 * MIDI emulation operators
109897 */
109898 static struct snd_midi_op emux_ops = {
109899 - snd_emux_note_on,
109900 - snd_emux_note_off,
109901 - snd_emux_key_press,
109902 - snd_emux_terminate_note,
109903 - snd_emux_control,
109904 - snd_emux_nrpn,
109905 - snd_emux_sysex,
109906 + .note_on = snd_emux_note_on,
109907 + .note_off = snd_emux_note_off,
109908 + .key_press = snd_emux_key_press,
109909 + .note_terminate = snd_emux_terminate_note,
109910 + .control = snd_emux_control,
109911 + .nrpn = snd_emux_nrpn,
109912 + .sysex = snd_emux_sysex,
109913 };
109914
109915
109916 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
109917 new file mode 100644
109918 index 0000000..de92ed9
109919 --- /dev/null
109920 +++ b/tools/gcc/.gitignore
109921 @@ -0,0 +1 @@
109922 +randomize_layout_seed.h
109923 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
109924 new file mode 100644
109925 index 0000000..7b8921f
109926 --- /dev/null
109927 +++ b/tools/gcc/Makefile
109928 @@ -0,0 +1,52 @@
109929 +#CC := gcc
109930 +#PLUGIN_SOURCE_FILES := pax_plugin.c
109931 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
109932 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
109933 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
109934 +
109935 +ifeq ($(PLUGINCC),$(HOSTCC))
109936 +HOSTLIBS := hostlibs
109937 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
109938 +export HOST_EXTRACFLAGS
109939 +else
109940 +HOSTLIBS := hostcxxlibs
109941 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
109942 +export HOST_EXTRACXXFLAGS
109943 +endif
109944 +
109945 +export GCCPLUGINS_DIR HOSTLIBS
109946 +
109947 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
109948 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
109949 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
109950 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
109951 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
109952 +$(HOSTLIBS)-y += colorize_plugin.so
109953 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
109954 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
109955 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
109956 +
109957 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
109958 +subdir- += size_overflow_plugin
109959 +
109960 +always := $($(HOSTLIBS)-y)
109961 +
109962 +constify_plugin-objs := constify_plugin.o
109963 +stackleak_plugin-objs := stackleak_plugin.o
109964 +kallocstat_plugin-objs := kallocstat_plugin.o
109965 +kernexec_plugin-objs := kernexec_plugin.o
109966 +checker_plugin-objs := checker_plugin.o
109967 +colorize_plugin-objs := colorize_plugin.o
109968 +latent_entropy_plugin-objs := latent_entropy_plugin.o
109969 +structleak_plugin-objs := structleak_plugin.o
109970 +randomize_layout_plugin-objs := randomize_layout_plugin.o
109971 +
109972 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
109973 +
109974 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
109975 + cmd_create_randomize_layout_seed = \
109976 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
109977 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
109978 + $(call if_changed,create_randomize_layout_seed)
109979 +
109980 +targets += randomize_layout_seed.h randomize_layout_hash.h
109981 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
109982 new file mode 100644
109983 index 0000000..5452feea
109984 --- /dev/null
109985 +++ b/tools/gcc/checker_plugin.c
109986 @@ -0,0 +1,150 @@
109987 +/*
109988 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
109989 + * Licensed under the GPL v2
109990 + *
109991 + * Note: the choice of the license means that the compilation process is
109992 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
109993 + * but for the kernel it doesn't matter since it doesn't link against
109994 + * any of the gcc libraries
109995 + *
109996 + * gcc plugin to implement various sparse (source code checker) features
109997 + *
109998 + * TODO:
109999 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110000 + *
110001 + * BUGS:
110002 + * - none known
110003 + */
110004 +
110005 +#include "gcc-common.h"
110006 +
110007 +extern void c_register_addr_space (const char *str, addr_space_t as);
110008 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110009 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110010 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110011 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110012 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110013 +
110014 +int plugin_is_GPL_compatible;
110015 +
110016 +static struct plugin_info checker_plugin_info = {
110017 + .version = "201304082245",
110018 + .help = NULL,
110019 +};
110020 +
110021 +#define ADDR_SPACE_KERNEL 0
110022 +#define ADDR_SPACE_FORCE_KERNEL 1
110023 +#define ADDR_SPACE_USER 2
110024 +#define ADDR_SPACE_FORCE_USER 3
110025 +#define ADDR_SPACE_IOMEM 0
110026 +#define ADDR_SPACE_FORCE_IOMEM 0
110027 +#define ADDR_SPACE_PERCPU 0
110028 +#define ADDR_SPACE_FORCE_PERCPU 0
110029 +#define ADDR_SPACE_RCU 0
110030 +#define ADDR_SPACE_FORCE_RCU 0
110031 +
110032 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110033 +{
110034 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110035 +}
110036 +
110037 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110038 +{
110039 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110040 +}
110041 +
110042 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110043 +{
110044 + return default_addr_space_valid_pointer_mode(mode, as);
110045 +}
110046 +
110047 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110048 +{
110049 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110050 +}
110051 +
110052 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110053 +{
110054 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110055 +}
110056 +
110057 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110058 +{
110059 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110060 + return true;
110061 +
110062 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110063 + return true;
110064 +
110065 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110066 + return true;
110067 +
110068 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110069 + return true;
110070 +
110071 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110072 + return true;
110073 +
110074 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110075 + return true;
110076 +
110077 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110078 + return true;
110079 +
110080 + return subset == superset;
110081 +}
110082 +
110083 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110084 +{
110085 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110086 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110087 +
110088 + return op;
110089 +}
110090 +
110091 +static void register_checker_address_spaces(void *event_data, void *data)
110092 +{
110093 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110094 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110095 + c_register_addr_space("__user", ADDR_SPACE_USER);
110096 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110097 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110098 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110099 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110100 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110101 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110102 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110103 +
110104 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110105 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110106 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110107 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110108 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110109 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110110 + targetm.addr_space.convert = checker_addr_space_convert;
110111 +}
110112 +
110113 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110114 +{
110115 + const char * const plugin_name = plugin_info->base_name;
110116 + const int argc = plugin_info->argc;
110117 + const struct plugin_argument * const argv = plugin_info->argv;
110118 + int i;
110119 +
110120 + if (!plugin_default_version_check(version, &gcc_version)) {
110121 + error(G_("incompatible gcc/plugin versions"));
110122 + return 1;
110123 + }
110124 +
110125 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110126 +
110127 + for (i = 0; i < argc; ++i)
110128 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110129 +
110130 + if (TARGET_64BIT == 0)
110131 + return 0;
110132 +
110133 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110134 +
110135 + return 0;
110136 +}
110137 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110138 new file mode 100644
110139 index 0000000..54461af
110140 --- /dev/null
110141 +++ b/tools/gcc/colorize_plugin.c
110142 @@ -0,0 +1,210 @@
110143 +/*
110144 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110145 + * Licensed under the GPL v2
110146 + *
110147 + * Note: the choice of the license means that the compilation process is
110148 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110149 + * but for the kernel it doesn't matter since it doesn't link against
110150 + * any of the gcc libraries
110151 + *
110152 + * gcc plugin to colorize diagnostic output
110153 + *
110154 + */
110155 +
110156 +#include "gcc-common.h"
110157 +
110158 +int plugin_is_GPL_compatible;
110159 +
110160 +static struct plugin_info colorize_plugin_info = {
110161 + .version = "201404202350",
110162 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110163 +};
110164 +
110165 +#define GREEN "\033[32m\033[K"
110166 +#define LIGHTGREEN "\033[1;32m\033[K"
110167 +#define YELLOW "\033[33m\033[K"
110168 +#define LIGHTYELLOW "\033[1;33m\033[K"
110169 +#define RED "\033[31m\033[K"
110170 +#define LIGHTRED "\033[1;31m\033[K"
110171 +#define BLUE "\033[34m\033[K"
110172 +#define LIGHTBLUE "\033[1;34m\033[K"
110173 +#define BRIGHT "\033[1;m\033[K"
110174 +#define NORMAL "\033[m\033[K"
110175 +
110176 +static diagnostic_starter_fn old_starter;
110177 +static diagnostic_finalizer_fn old_finalizer;
110178 +
110179 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110180 +{
110181 + const char *color;
110182 + char *newprefix;
110183 +
110184 + switch (diagnostic->kind) {
110185 + case DK_NOTE:
110186 + color = LIGHTBLUE;
110187 + break;
110188 +
110189 + case DK_PEDWARN:
110190 + case DK_WARNING:
110191 + color = LIGHTYELLOW;
110192 + break;
110193 +
110194 + case DK_ERROR:
110195 + case DK_FATAL:
110196 + case DK_ICE:
110197 + case DK_PERMERROR:
110198 + case DK_SORRY:
110199 + color = LIGHTRED;
110200 + break;
110201 +
110202 + default:
110203 + color = NORMAL;
110204 + }
110205 +
110206 + old_starter(context, diagnostic);
110207 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110208 + return;
110209 + pp_destroy_prefix(context->printer);
110210 + pp_set_prefix(context->printer, newprefix);
110211 +}
110212 +
110213 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110214 +{
110215 + old_finalizer(context, diagnostic);
110216 +}
110217 +
110218 +static void colorize_arm(void)
110219 +{
110220 + old_starter = diagnostic_starter(global_dc);
110221 + old_finalizer = diagnostic_finalizer(global_dc);
110222 +
110223 + diagnostic_starter(global_dc) = start_colorize;
110224 + diagnostic_finalizer(global_dc) = finalize_colorize;
110225 +}
110226 +
110227 +static unsigned int execute_colorize_rearm(void)
110228 +{
110229 + if (diagnostic_starter(global_dc) == start_colorize)
110230 + return 0;
110231 +
110232 + colorize_arm();
110233 + return 0;
110234 +}
110235 +
110236 +#if BUILDING_GCC_VERSION >= 4009
110237 +static const struct pass_data colorize_rearm_pass_data = {
110238 +#else
110239 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110240 + .pass = {
110241 +#endif
110242 + .type = SIMPLE_IPA_PASS,
110243 + .name = "colorize_rearm",
110244 +#if BUILDING_GCC_VERSION >= 4008
110245 + .optinfo_flags = OPTGROUP_NONE,
110246 +#endif
110247 +#if BUILDING_GCC_VERSION >= 4009
110248 + .has_gate = false,
110249 + .has_execute = true,
110250 +#else
110251 + .gate = NULL,
110252 + .execute = execute_colorize_rearm,
110253 + .sub = NULL,
110254 + .next = NULL,
110255 + .static_pass_number = 0,
110256 +#endif
110257 + .tv_id = TV_NONE,
110258 + .properties_required = 0,
110259 + .properties_provided = 0,
110260 + .properties_destroyed = 0,
110261 + .todo_flags_start = 0,
110262 + .todo_flags_finish = 0
110263 +#if BUILDING_GCC_VERSION < 4009
110264 + }
110265 +#endif
110266 +};
110267 +
110268 +#if BUILDING_GCC_VERSION >= 4009
110269 +namespace {
110270 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110271 +public:
110272 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110273 + unsigned int execute() { return execute_colorize_rearm(); }
110274 +};
110275 +}
110276 +
110277 +static opt_pass *make_colorize_rearm_pass(void)
110278 +{
110279 + return new colorize_rearm_pass();
110280 +}
110281 +#else
110282 +static struct opt_pass *make_colorize_rearm_pass(void)
110283 +{
110284 + return &colorize_rearm_pass.pass;
110285 +}
110286 +#endif
110287 +
110288 +static void colorize_start_unit(void *gcc_data, void *user_data)
110289 +{
110290 + colorize_arm();
110291 +}
110292 +
110293 +static bool should_colorize(void)
110294 +{
110295 +#if BUILDING_GCC_VERSION >= 4009
110296 + return false;
110297 +#else
110298 + char const *t = getenv("TERM");
110299 +
110300 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
110301 +#endif
110302 +}
110303 +
110304 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110305 +{
110306 + const char * const plugin_name = plugin_info->base_name;
110307 + const int argc = plugin_info->argc;
110308 + const struct plugin_argument * const argv = plugin_info->argv;
110309 + int i;
110310 + struct register_pass_info colorize_rearm_pass_info;
110311 + bool colorize;
110312 +
110313 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
110314 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
110315 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
110316 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110317 +
110318 + if (!plugin_default_version_check(version, &gcc_version)) {
110319 + error(G_("incompatible gcc/plugin versions"));
110320 + return 1;
110321 + }
110322 +
110323 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
110324 +
110325 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
110326 +
110327 + for (i = 0; i < argc; ++i) {
110328 + if (!strcmp(argv[i].key, "color")) {
110329 + if (!argv[i].value) {
110330 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110331 + continue;
110332 + }
110333 + if (!strcmp(argv[i].value, "always"))
110334 + colorize = true;
110335 + else if (!strcmp(argv[i].value, "never"))
110336 + colorize = false;
110337 + else if (!strcmp(argv[i].value, "auto"))
110338 + colorize = should_colorize();
110339 + else
110340 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
110341 + continue;
110342 + }
110343 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110344 + }
110345 +
110346 + if (colorize) {
110347 + // TODO: parse GCC_COLORS as used by gcc 4.9+
110348 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
110349 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
110350 + }
110351 + return 0;
110352 +}
110353 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
110354 new file mode 100644
110355 index 0000000..82bc5a8
110356 --- /dev/null
110357 +++ b/tools/gcc/constify_plugin.c
110358 @@ -0,0 +1,557 @@
110359 +/*
110360 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
110361 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
110362 + * Licensed under the GPL v2, or (at your option) v3
110363 + *
110364 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
110365 + *
110366 + * Homepage:
110367 + * http://www.grsecurity.net/~ephox/const_plugin/
110368 + *
110369 + * Usage:
110370 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
110371 + * $ gcc -fplugin=constify_plugin.so test.c -O2
110372 + */
110373 +
110374 +#include "gcc-common.h"
110375 +
110376 +// unused C type flag in all versions 4.5-4.9
110377 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
110378 +
110379 +int plugin_is_GPL_compatible;
110380 +
110381 +static struct plugin_info const_plugin_info = {
110382 + .version = "201401270210",
110383 + .help = "no-constify\tturn off constification\n",
110384 +};
110385 +
110386 +typedef struct {
110387 + bool has_fptr_field;
110388 + bool has_writable_field;
110389 + bool has_do_const_field;
110390 + bool has_no_const_field;
110391 +} constify_info;
110392 +
110393 +static const_tree get_field_type(const_tree field)
110394 +{
110395 + return strip_array_types(TREE_TYPE(field));
110396 +}
110397 +
110398 +static bool is_fptr(const_tree field)
110399 +{
110400 + const_tree ptr = get_field_type(field);
110401 +
110402 + if (TREE_CODE(ptr) != POINTER_TYPE)
110403 + return false;
110404 +
110405 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
110406 +}
110407 +
110408 +/*
110409 + * determine whether the given structure type meets the requirements for automatic constification,
110410 + * including the constification attributes on nested structure types
110411 + */
110412 +static void constifiable(const_tree node, constify_info *cinfo)
110413 +{
110414 + const_tree field;
110415 +
110416 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110417 +
110418 + // e.g., pointer to structure fields while still constructing the structure type
110419 + if (TYPE_FIELDS(node) == NULL_TREE)
110420 + return;
110421 +
110422 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
110423 + const_tree type = get_field_type(field);
110424 + enum tree_code code = TREE_CODE(type);
110425 +
110426 + if (node == type)
110427 + continue;
110428 +
110429 + if (is_fptr(field))
110430 + cinfo->has_fptr_field = true;
110431 + else if (!TREE_READONLY(field))
110432 + cinfo->has_writable_field = true;
110433 +
110434 + if (code == RECORD_TYPE || code == UNION_TYPE) {
110435 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110436 + cinfo->has_do_const_field = true;
110437 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
110438 + cinfo->has_no_const_field = true;
110439 + else
110440 + constifiable(type, cinfo);
110441 + }
110442 + }
110443 +}
110444 +
110445 +static bool constified(const_tree node)
110446 +{
110447 + constify_info cinfo = {
110448 + .has_fptr_field = false,
110449 + .has_writable_field = false,
110450 + .has_do_const_field = false,
110451 + .has_no_const_field = false
110452 + };
110453 +
110454 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110455 +
110456 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
110457 +// gcc_assert(!TYPE_READONLY(node));
110458 + return false;
110459 + }
110460 +
110461 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
110462 + gcc_assert(TYPE_READONLY(node));
110463 + return true;
110464 + }
110465 +
110466 + constifiable(node, &cinfo);
110467 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
110468 + return false;
110469 +
110470 + return TYPE_READONLY(node);
110471 +}
110472 +
110473 +static void deconstify_tree(tree node);
110474 +
110475 +static void deconstify_type(tree type)
110476 +{
110477 + tree field;
110478 +
110479 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
110480 +
110481 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
110482 + const_tree fieldtype = get_field_type(field);
110483 +
110484 + // special case handling of simple ptr-to-same-array-type members
110485 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
110486 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
110487 +
110488 + if (TREE_TYPE(TREE_TYPE(field)) == type)
110489 + continue;
110490 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
110491 + continue;
110492 + if (!constified(ptrtype))
110493 + continue;
110494 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
110495 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
110496 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
110497 + }
110498 + continue;
110499 + }
110500 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
110501 + continue;
110502 + if (!constified(fieldtype))
110503 + continue;
110504 +
110505 + deconstify_tree(field);
110506 + TREE_READONLY(field) = 0;
110507 + }
110508 + TYPE_READONLY(type) = 0;
110509 + C_TYPE_FIELDS_READONLY(type) = 0;
110510 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110511 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110512 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
110513 + }
110514 +}
110515 +
110516 +static void deconstify_tree(tree node)
110517 +{
110518 + tree old_type, new_type, field;
110519 +
110520 + old_type = TREE_TYPE(node);
110521 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
110522 + node = TREE_TYPE(node) = copy_node(old_type);
110523 + old_type = TREE_TYPE(old_type);
110524 + }
110525 +
110526 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
110527 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
110528 +
110529 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
110530 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
110531 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
110532 + DECL_FIELD_CONTEXT(field) = new_type;
110533 +
110534 + deconstify_type(new_type);
110535 +
110536 + TREE_TYPE(node) = new_type;
110537 +}
110538 +
110539 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110540 +{
110541 + tree type;
110542 + constify_info cinfo = {
110543 + .has_fptr_field = false,
110544 + .has_writable_field = false,
110545 + .has_do_const_field = false,
110546 + .has_no_const_field = false
110547 + };
110548 +
110549 + *no_add_attrs = true;
110550 + if (TREE_CODE(*node) == FUNCTION_DECL) {
110551 + error("%qE attribute does not apply to functions (%qF)", name, *node);
110552 + return NULL_TREE;
110553 + }
110554 +
110555 + if (TREE_CODE(*node) == PARM_DECL) {
110556 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
110557 + return NULL_TREE;
110558 + }
110559 +
110560 + if (TREE_CODE(*node) == VAR_DECL) {
110561 + error("%qE attribute does not apply to variables (%qD)", name, *node);
110562 + return NULL_TREE;
110563 + }
110564 +
110565 + if (TYPE_P(*node)) {
110566 + type = *node;
110567 + } else {
110568 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
110569 + type = TREE_TYPE(*node);
110570 + }
110571 +
110572 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
110573 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
110574 + return NULL_TREE;
110575 + }
110576 +
110577 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
110578 + error("%qE attribute is already applied to the type %qT", name, type);
110579 + return NULL_TREE;
110580 + }
110581 +
110582 + if (TYPE_P(*node)) {
110583 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110584 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
110585 + else
110586 + *no_add_attrs = false;
110587 + return NULL_TREE;
110588 + }
110589 +
110590 + constifiable(type, &cinfo);
110591 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110592 + deconstify_tree(*node);
110593 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
110594 + return NULL_TREE;
110595 + }
110596 +
110597 + error("%qE attribute used on type %qT that is not constified", name, type);
110598 + return NULL_TREE;
110599 +}
110600 +
110601 +static void constify_type(tree type)
110602 +{
110603 + TYPE_READONLY(type) = 1;
110604 + C_TYPE_FIELDS_READONLY(type) = 1;
110605 + TYPE_CONSTIFY_VISITED(type) = 1;
110606 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110607 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
110608 +}
110609 +
110610 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110611 +{
110612 + *no_add_attrs = true;
110613 + if (!TYPE_P(*node)) {
110614 + error("%qE attribute applies to types only (%qD)", name, *node);
110615 + return NULL_TREE;
110616 + }
110617 +
110618 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
110619 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
110620 + return NULL_TREE;
110621 + }
110622 +
110623 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
110624 + error("%qE attribute used on %qT is already applied to the type", name, *node);
110625 + return NULL_TREE;
110626 + }
110627 +
110628 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
110629 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
110630 + return NULL_TREE;
110631 + }
110632 +
110633 + *no_add_attrs = false;
110634 + return NULL_TREE;
110635 +}
110636 +
110637 +static struct attribute_spec no_const_attr = {
110638 + .name = "no_const",
110639 + .min_length = 0,
110640 + .max_length = 0,
110641 + .decl_required = false,
110642 + .type_required = false,
110643 + .function_type_required = false,
110644 + .handler = handle_no_const_attribute,
110645 +#if BUILDING_GCC_VERSION >= 4007
110646 + .affects_type_identity = true
110647 +#endif
110648 +};
110649 +
110650 +static struct attribute_spec do_const_attr = {
110651 + .name = "do_const",
110652 + .min_length = 0,
110653 + .max_length = 0,
110654 + .decl_required = false,
110655 + .type_required = false,
110656 + .function_type_required = false,
110657 + .handler = handle_do_const_attribute,
110658 +#if BUILDING_GCC_VERSION >= 4007
110659 + .affects_type_identity = true
110660 +#endif
110661 +};
110662 +
110663 +static void register_attributes(void *event_data, void *data)
110664 +{
110665 + register_attribute(&no_const_attr);
110666 + register_attribute(&do_const_attr);
110667 +}
110668 +
110669 +static void finish_type(void *event_data, void *data)
110670 +{
110671 + tree type = (tree)event_data;
110672 + constify_info cinfo = {
110673 + .has_fptr_field = false,
110674 + .has_writable_field = false,
110675 + .has_do_const_field = false,
110676 + .has_no_const_field = false
110677 + };
110678 +
110679 + if (type == NULL_TREE || type == error_mark_node)
110680 + return;
110681 +
110682 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
110683 + return;
110684 +
110685 + constifiable(type, &cinfo);
110686 +
110687 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
110688 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
110689 + deconstify_type(type);
110690 + TYPE_CONSTIFY_VISITED(type) = 1;
110691 + } else
110692 + error("'no_const' attribute used on type %qT that is not constified", type);
110693 + return;
110694 + }
110695 +
110696 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110697 + if (!cinfo.has_writable_field) {
110698 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
110699 + return;
110700 + }
110701 + constify_type(type);
110702 + return;
110703 + }
110704 +
110705 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
110706 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110707 + error("'do_const' attribute used on type %qT that is constified", type);
110708 + return;
110709 + }
110710 + constify_type(type);
110711 + return;
110712 + }
110713 +
110714 + deconstify_type(type);
110715 + TYPE_CONSTIFY_VISITED(type) = 1;
110716 +}
110717 +
110718 +static void check_global_variables(void *event_data, void *data)
110719 +{
110720 +#if BUILDING_GCC_VERSION >= 4009
110721 + varpool_node *node;
110722 +#else
110723 + struct varpool_node *node;
110724 +#endif
110725 +
110726 + FOR_EACH_VARIABLE(node) {
110727 + tree var = NODE_DECL(node);
110728 + tree type = TREE_TYPE(var);
110729 +
110730 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110731 + continue;
110732 +
110733 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
110734 + continue;
110735 +
110736 + if (!TYPE_CONSTIFY_VISITED(type))
110737 + continue;
110738 +
110739 + if (DECL_EXTERNAL(var))
110740 + continue;
110741 +
110742 + if (DECL_INITIAL(var))
110743 + continue;
110744 +
110745 + // this works around a gcc bug/feature where uninitialized globals
110746 + // are moved into the .bss section regardless of any constification
110747 + DECL_INITIAL(var) = build_constructor(type, NULL);
110748 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
110749 + }
110750 +}
110751 +
110752 +static unsigned int check_local_variables(void)
110753 +{
110754 + unsigned int ret = 0;
110755 + tree var;
110756 +
110757 + unsigned int i;
110758 +
110759 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110760 + tree type = TREE_TYPE(var);
110761 +
110762 + gcc_assert(DECL_P(var));
110763 + if (is_global_var(var))
110764 + continue;
110765 +
110766 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110767 + continue;
110768 +
110769 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
110770 + continue;
110771 +
110772 + if (!TYPE_CONSTIFY_VISITED(type))
110773 + continue;
110774 +
110775 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
110776 + ret = 1;
110777 + }
110778 + return ret;
110779 +}
110780 +
110781 +#if BUILDING_GCC_VERSION >= 4009
110782 +static const struct pass_data check_local_variables_pass_data = {
110783 +#else
110784 +static struct gimple_opt_pass check_local_variables_pass = {
110785 + .pass = {
110786 +#endif
110787 + .type = GIMPLE_PASS,
110788 + .name = "check_local_variables",
110789 +#if BUILDING_GCC_VERSION >= 4008
110790 + .optinfo_flags = OPTGROUP_NONE,
110791 +#endif
110792 +#if BUILDING_GCC_VERSION >= 4009
110793 + .has_gate = false,
110794 + .has_execute = true,
110795 +#else
110796 + .gate = NULL,
110797 + .execute = check_local_variables,
110798 + .sub = NULL,
110799 + .next = NULL,
110800 + .static_pass_number = 0,
110801 +#endif
110802 + .tv_id = TV_NONE,
110803 + .properties_required = 0,
110804 + .properties_provided = 0,
110805 + .properties_destroyed = 0,
110806 + .todo_flags_start = 0,
110807 + .todo_flags_finish = 0
110808 +#if BUILDING_GCC_VERSION < 4009
110809 + }
110810 +#endif
110811 +};
110812 +
110813 +#if BUILDING_GCC_VERSION >= 4009
110814 +namespace {
110815 +class check_local_variables_pass : public gimple_opt_pass {
110816 +public:
110817 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
110818 + unsigned int execute() { return check_local_variables(); }
110819 +};
110820 +}
110821 +
110822 +static opt_pass *make_check_local_variables_pass(void)
110823 +{
110824 + return new check_local_variables_pass();
110825 +}
110826 +#else
110827 +static struct opt_pass *make_check_local_variables_pass(void)
110828 +{
110829 + return &check_local_variables_pass.pass;
110830 +}
110831 +#endif
110832 +
110833 +static struct {
110834 + const char *name;
110835 + const char *asm_op;
110836 +} sections[] = {
110837 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
110838 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
110839 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
110840 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
110841 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
110842 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
110843 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
110844 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
110845 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
110846 +};
110847 +
110848 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
110849 +
110850 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
110851 +{
110852 + size_t i;
110853 +
110854 + for (i = 0; i < ARRAY_SIZE(sections); i++)
110855 + if (!strcmp(sections[i].name, name))
110856 + return 0;
110857 + return old_section_type_flags(decl, name, reloc);
110858 +}
110859 +
110860 +static void constify_start_unit(void *gcc_data, void *user_data)
110861 +{
110862 +// size_t i;
110863 +
110864 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
110865 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
110866 +// sections[i].section = get_section(sections[i].name, 0, NULL);
110867 +
110868 + old_section_type_flags = targetm.section_type_flags;
110869 + targetm.section_type_flags = constify_section_type_flags;
110870 +}
110871 +
110872 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110873 +{
110874 + const char * const plugin_name = plugin_info->base_name;
110875 + const int argc = plugin_info->argc;
110876 + const struct plugin_argument * const argv = plugin_info->argv;
110877 + int i;
110878 + bool constify = true;
110879 +
110880 + struct register_pass_info check_local_variables_pass_info;
110881 +
110882 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
110883 + check_local_variables_pass_info.reference_pass_name = "ssa";
110884 + check_local_variables_pass_info.ref_pass_instance_number = 1;
110885 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
110886 +
110887 + if (!plugin_default_version_check(version, &gcc_version)) {
110888 + error(G_("incompatible gcc/plugin versions"));
110889 + return 1;
110890 + }
110891 +
110892 + for (i = 0; i < argc; ++i) {
110893 + if (!(strcmp(argv[i].key, "no-constify"))) {
110894 + constify = false;
110895 + continue;
110896 + }
110897 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110898 + }
110899 +
110900 + if (strcmp(lang_hooks.name, "GNU C")) {
110901 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110902 + constify = false;
110903 + }
110904 +
110905 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
110906 + if (constify) {
110907 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110908 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110909 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
110910 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
110911 + }
110912 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110913 +
110914 + return 0;
110915 +}
110916 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
110917 new file mode 100644
110918 index 0000000..e90c205
110919 --- /dev/null
110920 +++ b/tools/gcc/gcc-common.h
110921 @@ -0,0 +1,295 @@
110922 +#ifndef GCC_COMMON_H_INCLUDED
110923 +#define GCC_COMMON_H_INCLUDED
110924 +
110925 +#include "plugin.h"
110926 +#include "bversion.h"
110927 +#include "plugin-version.h"
110928 +#include "config.h"
110929 +#include "system.h"
110930 +#include "coretypes.h"
110931 +#include "tm.h"
110932 +#include "line-map.h"
110933 +#include "input.h"
110934 +#include "tree.h"
110935 +
110936 +#include "tree-inline.h"
110937 +#include "version.h"
110938 +#include "rtl.h"
110939 +#include "tm_p.h"
110940 +#include "flags.h"
110941 +//#include "insn-attr.h"
110942 +//#include "insn-config.h"
110943 +//#include "insn-flags.h"
110944 +#include "hard-reg-set.h"
110945 +//#include "recog.h"
110946 +#include "output.h"
110947 +#include "except.h"
110948 +#include "function.h"
110949 +#include "toplev.h"
110950 +//#include "expr.h"
110951 +#include "basic-block.h"
110952 +#include "intl.h"
110953 +#include "ggc.h"
110954 +//#include "regs.h"
110955 +#include "timevar.h"
110956 +
110957 +#include "params.h"
110958 +#include "pointer-set.h"
110959 +#include "emit-rtl.h"
110960 +//#include "reload.h"
110961 +//#include "ira.h"
110962 +//#include "dwarf2asm.h"
110963 +#include "debug.h"
110964 +#include "target.h"
110965 +#include "langhooks.h"
110966 +#include "cfgloop.h"
110967 +//#include "hosthooks.h"
110968 +#include "cgraph.h"
110969 +#include "opts.h"
110970 +//#include "coverage.h"
110971 +//#include "value-prof.h"
110972 +
110973 +#if BUILDING_GCC_VERSION >= 4007
110974 +#include "tree-pretty-print.h"
110975 +#include "gimple-pretty-print.h"
110976 +#include "c-tree.h"
110977 +//#include "alloc-pool.h"
110978 +#endif
110979 +
110980 +#if BUILDING_GCC_VERSION <= 4008
110981 +#include "tree-flow.h"
110982 +#else
110983 +#include "tree-cfgcleanup.h"
110984 +#endif
110985 +
110986 +#include "diagnostic.h"
110987 +//#include "tree-diagnostic.h"
110988 +#include "tree-dump.h"
110989 +#include "tree-pass.h"
110990 +//#include "df.h"
110991 +#include "predict.h"
110992 +#include "ipa-utils.h"
110993 +
110994 +#if BUILDING_GCC_VERSION >= 4009
110995 +#include "varasm.h"
110996 +#include "stor-layout.h"
110997 +#include "internal-fn.h"
110998 +#include "gimple-expr.h"
110999 +//#include "diagnostic-color.h"
111000 +#include "context.h"
111001 +#include "tree-ssa-alias.h"
111002 +#include "stringpool.h"
111003 +#include "tree-ssanames.h"
111004 +#include "print-tree.h"
111005 +#include "tree-eh.h"
111006 +#include "stmt.h"
111007 +#endif
111008 +
111009 +#include "gimple.h"
111010 +
111011 +#if BUILDING_GCC_VERSION >= 4009
111012 +#include "tree-ssa-operands.h"
111013 +#include "tree-phinodes.h"
111014 +#include "tree-cfg.h"
111015 +#include "gimple-iterator.h"
111016 +#include "gimple-ssa.h"
111017 +#include "ssa-iterators.h"
111018 +#endif
111019 +
111020 +//#include "lto/lto.h"
111021 +//#include "data-streamer.h"
111022 +//#include "lto-compress.h"
111023 +
111024 +//#include "expr.h" where are you...
111025 +extern rtx emit_move_insn(rtx x, rtx y);
111026 +
111027 +// missing from basic_block.h...
111028 +extern void debug_dominance_info(enum cdi_direction dir);
111029 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111030 +
111031 +#define __unused __attribute__((__unused__))
111032 +
111033 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111034 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111035 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111036 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111037 +
111038 +#if BUILDING_GCC_VERSION == 4005
111039 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111040 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111041 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111042 +#define TODO_rebuild_cgraph_edges 0
111043 +
111044 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111045 +{
111046 + tree fndecl;
111047 +
111048 + if (!is_gimple_call(stmt))
111049 + return false;
111050 + fndecl = gimple_call_fndecl(stmt);
111051 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111052 + return false;
111053 +// print_node(stderr, "pax", fndecl, 4);
111054 + return DECL_FUNCTION_CODE(fndecl) == code;
111055 +}
111056 +
111057 +static inline bool is_simple_builtin(tree decl)
111058 +{
111059 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111060 + return false;
111061 +
111062 + switch (DECL_FUNCTION_CODE(decl)) {
111063 + /* Builtins that expand to constants. */
111064 + case BUILT_IN_CONSTANT_P:
111065 + case BUILT_IN_EXPECT:
111066 + case BUILT_IN_OBJECT_SIZE:
111067 + case BUILT_IN_UNREACHABLE:
111068 + /* Simple register moves or loads from stack. */
111069 + case BUILT_IN_RETURN_ADDRESS:
111070 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111071 + case BUILT_IN_FROB_RETURN_ADDR:
111072 + case BUILT_IN_RETURN:
111073 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111074 + case BUILT_IN_FRAME_ADDRESS:
111075 + case BUILT_IN_VA_END:
111076 + case BUILT_IN_STACK_SAVE:
111077 + case BUILT_IN_STACK_RESTORE:
111078 + /* Exception state returns or moves registers around. */
111079 + case BUILT_IN_EH_FILTER:
111080 + case BUILT_IN_EH_POINTER:
111081 + case BUILT_IN_EH_COPY_VALUES:
111082 + return true;
111083 +
111084 + default:
111085 + return false;
111086 + }
111087 +}
111088 +#endif
111089 +
111090 +#if BUILDING_GCC_VERSION <= 4006
111091 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111092 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111093 +
111094 +// should come from c-tree.h if only it were installed for gcc 4.5...
111095 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111096 +
111097 +#define get_random_seed(noinit) ({ \
111098 + unsigned HOST_WIDE_INT seed; \
111099 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111100 + seed * seed; })
111101 +
111102 +static inline bool gimple_clobber_p(gimple s)
111103 +{
111104 + return false;
111105 +}
111106 +
111107 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111108 +{
111109 + return implicit_built_in_decls[fncode];
111110 +}
111111 +
111112 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111113 +{
111114 + struct cgraph_node *node = cgraph_get_node(decl);
111115 +
111116 + return node ? node : cgraph_node(decl);
111117 +}
111118 +
111119 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111120 +{
111121 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111122 +}
111123 +
111124 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111125 +{
111126 + struct cgraph_node *node;
111127 +
111128 + for (node = cgraph_nodes; node; node = node->next)
111129 + if (cgraph_function_with_gimple_body_p(node))
111130 + return node;
111131 + return NULL;
111132 +}
111133 +
111134 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111135 +{
111136 + for (node = node->next; node; node = node->next)
111137 + if (cgraph_function_with_gimple_body_p(node))
111138 + return node;
111139 + return NULL;
111140 +}
111141 +
111142 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111143 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111144 + (node) = cgraph_next_function_with_gimple_body(node))
111145 +#endif
111146 +
111147 +#if BUILDING_GCC_VERSION == 4006
111148 +extern void debug_gimple_stmt(gimple);
111149 +extern void debug_gimple_seq(gimple_seq);
111150 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111151 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111152 +extern void print_gimple_expr(FILE *, gimple, int, int);
111153 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111154 +#endif
111155 +
111156 +#if BUILDING_GCC_VERSION <= 4007
111157 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111158 +#define PROP_loops 0
111159 +
111160 +static inline int bb_loop_depth(const_basic_block bb)
111161 +{
111162 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111163 +}
111164 +
111165 +static inline bool gimple_store_p(gimple gs)
111166 +{
111167 + tree lhs = gimple_get_lhs(gs);
111168 + return lhs && !is_gimple_reg(lhs);
111169 +}
111170 +#endif
111171 +
111172 +#if BUILDING_GCC_VERSION >= 4007
111173 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111174 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111175 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111176 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111177 +#endif
111178 +
111179 +#if BUILDING_GCC_VERSION <= 4008
111180 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111181 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111182 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111183 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111184 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111185 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111186 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111187 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111188 +
111189 +static inline const char *get_tree_code_name(enum tree_code code)
111190 +{
111191 + gcc_assert(code < MAX_TREE_CODES);
111192 + return tree_code_name[code];
111193 +}
111194 +
111195 +#define ipa_remove_stmt_references(cnode, stmt)
111196 +#endif
111197 +
111198 +#if BUILDING_GCC_VERSION == 4008
111199 +#define NODE_DECL(node) node->symbol.decl
111200 +#else
111201 +#define NODE_DECL(node) node->decl
111202 +#endif
111203 +
111204 +#if BUILDING_GCC_VERSION >= 4008
111205 +#define add_referenced_var(var)
111206 +#define mark_sym_for_renaming(var)
111207 +#define varpool_mark_needed_node(node)
111208 +#define TODO_dump_func 0
111209 +#define TODO_dump_cgraph 0
111210 +#endif
111211 +
111212 +#if BUILDING_GCC_VERSION >= 4009
111213 +#define TODO_ggc_collect 0
111214 +#endif
111215 +
111216 +#endif
111217 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111218 new file mode 100644
111219 index 0000000..7514850
111220 --- /dev/null
111221 +++ b/tools/gcc/gen-random-seed.sh
111222 @@ -0,0 +1,8 @@
111223 +#!/bin/sh
111224 +
111225 +if [ ! -f "$1" ]; then
111226 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111227 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111228 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111229 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111230 +fi
111231 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111232 new file mode 100644
111233 index 0000000..d81c094
111234 --- /dev/null
111235 +++ b/tools/gcc/kallocstat_plugin.c
111236 @@ -0,0 +1,183 @@
111237 +/*
111238 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111239 + * Licensed under the GPL v2
111240 + *
111241 + * Note: the choice of the license means that the compilation process is
111242 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111243 + * but for the kernel it doesn't matter since it doesn't link against
111244 + * any of the gcc libraries
111245 + *
111246 + * gcc plugin to find the distribution of k*alloc sizes
111247 + *
111248 + * TODO:
111249 + *
111250 + * BUGS:
111251 + * - none known
111252 + */
111253 +
111254 +#include "gcc-common.h"
111255 +
111256 +int plugin_is_GPL_compatible;
111257 +
111258 +static struct plugin_info kallocstat_plugin_info = {
111259 + .version = "201401260140",
111260 + .help = NULL
111261 +};
111262 +
111263 +static const char * const kalloc_functions[] = {
111264 + "__kmalloc",
111265 + "kmalloc",
111266 + "kmalloc_large",
111267 + "kmalloc_node",
111268 + "kmalloc_order",
111269 + "kmalloc_order_trace",
111270 + "kmalloc_slab",
111271 + "kzalloc",
111272 + "kzalloc_node",
111273 +};
111274 +
111275 +static bool is_kalloc(const char *fnname)
111276 +{
111277 + size_t i;
111278 +
111279 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111280 + if (!strcmp(fnname, kalloc_functions[i]))
111281 + return true;
111282 + return false;
111283 +}
111284 +
111285 +static unsigned int execute_kallocstat(void)
111286 +{
111287 + basic_block bb;
111288 +
111289 + // 1. loop through BBs and GIMPLE statements
111290 + FOR_EACH_BB_FN(bb, cfun) {
111291 + gimple_stmt_iterator gsi;
111292 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111293 + // gimple match:
111294 + tree fndecl, size;
111295 + gimple stmt;
111296 + const char *fnname;
111297 +
111298 + // is it a call
111299 + stmt = gsi_stmt(gsi);
111300 + if (!is_gimple_call(stmt))
111301 + continue;
111302 + fndecl = gimple_call_fndecl(stmt);
111303 + if (fndecl == NULL_TREE)
111304 + continue;
111305 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
111306 + continue;
111307 +
111308 + // is it a call to k*alloc
111309 + fnname = DECL_NAME_POINTER(fndecl);
111310 + if (!is_kalloc(fnname))
111311 + continue;
111312 +
111313 + // is the size arg const or the result of a simple const assignment
111314 + size = gimple_call_arg(stmt, 0);
111315 + while (true) {
111316 + expanded_location xloc;
111317 + size_t size_val;
111318 +
111319 + if (TREE_CONSTANT(size)) {
111320 + xloc = expand_location(gimple_location(stmt));
111321 + if (!xloc.file)
111322 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111323 + size_val = TREE_INT_CST_LOW(size);
111324 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
111325 + break;
111326 + }
111327 +
111328 + if (TREE_CODE(size) != SSA_NAME)
111329 + break;
111330 + stmt = SSA_NAME_DEF_STMT(size);
111331 +//debug_gimple_stmt(stmt);
111332 +//debug_tree(size);
111333 + if (!stmt || !is_gimple_assign(stmt))
111334 + break;
111335 + if (gimple_num_ops(stmt) != 2)
111336 + break;
111337 + size = gimple_assign_rhs1(stmt);
111338 + }
111339 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111340 +//debug_tree(gimple_call_fn(call_stmt));
111341 +//print_node(stderr, "pax", fndecl, 4);
111342 + }
111343 + }
111344 +
111345 + return 0;
111346 +}
111347 +
111348 +#if BUILDING_GCC_VERSION >= 4009
111349 +static const struct pass_data kallocstat_pass_data = {
111350 +#else
111351 +static struct gimple_opt_pass kallocstat_pass = {
111352 + .pass = {
111353 +#endif
111354 + .type = GIMPLE_PASS,
111355 + .name = "kallocstat",
111356 +#if BUILDING_GCC_VERSION >= 4008
111357 + .optinfo_flags = OPTGROUP_NONE,
111358 +#endif
111359 +#if BUILDING_GCC_VERSION >= 4009
111360 + .has_gate = false,
111361 + .has_execute = true,
111362 +#else
111363 + .gate = NULL,
111364 + .execute = execute_kallocstat,
111365 + .sub = NULL,
111366 + .next = NULL,
111367 + .static_pass_number = 0,
111368 +#endif
111369 + .tv_id = TV_NONE,
111370 + .properties_required = 0,
111371 + .properties_provided = 0,
111372 + .properties_destroyed = 0,
111373 + .todo_flags_start = 0,
111374 + .todo_flags_finish = 0
111375 +#if BUILDING_GCC_VERSION < 4009
111376 + }
111377 +#endif
111378 +};
111379 +
111380 +#if BUILDING_GCC_VERSION >= 4009
111381 +namespace {
111382 +class kallocstat_pass : public gimple_opt_pass {
111383 +public:
111384 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
111385 + unsigned int execute() { return execute_kallocstat(); }
111386 +};
111387 +}
111388 +
111389 +static opt_pass *make_kallocstat_pass(void)
111390 +{
111391 + return new kallocstat_pass();
111392 +}
111393 +#else
111394 +static struct opt_pass *make_kallocstat_pass(void)
111395 +{
111396 + return &kallocstat_pass.pass;
111397 +}
111398 +#endif
111399 +
111400 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111401 +{
111402 + const char * const plugin_name = plugin_info->base_name;
111403 + struct register_pass_info kallocstat_pass_info;
111404 +
111405 + kallocstat_pass_info.pass = make_kallocstat_pass();
111406 + kallocstat_pass_info.reference_pass_name = "ssa";
111407 + kallocstat_pass_info.ref_pass_instance_number = 1;
111408 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111409 +
111410 + if (!plugin_default_version_check(version, &gcc_version)) {
111411 + error(G_("incompatible gcc/plugin versions"));
111412 + return 1;
111413 + }
111414 +
111415 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
111416 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
111417 +
111418 + return 0;
111419 +}
111420 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
111421 new file mode 100644
111422 index 0000000..89f256d
111423 --- /dev/null
111424 +++ b/tools/gcc/kernexec_plugin.c
111425 @@ -0,0 +1,522 @@
111426 +/*
111427 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111428 + * Licensed under the GPL v2
111429 + *
111430 + * Note: the choice of the license means that the compilation process is
111431 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111432 + * but for the kernel it doesn't matter since it doesn't link against
111433 + * any of the gcc libraries
111434 + *
111435 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
111436 + *
111437 + * TODO:
111438 + *
111439 + * BUGS:
111440 + * - none known
111441 + */
111442 +
111443 +#include "gcc-common.h"
111444 +
111445 +int plugin_is_GPL_compatible;
111446 +
111447 +static struct plugin_info kernexec_plugin_info = {
111448 + .version = "201401260140",
111449 + .help = "method=[bts|or]\tinstrumentation method\n"
111450 +};
111451 +
111452 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
111453 +static void (*kernexec_instrument_retaddr)(rtx);
111454 +
111455 +/*
111456 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
111457 + */
111458 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
111459 +{
111460 + gimple asm_movabs_stmt;
111461 +
111462 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
111463 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
111464 + gimple_asm_set_volatile(asm_movabs_stmt, true);
111465 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
111466 + update_stmt(asm_movabs_stmt);
111467 +}
111468 +
111469 +/*
111470 + * find all asm() stmts that clobber r12 and add a reload of r12
111471 + */
111472 +static unsigned int execute_kernexec_reload(void)
111473 +{
111474 + basic_block bb;
111475 +
111476 + // 1. loop through BBs and GIMPLE statements
111477 + FOR_EACH_BB_FN(bb, cfun) {
111478 + gimple_stmt_iterator gsi;
111479 +
111480 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111481 + // gimple match: __asm__ ("" : : : "r12");
111482 + gimple asm_stmt;
111483 + size_t nclobbers;
111484 +
111485 + // is it an asm ...
111486 + asm_stmt = gsi_stmt(gsi);
111487 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
111488 + continue;
111489 +
111490 + // ... clobbering r12
111491 + nclobbers = gimple_asm_nclobbers(asm_stmt);
111492 + while (nclobbers--) {
111493 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
111494 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
111495 + continue;
111496 + kernexec_reload_fptr_mask(&gsi);
111497 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
111498 + break;
111499 + }
111500 + }
111501 + }
111502 +
111503 + return 0;
111504 +}
111505 +
111506 +/*
111507 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
111508 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
111509 + */
111510 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
111511 +{
111512 + gimple assign_intptr, assign_new_fptr, call_stmt;
111513 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
111514 +
111515 + call_stmt = gsi_stmt(*gsi);
111516 + old_fptr = gimple_call_fn(call_stmt);
111517 +
111518 + // create temporary unsigned long variable used for bitops and cast fptr to it
111519 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
111520 + add_referenced_var(intptr);
111521 + intptr = make_ssa_name(intptr, NULL);
111522 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
111523 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111524 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111525 + update_stmt(assign_intptr);
111526 +
111527 + // apply logical or to temporary unsigned long and bitmask
111528 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
111529 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
111530 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
111531 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
111532 + assign_intptr = gimple_build_assign(intptr, orptr);
111533 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111534 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111535 + update_stmt(assign_intptr);
111536 +
111537 + // cast temporary unsigned long back to a temporary fptr variable
111538 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
111539 + add_referenced_var(new_fptr);
111540 + new_fptr = make_ssa_name(new_fptr, NULL);
111541 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
111542 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
111543 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
111544 + update_stmt(assign_new_fptr);
111545 +
111546 + // replace call stmt fn with the new fptr
111547 + gimple_call_set_fn(call_stmt, new_fptr);
111548 + update_stmt(call_stmt);
111549 +}
111550 +
111551 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
111552 +{
111553 + gimple asm_or_stmt, call_stmt;
111554 + tree old_fptr, new_fptr, input, output;
111555 +#if BUILDING_GCC_VERSION <= 4007
111556 + VEC(tree, gc) *inputs = NULL;
111557 + VEC(tree, gc) *outputs = NULL;
111558 +#else
111559 + vec<tree, va_gc> *inputs = NULL;
111560 + vec<tree, va_gc> *outputs = NULL;
111561 +#endif
111562 +
111563 + call_stmt = gsi_stmt(*gsi);
111564 + old_fptr = gimple_call_fn(call_stmt);
111565 +
111566 + // create temporary fptr variable
111567 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
111568 + add_referenced_var(new_fptr);
111569 + new_fptr = make_ssa_name(new_fptr, NULL);
111570 +
111571 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
111572 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
111573 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
111574 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
111575 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
111576 +#if BUILDING_GCC_VERSION <= 4007
111577 + VEC_safe_push(tree, gc, inputs, input);
111578 + VEC_safe_push(tree, gc, outputs, output);
111579 +#else
111580 + vec_safe_push(inputs, input);
111581 + vec_safe_push(outputs, output);
111582 +#endif
111583 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
111584 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
111585 + gimple_asm_set_volatile(asm_or_stmt, true);
111586 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
111587 + update_stmt(asm_or_stmt);
111588 +
111589 + // replace call stmt fn with the new fptr
111590 + gimple_call_set_fn(call_stmt, new_fptr);
111591 + update_stmt(call_stmt);
111592 +}
111593 +
111594 +/*
111595 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
111596 + */
111597 +static unsigned int execute_kernexec_fptr(void)
111598 +{
111599 + basic_block bb;
111600 +
111601 + // 1. loop through BBs and GIMPLE statements
111602 + FOR_EACH_BB_FN(bb, cfun) {
111603 + gimple_stmt_iterator gsi;
111604 +
111605 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111606 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
111607 + tree fn;
111608 + gimple call_stmt;
111609 +
111610 + // is it a call ...
111611 + call_stmt = gsi_stmt(gsi);
111612 + if (!is_gimple_call(call_stmt))
111613 + continue;
111614 + fn = gimple_call_fn(call_stmt);
111615 + if (TREE_CODE(fn) == ADDR_EXPR)
111616 + continue;
111617 + if (TREE_CODE(fn) != SSA_NAME)
111618 + gcc_unreachable();
111619 +
111620 + // ... through a function pointer
111621 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
111622 + fn = SSA_NAME_VAR(fn);
111623 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
111624 + debug_tree(fn);
111625 + gcc_unreachable();
111626 + }
111627 + }
111628 + fn = TREE_TYPE(fn);
111629 + if (TREE_CODE(fn) != POINTER_TYPE)
111630 + continue;
111631 + fn = TREE_TYPE(fn);
111632 + if (TREE_CODE(fn) != FUNCTION_TYPE)
111633 + continue;
111634 +
111635 + kernexec_instrument_fptr(&gsi);
111636 +
111637 +//debug_tree(gimple_call_fn(call_stmt));
111638 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111639 + }
111640 + }
111641 +
111642 + return 0;
111643 +}
111644 +
111645 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
111646 +static void kernexec_instrument_retaddr_bts(rtx insn)
111647 +{
111648 + rtx btsq;
111649 + rtvec argvec, constraintvec, labelvec;
111650 + int line;
111651 +
111652 + // create asm volatile("btsq $63,(%%rsp)":::)
111653 + argvec = rtvec_alloc(0);
111654 + constraintvec = rtvec_alloc(0);
111655 + labelvec = rtvec_alloc(0);
111656 + line = expand_location(RTL_LOCATION(insn)).line;
111657 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111658 + MEM_VOLATILE_P(btsq) = 1;
111659 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
111660 + emit_insn_before(btsq, insn);
111661 +}
111662 +
111663 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
111664 +static void kernexec_instrument_retaddr_or(rtx insn)
111665 +{
111666 + rtx orq;
111667 + rtvec argvec, constraintvec, labelvec;
111668 + int line;
111669 +
111670 + // create asm volatile("orq %%r12,(%%rsp)":::)
111671 + argvec = rtvec_alloc(0);
111672 + constraintvec = rtvec_alloc(0);
111673 + labelvec = rtvec_alloc(0);
111674 + line = expand_location(RTL_LOCATION(insn)).line;
111675 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111676 + MEM_VOLATILE_P(orq) = 1;
111677 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
111678 + emit_insn_before(orq, insn);
111679 +}
111680 +
111681 +/*
111682 + * find all asm level function returns and forcibly set the highest bit of the return address
111683 + */
111684 +static unsigned int execute_kernexec_retaddr(void)
111685 +{
111686 + rtx insn;
111687 +
111688 +// if (stack_realign_drap)
111689 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
111690 +
111691 + // 1. find function returns
111692 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
111693 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
111694 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
111695 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
111696 + rtx body;
111697 +
111698 + // is it a retn
111699 + if (!JUMP_P(insn))
111700 + continue;
111701 + body = PATTERN(insn);
111702 + if (GET_CODE(body) == PARALLEL)
111703 + body = XVECEXP(body, 0, 0);
111704 + if (!ANY_RETURN_P(body))
111705 + continue;
111706 + kernexec_instrument_retaddr(insn);
111707 + }
111708 +
111709 +// print_simple_rtl(stderr, get_insns());
111710 +// print_rtl(stderr, get_insns());
111711 +
111712 + return 0;
111713 +}
111714 +
111715 +static bool kernexec_cmodel_check(void)
111716 +{
111717 + tree section;
111718 +
111719 + if (ix86_cmodel != CM_KERNEL)
111720 + return false;
111721 +
111722 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
111723 + if (!section || !TREE_VALUE(section))
111724 + return true;
111725 +
111726 + section = TREE_VALUE(TREE_VALUE(section));
111727 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
111728 + return true;
111729 +
111730 + return false;
111731 +}
111732 +
111733 +#if BUILDING_GCC_VERSION >= 4009
111734 +static const struct pass_data kernexec_reload_pass_data = {
111735 +#else
111736 +static struct gimple_opt_pass kernexec_reload_pass = {
111737 + .pass = {
111738 +#endif
111739 + .type = GIMPLE_PASS,
111740 + .name = "kernexec_reload",
111741 +#if BUILDING_GCC_VERSION >= 4008
111742 + .optinfo_flags = OPTGROUP_NONE,
111743 +#endif
111744 +#if BUILDING_GCC_VERSION >= 4009
111745 + .has_gate = true,
111746 + .has_execute = true,
111747 +#else
111748 + .gate = kernexec_cmodel_check,
111749 + .execute = execute_kernexec_reload,
111750 + .sub = NULL,
111751 + .next = NULL,
111752 + .static_pass_number = 0,
111753 +#endif
111754 + .tv_id = TV_NONE,
111755 + .properties_required = 0,
111756 + .properties_provided = 0,
111757 + .properties_destroyed = 0,
111758 + .todo_flags_start = 0,
111759 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
111760 +#if BUILDING_GCC_VERSION < 4009
111761 + }
111762 +#endif
111763 +};
111764 +
111765 +#if BUILDING_GCC_VERSION >= 4009
111766 +static const struct pass_data kernexec_fptr_pass_data = {
111767 +#else
111768 +static struct gimple_opt_pass kernexec_fptr_pass = {
111769 + .pass = {
111770 +#endif
111771 + .type = GIMPLE_PASS,
111772 + .name = "kernexec_fptr",
111773 +#if BUILDING_GCC_VERSION >= 4008
111774 + .optinfo_flags = OPTGROUP_NONE,
111775 +#endif
111776 +#if BUILDING_GCC_VERSION >= 4009
111777 + .has_gate = true,
111778 + .has_execute = true,
111779 +#else
111780 + .gate = kernexec_cmodel_check,
111781 + .execute = execute_kernexec_fptr,
111782 + .sub = NULL,
111783 + .next = NULL,
111784 + .static_pass_number = 0,
111785 +#endif
111786 + .tv_id = TV_NONE,
111787 + .properties_required = 0,
111788 + .properties_provided = 0,
111789 + .properties_destroyed = 0,
111790 + .todo_flags_start = 0,
111791 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
111792 +#if BUILDING_GCC_VERSION < 4009
111793 + }
111794 +#endif
111795 +};
111796 +
111797 +#if BUILDING_GCC_VERSION >= 4009
111798 +static const struct pass_data kernexec_retaddr_pass_data = {
111799 +#else
111800 +static struct rtl_opt_pass kernexec_retaddr_pass = {
111801 + .pass = {
111802 +#endif
111803 + .type = RTL_PASS,
111804 + .name = "kernexec_retaddr",
111805 +#if BUILDING_GCC_VERSION >= 4008
111806 + .optinfo_flags = OPTGROUP_NONE,
111807 +#endif
111808 +#if BUILDING_GCC_VERSION >= 4009
111809 + .has_gate = true,
111810 + .has_execute = true,
111811 +#else
111812 + .gate = kernexec_cmodel_check,
111813 + .execute = execute_kernexec_retaddr,
111814 + .sub = NULL,
111815 + .next = NULL,
111816 + .static_pass_number = 0,
111817 +#endif
111818 + .tv_id = TV_NONE,
111819 + .properties_required = 0,
111820 + .properties_provided = 0,
111821 + .properties_destroyed = 0,
111822 + .todo_flags_start = 0,
111823 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
111824 +#if BUILDING_GCC_VERSION < 4009
111825 + }
111826 +#endif
111827 +};
111828 +
111829 +#if BUILDING_GCC_VERSION >= 4009
111830 +namespace {
111831 +class kernexec_reload_pass : public gimple_opt_pass {
111832 +public:
111833 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
111834 + bool gate() { return kernexec_cmodel_check(); }
111835 + unsigned int execute() { return execute_kernexec_reload(); }
111836 +};
111837 +
111838 +class kernexec_fptr_pass : public gimple_opt_pass {
111839 +public:
111840 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
111841 + bool gate() { return kernexec_cmodel_check(); }
111842 + unsigned int execute() { return execute_kernexec_fptr(); }
111843 +};
111844 +
111845 +class kernexec_retaddr_pass : public rtl_opt_pass {
111846 +public:
111847 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
111848 + bool gate() { return kernexec_cmodel_check(); }
111849 + unsigned int execute() { return execute_kernexec_retaddr(); }
111850 +};
111851 +}
111852 +
111853 +static opt_pass *make_kernexec_reload_pass(void)
111854 +{
111855 + return new kernexec_reload_pass();
111856 +}
111857 +
111858 +static opt_pass *make_kernexec_fptr_pass(void)
111859 +{
111860 + return new kernexec_fptr_pass();
111861 +}
111862 +
111863 +static opt_pass *make_kernexec_retaddr_pass(void)
111864 +{
111865 + return new kernexec_retaddr_pass();
111866 +}
111867 +#else
111868 +static struct opt_pass *make_kernexec_reload_pass(void)
111869 +{
111870 + return &kernexec_reload_pass.pass;
111871 +}
111872 +
111873 +static struct opt_pass *make_kernexec_fptr_pass(void)
111874 +{
111875 + return &kernexec_fptr_pass.pass;
111876 +}
111877 +
111878 +static struct opt_pass *make_kernexec_retaddr_pass(void)
111879 +{
111880 + return &kernexec_retaddr_pass.pass;
111881 +}
111882 +#endif
111883 +
111884 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111885 +{
111886 + const char * const plugin_name = plugin_info->base_name;
111887 + const int argc = plugin_info->argc;
111888 + const struct plugin_argument * const argv = plugin_info->argv;
111889 + int i;
111890 + struct register_pass_info kernexec_reload_pass_info;
111891 + struct register_pass_info kernexec_fptr_pass_info;
111892 + struct register_pass_info kernexec_retaddr_pass_info;
111893 +
111894 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
111895 + kernexec_reload_pass_info.reference_pass_name = "ssa";
111896 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
111897 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111898 +
111899 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
111900 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
111901 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
111902 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111903 +
111904 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
111905 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
111906 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
111907 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111908 +
111909 + if (!plugin_default_version_check(version, &gcc_version)) {
111910 + error(G_("incompatible gcc/plugin versions"));
111911 + return 1;
111912 + }
111913 +
111914 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
111915 +
111916 + if (TARGET_64BIT == 0)
111917 + return 0;
111918 +
111919 + for (i = 0; i < argc; ++i) {
111920 + if (!strcmp(argv[i].key, "method")) {
111921 + if (!argv[i].value) {
111922 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111923 + continue;
111924 + }
111925 + if (!strcmp(argv[i].value, "bts")) {
111926 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
111927 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
111928 + } else if (!strcmp(argv[i].value, "or")) {
111929 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
111930 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
111931 + fix_register("r12", 1, 1);
111932 + } else
111933 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111934 + continue;
111935 + }
111936 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111937 + }
111938 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
111939 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
111940 +
111941 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
111942 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
111943 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
111944 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
111945 +
111946 + return 0;
111947 +}
111948 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
111949 new file mode 100644
111950 index 0000000..e48b323
111951 --- /dev/null
111952 +++ b/tools/gcc/latent_entropy_plugin.c
111953 @@ -0,0 +1,466 @@
111954 +/*
111955 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
111956 + * Licensed under the GPL v2
111957 + *
111958 + * Note: the choice of the license means that the compilation process is
111959 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111960 + * but for the kernel it doesn't matter since it doesn't link against
111961 + * any of the gcc libraries
111962 + *
111963 + * gcc plugin to help generate a little bit of entropy from program state,
111964 + * used throughout the uptime of the kernel
111965 + *
111966 + * TODO:
111967 + * - add ipa pass to identify not explicitly marked candidate functions
111968 + * - mix in more program state (function arguments/return values, loop variables, etc)
111969 + * - more instrumentation control via attribute parameters
111970 + *
111971 + * BUGS:
111972 + * - LTO needs -flto-partition=none for now
111973 + */
111974 +
111975 +#include "gcc-common.h"
111976 +
111977 +int plugin_is_GPL_compatible;
111978 +
111979 +static tree latent_entropy_decl;
111980 +
111981 +static struct plugin_info latent_entropy_plugin_info = {
111982 + .version = "201409101820",
111983 + .help = NULL
111984 +};
111985 +
111986 +static unsigned HOST_WIDE_INT seed;
111987 +static unsigned HOST_WIDE_INT get_random_const(void)
111988 +{
111989 + unsigned int i;
111990 + unsigned HOST_WIDE_INT ret = 0;
111991 +
111992 + for (i = 0; i < 8 * sizeof ret; i++) {
111993 + ret = (ret << 1) | (seed & 1);
111994 + seed >>= 1;
111995 + if (ret & 1)
111996 + seed ^= 0xD800000000000000ULL;
111997 + }
111998 +
111999 + return ret;
112000 +}
112001 +
112002 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112003 +{
112004 + tree type;
112005 + unsigned long long mask;
112006 +#if BUILDING_GCC_VERSION <= 4007
112007 + VEC(constructor_elt, gc) *vals;
112008 +#else
112009 + vec<constructor_elt, va_gc> *vals;
112010 +#endif
112011 +
112012 + switch (TREE_CODE(*node)) {
112013 + default:
112014 + *no_add_attrs = true;
112015 + error("%qE attribute only applies to functions and variables", name);
112016 + break;
112017 +
112018 + case VAR_DECL:
112019 + if (DECL_INITIAL(*node)) {
112020 + *no_add_attrs = true;
112021 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112022 + break;
112023 + }
112024 +
112025 + if (!TREE_STATIC(*node)) {
112026 + *no_add_attrs = true;
112027 + error("variable %qD with %qE attribute must not be local", *node, name);
112028 + break;
112029 + }
112030 +
112031 + type = TREE_TYPE(*node);
112032 + switch (TREE_CODE(type)) {
112033 + default:
112034 + *no_add_attrs = true;
112035 + 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);
112036 + break;
112037 +
112038 + case RECORD_TYPE: {
112039 + tree field;
112040 + unsigned int nelt = 0;
112041 +
112042 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112043 + tree fieldtype;
112044 +
112045 + fieldtype = TREE_TYPE(field);
112046 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112047 + *no_add_attrs = true;
112048 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112049 + break;
112050 + }
112051 + }
112052 +
112053 + if (field)
112054 + break;
112055 +
112056 +#if BUILDING_GCC_VERSION <= 4007
112057 + vals = VEC_alloc(constructor_elt, gc, nelt);
112058 +#else
112059 + vec_alloc(vals, nelt);
112060 +#endif
112061 +
112062 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112063 + tree fieldtype;
112064 +
112065 + fieldtype = TREE_TYPE(field);
112066 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112067 + mask = 2 * (mask - 1) + 1;
112068 +
112069 + if (TYPE_UNSIGNED(fieldtype))
112070 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112071 + else
112072 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112073 + }
112074 +
112075 + DECL_INITIAL(*node) = build_constructor(type, vals);
112076 +//debug_tree(DECL_INITIAL(*node));
112077 + break;
112078 + }
112079 +
112080 + case INTEGER_TYPE:
112081 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112082 + mask = 2 * (mask - 1) + 1;
112083 +
112084 + if (TYPE_UNSIGNED(type))
112085 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112086 + else
112087 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112088 + break;
112089 +
112090 + case ARRAY_TYPE: {
112091 + tree elt_type, array_size, elt_size;
112092 + unsigned int i, nelt;
112093 +
112094 + elt_type = TREE_TYPE(type);
112095 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112096 + array_size = TYPE_SIZE_UNIT(type);
112097 +
112098 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112099 + *no_add_attrs = true;
112100 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112101 + break;
112102 + }
112103 +
112104 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112105 +#if BUILDING_GCC_VERSION <= 4007
112106 + vals = VEC_alloc(constructor_elt, gc, nelt);
112107 +#else
112108 + vec_alloc(vals, nelt);
112109 +#endif
112110 +
112111 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112112 + mask = 2 * (mask - 1) + 1;
112113 +
112114 + for (i = 0; i < nelt; i++)
112115 + if (TYPE_UNSIGNED(elt_type))
112116 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112117 + else
112118 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112119 +
112120 + DECL_INITIAL(*node) = build_constructor(type, vals);
112121 +//debug_tree(DECL_INITIAL(*node));
112122 + break;
112123 + }
112124 + }
112125 + break;
112126 +
112127 + case FUNCTION_DECL:
112128 + break;
112129 + }
112130 +
112131 + return NULL_TREE;
112132 +}
112133 +
112134 +static struct attribute_spec latent_entropy_attr = {
112135 + .name = "latent_entropy",
112136 + .min_length = 0,
112137 + .max_length = 0,
112138 + .decl_required = true,
112139 + .type_required = false,
112140 + .function_type_required = false,
112141 + .handler = handle_latent_entropy_attribute,
112142 +#if BUILDING_GCC_VERSION >= 4007
112143 + .affects_type_identity = false
112144 +#endif
112145 +};
112146 +
112147 +static void register_attributes(void *event_data, void *data)
112148 +{
112149 + register_attribute(&latent_entropy_attr);
112150 +}
112151 +
112152 +static bool gate_latent_entropy(void)
112153 +{
112154 + // don't bother with noreturn functions for now
112155 + if (TREE_THIS_VOLATILE(current_function_decl))
112156 + return false;
112157 +
112158 + // gcc-4.5 doesn't discover some trivial noreturn functions
112159 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112160 + return false;
112161 +
112162 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112163 +}
112164 +
112165 +static enum tree_code get_op(tree *rhs)
112166 +{
112167 + static enum tree_code op;
112168 + unsigned HOST_WIDE_INT random_const;
112169 +
112170 + random_const = get_random_const();
112171 +
112172 + switch (op) {
112173 + case BIT_XOR_EXPR:
112174 + op = PLUS_EXPR;
112175 + break;
112176 +
112177 + case PLUS_EXPR:
112178 + if (rhs) {
112179 + op = LROTATE_EXPR;
112180 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112181 + break;
112182 + }
112183 +
112184 + case LROTATE_EXPR:
112185 + default:
112186 + op = BIT_XOR_EXPR;
112187 + break;
112188 + }
112189 + if (rhs)
112190 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112191 + return op;
112192 +}
112193 +
112194 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112195 +{
112196 + gimple_stmt_iterator gsi;
112197 + gimple assign;
112198 + tree addxorrol, rhs;
112199 + enum tree_code op;
112200 +
112201 + op = get_op(&rhs);
112202 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112203 + assign = gimple_build_assign(local_entropy, addxorrol);
112204 + gsi = gsi_after_labels(bb);
112205 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112206 + update_stmt(assign);
112207 +//debug_bb(bb);
112208 +}
112209 +
112210 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112211 +{
112212 + gimple_stmt_iterator gsi;
112213 + gimple assign;
112214 + tree addxorrol, temp;
112215 +
112216 + // 1. create temporary copy of latent_entropy
112217 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112218 + add_referenced_var(temp);
112219 +
112220 + // 2. read...
112221 + temp = make_ssa_name(temp, NULL);
112222 + assign = gimple_build_assign(temp, latent_entropy_decl);
112223 + SSA_NAME_DEF_STMT(temp) = assign;
112224 + add_referenced_var(latent_entropy_decl);
112225 + gsi = gsi_after_labels(bb);
112226 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112227 + update_stmt(assign);
112228 +
112229 + // 3. ...modify...
112230 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112231 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112232 + assign = gimple_build_assign(temp, addxorrol);
112233 + SSA_NAME_DEF_STMT(temp) = assign;
112234 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112235 + update_stmt(assign);
112236 +
112237 + // 4. ...write latent_entropy
112238 + assign = gimple_build_assign(latent_entropy_decl, temp);
112239 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112240 + update_stmt(assign);
112241 +}
112242 +
112243 +static unsigned int execute_latent_entropy(void)
112244 +{
112245 + basic_block bb;
112246 + gimple assign;
112247 + gimple_stmt_iterator gsi;
112248 + tree local_entropy;
112249 +
112250 + if (!latent_entropy_decl) {
112251 +#if BUILDING_GCC_VERSION >= 4009
112252 + varpool_node *node;
112253 +#else
112254 + struct varpool_node *node;
112255 +#endif
112256 +
112257 + FOR_EACH_VARIABLE(node) {
112258 + tree var = NODE_DECL(node);
112259 +
112260 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112261 + continue;
112262 + latent_entropy_decl = var;
112263 +// debug_tree(var);
112264 + break;
112265 + }
112266 + if (!latent_entropy_decl) {
112267 +// debug_tree(current_function_decl);
112268 + return 0;
112269 + }
112270 + }
112271 +
112272 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112273 +
112274 + // 1. create local entropy variable
112275 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112276 + add_referenced_var(local_entropy);
112277 + mark_sym_for_renaming(local_entropy);
112278 +
112279 + // 2. initialize local entropy variable
112280 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112281 + if (dom_info_available_p(CDI_DOMINATORS))
112282 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112283 + gsi = gsi_start_bb(bb);
112284 +
112285 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112286 +// gimple_set_location(assign, loc);
112287 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112288 + update_stmt(assign);
112289 +//debug_bb(bb);
112290 + gcc_assert(single_succ_p(bb));
112291 + bb = single_succ(bb);
112292 +
112293 + // 3. instrument each BB with an operation on the local entropy variable
112294 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112295 + perturb_local_entropy(bb, local_entropy);
112296 +//debug_bb(bb);
112297 + bb = bb->next_bb;
112298 + };
112299 +
112300 + // 4. mix local entropy into the global entropy variable
112301 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112302 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
112303 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112304 + return 0;
112305 +}
112306 +
112307 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
112308 +{
112309 + tree latent_entropy_type;
112310 +
112311 + seed = get_random_seed(false);
112312 +
112313 + if (in_lto_p)
112314 + return;
112315 +
112316 + // extern volatile u64 latent_entropy
112317 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
112318 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
112319 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
112320 +
112321 + TREE_STATIC(latent_entropy_decl) = 1;
112322 + TREE_PUBLIC(latent_entropy_decl) = 1;
112323 + TREE_USED(latent_entropy_decl) = 1;
112324 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
112325 + DECL_EXTERNAL(latent_entropy_decl) = 1;
112326 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
112327 + lang_hooks.decls.pushdecl(latent_entropy_decl);
112328 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
112329 +// varpool_finalize_decl(latent_entropy_decl);
112330 +// varpool_mark_needed_node(latent_entropy_decl);
112331 +}
112332 +
112333 +#if BUILDING_GCC_VERSION >= 4009
112334 +static const struct pass_data latent_entropy_pass_data = {
112335 +#else
112336 +static struct gimple_opt_pass latent_entropy_pass = {
112337 + .pass = {
112338 +#endif
112339 + .type = GIMPLE_PASS,
112340 + .name = "latent_entropy",
112341 +#if BUILDING_GCC_VERSION >= 4008
112342 + .optinfo_flags = OPTGROUP_NONE,
112343 +#endif
112344 +#if BUILDING_GCC_VERSION >= 4009
112345 + .has_gate = true,
112346 + .has_execute = true,
112347 +#else
112348 + .gate = gate_latent_entropy,
112349 + .execute = execute_latent_entropy,
112350 + .sub = NULL,
112351 + .next = NULL,
112352 + .static_pass_number = 0,
112353 +#endif
112354 + .tv_id = TV_NONE,
112355 + .properties_required = PROP_gimple_leh | PROP_cfg,
112356 + .properties_provided = 0,
112357 + .properties_destroyed = 0,
112358 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
112359 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
112360 +#if BUILDING_GCC_VERSION < 4009
112361 + }
112362 +#endif
112363 +};
112364 +
112365 +#if BUILDING_GCC_VERSION >= 4009
112366 +namespace {
112367 +class latent_entropy_pass : public gimple_opt_pass {
112368 +public:
112369 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
112370 + bool gate() { return gate_latent_entropy(); }
112371 + unsigned int execute() { return execute_latent_entropy(); }
112372 +};
112373 +}
112374 +
112375 +static opt_pass *make_latent_entropy_pass(void)
112376 +{
112377 + return new latent_entropy_pass();
112378 +}
112379 +#else
112380 +static struct opt_pass *make_latent_entropy_pass(void)
112381 +{
112382 + return &latent_entropy_pass.pass;
112383 +}
112384 +#endif
112385 +
112386 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112387 +{
112388 + const char * const plugin_name = plugin_info->base_name;
112389 + struct register_pass_info latent_entropy_pass_info;
112390 +
112391 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
112392 + latent_entropy_pass_info.reference_pass_name = "optimized";
112393 + latent_entropy_pass_info.ref_pass_instance_number = 1;
112394 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
112395 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
112396 + {
112397 + .base = &latent_entropy_decl,
112398 + .nelt = 1,
112399 + .stride = sizeof(latent_entropy_decl),
112400 + .cb = &gt_ggc_mx_tree_node,
112401 + .pchw = &gt_pch_nx_tree_node
112402 + },
112403 + LAST_GGC_ROOT_TAB
112404 + };
112405 +
112406 + if (!plugin_default_version_check(version, &gcc_version)) {
112407 + error(G_("incompatible gcc/plugin versions"));
112408 + return 1;
112409 + }
112410 +
112411 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
112412 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
112413 + if (!in_lto_p)
112414 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
112415 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
112416 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
112417 +
112418 + return 0;
112419 +}
112420 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
112421 new file mode 100644
112422 index 0000000..a5cb46b
112423 --- /dev/null
112424 +++ b/tools/gcc/randomize_layout_plugin.c
112425 @@ -0,0 +1,915 @@
112426 +/*
112427 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
112428 + * and PaX Team <pageexec@freemail.hu>
112429 + * Licensed under the GPL v2
112430 + *
112431 + * Usage:
112432 + * $ # for 4.5/4.6/C based 4.7
112433 + * $ 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
112434 + * $ # for C++ based 4.7/4.8+
112435 + * $ 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
112436 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
112437 + */
112438 +
112439 +#include "gcc-common.h"
112440 +#include "randomize_layout_seed.h"
112441 +
112442 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
112443 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
112444 +#endif
112445 +
112446 +#define ORIG_TYPE_NAME(node) \
112447 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
112448 +
112449 +int plugin_is_GPL_compatible;
112450 +
112451 +static int performance_mode;
112452 +
112453 +static struct plugin_info randomize_layout_plugin_info = {
112454 + .version = "201402201816",
112455 + .help = "disable\t\t\tdo not activate plugin\n"
112456 + "performance-mode\tenable cacheline-aware layout randomization\n"
112457 +};
112458 +
112459 +/* from old Linux dcache.h */
112460 +static inline unsigned long
112461 +partial_name_hash(unsigned long c, unsigned long prevhash)
112462 +{
112463 + return (prevhash + (c << 4) + (c >> 4)) * 11;
112464 +}
112465 +static inline unsigned int
112466 +name_hash(const unsigned char *name)
112467 +{
112468 + unsigned long hash = 0;
112469 + unsigned int len = strlen((const char *)name);
112470 + while (len--)
112471 + hash = partial_name_hash(*name++, hash);
112472 + return (unsigned int)hash;
112473 +}
112474 +
112475 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112476 +{
112477 + tree type;
112478 +
112479 + *no_add_attrs = true;
112480 + if (TREE_CODE(*node) == FUNCTION_DECL) {
112481 + error("%qE attribute does not apply to functions (%qF)", name, *node);
112482 + return NULL_TREE;
112483 + }
112484 +
112485 + if (TREE_CODE(*node) == PARM_DECL) {
112486 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
112487 + return NULL_TREE;
112488 + }
112489 +
112490 + if (TREE_CODE(*node) == VAR_DECL) {
112491 + error("%qE attribute does not apply to variables (%qD)", name, *node);
112492 + return NULL_TREE;
112493 + }
112494 +
112495 + if (TYPE_P(*node)) {
112496 + type = *node;
112497 + } else {
112498 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
112499 + type = TREE_TYPE(*node);
112500 + }
112501 +
112502 + if (TREE_CODE(type) != RECORD_TYPE) {
112503 + error("%qE attribute used on %qT applies to struct types only", name, type);
112504 + return NULL_TREE;
112505 + }
112506 +
112507 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
112508 + error("%qE attribute is already applied to the type %qT", name, type);
112509 + return NULL_TREE;
112510 + }
112511 +
112512 + *no_add_attrs = false;
112513 +
112514 + return NULL_TREE;
112515 +}
112516 +
112517 +/* set on complete types that we don't need to inspect further at all */
112518 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112519 +{
112520 + *no_add_attrs = false;
112521 + return NULL_TREE;
112522 +}
112523 +
112524 +/*
112525 + * set on types that we've performed a shuffle on, to prevent re-shuffling
112526 + * this does not preclude us from inspecting its fields for potential shuffles
112527 + */
112528 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112529 +{
112530 + *no_add_attrs = false;
112531 + return NULL_TREE;
112532 +}
112533 +
112534 +/*
112535 + * 64bit variant of Bob Jenkins' public domain PRNG
112536 + * 256 bits of internal state
112537 + */
112538 +
112539 +typedef unsigned long long u64;
112540 +
112541 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
112542 +
112543 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
112544 +static u64 ranval(ranctx *x) {
112545 + u64 e = x->a - rot(x->b, 7);
112546 + x->a = x->b ^ rot(x->c, 13);
112547 + x->b = x->c + rot(x->d, 37);
112548 + x->c = x->d + e;
112549 + x->d = e + x->a;
112550 + return x->d;
112551 +}
112552 +
112553 +static void raninit(ranctx *x, u64 *seed) {
112554 + int i;
112555 +
112556 + x->a = seed[0];
112557 + x->b = seed[1];
112558 + x->c = seed[2];
112559 + x->d = seed[3];
112560 +
112561 + for (i=0; i < 30; ++i)
112562 + (void)ranval(x);
112563 +}
112564 +
112565 +static u64 shuffle_seed[4];
112566 +
112567 +struct partition_group {
112568 + tree tree_start;
112569 + unsigned long start;
112570 + unsigned long length;
112571 +};
112572 +
112573 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
112574 +{
112575 + unsigned long i;
112576 + unsigned long accum_size = 0;
112577 + unsigned long accum_length = 0;
112578 + unsigned long group_idx = 0;
112579 +
112580 + gcc_assert(length < INT_MAX);
112581 +
112582 + memset(size_groups, 0, sizeof(struct partition_group) * length);
112583 +
112584 + for (i = 0; i < length; i++) {
112585 + if (size_groups[group_idx].tree_start == NULL_TREE) {
112586 + size_groups[group_idx].tree_start = fields[i];
112587 + size_groups[group_idx].start = i;
112588 + accum_length = 0;
112589 + accum_size = 0;
112590 + }
112591 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
112592 + accum_length++;
112593 + if (accum_size >= 64) {
112594 + size_groups[group_idx].length = accum_length;
112595 + accum_length = 0;
112596 + group_idx++;
112597 + }
112598 + }
112599 +
112600 + if (size_groups[group_idx].tree_start != NULL_TREE &&
112601 + !size_groups[group_idx].length) {
112602 + size_groups[group_idx].length = accum_length;
112603 + group_idx++;
112604 + }
112605 +
112606 + *num_groups = group_idx;
112607 +}
112608 +
112609 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112610 +{
112611 + unsigned long i, x;
112612 + struct partition_group size_group[length];
112613 + unsigned long num_groups = 0;
112614 + unsigned long randnum;
112615 +
112616 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
112617 + for (i = num_groups - 1; i > 0; i--) {
112618 + struct partition_group tmp;
112619 + randnum = ranval(prng_state) % (i + 1);
112620 + tmp = size_group[i];
112621 + size_group[i] = size_group[randnum];
112622 + size_group[randnum] = tmp;
112623 + }
112624 +
112625 + for (x = 0; x < num_groups; x++) {
112626 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
112627 + tree tmp;
112628 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
112629 + continue;
112630 + randnum = ranval(prng_state) % (i + 1);
112631 + // we could handle this case differently if desired
112632 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
112633 + continue;
112634 + tmp = newtree[i];
112635 + newtree[i] = newtree[randnum];
112636 + newtree[randnum] = tmp;
112637 + }
112638 + }
112639 +}
112640 +
112641 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112642 +{
112643 + unsigned long i, randnum;
112644 +
112645 + for (i = length - 1; i > 0; i--) {
112646 + tree tmp;
112647 + randnum = ranval(prng_state) % (i + 1);
112648 + tmp = newtree[i];
112649 + newtree[i] = newtree[randnum];
112650 + newtree[randnum] = tmp;
112651 + }
112652 +}
112653 +
112654 +/* modern in-place Fisher-Yates shuffle */
112655 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
112656 +{
112657 + unsigned long i;
112658 + u64 seed[4];
112659 + ranctx prng_state;
112660 + const unsigned char *structname;
112661 +
112662 + if (length == 0)
112663 + return;
112664 +
112665 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112666 +
112667 + structname = ORIG_TYPE_NAME(type);
112668 +
112669 +#ifdef __DEBUG_PLUGIN
112670 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
112671 +#ifdef __DEBUG_VERBOSE
112672 + debug_tree((tree)type);
112673 +#endif
112674 +#endif
112675 +
112676 + for (i = 0; i < 4; i++) {
112677 + seed[i] = shuffle_seed[i];
112678 + seed[i] ^= name_hash(structname);
112679 + }
112680 +
112681 + raninit(&prng_state, (u64 *)&seed);
112682 +
112683 + if (performance_mode)
112684 + performance_shuffle(newtree, length, &prng_state);
112685 + else
112686 + full_shuffle(newtree, length, &prng_state);
112687 +}
112688 +
112689 +static bool is_flexible_array(const_tree field)
112690 +{
112691 + const_tree fieldtype;
112692 + const_tree typesize;
112693 + const_tree elemtype;
112694 + const_tree elemsize;
112695 +
112696 + fieldtype = TREE_TYPE(field);
112697 + typesize = TYPE_SIZE(fieldtype);
112698 +
112699 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
112700 + return false;
112701 +
112702 + elemtype = TREE_TYPE(fieldtype);
112703 + elemsize = TYPE_SIZE(elemtype);
112704 +
112705 + /* size of type is represented in bits */
112706 +
112707 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
112708 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
112709 + return true;
112710 +
112711 + if (typesize != NULL_TREE &&
112712 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
112713 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
112714 + return true;
112715 +
112716 + return false;
112717 +}
112718 +
112719 +static int relayout_struct(tree type)
112720 +{
112721 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
112722 + unsigned long shuffle_length = num_fields;
112723 + tree field;
112724 + tree newtree[num_fields];
112725 + unsigned long i;
112726 + tree list;
112727 + tree variant;
112728 + expanded_location xloc;
112729 +
112730 + if (TYPE_FIELDS(type) == NULL_TREE)
112731 + return 0;
112732 +
112733 + if (num_fields < 2)
112734 + return 0;
112735 +
112736 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112737 +
112738 + gcc_assert(num_fields < INT_MAX);
112739 +
112740 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
112741 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
112742 + return 0;
112743 +
112744 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
112745 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
112746 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
112747 + return 0;
112748 +
112749 + /* throw out any structs in uapi */
112750 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
112751 +
112752 + if (strstr(xloc.file, "/uapi/"))
112753 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
112754 +
112755 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
112756 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
112757 + newtree[i] = field;
112758 + }
112759 +
112760 + /*
112761 + * enforce that we don't randomize the layout of the last
112762 + * element of a struct if it's a 0 or 1-length array
112763 + * or a proper flexible array
112764 + */
112765 + if (is_flexible_array(newtree[num_fields - 1]))
112766 + shuffle_length--;
112767 +
112768 + shuffle(type, (tree *)newtree, shuffle_length);
112769 +
112770 + /*
112771 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
112772 + * as gcc provides no other way to detect such code
112773 + */
112774 + list = make_node(FIELD_DECL);
112775 + TREE_CHAIN(list) = newtree[0];
112776 + TREE_TYPE(list) = void_type_node;
112777 + DECL_SIZE(list) = bitsize_zero_node;
112778 + DECL_NONADDRESSABLE_P(list) = 1;
112779 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
112780 + DECL_SIZE_UNIT(list) = size_zero_node;
112781 + DECL_FIELD_OFFSET(list) = size_zero_node;
112782 + // to satisfy the constify plugin
112783 + TREE_READONLY(list) = 1;
112784 +
112785 + for (i = 0; i < num_fields - 1; i++)
112786 + TREE_CHAIN(newtree[i]) = newtree[i+1];
112787 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
112788 +
112789 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
112790 + TYPE_FIELDS(variant) = list;
112791 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
112792 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
112793 + // force a re-layout
112794 + TYPE_SIZE(variant) = NULL_TREE;
112795 + layout_type(variant);
112796 + }
112797 +
112798 + return 1;
112799 +}
112800 +
112801 +/* from constify plugin */
112802 +static const_tree get_field_type(const_tree field)
112803 +{
112804 + return strip_array_types(TREE_TYPE(field));
112805 +}
112806 +
112807 +/* from constify plugin */
112808 +static bool is_fptr(const_tree fieldtype)
112809 +{
112810 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
112811 + return false;
112812 +
112813 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
112814 +}
112815 +
112816 +/* derived from constify plugin */
112817 +static int is_pure_ops_struct(const_tree node)
112818 +{
112819 + const_tree field;
112820 +
112821 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
112822 +
112823 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
112824 + const_tree fieldtype = get_field_type(field);
112825 + enum tree_code code = TREE_CODE(fieldtype);
112826 +
112827 + if (node == fieldtype)
112828 + continue;
112829 +
112830 + if (!is_fptr(fieldtype))
112831 + return 0;
112832 +
112833 + if (code != RECORD_TYPE && code != UNION_TYPE)
112834 + continue;
112835 +
112836 + if (!is_pure_ops_struct(fieldtype))
112837 + return 0;
112838 + }
112839 +
112840 + return 1;
112841 +}
112842 +
112843 +static void randomize_type(tree type)
112844 +{
112845 + tree variant;
112846 +
112847 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112848 +
112849 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
112850 + return;
112851 +
112852 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
112853 + relayout_struct(type);
112854 +
112855 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
112856 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
112857 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
112858 + }
112859 +#ifdef __DEBUG_PLUGIN
112860 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
112861 +#ifdef __DEBUG_VERBOSE
112862 + debug_tree(type);
112863 +#endif
112864 +#endif
112865 +}
112866 +
112867 +static void randomize_layout_finish_decl(void *event_data, void *data)
112868 +{
112869 + tree decl = (tree)event_data;
112870 + tree type;
112871 +
112872 + if (decl == NULL_TREE || decl == error_mark_node)
112873 + return;
112874 +
112875 + type = TREE_TYPE(decl);
112876 +
112877 + if (TREE_CODE(decl) != VAR_DECL)
112878 + return;
112879 +
112880 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
112881 + return;
112882 +
112883 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
112884 + return;
112885 +
112886 + relayout_decl(decl);
112887 +}
112888 +
112889 +static void finish_type(void *event_data, void *data)
112890 +{
112891 + tree type = (tree)event_data;
112892 +
112893 + if (type == NULL_TREE || type == error_mark_node)
112894 + return;
112895 +
112896 + if (TREE_CODE(type) != RECORD_TYPE)
112897 + return;
112898 +
112899 + if (TYPE_FIELDS(type) == NULL_TREE)
112900 + return;
112901 +
112902 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
112903 + return;
112904 +
112905 +#ifdef __DEBUG_PLUGIN
112906 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
112907 +#endif
112908 +#ifdef __DEBUG_VERBOSE
112909 + debug_tree(type);
112910 +#endif
112911 + randomize_type(type);
112912 +
112913 + return;
112914 +}
112915 +
112916 +static struct attribute_spec randomize_layout_attr = {
112917 + .name = "randomize_layout",
112918 + // related to args
112919 + .min_length = 0,
112920 + .max_length = 0,
112921 + .decl_required = false,
112922 + // need type declaration
112923 + .type_required = true,
112924 + .function_type_required = false,
112925 + .handler = handle_randomize_layout_attr,
112926 +#if BUILDING_GCC_VERSION >= 4007
112927 + .affects_type_identity = true
112928 +#endif
112929 +};
112930 +
112931 +static struct attribute_spec no_randomize_layout_attr = {
112932 + .name = "no_randomize_layout",
112933 + // related to args
112934 + .min_length = 0,
112935 + .max_length = 0,
112936 + .decl_required = false,
112937 + // need type declaration
112938 + .type_required = true,
112939 + .function_type_required = false,
112940 + .handler = handle_randomize_layout_attr,
112941 +#if BUILDING_GCC_VERSION >= 4007
112942 + .affects_type_identity = true
112943 +#endif
112944 +};
112945 +
112946 +static struct attribute_spec randomize_considered_attr = {
112947 + .name = "randomize_considered",
112948 + // related to args
112949 + .min_length = 0,
112950 + .max_length = 0,
112951 + .decl_required = false,
112952 + // need type declaration
112953 + .type_required = true,
112954 + .function_type_required = false,
112955 + .handler = handle_randomize_considered_attr,
112956 +#if BUILDING_GCC_VERSION >= 4007
112957 + .affects_type_identity = false
112958 +#endif
112959 +};
112960 +
112961 +static struct attribute_spec randomize_performed_attr = {
112962 + .name = "randomize_performed",
112963 + // related to args
112964 + .min_length = 0,
112965 + .max_length = 0,
112966 + .decl_required = false,
112967 + // need type declaration
112968 + .type_required = true,
112969 + .function_type_required = false,
112970 + .handler = handle_randomize_performed_attr,
112971 +#if BUILDING_GCC_VERSION >= 4007
112972 + .affects_type_identity = false
112973 +#endif
112974 +};
112975 +
112976 +static void register_attributes(void *event_data, void *data)
112977 +{
112978 + register_attribute(&randomize_layout_attr);
112979 + register_attribute(&no_randomize_layout_attr);
112980 + register_attribute(&randomize_considered_attr);
112981 + register_attribute(&randomize_performed_attr);
112982 +}
112983 +
112984 +static void check_bad_casts_in_constructor(tree var, tree init)
112985 +{
112986 + unsigned HOST_WIDE_INT idx;
112987 + tree field, val;
112988 + tree field_type, val_type;
112989 +
112990 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
112991 + if (TREE_CODE(val) == CONSTRUCTOR) {
112992 + check_bad_casts_in_constructor(var, val);
112993 + continue;
112994 + }
112995 +
112996 + /* pipacs' plugin creates franken-arrays that differ from those produced by
112997 + normal code which all have valid 'field' trees. work around this */
112998 + if (field == NULL_TREE)
112999 + continue;
113000 + field_type = TREE_TYPE(field);
113001 + val_type = TREE_TYPE(val);
113002 +
113003 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113004 + continue;
113005 +
113006 + if (field_type == val_type)
113007 + continue;
113008 +
113009 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113010 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113011 +
113012 + if (field_type == void_type_node)
113013 + continue;
113014 + if (field_type == val_type)
113015 + continue;
113016 + if (TREE_CODE(val_type) != RECORD_TYPE)
113017 + continue;
113018 +
113019 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113020 + continue;
113021 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113022 + }
113023 +}
113024 +
113025 +/* derived from the constify plugin */
113026 +static void check_global_variables(void *event_data, void *data)
113027 +{
113028 + struct varpool_node *node;
113029 + tree init;
113030 +
113031 + FOR_EACH_VARIABLE(node) {
113032 + tree var = NODE_DECL(node);
113033 + init = DECL_INITIAL(var);
113034 + if (init == NULL_TREE)
113035 + continue;
113036 +
113037 + if (TREE_CODE(init) != CONSTRUCTOR)
113038 + continue;
113039 +
113040 + check_bad_casts_in_constructor(var, init);
113041 + }
113042 +}
113043 +
113044 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113045 +{
113046 + basic_block dom;
113047 + gimple dom_stmt;
113048 + gimple call_stmt;
113049 + const_tree dom_lhs;
113050 + const_tree poss_is_err_cond;
113051 + const_tree poss_is_err_func;
113052 + const_tree is_err_arg;
113053 +
113054 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113055 + if (!dom)
113056 + return false;
113057 +
113058 + dom_stmt = last_stmt(dom);
113059 + if (!dom_stmt)
113060 + return false;
113061 +
113062 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113063 + return false;
113064 +
113065 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113066 + return false;
113067 +
113068 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113069 + return false;
113070 +
113071 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113072 +
113073 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113074 + return false;
113075 +
113076 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113077 +
113078 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113079 + return false;
113080 +
113081 + dom_lhs = gimple_get_lhs(call_stmt);
113082 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113083 + if (!poss_is_err_func)
113084 + return false;
113085 + if (dom_lhs != poss_is_err_cond)
113086 + return false;
113087 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113088 + return false;
113089 +
113090 + is_err_arg = gimple_call_arg(call_stmt, 0);
113091 + if (!is_err_arg)
113092 + return false;
113093 +
113094 + if (is_err_arg != rhs)
113095 + return false;
113096 +
113097 + return true;
113098 +}
113099 +
113100 +static void handle_local_var_initializers(void)
113101 +{
113102 + tree var;
113103 + unsigned int i;
113104 +
113105 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113106 + tree init = DECL_INITIAL(var);
113107 + if (!init)
113108 + continue;
113109 + if (TREE_CODE(init) != CONSTRUCTOR)
113110 + continue;
113111 + check_bad_casts_in_constructor(var, init);
113112 + }
113113 +}
113114 +
113115 +/*
113116 + * iterate over all statements to find "bad" casts:
113117 + * those where the address of the start of a structure is cast
113118 + * to a pointer of a structure of a different type, or a
113119 + * structure pointer type is cast to a different structure pointer type
113120 + */
113121 +static unsigned int find_bad_casts(void)
113122 +{
113123 + basic_block bb;
113124 +
113125 + handle_local_var_initializers();
113126 +
113127 + FOR_ALL_BB_FN(bb, cfun) {
113128 + gimple_stmt_iterator gsi;
113129 +
113130 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113131 + gimple stmt;
113132 + const_tree lhs;
113133 + const_tree lhs_type;
113134 + const_tree rhs1;
113135 + const_tree rhs_type;
113136 + const_tree ptr_lhs_type;
113137 + const_tree ptr_rhs_type;
113138 + const_tree op0;
113139 + const_tree op0_type;
113140 + enum tree_code rhs_code;
113141 +
113142 + stmt = gsi_stmt(gsi);
113143 +
113144 +#ifdef __DEBUG_PLUGIN
113145 +#ifdef __DEBUG_VERBOSE
113146 + debug_gimple_stmt(stmt);
113147 + debug_tree(gimple_get_lhs(stmt));
113148 +#endif
113149 +#endif
113150 +
113151 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113152 + continue;
113153 +
113154 +#ifdef __DEBUG_PLUGIN
113155 +#ifdef __DEBUG_VERBOSE
113156 + debug_tree(gimple_assign_rhs1(stmt));
113157 +#endif
113158 +#endif
113159 +
113160 + rhs_code = gimple_assign_rhs_code(stmt);
113161 +
113162 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113163 + continue;
113164 +
113165 + lhs = gimple_get_lhs(stmt);
113166 + lhs_type = TREE_TYPE(lhs);
113167 + rhs1 = gimple_assign_rhs1(stmt);
113168 + rhs_type = TREE_TYPE(rhs1);
113169 +
113170 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113171 + TREE_CODE(lhs_type) != POINTER_TYPE)
113172 + continue;
113173 +
113174 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113175 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113176 +
113177 + if (ptr_rhs_type == void_type_node)
113178 + continue;
113179 +
113180 + if (ptr_lhs_type == void_type_node)
113181 + continue;
113182 +
113183 + if (dominated_by_is_err(rhs1, bb))
113184 + continue;
113185 +
113186 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113187 +#ifndef __DEBUG_PLUGIN
113188 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113189 +#endif
113190 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113191 + continue;
113192 + }
113193 +
113194 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113195 + continue;
113196 +
113197 + if (rhs_code == ADDR_EXPR) {
113198 + op0 = TREE_OPERAND(rhs1, 0);
113199 +
113200 + if (op0 == NULL_TREE)
113201 + continue;
113202 +
113203 + if (TREE_CODE(op0) != VAR_DECL)
113204 + continue;
113205 +
113206 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113207 + if (op0_type == ptr_lhs_type)
113208 + continue;
113209 +
113210 +#ifndef __DEBUG_PLUGIN
113211 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113212 +#endif
113213 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113214 + } else {
113215 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113216 + /* skip bogus type casts introduced by container_of */
113217 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113218 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113219 + continue;
113220 +#ifndef __DEBUG_PLUGIN
113221 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113222 +#endif
113223 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113224 + }
113225 +
113226 + }
113227 + }
113228 + return 0;
113229 +}
113230 +
113231 +#if BUILDING_GCC_VERSION >= 4009
113232 +static const struct pass_data randomize_layout_bad_cast_data = {
113233 +#else
113234 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113235 + .pass = {
113236 +#endif
113237 + .type = GIMPLE_PASS,
113238 + .name = "randomize_layout_bad_cast",
113239 +#if BUILDING_GCC_VERSION >= 4008
113240 + .optinfo_flags = OPTGROUP_NONE,
113241 +#endif
113242 +#if BUILDING_GCC_VERSION >= 4009
113243 + .has_gate = false,
113244 + .has_execute = true,
113245 +#else
113246 + .gate = NULL,
113247 + .execute = find_bad_casts,
113248 + .sub = NULL,
113249 + .next = NULL,
113250 + .static_pass_number = 0,
113251 +#endif
113252 + .tv_id = TV_NONE,
113253 + .properties_required = PROP_cfg,
113254 + .properties_provided = 0,
113255 + .properties_destroyed = 0,
113256 + .todo_flags_start = 0,
113257 + .todo_flags_finish = TODO_dump_func
113258 +#if BUILDING_GCC_VERSION < 4009
113259 + }
113260 +#endif
113261 +};
113262 +
113263 +#if BUILDING_GCC_VERSION >= 4009
113264 +namespace {
113265 +class randomize_layout_bad_cast : public gimple_opt_pass {
113266 +public:
113267 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113268 + unsigned int execute() { return find_bad_casts(); }
113269 +};
113270 +}
113271 +#endif
113272 +
113273 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113274 +{
113275 +#if BUILDING_GCC_VERSION >= 4009
113276 + return new randomize_layout_bad_cast();
113277 +#else
113278 + return &randomize_layout_bad_cast.pass;
113279 +#endif
113280 +}
113281 +
113282 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113283 +{
113284 + int i;
113285 + const char * const plugin_name = plugin_info->base_name;
113286 + const int argc = plugin_info->argc;
113287 + const struct plugin_argument * const argv = plugin_info->argv;
113288 + bool enable = true;
113289 + int obtained_seed = 0;
113290 + struct register_pass_info randomize_layout_bad_cast_info;
113291 +
113292 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113293 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113294 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113295 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113296 +
113297 + if (!plugin_default_version_check(version, &gcc_version)) {
113298 + error(G_("incompatible gcc/plugin versions"));
113299 + return 1;
113300 + }
113301 +
113302 + if (strcmp(lang_hooks.name, "GNU C")) {
113303 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
113304 + enable = false;
113305 + }
113306 +
113307 + for (i = 0; i < argc; ++i) {
113308 + if (!strcmp(argv[i].key, "disable")) {
113309 + enable = false;
113310 + continue;
113311 + }
113312 + if (!strcmp(argv[i].key, "performance-mode")) {
113313 + performance_mode = 1;
113314 + continue;
113315 + }
113316 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113317 + }
113318 +
113319 + if (strlen(randstruct_seed) != 64) {
113320 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
113321 + return 1;
113322 + }
113323 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
113324 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
113325 + if (obtained_seed != 4) {
113326 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
113327 + return 1;
113328 + }
113329 +
113330 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
113331 + if (enable) {
113332 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
113333 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
113334 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
113335 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
113336 + }
113337 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113338 +
113339 + return 0;
113340 +}
113341 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
113342 new file mode 100644
113343 index 0000000..1f0214f
113344 --- /dev/null
113345 +++ b/tools/gcc/size_overflow_plugin/.gitignore
113346 @@ -0,0 +1,3 @@
113347 +randomize_layout_seed.h
113348 +size_overflow_hash.h
113349 +size_overflow_hash_aux.h
113350 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
113351 new file mode 100644
113352 index 0000000..1ae2ed5
113353 --- /dev/null
113354 +++ b/tools/gcc/size_overflow_plugin/Makefile
113355 @@ -0,0 +1,20 @@
113356 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
113357 +always := $($(HOSTLIBS)-y)
113358 +
113359 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
113360 +
113361 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
113362 +
113363 +quiet_cmd_build_size_overflow_hash = GENHASH $@
113364 + cmd_build_size_overflow_hash = \
113365 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
113366 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
113367 + $(call if_changed,build_size_overflow_hash)
113368 +
113369 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
113370 + cmd_build_size_overflow_hash_aux = \
113371 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
113372 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
113373 + $(call if_changed,build_size_overflow_hash_aux)
113374 +
113375 +targets += size_overflow_hash.h size_overflow_hash_aux.h
113376 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113377 new file mode 100644
113378 index 0000000..12b1e3b
113379 --- /dev/null
113380 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113381 @@ -0,0 +1,102 @@
113382 +#!/bin/bash
113383 +
113384 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
113385 +
113386 +header1="size_overflow_hash.h"
113387 +database="size_overflow_hash.data"
113388 +n=65536
113389 +hashtable_name="size_overflow_hash"
113390 +
113391 +usage() {
113392 +cat <<EOF
113393 +usage: $0 options
113394 +OPTIONS:
113395 + -h|--help help
113396 + -o header file
113397 + -d database file
113398 + -n hash array size
113399 + -s name of the hash table
113400 +EOF
113401 + return 0
113402 +}
113403 +
113404 +while true
113405 +do
113406 + case "$1" in
113407 + -h|--help) usage && exit 0;;
113408 + -n) n=$2; shift 2;;
113409 + -o) header1="$2"; shift 2;;
113410 + -d) database="$2"; shift 2;;
113411 + -s) hashtable_name="$2"; shift 2;;
113412 + --) shift 1; break ;;
113413 + *) break ;;
113414 + esac
113415 +done
113416 +
113417 +create_defines() {
113418 + for i in `seq 0 31`
113419 + do
113420 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
113421 + done
113422 + echo >> "$header1"
113423 +}
113424 +
113425 +create_structs() {
113426 + rm -f "$header1"
113427 +
113428 + create_defines
113429 +
113430 + cat "$database" | while read data
113431 + do
113432 + data_array=($data)
113433 + struct_hash_name="${data_array[0]}"
113434 + funcn="${data_array[1]}"
113435 + params="${data_array[2]}"
113436 + next="${data_array[4]}"
113437 +
113438 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
113439 +
113440 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
113441 + echo -en "\t.param\t= " >> "$header1"
113442 + line=
113443 + for param_num in ${params//-/ };
113444 + do
113445 + line="${line}PARAM"$param_num"|"
113446 + done
113447 +
113448 + echo -e "${line%?},\n};\n" >> "$header1"
113449 + done
113450 +}
113451 +
113452 +create_headers() {
113453 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
113454 +}
113455 +
113456 +create_array_elements() {
113457 + index=0
113458 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
113459 + do
113460 + data_array=($data)
113461 + i="${data_array[3]}"
113462 + hash="${data_array[0]}"
113463 + while [[ $index -lt $i ]]
113464 + do
113465 + echo -e "\t["$index"]\t= NULL," >> "$header1"
113466 + index=$(($index + 1))
113467 + done
113468 + index=$(($index + 1))
113469 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
113470 + done
113471 + echo '};' >> $header1
113472 +}
113473 +
113474 +size_overflow_plugin_dir=`dirname $header1`
113475 +if [ "$size_overflow_plugin_dir" != '.' ]; then
113476 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
113477 +fi
113478 +
113479 +create_structs
113480 +create_headers
113481 +create_array_elements
113482 +
113483 +exit 0
113484 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113485 new file mode 100644
113486 index 0000000..c43901f
113487 --- /dev/null
113488 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113489 @@ -0,0 +1,748 @@
113490 +/*
113491 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113492 + * Licensed under the GPL v2, or (at your option) v3
113493 + *
113494 + * Homepage:
113495 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113496 + *
113497 + * Documentation:
113498 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113499 + *
113500 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113501 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113502 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113503 + *
113504 + * Usage:
113505 + * $ make
113506 + * $ make run
113507 + */
113508 +
113509 +#include "gcc-common.h"
113510 +#include "size_overflow.h"
113511 +
113512 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
113513 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
113514 +
113515 +// data for the size_overflow asm stmt
113516 +struct asm_data {
113517 + gimple def_stmt;
113518 + tree input;
113519 + tree output;
113520 +};
113521 +
113522 +#if BUILDING_GCC_VERSION <= 4007
113523 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
113524 +#else
113525 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
113526 +#endif
113527 +{
113528 + tree list;
113529 +#if BUILDING_GCC_VERSION <= 4007
113530 + VEC(tree, gc) *vec_list = NULL;
113531 +#else
113532 + vec<tree, va_gc> *vec_list = NULL;
113533 +#endif
113534 +
113535 + list = build_tree_list(NULL_TREE, string);
113536 + list = chainon(NULL_TREE, build_tree_list(list, io));
113537 +#if BUILDING_GCC_VERSION <= 4007
113538 + VEC_safe_push(tree, gc, vec_list, list);
113539 +#else
113540 + vec_safe_push(vec_list, list);
113541 +#endif
113542 + return vec_list;
113543 +}
113544 +
113545 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
113546 +{
113547 + gimple asm_stmt;
113548 + gimple_stmt_iterator gsi;
113549 +#if BUILDING_GCC_VERSION <= 4007
113550 + VEC(tree, gc) *input, *output = NULL;
113551 +#else
113552 + vec<tree, va_gc> *input, *output = NULL;
113553 +#endif
113554 +
113555 + input = create_asm_io_list(str_input, asm_data->input);
113556 +
113557 + if (asm_data->output)
113558 + output = create_asm_io_list(str_output, asm_data->output);
113559 +
113560 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
113561 + gsi = gsi_for_stmt(asm_data->def_stmt);
113562 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
113563 +
113564 + if (asm_data->output)
113565 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
113566 +}
113567 +
113568 +static void replace_call_lhs(const struct asm_data *asm_data)
113569 +{
113570 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
113571 + update_stmt(asm_data->def_stmt);
113572 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
113573 +}
113574 +
113575 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
113576 +{
113577 + enum mark cur_fndecl_attr;
113578 + gimple phi = get_def_stmt(result);
113579 + unsigned int i, n = gimple_phi_num_args(phi);
113580 +
113581 + pointer_set_insert(visited, phi);
113582 + for (i = 0; i < n; i++) {
113583 + tree arg = gimple_phi_arg_def(phi, i);
113584 +
113585 + cur_fndecl_attr = search_intentional(visited, arg);
113586 + if (cur_fndecl_attr != MARK_NO)
113587 + return cur_fndecl_attr;
113588 + }
113589 + return MARK_NO;
113590 +}
113591 +
113592 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
113593 +{
113594 + enum mark cur_fndecl_attr;
113595 + const_tree rhs1, rhs2;
113596 + gimple def_stmt = get_def_stmt(lhs);
113597 +
113598 + rhs1 = gimple_assign_rhs1(def_stmt);
113599 + rhs2 = gimple_assign_rhs2(def_stmt);
113600 +
113601 + cur_fndecl_attr = search_intentional(visited, rhs1);
113602 + if (cur_fndecl_attr != MARK_NO)
113603 + return cur_fndecl_attr;
113604 + return search_intentional(visited, rhs2);
113605 +}
113606 +
113607 +// Look up the intentional_overflow attribute on the caller and the callee functions.
113608 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
113609 +{
113610 + const_gimple def_stmt;
113611 +
113612 + if (TREE_CODE(lhs) != SSA_NAME)
113613 + return get_intentional_attr_type(lhs);
113614 +
113615 + def_stmt = get_def_stmt(lhs);
113616 + if (!def_stmt)
113617 + return MARK_NO;
113618 +
113619 + if (pointer_set_contains(visited, def_stmt))
113620 + return MARK_NO;
113621 +
113622 + switch (gimple_code(def_stmt)) {
113623 + case GIMPLE_NOP:
113624 + return search_intentional(visited, SSA_NAME_VAR(lhs));
113625 + case GIMPLE_ASM:
113626 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
113627 + return MARK_TURN_OFF;
113628 + return MARK_NO;
113629 + case GIMPLE_CALL:
113630 + return MARK_NO;
113631 + case GIMPLE_PHI:
113632 + return search_intentional_phi(visited, lhs);
113633 + case GIMPLE_ASSIGN:
113634 + switch (gimple_num_ops(def_stmt)) {
113635 + case 2:
113636 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
113637 + case 3:
113638 + return search_intentional_binary(visited, lhs);
113639 + }
113640 + case GIMPLE_RETURN:
113641 + return MARK_NO;
113642 + default:
113643 + debug_gimple_stmt((gimple)def_stmt);
113644 + error("%s: unknown gimple code", __func__);
113645 + gcc_unreachable();
113646 + }
113647 +}
113648 +
113649 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
113650 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
113651 +{
113652 + const_tree fndecl;
113653 + struct pointer_set_t *visited;
113654 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
113655 +
113656 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
113657 + if (is_end_intentional_intentional_attr(fndecl, argnum))
113658 + decl_attr = MARK_NOT_INTENTIONAL;
113659 + else if (is_yes_intentional_attr(fndecl, argnum))
113660 + decl_attr = MARK_YES;
113661 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113662 + return MARK_TURN_OFF;
113663 + }
113664 +
113665 + visited = pointer_set_create();
113666 + cur_fndecl_attr = search_intentional(visited, arg);
113667 + pointer_set_destroy(visited);
113668 +
113669 + switch (cur_fndecl_attr) {
113670 + case MARK_NO:
113671 + case MARK_TURN_OFF:
113672 + return cur_fndecl_attr;
113673 + default:
113674 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
113675 + return MARK_YES;
113676 + }
113677 +}
113678 +
113679 +static void check_missing_size_overflow_attribute(tree var)
113680 +{
113681 + tree orig_fndecl;
113682 + unsigned int num;
113683 +
113684 + if (is_a_return_check(var))
113685 + orig_fndecl = DECL_ORIGIN(var);
113686 + else
113687 + orig_fndecl = DECL_ORIGIN(current_function_decl);
113688 +
113689 + num = get_function_num(var, orig_fndecl);
113690 + if (num == CANNOT_FIND_ARG)
113691 + return;
113692 +
113693 + is_missing_function(orig_fndecl, num);
113694 +}
113695 +
113696 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
113697 +{
113698 + gimple phi = get_def_stmt(result);
113699 + unsigned int i, n = gimple_phi_num_args(phi);
113700 +
113701 + pointer_set_insert(visited, phi);
113702 + for (i = 0; i < n; i++) {
113703 + tree arg = gimple_phi_arg_def(phi, i);
113704 +
113705 + search_size_overflow_attribute(visited, arg);
113706 + }
113707 +}
113708 +
113709 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
113710 +{
113711 + const_gimple def_stmt = get_def_stmt(lhs);
113712 + tree rhs1, rhs2;
113713 +
113714 + rhs1 = gimple_assign_rhs1(def_stmt);
113715 + rhs2 = gimple_assign_rhs2(def_stmt);
113716 +
113717 + search_size_overflow_attribute(visited, rhs1);
113718 + search_size_overflow_attribute(visited, rhs2);
113719 +}
113720 +
113721 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
113722 +{
113723 + const_gimple def_stmt;
113724 +
113725 + if (TREE_CODE(lhs) == PARM_DECL) {
113726 + check_missing_size_overflow_attribute(lhs);
113727 + return;
113728 + }
113729 +
113730 + def_stmt = get_def_stmt(lhs);
113731 + if (!def_stmt)
113732 + return;
113733 +
113734 + if (pointer_set_insert(visited, def_stmt))
113735 + return;
113736 +
113737 + switch (gimple_code(def_stmt)) {
113738 + case GIMPLE_NOP:
113739 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
113740 + case GIMPLE_ASM:
113741 + return;
113742 + case GIMPLE_CALL: {
113743 + tree fndecl = gimple_call_fndecl(def_stmt);
113744 +
113745 + if (fndecl == NULL_TREE)
113746 + return;
113747 + check_missing_size_overflow_attribute(fndecl);
113748 + return;
113749 + }
113750 + case GIMPLE_PHI:
113751 + return search_size_overflow_attribute_phi(visited, lhs);
113752 + case GIMPLE_ASSIGN:
113753 + switch (gimple_num_ops(def_stmt)) {
113754 + case 2:
113755 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
113756 + case 3:
113757 + return search_size_overflow_attribute_binary(visited, lhs);
113758 + }
113759 + default:
113760 + debug_gimple_stmt((gimple)def_stmt);
113761 + error("%s: unknown gimple code", __func__);
113762 + gcc_unreachable();
113763 + }
113764 +}
113765 +
113766 +// Search missing entries in the hash table (invoked from the gimple pass)
113767 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
113768 +{
113769 + tree fndecl = NULL_TREE;
113770 + tree lhs;
113771 + struct pointer_set_t *visited;
113772 +
113773 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
113774 + return;
113775 +
113776 + if (num == 0) {
113777 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
113778 + lhs = gimple_return_retval(stmt);
113779 + } else {
113780 + gcc_assert(is_gimple_call(stmt));
113781 + lhs = gimple_call_arg(stmt, num - 1);
113782 + fndecl = gimple_call_fndecl(stmt);
113783 + }
113784 +
113785 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
113786 + return;
113787 +
113788 + visited = pointer_set_create();
113789 + search_size_overflow_attribute(visited, lhs);
113790 + pointer_set_destroy(visited);
113791 +}
113792 +
113793 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
113794 +{
113795 + gimple_stmt_iterator gsi;
113796 + gimple assign;
113797 +
113798 + assign = gimple_build_assign(asm_data->input, asm_data->output);
113799 + gsi = gsi_for_stmt(stmt);
113800 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113801 + asm_data->def_stmt = assign;
113802 +
113803 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
113804 + asm_data->output = make_ssa_name(asm_data->output, stmt);
113805 + if (gimple_code(stmt) == GIMPLE_RETURN)
113806 + gimple_return_set_retval(stmt, asm_data->output);
113807 + else
113808 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
113809 + update_stmt(stmt);
113810 +}
113811 +
113812 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
113813 +{
113814 + const char *fn_name;
113815 + char *asm_comment;
113816 + unsigned int len;
113817 +
113818 + if (argnum == 0)
113819 + fn_name = DECL_NAME_POINTER(current_function_decl);
113820 + else
113821 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
113822 +
113823 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
113824 + gcc_assert(len > 0);
113825 +
113826 + return asm_comment;
113827 +}
113828 +
113829 +static const char *convert_mark_to_str(enum mark mark)
113830 +{
113831 + switch (mark) {
113832 + case MARK_NO:
113833 + return OK_ASM_STR;
113834 + case MARK_YES:
113835 + case MARK_NOT_INTENTIONAL:
113836 + return YES_ASM_STR;
113837 + case MARK_TURN_OFF:
113838 + return TURN_OFF_ASM_STR;
113839 + }
113840 +
113841 + gcc_unreachable();
113842 +}
113843 +
113844 +/* Create the input of the size_overflow asm stmt.
113845 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
113846 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
113847 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
113848 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
113849 + */
113850 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
113851 +{
113852 + if (!asm_data->def_stmt) {
113853 + asm_data->input = NULL_TREE;
113854 + return;
113855 + }
113856 +
113857 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
113858 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
113859 +
113860 + switch (gimple_code(asm_data->def_stmt)) {
113861 + case GIMPLE_ASSIGN:
113862 + case GIMPLE_CALL:
113863 + replace_call_lhs(asm_data);
113864 + break;
113865 + case GIMPLE_PHI:
113866 + create_output_from_phi(stmt, argnum, asm_data);
113867 + break;
113868 + case GIMPLE_NOP: {
113869 + enum mark mark;
113870 + const char *mark_str;
113871 + char *asm_comment;
113872 +
113873 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
113874 +
113875 + asm_data->input = asm_data->output;
113876 + asm_data->output = NULL;
113877 + asm_data->def_stmt = stmt;
113878 +
113879 + mark_str = convert_mark_to_str(mark);
113880 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
113881 +
113882 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
113883 + free(asm_comment);
113884 + asm_data->input = NULL_TREE;
113885 + break;
113886 + }
113887 + case GIMPLE_ASM:
113888 + if (is_size_overflow_asm(asm_data->def_stmt)) {
113889 + asm_data->input = NULL_TREE;
113890 + break;
113891 + }
113892 + default:
113893 + debug_gimple_stmt(asm_data->def_stmt);
113894 + gcc_unreachable();
113895 + }
113896 +}
113897 +
113898 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
113899 + * is of the right kind create the appropriate size_overflow asm stmts:
113900 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
113901 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
113902 + */
113903 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
113904 +{
113905 + struct asm_data asm_data;
113906 + const char *mark_str;
113907 + char *asm_comment;
113908 + enum mark mark;
113909 +
113910 + if (is_gimple_constant(output_node))
113911 + return;
113912 +
113913 + asm_data.output = output_node;
113914 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
113915 + if (mark != MARK_TURN_OFF)
113916 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
113917 +
113918 + asm_data.def_stmt = get_def_stmt(asm_data.output);
113919 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
113920 + return;
113921 +
113922 + create_asm_input(stmt, argnum, &asm_data);
113923 + if (asm_data.input == NULL_TREE)
113924 + return;
113925 +
113926 + mark_str = convert_mark_to_str(mark);
113927 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
113928 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
113929 + free(asm_comment);
113930 +}
113931 +
113932 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
113933 +static bool create_mark_asm(gimple stmt, enum mark mark)
113934 +{
113935 + struct asm_data asm_data;
113936 + const char *asm_str;
113937 +
113938 + switch (mark) {
113939 + case MARK_TURN_OFF:
113940 + asm_str = TURN_OFF_ASM_STR;
113941 + break;
113942 + case MARK_NOT_INTENTIONAL:
113943 + case MARK_YES:
113944 + asm_str = YES_ASM_STR;
113945 + break;
113946 + default:
113947 + gcc_unreachable();
113948 + }
113949 +
113950 + asm_data.def_stmt = stmt;
113951 + asm_data.output = gimple_call_lhs(stmt);
113952 +
113953 + if (asm_data.output == NULL_TREE) {
113954 + asm_data.input = gimple_call_arg(stmt, 0);
113955 + if (is_gimple_constant(asm_data.input))
113956 + return false;
113957 + asm_data.output = NULL;
113958 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
113959 + return true;
113960 + }
113961 +
113962 + create_asm_input(stmt, 0, &asm_data);
113963 + gcc_assert(asm_data.input != NULL_TREE);
113964 +
113965 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
113966 + return true;
113967 +}
113968 +
113969 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
113970 +{
113971 + gimple def_stmt;
113972 +
113973 + def_stmt = get_def_stmt(lhs);
113974 + if (!def_stmt)
113975 + return;
113976 +
113977 + if (pointer_set_insert(visited, def_stmt))
113978 + return;
113979 +
113980 + switch (gimple_code(def_stmt)) {
113981 + case GIMPLE_NOP:
113982 + case GIMPLE_ASM:
113983 + case GIMPLE_CALL:
113984 + break;
113985 + case GIMPLE_PHI: {
113986 + unsigned int i, n = gimple_phi_num_args(def_stmt);
113987 +
113988 + pointer_set_insert(visited, def_stmt);
113989 +
113990 + for (i = 0; i < n; i++) {
113991 + tree arg = gimple_phi_arg_def(def_stmt, i);
113992 +
113993 + walk_use_def_ptr(visited, arg);
113994 + }
113995 + }
113996 + case GIMPLE_ASSIGN:
113997 + switch (gimple_num_ops(def_stmt)) {
113998 + case 2:
113999 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114000 + return;
114001 + case 3:
114002 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114003 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114004 + return;
114005 + default:
114006 + return;
114007 + }
114008 + default:
114009 + debug_gimple_stmt((gimple)def_stmt);
114010 + error("%s: unknown gimple code", __func__);
114011 + gcc_unreachable();
114012 + }
114013 +}
114014 +
114015 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114016 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114017 +{
114018 + struct pointer_set_t *visited;
114019 +
114020 + visited = pointer_set_create();
114021 + walk_use_def_ptr(visited, arg);
114022 + pointer_set_destroy(visited);
114023 +}
114024 +
114025 +// Determine the return value and insert the asm stmt to mark the return stmt.
114026 +static void insert_asm_ret(gimple stmt)
114027 +{
114028 + tree ret;
114029 +
114030 + ret = gimple_return_retval(stmt);
114031 + create_size_overflow_asm(stmt, ret, 0);
114032 +}
114033 +
114034 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114035 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114036 +{
114037 + tree arg;
114038 + unsigned int argnum;
114039 +
114040 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114041 + gcc_assert(argnum != 0);
114042 + if (argnum == CANNOT_FIND_ARG)
114043 + return;
114044 +
114045 + arg = gimple_call_arg(stmt, argnum - 1);
114046 + gcc_assert(arg != NULL_TREE);
114047 +
114048 + // skip all ptr - ptr expressions
114049 + insert_mark_not_intentional_asm_at_ptr(arg);
114050 +
114051 + create_size_overflow_asm(stmt, arg, argnum);
114052 +}
114053 +
114054 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114055 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114056 +{
114057 + unsigned int argnum;
114058 + tree attr_value;
114059 +
114060 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114061 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114062 + argnums[argnum] = true;
114063 + }
114064 +}
114065 +
114066 +// If a function arg or the return value is in the hash table then set its index in the array.
114067 +static void set_argnum_hash(tree fndecl, bool *argnums)
114068 +{
114069 + unsigned int num;
114070 + const struct size_overflow_hash *hash;
114071 +
114072 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114073 + if (!hash)
114074 + return;
114075 +
114076 + for (num = 0; num <= MAX_PARAM; num++) {
114077 + if (!(hash->param & (1U << num)))
114078 + continue;
114079 +
114080 + argnums[num] = true;
114081 + }
114082 +}
114083 +
114084 +static bool is_all_the_argnums_empty(bool *argnums)
114085 +{
114086 + unsigned int i;
114087 +
114088 + for (i = 0; i <= MAX_PARAM; i++)
114089 + if (argnums[i])
114090 + return false;
114091 + return true;
114092 +}
114093 +
114094 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114095 +static void search_interesting_args(tree fndecl, bool *argnums)
114096 +{
114097 + const_tree attr;
114098 +
114099 + set_argnum_hash(fndecl, argnums);
114100 + if (!is_all_the_argnums_empty(argnums))
114101 + return;
114102 +
114103 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114104 + if (attr && TREE_VALUE(attr))
114105 + set_argnum_attribute(attr, argnums);
114106 +}
114107 +
114108 +/*
114109 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114110 + * on the callee function.
114111 + */
114112 +static bool is_mark_turn_off_attribute(gimple stmt)
114113 +{
114114 + enum mark mark;
114115 + const_tree fndecl = gimple_call_fndecl(stmt);
114116 +
114117 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114118 + if (mark == MARK_TURN_OFF)
114119 + return true;
114120 + return false;
114121 +}
114122 +
114123 +// 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
114124 +static void handle_interesting_function(gimple stmt)
114125 +{
114126 + unsigned int argnum;
114127 + tree fndecl;
114128 + bool orig_argnums[MAX_PARAM + 1] = {false};
114129 +
114130 + if (gimple_call_num_args(stmt) == 0)
114131 + return;
114132 + fndecl = gimple_call_fndecl(stmt);
114133 + if (fndecl == NULL_TREE)
114134 + return;
114135 + fndecl = DECL_ORIGIN(fndecl);
114136 +
114137 + if (is_mark_turn_off_attribute(stmt)) {
114138 + create_mark_asm(stmt, MARK_TURN_OFF);
114139 + return;
114140 + }
114141 +
114142 + search_interesting_args(fndecl, orig_argnums);
114143 +
114144 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114145 + if (orig_argnums[argnum])
114146 + insert_asm_arg(stmt, argnum);
114147 +}
114148 +
114149 +// 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
114150 +static void handle_interesting_ret(gimple stmt)
114151 +{
114152 + bool orig_argnums[MAX_PARAM + 1] = {false};
114153 +
114154 + search_interesting_args(current_function_decl, orig_argnums);
114155 +
114156 + if (orig_argnums[0])
114157 + insert_asm_ret(stmt);
114158 +}
114159 +
114160 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114161 +static unsigned int search_interesting_functions(void)
114162 +{
114163 + basic_block bb;
114164 +
114165 + FOR_ALL_BB_FN(bb, cfun) {
114166 + gimple_stmt_iterator gsi;
114167 +
114168 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114169 + gimple stmt = gsi_stmt(gsi);
114170 +
114171 + if (is_size_overflow_asm(stmt))
114172 + continue;
114173 +
114174 + if (is_gimple_call(stmt))
114175 + handle_interesting_function(stmt);
114176 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114177 + handle_interesting_ret(stmt);
114178 + }
114179 + }
114180 + return 0;
114181 +}
114182 +
114183 +/*
114184 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114185 + * this pass inserts asm stmts to mark the interesting args
114186 + * that the ipa pass will detect and insert the size overflow checks for.
114187 + */
114188 +#if BUILDING_GCC_VERSION >= 4009
114189 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114190 +#else
114191 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114192 + .pass = {
114193 +#endif
114194 + .type = GIMPLE_PASS,
114195 + .name = "insert_size_overflow_asm",
114196 +#if BUILDING_GCC_VERSION >= 4008
114197 + .optinfo_flags = OPTGROUP_NONE,
114198 +#endif
114199 +#if BUILDING_GCC_VERSION >= 4009
114200 + .has_gate = false,
114201 + .has_execute = true,
114202 +#else
114203 + .gate = NULL,
114204 + .execute = search_interesting_functions,
114205 + .sub = NULL,
114206 + .next = NULL,
114207 + .static_pass_number = 0,
114208 +#endif
114209 + .tv_id = TV_NONE,
114210 + .properties_required = PROP_cfg,
114211 + .properties_provided = 0,
114212 + .properties_destroyed = 0,
114213 + .todo_flags_start = 0,
114214 + .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
114215 +#if BUILDING_GCC_VERSION < 4009
114216 + }
114217 +#endif
114218 +};
114219 +
114220 +#if BUILDING_GCC_VERSION >= 4009
114221 +namespace {
114222 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114223 +public:
114224 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114225 + unsigned int execute() { return search_interesting_functions(); }
114226 +};
114227 +}
114228 +#endif
114229 +
114230 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114231 +{
114232 +#if BUILDING_GCC_VERSION >= 4009
114233 + return new insert_size_overflow_asm_pass();
114234 +#else
114235 + return &insert_size_overflow_asm_pass.pass;
114236 +#endif
114237 +}
114238 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
114239 new file mode 100644
114240 index 0000000..73f0a12
114241 --- /dev/null
114242 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114243 @@ -0,0 +1,943 @@
114244 +/*
114245 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114246 + * Licensed under the GPL v2, or (at your option) v3
114247 + *
114248 + * Homepage:
114249 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114250 + *
114251 + * Documentation:
114252 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114253 + *
114254 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114255 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114256 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114257 + *
114258 + * Usage:
114259 + * $ make
114260 + * $ make run
114261 + */
114262 +
114263 +#include "gcc-common.h"
114264 +#include "size_overflow.h"
114265 +
114266 +#define MIN_CHECK true
114267 +#define MAX_CHECK false
114268 +
114269 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114270 +{
114271 + const_tree type;
114272 + tree new_type;
114273 +
114274 + gcc_assert(node != NULL_TREE);
114275 +
114276 + type = TREE_TYPE(node);
114277 +
114278 + if (pointer_set_contains(visited->my_stmts, stmt))
114279 + return TREE_TYPE(node);
114280 +
114281 + switch (TYPE_MODE(type)) {
114282 + case QImode:
114283 + new_type = size_overflow_type_HI;
114284 + break;
114285 + case HImode:
114286 + new_type = size_overflow_type_SI;
114287 + break;
114288 + case SImode:
114289 + new_type = size_overflow_type_DI;
114290 + break;
114291 + case DImode:
114292 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114293 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114294 + else
114295 + new_type = size_overflow_type_TI;
114296 + break;
114297 + case TImode:
114298 + gcc_assert(!TYPE_UNSIGNED(type));
114299 + new_type = size_overflow_type_TI;
114300 + break;
114301 + default:
114302 + debug_tree((tree)node);
114303 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114304 + gcc_unreachable();
114305 + }
114306 +
114307 + if (TYPE_QUALS(type) != 0)
114308 + return build_qualified_type(new_type, TYPE_QUALS(type));
114309 + return new_type;
114310 +}
114311 +
114312 +static tree get_lhs(const_gimple stmt)
114313 +{
114314 + switch (gimple_code(stmt)) {
114315 + case GIMPLE_ASSIGN:
114316 + case GIMPLE_CALL:
114317 + return gimple_get_lhs(stmt);
114318 + case GIMPLE_PHI:
114319 + return gimple_phi_result(stmt);
114320 + default:
114321 + return NULL_TREE;
114322 + }
114323 +}
114324 +
114325 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
114326 +{
114327 + gimple_stmt_iterator gsi;
114328 + tree lhs;
114329 + gimple new_stmt;
114330 +
114331 + if (rhs == NULL_TREE)
114332 + return NULL_TREE;
114333 +
114334 + gsi = gsi_for_stmt(stmt);
114335 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
114336 + pointer_set_insert(visited->my_stmts, new_stmt);
114337 +
114338 + lhs = get_lhs(new_stmt);
114339 + gcc_assert(lhs != NULL_TREE);
114340 + return lhs;
114341 +}
114342 +
114343 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
114344 +{
114345 + tree lhs, dst_type;
114346 + gimple_stmt_iterator gsi;
114347 +
114348 + if (rhs1 == NULL_TREE) {
114349 + debug_gimple_stmt(oldstmt);
114350 + error("%s: rhs1 is NULL_TREE", __func__);
114351 + gcc_unreachable();
114352 + }
114353 +
114354 + switch (gimple_code(oldstmt)) {
114355 + case GIMPLE_ASM:
114356 + lhs = rhs1;
114357 + break;
114358 + case GIMPLE_CALL:
114359 + case GIMPLE_ASSIGN:
114360 + lhs = gimple_get_lhs(oldstmt);
114361 + break;
114362 + default:
114363 + debug_gimple_stmt(oldstmt);
114364 + gcc_unreachable();
114365 + }
114366 +
114367 + gsi = gsi_for_stmt(oldstmt);
114368 + pointer_set_insert(visited->stmts, oldstmt);
114369 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
114370 + basic_block next_bb, cur_bb;
114371 + const_edge e;
114372 +
114373 + gcc_assert(before == false);
114374 + gcc_assert(stmt_can_throw_internal(oldstmt));
114375 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
114376 + gcc_assert(!gsi_end_p(gsi));
114377 +
114378 + cur_bb = gimple_bb(oldstmt);
114379 + next_bb = cur_bb->next_bb;
114380 + e = find_edge(cur_bb, next_bb);
114381 + gcc_assert(e != NULL);
114382 + gcc_assert(e->flags & EDGE_FALLTHRU);
114383 +
114384 + gsi = gsi_after_labels(next_bb);
114385 + gcc_assert(!gsi_end_p(gsi));
114386 +
114387 + before = true;
114388 + oldstmt = gsi_stmt(gsi);
114389 + }
114390 +
114391 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
114392 +
114393 + if (is_gimple_constant(rhs1))
114394 + return cast_a_tree(dst_type, rhs1);
114395 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
114396 +}
114397 +
114398 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
114399 +{
114400 + gimple stmt;
114401 + gimple_stmt_iterator gsi;
114402 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
114403 +
114404 + if (pointer_set_contains(visited->my_stmts, oldstmt))
114405 + return lhs;
114406 +
114407 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
114408 + rhs1 = gimple_assign_rhs1(oldstmt);
114409 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
114410 + }
114411 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
114412 + rhs2 = gimple_assign_rhs2(oldstmt);
114413 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
114414 + }
114415 +
114416 + stmt = gimple_copy(oldstmt);
114417 + gimple_set_location(stmt, gimple_location(oldstmt));
114418 + pointer_set_insert(visited->my_stmts, stmt);
114419 +
114420 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
114421 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
114422 +
114423 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
114424 +
114425 + new_var = create_new_var(size_overflow_type);
114426 + new_var = make_ssa_name(new_var, stmt);
114427 + gimple_assign_set_lhs(stmt, new_var);
114428 +
114429 + if (rhs1 != NULL_TREE)
114430 + gimple_assign_set_rhs1(stmt, rhs1);
114431 +
114432 + if (rhs2 != NULL_TREE)
114433 + gimple_assign_set_rhs2(stmt, rhs2);
114434 +#if BUILDING_GCC_VERSION >= 4006
114435 + if (rhs3 != NULL_TREE)
114436 + gimple_assign_set_rhs3(stmt, rhs3);
114437 +#endif
114438 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
114439 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
114440 +
114441 + gsi = gsi_for_stmt(oldstmt);
114442 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
114443 + update_stmt(stmt);
114444 + pointer_set_insert(visited->stmts, oldstmt);
114445 + return gimple_assign_lhs(stmt);
114446 +}
114447 +
114448 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
114449 +{
114450 + gimple assign;
114451 + gimple_stmt_iterator gsi;
114452 + basic_block first_bb;
114453 +
114454 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
114455 +
114456 + if (bb->index == 0) {
114457 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
114458 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114459 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
114460 + bb = first_bb;
114461 + }
114462 +
114463 + gsi = gsi_after_labels(bb);
114464 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
114465 + pointer_set_insert(visited->my_stmts, assign);
114466 +
114467 + return gimple_assign_lhs(assign);
114468 +}
114469 +
114470 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
114471 +{
114472 + gimple_stmt_iterator gsi;
114473 + gimple assign, def_stmt = get_def_stmt(new_arg);
114474 +
114475 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
114476 + gsi = gsi_after_labels(gimple_bb(def_stmt));
114477 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
114478 + } else {
114479 + gsi = gsi_for_stmt(def_stmt);
114480 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
114481 + }
114482 +
114483 + pointer_set_insert(visited->my_stmts, assign);
114484 + return gimple_assign_lhs(assign);
114485 +}
114486 +
114487 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
114488 +{
114489 + basic_block bb;
114490 + gimple_stmt_iterator gsi;
114491 + const_gimple def_stmt;
114492 + gimple assign;
114493 +
114494 + def_stmt = get_def_stmt(arg);
114495 + bb = gimple_bb(def_stmt);
114496 + gcc_assert(bb->index != 0);
114497 + gsi = gsi_after_labels(bb);
114498 +
114499 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
114500 + pointer_set_insert(visited->my_stmts, assign);
114501 + return gimple_assign_lhs(assign);
114502 +}
114503 +
114504 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
114505 +{
114506 + tree size_overflow_type;
114507 + tree arg;
114508 + const_gimple def_stmt;
114509 +
114510 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
114511 + return new_arg;
114512 +
114513 + arg = gimple_phi_arg_def(oldstmt, i);
114514 + def_stmt = get_def_stmt(arg);
114515 + gcc_assert(def_stmt != NULL);
114516 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114517 +
114518 + switch (gimple_code(def_stmt)) {
114519 + case GIMPLE_PHI:
114520 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
114521 + case GIMPLE_NOP: {
114522 + basic_block bb;
114523 +
114524 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
114525 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
114526 + }
114527 + case GIMPLE_ASM: {
114528 + gimple_stmt_iterator gsi;
114529 + gimple assign, stmt = get_def_stmt(arg);
114530 +
114531 + gsi = gsi_for_stmt(stmt);
114532 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
114533 + pointer_set_insert(visited->my_stmts, assign);
114534 + return gimple_assign_lhs(assign);
114535 + }
114536 + default:
114537 + gcc_assert(new_arg != NULL_TREE);
114538 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
114539 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
114540 + }
114541 +}
114542 +
114543 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
114544 +{
114545 + basic_block bb;
114546 + gimple phi;
114547 + gimple_seq seq;
114548 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
114549 +
114550 + bb = gsi_bb(gsi);
114551 +
114552 + if (result == NULL_TREE) {
114553 + tree old_result = gimple_phi_result(oldstmt);
114554 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
114555 +
114556 + result = create_new_var(size_overflow_type);
114557 + }
114558 +
114559 + phi = create_phi_node(result, bb);
114560 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
114561 + seq = phi_nodes(bb);
114562 + gsi = gsi_last(seq);
114563 + gsi_remove(&gsi, false);
114564 +
114565 + gsi = gsi_for_stmt(oldstmt);
114566 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
114567 + gimple_set_bb(phi, bb);
114568 + return phi;
114569 +}
114570 +
114571 +#if BUILDING_GCC_VERSION <= 4007
114572 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
114573 +#else
114574 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
114575 +#endif
114576 +{
114577 + gimple new_phi;
114578 + unsigned int i;
114579 + tree arg, result;
114580 + location_t loc = gimple_location(oldstmt);
114581 +
114582 +#if BUILDING_GCC_VERSION <= 4007
114583 + gcc_assert(!VEC_empty(tree, *args));
114584 +#else
114585 + gcc_assert(!args->is_empty());
114586 +#endif
114587 +
114588 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
114589 + result = gimple_phi_result(new_phi);
114590 + ssa_name_var = SSA_NAME_VAR(result);
114591 +
114592 +#if BUILDING_GCC_VERSION <= 4007
114593 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
114594 +#else
114595 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
114596 +#endif
114597 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
114598 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
114599 + }
114600 +
114601 +#if BUILDING_GCC_VERSION <= 4007
114602 + VEC_free(tree, heap, *args);
114603 +#else
114604 + vec_free(args);
114605 +#endif
114606 + update_stmt(new_phi);
114607 + pointer_set_insert(visited->my_stmts, new_phi);
114608 + return result;
114609 +}
114610 +
114611 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
114612 +{
114613 + tree ssa_name_var = NULL_TREE;
114614 +#if BUILDING_GCC_VERSION <= 4007
114615 + VEC(tree, heap) *args = NULL;
114616 +#else
114617 + vec<tree, va_heap, vl_embed> *args = NULL;
114618 +#endif
114619 + gimple oldstmt = get_def_stmt(orig_result);
114620 + unsigned int i, len = gimple_phi_num_args(oldstmt);
114621 +
114622 + pointer_set_insert(visited->stmts, oldstmt);
114623 + for (i = 0; i < len; i++) {
114624 + tree arg, new_arg;
114625 +
114626 + arg = gimple_phi_arg_def(oldstmt, i);
114627 + new_arg = expand(visited, caller_node, arg);
114628 +
114629 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
114630 + ssa_name_var = SSA_NAME_VAR(new_arg);
114631 +
114632 + if (is_gimple_constant(arg)) {
114633 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114634 +
114635 + new_arg = cast_a_tree(size_overflow_type, arg);
114636 + }
114637 +
114638 +#if BUILDING_GCC_VERSION <= 4007
114639 + VEC_safe_push(tree, heap, args, new_arg);
114640 +#else
114641 + vec_safe_push(args, new_arg);
114642 +#endif
114643 + }
114644 +
114645 +#if BUILDING_GCC_VERSION <= 4007
114646 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
114647 +#else
114648 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
114649 +#endif
114650 +}
114651 +
114652 +static tree create_cast_assign(struct visited *visited, gimple stmt)
114653 +{
114654 + tree rhs1 = gimple_assign_rhs1(stmt);
114655 + tree lhs = gimple_assign_lhs(stmt);
114656 + const_tree rhs1_type = TREE_TYPE(rhs1);
114657 + const_tree lhs_type = TREE_TYPE(lhs);
114658 +
114659 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
114660 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114661 +
114662 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
114663 +}
114664 +
114665 +static bool skip_lhs_cast_check(const_gimple stmt)
114666 +{
114667 + const_tree rhs = gimple_assign_rhs1(stmt);
114668 + const_gimple def_stmt = get_def_stmt(rhs);
114669 +
114670 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
114671 + if (gimple_code(def_stmt) == GIMPLE_ASM)
114672 + return true;
114673 +
114674 + if (is_const_plus_unsigned_signed_truncation(rhs))
114675 + return true;
114676 +
114677 + return false;
114678 +}
114679 +
114680 +static tree create_string_param(tree string)
114681 +{
114682 + tree i_type, a_type;
114683 + const int length = TREE_STRING_LENGTH(string);
114684 +
114685 + gcc_assert(length > 0);
114686 +
114687 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
114688 + a_type = build_array_type(char_type_node, i_type);
114689 +
114690 + TREE_TYPE(string) = a_type;
114691 + TREE_CONSTANT(string) = 1;
114692 + TREE_READONLY(string) = 1;
114693 +
114694 + return build1(ADDR_EXPR, ptr_type_node, string);
114695 +}
114696 +
114697 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
114698 +{
114699 + gimple cond_stmt;
114700 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
114701 +
114702 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
114703 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
114704 + update_stmt(cond_stmt);
114705 +}
114706 +
114707 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
114708 +{
114709 + gimple func_stmt;
114710 + const_gimple def_stmt;
114711 + const_tree loc_line;
114712 + tree loc_file, ssa_name, current_func;
114713 + expanded_location xloc;
114714 + char *ssa_name_buf;
114715 + int len;
114716 + struct cgraph_edge *edge;
114717 + struct cgraph_node *callee_node;
114718 + int frequency;
114719 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
114720 +
114721 + def_stmt = get_def_stmt(arg);
114722 + xloc = expand_location(gimple_location(def_stmt));
114723 +
114724 + if (!gimple_has_location(def_stmt)) {
114725 + xloc = expand_location(gimple_location(stmt));
114726 + if (!gimple_has_location(stmt))
114727 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
114728 + }
114729 +
114730 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
114731 +
114732 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
114733 + loc_file = create_string_param(loc_file);
114734 +
114735 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
114736 + current_func = create_string_param(current_func);
114737 +
114738 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
114739 + call_count++;
114740 + 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);
114741 + gcc_assert(len > 0);
114742 + ssa_name = build_string(len + 1, ssa_name_buf);
114743 + free(ssa_name_buf);
114744 + ssa_name = create_string_param(ssa_name);
114745 +
114746 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
114747 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
114748 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
114749 +
114750 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
114751 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
114752 +
114753 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
114754 + gcc_assert(edge != NULL);
114755 +}
114756 +
114757 +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)
114758 +{
114759 + basic_block cond_bb, join_bb, bb_true;
114760 + edge e;
114761 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114762 +
114763 + cond_bb = gimple_bb(stmt);
114764 + if (before)
114765 + gsi_prev(&gsi);
114766 + if (gsi_end_p(gsi))
114767 + e = split_block_after_labels(cond_bb);
114768 + else
114769 + e = split_block(cond_bb, gsi_stmt(gsi));
114770 + cond_bb = e->src;
114771 + join_bb = e->dest;
114772 + e->flags = EDGE_FALSE_VALUE;
114773 + e->probability = REG_BR_PROB_BASE;
114774 +
114775 + bb_true = create_empty_bb(cond_bb);
114776 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
114777 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
114778 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
114779 +
114780 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114781 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
114782 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
114783 +
114784 + if (current_loops != NULL) {
114785 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
114786 + add_bb_to_loop(bb_true, cond_bb->loop_father);
114787 + }
114788 +
114789 + insert_cond(cond_bb, arg, cond_code, type_value);
114790 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
114791 +
114792 +// print_the_code_insertions(stmt);
114793 +}
114794 +
114795 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
114796 +{
114797 + const_tree rhs_type = TREE_TYPE(rhs);
114798 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
114799 +
114800 + gcc_assert(rhs_type != NULL_TREE);
114801 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
114802 + return;
114803 +
114804 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
114805 +
114806 + if (is_const_plus_unsigned_signed_truncation(rhs))
114807 + return;
114808 +
114809 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
114810 + // typemax (-1) < typemin (0)
114811 + if (TREE_OVERFLOW(type_max))
114812 + return;
114813 +
114814 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
114815 +
114816 + cast_rhs_type = TREE_TYPE(cast_rhs);
114817 + type_max_type = TREE_TYPE(type_max);
114818 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
114819 +
114820 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
114821 +
114822 + // special case: get_size_overflow_type(), 32, u64->s
114823 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
114824 + return;
114825 +
114826 + type_min_type = TREE_TYPE(type_min);
114827 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
114828 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
114829 +}
114830 +
114831 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
114832 +{
114833 + bool cast_lhs, cast_rhs;
114834 + tree lhs = gimple_assign_lhs(stmt);
114835 + tree rhs = gimple_assign_rhs1(stmt);
114836 + const_tree lhs_type = TREE_TYPE(lhs);
114837 + const_tree rhs_type = TREE_TYPE(rhs);
114838 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
114839 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
114840 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
114841 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
114842 +
114843 + static bool check_lhs[3][4] = {
114844 + // ss su us uu
114845 + { false, true, true, false }, // lhs > rhs
114846 + { false, false, false, false }, // lhs = rhs
114847 + { true, true, true, true }, // lhs < rhs
114848 + };
114849 +
114850 + static bool check_rhs[3][4] = {
114851 + // ss su us uu
114852 + { true, false, true, true }, // lhs > rhs
114853 + { true, false, true, true }, // lhs = rhs
114854 + { true, false, true, true }, // lhs < rhs
114855 + };
114856 +
114857 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
114858 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
114859 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114860 +
114861 + if (lhs_size > rhs_size) {
114862 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114863 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114864 + } else if (lhs_size == rhs_size) {
114865 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114866 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114867 + } else {
114868 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114869 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114870 + }
114871 +
114872 + if (!cast_lhs && !cast_rhs)
114873 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114874 +
114875 + if (cast_lhs && !skip_lhs_cast_check(stmt))
114876 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
114877 +
114878 + if (cast_rhs)
114879 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
114880 +
114881 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114882 +}
114883 +
114884 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
114885 +{
114886 + enum tree_code rhs_code;
114887 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
114888 +
114889 + if (pointer_set_contains(visited->my_stmts, stmt))
114890 + return lhs;
114891 +
114892 + rhs1 = gimple_assign_rhs1(stmt);
114893 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
114894 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114895 +
114896 + new_rhs1 = expand(visited, caller_node, rhs1);
114897 +
114898 + if (new_rhs1 == NULL_TREE)
114899 + return create_cast_assign(visited, stmt);
114900 +
114901 + if (pointer_set_contains(visited->no_cast_check, stmt))
114902 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114903 +
114904 + rhs_code = gimple_assign_rhs_code(stmt);
114905 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
114906 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
114907 +
114908 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
114909 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
114910 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114911 + }
114912 +
114913 + if (!gimple_assign_cast_p(stmt))
114914 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114915 +
114916 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
114917 +}
114918 +
114919 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
114920 +{
114921 + tree rhs1, lhs = gimple_assign_lhs(stmt);
114922 + gimple def_stmt = get_def_stmt(lhs);
114923 +
114924 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
114925 + rhs1 = gimple_assign_rhs1(def_stmt);
114926 +
114927 + if (is_gimple_constant(rhs1))
114928 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114929 +
114930 + switch (TREE_CODE(rhs1)) {
114931 + case SSA_NAME: {
114932 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
114933 +
114934 + if (gimple_assign_cast_p(stmt))
114935 + unsigned_signed_cast_intentional_overflow(visited, stmt);
114936 + return ret;
114937 + }
114938 + case ARRAY_REF:
114939 + case BIT_FIELD_REF:
114940 + case ADDR_EXPR:
114941 + case COMPONENT_REF:
114942 + case INDIRECT_REF:
114943 +#if BUILDING_GCC_VERSION >= 4006
114944 + case MEM_REF:
114945 +#endif
114946 + case TARGET_MEM_REF:
114947 + case VIEW_CONVERT_EXPR:
114948 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114949 + case PARM_DECL:
114950 + case VAR_DECL:
114951 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114952 +
114953 + default:
114954 + debug_gimple_stmt(def_stmt);
114955 + debug_tree(rhs1);
114956 + gcc_unreachable();
114957 + }
114958 +}
114959 +
114960 +static void __unused print_the_code_insertions(const_gimple stmt)
114961 +{
114962 + location_t loc = gimple_location(stmt);
114963 +
114964 + inform(loc, "Integer size_overflow check applied here.");
114965 +}
114966 +
114967 +static bool is_from_cast(const_tree node)
114968 +{
114969 + gimple def_stmt = get_def_stmt(node);
114970 +
114971 + if (!def_stmt)
114972 + return false;
114973 +
114974 + if (gimple_assign_cast_p(def_stmt))
114975 + return true;
114976 +
114977 + return false;
114978 +}
114979 +
114980 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
114981 +static bool is_a_ptr_minus(gimple stmt)
114982 +{
114983 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
114984 +
114985 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114986 + return false;
114987 +
114988 + rhs1 = gimple_assign_rhs1(stmt);
114989 + if (!is_from_cast(rhs1))
114990 + return false;
114991 +
114992 + rhs2 = gimple_assign_rhs2(stmt);
114993 + if (!is_from_cast(rhs2))
114994 + return false;
114995 +
114996 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
114997 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
114998 +
114999 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115000 + return false;
115001 +
115002 + return true;
115003 +}
115004 +
115005 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115006 +{
115007 + enum intentional_overflow_type res;
115008 + tree rhs1, rhs2, new_lhs;
115009 + gimple def_stmt = get_def_stmt(lhs);
115010 + tree new_rhs1 = NULL_TREE;
115011 + tree new_rhs2 = NULL_TREE;
115012 +
115013 + if (is_a_ptr_minus(def_stmt))
115014 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115015 +
115016 + rhs1 = gimple_assign_rhs1(def_stmt);
115017 + rhs2 = gimple_assign_rhs2(def_stmt);
115018 +
115019 + /* no DImode/TImode division in the 32/64 bit kernel */
115020 + switch (gimple_assign_rhs_code(def_stmt)) {
115021 + case RDIV_EXPR:
115022 + case TRUNC_DIV_EXPR:
115023 + case CEIL_DIV_EXPR:
115024 + case FLOOR_DIV_EXPR:
115025 + case ROUND_DIV_EXPR:
115026 + case TRUNC_MOD_EXPR:
115027 + case CEIL_MOD_EXPR:
115028 + case FLOOR_MOD_EXPR:
115029 + case ROUND_MOD_EXPR:
115030 + case EXACT_DIV_EXPR:
115031 + case POINTER_PLUS_EXPR:
115032 + case BIT_AND_EXPR:
115033 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115034 + default:
115035 + break;
115036 + }
115037 +
115038 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115039 + if (new_lhs != NULL_TREE)
115040 + return new_lhs;
115041 +
115042 + if (TREE_CODE(rhs1) == SSA_NAME)
115043 + new_rhs1 = expand(visited, caller_node, rhs1);
115044 + if (TREE_CODE(rhs2) == SSA_NAME)
115045 + new_rhs2 = expand(visited, caller_node, rhs2);
115046 +
115047 + res = add_mul_intentional_overflow(def_stmt);
115048 + if (res != NO_INTENTIONAL_OVERFLOW) {
115049 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115050 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115051 + return new_lhs;
115052 + }
115053 +
115054 + if (skip_expr_on_double_type(def_stmt)) {
115055 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115056 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115057 + return new_lhs;
115058 + }
115059 +
115060 + if (is_a_neg_overflow(def_stmt, rhs2))
115061 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115062 + if (is_a_neg_overflow(def_stmt, rhs1))
115063 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115064 +
115065 +
115066 + if (is_a_constant_overflow(def_stmt, rhs2))
115067 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115068 + if (is_a_constant_overflow(def_stmt, rhs1))
115069 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115070 +
115071 + // the const is between 0 and (signed) MAX
115072 + if (is_gimple_constant(rhs1))
115073 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115074 + if (is_gimple_constant(rhs2))
115075 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115076 +
115077 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115078 +}
115079 +
115080 +#if BUILDING_GCC_VERSION >= 4006
115081 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115082 +{
115083 + if (is_gimple_constant(rhs))
115084 + return cast_a_tree(size_overflow_type, rhs);
115085 + if (TREE_CODE(rhs) != SSA_NAME)
115086 + return NULL_TREE;
115087 + return expand(visited, caller_node, rhs);
115088 +}
115089 +
115090 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115091 +{
115092 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115093 + gimple def_stmt = get_def_stmt(lhs);
115094 +
115095 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115096 +
115097 + rhs1 = gimple_assign_rhs1(def_stmt);
115098 + rhs2 = gimple_assign_rhs2(def_stmt);
115099 + rhs3 = gimple_assign_rhs3(def_stmt);
115100 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115101 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115102 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115103 +
115104 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115105 +}
115106 +#endif
115107 +
115108 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115109 +{
115110 + gimple_stmt_iterator gsi;
115111 + gimple next_stmt = NULL;
115112 +
115113 + gsi = gsi_for_stmt(stmt);
115114 +
115115 + do {
115116 + gsi_next(&gsi);
115117 + next_stmt = gsi_stmt(gsi);
115118 +
115119 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115120 + return NULL_TREE;
115121 +
115122 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115123 + break;
115124 +
115125 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115126 + } while (!gsi_end_p(gsi));
115127 +
115128 + gcc_assert(next_stmt);
115129 + return get_lhs(next_stmt);
115130 +}
115131 +
115132 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115133 +{
115134 + gimple_stmt_iterator gsi;
115135 + enum gimple_code code = gimple_code(def_stmt);
115136 +
115137 + if (code == GIMPLE_ASM)
115138 + return NULL_TREE;
115139 +
115140 + gsi = gsi_for_stmt(def_stmt);
115141 + gsi_next(&gsi);
115142 +
115143 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115144 + return NULL_TREE;
115145 + return get_my_stmt_lhs(visited, def_stmt);
115146 +}
115147 +
115148 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115149 +{
115150 + gimple def_stmt;
115151 +
115152 + def_stmt = get_def_stmt(lhs);
115153 +
115154 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115155 + return NULL_TREE;
115156 +
115157 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115158 + return lhs;
115159 +
115160 + if (pointer_set_contains(visited->stmts, def_stmt))
115161 + return expand_visited(visited, def_stmt);
115162 +
115163 + switch (gimple_code(def_stmt)) {
115164 + case GIMPLE_PHI:
115165 + return handle_phi(visited, caller_node, lhs);
115166 + case GIMPLE_CALL:
115167 + case GIMPLE_ASM:
115168 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115169 + case GIMPLE_ASSIGN:
115170 + switch (gimple_num_ops(def_stmt)) {
115171 + case 2:
115172 + return handle_unary_ops(visited, caller_node, def_stmt);
115173 + case 3:
115174 + return handle_binary_ops(visited, caller_node, lhs);
115175 +#if BUILDING_GCC_VERSION >= 4006
115176 + case 4:
115177 + return handle_ternary_ops(visited, caller_node, lhs);
115178 +#endif
115179 + }
115180 + default:
115181 + debug_gimple_stmt(def_stmt);
115182 + error("%s: unknown gimple code", __func__);
115183 + gcc_unreachable();
115184 + }
115185 +}
115186 +
115187 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
115188 new file mode 100644
115189 index 0000000..df50164
115190 --- /dev/null
115191 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115192 @@ -0,0 +1,1141 @@
115193 +/*
115194 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115195 + * Licensed under the GPL v2, or (at your option) v3
115196 + *
115197 + * Homepage:
115198 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115199 + *
115200 + * Documentation:
115201 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115202 + *
115203 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115204 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115205 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115206 + *
115207 + * Usage:
115208 + * $ make
115209 + * $ make run
115210 + */
115211 +
115212 +#include "gcc-common.h"
115213 +#include "size_overflow.h"
115214 +
115215 +#define VEC_LEN 128
115216 +#define RET_CHECK NULL_TREE
115217 +#define WRONG_NODE 32
115218 +#define NOT_INTENTIONAL_ASM NULL
115219 +
115220 +unsigned int call_count;
115221 +
115222 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115223 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115224 +
115225 +struct visited_fns {
115226 + struct visited_fns *next;
115227 + const_tree fndecl;
115228 + unsigned int num;
115229 + const_gimple first_stmt;
115230 +};
115231 +
115232 +struct next_cgraph_node {
115233 + struct next_cgraph_node *next;
115234 + struct cgraph_node *current_function;
115235 + tree callee_fndecl;
115236 + unsigned int num;
115237 +};
115238 +
115239 +// Don't want to duplicate entries in next_cgraph_node
115240 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115241 +{
115242 + const_tree new_callee_fndecl;
115243 + struct next_cgraph_node *cur_node;
115244 +
115245 + if (fndecl == RET_CHECK)
115246 + new_callee_fndecl = NODE_DECL(node);
115247 + else
115248 + new_callee_fndecl = fndecl;
115249 +
115250 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115251 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115252 + continue;
115253 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115254 + continue;
115255 + if (num == cur_node->num)
115256 + return true;
115257 + }
115258 + return false;
115259 +}
115260 +
115261 +/* Add a next_cgraph_node into the list for handle_function().
115262 + * handle_function() iterates over all the next cgraph nodes and
115263 + * starts the overflow check insertion process.
115264 + */
115265 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115266 +{
115267 + struct next_cgraph_node *new_node;
115268 +
115269 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115270 + return head;
115271 +
115272 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115273 + new_node->current_function = node;
115274 + new_node->next = NULL;
115275 + new_node->num = num;
115276 + if (fndecl == RET_CHECK)
115277 + new_node->callee_fndecl = NODE_DECL(node);
115278 + else
115279 + new_node->callee_fndecl = fndecl;
115280 +
115281 + if (!head)
115282 + return new_node;
115283 +
115284 + new_node->next = head;
115285 + return new_node;
115286 +}
115287 +
115288 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115289 +{
115290 + struct cgraph_edge *e;
115291 +
115292 + if (num == 0)
115293 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115294 +
115295 + for (e = node->callers; e; e = e->next_caller) {
115296 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115297 +
115298 + gcc_assert(fndecl != NULL_TREE);
115299 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115300 + }
115301 +
115302 + return head;
115303 +}
115304 +
115305 +struct missing_functions {
115306 + struct missing_functions *next;
115307 + const_tree node;
115308 + tree fndecl;
115309 +};
115310 +
115311 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115312 +{
115313 + struct missing_functions *new_function;
115314 +
115315 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115316 + new_function->node = node;
115317 + new_function->next = NULL;
115318 +
115319 + if (TREE_CODE(node) == FUNCTION_DECL)
115320 + new_function->fndecl = node;
115321 + else
115322 + new_function->fndecl = current_function_decl;
115323 + gcc_assert(new_function->fndecl);
115324 +
115325 + if (!missing_fn_head)
115326 + return new_function;
115327 +
115328 + new_function->next = missing_fn_head;
115329 + return new_function;
115330 +}
115331 +
115332 +/* If the function is missing from the hash table and it is a static function
115333 + * then create a next_cgraph_node from it for handle_function()
115334 + */
115335 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
115336 +{
115337 + unsigned int num;
115338 + const_tree orig_fndecl;
115339 + struct cgraph_node *next_node = NULL;
115340 +
115341 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
115342 +
115343 + num = get_function_num(missing_fn_head->node, orig_fndecl);
115344 + if (num == CANNOT_FIND_ARG)
115345 + return cnodes;
115346 +
115347 + if (!is_missing_function(orig_fndecl, num))
115348 + return cnodes;
115349 +
115350 + next_node = cgraph_get_node(missing_fn_head->fndecl);
115351 + if (next_node && next_node->local.local)
115352 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
115353 + return cnodes;
115354 +}
115355 +
115356 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
115357 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
115358 + */
115359 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
115360 +{
115361 + unsigned int i;
115362 + tree node;
115363 + struct missing_functions *cur, *missing_fn_head = NULL;
115364 +
115365 +#if BUILDING_GCC_VERSION <= 4007
115366 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
115367 +#else
115368 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
115369 +#endif
115370 + switch (TREE_CODE(node)) {
115371 + case PARM_DECL:
115372 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
115373 + break;
115374 + case FUNCTION_DECL:
115375 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
115376 + break;
115377 + default:
115378 + break;
115379 + }
115380 + }
115381 +
115382 + while (missing_fn_head) {
115383 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
115384 +
115385 + cur = missing_fn_head->next;
115386 + free(missing_fn_head);
115387 + missing_fn_head = cur;
115388 + }
115389 +
115390 + return cnodes;
115391 +}
115392 +
115393 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
115394 +{
115395 + gimple phi = get_def_stmt(result);
115396 + unsigned int i, n = gimple_phi_num_args(phi);
115397 +
115398 + pointer_set_insert(visited, phi);
115399 + for (i = 0; i < n; i++) {
115400 + const_tree arg = gimple_phi_arg_def(phi, i);
115401 +
115402 + set_conditions(visited, interesting_conditions, arg);
115403 + }
115404 +}
115405 +
115406 +enum conditions {
115407 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
115408 +};
115409 +
115410 +// Search for constants, cast assignments and binary/ternary assignments
115411 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
115412 +{
115413 + gimple def_stmt = get_def_stmt(lhs);
115414 +
115415 + if (is_gimple_constant(lhs)) {
115416 + interesting_conditions[FROM_CONST] = true;
115417 + return;
115418 + }
115419 +
115420 + if (!def_stmt)
115421 + return;
115422 +
115423 + if (pointer_set_contains(visited, def_stmt))
115424 + return;
115425 +
115426 + switch (gimple_code(def_stmt)) {
115427 + case GIMPLE_CALL:
115428 + if (lhs == gimple_call_lhs(def_stmt))
115429 + interesting_conditions[RET] = true;
115430 + return;
115431 + case GIMPLE_NOP:
115432 + case GIMPLE_ASM:
115433 + return;
115434 + case GIMPLE_PHI:
115435 + interesting_conditions[PHI] = true;
115436 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
115437 + case GIMPLE_ASSIGN:
115438 + if (gimple_num_ops(def_stmt) == 2) {
115439 + const_tree rhs = gimple_assign_rhs1(def_stmt);
115440 +
115441 + if (gimple_assign_cast_p(def_stmt))
115442 + interesting_conditions[CAST] = true;
115443 +
115444 + return set_conditions(visited, interesting_conditions, rhs);
115445 + } else {
115446 + interesting_conditions[NOT_UNARY] = true;
115447 + return;
115448 + }
115449 + default:
115450 + debug_gimple_stmt(def_stmt);
115451 + gcc_unreachable();
115452 + }
115453 +}
115454 +
115455 +// determine whether duplication will be necessary or not.
115456 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
115457 +{
115458 + struct pointer_set_t *visited;
115459 +
115460 + if (gimple_assign_cast_p(cur_node->first_stmt))
115461 + interesting_conditions[CAST] = true;
115462 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
115463 + interesting_conditions[NOT_UNARY] = true;
115464 +
115465 + visited = pointer_set_create();
115466 + set_conditions(visited, interesting_conditions, cur_node->node);
115467 + pointer_set_destroy(visited);
115468 +}
115469 +
115470 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
115471 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
115472 +{
115473 + gimple assign;
115474 + gimple_stmt_iterator gsi;
115475 +
115476 + // already removed
115477 + if (gimple_bb(asm_stmt) == NULL)
115478 + return;
115479 + gsi = gsi_for_stmt(asm_stmt);
115480 +
115481 + assign = gimple_build_assign(lhs, rhs);
115482 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
115483 + SSA_NAME_DEF_STMT(lhs) = assign;
115484 +
115485 + gsi_remove(&gsi, true);
115486 +}
115487 +
115488 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
115489 + * stmt is a return otherwise it is the callee function.
115490 + */
115491 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
115492 +{
115493 + const_tree fndecl;
115494 +
115495 + if (argnum == 0)
115496 + fndecl = current_function_decl;
115497 + else
115498 + fndecl = gimple_call_fndecl(stmt);
115499 +
115500 + if (fndecl == NULL_TREE)
115501 + return NULL_TREE;
115502 +
115503 + return DECL_ORIGIN(fndecl);
115504 +}
115505 +
115506 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115507 +static bool skip_asm(const_tree arg)
115508 +{
115509 + gimple def_stmt = get_def_stmt(arg);
115510 +
115511 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115512 + return false;
115513 +
115514 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115515 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115516 +}
115517 +
115518 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115519 +{
115520 + gimple phi = get_def_stmt(result);
115521 + unsigned int i, n = gimple_phi_num_args(phi);
115522 +
115523 + pointer_set_insert(visited, phi);
115524 + for (i = 0; i < n; i++) {
115525 + tree arg = gimple_phi_arg_def(phi, i);
115526 +
115527 + walk_use_def(visited, cur_node, arg);
115528 + }
115529 +}
115530 +
115531 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115532 +{
115533 + gimple def_stmt = get_def_stmt(lhs);
115534 + tree rhs1, rhs2;
115535 +
115536 + rhs1 = gimple_assign_rhs1(def_stmt);
115537 + rhs2 = gimple_assign_rhs2(def_stmt);
115538 +
115539 + walk_use_def(visited, cur_node, rhs1);
115540 + walk_use_def(visited, cur_node, rhs2);
115541 +}
115542 +
115543 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115544 +{
115545 + unsigned int i;
115546 + tree element;
115547 + enum tree_code code;
115548 +
115549 + gcc_assert(node != NULL_TREE);
115550 +
115551 + if (is_gimple_constant(node))
115552 + return;
115553 +
115554 + code = TREE_CODE(node);
115555 + if (code == VAR_DECL) {
115556 + node = DECL_ORIGIN(node);
115557 + code = TREE_CODE(node);
115558 + }
115559 +
115560 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115561 + return;
115562 +
115563 +#if BUILDING_GCC_VERSION <= 4007
115564 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115565 +#else
115566 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115567 +#endif
115568 + if (operand_equal_p(node, element, 0))
115569 + return;
115570 + }
115571 +
115572 +#if BUILDING_GCC_VERSION <= 4007
115573 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115574 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115575 +#else
115576 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115577 + vec_safe_push(cur_node->last_nodes, node);
115578 +#endif
115579 +}
115580 +
115581 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115582 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115583 +{
115584 + if (!is_size_overflow_asm(stmt))
115585 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115586 +}
115587 +
115588 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115589 + * and component refs (for checking the intentional_overflow attribute).
115590 + */
115591 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115592 +{
115593 + const_gimple def_stmt;
115594 +
115595 + if (TREE_CODE(lhs) != SSA_NAME) {
115596 + insert_last_node(cur_node, lhs);
115597 + return;
115598 + }
115599 +
115600 + def_stmt = get_def_stmt(lhs);
115601 + if (!def_stmt)
115602 + return;
115603 +
115604 + if (pointer_set_insert(visited, def_stmt))
115605 + return;
115606 +
115607 + switch (gimple_code(def_stmt)) {
115608 + case GIMPLE_NOP:
115609 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115610 + case GIMPLE_ASM:
115611 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115612 + case GIMPLE_CALL: {
115613 + tree fndecl = gimple_call_fndecl(def_stmt);
115614 +
115615 + if (fndecl == NULL_TREE)
115616 + return;
115617 + insert_last_node(cur_node, fndecl);
115618 + return;
115619 + }
115620 + case GIMPLE_PHI:
115621 + return walk_use_def_phi(visited, cur_node, lhs);
115622 + case GIMPLE_ASSIGN:
115623 + switch (gimple_num_ops(def_stmt)) {
115624 + case 2:
115625 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115626 + case 3:
115627 + return walk_use_def_binary(visited, cur_node, lhs);
115628 + }
115629 + default:
115630 + debug_gimple_stmt((gimple)def_stmt);
115631 + error("%s: unknown gimple code", __func__);
115632 + gcc_unreachable();
115633 + }
115634 +}
115635 +
115636 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115637 +static void set_last_nodes(struct interesting_node *cur_node)
115638 +{
115639 + struct pointer_set_t *visited;
115640 +
115641 + visited = pointer_set_create();
115642 + walk_use_def(visited, cur_node, cur_node->node);
115643 + pointer_set_destroy(visited);
115644 +}
115645 +
115646 +enum precond {
115647 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115648 +};
115649 +
115650 +/* 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.
115651 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115652 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115653 + * It skips the possible error codes too.
115654 + */
115655 +static enum precond check_preconditions(struct interesting_node *cur_node)
115656 +{
115657 + bool interesting_conditions[5] = {false, false, false, false, false};
115658 +
115659 + set_last_nodes(cur_node);
115660 +
115661 + check_intentional_attribute_ipa(cur_node);
115662 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115663 + return NO_ATTRIBUTE_SEARCH;
115664 +
115665 + search_interesting_conditions(cur_node, interesting_conditions);
115666 +
115667 + // error code: a phi, unary assign (not cast) and returns only
115668 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
115669 + return NO_ATTRIBUTE_SEARCH;
115670 +
115671 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
115672 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
115673 + return NO_ATTRIBUTE_SEARCH;
115674 +
115675 + // unnecessary overflow check
115676 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
115677 + return NO_CHECK_INSERT;
115678 +
115679 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
115680 + return NO_CHECK_INSERT;
115681 +
115682 + return NONE;
115683 +}
115684 +
115685 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
115686 +{
115687 + const_gimple assign;
115688 + tree orig_type = TREE_TYPE(orig_node);
115689 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115690 +
115691 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115692 + return gimple_assign_lhs(assign);
115693 +}
115694 +
115695 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
115696 +{
115697 + void (*set_rhs)(gimple, tree);
115698 + gimple stmt = cur_node->first_stmt;
115699 + const_tree orig_node = cur_node->node;
115700 +
115701 + switch (gimple_code(stmt)) {
115702 + case GIMPLE_RETURN:
115703 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
115704 + break;
115705 + case GIMPLE_CALL:
115706 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
115707 + break;
115708 + case GIMPLE_ASSIGN:
115709 + switch (cur_node->num) {
115710 + case 1:
115711 + set_rhs = &gimple_assign_set_rhs1;
115712 + break;
115713 + case 2:
115714 + set_rhs = &gimple_assign_set_rhs2;
115715 + break;
115716 +#if BUILDING_GCC_VERSION >= 4006
115717 + case 3:
115718 + set_rhs = &gimple_assign_set_rhs3;
115719 + break;
115720 +#endif
115721 + default:
115722 + gcc_unreachable();
115723 + }
115724 +
115725 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
115726 + break;
115727 + default:
115728 + debug_gimple_stmt(stmt);
115729 + gcc_unreachable();
115730 + }
115731 +
115732 + update_stmt(stmt);
115733 +}
115734 +
115735 +static struct visited *create_visited(void)
115736 +{
115737 + struct visited *new_node;
115738 +
115739 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
115740 + new_node->stmts = pointer_set_create();
115741 + new_node->my_stmts = pointer_set_create();
115742 + new_node->skip_expr_casts = pointer_set_create();
115743 + new_node->no_cast_check = pointer_set_create();
115744 + return new_node;
115745 +}
115746 +
115747 +static void free_visited(struct visited *visited)
115748 +{
115749 + pointer_set_destroy(visited->stmts);
115750 + pointer_set_destroy(visited->my_stmts);
115751 + pointer_set_destroy(visited->skip_expr_casts);
115752 + pointer_set_destroy(visited->no_cast_check);
115753 +
115754 + free(visited);
115755 +}
115756 +
115757 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
115758 + * 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
115759 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
115760 + */
115761 +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)
115762 +{
115763 + enum precond ret;
115764 + tree new_node, orig_node = cur_node->node;
115765 +
115766 + ret = check_preconditions(cur_node);
115767 + if (ret == NO_ATTRIBUTE_SEARCH)
115768 + return cnodes;
115769 +
115770 + cnodes = search_overflow_attribute(cnodes, cur_node);
115771 +
115772 + if (ret == NO_CHECK_INSERT)
115773 + return cnodes;
115774 +
115775 + new_node = expand(visited, caller_node, orig_node);
115776 + if (new_node == NULL_TREE)
115777 + return cnodes;
115778 +
115779 + change_orig_node(visited, cur_node, new_node);
115780 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
115781 +
115782 + return cnodes;
115783 +}
115784 +
115785 +// Check visited_fns interesting nodes.
115786 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
115787 +{
115788 + struct interesting_node *cur;
115789 +
115790 + for (cur = head; cur; cur = cur->next) {
115791 + if (!operand_equal_p(node, cur->node, 0))
115792 + continue;
115793 + if (num != cur->num)
115794 + continue;
115795 + if (first_stmt == cur->first_stmt)
115796 + return true;
115797 + }
115798 + return false;
115799 +}
115800 +
115801 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115802 + 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
115803 + 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
115804 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115805 + num: arg count of a call stmt or 0 when it is a ret
115806 + node: the recursion starts from here, it is a call arg or a return value
115807 + 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.
115808 + intentional_attr_decl: intentional_overflow attribute of the callee function
115809 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115810 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115811 + */
115812 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115813 +{
115814 + struct interesting_node *new_node;
115815 + tree fndecl;
115816 + enum gimple_code code;
115817 +
115818 + gcc_assert(node != NULL_TREE);
115819 + code = gimple_code(first_stmt);
115820 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115821 +
115822 + if (num == CANNOT_FIND_ARG)
115823 + return head;
115824 +
115825 + if (skip_types(node))
115826 + return head;
115827 +
115828 + if (skip_asm(node))
115829 + return head;
115830 +
115831 + if (is_gimple_call(first_stmt))
115832 + fndecl = gimple_call_fndecl(first_stmt);
115833 + else
115834 + fndecl = current_function_decl;
115835 +
115836 + if (fndecl == NULL_TREE)
115837 + return head;
115838 +
115839 + if (is_in_interesting_node(head, first_stmt, node, num))
115840 + return head;
115841 +
115842 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
115843 +
115844 + new_node->next = NULL;
115845 + new_node->first_stmt = first_stmt;
115846 +#if BUILDING_GCC_VERSION <= 4007
115847 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
115848 +#else
115849 + vec_alloc(new_node->last_nodes, VEC_LEN);
115850 +#endif
115851 + new_node->num = num;
115852 + new_node->node = node;
115853 + new_node->fndecl = fndecl;
115854 + new_node->intentional_attr_decl = MARK_NO;
115855 + new_node->intentional_attr_cur_fndecl = MARK_NO;
115856 + new_node->intentional_mark_from_gimple = asm_stmt;
115857 +
115858 + if (!head)
115859 + return new_node;
115860 +
115861 + new_node->next = head;
115862 + return new_node;
115863 +}
115864 +
115865 +/* 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).
115866 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
115867 + */
115868 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115869 +{
115870 + struct next_cgraph_node *cur_node;
115871 + tree ret = gimple_return_retval(stmt);
115872 +
115873 + if (ret == NULL_TREE)
115874 + return head;
115875 +
115876 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115877 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
115878 + continue;
115879 + if (cur_node->num == 0)
115880 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
115881 + }
115882 +
115883 + return head;
115884 +}
115885 +
115886 +/* 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).
115887 + * If the call stmt is in the next cgraph node list then it's an interesting call.
115888 + */
115889 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115890 +{
115891 + unsigned int argnum;
115892 + tree arg;
115893 + const_tree fndecl;
115894 + struct next_cgraph_node *cur_node;
115895 +
115896 + fndecl = gimple_call_fndecl(stmt);
115897 + if (fndecl == NULL_TREE)
115898 + return head;
115899 +
115900 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115901 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
115902 + continue;
115903 + argnum = get_correct_arg_count(cur_node->num, fndecl);
115904 + gcc_assert(argnum != CANNOT_FIND_ARG);
115905 + if (argnum == 0)
115906 + continue;
115907 +
115908 + arg = gimple_call_arg(stmt, argnum - 1);
115909 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
115910 + }
115911 +
115912 + return head;
115913 +}
115914 +
115915 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
115916 +{
115917 + if (!operand_equal_p(orig_node, node, 0))
115918 + return WRONG_NODE;
115919 + if (skip_types(node))
115920 + return WRONG_NODE;
115921 + return ret_count;
115922 +}
115923 +
115924 +// Get the index of the rhs node in an assignment
115925 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
115926 +{
115927 + const_tree rhs1, rhs2;
115928 + unsigned int ret;
115929 +
115930 + gcc_assert(stmt);
115931 + gcc_assert(is_gimple_assign(stmt));
115932 +
115933 + rhs1 = gimple_assign_rhs1(stmt);
115934 + gcc_assert(rhs1 != NULL_TREE);
115935 +
115936 + switch (gimple_num_ops(stmt)) {
115937 + case 2:
115938 + return check_ops(node, rhs1, 1);
115939 + case 3:
115940 + ret = check_ops(node, rhs1, 1);
115941 + if (ret != WRONG_NODE)
115942 + return ret;
115943 +
115944 + rhs2 = gimple_assign_rhs2(stmt);
115945 + gcc_assert(rhs2 != NULL_TREE);
115946 + return check_ops(node, rhs2, 2);
115947 + default:
115948 + gcc_unreachable();
115949 + }
115950 +}
115951 +
115952 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
115953 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
115954 +{
115955 + unsigned int i;
115956 +
115957 + if (gimple_call_fndecl(stmt) == NULL_TREE)
115958 + return CANNOT_FIND_ARG;
115959 +
115960 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
115961 + tree node;
115962 +
115963 + node = gimple_call_arg(stmt, i);
115964 + if (!operand_equal_p(arg, node, 0))
115965 + continue;
115966 + if (!skip_types(node))
115967 + return i + 1;
115968 + }
115969 +
115970 + return CANNOT_FIND_ARG;
115971 +}
115972 +
115973 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
115974 + * any of return, call or assignment stmts (because of inlining).
115975 + */
115976 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
115977 +{
115978 + use_operand_p use_p;
115979 + imm_use_iterator imm_iter;
115980 + unsigned int argnum;
115981 +
115982 + gcc_assert(TREE_CODE(node) == SSA_NAME);
115983 +
115984 + if (pointer_set_insert(visited, node))
115985 + return head;
115986 +
115987 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115988 + gimple stmt = USE_STMT(use_p);
115989 +
115990 + if (stmt == NULL)
115991 + return head;
115992 + if (is_gimple_debug(stmt))
115993 + continue;
115994 +
115995 + switch (gimple_code(stmt)) {
115996 + case GIMPLE_CALL:
115997 + argnum = find_arg_number_gimple(node, stmt);
115998 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115999 + break;
116000 + case GIMPLE_RETURN:
116001 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116002 + break;
116003 + case GIMPLE_ASSIGN:
116004 + argnum = get_assign_ops_count(stmt, node);
116005 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116006 + break;
116007 + case GIMPLE_PHI: {
116008 + tree result = gimple_phi_result(stmt);
116009 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116010 + break;
116011 + }
116012 + case GIMPLE_ASM:
116013 + if (gimple_asm_noutputs(stmt) != 0)
116014 + break;
116015 + if (!is_size_overflow_asm(stmt))
116016 + break;
116017 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116018 + break;
116019 + case GIMPLE_COND:
116020 + case GIMPLE_SWITCH:
116021 + break;
116022 + default:
116023 + debug_gimple_stmt(stmt);
116024 + gcc_unreachable();
116025 + break;
116026 + }
116027 + }
116028 + return head;
116029 +}
116030 +
116031 +static void remove_size_overflow_asm(gimple stmt)
116032 +{
116033 + gimple_stmt_iterator gsi;
116034 + tree input, output;
116035 +
116036 + if (!is_size_overflow_asm(stmt))
116037 + return;
116038 +
116039 + if (gimple_asm_noutputs(stmt) == 0) {
116040 + gsi = gsi_for_stmt(stmt);
116041 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116042 + gsi_remove(&gsi, true);
116043 + return;
116044 + }
116045 +
116046 + input = gimple_asm_input_op(stmt, 0);
116047 + output = gimple_asm_output_op(stmt, 0);
116048 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116049 +}
116050 +
116051 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116052 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116053 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116054 + */
116055 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116056 +{
116057 + const_tree output;
116058 + struct pointer_set_t *visited;
116059 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116060 +
116061 + if (!is_size_overflow_asm(stmt))
116062 + return head;
116063 +
116064 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116065 + intentional_asm = stmt;
116066 +
116067 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116068 +
116069 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116070 + return head;
116071 +
116072 + if (gimple_asm_noutputs(stmt) == 0) {
116073 + const_tree input;
116074 +
116075 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116076 + return head;
116077 +
116078 + input = gimple_asm_input_op(stmt, 0);
116079 + remove_size_overflow_asm(stmt);
116080 + if (is_gimple_constant(TREE_VALUE(input)))
116081 + return head;
116082 + visited = pointer_set_create();
116083 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116084 + pointer_set_destroy(visited);
116085 + return head;
116086 + }
116087 +
116088 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116089 + remove_size_overflow_asm(stmt);
116090 +
116091 + visited = pointer_set_create();
116092 + output = gimple_asm_output_op(stmt, 0);
116093 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116094 + pointer_set_destroy(visited);
116095 + return head;
116096 +}
116097 +
116098 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116099 + * or a call stmt or a return stmt and store them in the interesting_node list
116100 + */
116101 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116102 +{
116103 + basic_block bb;
116104 + struct interesting_node *head = NULL;
116105 +
116106 + FOR_ALL_BB_FN(bb, cfun) {
116107 + gimple_stmt_iterator gsi;
116108 +
116109 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116110 + enum gimple_code code;
116111 + gimple stmt = gsi_stmt(gsi);
116112 +
116113 + code = gimple_code(stmt);
116114 +
116115 + if (code == GIMPLE_ASM)
116116 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116117 +
116118 + if (!next_node)
116119 + continue;
116120 + if (code == GIMPLE_CALL)
116121 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116122 + if (code == GIMPLE_RETURN)
116123 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116124 + }
116125 + }
116126 + return head;
116127 +}
116128 +
116129 +static void free_interesting_node(struct interesting_node *head)
116130 +{
116131 + struct interesting_node *cur;
116132 +
116133 + while (head) {
116134 + cur = head->next;
116135 +#if BUILDING_GCC_VERSION <= 4007
116136 + VEC_free(tree, gc, head->last_nodes);
116137 +#else
116138 + vec_free(head->last_nodes);
116139 +#endif
116140 + free(head);
116141 + head = cur;
116142 + }
116143 +}
116144 +
116145 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116146 +{
116147 + struct visited_fns *new_visited_fns;
116148 +
116149 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116150 + new_visited_fns->fndecl = cur_node->fndecl;
116151 + new_visited_fns->num = cur_node->num;
116152 + new_visited_fns->first_stmt = cur_node->first_stmt;
116153 + new_visited_fns->next = NULL;
116154 +
116155 + if (!head)
116156 + return new_visited_fns;
116157 +
116158 + new_visited_fns->next = head;
116159 + return new_visited_fns;
116160 +}
116161 +
116162 +/* 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
116163 + * it is a visited_fns function.
116164 + */
116165 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116166 +{
116167 + struct visited_fns *cur;
116168 +
116169 + if (!head)
116170 + return false;
116171 +
116172 + for (cur = head; cur; cur = cur->next) {
116173 + if (cur_node->first_stmt != cur->first_stmt)
116174 + continue;
116175 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116176 + continue;
116177 + if (cur_node->num == cur->num)
116178 + return true;
116179 + }
116180 + return false;
116181 +}
116182 +
116183 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116184 +{
116185 + struct next_cgraph_node *cur;
116186 +
116187 + while (head) {
116188 + cur = head->next;
116189 + free(head);
116190 + head = cur;
116191 + }
116192 +}
116193 +
116194 +static void remove_all_size_overflow_asm(void)
116195 +{
116196 + basic_block bb;
116197 +
116198 + FOR_ALL_BB_FN(bb, cfun) {
116199 + gimple_stmt_iterator si;
116200 +
116201 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116202 + remove_size_overflow_asm(gsi_stmt(si));
116203 + }
116204 +}
116205 +
116206 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116207 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116208 + * the newly collected interesting functions (they are interesting if there is control flow between
116209 + * the interesting stmts and them).
116210 + */
116211 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116212 +{
116213 + struct visited *visited;
116214 + struct interesting_node *head, *cur_node;
116215 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116216 +
116217 + set_current_function_decl(NODE_DECL(node));
116218 + call_count = 0;
116219 +
116220 + head = collect_interesting_stmts(next_node);
116221 +
116222 + visited = create_visited();
116223 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116224 + if (is_visited_fns_function(visited_fns, cur_node))
116225 + continue;
116226 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116227 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116228 + }
116229 +
116230 + free_visited(visited);
116231 + free_interesting_node(head);
116232 + remove_all_size_overflow_asm();
116233 + unset_current_function_decl();
116234 +
116235 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116236 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116237 +
116238 + free_next_cgraph_node(cnodes_head);
116239 + return visited_fns;
116240 +}
116241 +
116242 +static void free_visited_fns(struct visited_fns *head)
116243 +{
116244 + struct visited_fns *cur;
116245 +
116246 + while (head) {
116247 + cur = head->next;
116248 + free(head);
116249 + head = cur;
116250 + }
116251 +}
116252 +
116253 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116254 +unsigned int search_function(void)
116255 +{
116256 + struct cgraph_node *node;
116257 + struct visited_fns *visited_fns = NULL;
116258 +
116259 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116260 + gcc_assert(cgraph_function_flags_ready);
116261 +#if BUILDING_GCC_VERSION <= 4007
116262 + gcc_assert(node->reachable);
116263 +#endif
116264 +
116265 + visited_fns = handle_function(node, NULL, visited_fns);
116266 + }
116267 +
116268 + free_visited_fns(visited_fns);
116269 + return 0;
116270 +}
116271 +
116272 +#if BUILDING_GCC_VERSION >= 4009
116273 +static const struct pass_data insert_size_overflow_check_data = {
116274 +#else
116275 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116276 + .pass = {
116277 +#endif
116278 + .type = SIMPLE_IPA_PASS,
116279 + .name = "size_overflow",
116280 +#if BUILDING_GCC_VERSION >= 4008
116281 + .optinfo_flags = OPTGROUP_NONE,
116282 +#endif
116283 +#if BUILDING_GCC_VERSION >= 4009
116284 + .has_gate = false,
116285 + .has_execute = true,
116286 +#else
116287 + .gate = NULL,
116288 + .execute = search_function,
116289 + .sub = NULL,
116290 + .next = NULL,
116291 + .static_pass_number = 0,
116292 +#endif
116293 + .tv_id = TV_NONE,
116294 + .properties_required = 0,
116295 + .properties_provided = 0,
116296 + .properties_destroyed = 0,
116297 + .todo_flags_start = 0,
116298 + .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,
116299 +#if BUILDING_GCC_VERSION < 4009
116300 + },
116301 + .generate_summary = NULL,
116302 + .write_summary = NULL,
116303 + .read_summary = NULL,
116304 +#if BUILDING_GCC_VERSION >= 4006
116305 + .write_optimization_summary = NULL,
116306 + .read_optimization_summary = NULL,
116307 +#endif
116308 + .stmt_fixup = NULL,
116309 + .function_transform_todo_flags_start = 0,
116310 + .function_transform = NULL,
116311 + .variable_transform = NULL,
116312 +#endif
116313 +};
116314 +
116315 +#if BUILDING_GCC_VERSION >= 4009
116316 +namespace {
116317 +class insert_size_overflow_check : public ipa_opt_pass_d {
116318 +public:
116319 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116320 + unsigned int execute() { return search_function(); }
116321 +};
116322 +}
116323 +#endif
116324 +
116325 +struct opt_pass *make_insert_size_overflow_check(void)
116326 +{
116327 +#if BUILDING_GCC_VERSION >= 4009
116328 + return new insert_size_overflow_check();
116329 +#else
116330 + return &insert_size_overflow_check.pass;
116331 +#endif
116332 +}
116333 +
116334 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116335 new file mode 100644
116336 index 0000000..d71d72a
116337 --- /dev/null
116338 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116339 @@ -0,0 +1,736 @@
116340 +/*
116341 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116342 + * Licensed under the GPL v2, or (at your option) v3
116343 + *
116344 + * Homepage:
116345 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116346 + *
116347 + * Documentation:
116348 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116349 + *
116350 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116351 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116352 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116353 + *
116354 + * Usage:
116355 + * $ make
116356 + * $ make run
116357 + */
116358 +
116359 +#include "gcc-common.h"
116360 +#include "size_overflow.h"
116361 +
116362 +/* Get the param of the intentional_overflow attribute.
116363 + * * 0: MARK_NOT_INTENTIONAL
116364 + * * 1..MAX_PARAM: MARK_YES
116365 + * * -1: MARK_TURN_OFF
116366 + */
116367 +static tree get_attribute_param(const_tree decl)
116368 +{
116369 + const_tree attr;
116370 +
116371 + if (decl == NULL_TREE)
116372 + return NULL_TREE;
116373 +
116374 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116375 + if (!attr || !TREE_VALUE(attr))
116376 + return NULL_TREE;
116377 +
116378 + return TREE_VALUE(attr);
116379 +}
116380 +
116381 +// MARK_TURN_OFF
116382 +bool is_turn_off_intentional_attr(const_tree decl)
116383 +{
116384 + const_tree param_head;
116385 +
116386 + param_head = get_attribute_param(decl);
116387 + if (param_head == NULL_TREE)
116388 + return false;
116389 +
116390 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116391 + return true;
116392 + return false;
116393 +}
116394 +
116395 +// MARK_NOT_INTENTIONAL
116396 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116397 +{
116398 + const_tree param_head;
116399 +
116400 + if (argnum == 0)
116401 + return false;
116402 +
116403 + param_head = get_attribute_param(decl);
116404 + if (param_head == NULL_TREE)
116405 + return false;
116406 +
116407 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116408 + return true;
116409 + return false;
116410 +}
116411 +
116412 +// MARK_YES
116413 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116414 +{
116415 + tree param, param_head;
116416 +
116417 + if (argnum == 0)
116418 + return false;
116419 +
116420 + param_head = get_attribute_param(decl);
116421 + for (param = param_head; param; param = TREE_CHAIN(param))
116422 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116423 + return true;
116424 + return false;
116425 +}
116426 +
116427 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116428 +{
116429 + location_t loc;
116430 +
116431 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116432 + return;
116433 +
116434 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116435 + return;
116436 +
116437 + loc = DECL_SOURCE_LOCATION(decl);
116438 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116439 +}
116440 +
116441 +// Get the field decl of a component ref for intentional_overflow checking
116442 +static const_tree search_field_decl(const_tree comp_ref)
116443 +{
116444 + const_tree field = NULL_TREE;
116445 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116446 +
116447 + for (i = 0; i < len; i++) {
116448 + field = TREE_OPERAND(comp_ref, i);
116449 + if (TREE_CODE(field) == FIELD_DECL)
116450 + break;
116451 + }
116452 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116453 + return field;
116454 +}
116455 +
116456 +/* Get the type of the intentional_overflow attribute of a node
116457 + * * MARK_TURN_OFF
116458 + * * MARK_YES
116459 + * * MARK_NO
116460 + * * MARK_NOT_INTENTIONAL
116461 + */
116462 +enum mark get_intentional_attr_type(const_tree node)
116463 +{
116464 + const_tree cur_decl;
116465 +
116466 + if (node == NULL_TREE)
116467 + return MARK_NO;
116468 +
116469 + switch (TREE_CODE(node)) {
116470 + case COMPONENT_REF:
116471 + cur_decl = search_field_decl(node);
116472 + if (is_turn_off_intentional_attr(cur_decl))
116473 + return MARK_TURN_OFF;
116474 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116475 + return MARK_YES;
116476 + break;
116477 + case PARM_DECL: {
116478 + unsigned int argnum;
116479 +
116480 + cur_decl = DECL_ORIGIN(current_function_decl);
116481 + argnum = find_arg_number_tree(node, cur_decl);
116482 + if (argnum == CANNOT_FIND_ARG)
116483 + return MARK_NO;
116484 + if (is_yes_intentional_attr(cur_decl, argnum))
116485 + return MARK_YES;
116486 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116487 + return MARK_NOT_INTENTIONAL;
116488 + break;
116489 + }
116490 + case FUNCTION_DECL:
116491 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116492 + return MARK_TURN_OFF;
116493 + break;
116494 + default:
116495 + break;
116496 + }
116497 + return MARK_NO;
116498 +}
116499 +
116500 +// Search for the intentional_overflow attribute on the last nodes
116501 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116502 +{
116503 + unsigned int i;
116504 + tree last_node;
116505 + enum mark mark = MARK_NO;
116506 +
116507 +#if BUILDING_GCC_VERSION <= 4007
116508 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116509 +#else
116510 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116511 +#endif
116512 + mark = get_intentional_attr_type(last_node);
116513 + if (mark != MARK_NO)
116514 + break;
116515 + }
116516 + return mark;
116517 +}
116518 +
116519 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116520 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116521 + */
116522 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116523 +{
116524 + if (!cur_node->intentional_mark_from_gimple)
116525 + return false;
116526 +
116527 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116528 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116529 + else
116530 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116531 +
116532 + // skip param decls
116533 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116534 + return true;
116535 + return true;
116536 +}
116537 +
116538 +/* Search intentional_overflow attribute on caller and on callee too.
116539 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116540 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116541 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116542 +*/
116543 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116544 +{
116545 + const_tree fndecl;
116546 +
116547 + if (is_intentional_attribute_from_gimple(cur_node))
116548 + return;
116549 +
116550 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116551 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116552 + return;
116553 + }
116554 +
116555 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116556 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116557 + return;
116558 + }
116559 +
116560 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116561 + return;
116562 +
116563 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116564 + if (is_turn_off_intentional_attr(fndecl)) {
116565 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116566 + return;
116567 + }
116568 +
116569 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116570 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116571 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116572 + cur_node->intentional_attr_decl = MARK_YES;
116573 +
116574 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116575 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116576 +}
116577 +
116578 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
116579 +{
116580 + const_tree rhs1, lhs, rhs1_type, lhs_type;
116581 + enum machine_mode lhs_mode, rhs_mode;
116582 + gimple def_stmt = get_def_stmt(no_const_rhs);
116583 +
116584 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116585 + return false;
116586 +
116587 + rhs1 = gimple_assign_rhs1(def_stmt);
116588 + lhs = gimple_assign_lhs(def_stmt);
116589 + rhs1_type = TREE_TYPE(rhs1);
116590 + lhs_type = TREE_TYPE(lhs);
116591 + rhs_mode = TYPE_MODE(rhs1_type);
116592 + lhs_mode = TYPE_MODE(lhs_type);
116593 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
116594 + return false;
116595 +
116596 + return true;
116597 +}
116598 +
116599 +static unsigned int uses_num(tree node)
116600 +{
116601 + imm_use_iterator imm_iter;
116602 + use_operand_p use_p;
116603 + unsigned int num = 0;
116604 +
116605 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116606 + gimple use_stmt = USE_STMT(use_p);
116607 +
116608 + if (use_stmt == NULL)
116609 + return num;
116610 + if (is_gimple_debug(use_stmt))
116611 + continue;
116612 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
116613 + continue;
116614 + num++;
116615 + }
116616 + return num;
116617 +}
116618 +
116619 +static bool no_uses(tree node)
116620 +{
116621 + return !uses_num(node);
116622 +}
116623 +
116624 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
116625 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
116626 +{
116627 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
116628 + gimple def_stmt = get_def_stmt(lhs);
116629 +
116630 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116631 + return false;
116632 +
116633 + rhs1 = gimple_assign_rhs1(def_stmt);
116634 + rhs_type = TREE_TYPE(rhs1);
116635 + lhs_type = TREE_TYPE(lhs);
116636 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
116637 + return false;
116638 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
116639 + return false;
116640 +
116641 + def_stmt = get_def_stmt(rhs1);
116642 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
116643 + return false;
116644 +
116645 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
116646 + return false;
116647 +
116648 + rhs1 = gimple_assign_rhs1(def_stmt);
116649 + rhs2 = gimple_assign_rhs2(def_stmt);
116650 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
116651 + return false;
116652 +
116653 + if (is_gimple_constant(rhs2))
116654 + not_const_rhs = rhs1;
116655 + else
116656 + not_const_rhs = rhs2;
116657 +
116658 + return no_uses(not_const_rhs);
116659 +}
116660 +
116661 +static bool is_lt_signed_type_max(const_tree rhs)
116662 +{
116663 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
116664 +
116665 + if (!TYPE_UNSIGNED(type))
116666 + return true;
116667 +
116668 + switch (TYPE_MODE(type)) {
116669 + case QImode:
116670 + new_type = intQI_type_node;
116671 + break;
116672 + case HImode:
116673 + new_type = intHI_type_node;
116674 + break;
116675 + case SImode:
116676 + new_type = intSI_type_node;
116677 + break;
116678 + case DImode:
116679 + new_type = intDI_type_node;
116680 + break;
116681 + default:
116682 + debug_tree((tree)type);
116683 + gcc_unreachable();
116684 + }
116685 +
116686 + type_max = TYPE_MAX_VALUE(new_type);
116687 + if (!tree_int_cst_lt(type_max, rhs))
116688 + return true;
116689 +
116690 + return false;
116691 +}
116692 +
116693 +static bool is_gt_zero(const_tree rhs)
116694 +{
116695 + const_tree type = TREE_TYPE(rhs);
116696 +
116697 + if (TYPE_UNSIGNED(type))
116698 + return true;
116699 +
116700 + if (!tree_int_cst_lt(rhs, integer_zero_node))
116701 + return true;
116702 +
116703 + return false;
116704 +}
116705 +
116706 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
116707 +{
116708 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
116709 + return false;
116710 + if (!is_gimple_constant(rhs))
116711 + return false;
116712 +
116713 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
116714 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
116715 + return false;
116716 +
116717 + return true;
116718 +}
116719 +
116720 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
116721 +{
116722 + gimple assign;
116723 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116724 + tree origtype = TREE_TYPE(orig_rhs);
116725 +
116726 + gcc_assert(is_gimple_assign(stmt));
116727 +
116728 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116729 + pointer_set_insert(visited->my_stmts, assign);
116730 + return gimple_assign_lhs(assign);
116731 +}
116732 +
116733 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
116734 +{
116735 + tree new_rhs, orig_rhs;
116736 + void (*gimple_assign_set_rhs)(gimple, tree);
116737 + tree rhs1 = gimple_assign_rhs1(stmt);
116738 + tree rhs2 = gimple_assign_rhs2(stmt);
116739 + tree lhs = gimple_assign_lhs(stmt);
116740 +
116741 + if (!check_overflow)
116742 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116743 +
116744 + if (change_rhs == NULL_TREE)
116745 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116746 +
116747 + if (new_rhs2 == NULL_TREE) {
116748 + orig_rhs = rhs1;
116749 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116750 + } else {
116751 + orig_rhs = rhs2;
116752 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116753 + }
116754 +
116755 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116756 +
116757 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
116758 + gimple_assign_set_rhs(stmt, new_rhs);
116759 + update_stmt(stmt);
116760 +
116761 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116762 +}
116763 +
116764 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
116765 +{
116766 + gimple rhs1_def_stmt, rhs2_def_stmt;
116767 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116768 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116769 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116770 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116771 +
116772 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116773 + return false;
116774 +
116775 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116776 +
116777 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116778 + return false;
116779 +
116780 + rhs1_def_stmt = get_def_stmt(rhs1);
116781 + rhs2_def_stmt = get_def_stmt(rhs2);
116782 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116783 + return false;
116784 +
116785 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116786 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116787 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116788 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116789 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116790 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116791 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116792 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116793 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116794 + return false;
116795 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116796 + return false;
116797 +
116798 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
116799 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
116800 + return true;
116801 +}
116802 +
116803 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
116804 +{
116805 + gimple assign;
116806 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116807 + tree type = TREE_TYPE(rhs1);
116808 + tree lhs = create_new_var(type);
116809 +
116810 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
116811 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
116812 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
116813 +
116814 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
116815 + update_stmt(assign);
116816 + pointer_set_insert(visited->my_stmts, assign);
116817 + return assign;
116818 +}
116819 +
116820 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
116821 +{
116822 + gimple_stmt_iterator gsi;
116823 + gimple cast_stmt;
116824 + tree type = TREE_TYPE(node);
116825 +
116826 + if (types_compatible_p(type, intTI_type_node))
116827 + return node;
116828 +
116829 + gsi = gsi_for_stmt(stmt);
116830 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116831 + pointer_set_insert(visited->my_stmts, cast_stmt);
116832 + return gimple_assign_lhs(cast_stmt);
116833 +}
116834 +
116835 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
116836 +{
116837 + tree rhs1, def_stmt_rhs1;
116838 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
116839 +
116840 + def_stmt = get_def_stmt(var);
116841 + if (!gimple_assign_cast_p(def_stmt))
116842 + return NULL_TREE;
116843 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
116844 +
116845 + rhs1 = gimple_assign_rhs1(def_stmt);
116846 + rhs1_def_stmt = get_def_stmt(rhs1);
116847 + if (!gimple_assign_cast_p(rhs1_def_stmt))
116848 + return rhs1;
116849 +
116850 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116851 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
116852 +
116853 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
116854 + case GIMPLE_CALL:
116855 + case GIMPLE_NOP:
116856 + case GIMPLE_ASM:
116857 + case GIMPLE_PHI:
116858 + return def_stmt_rhs1;
116859 + case GIMPLE_ASSIGN:
116860 + return rhs1;
116861 + default:
116862 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
116863 + gcc_unreachable();
116864 + }
116865 +}
116866 +
116867 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
116868 +{
116869 + tree new_rhs1, new_rhs2;
116870 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116871 + gimple assign, stmt = get_def_stmt(lhs);
116872 + tree rhs1 = gimple_assign_rhs1(stmt);
116873 + tree rhs2 = gimple_assign_rhs2(stmt);
116874 +
116875 + if (!is_subtraction_special(visited, stmt))
116876 + return NULL_TREE;
116877 +
116878 + new_rhs1 = expand(visited, caller_node, rhs1);
116879 + new_rhs2 = expand(visited, caller_node, rhs2);
116880 +
116881 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
116882 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
116883 +
116884 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116885 + return NULL_TREE;
116886 +
116887 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116888 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
116889 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
116890 + }
116891 +
116892 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116893 + new_lhs = gimple_assign_lhs(assign);
116894 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116895 +
116896 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116897 +}
116898 +
116899 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116900 +{
116901 + const_gimple def_stmt;
116902 +
116903 + if (TREE_CODE(rhs) != SSA_NAME)
116904 + return false;
116905 +
116906 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116907 + return false;
116908 +
116909 + def_stmt = get_def_stmt(rhs);
116910 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116911 + return false;
116912 +
116913 + return true;
116914 +}
116915 +
116916 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
116917 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
116918 + * fffffff * 16 > signed max -> truncate
116919 + */
116920 +static bool look_for_mult_and_add(const_gimple stmt)
116921 +{
116922 + const_tree res;
116923 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
116924 + const_gimple def_stmt;
116925 +
116926 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
116927 + return false;
116928 + if (!is_gimple_assign(stmt))
116929 + return false;
116930 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
116931 + return false;
116932 +
116933 + rhs1 = gimple_assign_rhs1(stmt);
116934 + rhs2 = gimple_assign_rhs2(stmt);
116935 + if (is_gimple_constant(rhs1)) {
116936 + const_rhs = rhs1;
116937 + def_stmt = get_def_stmt(rhs2);
116938 + } else if (is_gimple_constant(rhs2)) {
116939 + const_rhs = rhs2;
116940 + def_stmt = get_def_stmt(rhs1);
116941 + } else
116942 + return false;
116943 +
116944 + if (!is_gimple_assign(def_stmt))
116945 + return false;
116946 +
116947 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
116948 + return false;
116949 +
116950 + def_rhs1 = gimple_assign_rhs1(def_stmt);
116951 + def_rhs2 = gimple_assign_rhs2(def_stmt);
116952 + if (is_gimple_constant(def_rhs1))
116953 + def_const_rhs = def_rhs1;
116954 + else if (is_gimple_constant(def_rhs2))
116955 + def_const_rhs = def_rhs2;
116956 + else
116957 + return false;
116958 +
116959 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
116960 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
116961 + return false;
116962 + return true;
116963 +}
116964 +
116965 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
116966 +{
116967 + const_gimple def_stmt_1, def_stmt_2;
116968 + const_tree rhs1, rhs2;
116969 + bool add_mul_rhs1, add_mul_rhs2;
116970 +
116971 + rhs1 = gimple_assign_rhs1(stmt);
116972 + def_stmt_1 = get_def_stmt(rhs1);
116973 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
116974 +
116975 + rhs2 = gimple_assign_rhs2(stmt);
116976 + def_stmt_2 = get_def_stmt(rhs2);
116977 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
116978 +
116979 + if (add_mul_rhs1)
116980 + return RHS1_INTENTIONAL_OVERFLOW;
116981 + if (add_mul_rhs2)
116982 + return RHS2_INTENTIONAL_OVERFLOW;
116983 + return NO_INTENTIONAL_OVERFLOW;
116984 +}
116985 +
116986 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
116987 +{
116988 + gimple my_stmt;
116989 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116990 +
116991 + gsi_next(&gsi);
116992 + my_stmt = gsi_stmt(gsi);
116993 +
116994 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
116995 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
116996 +
116997 + return my_stmt;
116998 +}
116999 +
117000 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117001 + * unsigned type cast to signed type, unsigned type: no more uses
117002 + * e.g., lib/vsprintf.c:simple_strtol()
117003 + * _10 = (unsigned long int) _9
117004 + * _11 = -_10;
117005 + * _12 = (long int) _11; (_11_ no more uses)
117006 + */
117007 +static bool is_call_or_cast(gimple stmt)
117008 +{
117009 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117010 +}
117011 +
117012 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117013 +{
117014 + const_tree rhs;
117015 + gimple def_stmt;
117016 +
117017 + if (node == NULL_TREE)
117018 + return true;
117019 + if (is_gimple_constant(node))
117020 + return true;
117021 +
117022 + def_stmt = get_def_stmt(node);
117023 + if (!def_stmt)
117024 + return false;
117025 +
117026 + if (is_call_or_cast(def_stmt))
117027 + return true;
117028 +
117029 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117030 + return false;
117031 + rhs = gimple_assign_rhs1(def_stmt);
117032 + def_stmt = get_def_stmt(rhs);
117033 + if (!def_stmt)
117034 + return false;
117035 + return is_call_or_cast(def_stmt);
117036 +}
117037 +
117038 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117039 +{
117040 + unsigned int use_num;
117041 + gimple so_stmt;
117042 + const_gimple def_stmt;
117043 + const_tree rhs1, rhs2;
117044 + tree rhs = gimple_assign_rhs1(stmt);
117045 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117046 + const_tree rhs_type = TREE_TYPE(rhs);
117047 +
117048 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117049 + return;
117050 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117051 + return;
117052 + use_num = uses_num(rhs);
117053 + if (use_num != 1)
117054 + return;
117055 +
117056 + def_stmt = get_def_stmt(rhs);
117057 + if (!def_stmt)
117058 + return;
117059 + if (!is_gimple_assign(def_stmt))
117060 + return;
117061 +
117062 + rhs1 = gimple_assign_rhs1(def_stmt);
117063 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117064 + return;
117065 +
117066 + rhs2 = gimple_assign_rhs2(def_stmt);
117067 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117068 + return;
117069 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117070 + return;
117071 +
117072 + so_stmt = get_dup_stmt(visited, stmt);
117073 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117074 +}
117075 +
117076 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117077 new file mode 100644
117078 index 0000000..4bddad2
117079 --- /dev/null
117080 +++ b/tools/gcc/size_overflow_plugin/misc.c
117081 @@ -0,0 +1,203 @@
117082 +/*
117083 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117084 + * Licensed under the GPL v2, or (at your option) v3
117085 + *
117086 + * Homepage:
117087 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117088 + *
117089 + * Documentation:
117090 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117091 + *
117092 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117093 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117094 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117095 + *
117096 + * Usage:
117097 + * $ make
117098 + * $ make run
117099 + */
117100 +
117101 +#include "gcc-common.h"
117102 +#include "size_overflow.h"
117103 +
117104 +void set_current_function_decl(tree fndecl)
117105 +{
117106 + gcc_assert(fndecl != NULL_TREE);
117107 +
117108 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117109 + calculate_dominance_info(CDI_DOMINATORS);
117110 + current_function_decl = fndecl;
117111 +}
117112 +
117113 +void unset_current_function_decl(void)
117114 +{
117115 + free_dominance_info(CDI_DOMINATORS);
117116 + pop_cfun();
117117 + current_function_decl = NULL_TREE;
117118 +}
117119 +
117120 +static bool is_bool(const_tree node)
117121 +{
117122 + const_tree type;
117123 +
117124 + if (node == NULL_TREE)
117125 + return false;
117126 +
117127 + type = TREE_TYPE(node);
117128 + if (!INTEGRAL_TYPE_P(type))
117129 + return false;
117130 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117131 + return true;
117132 + if (TYPE_PRECISION(type) == 1)
117133 + return true;
117134 + return false;
117135 +}
117136 +
117137 +bool skip_types(const_tree var)
117138 +{
117139 + tree type;
117140 + enum tree_code code;
117141 +
117142 + if (is_gimple_constant(var))
117143 + return true;
117144 +
117145 + switch (TREE_CODE(var)) {
117146 + case ADDR_EXPR:
117147 +#if BUILDING_GCC_VERSION >= 4006
117148 + case MEM_REF:
117149 +#endif
117150 + case ARRAY_REF:
117151 + case BIT_FIELD_REF:
117152 + case INDIRECT_REF:
117153 + case TARGET_MEM_REF:
117154 + case COMPONENT_REF:
117155 + case VAR_DECL:
117156 + case VIEW_CONVERT_EXPR:
117157 + return true;
117158 + default:
117159 + break;
117160 + }
117161 +
117162 + code = TREE_CODE(var);
117163 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117164 +
117165 + type = TREE_TYPE(var);
117166 + switch (TREE_CODE(type)) {
117167 + case INTEGER_TYPE:
117168 + case ENUMERAL_TYPE:
117169 + return false;
117170 + case BOOLEAN_TYPE:
117171 + return is_bool(var);
117172 + default:
117173 + return true;
117174 + }
117175 +}
117176 +
117177 +gimple get_def_stmt(const_tree node)
117178 +{
117179 + gcc_assert(node != NULL_TREE);
117180 +
117181 + if (skip_types(node))
117182 + return NULL;
117183 +
117184 + if (TREE_CODE(node) != SSA_NAME)
117185 + return NULL;
117186 + return SSA_NAME_DEF_STMT(node);
117187 +}
117188 +
117189 +tree create_new_var(tree type)
117190 +{
117191 + tree new_var = create_tmp_var(type, "cicus");
117192 +
117193 + add_referenced_var(new_var);
117194 + return new_var;
117195 +}
117196 +
117197 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117198 +{
117199 + const_gimple def_stmt = get_def_stmt(rhs);
117200 +
117201 + if (force)
117202 + return false;
117203 +
117204 + if (is_gimple_constant(rhs))
117205 + return false;
117206 +
117207 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117208 + return false;
117209 +
117210 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117211 + return false;
117212 +
117213 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117214 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117215 + return false;
117216 +
117217 + return true;
117218 +}
117219 +
117220 +tree cast_a_tree(tree type, tree var)
117221 +{
117222 + gcc_assert(type != NULL_TREE);
117223 + gcc_assert(var != NULL_TREE);
117224 + gcc_assert(fold_convertible_p(type, var));
117225 +
117226 + return fold_convert(type, var);
117227 +}
117228 +
117229 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117230 +{
117231 + gimple assign, def_stmt;
117232 +
117233 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117234 + gcc_assert(!is_gimple_constant(rhs));
117235 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117236 + gcc_unreachable();
117237 +
117238 + def_stmt = get_def_stmt(rhs);
117239 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117240 + return def_stmt;
117241 +
117242 + if (lhs == CREATE_NEW_VAR)
117243 + lhs = create_new_var(dst_type);
117244 +
117245 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117246 +
117247 + if (!gsi_end_p(*gsi)) {
117248 + location_t loc = gimple_location(gsi_stmt(*gsi));
117249 + gimple_set_location(assign, loc);
117250 + }
117251 +
117252 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117253 +
117254 + if (before)
117255 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117256 + else
117257 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117258 + update_stmt(assign);
117259 + return assign;
117260 +}
117261 +
117262 +bool is_size_overflow_type(const_tree var)
117263 +{
117264 + const char *name;
117265 + const_tree type_name, type;
117266 +
117267 + if (var == NULL_TREE)
117268 + return false;
117269 +
117270 + type = TREE_TYPE(var);
117271 + type_name = TYPE_NAME(type);
117272 + if (type_name == NULL_TREE)
117273 + return false;
117274 +
117275 + if (DECL_P(type_name))
117276 + name = DECL_NAME_POINTER(type_name);
117277 + else
117278 + name = IDENTIFIER_POINTER(type_name);
117279 +
117280 + if (!strncmp(name, "size_overflow_type", 18))
117281 + return true;
117282 + return false;
117283 +}
117284 +
117285 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117286 new file mode 100644
117287 index 0000000..7c9e6d1
117288 --- /dev/null
117289 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117290 @@ -0,0 +1,138 @@
117291 +/*
117292 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117293 + * Licensed under the GPL v2, or (at your option) v3
117294 + *
117295 + * Homepage:
117296 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117297 + *
117298 + * Documentation:
117299 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117300 + *
117301 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117302 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117303 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117304 + *
117305 + * Usage:
117306 + * $ make
117307 + * $ make run
117308 + */
117309 +
117310 +#include "gcc-common.h"
117311 +#include "size_overflow.h"
117312 +
117313 +bool skip_expr_on_double_type(const_gimple stmt)
117314 +{
117315 + enum tree_code code = gimple_assign_rhs_code(stmt);
117316 +
117317 + switch (code) {
117318 + case RSHIFT_EXPR:
117319 + case TRUNC_DIV_EXPR:
117320 + case CEIL_DIV_EXPR:
117321 + case FLOOR_DIV_EXPR:
117322 + case ROUND_DIV_EXPR:
117323 + case EXACT_DIV_EXPR:
117324 + case RDIV_EXPR:
117325 + case TRUNC_MOD_EXPR:
117326 + case CEIL_MOD_EXPR:
117327 + case FLOOR_MOD_EXPR:
117328 + case ROUND_MOD_EXPR:
117329 + return true;
117330 + default:
117331 + return false;
117332 + }
117333 +}
117334 +
117335 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
117336 +{
117337 + const_tree orig_rhs1;
117338 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
117339 + gimple down_cast, up_cast;
117340 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
117341 +
117342 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117343 + down_lhs = gimple_assign_lhs(down_cast);
117344 +
117345 + gsi = gsi_for_stmt(use_stmt);
117346 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117347 + new_lhs = gimple_assign_lhs(up_cast);
117348 +
117349 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
117350 + if (operand_equal_p(orig_rhs1, rhs, 0))
117351 + gimple_assign_set_rhs1(use_stmt, new_lhs);
117352 + else
117353 + gimple_assign_set_rhs2(use_stmt, new_lhs);
117354 + update_stmt(use_stmt);
117355 +
117356 + pointer_set_insert(visited->my_stmts, up_cast);
117357 + pointer_set_insert(visited->my_stmts, down_cast);
117358 + pointer_set_insert(visited->skip_expr_casts, up_cast);
117359 + pointer_set_insert(visited->skip_expr_casts, down_cast);
117360 +}
117361 +
117362 +static tree get_proper_unsigned_half_type(const_tree node)
117363 +{
117364 + tree new_type, type;
117365 +
117366 + gcc_assert(is_size_overflow_type(node));
117367 +
117368 + type = TREE_TYPE(node);
117369 + switch (TYPE_MODE(type)) {
117370 + case HImode:
117371 + new_type = unsigned_intQI_type_node;
117372 + break;
117373 + case SImode:
117374 + new_type = unsigned_intHI_type_node;
117375 + break;
117376 + case DImode:
117377 + new_type = unsigned_intSI_type_node;
117378 + break;
117379 + case TImode:
117380 + new_type = unsigned_intDI_type_node;
117381 + break;
117382 + default:
117383 + gcc_unreachable();
117384 + }
117385 +
117386 + if (TYPE_QUALS(type) != 0)
117387 + return build_qualified_type(new_type, TYPE_QUALS(type));
117388 + return new_type;
117389 +}
117390 +
117391 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
117392 +{
117393 + tree type;
117394 +
117395 + if (rhs == NULL_TREE)
117396 + return;
117397 + if (!is_size_overflow_type(rhs))
117398 + return;
117399 +
117400 + type = get_proper_unsigned_half_type(rhs);
117401 + if (is_gimple_constant(rhs))
117402 + return;
117403 + create_up_and_down_cast(visited, stmt, type, rhs);
117404 +}
117405 +
117406 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
117407 +{
117408 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
117409 + return;
117410 + gcc_assert(is_size_overflow_type(rhs));
117411 + insert_cast_rhs(visited, stmt, rhs);
117412 +}
117413 +
117414 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
117415 +{
117416 + tree rhs1, rhs2;
117417 +
117418 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
117419 + rhs1 = gimple_assign_rhs1(stmt);
117420 + insert_cast(visited, stmt, rhs1);
117421 + }
117422 +
117423 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
117424 + rhs2 = gimple_assign_rhs2(stmt);
117425 + insert_cast(visited, stmt, rhs2);
117426 + }
117427 +}
117428 +
117429 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
117430 new file mode 100644
117431 index 0000000..e5b4e50
117432 --- /dev/null
117433 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
117434 @@ -0,0 +1,127 @@
117435 +#ifndef SIZE_OVERFLOW_H
117436 +#define SIZE_OVERFLOW_H
117437 +
117438 +#define CREATE_NEW_VAR NULL_TREE
117439 +#define CANNOT_FIND_ARG 32
117440 +#define MAX_PARAM 31
117441 +#define BEFORE_STMT true
117442 +#define AFTER_STMT false
117443 +
117444 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
117445 +#define YES_ASM_STR "# size_overflow MARK_YES "
117446 +#define OK_ASM_STR "# size_overflow "
117447 +
117448 +enum mark {
117449 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
117450 +};
117451 +
117452 +enum intentional_overflow_type {
117453 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
117454 +};
117455 +
117456 +struct visited {
117457 + struct pointer_set_t *stmts;
117458 + struct pointer_set_t *my_stmts;
117459 + struct pointer_set_t *skip_expr_casts;
117460 + struct pointer_set_t *no_cast_check;
117461 +};
117462 +
117463 +// size_overflow_plugin.c
117464 +extern tree report_size_overflow_decl;
117465 +extern tree size_overflow_type_HI;
117466 +extern tree size_overflow_type_SI;
117467 +extern tree size_overflow_type_DI;
117468 +extern tree size_overflow_type_TI;
117469 +
117470 +
117471 +// size_overflow_plugin_hash.c
117472 +struct size_overflow_hash {
117473 + const struct size_overflow_hash * const next;
117474 + const char * const name;
117475 + const unsigned int param;
117476 +};
117477 +
117478 +struct interesting_node {
117479 + struct interesting_node *next;
117480 + gimple first_stmt;
117481 + const_tree fndecl;
117482 + tree node;
117483 +#if BUILDING_GCC_VERSION <= 4007
117484 + VEC(tree, gc) *last_nodes;
117485 +#else
117486 + vec<tree, va_gc> *last_nodes;
117487 +#endif
117488 + unsigned int num;
117489 + enum mark intentional_attr_decl;
117490 + enum mark intentional_attr_cur_fndecl;
117491 + gimple intentional_mark_from_gimple;
117492 +};
117493 +
117494 +extern bool is_size_overflow_asm(const_gimple stmt);
117495 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
117496 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
117497 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
117498 +extern bool is_a_return_check(const_tree node);
117499 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
117500 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
117501 +
117502 +
117503 +// size_overflow_debug.c
117504 +extern struct opt_pass *make_dump_pass(void);
117505 +
117506 +
117507 +// intentional_overflow.c
117508 +extern enum mark get_intentional_attr_type(const_tree node);
117509 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
117510 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
117511 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
117512 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
117513 +extern bool is_turn_off_intentional_attr(const_tree decl);
117514 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
117515 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
117516 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
117517 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
117518 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
117519 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
117520 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
117521 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
117522 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
117523 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
117524 +
117525 +
117526 +// insert_size_overflow_check_ipa.c
117527 +extern unsigned int search_function(void);
117528 +extern unsigned int call_count;
117529 +extern struct opt_pass *make_insert_size_overflow_check(void);
117530 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
117531 +
117532 +
117533 +// insert_size_overflow_asm.c
117534 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
117535 +
117536 +
117537 +// misc.c
117538 +extern void set_current_function_decl(tree fndecl);
117539 +extern void unset_current_function_decl(void);
117540 +extern gimple get_def_stmt(const_tree node);
117541 +extern tree create_new_var(tree type);
117542 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
117543 +extern bool skip_types(const_tree var);
117544 +extern tree cast_a_tree(tree type, tree var);
117545 +extern bool is_size_overflow_type(const_tree var);
117546 +
117547 +
117548 +// insert_size_overflow_check_core.c
117549 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
117550 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
117551 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
117552 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
117553 +
117554 +
117555 +// remove_unnecessary_dup.c
117556 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
117557 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
117558 +extern bool skip_expr_on_double_type(const_gimple stmt);
117559 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
117560 +
117561 +#endif
117562 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117563 new file mode 100644
117564 index 0000000..4378111
117565 --- /dev/null
117566 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117567 @@ -0,0 +1,116 @@
117568 +/*
117569 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117570 + * Licensed under the GPL v2, or (at your option) v3
117571 + *
117572 + * Homepage:
117573 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117574 + *
117575 + * Documentation:
117576 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117577 + *
117578 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117579 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117580 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117581 + *
117582 + * Usage:
117583 + * $ make
117584 + * $ make run
117585 + */
117586 +
117587 +#include "gcc-common.h"
117588 +
117589 +static unsigned int dump_functions(void)
117590 +{
117591 + struct cgraph_node *node;
117592 +
117593 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117594 + basic_block bb;
117595 +
117596 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
117597 + current_function_decl = NODE_DECL(node);
117598 +
117599 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
117600 +
117601 + FOR_ALL_BB_FN(bb, cfun) {
117602 + gimple_stmt_iterator si;
117603 +
117604 + fprintf(stderr, "<bb %u>:\n", bb->index);
117605 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117606 + debug_gimple_stmt(gsi_stmt(si));
117607 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117608 + debug_gimple_stmt(gsi_stmt(si));
117609 + fprintf(stderr, "\n");
117610 + }
117611 +
117612 + fprintf(stderr, "-------------------------------------------------------------------------\n");
117613 +
117614 + pop_cfun();
117615 + current_function_decl = NULL_TREE;
117616 + }
117617 +
117618 + fprintf(stderr, "###############################################################################\n");
117619 +
117620 + return 0;
117621 +}
117622 +
117623 +#if BUILDING_GCC_VERSION >= 4009
117624 +static const struct pass_data dump_pass_data = {
117625 +#else
117626 +static struct ipa_opt_pass_d dump_pass = {
117627 + .pass = {
117628 +#endif
117629 + .type = SIMPLE_IPA_PASS,
117630 + .name = "dump",
117631 +#if BUILDING_GCC_VERSION >= 4008
117632 + .optinfo_flags = OPTGROUP_NONE,
117633 +#endif
117634 +#if BUILDING_GCC_VERSION >= 4009
117635 + .has_gate = false,
117636 + .has_execute = true,
117637 +#else
117638 + .gate = NULL,
117639 + .execute = dump_functions,
117640 + .sub = NULL,
117641 + .next = NULL,
117642 + .static_pass_number = 0,
117643 +#endif
117644 + .tv_id = TV_NONE,
117645 + .properties_required = 0,
117646 + .properties_provided = 0,
117647 + .properties_destroyed = 0,
117648 + .todo_flags_start = 0,
117649 + .todo_flags_finish = 0,
117650 +#if BUILDING_GCC_VERSION < 4009
117651 + },
117652 + .generate_summary = NULL,
117653 + .write_summary = NULL,
117654 + .read_summary = NULL,
117655 +#if BUILDING_GCC_VERSION >= 4006
117656 + .write_optimization_summary = NULL,
117657 + .read_optimization_summary = NULL,
117658 +#endif
117659 + .stmt_fixup = NULL,
117660 + .function_transform_todo_flags_start = 0,
117661 + .function_transform = NULL,
117662 + .variable_transform = NULL,
117663 +#endif
117664 +};
117665 +
117666 +#if BUILDING_GCC_VERSION >= 4009
117667 +namespace {
117668 +class dump_pass : public ipa_opt_pass_d {
117669 +public:
117670 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117671 + unsigned int execute() { return dump_functions(); }
117672 +};
117673 +}
117674 +#endif
117675 +
117676 +struct opt_pass *make_dump_pass(void)
117677 +{
117678 +#if BUILDING_GCC_VERSION >= 4009
117679 + return new dump_pass();
117680 +#else
117681 + return &dump_pass.pass;
117682 +#endif
117683 +}
117684 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
117685 new file mode 100644
117686 index 0000000..f527934
117687 --- /dev/null
117688 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
117689 @@ -0,0 +1,5911 @@
117690 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
117691 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
117692 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
117693 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
117694 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
117695 +padzero_55 padzero 1 55 &sel_read_policyvers_55
117696 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
117697 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
117698 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
117699 +load_msg_95 load_msg 2 95 NULL
117700 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
117701 +init_q_132 init_q 4 132 NULL
117702 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
117703 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
117704 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
117705 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
117706 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
117707 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
117708 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
117709 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
117710 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
117711 +br_port_info_size_268 br_port_info_size 0 268 NULL
117712 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
117713 +SYSC_connect_304 SYSC_connect 3 304 NULL
117714 +syslog_print_307 syslog_print 2 307 NULL
117715 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
117716 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
117717 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
117718 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
117719 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
117720 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
117721 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
117722 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
117723 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
117724 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
117725 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
117726 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
117727 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
117728 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
117729 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
117730 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
117731 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
117732 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
117733 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
117734 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
117735 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
117736 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
117737 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
117738 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
117739 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
117740 +unlink_queued_645 unlink_queued 4 645 NULL
117741 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
117742 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
117743 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
117744 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
117745 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
117746 +dvb_video_write_754 dvb_video_write 3 754 NULL
117747 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
117748 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
117749 +if_writecmd_815 if_writecmd 2 815 NULL
117750 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
117751 +error_state_read_859 error_state_read 6 859 NULL
117752 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
117753 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
117754 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
117755 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
117756 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
117757 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
117758 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
117759 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
117760 +readreg_1017 readreg 0-1 1017 NULL
117761 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
117762 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
117763 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
117764 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
117765 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
117766 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
117767 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
117768 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
117769 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
117770 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
117771 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
117772 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
117773 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
117774 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
117775 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
117776 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
117777 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
117778 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
117779 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
117780 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
117781 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
117782 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
117783 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
117784 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
117785 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
117786 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
117787 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
117788 +ffs_1322 ffs 0 1322 NULL
117789 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
117790 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
117791 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
117792 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
117793 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
117794 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
117795 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
117796 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
117797 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
117798 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
117799 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
117800 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
117801 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
117802 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
117803 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
117804 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
117805 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
117806 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
117807 +fpregs_set_1497 fpregs_set 4 1497 NULL
117808 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
117809 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
117810 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
117811 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
117812 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
117813 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
117814 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
117815 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
117816 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
117817 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
117818 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
117819 +rmap_add_1677 rmap_add 3 1677 NULL
117820 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
117821 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
117822 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
117823 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
117824 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
117825 +internal_create_group_1733 internal_create_group 0 1733 NULL
117826 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
117827 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
117828 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
117829 +cosa_write_1774 cosa_write 3 1774 NULL
117830 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
117831 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
117832 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
117833 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
117834 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
117835 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
117836 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
117837 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
117838 +azx_get_position_1927 azx_get_position 0 1927 NULL
117839 +bdev_erase_1933 bdev_erase 3 1933 NULL
117840 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
117841 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
117842 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
117843 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
117844 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
117845 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
117846 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
117847 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
117848 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
117849 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
117850 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
117851 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
117852 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
117853 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
117854 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
117855 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
117856 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
117857 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
117858 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
117859 +audit_expand_2098 audit_expand 0 2098 NULL
117860 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
117861 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
117862 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
117863 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
117864 +enable_read_2117 enable_read 3 2117 NULL
117865 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
117866 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
117867 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
117868 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
117869 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
117870 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
117871 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
117872 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
117873 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
117874 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
117875 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
117876 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
117877 +do_update_counters_2259 do_update_counters 4 2259 NULL
117878 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
117879 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
117880 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
117881 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
117882 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
117883 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
117884 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
117885 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
117886 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
117887 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
117888 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
117889 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
117890 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
117891 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
117892 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
117893 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
117894 +raid1_size_2419 raid1_size 0-2 2419 NULL
117895 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
117896 +wiphy_new_2482 wiphy_new 2 2482 NULL
117897 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
117898 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
117899 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
117900 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
117901 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
117902 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
117903 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
117904 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
117905 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
117906 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
117907 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
117908 +slot_bytes_2609 slot_bytes 0 2609 NULL
117909 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
117910 +switch_status_2629 switch_status 5 2629 NULL
117911 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
117912 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
117913 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
117914 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
117915 +oti6858_write_2692 oti6858_write 4 2692 NULL
117916 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
117917 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
117918 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
117919 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
117920 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
117921 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
117922 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
117923 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
117924 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
117925 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
117926 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
117927 +sock_create_2838 sock_create 0 2838 NULL
117928 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
117929 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
117930 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
117931 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
117932 +nla_padlen_2883 nla_padlen 1 2883 NULL
117933 +cmm_write_2896 cmm_write 3 2896 NULL
117934 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
117935 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
117936 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
117937 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
117938 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
117939 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
117940 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
117941 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
117942 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
117943 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
117944 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
117945 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
117946 +depth_write_3021 depth_write 3 3021 NULL
117947 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
117948 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
117949 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
117950 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
117951 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
117952 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
117953 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
117954 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
117955 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
117956 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
117957 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
117958 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
117959 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
117960 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
117961 +rb_alloc_3102 rb_alloc 1 3102 NULL
117962 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
117963 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
117964 +print_time_3132 print_time 0 3132 NULL
117965 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
117966 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
117967 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
117968 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
117969 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
117970 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
117971 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
117972 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
117973 +alloc_context_3194 alloc_context 1 3194 NULL
117974 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
117975 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
117976 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
117977 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
117978 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
117979 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
117980 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
117981 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
117982 +key_key_read_3241 key_key_read 3 3241 NULL
117983 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
117984 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
117985 +cgroup_name_3300 cgroup_name 3 3300 NULL
117986 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
117987 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
117988 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
117989 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
117990 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
117991 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
117992 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
117993 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
117994 +scnprintf_3360 scnprintf 0-2 3360 NULL
117995 +sr_read_3366 sr_read 3 3366 NULL
117996 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
117997 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
117998 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
117999 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118000 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118001 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118002 +softsynth_write_3455 softsynth_write 3 3455 NULL
118003 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118004 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118005 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118006 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118007 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118008 +SyS_readv_3539 SyS_readv 3 3539 NULL
118009 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118010 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118011 +evtchn_read_3569 evtchn_read 3 3569 NULL
118012 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118013 +vc_resize_3585 vc_resize 3-2 3585 NULL
118014 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118015 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118016 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118017 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118018 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118019 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118020 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118021 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118022 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118023 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118024 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118025 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118026 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118027 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118028 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118029 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118030 +get_fd_set_3866 get_fd_set 1 3866 NULL
118031 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118032 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118033 +nvram_write_3894 nvram_write 3 3894 NULL
118034 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118035 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118036 +vcs_write_3910 vcs_write 3 3910 NULL
118037 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118038 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118039 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118040 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118041 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118042 +do_add_counters_3992 do_add_counters 3 3992 NULL
118043 +userspace_status_4004 userspace_status 4 4004 NULL
118044 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118045 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118046 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118047 +blk_end_request_4024 blk_end_request 3 4024 NULL
118048 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118049 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118050 +read_file_queues_4078 read_file_queues 3 4078 NULL
118051 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118052 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118053 +tm6000_read_4151 tm6000_read 3 4151 NULL
118054 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118055 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118056 +get_alua_req_4166 get_alua_req 3 4166 NULL
118057 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118058 +read_file_bool_4180 read_file_bool 3 4180 NULL
118059 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118060 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118061 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118062 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118063 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118064 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118065 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118066 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118067 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118068 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118069 +count_strings_4315 count_strings 0 4315 NULL
118070 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118071 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118072 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118073 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118074 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118075 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118076 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118077 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118078 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118079 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118080 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118081 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118082 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118083 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118084 +set_link_security_4502 set_link_security 4 4502 NULL
118085 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118086 +tty_register_device_4544 tty_register_device 2 4544 NULL
118087 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118088 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118089 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118090 +bch_alloc_4593 bch_alloc 1 4593 NULL
118091 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118092 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118093 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118094 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118095 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118096 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118097 +kone_receive_4690 kone_receive 4 4690 NULL
118098 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118099 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118100 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118101 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118102 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118103 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118104 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118105 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118106 +create_subvol_4791 create_subvol 4 4791 NULL
118107 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118108 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118109 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118110 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118111 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118112 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118113 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118114 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118115 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118116 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118117 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118118 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118119 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118120 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118121 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118122 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118123 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118124 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118125 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118126 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118127 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118128 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118129 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118130 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118131 +sound_write_5102 sound_write 3 5102 NULL
118132 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118133 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118134 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118135 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118136 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118137 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118138 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118139 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118140 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118141 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118142 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118143 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118144 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118145 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118146 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118147 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118148 +cq_free_res_5355 cq_free_res 5 5355 NULL
118149 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118150 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118151 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118152 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118153 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118154 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118155 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118156 +tty_write_5494 tty_write 3 5494 NULL
118157 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118158 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118159 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118160 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118161 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118162 +le_readq_5557 le_readq 0 5557 NULL
118163 +inw_5558 inw 0 5558 NULL
118164 +bioset_create_5580 bioset_create 1 5580 NULL
118165 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118166 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118167 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118168 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118169 +get_arg_5694 get_arg 3 5694 NULL
118170 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118171 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118172 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118173 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118174 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118175 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
118176 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118177 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118178 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118179 +setup_req_5848 setup_req 3 5848 NULL
118180 +ria_page_count_5849 ria_page_count 0 5849 NULL
118181 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118182 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118183 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118184 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118185 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118186 +port_show_regs_5904 port_show_regs 3 5904 NULL
118187 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118188 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118189 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118190 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118191 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118192 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118193 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118194 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118195 +SyS_semop_5980 SyS_semop 3 5980 NULL
118196 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118197 +alloc_msg_6072 alloc_msg 1 6072 NULL
118198 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118199 +_random_read_6098 _random_read 3 6098 NULL
118200 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118201 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118202 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118203 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118204 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118205 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118206 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118207 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118208 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118209 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118210 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118211 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118212 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118213 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118214 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118215 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118216 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118217 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118218 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118219 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118220 +serial_port_in_6291 serial_port_in 0 6291 NULL
118221 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118222 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118223 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118224 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118225 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118226 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118227 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118228 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118229 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118230 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118231 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118232 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118233 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118234 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118235 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118236 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118237 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118238 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118239 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118240 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118241 +mei_read_6507 mei_read 3 6507 NULL
118242 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118243 +wdm_read_6549 wdm_read 3 6549 NULL
118244 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118245 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118246 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118247 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118248 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118249 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118250 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118251 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118252 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118253 +mpeg_read_6708 mpeg_read 3 6708 NULL
118254 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118255 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118256 +video_proc_write_6724 video_proc_write 3 6724 NULL
118257 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118258 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118259 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118260 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118261 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118262 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118263 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118264 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118265 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118266 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118267 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118268 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118269 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118270 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118271 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118272 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118273 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118274 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118275 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118276 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118277 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118278 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
118279 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118280 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118281 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118282 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118283 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118284 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118285 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118286 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118287 +request_key_async_6990 request_key_async 4 6990 NULL
118288 +tpl_write_6998 tpl_write 3 6998 NULL
118289 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118290 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118291 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
118292 +wimax_msg_7030 wimax_msg 4 7030 NULL
118293 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
118294 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
118295 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
118296 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
118297 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
118298 +event_enable_read_7074 event_enable_read 3 7074 NULL
118299 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
118300 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
118301 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
118302 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
118303 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
118304 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
118305 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
118306 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
118307 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
118308 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
118309 +get_string_7302 get_string 0 7302 NULL
118310 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
118311 +mgmt_control_7349 mgmt_control 3 7349 NULL
118312 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
118313 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
118314 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
118315 +hweight_long_7388 hweight_long 0-1 7388 NULL
118316 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
118317 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
118318 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
118319 +readb_7401 readb 0 7401 NULL
118320 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
118321 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
118322 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
118323 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
118324 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
118325 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
118326 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
118327 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
118328 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
118329 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
118330 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
118331 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
118332 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
118333 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
118334 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
118335 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
118336 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
118337 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
118338 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
118339 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
118340 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
118341 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
118342 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
118343 +dev_write_7708 dev_write 3 7708 NULL
118344 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
118345 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
118346 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
118347 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
118348 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
118349 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
118350 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
118351 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
118352 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
118353 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
118354 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
118355 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
118356 +config_desc_7878 config_desc 0 7878 NULL
118357 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
118358 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
118359 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
118360 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
118361 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
118362 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
118363 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
118364 +vcs_read_8017 vcs_read 3 8017 NULL
118365 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
118366 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
118367 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
118368 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
118369 +venus_lookup_8121 venus_lookup 4 8121 NULL
118370 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
118371 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
118372 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
118373 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
118374 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
118375 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
118376 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
118377 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
118378 +play_iframe_8219 play_iframe 3 8219 NULL
118379 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
118380 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
118381 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
118382 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
118383 +init_cdev_8274 init_cdev 1 8274 NULL
118384 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
118385 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
118386 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
118387 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
118388 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
118389 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
118390 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
118391 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
118392 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
118393 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
118394 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
118395 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
118396 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
118397 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
118398 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
118399 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
118400 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
118401 +dev_config_8506 dev_config 3 8506 NULL
118402 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
118403 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
118404 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
118405 +user_on_off_8552 user_on_off 2 8552 NULL
118406 +profile_remove_8556 profile_remove 3 8556 NULL
118407 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
118408 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
118409 +tower_write_8580 tower_write 3 8580 NULL
118410 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
118411 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
118412 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
118413 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
118414 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
118415 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
118416 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
118417 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
118418 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
118419 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
118420 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
118421 +arcfb_write_8702 arcfb_write 3 8702 NULL
118422 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
118423 +init_header_8703 init_header 0 8703 &i_size_read_8703
118424 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
118425 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
118426 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
118427 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
118428 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
118429 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
118430 +compound_order_8750 compound_order 0 8750 NULL
118431 +yurex_write_8761 yurex_write 3 8761 NULL
118432 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
118433 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
118434 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
118435 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
118436 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
118437 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
118438 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
118439 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
118440 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
118441 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
118442 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
118443 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
118444 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
118445 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
118446 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
118447 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
118448 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
118449 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
118450 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
118451 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
118452 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
118453 +write_file_ani_8918 write_file_ani 3 8918 NULL
118454 +layout_commit_8926 layout_commit 3 8926 NULL
118455 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
118456 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
118457 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
118458 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
118459 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
118460 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
118461 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
118462 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
118463 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
118464 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
118465 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
118466 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
118467 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
118468 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
118469 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
118470 +nla_put_9042 nla_put 3 9042 NULL
118471 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
118472 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
118473 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
118474 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
118475 +create_queues_9088 create_queues 2-3 9088 NULL
118476 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
118477 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
118478 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
118479 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
118480 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
118481 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
118482 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
118483 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
118484 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
118485 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
118486 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
118487 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
118488 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
118489 +card_send_command_9215 card_send_command 3 9215 NULL
118490 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
118491 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
118492 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
118493 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
118494 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
118495 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
118496 +flakey_status_9274 flakey_status 5 9274 NULL
118497 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
118498 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
118499 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
118500 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
118501 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
118502 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
118503 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
118504 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
118505 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
118506 +read_9397 read 3 9397 NULL
118507 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
118508 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
118509 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
118510 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
118511 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
118512 +get_registers_9470 get_registers 4 9470 NULL nohasharray
118513 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
118514 +crypt_status_9492 crypt_status 5 9492 NULL
118515 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
118516 +lp_write_9511 lp_write 3 9511 NULL
118517 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
118518 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
118519 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
118520 +read_file_dma_9530 read_file_dma 3 9530 NULL
118521 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
118522 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
118523 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
118524 +fw_node_create_9559 fw_node_create 2 9559 NULL
118525 +kobj_map_9566 kobj_map 2-3 9566 NULL
118526 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
118527 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
118528 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
118529 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
118530 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
118531 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
118532 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
118533 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
118534 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
118535 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
118536 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
118537 +dns_query_9676 dns_query 3 9676 NULL
118538 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
118539 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
118540 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
118541 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
118542 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
118543 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
118544 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
118545 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
118546 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
118547 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
118548 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
118549 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
118550 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
118551 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
118552 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
118553 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
118554 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
118555 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
118556 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
118557 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
118558 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
118559 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
118560 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
118561 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
118562 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
118563 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
118564 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
118565 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
118566 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
118567 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
118568 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
118569 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
118570 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
118571 +read_file_misc_9948 read_file_misc 3 9948 NULL
118572 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
118573 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
118574 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
118575 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
118576 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
118577 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
118578 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
118579 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
118580 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
118581 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
118582 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
118583 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
118584 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
118585 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
118586 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
118587 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
118588 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
118589 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
118590 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
118591 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
118592 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
118593 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
118594 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
118595 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
118596 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
118597 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
118598 +read_emulate_10310 read_emulate 2-4 10310 NULL
118599 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
118600 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
118601 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
118602 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
118603 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
118604 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
118605 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
118606 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
118607 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
118608 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
118609 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
118610 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
118611 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
118612 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
118613 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
118614 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
118615 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
118616 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
118617 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
118618 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
118619 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
118620 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
118621 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
118622 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
118623 +otp_read_10594 otp_read 2-4-5 10594 NULL
118624 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
118625 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
118626 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
118627 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
118628 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
118629 +parport_write_10669 parport_write 0 10669 NULL
118630 +edge_write_10692 edge_write 4 10692 NULL
118631 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
118632 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
118633 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
118634 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
118635 +spi_sync_10731 spi_sync 0 10731 NULL
118636 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
118637 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
118638 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
118639 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
118640 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
118641 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
118642 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
118643 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
118644 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
118645 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
118646 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
118647 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
118648 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
118649 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
118650 +get_scq_10897 get_scq 2 10897 NULL
118651 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
118652 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
118653 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
118654 +kobject_add_10919 kobject_add 0 10919 NULL
118655 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
118656 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
118657 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
118658 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
118659 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
118660 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
118661 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
118662 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
118663 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
118664 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
118665 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
118666 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
118667 +count_argc_11083 count_argc 0 11083 NULL
118668 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
118669 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
118670 +page_offset_11120 page_offset 0 11120 NULL
118671 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
118672 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
118673 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
118674 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
118675 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
118676 +of_irq_count_11253 of_irq_count 0 11253 NULL
118677 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
118678 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
118679 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
118680 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
118681 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
118682 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
118683 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
118684 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
118685 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
118686 +construct_key_11329 construct_key 3 11329 NULL nohasharray
118687 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
118688 +next_segment_11330 next_segment 0-2-1 11330 NULL
118689 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
118690 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
118691 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
118692 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
118693 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
118694 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
118695 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
118696 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
118697 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
118698 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
118699 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
118700 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
118701 +str_to_user_11411 str_to_user 2 11411 NULL
118702 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
118703 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
118704 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
118705 +trace_options_read_11419 trace_options_read 3 11419 NULL
118706 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
118707 +bttv_read_11432 bttv_read 3 11432 NULL
118708 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
118709 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
118710 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
118711 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
118712 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
118713 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
118714 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
118715 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
118716 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
118717 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
118718 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
118719 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
118720 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
118721 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
118722 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
118723 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
118724 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
118725 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
118726 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
118727 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
118728 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
118729 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
118730 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
118731 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
118732 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
118733 +split_11691 split 2 11691 NULL
118734 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
118735 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
118736 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
118737 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
118738 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
118739 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
118740 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
118741 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
118742 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
118743 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
118744 +umc_device_register_11824 umc_device_register 0 11824 NULL
118745 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
118746 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
118747 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
118748 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
118749 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
118750 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
118751 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
118752 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
118753 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
118754 +ti_write_11916 ti_write 4 11916 NULL
118755 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
118756 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
118757 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
118758 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
118759 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
118760 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
118761 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
118762 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
118763 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
118764 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
118765 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
118766 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
118767 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
118768 +set_powered_12129 set_powered 4 12129 NULL
118769 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
118770 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
118771 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
118772 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
118773 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
118774 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
118775 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
118776 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
118777 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
118778 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
118779 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
118780 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
118781 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
118782 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
118783 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
118784 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
118785 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
118786 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
118787 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
118788 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
118789 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
118790 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
118791 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
118792 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
118793 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
118794 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
118795 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
118796 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
118797 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
118798 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
118799 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
118800 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
118801 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
118802 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
118803 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
118804 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
118805 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
118806 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
118807 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
118808 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
118809 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
118810 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
118811 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
118812 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
118813 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
118814 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
118815 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
118816 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
118817 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
118818 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
118819 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
118820 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
118821 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
118822 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
118823 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
118824 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
118825 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
118826 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
118827 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
118828 +ivtv_write_12721 ivtv_write 3 12721 NULL
118829 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
118830 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
118831 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
118832 +listxattr_12769 listxattr 3 12769 NULL
118833 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
118834 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
118835 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
118836 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
118837 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
118838 +spidev_sync_12842 spidev_sync 0 12842 NULL
118839 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
118840 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
118841 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
118842 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
118843 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
118844 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
118845 +bm_status_write_12964 bm_status_write 3 12964 NULL
118846 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
118847 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
118848 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
118849 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
118850 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
118851 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
118852 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
118853 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
118854 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
118855 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
118856 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
118857 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
118858 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
118859 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
118860 +blk_update_request_13146 blk_update_request 3 13146 NULL
118861 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
118862 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
118863 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
118864 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
118865 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
118866 +comedi_read_13199 comedi_read 3 13199 NULL
118867 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
118868 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
118869 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
118870 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
118871 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
118872 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
118873 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
118874 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
118875 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
118876 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
118877 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
118878 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
118879 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
118880 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
118881 +sd_major_13294 sd_major 0-1 13294 NULL
118882 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
118883 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
118884 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
118885 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
118886 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
118887 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
118888 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
118889 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
118890 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
118891 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
118892 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
118893 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
118894 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
118895 +data_read_13494 data_read 3 13494 NULL nohasharray
118896 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
118897 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
118898 +core_status_13515 core_status 4 13515 NULL
118899 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
118900 +bm_init_13529 bm_init 2 13529 NULL
118901 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
118902 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
118903 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
118904 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
118905 +cache_write_13589 cache_write 3 13589 NULL
118906 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
118907 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
118908 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
118909 +packet_snd_13634 packet_snd 3 13634 NULL
118910 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
118911 +cache_downcall_13666 cache_downcall 3 13666 NULL
118912 +usb_get_string_13693 usb_get_string 0 13693 NULL
118913 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
118914 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
118915 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
118916 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
118917 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
118918 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
118919 +random_read_13815 random_read 3 13815 NULL
118920 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
118921 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
118922 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
118923 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
118924 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
118925 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
118926 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
118927 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
118928 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
118929 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
118930 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
118931 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
118932 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
118933 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
118934 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
118935 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
118936 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
118937 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
118938 +qcam_read_13977 qcam_read 3 13977 NULL
118939 +dsp_read_13980 dsp_read 2 13980 NULL
118940 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
118941 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
118942 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
118943 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
118944 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
118945 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
118946 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
118947 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
118948 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
118949 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
118950 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
118951 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
118952 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
118953 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
118954 +em_canid_change_14150 em_canid_change 3 14150 NULL
118955 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
118956 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
118957 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
118958 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
118959 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
118960 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
118961 +alloc_async_14208 alloc_async 1 14208 NULL
118962 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
118963 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
118964 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
118965 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
118966 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
118967 +rr_status_14293 rr_status 5 14293 NULL
118968 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
118969 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
118970 +oo_objects_14319 oo_objects 0 14319 NULL
118971 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
118972 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
118973 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
118974 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
118975 +lowpan_read_14369 lowpan_read 3 14369 NULL
118976 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
118977 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
118978 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
118979 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
118980 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
118981 +block_size_14443 block_size 0 14443 NULL
118982 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
118983 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
118984 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
118985 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
118986 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
118987 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
118988 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
118989 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
118990 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
118991 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
118992 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
118993 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
118994 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
118995 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
118996 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
118997 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
118998 +dbJoin_14644 dbJoin 0 14644 NULL
118999 +profile_replace_14652 profile_replace 3 14652 NULL
119000 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119001 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119002 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119003 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119004 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119005 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119006 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119007 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119008 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119009 +vfd_write_14717 vfd_write 3 14717 NULL
119010 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119011 +raid1_resize_14740 raid1_resize 2 14740 NULL
119012 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119013 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119014 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119015 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119016 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119017 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119018 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119019 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119020 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119021 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119022 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119023 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119024 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119025 +lcd_write_14857 lcd_write 3 14857 NULL
119026 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119027 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119028 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119029 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119030 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119031 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119032 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119033 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119034 +queue_cnt_14951 queue_cnt 0 14951 NULL
119035 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119036 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119037 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119038 +setkey_14987 setkey 3 14987 NULL nohasharray
119039 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119040 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119041 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119042 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119043 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119044 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119045 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119046 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119047 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119048 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119049 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119050 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119051 +start_port_15124 start_port 0 15124 NULL
119052 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119053 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119054 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119055 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119056 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119057 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119058 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119059 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119060 +simple_strtol_15273 simple_strtol 0 15273 NULL
119061 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119062 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119063 +ioread16_15342 ioread16 0 15342 NULL
119064 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119065 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119066 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119067 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119068 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119069 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119070 +get_modalias_15406 get_modalias 2 15406 NULL
119071 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119072 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119073 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119074 +memweight_15450 memweight 2 15450 NULL
119075 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119076 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119077 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119078 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119079 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119080 +persistent_status_15574 persistent_status 4 15574 NULL
119081 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119082 +vme_user_write_15587 vme_user_write 3 15587 NULL
119083 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119084 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119085 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119086 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119087 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119088 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119089 +fs_path_add_15648 fs_path_add 3 15648 NULL
119090 +xsd_read_15653 xsd_read 3 15653 NULL
119091 +unix_bind_15668 unix_bind 3 15668 NULL
119092 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119093 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119094 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119095 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119096 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119097 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119098 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119099 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119100 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119101 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119102 +table_size_15851 table_size 0-1-2 15851 NULL
119103 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119104 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119105 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119106 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119107 +power_read_15939 power_read 3 15939 NULL
119108 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119109 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119110 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119111 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119112 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119113 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119114 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119115 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119116 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119117 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119118 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119119 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119120 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119121 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119122 +fsm_init_16134 fsm_init 2 16134 NULL
119123 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119124 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119125 +mapping_level_16188 mapping_level 2-0 16188 NULL
119126 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119127 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119128 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119129 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119130 +create_table_16213 create_table 2 16213 NULL
119131 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119132 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119133 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119134 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119135 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119136 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119137 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119138 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119139 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119140 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119141 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119142 +account_16283 account 0-4-2 16283 NULL nohasharray
119143 +mirror_status_16283 mirror_status 5 16283 &account_16283
119144 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119145 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119146 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119147 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119148 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119149 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119150 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119151 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119152 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119153 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119154 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119155 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119156 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119157 +cmdline_store_16442 cmdline_store 4 16442 NULL
119158 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119159 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119160 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119161 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119162 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119163 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119164 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119165 +raid10_resize_16537 raid10_resize 2 16537 NULL
119166 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119167 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119168 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119169 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119170 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119171 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119172 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119173 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119174 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119175 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119176 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119177 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119178 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119179 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119180 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119181 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119182 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119183 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119184 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119185 +st_write_16874 st_write 3 16874 NULL
119186 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119187 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119188 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119189 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119190 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119191 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119192 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119193 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119194 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119195 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119196 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119197 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119198 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119199 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119200 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119201 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119202 +entry_length_17093 entry_length 0 17093 NULL
119203 +write_mem_17114 write_mem 3 17114 NULL
119204 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119205 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119206 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119207 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119208 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119209 +sep_read_17161 sep_read 3 17161 NULL
119210 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119211 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119212 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119213 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119214 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119215 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119216 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119217 +sync_request_17208 sync_request 2 17208 NULL
119218 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119219 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119220 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119221 +alloc_ep_17269 alloc_ep 1 17269 NULL
119222 +pg_read_17276 pg_read 3 17276 NULL
119223 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119224 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119225 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119226 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119227 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119228 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119229 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119230 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119231 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119232 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119233 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119234 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119235 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119236 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119237 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119238 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119239 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119240 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119241 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119242 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119243 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119244 +qp_free_res_17541 qp_free_res 5 17541 NULL
119245 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119246 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119247 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119248 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119249 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119250 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119251 +osst_execute_17607 osst_execute 7-6 17607 NULL
119252 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119253 +dma_map_page_17628 dma_map_page 0 17628 NULL
119254 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119255 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119256 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119257 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119258 +venus_rename_17707 venus_rename 4-5 17707 NULL
119259 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119260 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119261 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119262 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119263 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119264 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119265 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119266 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119267 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119268 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119269 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119270 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119271 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119272 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119273 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119274 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119275 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119276 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119277 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119278 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119279 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119280 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119281 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119282 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119283 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119284 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119285 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119286 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119287 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119288 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119289 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
119290 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
119291 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
119292 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
119293 +fpregs_get_18066 fpregs_get 4 18066 NULL
119294 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
119295 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
119296 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
119297 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
119298 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
119299 +svc_getnl_18120 svc_getnl 0 18120 NULL
119300 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
119301 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
119302 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
119303 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
119304 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
119305 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
119306 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
119307 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
119308 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
119309 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
119310 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
119311 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
119312 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
119313 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
119314 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
119315 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
119316 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
119317 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
119318 +um_idi_write_18293 um_idi_write 3 18293 NULL
119319 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
119320 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
119321 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
119322 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
119323 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
119324 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
119325 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
119326 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
119327 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
119328 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
119329 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
119330 +ep_io_18367 ep_io 0 18367 NULL
119331 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
119332 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
119333 +ci_role_write_18388 ci_role_write 3 18388 NULL
119334 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
119335 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
119336 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
119337 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
119338 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
119339 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
119340 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
119341 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
119342 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
119343 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
119344 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
119345 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
119346 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
119347 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
119348 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
119349 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
119350 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
119351 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
119352 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
119353 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
119354 +debug_output_18575 debug_output 3 18575 NULL
119355 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
119356 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
119357 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
119358 +from_buffer_18625 from_buffer 3 18625 NULL
119359 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
119360 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
119361 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
119362 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
119363 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
119364 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
119365 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
119366 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
119367 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
119368 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
119369 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
119370 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
119371 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
119372 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
119373 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
119374 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
119375 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
119376 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
119377 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
119378 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
119379 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
119380 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
119381 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
119382 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
119383 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
119384 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
119385 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
119386 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
119387 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
119388 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
119389 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
119390 +huge_page_size_19008 huge_page_size 0 19008 NULL
119391 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
119392 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
119393 +revalidate_19043 revalidate 2 19043 NULL
119394 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
119395 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
119396 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
119397 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
119398 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
119399 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
119400 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
119401 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
119402 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
119403 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
119404 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
119405 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
119406 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
119407 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
119408 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
119409 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
119410 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
119411 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
119412 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
119413 +ucma_query_19260 ucma_query 4 19260 NULL
119414 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
119415 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
119416 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
119417 +qc_capture_19298 qc_capture 3 19298 NULL
119418 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
119419 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
119420 +debug_read_19322 debug_read 3 19322 NULL
119421 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
119422 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
119423 +closure_sub_19359 closure_sub 2 19359 NULL
119424 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
119425 +read_zero_19366 read_zero 3 19366 NULL
119426 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
119427 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
119428 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
119429 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
119430 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
119431 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
119432 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
119433 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
119434 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
119435 +sky2_read16_19475 sky2_read16 0 19475 NULL
119436 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
119437 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
119438 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
119439 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
119440 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
119441 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
119442 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
119443 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
119444 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
119445 +nfsd_read_19568 nfsd_read 5 19568 NULL
119446 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
119447 +bm_status_read_19583 bm_status_read 3 19583 NULL
119448 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
119449 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
119450 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
119451 +parser_init_19651 parser_init 2 19651 NULL
119452 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
119453 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
119454 +read_reg_19723 read_reg 0 19723 NULL
119455 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
119456 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
119457 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
119458 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
119459 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
119460 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
119461 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
119462 +readhscx_19769 readhscx 0 19769 NULL
119463 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
119464 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
119465 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
119466 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
119467 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
119468 +__nla_put_19857 __nla_put 3 19857 NULL
119469 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
119470 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
119471 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
119472 +mangle_name_19923 mangle_name 0 19923 NULL
119473 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
119474 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
119475 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
119476 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
119477 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
119478 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
119479 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
119480 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
119481 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
119482 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
119483 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
119484 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
119485 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
119486 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
119487 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
119488 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
119489 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
119490 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
119491 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
119492 +target_message_20072 target_message 2 20072 NULL
119493 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
119494 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
119495 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
119496 +team_options_register_20091 team_options_register 3 20091 NULL
119497 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
119498 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
119499 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
119500 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
119501 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
119502 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
119503 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
119504 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
119505 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
119506 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
119507 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
119508 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
119509 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
119510 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
119511 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
119512 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
119513 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
119514 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
119515 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
119516 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
119517 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
119518 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
119519 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
119520 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
119521 +read_buf_20469 read_buf 2 20469 NULL
119522 +bio_trim_20472 bio_trim 2 20472 NULL
119523 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
119524 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
119525 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
119526 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
119527 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
119528 +venus_create_20555 venus_create 4 20555 NULL
119529 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
119530 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
119531 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
119532 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
119533 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
119534 +lirc_write_20604 lirc_write 3 20604 NULL
119535 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
119536 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
119537 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
119538 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
119539 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
119540 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
119541 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
119542 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
119543 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
119544 +cpumask_size_20683 cpumask_size 0 20683 NULL
119545 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
119546 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
119547 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
119548 +__maestro_read_20700 __maestro_read 0 20700 NULL
119549 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
119550 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
119551 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
119552 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
119553 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
119554 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
119555 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
119556 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
119557 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
119558 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
119559 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
119560 +edid_write_20797 edid_write 3 20797 NULL
119561 +lowpan_write_20800 lowpan_write 3 20800 NULL
119562 +strndup_user_20819 strndup_user 2 20819 NULL
119563 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
119564 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
119565 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
119566 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
119567 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
119568 +get_name_20855 get_name 4 20855 NULL
119569 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
119570 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
119571 +srq_free_res_20868 srq_free_res 5 20868 NULL
119572 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
119573 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
119574 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
119575 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
119576 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
119577 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
119578 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
119579 +htable_bits_20933 htable_bits 0 20933 NULL
119580 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
119581 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
119582 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
119583 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
119584 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
119585 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
119586 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
119587 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
119588 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
119589 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
119590 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
119591 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
119592 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
119593 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
119594 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
119595 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
119596 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
119597 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
119598 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
119599 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
119600 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
119601 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
119602 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
119603 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
119604 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
119605 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
119606 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
119607 +input_ff_create_21240 input_ff_create 2 21240 NULL
119608 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
119609 +fru_length_21257 fru_length 0 21257 NULL
119610 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
119611 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
119612 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
119613 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
119614 +add_res_range_21310 add_res_range 4 21310 NULL
119615 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
119616 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
119617 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
119618 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
119619 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
119620 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
119621 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
119622 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
119623 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
119624 +insert_ptr_21386 insert_ptr 6 21386 NULL
119625 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
119626 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
119627 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
119628 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
119629 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
119630 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
119631 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
119632 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
119633 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
119634 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
119635 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
119636 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
119637 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
119638 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
119639 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
119640 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
119641 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
119642 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
119643 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
119644 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
119645 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
119646 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
119647 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
119648 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
119649 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
119650 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
119651 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
119652 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
119653 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
119654 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
119655 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
119656 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
119657 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
119658 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
119659 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
119660 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
119661 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
119662 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
119663 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
119664 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
119665 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
119666 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
119667 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
119668 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
119669 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
119670 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
119671 +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
119672 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
119673 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
119674 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
119675 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
119676 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
119677 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
119678 +mem_rw_22085 mem_rw 3 22085 NULL
119679 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
119680 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
119681 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
119682 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
119683 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
119684 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
119685 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
119686 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
119687 +mem_write_22232 mem_write 3 22232 NULL
119688 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
119689 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
119690 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
119691 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
119692 +add_res_tree_22263 add_res_tree 7 22263 NULL
119693 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
119694 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
119695 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
119696 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
119697 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
119698 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
119699 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
119700 +atomic_read_22342 atomic_read 0 22342 NULL
119701 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
119702 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
119703 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
119704 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
119705 +zoran_write_22404 zoran_write 3 22404 NULL
119706 +queue_reply_22416 queue_reply 3 22416 NULL
119707 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
119708 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
119709 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
119710 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
119711 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
119712 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
119713 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
119714 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
119715 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
119716 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
119717 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
119718 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
119719 +snapshot_read_22601 snapshot_read 3 22601 NULL
119720 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
119721 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
119722 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
119723 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
119724 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
119725 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
119726 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
119727 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
119728 +reg_umr_22686 reg_umr 5 22686 NULL
119729 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
119730 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
119731 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
119732 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
119733 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
119734 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
119735 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
119736 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
119737 +print_frame_22769 print_frame 0 22769 NULL
119738 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
119739 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
119740 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
119741 +create_attr_set_22861 create_attr_set 1 22861 NULL
119742 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
119743 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
119744 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
119745 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
119746 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
119747 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
119748 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
119749 +__set_xattr_22923 __set_xattr 0 22923 NULL
119750 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
119751 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
119752 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
119753 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
119754 +vme_get_size_22964 vme_get_size 0 22964 NULL
119755 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
119756 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
119757 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
119758 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
119759 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
119760 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
119761 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
119762 +st_status_23032 st_status 5 23032 NULL
119763 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
119764 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
119765 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
119766 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
119767 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
119768 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
119769 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
119770 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
119771 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
119772 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
119773 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
119774 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
119775 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
119776 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
119777 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
119778 +__clear_user_23118 __clear_user 0-2 23118 NULL
119779 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
119780 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
119781 +read_file_ani_23161 read_file_ani 3 23161 NULL
119782 +usblp_write_23178 usblp_write 3 23178 NULL
119783 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
119784 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
119785 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
119786 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
119787 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
119788 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
119789 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
119790 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
119791 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
119792 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
119793 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
119794 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
119795 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
119796 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
119797 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
119798 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
119799 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
119800 +page_readlink_23346 page_readlink 3 23346 NULL
119801 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
119802 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
119803 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
119804 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
119805 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
119806 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
119807 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
119808 +linear_conf_23485 linear_conf 2 23485 NULL
119809 +event_filter_read_23494 event_filter_read 3 23494 NULL
119810 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
119811 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
119812 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
119813 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
119814 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
119815 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
119816 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
119817 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
119818 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
119819 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
119820 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
119821 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
119822 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
119823 +sInW_23663 sInW 0 23663 NULL
119824 +SyS_connect_23669 SyS_connect 3 23669 NULL
119825 +cx18_read_23699 cx18_read 3 23699 NULL
119826 +at_get_23708 at_get 0 23708 NULL
119827 +get_conn_info_23723 get_conn_info 4 23723 NULL
119828 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
119829 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
119830 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
119831 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
119832 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
119833 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
119834 +map_write_23795 map_write 3 23795 NULL
119835 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
119836 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
119837 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
119838 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
119839 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
119840 +p54_init_common_23850 p54_init_common 1 23850 NULL
119841 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
119842 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
119843 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
119844 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
119845 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
119846 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
119847 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
119848 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
119849 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
119850 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
119851 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
119852 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
119853 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
119854 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
119855 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
119856 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
119857 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
119858 +give_pages_24021 give_pages 3 24021 NULL
119859 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
119860 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
119861 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
119862 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
119863 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
119864 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
119865 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
119866 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
119867 +lov_brw_24122 lov_brw 4 24122 NULL
119868 +mpu401_read_24126 mpu401_read 3 24126 NULL
119869 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
119870 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
119871 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
119872 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
119873 +adu_read_24177 adu_read 3 24177 NULL
119874 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
119875 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
119876 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
119877 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
119878 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
119879 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
119880 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
119881 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
119882 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
119883 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
119884 +thin_status_24278 thin_status 5 24278 NULL
119885 +msg_size_24288 msg_size 0 24288 NULL
119886 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
119887 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
119888 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
119889 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
119890 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
119891 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
119892 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
119893 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
119894 +igetword_24373 igetword 0 24373 NULL
119895 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
119896 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
119897 +getxattr_24398 getxattr 4 24398 NULL nohasharray
119898 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
119899 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
119900 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
119901 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
119902 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
119903 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
119904 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
119905 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
119906 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
119907 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
119908 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
119909 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
119910 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
119911 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
119912 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
119913 +pd_video_read_24510 pd_video_read 3 24510 NULL
119914 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
119915 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
119916 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
119917 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
119918 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
119919 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
119920 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
119921 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
119922 +SyS_poll_24620 SyS_poll 2 24620 NULL
119923 +context_alloc_24645 context_alloc 3 24645 NULL
119924 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
119925 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
119926 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
119927 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
119928 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
119929 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
119930 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
119931 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
119932 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
119933 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
119934 +cache_read_24790 cache_read 3 24790 NULL
119935 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
119936 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
119937 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
119938 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
119939 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
119940 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
119941 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
119942 +queues_read_24877 queues_read 3 24877 NULL
119943 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
119944 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
119945 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
119946 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
119947 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
119948 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
119949 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
119950 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
119951 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
119952 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
119953 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
119954 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
119955 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
119956 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
119957 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
119958 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
119959 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
119960 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
119961 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
119962 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
119963 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
119964 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
119965 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
119966 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
119967 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
119968 +stripe_status_25259 stripe_status 5 25259 NULL
119969 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
119970 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
119971 +vfs_writev_25278 vfs_writev 3 25278 NULL
119972 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
119973 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
119974 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
119975 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
119976 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
119977 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
119978 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
119979 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
119980 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
119981 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
119982 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
119983 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
119984 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
119985 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
119986 +sb_permission_25523 sb_permission 0 25523 NULL
119987 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
119988 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
119989 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
119990 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
119991 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
119992 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
119993 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
119994 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
119995 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
119996 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
119997 +__direct_map_25647 __direct_map 6-5 25647 NULL
119998 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
119999 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120000 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120001 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120002 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120003 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120004 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120005 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120006 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120007 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120008 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120009 +sg_read_25799 sg_read 3 25799 NULL
120010 +system_enable_read_25815 system_enable_read 3 25815 NULL
120011 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120012 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120013 +parport_read_25855 parport_read 0 25855 NULL
120014 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120015 +key_attr_size_25865 key_attr_size 0 25865 NULL
120016 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120017 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120018 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120019 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120020 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120021 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120022 +rcname_read_25919 rcname_read 3 25919 NULL
120023 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120024 +key_flags_read_25931 key_flags_read 3 25931 NULL
120025 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120026 +flush_25957 flush 2 25957 NULL
120027 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120028 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120029 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120030 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120031 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120032 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120033 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120034 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120035 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120036 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120037 +read_sb_page_26119 read_sb_page 5 26119 NULL
120038 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120039 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120040 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120041 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120042 +disk_devt_26180 disk_devt 0 26180 NULL
120043 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120044 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120045 +mce_write_26201 mce_write 3 26201 NULL
120046 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120047 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120048 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120049 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120050 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120051 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120052 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120053 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120054 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120055 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120056 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120057 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120058 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120059 +ntty_write_26404 ntty_write 3 26404 NULL
120060 +firmware_store_26408 firmware_store 4 26408 NULL
120061 +pagemap_read_26441 pagemap_read 3 26441 NULL
120062 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120063 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120064 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120065 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120066 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
120067 +read_vmcore_26501 read_vmcore 3 26501 NULL
120068 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120069 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120070 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120071 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120072 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120073 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120074 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120075 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120076 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120077 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120078 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120079 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120080 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120081 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120082 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120083 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120084 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120085 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120086 +bos_desc_26752 bos_desc 0 26752 NULL
120087 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120088 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120089 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120090 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120091 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120092 +smk_write_load_26829 smk_write_load 3 26829 NULL
120093 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120094 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120095 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120096 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120097 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120098 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120099 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120100 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120101 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120102 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120103 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120104 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120105 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120106 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120107 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120108 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120109 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120110 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120111 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120112 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120113 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120114 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120115 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120116 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120117 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120118 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120119 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120120 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120121 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120122 +pms_capture_27142 pms_capture 4 27142 NULL
120123 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120124 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120125 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120126 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120127 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120128 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120129 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120130 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120131 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120132 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120133 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120134 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120135 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120136 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120137 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120138 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120139 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120140 +seq_read_27411 seq_read 3 27411 NULL
120141 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120142 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120143 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120144 +cypress_write_27423 cypress_write 4 27423 NULL
120145 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120146 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120147 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120148 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120149 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120150 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
120151 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120152 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120153 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120154 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120155 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120156 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120157 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120158 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120159 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120160 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120161 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120162 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120163 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120164 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120165 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120166 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120167 +evm_write_key_27715 evm_write_key 3 27715 NULL
120168 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120169 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120170 +load_scode_27738 load_scode 2 27738 NULL
120171 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120172 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120173 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120174 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120175 +SyS_readv_27804 SyS_readv 3 27804 NULL
120176 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120177 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120178 +init_header_complete_27833 init_header_complete 0 27833 NULL
120179 +read_profile_27859 read_profile 3 27859 NULL
120180 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120181 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120182 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120183 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120184 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120185 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120186 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120187 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120188 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120189 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120190 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120191 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120192 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120193 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120194 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120195 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120196 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120197 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120198 +pool_status_28055 pool_status 5 28055 NULL
120199 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120200 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120201 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120202 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120203 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120204 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120205 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120206 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120207 +video_read_28148 video_read 3 28148 NULL
120208 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120209 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120210 +vread_28173 vread 0-3 28173 NULL
120211 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120212 +counter_free_res_28187 counter_free_res 5 28187 NULL
120213 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120214 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120215 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120216 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120217 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120218 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120219 +usemap_size_28281 usemap_size 0 28281 NULL
120220 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120221 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120222 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120223 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120224 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120225 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120226 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120227 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120228 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120229 +snapshot_write_28351 snapshot_write 3 28351 NULL
120230 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120231 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120232 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120233 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120234 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120235 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120236 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120237 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120238 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120239 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120240 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120241 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120242 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120243 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120244 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120245 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120246 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120247 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120248 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120249 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120250 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120251 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120252 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120253 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120254 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120255 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120256 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120257 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120258 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120259 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120260 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120261 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120262 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120263 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120264 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120265 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
120266 +spi_execute_28736 spi_execute 5 28736 NULL
120267 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
120268 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
120269 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
120270 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
120271 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
120272 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
120273 +sel_write_member_28800 sel_write_member 3 28800 NULL
120274 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
120275 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
120276 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
120277 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
120278 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
120279 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
120280 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
120281 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
120282 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
120283 +push_rx_28939 push_rx 3 28939 NULL
120284 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
120285 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
120286 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
120287 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
120288 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
120289 +bin_uuid_28999 bin_uuid 3 28999 NULL
120290 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
120291 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
120292 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
120293 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
120294 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
120295 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
120296 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
120297 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
120298 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
120299 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
120300 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
120301 +snprintf_29125 snprintf 0 29125 NULL
120302 +iov_shorten_29130 iov_shorten 0 29130 NULL
120303 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
120304 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
120305 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
120306 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
120307 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
120308 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
120309 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
120310 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
120311 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
120312 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
120313 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
120314 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
120315 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
120316 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
120317 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
120318 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
120319 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
120320 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
120321 +tun_put_user_29337 tun_put_user 5 29337 NULL
120322 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
120323 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
120324 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
120325 +mempool_create_29437 mempool_create 1 29437 NULL
120326 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
120327 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
120328 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
120329 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
120330 +do_register_entry_29478 do_register_entry 4 29478 NULL
120331 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
120332 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
120333 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
120334 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
120335 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
120336 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
120337 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
120338 +ftrace_write_29551 ftrace_write 3 29551 NULL
120339 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
120340 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
120341 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
120342 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
120343 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
120344 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
120345 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
120346 +slots_per_page_29601 slots_per_page 0 29601 NULL
120347 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
120348 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
120349 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
120350 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
120351 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
120352 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
120353 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
120354 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
120355 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
120356 +probes_write_29711 probes_write 3 29711 NULL
120357 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
120358 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
120359 +std_nic_write_29752 std_nic_write 3 29752 NULL
120360 +static_key_count_29771 static_key_count 0 29771 NULL
120361 +dbAlloc_29794 dbAlloc 0 29794 NULL
120362 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
120363 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
120364 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
120365 +count_partial_29850 count_partial 0 29850 NULL
120366 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
120367 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
120368 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
120369 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
120370 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
120371 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
120372 +write_file_queue_29922 write_file_queue 3 29922 NULL
120373 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
120374 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
120375 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
120376 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
120377 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
120378 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
120379 +drp_wmove_30043 drp_wmove 4 30043 NULL
120380 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
120381 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
120382 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
120383 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
120384 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
120385 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
120386 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
120387 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
120388 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
120389 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
120390 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
120391 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
120392 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
120393 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
120394 +SyS_semop_30227 SyS_semop 3 30227 NULL
120395 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
120396 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
120397 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
120398 +compat_readv_30273 compat_readv 3 30273 NULL
120399 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
120400 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
120401 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
120402 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
120403 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
120404 +i8254_read_30330 i8254_read 0 30330 NULL
120405 +resource_from_user_30341 resource_from_user 3 30341 NULL
120406 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
120407 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
120408 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
120409 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
120410 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
120411 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
120412 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
120413 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
120414 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
120415 +enable_write_30456 enable_write 3 30456 NULL
120416 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
120417 +urandom_read_30462 urandom_read 3 30462 NULL
120418 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
120419 +adu_write_30487 adu_write 3 30487 NULL
120420 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
120421 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
120422 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
120423 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
120424 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
120425 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
120426 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
120427 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
120428 +set_le_30581 set_le 4 30581 NULL
120429 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
120430 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
120431 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
120432 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
120433 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
120434 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
120435 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
120436 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
120437 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
120438 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
120439 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
120440 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
120441 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
120442 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
120443 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
120444 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
120445 +snapshot_status_30744 snapshot_status 5 30744 NULL
120446 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
120447 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
120448 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
120449 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
120450 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
120451 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
120452 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
120453 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
120454 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
120455 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
120456 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
120457 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
120458 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
120459 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
120460 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
120461 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
120462 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
120463 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
120464 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
120465 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
120466 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
120467 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
120468 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
120469 +depth_read_31112 depth_read 3 31112 NULL
120470 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
120471 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
120472 +size_inside_page_31141 size_inside_page 0 31141 NULL
120473 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
120474 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
120475 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
120476 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
120477 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
120478 +__read_reg_31216 __read_reg 0 31216 NULL
120479 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
120480 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
120481 +cyy_readb_31240 cyy_readb 0 31240 NULL
120482 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
120483 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
120484 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
120485 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
120486 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
120487 +command_file_write_31318 command_file_write 3 31318 NULL
120488 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
120489 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
120490 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
120491 +outlen_write_31358 outlen_write 3 31358 NULL
120492 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
120493 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
120494 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
120495 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
120496 +inb_31388 inb 0 31388 NULL
120497 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
120498 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
120499 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
120500 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
120501 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
120502 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
120503 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
120504 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
120505 +alg_setkey_31485 alg_setkey 3 31485 NULL
120506 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
120507 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
120508 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
120509 +hidraw_write_31536 hidraw_write 3 31536 NULL
120510 +usbvision_read_31555 usbvision_read 3 31555 NULL
120511 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
120512 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
120513 +osst_write_31581 osst_write 3 31581 NULL
120514 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
120515 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
120516 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
120517 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
120518 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
120519 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
120520 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
120521 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
120522 +__lgread_31668 __lgread 4 31668 NULL
120523 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
120524 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
120525 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
120526 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
120527 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
120528 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
120529 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
120530 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
120531 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
120532 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
120533 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
120534 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
120535 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
120536 +get_count_order_31800 get_count_order 0 31800 NULL
120537 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
120538 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
120539 +data_write_31805 data_write 3 31805 NULL
120540 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
120541 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
120542 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
120543 +clone_bio_31854 clone_bio 4-3 31854 NULL
120544 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
120545 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
120546 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
120547 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
120548 +xattr_permission_31907 xattr_permission 0 31907 NULL
120549 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
120550 +new_dir_31919 new_dir 3 31919 NULL
120551 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
120552 +era_status_31934 era_status 5 31934 NULL
120553 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
120554 +read_mem_31942 read_mem 3 31942 NULL
120555 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
120556 +vb2_write_31948 vb2_write 3 31948 NULL
120557 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
120558 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
120559 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
120560 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
120561 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
120562 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
120563 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
120564 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
120565 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
120566 +calc_hmac_32010 calc_hmac 3 32010 NULL
120567 +aead_len_32021 aead_len 0 32021 NULL
120568 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
120569 +stk_read_32038 stk_read 3 32038 NULL
120570 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
120571 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
120572 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
120573 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
120574 +bio_alloc_32095 bio_alloc 2 32095 NULL
120575 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
120576 +disk_status_32120 disk_status 4 32120 NULL
120577 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
120578 +venus_link_32165 venus_link 5 32165 NULL
120579 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
120580 +do_writepages_32173 do_writepages 0 32173 NULL
120581 +del_ptr_32197 del_ptr 4 32197 NULL
120582 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
120583 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
120584 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
120585 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
120586 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
120587 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
120588 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
120589 +SyS_select_32319 SyS_select 1 32319 NULL
120590 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
120591 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
120592 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
120593 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
120594 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
120595 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
120596 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
120597 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
120598 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
120599 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
120600 +cache_status_32462 cache_status 5 32462 NULL
120601 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
120602 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
120603 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
120604 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
120605 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
120606 +disconnect_32521 disconnect 4 32521 NULL
120607 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
120608 +ilo_read_32531 ilo_read 3 32531 NULL
120609 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
120610 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
120611 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
120612 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
120613 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
120614 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
120615 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
120616 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
120617 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
120618 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
120619 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
120620 +kvmalloc_32646 kvmalloc 1 32646 NULL
120621 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
120622 +generic_readlink_32654 generic_readlink 3 32654 NULL
120623 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
120624 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
120625 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
120626 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
120627 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
120628 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
120629 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
120630 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
120631 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
120632 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
120633 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
120634 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
120635 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
120636 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
120637 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
120638 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
120639 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
120640 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
120641 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
120642 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
120643 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
120644 +compat_filldir_32999 compat_filldir 3 32999 NULL
120645 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
120646 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
120647 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
120648 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
120649 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
120650 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
120651 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
120652 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
120653 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
120654 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
120655 +alloc_tio_33077 alloc_tio 3 33077 NULL
120656 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
120657 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
120658 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
120659 +SyS_poll_33152 SyS_poll 2 33152 NULL
120660 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
120661 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
120662 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
120663 +pp_read_33210 pp_read 3 33210 NULL
120664 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
120665 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
120666 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
120667 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
120668 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
120669 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
120670 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
120671 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
120672 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
120673 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
120674 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
120675 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
120676 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
120677 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
120678 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
120679 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
120680 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
120681 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
120682 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
120683 +message_stats_list_33440 message_stats_list 5 33440 NULL
120684 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
120685 +create_entry_33479 create_entry 2 33479 NULL
120686 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
120687 +res_counter_read_33499 res_counter_read 4 33499 NULL
120688 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
120689 +fb_read_33506 fb_read 3 33506 NULL
120690 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
120691 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
120692 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
120693 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
120694 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
120695 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
120696 +count_subheaders_33591 count_subheaders 0 33591 NULL
120697 +scsi_execute_33596 scsi_execute 5 33596 NULL
120698 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
120699 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
120700 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
120701 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
120702 +stride_page_count_33641 stride_page_count 2 33641 NULL
120703 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
120704 +inw_p_33668 inw_p 0 33668 NULL
120705 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
120706 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
120707 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
120708 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
120709 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
120710 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
120711 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
120712 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
120713 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
120714 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
120715 +hashtab_create_33769 hashtab_create 3 33769 NULL
120716 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
120717 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
120718 +filter_write_33819 filter_write 3 33819 NULL
120719 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
120720 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
120721 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
120722 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
120723 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
120724 +get_user_pages_33908 get_user_pages 0 33908 NULL
120725 +sg_nents_33909 sg_nents 0 33909 NULL
120726 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
120727 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
120728 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
120729 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
120730 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
120731 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
120732 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
120733 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
120734 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
120735 +ppp_write_34034 ppp_write 3 34034 NULL
120736 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
120737 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
120738 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
120739 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
120740 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
120741 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
120742 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
120743 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
120744 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
120745 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
120746 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
120747 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
120748 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
120749 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
120750 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
120751 +device_private_init_34279 device_private_init 0 34279 NULL
120752 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
120753 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
120754 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
120755 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
120756 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
120757 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
120758 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
120759 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
120760 +ea_read_34378 ea_read 0 34378 NULL nohasharray
120761 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
120762 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
120763 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
120764 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
120765 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
120766 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
120767 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
120768 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
120769 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
120770 +security_socket_create_34439 security_socket_create 0 34439 NULL
120771 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
120772 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
120773 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
120774 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
120775 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
120776 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
120777 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
120778 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
120779 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
120780 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
120781 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
120782 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
120783 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
120784 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
120785 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
120786 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
120787 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
120788 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
120789 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
120790 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
120791 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
120792 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
120793 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
120794 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
120795 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
120796 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
120797 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
120798 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
120799 +port_print_34704 port_print 3 34704 NULL
120800 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
120801 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
120802 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
120803 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
120804 +bootmode_store_34762 bootmode_store 4 34762 NULL
120805 +device_add_34766 device_add 0 34766 NULL
120806 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
120807 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
120808 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
120809 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
120810 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
120811 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
120812 +file_page_index_34820 file_page_index 0-2 34820 NULL
120813 +bio_segments_34832 bio_segments 0 34832 NULL
120814 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
120815 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
120816 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
120817 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
120818 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
120819 +msg_print_text_34889 msg_print_text 0 34889 NULL
120820 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
120821 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
120822 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
120823 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
120824 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
120825 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
120826 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
120827 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
120828 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
120829 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
120830 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
120831 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
120832 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
120833 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
120834 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
120835 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
120836 +capi_write_35104 capi_write 3 35104 NULL nohasharray
120837 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
120838 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
120839 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
120840 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
120841 +message_stats_print_35158 message_stats_print 6 35158 NULL
120842 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
120843 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
120844 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
120845 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
120846 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
120847 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
120848 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
120849 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
120850 +set_fd_set_35249 set_fd_set 1 35249 NULL
120851 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
120852 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
120853 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
120854 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
120855 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
120856 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
120857 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
120858 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
120859 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
120860 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
120861 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
120862 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
120863 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
120864 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
120865 +read_kmem_35372 read_kmem 3 35372 NULL
120866 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
120867 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
120868 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
120869 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
120870 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
120871 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
120872 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
120873 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
120874 +async_setkey_35521 async_setkey 3 35521 NULL
120875 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
120876 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
120877 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
120878 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
120879 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
120880 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
120881 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
120882 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
120883 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
120884 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
120885 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
120886 +kernel_readv_35617 kernel_readv 3 35617 NULL
120887 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
120888 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
120889 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
120890 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
120891 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
120892 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
120893 +md_super_write_35703 md_super_write 4 35703 NULL
120894 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
120895 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
120896 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
120897 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
120898 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
120899 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
120900 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
120901 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
120902 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
120903 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
120904 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
120905 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
120906 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
120907 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
120908 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
120909 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
120910 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
120911 +acl_alloc_35979 acl_alloc 1 35979 NULL
120912 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
120913 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
120914 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
120915 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
120916 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
120917 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
120918 +account_shadowed_36048 account_shadowed 2 36048 NULL
120919 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
120920 +write_emulate_36065 write_emulate 2-4 36065 NULL
120921 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
120922 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
120923 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
120924 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
120925 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
120926 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
120927 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
120928 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
120929 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
120930 +twl_set_36154 twl_set 2 36154 NULL
120931 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
120932 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
120933 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
120934 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
120935 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
120936 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
120937 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
120938 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
120939 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
120940 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
120941 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
120942 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
120943 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
120944 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
120945 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
120946 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
120947 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
120948 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
120949 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
120950 +lc_create_36332 lc_create 4 36332 NULL
120951 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
120952 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
120953 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
120954 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
120955 +to_sector_36361 to_sector 0-1 36361 NULL
120956 +tunables_read_36385 tunables_read 3 36385 NULL
120957 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
120958 +sierra_write_36402 sierra_write 4 36402 NULL
120959 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
120960 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
120961 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
120962 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
120963 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
120964 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
120965 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
120966 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
120967 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
120968 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
120969 +cmd_loop_36491 cmd_loop 0 36491 NULL
120970 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
120971 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
120972 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
120973 +get_param_l_36518 get_param_l 0 36518 NULL
120974 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
120975 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
120976 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
120977 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
120978 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
120979 +__erst_read_36579 __erst_read 0 36579 NULL
120980 +put_cmsg_36589 put_cmsg 4 36589 NULL
120981 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
120982 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
120983 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
120984 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
120985 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
120986 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
120987 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
120988 +xillybus_read_36678 xillybus_read 3 36678 NULL
120989 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
120990 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
120991 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
120992 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
120993 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
120994 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
120995 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
120996 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
120997 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
120998 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
120999 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121000 +cm_write_36858 cm_write 3 36858 NULL
121001 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121002 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121003 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121004 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121005 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121006 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121007 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121008 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121009 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121010 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121011 +setxattr_37006 setxattr 4 37006 NULL
121012 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121013 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121014 +command_file_read_37038 command_file_read 3 37038 NULL
121015 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121016 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121017 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121018 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121019 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121020 +parse_command_37079 parse_command 2 37079 NULL
121021 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121022 +tun_get_user_37094 tun_get_user 5 37094 NULL
121023 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121024 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121025 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121026 +msg_word_37164 msg_word 0 37164 NULL
121027 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121028 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121029 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121030 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121031 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121032 +__do_replace_37227 __do_replace 5 37227 NULL
121033 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121034 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121035 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121036 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121037 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121038 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121039 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121040 +tipc_send_37315 tipc_send 3 37315 NULL
121041 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121042 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121043 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121044 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121045 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121046 +seek_firmware_37372 seek_firmware 2 37372 NULL
121047 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121048 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121049 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121050 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121051 +fru_alloc_37442 fru_alloc 1 37442 NULL
121052 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121053 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121054 +get_est_timing_37484 get_est_timing 0 37484 NULL
121055 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121056 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121057 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121058 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121059 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121060 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121061 +hdr_size_37536 hdr_size 0 37536 NULL
121062 +extent_map_end_37550 extent_map_end 0 37550 NULL
121063 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121064 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121065 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121066 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121067 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121068 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121069 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121070 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121071 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121072 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121073 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121074 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121075 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121076 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121077 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121078 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121079 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121080 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121081 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121082 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121083 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121084 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121085 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121086 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121087 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121088 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121089 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121090 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121091 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121092 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121093 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121094 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121095 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121096 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121097 +write_file_bool_37957 write_file_bool 3 37957 NULL
121098 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121099 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121100 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121101 +vfs_readv_38011 vfs_readv 3 38011 NULL
121102 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121103 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121104 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121105 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121106 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121107 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121108 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121109 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121110 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121111 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121112 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121113 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121114 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121115 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121116 +ep0_read_38095 ep0_read 3 38095 NULL
121117 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121118 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121119 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121120 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121121 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121122 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121123 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121124 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121125 +cdev_add_38176 cdev_add 2-3 38176 NULL
121126 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121127 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121128 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121129 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121130 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121131 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121132 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121133 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121134 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121135 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121136 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121137 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121138 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121139 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121140 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121141 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121142 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121143 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121144 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121145 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121146 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121147 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121148 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121149 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121150 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121151 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121152 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121153 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121154 +dev_names_read_38509 dev_names_read 3 38509 NULL
121155 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121156 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121157 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121158 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121159 +kuc_len_38557 kuc_len 0-1 38557 NULL
121160 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121161 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121162 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121163 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121164 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121165 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121166 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121167 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121168 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121169 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121170 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121171 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121172 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121173 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121174 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121175 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121176 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121177 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121178 +udf_readpages_38761 udf_readpages 4 38761 NULL
121179 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121180 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121181 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121182 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121183 +err_decode_38804 err_decode 2 38804 NULL
121184 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121185 +direct_entry_38836 direct_entry 3 38836 NULL
121186 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121187 +interfaces_38859 interfaces 2 38859 NULL
121188 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121189 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121190 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121191 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121192 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121193 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121194 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121195 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121196 +get_nodes_39012 get_nodes 3 39012 NULL
121197 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121198 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121199 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121200 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121201 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121202 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121203 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121204 +ea_foreach_39133 ea_foreach 0 39133 NULL
121205 +generic_permission_39150 generic_permission 0 39150 NULL
121206 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121207 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121208 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121209 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121210 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121211 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121212 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121213 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121214 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121215 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121216 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121217 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121218 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121219 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121220 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121221 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121222 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121223 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121224 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121225 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121226 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121227 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121228 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121229 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121230 +__send_to_port_39386 __send_to_port 3 39386 NULL
121231 +user_power_read_39414 user_power_read 3 39414 NULL
121232 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121233 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121234 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121235 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121236 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121237 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121238 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121239 +int_proc_write_39542 int_proc_write 3 39542 NULL
121240 +pp_write_39554 pp_write 3 39554 NULL
121241 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121242 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121243 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121244 +ext_depth_39607 ext_depth 0 39607 NULL
121245 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121246 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121247 +sdio_readb_39618 sdio_readb 0 39618 NULL
121248 +set_dev_class_39645 set_dev_class 4 39645 NULL
121249 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
121250 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
121251 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
121252 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
121253 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
121254 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
121255 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
121256 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
121257 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
121258 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
121259 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
121260 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
121261 +pkt_add_39897 pkt_add 3 39897 NULL
121262 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
121263 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
121264 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
121265 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
121266 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
121267 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
121268 +__spi_async_39932 __spi_async 0 39932 NULL
121269 +__get_order_39935 __get_order 0 39935 NULL
121270 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
121271 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
121272 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
121273 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
121274 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
121275 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
121276 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
121277 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
121278 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
121279 +server_name2svname_39998 server_name2svname 4 39998 NULL
121280 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
121281 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
121282 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
121283 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
121284 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
121285 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
121286 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
121287 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
121288 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
121289 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
121290 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
121291 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
121292 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
121293 +pt_write_40159 pt_write 3 40159 NULL
121294 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
121295 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
121296 +allocate_probes_40204 allocate_probes 1 40204 NULL
121297 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
121298 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
121299 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
121300 +osst_read_40237 osst_read 3 40237 NULL
121301 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
121302 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
121303 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
121304 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
121305 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
121306 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
121307 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
121308 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
121309 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
121310 +SyS_bind_40303 SyS_bind 3 40303 NULL
121311 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
121312 +mmio_read_40348 mmio_read 4 40348 NULL
121313 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
121314 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
121315 +get_chars_40373 get_chars 3 40373 NULL
121316 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
121317 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
121318 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
121319 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
121320 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
121321 +SyS_writev_40467 SyS_writev 3 40467 NULL
121322 +SyS_select_40473 SyS_select 1 40473 NULL
121323 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
121324 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
121325 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
121326 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
121327 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
121328 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
121329 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
121330 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
121331 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
121332 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
121333 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
121334 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
121335 +fops_read_40672 fops_read 3 40672 NULL
121336 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
121337 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
121338 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
121339 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
121340 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
121341 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
121342 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
121343 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
121344 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
121345 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
121346 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
121347 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
121348 +card_send_command_40757 card_send_command 3 40757 NULL
121349 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
121350 +pg_write_40766 pg_write 3 40766 NULL
121351 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
121352 +show_list_40775 show_list 3-0 40775 NULL
121353 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
121354 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
121355 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
121356 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
121357 +add_action_40811 add_action 4 40811 NULL
121358 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
121359 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
121360 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
121361 +read_file_queue_40895 read_file_queue 3 40895 NULL
121362 +waiters_read_40902 waiters_read 3 40902 NULL
121363 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
121364 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
121365 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
121366 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
121367 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
121368 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
121369 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
121370 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
121371 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
121372 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
121373 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
121374 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
121375 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
121376 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
121377 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
121378 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
121379 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
121380 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
121381 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
121382 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
121383 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
121384 +dma_attach_41094 dma_attach 5-6 41094 NULL
121385 +provide_user_output_41105 provide_user_output 3 41105 NULL
121386 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
121387 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
121388 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
121389 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
121390 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
121391 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
121392 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
121393 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
121394 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
121395 +erst_read_41260 erst_read 0 41260 NULL
121396 +alloc_context_41283 alloc_context 1 41283 NULL
121397 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
121398 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
121399 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
121400 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
121401 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
121402 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
121403 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
121404 +kmp_init_41373 kmp_init 2 41373 NULL
121405 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
121406 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
121407 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
121408 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
121409 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
121410 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
121411 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
121412 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
121413 +se_io_cb_41461 se_io_cb 3 41461 NULL
121414 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
121415 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
121416 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
121417 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
121418 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
121419 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
121420 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
121421 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
121422 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
121423 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
121424 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
121425 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
121426 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
121427 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
121428 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
121429 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
121430 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
121431 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
121432 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
121433 +a2mp_send_41615 a2mp_send 4 41615 NULL
121434 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
121435 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
121436 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
121437 +get_std_timing_41654 get_std_timing 0 41654 NULL
121438 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
121439 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
121440 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
121441 +connector_write_41709 connector_write 3 41709 NULL
121442 +fillonedir_41746 fillonedir 3 41746 NULL
121443 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
121444 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
121445 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
121446 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
121447 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
121448 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
121449 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
121450 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
121451 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
121452 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
121453 +pci_map_single_41869 pci_map_single 0 41869 NULL
121454 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
121455 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
121456 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
121457 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
121458 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
121459 +read_gssp_41947 read_gssp 3 41947 NULL
121460 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
121461 +portnames_read_41958 portnames_read 3 41958 NULL
121462 +dst_mtu_41969 dst_mtu 0 41969 NULL
121463 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
121464 +pool_allocate_42012 pool_allocate 3 42012 NULL
121465 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
121466 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
121467 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
121468 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
121469 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
121470 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
121471 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
121472 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
121473 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
121474 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
121475 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
121476 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
121477 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
121478 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
121479 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
121480 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
121481 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
121482 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
121483 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
121484 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
121485 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
121486 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
121487 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
121488 +find_last_bit_42260 find_last_bit 0 42260 NULL
121489 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
121490 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
121491 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
121492 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
121493 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
121494 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
121495 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
121496 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
121497 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
121498 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
121499 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
121500 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
121501 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
121502 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
121503 +krng_get_random_42420 krng_get_random 3 42420 NULL
121504 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
121505 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
121506 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
121507 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
121508 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
121509 +kuc_free_42455 kuc_free 2 42455 NULL
121510 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
121511 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
121512 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
121513 +bypass_write_42498 bypass_write 3 42498 NULL
121514 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
121515 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
121516 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
121517 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
121518 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
121519 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
121520 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
121521 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
121522 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
121523 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
121524 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
121525 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
121526 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
121527 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
121528 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
121529 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
121530 +vb2_read_42703 vb2_read 3 42703 NULL
121531 +read_status_42722 read_status 0 42722 NULL
121532 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
121533 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
121534 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
121535 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
121536 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
121537 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
121538 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
121539 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
121540 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
121541 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
121542 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
121543 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
121544 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
121545 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
121546 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
121547 +set_arg_42824 set_arg 3 42824 NULL
121548 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
121549 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
121550 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
121551 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
121552 +hd_end_request_42904 hd_end_request 2 42904 NULL
121553 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
121554 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
121555 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
121556 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
121557 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
121558 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
121559 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
121560 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
121561 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
121562 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
121563 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
121564 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
121565 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
121566 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
121567 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
121568 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
121569 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
121570 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
121571 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
121572 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
121573 +uio_write_43202 uio_write 3 43202 NULL
121574 +iso_callback_43208 iso_callback 3 43208 NULL
121575 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
121576 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
121577 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
121578 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
121579 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
121580 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
121581 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
121582 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
121583 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
121584 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
121585 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
121586 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
121587 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
121588 +xenfb_write_43412 xenfb_write 3 43412 NULL
121589 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
121590 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
121591 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
121592 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
121593 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
121594 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
121595 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
121596 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
121597 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
121598 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
121599 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
121600 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
121601 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
121602 +read_events_43534 read_events 3 43534 NULL
121603 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
121604 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
121605 +request_resource_43548 request_resource 0 43548 NULL
121606 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
121607 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
121608 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
121609 +proc_read_43614 proc_read 3 43614 NULL
121610 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
121611 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
121612 +random_write_43656 random_write 3 43656 NULL
121613 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
121614 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
121615 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
121616 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
121617 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
121618 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
121619 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
121620 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
121621 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
121622 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
121623 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
121624 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
121625 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
121626 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
121627 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
121628 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
121629 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
121630 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
121631 +read_flush_43851 read_flush 3 43851 NULL
121632 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
121633 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
121634 +SendString_43928 SendString 3 43928 NULL
121635 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
121636 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
121637 +nla_reserve_43984 nla_reserve 3 43984 NULL
121638 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
121639 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
121640 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
121641 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
121642 +emit_flags_44006 emit_flags 4-3 44006 NULL
121643 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
121644 +fru_strlen_44046 fru_strlen 0 44046 NULL
121645 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
121646 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
121647 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
121648 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
121649 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
121650 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
121651 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
121652 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
121653 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
121654 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
121655 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
121656 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
121657 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
121658 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
121659 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
121660 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
121661 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
121662 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
121663 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
121664 +device_create_file_44285 device_create_file 0 44285 NULL
121665 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
121666 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
121667 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
121668 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
121669 +rs_init_44327 rs_init 1 44327 NULL
121670 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
121671 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
121672 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
121673 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
121674 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
121675 +strlcpy_44400 strlcpy 3 44400 NULL
121676 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
121677 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
121678 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
121679 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
121680 +write_file_debug_44476 write_file_debug 3 44476 NULL
121681 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
121682 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
121683 +bio_advance_44496 bio_advance 2 44496 NULL
121684 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
121685 +ac_register_board_44504 ac_register_board 3 44504 NULL
121686 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
121687 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
121688 +spidev_write_44510 spidev_write 3 44510 NULL
121689 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
121690 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
121691 +comm_write_44537 comm_write 3 44537 NULL
121692 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
121693 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
121694 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
121695 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
121696 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
121697 +mpi_resize_44674 mpi_resize 2 44674 NULL
121698 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
121699 +ts_read_44687 ts_read 3 44687 NULL
121700 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
121701 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
121702 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
121703 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
121704 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
121705 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
121706 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
121707 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
121708 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
121709 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
121710 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
121711 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
121712 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
121713 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
121714 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
121715 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
121716 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
121717 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
121718 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
121719 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
121720 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
121721 +sisusb_write_44834 sisusb_write 3 44834 NULL
121722 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
121723 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
121724 +copydesc_user_44855 copydesc_user 3 44855 NULL
121725 +set_advertising_44870 set_advertising 4 44870 NULL
121726 +init_rs_44873 init_rs 1 44873 NULL
121727 +skb_availroom_44883 skb_availroom 0 44883 NULL
121728 +do_tty_write_44896 do_tty_write 5 44896 NULL
121729 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
121730 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
121731 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
121732 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
121733 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
121734 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
121735 +sel_write_user_45060 sel_write_user 3 45060 NULL
121736 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
121737 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
121738 +snd_card_new_45104 snd_card_new 5 45104 NULL
121739 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
121740 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
121741 +usbdev_read_45114 usbdev_read 3 45114 NULL
121742 +send_to_tty_45141 send_to_tty 3 45141 NULL
121743 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
121744 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
121745 +device_write_45156 device_write 3 45156 NULL nohasharray
121746 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
121747 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
121748 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
121749 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
121750 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
121751 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
121752 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
121753 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
121754 +event_enable_write_45238 event_enable_write 3 45238 NULL
121755 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
121756 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
121757 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
121758 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
121759 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
121760 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
121761 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
121762 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
121763 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
121764 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
121765 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
121766 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
121767 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
121768 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
121769 +__node_remap_45458 __node_remap 4 45458 NULL
121770 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
121771 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
121772 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
121773 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
121774 +copy_macs_45534 copy_macs 4 45534 NULL
121775 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
121776 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
121777 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
121778 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
121779 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
121780 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
121781 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
121782 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
121783 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
121784 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
121785 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
121786 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
121787 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
121788 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
121789 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
121790 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
121791 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
121792 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
121793 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
121794 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
121795 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
121796 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
121797 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
121798 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
121799 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
121800 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
121801 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
121802 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
121803 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
121804 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
121805 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
121806 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
121807 +isdn_write_45863 isdn_write 3 45863 NULL
121808 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
121809 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
121810 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
121811 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
121812 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
121813 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
121814 +alloc_mr_45935 alloc_mr 1 45935 NULL
121815 +copy_to_45969 copy_to 3 45969 NULL
121816 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
121817 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
121818 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
121819 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
121820 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
121821 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
121822 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
121823 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
121824 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
121825 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
121826 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
121827 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
121828 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
121829 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
121830 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
121831 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
121832 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
121833 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
121834 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
121835 +fq_resize_46195 fq_resize 2 46195 NULL
121836 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
121837 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
121838 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
121839 +dsp_write_46218 dsp_write 2 46218 NULL
121840 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
121841 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
121842 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
121843 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
121844 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
121845 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
121846 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
121847 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
121848 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
121849 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
121850 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
121851 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
121852 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
121853 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
121854 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
121855 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
121856 +filldir64_46469 filldir64 3 46469 NULL
121857 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
121858 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
121859 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
121860 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
121861 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
121862 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
121863 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
121864 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
121865 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
121866 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
121867 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
121868 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
121869 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
121870 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
121871 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
121872 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
121873 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
121874 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
121875 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
121876 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
121877 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
121878 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
121879 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
121880 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
121881 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
121882 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
121883 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
121884 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
121885 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
121886 +readreg_46845 readreg 0 46845 NULL
121887 +spi_async_46857 spi_async 0 46857 NULL
121888 +vsnprintf_46863 vsnprintf 0 46863 NULL
121889 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
121890 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
121891 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
121892 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
121893 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
121894 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
121895 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
121896 +fb_write_46924 fb_write 3 46924 NULL
121897 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
121898 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
121899 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
121900 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
121901 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
121902 +strlcat_46985 strlcat 3 46985 NULL
121903 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
121904 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
121905 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
121906 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
121907 +fs_path_len_47060 fs_path_len 0 47060 NULL
121908 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
121909 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
121910 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
121911 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
121912 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
121913 +mousedev_read_47123 mousedev_read 3 47123 NULL
121914 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
121915 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
121916 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
121917 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
121918 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
121919 +options_write_47243 options_write 3 47243 NULL
121920 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
121921 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
121922 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
121923 +vsnprintf_47291 vsnprintf 0 47291 NULL
121924 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
121925 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
121926 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
121927 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
121928 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
121929 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
121930 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
121931 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
121932 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
121933 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
121934 +nametbl_list_47391 nametbl_list 2 47391 NULL
121935 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
121936 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
121937 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
121938 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
121939 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
121940 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
121941 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
121942 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
121943 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
121944 +newpart_47485 newpart 6-4 47485 NULL
121945 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
121946 +core_sys_select_47494 core_sys_select 1 47494 NULL
121947 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
121948 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
121949 +unlink_simple_47506 unlink_simple 3 47506 NULL
121950 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
121951 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
121952 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
121953 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
121954 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
121955 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
121956 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
121957 +read_ldt_47570 read_ldt 2 47570 NULL
121958 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
121959 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
121960 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
121961 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
121962 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
121963 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
121964 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
121965 +get_size_47644 get_size 1-2 47644 NULL
121966 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
121967 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
121968 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
121969 +save_microcode_47717 save_microcode 3 47717 NULL
121970 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
121971 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
121972 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
121973 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
121974 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
121975 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
121976 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
121977 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
121978 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
121979 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
121980 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
121981 +lov_packmd_47810 lov_packmd 0 47810 NULL
121982 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
121983 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
121984 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
121985 +vhci_read_47878 vhci_read 3 47878 NULL
121986 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
121987 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
121988 +comedi_write_47926 comedi_write 3 47926 NULL
121989 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
121990 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
121991 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
121992 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
121993 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
121994 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
121995 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
121996 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
121997 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
121998 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
121999 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122000 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122001 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122002 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122003 +disc_write_48070 disc_write 3 48070 NULL
122004 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122005 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122006 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122007 +load_firmware_48128 load_firmware 2 48128 NULL
122008 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122009 +set_discoverable_48141 set_discoverable 4 48141 NULL
122010 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122011 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122012 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122013 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122014 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122015 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122016 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122017 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122018 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122019 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122020 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122021 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122022 +read_file_recv_48232 read_file_recv 3 48232 NULL
122023 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122024 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122025 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122026 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122027 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122028 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122029 +trace_options_write_48275 trace_options_write 3 48275 NULL
122030 +send_set_info_48288 send_set_info 7 48288 NULL
122031 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122032 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122033 +hash_setkey_48310 hash_setkey 3 48310 NULL
122034 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122035 +skb_add_data_48363 skb_add_data 3 48363 NULL
122036 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122037 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122038 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122039 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122040 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122041 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122042 +print_filtered_48442 print_filtered 2-0 48442 NULL
122043 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122044 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122045 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122046 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122047 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122048 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122049 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122050 +send_control_msg_48498 send_control_msg 6 48498 NULL
122051 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122052 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122053 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122054 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122055 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122056 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122057 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122058 +llog_data_len_48607 llog_data_len 1 48607 NULL
122059 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122060 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122061 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122062 +mtd_read_48655 mtd_read 0 48655 NULL
122063 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122064 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122065 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122066 +altera_drscan_48698 altera_drscan 2 48698 NULL
122067 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122068 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122069 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122070 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122071 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122072 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122073 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122074 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122075 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122076 +azx_get_position_48841 azx_get_position 0 48841 NULL
122077 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122078 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122079 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122080 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122081 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122082 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122083 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122084 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122085 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122086 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122087 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122088 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122089 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122090 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122091 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122092 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122093 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122094 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122095 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122096 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122097 +transient_status_49027 transient_status 4 49027 NULL
122098 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122099 +scsi_register_49094 scsi_register 2 49094 NULL
122100 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122101 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122102 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122103 +pt_read_49136 pt_read 3 49136 NULL
122104 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122105 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122106 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122107 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122108 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122109 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122110 +print_queue_49191 print_queue 0-4 49191 NULL
122111 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122112 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122113 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122114 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122115 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122116 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122117 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122118 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122119 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122120 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122121 +uio_read_49300 uio_read 3 49300 NULL
122122 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122123 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122124 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122125 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122126 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122127 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122128 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122129 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122130 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122131 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122132 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122133 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122134 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122135 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122136 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122137 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122138 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122139 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122140 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122141 +smk_write_access_49561 smk_write_access 3 49561 NULL
122142 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122143 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122144 +readfifo_49583 readfifo 1 49583 NULL
122145 +tap_write_49595 tap_write 3 49595 NULL
122146 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122147 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122148 +heap_init_49617 heap_init 2 49617 NULL
122149 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122150 +port_fops_read_49626 port_fops_read 3 49626 NULL
122151 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122152 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122153 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122154 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122155 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122156 +write_pool_49718 write_pool 3 49718 NULL
122157 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122158 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122159 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122160 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122161 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122162 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122163 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122164 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122165 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122166 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122167 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122168 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122169 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122170 +add_uuid_49831 add_uuid 4 49831 NULL
122171 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122172 +twl4030_write_49846 twl4030_write 2 49846 NULL
122173 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122174 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122175 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122176 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122177 +osc_brw_49896 osc_brw 4 49896 NULL
122178 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122179 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122180 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122181 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122182 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122183 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122184 +isdn_read_50021 isdn_read 3 50021 NULL
122185 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122186 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122187 +ioread8_50049 ioread8 0 50049 NULL
122188 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122189 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122190 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122191 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122192 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122193 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122194 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122195 +read_file_slot_50111 read_file_slot 3 50111 NULL
122196 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122197 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122198 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122199 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122200 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122201 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122202 +odev_update_50169 odev_update 2 50169 NULL
122203 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122204 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122205 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122206 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122207 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122208 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122209 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122210 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122211 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122212 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122213 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122214 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122215 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122216 +do_launder_page_50329 do_launder_page 0 50329 NULL
122217 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122218 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122219 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122220 +tpm_read_50344 tpm_read 3 50344 NULL
122221 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122222 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122223 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122224 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122225 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122226 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122227 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122228 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122229 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122230 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
122231 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
122232 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
122233 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
122234 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
122235 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
122236 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
122237 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
122238 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
122239 +fat_readpages_50582 fat_readpages 4 50582 NULL
122240 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
122241 +xillybus_write_50605 xillybus_write 3 50605 NULL
122242 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
122243 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
122244 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
122245 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
122246 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
122247 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
122248 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
122249 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
122250 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
122251 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
122252 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
122253 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
122254 +tpm_write_50798 tpm_write 3 50798 NULL
122255 +tun_do_read_50800 tun_do_read 4 50800 NULL
122256 +write_flush_50803 write_flush 3 50803 NULL
122257 +dvb_play_50814 dvb_play 3 50814 NULL
122258 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
122259 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
122260 +SetArea_50835 SetArea 4 50835 NULL
122261 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
122262 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
122263 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
122264 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
122265 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
122266 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
122267 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
122268 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
122269 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
122270 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
122271 +show_device_status_50947 show_device_status 0 50947 NULL
122272 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
122273 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
122274 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
122275 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
122276 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
122277 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
122278 +timeout_write_50991 timeout_write 3 50991 NULL
122279 +proc_write_51003 proc_write 3 51003 NULL
122280 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
122281 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
122282 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
122283 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
122284 +dump_midi_51040 dump_midi 3 51040 NULL
122285 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
122286 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
122287 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
122288 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
122289 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
122290 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
122291 +ti_recv_51110 ti_recv 3 51110 NULL
122292 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
122293 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
122294 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
122295 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
122296 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
122297 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
122298 +drm_property_create_51239 drm_property_create 4 51239 NULL
122299 +st_read_51251 st_read 3 51251 NULL
122300 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
122301 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
122302 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
122303 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
122304 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
122305 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
122306 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
122307 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
122308 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
122309 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
122310 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
122311 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
122312 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
122313 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
122314 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
122315 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
122316 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
122317 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
122318 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
122319 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
122320 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
122321 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
122322 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
122323 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
122324 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
122325 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
122326 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
122327 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
122328 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
122329 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
122330 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
122331 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
122332 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
122333 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
122334 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
122335 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
122336 +sel_write_access_51704 sel_write_access 3 51704 NULL
122337 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
122338 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
122339 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
122340 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
122341 +str_read_51731 str_read 4 51731 NULL
122342 +cm4040_read_51732 cm4040_read 3 51732 NULL
122343 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
122344 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
122345 +if_write_51756 if_write 3 51756 NULL
122346 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
122347 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
122348 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
122349 +ioread32_51847 ioread32 0 51847 NULL nohasharray
122350 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
122351 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
122352 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
122353 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
122354 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
122355 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
122356 +user_read_51881 user_read 3 51881 NULL
122357 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
122358 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
122359 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
122360 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
122361 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
122362 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
122363 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
122364 +get_clock_info_51952 get_clock_info 4 51952 NULL
122365 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
122366 +get_zone_51981 get_zone 0-1 51981 NULL
122367 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
122368 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
122369 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
122370 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
122371 +rdmalt_52022 rdmalt 0 52022 NULL
122372 +override_release_52032 override_release 2 52032 NULL
122373 +end_port_52042 end_port 0 52042 NULL
122374 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
122375 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
122376 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
122377 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
122378 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
122379 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
122380 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
122381 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
122382 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
122383 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
122384 +retry_count_read_52129 retry_count_read 3 52129 NULL
122385 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
122386 +sub_alloc_52140 sub_alloc 0 52140 NULL
122387 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
122388 +htable_size_52148 htable_size 0-1 52148 NULL
122389 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
122390 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
122391 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
122392 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
122393 +print_prefix_52176 print_prefix 0 52176 NULL
122394 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
122395 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
122396 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
122397 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
122398 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
122399 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
122400 +shrink_slab_52261 shrink_slab 2 52261 NULL
122401 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
122402 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
122403 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
122404 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
122405 +read_file_reset_52310 read_file_reset 3 52310 NULL
122406 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
122407 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
122408 +hwflags_read_52318 hwflags_read 3 52318 NULL
122409 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
122410 +hur_len_52339 hur_len 0 52339 NULL
122411 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
122412 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
122413 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
122414 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
122415 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
122416 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
122417 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
122418 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
122419 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
122420 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
122421 +delay_status_52431 delay_status 5 52431 NULL
122422 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
122423 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
122424 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
122425 +bt_alloc_52457 bt_alloc 2 52457 NULL
122426 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
122427 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
122428 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
122429 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
122430 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
122431 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
122432 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
122433 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
122434 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
122435 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
122436 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
122437 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
122438 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
122439 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
122440 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
122441 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
122442 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
122443 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
122444 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
122445 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
122446 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
122447 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
122448 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
122449 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
122450 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
122451 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
122452 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
122453 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
122454 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
122455 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
122456 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
122457 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
122458 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
122459 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
122460 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
122461 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
122462 +twlreg_write_52880 twlreg_write 3 52880 NULL
122463 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
122464 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
122465 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
122466 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
122467 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
122468 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
122469 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
122470 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
122471 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
122472 +num_node_state_52989 num_node_state 0 52989 NULL
122473 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
122474 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
122475 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
122476 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
122477 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
122478 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
122479 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
122480 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
122481 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
122482 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
122483 +verity_status_53120 verity_status 5 53120 NULL
122484 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
122485 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
122486 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
122487 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
122488 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
122489 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
122490 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
122491 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
122492 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
122493 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
122494 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
122495 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
122496 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
122497 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
122498 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
122499 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
122500 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
122501 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
122502 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
122503 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
122504 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
122505 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
122506 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
122507 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
122508 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
122509 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
122510 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
122511 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
122512 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
122513 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
122514 +check_acl_53512 check_acl 0 53512 NULL nohasharray
122515 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
122516 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
122517 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
122518 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
122519 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
122520 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
122521 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
122522 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
122523 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
122524 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
122525 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
122526 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
122527 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
122528 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
122529 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
122530 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
122531 +wdm_write_53735 wdm_write 3 53735 NULL
122532 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
122533 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
122534 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
122535 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
122536 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
122537 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
122538 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
122539 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
122540 +setup_data_read_53822 setup_data_read 3 53822 NULL
122541 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
122542 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
122543 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
122544 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
122545 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
122546 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
122547 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
122548 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
122549 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
122550 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
122551 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
122552 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
122553 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
122554 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
122555 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
122556 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
122557 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
122558 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
122559 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
122560 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
122561 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
122562 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
122563 +strn_len_54122 strn_len 0 54122 NULL
122564 +isku_receive_54130 isku_receive 4 54130 NULL
122565 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
122566 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
122567 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
122568 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
122569 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
122570 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
122571 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
122572 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
122573 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
122574 +reada_add_block_54247 reada_add_block 2 54247 NULL
122575 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
122576 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
122577 +audio_write_54261 audio_write 4 54261 NULL nohasharray
122578 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
122579 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
122580 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
122581 +sizeof_long_54276 sizeof_long 0 54276 NULL
122582 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
122583 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
122584 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
122585 +sprintf_54306 sprintf 0 54306 NULL
122586 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
122587 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
122588 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
122589 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
122590 +readlink_copy_54366 readlink_copy 2 54366 NULL
122591 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
122592 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
122593 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
122594 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
122595 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
122596 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
122597 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
122598 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
122599 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
122600 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
122601 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
122602 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
122603 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
122604 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
122605 +viacam_read_54526 viacam_read 3 54526 NULL
122606 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
122607 +setsockopt_54539 setsockopt 5 54539 NULL
122608 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
122609 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
122610 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
122611 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
122612 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
122613 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
122614 +port_fops_write_54627 port_fops_write 3 54627 NULL
122615 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
122616 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
122617 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
122618 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
122619 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
122620 +bus_add_device_54665 bus_add_device 0 54665 NULL
122621 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
122622 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
122623 +evm_read_key_54674 evm_read_key 3 54674 NULL
122624 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
122625 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
122626 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
122627 +kzalloc_54740 kzalloc 1 54740 NULL
122628 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
122629 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
122630 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
122631 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
122632 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
122633 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
122634 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
122635 +nfsd_write_54809 nfsd_write 6 54809 NULL
122636 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
122637 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
122638 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
122639 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
122640 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
122641 +write_rio_54837 write_rio 3 54837 NULL
122642 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
122643 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
122644 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
122645 +printer_read_54851 printer_read 3 54851 NULL
122646 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
122647 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
122648 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
122649 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
122650 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
122651 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
122652 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
122653 +add_port_54941 add_port 2 54941 NULL
122654 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
122655 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
122656 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
122657 +c4_add_card_54968 c4_add_card 3 54968 NULL
122658 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
122659 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
122660 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
122661 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
122662 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
122663 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
122664 +read_dma_55086 read_dma 3 55086 NULL
122665 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
122666 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
122667 +filldir_55137 filldir 3 55137 NULL
122668 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
122669 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
122670 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
122671 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
122672 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
122673 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
122674 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
122675 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
122676 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
122677 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
122678 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
122679 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
122680 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
122681 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
122682 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
122683 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
122684 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
122685 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
122686 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
122687 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
122688 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
122689 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
122690 +vme_user_read_55338 vme_user_read 3 55338 NULL
122691 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
122692 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
122693 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
122694 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
122695 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
122696 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
122697 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
122698 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
122699 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
122700 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
122701 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
122702 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
122703 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
122704 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
122705 +ea_get_55522 ea_get 3-0 55522 NULL
122706 +buffer_size_55534 buffer_size 0 55534 NULL
122707 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
122708 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
122709 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
122710 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
122711 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
122712 +add_partition_55588 add_partition 2 55588 NULL
122713 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
122714 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
122715 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
122716 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
122717 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
122718 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
122719 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
122720 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
122721 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
122722 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
122723 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
122724 +get_info_55681 get_info 3 55681 NULL
122725 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
122726 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
122727 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
122728 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
122729 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
122730 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
122731 +set_local_name_55757 set_local_name 4 55757 NULL
122732 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
122733 +strlen_55778 strlen 0 55778 NULL
122734 +set_spte_55783 set_spte 4-5 55783 NULL
122735 +conf_read_55786 conf_read 3 55786 NULL nohasharray
122736 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
122737 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
122738 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
122739 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
122740 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
122741 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
122742 +hsc_write_55875 hsc_write 3 55875 NULL
122743 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
122744 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
122745 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
122746 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
122747 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
122748 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
122749 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
122750 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
122751 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
122752 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
122753 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
122754 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
122755 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
122756 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
122757 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
122758 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
122759 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
122760 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
122761 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
122762 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
122763 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
122764 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
122765 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
122766 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
122767 +fd_copyin_56247 fd_copyin 3 56247 NULL
122768 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
122769 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
122770 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
122771 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
122772 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
122773 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
122774 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
122775 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
122776 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
122777 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
122778 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
122779 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
122780 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
122781 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
122782 +dev_read_56369 dev_read 3 56369 NULL
122783 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
122784 +lnet_ping_56378 lnet_ping 4 56378 NULL
122785 +write_gssp_56404 write_gssp 3 56404 NULL
122786 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
122787 +store_msg_56417 store_msg 3 56417 NULL
122788 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
122789 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
122790 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
122791 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
122792 +fl_create_56435 fl_create 5 56435 NULL
122793 +gnttab_map_56439 gnttab_map 2 56439 NULL
122794 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
122795 +set_connectable_56458 set_connectable 4 56458 NULL
122796 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
122797 +putused_user_56467 putused_user 3 56467 NULL
122798 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
122799 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
122800 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
122801 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
122802 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
122803 +init_map_ip_56508 init_map_ip 5 56508 NULL
122804 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
122805 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
122806 +ip_options_get_56538 ip_options_get 4 56538 NULL
122807 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
122808 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
122809 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
122810 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
122811 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
122812 +event_filter_write_56609 event_filter_write 3 56609 NULL
122813 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
122814 +gather_array_56641 gather_array 3 56641 NULL
122815 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
122816 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
122817 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
122818 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
122819 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
122820 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
122821 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
122822 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
122823 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
122824 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
122825 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
122826 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
122827 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
122828 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
122829 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
122830 +do_syslog_56807 do_syslog 3 56807 NULL
122831 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
122832 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
122833 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
122834 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
122835 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
122836 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
122837 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
122838 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
122839 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
122840 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
122841 +strcspn_56913 strcspn 0 56913 NULL
122842 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
122843 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
122844 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
122845 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
122846 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
122847 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
122848 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
122849 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
122850 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
122851 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
122852 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
122853 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
122854 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
122855 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
122856 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
122857 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
122858 +altera_get_note_57099 altera_get_note 6 57099 NULL
122859 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
122860 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
122861 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
122862 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
122863 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
122864 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
122865 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
122866 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
122867 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
122868 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
122869 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
122870 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
122871 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
122872 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
122873 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
122874 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
122875 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
122876 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
122877 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
122878 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
122879 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
122880 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
122881 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
122882 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
122883 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
122884 +write_file_regval_57313 write_file_regval 3 57313 NULL
122885 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
122886 +usblp_read_57342 usblp_read 3 57342 NULL
122887 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
122888 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
122889 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
122890 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
122891 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
122892 +read_file_blob_57406 read_file_blob 3 57406 NULL
122893 +enclosure_register_57412 enclosure_register 3 57412 NULL
122894 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
122895 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
122896 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
122897 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
122898 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
122899 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
122900 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
122901 +skb_headlen_57501 skb_headlen 0 57501 NULL
122902 +copy_in_user_57502 copy_in_user 3 57502 NULL
122903 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
122904 +init_tag_map_57515 init_tag_map 3 57515 NULL
122905 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
122906 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
122907 +cmm_read_57520 cmm_read 3 57520 NULL
122908 +inode_permission_57531 inode_permission 0 57531 NULL
122909 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
122910 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
122911 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
122912 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
122913 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
122914 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
122915 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
122916 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
122917 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
122918 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
122919 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
122920 +mem_read_57631 mem_read 3 57631 NULL
122921 +r3964_write_57662 r3964_write 4 57662 NULL
122922 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
122923 +__lgwrite_57669 __lgwrite 4 57669 NULL
122924 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
122925 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
122926 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
122927 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
122928 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
122929 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
122930 +ld2_57794 ld2 0 57794 NULL
122931 +ivtv_read_57796 ivtv_read 3 57796 NULL
122932 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
122933 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
122934 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
122935 +flash_read_57843 flash_read 3 57843 NULL
122936 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
122937 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
122938 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
122939 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
122940 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
122941 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
122942 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
122943 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
122944 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
122945 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
122946 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
122947 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
122948 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
122949 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
122950 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
122951 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
122952 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
122953 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
122954 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
122955 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
122956 +mce_async_out_58056 mce_async_out 3 58056 NULL
122957 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
122958 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
122959 +cm4040_write_58079 cm4040_write 3 58079 NULL
122960 +savemem_58129 savemem 3 58129 NULL
122961 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
122962 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
122963 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
122964 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
122965 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
122966 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
122967 +read_file_debug_58256 read_file_debug 3 58256 NULL
122968 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
122969 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
122970 +profile_load_58267 profile_load 3 58267 NULL
122971 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
122972 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
122973 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
122974 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
122975 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
122976 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
122977 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
122978 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
122979 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
122980 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
122981 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
122982 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
122983 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
122984 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
122985 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
122986 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
122987 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
122988 +capabilities_read_58457 capabilities_read 3 58457 NULL
122989 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
122990 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
122991 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
122992 +nv_rd08_58472 nv_rd08 0 58472 NULL
122993 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
122994 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
122995 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
122996 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
122997 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
122998 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
122999 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123000 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123001 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123002 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123003 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123004 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123005 +xip_file_read_58592 xip_file_read 3 58592 NULL
123006 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123007 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123008 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123009 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123010 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123011 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123012 +find_zero_58685 find_zero 0-1 58685 NULL
123013 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123014 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123015 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123016 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123017 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123018 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123019 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123020 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123021 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123022 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123023 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123024 +ep_read_58813 ep_read 3 58813 NULL
123025 +command_write_58841 command_write 3 58841 NULL
123026 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123027 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123028 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123029 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123030 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123031 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123032 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123033 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123034 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123035 +init_list_set_59005 init_list_set 3 59005 NULL
123036 +ep_write_59008 ep_write 3 59008 NULL
123037 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123038 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123039 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123040 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123041 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123042 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123043 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123044 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123045 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123046 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123047 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123048 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123049 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123050 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123051 +ksize_59176 ksize 0 59176 NULL
123052 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123053 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123054 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123055 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123056 +dt3155_read_59226 dt3155_read 3 59226 NULL
123057 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123058 +nla_len_59258 nla_len 0 59258 NULL
123059 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123060 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123061 +fd_copyout_59323 fd_copyout 3 59323 NULL
123062 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123063 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123064 +__map_request_59350 __map_request 0 59350 NULL
123065 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123066 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123067 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123068 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123069 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123070 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123071 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123072 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123073 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123074 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123075 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123076 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123077 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123078 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123079 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123080 +tunables_write_59563 tunables_write 3 59563 NULL
123081 +bio_split_59564 bio_split 2 59564 NULL
123082 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123083 +write_pbl_59583 write_pbl 4 59583 NULL
123084 +memdup_user_59590 memdup_user 2 59590 NULL
123085 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123086 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123087 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123088 +mtrr_write_59622 mtrr_write 3 59622 NULL
123089 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123090 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123091 +hidraw_read_59650 hidraw_read 3 59650 NULL
123092 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123093 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123094 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123095 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123096 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123097 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123098 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123099 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123100 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123101 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123102 +strnlen_59746 strnlen 0 59746 NULL
123103 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123104 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123105 +venus_remove_59781 venus_remove 4 59781 NULL
123106 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123107 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123108 +ipw_write_59807 ipw_write 3 59807 NULL
123109 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123110 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123111 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123112 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123113 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123114 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123115 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123116 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123117 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123118 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123119 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123120 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123121 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123122 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123123 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123124 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123125 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123126 +copy_items_60009 copy_items 7 60009 NULL
123127 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123128 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123129 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123130 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123131 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123132 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123133 +vcs_size_60050 vcs_size 0 60050 NULL
123134 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123135 +compat_writev_60063 compat_writev 3 60063 NULL
123136 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123137 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123138 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123139 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123140 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123141 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123142 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123143 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123144 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123145 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123146 +init_state_60165 init_state 2 60165 NULL
123147 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123148 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123149 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123150 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
123151 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123152 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123153 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123154 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123155 +printer_write_60276 printer_write 3 60276 NULL
123156 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123157 +getDataLength_60301 getDataLength 0 60301 NULL
123158 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123159 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123160 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123161 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123162 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123163 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123164 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123165 +driver_names_read_60399 driver_names_read 3 60399 NULL
123166 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123167 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123168 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123169 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123170 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123171 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123172 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123173 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123174 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123175 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123176 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123177 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123178 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123179 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123180 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123181 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123182 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123183 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123184 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123185 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123186 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123187 +raid_status_60755 raid_status 5 60755 NULL
123188 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123189 +opticon_write_60775 opticon_write 4 60775 NULL
123190 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123191 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123192 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123193 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123194 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123195 +generic_writepages_60871 generic_writepages 0 60871 NULL
123196 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123197 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123198 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123199 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123200 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123201 +pti_char_write_60960 pti_char_write 3 60960 NULL
123202 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123203 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123204 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123205 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123206 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123207 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123208 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123209 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123210 +symtab_init_61050 symtab_init 2 61050 NULL
123211 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
123212 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
123213 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
123214 +get_derived_key_61100 get_derived_key 4 61100 NULL
123215 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
123216 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
123217 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
123218 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
123219 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
123220 +pair_device_61175 pair_device 4 61175 NULL nohasharray
123221 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
123222 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
123223 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
123224 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
123225 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
123226 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
123227 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
123228 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
123229 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
123230 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
123231 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
123232 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
123233 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
123234 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
123235 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
123236 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
123237 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
123238 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
123239 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
123240 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
123241 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
123242 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
123243 +system_enable_write_61396 system_enable_write 3 61396 NULL
123244 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
123245 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
123246 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
123247 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
123248 +erst_errno_61526 erst_errno 0 61526 NULL
123249 +proc_write_device_61541 proc_write_device 3 61541 NULL
123250 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
123251 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
123252 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
123253 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
123254 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
123255 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
123256 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
123257 +seq_open_private_61589 seq_open_private 3 61589 NULL
123258 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
123259 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
123260 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
123261 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
123262 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
123263 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
123264 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
123265 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
123266 +resize_stripes_61650 resize_stripes 2 61650 NULL
123267 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
123268 +insert_one_name_61668 insert_one_name 7 61668 NULL
123269 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
123270 +lock_loop_61681 lock_loop 1 61681 NULL
123271 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
123272 +filter_read_61692 filter_read 3 61692 NULL
123273 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
123274 +iov_length_61716 iov_length 0 61716 NULL
123275 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
123276 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
123277 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
123278 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
123279 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
123280 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
123281 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
123282 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
123283 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
123284 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
123285 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
123286 +get_fw_name_61874 get_fw_name 3 61874 NULL
123287 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
123288 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
123289 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
123290 +kernfs_name_61910 kernfs_name 3 61910 NULL
123291 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
123292 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
123293 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
123294 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
123295 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
123296 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
123297 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
123298 +fix_read_error_61965 fix_read_error 4 61965 NULL
123299 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
123300 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
123301 +cow_file_range_61979 cow_file_range 3 61979 NULL
123302 +dequeue_event_62000 dequeue_event 3 62000 NULL
123303 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
123304 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
123305 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
123306 +SYSC_select_62024 SYSC_select 1 62024 NULL
123307 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
123308 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
123309 +do_pselect_62061 do_pselect 1 62061 NULL
123310 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
123311 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
123312 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
123313 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
123314 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
123315 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
123316 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
123317 +ql_status_62135 ql_status 5 62135 NULL nohasharray
123318 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
123319 +video_usercopy_62151 video_usercopy 2 62151 NULL
123320 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
123321 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
123322 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
123323 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
123324 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
123325 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
123326 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
123327 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
123328 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
123329 +get_random_int_62279 get_random_int 0 62279 NULL
123330 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
123331 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
123332 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
123333 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
123334 +subseq_list_62332 subseq_list 3-0 62332 NULL
123335 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
123336 +flash_write_62354 flash_write 3 62354 NULL
123337 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
123338 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
123339 +altera_irscan_62396 altera_irscan 2 62396 NULL
123340 +set_ssp_62411 set_ssp 4 62411 NULL
123341 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
123342 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
123343 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
123344 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
123345 +debugfs_read_62535 debugfs_read 3 62535 NULL
123346 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
123347 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
123348 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
123349 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
123350 +get_subdir_62581 get_subdir 3 62581 NULL
123351 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
123352 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
123353 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
123354 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
123355 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
123356 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
123357 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
123358 +rdm_62719 rdm 0 62719 NULL
123359 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
123360 +key_replays_read_62746 key_replays_read 3 62746 NULL
123361 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
123362 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
123363 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
123364 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
123365 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
123366 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
123367 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
123368 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
123369 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
123370 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
123371 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
123372 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
123373 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
123374 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
123375 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
123376 +aoechr_write_62883 aoechr_write 3 62883 NULL
123377 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
123378 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
123379 +getdqbuf_62908 getdqbuf 1 62908 NULL
123380 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
123381 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
123382 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
123383 +hwdep_read_62992 hwdep_read 3 62992 NULL
123384 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
123385 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
123386 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
123387 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
123388 +unlink1_63059 unlink1 3 63059 NULL
123389 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
123390 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
123391 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
123392 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
123393 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
123394 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
123395 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
123396 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
123397 +vme_master_read_63221 vme_master_read 0 63221 NULL
123398 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
123399 +ptp_read_63251 ptp_read 4 63251 NULL
123400 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
123401 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
123402 +raid5_resize_63306 raid5_resize 2 63306 NULL
123403 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
123404 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
123405 +proc_info_read_63344 proc_info_read 3 63344 NULL
123406 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
123407 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
123408 +idmouse_read_63374 idmouse_read 3 63374 NULL
123409 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
123410 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
123411 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
123412 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
123413 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
123414 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
123415 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
123416 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
123417 +read_kcore_63488 read_kcore 3 63488 NULL
123418 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
123419 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
123420 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
123421 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
123422 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
123423 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
123424 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
123425 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
123426 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
123427 +write_debug_level_63613 write_debug_level 3 63613 NULL
123428 +__spi_validate_63618 __spi_validate 0 63618 NULL
123429 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
123430 +hid_report_len_63637 hid_report_len 0 63637 NULL
123431 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
123432 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
123433 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
123434 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
123435 +vbi_read_63673 vbi_read 3 63673 NULL
123436 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
123437 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
123438 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
123439 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
123440 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
123441 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
123442 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
123443 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
123444 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
123445 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
123446 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
123447 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
123448 +sel_write_load_63830 sel_write_load 3 63830 NULL
123449 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
123450 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
123451 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
123452 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
123453 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
123454 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
123455 +__team_options_register_63941 __team_options_register 3 63941 NULL
123456 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
123457 +set_bredr_63975 set_bredr 4 63975 NULL
123458 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
123459 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
123460 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
123461 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
123462 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
123463 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
123464 +__sock_create_64069 __sock_create 0 64069 NULL
123465 +get_u8_64076 get_u8 0 64076 NULL
123466 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
123467 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
123468 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
123469 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
123470 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
123471 +to_bytes_64103 to_bytes 0-1 64103 NULL
123472 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
123473 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
123474 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
123475 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
123476 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
123477 +init_bch_64130 init_bch 1-2 64130 NULL
123478 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
123479 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
123480 +number_of_tds_64156 number_of_tds 0 64156 NULL
123481 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
123482 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
123483 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
123484 +read_pulse_64227 read_pulse 0-3 64227 NULL
123485 +ea_len_64229 ea_len 0 64229 NULL
123486 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
123487 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
123488 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
123489 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
123490 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
123491 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
123492 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
123493 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
123494 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
123495 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
123496 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
123497 +ts_write_64336 ts_write 3 64336 NULL
123498 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
123499 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
123500 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
123501 +reg_create_64372 reg_create 5 64372 NULL
123502 +ilo_write_64378 ilo_write 3 64378 NULL
123503 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
123504 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
123505 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
123506 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
123507 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
123508 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
123509 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
123510 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
123511 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
123512 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
123513 +single_open_size_64483 single_open_size 4 64483 NULL
123514 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
123515 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
123516 +remove_uuid_64505 remove_uuid 4 64505 NULL
123517 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
123518 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
123519 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
123520 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
123521 +SyS_bind_64544 SyS_bind 3 64544 NULL
123522 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
123523 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
123524 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
123525 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
123526 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
123527 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
123528 +do_erase_64574 do_erase 4 64574 NULL
123529 +fanotify_write_64623 fanotify_write 3 64623 NULL
123530 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
123531 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
123532 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
123533 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
123534 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
123535 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
123536 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
123537 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
123538 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
123539 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
123540 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
123541 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
123542 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
123543 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
123544 +hwdep_write_64776 hwdep_write 3 64776 NULL
123545 +message_for_md_64777 message_for_md 5 64777 NULL
123546 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
123547 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
123548 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
123549 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
123550 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
123551 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
123552 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
123553 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
123554 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
123555 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
123556 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
123557 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
123558 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
123559 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
123560 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
123561 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
123562 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
123563 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
123564 +insert_dent_65034 insert_dent 7 65034 NULL
123565 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
123566 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
123567 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
123568 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
123569 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
123570 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
123571 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
123572 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
123573 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
123574 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
123575 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
123576 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
123577 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
123578 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
123579 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
123580 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
123581 +get_var_len_65304 get_var_len 0 65304 NULL
123582 +unpack_array_65318 unpack_array 0 65318 NULL
123583 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
123584 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
123585 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
123586 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
123587 +SyS_writev_65372 SyS_writev 3 65372 NULL
123588 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
123589 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
123590 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
123591 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
123592 +device_add_groups_65423 device_add_groups 0 65423 NULL
123593 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
123594 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
123595 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
123596 +clear_user_65470 clear_user 2 65470 NULL
123597 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
123598 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
123599 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
123600 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
123601 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123602 new file mode 100644
123603 index 0000000..560cd7b
123604 --- /dev/null
123605 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123606 @@ -0,0 +1,92 @@
123607 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
123608 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
123609 +mappedread_2627 mappedread 2 2627 NULL
123610 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
123611 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
123612 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
123613 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
123614 +dmu_write_6048 dmu_write 4-3 6048 NULL
123615 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
123616 +update_pages_6225 update_pages 2-3 6225 NULL
123617 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
123618 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
123619 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
123620 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
123621 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
123622 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
123623 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
123624 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
123625 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
123626 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
123627 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
123628 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
123629 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
123630 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
123631 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
123632 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
123633 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
123634 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
123635 +uiocopy_18680 uiocopy 2 18680 NULL
123636 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
123637 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
123638 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
123639 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
123640 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
123641 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
123642 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
123643 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
123644 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
123645 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
123646 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
123647 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
123648 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
123649 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
123650 +splat_write_30943 splat_write 3 30943 NULL
123651 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
123652 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
123653 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
123654 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
123655 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
123656 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
123657 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
123658 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
123659 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
123660 +copyinstr_36980 copyinstr 3 36980 NULL
123661 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
123662 +splat_read_38116 splat_read 3 38116 NULL
123663 +sa_setup_38756 sa_setup 4 38756 NULL
123664 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
123665 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
123666 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
123667 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
123668 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
123669 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
123670 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
123671 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
123672 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
123673 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
123674 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
123675 +kcopy_write_43683 kcopy_write 3 43683 NULL
123676 +uiomove_44355 uiomove 2 44355 NULL
123677 +dmu_read_44418 dmu_read 4-3 44418 NULL
123678 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
123679 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
123680 +copyin_45945 copyin 3 45945 NULL
123681 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
123682 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
123683 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
123684 +spa_history_write_49650 spa_history_write 3 49650 NULL
123685 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
123686 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
123687 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
123688 +copyout_51409 copyout 3 51409 NULL
123689 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
123690 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
123691 +get_nvlist_56685 get_nvlist 2 56685 NULL
123692 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
123693 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
123694 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
123695 +zpios_write_61823 zpios_write 3 61823 NULL
123696 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
123697 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
123698 +zpios_read_64734 zpios_read 3 64734 NULL
123699 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
123700 new file mode 100644
123701 index 0000000..95f7abd
123702 --- /dev/null
123703 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
123704 @@ -0,0 +1,259 @@
123705 +/*
123706 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123707 + * Licensed under the GPL v2, or (at your option) v3
123708 + *
123709 + * Homepage:
123710 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123711 + *
123712 + * Documentation:
123713 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123714 + *
123715 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
123716 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
123717 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
123718 + *
123719 + * Usage:
123720 + * $ make
123721 + * $ make run
123722 + */
123723 +
123724 +#include "gcc-common.h"
123725 +#include "size_overflow.h"
123726 +
123727 +int plugin_is_GPL_compatible;
123728 +
123729 +tree report_size_overflow_decl;
123730 +
123731 +tree size_overflow_type_HI;
123732 +tree size_overflow_type_SI;
123733 +tree size_overflow_type_DI;
123734 +tree size_overflow_type_TI;
123735 +
123736 +static struct plugin_info size_overflow_plugin_info = {
123737 + .version = "20140725",
123738 + .help = "no-size-overflow\tturn off size overflow checking\n",
123739 +};
123740 +
123741 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
123742 +{
123743 + unsigned int arg_count;
123744 + enum tree_code code = TREE_CODE(*node);
123745 +
123746 + switch (code) {
123747 + case FUNCTION_DECL:
123748 + arg_count = type_num_arguments(TREE_TYPE(*node));
123749 + break;
123750 + case FUNCTION_TYPE:
123751 + case METHOD_TYPE:
123752 + arg_count = type_num_arguments(*node);
123753 + break;
123754 + default:
123755 + *no_add_attrs = true;
123756 + error("%s: %qE attribute only applies to functions", __func__, name);
123757 + return NULL_TREE;
123758 + }
123759 +
123760 + for (; args; args = TREE_CHAIN(args)) {
123761 + tree position = TREE_VALUE(args);
123762 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
123763 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
123764 + *no_add_attrs = true;
123765 + }
123766 + }
123767 + return NULL_TREE;
123768 +}
123769 +
123770 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
123771 +{
123772 + unsigned int arg_count;
123773 + enum tree_code code = TREE_CODE(*node);
123774 +
123775 + switch (code) {
123776 + case FUNCTION_DECL:
123777 + arg_count = type_num_arguments(TREE_TYPE(*node));
123778 + break;
123779 + case FUNCTION_TYPE:
123780 + case METHOD_TYPE:
123781 + arg_count = type_num_arguments(*node);
123782 + break;
123783 + case FIELD_DECL:
123784 + return NULL_TREE;
123785 + default:
123786 + *no_add_attrs = true;
123787 + error("%qE attribute only applies to functions", name);
123788 + return NULL_TREE;
123789 + }
123790 +
123791 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
123792 + return NULL_TREE;
123793 +
123794 + for (; args; args = TREE_CHAIN(args)) {
123795 + tree position = TREE_VALUE(args);
123796 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
123797 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
123798 + *no_add_attrs = true;
123799 + }
123800 + }
123801 + return NULL_TREE;
123802 +}
123803 +
123804 +static struct attribute_spec size_overflow_attr = {
123805 + .name = "size_overflow",
123806 + .min_length = 1,
123807 + .max_length = -1,
123808 + .decl_required = true,
123809 + .type_required = false,
123810 + .function_type_required = false,
123811 + .handler = handle_size_overflow_attribute,
123812 +#if BUILDING_GCC_VERSION >= 4007
123813 + .affects_type_identity = false
123814 +#endif
123815 +};
123816 +
123817 +static struct attribute_spec intentional_overflow_attr = {
123818 + .name = "intentional_overflow",
123819 + .min_length = 1,
123820 + .max_length = -1,
123821 + .decl_required = true,
123822 + .type_required = false,
123823 + .function_type_required = false,
123824 + .handler = handle_intentional_overflow_attribute,
123825 +#if BUILDING_GCC_VERSION >= 4007
123826 + .affects_type_identity = false
123827 +#endif
123828 +};
123829 +
123830 +static void register_attributes(void __unused *event_data, void __unused *data)
123831 +{
123832 + register_attribute(&size_overflow_attr);
123833 + register_attribute(&intentional_overflow_attr);
123834 +}
123835 +
123836 +static tree create_typedef(tree type, const char* ident)
123837 +{
123838 + tree new_type, decl;
123839 +
123840 + new_type = build_variant_type_copy(type);
123841 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
123842 + DECL_ORIGINAL_TYPE(decl) = type;
123843 + TYPE_NAME(new_type) = decl;
123844 + return new_type;
123845 +}
123846 +
123847 +// Create the noreturn report_size_overflow() function decl.
123848 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
123849 +{
123850 + tree const_char_ptr_type_node;
123851 + tree fntype;
123852 +
123853 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
123854 +
123855 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
123856 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
123857 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
123858 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
123859 +
123860 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
123861 + fntype = build_function_type_list(void_type_node,
123862 + const_char_ptr_type_node,
123863 + unsigned_type_node,
123864 + const_char_ptr_type_node,
123865 + const_char_ptr_type_node,
123866 + NULL_TREE);
123867 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
123868 +
123869 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
123870 + TREE_PUBLIC(report_size_overflow_decl) = 1;
123871 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
123872 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
123873 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
123874 +}
123875 +
123876 +
123877 +extern struct gimple_opt_pass pass_dce;
123878 +
123879 +static struct opt_pass *make_dce_pass(void)
123880 +{
123881 +#if BUILDING_GCC_VERSION >= 4009
123882 + return make_pass_dce(g);
123883 +#else
123884 + return &pass_dce.pass;
123885 +#endif
123886 +}
123887 +
123888 +
123889 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
123890 +{
123891 + int i;
123892 + const char * const plugin_name = plugin_info->base_name;
123893 + const int argc = plugin_info->argc;
123894 + const struct plugin_argument * const argv = plugin_info->argv;
123895 + bool enable = true;
123896 + struct register_pass_info insert_size_overflow_asm_pass_info;
123897 + struct register_pass_info __unused dump_before_pass_info;
123898 + struct register_pass_info __unused dump_after_pass_info;
123899 + struct register_pass_info insert_size_overflow_check_info;
123900 + struct register_pass_info dce_pass_info;
123901 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
123902 + {
123903 + .base = &report_size_overflow_decl,
123904 + .nelt = 1,
123905 + .stride = sizeof(report_size_overflow_decl),
123906 + .cb = &gt_ggc_mx_tree_node,
123907 + .pchw = &gt_pch_nx_tree_node
123908 + },
123909 + LAST_GGC_ROOT_TAB
123910 + };
123911 +
123912 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
123913 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
123914 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
123915 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
123916 +
123917 + dump_before_pass_info.pass = make_dump_pass();
123918 + dump_before_pass_info.reference_pass_name = "increase_alignment";
123919 + dump_before_pass_info.ref_pass_instance_number = 1;
123920 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
123921 +
123922 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
123923 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
123924 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
123925 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
123926 +
123927 + dump_after_pass_info.pass = make_dump_pass();
123928 + dump_after_pass_info.reference_pass_name = "increase_alignment";
123929 + dump_after_pass_info.ref_pass_instance_number = 1;
123930 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
123931 +
123932 + dce_pass_info.pass = make_dce_pass();
123933 + dce_pass_info.reference_pass_name = "vrp";
123934 + dce_pass_info.ref_pass_instance_number = 1;
123935 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
123936 +
123937 + if (!plugin_default_version_check(version, &gcc_version)) {
123938 + error(G_("incompatible gcc/plugin versions"));
123939 + return 1;
123940 + }
123941 +
123942 + for (i = 0; i < argc; ++i) {
123943 + if (!strcmp(argv[i].key, "no-size-overflow")) {
123944 + enable = false;
123945 + continue;
123946 + }
123947 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
123948 + }
123949 +
123950 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
123951 + if (enable) {
123952 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
123953 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
123954 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
123955 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
123956 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
123957 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
123958 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
123959 + }
123960 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
123961 +
123962 + return 0;
123963 +}
123964 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
123965 new file mode 100644
123966 index 0000000..0888f6c
123967 --- /dev/null
123968 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
123969 @@ -0,0 +1,364 @@
123970 +/*
123971 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123972 + * Licensed under the GPL v2, or (at your option) v3
123973 + *
123974 + * Homepage:
123975 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123976 + *
123977 + * Documentation:
123978 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123979 + *
123980 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
123981 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
123982 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
123983 + *
123984 + * Usage:
123985 + * $ make
123986 + * $ make run
123987 + */
123988 +
123989 +#include "gcc-common.h"
123990 +#include "size_overflow.h"
123991 +
123992 +#include "size_overflow_hash.h"
123993 +#include "size_overflow_hash_aux.h"
123994 +
123995 +#define CODES_LIMIT 32
123996 +
123997 +static unsigned char get_tree_code(const_tree type)
123998 +{
123999 + switch (TREE_CODE(type)) {
124000 + case ARRAY_TYPE:
124001 + return 0;
124002 + case BOOLEAN_TYPE:
124003 + return 1;
124004 + case ENUMERAL_TYPE:
124005 + return 2;
124006 + case FUNCTION_TYPE:
124007 + return 3;
124008 + case INTEGER_TYPE:
124009 + return 4;
124010 + case POINTER_TYPE:
124011 + return 5;
124012 + case RECORD_TYPE:
124013 + return 6;
124014 + case UNION_TYPE:
124015 + return 7;
124016 + case VOID_TYPE:
124017 + return 8;
124018 + case REAL_TYPE:
124019 + return 9;
124020 + case VECTOR_TYPE:
124021 + return 10;
124022 + case REFERENCE_TYPE:
124023 + return 11;
124024 + case OFFSET_TYPE:
124025 + return 12;
124026 + case COMPLEX_TYPE:
124027 + return 13;
124028 + default:
124029 + debug_tree((tree)type);
124030 + gcc_unreachable();
124031 + }
124032 +}
124033 +
124034 +struct function_hash {
124035 + size_t tree_codes_len;
124036 + unsigned char tree_codes[CODES_LIMIT];
124037 + const_tree fndecl;
124038 + unsigned int hash;
124039 +};
124040 +
124041 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124042 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124043 +{
124044 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124045 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124046 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124047 +
124048 + unsigned int m = 0x57559429;
124049 + unsigned int n = 0x5052acdb;
124050 + const unsigned int *key4 = (const unsigned int *)key;
124051 + unsigned int h = len;
124052 + unsigned int k = len + seed + n;
124053 + unsigned long long p;
124054 +
124055 + while (len >= 8) {
124056 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124057 + len -= 8;
124058 + }
124059 + if (len >= 4) {
124060 + cwmixb(key4[0]) key4 += 1;
124061 + len -= 4;
124062 + }
124063 + if (len)
124064 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124065 + cwmixb(h ^ (k + n));
124066 + return k ^ h;
124067 +
124068 +#undef cwfold
124069 +#undef cwmixa
124070 +#undef cwmixb
124071 +}
124072 +
124073 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124074 +{
124075 + unsigned int fn, codes, seed = 0;
124076 +
124077 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124078 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124079 +
124080 + fn_hash_data->hash = fn ^ codes;
124081 +}
124082 +
124083 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124084 +{
124085 + gcc_assert(type != NULL_TREE);
124086 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124087 +
124088 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124089 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124090 + fn_hash_data->tree_codes_len++;
124091 + type = TREE_TYPE(type);
124092 + }
124093 +}
124094 +
124095 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124096 +{
124097 + const_tree result;
124098 +
124099 + gcc_assert(node != NULL_TREE);
124100 +
124101 + if (DECL_P(node)) {
124102 + result = DECL_RESULT(node);
124103 + if (result != NULL_TREE)
124104 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124105 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124106 + }
124107 +
124108 + gcc_assert(TYPE_P(node));
124109 +
124110 + if (TREE_CODE(node) == FUNCTION_TYPE)
124111 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124112 +
124113 + return set_node_codes(node, fn_hash_data);
124114 +}
124115 +
124116 +static void set_function_codes(struct function_hash *fn_hash_data)
124117 +{
124118 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124119 + enum tree_code code = TREE_CODE(type);
124120 +
124121 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124122 +
124123 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124124 +
124125 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124126 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124127 +}
124128 +
124129 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124130 +{
124131 + while (entry) {
124132 + if (!strcmp(entry->name, func_name))
124133 + return entry;
124134 + entry = entry->next;
124135 + }
124136 + return NULL;
124137 +}
124138 +
124139 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124140 +{
124141 + const struct size_overflow_hash *entry;
124142 + struct function_hash fn_hash_data;
124143 + const char *func_name;
124144 +
124145 + // skip builtins __builtin_constant_p
124146 + if (DECL_BUILT_IN(fndecl))
124147 + return NULL;
124148 +
124149 + fn_hash_data.fndecl = fndecl;
124150 + fn_hash_data.tree_codes_len = 0;
124151 +
124152 + set_function_codes(&fn_hash_data);
124153 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124154 +
124155 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124156 + set_hash(func_name, &fn_hash_data);
124157 +
124158 + entry = size_overflow_hash[fn_hash_data.hash];
124159 + entry = get_proper_hash_chain(entry, func_name);
124160 + if (entry)
124161 + return entry;
124162 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124163 + return get_proper_hash_chain(entry, func_name);
124164 +}
124165 +
124166 +static void print_missing_msg(const_tree func, unsigned int argnum)
124167 +{
124168 + location_t loc;
124169 + const char *curfunc;
124170 + struct function_hash fn_hash_data;
124171 +
124172 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124173 + fn_hash_data.tree_codes_len = 0;
124174 +
124175 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124176 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124177 +
124178 + set_function_codes(&fn_hash_data);
124179 + set_hash(curfunc, &fn_hash_data);
124180 +
124181 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124182 +}
124183 +
124184 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124185 +{
124186 + tree var;
124187 + unsigned int argnum = 1;
124188 +
124189 + if (TREE_CODE(arg) == SSA_NAME)
124190 + arg = SSA_NAME_VAR(arg);
124191 +
124192 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124193 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124194 + continue;
124195 + if (!skip_types(var))
124196 + return argnum;
124197 + }
124198 +
124199 + return CANNOT_FIND_ARG;
124200 +}
124201 +
124202 +static const char *get_asm_string(const_gimple stmt)
124203 +{
124204 + if (!stmt)
124205 + return NULL;
124206 + if (gimple_code(stmt) != GIMPLE_ASM)
124207 + return NULL;
124208 +
124209 + return gimple_asm_string(stmt);
124210 +}
124211 +
124212 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
124213 +{
124214 + const char *str;
124215 +
124216 + str = get_asm_string(stmt);
124217 + if (!str)
124218 + return false;
124219 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
124220 +}
124221 +
124222 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
124223 +{
124224 + const char *str;
124225 +
124226 + str = get_asm_string(stmt);
124227 + if (!str)
124228 + return false;
124229 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
124230 +}
124231 +
124232 +bool is_size_overflow_asm(const_gimple stmt)
124233 +{
124234 + const char *str;
124235 +
124236 + str = get_asm_string(stmt);
124237 + if (!str)
124238 + return false;
124239 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
124240 +}
124241 +
124242 +bool is_a_return_check(const_tree node)
124243 +{
124244 + if (TREE_CODE(node) == FUNCTION_DECL)
124245 + return true;
124246 +
124247 + gcc_assert(TREE_CODE(node) == PARM_DECL);
124248 + return false;
124249 +}
124250 +
124251 +// Get the argnum of a function decl, if node is a return then the argnum is 0
124252 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
124253 +{
124254 + if (is_a_return_check(node))
124255 + return 0;
124256 + else
124257 + return find_arg_number_tree(node, orig_fndecl);
124258 +}
124259 +
124260 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
124261 +{
124262 + const struct size_overflow_hash *hash;
124263 + unsigned int new_argnum;
124264 + tree arg;
124265 + const_tree origarg;
124266 +
124267 + if (argnum == 0)
124268 + return argnum;
124269 +
124270 + hash = get_function_hash(fndecl);
124271 + if (hash && hash->param & (1U << argnum))
124272 + return argnum;
124273 +
124274 + if (DECL_EXTERNAL(fndecl))
124275 + return argnum;
124276 +
124277 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
124278 + argnum--;
124279 + while (origarg && argnum) {
124280 + origarg = TREE_CHAIN(origarg);
124281 + argnum--;
124282 + }
124283 + gcc_assert(argnum == 0);
124284 + gcc_assert(origarg != NULL_TREE);
124285 +
124286 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
124287 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
124288 + return new_argnum;
124289 +
124290 + return CANNOT_FIND_ARG;
124291 +}
124292 +
124293 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
124294 +{
124295 + const struct size_overflow_hash *hash;
124296 +
124297 + hash = get_function_hash(fndecl);
124298 + if (hash && (hash->param & (1U << num)))
124299 + return true;
124300 + return false;
124301 +}
124302 +
124303 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
124304 + * If the function is missing everywhere then print the missing message into stderr.
124305 + */
124306 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
124307 +{
124308 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
124309 +#if BUILDING_GCC_VERSION >= 4008
124310 + case BUILT_IN_BSWAP16:
124311 +#endif
124312 + case BUILT_IN_BSWAP32:
124313 + case BUILT_IN_BSWAP64:
124314 + case BUILT_IN_EXPECT:
124315 + case BUILT_IN_MEMCMP:
124316 + return false;
124317 + default:
124318 + break;
124319 + }
124320 +
124321 + // skip test.c
124322 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
124323 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
124324 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
124325 + }
124326 +
124327 + if (is_in_hash_table(orig_fndecl, num))
124328 + return false;
124329 +
124330 + print_missing_msg(orig_fndecl, num);
124331 + return true;
124332 +}
124333 +
124334 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
124335 new file mode 100644
124336 index 0000000..924652b
124337 --- /dev/null
124338 +++ b/tools/gcc/stackleak_plugin.c
124339 @@ -0,0 +1,395 @@
124340 +/*
124341 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
124342 + * Licensed under the GPL v2
124343 + *
124344 + * Note: the choice of the license means that the compilation process is
124345 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
124346 + * but for the kernel it doesn't matter since it doesn't link against
124347 + * any of the gcc libraries
124348 + *
124349 + * gcc plugin to help implement various PaX features
124350 + *
124351 + * - track lowest stack pointer
124352 + *
124353 + * TODO:
124354 + * - initialize all local variables
124355 + *
124356 + * BUGS:
124357 + * - none known
124358 + */
124359 +
124360 +#include "gcc-common.h"
124361 +
124362 +int plugin_is_GPL_compatible;
124363 +
124364 +static int track_frame_size = -1;
124365 +static const char track_function[] = "pax_track_stack";
124366 +static const char check_function[] = "pax_check_alloca";
124367 +static tree track_function_decl, check_function_decl;
124368 +static bool init_locals;
124369 +
124370 +static struct plugin_info stackleak_plugin_info = {
124371 + .version = "201408011900",
124372 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
124373 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
124374 +};
124375 +
124376 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
124377 +{
124378 + gimple check_alloca;
124379 + tree alloca_size;
124380 +
124381 + // insert call to void pax_check_alloca(unsigned long size)
124382 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
124383 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
124384 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
124385 +}
124386 +
124387 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
124388 +{
124389 + gimple track_stack;
124390 +
124391 + // insert call to void pax_track_stack(void)
124392 + track_stack = gimple_build_call(track_function_decl, 0);
124393 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
124394 +}
124395 +
124396 +static bool is_alloca(gimple stmt)
124397 +{
124398 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
124399 + return true;
124400 +
124401 +#if BUILDING_GCC_VERSION >= 4007
124402 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
124403 + return true;
124404 +#endif
124405 +
124406 + return false;
124407 +}
124408 +
124409 +static unsigned int execute_stackleak_tree_instrument(void)
124410 +{
124411 + basic_block bb, entry_bb;
124412 + bool prologue_instrumented = false, is_leaf = true;
124413 +
124414 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
124415 +
124416 + // 1. loop through BBs and GIMPLE statements
124417 + FOR_EACH_BB_FN(bb, cfun) {
124418 + gimple_stmt_iterator gsi;
124419 +
124420 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124421 + gimple stmt;
124422 +
124423 + stmt = gsi_stmt(gsi);
124424 +
124425 + if (is_gimple_call(stmt))
124426 + is_leaf = false;
124427 +
124428 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
124429 + if (!is_alloca(stmt))
124430 + continue;
124431 +
124432 + // 2. insert stack overflow check before each __builtin_alloca call
124433 + stackleak_check_alloca(&gsi);
124434 +
124435 + // 3. insert track call after each __builtin_alloca call
124436 + stackleak_add_instrumentation(&gsi);
124437 + if (bb == entry_bb)
124438 + prologue_instrumented = true;
124439 + }
124440 + }
124441 +
124442 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
124443 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
124444 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
124445 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
124446 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
124447 + return 0;
124448 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
124449 + return 0;
124450 +
124451 + // 4. insert track call at the beginning
124452 + if (!prologue_instrumented) {
124453 + gimple_stmt_iterator gsi;
124454 +
124455 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124456 + if (dom_info_available_p(CDI_DOMINATORS))
124457 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124458 + gsi = gsi_start_bb(bb);
124459 + stackleak_add_instrumentation(&gsi);
124460 + }
124461 +
124462 + return 0;
124463 +}
124464 +
124465 +static unsigned int execute_stackleak_final(void)
124466 +{
124467 + rtx insn, next;
124468 +
124469 + if (cfun->calls_alloca)
124470 + return 0;
124471 +
124472 + // keep calls only if function frame is big enough
124473 + if (get_frame_size() >= track_frame_size)
124474 + return 0;
124475 +
124476 + // 1. find pax_track_stack calls
124477 + for (insn = get_insns(); insn; insn = next) {
124478 + // 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))
124479 + rtx body;
124480 +
124481 + next = NEXT_INSN(insn);
124482 + if (!CALL_P(insn))
124483 + continue;
124484 + body = PATTERN(insn);
124485 + if (GET_CODE(body) != CALL)
124486 + continue;
124487 + body = XEXP(body, 0);
124488 + if (GET_CODE(body) != MEM)
124489 + continue;
124490 + body = XEXP(body, 0);
124491 + if (GET_CODE(body) != SYMBOL_REF)
124492 + continue;
124493 +// if (strcmp(XSTR(body, 0), track_function))
124494 + if (SYMBOL_REF_DECL(body) != track_function_decl)
124495 + continue;
124496 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124497 + // 2. delete call
124498 + delete_insn_and_edges(insn);
124499 +#if BUILDING_GCC_VERSION >= 4007
124500 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
124501 + insn = next;
124502 + next = NEXT_INSN(insn);
124503 + delete_insn_and_edges(insn);
124504 + }
124505 +#endif
124506 + }
124507 +
124508 +// print_simple_rtl(stderr, get_insns());
124509 +// print_rtl(stderr, get_insns());
124510 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124511 +
124512 + return 0;
124513 +}
124514 +
124515 +static bool gate_stackleak_track_stack(void)
124516 +{
124517 + tree section;
124518 +
124519 + if (ix86_cmodel != CM_KERNEL)
124520 + return false;
124521 +
124522 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
124523 + if (section && TREE_VALUE(section)) {
124524 + section = TREE_VALUE(TREE_VALUE(section));
124525 +
124526 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
124527 + return false;
124528 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
124529 + return false;
124530 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
124531 + return false;
124532 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
124533 + return false;
124534 + }
124535 +
124536 + return track_frame_size >= 0;
124537 +}
124538 +
124539 +static void stackleak_start_unit(void *gcc_data, void *user_data)
124540 +{
124541 + tree fntype;
124542 +
124543 + // void pax_track_stack(void)
124544 + fntype = build_function_type_list(void_type_node, NULL_TREE);
124545 + track_function_decl = build_fn_decl(track_function, fntype);
124546 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
124547 + TREE_PUBLIC(track_function_decl) = 1;
124548 + DECL_EXTERNAL(track_function_decl) = 1;
124549 + DECL_ARTIFICIAL(track_function_decl) = 1;
124550 +
124551 + // void pax_check_alloca(unsigned long)
124552 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
124553 + check_function_decl = build_fn_decl(check_function, fntype);
124554 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
124555 + TREE_PUBLIC(check_function_decl) = 1;
124556 + DECL_EXTERNAL(check_function_decl) = 1;
124557 + DECL_ARTIFICIAL(check_function_decl) = 1;
124558 +}
124559 +
124560 +#if BUILDING_GCC_VERSION >= 4009
124561 +static const struct pass_data stackleak_tree_instrument_pass_data = {
124562 +#else
124563 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
124564 + .pass = {
124565 +#endif
124566 + .type = GIMPLE_PASS,
124567 + .name = "stackleak_tree_instrument",
124568 +#if BUILDING_GCC_VERSION >= 4008
124569 + .optinfo_flags = OPTGROUP_NONE,
124570 +#endif
124571 +#if BUILDING_GCC_VERSION >= 4009
124572 + .has_gate = true,
124573 + .has_execute = true,
124574 +#else
124575 + .gate = gate_stackleak_track_stack,
124576 + .execute = execute_stackleak_tree_instrument,
124577 + .sub = NULL,
124578 + .next = NULL,
124579 + .static_pass_number = 0,
124580 +#endif
124581 + .tv_id = TV_NONE,
124582 + .properties_required = PROP_gimple_leh | PROP_cfg,
124583 + .properties_provided = 0,
124584 + .properties_destroyed = 0,
124585 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
124586 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
124587 +#if BUILDING_GCC_VERSION < 4009
124588 + }
124589 +#endif
124590 +};
124591 +
124592 +#if BUILDING_GCC_VERSION >= 4009
124593 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
124594 +#else
124595 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
124596 + .pass = {
124597 +#endif
124598 + .type = RTL_PASS,
124599 + .name = "stackleak_final",
124600 +#if BUILDING_GCC_VERSION >= 4008
124601 + .optinfo_flags = OPTGROUP_NONE,
124602 +#endif
124603 +#if BUILDING_GCC_VERSION >= 4009
124604 + .has_gate = true,
124605 + .has_execute = true,
124606 +#else
124607 + .gate = gate_stackleak_track_stack,
124608 + .execute = execute_stackleak_final,
124609 + .sub = NULL,
124610 + .next = NULL,
124611 + .static_pass_number = 0,
124612 +#endif
124613 + .tv_id = TV_NONE,
124614 + .properties_required = 0,
124615 + .properties_provided = 0,
124616 + .properties_destroyed = 0,
124617 + .todo_flags_start = 0,
124618 + .todo_flags_finish = TODO_dump_func
124619 +#if BUILDING_GCC_VERSION < 4009
124620 + }
124621 +#endif
124622 +};
124623 +
124624 +#if BUILDING_GCC_VERSION >= 4009
124625 +namespace {
124626 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
124627 +public:
124628 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
124629 + bool gate() { return gate_stackleak_track_stack(); }
124630 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
124631 +};
124632 +
124633 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
124634 +public:
124635 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
124636 + bool gate() { return gate_stackleak_track_stack(); }
124637 + unsigned int execute() { return execute_stackleak_final(); }
124638 +};
124639 +}
124640 +
124641 +static opt_pass *make_stackleak_tree_instrument_pass(void)
124642 +{
124643 + return new stackleak_tree_instrument_pass();
124644 +}
124645 +
124646 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
124647 +{
124648 + return new stackleak_final_rtl_opt_pass();
124649 +}
124650 +#else
124651 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
124652 +{
124653 + return &stackleak_tree_instrument_pass.pass;
124654 +}
124655 +
124656 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
124657 +{
124658 + return &stackleak_final_rtl_opt_pass.pass;
124659 +}
124660 +#endif
124661 +
124662 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124663 +{
124664 + const char * const plugin_name = plugin_info->base_name;
124665 + const int argc = plugin_info->argc;
124666 + const struct plugin_argument * const argv = plugin_info->argv;
124667 + int i;
124668 + struct register_pass_info stackleak_tree_instrument_pass_info;
124669 + struct register_pass_info stackleak_final_pass_info;
124670 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
124671 + {
124672 + .base = &track_function_decl,
124673 + .nelt = 1,
124674 + .stride = sizeof(track_function_decl),
124675 + .cb = &gt_ggc_mx_tree_node,
124676 + .pchw = &gt_pch_nx_tree_node
124677 + },
124678 + {
124679 + .base = &check_function_decl,
124680 + .nelt = 1,
124681 + .stride = sizeof(check_function_decl),
124682 + .cb = &gt_ggc_mx_tree_node,
124683 + .pchw = &gt_pch_nx_tree_node
124684 + },
124685 + LAST_GGC_ROOT_TAB
124686 + };
124687 +
124688 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
124689 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
124690 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
124691 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
124692 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124693 +
124694 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
124695 + stackleak_final_pass_info.reference_pass_name = "final";
124696 + stackleak_final_pass_info.ref_pass_instance_number = 1;
124697 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124698 +
124699 + if (!plugin_default_version_check(version, &gcc_version)) {
124700 + error(G_("incompatible gcc/plugin versions"));
124701 + return 1;
124702 + }
124703 +
124704 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
124705 +
124706 + for (i = 0; i < argc; ++i) {
124707 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
124708 + if (!argv[i].value) {
124709 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124710 + continue;
124711 + }
124712 + track_frame_size = atoi(argv[i].value);
124713 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
124714 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
124715 + continue;
124716 + }
124717 + if (!strcmp(argv[i].key, "initialize-locals")) {
124718 + if (argv[i].value) {
124719 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
124720 + continue;
124721 + }
124722 + init_locals = true;
124723 + continue;
124724 + }
124725 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124726 + }
124727 +
124728 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
124729 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
124730 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
124731 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
124732 +
124733 + return 0;
124734 +}
124735 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
124736 new file mode 100644
124737 index 0000000..4ee2231
124738 --- /dev/null
124739 +++ b/tools/gcc/structleak_plugin.c
124740 @@ -0,0 +1,274 @@
124741 +/*
124742 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
124743 + * Licensed under the GPL v2
124744 + *
124745 + * Note: the choice of the license means that the compilation process is
124746 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
124747 + * but for the kernel it doesn't matter since it doesn't link against
124748 + * any of the gcc libraries
124749 + *
124750 + * gcc plugin to forcibly initialize certain local variables that could
124751 + * otherwise leak kernel stack to userland if they aren't properly initialized
124752 + * by later code
124753 + *
124754 + * Homepage: http://pax.grsecurity.net/
124755 + *
124756 + * Usage:
124757 + * $ # for 4.5/4.6/C based 4.7
124758 + * $ 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
124759 + * $ # for C++ based 4.7/4.8+
124760 + * $ 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
124761 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
124762 + *
124763 + * TODO: eliminate redundant initializers
124764 + * increase type coverage
124765 + */
124766 +
124767 +#include "gcc-common.h"
124768 +
124769 +// unused C type flag in all versions 4.5-4.9
124770 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
124771 +
124772 +int plugin_is_GPL_compatible;
124773 +
124774 +static struct plugin_info structleak_plugin_info = {
124775 + .version = "201401260140",
124776 + .help = "disable\tdo not activate plugin\n",
124777 +};
124778 +
124779 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
124780 +{
124781 + *no_add_attrs = true;
124782 +
124783 + // check for types? for now accept everything linux has to offer
124784 + if (TREE_CODE(*node) != FIELD_DECL)
124785 + return NULL_TREE;
124786 +
124787 + *no_add_attrs = false;
124788 + return NULL_TREE;
124789 +}
124790 +
124791 +static struct attribute_spec user_attr = {
124792 + .name = "user",
124793 + .min_length = 0,
124794 + .max_length = 0,
124795 + .decl_required = false,
124796 + .type_required = false,
124797 + .function_type_required = false,
124798 + .handler = handle_user_attribute,
124799 +#if BUILDING_GCC_VERSION >= 4007
124800 + .affects_type_identity = true
124801 +#endif
124802 +};
124803 +
124804 +static void register_attributes(void *event_data, void *data)
124805 +{
124806 + register_attribute(&user_attr);
124807 +// register_attribute(&force_attr);
124808 +}
124809 +
124810 +static tree get_field_type(tree field)
124811 +{
124812 + return strip_array_types(TREE_TYPE(field));
124813 +}
124814 +
124815 +static bool is_userspace_type(tree type)
124816 +{
124817 + tree field;
124818 +
124819 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
124820 + tree fieldtype = get_field_type(field);
124821 + enum tree_code code = TREE_CODE(fieldtype);
124822 +
124823 + if (code == RECORD_TYPE || code == UNION_TYPE)
124824 + if (is_userspace_type(fieldtype))
124825 + return true;
124826 +
124827 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
124828 + return true;
124829 + }
124830 + return false;
124831 +}
124832 +
124833 +static void finish_type(void *event_data, void *data)
124834 +{
124835 + tree type = (tree)event_data;
124836 +
124837 + if (TYPE_USERSPACE(type))
124838 + return;
124839 +
124840 + if (is_userspace_type(type))
124841 + TYPE_USERSPACE(type) = 1;
124842 +}
124843 +
124844 +static void initialize(tree var)
124845 +{
124846 + basic_block bb;
124847 + gimple_stmt_iterator gsi;
124848 + tree initializer;
124849 + gimple init_stmt;
124850 +
124851 + // this is the original entry bb before the forced split
124852 + // TODO: check further BBs in case more splits occured before us
124853 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
124854 +
124855 + // first check if the variable is already initialized, warn otherwise
124856 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124857 + gimple stmt = gsi_stmt(gsi);
124858 + tree rhs1;
124859 +
124860 + // we're looking for an assignment of a single rhs...
124861 + if (!gimple_assign_single_p(stmt))
124862 + continue;
124863 + rhs1 = gimple_assign_rhs1(stmt);
124864 +#if BUILDING_GCC_VERSION >= 4007
124865 + // ... of a non-clobbering expression...
124866 + if (TREE_CLOBBER_P(rhs1))
124867 + continue;
124868 +#endif
124869 + // ... to our variable...
124870 + if (gimple_get_lhs(stmt) != var)
124871 + continue;
124872 + // if it's an initializer then we're good
124873 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
124874 + return;
124875 + }
124876 +
124877 + // these aren't the 0days you're looking for
124878 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
124879 +
124880 + // build the initializer expression
124881 + initializer = build_constructor(TREE_TYPE(var), NULL);
124882 +
124883 + // build the initializer stmt
124884 + init_stmt = gimple_build_assign(var, initializer);
124885 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
124886 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
124887 + update_stmt(init_stmt);
124888 +}
124889 +
124890 +static unsigned int handle_function(void)
124891 +{
124892 + basic_block bb;
124893 + unsigned int ret = 0;
124894 + tree var;
124895 + unsigned int i;
124896 +
124897 + // split the first bb where we can put the forced initializers
124898 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124899 + if (dom_info_available_p(CDI_DOMINATORS))
124900 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124901 +
124902 + // enumarate all local variables and forcibly initialize our targets
124903 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
124904 + tree type = TREE_TYPE(var);
124905 +
124906 + gcc_assert(DECL_P(var));
124907 + if (!auto_var_in_fn_p(var, current_function_decl))
124908 + continue;
124909 +
124910 + // only care about structure types
124911 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
124912 + continue;
124913 +
124914 + // if the type is of interest, examine the variable
124915 + if (TYPE_USERSPACE(type))
124916 + initialize(var);
124917 + }
124918 +
124919 + return ret;
124920 +}
124921 +
124922 +#if BUILDING_GCC_VERSION >= 4009
124923 +static const struct pass_data structleak_pass_data = {
124924 +#else
124925 +static struct gimple_opt_pass structleak_pass = {
124926 + .pass = {
124927 +#endif
124928 + .type = GIMPLE_PASS,
124929 + .name = "structleak",
124930 +#if BUILDING_GCC_VERSION >= 4008
124931 + .optinfo_flags = OPTGROUP_NONE,
124932 +#endif
124933 +#if BUILDING_GCC_VERSION >= 4009
124934 + .has_gate = false,
124935 + .has_execute = true,
124936 +#else
124937 + .gate = NULL,
124938 + .execute = handle_function,
124939 + .sub = NULL,
124940 + .next = NULL,
124941 + .static_pass_number = 0,
124942 +#endif
124943 + .tv_id = TV_NONE,
124944 + .properties_required = PROP_cfg,
124945 + .properties_provided = 0,
124946 + .properties_destroyed = 0,
124947 + .todo_flags_start = 0,
124948 + .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
124949 +#if BUILDING_GCC_VERSION < 4009
124950 + }
124951 +#endif
124952 +};
124953 +
124954 +#if BUILDING_GCC_VERSION >= 4009
124955 +namespace {
124956 +class structleak_pass : public gimple_opt_pass {
124957 +public:
124958 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
124959 + unsigned int execute() { return handle_function(); }
124960 +};
124961 +}
124962 +
124963 +static opt_pass *make_structleak_pass(void)
124964 +{
124965 + return new structleak_pass();
124966 +}
124967 +#else
124968 +static struct opt_pass *make_structleak_pass(void)
124969 +{
124970 + return &structleak_pass.pass;
124971 +}
124972 +#endif
124973 +
124974 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124975 +{
124976 + int i;
124977 + const char * const plugin_name = plugin_info->base_name;
124978 + const int argc = plugin_info->argc;
124979 + const struct plugin_argument * const argv = plugin_info->argv;
124980 + bool enable = true;
124981 + struct register_pass_info structleak_pass_info;
124982 +
124983 + structleak_pass_info.pass = make_structleak_pass();
124984 + structleak_pass_info.reference_pass_name = "ssa";
124985 + structleak_pass_info.ref_pass_instance_number = 1;
124986 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124987 +
124988 + if (!plugin_default_version_check(version, &gcc_version)) {
124989 + error(G_("incompatible gcc/plugin versions"));
124990 + return 1;
124991 + }
124992 +
124993 + if (strcmp(lang_hooks.name, "GNU C")) {
124994 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
124995 + enable = false;
124996 + }
124997 +
124998 + for (i = 0; i < argc; ++i) {
124999 + if (!strcmp(argv[i].key, "disable")) {
125000 + enable = false;
125001 + continue;
125002 + }
125003 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125004 + }
125005 +
125006 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125007 + if (enable) {
125008 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125009 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125010 + }
125011 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125012 +
125013 + return 0;
125014 +}
125015 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125016 index 88461f0..6fb70a0 100644
125017 --- a/tools/include/linux/compiler.h
125018 +++ b/tools/include/linux/compiler.h
125019 @@ -35,6 +35,14 @@
125020 # define unlikely(x) __builtin_expect(!!(x), 0)
125021 #endif
125022
125023 +#ifndef __size_overflow
125024 +# define __size_overflow(...)
125025 +#endif
125026 +
125027 +#ifndef __intentional_overflow
125028 +# define __intentional_overflow(...)
125029 +#endif
125030 +
125031 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125032
125033 #endif /* _TOOLS_LINUX_COMPILER_H */
125034 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125035 index ce00f7e..0aca5e4 100644
125036 --- a/tools/lib/api/Makefile
125037 +++ b/tools/lib/api/Makefile
125038 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
125039
125040 LIBFILE = libapikfs.a
125041
125042 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125043 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125044 EXTLIBS = -lelf -lpthread -lrt -lm
125045 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125046 ALL_LDFLAGS = $(LDFLAGS)
125047 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125048 index 6789d788..4afd019e 100644
125049 --- a/tools/perf/util/include/asm/alternative-asm.h
125050 +++ b/tools/perf/util/include/asm/alternative-asm.h
125051 @@ -5,4 +5,7 @@
125052
125053 #define altinstruction_entry #
125054
125055 + .macro pax_force_retaddr rip=0, reload=0
125056 + .endm
125057 +
125058 #endif
125059 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125060 index 0a578fe..b81f62d 100644
125061 --- a/tools/virtio/linux/uaccess.h
125062 +++ b/tools/virtio/linux/uaccess.h
125063 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125064 ({ \
125065 typeof(ptr) __pu_ptr = (ptr); \
125066 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125067 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125068 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125069 0; \
125070 })
125071
125072 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125073 index 6a3f29b..a1d2e93 100644
125074 --- a/virt/kvm/kvm_main.c
125075 +++ b/virt/kvm/kvm_main.c
125076 @@ -77,12 +77,17 @@ LIST_HEAD(vm_list);
125077
125078 static cpumask_var_t cpus_hardware_enabled;
125079 static int kvm_usage_count = 0;
125080 -static atomic_t hardware_enable_failed;
125081 +static atomic_unchecked_t hardware_enable_failed;
125082
125083 struct kmem_cache *kvm_vcpu_cache;
125084 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125085
125086 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125087 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125088 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125089 +static struct preempt_ops kvm_preempt_ops = {
125090 + .sched_in = kvm_sched_in,
125091 + .sched_out = kvm_sched_out,
125092 +};
125093
125094 struct dentry *kvm_debugfs_dir;
125095
125096 @@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125097 /* We can read the guest memory with __xxx_user() later on. */
125098 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125099 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125100 - !access_ok(VERIFY_WRITE,
125101 + !access_ok_noprefault(VERIFY_WRITE,
125102 (void __user *)(unsigned long)mem->userspace_addr,
125103 mem->memory_size)))
125104 goto out;
125105 @@ -1637,9 +1642,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125106
125107 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125108 {
125109 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125110 + int r;
125111 + unsigned long addr;
125112
125113 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125114 + addr = gfn_to_hva(kvm, gfn);
125115 + if (kvm_is_error_hva(addr))
125116 + return -EFAULT;
125117 + r = __clear_user((void __user *)addr + offset, len);
125118 + if (r)
125119 + return -EFAULT;
125120 + mark_page_dirty(kvm, gfn);
125121 + return 0;
125122 }
125123 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125124
125125 @@ -1889,7 +1902,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125126 return 0;
125127 }
125128
125129 -static struct file_operations kvm_vcpu_fops = {
125130 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125131 .release = kvm_vcpu_release,
125132 .unlocked_ioctl = kvm_vcpu_ioctl,
125133 #ifdef CONFIG_COMPAT
125134 @@ -2593,7 +2606,7 @@ out:
125135 }
125136 #endif
125137
125138 -static struct file_operations kvm_vm_fops = {
125139 +static file_operations_no_const kvm_vm_fops __read_only = {
125140 .release = kvm_vm_release,
125141 .unlocked_ioctl = kvm_vm_ioctl,
125142 #ifdef CONFIG_COMPAT
125143 @@ -2666,7 +2679,7 @@ out:
125144 return r;
125145 }
125146
125147 -static struct file_operations kvm_chardev_ops = {
125148 +static file_operations_no_const kvm_chardev_ops __read_only = {
125149 .unlocked_ioctl = kvm_dev_ioctl,
125150 .compat_ioctl = kvm_dev_ioctl,
125151 .llseek = noop_llseek,
125152 @@ -2692,7 +2705,7 @@ static void hardware_enable_nolock(void *junk)
125153
125154 if (r) {
125155 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125156 - atomic_inc(&hardware_enable_failed);
125157 + atomic_inc_unchecked(&hardware_enable_failed);
125158 printk(KERN_INFO "kvm: enabling virtualization on "
125159 "CPU%d failed\n", cpu);
125160 }
125161 @@ -2748,10 +2761,10 @@ static int hardware_enable_all(void)
125162
125163 kvm_usage_count++;
125164 if (kvm_usage_count == 1) {
125165 - atomic_set(&hardware_enable_failed, 0);
125166 + atomic_set_unchecked(&hardware_enable_failed, 0);
125167 on_each_cpu(hardware_enable_nolock, NULL, 1);
125168
125169 - if (atomic_read(&hardware_enable_failed)) {
125170 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125171 hardware_disable_all_nolock();
125172 r = -EBUSY;
125173 }
125174 @@ -3156,7 +3169,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125175 kvm_arch_vcpu_put(vcpu);
125176 }
125177
125178 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125179 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125180 struct module *module)
125181 {
125182 int r;
125183 @@ -3203,7 +3216,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125184 if (!vcpu_align)
125185 vcpu_align = __alignof__(struct kvm_vcpu);
125186 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125187 - 0, NULL);
125188 + SLAB_USERCOPY, NULL);
125189 if (!kvm_vcpu_cache) {
125190 r = -ENOMEM;
125191 goto out_free_3;
125192 @@ -3213,9 +3226,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125193 if (r)
125194 goto out_free;
125195
125196 + pax_open_kernel();
125197 kvm_chardev_ops.owner = module;
125198 kvm_vm_fops.owner = module;
125199 kvm_vcpu_fops.owner = module;
125200 + pax_close_kernel();
125201
125202 r = misc_register(&kvm_dev);
125203 if (r) {
125204 @@ -3225,9 +3240,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125205
125206 register_syscore_ops(&kvm_syscore_ops);
125207
125208 - kvm_preempt_ops.sched_in = kvm_sched_in;
125209 - kvm_preempt_ops.sched_out = kvm_sched_out;
125210 -
125211 r = kvm_init_debug();
125212 if (r) {
125213 printk(KERN_ERR "kvm: create debugfs files failed\n");